@portone/server-sdk
Version:
PortOne JavaScript SDK for server-side usage
67 lines (66 loc) • 1.9 kB
JavaScript
import { CompanyError } from "./CompanyError.mjs";
import { USER_AGENT } from "../../../client.mjs";
export function CompanyClient(init) {
const baseUrl = init.baseUrl ?? "https://api.portone.io";
const secret = init.secret;
return {
getB2bBusinessInfos: async (options) => {
const {
brnList
} = options;
const requestBody = JSON.stringify({
brnList
});
const response = await fetch(
new URL("/b2b/companies/business-info", baseUrl),
{
method: "POST",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new GetB2bBusinessInfosError(await response.json());
}
return response.json();
},
getPlatformCompanyState: async (options) => {
const {
businessRegistrationNumber
} = options;
const response = await fetch(
new URL(`/platform/companies/${encodeURIComponent(businessRegistrationNumber)}/state`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformCompanyStateError(await response.json());
}
return response.json();
}
};
}
export class GetB2bBusinessInfosError extends CompanyError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetB2bBusinessInfosError.prototype);
this.name = "GetB2bBusinessInfosError";
}
}
export class GetPlatformCompanyStateError extends CompanyError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformCompanyStateError.prototype);
this.name = "GetPlatformCompanyStateError";
}
}