@ecomiq/core 1.1.1 → 1.2.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 (32) hide show
  1. package/README.md +16 -2
  2. package/dist/client.cjs +180 -23
  3. package/dist/client.d.cts +8 -2
  4. package/dist/client.d.ts +8 -2
  5. package/dist/client.js +183 -26
  6. package/dist/index.cjs +8 -3
  7. package/dist/index.d.cts +3 -3
  8. package/dist/index.d.ts +3 -3
  9. package/dist/index.js +6 -6
  10. package/dist/libs/{graphql-_6Y8lR_Q.js → graphql-8PZkrq66.js} +12 -8
  11. package/dist/libs/{graphql-wJH7HaQU.cjs → graphql-BICZrYlZ.cjs} +12 -7
  12. package/dist/libs/graphql-batch-AFRui-4Y.js +125 -0
  13. package/dist/libs/graphql-batch-B0xSD6G2.cjs +125 -0
  14. package/dist/libs/graphql-batch.d.cts +2 -0
  15. package/dist/libs/graphql-batch.d.ts +2 -0
  16. package/dist/models/collections.cjs +5 -0
  17. package/dist/models/collections.d.cts +109 -1
  18. package/dist/models/collections.d.ts +109 -1
  19. package/dist/models/collections.js +4 -1
  20. package/dist/models/storefront-reviews.cjs +9 -2
  21. package/dist/models/storefront-reviews.d.cts +99 -0
  22. package/dist/models/storefront-reviews.d.ts +99 -0
  23. package/dist/models/storefront-reviews.js +7 -3
  24. package/dist/services/layout.service-C6zG6zY7.cjs +65 -0
  25. package/dist/services/layout.service-DufBhrOR.js +65 -0
  26. package/dist/services/layout.service.d.cts +1 -0
  27. package/dist/services/layout.service.d.ts +1 -0
  28. package/dist/services/{review.service-CO2icjpu.cjs → review.service-BgRGfq4t.cjs} +0 -8
  29. package/dist/services/{review.service-De1YkhFp.js → review.service-DMgxbO94.js} +2 -9
  30. package/package.json +1 -1
  31. package/dist/services/layout.service-BkvLzl1g.cjs +0 -50
  32. package/dist/services/layout.service-DmbeMOkK.js +0 -50
@@ -38,6 +38,14 @@ export declare const StorefrontReviewsSchema: z.ZodObject<{
38
38
  nextCursor: z.ZodNullable<z.ZodString>;
39
39
  totalCount: z.ZodNullable<z.ZodNumber>;
40
40
  }, z.core.$strip>;
41
+ export declare const ProductReviewSortSchema: z.ZodEnum<{
42
+ createdOn: "createdOn";
43
+ rating: "rating";
44
+ }>;
45
+ export declare const ProductReviewDirectionSchema: z.ZodEnum<{
46
+ asc: "asc";
47
+ desc: "desc";
48
+ }>;
41
49
  export declare const ListProductReviewsParamsSchema: z.ZodObject<{
42
50
  productId: z.ZodString;
43
51
  limit: z.ZodOptional<z.ZodNumber>;
@@ -53,6 +61,97 @@ export declare const ListProductReviewsParamsSchema: z.ZodObject<{
53
61
  }>>;
54
62
  rating: z.ZodOptional<z.ZodNumber>;
55
63
  }, z.core.$strip>;
