@keetanetwork/anchor 0.0.21 → 0.0.23

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 (67) hide show
  1. package/config.d.ts +1 -1
  2. package/config.d.ts.map +1 -1
  3. package/config.js +1 -1
  4. package/config.js.map +1 -1
  5. package/lib/certificates.d.ts +4 -1
  6. package/lib/certificates.d.ts.map +1 -1
  7. package/lib/certificates.js +148 -14
  8. package/lib/certificates.js.map +1 -1
  9. package/lib/error.d.ts +35 -0
  10. package/lib/error.d.ts.map +1 -1
  11. package/lib/error.js +203 -7
  12. package/lib/error.js.map +1 -1
  13. package/lib/http-server/common.d.ts +6 -0
  14. package/lib/http-server/common.d.ts.map +1 -0
  15. package/lib/http-server/common.js +2 -0
  16. package/lib/http-server/common.js.map +1 -0
  17. package/lib/{http-server.d.ts → http-server/index.d.ts} +30 -12
  18. package/lib/http-server/index.d.ts.map +1 -0
  19. package/lib/{http-server.js → http-server/index.js} +107 -46
  20. package/lib/http-server/index.js.map +1 -0
  21. package/lib/resolver.d.ts +5 -2
  22. package/lib/resolver.d.ts.map +1 -1
  23. package/lib/resolver.js +15 -2
  24. package/lib/resolver.js.map +1 -1
  25. package/lib/utils/asn1.d.ts +0 -13
  26. package/lib/utils/asn1.d.ts.map +1 -1
  27. package/lib/utils/asn1.js +0 -1498
  28. package/lib/utils/asn1.js.map +1 -1
  29. package/lib/utils/external.d.ts.map +1 -1
  30. package/lib/utils/external.js +9 -2
  31. package/lib/utils/external.js.map +1 -1
  32. package/npm-shrinkwrap.json +5 -5
  33. package/package.json +2 -2
  34. package/services/asset-movement/client.d.ts +1 -0
  35. package/services/asset-movement/client.d.ts.map +1 -1
  36. package/services/asset-movement/client.js +13 -9
  37. package/services/asset-movement/client.js.map +1 -1
  38. package/services/asset-movement/common.d.ts +1 -1
  39. package/services/asset-movement/common.d.ts.map +1 -1
  40. package/services/asset-movement/common.js.map +1 -1
  41. package/services/asset-movement/server.d.ts +1 -1
  42. package/services/asset-movement/server.d.ts.map +1 -1
  43. package/services/asset-movement/server.js +1 -1
  44. package/services/asset-movement/server.js.map +1 -1
  45. package/services/fx/common.d.ts +15 -5
  46. package/services/fx/common.d.ts.map +1 -1
  47. package/services/fx/common.js +29 -0
  48. package/services/fx/common.js.map +1 -1
  49. package/services/fx/server.d.ts +12 -2
  50. package/services/fx/server.d.ts.map +1 -1
  51. package/services/fx/server.js +9 -2
  52. package/services/fx/server.js.map +1 -1
  53. package/services/kyc/common.d.ts +3 -5
  54. package/services/kyc/common.d.ts.map +1 -1
  55. package/services/kyc/common.generated.js +2 -2
  56. package/services/kyc/common.js +1 -0
  57. package/services/kyc/common.js.map +1 -1
  58. package/services/kyc/iso20022.generated.js +54 -54
  59. package/services/kyc/iso20022.generated.js.map +1 -1
  60. package/services/kyc/server.d.ts +1 -1
  61. package/services/kyc/server.d.ts.map +1 -1
  62. package/services/kyc/server.js +1 -1
  63. package/services/kyc/server.js.map +1 -1
  64. package/services/kyc/utils/generate-kyc-schema.js +34 -6
  65. package/services/kyc/utils/generate-kyc-schema.js.map +1 -1
  66. package/lib/http-server.d.ts.map +0 -1
  67. package/lib/http-server.js.map +0 -1
package/lib/error.js CHANGED
@@ -1,3 +1,6 @@
1
+ import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard.js";
2
+ import * as __typia_transform__accessExpressionAsString from "typia/lib/internal/_accessExpressionAsString.js";
3
+ import { createAssertEquals, createIs } from 'typia';
1
4
  /**
2
5
  * Lazy-loaded error classes to avoid circular dependencies
3
6
  * The classes are loaded on first use
@@ -7,20 +10,23 @@ async function getErrorClassMapping() {
7
10
  if (ERROR_CLASS_MAPPING) {
8
11
  return (ERROR_CLASS_MAPPING);
9
12
  }
10
- // Dynamically import KYC errors to avoid circular dependencies
11
- const kycModule = await import('../services/kyc/common.js');
12
- const KYCErrors = kycModule.Errors;
13
13
  const ERROR_CLASSES = [
14
14
  /*
15
15
  * We purposefully leave out KeetaAnchorError here since it
16
16
  * is the base error class and could cause circular resolution
17
17
  */
18
18
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
19
- KeetaAnchorUserError,
20
- KYCErrors.VerificationNotFound,
21
- KYCErrors.CertificateNotFound,
22
- KYCErrors.PaymentRequired
19
+ KeetaAnchorUserError, KeetaAnchorUserValidationError
23
20
  ];
21
+ // Dynamically import errors to avoid circular dependencies
22
+ const importPromises = await Promise.all([
23
+ import('../services/kyc/common.js'),
24
+ import('../services/fx/common.js')
25
+ ]);
26
+ for (const module of importPromises) {
27
+ const classes = Object.values(module.Errors);
28
+ ERROR_CLASSES.push(...classes);
29
+ }
24
30
  const mapping = {};
