oneentry 1.0.157 → 1.0.159
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 +20 -0
- package/changelog.md +89 -0
- package/dist/admins/adminsApi.js +36 -2
- package/dist/attribute-sets/attributeSetsApi.d.ts +2 -2
- package/dist/attribute-sets/attributeSetsApi.js +40 -6
- package/dist/attribute-sets/attributeSetsInterfaces.d.ts +19 -7
- package/dist/auth-provider/authProviderApi.js +38 -4
- package/dist/base/asyncModules.d.ts +6 -4
- package/dist/base/asyncModules.js +44 -8
- package/dist/base/syncModules.d.ts +2 -1
- package/dist/base/syncModules.js +10 -1
- package/dist/base/timeIntervals.js +6 -5
- package/dist/base/utils.d.ts +12 -8
- package/dist/blocks/blocksApi.d.ts +21 -21
- package/dist/blocks/blocksApi.js +48 -14
- package/dist/blocks/blocksInterfaces.d.ts +20 -20
- package/dist/blocks/blocksSchemas.d.ts +2 -0
- package/dist/discounts/discountsInterfaces.d.ts +4 -4
- package/dist/events/eventsApi.d.ts +3 -3
- package/dist/events/eventsApi.js +1 -1
- package/dist/events/eventsInterfaces.d.ts +16 -5
- package/dist/file-uploading/fileUploadingApi.js +36 -2
- package/dist/filters/filtersApi.js +36 -2
- package/dist/forms/formsApi.js +37 -3
- package/dist/forms/formsInterfaces.d.ts +22 -20
- package/dist/forms-data/formsDataApi.js +38 -4
- package/dist/general-types/generalTypesApi.js +36 -2
- package/dist/index.d.ts +2 -2
- package/dist/integration-collections/integrationCollectionsApi.js +43 -9
- package/dist/locales/localesApi.js +36 -2
- package/dist/menus/menusApi.js +36 -2
- package/dist/orders/ordersApi.js +39 -5
- package/dist/orders/ordersInterfaces.d.ts +11 -3
- package/dist/pages/pagesApi.js +42 -8
- package/dist/payments/paymentsApi.js +39 -5
- package/dist/product-statuses/productStatusesApi.js +38 -4
- package/dist/products/productsApi.d.ts +2 -2
- package/dist/products/productsApi.js +42 -8
- package/dist/products/productsInterfaces.d.ts +23 -15
- package/dist/products/productsSchemas.d.ts +1 -0
- package/dist/products/productsSchemas.js +1 -0
- package/dist/subscriptions/subscriptionsApi.js +38 -4
- package/dist/templates/templatesApi.js +38 -4
- package/dist/templates-preview/templatesPreviewApi.js +37 -3
- package/dist/users/usersApi.js +45 -11
- package/dist/web-socket/wsApi.d.ts +2 -0
- package/dist/web-socket/wsApi.js +47 -10
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -175,12 +175,32 @@ const api = defineOneEntry('your-url', {
|
|
|
175
175
|
})
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
+
## TypeScript Types
|
|
179
|
+
|
|
180
|
+
All public interfaces and types are re-exported from the package root, so deep paths are not needed:
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import type { IAttributeSchemaItem, IAttributeSetsEntity } from 'oneentry'
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The same set is also available from a types-only entry point, if you prefer to keep type imports separate from the runtime import:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import type { IProductsEntity, IUserEntity } from 'oneentry/types'
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Deep imports such as `oneentry/dist/attribute-sets/attributeSetsInterfaces` still work and remain supported.
|
|
193
|
+
|
|
178
194
|
## Optional Features
|
|
179
195
|
|
|
180
196
|
### API Response Validation
|
|
181
197
|
|
|
182
198
|
OneEntry SDK supports optional validation of API responses using Zod. This feature is disabled by default and can be enabled for development or critical operations.
|
|
183
199
|
|
|
200
|
+
Zod and the response schemas are loaded on demand, the first time a response actually has to be validated. Leaving validation off — the default — keeps them out of the code your app loads. Socket.io is deferred the same way, until the first `WS.connect()`.
|
|
201
|
+
|
|
202
|
+
Together that means a project calling a single SDK method loads about **43 kB minified (9.7 kB gzip)** instead of 536 kB, with Zod, the schemas and Socket.io landing in chunks that are never requested. The SDK is published as both CommonJS and ESM (`sideEffects: false`), so bundlers can tree-shake the rest.
|
|
203
|
+
|
|
184
204
|
### Time Intervals
|
|
185
205
|
|
|
186
206
|
Attributes of type `timeInterval` return a compact recurrence rule (an anchor date, daily time ranges and repeat flags), not a ready list of slots. The SDK does not expand it eagerly — a single attribute can materialize into megabytes of slots — so resolve it on demand with `expandAttributeTimeIntervals`, passing the window you actually render:
|
package/changelog.md
CHANGED
|
@@ -1,5 +1,94 @@
|
|
|
1
1
|
# SDK Change Log
|
|
2
2
|
|
|
3
|
+
## v.1.0.159
|
|
4
|
+
|
|
5
|
+
### What's New
|
|
6
|
+
|
|
7
|
+
- All public types are now re-exported from the package root and from a new `oneentry/types` entry point, so deep paths are no longer required:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// before
|
|
11
|
+
import type { IAttributeSchemaItem, IAttributeSetsEntity } from 'oneentry/dist/attribute-sets/attributeSetsInterfaces';
|
|
12
|
+
|
|
13
|
+
// now — either of these
|
|
14
|
+
import type { IAttributeSchemaItem, IAttributeSetsEntity } from 'oneentry';
|
|
15
|
+
import type { IAttributeSchemaItem, IAttributeSetsEntity } from 'oneentry/types';
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Every interface and type of every module (`base/utils` included) is available under both entry points. Old `oneentry/dist/<module>/<module>Interfaces` imports keep working — nothing is removed.
|
|
19
|
+
|
|
20
|
+
- The package now ships an ESM build alongside the CommonJS one (`"module": "esm/index.js"`, `"sideEffects": false`), so bundlers can tree-shake the SDK. Node keeps resolving the CommonJS build through `"main"` — there is no `"exports"` map, so every existing deep import resolves exactly as before.
|
|
21
|
+
|
|
22
|
+
### What's Changed
|
|
23
|
+
|
|
24
|
+
- **Zod is no longer part of the import graph unless validation is enabled.** Response schemas used to be imported statically by every `*Api` module, which pulled Zod into every consumer's bundle even though `validation.enabled` defaults to `false`. Schemas and the validation helpers are now loaded on demand, the first time a response actually has to be validated.
|
|
25
|
+
|
|
26
|
+
For a project that calls a single method and leaves validation off, the code that actually loads drops from **536 kB to 83 kB** minified (110 kB → 22 kB gzip): Zod and the per-module schemas (341 kB) end up in chunks that are never requested. That figure assumes a bundler doing code splitting — the default in webpack, Vite and Rollup. A bundle forced into a single file still shrinks, but only to ~427 kB, since Zod is then inlined even though it never runs.
|
|
27
|
+
|
|
28
|
+
With `validation.enabled: true` the behaviour is unchanged; the schemas are simply fetched when first needed. In Node, `require('oneentry')` no longer loads Zod at startup either.
|
|
29
|
+
|
|
30
|
+
No public API changed. The internal `_validateResponse` helper became `async` — relevant only if you extended the SDK's base classes yourself.
|
|
31
|
+
|
|
32
|
+
- **Socket.io is no longer bundled unless you open a socket.** `WS.connect()` keeps its synchronous signature and still returns a `Socket`, but `socket.io-client` (~41 kB) is now imported the first time `connect()` is called. Until the chunk resolves, the returned object queues whatever you do with it — `on`, `emit`, `disconnect` — and replays it onto the real socket in the same tick it is created, before the connection can deliver anything, so no event is lost.
|
|
33
|
+
|
|
34
|
+
Reading connection state early stays accurate, because a freshly created socket is not connected either: `id` is `undefined` and `connected` is `false` in both the old and the new behaviour. The one difference: a method that has to *return* something (e.g. `listeners()`) cannot answer before the chunk arrives, and nested objects such as `socket.io` are reachable only once loaded. Registering handlers and emitting — the normal use — is unaffected.
|
|
35
|
+
|
|
36
|
+
Together with the Zod change, a project that calls one method and never opens a socket now loads **43 kB minified (9.7 kB gzip), down from 536 kB (110 kB gzip)**.
|
|
37
|
+
|
|
38
|
+
## v.1.0.158
|
|
39
|
+
|
|
40
|
+
### What's New
|
|
41
|
+
|
|
42
|
+
- Orders > `IOrderStatus` — four fields the API already returns on every status are now declared (all optional, like the rest of the interface): `axis` (status pipeline, e.g. `"payment"`), `isCancelFinal`, `isFinalSuccess`, `isMapped`.
|
|
43
|
+
|
|
44
|
+
- Base > `ILocalizeInfo` — `plainContent?: string | null` is now declared: pages and menus return it as the plain-text counterpart of `htmlContent`.
|
|
45
|
+
|
|
46
|
+
- Events > `IFormSubscriptionsResponse` — new exported type describing the container returned by `getFormSubscriptions`: `{ items: IListFormSubscription[]; total: number }`.
|
|
47
|
+
|
|
48
|
+
- Products > `IProductsResponse` — `totalFound?: number` is now declared (and validated by `ProductsResponseSchema`): block product endpoints (`similarProducts` inside blocks, cart/wishlist recommendations, frequently ordered) return it alongside `items`/`total`; the `Products.getProducts*` endpoints do not, hence optional.
|
|
49
|
+
|
|
50
|
+
- Products > `IProductBlockSimilarRule` — rewritten to match the real shape of `customSettings.similarProductRules[]` returned by `getProductBlockById`: `{ id, title, attributeMarker, conditionMarker, conditionValue, statusMarker, pageUrls }`. The previously declared fields (`property`, `includes`, `keywords`, `strict`) never occurred in real data.
|
|
51
|
+
|
|
52
|
+
- AttributeSets > `IAttributeSchemaItem` — six fields the API already returns on schema items are now declared (all optional):
|
|
53
|
+
- `position` — sort position of the field inside the set;
|
|
54
|
+
- `listTitles` (`IListTitle[]`) — options for `list`/`radioButton`/`entity` fields, with extended data or linked-entity values;
|
|
55
|
+
- `listType` — for `entity` fields, how the option list is organized (e.g. `"nested"`);
|
|
56
|
+
- `moduleIdentifier` — for `entity` fields, the module the linked entities are taken from (e.g. `"catalog"`);
|
|
57
|
+
- `parentId` — parent field id, `null` for top-level;
|
|
58
|
+
- `splitParts` (`number[] | boolean`) — for split-price fields, ids of the schema fields the price is split into, `false` when the field does not split.
|
|
59
|
+
|
|
60
|
+
### What's Changed
|
|
61
|
+
|
|
62
|
+
- **Breaking** — Blocks > the ten recommendation methods (`getCartComplement`, `getCartComplementByProductIds`, `getCartSimilar`, `getCartSimilarByProductIds`, `getWishlistSimilar`, `getWishlistSimilarByProductIds`, `getTrending`, `getPersonalRecommendations`, `getRecentlyViewed`, `getRepeatPurchase`) — the declared return type is corrected from `IProductsEntity[]` to `IProductsResponse`: the endpoints actually return a container `{ items, total, totalFound? }`, and the SDK does not unwrap it. Type-level fix only; the response itself is unchanged — code that (incorrectly) called `res.map(...)` never worked on real data.
|
|
63
|
+
|
|
64
|
+
- **Breaking** — Products > `getProductsByVectorSearch` — the declared return type is corrected from `IProductsEntity[]` to `IProductsResponse`: the endpoint returns `{ items, total }`. Type-level fix only.
|
|
65
|
+
|
|
66
|
+
- **Breaking** — Events > `getFormSubscriptions` — the declared return type is corrected from `IListFormSubscription[]` to the new `IFormSubscriptionsResponse`: the endpoint returns `{ items, total }`. Type-level fix only.
|
|
67
|
+
|
|
68
|
+
- Orders > `IBaseOrdersEntity.totalSum` — type corrected from `string` to `number`: `createOrder` and `updateOrderByMarkerAndId` return a number (e.g. `285`), which the Zod schemas (`CreateOrderResponseSchema` / `UpdateOrderResponseSchema`) already declared. `IOrderByMarkerEntity.totalSum` stays `string` — the by-marker endpoints really return `"300.00"`.
|
|
69
|
+
|
|
70
|
+
- Forms > `IFormAttribute` — the seven auth/notification flags (`isLogin`, `isSignUp`, `isPassword`, `isSignUpRequired`, `isNotificationEmail`, `isNotificationPhonePush`, `isNotificationPhoneSMS`) are now optional: the API returns them only on attributes of sign-in/sign-up forms.
|
|
71
|
+
|
|
72
|
+
- Forms > `IFormLocalizeInfo` — `title` is now optional: the API returns an empty `localizeInfos` object when the form has no localization for the requested language (all list responses on the test project). Same for attribute localization: Base > `IAttributeLocalizeInfo.title` is now optional too.
|
|
73
|
+
|
|
74
|
+
- Forms > `IFormAttributeAdditionalField.marker` — now optional: entries of `additionalFields` arrive as `{ type, value }`, the marker is the map key.
|
|
75
|
+
|
|
76
|
+
- Forms > a form with no attributes now returns `attributes: []`: the API sends an empty **object** (`{}`) in that case, and the SDK normalizes it to an empty array in `_normalizeAttr`, so `attributes` is always `IFormAttribute[]` and `form.attributes.map(...)` is safe on every form.
|
|
77
|
+
|
|
78
|
+
- Events > `IContentApiEvent.module` — now optional: system events not bound to a module (e.g. `send_code`, `registration_event`) come without it.
|
|
79
|
+
|
|
80
|
+
- Discounts > `IDiscountsEntity.attributeSetId` and `IDiscountValue.maxAmount` — type widened to `number | null`: both arrive as `null` when not configured.
|
|
81
|
+
|
|
82
|
+
- Products > `IProductBlockProductConfig` — `quantity` and `countElementsPerRow` are now optional: `customSettings.productConfig` arrives as an empty object when the block is not configured.
|
|
83
|
+
|
|
84
|
+
- Base > `ITimeIntervalRange.period` — type corrected to `number | null`: ranges that are not sliced into slots carry `period: null`. The runtime (`expandTimeIntervals`) already guarded against it; only the type (and the internal narrowing in `_addSlotsFromRanges`) changed.
|
|
85
|
+
|
|
86
|
+
- AttributeSets > `getAttributesByMarker` — the declared return type is corrected from `IAttributeSetsEntity[]` (the attribute **set** entity: `id`, `schema`, `createdDate`, …) to `IAttributesSetsEntity[]` — the attribute entities the endpoint actually returns (`marker`, `type`, `value`, `listTitles`, `validators`, `localizeInfos`, `additionalFields`, …). Type-level fix only; runtime behavior and the response itself are unchanged.
|
|
87
|
+
|
|
88
|
+
- AttributeSets > `IAttributeSchemaItem` — `initialValue` and `isPrice` are now optional: the API omits them on some fields (`isPrice` is returned only on product attribute sets).
|
|
89
|
+
|
|
90
|
+
- Base > `ITimeIntervalSchedule` — `fullMonth` and `selectedYear` are now optional: the API returns them only when the schedule is pinned to a month/year rather than an explicit date `range`.
|
|
91
|
+
|
|
3
92
|
## v.1.0.157
|
|
4
93
|
|
|
5
94
|
### What's New
|
package/dist/admins/adminsApi.js
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
const asyncModules_1 = __importDefault(require("../base/asyncModules"));
|
|
7
|
-
const
|
|
40
|
+
const lazySchema_1 = __importDefault(require("../base/lazySchema"));
|
|
41
|
+
const schema = (0, lazySchema_1.default)(() => Promise.resolve().then(() => __importStar(require('./adminsSchemas'))));
|
|
8
42
|
/**
|
|
9
43
|
* Controllers for working with users - admins.
|
|
10
44
|
* @class AdminsApi
|
|
@@ -59,7 +93,7 @@ class AdminsApi extends asyncModules_1.default {
|
|
|
59
93
|
};
|
|
60
94
|
const response = await this._fetchPost(`?` + this._queryParamsToString(query), body);
|
|
61
95
|
// Validate response if validation is enabled
|
|
62
|
-
const validated = this._validateResponse(response,
|
|
96
|
+
const validated = await this._validateResponse(response, schema('AdminsResponseSchema'));
|
|
63
97
|
return this._normalizeData(validated, langCode);
|
|
64
98
|
}
|
|
65
99
|
}
|
|
@@ -38,11 +38,11 @@ export default class AttributesSetsApi extends AsyncModules implements IAttribut
|
|
|
38
38
|
* @handleName getAttributesByMarker
|
|
39
39
|
* @param {string} marker - Attribute marker. Example: "productAttributes".
|
|
40
40
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
41
|
-
* @returns {Promise<
|
|
41
|
+
* @returns {Promise<IAttributesSetsEntity[] | IError>} Returns an array of Attributes objects.
|
|
42
42
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
43
43
|
* @see {@link https://js-sdk.oneentry.cloud/docs/attribute-sets/getAttributesByMarker getAttributesByMarker} documentation.
|
|
44
44
|
*/
|
|
45
|
-
getAttributesByMarker(marker: string, langCode?: string): Promise<
|
|
45
|
+
getAttributesByMarker(marker: string, langCode?: string): Promise<IAttributesSetsEntity[] | IError>;
|
|
46
46
|
/**
|
|
47
47
|
* Get a single attribute with data from the attribute sets.
|
|
48
48
|
* @handleName getSingleAttributeByMarkerSet
|
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
const asyncModules_1 = __importDefault(require("../base/asyncModules"));
|
|
7
|
-
const
|
|
40
|
+
const lazySchema_1 = __importDefault(require("../base/lazySchema"));
|
|
41
|
+
const schema = (0, lazySchema_1.default)(() => Promise.resolve().then(() => __importStar(require('./attributeSetsSchemas'))));
|
|
8
42
|
/**
|
|
9
43
|
* Controllers for working with attributes - AttributesSetsApi.
|
|
10
44
|
* @class AttributesSetsApi
|
|
@@ -49,7 +83,7 @@ class AttributesSetsApi extends asyncModules_1.default {
|
|
|
49
83
|
};
|
|
50
84
|
const result = await this._fetchGet(`?` + this._queryParamsToString(query));
|
|
51
85
|
// Validate response if validation is enabled
|
|
52
|
-
const validated = this._validateResponse(result,
|
|
86
|
+
const validated = await this._validateResponse(result, schema('AttributeSetsResponseSchema'));
|
|
53
87
|
return this._normalizeData(validated, langCode);
|
|
54
88
|
}
|
|
55
89
|
/**
|
|
@@ -57,14 +91,14 @@ class AttributesSetsApi extends asyncModules_1.default {
|
|
|
57
91
|
* @handleName getAttributesByMarker
|
|
58
92
|
* @param {string} marker - Attribute marker. Example: "productAttributes".
|
|
59
93
|
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
60
|
-
* @returns {Promise<
|
|
94
|
+
* @returns {Promise<IAttributesSetsEntity[] | IError>} Returns an array of Attributes objects.
|
|
61
95
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
62
96
|
* @see {@link https://js-sdk.oneentry.cloud/docs/attribute-sets/getAttributesByMarker getAttributesByMarker} documentation.
|
|
63
97
|
*/
|
|
64
98
|
async getAttributesByMarker(marker, langCode = this.state.lang) {
|
|
65
99
|
const result = await this._fetchGet(`/${marker}/attributes?langCode=${langCode}`);
|
|
66
100
|
// Validate response if validation is enabled
|
|
67
|
-
const validated = this._validateResponse(result,
|
|
101
|
+
const validated = await this._validateResponse(result, schema('AttributesArrayResponseSchema'));
|
|
68
102
|
return this._normalizeData(validated, langCode);
|
|
69
103
|
}
|
|
70
104
|
/**
|
|
@@ -80,7 +114,7 @@ class AttributesSetsApi extends asyncModules_1.default {
|
|
|
80
114
|
async getSingleAttributeByMarkerSet(setMarker, attributeMarker, langCode = this.state.lang) {
|
|
81
115
|
const result = await this._fetchGet(`/${setMarker}/attributes/${attributeMarker}?langCode=${langCode}`);
|
|
82
116
|
// Validate response if validation is enabled
|
|
83
|
-
const validated = this._validateResponse(result,
|
|
117
|
+
const validated = await this._validateResponse(result, schema('AttributeEntitySchema'));
|
|
84
118
|
return this._normalizeData(validated, langCode);
|
|
85
119
|
}
|
|
86
120
|
/**
|
|
@@ -95,7 +129,7 @@ class AttributesSetsApi extends asyncModules_1.default {
|
|
|
95
129
|
async getAttributeSetByMarker(marker, langCode = this.state.lang) {
|
|
96
130
|
const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
|
|
97
131
|
// Validate response if validation is enabled
|
|
98
|
-
const validated = this._validateResponse(result,
|
|
132
|
+
const validated = await this._validateResponse(result, schema('AttributeSetEntitySchema'));
|
|
99
133
|
return this._normalizeData(validated, langCode);
|
|
100
134
|
}
|
|
101
135
|
}
|
|
@@ -10,11 +10,11 @@ interface IAttributesSets {
|
|
|
10
10
|
* @handleName getAttributesByMarker
|
|
11
11
|
* @param {string} marker - The marker used to identify the attribute set. Example: "productAttributes".
|
|
12
12
|
* @param {string} [langCode] - The language code for localization purposes. Default: 'en_US'.
|
|
13
|
-
* @returns {
|
|
13
|
+
* @returns {IAttributesSetsEntity[]} A promise that resolves to an array of attribute entities or an error.
|
|
14
14
|
* @throws {IError} - If there is an error during the fetch operation, it will return an error object.
|
|
15
15
|
* @description This method fetches attributes by a specific marker.
|
|
16
16
|
*/
|
|
17
|
-
getAttributesByMarker(marker: string, langCode: string): Promise<
|
|
17
|
+
getAttributesByMarker(marker: string, langCode: string): Promise<IAttributesSetsEntity[] | IError>;
|
|
18
18
|
/**
|
|
19
19
|
* Fetches a single attribute by its marker and the set marker.
|
|
20
20
|
* @handleName getSingleAttributeByMarkerSet
|
|
@@ -137,35 +137,47 @@ interface IAttributesSetsEntity {
|
|
|
137
137
|
* @interface IAttributeSchemaItem
|
|
138
138
|
* @property {number} id - Unique identifier of the schema item. Example: 1.
|
|
139
139
|
* @property {string} identifier - Field marker (machine name) within the schema. Example: "name".
|
|
140
|
-
* @property {unknown} initialValue - Default value applied when the field is not filled.
|
|
141
|
-
* @property {boolean} isPrice - Whether the field's numeric value is treated as the price for product entities. Example: false.
|
|
140
|
+
* @property {unknown} [initialValue] - Default value applied when the field is not filled. Optional — absent on some fields.
|
|
141
|
+
* @property {boolean} [isPrice] - Whether the field's numeric value is treated as the price for product entities. Optional — present on product (`forProducts`) attribute sets. Example: false.
|
|
142
142
|
* @property {boolean} isVisible - Whether the field is exposed in the public API/UI. Example: true.
|
|
143
143
|
* @property {IAttributeLocalizeInfo} localizeInfos - Localized labels for the field.
|
|
144
144
|
* @property {boolean} original - Whether the field is part of the original (system) schema, not a user extension. Example: true.
|
|
145
145
|
* @property {AttributeType} type - Attribute data type (e.g. "string", "file").
|
|
146
|
+
* @property {number} [position] - Sort position of the field inside the set. Optional. Example: 1.
|
|
147
|
+
* @property {IListTitle[]} [listTitles] - Options for `list`/`radioButton`/`entity` fields (with extended data or linked-entity values). Optional.
|
|
148
|
+
* @property {string} [listType] - For `entity` fields — how the option list is organized. Optional. Example: "nested".
|
|
149
|
+
* @property {string} [moduleIdentifier] - For `entity` fields — identifier of the module the linked entities are taken from. Optional. Example: "catalog".
|
|
150
|
+
* @property {number | null} [parentId] - Identifier of the parent field, `null` for top-level. Optional, seen on `groupOfImages` fields.
|
|
146
151
|
* @property {Record<string, IAttributeSchemaItem>} [additionalFields] - Nested sub-fields keyed by marker. Optional.
|
|
147
152
|
* @property {IAttributeValidators} [validators] - Validation rules for the field. Optional.
|
|
148
153
|
* @property {boolean | string} [splitUnit] - Splitting unit configuration; `false` when disabled, otherwise the unit name (e.g. "percent"). Optional, used by numeric fields.
|
|
154
|
+
* @property {number[] | boolean} [splitParts] - For split-price fields — ids of the schema fields the price is split into (e.g. [2, 3]); `false` when the field does not split. Optional.
|
|
149
155
|
* @property {boolean} [isCurrency] - Whether the field stores currency values. Optional.
|
|
150
156
|
* @property {boolean} [splitPrice] - Whether the price is split between several fields. Optional.
|
|
151
157
|
* @property {boolean} [isCompress] - Whether uploaded images are compressed. Optional, used by `image`/`groupOfImages` fields.
|
|
152
158
|
* @property {boolean} [receiveValues] - For `timeInterval` fields — whether the field receives precomputed values. Optional.
|
|
153
159
|
* @property {ITimeIntervalSchedule[]} [intervals] - For `timeInterval` fields — top-level schedule definition (separate from `localizeInfos.intervals`). Optional.
|
|
154
|
-
* @property {unknown} [value] -
|
|
160
|
+
* @property {unknown} [value] - Current value of the field: `null` on numeric fields without a value, an array of schedule groups on `timeInterval` fields. Optional.
|
|
155
161
|
* @description Definition of a single field inside an attribute set's schema.
|
|
156
162
|
*/
|
|
157
163
|
interface IAttributeSchemaItem {
|
|
158
164
|
id: number;
|
|
159
165
|
identifier: string;
|
|
160
|
-
initialValue
|
|
161
|
-
isPrice
|
|
166
|
+
initialValue?: unknown;
|
|
167
|
+
isPrice?: boolean;
|
|
162
168
|
isVisible: boolean;
|
|
163
169
|
localizeInfos: IAttributeLocalizeInfo;
|
|
164
170
|
original: boolean;
|
|
165
171
|
type: AttributeType;
|
|
172
|
+
position?: number;
|
|
173
|
+
listTitles?: IListTitle[];
|
|
174
|
+
listType?: string;
|
|
175
|
+
moduleIdentifier?: string;
|
|
176
|
+
parentId?: number | null;
|
|
166
177
|
additionalFields?: Record<string, IAttributeSchemaItem>;
|
|
167
178
|
validators?: IAttributeValidators;
|
|
168
179
|
splitUnit?: boolean | string;
|
|
180
|
+
splitParts?: number[] | boolean;
|
|
169
181
|
isCurrency?: boolean;
|
|
170
182
|
splitPrice?: boolean;
|
|
171
183
|
isCompress?: boolean;
|
|
@@ -1,11 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
/* eslint-disable jsdoc/no-undefined-types */
|
|
7
40
|
const asyncModules_1 = __importDefault(require("../base/asyncModules"));
|
|
8
|
-
const
|
|
41
|
+
const lazySchema_1 = __importDefault(require("../base/lazySchema"));
|
|
42
|
+
const schema = (0, lazySchema_1.default)(() => Promise.resolve().then(() => __importStar(require('./authProviderSchemas'))));
|
|
9
43
|
/**
|
|
10
44
|
* Controllers for working with auth services.
|
|
11
45
|
* @handle /api/content/users-auth-providers
|
|
@@ -93,7 +127,7 @@ class AuthProviderApi extends asyncModules_1.default {
|
|
|
93
127
|
body['langCode'] = langCode;
|
|
94
128
|
const result = await this._fetchPost(`/marker/${marker}/users/sign-up`, this._normalizePostBody(body, langCode));
|
|
95
129
|
// Validate response if validation is enabled
|
|
96
|
-
const validated = this._validateResponse(result,
|
|
130
|
+
const validated = await this._validateResponse(result, schema('SignUpResponseSchema'));
|
|
97
131
|
return this._normalizeData(validated);
|
|
98
132
|
}
|
|
99
133
|
/**
|
|
@@ -191,7 +225,7 @@ class AuthProviderApi extends asyncModules_1.default {
|
|
|
191
225
|
async auth(marker, body) {
|
|
192
226
|
const result = await this._fetchPost(`/marker/${marker}/users/auth`, body);
|
|
193
227
|
// Validate response if validation is enabled
|
|
194
|
-
const validated = this._validateResponse(result,
|
|
228
|
+
const validated = await this._validateResponse(result, schema('AuthResponseSchema'));
|
|
195
229
|
if (!('statusCode' in validated)) {
|
|
196
230
|
this.state.accessToken = validated.accessToken;
|
|
197
231
|
this.state.refreshToken = validated.refreshToken;
|
|
@@ -310,7 +344,7 @@ class AuthProviderApi extends asyncModules_1.default {
|
|
|
310
344
|
async getAuthProviders(langCode = this.state.lang, offset = 0, limit = 30) {
|
|
311
345
|
const result = await this._fetchGet(`?langCode=${langCode}&offset=${offset}&limit=${limit}`);
|
|
312
346
|
// Validate response if validation is enabled
|
|
313
|
-
const validated = this._validateResponse(result,
|
|
347
|
+
const validated = await this._validateResponse(result, schema('AuthProvidersResponseSchema'));
|
|
314
348
|
return this._normalizeData(validated);
|
|
315
349
|
}
|
|
316
350
|
/**
|
|
@@ -29,11 +29,13 @@ export default abstract class AsyncModules extends SyncModules {
|
|
|
29
29
|
/**
|
|
30
30
|
* Validates API response against a Zod schema (optional)
|
|
31
31
|
* @param {unknown} data - The data to validate
|
|
32
|
-
* @param {z.ZodSchema<T
|
|
33
|
-
* @returns {T | IError} Validated data or error object
|
|
34
|
-
* @description Validates response data if validation is enabled in config
|
|
32
|
+
* @param {() => Promise<z.ZodSchema<T>>} [loadSchema] - Optional loader resolving to the Zod schema for validation
|
|
33
|
+
* @returns {Promise<T | IError>} Validated data or error object
|
|
34
|
+
* @description Validates response data if validation is enabled in config.
|
|
35
|
+
* The schema — and Zod itself — are imported on demand, so a project that leaves
|
|
36
|
+
* validation disabled (the default) never pulls Zod into its bundle.
|
|
35
37
|
*/
|
|
36
|
-
protected _validateResponse<T>(data: unknown,
|
|
38
|
+
protected _validateResponse<T>(data: unknown, loadSchema?: () => Promise<z.ZodSchema<T>>): Promise<T | IError>;
|
|
37
39
|
/**
|
|
38
40
|
* Performs an HTTP GET request.
|
|
39
41
|
* @param {string} path - The path to append to the base URL.
|
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
const syncModules_1 = __importDefault(require("./syncModules"));
|
|
7
|
-
const validation_1 = require("./validation");
|
|
8
40
|
/**
|
|
9
41
|
* Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
|
|
10
42
|
* @description Abstract class AsyncModules extends SyncModules to provide asynchronous HTTP request functionalities.
|
|
@@ -43,22 +75,26 @@ class AsyncModules extends syncModules_1.default {
|
|
|
43
75
|
/**
|
|
44
76
|
* Validates API response against a Zod schema (optional)
|
|
45
77
|
* @param {unknown} data - The data to validate
|
|
46
|
-
* @param {z.ZodSchema<T
|
|
47
|
-
* @returns {T | IError} Validated data or error object
|
|
48
|
-
* @description Validates response data if validation is enabled in config
|
|
78
|
+
* @param {() => Promise<z.ZodSchema<T>>} [loadSchema] - Optional loader resolving to the Zod schema for validation
|
|
79
|
+
* @returns {Promise<T | IError>} Validated data or error object
|
|
80
|
+
* @description Validates response data if validation is enabled in config.
|
|
81
|
+
* The schema — and Zod itself — are imported on demand, so a project that leaves
|
|
82
|
+
* validation disabled (the default) never pulls Zod into its bundle.
|
|
49
83
|
*/
|
|
50
|
-
_validateResponse(data,
|
|
84
|
+
async _validateResponse(data, loadSchema) {
|
|
51
85
|
// Skip validation if not enabled or no schema provided
|
|
52
|
-
if (!this.state.validationEnabled || !
|
|
86
|
+
if (!this.state.validationEnabled || !loadSchema) {
|
|
53
87
|
return data;
|
|
54
88
|
}
|
|
55
89
|
// Skip validation for error responses (statusCode indicates API error)
|
|
56
90
|
if (this._isErrorResponse(data)) {
|
|
57
91
|
return data;
|
|
58
92
|
}
|
|
93
|
+
// Pull the schema and the Zod-backed validators only now that they are needed
|
|
94
|
+
const [schema, { validateResponse, validateResponseSafe }] = await Promise.all([loadSchema(), Promise.resolve().then(() => __importStar(require('./validation')))]);
|
|
59
95
|
// Use strict or safe validation based on config
|
|
60
96
|
if (this.state.validationStrictMode) {
|
|
61
|
-
const result =
|
|
97
|
+
const result = validateResponse(schema, data, {
|
|
62
98
|
logErrors: this.state.validationLogErrors,
|
|
63
99
|
});
|
|
64
100
|
if (!result.success) {
|
|
@@ -78,7 +114,7 @@ class AsyncModules extends syncModules_1.default {
|
|
|
78
114
|
}
|
|
79
115
|
else {
|
|
80
116
|
// Non-strict mode: log errors but return original data
|
|
81
|
-
return
|
|
117
|
+
return validateResponseSafe(schema, data, this.state.validationLogErrors);
|
|
82
118
|
}
|
|
83
119
|
}
|
|
84
120
|
/**
|
|
@@ -145,7 +145,8 @@ export default abstract class SyncModules {
|
|
|
145
145
|
*
|
|
146
146
|
* **2. `attributes`** — form attributes, an array (or a marker map on some
|
|
147
147
|
* endpoints); form-only boolean flags (`isLogin`, `isSignUp`, notifications)
|
|
148
|
-
* are additionally coerced from `null` to `false`.
|
|
148
|
+
* are additionally coerced from `null` to `false`. A form with no attributes
|
|
149
|
+
* arrives as an empty object `{}` — it is normalized to an empty array.
|
|
149
150
|
*
|
|
150
151
|
* **3. `type`** — a standalone attribute: an attribute-set entry, a form-data
|
|
151
152
|
* field or a nested `additionalFields` entry. Same transformations, but there
|
package/dist/base/syncModules.js
CHANGED
|
@@ -313,7 +313,8 @@ class SyncModules {
|
|
|
313
313
|
*
|
|
314
314
|
* **2. `attributes`** — form attributes, an array (or a marker map on some
|
|
315
315
|
* endpoints); form-only boolean flags (`isLogin`, `isSignUp`, notifications)
|
|
316
|
-
* are additionally coerced from `null` to `false`.
|
|
316
|
+
* are additionally coerced from `null` to `false`. A form with no attributes
|
|
317
|
+
* arrives as an empty object `{}` — it is normalized to an empty array.
|
|
317
318
|
*
|
|
318
319
|
* **3. `type`** — a standalone attribute: an attribute-set entry, a form-data
|
|
319
320
|
* field or a nested `additionalFields` entry. Same transformations, but there
|
|
@@ -351,6 +352,14 @@ class SyncModules {
|
|
|
351
352
|
// for forms attributes - forms attributes collections
|
|
352
353
|
if ('attributes' in data) {
|
|
353
354
|
const d = data.attributes;
|
|
355
|
+
// A form with no attributes arrives as an empty object `{}` — normalize
|
|
356
|
+
// it to an empty array, the container every non-empty form uses.
|
|
357
|
+
if (d &&
|
|
358
|
+
typeof d === 'object' &&
|
|
359
|
+
!Array.isArray(d) &&
|
|
360
|
+
Object.keys(d).length === 0) {
|
|
361
|
+
return { ...data, attributes: [] };
|
|
362
|
+
}
|
|
354
363
|
Object.keys(d).forEach((attr) => {
|
|
355
364
|
this._normalizeAdditionalFields(d[attr]);
|
|
356
365
|
this._normalizeAttrValue(d[attr]);
|
|
@@ -136,13 +136,14 @@ function _addSlotsFromRanges(day, ranges, out) {
|
|
|
136
136
|
const endMinutes = _toMinutes(range === null || range === void 0 ? void 0 : range.end);
|
|
137
137
|
if (startMinutes === null || endMinutes === null)
|
|
138
138
|
return;
|
|
139
|
-
// A non-positive period would never advance the cursor; a
|
|
140
|
-
// would concatenate into it.
|
|
141
|
-
|
|
139
|
+
// A non-positive period would never advance the cursor; a null or
|
|
140
|
+
// non-numeric one would concatenate into it.
|
|
141
|
+
const period = range === null || range === void 0 ? void 0 : range.period;
|
|
142
|
+
if (typeof period !== 'number' || !Number.isFinite(period) || period <= 0)
|
|
142
143
|
return;
|
|
143
|
-
for (let minutes = startMinutes; minutes +
|
|
144
|
+
for (let minutes = startMinutes; minutes + period <= endMinutes; minutes += period) {
|
|
144
145
|
const from = day + minutes * _MS_PER_MINUTE;
|
|
145
|
-
const to = day + (minutes +
|
|
146
|
+
const to = day + (minutes + period) * _MS_PER_MINUTE;
|
|
146
147
|
out.push([new Date(from).toISOString(), new Date(to).toISOString()]);
|
|
147
148
|
}
|
|
148
149
|
});
|