@notabene/javascript-sdk 2.9.0-next.2 → 2.9.0-next.4

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 (135) hide show
  1. package/dist/cjs/notabene.cjs +1 -1
  2. package/dist/cjs/notabene.d.ts +32 -2
  3. package/dist/cjs/package.json +1 -1
  4. package/dist/esm/notabene.d.ts +32 -2
  5. package/dist/esm/notabene.js +86 -79
  6. package/dist/esm/package.json +1 -1
  7. package/dist/notabene.d.ts +32 -2
  8. package/dist/notabene.js +86 -79
  9. package/docs/README.md +12 -3
  10. package/docs/_media/TransactionOptions.md +16 -6
  11. package/docs/ivms/types/enumerations/PayloadVersionCode.md +2 -2
  12. package/docs/ivms/types/interfaces/PayloadMetadata.md +2 -2
  13. package/docs/ivms/types/type-aliases/Address.md +1 -1
  14. package/docs/ivms/types/type-aliases/AddressTypeCode.md +1 -1
  15. package/docs/ivms/types/type-aliases/Beneficiary.md +1 -1
  16. package/docs/ivms/types/type-aliases/BeneficiaryVASP.md +1 -1
  17. package/docs/ivms/types/type-aliases/DateAndPlaceOfBirth.md +1 -1
  18. package/docs/ivms/types/type-aliases/ISOCountryCode.md +1 -1
  19. package/docs/ivms/types/type-aliases/ISODate.md +1 -1
  20. package/docs/ivms/types/type-aliases/IVMS101.md +1 -1
  21. package/docs/ivms/types/type-aliases/IntermediaryVASP.md +1 -1
  22. package/docs/ivms/types/type-aliases/LegalPerson.md +1 -1
  23. package/docs/ivms/types/type-aliases/LegalPersonName.md +1 -1
  24. package/docs/ivms/types/type-aliases/LegalPersonNameID.md +1 -1
  25. package/docs/ivms/types/type-aliases/LegalPersonNameTypeCode.md +1 -1
  26. package/docs/ivms/types/type-aliases/LocalLegalPersonNameID.md +1 -1
  27. package/docs/ivms/types/type-aliases/LocalNaturalPersonNameID.md +1 -1
  28. package/docs/ivms/types/type-aliases/NationalIdentification.md +1 -1
  29. package/docs/ivms/types/type-aliases/NationalIdentifierTypeCode.md +1 -1
  30. package/docs/ivms/types/type-aliases/NaturalPerson.md +1 -1
  31. package/docs/ivms/types/type-aliases/NaturalPersonName.md +1 -1
  32. package/docs/ivms/types/type-aliases/NaturalPersonNameID.md +1 -1
  33. package/docs/ivms/types/type-aliases/NaturalPersonNameTypeCode.md +1 -1
  34. package/docs/ivms/types/type-aliases/OriginatingVASP.md +1 -1
  35. package/docs/ivms/types/type-aliases/Originator.md +1 -1
  36. package/docs/ivms/types/type-aliases/Person.md +1 -1
  37. package/docs/ivms/types/type-aliases/TransferPath.md +1 -1
  38. package/docs/ivms/types/type-aliases/TransliterationMethodCode.md +1 -1
  39. package/docs/notabene/README.md +15 -0
  40. package/docs/notabene/classes/ConnectionManager.md +14 -6
  41. package/docs/notabene/classes/EmbeddedComponent.md +17 -17
  42. package/docs/notabene/classes/default.md +7 -7
  43. package/docs/notabene/functions/decodeFragmentToObject.md +1 -1
  44. package/docs/notabene/functions/getRefreshResult.md +27 -0
  45. package/docs/notabene/interfaces/ConnectionData.md +13 -3
  46. package/docs/notabene/interfaces/ConnectionMetadata.md +3 -3
  47. package/docs/notabene/interfaces/ConnectionResponse.md +15 -5
  48. package/docs/notabene/interfaces/ConnectionResult.md +61 -0
  49. package/docs/notabene/interfaces/NotabeneConfig.md +5 -5
  50. package/docs/notabene/type-aliases/ConnectionStatus.md +13 -0
  51. package/docs/notabene/type-aliases/MessageCallback.md +1 -1
  52. package/docs/notabene/type-aliases/TransactionType.md +1 -1
  53. package/docs/types/README.md +1 -0
  54. package/docs/types/enumerations/AgentType.md +2 -2
  55. package/docs/types/enumerations/CMType.md +7 -7
  56. package/docs/types/enumerations/ErrorIdentifierCode.md +4 -4
  57. package/docs/types/enumerations/HMType.md +2 -2
  58. package/docs/types/enumerations/PersonType.md +3 -3
  59. package/docs/types/enumerations/ProofStatus.md +4 -4
  60. package/docs/types/enumerations/ProofTypes.md +17 -17
  61. package/docs/types/enumerations/Status.md +5 -5
  62. package/docs/types/enumerations/VASPSearchControl.md +2 -2
  63. package/docs/types/enumerations/ValidationSections.md +4 -4
  64. package/docs/types/interfaces/Agent.md +6 -6
  65. package/docs/types/interfaces/CallbackOptions.md +2 -2
  66. package/docs/types/interfaces/ComponentRequest.md +2 -2
  67. package/docs/types/interfaces/ComponentResponse.md +4 -4
  68. package/docs/types/interfaces/ConnectionRecord.md +7 -7
  69. package/docs/types/interfaces/ConnectionRequest.md +3 -3
  70. package/docs/types/interfaces/Counterparty.md +10 -10
  71. package/docs/types/interfaces/DeclarationProof.md +6 -6
  72. package/docs/types/interfaces/Deposit.md +11 -11
  73. package/docs/types/interfaces/DepositRequest.md +7 -7
  74. package/docs/types/interfaces/DepositRequestOptions.md +1 -1
  75. package/docs/types/interfaces/DepositTransaction.md +9 -9
  76. package/docs/types/interfaces/LegalPerson.md +13 -13
  77. package/docs/types/interfaces/MicroTransferProof.md +9 -9
  78. package/docs/types/interfaces/NaturalPerson.md +13 -13
  79. package/docs/types/interfaces/OwnershipProof.md +4 -4
  80. package/docs/types/interfaces/RefreshSource.md +2 -2
  81. package/docs/types/interfaces/Refreshable.md +1 -1
  82. package/docs/types/interfaces/ScreenshotProof.md +5 -5
  83. package/docs/types/interfaces/SignatureProof.md +9 -9
  84. package/docs/types/interfaces/ThresholdOptions.md +3 -3
  85. package/docs/types/interfaces/Transaction.md +8 -8
  86. package/docs/types/interfaces/TransactionOptions.md +16 -6
  87. package/docs/types/interfaces/TransactionResponse.md +9 -9
  88. package/docs/types/interfaces/VASP.md +9 -9
  89. package/docs/types/interfaces/Wallet.md +8 -8
  90. package/docs/types/interfaces/Withdrawal.md +10 -10
  91. package/docs/types/type-aliases/BlockchainAddress.md +1 -1
  92. package/docs/types/type-aliases/CAIP10.md +1 -1
  93. package/docs/types/type-aliases/CAIP19.md +1 -1
  94. package/docs/types/type-aliases/CAIP2.md +1 -1
  95. package/docs/types/type-aliases/CAIP220.md +1 -1
  96. package/docs/types/type-aliases/Cancel.md +1 -1
  97. package/docs/types/type-aliases/Completed.md +1 -1
  98. package/docs/types/type-aliases/ComponentMessage.md +1 -1
  99. package/docs/types/type-aliases/ConnectionOptions.md +1 -1
  100. package/docs/types/type-aliases/CounterpartyAssistConfig.md +19 -0
  101. package/docs/types/type-aliases/CryptoCredential.md +1 -1
  102. package/docs/types/type-aliases/DID.md +1 -1
  103. package/docs/types/type-aliases/DTI.md +1 -1
  104. package/docs/types/type-aliases/Destination.md +1 -1
  105. package/docs/types/type-aliases/Error.md +1 -1
  106. package/docs/types/type-aliases/FieldOptions.md +1 -1
  107. package/docs/types/type-aliases/FieldTypes.md +1 -1
  108. package/docs/types/type-aliases/HostMessage.md +1 -1
  109. package/docs/types/type-aliases/ISOCurrency.md +1 -1
  110. package/docs/types/type-aliases/InvalidValue.md +1 -1
  111. package/docs/types/type-aliases/LEI.md +1 -1
  112. package/docs/types/type-aliases/LegalPersonFieldName.md +1 -1
  113. package/docs/types/type-aliases/LegalPersonFields.md +1 -1
  114. package/docs/types/type-aliases/NationalIdentifierTypeFieldOptions.md +1 -1
  115. package/docs/types/type-aliases/NaturalPersonFieldName.md +1 -1
  116. package/docs/types/type-aliases/NaturalPersonFields.md +1 -1
  117. package/docs/types/type-aliases/NotabeneAsset.md +1 -1
  118. package/docs/types/type-aliases/Ready.md +1 -1
  119. package/docs/types/type-aliases/ResizeRequest.md +1 -1
  120. package/docs/types/type-aliases/Source.md +1 -1
  121. package/docs/types/type-aliases/Theme.md +1 -1
  122. package/docs/types/type-aliases/TransactionAsset.md +1 -1
  123. package/docs/types/type-aliases/TravelAddress.md +1 -1
  124. package/docs/types/type-aliases/URI.md +1 -1
  125. package/docs/types/type-aliases/UUID.md +1 -1
  126. package/docs/types/type-aliases/UpdateValue.md +1 -1
  127. package/docs/types/type-aliases/V1Asset.md +1 -1
  128. package/docs/types/type-aliases/V1Transaction.md +1 -1
  129. package/docs/types/type-aliases/VASPOptions.md +1 -1
  130. package/docs/types/type-aliases/ValidationError.md +1 -1
  131. package/package.json +1 -1
  132. package/src/notabene.ts +4 -0
  133. package/src/types.ts +33 -1
  134. package/src/utils/__tests__/connections.test.ts +160 -24
  135. package/src/utils/connections.ts +21 -7
package/src/types.ts CHANGED
@@ -312,6 +312,18 @@ export interface Wallet extends Agent {
312
312
  wallet_connect_id?: string;
313
313
  }
314
314
 
315
+ /**
316
+ * A blockchain account
317
+ * @public
318
+ */
319
+ export interface Account {
320
+ did?: DID;
321
+ blockchainAddress?: BlockchainAddress;
322
+ chain?: CAIP2;
323
+ caip10?: CAIP10;
324
+ identifier?: string;
325
+ }
326
+
315
327
  /**
316
328
  * The counterparty of a transaction.
317
329
  * @public
@@ -496,7 +508,7 @@ type BeneficiaryFields = {
496
508
  type DepositRequestFields = {
497
509
  destination: BlockchainAddress | CAIP10;
498
510
  asset: TransactionAsset;
499
- amountDecimal?: number;
511
+ amountDecimal: number;
500
512
  travelAddress?: TravelAddress;
501
513
  cryptoCredential?: CryptoCredential;
502
514
  };
@@ -557,6 +569,7 @@ export interface Transaction extends ComponentRequest {
557
569
  price: number;
558
570
  currency: ISOCurrency;
559
571
  };
572
+ account?: Account;
560
573
  }
561
574
 
562
575
  export interface RefreshSource {
@@ -780,6 +793,24 @@ export type VASPOptions = {
780
793
  searchable?: VASPSearchControl[]; // If array left empty all VASPs will be searchable
781
794
  };
782
795
 
796
+ /**
797
+ * Counterparty Assist Configuration options for recipient selection
798
+ *
799
+ * @remarks
800
+ * Controls for each person type, whether to show the share feature or not.
801
+ *
802
+ * @public
803
+ */
804
+ export type CounterpartyAssistConfig =
805
+ | {
806
+ enabled?: boolean;
807
+ }
808
+ | {
809
+ [key in PersonType]: {
810
+ enabled?: boolean;
811
+ };
812
+ };
813
+
783
814
  /**
784
815
  * Sections in a WithdrawalAssist screen
785
816
  *
@@ -828,6 +859,7 @@ export interface TransactionOptions {
828
859
  fields?: FieldTypes;
829
860
  vasps?: VASPOptions;
830
861
  hide?: ValidationSections[]; // You can hide a specific section of the component by listing it here
862
+ counterpartyAssistConfig?: CounterpartyAssistConfig;
831
863
  }
832
864
  /**
833
865
  * Component Message Type enum representing different message types that can be sent
@@ -1,7 +1,12 @@
1
1
  import fc from 'fast-check';
2
2
  import { beforeEach, describe, expect, it, vi } from 'vitest';
3
- import type { DID } from '../../types';
4
- import { ConnectionManager, TransactionType } from '../connections';
3
+ import type { DID, RefreshSource } from '../../types';
4
+ import {
5
+ ConnectionManager,
6
+ ConnectionStatus,
7
+ getRefreshResult,
8
+ TransactionType,
9
+ } from '../connections';
5
10
  import { seal } from '../encryption';
6
11
 
7
12
  // Mock fetch globally
@@ -13,30 +18,32 @@ const arbDID = fc
13
18
  .tuple(fc.string(), fc.string())
14
19
  .map(([method, id]) => `did:${method}:${id}` as DID);
15
20
 
21
+ const arbTx = fc.record({
22
+ requestId: fc.option(fc.uuid(), { nil: undefined }),
23
+ customer: fc.option(
24
+ fc.record({
25
+ name: fc.string(),
26
+ email: fc.option(fc.string(), { nil: undefined }),
27
+ phone: fc.option(fc.string(), { nil: undefined }),
28
+ type: fc.constant(undefined), // Optional PersonType
29
+ accountNumber: fc.option(fc.string(), { nil: undefined }),
30
+ did: fc.option(arbDID, { nil: undefined }),
31
+ verified: fc.option(fc.boolean(), { nil: undefined }),
32
+ website: fc.option(fc.webUrl(), { nil: undefined }),
33
+ geographicAddress: fc.option(fc.constant(undefined), {
34
+ nil: undefined,
35
+ }),
36
+ nationalIdentification: fc.option(fc.constant(undefined), {
37
+ nil: undefined,
38
+ }),
39
+ }),
40
+ { nil: undefined },
41
+ ),
42
+ });
43
+
16
44
  // Test helper to create arbitrary ComponentRequests
17
45
  const arbComponentRequest = fc.record({
18
- tx: fc.record({
19
- requestId: fc.option(fc.uuid(), { nil: undefined }),
20
- customer: fc.option(
21
- fc.record({
22
- name: fc.string(),
23
- email: fc.option(fc.string(), { nil: undefined }),
24
- phone: fc.option(fc.string(), { nil: undefined }),
25
- type: fc.constant(undefined), // Optional PersonType
26
- accountNumber: fc.option(fc.string(), { nil: undefined }),
27
- did: fc.option(arbDID, { nil: undefined }),
28
- verified: fc.option(fc.boolean(), { nil: undefined }),
29
- website: fc.option(fc.webUrl(), { nil: undefined }),
30
- geographicAddress: fc.option(fc.constant(undefined), {
31
- nil: undefined,
32
- }),
33
- nationalIdentification: fc.option(fc.constant(undefined), {
34
- nil: undefined,
35
- }),
36
- }),
37
- { nil: undefined },
38
- ),
39
- }),
46
+ tx: arbTx,
40
47
  authToken: fc.option(fc.string(), { nil: undefined }),
41
48
  txOptions: fc.option(fc.record({}), { nil: undefined }),
42
49
  });
@@ -298,4 +305,133 @@ describe('ConnectionManager', () => {
298
305
  );
299
306
  });
300
307
  });
308
+
309
+ describe('getRefreshResult', async () => {
310
+ // Create test data and sealed object
311
+ const tx = { requestId: 'test-123' };
312
+ const result = { txCreate: { requestId: 'test-123' } };
313
+ const testData = { tx, result };
314
+ const sealed = await seal(testData);
315
+
316
+ // Create a refresh source with the real key
317
+ const refreshSource: RefreshSource = {
318
+ url: 'https://test-endpoint.com',
319
+ key: sealed.key,
320
+ };
321
+
322
+ // Common metadata for all tests
323
+ const metadata = {
324
+ participants: ['participant1'],
325
+ nodeUrl: 'https://node-url.com',
326
+ transactionType: 'withdraw' as TransactionType,
327
+ };
328
+
329
+ // Helper function to create mock responses
330
+ const createMockResponse = (
331
+ status: ConnectionStatus,
332
+ sealedData = sealed.ciphertext,
333
+ ) => ({
334
+ id: 'test-id',
335
+ metadata,
336
+ status,
337
+ sealed: [sealedData],
338
+ version: 1,
339
+ });
340
+
341
+ it('should return basic data for closed status', async () => {
342
+ const mockResponse = createMockResponse('closed');
343
+
344
+ fetchMock.mockResolvedValueOnce({
345
+ ok: true,
346
+ json: async () => mockResponse,
347
+ });
348
+
349
+ const result = await getRefreshResult(refreshSource);
350
+
351
+ expect(result).toEqual({
352
+ id: mockResponse.id,
353
+ metadata: mockResponse.metadata,
354
+ status: 'closed',
355
+ });
356
+ });
357
+
358
+ it('should return data with tx for active status', async () => {
359
+ const mockResponse = createMockResponse('active');
360
+
361
+ fetchMock.mockResolvedValueOnce({
362
+ ok: true,
363
+ json: async () => mockResponse,
364
+ });
365
+
366
+ const result = await getRefreshResult(refreshSource);
367
+
368
+ expect(result).toEqual({
369
+ id: mockResponse.id,
370
+ metadata: mockResponse.metadata,
371
+ status: 'active',
372
+ tx,
373
+ });
374
+ });
375
+
376
+ it('should return data with result for completed status', async () => {
377
+ // Create sealed data with a result
378
+ const transactionResponse = { success: true, data: { id: 'test-id' } };
379
+ const completedSealed = await seal({
380
+ tx: testData,
381
+ result: transactionResponse,
382
+ });
383
+
384
+ // Create a refresh source with the new key
385
+ const completedRefreshSource: RefreshSource = {
386
+ url: 'https://test-endpoint.com',
387
+ key: completedSealed.key,
388
+ };
389
+
390
+ const mockResponse = createMockResponse(
391
+ 'completed',
392
+ completedSealed.ciphertext,
393
+ );
394
+
395
+ fetchMock.mockResolvedValueOnce({
396
+ ok: true,
397
+ json: async () => mockResponse,
398
+ });
399
+
400
+ const result = await getRefreshResult(completedRefreshSource);
401
+
402
+ expect(result).toEqual({
403
+ id: mockResponse.id,
404
+ metadata: mockResponse.metadata,
405
+ status: 'completed',
406
+ result: transactionResponse,
407
+ });
408
+ });
409
+
410
+ it('should throw error when no sealed data is present', async () => {
411
+ fetchMock.mockResolvedValueOnce({
412
+ ok: true,
413
+ json: async () => ({
414
+ id: 'test-id',
415
+ metadata,
416
+ status: 'active' as ConnectionStatus,
417
+ sealed: null,
418
+ }),
419
+ });
420
+
421
+ await expect(getRefreshResult(refreshSource)).rejects.toThrow(
422
+ 'Data missing from server response',
423
+ );
424
+ });
425
+
426
+ it('should throw error on failed request', async () => {
427
+ fetchMock.mockResolvedValueOnce({
428
+ ok: false,
429
+ text: async () => 'Request failed',
430
+ });
431
+
432
+ await expect(getRefreshResult(refreshSource)).rejects.toThrow(
433
+ 'Failed to get connection',
434
+ );
435
+ });
436
+ });
301
437
  });
@@ -34,7 +34,7 @@ export interface ConnectionResult<T extends ComponentRequest> {
34
34
  id: UUID;
35
35
  metadata: ConnectionMetadata;
36
36
  status: ConnectionStatus;
37
- tx: T;
37
+ tx?: T;
38
38
  result?: TransactionResponse<T>;
39
39
  }
40
40
 
@@ -51,8 +51,18 @@ export async function getRefreshResult<T extends ComponentRequest>(
51
51
 
52
52
  const result = await response.json();
53
53
 
54
- if (!result.sealed) {
55
- throw new Error('No data found');
54
+ if (!result.id || !result.metadata || !result.status || !result.sealed) {
55
+ throw new Error('Data missing from server response');
56
+ }
57
+
58
+ const basicData = {
59
+ id: result.id,
60
+ metadata: result.metadata,
61
+ status: result.status,
62
+ };
63
+
64
+ if (result.status === 'closed') {
65
+ return basicData;
56
66
  }
57
67
 
58
68
  // Get the latest sealed data
@@ -64,12 +74,16 @@ export async function getRefreshResult<T extends ComponentRequest>(
64
74
  key: refreshSource.key,
65
75
  });
66
76
 
77
+ if (result.status === 'completed') {
78
+ return {
79
+ ...basicData,
80
+ result: data.result,
81
+ };
82
+ }
83
+
67
84
  return {
68
- id: result.id,
69
- metadata: result.metadata,
70
- status: result.status,
85
+ ...basicData,
71
86
  tx: data.tx,
72
- result: data.result,
73
87
  };
74
88
  }
75
89