@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
package/dist/client.js
CHANGED
|
@@ -30,10 +30,8 @@ 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
37
|
var import_react = require("react");
|
|
@@ -652,6 +650,12 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
652
650
|
options
|
|
653
651
|
);
|
|
654
652
|
};
|
|
653
|
+
const catalogGetProduct = (orgSlug, idOrSlug, options) => {
|
|
654
|
+
return axiosInstance.get(
|
|
655
|
+
`/v3/${orgSlug}/catalog/products/${idOrSlug}`,
|
|
656
|
+
options
|
|
657
|
+
);
|
|
658
|
+
};
|
|
655
659
|
const catalogGetServices = (orgSlug, params, options) => {
|
|
656
660
|
return axiosInstance.get(
|
|
657
661
|
`/v3/${orgSlug}/catalog/services`,
|
|
@@ -691,6 +695,29 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
691
695
|
options
|
|
692
696
|
);
|
|
693
697
|
};
|
|
698
|
+
const catalogCreateReview = (orgSlug, productId, createProductReviewDto, options) => {
|
|
699
|
+
return axiosInstance.post(
|
|
700
|
+
`/v3/${orgSlug}/catalog/products/${productId}/reviews`,
|
|
701
|
+
createProductReviewDto,
|
|
702
|
+
options
|
|
703
|
+
);
|
|
704
|
+
};
|
|
705
|
+
const catalogUpdateReview = (orgSlug, reviewId, updateProductReviewDto, options) => {
|
|
706
|
+
return axiosInstance.patch(
|
|
707
|
+
`/v3/${orgSlug}/catalog/reviews/${reviewId}`,
|
|
708
|
+
updateProductReviewDto,
|
|
709
|
+
options
|
|
710
|
+
);
|
|
711
|
+
};
|
|
712
|
+
const catalogDeleteReview = (orgSlug, reviewId, params, options) => {
|
|
713
|
+
return axiosInstance.delete(
|
|
714
|
+
`/v3/${orgSlug}/catalog/reviews/${reviewId}`,
|
|
715
|
+
{
|
|
716
|
+
...options,
|
|
717
|
+
params: { ...params, ...options?.params }
|
|
718
|
+
}
|
|
719
|
+
);
|
|
720
|
+
};
|
|
694
721
|
const servicesCreateCategory = (orgSlug, createServiceCategoryDto, options) => {
|
|
695
722
|
return axiosInstance.post(
|
|
696
723
|
`/v3/${orgSlug}/services/categories`,
|
|
@@ -928,13 +955,6 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
928
955
|
options
|
|
929
956
|
);
|
|
930
957
|
};
|
|
931
|
-
const customersProvisionZitadel = (orgSlug, provisionZitadelDto, options) => {
|
|
932
|
-
return axiosInstance.post(
|
|
933
|
-
`/v3/${orgSlug}/customers/zitadel/provision`,
|
|
934
|
-
provisionZitadelDto,
|
|
935
|
-
options
|
|
936
|
-
);
|
|
937
|
-
};
|
|
938
958
|
const customersGetCustomers = (orgSlug, params, options) => {
|
|
939
959
|
return axiosInstance.get(
|
|
940
960
|
`/v3/${orgSlug}/customers`,
|
|
@@ -951,6 +971,13 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
951
971
|
options
|
|
952
972
|
);
|
|
953
973
|
};
|
|
974
|
+
const customerRegister = (orgSlug, registerCustomerDto, options) => {
|
|
975
|
+
return axiosInstance.post(
|
|
976
|
+
`/v3/${orgSlug}/customers/../customer/register`,
|
|
977
|
+
registerCustomerDto,
|
|
978
|
+
options
|
|
979
|
+
);
|
|
980
|
+
};
|
|
954
981
|
const customersLogin = (orgSlug, customerLoginDto, options) => {
|
|
955
982
|
return axiosInstance.post(
|
|
956
983
|
`/v3/${orgSlug}/customers/auth/login`,
|
|
@@ -958,6 +985,13 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
958
985
|
options
|
|
959
986
|
);
|
|
960
987
|
};
|
|
988
|
+
const customersRefreshSession = (orgSlug, options) => {
|
|
989
|
+
return axiosInstance.post(
|
|
990
|
+
`/v3/${orgSlug}/customers/auth/refresh`,
|
|
991
|
+
void 0,
|
|
992
|
+
options
|
|
993
|
+
);
|
|
994
|
+
};
|
|
961
995
|
const customersGetCurrentSession = (orgSlug, options) => {
|
|
962
996
|
return axiosInstance.get(
|
|
963
997
|
`/v3/${orgSlug}/customers/auth/session`,
|
|
@@ -1896,7 +1930,7 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
1896
1930
|
}
|
|
1897
1931
|
);
|
|
1898
1932
|
};
|
|
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,
|
|
1933
|
+
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 };
|
|
1900
1934
|
};
|
|
1901
1935
|
|
|
1902
1936
|
// src/base.ts
|
|
@@ -1935,12 +1969,16 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
1935
1969
|
"webhooksList",
|
|
1936
1970
|
"webhooksDelete",
|
|
1937
1971
|
"catalogGetProducts",
|
|
1972
|
+
"catalogGetProduct",
|
|
1938
1973
|
"catalogCreateProduct",
|
|
1939
1974
|
"catalogGetServices",
|
|
1940
1975
|
"catalogUpdateProduct",
|
|
1941
1976
|
"catalogUpdateSupplierVariant",
|
|
1942
1977
|
"catalogGetPriceChangeRequests",
|
|
1943
1978
|
"catalogReviewPriceChangeRequest",
|
|
1979
|
+
"catalogCreateReview",
|
|
1980
|
+
"catalogUpdateReview",
|
|
1981
|
+
"catalogDeleteReview",
|
|
1944
1982
|
"servicesCreateCategory",
|
|
1945
1983
|
"servicesGetCategories",
|
|
1946
1984
|
"servicesUpdateCategory",
|
|
@@ -1968,7 +2006,6 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
1968
2006
|
"servicesGetUtilization",
|
|
1969
2007
|
"servicesGetPerformance",
|
|
1970
2008
|
"servicesGetFunnel",
|
|
1971
|
-
"customersProvisionZitadel",
|
|
1972
2009
|
"customersGetCustomers",
|
|
1973
2010
|
"customersRegister",
|
|
1974
2011
|
"customersUpdate",
|
|
@@ -1977,6 +2014,10 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
1977
2014
|
"customersGetAddresses",
|
|
1978
2015
|
"customersAddAddress",
|
|
1979
2016
|
"customersGetCurrentSession",
|
|
2017
|
+
"customersGetSessions",
|
|
2018
|
+
"customersRevokeSession",
|
|
2019
|
+
"customersRevokeAllSessions",
|
|
2020
|
+
"customersRefreshSession",
|
|
1980
2021
|
"businessAccountControllerCreate",
|
|
1981
2022
|
"businessAccountControllerGetOne",
|
|
1982
2023
|
"crmControllerCreateRecord",
|
|
@@ -2045,12 +2086,16 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2045
2086
|
]);
|
|
2046
2087
|
var catalogMapping = {
|
|
2047
2088
|
getProducts: "catalogGetProducts",
|
|
2089
|
+
getProduct: "catalogGetProduct",
|
|
2048
2090
|
createProduct: "catalogCreateProduct",
|
|
2049
2091
|
getServices: "catalogGetServices",
|
|
2050
2092
|
updateProduct: "catalogUpdateProduct",
|
|
2051
2093
|
updateSupplierVariant: "catalogUpdateSupplierVariant",
|
|
2052
2094
|
getPriceChangeRequests: "catalogGetPriceChangeRequests",
|
|
2053
2095
|
reviewPriceChangeRequest: "catalogReviewPriceChangeRequest",
|
|
2096
|
+
createReview: "catalogCreateReview",
|
|
2097
|
+
updateReview: "catalogUpdateReview",
|
|
2098
|
+
deleteReview: "catalogDeleteReview",
|
|
2054
2099
|
createServiceCategory: "servicesCreateCategory",
|
|
2055
2100
|
getServiceCategories: "servicesGetCategories",
|
|
2056
2101
|
updateServiceCategory: "servicesUpdateCategory",
|
|
@@ -2343,7 +2388,6 @@ var adminMapping = {
|
|
|
2343
2388
|
handleWindmillApprovalCallback: "windmillCallbackControllerHandleApprovalCallback",
|
|
2344
2389
|
handleWindmillBakeryDisposalCallback: "windmillCallbackControllerHandleBakeryDisposalCallback",
|
|
2345
2390
|
handleWindmillOutcomeCallback: "windmillCallbackControllerHandleOutcomeCallback",
|
|
2346
|
-
provisionZitadel: "customersProvisionZitadel",
|
|
2347
2391
|
getCustomers: "customersGetCustomers",
|
|
2348
2392
|
registerCustomer: "customersRegister",
|
|
2349
2393
|
updateCustomer: "customersUpdate",
|
|
@@ -2465,7 +2509,6 @@ var getScrymeV3API2 = (axiosInstance, defaultOrgSlug) => {
|
|
|
2465
2509
|
};
|
|
2466
2510
|
|
|
2467
2511
|
// src/client.tsx
|
|
2468
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
2469
2512
|
var InMemoryStorage = class {
|
|
2470
2513
|
constructor() {
|
|
2471
2514
|
this.cache = /* @__PURE__ */ new Map();
|
|
@@ -2484,6 +2527,10 @@ var SCRYME_SESSION_TOKEN_KEY = "scryme_session_token";
|
|
|
2484
2527
|
var SCRYME_USER_KEY = "scryme_user";
|
|
2485
2528
|
var SCRYME_EXPIRES_AT_KEY = "scryme_expires_at";
|
|
2486
2529
|
var ScrymeClientSDK = class {
|
|
2530
|
+
/**
|
|
2531
|
+
* Initializes the ScrymeClientSDK.
|
|
2532
|
+
* @param config Application and organization configuration parameters.
|
|
2533
|
+
*/
|
|
2487
2534
|
constructor(config) {
|
|
2488
2535
|
if (!config || !config.clientId || !config.orgSlug) {
|
|
2489
2536
|
throw new Error(
|
|
@@ -2548,8 +2595,8 @@ var ScrymeClientSDK = class {
|
|
|
2548
2595
|
state.user = null;
|
|
2549
2596
|
}
|
|
2550
2597
|
}
|
|
2551
|
-
notify("INITIAL_SESSION");
|
|
2552
2598
|
}
|
|
2599
|
+
notify("INITIAL_SESSION");
|
|
2553
2600
|
} catch (e) {
|
|
2554
2601
|
console.error("Failed to initialize Scryme Client SDK session:", e);
|
|
2555
2602
|
}
|
|
@@ -2597,13 +2644,13 @@ var ScrymeClientSDK = class {
|
|
|
2597
2644
|
};
|
|
2598
2645
|
this.axiosInstance.interceptors.request.use(async (req) => {
|
|
2599
2646
|
await initPromise;
|
|
2600
|
-
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh")
|
|
2647
|
+
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh"));
|
|
2601
2648
|
if (!isAuthTokenRequest) {
|
|
2602
2649
|
const isExpired = !state.token || state.expiresAt && Date.now() >= (state.expiresAt || 0) - 3e4;
|
|
2603
2650
|
if (isExpired) {
|
|
2604
2651
|
if (state.token) {
|
|
2605
2652
|
try {
|
|
2606
|
-
await this.auth.refreshSession();
|
|
2653
|
+
await this.customer.auth.refreshSession();
|
|
2607
2654
|
} catch (e) {
|
|
2608
2655
|
console.error(
|
|
2609
2656
|
"Proactive customer session refresh failed in request interceptor:",
|
|
@@ -2631,12 +2678,12 @@ var ScrymeClientSDK = class {
|
|
|
2631
2678
|
(response) => response,
|
|
2632
2679
|
async (error) => {
|
|
2633
2680
|
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")
|
|
2681
|
+
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh"));
|
|
2635
2682
|
if (error.response && error.response.status === 401 && originalRequest && !originalRequest._retry && !isAuthTokenRequest) {
|
|
2636
2683
|
originalRequest._retry = true;
|
|
2637
2684
|
try {
|
|
2638
2685
|
if (state.token) {
|
|
2639
|
-
await this.auth.refreshSession();
|
|
2686
|
+
await this.customer.auth.refreshSession();
|
|
2640
2687
|
if (state.token) {
|
|
2641
2688
|
originalRequest.headers["Authorization"] = `Bearer ${state.token}`;
|
|
2642
2689
|
}
|
|
@@ -2656,7 +2703,87 @@ var ScrymeClientSDK = class {
|
|
|
2656
2703
|
}
|
|
2657
2704
|
);
|
|
2658
2705
|
this.api = getScrymeV3API2(this.axiosInstance, config.orgSlug);
|
|
2659
|
-
|
|
2706
|
+
const baseCatalog = buildModule(this.api, config.orgSlug, catalogMapping);
|
|
2707
|
+
this.catalog = {
|
|
2708
|
+
...baseCatalog,
|
|
2709
|
+
getProduct: async (idOrSlug, options) => {
|
|
2710
|
+
const response = await this.catalog.getProducts(void 0, options);
|
|
2711
|
+
const products = response.data || [];
|
|
2712
|
+
const product = products.find((p) => {
|
|
2713
|
+
if (typeof idOrSlug === "string") {
|
|
2714
|
+
return p.id === idOrSlug || p.slug === idOrSlug;
|
|
2715
|
+
} else {
|
|
2716
|
+
const { id, slug } = idOrSlug;
|
|
2717
|
+
if (id && p.id === id) return true;
|
|
2718
|
+
if (slug && p.slug === slug) return true;
|
|
2719
|
+
return false;
|
|
2720
|
+
}
|
|
2721
|
+
});
|
|
2722
|
+
if (!product) {
|
|
2723
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
2724
|
+
throw new Error(`Product not found matching criteria: ${criteria}`);
|
|
2725
|
+
}
|
|
2726
|
+
return {
|
|
2727
|
+
...response,
|
|
2728
|
+
data: product
|
|
2729
|
+
};
|
|
2730
|
+
},
|
|
2731
|
+
getService: async (idOrSlug, options) => {
|
|
2732
|
+
const response = await this.catalog.getServices(void 0, options);
|
|
2733
|
+
const services = response.data || [];
|
|
2734
|
+
const service = services.find((s) => {
|
|
2735
|
+
if (typeof idOrSlug === "string") {
|
|
2736
|
+
return s.id === idOrSlug || s.slug === idOrSlug;
|
|
2737
|
+
} else {
|
|
2738
|
+
const { id, slug } = idOrSlug;
|
|
2739
|
+
if (id && s.id === id) return true;
|
|
2740
|
+
if (slug && s.slug === slug) return true;
|
|
2741
|
+
return false;
|
|
2742
|
+
}
|
|
2743
|
+
});
|
|
2744
|
+
if (!service) {
|
|
2745
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
2746
|
+
throw new Error(`Service not found matching criteria: ${criteria}`);
|
|
2747
|
+
}
|
|
2748
|
+
return {
|
|
2749
|
+
...response,
|
|
2750
|
+
data: service
|
|
2751
|
+
};
|
|
2752
|
+
},
|
|
2753
|
+
createReview: async (productId, dto, options) => {
|
|
2754
|
+
if (!dto.customerId) {
|
|
2755
|
+
const session = await this.auth.getSession();
|
|
2756
|
+
const user = session?.user;
|
|
2757
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2758
|
+
if (customerId) {
|
|
2759
|
+
dto = { ...dto, customerId };
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
return baseCatalog.createReview(productId, dto, options);
|
|
2763
|
+
},
|
|
2764
|
+
updateReview: async (reviewId, dto, options) => {
|
|
2765
|
+
if (!dto.customerId) {
|
|
2766
|
+
const session = await this.auth.getSession();
|
|
2767
|
+
const user = session?.user;
|
|
2768
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2769
|
+
if (customerId) {
|
|
2770
|
+
dto = { ...dto, customerId };
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
return baseCatalog.updateReview(reviewId, dto, options);
|
|
2774
|
+
},
|
|
2775
|
+
deleteReview: async (reviewId, params, options) => {
|
|
2776
|
+
if (!params || !params.customerId) {
|
|
2777
|
+
const session = await this.auth.getSession();
|
|
2778
|
+
const user = session?.user;
|
|
2779
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2780
|
+
if (customerId) {
|
|
2781
|
+
params = { ...params, customerId };
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
return baseCatalog.deleteReview(reviewId, params, options);
|
|
2785
|
+
}
|
|
2786
|
+
};
|
|
2660
2787
|
this.inventory = buildModule(this.api, config.orgSlug, inventoryMapping);
|
|
2661
2788
|
this.orders = buildModule(this.api, config.orgSlug, ordersMapping);
|
|
2662
2789
|
this.crm = buildModule(this.api, config.orgSlug, crmMapping);
|
|
@@ -2667,20 +2794,47 @@ var ScrymeClientSDK = class {
|
|
|
2667
2794
|
this.admin = buildModule(this.api, config.orgSlug, adminMapping);
|
|
2668
2795
|
this.cart = {
|
|
2669
2796
|
get: async (params) => {
|
|
2670
|
-
return this.orders.getCart(params
|
|
2797
|
+
return this.orders.getCart(params);
|
|
2671
2798
|
},
|
|
2672
2799
|
add: async (dto) => {
|
|
2800
|
+
if (!dto.customerId) {
|
|
2801
|
+
const session = await this.auth.getSession();
|
|
2802
|
+
const user = session?.user;
|
|
2803
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2804
|
+
if (!customerId) {
|
|
2805
|
+
throw new Error("Unauthorized: customerId is required.");
|
|
2806
|
+
}
|
|
2807
|
+
dto = { ...dto, customerId };
|
|
2808
|
+
}
|
|
2673
2809
|
return this.orders.addToCart(dto);
|
|
2674
2810
|
},
|
|
2675
2811
|
remove: async (dto) => {
|
|
2812
|
+
if (!dto.customerId) {
|
|
2813
|
+
const session = await this.auth.getSession();
|
|
2814
|
+
const user = session?.user;
|
|
2815
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2816
|
+
if (!customerId) {
|
|
2817
|
+
throw new Error("Unauthorized: customerId is required.");
|
|
2818
|
+
}
|
|
2819
|
+
dto = { ...dto, customerId };
|
|
2820
|
+
}
|
|
2676
2821
|
return this.orders.removeFromCart(dto);
|
|
2677
2822
|
},
|
|
2678
2823
|
clear: async (params) => {
|
|
2679
|
-
return this.orders.clearCart(params
|
|
2824
|
+
return this.orders.clearCart(params);
|
|
2680
2825
|
},
|
|
2681
2826
|
update: async (dto) => {
|
|
2827
|
+
if (!dto.customerId) {
|
|
2828
|
+
const session = await this.auth.getSession();
|
|
2829
|
+
const user = session?.user;
|
|
2830
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
2831
|
+
if (!customerId) {
|
|
2832
|
+
throw new Error("Unauthorized: customerId is required.");
|
|
2833
|
+
}
|
|
2834
|
+
dto = { ...dto, customerId };
|
|
2835
|
+
}
|
|
2682
2836
|
const response = await this.orders.getCart({
|
|
2683
|
-
sessionId: dto.sessionId
|
|
2837
|
+
sessionId: dto.sessionId || ""
|
|
2684
2838
|
});
|
|
2685
2839
|
const data = response.data;
|
|
2686
2840
|
const items = data?.data?.items || data?.items || [];
|
|
@@ -2701,7 +2855,7 @@ var ScrymeClientSDK = class {
|
|
|
2701
2855
|
productId: dto.productId,
|
|
2702
2856
|
variantId: dto.variantId,
|
|
2703
2857
|
serviceId: dto.serviceId,
|
|
2704
|
-
sessionId: dto.sessionId,
|
|
2858
|
+
sessionId: dto.sessionId || "",
|
|
2705
2859
|
customerId: dto.customerId
|
|
2706
2860
|
});
|
|
2707
2861
|
} else {
|
|
@@ -2721,12 +2875,12 @@ var ScrymeClientSDK = class {
|
|
|
2721
2875
|
}
|
|
2722
2876
|
},
|
|
2723
2877
|
getItems: async (params) => {
|
|
2724
|
-
const res = await this.orders.getCart(params
|
|
2878
|
+
const res = await this.orders.getCart(params);
|
|
2725
2879
|
const data = res?.data || res;
|
|
2726
2880
|
return data?.items || data?.data?.items || [];
|
|
2727
2881
|
},
|
|
2728
2882
|
getTotals: async (params) => {
|
|
2729
|
-
const res = await this.orders.getCart(params
|
|
2883
|
+
const res = await this.orders.getCart(params);
|
|
2730
2884
|
const data = res?.data || res;
|
|
2731
2885
|
const items = data?.items || data?.data?.items || [];
|
|
2732
2886
|
const itemsCount = items.reduce(
|
|
@@ -2768,122 +2922,65 @@ var ScrymeClientSDK = class {
|
|
|
2768
2922
|
return orderResponse?.data || orderResponse;
|
|
2769
2923
|
}
|
|
2770
2924
|
};
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
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();
|
|
2925
|
+
const customerAuth = {
|
|
2926
|
+
get session() {
|
|
2927
|
+
if (!state.token) {
|
|
2928
|
+
return {
|
|
2929
|
+
data: null,
|
|
2930
|
+
isPending: false,
|
|
2931
|
+
error: null
|
|
2932
|
+
};
|
|
2933
|
+
}
|
|
2934
|
+
const userId = state.user?.id || state.user?.userId || state.user?.customerId || "";
|
|
2935
|
+
return {
|
|
2936
|
+
data: {
|
|
2937
|
+
session: {
|
|
2938
|
+
id: userId || state.token,
|
|
2939
|
+
userId,
|
|
2940
|
+
expiresAt: state.expiresAt ? new Date(state.expiresAt) : null,
|
|
2941
|
+
token: state.token
|
|
2942
|
+
},
|
|
2943
|
+
user: state.user
|
|
2944
|
+
},
|
|
2945
|
+
isPending: false,
|
|
2946
|
+
error: null
|
|
2947
|
+
};
|
|
2806
2948
|
},
|
|
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,
|
|
2814
2949
|
signUp: async (dto) => {
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
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");
|
|
2950
|
+
const res = await this.api.customersRegister(config.orgSlug, dto);
|
|
2951
|
+
if (dto.password) {
|
|
2952
|
+
try {
|
|
2953
|
+
await customerAuth.signIn({
|
|
2954
|
+
email: dto.email,
|
|
2955
|
+
password: dto.password
|
|
2956
|
+
});
|
|
2957
|
+
} catch (e) {
|
|
2958
|
+
console.error("Auto sign-in after sign-up failed:", e);
|
|
2850
2959
|
}
|
|
2851
|
-
} catch (e) {
|
|
2852
2960
|
}
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
);
|
|
2857
|
-
const
|
|
2858
|
-
const token =
|
|
2859
|
-
const user = data?.session || null;
|
|
2961
|
+
return res;
|
|
2962
|
+
},
|
|
2963
|
+
signIn: async (credentials) => {
|
|
2964
|
+
const res = await this.api.customersLogin(config.orgSlug, credentials);
|
|
2965
|
+
const authData = res.data;
|
|
2966
|
+
const token = authData?.accessToken || authData?.token;
|
|
2860
2967
|
if (token) {
|
|
2861
2968
|
state.token = token;
|
|
2862
|
-
state.user = user;
|
|
2969
|
+
state.user = authData?.user || authData?.customer || authData?.session;
|
|
2863
2970
|
const jwtExp = getJwtExpiry(token);
|
|
2971
|
+
if (jwtExp) state.expiresAt = jwtExp;
|
|
2864
2972
|
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);
|
|
2973
|
+
if (state.user) {
|
|
2974
|
+
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(state.user));
|
|
2874
2975
|
}
|
|
2875
|
-
if (
|
|
2876
|
-
await storage.setItem(
|
|
2976
|
+
if (state.expiresAt) {
|
|
2977
|
+
await storage.setItem(SCRYME_EXPIRES_AT_KEY, String(state.expiresAt));
|
|
2877
2978
|
}
|
|
2878
2979
|
notify("SIGNED_IN");
|
|
2879
2980
|
}
|
|
2880
|
-
return
|
|
2981
|
+
return authData;
|
|
2881
2982
|
},
|
|
2882
2983
|
signOut: async () => {
|
|
2883
|
-
try {
|
|
2884
|
-
await this.axiosInstance.post("/auth/sign-out");
|
|
2885
|
-
} catch {
|
|
2886
|
-
}
|
|
2887
2984
|
state.token = null;
|
|
2888
2985
|
state.user = null;
|
|
2889
2986
|
delete state.expiresAt;
|
|
@@ -2898,13 +2995,6 @@ var ScrymeClientSDK = class {
|
|
|
2898
2995
|
},
|
|
2899
2996
|
onAuthStateChange: (callback) => {
|
|
2900
2997
|
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
2998
|
return {
|
|
2909
2999
|
unsubscribe: () => {
|
|
2910
3000
|
listeners.delete(callback);
|
|
@@ -2912,86 +3002,158 @@ var ScrymeClientSDK = class {
|
|
|
2912
3002
|
};
|
|
2913
3003
|
},
|
|
2914
3004
|
getSessions: async () => {
|
|
2915
|
-
const res = await this.
|
|
2916
|
-
`/${config.orgSlug}/customers/auth/sessions`
|
|
2917
|
-
);
|
|
3005
|
+
const res = await this.api.customersGetSessions(config.orgSlug);
|
|
2918
3006
|
return res.data?.data || res.data;
|
|
2919
3007
|
},
|
|
2920
3008
|
revokeSession: async (id) => {
|
|
2921
|
-
|
|
2922
|
-
`/${config.orgSlug}/customers/auth/sessions/${id}`
|
|
2923
|
-
);
|
|
2924
|
-
return res.data?.data || res.data;
|
|
3009
|
+
return this.api.customersRevokeSession(config.orgSlug, id);
|
|
2925
3010
|
},
|
|
2926
3011
|
revokeAllSessions: async (mode) => {
|
|
2927
|
-
|
|
2928
|
-
const res = await this.axiosInstance.delete(url);
|
|
2929
|
-
return res.data?.data || res.data;
|
|
3012
|
+
return this.api.customersRevokeAllSessions(config.orgSlug, { mode });
|
|
2930
3013
|
},
|
|
2931
3014
|
getCurrentSession: async () => {
|
|
2932
|
-
const res = await this.
|
|
2933
|
-
`/${config.orgSlug}/customers/auth/session`
|
|
2934
|
-
);
|
|
3015
|
+
const res = await this.api.customersGetCurrentSession(config.orgSlug);
|
|
2935
3016
|
return res.data?.data || res.data;
|
|
2936
3017
|
},
|
|
2937
3018
|
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;
|
|
3019
|
+
const res = await this.api.customersRefreshSession(config.orgSlug);
|
|
3020
|
+
const authData = res.data;
|
|
3021
|
+
const token = authData?.accessToken || authData?.token;
|
|
2944
3022
|
if (token) {
|
|
2945
3023
|
state.token = token;
|
|
2946
|
-
|
|
3024
|
+
if (authData?.user || authData?.customer) {
|
|
3025
|
+
state.user = authData.user || authData.customer;
|
|
3026
|
+
}
|
|
2947
3027
|
const jwtExp = getJwtExpiry(token);
|
|
3028
|
+
if (jwtExp) state.expiresAt = jwtExp;
|
|
2948
3029
|
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
2949
|
-
if (
|
|
2950
|
-
state.
|
|
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);
|
|
3030
|
+
if (state.user) {
|
|
3031
|
+
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(state.user));
|
|
2958
3032
|
}
|
|
2959
|
-
if (
|
|
2960
|
-
await storage.setItem(
|
|
3033
|
+
if (state.expiresAt) {
|
|
3034
|
+
await storage.setItem(SCRYME_EXPIRES_AT_KEY, String(state.expiresAt));
|
|
2961
3035
|
}
|
|
2962
3036
|
notify("SIGNED_IN");
|
|
2963
3037
|
}
|
|
2964
|
-
return
|
|
3038
|
+
return authData;
|
|
2965
3039
|
},
|
|
2966
|
-
|
|
2967
|
-
const
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
);
|
|
2971
|
-
const
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
3040
|
+
useSession: () => {
|
|
3041
|
+
const currentSession = customerAuth.session;
|
|
3042
|
+
const [data, setData] = (0, import_react.useState)(currentSession.data);
|
|
3043
|
+
const [isPending, setIsPending] = (0, import_react.useState)(false);
|
|
3044
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
3045
|
+
const fetchSessionSync = () => {
|
|
3046
|
+
const s = customerAuth.session;
|
|
3047
|
+
setData(s.data);
|
|
3048
|
+
setError(s.error);
|
|
3049
|
+
setIsPending(s.isPending);
|
|
3050
|
+
};
|
|
3051
|
+
const fetchSessionAsync = async () => {
|
|
3052
|
+
setIsPending(true);
|
|
3053
|
+
try {
|
|
3054
|
+
const res = await customerAuth.getCurrentSession();
|
|
3055
|
+
if (res && (res.session || res.customer || res.user)) {
|
|
3056
|
+
setData({
|
|
3057
|
+
session: res.session,
|
|
3058
|
+
user: res.customer || res.user
|
|
3059
|
+
});
|
|
3060
|
+
} else {
|
|
3061
|
+
const sessionState = await customerAuth.getSession();
|
|
3062
|
+
setData({
|
|
3063
|
+
session: {
|
|
3064
|
+
id: sessionState.user?.id || sessionState.user?.userId || sessionState.user?.customerId || sessionState.token,
|
|
3065
|
+
userId: sessionState.user?.id || sessionState.user?.userId || sessionState.user?.customerId || "",
|
|
3066
|
+
expiresAt: sessionState.expiresAt ? new Date(sessionState.expiresAt) : null,
|
|
3067
|
+
token: sessionState.token
|
|
3068
|
+
},
|
|
3069
|
+
user: sessionState.user
|
|
3070
|
+
});
|
|
3071
|
+
}
|
|
3072
|
+
setError(null);
|
|
3073
|
+
} catch (e) {
|
|
3074
|
+
setError(e instanceof Error ? e : new Error(String(e)));
|
|
3075
|
+
setData(null);
|
|
3076
|
+
} finally {
|
|
3077
|
+
setIsPending(false);
|
|
2988
3078
|
}
|
|
2989
|
-
|
|
2990
|
-
|
|
3079
|
+
};
|
|
3080
|
+
(0, import_react.useEffect)(() => {
|
|
3081
|
+
fetchSessionSync();
|
|
3082
|
+
const { unsubscribe } = customerAuth.onAuthStateChange(() => {
|
|
3083
|
+
fetchSessionSync();
|
|
3084
|
+
});
|
|
3085
|
+
return () => unsubscribe();
|
|
3086
|
+
}, []);
|
|
3087
|
+
return {
|
|
3088
|
+
data,
|
|
3089
|
+
isPending,
|
|
3090
|
+
error,
|
|
3091
|
+
refetch: fetchSessionAsync
|
|
3092
|
+
};
|
|
3093
|
+
}
|
|
3094
|
+
};
|
|
3095
|
+
this.customer = {
|
|
3096
|
+
getProfile: async () => {
|
|
3097
|
+
return this.customer.auth.getCurrentSession();
|
|
3098
|
+
},
|
|
3099
|
+
updateProfile: async (dto) => {
|
|
3100
|
+
const session = await this.auth.getSession();
|
|
3101
|
+
const user = session.user;
|
|
3102
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3103
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3104
|
+
return this.admin.updateCustomer(customerId, dto);
|
|
3105
|
+
},
|
|
3106
|
+
getAddresses: async () => {
|
|
3107
|
+
const session = await this.auth.getSession();
|
|
3108
|
+
const user = session.user;
|
|
3109
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3110
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3111
|
+
return this.admin.getCustomerAddresses(customerId);
|
|
3112
|
+
},
|
|
3113
|
+
addAddress: async (dto) => {
|
|
3114
|
+
const session = await this.auth.getSession();
|
|
3115
|
+
const user = session.user;
|
|
3116
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3117
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3118
|
+
return this.admin.addCustomerAddress(customerId, dto);
|
|
3119
|
+
},
|
|
3120
|
+
auth: customerAuth
|
|
3121
|
+
};
|
|
3122
|
+
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
3123
|
+
this.auth = {
|
|
3124
|
+
...baseAuth,
|
|
3125
|
+
...customerAuth,
|
|
3126
|
+
authenticate: async () => {
|
|
3127
|
+
return performExchange();
|
|
3128
|
+
},
|
|
3129
|
+
get session() {
|
|
3130
|
+
return customerAuth.session;
|
|
3131
|
+
},
|
|
3132
|
+
useSession() {
|
|
3133
|
+
return customerAuth.useSession();
|
|
3134
|
+
}
|
|
3135
|
+
};
|
|
3136
|
+
this.bookings = {
|
|
3137
|
+
create: async (dto) => {
|
|
3138
|
+
if (!dto.customerId) {
|
|
3139
|
+
const session = await this.auth.getSession();
|
|
3140
|
+
const user = session?.user;
|
|
3141
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3142
|
+
if (!customerId) {
|
|
3143
|
+
throw new Error("Unauthorized: customerId is required.");
|
|
2991
3144
|
}
|
|
2992
|
-
|
|
3145
|
+
dto = { ...dto, customerId };
|
|
2993
3146
|
}
|
|
2994
|
-
return
|
|
3147
|
+
return this.catalog.createBooking(dto);
|
|
3148
|
+
},
|
|
3149
|
+
get: async (id) => {
|
|
3150
|
+
return this.catalog.getBooking(id);
|
|
3151
|
+
},
|
|
3152
|
+
list: async () => {
|
|
3153
|
+
return this.catalog.getBookings();
|
|
3154
|
+
},
|
|
3155
|
+
cancel: async (id) => {
|
|
3156
|
+
return this.catalog.updateBookingStatus(id, "CANCELLED");
|
|
2995
3157
|
}
|
|
2996
3158
|
};
|
|
2997
3159
|
}
|
|
@@ -2999,209 +3161,13 @@ var ScrymeClientSDK = class {
|
|
|
2999
3161
|
function createClientSDK(config = {}) {
|
|
3000
3162
|
const finalConfig = {
|
|
3001
3163
|
clientId: config.clientId || "mock-client-id",
|
|
3002
|
-
clientSecret: config.clientSecret || "mock-client-secret",
|
|
3003
3164
|
orgSlug: config.orgSlug || "mock-org-slug",
|
|
3004
3165
|
...config
|
|
3005
3166
|
};
|
|
3006
3167
|
return new ScrymeClientSDK(finalConfig);
|
|
3007
3168
|
}
|
|
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
3169
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3202
3170
|
0 && (module.exports = {
|
|
3203
|
-
ScrymeAuthProvider,
|
|
3204
3171
|
ScrymeClientSDK,
|
|
3205
|
-
createClientSDK
|
|
3206
|
-
useScrymeAuth
|
|
3172
|
+
createClientSDK
|
|
3207
3173
|
});
|