@notabene/javascript-sdk 2.0.2 → 2.0.4-NEXT.0

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 (118) hide show
  1. package/README.md +28 -0
  2. package/dist/notabene.cjs +1 -1
  3. package/dist/notabene.d.ts +30 -17
  4. package/dist/notabene.js +98 -70
  5. package/docs/README.md +28 -0
  6. package/docs/_media/TransactionOptions.md +6 -6
  7. package/docs/ivms/types/enumerations/PayloadVersionCode.md +2 -2
  8. package/docs/ivms/types/interfaces/PayloadMetadata.md +2 -2
  9. package/docs/ivms/types/type-aliases/Address.md +1 -1
  10. package/docs/ivms/types/type-aliases/AddressTypeCode.md +1 -1
  11. package/docs/ivms/types/type-aliases/Beneficiary.md +1 -1
  12. package/docs/ivms/types/type-aliases/BeneficiaryVASP.md +1 -1
  13. package/docs/ivms/types/type-aliases/DateAndPlaceOfBirth.md +1 -1
  14. package/docs/ivms/types/type-aliases/ISOCountryCode.md +1 -1
  15. package/docs/ivms/types/type-aliases/ISODate.md +1 -1
  16. package/docs/ivms/types/type-aliases/IVMS101.md +1 -1
  17. package/docs/ivms/types/type-aliases/IntermediaryVASP.md +1 -1
  18. package/docs/ivms/types/type-aliases/LegalPerson.md +1 -1
  19. package/docs/ivms/types/type-aliases/LegalPersonName.md +1 -1
  20. package/docs/ivms/types/type-aliases/LegalPersonNameID.md +1 -1
  21. package/docs/ivms/types/type-aliases/LegalPersonNameTypeCode.md +1 -1
  22. package/docs/ivms/types/type-aliases/LocalLegalPersonNameID.md +1 -1
  23. package/docs/ivms/types/type-aliases/LocalNaturalPersonNameID.md +1 -1
  24. package/docs/ivms/types/type-aliases/NationalIdentification.md +1 -1
  25. package/docs/ivms/types/type-aliases/NationalIdentifierTypeCode.md +1 -1
  26. package/docs/ivms/types/type-aliases/NaturalPerson.md +1 -1
  27. package/docs/ivms/types/type-aliases/NaturalPersonName.md +1 -1
  28. package/docs/ivms/types/type-aliases/NaturalPersonNameID.md +1 -1
  29. package/docs/ivms/types/type-aliases/NaturalPersonNameTypeCode.md +1 -1
  30. package/docs/ivms/types/type-aliases/OriginatingVASP.md +1 -1
  31. package/docs/ivms/types/type-aliases/Originator.md +1 -1
  32. package/docs/ivms/types/type-aliases/Person.md +1 -1
  33. package/docs/ivms/types/type-aliases/TransferPath.md +1 -1
  34. package/docs/ivms/types/type-aliases/TransliterationMethodCode.md +1 -1
  35. package/docs/notabene/README.md +6 -6
  36. package/docs/notabene/classes/EmbeddedComponent.md +39 -16
  37. package/docs/notabene/classes/default.md +6 -6
  38. package/docs/notabene/functions/decodeFragmentToObject.md +1 -1
  39. package/docs/notabene/interfaces/NotabeneConfig.md +5 -5
  40. package/docs/notabene/type-aliases/MessageCallback.md +1 -1
  41. package/docs/types/README.md +1 -1
  42. package/docs/types/enumerations/AgentType.md +2 -2
  43. package/docs/types/enumerations/CMType.md +6 -17
  44. package/docs/types/enumerations/HMType.md +2 -2
  45. package/docs/types/enumerations/PersonType.md +3 -3
  46. package/docs/types/enumerations/ProofStatus.md +4 -4
  47. package/docs/types/enumerations/ProofTypes.md +12 -12
  48. package/docs/types/enumerations/Status.md +5 -5
  49. package/docs/types/enumerations/VASPSearchControl.md +34 -0
  50. package/docs/types/enumerations/ValidationSections.md +4 -4
  51. package/docs/types/interfaces/Agent.md +6 -6
  52. package/docs/types/interfaces/CallbackOptions.md +2 -2
  53. package/docs/types/interfaces/ComponentRequest.md +2 -2
  54. package/docs/types/interfaces/ComponentResponse.md +4 -4
  55. package/docs/types/interfaces/ConnectionRecord.md +7 -7
  56. package/docs/types/interfaces/ConnectionRequest.md +3 -3
  57. package/docs/types/interfaces/Counterparty.md +10 -10
  58. package/docs/types/interfaces/DeclarationProof.md +6 -6
  59. package/docs/types/interfaces/Deposit.md +9 -9
  60. package/docs/types/interfaces/DepositRequest.md +7 -7
  61. package/docs/types/interfaces/DepositRequestOptions.md +1 -1
  62. package/docs/types/interfaces/LegalPerson.md +13 -13
  63. package/docs/types/interfaces/MicroTransferProof.md +9 -9
  64. package/docs/types/interfaces/NaturalPerson.md +13 -13
  65. package/docs/types/interfaces/OwnershipProof.md +4 -4
  66. package/docs/types/interfaces/ScreenshotProof.md +5 -5
  67. package/docs/types/interfaces/SignatureProof.md +7 -7
  68. package/docs/types/interfaces/ThresholdOptions.md +3 -3
  69. package/docs/types/interfaces/Transaction.md +8 -8
  70. package/docs/types/interfaces/TransactionOptions.md +6 -6
  71. package/docs/types/interfaces/TransactionResponse.md +8 -8
  72. package/docs/types/interfaces/VASP.md +9 -9
  73. package/docs/types/interfaces/Wallet.md +8 -8
  74. package/docs/types/interfaces/Withdrawal.md +9 -9
  75. package/docs/types/type-aliases/BlockchainAddress.md +1 -1
  76. package/docs/types/type-aliases/CAIP10.md +1 -1
  77. package/docs/types/type-aliases/CAIP19.md +1 -1
  78. package/docs/types/type-aliases/CAIP2.md +1 -1
  79. package/docs/types/type-aliases/CAIP220.md +1 -1
  80. package/docs/types/type-aliases/Cancel.md +1 -1
  81. package/docs/types/type-aliases/Completed.md +1 -1
  82. package/docs/types/type-aliases/ComponentMessage.md +2 -4
  83. package/docs/types/type-aliases/ConnectionOptions.md +1 -1
  84. package/docs/types/type-aliases/CryptoCredential.md +1 -1
  85. package/docs/types/type-aliases/DID.md +1 -1
  86. package/docs/types/type-aliases/DTI.md +1 -1
  87. package/docs/types/type-aliases/Destination.md +1 -1
  88. package/docs/types/type-aliases/Error.md +17 -1
  89. package/docs/types/type-aliases/FieldOptions.md +1 -1
  90. package/docs/types/type-aliases/FieldTypes.md +1 -1
  91. package/docs/types/type-aliases/HostMessage.md +1 -1
  92. package/docs/types/type-aliases/ISOCurrency.md +1 -1
  93. package/docs/types/type-aliases/InvalidValue.md +1 -1
  94. package/docs/types/type-aliases/LEI.md +1 -1
  95. package/docs/types/type-aliases/LegalPersonFieldName.md +1 -1
  96. package/docs/types/type-aliases/LegalPersonFields.md +1 -1
  97. package/docs/types/type-aliases/NaturalPersonFieldName.md +1 -1
  98. package/docs/types/type-aliases/NaturalPersonFields.md +1 -1
  99. package/docs/types/type-aliases/NotabeneAsset.md +1 -1
  100. package/docs/types/type-aliases/ResizeRequest.md +1 -1
  101. package/docs/types/type-aliases/Source.md +1 -1
  102. package/docs/types/type-aliases/Theme.md +9 -9
  103. package/docs/types/type-aliases/TransactionAsset.md +1 -1
  104. package/docs/types/type-aliases/TravelAddress.md +1 -1
  105. package/docs/types/type-aliases/URI.md +1 -1
  106. package/docs/types/type-aliases/UUID.md +1 -1
  107. package/docs/types/type-aliases/UpdateValue.md +1 -1
  108. package/docs/types/type-aliases/V1Asset.md +1 -1
  109. package/docs/types/type-aliases/V1Transaction.md +1 -1
  110. package/docs/types/type-aliases/VASPOptions.md +5 -1
  111. package/docs/types/type-aliases/ValidationError.md +1 -1
  112. package/package.json +15 -14
  113. package/src/components/EmbeddedComponent.ts +45 -4
  114. package/src/components/__tests__/EmbeddedComponent.test.ts +126 -3
  115. package/src/notabene.ts +23 -23
  116. package/src/types.ts +23 -18
  117. package/src/utils/__tests__/MessageEventManager.test.ts +7 -7
  118. package/docs/types/type-aliases/Ready.md +0 -21
