arky-sdk 0.9.19 → 0.10.0
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/README.md +171 -105
- package/dist/admin.cjs +55 -19
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.d.cts +5 -3
- package/dist/admin.d.ts +5 -3
- package/dist/admin.js +55 -19
- package/dist/admin.js.map +1 -1
- package/dist/{api-CuqZQQGv.d.cts → index-B0Pd1s-2.d.cts} +4457 -4455
- package/dist/{api-CuqZQQGv.d.ts → index-B0Pd1s-2.d.ts} +4457 -4455
- package/dist/index.cjs +2290 -524
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3828 -3
- package/dist/index.d.ts +3828 -3
- package/dist/index.js +2286 -525
- package/dist/index.js.map +1 -1
- package/dist/{inventory-DNX8Vg-N.d.ts → inventory-C2EZEnV9.d.ts} +1 -1
- package/dist/{inventory-DrVRUkE2.d.cts → inventory-t9OBR0CC.d.cts} +1 -1
- package/dist/storefront.cjs +650 -678
- package/dist/storefront.cjs.map +1 -1
- package/dist/storefront.d.cts +5 -512
- package/dist/storefront.d.ts +5 -512
- package/dist/storefront.js +650 -678
- package/dist/storefront.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +1 -1
- package/dist/admin-CgER0AZn.d.cts +0 -1543
- package/dist/admin-CqasPNLl.d.ts +0 -1543
package/dist/admin.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
import './inventory-
|
|
1
|
+
export { AdminSession, ApiConfig, AuthStateListener, CreateAdminConfig, createAdmin } from './index.cjs';
|
|
2
|
+
export { aE as AuthStorage, aG as HttpClientConfig } from './index-B0Pd1s-2.cjs';
|
|
3
|
+
import './inventory-t9OBR0CC.cjs';
|
|
4
|
+
import 'nanostores';
|
|
5
|
+
import '@stripe/stripe-js';
|
package/dist/admin.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
import './inventory-
|
|
1
|
+
export { AdminSession, ApiConfig, AuthStateListener, CreateAdminConfig, createAdmin } from './index.js';
|
|
2
|
+
export { aE as AuthStorage, aG as HttpClientConfig } from './index-B0Pd1s-2.js';
|
|
3
|
+
import './inventory-C2EZEnV9.js';
|
|
4
|
+
import 'nanostores';
|
|
5
|
+
import '@stripe/stripe-js';
|
package/dist/admin.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import 'nanostores';
|
|
2
|
+
|
|
1
3
|
// src/utils/queryParams.ts
|
|
2
4
|
function buildQueryString(params) {
|
|
3
5
|
const queryParts = Object.entries(params).flatMap(
|
|
@@ -25,6 +27,15 @@ function requestError(name, message, details = {}) {
|
|
|
25
27
|
function isRecord(value) {
|
|
26
28
|
return typeof value === "object" && value !== null;
|
|
27
29
|
}
|
|
30
|
+
function omitStorefrontRouting(value) {
|
|
31
|
+
if (!isRecord(value) || Array.isArray(value)) return value;
|
|
32
|
+
const prototype = Object.getPrototypeOf(value);
|
|
33
|
+
if (prototype !== Object.prototype && prototype !== null) return value;
|
|
34
|
+
const result = { ...value };
|
|
35
|
+
delete result.store_id;
|
|
36
|
+
delete result.market;
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
28
39
|
function isTokenSet(value) {
|
|
29
40
|
return isRecord(value) && typeof value.access_token === "string" && (value.refresh_token === void 0 || typeof value.refresh_token === "string") && (value.access_expires_at === void 0 || typeof value.access_expires_at === "number");
|
|
30
41
|
}
|
|
@@ -100,10 +111,25 @@ function createHttpClient(cfg) {
|
|
|
100
111
|
if (!retried && options?.transformRequest) {
|
|
101
112
|
body = options.transformRequest(body);
|
|
102
113
|
}
|
|
114
|
+
if (cfg.storefrontMode) {
|
|
115
|
+
body = omitStorefrontRouting(body);
|
|
116
|
+
}
|
|
117
|
+
const forcedHeaders = typeof cfg.forcedHeaders === "function" ? cfg.forcedHeaders() : cfg.forcedHeaders || {};
|
|
118
|
+
const callerHeaders = { ...options?.headers || {} };
|
|
119
|
+
const protectedHeaderNames = new Set(
|
|
120
|
+
Object.keys(forcedHeaders).map((name) => name.toLowerCase())
|
|
121
|
+
);
|
|
122
|
+
if (cfg.storefrontMode) protectedHeaderNames.add("authorization");
|
|
123
|
+
for (const name of Object.keys(callerHeaders)) {
|
|
124
|
+
if (protectedHeaderNames.has(name.toLowerCase())) {
|
|
125
|
+
delete callerHeaders[name];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
103
128
|
const headers = {
|
|
104
129
|
Accept: "application/json",
|
|
105
130
|
"Content-Type": "application/json",
|
|
106
|
-
...
|
|
131
|
+
...callerHeaders,
|
|
132
|
+
...forcedHeaders
|
|
107
133
|
};
|
|
108
134
|
let tokens = authStorage.getTokens();
|
|
109
135
|
const nowSec = Date.now() / 1e3;
|
|
@@ -114,7 +140,8 @@ function createHttpClient(cfg) {
|
|
|
114
140
|
if (tokens?.access_token) {
|
|
115
141
|
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
116
142
|
}
|
|
117
|
-
const
|
|
143
|
+
const requestParams = cfg.storefrontMode ? omitStorefrontRouting(options?.params) : options?.params;
|
|
144
|
+
const finalPath = requestParams ? path + buildQueryString(requestParams) : path;
|
|
118
145
|
const fetchOptions = {
|
|
119
146
|
method,
|
|
120
147
|
headers,
|
|
@@ -145,8 +172,19 @@ function createHttpClient(cfg) {
|
|
|
145
172
|
throw err;
|
|
146
173
|
}
|
|
147
174
|
if (res.status === 401 && !retried) {
|
|
148
|
-
|
|
149
|
-
|
|
175
|
+
if (cfg.onUnauthorized) {
|
|
176
|
+
const recovered = await cfg.onUnauthorized({
|
|
177
|
+
hadAuthorization: Boolean(tokens?.access_token),
|
|
178
|
+
authorizationToken: tokens?.access_token || null,
|
|
179
|
+
path
|
|
180
|
+
});
|
|
181
|
+
if (recovered) {
|
|
182
|
+
return request(method, path, body, options, true);
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
await ensureFreshToken();
|
|
186
|
+
return request(method, path, body, options, true);
|
|
187
|
+
}
|
|
150
188
|
}
|
|
151
189
|
try {
|
|
152
190
|
const contentLength = res.headers.get("content-length");
|
|
@@ -362,6 +400,14 @@ var createStoreApi = (apiConfig, _updateSession) => {
|
|
|
362
400
|
params
|
|
363
401
|
});
|
|
364
402
|
},
|
|
403
|
+
async regeneratePublishableKey(params = {}, options) {
|
|
404
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
405
|
+
return apiConfig.httpClient.post(
|
|
406
|
+
`/v1/stores/${store_id}/publishable-key/regenerate`,
|
|
407
|
+
{},
|
|
408
|
+
options
|
|
409
|
+
);
|
|
410
|
+
},
|
|
365
411
|
async getSubscriptionPlans(_params, options) {
|
|
366
412
|
return apiConfig.httpClient.get("/v1/stores/plans", options);
|
|
367
413
|
},
|
|
@@ -1260,7 +1306,10 @@ var createMarketApi = (apiConfig) => {
|
|
|
1260
1306
|
async delete(params, options) {
|
|
1261
1307
|
return apiConfig.httpClient.delete(
|
|
1262
1308
|
`/v1/stores/${apiConfig.storeId}/markets/${params.id}`,
|
|
1263
|
-
|
|
1309
|
+
{
|
|
1310
|
+
...options,
|
|
1311
|
+
params: params.replacement_default_market_id ? { replacement_default_market_id: params.replacement_default_market_id } : options?.params
|
|
1312
|
+
}
|
|
1264
1313
|
);
|
|
1265
1314
|
}
|
|
1266
1315
|
};
|
|
@@ -1281,11 +1330,7 @@ var createActionAdminApi = (apiConfig) => ({
|
|
|
1281
1330
|
async find(params, options) {
|
|
1282
1331
|
const store_id = params.store_id || apiConfig.storeId;
|
|
1283
1332
|
const queryParams = {};
|
|
1284
|
-
if (params.query) queryParams.query = params.query;
|
|
1285
1333
|
if (params.contact_id) queryParams.contact_id = params.contact_id;
|
|
1286
|
-
if (params.types && params.types.length > 0) queryParams.types = params.types;
|
|
1287
|
-
if (params.from !== void 0) queryParams.from = params.from;
|
|
1288
|
-
if (params.to !== void 0) queryParams.to = params.to;
|
|
1289
1334
|
if (params.limit !== void 0) queryParams.limit = params.limit;
|
|
1290
1335
|
if (params.cursor) queryParams.cursor = params.cursor;
|
|
1291
1336
|
return apiConfig.httpClient.get(
|
|
@@ -1331,16 +1376,6 @@ var createContactApi = (apiConfig) => {
|
|
|
1331
1376
|
}
|
|
1332
1377
|
);
|
|
1333
1378
|
},
|
|
1334
|
-
async findActions(params, options) {
|
|
1335
|
-
const { store_id, ...queryParams } = params || {};
|
|
1336
|
-
return apiConfig.httpClient.get(
|
|
1337
|
-
`/v1/stores/${store_id || apiConfig.storeId}/actions`,
|
|
1338
|
-
{
|
|
1339
|
-
...options,
|
|
1340
|
-
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
1341
|
-
}
|
|
1342
|
-
);
|
|
1343
|
-
},
|
|
1344
1379
|
async update(params, options) {
|
|
1345
1380
|
const { id, store_id, ...body } = params;
|
|
1346
1381
|
return apiConfig.httpClient.put(
|
|
@@ -3520,6 +3555,7 @@ function createAdmin(config) {
|
|
|
3520
3555
|
update: storeApi.updateStore,
|
|
3521
3556
|
get: storeApi.getStore,
|
|
3522
3557
|
find: storeApi.getStores,
|
|
3558
|
+
regeneratePublishableKey: storeApi.regeneratePublishableKey,
|
|
3523
3559
|
subscription: {
|
|
3524
3560
|
get: storeApi.getSubscription,
|
|
3525
3561
|
getPlans: storeApi.getSubscriptionPlans,
|