oneentry 1.0.176 → 1.0.178
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/README.md +12 -5
- package/changelog.md +116 -0
- package/dist/admins/adminsApi.js +2 -9
- package/dist/admins/adminsInterfaces.d.ts +5 -5
- package/dist/admins/adminsSchemas.d.ts +4 -4
- package/dist/admins/adminsSchemas.js +2 -2
- package/dist/attribute-sets/attributeSetsApi.d.ts +1 -1
- package/dist/attribute-sets/attributeSetsApi.js +4 -4
- package/dist/attribute-sets/attributeSetsInterfaces.d.ts +65 -14
- package/dist/attribute-sets/attributeSetsSchemas.d.ts +8 -6
- package/dist/attribute-sets/attributeSetsSchemas.js +6 -9
- package/dist/auth-provider/authProviderApi.d.ts +4 -4
- package/dist/auth-provider/authProviderApi.js +90 -23
- package/dist/auth-provider/authProviderSchemas.d.ts +1 -0
- package/dist/auth-provider/authProviderSchemas.js +1 -0
- package/dist/auth-provider/authProvidersInterfaces.d.ts +8 -6
- package/dist/base/asyncModules.d.ts +62 -1
- package/dist/base/asyncModules.js +219 -37
- package/dist/base/stateModule.d.ts +2 -0
- package/dist/base/stateModule.js +22 -12
- package/dist/base/syncModules.d.ts +18 -10
- package/dist/base/syncModules.js +100 -29
- package/dist/base/utils.d.ts +26 -21
- package/dist/base/validation.d.ts +3 -3
- package/dist/base/validation.js +6 -7
- package/dist/blocks/blocksApi.d.ts +20 -17
- package/dist/blocks/blocksApi.js +82 -64
- package/dist/blocks/blocksInterfaces.d.ts +8 -8
- package/dist/discounts/discountsApi.d.ts +9 -7
- package/dist/discounts/discountsApi.js +16 -13
- package/dist/discounts/discountsInterfaces.d.ts +14 -10
- package/dist/events/eventsApi.d.ts +3 -3
- package/dist/events/eventsApi.js +3 -3
- package/dist/events/eventsInterfaces.d.ts +10 -14
- package/dist/file-uploading/fileUploadingApi.d.ts +4 -4
- package/dist/file-uploading/fileUploadingApi.js +13 -5
- package/dist/file-uploading/fileUploadingInterfaces.d.ts +5 -6
- package/dist/filters/filtersApi.js +2 -2
- package/dist/forms/formsApi.js +2 -2
- package/dist/forms/formsInterfaces.d.ts +1 -3
- package/dist/forms/formsSchemas.d.ts +3 -6
- package/dist/forms/formsSchemas.js +2 -4
- package/dist/forms-data/formsDataApi.d.ts +27 -1
- package/dist/forms-data/formsDataApi.js +119 -68
- package/dist/forms-data/formsDataInterfaces.d.ts +17 -13
- package/dist/general-types/generalTypesInterfaces.d.ts +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +50 -7
- package/dist/integration-collections/integrationCollectionsApi.d.ts +15 -4
- package/dist/integration-collections/integrationCollectionsApi.js +41 -14
- package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +8 -9
- package/dist/integration-collections/integrationCollectionsSchemas.d.ts +0 -2
- package/dist/integration-collections/integrationCollectionsSchemas.js +0 -1
- package/dist/menus/menusApi.js +1 -1
- package/dist/orders/ordersApi.d.ts +1 -13
- package/dist/orders/ordersApi.js +21 -42
- package/dist/orders/ordersInterfaces.d.ts +21 -14
- package/dist/pages/pagesApi.d.ts +8 -6
- package/dist/pages/pagesApi.js +48 -33
- package/dist/pages/pagesInterfaces.d.ts +20 -16
- package/dist/pages/pagesSchemas.d.ts +0 -3
- package/dist/pages/pagesSchemas.js +0 -1
- package/dist/payments/paymentsApi.d.ts +10 -11
- package/dist/payments/paymentsApi.js +22 -18
- package/dist/payments/paymentsInterfaces.d.ts +12 -14
- package/dist/payments/paymentsSchemas.d.ts +21 -20
- package/dist/payments/paymentsSchemas.js +5 -8
- package/dist/product-statuses/productStatusesApi.d.ts +1 -1
- package/dist/product-statuses/productStatusesApi.js +3 -3
- package/dist/product-statuses/productStatusesInterfaces.d.ts +1 -4
- package/dist/products/productsApi.d.ts +50 -64
- package/dist/products/productsApi.js +79 -80
- package/dist/products/productsInterfaces.d.ts +59 -90
- package/dist/search/searchApi.d.ts +3 -2
- package/dist/search/searchApi.js +7 -4
- package/dist/search/searchInterfaces.d.ts +2 -1
- package/dist/sitemap/sitemapInterfaces.d.ts +10 -6
- package/dist/subscriptions/subscriptionsApi.d.ts +1 -1
- package/dist/subscriptions/subscriptionsApi.js +1 -1
- package/dist/subscriptions/subscriptionsInterfaces.d.ts +1 -1
- package/dist/system/systemApi.d.ts +2 -0
- package/dist/system/systemApi.js +2 -0
- package/dist/system/systemInterfaces.d.ts +2 -0
- package/dist/templates/templatesApi.d.ts +2 -2
- package/dist/templates/templatesApi.js +12 -11
- package/dist/templates/templatesInterfaces.d.ts +2 -2
- package/dist/templates-preview/templatesPreviewApi.js +2 -2
- package/dist/templates-preview/templatesPreviewInterfaces.d.ts +23 -13
- package/dist/templates-preview/templatesPreviewSchemas.d.ts +7 -0
- package/dist/templates-preview/templatesPreviewSchemas.js +2 -0
- package/dist/user-groups/userGroupsApi.js +5 -5
- package/dist/user-groups/userGroupsSchemas.d.ts +4 -4
- package/dist/users/usersApi.d.ts +1 -1
- package/dist/users/usersApi.js +28 -15
- package/dist/users/usersInterfaces.d.ts +2 -9
- package/dist/web-socket/lazySocket.d.ts +6 -5
- package/dist/web-socket/lazySocket.js +212 -15
- package/dist/web-socket/wsApi.d.ts +7 -4
- package/dist/web-socket/wsApi.js +49 -12
- package/dist/web-socket/wsInterfaces.d.ts +41 -4
- package/esm/admins/adminsApi.js +2 -9
- package/esm/admins/adminsInterfaces.d.ts +5 -5
- package/esm/admins/adminsSchemas.d.ts +4 -4
- package/esm/admins/adminsSchemas.js +2 -2
- package/esm/attribute-sets/attributeSetsApi.d.ts +1 -1
- package/esm/attribute-sets/attributeSetsApi.js +4 -4
- package/esm/attribute-sets/attributeSetsInterfaces.d.ts +65 -14
- package/esm/attribute-sets/attributeSetsSchemas.d.ts +8 -6
- package/esm/attribute-sets/attributeSetsSchemas.js +6 -9
- package/esm/auth-provider/authProviderApi.d.ts +4 -4
- package/esm/auth-provider/authProviderApi.js +90 -23
- package/esm/auth-provider/authProviderSchemas.d.ts +1 -0
- package/esm/auth-provider/authProviderSchemas.js +1 -0
- package/esm/auth-provider/authProvidersInterfaces.d.ts +8 -6
- package/esm/base/asyncModules.d.ts +62 -1
- package/esm/base/asyncModules.js +219 -37
- package/esm/base/stateModule.d.ts +2 -0
- package/esm/base/stateModule.js +22 -12
- package/esm/base/syncModules.d.ts +18 -10
- package/esm/base/syncModules.js +99 -29
- package/esm/base/utils.d.ts +26 -21
- package/esm/base/validation.d.ts +3 -3
- package/esm/base/validation.js +6 -7
- package/esm/blocks/blocksApi.d.ts +20 -17
- package/esm/blocks/blocksApi.js +82 -64
- package/esm/blocks/blocksInterfaces.d.ts +8 -8
- package/esm/discounts/discountsApi.d.ts +9 -7
- package/esm/discounts/discountsApi.js +16 -13
- package/esm/discounts/discountsInterfaces.d.ts +14 -10
- package/esm/events/eventsApi.d.ts +3 -3
- package/esm/events/eventsApi.js +3 -3
- package/esm/events/eventsInterfaces.d.ts +10 -14
- package/esm/file-uploading/fileUploadingApi.d.ts +4 -4
- package/esm/file-uploading/fileUploadingApi.js +13 -5
- package/esm/file-uploading/fileUploadingInterfaces.d.ts +5 -6
- package/esm/filters/filtersApi.js +2 -2
- package/esm/forms/formsApi.js +2 -2
- package/esm/forms/formsInterfaces.d.ts +1 -3
- package/esm/forms/formsSchemas.d.ts +3 -6
- package/esm/forms/formsSchemas.js +2 -4
- package/esm/forms-data/formsDataApi.d.ts +27 -1
- package/esm/forms-data/formsDataApi.js +119 -68
- package/esm/forms-data/formsDataInterfaces.d.ts +17 -13
- package/esm/general-types/generalTypesInterfaces.d.ts +1 -1
- package/esm/index.d.ts +7 -6
- package/esm/index.js +50 -7
- package/esm/integration-collections/integrationCollectionsApi.d.ts +15 -4
- package/esm/integration-collections/integrationCollectionsApi.js +41 -14
- package/esm/integration-collections/integrationCollectionsInterfaces.d.ts +8 -9
- package/esm/integration-collections/integrationCollectionsSchemas.d.ts +0 -2
- package/esm/integration-collections/integrationCollectionsSchemas.js +0 -1
- package/esm/menus/menusApi.js +1 -1
- package/esm/orders/ordersApi.d.ts +1 -13
- package/esm/orders/ordersApi.js +21 -42
- package/esm/orders/ordersInterfaces.d.ts +21 -14
- package/esm/pages/pagesApi.d.ts +8 -6
- package/esm/pages/pagesApi.js +48 -33
- package/esm/pages/pagesInterfaces.d.ts +20 -16
- package/esm/pages/pagesSchemas.d.ts +0 -3
- package/esm/pages/pagesSchemas.js +0 -1
- package/esm/payments/paymentsApi.d.ts +10 -11
- package/esm/payments/paymentsApi.js +22 -18
- package/esm/payments/paymentsInterfaces.d.ts +12 -14
- package/esm/payments/paymentsSchemas.d.ts +21 -20
- package/esm/payments/paymentsSchemas.js +5 -8
- package/esm/product-statuses/productStatusesApi.d.ts +1 -1
- package/esm/product-statuses/productStatusesApi.js +3 -3
- package/esm/product-statuses/productStatusesInterfaces.d.ts +1 -4
- package/esm/products/productsApi.d.ts +50 -64
- package/esm/products/productsApi.js +79 -80
- package/esm/products/productsInterfaces.d.ts +59 -90
- package/esm/search/searchApi.d.ts +3 -2
- package/esm/search/searchApi.js +7 -4
- package/esm/search/searchInterfaces.d.ts +2 -1
- package/esm/sitemap/sitemapInterfaces.d.ts +10 -6
- package/esm/subscriptions/subscriptionsApi.d.ts +1 -1
- package/esm/subscriptions/subscriptionsApi.js +1 -1
- package/esm/subscriptions/subscriptionsInterfaces.d.ts +1 -1
- package/esm/system/systemApi.d.ts +2 -0
- package/esm/system/systemApi.js +2 -0
- package/esm/system/systemInterfaces.d.ts +2 -0
- package/esm/templates/templatesApi.d.ts +2 -2
- package/esm/templates/templatesApi.js +11 -10
- package/esm/templates/templatesInterfaces.d.ts +2 -2
- package/esm/templates-preview/templatesPreviewApi.js +2 -2
- package/esm/templates-preview/templatesPreviewInterfaces.d.ts +23 -13
- package/esm/templates-preview/templatesPreviewSchemas.d.ts +7 -0
- package/esm/templates-preview/templatesPreviewSchemas.js +2 -0
- package/esm/user-groups/userGroupsApi.js +5 -5
- package/esm/user-groups/userGroupsSchemas.d.ts +4 -4
- package/esm/users/usersApi.d.ts +1 -1
- package/esm/users/usersApi.js +28 -15
- package/esm/users/usersInterfaces.d.ts +2 -9
- package/esm/web-socket/lazySocket.d.ts +6 -5
- package/esm/web-socket/lazySocket.js +212 -15
- package/esm/web-socket/wsApi.d.ts +7 -4
- package/esm/web-socket/wsApi.js +49 -12
- package/esm/web-socket/wsInterfaces.d.ts +41 -4
- package/package.json +2 -2
package/esm/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ import WsApi from './web-socket/wsApi.js';
|
|
|
34
34
|
export { getAdditionalFields, getAttributeFile, getAttributeFiles, isFileAttribute, isListAttribute, isNumberAttribute, isStringAttribute, } from './base/attributes.js';
|
|
35
35
|
export { expandAttributeTimeIntervals, expandTimeIntervals, isTimeIntervalAttribute, } from './base/timeIntervals.js';
|
|
36
36
|
export type * from './types.js';
|
|
37
|
+
export type { IDefineApi };
|
|
37
38
|
/**
|
|
38
39
|
* IDefineApi interface
|
|
39
40
|
* @interface IDefineApi
|
|
@@ -132,17 +133,17 @@ interface IDefineApi {
|
|
|
132
133
|
* @function defineOneEntry
|
|
133
134
|
* @param {string} url - URl of your project.
|
|
134
135
|
* @param {IConfig} config - Custom configuration settings
|
|
135
|
-
* @param {string}
|
|
136
|
+
* @param {string} config.token - App token of the project. Required: `defineOneEntry` throws without it.
|
|
136
137
|
* @param {string} [config.guestId] - Optional guest identifier sent as the `x-guest-id` header for guest cart/wishlist/activity flows (only while unauthenticated). In the browser, if omitted, a stable per-device id is generated and persisted in localStorage. On the server you MUST pass a per-visitor `guestId` (or call `setGuestId`): the SDK never auto-generates a server id, to avoid sharing one guest across visitors.
|
|
137
138
|
* @param {string} [config.deviceMetadata] - Optional device-metadata string sent as the `x-device-metadata` header instead of the environment-derived fingerprint. Refresh tokens are bound to this header, so a server issuing tokens for a browser (OAuth code exchange) must pass the browser's string (from `getDeviceMetadata()`), or the token will not be refreshable from that browser.
|
|
138
|
-
* @param {string} [config.langCode] - Optional
|
|
139
|
+
* @param {string} [config.langCode] - Optional default language. Default: 'en_US'.
|
|
139
140
|
* @param {boolean} [config.traficLimit] - Some methods use multiple queries to make it easier to work with the API. Set it to `true` to save traffic and decide for yourself what data you need: the SDK then skips its follow-up requests, and some results change shape (e.g. `searchPage` returns short `{ id, title }` cards). Default: false.
|
|
140
|
-
* @param {
|
|
141
|
+
* @param {object} [config.auth] - An object with authorization settings.
|
|
141
142
|
* @param {boolean} [config.auth.customAuth] - Set this flag to true if you want to configure the authorization process yourself. Set the flag to false, or do not pass it at all to have automatic authorization and token renewal.
|
|
142
|
-
* @param {string} [config.auth.refreshToken] - Transfer the refresh token here, for example from the local storage, to resume the user's session. Otherwise, the user will need to log in every time a new session is created.
|
|
143
|
+
* @param {string} [config.auth.refreshToken] - Transfer the refresh token here, for example from the local storage, to resume the user's session. Otherwise, the user will need to log in every time a new session is created. On the server, also pass the `deviceMetadata` saved with the token: the API binds refresh tokens to it.
|
|
143
144
|
* @param {string} [config.auth.providerMarker] - The marker of the authorization provider.
|
|
144
|
-
* @param {string} [config.auth.saveFunction] - If you want to store the token between sessions, for example in local storage, create a custom function that takes refreshToken as a parameter and executes the necessary instructions. This function will be called every time the tokens are updated.
|
|
145
|
+
* @param {function(string): void} [config.auth.saveFunction] - If you want to store the token between sessions, for example in local storage, create a custom function that takes refreshToken as a parameter and executes the necessary instructions. This function will be called every time the tokens are updated.
|
|
145
146
|
* @returns {IDefineApi} List of methods set.
|
|
146
|
-
* @description Define API.
|
|
147
|
+
* @description Define API. The returned client holds one session (tokens, guest id) shared by all its modules: on a server, create a client per request for user calls — a client shared between requests serves the signed-in user's data to every visitor. `logout` does not change the guest id.
|
|
147
148
|
*/
|
|
148
149
|
export declare function defineOneEntry(url: string, config: IConfig): IDefineApi;
|
package/esm/index.js
CHANGED
|
@@ -33,23 +33,55 @@ import UsersApi from './users/usersApi.js';
|
|
|
33
33
|
import WsApi from './web-socket/wsApi.js';
|
|
34
34
|
export { getAdditionalFields, getAttributeFile, getAttributeFiles, isFileAttribute, isListAttribute, isNumberAttribute, isStringAttribute, } from './base/attributes.js';
|
|
35
35
|
export { expandAttributeTimeIntervals, expandTimeIntervals, isTimeIntervalAttribute, } from './base/timeIntervals.js';
|
|
36
|
+
/**
|
|
37
|
+
* Checks the project URL every request path is appended to.
|
|
38
|
+
* @param {string} raw - The URL as passed, trimmed.
|
|
39
|
+
* @param {string} base - The URL with trailing `/` and `/api/content` removed.
|
|
40
|
+
* @returns {boolean} True for an http(s) origin (optionally with a path) or a same-origin proxy path.
|
|
41
|
+
* @description A backslash is read as `/` by browsers: `/\\evil.example` was a "path" that sent
|
|
42
|
+
* every request — and the app token — to another host. A query or fragment swallowed every
|
|
43
|
+
* path appended to it, and credentials in the URL make `fetch` throw on each call.
|
|
44
|
+
*/
|
|
45
|
+
function _isProjectUrl(raw, base) {
|
|
46
|
+
if (/[\\?#\s]/.test(base)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (raw.startsWith('/')) {
|
|
50
|
+
// `/` and `/api/content` leave an empty base: the site's own origin
|
|
51
|
+
return !raw.startsWith('//') && (base === '' || base.startsWith('/'));
|
|
52
|
+
}
|
|
53
|
+
// `https:evil.example` parses with that host, but a browser resolves it as a path
|
|
54
|
+
if (!/^https?:\/\//i.test(base)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const parsed = new URL(base);
|
|
59
|
+
return ((parsed.protocol === 'http:' || parsed.protocol === 'https:') &&
|
|
60
|
+
!!parsed.hostname &&
|
|
61
|
+
!parsed.username &&
|
|
62
|
+
!parsed.password);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
36
68
|
/**
|
|
37
69
|
* Define API.
|
|
38
70
|
* @function defineOneEntry
|
|
39
71
|
* @param {string} url - URl of your project.
|
|
40
72
|
* @param {IConfig} config - Custom configuration settings
|
|
41
|
-
* @param {string}
|
|
73
|
+
* @param {string} config.token - App token of the project. Required: `defineOneEntry` throws without it.
|
|
42
74
|
* @param {string} [config.guestId] - Optional guest identifier sent as the `x-guest-id` header for guest cart/wishlist/activity flows (only while unauthenticated). In the browser, if omitted, a stable per-device id is generated and persisted in localStorage. On the server you MUST pass a per-visitor `guestId` (or call `setGuestId`): the SDK never auto-generates a server id, to avoid sharing one guest across visitors.
|
|
43
75
|
* @param {string} [config.deviceMetadata] - Optional device-metadata string sent as the `x-device-metadata` header instead of the environment-derived fingerprint. Refresh tokens are bound to this header, so a server issuing tokens for a browser (OAuth code exchange) must pass the browser's string (from `getDeviceMetadata()`), or the token will not be refreshable from that browser.
|
|
44
|
-
* @param {string} [config.langCode] - Optional
|
|
76
|
+
* @param {string} [config.langCode] - Optional default language. Default: 'en_US'.
|
|
45
77
|
* @param {boolean} [config.traficLimit] - Some methods use multiple queries to make it easier to work with the API. Set it to `true` to save traffic and decide for yourself what data you need: the SDK then skips its follow-up requests, and some results change shape (e.g. `searchPage` returns short `{ id, title }` cards). Default: false.
|
|
46
|
-
* @param {
|
|
78
|
+
* @param {object} [config.auth] - An object with authorization settings.
|
|
47
79
|
* @param {boolean} [config.auth.customAuth] - Set this flag to true if you want to configure the authorization process yourself. Set the flag to false, or do not pass it at all to have automatic authorization and token renewal.
|
|
48
|
-
* @param {string} [config.auth.refreshToken] - Transfer the refresh token here, for example from the local storage, to resume the user's session. Otherwise, the user will need to log in every time a new session is created.
|
|
80
|
+
* @param {string} [config.auth.refreshToken] - Transfer the refresh token here, for example from the local storage, to resume the user's session. Otherwise, the user will need to log in every time a new session is created. On the server, also pass the `deviceMetadata` saved with the token: the API binds refresh tokens to it.
|
|
49
81
|
* @param {string} [config.auth.providerMarker] - The marker of the authorization provider.
|
|
50
|
-
* @param {string} [config.auth.saveFunction] - If you want to store the token between sessions, for example in local storage, create a custom function that takes refreshToken as a parameter and executes the necessary instructions. This function will be called every time the tokens are updated.
|
|
82
|
+
* @param {function(string): void} [config.auth.saveFunction] - If you want to store the token between sessions, for example in local storage, create a custom function that takes refreshToken as a parameter and executes the necessary instructions. This function will be called every time the tokens are updated.
|
|
51
83
|
* @returns {IDefineApi} List of methods set.
|
|
52
|
-
* @description Define API.
|
|
84
|
+
* @description Define API. The returned client holds one session (tokens, guest id) shared by all its modules: on a server, create a client per request for user calls — a client shared between requests serves the signed-in user's data to every visitor. `logout` does not change the guest id.
|
|
53
85
|
*/
|
|
54
86
|
export function defineOneEntry(url, config) {
|
|
55
87
|
if (typeof url !== 'string' || url.trim() === '') {
|
|
@@ -64,7 +96,18 @@ export function defineOneEntry(url, config) {
|
|
|
64
96
|
'Pass it via config, e.g. ' +
|
|
65
97
|
'defineOneEntry("https://your-project.oneentry.cloud", { token: "your-app-token" }).');
|
|
66
98
|
}
|
|
67
|
-
|
|
99
|
+
// Trailing slashes and a copied `/api/content` suffix used to double up in every path
|
|
100
|
+
// (`//api/content/…`, `/api/content/api/content/…`) and fail each call with a 404
|
|
101
|
+
const baseUrl = url
|
|
102
|
+
.trim()
|
|
103
|
+
.replace(/\/+$/, '')
|
|
104
|
+
.replace(/\/api\/content$/i, '');
|
|
105
|
+
if (!_isProjectUrl(url.trim(), baseUrl)) {
|
|
106
|
+
throw new Error('OneEntry SDK: project URL must be an http(s) URL without credentials, query or fragment, ' +
|
|
107
|
+
'or a same-origin proxy path starting with "/", e.g. ' +
|
|
108
|
+
'defineOneEntry("https://your-project.oneentry.cloud", { token: "your-app-token" }).');
|
|
109
|
+
}
|
|
110
|
+
const stateModule = new StateModule(baseUrl, config);
|
|
68
111
|
const Admins = new AdminsApi(stateModule);
|
|
69
112
|
const AttributesSets = new AttributesSetsApi(stateModule);
|
|
70
113
|
const AuthProvider = new AuthProviderApi(stateModule);
|
|
@@ -86,11 +86,13 @@ export default class IntegrationCollectionsApi extends AsyncModules implements I
|
|
|
86
86
|
* @handleName getICollectionRowsByMarker
|
|
87
87
|
* @param {string} marker - Marker of the collection. Example: "collection1".
|
|
88
88
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
89
|
+
* @param {ICollectionQuery} [userQuery] - Pagination and entity filter, as in `getICollectionRowsById`. Without it the API returns the first 30 records only. Example: `{ limit: 100, offset: 0 }`.
|
|
89
90
|
* @returns {Promise<ICollectionRowsResponce | IError>} Returns CollectionRowEntity object.
|
|
90
91
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
92
|
+
* @description Records of the collection, one page at a time: `limit` defaults to 30 and `total` holds the full count.
|
|
91
93
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/getICollectionRowsByMarker getICollectionRowsByMarker} documentation.
|
|
92
94
|
*/
|
|
93
|
-
getICollectionRowsByMarker(marker: string, langCode?: string): Promise<ICollectionRowsResponce | IError>;
|
|
95
|
+
getICollectionRowsByMarker(marker: string, langCode?: string, userQuery?: ICollectionQuery): Promise<ICollectionRowsResponce | IError>;
|
|
94
96
|
/**
|
|
95
97
|
* Getting one record from the collection.
|
|
96
98
|
* @handleName getICollectionRowByMarkerAndId
|
|
@@ -121,7 +123,7 @@ export default class IntegrationCollectionsApi extends AsyncModules implements I
|
|
|
121
123
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
122
124
|
* @returns {Promise<ICollectionRow | IError>} Returns object of type ICollectionRow.
|
|
123
125
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
124
|
-
* @description Create a record in the collection.
|
|
126
|
+
* @description Create a record in the collection. The row is stored under the language key of `formData` when it is wrapped (`{ "en_US": [...] }`), not under `langCode` of the call; the returned `formData` is an array either way.
|
|
125
127
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/createICollectionRow createICollectionRow} documentation.
|
|
126
128
|
*/
|
|
127
129
|
createICollectionRow(marker: string, body: ICollectionFormObject, langCode?: string): Promise<ICollectionRow | IError>;
|
|
@@ -147,7 +149,7 @@ export default class IntegrationCollectionsApi extends AsyncModules implements I
|
|
|
147
149
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
148
150
|
* @returns {Promise<ICollectionRow | IError>} Returns object of type ICollectionRow.
|
|
149
151
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
150
|
-
* @description Edit a record in the collection.
|
|
152
|
+
* @description Edit a record in the collection. `formData` **replaces** every field of the row: fields left out of the body are removed, not kept.
|
|
151
153
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/updateICollectionRow updateICollectionRow} documentation.
|
|
152
154
|
*/
|
|
153
155
|
updateICollectionRow(marker: string, id: number, body: {
|
|
@@ -159,10 +161,19 @@ export default class IntegrationCollectionsApi extends AsyncModules implements I
|
|
|
159
161
|
* @handleName deleteICollectionRowByMarkerAndId
|
|
160
162
|
* @param {string} marker - Marker of the collection. Example: "collection1".
|
|
161
163
|
* @param {number} id - ID of the collection row. Example: 12.
|
|
162
|
-
* @returns {Promise<boolean | IError>} Returns true
|
|
164
|
+
* @returns {Promise<boolean | IError>} Returns `true` once the row is deleted; a row that is not there (or already deleted) answers IError `404 Row not found`, not `false`. Permission "collections.row.delete" is required.
|
|
163
165
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
164
166
|
* @description Deletion of collection record object
|
|
165
167
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/deleteICollectionRowByMarkerAndId deleteICollectionRowByMarkerAndId} documentation.
|
|
166
168
|
*/
|
|
167
169
|
deleteICollectionRowByMarkerAndId(marker: string, id: number): Promise<boolean | IError>;
|
|
170
|
+
/**
|
|
171
|
+
* Unwraps `formData` of a created or updated row that is still keyed by a language.
|
|
172
|
+
* @param {any} row - The normalized row.
|
|
173
|
+
* @returns {any} The row with `formData` as an array.
|
|
174
|
+
* @description The row is stored under the language key of the body, and the answer
|
|
175
|
+
* keeps that key: `createICollectionRow(…, 'ru_RU')` with `{ en_US: [...] }` returned
|
|
176
|
+
* `formData` as an object, while `ICollectionRow.formData` is an array.
|
|
177
|
+
*/
|
|
178
|
+
private _rowFormDataAsArray;
|
|
168
179
|
}
|
|
@@ -56,7 +56,8 @@ export default class IntegrationCollectionsApi extends AsyncModules {
|
|
|
56
56
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/getICollectionById getICollectionById} documentation.
|
|
57
57
|
*/
|
|
58
58
|
async getICollectionById(id, langCode = this.state.lang) {
|
|
59
|
-
const result = await this._fetchGet(`/${id}?` +
|
|
59
|
+
const result = await this._fetchGet(`/${this._pathSegment(String(id))}?` +
|
|
60
|
+
this._queryParamsToString({ langCode }));
|
|
60
61
|
// Validate response if validation is enabled
|
|
61
62
|
const validated = await this._validateResponse(result, schema('CollectionEntitySchema'));
|
|
62
63
|
return this._normalizeData(validated, langCode);
|
|
@@ -84,7 +85,7 @@ export default class IntegrationCollectionsApi extends AsyncModules {
|
|
|
84
85
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/getICollectionRowsById getICollectionRowsById} documentation.
|
|
85
86
|
*/
|
|
86
87
|
async getICollectionRowsById(id, langCode = this.state.lang, userQuery) {
|
|
87
|
-
const result = await this._fetchGet(`/${id}/rows?` +
|
|
88
|
+
const result = await this._fetchGet(`/${this._pathSegment(String(id))}/rows?` +
|
|
88
89
|
this._queryParamsToString({
|
|
89
90
|
...this._defaultQuery,
|
|
90
91
|
...userQuery,
|
|
@@ -118,12 +119,19 @@ export default class IntegrationCollectionsApi extends AsyncModules {
|
|
|
118
119
|
* @handleName getICollectionRowsByMarker
|
|
119
120
|
* @param {string} marker - Marker of the collection. Example: "collection1".
|
|
120
121
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
122
|
+
* @param {ICollectionQuery} [userQuery] - Pagination and entity filter, as in `getICollectionRowsById`. Without it the API returns the first 30 records only. Example: `{ limit: 100, offset: 0 }`.
|
|
121
123
|
* @returns {Promise<ICollectionRowsResponce | IError>} Returns CollectionRowEntity object.
|
|
122
124
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
125
|
+
* @description Records of the collection, one page at a time: `limit` defaults to 30 and `total` holds the full count.
|
|
123
126
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/getICollectionRowsByMarker getICollectionRowsByMarker} documentation.
|
|
124
127
|
*/
|
|
125
|
-
async getICollectionRowsByMarker(marker, langCode = this.state.lang) {
|
|
126
|
-
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/rows
|
|
128
|
+
async getICollectionRowsByMarker(marker, langCode = this.state.lang, userQuery) {
|
|
129
|
+
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/rows?` +
|
|
130
|
+
this._queryParamsToString({
|
|
131
|
+
...this._defaultQuery,
|
|
132
|
+
...userQuery,
|
|
133
|
+
langCode,
|
|
134
|
+
}));
|
|
127
135
|
// Validate response if validation is enabled
|
|
128
136
|
const validated = await this._validateResponse(result, schema('CollectionRowsResponseSchema'));
|
|
129
137
|
return this._normalizeData(validated, langCode);
|
|
@@ -139,7 +147,7 @@ export default class IntegrationCollectionsApi extends AsyncModules {
|
|
|
139
147
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/getICollectionRowByMarkerAndId getICollectionRowByMarkerAndId} documentation.
|
|
140
148
|
*/
|
|
141
149
|
async getICollectionRowByMarkerAndId(marker, id, langCode = this.state.lang) {
|
|
142
|
-
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/rows/${id}?langCode=${langCode}`);
|
|
150
|
+
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/rows/${this._pathSegment(String(id))}?langCode=${encodeURIComponent(langCode)}`);
|
|
143
151
|
// Validate response if validation is enabled
|
|
144
152
|
const validated = await this._validateResponse(result, schema('CollectionRowSchema'));
|
|
145
153
|
return this._normalizeData(validated, langCode);
|
|
@@ -163,14 +171,14 @@ export default class IntegrationCollectionsApi extends AsyncModules {
|
|
|
163
171
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
164
172
|
* @returns {Promise<ICollectionRow | IError>} Returns object of type ICollectionRow.
|
|
165
173
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
166
|
-
* @description Create a record in the collection.
|
|
174
|
+
* @description Create a record in the collection. The row is stored under the language key of `formData` when it is wrapped (`{ "en_US": [...] }`), not under `langCode` of the call; the returned `formData` is an array either way.
|
|
167
175
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/createICollectionRow createICollectionRow} documentation.
|
|
168
176
|
*/
|
|
169
177
|
async createICollectionRow(marker, body, langCode = this.state.lang) {
|
|
170
|
-
const response = await this._fetchPost(`/marker/${this._pathSegment(marker)}/rows?langCode=${langCode}`, body);
|
|
178
|
+
const response = await this._fetchPost(`/marker/${this._pathSegment(marker)}/rows?langCode=${encodeURIComponent(langCode)}`, body);
|
|
171
179
|
// Validate response if validation is enabled
|
|
172
180
|
const validated = await this._validateResponse(response, schema('CollectionRowSchema'));
|
|
173
|
-
return this._normalizeData(validated, langCode);
|
|
181
|
+
return this._rowFormDataAsArray(this._normalizeData(validated, langCode));
|
|
174
182
|
}
|
|
175
183
|
/**
|
|
176
184
|
* Edit a record in the collection.
|
|
@@ -194,28 +202,47 @@ export default class IntegrationCollectionsApi extends AsyncModules {
|
|
|
194
202
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
195
203
|
* @returns {Promise<ICollectionRow | IError>} Returns object of type ICollectionRow.
|
|
196
204
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
197
|
-
* @description Edit a record in the collection.
|
|
205
|
+
* @description Edit a record in the collection. `formData` **replaces** every field of the row: fields left out of the body are removed, not kept.
|
|
198
206
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/updateICollectionRow updateICollectionRow} documentation.
|
|
199
207
|
*/
|
|
200
208
|
async updateICollectionRow(marker, id, body, langCode = this.state.lang) {
|
|
201
|
-
const response = await this._fetchPut(`/marker/${this._pathSegment(marker)}/rows/${id}?` +
|
|
202
|
-
`langCode=${langCode}`, body);
|
|
209
|
+
const response = await this._fetchPut(`/marker/${this._pathSegment(marker)}/rows/${this._pathSegment(String(id))}?` +
|
|
210
|
+
`langCode=${encodeURIComponent(langCode)}`, body);
|
|
203
211
|
// Validate response if validation is enabled
|
|
204
212
|
const validated = await this._validateResponse(response, schema('CollectionRowSchema'));
|
|
205
|
-
return this._normalizeData(validated, langCode);
|
|
213
|
+
return this._rowFormDataAsArray(this._normalizeData(validated, langCode));
|
|
206
214
|
}
|
|
207
215
|
/**
|
|
208
216
|
* Deletion of collection record object
|
|
209
217
|
* @handleName deleteICollectionRowByMarkerAndId
|
|
210
218
|
* @param {string} marker - Marker of the collection. Example: "collection1".
|
|
211
219
|
* @param {number} id - ID of the collection row. Example: 12.
|
|
212
|
-
* @returns {Promise<boolean | IError>} Returns true
|
|
220
|
+
* @returns {Promise<boolean | IError>} Returns `true` once the row is deleted; a row that is not there (or already deleted) answers IError `404 Row not found`, not `false`. Permission "collections.row.delete" is required.
|
|
213
221
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
214
222
|
* @description Deletion of collection record object
|
|
215
223
|
* @see {@link https://js-sdk.oneentry.cloud/docs/integration-collections/deleteICollectionRowByMarkerAndId deleteICollectionRowByMarkerAndId} documentation.
|
|
216
224
|
*/
|
|
217
225
|
async deleteICollectionRowByMarkerAndId(marker, id) {
|
|
218
|
-
const result = await this._fetchDelete(`/marker/${this._pathSegment(marker)}/rows/${id}`);
|
|
226
|
+
const result = await this._fetchDelete(`/marker/${this._pathSegment(marker)}/rows/${this._pathSegment(String(id))}`);
|
|
219
227
|
return result;
|
|
220
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Unwraps `formData` of a created or updated row that is still keyed by a language.
|
|
231
|
+
* @param {any} row - The normalized row.
|
|
232
|
+
* @returns {any} The row with `formData` as an array.
|
|
233
|
+
* @description The row is stored under the language key of the body, and the answer
|
|
234
|
+
* keeps that key: `createICollectionRow(…, 'ru_RU')` with `{ en_US: [...] }` returned
|
|
235
|
+
* `formData` as an object, while `ICollectionRow.formData` is an array.
|
|
236
|
+
*/
|
|
237
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
238
|
+
_rowFormDataAsArray(row) {
|
|
239
|
+
const formData = row === null || row === void 0 ? void 0 : row.formData;
|
|
240
|
+
if (formData && typeof formData === 'object' && !Array.isArray(formData)) {
|
|
241
|
+
const keys = Object.keys(formData);
|
|
242
|
+
if (keys.length === 1 && Array.isArray(formData[keys[0]])) {
|
|
243
|
+
return { ...row, formData: formData[keys[0]] };
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return row;
|
|
247
|
+
}
|
|
221
248
|
}
|
|
@@ -71,11 +71,12 @@ interface ICollectionsApi {
|
|
|
71
71
|
* @handleName getICollectionRowsByMarker
|
|
72
72
|
* @param {string} marker - Marker of the collection. Example: "collection1".
|
|
73
73
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
74
|
+
* @param {ICollectionQuery} [userQuery] - Pagination and entity filter. Without it the API returns the first 30 records only.
|
|
74
75
|
* @returns {ICollectionRowsResponce} Returns collection row entity object.
|
|
75
76
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
76
|
-
* @description
|
|
77
|
+
* @description Records of the collection, one page at a time: `limit` defaults to 30 and `total` holds the full count.
|
|
77
78
|
*/
|
|
78
|
-
getICollectionRowsByMarker(marker: string, langCode?: string): Promise<ICollectionRowsResponce | IError>;
|
|
79
|
+
getICollectionRowsByMarker(marker: string, langCode?: string, userQuery?: ICollectionQuery): Promise<ICollectionRowsResponce | IError>;
|
|
79
80
|
/**
|
|
80
81
|
* Getting one record from the collection.
|
|
81
82
|
* @handleName getICollectionRowByMarkerAndId
|
|
@@ -189,13 +190,13 @@ interface ICollectionResponce {
|
|
|
189
190
|
* @interface ICollectionFormData
|
|
190
191
|
* @property {string} marker - Text identifier (marker) of the form field. Example: "collection_marker".
|
|
191
192
|
* @property {string} type - Type of the form field, for example `"text"`, `"number"` or `"date"`. Example: "number".
|
|
192
|
-
* @property {string} value - Value of the form field. Example: "Collection marker".
|
|
193
|
+
* @property {string | number | null} value - Value of the form field. Send a string; on reading, `integer`/`float`/`real` fields come back as a `number` — and as `null` when the stored value is not a number (the API stores `"abc"` in a `float` field as is, the SDK does not pass it on). Example: "Collection marker".
|
|
193
194
|
* @description Represents a form data object within a collection, containing a marker, type, and value.
|
|
194
195
|
*/
|
|
195
196
|
interface ICollectionFormData {
|
|
196
197
|
marker: string;
|
|
197
198
|
type: string;
|
|
198
|
-
value: string;
|
|
199
|
+
value: string | number | null;
|
|
199
200
|
}
|
|
200
201
|
/**
|
|
201
202
|
* Collection form object
|
|
@@ -225,7 +226,7 @@ interface ICollectionFormObject {
|
|
|
225
226
|
* @property {number} id - Object ID. Example: 1.
|
|
226
227
|
* @property {string} createdDate - Creation date of the record. Example: "2023-01-01T00:00:00Z".
|
|
227
228
|
* @property {string} updatedDate - Date the record was last updated. Example: "2023-01-02T00:00:00Z".
|
|
228
|
-
* @property {number | null} [collectionId] - ID of the collection the row belongs to.
|
|
229
|
+
* @property {number | null} [collectionId] - ID of the collection the row belongs to. The row list and row-by-id endpoints do not return it. Example: 1.
|
|
229
230
|
* @property {ICollectionFormData[]} formData - Form fields of the collection row.
|
|
230
231
|
* @example
|
|
231
232
|
[
|
|
@@ -240,8 +241,7 @@ interface ICollectionFormObject {
|
|
|
240
241
|
* @property {string | null} [attributeSetIdentifier] - Marker of the attribute set used by the form attached to the collection row, or `null` if there is none. Example: "attributeSet1" or null.
|
|
241
242
|
* @property {string | null} [langCode] - Language code the row was stored under. Example: "en_US".
|
|
242
243
|
* @property {string | null} [formIdentifier] - Marker of the form the row was created from; returned by the create and update row endpoints. Example: "collection_form".
|
|
243
|
-
* @
|
|
244
|
-
* @description Represents a row in a collection, containing various properties such as identifiers, dates, form data, and an optional total value.
|
|
244
|
+
* @description Represents a row in a collection, containing various properties such as identifiers, dates and form data.
|
|
245
245
|
*/
|
|
246
246
|
interface ICollectionRow {
|
|
247
247
|
id: number;
|
|
@@ -254,7 +254,6 @@ interface ICollectionRow {
|
|
|
254
254
|
attributeSetIdentifier?: string | null;
|
|
255
255
|
langCode?: string | null;
|
|
256
256
|
formIdentifier?: string | null;
|
|
257
|
-
total?: string;
|
|
258
257
|
}
|
|
259
258
|
/**
|
|
260
259
|
* Collection rows response object
|
|
@@ -315,4 +314,4 @@ interface ICollectionQuery {
|
|
|
315
314
|
* @property {number} [offset] - Number of records to skip. Default: 0.
|
|
316
315
|
*/
|
|
317
316
|
type ICollectionsListQuery = Pick<ICollectionQuery, 'limit' | 'offset'>;
|
|
318
|
-
export type { ICollectionEntity, ICollectionFormObject, ICollectionIsValid, ICollectionQuery, ICollectionResponce, ICollectionRow, ICollectionRowsResponce, ICollectionsApi, ICollectionsListQuery, };
|
|
317
|
+
export type { ICollectionEntity, ICollectionFormData, ICollectionFormObject, ICollectionIsValid, ICollectionQuery, ICollectionResponce, ICollectionRow, ICollectionRowsResponce, ICollectionsApi, ICollectionsListQuery, };
|
|
@@ -51,7 +51,6 @@ export declare const CollectionRowSchema: z.ZodObject<{
|
|
|
51
51
|
attributeSetIdentifier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
52
52
|
langCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
53
53
|
formIdentifier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
|
-
total: z.ZodOptional<z.ZodString>;
|
|
55
54
|
}, z.core.$strip>;
|
|
56
55
|
/**
|
|
57
56
|
* Collection rows response schema
|
|
@@ -72,7 +71,6 @@ export declare const CollectionRowsResponseSchema: z.ZodObject<{
|
|
|
72
71
|
attributeSetIdentifier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
73
72
|
langCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
74
73
|
formIdentifier: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
75
|
-
total: z.ZodOptional<z.ZodString>;
|
|
76
74
|
}, z.core.$strip>>;
|
|
77
75
|
total: z.ZodNumber;
|
|
78
76
|
}, z.core.$strip>;
|
|
@@ -43,7 +43,6 @@ export const CollectionRowSchema = z.object({
|
|
|
43
43
|
attributeSetIdentifier: z.string().nullable().optional(),
|
|
44
44
|
langCode: z.string().nullable().optional(),
|
|
45
45
|
formIdentifier: z.string().nullable().optional(),
|
|
46
|
-
total: z.string().optional(),
|
|
47
46
|
});
|
|
48
47
|
/**
|
|
49
48
|
* Collection rows response schema
|
package/esm/menus/menusApi.js
CHANGED
|
@@ -27,7 +27,7 @@ export default class MenusApi extends AsyncModules {
|
|
|
27
27
|
* @see {@link https://js-sdk.oneentry.cloud/docs/menus/getMenusByMarker getMenusByMarker} documentation.
|
|
28
28
|
*/
|
|
29
29
|
async getMenusByMarker(marker, langCode = this.state.lang) {
|
|
30
|
-
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${langCode}`);
|
|
30
|
+
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${encodeURIComponent(langCode)}`);
|
|
31
31
|
// Validate response if validation is enabled
|
|
32
32
|
const validated = await this._validateResponse(result, schema('MenuEntitySchema'));
|
|
33
33
|
return this._normalizeData(validated, langCode);
|
|
@@ -165,6 +165,7 @@ export default class OrdersApi extends AsyncModules implements IOrdersApi {
|
|
|
165
165
|
* @param {number} [limit] - Maximum number of records to return. Default: 30.
|
|
166
166
|
* @returns {Promise<IOrderStatus[] | IError>} Returns an object with the orders statuses.
|
|
167
167
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
168
|
+
* @description Get all order statuses of the storage. This method requires user authorization: a guest gets `401 Unauthorized`.
|
|
168
169
|
* @see For more information about configuring the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider authorization module}, see the documentation in the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider configuration settings section of the SDK}.
|
|
169
170
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getAllStatusesByStorageMarker getAllStatusesByStorageMarker} documentation.
|
|
170
171
|
*/
|
|
@@ -211,19 +212,6 @@ export default class OrdersApi extends AsyncModules implements IOrdersApi {
|
|
|
211
212
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getOrdersByVectorSearch getOrdersByVectorSearch} documentation.
|
|
212
213
|
*/
|
|
213
214
|
getOrdersByVectorSearch(body: IOrdersVectorSearch, langCode?: string, offset?: number, limit?: number): Promise<IVectorSearchResponse<IOrdersByMarkerEntity> | IError>;
|
|
214
|
-
/**
|
|
215
|
-
* Runs a fetch against the `/orders` base URL instead of the default
|
|
216
|
-
* `/orders-storage`, then restores the original URL.
|
|
217
|
-
*
|
|
218
|
-
* Refund endpoints live under `/api/content/orders`, while this class is based
|
|
219
|
-
* on `/api/content/orders-storage`. The helper swaps `_url` for the duration of
|
|
220
|
-
* the call and restores it in `finally`, so the base URL is restored even if
|
|
221
|
-
* the request throws.
|
|
222
|
-
* @param {() => Promise<T>} fetcher - Thunk performing the fetch call.
|
|
223
|
-
* @returns {Promise<T>} The fetcher result.
|
|
224
|
-
* @template T
|
|
225
|
-
*/
|
|
226
|
-
private _withOrdersUrl;
|
|
227
215
|
/**
|
|
228
216
|
* Builds the order body the API expects: `formData` wrapped in a map keyed by locale.
|
|
229
217
|
*
|
package/esm/orders/ordersApi.js
CHANGED
|
@@ -31,8 +31,8 @@ export default class OrdersApi extends AsyncModules {
|
|
|
31
31
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getAllOrdersStorage getAllOrdersStorage} documentation.
|
|
32
32
|
*/
|
|
33
33
|
async getAllOrdersStorage(langCode = this.state.lang, offset = 0, limit = 30) {
|
|
34
|
-
const result = await this._fetchGet(`?langCode=${langCode}&limit=${limit}&offset=${offset}`);
|
|
35
|
-
return this._normalizeData(result);
|
|
34
|
+
const result = await this._fetchGet(`?langCode=${encodeURIComponent(langCode)}&limit=${encodeURIComponent(String(limit))}&offset=${encodeURIComponent(String(offset))}`);
|
|
35
|
+
return this._normalizeData(result, langCode);
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Getting all orders from the orders storage object created by the user.
|
|
@@ -48,10 +48,10 @@ export default class OrdersApi extends AsyncModules {
|
|
|
48
48
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getAllOrdersByMarker getAllOrdersByMarker} documentation.
|
|
49
49
|
*/
|
|
50
50
|
async getAllOrdersByMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
51
|
-
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/orders?langCode=${langCode}&limit=${limit}&offset=${offset}`);
|
|
51
|
+
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/orders?langCode=${encodeURIComponent(langCode)}&limit=${encodeURIComponent(String(limit))}&offset=${encodeURIComponent(String(offset))}`);
|
|
52
52
|
// Validate response if validation is enabled
|
|
53
53
|
const validated = await this._validateResponse(result, schema('OrdersResponseSchema'));
|
|
54
|
-
return this._normalizeData(validated);
|
|
54
|
+
return this._normalizeData(validated, langCode);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Retrieve one order storage object by marker.
|
|
@@ -65,8 +65,8 @@ export default class OrdersApi extends AsyncModules {
|
|
|
65
65
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getOrdersStorageByMarker getOrdersStorageByMarker} documentation.
|
|
66
66
|
*/
|
|
67
67
|
async getOrdersStorageByMarker(marker, langCode = this.state.lang) {
|
|
68
|
-
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${langCode}`);
|
|
69
|
-
return this._normalizeData(result);
|
|
68
|
+
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${encodeURIComponent(langCode)}`);
|
|
69
|
+
return this._normalizeData(result, langCode);
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Getting a single order from the order storage object created by the user.
|
|
@@ -81,10 +81,10 @@ export default class OrdersApi extends AsyncModules {
|
|
|
81
81
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getOrderByMarkerAndId getOrderByMarkerAndId} documentation.
|
|
82
82
|
*/
|
|
83
83
|
async getOrderByMarkerAndId(marker, id, langCode = this.state.lang) {
|
|
84
|
-
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/orders/${id}?langCode=${langCode}`);
|
|
84
|
+
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}/orders/${this._pathSegment(String(id))}?langCode=${encodeURIComponent(langCode)}`);
|
|
85
85
|
// Validate response if validation is enabled
|
|
86
86
|
const validated = await this._validateResponse(result, schema('OrderEntitySchema'));
|
|
87
|
-
return this._normalizeData(validated);
|
|
87
|
+
return this._normalizeData(validated, langCode);
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* Getting a single order created by the user, by its own id.
|
|
@@ -100,10 +100,10 @@ export default class OrdersApi extends AsyncModules {
|
|
|
100
100
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getOrderById getOrderById} documentation.
|
|
101
101
|
*/
|
|
102
102
|
async getOrderById(id, langCode = this.state.lang) {
|
|
103
|
-
const result = await this.
|
|
103
|
+
const result = await this._withBaseUrl(this._ordersUrl)._fetchGet(`/${this._pathSegment(String(id))}?langCode=${encodeURIComponent(langCode)}`);
|
|
104
104
|
// Validate response if validation is enabled
|
|
105
105
|
const validated = await this._validateResponse(result, schema('OrderEntitySchema'));
|
|
106
|
-
return this._normalizeData(validated);
|
|
106
|
+
return this._normalizeData(validated, langCode);
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Preview order calculation with discounts and coupons (without saving).
|
|
@@ -117,8 +117,8 @@ export default class OrdersApi extends AsyncModules {
|
|
|
117
117
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/previewOrder previewOrder} documentation.
|
|
118
118
|
*/
|
|
119
119
|
async previewOrder(body, langCode = this.state.lang) {
|
|
120
|
-
const result = await this._fetchPost(`/orders/preview?langCode=${langCode}`, body);
|
|
121
|
-
return this._normalizeData(result);
|
|
120
|
+
const result = await this._fetchPost(`/orders/preview?langCode=${encodeURIComponent(langCode)}`, body);
|
|
121
|
+
return this._normalizeData(result, langCode);
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
124
124
|
* Creation of an order in the order storage.
|
|
@@ -152,7 +152,7 @@ export default class OrdersApi extends AsyncModules {
|
|
|
152
152
|
const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}/orders`, this._wrapOrderFormData(body, langCode));
|
|
153
153
|
// Validate response if validation is enabled
|
|
154
154
|
const validated = await this._validateResponse(result, schema('CreateOrderResponseSchema'));
|
|
155
|
-
return this._normalizeData(validated);
|
|
155
|
+
return this._normalizeData(validated, langCode);
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Changing an order in the orders storage
|
|
@@ -185,10 +185,10 @@ export default class OrdersApi extends AsyncModules {
|
|
|
185
185
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/updateOrderByMarkerAndId updateOrderByMarkerAndId} documentation.
|
|
186
186
|
*/
|
|
187
187
|
async updateOrderByMarkerAndId(marker, id, body, langCode = this.state.lang) {
|
|
188
|
-
const result = await this._fetchPut(`/marker/${this._pathSegment(marker)}/orders/${id}?langCode=${langCode}`, this._wrapOrderFormData(body, langCode));
|
|
188
|
+
const result = await this._fetchPut(`/marker/${this._pathSegment(marker)}/orders/${this._pathSegment(String(id))}?langCode=${encodeURIComponent(langCode)}`, this._wrapOrderFormData(body, langCode));
|
|
189
189
|
// Validate response if validation is enabled
|
|
190
190
|
const validated = await this._validateResponse(result, schema('UpdateOrderResponseSchema'));
|
|
191
|
-
return this._normalizeData(validated);
|
|
191
|
+
return this._normalizeData(validated, langCode);
|
|
192
192
|
}
|
|
193
193
|
/**
|
|
194
194
|
* Get all orders statuses by Storage marker
|
|
@@ -199,6 +199,7 @@ export default class OrdersApi extends AsyncModules {
|
|
|
199
199
|
* @param {number} [limit] - Maximum number of records to return. Default: 30.
|
|
200
200
|
* @returns {Promise<IOrderStatus[] | IError>} Returns an object with the orders statuses.
|
|
201
201
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
202
|
+
* @description Get all order statuses of the storage. This method requires user authorization: a guest gets `401 Unauthorized`.
|
|
202
203
|
* @see For more information about configuring the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider authorization module}, see the documentation in the {@link https://js-sdk.oneentry.cloud/docs/category/authprovider configuration settings section of the SDK}.
|
|
203
204
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getAllStatusesByStorageMarker getAllStatusesByStorageMarker} documentation.
|
|
204
205
|
*/
|
|
@@ -210,7 +211,7 @@ export default class OrdersApi extends AsyncModules {
|
|
|
210
211
|
};
|
|
211
212
|
const data = await this._fetchGet(`/marker/${this._pathSegment(marker)}/order-statuses?` +
|
|
212
213
|
this._queryParamsToString(query));
|
|
213
|
-
return this._normalizeData(data);
|
|
214
|
+
return this._normalizeData(data, langCode);
|
|
214
215
|
}
|
|
215
216
|
/**
|
|
216
217
|
* Get all refund requests for an order.
|
|
@@ -221,7 +222,7 @@ export default class OrdersApi extends AsyncModules {
|
|
|
221
222
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/getRefunds getRefunds} documentation.
|
|
222
223
|
*/
|
|
223
224
|
async getRefunds(id) {
|
|
224
|
-
const data = await this.
|
|
225
|
+
const data = await this._withBaseUrl(this._ordersUrl)._fetchGet(`/${this._pathSegment(String(id))}/refund`);
|
|
225
226
|
return this._normalizeData(data);
|
|
226
227
|
}
|
|
227
228
|
/**
|
|
@@ -234,7 +235,7 @@ export default class OrdersApi extends AsyncModules {
|
|
|
234
235
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/createRefundRequest createRefundRequest} documentation.
|
|
235
236
|
*/
|
|
236
237
|
async createRefundRequest(id, body) {
|
|
237
|
-
const data = await this.
|
|
238
|
+
const data = await this._withBaseUrl(this._ordersUrl)._fetchPost(`/${this._pathSegment(String(id))}/refund`, body);
|
|
238
239
|
return this._normalizeData(data);
|
|
239
240
|
}
|
|
240
241
|
/**
|
|
@@ -246,7 +247,7 @@ export default class OrdersApi extends AsyncModules {
|
|
|
246
247
|
* @see {@link https://js-sdk.oneentry.cloud/docs/orders/cancelRefundRequest cancelRefundRequest} documentation.
|
|
247
248
|
*/
|
|
248
249
|
async cancelRefundRequest(id) {
|
|
249
|
-
const data = await this.
|
|
250
|
+
const data = await this._withBaseUrl(this._ordersUrl)._fetchDelete(`/${this._pathSegment(String(id))}/refund`);
|
|
250
251
|
return this._normalizeData(data);
|
|
251
252
|
}
|
|
252
253
|
/**
|
|
@@ -268,31 +269,9 @@ export default class OrdersApi extends AsyncModules {
|
|
|
268
269
|
offset,
|
|
269
270
|
limit,
|
|
270
271
|
};
|
|
271
|
-
const data = await this.
|
|
272
|
+
const data = await this._withBaseUrl(this._ordersUrl)._fetchPost(`/vector/search?` + this._queryParamsToString(query), body);
|
|
272
273
|
return this._normalizeData(data, langCode);
|
|
273
274
|
}
|
|
274
|
-
/**
|
|
275
|
-
* Runs a fetch against the `/orders` base URL instead of the default
|
|
276
|
-
* `/orders-storage`, then restores the original URL.
|
|
277
|
-
*
|
|
278
|
-
* Refund endpoints live under `/api/content/orders`, while this class is based
|
|
279
|
-
* on `/api/content/orders-storage`. The helper swaps `_url` for the duration of
|
|
280
|
-
* the call and restores it in `finally`, so the base URL is restored even if
|
|
281
|
-
* the request throws.
|
|
282
|
-
* @param {() => Promise<T>} fetcher - Thunk performing the fetch call.
|
|
283
|
-
* @returns {Promise<T>} The fetcher result.
|
|
284
|
-
* @template T
|
|
285
|
-
*/
|
|
286
|
-
async _withOrdersUrl(fetcher) {
|
|
287
|
-
const savedUrl = this._url;
|
|
288
|
-
this._url = this._ordersUrl;
|
|
289
|
-
try {
|
|
290
|
-
return await fetcher();
|
|
291
|
-
}
|
|
292
|
-
finally {
|
|
293
|
-
this._url = savedUrl;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
275
|
/**
|
|
297
276
|
* Builds the order body the API expects: `formData` wrapped in a map keyed by locale.
|
|
298
277
|
*
|