oneentry 1.0.162 → 1.0.163

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +18 -0
  2. package/changelog.md +59 -0
  3. package/dist/admins/adminsSchemas.d.ts +6 -22
  4. package/dist/admins/adminsSchemas.js +2 -9
  5. package/dist/attribute-sets/attributeSetsInterfaces.d.ts +6 -6
  6. package/dist/auth-provider/authProvidersInterfaces.d.ts +4 -4
  7. package/dist/base/attributes.d.ts +105 -0
  8. package/dist/base/attributes.js +172 -0
  9. package/dist/base/utils.d.ts +95 -2
  10. package/dist/base/validation.d.ts +29 -0
  11. package/dist/base/validation.js +93 -1
  12. package/dist/blocks/blocksInterfaces.d.ts +1 -1
  13. package/dist/blocks/blocksSchemas.d.ts +6 -6
  14. package/dist/blocks/blocksSchemas.js +2 -1
  15. package/dist/discounts/discountsInterfaces.d.ts +1 -1
  16. package/dist/forms-data/formsDataApi.d.ts +16 -6
  17. package/dist/forms-data/formsDataApi.js +14 -4
  18. package/dist/forms-data/formsDataInterfaces.d.ts +48 -15
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.js +9 -1
  21. package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +6 -6
  22. package/dist/menus/menusInterfaces.d.ts +1 -1
  23. package/dist/menus/menusSchemas.js +2 -1
  24. package/dist/orders/ordersInterfaces.d.ts +1 -1
  25. package/dist/pages/pagesSchemas.d.ts +3 -3
  26. package/dist/pages/pagesSchemas.js +2 -1
  27. package/dist/product-statuses/productStatusesInterfaces.d.ts +2 -2
  28. package/dist/products/productsSchemas.d.ts +5 -5
  29. package/dist/products/productsSchemas.js +3 -2
  30. package/dist/templates/templatesInterfaces.d.ts +1 -1
  31. package/dist/templates/templatesSchemas.d.ts +3 -3
  32. package/dist/templates/templatesSchemas.js +2 -1
  33. package/dist/templates-preview/templatesPreviewInterfaces.d.ts +2 -2
  34. package/esm/admins/adminsSchemas.d.ts +6 -22
  35. package/esm/admins/adminsSchemas.js +2 -9
  36. package/esm/attribute-sets/attributeSetsInterfaces.d.ts +6 -6
  37. package/esm/auth-provider/authProvidersInterfaces.d.ts +4 -4
  38. package/esm/base/attributes.d.ts +105 -0
  39. package/esm/base/attributes.js +163 -0
  40. package/esm/base/utils.d.ts +95 -2
  41. package/esm/base/validation.d.ts +29 -0
  42. package/esm/base/validation.js +92 -0
  43. package/esm/blocks/blocksInterfaces.d.ts +1 -1
  44. package/esm/blocks/blocksSchemas.d.ts +6 -6
  45. package/esm/blocks/blocksSchemas.js +2 -1
  46. package/esm/discounts/discountsInterfaces.d.ts +1 -1
  47. package/esm/forms-data/formsDataApi.d.ts +16 -6
  48. package/esm/forms-data/formsDataApi.js +14 -4
  49. package/esm/forms-data/formsDataInterfaces.d.ts +48 -15
  50. package/esm/index.d.ts +1 -0
  51. package/esm/index.js +1 -0
  52. package/esm/integration-collections/integrationCollectionsInterfaces.d.ts +6 -6
  53. package/esm/menus/menusInterfaces.d.ts +1 -1
  54. package/esm/menus/menusSchemas.js +2 -1
  55. package/esm/orders/ordersInterfaces.d.ts +1 -1
  56. package/esm/pages/pagesSchemas.d.ts +3 -3
  57. package/esm/pages/pagesSchemas.js +2 -1
  58. package/esm/product-statuses/productStatusesInterfaces.d.ts +2 -2
  59. package/esm/products/productsSchemas.d.ts +5 -5
  60. package/esm/products/productsSchemas.js +3 -2
  61. package/esm/templates/templatesInterfaces.d.ts +1 -1
  62. package/esm/templates/templatesSchemas.d.ts +3 -3
  63. package/esm/templates/templatesSchemas.js +2 -1
  64. package/esm/templates-preview/templatesPreviewInterfaces.d.ts +2 -2
  65. package/package.json +2 -2