@@ -24,4 +24,4 @@ Represents a resize request component message. This is handled by the library.
24
24
 
25
25
  ## Defined in
26
26
 
27
- [types.ts:807](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L807)
27
+ [types.ts:811](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L811)
@@ -12,4 +12,4 @@ The source of a transaction
12
12
 
13
13
  ## Defined in
14
14
 
15
- [types.ts:207](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L207)
15
+ [types.ts:207](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L207)
@@ -12,22 +12,22 @@ The theme of the Notabene SDK
12
12
 
13
13
  ## Type declaration
14
14
 
15
- ### fontFamily
15
+ ### fontFamily?
16
16
 
17
- > **fontFamily**: `string`
17
+ > `optional` **fontFamily**: `string`
18
18
 
19
- ### logo
19
+ ### logo?
20
20
 
21
- > **logo**: `string`
21
+ > `optional` **logo**: `string`
22
22
 
23
- ### primaryColor
23
+ ### primaryColor?
24
24
 
25
- > **primaryColor**: `string`
25
+ > `optional` **primaryColor**: `string`
26
26
 
27
- ### secondaryColor
27
+ ### secondaryColor?
28
28
 
29
- > **secondaryColor**: `string`
29
+ > `optional` **secondaryColor**: `string`
30
30
 
31
31
  ## Defined in
