@scryme/sdk 9.65.0 → 9.67.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 +1 -1
- package/dist/{base-DZWqHn_L.d.mts → base-1B2-e5i_.d.mts} +78 -20
- package/dist/{base-DZWqHn_L.d.ts → base-1B2-e5i_.d.ts} +78 -20
- package/dist/{chunk-PPNV4D3M.mjs → chunk-QS5K7GIL.mjs} +284 -445
- package/dist/client.d.mts +149 -87
- package/dist/client.d.ts +149 -87
- package/dist/client.js +160 -394
- package/dist/client.mjs +3 -7
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +285 -448
- package/dist/index.mjs +3 -7
- package/dist/server.d.mts +199 -29
- package/dist/server.d.ts +199 -29
- package/dist/server.js +145 -67
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -30,13 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/client.tsx
|
|
31
31
|
var client_exports = {};
|
|
32
32
|
__export(client_exports, {
|
|
33
|
-
ScrymeAuthProvider: () => ScrymeAuthProvider,
|
|
34
33
|
ScrymeClientSDK: () => ScrymeClientSDK,
|
|
35
|
-
createClientSDK: () => createClientSDK
|
|
36
|
-
useScrymeAuth: () => useScrymeAuth
|
|
34
|
+
createClientSDK: () => createClientSDK
|
|
37
35
|
});
|
|
38
36
|
module.exports = __toCommonJS(client_exports);
|
|
39
|
-
var import_react = require("react");
|
|
40
37
|
var import_axios3 = __toESM(require("axios"));
|
|
41
38
|
|
|
42
39
|
// src/generated/scryme.ts
|
|
@@ -652,6 +649,12 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
652
649
|
options
|
|
653
650
|
);
|
|
654
651
|
};
|
|
652
|
+
const catalogGetProduct = (orgSlug, idOrSlug, options) => {
|
|
653
|
+
return axiosInstance.get(
|
|
654
|
+
`/v3/${orgSlug}/catalog/products/${idOrSlug}`,
|
|
655
|
+
options
|
|
656
|
+
);
|
|
657
|
+
};
|
|
655
658
|
const catalogGetServices = (orgSlug, params, options) => {
|
|
656
659
|
return axiosInstance.get(
|
|
657
660
|
`/v3/${orgSlug}/catalog/services`,
|
|
@@ -928,13 +931,6 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
928
931
|
options
|
|
929
932
|
);
|
|
930
933
|
};
|
|
931
|
-
const customersProvisionZitadel = (orgSlug, provisionZitadelDto, options) => {
|
|
932
|
-
return axiosInstance.post(
|
|
933
|
-
`/v3/${orgSlug}/customers/zitadel/provision`,
|
|
934
|
-
provisionZitadelDto,
|
|
935
|
-
options
|
|
936
|
-
);
|
|
937
|
-
};
|
|
938
934
|
const customersGetCustomers = (orgSlug, params, options) => {
|
|
939
935
|
return axiosInstance.get(
|
|
940
936
|
`/v3/${orgSlug}/customers`,
|
|
@@ -958,6 +954,13 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
958
954
|
options
|
|
959
955
|
);
|
|
960
956
|
};
|
|
957
|
+
const customersRefreshSession = (orgSlug, options) => {
|
|
958
|
+
return axiosInstance.post(
|
|
959
|
+
`/v3/${orgSlug}/customers/auth/refresh`,
|
|
960
|
+
void 0,
|
|
961
|
+
options
|
|
962
|
+
);
|
|
963
|
+
};
|
|
961
964
|
const customersGetCurrentSession = (orgSlug, options) => {
|
|
962
965
|
return axiosInstance.get(
|
|
963
966
|
`/v3/${orgSlug}/customers/auth/session`,
|
|
@@ -1896,7 +1899,7 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
1896
1899
|
}
|
|
1897
1900
|
);
|
|
1898
1901
|
};
|
|
1899
|
-
return { inventoryVerifyIntegrity, inventoryFixIntegrity, inventoryGetInventory, inventoryTraceBatch, inventorySplitBatch, inventoryMergeBatches, inventoryCreateAssembly, inventoryCompleteAssembly, inventoryRequestAdjustment, inventoryGetAdjustments, inventoryApproveAdjustment, inventoryRejectAdjustment, inventoryGetLeadTime, inventoryGetWasteAnalysis, inventoryCheckB2BAvailability, inventoryUnpackBatch, inventoryScanUnpackBatch, inventoryQuickStockInquiry, expenseControllerCreateExpense, expenseControllerGetExpenses, expenseControllerGetExpenseCategories, expenseControllerGetExpense, pettyCashControllerCreateFund, pettyCashControllerGetFunds, pettyCashControllerGetFund, pettyCashControllerTopUpFund, pettyCashControllerGetFundTransactions, utilityAccountControllerCreateAccount, utilityAccountControllerGetAccounts, utilityAccountControllerGetAccount, accountingInitialize, accountingGetProfitLoss, accountingGetBalanceSheet, accountingGetCashFlow, accountingGetTaxSummary, invoiceControllerCreateInvoice, invoiceControllerGetInvoices, invoiceControllerGetInvoice, invoiceControllerUpdateInvoice, invoiceControllerDeleteInvoice, invoiceControllerFinalizeInvoice, invoiceControllerGetTemplates, invoiceControllerCreateTemplate, invoiceControllerGetConfig, invoiceControllerUpdateConfig, publicInvoiceControllerDownloadInvoice, publicInvoiceControllerDownloadInvoiceByTransaction, publicInvoiceControllerDownloadReceipt, publicInvoiceControllerGeneratePublicLink, authExchangeToken, authControllerHandleOAuth2, adminControllerGetStats, adminControllerListOrganizations, adminControllerCreateOrganization, adminControllerGetOrganizationDetails, adminControllerUpdateOrganization, adminControllerDeleteOrganization, adminControllerListMembers, adminControllerListUsers, adminControllerBanUser, adminControllerUnbanUser, adminControllerListConnectedApps, adminControllerListSystemLogs, adminControllerListGlobalSettings, adminControllerSetGlobalSetting, adminControllerDeleteGlobalSetting, adminControllerListTiers, adminControllerDefineTier, adminControllerDeleteTier, adminControllerGetOrganizationSubscription, adminControllerUpdateOrganizationSubscription, adminControllerListSystemPayments, adminControllerRecordCustomPayment, adminControllerListIntegrationDefinitions, adminControllerCreateIntegrationDefinition, adminControllerUpdateIntegrationDefinition, adminControllerDeleteIntegrationDefinition, adminControllerListActiveOrganizationIntegrations, webhooksCreate, webhooksList, webhooksDelete, windmillCallbackControllerHandleCallback, windmillCallbackControllerHandleApprovalCallback, windmillCallbackControllerHandleBakeryDisposalCallback, windmillCallbackControllerHandleOutcomeCallback, catalogGetProducts, catalogCreateProduct, catalogGetServices, catalogUpdateProduct, catalogUpdateSupplierVariant, catalogGetPriceChangeRequests, catalogReviewPriceChangeRequest, servicesCreateCategory, servicesGetCategories, servicesUpdateCategory, servicesDeleteCategory, servicesCreateService, servicesGetServices, servicesGetCurrentMemberShifts, servicesGetShifts, servicesGetService, servicesUpdateService, servicesDeleteService, servicesCreateResource, servicesGetResources, servicesUpdateResource, servicesDeleteResource, servicesCreateBooking, servicesGetBookings, servicesGetBooking, servicesUpdateBookingStatus, servicesCompleteBooking, servicesCreateShift, servicesGetStaffShifts, servicesAddBreak, servicesRegisterCustomerApp, servicesGetUtilization, servicesGetPerformance, servicesGetFunnel, publicServicesListServices, publicServicesGetCategories, publicServicesGetService, publicServicesGetAvailability, publicServicesRequestOtp, publicServicesVerifyOtp, publicServicesCreatePublicBooking,
|
|
1902
|
+
return { inventoryVerifyIntegrity, inventoryFixIntegrity, inventoryGetInventory, inventoryTraceBatch, inventorySplitBatch, inventoryMergeBatches, inventoryCreateAssembly, inventoryCompleteAssembly, inventoryRequestAdjustment, inventoryGetAdjustments, inventoryApproveAdjustment, inventoryRejectAdjustment, inventoryGetLeadTime, inventoryGetWasteAnalysis, inventoryCheckB2BAvailability, inventoryUnpackBatch, inventoryScanUnpackBatch, inventoryQuickStockInquiry, expenseControllerCreateExpense, expenseControllerGetExpenses, expenseControllerGetExpenseCategories, expenseControllerGetExpense, pettyCashControllerCreateFund, pettyCashControllerGetFunds, pettyCashControllerGetFund, pettyCashControllerTopUpFund, pettyCashControllerGetFundTransactions, utilityAccountControllerCreateAccount, utilityAccountControllerGetAccounts, utilityAccountControllerGetAccount, accountingInitialize, accountingGetProfitLoss, accountingGetBalanceSheet, accountingGetCashFlow, accountingGetTaxSummary, invoiceControllerCreateInvoice, invoiceControllerGetInvoices, invoiceControllerGetInvoice, invoiceControllerUpdateInvoice, invoiceControllerDeleteInvoice, invoiceControllerFinalizeInvoice, invoiceControllerGetTemplates, invoiceControllerCreateTemplate, invoiceControllerGetConfig, invoiceControllerUpdateConfig, publicInvoiceControllerDownloadInvoice, publicInvoiceControllerDownloadInvoiceByTransaction, publicInvoiceControllerDownloadReceipt, publicInvoiceControllerGeneratePublicLink, authExchangeToken, authControllerHandleOAuth2, adminControllerGetStats, adminControllerListOrganizations, adminControllerCreateOrganization, adminControllerGetOrganizationDetails, adminControllerUpdateOrganization, adminControllerDeleteOrganization, adminControllerListMembers, adminControllerListUsers, adminControllerBanUser, adminControllerUnbanUser, adminControllerListConnectedApps, adminControllerListSystemLogs, adminControllerListGlobalSettings, adminControllerSetGlobalSetting, adminControllerDeleteGlobalSetting, adminControllerListTiers, adminControllerDefineTier, adminControllerDeleteTier, adminControllerGetOrganizationSubscription, adminControllerUpdateOrganizationSubscription, adminControllerListSystemPayments, adminControllerRecordCustomPayment, adminControllerListIntegrationDefinitions, adminControllerCreateIntegrationDefinition, adminControllerUpdateIntegrationDefinition, adminControllerDeleteIntegrationDefinition, adminControllerListActiveOrganizationIntegrations, webhooksCreate, webhooksList, webhooksDelete, windmillCallbackControllerHandleCallback, windmillCallbackControllerHandleApprovalCallback, windmillCallbackControllerHandleBakeryDisposalCallback, windmillCallbackControllerHandleOutcomeCallback, catalogGetProducts, catalogCreateProduct, catalogGetProduct, catalogGetServices, catalogUpdateProduct, catalogUpdateSupplierVariant, catalogGetPriceChangeRequests, catalogReviewPriceChangeRequest, servicesCreateCategory, servicesGetCategories, servicesUpdateCategory, servicesDeleteCategory, servicesCreateService, servicesGetServices, servicesGetCurrentMemberShifts, servicesGetShifts, servicesGetService, servicesUpdateService, servicesDeleteService, servicesCreateResource, servicesGetResources, servicesUpdateResource, servicesDeleteResource, servicesCreateBooking, servicesGetBookings, servicesGetBooking, servicesUpdateBookingStatus, servicesCompleteBooking, servicesCreateShift, servicesGetStaffShifts, servicesAddBreak, servicesRegisterCustomerApp, servicesGetUtilization, servicesGetPerformance, servicesGetFunnel, publicServicesListServices, publicServicesGetCategories, publicServicesGetService, publicServicesGetAvailability, publicServicesRequestOtp, publicServicesVerifyOtp, publicServicesCreatePublicBooking, customersGetCustomers, customersRegister, customersLogin, customersRefreshSession, customersGetCurrentSession, customersGetSessions, customersRevokeAllSessions, customersRevokeSession, customersUpdate, customersGetCustomerById, customersDelete, customersGetAddresses, customersAddAddress, businessAccountControllerCreate, businessAccountControllerGetOne, crmControllerCreateRecord, crmControllerGetRecord, crmControllerUpdateRecord, crmControllerCreateNote, crmControllerGetRecordNotes, crmControllerCreateActivity, crmControllerGetTimeline, crmControllerCreateObject, crmControllerListObjects, crmControllerCreateField, crmControllerListFields, crmControllerCreateRelationship, crmControllerListRelationships, crmControllerCreateAssociation, crmControllerListRecordAssociations, loyaltyRedeemReward, loyaltyGetCustomerStatus, loyaltyValidateVoucher, ordersCreateOrder, ordersGetOrders, ordersUpdateStatus, ordersRequestB2BQuote, ordersConvertQuoteToOrder, paymentsControllerHandleStkCallback, pOSProvision, pOSLogin, pOSGetMe, pOSProcessSale, pOSSync, pOSGetTransactions, pOSRegisterPettyCash, pOSGetPettyCashFunds, pOSGetPettyCashTransactions, membersControllerGetMembers, membersControllerCreateMember, membersControllerGetMember, membersControllerUpdateMember, membersControllerDeleteMember, membersControllerGetMemberActivity, membersControllerUpdateStatus, membersControllerAdminCheckOut, terminalMembersControllerLogin, invitationsList, invitationsCreate, invitationsRevoke, invitationsAccept, roleManagementControllerGetCustomRoles, roleManagementControllerCreateCustomRole, roleManagementControllerUpdateCustomRole, roleManagementControllerDeleteCustomRole, roleManagementControllerGetPermissionSets, roleManagementControllerCreatePermissionSet, roleManagementControllerGetRoleGroups, roleManagementControllerCreateRoleGroup, roleManagementControllerAssignRoles, roleManagementControllerRemoveRoles, departmentsList, departmentsCreate, departmentsGet, departmentsUpdate, departmentsDelete, departmentsAddMember, departmentsRemoveMember, attendanceControllerGetLogs, attendanceControllerCheckIn, attendanceControllerCheckOut, attendanceControllerGetMyStatus, attendanceControllerGetStatus, announcementControllerBroadcastAnnouncement, cartControllerGetCart, cartControllerClearCart, cartControllerAddToCart, cartControllerRemoveFromCart, favoritesControllerGetFavorites, favoritesControllerAddFavorite, favoritesControllerRemoveFavorite, stockingGetPurchases, stockingCreatePurchase, stockingReceivePurchase, stockingGetTransfers, stockingCreateTransfer, stockingShipTransfer, stockingReceiveTransfer, stockingGetRequests, stockingGetPendingDispatch, stockingDispatchOrders, stockingGetActiveDeliveries, stockingReconcilePod, stockingGetPhysicalReconciliations, stockingSubmitPhysicalReconciliation, stockingGetReconciliationReport, stockingGetPartners, stockingCreatePartner, stockingGetPartner, stockingUpdatePartner, stockingAdjustPartnerWallet, standalonePosControllerCreateSetupKey, standalonePosControllerActivateDevice, standalonePosControllerValidateKey, standalonePosControllerLinkOrganization, b2BGetCatalog, b2BGetInvoices, b2BGetOrders, b2BCreateOrder, b2BCreateQuote, crmIntegrationsGetAuthUrl, crmIntegrationsHandleCallback, crmIntegrationsHandleWebhook, crmIntegrationsReplyToActivity, unitsGetUnits, strapiCreateConnection, strapiListConnections, strapiGetConnection, strapiUpdateConnection, strapiDeleteConnection, strapiTriggerSync, strapiEnqueueSync, strapiGetWebhookLogs, strapiGetSyncLogs, strapiExchangeCustomerToken, strapiRegisterCustomer, strapiReceiveWebhook, analyticsControllerGetDashboardAnalytics, analyticsControllerGetResourceUtilization };
|
|
1900
1903
|
};
|
|
1901
1904
|
|
|
1902
1905
|
// src/base.ts
|
|
@@ -1935,6 +1938,7 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
1935
1938
|
"webhooksList",
|
|
1936
1939
|
"webhooksDelete",
|
|
1937
1940
|
"catalogGetProducts",
|
|
1941
|
+
"catalogGetProduct",
|
|
1938
1942
|
"catalogCreateProduct",
|
|
1939
1943
|
"catalogGetServices",
|
|
1940
1944
|
"catalogUpdateProduct",
|
|
@@ -1968,7 +1972,6 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
1968
1972
|
"servicesGetUtilization",
|
|
1969
1973
|
"servicesGetPerformance",
|
|
1970
1974
|
"servicesGetFunnel",
|
|
1971
|
-
"customersProvisionZitadel",
|
|
1972
1975
|
"customersGetCustomers",
|
|
1973
1976
|
"customersRegister",
|
|
1974
1977
|
"customersUpdate",
|
|
@@ -1977,6 +1980,10 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
1977
1980
|
"customersGetAddresses",
|
|
1978
1981
|
"customersAddAddress",
|
|
1979
1982
|
"customersGetCurrentSession",
|
|
1983
|
+
"customersGetSessions",
|
|
1984
|
+
"customersRevokeSession",
|
|
1985
|
+
"customersRevokeAllSessions",
|
|
1986
|
+
"customersRefreshSession",
|
|
1980
1987
|
"businessAccountControllerCreate",
|
|
1981
1988
|
"businessAccountControllerGetOne",
|
|
1982
1989
|
"crmControllerCreateRecord",
|
|
@@ -2045,6 +2052,7 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2045
2052
|
]);
|
|
2046
2053
|
var catalogMapping = {
|
|
2047
2054
|
getProducts: "catalogGetProducts",
|
|
2055
|
+
getProduct: "catalogGetProduct",
|
|
2048
2056
|
createProduct: "catalogCreateProduct",
|
|
2049
2057
|
getServices: "catalogGetServices",
|
|
2050
2058
|
updateProduct: "catalogUpdateProduct",
|
|
@@ -2343,7 +2351,6 @@ var adminMapping = {
|
|
|
2343
2351
|
handleWindmillApprovalCallback: "windmillCallbackControllerHandleApprovalCallback",
|
|
2344
2352
|
handleWindmillBakeryDisposalCallback: "windmillCallbackControllerHandleBakeryDisposalCallback",
|
|
2345
2353
|
handleWindmillOutcomeCallback: "windmillCallbackControllerHandleOutcomeCallback",
|
|
2346
|
-
provisionZitadel: "customersProvisionZitadel",
|
|
2347
2354
|
getCustomers: "customersGetCustomers",
|
|
2348
2355
|
registerCustomer: "customersRegister",
|
|
2349
2356
|
updateCustomer: "customersUpdate",
|
|
@@ -2465,7 +2472,6 @@ var getScrymeV3API2 = (axiosInstance, defaultOrgSlug) => {
|
|
|
2465
2472
|
};
|
|
2466
2473
|
|
|
2467
2474
|
// src/client.tsx
|
|
2468
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
2469
2475
|
var InMemoryStorage = class {
|
|
2470
2476
|
constructor() {
|
|
2471
2477
|
this.cache = /* @__PURE__ */ new Map();
|
|
@@ -2484,6 +2490,10 @@ var SCRYME_SESSION_TOKEN_KEY = "scryme_session_token";
|
|
|
2484
2490
|
var SCRYME_USER_KEY = "scryme_user";
|
|
2485
2491
|
var SCRYME_EXPIRES_AT_KEY = "scryme_expires_at";
|
|
2486
2492
|
var ScrymeClientSDK = class {
|
|
2493
|
+
/**
|
|
2494
|
+
* Initializes the ScrymeClientSDK.
|
|
2495
|
+
* @param config Application and organization configuration parameters.
|
|
2496
|
+
*/
|
|
2487
2497
|
constructor(config) {
|
|
2488
2498
|
if (!config || !config.clientId || !config.orgSlug) {
|
|
2489
2499
|
throw new Error(
|
|
@@ -2548,8 +2558,8 @@ var ScrymeClientSDK = class {
|
|
|
2548
2558
|
state.user = null;
|
|
2549
2559
|
}
|
|
2550
2560
|
}
|
|
2551
|
-
notify("INITIAL_SESSION");
|
|
2552
2561
|
}
|
|
2562
|
+
notify("INITIAL_SESSION");
|
|
2553
2563
|
} catch (e) {
|
|
2554
2564
|
console.error("Failed to initialize Scryme Client SDK session:", e);
|
|
2555
2565
|
}
|
|
@@ -2597,13 +2607,13 @@ var ScrymeClientSDK = class {
|
|
|
2597
2607
|
};
|
|
2598
2608
|
this.axiosInstance.interceptors.request.use(async (req) => {
|
|
2599
2609
|
await initPromise;
|
|
2600
|
-
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh")
|
|
2610
|
+
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh"));
|
|
2601
2611
|
if (!isAuthTokenRequest) {
|
|
2602
2612
|
const isExpired = !state.token || state.expiresAt && Date.now() >= (state.expiresAt || 0) - 3e4;
|
|
2603
2613
|
if (isExpired) {
|
|
2604
2614
|
if (state.token) {
|
|
2605
2615
|
try {
|
|
2606
|
-
await this.auth.refreshSession();
|
|
2616
|
+
await this.customer.auth.refreshSession();
|
|
2607
2617
|
} catch (e) {
|
|
2608
2618
|
console.error(
|
|
2609
2619
|
"Proactive customer session refresh failed in request interceptor:",
|
|
@@ -2631,12 +2641,12 @@ var ScrymeClientSDK = class {
|
|
|
2631
2641
|
(response) => response,
|
|
2632
2642
|
async (error) => {
|
|
2633
2643
|
const originalRequest = error.config;
|
|
2634
|
-
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh")
|
|
2644
|
+
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh"));
|
|
2635
2645
|
if (error.response && error.response.status === 401 && originalRequest && !originalRequest._retry && !isAuthTokenRequest) {
|
|
2636
2646
|
originalRequest._retry = true;
|
|
2637
2647
|
try {
|
|
2638
2648
|
if (state.token) {
|
|
2639
|
-
await this.auth.refreshSession();
|
|
2649
|
+
await this.customer.auth.refreshSession();
|
|
2640
2650
|
if (state.token) {
|
|
2641
2651
|
originalRequest.headers["Authorization"] = `Bearer ${state.token}`;
|
|
2642
2652
|
}
|
|
@@ -2656,7 +2666,54 @@ var ScrymeClientSDK = class {
|
|
|
2656
2666
|
}
|
|
2657
2667
|
);
|
|
2658
2668
|
this.api = getScrymeV3API2(this.axiosInstance, config.orgSlug);
|
|
2659
|
-
|
|
2669
|
+
const baseCatalog = buildModule(this.api, config.orgSlug, catalogMapping);
|
|
2670
|
+
this.catalog = {
|
|
2671
|
+
...baseCatalog,
|
|
2672
|
+
getProduct: async (idOrSlug, options) => {
|
|
2673
|
+
const response = await this.catalog.getProducts(void 0, options);
|
|
2674
|
+
const products = response.data || [];
|
|
2675
|
+
const product = products.find((p) => {
|
|
2676
|
+
if (typeof idOrSlug === "string") {
|
|
2677
|
+
return p.id === idOrSlug || p.slug === idOrSlug;
|
|
2678
|
+
} else {
|
|
2679
|
+
const { id, slug } = idOrSlug;
|
|
2680
|
+
if (id && p.id === id) return true;
|
|
2681
|
+
if (slug && p.slug === slug) return true;
|
|
2682
|
+
return false;
|
|
2683
|
+
}
|
|
2684
|
+
});
|
|
2685
|
+
if (!product) {
|
|
2686
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
2687
|
+
throw new Error(`Product not found matching criteria: ${criteria}`);
|
|
2688
|
+
}
|
|
2689
|
+
return {
|
|
2690
|
+
...response,
|
|
2691
|
+
data: product
|
|
2692
|
+
};
|
|
2693
|
+
},
|
|
2694
|
+
getService: async (idOrSlug, options) => {
|
|
2695
|
+
const response = await this.catalog.getServices(void 0, options);
|
|
2696
|
+
const services = response.data || [];
|
|
2697
|
+
const service = services.find((s) => {
|
|
2698
|
+
if (typeof idOrSlug === "string") {
|
|
2699
|
+
return s.id === idOrSlug || s.slug === idOrSlug;
|
|
2700
|
+
} else {
|
|
2701
|
+
const { id, slug } = idOrSlug;
|
|
2702
|
+
if (id && s.id === id) return true;
|
|
2703
|
+
if (slug && s.slug === slug) return true;
|
|
2704
|
+
return false;
|
|
2705
|
+
}
|
|
2706
|
+
});
|
|
2707
|
+
if (!service) {
|
|
2708
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
2709
|
+
throw new Error(`Service not found matching criteria: ${criteria}`);
|
|
2710
|
+
}
|
|
2711
|
+
return {
|
|
2712
|
+
...response,
|
|
2713
|
+
data: service
|
|
2714
|
+
};
|
|
2715
|
+
}
|
|
2716
|
+
};
|
|
2660
2717
|
this.inventory = buildModule(this.api, config.orgSlug, inventoryMapping);
|
|
2661
2718
|
this.orders = buildModule(this.api, config.orgSlug, ordersMapping);
|
|
2662
2719
|
this.crm = buildModule(this.api, config.orgSlug, crmMapping);
|
|
@@ -2667,7 +2724,7 @@ var ScrymeClientSDK = class {
|
|
|
2667
2724
|
this.admin = buildModule(this.api, config.orgSlug, adminMapping);
|
|
2668
2725
|
this.cart = {
|
|
2669
2726
|
get: async (params) => {
|
|
2670
|
-
return this.orders.getCart(params
|
|
2727
|
+
return this.orders.getCart(params);
|
|
2671
2728
|
},
|
|
2672
2729
|
add: async (dto) => {
|
|
2673
2730
|
return this.orders.addToCart(dto);
|
|
@@ -2676,11 +2733,11 @@ var ScrymeClientSDK = class {
|
|
|
2676
2733
|
return this.orders.removeFromCart(dto);
|
|
2677
2734
|
},
|
|
2678
2735
|
clear: async (params) => {
|
|
2679
|
-
return this.orders.clearCart(params
|
|
2736
|
+
return this.orders.clearCart(params);
|
|
2680
2737
|
},
|
|
2681
2738
|
update: async (dto) => {
|
|
2682
2739
|
const response = await this.orders.getCart({
|
|
2683
|
-
sessionId: dto.sessionId
|
|
2740
|
+
sessionId: dto.sessionId || ""
|
|
2684
2741
|
});
|
|
2685
2742
|
const data = response.data;
|
|
2686
2743
|
const items = data?.data?.items || data?.items || [];
|
|
@@ -2701,7 +2758,7 @@ var ScrymeClientSDK = class {
|
|
|
2701
2758
|
productId: dto.productId,
|
|
2702
2759
|
variantId: dto.variantId,
|
|
2703
2760
|
serviceId: dto.serviceId,
|
|
2704
|
-
sessionId: dto.sessionId,
|
|
2761
|
+
sessionId: dto.sessionId || "",
|
|
2705
2762
|
customerId: dto.customerId
|
|
2706
2763
|
});
|
|
2707
2764
|
} else {
|
|
@@ -2721,12 +2778,12 @@ var ScrymeClientSDK = class {
|
|
|
2721
2778
|
}
|
|
2722
2779
|
},
|
|
2723
2780
|
getItems: async (params) => {
|
|
2724
|
-
const res = await this.orders.getCart(params
|
|
2781
|
+
const res = await this.orders.getCart(params);
|
|
2725
2782
|
const data = res?.data || res;
|
|
2726
2783
|
return data?.items || data?.data?.items || [];
|
|
2727
2784
|
},
|
|
2728
2785
|
getTotals: async (params) => {
|
|
2729
|
-
const res = await this.orders.getCart(params
|
|
2786
|
+
const res = await this.orders.getCart(params);
|
|
2730
2787
|
const data = res?.data || res;
|
|
2731
2788
|
const items = data?.items || data?.data?.items || [];
|
|
2732
2789
|
const itemsCount = items.reduce(
|
|
@@ -2768,122 +2825,31 @@ var ScrymeClientSDK = class {
|
|
|
2768
2825
|
return orderResponse?.data || orderResponse;
|
|
2769
2826
|
}
|
|
2770
2827
|
};
|
|
2771
|
-
|
|
2772
|
-
getProfile: async () => {
|
|
2773
|
-
return this.auth.getCurrentSession();
|
|
2774
|
-
},
|
|
2775
|
-
updateProfile: async (dto) => {
|
|
2776
|
-
const session = await this.auth.getSession();
|
|
2777
|
-
const user = session.user;
|
|
2778
|
-
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2779
|
-
if (!customerId) throw new Error("No authenticated customer found.");
|
|
2780
|
-
return this.admin.updateCustomer(customerId, dto);
|
|
2781
|
-
},
|
|
2782
|
-
getAddresses: async () => {
|
|
2783
|
-
const session = await this.auth.getSession();
|
|
2784
|
-
const user = session.user;
|
|
2785
|
-
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2786
|
-
if (!customerId) throw new Error("No authenticated customer found.");
|
|
2787
|
-
return this.admin.getCustomerAddresses(customerId);
|
|
2788
|
-
},
|
|
2789
|
-
addAddress: async (dto) => {
|
|
2790
|
-
const session = await this.auth.getSession();
|
|
2791
|
-
const user = session.user;
|
|
2792
|
-
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2793
|
-
if (!customerId) throw new Error("No authenticated customer found.");
|
|
2794
|
-
return this.admin.addCustomerAddress(customerId, dto);
|
|
2795
|
-
}
|
|
2796
|
-
};
|
|
2797
|
-
this.bookings = {
|
|
2798
|
-
create: async (dto) => {
|
|
2799
|
-
return this.catalog.createBooking(dto);
|
|
2800
|
-
},
|
|
2801
|
-
get: async (id) => {
|
|
2802
|
-
return this.catalog.getBooking(id);
|
|
2803
|
-
},
|
|
2804
|
-
list: async () => {
|
|
2805
|
-
return this.catalog.getBookings();
|
|
2806
|
-
},
|
|
2807
|
-
cancel: async (id) => {
|
|
2808
|
-
return this.catalog.updateBookingStatus(id, "CANCELLED");
|
|
2809
|
-
}
|
|
2810
|
-
};
|
|
2811
|
-
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
2812
|
-
this.auth = {
|
|
2813
|
-
...baseAuth,
|
|
2828
|
+
const customerAuth = {
|
|
2814
2829
|
signUp: async (dto) => {
|
|
2815
2830
|
return this.api.customersRegister(config.orgSlug, dto);
|
|
2816
2831
|
},
|
|
2817
|
-
authenticate: async () => {
|
|
2818
|
-
return performExchange();
|
|
2819
|
-
},
|
|
2820
2832
|
signIn: async (credentials) => {
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
const response2 = await import_axios3.default.post(postUrl, credentials);
|
|
2825
|
-
const data2 = response2.data;
|
|
2826
|
-
const token2 = data2?.session?.token || data2?.token || null;
|
|
2827
|
-
const user2 = data2?.user || null;
|
|
2828
|
-
if (token2) {
|
|
2829
|
-
state.token = token2;
|
|
2830
|
-
state.user = user2;
|
|
2831
|
-
const jwtExp = getJwtExpiry(token2);
|
|
2832
|
-
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token2);
|
|
2833
|
-
if (jwtExp) {
|
|
2834
|
-
state.expiresAt = jwtExp;
|
|
2835
|
-
await storage.setItem(
|
|
2836
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
2837
|
-
String(state.expiresAt)
|
|
2838
|
-
);
|
|
2839
|
-
} else {
|
|
2840
|
-
delete state.expiresAt;
|
|
2841
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
2842
|
-
}
|
|
2843
|
-
if (user2) {
|
|
2844
|
-
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(user2));
|
|
2845
|
-
}
|
|
2846
|
-
notify("SIGNED_IN");
|
|
2847
|
-
return data2;
|
|
2848
|
-
} else {
|
|
2849
|
-
throw new Error("No token returned");
|
|
2850
|
-
}
|
|
2851
|
-
} catch (e) {
|
|
2852
|
-
}
|
|
2853
|
-
const response = await this.axiosInstance.post(
|
|
2854
|
-
`/${config.orgSlug}/customers/auth/login`,
|
|
2855
|
-
credentials
|
|
2856
|
-
);
|
|
2857
|
-
const data = response.data?.data || response.data;
|
|
2858
|
-
const token = data?.token || null;
|
|
2859
|
-
const user = data?.session || null;
|
|
2833
|
+
const res = await this.api.customersLogin(config.orgSlug, credentials);
|
|
2834
|
+
const authData = res.data;
|
|
2835
|
+
const token = authData?.accessToken || authData?.token;
|
|
2860
2836
|
if (token) {
|
|
2861
2837
|
state.token = token;
|
|
2862
|
-
state.user = user;
|
|
2838
|
+
state.user = authData?.user || authData?.customer || authData?.session;
|
|
2863
2839
|
const jwtExp = getJwtExpiry(token);
|
|
2840
|
+
if (jwtExp) state.expiresAt = jwtExp;
|
|
2864
2841
|
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
2865
|
-
if (
|
|
2866
|
-
state.
|
|
2867
|
-
await storage.setItem(
|
|
2868
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
2869
|
-
String(state.expiresAt)
|
|
2870
|
-
);
|
|
2871
|
-
} else {
|
|
2872
|
-
delete state.expiresAt;
|
|
2873
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
2842
|
+
if (state.user) {
|
|
2843
|
+
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(state.user));
|
|
2874
2844
|
}
|
|
2875
|
-
if (
|
|
2876
|
-
await storage.setItem(
|
|
2845
|
+
if (state.expiresAt) {
|
|
2846
|
+
await storage.setItem(SCRYME_EXPIRES_AT_KEY, String(state.expiresAt));
|
|
2877
2847
|
}
|
|
2878
2848
|
notify("SIGNED_IN");
|
|
2879
2849
|
}
|
|
2880
|
-
return
|
|
2850
|
+
return authData;
|
|
2881
2851
|
},
|
|
2882
2852
|
signOut: async () => {
|
|
2883
|
-
try {
|
|
2884
|
-
await this.axiosInstance.post("/auth/sign-out");
|
|
2885
|
-
} catch {
|
|
2886
|
-
}
|
|
2887
2853
|
state.token = null;
|
|
2888
2854
|
state.user = null;
|
|
2889
2855
|
delete state.expiresAt;
|
|
@@ -2898,13 +2864,6 @@ var ScrymeClientSDK = class {
|
|
|
2898
2864
|
},
|
|
2899
2865
|
onAuthStateChange: (callback) => {
|
|
2900
2866
|
listeners.add(callback);
|
|
2901
|
-
initPromise.then(() => {
|
|
2902
|
-
try {
|
|
2903
|
-
callback("INITIAL_SESSION", { ...state });
|
|
2904
|
-
} catch (e) {
|
|
2905
|
-
console.error("Error in immediate auth state listener call:", e);
|
|
2906
|
-
}
|
|
2907
|
-
});
|
|
2908
2867
|
return {
|
|
2909
2868
|
unsubscribe: () => {
|
|
2910
2869
|
listeners.delete(callback);
|
|
@@ -2912,86 +2871,89 @@ var ScrymeClientSDK = class {
|
|
|
2912
2871
|
};
|
|
2913
2872
|
},
|
|
2914
2873
|
getSessions: async () => {
|
|
2915
|
-
const res = await this.
|
|
2916
|
-
`/${config.orgSlug}/customers/auth/sessions`
|
|
2917
|
-
);
|
|
2874
|
+
const res = await this.api.customersGetSessions(config.orgSlug);
|
|
2918
2875
|
return res.data?.data || res.data;
|
|
2919
2876
|
},
|
|
2920
2877
|
revokeSession: async (id) => {
|
|
2921
|
-
|
|
2922
|
-
`/${config.orgSlug}/customers/auth/sessions/${id}`
|
|
2923
|
-
);
|
|
2924
|
-
return res.data?.data || res.data;
|
|
2878
|
+
return this.api.customersRevokeSession(config.orgSlug, id);
|
|
2925
2879
|
},
|
|
2926
2880
|
revokeAllSessions: async (mode) => {
|
|
2927
|
-
|
|
2928
|
-
const res = await this.axiosInstance.delete(url);
|
|
2929
|
-
return res.data?.data || res.data;
|
|
2881
|
+
return this.api.customersRevokeAllSessions(config.orgSlug, { mode });
|
|
2930
2882
|
},
|
|
2931
2883
|
getCurrentSession: async () => {
|
|
2932
|
-
const res = await this.
|
|
2933
|
-
`/${config.orgSlug}/customers/auth/session`
|
|
2934
|
-
);
|
|
2884
|
+
const res = await this.api.customersGetCurrentSession(config.orgSlug);
|
|
2935
2885
|
return res.data?.data || res.data;
|
|
2936
2886
|
},
|
|
2937
2887
|
refreshSession: async () => {
|
|
2938
|
-
const
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
const data = response.data?.data || response.data;
|
|
2942
|
-
const token = data?.token || null;
|
|
2943
|
-
const user = data?.session || null;
|
|
2888
|
+
const res = await this.api.customersRefreshSession(config.orgSlug);
|
|
2889
|
+
const authData = res.data;
|
|
2890
|
+
const token = authData?.accessToken || authData?.token;
|
|
2944
2891
|
if (token) {
|
|
2945
2892
|
state.token = token;
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
2949
|
-
if (jwtExp) {
|
|
2950
|
-
state.expiresAt = jwtExp;
|
|
2951
|
-
await storage.setItem(
|
|
2952
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
2953
|
-
String(state.expiresAt)
|
|
2954
|
-
);
|
|
2955
|
-
} else {
|
|
2956
|
-
delete state.expiresAt;
|
|
2957
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
2958
|
-
}
|
|
2959
|
-
if (user) {
|
|
2960
|
-
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(user));
|
|
2893
|
+
if (authData?.user || authData?.customer) {
|
|
2894
|
+
state.user = authData.user || authData.customer;
|
|
2961
2895
|
}
|
|
2962
|
-
notify("SIGNED_IN");
|
|
2963
|
-
}
|
|
2964
|
-
return data;
|
|
2965
|
-
},
|
|
2966
|
-
swapZitadel: async (zitadelToken) => {
|
|
2967
|
-
const response = await this.axiosInstance.post(
|
|
2968
|
-
`/${config.orgSlug}/customers/auth/swap-zitadel`,
|
|
2969
|
-
{ zitadelToken }
|
|
2970
|
-
);
|
|
2971
|
-
const data = response.data?.data || response.data;
|
|
2972
|
-
const token = data?.token || null;
|
|
2973
|
-
const user = data?.session || null;
|
|
2974
|
-
if (token) {
|
|
2975
|
-
state.token = token;
|
|
2976
|
-
state.user = user;
|
|
2977
2896
|
const jwtExp = getJwtExpiry(token);
|
|
2897
|
+
if (jwtExp) state.expiresAt = jwtExp;
|
|
2978
2898
|
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
2979
|
-
if (
|
|
2980
|
-
state.
|
|
2981
|
-
await storage.setItem(
|
|
2982
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
2983
|
-
String(state.expiresAt)
|
|
2984
|
-
);
|
|
2985
|
-
} else {
|
|
2986
|
-
delete state.expiresAt;
|
|
2987
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
2899
|
+
if (state.user) {
|
|
2900
|
+
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(state.user));
|
|
2988
2901
|
}
|
|
2989
|
-
if (
|
|
2990
|
-
await storage.setItem(
|
|
2902
|
+
if (state.expiresAt) {
|
|
2903
|
+
await storage.setItem(SCRYME_EXPIRES_AT_KEY, String(state.expiresAt));
|
|
2991
2904
|
}
|
|
2992
2905
|
notify("SIGNED_IN");
|
|
2993
2906
|
}
|
|
2994
|
-
return
|
|
2907
|
+
return authData;
|
|
2908
|
+
}
|
|
2909
|
+
};
|
|
2910
|
+
this.customer = {
|
|
2911
|
+
getProfile: async () => {
|
|
2912
|
+
return this.customer.auth.getCurrentSession();
|
|
2913
|
+
},
|
|
2914
|
+
updateProfile: async (dto) => {
|
|
2915
|
+
const session = await this.auth.getSession();
|
|
2916
|
+
const user = session.user;
|
|
2917
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2918
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
2919
|
+
return this.admin.updateCustomer(customerId, dto);
|
|
2920
|
+
},
|
|
2921
|
+
getAddresses: async () => {
|
|
2922
|
+
const session = await this.auth.getSession();
|
|
2923
|
+
const user = session.user;
|
|
2924
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2925
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
2926
|
+
return this.admin.getCustomerAddresses(customerId);
|
|
2927
|
+
},
|
|
2928
|
+
addAddress: async (dto) => {
|
|
2929
|
+
const session = await this.auth.getSession();
|
|
2930
|
+
const user = session.user;
|
|
2931
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2932
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
2933
|
+
return this.admin.addCustomerAddress(customerId, dto);
|
|
2934
|
+
},
|
|
2935
|
+
auth: customerAuth
|
|
2936
|
+
};
|
|
2937
|
+
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
2938
|
+
this.auth = {
|
|
2939
|
+
...baseAuth,
|
|
2940
|
+
...customerAuth,
|
|
2941
|
+
authenticate: async () => {
|
|
2942
|
+
return performExchange();
|
|
2943
|
+
}
|
|
2944
|
+
};
|
|
2945
|
+
this.bookings = {
|
|
2946
|
+
create: async (dto) => {
|
|
2947
|
+
return this.catalog.createBooking(dto);
|
|
2948
|
+
},
|
|
2949
|
+
get: async (id) => {
|
|
2950
|
+
return this.catalog.getBooking(id);
|
|
2951
|
+
},
|
|
2952
|
+
list: async () => {
|
|
2953
|
+
return this.catalog.getBookings();
|
|
2954
|
+
},
|
|
2955
|
+
cancel: async (id) => {
|
|
2956
|
+
return this.catalog.updateBookingStatus(id, "CANCELLED");
|
|
2995
2957
|
}
|
|
2996
2958
|
};
|
|
2997
2959
|
}
|
|
@@ -2999,209 +2961,13 @@ var ScrymeClientSDK = class {
|
|
|
2999
2961
|
function createClientSDK(config = {}) {
|
|
3000
2962
|
const finalConfig = {
|
|
3001
2963
|
clientId: config.clientId || "mock-client-id",
|
|
3002
|
-
clientSecret: config.clientSecret || "mock-client-secret",
|
|
3003
2964
|
orgSlug: config.orgSlug || "mock-org-slug",
|
|
3004
2965
|
...config
|
|
3005
2966
|
};
|
|
3006
2967
|
return new ScrymeClientSDK(finalConfig);
|
|
3007
2968
|
}
|
|
3008
|
-
var AuthContext = (0, import_react.createContext)(void 0);
|
|
3009
|
-
var ScrymeAuthProvider = ({
|
|
3010
|
-
sdk,
|
|
3011
|
-
children
|
|
3012
|
-
}) => {
|
|
3013
|
-
const [session, setSession] = (0, import_react.useState)({
|
|
3014
|
-
token: null,
|
|
3015
|
-
user: null
|
|
3016
|
-
});
|
|
3017
|
-
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
3018
|
-
const [cart, setCart] = (0, import_react.useState)(null);
|
|
3019
|
-
const [cartLoading, setCartLoading] = (0, import_react.useState)(false);
|
|
3020
|
-
const [customerProfile, setCustomerProfile] = (0, import_react.useState)(null);
|
|
3021
|
-
const [customerAddresses, setCustomerAddresses] = (0, import_react.useState)([]);
|
|
3022
|
-
const [bookingsList, setBookingsList] = (0, import_react.useState)([]);
|
|
3023
|
-
const [bookingsLoading, setBookingsLoading] = (0, import_react.useState)(false);
|
|
3024
|
-
(0, import_react.useEffect)(() => {
|
|
3025
|
-
const { unsubscribe } = sdk.auth.onAuthStateChange((event, newSession) => {
|
|
3026
|
-
setSession(newSession);
|
|
3027
|
-
setIsLoading(false);
|
|
3028
|
-
});
|
|
3029
|
-
return () => unsubscribe();
|
|
3030
|
-
}, [sdk]);
|
|
3031
|
-
const refreshCart = async () => {
|
|
3032
|
-
if (!session.token) {
|
|
3033
|
-
setCart(null);
|
|
3034
|
-
return;
|
|
3035
|
-
}
|
|
3036
|
-
setCartLoading(true);
|
|
3037
|
-
try {
|
|
3038
|
-
const res = await sdk.cart.get();
|
|
3039
|
-
setCart(res.data?.data || res.data || null);
|
|
3040
|
-
} catch (err) {
|
|
3041
|
-
console.error("Failed to fetch cart:", err);
|
|
3042
|
-
} finally {
|
|
3043
|
-
setCartLoading(false);
|
|
3044
|
-
}
|
|
3045
|
-
};
|
|
3046
|
-
const refreshProfile = async () => {
|
|
3047
|
-
if (!session.token) {
|
|
3048
|
-
setCustomerProfile(null);
|
|
3049
|
-
setCustomerAddresses([]);
|
|
3050
|
-
return;
|
|
3051
|
-
}
|
|
3052
|
-
try {
|
|
3053
|
-
const profile = await sdk.customer.getProfile();
|
|
3054
|
-
setCustomerProfile(profile || null);
|
|
3055
|
-
const addresses = await sdk.customer.getAddresses();
|
|
3056
|
-
setCustomerAddresses(addresses?.data || addresses || []);
|
|
3057
|
-
} catch (err) {
|
|
3058
|
-
console.error("Failed to fetch customer profile or addresses:", err);
|
|
3059
|
-
}
|
|
3060
|
-
};
|
|
3061
|
-
const refreshBookings = async () => {
|
|
3062
|
-
if (!session.token) {
|
|
3063
|
-
setBookingsList([]);
|
|
3064
|
-
return;
|
|
3065
|
-
}
|
|
3066
|
-
setBookingsLoading(true);
|
|
3067
|
-
try {
|
|
3068
|
-
const res = await sdk.bookings.list();
|
|
3069
|
-
setBookingsList(res?.data || res || []);
|
|
3070
|
-
} catch (err) {
|
|
3071
|
-
console.error("Failed to fetch bookings:", err);
|
|
3072
|
-
} finally {
|
|
3073
|
-
setBookingsLoading(false);
|
|
3074
|
-
}
|
|
3075
|
-
};
|
|
3076
|
-
(0, import_react.useEffect)(() => {
|
|
3077
|
-
if (session.token) {
|
|
3078
|
-
refreshCart();
|
|
3079
|
-
refreshProfile();
|
|
3080
|
-
refreshBookings();
|
|
3081
|
-
} else {
|
|
3082
|
-
setCart(null);
|
|
3083
|
-
setCustomerProfile(null);
|
|
3084
|
-
setCustomerAddresses([]);
|
|
3085
|
-
setBookingsList([]);
|
|
3086
|
-
}
|
|
3087
|
-
}, [session.token]);
|
|
3088
|
-
const signIn = async (credentials) => {
|
|
3089
|
-
const res = await sdk.auth.signIn(credentials);
|
|
3090
|
-
return res;
|
|
3091
|
-
};
|
|
3092
|
-
const signUp = async (dto) => {
|
|
3093
|
-
const res = await sdk.auth.signUp(dto);
|
|
3094
|
-
return res;
|
|
3095
|
-
};
|
|
3096
|
-
const signOut = async () => {
|
|
3097
|
-
await sdk.auth.signOut();
|
|
3098
|
-
};
|
|
3099
|
-
const addToCart = async (dto) => {
|
|
3100
|
-
if (!session.token)
|
|
3101
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3102
|
-
await sdk.cart.add(dto);
|
|
3103
|
-
await refreshCart();
|
|
3104
|
-
};
|
|
3105
|
-
const removeFromCart = async (dto) => {
|
|
3106
|
-
if (!session.token)
|
|
3107
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3108
|
-
await sdk.cart.remove(dto);
|
|
3109
|
-
await refreshCart();
|
|
3110
|
-
};
|
|
3111
|
-
const updateCartItem = async (dto) => {
|
|
3112
|
-
if (!session.token)
|
|
3113
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3114
|
-
await sdk.cart.update(dto);
|
|
3115
|
-
await refreshCart();
|
|
3116
|
-
};
|
|
3117
|
-
const clearCart = async (params) => {
|
|
3118
|
-
if (!session.token)
|
|
3119
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3120
|
-
await sdk.cart.clear(params);
|
|
3121
|
-
await refreshCart();
|
|
3122
|
-
};
|
|
3123
|
-
const addAddress = async (dto) => {
|
|
3124
|
-
if (!session.token)
|
|
3125
|
-
throw new Error("Customer must be logged in to manage addresses");
|
|
3126
|
-
const res = await sdk.customer.addAddress(dto);
|
|
3127
|
-
await refreshProfile();
|
|
3128
|
-
return res;
|
|
3129
|
-
};
|
|
3130
|
-
const updateProfile = async (dto) => {
|
|
3131
|
-
if (!session.token)
|
|
3132
|
-
throw new Error("Customer must be logged in to update profile");
|
|
3133
|
-
const res = await sdk.customer.updateProfile(dto);
|
|
3134
|
-
await refreshProfile();
|
|
3135
|
-
return res;
|
|
3136
|
-
};
|
|
3137
|
-
const createBooking = async (dto) => {
|
|
3138
|
-
if (!session.token)
|
|
3139
|
-
throw new Error("Customer must be logged in to create bookings");
|
|
3140
|
-
const res = await sdk.bookings.create(dto);
|
|
3141
|
-
await refreshBookings();
|
|
3142
|
-
return res;
|
|
3143
|
-
};
|
|
3144
|
-
const cancelBooking = async (id) => {
|
|
3145
|
-
if (!session.token)
|
|
3146
|
-
throw new Error("Customer must be logged in to cancel bookings");
|
|
3147
|
-
const res = await sdk.bookings.cancel(id);
|
|
3148
|
-
await refreshBookings();
|
|
3149
|
-
return res;
|
|
3150
|
-
};
|
|
3151
|
-
const checkoutCart = async (params) => {
|
|
3152
|
-
if (!session.token)
|
|
3153
|
-
throw new Error("Customer must be logged in to checkout");
|
|
3154
|
-
const res = await sdk.cart.checkout(params);
|
|
3155
|
-
await refreshCart();
|
|
3156
|
-
await refreshBookings();
|
|
3157
|
-
return res;
|
|
3158
|
-
};
|
|
3159
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3160
|
-
AuthContext.Provider,
|
|
3161
|
-
{
|
|
3162
|
-
value: {
|
|
3163
|
-
sdk,
|
|
3164
|
-
session,
|
|
3165
|
-
user: session.user,
|
|
3166
|
-
token: session.token,
|
|
3167
|
-
isLoading,
|
|
3168
|
-
signIn,
|
|
3169
|
-
signUp,
|
|
3170
|
-
signOut,
|
|
3171
|
-
cart,
|
|
3172
|
-
cartLoading,
|
|
3173
|
-
addToCart,
|
|
3174
|
-
removeFromCart,
|
|
3175
|
-
updateCartItem,
|
|
3176
|
-
clearCart,
|
|
3177
|
-
refreshCart,
|
|
3178
|
-
customerProfile,
|
|
3179
|
-
customerAddresses,
|
|
3180
|
-
bookings: bookingsList,
|
|
3181
|
-
bookingsLoading,
|
|
3182
|
-
addAddress,
|
|
3183
|
-
updateProfile,
|
|
3184
|
-
createBooking,
|
|
3185
|
-
cancelBooking,
|
|
3186
|
-
checkoutCart,
|
|
3187
|
-
refreshProfile,
|
|
3188
|
-
refreshBookings
|
|
3189
|
-
},
|
|
3190
|
-
children
|
|
3191
|
-
}
|
|
3192
|
-
);
|
|
3193
|
-
};
|
|
3194
|
-
var useScrymeAuth = () => {
|
|
3195
|
-
const context = (0, import_react.useContext)(AuthContext);
|
|
3196
|
-
if (context === void 0) {
|
|
3197
|
-
throw new Error("useScrymeAuth must be used within a ScrymeAuthProvider");
|
|
3198
|
-
}
|
|
3199
|
-
return context;
|
|
3200
|
-
};
|
|
3201
2969
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3202
2970
|
0 && (module.exports = {
|
|
3203
|
-
ScrymeAuthProvider,
|
|
3204
2971
|
ScrymeClientSDK,
|
|
3205
|
-
createClientSDK
|
|
3206
|
-
useScrymeAuth
|
|
2972
|
+
createClientSDK
|
|
3207
2973
|
});
|