@cimplify/sdk 0.49.0 → 0.49.1

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/server.d.mts CHANGED
@@ -84,42 +84,79 @@ declare const tags: {
84
84
  readonly order: (id: string) => string;
85
85
  };
86
86
 
87
+ /** Next 16 `revalidateTag` profile arg — built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
88
+ type RevalidateProfile$1 = string | {
89
+ expire: number;
90
+ };
87
91
  /**
88
92
  * Invalidate every cache entry tagged with the products list. Call after a
89
- * Server Action that creates / deletes / reorders products.
93
+ * Server Action that creates / deletes / reorders products. The optional
94
+ * `profile` is the Next 16 cacheLife profile (defaults to `'max'` SWR).
90
95
  */
91
- declare function revalidateProducts(): Promise<void>;
96
+ declare function revalidateProducts(profile?: RevalidateProfile$1): Promise<void>;
92
97
  /**
93
98
  * Invalidate the cached detail of a single product (and the products list,
94
99
  * since list-shaped caches typically embed each product's denormalized
95
100
  * fields). Call after a Server Action that edits a product.
96
101
  */
97
- declare function revalidateProduct(id: string): Promise<void>;
98
- declare function revalidateCategories(): Promise<void>;
99
- declare function revalidateCategory(id: string): Promise<void>;
100
- declare function revalidateCollections(): Promise<void>;
101
- declare function revalidateCollection(id: string): Promise<void>;
102
- declare function revalidateBusiness(): Promise<void>;
103
- declare function revalidateBrand(): Promise<void>;
104
- declare function revalidateLocations(): Promise<void>;
105
- declare function revalidateLocation(id: string): Promise<void>;
106
- declare function revalidatePricing(): Promise<void>;
107
- declare function revalidateAddOns(): Promise<void>;
108
- declare function revalidateAddOn(id: string): Promise<void>;
109
- declare function revalidateSubscriptions(): Promise<void>;
110
- declare function revalidateSubscription(id: string): Promise<void>;
111
- declare function revalidateStock(productId?: string): Promise<void>;
102
+ declare function revalidateProduct(id: string, profile?: RevalidateProfile$1): Promise<void>;
103
+ declare function revalidateCategories(profile?: RevalidateProfile$1): Promise<void>;
104
+ declare function revalidateCategory(id: string, profile?: RevalidateProfile$1): Promise<void>;
105
+ declare function revalidateCollections(profile?: RevalidateProfile$1): Promise<void>;
106
+ declare function revalidateCollection(id: string, profile?: RevalidateProfile$1): Promise<void>;
107
+ declare function revalidateBusiness(profile?: RevalidateProfile$1): Promise<void>;
108
+ declare function revalidateBrand(profile?: RevalidateProfile$1): Promise<void>;
109
+ declare function revalidateLocations(profile?: RevalidateProfile$1): Promise<void>;
110
+ declare function revalidateLocation(id: string, profile?: RevalidateProfile$1): Promise<void>;
111
+ declare function revalidatePricing(profile?: RevalidateProfile$1): Promise<void>;
112
+ declare function revalidateAddOns(profile?: RevalidateProfile$1): Promise<void>;
113
+ declare function revalidateAddOn(id: string, profile?: RevalidateProfile$1): Promise<void>;
114
+ declare function revalidateSubscriptions(profile?: RevalidateProfile$1): Promise<void>;
115
+ declare function revalidateSubscription(id: string, profile?: RevalidateProfile$1): Promise<void>;
116
+ declare function revalidateStock(productId?: string, profile?: RevalidateProfile$1): Promise<void>;
112
117
  /**
113
118
  * Escape hatch: invalidate by raw tag string. Prefer the typed helpers
114
119
  * above where possible — they keep the tag scheme in one place.
115
120
  */
116
- declare function revalidateByTag(tag: string): Promise<void>;
121
+ declare function revalidateByTag(tag: string, profile?: RevalidateProfile$1): Promise<void>;
117
122
 
