@scryme/sdk 9.66.0 → 9.67.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/{base-Cl7_QxqC.d.mts → base-1B2-e5i_.d.mts} +58 -20
- package/dist/{base-Cl7_QxqC.d.ts → base-1B2-e5i_.d.ts} +58 -20
- package/dist/{chunk-PPNV4D3M.mjs → chunk-QS5K7GIL.mjs} +284 -445
- package/dist/client.d.mts +126 -51
- package/dist/client.d.ts +126 -51
- package/dist/client.js +160 -394
- package/dist/client.mjs +3 -7
- package/dist/index.d.mts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +285 -448
- package/dist/index.mjs +3 -7
- package/dist/server.d.mts +184 -4
- package/dist/server.d.ts +184 -4
- package/dist/server.js +145 -67
- package/dist/server.mjs +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -64,7 +64,6 @@ __export(index_exports, {
|
|
|
64
64
|
RegisterPettyCashDtoPaymentMethod: () => RegisterPettyCashDtoPaymentMethod,
|
|
65
65
|
ReviewPriceChangeDtoStatus: () => ReviewPriceChangeDtoStatus,
|
|
66
66
|
RoleManagementControllerGetCustomRolesSortOrder: () => RoleManagementControllerGetCustomRolesSortOrder,
|
|
67
|
-
ScrymeAuthProvider: () => ScrymeAuthProvider,
|
|
68
67
|
ScrymeClientSDK: () => ScrymeClientSDK,
|
|
69
68
|
ScrymeServerSDK: () => ScrymeServerSDK,
|
|
70
69
|
ServicesUpdateBookingStatusBodyStatus: () => ServicesUpdateBookingStatusBodyStatus,
|
|
@@ -97,8 +96,7 @@ __export(index_exports, {
|
|
|
97
96
|
ordersMapping: () => ordersMapping,
|
|
98
97
|
posMapping: () => posMapping,
|
|
99
98
|
publicServicesMapping: () => publicServicesMapping,
|
|
100
|
-
servicesMapping: () => servicesMapping
|
|
101
|
-
useScrymeAuth: () => useScrymeAuth
|
|
99
|
+
servicesMapping: () => servicesMapping
|
|
102
100
|
});
|
|
103
101
|
module.exports = __toCommonJS(index_exports);
|
|
104
102
|
|
|
@@ -715,6 +713,12 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
715
713
|
options
|
|
716
714
|
);
|
|
717
715
|
};
|
|
716
|
+
const catalogGetProduct = (orgSlug, idOrSlug, options) => {
|
|
717
|
+
return axiosInstance.get(
|
|
718
|
+
`/v3/${orgSlug}/catalog/products/${idOrSlug}`,
|
|
719
|
+
options
|
|
720
|
+
);
|
|
721
|
+
};
|
|
718
722
|
const catalogGetServices = (orgSlug, params, options) => {
|
|
719
723
|
return axiosInstance.get(
|
|
720
724
|
`/v3/${orgSlug}/catalog/services`,
|
|
@@ -991,13 +995,6 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
991
995
|
options
|
|
992
996
|
);
|
|
993
997
|
};
|
|
994
|
-
const customersProvisionZitadel = (orgSlug, provisionZitadelDto, options) => {
|
|
995
|
-
return axiosInstance.post(
|
|
996
|
-
`/v3/${orgSlug}/customers/zitadel/provision`,
|
|
997
|
-
provisionZitadelDto,
|
|
998
|
-
options
|
|
999
|
-
);
|
|
1000
|
-
};
|
|
1001
998
|
const customersGetCustomers = (orgSlug, params, options) => {
|
|
1002
999
|
return axiosInstance.get(
|
|
1003
1000
|
`/v3/${orgSlug}/customers`,
|
|
@@ -1021,6 +1018,13 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
1021
1018
|
options
|
|
1022
1019
|
);
|
|
1023
1020
|
};
|
|
1021
|
+
const customersRefreshSession = (orgSlug, options) => {
|
|
1022
|
+
return axiosInstance.post(
|
|
1023
|
+
`/v3/${orgSlug}/customers/auth/refresh`,
|
|
1024
|
+
void 0,
|
|
1025
|
+
options
|
|
1026
|
+
);
|
|
1027
|
+
};
|
|
1024
1028
|
const customersGetCurrentSession = (orgSlug, options) => {
|
|
1025
1029
|
return axiosInstance.get(
|
|
1026
1030
|
`/v3/${orgSlug}/customers/auth/session`,
|
|
@@ -1959,7 +1963,7 @@ var getScrymeV3API = (axiosInstance = import_axios.default) => {
|
|
|
1959
1963
|
}
|
|
1960
1964
|
);
|
|
1961
1965
|
};
|
|
1962
|
-
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,
|
|
1966
|
+
return { inventoryVerifyIntegrity, inventoryFixIntegrity, inventoryGetInventory, inventoryTraceBatch, inventorySplitBatch, inventoryMergeBatches, inventoryCreateAssembly, inventoryCompleteAssembly, inventoryRequestAdjustment, inventoryGetAdjustments, inventoryApproveAdjustment, inventoryRejectAdjustment, inventoryGetLeadTime, inventoryGetWasteAnalysis, inventoryCheckB2BAvailability, inventoryUnpackBatch, inventoryScanUnpackBatch, inventoryQuickStockInquiry, expenseControllerCreateExpense, expenseControllerGetExpenses, expenseControllerGetExpenseCategories, expenseControllerGetExpense, pettyCashControllerCreateFund, pettyCashControllerGetFunds, pettyCashControllerGetFund, pettyCashControllerTopUpFund, pettyCashControllerGetFundTransactions, utilityAccountControllerCreateAccount, utilityAccountControllerGetAccounts, utilityAccountControllerGetAccount, accountingInitialize, accountingGetProfitLoss, accountingGetBalanceSheet, accountingGetCashFlow, accountingGetTaxSummary, invoiceControllerCreateInvoice, invoiceControllerGetInvoices, invoiceControllerGetInvoice, invoiceControllerUpdateInvoice, invoiceControllerDeleteInvoice, invoiceControllerFinalizeInvoice, invoiceControllerGetTemplates, invoiceControllerCreateTemplate, invoiceControllerGetConfig, invoiceControllerUpdateConfig, publicInvoiceControllerDownloadInvoice, publicInvoiceControllerDownloadInvoiceByTransaction, publicInvoiceControllerDownloadReceipt, publicInvoiceControllerGeneratePublicLink, authExchangeToken, authControllerHandleOAuth2, adminControllerGetStats, adminControllerListOrganizations, adminControllerCreateOrganization, adminControllerGetOrganizationDetails, adminControllerUpdateOrganization, adminControllerDeleteOrganization, adminControllerListMembers, adminControllerListUsers, adminControllerBanUser, adminControllerUnbanUser, adminControllerListConnectedApps, adminControllerListSystemLogs, adminControllerListGlobalSettings, adminControllerSetGlobalSetting, adminControllerDeleteGlobalSetting, adminControllerListTiers, adminControllerDefineTier, adminControllerDeleteTier, adminControllerGetOrganizationSubscription, adminControllerUpdateOrganizationSubscription, adminControllerListSystemPayments, adminControllerRecordCustomPayment, adminControllerListIntegrationDefinitions, adminControllerCreateIntegrationDefinition, adminControllerUpdateIntegrationDefinition, adminControllerDeleteIntegrationDefinition, adminControllerListActiveOrganizationIntegrations, webhooksCreate, webhooksList, webhooksDelete, windmillCallbackControllerHandleCallback, windmillCallbackControllerHandleApprovalCallback, windmillCallbackControllerHandleBakeryDisposalCallback, windmillCallbackControllerHandleOutcomeCallback, catalogGetProducts, catalogCreateProduct, catalogGetProduct, catalogGetServices, catalogUpdateProduct, catalogUpdateSupplierVariant, catalogGetPriceChangeRequests, catalogReviewPriceChangeRequest, servicesCreateCategory, servicesGetCategories, servicesUpdateCategory, servicesDeleteCategory, servicesCreateService, servicesGetServices, servicesGetCurrentMemberShifts, servicesGetShifts, servicesGetService, servicesUpdateService, servicesDeleteService, servicesCreateResource, servicesGetResources, servicesUpdateResource, servicesDeleteResource, servicesCreateBooking, servicesGetBookings, servicesGetBooking, servicesUpdateBookingStatus, servicesCompleteBooking, servicesCreateShift, servicesGetStaffShifts, servicesAddBreak, servicesRegisterCustomerApp, servicesGetUtilization, servicesGetPerformance, servicesGetFunnel, publicServicesListServices, publicServicesGetCategories, publicServicesGetService, publicServicesGetAvailability, publicServicesRequestOtp, publicServicesVerifyOtp, publicServicesCreatePublicBooking, customersGetCustomers, customersRegister, customersLogin, customersRefreshSession, customersGetCurrentSession, customersGetSessions, customersRevokeAllSessions, customersRevokeSession, customersUpdate, customersGetCustomerById, customersDelete, customersGetAddresses, customersAddAddress, businessAccountControllerCreate, businessAccountControllerGetOne, crmControllerCreateRecord, crmControllerGetRecord, crmControllerUpdateRecord, crmControllerCreateNote, crmControllerGetRecordNotes, crmControllerCreateActivity, crmControllerGetTimeline, crmControllerCreateObject, crmControllerListObjects, crmControllerCreateField, crmControllerListFields, crmControllerCreateRelationship, crmControllerListRelationships, crmControllerCreateAssociation, crmControllerListRecordAssociations, loyaltyRedeemReward, loyaltyGetCustomerStatus, loyaltyValidateVoucher, ordersCreateOrder, ordersGetOrders, ordersUpdateStatus, ordersRequestB2BQuote, ordersConvertQuoteToOrder, paymentsControllerHandleStkCallback, pOSProvision, pOSLogin, pOSGetMe, pOSProcessSale, pOSSync, pOSGetTransactions, pOSRegisterPettyCash, pOSGetPettyCashFunds, pOSGetPettyCashTransactions, membersControllerGetMembers, membersControllerCreateMember, membersControllerGetMember, membersControllerUpdateMember, membersControllerDeleteMember, membersControllerGetMemberActivity, membersControllerUpdateStatus, membersControllerAdminCheckOut, terminalMembersControllerLogin, invitationsList, invitationsCreate, invitationsRevoke, invitationsAccept, roleManagementControllerGetCustomRoles, roleManagementControllerCreateCustomRole, roleManagementControllerUpdateCustomRole, roleManagementControllerDeleteCustomRole, roleManagementControllerGetPermissionSets, roleManagementControllerCreatePermissionSet, roleManagementControllerGetRoleGroups, roleManagementControllerCreateRoleGroup, roleManagementControllerAssignRoles, roleManagementControllerRemoveRoles, departmentsList, departmentsCreate, departmentsGet, departmentsUpdate, departmentsDelete, departmentsAddMember, departmentsRemoveMember, attendanceControllerGetLogs, attendanceControllerCheckIn, attendanceControllerCheckOut, attendanceControllerGetMyStatus, attendanceControllerGetStatus, announcementControllerBroadcastAnnouncement, cartControllerGetCart, cartControllerClearCart, cartControllerAddToCart, cartControllerRemoveFromCart, favoritesControllerGetFavorites, favoritesControllerAddFavorite, favoritesControllerRemoveFavorite, stockingGetPurchases, stockingCreatePurchase, stockingReceivePurchase, stockingGetTransfers, stockingCreateTransfer, stockingShipTransfer, stockingReceiveTransfer, stockingGetRequests, stockingGetPendingDispatch, stockingDispatchOrders, stockingGetActiveDeliveries, stockingReconcilePod, stockingGetPhysicalReconciliations, stockingSubmitPhysicalReconciliation, stockingGetReconciliationReport, stockingGetPartners, stockingCreatePartner, stockingGetPartner, stockingUpdatePartner, stockingAdjustPartnerWallet, standalonePosControllerCreateSetupKey, standalonePosControllerActivateDevice, standalonePosControllerValidateKey, standalonePosControllerLinkOrganization, b2BGetCatalog, b2BGetInvoices, b2BGetOrders, b2BCreateOrder, b2BCreateQuote, crmIntegrationsGetAuthUrl, crmIntegrationsHandleCallback, crmIntegrationsHandleWebhook, crmIntegrationsReplyToActivity, unitsGetUnits, strapiCreateConnection, strapiListConnections, strapiGetConnection, strapiUpdateConnection, strapiDeleteConnection, strapiTriggerSync, strapiEnqueueSync, strapiGetWebhookLogs, strapiGetSyncLogs, strapiExchangeCustomerToken, strapiRegisterCustomer, strapiReceiveWebhook, analyticsControllerGetDashboardAnalytics, analyticsControllerGetResourceUtilization };
|
|
1963
1967
|
};
|
|
1964
1968
|
|
|
1965
1969
|
// src/generated/model/addDepartmentMemberDtoRole.ts
|
|
@@ -2409,6 +2413,7 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2409
2413
|
"webhooksList",
|
|
2410
2414
|
"webhooksDelete",
|
|
2411
2415
|
"catalogGetProducts",
|
|
2416
|
+
"catalogGetProduct",
|
|
2412
2417
|
"catalogCreateProduct",
|
|
2413
2418
|
"catalogGetServices",
|
|
2414
2419
|
"catalogUpdateProduct",
|
|
@@ -2442,7 +2447,6 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2442
2447
|
"servicesGetUtilization",
|
|
2443
2448
|
"servicesGetPerformance",
|
|
2444
2449
|
"servicesGetFunnel",
|
|
2445
|
-
"customersProvisionZitadel",
|
|
2446
2450
|
"customersGetCustomers",
|
|
2447
2451
|
"customersRegister",
|
|
2448
2452
|
"customersUpdate",
|
|
@@ -2451,6 +2455,10 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2451
2455
|
"customersGetAddresses",
|
|
2452
2456
|
"customersAddAddress",
|
|
2453
2457
|
"customersGetCurrentSession",
|
|
2458
|
+
"customersGetSessions",
|
|
2459
|
+
"customersRevokeSession",
|
|
2460
|
+
"customersRevokeAllSessions",
|
|
2461
|
+
"customersRefreshSession",
|
|
2454
2462
|
"businessAccountControllerCreate",
|
|
2455
2463
|
"businessAccountControllerGetOne",
|
|
2456
2464
|
"crmControllerCreateRecord",
|
|
@@ -2519,6 +2527,7 @@ var methodsWithOrgSlugSet = /* @__PURE__ */ new Set([
|
|
|
2519
2527
|
]);
|
|
2520
2528
|
var catalogMapping = {
|
|
2521
2529
|
getProducts: "catalogGetProducts",
|
|
2530
|
+
getProduct: "catalogGetProduct",
|
|
2522
2531
|
createProduct: "catalogCreateProduct",
|
|
2523
2532
|
getServices: "catalogGetServices",
|
|
2524
2533
|
updateProduct: "catalogUpdateProduct",
|
|
@@ -2817,7 +2826,6 @@ var adminMapping = {
|
|
|
2817
2826
|
handleWindmillApprovalCallback: "windmillCallbackControllerHandleApprovalCallback",
|
|
2818
2827
|
handleWindmillBakeryDisposalCallback: "windmillCallbackControllerHandleBakeryDisposalCallback",
|
|
2819
2828
|
handleWindmillOutcomeCallback: "windmillCallbackControllerHandleOutcomeCallback",
|
|
2820
|
-
provisionZitadel: "customersProvisionZitadel",
|
|
2821
2829
|
getCustomers: "customersGetCustomers",
|
|
2822
2830
|
registerCustomer: "customersRegister",
|
|
2823
2831
|
updateCustomer: "customersUpdate",
|
|
@@ -2870,9 +2878,7 @@ function getJwtExpiry(token) {
|
|
|
2870
2878
|
}
|
|
2871
2879
|
|
|
2872
2880
|
// src/client.tsx
|
|
2873
|
-
var import_react = require("react");
|
|
2874
2881
|
var import_axios2 = __toESM(require("axios"));
|
|
2875
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
2876
2882
|
var InMemoryStorage = class {
|
|
2877
2883
|
constructor() {
|
|
2878
2884
|
this.cache = /* @__PURE__ */ new Map();
|
|
@@ -2891,6 +2897,10 @@ var SCRYME_SESSION_TOKEN_KEY = "scryme_session_token";
|
|
|
2891
2897
|
var SCRYME_USER_KEY = "scryme_user";
|
|
2892
2898
|
var SCRYME_EXPIRES_AT_KEY = "scryme_expires_at";
|
|
2893
2899
|
var ScrymeClientSDK = class {
|
|
2900
|
+
/**
|
|
2901
|
+
* Initializes the ScrymeClientSDK.
|
|
2902
|
+
* @param config Application and organization configuration parameters.
|
|
2903
|
+
*/
|
|
2894
2904
|
constructor(config) {
|
|
2895
2905
|
if (!config || !config.clientId || !config.orgSlug) {
|
|
2896
2906
|
throw new Error(
|
|
@@ -2955,8 +2965,8 @@ var ScrymeClientSDK = class {
|
|
|
2955
2965
|
state.user = null;
|
|
2956
2966
|
}
|
|
2957
2967
|
}
|
|
2958
|
-
notify("INITIAL_SESSION");
|
|
2959
2968
|
}
|
|
2969
|
+
notify("INITIAL_SESSION");
|
|
2960
2970
|
} catch (e) {
|
|
2961
2971
|
console.error("Failed to initialize Scryme Client SDK session:", e);
|
|
2962
2972
|
}
|
|
@@ -3004,13 +3014,13 @@ var ScrymeClientSDK = class {
|
|
|
3004
3014
|
};
|
|
3005
3015
|
this.axiosInstance.interceptors.request.use(async (req) => {
|
|
3006
3016
|
await initPromise;
|
|
3007
|
-
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh")
|
|
3017
|
+
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh"));
|
|
3008
3018
|
if (!isAuthTokenRequest) {
|
|
3009
3019
|
const isExpired = !state.token || state.expiresAt && Date.now() >= (state.expiresAt || 0) - 3e4;
|
|
3010
3020
|
if (isExpired) {
|
|
3011
3021
|
if (state.token) {
|
|
3012
3022
|
try {
|
|
3013
|
-
await this.auth.refreshSession();
|
|
3023
|
+
await this.customer.auth.refreshSession();
|
|
3014
3024
|
} catch (e) {
|
|
3015
3025
|
console.error(
|
|
3016
3026
|
"Proactive customer session refresh failed in request interceptor:",
|
|
@@ -3038,12 +3048,12 @@ var ScrymeClientSDK = class {
|
|
|
3038
3048
|
(response) => response,
|
|
3039
3049
|
async (error) => {
|
|
3040
3050
|
const originalRequest = error.config;
|
|
3041
|
-
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh")
|
|
3051
|
+
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh"));
|
|
3042
3052
|
if (error.response && error.response.status === 401 && originalRequest && !originalRequest._retry && !isAuthTokenRequest) {
|
|
3043
3053
|
originalRequest._retry = true;
|
|
3044
3054
|
try {
|
|
3045
3055
|
if (state.token) {
|
|
3046
|
-
await this.auth.refreshSession();
|
|
3056
|
+
await this.customer.auth.refreshSession();
|
|
3047
3057
|
if (state.token) {
|
|
3048
3058
|
originalRequest.headers["Authorization"] = `Bearer ${state.token}`;
|
|
3049
3059
|
}
|
|
@@ -3063,7 +3073,54 @@ var ScrymeClientSDK = class {
|
|
|
3063
3073
|
}
|
|
3064
3074
|
);
|
|
3065
3075
|
this.api = getScrymeV3API2(this.axiosInstance, config.orgSlug);
|
|
3066
|
-
|
|
3076
|
+
const baseCatalog = buildModule(this.api, config.orgSlug, catalogMapping);
|
|
3077
|
+
this.catalog = {
|
|
3078
|
+
...baseCatalog,
|
|
3079
|
+
getProduct: async (idOrSlug, options) => {
|
|
3080
|
+
const response = await this.catalog.getProducts(void 0, options);
|
|
3081
|
+
const products = response.data || [];
|
|
3082
|
+
const product = products.find((p) => {
|
|
3083
|
+
if (typeof idOrSlug === "string") {
|
|
3084
|
+
return p.id === idOrSlug || p.slug === idOrSlug;
|
|
3085
|
+
} else {
|
|
3086
|
+
const { id, slug } = idOrSlug;
|
|
3087
|
+
if (id && p.id === id) return true;
|
|
3088
|
+
if (slug && p.slug === slug) return true;
|
|
3089
|
+
return false;
|
|
3090
|
+
}
|
|
3091
|
+
});
|
|
3092
|
+
if (!product) {
|
|
3093
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
3094
|
+
throw new Error(`Product not found matching criteria: ${criteria}`);
|
|
3095
|
+
}
|
|
3096
|
+
return {
|
|
3097
|
+
...response,
|
|
3098
|
+
data: product
|
|
3099
|
+
};
|
|
3100
|
+
},
|
|
3101
|
+
getService: async (idOrSlug, options) => {
|
|
3102
|
+
const response = await this.catalog.getServices(void 0, options);
|
|
3103
|
+
const services = response.data || [];
|
|
3104
|
+
const service = services.find((s) => {
|
|
3105
|
+
if (typeof idOrSlug === "string") {
|
|
3106
|
+
return s.id === idOrSlug || s.slug === idOrSlug;
|
|
3107
|
+
} else {
|
|
3108
|
+
const { id, slug } = idOrSlug;
|
|
3109
|
+
if (id && s.id === id) return true;
|
|
3110
|
+
if (slug && s.slug === slug) return true;
|
|
3111
|
+
return false;
|
|
3112
|
+
}
|
|
3113
|
+
});
|
|
3114
|
+
if (!service) {
|
|
3115
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
3116
|
+
throw new Error(`Service not found matching criteria: ${criteria}`);
|
|
3117
|
+
}
|
|
3118
|
+
return {
|
|
3119
|
+
...response,
|
|
3120
|
+
data: service
|
|
3121
|
+
};
|
|
3122
|
+
}
|
|
3123
|
+
};
|
|
3067
3124
|
this.inventory = buildModule(this.api, config.orgSlug, inventoryMapping);
|
|
3068
3125
|
this.orders = buildModule(this.api, config.orgSlug, ordersMapping);
|
|
3069
3126
|
this.crm = buildModule(this.api, config.orgSlug, crmMapping);
|
|
@@ -3074,7 +3131,7 @@ var ScrymeClientSDK = class {
|
|
|
3074
3131
|
this.admin = buildModule(this.api, config.orgSlug, adminMapping);
|
|
3075
3132
|
this.cart = {
|
|
3076
3133
|
get: async (params) => {
|
|
3077
|
-
return this.orders.getCart(params
|
|
3134
|
+
return this.orders.getCart(params);
|
|
3078
3135
|
},
|
|
3079
3136
|
add: async (dto) => {
|
|
3080
3137
|
return this.orders.addToCart(dto);
|
|
@@ -3083,11 +3140,11 @@ var ScrymeClientSDK = class {
|
|
|
3083
3140
|
return this.orders.removeFromCart(dto);
|
|
3084
3141
|
},
|
|
3085
3142
|
clear: async (params) => {
|
|
3086
|
-
return this.orders.clearCart(params
|
|
3143
|
+
return this.orders.clearCart(params);
|
|
3087
3144
|
},
|
|
3088
3145
|
update: async (dto) => {
|
|
3089
3146
|
const response = await this.orders.getCart({
|
|
3090
|
-
sessionId: dto.sessionId
|
|
3147
|
+
sessionId: dto.sessionId || ""
|
|
3091
3148
|
});
|
|
3092
3149
|
const data = response.data;
|
|
3093
3150
|
const items = data?.data?.items || data?.items || [];
|
|
@@ -3108,7 +3165,7 @@ var ScrymeClientSDK = class {
|
|
|
3108
3165
|
productId: dto.productId,
|
|
3109
3166
|
variantId: dto.variantId,
|
|
3110
3167
|
serviceId: dto.serviceId,
|
|
3111
|
-
sessionId: dto.sessionId,
|
|
3168
|
+
sessionId: dto.sessionId || "",
|
|
3112
3169
|
customerId: dto.customerId
|
|
3113
3170
|
});
|
|
3114
3171
|
} else {
|
|
@@ -3128,12 +3185,12 @@ var ScrymeClientSDK = class {
|
|
|
3128
3185
|
}
|
|
3129
3186
|
},
|
|
3130
3187
|
getItems: async (params) => {
|
|
3131
|
-
const res = await this.orders.getCart(params
|
|
3188
|
+
const res = await this.orders.getCart(params);
|
|
3132
3189
|
const data = res?.data || res;
|
|
3133
3190
|
return data?.items || data?.data?.items || [];
|
|
3134
3191
|
},
|
|
3135
3192
|
getTotals: async (params) => {
|
|
3136
|
-
const res = await this.orders.getCart(params
|
|
3193
|
+
const res = await this.orders.getCart(params);
|
|
3137
3194
|
const data = res?.data || res;
|
|
3138
3195
|
const items = data?.items || data?.data?.items || [];
|
|
3139
3196
|
const itemsCount = items.reduce(
|
|
@@ -3175,122 +3232,31 @@ var ScrymeClientSDK = class {
|
|
|
3175
3232
|
return orderResponse?.data || orderResponse;
|
|
3176
3233
|
}
|
|
3177
3234
|
};
|
|
3178
|
-
|
|
3179
|
-
getProfile: async () => {
|
|
3180
|
-
return this.auth.getCurrentSession();
|
|
3181
|
-
},
|
|
3182
|
-
updateProfile: async (dto) => {
|
|
3183
|
-
const session = await this.auth.getSession();
|
|
3184
|
-
const user = session.user;
|
|
3185
|
-
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3186
|
-
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3187
|
-
return this.admin.updateCustomer(customerId, dto);
|
|
3188
|
-
},
|
|
3189
|
-
getAddresses: async () => {
|
|
3190
|
-
const session = await this.auth.getSession();
|
|
3191
|
-
const user = session.user;
|
|
3192
|
-
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3193
|
-
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3194
|
-
return this.admin.getCustomerAddresses(customerId);
|
|
3195
|
-
},
|
|
3196
|
-
addAddress: async (dto) => {
|
|
3197
|
-
const session = await this.auth.getSession();
|
|
3198
|
-
const user = session.user;
|
|
3199
|
-
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3200
|
-
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3201
|
-
return this.admin.addCustomerAddress(customerId, dto);
|
|
3202
|
-
}
|
|
3203
|
-
};
|
|
3204
|
-
this.bookings = {
|
|
3205
|
-
create: async (dto) => {
|
|
3206
|
-
return this.catalog.createBooking(dto);
|
|
3207
|
-
},
|
|
3208
|
-
get: async (id) => {
|
|
3209
|
-
return this.catalog.getBooking(id);
|
|
3210
|
-
},
|
|
3211
|
-
list: async () => {
|
|
3212
|
-
return this.catalog.getBookings();
|
|
3213
|
-
},
|
|
3214
|
-
cancel: async (id) => {
|
|
3215
|
-
return this.catalog.updateBookingStatus(id, "CANCELLED");
|
|
3216
|
-
}
|
|
3217
|
-
};
|
|
3218
|
-
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
3219
|
-
this.auth = {
|
|
3220
|
-
...baseAuth,
|
|
3235
|
+
const customerAuth = {
|
|
3221
3236
|
signUp: async (dto) => {
|
|
3222
3237
|
return this.api.customersRegister(config.orgSlug, dto);
|
|
3223
3238
|
},
|
|
3224
|
-
authenticate: async () => {
|
|
3225
|
-
return performExchange();
|
|
3226
|
-
},
|
|
3227
3239
|
signIn: async (credentials) => {
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
const response2 = await import_axios2.default.post(postUrl, credentials);
|
|
3232
|
-
const data2 = response2.data;
|
|
3233
|
-
const token2 = data2?.session?.token || data2?.token || null;
|
|
3234
|
-
const user2 = data2?.user || null;
|
|
3235
|
-
if (token2) {
|
|
3236
|
-
state.token = token2;
|
|
3237
|
-
state.user = user2;
|
|
3238
|
-
const jwtExp = getJwtExpiry(token2);
|
|
3239
|
-
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token2);
|
|
3240
|
-
if (jwtExp) {
|
|
3241
|
-
state.expiresAt = jwtExp;
|
|
3242
|
-
await storage.setItem(
|
|
3243
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
3244
|
-
String(state.expiresAt)
|
|
3245
|
-
);
|
|
3246
|
-
} else {
|
|
3247
|
-
delete state.expiresAt;
|
|
3248
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
3249
|
-
}
|
|
3250
|
-
if (user2) {
|
|
3251
|
-
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(user2));
|
|
3252
|
-
}
|
|
3253
|
-
notify("SIGNED_IN");
|
|
3254
|
-
return data2;
|
|
3255
|
-
} else {
|
|
3256
|
-
throw new Error("No token returned");
|
|
3257
|
-
}
|
|
3258
|
-
} catch (e) {
|
|
3259
|
-
}
|
|
3260
|
-
const response = await this.axiosInstance.post(
|
|
3261
|
-
`/${config.orgSlug}/customers/auth/login`,
|
|
3262
|
-
credentials
|
|
3263
|
-
);
|
|
3264
|
-
const data = response.data?.data || response.data;
|
|
3265
|
-
const token = data?.token || null;
|
|
3266
|
-
const user = data?.session || null;
|
|
3240
|
+
const res = await this.api.customersLogin(config.orgSlug, credentials);
|
|
3241
|
+
const authData = res.data;
|
|
3242
|
+
const token = authData?.accessToken || authData?.token;
|
|
3267
3243
|
if (token) {
|
|
3268
3244
|
state.token = token;
|
|
3269
|
-
state.user = user;
|
|
3245
|
+
state.user = authData?.user || authData?.customer || authData?.session;
|
|
3270
3246
|
const jwtExp = getJwtExpiry(token);
|
|
3247
|
+
if (jwtExp) state.expiresAt = jwtExp;
|
|
3271
3248
|
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
3272
|
-
if (
|
|
3273
|
-
state.
|
|
3274
|
-
await storage.setItem(
|
|
3275
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
3276
|
-
String(state.expiresAt)
|
|
3277
|
-
);
|
|
3278
|
-
} else {
|
|
3279
|
-
delete state.expiresAt;
|
|
3280
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
3249
|
+
if (state.user) {
|
|
3250
|
+
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(state.user));
|
|
3281
3251
|
}
|
|
3282
|
-
if (
|
|
3283
|
-
await storage.setItem(
|
|
3252
|
+
if (state.expiresAt) {
|
|
3253
|
+
await storage.setItem(SCRYME_EXPIRES_AT_KEY, String(state.expiresAt));
|
|
3284
3254
|
}
|
|
3285
3255
|
notify("SIGNED_IN");
|
|
3286
3256
|
}
|
|
3287
|
-
return
|
|
3257
|
+
return authData;
|
|
3288
3258
|
},
|
|
3289
3259
|
signOut: async () => {
|
|
3290
|
-
try {
|
|
3291
|
-
await this.axiosInstance.post("/auth/sign-out");
|
|
3292
|
-
} catch {
|
|
3293
|
-
}
|
|
3294
3260
|
state.token = null;
|
|
3295
3261
|
state.user = null;
|
|
3296
3262
|
delete state.expiresAt;
|
|
@@ -3305,13 +3271,6 @@ var ScrymeClientSDK = class {
|
|
|
3305
3271
|
},
|
|
3306
3272
|
onAuthStateChange: (callback) => {
|
|
3307
3273
|
listeners.add(callback);
|
|
3308
|
-
initPromise.then(() => {
|
|
3309
|
-
try {
|
|
3310
|
-
callback("INITIAL_SESSION", { ...state });
|
|
3311
|
-
} catch (e) {
|
|
3312
|
-
console.error("Error in immediate auth state listener call:", e);
|
|
3313
|
-
}
|
|
3314
|
-
});
|
|
3315
3274
|
return {
|
|
3316
3275
|
unsubscribe: () => {
|
|
3317
3276
|
listeners.delete(callback);
|
|
@@ -3319,86 +3278,89 @@ var ScrymeClientSDK = class {
|
|
|
3319
3278
|
};
|
|
3320
3279
|
},
|
|
3321
3280
|
getSessions: async () => {
|
|
3322
|
-
const res = await this.
|
|
3323
|
-
`/${config.orgSlug}/customers/auth/sessions`
|
|
3324
|
-
);
|
|
3281
|
+
const res = await this.api.customersGetSessions(config.orgSlug);
|
|
3325
3282
|
return res.data?.data || res.data;
|
|
3326
3283
|
},
|
|
3327
3284
|
revokeSession: async (id) => {
|
|
3328
|
-
|
|
3329
|
-
`/${config.orgSlug}/customers/auth/sessions/${id}`
|
|
3330
|
-
);
|
|
3331
|
-
return res.data?.data || res.data;
|
|
3285
|
+
return this.api.customersRevokeSession(config.orgSlug, id);
|
|
3332
3286
|
},
|
|
3333
3287
|
revokeAllSessions: async (mode) => {
|
|
3334
|
-
|
|
3335
|
-
const res = await this.axiosInstance.delete(url);
|
|
3336
|
-
return res.data?.data || res.data;
|
|
3288
|
+
return this.api.customersRevokeAllSessions(config.orgSlug, { mode });
|
|
3337
3289
|
},
|
|
3338
3290
|
getCurrentSession: async () => {
|
|
3339
|
-
const res = await this.
|
|
3340
|
-
`/${config.orgSlug}/customers/auth/session`
|
|
3341
|
-
);
|
|
3291
|
+
const res = await this.api.customersGetCurrentSession(config.orgSlug);
|
|
3342
3292
|
return res.data?.data || res.data;
|
|
3343
3293
|
},
|
|
3344
3294
|
refreshSession: async () => {
|
|
3345
|
-
const
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
const data = response.data?.data || response.data;
|
|
3349
|
-
const token = data?.token || null;
|
|
3350
|
-
const user = data?.session || null;
|
|
3295
|
+
const res = await this.api.customersRefreshSession(config.orgSlug);
|
|
3296
|
+
const authData = res.data;
|
|
3297
|
+
const token = authData?.accessToken || authData?.token;
|
|
3351
3298
|
if (token) {
|
|
3352
3299
|
state.token = token;
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
3356
|
-
if (jwtExp) {
|
|
3357
|
-
state.expiresAt = jwtExp;
|
|
3358
|
-
await storage.setItem(
|
|
3359
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
3360
|
-
String(state.expiresAt)
|
|
3361
|
-
);
|
|
3362
|
-
} else {
|
|
3363
|
-
delete state.expiresAt;
|
|
3364
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
3300
|
+
if (authData?.user || authData?.customer) {
|
|
3301
|
+
state.user = authData.user || authData.customer;
|
|
3365
3302
|
}
|
|
3366
|
-
if (user) {
|
|
3367
|
-
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(user));
|
|
3368
|
-
}
|
|
3369
|
-
notify("SIGNED_IN");
|
|
3370
|
-
}
|
|
3371
|
-
return data;
|
|
3372
|
-
},
|
|
3373
|
-
swapZitadel: async (zitadelToken) => {
|
|
3374
|
-
const response = await this.axiosInstance.post(
|
|
3375
|
-
`/${config.orgSlug}/customers/auth/swap-zitadel`,
|
|
3376
|
-
{ zitadelToken }
|
|
3377
|
-
);
|
|
3378
|
-
const data = response.data?.data || response.data;
|
|
3379
|
-
const token = data?.token || null;
|
|
3380
|
-
const user = data?.session || null;
|
|
3381
|
-
if (token) {
|
|
3382
|
-
state.token = token;
|
|
3383
|
-
state.user = user;
|
|
3384
3303
|
const jwtExp = getJwtExpiry(token);
|
|
3304
|
+
if (jwtExp) state.expiresAt = jwtExp;
|
|
3385
3305
|
await storage.setItem(SCRYME_SESSION_TOKEN_KEY, token);
|
|
3386
|
-
if (
|
|
3387
|
-
state.
|
|
3388
|
-
await storage.setItem(
|
|
3389
|
-
SCRYME_EXPIRES_AT_KEY,
|
|
3390
|
-
String(state.expiresAt)
|
|
3391
|
-
);
|
|
3392
|
-
} else {
|
|
3393
|
-
delete state.expiresAt;
|
|
3394
|
-
await storage.removeItem(SCRYME_EXPIRES_AT_KEY);
|
|
3306
|
+
if (state.user) {
|
|
3307
|
+
await storage.setItem(SCRYME_USER_KEY, JSON.stringify(state.user));
|
|
3395
3308
|
}
|
|
3396
|
-
if (
|
|
3397
|
-
await storage.setItem(
|
|
3309
|
+
if (state.expiresAt) {
|
|
3310
|
+
await storage.setItem(SCRYME_EXPIRES_AT_KEY, String(state.expiresAt));
|
|
3398
3311
|
}
|
|
3399
3312
|
notify("SIGNED_IN");
|
|
3400
3313
|
}
|
|
3401
|
-
return
|
|
3314
|
+
return authData;
|
|
3315
|
+
}
|
|
3316
|
+
};
|
|
3317
|
+
this.customer = {
|
|
3318
|
+
getProfile: async () => {
|
|
3319
|
+
return this.customer.auth.getCurrentSession();
|
|
3320
|
+
},
|
|
3321
|
+
updateProfile: async (dto) => {
|
|
3322
|
+
const session = await this.auth.getSession();
|
|
3323
|
+
const user = session.user;
|
|
3324
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3325
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3326
|
+
return this.admin.updateCustomer(customerId, dto);
|
|
3327
|
+
},
|
|
3328
|
+
getAddresses: async () => {
|
|
3329
|
+
const session = await this.auth.getSession();
|
|
3330
|
+
const user = session.user;
|
|
3331
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3332
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3333
|
+
return this.admin.getCustomerAddresses(customerId);
|
|
3334
|
+
},
|
|
3335
|
+
addAddress: async (dto) => {
|
|
3336
|
+
const session = await this.auth.getSession();
|
|
3337
|
+
const user = session.user;
|
|
3338
|
+
const customerId = user?.customerId || user?.id || user?.customer?.id;
|
|
3339
|
+
if (!customerId) throw new Error("No authenticated customer found.");
|
|
3340
|
+
return this.admin.addCustomerAddress(customerId, dto);
|
|
3341
|
+
},
|
|
3342
|
+
auth: customerAuth
|
|
3343
|
+
};
|
|
3344
|
+
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
3345
|
+
this.auth = {
|
|
3346
|
+
...baseAuth,
|
|
3347
|
+
...customerAuth,
|
|
3348
|
+
authenticate: async () => {
|
|
3349
|
+
return performExchange();
|
|
3350
|
+
}
|
|
3351
|
+
};
|
|
3352
|
+
this.bookings = {
|
|
3353
|
+
create: async (dto) => {
|
|
3354
|
+
return this.catalog.createBooking(dto);
|
|
3355
|
+
},
|
|
3356
|
+
get: async (id) => {
|
|
3357
|
+
return this.catalog.getBooking(id);
|
|
3358
|
+
},
|
|
3359
|
+
list: async () => {
|
|
3360
|
+
return this.catalog.getBookings();
|
|
3361
|
+
},
|
|
3362
|
+
cancel: async (id) => {
|
|
3363
|
+
return this.catalog.updateBookingStatus(id, "CANCELLED");
|
|
3402
3364
|
}
|
|
3403
3365
|
};
|
|
3404
3366
|
}
|
|
@@ -3406,205 +3368,11 @@ var ScrymeClientSDK = class {
|
|
|
3406
3368
|
function createClientSDK(config = {}) {
|
|
3407
3369
|
const finalConfig = {
|
|
3408
3370
|
clientId: config.clientId || "mock-client-id",
|
|
3409
|
-
clientSecret: config.clientSecret || "mock-client-secret",
|
|
3410
3371
|
orgSlug: config.orgSlug || "mock-org-slug",
|
|
3411
3372
|
...config
|
|
3412
3373
|
};
|
|
3413
3374
|
return new ScrymeClientSDK(finalConfig);
|
|
3414
3375
|
}
|
|
3415
|
-
var AuthContext = (0, import_react.createContext)(void 0);
|
|
3416
|
-
var ScrymeAuthProvider = ({
|
|
3417
|
-
sdk,
|
|
3418
|
-
children
|
|
3419
|
-
}) => {
|
|
3420
|
-
const [session, setSession] = (0, import_react.useState)({
|
|
3421
|
-
token: null,
|
|
3422
|
-
user: null
|
|
3423
|
-
});
|
|
3424
|
-
const [isLoading, setIsLoading] = (0, import_react.useState)(true);
|
|
3425
|
-
const [cart, setCart] = (0, import_react.useState)(null);
|
|
3426
|
-
const [cartLoading, setCartLoading] = (0, import_react.useState)(false);
|
|
3427
|
-
const [customerProfile, setCustomerProfile] = (0, import_react.useState)(null);
|
|
3428
|
-
const [customerAddresses, setCustomerAddresses] = (0, import_react.useState)([]);
|
|
3429
|
-
const [bookingsList, setBookingsList] = (0, import_react.useState)([]);
|
|
3430
|
-
const [bookingsLoading, setBookingsLoading] = (0, import_react.useState)(false);
|
|
3431
|
-
(0, import_react.useEffect)(() => {
|
|
3432
|
-
const { unsubscribe } = sdk.auth.onAuthStateChange((event, newSession) => {
|
|
3433
|
-
setSession(newSession);
|
|
3434
|
-
setIsLoading(false);
|
|
3435
|
-
});
|
|
3436
|
-
return () => unsubscribe();
|
|
3437
|
-
}, [sdk]);
|
|
3438
|
-
const refreshCart = async () => {
|
|
3439
|
-
if (!session.token) {
|
|
3440
|
-
setCart(null);
|
|
3441
|
-
return;
|
|
3442
|
-
}
|
|
3443
|
-
setCartLoading(true);
|
|
3444
|
-
try {
|
|
3445
|
-
const res = await sdk.cart.get();
|
|
3446
|
-
setCart(res.data?.data || res.data || null);
|
|
3447
|
-
} catch (err) {
|
|
3448
|
-
console.error("Failed to fetch cart:", err);
|
|
3449
|
-
} finally {
|
|
3450
|
-
setCartLoading(false);
|
|
3451
|
-
}
|
|
3452
|
-
};
|
|
3453
|
-
const refreshProfile = async () => {
|
|
3454
|
-
if (!session.token) {
|
|
3455
|
-
setCustomerProfile(null);
|
|
3456
|
-
setCustomerAddresses([]);
|
|
3457
|
-
return;
|
|
3458
|
-
}
|
|
3459
|
-
try {
|
|
3460
|
-
const profile = await sdk.customer.getProfile();
|
|
3461
|
-
setCustomerProfile(profile || null);
|
|
3462
|
-
const addresses = await sdk.customer.getAddresses();
|
|
3463
|
-
setCustomerAddresses(addresses?.data || addresses || []);
|
|
3464
|
-
} catch (err) {
|
|
3465
|
-
console.error("Failed to fetch customer profile or addresses:", err);
|
|
3466
|
-
}
|
|
3467
|
-
};
|
|
3468
|
-
const refreshBookings = async () => {
|
|
3469
|
-
if (!session.token) {
|
|
3470
|
-
setBookingsList([]);
|
|
3471
|
-
return;
|
|
3472
|
-
}
|
|
3473
|
-
setBookingsLoading(true);
|
|
3474
|
-
try {
|
|
3475
|
-
const res = await sdk.bookings.list();
|
|
3476
|
-
setBookingsList(res?.data || res || []);
|
|
3477
|
-
} catch (err) {
|
|
3478
|
-
console.error("Failed to fetch bookings:", err);
|
|
3479
|
-
} finally {
|
|
3480
|
-
setBookingsLoading(false);
|
|
3481
|
-
}
|
|
3482
|
-
};
|
|
3483
|
-
(0, import_react.useEffect)(() => {
|
|
3484
|
-
if (session.token) {
|
|
3485
|
-
refreshCart();
|
|
3486
|
-
refreshProfile();
|
|
3487
|
-
refreshBookings();
|
|
3488
|
-
} else {
|
|
3489
|
-
setCart(null);
|
|
3490
|
-
setCustomerProfile(null);
|
|
3491
|
-
setCustomerAddresses([]);
|
|
3492
|
-
setBookingsList([]);
|
|
3493
|
-
}
|
|
3494
|
-
}, [session.token]);
|
|
3495
|
-
const signIn = async (credentials) => {
|
|
3496
|
-
const res = await sdk.auth.signIn(credentials);
|
|
3497
|
-
return res;
|
|
3498
|
-
};
|
|
3499
|
-
const signUp = async (dto) => {
|
|
3500
|
-
const res = await sdk.auth.signUp(dto);
|
|
3501
|
-
return res;
|
|
3502
|
-
};
|
|
3503
|
-
const signOut = async () => {
|
|
3504
|
-
await sdk.auth.signOut();
|
|
3505
|
-
};
|
|
3506
|
-
const addToCart = async (dto) => {
|
|
3507
|
-
if (!session.token)
|
|
3508
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3509
|
-
await sdk.cart.add(dto);
|
|
3510
|
-
await refreshCart();
|
|
3511
|
-
};
|
|
3512
|
-
const removeFromCart = async (dto) => {
|
|
3513
|
-
if (!session.token)
|
|
3514
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3515
|
-
await sdk.cart.remove(dto);
|
|
3516
|
-
await refreshCart();
|
|
3517
|
-
};
|
|
3518
|
-
const updateCartItem = async (dto) => {
|
|
3519
|
-
if (!session.token)
|
|
3520
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3521
|
-
await sdk.cart.update(dto);
|
|
3522
|
-
await refreshCart();
|
|
3523
|
-
};
|
|
3524
|
-
const clearCart = async (params) => {
|
|
3525
|
-
if (!session.token)
|
|
3526
|
-
throw new Error("Customer must be logged in to manage cart");
|
|
3527
|
-
await sdk.cart.clear(params);
|
|
3528
|
-
await refreshCart();
|
|
3529
|
-
};
|
|
3530
|
-
const addAddress = async (dto) => {
|
|
3531
|
-
if (!session.token)
|
|
3532
|
-
throw new Error("Customer must be logged in to manage addresses");
|
|
3533
|
-
const res = await sdk.customer.addAddress(dto);
|
|
3534
|
-
await refreshProfile();
|
|
3535
|
-
return res;
|
|
3536
|
-
};
|
|
3537
|
-
const updateProfile = async (dto) => {
|
|
3538
|
-
if (!session.token)
|
|
3539
|
-
throw new Error("Customer must be logged in to update profile");
|
|
3540
|
-
const res = await sdk.customer.updateProfile(dto);
|
|
3541
|
-
await refreshProfile();
|
|
3542
|
-
return res;
|
|
3543
|
-
};
|
|
3544
|
-
const createBooking = async (dto) => {
|
|
3545
|
-
if (!session.token)
|
|
3546
|
-
throw new Error("Customer must be logged in to create bookings");
|
|
3547
|
-
const res = await sdk.bookings.create(dto);
|
|
3548
|
-
await refreshBookings();
|
|
3549
|
-
return res;
|
|
3550
|
-
};
|
|
3551
|
-
const cancelBooking = async (id) => {
|
|
3552
|
-
if (!session.token)
|
|
3553
|
-
throw new Error("Customer must be logged in to cancel bookings");
|
|
3554
|
-
const res = await sdk.bookings.cancel(id);
|
|
3555
|
-
await refreshBookings();
|
|
3556
|
-
return res;
|
|
3557
|
-
};
|
|
3558
|
-
const checkoutCart = async (params) => {
|
|
3559
|
-
if (!session.token)
|
|
3560
|
-
throw new Error("Customer must be logged in to checkout");
|
|
3561
|
-
const res = await sdk.cart.checkout(params);
|
|
3562
|
-
await refreshCart();
|
|
3563
|
-
await refreshBookings();
|
|
3564
|
-
return res;
|
|
3565
|
-
};
|
|
3566
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
3567
|
-
AuthContext.Provider,
|
|
3568
|
-
{
|
|
3569
|
-
value: {
|
|
3570
|
-
sdk,
|
|
3571
|
-
session,
|
|
3572
|
-
user: session.user,
|
|
3573
|
-
token: session.token,
|
|
3574
|
-
isLoading,
|
|
3575
|
-
signIn,
|
|
3576
|
-
signUp,
|
|
3577
|
-
signOut,
|
|
3578
|
-
cart,
|
|
3579
|
-
cartLoading,
|
|
3580
|
-
addToCart,
|
|
3581
|
-
removeFromCart,
|
|
3582
|
-
updateCartItem,
|
|
3583
|
-
clearCart,
|
|
3584
|
-
refreshCart,
|
|
3585
|
-
customerProfile,
|
|
3586
|
-
customerAddresses,
|
|
3587
|
-
bookings: bookingsList,
|
|
3588
|
-
bookingsLoading,
|
|
3589
|
-
addAddress,
|
|
3590
|
-
updateProfile,
|
|
3591
|
-
createBooking,
|
|
3592
|
-
cancelBooking,
|
|
3593
|
-
checkoutCart,
|
|
3594
|
-
refreshProfile,
|
|
3595
|
-
refreshBookings
|
|
3596
|
-
},
|
|
3597
|
-
children
|
|
3598
|
-
}
|
|
3599
|
-
);
|
|
3600
|
-
};
|
|
3601
|
-
var useScrymeAuth = () => {
|
|
3602
|
-
const context = (0, import_react.useContext)(AuthContext);
|
|
3603
|
-
if (context === void 0) {
|
|
3604
|
-
throw new Error("useScrymeAuth must be used within a ScrymeAuthProvider");
|
|
3605
|
-
}
|
|
3606
|
-
return context;
|
|
3607
|
-
};
|
|
3608
3376
|
|
|
3609
3377
|
// src/server.ts
|
|
3610
3378
|
var import_axios3 = __toESM(require("axios"));
|
|
@@ -3663,7 +3431,7 @@ var ScrymeServerSDK = class {
|
|
|
3663
3431
|
return this.activeAuthPromise;
|
|
3664
3432
|
};
|
|
3665
3433
|
this.axiosInstance.interceptors.request.use(async (req) => {
|
|
3666
|
-
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh")
|
|
3434
|
+
const isAuthTokenRequest = req.url && (req.url.endsWith("/auth/token") || req.url.includes("/auth/token") || req.url.includes("/customers/auth/refresh"));
|
|
3667
3435
|
if (!isAuthTokenRequest && !config.apiKey) {
|
|
3668
3436
|
const isExpired = !this.token || this.expiresAt && Date.now() >= this.expiresAt - 3e4;
|
|
3669
3437
|
if (isExpired) {
|
|
@@ -3698,7 +3466,7 @@ var ScrymeServerSDK = class {
|
|
|
3698
3466
|
(response) => response,
|
|
3699
3467
|
async (error) => {
|
|
3700
3468
|
const originalRequest = error.config;
|
|
3701
|
-
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh")
|
|
3469
|
+
const isAuthTokenRequest = originalRequest && originalRequest.url && (originalRequest.url.endsWith("/auth/token") || originalRequest.url.includes("/auth/token") || originalRequest.url.includes("/customers/auth/refresh"));
|
|
3702
3470
|
if (error.response && error.response.status === 401 && originalRequest && !originalRequest._retry && !isAuthTokenRequest && !config.apiKey) {
|
|
3703
3471
|
originalRequest._retry = true;
|
|
3704
3472
|
try {
|
|
@@ -3724,7 +3492,54 @@ var ScrymeServerSDK = class {
|
|
|
3724
3492
|
}
|
|
3725
3493
|
);
|
|
3726
3494
|
this.api = getScrymeV3API2(this.axiosInstance, config.orgSlug);
|
|
3727
|
-
|
|
3495
|
+
const baseCatalog = buildModule(this.api, config.orgSlug, catalogMapping);
|
|
3496
|
+
this.catalog = {
|
|
3497
|
+
...baseCatalog,
|
|
3498
|
+
getProduct: async (idOrSlug, options) => {
|
|
3499
|
+
const response = await this.catalog.getProducts(void 0, options);
|
|
3500
|
+
const products = response.data || [];
|
|
3501
|
+
const product = products.find((p) => {
|
|
3502
|
+
if (typeof idOrSlug === "string") {
|
|
3503
|
+
return p.id === idOrSlug || p.slug === idOrSlug;
|
|
3504
|
+
} else {
|
|
3505
|
+
const { id, slug } = idOrSlug;
|
|
3506
|
+
if (id && p.id === id) return true;
|
|
3507
|
+
if (slug && p.slug === slug) return true;
|
|
3508
|
+
return false;
|
|
3509
|
+
}
|
|
3510
|
+
});
|
|
3511
|
+
if (!product) {
|
|
3512
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
3513
|
+
throw new Error(`Product not found matching criteria: ${criteria}`);
|
|
3514
|
+
}
|
|
3515
|
+
return {
|
|
3516
|
+
...response,
|
|
3517
|
+
data: product
|
|
3518
|
+
};
|
|
3519
|
+
},
|
|
3520
|
+
getService: async (idOrSlug, options) => {
|
|
3521
|
+
const response = await this.catalog.getServices(void 0, options);
|
|
3522
|
+
const services = response.data || [];
|
|
3523
|
+
const service = services.find((s) => {
|
|
3524
|
+
if (typeof idOrSlug === "string") {
|
|
3525
|
+
return s.id === idOrSlug || s.slug === idOrSlug;
|
|
3526
|
+
} else {
|
|
3527
|
+
const { id, slug } = idOrSlug;
|
|
3528
|
+
if (id && s.id === id) return true;
|
|
3529
|
+
if (slug && s.slug === slug) return true;
|
|
3530
|
+
return false;
|
|
3531
|
+
}
|
|
3532
|
+
});
|
|
3533
|
+
if (!service) {
|
|
3534
|
+
const criteria = typeof idOrSlug === "string" ? idOrSlug : JSON.stringify(idOrSlug);
|
|
3535
|
+
throw new Error(`Service not found matching criteria: ${criteria}`);
|
|
3536
|
+
}
|
|
3537
|
+
return {
|
|
3538
|
+
...response,
|
|
3539
|
+
data: service
|
|
3540
|
+
};
|
|
3541
|
+
}
|
|
3542
|
+
};
|
|
3728
3543
|
this.inventory = buildModule(this.api, config.orgSlug, inventoryMapping);
|
|
3729
3544
|
this.orders = buildModule(this.api, config.orgSlug, ordersMapping);
|
|
3730
3545
|
this.crm = buildModule(this.api, config.orgSlug, crmMapping);
|
|
@@ -3736,7 +3551,9 @@ var ScrymeServerSDK = class {
|
|
|
3736
3551
|
this.services = buildModule(this.api, config.orgSlug, servicesMapping);
|
|
3737
3552
|
this.cart = {
|
|
3738
3553
|
get: async (params) => {
|
|
3739
|
-
return this.orders.getCart(
|
|
3554
|
+
return this.orders.getCart(
|
|
3555
|
+
params
|
|
3556
|
+
);
|
|
3740
3557
|
},
|
|
3741
3558
|
add: async (dto) => {
|
|
3742
3559
|
return this.orders.addToCart(dto);
|
|
@@ -3745,11 +3562,11 @@ var ScrymeServerSDK = class {
|
|
|
3745
3562
|
return this.orders.removeFromCart(dto);
|
|
3746
3563
|
},
|
|
3747
3564
|
clear: async (params) => {
|
|
3748
|
-
return this.orders.clearCart(params
|
|
3565
|
+
return this.orders.clearCart(params);
|
|
3749
3566
|
},
|
|
3750
3567
|
update: async (dto) => {
|
|
3751
3568
|
const response = await this.orders.getCart({
|
|
3752
|
-
sessionId: dto.sessionId
|
|
3569
|
+
sessionId: dto.sessionId || ""
|
|
3753
3570
|
});
|
|
3754
3571
|
const data = response.data;
|
|
3755
3572
|
const items = data?.data?.items || data?.items || [];
|
|
@@ -3770,7 +3587,7 @@ var ScrymeServerSDK = class {
|
|
|
3770
3587
|
productId: dto.productId,
|
|
3771
3588
|
variantId: dto.variantId,
|
|
3772
3589
|
serviceId: dto.serviceId,
|
|
3773
|
-
sessionId: dto.sessionId,
|
|
3590
|
+
sessionId: dto.sessionId || "",
|
|
3774
3591
|
customerId: dto.customerId
|
|
3775
3592
|
});
|
|
3776
3593
|
} else {
|
|
@@ -3790,12 +3607,16 @@ var ScrymeServerSDK = class {
|
|
|
3790
3607
|
}
|
|
3791
3608
|
},
|
|
3792
3609
|
getItems: async (params) => {
|
|
3793
|
-
const res = await this.orders.getCart(
|
|
3610
|
+
const res = await this.orders.getCart(
|
|
3611
|
+
params
|
|
3612
|
+
);
|
|
3794
3613
|
const data = res?.data || res;
|
|
3795
3614
|
return data?.items || data?.data?.items || [];
|
|
3796
3615
|
},
|
|
3797
3616
|
getTotals: async (params) => {
|
|
3798
|
-
const res = await this.orders.getCart(
|
|
3617
|
+
const res = await this.orders.getCart(
|
|
3618
|
+
params
|
|
3619
|
+
);
|
|
3799
3620
|
const data = res?.data || res;
|
|
3800
3621
|
const items = data?.items || data?.data?.items || [];
|
|
3801
3622
|
const itemsCount = items.reduce(
|
|
@@ -3849,6 +3670,61 @@ var ScrymeServerSDK = class {
|
|
|
3849
3670
|
},
|
|
3850
3671
|
addAddress: async (customerId, dto) => {
|
|
3851
3672
|
return this.admin.addCustomerAddress(customerId, dto);
|
|
3673
|
+
},
|
|
3674
|
+
auth: {
|
|
3675
|
+
signUp: async (dto) => {
|
|
3676
|
+
return this.api.customersRegister(config.orgSlug, dto);
|
|
3677
|
+
},
|
|
3678
|
+
signIn: async (credentials) => {
|
|
3679
|
+
const response = await this.axiosInstance.post(
|
|
3680
|
+
"/auth/sign-in/email",
|
|
3681
|
+
credentials
|
|
3682
|
+
);
|
|
3683
|
+
const data = response.data;
|
|
3684
|
+
const token = data?.session?.token || data?.token || null;
|
|
3685
|
+
if (token) {
|
|
3686
|
+
this.token = token;
|
|
3687
|
+
this.expiresAt = getJwtExpiry(token);
|
|
3688
|
+
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3689
|
+
}
|
|
3690
|
+
return data;
|
|
3691
|
+
},
|
|
3692
|
+
getCurrentSession: async (headers) => {
|
|
3693
|
+
const requestConfig = {};
|
|
3694
|
+
if (headers) {
|
|
3695
|
+
const requestHeaders = {};
|
|
3696
|
+
if (typeof headers.forEach === "function") {
|
|
3697
|
+
headers.forEach((value, key) => {
|
|
3698
|
+
requestHeaders[key] = value;
|
|
3699
|
+
});
|
|
3700
|
+
} else {
|
|
3701
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
3702
|
+
if (value !== void 0) {
|
|
3703
|
+
requestHeaders[key] = Array.isArray(value) ? value.join(", ") : String(value);
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
}
|
|
3707
|
+
requestConfig.headers = requestHeaders;
|
|
3708
|
+
}
|
|
3709
|
+
const response = await this.axiosInstance.get(
|
|
3710
|
+
`/${config.orgSlug}/customers/auth/session`,
|
|
3711
|
+
requestConfig
|
|
3712
|
+
);
|
|
3713
|
+
return response.data?.data || response.data;
|
|
3714
|
+
},
|
|
3715
|
+
refreshSession: async () => {
|
|
3716
|
+
const response = await this.axiosInstance.post(
|
|
3717
|
+
`/${config.orgSlug}/customers/auth/refresh`
|
|
3718
|
+
);
|
|
3719
|
+
const data = response.data?.data || response.data;
|
|
3720
|
+
const token = data?.token || null;
|
|
3721
|
+
if (token) {
|
|
3722
|
+
this.token = token;
|
|
3723
|
+
this.expiresAt = getJwtExpiry(token);
|
|
3724
|
+
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3725
|
+
}
|
|
3726
|
+
return data;
|
|
3727
|
+
}
|
|
3852
3728
|
}
|
|
3853
3729
|
};
|
|
3854
3730
|
this.bookings = {
|
|
@@ -3871,58 +3747,21 @@ var ScrymeServerSDK = class {
|
|
|
3871
3747
|
const baseAuth = buildModule(this.api, config.orgSlug, authMapping);
|
|
3872
3748
|
this.auth = {
|
|
3873
3749
|
...baseAuth,
|
|
3874
|
-
|
|
3875
|
-
return this.api.customersRegister(config.orgSlug, dto);
|
|
3876
|
-
},
|
|
3750
|
+
...this.customer.auth,
|
|
3877
3751
|
authenticate: async () => {
|
|
3878
3752
|
return performExchange();
|
|
3879
3753
|
},
|
|
3754
|
+
signUp: async (dto) => {
|
|
3755
|
+
return this.customer.auth.signUp(dto);
|
|
3756
|
+
},
|
|
3880
3757
|
signIn: async (credentials) => {
|
|
3881
|
-
|
|
3882
|
-
"/auth/sign-in/email",
|
|
3883
|
-
credentials
|
|
3884
|
-
);
|
|
3885
|
-
const data = response.data;
|
|
3886
|
-
const token = data?.session?.token || data?.token || null;
|
|
3887
|
-
if (token) {
|
|
3888
|
-
this.token = token;
|
|
3889
|
-
this.expiresAt = getJwtExpiry(token);
|
|
3890
|
-
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3891
|
-
}
|
|
3892
|
-
return data;
|
|
3758
|
+
return this.customer.auth.signIn(credentials);
|
|
3893
3759
|
},
|
|
3894
|
-
getCurrentSession: async () => {
|
|
3895
|
-
|
|
3896
|
-
`/${config.orgSlug}/customers/auth/session`
|
|
3897
|
-
);
|
|
3898
|
-
return response.data?.data || response.data;
|
|
3760
|
+
getCurrentSession: async (headers) => {
|
|
3761
|
+
return this.customer.auth.getCurrentSession(headers);
|
|
3899
3762
|
},
|
|
3900
3763
|
refreshSession: async () => {
|
|
3901
|
-
|
|
3902
|
-
`/${config.orgSlug}/customers/auth/refresh`
|
|
3903
|
-
);
|
|
3904
|
-
const data = response.data?.data || response.data;
|
|
3905
|
-
const token = data?.token || null;
|
|
3906
|
-
if (token) {
|
|
3907
|
-
this.token = token;
|
|
3908
|
-
this.expiresAt = getJwtExpiry(token);
|
|
3909
|
-
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3910
|
-
}
|
|
3911
|
-
return data;
|
|
3912
|
-
},
|
|
3913
|
-
swapZitadel: async (zitadelToken) => {
|
|
3914
|
-
const response = await this.axiosInstance.post(
|
|
3915
|
-
`/${config.orgSlug}/customers/auth/swap-zitadel`,
|
|
3916
|
-
{ zitadelToken }
|
|
3917
|
-
);
|
|
3918
|
-
const data = response.data?.data || response.data;
|
|
3919
|
-
const token = data?.token || null;
|
|
3920
|
-
if (token) {
|
|
3921
|
-
this.token = token;
|
|
3922
|
-
this.expiresAt = getJwtExpiry(token);
|
|
3923
|
-
this.axiosInstance.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
3924
|
-
}
|
|
3925
|
-
return data;
|
|
3764
|
+
return this.customer.auth.refreshSession();
|
|
3926
3765
|
}
|
|
3927
3766
|
};
|
|
3928
3767
|
}
|
|
@@ -4038,7 +3877,6 @@ var getScrymeV3API2 = (axiosInstance, defaultOrgSlug) => {
|
|
|
4038
3877
|
RegisterPettyCashDtoPaymentMethod,
|
|
4039
3878
|
ReviewPriceChangeDtoStatus,
|
|
4040
3879
|
RoleManagementControllerGetCustomRolesSortOrder,
|
|
4041
|
-
ScrymeAuthProvider,
|
|
4042
3880
|
ScrymeClientSDK,
|
|
4043
3881
|
ScrymeServerSDK,
|
|
4044
3882
|
ServicesUpdateBookingStatusBodyStatus,
|
|
@@ -4071,6 +3909,5 @@ var getScrymeV3API2 = (axiosInstance, defaultOrgSlug) => {
|
|
|
4071
3909
|
ordersMapping,
|
|
4072
3910
|
posMapping,
|
|
4073
3911
|
publicServicesMapping,
|
|
4074
|
-
servicesMapping
|
|
4075
|
-
useScrymeAuth
|
|
3912
|
+
servicesMapping
|
|
4076
3913
|
});
|