@@ -6,6 +6,7 @@ exports.SinglePageSchema = exports.PageSearchResponseSchema = exports.PageSearch
6
6
  * @description Zod schemas for validating pages-related API responses
7
7
  */
8
8
  const zod_1 = require("zod");
9
+ const validation_1 = require("../base/validation");
9
10
  /**
10
11
  * Page entity schema
11
12
  * Includes all fields returned by the API
@@ -21,7 +22,7 @@ exports.PageEntitySchema = zod_1.z.object({
21
22
  type: zod_1.z.enum(['catalog_page', 'common_page', 'error_page', 'external_page']),
22
23
  templateIdentifier: zod_1.z.string().nullable(),
23
24
  attributeSetIdentifier: zod_1.z.string().nullable(),
24
- attributeValues: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
25
+ attributeValues: validation_1.AttributeValuesSchema,
25
26
  moduleFormConfigs: zod_1.z.array(zod_1.z.any()).optional(),
26
27
  rating: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
27
28
  isSync: zod_1.z.boolean(),
@@ -12,7 +12,7 @@ interface IProductStatusesApi {
12
12
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
13
13
  * @description This method searches for all product status objects.
14
14
  */
15
- getProductStatuses(langCode: string): Promise<IProductStatusEntity[] | IError>;
15
+ getProductStatuses(langCode?: string): Promise<IProductStatusEntity[] | IError>;
16
16
  /**
17
17
  * Search for a product status object by its textual identifier (marker).
18
18
  * @handleName getProductsByStatusMarker
@@ -22,7 +22,7 @@ interface IProductStatusesApi {
22
22
  * @throws {IError} If there is an error during the fetch operation, it will return an error object.
23
23
  * @description This method searches for a product status object by its textual identifier (marker).
24
24
  */
25
- getProductsByStatusMarker(marker: string, langCode: string): Promise<IProductStatusEntity | IError>;
25
+ getProductsByStatusMarker(marker: string, langCode?: string): Promise<IProductStatusEntity | IError>;
26
26
  /**
27
27
  * Check the existence of a textual identifier.
28
28
  * @handleName validateMarker
@@ -41,7 +41,7 @@ export declare const ProductEntitySchema: z.ZodObject<{
41
41
  }, z.core.$strip>;
42
42
  sku: z.ZodNullable<z.ZodString>;
43
43
  isSync: z.ZodBoolean;
44
- attributeValues: z.ZodRecord<z.ZodString, z.ZodAny>;
44
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
45
45
  categories: z.ZodArray<z.ZodString>;
46
46
  isVisible: z.ZodBoolean;
47
47
  moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
@@ -83,7 +83,7 @@ export declare const ProductsResponseSchema: z.ZodObject<{
83
83
  }, z.core.$strip>;
84
84
  sku: z.ZodNullable<z.ZodString>;
85
85
  isSync: z.ZodBoolean;
86
- attributeValues: z.ZodRecord<z.ZodString, z.ZodAny>;
86
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
87
87
  categories: z.ZodArray<z.ZodString>;
88
88
  isVisible: z.ZodBoolean;
89
89
  moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
@@ -127,7 +127,7 @@ export declare const SingleProductSchema: z.ZodObject<{
127
127
  }, z.core.$strip>;
128
128
  sku: z.ZodNullable<z.ZodString>;
129
129
  isSync: z.ZodBoolean;
130
- attributeValues: z.ZodRecord<z.ZodString, z.ZodAny>;
130
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
131
131
  categories: z.ZodArray<z.ZodString>;
132
132
  isVisible: z.ZodBoolean;
133
133
  moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
@@ -189,7 +189,7 @@ export declare const ProductBlockSchema: z.ZodObject<{
189
189
  templateIdentifier: z.ZodNullable<z.ZodString>;
190
190
  isVisible: z.ZodBoolean;
191
191
  isSync: z.ZodBoolean;
192
- attributeValues: z.ZodRecord<z.ZodString, z.ZodAny>;
192
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
193
193
  }, z.core.$strip>;
194
194
  /**
195
195
  * Related products schema
@@ -210,7 +210,7 @@ export declare const RelatedProductsSchema: z.ZodArray<z.ZodObject<{
210
210
  }, z.core.$strip>;
211
211
  sku: z.ZodNullable<z.ZodString>;
212
212
  isSync: z.ZodBoolean;
213
- attributeValues: z.ZodRecord<z.ZodString, z.ZodAny>;
213
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
214
214
  categories: z.ZodArray<z.ZodString>;
215
215
  isVisible: z.ZodBoolean;
216
216
  moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
@@ -6,6 +6,7 @@ exports.RelatedProductsSchema = exports.ProductBlockSchema = exports.ProductsCou
6
6
  * @description Zod schemas for validating products-related API responses
7
7
  */
