@cimplify/sdk 0.52.2 → 0.54.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.
Files changed (60) hide show
  1. package/dist/{ads-BxbWrwqp.d.mts → ads-C2c2Aald.d.mts} +1 -1
  2. package/dist/{ads-BxbWrwqp.d.ts → ads-C2c2Aald.d.ts} +1 -1
  3. package/dist/advanced.d.mts +3 -3
  4. package/dist/advanced.d.ts +3 -3
  5. package/dist/advanced.js +20 -20
  6. package/dist/advanced.mjs +1 -1
  7. package/dist/{chunk-R3F55BRN.mjs → chunk-3G4QCENX.mjs} +42 -22
  8. package/dist/{chunk-APHYBBDD.mjs → chunk-6QZQQRBB.mjs} +20 -9
  9. package/dist/{chunk-GLAVTDDE.mjs → chunk-B3Y4C4A7.mjs} +56 -53
  10. package/dist/{chunk-ROURLUXG.js → chunk-EJUKGJTZ.js} +4 -4
  11. package/dist/{chunk-Q5VGDCQF.js → chunk-HCZTBWU4.js} +42 -22
  12. package/dist/{chunk-EMS6DQIX.js → chunk-IJ32BXKZ.js} +54 -43
  13. package/dist/{chunk-VZS453ON.mjs → chunk-NEK7CVE2.mjs} +2 -2
  14. package/dist/{chunk-EQLT46ZR.js → chunk-YJLOOC3L.js} +56 -53
  15. package/dist/{client-C6J_RGlr.d.mts → client-306peWZ0.d.ts} +47 -29
  16. package/dist/{client-CX7IFIkL.d.ts → client-Bj2apl_y.d.mts} +47 -29
  17. package/dist/{client-Lt7uGLmT.d.ts → client-C2bKMy5g.d.ts} +2 -2
  18. package/dist/{client-DdefKjcs.d.mts → client-D1Gknspz.d.mts} +2 -2
  19. package/dist/{index-Bo0NjgR6.d.mts → index-D8vnKlOQ.d.mts} +4 -4
  20. package/dist/{index-BAohYhdg.d.ts → index-DIIlPUOC.d.ts} +4 -4
  21. package/dist/index.d.mts +7 -7
  22. package/dist/index.d.ts +7 -7
  23. package/dist/index.js +61 -61
  24. package/dist/index.mjs +2 -2
  25. package/dist/mock/cli.mjs +42 -22
  26. package/dist/mock/library.js +42 -22
  27. package/dist/mock/library.mjs +42 -22
  28. package/dist/mock/msw.js +42 -22
  29. package/dist/mock/msw.mjs +42 -22
  30. package/dist/{payment-_e99nSRj.d.ts → payment-DVS7ZUEp.d.mts} +2 -2
  31. package/dist/{payment-9L_-GWqQ.d.mts → payment-sn-yGL7v.d.ts} +2 -2
  32. package/dist/{price-BjehlIhG.d.mts → price-9T1Y47oS.d.ts} +2 -2
  33. package/dist/{price-CWQ5TQmk.d.ts → price-Cm0tU0V5.d.mts} +2 -2
  34. package/dist/{product-C-xLzh7Q.d.ts → product-B_kS4Oxa.d.mts} +1 -1
  35. package/dist/{product-C-xLzh7Q.d.mts → product-B_kS4Oxa.d.ts} +1 -1
  36. package/dist/react.d.mts +6 -6
  37. package/dist/react.d.ts +6 -6
  38. package/dist/react.js +16 -16
  39. package/dist/react.mjs +2 -2
  40. package/dist/{server-72rzvJ4Y.d.ts → server-BQzz921M.d.ts} +1 -1
  41. package/dist/{server-BgccqOLT.d.mts → server-D8rwqZQ6.d.mts} +1 -1
  42. package/dist/server.d.mts +39 -47
  43. package/dist/server.d.ts +39 -47
  44. package/dist/server.js +3 -89
  45. package/dist/server.mjs +3 -88
  46. package/dist/testing/msw.d.mts +2 -2
  47. package/dist/testing/msw.d.ts +2 -2
  48. package/dist/testing/msw.js +2 -2
  49. package/dist/testing/msw.mjs +1 -1
  50. package/dist/testing/suite.d.mts +6 -6
  51. package/dist/testing/suite.d.ts +6 -6
  52. package/dist/testing/suite.js +23 -23
  53. package/dist/testing/suite.mjs +4 -4
  54. package/dist/testing.d.mts +5 -5
  55. package/dist/testing.d.ts +5 -5
  56. package/dist/testing.js +79 -79
  57. package/dist/testing.mjs +5 -5
  58. package/dist/utils.d.mts +4 -4
  59. package/dist/utils.d.ts +4 -4
  60. package/package.json +1 -1
package/dist/react.js CHANGED
@@ -2,8 +2,8 @@
2
2
  'use strict';
3
3
 
4
4
  var chunkMN4PNKJA_js = require('./chunk-MN4PNKJA.js');
5
- var chunkEMS6DQIX_js = require('./chunk-EMS6DQIX.js');
6
- var chunkEQLT46ZR_js = require('./chunk-EQLT46ZR.js');
5
+ var chunkIJ32BXKZ_js = require('./chunk-IJ32BXKZ.js');
6
+ var chunkYJLOOC3L_js = require('./chunk-YJLOOC3L.js');
7
7
  var chunk7Y2O3E4D_js = require('./chunk-7Y2O3E4D.js');
