@ecomweb/sdk 0.6.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,92 +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({ ...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({
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({
1303
1278
  ...base,
1304
- type: z15.literal("checkbox"),
1305
- default: z15.boolean().optional()
1279
+ type: z14.literal("checkbox"),
1280
+ default: z14.boolean().optional()
1306
1281
  }),
1307
- z15.object({
1282
+ z14.object({
1308
1283
  ...base,
1309
- type: z15.literal("number"),
1310
- default: z15.number().optional(),
1311
- min: z15.number().optional(),
1312
- max: z15.number().optional()
1284
+ type: z14.literal("number"),
1285
+ default: z14.number().optional(),
1286
+ min: z14.number().optional(),
1287
+ max: z14.number().optional()
1313
1288
  }),
1314
- z15.object({
1289
+ z14.object({
1315
1290
  ...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()
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()
1322
1297
  }),
1323
- z15.object({
1298
+ z14.object({
1324
1299
  ...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()
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()
1328
1303
  }),
1329
- z15.object({ type: z15.literal("header"), content: z15.string().min(1) }),
1330
- 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) })
1331
1306
  ]);
1332
- 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) => {
1333
1308
  const settings = groups.flatMap((g) => g.settings).filter(isSetting);
1334
1309
  const ids = /* @__PURE__ */ new Set();
1335
1310
  for (const s of settings) {
@@ -1391,7 +1366,7 @@ function parseThemeSchema(input) {
1391
1366
  const result = themeSchemaSchema.safeParse(input);
1392
1367
  if (!result.success) {
1393
1368
  throw new Error(`Invalid theme schema:
1394
- ${z15.prettifyError(result.error)}`);
1369
+ ${z14.prettifyError(result.error)}`);
1395
1370
  }
1396
1371
  return result.data;
1397
1372
  }
@@ -1467,6 +1442,99 @@ function isSettingVisible(setting, values) {
1467
1442
  if (rule.equals !== void 0) return value === rule.equals;
1468
1443
  return value !== rule.not_equals;
1469
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
+ }
1470
1538
 
1471
1539
  // src/types/metafield-engine.ts
1472
1540
  var METAFIELD_OWNER_TYPES = [
@@ -3128,6 +3196,13 @@ var ThemesApi = class {
3128
3196
  );
3129
3197
  return unwrapOrNull(res, NO_PREVIEW);
3130
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
+ }
3131
3206
  };
3132
3207
 
3133
3208
  // src/modules/metaobjects/api.ts
@@ -3194,20 +3269,6 @@ var SearchApi = class {
3194
3269
  }
3195
3270
  };
3196
3271
 
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
3272
  // src/modules/shipping/api.ts
3212
3273
  var ShippingApi = class {
3213
3274
  constructor(http) {
@@ -3832,7 +3893,6 @@ function createEcomwebSdk(options) {
3832
3893
  themes: new ThemesApi(publicHttp),
3833
3894
  metaobjects: new MetaobjectsApi(publicHttp, authHttp),
3834
3895
  search: new SearchApi(publicHttp),
3835
- banners: new BannersApi(publicHttp),
3836
3896
  shipping: new ShippingApi(publicHttp),
3837
3897
  promotions: new PromotionsApi(publicHttp),
3838
3898
  paymentMethods: new PaymentMethodsApi(publicHttp),
@@ -3851,7 +3911,6 @@ export {
3851
3911
  AddressesApi,
3852
3912
  ApiClientError,
3853
3913
  AuthApi,
3854
- BannersApi,
3855
3914
  BlogApi,
3856
3915
  COLLECTION_RULE_MATRIX,
3857
3916
  CONDITION_TYPE_LABELS,
@@ -3946,10 +4005,10 @@ export {
3946
4005
  allowedFileKinds,
3947
4006
  allowedValuesFor,
3948
4007
  appliedPromotionSchema,
4008
+ applyThemeMigration,
3949
4009
  assetBaseUrl,
3950
4010
  attributeLinkSchema,
3951
4011
  attributeLinkValueSchema,
3952
- bannerSchema,
3953
4012
  baseDeleteOptionsSchema,
3954
4013
  baseDeleteResultSchema,
3955
4014
  baseQueryParamsSchema,
@@ -3973,7 +4032,6 @@ export {
3973
4032
  compareDecimal,
3974
4033
  contentPageSchema,
3975
4034
  createAuthAwareHttpClient,
3976
- createBannerSchema,
3977
4035
  createBlogCategorySchema,
3978
4036
  createBlogCommentSchema,
3979
4037
  createBlogPostSchema,
@@ -4046,6 +4104,7 @@ export {
4046
4104
  paginationSchema,
4047
4105
  parseMetafieldIdentifier,
4048
4106
  parseStorageUrl,
4107
+ parseThemeMigration,
4049
4108
  parseThemeSchema,
4050
4109
  paymentMethodSchema,
4051
4110
  paymentStatusSchema,
@@ -4085,6 +4144,8 @@ export {
4085
4144
  storefrontAccessAllowed,
4086
4145
  strictUrlSchema,
4087
4146
  themeDefaults,
4147
+ themeMajor,
4148
+ themeMigrationSchema,
4088
4149
  themeSchemaSchema,
4089
4150
  themeSettings,
4090
4151
  timestampSchema,
@@ -4097,8 +4158,6 @@ export {
4097
4158
  unavailable,
4098
4159
  unwrap,
4099
4160
  unwrapOrNull,
4100
- updateBannerPositionSchema,
4101
- updateBannerSchema,
4102
4161
  updateBlogCategorySchema,
4103
4162
  updateBlogCommentSchema,
4104
4163
  updateBlogPostSchema,