@commercelayer/provisioning-sdk 2.10.2 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/lib/actions.cjs +4 -0
- package/lib/actions.cjs.map +1 -0
- package/lib/actions.d.cts +15 -0
- package/lib/actions.d.ts +15 -0
- package/lib/actions.js +3 -0
- package/lib/actions.js.map +1 -0
- package/lib/{index.d.mts → api-BQ6Y-J8P.d.ts} +546 -495
- package/lib/api-BQZ9r4RA.d.cts +1643 -0
- package/lib/api.cjs +62 -0
- package/lib/api.cjs.map +1 -0
- package/lib/api.d.cts +2 -0
- package/lib/api.d.ts +2 -0
- package/lib/api.js +17 -0
- package/lib/api.js.map +1 -0
- package/lib/binding.cjs +14 -0
- package/lib/binding.cjs.map +1 -0
- package/lib/binding.d.cts +21 -0
- package/lib/binding.d.ts +21 -0
- package/lib/binding.js +5 -0
- package/lib/binding.js.map +1 -0
- package/lib/bundle.cjs +34 -0
- package/lib/bundle.cjs.map +1 -0
- package/lib/bundle.d.cts +27 -0
- package/lib/bundle.d.ts +25 -0
- package/lib/bundle.js +19 -0
- package/lib/bundle.js.map +1 -0
- package/lib/chunk-47HG76BX.cjs +19 -0
- package/lib/chunk-47HG76BX.cjs.map +1 -0
- package/lib/chunk-4GOUGGBM.js +114 -0
- package/lib/chunk-4GOUGGBM.js.map +1 -0
- package/lib/chunk-5D5YOHG4.cjs +93 -0
- package/lib/chunk-5D5YOHG4.cjs.map +1 -0
- package/lib/chunk-6B2AFMGT.js +82 -0
- package/lib/chunk-6B2AFMGT.js.map +1 -0
- package/lib/chunk-BFXJ3YNR.js +57 -0
- package/lib/chunk-BFXJ3YNR.js.map +1 -0
- package/lib/chunk-BI4FXO5V.cjs +43 -0
- package/lib/chunk-BI4FXO5V.cjs.map +1 -0
- package/lib/chunk-CESAPW7Z.js +90 -0
- package/lib/chunk-CESAPW7Z.js.map +1 -0
- package/lib/chunk-F2Z6XJTZ.js +59 -0
- package/lib/chunk-F2Z6XJTZ.js.map +1 -0
- package/lib/chunk-FHXWFSIQ.cjs +88 -0
- package/lib/chunk-FHXWFSIQ.cjs.map +1 -0
- package/lib/chunk-HNSO4ZPF.js +808 -0
- package/lib/chunk-HNSO4ZPF.js.map +1 -0
- package/lib/chunk-IW2T22VR.js +3 -0
- package/lib/chunk-IW2T22VR.js.map +1 -0
- package/lib/chunk-JDXNOZFC.cjs +66 -0
- package/lib/chunk-JDXNOZFC.cjs.map +1 -0
- package/lib/chunk-KJRFIWHK.cjs +61 -0
- package/lib/chunk-KJRFIWHK.cjs.map +1 -0
- package/lib/chunk-LISATEFD.cjs +26 -0
- package/lib/chunk-LISATEFD.cjs.map +1 -0
- package/lib/chunk-MANW7JPJ.js +12 -0
- package/lib/chunk-MANW7JPJ.js.map +1 -0
- package/lib/chunk-N567T7FT.cjs +4 -0
- package/lib/chunk-N567T7FT.cjs.map +1 -0
- package/lib/chunk-NFF6DWKZ.cjs +32 -0
- package/lib/chunk-NFF6DWKZ.cjs.map +1 -0
- package/lib/chunk-O6ACW64H.js +30 -0
- package/lib/chunk-O6ACW64H.js.map +1 -0
- package/lib/chunk-OAXFNHFA.js +59 -0
- package/lib/chunk-OAXFNHFA.js.map +1 -0
- package/lib/chunk-OEYUWL5K.js +41 -0
- package/lib/chunk-OEYUWL5K.js.map +1 -0
- package/lib/chunk-OKBMV3W5.cjs +59 -0
- package/lib/chunk-OKBMV3W5.cjs.map +1 -0
- package/lib/chunk-PIDJDUN3.js +86 -0
- package/lib/chunk-PIDJDUN3.js.map +1 -0
- package/lib/chunk-QRMCUYRK.js +24 -0
- package/lib/chunk-QRMCUYRK.js.map +1 -0
- package/lib/chunk-QTTL5EGB.cjs +816 -0
- package/lib/chunk-QTTL5EGB.cjs.map +1 -0
- package/lib/chunk-QVV2ORWB.cjs +61 -0
- package/lib/chunk-QVV2ORWB.cjs.map +1 -0
- package/lib/chunk-RSAADRRH.cjs +84 -0
- package/lib/chunk-RSAADRRH.cjs.map +1 -0
- package/lib/chunk-SZSANTXM.cjs +118 -0
- package/lib/chunk-SZSANTXM.cjs.map +1 -0
- package/lib/chunk-TOXS3OUT.cjs +80 -0
- package/lib/chunk-TOXS3OUT.cjs.map +1 -0
- package/lib/chunk-U76G3DPW.js +64 -0
- package/lib/chunk-U76G3DPW.js.map +1 -0
- package/lib/chunk-VFTFSHXQ.cjs +88 -0
- package/lib/chunk-VFTFSHXQ.cjs.map +1 -0
- package/lib/chunk-XCKSYX22.js +78 -0
- package/lib/chunk-XCKSYX22.js.map +1 -0
- package/lib/chunk-XV25RH6C.js +17 -0
- package/lib/chunk-XV25RH6C.js.map +1 -0
- package/lib/chunk-YFZRO7OE.cjs +84 -0
- package/lib/chunk-YFZRO7OE.cjs.map +1 -0
- package/lib/chunk-YLA6YCK5.cjs +16 -0
- package/lib/chunk-YLA6YCK5.cjs.map +1 -0
- package/lib/chunk-YS5PCY5D.js +76 -0
- package/lib/chunk-YS5PCY5D.js.map +1 -0
- package/lib/chunk-ZTAL3U2D.js +82 -0
- package/lib/chunk-ZTAL3U2D.js.map +1 -0
- package/lib/commercelayer.cjs +38 -0
- package/lib/commercelayer.cjs.map +1 -0
- package/lib/commercelayer.d.cts +58 -0
- package/lib/commercelayer.d.ts +56 -0
- package/lib/commercelayer.js +7 -0
- package/lib/commercelayer.js.map +1 -0
- package/lib/enum.cjs +52 -0
- package/lib/enum.cjs.map +1 -0
- package/lib/enum.d.cts +2 -0
- package/lib/enum.d.ts +2 -0
- package/lib/enum.js +3 -0
- package/lib/enum.js.map +1 -0
- package/lib/error-CVRdwnY9.d.cts +33 -0
- package/lib/error-CVRdwnY9.d.ts +33 -0
- package/lib/index.cjs +57 -0
- package/lib/index.cjs.map +1 -0
- package/lib/index.d.cts +14 -0
- package/lib/index.d.ts +9 -1591
- package/lib/index.js +26 -1
- package/lib/index.js.map +1 -0
- package/lib/model.cjs +4 -0
- package/lib/model.cjs.map +1 -0
- package/lib/model.d.cts +2 -0
- package/lib/model.d.ts +2 -0
- package/lib/model.js +3 -0
- package/lib/model.js.map +1 -0
- package/lib/resources/api_credentials.cjs +15 -0
- package/lib/resources/api_credentials.cjs.map +1 -0
- package/lib/resources/api_credentials.d.cts +5 -0
- package/lib/resources/api_credentials.d.ts +2 -0
- package/lib/resources/api_credentials.js +7 -0
- package/lib/resources/api_credentials.js.map +1 -0
- package/lib/resources/application_memberships.cjs +15 -0
- package/lib/resources/application_memberships.cjs.map +1 -0
- package/lib/resources/application_memberships.d.cts +5 -0
- package/lib/resources/application_memberships.d.ts +2 -0
- package/lib/resources/application_memberships.js +7 -0
- package/lib/resources/application_memberships.js.map +1 -0
- package/lib/resources/identity_providers.cjs +15 -0
- package/lib/resources/identity_providers.cjs.map +1 -0
- package/lib/resources/identity_providers.d.cts +5 -0
- package/lib/resources/identity_providers.d.ts +2 -0
- package/lib/resources/identity_providers.js +7 -0
- package/lib/resources/identity_providers.js.map +1 -0
- package/lib/resources/membership_profiles.cjs +15 -0
- package/lib/resources/membership_profiles.cjs.map +1 -0
- package/lib/resources/membership_profiles.d.cts +5 -0
- package/lib/resources/membership_profiles.d.ts +2 -0
- package/lib/resources/membership_profiles.js +7 -0
- package/lib/resources/membership_profiles.js.map +1 -0
- package/lib/resources/memberships.cjs +15 -0
- package/lib/resources/memberships.cjs.map +1 -0
- package/lib/resources/memberships.d.cts +5 -0
- package/lib/resources/memberships.d.ts +2 -0
- package/lib/resources/memberships.js +7 -0
- package/lib/resources/memberships.js.map +1 -0
- package/lib/resources/organizations.cjs +15 -0
- package/lib/resources/organizations.cjs.map +1 -0
- package/lib/resources/organizations.d.cts +5 -0
- package/lib/resources/organizations.d.ts +2 -0
- package/lib/resources/organizations.js +7 -0
- package/lib/resources/organizations.js.map +1 -0
- package/lib/resources/permissions.cjs +15 -0
- package/lib/resources/permissions.cjs.map +1 -0
- package/lib/resources/permissions.d.cts +5 -0
- package/lib/resources/permissions.d.ts +2 -0
- package/lib/resources/permissions.js +7 -0
- package/lib/resources/permissions.js.map +1 -0
- package/lib/resources/roles.cjs +15 -0
- package/lib/resources/roles.cjs.map +1 -0
- package/lib/resources/roles.d.cts +5 -0
- package/lib/resources/roles.d.ts +2 -0
- package/lib/resources/roles.js +7 -0
- package/lib/resources/roles.js.map +1 -0
- package/lib/resources/users.cjs +15 -0
- package/lib/resources/users.cjs.map +1 -0
- package/lib/resources/users.d.cts +5 -0
- package/lib/resources/users.d.ts +2 -0
- package/lib/resources/users.js +7 -0
- package/lib/resources/users.js.map +1 -0
- package/lib/resources/versions.cjs +15 -0
- package/lib/resources/versions.cjs.map +1 -0
- package/lib/resources/versions.d.cts +5 -0
- package/lib/resources/versions.d.ts +2 -0
- package/lib/resources/versions.js +7 -0
- package/lib/resources/versions.js.map +1 -0
- package/lib/static.cjs +17 -0
- package/lib/static.cjs.map +1 -0
- package/lib/static.d.cts +18 -0
- package/lib/static.d.ts +18 -0
- package/lib/static.js +8 -0
- package/lib/static.js.map +1 -0
- package/lib/version.cjs +20 -0
- package/lib/version.cjs.map +1 -0
- package/lib/version.d.cts +12 -0
- package/lib/version.d.ts +12 -0
- package/lib/version.js +3 -0
- package/lib/version.js.map +1 -0
- package/package.json +36 -26
- package/lib/index.mjs +0 -1
|
@@ -0,0 +1,816 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk47HG76BX_cjs = require('./chunk-47HG76BX.cjs');
|
|
4
|
+
|
|
5
|
+
// ../sdk-runtime/src/debug.ts
|
|
6
|
+
var PREFIX = "clsdk";
|
|
7
|
+
var debugEnv = () => {
|
|
8
|
+
try {
|
|
9
|
+
return typeof process !== "undefined" ? process.env?.DEBUG ?? "" : "";
|
|
10
|
+
} catch {
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var toMatcher = (pattern) => new RegExp(`^${pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`);
|
|
15
|
+
var isEnabled = (namespace) => {
|
|
16
|
+
const env = debugEnv();
|
|
17
|
+
if (!env) return false;
|
|
18
|
+
return env.split(",").map((p) => p.trim()).filter(Boolean).some((p) => toMatcher(p).test(namespace));
|
|
19
|
+
};
|
|
20
|
+
var interpolate = (pattern, args) => {
|
|
21
|
+
let i = 0;
|
|
22
|
+
const out = pattern.replace(/%[oOjsdi%]/g, (token) => {
|
|
23
|
+
if (token === "%%") return "%";
|
|
24
|
+
if (i >= args.length) return token;
|
|
25
|
+
const arg = args[i++];
|
|
26
|
+
switch (token) {
|
|
27
|
+
case "%s":
|
|
28
|
+
return String(arg);
|
|
29
|
+
case "%d":
|
|
30
|
+
case "%i":
|
|
31
|
+
return String(Number(arg));
|
|
32
|
+
default:
|
|
33
|
+
try {
|
|
34
|
+
return JSON.stringify(arg);
|
|
35
|
+
} catch {
|
|
36
|
+
return String(arg);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const rest = args.slice(i);
|
|
41
|
+
return rest.length > 0 ? `${out} ${rest.map((a) => safeStringify(a)).join(" ")}` : out;
|
|
42
|
+
};
|
|
43
|
+
var safeStringify = (value) => {
|
|
44
|
+
if (typeof value === "string") return value;
|
|
45
|
+
try {
|
|
46
|
+
return JSON.stringify(value) ?? String(value);
|
|
47
|
+
} catch {
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var debug = (namespace) => {
|
|
52
|
+
const full = `${PREFIX}:${namespace}`;
|
|
53
|
+
return (pattern, ...args) => {
|
|
54
|
+
if (!isEnabled(full)) return;
|
|
55
|
+
console.error(`${full} ${interpolate(pattern, args)}`);
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
var debug_default = debug;
|
|
59
|
+
|
|
60
|
+
// ../sdk-runtime/src/fetch.ts
|
|
61
|
+
var debug2 = debug_default("fetch");
|
|
62
|
+
var FetchError = class _FetchError extends Error {
|
|
63
|
+
static NAME = "FetchError";
|
|
64
|
+
static isFetchError = (error) => {
|
|
65
|
+
return error instanceof _FetchError;
|
|
66
|
+
};
|
|
67
|
+
#errors;
|
|
68
|
+
#status;
|
|
69
|
+
#statusText;
|
|
70
|
+
#request;
|
|
71
|
+
constructor(status, statusText, body, request) {
|
|
72
|
+
super(statusText);
|
|
73
|
+
this.#status = status;
|
|
74
|
+
this.#statusText = statusText;
|
|
75
|
+
if (body) this.#errors = body.errors;
|
|
76
|
+
if (request) this.#request = request;
|
|
77
|
+
this.name = _FetchError.NAME;
|
|
78
|
+
}
|
|
79
|
+
get errors() {
|
|
80
|
+
return this.#errors;
|
|
81
|
+
}
|
|
82
|
+
get status() {
|
|
83
|
+
return this.#status;
|
|
84
|
+
}
|
|
85
|
+
get statusText() {
|
|
86
|
+
return this.#statusText;
|
|
87
|
+
}
|
|
88
|
+
get request() {
|
|
89
|
+
return this.#request;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var fetchURL = async (url, requestOptions, clientOptions) => {
|
|
93
|
+
debug2("fetch: %s, %O, native[%s]", url, requestOptions || {}, clientOptions?.fetch ? "no" : "yes");
|
|
94
|
+
const interceptors = clientOptions?.interceptors;
|
|
95
|
+
if (interceptors?.request?.onSuccess)
|
|
96
|
+
({ url, options: requestOptions } = await interceptors.request.onSuccess({ url, options: requestOptions }));
|
|
97
|
+
const fetchClient = clientOptions?.fetch || fetch;
|
|
98
|
+
let response = await fetchClient(url, requestOptions);
|
|
99
|
+
if (response.ok) {
|
|
100
|
+
if (interceptors?.rawReader?.onSuccess) await interceptors.rawReader.onSuccess(response);
|
|
101
|
+
if (interceptors?.response?.onSuccess) response = await interceptors.response.onSuccess(response);
|
|
102
|
+
} else {
|
|
103
|
+
if (interceptors?.rawReader?.onFailure) await interceptors.rawReader.onFailure(response);
|
|
104
|
+
}
|
|
105
|
+
const responseBody = response.body && response.status !== 204 ? await response.json().then((json) => {
|
|
106
|
+
debug2("response: %O", json);
|
|
107
|
+
return json;
|
|
108
|
+
}).catch((err) => {
|
|
109
|
+
debug2("error: %s", err.message);
|
|
110
|
+
if (response.ok) throw new SdkError({ message: "Error parsing API response body", type: "parse" /* PARSE */ });
|
|
111
|
+
}) : void 0;
|
|
112
|
+
if (!response.ok) {
|
|
113
|
+
let error = new FetchError(response.status, response.statusText, responseBody, requestOptions);
|
|
114
|
+
if (interceptors?.response?.onFailure) error = await interceptors.response.onFailure(error);
|
|
115
|
+
if (error) throw error;
|
|
116
|
+
}
|
|
117
|
+
return responseBody;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// ../sdk-runtime/src/error.ts
|
|
121
|
+
var ErrorType = /* @__PURE__ */ ((ErrorType2) => {
|
|
122
|
+
ErrorType2["CLIENT"] = "client";
|
|
123
|
+
ErrorType2["REQUEST"] = "request";
|
|
124
|
+
ErrorType2["RESPONSE"] = "response";
|
|
125
|
+
ErrorType2["CANCEL"] = "cancel";
|
|
126
|
+
ErrorType2["PARSE"] = "parse";
|
|
127
|
+
ErrorType2["TIMEOUT"] = "timeout";
|
|
128
|
+
ErrorType2["TOKEN_REFRESH"] = "token-refresh";
|
|
129
|
+
return ErrorType2;
|
|
130
|
+
})(ErrorType || {});
|
|
131
|
+
var SdkError = class _SdkError extends Error {
|
|
132
|
+
static NAME = "SdkError";
|
|
133
|
+
static isSdkError(error) {
|
|
134
|
+
return error && [_SdkError.NAME, ApiError.NAME].includes(error.name) && Object.values(ErrorType).includes(error.type);
|
|
135
|
+
}
|
|
136
|
+
type;
|
|
137
|
+
code;
|
|
138
|
+
source;
|
|
139
|
+
constructor(error) {
|
|
140
|
+
super(error.message);
|
|
141
|
+
this.name = _SdkError.NAME;
|
|
142
|
+
this.type = error.type || "client" /* CLIENT */;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var ApiError = class _ApiError extends SdkError {
|
|
146
|
+
static NAME = "ApiError";
|
|
147
|
+
static isApiError(error) {
|
|
148
|
+
return SdkError.isSdkError(error) && error.name === _ApiError.NAME && error.type === "response" /* RESPONSE */;
|
|
149
|
+
}
|
|
150
|
+
errors = [];
|
|
151
|
+
status;
|
|
152
|
+
statusText;
|
|
153
|
+
// constructor(error: SdkError)
|
|
154
|
+
constructor(error) {
|
|
155
|
+
super({ ...error, type: "response" /* RESPONSE */ });
|
|
156
|
+
this.name = _ApiError.NAME;
|
|
157
|
+
}
|
|
158
|
+
first() {
|
|
159
|
+
return this.errors?.length > 0 ? this.errors[0] : void 0;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var isRequestError = (error) => {
|
|
163
|
+
return error instanceof TypeError && error.message !== "fetch failed";
|
|
164
|
+
};
|
|
165
|
+
var isCancelError = (error) => {
|
|
166
|
+
return error instanceof DOMException && error.name === "AbortError";
|
|
167
|
+
};
|
|
168
|
+
var isTimeoutError = (error) => {
|
|
169
|
+
return error instanceof DOMException && error.name === "TimeoutError";
|
|
170
|
+
};
|
|
171
|
+
var isExpiredTokenError = (error) => {
|
|
172
|
+
const invalidTokenCodes = [
|
|
173
|
+
"INVALID_TOKEN"
|
|
174
|
+
/*, 'UNAUTHORIZED' */
|
|
175
|
+
];
|
|
176
|
+
return ApiError.isApiError(error) && error.status === 401 && (invalidTokenCodes.includes(error.code || "") || error.errors && error.errors.length > 0 && invalidTokenCodes.includes(error.errors[0].code));
|
|
177
|
+
};
|
|
178
|
+
var handleError = (error) => {
|
|
179
|
+
if (SdkError.isSdkError(error) || ApiError.isApiError(error)) throw error;
|
|
180
|
+
let sdkError = new SdkError({ message: error.message });
|
|
181
|
+
if (FetchError.isFetchError(error)) {
|
|
182
|
+
const apiError = new ApiError(sdkError);
|
|
183
|
+
apiError.type = "response" /* RESPONSE */;
|
|
184
|
+
apiError.status = error.status;
|
|
185
|
+
apiError.statusText = error.statusText;
|
|
186
|
+
apiError.code = String(apiError.status);
|
|
187
|
+
apiError.errors = error.errors || [];
|
|
188
|
+
if (!apiError.message && apiError.statusText) apiError.message = apiError.statusText;
|
|
189
|
+
sdkError = apiError;
|
|
190
|
+
} else if (isRequestError(error)) {
|
|
191
|
+
sdkError.type = "request" /* REQUEST */;
|
|
192
|
+
} else if (isCancelError(error)) {
|
|
193
|
+
sdkError.type = "cancel" /* CANCEL */;
|
|
194
|
+
} else if (isTimeoutError(error)) {
|
|
195
|
+
sdkError.type = "timeout" /* TIMEOUT */;
|
|
196
|
+
} else {
|
|
197
|
+
sdkError.type = "client" /* CLIENT */;
|
|
198
|
+
sdkError.source = error;
|
|
199
|
+
}
|
|
200
|
+
throw sdkError;
|
|
201
|
+
};
|
|
202
|
+
function isSdkError(error) {
|
|
203
|
+
return SdkError.isSdkError(error);
|
|
204
|
+
}
|
|
205
|
+
function isApiError(error) {
|
|
206
|
+
return ApiError.isApiError(error);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ../sdk-runtime/src/util.ts
|
|
210
|
+
var extractTokenData = (token) => {
|
|
211
|
+
try {
|
|
212
|
+
const data = JSON.parse(atob(token.split(".")[1]));
|
|
213
|
+
return {
|
|
214
|
+
organization: data.organization.slug,
|
|
215
|
+
domain: data.iss ? String(data.iss).replace("https://auth.", "") : void 0,
|
|
216
|
+
expiration: data.exp
|
|
217
|
+
};
|
|
218
|
+
} catch (_err) {
|
|
219
|
+
return void 0;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var isTokenExpired = (token) => {
|
|
223
|
+
try {
|
|
224
|
+
const tokenData = extractTokenData(token);
|
|
225
|
+
return tokenData?.expiration ? tokenData.expiration * 1e3 - Date.now() < 0 : false;
|
|
226
|
+
} catch (_err) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// ../sdk-runtime/src/config.ts
|
|
232
|
+
var config = {
|
|
233
|
+
default: {
|
|
234
|
+
domain: "commercelayer.io",
|
|
235
|
+
pageNumber: 1,
|
|
236
|
+
pageSize: 10
|
|
237
|
+
},
|
|
238
|
+
client: {
|
|
239
|
+
timeout: 15e3,
|
|
240
|
+
requiredAttributes: ["organization", "accessToken"]
|
|
241
|
+
},
|
|
242
|
+
jsonapi: {
|
|
243
|
+
maxResourceIncluded: 2
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
var config_default = config;
|
|
247
|
+
|
|
248
|
+
// ../sdk-runtime/src/client.ts
|
|
249
|
+
var CLIENT_HEADER_NAME = "X-CL-SDK";
|
|
250
|
+
var debug3 = debug_default("client");
|
|
251
|
+
var baseURL = (organization, domain, apiVersion) => {
|
|
252
|
+
const versionSegment = apiVersion ? `/${apiVersion}` : "";
|
|
253
|
+
const subdomain = chunk47HG76BX_cjs.binding.subdomain ?? organization.toLowerCase();
|
|
254
|
+
return `https://${subdomain}.${domain || config_default.default.domain}/api${versionSegment}`;
|
|
255
|
+
};
|
|
256
|
+
var ApiClient = class _ApiClient {
|
|
257
|
+
static create(options) {
|
|
258
|
+
if ((!options.organization || !options.domain) && options.accessToken) {
|
|
259
|
+
const tokenData = extractTokenData(options.accessToken);
|
|
260
|
+
if (!options.organization && tokenData?.organization) options.organization = tokenData.organization;
|
|
261
|
+
if (!options.domain && tokenData?.domain) options.domain = tokenData.domain;
|
|
262
|
+
}
|
|
263
|
+
const required = chunk47HG76BX_cjs.binding.subdomain ? config_default.client.requiredAttributes.filter((a) => a !== "organization") : config_default.client.requiredAttributes;
|
|
264
|
+
for (const attr of required) if (!options[attr]) throw new SdkError({ message: `Undefined '${attr}' parameter` });
|
|
265
|
+
return new _ApiClient(options);
|
|
266
|
+
}
|
|
267
|
+
#baseUrl;
|
|
268
|
+
#accessToken;
|
|
269
|
+
#organization;
|
|
270
|
+
#domain;
|
|
271
|
+
#apiVersion;
|
|
272
|
+
#clientConfig;
|
|
273
|
+
#interceptors;
|
|
274
|
+
constructor(options) {
|
|
275
|
+
debug3("new client instance %O", options);
|
|
276
|
+
this.#apiVersion = options.apiVersion;
|
|
277
|
+
this.#baseUrl = baseURL(options.organization ?? "", options.domain, this.#apiVersion);
|
|
278
|
+
this.#accessToken = options.accessToken;
|
|
279
|
+
this.#organization = options.organization ?? "";
|
|
280
|
+
this.#domain = options.domain;
|
|
281
|
+
const fetchConfig = {
|
|
282
|
+
timeout: options.timeout || config_default.client.timeout,
|
|
283
|
+
fetch: options.fetch,
|
|
284
|
+
refreshToken: options.refreshToken
|
|
285
|
+
};
|
|
286
|
+
const customHeaders = this.customHeaders(options.headers);
|
|
287
|
+
const headers = {
|
|
288
|
+
...customHeaders,
|
|
289
|
+
Accept: "application/vnd.api+json",
|
|
290
|
+
"Content-Type": "application/vnd.api+json",
|
|
291
|
+
Authorization: "Bearer " + this.#accessToken
|
|
292
|
+
};
|
|
293
|
+
if (options.telemetry !== false) headers[CLIENT_HEADER_NAME] = `js/${chunk47HG76BX_cjs.binding.name}-v${chunk47HG76BX_cjs.binding.sdkVersion}`;
|
|
294
|
+
if (options.userAgent) headers["User-Agent"] = options.userAgent;
|
|
295
|
+
fetchConfig.headers = headers;
|
|
296
|
+
this.#clientConfig = fetchConfig;
|
|
297
|
+
debug3("fetch config: %O", fetchConfig);
|
|
298
|
+
this.#interceptors = {};
|
|
299
|
+
}
|
|
300
|
+
get interceptors() {
|
|
301
|
+
return this.#interceptors;
|
|
302
|
+
}
|
|
303
|
+
get requestHeaders() {
|
|
304
|
+
if (!this.#clientConfig.headers) this.#clientConfig.headers = {};
|
|
305
|
+
return this.#clientConfig.headers;
|
|
306
|
+
}
|
|
307
|
+
/*
|
|
308
|
+
set requestHeaders(headers: RequestHeaders) {
|
|
309
|
+
this.#clientConfig.headers = { ...this.#clientConfig.headers, ...headers }
|
|
310
|
+
}
|
|
311
|
+
*/
|
|
312
|
+
config(config2) {
|
|
313
|
+
debug3("config %o", config2);
|
|
314
|
+
const def = this.#clientConfig;
|
|
315
|
+
if (!def.headers) def.headers = {};
|
|
316
|
+
if (config2.timeout) def.timeout = config2.timeout;
|
|
317
|
+
if (config2.userAgent) this.userAgent(config2.userAgent);
|
|
318
|
+
if (config2.fetch) this.#clientConfig.fetch = config2.fetch;
|
|
319
|
+
if (config2.refreshToken) this.#clientConfig.refreshToken = config2.refreshToken;
|
|
320
|
+
if (config2.apiVersion !== void 0) this.#apiVersion = config2.apiVersion;
|
|
321
|
+
if (config2.organization || config2.domain || config2.apiVersion !== void 0)
|
|
322
|
+
this.#baseUrl = baseURL(
|
|
323
|
+
config2.organization || this.#organization,
|
|
324
|
+
config2.domain || this.#domain,
|
|
325
|
+
this.#apiVersion
|
|
326
|
+
);
|
|
327
|
+
if (config2.organization) this.#organization = config2.organization;
|
|
328
|
+
if (config2.domain) this.#domain = config2.domain;
|
|
329
|
+
if (config2.accessToken) {
|
|
330
|
+
this.#accessToken = config2.accessToken;
|
|
331
|
+
def.headers.Authorization = "Bearer " + this.#accessToken;
|
|
332
|
+
}
|
|
333
|
+
if (config2.headers) def.headers = { ...def.headers, ...this.customHeaders(config2.headers) };
|
|
334
|
+
return this;
|
|
335
|
+
}
|
|
336
|
+
userAgent(userAgent) {
|
|
337
|
+
if (userAgent) this.requestHeaders["User-Agent"] = userAgent;
|
|
338
|
+
return this;
|
|
339
|
+
}
|
|
340
|
+
async request(method, path, body, options) {
|
|
341
|
+
debug3("request %s %s, %O, %O", method, path, body || {}, options || {});
|
|
342
|
+
if (options?.userAgent) debug3("User-Agent header ignored in request config");
|
|
343
|
+
const baseUrl = options?.organization || options?.apiVersion !== void 0 ? baseURL(options.organization || this.#organization, options.domain, options.apiVersion ?? this.#apiVersion) : this.#baseUrl;
|
|
344
|
+
const url = new URL(`${baseUrl}/${path}`);
|
|
345
|
+
const bodyData = body ? JSON.stringify({ data: body }) : void 0;
|
|
346
|
+
const headers = { ...this.requestHeaders, ...this.customHeaders(options?.headers) };
|
|
347
|
+
const accessToken = options?.accessToken || this.#accessToken;
|
|
348
|
+
if (accessToken) headers.Authorization = "Bearer " + accessToken;
|
|
349
|
+
const refreshToken = options?.refreshToken || this.#clientConfig.refreshToken;
|
|
350
|
+
const fetchFunction = options?.fetch || this.#clientConfig.fetch;
|
|
351
|
+
const requestOptions = { method, body: bodyData, headers };
|
|
352
|
+
const timeout = options?.timeout || this.#clientConfig.timeout;
|
|
353
|
+
if (timeout) {
|
|
354
|
+
if (AbortSignal?.timeout) requestOptions.signal = AbortSignal.timeout(timeout);
|
|
355
|
+
else debug3("Timeout not set. Undefined function: %s", "AbortSignal.timeout");
|
|
356
|
+
}
|
|
357
|
+
if (options?.params)
|
|
358
|
+
Object.entries(options?.params).forEach(([name, value]) => {
|
|
359
|
+
url.searchParams.append(name, String(value));
|
|
360
|
+
});
|
|
361
|
+
const clientOptions = {
|
|
362
|
+
interceptors: this.interceptors,
|
|
363
|
+
fetch: fetchFunction
|
|
364
|
+
};
|
|
365
|
+
try {
|
|
366
|
+
return await fetchURL(url, requestOptions, clientOptions).catch((error) => handleError(error));
|
|
367
|
+
} catch (err) {
|
|
368
|
+
if (isExpiredTokenError(err) && refreshToken && isTokenExpired(accessToken)) {
|
|
369
|
+
debug3("Access token has expired");
|
|
370
|
+
const newAccessToken = await refreshToken(this.#accessToken).catch((e) => {
|
|
371
|
+
debug3("Refresh token error: %s", e.message);
|
|
372
|
+
const tokenError = new SdkError({ message: "Error refreshing access token", type: "token-refresh" /* TOKEN_REFRESH */ });
|
|
373
|
+
tokenError.source = e;
|
|
374
|
+
throw tokenError;
|
|
375
|
+
});
|
|
376
|
+
if (newAccessToken) {
|
|
377
|
+
debug3("Access token refreshed");
|
|
378
|
+
this.config({ accessToken: newAccessToken });
|
|
379
|
+
this.#accessToken = newAccessToken;
|
|
380
|
+
if (requestOptions.headers)
|
|
381
|
+
requestOptions.headers.Authorization = `Bearer ${newAccessToken}`;
|
|
382
|
+
const response = await fetchURL(url, requestOptions, clientOptions).catch(
|
|
383
|
+
(error) => handleError(error)
|
|
384
|
+
);
|
|
385
|
+
return response;
|
|
386
|
+
}
|
|
387
|
+
} else throw err;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
customHeaders(headers) {
|
|
391
|
+
const customHeaders = {};
|
|
392
|
+
if (headers) {
|
|
393
|
+
for (const [name, value] of Object.entries(headers))
|
|
394
|
+
if (!["accept", "content-type", "authorization", "user-agent", CLIENT_HEADER_NAME.toLowerCase()].includes(
|
|
395
|
+
name.toLowerCase()
|
|
396
|
+
))
|
|
397
|
+
customHeaders[name] = value;
|
|
398
|
+
}
|
|
399
|
+
return customHeaders;
|
|
400
|
+
}
|
|
401
|
+
get currentAccessToken() {
|
|
402
|
+
return this.#accessToken;
|
|
403
|
+
}
|
|
404
|
+
get currentOrganization() {
|
|
405
|
+
return this.#organization;
|
|
406
|
+
}
|
|
407
|
+
/** The API version pinned via `apiVersion`, or `undefined` when requests are unversioned. */
|
|
408
|
+
get currentApiVersion() {
|
|
409
|
+
return this.#apiVersion;
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
var client_default = ApiClient;
|
|
413
|
+
|
|
414
|
+
// ../sdk-runtime/src/jsonapi.ts
|
|
415
|
+
var debug4 = debug_default("jsonapi");
|
|
416
|
+
var denormalize = (response) => {
|
|
417
|
+
if (!response) return response;
|
|
418
|
+
let denormalizedResponse;
|
|
419
|
+
if (response.links) delete response.links;
|
|
420
|
+
const data = response.data;
|
|
421
|
+
const included = response.included;
|
|
422
|
+
if (!data) denormalizedResponse = data;
|
|
423
|
+
else {
|
|
424
|
+
if (Array.isArray(data)) denormalizedResponse = data.map((res) => denormalizeResource(res, included));
|
|
425
|
+
else denormalizedResponse = denormalizeResource(data, included);
|
|
426
|
+
}
|
|
427
|
+
return denormalizedResponse;
|
|
428
|
+
};
|
|
429
|
+
var findIncluded = (rel, included = []) => {
|
|
430
|
+
const inc = included.find((inc2) => {
|
|
431
|
+
return rel.id === inc2.id && rel.type === inc2.type;
|
|
432
|
+
});
|
|
433
|
+
return inc || rel;
|
|
434
|
+
};
|
|
435
|
+
var denormalizeResource = (res, included, chain = []) => {
|
|
436
|
+
debug4("denormalize resource: %O, %o", res, included || {});
|
|
437
|
+
if (!res) return res;
|
|
438
|
+
const resource = {
|
|
439
|
+
id: res.id,
|
|
440
|
+
type: res.type,
|
|
441
|
+
...res.attributes
|
|
442
|
+
};
|
|
443
|
+
if (res.relationships)
|
|
444
|
+
Object.keys(res.relationships).forEach((key) => {
|
|
445
|
+
const rel = res.relationships[key].data;
|
|
446
|
+
if (rel) {
|
|
447
|
+
if (chain.filter((r) => r.id === rel.id && r.type === rel.type).length >= config_default.jsonapi.maxResourceIncluded)
|
|
448
|
+
resource[key] = rel;
|
|
449
|
+
else {
|
|
450
|
+
if (Array.isArray(rel))
|
|
451
|
+
resource[key] = rel.map(
|
|
452
|
+
(r) => denormalizeResource(findIncluded(r, included), included, [...chain, r])
|
|
453
|
+
);
|
|
454
|
+
else resource[key] = denormalizeResource(findIncluded(rel, included), included, [...chain, rel]);
|
|
455
|
+
}
|
|
456
|
+
} else if (rel === null) resource[key] = null;
|
|
457
|
+
});
|
|
458
|
+
debug4("denormalized resource: %O", resource);
|
|
459
|
+
return resource;
|
|
460
|
+
};
|
|
461
|
+
var normalize = (resource) => {
|
|
462
|
+
debug4("normalize resource: %O", resource);
|
|
463
|
+
const attributes = {};
|
|
464
|
+
const relationships = {};
|
|
465
|
+
for (const field in resource) {
|
|
466
|
+
if (["type", "id"].includes(field)) continue;
|
|
467
|
+
const value = resource[field];
|
|
468
|
+
if (Array.isArray(value) && value.length === 1 && isResourceType(value[0]) && value[0].id === null) {
|
|
469
|
+
relationships[field] = { data: [] };
|
|
470
|
+
} else if (value && isResourceType(value) && value.id === null) {
|
|
471
|
+
relationships[field] = { data: null };
|
|
472
|
+
} else if (value && (isResourceId(value) || Array.isArray(value) && isResourceId(value[0]))) {
|
|
473
|
+
relationships[field] = { data: value };
|
|
474
|
+
} else attributes[field] = value;
|
|
475
|
+
}
|
|
476
|
+
const normalized = {
|
|
477
|
+
type: resource.type,
|
|
478
|
+
attributes,
|
|
479
|
+
relationships
|
|
480
|
+
};
|
|
481
|
+
if (isResourceId(resource)) normalized.id = resource.id;
|
|
482
|
+
debug4("normalized resource: %O", normalized);
|
|
483
|
+
return normalized;
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// ../sdk-runtime/src/query.ts
|
|
487
|
+
var debug5 = debug_default("query");
|
|
488
|
+
var arrayFilters = ["_any", "_all", "_in", "_not_in_or_null"];
|
|
489
|
+
var isArrayFilter = (filter) => {
|
|
490
|
+
return arrayFilters.some((f) => filter.endsWith(f));
|
|
491
|
+
};
|
|
492
|
+
var objectFilters = ["_jcont"];
|
|
493
|
+
var isObjectFilter = (filter) => {
|
|
494
|
+
return objectFilters.some((f) => filter.endsWith(f));
|
|
495
|
+
};
|
|
496
|
+
var isParamsList = (params) => {
|
|
497
|
+
return params && (params.filters || params.pageNumber || params.pageSize || params.sort || params.pageAfter || params.pageBefore);
|
|
498
|
+
};
|
|
499
|
+
var generateQueryStringParams = (params, res) => {
|
|
500
|
+
debug5("generate query string params: %O, %O", params, res);
|
|
501
|
+
const qp = {};
|
|
502
|
+
if (!params) return qp;
|
|
503
|
+
if (params.include) qp.include = params.include.join(",");
|
|
504
|
+
if (params.fields) {
|
|
505
|
+
if (Array.isArray(params.fields)) params.fields = { [res.type || res]: params.fields };
|
|
506
|
+
Object.entries(params.fields).forEach(([p, v]) => {
|
|
507
|
+
qp[`fields[${p}]`] = v.join(",");
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
if (isParamsList(params)) {
|
|
511
|
+
if (params.sort) {
|
|
512
|
+
if (Array.isArray(params.sort)) qp.sort = params.sort.join(",");
|
|
513
|
+
else
|
|
514
|
+
qp.sort = Object.entries(params.sort).map(([k, v]) => `${v === "desc" ? "-" : ""}${k}`).join(",");
|
|
515
|
+
}
|
|
516
|
+
if (params.pageNumber) qp["page[number]"] = String(params.pageNumber);
|
|
517
|
+
if (params.pageSize) qp["page[size]"] = String(params.pageSize);
|
|
518
|
+
if (params.pageAfter) qp["page[after]"] = String(params.pageAfter);
|
|
519
|
+
if (params.pageBefore) qp["page[before]"] = String(params.pageBefore);
|
|
520
|
+
if (params.filters) {
|
|
521
|
+
Object.entries(params.filters).forEach(([p, v]) => {
|
|
522
|
+
let val;
|
|
523
|
+
if (Array.isArray(v)) {
|
|
524
|
+
if (!isArrayFilter(p))
|
|
525
|
+
throw new SdkError({
|
|
526
|
+
message: `Incorrect filter [${p}]: Array value is supported only for the following filters: ${arrayFilters.join(", ")}`,
|
|
527
|
+
type: "request" /* REQUEST */
|
|
528
|
+
});
|
|
529
|
+
val = v.join(",");
|
|
530
|
+
} else if (typeof v === "object") {
|
|
531
|
+
if (!isObjectFilter(p))
|
|
532
|
+
throw new SdkError({
|
|
533
|
+
message: `Incorrect filter [${p}]: Object value is supported only for the following filters: ${objectFilters.join(", ")}`,
|
|
534
|
+
type: "request" /* REQUEST */
|
|
535
|
+
});
|
|
536
|
+
val = JSON.stringify(v);
|
|
537
|
+
} else val = String(v);
|
|
538
|
+
qp[`filter[q][${p}]`] = val;
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
debug5("query string params: %O", qp);
|
|
543
|
+
return qp;
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// ../sdk-runtime/src/resource.ts
|
|
547
|
+
var debug6 = debug_default("resource");
|
|
548
|
+
var ListResponse = class extends Array {
|
|
549
|
+
meta;
|
|
550
|
+
constructor(meta, data) {
|
|
551
|
+
super(...data || []);
|
|
552
|
+
this.meta = meta;
|
|
553
|
+
}
|
|
554
|
+
first() {
|
|
555
|
+
return this.length ? this[0] : void 0;
|
|
556
|
+
}
|
|
557
|
+
last() {
|
|
558
|
+
return this.length ? this[this.length - 1] : void 0;
|
|
559
|
+
}
|
|
560
|
+
get(index) {
|
|
561
|
+
return this.length && index >= 0 ? this[index] : void 0;
|
|
562
|
+
}
|
|
563
|
+
hasNextPage() {
|
|
564
|
+
return this.meta.currentPage < this.meta.pageCount;
|
|
565
|
+
}
|
|
566
|
+
hasPrevPage() {
|
|
567
|
+
return this.meta.currentPage > 1;
|
|
568
|
+
}
|
|
569
|
+
getRecordCount() {
|
|
570
|
+
return this.meta.recordCount;
|
|
571
|
+
}
|
|
572
|
+
getPageCount() {
|
|
573
|
+
return this.meta.pageCount;
|
|
574
|
+
}
|
|
575
|
+
get recordCount() {
|
|
576
|
+
return this.meta.recordCount;
|
|
577
|
+
}
|
|
578
|
+
get pageCount() {
|
|
579
|
+
return this.meta.pageCount;
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
var parseCursorLink = (url) => {
|
|
583
|
+
if (!url) return void 0;
|
|
584
|
+
let params;
|
|
585
|
+
try {
|
|
586
|
+
params = new URL(url).searchParams;
|
|
587
|
+
} catch {
|
|
588
|
+
return void 0;
|
|
589
|
+
}
|
|
590
|
+
const after = params.get("page[after]") ?? void 0;
|
|
591
|
+
const before = params.get("page[before]") ?? void 0;
|
|
592
|
+
return after != null || before != null ? { before, after } : void 0;
|
|
593
|
+
};
|
|
594
|
+
var buildListMeta = (res, links, params) => {
|
|
595
|
+
const recordsPerPage = params?.pageSize || config_default.default.pageSize;
|
|
596
|
+
if (res.meta?.page_count == null) {
|
|
597
|
+
return {
|
|
598
|
+
// Offset fields aren't applicable to cursor pagination; kept as NaN so the
|
|
599
|
+
// shared `meta.*` interface still resolves (see ListMeta).
|
|
600
|
+
pageCount: NaN,
|
|
601
|
+
recordCount: NaN,
|
|
602
|
+
currentPage: NaN,
|
|
603
|
+
recordsPerPage,
|
|
604
|
+
cursor: {
|
|
605
|
+
prev: parseCursorLink(links?.prev),
|
|
606
|
+
next: parseCursorLink(links?.next)
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
return {
|
|
611
|
+
pageCount: Number(res.meta?.page_count),
|
|
612
|
+
recordCount: Number(res.meta?.record_count),
|
|
613
|
+
currentPage: params?.pageNumber || config_default.default.pageNumber,
|
|
614
|
+
recordsPerPage
|
|
615
|
+
};
|
|
616
|
+
};
|
|
617
|
+
var ApiResourceAdapter = class _ApiResourceAdapter {
|
|
618
|
+
static adapter;
|
|
619
|
+
constructor() {
|
|
620
|
+
}
|
|
621
|
+
static init(config2) {
|
|
622
|
+
_ApiResourceAdapter.adapter = new ResourceAdapter(config2);
|
|
623
|
+
debug6("resource adapter initialized");
|
|
624
|
+
return _ApiResourceAdapter.get();
|
|
625
|
+
}
|
|
626
|
+
static get(config2) {
|
|
627
|
+
if (config2) return _ApiResourceAdapter.init(config2);
|
|
628
|
+
else {
|
|
629
|
+
if (_ApiResourceAdapter.adapter) return _ApiResourceAdapter.adapter;
|
|
630
|
+
else throw new SdkError({ message: "Commerce Layer not initialized" });
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
static config(config2) {
|
|
634
|
+
_ApiResourceAdapter.get().config(config2);
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
var ResourceAdapter = class {
|
|
638
|
+
#client;
|
|
639
|
+
#config = {};
|
|
640
|
+
constructor(config2) {
|
|
641
|
+
this.#client = client_default.create(config2);
|
|
642
|
+
this.localConfig(config2);
|
|
643
|
+
}
|
|
644
|
+
localConfig(config2) {
|
|
645
|
+
Object.assign(this.#config, config2);
|
|
646
|
+
}
|
|
647
|
+
config(config2) {
|
|
648
|
+
debug6("config %o", config2);
|
|
649
|
+
this.localConfig(config2);
|
|
650
|
+
this.#client.config(config2);
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
get client() {
|
|
654
|
+
return this.#client;
|
|
655
|
+
}
|
|
656
|
+
async singleton(resource, params, options, path) {
|
|
657
|
+
debug6("singleton: %o, %O, %O", resource, params || {}, options || {});
|
|
658
|
+
const queryParams = generateQueryStringParams(params, resource);
|
|
659
|
+
if (options?.params) Object.assign(queryParams, options?.params);
|
|
660
|
+
const res = await this.#client.request("GET", `${path || resource.type}`, void 0, {
|
|
661
|
+
...options,
|
|
662
|
+
params: queryParams
|
|
663
|
+
});
|
|
664
|
+
const r = denormalize(res);
|
|
665
|
+
return r;
|
|
666
|
+
}
|
|
667
|
+
async retrieve(resource, params, options) {
|
|
668
|
+
debug6("retrieve: %o, %O, %O", resource, params || {}, options || {});
|
|
669
|
+
const queryParams = generateQueryStringParams(params, resource);
|
|
670
|
+
if (options?.params) Object.assign(queryParams, options?.params);
|
|
671
|
+
const res = await this.#client.request("GET", `${resource.type}/${resource.id}`, void 0, {
|
|
672
|
+
...options,
|
|
673
|
+
params: queryParams
|
|
674
|
+
});
|
|
675
|
+
const r = denormalize(res);
|
|
676
|
+
return r;
|
|
677
|
+
}
|
|
678
|
+
async list(resource, params, options) {
|
|
679
|
+
debug6("list: %o, %O, %O", resource, params || {}, options || {});
|
|
680
|
+
const queryParams = generateQueryStringParams(params, resource);
|
|
681
|
+
if (options?.params) Object.assign(queryParams, options?.params);
|
|
682
|
+
const usesCursor = queryParams["page[after]"] != null || queryParams["page[before]"] != null;
|
|
683
|
+
if (!usesCursor && !queryParams["page[number]"]) queryParams["page[number]"] = "1";
|
|
684
|
+
const res = await this.#client.request("GET", `${resource.type}`, void 0, { ...options, params: queryParams });
|
|
685
|
+
const links = res.links;
|
|
686
|
+
const r = denormalize(res);
|
|
687
|
+
return new ListResponse(buildListMeta(res, links, params), r);
|
|
688
|
+
}
|
|
689
|
+
async create(resource, params, options) {
|
|
690
|
+
debug6("create: %o, %O, %O", resource, params || {}, options || {});
|
|
691
|
+
const queryParams = generateQueryStringParams(params, resource);
|
|
692
|
+
if (options?.params) Object.assign(queryParams, options?.params);
|
|
693
|
+
const data = normalize(resource);
|
|
694
|
+
const res = await this.#client.request("POST", resource.type, data, { ...options, params: queryParams });
|
|
695
|
+
const r = denormalize(res);
|
|
696
|
+
return r;
|
|
697
|
+
}
|
|
698
|
+
async update(resource, params, options, path) {
|
|
699
|
+
debug6("update: %o, %O, %O", resource, params || {}, options || {});
|
|
700
|
+
const queryParams = generateQueryStringParams(params, resource);
|
|
701
|
+
if (options?.params) Object.assign(queryParams, options?.params);
|
|
702
|
+
const data = normalize(resource);
|
|
703
|
+
const res = await this.#client.request("PATCH", path || `${resource.type}/${resource.id}`, data, {
|
|
704
|
+
...options,
|
|
705
|
+
params: queryParams
|
|
706
|
+
});
|
|
707
|
+
const r = denormalize(res);
|
|
708
|
+
return r;
|
|
709
|
+
}
|
|
710
|
+
async delete(resource, options) {
|
|
711
|
+
debug6("delete: %o, %O", resource, options || {});
|
|
712
|
+
await this.#client.request("DELETE", `${resource.type}/${resource.id}`, void 0, options);
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Calls a non-CRUD endpoint hosted at a sub-path of a resource, e.g.
|
|
716
|
+
* `POST memberships/:id/resend`. These endpoints are not described by the
|
|
717
|
+
* public resources schema, so they are declared in a target config and
|
|
718
|
+
* emitted from it.
|
|
719
|
+
*/
|
|
720
|
+
async action(cmd, path, payload, options) {
|
|
721
|
+
debug6("action: %o %o, %O", cmd, path, options || {});
|
|
722
|
+
const queryParams = {};
|
|
723
|
+
if (options?.params) Object.assign(queryParams, options.params);
|
|
724
|
+
const data = payload && isResourceId(payload) ? normalize(payload) : payload;
|
|
725
|
+
await this.#client.request(cmd, path, data, { ...options, params: queryParams });
|
|
726
|
+
}
|
|
727
|
+
async fetch(resource, path, params, options) {
|
|
728
|
+
debug6("fetch: %o, %O, %O", path, params || {}, options || {});
|
|
729
|
+
const queryParams = generateQueryStringParams(params, resource);
|
|
730
|
+
if (options?.params) Object.assign(queryParams, options?.params);
|
|
731
|
+
const res = await this.#client.request("GET", path, void 0, { ...options, params: queryParams });
|
|
732
|
+
const links = res.links;
|
|
733
|
+
const r = denormalize(res);
|
|
734
|
+
if (Array.isArray(r)) {
|
|
735
|
+
const p = params;
|
|
736
|
+
return new ListResponse(buildListMeta(res, links, p), r);
|
|
737
|
+
} else return r;
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
var ApiResourceBase = class {
|
|
741
|
+
static TYPE;
|
|
742
|
+
#resources;
|
|
743
|
+
constructor(adapter) {
|
|
744
|
+
debug6("new resource instance: %s", this.type());
|
|
745
|
+
if (adapter) this.#resources = adapter;
|
|
746
|
+
}
|
|
747
|
+
get resources() {
|
|
748
|
+
return this.#resources || ApiResourceAdapter.get();
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Returns a copy of this resource instance bound to a specific
|
|
752
|
+
* `ResourceAdapter`. Used by the bundle client so each client instance
|
|
753
|
+
* routes requests through its own adapter (its own access token) instead
|
|
754
|
+
* of the process-global static adapter. Resource classes are type-only
|
|
755
|
+
* exports, so we clone via `this.constructor` rather than referencing the
|
|
756
|
+
* class directly.
|
|
757
|
+
*/
|
|
758
|
+
withAdapter(adapter) {
|
|
759
|
+
return new this.constructor(adapter);
|
|
760
|
+
}
|
|
761
|
+
relationshipOneToOne(id) {
|
|
762
|
+
return id === null || typeof id === "string" ? { id, type: this.type() } : { id: id.id, type: this.type() };
|
|
763
|
+
}
|
|
764
|
+
relationshipOneToMany(...ids) {
|
|
765
|
+
return ids === null || ids.length === 0 || ids[0] === null ? [{ id: null, type: this.type() }] : ids.map((id) => {
|
|
766
|
+
return { id, type: this.type() };
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
path() {
|
|
770
|
+
return this.type();
|
|
771
|
+
}
|
|
772
|
+
// reference, reference_origin and metadata attributes are always updatable
|
|
773
|
+
async update(resource, params, options) {
|
|
774
|
+
return this.resources.update({ ...resource, type: this.type() }, params, options);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
var ApiResource = class extends ApiResourceBase {
|
|
778
|
+
async retrieve(id, params, options) {
|
|
779
|
+
const resId = typeof id === "string" ? { type: this.type(), id } : id;
|
|
780
|
+
if (!resId.id) throw new SdkError({ message: "Resource id cannot be blank" });
|
|
781
|
+
return this.resources.retrieve(resId, params, options);
|
|
782
|
+
}
|
|
783
|
+
async list(params, options) {
|
|
784
|
+
return this.resources.list({ type: this.type() }, params, options);
|
|
785
|
+
}
|
|
786
|
+
async count(filter, options) {
|
|
787
|
+
const params = {
|
|
788
|
+
filters: isParamsList(filter) ? filter.filters : filter,
|
|
789
|
+
pageNumber: 1,
|
|
790
|
+
pageSize: 1
|
|
791
|
+
};
|
|
792
|
+
const response = await this.list(params, options);
|
|
793
|
+
return Promise.resolve(response.meta.recordCount);
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
var ApiSingleton = class extends ApiResourceBase {
|
|
797
|
+
async retrieve(params, options) {
|
|
798
|
+
return this.resources.singleton({ type: this.type() }, params, options, this.path());
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
var isResourceId = (resource) => {
|
|
802
|
+
return resource?.type && resource.id && chunk47HG76BX_cjs.binding.resourceList.includes(resource.type);
|
|
803
|
+
};
|
|
804
|
+
var isResourceType = (resource) => {
|
|
805
|
+
return resource?.type && chunk47HG76BX_cjs.binding.resourceList.includes(resource.type);
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
exports.ApiResource = ApiResource;
|
|
809
|
+
exports.ApiResourceAdapter = ApiResourceAdapter;
|
|
810
|
+
exports.ApiSingleton = ApiSingleton;
|
|
811
|
+
exports.debug_default = debug_default;
|
|
812
|
+
exports.isApiError = isApiError;
|
|
813
|
+
exports.isSdkError = isSdkError;
|
|
814
|
+
exports.isTokenExpired = isTokenExpired;
|
|
815
|
+
//# sourceMappingURL=chunk-QTTL5EGB.cjs.map
|
|
816
|
+
//# sourceMappingURL=chunk-QTTL5EGB.cjs.map
|