omni-sync-sdk 0.2.0 → 0.3.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/dist/index.mjs CHANGED
@@ -10,18 +10,86 @@ var DEFAULT_BASE_URL = "https://api.omni-sync.com";
10
10
  var DEFAULT_TIMEOUT = 3e4;
11
11
  var OmniSyncClient = class {
12
12
  constructor(options) {
13
- if (!options.apiKey) {
14
- throw new Error("OmniSyncClient: apiKey is required");
13
+ this.customerToken = null;
14
+ if (!options.apiKey && !options.storeId && !options.connectionId) {
15
+ throw new Error("OmniSyncClient: either connectionId, apiKey, or storeId is required");
15
16
  }
16
- if (!options.apiKey.startsWith("omni_")) {
17
+ if (options.apiKey && !options.apiKey.startsWith("omni_")) {
17
18
  console.warn('OmniSyncClient: apiKey should start with "omni_"');
18
19
  }
20
+ if (options.connectionId && !options.connectionId.startsWith("vc_")) {
21
+ console.warn('OmniSyncClient: connectionId should start with "vc_"');
22
+ }
23
+ if (options.apiKey && typeof window !== "undefined") {
24
+ console.warn(
25
+ "OmniSyncClient: WARNING - API key detected in browser environment. This is a security risk! Use connectionId or storeId for frontend applications."
26
+ );
27
+ }
19
28
  this.apiKey = options.apiKey;
29
+ this.storeId = options.storeId;
30
+ this.connectionId = options.connectionId;
20
31
  this.baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
21
32
  this.timeout = options.timeout || DEFAULT_TIMEOUT;
22
33
  }
34
+ // -------------------- Mode Detection --------------------
35
+ /**
36
+ * Check if client is in vibe-coded mode (using connectionId)
37
+ */
38
+ isVibeCodedMode() {
39
+ return !!this.connectionId && !this.apiKey;
40
+ }
41
+ /**
42
+ * Check if client is in storefront mode (using storeId)
43
+ */
44
+ isStorefrontMode() {
45
+ return !!this.storeId && !this.apiKey && !this.connectionId;
46
+ }
47
+ /**
48
+ * Check if client is in admin mode (using apiKey)
49
+ */
50
+ isAdminMode() {
51
+ return !!this.apiKey;
52
+ }
53
+ // -------------------- Customer Token Management --------------------
54
+ /**
55
+ * Set the customer authentication token (obtained from login/register).
56
+ * Required for accessing customer-specific data in storefront mode.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const auth = await omni.loginCustomer('user@example.com', 'password');
61
+ * omni.setCustomerToken(auth.token);
62
+ *
63
+ * // Now can access customer data
64
+ * const profile = await omni.getMyProfile();
65
+ * ```
66
+ */
67
+ setCustomerToken(token) {
68
+ this.customerToken = token;
69
+ }
70
+ /**
71
+ * Get the current customer token
72
+ */
73
+ getCustomerToken() {
74
+ return this.customerToken;
75
+ }
76
+ /**
77
+ * Clear the customer token (logout)
78
+ */
79
+ clearCustomerToken() {
80
+ this.customerToken = null;
81
+ }
23
82
  // -------------------- Private Methods --------------------
24
- async request(method, path, body, queryParams) {
83
+ /**
84
+ * Make a request to the Admin API (requires apiKey)
85
+ */
86
+ async adminRequest(method, path, body, queryParams) {
87
+ if (!this.apiKey) {
88
+ throw new OmniSyncError(
89
+ "This operation requires an API key. Initialize with apiKey instead of storeId.",
90
+ 403
91
+ );
92
+ }
25
93
  const url = new URL(`${this.baseUrl}${path}`);
26
94
  if (queryParams) {
27
95
  Object.entries(queryParams).forEach(([key, value]) => {
@@ -38,7 +106,7 @@ var OmniSyncClient = class {
38
106
  headers: {
39
107
  Authorization: `Bearer ${this.apiKey}`,
40
108
  "Content-Type": "application/json",
41
- "X-SDK-Version": "0.1.1",
109
+ "X-SDK-Version": "0.3.0",
42
110
  "ngrok-skip-browser-warning": "true"
43
111
  },
44
112
  body: body ? JSON.stringify(body) : void 0,
@@ -70,12 +138,149 @@ var OmniSyncClient = class {
70
138
  throw new OmniSyncError("Unknown error occurred", 0);
71
139
  }
72
140
  }
141
+ /**
142
+ * Make a request to the Vibe-Coded API (public, uses connectionId)
143
+ */
144
+ async vibeCodedRequest(method, path, body, queryParams) {
145
+ if (!this.connectionId) {
146
+ throw new OmniSyncError("connectionId is required for vibe-coded requests", 400);
147
+ }
148
+ const url = new URL(`${this.baseUrl}/api/vc/${this.connectionId}${path}`);
149
+ if (queryParams) {
150
+ Object.entries(queryParams).forEach(([key, value]) => {
151
+ if (value !== void 0) {
152
+ url.searchParams.set(key, String(value));
153
+ }
154
+ });
155
+ }
156
+ const controller = new AbortController();
157
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
158
+ try {
159
+ const headers = {
160
+ "Content-Type": "application/json",
161
+ "X-SDK-Version": "0.3.0",
162
+ "ngrok-skip-browser-warning": "true"
163
+ };
164
+ const response = await fetch(url.toString(), {
165
+ method,
166
+ headers,
167
+ body: body ? JSON.stringify(body) : void 0,
168
+ signal: controller.signal
169
+ });
170
+ clearTimeout(timeoutId);
171
+ if (!response.ok) {
172
+ const errorData = await response.json().catch(() => ({}));
173
+ throw new OmniSyncError(
174
+ errorData.message || `Request failed with status ${response.status}`,
175
+ response.status,
176
+ errorData
177
+ );
178
+ }
179
+ const text = await response.text();
180
+ if (!text) return {};
181
+ return JSON.parse(text);
182
+ } catch (error) {
183
+ clearTimeout(timeoutId);
184
+ if (error instanceof OmniSyncError) {
185
+ throw error;
186
+ }
187
+ if (error instanceof Error) {
188
+ if (error.name === "AbortError") {
189
+ throw new OmniSyncError("Request timeout", 408);
190
+ }
191
+ throw new OmniSyncError(error.message, 0);
192
+ }
193
+ throw new OmniSyncError("Unknown error occurred", 0);
194
+ }
195
+ }
196
+ /**
197
+ * Make a request to the Storefront API (public, uses storeId)
198
+ */
199
+ async storefrontRequest(method, path, body, queryParams) {
200
+ if (!this.storeId) {
201
+ throw new OmniSyncError("storeId is required for storefront requests", 400);
202
+ }
203
+ const url = new URL(`${this.baseUrl}/stores/${this.storeId}${path}`);
204
+ if (queryParams) {
205
+ Object.entries(queryParams).forEach(([key, value]) => {
206
+ if (value !== void 0) {
207
+ url.searchParams.set(key, String(value));
208
+ }
209
+ });
210
+ }
211
+ const controller = new AbortController();
212
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
213
+ try {
214
+ const headers = {
215
+ "Content-Type": "application/json",
216
+ "X-SDK-Version": "0.3.0",
217
+ "ngrok-skip-browser-warning": "true"
218
+ };
219
+ if (this.customerToken) {
220
+ headers["Authorization"] = `Bearer ${this.customerToken}`;
221
+ }
222
+ const response = await fetch(url.toString(), {
223
+ method,
224
+ headers,
225
+ body: body ? JSON.stringify(body) : void 0,
226
+ signal: controller.signal
227
+ });
228
+ clearTimeout(timeoutId);
229
+ if (!response.ok) {
230
+ const errorData = await response.json().catch(() => ({}));
231
+ throw new OmniSyncError(
232
+ errorData.message || `Request failed with status ${response.status}`,
233
+ response.status,
234
+ errorData
235
+ );
236
+ }
237
+ const text = await response.text();
238
+ if (!text) return {};
239
+ return JSON.parse(text);
240
+ } catch (error) {
241
+ clearTimeout(timeoutId);
242
+ if (error instanceof OmniSyncError) {
243
+ throw error;
244
+ }
245
+ if (error instanceof Error) {
246
+ if (error.name === "AbortError") {
247
+ throw new OmniSyncError("Request timeout", 408);
248
+ }
249
+ throw new OmniSyncError(error.message, 0);
250
+ }
251
+ throw new OmniSyncError("Unknown error occurred", 0);
252
+ }
253
+ }
254
+ /**
255
+ * Smart request - uses storefront or admin API based on client mode
256
+ */
257
+ async request(method, path, body, queryParams) {
258
+ if (this.apiKey) {
259
+ return this.adminRequest(method, path, body, queryParams);
260
+ }
261
+ return this.storefrontRequest(method, path, body, queryParams);
262
+ }
263
+ // -------------------- Store Info --------------------
264
+ /**
265
+ * Get store information
266
+ * Works in vibe-coded, storefront, and admin mode
267
+ */
268
+ async getStoreInfo() {
269
+ if (this.isVibeCodedMode()) {
270
+ return this.vibeCodedRequest("GET", "/info");
271
+ }
272
+ if (this.storeId && !this.apiKey) {
273
+ return this.storefrontRequest("GET", "/info");
274
+ }
275
+ return this.adminRequest("GET", "/api/v1/store");
276
+ }
73
277
  // -------------------- Products --------------------
74
278
  /**
75
279
  * Get a list of products with pagination
280
+ * Works in vibe-coded, storefront (public), and admin mode
76
281
  */
77
282
  async getProducts(params) {
78
- return this.request("GET", "/api/v1/products", void 0, {
283
+ const queryParams = {
79
284
  page: params?.page,
80
285
  limit: params?.limit,
81
286
  search: params?.search,
@@ -83,13 +288,42 @@ var OmniSyncClient = class {
83
288
  type: params?.type,
84
289
  sortBy: params?.sortBy,
85
290
  sortOrder: params?.sortOrder
86
- });
291
+ };
292
+ if (this.isVibeCodedMode()) {
293
+ return this.vibeCodedRequest(
294
+ "GET",
295
+ "/products",
296
+ void 0,
297
+ queryParams
298
+ );
299
+ }
300
+ if (this.storeId && !this.apiKey) {
301
+ return this.storefrontRequest(
302
+ "GET",
303
+ "/products",
304
+ void 0,
305
+ queryParams
306
+ );
307
+ }
308
+ return this.adminRequest(
309
+ "GET",
310
+ "/api/v1/products",
311
+ void 0,
312
+ queryParams
313
+ );
87
314
  }
88
315
  /**
89
316
  * Get a single product by ID
317
+ * Works in vibe-coded, storefront (public), and admin mode
90
318
  */
91
319
  async getProduct(productId) {
92
- return this.request("GET", `/api/v1/products/${productId}`);
320
+ if (this.isVibeCodedMode()) {
321
+ return this.vibeCodedRequest("GET", `/products/${productId}`);
322
+ }
323
+ if (this.storeId && !this.apiKey) {
324
+ return this.storefrontRequest("GET", `/products/${productId}`);
325
+ }
326
+ return this.adminRequest("GET", `/api/v1/products/${productId}`);
93
327
  }
94
328
  /**
95
329
  * Create a new product
@@ -579,13 +813,6 @@ var OmniSyncClient = class {
579
813
  async getSyncStatus(jobId) {
580
814
  return this.request("GET", `/api/v1/sync/${jobId}`);
581
815
  }
582
- // -------------------- Store Info --------------------
583
- /**
584
- * Get information about the connected store
585
- */
586
- async getStoreInfo() {
587
- return this.request("GET", "/api/v1/store");
588
- }
589
816
  // -------------------- Coupons --------------------
590
817
  /**
591
818
  * Get a list of coupons with pagination
@@ -728,7 +955,13 @@ var OmniSyncClient = class {
728
955
  * ```
729
956
  */
730
957
  async loginCustomer(email, password) {
731
- return this.request("POST", "/api/v1/customers/login", {
958
+ if (this.storeId && !this.apiKey) {
959
+ return this.storefrontRequest("POST", "/customers/login", {
960
+ email,
961
+ password
962
+ });
963
+ }
964
+ return this.adminRequest("POST", "/api/v1/customers/login", {
732
965
  email,
733
966
  password
734
967
  });
@@ -747,13 +980,21 @@ var OmniSyncClient = class {
747
980
  * ```
748
981
  */
749
982
  async registerCustomer(data) {
750
- return this.request("POST", "/api/v1/customers/register", data);
983
+ if (this.storeId && !this.apiKey) {
984
+ return this.storefrontRequest("POST", "/customers/register", data);
985
+ }
986
+ return this.adminRequest("POST", "/api/v1/customers/register", data);
751
987
  }
752
988
  /**
753
989
  * Request a password reset email for a customer
754
990
  */
755
991
  async forgotPassword(email) {
756
- return this.request("POST", "/api/v1/customers/forgot-password", {
992
+ if (this.storeId && !this.apiKey) {
993
+ return this.storefrontRequest("POST", "/customers/forgot-password", {
994
+ email
995
+ });
996
+ }
997
+ return this.adminRequest("POST", "/api/v1/customers/forgot-password", {
757
998
  email
758
999
  });
759
1000
  }
@@ -833,7 +1074,10 @@ var OmniSyncClient = class {
833
1074
  * ```
834
1075
  */
835
1076
  async createCart() {
836
- return this.request("POST", "/api/v1/cart");
1077
+ if (this.storeId && !this.apiKey) {
1078
+ return this.storefrontRequest("POST", "/cart");
1079
+ }
1080
+ return this.adminRequest("POST", "/api/v1/cart");
837
1081
  }
838
1082
  /**
839
1083
  * Get a cart by session token (for guest users)
@@ -845,7 +1089,10 @@ var OmniSyncClient = class {
845
1089
  * ```
846
1090
  */
847
1091
  async getCartBySession(sessionToken) {
848
- return this.request("GET", `/api/v1/cart/session/${sessionToken}`);
1092
+ if (this.storeId && !this.apiKey) {
1093
+ return this.storefrontRequest("GET", `/cart/session/${sessionToken}`);
1094
+ }
1095
+ return this.adminRequest("GET", `/api/v1/cart/session/${sessionToken}`);
849
1096
  }
850
1097
  /**
851
1098
  * Get a cart by customer ID (for authenticated users)
@@ -857,13 +1104,19 @@ var OmniSyncClient = class {
857
1104
  * ```
858
1105
  */
859
1106
  async getCartByCustomer(customerId) {
860
- return this.request("GET", `/api/v1/cart/customer/${customerId}`);
1107
+ if (this.storeId && !this.apiKey) {
1108
+ return this.storefrontRequest("GET", `/cart/customer/${customerId}`);
1109
+ }
1110
+ return this.adminRequest("GET", `/api/v1/cart/customer/${customerId}`);
861
1111
  }
862
1112
  /**
863
1113
  * Get a cart by ID
864
1114
  */
865
1115
  async getCart(cartId) {
866
- return this.request("GET", `/api/v1/cart/${cartId}`);
1116
+ if (this.storeId && !this.apiKey) {
1117
+ return this.storefrontRequest("GET", `/cart/${cartId}`);
1118
+ }
1119
+ return this.adminRequest("GET", `/api/v1/cart/${cartId}`);
867
1120
  }
868
1121
  /**
869
1122
  * Add an item to the cart
@@ -878,7 +1131,10 @@ var OmniSyncClient = class {
878
1131
  * ```
879
1132
  */
880
1133
  async addToCart(cartId, item) {
881
- return this.request("POST", `/api/v1/cart/${cartId}/items`, item);
1134
+ if (this.storeId && !this.apiKey) {
1135
+ return this.storefrontRequest("POST", `/cart/${cartId}/items`, item);
1136
+ }
1137
+ return this.adminRequest("POST", `/api/v1/cart/${cartId}/items`, item);
882
1138
  }
883
1139
  /**
884
1140
  * Update an item quantity in the cart
@@ -889,7 +1145,10 @@ var OmniSyncClient = class {
889
1145
  * ```
890
1146
  */
891
1147
  async updateCartItem(cartId, itemId, data) {
892
- return this.request("PATCH", `/api/v1/cart/${cartId}/items/${itemId}`, data);
1148
+ if (this.storeId && !this.apiKey) {
1149
+ return this.storefrontRequest("PATCH", `/cart/${cartId}/items/${itemId}`, data);
1150
+ }
1151
+ return this.adminRequest("PATCH", `/api/v1/cart/${cartId}/items/${itemId}`, data);
893
1152
  }
894
1153
  /**
895
1154
  * Remove an item from the cart
@@ -900,7 +1159,10 @@ var OmniSyncClient = class {
900
1159
  * ```
901
1160
  */
902
1161
  async removeCartItem(cartId, itemId) {
903
- return this.request("DELETE", `/api/v1/cart/${cartId}/items/${itemId}`);
1162
+ if (this.storeId && !this.apiKey) {
1163
+ return this.storefrontRequest("DELETE", `/cart/${cartId}/items/${itemId}`);
1164
+ }
1165
+ return this.adminRequest("DELETE", `/api/v1/cart/${cartId}/items/${itemId}`);
904
1166
  }
905
1167
  /**
906
1168
  * Clear all items from the cart
@@ -911,7 +1173,11 @@ var OmniSyncClient = class {
911
1173
  * ```
912
1174
  */
913
1175
  async clearCart(cartId) {
914
- await this.request("DELETE", `/api/v1/cart/${cartId}/items`);
1176
+ if (this.storeId && !this.apiKey) {
1177
+ await this.storefrontRequest("DELETE", `/cart/${cartId}/items`);
1178
+ return;
1179
+ }
1180
+ await this.adminRequest("DELETE", `/api/v1/cart/${cartId}/items`);
915
1181
  }
916
1182
  /**
917
1183
  * Apply a coupon to the cart
@@ -923,7 +1189,10 @@ var OmniSyncClient = class {
923
1189
  * ```
924
1190
  */
925
1191
  async applyCoupon(cartId, code) {
926
- return this.request("POST", `/api/v1/cart/${cartId}/coupon`, { code });
1192
+ if (this.storeId && !this.apiKey) {
1193
+ return this.storefrontRequest("POST", `/cart/${cartId}/coupon`, { code });
1194
+ }
1195
+ return this.adminRequest("POST", `/api/v1/cart/${cartId}/coupon`, { code });
927
1196
  }
928
1197
  /**
929
1198
  * Remove a coupon from the cart
@@ -934,7 +1203,10 @@ var OmniSyncClient = class {
934
1203
  * ```
935
1204
  */
936
1205
  async removeCoupon(cartId) {
937
- return this.request("DELETE", `/api/v1/cart/${cartId}/coupon`);
1206
+ if (this.storeId && !this.apiKey) {
1207
+ return this.storefrontRequest("DELETE", `/cart/${cartId}/coupon`);
1208
+ }
1209
+ return this.adminRequest("DELETE", `/api/v1/cart/${cartId}/coupon`);
938
1210
  }
939
1211
  /**
940
1212
  * Merge a guest cart into a customer's cart (after login)
@@ -950,7 +1222,10 @@ var OmniSyncClient = class {
950
1222
  * ```
951
1223
  */
952
1224
  async mergeCarts(data) {
953
- return this.request("POST", "/api/v1/cart/merge", data);
1225
+ if (this.storeId && !this.apiKey) {
1226
+ return this.storefrontRequest("POST", "/cart/merge", data);
1227
+ }
1228
+ return this.adminRequest("POST", "/api/v1/cart/merge", data);
954
1229
  }
955
1230
  // -------------------- Checkout --------------------
956
1231
  /**
@@ -964,7 +1239,10 @@ var OmniSyncClient = class {
964
1239
  * ```
965
1240
  */
966
1241
  async createCheckout(data) {
967
- return this.request("POST", "/api/v1/checkout", data);
1242
+ if (this.storeId && !this.apiKey) {
1243
+ return this.storefrontRequest("POST", "/checkout", data);
1244
+ }
1245
+ return this.adminRequest("POST", "/api/v1/checkout", data);
968
1246
  }
969
1247
  /**
970
1248
  * Get a checkout by ID
@@ -976,7 +1254,10 @@ var OmniSyncClient = class {
976
1254
  * ```
977
1255
  */
978
1256
  async getCheckout(checkoutId) {
979
- return this.request("GET", `/api/v1/checkout/${checkoutId}`);
1257
+ if (this.storeId && !this.apiKey) {
1258
+ return this.storefrontRequest("GET", `/checkout/${checkoutId}`);
1259
+ }
1260
+ return this.adminRequest("GET", `/api/v1/checkout/${checkoutId}`);
980
1261
  }
981
1262
  /**
982
1263
  * Set customer information on checkout
@@ -991,7 +1272,10 @@ var OmniSyncClient = class {
991
1272
  * ```
992
1273
  */
993
1274
  async setCheckoutCustomer(checkoutId, data) {
994
- return this.request("PATCH", `/api/v1/checkout/${checkoutId}/customer`, data);
1275
+ if (this.storeId && !this.apiKey) {
1276
+ return this.storefrontRequest("PATCH", `/checkout/${checkoutId}/customer`, data);
1277
+ }
1278
+ return this.adminRequest("PATCH", `/api/v1/checkout/${checkoutId}/customer`, data);
995
1279
  }
996
1280
  /**
997
1281
  * Set shipping address on checkout
@@ -1012,7 +1296,14 @@ var OmniSyncClient = class {
1012
1296
  * ```
1013
1297
  */
1014
1298
  async setShippingAddress(checkoutId, address) {
1015
- return this.request(
1299
+ if (this.storeId && !this.apiKey) {
1300
+ return this.storefrontRequest(
1301
+ "PATCH",
1302
+ `/checkout/${checkoutId}/shipping-address`,
1303
+ address
1304
+ );
1305
+ }
1306
+ return this.adminRequest(
1016
1307
  "PATCH",
1017
1308
  `/api/v1/checkout/${checkoutId}/shipping-address`,
1018
1309
  address
@@ -1029,7 +1320,16 @@ var OmniSyncClient = class {
1029
1320
  * ```
1030
1321
  */
1031
1322
  async getShippingRates(checkoutId) {
1032
- return this.request("GET", `/api/v1/checkout/${checkoutId}/shipping-rates`);
1323
+ if (this.storeId && !this.apiKey) {
1324
+ return this.storefrontRequest(
1325
+ "GET",
1326
+ `/checkout/${checkoutId}/shipping-rates`
1327
+ );
1328
+ }
1329
+ return this.adminRequest(
1330
+ "GET",
1331
+ `/api/v1/checkout/${checkoutId}/shipping-rates`
1332
+ );
1033
1333
  }
1034
1334
  /**
1035
1335
  * Select a shipping method for checkout
@@ -1041,7 +1341,12 @@ var OmniSyncClient = class {
1041
1341
  * ```
1042
1342
  */
1043
1343
  async selectShippingMethod(checkoutId, shippingRateId) {
1044
- return this.request("PATCH", `/api/v1/checkout/${checkoutId}/shipping-method`, {
1344
+ if (this.storeId && !this.apiKey) {
1345
+ return this.storefrontRequest("PATCH", `/checkout/${checkoutId}/shipping-method`, {
1346
+ shippingRateId
1347
+ });
1348
+ }
1349
+ return this.adminRequest("PATCH", `/api/v1/checkout/${checkoutId}/shipping-method`, {
1045
1350
  shippingRateId
1046
1351
  });
1047
1352
  }
@@ -1070,7 +1375,14 @@ var OmniSyncClient = class {
1070
1375
  * ```
1071
1376
  */
1072
1377
  async setBillingAddress(checkoutId, address) {
1073
- return this.request(
1378
+ if (this.storeId && !this.apiKey) {
1379
+ return this.storefrontRequest(
1380
+ "PATCH",
1381
+ `/checkout/${checkoutId}/billing-address`,
1382
+ address
1383
+ );
1384
+ }
1385
+ return this.adminRequest(
1074
1386
  "PATCH",
1075
1387
  `/api/v1/checkout/${checkoutId}/billing-address`,
1076
1388
  address
@@ -1087,11 +1399,143 @@ var OmniSyncClient = class {
1087
1399
  * ```
1088
1400
  */
1089
1401
  async completeCheckout(checkoutId) {
1090
- return this.request(
1402
+ if (this.storeId && !this.apiKey) {
1403
+ return this.storefrontRequest(
1404
+ "POST",
1405
+ `/checkout/${checkoutId}/complete`
1406
+ );
1407
+ }
1408
+ return this.adminRequest(
1091
1409
  "POST",
1092
1410
  `/api/v1/checkout/${checkoutId}/complete`
1093
1411
  );
1094
1412
  }
1413
+ // -------------------- Storefront Customer Self-Service --------------------
1414
+ // These methods require customerToken to be set (call setCustomerToken after login)
1415
+ /**
1416
+ * Get the current customer's profile (requires customerToken)
1417
+ * Only available in storefront mode
1418
+ *
1419
+ * @example
1420
+ * ```typescript
1421
+ * const auth = await omni.loginCustomer('user@example.com', 'password');
1422
+ * omni.setCustomerToken(auth.token);
1423
+ * const profile = await omni.getMyProfile();
1424
+ * ```
1425
+ */
1426
+ async getMyProfile() {
1427
+ if (!this.storeId) {
1428
+ throw new OmniSyncError("getMyProfile is only available in storefront mode", 400);
1429
+ }
1430
+ if (!this.customerToken) {
1431
+ throw new OmniSyncError("Customer token required. Call setCustomerToken() after login.", 401);
1432
+ }
1433
+ return this.storefrontRequest("GET", "/customers/me");
1434
+ }
1435
+ /**
1436
+ * Update the current customer's profile (requires customerToken)
1437
+ * Only available in storefront mode
1438
+ */
1439
+ async updateMyProfile(data) {
1440
+ if (!this.storeId) {
1441
+ throw new OmniSyncError("updateMyProfile is only available in storefront mode", 400);
1442
+ }
1443
+ if (!this.customerToken) {
1444
+ throw new OmniSyncError("Customer token required. Call setCustomerToken() after login.", 401);
1445
+ }
1446
+ return this.storefrontRequest("PATCH", "/customers/me", data);
1447
+ }
1448
+ /**
1449
+ * Get the current customer's orders (requires customerToken)
1450
+ * Only available in storefront mode
1451
+ */
1452
+ async getMyOrders(params) {
1453
+ if (!this.storeId) {
1454
+ throw new OmniSyncError("getMyOrders is only available in storefront mode", 400);
1455
+ }
1456
+ if (!this.customerToken) {
1457
+ throw new OmniSyncError("Customer token required. Call setCustomerToken() after login.", 401);
1458
+ }
1459
+ return this.storefrontRequest(
1460
+ "GET",
1461
+ "/customers/me/orders",
1462
+ void 0,
1463
+ {
1464
+ page: params?.page,
1465
+ limit: params?.limit
1466
+ }
1467
+ );
1468
+ }
1469
+ /**
1470
+ * Get the current customer's addresses (requires customerToken)
1471
+ * Only available in storefront mode
1472
+ */
1473
+ async getMyAddresses() {
1474
+ if (!this.storeId) {
1475
+ throw new OmniSyncError("getMyAddresses is only available in storefront mode", 400);
1476
+ }
1477
+ if (!this.customerToken) {
1478
+ throw new OmniSyncError("Customer token required. Call setCustomerToken() after login.", 401);
1479
+ }
1480
+ return this.storefrontRequest("GET", "/customers/me/addresses");
1481
+ }
1482
+ /**
1483
+ * Add an address to the current customer (requires customerToken)
1484
+ * Only available in storefront mode
1485
+ */
1486
+ async addMyAddress(address) {
1487
+ if (!this.storeId) {
1488
+ throw new OmniSyncError("addMyAddress is only available in storefront mode", 400);
1489
+ }
1490
+ if (!this.customerToken) {
1491
+ throw new OmniSyncError("Customer token required. Call setCustomerToken() after login.", 401);
1492
+ }
1493
+ return this.storefrontRequest("POST", "/customers/me/addresses", address);
1494
+ }
1495
+ /**
1496
+ * Update a customer address (requires customerToken)
1497
+ * Only available in storefront mode
1498
+ */
1499
+ async updateMyAddress(addressId, data) {
1500
+ if (!this.storeId) {
1501
+ throw new OmniSyncError("updateMyAddress is only available in storefront mode", 400);
1502
+ }
1503
+ if (!this.customerToken) {
1504
+ throw new OmniSyncError("Customer token required. Call setCustomerToken() after login.", 401);
1505
+ }
1506
+ return this.storefrontRequest(
1507
+ "PATCH",
1508
+ `/customers/me/addresses/${addressId}`,
1509
+ data
1510
+ );
1511
+ }
1512
+ /**
1513
+ * Delete a customer address (requires customerToken)
1514
+ * Only available in storefront mode
1515
+ */
1516
+ async deleteMyAddress(addressId) {
1517
+ if (!this.storeId) {
1518
+ throw new OmniSyncError("deleteMyAddress is only available in storefront mode", 400);
1519
+ }
1520
+ if (!this.customerToken) {
1521
+ throw new OmniSyncError("Customer token required. Call setCustomerToken() after login.", 401);
1522
+ }
1523
+ await this.storefrontRequest("DELETE", `/customers/me/addresses/${addressId}`);
1524
+ }
1525
+ /**
1526
+ * Get the current customer's cart (requires customerToken)
1527
+ * Creates a new cart if none exists
1528
+ * Only available in storefront mode
1529
+ */
1530
+ async getMyCart() {
1531
+ if (!this.storeId) {
1532
+ throw new OmniSyncError("getMyCart is only available in storefront mode", 400);
1533
+ }
1534
+ if (!this.customerToken) {
1535
+ throw new OmniSyncError("Customer token required. Call setCustomerToken() after login.", 401);
1536
+ }
1537
+ return this.storefrontRequest("GET", "/customers/me/cart");
1538
+ }
1095
1539
  };
1096
1540
  var OmniSyncError = class extends Error {
1097
1541
  constructor(message, statusCode, details) {