8
8
  const zod_1 = require("zod");
9
+ const validation_1 = require("../base/validation");
9
10
  /**
10
11
  * Product price schema
11
12
  */
@@ -44,7 +45,7 @@ exports.ProductEntitySchema = zod_1.z.object({
44
45
  }),
45
46
  sku: zod_1.z.string().nullable(),
46
47
  isSync: zod_1.z.boolean(),
47
- attributeValues: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
48
+ attributeValues: validation_1.AttributeValuesSchema,
48
49
  categories: zod_1.z.array(zod_1.z.string()),
49
50
  isVisible: zod_1.z.boolean(),
50
51
  moduleFormConfigs: zod_1.z.array(zod_1.z.any()).optional(),
@@ -116,7 +117,7 @@ exports.ProductBlockSchema = zod_1.z.object({
116
117
  templateIdentifier: zod_1.z.string().nullable(),
117
118
  isVisible: zod_1.z.boolean(),
118
119
  isSync: zod_1.z.boolean(),
119
- attributeValues: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
120
+ attributeValues: validation_1.AttributeValuesSchema,
120
121
  });
121
122
  /**
122
123
  * Related products schema
@@ -23,7 +23,7 @@ interface ITemplatesApi {
23
23
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
24
24
  * @description This method gets template objects by type.
25
25
  */
26
- getTemplateByType(type: BlockType, langCode: string): Promise<ITemplateEntity[] | IError>;
26
+ getTemplateByType(type: BlockType, langCode?: string): Promise<ITemplateEntity[] | IError>;
27
27
  /**
28
28
  * Get one template object by id.
29
29
  * @handleName getTemplateByMarker
@@ -15,7 +15,7 @@ export declare const TemplateEntitySchema: z.ZodObject<{
15
15
  identifier: z.ZodString;
16
16
  version: z.ZodNumber;
17
17
  generalTypeName: z.ZodString;
18
- attributeValues: z.ZodRecord<z.ZodString, z.ZodAny>;
18
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
19
19
  position: z.ZodNumber;
20
20
  }, z.core.$strip>;
21
21
  /**
@@ -29,7 +29,7 @@ export declare const TemplatesResponseSchema: z.ZodArray<z.ZodObject<{
29
29
  identifier: z.ZodString;
30
30
  version: z.ZodNumber;
31
31
  generalTypeName: z.ZodString;
32
- attributeValues: z.ZodRecord<z.ZodString, z.ZodAny>;
32
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
33
33
  position: z.ZodNumber;
34
34
  }, z.core.$strip>>;
35
35
  /**
@@ -43,6 +43,6 @@ export declare const GroupedTemplatesResponseSchema: z.ZodRecord<z.ZodString, z.
43
43
  identifier: z.ZodString;
44
44
  version: z.ZodNumber;
45
45
  generalTypeName: z.ZodString;
46
- attributeValues: z.ZodRecord<z.ZodString, z.ZodAny>;
46
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
47
47
  position: z.ZodNumber;
48
48
  }, z.core.$strip>>>;
@@ -6,6 +6,7 @@ exports.GroupedTemplatesResponseSchema = exports.TemplatesResponseSchema = expor
6
6
  * @description Zod schemas for validating templates-related API responses
7
7
  */
8
8
  const zod_1 = require("zod");
9
+ const validation_1 = require("../base/validation");
9
10
  /**
10
11
  * Template entity schema
11
12
  * Includes all fields returned by the API
@@ -18,7 +19,7 @@ exports.TemplateEntitySchema = zod_1.z.object({
18
19
  identifier: zod_1.z.string(),
19
20
  version: zod_1.z.number(),
20
21
  generalTypeName: zod_1.z.string(),
21
- attributeValues: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
22
+ attributeValues: validation_1.AttributeValuesSchema,
22
23
  position: zod_1.z.number(),
23
24
  });
24
25
  /**
@@ -10,7 +10,7 @@ interface ITemplatesPreviewApi {
10
10
  * @returns {ITemplatesPreviewEntity[]} A promise resolving to an array of template preview entities or an error.
11
11
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
12
12
  */
