cloudcommerce 0.0.2 → 0.0.5

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 (48) hide show
  1. package/{.eslintrc.js → .eslintrc.cjs} +4 -4
  2. package/.github/renovate.json +2 -1
  3. package/CHANGELOG.md +34 -0
  4. package/README.md +2 -2
  5. package/package.json +11 -7
  6. package/packages/api/lib/index.d.ts +134 -0
  7. package/packages/api/lib/index.js +89 -0
  8. package/packages/api/lib/index.js.map +1 -0
  9. package/packages/api/lib/types/applications.d.ts +208 -0
  10. package/packages/api/lib/types/authentications.d.ts +97 -0
  11. package/packages/api/lib/types/brands.d.ts +148 -0
  12. package/packages/api/lib/types/carts.d.ts +292 -0
  13. package/packages/api/lib/types/categories.d.ts +190 -0
  14. package/packages/api/lib/types/collections.d.ts +151 -0
  15. package/packages/api/lib/types/customers.d.ts +495 -0
  16. package/packages/api/lib/types/grids.d.ts +149 -0
  17. package/packages/api/lib/types/orders.d.ts +1588 -0
  18. package/packages/api/lib/types/products.d.ts +1284 -0
  19. package/packages/api/lib/types/stores.d.ts +120 -0
  20. package/packages/api/lib/types.d.ts +39 -0
  21. package/packages/api/lib/types.js +2 -0
  22. package/packages/api/lib/types.js.map +1 -0
  23. package/packages/api/package.json +5 -3
  24. package/packages/api/scripts/build.sh +6 -0
  25. package/packages/api/src/index.ts +66 -72
  26. package/packages/api/src/types/applications.d.ts +208 -0
  27. package/packages/api/src/types/authentications.d.ts +97 -0
  28. package/packages/api/src/types/brands.d.ts +148 -0
  29. package/packages/api/src/types/carts.d.ts +292 -0
  30. package/packages/api/src/types/categories.d.ts +190 -0
  31. package/packages/api/src/types/collections.d.ts +151 -0
  32. package/packages/api/src/types/customers.d.ts +495 -0
  33. package/packages/api/src/types/grids.d.ts +149 -0
  34. package/packages/api/src/types/orders.d.ts +1588 -0
  35. package/packages/api/src/types/products.d.ts +1284 -0
  36. package/packages/api/src/types/stores.d.ts +120 -0
  37. package/packages/api/src/types.ts +76 -0
  38. package/packages/api/tests/fetch-polyfill.js +21 -0
  39. package/packages/api/tests/index.test.ts +30 -0
  40. package/packages/api/tsconfig.json +2 -97
  41. package/packages/apps/discounts/package.json +1 -1
  42. package/packages/storefront/package.json +3 -2
  43. package/tsconfig.json +107 -0
  44. package/tsconfig.test.json +11 -0
  45. package/turbo.json +9 -1
  46. package/vite.config.ts +12 -0
  47. package/packages/api/dist/index.js +0 -73
  48. package/packages/api/dist/index.js.map +0 -1
