@edirect/tokenization 0.0.1 → 0.0.2

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 ADDED
@@ -0,0 +1,90 @@
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
+ ## Usage
14
+
15
+ The `Tokenization` class provides methods to tokenize and detokenize payloads. Below is an example of how to use the class.
16
+
17
+ ### Importing the Tokenization Class
18
+
19
+ ```javascript
20
+ import { Tokenization } from "@edirect/tokenization";
21
+ ```
22
+
23
+ ### Creating an Instance
24
+
25
+ To create an instance of the `Tokenization` class, you need to provide the base URL of the tokenization service.
26
+
27
+ ```javascript
28
+ const baseUrl = "https://tokenization-service.api.example.com";
29
+ const tokenization = new Tokenization(baseUrl);
30
+ ```
31
+
32
+ ### Tokenizing a Payload
33
+
34
+ To tokenize a payload, use the `tokenize` method. You need to provide the authentication token, tenant, configuration, and the payload to be tokenized.
35
+
36
+ ```javascript
37
+ const auth = 'your-auth-token';
38
+ const tenant = 'your-tenant';
39
+ const config = 'your-config';
40
+ const payload = {
41
+ name: 'John Doe',
42
+ email: 'johndoe@test.com',
43
+ phone: '123-456-7890'
44
+ payment: {
45
+ cardNumber: '1234 5678 9012 3456',
46
+ expirationDate: '12/23',
47
+ cvv: '123'
48
+ }
49
+ };
50
+
51
+ const tokenizedData = await tokenization.tokenize(auth, tenant, config, payload);
52
+ console.log('Tokenized Payload:', tokenizedData);
53
+ ```
54
+
55
+ ### Detokenizing a Payload
56
+
57
+ To detokenize a payload, use the `detokenize` method. You need to provide the authentication token, tenant, configuration, and the payload to be detokenized.
58
+
59
+ ```javascript
60
+ const detokenizedData = await tokenization.detokenize(auth, tenant, config, payload);
61
+ console.log("Detokenized Payload:", detokenizedData);
62
+ ```
63
+
64
+ ## API
65
+
66
+ ### `Tokenization`
67
+
68
+ #### `constructor(baseUrl: string)`
69
+
70
+ Creates an instance of the `Tokenization` class.
71
+
72
+ - `baseUrl`: The base URL of the tokenization service.
73
+
74
+ #### `tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>`
75
+
76
+ Tokenizes the given payload.
77
+
78
+ - `auth`: The authentication token.
79
+ - `tenant`: The tenant to tokenize the payload for.
80
+ - `config`: The configuration for tokenization.
81
+ - `payload`: The payload to tokenize.
82
+
83
+ #### `detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>`
84
+
85
+ Detokenizes the given payload.
86
+
87
+ - `auth`: The authentication token.
88
+ - `tenant`: The tenant to detokenize the payload for.
89
+ - `config`: The configuration for detokenization.
90
+ - `payload`: The payload to detokenize.
package/dist/index.d.mts CHANGED
@@ -1,76 +1,8 @@
1
- /**
2
- * @file This file contains the models used in the application.
3
- */
4
-
5
- /**
6
- * The classification of a field.
7
- * 0: The field is not sensitive.
8
- * 1: The field is sensitive.
9
- */
10
- type Classification = 0 | 1;
11
- /**
12
- * The model of a field classification.
13
- * @property path The path of the field.
14
- * @property classification The classification of the field.
15
- * @example
16
- * {
17
- * path: "data.*.name",
18
- * classification: 1
19
- * }
20
- * @see Classification
21
- */
22
- type FieldClassification = {
23
- path: string;
24
- classification: Classification;
25
- };
26
- /**
27
- * The model of a configuration.
28
- * @property key The key of the configuration.
29
- * @property tenant The tenant of the configuration.
30
- * @property defaultClassification The default classification of the configuration.
31
- * @property fields The fields of the configuration.
32
- * @example
33
- * {
34
- * key: "configuration",
35
- * tenant: "tenant",
36
- * defaultClassification: 0,
37
- * fields: [
38
- * {
39
- * path: "data.*.name",
40
- * classification: 1
41
- * }
42
- * ]
43
- * }
44
- * @see FieldClassification
45
- * @see Classification
46
- */
47
- type Configuration = {
48
- key: string;
49
- tenant: string;
50
- defaultClassification: Classification;
51
- fields: FieldClassification[];
52
- };
53
1
  /**
54
2
  * The model of a token payload.
55
3
  */