13
- getTemplatePreviews(langCode: string): Promise<ITemplatesPreviewEntity[] | IError>;
13
+ getTemplatePreviews(langCode?: string): Promise<ITemplatesPreviewEntity[] | IError>;
14
14
  /**
15
15
  * Retrieves a specific template preview object by its marker.
16
16
  * @handleName getTemplatePreviewByMarker
@@ -20,7 +20,7 @@ interface ITemplatesPreviewApi {
20
20
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
21
21
  * @description This method retrieves a specific template preview object by its marker.
22
22
  */
23
- getTemplatePreviewByMarker(marker: string, langCode: string): Promise<ITemplatesPreviewEntity | IError>;
23
+ getTemplatePreviewByMarker(marker: string, langCode?: string): Promise<ITemplatesPreviewEntity | IError>;
24
24
  }
25
25
  /**
26
26
  * The `ITemplatesPreview` interface defines the structure of template preview entities.
@@ -3,6 +3,10 @@
3
3
  * @description Zod schemas for validating admins-related API responses
4
4
  */
5
5
  import { z } from 'zod';
6
+ /**
7
+ * Admin entity schema
8
+ * Includes all fields returned by the API
9
+ */
6
10
  export declare const AdminEntitySchema: z.ZodObject<{
7
11
  id: z.ZodNumber;
8
12
  attributeSetId: z.ZodNullable<z.ZodNumber>;
@@ -10,17 +14,7 @@ export declare const AdminEntitySchema: z.ZodObject<{
10
14
  attributeSetIdentifier: z.ZodNullable<z.ZodString>;
11
15
  position: z.ZodNullable<z.ZodNumber>;
12
16
  isSync: z.ZodBoolean;
13
- attributeValues: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodType<{
14
- type: string;
15
- value: unknown;
16
- position?: number;
17
- additionalFields?: Record<string, unknown> | unknown[];
18
- }, unknown, z.core.$ZodTypeInternals<{
19
- type: string;
20
- value: unknown;
21
- position?: number;
22
- additionalFields?: Record<string, unknown> | unknown[];
23
- }, unknown>>>>;
17
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
24
18
  moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
25
19
  distance: z.ZodOptional<z.ZodNumber>;
26
20
  }, z.core.$strip>;
@@ -34,17 +28,7 @@ export declare const AdminsResponseSchema: z.ZodArray<z.ZodObject<{
34
28
  attributeSetIdentifier: z.ZodNullable<z.ZodString>;
35
29
  position: z.ZodNullable<z.ZodNumber>;
36
30
  isSync: z.ZodBoolean;
37
- attributeValues: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodType<{
38
- type: string;
39
- value: unknown;
40
- position?: number;
41
- additionalFields?: Record<string, unknown> | unknown[];
42
- }, unknown, z.core.$ZodTypeInternals<{
43
- type: string;
44
- value: unknown;
45
- position?: number;
46
- additionalFields?: Record<string, unknown> | unknown[];
47
- }, unknown>>>>;
31
+ attributeValues: z.ZodRecord<z.ZodString, z.ZodUnknown>;
48
32
  moduleFormConfigs: z.ZodOptional<z.ZodArray<z.ZodAny>>;
49
33
  distance: z.ZodOptional<z.ZodNumber>;
50
34
  }, z.core.$strip>>;
@@ -3,18 +3,11 @@
3
3
  * @description Zod schemas for validating admins-related API responses
4
4
  */
5
5
  import { z } from 'zod';
6
+ import { AttributeValuesSchema } from '../base/validation.js';
6
7
  /**
7
8
  * Admin entity schema
8
9
  * Includes all fields returned by the API
9
10
  */
10
- const AttributeValueSchema = z.object({
11
- type: z.string(),
12
- value: z.unknown(),
13
- position: z.number().optional(),
14
- additionalFields: z
15
- .union([z.record(z.string(), z.unknown()), z.array(z.unknown())])
16
- .optional(),
17
- });
18
11
  export const AdminEntitySchema = z.object({
19
12
  id: z.number(),
20
13
  attributeSetId: z.number().nullable(),
@@ -22,7 +15,7 @@ export const AdminEntitySchema = z.object({
22
15
  attributeSetIdentifier: z.string().nullable(),
23
16
  position: z.number().nullable(),
24
17
  isSync: z.boolean(),
25
- attributeValues: z.record(z.string(), z.record(z.string(), AttributeValueSchema)),
18
+ attributeValues: AttributeValuesSchema,
26
19
  moduleFormConfigs: z.array(z.any()).optional(),
27
20
  distance: z.number().optional(),
28
21
  });
@@ -14,18 +14,18 @@ interface IAttributesSets {
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<IAttributesSetsEntity[] | IError>;
17
+ getAttributesByMarker(marker: string, langCode?: string): Promise<IAttributesSetsEntity[] | IError>;
18
18
  /**
19
- * Fetches a single attribute by its marker and the set marker.
19
+ * Fetches a single attribute by the set marker and the attribute marker.
20
20
  * @handleName getSingleAttributeByMarkerSet
21
- * @param {string} attributeMarker - The marker identifying the attribute. Example: "color".
22
- * @param {string} setMarker - The marker identifying the attribute set. Example: "productAttributes".
21
+ * @param {string} setMarker - The marker identifying the attribute set — the first path segment. Example: "productAttributes".
22
+ * @param {string} attributeMarker - The marker identifying the attribute inside that set. Example: "color".
23
23
  * @param {string} [langCode] - The language code for localization purposes. Default: "en_US".
24
24
  * @returns {IAttributesSetsEntity} A promise that resolves to an attribute set entity or an error.
25
25
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
26
- * @description This method fetches a single attribute by its marker and the set marker.
26
+ * @description This method fetches a single attribute of an attribute set. The order matches the request path `/{setMarker}/attributes/{attributeMarker}`: the set comes first. Both parameters are strings, so swapping them type-checks and answers `404 Attribute not found`.
27
27
  */
28
- getSingleAttributeByMarkerSet(attributeMarker: string, setMarker: string, langCode: string): Promise<IAttributesSetsEntity | IError>;
28
+ getSingleAttributeByMarkerSet(setMarker: string, attributeMarker: string, langCode?: string): Promise<IAttributesSetsEntity | IError>;
29
29
  }
30
30
  /**
31
31
  * Represents the structure of a list item.
@@ -8,7 +8,7 @@ interface IAuthProvider {
8
8
  * Registers a new user.
9
9
  * @handleName signUp
10
10
  * @param {string} marker - The marker identifying the auth provider. Example: "email".
11
- * @param {ISignUpData} data - The data required for user registration.
11
+ * @param {ISignUpData} body - The data required for user registration.
12
12
  * @example
13
13
  {
14
14
  "formIdentifier": "reg",
@@ -40,7 +40,7 @@ interface IAuthProvider {
40
40
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
41
41
  * @description This method registers a new user.
42
42
  */
43
- signUp(marker: string, data: ISignUpData, langCode?: string): Promise<ISignUpEntity | IError>;
43
+ signUp(marker: string, body: ISignUpData, langCode?: string): Promise<ISignUpEntity | IError>;
44
44
  /**
45
45
  * Generates an activation code for a user.
46
46
  * @handleName generateCode
@@ -79,12 +79,12 @@ interface IAuthProvider {
79
79
  * Authorizes a user.
80
80
  * @handleName auth
81
81
  * @param {string} marker - The marker identifying the auth provider. Example: "email".
82
- * @param {IAuthPostBody} data - The data required for user authorization. Example: .
82
+ * @param {IAuthPostBody} body - The data required for user authorization. Example: .
83
83
  * @returns {IAuthEntity} A promise that resolves to an auth entity or an error.
84
84
  * @throws {IError} - If there is an error during the fetch operation, it will return an error object.
85
85
  * @description This method authorizes a user.
86
86
  */
87
- auth(marker: string, data: IAuthPostBody): Promise<IAuthEntity | IError>;
87
+ auth(marker: string, body: IAuthPostBody): Promise<IAuthEntity | IError>;
88
88
  /**
89
89
  * Refreshes a user's access token.
90
90
  * @handleName refresh
@@ -0,0 +1,105 @@
1
+ import type { IAttributeFile, IAttributeValue, IFileAttributeValue, IListAttributeValue, INumberAttributeValue, IStringAttributeValue } from './utils.js';
2
+ /**
3
+ * Narrows an attribute value to a file-bearing attribute.
4
+ *
5
+ * `IAttributeValue.value` is `unknown` — its shape depends on `type` — so this
6
+ * guard is what lets you reach the files without a cast. It accepts both shapes
7
+ * the SDK produces: a single file object for an `image`/`file` attribute holding
8
+ * exactly one file, an array for several and for every `groupOfImages`.
9
+ * @param {IAttributeValue | undefined} attr - The attribute value to test.
10
+ * @returns {boolean} True when the attribute is an `image`, `file` or `groupOfImages` carrying files (or nothing).
11
+ * @example
12
+ * ```ts
13
+ * const attr = page.attributeValues.cover;
14
+ * if (isFileAttribute(attr)) {
15
+ * // attr.value is IAttributeFile | IAttributeFile[] | null — no cast
16
+ * }
17
+ * ```
18
+ */
19
+ export declare function isFileAttribute(attr: IAttributeValue | undefined): attr is IFileAttributeValue;
20
+ /**
21
+ * Reads every file of an attribute as an array.
22
+ *
23
+ * The one-call path for the common case. An `image`/`file` attribute holding a
24
+ * single file has it unwrapped to the object itself, while several files and
25
+ * every `groupOfImages` stay an array — a rule that is easy to get wrong in a
26
+ * way the compiler cannot catch, since `value` is `unknown`: reading `value[0]`
27
+ * off a single file yields `undefined` and nothing anywhere reports an error.
28
+ * This helper collapses both shapes to a list.
29
+ *
30
+ * Anything that is not a file-bearing attribute yields an empty array, so it is
31
+ * safe to call on an arbitrary attribute without checking `type` first.
32
+ * @param {IAttributeValue | undefined} attr - An attribute value, e.g. `page.attributeValues.cover`.
33
+ * @returns {IAttributeFile[]} The files, in the order the API returned them; empty when the attribute holds none or is not file-bearing.
34
+ * @example
35
+ * ```ts
36
+ * import { getAttributeFiles } from 'oneentry';
37
+ *
38
+ * // Works the same for one image and for a gallery.
39
+ * const images = getAttributeFiles(page.attributeValues.cover);
40
+ * images.map((file) => file.downloadLink);
41
+ * ```
42
+ */
43
+ export declare function getAttributeFiles(attr: IAttributeValue | undefined): IAttributeFile[];
44
+ /**
45
+ * Reads the first file of an attribute.
46
+ *
47
+ * The single-image counterpart of {@link getAttributeFiles} — same shape
48
+ * handling, but returns the file itself instead of a list. For a gallery it
49
+ * returns the first entry, which is what a preview or a cover usually needs.
50
+ * @param {IAttributeValue | undefined} attr - An attribute value, e.g. `product.attributeValues.img`.
51
+ * @returns {IAttributeFile | null} The first file, or null when the attribute holds none.
52
+ * @example
53
+ * ```ts
54
+ * import { getAttributeFile } from 'oneentry';
55
+ *
56
+ * const cover = getAttributeFile(product.attributeValues.img);
57
+ * const blurDataURL = cover?.previewLink?.default?.[0];
58
+ * ```
59
+ */
60
+ export declare function getAttributeFile(attr: IAttributeValue | undefined): IAttributeFile | null;
61
+ /**
62
+ * Narrows an attribute value to a text attribute.
63
+ * @param {IAttributeValue | undefined} attr - The attribute value to test.
64
+ * @returns {boolean} True when the attribute is a `string`, `text` or `textEditor` carrying a string (or nothing).
65
+ */
66
+ export declare function isStringAttribute(attr: IAttributeValue | undefined): attr is IStringAttributeValue;
67
+ /**
68
+ * Narrows an attribute value to a numeric attribute.
69
+ *
70
+ * The SDK casts `integer`, `float` and `real` values to a JS number, so the
71
+ * guard checks for one — a value that failed to cast is `null`.
72
+ * @param {IAttributeValue | undefined} attr - The attribute value to test.
73
+ * @returns {boolean} True when the attribute is an `integer`, `float` or `real` carrying a number (or nothing).
74
+ */
75
+ export declare function isNumberAttribute(attr: IAttributeValue | undefined): attr is INumberAttributeValue;
76
+ /**
77
+ * Narrows an attribute value to a `list` attribute.
78
+ *
79
+ * The option shape is defined by the attribute set, so the entries stay
80
+ * `unknown` — the guard only promises the array container.
81
+ * @param {IAttributeValue | undefined} attr - The attribute value to test.
82
+ * @returns {boolean} True when the attribute is a `list` carrying an array.
83
+ */
84
+ export declare function isListAttribute(attr: IAttributeValue | undefined): attr is IListAttributeValue;
85
+ /**
86
+ * Reads the nested fields of an attribute as a marker map.
87
+ *
88
+ * `additionalFields` is typed `Record<string, IAttributeValue> | unknown[]`
89
+ * because the API returns an empty **array** when an attribute has no nested
90
+ * fields — the union makes every read of a field a type error. This helper
91
+ * collapses that case to an empty map, so the result is always keyed by marker.
92
+ *
93
+ * With `rawData: true` in the config the SDK keeps the API's original array of
94
+ * fields; it is converted here by `marker` as well, so the helper returns the
95
+ * same map in both modes.
96
+ * @param {IAttributeValue | undefined} attr - An attribute value whose nested fields to read.
97
+ * @returns {Record<string, IAttributeValue>} Nested attribute values keyed by marker; empty when there are none.
98
+ * @example
99
+ * ```ts
100
+ * import { getAdditionalFields } from 'oneentry';
101
+ *
102
+ * const alt = getAdditionalFields(page.attributeValues.cover).alt?.value;
103
+ * ```
104
+ */
105
+ export declare function getAdditionalFields(attr: IAttributeValue | undefined): Record<string, IAttributeValue>;
@@ -0,0 +1,163 @@
1
+ const _FILE_TYPES = ['image', 'file', 'groupOfImages'];
2
+ /**
3
+ * Tests whether a value looks like a file object of an attribute.
4
+ *
5
+ * A file is identified by `downloadLink`: it is the one field every file of
6
+ * every attribute carries, while previews are only generated for images.
7
+ * @param {unknown} value - The value to test.
8
+ * @returns {boolean} True when the value is a file object.
9
+ */
10
+ function _isFile(value) {
11
+ return (!!value &&
12
+ typeof value === 'object' &&
13
+ typeof value.downloadLink === 'string');
14
+ }
15
+ /**
16
+ * Narrows an attribute value to a file-bearing attribute.
17
+ *
18
+ * `IAttributeValue.value` is `unknown` — its shape depends on `type` — so this
19
+ * guard is what lets you reach the files without a cast. It accepts both shapes
20
+ * the SDK produces: a single file object for an `image`/`file` attribute holding
21
+ * exactly one file, an array for several and for every `groupOfImages`.
22
+ * @param {IAttributeValue | undefined} attr - The attribute value to test.
23
+ * @returns {boolean} True when the attribute is an `image`, `file` or `groupOfImages` carrying files (or nothing).
24
+ * @example
25
+ * ```ts
26
+ * const attr = page.attributeValues.cover;
27
+ * if (isFileAttribute(attr)) {
28
+ * // attr.value is IAttributeFile | IAttributeFile[] | null — no cast
29
+ * }
30
+ * ```
31
+ */
32
+ export function isFileAttribute(attr) {
33
+ if (!attr || !_FILE_TYPES.includes(attr.type))
34
+ return false;
35
+ if (attr.value === null || attr.value === undefined)
36
+ return true;
37
+ return Array.isArray(attr.value)
38
+ ? attr.value.every((item) => _isFile(item))
39
+ : _isFile(attr.value);
40
+ }
41
+ /**
42
+ * Reads every file of an attribute as an array.
43
+ *
44
+ * The one-call path for the common case. An `image`/`file` attribute holding a
45
+ * single file has it unwrapped to the object itself, while several files and
46
+ * every `groupOfImages` stay an array — a rule that is easy to get wrong in a
47
+ * way the compiler cannot catch, since `value` is `unknown`: reading `value[0]`
48
+ * off a single file yields `undefined` and nothing anywhere reports an error.
49
+ * This helper collapses both shapes to a list.
50
+ *
51
+ * Anything that is not a file-bearing attribute yields an empty array, so it is
52
+ * safe to call on an arbitrary attribute without checking `type` first.
53
+ * @param {IAttributeValue | undefined} attr - An attribute value, e.g. `page.attributeValues.cover`.
54
+ * @returns {IAttributeFile[]} The files, in the order the API returned them; empty when the attribute holds none or is not file-bearing.
55
+ * @example
56
+ * ```ts
57
+ * import { getAttributeFiles } from 'oneentry';
58
+ *
59
+ * // Works the same for one image and for a gallery.
60
+ * const images = getAttributeFiles(page.attributeValues.cover);
61
+ * images.map((file) => file.downloadLink);
62
+ * ```
63
+ */
64
+ export function getAttributeFiles(attr) {
65
+ if (!attr)
66
+ return [];
67
+ const value = attr.value;
68
+ if (Array.isArray(value))
69
+ return value.filter((item) => _isFile(item));
70
+ return _isFile(value) ? [value] : [];
71
+ }
72
+ /**
73
+ * Reads the first file of an attribute.
74
+ *
75
+ * The single-image counterpart of {@link getAttributeFiles} — same shape
76
+ * handling, but returns the file itself instead of a list. For a gallery it
77
+ * returns the first entry, which is what a preview or a cover usually needs.
78
+ * @param {IAttributeValue | undefined} attr - An attribute value, e.g. `product.attributeValues.img`.
79
+ * @returns {IAttributeFile | null} The first file, or null when the attribute holds none.
80
+ * @example
81
+ * ```ts
82
+ * import { getAttributeFile } from 'oneentry';
83
+ *
84
+ * const cover = getAttributeFile(product.attributeValues.img);
85
+ * const blurDataURL = cover?.previewLink?.default?.[0];
86
+ * ```
87
+ */
88
+ export function getAttributeFile(attr) {
89
+ var _a;
90
+ return (_a = getAttributeFiles(attr)[0]) !== null && _a !== void 0 ? _a : null;
91
+ }
92
+ /**
93
+ * Narrows an attribute value to a text attribute.
94
+ * @param {IAttributeValue | undefined} attr - The attribute value to test.
95
+ * @returns {boolean} True when the attribute is a `string`, `text` or `textEditor` carrying a string (or nothing).
96
+ */
97
+ export function isStringAttribute(attr) {
98
+ return (!!attr &&
99
+ (attr.type === 'string' ||
100
+ attr.type === 'text' ||
101
+ attr.type === 'textEditor') &&
102
+ (attr.value === null || typeof attr.value === 'string'));
103
+ }
104
+ /**
105
+ * Narrows an attribute value to a numeric attribute.
106
+ *
107
+ * The SDK casts `integer`, `float` and `real` values to a JS number, so the
108
+ * guard checks for one — a value that failed to cast is `null`.
109
+ * @param {IAttributeValue | undefined} attr - The attribute value to test.
110
+ * @returns {boolean} True when the attribute is an `integer`, `float` or `real` carrying a number (or nothing).
111
+ */
112
+ export function isNumberAttribute(attr) {
113
+ return (!!attr &&
114
+ (attr.type === 'integer' ||
115
+ attr.type === 'float' ||
116
+ attr.type === 'real') &&
117
+ (attr.value === null || typeof attr.value === 'number'));
118
+ }
119
+ /**
120
+ * Narrows an attribute value to a `list` attribute.
121
+ *
122
+ * The option shape is defined by the attribute set, so the entries stay
123
+ * `unknown` — the guard only promises the array container.
124
+ * @param {IAttributeValue | undefined} attr - The attribute value to test.
125
+ * @returns {boolean} True when the attribute is a `list` carrying an array.
126
+ */
127
+ export function isListAttribute(attr) {
128
+ return !!attr && attr.type === 'list' && Array.isArray(attr.value);
129
+ }
130
+ /**
131
+ * Reads the nested fields of an attribute as a marker map.
132
+ *
133
+ * `additionalFields` is typed `Record<string, IAttributeValue> | unknown[]`
134
+ * because the API returns an empty **array** when an attribute has no nested
135
+ * fields — the union makes every read of a field a type error. This helper
136
+ * collapses that case to an empty map, so the result is always keyed by marker.
137
+ *
138
+ * With `rawData: true` in the config the SDK keeps the API's original array of
139
+ * fields; it is converted here by `marker` as well, so the helper returns the
140
+ * same map in both modes.
141
+ * @param {IAttributeValue | undefined} attr - An attribute value whose nested fields to read.
142
+ * @returns {Record<string, IAttributeValue>} Nested attribute values keyed by marker; empty when there are none.
143
+ * @example
144
+ * ```ts
145
+ * import { getAdditionalFields } from 'oneentry';
146
+ *
147
+ * const alt = getAdditionalFields(page.attributeValues.cover).alt?.value;
148
+ * ```
149
+ */
150
+ export function getAdditionalFields(attr) {
151
+ const fields = attr === null || attr === void 0 ? void 0 : attr.additionalFields;
152
+ if (!fields || typeof fields !== 'object')
153
+ return {};
154
+ if (Array.isArray(fields)) {
155
+ // rawData mode: the API's own array of fields, each carrying its marker.
156
+ return Object.fromEntries(fields
157
+ .filter((field) => !!field &&
158
+ typeof field === 'object' &&
159
+ typeof field.marker === 'string')
160
+ .map((field) => [field.marker, field]));
161
+ }
162
+ return fields;
163
+ }