@commercelayer/demo-store-types 2.2.0 → 3.0.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 CHANGED
@@ -10,7 +10,7 @@ By using this package, that operation will be much easier to do and error-proof.
10
10
 
11
11
  <img width="1158" alt="IntelliSense in Visual Studio Code" src="https://user-images.githubusercontent.com/1681269/208510718-23cd21e1-e602-41f7-8748-440bbb07d5ea.png">
12
12
 
13
- ## Data
13
+ ## Create data
14
14
 
15
15
  The Demo Store data are composed of a set of 8 JSON files usually located at `/data/json`.
16
16
 
@@ -82,9 +82,29 @@ The Demo Store data are composed of a set of 8 JSON files usually located at `/d
82
82
  )
83
83
  ```
84
84
 
85
+ ## Test data
86
+
87
+ This package is shipped with built-in tests.
88
+
89
+ You can use it inside a JavaScript file like so:
90
+
91
+ ```js
92
+ //= runTestData.js
93
+
94
+ const { testJsonData } = require('@commercelayer/demo-store-types/dist/test')
95
+
96
+ testJsonData('./data/json/')
97
+ ```
98
+
99
+ ```sh
100
+ node runTestData.js
101
+ ```
102
+
85
103
  ## Example
86
104
 
87
- Here below you can find a working example with Node.js 18 that converts a list of products coming from an external service, to the Demo Store `products.json`:
105
+ Here below you can find a working example with Node.js 18 that converts a list of products coming from an external service, to the Demo Store `products.json`.
106
+
107
+ Setup a new project from scratch:
88
108
 
89
109
  ```sh
90
110
  mkdir demo
@@ -93,6 +113,8 @@ npm init -y
93
113
  npm install typescript @types/node tsm @commercelayer/demo-store-types
94
114
  ```
95
115
 
116
+ Create a new file `index.ts`:
117
+
96
118
  ```ts
97
119
  //= index.ts
98
120
 
@@ -128,7 +150,16 @@ import { writeFile } from 'fs/promises'
128
150
  console.log(demoStoreProducts)
129
151
 
130
152
  })()
153
+ ```
154
+
155
+ Just run:
131
156
 
157
+ ```sh
158
+ node -r tsm index.ts
159
+ ```
160
+
161
+ ```ts
162
+ //= output
132
163
 
133
164
  // [
134
165
  // {
@@ -178,7 +209,3 @@ import { writeFile } from 'fs/promises'
178
209
  // }
179
210
  // ]
180
211
  ```
181
-
182
- ```sh
183
- node -r tsm index.ts
184
- ```
@@ -185,47 +185,181 @@ export declare const rawDataProducts_schema: z.ZodArray<z.ZodObject<{
185
185
  * ]
186
186
  */
187
187
  details: z.ZodOptional<z.ZodArray<DetailSchema>>;
