@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.
- package/README.md +16 -2
- package/dist/client.cjs +180 -23
- package/dist/client.d.cts +8 -2
- package/dist/client.d.ts +8 -2
- package/dist/client.js +183 -26
- package/dist/index.cjs +8 -3
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -6
- package/dist/libs/{graphql-_6Y8lR_Q.js → graphql-8PZkrq66.js} +12 -8
- package/dist/libs/{graphql-wJH7HaQU.cjs → graphql-BICZrYlZ.cjs} +12 -7
- package/dist/libs/graphql-batch-AFRui-4Y.js +125 -0
- package/dist/libs/graphql-batch-B0xSD6G2.cjs +125 -0
- package/dist/libs/graphql-batch.d.cts +2 -0
- package/dist/libs/graphql-batch.d.ts +2 -0
- package/dist/models/collections.cjs +5 -0
- package/dist/models/collections.d.cts +109 -1
- package/dist/models/collections.d.ts +109 -1
- package/dist/models/collections.js +4 -1
- package/dist/models/storefront-reviews.cjs +9 -2
- package/dist/models/storefront-reviews.d.cts +99 -0
- package/dist/models/storefront-reviews.d.ts +99 -0
- package/dist/models/storefront-reviews.js +7 -3
- package/dist/services/layout.service-C6zG6zY7.cjs +65 -0
- package/dist/services/layout.service-DufBhrOR.js +65 -0
- package/dist/services/layout.service.d.cts +1 -0
- package/dist/services/layout.service.d.ts +1 -0
- package/dist/services/{review.service-CO2icjpu.cjs → review.service-BgRGfq4t.cjs} +0 -8
- package/dist/services/{review.service-De1YkhFp.js → review.service-DMgxbO94.js} +2 -9
- package/package.json +1 -1
- package/dist/services/layout.service-BkvLzl1g.cjs +0 -50
- package/dist/services/layout.service-DmbeMOkK.js +0 -50
|
@@ -19,21 +19,25 @@ var GraphQLResponseError = class extends Error {
|
|
|
19
19
|
this.name = "GraphQLResponseError";
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const GraphQLEnvelopeSchema = z.object({
|
|
23
|
+
data: z.unknown().optional(),
|
|
24
|
+
errors: z.array(GraphQLErrorSchema).optional()
|
|
25
|
+
});
|
|
26
|
+
function sendGraphQL(api, domain, document, variables, options = {}) {
|
|
24
27
|
const headers = { "x-Store-Domain": domain };
|
|
25
28
|
if (options.cache === "no-store") headers["cache-control"] = "no-store";
|
|
26
29
|
else if (options.allowStale === false) headers["cache-control"] = "max-stale=0";
|
|
27
|
-
|
|
30
|
+
return api.post("graphql", {
|
|
28
31
|
query: document,
|
|
29
32
|
variables
|
|
30
|
-
},
|
|
31
|
-
data: z.unknown().optional(),
|
|
32
|
-
errors: z.array(GraphQLErrorSchema).optional()
|
|
33
|
-
}), {
|
|
33
|
+
}, GraphQLEnvelopeSchema, {
|
|
34
34
|
headers,
|
|
35
35
|
signal: options.signal
|
|
36
36
|
});
|
|
37
|
+
}
|
|
38
|
+
async function executeGraphQL(api, domain, document, dataSchema, variables, options = {}) {
|
|
39
|
+
if (!document.trim()) throw new Error("GraphQL document is required");
|
|
40
|
+
const response = await sendGraphQL(api, domain, document, variables, options);
|
|
37
41
|
if (response.errors?.length) throw new GraphQLResponseError(response.errors, response.data);
|
|
38
42
|
if (response.data == null) throw new GraphQLResponseError([{ message: "GraphQL response did not include data" }]);
|
|
39
43
|
const parsed = dataSchema.safeParse(response.data);
|
|
@@ -46,4 +50,4 @@ async function executeGraphQL(api, domain, document, dataSchema, variables, opti
|
|
|
46
50
|
}
|
|
47
51
|
return parsed.data;
|
|
48
52
|
}
|
|
49
|
-
export { GraphQLResponseError, executeGraphQL };
|
|
53
|
+
export { GraphQLResponseError, executeGraphQL, sendGraphQL };
|
|
@@ -19,21 +19,25 @@ var GraphQLResponseError = class extends Error {
|
|
|
19
19
|
this.name = "GraphQLResponseError";
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const GraphQLEnvelopeSchema = zod.z.object({
|
|
23
|
+
data: zod.z.unknown().optional(),
|
|
24
|
+
errors: zod.z.array(GraphQLErrorSchema).optional()
|
|
25
|
+
});
|
|
26
|
+
function sendGraphQL(api, domain, document, variables, options = {}) {
|
|
24
27
|
const headers = { "x-Store-Domain": domain };
|
|
25
28
|
if (options.cache === "no-store") headers["cache-control"] = "no-store";
|
|
26
29
|
else if (options.allowStale === false) headers["cache-control"] = "max-stale=0";
|
|
27
|
-
|
|
30
|
+
return api.post("graphql", {
|
|
28
31
|
query: document,
|
|
29
32
|
variables
|
|
30
|
-
},
|
|
31
|
-
data: zod.z.unknown().optional(),
|
|
32
|
-
errors: zod.z.array(GraphQLErrorSchema).optional()
|
|
33
|
-
}), {
|
|
33
|
+
}, GraphQLEnvelopeSchema, {
|
|
34
34
|
headers,
|
|
35
35
|
signal: options.signal
|
|
36
36
|
});
|
|
37
|
+
}
|
|
38
|
+
async function executeGraphQL(api, domain, document, dataSchema, variables, options = {}) {
|
|
39
|
+
if (!document.trim()) throw new Error("GraphQL document is required");
|
|
40
|
+
const response = await sendGraphQL(api, domain, document, variables, options);
|
|
37
41
|
if (response.errors?.length) throw new GraphQLResponseError(response.errors, response.data);
|
|
38
42
|
if (response.data == null) throw new GraphQLResponseError([{ message: "GraphQL response did not include data" }]);
|
|
39
43
|
const parsed = dataSchema.safeParse(response.data);
|
|
@@ -48,3 +52,4 @@ async function executeGraphQL(api, domain, document, dataSchema, variables, opti
|
|
|
48
52
|
}
|
|
49
53
|
exports.GraphQLResponseError = GraphQLResponseError;
|
|
50
54
|
exports.executeGraphQL = executeGraphQL;
|
|
55
|
+
exports.sendGraphQL = sendGraphQL;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { GraphQLResponseError } from "./graphql-8PZkrq66.js";
|
|
2
|
+
import "zod";
|
|
3
|
+
// src/libs/graphql-batch.ts
|
|
4
|
+
const MAX_FIELDS_PER_REQUEST = 20;
|
|
5
|
+
function batchDocument(pending) {
|
|
6
|
+
const declarations = [];
|
|
7
|
+
const fields = [];
|
|
8
|
+
const variables = {};
|
|
9
|
+
pending.forEach(({ request }, index) => {
|
|
10
|
+
const alias = `f${index}`;
|
|
11
|
+
const passed = (request.arguments ?? []).filter((argument) => argument.value !== void 0).map((argument) => {
|
|
12
|
+
const variable = `${alias}_${argument.name}`;
|
|
13
|
+
declarations.push(`$${variable}: ${argument.type}`);
|
|
14
|
+
variables[variable] = argument.value;
|
|
15
|
+
return `${argument.name}: $${variable}`;
|
|
16
|
+
});
|
|
17
|
+
const call = passed.length === 0 ? request.field : `${request.field}(${passed.join(", ")})`;
|
|
18
|
+
fields.push(request.selection ? `${alias}: ${call} { ${request.selection} }` : `${alias}: ${call}`);
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
document: `query StorefrontBatch${declarations.length === 0 ? "" : `(${declarations.join(", ")})`} { ${fields.join(" ")} }`,
|
|
22
|
+
variables
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function fieldErrors(errors, alias, field) {
|
|
26
|
+
return errors.filter((error) => error.path?.[0] === alias).map((error) => ({
|
|
27
|
+
...error,
|
|
28
|
+
path: [field, ...(error.path ?? []).slice(1)]
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
function settle(pending, response) {
|
|
32
|
+
const data = response.data !== null && typeof response.data === "object" ? response.data : null;
|
|
33
|
+
pending.forEach((entry, index) => {
|
|
34
|
+
const alias = `f${index}`;
|
|
35
|
+
const value = data?.[alias];
|
|
36
|
+
const errors = fieldErrors(response.errors ?? [], alias, entry.request.field);
|
|
37
|
+
if (errors.length > 0) {
|
|
38
|
+
entry.reject(new GraphQLResponseError(errors, value));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (data === null || !(alias in data)) {
|
|
42
|
+
entry.reject(new GraphQLResponseError([{ message: "GraphQL response did not include data" }]));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const parsed = entry.request.schema.safeParse(value);
|
|
46
|
+
if (!parsed.success) {
|
|
47
|
+
const issue = parsed.error.issues[0];
|
|
48
|
+
entry.reject(new GraphQLResponseError([{
|
|
49
|
+
message: `Unexpected GraphQL data: ${[entry.request.field, ...issue?.path ?? []].join(".")} ${issue?.message}`,
|
|
50
|
+
extensions: { code: "INVALID_RESPONSE" }
|
|
51
|
+
}], value));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
entry.resolve(parsed.data);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function requestKey(options) {
|
|
58
|
+
if (options.cache === "no-store") return "no-store";
|
|
59
|
+
if (options.allowStale === false) return "fresh";
|
|
60
|
+
return "default";
|
|
61
|
+
}
|
|
62
|
+
function createGraphQLBatcher(send) {
|
|
63
|
+
const queues = /* @__PURE__ */ new Map();
|
|
64
|
+
async function run(pending, options) {
|
|
65
|
+
const { document, variables } = batchDocument(pending);
|
|
66
|
+
let response;
|
|
67
|
+
try {
|
|
68
|
+
response = await send(document, variables, options);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
for (const entry of pending) entry.reject(error);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const errors = response.errors ?? [];
|
|
74
|
+
if (response.data == null && errors.length > 0) {
|
|
75
|
+
if (pending.length === 1) {
|
|
76
|
+
const own = fieldErrors(errors, "f0", pending[0].request.field);
|
|
77
|
+
pending[0].reject(new GraphQLResponseError(own.length > 0 ? own : errors));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const failed = new Set(errors.map((error) => error.path?.[0]));
|
|
81
|
+
const rest = pending.filter((_, index) => !failed.has(`f${index}`));
|
|
82
|
+
if (rest.length === pending.length) {
|
|
83
|
+
for (const entry of pending) run([entry], options);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
pending.forEach((entry, index) => {
|
|
87
|
+
if (failed.has(`f${index}`)) entry.reject(new GraphQLResponseError(fieldErrors(errors, `f${index}`, entry.request.field)));
|
|
88
|
+
});
|
|
89
|
+
if (rest.length > 0) run(rest, options);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
settle(pending, response);
|
|
93
|
+
}
|
|
94
|
+
function flush(key) {
|
|
95
|
+
const queue = queues.get(key);
|
|
96
|
+
queues.delete(key);
|
|
97
|
+
if (!queue) return;
|
|
98
|
+
for (let offset = 0; offset < queue.pending.length; offset += MAX_FIELDS_PER_REQUEST) run(queue.pending.slice(offset, offset + MAX_FIELDS_PER_REQUEST), queue.options);
|
|
99
|
+
}
|
|
100
|
+
return { request(request, options = {}) {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
const entry = {
|
|
103
|
+
request,
|
|
104
|
+
resolve,
|
|
105
|
+
reject
|
|
106
|
+
};
|
|
107
|
+
if (options.signal) {
|
|
108
|
+
run([entry], options);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const key = requestKey(options);
|
|
112
|
+
const queue = queues.get(key);
|
|
113
|
+
if (queue) {
|
|
114
|
+
queue.pending.push(entry);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
queues.set(key, {
|
|
118
|
+
options,
|
|
119
|
+
pending: [entry]
|
|
120
|
+
});
|
|
121
|
+
setTimeout(() => flush(key), 0);
|
|
122
|
+
});
|
|
123
|
+
} };
|
|
124
|
+
}
|
|
125
|
+
export { createGraphQLBatcher };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const require_graphql = require("./graphql-BICZrYlZ.cjs");
|
|
2
|
+
require("zod");
|
|
3
|
+
// src/libs/graphql-batch.ts
|
|
4
|
+
const MAX_FIELDS_PER_REQUEST = 20;
|
|
5
|
+
function batchDocument(pending) {
|
|
6
|
+
const declarations = [];
|
|
7
|
+
const fields = [];
|
|
8
|
+
const variables = {};
|
|
9
|
+
pending.forEach(({ request }, index) => {
|
|
10
|
+
const alias = `f${index}`;
|
|
11
|
+
const passed = (request.arguments ?? []).filter((argument) => argument.value !== void 0).map((argument) => {
|
|
12
|
+
const variable = `${alias}_${argument.name}`;
|
|
13
|
+
declarations.push(`$${variable}: ${argument.type}`);
|
|
14
|
+
variables[variable] = argument.value;
|
|
15
|
+
return `${argument.name}: $${variable}`;
|
|
16
|
+
});
|
|
17
|
+
const call = passed.length === 0 ? request.field : `${request.field}(${passed.join(", ")})`;
|
|
18
|
+
fields.push(request.selection ? `${alias}: ${call} { ${request.selection} }` : `${alias}: ${call}`);
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
document: `query StorefrontBatch${declarations.length === 0 ? "" : `(${declarations.join(", ")})`} { ${fields.join(" ")} }`,
|
|
22
|
+
variables
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function fieldErrors(errors, alias, field) {
|
|
26
|
+
return errors.filter((error) => error.path?.[0] === alias).map((error) => ({
|
|
27
|
+
...error,
|
|
28
|
+
path: [field, ...(error.path ?? []).slice(1)]
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
function settle(pending, response) {
|
|
32
|
+
const data = response.data !== null && typeof response.data === "object" ? response.data : null;
|
|
33
|
+
pending.forEach((entry, index) => {
|
|
34
|
+
const alias = `f${index}`;
|
|
35
|
+
const value = data?.[alias];
|
|
36
|
+
const errors = fieldErrors(response.errors ?? [], alias, entry.request.field);
|
|
37
|
+
if (errors.length > 0) {
|
|
38
|
+
entry.reject(new require_graphql.GraphQLResponseError(errors, value));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (data === null || !(alias in data)) {
|
|
42
|
+
entry.reject(new require_graphql.GraphQLResponseError([{ message: "GraphQL response did not include data" }]));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const parsed = entry.request.schema.safeParse(value);
|
|
46
|
+
if (!parsed.success) {
|
|
47
|
+
const issue = parsed.error.issues[0];
|
|
48
|
+
entry.reject(new require_graphql.GraphQLResponseError([{
|
|
49
|
+
message: `Unexpected GraphQL data: ${[entry.request.field, ...issue?.path ?? []].join(".")} ${issue?.message}`,
|
|
50
|
+
extensions: { code: "INVALID_RESPONSE" }
|
|
51
|
+
}], value));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
entry.resolve(parsed.data);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function requestKey(options) {
|
|
58
|
+
if (options.cache === "no-store") return "no-store";
|
|
59
|
+
if (options.allowStale === false) return "fresh";
|
|
60
|
+
return "default";
|
|
61
|
+
}
|
|
62
|
+
function createGraphQLBatcher(send) {
|
|
63
|
+
const queues = /* @__PURE__ */ new Map();
|
|
64
|
+
async function run(pending, options) {
|
|
65
|
+
const { document, variables } = batchDocument(pending);
|
|
66
|
+
let response;
|
|
67
|
+
try {
|
|
68
|
+
response = await send(document, variables, options);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
for (const entry of pending) entry.reject(error);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const errors = response.errors ?? [];
|
|
74
|
+
if (response.data == null && errors.length > 0) {
|
|
75
|
+
if (pending.length === 1) {
|
|
76
|
+
const own = fieldErrors(errors, "f0", pending[0].request.field);
|
|
77
|
+
pending[0].reject(new require_graphql.GraphQLResponseError(own.length > 0 ? own : errors));
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const failed = new Set(errors.map((error) => error.path?.[0]));
|
|
81
|
+
const rest = pending.filter((_, index) => !failed.has(`f${index}`));
|
|
82
|
+
if (rest.length === pending.length) {
|
|
83
|
+
for (const entry of pending) run([entry], options);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
pending.forEach((entry, index) => {
|
|
87
|
+
if (failed.has(`f${index}`)) entry.reject(new require_graphql.GraphQLResponseError(fieldErrors(errors, `f${index}`, entry.request.field)));
|
|
88
|
+
});
|
|
89
|
+
if (rest.length > 0) run(rest, options);
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
settle(pending, response);
|
|
93
|
+
}
|
|
94
|
+
function flush(key) {
|
|
95
|
+
const queue = queues.get(key);
|
|
96
|
+
queues.delete(key);
|
|
97
|
+
if (!queue) return;
|
|
98
|
+
for (let offset = 0; offset < queue.pending.length; offset += MAX_FIELDS_PER_REQUEST) run(queue.pending.slice(offset, offset + MAX_FIELDS_PER_REQUEST), queue.options);
|
|
99
|
+
}
|
|
100
|
+
return { request(request, options = {}) {
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
const entry = {
|
|
103
|
+
request,
|
|
104
|
+
resolve,
|
|
105
|
+
reject
|
|
106
|
+
};
|
|
107
|
+
if (options.signal) {
|
|
108
|
+
run([entry], options);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const key = requestKey(options);
|
|
112
|
+
const queue = queues.get(key);
|
|
113
|
+
if (queue) {
|
|
114
|
+
queue.pending.push(entry);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
queues.set(key, {
|
|
118
|
+
options,
|
|
119
|
+
pending: [entry]
|
|
120
|
+
});
|
|
121
|
+
setTimeout(() => flush(key), 0);
|
|
122
|
+
});
|
|
123
|
+
} };
|
|
124
|
+
}
|
|
125
|
+
exports.createGraphQLBatcher = createGraphQLBatcher;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_models_ids = require("./ids.cjs");
|
|
3
|
+
const require_models_products = require("./products.cjs");
|
|
3
4
|
let zod = require("zod");
|
|
4
5
|
// src/models/collections.ts
|
|
5
6
|
const CollectionSchema = zod.z.object({
|
|
@@ -13,5 +14,9 @@ const CollectionSchema = zod.z.object({
|
|
|
13
14
|
template: zod.z.string().nullable().optional()
|
|
14
15
|
});
|
|
15
16
|
const CollectionsSchema = zod.z.array(CollectionSchema);
|
|
17
|
+
const CollectionWithCoversSchema = CollectionSchema.extend({ imageCandidates: zod.z.array(zod.z.string()) });
|
|
18
|
+
const CollectionWithProductsSchema = CollectionSchema.extend({ products: zod.z.array(require_models_products.ProductSummarySchema) });
|
|
16
19
|
exports.CollectionSchema = CollectionSchema;
|
|
20
|
+
exports.CollectionWithCoversSchema = CollectionWithCoversSchema;
|
|
21
|
+
exports.CollectionWithProductsSchema = CollectionWithProductsSchema;
|
|
17
22
|
exports.CollectionsSchema = CollectionsSchema;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ProductSort } from "./products.cjs";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
export declare const CollectionSchema: z.ZodObject<{
|
|
3
4
|
id: z.ZodString;
|
|
@@ -19,5 +20,112 @@ export declare const CollectionsSchema: z.ZodArray<z.ZodObject<{
|
|
|
19
20
|
productCount: z.ZodOptional<z.ZodNumber>;
|
|
20
21
|
template: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
22
|
}, z.core.$strip>>;
|
|
23
|
+
export declare const CollectionWithCoversSchema: z.ZodObject<{
|
|
24
|
+
id: z.ZodString;
|
|
25
|
+
slug: z.ZodString;
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
imageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
+
type: z.ZodString;
|
|
30
|
+
productCount: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
template: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
32
|
+
imageCandidates: z.ZodArray<z.ZodString>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export declare const CollectionWithProductsSchema: z.ZodObject<{
|
|
35
|
+
id: z.ZodString;
|
|
36
|
+
slug: z.ZodString;
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
|
+
imageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
|
+
type: z.ZodString;
|
|
41
|
+
productCount: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
template: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
products: z.ZodArray<z.ZodObject<{
|
|
44
|
+
id: z.ZodString;
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
slug: z.ZodString;
|
|
47
|
+
url: z.ZodString;
|
|
48
|
+
productType: z.ZodString;
|
|
49
|
+
imageUrl: z.ZodString;
|
|
50
|
+
price: z.ZodNumber;
|
|
51
|
+
compareAtPrice: z.ZodNullable<z.ZodNumber>;
|
|
52
|
+
variantCount: z.ZodNumber;
|
|
53
|
+
isAvailable: z.ZodBoolean;
|
|
54
|
+
totalInventory: z.ZodNumber;
|
|
55
|
+
bundleItemsCount: z.ZodNumber;
|
|
56
|
+
brand: z.ZodString;
|
|
57
|
+
category: z.ZodString;
|
|
58
|
+
status: z.ZodString;
|
|
59
|
+
collections: z.ZodArray<z.ZodString>;
|
|
60
|
+
tags: z.ZodArray<z.ZodString>;
|
|
61
|
+
seller: z.ZodNullable<z.ZodObject<{
|
|
62
|
+
id: z.ZodString;
|
|
63
|
+
name: z.ZodString;
|
|
64
|
+
slug: z.ZodString;
|
|
65
|
+
}, z.core.$strip>>;
|
|
66
|
+
options: z.ZodArray<z.ZodObject<{
|
|
67
|
+
key: z.ZodString;
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
70
|
+
checkbox: "checkbox";
|
|
71
|
+
colorPicker: "colorPicker";
|
|
72
|
+
datePicker: "datePicker";
|
|
73
|
+
dateTimePicker: "dateTimePicker";
|
|
74
|
+
file: "file";
|
|
75
|
+
input: "input";
|
|
76
|
+
number: "number";
|
|
77
|
+
select: "select";
|
|
78
|
+
textArea: "textArea";
|
|
79
|
+
timePicker: "timePicker";
|
|
80
|
+
url: "url";
|
|
81
|
+
}>>;
|
|
82
|
+
values: z.ZodArray<z.ZodObject<{
|
|
83
|
+
key: z.ZodString;
|
|
84
|
+
name: z.ZodString;
|
|
85
|
+
value: z.ZodString;
|
|
86
|
+
valueId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
87
|
+
valueName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
88
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
89
|
+
checkbox: "checkbox";
|
|
90
|
+
colorPicker: "colorPicker";
|
|
91
|
+
datePicker: "datePicker";
|
|
92
|
+
dateTimePicker: "dateTimePicker";
|
|
93
|
+
file: "file";
|
|
94
|
+
input: "input";
|
|
95
|
+
number: "number";
|
|
96
|
+
select: "select";
|
|
97
|
+
textArea: "textArea";
|
|
98
|
+
timePicker: "timePicker";
|
|
99
|
+
url: "url";
|
|
100
|
+
}>>;
|
|
101
|
+
color: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
102
|
+
imageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
103
|
+
unit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
104
|
+
}, z.core.$strip>>;
|
|
105
|
+
}, z.core.$strip>>;
|
|
106
|
+
images: z.ZodArray<z.ZodObject<{
|
|
107
|
+
url: z.ZodString;
|
|
108
|
+
name: z.ZodString;
|
|
109
|
+
order: z.ZodNumber;
|
|
110
|
+
type: z.ZodDefault<z.ZodCatch<z.ZodEnum<{
|
|
111
|
+
image: "image";
|
|
112
|
+
video: "video";
|
|
113
|
+
}>>>;
|
|
114
|
+
}, z.core.$strip>>;
|
|
115
|
+
availableVariantId: z.ZodNullable<z.ZodString>;
|
|
116
|
+
hasModifierGroups: z.ZodBoolean;
|
|
117
|
+
}, z.core.$strip>>;
|
|
118
|
+
}, z.core.$strip>;
|
|
22
119
|
export type Collection = z.infer<typeof CollectionSchema>;
|
|
23
|
-
export type Collections = z.infer<typeof CollectionsSchema>;
|
|
120
|
+
export type Collections = z.infer<typeof CollectionsSchema>;
|
|
121
|
+
export type CollectionWithCovers = z.infer<typeof CollectionWithCoversSchema>;
|
|
122
|
+
export type CollectionWithProducts = z.infer<typeof CollectionWithProductsSchema>;
|
|
123
|
+
export type CollectionCoversOptions = {
|
|
124
|
+
limit?: number;
|
|
125
|
+
candidates?: number;
|
|
126
|
+
};
|
|
127
|
+
export type CollectionsWithProductsOptions = {
|
|
128
|
+
limit?: number;
|
|
129
|
+
products: number;
|
|
130
|
+
sort?: ProductSort;
|
|
131
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ProductSort } from "./products.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
export declare const CollectionSchema: z.ZodObject<{
|
|
3
4
|
id: z.ZodString;
|
|
@@ -19,5 +20,112 @@ export declare const CollectionsSchema: z.ZodArray<z.ZodObject<{
|
|
|
19
20
|
productCount: z.ZodOptional<z.ZodNumber>;
|
|
20
21
|
template: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
21
22
|
}, z.core.$strip>>;
|
|
23
|
+
export declare const CollectionWithCoversSchema: z.ZodObject<{
|
|
24
|
+
id: z.ZodString;
|
|
25
|
+
slug: z.ZodString;
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
28
|
+
imageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
29
|
+
type: z.ZodString;
|
|
30
|
+
productCount: z.ZodOptional<z.ZodNumber>;
|
|
31
|
+
template: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
32
|
+
imageCandidates: z.ZodArray<z.ZodString>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export declare const CollectionWithProductsSchema: z.ZodObject<{
|
|
35
|
+
id: z.ZodString;
|
|
36
|
+
slug: z.ZodString;
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
39
|
+
imageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
40
|
+
type: z.ZodString;
|
|
41
|
+
productCount: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
template: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
products: z.ZodArray<z.ZodObject<{
|
|
44
|
+
id: z.ZodString;
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
slug: z.ZodString;
|
|
47
|
+
url: z.ZodString;
|
|
48
|
+
productType: z.ZodString;
|
|
49
|
+
imageUrl: z.ZodString;
|
|
50
|
+
price: z.ZodNumber;
|
|
51
|
+
compareAtPrice: z.ZodNullable<z.ZodNumber>;
|
|
52
|
+
variantCount: z.ZodNumber;
|
|
53
|
+
isAvailable: z.ZodBoolean;
|
|
54
|
+
totalInventory: z.ZodNumber;
|
|
55
|
+
bundleItemsCount: z.ZodNumber;
|
|
56
|
+
brand: z.ZodString;
|
|
57
|
+
category: z.ZodString;
|
|
58
|
+
status: z.ZodString;
|
|
59
|
+
collections: z.ZodArray<z.ZodString>;
|
|
60
|
+
tags: z.ZodArray<z.ZodString>;
|
|
61
|
+
seller: z.ZodNullable<z.ZodObject<{
|
|
62
|
+
id: z.ZodString;
|
|
63
|
+
name: z.ZodString;
|
|
64
|
+
slug: z.ZodString;
|
|
65
|
+
}, z.core.$strip>>;
|
|
66
|
+
options: z.ZodArray<z.ZodObject<{
|
|
67
|
+
key: z.ZodString;
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
70
|
+
checkbox: "checkbox";
|
|
71
|
+
colorPicker: "colorPicker";
|
|
72
|
+
datePicker: "datePicker";
|
|
73
|
+
dateTimePicker: "dateTimePicker";
|
|
74
|
+
file: "file";
|
|
75
|
+
input: "input";
|
|
76
|
+
number: "number";
|
|
77
|
+
select: "select";
|
|
78
|
+
textArea: "textArea";
|
|
79
|
+
timePicker: "timePicker";
|
|
80
|
+
url: "url";
|
|
81
|
+
}>>;
|
|
82
|
+
values: z.ZodArray<z.ZodObject<{
|
|
83
|
+
key: z.ZodString;
|
|
84
|
+
name: z.ZodString;
|
|
85
|
+
value: z.ZodString;
|
|
86
|
+
valueId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
87
|
+
valueName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
88
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
89
|
+
checkbox: "checkbox";
|
|
90
|
+
colorPicker: "colorPicker";
|
|
91
|
+
datePicker: "datePicker";
|
|
92
|
+
dateTimePicker: "dateTimePicker";
|
|
93
|
+
file: "file";
|
|
94
|
+
input: "input";
|
|
95
|
+
number: "number";
|
|
96
|
+
select: "select";
|
|
97
|
+
textArea: "textArea";
|
|
98
|
+
timePicker: "timePicker";
|
|
99
|
+
url: "url";
|
|
100
|
+
}>>;
|
|
101
|
+
color: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
102
|
+
imageUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
103
|
+
unit: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
104
|
+
}, z.core.$strip>>;
|
|
105
|
+
}, z.core.$strip>>;
|
|
106
|
+
images: z.ZodArray<z.ZodObject<{
|
|
107
|
+
url: z.ZodString;
|
|
108
|
+
name: z.ZodString;
|
|
109
|
+
order: z.ZodNumber;
|
|
110
|
+
type: z.ZodDefault<z.ZodCatch<z.ZodEnum<{
|
|
111
|
+
image: "image";
|
|
112
|
+
video: "video";
|
|
113
|
+
}>>>;
|
|
114
|
+
}, z.core.$strip>>;
|
|
115
|
+
availableVariantId: z.ZodNullable<z.ZodString>;
|
|
116
|
+
hasModifierGroups: z.ZodBoolean;
|
|
117
|
+
}, z.core.$strip>>;
|
|
118
|
+
}, z.core.$strip>;
|
|
22
119
|
export type Collection = z.infer<typeof CollectionSchema>;
|
|
23
|
-
export type Collections = z.infer<typeof CollectionsSchema>;
|
|
120
|
+
export type Collections = z.infer<typeof CollectionsSchema>;
|
|
121
|
+
export type CollectionWithCovers = z.infer<typeof CollectionWithCoversSchema>;
|
|
122
|
+
export type CollectionWithProducts = z.infer<typeof CollectionWithProductsSchema>;
|
|
123
|
+
export type CollectionCoversOptions = {
|
|
124
|
+
limit?: number;
|
|
125
|
+
candidates?: number;
|
|
126
|
+
};
|
|
127
|
+
export type CollectionsWithProductsOptions = {
|
|
128
|
+
limit?: number;
|
|
129
|
+
products: number;
|
|
130
|
+
sort?: ProductSort;
|
|
131
|
+
};
|
|
@@ -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/collections.ts
|
|
4
5
|
const CollectionSchema = z.object({
|
|
@@ -12,4 +13,6 @@ const CollectionSchema = z.object({
|
|
|
12
13
|
template: z.string().nullable().optional()
|
|
13
14
|
});
|
|
14
15
|
const CollectionsSchema = z.array(CollectionSchema);
|
|
15
|
-
|
|
16
|
+
const CollectionWithCoversSchema = CollectionSchema.extend({ imageCandidates: z.array(z.string()) });
|
|
17
|
+
const CollectionWithProductsSchema = CollectionSchema.extend({ products: z.array(ProductSummarySchema) });
|
|
18
|
+
export { CollectionSchema, CollectionWithCoversSchema, CollectionWithProductsSchema, CollectionsSchema };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_models_ids = require("./ids.cjs");
|
|
3
|
+
const require_models_products = require("./products.cjs");
|
|
3
4
|
let zod = require("zod");
|
|
4
5
|
// src/models/storefront-reviews.ts
|
|
5
6
|
const StorefrontReviewSchema = zod.z.object({
|
|
@@ -32,15 +33,18 @@ const StorefrontReviewsSchema = zod.z.object({
|
|
|
32
33
|
nextCursor: zod.z.string().nullable(),
|
|
33
34
|
totalCount: zod.z.number().int().nonnegative().nullable()
|
|
34
35
|
});
|
|
36
|
+
const ProductReviewSortSchema = zod.z.enum(["rating", "createdOn"]);
|
|
37
|
+
const ProductReviewDirectionSchema = zod.z.enum(["asc", "desc"]);
|
|
35
38
|
const ListProductReviewsParamsSchema = zod.z.object({
|
|
36
39
|
productId: require_models_ids.EntityIdSchema,
|
|
37
40
|
limit: zod.z.number().int().min(1).max(200).optional(),
|
|
38
41
|
cursor: zod.z.string().optional(),
|
|
39
42
|
search: zod.z.string().optional(),
|
|
40
|
-
sortBy:
|
|
41
|
-
sortDirection:
|
|
43
|
+
sortBy: ProductReviewSortSchema.optional(),
|
|
44
|
+
sortDirection: ProductReviewDirectionSchema.optional(),
|
|
42
45
|
rating: zod.z.number().int().min(1).max(5).optional()
|
|
43
46
|
});
|
|
47
|
+
const ProductWithReviewsSchema = require_models_products.ProductSummarySchema.extend({ reviews: zod.z.array(StorefrontReviewSchema) });
|
|
44
48
|
const CreateProductReviewParamsSchema = zod.z.object({
|
|
45
49
|
productId: require_models_ids.EntityIdSchema,
|
|
46
50
|
rating: zod.z.number().int().min(1).max(5),
|
|
@@ -62,6 +66,9 @@ exports.CreateCustomerProductReviewParamsSchema = CreateCustomerProductReviewPar
|
|
|
62
66
|
exports.CreateProductReviewParamsSchema = CreateProductReviewParamsSchema;
|
|
63
67
|
exports.ListProductReviewsParamsSchema = ListProductReviewsParamsSchema;
|
|
64
68
|
exports.ListStoreReviewsParamsSchema = ListStoreReviewsParamsSchema;
|
|
69
|
+
exports.ProductReviewDirectionSchema = ProductReviewDirectionSchema;
|
|
70
|
+
exports.ProductReviewSortSchema = ProductReviewSortSchema;
|
|
71
|
+
exports.ProductWithReviewsSchema = ProductWithReviewsSchema;
|
|
65
72
|
exports.StorefrontReviewSchema = StorefrontReviewSchema;
|
|
66
73
|
exports.StorefrontReviewsSchema = StorefrontReviewsSchema;
|
|
67
74
|
exports.StorefrontStoreReviewSchema = StorefrontStoreReviewSchema;
|