@dataggo/node-akeneo-api 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +92 -0
  3. package/dist/cjs/endpoints/asset-family.d.ts +39 -0
  4. package/dist/cjs/endpoints/asset-family.js +41 -0
  5. package/dist/cjs/endpoints/attribute.d.ts +24 -0
  6. package/dist/cjs/endpoints/attribute.js +30 -0
  7. package/dist/cjs/endpoints/category.d.ts +21 -0
  8. package/dist/cjs/endpoints/category.js +39 -0
  9. package/dist/cjs/endpoints/family.d.ts +15 -0
  10. package/dist/cjs/endpoints/family.js +21 -0
  11. package/dist/cjs/endpoints/index.d.ts +7 -0
  12. package/dist/cjs/endpoints/index.js +29 -0
  13. package/dist/cjs/endpoints/product-model.d.ts +17 -0
  14. package/dist/cjs/endpoints/product-model.js +31 -0
  15. package/dist/cjs/endpoints/product.d.ts +21 -0
  16. package/dist/cjs/endpoints/product.js +33 -0
  17. package/dist/cjs/endpoints/raw.d.ts +11 -0
  18. package/dist/cjs/endpoints/raw.js +92 -0
  19. package/dist/cjs/endpoints/reference-entity.d.ts +15 -0
  20. package/dist/cjs/endpoints/reference-entity.js +21 -0
  21. package/dist/cjs/error-handler.d.ts +2 -0
  22. package/dist/cjs/error-handler.js +32 -0
  23. package/dist/cjs/http-client.d.ts +16 -0
  24. package/dist/cjs/http-client.js +87 -0
  25. package/dist/cjs/index.d.ts +349 -0
  26. package/dist/cjs/index.js +166 -0
  27. package/dist/cjs/package.json +3 -0
  28. package/dist/cjs/types.d.ts +243 -0
  29. package/dist/cjs/types.js +2 -0
  30. package/dist/mjs/endpoints/asset-family.d.ts +39 -0
  31. package/dist/mjs/endpoints/asset-family.js +31 -0
  32. package/dist/mjs/endpoints/attribute.d.ts +24 -0
  33. package/dist/mjs/endpoints/attribute.js +22 -0
  34. package/dist/mjs/endpoints/category.d.ts +21 -0
  35. package/dist/mjs/endpoints/category.js +18 -0
  36. package/dist/mjs/endpoints/family.d.ts +15 -0
  37. package/dist/mjs/endpoints/family.js +17 -0
  38. package/dist/mjs/endpoints/index.d.ts +7 -0
  39. package/dist/mjs/endpoints/index.js +7 -0
  40. package/dist/mjs/endpoints/product-model.d.ts +17 -0
  41. package/dist/mjs/endpoints/product-model.js +22 -0
  42. package/dist/mjs/endpoints/product.d.ts +21 -0
  43. package/dist/mjs/endpoints/product.js +24 -0
  44. package/dist/mjs/endpoints/raw.d.ts +11 -0
  45. package/dist/mjs/endpoints/raw.js +81 -0
  46. package/dist/mjs/endpoints/reference-entity.d.ts +15 -0
  47. package/dist/mjs/endpoints/reference-entity.js +13 -0
  48. package/dist/mjs/error-handler.d.ts +2 -0
  49. package/dist/mjs/error-handler.js +33 -0
  50. package/dist/mjs/http-client.d.ts +16 -0
  51. package/dist/mjs/http-client.js +86 -0
  52. package/dist/mjs/index.d.ts +349 -0
  53. package/dist/mjs/index.js +124 -0
  54. package/dist/mjs/package.json +3 -0
  55. package/dist/mjs/types.d.ts +243 -0
  56. package/dist/mjs/types.js +1 -0
  57. package/package.json +75 -0
