@portone/server-sdk
Version:
PortOne JavaScript SDK for server-side usage
693 lines (692 loc) • 20.9 kB
JavaScript
import { PlatformError } from "./PlatformError.mjs";
import { USER_AGENT } from "../../client.mjs";
import { CompanyClient } from "./company/client.mjs";
import { AccountTransferClient } from "./accountTransfer/client.mjs";
import { PolicyClient } from "./policy/client.mjs";
import { AccountClient } from "./account/client.mjs";
import { BulkPayoutClient } from "./bulkPayout/client.mjs";
import { PartnerSettlementClient } from "./partnerSettlement/client.mjs";
import { PartnerClient } from "./partner/client.mjs";
import { PayoutClient } from "./payout/client.mjs";
import { TransferClient } from "./transfer/client.mjs";
export function PlatformClient(init) {
const baseUrl = init.baseUrl ?? "https://api.portone.io";
const secret = init.secret;
return {
getPlatform: async (options) => {
const response = await fetch(
new URL("/platform", baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformError(await response.json());
}
return response.json();
},
getPlatformAdditionalFeePolicySchedule: async (options) => {
const {
id
} = options;
const response = await fetch(
new URL(`/platform/additional-fee-policies/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformAdditionalFeePolicyScheduleError(await response.json());
}
return response.json();
},
rescheduleAdditionalFeePolicy: async (options) => {
const {
id,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
update,
appliedAt
});
const response = await fetch(
new URL(`/platform/additional-fee-policies/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "PUT",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new RescheduleAdditionalFeePolicyError(await response.json());
}
return response.json();
},
scheduleAdditionalFeePolicy: async (options) => {
const {
id,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
update,
appliedAt
});
const response = await fetch(
new URL(`/platform/additional-fee-policies/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "POST",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new ScheduleAdditionalFeePolicyError(await response.json());
}
return response.json();
},
cancelPlatformAdditionalFeePolicySchedule: async (options) => {
const {
id
} = options;
const response = await fetch(
new URL(`/platform/additional-fee-policies/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "DELETE",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new CancelPlatformAdditionalFeePolicyScheduleError(await response.json());
}
return response.json();
},
getPlatformContractSchedule: async (options) => {
const {
id
} = options;
const response = await fetch(
new URL(`/platform/contracts/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformContractScheduleError(await response.json());
}
return response.json();
},
rescheduleContract: async (options) => {
const {
id,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
update,
appliedAt
});
const response = await fetch(
new URL(`/platform/contracts/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "PUT",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new RescheduleContractError(await response.json());
}
return response.json();
},
scheduleContract: async (options) => {
const {
id,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
update,
appliedAt
});
const response = await fetch(
new URL(`/platform/contracts/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "POST",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new ScheduleContractError(await response.json());
}
return response.json();
},
cancelPlatformContractSchedule: async (options) => {
const {
id
} = options;
const response = await fetch(
new URL(`/platform/contracts/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "DELETE",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new CancelPlatformContractScheduleError(await response.json());
}
return response.json();
},
getPlatformDiscountSharePolicySchedule: async (options) => {
const {
id
} = options;
const response = await fetch(
new URL(`/platform/discount-share-policies/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformDiscountSharePolicyScheduleError(await response.json());
}
return response.json();
},
rescheduleDiscountSharePolicy: async (options) => {
const {
id,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
update,
appliedAt
});
const response = await fetch(
new URL(`/platform/discount-share-policies/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "PUT",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new RescheduleDiscountSharePolicyError(await response.json());
}
return response.json();
},
scheduleDiscountSharePolicy: async (options) => {
const {
id,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
update,
appliedAt
});
const response = await fetch(
new URL(`/platform/discount-share-policies/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "POST",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new ScheduleDiscountSharePolicyError(await response.json());
}
return response.json();
},
cancelPlatformDiscountSharePolicySchedule: async (options) => {
const {
id
} = options;
const response = await fetch(
new URL(`/platform/discount-share-policies/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "DELETE",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new CancelPlatformDiscountSharePolicyScheduleError(await response.json());
}
return response.json();
},
getPlatformDiscountSharePolicyFilterOptions: async (options) => {
const isArchived = options?.isArchived;
const query = [
["isArchived", isArchived]
].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&");
const response = await fetch(
new URL(`/platform/discount-share-policy-filter-options?${query}`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformDiscountSharePolicyFilterOptionsError(await response.json());
}
return response.json();
},
getPlatformPartnerFilterOptions: async (options) => {
const isArchived = options?.isArchived;
const query = [
["isArchived", isArchived]
].flatMap(([key, value]) => value == null ? [] : `${key}=${encodeURIComponent(value)}`).join("&");
const response = await fetch(
new URL(`/platform/partner-filter-options?${query}`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformPartnerFilterOptionsError(await response.json());
}
return response.json();
},
schedulePlatformPartners: async (options) => {
const {
filter,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
filter,
update,
appliedAt
});
const response = await fetch(
new URL("/platform/partners/schedule", baseUrl),
{
method: "POST",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new SchedulePlatformPartnersError(await response.json());
}
return response.json();
},
getPlatformPartnerSchedule: async (options) => {
const {
id
} = options;
const response = await fetch(
new URL(`/platform/partners/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformPartnerScheduleError(await response.json());
}
return response.json();
},
reschedulePartner: async (options) => {
const {
id,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
update,
appliedAt
});
const response = await fetch(
new URL(`/platform/partners/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "PUT",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new ReschedulePartnerError(await response.json());
}
return response.json();
},
schedulePartner: async (options) => {
const {
id,
update,
appliedAt
} = options;
const requestBody = JSON.stringify({
update,
appliedAt
});
const response = await fetch(
new URL(`/platform/partners/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "POST",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new SchedulePartnerError(await response.json());
}
return response.json();
},
cancelPlatformPartnerSchedule: async (options) => {
const {
id
} = options;
const response = await fetch(
new URL(`/platform/partners/${encodeURIComponent(id)}/schedule`, baseUrl),
{
method: "DELETE",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new CancelPlatformPartnerScheduleError(await response.json());
}
return response.json();
},
getPlatformSetting: async (options) => {
const response = await fetch(
new URL("/platform/setting", baseUrl),
{
method: "GET",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
}
}
);
if (!response.ok) {
throw new GetPlatformSettingError(await response.json());
}
return response.json();
},
updatePlatformSetting: async (options) => {
const defaultWithdrawalMemo = options?.defaultWithdrawalMemo;
const defaultDepositMemo = options?.defaultDepositMemo;
const supportsMultipleOrderTransfersPerPartner = options?.supportsMultipleOrderTransfersPerPartner;
const adjustSettlementDateAfterHolidayIfEarlier = options?.adjustSettlementDateAfterHolidayIfEarlier;
const deductWht = options?.deductWht;
const settlementAmountType = options?.settlementAmountType;
const requestBody = JSON.stringify({
defaultWithdrawalMemo,
defaultDepositMemo,
supportsMultipleOrderTransfersPerPartner,
adjustSettlementDateAfterHolidayIfEarlier,
deductWht,
settlementAmountType
});
const response = await fetch(
new URL("/platform/setting", baseUrl),
{
method: "PATCH",
headers: {
Authorization: `PortOne ${secret}`,
"User-Agent": USER_AGENT
},
body: requestBody
}
);
if (!response.ok) {
throw new UpdatePlatformSettingError(await response.json());
}
return response.json();
},
company: CompanyClient(init),
accountTransfer: AccountTransferClient(init),
policy: PolicyClient(init),
account: AccountClient(init),
bulkPayout: BulkPayoutClient(init),
partnerSettlement: PartnerSettlementClient(init),
partner: PartnerClient(init),
payout: PayoutClient(init),
transfer: TransferClient(init)
};
}
export class GetPlatformError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformError.prototype);
this.name = "GetPlatformError";
}
}
export class GetPlatformAdditionalFeePolicyScheduleError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformAdditionalFeePolicyScheduleError.prototype);
this.name = "GetPlatformAdditionalFeePolicyScheduleError";
}
}
export class RescheduleAdditionalFeePolicyError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, RescheduleAdditionalFeePolicyError.prototype);
this.name = "RescheduleAdditionalFeePolicyError";
}
}
export class ScheduleAdditionalFeePolicyError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, ScheduleAdditionalFeePolicyError.prototype);
this.name = "ScheduleAdditionalFeePolicyError";
}
}
export class CancelPlatformAdditionalFeePolicyScheduleError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, CancelPlatformAdditionalFeePolicyScheduleError.prototype);
this.name = "CancelPlatformAdditionalFeePolicyScheduleError";
}
}
export class GetPlatformContractScheduleError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformContractScheduleError.prototype);
this.name = "GetPlatformContractScheduleError";
}
}
export class RescheduleContractError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, RescheduleContractError.prototype);
this.name = "RescheduleContractError";
}
}
export class ScheduleContractError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, ScheduleContractError.prototype);
this.name = "ScheduleContractError";
}
}
export class CancelPlatformContractScheduleError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, CancelPlatformContractScheduleError.prototype);
this.name = "CancelPlatformContractScheduleError";
}
}
export class GetPlatformDiscountSharePolicyScheduleError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformDiscountSharePolicyScheduleError.prototype);
this.name = "GetPlatformDiscountSharePolicyScheduleError";
}
}
export class RescheduleDiscountSharePolicyError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, RescheduleDiscountSharePolicyError.prototype);
this.name = "RescheduleDiscountSharePolicyError";
}
}
export class ScheduleDiscountSharePolicyError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, ScheduleDiscountSharePolicyError.prototype);
this.name = "ScheduleDiscountSharePolicyError";
}
}
export class CancelPlatformDiscountSharePolicyScheduleError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, CancelPlatformDiscountSharePolicyScheduleError.prototype);
this.name = "CancelPlatformDiscountSharePolicyScheduleError";
}
}
export class GetPlatformDiscountSharePolicyFilterOptionsError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformDiscountSharePolicyFilterOptionsError.prototype);
this.name = "GetPlatformDiscountSharePolicyFilterOptionsError";
}
}
export class GetPlatformPartnerFilterOptionsError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformPartnerFilterOptionsError.prototype);
this.name = "GetPlatformPartnerFilterOptionsError";
}
}
export class SchedulePlatformPartnersError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, SchedulePlatformPartnersError.prototype);
this.name = "SchedulePlatformPartnersError";
}
}
export class GetPlatformPartnerScheduleError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformPartnerScheduleError.prototype);
this.name = "GetPlatformPartnerScheduleError";
}
}
export class ReschedulePartnerError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, ReschedulePartnerError.prototype);
this.name = "ReschedulePartnerError";
}
}
export class SchedulePartnerError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, SchedulePartnerError.prototype);
this.name = "SchedulePartnerError";
}
}
export class CancelPlatformPartnerScheduleError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, CancelPlatformPartnerScheduleError.prototype);
this.name = "CancelPlatformPartnerScheduleError";
}
}
export class GetPlatformSettingError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, GetPlatformSettingError.prototype);
this.name = "GetPlatformSettingError";
}
}
export class UpdatePlatformSettingError extends PlatformError {
/** @ignore */
constructor(data) {
super(data);
Object.setPrototypeOf(this, UpdatePlatformSettingError.prototype);
this.name = "UpdatePlatformSettingError";
}
}