@@ -0,0 +1,120 @@
1
+ /* tslint:disable */
2
+ /**
3
+ * This file was automatically generated by json-schema-to-typescript.
4
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5
+ * and run json-schema-to-typescript to regenerate this file.
6
+ */
7
+
8
+ export interface Stores {
9
+ _id: string;
10
+ created_at: string;
11
+ updated_at: string;
12
+ store_id: number;
13
+ /**
14
+ * Store name
15
+ */
16
+ name: string;
17
+ /**
18
+ * Simple description of store
19
+ */
20
+ description?: string;
21
+ /**
22
+ * ID of store main segment, get options and IDs at /segments.json
23
+ */
24
+ segment_id: number;
25
+ /**
26
+ * Responsible person or organization document type
27
+ */
28
+ doc_type: 'CPF' | 'CNPJ';
29
+ /**
30
+ * Responsible person or organization document number (only numbers)
31
+ */
32
+ doc_number: string;
33
+ /**
34
+ * Municipal or state registration if exists
35
+ */
36
+ inscription_type?: 'State' | 'Municipal';
37
+ /**
38
+ * Municipal or state registration number (with characters) if exists
39
+ */
40
+ inscription_number?: string;
41
+ /**
42
+ * Registered company name or responsible fullname
43
+ */
44
+ corporate_name: string;
45
+ /**
46
+ * Full registered address of company
47
+ */
48
+ address?: string;
49
+ /**
50
+ * Financial contact phone
51
+ */
52
+ phone?: string;
53
+ /**
54
+ * Name of company representative for commercial contact
55
+ */
56
+ representant_name?: string;
57
+ /**
58
+ * Email address of company representative
59
+ */
60
+ representant_email?: string;
61
+ /**
62
+ * Public email address for news and general contact
63
+ */
64
+ contact_email?: string;
65
+ /**
66
+ * Email address to receive notifications, invoices and vouchers
67
+ */
68
+ financial_email: string;
69
+ /**
70
+ * Image link to shop's logo
71
+ */
72
+ logo?: {
73
+ /**
74
+ * Image link
75
+ */
76
+ url: string;
77
+ /**
78
+ * Image size (width x height) in px, such as 100x50 (100px width, 50px height)
79
+ */
80
+ size?: string;
81
+ /**
82
+ * Alternative text, HTML alt tag (important for SEO)
83
+ */
84
+ alt?: string;
85
+ };
86
+ /**
87
+ * Preferred sales channel domain name, with subdomain if any
88
+ */
89
+ domain?: string;
90
+ /**
91
+ * Preferred shop homepage link (full URI)
92
+ */
93
+ homepage?: string;
94
+ /**
95
+ * Main colors to compose shop's visual identity
96
+ */
97
+ brand_colors?: {
98
+ /**
99
+ * Primary color RGB code with #
100
+ */
101
+ primary?: string;
102
+ /**
103
+ * Secondary color RGB code with #
104
+ */
105
+ secondary?: string;
106
+ };
107
+ /**
108
+ * Public contact phone
109
+ */
110
+ contact_phone?: string;
111
+ /**
112
+ * Secondary public contact phone, commonly a cell phone number
113
+ */
114
+ contact_cellphone?: string;
115
+ sales_channels?: {
116
+ channel_id: string;
117
+ type?: 'ecommerce' | 'mobile' | 'pos' | 'button' | 'social' | 'chatbot' | 'live';
118
+ title?: string;
119
+ }[];
120
+ }
@@ -0,0 +1,76 @@
1
+ import type { Products } from './types/products';
2
+ import type { Categories } from './types/categories';
3
+ import type { Brands } from './types/brands';
4
+ import type { Collections } from './types/collections';
5
+ import type { Grids } from './types/grids';
6
+ import type { Carts } from './types/carts';
7
+ import type { Orders } from './types/orders';
8
+ import type { Customers } from './types/customers';
9
+ import type { Stores } from './types/stores';
10
+ import type { Applications } from './types/applications';
11
+
12
+ type Resource = 'products'
13
+ | 'categories'
14
+ | 'brands'
15
+ | 'collections'
16
+ | 'grids'
17
+ | 'carts'
18
+ | 'orders'
19
+ | 'customers'
20
+ | 'stores'
21
+ | 'applications';
22
+
23
+ type ResourceId = string & { length: 24 };
24
+
25
+ type ResourceAndId = `${Resource}/${ResourceId}`;
26
+
27
+ type Endpoint = Resource | ResourceAndId | `${ResourceAndId}/${string}`;
28
+
29
+ type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
30
+
31
+ type Config = {
32
+ baseUrl?: string,
33
+ storeId?: number,
34
+ lang?: string,
35
+ method?: Method,
36
+ endpoint: Endpoint,
37
+ params?: Record<string, string | number>,
38
+ headers?: Record<string, string>,
39
+ timeout?: number,
40
+ };
41
+
42
+ type ReadConfig<endpoint> = Config & { method?: 'get', endpoint: endpoint };
43
+
44
+ type ResponseBody<T> =
45
+ T extends Config & { method: 'post' } ? { _id: ResourceId } :
46
+ T extends Config & { method: 'put' | 'patch' | 'delete' } ? null :
47
+ T extends ReadConfig<`products/${ResourceId}`> ? Products :
48
+ T extends ReadConfig<`categories/${ResourceId}`> ? Categories :
49
+ T extends ReadConfig<`brands/${ResourceId}`> ? Brands :
50
+ T extends ReadConfig<`collections/${ResourceId}`> ? Collections :
51
+ T extends ReadConfig<`grids/${ResourceId}`> ? Grids :
52
+ T extends ReadConfig<`carts/${ResourceId}`> ? Carts :
53
+ T extends ReadConfig<`orders/${ResourceId}`> ? Orders :
54
+ T extends ReadConfig<`customers/${ResourceId}`> ? Customers :
55
+ T extends ReadConfig<`stores/${ResourceId}`> ? Stores :
56
+ T extends ReadConfig<`applications/${ResourceId}`> ? Applications :
57
+ any
58
+
59
+ export type {
60
+ Products,
61
+ Categories,
62
+ Brands,
63
+ Collections,
64
+ Grids,
65
+ Carts,
66
+ Orders,
67
+ Customers,
68
+ Stores,
69
+ Applications,
70
+ Resource,
71
+ ResourceAndId,
72
+ Endpoint,
73
+ Method,
74
+ Config,
75
+ ResponseBody,
76
+ };
@@ -0,0 +1,21 @@
1
+ /* eslint-disable import/no-extraneous-dependencies, no-unused-vars */
2
+
3
+ import fetch, {
4
+ Blob,
5
+ blobFrom,
6
+ blobFromSync,
7
+ File,
8
+ fileFrom,
9
+ fileFromSync,
10
+ FormData,
11
+ Headers,
12
+ Request,
13
+ Response,
14
+ } from 'node-fetch';
15
+
16
+ if (!globalThis.fetch) {
17
+ globalThis.fetch = fetch;
18
+ globalThis.Headers = Headers;
19
+ globalThis.Request = Request;
20
+ globalThis.Response = Response;
21
+ }
@@ -0,0 +1,30 @@
1
+ /* eslint-disable no-console, import/no-extraneous-dependencies */
2
+
3
+ import { test, expect } from 'vitest';
4
+ import './fetch-polyfill';
5
+ import api from '../src/index';
6
+
7
+ const productId = '618041aa239b7206d3fc06de';
8
+ test('Read product and typecheck SKU', async () => {
9
+ const { data } = await api({
10
+ storeId: 1056,
11
+ endpoint: `products/${productId}`,
12
+ });
13
+ if (data.sku === '123') {
14
+ console.log('\\o/');
15
+ }
16
+ expect(data.sku).toBeTypeOf('string');
17
+ expect(data._id).toBe(productId);
18
+ });
19
+
20
+ test('404 with different Store ID from env', async () => {
21
+ process.env.ECOM_STORE_ID = '1011';
22
+ try {
23
+ const { data } = await api.get(`products/${productId}`);
24
+ console.log(data);
25
+ throw new Error('Should have thrown not found');
26
+ } catch (error: any) {
27
+ expect(error.statusCode).toBe(404);
28
+ expect(error.response?.status).toBe(404);
29
+ }
30
+ });
@@ -1,101 +1,6 @@
1
1
  {
2
+ "extends": "../../tsconfig.json",
2
3
  "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Projects */
6
- // "incremental": true, /* Enable incremental compilation */
7
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
- // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
9
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
10
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
-
13
- /* Language and Environment */
14
- "target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
- // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
- // "jsx": "preserve", /* Specify what JSX code is generated. */
17
- // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
20
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
22
- // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
23
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
-
26
- /* Modules */
27
- "module": "es2020", /* Specify what module code is generated. */
28
- // "rootDir": "lib/app/src", /* Specify the root folder within your source files. */
29
- "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
30
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
31
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
32
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
33
- // "typeRoots": ["lib/app/src/@types"], /* Specify multiple folders that act like `./node_modules/@types`. */
34
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
35
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
36
- "resolveJsonModule": true, /* Enable importing .json files */
37
- // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
38
-
39
- /* JavaScript Support */
40
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
41
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
42
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
43
-
44
- /* Emit */
45
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
46
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
47
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
48
- "sourceMap": true, /* Create source map files for emitted JavaScript files. */
49
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
50
- "outDir": "dist", /* Specify an output folder for all emitted files. */
51
- "removeComments": false, /* Disable emitting comments. */
52
- // "noEmit": true, /* Disable emitting files from a compilation. */
53
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
54
- // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
55
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
56
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
57
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
59
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
60
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
61
- "newLine": "lf", /* Set the newline character for emitting files. */
62
- // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
63
- // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
64
- "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
65
- // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
66
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
67
- // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
68
-
69
- /* Interop Constraints */
70
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
71
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
72
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
73
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
74
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
75
-
76
- /* Type Checking */
77
- "strict": true, /* Enable all strict type-checking options. */
78
- "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
79
- // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
80
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
81
- // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
82
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
83
- // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
84
- // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
85
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
86
- // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
87
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
88
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
89
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
90
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
91
- // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
92
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
93
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
94
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
95
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
96
-
97
- /* Completeness */
98
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
4
+ "declaration": true
100
5
  }