32
32
 
33
- [types.ts:237](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L237)
33
+ [types.ts:237](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L237)
@@ -12,4 +12,4 @@ The asset of a transaction either a Notabene asset, a CAIP-19 asset, or a DTI.
12
12
 
13
13
  ## Defined in
14
14
 
15
- [types.ts:145](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L145)
15
+ [types.ts:145](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L145)
@@ -34,4 +34,4 @@ VASPs and blockchain networks while maintaining privacy.
34
34
 
35
35
  ## Defined in
36
36
 
37
- [types.ts:186](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L186)
37
+ [types.ts:186](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L186)
@@ -12,4 +12,4 @@ A Uniform Resource Identifier
12
12
 
13
13
  ## Defined in
14
14
 
15
- [types.ts:213](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L213)
15
+ [types.ts:213](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L213)
@@ -24,4 +24,4 @@ Format: 8-4-4-4-12 hexadecimal digits
24
24
 
25
25
  ## Defined in
26
26
 
27
- [types.ts:39](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L39)
27
+ [types.ts:39](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L39)
@@ -51,4 +51,4 @@ and its configuration without requiring a full reload/reinitialize.
51
51
 
52
52
  ## Defined in
53
53
 
54
- [types.ts:907](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L907)
54
+ [types.ts:912](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L912)
@@ -33,4 +33,4 @@ Used for backwards compatibility with V1 API transaction payloads:
33
33
 
34
34
  ## Defined in
35
35
 
36
- [types.ts:605](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L605)
36
+ [types.ts:605](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L605)
@@ -46,4 +46,4 @@ Transaction payload suitable for calling Notabene v1 tx/create
46
46
 
47
47
  ## Defined in
48
48
 
49
- [types.ts:611](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L611)
49
+ [types.ts:611](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L611)
@@ -20,6 +20,10 @@ Options for which VASPs to be searchable
20
20
 
21
21
  > `optional` **onlyActive**: `boolean`
22
22
 
23
+ ### searchable?
24
+
25
+ > `optional` **searchable**: [`VASPSearchControl`](../enumerations/VASPSearchControl.md)[]
26
+
23
27
  ## Defined in
24
28
 
25
- [types.ts:707](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L707)
29
+ [types.ts:720](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L720)
@@ -22,4 +22,4 @@ Validation error
22
22
 
