@rebuy/rebuy 3.33.0 → 3.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ Node `^22.14.0 || ^24.10.0 || ^26.0.0` for development; the published artifacts
17
17
  | Subpath | Contents |
18
18
  | --- | --- |
19
19
  | `@rebuy/rebuy` | Root barrel: schemas, client helpers, utilities |
20
- | `@rebuy/rebuy/cab` | zod-free CAB renderer helpers shared by every renderer (`contentText`, `tiptapPlainText`, `tiptapRuns`, `asLayout`, `idFromGid`, `toCents`, `decoratedOrderId`, `reviewStars`) |
20
+ | `@rebuy/rebuy/cab` | zod-free CAB renderer helpers shared by every renderer (`contentText`, `tiptapPlainText`, `tiptapRuns`, `asLayout`, `idFromGid`, `toCents`, `decoratedOrderId`, `reviewStars`, `utf8ByteLength`) |
21
21
  | `@rebuy/rebuy/client` | `RebuyClient` API client |
22
22
  | `@rebuy/rebuy/gwp` | Gift-with-purchase validation helpers |
23
23
  | `@rebuy/rebuy/pricing` | Variant pricing/discount forecast (`priceVariant`, `currencyDecimals`) |
@@ -30,7 +30,8 @@ __export(cab_exports, {
30
30
  selectLanguage: () => selectLanguage,
31
31
  tiptapPlainText: () => tiptapPlainText,
32
32
  tiptapRuns: () => tiptapRuns,
33
- toCents: () => toCents
33
+ toCents: () => toCents,
34
+ utf8ByteLength: () => utf8ByteLength
34
35
  });
35
36
  module.exports = __toCommonJS(cab_exports);
36
37
 
@@ -204,3 +205,13 @@ var tiptapRuns = (paragraph, variables) => {
204
205
 
205
206
  // src/cab/toCents.ts
206
207
  var toCents = (amount) => Math.round(Number(amount ?? 0) * 100);
208
+
209
+ // src/cab/utf8ByteLength.ts
210
+ var utf8ByteLength = (value) => {
211
+ let bytes = 0;
212
+ for (const character of value) {
213
+ const code = character.codePointAt(0);
214
+ bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
215
+ }
216
+ return bytes;
217
+ };
@@ -8,3 +8,4 @@ export * from '../cab/selectLanguage';
8
8
  export * from '../cab/tiptapPlain';
9
9
  export * from '../cab/tiptapRuns';
10
10
  export * from '../cab/toCents';
11
+ export * from '../cab/utf8ByteLength';
@@ -168,6 +168,16 @@ var tiptapRuns = (paragraph, variables) => {
168
168
 
169
169
  // src/cab/toCents.ts
170
170
  var toCents = (amount) => Math.round(Number(amount ?? 0) * 100);
171
+
172
+ // src/cab/utf8ByteLength.ts
173
+ var utf8ByteLength = (value) => {
174
+ let bytes = 0;
175
+ for (const character of value) {
176
+ const code = character.codePointAt(0);
177
+ bytes += code < 128 ? 1 : code < 2048 ? 2 : code < 65536 ? 3 : 4;
178
+ }
179
+ return bytes;
180
+ };
171
181
  export {
172
182
  asLayout,
173
183
  contentText,
@@ -179,5 +189,6 @@ export {
179
189
  selectLanguage,
180
190
  tiptapPlainText,
181
191
  tiptapRuns,
182
- toCents
192
+ toCents,
193
+ utf8ByteLength
183
194
  };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The UTF-8 encoded size of a string in bytes — what a body limit such as rebuy-api's 64 KiB shadow cap
3
+ * counts — without `TextEncoder`, which a renderer's sandbox (Shopify's post-purchase worker) may not
4
+ * provide. An unpaired surrogate counts as the 3-byte U+FFFD replacement `TextEncoder` would emit.
5
+ */
6
+ export declare const utf8ByteLength: (value: string) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebuy/rebuy",
3
- "version": "3.33.0",
3
+ "version": "3.34.0",
4
4
  "description": "Shared zod schemas, legacy-to-CAB widget transforms, and server orchestrators for Rebuy's Shopify consumers (rebuy-api, admin-nextjs, rebuy-shopify-extensions)",
5
5
  "license": "MIT",
6
6
  "author": "Rebuy, Inc.",