@cloudcommerce/api 0.0.125 → 0.0.127
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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-test.log +7 -7
- package/lib/api.d.ts +4 -4
- package/lib/types.d.ts +41 -41
- package/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
|
|
2
|
-
> @cloudcommerce/api@0.0.
|
|
2
|
+
> @cloudcommerce/api@0.0.126 test /home/leo/code/ecomplus/cloud-commerce/packages/api
|
|
3
3
|
> tsc -p ../../tsconfig.test.json && vitest run
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
RUN v0.
|
|
6
|
+
RUN v0.25.3 /home/leo/code/ecomplus/cloud-commerce/packages/api
|
|
7
7
|
|
|
8
8
|
✓ tests/index.test.ts > Read product and typecheck SKU
|
|
9
|
-
(node:
|
|
9
|
+
(node:43307) [https://github.com/node-fetch/node-fetch/issues/1000 (response)] DeprecationWarning: data doesn't exist, use json(), text(), arrayBuffer(), or body instead
|
|
10
10
|
(Use `node --trace-deprecation ...` to show where the warning was created)
|
|
11
11
|
✓ tests/index.test.ts > 404 with different Store ID from env
|
|
12
12
|
✓ tests/index.test.ts > List categories and typecheck result
|
|
13
13
|
✓ tests/index.test.ts > 401 trying to list API events
|
|
14
14
|
✓ tests/index.test.ts > 401 to create category and body typecheck
|
|
15
15
|
|
|
16
|
-
Test Files 1 passed (1)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
Test Files 1 passed (1)
|
|
17
|
+
Tests 5 passed (5)
|
|
18
|
+
Start at 20:06:51
|
|
19
|
+
Duration 2.82s (transform 912ms, setup 0ms, collect 173ms, tests 1.14s)
|
|
20
20
|
|
package/lib/api.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ declare const api: {
|
|
|
70
70
|
data: null;
|
|
71
71
|
}>;
|
|
72
72
|
};
|
|
73
|
-
|
|
73
|
+
type AbstractedConfig = Omit<Config, 'endpoint' | 'method'>;
|
|
74
74
|
declare const get: <E extends Endpoint, C extends AbstractedConfig>(endpoint: E, config?: C | undefined) => Promise<Response & {
|
|
75
75
|
config: Config;
|
|
76
76
|
data: E extends `${string}/${string}/${string}` ? any : E extends `products/${string}` ? import("./types").Products : E extends `categories/${string}` ? import("./types").Categories : E extends `brands/${string}` ? import("./types").Brands : E extends `collections/${string}` ? import("./types").Collections : E extends `grids/${string}` ? import("./types").Grids : E extends `carts/${string}` ? import("./types").Carts : E extends `orders/${string}` ? import("./types").Orders : E extends `customers/${string}` ? import("./types").Customers : E extends `stores/${string}` ? import("./types").Stores : E extends `applications/${string}` ? import("./types").Applications : E extends `authentications/${string}` ? import("./types").Authentications : E extends ResourceOpQuery ? import("./types").ResourceListResult<E> : E extends "events/products" | "events/categories" | "events/brands" | "events/collections" | "events/grids" | "events/carts" | "events/orders" | "events/customers" | "events/stores" | "events/applications" | "events/authentications" | `events/products/${string}` | `events/categories/${string}` | `events/brands/${string}` | `events/collections/${string}` | `events/grids/${string}` | `events/carts/${string}` | `events/orders/${string}` | `events/customers/${string}` | `events/stores/${string}` | `events/applications/${string}` | `events/authentications/${string}` | "events/me" ? import("./types").EventsResult<E> : any;
|
|
@@ -103,6 +103,6 @@ declare const del: (endpoint: Endpoint, config?: AbstractedConfig) => Promise<Re
|
|
|
103
103
|
}>;
|
|
104
104
|
export default api;
|
|
105
105
|
export { setMiddleware, get, post, put, patch, del, ApiError, };
|
|
106
|
-
export
|
|
107
|
-
export
|
|
108
|
-
export
|
|
106
|
+
export type ApiEndpoint = Endpoint;
|
|
107
|
+
export type ApiConfig = Config;
|
|
108
|
+
export type ApiErrorBody = ErrorBody;
|
package/lib/types.d.ts
CHANGED
|
@@ -9,16 +9,16 @@ import type { Customers } from './types/customers';
|
|
|
9
9
|
import type { Stores } from './types/stores';
|
|
10
10
|
import type { Applications } from './types/applications';
|
|
11
11
|
import type { Authentications } from './types/authentications';
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
type Resource = 'products' | 'categories' | 'brands' | 'collections' | 'grids' | 'carts' | 'orders' | 'customers' | 'stores' | 'applications' | 'authentications';
|
|
13
|
+
type ResourceId = string & {
|
|
14
14
|
length: 24;
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
type ResourceAndId = `${Resource}/${ResourceId}`;
|
|
17
|
+
type ResourceOpQuery = Resource | `${Resource}?${string}`;
|
|
18
|
+
type EventsEndpoint = `events/${Resource}` | `events/${ResourceAndId}` | 'events/me';
|
|
19
|
+
type Endpoint = ResourceOpQuery | ResourceAndId | `${ResourceAndId}/${string}` | `slugs/${string}` | 'search/v1' | EventsEndpoint | 'login' | 'authenticate' | 'ask-auth-callback' | 'check-username' | `$aggregate/${Exclude<Resource, 'stores' | 'applications' | 'authentications'>}` | `schemas/${Resource}`;
|
|
20
|
+
type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
21
|
+
type Config = {
|
|
22
22
|
baseUrl?: string;
|
|
23
23
|
storeId?: number;
|
|
24
24
|
accessToken?: string;
|
|
@@ -36,27 +36,27 @@ declare type Config = {
|
|
|
36
36
|
cacheMaxAge?: number;
|
|
37
37
|
fetch?: typeof fetch;
|
|
38
38
|
};
|
|
39
|
-
|
|
39
|
+
type BaseListResultMeta = {
|
|
40
40
|
offset: number;
|
|
41
41
|
limit: number;
|
|
42
42
|
fields: Array<string>;
|
|
43
43
|
};
|
|
44
|
-
|
|
44
|
+
type ListResultDocs<Document extends any> = Array<Partial<Document> & {
|
|
45
45
|
_id: ResourceId;
|
|
46
46
|
}>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
type ProductsList = ListResultDocs<Products>;
|
|
48
|
+
type CategoriesList = ListResultDocs<Categories>;
|
|
49
|
+
type BrandsList = ListResultDocs<Brands>;
|
|
50
|
+
type CollectionsList = ListResultDocs<Collections>;
|
|
51
|
+
type GridsList = ListResultDocs<Grids>;
|
|
52
|
+
type CartsList = ListResultDocs<Carts>;
|
|
53
|
+
type OrdersList = ListResultDocs<Orders>;
|
|
54
|
+
type CustomersList = ListResultDocs<Customers>;
|
|
55
|
+
type StoresList = ListResultDocs<Stores>;
|
|
56
|
+
type ApplicationsList = ListResultDocs<Applications>;
|
|
57
|
+
type AuthenticationsList = ListResultDocs<Authentications>;
|
|
58
|
+
type ListEndpoint<TResource extends Resource> = TResource | `${TResource}?${string}`;
|
|
59
|
+
type ResourceListResult<TEndpoint extends ResourceOpQuery> = {
|
|
60
60
|
result: TEndpoint extends ListEndpoint<'products'> ? ProductsList : TEndpoint extends ListEndpoint<'categories'> ? CategoriesList : TEndpoint extends ListEndpoint<'brands'> ? BrandsList : TEndpoint extends ListEndpoint<'collections'> ? CollectionsList : TEndpoint extends ListEndpoint<'grids'> ? GridsList : TEndpoint extends ListEndpoint<'carts'> ? CartsList : TEndpoint extends ListEndpoint<'orders'> ? OrdersList : TEndpoint extends ListEndpoint<'customers'> ? CustomersList : TEndpoint extends ListEndpoint<'stores'> ? StoresList : TEndpoint extends ListEndpoint<'applications'> ? ApplicationsList : TEndpoint extends ListEndpoint<'authentications'> ? AuthenticationsList : never;
|
|
61
61
|
meta: BaseListResultMeta & {
|
|
62
62
|
count?: number;
|
|
@@ -69,7 +69,7 @@ declare type ResourceListResult<TEndpoint extends ResourceOpQuery> = {
|
|
|
69
69
|
};
|
|
70
70
|
};
|
|
71
71
|
};
|
|
72
|
-
|
|
72
|
+
type EventFieldsByEndpoint<TEndpoint extends EventsEndpoint> = TEndpoint extends `events/${Resource}` ? {
|
|
73
73
|
resource_id: ResourceId;
|
|
74
74
|
authentication_id: ResourceId | null;
|
|
75
75
|
} : TEndpoint extends `events/${ResourceAndId}` ? {
|
|
@@ -78,7 +78,7 @@ declare type EventFieldsByEndpoint<TEndpoint extends EventsEndpoint> = TEndpoint
|
|
|
78
78
|
resource: Resource;
|
|
79
79
|
resource_id: ResourceId;
|
|
80
80
|
} : never;
|
|
81
|
-
|
|
81
|
+
type EventsResult<TEndpoint extends EventsEndpoint> = {
|
|
82
82
|
result: Array<{
|
|
83
83
|
timestamp: string;
|
|
84
84
|
store_id?: number;
|
|
@@ -94,7 +94,7 @@ declare type EventsResult<TEndpoint extends EventsEndpoint> = {
|
|
|
94
94
|
} & EventFieldsByEndpoint<TEndpoint>>;
|
|
95
95
|
meta: BaseListResultMeta;
|
|
96
96
|
};
|
|
97
|
-
|
|
97
|
+
type ResponseBody<TConfig extends Config> = TConfig['method'] extends 'post' ? TConfig['endpoint'] extends 'login' ? {
|
|
98
98
|
_id: ResourceId;
|
|
99
99
|
store_ids: number[];
|
|
100
100
|
api_key: string;
|
|
@@ -105,21 +105,21 @@ declare type ResponseBody<TConfig extends Config> = TConfig['method'] extends 'p
|
|
|
105
105
|
} : {
|
|
106
106
|
_id: ResourceId;
|
|
107
107
|
} : TConfig['method'] extends 'put' | 'patch' | 'delete' ? null : TConfig['endpoint'] extends `${string}/${ResourceId}/${string}` ? any : TConfig['endpoint'] extends `products/${ResourceId}` ? Products : TConfig['endpoint'] extends `categories/${ResourceId}` ? Categories : TConfig['endpoint'] extends `brands/${ResourceId}` ? Brands : TConfig['endpoint'] extends `collections/${ResourceId}` ? Collections : TConfig['endpoint'] extends `grids/${ResourceId}` ? Grids : TConfig['endpoint'] extends `carts/${ResourceId}` ? Carts : TConfig['endpoint'] extends `orders/${ResourceId}` ? Orders : TConfig['endpoint'] extends `customers/${ResourceId}` ? Customers : TConfig['endpoint'] extends `stores/${ResourceId}` ? Stores : TConfig['endpoint'] extends `applications/${ResourceId}` ? Applications : TConfig['endpoint'] extends `authentications/${ResourceId}` ? Authentications : TConfig['endpoint'] extends ResourceOpQuery ? ResourceListResult<TConfig['endpoint']> : TConfig['endpoint'] extends EventsEndpoint ? EventsResult<TConfig['endpoint']> : any;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
108
|
+
type DocSchema<Document extends any> = Omit<Document, '_id' | 'store_id' | 'store_ids' | 'created_at' | 'updated_at'>;
|
|
109
|
+
type CustomerSet = DocSchema<Customers>;
|
|
110
|
+
type OrderSet = DocSchema<Orders>;
|
|
111
|
+
type CartSet = DocSchema<Carts>;
|
|
112
|
+
type ProductSet = DocSchema<Products>;
|
|
113
|
+
type CategorySet = DocSchema<Categories>;
|
|
114
|
+
type BrandSet = DocSchema<Brands>;
|
|
115
|
+
type CollectionSet = DocSchema<Collections>;
|
|
116
|
+
type GridSet = DocSchema<Grids>;
|
|
117
|
+
type StoreSet = DocSchema<Stores>;
|
|
118
|
+
type ApplicationSet = DocSchema<Applications>;
|
|
119
|
+
type AuthenticationSet = DocSchema<Authentications>;
|
|
120
|
+
type SetDocEndpoint<TResource extends Resource> = TResource | `${TResource}/${ResourceId}`;
|
|
121
|
+
type RequestBody<TConfig extends Config> = TConfig['method'] extends undefined | 'get' | 'delete' ? undefined : TConfig['method'] extends 'patch' ? any : TConfig['endpoint'] extends SetDocEndpoint<'products'> ? ProductSet : TConfig['endpoint'] extends SetDocEndpoint<'categories'> ? CategorySet : TConfig['endpoint'] extends SetDocEndpoint<'brands'> ? BrandSet : TConfig['endpoint'] extends SetDocEndpoint<'collections'> ? CollectionSet : TConfig['endpoint'] extends SetDocEndpoint<'grids'> ? GridSet : TConfig['endpoint'] extends SetDocEndpoint<'carts'> ? CartSet : TConfig['endpoint'] extends SetDocEndpoint<'orders'> ? OrderSet : TConfig['endpoint'] extends SetDocEndpoint<'customers'> ? CustomerSet : TConfig['endpoint'] extends SetDocEndpoint<'stores'> ? StoreSet : TConfig['endpoint'] extends SetDocEndpoint<'applications'> ? ApplicationSet : TConfig['endpoint'] extends SetDocEndpoint<'authentications'> ? AuthenticationSet : any;
|
|
122
|
+
type ErrorBody = {
|
|
123
123
|
status: number;
|
|
124
124
|
error_code: number;
|
|
125
125
|
message: string;
|