@rebuy/rebuy 2.2.0 → 2.4.0-rc.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.
Files changed (74) hide show
  1. package/dist/api.d.ts.map +1 -1
  2. package/dist/index.d.ts +4 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +131 -27
  5. package/dist/index.js.map +4 -4
  6. package/dist/index.mjs +132 -28
  7. package/dist/index.mjs.map +4 -4
  8. package/dist/schema/cab/button.d.ts.map +1 -0
  9. package/dist/schema/cab/common.d.ts.map +1 -0
  10. package/dist/schema/cab/constants.d.ts.map +1 -0
  11. package/dist/schema/cab/data-source.d.ts.map +1 -0
  12. package/dist/schema/cab/image.d.ts.map +1 -0
  13. package/dist/schema/cab/index.d.ts.map +1 -0
  14. package/dist/schema/cab/layout.d.ts.map +1 -0
  15. package/dist/schema/cab/offers.d.ts.map +1 -0
  16. package/dist/schema/cab/product.d.ts.map +1 -0
  17. package/dist/schema/cab/products.d.ts.map +1 -0
  18. package/dist/schema/cab/quantity.d.ts.map +1 -0
  19. package/dist/schema/{regex.d.ts → cab/regex.d.ts} +2 -0
  20. package/dist/schema/cab/regex.d.ts.map +1 -0
  21. package/dist/schema/cab/reviews.d.ts.map +1 -0
  22. package/dist/schema/cab/root.d.ts.map +1 -0
  23. package/dist/schema/cab/shared.d.ts.map +1 -0
  24. package/dist/schema/cab/subscription.d.ts.map +1 -0
  25. package/dist/schema/cab/table.d.ts.map +1 -0
  26. package/dist/schema/cab/text.d.ts.map +1 -0
  27. package/dist/schema/{utils.d.ts → cab/utils.d.ts} +1 -0
  28. package/dist/schema/cab/utils.d.ts.map +1 -0
  29. package/dist/schema/cab/variants.d.ts.map +1 -0
  30. package/dist/schema/shopConfig.d.ts +63 -0
  31. package/dist/schema/shopConfig.d.ts.map +1 -0
  32. package/dist/schema/userConfig.d.ts +66 -0
  33. package/dist/schema/userConfig.d.ts.map +1 -0
  34. package/dist/schema/widgetSettings.d.ts +152 -0
  35. package/dist/schema/widgetSettings.d.ts.map +1 -0
  36. package/package.json +1 -1
  37. package/dist/schema/button.d.ts.map +0 -1
  38. package/dist/schema/common.d.ts.map +0 -1
  39. package/dist/schema/constants.d.ts.map +0 -1
  40. package/dist/schema/data-source.d.ts.map +0 -1
  41. package/dist/schema/image.d.ts.map +0 -1
  42. package/dist/schema/index.d.ts.map +0 -1
  43. package/dist/schema/layout.d.ts.map +0 -1
  44. package/dist/schema/offers.d.ts.map +0 -1
  45. package/dist/schema/product.d.ts.map +0 -1
  46. package/dist/schema/products.d.ts.map +0 -1
  47. package/dist/schema/quantity.d.ts.map +0 -1
  48. package/dist/schema/regex.d.ts.map +0 -1
  49. package/dist/schema/reviews.d.ts.map +0 -1
  50. package/dist/schema/root.d.ts.map +0 -1
  51. package/dist/schema/shared.d.ts.map +0 -1
  52. package/dist/schema/subscription.d.ts.map +0 -1
  53. package/dist/schema/table.d.ts.map +0 -1
  54. package/dist/schema/text.d.ts.map +0 -1
  55. package/dist/schema/utils.d.ts.map +0 -1
  56. package/dist/schema/variants.d.ts.map +0 -1
  57. /package/dist/schema/{button.d.ts → cab/button.d.ts} +0 -0
  58. /package/dist/schema/{common.d.ts → cab/common.d.ts} +0 -0
  59. /package/dist/schema/{constants.d.ts → cab/constants.d.ts} +0 -0
  60. /package/dist/schema/{data-source.d.ts → cab/data-source.d.ts} +0 -0
  61. /package/dist/schema/{image.d.ts → cab/image.d.ts} +0 -0
  62. /package/dist/schema/{index.d.ts → cab/index.d.ts} +0 -0
  63. /package/dist/schema/{layout.d.ts → cab/layout.d.ts} +0 -0
  64. /package/dist/schema/{offers.d.ts → cab/offers.d.ts} +0 -0
  65. /package/dist/schema/{product.d.ts → cab/product.d.ts} +0 -0
  66. /package/dist/schema/{products.d.ts → cab/products.d.ts} +0 -0
  67. /package/dist/schema/{quantity.d.ts → cab/quantity.d.ts} +0 -0
  68. /package/dist/schema/{reviews.d.ts → cab/reviews.d.ts} +0 -0
  69. /package/dist/schema/{root.d.ts → cab/root.d.ts} +0 -0
  70. /package/dist/schema/{shared.d.ts → cab/shared.d.ts} +0 -0
  71. /package/dist/schema/{subscription.d.ts → cab/subscription.d.ts} +0 -0
  72. /package/dist/schema/{table.d.ts → cab/table.d.ts} +0 -0
  73. /package/dist/schema/{text.d.ts → cab/text.d.ts} +0 -0
  74. /package/dist/schema/{variants.d.ts → cab/variants.d.ts} +0 -0
