@edirect/tokenization 11.0.44 → 11.0.45

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 (34) hide show
  1. package/package.json +1 -1
  2. package/dist/README.md +0 -110
  3. package/dist/package.json +0 -36
  4. package/dist/src/core/app.d.ts +0 -17
  5. package/dist/src/core/app.d.ts.map +0 -1
  6. package/dist/src/core/app.js +0 -114
  7. package/dist/src/core/domain.d.ts +0 -25
  8. package/dist/src/core/domain.d.ts.map +0 -1
  9. package/dist/src/core/domain.js +0 -2
  10. package/dist/src/core/evaluator/basic.d.ts +0 -5
  11. package/dist/src/core/evaluator/basic.d.ts.map +0 -1
  12. package/dist/src/core/evaluator/basic.js +0 -32
  13. package/dist/src/core/evaluator/index.d.ts +0 -8
  14. package/dist/src/core/evaluator/index.d.ts.map +0 -1
  15. package/dist/src/core/evaluator/index.js +0 -26
  16. package/dist/src/core/services/configuration.d.ts +0 -12
  17. package/dist/src/core/services/configuration.d.ts.map +0 -1
  18. package/dist/src/core/services/configuration.js +0 -82
  19. package/dist/src/core/services/tokenization.d.ts +0 -9
  20. package/dist/src/core/services/tokenization.d.ts.map +0 -1
  21. package/dist/src/core/services/tokenization.js +0 -43
  22. package/dist/src/core/traverser/index.d.ts +0 -4
  23. package/dist/src/core/traverser/index.d.ts.map +0 -1
  24. package/dist/src/core/traverser/index.js +0 -19
  25. package/dist/src/core/utils/object.d.ts +0 -7
  26. package/dist/src/core/utils/object.d.ts.map +0 -1
  27. package/dist/src/core/utils/object.js +0 -33
  28. package/dist/src/index.d.ts +0 -29
  29. package/dist/src/index.d.ts.map +0 -1
  30. package/dist/src/index.js +0 -70
  31. package/dist/src/types.d.ts +0 -56
  32. package/dist/src/types.d.ts.map +0 -1
  33. package/dist/src/types.js +0 -5
  34. package/dist/tsconfig.lib.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/tokenization",
3
- "version": "11.0.44",
3
+ "version": "11.0.45",
4
4
  "description": "Javascript library for tokenization service",
5
5
  "packageScope": "@edirect",
6
6
  "main": "./dist/src/index.js",
