cloudcommerce 0.0.4 → 0.0.7

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 (39) hide show
  1. package/.eslintrc.cjs +2 -1
  2. package/CHANGELOG.md +35 -0
  3. package/package.json +10 -9
  4. package/packages/api/lib/index.d.ts +183 -0
  5. package/packages/api/lib/index.js +115 -0
  6. package/packages/api/lib/index.js.map +1 -0
  7. package/packages/api/{dist → lib}/types/applications.d.ts +0 -0
  8. package/packages/api/{dist → lib}/types/authentications.d.ts +0 -0
  9. package/packages/api/{dist → lib}/types/brands.d.ts +0 -0
  10. package/packages/api/{dist → lib}/types/carts.d.ts +0 -0
  11. package/packages/api/{dist → lib}/types/categories.d.ts +0 -0
  12. package/packages/api/{dist → lib}/types/collections.d.ts +0 -0
  13. package/packages/api/{dist → lib}/types/customers.d.ts +0 -0
  14. package/packages/api/{dist → lib}/types/grids.d.ts +0 -0
  15. package/packages/api/{dist → lib}/types/orders.d.ts +0 -0
  16. package/packages/api/{dist → lib}/types/products.d.ts +0 -0
  17. package/packages/api/{dist → lib}/types/stores.d.ts +0 -0
  18. package/packages/api/lib/types.d.ts +77 -0
  19. package/packages/api/lib/types.js +2 -0
  20. package/packages/api/{dist → lib}/types.js.map +0 -0
  21. package/packages/api/package.json +5 -5
  22. package/packages/api/scripts/build.sh +6 -0
  23. package/packages/api/src/index.ts +74 -34
  24. package/packages/api/src/types.ts +96 -16
  25. package/packages/api/tests/index.test.ts +50 -10
  26. package/packages/api/tsconfig.json +6 -0
  27. package/packages/apps/discounts/package.json +1 -1
  28. package/packages/storefront/package.json +3 -2
  29. package/tsconfig.json +2 -1
  30. package/tsconfig.test.json +5 -100
  31. package/turbo.json +6 -1
  32. package/vite.config.ts +12 -0
  33. package/packages/api/dist/index.d.ts +0 -65
  34. package/packages/api/dist/index.js +0 -89
  35. package/packages/api/dist/index.js.map +0 -1
  36. package/packages/api/dist/types.d.ts +0 -65
  37. package/packages/api/dist/types.js +0 -2
  38. package/packages/api/scripts/build.mjs +0 -5
  39. package/packages/api/scripts/test.mjs +0 -4
@@ -5,6 +5,20 @@ const env: { [key: string]: string } = (typeof window === 'object' && window)
5
5
  || (typeof process === 'object' && process && process.env)
6
6
  || {};
7
7
 