123
+ /** Expire the products list with read-your-writes. Call from a Server Action that creates / deletes / reorders. */
124
+ declare function updateProducts(): Promise<void>;
125
+ /** Expire a single product + the products list with read-your-writes. */
126
+ declare function updateProduct(id: string): Promise<void>;
127
+ declare function updateCategories(): Promise<void>;
128
+ declare function updateCategory(id: string): Promise<void>;
129
+ declare function updateCollections(): Promise<void>;
130
+ declare function updateCollection(id: string): Promise<void>;
131
+ declare function updateBusiness(): Promise<void>;
132
+ declare function updateBrand(): Promise<void>;
133
+ declare function updateLocations(): Promise<void>;
134
+ declare function updateLocation(id: string): Promise<void>;
135
+ declare function updatePricing(): Promise<void>;
136
+ declare function updateAddOns(): Promise<void>;
137
+ declare function updateAddOn(id: string): Promise<void>;
138
+ declare function updateSubscriptions(): Promise<void>;
139
+ declare function updateSubscription(id: string): Promise<void>;
140
+ declare function updateStock(productId?: string): Promise<void>;
141
+ /** Escape hatch: expire a raw tag with read-your-writes. Prefer the typed helpers above. */
142
+ declare function updateByTag(tag: string): Promise<void>;
143
+ /**
144
+ * Refresh uncached data on the current page (notification counts, live
145
+ * metrics, status indicators). Server-Action-only. Complements
146
+ * `router.refresh()` on the client.
147
+ */
148
+ declare function refreshPage(): Promise<void>;
149
+
150
+ /** Next 16 `revalidateTag` profile arg — built-in name (`'max'`/`'hours'`/…) or inline `{expire: secs}`. */
151
+ type RevalidateProfile = string | {
152
+ expire: number;
153
+ };
118
154
  interface RevalidateRouteOptions {
119
155
  secret?: string;
120
- revalidateTag?: (tag: string) => void;
156
+ revalidateTag?: (tag: string, profile: RevalidateProfile) => void;
121
157
  now?: () => number;
158
+ defaultProfile?: RevalidateProfile;
122
159
  }
123
160
  declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
124
161
 
125
- export { CimplifyClient, type RevalidateRouteOptions, type ServerClientOptions, getServerClient, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags };
162
+ export { 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 };
package/dist/server.d.ts CHANGED
@@ -84,42 +84,79 @@ declare const tags: {
84
84
  readonly order: (id: string) => string;
85
85
  };
86
86
 
87
+ /** Next 16 `revalidateTag` profile arg — built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
88
+ type RevalidateProfile$1 = string | {
89
+ expire: number;
90
+ };
87
91
  /**
88
92
  * Invalidate every cache entry tagged with the products list. Call after a
89
- * Server Action that creates / deletes / reorders products.
93
+ * Server Action that creates / deletes / reorders products. The optional
94
+ * `profile` is the Next 16 cacheLife profile (defaults to `'max'` SWR).
90
95
  */
91
- declare function revalidateProducts(): Promise<void>;
96
+ declare function revalidateProducts(profile?: RevalidateProfile$1): Promise<void>;
92
97
  /**
93
98
  * Invalidate the cached detail of a single product (and the products list,
94
99
  * since list-shaped caches typically embed each product's denormalized
95
100
  * fields). Call after a Server Action that edits a product.
96
101
  */
97
- declare function revalidateProduct(id: string): Promise<void>;
98
- declare function revalidateCategories(): Promise<void>;
99
- declare function revalidateCategory(id: string): Promise<void>;
100
- declare function revalidateCollections(): Promise<void>;
101
- declare function revalidateCollection(id: string): Promise<void>;
102
- declare function revalidateBusiness(): Promise<void>;
103
- declare function revalidateBrand(): Promise<void>;
104
- declare function revalidateLocations(): Promise<void>;
105
- declare function revalidateLocation(id: string): Promise<void>;
106
- declare function revalidatePricing(): Promise<void>;
107
- declare function revalidateAddOns(): Promise<void>;
108
- declare function revalidateAddOn(id: string): Promise<void>;
109
- declare function revalidateSubscriptions(): Promise<void>;
110
- declare function revalidateSubscription(id: string): Promise<void>;
111
- declare function revalidateStock(productId?: string): Promise<void>;
102
+ declare function revalidateProduct(id: string, profile?: RevalidateProfile$1): Promise<void>;
103
+ declare function revalidateCategories(profile?: RevalidateProfile$1): Promise<void>;
104
+ declare function revalidateCategory(id: string, profile?: RevalidateProfile$1): Promise<void>;
105
+ declare function revalidateCollections(profile?: RevalidateProfile$1): Promise<void>;
106
+ declare function revalidateCollection(id: string, profile?: RevalidateProfile$1): Promise<void>;
107
+ declare function revalidateBusiness(profile?: RevalidateProfile$1): Promise<void>;
108
+ declare function revalidateBrand(profile?: RevalidateProfile$1): Promise<void>;
109
+ declare function revalidateLocations(profile?: RevalidateProfile$1): Promise<void>;
110
+ declare function revalidateLocation(id: string, profile?: RevalidateProfile$1): Promise<void>;
111
+ declare function revalidatePricing(profile?: RevalidateProfile$1): Promise<void>;
112
+ declare function revalidateAddOns(profile?: RevalidateProfile$1): Promise<void>;
113
+ declare function revalidateAddOn(id: string, profile?: RevalidateProfile$1): Promise<void>;
114
+ declare function revalidateSubscriptions(profile?: RevalidateProfile$1): Promise<void>;
115
+ declare function revalidateSubscription(id: string, profile?: RevalidateProfile$1): Promise<void>;
116
+ declare function revalidateStock(productId?: string, profile?: RevalidateProfile$1): Promise<void>;
112
117
  /**
113
118
  * Escape hatch: invalidate by raw tag string. Prefer the typed helpers
114
119
  * above where possible — they keep the tag scheme in one place.
115
120
  */
