This SDK provides an easy-to-use interface for interacting with the TrustedShops API. It supports authentication, account management, and review operations.
Important: Remember, use this repo ONLY server-side.
To install the SDK, run:
npm install trustedshops-typescript-sdk
or
npm install @krystianslowik/trustedshops-typescript-sdk
Start by authenticating with your TrustedShops credentials:
import { TrustedShops } from "trustedshops-typescript-sdk";
await TrustedShops.initialize("your-client-id", "your-client-secret");
After authentication, you can manage your channels & reviews:
// Get all channels
const allChannels = TrustedShops.getChannels();
console.log("All channels:", allChannels);
// Refresh the list of channels
const refreshedChannels = await TrustedShops.refreshChannelsList();
console.log("Refreshed channels list:", refreshedChannels);
// Get a channel by ID, name, or locale
const channelById = TrustedShops.getChannel("chl-12345");
console.log("Channel by ID:", channelById);
const channelByName = TrustedShops.getChannel("My Shop");
console.log("Channel by name:", channelByName);
const channelByLocale = TrustedShops.getChannel("de_DE");
console.log("Channel by locale:", channelByLocale);
// Get all channels by locale
const germanChannels = TrustedShops.getChannelsByLocale("de_DE");
console.log("All channels for German locale:", germanChannels);
// Update a channel
const myShopChannel = TrustedShops.getChannel("My Shop");
if (myShopChannel) {
await TrustedShops.updateChannel(myShopChannel.id, {
name: "My Updated Shop",
});
console.log(
"Channel updated:",
await TrustedShops.getChannel(myShopChannel.id)
);
}
// Get reviews for a specific channel by ID, name, or locale
const reviewsForChannel = await TrustedShops.getReviewsForChannel("My Shop", {
count: 10,
});
console.log("Reviews for 'My Shop':", reviewsForChannel);
// Get reviews for all channels
const reviewsForAllChannels = await TrustedShops.getReviewsForAllChannels({
count: 20,
});
console.log("Reviews for all channels:", reviewsForAllChannels);
// Trigger an event with the specified event data, channel name, or channel ID
const eventData = {
type: "purchase",
customer: { email: "customer@example.com" },
transaction: { reference: "ORDER12345" },
};
const eventResponse = await TrustedShops.triggerEvent(eventData, "en-US");
console.log("Event created with reference:", eventResponse.EventRef);
// Check details of a specific event by its ID
const eventDetails = await TrustedShops.checkEventDetails("EVT123456");
console.log("Event details:", eventDetails);
The ReviewsService
in the TrustedShops
class allows you to interact with the TrustedShops API to fetch, create, and manage reviews. Below are the available methods and examples of how to use them.
You can fetch a list of reviews based on certain channels and filtering options.
Fetches a list of reviews based on the provided channels and options.
const channels = ["chl-123", "chl-456"];
const options = {
rating: 4,
status: ["APPROVED", "REJECTED"],
type: ["PRODUCT_REVIEW"],
orderBy: "submittedAt",
};
const reviews = await TrustedShops.Reviews.getReviews(channels, options);
console.log(reviews);
getMinimalReviews(channels?: string[], options?: ReviewOptions): Promise<CustomerReviewListResponse>
Fetches a minimal list of reviews based on the provided channels and options.
const channels = ["chl-123", "chl-456"];
const options = {
rating: 5,
status: ["APPROVED"],
type: ["SERVICE_REVIEW"],
orderBy: "submittedAt",
};
const minimalReviews = await TrustedShops.Reviews.getMinimalReviews(
channels,
options
);
console.log(minimalReviews);
Retrieves the details of a specific review.
const reviewId = "review12345";
const review = await TrustedShops.Reviews.getReview(reviewId);
console.log(review);
Creates a veto for a specific review.
const reviewVetoRequest = {
comment: "This review contains abusive language.",
reason: "ABUSIVE",
vetoReporterEmail: "reporter@example.com",
channelName: "Web",
};
const vetoResponse = await TrustedShops.Reviews.createVeto(
"review12345",
reviewVetoRequest
);
console.log(vetoResponse);
Retrieves the veto details for a specific review.
const reviewId = "review12345";
const reviewVeto = await TrustedShops.Reviews.getReviewVeto(reviewId);
console.log(reviewVeto);
Saves a reply to a specific review.
const reviewReply = {
comment: "Thank you for your feedback!",
sendNotification: true,
};
await TrustedShops.Reviews.saveReviewReply("review12345", reviewReply);
Deletes a reply from a specific review.
await TrustedShops.Reviews.deleteReviewReply("review12345");
Filters an array of reviews based on the provided rating and type.
const reviews = TrustedShops.Reviews.;
const filteredReviews = await TrustedShops.Reviews.filterFetchedReviews(
reviews,
5,
"SERVICE_REVIEW"
);
console.log(filteredReviews);
getReviewsCount(options?: { channels?: string[], submittedAfter?: string, submittedBefore?: string, rating?: number[], status?: ReviewState[], type?: ReviewType[], hasReply?: boolean, ignoreStatements?: boolean, query?: string, sku?: string[] }): Promise<ChannelReviewCountResponse>
Fetches the count of reviews based on the provided filter options.
const options = {
channels: ["chl-123", "chl-456"],
submittedAfter: "2024-01-01",
rating: [4, 5],
};
const reviewsCount = await TrustedShops.Reviews.getReviewsCount(options);
console.log(reviewsCount);
The TrustedShops SDK provides methods to create and manage events associated with customer transactions. Below are the key methods related to event management.
The triggerEvent
method is used to create a new event, such as a purchase or order, associated with a specific customer and channel. This method allows you to specify event details, including customer information, transaction details, and product information.
public static async triggerEvent(
eventData: Partial<EventRequest>,
channelIdentifier?: ChannelId | string
): Promise<EventPostResponse>
-
eventData
(Partial): The event data that includes details like event type, customer information, transaction reference, and product details. -
channelIdentifier
(ChannelId | string, optional): The ID, name, or locale of the channel associated with the event. If provided, the SDK will attempt to resolve the channel ID based on this value.
A Promise
that resolves to an EventPostResponse
, which contains information about the created event, including the event reference.
import { TrustedShops } from "trustedshops-sdk";
async function createPurchaseEvent() {
const eventData: Partial<EventRequest> = {
type: "purchase",
customer: {
email: "customer@example.com",
firstName: "John",
lastName: "Doe",
},
transaction: {
reference: "ORDER12345",
date: "2024-08-21",
},
products: [
{
name: "Sample Product",
sku: "SKU12345",
url: "https://example.com/product",
},
],
};
const response = await TrustedShops.triggerEvent(eventData, "en-US");
console.log("Event created with reference:", response.EventRef);
}
createPurchaseEvent();
The checkEventDetails
method retrieves the details of an event using its reference ID. This is useful for checking the status or details of an event after it has been created.
public static async checkEventDetails(
eventId: string
): Promise<EventGetResponse>
-
eventId
(string): The reference ID of the event to retrieve.
A Promise
that resolves to an EventGetResponse
, containing detailed information about the event, including customer and transaction details.
import { TrustedShops } from "trustedshops-sdk";
async function getEventDetails() {
const eventId = "EVT123456";
const eventDetails = await TrustedShops.checkEventDetails(eventId);
console.log("Event details:", eventDetails);
}
getEventDetails();
The EventRequest
interface defines the structure of the event data required by the triggerEvent
method.
-
type
(string): The type of event (e.g., "purchase"). -
defaultLocale
(string, optional): The default locale for the event. -
customer
(object): The customer details, includingfirstName
,lastName
, andemail
. -
channel
(object): The channel information, includingid
andtype
. -
transaction
(object): The transaction details, includingreference
anddate
. -
estimatedDeliveryDate
(string, optional): The estimated delivery date for the products. -
products
(Array, optional): A list of products associated with the event, each containing properties likename
,sku
, andurl
. -
system
(string, optional): The system creating the event (default is "Trusted Shops TypeScript SDK"). -
systemVersion
(string, optional): The version of the system creating the event. -
metadata
(object, optional): Additional metadata for the event.
The EventPostResponse
interface defines the structure of the response returned after creating an event.
-
Message
(string): A message indicating the status of the event creation. -
EventRef
(string): The reference ID of the created event.
The EventGetResponse
interface defines the structure of the response returned when retrieving an event's details.
-
id
(string): The unique ID of the event. -
accountRef
(string): The reference to the account associated with the event. -
type
(string): The type of the event. -
customer
(object): The customer details. -
channel
(object): The channel details. -
transaction
(object): The transaction details. -
products
(Array): A list of products associated with the event. -
system
(string): The system that created the event. -
systemVersion
(string): The version of the system that created the event. -
metadata
(object): Additional metadata for the event. -
createdAt
(string): The timestamp when the event was created.
This SDK is written in TypeScript and provides full type definitions for all methods and returned data structures.
Contributions are welcome! Please submit pull requests with any enhancements, bug fixes, or documentation improvements.
This SDK is released under the MIT License.