56
4
  type TokenPayload = Record<string, unknown>;
57
- type TokenizationClientConfig = {
58
- services?: {
59
- tokenizationService?: ITokenizationService;
60
- configurationService?: IConfigurationService;
61
- };
62
- };
63
5
 
64
- interface ITokenizationService {
65
- tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
66
- detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
67
- }
68
- interface IConfigurationService {
69
- get(auth: string, tenant: string, config: string): Promise<Configuration | undefined>;
70
- create(auth: string, tenant: string, config: Configuration): Promise<Configuration>;
71
- update(auth: string, tenant: string, config: Configuration): Promise<Configuration>;
72
- delete(auth: string, tenant: string, config: string): Promise<void>;
73
- }
74
6
  interface ITokenizationApp {
75
7
  tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
76
8
  detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
@@ -85,7 +17,7 @@ declare class Tokenization {
85
17
  * The constructor of the TokenizationClient class.
86
18
  * @param url The URL of the tokenization server.
87
19
  */
88
- constructor(configOrApp?: TokenizationClientConfig | ITokenizationApp);
20
+ constructor(baseUrlOrApp?: string | ITokenizationApp);
89
21
  /**
90
22
  * Tokenizes the given payload.
91
23
  * @param tenant The tenant to tokenize the payload for.
package/dist/index.d.ts CHANGED
@@ -1,76 +1,8 @@
1
- /**
2
- * @file This file contains the models used in the application.
3
- */
4
-
5
- /**
6
- * The classification of a field.
7
- * 0: The field is not sensitive.
8
- * 1: The field is sensitive.
9
- */
10
- type Classification = 0 | 1;
11
- /**
12
- * The model of a field classification.
13
- * @property path The path of the field.
14
- * @property classification The classification of the field.
15
- * @example
16
- * {
17
- * path: "data.*.name",
18
- * classification: 1
19
- * }
20
- * @see Classification
21
- */
22
- type FieldClassification = {
23
- path: string;
24
- classification: Classification;
25
- };
26
- /**
27
- * The model of a configuration.
28
- * @property key The key of the configuration.
29
- * @property tenant The tenant of the configuration.
30
- * @property defaultClassification The default classification of the configuration.
31
- * @property fields The fields of the configuration.
32
- * @example
33
- * {
34
- * key: "configuration",
35
- * tenant: "tenant",
36
- * defaultClassification: 0,
37
- * fields: [
38
- * {
39
- * path: "data.*.name",
40
- * classification: 1
41
- * }
42
- * ]
43
- * }
44
- * @see FieldClassification
45
- * @see Classification
46
- */
47
- type Configuration = {
48
- key: string;
49
- tenant: string;
50
- defaultClassification: Classification;
51
- fields: FieldClassification[];
52
- };
53
1
  /**
54
2
  * The model of a token payload.
55
3
  */
56
4
  type TokenPayload = Record<string, unknown>;
57
- type TokenizationClientConfig = {
58
- services?: {
59
- tokenizationService?: ITokenizationService;
60
- configurationService?: IConfigurationService;
61
- };
62
- };
63
5
 
64
- interface ITokenizationService {
65
- tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
66
- detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
67
- }
68
- interface IConfigurationService {
69
- get(auth: string, tenant: string, config: string): Promise<Configuration | undefined>;
70
- create(auth: string, tenant: string, config: Configuration): Promise<Configuration>;
71
- update(auth: string, tenant: string, config: Configuration): Promise<Configuration>;
72
- delete(auth: string, tenant: string, config: string): Promise<void>;
73
- }
74
6
  interface ITokenizationApp {
75
7
  tokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
76
8
  detokenize(auth: string, tenant: string, config: string, payload: TokenPayload): Promise<TokenPayload>;
@@ -85,7 +17,7 @@ declare class Tokenization {
85
17
  * The constructor of the TokenizationClient class.
86
18
  * @param url The URL of the tokenization server.
87
19
  */
88
- constructor(configOrApp?: TokenizationClientConfig | ITokenizationApp);
20
+ constructor(baseUrlOrApp?: string | ITokenizationApp);
89
21
  /**
90
22
  * Tokenizes the given payload.
91
23
  * @param tenant The tenant to tokenize the payload for.
package/dist/index.js CHANGED
@@ -291,22 +291,14 @@ var Tokenization = class {
291
291
  * The constructor of the TokenizationClient class.
292
292
  * @param url The URL of the tokenization server.
293
293
  */
294
- constructor(configOrApp) {
295
- if (configOrApp && "tokenize" in configOrApp && "detokenize" in configOrApp) {
296
- this.app = configOrApp;
294
+ constructor(baseUrlOrApp) {
295
+ if (baseUrlOrApp && typeof baseUrlOrApp !== "string") {
296
+ this.app = baseUrlOrApp;
297
297
  return;
298
298
  }
299
- if (configOrApp && "services" in configOrApp && configOrApp.services && "tokenizationService" in configOrApp.services && "configurationService" in configOrApp.services && configOrApp.services.tokenizationService && configOrApp.services.configurationService) {
300
- const tokenizationService2 = configOrApp.services.tokenizationService;
301
- const configurationService2 = configOrApp.services.configurationService;
302
- this.app = new TokenizationApp(tokenizationService2, configurationService2);
303
- return;
304
- }
305
- const tokenizationService = new TokenizationService(
306
- process.env.TOKENIZATION_SERVICE_BASE_URL
307
- );
299
+ const tokenizationService = new TokenizationService(baseUrlOrApp);
308
300
  const configurationService = new ConfigurationService(
309
- process.env.CONFIGURATION_SERVICE_BASE_URL
301
+ baseUrlOrApp
310
302
  );
311
303
  this.app = new TokenizationApp(tokenizationService, configurationService);
312
304
  return;
package/dist/index.mjs CHANGED
@@ -265,22 +265,14 @@ var Tokenization = class {
265
265
  * The constructor of the TokenizationClient class.
266
266
  * @param url The URL of the tokenization server.
267
267
  */
268
- constructor(configOrApp) {
269
- if (configOrApp && "tokenize" in configOrApp && "detokenize" in configOrApp) {
270
- this.app = configOrApp;
268
+ constructor(baseUrlOrApp) {
269
+ if (baseUrlOrApp && typeof baseUrlOrApp !== "string") {
270
+ this.app = baseUrlOrApp;
271
271
  return;
272
272
  }
273
- if (configOrApp && "services" in configOrApp && configOrApp.services && "tokenizationService" in configOrApp.services && "configurationService" in configOrApp.services && configOrApp.services.tokenizationService && configOrApp.services.configurationService) {
274
- const tokenizationService2 = configOrApp.services.tokenizationService;
275
- const configurationService2 = configOrApp.services.configurationService;
276
- this.app = new TokenizationApp(tokenizationService2, configurationService2);
277
- return;
278
- }
279
- const tokenizationService = new TokenizationService(
280
- process.env.TOKENIZATION_SERVICE_BASE_URL
281
- );
273
+ const tokenizationService = new TokenizationService(baseUrlOrApp);
282
274
  const configurationService = new ConfigurationService(
283
- process.env.CONFIGURATION_SERVICE_BASE_URL
275
+ baseUrlOrApp
284
276
  );
285
277
  this.app = new TokenizationApp(tokenizationService, configurationService);
286
278
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/tokenization",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Javascript library for tokenization service",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",