101
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-discounts",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "E-Com Plus Cloud Commerce app for complex discount rules",
5
5
  "main": "functions/dist/index.js",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcommerce/storefront",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "E-Com Plus Cloud Commerce storefront with Astro",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -18,6 +18,7 @@
18
18
  "build": "echo '@ecomplus/storefront'"
19
19
  },
20
20
  "dependencies": {
21
- "@cloudcommerce/api": "workspace:*"
21
+ "@cloudcommerce/api": "workspace:*",
22
+ "astro": "1.0.0-beta.46"
22
23
  }
23
24
  }
package/tsconfig.json ADDED
@@ -0,0 +1,107 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
+
5
+ /* Projects */
6
+ // "incremental": true, /* Enable incremental compilation */
7
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
+ // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
9
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
10
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
+
13
+ /* Language and Environment */
14
+ "target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
17
+ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
+ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
20
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
22
+ // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
23
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
+
26
+ /* Modules */
27
+ "module": "es2020", /* Specify what module code is generated. */
28
+ // "rootDir": "src", /* Specify the root folder within your source files. */
29
+ "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
30
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
31
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
32
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
33
+ // "typeRoots": ["lib/app/src/@types"], /* Specify multiple folders that act like `./node_modules/@types`. */
34
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
35
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
36
+ "resolveJsonModule": true, /* Enable importing .json files */
37
+ // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
38
+
39
+ /* JavaScript Support */
40
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
41
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
42
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
43
+
44
+ /* Emit */
45
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
46
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
47
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
48
+ "sourceMap": true, /* Create source map files for emitted JavaScript files. */
49
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
50
+ "outDir": "dist", /* Specify an output folder for all emitted files. */
51
+ "removeComments": false, /* Disable emitting comments. */
52
+ // "noEmit": true, /* Disable emitting files from a compilation. */
53
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
54
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
55
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
56
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
57
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
59
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
60
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
61
+ "newLine": "lf", /* Set the newline character for emitting files. */
62
+ // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
63
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
64
+ "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
65
+ // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
66
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
67
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
68
+
69
+ /* Interop Constraints */
70
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
71
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
72
+ "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
73
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
74
+ "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
75
+
76
+ /* Type Checking */
77
+ "strict": true, /* Enable all strict type-checking options. */
78
+ "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
79
+ // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
80
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
81
+ // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
82
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
83
+ // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
84
+ // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
85
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
86
+ // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
87
+ // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
88
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
89
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
90
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
91
+ // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
92
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
93
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
94
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
95
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
96
+
97
+ /* Completeness */
98
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
100
+ },
101
+ "exclude": [
102
+ "**/node_modules/**",
103
+ "**/dist/**",
104
+ "**/scripts/**",
105
+ "**/tests/**"
106
+ ]
107
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": true
5
+ },
6
+ "include": [
7
+ "packages/*/tests/**/*.ts"
8
+ ],
9
+ "exclude": [
10
+ ]
11
+ }
package/turbo.json CHANGED
@@ -9,6 +9,14 @@
9
9
  "outputs": [
10
10
  "**/dist/**"
11
11
  ]