8
+ class ApiError extends Error {
9
+ config: Config;
10
+ response?: Response;
11
+ statusCode?: number;
12
+ isTimeout: boolean;
13
+ constructor(config: Config, response?: Response, msg?: string, isTimeout: boolean = false) {
14
+ super(response?.statusText || msg || 'Request error');
15
+ this.config = config;
16
+ this.response = response;
17
+ this.statusCode = response?.status;
18
+ this.isTimeout = isTimeout;
19
+ }
20
+ }
21
+
8
22
  const def = {
9
23
  middleware(config: Config) {
10
24
  let url = config.baseUrl || env.API_BASE_URL || 'https://ecomplus.io/v2';
@@ -29,76 +43,101 @@ const def = {
29
43
  },
30
44
  };
31
45
 
32
- // eslint-disable-next-line no-unused-vars
33
46
  const setMiddleware = (middleware: typeof def.middleware) => {
34
47
  def.middleware = middleware;
35
48
  };
36
49
 
37
- const callApi = async <T extends Config>(config: T): Promise<Response & {
50
+ const api = async <T extends Config>(config: T, retries = 0): Promise<Response & {
38
51
  config: Config,
39
52
  data: ResponseBody<T>,
40
53
  }> => {
41
54
  const url = def.middleware(config);
42
- const { method, headers, timeout = 20000 } = config;
43
- const abortController = new AbortController();
44
- const timer = setTimeout(() => abortController.abort(), timeout);
45
- const response = await fetch(url, {
55
+ const {
46
56
  method,
47
57
  headers,
48
- signal: abortController.signal,
49
- });
58
+ timeout = 20000,
59
+ maxRetries = 3,
60
+ } = config;
61
+ const abortController = new AbortController();
62
+ let isTimeout = false;
63
+ const timer = setTimeout(() => {
64
+ abortController.abort();
65
+ isTimeout = true;
66
+ }, timeout);
67
+ let response: Response | undefined;
68
+ try {
69
+ response = await (config.fetch || fetch)(url, {
70
+ method,
71
+ headers,
72
+ signal: abortController.signal,
73
+ });
74
+ } catch (err: any) {
75
+ throw new ApiError(config, response, err.message, isTimeout);
76
+ }
50
77
  clearTimeout(timer);
51
- if (response.ok) {
52
- return {
53
- ...response,
54
- config,
55
- data: await response.json(),
56
- };
78
+ if (response) {
79
+ if (response.ok) {
80
+ return {
81
+ ...response,
82
+ config,
83
+ data: await response.json(),
84
+ };
85
+ }
86
+ const { status } = response;
87
+ if (maxRetries < retries && (status === 429 || status >= 500)) {
88
+ const retryAfter = response.headers.get('retry-after');
89
+ return new Promise((resolve, reject) => {
90
+ setTimeout(() => {
91
+ api(config, retries + 1).then(resolve).catch(reject);
92
+ }, (retryAfter && parseInt(retryAfter, 10)) || 5000);
93
+ });
94
+ }
57
95
  }
58
- const error: any = new Error(response.statusText);
59
- error.config = config;
60
- error.response = response;
61
- throw error;
96
+ throw new ApiError(config, response);
62
97
  };
63
98
 
64
- const get = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => callApi({
65
- ...config,
66
- method: 'get',
67
- endpoint,
68
- });
99
+ type AbstractedConfig = Omit<Config, 'endpoint' | 'method'>;
100
+
101
+ const get = <E extends Endpoint, C extends AbstractedConfig>(
102
+ endpoint: E,
103
+ config?: C,
104
+ ): Promise<Response & {
105
+ config: Config,
106
+ data: ResponseBody<{ endpoint: E }>,
107
+ }> => api({ ...config, endpoint });
69
108
 
70
- const post = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => callApi({
109
+ const post = (endpoint: Endpoint, config?: AbstractedConfig) => api({
71
110
  ...config,
72
111
  method: 'post',
73
112
  endpoint,
74
113
  });
75
114
 
76
- const put = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => callApi({
115
+ const put = (endpoint: Endpoint, config?: AbstractedConfig) => api({
77
116
  ...config,
78
117
  method: 'put',
79
118
  endpoint,
80
119
  });
81
120
 
82
- const patch = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => callApi({
121
+ const patch = (endpoint: Endpoint, config?: AbstractedConfig) => api({
83
122
  ...config,
84
123
  method: 'patch',
85
124
  endpoint,
86
125
  });
87
126
 
88
- const del = (endpoint: Endpoint, config: Exclude<Config, 'method'>) => callApi({
127
+ const del = (endpoint: Endpoint, config?: AbstractedConfig) => api({
89
128
  ...config,
90
129
  method: 'delete',
91
130
  endpoint,
92
131
  });
93
132
 
94
- callApi.get = get;
95
- callApi.post = post;
96
- callApi.put = put;
97
- callApi.patch = patch;
98
- callApi.del = del;
99
- callApi.delete = del;
133
+ api.get = get;
134
+ api.post = post;
135
+ api.put = put;
136
+ api.patch = patch;
137
+ api.del = del;
138
+ api.delete = del;
100
139
 
101
- export default callApi;
140
+ export default api;
102
141
 
103
142
  export {
104
143
  setMiddleware,
@@ -107,4 +146,5 @@ export {
107
146
  put,
108
147
  patch,
109
148
  del,
149
+ ApiError,
110
150
  };
@@ -24,7 +24,22 @@ type ResourceId = string & { length: 24 };
24
24
 
25
25
  type ResourceAndId = `${Resource}/${ResourceId}`;
26
26
 
27
- type Endpoint = Resource | ResourceAndId | `${ResourceAndId}/${string}`;
27
+ type EventsEndpoint = `events/${Resource}`
28
+ | `events/${ResourceAndId}`
29
+ | 'events/me';
30
+
31
+ type Endpoint = Resource
32
+ | ResourceAndId
33
+ | `${ResourceAndId}/${string}`
34
+ | `slugs/${string}`
35
+ | 'search/v1'
36
+ | EventsEndpoint
37
+ | 'login'
38
+ | 'authenticate'
39
+ | 'ask-auth-callback'
40
+ | 'check-username'
41
+ | `$aggregate/${Exclude<Resource, 'stores' | 'applications'>}`
42
+ | `schemas/${Resource}`;
28
43
 
29
44
  type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
30
45
 
@@ -32,27 +47,92 @@ type Config = {
32
47
  baseUrl?: string,
33
48
  storeId?: number,
34
49
  lang?: string,
35
- method: Method,
50
+ method?: Method,
36
51
  endpoint: Endpoint,
37
52
  params?: Record<string, string | number>,
38
53
  headers?: Record<string, string>,
39
54
  timeout?: number,
55
+ maxRetries?: number,
56
+ fetch?: typeof fetch,
57
+ };
58
+
59
+ type BaseListResultMeta = {
60
+ offset: number,
61
+ limit: number,
62
+ fields: Array<string>,
63
+ };
64
+
65
+ type ResourceListResult<TResource extends Resource> = {
66
+ result:
67
+ TResource extends 'products' ? Products[] :
68
+ TResource extends 'categories' ? Categories[] :
69
+ TResource extends 'brands' ? Brands[] :
70
+ TResource extends 'collections' ? Collections[] :
71
+ TResource extends 'grids' ? Grids[] :
72
+ TResource extends 'carts' ? Carts[] :
73
+ TResource extends 'orders' ? Orders[] :
74
+ TResource extends 'customers' ? Customers[] :
75
+ TResource extends 'stores' ? Stores[] :
76
+ TResource extends 'applications' ? Applications[] :
77
+ never,
78
+ meta: BaseListResultMeta & {
79
+ count?: number,
80
+ sort: Array<{
81
+ field: string,
82
+ order: 1 | -1,
83
+ }>,
84
+ query: { [key: string]: any },
85
+ },
86
+ };
87
+
88
+ type EventFieldsByEndpoint<TEndpoint extends EventsEndpoint> =
89
+ TEndpoint extends `events/${Resource}` ? {
90
+ resource_id: ResourceId,
91
+ authentication_id: ResourceId | null,
92
+ } :
93
+ TEndpoint extends `events/${ResourceAndId}` ? {
94
+ authentication_id: ResourceId | null,
95
+ } :
96
+ TEndpoint extends 'events/me' ? {
97
+ resource: Resource,
98
+ resource_id: ResourceId,
99
+ } :
100
+ never;
101
+
102
+ type EventsResult<TEndpoint extends EventsEndpoint> = {
103
+ result: Array<{
104
+ timestamp: string,
105
+ store_id?: number,
106
+ resource?: string,
107
+ authentication_id?: ResourceId | null,
108
+ resource_id?: ResourceId,
109
+ action: string,
110
+ modified_fields: string[],
111
+ method?: number | undefined,
112
+ endpoint?: string,
113
+ body?: any,
114
+ ip?: string,
115
+ } & EventFieldsByEndpoint<TEndpoint>>,
116
+ meta: BaseListResultMeta,
40
117
  };
41
118
 
42
- type ResponseBody<T> =
43
- T extends Config & { method: 'post' } ? { _id: ResourceId } :
44
- T extends Config & { method: 'put' | 'patch' | 'delete' } ? null :
45
- T extends Config & { method: 'get', endpoint: `products/${ResourceId}` } ? Products :
46
- T extends Config & { method: 'get', endpoint: `categories/${ResourceId}` } ? Categories :
47
- T extends Config & { method: 'get', endpoint: `brands/${ResourceId}` } ? Brands :
48
- T extends Config & { method: 'get', endpoint: `collections/${ResourceId}` } ? Collections :
49
- T extends Config & { method: 'get', endpoint: `grids/${ResourceId}` } ? Grids :
50
- T extends Config & { method: 'get', endpoint: `carts/${ResourceId}` } ? Carts :
51
- T extends Config & { method: 'get', endpoint: `orders/${ResourceId}` } ? Orders :
52
- T extends Config & { method: 'get', endpoint: `customers/${ResourceId}` } ? Customers :
53
- T extends Config & { method: 'get', endpoint: `stores/${ResourceId}` } ? Stores :
54
- T extends Config & { method: 'get', endpoint: `applications/${ResourceId}` } ? Applications :
55
- any
119
+ type ResponseBody<TConfig extends Config> =
120
+ TConfig['method'] extends 'post' ? { _id: ResourceId } :
121
+ TConfig['method'] extends 'put' | 'patch' | 'delete' ? null :
122
+ // method?: 'get'
123
+ TConfig['endpoint'] extends `products/${ResourceId}` ? Products :
124
+ TConfig['endpoint'] extends `categories/${ResourceId}` ? Categories :
125
+ TConfig['endpoint'] extends `brands/${ResourceId}` ? Brands :
126
+ TConfig['endpoint'] extends `collections/${ResourceId}` ? Collections :
127
+ TConfig['endpoint'] extends `grids/${ResourceId}` ? Grids :
128
+ TConfig['endpoint'] extends `carts/${ResourceId}` ? Carts :
129
+ TConfig['endpoint'] extends `orders/${ResourceId}` ? Orders :
130
+ TConfig['endpoint'] extends `customers/${ResourceId}` ? Customers :
131
+ TConfig['endpoint'] extends `stores/${ResourceId}` ? Stores :
132
+ TConfig['endpoint'] extends `applications/${ResourceId}` ? Applications :
133
+ TConfig['endpoint'] extends Resource ? ResourceListResult<TConfig['endpoint']> :
134
+ TConfig['endpoint'] extends EventsEndpoint ? EventsResult<TConfig['endpoint']> :
135
+ any;
56
136
 
57
137
  export type {
58
138
  Products,
@@ -1,14 +1,54 @@
1
- /* eslint-disable no-console */
1
+ /* eslint-disable no-console, import/no-extraneous-dependencies */
2
+
3
+ import { test, expect } from 'vitest';
2
4
  import './fetch-polyfill';
3
- import callApi from '../src/index';
4
-
5
- callApi({
6
- storeId: 1056,
7
- method: 'get',
8
- endpoint: 'products/618041aa239b7206d3fc06de',
9
- }).then(({ data }) => {
10
- if (data.sku === 'string') {
5
+ import api, { ApiError } 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') {
11
14
  console.log('\\o/');
12
15
  }
13
- console.info(`✓ Read product ${data.sku} and checked SKU type string`);
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 (err: any) {
27
+ const error = err as ApiError;
28
+ expect(error.statusCode).toBe(404);
29
+ expect(error.response?.status).toBe(404);
30
+ }
31
+ });
32
+
33
+ test('List categories and typecheck result', async () => {
34
+ const { data } = await api.get('categories');
35
+ if (data.result === []) {
36
+ console.log('Any category found');
37
+ }
38
+ expect(Array.isArray(data.result)).toBe(true);
39
+ expect(data.meta).toBeTypeOf('object');
40
+ expect(data.meta.offset).toBeTypeOf('number');
41
+ });
42
+
43
+ test('401 trying to list API events', async () => {
44
+ try {
45
+ const { data } = await api.get('events/orders');
46
+ console.log(data);
47
+ console.log(data.result[0].modified_fields);
48
+ throw new Error('Should have thrown unauthorized');
49
+ } catch (err: any) {
50
+ const error = err as ApiError;
51
+ expect(error.statusCode).toBe(401);
52
+ expect(error.response?.status).toBe(401);
53
+ }
14
54
  });
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true
5
+ }
6
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcommerce/app-discounts",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
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.4",
3
+ "version": "0.0.7",
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 CHANGED
@@ -99,8 +99,9 @@
99
99
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
100
100
  },
101
101
  "exclude": [
102
- "**/dist/**",
103
102
  "**/node_modules/**",
103
+ "**/dist/**",
104
+ "**/scripts/**",
104
105
  "**/tests/**"
105
106
  ]
106
107
  }
@@ -1,106 +1,11 @@
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": "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": true, /* 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
+ "noEmit": true
100
5
  },
6
+ "include": [
7
+ "packages/*/tests/**/*.ts"
8
+ ],
101
9
  "exclude": [
102
- "**/dist/**",
103
- "**/node_modules/**",
104
- "**/src/**"
105
10
  ]
106
11
  }
package/turbo.json CHANGED
@@ -13,5 +13,10 @@
13
13
  "test": {
14
14
  "outputs": []
15
15
  }
16
- }
16
+ },
17
+ "globalDependencies": [
18
+ ".env",
19
+ "tsconfig.json",
20
+ "vite.config.ts"
21
+ ]
17
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,65 +0,0 @@
1
- import type { Endpoint, Config, ResponseBody } from './types';
2
- declare const def: {
3
- middleware(config: Config): string;
4
- };
5
- declare const setMiddleware: (middleware: (config: Config) => string) => void;
6
- declare const callApi: {
7
- <T extends Config>(config: T): Promise<Response & {
8
- config: Config;
9
- data: ResponseBody<T>;
10
- }>;
11
- get: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
12
- config: Config;
13
- data: any;
14
- }>;
15
- post: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
16
- config: Config;
17
- data: {
18
- _id: string & {
19
- length: 24;
20
- };
21
- };
22
- }>;
23
- put: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
24
- config: Config;
25
- data: null;
26
- }>;
27
- patch: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
28
- config: Config;
29
- data: null;
30
- }>;
31
- del: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
32
- config: Config;
33
- data: null;
34
- }>;
35
- delete: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
36
- config: Config;
37
- data: null;
38
- }>;
39
- };
40
- declare const get: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
41
- config: Config;
42
- data: any;
43
- }>;
44
- declare const post: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
45
- config: Config;
46
- data: {
47
- _id: string & {
48
- length: 24;
49
- };
50
- };
51
- }>;
52
- declare const put: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
53
- config: Config;
54
- data: null;
55
- }>;
56
- declare const patch: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
57
- config: Config;
58
- data: null;
59
- }>;
60
- declare const del: (endpoint: Endpoint, config: Exclude<Config, 'method'>) => Promise<Response & {
61
- config: Config;
62
- data: null;
63
- }>;
64
- export default callApi;
65
- export { setMiddleware, get, post, put, patch, del, };