@edirect/tokenization 0.0.8 → 0.0.10

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/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -212,6 +222,7 @@ var TokenizationApp = class {
212
222
  notFound: {}
213
223
  };
214
224
  traverse(payload, (value, path) => {
225
+ if (!value) return;
215
226
  if (this.evaluator.shouldTokenizeField(config, path)) {
216
227
  const fromCache = this.cache.get(value.toString());
217
228
  if (fromCache) {
@@ -227,6 +238,7 @@ var TokenizationApp = class {
227
238
 
228
239
  // src/core/services/configuration.ts
229
240
  var import_lru_cache2 = require("lru-cache");
241
+ var import_axios = __toESM(require("axios"));
230
242
  var ConfigurationService = class {
231
243
  constructor(baseUrl) {
232
244
  this.baseUrl = baseUrl;
@@ -248,76 +260,77 @@ var ConfigurationService = class {
248
260
  if (cached) {
249
261
  return cached;
250
262
  }
251
- const resp = await fetch(
252
- `${this.baseUrl}/api/v1/${tenant}/${config}/config`,
253
- {
254
- method: "GET",
255
- headers: {
256
- Authorization: `Bearer ${auth}`
263
+ try {
264
+ const resp = await import_axios.default.get(
265
+ `${this.baseUrl}/api/v1/${tenant}/${config}/config`,
266
+ {
267
+ headers: {
268
+ Authorization: `Bearer ${auth}`
269
+ }
257
270
  }
271
+ );
272
+ const data = resp.data;
273
+ this.cache.set(`${tenant}/${config}`, data);
274
+ return data;
275
+ } catch (error) {
276
+ if (import_axios.default.isAxiosError(error) && error.response?.status === 404) {
277
+ return void 0;
258
278
  }
259
- );
260
- if (resp.status === 404) {
261
- return void 0;
262
- }
263
- if (resp.status !== 200) {
264
279
  throw new Error("Failed to get configuration");
265
280
  }
266
- const data = await resp.json();
267
- this.cache.set(`${tenant}/${config}`, data);
268
- return data;
269
281
  }
270
282
  async create(auth, tenant, config) {
271
- const resp = await fetch(
272
- `${this.baseUrl}/api/v1/${tenant}/${config.key}/config`,
273
- {
274
- method: "POST",
275
- body: JSON.stringify(config),
276
- headers: {
277
- Authorization: `Bearer ${auth}`,
278
- "Content-Type": "application/json"
283
+ try {
284
+ await import_axios.default.post(
285
+ `${this.baseUrl}/api/v1/${tenant}/${config.key}/config`,
286
+ config,
287
+ {
288
+ headers: {
289
+ Authorization: `Bearer ${auth}`,
290
+ "Content-Type": "application/json"
291
+ }
279
292
  }
280
- }
281
- );
282
- if (resp.status !== 200) {
293
+ );
294
+ return config;
295
+ } catch (error) {
283
296
  throw new Error("Failed to create configuration");
284
297
  }
285
- return config;
286
298
  }
287
299
  async update(auth, tenant, config) {
288
- const respo = await fetch(
289
- `${this.baseUrl}/api/v1/${tenant}/${config.key}/config`,
290
- {
291
- method: "PUT",
292
- body: JSON.stringify(config),
293
- headers: {
294
- Authorization: `Bearer ${auth}`,
295
- "Content-Type": "application/json"
300
+ try {
301
+ await import_axios.default.put(
302
+ `${this.baseUrl}/api/v1/${tenant}/${config.key}/config`,
303
+ config,
304
+ {
305
+ headers: {
306
+ Authorization: `Bearer ${auth}`,
307
+ "Content-Type": "application/json"
308
+ }
296
309
  }
297
- }
298
- );
299
- if (respo.status !== 200) {
310
+ );
311
+ return config;
312
+ } catch (error) {
300
313
  throw new Error("Failed to update configuration");
301
314
  }
302
- return config;
303
315
  }
304
316
  async delete(auth, tenant, config) {
305
- const resp = await fetch(
306
- `${this.baseUrl}/api/v1/${tenant}/${config}/config`,
307
- {
308
- method: "DELETE",
309
- headers: {
310
- Authorization: `Bearer ${auth}`
317
+ try {
318
+ await import_axios.default.delete(
319
+ `${this.baseUrl}/api/v1/${tenant}/${config}/config`,
320
+ {
321
+ headers: {
322
+ Authorization: `Bearer ${auth}`
323
+ }
311
324
  }
312
- }
313
- );
314
- if (resp.status !== 204) {
325
+ );
326
+ } catch (error) {
315
327
  throw new Error("Failed to delete configuration");
316
328
  }
317
329
  }
318
330
  };
319
331
 
320
332
  // src/core/services/tokenization.ts
333
+ var import_axios2 = __toESM(require("axios"));
321
334
  var TokenizationService = class {
322
335
  constructor(baseUrl) {
323
336
  this.baseUrl = baseUrl;
@@ -326,40 +339,38 @@ var TokenizationService = class {
326
339
  }
327
340
  }
328
341
  async tokenize(auth, tenant, config, payload) {
329
- const resp = await fetch(
330
- `${this.baseUrl}/api/v1/${tenant}/${config}/token/tokenize`,
331
- {
332
- method: "POST",
333
- body: JSON.stringify(payload),
334
- headers: {
335
- "Authorization": `Bearer ${auth}`,
336
- "Content-Type": "application/json"
342
+ try {
343
+ const resp = await import_axios2.default.post(
344
+ `${this.baseUrl}/api/v1/${tenant}/${config}/token/tokenize`,
345
+ payload,
346
+ {
347
+ headers: {
348
+ "Authorization": `Bearer ${auth}`,
349
+ "Content-Type": "application/json"
350
+ }
337
351
  }
338
- }
339
- );
340
- if (resp.status !== 200) {
352
+ );
353
+ return resp.data;
354
+ } catch (error) {
341
355
  throw new Error("Failed to tokenize payload");
342
356
  }
343
- const data = await resp.json();
344
- return data;
345
357
  }
346
358
  async detokenize(auth, tenant, config, payload) {
347
- const resp = await fetch(
348
- `${this.baseUrl}/api/v1/${tenant}/${config}/token/detokenize`,
349
- {
350
- method: "POST",
351
- body: JSON.stringify(payload),
352
- headers: {
353
- "Authorization": `Bearer ${auth}`,
354
- "Content-Type": "application/json"
359
+ try {
360
+ const resp = await import_axios2.default.post(
361
+ `${this.baseUrl}/api/v1/${tenant}/${config}/token/detokenize`,
362
+ payload,
363
+ {
364
+ headers: {
365
+ "Authorization": `Bearer ${auth}`,
366
+ "Content-Type": "application/json"
367
+ }
355
368
  }
356
- }
357
- );
358
- if (resp.status !== 200) {
369
+ );
370
+ return resp.data;
371
+ } catch (error) {
359
372
  throw new Error("Failed to detokenize payload");
360
373
  }
361
- const data = await resp.json();
362
- return data;
363
374
  }
364
375
  };
365
376
 
package/dist/index.mjs CHANGED
@@ -186,6 +186,7 @@ var TokenizationApp = class {
186
186
  notFound: {}
187
187
  };
188
188
  traverse(payload, (value, path) => {
189
+ if (!value) return;
189
190
  if (this.evaluator.shouldTokenizeField(config, path)) {
190
191
  const fromCache = this.cache.get(value.toString());
191
192
  if (fromCache) {
@@ -201,6 +202,7 @@ var TokenizationApp = class {
201
202
 
202
203
  // src/core/services/configuration.ts
203
204
  import { LRUCache as LRUCache2 } from "lru-cache";
205
+ import axios from "axios";
204
206
  var ConfigurationService = class {
205
207
  constructor(baseUrl) {
206
208
  this.baseUrl = baseUrl;
@@ -222,76 +224,77 @@ var ConfigurationService = class {
222
224
  if (cached) {
223
225
  return cached;
224
226
  }
225
- const resp = await fetch(
226
- `${this.baseUrl}/api/v1/${tenant}/${config}/config`,
227
- {
228
- method: "GET",
229
- headers: {
230
- Authorization: `Bearer ${auth}`
227
+ try {
228
+ const resp = await axios.get(
229
+ `${this.baseUrl}/api/v1/${tenant}/${config}/config`,
230
+ {
231
+ headers: {
232
+ Authorization: `Bearer ${auth}`
233
+ }
231
234
  }
235
+ );
236
+ const data = resp.data;
237
+ this.cache.set(`${tenant}/${config}`, data);
238
+ return data;
239
+ } catch (error) {
240
+ if (axios.isAxiosError(error) && error.response?.status === 404) {
241
+ return void 0;
232
242
  }
233
- );
234
- if (resp.status === 404) {
235
- return void 0;
236
- }
237
- if (resp.status !== 200) {
238
243
  throw new Error("Failed to get configuration");
239
244
  }
240
- const data = await resp.json();
241
- this.cache.set(`${tenant}/${config}`, data);
242
- return data;
243
245
  }
244
246
  async create(auth, tenant, config) {
245
- const resp = await fetch(
246
- `${this.baseUrl}/api/v1/${tenant}/${config.key}/config`,
247
- {
248
- method: "POST",
249
- body: JSON.stringify(config),
250
- headers: {
251
- Authorization: `Bearer ${auth}`,
252
- "Content-Type": "application/json"
247
+ try {
248
+ await axios.post(
249
+ `${this.baseUrl}/api/v1/${tenant}/${config.key}/config`,
250
+ config,
251
+ {
252
+ headers: {
253
+ Authorization: `Bearer ${auth}`,
254
+ "Content-Type": "application/json"
255
+ }
253
256
  }
254
- }
255
- );
256
- if (resp.status !== 200) {
257
+ );
258
+ return config;
259
+ } catch (error) {
257
260
  throw new Error("Failed to create configuration");
258
261
  }
259
- return config;
260
262
  }
261
263
  async update(auth, tenant, config) {
262
- const respo = await fetch(
263
- `${this.baseUrl}/api/v1/${tenant}/${config.key}/config`,
264
- {
265
- method: "PUT",
266
- body: JSON.stringify(config),
267
- headers: {
268
- Authorization: `Bearer ${auth}`,
269
- "Content-Type": "application/json"
264
+ try {
265
+ await axios.put(
266
+ `${this.baseUrl}/api/v1/${tenant}/${config.key}/config`,
267
+ config,
268
+ {
269
+ headers: {
270
+ Authorization: `Bearer ${auth}`,
271
+ "Content-Type": "application/json"
272
+ }
270
273
  }
271
- }
272
- );
273
- if (respo.status !== 200) {
274
+ );
275
+ return config;
276
+ } catch (error) {
274
277
  throw new Error("Failed to update configuration");
275
278
  }
276
- return config;
277
279
  }
278
280
  async delete(auth, tenant, config) {
279
- const resp = await fetch(
280
- `${this.baseUrl}/api/v1/${tenant}/${config}/config`,
281
- {
282
- method: "DELETE",
283
- headers: {
284
- Authorization: `Bearer ${auth}`
281
+ try {
282
+ await axios.delete(
283
+ `${this.baseUrl}/api/v1/${tenant}/${config}/config`,
284
+ {
285
+ headers: {
286
+ Authorization: `Bearer ${auth}`
287
+ }
285
288
  }
286
- }
287
- );
288
- if (resp.status !== 204) {
289
+ );
290
+ } catch (error) {
289
291
  throw new Error("Failed to delete configuration");
290
292
  }
291
293
  }
292
294
  };
293
295
 
294
296
  // src/core/services/tokenization.ts
297
+ import axios2 from "axios";
295
298
  var TokenizationService = class {
296
299
  constructor(baseUrl) {
297
300
  this.baseUrl = baseUrl;
@@ -300,40 +303,38 @@ var TokenizationService = class {
300
303
  }
301
304
  }
302
305
  async tokenize(auth, tenant, config, payload) {
303
- const resp = await fetch(
304
- `${this.baseUrl}/api/v1/${tenant}/${config}/token/tokenize`,
305
- {
306
- method: "POST",
307
- body: JSON.stringify(payload),
308
- headers: {
309
- "Authorization": `Bearer ${auth}`,
310
- "Content-Type": "application/json"
306
+ try {
307
+ const resp = await axios2.post(
308
+ `${this.baseUrl}/api/v1/${tenant}/${config}/token/tokenize`,
309
+ payload,
310
+ {
311
+ headers: {
312
+ "Authorization": `Bearer ${auth}`,
313
+ "Content-Type": "application/json"
314
+ }
311
315
  }
312
- }
313
- );
314
- if (resp.status !== 200) {
316
+ );
317
+ return resp.data;
318
+ } catch (error) {
315
319
  throw new Error("Failed to tokenize payload");
316
320
  }
317
- const data = await resp.json();
318
- return data;
319
321
  }
320
322
  async detokenize(auth, tenant, config, payload) {
321
- const resp = await fetch(
322
- `${this.baseUrl}/api/v1/${tenant}/${config}/token/detokenize`,
323
- {
324
- method: "POST",
325
- body: JSON.stringify(payload),
326
- headers: {
327
- "Authorization": `Bearer ${auth}`,
328
- "Content-Type": "application/json"
323
+ try {
324
+ const resp = await axios2.post(
325
+ `${this.baseUrl}/api/v1/${tenant}/${config}/token/detokenize`,
326
+ payload,
327
+ {
328
+ headers: {
329
+ "Authorization": `Bearer ${auth}`,
330
+ "Content-Type": "application/json"
331
+ }
329
332
  }
330
- }
331
- );
332
- if (resp.status !== 200) {
333
+ );
334
+ return resp.data;
335
+ } catch (error) {
333
336
  throw new Error("Failed to detokenize payload");
334
337
  }
335
- const data = await resp.json();
336
- return data;
337
338
  }
338
339
  };
339
340
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/tokenization",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Javascript library for tokenization service",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -34,6 +34,7 @@
34
34
  "vitest": "^2.1.8"
35
35
  },
36
36
  "dependencies": {
37
+ "axios": "^1.7.9",
37
38
  "lru-cache": "^11.0.2"
38
39
  }
39
40
  }