package/dist/README.md DELETED
@@ -1,110 +0,0 @@
1
- # @edirect/tokenization
2
-
3
- `@edirect/tokenization` is a Node.js client for the Tokenization Service, providing methods to securely tokenize and detokenize sensitive data. It supports caching of configurations and tokens to reduce unnecessary requests.
4
-
5
- ## Features
6
-
7
- - Tokenize and detokenize payloads with a simple API
8
- - Caches configurations (5 min) and tokens (1 min) for efficiency
9
- - Supports parsing and validation of token strings
10
-
11
- ---
12
-
13
- ## Installation
14
-
15
- ```sh
16
- pnpm add @edirect/tokenization
17
- # or
18
- npm install @edirect/tokenization
19
- ```
20
-
21
- ## Caching Behavior
22
-
23
- This client **caches** configurations for **5 minutes** and tokens for **1 minute** to avoid unnecessary requests. If you update configurations on the tokenization service, allow cache expiry before expecting changes.
24
-
25
- ## Usage
26
-
27
- The `Tokenization` class provides methods to tokenize and detokenize payloads.
28
-
29
- ### Importing the Tokenization Class
30
-
31
- ```js
32
- import { Tokenization } from '@edirect/tokenization';
33
- ```
34
-
35
- ### Creating an Instance
36
-
37
- ```js
38
- const baseUrl = 'https://tokenization-service.api.example.com';
39
- const tokenization = new Tokenization(baseUrl);
40
- ```
41
-
42
- ### Tokenizing a Payload
43
-
44
- ```js
45
- const auth = 'your-auth-token';
46
- const tenant = 'your-tenant';
47
- const config = 'your-config';
48
- const payload = {
49
- name: 'John Doe',
50
- email: 'johndoe@test.com',
51
- phone: '123-456-7890',
52
- payment: {
53
- cardNumber: '1234 5678 9012 3456',
54
- expirationDate: '12/23',
55
- cvv: '123',
56
- },
57
- };
58
-
59
- const tokenizedData = await tokenization.tokenize(
60
- auth,
61
- tenant,
62
- config,
63
- payload
64
- );
65
- console.log('Tokenized Payload:', tokenizedData);
66
- ```
67
-
68
- ### Detokenizing a Payload
69
-
70
- ```js
71
- const detokenizedData = await tokenization.detokenize(
72
- auth,
73
- tenant,
74
- config,
75
- payload
76
- );
77
- console.log('Detokenized Payload:', detokenizedData);
78
- ```
79
-
80
- ### Parsing the Token
81
-
82
- ```js
83
- const token = Tokenization.parseToken('token:tenant1:str:asdf1234');
84
- console.log(`Is Token: ${token.isToken}`);
85
- console.log(`Tenant: ${token.tenant}`);
86
- console.log(`Type: ${token.type}`);
87
- console.log(`Hash: ${token.Hash}`);
88
- ```
89
-
90
- ## API
91
-
92
- ### `Tokenization`
93
-
94
- - `constructor(baseUrl: string)`
95
- - Creates an instance of the `Tokenization` class.
96
- - `baseUrl`: The base URL of the tokenization service.
97
-
98
- - `tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>`
99
- - Tokenizes the given payload.
100
- - `auth`: The authentication token.
101
- - `tenant`: The tenant to tokenize the payload for.
102
- - `config`: The configuration for tokenization.
103
- - `payload`: The payload to tokenize.
104
-
105
- - `detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>`
106
- - Detokenizes the given payload.
107
- - `auth`: The authentication token.
108
- - `tenant`: The tenant to detokenize the payload for.
109
- - `config`: The configuration for detokenization.
110
- - `payload`: The payload to detokenize.
package/dist/package.json DELETED
@@ -1,36 +0,0 @@
1
- {
2
- "name": "@edirect/tokenization",
3
- "version": "11.0.43",
4
- "description": "Javascript library for tokenization service",
5
- "main": "./dist/src/index.js",
6
- "types": "./dist/src/index.d.ts",
7
- "exports": {
8
- ".": {
9
- "import": "./dist/src/index.js",
10
- "default": "./dist/src/index.js",
11
- "require": "./dist/src/index.js",
12
- "types": "./dist/src/index.d.ts"
13
- },
14
- "./package.json": "./package.json"
15
- },
16
- "files": [
17
- "dist"
18
- ],
19
- "keywords": [
20
- "typescript",
21
- "library"
22
- ],
23
- "author": "Igor Quirino <igor.quirino@bolttech.com>",
24
- "license": "MIT",
25
- "homepage": "https://bolttech.io",
26
- "dependencies": {
27
- "lru-cache": "^11.2.5",
28
- "tslib": "^2.8.1",
29
- "vitest": "4.0.18"
30
- },
31
- "devDependencies": {
32
- "@types/node": "^25.0.10",
33
- "typescript": "^5.9.3"
34
- },
35
- "type": "commonjs"
36
- }
@@ -1,17 +0,0 @@
1
- import { TokenPayload } from '../types';
2
- import { IConfigurationService, IEvaluator, ITokenizationApp, ITokenizationService } from './domain';
3
- export type CacheTokenPayload = {
4
- found: TokenPayload;
5
- notFound: TokenPayload;
6
- };
7
- export declare class TokenizationApp implements ITokenizationApp {
8
- private cache;
9
- private tokenizationService;
10
- private configurationService;
11
- private evaluator;
12
- constructor(tokenizationService: ITokenizationService, configurationService: IConfigurationService, evaluator?: IEvaluator | undefined);
13
- tokenize(auth: string, tenant: string, configKey: string, payload: TokenPayload): Promise<TokenPayload>;
14
- detokenize(auth: string, tenant: string, configKey: string, payload: TokenPayload): Promise<TokenPayload>;
15
- private processRequest;
16
- }
17
- //# sourceMappingURL=app.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../../src/core/app.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,YAAY,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAKlB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,YAAY,CAAC;CACxB,CAAC;AAEF,qBAAa,eAAgB,YAAW,gBAAgB;IACtD,OAAO,CAAC,KAAK,CAAwB;IAErC,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAAO,CAAC,oBAAoB,CAAwB;IACpD,OAAO,CAAC,SAAS,CAAiB;gBAEhC,mBAAmB,EAAE,oBAAoB,EACzC,oBAAoB,EAAE,qBAAqB,EAC3C,SAAS,CAAC,EAAE,UAAU,GAAG,SAAS;IAc9B,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC;IAuClB,UAAU,CACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC;IAwCxB,OAAO,CAAC,cAAc;CAgCvB"}
@@ -1,114 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenizationApp = void 0;
4
- /* eslint-disable @typescript-eslint/no-explicit-any */
5
- const lru_cache_1 = require("lru-cache");
6
- const evaluator_1 = require("./evaluator");
7
- const traverser_1 = require("./traverser");
8
- const object_1 = require("./utils/object");
9
- class TokenizationApp {
10
- cache;
11
- tokenizationService;
12
- configurationService;
13
- evaluator;
14
- constructor(tokenizationService, configurationService, evaluator) {
15
- this.tokenizationService = tokenizationService;
16
- this.configurationService = configurationService;
17
- this.evaluator = new evaluator_1.TokenEvaluator(evaluator);
18
- this.cache = new lru_cache_1.LRUCache({
19
- max: 5000,
20
- ttl: 1000 * 60 * 1, // 1 minute
21
- allowStale: false,
22
- updateAgeOnGet: false,
23
- updateAgeOnHas: false,
24
- });
25
- }
26
- async tokenize(auth, tenant, configKey, payload) {
27
- const config = await this.configurationService.get(auth, tenant, configKey);
28
- if (!config)
29
- return payload;
30
- if ((!config.fields || config.fields.length === 0) &&
31
- config.defaultClassification === 0)
32
- return payload;
33
- const respPayload = payload;
34
- const processedPayload = await this.processRequest(config, payload);
35
- if (Object.keys(processedPayload.notFound).length > 0) {
36
- const tokenPayload = await this.tokenizationService.tokenize(auth, tenant, configKey, processedPayload.notFound);
37
- for (const key in tokenPayload) {
38
- const path = key.split('.');
39
- const token = tokenPayload[key];
40
- const original = (0, object_1.get)(respPayload, path);
41
- (0, object_1.set)(respPayload, path, token);
42
- if (typeof token === 'string') {
43
- this.cache.set(token, original);
44
- this.cache.set(original.toString(), token);
45
- }
46
- }
47
- }
48
- if (Object.keys(processedPayload.found).length > 0) {
49
- for (const key in processedPayload.found) {
50
- (0, object_1.set)(respPayload, key.split('.'), processedPayload.found[key]);
51
- }
52
- }
53
- return respPayload;
54
- }
55
- async detokenize(auth, tenant, configKey, payload) {
56
- const config = await this.configurationService.get(auth, tenant, configKey);
57
- if (!config)
58
- return payload;
59
- if ((!config.fields || config.fields.length === 0) &&
60
- config.defaultClassification === 0)
61
- return payload;
62
- const respPayload = payload;
63
- const processedPayload = this.processRequest(config, payload);
64
- if (Object.keys(processedPayload.notFound).length > 0) {
65
- const tokenPayload = await this.tokenizationService.detokenize(auth, tenant, configKey, processedPayload.notFound);
66
- for (const key in tokenPayload) {
67
- const path = key.split('.');
68
- const token = (0, object_1.get)(respPayload, path);
69
- const original = tokenPayload[key];
70
- if (typeof original === 'string') {
71
- this.cache.set(token, original);
72
- this.cache.set(original.toString(), token);
73
- }
74
- (0, object_1.set)(respPayload, key.split('.'), original);
75
- }
76
- }
77
- if (Object.keys(processedPayload.found).length > 0) {
78
- for (const key in processedPayload.found) {
79
- (0, object_1.set)(respPayload, key.split('.'), processedPayload.found[key]);
80
- }
81
- }
82
- return respPayload;
83
- }
84
- processRequest(config, payload) {
85
- // if (config.defaultClassification === 1) { removing because the caller is already checking for this
86
- // return payload;
87
- // }
88
- if (config.fields.length === 0) {
89
- return {
90
- found: payload,
91
- notFound: {},
92
- };
93
- }
94
- const req = {
95
- found: {},
96
- notFound: {},
97
- };
98
- (0, traverser_1.traverse)(payload, (value, path) => {
99
- if (!value)
100
- return;
101
- if (this.evaluator.shouldTokenizeField(config, path)) {
102
- const fromCache = this.cache.get(value.toString());
103
- if (fromCache) {
104
- req.found[path.join('.')] = fromCache;
105
- }
106
- else {
107
- req.notFound[path.join('.')] = value;
108
- }
109
- }
110
- });
111
- return req;
112
- }
113
- }
114
- exports.TokenizationApp = TokenizationApp;
@@ -1,25 +0,0 @@
1
- import { Configuration, TokenPayload } from '../types';
2
- export interface ITokenizationService {
3
- tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
4
- detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
5
- }
6
- export interface IConfigurationService {
7
- get(auth: string, tenant: string, config: string): Promise<Configuration | undefined>;
8
- create(auth: string, tenant: string, config: Configuration): Promise<Configuration>;
9
- update(auth: string, tenant: string, config: Configuration): Promise<Configuration>;
10
- delete(auth: string, tenant: string, config: string): Promise<void>;
11
- }
12
- export interface IEvaluator {
13
- Evaluate(path: string, ...properties: string[]): boolean;
14
- }
15
- export interface ITokenizationApp {
16
- tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
17
- detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
18
- }
19
- export type Token = {
20
- isToken: boolean;
21
- tenant: string;
22
- type: string;
23
- hash: string;
24
- };
25
- //# sourceMappingURL=domain.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../../src/core/domain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAEvD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,UAAU,CACR,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,CACD,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IACtC,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1B,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1B,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;CAC1D;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CACN,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,UAAU,CACR,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC,CAAC;CAC1B;AAED,MAAM,MAAM,KAAK,GAAG;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- import { IEvaluator } from '../domain';
2
- export declare class BasicEvaluator implements IEvaluator {
3
- Evaluate(path: string, ...properties: string[]): boolean;
4
- }
5
- //# sourceMappingURL=basic.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../../../src/core/evaluator/basic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC,qBAAa,cAAe,YAAW,UAAU;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO;CA+BzD"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BasicEvaluator = void 0;
4
- class BasicEvaluator {
5
- Evaluate(path, ...properties) {
6
- const pathSegments = path.split('.');
7
- const propertiesSegments = properties;
8
- let i = 0, j = 0;
9
- while (i < pathSegments.length && j < propertiesSegments.length) {
10
- if (pathSegments[i] === '**') {
11
- if (i === pathSegments.length - 1) {
12
- return true;
13
- }
14
- i++;
15
- while (j < propertiesSegments.length &&
16
- propertiesSegments[j] !== pathSegments[i]) {
17
- j++;
18
- }
19
- }
20
- else if (pathSegments[i] === '*' ||
21
- pathSegments[i] === propertiesSegments[j]) {
22
- i++;
23
- j++;
24
- }
25
- else {
26
- return false;
27
- }
28
- }
29
- return i === pathSegments.length && j === propertiesSegments.length;
30
- }
31
- }
32
- exports.BasicEvaluator = BasicEvaluator;
@@ -1,8 +0,0 @@
1
- import { Configuration } from '../../types';
2
- import { IEvaluator } from '../domain';
3
- export declare class TokenEvaluator {
4
- private evaluator;
5
- constructor(evaluator?: IEvaluator | undefined);
6
- shouldTokenizeField(config: Configuration | undefined, path: string[]): boolean;
7
- }
8
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/evaluator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAGvC,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAa;gBAClB,SAAS,CAAC,EAAE,UAAU,GAAG,SAAS;IAI9C,mBAAmB,CACjB,MAAM,EAAE,aAAa,GAAG,SAAS,EACjC,IAAI,EAAE,MAAM,EAAE,GACb,OAAO;CAkBX"}
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenEvaluator = void 0;
4
- const basic_1 = require("./basic");
5
- class TokenEvaluator {
6
- evaluator;
7
- constructor(evaluator) {
8
- this.evaluator = evaluator || new basic_1.BasicEvaluator();
9
- }
10
- shouldTokenizeField(config, path) {
11
- if (!config) {
12
- return false;
13
- }
14
- if (config.fields.length === 0) {
15
- return config.defaultClassification > 0;
16
- }
17
- const ret = config.fields.map(field => {
18
- if (!field.classification) {
19
- return false;
20
- }
21
- return this.evaluator.Evaluate(field.path, ...path);
22
- });
23
- return ret.some(r => r) || config.defaultClassification > 0;
24
- }
25
- }
26
- exports.TokenEvaluator = TokenEvaluator;
@@ -1,12 +0,0 @@
1
- import { IConfigurationService } from '../domain';
2
- import { Configuration } from '../../types';
3
- export declare class ConfigurationService implements IConfigurationService {
4
- private baseUrl;
5
- private cache;
6
- constructor(baseUrl: string);
7
- get(auth: string, tenant: string, config: string): Promise<Configuration | undefined>;
8
- create(auth: string, tenant: string, config: Configuration): Promise<Configuration>;
9
- update(auth: string, tenant: string, config: Configuration): Promise<Configuration>;
10
- delete(auth: string, tenant: string, config: string): Promise<void>;
11
- }
12
- //# sourceMappingURL=configuration.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../../src/core/services/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,qBAAa,oBAAqB,YAAW,qBAAqB;IAGpD,OAAO,CAAC,OAAO;IAF3B,OAAO,CAAC,KAAK,CAAkC;gBAE3B,OAAO,EAAE,MAAM;IActB,GAAG,CACd,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC;IAyBxB,MAAM,CACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC;IAkBZ,MAAM,CACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC;IAkBZ,MAAM,CACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC;CAcjB"}
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigurationService = void 0;
4
- const lru_cache_1 = require("lru-cache");
5
- class ConfigurationService {
6
- baseUrl;
7
- cache;
8
- constructor(baseUrl) {
9
- this.baseUrl = baseUrl;
10
- if (!this.baseUrl) {
11
- throw new Error('Configuration Service BaseUrl is required');
12
- }
13
- this.cache = new lru_cache_1.LRUCache({
14
- max: 100,
15
- ttl: 1000 * 60 * 5, // 5 minutes
16
- allowStale: false,
17
- updateAgeOnGet: false,
18
- updateAgeOnHas: false,
19
- });
20
- }
21
- async get(auth, tenant, config) {
22
- const cached = this.cache.get(`${tenant}/${config}`);
23
- if (cached) {
24
- return cached;
25
- }
26
- const resp = await fetch(`${this.baseUrl}/api/v1/${tenant}/${config}/config`, {
27
- method: 'GET',
28
- headers: {
29
- Authorization: `Bearer ${auth}`,
30
- },
31
- });
32
- if (resp.status === 404) {
33
- return undefined;
34
- }
35
- if (resp.status !== 200) {
36
- throw new Error('Failed to get configuration');
37
- }
38
- const data = (await resp.json());
39
- this.cache.set(`${tenant}/${config}`, data);
40
- return data;
41
- }
42
- async create(auth, tenant, config) {
43
- const resp = await fetch(`${this.baseUrl}/api/v1/${tenant}/${config.key}/config`, {
44
- method: 'POST',
45
- body: JSON.stringify(config),
46
- headers: {
47
- Authorization: `Bearer ${auth}`,
48
- 'Content-Type': 'application/json',
49
- },
50
- });
51
- if (resp.status !== 200) {
52
- throw new Error('Failed to create configuration');
53
- }
54
- return config;
55
- }
56
- async update(auth, tenant, config) {
57
- const respo = await fetch(`${this.baseUrl}/api/v1/${tenant}/${config.key}/config`, {
58
- method: 'PUT',
59
- body: JSON.stringify(config),
60
- headers: {
61
- Authorization: `Bearer ${auth}`,
62
- 'Content-Type': 'application/json',
63
- },
64
- });
65
- if (respo.status !== 200) {
66
- throw new Error('Failed to update configuration');
67
- }
68
- return config;
69
- }
70
- async delete(auth, tenant, config) {
71
- const resp = await fetch(`${this.baseUrl}/api/v1/${tenant}/${config}/config`, {
72
- method: 'DELETE',
73
- headers: {
74
- Authorization: `Bearer ${auth}`,
75
- },
76
- });
77
- if (resp.status !== 204) {
78
- throw new Error('Failed to delete configuration');
79
- }
80
- }
81
- }
82
- exports.ConfigurationService = ConfigurationService;
@@ -1,9 +0,0 @@
1
- import { ITokenizationService } from '../domain';
2
- import { TokenPayload } from '../../types';
3
- export declare class TokenizationService implements ITokenizationService {
4
- private baseUrl;
5
- constructor(baseUrl: string);
6
- tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
7
- detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
8
- }
9
- //# sourceMappingURL=tokenization.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tokenization.d.ts","sourceRoot":"","sources":["../../../../src/core/services/tokenization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,qBAAa,mBAAoB,YAAW,oBAAoB;IAClD,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,MAAM;IAMtB,QAAQ,CACnB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC;IAmBX,UAAU,CACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC;CAkBzB"}
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenizationService = void 0;
4
- class TokenizationService {
5
- baseUrl;
6
- constructor(baseUrl) {
7
- this.baseUrl = baseUrl;
8
- if (!this.baseUrl) {
9
- throw new Error('Tokenization Service BaseUrl is required');
10
- }
11
- }
12
- async tokenize(auth, tenant, config, payload) {
13
- const resp = await fetch(`${this.baseUrl}/api/v1/${tenant}/${config}/token/tokenize`, {
14
- method: 'POST',
15
- body: JSON.stringify(payload),
16
- headers: {
17
- Authorization: `Bearer ${auth}`,
18
- 'Content-Type': 'application/json',
19
- },
20
- });
21
- if (resp.status !== 200) {
22
- throw new Error('Failed to tokenize payload');
23
- }
24
- const data = (await resp.json());
25
- return data;
26
- }
27
- async detokenize(auth, tenant, config, payload) {
28
- const resp = await fetch(`${this.baseUrl}/api/v1/${tenant}/${config}/token/detokenize`, {
29
- method: 'POST',
30
- body: JSON.stringify(payload),
31
- headers: {
32
- Authorization: `Bearer ${auth}`,
33
- 'Content-Type': 'application/json',
34
- },
35
- });
36
- if (resp.status !== 200) {
37
- throw new Error('Failed to detokenize payload');
38
- }
39
- const data = (await resp.json());
40
- return data;
41
- }
42
- }
43
- exports.TokenizationService = TokenizationService;
@@ -1,4 +0,0 @@
1
- type Callback = (value: any, path: string[]) => void;
2
- export declare const traverse: (obj: any, callback: Callback, path?: string[]) => void;
3
- export {};
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/traverser/index.ts"],"names":[],"mappings":"AACA,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;AAErD,eAAO,MAAM,QAAQ,GACnB,KAAK,GAAG,EACR,UAAU,QAAQ,EAClB,OAAM,MAAM,EAAO,KAClB,IAYF,CAAC"}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.traverse = void 0;
4
- const traverse = (obj, callback, path = []) => {
5
- if (Array.isArray(obj)) {
6
- obj.forEach((value, index) => {
7
- (0, exports.traverse)(value, callback, [...path, `${index}`]);
8
- });
9
- }
10
- else if (obj !== null && typeof obj === 'object') {
11
- Object.keys(obj).forEach(key => {
12
- (0, exports.traverse)(obj[key], callback, [...path, key]);
13
- });
14
- }
15
- else {
16
- callback(obj, path);
17
- }
18
- };
19
- exports.traverse = traverse;
@@ -1,7 +0,0 @@
1
- type AnyObject = {
2
- [key: string]: any;
3
- };
4
- export declare const get: (obj: AnyObject, path: string[]) => any;
5
- export declare const set: (obj: AnyObject, path: string[], value: any) => void;
6
- export {};
7
- //# sourceMappingURL=object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/object.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC;AAExC,eAAO,MAAM,GAAG,GAAI,KAAK,SAAS,EAAE,MAAM,MAAM,EAAE,KAAG,GAcpD,CAAC;AAEF,eAAO,MAAM,GAAG,GAAI,KAAK,SAAS,EAAE,MAAM,MAAM,EAAE,EAAE,OAAO,GAAG,KAAG,IAehE,CAAC"}
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.set = exports.get = void 0;
4
- const get = (obj, path) => {
5
- let currentObj = obj;
6
- for (let i = 0; i < path.length; i++) {
7
- const key = path[i];
8
- if (currentObj[key] !== undefined) {
9
- currentObj = currentObj[key];
10
- }
11
- else {
12
- return undefined;
13
- }
14
- }
15
- return currentObj;
16
- };
17
- exports.get = get;
18
- const set = (obj, path, value) => {
19
- let currentObj = obj;
20
- for (let i = 0; i < path.length; i++) {
21
- const key = path[i];
22
- if (i === path.length - 1) {
23
- currentObj[key] = value;
24
- }
25
- else {
26
- if (!currentObj[key] || typeof currentObj[key] !== 'object') {
27
- currentObj[key] = isNaN(Number(path[i + 1])) ? {} : [];
28
- }
29
- currentObj = currentObj[key];
30
- }
31
- }
32
- };
33
- exports.set = set;
@@ -1,29 +0,0 @@
1
- import { ITokenizationApp, Token } from './core/domain';
2
- import { TokenPayload } from './types';
3
- /**
4
- * The TokenizationClient class.
5
- */
6
- export declare class Tokenization {
7
- private app;
8
- /**
9
- * The constructor of the TokenizationClient class.
10
- * @param url The URL of the tokenization server.
11
- */
12
- constructor(baseUrlOrApp?: string | ITokenizationApp);
13
- /**
14
- * Tokenizes the given payload.
15
- * @param tenant The tenant to tokenize the payload for.
16
- * @param payload The payload to tokenize.
17
- * @returns The tokenized payload.
18
- */
19
- tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
20
- /**
21
- * Detokenizes the given payload.
22
- * @param tenant The tenant to detokenize the payload for.
23
- * @param payload The payload to detokenize.
24
- * @returns The detokenized payload.
25
- */
26
- detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
27
- static parseToken(token: string): Token;
28
- }
29
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAmB;IAE9B;;;OAGG;gBACS,YAAY,CAAC,EAAE,MAAM,GAAG,gBAAgB;IAcpD;;;;;OAKG;IACI,QAAQ,CACb,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC;IAIxB;;;;;OAKG;IACI,UAAU,CACf,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,YAAY,CAAC;WAIV,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK;CA2B/C"}
package/dist/src/index.js DELETED
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tokenization = void 0;
4
- const app_1 = require("./core/app");
5
- const configuration_1 = require("./core/services/configuration");
6
- const tokenization_1 = require("./core/services/tokenization");
7
- /**
8
- * The TokenizationClient class.
9
- */
10
- class Tokenization {
11
- app;
12
- /**
13
- * The constructor of the TokenizationClient class.
14
- * @param url The URL of the tokenization server.
15
- */
16
- constructor(baseUrlOrApp) {
17
- if (baseUrlOrApp && typeof baseUrlOrApp !== 'string') {
18
- this.app = baseUrlOrApp;
19
- return;
20
- }
21
- const tokenizationService = new tokenization_1.TokenizationService(baseUrlOrApp);
22
- const configurationService = new configuration_1.ConfigurationService(baseUrlOrApp);
23
- this.app = new app_1.TokenizationApp(tokenizationService, configurationService);
24
- return;
25
- }
26
- /**
27
- * Tokenizes the given payload.
28
- * @param tenant The tenant to tokenize the payload for.
29
- * @param payload The payload to tokenize.
30
- * @returns The tokenized payload.
31
- */
32
- tokenize(auth, tenant, config, payload) {
33
- return this.app.tokenize(auth, tenant, config, payload);
34
- }
35
- /**
36
- * Detokenizes the given payload.
37
- * @param tenant The tenant to detokenize the payload for.
38
- * @param payload The payload to detokenize.
39
- * @returns The detokenized payload.
40
- */
41
- detokenize(auth, tenant, config, payload) {
42
- return this.app.detokenize(auth, tenant, config, payload);
43
- }
44
- static parseToken(token) {
45
- const parts = token.split(':');
46
- if (parts.length !== 4) {
47
- return {
48
- isToken: false,
49
- tenant: '',
50
- type: '',
51
- hash: '',
52
- };
53
- }
54
- if (parts[0] !== 'token') {
55
- return {
56
- isToken: false,
57
- tenant: '',
58
- type: '',
59
- hash: '',
60
- };
61
- }
62
- return {
63
- isToken: true,
64
- tenant: parts[1],
65
- type: parts[2],
66
- hash: parts[3],
67
- };
68
- }
69
- }
70
- exports.Tokenization = Tokenization;
@@ -1,56 +0,0 @@
1
- /**
2
- * @file This file contains the models used in the application.
3
- */
4
- /**
5
- * The classification of a field.
6
- * 0: The field is not sensitive.
7
- * 1: The field is sensitive.
8
- */
9
- export type Classification = 0 | 1;
10
- /**
11
- * The model of a field classification.
12
- * @property path The path of the field.
13
- * @property classification The classification of the field.
14
- * @example
15
- * {
16
- * path: "data.*.name",
17
- * classification: 1
18
- * }
19
- * @see Classification
20
- */
21
- export type FieldClassification = {
22
- path: string;
23
- classification: Classification;
24
- };
25
- /**
26
- * The model of a configuration.
27
- * @property key The key of the configuration.
28
- * @property tenant The tenant of the configuration.
29
- * @property defaultClassification The default classification of the configuration.
30
- * @property fields The fields of the configuration.
31
- * @example
32
- * {
33
- * key: "configuration",
34
- * tenant: "tenant",
35
- * defaultClassification: 0,
36
- * fields: [
37
- * {
38
- * path: "data.*.name",
39
- * classification: 1
40
- * }
41
- * ]
42
- * }
43
- * @see FieldClassification
44
- * @see Classification
45
- */
46
- export type Configuration = {
47
- key: string;
48
- tenant: string;
49
- defaultClassification: Classification;
50
- fields: FieldClassification[];
51
- };
52
- /**
53
- * The model of a token payload.
54
- */
55
- export type TokenPayload = Record<string, unknown>;
56
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,CAAC;AAEnC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,qBAAqB,EAAE,cAAc,CAAC;IACtC,MAAM,EAAE,mBAAmB,EAAE,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
package/dist/src/types.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- /**
3
- * @file This file contains the models used in the application.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +0,0 @@
1
- {"version":"5.9.3"}