@01.software/sdk 0.22.0 → 0.24.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.
Files changed (44) hide show
  1. package/README.md +101 -71
  2. package/dist/analytics.cjs.map +1 -1
  3. package/dist/analytics.js.map +1 -1
  4. package/dist/const-CMdmNgEs.d.ts +34 -0
  5. package/dist/const-Cgd4op4V.d.cts +34 -0
  6. package/dist/index.cjs +50 -8
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +7 -7
  9. package/dist/index.d.ts +7 -7
  10. package/dist/index.js +50 -8
  11. package/dist/index.js.map +1 -1
  12. package/dist/{payload-types-DeLBmtzd.d.cts → payload-types-D8-G1PiT.d.cts} +129 -8
  13. package/dist/{payload-types-DeLBmtzd.d.ts → payload-types-D8-G1PiT.d.ts} +129 -8
  14. package/dist/realtime.cjs.map +1 -1
  15. package/dist/realtime.d.cts +2 -2
  16. package/dist/realtime.d.ts +2 -2
  17. package/dist/realtime.js.map +1 -1
  18. package/dist/{server-BARh_6zH.d.ts → server-D7FcHj7J.d.ts} +35 -12
  19. package/dist/{server-BcQr-nGn.d.cts → server-DJcDyOmM.d.cts} +35 -12
  20. package/dist/server.cjs +9 -1
  21. package/dist/server.cjs.map +1 -1
  22. package/dist/server.d.cts +4 -4
  23. package/dist/server.d.ts +4 -4
  24. package/dist/server.js +9 -1
  25. package/dist/server.js.map +1 -1
  26. package/dist/{types-D7iFEsPc.d.cts → types-BQqfXbB2.d.ts} +18 -2
  27. package/dist/{types-KkuKwsli.d.ts → types-C_kwEIvY.d.cts} +18 -2
  28. package/dist/ui/code-block.cjs.map +1 -1
  29. package/dist/ui/code-block.js.map +1 -1
  30. package/dist/ui/form.d.cts +1 -1
  31. package/dist/ui/form.d.ts +1 -1
  32. package/dist/ui/rich-text.cjs +170 -10
  33. package/dist/ui/rich-text.cjs.map +1 -1
  34. package/dist/ui/rich-text.d.cts +22 -3
  35. package/dist/ui/rich-text.d.ts +22 -3
  36. package/dist/ui/rich-text.js +165 -5
  37. package/dist/ui/rich-text.js.map +1 -1
  38. package/dist/ui/video.d.cts +1 -1
  39. package/dist/ui/video.d.ts +1 -1
  40. package/dist/webhook.d.cts +3 -3
  41. package/dist/webhook.d.ts +3 -3
  42. package/package.json +5 -4
  43. package/dist/const-CfcjPbOu.d.ts +0 -24
  44. package/dist/const-DraU44bA.d.cts +0 -24
package/dist/index.cjs CHANGED
@@ -52,7 +52,11 @@ __export(src_exports, {
52
52
  ReadOnlyCollectionClient: () => ReadOnlyCollectionClient,
53
53
  RealtimeConnection: () => RealtimeConnection,
54
54
  SDKError: () => SDKError,
55
+ SERVER_COLLECTIONS: () => SERVER_COLLECTIONS,
56
+ SERVER_ONLY_COLLECTIONS: () => SERVER_ONLY_COLLECTIONS,
55
57
  ServerClient: () => ServerClient,
58
+ ServerCollectionClient: () => ServerCollectionClient,
59
+ ServerCollectionQueryBuilder: () => ServerCollectionQueryBuilder,
56
60
  ServerCommerceClient: () => ServerCommerceClient,
57
61
  ServiceUnavailableError: () => ServiceUnavailableError,
58
62
  ShippingApi: () => ShippingApi,
@@ -349,6 +353,8 @@ var CollectionQueryBuilder = class {
349
353
  );
350
354
  }
351
355
  };