116
- declare function revalidateByTag(tag: string): Promise<void>;
121
+ declare function revalidateByTag(tag: string, profile?: RevalidateProfile$1): Promise<void>;
117
122
 
123
+ /** Expire the products list with read-your-writes. Call from a Server Action that creates / deletes / reorders. */
124
+ declare function updateProducts(): Promise<void>;
125
+ /** Expire a single product + the products list with read-your-writes. */
126
+ declare function updateProduct(id: string): Promise<void>;
127
+ declare function updateCategories(): Promise<void>;
128
+ declare function updateCategory(id: string): Promise<void>;
129
+ declare function updateCollections(): Promise<void>;
130
+ declare function updateCollection(id: string): Promise<void>;
131
+ declare function updateBusiness(): Promise<void>;
132
+ declare function updateBrand(): Promise<void>;
133
+ declare function updateLocations(): Promise<void>;
134
+ declare function updateLocation(id: string): Promise<void>;
135
+ declare function updatePricing(): Promise<void>;
136
+ declare function updateAddOns(): Promise<void>;
137
+ declare function updateAddOn(id: string): Promise<void>;
138
+ declare function updateSubscriptions(): Promise<void>;
139
+ declare function updateSubscription(id: string): Promise<void>;
140
+ declare function updateStock(productId?: string): Promise<void>;
141
+ /** Escape hatch: expire a raw tag with read-your-writes. Prefer the typed helpers above. */
142
+ declare function updateByTag(tag: string): Promise<void>;
143
+ /**
144
+ * Refresh uncached data on the current page (notification counts, live
145
+ * metrics, status indicators). Server-Action-only. Complements
146
+ * `router.refresh()` on the client.
147
+ */
148
+ declare function refreshPage(): Promise<void>;
149
+
150
+ /** Next 16 `revalidateTag` profile arg — built-in name (`'max'`/`'hours'`/…) or inline `{expire: secs}`. */
151
+ type RevalidateProfile = string | {
152
+ expire: number;
153
+ };
118
154
  interface RevalidateRouteOptions {
119
155
  secret?: string;
120
- revalidateTag?: (tag: string) => void;
156
+ revalidateTag?: (tag: string, profile: RevalidateProfile) => void;
121
157
  now?: () => number;
158
+ defaultProfile?: RevalidateProfile;
122
159
  }
123
160
  declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
124
161
 
125
- export { CimplifyClient, type RevalidateRouteOptions, type ServerClientOptions, getServerClient, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags };
162
+ export { 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 };
package/dist/server.js CHANGED
@@ -59,6 +59,7 @@ var tags = {
59
59
  };
60
60
 
61
61
  // src/server/revalidate.ts
62
+ var DEFAULT_PROFILE = "max";
62
63
  var _revalidateTag = null;