188
- }, "passthrough", z.ZodTypeAny, {
189
- details?: {
190
- title: {
191
- [localeCode: string]: string;
192
- };
193
- content: {
194
- [localeCode: string]: string;
195
- };
196
- }[] | undefined;
197
- name: {
198
- [localeCode: string]: string;
199
- };
200
- description: {
201
- [localeCode: string]: string;
202
- };
203
- productCode: string;
204
- variantCode: string;
205
- sku: string;
206
- slug: string;
207
- images: string[];
208
- }, {
209
- details?: {
210
- title: {
211
- [localeCode: string]: string;
212
- };
213
- content: {
214
- [localeCode: string]: string;
215
- };
216
- }[] | undefined;
217
- name: {
218
- [localeCode: string]: string;
219
- };
220
- description: {
221
- [localeCode: string]: string;
222
- };
223
- productCode: string;
224
- variantCode: string;
225
- sku: string;
226
- slug: string;
227
- images: string[];
228
- }>, "many">;
188
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
189
+ /**
190
+ * The **product code** identifies the base product
191
+ *
192
+ * A master product or base product is a non-sellable product that represents a group of similar or related products.
193
+ *
194
+ * For example, a clothing retailer may have a master product for each type of clothing item, such as "men's t-shirts" or "women's dresses".
195
+ * Each of these master products would contain multiple variations, such as different sizes, colors, and styles.
196
+ */
197
+ productCode: z.ZodString;
198
+ /**
199
+ * The **variant code** identifies a variation product
200
+ *
201
+ * A variation product is a product that is part of a group of similar or related products,
202
+ * and it is identified by specific attributes or characteristics that distinguish it from the other products in the group (color, material, size, etc.).
203
+ *
204
+ * The `variantCode`, in Demo Store, is used for grouping similar products in the listing page.
205
+ * Usually a different `variantCode` corresponds to a different product image.
206
+ */
207
+ variantCode: z.ZodString;
208
+ /**
209
+ * The **sku** is a **unique identifier**, meaning *Stock Keeping Unit*.
210
+ *
211
+ * This is the stock unit in a warehouse used to track availability and stock variations of an item to be sold.
212
+ * SKUs can be a variant of any item (e.g., Medium or Large size of a jogger pant).
213
+ *
214
+ * An SKU usually consists of letters and numbers (either EAN code, UPC, or any other code format) like "LSLEEVMM000000FFFFFFMXXX".
215
+ * SKU refers to an item's details, including variants data (e.g., a T-shirt, Red color, Nike brand, 0.5g, XL size).
216
+ * An SKU identifies each product item's characteristics such as manufacturer name, brand name, style, color, weight, and size.
217
+ */
218
+ sku: z.ZodString;
219
+ /**
220
+ * The product URL slug
221
+ *
222
+ * The slug is the part of a URL that identifies a particular page on a website in an easy-to-read form.
223
+ *
224
+ * It should always start with a forward slash (`/`).
225
+ * @example "/white-apron-with-black-logo/APRONXXXFFFFFF000000XXXX"
226
+ */
227
+ slug: z.ZodEffects<z.ZodString>;
228
+ /**
229
+ * The localized product name
230
+ *
231
+ * @example
232
+ * {
233
+ * "it": "Maglietta Grigia",
234
+ * "en-US": "Gray T-Shirt"
235
+ * }
236
+ */
237
+ name: LocalizedFieldSchema<z.ZodString>;
238
+ /**
239
+ * The localized product description
240
+ *
241
+ * @example
242
+ * {
243
+ * "it": "Descrizione"
244
+ * "en-US": "Description",
245
+ * }
246
+ */
247
+ description: LocalizedFieldSchema<z.ZodString>;
248
+ /**
249
+ * A carousel of image URLs that represent the product
250
+ *
251
+ * @example
252
+ * [
253
+ * "https://res.cloudinary.com/commercelayer/image/upload/f_auto,b_white/demo-store/skus/TSHIRTMSB0B0B2000000LXXX_FLAT.png"
254
+ * ]
255
+ */
256
+ images: z.ZodArray<z.ZodString>;
257
+ /**
258
+ * Additional product details
259
+ *
260
+ * This attribute is presented as accordion just below the "Add to cart" button.
261
+ *
262
+ * @example
263
+ * [
264
+ * {
265
+ * "title": {
266
+ * "en": "Details"
267
+ * },
268
+ * "content": {
269
+ * "en": "Content here."
270
+ * }
271
+ * }
272
+ * ]
273
+ */
274
+ details: z.ZodOptional<z.ZodArray<DetailSchema>>;
275
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
276
+ /**
277
+ * The **product code** identifies the base product
278
+ *
279
+ * A master product or base product is a non-sellable product that represents a group of similar or related products.
280
+ *
281
+ * For example, a clothing retailer may have a master product for each type of clothing item, such as "men's t-shirts" or "women's dresses".
282
+ * Each of these master products would contain multiple variations, such as different sizes, colors, and styles.
283
+ */
284
+ productCode: z.ZodString;
285
+ /**
286
+ * The **variant code** identifies a variation product
287
+ *
288
+ * A variation product is a product that is part of a group of similar or related products,
289
+ * and it is identified by specific attributes or characteristics that distinguish it from the other products in the group (color, material, size, etc.).
290
+ *
291
+ * The `variantCode`, in Demo Store, is used for grouping similar products in the listing page.
292
+ * Usually a different `variantCode` corresponds to a different product image.
293
+ */
294
+ variantCode: z.ZodString;
295
+ /**
296
+ * The **sku** is a **unique identifier**, meaning *Stock Keeping Unit*.
297
+ *
298
+ * This is the stock unit in a warehouse used to track availability and stock variations of an item to be sold.
299
+ * SKUs can be a variant of any item (e.g., Medium or Large size of a jogger pant).
300
+ *
301
+ * An SKU usually consists of letters and numbers (either EAN code, UPC, or any other code format) like "LSLEEVMM000000FFFFFFMXXX".
302
+ * SKU refers to an item's details, including variants data (e.g., a T-shirt, Red color, Nike brand, 0.5g, XL size).
303
+ * An SKU identifies each product item's characteristics such as manufacturer name, brand name, style, color, weight, and size.
304
+ */
305
+ sku: z.ZodString;
306
+ /**
307
+ * The product URL slug
308
+ *
309
+ * The slug is the part of a URL that identifies a particular page on a website in an easy-to-read form.
310
+ *
311
+ * It should always start with a forward slash (`/`).
312
+ * @example "/white-apron-with-black-logo/APRONXXXFFFFFF000000XXXX"
313
+ */
314
+ slug: z.ZodEffects<z.ZodString>;
315
+ /**
316
+ * The localized product name
317
+ *
318
+ * @example
319
+ * {
320
+ * "it": "Maglietta Grigia",
321
+ * "en-US": "Gray T-Shirt"
322
+ * }
323
+ */
324
+ name: LocalizedFieldSchema<z.ZodString>;
325
+ /**
326
+ * The localized product description
327
+ *
328
+ * @example
329
+ * {
330
+ * "it": "Descrizione"
331
+ * "en-US": "Description",
332
+ * }
333
+ */
334
+ description: LocalizedFieldSchema<z.ZodString>;
335
+ /**
336
+ * A carousel of image URLs that represent the product
337
+ *
338
+ * @example
339
+ * [
340
+ * "https://res.cloudinary.com/commercelayer/image/upload/f_auto,b_white/demo-store/skus/TSHIRTMSB0B0B2000000LXXX_FLAT.png"
341
+ * ]
342
+ */
343
+ images: z.ZodArray<z.ZodString>;
344
+ /**
345
+ * Additional product details
346
+ *
347
+ * This attribute is presented as accordion just below the "Add to cart" button.
348
+ *
349
+ * @example
350
+ * [
351
+ * {
352
+ * "title": {
353
+ * "en": "Details"
354
+ * },
355
+ * "content": {
356
+ * "en": "Content here."
357
+ * }
358
+ * }
359
+ * ]
360
+ */
361
+ details: z.ZodOptional<z.ZodArray<DetailSchema>>;
362
+ }, z.ZodTypeAny, "passthrough">>, "many">;
229
363
  /**
230
364
  * Product
231
365
  *
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs_1 = require("fs");
4
+ const data_1 = require("./data");
5
+ const path = process.argv[2];
6
+ if (!path || !(0, fs_1.existsSync)(path)) {
7
+ throw new Error(`Folder "${path}" doesn't exist!`);
8
+ }
9
+ (0, data_1.testJsonData)(path);
@@ -0,0 +1 @@
1
+ export declare function testJsonData(path: string): void;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.testJsonData = void 0;
39
+ const at_1 = __importDefault(require("lodash/at"));
40
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
41
+ const set_1 = __importDefault(require("lodash/set"));
42
+ const path_1 = require("path");
43
+ const uvu_1 = require("uvu");
44
+ const assert_1 = require("uvu/assert");
45
+ const __1 = require("..");
46
+ function importJson(...paths) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ return (yield Promise.resolve(`${(0, path_1.resolve)(...paths)}`).then(s => __importStar(require(s)))).default;
49
+ });
50
+ }
51
+ function green(test) {
52
+ test('', () => {
53
+ (0, assert_1.is)(true, true);
54
+ });
55
+ }
56
+ function testJsonData(path) {
57
+ test('catalogs.json', __1.rawDataCatalogs_schema);
58
+ test('countries.json', __1.rawDataCountries_schema);
59
+ test('languages.json', __1.rawDataLanguages_schema);
60
+ test('organization.json', __1.rawDataOrganization_schema);
61
+ test('pages.json', __1.rawDataPages_schema);
62
+ test('products.json', __1.rawDataProducts_schema);
63
+ test('taxonomies.json', __1.rawDataTaxonomies_schema);
64
+ test('taxons.json', __1.rawDataTaxons_schema);
65
+ function test(filename, schema) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const suiteName = filename;
68
+ // const suiteName = `'${filename}' should be properly defined.`
69
+ const json = yield importJson(path, filename);
70
+ const result = schema.safeParse(json);
71
+ const test = (0, uvu_1.suite)(suiteName);
72
+ if (result.success === true) {
73
+ green(test);
74
+ }
75
+ else {
76
+ result.error.issues.forEach(issue => {
77
+ // @ts-expect-error
78
+ const expectedType = issue.expected ? ` - Expected type '${issue.expected}'` : '';
79
+ const testName = `Path '${issue.path.join('.')}' - ${issue.message}${expectedType}`;
80
+ test(testName, () => {
81
+ const actual = (0, at_1.default)(json, [issue.path[0]])[0];
82
+ const expected = (0, cloneDeep_1.default)(actual);
83
+ (0, set_1.default)(expected, issue.path.slice(1), `ERROR - ${issue.message}${expectedType}`);
84
+ (0, assert_1.equal)(actual, expected, ' ');
85
+ });
86
+ });
87
+ }
88
+ test.run();
89
+ });
90
+ }
91
+ }
92
+ exports.testJsonData = testJsonData;
@@ -0,0 +1 @@
1
+ export * from './data';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./data"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/demo-store-types",
3
- "version": "2.2.0",
3
+ "version": "3.0.0",
4
4
  "description": "Demo Store types",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,10 +8,13 @@
8
8
  "dist"
9
9
  ],
10
10
  "dependencies": {
11
- "zod": "^3.20.6"
11
+ "@types/lodash": "^4.14.202",
12
+ "lodash": "^4.17.21",
13
+ "uvu": "^0.5.6",
14
+ "zod": "^3.22.4"
12
15
  },
13
16
  "devDependencies": {
14
- "typescript": "^4.9.5"
17
+ "typescript": "^5.3.3"
15
18
  },
16
19
  "scripts": {
17
20
  "ts:check": "tsc --noEmit",
@@ -22,5 +25,5 @@
22
25
  "publishConfig": {
23
26
  "access": "public"
24
27
  },
25
- "gitHead": "b0c40b8bf993413e7c97b237426e51ba436e612d"
28
+ "gitHead": "92098b0f4a6031ba61353a48c29b69f0f7937c1a"
26
29
  }