@softwear/latestcollectioncore 1.0.196 → 1.0.197

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/dist/consts.d.ts CHANGED
@@ -4,21 +4,25 @@ declare const SUBSCRIPTION_LIMITS: {
4
4
  readonly maxBarcodes: 1000;
5
5
  readonly maxDownloadBarcodes: 1000;
6
6
  readonly maxCustomers: 0;
7
+ readonly maxDataRetentionYears: 3;
7
8
  };
8
9
  readonly basiq: {
9
10
  readonly maxBarcodes: 100000;
10
11
  readonly maxDownloadBarcodes: 10000;
11
12
  readonly maxCustomers: 1000;
13
+ readonly maxDataRetentionYears: 3;
12
14
  };
13
15
  readonly pro: {
14
16
  readonly maxBarcodes: 200000;
15
17
  readonly maxDownloadBarcodes: 20000;
16
18
  readonly maxCustomers: 10000;
19
+ readonly maxDataRetentionYears: 5;
17
20
  };
18
21
  readonly ultimate: {
19
22
  readonly maxBarcodes: 500000;
20
23
  readonly maxDownloadBarcodes: 50000;
21
24
  readonly maxCustomers: 100000;
25
+ readonly maxDataRetentionYears: 7;
22
26
  };
23
27
  };
24
28
  declare const latestCollectionGLN: "8719332204995";
package/dist/consts.js CHANGED
@@ -22,21 +22,25 @@ const SUBSCRIPTION_LIMITS = {
22
22
  maxBarcodes: 1000,
23
23
  maxDownloadBarcodes: 1000,
24
24
  maxCustomers: 0,
25
+ maxDataRetentionYears: 3,
25
26
  },
26
27
  basiq: {
27
28
  maxBarcodes: 100000,
28
29
  maxDownloadBarcodes: 10000,
29
30
  maxCustomers: 1000,
31
+ maxDataRetentionYears: 3,
30
32
  },
31
33
  pro: {
32
34
  maxBarcodes: 200000,
33
35
  maxDownloadBarcodes: 20000,
34
36
  maxCustomers: 10000,
37
+ maxDataRetentionYears: 5,
35
38
  },
36
39
  ultimate: {
37
40
  maxBarcodes: 500000,
38
41
  maxDownloadBarcodes: 50000,
39
42
  maxCustomers: 100000,
43
+ maxDataRetentionYears: 7,
40
44
  },
41
45
  };
42
46
  exports.SUBSCRIPTION_LIMITS = SUBSCRIPTION_LIMITS;
@@ -0,0 +1,4 @@
1
+ export declare function getMaxDataRetentionYears(subscription: string): number;
2
+ export declare function getEarliestAllowedYear(maxRetentionYears: number, thisYear?: number): number;
3
+ export declare function isYearWithinDataRetention(year: number | string, maxRetentionYears: number, thisYear?: number): boolean;
4
+ export declare function isDateWithinDataRetention(date: string, maxRetentionYears: number, thisYear?: number): boolean;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDateWithinDataRetention = exports.isYearWithinDataRetention = exports.getEarliestAllowedYear = exports.getMaxDataRetentionYears = void 0;
4
+ const consts_1 = require("./consts");
5
+ function getMaxDataRetentionYears(subscription) {
6
+ var _a;
7
+ const limits = consts_1.SUBSCRIPTION_LIMITS[subscription];
8
+ return (_a = limits === null || limits === void 0 ? void 0 : limits.maxDataRetentionYears) !== null && _a !== void 0 ? _a : consts_1.SUBSCRIPTION_LIMITS.basiq.maxDataRetentionYears;
9
+ }
10
+ exports.getMaxDataRetentionYears = getMaxDataRetentionYears;
11
+ function getEarliestAllowedYear(maxRetentionYears, thisYear = new Date().getFullYear()) {
12
+ return thisYear - maxRetentionYears + 1;
13
+ }
14
+ exports.getEarliestAllowedYear = getEarliestAllowedYear;
15
+ function isYearWithinDataRetention(year, maxRetentionYears, thisYear = new Date().getFullYear()) {
16
+ const parsedYear = parseInt(String(year), 10);
17
+ if (Number.isNaN(parsedYear))
18
+ return true;
19
+ return parsedYear >= getEarliestAllowedYear(maxRetentionYears, thisYear);
20
+ }
21
+ exports.isYearWithinDataRetention = isYearWithinDataRetention;
22
+ function isDateWithinDataRetention(date, maxRetentionYears, thisYear = new Date().getFullYear()) {
23
+ if (!date)
24
+ return true;
25
+ return isYearWithinDataRetention(parseInt(date.substring(0, 4), 10), maxRetentionYears, thisYear);
26
+ }
27
+ exports.isDateWithinDataRetention = isDateWithinDataRetention;
package/dist/index.d.ts CHANGED
@@ -25,5 +25,6 @@ export * from './pdf';
25
25
  export type { GenPdfAlert, GenPdfOptions, PdfFontDefinition, PdfFontVariant, PdfImageAsset } from './reports';
26
26
  export * from './types';
27
27
  export * from './consts';
28
+ export * from './dataRetention';
28
29
  export { default as lcAxios, createAxiosInstance, axiosRetry, exponentialDelay, isAxiosError, } from './lcAxios';
