oneentry 1.0.33 → 1.0.35

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.
@@ -0,0 +1,27 @@
1
+ import OneEntry from "../base/oneEntry";
2
+ import { IAttributesSets, IAttributesSetsEntity } from "./attributeSetsInterfaces";
3
+ /**
4
+ * Controllers for working with attributes.
5
+ */
6
+ export default class AttributesSetsApi extends OneEntry implements IAttributesSets {
7
+ constructor(url: string, token: string);
8
+ /**
9
+ * Get all attributes with data from the attribute sets.
10
+ *
11
+ * @param {string} marker - Attribute marker.
12
+ * @param {string} langCode - Language code.
13
+ *
14
+ * @returns Returns an array of AttributeInSet objects.
15
+ */
16
+ getAttributesByMarker(marker: string, langCode: string): Promise<Array<IAttributesSetsEntity>>;
17
+ /**
18
+ * Get a single attribute with data from the attribute sets.
19
+ *
20
+ * @param {string} attributeMarker - Text identifier (marker) of the attribute in the set.
21
+ * @param {string} setMarker - Text identifier (marker) of the attribute set.
22
+ * @param {string} langCode - Language code.
23
+ *
24
+ * @returns Returns a AttributeInSet object.
25
+ */
26
+ getSingleAttributeByMarkerSet(attributeMarker: string, setMarker: string, langCode: string): Promise<IAttributesSetsEntity>;
27
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const oneEntry_1 = require("../base/oneEntry");
4
+ /**
5
+ * Controllers for working with attributes.
6
+ */
7
+ class AttributesSetsApi extends oneEntry_1.default {
8
+ constructor(url, token) {
9
+ super(url, token);
10
+ this._url += '/api/content/attributes-sets';
11
+ }
12
+ /**
13
+ * Get all attributes with data from the attribute sets.
14
+ *
15
+ * @param {string} marker - Attribute marker.
16
+ * @param {string} langCode - Language code.
17
+ *
18
+ * @returns Returns an array of AttributeInSet objects.
19
+ */
20
+ async getAttributesByMarker(marker, langCode) {
21
+ const result = await this._fetchGet(`/${marker}/attributes?langCode=${langCode}`);
22
+ return result;
23
+ }
24
+ /**
25
+ * Get a single attribute with data from the attribute sets.
26
+ *
27
+ * @param {string} attributeMarker - Text identifier (marker) of the attribute in the set.
28
+ * @param {string} setMarker - Text identifier (marker) of the attribute set.
29
+ * @param {string} langCode - Language code.
30
+ *
31
+ * @returns Returns a AttributeInSet object.
32
+ */
33
+ async getSingleAttributeByMarkerSet(attributeMarker, setMarker, langCode) {
34
+ const result = await this._fetchGet(`/${setMarker}/attributes/${attributeMarker}?langCode=${langCode}`);
35
+ return result;
36
+ }
37
+ }
38
+ exports.default = AttributesSetsApi;
@@ -0,0 +1,46 @@
1
+ import { ILocalizeInfos, Types } from "../base/utils";
2
+ /**
3
+ * Represents an interface object of AttributesSets Api.
4
+ *
5
+ * @property {function} getAttributesByMarker - Get all attributes with data from the attribute sets.
6
+ *
7
+ * @property {function} getSingleAttributeByMarkerSet - Get a single attribute with data from the attribute sets.
8
+ */
9
+ interface IAttributesSets {
10
+ getAttributesByMarker(marker: string, langCode: string): Promise<Array<IAttributesSetsEntity>>;
11
+ getSingleAttributeByMarkerSet(attributeMarker: string, setMarker: string, langCode: string): Promise<IAttributesSetsEntity>;
12
+ }
13
+ /**
14
+ * Represents a template entity object.
15
+ *
16
+ * @interface
17
+ * @property {Types} type - Attribute type.
18
+ * @property {string} marker - Textual identifier of the attribute (marker).
19
+ * @property {number} position - Position number for sorting.
20
+ * @property {Record<string, any>} validators - Set of validators for validation.
21
+ * @property {ILocalizeInfos} localizeInfos - The name of the template, taking into account localization.
22
+ * @property {Array<Record<string, any>>} listTitles - Array of values (with extended data) for list and radioButton attributes.
23
+ *
24
+ */
25
+ interface IAttributesSetsEntity {
26
+ type: Types;
27
+ marker: string;
28
+ position: number;
29
+ validators: {
30
+ requiredValidator: {
31
+ strict: boolean;
32
+ };
33
+ defaultValueValidator: {
34
+ fieldDefaultValue: number;
35
+ };
36
+ };
37
+ localizeInfos: ILocalizeInfos;
38
+ listTitles: Array<{
39
+ title: string;
40
+ value: number | string;
41
+ position: string | number | null;
42
+ extendedValue: string | number | null;
43
+ extendedValueType: string | number | null;
44
+ }>;
45
+ }
46
+ export { IAttributesSets, IAttributesSetsEntity };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -5,6 +5,7 @@ export default abstract class OneEntry {
5
5
  protected _url: string;
6
6
  protected _token: string;
7
7
  protected _LANGCODE_KEY: string;
8
+ protected _NO_FETCH: boolean;
8
9
  constructor(url: string, token?: string);
9
10
  protected _getFullPath(path: string): string;
10
11
  protected _fetchGet(path: string): Promise<any>;
@@ -1,49 +1,114 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const https = require('https');
3
4
  class OneEntry {
4
5
  constructor(url, token) {
5
6
  this._LANGCODE_KEY = '$LANGCODE';
7
+ this._NO_FETCH = false;
6
8
  this._url = url;
7
9
  if (token) {
8
10
  this._token = token;
9
11
  }
12
+ if (typeof process === 'object' && process.versions && process.versions.node) {
13
+ this._NO_FETCH = true;
14
+ }
10
15
  }
11
16
  _getFullPath(path) {
12
17
  return (this._url + path);
13
18
  }
14
19
  async _fetchGet(path) {
15
- const response = await fetch(this._getFullPath(path), {
20
+ const options = {
16
21
  method: 'GET',
17
22
  headers: {
18
23
  'Content-Type': 'application/json',
19
24
  'x-app-token': this._token,
20
25
  }
21
- });
22
- const result = await response.json();
23
- return result;
26
+ };
27
+ if (!this._NO_FETCH) {
28
+ const response = await fetch(this._getFullPath(path), options);
29
+ const result = await response.json();
30
+ return result;
31
+ }
32
+ else {
33
+ return new Promise((resolve, reject) => {
34
+ const req = https.get(this._getFullPath(path), options, (res) => {
35
+ let data = '';
36
+ res.on('data', (chunk) => {
37
+ data += chunk;
38
+ });
39
+ res.on('end', () => {
40
+ resolve(JSON.parse(data));
41
+ });
42
+ });
43
+ req.on('error', (error) => {
44
+ reject(error);
45
+ });
46
+ });
47
+ }
24
48
  }
25
49
  async _fetchPost(path, data) {
26
- const response = await fetch(this._getFullPath(path), {
50
+ const options = {
27
51
  method: 'POST',
28
52
  headers: {
29
53
  'Content-Type': 'application/json',
30
54
  'x-app-token': this._token,
31
- },
32
- body: JSON.stringify(data)
33
- });
34
- const result = await response.json();
35
- return result;
55
+ }
56
+ };
57
+ if (!this._NO_FETCH) {
58
+ const response = await fetch(this._getFullPath(path), {
59
+ ...options,
60
+ body: JSON.stringify(data)
61
+ });
62
+ return await response.json();
63
+ }
64
+ else {
65
+ return new Promise((resolve, reject) => {
66
+ const req = https.request(this._getFullPath(path), options, (res) => {
67
+ let responseData = '';
68
+ res.on('data', (chunk) => {
69
+ responseData += chunk;
70
+ });
71
+ res.on('end', () => {
72
+ resolve(JSON.parse(responseData));
73
+ });
74
+ });
75
+ req.on('error', (error) => {
76
+ reject(error);
77
+ });
78
+ req.write(JSON.stringify(data));
79
+ req.end();
80
+ });
81
+ }
36
82
  }
37
83
  async _fetchDelete(path) {
38
- const response = await fetch(this._getFullPath(path), {
84
+ const options = {
39
85
  method: 'DELETE',
40
86
  headers: {
41
87
  'Content-Type': 'application/json',
42
88
  'x-app-token': this._token,
43
- },
44
- });
45
- const result = await response.json();
46
- return result;
89
+ }
90
+ };
91
+ if (!this._NO_FETCH) {
92
+ const response = await fetch(this._getFullPath(path), options);
93
+ const result = await response.json();
94
+ return result;
95
+ }
96
+ else {
97
+ return new Promise((resolve, reject) => {
98
+ const req = https.get(this._getFullPath(path), options, (res) => {
99
+ let data = '';
100
+ res.on('data', (chunk) => {
101
+ data += chunk;
102
+ });
103
+ res.on('end', () => {
104
+ resolve(JSON.parse(data));
105
+ });
106
+ });
107
+ req.on('error', (error) => {
108
+ reject(error);
109
+ });
110
+ });
111
+ }
47
112
  }
48
113
  _queryParamsToString(query) {
49
114
  let result = '';
@@ -5,16 +5,6 @@ import { IBlocks, IBlocksEntity } from "./blocksInterfaces";
5
5
  */
6
6
  export default class BlocksApi extends OneEntry implements IBlocks {
7
7
  constructor(url: string, token: string);
8
- /**
9
- * Get blocks by parameters.
10
- *
11
- * @param {string} [langCode] - Language code. Default "en_US"
12
- * @param {number} [offset] - Parameter for pagination. Default 0
13
- * @param {number} [limit] - Parameter for pagination. Default 30
14
- *
15
- * @returns Return array of BlocksEntity object.
16
- */
17
- getBlocks(langCode?: string, offset?: number, limit?: number): Promise<Array<IBlocksEntity>>;
18
8
  /**
19
9
  * Get block by marker.
20
10
  *
@@ -9,19 +9,19 @@ class BlocksApi extends oneEntry_1.default {
9
9
  super(url, token);
10
10
  this._url += '/api/content/blocks';
11
11
  }
12
- /**
13
- * Get blocks by parameters.
14
- *
15
- * @param {string} [langCode] - Language code. Default "en_US"
16
- * @param {number} [offset] - Parameter for pagination. Default 0
17
- * @param {number} [limit] - Parameter for pagination. Default 30
18
- *
19
- * @returns Return array of BlocksEntity object.
20
- */
21
- async getBlocks(langCode = 'en_US', offset = 0, limit = 30) {
22
- const result = await this._fetchGet(`&langCode=${langCode}&offset=${offset}&limit=${limit}`);
23
- return result;
24
- }
12
+ // /**
13
+ // * Get blocks by parameters.
14
+ // *
15
+ // * @param {string} [langCode] - Language code. Default "en_US"
16
+ // * @param {number} [offset] - Parameter for pagination. Default 0
17
+ // * @param {number} [limit] - Parameter for pagination. Default 30
18
+ // *
19
+ // * @returns Return array of BlocksEntity object.
20
+ // */
21
+ // public async getBlocks(langCode:string = 'en_US', offset:number = 0, limit:number = 30):Promise<Array<IBlocksEntity>>{
22
+ // const result = await this._fetchGet(`&langCode=${langCode}&offset=${offset}&limit=${limit}`)
23
+ // return result
24
+ // }
25
25
  /**
26
26
  * Get block by marker.
27
27
  *
@@ -31,7 +31,7 @@ class BlocksApi extends oneEntry_1.default {
31
31
  * @returns Return BlocksEntity object.
32
32
  */
33
33
  async getBlockByMarker(marker, langCode = 'en_US') {
34
- const result = await this._fetchGet(`/marker/${marker}&langCode=${langCode}`);
34
+ const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
35
35
  return result;
36
36
  }
37
37
  }
@@ -6,7 +6,6 @@ import { IAttributeValues, ILocalizeInfos } from "../base/utils";
6
6
  * @property {function} getBlockByMarker - Get Block object by marker.
7
7
  */
8
8
  interface IBlocks {
9
- getBlocks(langCode: string, offset?: number, limit?: number): Promise<Array<IBlocksEntity>>;
10
9
  getBlockByMarker(marker: string, langCode: string): Promise<IBlocksEntity>;
11
10
  }
12
11
  interface IBlocksEntity {
package/dist/index.d.ts CHANGED
@@ -12,8 +12,10 @@ import FormsDataApi from "./formsData/formsDataApi";
12
12
  import FileUploadingApi from "./file-uploding/fileUploadingApi";
13
13
  import SystemApi from "./system/systemApi";
14
14
  import BlocksApi from "./blocks/blocksApi";
15
+ import AttributesSetsApi from "./attribute-sets/attributeSetsApi";
15
16
  interface IDefineApi {
16
17
  Admins: AdminsApi;
18
+ AttributesSets: AttributesSetsApi;
17
19
  Blocks: BlocksApi;
18
20
  FileUploading: FileUploadingApi;
19
21
  Forms: FormsApi;
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ const formsDataApi_1 = require("./formsData/formsDataApi");
15
15
  const fileUploadingApi_1 = require("./file-uploding/fileUploadingApi");
16
16
  const systemApi_1 = require("./system/systemApi");
17
17
  const blocksApi_1 = require("./blocks/blocksApi");
18
+ const attributeSetsApi_1 = require("./attribute-sets/attributeSetsApi");
18
19
  /**
19
20
  * Define API.
20
21
  * @param {string} url - URl of your project.
@@ -22,6 +23,7 @@ const blocksApi_1 = require("./blocks/blocksApi");
22
23
  */
23
24
  function defineOneEntry(url, token) {
24
25
  const Admins = new adminsApi_1.default(url, token);
26
+ const AttributesSets = new attributeSetsApi_1.default(url, token);
25
27
  const Blocks = new blocksApi_1.default(url, token);
26
28
  const FileUploading = new fileUploadingApi_1.default(url, token);
27
29
  const Forms = new formsApi_1.default(url, token);
@@ -37,6 +39,7 @@ function defineOneEntry(url, token) {
37
39
  const TemplatePreviews = new templatesPreviewApi_1.default(url, token);
38
40
  return {
39
41
  Admins,
42
+ AttributesSets,
40
43
  Blocks,
41
44
  FileUploading,
42
45
  Forms,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,5 +12,8 @@
12
12
  "dependencies": {
13
13
  "jsdoc": "^4.0.2",
14
14
  "typescript": "^5.2.2"
15
+ },
16
+ "devDependencies": {
17
+ "@types/node": "^20.10.4"
15
18
  }
16
19
  }