@@ -0,0 +1,33 @@
1
+ import { path } from 'ramda';
2
+ const cleanHeaders = (headers) => headers && headers.Authorization
3
+ ? {
4
+ ...headers,
5
+ Authorization: `Bearer ${`...${headers.Authorization.substr(-5)}`}`,
6
+ }
7
+ : headers;
8
+ export default function errorHandler({ config, response }) {
9
+ const data = response?.data;
10
+ const errorData = {
11
+ status: response?.status,
12
+ statusText: response?.statusText,
13
+ message: data && 'message' in data ? data.message : '',
14
+ details: data && 'details' in data ? data.details : {},
15
+ request: config
16
+ ? {
17
+ url: config.url,
18
+ headers: cleanHeaders(config.headers),
19
+ method: config.method,
20
+ payloadData: config.data,
21
+ }
22
+ : {},
23
+ };
24
+ const error = new Error();
25
+ error.name = `${response?.status} ${response?.statusText}`;
26
+ try {
27
+ error.message = JSON.stringify(errorData, null, ' ');
28
+ }
29
+ catch {
30
+ error.message = path(['message'], errorData) || '';
31
+ }
32
+ throw error;
33
+ }
@@ -0,0 +1,16 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { AppParams, ClientParams } from './types';
3
+ /**
4
+ * Create pre-configured axios instance
5
+ * @private
6
+ * @param {ClientParams} options - Initialization parameters for the HTTP client
7
+ * @return {AxiosInstance} Initialized axios instance
8
+ */
9
+ export declare const createConnectionHttpClient: (options: ClientParams) => AxiosInstance;
10
+ /**
11
+ * Create pre-configured axios instance
12
+ * @private
13
+ * @param {ClientParams} options - Initialization parameters for the HTTP client
14
+ * @return {AxiosInstance} Initialized axios instance
15
+ */
16
+ export declare const createAppHttpClient: (options: AppParams) => AxiosInstance;
@@ -0,0 +1,86 @@
1
+ /* eslint-disable no-underscore-dangle */
2
+ import qs from 'qs';
3
+ import axios from 'axios';
4
+ const TOKEN_PATH = '/api/oauth/v1/token';
5
+ const defaultConfig = {
6
+ insecure: false,
7
+ retryOnError: true,
8
+ headers: {},
9
+ httpAgent: false,
10
+ httpsAgent: false,
11
+ timeout: 30000,
12
+ proxy: false,
13
+ basePath: '',
14
+ adapter: undefined,
15
+ maxContentLength: 1073741824,
16
+ paramsSerializer: qs.stringify,
17
+ };
18
+ /**
19
+ * Create pre-configured axios instance
20
+ * @private
21
+ * @param {ClientParams} options - Initialization parameters for the HTTP client
22
+ * @return {AxiosInstance} Initialized axios instance
23
+ */
24
+ export const createConnectionHttpClient = (options) => {
25
+ let accessToken = '';
26
+ const { url, clientId, secret, username, password } = options;
27
+ const baseURL = url.replace(/\/+$/, '');
28
+ const instance = axios.create({
29
+ ...defaultConfig,
30
+ ...(options.axiosOptions || {}),
31
+ baseURL,
32
+ });
33
+ const base64Encoded = Buffer.from(`${clientId}:${secret}`).toString('base64');
34
+ const refreshAccessToken = async () => {
35
+ const tokenResult = await axios.post(`${baseURL}${TOKEN_PATH}`, { grant_type: 'password', username, password }, {
36
+ headers: {
37
+ Authorization: `Basic ${base64Encoded}`,
38
+ },
39
+ });
40
+ accessToken = tokenResult.data.access_token;
41
+ return accessToken;
42
+ };
43
+ instance.interceptors.request.use(async (config) => ({
44
+ ...config,
45
+ headers: {
46
+ ...config.headers,
47
+ Authorization: `Bearer ${accessToken || (await refreshAccessToken())}`,
48
+ },
49
+ }));
50
+ instance.interceptors.response.use((response) => response, async (error) => {
51
+ const originalRequest = error.config;
52
+ if (error.response &&
53
+ (error.response.status === 403 || error.response.status === 401) &&
54
+ !originalRequest._retry) {
55
+ originalRequest._retry = true;
56
+ accessToken = '';
57
+ originalRequest.headers.Authorization = `Bearer ${await refreshAccessToken()}`;
58
+ return instance(originalRequest);
59
+ }
60
+ return Promise.reject(error);
61
+ });
62
+ return instance;
63
+ };
64
+ /**
65
+ * Create pre-configured axios instance
66
+ * @private
67
+ * @param {ClientParams} options - Initialization parameters for the HTTP client
68
+ * @return {AxiosInstance} Initialized axios instance
69
+ */
70
+ export const createAppHttpClient = (options) => {
71
+ const { url, accessToken } = options;
72
+ const baseURL = url.replace(/\/+$/, '');
73
+ const instance = axios.create({
74
+ ...defaultConfig,
75
+ ...(options.axiosOptions || {}),
76
+ baseURL,
77
+ });
78
+ instance.interceptors.request.use(async (config) => ({
79
+ ...config,
80
+ headers: {
81
+ ...config.headers,
82
+ Authorization: `Bearer ${accessToken}`,
83
+ },
84
+ }));
85
+ return instance;
86
+ };
@@ -0,0 +1,349 @@
1
+ /**
2
+ * Akeneo Management API SDK. Allows you to create instances of a client
3
+ * with access to the Akeneo API.
4
+ */
5
+ import { AxiosInstance } from 'axios';
6
+ import { AppParams, ClientParams } from './types';
7
+ /**
8
+ * Create a client instance
9
+ * @param params - Client initialization parameters
10
+ *
11
+ * ```javascript
12
+ * const client = akeneo({
13
+ * url: AKENEO_API_URL,
14
+ * username: AKENEO_USERNAME,
15
+ * password: AKENEO_PASSWORD,
16
+ * clientId: AKENEO_CLIENT_ID,
17
+ * secret: AKENEO_SECRET,
18
+ * });
19
+ * ```
20
+ */
21
+ export declare const createClient: (params: ClientParams) => {
22
+ raw: {
23
+ http: AxiosInstance;
24
+ };
25
+ category: {
26
+ getOne: (params: {
27
+ code: string;
28
+ query?: {
29
+ with_attribute_options?: boolean | undefined;
30
+ with_quality_scores?: boolean | undefined;
31
+ } | undefined;
32
+ }) => Promise<import("./types").Category<Record<string, any>>>;
33
+ get: (params: {
34
+ query?: import("./types").CategoryQueryParameters | undefined;
35
+ }) => Promise<import("./types").ListResponse<import("./types").Category<Record<string, any>>>>;
36
+ getAll: (params: {
37
+ query?: import("./types").CategoryQueryParameters | undefined;
38
+ }) => Promise<import("./types").ListResponse<import("./types").Category<Record<string, any>>>>;
39
+ };
40
+ productModel: {
41
+ getOne: (params: {
42
+ code: string;
43
+ }) => Promise<import("./types").ProductModel>;
44
+ get: (params: {
45
+ query?: import("./types").ProductModelQueryParameters | undefined;
46
+ }) => Promise<import("./types").ListResponse<import("./types").ProductModel>>;
47
+ getAll: (params: {
48
+ query?: import("./types").ProductModelQueryParameters | undefined;
49
+ }) => Promise<import("./types").ListResponse<import("./types").ProductModel>>;
50
+ };
51
+ product: {
52
+ getOne: (params: {
53
+ code: string;
54
+ query?: {
55
+ with_attribute_options?: boolean | undefined;
56
+ with_quality_scores?: boolean | undefined;
57
+ } | undefined;
58
+ }) => Promise<import("./types").Product>;
59
+ get: (params: {
60
+ query?: import("./types").ProductQueryParameters | undefined;
61
+ }) => Promise<import("./types").ListResponse<import("./types").Product>>;
62
+ getAll: (params: {
63
+ query?: import("./types").ProductQueryParameters | undefined;
64
+ }) => Promise<import("./types").ListResponse<import("./types").Product>>;
65
+ };
66
+ assetFamily: {
67
+ getOne: (params: {
68
+ code: string;
69
+ query?: {
70
+ with_attribute_options?: boolean | undefined;
71
+ with_quality_scores?: boolean | undefined;
72
+ } | undefined;
73
+ }) => Promise<import("./types").AssetFamily>;
74
+ get: (params: {
75
+ query?: import("./types").AssetFamilyQueryParameters | undefined;
76
+ }) => Promise<import("./types").ListResponse<import("./types").AssetFamily>>;
77
+ getAll: (params: {
78
+ query?: import("./types").AssetFamilyQueryParameters | undefined;
79
+ }) => Promise<import("./types").ListResponse<import("./types").AssetFamily>>;
80
+ getAssets: (params: {
81
+ assetFamilyCode: string;
82
+ query?: import("./types").AssetQueryParameters | undefined;
83
+ }) => Promise<import("./types").ListResponse<import("./types").Asset>>;
84
+ getAsset: (params: {
85
+ assetFamilyCode: string;
86
+ code: string;
87
+ }) => Promise<import("./types").Asset>;
88
+ getAssetsAll: (params: {
89
+ assetFamilyCode: string;
90
+ query?: import("./types").AssetQueryParameters | undefined;
91
+ }) => Promise<import("./types").ListResponse<import("./types").Asset>>;
92
+ };
93
+ assetMediaFile: {
94
+ /**
95
+ *
96
+ * @see https://api.akeneo.com/api-reference.html#get_asset_media_files__code
97
+ */
98
+ get: (code: string) => Promise<import("axios").AxiosResponse<any>>;
99
+ };
100
+ referenceEntitiesMediaFile: {
101
+ /**
102
+ * @see https://api.akeneo.com/api-reference.html#get_reference_entity_media_files__code
103
+ */
104
+ get: (code: string) => Promise<any>;
105
+ };
106
+ attribute: {
107
+ getOne: (params: {
108
+ code: string;
109
+ }) => Promise<import("./types").Attribute>;
110
+ get: (params: {
111
+ query?: import("./types").AttributeQueryParameters | undefined;
112
+ }) => Promise<import("./types").ListResponse<import("./types").Attribute>>;
113
+ getAll: (params: {
114
+ query?: import("./types").AttributeQueryParameters | undefined;
115
+ }) => Promise<import("./types").ListResponse<import("./types").Attribute>>;
116
+ getOptions: (params: {
117
+ attributeCode: string;
118
+ query?: import("./types").AttributeOptionQueryParameters | undefined;
119
+ }) => Promise<import("./types").ListResponse<import("./types").AttributeOption>>;
120
+ add: ({ code, attribute }: {
121
+ code: string;
122
+ attribute: any;
123
+ }) => Promise<import("axios").AxiosResponse<any>>;
124
+ addOption: ({ attributeCode, code, option, }: {
125
+ attributeCode: string;
126
+ code: string;
127
+ option: any;
128
+ }) => Promise<import("axios").AxiosResponse<any>>;
129
+ };
130
+ referenceEntity: {
131
+ get: (params: {
132
+ query?: import("./types").ReferenceEntityQueryParameters | undefined;
133
+ }) => Promise<import("./types").ListResponse<import("./types").Entity>>;
134
+ getRecords: (params: {
135
+ referenceEntityCode: string;
136
+ query?: import("./types").ReferenceEntityRecordQueryParameters | undefined;
137
+ }) => Promise<import("./types").ListResponse<import("./types").EntityRecord>>;
138
+ /**
139
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity__code_
140
+ */ add: ({ code, body }: {
141
+ code: string;
142
+ body: any;
143
+ }) => Promise<import("axios").AxiosResponse<any>>;
144
+ /**
145
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_attributes__code_
146
+ */
147
+ addAttribute: ({ referenceEntityCode, code, attribute, }: {
148
+ referenceEntityCode: string;
149
+ code: string;
150
+ attribute: any;
151
+ }) => Promise<void>;
152
+ /**
153
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_attributes__attribute_code__options__code_
154
+ */
155
+ addAttributeOption: ({ referenceEntityCode, attributeCode, code, option, }: {
156
+ referenceEntityCode: string;
157
+ attributeCode: string;
158
+ code: string;
159
+ option: any;
160
+ }) => Promise<import("axios").AxiosResponse<any>>;
161
+ /**
162
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_records
163
+ */
164
+ addRecords: ({ referenceEntityCode, records, }: {
165
+ referenceEntityCode: string;
166
+ records: any[];
167
+ }) => Promise<import("axios").AxiosResponse<any>>;
168
+ };
169
+ family: {
170
+ get: (params: {
171
+ query?: import("./types").FamilyQueryParameters | undefined;
172
+ }) => Promise<import("./types").ListResponse<import("./types").Family>>;
173
+ getVariants: (params: {
174
+ familyCode: string;
175
+ query?: import("./types").FamilyVariantQueryParameters | undefined;
176
+ }) => Promise<import("./types").ListResponse<import("./types").Variant>>;
177
+ };
178
+ };
179
+ /**
180
+ * Create a client instance
181
+ * @param params - Client initialization parameters
182
+ *
183
+ * ```javascript
184
+ * const client = akeneo({
185
+ * url: AKENEO_API_URL,
186
+ * accessToken: AKENEO_SECRET,
187
+ * });
188
+ * ```
189
+ */
190
+ export declare const createAppClient: (params: AppParams) => {
191
+ raw: {
192
+ http: AxiosInstance;
193
+ };
194
+ category: {
195
+ getOne: (params: {
196
+ code: string;
197
+ query?: {
198
+ with_attribute_options?: boolean | undefined;
199
+ with_quality_scores?: boolean | undefined;
200
+ } | undefined;
201
+ }) => Promise<import("./types").Category<Record<string, any>>>;
202
+ get: (params: {
203
+ query?: import("./types").CategoryQueryParameters | undefined;
204
+ }) => Promise<import("./types").ListResponse<import("./types").Category<Record<string, any>>>>;
205
+ getAll: (params: {
206
+ query?: import("./types").CategoryQueryParameters | undefined;
207
+ }) => Promise<import("./types").ListResponse<import("./types").Category<Record<string, any>>>>;
208
+ };
209
+ productModel: {
210
+ getOne: (params: {
211
+ code: string;
212
+ }) => Promise<import("./types").ProductModel>;
213
+ get: (params: {
214
+ query?: import("./types").ProductModelQueryParameters | undefined;
215
+ }) => Promise<import("./types").ListResponse<import("./types").ProductModel>>;
216
+ getAll: (params: {
217
+ query?: import("./types").ProductModelQueryParameters | undefined;
218
+ }) => Promise<import("./types").ListResponse<import("./types").ProductModel>>;
219
+ };
220
+ product: {
221
+ getOne: (params: {
222
+ code: string;
223
+ query?: {
224
+ with_attribute_options?: boolean | undefined;
225
+ with_quality_scores?: boolean | undefined;
226
+ } | undefined;
227
+ }) => Promise<import("./types").Product>;
228
+ get: (params: {
229
+ query?: import("./types").ProductQueryParameters | undefined;
230
+ }) => Promise<import("./types").ListResponse<import("./types").Product>>;
231
+ getAll: (params: {
232
+ query?: import("./types").ProductQueryParameters | undefined;
233
+ }) => Promise<import("./types").ListResponse<import("./types").Product>>;
234
+ };
235
+ assetFamily: {
236
+ getOne: (params: {
237
+ code: string;
238
+ query?: {
239
+ with_attribute_options?: boolean | undefined;
240
+ with_quality_scores?: boolean | undefined;
241
+ } | undefined;
242
+ }) => Promise<import("./types").AssetFamily>;
243
+ get: (params: {
244
+ query?: import("./types").AssetFamilyQueryParameters | undefined;
245
+ }) => Promise<import("./types").ListResponse<import("./types").AssetFamily>>;
246
+ getAll: (params: {
247
+ query?: import("./types").AssetFamilyQueryParameters | undefined;
248
+ }) => Promise<import("./types").ListResponse<import("./types").AssetFamily>>;
249
+ getAssets: (params: {
250
+ assetFamilyCode: string;
251
+ query?: import("./types").AssetQueryParameters | undefined;
252
+ }) => Promise<import("./types").ListResponse<import("./types").Asset>>;
253
+ getAsset: (params: {
254
+ assetFamilyCode: string;
255
+ code: string;
256
+ }) => Promise<import("./types").Asset>;
257
+ getAssetsAll: (params: {
258
+ assetFamilyCode: string;
259
+ query?: import("./types").AssetQueryParameters | undefined;
260
+ }) => Promise<import("./types").ListResponse<import("./types").Asset>>;
261
+ };
262
+ assetMediaFile: {
263
+ /**
264
+ *
265
+ * @see https://api.akeneo.com/api-reference.html#get_asset_media_files__code
266
+ */
267
+ get: (code: string) => Promise<import("axios").AxiosResponse<any>>;
268
+ };
269
+ referenceEntitiesMediaFile: {
270
+ /**
271
+ * @see https://api.akeneo.com/api-reference.html#get_reference_entity_media_files__code
272
+ */
273
+ get: (code: string) => Promise<any>;
274
+ };
275
+ attribute: {
276
+ getOne: (params: {
277
+ code: string;
278
+ }) => Promise<import("./types").Attribute>;
279
+ get: (params: {
280
+ query?: import("./types").AttributeQueryParameters | undefined;
281
+ }) => Promise<import("./types").ListResponse<import("./types").Attribute>>;
282
+ getAll: (params: {
283
+ query?: import("./types").AttributeQueryParameters | undefined;
284
+ }) => Promise<import("./types").ListResponse<import("./types").Attribute>>;
285
+ getOptions: (params: {
286
+ attributeCode: string;
287
+ query?: import("./types").AttributeOptionQueryParameters | undefined;
288
+ }) => Promise<import("./types").ListResponse<import("./types").AttributeOption>>;
289
+ add: ({ code, attribute }: {
290
+ code: string;
291
+ attribute: any;
292
+ }) => Promise<import("axios").AxiosResponse<any>>;
293
+ addOption: ({ attributeCode, code, option, }: {
294
+ attributeCode: string;
295
+ code: string;
296
+ option: any;
297
+ }) => Promise<import("axios").AxiosResponse<any>>;
298
+ };
299
+ referenceEntity: {
300
+ get: (params: {
301
+ query?: import("./types").ReferenceEntityQueryParameters | undefined;
302
+ }) => Promise<import("./types").ListResponse<import("./types").Entity>>;
303
+ getRecords: (params: {
304
+ referenceEntityCode: string;
305
+ query?: import("./types").ReferenceEntityRecordQueryParameters | undefined;
306
+ }) => Promise<import("./types").ListResponse<import("./types").EntityRecord>>;
307
+ /**
308
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity__code_
309
+ */ add: ({ code, body }: {
310
+ code: string;
311
+ body: any;
312
+ }) => Promise<import("axios").AxiosResponse<any>>;
313
+ /**
314
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_attributes__code_
315
+ */
316
+ addAttribute: ({ referenceEntityCode, code, attribute, }: {
317
+ referenceEntityCode: string;
318
+ code: string;
319
+ attribute: any;
320
+ }) => Promise<void>;
321
+ /**
322
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_attributes__attribute_code__options__code_
323
+ */
324
+ addAttributeOption: ({ referenceEntityCode, attributeCode, code, option, }: {
325
+ referenceEntityCode: string;
326
+ attributeCode: string;
327
+ code: string;
328
+ option: any;
329
+ }) => Promise<import("axios").AxiosResponse<any>>;
330
+ /**
331
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_records
332
+ */
333
+ addRecords: ({ referenceEntityCode, records, }: {
334
+ referenceEntityCode: string;
335
+ records: any[];
336
+ }) => Promise<import("axios").AxiosResponse<any>>;
337
+ };
338
+ family: {
339
+ get: (params: {
340
+ query?: import("./types").FamilyQueryParameters | undefined;
341
+ }) => Promise<import("./types").ListResponse<import("./types").Family>>;
342
+ getVariants: (params: {
343
+ familyCode: string;
344
+ query?: import("./types").FamilyVariantQueryParameters | undefined;
345
+ }) => Promise<import("./types").ListResponse<import("./types").Variant>>;
346
+ };
347
+ };
348
+ export declare type AkeneoClientAPI = ReturnType<typeof createClient>;
349
+ export * from './types';
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Akeneo Management API SDK. Allows you to create instances of a client
3
+ * with access to the Akeneo API.
4
+ */
5
+ import { createConnectionHttpClient, createAppHttpClient } from './http-client';
6
+ import * as endpoints from './endpoints';
7
+ const ATTRIBUTES_PATH = '/api/rest/v1/attributes';
8
+ const ASSET_MEDIA_FILES = '/api/rest/v1/asset-media-files';
9
+ const REFERENCE_ENTITIES_MEDIA_FILES = '/api/rest/v1/reference-entities-media-files';
10
+ const wrap = (http, fn) => (params) => fn(http, params);
11
+ const getHttpClientWithEndpoint = (http) => ({
12
+ raw: {
13
+ http,
14
+ },
15
+ category: {
16
+ getOne: wrap(http, endpoints.category.getOne),
17
+ get: wrap(http, endpoints.category.get),
18
+ getAll: wrap(http, endpoints.category.getAll),
19
+ },
20
+ productModel: {
21
+ getOne: wrap(http, endpoints.productModel.getOne),
22
+ get: wrap(http, endpoints.productModel.get),
23
+ getAll: wrap(http, endpoints.productModel.getAll),
24
+ },
25
+ product: {
26
+ getOne: wrap(http, endpoints.product.getOne),
27
+ get: wrap(http, endpoints.product.get),
28
+ getAll: wrap(http, endpoints.product.getAll),
29
+ },
30
+ assetFamily: {
31
+ getOne: wrap(http, endpoints.assetFamily.getOne),
32
+ get: wrap(http, endpoints.assetFamily.get),
33
+ getAll: wrap(http, endpoints.assetFamily.getAll),
34
+ getAssets: wrap(http, endpoints.assetFamily.getAssets),
35
+ getAsset: wrap(http, endpoints.assetFamily.getAsset),
36
+ getAssetsAll: wrap(http, endpoints.assetFamily.getAssetsAll),
37
+ },
38
+ assetMediaFile: {
39
+ /**
40
+ *
41
+ * @see https://api.akeneo.com/api-reference.html#get_asset_media_files__code
42
+ */
43
+ get: async (code) => http.get(`${ASSET_MEDIA_FILES}/${code}`, {
44
+ responseType: 'arraybuffer',
45
+ params: {},
46
+ }),
47
+ },
48
+ referenceEntitiesMediaFile: {
49
+ /**
50
+ * @see https://api.akeneo.com/api-reference.html#get_reference_entity_media_files__code
51
+ */
52
+ get: async (code) => http.get(`${REFERENCE_ENTITIES_MEDIA_FILES}/${code}`, {
53
+ responseType: 'arraybuffer',
54
+ params: {},
55
+ }),
56
+ },
57
+ attribute: {
58
+ getOne: wrap(http, endpoints.attribute.getOne),
59
+ get: wrap(http, endpoints.attribute.get),
60
+ getAll: wrap(http, endpoints.attribute.getAll),
61
+ getOptions: wrap(http, endpoints.attribute.getOptions),
62
+ add: async ({ code, attribute }) => http.patch(`${ATTRIBUTES_PATH}/${code}`, attribute),
63
+ addOption: async ({ attributeCode, code, option, }) => http.patch(`${ATTRIBUTES_PATH}/${attributeCode}/options/${code}`, option),
64
+ },
65
+ referenceEntity: {
66
+ get: wrap(http, endpoints.referenceEntity.get),
67
+ getRecords: wrap(http, endpoints.referenceEntity.getRecords),
68
+ /**
69
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity__code_
70
+ */ add: async ({ code, body }) => http.patch(`/api/rest/v1/reference-entities/${code}`, body),
71
+ /**
72
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_attributes__code_
73
+ */
74
+ addAttribute: async ({ referenceEntityCode, code, attribute, }) => {
75
+ await http.patch(`/api/rest/v1/reference-entities/${referenceEntityCode}/attributes/${code}`, attribute);
76
+ },
77
+ /**
78
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_attributes__attribute_code__options__code_
79
+ */
80
+ addAttributeOption: ({ referenceEntityCode, attributeCode, code, option, }) => http.patch(`/api/rest/v1/reference-entities/${referenceEntityCode}/attributes/${attributeCode}/options/${code}`, option),
81
+ /**
82
+ * @see https://api.akeneo.com/api-reference.html#patch_reference_entity_records
83
+ */
84
+ addRecords: ({ referenceEntityCode, records, }) => http.patch(`/api/rest/v1/reference-entities/${referenceEntityCode}/records`, records),
85
+ },
86
+ family: {
87
+ get: wrap(http, endpoints.family.get),
88
+ getVariants: wrap(http, endpoints.family.getVariants),
89
+ },
90
+ });
91
+ /**
92
+ * Create a client instance
93
+ * @param params - Client initialization parameters
94
+ *
95
+ * ```javascript
96
+ * const client = akeneo({
97
+ * url: AKENEO_API_URL,
98
+ * username: AKENEO_USERNAME,
99
+ * password: AKENEO_PASSWORD,
100
+ * clientId: AKENEO_CLIENT_ID,
101
+ * secret: AKENEO_SECRET,
102
+ * });
103
+ * ```
104
+ */
105
+ export const createClient = (params) => {
106
+ const http = createConnectionHttpClient(params);
107
+ return getHttpClientWithEndpoint(http);
108
+ };
109
+ /**
110
+ * Create a client instance
111
+ * @param params - Client initialization parameters
112
+ *
113
+ * ```javascript
114
+ * const client = akeneo({
115
+ * url: AKENEO_API_URL,
116
+ * accessToken: AKENEO_SECRET,
117
+ * });
118
+ * ```
119
+ */
120
+ export const createAppClient = (params) => {
121
+ const http = createAppHttpClient(params);
122
+ return getHttpClientWithEndpoint(http);
123
+ };
124
+ export * from './types';
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }