@ecomweb/sdk 0.5.0 → 0.9.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(),
@@ -1197,38 +1196,14 @@ var blogCommentWithRepliesSchemaInner = z12.lazy(
1197
1196
  );
1198
1197
  var blogCommentWithRepliesSchema = blogCommentWithRepliesSchemaInner;
1199
1198
 
1200
- // src/types/banner.ts
1199
+ // src/types/content.ts
1201
1200
  import { z as z13 } from "zod";
1202
- var bannerSchema = z13.object({
1201
+ var contentPageSchema = z13.object({
1203
1202
  id: idSchema,
1204
1203
  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(),
1204
+ content: z13.string().optional().nullable(),
1205
+ is_published: z13.boolean().default(false),
1206
+ page_type: z13.string().optional().nullable(),
1232
1207
  sort_order: positionOrderSchema,
1233
1208
  slug: slugSchema.max(255)
1234
1209
  }).extend(timestampSchema.shape);
@@ -1244,87 +1219,92 @@ var updateContentPageSchema = contentPageSchema.omit({
1244
1219
  }).partial();
1245
1220
 
1246
1221
  // src/types/theme-schema.ts
1247
- import { z as z15 } from "zod";
1222
+ import { z as z14 } from "zod";
1248
1223
  var THEME_HEX_COLOR = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
1249
1224
  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),
1225
+ var primitive = z14.union([z14.string(), z14.number(), z14.boolean()]);
1226
+ var visibleIfSchema = z14.object({
1227
+ setting: z14.string().regex(SETTING_ID),
1253
1228
  equals: primitive.optional(),
1254
1229
  not_equals: primitive.optional(),
1255
- is_set: z15.boolean().optional()
1230
+ is_set: z14.boolean().optional()
1256
1231
  }).refine(
1257
1232
  (v) => [v.equals, v.not_equals, v.is_set].filter((x) => x !== void 0).length === 1,
1258
1233
  { message: "visible_if needs exactly one of equals, not_equals, is_set" }
1259
1234
  );
1260
1235
  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(),
1236
+ id: z14.string().regex(SETTING_ID, "setting ids are snake_case"),
1237
+ label: z14.string().min(1),
1238
+ info: z14.string().optional(),
1264
1239
  visible_if: visibleIfSchema.optional()
1265
1240
  };
1266
- var itemSchema = z15.discriminatedUnion("type", [
1267
- z15.object({
1241
+ var itemSchema = z14.discriminatedUnion("type", [
1242
+ z14.object({
1268
1243
  ...base,
1269
- type: z15.literal("text"),
1270
- default: z15.string().optional(),
1271
- placeholder: z15.string().optional()
1244
+ type: z14.literal("text"),
1245
+ default: z14.string().optional(),
1246
+ placeholder: z14.string().optional()
1272
1247
  }),
1273
- z15.object({
1248
+ z14.object({
1274
1249
  ...base,
1275
- type: z15.literal("textarea"),
1276
- default: z15.string().optional(),
1277
- placeholder: z15.string().optional()
1250
+ type: z14.literal("textarea"),
1251
+ default: z14.string().optional(),
1252
+ placeholder: z14.string().optional()
1278
1253
  }),
1279
- z15.object({
1254
+ z14.object({
1280
1255
  ...base,
1281
- type: z15.literal("richtext"),
1282
- default: z15.string().optional()
1256
+ type: z14.literal("richtext"),
1257
+ default: z14.string().optional()
1283
1258
  }),
1284
- z15.object({ ...base, type: z15.literal("url"), default: z15.string().optional() }),
1285
- z15.object({
1259
+ z14.object({ ...base, type: z14.literal("url"), default: z14.string().optional() }),
1260
+ z14.object({
1286
1261
  ...base,
1287
- type: z15.literal("color"),
1288
- default: z15.string().regex(THEME_HEX_COLOR).optional()
1262
+ type: z14.literal("color"),
1263
+ default: z14.string().regex(THEME_HEX_COLOR).optional()
1289
1264
  }),
1290
- z15.object({
1265
+ z14.object({
1291
1266
  ...base,
1292
- type: z15.literal("menu"),
1293
- default: z15.string().optional()
1267
+ type: z14.literal("menu"),
1268
+ default: z14.string().optional()
1294
1269
  }),
1295
- z15.object({ ...base, type: z15.literal("image_picker") }),
1296
- z15.object({ ...base, type: z15.literal("collection") }),
1297
- z15.object({
1270
+ z14.object({ ...base, type: z14.literal("image_picker") }),
1271
+ z14.object({ ...base, type: z14.literal("collection") }),
1272
+ z14.object({ ...base, type: z14.literal("page") }),
1273
+ z14.object({ ...base, type: z14.literal("blog_post") }),
1274
+ z14.object({ ...base, type: z14.literal("blog_category") }),
1275
+ z14.object({ ...base, type: z14.literal("blog_tag") }),
1276
+ z14.object({ ...base, type: z14.literal("product") }),
1277
+ z14.object({
1298
1278
  ...base,
1299
- type: z15.literal("checkbox"),
1300
- default: z15.boolean().optional()
1279
+ type: z14.literal("checkbox"),
1280
+ default: z14.boolean().optional()
1301
1281
  }),
1302
- z15.object({
1282
+ z14.object({
1303
1283
  ...base,
1304
- type: z15.literal("number"),
1305
- default: z15.number().optional(),
1306
- min: z15.number().optional(),
1307
- max: z15.number().optional()
1284
+ type: z14.literal("number"),
1285
+ default: z14.number().optional(),
1286
+ min: z14.number().optional(),
1287
+ max: z14.number().optional()
1308
1288
  }),
1309
- z15.object({
1289
+ z14.object({
1310
1290
  ...base,
1311
- type: z15.literal("range"),
1312
- min: z15.number(),
1313
- max: z15.number(),
1314
- step: z15.number().positive(),
1315
- unit: z15.string().optional(),
1316
- default: z15.number()
1291
+ type: z14.literal("range"),
1292
+ min: z14.number(),
1293
+ max: z14.number(),
1294
+ step: z14.number().positive(),
1295
+ unit: z14.string().optional(),
1296
+ default: z14.number()
1317
1297
  }),
1318
- z15.object({
1298
+ z14.object({
1319
1299
  ...base,
1320
- type: z15.literal("select"),
1321
- options: z15.array(z15.object({ value: z15.string(), label: z15.string().min(1) })).min(1),
1322
- default: z15.string().optional()
1300
+ type: z14.literal("select"),
1301
+ options: z14.array(z14.object({ value: z14.string(), label: z14.string().min(1) })).min(1),
1302
+ default: z14.string().optional()
1323
1303
  }),
1324
- z15.object({ type: z15.literal("header"), content: z15.string().min(1) }),
1325
- z15.object({ type: z15.literal("paragraph"), content: z15.string().min(1) })
1304
+ z14.object({ type: z14.literal("header"), content: z14.string().min(1) }),
1305
+ z14.object({ type: z14.literal("paragraph"), content: z14.string().min(1) })
1326
1306
  ]);
1327
- var themeSchemaSchema = z15.array(z15.object({ name: z15.string().min(1), settings: z15.array(itemSchema) })).superRefine((groups, ctx) => {
1307
+ var themeSchemaSchema = z14.array(z14.object({ name: z14.string().min(1), settings: z14.array(itemSchema) })).superRefine((groups, ctx) => {
1328
1308
  const settings = groups.flatMap((g) => g.settings).filter(isSetting);
1329
1309
  const ids = /* @__PURE__ */ new Set();
1330
1310
  for (const s of settings) {
@@ -1386,7 +1366,7 @@ function parseThemeSchema(input) {
1386
1366
  const result = themeSchemaSchema.safeParse(input);
1387
1367
  if (!result.success) {
1388
1368
  throw new Error(`Invalid theme schema:
1389
- ${z15.prettifyError(result.error)}`);
1369
+ ${z14.prettifyError(result.error)}`);
1390
1370
  }
1391
1371
  return result.data;
1392
1372
  }
@@ -1462,6 +1442,99 @@ function isSettingVisible(setting, values) {
1462
1442
  if (rule.equals !== void 0) return value === rule.equals;
1463
1443
  return value !== rule.not_equals;
1464
1444
  }
1445
+ function themeMajor(version) {
1446
+ const match = /^(\d+)\.\d+\.\d+$/.exec(version ?? "");
1447
+ return match ? Number(match[1]) : null;
1448
+ }
1449
+ var migrationValue = z14.union([z14.string(), z14.number(), z14.boolean()]);
1450
+ var migrationKey = z14.string().regex(SETTING_ID);
1451
+ var themeMigrationSchema = z14.object({
1452
+ from: z14.number().int().min(1),
1453
+ steps: z14.array(
1454
+ z14.discriminatedUnion("op", [
1455
+ z14.object({
1456
+ op: z14.literal("rename"),
1457
+ from: migrationKey,
1458
+ to: migrationKey
1459
+ }).strict(),
1460
+ z14.object({ op: z14.literal("remove"), key: migrationKey }).strict(),
1461
+ z14.object({
1462
+ op: z14.literal("map"),
1463
+ key: migrationKey,
1464
+ values: z14.record(z14.string(), migrationValue)
1465
+ }).strict(),
1466
+ z14.object({
1467
+ op: z14.literal("copy"),
1468
+ from: migrationKey,
1469
+ to: migrationKey
1470
+ }).strict(),
1471
+ z14.object({
1472
+ op: z14.literal("default"),
1473
+ key: migrationKey,
1474
+ value: migrationValue
1475
+ }).strict()
1476
+ ])
1477
+ ).max(500)
1478
+ }).strict();
1479
+ function parseThemeMigration(input) {
1480
+ const result = themeMigrationSchema.safeParse(input);
1481
+ if (!result.success) {
1482
+ const issues = result.error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
1483
+ throw new Error(`Invalid theme migration: ${issues}`);
1484
+ }
1485
+ return result.data;
1486
+ }
1487
+ function present(values, key) {
1488
+ return Object.prototype.hasOwnProperty.call(values, key) && values[key] !== void 0;
1489
+ }
1490
+ function applyThemeMigration(input, migration) {
1491
+ const values = { ...input };
1492
+ const report = {
1493
+ renamed: [],
1494
+ removed: [],
1495
+ mapped: [],
1496
+ copied: [],
1497
+ defaulted: []
1498
+ };
1499
+ for (const step of migration.steps) {
1500
+ switch (step.op) {
1501
+ case "rename":
1502
+ if (step.from === step.to || !present(values, step.from)) break;
1503
+ values[step.to] = values[step.from];
1504
+ delete values[step.from];
1505
+ report.renamed.push({ from: step.from, to: step.to });
1506
+ break;
1507
+ case "remove":
1508
+ if (!present(values, step.key)) break;
1509
+ delete values[step.key];
1510
+ report.removed.push(step.key);
1511
+ break;
1512
+ case "map": {
1513
+ const value = values[step.key];
1514
+ if (typeof value === "string" && Object.prototype.hasOwnProperty.call(step.values, value)) {
1515
+ values[step.key] = step.values[value];
1516
+ report.mapped.push({
1517
+ key: step.key,
1518
+ from: value,
1519
+ to: step.values[value]
1520
+ });
1521
+ }
1522
+ break;
1523
+ }
1524
+ case "copy":
1525
+ if (step.from === step.to || !present(values, step.from)) break;
1526
+ values[step.to] = values[step.from];
1527
+ report.copied.push({ from: step.from, to: step.to });
1528
+ break;
1529
+ case "default":
1530
+ if (present(values, step.key) && values[step.key] !== null) break;
1531
+ values[step.key] = step.value;
1532
+ report.defaulted.push(step.key);
1533
+ break;
1534
+ }
1535
+ }
1536
+ return { values, report };
1537
+ }
1465
1538
 
1466
1539
  // src/types/metafield-engine.ts
1467
1540
  var METAFIELD_OWNER_TYPES = [
@@ -3123,6 +3196,13 @@ var ThemesApi = class {
3123
3196
  );
3124
3197
  return unwrapOrNull(res, NO_PREVIEW);
3125
3198
  }
3199
+ /** The theme on a preview host, p-<slug>, with its saved values. */
3200
+ async getPreviewBySlug(storeRef, slug) {
3201
+ const res = await this.http.get(
3202
+ `/public/stores/${storeRef}/theme-preview?slug=${encodeURIComponent(slug)}`
3203
+ );
3204
+ return unwrapOrNull(res, NO_PREVIEW);
3205
+ }
3126
3206
  };
3127
3207
 
3128
3208
  // src/modules/metaobjects/api.ts
@@ -3189,20 +3269,6 @@ var SearchApi = class {
3189
3269
  }
3190
3270
  };
3191
3271
 
3192
- // src/modules/banners/api.ts
3193
- var BannersApi = class {
3194
- constructor(http) {
3195
- this.http = http;
3196
- }
3197
- async getPaginated(storeRef, query) {
3198
- const queryString = stringify(query ?? {});
3199
- const res = await this.http.get(
3200
- `/public/stores/${storeRef}/banners${queryString ? "?" + queryString : ""}`
3201
- );
3202
- return unwrap(res);
3203
- }
3204
- };
3205
-
3206
3272
  // src/modules/shipping/api.ts
3207
3273
  var ShippingApi = class {
3208
3274
  constructor(http) {
@@ -3827,7 +3893,6 @@ function createEcomwebSdk(options) {
3827
3893
  themes: new ThemesApi(publicHttp),
3828
3894
  metaobjects: new MetaobjectsApi(publicHttp, authHttp),
3829
3895
  search: new SearchApi(publicHttp),
3830
- banners: new BannersApi(publicHttp),
3831
3896
  shipping: new ShippingApi(publicHttp),
3832
3897
  promotions: new PromotionsApi(publicHttp),
3833
3898
  paymentMethods: new PaymentMethodsApi(publicHttp),
@@ -3846,7 +3911,6 @@ export {
3846
3911
  AddressesApi,
3847
3912
  ApiClientError,
3848
3913
  AuthApi,
3849
- BannersApi,
3850
3914
  BlogApi,
3851
3915
  COLLECTION_RULE_MATRIX,
3852
3916
  CONDITION_TYPE_LABELS,
@@ -3941,10 +4005,10 @@ export {
3941
4005
  allowedFileKinds,
3942
4006
  allowedValuesFor,
3943
4007
  appliedPromotionSchema,
4008
+ applyThemeMigration,
3944
4009
  assetBaseUrl,
3945
4010
  attributeLinkSchema,
3946
4011
  attributeLinkValueSchema,
3947
- bannerSchema,
3948
4012
  baseDeleteOptionsSchema,
3949
4013
  baseDeleteResultSchema,
3950
4014
  baseQueryParamsSchema,
@@ -3968,7 +4032,6 @@ export {
3968
4032
  compareDecimal,
3969
4033
  contentPageSchema,
3970
4034
  createAuthAwareHttpClient,
3971
- createBannerSchema,
3972
4035
  createBlogCategorySchema,
3973
4036
  createBlogCommentSchema,
3974
4037
  createBlogPostSchema,
@@ -4041,6 +4104,7 @@ export {
4041
4104
  paginationSchema,
4042
4105
  parseMetafieldIdentifier,
4043
4106
  parseStorageUrl,
4107
+ parseThemeMigration,
4044
4108
  parseThemeSchema,
4045
4109
  paymentMethodSchema,
4046
4110
  paymentStatusSchema,
@@ -4080,6 +4144,8 @@ export {
4080
4144
  storefrontAccessAllowed,
4081
4145
  strictUrlSchema,
4082
4146
  themeDefaults,
4147
+ themeMajor,
4148
+ themeMigrationSchema,
4083
4149
  themeSchemaSchema,
4084
4150
  themeSettings,
4085
4151
  timestampSchema,
@@ -4092,8 +4158,6 @@ export {
4092
4158
  unavailable,
4093
4159
  unwrap,
4094
4160
  unwrapOrNull,
4095
- updateBannerPositionSchema,
4096
- updateBannerSchema,
4097
4161
  updateBlogCategorySchema,
4098
4162
  updateBlogCommentSchema,
4099
4163
  updateBlogPostSchema,