8
8
  var chunkXA3ZNR75_js = require('./chunk-XA3ZNR75.js');
9
9
  require('./chunk-OWW5GUSB.js');
@@ -1085,7 +1085,7 @@ var DEFAULT_COUNTRY = "US";
1085
1085
  function createDefaultClient() {
1086
1086
  const processRef = globalThis.process;
1087
1087
  const envPublicKey = processRef?.env?.NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY || "";
1088
- return chunkEMS6DQIX_js.createCimplifyClient({ publicKey: envPublicKey });
1088
+ return chunkIJ32BXKZ_js.createCimplifyClient({ publicKey: envPublicKey });
1089
1089
  }
1090
1090
  function getStoredLocationId() {
1091
1091
  if (typeof window === "undefined" || !window.localStorage) {
@@ -3520,19 +3520,19 @@ function AuthElement({
3520
3520
  }, [onReady, onAuthenticated, onRequiresOtp, onError]);
3521
3521
  React10.useEffect(() => {
3522
3522
  if (!elements || !containerRef.current) return;
3523
- const element = elements.create(chunkEQLT46ZR_js.ELEMENT_TYPES.AUTH, { prefillEmail });
3523
+ const element = elements.create(chunkYJLOOC3L_js.ELEMENT_TYPES.AUTH, { prefillEmail });
3524
3524
  elementRef.current = element;
3525
- element.on(chunkEQLT46ZR_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
3525
+ element.on(chunkYJLOOC3L_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
3526
3526
  element.on(
3527
- chunkEQLT46ZR_js.EVENT_TYPES.AUTHENTICATED,
3527
+ chunkYJLOOC3L_js.EVENT_TYPES.AUTHENTICATED,
3528
3528
  (data) => onAuthenticatedRef.current?.(data)
3529
3529
  );
3530
3530
  element.on(
3531
- chunkEQLT46ZR_js.EVENT_TYPES.REQUIRES_OTP,
3531
+ chunkYJLOOC3L_js.EVENT_TYPES.REQUIRES_OTP,
3532
3532
  (data) => onRequiresOtpRef.current?.(data)
3533
3533
  );
3534
3534
  element.on(
3535
- chunkEQLT46ZR_js.EVENT_TYPES.ERROR,
3535
+ chunkYJLOOC3L_js.EVENT_TYPES.ERROR,
3536
3536
  (data) => onErrorRef.current?.(data)
3537
3537
  );
3538
3538
  element.mount(containerRef.current);
@@ -3561,15 +3561,15 @@ function AddressElement({
3561
3561
  }, [onReady, onChange, onError]);
3562
3562
  React10.useEffect(() => {
3563
3563
  if (!elements || !containerRef.current) return;
3564
- const element = elements.create(chunkEQLT46ZR_js.ELEMENT_TYPES.ADDRESS, { mode });
3564
+ const element = elements.create(chunkYJLOOC3L_js.ELEMENT_TYPES.ADDRESS, { mode });
3565
3565
  elementRef.current = element;
3566
- element.on(chunkEQLT46ZR_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
3566
+ element.on(chunkYJLOOC3L_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
3567
3567
  element.on(
3568
- chunkEQLT46ZR_js.EVENT_TYPES.CHANGE,
3568
+ chunkYJLOOC3L_js.EVENT_TYPES.CHANGE,
3569
3569
  (data) => onChangeRef.current?.(data)
3570
3570
  );
3571
3571
  element.on(
3572
- chunkEQLT46ZR_js.EVENT_TYPES.ERROR,
3572
+ chunkYJLOOC3L_js.EVENT_TYPES.ERROR,
3573
3573
  (data) => onErrorRef.current?.(data)
3574
3574
  );
3575
3575
  element.mount(containerRef.current);
@@ -3599,15 +3599,15 @@ function PaymentElement({
3599
3599
  }, [onReady, onChange, onError]);
3600
3600
  React10.useEffect(() => {
3601
3601
  if (!elements || !containerRef.current) return;
3602
- const element = elements.create(chunkEQLT46ZR_js.ELEMENT_TYPES.PAYMENT, { amount, currency });
3602
+ const element = elements.create(chunkYJLOOC3L_js.ELEMENT_TYPES.PAYMENT, { amount, currency });
3603
3603
  elementRef.current = element;
3604
- element.on(chunkEQLT46ZR_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
3604
+ element.on(chunkYJLOOC3L_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
3605
3605
  element.on(
3606
- chunkEQLT46ZR_js.EVENT_TYPES.CHANGE,
3606
+ chunkYJLOOC3L_js.EVENT_TYPES.CHANGE,
3607
3607
  (data) => onChangeRef.current?.(data)
3608
3608
  );
3609
3609
  element.on(
3610
- chunkEQLT46ZR_js.EVENT_TYPES.ERROR,
3610
+ chunkYJLOOC3L_js.EVENT_TYPES.ERROR,
3611
3611
  (data) => onErrorRef.current?.(data)
3612
3612
  );
3613
3613
  element.mount(containerRef.current);
package/dist/react.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { DURATION_UNIT, getVariantDisplayName, INPUT_FIELD_TYPE, PRODUCT_TYPE, RENDER_HINT } from './chunk-NRDRVZ62.mjs';
3
3
  export { getVariantDisplayName } from './chunk-NRDRVZ62.mjs';
4
- import { createCimplifyClient } from './chunk-APHYBBDD.mjs';
5
- import { ELEMENT_TYPES, EVENT_TYPES } from './chunk-GLAVTDDE.mjs';
4
+ import { createCimplifyClient } from './chunk-6QZQQRBB.mjs';
5
+ import { ELEMENT_TYPES, EVENT_TYPES } from './chunk-B3Y4C4A7.mjs';
6
6
  import { formatPrice, parsePrice, getUnitPriceAtQuantity, isOnSale, getDiscountPercentage, getBasePrice, getPriceRange, formatPriceRange } from './chunk-TD3AY34U.mjs';
7
7
  import { isSupportedCurrency } from './chunk-AMZXALF6.mjs';
8
8
  import './chunk-3G6RQLXK.mjs';
@@ -1,5 +1,5 @@
1
1
  import { Hono } from 'hono';
2
- import { a6 as ProductInputField } from './product-C-xLzh7Q.js';
2
+ import { b1 as ProductInputField } from './product-B_kS4Oxa.js';
3
3
 
4
4
  interface Clock {
5
5
  now(): Date;
@@ -1,5 +1,5 @@
1
1
  import { Hono } from 'hono';
2
- import { a6 as ProductInputField } from './product-C-xLzh7Q.mjs';
2
+ import { b1 as ProductInputField } from './product-B_kS4Oxa.mjs';
3
3
 
4
4
  interface Clock {
5
5
  now(): Date;
package/dist/server.d.mts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as CimplifyClient } from './client-C6J_RGlr.mjs';
2
- export { aO as Result } from './client-C6J_RGlr.mjs';
3
- export { ap as Category, h as CimplifyError, ar as Collection, X as Product, aa as ProductWithDetails } from './product-C-xLzh7Q.mjs';
4
- import './payment-9L_-GWqQ.mjs';
1
+ import { ac as CimplifyClient } from './client-Bj2apl_y.mjs';
2
+ export { J as CacheOptions, c7 as ReadRequestOptions, ct as Result } from './client-Bj2apl_y.mjs';
3
+ export { Q as Category, T as CimplifyError, U as Collection, aX as Product, b9 as ProductWithDetails } from './product-B_kS4Oxa.mjs';
4
+ import './payment-DVS7ZUEp.mjs';
5
5
 
6
6
  interface ServerClientOptions {
7
7
  /**
@@ -27,9 +27,17 @@ interface ServerClientOptions {
27
27
  *
28
28
  * The returned client is the exact same surface the browser uses — every
29
29
  * resource (catalogue, cart, checkout, …) and every method works identically.
30
- * Caching is Next.js's responsibility: wrap your composed reads with
31
- * `'use cache'` + `cacheTag` (using the tag builders from `@cimplify/sdk/server`),
32
- * or set `next: { revalidate, tags }` on individual fetches.
30
+ *
31
+ * Caching is Next.js's responsibility. Pass `cacheOptions` per read method
32
+ * (`{ revalidate, tags }`); the SDK forwards them as `next: { revalidate, tags }`
33
+ * on the underlying fetch — Next 16's documented ISR API. Invalidate via the
34
+ * `revalidate*` helpers (also exported from this entry) or the bare
35
+ * `revalidateTag` / `revalidatePath` from `next/cache`.
36
+ *
37
+ * If you have `cacheComponents: true` in `next.config.ts` (Next 16 PPR-style
38
+ * caching), the `'use cache'` + `cacheTag` / `cacheLife` directives work too —
39
+ * but they require a Node-compatible runtime and won't function on Cloudflare
40
+ * Workers. For Workers / WfP storefronts, stay on the ISR (`cacheOptions`) path.
33
41
  *
34
42
  * Errors continue to flow through `Result<T, CimplifyError>`. Use the SDK's
35
43
  * `unwrap()` helper, or `if (!result.ok) notFound()` — whichever is
@@ -37,13 +45,13 @@ interface ServerClientOptions {
37
45
  *
38
46
  * @example
39
47
  * import { getServerClient, tags } from "@cimplify/sdk/server";
40
- * import { cacheTag, cacheLife } from "next/cache";
48
+ *
49
+ * export const revalidate = 3600;
41
50
  *
42
51
  * async function getProduct(slug: string) {
43
- * "use cache";
44
- * cacheTag(tags.product(slug));
45
- * cacheLife("hours");
46
- * const r = await getServerClient().catalogue.getProductBySlug(slug);
52
+ * const r = await getServerClient().catalogue.getProductBySlug(slug, {
53
+ * cacheOptions: { revalidate: 3600, tags: [tags.product(slug)] },
54
+ * });
47
55
  * if (!r.ok) throw new Error(r.error.message);
48
56
  * return r.value;
49
57
  * }
@@ -137,26 +145,26 @@ type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
137
145
  type CacheLifeProbe = typeof CACHE_LIFE_PROBE;
138
146
 
139
147
  /** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
140
- type RevalidateProfile$1 = string | {
148
+ type RevalidateProfile = string | {
141
149
  expire: number;
142
150
  };
143
- declare function revalidateProducts(profile?: RevalidateProfile$1): Promise<void>;
144
- declare function revalidateProduct(id: string, profile?: RevalidateProfile$1): Promise<void>;
145
- declare function revalidateCategories(profile?: RevalidateProfile$1): Promise<void>;
146
- declare function revalidateCategory(id: string, profile?: RevalidateProfile$1): Promise<void>;
147
- declare function revalidateCollections(profile?: RevalidateProfile$1): Promise<void>;
148
- declare function revalidateCollection(id: string, profile?: RevalidateProfile$1): Promise<void>;
149
- declare function revalidateBusiness(profile?: RevalidateProfile$1): Promise<void>;
150
- declare function revalidateBrand(profile?: RevalidateProfile$1): Promise<void>;
151
- declare function revalidateLocations(profile?: RevalidateProfile$1): Promise<void>;
152
- declare function revalidateLocation(id: string, profile?: RevalidateProfile$1): Promise<void>;
153
- declare function revalidatePricing(profile?: RevalidateProfile$1): Promise<void>;
154
- declare function revalidateAddOns(profile?: RevalidateProfile$1): Promise<void>;
155
- declare function revalidateAddOn(id: string, profile?: RevalidateProfile$1): Promise<void>;
156
- declare function revalidateSubscriptions(profile?: RevalidateProfile$1): Promise<void>;
157
- declare function revalidateSubscription(id: string, profile?: RevalidateProfile$1): Promise<void>;
158
- declare function revalidateStock(productId?: string, profile?: RevalidateProfile$1): Promise<void>;
159
- declare function revalidateByTag(tag: string, profile?: RevalidateProfile$1): Promise<void>;
151
+ declare function revalidateProducts(profile?: RevalidateProfile): Promise<void>;
152
+ declare function revalidateProduct(id: string, profile?: RevalidateProfile): Promise<void>;
153
+ declare function revalidateCategories(profile?: RevalidateProfile): Promise<void>;
154
+ declare function revalidateCategory(id: string, profile?: RevalidateProfile): Promise<void>;
155
+ declare function revalidateCollections(profile?: RevalidateProfile): Promise<void>;
156
+ declare function revalidateCollection(id: string, profile?: RevalidateProfile): Promise<void>;
157
+ declare function revalidateBusiness(profile?: RevalidateProfile): Promise<void>;
158
+ declare function revalidateBrand(profile?: RevalidateProfile): Promise<void>;
159
+ declare function revalidateLocations(profile?: RevalidateProfile): Promise<void>;
160
+ declare function revalidateLocation(id: string, profile?: RevalidateProfile): Promise<void>;
161
+ declare function revalidatePricing(profile?: RevalidateProfile): Promise<void>;
162
+ declare function revalidateAddOns(profile?: RevalidateProfile): Promise<void>;
163
+ declare function revalidateAddOn(id: string, profile?: RevalidateProfile): Promise<void>;
164
+ declare function revalidateSubscriptions(profile?: RevalidateProfile): Promise<void>;
165
+ declare function revalidateSubscription(id: string, profile?: RevalidateProfile): Promise<void>;
166
+ declare function revalidateStock(productId?: string, profile?: RevalidateProfile): Promise<void>;
167
+ declare function revalidateByTag(tag: string, profile?: RevalidateProfile): Promise<void>;
160
168
 
161
169
  declare function updateProducts(): Promise<void>;
162
170
  declare function updateProduct(id: string): Promise<void>;
@@ -177,20 +185,4 @@ declare function updateStock(productId?: string): Promise<void>;
177
185
  declare function updateByTag(tag: string): Promise<void>;
178
186
  declare function refreshPage(): Promise<void>;
179
187
 
180
- /** Next 16 cacheLife profile a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
181
- type RevalidateProfile = string | {
182
- expire: number;
183
- };
184
- interface RevalidateRouteOptions {
185
- /** Defaults to `process.env.CIMPLIFY_REVALIDATE_SECRET`. */
186
- secret?: string;
187
- /** Defaults to a lazy import of `next/cache.revalidateTag`. Override for tests. */
188
- revalidateTag?: (tag: string, profile: RevalidateProfile) => void;
189
- /** Defaults to `Date.now`. Override for tests. */
190
- now?: () => number;
191
- /** Profile used when the request body doesn't include one. Defaults to `'max'`. */
192
- defaultProfile?: RevalidateProfile;
193
- }
194
- declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
195
-
196
- export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile$1 as RevalidateProfile, type RevalidateRouteOptions, type RevalidateProfile as RevalidateRouteProfile, type ServerClientOptions, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
188
+ export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile, type ServerClientOptions, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
package/dist/server.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { C as CimplifyClient } from './client-CX7IFIkL.js';
2
- export { aO as Result } from './client-CX7IFIkL.js';
3
- export { ap as Category, h as CimplifyError, ar as Collection, X as Product, aa as ProductWithDetails } from './product-C-xLzh7Q.js';
4
- import './payment-_e99nSRj.js';
1
+ import { ac as CimplifyClient } from './client-306peWZ0.js';
2
+ export { J as CacheOptions, c7 as ReadRequestOptions, ct as Result } from './client-306peWZ0.js';
3
+ export { Q as Category, T as CimplifyError, U as Collection, aX as Product, b9 as ProductWithDetails } from './product-B_kS4Oxa.js';
4
+ import './payment-sn-yGL7v.js';
5
5
 
6
6
  interface ServerClientOptions {
7
7
  /**
@@ -27,9 +27,17 @@ interface ServerClientOptions {
27
27
  *
28
28
  * The returned client is the exact same surface the browser uses — every
29
29
  * resource (catalogue, cart, checkout, …) and every method works identically.
30
- * Caching is Next.js's responsibility: wrap your composed reads with
31
- * `'use cache'` + `cacheTag` (using the tag builders from `@cimplify/sdk/server`),
32
- * or set `next: { revalidate, tags }` on individual fetches.
30
+ *
31
+ * Caching is Next.js's responsibility. Pass `cacheOptions` per read method
32
+ * (`{ revalidate, tags }`); the SDK forwards them as `next: { revalidate, tags }`
33
+ * on the underlying fetch — Next 16's documented ISR API. Invalidate via the
34
+ * `revalidate*` helpers (also exported from this entry) or the bare
35
+ * `revalidateTag` / `revalidatePath` from `next/cache`.
36
+ *
37
+ * If you have `cacheComponents: true` in `next.config.ts` (Next 16 PPR-style
38
+ * caching), the `'use cache'` + `cacheTag` / `cacheLife` directives work too —
39
+ * but they require a Node-compatible runtime and won't function on Cloudflare
40
+ * Workers. For Workers / WfP storefronts, stay on the ISR (`cacheOptions`) path.
33
41
  *
34
42
  * Errors continue to flow through `Result<T, CimplifyError>`. Use the SDK's
35
43
  * `unwrap()` helper, or `if (!result.ok) notFound()` — whichever is
@@ -37,13 +45,13 @@ interface ServerClientOptions {
37
45
  *
38
46
  * @example
39
47
  * import { getServerClient, tags } from "@cimplify/sdk/server";
40
- * import { cacheTag, cacheLife } from "next/cache";
48
+ *
49
+ * export const revalidate = 3600;
41
50
  *
42
51
  * async function getProduct(slug: string) {
43
- * "use cache";
44
- * cacheTag(tags.product(slug));
45
- * cacheLife("hours");
46
- * const r = await getServerClient().catalogue.getProductBySlug(slug);
52
+ * const r = await getServerClient().catalogue.getProductBySlug(slug, {
53
+ * cacheOptions: { revalidate: 3600, tags: [tags.product(slug)] },
54
+ * });
47
55
  * if (!r.ok) throw new Error(r.error.message);
48
56
  * return r.value;
49
57
  * }
@@ -137,26 +145,26 @@ type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
137
145
  type CacheLifeProbe = typeof CACHE_LIFE_PROBE;
138
146
 
139
147
  /** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
140
- type RevalidateProfile$1 = string | {
148
+ type RevalidateProfile = string | {
141
149
  expire: number;
142
150
  };
143
- declare function revalidateProducts(profile?: RevalidateProfile$1): Promise<void>;
144
- declare function revalidateProduct(id: string, profile?: RevalidateProfile$1): Promise<void>;
145
- declare function revalidateCategories(profile?: RevalidateProfile$1): Promise<void>;
146
- declare function revalidateCategory(id: string, profile?: RevalidateProfile$1): Promise<void>;
147
- declare function revalidateCollections(profile?: RevalidateProfile$1): Promise<void>;
148
- declare function revalidateCollection(id: string, profile?: RevalidateProfile$1): Promise<void>;
149
- declare function revalidateBusiness(profile?: RevalidateProfile$1): Promise<void>;
150
- declare function revalidateBrand(profile?: RevalidateProfile$1): Promise<void>;
151
- declare function revalidateLocations(profile?: RevalidateProfile$1): Promise<void>;
152
- declare function revalidateLocation(id: string, profile?: RevalidateProfile$1): Promise<void>;
153
- declare function revalidatePricing(profile?: RevalidateProfile$1): Promise<void>;
154
- declare function revalidateAddOns(profile?: RevalidateProfile$1): Promise<void>;
155
- declare function revalidateAddOn(id: string, profile?: RevalidateProfile$1): Promise<void>;
156
- declare function revalidateSubscriptions(profile?: RevalidateProfile$1): Promise<void>;
157
- declare function revalidateSubscription(id: string, profile?: RevalidateProfile$1): Promise<void>;
158
- declare function revalidateStock(productId?: string, profile?: RevalidateProfile$1): Promise<void>;
159
- declare function revalidateByTag(tag: string, profile?: RevalidateProfile$1): Promise<void>;
151
+ declare function revalidateProducts(profile?: RevalidateProfile): Promise<void>;
152
+ declare function revalidateProduct(id: string, profile?: RevalidateProfile): Promise<void>;
153
+ declare function revalidateCategories(profile?: RevalidateProfile): Promise<void>;
154
+ declare function revalidateCategory(id: string, profile?: RevalidateProfile): Promise<void>;
155
+ declare function revalidateCollections(profile?: RevalidateProfile): Promise<void>;
156
+ declare function revalidateCollection(id: string, profile?: RevalidateProfile): Promise<void>;
157
+ declare function revalidateBusiness(profile?: RevalidateProfile): Promise<void>;
158
+ declare function revalidateBrand(profile?: RevalidateProfile): Promise<void>;
159
+ declare function revalidateLocations(profile?: RevalidateProfile): Promise<void>;
160
+ declare function revalidateLocation(id: string, profile?: RevalidateProfile): Promise<void>;
161
+ declare function revalidatePricing(profile?: RevalidateProfile): Promise<void>;
162
+ declare function revalidateAddOns(profile?: RevalidateProfile): Promise<void>;
163
+ declare function revalidateAddOn(id: string, profile?: RevalidateProfile): Promise<void>;
164
+ declare function revalidateSubscriptions(profile?: RevalidateProfile): Promise<void>;
165
+ declare function revalidateSubscription(id: string, profile?: RevalidateProfile): Promise<void>;
166
+ declare function revalidateStock(productId?: string, profile?: RevalidateProfile): Promise<void>;
167
+ declare function revalidateByTag(tag: string, profile?: RevalidateProfile): Promise<void>;
160
168
 
161
169
  declare function updateProducts(): Promise<void>;
162
170
  declare function updateProduct(id: string): Promise<void>;
@@ -177,20 +185,4 @@ declare function updateStock(productId?: string): Promise<void>;
177
185
  declare function updateByTag(tag: string): Promise<void>;
178
186
  declare function refreshPage(): Promise<void>;
179
187
 
180
- /** Next 16 cacheLife profile a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
181
- type RevalidateProfile = string | {
182
- expire: number;
183
- };
184
- interface RevalidateRouteOptions {
185
- /** Defaults to `process.env.CIMPLIFY_REVALIDATE_SECRET`. */
186
- secret?: string;
187
- /** Defaults to a lazy import of `next/cache.revalidateTag`. Override for tests. */
188
- revalidateTag?: (tag: string, profile: RevalidateProfile) => void;
189
- /** Defaults to `Date.now`. Override for tests. */
190
- now?: () => number;
191
- /** Profile used when the request body doesn't include one. Defaults to `'max'`. */
192
- defaultProfile?: RevalidateProfile;
193
- }
194
- declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
195
-
196
- export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile$1 as RevalidateProfile, type RevalidateRouteOptions, type RevalidateProfile as RevalidateRouteProfile, type ServerClientOptions, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
188
+ export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile, type ServerClientOptions, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
package/dist/server.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkEMS6DQIX_js = require('./chunk-EMS6DQIX.js');
4
- require('./chunk-EQLT46ZR.js');
3
+ var chunkIJ32BXKZ_js = require('./chunk-IJ32BXKZ.js');
4
+ require('./chunk-YJLOOC3L.js');
5
5
  require('./chunk-7Y2O3E4D.js');
6
6
  var chunkXA3ZNR75_js = require('./chunk-XA3ZNR75.js');
7
7
  require('./chunk-OWW5GUSB.js');
@@ -25,7 +25,7 @@ function readEnv(...keys) {
25
25
  var getServerClient = react.cache((opts = {}) => {
26
26
  const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ?? defaultBaseUrl();
27
27
  const publicKey = opts.secretKey ?? readEnv("CIMPLIFY_SECRET_KEY", "NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY") ?? "mock-dev";
28
- const client = chunkEMS6DQIX_js.createCimplifyClient({
28
+ const client = chunkIJ32BXKZ_js.createCimplifyClient({
29
29
  baseUrl,
30
30
  publicKey,
31
31
  suppressPublicKeyWarning: true
@@ -234,91 +234,6 @@ async function refreshPage() {
234
234
  fn();
235
235
  }
236
236
 
237
- // src/server/revalidate-route.ts
238
- var TIMESTAMP_HEADER = "x-cimplify-timestamp";
239
- var SIGNATURE_HEADER = "x-cimplify-signature";
240
- var SIGNATURE_PREFIX = "sha256=";
241
- var MAX_SKEW_MS = 5 * 60 * 1e3;
242
- var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
243
- var DEFAULT_PROFILE2 = CACHE_LIFE_DEFAULT;
244
- async function revalidateRouteHandler(req, options = {}) {
245
- const secret = options.secret ?? envSecret();
246
- if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
247
- const timestamp = req.headers.get(TIMESTAMP_HEADER);
248
- const signature = req.headers.get(SIGNATURE_HEADER);
249
- if (!timestamp || !signature) return text("missing auth headers", 401);
250
- const ts = Number.parseInt(timestamp, 10);
251
- const now = options.now ?? Date.now;
252
- if (!Number.isFinite(ts) || Math.abs(now() - ts) > MAX_SKEW_MS) {
253
- return text("stale or invalid timestamp", 401);
254
- }
255
- const body = await req.text();
256
- if (!await verifyHmac(secret, `${timestamp}.${body}`, signature)) {
257
- return text("invalid signature", 401);
258
- }
259
- let parsed;
260
- try {
261
- parsed = JSON.parse(body);
262
- } catch {
263
- return text("invalid json", 400);
264
- }
265
- const tags2 = Array.isArray(parsed.tags) ? parsed.tags.filter((t) => typeof t === "string" && t.length > 0) : [];
266
- if (tags2.length === 0) return text("no tags", 400);
267
- const profile = parseProfile(parsed.profile) ?? options.defaultProfile ?? DEFAULT_PROFILE2;
268
- const revalidate2 = options.revalidateTag ?? await loadRevalidateTag();
269
- for (const tag of tags2) revalidate2(tag, profile);
270
- return Response.json({ ok: true, revalidated: tags2.length, profile });
271
- }
272
- function parseProfile(raw) {
273
- if (typeof raw === "string" && raw.length > 0) return raw;
274
- if (raw && typeof raw === "object" && "expire" in raw && typeof raw.expire === "number") {
275
- return { expire: raw.expire };
276
- }
277
- return void 0;
278
- }
279
- var cachedRevalidateTag = null;
280
- async function loadRevalidateTag() {
281
- if (cachedRevalidateTag) return cachedRevalidateTag;
282
- const specifier = "next/cache";
283
- const mod = await import(
284
- /* webpackIgnore: true */
285
- /* @vite-ignore */
286
- specifier
287
- );
288
- cachedRevalidateTag = mod.revalidateTag;
289
- return cachedRevalidateTag;
290
- }
291
- async function verifyHmac(secret, payload, signatureHeader) {
292
- if (!signatureHeader.startsWith(SIGNATURE_PREFIX)) return false;
293
- const providedBytes = hexToBytes(signatureHeader.slice(SIGNATURE_PREFIX.length));
294
- if (!providedBytes) return false;
295
- const enc = new TextEncoder();
296
- const key = await crypto.subtle.importKey(
297
- "raw",
298
- enc.encode(secret),
299
- { name: "HMAC", hash: "SHA-256" },
300
- false,
301
- ["verify"]
302
- );
303
- return crypto.subtle.verify("HMAC", key, providedBytes, enc.encode(payload));
304
- }
305
- function hexToBytes(hex) {
306
- if (hex.length % 2 !== 0 || !/^[0-9a-f]+$/i.test(hex)) return null;
307
- const buf = new ArrayBuffer(hex.length / 2);
308
- const out = new Uint8Array(buf);
309
- for (let i = 0; i < hex.length; i += 2) {
310
- out[i / 2] = Number.parseInt(hex.slice(i, i + 2), 16);
311
- }
312
- return out;
313
- }
314
- function envSecret() {
315
- const proc = globalThis.process;
316
- return proc?.env?.[SECRET_ENV];
317
- }
318
- function text(message, status) {
319
- return new Response(message, { status, headers: { "content-type": "text/plain" } });
320
- }
321
-
322
237
  Object.defineProperty(exports, "CimplifyError", {
323
238
  enumerable: true,
324
239
  get: function () { return chunkXA3ZNR75_js.CimplifyError; }
@@ -341,7 +256,6 @@ exports.revalidateLocations = revalidateLocations;
341
256
  exports.revalidatePricing = revalidatePricing;
342
257
  exports.revalidateProduct = revalidateProduct;
343
258
  exports.revalidateProducts = revalidateProducts;
344
- exports.revalidateRouteHandler = revalidateRouteHandler;
345
259
  exports.revalidateStock = revalidateStock;
346
260
  exports.revalidateSubscription = revalidateSubscription;
347
261
  exports.revalidateSubscriptions = revalidateSubscriptions;
package/dist/server.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { createCimplifyClient } from './chunk-APHYBBDD.mjs';
2
- import './chunk-GLAVTDDE.mjs';
1
+ import { createCimplifyClient } from './chunk-6QZQQRBB.mjs';
2
+ import './chunk-B3Y4C4A7.mjs';
3
3
  import './chunk-TD3AY34U.mjs';
4
4
  export { CimplifyError } from './chunk-AMZXALF6.mjs';
5
5
  import './chunk-3G6RQLXK.mjs';
@@ -232,89 +232,4 @@ async function refreshPage() {
232
232
  fn();
233
233
  }
234
234
 
235
- // src/server/revalidate-route.ts
236
- var TIMESTAMP_HEADER = "x-cimplify-timestamp";
237
- var SIGNATURE_HEADER = "x-cimplify-signature";
238
- var SIGNATURE_PREFIX = "sha256=";
239
- var MAX_SKEW_MS = 5 * 60 * 1e3;
240
- var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
241
- var DEFAULT_PROFILE2 = CACHE_LIFE_DEFAULT;
242
- async function revalidateRouteHandler(req, options = {}) {
243
- const secret = options.secret ?? envSecret();
244
- if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
245
- const timestamp = req.headers.get(TIMESTAMP_HEADER);
246
- const signature = req.headers.get(SIGNATURE_HEADER);
247
- if (!timestamp || !signature) return text("missing auth headers", 401);
248
- const ts = Number.parseInt(timestamp, 10);
249
- const now = options.now ?? Date.now;
250
- if (!Number.isFinite(ts) || Math.abs(now() - ts) > MAX_SKEW_MS) {
251
- return text("stale or invalid timestamp", 401);
252
- }
253
- const body = await req.text();
254
- if (!await verifyHmac(secret, `${timestamp}.${body}`, signature)) {
255
- return text("invalid signature", 401);
256
- }
257
- let parsed;
258
- try {
259
- parsed = JSON.parse(body);
260
- } catch {
261
- return text("invalid json", 400);
262
- }
263
- const tags2 = Array.isArray(parsed.tags) ? parsed.tags.filter((t) => typeof t === "string" && t.length > 0) : [];
264
- if (tags2.length === 0) return text("no tags", 400);
265
- const profile = parseProfile(parsed.profile) ?? options.defaultProfile ?? DEFAULT_PROFILE2;
266
- const revalidate2 = options.revalidateTag ?? await loadRevalidateTag();
267
- for (const tag of tags2) revalidate2(tag, profile);
268
- return Response.json({ ok: true, revalidated: tags2.length, profile });
269
- }
270
- function parseProfile(raw) {
271
- if (typeof raw === "string" && raw.length > 0) return raw;
272
- if (raw && typeof raw === "object" && "expire" in raw && typeof raw.expire === "number") {
273
- return { expire: raw.expire };
274
- }
275
- return void 0;
276
- }
277
- var cachedRevalidateTag = null;
278
- async function loadRevalidateTag() {
279
- if (cachedRevalidateTag) return cachedRevalidateTag;
280
- const specifier = "next/cache";
281
- const mod = await import(
282
- /* webpackIgnore: true */
283
- /* @vite-ignore */
284
- specifier
285
- );
286
- cachedRevalidateTag = mod.revalidateTag;
287
- return cachedRevalidateTag;
288
- }
289
- async function verifyHmac(secret, payload, signatureHeader) {
290
- if (!signatureHeader.startsWith(SIGNATURE_PREFIX)) return false;
291
- const providedBytes = hexToBytes(signatureHeader.slice(SIGNATURE_PREFIX.length));
292
- if (!providedBytes) return false;
293
- const enc = new TextEncoder();
294
- const key = await crypto.subtle.importKey(
295
- "raw",
296
- enc.encode(secret),
297
- { name: "HMAC", hash: "SHA-256" },
298
- false,
299
- ["verify"]
300
- );
301
- return crypto.subtle.verify("HMAC", key, providedBytes, enc.encode(payload));
302
- }
303
- function hexToBytes(hex) {
304
- if (hex.length % 2 !== 0 || !/^[0-9a-f]+$/i.test(hex)) return null;
305
- const buf = new ArrayBuffer(hex.length / 2);
306
- const out = new Uint8Array(buf);
307
- for (let i = 0; i < hex.length; i += 2) {
308
- out[i / 2] = Number.parseInt(hex.slice(i, i + 2), 16);
309
- }
310
- return out;
311
- }
312
- function envSecret() {
313
- const proc = globalThis.process;
314
- return proc?.env?.[SECRET_ENV];
315
- }
316
- function text(message, status) {
317
- return new Response(message, { status, headers: { "content-type": "text/plain" } });
318
- }
319
-
320
- export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
235
+ export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
@@ -1,6 +1,6 @@
1
- import { A as AppHandle, C as CreateAppOptions } from '../server-BgccqOLT.mjs';
1
+ import { A as AppHandle, C as CreateAppOptions } from '../server-D8rwqZQ6.mjs';
2
2
  import 'hono';
3
- import '../product-C-xLzh7Q.mjs';
3
+ import '../product-B_kS4Oxa.mjs';
4
4
 
5
5
  interface MswHandlerSetup {
6
6
  handlers: unknown[];
@@ -1,6 +1,6 @@
1
- import { A as AppHandle, C as CreateAppOptions } from '../server-72rzvJ4Y.js';
1
+ import { A as AppHandle, C as CreateAppOptions } from '../server-BQzz921M.js';
2
2
  import 'hono';
3
- import '../product-C-xLzh7Q.js';
3
+ import '../product-B_kS4Oxa.js';
4
4
 
5
5
  interface MswHandlerSetup {
6
6
  handlers: unknown[];
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var chunkQ5VGDCQF_js = require('../chunk-Q5VGDCQF.js');
3
+ var chunkHCZTBWU4_js = require('../chunk-HCZTBWU4.js');
4
4
  require('../chunk-XA3ZNR75.js');
5
5
  require('../chunk-OWW5GUSB.js');
6
6
 
7
7
  // src/mock/msw.ts
8
8
  async function createMswHandlers(options = {}) {
9
9
  const baseUrl = options.baseUrl ?? "http://localhost:8787";
10
- const handle = chunkQ5VGDCQF_js.createMockApp(options);
10
+ const handle = chunkHCZTBWU4_js.createMockApp(options);
11
11
  const msw = await import('msw').catch(() => {
12
12
  throw new Error("msw is required to use @cimplify/sdk/mock/msw \u2014 install it as a peer dependency");
13
13
  });
@@ -1,4 +1,4 @@
1
- import { createMockApp } from '../chunk-R3F55BRN.mjs';
1
+ import { createMockApp } from '../chunk-3G4QCENX.mjs';
2
2
  import '../chunk-AMZXALF6.mjs';
3
3
  import '../chunk-3G6RQLXK.mjs';
4
4
 
@@ -1,10 +1,10 @@
1
1
  import { TestAPI } from 'vitest';
2
- import { T as TestClientHandle } from '../client-DdefKjcs.mjs';
3
- import { C as CreateAppOptions } from '../server-BgccqOLT.mjs';
4
- export { S as SeedName } from '../server-BgccqOLT.mjs';
5
- import '../client-C6J_RGlr.mjs';
6
- import '../product-C-xLzh7Q.mjs';
7
- import '../payment-9L_-GWqQ.mjs';
2
+ import { T as TestClientHandle } from '../client-D1Gknspz.mjs';
3
+ import { C as CreateAppOptions } from '../server-D8rwqZQ6.mjs';
4
+ export { S as SeedName } from '../server-D8rwqZQ6.mjs';
5
+ import '../client-Bj2apl_y.mjs';
6
+ import '../product-B_kS4Oxa.mjs';
7
+ import '../payment-DVS7ZUEp.mjs';
8
8
  import 'hono';
9
9
 
10
10
  /**