@portone/server-sdk
Version:
PortOne JavaScript SDK for server-side usage
69 lines (68 loc) • 2.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CompanyClient = CompanyClient;
exports.GetPlatformCompanyStateError = exports.GetB2bBusinessInfosError = void 0;
var _CompanyError = require("./CompanyError.cjs");
var _client = require("../../../client.cjs");
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": _client.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": _client.USER_AGENT
}
});
if (!response.ok) {
throw new GetPlatformCompanyStateError(await response.json());
}
return response.json();
}
};
}
class GetB2bBusinessInfosError extends _CompanyError.CompanyError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetB2bBusinessInfosError.prototype);
this.name = "GetB2bBusinessInfosError";
}
}
exports.GetB2bBusinessInfosError = GetB2bBusinessInfosError;
class GetPlatformCompanyStateError extends _CompanyError.CompanyError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformCompanyStateError.prototype);
this.name = "GetPlatformCompanyStateError";
}
}
exports.GetPlatformCompanyStateError = GetPlatformCompanyStateError;