oneentry 1.0.167 → 1.0.169

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.
@@ -13,11 +13,12 @@ interface ISearchApi {
13
13
  * @param {'all' | 'visible' | 'hidden'} [visibility] - Visibility filter of the searched records. Default: "all".
14
14
  * @param {number} [offset] - Drilldown mode offset. Pass it only together with a single accessible type in `types`.
15
15
  * @param {number} [limit] - Drilldown mode page size. Pass it only together with a single accessible type in `types`, otherwise the API answers 400 "Drilldown mode (limit/offset) requires exactly one accessible type in `types`". Without it every group is returned in full.
16
+ * @param {string} [langCode] - Language code. Default: "en_US". The search index is per language: a word of a second locale is found only when its own langCode is sent (CMS-912).
16
17
  * @returns {Promise<IGlobalSearchResponse | IError>} Returns the query and the found records grouped by entity type.
17
18
  * @throws {IError} When isShell=false and an error occurs during the fetch
18
- * @description Searches names and attribute values of visible records across entity types.
19
+ * @description Searches names and attribute values of visible records across entity types. The index is per language — the request carries `langCode`, so a bilingual project finds a word of either locale.
19
20
  */
20
- globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number): Promise<IGlobalSearchResponse | IError>;
21
+ globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number, langCode?: string): Promise<IGlobalSearchResponse | IError>;
21
22
  }
22
23
  /**
23
24
  * Entity type a global search group or item belongs to.
@@ -147,9 +147,9 @@ class UsersApi extends asyncModules_1.default {
147
147
  * @see {@link https://js-sdk.oneentry.cloud/docs/users/updateUser updateUser} documentation.
148
148
  */
149
149
  async updateUser(body, langCode = this.state.lang) {
150
- if (!('langCode' in body))
151
- body['langCode'] = langCode;
152
- const result = await this._fetchPut('/me', this._normalizePostBody(body, langCode));
150
+ // The language goes onto our own copy; the caller's body is left alone (CMS-909).
151
+ const payload = 'langCode' in body ? body : { ...body, langCode };
152
+ const result = await this._fetchPut('/me', this._normalizePostBody(payload, langCode));
153
153
  const validated = await this._validateResponse(result, schema('UpdateUserResponseSchema'));
154
154
  return validated;
155
155
  }