25
31
  for (const errorClass of ERROR_CLASSES) {
26
32
  mapping[errorClass.name] = errorClass.fromJSON.bind(errorClass);
@@ -39,6 +45,7 @@ export class KeetaAnchorError extends Error {
39
45
  keetaAnchorErrorObjectTypeID;
40
46
  static keetaAnchorErrorObjectTypeID = '5d7f1578-e887-4104-bab0-4115ae33b08f';
41
47
  userError = false;
48
+ logLevel = 'ERROR';
42
49
  get name() {
43
50
  return (this.#name);
44
51
  }
@@ -214,4 +221,193 @@ export class KeetaAnchorUserError extends KeetaAnchorError {
214
221
  return (error);
215
222
  }
216
223
  }
224
+ const assertKeetaAnchorUserValidationErrorDetails = (() => { const _io0 = (input, _exceptionable = true) => Array.isArray(input.fields) && input.fields.every((elem, _index1) => "object" === typeof elem && null !== elem && _io1(elem, true && _exceptionable)) && (1 === Object.keys(input).length || Object.keys(input).every(key => {
225
+ if (["fields"].some(prop => key === prop))
226
+ return true;
227
+ const value = input[key];
228
+ if (undefined === value)
229
+ return true;
230
+ return false;
231
+ })); const _io1 = (input, _exceptionable = true) => (undefined === input.path || "string" === typeof input.path) && "string" === typeof input.message && (undefined === input.allowedValues || Array.isArray(input.allowedValues) && input.allowedValues.every((elem, _index2) => "string" === typeof elem)) && (undefined === input.expected || "string" === typeof input.expected) && true && (1 === Object.keys(input).length || Object.keys(input).every(key => {
232
+ if (["path", "message", "allowedValues", "expected", "receivedValue"].some(prop => key === prop))
233
+ return true;
234
+ const value = input[key];
235
+ if (undefined === value)
236
+ return true;
237
+ return false;
238
+ })); const _ao0 = (input, _path, _exceptionable = true) => ((Array.isArray(input.fields) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
239
+ method: "createAssertEquals",
240
+ path: _path + ".fields",
241
+ expected: "Array<__type>",
242
+ value: input.fields
243
+ }, _errorFactory)) && input.fields.every((elem, _index3) => ("object" === typeof elem && null !== elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
244
+ method: "createAssertEquals",
245
+ path: _path + ".fields[" + _index3 + "]",
246
+ expected: "__type",
247
+ value: elem
248
+ }, _errorFactory)) && _ao1(elem, _path + ".fields[" + _index3 + "]", true && _exceptionable) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
249
+ method: "createAssertEquals",
250
+ path: _path + ".fields[" + _index3 + "]",
251
+ expected: "__type",
252
+ value: elem
253
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
254
+ method: "createAssertEquals",
255
+ path: _path + ".fields",
256
+ expected: "Array<__type>",
257
+ value: input.fields
258
+ }, _errorFactory)) && (1 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).every(key => {
259
+ if (["fields"].some(prop => key === prop))
260
+ return true;
261
+ const value = input[key];
262
+ if (undefined === value)
263
+ return true;
264
+ return __typia_transform__assertGuard._assertGuard(_exceptionable, {
265
+ method: "createAssertEquals",
266
+ path: _path + __typia_transform__accessExpressionAsString._accessExpressionAsString(key),
267
+ expected: "undefined",
268
+ value: value
269
+ }, _errorFactory);
270
+ }))); const _ao1 = (input, _path, _exceptionable = true) => (undefined === input.path || "string" === typeof input.path || __typia_transform__assertGuard._assertGuard(_exceptionable, {
271
+ method: "createAssertEquals",
272
+ path: _path + ".path",
273
+ expected: "(string | undefined)",
274
+ value: input.path
275
+ }, _errorFactory)) && ("string" === typeof input.message || __typia_transform__assertGuard._assertGuard(_exceptionable, {
276
+ method: "createAssertEquals",
277
+ path: _path + ".message",
278
+ expected: "string",
279
+ value: input.message
280
+ }, _errorFactory)) && (undefined === input.allowedValues || (Array.isArray(input.allowedValues) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
281
+ method: "createAssertEquals",
282
+ path: _path + ".allowedValues",
283
+ expected: "(Array<string> | undefined)",
284
+ value: input.allowedValues
285
+ }, _errorFactory)) && input.allowedValues.every((elem, _index4) => "string" === typeof elem || __typia_transform__assertGuard._assertGuard(_exceptionable, {
286
+ method: "createAssertEquals",
287
+ path: _path + ".allowedValues[" + _index4 + "]",
288
+ expected: "string",
289
+ value: elem
290
+ }, _errorFactory)) || __typia_transform__assertGuard._assertGuard(_exceptionable, {
291
+ method: "createAssertEquals",
292
+ path: _path + ".allowedValues",
293
+ expected: "(Array<string> | undefined)",
294
+ value: input.allowedValues
295
+ }, _errorFactory)) && (undefined === input.expected || "string" === typeof input.expected || __typia_transform__assertGuard._assertGuard(_exceptionable, {
296
+ method: "createAssertEquals",
297
+ path: _path + ".expected",
298
+ expected: "(string | undefined)",
299
+ value: input.expected
300
+ }, _errorFactory)) && true && (1 === Object.keys(input).length || (false === _exceptionable || Object.keys(input).every(key => {
301
+ if (["path", "message", "allowedValues", "expected", "receivedValue"].some(prop => key === prop))
302
+ return true;
303
+ const value = input[key];
304
+ if (undefined === value)
305
+ return true;
306
+ return __typia_transform__assertGuard._assertGuard(_exceptionable, {
307
+ method: "createAssertEquals",
308
+ path: _path + __typia_transform__accessExpressionAsString._accessExpressionAsString(key),
309
+ expected: "undefined",
310
+ value: value
311
+ }, _errorFactory);
312
+ }))); const __is = (input, _exceptionable = true) => "object" === typeof input && null !== input && _io0(input, true); let _errorFactory; return (input, errorFactory) => {
313
+ if (false === __is(input)) {
314
+ _errorFactory = errorFactory;
315
+ ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || __typia_transform__assertGuard._assertGuard(true, {
316
+ method: "createAssertEquals",
317
+ path: _path + "",
318
+ expected: "KeetaAnchorUserValidationErrorDetails",
319
+ value: input
320
+ }, _errorFactory)) && _ao0(input, _path + "", true) || __typia_transform__assertGuard._assertGuard(true, {
321
+ method: "createAssertEquals",
322
+ path: _path + "",
323
+ expected: "KeetaAnchorUserValidationErrorDetails",
324
+ value: input
325
+ }, _errorFactory))(input, "$input", true);
326
+ }
327
+ return input;
328
+ }; })();
329
+ const isTypeGuardErrorLike = (() => { const _io0 = input => true && (undefined === input.path || "string" === typeof input.path) && "string" === typeof input.expected; return input => "object" === typeof input && null !== input && _io0(input); })();
330
+ export class KeetaAnchorUserValidationError extends KeetaAnchorUserError {
331
+ static isTypeGuardErrorLike = isTypeGuardErrorLike;
332
+ static name = 'KeetaAnchorUserValidationError';
333
+ KeetaAnchorUserValidationErrorObjectTypeID;
334
+ static KeetaAnchorUserValidationErrorObjectTypeID = '5fa46799-48b8-4cf2-a3de-9c01418d3ba0';
335
+ userError = true;
336
+ fields;
337
+ static isInstance(input) {
338
+ return (this.hasPropWithValue(input, 'KeetaAnchorUserValidationErrorObjectTypeID', KeetaAnchorUserValidationError.KeetaAnchorUserValidationErrorObjectTypeID));
339
+ }
340
+ constructor(args, message) {
341
+ super(message ?? `Validation error on fields ${args.fields.map((f) => f.path).join(', ')}`);
342
+ Object.defineProperty(this, 'KeetaAnchorUserValidationErrorObjectTypeID', {
343
+ value: KeetaAnchorUserValidationError.KeetaAnchorUserValidationErrorObjectTypeID,
344
+ enumerable: false
345
+ });
346
+ this.fields = args.fields;
347
+ }
348
+ get statusCode() {
349
+ return (400);
350
+ }
351
+ asErrorResponse(contentType) {
352
+ let message = this.message;
353
+ if (contentType === 'application/json') {
354
+ message = JSON.stringify({
355
+ ok: false,
356
+ name: this.name,
357
+ data: { fields: this.fields },
358
+ error: this.message
359
+ });
360
+ }
361
+ return ({
362
+ error: message,
363
+ statusCode: this.statusCode,
364
+ contentType: contentType
365
+ });
366
+ }
367
+ toJSON() {
368
+ return ({
369
+ ...super.toJSON(),
370
+ fields: this.fields
371
+ });
372
+ }
373
+ static async fromJSON(input) {
374
+ const { message, other } = this.extractErrorProperties(input, this);
375
+ if (!('data' in other)) {
376
+ throw (new Error('Invalid KeetaAnchorUserValidationError JSON: missing data property'));
377
+ }
378
+ const parsed = assertKeetaAnchorUserValidationErrorDetails(other.data);
379
+ const error = new this({ fields: parsed.fields }, message);
380
+ error.restoreFromJSON(other);
381
+ return (error);
382
+ }
383
+ static fromTypeGuardError(input, message) {
384
+ let asArr;
385
+ if (Array.isArray(input)) {
386
+ asArr = input;
387
+ }
388
+ else {
389
+ asArr = [input];
390
+ }
391
+ return (new this({
392
+ fields: asArr.map(function (single) {
393
+ let path;
394
+ if (single.path !== undefined) {
395
+ const split = single.path.split('.');
396
+ if (split[0] === '$input') {
397
+ split.shift();
398
+ }
399
+ if (split.length > 0) {
400
+ path = split.join('.');
401
+ }
402
+ }
403
+ return ({
404
+ path,
405
+ message: message ?? 'Invalid value',
406
+ expected: single.expected,
407
+ receivedValue: single.value
408
+ });
409
+ })
410
+ }, message));
411
+ }
412
+ }
217
413
  //# sourceMappingURL=error.js.map
