@scryme/sdk 9.66.0 → 9.68.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-Cl7_QxqC.d.mts → base-CSVOv3Nr.d.mts} +242 -20
- package/dist/{base-Cl7_QxqC.d.ts → base-CSVOv3Nr.d.ts} +242 -20
- package/dist/{chunk-PPNV4D3M.mjs → chunk-SYGBIPUK.mjs} +492 -442
- package/dist/client.d.mts +379 -52
- package/dist/client.d.ts +379 -52
- package/dist/client.js +356 -390
- package/dist/client.mjs +3 -7
- package/dist/index.d.mts +10 -7
- package/dist/index.d.ts +10 -7
- package/dist/index.js +492 -444
- package/dist/index.mjs +3 -7
- package/dist/server.d.mts +184 -4
- package/dist/server.d.ts +184 -4
- package/dist/server.js +192 -66
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
|
@@ -614,6 +614,12 @@ var getScrymeV3API = (axiosInstance = axios) => {
|
|
|
614
614
|
options
|
|
615
615
|
);
|
|
616
616
|
};
|
|
617
|
+
const catalogGetProduct = (orgSlug, idOrSlug, options) => {
|
|
618
|
+
return axiosInstance.get(
|
|
619
|
+
`/v3/${orgSlug}/catalog/products/${idOrSlug}`,
|
|
620
|
+
options
|
|
621
|
+
);
|
|
622
|
+
};
|
|
617
623
|
const catalogGetServices = (orgSlug, params, options) => {
|
|
618
624
|
return axiosInstance.get(
|
|
619
625
|
`/v3/${orgSlug}/catalog/services`,
|
|
@@ -653,6 +659,29 @@ var getScrymeV3API = (axiosInstance = axios) => {
|
|
|
653
659
|
options
|
|
654
660
|
);
|
|
655
661
|
};
|
|
662
|
+
const catalogCreateReview = (orgSlug, productId, createProductReviewDto, options) => {
|
|
663
|
+
return axiosInstance.post(
|
|
664
|
+
`/v3/${orgSlug}/catalog/products/${productId}/reviews`,
|
|
665
|
+
createProductReviewDto,
|
|
666
|
+
options
|
|
667
|
+
);
|
|
668
|
+
};
|
|
669
|
+
const catalogUpdateReview = (orgSlug, reviewId, updateProductReviewDto, options) => {
|
|
670
|
+
return axiosInstance.patch(
|
|
671
|
+
`/v3/${orgSlug}/catalog/reviews/${reviewId}`,
|
|
672
|
+
updateProductReviewDto,
|
|
673
|
+
options
|
|
674
|
+
);
|
|
675
|
+
};
|
|
676
|
+
const catalogDeleteReview = (orgSlug, reviewId, params, options) => {
|
|
677
|
+
return axiosInstance.delete(
|
|
678
|
+
`/v3/${orgSlug}/catalog/reviews/${reviewId}`,
|
|
679
|
+
{
|
|
680
|
+
...options,
|
|
681
|
+
params: { ...params, ...options?.params }
|
|
682
|
+
}
|
|
683
|
+
);
|
|
684
|
+
};
|
|
656
685
|
const servicesCreateCategory = (orgSlug, createServiceCategoryDto, options) => {
|
|
657
686
|
return axiosInstance.post(
|
|
658
687
|
`/v3/${orgSlug}/services/categories`,
|
|
@@ -890,13 +919,6 @@ var getScrymeV3API = (axiosInstance = axios) => {
|
|
|
890
919
|
options
|
|
891
920
|
);
|
|
892
921
|
};
|
|
893
|
-
const customersProvisionZitadel = (orgSlug, provisionZitadelDto, options) => {
|
|
894
|
-
return axiosInstance.post(
|
|
895
|
-
`/v3/${orgSlug}/customers/zitadel/provision`,
|
|
896
|
-
provisionZitadelDto,
|
|
897
|
-
options
|
|
898
|
-
);
|
|
899
|
-
};
|
|
900
922
|
const customersGetCustomers = (orgSlug, params, options) => {
|
|
901
923
|
return axiosInstance.get(
|
|
902
924
|
`/v3/${orgSlug}/customers`,
|
|
@@ -913,6 +935,13 @@ var getScrymeV3API = (axiosInstance = axios) => {
|
|
|
913
935
|
options
|
|
914
936
|
);
|
|
915
937
|
};
|
|
938
|
+
const customerRegister = (orgSlug, registerCustomerDto, options) => {
|
|
939
|
+
return axiosInstance.post(
|
|
940
|
+
`/v3/${orgSlug}/customers/../customer/register`,
|
|
941
|
+
registerCustomerDto,
|
|
942
|
+
options
|
|
943
|
+
);
|
|
944
|
+
};
|
|
916
945
|
const customersLogin = (orgSlug, customerLoginDto, options) => {
|
|
917
946
|
return axiosInstance.post(
|
|
918
947
|
`/v3/${orgSlug}/customers/auth/login`,
|
|
@@ -920,6 +949,13 @@ var getScrymeV3API = (axiosInstance = axios) => {
|
|
|
920
949
|
options
|
|
921
950
|
);
|
|
922
951
|
};
|
|
952
|
+
const customersRefreshSession = (orgSlug, options) => {
|
|
953
|
+
return axiosInstance.post(
|
|
954
|
+
`/v3/${orgSlug}/customers/auth/refresh`,
|
|
955
|
+
void 0,
|
|
956
|
+
options
|
|
957
|
+
);
|
|
958
|
+
};
|
|
923
959
|
const customersGetCurrentSession = (orgSlug, options) => {
|
|
924
960
|
return axiosInstance.get(
|
|
925
961
|
`/v3/${orgSlug}/customers/auth/session`,
|
|
@@ -1858,7 +1894,7 @@ var getScrymeV3API = (axiosInstance = axios) => {
|
|
|
1858
1894
|
}
|
|
1859
1895
|
);
|
|
1860
1896
|
};
|
|
1861
|
-
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,
|
|
1897
|
+
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, catalogCreateReview, catalogUpdateReview, catalogDeleteReview, 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, customerRegister, 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 };
|
|
1862
1898
|
};
|
|
1863
1899
|
|
|
1864
1900
|
// src/generated/model/addDepartmentMemberDtoRole.ts
|
|
@@ -2308,12 +2344,16 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2308
2344
|
"webhooksList",
|
|
2309
2345
|
"webhooksDelete",
|
|
2310
2346
|
"catalogGetProducts",
|
|
2347
|
+
"catalogGetProduct",
|
|
2311
2348
|
"catalogCreateProduct",
|
|
2312
2349
|
"catalogGetServices",
|
|
2313
2350
|
"catalogUpdateProduct",
|
|
2314
2351
|
"catalogUpdateSupplierVariant",
|
|
2315
2352
|
"catalogGetPriceChangeRequests",
|
|
2316
2353
|
"catalogReviewPriceChangeRequest",
|
|
2354
|
+
"catalogCreateReview",
|
|
2355
|
+
"catalogUpdateReview",
|
|
2356
|
+
"catalogDeleteReview",
|
|
2317
2357
|
"servicesCreateCategory",
|
|
2318
2358
|
"servicesGetCategories",
|
|
2319
2359
|
"servicesUpdateCategory",
|
|
@@ -2341,7 +2381,6 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2341
2381
|
"servicesGetUtilization",
|
|
2342
2382
|
"servicesGetPerformance",
|
|
2343
2383
|
"servicesGetFunnel",
|
|
2344
|
-
"customersProvisionZitadel",
|
|
2345
2384
|
"customersGetCustomers",
|
|
2346
2385
|
"customersRegister",
|
|
2347
2386
|
"customersUpdate",
|
|
@@ -2350,6 +2389,10 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2350
2389
|
"customersGetAddresses",
|
|
2351
2390
|
"customersAddAddress",
|
|
2352
2391
|
"customersGetCurrentSession",
|
|
2392
|
+
"customersGetSessions",
|
|
2393
|
+
"customersRevokeSession",
|
|
2394
|
+
"customersRevokeAllSessions",
|
|
2395
|
+
"customersRefreshSession",
|
|
2353
2396
|
"businessAccountControllerCreate",
|
|
2354
2397
|
"businessAccountControllerGetOne",
|
|
2355
2398
|
"crmControllerCreateRecord",
|
|
@@ -2418,12 +2461,16 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2418
2461
|
]);
|
|
2419
2462
|
var catalogMapping = {
|
|
2420
2463
|
getProducts: "catalogGetProducts",
|
|
2464
|
+
getProduct: "catalogGetProduct",
|
|
2421
2465
|
createProduct: "catalogCreateProduct",
|
|
2422
2466
|
getServices: "catalogGetServices",
|
|
2423
2467
|
updateProduct: "catalogUpdateProduct",
|
|
2424
2468
|
updateSupplierVariant: "catalogUpdateSupplierVariant",
|
|
2425
2469
|
getPriceChangeRequests: "catalogGetPriceChangeRequests",
|
|
2426
2470
|
reviewPriceChangeRequest: "catalogReviewPriceChangeRequest",
|
|
2471
|
+
createReview: "catalogCreateReview",
|
|
2472
|
+
updateReview: "catalogUpdateReview",
|
|
2473
|
+
deleteReview: "catalogDeleteReview",
|
|
2427
2474
|
createServiceCategory: "servicesCreateCategory",
|
|
2428
2475
|
getServiceCategories: "servicesGetCategories",
|
|
2429
2476
|
updateServiceCategory: "servicesUpdateCategory",
|
|
@@ -2716,7 +2763,6 @@ var adminMapping = {
|
|
|
2716
2763
|
handleWindmillApprovalCallback: "windmillCallbackControllerHandleApprovalCallback",
|
|
2717
2764
|
handleWindmillBakeryDisposalCallback: "windmillCallbackControllerHandleBakeryDisposalCallback",
|
|
2718
2765
|
handleWindmillOutcomeCallback: "windmillCallbackControllerHandleOutcomeCallback",
|
|
2719
|
-
provisionZitadel: "customersProvisionZitadel",
|
|
2720
2766
|
getCustomers: "customersGetCustomers",
|
|
2721
2767
|
registerCustomer: "customersRegister",
|
|
2722
2768
|
updateCustomer: "customersUpdate",
|
|
@@ -2769,9 +2815,8 @@ function getJwtExpiry(token) {
|
|
|
2769
2815
|
}
|
|
2770
2816
|
|
|
2771
2817
|
// src/client.tsx
|
|
2772
|
-
import {
|
|
2818
|
+
import { useEffect, useState } from "react";
|
|
2773
2819
|
import axios2 from "axios";
|
|
2774
|
-
import { jsx } from "react/jsx-runtime";
|
|
2775
2820
|
var InMemoryStorage = class {
|
|
2776
2821
|
constructor() {
|
|
2777
2822
|
this.cache = /* @__PURE__ */ new Map();
|
|
@@ -2790,6 +2835,10 @@ var SCRYME_SESSION_TOKEN_KEY = "scryme_session_token";
|
|
|
2790
2835
|
var SCRYME_USER_KEY = "scryme_user";
|
|
2791
2836
|
var SCRYME_EXPIRES_AT_KEY = "scryme_expires_at";
|
|
2792
2837
|
var ScrymeClientSDK = class {
|
|
2838
|
+
/**
|
|
2839
|
+
* Initializes the ScrymeClientSDK.
|
|
2840
|
+
* @param config Application and organization configuration parameters.
|
|
2841
|
+
*/
|
|
2793
2842
|
constructor(config) {
|
|
2794
2843
|
if (!config || !config.clientId || !config.orgSlug) {
|
|
2795
2844
|
throw new Error(
|
|
@@ -2854,8 +2903,8 @@ var ScrymeClientSDK = class {
|
|
|
2854
2903
|
state.user = null;
|
|
2855
2904
|
}
|
|
2856
2905
|
}
|
|
2857
|
-
notify("INITIAL_SESSION");
|
|
2858
2906
|
}
|
|
2907
|
+
notify("INITIAL_SESSION");
|
|
2859
2908
|
} catch (e) {
|
|
2860
2909
|
console.error("Failed to initialize Scryme Client SDK session:", e);
|
|
2861
2910
|
}
|
|
@@ -2903,13 +2952,13 @@ var ScrymeClientSDK = class {
|
|
|
2903
2952
|
};
|
|
2904
2953
|
this.axiosInstance.interceptors.request.use(async (req) => {
|
|
2905
2954
|
await initPromise;
|
|
2906
|
-
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh")
|
|
2955
|
+
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh"));
|
|
2907
2956
|
if (!isAuthTokenRequest) {
|
|
2908
2957
|
const isExpired = !state.token || state.expiresAt && Date.now() >= (state.expiresAt || 0) - 3e4;
|
|
2909
2958
|
if (isExpired) {
|
|
2910
2959
|
if (state.token) {
|
|
2911
2960
|
try {
|
|
2912
|
-
await this.auth.refreshSession();
|
|
2961
|
+
await this.customer.auth.refreshSession();
|
|
2913
2962
|
} catch (e) {
|
|
2914
2963
|
console.error(
|
|
2915
2964
|
"Proactive customer session refresh failed in request interceptor:",
|
|
@@ -2937,12 +2986,12 @@ var ScrymeClientSDK = class {
|
|
|
2937
2986
|
(response) => response,
|
|
2938
2987
|
async (error) => {
|
|
2939
2988
|
const originalRequest = error.config;
|
|
2940
|
-
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh")
|
|
2989
|
+
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh"));
|
|
2941
2990
|
if (error.response && error.response.status === 401 && originalRequest && !originalRequest._retry && !isAuthTokenRequest) {
|
|
2942
2991
|
originalRequest._retry = true;
|
|
2943
2992
|
try {
|
|
2944
2993
|
if (state.token) {
|
|
2945
|
-
await this.auth.refreshSession();
|
|
2994
|
+
await this.customer.auth.refreshSession();
|
|
2946
2995
|
if (state.token) {
|
|
2947
2996
|
originalRequest.headers["Authorization"] = `Bearer ${state.token}`;
|
|
2948
2997
|
}
|
|
@@ -2962,7 +3011,87 @@ var ScrymeClientSDK = class {
|
|
|
2962
3011
|
}
|
|
2963
3012
|
);
|
|
2964
3013
|
this.api = getScrymeV3API2(this.axiosInstance, config.orgSlug);
|
|
2965
|
-
|
|
3014
|
+
const baseCatalog = buildModule(this.api, config.orgSlug, catalogMapping);
|
|
3015
|
+
this.catalog = {
|
|
3016
|
+
...baseCatalog,
|
|
3017
|
+
getProduct: async (idOrSlug, options) => {
|
|
3018
|
+
const response = await this.catalog.getProducts(void 0, options);
|
|
3019
|
+
const products = response.data || [];
|
|
3020
|
+
const product = products.find((p) => {
|
|
3021
|
+
if (typeof idOrSlug === "string") {
|
|
3022
|
+
return p.id === idOrSlug || p.slug === idOrSlug;
|
|
3023
|
+
} else {
|
|
3024
|
+
const { id, slug } = idOrSlug;
|
|
3025
|
+
if (id && p.id === id) return true;
|
|
3026
|
+
if (slug && p.slug === slug) return true;
|
|
3027
|
+
return false;
|
|
3028
|
+
}
|
|
3029
|
+
});
|
|
3030
|
+
if (!product) {
|
|
3031
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
3032
|
+
throw new Error(`Product not found matching criteria: ${criteria}`);
|
|
3033
|
+
}
|
|
3034
|
+
return {
|
|
3035
|
+
...response,
|
|
3036
|
+
data: product
|
|
3037
|
+
};
|
|
3038
|
+
},
|
|
3039
|
+
getService: async (idOrSlug, options) => {
|
|
3040
|
+
const response = await this.catalog.getServices(void 0, options);
|
|
3041
|
+
const services = response.data || [];
|
|
3042
|
+
const service = services.find((s) => {
|
|
3043
|
+
if (typeof idOrSlug === "string") {
|
|
3044
|
+
return s.id === idOrSlug || s.slug === idOrSlug;
|
|
3045
|
+
} else {
|
|
3046
|
+
const { id, slug } = idOrSlug;
|
|
3047
|
+
if (id && s.id === id) return true;
|
|
3048
|
+
if (slug && s.slug === slug) return true;
|
|
3049
|
+
return false;
|
|
3050
|
+
}
|
|
3051
|
+
});
|
|
3052
|
+
if (!service) {
|
|
3053
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
3054
|
+
throw new Error(`Service not found matching criteria: ${criteria}`);
|
|
3055
|
+
}
|
|
3056
|
+
return {
|
|
3057
|
+
...response,
|
|
3058
|
+
data: service
|
|
3059
|
+
};
|
|
3060
|
+
},
|
|
3061
|
+
createReview: async (productId, dto, options) => {
|
|
3062
|
+
if (!dto.customerId) {
|
|
3063
|
+
const session = await this.auth.getSession();
|
|
3064
|
+
const user = session?.user;
|
|
3065
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3066
|
+
if (customerId) {
|
|
3067
|
+
dto = { ...dto, customerId };
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
return baseCatalog.createReview(productId, dto, options);
|
|
3071
|
+
},
|
|
3072
|
+
updateReview: async (reviewId, dto, options) => {
|
|
3073
|
+
if (!dto.customerId) {
|
|
3074
|
+
const session = await this.auth.getSession();
|
|
3075
|
+
const user = session?.user;
|
|
3076
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3077
|
+
if (customerId) {
|
|
3078
|
+
dto = { ...dto, customerId };
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
return baseCatalog.updateReview(reviewId, dto, options);
|
|
3082
|
+
},
|
|
3083
|
+
deleteReview: async (reviewId, params, options) => {
|
|
3084
|
+
if (!params || !params.customerId) {
|
|
3085
|
+
const session = await this.auth.getSession();
|
|
3086
|
+
const user = session?.user;
|
|
3087
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3088
|
+
if (customerId) {
|
|
3089
|
+
params = { ...params, customerId };
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
return baseCatalog.deleteReview(reviewId, params, options);
|
|
3093
|
+
}
|
|
3094
|
+
};
|
|
2966
3095
|
this.inventory = buildModule(this.api, config.orgSlug, inventoryMapping);
|
|
2967
3096
|
this.orders = buildModule(this.api, config.orgSlug, ordersMapping);
|
|
2968
3097
|
this.crm = buildModule(this.api, config.orgSlug, crmMapping);
|
|
@@ -2973,20 +3102,47 @@ var ScrymeClientSDK = class {
|
|
|
2973
3102
|
this.admin = buildModule(this.api, config.orgSlug, adminMapping);
|
|
2974
3103
|
this.cart = {
|
|
2975
3104
|
get: async (params) => {
|
|
2976
|
-
return this.orders.getCart(params
|
|
3105
|
+
return this.orders.getCart(params);
|
|
2977
3106
|
},
|
|
2978
3107
|
add: async (dto) => {
|
|
3108
|
+
if (!dto.customerId) {
|
|
3109
|
+
const session = await this.auth.getSession();
|
|
3110
|
+
const user = session?.user;
|
|
3111
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3112
|
+
if (!customerId) {
|
|
3113
|
+
throw new Error("Unauthorized: customerId is required.");
|
|
3114
|
+
}
|
|
3115
|
+
dto = { ...dto, customerId };
|
|
3116
|
+
}
|
|
2979
3117
|
return this.orders.addToCart(dto);
|
|
2980
3118
|
},
|
|
2981
3119
|
remove: async (dto) => {
|
|
3120
|
+
if (!dto.customerId) {
|
|
3121
|
+
const session = await this.auth.getSession();
|
|
3122
|
+
const user = session?.user;
|
|
3123
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3124
|
+
if (!customerId) {
|
|
3125
|
+
throw new Error("Unauthorized: customerId is required.");
|
|
3126
|
+
}
|
|
3127
|
+
dto = { ...dto, customerId };
|
|
3128
|
+
}
|
|
2982
3129
|
return this.orders.removeFromCart(dto);
|
|
2983
3130
|
},
|
|
2984
3131
|
clear: async (params) => {
|
|
2985
|
-
return this.orders.clearCart(params
|
|
3132
|
+
return this.orders.clearCart(params);
|
|
2986
3133
|
},
|
|
2987
3134
|
update: async (dto) => {
|
|
3135
|
+
if (!dto.customerId) {
|
|
3136
|
+
const session = await this.auth.getSession();
|
|
3137
|
+
const user = session?.user;
|
|
3138
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3139
|
+
if (!customerId) {
|
|
3140
|
+
throw new Error("Unauthorized: customerId is required.");
|
|
3141
|
+
}
|
|
3142
|
+
dto = { ...dto, customerId };
|
|
3143
|
+
}
|
|
2988
3144
|
const response = await this.orders.getCart({
|
|
2989
|
-
sessionId: dto.sessionId
|
|
3145
|
+
sessionId: dto.sessionId || ""
|
|
2990
3146
|
});
|
|
2991
3147
|
const data = response.data;
|
|
2992
3148
|
const items = data?.data?.items || data?.items || [];
|
|
@@ -3007,7 +3163,7 @@ var ScrymeClientSDK = class {
|
|
|
3007
3163
|
productId: dto.productId,
|
|
3008
3164
|
variantId: dto.variantId,
|
|
3009
3165
|
serviceId: dto.serviceId,
|
|
3010
|
-
sessionId: dto.sessionId,
|
|
3166
|
+
sessionId: dto.sessionId || "",
|
|
3011
3167
|
customerId: dto.customerId
|
|
3012
3168
|
});
|
|
3013
3169
|
} else {
|
|
@@ -3027,12 +3183,12 @@ var ScrymeClientSDK = class {
|
|
|
3027
3183
|
}
|
|
3028
3184
|
},
|
|
3029
3185
|
getItems: async (params) => {
|
|
3030
|
-
const res = await this.orders.getCart(params
|
|
3186
|
+
const res = await this.orders.getCart(params);
|
|
3031
3187
|
const data = res?.data || res;
|
|
3032
3188
|
return data?.items || data?.data?.items || [];
|
|
3033
3189
|
},
|
|
3034
3190
|
getTotals: async (params) => {
|
|
3035
|
-
const res = await this.orders.getCart(params
|
|
3191
|
+
const res = await this.orders.getCart(params);
|
|
3036
3192
|
const data = res?.data || res;
|
|
3037
3193
|
const items = data?.items || data?.data?.items || [];
|
|
3038
3194
|
const itemsCount = items.reduce(
|
|
@@ -3074,122 +3230,65 @@ var ScrymeClientSDK = class {
|
|
|
3074
3230
|
return orderResponse?.data || orderResponse;
|
|
3075
3231
|
}
|
|
3076
3232
|
};
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
return this.admin.addCustomerAddress(customerId, dto);
|
|
3101
|
-
}
|
|
3102
|
-
};
|
|
3103
|
-
this.bookings = {
|
|
3104
|
-
create: async (dto) => {
|
|
3105
|
-
return this.catalog.createBooking(dto);
|
|
3106
|
-
},
|
|
3107
|
-
get: async (id) => {
|
|
3108
|
-
return this.catalog.getBooking(id);
|
|
3109
|
-
},
|
|
3110
|
-
list: async () => {
|
|
3111
|
-
return this.catalog.getBookings();
|
|
3233
|
+
const customerAuth = {
|
|
3234
|
+
get session() {
|
|
3235
|
+
if (!state.token) {
|
|
3236
|
+
return {
|
|
3237
|
+
data: null,
|
|
3238
|
+
isPending: false,
|
|
3239
|
+
error: null
|
|
3240
|
+
};
|
|
3241
|
+
}
|
|
3242
|
+
const userId = state.user?.id || state.user?.userId || state.user?.customerId || "";
|
|
3243
|
+
return {
|
|
3244
|
+
data: {
|
|
3245
|
+
session: {
|
|
3246
|
+
id: userId || state.token,
|
|
3247
|
+
userId,
|
|
3248
|
+
expiresAt: state.expiresAt ? new Date(state.expiresAt) : null,
|
|
3249
|
+
token: state.token
|
|
3250
|
+
},
|
|
3251
|
+
user: state.user
|
|
3252
|
+
},
|
|
3253
|
+
isPending: false,
|
|
3254
|
+
error: null
|
|
3255
|
+
};
|
|
3112
3256
|
},
|
|
3113
|
-
cancel: async (id) => {
|
|
3114
|
-
return this.catalog.updateBookingStatus(id, "CANCELLED");
|
|
3115
|
-
}
|
|
3116
|
-
};
|
|
3117
|
-
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
3118
|
-
this.auth = {
|
|
3119
|
-
...baseAuth,
|
|
3120
3257
|
signUp: async (dto) => {
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
const response2 = await axios2.post(postUrl, credentials);
|
|
3131
|
-
const data2 = response2.data;
|
|
3132
|
-
const token2 = data2?.session?.token || data2?.token || null;
|
|
3133
|
-
const user2 = data2?.user || null;
|
|
3134
|
-
if (token2) {
|
|
3135
|
-
state.token = token2;
|
|
3136
|
-
state.user = user2;
|
|
3137
|
-
const jwtExp = getJwtExpiry(token2);
|
|
3138
|
-
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token2);
|
|
3139
|
-
if (jwtExp) {
|
|
3140
|
-
state.expiresAt = jwtExp;
|
|
3141
|
-
await storage.setItem(
|
|
3142
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
3143
|
-
String(state.expiresAt)
|
|
3144
|
-
);
|
|
3145
|
-
} else {
|
|
3146
|
-
delete state.expiresAt;
|
|
3147
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
3148
|
-
}
|
|
3149
|
-
if (user2) {
|
|
3150
|
-
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(user2));
|
|
3151
|
-
}
|
|
3152
|
-
notify("SIGNED_IN");
|
|
3153
|
-
return data2;
|
|
3154
|
-
} else {
|
|
3155
|
-
throw new Error("No token returned");
|
|
3258
|
+
const res = await this.api.customersRegister(config.orgSlug, dto);
|
|
3259
|
+
if (dto.password) {
|
|
3260
|
+
try {
|
|
3261
|
+
await customerAuth.signIn({
|
|
3262
|
+
email: dto.email,
|
|
3263
|
+
password: dto.password
|
|
3264
|
+
});
|
|
3265
|
+
} catch (e) {
|
|
3266
|
+
console.error("Auto sign-in after sign-up failed:", e);
|
|
3156
3267
|
}
|
|
3157
|
-
} catch (e) {
|
|
3158
3268
|
}
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
);
|
|
3163
|
-
const
|
|
3164
|
-
const token =
|
|
3165
|
-
const user = data?.session || null;
|
|
3269
|
+
return res;
|
|
3270
|
+
},
|
|
3271
|
+
signIn: async (credentials) => {
|
|
3272
|
+
const res = await this.api.customersLogin(config.orgSlug, credentials);
|
|
3273
|
+
const authData = res.data;
|
|
3274
|
+
const token = authData?.accessToken || authData?.token;
|
|
3166
3275
|
if (token) {
|
|
3167
3276
|
state.token = token;
|
|
3168
|
-
state.user = user;
|
|
3277
|
+
state.user = authData?.user || authData?.customer || authData?.session;
|
|
3169
3278
|
const jwtExp = getJwtExpiry(token);
|
|
3279
|
+
if (jwtExp) state.expiresAt = jwtExp;
|
|
3170
3280
|
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
3171
|
-
if (
|
|
3172
|
-
state.
|
|
3173
|
-
await storage.setItem(
|
|
3174
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
3175
|
-
String(state.expiresAt)
|
|
3176
|
-
);
|
|
3177
|
-
} else {
|
|
3178
|
-
delete state.expiresAt;
|
|
3179
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
3281
|
+
if (state.user) {
|
|
3282
|
+
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(state.user));
|
|
3180
3283
|
}
|
|
3181
|
-
if (
|
|
3182
|
-
await storage.setItem(
|
|
3284
|
+
if (state.expiresAt) {
|
|
3285
|
+
await storage.setItem(SCRYME_EXPIRES_AT_KEY, String(state.expiresAt));
|
|
3183
3286
|
}
|
|
3184
3287
|
notify("SIGNED_IN");
|
|
3185
3288
|
}
|
|
3186
|
-
return
|
|
3289
|
+
return authData;
|
|
3187
3290
|
},
|
|
3188
3291
|
signOut: async () => {
|
|
3189
|
-
try {
|
|
3190
|
-
await this.axiosInstance.post("/auth/sign-out");
|
|
3191
|
-
} catch {
|
|
3192
|
-
}
|
|
3193
3292
|
state.token = null;
|
|
3194
3293
|
state.user = null;
|
|
3195
3294
|
delete state.expiresAt;
|
|
@@ -3204,13 +3303,6 @@ var ScrymeClientSDK = class {
|
|
|
3204
3303
|
},
|
|
3205
3304
|
onAuthStateChange: (callback) => {
|
|
3206
3305
|
listeners.add(callback);
|
|
3207
|
-
initPromise.then(() => {
|
|
3208
|
-
try {
|
|
3209
|
-
callback("INITIAL_SESSION", { ...state });
|
|
3210
|
-
} catch (e) {
|
|
3211
|
-
console.error("Error in immediate auth state listener call:", e);
|
|
3212
|
-
}
|
|
3213
|
-
});
|
|
3214
3306
|
return {
|
|
3215
3307
|
unsubscribe: () => {
|
|
3216
3308
|
listeners.delete(callback);
|
|
@@ -3218,86 +3310,158 @@ var ScrymeClientSDK = class {
|
|
|
3218
3310
|
};
|
|
3219
3311
|
},
|
|
3220
3312
|
getSessions: async () => {
|
|
3221
|
-
const res = await this.
|
|
3222
|
-
`/${config.orgSlug}/customers/auth/sessions`
|
|
3223
|
-
);
|
|
3313
|
+
const res = await this.api.customersGetSessions(config.orgSlug);
|
|
3224
3314
|
return res.data?.data || res.data;
|
|
3225
3315
|
},
|
|
3226
3316
|
revokeSession: async (id) => {
|
|
3227
|
-
|
|
3228
|
-
`/${config.orgSlug}/customers/auth/sessions/${id}`
|
|
3229
|
-
);
|
|
3230
|
-
return res.data?.data || res.data;
|
|
3317
|
+
return this.api.customersRevokeSession(config.orgSlug, id);
|
|
3231
3318
|
},
|
|
3232
3319
|
revokeAllSessions: async (mode) => {
|
|
3233
|
-
|
|
3234
|
-
const res = await this.axiosInstance.delete(url);
|
|
3235
|
-
return res.data?.data || res.data;
|
|
3320
|
+
return this.api.customersRevokeAllSessions(config.orgSlug, { mode });
|
|
3236
3321
|
},
|
|
3237
3322
|
getCurrentSession: async () => {
|
|
3238
|
-
const res = await this.
|
|
3239
|
-
`/${config.orgSlug}/customers/auth/session`
|
|
3240
|
-
);
|
|
3323
|
+
const res = await this.api.customersGetCurrentSession(config.orgSlug);
|
|
3241
3324
|
return res.data?.data || res.data;
|
|
3242
3325
|
},
|
|
3243
3326
|
refreshSession: async () => {
|
|
3244
|
-
const
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
const data = response.data?.data || response.data;
|
|
3248
|
-
const token = data?.token || null;
|
|
3249
|
-
const user = data?.session || null;
|
|
3327
|
+
const res = await this.api.customersRefreshSession(config.orgSlug);
|
|
3328
|
+
const authData = res.data;
|
|
3329
|
+
const token = authData?.accessToken || authData?.token;
|
|
3250
3330
|
if (token) {
|
|
3251
3331
|
state.token = token;
|
|
3252
|
-
|
|
3332
|
+
if (authData?.user || authData?.customer) {
|
|
3333
|
+
state.user = authData.user || authData.customer;
|
|
3334
|
+
}
|
|
3253
3335
|
const jwtExp = getJwtExpiry(token);
|
|
3336
|
+
if (jwtExp) state.expiresAt = jwtExp;
|
|
3254
3337
|
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
3255
|
-
if (
|
|
3256
|
-
state.
|
|
3257
|
-
await storage.setItem(
|
|
3258
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
3259
|
-
String(state.expiresAt)
|
|
3260
|
-
);
|
|
3261
|
-
} else {
|
|
3262
|
-
delete state.expiresAt;
|
|
3263
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
3338
|
+
if (state.user) {
|
|
3339
|
+
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(state.user));
|
|
3264
3340
|
}
|
|
3265
|
-
if (
|
|
3266
|
-
await storage.setItem(
|
|
3341
|
+
if (state.expiresAt) {
|
|
3342
|
+
await storage.setItem(SCRYME_EXPIRES_AT_KEY, String(state.expiresAt));
|
|
3267
3343
|
}
|
|
3268
3344
|
notify("SIGNED_IN");
|
|
3269
3345
|
}
|
|
3270
|
-
return
|
|
3346
|
+
return authData;
|
|
3271
3347
|
},
|
|
3272
|
-
|
|
3273
|
-
const
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
);
|
|
3277
|
-
const
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3348
|
+
useSession: () => {
|
|
3349
|
+
const currentSession = customerAuth.session;
|
|
3350
|
+
const [data, setData] = useState(currentSession.data);
|
|
3351
|
+
const [isPending, setIsPending] = useState(false);
|
|
3352
|
+
const [error, setError] = useState(null);
|
|
3353
|
+
const fetchSessionSync = () => {
|
|
3354
|
+
const s = customerAuth.session;
|
|
3355
|
+
setData(s.data);
|
|
3356
|
+
setError(s.error);
|
|
3357
|
+
setIsPending(s.isPending);
|
|
3358
|
+
};
|
|
3359
|
+
const fetchSessionAsync = async () => {
|
|
3360
|
+
setIsPending(true);
|
|
3361
|
+
try {
|
|
3362
|
+
const res = await customerAuth.getCurrentSession();
|
|
3363
|
+
if (res && (res.session || res.customer || res.user)) {
|
|
3364
|
+
setData({
|
|
3365
|
+
session: res.session,
|
|
3366
|
+
user: res.customer || res.user
|
|
3367
|
+
});
|
|
3368
|
+
} else {
|
|
3369
|
+
const sessionState = await customerAuth.getSession();
|
|
3370
|
+
setData({
|
|
3371
|
+
session: {
|
|
3372
|
+
id: sessionState.user?.id || sessionState.user?.userId || sessionState.user?.customerId || sessionState.token,
|
|
3373
|
+
userId: sessionState.user?.id || sessionState.user?.userId || sessionState.user?.customerId || "",
|
|
3374
|
+
expiresAt: sessionState.expiresAt ? new Date(sessionState.expiresAt) : null,
|
|
3375
|
+
token: sessionState.token
|
|
3376
|
+
},
|
|
3377
|
+
user: sessionState.user
|
|
3378
|
+
});
|
|
3379
|
+
}
|
|
3380
|
+
setError(null);
|
|
3381
|
+
} catch (e) {
|
|
3382
|
+
setError(e instanceof Error ? e : new Error(String(e)));
|
|
3383
|
+
setData(null);
|
|
3384
|
+
} finally {
|
|
3385
|
+
setIsPending(false);
|
|
3294
3386
|
}
|
|
3295
|
-
|
|
3296
|
-
|
|
3387
|
+
};
|
|
3388
|
+
useEffect(() => {
|
|
3389
|
+
fetchSessionSync();
|
|
3390
|
+
const { unsubscribe } = customerAuth.onAuthStateChange(() => {
|
|
3391
|
+
fetchSessionSync();
|
|
3392
|
+
});
|
|
3393
|
+
return () => unsubscribe();
|
|
3394
|
+
}, []);
|
|
3395
|
+
return {
|
|
3396
|
+
data,
|
|
3397
|
+
isPending,
|
|
3398
|
+
error,
|
|
3399
|
+
refetch: fetchSessionAsync
|
|
3400
|
+
};
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
this.customer = {
|
|
3404
|
+
getProfile: async () => {
|
|
3405
|
+
return this.customer.auth.getCurrentSession();
|
|
3406
|
+
},
|
|
3407
|
+
updateProfile: async (dto) => {
|
|
3408
|
+
const session = await this.auth.getSession();
|
|
3409
|
+
const user = session.user;
|
|
3410
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3411
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3412
|
+
return this.admin.updateCustomer(customerId, dto);
|
|
3413
|
+
},
|
|
3414
|
+
getAddresses: async () => {
|
|
3415
|
+
const session = await this.auth.getSession();
|
|
3416
|
+
const user = session.user;
|
|
3417
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3418
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3419
|
+
return this.admin.getCustomerAddresses(customerId);
|
|
3420
|
+
},
|
|
3421
|
+
addAddress: async (dto) => {
|
|
3422
|
+
const session = await this.auth.getSession();
|
|
3423
|
+
const user = session.user;
|
|
3424
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3425
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3426
|
+
return this.admin.addCustomerAddress(customerId, dto);
|
|
3427
|
+
},
|
|
3428
|
+
auth: customerAuth
|
|
3429
|
+
};
|
|
3430
|
+
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
3431
|
+
this.auth = {
|
|
3432
|
+
...baseAuth,
|
|
3433
|
+
...customerAuth,
|
|
3434
|
+
authenticate: async () => {
|
|
3435
|
+
return performExchange();
|
|
3436
|
+
},
|
|
3437
|
+
get session() {
|
|
3438
|
+
return customerAuth.session;
|
|
3439
|
+
},
|
|
3440
|
+
useSession() {
|
|
3441
|
+
return customerAuth.useSession();
|
|
3442
|
+
}
|
|
3443
|
+
};
|
|
3444
|
+
this.bookings = {
|
|
3445
|
+
create: async (dto) => {
|
|
3446
|
+
if (!dto.customerId) {
|
|
3447
|
+
const session = await this.auth.getSession();
|
|
3448
|
+
const user = session?.user;
|
|
3449
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3450
|
+
if (!customerId) {
|
|
3451
|
+
throw new Error("Unauthorized: customerId is required.");
|
|
3297
3452
|
}
|
|
3298
|
-
|
|
3453
|
+
dto = { ...dto, customerId };
|
|
3299
3454
|
}
|
|
3300
|
-
return
|
|
3455
|
+
return this.catalog.createBooking(dto);
|
|
3456
|
+
},
|
|
3457
|
+
get: async (id) => {
|
|
3458
|
+
return this.catalog.getBooking(id);
|
|
3459
|
+
},
|
|
3460
|
+
list: async () => {
|
|
3461
|
+
return this.catalog.getBookings();
|
|
3462
|
+
},
|
|
3463
|
+
cancel: async (id) => {
|
|
3464
|
+
return this.catalog.updateBookingStatus(id, "CANCELLED");
|
|
3301
3465
|
}
|
|
3302
3466
|
};
|
|
3303
3467
|
}
|
|
@@ -3305,205 +3469,11 @@ var ScrymeClientSDK = class {
|
|
|
3305
3469
|
function createClientSDK(config = {}) {
|
|
3306
3470
|
const finalConfig = {
|
|
3307
3471
|
clientId: config.clientId || "mock-client-id",
|
|
3308
|
-
clientSecret: config.clientSecret || "mock-client-secret",
|
|
3309
3472
|
orgSlug: config.orgSlug || "mock-org-slug",
|
|
3310
3473
|
...config
|
|
3311
3474
|
};
|
|
3312
3475
|
return new ScrymeClientSDK(finalConfig);
|
|
3313
3476
|
}
|
|
3314
|
-
var AuthContext = createContext(void 0);
|
|
3315
|
-
var ScrymeAuthProvider = ({
|
|
3316
|
-
sdk,
|
|
3317
|
-
children
|
|
3318
|
-
}) => {
|
|
3319
|
-
const [session, setSession] = useState({
|
|
3320
|
-
token: null,
|
|
3321
|
-
user: null
|
|
3322
|
-
});
|
|
3323
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
3324
|
-
const [cart, setCart] = useState(null);
|
|
3325
|
-
const [cartLoading, setCartLoading] = useState(false);
|
|
3326
|
-
const [customerProfile, setCustomerProfile] = useState(null);
|
|
3327
|
-
const [customerAddresses, setCustomerAddresses] = useState([]);
|
|
3328
|
-
const [bookingsList, setBookingsList] = useState([]);
|
|
3329
|
-
const [bookingsLoading, setBookingsLoading] = useState(false);
|
|
3330
|
-
useEffect(() => {
|
|
3331
|
-
const { unsubscribe } = sdk.auth.onAuthStateChange((event, newSession) => {
|
|
3332
|
-
setSession(newSession);
|
|
3333
|
-
setIsLoading(false);
|
|
3334
|
-
});
|
|
3335
|
-
return () => unsubscribe();
|
|
3336
|
-
}, [sdk]);
|
|
3337
|
-
const refreshCart = async () => {
|
|
3338
|
-
if (!session.token) {
|
|
3339
|
-
setCart(null);
|
|
3340
|
-
return;
|
|
3341
|
-
}
|
|
3342
|
-
setCartLoading(true);
|
|
3343
|
-
try {
|
|
3344
|
-
const res = await sdk.cart.get();
|
|
3345
|
-
setCart(res.data?.data || res.data || null);
|
|
3346
|
-
} catch (err) {
|
|
3347
|
-
console.error("Failed to fetch cart:", err);
|
|
3348
|
-
} finally {
|
|
3349
|
-
setCartLoading(false);
|
|
3350
|
-
}
|
|
3351
|
-
};
|
|
3352
|
-
const refreshProfile = async () => {
|
|
3353
|
-
if (!session.token) {
|
|
3354
|
-
setCustomerProfile(null);
|
|
3355
|
-
setCustomerAddresses([]);
|
|
3356
|
-
return;
|
|
3357
|
-
}
|
|
3358
|
-
try {
|
|
3359
|
-
const profile = await sdk.customer.getProfile();
|
|
3360
|
-
setCustomerProfile(profile || null);
|
|
3361
|
-
const addresses = await sdk.customer.getAddresses();
|
|
3362
|
-
setCustomerAddresses(addresses?.data || addresses || []);
|
|
3363
|
-
} catch (err) {
|
|
3364
|
-
console.error("Failed to fetch customer profile or addresses:", err);
|
|
3365
|
-
}
|
|
3366
|
-
};
|
|
3367
|
-
const refreshBookings = async () => {
|
|
3368
|
-
if (!session.token) {
|
|
3369
|
-
setBookingsList([]);
|
|
3370
|
-
return;
|
|
3371
|
-
}
|
|
3372
|
-
setBookingsLoading(true);
|
|
3373
|
-
try {
|
|
3374
|
-
const res = await sdk.bookings.list();
|
|
3375
|
-
setBookingsList(res?.data || res || []);
|
|
3376
|
-
} catch (err) {
|
|
3377
|
-
console.error("Failed to fetch bookings:", err);
|
|
3378
|
-
} finally {
|
|
3379
|
-
setBookingsLoading(false);
|
|
3380
|
-
}
|
|
3381
|
-
};
|
|
3382
|
-
useEffect(() => {
|
|
3383
|
-
if (session.token) {
|
|
3384
|
-
refreshCart();
|
|
3385
|
-
refreshProfile();
|
|
3386
|
-
refreshBookings();
|
|
3387
|
-
} else {
|
|
3388
|
-
setCart(null);
|
|
3389
|
-
setCustomerProfile(null);
|
|
3390
|
-
setCustomerAddresses([]);
|
|
3391
|
-
setBookingsList([]);
|
|
3392
|
-
}
|
|
3393
|
-
}, [session.token]);
|
|
3394
|
-
const signIn = async (credentials) => {
|
|
3395
|
-
const res = await sdk.auth.signIn(credentials);
|
|
3396
|
-
return res;
|
|
3397
|
-
};
|
|
3398
|
-
const signUp = async (dto) => {
|
|
3399
|
-
const res = await sdk.auth.signUp(dto);
|
|
3400
|
-
return res;
|
|
3401
|
-
};
|
|
3402
|
-
const signOut = async () => {
|
|
3403
|
-
await sdk.auth.signOut();
|
|
3404
|
-
};
|
|
3405
|
-
const addToCart = async (dto) => {
|
|
3406
|
-
if (!session.token)
|
|
3407
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3408
|
-
await sdk.cart.add(dto);
|
|
3409
|
-
await refreshCart();
|
|
3410
|
-
};
|
|
3411
|
-
const removeFromCart = async (dto) => {
|
|
3412
|
-
if (!session.token)
|
|
3413
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3414
|
-
await sdk.cart.remove(dto);
|
|
3415
|
-
await refreshCart();
|
|
3416
|
-
};
|
|
3417
|
-
const updateCartItem = async (dto) => {
|
|
3418
|
-
if (!session.token)
|
|
3419
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3420
|
-
await sdk.cart.update(dto);
|
|
3421
|
-
await refreshCart();
|
|
3422
|
-
};
|
|
3423
|
-
const clearCart = async (params) => {
|
|
3424
|
-
if (!session.token)
|
|
3425
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3426
|
-
await sdk.cart.clear(params);
|
|
3427
|
-
await refreshCart();
|
|
3428
|
-
};
|
|
3429
|
-
const addAddress = async (dto) => {
|
|
3430
|
-
if (!session.token)
|
|
3431
|
-
throw new Error("Customer must be logged in to manage addresses");
|
|
3432
|
-
const res = await sdk.customer.addAddress(dto);
|
|
3433
|
-
await refreshProfile();
|
|
3434
|
-
return res;
|
|
3435
|
-
};
|
|
3436
|
-
const updateProfile = async (dto) => {
|
|
3437
|
-
if (!session.token)
|
|
3438
|
-
throw new Error("Customer must be logged in to update profile");
|
|
3439
|
-
const res = await sdk.customer.updateProfile(dto);
|
|
3440
|
-
await refreshProfile();
|
|
3441
|
-
return res;
|
|
3442
|
-
};
|
|
3443
|
-
const createBooking = async (dto) => {
|
|
3444
|
-
if (!session.token)
|
|
3445
|
-
throw new Error("Customer must be logged in to create bookings");
|
|
3446
|
-
const res = await sdk.bookings.create(dto);
|
|
3447
|
-
await refreshBookings();
|
|
3448
|
-
return res;
|
|
3449
|
-
};
|
|
3450
|
-
const cancelBooking = async (id) => {
|
|
3451
|
-
if (!session.token)
|
|
3452
|
-
throw new Error("Customer must be logged in to cancel bookings");
|
|
3453
|
-
const res = await sdk.bookings.cancel(id);
|
|
3454
|
-
await refreshBookings();
|
|
3455
|
-
return res;
|
|
3456
|
-
};
|
|
3457
|
-
const checkoutCart = async (params) => {
|
|
3458
|
-
if (!session.token)
|
|
3459
|
-
throw new Error("Customer must be logged in to checkout");
|
|
3460
|
-
const res = await sdk.cart.checkout(params);
|
|
3461
|
-
await refreshCart();
|
|
3462
|
-
await refreshBookings();
|
|
3463
|
-
return res;
|
|
3464
|
-
};
|
|
3465
|
-
return /* @__PURE__ */ jsx(
|
|
3466
|
-
AuthContext.Provider,
|
|
3467
|
-
{
|
|
3468
|
-
value: {
|
|
3469
|
-
sdk,
|
|
3470
|
-
session,
|
|
3471
|
-
user: session.user,
|
|
3472
|
-
token: session.token,
|
|
3473
|
-
isLoading,
|
|
3474
|
-
signIn,
|
|
3475
|
-
signUp,
|
|
3476
|
-
signOut,
|
|
3477
|
-
cart,
|
|
3478
|
-
cartLoading,
|
|
3479
|
-
addToCart,
|
|
3480
|
-
removeFromCart,
|
|
3481
|
-
updateCartItem,
|
|
3482
|
-
clearCart,
|
|
3483
|
-
refreshCart,
|
|
3484
|
-
customerProfile,
|
|
3485
|
-
customerAddresses,
|
|
3486
|
-
bookings: bookingsList,
|
|
3487
|
-
bookingsLoading,
|
|
3488
|
-
addAddress,
|
|
3489
|
-
updateProfile,
|
|
3490
|
-
createBooking,
|
|
3491
|
-
cancelBooking,
|
|
3492
|
-
checkoutCart,
|
|
3493
|
-
refreshProfile,
|
|
3494
|
-
refreshBookings
|
|
3495
|
-
},
|
|
3496
|
-
children
|
|
3497
|
-
}
|
|
3498
|
-
);
|
|
3499
|
-
};
|
|
3500
|
-
var useScrymeAuth = () => {
|
|
3501
|
-
const context = useContext(AuthContext);
|
|
3502
|
-
if (context === void 0) {
|
|
3503
|
-
throw new Error("useScrymeAuth must be used within a ScrymeAuthProvider");
|
|
3504
|
-
}
|
|
3505
|
-
return context;
|
|
3506
|
-
};
|
|
3507
3477
|
|
|
3508
3478
|
// src/index.ts
|
|
3509
3479
|
function getEnvOrgSlug() {
|
|
@@ -3627,7 +3597,7 @@ var ScrymeServerSDK = class {
|
|
|
3627
3597
|
return this.activeAuthPromise;
|
|
3628
3598
|
};
|
|
3629
3599
|
this.axiosInstance.interceptors.request.use(async (req) => {
|
|
3630
|
-
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh")
|
|
3600
|
+
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh"));
|
|
3631
3601
|
if (!isAuthTokenRequest && !config.apiKey) {
|
|
3632
3602
|
const isExpired = !this.token || this.expiresAt && Date.now() >= this.expiresAt - 3e4;
|
|
3633
3603
|
if (isExpired) {
|
|
@@ -3662,7 +3632,7 @@ var ScrymeServerSDK = class {
|
|
|
3662
3632
|
(response) => response,
|
|
3663
3633
|
async (error) => {
|
|
3664
3634
|
const originalRequest = error.config;
|
|
3665
|
-
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh")
|
|
3635
|
+
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh"));
|
|
3666
3636
|
if (error.response && error.response.status === 401 && originalRequest && !originalRequest._retry && !isAuthTokenRequest && !config.apiKey) {
|
|
3667
3637
|
originalRequest._retry = true;
|
|
3668
3638
|
try {
|
|
@@ -3688,7 +3658,54 @@ var ScrymeServerSDK = class {
|
|
|
3688
3658
|
}
|
|
3689
3659
|
);
|
|
3690
3660
|
this.api = getScrymeV3API2(this.axiosInstance, config.orgSlug);
|
|
3691
|
-
|
|
3661
|
+
const baseCatalog = buildModule(this.api, config.orgSlug, catalogMapping);
|
|
3662
|
+
this.catalog = {
|
|
3663
|
+
...baseCatalog,
|
|
3664
|
+
getProduct: async (idOrSlug, options) => {
|
|
3665
|
+
const response = await this.catalog.getProducts(void 0, options);
|
|
3666
|
+
const products = response.data || [];
|
|
3667
|
+
const product = products.find((p) => {
|
|
3668
|
+
if (typeof idOrSlug === "string") {
|
|
3669
|
+
return p.id === idOrSlug || p.slug === idOrSlug;
|
|
3670
|
+
} else {
|
|
3671
|
+
const { id, slug } = idOrSlug;
|
|
3672
|
+
if (id && p.id === id) return true;
|
|
3673
|
+
if (slug && p.slug === slug) return true;
|
|
3674
|
+
return false;
|
|
3675
|
+
}
|
|
3676
|
+
});
|
|
3677
|
+
if (!product) {
|
|
3678
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
3679
|
+
throw new Error(`Product not found matching criteria: ${criteria}`);
|
|
3680
|
+
}
|
|
3681
|
+
return {
|
|
3682
|
+
...response,
|
|
3683
|
+
data: product
|
|
3684
|
+
};
|
|
3685
|
+
},
|
|
3686
|
+
getService: async (idOrSlug, options) => {
|
|
3687
|
+
const response = await this.catalog.getServices(void 0, options);
|
|
3688
|
+
const services = response.data || [];
|
|
3689
|
+
const service = services.find((s) => {
|
|
3690
|
+
if (typeof idOrSlug === "string") {
|
|
3691
|
+
return s.id === idOrSlug || s.slug === idOrSlug;
|
|
3692
|
+
} else {
|
|
3693
|
+
const { id, slug } = idOrSlug;
|
|
3694
|
+
if (id && s.id === id) return true;
|
|
3695
|
+
if (slug && s.slug === slug) return true;
|
|
3696
|
+
return false;
|
|
3697
|
+
}
|
|
3698
|
+
});
|
|
3699
|
+
if (!service) {
|
|
3700
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
3701
|
+
throw new Error(`Service not found matching criteria: ${criteria}`);
|
|
3702
|
+
}
|
|
3703
|
+
return {
|
|
3704
|
+
...response,
|
|
3705
|
+
data: service
|
|
3706
|
+
};
|
|
3707
|
+
}
|
|
3708
|
+
};
|
|
3692
3709
|
this.inventory = buildModule(this.api, config.orgSlug, inventoryMapping);
|
|
3693
3710
|
this.orders = buildModule(this.api, config.orgSlug, ordersMapping);
|
|
3694
3711
|
this.crm = buildModule(this.api, config.orgSlug, crmMapping);
|
|
@@ -3700,7 +3717,9 @@ var ScrymeServerSDK = class {
|
|
|
3700
3717
|
this.services = buildModule(this.api, config.orgSlug, servicesMapping);
|
|
3701
3718
|
this.cart = {
|
|
3702
3719
|
get: async (params) => {
|
|
3703
|
-
return this.orders.getCart(
|
|
3720
|
+
return this.orders.getCart(
|
|
3721
|
+
params
|
|
3722
|
+
);
|
|
3704
3723
|
},
|
|
3705
3724
|
add: async (dto) => {
|
|
3706
3725
|
return this.orders.addToCart(dto);
|
|
@@ -3709,11 +3728,11 @@ var ScrymeServerSDK = class {
|
|
|
3709
3728
|
return this.orders.removeFromCart(dto);
|
|
3710
3729
|
},
|
|
3711
3730
|
clear: async (params) => {
|
|
3712
|
-
return this.orders.clearCart(params
|
|
3731
|
+
return this.orders.clearCart(params);
|
|
3713
3732
|
},
|
|
3714
3733
|
update: async (dto) => {
|
|
3715
3734
|
const response = await this.orders.getCart({
|
|
3716
|
-
sessionId: dto.sessionId
|
|
3735
|
+
sessionId: dto.sessionId || ""
|
|
3717
3736
|
});
|
|
3718
3737
|
const data = response.data;
|
|
3719
3738
|
const items = data?.data?.items || data?.items || [];
|
|
@@ -3734,7 +3753,7 @@ var ScrymeServerSDK = class {
|
|
|
3734
3753
|
productId: dto.productId,
|
|
3735
3754
|
variantId: dto.variantId,
|
|
3736
3755
|
serviceId: dto.serviceId,
|
|
3737
|
-
sessionId: dto.sessionId,
|
|
3756
|
+
sessionId: dto.sessionId || "",
|
|
3738
3757
|
customerId: dto.customerId
|
|
3739
3758
|
});
|
|
3740
3759
|
} else {
|
|
@@ -3754,12 +3773,16 @@ var ScrymeServerSDK = class {
|
|
|
3754
3773
|
}
|
|
3755
3774
|
},
|
|
3756
3775
|
getItems: async (params) => {
|
|
3757
|
-
const res = await this.orders.getCart(
|
|
3776
|
+
const res = await this.orders.getCart(
|
|
3777
|
+
params
|
|
3778
|
+
);
|
|
3758
3779
|
const data = res?.data || res;
|
|
3759
3780
|
return data?.items || data?.data?.items || [];
|
|
3760
3781
|
},
|
|
3761
3782
|
getTotals: async (params) => {
|
|
3762
|
-
const res = await this.orders.getCart(
|
|
3783
|
+
const res = await this.orders.getCart(
|
|
3784
|
+
params
|
|
3785
|
+
);
|
|
3763
3786
|
const data = res?.data || res;
|
|
3764
3787
|
const items = data?.items || data?.data?.items || [];
|
|
3765
3788
|
const itemsCount = items.reduce(
|
|
@@ -3813,6 +3836,72 @@ var ScrymeServerSDK = class {
|
|
|
3813
3836
|
},
|
|
3814
3837
|
addAddress: async (customerId, dto) => {
|
|
3815
3838
|
return this.admin.addCustomerAddress(customerId, dto);
|
|
3839
|
+
},
|
|
3840
|
+
auth: {
|
|
3841
|
+
signUp: async (dto) => {
|
|
3842
|
+
const res = await this.api.customersRegister(config.orgSlug, dto);
|
|
3843
|
+
if (dto.password) {
|
|
3844
|
+
try {
|
|
3845
|
+
await this.customer.auth.signIn({
|
|
3846
|
+
email: dto.email,
|
|
3847
|
+
password: dto.password
|
|
3848
|
+
});
|
|
3849
|
+
} catch (e) {
|
|
3850
|
+
console.error("Auto sign-in after sign-up failed on server SDK:", e);
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
return res;
|
|
3854
|
+
},
|
|
3855
|
+
signIn: async (credentials) => {
|
|
3856
|
+
const response = await this.axiosInstance.post(
|
|
3857
|
+
"/auth/sign-in/email",
|
|
3858
|
+
credentials
|
|
3859
|
+
);
|
|
3860
|
+
const data = response.data;
|
|
3861
|
+
const token = data?.session?.token || data?.token || null;
|
|
3862
|
+
if (token) {
|
|
3863
|
+
this.token = token;
|
|
3864
|
+
this.expiresAt = getJwtExpiry(token);
|
|
3865
|
+
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3866
|
+
}
|
|
3867
|
+
return data;
|
|
3868
|
+
},
|
|
3869
|
+
getCurrentSession: async (headers) => {
|
|
3870
|
+
const requestConfig = {};
|
|
3871
|
+
if (headers) {
|
|
3872
|
+
const requestHeaders = {};
|
|
3873
|
+
if (typeof headers.forEach === "function") {
|
|
3874
|
+
headers.forEach((value, key) => {
|
|
3875
|
+
requestHeaders[key] = value;
|
|
3876
|
+
});
|
|
3877
|
+
} else {
|
|
3878
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
3879
|
+
if (value !== void 0) {
|
|
3880
|
+
requestHeaders[key] = Array.isArray(value) ? value.join(", ") : String(value);
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3884
|
+
requestConfig.headers = requestHeaders;
|
|
3885
|
+
}
|
|
3886
|
+
const response = await this.axiosInstance.get(
|
|
3887
|
+
`/${config.orgSlug}/customers/auth/session`,
|
|
3888
|
+
requestConfig
|
|
3889
|
+
);
|
|
3890
|
+
return response.data?.data || response.data;
|
|
3891
|
+
},
|
|
3892
|
+
refreshSession: async () => {
|
|
3893
|
+
const response = await this.axiosInstance.post(
|
|
3894
|
+
`/${config.orgSlug}/customers/auth/refresh`
|
|
3895
|
+
);
|
|
3896
|
+
const data = response.data?.data || response.data;
|
|
3897
|
+
const token = data?.token || null;
|
|
3898
|
+
if (token) {
|
|
3899
|
+
this.token = token;
|
|
3900
|
+
this.expiresAt = getJwtExpiry(token);
|
|
3901
|
+
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3902
|
+
}
|
|
3903
|
+
return data;
|
|
3904
|
+
}
|
|
3816
3905
|
}
|
|
3817
3906
|
};
|
|
3818
3907
|
this.bookings = {
|
|
@@ -3835,58 +3924,21 @@ var ScrymeServerSDK = class {
|
|
|
3835
3924
|
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
3836
3925
|
this.auth = {
|
|
3837
3926
|
...baseAuth,
|
|
3838
|
-
|
|
3839
|
-
return this.api.customersRegister(config.orgSlug, dto);
|
|
3840
|
-
},
|
|
3927
|
+
...this.customer.auth,
|
|
3841
3928
|
authenticate: async () => {
|
|
3842
3929
|
return performExchange();
|
|
3843
3930
|
},
|
|
3931
|
+
signUp: async (dto) => {
|
|
3932
|
+
return this.customer.auth.signUp(dto);
|
|
3933
|
+
},
|
|
3844
3934
|
signIn: async (credentials) => {
|
|
3845
|
-
|
|
3846
|
-
"/auth/sign-in/email",
|
|
3847
|
-
credentials
|
|
3848
|
-
);
|
|
3849
|
-
const data = response.data;
|
|
3850
|
-
const token = data?.session?.token || data?.token || null;
|
|
3851
|
-
if (token) {
|
|
3852
|
-
this.token = token;
|
|
3853
|
-
this.expiresAt = getJwtExpiry(token);
|
|
3854
|
-
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3855
|
-
}
|
|
3856
|
-
return data;
|
|
3935
|
+
return this.customer.auth.signIn(credentials);
|
|
3857
3936
|
},
|
|
3858
|
-
getCurrentSession: async () => {
|
|
3859
|
-
|
|
3860
|
-
`/${config.orgSlug}/customers/auth/session`
|
|
3861
|
-
);
|
|
3862
|
-
return response.data?.data || response.data;
|
|
3937
|
+
getCurrentSession: async (headers) => {
|
|
3938
|
+
return this.customer.auth.getCurrentSession(headers);
|
|
3863
3939
|
},
|
|
3864
3940
|
refreshSession: async () => {
|
|
3865
|
-
|
|
3866
|
-
`/${config.orgSlug}/customers/auth/refresh`
|
|
3867
|
-
);
|
|
3868
|
-
const data = response.data?.data || response.data;
|
|
3869
|
-
const token = data?.token || null;
|
|
3870
|
-
if (token) {
|
|
3871
|
-
this.token = token;
|
|
3872
|
-
this.expiresAt = getJwtExpiry(token);
|
|
3873
|
-
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3874
|
-
}
|
|
3875
|
-
return data;
|
|
3876
|
-
},
|
|
3877
|
-
swapZitadel: async (zitadelToken) => {
|
|
3878
|
-
const response = await this.axiosInstance.post(
|
|
3879
|
-
`/${config.orgSlug}/customers/auth/swap-zitadel`,
|
|
3880
|
-
{ zitadelToken }
|
|
3881
|
-
);
|
|
3882
|
-
const data = response.data?.data || response.data;
|
|
3883
|
-
const token = data?.token || null;
|
|
3884
|
-
if (token) {
|
|
3885
|
-
this.token = token;
|
|
3886
|
-
this.expiresAt = getJwtExpiry(token);
|
|
3887
|
-
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3888
|
-
}
|
|
3889
|
-
return data;
|
|
3941
|
+
return this.customer.auth.refreshSession();
|
|
3890
3942
|
}
|
|
3891
3943
|
};
|
|
3892
3944
|
}
|
|
@@ -3968,7 +4020,5 @@ export {
|
|
|
3968
4020
|
createServerSDK,
|
|
3969
4021
|
getScrymeV3API2 as getScrymeV3API,
|
|
3970
4022
|
ScrymeClientSDK,
|
|
3971
|
-
createClientSDK
|
|
3972
|
-
ScrymeAuthProvider,
|
|
3973
|
-
useScrymeAuth
|
|
4023
|
+
createClientSDK
|
|
3974
4024
|
};
|