@portone/server-sdk
Version:
PortOne JavaScript SDK for server-side usage
36 lines (35 loc) • 976 B
JavaScript
import { PromotionError } from "./PromotionError.mjs";
import { USER_AGENT } from "../../../client.mjs";
export function PromotionClient(init) {
const baseUrl = init.baseUrl ?? "https://api.portone.io";
const secret = init.secret;
return {
getPromotion: async (options) => {
const {
promotionId
} = options;
const response = await fetch(
new URL(`/promotions/${encodeURIComponent(promotionId)}`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPromotionError(await response.json());
}
return response.json();
}
};
}
export class GetPromotionError extends PromotionError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPromotionError.prototype);
this.name = "GetPromotionError";
}
}