oneentry 1.0.176 → 1.0.177
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 +16 -0
- package/dist/forms-data/formsDataApi.js +32 -5
- 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 +6 -5
- package/dist/pages/pagesApi.js +44 -31
- package/dist/pages/pagesInterfaces.d.ts +18 -15
- 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 +38 -58
- package/dist/products/productsApi.js +59 -72
- package/dist/products/productsInterfaces.d.ts +48 -85
- package/dist/search/searchApi.d.ts +1 -1
- package/dist/search/searchApi.js +4 -3
- 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 +16 -0
- package/esm/forms-data/formsDataApi.js +32 -5
- 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 +6 -5
- package/esm/pages/pagesApi.js +44 -31
- package/esm/pages/pagesInterfaces.d.ts +18 -15
- 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 +38 -58
- package/esm/products/productsApi.js +59 -72
- package/esm/products/productsInterfaces.d.ts +48 -85
- package/esm/search/searchApi.d.ts +1 -1
- package/esm/search/searchApi.js +4 -3
- 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
|
@@ -20,7 +20,7 @@ interface IEvents {
|
|
|
20
20
|
* @handleName subscribeByMarker
|
|
21
21
|
* @param {string} marker - The marker identifying the event. Example: "product_price_change".
|
|
22
22
|
* @param {number} productId - The ID of the product to subscribe to. Example: 12345.
|
|
23
|
-
* @param {string} [langCode] - Optional language code for localization. Default:
|
|
23
|
+
* @param {string} [langCode] - Optional language code for localization. Default: the client's language.
|
|
24
24
|
* @returns {Promise<boolean | IError>} A promise that resolves to any type or an error.
|
|
25
25
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
26
26
|
* @description This method subscribes to an event on a product by its marker.
|
|
@@ -31,7 +31,7 @@ interface IEvents {
|
|
|
31
31
|
* @handleName unsubscribeByMarker
|
|
32
32
|
* @param {string} marker - The marker identifying the event. Example: "product_price_change".
|
|
33
33
|
* @param {number} productId - ID of the product to unsubscribe from. Example: 12345.
|
|
34
|
-
* @param {string} [langCode] - Optional language code for localization. Default:
|
|
34
|
+
* @param {string} [langCode] - Optional language code for localization. Default: the client's language.
|
|
35
35
|
* @returns {Promise<boolean | IError>} A promise that resolves to any type or an error.
|
|
36
36
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
37
37
|
* @description This method unsubscribes from an event on a product by its marker.
|
|
@@ -42,7 +42,7 @@ interface IEvents {
|
|
|
42
42
|
* @handleName getAllEvents
|
|
43
43
|
* @returns {Promise<IContentApiEvent[] | IError>} A promise that resolves to an array of events or an error.
|
|
44
44
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
45
|
-
* @description This method returns all available events.
|
|
45
|
+
* @description This method returns all available events. This method requires user authorization — without it the API answers `401 Unauthorized`.
|
|
46
46
|
*/
|
|
47
47
|
getAllEvents(): Promise<IContentApiEvent[] | IError>;
|
|
48
48
|
/**
|
|
@@ -85,16 +85,12 @@ interface IEvents {
|
|
|
85
85
|
* @property {number} total - Total number of found records. Example: 100.
|
|
86
86
|
* @property {ISubscriptionItem[]} items - Subscriptions, each with an event marker and a product ID.
|
|
87
87
|
* @example
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
productId:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
eventMarker: 'product_stock_update',
|
|
95
|
-
productId: 67890
|
|
96
|
-
}
|
|
97
|
-
]
|
|
88
|
+
{
|
|
89
|
+
"total": 1,
|
|
90
|
+
"items": [
|
|
91
|
+
{ "eventMarker": "lessPrice", "productId": 2954 }
|
|
92
|
+
]
|
|
93
|
+
}
|
|
98
94
|
* @property { string } items.eventMarker - Event marker.
|
|
99
95
|
* @property { number } items.productId - Product ID.
|
|
100
96
|
* @description Represents a response from the events API containing a total count and an array of subscription items.
|
|
@@ -173,4 +169,4 @@ interface ISubscribeFormEvent {
|
|
|
173
169
|
formDataId: number;
|
|
174
170
|
status?: string;
|
|
175
171
|
}
|
|
176
|
-
export type { IContentApiEvent, IEvents, IFormSubscriptionsResponse, IListFormSubscription, ISubscribeBody, ISubscribeFormEvent, ISubscriptions, };
|
|
172
|
+
export type { IContentApiEvent, IEvents, IFormSubscriptionsResponse, IListFormSubscription, ISubscribeBody, ISubscribeFormEvent, ISubscriptionItem, ISubscriptions, };
|
|
@@ -99,6 +99,7 @@ export default class FileUploadingApi extends AsyncModules implements IFileUploa
|
|
|
99
99
|
* @param {string} filename - The name to give the created file.
|
|
100
100
|
* @param {string} [mimeType] - Optional MIME type for the file.
|
|
101
101
|
* @returns {Promise<File>} A promise that resolves to a File object.
|
|
102
|
+
* @throws {Error} When the URL answers with an error status — the body of the error page is not turned into a file.
|
|
102
103
|
*/
|
|
103
104
|
createFileFromUrl(url: string, filename: string, mimeType?: string): Promise<File>;
|
|
104
105
|
/**
|
|
@@ -108,10 +109,9 @@ export default class FileUploadingApi extends AsyncModules implements IFileUploa
|
|
|
108
109
|
* @param {string} type - Storage type; determines the folder the file is stored in, for example `"page"`. Example: "page".
|
|
109
110
|
* @param {string} entity - Name of the entity the file belongs to; sets the folder name in the storage. Example: "editor".
|
|
110
111
|
* @param {string} filename - File name. Example: "file.png".
|
|
111
|
-
* @param {string} [template] -
|
|
112
|
-
* @returns {Promise<Response
|
|
113
|
-
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
112
|
+
* @param {string} [template] - Kept for compatibility: `GET /files` ignores it — the answer is the original file with any value, an unknown template included (CMS-1101, CMS-1128). Previews are made on `upload`.
|
|
113
|
+
* @returns {Promise<Response>} Resolves to the raw `Response` of the request — also on an error: check `response.ok`. A missing file answers `404` with a JSON body but a `content-type` taken from the requested file name (`image/png` …).
|
|
114
114
|
* @see {@link https://js-sdk.oneentry.cloud/docs/file-uploading/getFile getFile} documentation.
|
|
115
115
|
*/
|
|
116
|
-
getFile(id: number, type: string, entity: string, filename: string, template?: string): Promise<Response
|
|
116
|
+
getFile(id: number, type: string, entity: string, filename: string, template?: string): Promise<Response>;
|
|
117
117
|
}
|
|
@@ -121,7 +121,10 @@ class FileUploadingApi extends asyncModules_1.default {
|
|
|
121
121
|
const query = { ...this._defaultQuery, ...fileQuery };
|
|
122
122
|
// The endpoint answers 200 with an empty body, which _parseJson reads as `{}`;
|
|
123
123
|
// _fetchBoolean turns that into the declared `true` (CMS-1072)
|
|
124
|
-
return this._fetchBoolean(() => this._fetchDelete(
|
|
124
|
+
return this._fetchBoolean(() => this._fetchDelete(
|
|
125
|
+
// The name is encoded like the other parameters: `#` cut the query and dropped
|
|
126
|
+
// type/entity/id, `&id=` added parameters of its own
|
|
127
|
+
`?` + this._queryParamsToString({ filename, ...query })));
|
|
125
128
|
}
|
|
126
129
|
/**
|
|
127
130
|
* Public search across the content of files attached to records.
|
|
@@ -171,10 +174,15 @@ class FileUploadingApi extends asyncModules_1.default {
|
|
|
171
174
|
* @param {string} filename - The name to give the created file.
|
|
172
175
|
* @param {string} [mimeType] - Optional MIME type for the file.
|
|
173
176
|
* @returns {Promise<File>} A promise that resolves to a File object.
|
|
177
|
+
* @throws {Error} When the URL answers with an error status — the body of the error page is not turned into a file.
|
|
174
178
|
*/
|
|
175
179
|
async createFileFromUrl(url, filename, mimeType) {
|
|
176
180
|
// eslint-disable-next-line no-undef
|
|
177
181
|
const response = await fetch(url);
|
|
182
|
+
// A 404 page of the storage used to become the "file" and was then uploaded as is
|
|
183
|
+
if (!response.ok) {
|
|
184
|
+
throw new Error(`OneEntry SDK: createFileFromUrl got ${response.status} from ${url}`);
|
|
185
|
+
}
|
|
178
186
|
const blob = await response.blob();
|
|
179
187
|
const file = new File([blob], filename, { type: mimeType || blob.type });
|
|
180
188
|
return file;
|
|
@@ -186,14 +194,14 @@ class FileUploadingApi extends asyncModules_1.default {
|
|
|
186
194
|
* @param {string} type - Storage type; determines the folder the file is stored in, for example `"page"`. Example: "page".
|
|
187
195
|
* @param {string} entity - Name of the entity the file belongs to; sets the folder name in the storage. Example: "editor".
|
|
188
196
|
* @param {string} filename - File name. Example: "file.png".
|
|
189
|
-
* @param {string} [template] -
|
|
190
|
-
* @returns {Promise<Response
|
|
191
|
-
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
197
|
+
* @param {string} [template] - Kept for compatibility: `GET /files` ignores it — the answer is the original file with any value, an unknown template included (CMS-1101, CMS-1128). Previews are made on `upload`.
|
|
198
|
+
* @returns {Promise<Response>} Resolves to the raw `Response` of the request — also on an error: check `response.ok`. A missing file answers `404` with a JSON body but a `content-type` taken from the requested file name (`image/png` …).
|
|
192
199
|
* @see {@link https://js-sdk.oneentry.cloud/docs/file-uploading/getFile getFile} documentation.
|
|
193
200
|
*/
|
|
194
201
|
async getFile(id, type, entity, filename, template) {
|
|
195
202
|
// eslint-disable-next-line no-undef
|
|
196
|
-
const response = await fetch(this._getFullPath(
|
|
203
|
+
const response = await fetch(this._getFullPath('?' +
|
|
204
|
+
this._queryParamsToString({ id, type, entity, filename, template })), {
|
|
197
205
|
method: 'GET',
|
|
198
206
|
headers: {
|
|
199
207
|
'Content-Type': 'application/json',
|
|
@@ -66,11 +66,10 @@ interface IFileUploading {
|
|
|
66
66
|
* @param {string} type - Storage type; determines the folder the file is stored in, for example `"page"`. Example: "page".
|
|
67
67
|
* @param {string} entity - Name of the entity the file belongs to; sets the folder name in the storage. Example: "editor".
|
|
68
68
|
* @param {string} filename - File name. Example: "file.png".
|
|
69
|
-
* @param {string} [template] -
|
|
70
|
-
* @returns {Response
|
|
71
|
-
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
69
|
+
* @param {string} [template] - Kept for compatibility: `GET /files` ignores it — the answer is the original file with any value, an unknown template included (CMS-1101, CMS-1128). Previews are made on `upload`.
|
|
70
|
+
* @returns {Response} The raw `Response` of the request — also on an error: check `response.ok`. A missing file answers `404` with a JSON body but a `content-type` taken from the file name. No IError is returned and nothing is thrown on an HTTP error.
|
|
72
71
|
*/
|
|
73
|
-
getFile(id: number, type: string, entity: string, filename: string, template?: string): Promise<Response
|
|
72
|
+
getFile(id: number, type: string, entity: string, filename: string, template?: string): Promise<Response>;
|
|
74
73
|
/**
|
|
75
74
|
* Public search across the content of files attached to records.
|
|
76
75
|
* @handleName searchFileContent
|
|
@@ -186,7 +185,7 @@ interface IFileSearchItem {
|
|
|
186
185
|
* The `IFileSearchQueryLanguage` interface describes how the query language was resolved.
|
|
187
186
|
* @interface IFileSearchQueryLanguage
|
|
188
187
|
* @property {string[]} resolved - Languages the query was actually run in. Example: ["english"].
|
|
189
|
-
* @property {string} source - How they were chosen: "explicit" when taken from `langCode
|
|
188
|
+
* @property {string} source - How they were chosen: `"explicit"` when taken from `langCode`; detected otherwise (seen: `"script"`). Detection runs only with `langCode: ""` — by default the client's language is sent. Example: "explicit".
|
|
190
189
|
* @property {string[]} candidates - Languages that were considered. Example: ["english"].
|
|
191
190
|
* @description How the query language was resolved for the search.
|
|
192
191
|
*/
|
|
@@ -202,7 +201,7 @@ interface IFileSearchQueryLanguage {
|
|
|
202
201
|
* @property {number} offset - Number of records to skip. Example: 0.
|
|
203
202
|
* @property {number} limit - Maximum number of records to return. Example: 10.
|
|
204
203
|
* @property {IFileSearchQueryLanguage} queryLanguage - How the query language was resolved.
|
|
205
|
-
* @property {string[]} warnings -
|
|
204
|
+
* @property {string[]} warnings - Warning codes, empty when there are none. Seen: `processing_disabled` (content indexing is off — `items` is always empty), `query_language_capped`, `query_too_common`.
|
|
206
205
|
* @property {IFileSearchItem[]} items - Files that match the query.
|
|
207
206
|
* @description The result of a file content search.
|
|
208
207
|
*/
|
|
@@ -67,9 +67,9 @@ class FiltersApi extends asyncModules_1.default {
|
|
|
67
67
|
* @see {@link https://js-sdk.oneentry.cloud/docs/filters/getFilterByMarker getFilterByMarker} documentation.
|
|
68
68
|
*/
|
|
69
69
|
async getFilterByMarker(marker, langCode = this.state.lang) {
|
|
70
|
-
const data = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${langCode}`);
|
|
70
|
+
const data = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${encodeURIComponent(langCode)}`);
|
|
71
71
|
const validated = await this._validateResponse(data, schema('ContentFilterSchema'));
|
|
72
|
-
return this._normalizeData(validated);
|
|
72
|
+
return this._normalizeData(validated, langCode);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
exports.default = FiltersApi;
|
package/dist/forms/formsApi.js
CHANGED
|
@@ -69,7 +69,7 @@ class FormsApi extends asyncModules_1.default {
|
|
|
69
69
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms/getAllForms getAllForms} documentation.
|
|
70
70
|
*/
|
|
71
71
|
async getAllForms(langCode = this.state.lang, offset = 0, limit = 30) {
|
|
72
|
-
const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
|
|
72
|
+
const result = await this._fetchGet(`?langCode=${encodeURIComponent(langCode)}&offset=${encodeURIComponent(String(offset))}&limit=${encodeURIComponent(String(limit))}`);
|
|
73
73
|
// Validate response if validation is enabled
|
|
74
74
|
const validated = await this._validateResponse(result, schema('FormsResponseSchema'));
|
|
75
75
|
return this._normalizeData(validated, langCode);
|
|
@@ -84,7 +84,7 @@ class FormsApi extends asyncModules_1.default {
|
|
|
84
84
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms/getFormByMarker getFormByMarker} documentation.
|
|
85
85
|
*/
|
|
86
86
|
async getFormByMarker(marker, langCode = this.state.lang) {
|
|
87
|
-
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${langCode}`);
|
|
87
|
+
const result = await this._fetchGet(`/marker/${this._pathSegment(marker)}?langCode=${encodeURIComponent(langCode)}`);
|
|
88
88
|
// Validate response if validation is enabled
|
|
89
89
|
const validated = await this._validateResponse(result, schema('FormEntitySchema'));
|
|
90
90
|
return this._normalizeData(validated, langCode);
|
|
@@ -69,10 +69,9 @@ interface IFromPages {
|
|
|
69
69
|
* @property {number} version - Version number of the object; changes with each update. Example: 1.
|
|
70
70
|
* @property {number} position - Position of the object, used for sorting. Example: 1.
|
|
71
71
|
* @property {string} identifier - Text identifier (marker) of the object. Example: "form_contact_us".
|
|
72
|
-
* @property {string} processingType - How form submissions are processed
|
|
72
|
+
* @property {string} processingType - How form submissions are processed: the processing type chosen in the form settings. Example: "script".
|
|
73
73
|
* @property {number | null} templateId - ID of the template used by the form, or `null` when the form has no template. Example: 6789.
|
|
74
74
|
* @property {IFormAttribute[]} attributes - Form fields with their localization, validators and form-specific flags, sorted by `position`. The API returns an empty object for forms with no attributes — the SDK normalizes it to an empty array.
|
|
75
|
-
* @property {number | string} [total] - Total count of related entries. Example: "1".
|
|
76
75
|
* @property {IFormConfig[]} [moduleFormConfigs] - Form configurations of the module associated with the form.
|
|
77
76
|
* @description This interface defines the structure of a form entity, including its identifiers, attributes, and processing data.
|
|
78
77
|
*/
|
|
@@ -87,7 +86,6 @@ interface IFormsEntity {
|
|
|
87
86
|
processingType: string;
|
|
88
87
|
templateId: number | null;
|
|
89
88
|
attributes: IFormAttribute[];
|
|
90
|
-
total?: number | string;
|
|
91
89
|
moduleFormConfigs?: IFormConfig[];
|
|
92
90
|
}
|
|
93
91
|
/**
|
|
@@ -13,8 +13,7 @@ export declare const FormEntitySchema: z.ZodObject<{
|
|
|
13
13
|
type: z.ZodNullable<z.ZodString>;
|
|
14
14
|
attributeSetId: z.ZodNullable<z.ZodNumber>;
|
|
15
15
|
templateId: z.ZodNullable<z.ZodNumber>;
|
|
16
|
-
|
|
17
|
-
attributes: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
|
|
16
|
+
attributes: z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>;
|
|
18
17
|
moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
19
18
|
}, z.core.$strip>;
|
|
20
19
|
/**
|
|
@@ -32,8 +31,7 @@ export declare const FormsResponseSchema: z.ZodObject<{
|
|
|
32
31
|
type: z.ZodNullable<z.ZodString>;
|
|
33
32
|
attributeSetId: z.ZodNullable<z.ZodNumber>;
|
|
34
33
|
templateId: z.ZodNullable<z.ZodNumber>;
|
|
35
|
-
|
|
36
|
-
attributes: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
|
|
34
|
+
attributes: z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>;
|
|
37
35
|
moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
38
36
|
}, z.core.$strip>>;
|
|
39
37
|
}, z.core.$strip>;
|
|
@@ -50,7 +48,6 @@ export declare const SingleFormSchema: z.ZodObject<{
|
|
|
50
48
|
type: z.ZodNullable<z.ZodString>;
|
|
51
49
|
attributeSetId: z.ZodNullable<z.ZodNumber>;
|
|
52
50
|
templateId: z.ZodNullable<z.ZodNumber>;
|
|
53
|
-
|
|
54
|
-
attributes: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>>;
|
|
51
|
+
attributes: z.ZodUnion<readonly [z.ZodArray<z.ZodAny>, z.ZodRecord<z.ZodString, z.ZodAny>]>;
|
|
55
52
|
moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
56
53
|
}, z.core.$strip>;
|
|
@@ -16,10 +16,8 @@ exports.FormEntitySchema = zod_1.z.object({
|
|
|
16
16
|
type: zod_1.z.string().nullable(),
|
|
17
17
|
attributeSetId: zod_1.z.number().nullable(),
|
|
18
18
|
templateId: zod_1.z.number().nullable(),
|
|
19
|
-
|
|
20
|
-
attributes: zod_1.z
|
|
21
|
-
.union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())])
|
|
22
|
-
.optional(),
|
|
19
|
+
// Required as in IFormsEntity: a form without fields comes as `{}`
|
|
20
|
+
attributes: zod_1.z.union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())]),
|
|
23
21
|
moduleFormConfigs: zod_1.z.array(zod_1.z.any()).optional(),
|
|
24
22
|
});
|
|
25
23
|
/**
|
|
@@ -140,6 +140,22 @@ export default class FormsDataApi extends AsyncModules implements IFormsData {
|
|
|
140
140
|
* Update one object of form data by id. Requires user authentication.
|
|
141
141
|
* @handleName updateFormsDataByid
|
|
142
142
|
* @param {number} id - Form data ID. Example: 1.
|
|
143
|
+
* @param {object} [body] - Form data to save: the same fields as in `postFormsData` (`formIdentifier`, `formModuleConfigId`, `moduleEntityIdentifier`, `replayTo`, `status`, `formData`). Default: `{}`.
|
|
144
|
+
* @example
|
|
145
|
+
{
|
|
146
|
+
"formIdentifier": "test-form",
|
|
147
|
+
"formModuleConfigId": 2,
|
|
148
|
+
"moduleEntityIdentifier": "blog",
|
|
149
|
+
"replayTo": null,
|
|
150
|
+
"status": "sent",
|
|
151
|
+
"formData": [
|
|
152
|
+
{
|
|
153
|
+
"marker": "name",
|
|
154
|
+
"type": "string",
|
|
155
|
+
"value": "Test"
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
}
|
|
143
159
|
* @returns {Promise<IUpdateFormsData | IError>} Returns an object containing the updated form data or an error object if there was an issue.
|
|
144
160
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/updateFormsDataByid updateFormsDataByid} documentation.
|
|
145
161
|
*/
|
|
@@ -166,6 +166,17 @@ class FormsDataApi extends asyncModules_1.default {
|
|
|
166
166
|
return field;
|
|
167
167
|
}));
|
|
168
168
|
}
|
|
169
|
+
// A failed upload used to be sent to the platform as the field's value, and the caller
|
|
170
|
+
// got a success: the form is not sent, the upload's error is the answer
|
|
171
|
+
const uploadError = formData[langCode]
|
|
172
|
+
.flatMap((field) => Array.isArray(field === null || field === void 0 ? void 0 : field.value) ? field.value : [field === null || field === void 0 ? void 0 : field.value])
|
|
173
|
+
.find((value) => this._isErrorResponse(value));
|
|
174
|
+
if (uploadError) {
|
|
175
|
+
if (this.state.isShell) {
|
|
176
|
+
return uploadError;
|
|
177
|
+
}
|
|
178
|
+
throw uploadError;
|
|
179
|
+
}
|
|
169
180
|
// The wrapped formData goes into a new body: written back into the caller's
|
|
170
181
|
// object, a second call with it wrapped the wrapper and answered `400` (CMS-1071)
|
|
171
182
|
const result = await this._fetchPost(``, { ...body, formData });
|
|
@@ -272,7 +283,7 @@ class FormsDataApi extends asyncModules_1.default {
|
|
|
272
283
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/getFormsDataByMarker getFormsDataByMarker} documentation.
|
|
273
284
|
*/
|
|
274
285
|
async getFormsDataByMarker(marker, formModuleConfigId, body = {}, isExtended = 0, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
275
|
-
const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}?formModuleConfigId=${formModuleConfigId}&isExtended=${isExtended}&langCode=${langCode}&offset=${offset}&limit=${limit}`, this._stripEmptyDates(body));
|
|
286
|
+
const result = await this._fetchPost(`/marker/${this._pathSegment(marker)}?formModuleConfigId=${encodeURIComponent(String(formModuleConfigId))}&isExtended=${encodeURIComponent(String(isExtended))}&langCode=${encodeURIComponent(langCode)}&offset=${encodeURIComponent(String(offset))}&limit=${encodeURIComponent(String(limit))}`, this._stripEmptyDates(body));
|
|
276
287
|
// Validate response if validation is enabled
|
|
277
288
|
const validated = await this._validateResponse(result, schema('FormsByMarkerDataResponseSchema'));
|
|
278
289
|
return this._normalizeData(validated, langCode);
|
|
@@ -281,11 +292,27 @@ class FormsDataApi extends asyncModules_1.default {
|
|
|
281
292
|
* Update one object of form data by id. Requires user authentication.
|
|
282
293
|
* @handleName updateFormsDataByid
|
|
283
294
|
* @param {number} id - Form data ID. Example: 1.
|
|
295
|
+
* @param {object} [body] - Form data to save: the same fields as in `postFormsData` (`formIdentifier`, `formModuleConfigId`, `moduleEntityIdentifier`, `replayTo`, `status`, `formData`). Default: `{}`.
|
|
296
|
+
* @example
|
|
297
|
+
{
|
|
298
|
+
"formIdentifier": "test-form",
|
|
299
|
+
"formModuleConfigId": 2,
|
|
300
|
+
"moduleEntityIdentifier": "blog",
|
|
301
|
+
"replayTo": null,
|
|
302
|
+
"status": "sent",
|
|
303
|
+
"formData": [
|
|
304
|
+
{
|
|
305
|
+
"marker": "name",
|
|
306
|
+
"type": "string",
|
|
307
|
+
"value": "Test"
|
|
308
|
+
}
|
|
309
|
+
]
|
|
310
|
+
}
|
|
284
311
|
* @returns {Promise<IUpdateFormsData | IError>} Returns an object containing the updated form data or an error object if there was an issue.
|
|
285
312
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/updateFormsDataByid updateFormsDataByid} documentation.
|
|
286
313
|
*/
|
|
287
314
|
async updateFormsDataByid(id, body = {}) {
|
|
288
|
-
const result = await this._fetchPut(`/${id}`, body);
|
|
315
|
+
const result = await this._fetchPut(`/${this._pathSegment(String(id))}`, body);
|
|
289
316
|
// Validate response if validation is enabled
|
|
290
317
|
const validated = await this._validateResponse(result, schema('UpdateFormsDataSchema'));
|
|
291
318
|
return validated;
|
|
@@ -299,7 +326,7 @@ class FormsDataApi extends asyncModules_1.default {
|
|
|
299
326
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/updateFormsDataStatusByid updateFormsDataStatusByid} documentation.
|
|
300
327
|
*/
|
|
301
328
|
async updateFormsDataStatusByid(id, body = {}) {
|
|
302
|
-
const result = await this._fetchPut(`/${id}/update-status`, body);
|
|
329
|
+
const result = await this._fetchPut(`/${this._pathSegment(String(id))}/update-status`, body);
|
|
303
330
|
return result;
|
|
304
331
|
}
|
|
305
332
|
/**
|
|
@@ -310,8 +337,8 @@ class FormsDataApi extends asyncModules_1.default {
|
|
|
310
337
|
* @see {@link https://js-sdk.oneentry.cloud/docs/forms-data/deleteFormsDataByid deleteFormsDataByid} documentation.
|
|
311
338
|
*/
|
|
312
339
|
async deleteFormsDataByid(id) {
|
|
313
|
-
const result = await this._fetchDelete(`/${id}`);
|
|
314
|
-
return result;
|
|
340
|
+
const result = await this._fetchDelete(`/${this._pathSegment(String(id))}`);
|
|
341
|
+
return this._asBoolean(result);
|
|
315
342
|
}
|
|
316
343
|
/**
|
|
317
344
|
* Semantic (vector) search for form data.
|
|
@@ -225,9 +225,14 @@ interface IFormDataEntity {
|
|
|
225
225
|
"id": 1,
|
|
226
226
|
"formIdentifier": "form",
|
|
227
227
|
"time": "2025-06-06T19:07:45.993Z",
|
|
228
|
-
"formData":
|
|
229
|
-
|
|
230
|
-
|
|
228
|
+
"formData": [
|
|
229
|
+
{
|
|
230
|
+
"marker": "name",
|
|
231
|
+
"type": "string",
|
|
232
|
+
"value": "Test"
|
|
233
|
+
}
|
|
234
|
+
],
|
|
235
|
+
"attributeSetIdentifier": "form"
|
|
231
236
|
}
|
|
232
237
|
]
|
|
233
238
|
* @property {number} total - Total number of found records. Example: 100.
|
|
@@ -241,13 +246,13 @@ interface IFormsDataEntity {
|
|
|
241
246
|
* Represents the structure of a form data entity.
|
|
242
247
|
* @interface IFormByMarkerDataEntity
|
|
243
248
|
* @property {number} id - ID of the form data record. Example: 12345.
|
|
244
|
-
* @property {null | number} parentId - ID of the parent form data record; `null` for a top-level record. Example: 123.
|
|
249
|
+
* @property {null | number} [parentId] - ID of the parent form data record; `null` for a top-level record. Returned only with `isExtended` = 1. Example: 123.
|
|
245
250
|
* @property {string} formIdentifier - Marker of the form. Example: "contact_form".
|
|
246
|
-
* @property {number} depth - Example: 1.
|
|
247
|
-
* @property {string | null} ip - IP address the form was submitted from. Example: '127.0.0.1'.
|
|
248
|
-
* @property {string | null} fingerprint - Device fingerprint of the sender. Example: 'fingerprint'.
|
|
249
|
-
* @property {string | null} status - Moderation status of the record: "sent", "moderation", "approved", "banned" or "deleted"; `null` when the form does not moderate. Example: 'approved'.
|
|
250
|
-
* @property {string | null} userIdentifier - Text identifier (marker) of the user. Example: "admin".
|
|
251
|
+
* @property {number} [depth] - Nesting depth of the record. Returned only with `isExtended` = 1. Example: 1.
|
|
252
|
+
* @property {string | null} [ip] - IP address the form was submitted from. Not returned by the by-marker list. Example: '127.0.0.1'.
|
|
253
|
+
* @property {string | null} [fingerprint] - Device fingerprint of the sender. Not returned by the by-marker list. Example: 'fingerprint'.
|
|
254
|
+
* @property {string | null} [status] - Moderation status of the record: "sent", "moderation", "approved", "banned" or "deleted"; `null` when the form does not moderate. Returned only with `isExtended` = 1. Example: 'approved'.
|
|
255
|
+
* @property {string | null} [userIdentifier] - Text identifier (marker) of the user. Returned only with `isExtended` = 1. Example: "admin".
|
|
251
256
|
* @property {FormDataType[]} formData - Submitted fields, **already unwrapped from the locale**: the API returns `{ "en_US": [ … ] }` and the SDK hands over the array for the requested `langCode`. Read `formData` directly — `formData[langCode]` is `undefined`.
|
|
252
257
|
* @example
|
|
253
258
|
[
|
|
@@ -260,7 +265,7 @@ interface IFormsDataEntity {
|
|
|
260
265
|
* @property {string | null} attributeSetIdentifier - Marker of the attribute set used by the form. Example: "product_attributes".
|
|
261
266
|
* @property {Date | string} time - Date and time the form data was last changed. Example: "2023-10-01T12:00:00Z".
|
|
262
267
|
* @property {string} entityIdentifier - Marker of the entity the record belongs to. Example: "test".
|
|
263
|
-
* @property {boolean} isUserAdmin - Whether the record was submitted by an admin. Example: true.
|
|
268
|
+
* @property {boolean} [isUserAdmin] - Whether the record was submitted by an admin. Returned only with `isExtended` = 1. Example: true.
|
|
264
269
|
* @property {number} formModuleConfigId - ID of the form module configuration. Example: 2.
|
|
265
270
|
* @property {string} [moduleIdentifier] - Marker of the module. Example: "blog".
|
|
266
271
|
* @property {number} entityId - ID of the entity the record belongs to. Example: 2.
|
|
@@ -287,7 +292,7 @@ interface IFormByMarkerDataEntity {
|
|
|
287
292
|
/**
|
|
288
293
|
* Represents a collection of form data entities.
|
|
289
294
|
* @interface IFormsByMarkerDataEntity
|
|
290
|
-
* @property {IFormByMarkerDataEntity[]} items - Form data records.
|
|
295
|
+
* @property {IFormByMarkerDataEntity[]} items - Form data records. The example shows a record with `isExtended` = 1; without it `parentId`, `depth`, `status`, `userIdentifier` and `isUserAdmin` are not returned.
|
|
291
296
|
* @example
|
|
292
297
|
[
|
|
293
298
|
{
|
|
@@ -295,7 +300,6 @@ interface IFormByMarkerDataEntity {
|
|
|
295
300
|
"parentId": null,
|
|
296
301
|
"formIdentifier": "test-form",
|
|
297
302
|
"depth": 0,
|
|
298
|
-
"ip": null,
|
|
299
303
|
"status": null,
|
|
300
304
|
"userIdentifier": null,
|
|
301
305
|
"formData": [
|
|
@@ -862,4 +866,4 @@ interface IListOptionValue {
|
|
|
862
866
|
value: string;
|
|
863
867
|
extended: IListOptionExtended;
|
|
864
868
|
}
|
|
865
|
-
export type { FormDataPostType, FormDataStatus, FormDataType, IBodyPostFormData, IBodyPostTypeList, IBodyPostTypeSpam, IBodyPostTypeText, IBodyTypeEntity, IBodyTypeFile, IBodyTypeImageGroupOfImages, IBodyTypeRadioButtonList, IBodyTypeStringNumberFloat, IBodyTypeText, IBodyTypeTextWithHeader, IBodyTypeTimeDate, IBodyTypeTimeInterval, ICaptchaEvent, ICaptchaValue, IFileValue, IFormByMarkerDataEntity, IFormDataEntity, IFormDataSearchEntity, IFormsByMarkerDataEntity, IFormsData, IFormsDataEntity, IFormsDataFilter, IFormsDataSearchResponse, IFormsDataVectorSearch, IImageValue, IImageValueParams, IListOptionExtended, IListOptionValue, IPostFormResponse, IPostFormResponseData, ITextEditorParams, ITextSubmissionValue, ITextValue, ITextWithHeaderValue, ITimeDateValue, IUpdateFormsData, };
|
|
869
|
+
export type { FormDataPostType, FormDataStatus, FormDataType, IBodyPostFormData, IBodyPostTypeList, IBodyPostTypeSpam, IBodyPostTypeText, IBodyTypeEntity, IBodyTypeFile, IBodyTypeImageGroupOfImages, IBodyTypeRadioButtonList, IBodyTypeStringNumberFloat, IBodyTypeText, IBodyTypeTextWithHeader, IBodyTypeTimeDate, IBodyTypeTimeInterval, ICaptchaEvent, ICaptchaValue, IFileValue, IFormByMarkerDataEntity, IFormDataEntity, IFormDataSearchEntity, IFormsByMarkerDataEntity, IFormsData, IFormsDataEntity, IFormsDataFilter, IFormsDataSearchResponse, IFormsDataVectorSearch, IImageValue, IImageValueParams, IListOptionExtended, IListOptionValue, IPostFormResponse, IPostFormResponseData, ITextEditorParams, ITextSubmissionValue, ITextSubmissionValueHtml, ITextSubmissionValueMd, ITextSubmissionValuePlain, ITextValue, ITextWithHeaderValue, ITimeDateValue, IUpdateFormsData, };
|
|
@@ -19,7 +19,7 @@ interface IGeneralTypes {
|
|
|
19
19
|
* Represents a general type entity.
|
|
20
20
|
* @interface IGeneralTypesEntity
|
|
21
21
|
* @property {number} id - ID of the type. Example: 1.
|
|
22
|
-
* @property {BlockType} type - Type name: a `BlockType` value such as `"product"` or `"service"`. Example: "product"
|
|
22
|
+
* @property {BlockType} type - Type name: a `BlockType` value such as `"product"`, `"catalog_page"`, `"product_block"` or `"service"`. Example: "product".
|
|
23
23
|
* @description Represents a general type entity with an identifier and a type.
|
|
24
24
|
*/
|
|
25
25
|
interface IGeneralTypesEntity {
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ import WsApi from './web-socket/wsApi';
|
|
|
34
34
|
export { getAdditionalFields, getAttributeFile, getAttributeFiles, isFileAttribute, isListAttribute, isNumberAttribute, isStringAttribute, } from './base/attributes';
|
|
35
35
|
export { expandAttributeTimeIntervals, expandTimeIntervals, isTimeIntervalAttribute, } from './base/timeIntervals';
|
|
36
36
|
export type * from './types';
|
|
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/dist/index.js
CHANGED
|
@@ -50,23 +50,55 @@ var timeIntervals_1 = require("./base/timeIntervals");
|
|
|
50
50
|
Object.defineProperty(exports, "expandAttributeTimeIntervals", { enumerable: true, get: function () { return timeIntervals_1.expandAttributeTimeIntervals; } });
|
|
51
51
|
Object.defineProperty(exports, "expandTimeIntervals", { enumerable: true, get: function () { return timeIntervals_1.expandTimeIntervals; } });
|
|
52
52
|
Object.defineProperty(exports, "isTimeIntervalAttribute", { enumerable: true, get: function () { return timeIntervals_1.isTimeIntervalAttribute; } });
|
|
53
|
+
/**
|
|
54
|
+
* Checks the project URL every request path is appended to.
|
|
55
|
+
* @param {string} raw - The URL as passed, trimmed.
|
|
56
|
+
* @param {string} base - The URL with trailing `/` and `/api/content` removed.
|
|
57
|
+
* @returns {boolean} True for an http(s) origin (optionally with a path) or a same-origin proxy path.
|
|
58
|
+
* @description A backslash is read as `/` by browsers: `/\\evil.example` was a "path" that sent
|
|
59
|
+
* every request — and the app token — to another host. A query or fragment swallowed every
|
|
60
|
+
* path appended to it, and credentials in the URL make `fetch` throw on each call.
|
|
61
|
+
*/
|
|
62
|
+
function _isProjectUrl(raw, base) {
|
|
63
|
+
if (/[\\?#\s]/.test(base)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
if (raw.startsWith('/')) {
|
|
67
|
+
// `/` and `/api/content` leave an empty base: the site's own origin
|
|
68
|
+
return !raw.startsWith('//') && (base === '' || base.startsWith('/'));
|
|
69
|
+
}
|
|
70
|
+
// `https:evil.example` parses with that host, but a browser resolves it as a path
|
|
71
|
+
if (!/^https?:\/\//i.test(base)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const parsed = new URL(base);
|
|
76
|
+
return ((parsed.protocol === 'http:' || parsed.protocol === 'https:') &&
|
|
77
|
+
!!parsed.hostname &&
|
|
78
|
+
!parsed.username &&
|
|
79
|
+
!parsed.password);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
53
85
|
/**
|
|
54
86
|
* Define API.
|
|
55
87
|
* @function defineOneEntry
|
|
56
88
|
* @param {string} url - URl of your project.
|
|
57
89
|
* @param {IConfig} config - Custom configuration settings
|
|
58
|
-
* @param {string}
|
|
90
|
+
* @param {string} config.token - App token of the project. Required: `defineOneEntry` throws without it.
|
|
59
91
|
* @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.
|
|
60
92
|
* @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.
|
|
61
|
-
* @param {string} [config.langCode] - Optional
|
|
93
|
+
* @param {string} [config.langCode] - Optional default language. Default: 'en_US'.
|
|
62
94
|
* @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.
|
|
63
|
-
* @param {
|
|
95
|
+
* @param {object} [config.auth] - An object with authorization settings.
|
|
64
96
|
* @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.
|
|
65
|
-
* @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.
|
|
97
|
+
* @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.
|
|
66
98
|
* @param {string} [config.auth.providerMarker] - The marker of the authorization provider.
|
|
67
|
-
* @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.
|
|
99
|
+
* @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.
|
|
68
100
|
* @returns {IDefineApi} List of methods set.
|
|
69
|
-
* @description Define API.
|
|
101
|
+
* @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.
|
|
70
102
|
*/
|
|
71
103
|
function defineOneEntry(url, config) {
|
|
72
104
|
if (typeof url !== 'string' || url.trim() === '') {
|
|
@@ -81,7 +113,18 @@ function defineOneEntry(url, config) {
|
|
|
81
113
|
'Pass it via config, e.g. ' +
|
|
82
114
|
'defineOneEntry("https://your-project.oneentry.cloud", { token: "your-app-token" }).');
|
|
83
115
|
}
|
|
84
|
-
|
|
116
|
+
// Trailing slashes and a copied `/api/content` suffix used to double up in every path
|
|
117
|
+
// (`//api/content/…`, `/api/content/api/content/…`) and fail each call with a 404
|
|
118
|
+
const baseUrl = url
|
|
119
|
+
.trim()
|
|
120
|
+
.replace(/\/+$/, '')
|
|
121
|
+
.replace(/\/api\/content$/i, '');
|
|
122
|
+
if (!_isProjectUrl(url.trim(), baseUrl)) {
|
|
123
|
+
throw new Error('OneEntry SDK: project URL must be an http(s) URL without credentials, query or fragment, ' +
|
|
124
|
+
'or a same-origin proxy path starting with "/", e.g. ' +
|
|
125
|
+
'defineOneEntry("https://your-project.oneentry.cloud", { token: "your-app-token" }).');
|
|
126
|
+
}
|
|
127
|
+
const stateModule = new stateModule_1.default(baseUrl, config);
|
|
85
128
|
const Admins = new adminsApi_1.default(stateModule);
|
|
86
129
|
const AttributesSets = new attributeSetsApi_1.default(stateModule);
|
|
87
130
|
const AuthProvider = new authProviderApi_1.default(stateModule);
|