23
23
  ## Defined in
24
24
 
25
- [types.ts:677](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f75feb1dd5dd91003bcc9aa8429d05c94c878b06/src/types.ts#L677)
25
+ [types.ts:677](https://gitlab.com/notabene/open-source/javascript-sdk/-/blob/f4e73b4e984837ed8a53f91590a8d1276a1aa25a/src/types.ts#L677)
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  },
10
10
  "author": "Notabene <developers@notabene.id>",
11
11
  "license": "MIT",
12
- "packageManager": "yarn@3.2.2",
13
- "version": "2.0.2",
12
+ "packageManager": "yarn@4.5.1",
13
+ "version": "2.0.4-NEXT.0",
14
14
  "source": "src/notabene.ts",
15
15
  "main": "dist/notabene.js",
16
16
  "types": "dist/notabene.d.ts",
@@ -27,17 +27,18 @@
27
27
  "prepare": "husky",
28
28
  "dev": "vite",
29
29
  "preview": "vite preview",
30
- "watch": "parcel watch",
31
30
  "build:dev": "yarn build && yarn dev",
32
- "build:clean": "rimraf dist/ ts-out coverage temp etc",
33
- "build": "yarn lint && vite build && tsc && api-extractor run && yarn docs",
34
- "lint": "eslint .",
35
- "format": "prettier --write .",
31
+ "build:clean": "rimraf dist ts-out coverage temp",
32
+ "build": "yarn lint && vite build && yarn typecheck && api-extractor run && yarn docs",
33
+ "lint": "eslint . --max-warnings 0",
34
+ "lint:fix": "yarn lint --fix --cache --no-warn-ignored",
35
+ "format": "prettier --write --cache .",
36
+ "format:check": "prettier --check .",
37
+ "format:fix": "prettier --write .",
36
38
  "test": "vitest",
37
- "typecheck": "tsc --noEmit",
39
+ "typecheck": "tsc --skipLibCheck",
38
40
  "coverage": "vitest run --coverage --coverage.extension=.ts",
39
- "release": "semantic-release",
40
- "publish": "yarn build && npm publish"
41
+ "release": "semantic-release"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@commitlint/cli": "^19.5.0",
@@ -48,8 +49,6 @@
48
49
  "@semantic-release/git": "^10.0.1",
49
50
  "@semantic-release/gitlab": "^13.2.1",
50
51
  "@semantic-release/npm": "^12.0.1",
51
- "@typescript-eslint/eslint-plugin": "^8.11.0",
52
- "@typescript-eslint/parser": "^8.11.0",
53
52
  "@vitest/coverage-v8": "2.1.3",
54
53
  "eslint": "^9.14.0",
55
54
  "eslint-config-prettier": "^9.1.0",
@@ -59,8 +58,8 @@
59
58
  "husky": "^9.1.6",
60
59
  "jsdom": "^25.0.1",
61
60
  "lint-staged": "^15.2.10",
62
- "organize-imports-cli": "^0.10.0",
63
61
  "prettier": "^3.3.3",
62
+ "prettier-plugin-organize-imports": "^4.1.0",
64
63
  "rimraf": "^6.0.1",
65
64
  "semantic-release": "^24.2.0",
66
65
  "typedoc": "^0.26.11",
@@ -72,8 +71,10 @@
72
71
  },
73
72
  "lint-staged": {
74
73
  "*.ts": [
74
+ "yarn format:check",
75
75
  "organize-imports-cli",
76
- "eslint --fix"
76
+ "yarn lint:fix",
77
+ "yarn test --run"
77
78
  ]
78
79
  },
