oneentry 1.0.138 → 1.0.139

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.
@@ -8,6 +8,7 @@ export default abstract class SyncModules {
8
8
  /** Protected properties for state and URL */
9
9
  protected state: StateModule;
10
10
  protected _url: string;
11
+ private readonly _nodeDeviceId;
11
12
  /**
12
13
  * Constructor to initialize state and URL.
13
14
  * @param {StateModule} state - StateModule instance.
@@ -1,9 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Using WeakMap to store unique instance IDs for each object instance
4
- const instanceIds = new WeakMap();
5
- // Counter to ensure even more uniqueness
6
- let instanceCounter = 0;
3
+ // Browser: module-level persistent device ID (localStorage-backed)
4
+ let _persistentDeviceId = null;
5
+ function _getBrowserDeviceId() {
6
+ const win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
7
+ if (!(win === null || win === void 0 ? void 0 : win.localStorage))
8
+ return null;
9
+ if (_persistentDeviceId)
10
+ return _persistentDeviceId;
11
+ try {
12
+ const stored = win.localStorage.getItem('oneentry_device_id');
13
+ if (stored) {
14
+ _persistentDeviceId = stored;
15
+ return _persistentDeviceId;
16
+ }
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
+ }
19
+ catch (_e) {
20
+ // ignore
21
+ }
22
+ const id = Date.now().toString(36) +
23
+ Math.random().toString(36).substring(2, 15) +
24
+ Math.random().toString(36).substring(2, 15);
25
+ _persistentDeviceId = id;
26
+ try {
27
+ win.localStorage.setItem('oneentry_device_id', id);
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ }
30
+ catch (_e) {
31
+ // ignore
32
+ }
33
+ return _persistentDeviceId;
34
+ }
7
35
  /**
8
36
  * Abstract class representing synchronization modules.
9
37
  */
@@ -21,15 +49,10 @@ class SyncModules {
21
49
  this._sortAttributes = (data) => Object.fromEntries(Object.entries(data).sort(([, a], [, b]) => a.position - b.position));
22
50
  this.state = state;
23
51
  this._url = state.url;
24
- // Generate and store a unique instance ID using WeakMap
25
- if (!instanceIds.has(this)) {
26
- const timestampPart = Date.now().toString(36);
27
- const randomPart = Math.random().toString(36).substring(2, 15) +
52
+ this._nodeDeviceId =
53
+ Date.now().toString(36) +
54
+ Math.random().toString(36).substring(2, 15) +
28
55
  Math.random().toString(36).substring(2, 15);
29
- const counterPart = (++instanceCounter).toString(36);
30
- const instanceId = `${timestampPart}${randomPart}${counterPart}`;
31
- instanceIds.set(this, instanceId);
32
- }
33
56
  }
34
57
  /**
35
58
  * Constructs the full URL path by appending the given path to the base URL.
@@ -449,19 +472,15 @@ class SyncModules {
449
472
  * @returns {string} - Returns an object containing device metadata.
450
473
  */
451
474
  _getDeviceMetadata() {
475
+ var _a;
452
476
  // Check if we're in a browser environment
453
477
  if (typeof globalThis === 'undefined') {
454
478
  return '';
455
479
  }
456
480
  // Access navigator through globalThis.window object to avoid direct reference
457
481
  const win = globalThis.window;
458
- // Get the instance ID from the WeakMap
459
- const instanceId = instanceIds.get(this) ||
460
- Date.now().toString(36) +
461
- Math.random().toString(36).substring(2, 15) +
462
- Math.random().toString(36).substring(2, 15) +
463
- (++instanceCounter).toString(36);
464
- // Node.js environment - unique per-instance fingerprint (no shared process ID)
482
+ const instanceId = (_a = _getBrowserDeviceId()) !== null && _a !== void 0 ? _a : this._nodeDeviceId;
483
+ // Node.js environment
465
484
  if (!win) {
466
485
  return JSON.stringify({
467
486
  fingerprint: `UQ_${instanceId}`,
@@ -16,7 +16,6 @@ export default class ProductApi extends AsyncModules implements IProductApi {
16
16
  * @description Constructor initializes the ProductApi with a given state.
17
17
  */
18
18
  constructor(state: StateModule);
19
- private _defaultQuery;
20
19
  /**
21
20
  * Search for all products with pagination and filter.
22
21
  * @handleName getProducts
@@ -19,12 +19,6 @@ class ProductApi extends asyncModules_1.default {
19
19
  */
20
20
  constructor(state) {
21
21
  super(state);
22
- this._defaultQuery = {
23
- offset: 0,
24
- limit: 30,
25
- sortOrder: 'DESC',
26
- sortKey: 'id',
27
- };
28
22
  this._url = state.url + '/api/content/products';
29
23
  }
30
24
  /**
@@ -76,7 +70,6 @@ class ProductApi extends asyncModules_1.default {
76
70
  */
77
71
  async getProducts(body = [], langCode = this.state.lang, userQuery) {
78
72
  const query = {
79
- ...this._defaultQuery,
80
73
  ...userQuery,
81
74
  langCode,
82
75
  };
@@ -107,7 +100,7 @@ class ProductApi extends asyncModules_1.default {
107
100
  * @description Search for all product page objects with pagination that do not have a category.
108
101
  */
109
102
  async getProductsEmptyPage(langCode = this.state.lang, userQuery) {
110
- const query = { ...this._defaultQuery, ...userQuery };
103
+ const query = { ...userQuery };
111
104
  const result = await this._fetchGet(`/empty-page?langCode=${langCode}&` + this._queryParamsToString(query));
112
105
  // Validate response if validation is enabled
113
106
  const validated = this._validateResponse(result, productsSchemas_1.ProductsResponseSchema);
@@ -161,7 +154,7 @@ class ProductApi extends asyncModules_1.default {
161
154
  * @description Fetch products by page ID with optional filters and pagination.
162
155
  */
163
156
  async getProductsByPageId(id, body = [], langCode = this.state.lang, userQuery) {
164
- const query = { ...this._defaultQuery, ...userQuery };
157
+ const query = { ...userQuery };
165
158
  const result = await this._fetchPost(`/page/${id}?langCode=${langCode}&` + this._queryParamsToString(query), body);
166
159
  // Validate response if validation is enabled
167
160
  const validated = this._validateResponse(result, productsSchemas_1.ProductsResponseSchema);
@@ -191,7 +184,6 @@ class ProductApi extends asyncModules_1.default {
191
184
  */
192
185
  async getProductsPriceByPageUrl(url, langCode = this.state.lang, userQuery) {
193
186
  const query = {
194
- ...this._defaultQuery,
195
187
  ...userQuery,
196
188
  langCode,
197
189
  };
@@ -246,7 +238,7 @@ class ProductApi extends asyncModules_1.default {
246
238
  * @description Search for all products with pagination for the selected category.
247
239
  */
248
240
  async getProductsByPageUrl(url, body = [], langCode = this.state.lang, userQuery) {
249
- const query = { ...this._defaultQuery, ...userQuery };
241
+ const query = { ...userQuery };
250
242
  const result = await this._fetchPost(`/page/url/${url}?langCode=${langCode}&` +
251
243
  this._queryParamsToString(query), body);
252
244
  // Validate response if validation is enabled
@@ -280,7 +272,7 @@ class ProductApi extends asyncModules_1.default {
280
272
  * @description Find all related product page objects.
281
273
  */
282
274
  async getRelatedProductsById(id, langCode = this.state.lang, userQuery) {
283
- const query = { ...this._defaultQuery, ...userQuery };
275
+ const query = { ...userQuery };
284
276
  const result = await this._fetchGet(`/${id}/related?langCode=${langCode}&` + this._queryParamsToString(query));
285
277
  // Validate response if validation is enabled
286
278
  const validated = this._validateResponse(result, productsSchemas_1.ProductsResponseSchema);
@@ -321,7 +313,6 @@ class ProductApi extends asyncModules_1.default {
321
313
  const query = {
322
314
  ids,
323
315
  langCode,
324
- ...this._defaultQuery,
325
316
  ...userQuery,
326
317
  };
327
318
  const result = await this._fetchGet(`/ids?` + this._queryParamsToString(query));
@@ -346,10 +346,10 @@ interface IProductApi {
346
346
  * @description This interface defines the structure of a query for retrieving products, including pagination, sorting, and filtering parameters.
347
347
  */
348
348
  interface IProductsQuery {
349
- offset: number;
350
- limit: number;
351
- sortOrder: 'DESC' | 'ASC' | null;
352
- sortKey: 'id' | 'position' | 'title' | 'date' | 'price' | null;
349
+ offset?: number;
350
+ limit?: number;
351
+ sortOrder?: 'DESC' | 'ASC' | null;
352
+ sortKey?: 'id' | 'position' | 'title' | 'date' | 'price' | null;
353
353
  signPrice?: string;
354
354
  templateMarker?: string | null;
355
355
  statusMarker?: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.138",
3
+ "version": "1.0.139",
4
4
  "description": "OneEntry NPM package",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",