package/dist/index.mjs CHANGED
@@ -291,6 +291,7 @@ var staging = {
291
291
  staticDomain: "https://cdn.enigneyuber.com"
292
292
  };
293
293
  var stagingDomains = [
294
+ "cab-staging.myshopify.com",
294
295
  "enigneyuber.com",
295
296
  "rebuy-engine-regression.myshopify.com",
296
297
  "rebuy-stage-currency-test.myshopify.com",
@@ -733,11 +734,11 @@ var RebuyClient = class {
733
734
  }
734
735
  };
735
736
 
736
- // src/schema/button.ts
737
+ // src/schema/cab/button.ts
737
738
  import { v7 as uuidv712 } from "uuid";
738
739
  import { z as z16 } from "zod/v4";
739
740
 
740
- // src/schema/common.ts
741
+ // src/schema/cab/common.ts
741
742
  import { z } from "zod/v4";
742
743
  var borderRadii = ["none", "small", "base", "large", "fullyRounded"];
743
744
  var borderRadius = z.enum(borderRadii);
@@ -873,23 +874,24 @@ var verticalAlignments = ["top", "middle", "bottom"];
873
874
  var verticalAlignment = z.enum(verticalAlignments);
874
875
  var VerticalAlignment = verticalAlignment.enum;
875
876
 
876
- // src/schema/image.ts
877
+ // src/schema/cab/image.ts
877
878
  import { v7 as uuidv711 } from "uuid";
878
879
  import { z as z15 } from "zod/v4";
879
880
 
880
- // src/schema/regex.ts
881
+ // src/schema/cab/regex.ts
882
+ var ARRAY_INDEX_STRING = /^(0|[1-9]\d*)$/;
881
883
  var DYNAMIC_TOKEN_REGEX = /^\{\{\s*[A-Za-z]+\s*\}\}$/;
882
884
  var HEX_COLOR_REGEX = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
883
885
  var HTML_TAGS_REGEX = /<[^>]*>/gi;
884
886
 
885
- // src/schema/shared.ts
887
+ // src/schema/cab/shared.ts
886
888
  import { z as z14 } from "zod/v4";
887
889
 
888
- // src/schema/data-source.ts
890
+ // src/schema/cab/data-source.ts
889
891
  import { v7 as uuidv7 } from "uuid";
890
892
  import { z as z3 } from "zod/v4";
891
893
 
892
- // src/schema/constants.ts
894
+ // src/schema/cab/constants.ts
893
895
  import { uniqBy } from "lodash-es";
894
896
  import { z as z2 } from "zod/v4";
