@uniformdev/next-app-router-shared 20.53.1 → 20.54.1-alpha.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/index.d.mts CHANGED
@@ -79,8 +79,9 @@ declare const resolveRuleFromPageState: ({ pageState, rule, }: {
79
79
  pageState: PageState;
80
80
  rule: VisibilityParameterValue;
81
81
  }) => boolean | undefined;
82
- declare const serializeEvaluationResult: ({ payload, encode, }: {
82
+ declare const serializeEvaluationResult: ({ payload, }: {
83
83
  payload: PageState;
84
+ /** @deprecated No longer needed — v2 format is URL-safe by default. */
84
85
  encode?: boolean;
85
86
  }) => string;
86
87
  declare const deserializeEvaluationResult: ({ input: providedInput, decode, }: {
package/dist/index.d.ts CHANGED
@@ -79,8 +79,9 @@ declare const resolveRuleFromPageState: ({ pageState, rule, }: {
79
79
  pageState: PageState;
80
80
  rule: VisibilityParameterValue;
81
81
  }) => boolean | undefined;
82
- declare const serializeEvaluationResult: ({ payload, encode, }: {
82
+ declare const serializeEvaluationResult: ({ payload, }: {
83
83
  payload: PageState;
84
+ /** @deprecated No longer needed — v2 format is URL-safe by default. */
84
85
  encode?: boolean;
85
86
  }) => string;
86
87
  declare const deserializeEvaluationResult: ({ input: providedInput, decode, }: {
package/dist/index.esm.js CHANGED
@@ -160,23 +160,11 @@ var resolveRuleFromPageState = ({
160
160
  }
161
161
  return value;
162
162
  };
163
- var replaceReservedCharacters = (value) => {
164
- return ENCODED_RESERVED_CHARACTERS.reduce((acc, char) => {
165
- return acc.replaceAll(char.character, char.replacement);
166
- }, value);
167
- };
168
163
  var unreplaceReservedCharacters = (value) => {
169
164
  return ENCODED_RESERVED_CHARACTERS.reduce((acc, char) => {
170
165
  return acc.replaceAll(char.replacement, char.character);
171
166
  }, value);
172
167
  };
173
- var encodeWithReplacements = (value) => {
174
- return replaceReservedCharacters(btoa(value));
175
- };
176
- var decodeWithReplacements = (value) => {
177
- const urlDecoded = decodeURIComponent(value);
178
- return atob(unreplaceReservedCharacters(urlDecoded));
179
- };
180
168
  var compressIds = (ids) => {
181
169
  const uuidV4Length = 36;
182
170
  let compressedRegistry;
@@ -206,22 +194,58 @@ var compressIds = (ids) => {
206
194
  );
207
195
  };
208
196
  var NAMESPACE_UUID = "00000000-0000-0000-0000-000000000000";
209
- var serializeEvaluationResult = ({
210
- payload,
211
- encode = true
212
- }) => {
213
- const compressedPageState = {
214
- cs: payload.compositionState,
215
- r: payload.routePath,
216
- c: {},
217
- k: payload.keys,
218
- ri: payload.releaseId,
219
- dc: typeof payload.defaultConsent !== "undefined" ? payload.defaultConsent ? 1 : 0 : void 0,
220
- pm: payload.previewMode === "editor" ? "e" : payload.previewMode === "preview" ? "p" : void 0,
221
- rl: void 0,
222
- l: payload.locale,
223
- pf: payload.isPrefetch ? 1 : void 0
197
+ var V2_FIELD_SEP = "~";
198
+ var V2_ENTRY_SEP = ".";
199
+ var V2_KV_SEP = ":";
200
+ var V2_INDEX_SEP = ",";
201
+ var toBase64Url = (value) => {
202
+ const bytes = new TextEncoder().encode(value);
203
+ const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join("");
204
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
205
+ };
206
+ var fromBase64Url = (value) => {
207
+ let base64 = value.replace(/-/g, "+").replace(/_/g, "/");
208
+ const pad = base64.length % 4;
209
+ if (pad === 2) {
210
+ base64 += "==";
211
+ } else if (pad === 3) {
212
+ base64 += "=";
213
+ }
214
+ const binary = atob(base64);
215
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
216
+ return new TextDecoder().decode(bytes);
217
+ };
218
+ var encodeFlags = (payload) => {
219
+ let flags = 0;
220
+ if (typeof payload.defaultConsent !== "undefined") {
221
+ flags |= 1;
222
+ if (payload.defaultConsent) {
223
+ flags |= 2;
224
+ }
225
+ }
226
+ if (payload.previewMode === "editor") {
227
+ flags |= 4;
228
+ }
229
+ if (payload.previewMode === "preview") {
230
+ flags |= 8;
231
+ }
232
+ if (payload.isPrefetch) {
233
+ flags |= 16;
234
+ }
235
+ return flags.toString(16);
236
+ };
237
+ var decodeFlags = (hex) => {
238
+ const flags = parseInt(hex, 16) || 0;
239
+ return {
240
+ defaultConsent: flags & 1 ? Boolean(flags & 2) : void 0,
241
+ previewMode: flags & 4 ? "editor" : flags & 8 ? "preview" : void 0,
242
+ isPrefetch: flags & 16 ? true : void 0
224
243
  };
244
+ };
245
+ var serializeV2 = (payload) => {
246
+ const parts = ["2"];
247
+ parts.push(String(payload.compositionState));
248
+ parts.push(toBase64Url(payload.routePath));
225
249
  const componentKeys = Object.keys(payload.components);
226
250
  const sortedKeys = componentKeys.sort();
227
251
  const sortedComponents = sortedKeys.map((key) => ({
@@ -229,6 +253,7 @@ var serializeEvaluationResult = ({
229
253
  ...payload.components[key]
230
254
  }));
231
255
  const compressedComponentIds = compressIds(sortedComponents.map((c) => c._id));
256
+ const componentEntries = [];
232
257
  Object.keys(compressedComponentIds).forEach((compressedId) => {
233
258
  var _a;
234
259
  const originalId = compressedComponentIds[compressedId];
@@ -236,32 +261,117 @@ var serializeEvaluationResult = ({
236
261
  if (!component) {
237
262
  throw new Error(`Component ${originalId} not found`);
238
263
  }
239
- compressedPageState.c[compressedId] = {
240
- i: ((_a = component.indexes) == null ? void 0 : _a.length) ? component.indexes : void 0
241
- };
264
+ const indexes = ((_a = component.indexes) == null ? void 0 : _a.length) ? component.indexes : void 0;
265
+ if (indexes) {
266
+ componentEntries.push(`${compressedId}${V2_KV_SEP}${indexes.join(V2_INDEX_SEP)}`);
267
+ } else {
268
+ componentEntries.push(compressedId);
269
+ }
242
270
  });
271
+ parts.push(componentEntries.join(V2_ENTRY_SEP));
272
+ let rulesStr = "";
243
273
  if (typeof payload.rules !== "undefined") {
244
274
  const ruleKeys = Object.keys(payload.rules);
245
275
  if (ruleKeys.length !== 0) {
246
- compressedPageState.rl = {};
247
276
  const sortedRuleKeys = ruleKeys.sort();
248
277
  const compressedRuleKeys = compressIds(sortedRuleKeys);
278
+ const ruleEntries = [];
249
279
  Object.keys(compressedRuleKeys).forEach((compressedId) => {
250
280
  const originalId = compressedRuleKeys[compressedId];
251
- compressedPageState.rl[compressedId] = payload.rules[originalId] ? 1 : 0;
281
+ ruleEntries.push(`${compressedId}${V2_KV_SEP}${payload.rules[originalId] ? 1 : 0}`);
252
282
  });
283
+ rulesStr = ruleEntries.join(V2_ENTRY_SEP);
253
284
  }
254
285
  }
255
- const result = JSON.stringify(compressedPageState);
256
- return encode ? encodeWithReplacements(result) : result;
286
+ parts.push(rulesStr);
287
+ let keysStr = "";
288
+ if (payload.keys) {
289
+ const keyEntries = Object.entries(payload.keys).map(
290
+ ([k, v]) => `${toBase64Url(k)}${V2_KV_SEP}${toBase64Url(v)}`
291
+ );
292
+ keysStr = keyEntries.join(V2_ENTRY_SEP);
293
+ }
294
+ parts.push(keysStr);
295
+ parts.push(encodeFlags(payload));
296
+ parts.push(payload.releaseId ? toBase64Url(payload.releaseId) : "");
297
+ parts.push(payload.locale ? toBase64Url(payload.locale) : "");
298
+ return parts.join(V2_FIELD_SEP);
299
+ };
300
+ var deserializeV2 = (input) => {
301
+ var _a, _b, _c, _d;
302
+ const fields = input.split(V2_FIELD_SEP);
303
+ const compositionState = parseInt(fields[1], 10);
304
+ const routePath = fromBase64Url(fields[2]);
305
+ const components = {};
306
+ const componentsStr = (_a = fields[3]) != null ? _a : "";
307
+ if (componentsStr) {
308
+ componentsStr.split(V2_ENTRY_SEP).forEach((entry) => {
309
+ const sepIdx = entry.indexOf(V2_KV_SEP);
310
+ if (sepIdx === -1) {
311
+ components[entry] = {};
312
+ } else {
313
+ const id = entry.slice(0, sepIdx);
314
+ const indexes = entry.slice(sepIdx + 1).split(V2_INDEX_SEP).map(Number);
315
+ components[id] = { indexes };
316
+ }
317
+ });
318
+ }
319
+ const rulesStr = (_b = fields[4]) != null ? _b : "";
320
+ let rules;
321
+ if (rulesStr) {
322
+ rules = {};
323
+ rulesStr.split(V2_ENTRY_SEP).forEach((entry) => {
324
+ const sepIdx = entry.indexOf(V2_KV_SEP);
325
+ if (sepIdx !== -1) {
326
+ const id = entry.slice(0, sepIdx);
327
+ rules[id] = entry.slice(sepIdx + 1) === "1";
328
+ }
329
+ });
330
+ }
331
+ const keysStr = (_c = fields[5]) != null ? _c : "";
332
+ const keys = {};
333
+ if (keysStr) {
334
+ keysStr.split(V2_ENTRY_SEP).forEach((entry) => {
335
+ const sepIdx = entry.indexOf(V2_KV_SEP);
336
+ if (sepIdx !== -1) {
337
+ const k = fromBase64Url(entry.slice(0, sepIdx));
338
+ const v = fromBase64Url(entry.slice(sepIdx + 1));
339
+ keys[k] = v;
340
+ }
341
+ });
342
+ }
343
+ const { defaultConsent, previewMode, isPrefetch } = decodeFlags((_d = fields[6]) != null ? _d : "0");
344
+ const releaseId = fields[7] ? fromBase64Url(fields[7]) : void 0;
345
+ const locale = fields[8] ? fromBase64Url(fields[8]) : void 0;
346
+ return {
347
+ compositionState,
348
+ routePath,
349
+ components,
350
+ rules,
351
+ keys,
352
+ releaseId,
353
+ defaultConsent,
354
+ previewMode,
355
+ locale,
356
+ isPrefetch
357
+ };
358
+ };
359
+ var serializeEvaluationResult = ({
360
+ payload
361
+ }) => {
362
+ return serializeV2(payload);
257
363
  };
258
364
  var deserializeEvaluationResult = ({
259
365
  input: providedInput,
260
366
  decode = true
261
367
  }) => {
262
368
  var _a, _b, _c;
263
- const input = decode ? decodeWithReplacements(providedInput) : providedInput;
264
- const parsed = JSON.parse(input);
369
+ const input = decode ? decodeURIComponent(providedInput) : providedInput;
370
+ if (input.startsWith("2~")) {
371
+ return deserializeV2(input);
372
+ }
373
+ const jsonInput = decode ? atob(unreplaceReservedCharacters(input)) : input;
374
+ const parsed = JSON.parse(jsonInput);
265
375
  const pageState = {
266
376
  compositionState: parsed.cs,
267
377
  routePath: parsed.r,
package/dist/index.js CHANGED
@@ -195,23 +195,11 @@ var resolveRuleFromPageState = ({
195
195
  }
196
196
  return value;
197
197
  };
198
- var replaceReservedCharacters = (value) => {
199
- return ENCODED_RESERVED_CHARACTERS.reduce((acc, char) => {
200
- return acc.replaceAll(char.character, char.replacement);
201
- }, value);
202
- };
203
198
  var unreplaceReservedCharacters = (value) => {
204
199
  return ENCODED_RESERVED_CHARACTERS.reduce((acc, char) => {
205
200
  return acc.replaceAll(char.replacement, char.character);
206
201
  }, value);
207
202
  };
208
- var encodeWithReplacements = (value) => {
209
- return replaceReservedCharacters(btoa(value));
210
- };
211
- var decodeWithReplacements = (value) => {
212
- const urlDecoded = decodeURIComponent(value);
213
- return atob(unreplaceReservedCharacters(urlDecoded));
214
- };
215
203
  var compressIds = (ids) => {
216
204
  const uuidV4Length = 36;
217
205
  let compressedRegistry;
@@ -241,22 +229,58 @@ var compressIds = (ids) => {
241
229
  );
242
230
  };
243
231
  var NAMESPACE_UUID = "00000000-0000-0000-0000-000000000000";
244
- var serializeEvaluationResult = ({
245
- payload,
246
- encode = true
247
- }) => {
248
- const compressedPageState = {
249
- cs: payload.compositionState,
250
- r: payload.routePath,
251
- c: {},
252
- k: payload.keys,
253
- ri: payload.releaseId,
254
- dc: typeof payload.defaultConsent !== "undefined" ? payload.defaultConsent ? 1 : 0 : void 0,
255
- pm: payload.previewMode === "editor" ? "e" : payload.previewMode === "preview" ? "p" : void 0,
256
- rl: void 0,
257
- l: payload.locale,
258
- pf: payload.isPrefetch ? 1 : void 0
232
+ var V2_FIELD_SEP = "~";
233
+ var V2_ENTRY_SEP = ".";
234
+ var V2_KV_SEP = ":";
235
+ var V2_INDEX_SEP = ",";
236
+ var toBase64Url = (value) => {
237
+ const bytes = new TextEncoder().encode(value);
238
+ const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join("");
239
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
240
+ };
241
+ var fromBase64Url = (value) => {
242
+ let base64 = value.replace(/-/g, "+").replace(/_/g, "/");
243
+ const pad = base64.length % 4;
244
+ if (pad === 2) {
245
+ base64 += "==";
246
+ } else if (pad === 3) {
247
+ base64 += "=";
248
+ }
249
+ const binary = atob(base64);
250
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
251
+ return new TextDecoder().decode(bytes);
252
+ };
253
+ var encodeFlags = (payload) => {
254
+ let flags = 0;
255
+ if (typeof payload.defaultConsent !== "undefined") {
256
+ flags |= 1;
257
+ if (payload.defaultConsent) {
258
+ flags |= 2;
259
+ }
260
+ }
261
+ if (payload.previewMode === "editor") {
262
+ flags |= 4;
263
+ }
264
+ if (payload.previewMode === "preview") {
265
+ flags |= 8;
266
+ }
267
+ if (payload.isPrefetch) {
268
+ flags |= 16;
269
+ }
270
+ return flags.toString(16);
271
+ };
272
+ var decodeFlags = (hex) => {
273
+ const flags = parseInt(hex, 16) || 0;
274
+ return {
275
+ defaultConsent: flags & 1 ? Boolean(flags & 2) : void 0,
276
+ previewMode: flags & 4 ? "editor" : flags & 8 ? "preview" : void 0,
277
+ isPrefetch: flags & 16 ? true : void 0
259
278
  };
279
+ };
280
+ var serializeV2 = (payload) => {
281
+ const parts = ["2"];
282
+ parts.push(String(payload.compositionState));
283
+ parts.push(toBase64Url(payload.routePath));
260
284
  const componentKeys = Object.keys(payload.components);
261
285
  const sortedKeys = componentKeys.sort();
262
286
  const sortedComponents = sortedKeys.map((key) => ({
@@ -264,6 +288,7 @@ var serializeEvaluationResult = ({
264
288
  ...payload.components[key]
265
289
  }));
266
290
  const compressedComponentIds = compressIds(sortedComponents.map((c) => c._id));
291
+ const componentEntries = [];
267
292
  Object.keys(compressedComponentIds).forEach((compressedId) => {
268
293
  var _a;
269
294
  const originalId = compressedComponentIds[compressedId];
@@ -271,32 +296,117 @@ var serializeEvaluationResult = ({
271
296
  if (!component) {
272
297
  throw new Error(`Component ${originalId} not found`);
273
298
  }
274
- compressedPageState.c[compressedId] = {
275
- i: ((_a = component.indexes) == null ? void 0 : _a.length) ? component.indexes : void 0
276
- };
299
+ const indexes = ((_a = component.indexes) == null ? void 0 : _a.length) ? component.indexes : void 0;
300
+ if (indexes) {
301
+ componentEntries.push(`${compressedId}${V2_KV_SEP}${indexes.join(V2_INDEX_SEP)}`);
302
+ } else {
303
+ componentEntries.push(compressedId);
304
+ }
277
305
  });
306
+ parts.push(componentEntries.join(V2_ENTRY_SEP));
307
+ let rulesStr = "";
278
308
  if (typeof payload.rules !== "undefined") {
279
309
  const ruleKeys = Object.keys(payload.rules);
280
310
  if (ruleKeys.length !== 0) {
281
- compressedPageState.rl = {};
282
311
  const sortedRuleKeys = ruleKeys.sort();
283
312
  const compressedRuleKeys = compressIds(sortedRuleKeys);
313
+ const ruleEntries = [];
284
314
  Object.keys(compressedRuleKeys).forEach((compressedId) => {
285
315
  const originalId = compressedRuleKeys[compressedId];
286
- compressedPageState.rl[compressedId] = payload.rules[originalId] ? 1 : 0;
316
+ ruleEntries.push(`${compressedId}${V2_KV_SEP}${payload.rules[originalId] ? 1 : 0}`);
287
317
  });
318
+ rulesStr = ruleEntries.join(V2_ENTRY_SEP);
288
319
  }
289
320
  }
290
- const result = JSON.stringify(compressedPageState);
291
- return encode ? encodeWithReplacements(result) : result;
321
+ parts.push(rulesStr);
322
+ let keysStr = "";
323
+ if (payload.keys) {
324
+ const keyEntries = Object.entries(payload.keys).map(
325
+ ([k, v]) => `${toBase64Url(k)}${V2_KV_SEP}${toBase64Url(v)}`
326
+ );
327
+ keysStr = keyEntries.join(V2_ENTRY_SEP);
328
+ }
329
+ parts.push(keysStr);
330
+ parts.push(encodeFlags(payload));
331
+ parts.push(payload.releaseId ? toBase64Url(payload.releaseId) : "");
332
+ parts.push(payload.locale ? toBase64Url(payload.locale) : "");
333
+ return parts.join(V2_FIELD_SEP);
334
+ };
335
+ var deserializeV2 = (input) => {
336
+ var _a, _b, _c, _d;
337
+ const fields = input.split(V2_FIELD_SEP);
338
+ const compositionState = parseInt(fields[1], 10);
339
+ const routePath = fromBase64Url(fields[2]);
340
+ const components = {};
341
+ const componentsStr = (_a = fields[3]) != null ? _a : "";
342
+ if (componentsStr) {
343
+ componentsStr.split(V2_ENTRY_SEP).forEach((entry) => {
344
+ const sepIdx = entry.indexOf(V2_KV_SEP);
345
+ if (sepIdx === -1) {
346
+ components[entry] = {};
347
+ } else {
348
+ const id = entry.slice(0, sepIdx);
349
+ const indexes = entry.slice(sepIdx + 1).split(V2_INDEX_SEP).map(Number);
350
+ components[id] = { indexes };
351
+ }
352
+ });
353
+ }
354
+ const rulesStr = (_b = fields[4]) != null ? _b : "";
355
+ let rules;
356
+ if (rulesStr) {
357
+ rules = {};
358
+ rulesStr.split(V2_ENTRY_SEP).forEach((entry) => {
359
+ const sepIdx = entry.indexOf(V2_KV_SEP);
360
+ if (sepIdx !== -1) {
361
+ const id = entry.slice(0, sepIdx);
362
+ rules[id] = entry.slice(sepIdx + 1) === "1";
363
+ }
364
+ });
365
+ }
366
+ const keysStr = (_c = fields[5]) != null ? _c : "";
367
+ const keys = {};
368
+ if (keysStr) {
369
+ keysStr.split(V2_ENTRY_SEP).forEach((entry) => {
370
+ const sepIdx = entry.indexOf(V2_KV_SEP);
371
+ if (sepIdx !== -1) {
372
+ const k = fromBase64Url(entry.slice(0, sepIdx));
373
+ const v = fromBase64Url(entry.slice(sepIdx + 1));
374
+ keys[k] = v;
375
+ }
376
+ });
377
+ }
378
+ const { defaultConsent, previewMode, isPrefetch } = decodeFlags((_d = fields[6]) != null ? _d : "0");
379
+ const releaseId = fields[7] ? fromBase64Url(fields[7]) : void 0;
380
+ const locale = fields[8] ? fromBase64Url(fields[8]) : void 0;
381
+ return {
382
+ compositionState,
383
+ routePath,
384
+ components,
385
+ rules,
386
+ keys,
387
+ releaseId,
388
+ defaultConsent,
389
+ previewMode,
390
+ locale,
391
+ isPrefetch
392
+ };
393
+ };
394
+ var serializeEvaluationResult = ({
395
+ payload
396
+ }) => {
397
+ return serializeV2(payload);
292
398
  };
293
399
  var deserializeEvaluationResult = ({
294
400
  input: providedInput,
295
401
  decode = true
296
402
  }) => {
297
403
  var _a, _b, _c;
298
- const input = decode ? decodeWithReplacements(providedInput) : providedInput;
299
- const parsed = JSON.parse(input);
404
+ const input = decode ? decodeURIComponent(providedInput) : providedInput;
405
+ if (input.startsWith("2~")) {
406
+ return deserializeV2(input);
407
+ }
408
+ const jsonInput = decode ? atob(unreplaceReservedCharacters(input)) : input;
409
+ const parsed = JSON.parse(jsonInput);
300
410
  const pageState = {
301
411
  compositionState: parsed.cs,
302
412
  routePath: parsed.r,
package/dist/index.mjs CHANGED
@@ -160,23 +160,11 @@ var resolveRuleFromPageState = ({
160
160
  }
161
161
  return value;
162
162
  };
163
- var replaceReservedCharacters = (value) => {
164
- return ENCODED_RESERVED_CHARACTERS.reduce((acc, char) => {
165
- return acc.replaceAll(char.character, char.replacement);
166
- }, value);
167
- };
168
163
  var unreplaceReservedCharacters = (value) => {
169
164
  return ENCODED_RESERVED_CHARACTERS.reduce((acc, char) => {
170
165
  return acc.replaceAll(char.replacement, char.character);
171
166
  }, value);
172
167
  };
173
- var encodeWithReplacements = (value) => {
174
- return replaceReservedCharacters(btoa(value));
175
- };
176
- var decodeWithReplacements = (value) => {
177
- const urlDecoded = decodeURIComponent(value);
178
- return atob(unreplaceReservedCharacters(urlDecoded));
179
- };
180
168
  var compressIds = (ids) => {
181
169
  const uuidV4Length = 36;
182
170
  let compressedRegistry;
@@ -206,22 +194,58 @@ var compressIds = (ids) => {
206
194
  );
207
195
  };
208
196
  var NAMESPACE_UUID = "00000000-0000-0000-0000-000000000000";
209
- var serializeEvaluationResult = ({
210
- payload,
211
- encode = true
212
- }) => {
213
- const compressedPageState = {
214
- cs: payload.compositionState,
215
- r: payload.routePath,
216
- c: {},
217
- k: payload.keys,
218
- ri: payload.releaseId,
219
- dc: typeof payload.defaultConsent !== "undefined" ? payload.defaultConsent ? 1 : 0 : void 0,
220
- pm: payload.previewMode === "editor" ? "e" : payload.previewMode === "preview" ? "p" : void 0,
221
- rl: void 0,
222
- l: payload.locale,
223
- pf: payload.isPrefetch ? 1 : void 0
197
+ var V2_FIELD_SEP = "~";
198
+ var V2_ENTRY_SEP = ".";
199
+ var V2_KV_SEP = ":";
200
+ var V2_INDEX_SEP = ",";
201
+ var toBase64Url = (value) => {
202
+ const bytes = new TextEncoder().encode(value);
203
+ const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join("");
204
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
205
+ };
206
+ var fromBase64Url = (value) => {
207
+ let base64 = value.replace(/-/g, "+").replace(/_/g, "/");
208
+ const pad = base64.length % 4;
209
+ if (pad === 2) {
210
+ base64 += "==";
211
+ } else if (pad === 3) {
212
+ base64 += "=";
213
+ }
214
+ const binary = atob(base64);
215
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
216
+ return new TextDecoder().decode(bytes);
217
+ };
218
+ var encodeFlags = (payload) => {
219
+ let flags = 0;
220
+ if (typeof payload.defaultConsent !== "undefined") {
221
+ flags |= 1;
222
+ if (payload.defaultConsent) {
223
+ flags |= 2;
224
+ }
225
+ }
226
+ if (payload.previewMode === "editor") {
227
+ flags |= 4;
228
+ }
229
+ if (payload.previewMode === "preview") {
230
+ flags |= 8;
231
+ }
232
+ if (payload.isPrefetch) {
233
+ flags |= 16;
234
+ }
235
+ return flags.toString(16);
236
+ };
237
+ var decodeFlags = (hex) => {
238
+ const flags = parseInt(hex, 16) || 0;
239
+ return {
240
+ defaultConsent: flags & 1 ? Boolean(flags & 2) : void 0,
241
+ previewMode: flags & 4 ? "editor" : flags & 8 ? "preview" : void 0,
242
+ isPrefetch: flags & 16 ? true : void 0
224
243
  };
244
+ };
245
+ var serializeV2 = (payload) => {
246
+ const parts = ["2"];
247
+ parts.push(String(payload.compositionState));
248
+ parts.push(toBase64Url(payload.routePath));
225
249
  const componentKeys = Object.keys(payload.components);
226
250
  const sortedKeys = componentKeys.sort();
227
251
  const sortedComponents = sortedKeys.map((key) => ({
@@ -229,6 +253,7 @@ var serializeEvaluationResult = ({
229
253
  ...payload.components[key]
230
254
  }));
231
255
  const compressedComponentIds = compressIds(sortedComponents.map((c) => c._id));
256
+ const componentEntries = [];
232
257
  Object.keys(compressedComponentIds).forEach((compressedId) => {
233
258
  var _a;
234
259
  const originalId = compressedComponentIds[compressedId];
@@ -236,32 +261,117 @@ var serializeEvaluationResult = ({
236
261
  if (!component) {
237
262
  throw new Error(`Component ${originalId} not found`);
238
263
  }
239
- compressedPageState.c[compressedId] = {
240
- i: ((_a = component.indexes) == null ? void 0 : _a.length) ? component.indexes : void 0
241
- };
264
+ const indexes = ((_a = component.indexes) == null ? void 0 : _a.length) ? component.indexes : void 0;
265
+ if (indexes) {
266
+ componentEntries.push(`${compressedId}${V2_KV_SEP}${indexes.join(V2_INDEX_SEP)}`);
267
+ } else {
268
+ componentEntries.push(compressedId);
269
+ }
242
270
  });
271
+ parts.push(componentEntries.join(V2_ENTRY_SEP));
272
+ let rulesStr = "";
243
273
  if (typeof payload.rules !== "undefined") {
244
274
  const ruleKeys = Object.keys(payload.rules);
245
275
  if (ruleKeys.length !== 0) {
246
- compressedPageState.rl = {};
247
276
  const sortedRuleKeys = ruleKeys.sort();
248
277
  const compressedRuleKeys = compressIds(sortedRuleKeys);
278
+ const ruleEntries = [];
249
279
  Object.keys(compressedRuleKeys).forEach((compressedId) => {
250
280
  const originalId = compressedRuleKeys[compressedId];
251
- compressedPageState.rl[compressedId] = payload.rules[originalId] ? 1 : 0;
281
+ ruleEntries.push(`${compressedId}${V2_KV_SEP}${payload.rules[originalId] ? 1 : 0}`);
252
282
  });
283
+ rulesStr = ruleEntries.join(V2_ENTRY_SEP);
253
284
  }
254
285
  }
255
- const result = JSON.stringify(compressedPageState);
256
- return encode ? encodeWithReplacements(result) : result;
286
+ parts.push(rulesStr);
287
+ let keysStr = "";
288
+ if (payload.keys) {
289
+ const keyEntries = Object.entries(payload.keys).map(
290
+ ([k, v]) => `${toBase64Url(k)}${V2_KV_SEP}${toBase64Url(v)}`
291
+ );
292
+ keysStr = keyEntries.join(V2_ENTRY_SEP);
293
+ }
294
+ parts.push(keysStr);
295
+ parts.push(encodeFlags(payload));
296
+ parts.push(payload.releaseId ? toBase64Url(payload.releaseId) : "");
297
+ parts.push(payload.locale ? toBase64Url(payload.locale) : "");
298
+ return parts.join(V2_FIELD_SEP);
299
+ };
300
+ var deserializeV2 = (input) => {
301
+ var _a, _b, _c, _d;
302
+ const fields = input.split(V2_FIELD_SEP);
303
+ const compositionState = parseInt(fields[1], 10);
304
+ const routePath = fromBase64Url(fields[2]);
305
+ const components = {};
306
+ const componentsStr = (_a = fields[3]) != null ? _a : "";
307
+ if (componentsStr) {
308
+ componentsStr.split(V2_ENTRY_SEP).forEach((entry) => {
309
+ const sepIdx = entry.indexOf(V2_KV_SEP);
310
+ if (sepIdx === -1) {
311
+ components[entry] = {};
312
+ } else {
313
+ const id = entry.slice(0, sepIdx);
314
+ const indexes = entry.slice(sepIdx + 1).split(V2_INDEX_SEP).map(Number);
315
+ components[id] = { indexes };
316
+ }
317
+ });
318
+ }
319
+ const rulesStr = (_b = fields[4]) != null ? _b : "";
320
+ let rules;
321
+ if (rulesStr) {
322
+ rules = {};
323
+ rulesStr.split(V2_ENTRY_SEP).forEach((entry) => {
324
+ const sepIdx = entry.indexOf(V2_KV_SEP);
325
+ if (sepIdx !== -1) {
326
+ const id = entry.slice(0, sepIdx);
327
+ rules[id] = entry.slice(sepIdx + 1) === "1";
328
+ }
329
+ });
330
+ }
331
+ const keysStr = (_c = fields[5]) != null ? _c : "";
332
+ const keys = {};
333
+ if (keysStr) {
334
+ keysStr.split(V2_ENTRY_SEP).forEach((entry) => {
335
+ const sepIdx = entry.indexOf(V2_KV_SEP);
336
+ if (sepIdx !== -1) {
337
+ const k = fromBase64Url(entry.slice(0, sepIdx));
338
+ const v = fromBase64Url(entry.slice(sepIdx + 1));
339
+ keys[k] = v;
340
+ }
341
+ });
342
+ }
343
+ const { defaultConsent, previewMode, isPrefetch } = decodeFlags((_d = fields[6]) != null ? _d : "0");
344
+ const releaseId = fields[7] ? fromBase64Url(fields[7]) : void 0;
345
+ const locale = fields[8] ? fromBase64Url(fields[8]) : void 0;
346
+ return {
347
+ compositionState,
348
+ routePath,
349
+ components,
350
+ rules,
351
+ keys,
352
+ releaseId,
353
+ defaultConsent,
354
+ previewMode,
355
+ locale,
356
+ isPrefetch
357
+ };
358
+ };
359
+ var serializeEvaluationResult = ({
360
+ payload
361
+ }) => {
362
+ return serializeV2(payload);
257
363
  };
258
364
  var deserializeEvaluationResult = ({
259
365
  input: providedInput,
260
366
  decode = true
261
367
  }) => {
262
368
  var _a, _b, _c;
263
- const input = decode ? decodeWithReplacements(providedInput) : providedInput;
264
- const parsed = JSON.parse(input);
369
+ const input = decode ? decodeURIComponent(providedInput) : providedInput;
370
+ if (input.startsWith("2~")) {
371
+ return deserializeV2(input);
372
+ }
373
+ const jsonInput = decode ? atob(unreplaceReservedCharacters(input)) : input;
374
+ const parsed = JSON.parse(jsonInput);
265
375
  const pageState = {
266
376
  compositionState: parsed.cs,
267
377
  routePath: parsed.r,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/next-app-router-shared",
3
- "version": "20.53.1",
3
+ "version": "20.54.1-alpha.1+028680cba4",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -36,8 +36,8 @@
36
36
  "vitest": "3.2.4"
37
37
  },
38
38
  "dependencies": {
39
- "@uniformdev/canvas": "20.53.1",
40
- "@uniformdev/context": "20.53.1",
39
+ "@uniformdev/canvas": "20.54.1-alpha.1+028680cba4",
40
+ "@uniformdev/context": "20.54.1-alpha.1+028680cba4",
41
41
  "uuid": "9.0.1"
42
42
  },
43
43
  "engines": {
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "2a33fdce31a3a0f83b7b762356e03cdd65013a42"
54
+ "gitHead": "028680cba478a17da934cdb2ddebb777e2553455"
55
55
  }