79
80
  "commitlint": {
@@ -102,8 +102,9 @@ export default class EmbeddedComponent<V, O> {
102
102
  this.removeEmbed();
103
103
  this.iframe = document.createElement('iframe');
104
104
  this.iframe.src = this.url + (!modal ? '&embedded=true' : '');
105
- this.iframe.allow = 'web-share; clipboard-write';
105
+ this.iframe.allow = 'web-share; clipboard-write; hid; bluetooth;';
106
106
  this.iframe.style.width = '100%';
107
+ this.iframe.style.height = '0px';
107
108
  this.iframe.style.border = 'none';
108
109
  this.iframe.style.overflow = 'hidden';
109
110
  this.iframe.scrolling = 'no';
@@ -172,15 +173,21 @@ export default class EmbeddedComponent<V, O> {
172
173
  completion(): Promise<TransactionResponse<V>> {
173
174
  return new Promise((resolve, reject) => {
174
175
  let removeComplete: undefined | (() => void) = undefined;
176
+ let removeCancel: undefined | (() => void) = undefined;
175
177
  let removeError: undefined | (() => void) = undefined;
176
178
  function cleanup() {
177
179
  if (removeComplete) removeComplete();
180
+ if (removeCancel) removeCancel();
178
181
  if (removeError) removeError();
179
182
  }
180
183
  removeComplete = this.on(CMType.COMPLETE, (message) => {
181
184
  resolve((message as any).response);
182
185
  cleanup();
183
186
  });
187
+ removeCancel = this.on(CMType.CANCEL, () => {
188
+ reject(new Error('User cancelled'));
189
+ cleanup();
190
+ });
184
191
  removeError = this.on('error', (message) => {
185
192
  reject(new Error((message as any).message));
186
193
  cleanup();
@@ -206,11 +213,11 @@ export default class EmbeddedComponent<V, O> {
206
213
 
207
214
  document.body.appendChild(this.modal);
208
215
  this.embed(this.modal, true);
209
- this.on(CMType.CANCEL, () => {
216
+ const removeCancel = this.on(CMType.CANCEL, () => {
210
217
  this.closeModal();
211
218
  });
212
219
 
213
- this.on(CMType.COMPLETE, () => {
220
+ const removeComplete = this.on(CMType.COMPLETE, () => {
214
221
  this.closeModal();
215
222
  });
216
223
 
@@ -219,8 +226,12 @@ export default class EmbeddedComponent<V, O> {
219
226
  // console.log('click');
220
227
  this.closeModal();
221
228
  });
222
- return this.completion();
229
+ return this.completion().finally(() => {
230
+ removeCancel();
231
+ removeComplete();
232
+ });
223
233
  }
234
+
224
235
  /**
225
236
  * Closes the modal dialog
226
237
  *
@@ -234,4 +245,34 @@ export default class EmbeddedComponent<V, O> {
234
245
  this.modal = undefined;
235
246
  }
236
247
  }
248
+
249
+ /**
250
+ * Opens the component in a popup window. This may be needed to support many self-hosted wallets
251
+ * @returns A promise that resolves with the transaction response
252
+ * @see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/open#restrictions)
253
+ * @see [Cross-Origin-Opener-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy)
254
+ */
255
+ public popup(): Promise<TransactionResponse<V>> {
256
+ const popup = window.open(this.url, '_blank', 'popup=true');
257
+ window.addEventListener('message', (event: MessageEvent) => {
258
+ if (event.source !== popup) {
259
+ return;
260
+ }
261
+ console.log('received message from popup', event.data);
262
+ this.eventManager?.setPort(event.ports[0]);
263
+ });
264
+
265
+ const removeCancel = this.on(CMType.CANCEL, () => {
266
+ popup?.close();
267
+ });
268
+
269
+ const removeComplete = this.on(CMType.COMPLETE, () => {
270
+ popup?.close();
271
+ });
272
+
273
+ return this.completion().finally(() => {
274
+ removeCancel();
275
+ removeComplete();
276
+ });
277
+ }
237
278
  }
@@ -281,8 +281,8 @@ describe('EmbeddedComponent', () => {
281
281
  vi.unstubAllGlobals();
282
282
  });
283
283
 
284
- test('modal closes on cancel message', () => {
285
- component.openModal();
284
+ test('modal closes on cancel message', async () => {
285
+ const completionPromise = component.openModal();
286
286
 
287
287
  // Trigger cancel message through event manager
288
288
  component['eventManager']['handleMessage']({
@@ -291,7 +291,9 @@ describe('EmbeddedComponent', () => {
291
291
 
292
292
  expect(dialog.close).toHaveBeenCalled();
293
293
  expect(dialog.remove).toHaveBeenCalled();
294
- // await expect(completionPromise).rejects.toThrow();
294
+
295
+ // Add expectation for the rejection
296
+ await expect(completionPromise).rejects.toThrow('User cancelled');
295
297
  });
296
298
 
297
299
  test('modal closes on completion', async () => {
@@ -527,4 +529,125 @@ describe('EmbeddedComponent', () => {
527
529
  expect(component.options).toEqual(newOptions);
528
530
  });
529
531
  });
532
+
533
+ describe('popup', () => {
534
+ let component: EmbeddedComponent<Withdrawal, TransactionOptions>;
535
+ let mockWindow: Window;
536
+ let popupWindow: Window;
537
+
538
+ beforeEach(() => {
539
+ popupWindow = {
540
+ close: vi.fn(),
541
+ } as unknown as Window;
542
+
543
+ mockWindow = {
544
+ open: vi.fn().mockReturnValue(popupWindow),
545
+ addEventListener: vi.fn(),
546
+ } as unknown as Window;
547
+
548
+ vi.stubGlobal('window', mockWindow);
549
+
550
+ component = new EmbeddedComponent<Withdrawal, TransactionOptions>(
551
+ url,
552
+ value,
553
+ );
554
+ });
555
+
556
+ afterEach(() => {
557
+ vi.unstubAllGlobals();
558
+ });
559
+
560
+ test('opens popup window with correct parameters', () => {
561
+ component.popup();
562
+ expect(mockWindow.open).toHaveBeenCalledWith(url, '_blank', 'popup=true');
563
+ });
564
+
565
+ test('popup closes on cancel message', async () => {
566
+ const completionPromise = component.popup();
567
+
568
+ // Trigger cancel message through event manager
569
+ component['eventManager']['handleMessage']({
570
+ data: { type: CMType.CANCEL },
571
+ } as MessageEvent);
572
+
573
+ expect(popupWindow.close).toHaveBeenCalled();
574
+ await expect(completionPromise).rejects.toThrow('User cancelled');
575
+ });
576
+
577
+ test('popup closes on completion', async () => {
578
+ const completionPromise = component.popup();
579
+ const response = { valid: true, value: 'completed' };
580
+
581
+ // Trigger complete message through event manager
582
+ component['eventManager']['handleMessage']({
583
+ data: { type: CMType.COMPLETE, response },
584
+ } as MessageEvent);
585
+
586
+ expect(popupWindow.close).toHaveBeenCalled();
587
+ await expect(completionPromise).resolves.toBe(response);
588
+ });
589
+
590
+ test('handles message events from popup window', async () => {
591
+ const completionPromise = component.popup(); // Store the promise
592
+
593
+ // Get the event listener callback
594
+ const messageHandler =
595
+ // @ts-expect-error TS is getting confused with the mock
596
+ (mockWindow.addEventListener as vi.Mock).mock.calls.find(
597
+ // @ts-expect-error TS is getting confused with the mock
598
+ (call) => call[0] === 'message',
599
+ )?.[1];
600
+
601
+ expect(messageHandler).toBeDefined();
602
+
603
+ // Mock a message event from the popup
604
+ const mockPort = { start: vi.fn() };
605
+ const mockEvent = {
606
+ source: popupWindow,
607
+ ports: [mockPort],
608
+ };
609
+
610
+ // Call the handler
611
+ messageHandler(mockEvent);
612
+
613
+ // Verify the port was set in the event manager
614
+ expect(component['eventManager']['port']).toBe(mockPort);
615
+
616
+ // Clean up by completing the promise
617
+ component['eventManager']['handleMessage']({
618
+ data: { type: CMType.COMPLETE, response: { valid: true } },
619
+ } as MessageEvent);
620
+
621
+ await completionPromise; // Wait for the promise to complete
622
+ });
623
+
624
+ test('ignores message events from other sources', async () => {
625
+ const completionPromise = component.popup();
626
+
627
+ const messageHandler =
628
+ // @ts-expect-error TS is getting confused with the mock
629
+ (mockWindow.addEventListener as vi.Mock).mock.calls.find(
630
+ // @ts-expect-error TS is getting confused with the mock
631
+ (call) => call[0] === 'message',
632
+ )?.[1];
633
+
634
+ // Mock a message event from a different source
635
+ const mockEvent = {
636
+ source: {} as Window,
637
+ ports: [{ start: vi.fn() }],
638
+ };
639
+
640
+ messageHandler(mockEvent);
641
+
642
+ // Verify the port was not set in the event manager
643
+ expect(component['eventManager']['port']).toBeUndefined();
644
+
645
+ // Clean up by completing the promise
646
+ component['eventManager']['handleMessage']({
647
+ data: { type: CMType.COMPLETE, response: { valid: true } },
648
+ } as MessageEvent);
649
+
650
+ await completionPromise; // Wait for the promise to complete
651
+ });
652
+ });
530
653
  });
package/src/notabene.ts CHANGED
@@ -33,7 +33,6 @@ import type {
33
33
  NaturalPerson,
34
34
  NotabeneAsset,
35
35
  OwnershipProof,
36
- Ready,
37
36
  ResizeRequest,
38
37
  ScreenshotProof,
39
38
  SignatureProof,
@@ -61,26 +60,30 @@ import {
61
60
  ProofTypes,
62
61
  Status,
63
62
  ValidationSections,
63
+ VASPSearchControl,
64
64
  } from './types';
65
65
  import { type MessageCallback } from './utils/MessageEventManager';
66
66
  import { decodeFragmentToObject, encodeObjectToFragment } from './utils/urls';
67
67
  // Must be exported for React Native SDK to use
68
68
  export { default as EmbeddedComponent } from './components/EmbeddedComponent';
69
+ export {
70
+ AgentType,
71
+ CMType,
72
+ decodeFragmentToObject,
73
+ HMType,
74
+ PersonType,
75
+ ProofStatus,
76
+ ProofTypes,
77
+ Status,
78
+ ValidationSections,
79
+ VASPSearchControl,
80
+ };
69
81
  export type {
70
82
  Agent,
71
83
  BlockchainAddress,
72
- CAIP2,
73
84
  CAIP10,
74
85
  CAIP19,
75
- CryptoCredential,
76
- TravelAddress,
77
- NotabeneAsset,
78
- DTI,
79
- VASPOptions,
80
- NationalIdentification,
81
- FieldTypes,
82
- DID,
83
- MessageCallback,
86
+ CAIP2,
84
87
  CallbackOptions,
85
88
  Cancel,
86
89
  Completed,
@@ -88,20 +91,26 @@ export type {
88
91
  ComponentResponse,
89
92
  ConnectionRequest,
90
93
  Counterparty,
94
+ CryptoCredential,
91
95
  DeclarationProof,
92
96
  Deposit,
93
97
  DepositRequest,
94
98
  Destination,
99
+ DID,
100
+ DTI,
95
101
  Error,
102
+ FieldTypes,
96
103
  HostMessage,
97
104
  InvalidValue,
98
105
  IVMS101,
99
106
  LegalPerson,
100
107
  LEI,
108
+ MessageCallback,
101
109
  MicroTransferProof,
110
+ NationalIdentification,
102
111
  NaturalPerson,
112
+ NotabeneAsset,
103
113
  OwnershipProof,
104
- Ready,
105
114
  ResizeRequest,
106
115
  ScreenshotProof,
107
116
  SignatureProof,
@@ -111,24 +120,15 @@ export type {
111
120
  TransactionAsset,
112
121
  TransactionOptions,
113
122
  TransactionResponse,
123
+ TravelAddress,
114
124
  UpdateValue,
115
125
  V1Transaction,
116
126
  ValidationError,
117
127
  VASP,
128
+ VASPOptions,
118
129
  Wallet,
119
130
  Withdrawal,
120
131
  };
121
- export {
122
- CMType,
123
- HMType,
124
- ProofStatus,
125
- ProofTypes,
126
- PersonType,
127
- Status,
128
- AgentType,
129
- ValidationSections,
130
- decodeFragmentToObject,
131
- };
132
132
 
133
133
  /**
134
134
  * Configuration for the Notabene SDK
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  Address,
3
3
  Beneficiary,
4
4
  ISOCountryCode,
@@ -235,10 +235,10 @@ export type ISOCurrency = string;
235
235
  * @public
236
236
  */
237
237
  export type Theme = {
238
- primaryColor: string;
239
- secondaryColor: string;
240
- fontFamily: string;
241
- logo: string;
238
+ primaryColor?: string;
239
+ secondaryColor?: string;
240
+ fontFamily?: string;
241
+ logo?: string;
242
242
  };
243
243
 
244
244
  /**
@@ -700,6 +700,19 @@ export type FieldTypes = {
700
700
  legalPerson?: LegalPersonFields;
701
701
  };
702
702
 
703
+ /**
704
+ * VASP Visibility Control representing allow/deny behaviour for VASP visibility
705
+ *
706
+ * @remarks
707
+ * - ALLOWED: Include VASPs you have explicitly allowed in the Notabene Network
708
+ * - PENDING: Include VASPs neither allowed nor denied
709
+ * @public
710
+ */
711
+ export const enum VASPSearchControl {
712
+ ALLOWED = 'allowed',
713
+ PENDING = 'pending',
714
+ }
715
+
703
716
  /**
704
717
  * Options for which VASPs to be searchable
705
718
  * @public
@@ -707,6 +720,7 @@ export type FieldTypes = {
707
720
  export type VASPOptions = {
708
721
  addUnknown?: boolean;
709
722
  onlyActive?: boolean;
723
+ searchable?: VASPSearchControl[]; // If array left empty all VASPs will be searchable
710
724
  };
711
725
 
712
726
  /**
@@ -765,7 +779,6 @@ export interface TransactionOptions {
765
779
  * - COMPLETE: Indicates a completed operation with response data
766
780
  * - RESIZE: Request to adjust component size/dimensions
767
781
  * - RESULT: Operation result notification
768
- * - READY: Component is initialized and ready
769
782
  * - INVALID: Validation failed with errors
770
783
  * - ERROR: Operation encountered an error
771
784
  * - CANCEL: Operation was cancelled
@@ -775,7 +788,6 @@ export const enum CMType {
775
788
  COMPLETE = 'complete',
776
789
  RESIZE = 'resize',
777
790
  RESULT = 'result',
778
- READY = 'ready',
779
791
  INVALID = 'invalid',
780
792
  ERROR = 'error',
781
793
  CANCEL = 'cancel',
@@ -792,14 +804,6 @@ export type Completed<T> = {
792
804
  response: TransactionResponse<T>;
793
805
  };
794
806
 
795
- /**
796
- * Represents a ready component message
797
- * @public
798
- */
799
- export type Ready = {
800
- type: CMType.READY;
801
- };
802
-
803
807
  /**
804
808
  * Represents a resize request component message. This is handled by the library.
805
809
  * @internal
@@ -812,11 +816,15 @@ export type ResizeRequest = {
812
816
  /**
813
817
  * Represents an error component message
814
818
  * @param message - Error message
819
+ * @param description - Description of the error message
820
+ * @param identifier - Identifier code of the error message
815
821
  * @public
816
822
  */
817
823
  export type Error = {
818
824
  type: CMType.ERROR;
819
825
  message: string;
826
+ description?: string;
827
+ identifier?: string;
820
828
  };
821
829
 
822
830
  /**
@@ -849,7 +857,6 @@ export type InvalidValue<T> = {
849
857
  * - Completed: Operation finished successfully with response data
850
858
  * - Cancel: User cancelled the operation
851
859
  * - Error: Operation failed with error message
852
- * - Ready: Component initialized and ready for use
853
860
  * - ResizeRequest: Component needs to adjust its dimensions
854
861
  * - InvalidValue: Validation failed with current partial value
855
862
  *
@@ -858,7 +865,6 @@ export type InvalidValue<T> = {
858
865
  * @see {@link Completed} For successful completion message format
859
866
  * @see {@link Cancel} For cancellation message format
860
867
  * @see {@link Error} For error message format
861
- * @see {@link Ready} For ready message format
862
868
  * @see {@link ResizeRequest} For resize message format
863
869
  * @see {@link InvalidValue} For validation failure message format
864
870
  * @public
@@ -867,7 +873,6 @@ export type ComponentMessage<T> =
867
873
  | Completed<T>
868
874
  | Cancel
869
875
  | Error
870
- | Ready
871
876
  | ResizeRequest
872
877
  | InvalidValue<T>;
873
878