356
+ var ServerCollectionQueryBuilder = class extends CollectionQueryBuilder {
357
+ };
352
358
 
353
359
  // src/core/collection/http-client.ts
354
360
  var import_qs_esm = require("qs-esm");
@@ -1187,6 +1193,11 @@ var CollectionClient = class extends HttpClient {
1187
1193
  return this.parseMutationResponse(response);
1188
1194
  }
1189
1195
  };
1196
+ var ServerCollectionClient = class extends CollectionClient {
1197
+ from(collection) {
1198
+ return new ServerCollectionQueryBuilder(this, collection);
1199
+ }
1200
+ };
1190
1201
  var ReadOnlyCollectionClient = class extends HttpClient {
1191
1202
  from(collection) {
1192
1203
  return new ReadOnlyCollectionQueryBuilder(this, collection);
@@ -1268,8 +1279,8 @@ var COLLECTIONS = [
1268
1279
  "transactions",
1269
1280
  "customers",
1270
1281
  "customer-profiles",
1282
+ "customer-profile-lists",
1271
1283
  "customer-addresses",
1272
- "customer-groups",
1273
1284
  "carts",
1274
1285
  "cart-items",
1275
1286
  "discounts",
@@ -1325,6 +1336,11 @@ var COLLECTIONS = [
1325
1336
  "event-occurrences",
1326
1337
  "event-tags"
1327
1338
  ];
1339
+ var SERVER_ONLY_COLLECTIONS = ["customer-groups"];
1340
+ var SERVER_COLLECTIONS = [
1341
+ ...COLLECTIONS,
1342
+ ...SERVER_ONLY_COLLECTIONS
1343
+ ];
1328
1344
 
1329
1345
  // src/core/api/parse-response.ts
1330
1346
  async function parseApiResponse(response, endpoint) {
@@ -2725,7 +2741,7 @@ var ServerClient = class {
2725
2741
  unbanCustomer: moderationApi.unbanCustomer.bind(moderationApi)
2726
2742
  }
2727
2743
  });
2728
- this.collections = new CollectionClient(
2744
+ this.collections = new ServerCollectionClient(
2729
2745
  this.config.publishableKey,
2730
2746
  this.config.secretKey,
2731
2747
  void 0,
@@ -3047,12 +3063,24 @@ function getVariantPrimaryImage(variant) {
3047
3063
  if (!variant) return null;
3048
3064
  return extractEntityId(variant.thumbnail) ?? getFirstMediaId(variant.images);
3049
3065
  }
3066
+ function getFirstAvailableVariantPrimaryImage(variants) {
3067
+ const orderedVariants = [...variants].sort(compareVariantOrder);
3068
+ for (const variant of orderedVariants) {
3069
+ if (!isVariantAvailableForSale(variant)) continue;
3070
+ const image = getVariantPrimaryImage(variant);
3071
+ if (image != null) return image;
3072
+ }
3073
+ return null;
3074
+ }
3050
3075
  function normalizeOptionValue(value, fallbackOptionId) {
3051
3076
  return {
3052
3077
  id: String(value.id),
3053
3078
  optionId: getRelationID(value.option) ?? fallbackOptionId,
3054
3079
  label: value.value || value.slug || String(value.id),
3055
3080
  slug: value.slug ?? null,
3081
+ swatchColor: value.swatchColor ?? null,
3082
+ thumbnail: value.thumbnail ?? null,
3083
+ images: value.images ?? null,
3056
3084
  order: value._order ?? value["_product-option-values_values_order"] ?? ""
3057
3085
  };
3058
3086
  }
@@ -3081,7 +3109,10 @@ function buildProductOptionMatrix({
3081
3109
  const valuesById = /* @__PURE__ */ new Map();
3082
3110
  for (const rawValue of option.values?.docs ?? []) {
3083
3111
  if (!isProductOptionValueDoc(rawValue)) continue;
3084
- const normalizedValue = normalizeOptionValue(rawValue, String(option.id));
3112
+ const normalizedValue = normalizeOptionValue(
3113
+ rawValue,
3114
+ String(option.id)
3115
+ );
3085
3116
  valuesById.set(normalizedValue.id, normalizedValue);
3086
3117
  }
3087
3118
  return {
@@ -3093,7 +3124,9 @@ function buildProductOptionMatrix({
3093
3124
  )
3094
3125
  };
3095
3126
  }).sort((left, right) => compareOrder(left.order, right.order));
3096
- const optionById = new Map(normalizedOptions.map((option) => [option.id, option]));
3127
+ const optionById = new Map(
3128
+ normalizedOptions.map((option) => [option.id, option])
3129
+ );
3097
3130
  const valueById = /* @__PURE__ */ new Map();
3098
3131
  const valueToOptionId = /* @__PURE__ */ new Map();
3099
3132
  for (const option of normalizedOptions) {
@@ -3172,10 +3205,12 @@ function compareVariantOrder(a, b) {
3172
3205
  function isVariantAvailableForSale(variant) {
3173
3206
  if (variant.isActive === false) return false;
3174
3207
  if (variant.isUnlimited) return true;
3175
- return (variant.stock ?? 0) > 0;
3208
+ return (variant.stock ?? 0) - (variant.reservedStock ?? 0) > 0;
3176
3209
  }
3177
3210
  function getMinMax(values) {
3178
- const numbers = values.filter((value) => typeof value === "number");
3211
+ const numbers = values.filter(
3212
+ (value) => typeof value === "number"
3213
+ );
3179
3214
  if (numbers.length === 0) {
3180
3215
  return { min: null, max: null };
3181
3216
  }
@@ -3186,7 +3221,9 @@ function getMinMax(values) {
3186
3221
  }
3187
3222
  function buildProductListingProjection(product, variants) {
3188
3223
  const orderedVariants = [...variants].sort(compareVariantOrder);
3189
- const activeVariants = orderedVariants.filter((variant) => variant.isActive !== false);
3224
+ const activeVariants = orderedVariants.filter(
3225
+ (variant) => variant.isActive !== false
3226
+ );
3190
3227
  const availableVariants = activeVariants.filter(isVariantAvailableForSale);
3191
3228
  const selectionHintVariant = availableVariants[0] ?? activeVariants[0] ?? null;
3192
3229
  const { min: minPrice, max: maxPrice } = getMinMax(
@@ -3225,7 +3262,9 @@ function buildProductListingGroupsByOption(args) {
3225
3262
  return [];
3226
3263
  }
3227
3264
  const listingBase = buildProductListingProjection(void 0, variants);
3265
+ const optionValuePrimaryImage = extractEntityId(value.thumbnail) ?? getFirstMediaId(value.images);
3228
3266
  const productFallbackImage = extractEntityId(args.product?.thumbnail) ?? getFirstMediaId(args.product?.images);
3267
+ const groupPrimaryImage = getFirstAvailableVariantPrimaryImage(variants) ?? optionValuePrimaryImage ?? productFallbackImage;
3229
3268
  return [
3230
3269
  {
3231
3270
  optionId: primaryOption.id,
@@ -3233,12 +3272,15 @@ function buildProductListingGroupsByOption(args) {
3233
3272
  optionValueId: value.id,
3234
3273
  optionValueLabel: value.label,
3235
3274
  optionValueSlug: value.slug,
3275
+ optionValueSwatchColor: value.swatchColor ?? null,
3276
+ optionValueThumbnail: value.thumbnail ?? null,
3277
+ optionValueImages: value.images ?? null,
3236
3278
  variantIds: variants.map((variant) => String(variant.id)),
3237
3279
  variantCount: variants.length,
3238
3280
  variants,
3239
3281
  listing: {
3240
3282
  ...listingBase,
3241
- primaryImage: listingBase.primaryImage ?? productFallbackImage
3283
+ primaryImage: groupPrimaryImage
3242
3284
  }
3243
3285
  }
3244
3286
  ];