@edirect/tokenization 0.0.10 → 11.0.25
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/README.md +10 -5
- package/dist/README.md +113 -0
- package/dist/package.json +36 -0
- package/dist/src/core/app.d.ts +17 -0
- package/dist/src/core/app.d.ts.map +1 -0
- package/dist/src/core/app.js +114 -0
- package/dist/src/core/domain.d.ts +25 -0
- package/dist/src/core/domain.d.ts.map +1 -0
- package/dist/src/core/domain.js +2 -0
- package/dist/src/core/evaluator/basic.d.ts +5 -0
- package/dist/src/core/evaluator/basic.d.ts.map +1 -0
- package/dist/src/core/evaluator/basic.js +32 -0
- package/dist/src/core/evaluator/index.d.ts +8 -0
- package/dist/src/core/evaluator/index.d.ts.map +1 -0
- package/dist/src/core/evaluator/index.js +26 -0
- package/dist/src/core/services/configuration.d.ts +12 -0
- package/dist/src/core/services/configuration.d.ts.map +1 -0
- package/dist/src/core/services/configuration.js +82 -0
- package/dist/src/core/services/tokenization.d.ts +9 -0
- package/dist/src/core/services/tokenization.d.ts.map +1 -0
- package/dist/src/core/services/tokenization.js +43 -0
- package/dist/src/core/traverser/index.d.ts +4 -0
- package/dist/src/core/traverser/index.d.ts.map +1 -0
- package/dist/src/core/traverser/index.js +19 -0
- package/dist/src/core/utils/object.d.ts +7 -0
- package/dist/src/core/utils/object.d.ts.map +1 -0
- package/dist/src/core/utils/object.js +33 -0
- package/dist/{index.d.ts → src/index.d.ts} +4 -19
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +70 -0
- package/dist/src/types.d.ts +56 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +5 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +44 -24
- package/dist/index.d.mts +0 -44
- package/dist/index.js +0 -443
- package/dist/index.mjs +0 -406
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ The `Tokenization` class provides methods to tokenize and detokenize payloads. B
|
|
|
23
23
|
### Importing the Tokenization Class
|
|
24
24
|
|
|
25
25
|
```javascript
|
|
26
|
-
import { Tokenization } from
|
|
26
|
+
import { Tokenization } from '@edirect/tokenization';
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
### Creating an Instance
|
|
@@ -31,7 +31,7 @@ import { Tokenization } from "@edirect/tokenization";
|
|
|
31
31
|
To create an instance of the `Tokenization` class, you need to provide the base URL of the tokenization service.
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
|
-
const baseUrl =
|
|
34
|
+
const baseUrl = 'https://tokenization-service.api.example.com';
|
|
35
35
|
const tokenization = new Tokenization(baseUrl);
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -63,8 +63,13 @@ console.log('Tokenized Payload:', tokenizedData);
|
|
|
63
63
|
To detokenize a payload, use the `detokenize` method. You need to provide the authentication token, tenant, configuration, and the payload to be detokenized.
|
|
64
64
|
|
|
65
65
|
```javascript
|
|
66
|
-
const detokenizedData = await tokenization.detokenize(
|
|
67
|
-
|
|
66
|
+
const detokenizedData = await tokenization.detokenize(
|
|
67
|
+
auth,
|
|
68
|
+
tenant,
|
|
69
|
+
config,
|
|
70
|
+
payload
|
|
71
|
+
);
|
|
72
|
+
console.log('Detokenized Payload:', detokenizedData);
|
|
68
73
|
```
|
|
69
74
|
|
|
70
75
|
### Parsing the Token
|
|
@@ -72,7 +77,7 @@ console.log("Detokenized Payload:", detokenizedData);
|
|
|
72
77
|
The tokenized payload is a string that contains the tokenized values. To parse the tokenized payload, you can use the `parseToken` method.
|
|
73
78
|
|
|
74
79
|
```javascript
|
|
75
|
-
const token = Tokenization.parseToken(
|
|
80
|
+
const token = Tokenization.parseToken('token:tenant1:str:asdf1234');
|
|
76
81
|
console.log(`Is Token: ${token.isToken}`);
|
|
77
82
|
console.log(`Tenant: ${token.tenant}`);
|
|
78
83
|
console.log(`Type: ${token.type}`);
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Tokenization Service Node.js
|
|
2
|
+
|
|
3
|
+
This README provides instructions on how to use the `Tokenization` class in the Tokenization Service Node.js project.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the necessary dependencies, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save @edirect/tokenization
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Important Note
|
|
14
|
+
|
|
15
|
+
This client **caches** the **configurations** for `5 minutes` and the **tokens** for `1 minute`.
|
|
16
|
+
|
|
17
|
+
This is to avoid making unnecessary requests to the tokenization service. If you want to change any configuration on the tokenization service, you'll need to wait for the cache to expire.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
The `Tokenization` class provides methods to tokenize and detokenize payloads. Below is an example of how to use the class.
|
|
22
|
+
|
|
23
|
+
### Importing the Tokenization Class
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import { Tokenization } from '@edirect/tokenization';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Creating an Instance
|
|
30
|
+
|
|
31
|
+
To create an instance of the `Tokenization` class, you need to provide the base URL of the tokenization service.
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const baseUrl = 'https://tokenization-service.api.example.com';
|
|
35
|
+
const tokenization = new Tokenization(baseUrl);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Tokenizing a Payload
|
|
39
|
+
|
|
40
|
+
To tokenize a payload, use the `tokenize` method. You need to provide the authentication token, tenant, configuration, and the payload to be tokenized.
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
const auth = 'your-auth-token';
|
|
44
|
+
const tenant = 'your-tenant';
|
|
45
|
+
const config = 'your-config';
|
|
46
|
+
const payload = {
|
|
47
|
+
name: 'John Doe',
|
|
48
|
+
email: 'johndoe@test.com',
|
|
49
|
+
phone: '123-456-7890'
|
|
50
|
+
payment: {
|
|
51
|
+
cardNumber: '1234 5678 9012 3456',
|
|
52
|
+
expirationDate: '12/23',
|
|
53
|
+
cvv: '123'
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const tokenizedData = await tokenization.tokenize(auth, tenant, config, payload);
|
|
58
|
+
console.log('Tokenized Payload:', tokenizedData);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Detokenizing a Payload
|
|
62
|
+
|
|
63
|
+
To detokenize a payload, use the `detokenize` method. You need to provide the authentication token, tenant, configuration, and the payload to be detokenized.
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
const detokenizedData = await tokenization.detokenize(
|
|
67
|
+
auth,
|
|
68
|
+
tenant,
|
|
69
|
+
config,
|
|
70
|
+
payload
|
|
71
|
+
);
|
|
72
|
+
console.log('Detokenized Payload:', detokenizedData);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Parsing the Token
|
|
76
|
+
|
|
77
|
+
The tokenized payload is a string that contains the tokenized values. To parse the tokenized payload, you can use the `parseToken` method.
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
const token = Tokenization.parseToken('token:tenant1:str:asdf1234');
|
|
81
|
+
console.log(`Is Token: ${token.isToken}`);
|
|
82
|
+
console.log(`Tenant: ${token.tenant}`);
|
|
83
|
+
console.log(`Type: ${token.type}`);
|
|
84
|
+
console.log(`Hash: ${token.Hash}`);
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## API
|
|
88
|
+
|
|
89
|
+
### `Tokenization`
|
|
90
|
+
|
|
91
|
+
#### `constructor(baseUrl: string)`
|
|
92
|
+
|
|
93
|
+
Creates an instance of the `Tokenization` class.
|
|
94
|
+
|
|
95
|
+
- `baseUrl`: The base URL of the tokenization service.
|
|
96
|
+
|
|
97
|
+
#### `tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>`
|
|
98
|
+
|
|
99
|
+
Tokenizes the given payload.
|
|
100
|
+
|
|
101
|
+
- `auth`: The authentication token.
|
|
102
|
+
- `tenant`: The tenant to tokenize the payload for.
|
|
103
|
+
- `config`: The configuration for tokenization.
|
|
104
|
+
- `payload`: The payload to tokenize.
|
|
105
|
+
|
|
106
|
+
#### `detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>`
|
|
107
|
+
|
|
108
|
+
Detokenizes the given payload.
|
|
109
|
+
|
|
110
|
+
- `auth`: The authentication token.
|
|
111
|
+
- `tenant`: The tenant to detokenize the payload for.
|
|
112
|
+
- `config`: The configuration for detokenization.
|
|
113
|
+
- `payload`: The payload to detokenize.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edirect/tokenization",
|
|
3
|
+
"version": "11.0.25",
|
|
4
|
+
"description": "Javascript library for tokenization service",
|
|
5
|
+
"main": "./dist/src/index.js",
|
|
6
|
+
"types": "./dist/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"development": "./src/index.ts",
|
|
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.1.0",
|
|
28
|
+
"vitest": "3.2.4",
|
|
29
|
+
"tslib": "^2.8.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^24.3.0",
|
|
33
|
+
"typescript": "^5.9.2"
|
|
34
|
+
},
|
|
35
|
+
"type": "commonjs"
|
|
36
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,114 @@
|
|
|
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;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,82 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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;
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|