12
+ },
13
+ "test": {
14
+ "outputs": []
12
15
  }
13
- }
16
+ },
17
+ "globalDependencies": [
18
+ ".env",
19
+ "tsconfig.json",
20
+ "vite.config.ts"
21
+ ]
14
22
  }
package/vite.config.ts ADDED
@@ -0,0 +1,12 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ /// <reference types="vitest" />
3
+ // Configure Vitest (https://vitest.dev/config/)
4
+
5
+ import { defineConfig } from 'vite';
6
+
7
+ export default defineConfig({
8
+ test: {
9
+ globals: true,
10
+ reporters: 'verbose',
11
+ },
12
+ });
@@ -1,73 +0,0 @@
1
- // @ts-ignore
2
- const env = (typeof window === 'object' && window)
3
- || (typeof process === 'object' && process && process.env)
4
- || {};
5
- const def = {
6
- middleware(options) {
7
- let url = options.baseUrl || env.API_BASE_URL || 'https://ecomplus.io/v2';
8
- if (!url) {
9
- const storeId = options.storeId || env.ECOM_STORE_ID;
10
- if (!storeId) {
11
- throw new Error('`storeId` must be set in options or `ECOM_STORE_ID` env var');
12
- }
13
- url += `/:${storeId}`;
14
- const lang = options.lang || env.ECOM_LANG;
15
- if (lang) {
16
- url += `,lang:${lang}`;
17
- }
18
- }
19
- if (options.params) {
20
- if (typeof options.params === 'string') {
21
- url += `?${options.params}`;
22
- }
23
- else {
24
- // https://github.com/microsoft/TypeScript/issues/32951
25
- url += `?${new URLSearchParams(options.params)}`;
26
- }
27
- }
28
- return `${url}/${options.endpoint}`;
29
- },
30
- };
31
- // eslint-disable-next-line no-unused-vars
32
- const setMiddleware = (middleware) => {
33
- def.middleware = middleware;
34
- };
35
- const callApi = (options) => {
36
- const url = def.middleware(options);
37
- const { method, headers } = options;
38
- return fetch(url, { method, headers });
39
- };
40
- const get = (endpoint, options) => callApi({
41
- ...options,
42
- method: 'get',
43
- endpoint,
44
- });
45
- const post = (endpoint, options) => callApi({
46
- ...options,
47
- method: 'post',
48
- endpoint,
49
- });
50
- const put = (endpoint, options) => callApi({
51
- ...options,
52
- method: 'put',
53
- endpoint,
54
- });
55
- const patch = (endpoint, options) => callApi({
56
- ...options,
57
- method: 'patch',
58
- endpoint,
59
- });
60
- const del = (endpoint, options) => callApi({
61
- ...options,
62
- method: 'delete',
63
- endpoint,
64
- });
65
- callApi.get = get;
66
- callApi.post = post;
67
- callApi.put = put;
68
- callApi.patch = patch;
69
- callApi.del = del;
70
- callApi.delete = del;
71
- export default callApi;
72
- export { setMiddleware, get, post, put, patch, del, };
73
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAyBA,aAAa;AACb,MAAM,GAAG,GAA8B,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC;OACxE,CAAC,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC;OACvD,EAAE,CAAC;AAER,MAAM,GAAG,GAAG;IACV,UAAU,CAAC,OAAmB;QAC5B,IAAI,GAAG,GAAG,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,YAAY,IAAI,wBAAwB,CAAC;QAC1E,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,aAAa,CAAC;YACrD,IAAI,CAAC,OAAO,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;aAChF;YACD,GAAG,IAAI,KAAK,OAAO,EAAE,CAAC;YACtB,MAAM,IAAI,GA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