895
897
  var DEFAULT_ENDPOINTS = [
@@ -967,7 +969,7 @@ var widgetTypes = [
967
969
  var widgetType = z2.enum(widgetTypes);
968
970
  var WidgetType = widgetType.enum;
969
971
 
970
- // src/schema/data-source.ts
972
+ // src/schema/cab/data-source.ts
971
973
  var CABDataSourceSection = z3.object({
972
974
  dataSourceId: z3.number().nullable().default(null),
973
975
  dataSourcePath: z3.string().default(DEFAULT_ENDPOINTS[0].value),
@@ -977,7 +979,7 @@ var CABDataSourceSection = z3.object({
977
979
  sectionType: z3.literal(SectionType.dataSource).default(SectionType.dataSource)
978
980
  });
979
981
 
980
- // src/schema/layout.ts
982
+ // src/schema/cab/layout.ts
981
983
  import { v7 as uuidv72 } from "uuid";
982
984
  import { z as z4 } from "zod/v4";
983
985
  var CABLayoutSection = z4.object({
@@ -999,24 +1001,24 @@ var CABLayoutSection = z4.object({
999
1001
  width: z4.number().default(100)
1000
1002
  });
1001
1003
 
1002
- // src/schema/offers.ts
1004
+ // src/schema/cab/offers.ts
1003
1005
  import { z as z8 } from "zod/v4";
1004
1006
 
1005
- // src/schema/products.ts
1007
+ // src/schema/cab/products.ts
1006
1008
  import { v7 as uuidv75 } from "uuid";
1007
1009
  import { z as z7 } from "zod/v4";
1008
1010
 
1009
- // src/schema/product.ts
1011
+ // src/schema/cab/product.ts
1010
1012
  import { v7 as uuidv74 } from "uuid";
1011
1013
  import { z as z6 } from "zod/v4";
1012
1014
 
1013
- // src/schema/text.ts
1015
+ // src/schema/cab/text.ts
1014
1016
  import { forEach, isString as isString2 } from "lodash-es";
1015
1017
  import { v7 as uuidv73 } from "uuid";
1016
1018
  import { z as z5 } from "zod/v4";
1017
1019
 
1018
- // src/schema/utils.ts
1019
- import { get as get2, isPlainObject, isString } from "lodash-es";
1020
+ // src/schema/cab/utils.ts
1021
+ import { entries, every, get as get2, isArray, isPlainObject, isString, map, mapValues, size } from "lodash-es";
1020
1022
  var isHTML = (html = "") => {
1021
1023
  if (typeof window !== "undefined") {
1022
1024
  const parser = new DOMParser();
@@ -1042,8 +1044,18 @@ var isSubscriptionType = (section) => get2(section, "sectionType") === SectionTy
1042
1044
  var isTableType = (section) => get2(section, "sectionType") === SectionType.table;
1043
1045
  var isTextType = (section) => get2(section, "sectionType") === SectionType.text;
1044
1046
  var isVariantsType = (section) => get2(section, "sectionType") === SectionType.variants;
1047
+ var hasOnlyNumericKeys = (input) => !!size(input) && every(input, (_, key) => ARRAY_INDEX_STRING.test(key) && Number.isSafeInteger(Number(key)));
1048
+ var numericObjectToArray = (input) => entries(input).sort(([a], [b]) => Number(a) - Number(b)).map(([_, value]) => value);
1049
+ var convertNumericObjects = (input) => {
1050
+ if (isArray(input)) return map(input, convertNumericObjects);
1051
+ if (isPlainObject(input)) {
1052
+ const obj = input;
1053
+ return hasOnlyNumericKeys(obj) ? map(numericObjectToArray(obj), convertNumericObjects) : mapValues(obj, convertNumericObjects);
1054
+ }
1055
+ return input;
1056
+ };
1045
1057
 
1046
- // src/schema/text.ts
1058
+ // src/schema/cab/text.ts
1047
1059
  var enumOrOmit = (...vals) => z5.string().transform((val) => vals.includes(val) ? val : void 0).optional();
1048
1060
  var TiptapText = z5.object({
1049
1061
  marks: z5.array(
@@ -1111,7 +1123,7 @@ var CABTextSection = z5.object({
1111
1123
  }
1112
1124
  });
1113
1125
 
1114
- // src/schema/product.ts
1126
+ // src/schema/cab/product.ts
1115
1127
  var CABProductSection = z6.object({
1116
1128
  name: z6.string().optional(),
1117
1129
  options: z6.array(
@@ -1136,7 +1148,7 @@ var CABProductSection = z6.object({
1136
1148
  sectionType: z6.literal(SectionType.product).default(SectionType.product)
1137
1149
  });
1138
1150
 
1139
- // src/schema/products.ts
1151
+ // src/schema/cab/products.ts
1140
1152
  var CABProductsSection = z7.object({
1141
1153
  name: z7.string().optional(),
1142
1154
  sectionId: z7.uuidv7().default(() => uuidv75()),
@@ -1144,7 +1156,7 @@ var CABProductsSection = z7.object({
1144
1156
  sectionType: z7.literal(SectionType.products).default(SectionType.products)
1145
1157
  });
1146
1158
 
1147
- // src/schema/offers.ts
1159
+ // src/schema/cab/offers.ts
1148
1160
  var CABOffersSection = CABLayoutSection.omit({ sections: true, sectionType: true }).extend(
1149
1161
  z8.object({
1150
1162
  sections: z8.array(z8.lazy(() => CABSection)).default(() => [CABDataSourceSection.parse({}), CABProductsSection.parse({})]),
@@ -1152,7 +1164,7 @@ var CABOffersSection = CABLayoutSection.omit({ sections: true, sectionType: true
1152
1164
  }).shape
1153
1165
  );
1154
1166
 
1155
- // src/schema/quantity.ts
1167
+ // src/schema/cab/quantity.ts
1156
1168
  import { v7 as uuidv76 } from "uuid";
1157
1169
  import { z as z9 } from "zod/v4";
1158
1170
  var CABQuantitySection = z9.object({
@@ -1178,7 +1190,7 @@ var CABQuantitySection = z9.object({
1178
1190
  sectionType: z9.literal(SectionType.quantity).default(SectionType.quantity)
1179
1191
  });
1180
1192
 
1181
- // src/schema/reviews.ts
1193
+ // src/schema/cab/reviews.ts
1182
1194
  import { v7 as uuidv77 } from "uuid";
1183
1195
  import { z as z10 } from "zod/v4";
1184
1196
  var CABReviewsSection = z10.object({
@@ -1187,7 +1199,7 @@ var CABReviewsSection = z10.object({
1187
1199
  sectionType: z10.literal(SectionType.reviews).default(SectionType.reviews)
1188
1200
  });
1189
1201
 
1190
- // src/schema/subscription.ts
1202
+ // src/schema/cab/subscription.ts
1191
1203
  import { v7 as uuidv78 } from "uuid";
1192
1204
  import { z as z11 } from "zod/v4";
1193
1205
  var CABSubscriptionSection = z11.object({
@@ -1196,7 +1208,7 @@ var CABSubscriptionSection = z11.object({
1196
1208
  sectionType: z11.literal(SectionType.subscription).default(SectionType.subscription)
1197
1209
  });
1198
1210
 
1199
- // src/schema/table.ts
1211
+ // src/schema/cab/table.ts
1200
1212
  import { v7 as uuidv79 } from "uuid";
1201
1213
  import { z as z12 } from "zod/v4";
1202
1214
  var CABTableSection = z12.object({
@@ -1205,7 +1217,7 @@ var CABTableSection = z12.object({
1205
1217
  sectionType: z12.literal(SectionType.table).default(SectionType.table)
1206
1218
  });
1207
1219
 
1208
- // src/schema/variants.ts
1220
+ // src/schema/cab/variants.ts
1209
1221
  import { slice } from "lodash-es";
1210
1222
  import { v7 as uuidv710 } from "uuid";
1211
1223
  import { z as z13 } from "zod/v4";
@@ -1216,7 +1228,7 @@ var CABVariantsSection = z13.object({
1216
1228
  selector: z13.enum(slice(variantSelectors, 0, 3)).default(VariantSelector.menu)
1217
1229
  });
1218
1230
 
1219
- // src/schema/shared.ts
1231
+ // src/schema/cab/shared.ts
1220
1232
  var CABBorder = z14.object({
1221
1233
  radius: z14.enum(borderRadii).default(BorderRadius.base),
1222
1234
  style: z14.enum(borderStyles).default(BorderStyle.none),
@@ -1244,7 +1256,7 @@ var CABSection = z14.lazy(
1244
1256
  ])
1245
1257
  );
1246
1258
 
1247
- // src/schema/image.ts
1259
+ // src/schema/cab/image.ts
1248
1260
  var CABImageSection = z15.object({
1249
1261
  altText: z15.string().refine(checkForHTML, NO_HTML).default(""),
1250
1262
  aspectRatio: z15.literal(1).nullable().default(null),
@@ -1261,7 +1273,7 @@ var CABImageSection = z15.object({
1261
1273
  width: z15.number().default(100)
1262
1274
  });
1263
1275
 
1264
- // src/schema/button.ts
1276
+ // src/schema/cab/button.ts
1265
1277
  var CABButtonContent = z16.lazy(() => z16.discriminatedUnion("sectionType", [CABImageSection, CABTextSection]));
1266
1278
  var CABButtonSection = z16.object({
1267
1279
  action: z16.union([z16.literal(""), z16.enum(buttonActions)]).default(""),
@@ -1281,7 +1293,7 @@ var CABButtonSection = z16.object({
1281
1293
  sectionType: z16.literal(SectionType.button).default(SectionType.button)
1282
1294
  });
1283
1295
 
1284
- // src/schema/root.ts
1296
+ // src/schema/cab/root.ts
1285
1297
  import { z as z17 } from "zod/v4";
1286
1298
  var TargetArea = z17.object({
1287
1299
  fill: z17.boolean().optional(),
@@ -1301,7 +1313,94 @@ var CABRootSection = CABLayoutSection.extend(
1301
1313
  widgetId: z17.number().nullable().default(null)
1302
1314
  }).shape
1303
1315
  );
1316
+
1317
+ // src/schema/shopConfig.ts
1318
+ import { z as z18 } from "zod/v4";
1319
+ var ShopConfig = z18.object({
1320
+ activeExperiments: z18.array(
1321
+ z18.object({
1322
+ data: z18.array(
1323
+ z18.object({
1324
+ aliasName: z18.string(),
1325
+ cssInput: z18.string().nullish(),
1326
+ elementId: z18.string(),
1327
+ id: z18.string(),
1328
+ javascriptInput: z18.string().nullish(),
1329
+ traffic: z18.string()
1330
+ })
1331
+ ),
1332
+ id: z18.string(),
1333
+ name: z18.string(),
1334
+ pageTarget: z18.string().nullable(),
1335
+ placeholderId: z18.string().nullable(),
1336
+ type: z18.string()
1337
+ })
1338
+ ).optional(),
1339
+ activePackages: z18.array(
1340
+ z18.object({
1341
+ cancelledAt: z18.string().nullable(),
1342
+ id: z18.number(),
1343
+ installedAt: z18.string().nullable(),
1344
+ isActive: z18.boolean(),
1345
+ isBillable: z18.boolean(),
1346
+ packageId: z18.number(),
1347
+ packageName: z18.string(),
1348
+ shortName: z18.string(),
1349
+ trialDays: z18.number(),
1350
+ uninstalledAt: z18.string().nullable()
1351
+ })
1352
+ ).optional(),
1353
+ apiKey: z18.string(),
1354
+ billingVersion: z18.string().optional(),
1355
+ cacheKey: z18.string().regex(/^[0-9]+$/),
1356
+ carousel: z18.string(),
1357
+ currency: z18.string(),
1358
+ currencySymbol: z18.string(),
1359
+ domain: z18.string(),
1360
+ enabledJquery: z18.boolean(),
1361
+ enabledPresentmentCurrencies: z18.array(z18.string()),
1362
+ hasSmartCollectionsEnabled: z18.boolean().optional(),
1363
+ hasSmartSearchEnabled: z18.boolean(),
1364
+ id: z18.string().regex(/^[0-9]+$/),
1365
+ integrations: z18.record(z18.string(), z18.boolean()),
1366
+ markets: z18.object({
1367
+ enabled: z18.boolean()
1368
+ }),
1369
+ moneyFormat: z18.string(),
1370
+ myshopifyDomain: z18.string(),
1371
+ primaryLocale: z18.string(),
1372
+ productGroupsEnabled: z18.enum(["no", "yes"]),
1373
+ rechargeCustomDomain: z18.string().nullable(),
1374
+ sellingPlansEnabled: z18.boolean(),
1375
+ shopId: z18.number(),
1376
+ shopifySellingPlansEnabled: z18.boolean(),
1377
+ shopName: z18.string(),
1378
+ storefrontAccessToken: z18.string().nullable(),
1379
+ useRebuyIcons: z18.boolean()
1380
+ });
1381
+
1382
+ // src/schema/userConfig.ts
1383
+ import { z as z19 } from "zod/v4";
1384
+ var UserConfig = z19.object({
1385
+ shop: ShopConfig,
1386
+ smartCart: z19.unknown(),
1387
+ smartFlows: z19.array(z19.unknown())
1388
+ });
1389
+
1390
+ // src/schema/widgetSettings.ts
1391
+ import { z as z20 } from "zod/v4";
1392
+ var LegacyV1Widget = z20.discriminatedUnion("type", [
1393
+ z20.object({ type: z20.literal(WidgetType.gift_with_purchase), version: z20.literal(1) }),
1394
+ z20.object({ type: z20.literal(WidgetType.shopify_checkout_extension), version: z20.literal(1) }),
1395
+ z20.object({ type: z20.literal(WidgetType.ui_extension_ad), version: z20.literal(1) }),
1396
+ z20.object({ type: z20.literal(WidgetType.ui_extension_button), version: z20.literal(1) }),
1397
+ z20.object({ type: z20.literal(WidgetType.ui_extension_content_block), version: z20.literal(1) }),
1398
+ z20.object({ type: z20.literal(WidgetType.ui_extension_line_item_editor), version: z20.literal(1) }),
1399
+ z20.object({ type: z20.literal(WidgetType.ui_extension_progress_bar), version: z20.literal(1) })
1400
+ ]);
1401
+ var WidgetSettings = z20.discriminatedUnion("version", [LegacyV1Widget, CABRootSection]);
1304
1402
  export {
1403
+ ARRAY_INDEX_STRING,
1305
1404
  Api,
1306
1405
  BorderRadius,
1307
1406
  BorderStyle,
@@ -1337,6 +1436,7 @@ export {
1337
1436
  HorizontalAlignment,
1338
1437
  Identity,
1339
1438
  LanguageKey,
1439
+ LegacyV1Widget,
1340
1440
  NO_HTML,
1341
1441
  ObjectFit,
1342
1442
  QuantityInput,
@@ -1344,6 +1444,7 @@ export {
1344
1444
  STATIC_ENDPOINTS,
1345
1445
  SectionType,
1346
1446
  Session,
1447
+ ShopConfig,
1347
1448
  Spacing,
1348
1449
  TextAlignment,
1349
1450
  TextColorName,
@@ -1351,8 +1452,10 @@ export {
1351
1452
  TiptapDocument,
1352
1453
  TiptapParagraph,
1353
1454
  TiptapText,
1455
+ UserConfig,
1354
1456
  VariantSelector,
1355
1457
  VerticalAlignment,
1458
+ WidgetSettings,
1356
1459
  WidgetType,
1357
1460
  amountToCents,
1358
1461
  borderRadii,
@@ -1362,6 +1465,7 @@ export {
1362
1465
  buttonFields,
1363
1466
  buttonStyles,
1364
1467
  checkForHTML,
1468
+ convertNumericObjects,
1365
1469
  convertProductToStorefrontFormat,
1366
1470
  convertToNodes,
1367
1471
  convertVariantToStorefrontFormat,