63
64
  async function getRevalidateTag() {
64
65
  if (_revalidateTag) return _revalidateTag;
@@ -71,64 +72,156 @@ async function getRevalidateTag() {
71
72
  _revalidateTag = mod.revalidateTag;
72
73
  return _revalidateTag;
73
74
  }
74
- async function revalidate(...tagList) {
75
+ async function revalidate(profile, ...tagList) {
75
76
  const fn = await getRevalidateTag();
76
- for (const t of tagList) fn(t);
77
+ for (const t of tagList) fn(t, profile);
77
78
  }
78
- async function revalidateProducts() {
79
- return revalidate(tags.products());
79
+ async function revalidateProducts(profile = DEFAULT_PROFILE) {
80
+ return revalidate(profile, tags.products());
80
81
  }
81
- async function revalidateProduct(id) {
82
- return revalidate(tags.product(id), tags.products());
82
+ async function revalidateProduct(id, profile = DEFAULT_PROFILE) {
83
+ return revalidate(profile, tags.product(id), tags.products());
83
84
  }
84
- async function revalidateCategories() {
85
- return revalidate(tags.categories());
85
+ async function revalidateCategories(profile = DEFAULT_PROFILE) {
86
+ return revalidate(profile, tags.categories());
86
87
  }
87
- async function revalidateCategory(id) {
88
- return revalidate(tags.category(id), tags.categoryProducts(id), tags.categories());
88
+ async function revalidateCategory(id, profile = DEFAULT_PROFILE) {
89
+ return revalidate(profile, tags.category(id), tags.categoryProducts(id), tags.categories());
89
90
  }
90
- async function revalidateCollections() {
91
- return revalidate(tags.collections());
91
+ async function revalidateCollections(profile = DEFAULT_PROFILE) {
92
+ return revalidate(profile, tags.collections());
92
93
  }
93
- async function revalidateCollection(id) {
94
+ async function revalidateCollection(id, profile = DEFAULT_PROFILE) {
94
95
  return revalidate(
96
+ profile,
95
97
  tags.collection(id),
96
98
  tags.collectionProducts(id),
97
99
  tags.collections()
98
100
  );
99
101
  }
100
- async function revalidateBusiness() {
101
- return revalidate(tags.business());
102
+ async function revalidateBusiness(profile = DEFAULT_PROFILE) {
103
+ return revalidate(profile, tags.business());
102
104
  }
103
- async function revalidateBrand() {
104
- return revalidate(tags.brand());
105
+ async function revalidateBrand(profile = DEFAULT_PROFILE) {
106
+ return revalidate(profile, tags.brand());
105
107
  }
106
- async function revalidateLocations() {
107
- return revalidate(tags.locations());
108
+ async function revalidateLocations(profile = DEFAULT_PROFILE) {
109
+ return revalidate(profile, tags.locations());
108
110
  }
109
- async function revalidateLocation(id) {
110
- return revalidate(tags.location(id), tags.locations());
111
+ async function revalidateLocation(id, profile = DEFAULT_PROFILE) {
112
+ return revalidate(profile, tags.location(id), tags.locations());
111
113
  }
112
- async function revalidatePricing() {
113
- return revalidate(tags.pricing(), tags.products());
114
+ async function revalidatePricing(profile = DEFAULT_PROFILE) {
115
+ return revalidate(profile, tags.pricing(), tags.products());
114
116
  }
115
- async function revalidateAddOns() {
116
- return revalidate(tags.addons());
117
+ async function revalidateAddOns(profile = DEFAULT_PROFILE) {
118
+ return revalidate(profile, tags.addons());
117
119
  }
118
- async function revalidateAddOn(id) {
119
- return revalidate(tags.addon(id), tags.addons());
120
+ async function revalidateAddOn(id, profile = DEFAULT_PROFILE) {
121
+ return revalidate(profile, tags.addon(id), tags.addons());
120
122
  }
121
- async function revalidateSubscriptions() {
122
- return revalidate(tags.subscriptions());
123
+ async function revalidateSubscriptions(profile = DEFAULT_PROFILE) {
124
+ return revalidate(profile, tags.subscriptions());
123
125
  }
124
- async function revalidateSubscription(id) {
125
- return revalidate(tags.subscription(id), tags.subscriptions());
126
+ async function revalidateSubscription(id, profile = DEFAULT_PROFILE) {
127
+ return revalidate(profile, tags.subscription(id), tags.subscriptions());
126
128
  }
127
- async function revalidateStock(productId) {
128
- return productId ? revalidate(tags.stockFor(productId), tags.stock()) : revalidate(tags.stock());
129
+ async function revalidateStock(productId, profile = DEFAULT_PROFILE) {
130
+ return productId ? revalidate(profile, tags.stockFor(productId), tags.stock()) : revalidate(profile, tags.stock());
129
131
  }
130
- async function revalidateByTag(tag) {
131
- return revalidate(tag);
132
+ async function revalidateByTag(tag, profile = DEFAULT_PROFILE) {
133
+ return revalidate(profile, tag);
134
+ }
135
+
136
+ // src/server/update.ts
137
+ var _updateTag = null;
138
+ var _refresh = null;
139
+ async function getUpdateTag() {
140
+ if (_updateTag) return _updateTag;
141
+ const specifier = "next/cache";
142
+ const mod = await import(
143
+ /* webpackIgnore: true */
144
+ /* @vite-ignore */
145
+ specifier
146
+ );
147
+ if (!mod.updateTag) {
148
+ throw new Error("updateTag is not exported from next/cache \u2014 requires Next 16+");
149
+ }
150
+ _updateTag = mod.updateTag;
151
+ return _updateTag;
152
+ }
153
+ async function getRefresh() {
154
+ if (_refresh) return _refresh;
155
+ const specifier = "next/cache";
156
+ const mod = await import(
157
+ /* webpackIgnore: true */
158
+ /* @vite-ignore */
159
+ specifier
160
+ );
161
+ if (!mod.refresh) {
162
+ throw new Error("refresh is not exported from next/cache \u2014 requires Next 16+");
163
+ }
164
+ _refresh = mod.refresh;
165
+ return _refresh;
166
+ }
167
+ async function update(...tagList) {
168
+ const fn = await getUpdateTag();
169
+ for (const t of tagList) fn(t);
170
+ }
171
+ async function updateProducts() {
172
+ return update(tags.products());
173
+ }
174
+ async function updateProduct(id) {
175
+ return update(tags.product(id), tags.products());
176
+ }
177
+ async function updateCategories() {
178
+ return update(tags.categories());
179
+ }
180
+ async function updateCategory(id) {
181
+ return update(tags.category(id), tags.categoryProducts(id), tags.categories());
182
+ }
183
+ async function updateCollections() {
184
+ return update(tags.collections());
185
+ }
186
+ async function updateCollection(id) {
187
+ return update(tags.collection(id), tags.collectionProducts(id), tags.collections());
188
+ }
189
+ async function updateBusiness() {
190
+ return update(tags.business());
191
+ }
192
+ async function updateBrand() {
193
+ return update(tags.brand());
194
+ }
195
+ async function updateLocations() {
196
+ return update(tags.locations());
197
+ }
198
+ async function updateLocation(id) {
199
+ return update(tags.location(id), tags.locations());
200
+ }
201
+ async function updatePricing() {
202
+ return update(tags.pricing(), tags.products());
203
+ }
204
+ async function updateAddOns() {
205
+ return update(tags.addons());
206
+ }
207
+ async function updateAddOn(id) {
208
+ return update(tags.addon(id), tags.addons());
209
+ }
210
+ async function updateSubscriptions() {
211
+ return update(tags.subscriptions());
212
+ }
213
+ async function updateSubscription(id) {
214
+ return update(tags.subscription(id), tags.subscriptions());
215
+ }
216
+ async function updateStock(productId) {
217
+ return productId ? update(tags.stockFor(productId), tags.stock()) : update(tags.stock());
218
+ }
219
+ async function updateByTag(tag) {
220
+ return update(tag);
221
+ }
222
+ async function refreshPage() {
223
+ const fn = await getRefresh();
224
+ fn();
132
225
  }
133
226
 
134
227
  // src/server/revalidate-route.ts
@@ -137,6 +230,7 @@ var SIGNATURE_HEADER = "x-cimplify-signature";
137
230
  var SIGNATURE_PREFIX = "sha256=";
138
231
  var MAX_SKEW_MS = 5 * 60 * 1e3;
139
232
  var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
233
+ var DEFAULT_PROFILE2 = "max";
140
234
  async function revalidateRouteHandler(req, options = {}) {
141
235
  const secret = options.secret ?? envSecret();
142
236
  if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
@@ -160,9 +254,17 @@ async function revalidateRouteHandler(req, options = {}) {
160
254
  }
161
255
  const tags2 = Array.isArray(parsed.tags) ? parsed.tags.filter((t) => typeof t === "string" && t.length > 0) : [];
162
256
  if (tags2.length === 0) return text("no tags", 400);
257
+ const profile = parseProfile(parsed.profile) ?? options.defaultProfile ?? DEFAULT_PROFILE2;
163
258
  const revalidate2 = options.revalidateTag ?? await loadRevalidateTag();
164
- for (const tag of tags2) revalidate2(tag);
165
- return Response.json({ ok: true, revalidated: tags2.length });
259
+ for (const tag of tags2) revalidate2(tag, profile);
260
+ return Response.json({ ok: true, revalidated: tags2.length, profile });
261
+ }
262
+ function parseProfile(raw) {
263
+ if (typeof raw === "string" && raw.length > 0) return raw;
264
+ if (raw && typeof raw === "object" && "expire" in raw && typeof raw.expire === "number") {
265
+ return { expire: raw.expire };
266
+ }
267
+ return void 0;
166
268
  }
167
269
  var cachedRevalidateTag = null;
168
270
  async function loadRevalidateTag() {
@@ -212,6 +314,7 @@ Object.defineProperty(exports, "CimplifyError", {
212
314
  get: function () { return chunkTKOTACKZ_js.CimplifyError; }
213
315
  });
214
316
  exports.getServerClient = getServerClient;
317
+ exports.refreshPage = refreshPage;
215
318
  exports.revalidateAddOn = revalidateAddOn;
216
319
  exports.revalidateAddOns = revalidateAddOns;
217
320
  exports.revalidateBrand = revalidateBrand;
@@ -231,3 +334,20 @@ exports.revalidateStock = revalidateStock;
231
334
  exports.revalidateSubscription = revalidateSubscription;
232
335
  exports.revalidateSubscriptions = revalidateSubscriptions;
233
336
  exports.tags = tags;
337
+ exports.updateAddOn = updateAddOn;
338
+ exports.updateAddOns = updateAddOns;
339
+ exports.updateBrand = updateBrand;
340
+ exports.updateBusiness = updateBusiness;
341
+ exports.updateByTag = updateByTag;
342
+ exports.updateCategories = updateCategories;
343
+ exports.updateCategory = updateCategory;
344
+ exports.updateCollection = updateCollection;
345
+ exports.updateCollections = updateCollections;
346
+ exports.updateLocation = updateLocation;
347
+ exports.updateLocations = updateLocations;
348
+ exports.updatePricing = updatePricing;
349
+ exports.updateProduct = updateProduct;
350
+ exports.updateProducts = updateProducts;
351
+ exports.updateStock = updateStock;
352
+ exports.updateSubscription = updateSubscription;
353
+ exports.updateSubscriptions = updateSubscriptions;
package/dist/server.mjs CHANGED
@@ -57,6 +57,7 @@ var tags = {
57
57
  };
58
58
 
59
59
  // src/server/revalidate.ts
60
+ var DEFAULT_PROFILE = "max";
60
61
  var _revalidateTag = null;
61
62
  async function getRevalidateTag() {
62
63
  if (_revalidateTag) return _revalidateTag;
@@ -69,64 +70,156 @@ async function getRevalidateTag() {
69
70
  _revalidateTag = mod.revalidateTag;
70
71
  return _revalidateTag;
71
72
  }
72
- async function revalidate(...tagList) {
73
+ async function revalidate(profile, ...tagList) {
73
74
  const fn = await getRevalidateTag();
74
- for (const t of tagList) fn(t);
75
+ for (const t of tagList) fn(t, profile);
75
76
  }
76
- async function revalidateProducts() {
77
- return revalidate(tags.products());
77
+ async function revalidateProducts(profile = DEFAULT_PROFILE) {
78
+ return revalidate(profile, tags.products());
78
79
  }
79
- async function revalidateProduct(id) {
80
- return revalidate(tags.product(id), tags.products());
80
+ async function revalidateProduct(id, profile = DEFAULT_PROFILE) {
81
+ return revalidate(profile, tags.product(id), tags.products());
81
82
  }
82
- async function revalidateCategories() {
83
- return revalidate(tags.categories());
83
+ async function revalidateCategories(profile = DEFAULT_PROFILE) {
84
+ return revalidate(profile, tags.categories());
84
85
  }
85
- async function revalidateCategory(id) {
86
- return revalidate(tags.category(id), tags.categoryProducts(id), tags.categories());
86
+ async function revalidateCategory(id, profile = DEFAULT_PROFILE) {
87
+ return revalidate(profile, tags.category(id), tags.categoryProducts(id), tags.categories());
87
88
  }
88
- async function revalidateCollections() {
89
- return revalidate(tags.collections());
89
+ async function revalidateCollections(profile = DEFAULT_PROFILE) {
90
+ return revalidate(profile, tags.collections());
90
91
  }
91
- async function revalidateCollection(id) {
92
+ async function revalidateCollection(id, profile = DEFAULT_PROFILE) {
92
93
  return revalidate(
94
+ profile,
93
95
  tags.collection(id),
94
96
  tags.collectionProducts(id),
95
97
  tags.collections()
96
98
  );
97
99
  }
98
- async function revalidateBusiness() {
99
- return revalidate(tags.business());
100
+ async function revalidateBusiness(profile = DEFAULT_PROFILE) {
101
+ return revalidate(profile, tags.business());
100
102
  }
101
- async function revalidateBrand() {
102
- return revalidate(tags.brand());
103
+ async function revalidateBrand(profile = DEFAULT_PROFILE) {
104
+ return revalidate(profile, tags.brand());
103
105
  }
104
- async function revalidateLocations() {
105
- return revalidate(tags.locations());
106
+ async function revalidateLocations(profile = DEFAULT_PROFILE) {
107
+ return revalidate(profile, tags.locations());
106
108
  }
107
- async function revalidateLocation(id) {
108
- return revalidate(tags.location(id), tags.locations());
109
+ async function revalidateLocation(id, profile = DEFAULT_PROFILE) {
110
+ return revalidate(profile, tags.location(id), tags.locations());
109
111
  }
110
- async function revalidatePricing() {
111
- return revalidate(tags.pricing(), tags.products());
112
+ async function revalidatePricing(profile = DEFAULT_PROFILE) {
113
+ return revalidate(profile, tags.pricing(), tags.products());
112
114
  }
113
- async function revalidateAddOns() {
114
- return revalidate(tags.addons());
115
+ async function revalidateAddOns(profile = DEFAULT_PROFILE) {
116
+ return revalidate(profile, tags.addons());
115
117
  }
116
- async function revalidateAddOn(id) {
117
- return revalidate(tags.addon(id), tags.addons());
118
+ async function revalidateAddOn(id, profile = DEFAULT_PROFILE) {
119
+ return revalidate(profile, tags.addon(id), tags.addons());
118
120
  }
119
- async function revalidateSubscriptions() {
120
- return revalidate(tags.subscriptions());
121
+ async function revalidateSubscriptions(profile = DEFAULT_PROFILE) {
122
+ return revalidate(profile, tags.subscriptions());
121
123
  }
122
- async function revalidateSubscription(id) {
123
- return revalidate(tags.subscription(id), tags.subscriptions());
124
+ async function revalidateSubscription(id, profile = DEFAULT_PROFILE) {
125
+ return revalidate(profile, tags.subscription(id), tags.subscriptions());
124
126
  }
125
- async function revalidateStock(productId) {
126
- return productId ? revalidate(tags.stockFor(productId), tags.stock()) : revalidate(tags.stock());
127
+ async function revalidateStock(productId, profile = DEFAULT_PROFILE) {
128
+ return productId ? revalidate(profile, tags.stockFor(productId), tags.stock()) : revalidate(profile, tags.stock());
127
129
  }
128
- async function revalidateByTag(tag) {
129
- return revalidate(tag);
130
+ async function revalidateByTag(tag, profile = DEFAULT_PROFILE) {
131
+ return revalidate(profile, tag);
132
+ }
133
+
134
+ // src/server/update.ts
135
+ var _updateTag = null;
136
+ var _refresh = null;
137
+ async function getUpdateTag() {
138
+ if (_updateTag) return _updateTag;
139
+ const specifier = "next/cache";
140
+ const mod = await import(
141
+ /* webpackIgnore: true */
142
+ /* @vite-ignore */
143
+ specifier
144
+ );
145
+ if (!mod.updateTag) {
146
+ throw new Error("updateTag is not exported from next/cache \u2014 requires Next 16+");
147
+ }
148
+ _updateTag = mod.updateTag;
149
+ return _updateTag;
150
+ }
151
+ async function getRefresh() {
152
+ if (_refresh) return _refresh;
153
+ const specifier = "next/cache";
154
+ const mod = await import(
155
+ /* webpackIgnore: true */
156
+ /* @vite-ignore */
157
+ specifier
158
+ );
159
+ if (!mod.refresh) {
160
+ throw new Error("refresh is not exported from next/cache \u2014 requires Next 16+");
161
+ }
162
+ _refresh = mod.refresh;
163
+ return _refresh;
164
+ }
165
+ async function update(...tagList) {
166
+ const fn = await getUpdateTag();
167
+ for (const t of tagList) fn(t);
168
+ }
169
+ async function updateProducts() {
170
+ return update(tags.products());
171
+ }
172
+ async function updateProduct(id) {
173
+ return update(tags.product(id), tags.products());
174
+ }
175
+ async function updateCategories() {
176
+ return update(tags.categories());
177
+ }
178
+ async function updateCategory(id) {
179
+ return update(tags.category(id), tags.categoryProducts(id), tags.categories());
180
+ }
181
+ async function updateCollections() {
182
+ return update(tags.collections());
183
+ }
184
+ async function updateCollection(id) {
185
+ return update(tags.collection(id), tags.collectionProducts(id), tags.collections());
186
+ }
187
+ async function updateBusiness() {
188
+ return update(tags.business());
189
+ }
190
+ async function updateBrand() {
191
+ return update(tags.brand());
192
+ }
193
+ async function updateLocations() {
194
+ return update(tags.locations());
195
+ }
196
+ async function updateLocation(id) {
197
+ return update(tags.location(id), tags.locations());
198
+ }
199
+ async function updatePricing() {
200
+ return update(tags.pricing(), tags.products());
201
+ }
202
+ async function updateAddOns() {
203
+ return update(tags.addons());
204
+ }
205
+ async function updateAddOn(id) {
206
+ return update(tags.addon(id), tags.addons());
207
+ }
208
+ async function updateSubscriptions() {
209
+ return update(tags.subscriptions());
210
+ }
211
+ async function updateSubscription(id) {
212
+ return update(tags.subscription(id), tags.subscriptions());
213
+ }
214
+ async function updateStock(productId) {
215
+ return productId ? update(tags.stockFor(productId), tags.stock()) : update(tags.stock());
216
+ }
217
+ async function updateByTag(tag) {
218
+ return update(tag);
219
+ }
220
+ async function refreshPage() {
221
+ const fn = await getRefresh();
222
+ fn();
130
223
  }
131
224
 
132
225
  // src/server/revalidate-route.ts
@@ -135,6 +228,7 @@ var SIGNATURE_HEADER = "x-cimplify-signature";
135
228
  var SIGNATURE_PREFIX = "sha256=";
136
229
  var MAX_SKEW_MS = 5 * 60 * 1e3;
137
230
  var SECRET_ENV = "CIMPLIFY_REVALIDATE_SECRET";
231
+ var DEFAULT_PROFILE2 = "max";
138
232
  async function revalidateRouteHandler(req, options = {}) {
139
233
  const secret = options.secret ?? envSecret();
140
234
  if (!secret) return text(`revalidate disabled: ${SECRET_ENV} not set`, 500);
@@ -158,9 +252,17 @@ async function revalidateRouteHandler(req, options = {}) {
158
252
  }
159
253
  const tags2 = Array.isArray(parsed.tags) ? parsed.tags.filter((t) => typeof t === "string" && t.length > 0) : [];
160
254
  if (tags2.length === 0) return text("no tags", 400);
255
+ const profile = parseProfile(parsed.profile) ?? options.defaultProfile ?? DEFAULT_PROFILE2;
161
256
  const revalidate2 = options.revalidateTag ?? await loadRevalidateTag();
162
- for (const tag of tags2) revalidate2(tag);
163
- return Response.json({ ok: true, revalidated: tags2.length });
257
+ for (const tag of tags2) revalidate2(tag, profile);
258
+ return Response.json({ ok: true, revalidated: tags2.length, profile });
259
+ }
260
+ function parseProfile(raw) {
261
+ if (typeof raw === "string" && raw.length > 0) return raw;
262
+ if (raw && typeof raw === "object" && "expire" in raw && typeof raw.expire === "number") {
263
+ return { expire: raw.expire };
264
+ }
265
+ return void 0;
164
266
  }
165
267
  var cachedRevalidateTag = null;
166
268
  async function loadRevalidateTag() {
@@ -205,4 +307,4 @@ function text(message, status) {
205
307
  return new Response(message, { status, headers: { "content-type": "text/plain" } });
206
308
  }
207
309
 
208
- export { getServerClient, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags };
310
+ export { 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cimplify/sdk",
3
- "version": "0.49.0",
3
+ "version": "0.49.1",
4
4
  "description": "Cimplify Commerce SDK for storefronts",
5
5
  "keywords": [
6
6
  "cimplify",