@@ -86,8 +86,9 @@ export default class AuthProviderApi extends AsyncModules {
86
86
  * @see {@link https://js-sdk.oneentry.cloud/docs/auth-provider/signUp signUp} documentation.
87
87
  */
88
88
  async signUp(marker, body, langCode = this.state.lang) {
89
- body['langCode'] = langCode;
90
- const result = await this._fetchPost(`/marker/${marker}/users/sign-up`, this._normalizePostBody(body, langCode));
89
+ // `langCode` goes onto our own copy — the caller's body stays as it was
90
+ // given, so a retry or a second parallel call sends the same thing (CMS-909).
91
+ const result = await this._fetchPost(`/marker/${marker}/users/sign-up`, this._normalizePostBody({ ...body, langCode }, langCode));
91
92
  // Validate response if validation is enabled
92
93
  const validated = await this._validateResponse(result, schema('SignUpResponseSchema'));
93
94
  return this._normalizeData(validated);
@@ -103,13 +103,19 @@ export default abstract class AsyncModules extends SyncModules {
103
103
  */
104
104
  private makeOptions;
105
105
  /**
106
- * Reads a response body as JSON, tolerating an empty body.
106
+ * Reads an error response body as JSON, tolerating an empty body.
107
107
  *
108
108
  * `Response.json()` throws on an empty body (e.g. 204 or an empty error
109
109
  * payload); this helper mirrors the OK-path guard (`text ? JSON.parse : {}`)
110
110
  * so both the success and the error branches handle empty bodies the same way.
111
+ *
112
+ * A body that is present but is not JSON — a gateway's HTML page in front of a
113
+ * 502, the platform's own admin page (CMS-957) — used to collapse into `{}`,
114
+ * which carries no `statusCode` and therefore does not read as an error at all:
115
+ * a failed request came back looking like an empty success. It is described
116
+ * instead, keeping the status the server actually sent.
111
117
  * @param {Response} response - The fetch Response to read.
112
- * @returns {Promise<unknown>} Parsed JSON, or an empty object when the body is empty/unparsable.
118
+ * @returns {Promise<unknown>} Parsed JSON, `{}` for an empty body, or a described error for a body that is not JSON.
113
119
  */
114
120
  private _parseJson;
115
121
  /**
@@ -120,4 +126,42 @@ export default abstract class AsyncModules extends SyncModules {
120
126
  * @description Define an asynchronous method 'browserResponse' that takes a path and options as parameters
121
127
  */
122
128
  private browserResponse;
129
+ /**
130
+ * Describes a response whose body is not the JSON the API is supposed to send.
131
+ *
132
+ * The platform has been seen answering `200 OK` with `content-type: text/html`
133
+ * and the admin page as the body — every content endpoint at once, for minutes
134
+ * (CMS-957). A successful status carrying someone else's body is indistinguishable
135
+ * from a real answer by status alone, and the only symptom used to be
136
+ * `SyntaxError: Unexpected token '<'` from the JSON parser: a message about the
137
+ * SDK's own parsing rather than about what the platform did. Callers read that as
138
+ * "this record does not exist" and a static build baked 404s over live products.
139
+ *
140
+ * The returned error names the received content type, the HTTP status and the
141
+ * first characters of the body, so a log line says what arrived instead of JSON.
142
+ * `statusCode` stays `0` — the request produced no usable answer, the same
143
+ * contract as a dropped connection, and a value no HTTP answer uses.
144
+ * @param {Response} response - The response whose body could not be parsed.
145
+ * @param {string} text - The raw body as read.
146
+ * @returns {IError} The error in the shape the SDK returns for platform errors.
147
+ */
148
+ private _nonJsonError;
149
+ /**
150
+ * Turns whatever was thrown into the error shape the SDK already returns.
151
+ *
152
+ * With `isShell` on, a failure is returned rather than thrown — and a dropped
153
+ * connection throws a `TypeError`, whose `message` and `stack` are not
154
+ * enumerable. Returned as it was, it serializes to `{}` and reads exactly
155
+ * like an empty answer: on the sanbenitocog pilot such a value entered the
156
+ * page cache and was served for minutes after the link came back, and
157
+ * `next build` baked a site of 404s while reporting success (CMS-780).
158
+ *
159
+ * An object that already carries a `statusCode` is the platform's own error
160
+ * and is passed through untouched. Everything else becomes
161
+ * `{ statusCode: 0, message, pageData: null, timestamp }` — `statusCode: 0`
162
+ * says "the request never reached the platform", which no HTTP answer uses.
163
+ * @param {unknown} e - Whatever the try block threw.
164
+ * @returns {IError} The error in the shape the SDK returns for platform errors.
165
+ */
166
+ private _toShellError;
123
167
  }
@@ -201,8 +201,14 @@ export default class AsyncModules extends SyncModules {
201
201
  });
202
202
  // Check if the response status is OK (status code 200-299)
203
203
  if (response.ok) {
204
- // Parse the response body as JSON and store the result
205
- const result = await response.json();
204
+ // Parsed through the shared helper rather than `response.json()`: a `200` whose body is
205
+ // not JSON (CMS-957) threw a raw SyntaxError out of the refresh and took the request that
206
+ // triggered it with it. A body without tokens is a failed refresh, reported as such.
207
+ const result = await this._parseJson(response);
208
+ if (typeof (result === null || result === void 0 ? void 0 : result.refreshToken) !== 'string' ||
209
+ typeof (result === null || result === void 0 ? void 0 : result.accessToken) !== 'string') {
210
+ return false;
211
+ }
206
212
  // Update the state's refreshToken and accessToken with the new tokens from the response
207
213
  this.state.refreshToken = result.refreshToken;
208
214
  this.state.accessToken = result.accessToken;
@@ -275,22 +281,37 @@ export default class AsyncModules extends SyncModules {
275
281
  return options;
276
282
  }
277
283
  /**
278
- * Reads a response body as JSON, tolerating an empty body.
284
+ * Reads an error response body as JSON, tolerating an empty body.
279
285
  *
280
286
  * `Response.json()` throws on an empty body (e.g. 204 or an empty error
281
287
  * payload); this helper mirrors the OK-path guard (`text ? JSON.parse : {}`)
282
288
  * so both the success and the error branches handle empty bodies the same way.
289
+ *
290
+ * A body that is present but is not JSON — a gateway's HTML page in front of a
291
+ * 502, the platform's own admin page (CMS-957) — used to collapse into `{}`,
292
+ * which carries no `statusCode` and therefore does not read as an error at all:
293
+ * a failed request came back looking like an empty success. It is described
294
+ * instead, keeping the status the server actually sent.
283
295
  * @param {Response} response - The fetch Response to read.
284
- * @returns {Promise<unknown>} Parsed JSON, or an empty object when the body is empty/unparsable.
296
+ * @returns {Promise<unknown>} Parsed JSON, `{}` for an empty body, or a described error for a body that is not JSON.
285
297
  */
286
298
  async _parseJson(response) {
299
+ let text;
287
300
  try {
288
- const text = await response.text();
289
- return text ? JSON.parse(text) : {};
301
+ text = await response.text();
290
302
  }
291
303
  catch {
292
304
  return {};
293
305
  }
306
+ if (!text) {
307
+ return {};
308
+ }
309
+ try {
310
+ return JSON.parse(text);
311
+ }
312
+ catch {
313
+ return this._nonJsonError(response, text);
314
+ }
294
315
  }
295
316
  /**
296
317
  * Handles responses from the browser's fetch API.
@@ -348,10 +369,18 @@ export default class AsyncModules extends SyncModules {
348
369
  // Check if the response status is OK (status code 200-299)
349
370
  if (response.ok) {
350
371
  // Read the body as text; if it is empty return an empty object,
351
- // otherwise parse it as JSON. A parse failure propagates to the
352
- // catch below and is handled according to isShell.
372
+ // otherwise parse it as JSON. A body that is not JSON is turned into a
373
+ // described error by `_nonJsonError` and handled according to isShell.
353
374
  const text = await response.text();
354
- return (text ? JSON.parse(text) : {});
375
+ if (!text) {
376
+ return {};
377
+ }
378
+ try {
379
+ return JSON.parse(text);
380
+ }
381
+ catch {
382
+ throw this._nonJsonError(response, text);
383
+ }
355
384
  }
356
385
  // Handle non-OK responses (applies to the first response and to a failed retry).
357
386
  const status = response.status;
@@ -372,11 +401,78 @@ export default class AsyncModules extends SyncModules {
372
401
  // Handle any errors that occur during the fetch process
373
402
  // Determine whether to return or throw the error based on 'isShell' state
374
403
  if (this.state.isShell) {
375
- return e;
404
+ return this._toShellError(e);
376
405
  }
377
406
  else {
378
407
  throw e;
379
408
  }
380
409
  }
381
410
  }
411
+ /**
412
+ * Describes a response whose body is not the JSON the API is supposed to send.
413
+ *
414
+ * The platform has been seen answering `200 OK` with `content-type: text/html`
415
+ * and the admin page as the body — every content endpoint at once, for minutes
416
+ * (CMS-957). A successful status carrying someone else's body is indistinguishable
417
+ * from a real answer by status alone, and the only symptom used to be
418
+ * `SyntaxError: Unexpected token '<'` from the JSON parser: a message about the
419
+ * SDK's own parsing rather than about what the platform did. Callers read that as
420
+ * "this record does not exist" and a static build baked 404s over live products.
421
+ *
422
+ * The returned error names the received content type, the HTTP status and the
423
+ * first characters of the body, so a log line says what arrived instead of JSON.
424
+ * `statusCode` stays `0` — the request produced no usable answer, the same
425
+ * contract as a dropped connection, and a value no HTTP answer uses.
426
+ * @param {Response} response - The response whose body could not be parsed.
427
+ * @param {string} text - The raw body as read.
428
+ * @returns {IError} The error in the shape the SDK returns for platform errors.
429
+ */
430
+ _nonJsonError(response, text) {
431
+ var _a, _b, _c;
432
+ const contentType = (_c = (_b = (_a = response.headers) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, 'content-type')) !== null && _c !== void 0 ? _c : 'unknown';
433
+ const excerpt = text.trim().slice(0, 120).replace(/\s+/g, ' ');
434
+ return {
435
+ // A successful status carrying a non-JSON body produced no usable answer, the same
436
+ // contract as a dropped connection. A failing one already says something true about
437
+ // the request, so that status is kept.
438
+ statusCode: response.ok ? 0 : response.status,
439
+ message: `Expected JSON from the platform, received ${contentType} ` +
440
+ `(HTTP ${response.status}): ${excerpt}`,
441
+ pageData: null,
442
+ timestamp: new Date().toISOString(),
443
+ };
444
+ }
445
+ /**
446
+ * Turns whatever was thrown into the error shape the SDK already returns.
447
+ *
448
+ * With `isShell` on, a failure is returned rather than thrown — and a dropped
449
+ * connection throws a `TypeError`, whose `message` and `stack` are not
450
+ * enumerable. Returned as it was, it serializes to `{}` and reads exactly
451
+ * like an empty answer: on the sanbenitocog pilot such a value entered the
452
+ * page cache and was served for minutes after the link came back, and
453
+ * `next build` baked a site of 404s while reporting success (CMS-780).
454
+ *
455
+ * An object that already carries a `statusCode` is the platform's own error
456
+ * and is passed through untouched. Everything else becomes
457
+ * `{ statusCode: 0, message, pageData: null, timestamp }` — `statusCode: 0`
458
+ * says "the request never reached the platform", which no HTTP answer uses.
459
+ * @param {unknown} e - Whatever the try block threw.
460
+ * @returns {IError} The error in the shape the SDK returns for platform errors.
461
+ */
462
+ _toShellError(e) {
463
+ if (e && typeof e === 'object' && 'statusCode' in e) {
464
+ return e;
465
+ }
466
+ const message = e instanceof Error
467
+ ? `${e.name}: ${e.message}`
468
+ : typeof e === 'string'
469
+ ? e
470
+ : 'Request failed before a response was received';
471
+ return {
472
+ statusCode: 0,
473
+ message,
474
+ pageData: null,
475
+ timestamp: new Date().toISOString(),
476
+ };
477
+ }
382
478
  }
@@ -81,10 +81,17 @@ export default abstract class SyncModules {
81
81
  * 2. **formData localization**: the API expects formData as
82
82
  * `{ "<langCode>": [...fields] }`, but callers pass a flat array or a single object.
83
83
  * The method wraps the data into the required structure.
84
- * If `formData` is absent from the body — return the body as-is (only phoneSMS cleanup applied).
85
- * @param {any} body - The body to normalize.
84
+ * If `formData` is absent from the body — return a copy with only the phoneSMS cleanup applied.
85
+ *
86
+ * **The caller's object is never touched.** Methods that post a body are
87
+ * routinely called with one that is reused — a retry wrapper, two parallel
88
+ * calls, a shared default. Normalizing in place sends the already-wrapped
89
+ * value the second time, it is wrapped again, and the platform answers
90
+ * `400 "formData.en_US[0].marker" is required` about a field the caller
91
+ * never sent (CMS-909).
92
+ * @param {any} body - The body to normalize. Left unchanged.
86
93
  * @param {string} [langCode] - The language code for normalization.
87
- * @returns {any} Normalized body.
94
+ * @returns {any} A normalized copy of the body.
88
95
  */
89
96
  protected _normalizePostBody(body: any, langCode?: string): any;
90
97
  /**
@@ -218,27 +218,38 @@ export default class SyncModules {
218
218
  * 2. **formData localization**: the API expects formData as
219
219
  * `{ "<langCode>": [...fields] }`, but callers pass a flat array or a single object.
220
220
  * The method wraps the data into the required structure.
221
- * If `formData` is absent from the body — return the body as-is (only phoneSMS cleanup applied).
222
- * @param {any} body - The body to normalize.
221
+ * If `formData` is absent from the body — return a copy with only the phoneSMS cleanup applied.
222
+ *
223
+ * **The caller's object is never touched.** Methods that post a body are
224
+ * routinely called with one that is reused — a retry wrapper, two parallel
225
+ * calls, a shared default. Normalizing in place sends the already-wrapped
226
+ * value the second time, it is wrapped again, and the platform answers
227
+ * `400 "formData.en_US[0].marker" is required` about a field the caller
228
+ * never sent (CMS-909).
229
+ * @param {any} body - The body to normalize. Left unchanged.
223
230
  * @param {string} [langCode] - The language code for normalization.
224
- * @returns {any} Normalized body.
231
+ * @returns {any} A normalized copy of the body.
225
232
  */
226
233
  _normalizePostBody(body, langCode = this.state.lang) {
227
- // API does not accept phoneSMS = '' — delete the field if empty.
228
- if (body.notificationData && body.notificationData.phoneSMS === '') {
229
- delete body.notificationData.phoneSMS;
234
+ const next = { ...body };
235
+ // API does not accept phoneSMS = '' — drop the field if empty. `notificationData`
236
+ // is copied too: deleting the key on the original would reach the caller.
237
+ if (next.notificationData && next.notificationData.phoneSMS === '') {
238
+ next.notificationData = { ...next.notificationData };
239
+ delete next.notificationData.phoneSMS;
230
240
  }
231
241
  // If formData is not provided — no further normalization needed.
232
- if (!body.formData)
233
- return body;
242
+ if (!next.formData)
243
+ return next;
234
244
  // Wrap form fields in an object keyed by locale:
235
245
  // [{ marker, value }] → { "en_US": [{ marker, value }] }
236
- const formData = {};
237
- formData[langCode] = Array.isArray(body.formData)
238
- ? body.formData
239
- : [body.formData];
240
- body.formData = formData;
241
- return body;
246
+ // The fields themselves are reused by reference — they are not modified.
247
+ next.formData = {
248
+ [langCode]: Array.isArray(next.formData)
249
+ ? next.formData
250
+ : [next.formData],
251
+ };
252
+ return next;
242
253
  }
243
254
  /**
244
255
  * Normalizes the value of a single attribute in place.
@@ -1,7 +1,7 @@
1
1
  import AsyncModules from '../base/asyncModules.js';
2
2
  import type StateModule from '../base/stateModule.js';
3
3
  import type { IError } from '../base/utils.js';
4
- import type { IBonusBalanceEntity, IBonusTransactionEntity, IBonusTransactionType, ICouponValidationResult, IDiscountsApi, IDiscountsEntity, IDiscountsResponse, IDiscountsVectorSearch, IDiscountType } from './discountsInterfaces.js';
4
+ import type { IBonusBalanceEntity, IBonusHistoryResponse, IBonusTransactionType, ICouponValidationResult, IDiscountsApi, IDiscountsEntity, IDiscountsResponse, IDiscountsVectorSearch, IDiscountType } from './discountsInterfaces.js';
5
5
  /**
6
6
  * Controllers for working with events
7
7
  * @handle /api/content/events
@@ -63,11 +63,11 @@ export default class DiscountsApi extends AsyncModules implements IDiscountsApi
63
63
  * @param {number} [discountId] - Discount id filter.
64
64
  * @param {number} [moduleId] - Module id filter.
65
65
  * @param {boolean} [isAdmin] - Admin filter.
66
- * @returns {Promise<IBonusTransactionEntity[] | IError>} Returns array of bonus transactions or an error object.
66
+ * @returns {Promise<IBonusHistoryResponse | IError>} Returns the container with the transactions and their total, or an error object.
67
67
  * @throws {IError} When isShell=false and an error occurs during the fetch
68
68
  * @see {@link https://js-sdk.oneentry.cloud/docs/discounts/getBonusHistory getBonusHistory} documentation.
69
69
  */
70
- getBonusHistory(type?: IBonusTransactionType, dateFrom?: string, dateTo?: string, discountId?: number, moduleId?: number, isAdmin?: boolean): Promise<IBonusTransactionEntity[] | IError>;
70
+ getBonusHistory(type?: IBonusTransactionType, dateFrom?: string, dateTo?: string, discountId?: number, moduleId?: number, isAdmin?: boolean): Promise<IBonusHistoryResponse | IError>;
71
71
  /**
72
72
  * Validate discounts coupon
73
73
  * @handleName validateDiscountsCoupon
@@ -80,7 +80,7 @@ export default class DiscountsApi extends AsyncModules {
80
80
  * @param {number} [discountId] - Discount id filter.
81
81
  * @param {number} [moduleId] - Module id filter.
82
82
  * @param {boolean} [isAdmin] - Admin filter.
83
- * @returns {Promise<IBonusTransactionEntity[] | IError>} Returns array of bonus transactions or an error object.
83
+ * @returns {Promise<IBonusHistoryResponse | IError>} Returns the container with the transactions and their total, or an error object.
84
84
  * @throws {IError} When isShell=false and an error occurs during the fetch
85
85
  * @see {@link https://js-sdk.oneentry.cloud/docs/discounts/getBonusHistory getBonusHistory} documentation.
86
86
  */
@@ -55,10 +55,10 @@ interface IDiscountsApi {
55
55
  * @param {number} [discountId] - Discount id filter.
56
56
  * @param {number} [moduleId] - Module id filter.
57
57
  * @param {boolean} [isAdmin] - Admin filter.
58
- * @returns {Promise<IBonusTransactionEntity[] | IError>} Returns array of bonus transactions or an error object.
58
+ * @returns {Promise<IBonusHistoryResponse | IError>} Returns the container with the transactions and their total, or an error object.
59
59
  * @throws {IError} When isShell=false and an error occurs during the fetch
60
60
  */
61
- getBonusHistory(type?: IBonusTransactionType, dateFrom?: string, dateTo?: string, discountId?: number, moduleId?: number, isAdmin?: boolean): Promise<IBonusTransactionEntity[] | IError>;
61
+ getBonusHistory(type?: IBonusTransactionType, dateFrom?: string, dateTo?: string, discountId?: number, moduleId?: number, isAdmin?: boolean): Promise<IBonusHistoryResponse | IError>;
62
62
  /**
63
63
  * Semantic (vector) search for discounts.
64
64
  * @handleName getDiscountsByVectorSearch
@@ -284,6 +284,18 @@ interface IBonusTransactionEntity {
284
284
  expiresAt?: string;
285
285
  createdAt?: string;
286
286
  }
287
+ /**
288
+ * @interface IBonusHistoryResponse
289
+ * @property {IBonusTransactionEntity[]} items - The transactions of the current page.
290
+ * @property {number} total - How many transactions the filter matches in total.
291
+ * @description Container the bonus history arrives in. The endpoint answers
292
+ * `{ items, total }`, not a bare array — measured on the SDK test stand,
293
+ * 2026-09-28: an account with no transactions answers `{"items":[],"total":0}`.
294
+ */
295
+ interface IBonusHistoryResponse {
296
+ items: IBonusTransactionEntity[];
297
+ total: number;
298
+ }
287
299
  /**
288
300
  * @interface IBonusBalanceEntity
289
301
  * @description Represents the balance of bonus points.
@@ -292,4 +304,4 @@ interface IBonusTransactionEntity {
292
304
  interface IBonusBalanceEntity {
293
305
  balance: number;
294
306
  }
295
- export type { IBonusBalanceEntity, IBonusHistoryQuery, IBonusTransactionEntity, IBonusTransactionType, ICouponEntity, ICouponValidationResult, IDiscountByMarkerQuery, IDiscountCondition, IDiscountsApi, IDiscountsEntity, IDiscountsQuery, IDiscountsResponse, IDiscountsValidateCoupon, IDiscountsVectorSearch, IDiscountType, IDiscountValue, };
307
+ export type { IBonusBalanceEntity, IBonusHistoryQuery, IBonusHistoryResponse, IBonusTransactionEntity, IBonusTransactionType, ICouponEntity, ICouponValidationResult, IDiscountByMarkerQuery, IDiscountCondition, IDiscountsApi, IDiscountsEntity, IDiscountsQuery, IDiscountsResponse, IDiscountsValidateCoupon, IDiscountsVectorSearch, IDiscountType, IDiscountValue, };
@@ -420,6 +420,133 @@ interface IUpdateFormsData {
420
420
  * Contains an array of data form objects with the following values
421
421
  */
422
422
  type FormDataType = IBodyTypeStringNumberFloat | IBodyTypeTimeDate | IBodyTypeText | IBodyTypeTextWithHeader | IBodyTypeImageGroupOfImages | IBodyTypeFile | IBodyTypeRadioButtonList | Record<string, unknown>;
423
+ /**
424
+ * Value shapes accepted by a SUBMISSION (`POST /form-data`).
425
+ *
426
+ * For three field kinds they are not the shapes a page attribute uses, and a
427
+ * body written from the read types is refused. Measured on
428
+ * rwah2o.oneentry.cloud, 2026-09-12 and again 2026-09-28 (CMS-888).
429
+ *
430
+ * `list` takes a list of strings; the `[{ title, value }]` form of a page
431
+ * attribute answers `400 formData's marker '<marker>' value[0] must be a string`.
432
+ *
433
+ * `text` takes a one-element array holding exactly ONE of `plainValue`,
434
+ * `htmlValue` or `mdValue`, and no `params`. The object form answers
435
+ * `400 … value must be an array`, `params` answers `… is not allowed`, and two
436
+ * representations answer `Only one of htmlValue, plainValue or mdValue can be provided`.
437
+ *
438
+ * `spam` takes the captcha event, not the bare token.
439
+ */
440
+ type FormDataPostType = IBodyTypeStringNumberFloat | IBodyTypeTimeDate | IBodyPostTypeText | IBodyPostTypeList | IBodyPostTypeSpam | IBodyTypeTextWithHeader | IBodyTypeImageGroupOfImages | IBodyTypeFile | Record<string, unknown>;
441
+ /**
442
+ * Represents a `list` field of a form SUBMISSION.
443
+ * @interface IBodyPostTypeList
444
+ * @property {string} marker - marker name. Example: "recipient".
445
+ * @property {string} type - Type value. Example: "list".
446
+ * @property {string[]} value - Chosen options as plain strings. Example: ["Tom Hoffart"].
447
+ * @example
448
+ {
449
+ "marker": "recipient",
450
+ "type": "list",
451
+ "value": ["Tom Hoffart"]
452
+ }
453
+ * @description A submission sends the chosen options as strings. The `[{ title, value }]`
454
+ * shape a page attribute stores is refused here with `value[0] must be a string`.
455
+ */
456
+ interface IBodyPostTypeList {
457
+ marker: string;
458
+ type: 'list';
459
+ value: string[];
460
+ }
461
+ /**
462
+ * Represents a `text` field of a form SUBMISSION.
463
+ * @interface IBodyPostTypeText
464
+ * @property {string} marker - marker name. Example: "your_message".
465
+ * @property {string} type - Type value. Example: "text".
466
+ * @property {ITextSubmissionValue[]} value - One-element array holding exactly one representation.
467
+ * @example
468
+ {
469
+ "marker": "your_message",
470
+ "type": "text",
471
+ "value": [{ "plainValue": "Hello" }]
472
+ }
473
+ * @description The array holds one object carrying exactly one of `plainValue`,
474
+ * `htmlValue` or `mdValue`. Editor `params` are refused, and so is sending two
475
+ * representations at once.
476
+ */
477
+ interface IBodyPostTypeText {
478
+ marker: string;
479
+ type: 'text';
480
+ value: ITextSubmissionValue[];
481
+ }
482
+ /**
483
+ * @interface ITextSubmissionValuePlain
484
+ * @property {string} plainValue - Plain-text representation. Example: "Hello".
485
+ * @description Plain-text branch of a submitted text value.
486
+ */
487
+ interface ITextSubmissionValuePlain {
488
+ plainValue: string;
489
+ }
490
+ /**
491
+ * @interface ITextSubmissionValueHtml
492
+ * @property {string} htmlValue - HTML representation. Example: "<p>Hello</p>".
493
+ * @description HTML branch of a submitted text value.
494
+ */
495
+ interface ITextSubmissionValueHtml {
496
+ htmlValue: string;
497
+ }
498
+ /**
499
+ * @interface ITextSubmissionValueMd
500
+ * @property {string} mdValue - Markdown representation. Must not be empty. Example: "**Hello**".
501
+ * @description Markdown branch of a submitted text value.
502
+ */
503
+ interface ITextSubmissionValueMd {
504
+ mdValue: string;
505
+ }
506
+ /**
507
+ * Exactly one representation of a submitted text value.
508
+ */
509
+ type ITextSubmissionValue = ITextSubmissionValuePlain | ITextSubmissionValueHtml | ITextSubmissionValueMd;
510
+ /**
511
+ * Represents a `spam` (captcha) field of a form SUBMISSION.
512
+ * @interface IBodyPostTypeSpam
513
+ * @property {string} marker - marker name. Example: "spam".
514
+ * @property {string} type - Type value. Example: "spam".
515
+ * @property {ICaptchaValue} value - The captcha event, not the bare token.
516
+ * @example
517
+ {
518
+ "marker": "spam",
519
+ "type": "spam",
520
+ "value": { "event": { "token": "<reCAPTCHA v3 token>", "siteKey": "6Ldjk7Yt…" } }
521
+ }
522
+ * @description The field carries a reCAPTCHA v3 token obtained in the browser.
523
+ * A bare string is refused with the same sentence as a wrong token —
524
+ * `Captcha Validation Failed, captcha type is: google` — so a malformed value
525
+ * is indistinguishable from a bot.
526
+ */
527
+ interface IBodyPostTypeSpam {
528
+ marker: string;
529
+ type: 'spam';
530
+ value: ICaptchaValue;
531
+ }
532
+ /**
533
+ * @interface ICaptchaEvent
534
+ * @property {string} token - The token issued by the captcha provider in the browser.
535
+ * @property {string} siteKey - The site key the token was issued for. Example: "6Ldjk7Yt…".
536
+ * @description The captcha payload of a `spam` field.
537
+ */
538
+ interface ICaptchaEvent {
539
+ token: string;
540
+ siteKey: string;
541
+ }
542
+ /**
543
+ * @interface ICaptchaValue
544
+ * @property {ICaptchaEvent} event - The captcha payload.
545
+ * @description Wrapper the platform expects around the captcha payload.
546
+ */
547
+ interface ICaptchaValue {
548
+ event: ICaptchaEvent;
549
+ }
423
550
  /**
424
551
  * Represents the structure of the body for posting form data.
425
552
  * @interface IBodyPostFormData
@@ -428,7 +555,7 @@ type FormDataType = IBodyTypeStringNumberFloat | IBodyTypeTimeDate | IBodyTypeTe
428
555
  * @property {string} moduleEntityIdentifier - Text identifier (marker) of the module entity. Example: "blog".
429
556
  * @property {string | null} replayTo - Email to reply to. Example: "some@email.com".
430
557
  * @property {string} status - Status of the form. Example: "sent".
431
- * @property {FormDataType[]} formData - Array of form data objects.
558
+ * @property {FormDataPostType[]} formData - Array of form data objects. A submission's value shapes differ from the read shapes — see FormDataPostType.
432
559
  * @example
433
560
  [
434
561
  {
@@ -455,7 +582,7 @@ interface IBodyPostFormData {
455
582
  moduleEntityIdentifier: string;
456
583
  replayTo: string | null;
457
584
  status: string;
458
- formData: FormDataType[];
585
+ formData: FormDataPostType[];
459
586
  fileQuery?: IUploadingQuery;
460
587
  }
461
588
  /**
@@ -711,4 +838,4 @@ interface IListOptionValue {
711
838
  value: string;
712
839
  extended: IListOptionExtended;
713
840
  }
714
- export type { FormDataStatus, FormDataType, IBodyPostFormData, IBodyTypeFile, IBodyTypeImageGroupOfImages, IBodyTypeRadioButtonList, IBodyTypeStringNumberFloat, IBodyTypeText, IBodyTypeTextWithHeader, IBodyTypeTimeDate, IFileValue, IFormByMarkerDataEntity, IFormDataEntity, IFormDataSearchEntity, IFormsByMarkerDataEntity, IFormsData, IFormsDataEntity, IFormsDataFilter, IFormsDataSearchResponse, IFormsDataVectorSearch, IImageValue, IImageValueParams, IListOptionExtended, IListOptionValue, IPostFormResponse, IPostFormResponseData, ITextEditorParams, ITextValue, ITextWithHeaderValue, ITimeDateValue, IUpdateFormsData, };
841
+ export type { FormDataPostType, FormDataStatus, FormDataType, IBodyPostFormData, IBodyPostTypeList, IBodyPostTypeSpam, IBodyPostTypeText, IBodyTypeFile, IBodyTypeImageGroupOfImages, IBodyTypeRadioButtonList, IBodyTypeStringNumberFloat, IBodyTypeText, IBodyTypeTextWithHeader, IBodyTypeTimeDate, ICaptchaEvent, ICaptchaValue, IFileValue, IFormByMarkerDataEntity, IFormDataEntity, IFormDataSearchEntity, IFormsByMarkerDataEntity, IFormsData, IFormsDataEntity, IFormsDataFilter, IFormsDataSearchResponse, IFormsDataVectorSearch, IImageValue, IImageValueParams, IListOptionExtended, IListOptionValue, IPostFormResponse, IPostFormResponseData, ITextEditorParams, ITextSubmissionValue, ITextValue, ITextWithHeaderValue, ITimeDateValue, IUpdateFormsData, };
@@ -26,10 +26,11 @@ export default class SearchApi extends AsyncModules implements ISearchApi {
26
26
  * @param {'all' | 'visible' | 'hidden'} [visibility] - Visibility filter of the searched records. Default: "all".
27
27
  * @param {number} [offset] - Drilldown mode offset. Pass it only together with a single accessible type in `types`.
28
28
  * @param {number} [limit] - Drilldown mode page size. Pass it only together with a single accessible type in `types`, otherwise the API answers 400 "Drilldown mode (limit/offset) requires exactly one accessible type in `types`". Without it every group is returned in full.
29
+ * @param {string} [langCode] - Language code. Default: "en_US". The search index is per language: a word of a second locale is found only when its own langCode is sent (CMS-912).
29
30
  * @returns {Promise<IGlobalSearchResponse | IError>} Returns the query and the found records grouped by entity type.
30
31
  * @throws {IError} When isShell=false and an error occurs during the fetch
31
- * @description Searches names and attribute values of visible records across entity types.
32
+ * @description Searches names and attribute values of visible records across entity types. The index is per language — the request carries `langCode`, so a bilingual project finds a word of either locale.
32
33
  * @see {@link https://js-sdk.oneentry.cloud/docs/search/globalSearch globalSearch} documentation.
33
34
  */
34
- globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number): Promise<IGlobalSearchResponse | IError>;
35
+ globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number, langCode?: string): Promise<IGlobalSearchResponse | IError>;
35
36
  }
@@ -26,19 +26,23 @@ export default class SearchApi extends AsyncModules {
26
26
  * @param {'all' | 'visible' | 'hidden'} [visibility] - Visibility filter of the searched records. Default: "all".
27
27
  * @param {number} [offset] - Drilldown mode offset. Pass it only together with a single accessible type in `types`.
28
28
  * @param {number} [limit] - Drilldown mode page size. Pass it only together with a single accessible type in `types`, otherwise the API answers 400 "Drilldown mode (limit/offset) requires exactly one accessible type in `types`". Without it every group is returned in full.
29
+ * @param {string} [langCode] - Language code. Default: "en_US". The search index is per language: a word of a second locale is found only when its own langCode is sent (CMS-912).
29
30
  * @returns {Promise<IGlobalSearchResponse | IError>} Returns the query and the found records grouped by entity type.
30
31
  * @throws {IError} When isShell=false and an error occurs during the fetch
31
- * @description Searches names and attribute values of visible records across entity types.
32
+ * @description Searches names and attribute values of visible records across entity types. The index is per language — the request carries `langCode`, so a bilingual project finds a word of either locale.
32
33
  * @see {@link https://js-sdk.oneentry.cloud/docs/search/globalSearch globalSearch} documentation.
33
34
  */
34
- async globalSearch(query, types, visibility, offset, limit) {
35
+ async globalSearch(query, types, visibility, offset, limit, langCode = this.state.lang) {
35
36
  // `types` is sent comma-separated — the array stringifies to exactly that.
37
+ // `langCode` is not optional decoration: the index is per language, and
38
+ // without it a word of a second locale answers an empty group (CMS-912).
36
39
  const params = {
37
40
  q: query,
38
41
  types,
39
42
  visibility,
40
43
  offset,
41
44
  limit,
45
+ langCode,
42
46
  };
43
47
  const data = await this._fetchGet(`?` + this._queryParamsToString(params));
44
48
  const validated = await this._validateResponse(data, schema('GlobalSearchResponseSchema'));
@@ -13,11 +13,12 @@ interface ISearchApi {
13
13
  * @param {'all' | 'visible' | 'hidden'} [visibility] - Visibility filter of the searched records. Default: "all".
14
14
  * @param {number} [offset] - Drilldown mode offset. Pass it only together with a single accessible type in `types`.
15
15
  * @param {number} [limit] - Drilldown mode page size. Pass it only together with a single accessible type in `types`, otherwise the API answers 400 "Drilldown mode (limit/offset) requires exactly one accessible type in `types`". Without it every group is returned in full.
16
+ * @param {string} [langCode] - Language code. Default: "en_US". The search index is per language: a word of a second locale is found only when its own langCode is sent (CMS-912).
16
17
  * @returns {Promise<IGlobalSearchResponse | IError>} Returns the query and the found records grouped by entity type.
17
18
  * @throws {IError} When isShell=false and an error occurs during the fetch
18
- * @description Searches names and attribute values of visible records across entity types.
19
+ * @description Searches names and attribute values of visible records across entity types. The index is per language — the request carries `langCode`, so a bilingual project finds a word of either locale.
19
20
  */
20
- globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number): Promise<IGlobalSearchResponse | IError>;
21
+ globalSearch(query: string, types?: TGlobalSearchEntityType[], visibility?: 'all' | 'visible' | 'hidden', offset?: number, limit?: number, langCode?: string): Promise<IGlobalSearchResponse | IError>;
21
22
  }
22
23
  /**
23
24
  * Entity type a global search group or item belongs to.