29
30
  export type { AxiosRequestConfig, AxiosResponse, AxiosPromise, AxiosError, AxiosTransformer, AxiosRetryOptions, AxiosRequestConfigAny, } from './lcAxios';
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ Object.defineProperty(exports, "shouldSuppressZeroField", { enumerable: true, ge
69
69
  __exportStar(require("./pdf"), exports);
70
70
  __exportStar(require("./types"), exports);
71
71
  __exportStar(require("./consts"), exports);
72
+ __exportStar(require("./dataRetention"), exports);
72
73
  var lcAxios_1 = require("./lcAxios");
73
74
  Object.defineProperty(exports, "lcAxios", { enumerable: true, get: function () { return __importDefault(lcAxios_1).default; } });
74
75
  Object.defineProperty(exports, "createAxiosInstance", { enumerable: true, get: function () { return lcAxios_1.createAxiosInstance; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.196",
3
+ "version": "1.0.197",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/consts.ts CHANGED
@@ -18,21 +18,25 @@ const SUBSCRIPTION_LIMITS = {
18
18
  maxBarcodes: 1000,
19
19
  maxDownloadBarcodes: 1000,
20
20
  maxCustomers: 0,
21
+ maxDataRetentionYears: 3,
21
22
  },
22
23
  basiq: {
23
24
  maxBarcodes: 100000,
24
25
  maxDownloadBarcodes: 10000,
25
26
  maxCustomers: 1000,
27
+ maxDataRetentionYears: 3,
26
28
  },
27
29
  pro: {
28
30
  maxBarcodes: 200000,
29
31
  maxDownloadBarcodes: 20000,
30
32
  maxCustomers: 10000,
33
+ maxDataRetentionYears: 5,
31
34
  },
32
35
  ultimate: {
33
36
  maxBarcodes: 500000,
34
37
  maxDownloadBarcodes: 50000,
35
38
  maxCustomers: 100000,
39
+ maxDataRetentionYears: 7,
36
40
  },
37
41
  } as const
38
42
  const latestCollectionGLN = '8719332204995' as const
@@ -0,0 +1,23 @@
1
+ import { SUBSCRIPTION_LIMITS } from './consts'
2
+
3
+ type SubscriptionKey = keyof typeof SUBSCRIPTION_LIMITS
4
+
5
+ export function getMaxDataRetentionYears(subscription: string): number {
6
+ const limits = SUBSCRIPTION_LIMITS[subscription as SubscriptionKey]
7
+ return limits?.maxDataRetentionYears ?? SUBSCRIPTION_LIMITS.basiq.maxDataRetentionYears
8
+ }
9
+
10
+ export function getEarliestAllowedYear(maxRetentionYears: number, thisYear = new Date().getFullYear()): number {
11
+ return thisYear - maxRetentionYears + 1
12
+ }
13
+
14
+ export function isYearWithinDataRetention(year: number | string, maxRetentionYears: number, thisYear = new Date().getFullYear()): boolean {
15
+ const parsedYear = parseInt(String(year), 10)
16
+ if (Number.isNaN(parsedYear)) return true
17
+ return parsedYear >= getEarliestAllowedYear(maxRetentionYears, thisYear)
18
+ }
19
+
20
+ export function isDateWithinDataRetention(date: string, maxRetentionYears: number, thisYear = new Date().getFullYear()): boolean {
21
+ if (!date) return true
22
+ return isYearWithinDataRetention(parseInt(date.substring(0, 4), 10), maxRetentionYears, thisYear)
23
+ }
package/src/index.ts CHANGED
@@ -25,6 +25,7 @@ export * from './pdf'
25
25
  export type { GenPdfAlert, GenPdfOptions, PdfFontDefinition, PdfFontVariant, PdfImageAsset } from './reports'
26
26
  export * from './types'
27
27
  export * from './consts'
28
+ export * from './dataRetention'
28
29
  export {
29
30
  default as lcAxios,
30
31
  createAxiosInstance,
@@ -0,0 +1,21 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { getEarliestAllowedYear, getMaxDataRetentionYears, isDateWithinDataRetention, isYearWithinDataRetention } from '../src/dataRetention'
3
+
4
+ describe('dataRetention', () => {
5
+ const thisYear = 2026
6
+
7
+ it('returns retention years per subscription', () => {
8
+ expect(getMaxDataRetentionYears('basiq')).toBe(3)
9
+ expect(getMaxDataRetentionYears('pro')).toBe(5)
10
+ expect(getMaxDataRetentionYears('ultimate')).toBe(7)
11
+ expect(getMaxDataRetentionYears('unknown')).toBe(3)
12
+ })
13
+
14
+ it('checks year and date access against retention', () => {
15
+ expect(getEarliestAllowedYear(3, thisYear)).toBe(2024)
16
+ expect(isYearWithinDataRetention(2024, 3, thisYear)).toBe(true)
17
+ expect(isYearWithinDataRetention(2023, 3, thisYear)).toBe(false)
18
+ expect(isDateWithinDataRetention('2023-12-31', 3, thisYear)).toBe(false)
19
+ expect(isDateWithinDataRetention('2024-01-01', 3, thisYear)).toBe(true)
20
+ })
21
+ })