package/lib/error.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/lib/error.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,IAAI,mBAAmB,GAA4E,IAAI,CAAC;AAExG,KAAK,UAAU,oBAAoB;IAClC,IAAI,mBAAmB,EAAE,CAAC;QACzB,OAAM,CAAC,mBAAmB,CAAC,CAAC;IAC7B,CAAC;IAED,+DAA+D;IAC/D,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;IAC5D,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;IAEnC,MAAM,aAAa,GAA+B;QACjD;;;WAGG;QACH,mEAAmE;QACnE,oBAAoB;QACpB,SAAS,CAAC,oBAAoB;QAC9B,SAAS,CAAC,mBAAmB;QAC7B,SAAS,CAAC,eAAe;KACzB,CAAC;IAEF,MAAM,OAAO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CAAC,KAAK,CAAC,eAAe,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAc;QACnC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACpE,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;QAChC,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAM,CAAC,KAAK,CAAC,CAAC;IACf,CAAC","sourcesContent":["/**\n * Type for error classes that can be deserialized\n */\ninterface DeserializableErrorClass {\n\treadonly name: string;\n\tfromJSON: (input: unknown) => Promise<KeetaAnchorError>;\n}\n\n/**\n * Lazy-loaded error classes to avoid circular dependencies\n * The classes are loaded on first use\n */\nlet ERROR_CLASS_MAPPING: { [key: string]: (input: unknown) => Promise<KeetaAnchorError> } | null = null;\n\nasync function getErrorClassMapping(): Promise<{ [key: string]: (input: unknown) => Promise<KeetaAnchorError> }> {\n\tif (ERROR_CLASS_MAPPING) {\n\t\treturn(ERROR_CLASS_MAPPING);\n\t}\n\n\t// Dynamically import KYC errors to avoid circular dependencies\n\tconst kycModule = await import('../services/kyc/common.js');\n\tconst KYCErrors = kycModule.Errors;\n\n\tconst ERROR_CLASSES: DeserializableErrorClass[] = [\n\t\t/*\n\t\t * We purposefully leave out KeetaAnchorError here since it\n\t\t * is the base error class and could cause circular resolution\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\t\tKeetaAnchorUserError,\n\t\tKYCErrors.VerificationNotFound,\n\t\tKYCErrors.CertificateNotFound,\n\t\tKYCErrors.PaymentRequired\n\t];\n\n\tconst mapping: { [key: string]: (input: unknown) => Promise<KeetaAnchorError> } = {};\n\tfor (const errorClass of ERROR_CLASSES) {\n\t\tmapping[errorClass.name] = errorClass.fromJSON.bind(errorClass);\n\t}\n\n\tERROR_CLASS_MAPPING = mapping;\n\treturn(mapping);\n}\n\n/**\n * Base error class for all Keeta Anchor errors\n */\nexport class KeetaAnchorError extends Error {\n\tstatic override readonly name: string = 'KeetaAnchorError';\n\t#name: string;\n\t#statusCode = 400;\n\t#retryable = false;\n\tprivate readonly keetaAnchorErrorObjectTypeID!: string;\n\tprivate static readonly keetaAnchorErrorObjectTypeID = '5d7f1578-e887-4104-bab0-4115ae33b08f';\n\tprotected userError = false;\n\n\tget name(): string {\n\t\treturn(this.#name);\n\t}\n\n\tprotected set name(value: string) {\n\t\tthis.#name = value;\n\t}\n\n\tget statusCode(): number {\n\t\treturn(this.#statusCode);\n\t}\n\n\tprotected set statusCode(value: number) {\n\t\tthis.#statusCode = value;\n\t}\n\n\tget retryable(): boolean {\n\t\treturn(this.#retryable);\n\t}\n\n\tprotected set retryable(value: boolean) {\n\t\tthis.#retryable = value;\n\t}\n\n\tconstructor(message: string) {\n\t\tsuper(message);\n\n\t\t// Need to cast to access the static name property from the constructor\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.#name = (this.constructor as typeof KeetaAnchorError).name;\n\n\t\tObject.defineProperty(this, 'keetaAnchorErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorError.keetaAnchorErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\t/**\n\t * Protected method to restore error properties from JSON\n\t * This allows subclasses to properly restore properties without using any\n\t */\n\tprotected restoreFromJSON(other: { [key: string]: unknown }): void {\n\t\t// Restore statusCode if present\n\t\tif ('statusCode' in other) {\n\t\t\tif (typeof other.statusCode !== 'number') {\n\t\t\t\tthrow(new TypeError('Invalid statusCode: expected number'));\n\t\t\t}\n\t\t\tthis.statusCode = other.statusCode;\n\t\t}\n\n\t\t// Restore retryable if present\n\t\tif ('retryable' in other) {\n\t\t\tif (typeof other.retryable !== 'boolean') {\n\t\t\t\tthrow(new TypeError('Invalid retryable: expected boolean'));\n\t\t\t}\n\t\t\tthis.retryable = other.retryable;\n\t\t}\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorError {\n\t\treturn(this.hasPropWithValue(input, 'keetaAnchorErrorObjectTypeID', KeetaAnchorError.keetaAnchorErrorObjectTypeID));\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json', message?: string): { error: string; statusCode: number; contentType: string } {\n\t\tmessage ??= 'Internal error';\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\t...this.toJSON(),\n\t\t\t\tstatusCode: undefined\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): { ok: false; retryable: boolean; error: string; name: string; statusCode: number } {\n\t\tlet message = 'Internal error';\n\t\tif (this.userError) {\n\t\t\tmessage = this.message;\n\t\t}\n\n\t\treturn({\n\t\t\tok: false,\n\t\t\tretryable: this.retryable,\n\t\t\terror: message,\n\t\t\tname: this.#name,\n\t\t\tstatusCode: this.statusCode\n\t\t});\n\t}\n\n\tprotected static hasPropWithValue<PROP extends string, VALUE extends string | number | boolean>(input: unknown, prop: PROP, value: VALUE): input is { [key in PROP]: VALUE } {\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (!(prop in input)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst inputValue = input[prop as keyof typeof input] as unknown;\n\t\tif (inputValue !== value) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(true);\n\t}\n\n\t/**\n\t * Extract common error properties from JSON input\n\t * This validates the structure and extracts properties needed for construction\n\t */\n\tprotected static extractErrorProperties(input: unknown, expectedClass?: { name: string }): { message: string; other: { [key: string]: unknown }} {\n\t\tif (!this.hasPropWithValue(input, 'ok', false)) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\t// Verify the name matches if an expected class is provided\n\t\tif (expectedClass && 'name' in input && input.name !== expectedClass.name) {\n\t\t\tthrow(new Error(`Error name mismatch: expected ${expectedClass.name}, got ${input.name}`));\n\t\t}\n\n\t\t// Extract error message\n\t\tlet message = 'Internal error';\n\t\tif ('error' in input && typeof input.error === 'string') {\n\t\t\tmessage = input.error;\n\t\t}\n\n\t\t// Extract other properties\n\t\tconst other: { [key: string]: unknown } = {};\n\t\tfor (const key in input) {\n\t\t\tif (key !== 'error' && key !== 'ok') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tother[key] = input[key as keyof typeof input];\n\t\t\t}\n\t\t}\n\n\t\treturn({ message, other });\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaAnchorError> {\n\t\t// Try to use the deserializer mapping if available for subclasses\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\tif (!('ok' in input) || input.ok !== false) {\n\t\t\tthrow(new Error('Invalid error JSON object: expected ok: false'));\n\t\t}\n\n\t\t// Check if there's a specific error class name\n\t\tif ('name' in input && typeof input.name === 'string') {\n\t\t\tif (input.name === 'KeetaAnchorError') {\n\t\t\t\tconst { message, other } = KeetaAnchorError.extractErrorProperties(input, this);\n\t\t\t\tconst error = new this(message);\n\t\t\t\terror.restoreFromJSON(other);\n\t\t\t\treturn(error);\n\t\t\t}\n\t\t\tconst mapping = await getErrorClassMapping();\n\t\t\tconst deserializer = mapping[input.name];\n\t\t\tif (deserializer) {\n\t\t\t\treturn(await deserializer(input));\n\t\t\t}\n\t\t}\n\n\t\tthrow(new Error('Invalid error JSON object: unknown error class'));\n\t}\n}\n\n/**\n * User-facing error class that extends KeetaAnchorError\n */\nexport class KeetaAnchorUserError extends KeetaAnchorError {\n\tstatic readonly name: string = 'KeetaAnchorUserError';\n\tprivate readonly keetaAnchorUserErrorObjectTypeID!: string;\n\tprivate static readonly keetaAnchorUserErrorObjectTypeID = 'a1e64819-14b6-45ac-a1ec-b9c0bdd51e7b';\n\tprotected override userError = true;\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorUserError {\n\t\treturn(this.hasPropWithValue(input, 'keetaAnchorUserErrorObjectTypeID', KeetaAnchorUserError.keetaAnchorUserErrorObjectTypeID));\n\t}\n\n\tconstructor(message: string) {\n\t\tsuper(message);\n\n\t\tObject.defineProperty(this, 'keetaAnchorUserErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorUserError.keetaAnchorUserErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\treturn(super.asErrorResponse(contentType, this.message));\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<InstanceType<typeof this>> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\t\tconst error = new this(message);\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n"]}
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/lib/error.ts"],"names":[],"mappings":";;AACA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUrD;;;GAGG;AACH,IAAI,mBAAmB,GAA4E,IAAI,CAAC;AAExG,KAAK,UAAU,oBAAoB;IAClC,IAAI,mBAAmB,EAAE,CAAC;QACzB,OAAM,CAAC,mBAAmB,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,aAAa,GAA+B;QACjD;;;WAGG;QACH,mEAAmE;QACnE,oBAAoB,EAAE,8BAA8B;KACpD,CAAC;IAEF,2DAA2D;IAC3D,MAAM,cAAc,GAA6D,MAAM,OAAO,CAAC,GAAG,CAAC;QAClG,MAAM,CAAC,2BAA2B,CAAC;QACnC,MAA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gBAED,OAAM,CAAC;oBACN,IAAI;oBACJ,OAAO,EAAE,OAAO,IAAI,eAAe;oBACnC,QAAQ,EAAE,MAAM,CAAC,QAAQ;oBACzB,aAAa,EAAE,MAAM,CAAC,KAAK;iBAC3B,CAAC,CAAC;YACJ,CAAC,CAAC;SACF,EAAE,OAAO,CAAC,CAAC,CAAA;IACb,CAAC","sourcesContent":["import type { IValidation, TypeGuardError } from 'typia';\nimport { createAssertEquals, createIs } from 'typia';\nimport type { LogLevel } from './log/index.ts';\n/**\n * Type for error classes that can be deserialized\n */\ninterface DeserializableErrorClass {\n\treadonly name: string;\n\tfromJSON: (input: unknown) => Promise<KeetaAnchorError>;\n}\n\n/**\n * Lazy-loaded error classes to avoid circular dependencies\n * The classes are loaded on first use\n */\nlet ERROR_CLASS_MAPPING: { [key: string]: (input: unknown) => Promise<KeetaAnchorError> } | null = null;\n\nasync function getErrorClassMapping(): Promise<{ [key: string]: (input: unknown) => Promise<KeetaAnchorError> }> {\n\tif (ERROR_CLASS_MAPPING) {\n\t\treturn(ERROR_CLASS_MAPPING);\n\t}\n\n\tconst ERROR_CLASSES: DeserializableErrorClass[] = [\n\t\t/*\n\t\t * We purposefully leave out KeetaAnchorError here since it\n\t\t * is the base error class and could cause circular resolution\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/no-use-before-define\n\t\tKeetaAnchorUserError, KeetaAnchorUserValidationError\n\t];\n\n\t// Dynamically import errors to avoid circular dependencies\n\tconst importPromises: { Errors: { [key: string]: DeserializableErrorClass }}[] = await Promise.all([\n\t\timport('../services/kyc/common.js'),\n\t\timport('../services/fx/common.js')\n\t]);\n\n\tfor (const module of importPromises) {\n\t\tconst classes = Object.values(module.Errors);\n\t\tERROR_CLASSES.push(...classes);\n\t}\n\n\tconst mapping: { [key: string]: (input: unknown) => Promise<KeetaAnchorError> } = {};\n\tfor (const errorClass of ERROR_CLASSES) {\n\t\tmapping[errorClass.name] = errorClass.fromJSON.bind(errorClass);\n\t}\n\n\tERROR_CLASS_MAPPING = mapping;\n\treturn(mapping);\n}\n\n/**\n * Base error class for all Keeta Anchor errors\n */\nexport class KeetaAnchorError extends Error {\n\tstatic override readonly name: string = 'KeetaAnchorError';\n\t#name: string;\n\t#statusCode = 400;\n\t#retryable = false;\n\tprivate readonly keetaAnchorErrorObjectTypeID!: string;\n\tprivate static readonly keetaAnchorErrorObjectTypeID = '5d7f1578-e887-4104-bab0-4115ae33b08f';\n\tprotected userError = false;\n\treadonly logLevel: LogLevel = 'ERROR';\n\n\tget name(): string {\n\t\treturn(this.#name);\n\t}\n\n\tprotected set name(value: string) {\n\t\tthis.#name = value;\n\t}\n\n\tget statusCode(): number {\n\t\treturn(this.#statusCode);\n\t}\n\n\tprotected set statusCode(value: number) {\n\t\tthis.#statusCode = value;\n\t}\n\n\tget retryable(): boolean {\n\t\treturn(this.#retryable);\n\t}\n\n\tprotected set retryable(value: boolean) {\n\t\tthis.#retryable = value;\n\t}\n\n\tconstructor(message: string) {\n\t\tsuper(message);\n\n\t\t// Need to cast to access the static name property from the constructor\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.#name = (this.constructor as typeof KeetaAnchorError).name;\n\n\t\tObject.defineProperty(this, 'keetaAnchorErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorError.keetaAnchorErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\t/**\n\t * Protected method to restore error properties from JSON\n\t * This allows subclasses to properly restore properties without using any\n\t */\n\tprotected restoreFromJSON(other: { [key: string]: unknown }): void {\n\t\t// Restore statusCode if present\n\t\tif ('statusCode' in other) {\n\t\t\tif (typeof other.statusCode !== 'number') {\n\t\t\t\tthrow(new TypeError('Invalid statusCode: expected number'));\n\t\t\t}\n\t\t\tthis.statusCode = other.statusCode;\n\t\t}\n\n\t\t// Restore retryable if present\n\t\tif ('retryable' in other) {\n\t\t\tif (typeof other.retryable !== 'boolean') {\n\t\t\t\tthrow(new TypeError('Invalid retryable: expected boolean'));\n\t\t\t}\n\t\t\tthis.retryable = other.retryable;\n\t\t}\n\t}\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorError {\n\t\treturn(this.hasPropWithValue(input, 'keetaAnchorErrorObjectTypeID', KeetaAnchorError.keetaAnchorErrorObjectTypeID));\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json', message?: string): { error: string; statusCode: number; contentType: string } {\n\t\tmessage ??= 'Internal error';\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\t...this.toJSON(),\n\t\t\t\tstatusCode: undefined\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): { ok: false; retryable: boolean; error: string; name: string; statusCode: number } {\n\t\tlet message = 'Internal error';\n\t\tif (this.userError) {\n\t\t\tmessage = this.message;\n\t\t}\n\n\t\treturn({\n\t\t\tok: false,\n\t\t\tretryable: this.retryable,\n\t\t\terror: message,\n\t\t\tname: this.#name,\n\t\t\tstatusCode: this.statusCode\n\t\t});\n\t}\n\n\tprotected static hasPropWithValue<PROP extends string, VALUE extends string | number | boolean>(input: unknown, prop: PROP, value: VALUE): input is { [key in PROP]: VALUE } {\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (!(prop in input)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tconst inputValue = input[prop as keyof typeof input] as unknown;\n\t\tif (inputValue !== value) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(true);\n\t}\n\n\t/**\n\t * Extract common error properties from JSON input\n\t * This validates the structure and extracts properties needed for construction\n\t */\n\tprotected static extractErrorProperties(input: unknown, expectedClass?: { name: string }): { message: string; other: { [key: string]: unknown }} {\n\t\tif (!this.hasPropWithValue(input, 'ok', false)) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\t// Verify the name matches if an expected class is provided\n\t\tif (expectedClass && 'name' in input && input.name !== expectedClass.name) {\n\t\t\tthrow(new Error(`Error name mismatch: expected ${expectedClass.name}, got ${input.name}`));\n\t\t}\n\n\t\t// Extract error message\n\t\tlet message = 'Internal error';\n\t\tif ('error' in input && typeof input.error === 'string') {\n\t\t\tmessage = input.error;\n\t\t}\n\n\t\t// Extract other properties\n\t\tconst other: { [key: string]: unknown } = {};\n\t\tfor (const key in input) {\n\t\t\tif (key !== 'error' && key !== 'ok') {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\tother[key] = input[key as keyof typeof input];\n\t\t\t}\n\t\t}\n\n\t\treturn({ message, other });\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaAnchorError> {\n\t\t// Try to use the deserializer mapping if available for subclasses\n\t\tif (typeof input !== 'object' || input === null) {\n\t\t\tthrow(new Error('Invalid error JSON object'));\n\t\t}\n\n\t\tif (!('ok' in input) || input.ok !== false) {\n\t\t\tthrow(new Error('Invalid error JSON object: expected ok: false'));\n\t\t}\n\n\t\t// Check if there's a specific error class name\n\t\tif ('name' in input && typeof input.name === 'string') {\n\t\t\tif (input.name === 'KeetaAnchorError') {\n\t\t\t\tconst { message, other } = KeetaAnchorError.extractErrorProperties(input, this);\n\t\t\t\tconst error = new this(message);\n\t\t\t\terror.restoreFromJSON(other);\n\t\t\t\treturn(error);\n\t\t\t}\n\t\t\tconst mapping = await getErrorClassMapping();\n\t\t\tconst deserializer = mapping[input.name];\n\t\t\tif (deserializer) {\n\t\t\t\treturn(await deserializer(input));\n\t\t\t}\n\t\t}\n\n\t\tthrow(new Error('Invalid error JSON object: unknown error class'));\n\t}\n}\n\n/**\n * User-facing error class that extends KeetaAnchorError\n */\nexport class KeetaAnchorUserError extends KeetaAnchorError {\n\tstatic readonly name: string = 'KeetaAnchorUserError';\n\tprivate readonly keetaAnchorUserErrorObjectTypeID!: string;\n\tprivate static readonly keetaAnchorUserErrorObjectTypeID = 'a1e64819-14b6-45ac-a1ec-b9c0bdd51e7b';\n\tprotected override userError = true;\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorUserError {\n\t\treturn(this.hasPropWithValue(input, 'keetaAnchorUserErrorObjectTypeID', KeetaAnchorUserError.keetaAnchorUserErrorObjectTypeID));\n\t}\n\n\tconstructor(message: string) {\n\t\tsuper(message);\n\n\t\tObject.defineProperty(this, 'keetaAnchorUserErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorUserError.keetaAnchorUserErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\treturn(super.asErrorResponse(contentType, this.message));\n\t}\n\n\tstatic async fromJSON(input: unknown): Promise<InstanceType<typeof this>> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\t\tconst error = new this(message);\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n}\n\ninterface KeetaAnchorUserValidationErrorDetails {\n\tfields: {\n\t\tpath?: string | undefined;\n\t\tmessage: string;\n\t\tallowedValues?: string[];\n\t\texpected?: string;\n\t\treceivedValue?: unknown;\n\t}[];\n}\n\nconst assertKeetaAnchorUserValidationErrorDetails: (input: unknown) => KeetaAnchorUserValidationErrorDetails = createAssertEquals<KeetaAnchorUserValidationErrorDetails>();\ntype KeetaAnchorUserValidationErrorJSON = ReturnType<KeetaAnchorUserError['toJSON']> & KeetaAnchorUserValidationErrorDetails;\n\ntype TypeGuardErrorLike = Pick<TypeGuardError.IProps | IValidation.IError, 'path' | 'expected' | 'value'>;\n\nconst isTypeGuardErrorLike: (error: unknown) => error is TypeGuardErrorLike = createIs<TypeGuardErrorLike>();\n\nexport class KeetaAnchorUserValidationError extends KeetaAnchorUserError implements KeetaAnchorUserValidationErrorDetails {\n\tstatic readonly isTypeGuardErrorLike: typeof isTypeGuardErrorLike = isTypeGuardErrorLike;\n\n\tstatic override readonly name: string = 'KeetaAnchorUserValidationError';\n\tprivate readonly KeetaAnchorUserValidationErrorObjectTypeID!: string;\n\tprivate static readonly KeetaAnchorUserValidationErrorObjectTypeID = '5fa46799-48b8-4cf2-a3de-9c01418d3ba0';\n\tprotected override userError = true;\n\n\treadonly fields: KeetaAnchorUserValidationErrorDetails['fields'];\n\n\tstatic isInstance(input: unknown): input is KeetaAnchorUserError {\n\t\treturn(this.hasPropWithValue(input, 'KeetaAnchorUserValidationErrorObjectTypeID', KeetaAnchorUserValidationError.KeetaAnchorUserValidationErrorObjectTypeID));\n\t}\n\n\tconstructor(args: KeetaAnchorUserValidationErrorDetails, message?: string) {\n\t\tsuper(message ?? `Validation error on fields ${args.fields.map((f) => f.path).join(', ')}`);\n\n\t\tObject.defineProperty(this, 'KeetaAnchorUserValidationErrorObjectTypeID', {\n\t\t\tvalue: KeetaAnchorUserValidationError.KeetaAnchorUserValidationErrorObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.fields = args.fields;\n\t}\n\n\toverride get statusCode() {\n\t\treturn(400);\n\t}\n\n\tasErrorResponse(contentType: 'text/plain' | 'application/json'): { error: string; statusCode: number; contentType: string } {\n\t\tlet message = this.message;\n\t\tif (contentType === 'application/json') {\n\t\t\tmessage = JSON.stringify({\n\t\t\t\tok: false,\n\t\t\t\tname: this.name,\n\t\t\t\tdata: { fields: this.fields },\n\t\t\t\terror: this.message\n\t\t\t});\n\t\t}\n\n\t\treturn({\n\t\t\terror: message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tcontentType: contentType\n\t\t});\n\t}\n\n\ttoJSON(): KeetaAnchorUserValidationErrorJSON {\n\t\treturn({\n\t\t\t...super.toJSON(),\n\t\t\tfields: this.fields\n\t\t});\n\t}\n\n\n\tstatic async fromJSON(input: unknown): Promise<KeetaAnchorUserValidationError> {\n\t\tconst { message, other } = this.extractErrorProperties(input, this);\n\n\t\tif (!('data' in other)) {\n\t\t\tthrow(new Error('Invalid KeetaAnchorUserValidationError JSON: missing data property'));\n\t\t}\n\n\t\tconst parsed = assertKeetaAnchorUserValidationErrorDetails(other.data);\n\n\t\tconst error = new this(\n\t\t\t{ fields: parsed.fields },\n\t\t\tmessage\n\t\t);\n\n\t\terror.restoreFromJSON(other);\n\t\treturn(error);\n\t}\n\n\tstatic fromTypeGuardError(input: TypeGuardErrorLike | TypeGuardErrorLike[], message?: string): KeetaAnchorUserValidationError {\n\t\tlet asArr;\n\n\t\tif (Array.isArray(input)) {\n\t\t\tasArr = input;\n\t\t} else {\n\t\t\tasArr = [ input ];\n\t\t}\n\n\t\treturn(new this({\n\t\t\tfields: asArr.map(function(single) {\n\t\t\t\tlet path;\n\t\t\t\tif (single.path !== undefined) {\n\t\t\t\t\tconst split = single.path.split('.');\n\n\t\t\t\t\tif (split[0] === '$input') {\n\t\t\t\t\t\tsplit.shift();\n\t\t\t\t\t}\n\n\t\t\t\t\tif (split.length > 0) {\n\t\t\t\t\t\tpath = split.join('.');\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn({\n\t\t\t\t\tpath,\n\t\t\t\t\tmessage: message ?? 'Invalid value',\n\t\t\t\t\texpected: single.expected,\n\t\t\t\t\treceivedValue: single.value\n\t\t\t\t});\n\t\t\t})\n\t\t}, message))\n\t}\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export interface HTTPSignedField {
2
+ nonce: string;
3
+ timestamp: string;
4
+ signature: string;
5
+ }
6
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/lib/http-server/common.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,MAAM,CAAC;IAEd,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;CAClB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/lib/http-server/common.ts"],"names":[],"mappings":"","sourcesContent":["export interface HTTPSignedField {\n\tnonce: string;\n\t/* Date and time of the request in ISO 8601 format */\n\ttimestamp: string;\n\t/* Signature of the account public key and the nonce as an ASN.1 Sequence, Base64 DER */\n\tsignature: string;\n}\n"]}
@@ -1,20 +1,35 @@
1
1
  import * as http from 'http';
2
- import type { JSONSerializable } from './utils/json.js';
3
- import type { Logger } from './log/index.js';
2
+ import type { JSONSerializable } from '../utils/json.js';
3
+ import type { Logger } from '../log/index.js';
4
4
  export declare const AssertHTTPErrorData: (input: unknown) => {
5
5
  error: string;
6
6
  statusCode?: number;
7
7
  contentType?: string;
8
8
  };
9
+ type RouteHandlerMethod<BodyDataType = JSONSerializable | undefined> = (urlParams: Map<string, string>, postData: BodyDataType, requestHeaders: http.IncomingHttpHeaders, requestUrl: URL) => Promise<{
10
+ output: string | Buffer;
11
+ statusCode?: number;
12
+ contentType?: string;
13
+ headers?: {
14
+ [headerName: string]: string;
15
+ };
16
+ }>;
17
+ type RouteHandlerWithConfig = {
18
+ bodyType: 'raw';
19
+ handler: RouteHandlerMethod<Buffer>;
20
+ } | {
21
+ bodyType: 'parsed';
22
+ handler: RouteHandlerMethod;
23
+ } | {
24
+ bodyType: 'none';
25
+ handler: RouteHandlerMethod<undefined>;
26
+ };
27
+ type RouteHandler = RouteHandlerMethod | RouteHandlerWithConfig;
9
28
  export type Routes = {
10
- [route: string]: (urlParams: Map<string, string>, postData: JSONSerializable | undefined, requestHeaders: http.IncomingHttpHeaders) => Promise<{
11
- output: string | Buffer;
12
- statusCode?: number;
13
- contentType?: string;
14
- headers?: {
15
- [headerName: string]: string;
16
- };
17
- }>;
29
+ [route: string]: RouteHandler;
30
+ };
31
+ export type RoutesWithConfigs = {
32
+ [route: string]: RouteHandlerWithConfig;
18
33
  };
19
34
  export interface KeetaAnchorHTTPServerConfig {
20
35
  /**
@@ -52,9 +67,12 @@ export declare abstract class KeetaNetAnchorHTTPServer<ConfigType extends KeetaA
52
67
  /**
53
68
  * Get the URL of the server, which can be used to make requests to
54
69
  * it. This will use "localhost" as the hostname and the port that
55
- * the server is listening on.
70
+ * the server is listening on by default but can be overridden by
71
+ * setting a custom URL.
56
72
  */
57
73
  get url(): string;
74
+ set url(value: string | URL | ((object: this) => string));
58
75
  [Symbol.asyncDispose](): Promise<void>;
59
76
  }
60
- //# sourceMappingURL=http-server.d.ts.map
77
+ export {};
78
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/http-server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAK7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAY,MAAM,iBAAiB,CAAC;AAKxD,eAAO,MAAM,mBAAmB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAAkF,CAAC;AAOpM,KAAK,kBAAkB,CAAC,YAAY,GAAG,gBAAgB,GAAG,SAAS,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,IAAI,CAAC,mBAAmB,EAAE,UAAU,EAAE,GAAG,KAAK,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE;QAAE,CAAC,UAAU,E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