@cloudcommerce/api 1.0.0-alpha.8 → 2.0.1
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 +4 -5
- package/.turbo/turbo-test.log +18 -0
- package/LICENSE.md +230 -0
- package/lib/api.d.ts +125 -0
- package/lib/api.js +215 -0
- package/lib/api.js.map +1 -0
- package/package.json +10 -3
- package/src/api.ts +298 -0
- package/tests/index.test.ts +82 -0
- package/tsconfig.json +2 -97
- package/types/applications.d.ts +180 -0
- package/types/authentications.d.ts +121 -0
- package/types/brands.d.ts +174 -0
- package/types/carts.d.ts +380 -0
- package/types/categories.d.ts +216 -0
- package/types/collections.d.ts +174 -0
- package/types/customers.d.ts +535 -0
- package/types/grids.d.ts +172 -0
- package/types/orders.d.ts +1743 -0
- package/types/products.d.ts +1441 -0
- package/types/stores.d.ts +138 -0
- package/types.d.ts +509 -0
- package/types.ts +2 -0
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/src/index.ts +0 -27
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
/**
|
|
9
|
+
* Head store and company info
|
|
10
|
+
*/
|
|
11
|
+
export interface Stores {
|
|
12
|
+
/**
|
|
13
|
+
* Store ID (ObjectID) [auto]
|
|
14
|
+
*/
|
|
15
|
+
_id: string & { length: 24 };
|
|
16
|
+
/**
|
|
17
|
+
* When object was seted (POST/PUT), date and time in ISO 8601 standard representation [auto]
|
|
18
|
+
*/
|
|
19
|
+
created_at: string;
|
|
20
|
+
/**
|
|
21
|
+
* When was it last changed, date and time in ISO 8601 standard representation [auto]
|
|
22
|
+
*/
|
|
23
|
+
updated_at: string;
|
|
24
|
+
/**
|
|
25
|
+
* ID of store [auto]
|
|
26
|
+
*/
|
|
27
|
+
store_id: number;
|
|
28
|
+
/**
|
|
29
|
+
* Store name
|
|
30
|
+
*/
|
|
31
|
+
name: string;
|
|
32
|
+
/**
|
|
33
|
+
* Simple description of store
|
|
34
|
+
*/
|
|
35
|
+
description?: string;
|
|
36
|
+
/**
|
|
37
|
+
* ID of store main segment, get options and IDs at /segments.json
|
|
38
|
+
*/
|
|
39
|
+
segment_id: number;
|
|
40
|
+
/**
|
|
41
|
+
* Responsible person or organization document type
|
|
42
|
+
*/
|
|
43
|
+
doc_type: 'CPF' | 'CNPJ';
|
|
44
|
+
/**
|
|
45
|
+
* Responsible person or organization document number (only numbers)
|
|
46
|
+
*/
|
|
47
|
+
doc_number: string;
|
|
48
|
+
/**
|
|
49
|
+
* Municipal or state registration if exists
|
|
50
|
+
*/
|
|
51
|
+
inscription_type?: 'State' | 'Municipal';
|
|
52
|
+
/**
|
|
53
|
+
* Municipal or state registration number (with characters) if exists
|
|
54
|
+
*/
|
|
55
|
+
inscription_number?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Registered company name or responsible fullname
|
|
58
|
+
*/
|
|
59
|
+
corporate_name: string;
|
|
60
|
+
/**
|
|
61
|
+
* Full registered address of company
|
|
62
|
+
*/
|
|
63
|
+
address?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Financial contact phone
|
|
66
|
+
*/
|
|
67
|
+
phone?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Name of company representative for commercial contact
|
|
70
|
+
*/
|
|
71
|
+
representant_name?: string;
|
|
72
|
+
/**
|
|
73
|
+
* Email address of company representative
|
|
74
|
+
*/
|
|
75
|
+
representant_email?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Public email address for news and general contact
|
|
78
|
+
*/
|
|
79
|
+
contact_email?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Email address to receive notifications, invoices and vouchers
|
|
82
|
+
*/
|
|
83
|
+
financial_email: string;
|
|
84
|
+
/**
|
|
85
|
+
* Image link to shop's logo
|
|
86
|
+
*/
|
|
87
|
+
logo?: {
|
|
88
|
+
/**
|
|
89
|
+
* Image link
|
|
90
|
+
*/
|
|
91
|
+
url: string;
|
|
92
|
+
/**
|
|
93
|
+
* Image size (width x height) in px, such as 100x50 (100px width, 50px height)
|
|
94
|
+
*/
|
|
95
|
+
size?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Alternative text, HTML alt tag (important for SEO)
|
|
98
|
+
*/
|
|
99
|
+
alt?: string;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Preferred sales channel domain name, with subdomain if any
|
|
103
|
+
*/
|
|
104
|
+
domain?: string;
|
|
105
|
+
/**
|
|
106
|
+
* Preferred shop homepage link (full URI)
|
|
107
|
+
*/
|
|
108
|
+
homepage?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Main colors to compose shop's visual identity
|
|
111
|
+
*/
|
|
112
|
+
brand_colors?: {
|
|
113
|
+
/**
|
|
114
|
+
* Primary color RGB code with #
|
|
115
|
+
*/
|
|
116
|
+
primary?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Secondary color RGB code with #
|
|
119
|
+
*/
|
|
120
|
+
secondary?: string;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Public contact phone
|
|
124
|
+
*/
|
|
125
|
+
contact_phone?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Secondary public contact phone, commonly a cell phone number
|
|
128
|
+
*/
|
|
129
|
+
contact_cellphone?: string;
|
|
130
|
+
/**
|
|
131
|
+
* @maxItems 30
|
|
132
|
+
*/
|
|
133
|
+
sales_channels?: {
|
|
134
|
+
channel_id: string;
|
|
135
|
+
type?: 'ecommerce' | 'mobile' | 'pos' | 'button' | 'social' | 'chatbot' | 'live';
|
|
136
|
+
title?: string;
|
|
137
|
+
}[];
|
|
138
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,509 @@
|
|
|
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
|
+
import type { Authentications } from './types/authentications';
|
|
12
|
+
|
|
13
|
+
type Resource = 'products'
|
|
14
|
+
| 'categories'
|
|
15
|
+
| 'brands'
|
|
16
|
+
| 'collections'
|
|
17
|
+
| 'grids'
|
|
18
|
+
| 'carts'
|
|
19
|
+
| 'orders'
|
|
20
|
+
| 'customers'
|
|
21
|
+
| 'stores'
|
|
22
|
+
| 'applications'
|
|
23
|
+
| 'authentications';
|
|
24
|
+
|
|
25
|
+
type ResourceId = string & { length: 24 };
|
|
26
|
+
type ResourceAndId = `${Resource}/${ResourceId}`;
|
|
27
|
+
type ResourceAndFind = ResourceAndId
|
|
28
|
+
| `${Resource}/${string}:${string}`
|
|
29
|
+
| 'stores/me'
|
|
30
|
+
| 'authentications/me';
|
|
31
|
+
type ResourceOpQuery = Resource | `${Resource}?${string}`;
|
|
32
|
+
|
|
33
|
+
type SearchV1OpQuery = 'search/v1'
|
|
34
|
+
| `search/v1?${string}`;
|
|
35
|
+
type SearchOpQuery = SearchV1OpQuery
|
|
36
|
+
| 'search/_els'
|
|
37
|
+
| `search/_els?${string}`;
|
|
38
|
+
|
|
39
|
+
type SearchHistoryOpQuery = 'search/v1/history'
|
|
40
|
+
| `search/v1/history?${string}`;
|
|
41
|
+
|
|
42
|
+
type EventsEndpoint = `events/${Resource}`
|
|
43
|
+
| `events/${ResourceAndId}`
|
|
44
|
+
| 'events/me';
|
|
45
|
+
|
|
46
|
+
type Endpoint = ResourceOpQuery
|
|
47
|
+
| ResourceAndFind
|
|
48
|
+
| `${ResourceAndFind}/${string}`
|
|
49
|
+
| `slugs/${string}`
|
|
50
|
+
| SearchOpQuery
|
|
51
|
+
| SearchHistoryOpQuery
|
|
52
|
+
| EventsEndpoint
|
|
53
|
+
| 'login'
|
|
54
|
+
| 'authenticate'
|
|
55
|
+
| 'ask-auth-callback'
|
|
56
|
+
| 'check-username'
|
|
57
|
+
| `$aggregate/${Exclude<Resource, 'stores' | 'applications' | 'authentications'>}`
|
|
58
|
+
| `schemas/${Resource}`;
|
|
59
|
+
|
|
60
|
+
type Method = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
61
|
+
|
|
62
|
+
type Config = {
|
|
63
|
+
baseUrl?: string,
|
|
64
|
+
storeId?: number,
|
|
65
|
+
accessToken?: string,
|
|
66
|
+
authenticationId?: string,
|
|
67
|
+
apiKey?: string,
|
|
68
|
+
isNoAuth?: boolean,
|
|
69
|
+
lang?: string,
|
|
70
|
+
method?: Method,
|
|
71
|
+
endpoint: Endpoint,
|
|
72
|
+
fields?: readonly string[],
|
|
73
|
+
sort?: readonly string[],
|
|
74
|
+
limit?: number,
|
|
75
|
+
offset?: number,
|
|
76
|
+
count?: boolean,
|
|
77
|
+
buckets?: boolean,
|
|
78
|
+
verbose?: boolean,
|
|
79
|
+
concise?: boolean,
|
|
80
|
+
params?: string | Record<
|
|
81
|
+
string,
|
|
82
|
+
string | number | boolean | string[] | number[] | undefined,
|
|
83
|
+
>,
|
|
84
|
+
headers?: Headers | Record<string, string>,
|
|
85
|
+
timeout?: number,
|
|
86
|
+
maxRetries?: number,
|
|
87
|
+
canCache?: boolean,
|
|
88
|
+
cacheMaxAge?: number,
|
|
89
|
+
fetch?: typeof fetch,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
type BaseListResultMeta = {
|
|
93
|
+
offset: number,
|
|
94
|
+
limit: number,
|
|
95
|
+
fields: Array<string>,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
type DocField<T extends string> = T extends `${infer U}.${string}` ? U : T;
|
|
99
|
+
type ListResultDocs<
|
|
100
|
+
Document extends Record<string, any>,
|
|
101
|
+
Fields extends string[] | '*' = '*',
|
|
102
|
+
> = Array<Omit<(
|
|
103
|
+
Fields extends '*' ? Partial<Document> :
|
|
104
|
+
Pick<Document, Extract<keyof Document, DocField<Fields[number]>>>
|
|
105
|
+
), '_id'> & { _id: ResourceId }>;
|
|
106
|
+
|
|
107
|
+
type DefaultProductsFields = [
|
|
108
|
+
'sku',
|
|
109
|
+
'slug',
|
|
110
|
+
];
|
|
111
|
+
type ProductsList<Fields extends null | string[] | '*' = '*'> =
|
|
112
|
+
ListResultDocs<Products, Fields extends null ? DefaultProductsFields : Fields>;
|
|
113
|
+
|
|
114
|
+
type DefaultCategoriesFields = [
|
|
115
|
+
'name',
|
|
116
|
+
'slug',
|
|
117
|
+
'parent',
|
|
118
|
+
'icon',
|
|
119
|
+
'pictures.0',
|
|
120
|
+
];
|
|
121
|
+
type CategoriesList<Fields extends null | string[] | '*' = '*'> =
|
|
122
|
+
ListResultDocs<Categories, Fields extends null ? DefaultCategoriesFields : Fields>;
|
|
123
|
+
|
|
124
|
+
type DefaultBrandsFields = [
|
|
125
|
+
'name',
|
|
126
|
+
'slug',
|
|
127
|
+
'logo',
|
|
128
|
+
'pictures.0',
|
|
129
|
+
];
|
|
130
|
+
type BrandsList<Fields extends null | string[] | '*' = '*'> =
|
|
131
|
+
ListResultDocs<Brands, Fields extends null ? DefaultBrandsFields : Fields>;
|
|
132
|
+
|
|
133
|
+
type DefaultCollectionsFields = [
|
|
134
|
+
'name',
|
|
135
|
+
'slug',
|
|
136
|
+
'products',
|
|
137
|
+
'pictures.0',
|
|
138
|
+
];
|
|
139
|
+
type CollectionsList<Fields extends null | string[] | '*' = '*'> =
|
|
140
|
+
ListResultDocs<Collections, Fields extends null ? DefaultCollectionsFields : Fields>;
|
|
141
|
+
|
|
142
|
+
type DefaultGridsFields = [
|
|
143
|
+
'title',
|
|
144
|
+
'grid_id',
|
|
145
|
+
'options.text',
|
|
146
|
+
'options.colors',
|
|
147
|
+
];
|
|
148
|
+
type GridsList<Fields extends null | string[] | '*' = '*'> =
|
|
149
|
+
ListResultDocs<Grids, Fields extends null ? DefaultGridsFields : Fields>;
|
|
150
|
+
|
|
151
|
+
type DefaultCartsFields = [
|
|
152
|
+
'available',
|
|
153
|
+
'completed',
|
|
154
|
+
'permalink',
|
|
155
|
+
'status',
|
|
156
|
+
'customers',
|
|
157
|
+
'other_customers',
|
|
158
|
+
'items.product_id',
|
|
159
|
+
'items.sku',
|
|
160
|
+
'items.name',
|
|
161
|
+
'items.quantity',
|
|
162
|
+
'items.final_price',
|
|
163
|
+
'subtotal',
|
|
164
|
+
];
|
|
165
|
+
type CartsList<Fields extends null | string[] | '*' = '*'> =
|
|
166
|
+
ListResultDocs<Carts, Fields extends null ? DefaultCartsFields : Fields>;
|
|
167
|
+
|
|
168
|
+
type DefaultOrdersFields = [
|
|
169
|
+
'channel_id',
|
|
170
|
+
'number',
|
|
171
|
+
'code',
|
|
172
|
+
'status',
|
|
173
|
+
'financial_status.updated_at',
|
|
174
|
+
'financial_status.current',
|
|
175
|
+
'fulfillment_status.updated_at',
|
|
176
|
+
'fulfillment_status.current',
|
|
177
|
+
'amount',
|
|
178
|
+
'payment_method_label',
|
|
179
|
+
'shipping_method_label',
|
|
180
|
+
'buyers._id',
|
|
181
|
+
'buyers.main_email',
|
|
182
|
+
'buyers.display_name',
|
|
183
|
+
'items.product_id',
|
|
184
|
+
'items.sku',
|
|
185
|
+
'items.name',
|
|
186
|
+
'items.quantity',
|
|
187
|
+
];
|
|
188
|
+
type OrdersList<Fields extends null | string[] | '*' = '*'> =
|
|
189
|
+
ListResultDocs<Orders, Fields extends null ? DefaultOrdersFields : Fields>;
|
|
190
|
+
|
|
191
|
+
type DefaultCustomersFields = [
|
|
192
|
+
'state',
|
|
193
|
+
'enabled',
|
|
194
|
+
'login',
|
|
195
|
+
'status',
|
|
196
|
+
'main_email',
|
|
197
|
+
'accepts_marketing',
|
|
198
|
+
'display_name',
|
|
199
|
+
'orders_count',
|
|
200
|
+
'orders_total_value',
|
|
201
|
+
];
|
|
202
|
+
type CustomersList<Fields extends null | string[] | '*' = '*'> =
|
|
203
|
+
ListResultDocs<Customers, Fields extends null ? DefaultCustomersFields : Fields>;
|
|
204
|
+
|
|
205
|
+
type DefaultStoresFields = [
|
|
206
|
+
'store_id',
|
|
207
|
+
'name',
|
|
208
|
+
'domain',
|
|
209
|
+
];
|
|
210
|
+
type StoresList<Fields extends null | string[] | '*' = '*'> =
|
|
211
|
+
ListResultDocs<Stores, Fields extends null ? DefaultStoresFields : Fields>;
|
|
212
|
+
|
|
213
|
+
type DefaultApplicationsFields = [
|
|
214
|
+
'app_id',
|
|
215
|
+
'title',
|
|
216
|
+
'state',
|
|
217
|
+
'version',
|
|
218
|
+
'type',
|
|
219
|
+
];
|
|
220
|
+
type ApplicationsList<Fields extends null | string[] | '*' = '*'> =
|
|
221
|
+
ListResultDocs<Applications, Fields extends null ? DefaultApplicationsFields : Fields>;
|
|
222
|
+
|
|
223
|
+
type DefaultAuthenticationsFields = [
|
|
224
|
+
'username',
|
|
225
|
+
'email',
|
|
226
|
+
'app',
|
|
227
|
+
];
|
|
228
|
+
type AuthenticationsList<Fields extends null | string[] | '*' = '*'> =
|
|
229
|
+
ListResultDocs<Authentications, Fields extends null ? DefaultAuthenticationsFields : Fields>;
|
|
230
|
+
|
|
231
|
+
type ListEndpoint<TResource extends Resource> = TResource | `${TResource}?${string}`;
|
|
232
|
+
type ResourceListResult<
|
|
233
|
+
TEndpoint extends ResourceOpQuery,
|
|
234
|
+
Fields extends string[] | null = TEndpoint extends Resource ? null : '*',
|
|
235
|
+
> = {
|
|
236
|
+
result:
|
|
237
|
+
TEndpoint extends ListEndpoint<'products'> ? ProductsList<Fields> :
|
|
238
|
+
TEndpoint extends ListEndpoint<'categories'> ? CategoriesList<Fields> :
|
|
239
|
+
TEndpoint extends ListEndpoint<'brands'> ? BrandsList<Fields> :
|
|
240
|
+
TEndpoint extends ListEndpoint<'collections'> ? CollectionsList<Fields> :
|
|
241
|
+
TEndpoint extends ListEndpoint<'grids'> ? GridsList<Fields> :
|
|
242
|
+
TEndpoint extends ListEndpoint<'carts'> ? CartsList<Fields> :
|
|
243
|
+
TEndpoint extends ListEndpoint<'orders'> ? OrdersList<Fields> :
|
|
244
|
+
TEndpoint extends ListEndpoint<'customers'> ? CustomersList<Fields> :
|
|
245
|
+
TEndpoint extends ListEndpoint<'stores'> ? StoresList<Fields> :
|
|
246
|
+
TEndpoint extends ListEndpoint<'applications'> ? ApplicationsList<Fields> :
|
|
247
|
+
TEndpoint extends ListEndpoint<'authentications'> ? AuthenticationsList<Fields> :
|
|
248
|
+
never,
|
|
249
|
+
meta: BaseListResultMeta & {
|
|
250
|
+
count?: number,
|
|
251
|
+
sort: Array<{
|
|
252
|
+
field: string,
|
|
253
|
+
order: 1 | -1,
|
|
254
|
+
}>,
|
|
255
|
+
query: { [key: string]: any },
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
interface SearchProducts extends Products {
|
|
260
|
+
has_variations: boolean;
|
|
261
|
+
_score: number;
|
|
262
|
+
}
|
|
263
|
+
type DefaultSearchFields = [
|
|
264
|
+
'sku',
|
|
265
|
+
'name',
|
|
266
|
+
'slug',
|
|
267
|
+
'available',
|
|
268
|
+
'visible',
|
|
269
|
+
'price',
|
|
270
|
+
'base_price',
|
|
271
|
+
'quantity',
|
|
272
|
+
'min_quantity',
|
|
273
|
+
'inventory',
|
|
274
|
+
'measurement',
|
|
275
|
+
'condition',
|
|
276
|
+
'warranty',
|
|
277
|
+
'pictures.normal',
|
|
278
|
+
'has_variations',
|
|
279
|
+
];
|
|
280
|
+
|
|
281
|
+
type SearchItem<Fields extends null | string[] | '*' = '*'> = Omit<(
|
|
282
|
+
Fields extends '*' ? Partial<SearchProducts> :
|
|
283
|
+
Pick<
|
|
284
|
+
SearchProducts,
|
|
285
|
+
Extract<keyof SearchProducts,
|
|
286
|
+
DocField<Fields extends null ? DefaultSearchFields[number] : Fields[number]>>
|
|
287
|
+
>
|
|
288
|
+
), '_id' | '_score'> & {
|
|
289
|
+
_id: ResourceId,
|
|
290
|
+
_score: number,
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
type SearchResult<
|
|
294
|
+
TEndpoint extends SearchOpQuery | 'v1' | 'els',
|
|
295
|
+
Fields extends string[] | null = TEndpoint extends SearchV1OpQuery | 'v1' ? null : '*',
|
|
296
|
+
> =
|
|
297
|
+
TEndpoint extends SearchV1OpQuery | 'v1' ? {
|
|
298
|
+
result: SearchItem<Fields>[],
|
|
299
|
+
meta: BaseListResultMeta & {
|
|
300
|
+
count?: number,
|
|
301
|
+
sort: Array<{
|
|
302
|
+
field: string,
|
|
303
|
+
order: 1 | -1,
|
|
304
|
+
}>,
|
|
305
|
+
query: { [key: string]: any },
|
|
306
|
+
buckets?: {
|
|
307
|
+
prices?: Array<{
|
|
308
|
+
min: null | number,
|
|
309
|
+
max: null | number,
|
|
310
|
+
avg: null | number,
|
|
311
|
+
count: number,
|
|
312
|
+
}>,
|
|
313
|
+
'brands.name'?: {
|
|
314
|
+
[key: string]: number,
|
|
315
|
+
},
|
|
316
|
+
'categories.name'?: {
|
|
317
|
+
[key: string]: number,
|
|
318
|
+
},
|
|
319
|
+
specs?: {
|
|
320
|
+
[key: string]: number,
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
} :
|
|
325
|
+
TEndpoint extends 'search/_els' | `search/_els?${string}` | 'els' ? {
|
|
326
|
+
hits: {
|
|
327
|
+
hits: SearchItem<'*'>[],
|
|
328
|
+
total: number,
|
|
329
|
+
max_score: null,
|
|
330
|
+
},
|
|
331
|
+
aggregations: Record<string, any>,
|
|
332
|
+
took: number,
|
|
333
|
+
} :
|
|
334
|
+
never;
|
|
335
|
+
|
|
336
|
+
type SearchHistoryResult = {
|
|
337
|
+
result: Array<{
|
|
338
|
+
terms: string[];
|
|
339
|
+
hits_count?: number;
|
|
340
|
+
counted_at?: string;
|
|
341
|
+
}>,
|
|
342
|
+
meta: {
|
|
343
|
+
offset: number,
|
|
344
|
+
limit: number,
|
|
345
|
+
query: {
|
|
346
|
+
terms?: any,
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
type EventFieldsByEndpoint<TEndpoint extends EventsEndpoint> =
|
|
352
|
+
TEndpoint extends `events/${Resource}` ? {
|
|
353
|
+
resource_id: ResourceId,
|
|
354
|
+
authentication_id: ResourceId | null,
|
|
355
|
+
} :
|
|
356
|
+
TEndpoint extends `events/${ResourceAndId}` ? {
|
|
357
|
+
authentication_id: ResourceId | null,
|
|
358
|
+
} :
|
|
359
|
+
TEndpoint extends 'events/me' ? {
|
|
360
|
+
resource: Resource,
|
|
361
|
+
resource_id: ResourceId,
|
|
362
|
+
} :
|
|
363
|
+
never;
|
|
364
|
+
|
|
365
|
+
type EventsResult<TEndpoint extends EventsEndpoint> = {
|
|
366
|
+
result: Array<{
|
|
367
|
+
timestamp: string,
|
|
368
|
+
store_id?: number,
|
|
369
|
+
resource?: string,
|
|
370
|
+
authentication_id?: ResourceId | null,
|
|
371
|
+
resource_id?: ResourceId,
|
|
372
|
+
action: string,
|
|
373
|
+
modified_fields: string[],
|
|
374
|
+
method?: number | undefined,
|
|
375
|
+
endpoint?: string,
|
|
376
|
+
body?: any,
|
|
377
|
+
ip?: string,
|
|
378
|
+
} & EventFieldsByEndpoint<TEndpoint>>,
|
|
379
|
+
meta: BaseListResultMeta,
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
type ResponseBody<
|
|
383
|
+
TConfig extends Config,
|
|
384
|
+
ListFields extends string[] | null = TConfig['endpoint'] extends Resource | SearchV1OpQuery
|
|
385
|
+
? TConfig['params']['fields'] extends string ? '*'
|
|
386
|
+
: TConfig['fields'] extends readonly string[] ? TConfig['fields']
|
|
387
|
+
: null
|
|
388
|
+
: '*',
|
|
389
|
+
> =
|
|
390
|
+
TConfig['method'] extends 'post' ?
|
|
391
|
+
TConfig['endpoint'] extends 'login' ? { _id: ResourceId, store_ids: number[], api_key: string } :
|
|
392
|
+
TConfig['endpoint'] extends 'authenticate' ? { my_id: string, access_token: string, expires: string } :
|
|
393
|
+
{ _id: ResourceId } :
|
|
394
|
+
TConfig['method'] extends 'put' | 'patch' | 'delete' ? null :
|
|
395
|
+
// method?: 'get'
|
|
396
|
+
TConfig['endpoint'] extends `${string}/${ResourceId}/${string}` ? any :
|
|
397
|
+
TConfig['endpoint'] extends `products/${ResourceId}` ? Products :
|
|
398
|
+
TConfig['endpoint'] extends `categories/${ResourceId}` ? Categories :
|
|
399
|
+
TConfig['endpoint'] extends `brands/${ResourceId}` ? Brands :
|
|
400
|
+
TConfig['endpoint'] extends `collections/${ResourceId}` ? Collections :
|
|
401
|
+
TConfig['endpoint'] extends `grids/${ResourceId}` ? Grids :
|
|
402
|
+
TConfig['endpoint'] extends `carts/${ResourceId}` ? Carts :
|
|
403
|
+
TConfig['endpoint'] extends `orders/${ResourceId}` ? Orders :
|
|
404
|
+
TConfig['endpoint'] extends `customers/${ResourceId}` ? Customers :
|
|
405
|
+
TConfig['endpoint'] extends `stores/${ResourceId}` ? Stores :
|
|
406
|
+
TConfig['endpoint'] extends 'stores/me' ? Stores :
|
|
407
|
+
TConfig['endpoint'] extends `applications/${ResourceId}` ? Applications :
|
|
408
|
+
TConfig['endpoint'] extends `authentications/${ResourceId}` ? Authentications :
|
|
409
|
+
TConfig['endpoint'] extends 'authentications/me' ? Authentications :
|
|
410
|
+
TConfig['endpoint'] extends ResourceOpQuery ? ResourceListResult<TConfig['endpoint'], ListFields> :
|
|
411
|
+
TConfig['endpoint'] extends SearchOpQuery ? SearchResult<TConfig['endpoint'], ListFields> :
|
|
412
|
+
TConfig['endpoint'] extends SearchHistoryOpQuery ? SearchHistoryResult :
|
|
413
|
+
TConfig['endpoint'] extends EventsEndpoint ? EventsResult<TConfig['endpoint']> :
|
|
414
|
+
any;
|
|
415
|
+
|
|
416
|
+
type DocSchema<Document extends any> =
|
|
417
|
+
Omit<Document, '_id' | 'store_id' | 'store_ids' | 'created_at' | 'updated_at'>;
|
|
418
|
+
type CustomerSet = DocSchema<Customers>;
|
|
419
|
+
type OrderSet = DocSchema<Orders>;
|
|
420
|
+
type CartSet = DocSchema<Carts>;
|
|
421
|
+
type ProductSet = DocSchema<Products>;
|
|
422
|
+
type CategorySet = DocSchema<Categories>;
|
|
423
|
+
type BrandSet = DocSchema<Brands>;
|
|
424
|
+
type CollectionSet = DocSchema<Collections>;
|
|
425
|
+
type GridSet = DocSchema<Grids>;
|
|
426
|
+
type StoreSet = DocSchema<Stores>;
|
|
427
|
+
type ApplicationSet = DocSchema<Applications>;
|
|
428
|
+
type AuthenticationSet = DocSchema<Authentications>;
|
|
429
|
+
|
|
430
|
+
type SetDocEndpoint<TResource extends Resource> = TResource | `${TResource}/${ResourceId}`;
|
|
431
|
+
|
|
432
|
+
type RequestBody<TConfig extends Config> =
|
|
433
|
+
TConfig['method'] extends undefined | 'get' | 'delete' ? undefined :
|
|
434
|
+
TConfig['method'] extends 'patch' ? any : // TODO: partial body
|
|
435
|
+
// method: 'post' | 'put'
|
|
436
|
+
TConfig['endpoint'] extends SetDocEndpoint<'products'> ? ProductSet :
|
|
437
|
+
TConfig['endpoint'] extends SetDocEndpoint<'categories'> ? CategorySet :
|
|
438
|
+
TConfig['endpoint'] extends SetDocEndpoint<'brands'> ? BrandSet :
|
|
439
|
+
TConfig['endpoint'] extends SetDocEndpoint<'collections'> ? CollectionSet :
|
|
440
|
+
TConfig['endpoint'] extends SetDocEndpoint<'grids'> ? GridSet :
|
|
441
|
+
TConfig['endpoint'] extends SetDocEndpoint<'carts'> ? CartSet :
|
|
442
|
+
TConfig['endpoint'] extends SetDocEndpoint<'orders'> ? OrderSet :
|
|
443
|
+
TConfig['endpoint'] extends SetDocEndpoint<'customers'> ? CustomerSet :
|
|
444
|
+
TConfig['endpoint'] extends SetDocEndpoint<'stores'> ? StoreSet :
|
|
445
|
+
TConfig['endpoint'] extends SetDocEndpoint<'applications'> ? ApplicationSet :
|
|
446
|
+
TConfig['endpoint'] extends SetDocEndpoint<'authentications'> ? AuthenticationSet :
|
|
447
|
+
any;
|
|
448
|
+
|
|
449
|
+
type ErrorBody = {
|
|
450
|
+
status: number,
|
|
451
|
+
error_code: number,
|
|
452
|
+
message: string,
|
|
453
|
+
user_message?: {
|
|
454
|
+
en_us: string,
|
|
455
|
+
pt_br: string,
|
|
456
|
+
},
|
|
457
|
+
more_info?: string,
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
export type {
|
|
461
|
+
Products,
|
|
462
|
+
Categories,
|
|
463
|
+
Brands,
|
|
464
|
+
Collections,
|
|
465
|
+
Grids,
|
|
466
|
+
Carts,
|
|
467
|
+
Orders,
|
|
468
|
+
Customers,
|
|
469
|
+
Stores,
|
|
470
|
+
Applications,
|
|
471
|
+
Authentications,
|
|
472
|
+
ProductSet,
|
|
473
|
+
CategorySet,
|
|
474
|
+
BrandSet,
|
|
475
|
+
CollectionSet,
|
|
476
|
+
GridSet,
|
|
477
|
+
CartSet,
|
|
478
|
+
OrderSet,
|
|
479
|
+
CustomerSet,
|
|
480
|
+
StoreSet,
|
|
481
|
+
ApplicationSet,
|
|
482
|
+
AuthenticationSet,
|
|
483
|
+
ProductsList,
|
|
484
|
+
CategoriesList,
|
|
485
|
+
BrandsList,
|
|
486
|
+
CollectionsList,
|
|
487
|
+
GridsList,
|
|
488
|
+
CartsList,
|
|
489
|
+
OrdersList,
|
|
490
|
+
CustomersList,
|
|
491
|
+
StoresList,
|
|
492
|
+
ApplicationsList,
|
|
493
|
+
AuthenticationsList,
|
|
494
|
+
Resource,
|
|
495
|
+
ResourceId,
|
|
496
|
+
ResourceAndId,
|
|
497
|
+
ResourceAndFind,
|
|
498
|
+
ResourceOpQuery,
|
|
499
|
+
Endpoint,
|
|
500
|
+
Method,
|
|
501
|
+
Config,
|
|
502
|
+
ResourceListResult,
|
|
503
|
+
SearchItem,
|
|
504
|
+
SearchResult,
|
|
505
|
+
EventsResult,
|
|
506
|
+
ResponseBody,
|
|
507
|
+
RequestBody,
|
|
508
|
+
ErrorBody,
|
|
509
|
+
};
|
package/types.ts
ADDED
package/dist/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
const env = (typeof window === 'object' && window)
|
|
3
|
-
|| (typeof process === 'object' && process && process.env)
|
|
4
|
-
|| {};
|
|
5
|
-
const baseUrl = env.API_BASE_URL || `https://ecomplus.io/v2/:${env.API_STORE_ID}/`;
|
|
6
|
-
const list = async (resource, options = {}) => {
|
|
7
|
-
const { params, headers } = options;
|
|
8
|
-
let url = `${baseUrl}${resource}`;
|
|
9
|
-
if (params) {
|
|
10
|
-
if (typeof params === 'string') {
|
|
11
|
-
url += `?${params}`;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
// https://github.com/microsoft/TypeScript/issues/32951
|
|
15
|
-
url += `?${new URLSearchParams(params)}`;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return fetch(url, { headers }).then((res) => res.json());
|
|
19
|
-
};
|
|
20
|
-
export default { list };
|
|
21
|
-
export { list };
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,OAAO,GAAG,GAAG,CAAC,YAAY,IAAI,2BAA2B,GAAG,CAAC,YAAY,GAAG,CAAC;AAEnF,MAAM,IAAI,GAAG,KAAK,EAAE,QAAgB,EAAE,UAGlC,EAAE,EAAE,EAAE;IACR,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACpC,IAAI,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,EAAE,CAAC;IAClC,IAAI,MAAM,EAAE;QACV,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,GAAG,IAAI,IAAI,MAAM,EAAE,CAAC;SACrB;aAAM;YACL,uDAAuD;YACvD,GAAG,IAAI,IAAI,IAAI,eAAe,CAAC,MAAgC,CAAC,EAAE,CAAC;SACpE;KACF;IACD,OAAO,KAAK,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC,CAAC;AAEF,eAAe,EAAE,IAAI,EAAE,CAAC;AAExB,OAAO,EAAE,IAAI,EAAE,CAAC"}
|
package/src/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
const env: { [key: string]: string } = (typeof window === 'object' && window)
|
|
3
|
-
|| (typeof process === 'object' && process && process.env)
|
|
4
|
-
|| {};
|
|
5
|
-
|
|
6
|
-
const baseUrl = env.API_BASE_URL || `https://ecomplus.io/v2/:${env.API_STORE_ID}/`;
|
|
7
|
-
|
|
8
|
-
const list = async (resource: string, options: {
|
|
9
|
-
params?: Record<string, string | number>,
|
|
10
|
-
headers?: Record<string, string>,
|
|
11
|
-
} = {}) => {
|
|
12
|
-
const { params, headers } = options;
|
|
13
|
-
let url = `${baseUrl}${resource}`;
|
|
14
|
-
if (params) {
|
|
15
|
-
if (typeof params === 'string') {
|
|
16
|
-
url += `?${params}`;
|
|
17
|
-
} else {
|
|
18
|
-
// https://github.com/microsoft/TypeScript/issues/32951
|
|
19
|
-
url += `?${new URLSearchParams(params as Record<string, string>)}`;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return fetch(url, { headers }).then((res) => res.json());
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default { list };
|
|
26
|
-
|
|
27
|
-
export { list };
|