64
+ export declare const ProductWithReviewsSchema: z.ZodObject<{
65
+ id: z.ZodString;
66
+ name: z.ZodString;
67
+ slug: z.ZodString;
68
+ url: z.ZodString;
69
+ productType: z.ZodString;
70
+ imageUrl: z.ZodString;
71
+ price: z.ZodNumber;
72
+ compareAtPrice: z.ZodNullable<z.ZodNumber>;
73
+ variantCount: z.ZodNumber;
74
+ isAvailable: z.ZodBoolean;
75
+ totalInventory: z.ZodNumber;
76
+ bundleItemsCount: z.ZodNumber;
77
+ brand: z.ZodString;
78
+ category: z.ZodString;
79
+ status: z.ZodString;
80
+ collections: z.ZodArray<z.ZodString>;
81
+ tags: z.ZodArray<z.ZodString>;
82
+ seller: z.ZodNullable<z.ZodObject<{
83
+ id: z.ZodString;
84
+ name: z.ZodString;
85
+ slug: z.ZodString;
86
+ }, z.core.$strip>>;
87
+ options: z.ZodArray<z.ZodObject<{
88
+ key: z.ZodString;
89
+ name: z.ZodString;
90
+ type: z.ZodOptional<z.ZodEnum<{
91
+ checkbox: "checkbox";
92
+ colorPicker: "colorPicker";
93
+ datePicker: "datePicker";
94
+ dateTimePicker: "dateTimePicker";
95
+ file: "file";
96
+ input: "input";
97
+ number: "number";
98
+ select: "select";
99
+ textArea: "textArea";
100
+ timePicker: "timePicker";
101
+ url: "url";
102
+ }>>;
103
+ values: z.ZodArray<z.ZodObject<{
104
+ key: z.ZodString;
105
+ name: z.ZodString;
106
+ value: z.ZodString;
107
+ valueId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
108
+ valueName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
109
+ type: z.ZodOptional<z.ZodEnum<{
110
+ checkbox: "checkbox";
111
+ colorPicker: "colorPicker";
112
+ datePicker: "datePicker";
113
+ dateTimePicker: "dateTimePicker";
114
+ file: "file";
115
+ input: "input";
116
+ number: "number";
117
+ select: "select";
118
+ textArea: "textArea";
119
+ timePicker: "timePicker";
120
+ url: "url";
121
+ }>>;
122
+ color: z.ZodOptional<z.ZodNullable<z.ZodString>>;
123
+ imageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
124
+ unit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
125
+ }, z.core.$strip>>;
126
+ }, z.core.$strip>>;
127
+ images: z.ZodArray<z.ZodObject<{
128
+ url: z.ZodString;
129
+ name: z.ZodString;
130
+ order: z.ZodNumber;
131
+ type: z.ZodDefault<z.ZodCatch<z.ZodEnum<{
132
+ image: "image";
133
+ video: "video";
134
+ }>>>;
135
+ }, z.core.$strip>>;
136
+ availableVariantId: z.ZodNullable<z.ZodString>;
137
+ hasModifierGroups: z.ZodBoolean;
138
+ reviews: z.ZodArray<z.ZodObject<{
139
+ id: z.ZodString;
140
+ productId: z.ZodString;
141
+ isVerifiedPurchase: z.ZodBoolean;
142
+ rating: z.ZodNumber;
143
+ title: z.ZodNullable<z.ZodString>;
144
+ content: z.ZodString;
145
+ reviewerName: z.ZodNullable<z.ZodString>;
146
+ createdOn: z.ZodString;
147
+ }, z.core.$strip>>;
148
+ }, z.core.$strip>;
149
+ export type ProductWithReviews = z.infer<typeof ProductWithReviewsSchema>;
150
+ export type ProductReviewsOptions = {
151
+ limit?: number;
152
+ sortBy?: z.infer<typeof ProductReviewSortSchema>;
153
+ sortDirection?: z.infer<typeof ProductReviewDirectionSchema>;
154
+ };
56
155
  export declare const CreateProductReviewParamsSchema: z.ZodObject<{
57
156
  productId: z.ZodString;
58
157
  rating: z.ZodNumber;
@@ -38,6 +38,14 @@ export declare const StorefrontReviewsSchema: z.ZodObject<{
38
38
  nextCursor: z.ZodNullable<z.ZodString>;
39
39
  totalCount: z.ZodNullable<z.ZodNumber>;
40
40
  }, z.core.$strip>;
41
+ export declare const ProductReviewSortSchema: z.ZodEnum<{
42
+ createdOn: "createdOn";
43
+ rating: "rating";
44
+ }>;
45
+ export declare const ProductReviewDirectionSchema: z.ZodEnum<{
46
+ asc: "asc";
47
+ desc: "desc";
48
+ }>;
41
49
  export declare const ListProductReviewsParamsSchema: z.ZodObject<{
42
50
  productId: z.ZodString;
43
51
  limit: z.ZodOptional<z.ZodNumber>;
@@ -53,6 +61,97 @@ export declare const ListProductReviewsParamsSchema: z.ZodObject<{
53
61
  }>>;
54
62
  rating: z.ZodOptional<z.ZodNumber>;
55
63
  }, z.core.$strip>;
64
+ export declare const ProductWithReviewsSchema: z.ZodObject<{
65
+ id: z.ZodString;
66
+ name: z.ZodString;
67
+ slug: z.ZodString;
68
+ url: z.ZodString;
69
+ productType: z.ZodString;
70
+ imageUrl: z.ZodString;
71
+ price: z.ZodNumber;
72
+ compareAtPrice: z.ZodNullable<z.ZodNumber>;
73
+ variantCount: z.ZodNumber;
74
+ isAvailable: z.ZodBoolean;
75
+ totalInventory: z.ZodNumber;
76
+ bundleItemsCount: z.ZodNumber;
77
+ brand: z.ZodString;
78
+ category: z.ZodString;
79
+ status: z.ZodString;
80
+ collections: z.ZodArray<z.ZodString>;
81
+ tags: z.ZodArray<z.ZodString>;
82
+ seller: z.ZodNullable<z.ZodObject<{
83
+ id: z.ZodString;
84
+ name: z.ZodString;
85
+ slug: z.ZodString;
86
+ }, z.core.$strip>>;
87
+ options: z.ZodArray<z.ZodObject<{
88
+ key: z.ZodString;
89
+ name: z.ZodString;
90
+ type: z.ZodOptional<z.ZodEnum<{
91
+ checkbox: "checkbox";
92
+ colorPicker: "colorPicker";
93
+ datePicker: "datePicker";
94
+ dateTimePicker: "dateTimePicker";
95
+ file: "file";
96
+ input: "input";
97
+ number: "number";
98
+ select: "select";
99
+ textArea: "textArea";
100
+ timePicker: "timePicker";
101
+ url: "url";
102
+ }>>;
103
+ values: z.ZodArray<z.ZodObject<{
104
+ key: z.ZodString;
105
+ name: z.ZodString;
106
+ value: z.ZodString;
107
+ valueId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
108
+ valueName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
109
+ type: z.ZodOptional<z.ZodEnum<{
110
+ checkbox: "checkbox";
111
+ colorPicker: "colorPicker";
112
+ datePicker: "datePicker";
113
+ dateTimePicker: "dateTimePicker";
114
+ file: "file";
115
+ input: "input";
116
+ number: "number";
117
+ select: "select";
118
+ textArea: "textArea";
119
+ timePicker: "timePicker";
120
+ url: "url";
121
+ }>>;
122
+ color: z.ZodOptional<z.ZodNullable<z.ZodString>>;
123
+ imageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
124
+ unit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
125
+ }, z.core.$strip>>;
126
+ }, z.core.$strip>>;
127
+ images: z.ZodArray<z.ZodObject<{
128
+ url: z.ZodString;
129
+ name: z.ZodString;
130
+ order: z.ZodNumber;
131
+ type: z.ZodDefault<z.ZodCatch<z.ZodEnum<{
132
+ image: "image";
133
+ video: "video";
134
+ }>>>;
135
+ }, z.core.$strip>>;
136
+ availableVariantId: z.ZodNullable<z.ZodString>;
137
+ hasModifierGroups: z.ZodBoolean;
138
+ reviews: z.ZodArray<z.ZodObject<{
139
+ id: z.ZodString;
140
+ productId: z.ZodString;
141
+ isVerifiedPurchase: z.ZodBoolean;
142
+ rating: z.ZodNumber;
143
+ title: z.ZodNullable<z.ZodString>;
144
+ content: z.ZodString;
145
+ reviewerName: z.ZodNullable<z.ZodString>;
146
+ createdOn: z.ZodString;
147
+ }, z.core.$strip>>;
148
+ }, z.core.$strip>;
149
+ export type ProductWithReviews = z.infer<typeof ProductWithReviewsSchema>;
150
+ export type ProductReviewsOptions = {
151
+ limit?: number;
152
+ sortBy?: z.infer<typeof ProductReviewSortSchema>;
153
+ sortDirection?: z.infer<typeof ProductReviewDirectionSchema>;
154
+ };
56
155
  export declare const CreateProductReviewParamsSchema: z.ZodObject<{
57
156
  productId: z.ZodString;
58
157
  rating: z.ZodNumber;
@@ -1,4 +1,5 @@
1
1
  import { EntityIdSchema } from "./ids.js";
2
+ import { ProductSummarySchema } from "./products.js";
2
3
  import { z } from "zod";
3
4
  // src/models/storefront-reviews.ts
4
5
  const StorefrontReviewSchema = z.object({
@@ -31,15 +32,18 @@ const StorefrontReviewsSchema = z.object({
31
32
  nextCursor: z.string().nullable(),
32
33
  totalCount: z.number().int().nonnegative().nullable()
33
34
  });
35
+ const ProductReviewSortSchema = z.enum(["rating", "createdOn"]);
36
+ const ProductReviewDirectionSchema = z.enum(["asc", "desc"]);
34
37
  const ListProductReviewsParamsSchema = z.object({
35
38
  productId: EntityIdSchema,
36
39
  limit: z.number().int().min(1).max(200).optional(),
37
40
  cursor: z.string().optional(),
38
41
  search: z.string().optional(),
39
- sortBy: z.enum(["rating", "createdOn"]).optional(),
40
- sortDirection: z.enum(["asc", "desc"]).optional(),
42
+ sortBy: ProductReviewSortSchema.optional(),
43
+ sortDirection: ProductReviewDirectionSchema.optional(),
41
44
  rating: z.number().int().min(1).max(5).optional()
42
45
  });
46
+ const ProductWithReviewsSchema = ProductSummarySchema.extend({ reviews: z.array(StorefrontReviewSchema) });
43
47
  const CreateProductReviewParamsSchema = z.object({
44
48
  productId: EntityIdSchema,
45
49
  rating: z.number().int().min(1).max(5),
@@ -57,4 +61,4 @@ const CreateCustomerProductReviewParamsSchema = z.object({
57
61
  title: z.string().max(200).optional(),
58
62
  reviewerName: z.string().min(1).max(200)
59
63
  });
60
- export { CreateCustomerProductReviewParamsSchema, CreateProductReviewParamsSchema, ListProductReviewsParamsSchema, ListStoreReviewsParamsSchema, StorefrontReviewSchema, StorefrontReviewsSchema, StorefrontStoreReviewSchema };
64
+ export { CreateCustomerProductReviewParamsSchema, CreateProductReviewParamsSchema, ListProductReviewsParamsSchema, ListStoreReviewsParamsSchema, ProductReviewDirectionSchema, ProductReviewSortSchema, ProductWithReviewsSchema, StorefrontReviewSchema, StorefrontReviewsSchema, StorefrontStoreReviewSchema };
@@ -0,0 +1,65 @@
1
+ const require_graphql_selection = require("../libs/graphql-selection-Cj51WkJn.cjs");
2
+ const require_catalog_links = require("../models/catalog-links-c4LADGf_.cjs");
3
+ const require_catalog_link_key = require("../libs/catalog-link-key-CZTHJBGD.cjs");
4
+ const require_models_collections = require("../models/collections.cjs");
5
+ const require_models_settings = require("../models/settings.cjs");
6
+ let zod = require("zod");
7
+ // src/services/layout.service.ts
8
+ const LinksSchema = zod.z.object({ links: zod.z.array(require_catalog_links.CatalogLinkSchema).nullable() });
9
+ const SETTINGS_FIELDS = require_graphql_selection.graphQLSelection(require_models_settings.StorefrontSettingsSchema);
10
+ const COLLECTION_FIELDS = require_graphql_selection.graphQLSelection(require_models_collections.CollectionSchema);
11
+ const LINK_FIELDS = require_graphql_selection.graphQLSelection(require_catalog_links.CatalogLinkSchema);
12
+ const LINKS = `query StorefrontLinks($links: [StorefrontLinkInput!]!) {
13
+ links(links: $links) { ${LINK_FIELDS} }
14
+ }`;
15
+ const SHARED_READ = { allowStale: false };
16
+ async function getLayout({ batcher, graphql, links }) {
17
+ const input = links.map(require_catalog_links.readCatalogLink);
18
+ const candidates = require_catalog_links.catalogLinkCandidates(input);
19
+ const first = candidates.slice(0, 100);
20
+ const settings = batcher.request({
21
+ field: "settings",
22
+ selection: SETTINGS_FIELDS,
23
+ schema: require_models_settings.StorefrontSettingsSchema
24
+ }, SHARED_READ);
25
+ const collections = batcher.request({
26
+ field: "collections",
27
+ selection: COLLECTION_FIELDS,
28
+ schema: require_models_collections.CollectionsSchema.nullable()
29
+ }, SHARED_READ).catch(() => null);
30
+ const firstLinks = first.length === 0 ? Promise.resolve(null) : batcher.request({
31
+ field: "links",
32
+ arguments: [{
33
+ name: "links",
34
+ type: "[StorefrontLinkInput!]!",
35
+ value: first
36
+ }],
37
+ selection: LINK_FIELDS,
38
+ schema: zod.z.array(require_catalog_links.CatalogLinkSchema).nullable()
39
+ }, SHARED_READ).catch(() => null);
40
+ const remaining = [];
41
+ for (let offset = 100; offset < candidates.length; offset += 100) {
42
+ const batch = candidates.slice(offset, offset + 100);
43
+ remaining.push(graphql(LINKS, LinksSchema, { links: batch }, SHARED_READ).then((result) => batch.map((link, index) => result.links?.[index] ?? link)).catch(() => batch));
44
+ }
45
+ const [resolvedSettings, resolvedCollections, resolvedLinks, batches] = await Promise.all([
46
+ settings,
47
+ collections,
48
+ firstLinks,
49
+ Promise.all(remaining)
50
+ ]);
51
+ const result = {
52
+ settings: resolvedSettings,
53
+ collections: resolvedCollections,
54
+ links: resolvedLinks
55
+ };
56
+ const resolved = /* @__PURE__ */ new Map();
57
+ const values = [...first.map((link, index) => result.links?.[index] ?? link), ...batches.flat()];
58
+ candidates.forEach((link, index) => resolved.set(require_catalog_link_key.catalogLinkKey(link), values[index] ?? link));
59
+ return {
60
+ settings: result.settings,
61
+ collections: result.collections ?? [],
62
+ links: input.map((link) => resolved.get(require_catalog_link_key.catalogLinkKey(link)) ?? link)
63
+ };
64
+ }
65
+ exports.getLayout = getLayout;
@@ -0,0 +1,65 @@
1
+ import { graphQLSelection } from "../libs/graphql-selection-H1RMh6VD.js";
2
+ import { CatalogLinkSchema, catalogLinkCandidates, readCatalogLink } from "../models/catalog-links-BzJeyBy4.js";
3
+ import { catalogLinkKey } from "../libs/catalog-link-key-B7l5KZsF.js";
4
+ import { CollectionSchema, CollectionsSchema } from "../models/collections.js";
5
+ import { StorefrontSettingsSchema } from "../models/settings.js";
6
+ import { z } from "zod";
7
+ // src/services/layout.service.ts
8
+ const LinksSchema = z.object({ links: z.array(CatalogLinkSchema).nullable() });
9
+ const SETTINGS_FIELDS = graphQLSelection(StorefrontSettingsSchema);
10
+ const COLLECTION_FIELDS = graphQLSelection(CollectionSchema);
11
+ const LINK_FIELDS = graphQLSelection(CatalogLinkSchema);
12
+ const LINKS = `query StorefrontLinks($links: [StorefrontLinkInput!]!) {
13
+ links(links: $links) { ${LINK_FIELDS} }
14
+ }`;
15
+ const SHARED_READ = { allowStale: false };
16
+ async function getLayout({ batcher, graphql, links }) {
17
+ const input = links.map(readCatalogLink);
18
+ const candidates = catalogLinkCandidates(input);
19
+ const first = candidates.slice(0, 100);
20
+ const settings = batcher.request({
21
+ field: "settings",
22
+ selection: SETTINGS_FIELDS,
23
+ schema: StorefrontSettingsSchema
24
+ }, SHARED_READ);
25
+ const collections = batcher.request({
26
+ field: "collections",
27
+ selection: COLLECTION_FIELDS,
28
+ schema: CollectionsSchema.nullable()
29
+ }, SHARED_READ).catch(() => null);
30
+ const firstLinks = first.length === 0 ? Promise.resolve(null) : batcher.request({
31
+ field: "links",
32
+ arguments: [{
33
+ name: "links",
34
+ type: "[StorefrontLinkInput!]!",
35
+ value: first
36
+ }],
37
+ selection: LINK_FIELDS,
38
+ schema: z.array(CatalogLinkSchema).nullable()
39
+ }, SHARED_READ).catch(() => null);
40
+ const remaining = [];
41
+ for (let offset = 100; offset < candidates.length; offset += 100) {
42
+ const batch = candidates.slice(offset, offset + 100);
43
+ remaining.push(graphql(LINKS, LinksSchema, { links: batch }, SHARED_READ).then((result) => batch.map((link, index) => result.links?.[index] ?? link)).catch(() => batch));
44
+ }
45
+ const [resolvedSettings, resolvedCollections, resolvedLinks, batches] = await Promise.all([
46
+ settings,
47
+ collections,
48
+ firstLinks,
49
+ Promise.all(remaining)
50
+ ]);
51
+ const result = {
52
+ settings: resolvedSettings,
53
+ collections: resolvedCollections,
54
+ links: resolvedLinks
55
+ };
56
+ const resolved = /* @__PURE__ */ new Map();
57
+ const values = [...first.map((link, index) => result.links?.[index] ?? link), ...batches.flat()];
58
+ candidates.forEach((link, index) => resolved.set(catalogLinkKey(link), values[index] ?? link));
59
+ return {
60
+ settings: result.settings,
61
+ collections: result.collections ?? [],
62
+ links: input.map((link) => resolved.get(catalogLinkKey(link)) ?? link)
63
+ };
64
+ }
65
+ export { getLayout };
@@ -1,4 +1,5 @@
1
1
  import "../client.cjs";
2
+ import "../libs/graphql-batch.cjs";
2
3
  import { CatalogLink } from "../models/catalog-links.cjs";
3
4
  import { Collections } from "../models/collections.cjs";
4
5
  import { StorefrontSettings } from "../models/settings.cjs";
@@ -1,4 +1,5 @@
1
1
  import "../client.js";
2
+ import "../libs/graphql-batch.js";
2
3
  import { CatalogLink } from "../models/catalog-links.js";
3
4
  import { Collections } from "../models/collections.js";
4
5
  import { StorefrontSettings } from "../models/settings.js";
@@ -11,13 +11,6 @@ async function listProductReviews(api, params) {
11
11
  rating: input.rating
12
12
  } });
13
13
  }
14
- async function listStoreReviews(api, params = {}) {
15
- const input = require_models_storefront_reviews.ListStoreReviewsParamsSchema.parse(params);
16
- return api.get("reviews", require_models_storefront_reviews.StorefrontStoreReviewSchema.array(), { query: {
17
- limit: input.limit,
18
- minRating: input.minRating
19
- } });
20
- }
21
14
  async function createProductReview(api, params) {
22
15
  const input = require_models_storefront_reviews.CreateProductReviewParamsSchema.parse(params);
23
16
  return api.post(`products/${encodeURIComponent(input.productId)}/reviews`, {
@@ -43,4 +36,3 @@ async function createCustomerProductReview(api, params, options) {
43
36
  exports.createCustomerProductReview = createCustomerProductReview;
44
37
  exports.createProductReview = createProductReview;
45
38
  exports.listProductReviews = listProductReviews;
46
- exports.listStoreReviews = listStoreReviews;
@@ -1,4 +1,4 @@
1
- import { CreateCustomerProductReviewParamsSchema, CreateProductReviewParamsSchema, ListProductReviewsParamsSchema, ListStoreReviewsParamsSchema, StorefrontReviewSchema, StorefrontReviewsSchema, StorefrontStoreReviewSchema } from "../models/storefront-reviews.js";
1
+ import { CreateCustomerProductReviewParamsSchema, CreateProductReviewParamsSchema, ListProductReviewsParamsSchema, StorefrontReviewSchema, StorefrontReviewsSchema } from "../models/storefront-reviews.js";
2
2
  // src/services/review.service.ts
3
3
  async function listProductReviews(api, params) {
4
4
  const input = ListProductReviewsParamsSchema.parse(params);
@@ -11,13 +11,6 @@ async function listProductReviews(api, params) {
11
11
  rating: input.rating
12
12
  } });
13
13
  }
14
- async function listStoreReviews(api, params = {}) {
15
- const input = ListStoreReviewsParamsSchema.parse(params);
16
- return api.get("reviews", StorefrontStoreReviewSchema.array(), { query: {
17
- limit: input.limit,
18
- minRating: input.minRating
19
- } });
20
- }
21
14
  async function createProductReview(api, params) {
22
15
  const input = CreateProductReviewParamsSchema.parse(params);
23
16
  return api.post(`products/${encodeURIComponent(input.productId)}/reviews`, {
@@ -40,4 +33,4 @@ async function createCustomerProductReview(api, params, options) {
40
33
  reviewerName: input.reviewerName
41
34
  }, StorefrontReviewSchema, options);
42
35
  }
43
- export { createCustomerProductReview, createProductReview, listProductReviews, listStoreReviews };
36
+ export { createCustomerProductReview, createProductReview, listProductReviews };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomiq/core",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "description": "Modelos, API client y schemas compartidos de Ecomiq",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,50 +0,0 @@
1
- const require_graphql = require("../libs/graphql-wJH7HaQU.cjs");
2
- const require_graphql_selection = require("../libs/graphql-selection-Cj51WkJn.cjs");
3
- const require_catalog_links = require("../models/catalog-links-c4LADGf_.cjs");
4
- const require_catalog_link_key = require("../libs/catalog-link-key-CZTHJBGD.cjs");
5
- const require_models_collections = require("../models/collections.cjs");
6
- const require_models_settings = require("../models/settings.cjs");
7
- let zod = require("zod");
8
- // src/services/layout.service.ts
9
- const LayoutSchema = zod.z.object({
10
- settings: require_models_settings.StorefrontSettingsSchema,
11
- collections: require_models_collections.CollectionsSchema.nullable(),
12
- links: zod.z.array(require_catalog_links.CatalogLinkSchema).nullable()
13
- });
14
- const LinksSchema = LayoutSchema.pick({ links: true });
15
- const LINK_FIELDS = require_graphql_selection.graphQLSelection(require_catalog_links.CatalogLinkSchema);
16
- const LAYOUT = `query StorefrontLayoutV3($links: [StorefrontLinkInput!]!) {
17
- settings { ${require_graphql_selection.graphQLSelection(require_models_settings.StorefrontSettingsSchema)} }
18
- collections { ${require_graphql_selection.graphQLSelection(require_models_collections.CollectionSchema)} }
19
- links(links: $links) { ${LINK_FIELDS} }
20
- }`;
21
- const LINKS = `query StorefrontLinks($links: [StorefrontLinkInput!]!) {
22
- links(links: $links) { ${LINK_FIELDS} }
23
- }`;
24
- async function getLayout({ graphql, links }) {
25
- const input = links.map(require_catalog_links.readCatalogLink);
26
- const candidates = require_catalog_links.catalogLinkCandidates(input);
27
- const first = candidates.slice(0, 100);
28
- const layout = graphql(LAYOUT, LayoutSchema, { links: first }, { allowStale: false }).catch((error) => {
29
- if (error instanceof require_graphql.GraphQLResponseError && error.errors.every((item) => item.path?.[0] === "collections" || item.path?.[0] === "links")) {
30
- const partial = LayoutSchema.safeParse(error.data);
31
- if (partial.success) return partial.data;
32
- }
33
- throw error;
34
- });
35
- const remaining = [];
36
- for (let offset = 100; offset < candidates.length; offset += 100) {
37
- const batch = candidates.slice(offset, offset + 100);
38
- remaining.push(graphql(LINKS, LinksSchema, { links: batch }, { allowStale: false }).then((result) => batch.map((link, index) => result.links?.[index] ?? link)).catch(() => batch));
39
- }
40
- const [result, batches] = await Promise.all([layout, Promise.all(remaining)]);
41
- const resolved = /* @__PURE__ */ new Map();
42
- const values = [...first.map((link, index) => result.links?.[index] ?? link), ...batches.flat()];
43
- candidates.forEach((link, index) => resolved.set(require_catalog_link_key.catalogLinkKey(link), values[index] ?? link));
44
- return {
45
- settings: result.settings,
46
- collections: result.collections ?? [],
47
- links: input.map((link) => resolved.get(require_catalog_link_key.catalogLinkKey(link)) ?? link)
48
- };
49
- }
50
- exports.getLayout = getLayout;
@@ -1,50 +0,0 @@
1
- import { GraphQLResponseError } from "../libs/graphql-_6Y8lR_Q.js";
2
- import { graphQLSelection } from "../libs/graphql-selection-H1RMh6VD.js";
3
- import { CatalogLinkSchema, catalogLinkCandidates, readCatalogLink } from "../models/catalog-links-BzJeyBy4.js";
4
- import { catalogLinkKey } from "../libs/catalog-link-key-B7l5KZsF.js";
5
- import { CollectionSchema, CollectionsSchema } from "../models/collections.js";
6
- import { StorefrontSettingsSchema } from "../models/settings.js";
7
- import { z } from "zod";
8
- // src/services/layout.service.ts
9
- const LayoutSchema = z.object({
10
- settings: StorefrontSettingsSchema,
11
- collections: CollectionsSchema.nullable(),
12
- links: z.array(CatalogLinkSchema).nullable()
13
- });
14
- const LinksSchema = LayoutSchema.pick({ links: true });
15
- const LINK_FIELDS = graphQLSelection(CatalogLinkSchema);
16
- const LAYOUT = `query StorefrontLayoutV3($links: [StorefrontLinkInput!]!) {
17
- settings { ${graphQLSelection(StorefrontSettingsSchema)} }
18
- collections { ${graphQLSelection(CollectionSchema)} }
19
- links(links: $links) { ${LINK_FIELDS} }
20
- }`;
21
- const LINKS = `query StorefrontLinks($links: [StorefrontLinkInput!]!) {
22
- links(links: $links) { ${LINK_FIELDS} }
23
- }`;
24
- async function getLayout({ graphql, links }) {
25
- const input = links.map(readCatalogLink);
26
- const candidates = catalogLinkCandidates(input);
27
- const first = candidates.slice(0, 100);
28
- const layout = graphql(LAYOUT, LayoutSchema, { links: first }, { allowStale: false }).catch((error) => {
29
- if (error instanceof GraphQLResponseError && error.errors.every((item) => item.path?.[0] === "collections" || item.path?.[0] === "links")) {
30
- const partial = LayoutSchema.safeParse(error.data);
31
- if (partial.success) return partial.data;
32
- }
33
- throw error;
34
- });
35
- const remaining = [];
36
- for (let offset = 100; offset < candidates.length; offset += 100) {
37
- const batch = candidates.slice(offset, offset + 100);
38
- remaining.push(graphql(LINKS, LinksSchema, { links: batch }, { allowStale: false }).then((result) => batch.map((link, index) => result.links?.[index] ?? link)).catch(() => batch));
39
- }
40
- const [result, batches] = await Promise.all([layout, Promise.all(remaining)]);
41
- const resolved = /* @__PURE__ */ new Map();
42
- const values = [...first.map((link, index) => result.links?.[index] ?? link), ...batches.flat()];
43
- candidates.forEach((link, index) => resolved.set(catalogLinkKey(link), values[index] ?? link));
44
- return {
45
- settings: result.settings,
46
- collections: result.collections ?? [],
47
- links: input.map((link) => resolved.get(catalogLinkKey(link)) ?? link)
48
- };
49
- }
50
- export { getLayout };