arky-sdk 0.9.0 → 0.9.6
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 +2 -2
- package/dist/{admin-CfHen7c5.d.cts → admin-DjYydKeB.d.ts} +477 -124
- package/dist/{admin-ru7pX5bd.d.ts → admin-DlL8mCxL.d.cts} +477 -124
- package/dist/admin.cjs +592 -202
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.d.cts +3 -3
- package/dist/admin.d.ts +3 -3
- package/dist/admin.js +592 -202
- package/dist/admin.js.map +1 -1
- package/dist/api-BbBHcd4p.d.cts +3289 -0
- package/dist/api-BbBHcd4p.d.ts +3289 -0
- package/dist/{index-C5gikdBg.d.cts → index-CZxubTDA.d.ts} +1 -1
- package/dist/{index-MFMjlIfS.d.ts → index-nCF3Z6Af.d.cts} +1 -1
- package/dist/index.cjs +666 -319
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +666 -319
- package/dist/index.js.map +1 -1
- package/dist/storefront-store.cjs +149 -134
- package/dist/storefront-store.cjs.map +1 -1
- package/dist/storefront-store.d.cts +3 -3
- package/dist/storefront-store.d.ts +3 -3
- package/dist/storefront-store.js +149 -134
- package/dist/storefront-store.js.map +1 -1
- package/dist/storefront.cjs +149 -134
- package/dist/storefront.cjs.map +1 -1
- package/dist/storefront.d.cts +45 -102
- package/dist/storefront.d.ts +45 -102
- package/dist/storefront.js +149 -134
- package/dist/storefront.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -2666
- package/dist/types.d.ts +1 -2666
- package/dist/types.js.map +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.ts +2 -2
- package/package.json +3 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { A as ArkyCalendarDay, ArkyCartInput, ArkyCartSnapshot, ArkyCartStatus, ArkyCartStore, ArkyCmsNodeParams, ArkyCmsState, ArkyEshopState, ArkyLastOrder, ArkyServiceCartItem, a as ArkyServiceSlot, b as ArkyServiceState, ArkyServiceStore, ArkyStore, ArkyStoreConfig, ArkyStoreContext, ArkyStoreSetupOptions, ArkyStoreSetupResult, createArkyStore } from './storefront.cjs';
|
|
2
|
-
import './admin-
|
|
3
|
-
import './
|
|
4
|
-
import './index-
|
|
2
|
+
import './admin-DlL8mCxL.cjs';
|
|
3
|
+
import './api-BbBHcd4p.cjs';
|
|
4
|
+
import './index-nCF3Z6Af.cjs';
|
|
5
5
|
import 'nanostores';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { A as ArkyCalendarDay, ArkyCartInput, ArkyCartSnapshot, ArkyCartStatus, ArkyCartStore, ArkyCmsNodeParams, ArkyCmsState, ArkyEshopState, ArkyLastOrder, ArkyServiceCartItem, a as ArkyServiceSlot, b as ArkyServiceState, ArkyServiceStore, ArkyStore, ArkyStoreConfig, ArkyStoreContext, ArkyStoreSetupOptions, ArkyStoreSetupResult, createArkyStore } from './storefront.js';
|
|
2
|
-
import './admin-
|
|
3
|
-
import './
|
|
4
|
-
import './index-
|
|
2
|
+
import './admin-DjYydKeB.js';
|
|
3
|
+
import './api-BbBHcd4p.js';
|
|
4
|
+
import './index-CZxubTDA.js';
|
|
5
5
|
import 'nanostores';
|
package/dist/storefront-store.js
CHANGED
|
@@ -177,7 +177,7 @@ var createActivityApi = (apiConfig) => ({
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
});
|
|
180
|
-
var createStorefrontApi = (apiConfig,
|
|
180
|
+
var createStorefrontApi = (apiConfig, updateProfileSession) => {
|
|
181
181
|
const base = (storeId = apiConfig.storeId) => `/v1/storefront/${storeId}`;
|
|
182
182
|
return {
|
|
183
183
|
store: {
|
|
@@ -498,11 +498,11 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
|
|
|
498
498
|
}
|
|
499
499
|
},
|
|
500
500
|
crm: {
|
|
501
|
-
|
|
501
|
+
profile: {
|
|
502
502
|
async identify(params, options) {
|
|
503
503
|
const store_id = apiConfig.storeId;
|
|
504
504
|
const result = await apiConfig.httpClient.post(
|
|
505
|
-
`${base(store_id)}/
|
|
505
|
+
`${base(store_id)}/profiles/identify`,
|
|
506
506
|
{
|
|
507
507
|
store_id,
|
|
508
508
|
market: params?.market || apiConfig.market || null,
|
|
@@ -512,9 +512,9 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
|
|
|
512
512
|
options
|
|
513
513
|
);
|
|
514
514
|
if (result?.token?.token) {
|
|
515
|
-
|
|
515
|
+
updateProfileSession(() => ({
|
|
516
516
|
access_token: result.token.token,
|
|
517
|
-
|
|
517
|
+
profile: result.profile,
|
|
518
518
|
store: result.store,
|
|
519
519
|
market: result.market
|
|
520
520
|
}));
|
|
@@ -524,12 +524,12 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
|
|
|
524
524
|
async verify(params, options) {
|
|
525
525
|
const store_id = apiConfig.storeId;
|
|
526
526
|
const result = await apiConfig.httpClient.post(
|
|
527
|
-
`${base(store_id)}/
|
|
527
|
+
`${base(store_id)}/profiles/verify`,
|
|
528
528
|
{ store_id, code: params.code },
|
|
529
529
|
options
|
|
530
530
|
);
|
|
531
531
|
if (result?.token) {
|
|
532
|
-
|
|
532
|
+
updateProfileSession(
|
|
533
533
|
(prev) => prev ? { ...prev, access_token: result.token } : null
|
|
534
534
|
);
|
|
535
535
|
}
|
|
@@ -539,132 +539,63 @@ var createStorefrontApi = (apiConfig, updateCustomerSession) => {
|
|
|
539
539
|
const store_id = apiConfig.storeId;
|
|
540
540
|
try {
|
|
541
541
|
await apiConfig.httpClient.post(
|
|
542
|
-
`${base(store_id)}/
|
|
542
|
+
`${base(store_id)}/profiles/logout`,
|
|
543
543
|
{},
|
|
544
544
|
options
|
|
545
545
|
);
|
|
546
546
|
} finally {
|
|
547
|
-
|
|
547
|
+
updateProfileSession(() => null);
|
|
548
548
|
}
|
|
549
549
|
},
|
|
550
550
|
getMe(options) {
|
|
551
|
-
return apiConfig.httpClient.get(`${base()}/
|
|
551
|
+
return apiConfig.httpClient.get(`${base()}/profiles/me`, options);
|
|
552
552
|
}
|
|
553
553
|
},
|
|
554
|
-
|
|
554
|
+
profileList: {
|
|
555
555
|
get(params, options) {
|
|
556
|
-
|
|
557
|
-
if (params.id) {
|
|
558
|
-
identifier = params.id;
|
|
559
|
-
} else if (params.key) {
|
|
560
|
-
identifier = `${apiConfig.storeId}:${params.key}`;
|
|
561
|
-
} else {
|
|
562
|
-
throw new Error("GetAudienceParams requires id or key");
|
|
563
|
-
}
|
|
556
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
564
557
|
return apiConfig.httpClient.get(
|
|
565
|
-
`${base(
|
|
558
|
+
`${base(store_id)}/profile-lists/${params.id}`,
|
|
566
559
|
options
|
|
567
560
|
);
|
|
568
561
|
},
|
|
569
562
|
find(params, options) {
|
|
570
|
-
|
|
563
|
+
const { store_id, ...queryParams } = params || {};
|
|
564
|
+
return apiConfig.httpClient.get(`${base(store_id)}/profile-lists`, {
|
|
571
565
|
...options,
|
|
572
|
-
params
|
|
566
|
+
params: queryParams
|
|
573
567
|
});
|
|
574
568
|
},
|
|
575
569
|
subscribe(params, options) {
|
|
570
|
+
const { store_id, id, ...payload } = params;
|
|
576
571
|
return apiConfig.httpClient.post(
|
|
577
|
-
`${base()}/
|
|
578
|
-
|
|
579
|
-
customer_id: params.customer_id,
|
|
580
|
-
price_id: params.price_id,
|
|
581
|
-
success_url: params.success_url,
|
|
582
|
-
cancel_url: params.cancel_url,
|
|
583
|
-
confirm_url: params.confirm_url
|
|
584
|
-
},
|
|
572
|
+
`${base(store_id)}/profile-lists/${id}/subscribe`,
|
|
573
|
+
payload,
|
|
585
574
|
options
|
|
586
575
|
);
|
|
587
576
|
},
|
|
588
577
|
checkAccess(params, options) {
|
|
578
|
+
const store_id = params.store_id || apiConfig.storeId;
|
|
589
579
|
return apiConfig.httpClient.get(
|
|
590
|
-
`${base()}/
|
|
580
|
+
`${base(store_id)}/profile-lists/${params.id}/access`,
|
|
591
581
|
options
|
|
592
582
|
);
|
|
593
583
|
},
|
|
594
584
|
unsubscribe(token, options) {
|
|
595
|
-
return apiConfig.httpClient.get(`${base()}/
|
|
585
|
+
return apiConfig.httpClient.get(`${base()}/profile-lists/unsubscribe`, {
|
|
596
586
|
...options,
|
|
597
587
|
params: { token }
|
|
598
588
|
});
|
|
599
589
|
},
|
|
600
590
|
confirm(token, options) {
|
|
601
|
-
return apiConfig.httpClient.get(`${base()}/
|
|
591
|
+
return apiConfig.httpClient.get(`${base()}/profile-lists/confirm`, {
|
|
602
592
|
...options,
|
|
603
593
|
params: { token }
|
|
604
594
|
});
|
|
605
595
|
}
|
|
606
596
|
}
|
|
607
597
|
},
|
|
608
|
-
activity: createActivityApi(apiConfig)
|
|
609
|
-
automation: {
|
|
610
|
-
agent: {
|
|
611
|
-
getAgents(params, options) {
|
|
612
|
-
const store_id = params?.store_id || apiConfig.storeId;
|
|
613
|
-
const queryParams = { ...params || {} };
|
|
614
|
-
delete queryParams.store_id;
|
|
615
|
-
return apiConfig.httpClient.get(`${base(store_id)}/agents`, {
|
|
616
|
-
...options,
|
|
617
|
-
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
618
|
-
});
|
|
619
|
-
},
|
|
620
|
-
getAgent(params, options) {
|
|
621
|
-
const store_id = params.store_id || apiConfig.storeId;
|
|
622
|
-
return apiConfig.httpClient.get(
|
|
623
|
-
`${base(store_id)}/agents/${params.id}`,
|
|
624
|
-
options
|
|
625
|
-
);
|
|
626
|
-
},
|
|
627
|
-
sendMessage(params, options) {
|
|
628
|
-
const store_id = params.store_id || apiConfig.storeId;
|
|
629
|
-
const body = { message: params.message };
|
|
630
|
-
if (params.chat_id) body.chat_id = params.chat_id;
|
|
631
|
-
return apiConfig.httpClient.post(
|
|
632
|
-
`${base(store_id)}/agents/${params.id}/chats/messages`,
|
|
633
|
-
body,
|
|
634
|
-
options
|
|
635
|
-
);
|
|
636
|
-
},
|
|
637
|
-
getChat(params, options) {
|
|
638
|
-
const store_id = params.store_id || apiConfig.storeId;
|
|
639
|
-
return apiConfig.httpClient.get(
|
|
640
|
-
`${base(store_id)}/agents/${params.id}/chats/${params.chat_id}`,
|
|
641
|
-
options
|
|
642
|
-
);
|
|
643
|
-
},
|
|
644
|
-
getChatMessages(params, options) {
|
|
645
|
-
const store_id = params.store_id || apiConfig.storeId;
|
|
646
|
-
const queryParams = {};
|
|
647
|
-
if (params.limit) queryParams.limit = String(params.limit);
|
|
648
|
-
return apiConfig.httpClient.get(
|
|
649
|
-
`${base(store_id)}/agents/${params.id}/chats/${params.chat_id}/messages`,
|
|
650
|
-
{
|
|
651
|
-
...options,
|
|
652
|
-
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
653
|
-
}
|
|
654
|
-
);
|
|
655
|
-
},
|
|
656
|
-
rateChat(params, options) {
|
|
657
|
-
const store_id = params.store_id || apiConfig.storeId;
|
|
658
|
-
const body = { rating: params.rating };
|
|
659
|
-
if (params.comment) body.comment = params.comment;
|
|
660
|
-
return apiConfig.httpClient.post(
|
|
661
|
-
`${base(store_id)}/agents/${params.id}/chats/${params.chat_id}/rate`,
|
|
662
|
-
body,
|
|
663
|
-
options
|
|
664
|
-
);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
598
|
+
activity: createActivityApi(apiConfig)
|
|
668
599
|
};
|
|
669
600
|
};
|
|
670
601
|
|
|
@@ -999,6 +930,41 @@ function createHttpClient(cfg) {
|
|
|
999
930
|
};
|
|
1000
931
|
}
|
|
1001
932
|
|
|
933
|
+
// src/api/support.ts
|
|
934
|
+
function supportConversationQuery(params) {
|
|
935
|
+
const qs = new URLSearchParams({ store_id: params.store_id });
|
|
936
|
+
if (params.message_limit) qs.set("message_limit", String(params.message_limit));
|
|
937
|
+
if (typeof params.after_created_at === "number") qs.set("after_created_at", String(params.after_created_at));
|
|
938
|
+
if (params.after_id) qs.set("after_id", params.after_id);
|
|
939
|
+
return qs.toString();
|
|
940
|
+
}
|
|
941
|
+
function createStorefrontSupportApi(config) {
|
|
942
|
+
const { httpClient, storeId } = config;
|
|
943
|
+
return {
|
|
944
|
+
async startConversation(params = {}, opts) {
|
|
945
|
+
return httpClient.post(
|
|
946
|
+
`/v1/storefront/${storeId}/support/conversations`,
|
|
947
|
+
{ store_id: storeId, ...params },
|
|
948
|
+
opts
|
|
949
|
+
);
|
|
950
|
+
},
|
|
951
|
+
async sendMessage(params, opts) {
|
|
952
|
+
return httpClient.post(
|
|
953
|
+
`/v1/storefront/${storeId}/support/conversations/${params.conversation_id}/messages`,
|
|
954
|
+
{ store_id: storeId, ...params },
|
|
955
|
+
opts
|
|
956
|
+
);
|
|
957
|
+
},
|
|
958
|
+
async getConversation(params, opts) {
|
|
959
|
+
const qs = supportConversationQuery({ store_id: storeId, ...params });
|
|
960
|
+
return httpClient.get(
|
|
961
|
+
`/v1/storefront/${storeId}/support/conversations/${params.conversation_id}?${qs}`,
|
|
962
|
+
opts
|
|
963
|
+
);
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
|
|
1002
968
|
// src/utils/price.ts
|
|
1003
969
|
function formatCurrency(amount, currencyCode, locale = "en") {
|
|
1004
970
|
if (!currencyCode) return "";
|
|
@@ -1288,22 +1254,22 @@ function createUtilitySurface(apiConfig) {
|
|
|
1288
1254
|
getFirstAvailableFCId
|
|
1289
1255
|
};
|
|
1290
1256
|
}
|
|
1291
|
-
var
|
|
1292
|
-
function
|
|
1257
|
+
var PROFILE_STORAGE_KEY = "arky_profile_session";
|
|
1258
|
+
function readProfileSession() {
|
|
1293
1259
|
if (typeof window === "undefined") return null;
|
|
1294
1260
|
try {
|
|
1295
|
-
const raw = localStorage.getItem(
|
|
1261
|
+
const raw = localStorage.getItem(PROFILE_STORAGE_KEY);
|
|
1296
1262
|
return raw ? JSON.parse(raw) : null;
|
|
1297
1263
|
} catch {
|
|
1298
1264
|
return null;
|
|
1299
1265
|
}
|
|
1300
1266
|
}
|
|
1301
|
-
function
|
|
1267
|
+
function writeProfileSession(s) {
|
|
1302
1268
|
if (typeof window === "undefined") return;
|
|
1303
1269
|
if (s) {
|
|
1304
|
-
localStorage.setItem(
|
|
1270
|
+
localStorage.setItem(PROFILE_STORAGE_KEY, JSON.stringify(s));
|
|
1305
1271
|
} else {
|
|
1306
|
-
localStorage.removeItem(
|
|
1272
|
+
localStorage.removeItem(PROFILE_STORAGE_KEY);
|
|
1307
1273
|
}
|
|
1308
1274
|
}
|
|
1309
1275
|
function createStorefront(config) {
|
|
@@ -1312,10 +1278,10 @@ function createStorefront(config) {
|
|
|
1312
1278
|
const listeners = /* @__PURE__ */ new Set();
|
|
1313
1279
|
let bareIdentifyPromise = null;
|
|
1314
1280
|
function toPublic(s) {
|
|
1315
|
-
return s ? {
|
|
1281
|
+
return s ? { profile: s.profile, store: s.store, market: s.market } : null;
|
|
1316
1282
|
}
|
|
1317
1283
|
function emit() {
|
|
1318
|
-
const pub = toPublic(
|
|
1284
|
+
const pub = toPublic(readProfileSession());
|
|
1319
1285
|
for (const l of listeners) {
|
|
1320
1286
|
Promise.resolve().then(() => l(pub)).catch(() => {
|
|
1321
1287
|
});
|
|
@@ -1323,9 +1289,9 @@ function createStorefront(config) {
|
|
|
1323
1289
|
}
|
|
1324
1290
|
const updateSession = (updater) => {
|
|
1325
1291
|
if (config.apiToken) return;
|
|
1326
|
-
const prev =
|
|
1292
|
+
const prev = readProfileSession();
|
|
1327
1293
|
const next = updater(prev);
|
|
1328
|
-
|
|
1294
|
+
writeProfileSession(next);
|
|
1329
1295
|
emit();
|
|
1330
1296
|
};
|
|
1331
1297
|
const authStorage = config.apiToken ? {
|
|
@@ -1336,7 +1302,7 @@ function createStorefront(config) {
|
|
|
1336
1302
|
}
|
|
1337
1303
|
} : {
|
|
1338
1304
|
getTokens() {
|
|
1339
|
-
const s =
|
|
1305
|
+
const s = readProfileSession();
|
|
1340
1306
|
return s ? { access_token: s.access_token } : null;
|
|
1341
1307
|
},
|
|
1342
1308
|
onTokensRefreshed() {
|
|
@@ -1363,20 +1329,20 @@ function createStorefront(config) {
|
|
|
1363
1329
|
authStorage
|
|
1364
1330
|
};
|
|
1365
1331
|
const storefrontApi = createStorefrontApi(apiConfig, updateSession);
|
|
1366
|
-
const
|
|
1332
|
+
const profileApi = storefrontApi.crm.profile;
|
|
1367
1333
|
function identify(params) {
|
|
1368
1334
|
if (params?.market !== void 0) apiConfig.market = params.market;
|
|
1369
1335
|
const isBareCall = !params?.email && !params?.verify;
|
|
1370
1336
|
if (isBareCall && bareIdentifyPromise) return bareIdentifyPromise;
|
|
1371
1337
|
const promise = (async () => {
|
|
1372
1338
|
try {
|
|
1373
|
-
const result = await
|
|
1339
|
+
const result = await profileApi.identify({
|
|
1374
1340
|
market: apiConfig.market,
|
|
1375
1341
|
email: params?.email,
|
|
1376
1342
|
verify: params?.verify
|
|
1377
1343
|
});
|
|
1378
1344
|
return {
|
|
1379
|
-
|
|
1345
|
+
profile: result.profile,
|
|
1380
1346
|
store: result.store,
|
|
1381
1347
|
market: result.market
|
|
1382
1348
|
};
|
|
@@ -1385,9 +1351,9 @@ function createStorefront(config) {
|
|
|
1385
1351
|
const status = e?.statusCode || e?.status || e?.response?.status;
|
|
1386
1352
|
if (isBareCall && status === 401) {
|
|
1387
1353
|
updateSession(() => null);
|
|
1388
|
-
const result = await
|
|
1354
|
+
const result = await profileApi.identify({ market: apiConfig.market });
|
|
1389
1355
|
return {
|
|
1390
|
-
|
|
1356
|
+
profile: result.profile,
|
|
1391
1357
|
store: result.store,
|
|
1392
1358
|
market: result.market
|
|
1393
1359
|
};
|
|
@@ -1402,7 +1368,7 @@ function createStorefront(config) {
|
|
|
1402
1368
|
return promise;
|
|
1403
1369
|
}
|
|
1404
1370
|
async function verify(params) {
|
|
1405
|
-
const result = await
|
|
1371
|
+
const result = await profileApi.verify(params);
|
|
1406
1372
|
bareIdentifyPromise = null;
|
|
1407
1373
|
return result;
|
|
1408
1374
|
}
|
|
@@ -1410,7 +1376,7 @@ function createStorefront(config) {
|
|
|
1410
1376
|
if (config.apiToken) return;
|
|
1411
1377
|
bareIdentifyPromise = null;
|
|
1412
1378
|
try {
|
|
1413
|
-
await
|
|
1379
|
+
await profileApi.logout();
|
|
1414
1380
|
} catch {
|
|
1415
1381
|
updateSession(() => null);
|
|
1416
1382
|
}
|
|
@@ -1419,19 +1385,19 @@ function createStorefront(config) {
|
|
|
1419
1385
|
identify,
|
|
1420
1386
|
verify,
|
|
1421
1387
|
logout,
|
|
1422
|
-
me: () =>
|
|
1388
|
+
me: () => profileApi.getMe(),
|
|
1423
1389
|
get session() {
|
|
1424
1390
|
if (config.apiToken) return null;
|
|
1425
|
-
return toPublic(
|
|
1391
|
+
return toPublic(readProfileSession());
|
|
1426
1392
|
},
|
|
1427
1393
|
get isAuthenticated() {
|
|
1428
1394
|
if (config.apiToken) return true;
|
|
1429
|
-
const s =
|
|
1395
|
+
const s = readProfileSession();
|
|
1430
1396
|
return s !== null && !!s.access_token;
|
|
1431
1397
|
},
|
|
1432
1398
|
onAuthStateChanged(listener) {
|
|
1433
1399
|
listeners.add(listener);
|
|
1434
|
-
const current = toPublic(
|
|
1400
|
+
const current = toPublic(readProfileSession());
|
|
1435
1401
|
if (current) {
|
|
1436
1402
|
Promise.resolve().then(() => listener(current)).catch(() => {
|
|
1437
1403
|
});
|
|
@@ -1446,7 +1412,7 @@ function createStorefront(config) {
|
|
|
1446
1412
|
eshop: storefrontApi.eshop,
|
|
1447
1413
|
crm: storefrontApi.crm,
|
|
1448
1414
|
activity: storefrontApi.activity,
|
|
1449
|
-
|
|
1415
|
+
support: createStorefrontSupportApi(apiConfig),
|
|
1450
1416
|
setStoreId: (storeId) => {
|
|
1451
1417
|
apiConfig.storeId = storeId;
|
|
1452
1418
|
bareIdentifyPromise = null;
|
|
@@ -1517,7 +1483,7 @@ function priceForMarket(prices, market, fallbackCurrency) {
|
|
|
1517
1483
|
market: price?.market || market,
|
|
1518
1484
|
currency: price?.currency || fallbackCurrency || "",
|
|
1519
1485
|
compare_at: price?.compare_at,
|
|
1520
|
-
|
|
1486
|
+
profile_list_id: price?.profile_list_id
|
|
1521
1487
|
};
|
|
1522
1488
|
}
|
|
1523
1489
|
function availableStock(client, variant) {
|
|
@@ -1712,18 +1678,46 @@ function createArkyStore(config) {
|
|
|
1712
1678
|
selected_shipping_method_id: null,
|
|
1713
1679
|
user_token: null
|
|
1714
1680
|
});
|
|
1681
|
+
function rawProductItemCount(value) {
|
|
1682
|
+
return (value?.items || []).reduce((total, item) => {
|
|
1683
|
+
if (item.type !== "product") return total;
|
|
1684
|
+
return total + (item.quantity || 0);
|
|
1685
|
+
}, 0);
|
|
1686
|
+
}
|
|
1687
|
+
function rawServiceItemCount(value) {
|
|
1688
|
+
return (value?.items || []).reduce((total, item) => {
|
|
1689
|
+
if (item.type !== "service") return total;
|
|
1690
|
+
return total + Math.max(1, item.slots?.length || 0);
|
|
1691
|
+
}, 0);
|
|
1692
|
+
}
|
|
1715
1693
|
const product_item_count = computed(
|
|
1716
|
-
product_items,
|
|
1717
|
-
(items) =>
|
|
1694
|
+
[cart, product_items],
|
|
1695
|
+
(cartValue, items) => Math.max(
|
|
1696
|
+
rawProductItemCount(cartValue),
|
|
1697
|
+
items.reduce((total, item) => total + (item.quantity || 0), 0)
|
|
1698
|
+
)
|
|
1699
|
+
);
|
|
1700
|
+
const service_item_count = computed(
|
|
1701
|
+
[cart, service_items],
|
|
1702
|
+
(cartValue, items) => Math.max(rawServiceItemCount(cartValue), items.length)
|
|
1703
|
+
);
|
|
1704
|
+
const item_count = computed(
|
|
1705
|
+
[cart, product_item_count, service_item_count],
|
|
1706
|
+
(cartValue, products, services) => Math.max(cartValue?.item_count || 0, products + services)
|
|
1718
1707
|
);
|
|
1719
|
-
const service_item_count = computed(service_items, (items) => items.length);
|
|
1720
|
-
const item_count = computed([product_item_count, service_item_count], (products, services) => products + services);
|
|
1721
1708
|
const snapshot = computed([cart, product_items, service_items, item_count], (cartValue, products, services, count) => ({
|
|
1722
1709
|
cart: cartValue,
|
|
1723
1710
|
product_items: products,
|
|
1724
1711
|
service_items: services,
|
|
1725
1712
|
item_count: count
|
|
1726
1713
|
}));
|
|
1714
|
+
let cartWriteRevision = 0;
|
|
1715
|
+
let sessionRequest = null;
|
|
1716
|
+
let cartRequest = null;
|
|
1717
|
+
function nextCartWriteRevision() {
|
|
1718
|
+
cartWriteRevision += 1;
|
|
1719
|
+
return cartWriteRevision;
|
|
1720
|
+
}
|
|
1727
1721
|
const cms_state = map({
|
|
1728
1722
|
nodes: {},
|
|
1729
1723
|
forms: {},
|
|
@@ -1771,7 +1765,12 @@ function createArkyStore(config) {
|
|
|
1771
1765
|
const current = session.get();
|
|
1772
1766
|
const marketKey = currentMarketKey();
|
|
1773
1767
|
if (current && (!marketKey || current.market?.key === marketKey)) return current;
|
|
1774
|
-
|
|
1768
|
+
if (!sessionRequest) {
|
|
1769
|
+
sessionRequest = identify({ market: marketKey }).finally(() => {
|
|
1770
|
+
sessionRequest = null;
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
return sessionRequest;
|
|
1775
1774
|
}
|
|
1776
1775
|
async function identify(params = {}) {
|
|
1777
1776
|
if (params.market) setMarket(params.market);
|
|
@@ -1797,17 +1796,23 @@ function createArkyStore(config) {
|
|
|
1797
1796
|
if (context.market) setMarket(context.market);
|
|
1798
1797
|
}
|
|
1799
1798
|
async function ensureCart() {
|
|
1799
|
+
if (cartRequest) return cartRequest;
|
|
1800
1800
|
cart_status.setKey("loading", true);
|
|
1801
1801
|
cart_status.setKey("error", null);
|
|
1802
|
-
|
|
1802
|
+
const refreshRevision = cartWriteRevision;
|
|
1803
|
+
cartRequest = (async () => {
|
|
1803
1804
|
await ensureSession();
|
|
1804
1805
|
const response = await client.cart.refresh({ market: currentMarketKey() });
|
|
1805
|
-
await hydrateCart(response);
|
|
1806
|
+
await hydrateCart(response, { ifRevision: refreshRevision });
|
|
1806
1807
|
return response;
|
|
1808
|
+
})();
|
|
1809
|
+
try {
|
|
1810
|
+
return await cartRequest;
|
|
1807
1811
|
} catch (error) {
|
|
1808
1812
|
cart_status.setKey("error", readErrorMessage(error, "Failed to load cart."));
|
|
1809
1813
|
throw error;
|
|
1810
1814
|
} finally {
|
|
1815
|
+
cartRequest = null;
|
|
1811
1816
|
cart_status.setKey("loading", false);
|
|
1812
1817
|
}
|
|
1813
1818
|
}
|
|
@@ -1860,7 +1865,10 @@ function createArkyStore(config) {
|
|
|
1860
1865
|
}
|
|
1861
1866
|
return rows;
|
|
1862
1867
|
}
|
|
1863
|
-
async function hydrateCart(response) {
|
|
1868
|
+
async function hydrateCart(response, options = {}) {
|
|
1869
|
+
if (options.ifRevision !== void 0 && options.ifRevision !== cartWriteRevision) {
|
|
1870
|
+
return cart.get() || response;
|
|
1871
|
+
}
|
|
1864
1872
|
cart.set(response);
|
|
1865
1873
|
cart_status.setKey("user_token", response.token || null);
|
|
1866
1874
|
cart_status.setKey("selected_shipping_method_id", response.shipping_method_id || null);
|
|
@@ -1883,7 +1891,7 @@ function createArkyStore(config) {
|
|
|
1883
1891
|
...toServiceCheckoutItems(input.service_items || service_items.get())
|
|
1884
1892
|
];
|
|
1885
1893
|
}
|
|
1886
|
-
async function syncCart(input = {}) {
|
|
1894
|
+
async function syncCart(input = {}, writeRevision = nextCartWriteRevision()) {
|
|
1887
1895
|
cart_status.setKey("syncing", true);
|
|
1888
1896
|
cart_status.setKey("error", null);
|
|
1889
1897
|
try {
|
|
@@ -1903,7 +1911,7 @@ function createArkyStore(config) {
|
|
|
1903
1911
|
if (input.shipping_method_id !== void 0) {
|
|
1904
1912
|
cart_status.setKey("selected_shipping_method_id", input.shipping_method_id);
|
|
1905
1913
|
}
|
|
1906
|
-
await hydrateCart(response);
|
|
1914
|
+
await hydrateCart(response, { ifRevision: writeRevision });
|
|
1907
1915
|
return response;
|
|
1908
1916
|
} catch (error) {
|
|
1909
1917
|
cart_status.setKey("error", readErrorMessage(error, "Failed to sync cart."));
|
|
@@ -1914,6 +1922,7 @@ function createArkyStore(config) {
|
|
|
1914
1922
|
}
|
|
1915
1923
|
async function addProduct(product, variant, quantity = 1) {
|
|
1916
1924
|
cart_status.setKey("error", null);
|
|
1925
|
+
const writeRevision = nextCartWriteRevision();
|
|
1917
1926
|
try {
|
|
1918
1927
|
const current = cart.get() || await ensureCart();
|
|
1919
1928
|
const response = await client.cart.addItem({
|
|
@@ -1925,7 +1934,7 @@ function createArkyStore(config) {
|
|
|
1925
1934
|
quantity
|
|
1926
1935
|
}
|
|
1927
1936
|
});
|
|
1928
|
-
await hydrateCart(response);
|
|
1937
|
+
await hydrateCart(response, { ifRevision: writeRevision });
|
|
1929
1938
|
await client.activity.track({ type: "cart_added", payload: { product_id: product.id, variant_id: variant.id, quantity } });
|
|
1930
1939
|
return response;
|
|
1931
1940
|
} catch (error) {
|
|
@@ -1934,15 +1943,17 @@ function createArkyStore(config) {
|
|
|
1934
1943
|
}
|
|
1935
1944
|
}
|
|
1936
1945
|
async function setProductQuantity(itemId, quantity) {
|
|
1946
|
+
const writeRevision = nextCartWriteRevision();
|
|
1937
1947
|
const next = product_items.get().map((item) => {
|
|
1938
1948
|
if (item.id !== itemId) return item;
|
|
1939
1949
|
const bounded = item.max_stock ? Math.min(Math.max(1, quantity), item.max_stock) : Math.max(1, quantity);
|
|
1940
1950
|
return { ...item, quantity: bounded };
|
|
1941
1951
|
});
|
|
1942
1952
|
product_items.set(next);
|
|
1943
|
-
return syncCart({ product_items: next });
|
|
1953
|
+
return syncCart({ product_items: next }, writeRevision);
|
|
1944
1954
|
}
|
|
1945
1955
|
async function removeProduct(itemId) {
|
|
1956
|
+
const writeRevision = nextCartWriteRevision();
|
|
1946
1957
|
const item = product_items.get().find((candidate) => candidate.id === itemId);
|
|
1947
1958
|
product_items.set(product_items.get().filter((candidate) => candidate.id !== itemId));
|
|
1948
1959
|
const current = cart.get();
|
|
@@ -1953,21 +1964,24 @@ function createArkyStore(config) {
|
|
|
1953
1964
|
product_id: item.product_id,
|
|
1954
1965
|
variant_id: item.variant_id
|
|
1955
1966
|
});
|
|
1956
|
-
await hydrateCart(response);
|
|
1967
|
+
await hydrateCart(response, { ifRevision: writeRevision });
|
|
1957
1968
|
await client.activity.track({ type: "cart_removed", payload: { product_id: item.product_id, variant_id: item.variant_id } });
|
|
1958
1969
|
return response;
|
|
1959
1970
|
}
|
|
1960
1971
|
async function addServiceItem(item) {
|
|
1972
|
+
const writeRevision = nextCartWriteRevision();
|
|
1961
1973
|
const next = [...service_items.get(), item];
|
|
1962
1974
|
service_items.set(next);
|
|
1963
|
-
return syncCart({ service_items: next });
|
|
1975
|
+
return syncCart({ service_items: next }, writeRevision);
|
|
1964
1976
|
}
|
|
1965
1977
|
async function removeServiceItem(itemId) {
|
|
1978
|
+
const writeRevision = nextCartWriteRevision();
|
|
1966
1979
|
const next = service_items.get().filter((item) => item.id !== itemId);
|
|
1967
1980
|
service_items.set(next);
|
|
1968
|
-
return syncCart({ service_items: next });
|
|
1981
|
+
return syncCart({ service_items: next }, writeRevision);
|
|
1969
1982
|
}
|
|
1970
1983
|
async function clearCart() {
|
|
1984
|
+
const writeRevision = nextCartWriteRevision();
|
|
1971
1985
|
product_items.set([]);
|
|
1972
1986
|
service_items.set([]);
|
|
1973
1987
|
quote.set(null);
|
|
@@ -1976,7 +1990,7 @@ function createArkyStore(config) {
|
|
|
1976
1990
|
const current = cart.get();
|
|
1977
1991
|
if (!current) return null;
|
|
1978
1992
|
const response = await client.cart.clear({ id: current.id });
|
|
1979
|
-
await hydrateCart(response);
|
|
1993
|
+
await hydrateCart(response, { ifRevision: writeRevision });
|
|
1980
1994
|
return response;
|
|
1981
1995
|
}
|
|
1982
1996
|
async function fetchQuote(input = {}) {
|
|
@@ -2744,6 +2758,7 @@ function createArkyStore(config) {
|
|
|
2744
2758
|
setMarket,
|
|
2745
2759
|
setLocale,
|
|
2746
2760
|
setContext,
|
|
2761
|
+
getStoreId: client.getStoreId,
|
|
2747
2762
|
getMarket: currentMarketKey,
|
|
2748
2763
|
getLocale: currentLocale,
|
|
2749
2764
|
cms: {
|
|
@@ -2781,8 +2796,8 @@ function createArkyStore(config) {
|
|
|
2781
2796
|
},
|
|
2782
2797
|
state: atom(null)
|
|
2783
2798
|
},
|
|
2799
|
+
support: client.support,
|
|
2784
2800
|
store: client.store,
|
|
2785
|
-
automation: client.automation,
|
|
2786
2801
|
utils: client.utils
|
|
2787
2802
|
};
|
|
2788
2803
|
}
|