@ecomweb/sdk 0.6.0 → 0.10.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/dist/index.js CHANGED
@@ -297,7 +297,6 @@ var storeSettingsSchema = z5.object({
297
297
  facebook_link: urlSchema,
298
298
  instagram_link: urlSchema,
299
299
  google_analytics_key: z5.string().optional().nullable(),
300
- shop_introduction: z5.string().optional().nullable(),
301
300
  tagline: z5.string().optional().nullable(),
302
301
  blog_title: z5.string().optional().nullable(),
303
302
  is_blog_enabled: z5.boolean().optional().nullable(),
@@ -878,6 +877,22 @@ var customerOrderSummarySchema = z10.object({
878
877
  last_order_date: z10.iso.datetime().optional().nullable()
879
878
  });
880
879
 
880
+ // src/types/shipment.ts
881
+ var SHIPMENT_STATUSES = [
882
+ "booked",
883
+ "picked_up",
884
+ "in_transit",
885
+ "out_for_delivery",
886
+ "delivered",
887
+ "failed",
888
+ "returned",
889
+ "cancelled"
890
+ ];
891
+ var ORDER_SHIPMENT_ERROR_CODES = {
892
+ /** Cancelling is refused because a carrier shipment is already in progress. */
893
+ CANCEL_BLOCKED_BY_SHIPMENT: "ORDER_CANCEL_BLOCKED_BY_SHIPMENT"
894
+ };
895
+
881
896
  // src/types/order-timeline.ts
882
897
  var ORDER_EVENT_TYPES = [
883
898
  "placed",
@@ -885,14 +900,18 @@ var ORDER_EVENT_TYPES = [
885
900
  "fulfillment_status_changed",
886
901
  "shipping_status_changed",
887
902
  "payment_status_changed",
888
- "tracking_number_updated"
903
+ "tracking_number_updated",
904
+ "shipment_booked",
905
+ "shipment_cancelled",
906
+ "shipment_failed"
889
907
  ];
890
908
  var ORDER_ACTOR_TYPES = [
891
909
  "staff",
892
910
  "customer",
893
911
  "api_key",
894
912
  "gateway",
895
- "system"
913
+ "system",
914
+ "carrier"
896
915
  ];
897
916
 
898
917
  // src/types/promotion.ts
@@ -1197,38 +1216,14 @@ var blogCommentWithRepliesSchemaInner = z12.lazy(
1197
1216
  );
1198
1217
  var blogCommentWithRepliesSchema = blogCommentWithRepliesSchemaInner;
1199
1218
 
1200
- // src/types/banner.ts
1219
+ // src/types/content.ts
1201
1220
  import { z as z13 } from "zod";
1202
- var bannerSchema = z13.object({
1221
+ var contentPageSchema = z13.object({
1203
1222
  id: idSchema,
1204
1223
  title: z13.string().min(1),
1205
- subtitle: z13.string().optional().nullable(),
1206
- image_url: strictUrlSchema,
1207
- link_url: urlSchema,
1208
- button_text: z13.string().optional().nullable(),
1209
- position: positionOrderSchema,
1210
- is_active: z13.boolean().default(true),
1211
- metadata: z13.any()
1212
- }).extend(optionalTimestampSchema.shape);
1213
- var createBannerSchema = bannerSchema.omit({
1214
- id: true,
1215
- created_at: true,
1216
- updated_at: true
1217
- });
1218
- var updateBannerSchema = createBannerSchema.partial();
1219
- var updateBannerPositionSchema = z13.object({
1220
- id: idSchema,
1221
- position: z13.int32()
1222
- });
1223
-
1224
- // src/types/content.ts
1225
- import { z as z14 } from "zod";
1226
- var contentPageSchema = z14.object({
1227
- id: idSchema,
1228
- title: z14.string().min(1),
1229
- content: z14.string().optional().nullable(),
1230
- is_published: z14.boolean().default(false),
1231
- page_type: z14.string().optional().nullable(),
1224
+ content: z13.string().optional().nullable(),
1225
+ is_published: z13.boolean().default(false),
1226
+ page_type: z13.string().optional().nullable(),
1232
1227
  sort_order: positionOrderSchema,
1233
1228
  slug: slugSchema.max(255)
1234
1229
  }).extend(timestampSchema.shape);
@@ -1244,92 +1239,92 @@ var updateContentPageSchema = contentPageSchema.omit({
1244
1239
  }).partial();
1245
1240
 
1246
1241
  // src/types/theme-schema.ts
1247
- import { z as z15 } from "zod";
1242
+ import { z as z14 } from "zod";
1248
1243
  var THEME_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
1249
1244
  var SETTING_ID = /^[a-z][a-z0-9_]*$/;
1250
- var primitive = z15.union([z15.string(), z15.number(), z15.boolean()]);
1251
- var visibleIfSchema = z15.object({
1252
- setting: z15.string().regex(SETTING_ID),
1245
+ var primitive = z14.union([z14.string(), z14.number(), z14.boolean()]);
1246
+ var visibleIfSchema = z14.object({
1247
+ setting: z14.string().regex(SETTING_ID),
1253
1248
  equals: primitive.optional(),
1254
1249
  not_equals: primitive.optional(),
1255
- is_set: z15.boolean().optional()
1250
+ is_set: z14.boolean().optional()
1256
1251
  }).refine(
1257
1252
  (v) => [v.equals, v.not_equals, v.is_set].filter((x) => x !== void 0).length === 1,
1258
1253
  { message: "visible_if needs exactly one of equals, not_equals, is_set" }
1259
1254
  );
1260
1255
  var base = {
1261
- id: z15.string().regex(SETTING_ID, "setting ids are snake_case"),
1262
- label: z15.string().min(1),
1263
- info: z15.string().optional(),
1256
+ id: z14.string().regex(SETTING_ID, "setting ids are snake_case"),
1257
+ label: z14.string().min(1),
1258
+ info: z14.string().optional(),
1264
1259
  visible_if: visibleIfSchema.optional()
1265
1260
  };
1266
- var itemSchema = z15.discriminatedUnion("type", [
1267
- z15.object({
1261
+ var itemSchema = z14.discriminatedUnion("type", [
1262
+ z14.object({
1268
1263
  ...base,
1269
- type: z15.literal("text"),
1270
- default: z15.string().optional(),
1271
- placeholder: z15.string().optional()
1264
+ type: z14.literal("text"),
1265
+ default: z14.string().optional(),
1266
+ placeholder: z14.string().optional()
1272
1267
  }),
1273
- z15.object({
1268
+ z14.object({
1274
1269
  ...base,
1275
- type: z15.literal("textarea"),
1276
- default: z15.string().optional(),
1277
- placeholder: z15.string().optional()
1270
+ type: z14.literal("textarea"),
1271
+ default: z14.string().optional(),
1272
+ placeholder: z14.string().optional()
1278
1273
  }),
1279
- z15.object({
1274
+ z14.object({
1280
1275
  ...base,
1281
- type: z15.literal("richtext"),
1282
- default: z15.string().optional()
1276
+ type: z14.literal("richtext"),
1277
+ default: z14.string().optional()
1283
1278
  }),
1284
- z15.object({ ...base, type: z15.literal("url"), default: z15.string().optional() }),
1285
- z15.object({
1279
+ z14.object({ ...base, type: z14.literal("url"), default: z14.string().optional() }),
1280
+ z14.object({
1286
1281
  ...base,
1287
- type: z15.literal("color"),
1288
- default: z15.string().regex(THEME_HEX_COLOR).optional()
1282
+ type: z14.literal("color"),
1283
+ default: z14.string().regex(THEME_HEX_COLOR).optional()
1289
1284
  }),
1290
- z15.object({
1285
+ z14.object({
1291
1286
  ...base,
1292
- type: z15.literal("menu"),
1293
- default: z15.string().optional()
1287
+ type: z14.literal("menu"),
1288
+ default: z14.string().optional()
1294
1289
  }),
1295
- z15.object({ ...base, type: z15.literal("image_picker") }),
1296
- z15.object({ ...base, type: z15.literal("collection") }),
1297
- z15.object({ ...base, type: z15.literal("page") }),
1298
- z15.object({ ...base, type: z15.literal("blog_post") }),
1299
- z15.object({ ...base, type: z15.literal("blog_category") }),
1300
- z15.object({ ...base, type: z15.literal("blog_tag") }),
1301
- z15.object({ ...base, type: z15.literal("product") }),
1302
- z15.object({
1290
+ z14.object({ ...base, type: z14.literal("image_picker") }),
1291
+ z14.object({ ...base, type: z14.literal("collection") }),
1292
+ z14.object({ ...base, type: z14.literal("page") }),
1293
+ z14.object({ ...base, type: z14.literal("blog_post") }),
1294
+ z14.object({ ...base, type: z14.literal("blog_category") }),
1295
+ z14.object({ ...base, type: z14.literal("blog_tag") }),
1296
+ z14.object({ ...base, type: z14.literal("product") }),
1297
+ z14.object({
1303
1298
  ...base,
1304
- type: z15.literal("checkbox"),
1305
- default: z15.boolean().optional()
1299
+ type: z14.literal("checkbox"),
1300
+ default: z14.boolean().optional()
1306
1301
  }),
1307
- z15.object({
1302
+ z14.object({
1308
1303
  ...base,
1309
- type: z15.literal("number"),
1310
- default: z15.number().optional(),
1311
- min: z15.number().optional(),
1312
- max: z15.number().optional()
1304
+ type: z14.literal("number"),
1305
+ default: z14.number().optional(),
1306
+ min: z14.number().optional(),
1307
+ max: z14.number().optional()
1313
1308
  }),
1314
- z15.object({
1309
+ z14.object({
1315
1310
  ...base,
1316
- type: z15.literal("range"),
1317
- min: z15.number(),
1318
- max: z15.number(),
1319
- step: z15.number().positive(),
1320
- unit: z15.string().optional(),
1321
- default: z15.number()
1311
+ type: z14.literal("range"),
1312
+ min: z14.number(),
1313
+ max: z14.number(),
1314
+ step: z14.number().positive(),
1315
+ unit: z14.string().optional(),
1316
+ default: z14.number()
1322
1317
  }),
1323
- z15.object({
1318
+ z14.object({
1324
1319
  ...base,
1325
- type: z15.literal("select"),
1326
- options: z15.array(z15.object({ value: z15.string(), label: z15.string().min(1) })).min(1),
1327
- default: z15.string().optional()
1320
+ type: z14.literal("select"),
1321
+ options: z14.array(z14.object({ value: z14.string(), label: z14.string().min(1) })).min(1),
1322
+ default: z14.string().optional()
1328
1323
  }),
1329
- z15.object({ type: z15.literal("header"), content: z15.string().min(1) }),
1330
- z15.object({ type: z15.literal("paragraph"), content: z15.string().min(1) })
1324
+ z14.object({ type: z14.literal("header"), content: z14.string().min(1) }),
1325
+ z14.object({ type: z14.literal("paragraph"), content: z14.string().min(1) })
1331
1326
  ]);
1332
- var themeSchemaSchema = z15.array(z15.object({ name: z15.string().min(1), settings: z15.array(itemSchema) })).superRefine((groups, ctx) => {
1327
+ var themeSchemaSchema = z14.array(z14.object({ name: z14.string().min(1), settings: z14.array(itemSchema) })).superRefine((groups, ctx) => {
1333
1328
  const settings = groups.flatMap((g) => g.settings).filter(isSetting);
1334
1329
  const ids = /* @__PURE__ */ new Set();
1335
1330
  for (const s of settings) {
@@ -1391,7 +1386,7 @@ function parseThemeSchema(input) {
1391
1386
  const result = themeSchemaSchema.safeParse(input);
1392
1387
  if (!result.success) {
1393
1388
  throw new Error(`Invalid theme schema:
1394
- ${z15.prettifyError(result.error)}`);
1389
+ ${z14.prettifyError(result.error)}`);
1395
1390
  }
1396
1391
  return result.data;
1397
1392
  }
@@ -1467,6 +1462,99 @@ function isSettingVisible(setting, values) {
1467
1462
  if (rule.equals !== void 0) return value === rule.equals;
1468
1463
  return value !== rule.not_equals;
1469
1464
  }
1465
+ function themeMajor(version) {
1466
+ const match = /^(\d+)\.\d+\.\d+$/.exec(version ?? "");
1467
+ return match ? Number(match[1]) : null;
1468
+ }
1469
+ var migrationValue = z14.union([z14.string(), z14.number(), z14.boolean()]);
1470
+ var migrationKey = z14.string().regex(SETTING_ID);
1471
+ var themeMigrationSchema = z14.object({
1472
+ from: z14.number().int().min(1),
1473
+ steps: z14.array(
1474
+ z14.discriminatedUnion("op", [
1475
+ z14.object({
1476
+ op: z14.literal("rename"),
1477
+ from: migrationKey,
1478
+ to: migrationKey
1479
+ }).strict(),
1480
+ z14.object({ op: z14.literal("remove"), key: migrationKey }).strict(),
1481
+ z14.object({
1482
+ op: z14.literal("map"),
1483
+ key: migrationKey,
1484
+ values: z14.record(z14.string(), migrationValue)
1485
+ }).strict(),
1486
+ z14.object({
1487
+ op: z14.literal("copy"),
1488
+ from: migrationKey,
1489
+ to: migrationKey
1490
+ }).strict(),
1491
+ z14.object({
1492
+ op: z14.literal("default"),
1493
+ key: migrationKey,
1494
+ value: migrationValue
1495
+ }).strict()
1496
+ ])
1497
+ ).max(500)
1498
+ }).strict();
1499
+ function parseThemeMigration(input) {
1500
+ const result = themeMigrationSchema.safeParse(input);
1501
+ if (!result.success) {
1502
+ const issues = result.error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
1503
+ throw new Error(`Invalid theme migration: ${issues}`);
1504
+ }
1505
+ return result.data;
1506
+ }
1507
+ function present(values, key) {
1508
+ return Object.prototype.hasOwnProperty.call(values, key) && values[key] !== void 0;
1509
+ }
1510
+ function applyThemeMigration(input, migration) {
1511
+ const values = { ...input };
1512
+ const report = {
1513
+ renamed: [],
1514
+ removed: [],
1515
+ mapped: [],
1516
+ copied: [],
1517
+ defaulted: []
1518
+ };
1519
+ for (const step of migration.steps) {
1520
+ switch (step.op) {
1521
+ case "rename":
1522
+ if (step.from === step.to || !present(values, step.from)) break;
1523
+ values[step.to] = values[step.from];
1524
+ delete values[step.from];
1525
+ report.renamed.push({ from: step.from, to: step.to });
1526
+ break;
1527
+ case "remove":
1528
+ if (!present(values, step.key)) break;
1529
+ delete values[step.key];
1530
+ report.removed.push(step.key);
1531
+ break;
1532
+ case "map": {
1533
+ const value = values[step.key];
1534
+ if (typeof value === "string" && Object.prototype.hasOwnProperty.call(step.values, value)) {
1535
+ values[step.key] = step.values[value];
1536
+ report.mapped.push({
1537
+ key: step.key,
1538
+ from: value,
1539
+ to: step.values[value]
1540
+ });
1541
+ }
1542
+ break;
1543
+ }
1544
+ case "copy":
1545
+ if (step.from === step.to || !present(values, step.from)) break;
1546
+ values[step.to] = values[step.from];
1547
+ report.copied.push({ from: step.from, to: step.to });
1548
+ break;
1549
+ case "default":
1550
+ if (present(values, step.key) && values[step.key] !== null) break;
1551
+ values[step.key] = step.value;
1552
+ report.defaulted.push(step.key);
1553
+ break;
1554
+ }
1555
+ }
1556
+ return { values, report };
1557
+ }
1470
1558
 
1471
1559
  // src/types/metafield-engine.ts
1472
1560
  var METAFIELD_OWNER_TYPES = [
@@ -3128,6 +3216,13 @@ var ThemesApi = class {
3128
3216
  );
3129
3217
  return unwrapOrNull(res, NO_PREVIEW);
3130
3218
  }
3219
+ /** The theme on a preview host, p-<slug>, with its saved values. */
3220
+ async getPreviewBySlug(storeRef, slug) {
3221
+ const res = await this.http.get(
3222
+ `/public/stores/${storeRef}/theme-preview?slug=${encodeURIComponent(slug)}`
3223
+ );
3224
+ return unwrapOrNull(res, NO_PREVIEW);
3225
+ }
3131
3226
  };
3132
3227
 
3133
3228
  // src/modules/metaobjects/api.ts
@@ -3194,20 +3289,6 @@ var SearchApi = class {
3194
3289
  }
3195
3290
  };
3196
3291
 
3197
- // src/modules/banners/api.ts
3198
- var BannersApi = class {
3199
- constructor(http) {
3200
- this.http = http;
3201
- }
3202
- async getPaginated(storeRef, query) {
3203
- const queryString = stringify(query ?? {});
3204
- const res = await this.http.get(
3205
- `/public/stores/${storeRef}/banners${queryString ? "?" + queryString : ""}`
3206
- );
3207
- return unwrap(res);
3208
- }
3209
- };
3210
-
3211
3292
  // src/modules/shipping/api.ts
3212
3293
  var ShippingApi = class {
3213
3294
  constructor(http) {
@@ -3817,6 +3898,10 @@ var SHIPPING_CONDITION_TYPES = [
3817
3898
  "ORDER_VALUE",
3818
3899
  "WEIGHT"
3819
3900
  ];
3901
+ var SHIPPING_ERROR_CODES = {
3902
+ QUOTE_CHANGED: "SHIPPING_QUOTE_CHANGED",
3903
+ RATE_UNAVAILABLE: "ORDER_SHIPPING_RATE_UNAVAILABLE"
3904
+ };
3820
3905
 
3821
3906
  // src/index.ts
3822
3907
  function createEcomwebSdk(options) {
@@ -3832,7 +3917,6 @@ function createEcomwebSdk(options) {
3832
3917
  themes: new ThemesApi(publicHttp),
3833
3918
  metaobjects: new MetaobjectsApi(publicHttp, authHttp),
3834
3919
  search: new SearchApi(publicHttp),
3835
- banners: new BannersApi(publicHttp),
3836
3920
  shipping: new ShippingApi(publicHttp),
3837
3921
  promotions: new PromotionsApi(publicHttp),
3838
3922
  paymentMethods: new PaymentMethodsApi(publicHttp),
@@ -3851,7 +3935,6 @@ export {
3851
3935
  AddressesApi,
3852
3936
  ApiClientError,
3853
3937
  AuthApi,
3854
- BannersApi,
3855
3938
  BlogApi,
3856
3939
  COLLECTION_RULE_MATRIX,
3857
3940
  CONDITION_TYPE_LABELS,
@@ -3899,6 +3982,7 @@ export {
3899
3982
  OBJECT_PREFIX,
3900
3983
  ORDER_ACTOR_TYPES,
3901
3984
  ORDER_EVENT_TYPES,
3985
+ ORDER_SHIPMENT_ERROR_CODES,
3902
3986
  ORDER_SOURCES,
3903
3987
  OrdersApi,
3904
3988
  PAGINATION_DEFAULTS,
@@ -3931,8 +4015,10 @@ export {
3931
4015
  RULE_FIELDS,
3932
4016
  RedirectsApi,
3933
4017
  ReviewsApi,
4018
+ SHIPMENT_STATUSES,
3934
4019
  SHIPPING_CONDITION_TYPES,
3935
4020
  SHIPPING_DELIVERY_TYPES,
4021
+ SHIPPING_ERROR_CODES,
3936
4022
  SHIPPING_RATE_TYPES,
3937
4023
  SearchApi,
3938
4024
  ShippingApi,
@@ -3946,10 +4032,10 @@ export {
3946
4032
  allowedFileKinds,
3947
4033
  allowedValuesFor,
3948
4034
  appliedPromotionSchema,
4035
+ applyThemeMigration,
3949
4036
  assetBaseUrl,
3950
4037
  attributeLinkSchema,
3951
4038
  attributeLinkValueSchema,
3952
- bannerSchema,
3953
4039
  baseDeleteOptionsSchema,
3954
4040
  baseDeleteResultSchema,
3955
4041
  baseQueryParamsSchema,
@@ -3973,7 +4059,6 @@ export {
3973
4059
  compareDecimal,
3974
4060
  contentPageSchema,
3975
4061
  createAuthAwareHttpClient,
3976
- createBannerSchema,
3977
4062
  createBlogCategorySchema,
3978
4063
  createBlogCommentSchema,
3979
4064
  createBlogPostSchema,
@@ -4046,6 +4131,7 @@ export {
4046
4131
  paginationSchema,
4047
4132
  parseMetafieldIdentifier,
4048
4133
  parseStorageUrl,
4134
+ parseThemeMigration,
4049
4135
  parseThemeSchema,
4050
4136
  paymentMethodSchema,
4051
4137
  paymentStatusSchema,
@@ -4085,6 +4171,8 @@ export {
4085
4171
  storefrontAccessAllowed,
4086
4172
  strictUrlSchema,
4087
4173
  themeDefaults,
4174
+ themeMajor,
4175
+ themeMigrationSchema,
4088
4176
  themeSchemaSchema,
4089
4177
  themeSettings,
4090
4178
  timestampSchema,
@@ -4097,8 +4185,6 @@ export {
4097
4185
  unavailable,
4098
4186
  unwrap,
4099
4187
  unwrapOrNull,
4100
- updateBannerPositionSchema,
4101
- updateBannerSchema,
4102
4188
  updateBlogCategorySchema,
4103
4189
  updateBlogCommentSchema,
4104
4190
  updateBlogPostSchema,