@notabene/javascript-sdk 1.34.0 → 2.0.0-next.3

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 (73) hide show
  1. package/.gitlab-ci.yml +12 -1
  2. package/.husky/commit-msg +0 -0
  3. package/.husky/pre-commit +0 -0
  4. package/.husky/pre-push +1 -1
  5. package/.vscode/extensions.json +1 -5
  6. package/.vscode/settings.json +4 -4
  7. package/.yarn/releases/yarn-berry.cjs +925 -0
  8. package/.yarnrc.yml +3 -0
  9. package/README.md +126 -69
  10. package/api-extractor.json +434 -0
  11. package/dist/notabene.cjs +1 -0
  12. package/dist/notabene.d.ts +678 -0
  13. package/dist/notabene.js +187 -0
  14. package/dist/tsdoc-metadata.json +11 -0
  15. package/eslint.config.js +24 -0
  16. package/etc/javascript-sdk.api.md +363 -0
  17. package/index.html +135 -0
  18. package/package.json +29 -54
  19. package/src/__tests__/notabene.test.ts +131 -0
  20. package/src/arbitraries.ts +13 -0
  21. package/src/components/EmbeddedComponent.ts +110 -0
  22. package/src/components/__tests__/EmbeddedComponent.test.ts +160 -0
  23. package/src/ivms/types.ts +2 -0
  24. package/src/notabene.ts +174 -290
  25. package/src/types.ts +380 -49
  26. package/src/utils/MessageEventManager.ts +55 -0
  27. package/src/utils/__tests__/MessageEventManager.test.ts +95 -0
  28. package/src/utils/arbitraries.ts +21 -0
  29. package/src/utils/caip.ts +16 -0
  30. package/src/utils/urls.ts +15 -0
  31. package/temp/javascript-sdk.api.json +3509 -0
  32. package/temp/javascript-sdk.api.md +363 -0
  33. package/ts-out/src/__tests__/notabene.test.d.ts +1 -0
  34. package/ts-out/src/__tests__/notabene.test.js +97 -0
  35. package/ts-out/src/arbitraries.d.ts +4 -0
  36. package/ts-out/src/arbitraries.js +8 -0
  37. package/ts-out/src/components/EmbeddedComponent.d.ts +25 -0
  38. package/ts-out/src/components/EmbeddedComponent.js +87 -0
  39. package/ts-out/src/components/__tests__/EmbeddedComponent.test.d.ts +1 -0
  40. package/ts-out/src/components/__tests__/EmbeddedComponent.test.js +132 -0
  41. package/ts-out/src/ivms/types.d.ts +252 -0
  42. package/ts-out/src/ivms/types.js +1 -0
  43. package/ts-out/src/notabene.d.ts +35 -0
  44. package/ts-out/src/notabene.js +60 -0
  45. package/ts-out/src/types.d.ts +357 -0
  46. package/ts-out/src/types.js +85 -0
  47. package/ts-out/src/utils/MessageEventManager.d.ts +12 -0
  48. package/ts-out/src/utils/MessageEventManager.js +45 -0
  49. package/ts-out/src/utils/__tests__/MessageEventManager.test.d.ts +1 -0
  50. package/ts-out/src/utils/__tests__/MessageEventManager.test.js +73 -0
  51. package/ts-out/src/utils/arbitraries.d.ts +6 -0
  52. package/ts-out/src/utils/arbitraries.js +7 -0
  53. package/ts-out/src/utils/caip.d.ts +13 -0
  54. package/ts-out/src/utils/caip.js +15 -0
  55. package/ts-out/src/utils/urls.d.ts +1 -0
  56. package/ts-out/src/utils/urls.js +14 -0
  57. package/ts-out/tsconfig.tsbuildinfo +1 -0
  58. package/tsconfig.json +15 -11
  59. package/tsconfig.tsbuildinfo +1 -0
  60. package/vite.config.js +13 -0
  61. package/.envrc.template +0 -1
  62. package/.eslintignore +0 -3
  63. package/.eslintrc.js +0 -13
  64. package/.nvmrc +0 -1
  65. package/.tool-versions +0 -3
  66. package/dist/es/index.js +0 -1
  67. package/dist/lib/index.js +0 -376
  68. package/jest.config.js +0 -5
  69. package/public/index.html +0 -93
  70. package/public/js/.gitkeep +0 -0
  71. package/src/lib/index.ts +0 -2
  72. package/src/module/index.ts +0 -10
  73. package/src/zoidComponentProps.ts +0 -81
package/.yarnrc.yml ADDED
@@ -0,0 +1,3 @@
1
+ nodeLinker: node-modules
2
+
3
+ yarnPath: .yarn/releases/yarn-berry.cjs
package/README.md CHANGED
@@ -8,27 +8,37 @@
8
8
  [![pipeline status](https://gitlab.com/notabene/open-source/javascript-sdk/badges/master/pipeline.svg)](https://gitlab.com/notabene/open-source/javascript-sdk/-/commits/master)
9
9
  [![Latest Release](https://gitlab.com/notabene/open-source/javascript-sdk/-/badges/release.svg)](https://gitlab.com/notabene/open-source/javascript-sdk/-/releases)
10
10
 
11
- This library is the JavaScript SDK for loading the widget on a frontend.
11
+ This library is the JavaScript SDK for loading the Notabene UX components in the front-end.
12
12
 
13
13
  [Documentation](https://devx.notabene.id/docs/widget-v2) •
14
14
  [Installation](#installation)
15
15
 
16
16
  </div>
17
17
 
18
- - [Installation](#installation)
19
- - [Usage](#usage)
20
- - [Supported asset formats](#supported-asset-formats)
21
- - [Re-rendering](#re-rendering)
22
- - [Error handling](#error-handling)
23
- - [Customization](#customization)
24
- - [Functionality](#functionality)
25
- - [Pass the variables in the configuration](#pass-the-variables-in-the-configuration)
26
- - [Theme](#theme)
27
- - [Dictionary](#dictionary)
28
- - [Fields Properties](#fields-properties)
29
- - [Fallbacks](#fallbacks)
30
- - [Transaction Custom Asset Price](#transaction-custom-asset-price)
31
- - [License](#license)
18
+ - [JavaScript SDK](#javascript-sdk)
19
+ - [Installation](#installation)
20
+ - [Usage](#usage)
21
+ - [Authentication](#authentication)
22
+ - [Assisted Withdrawal](#assisted-withdrawal)
23
+ - [Embedded Component](#embedded-component)
24
+ - [Dynamic updates](#dynamic-updates)
25
+ - [Linked Component](#linked-component)
26
+ - [Transaction parameters](#transaction-parameters)
27
+ - [Asset specification](#asset-specification)
28
+ - [Transaction amount specification](#transaction-amount-specification)
29
+ - [Destination address](#destination-address)
30
+ - [Error handling](#error-handling)
31
+ - [Customization](#customization)
32
+ - [Functionality](#functionality)
33
+ - [Pass the variables in the configuration](#pass-the-variables-in-the-configuration)
34
+ - [Theme](#theme)
35
+ - [Dictionary](#dictionary)
36
+ - [The property name must be the same as the text in the widget, for it to be replaced](#the-property-name-must-be-the-same-as-the-text-in-the-widget-for-it-to-be-replaced)
37
+ - [Fields Properties](#fields-properties)
38
+ - [Fallbacks](#fallbacks)
39
+ - [Opt-In Features](#opt-in-features)
40
+ - [Transaction Custom Asset Price](#transaction-custom-asset-price)
41
+ - [License](#license)
32
42
 
33
43
  ## Installation
34
44
 
@@ -57,83 +67,121 @@ Use the [customer token endpoint](https://devx.notabene.id/docs/customertoken) w
57
67
  Create a new Notabene instance:
58
68
 
59
69
  ```js
70
+
60
71
  const notabene = new Notabene({
61
- vaspDID: 'did:ethr:0x94c38fd29ef36f5cb2f7bc771f9d5bd9f7d05f27',
62
- widget: 'https://beta-widget.notabene.id',
63
- container: '#container',
64
- authToken: '{CUSTOMER_TOKEN}',
65
- onValidStateChange: (isValid) => {
66
- // Use this value to determine if the transaction is ready to be created.
67
- console.log('is transaction valid', isValid);
68
- },
69
- onError: (err) => {
70
- // If any errors are encountered, they will be passed to this function
71
- alert(err.message);
72
- },
72
+ nodeUrl: 'https://api.notabene.id',
73
+ authToken: '{CUSTOMER_TOKEN}'
73
74
  });
74
75
  ```
75
76
 
76
- Then render the widget:
77
+ Use the same `nodeUrl` that you use to interact with the Notabene API.
77
78
 
78
- ```js
79
- // Use this method when you need to collect missing information from the sender about the recipient (normal withdrawal)
80
- notabene.renderWidget('WITHDRAWAL');
79
+ ## Assisted Withdrawal
80
+
81
+ The Withdrawal Assist component helps you collect additional required information from your user during a standard crypto withdrawal process.
81
82
 
82
- // Use this method when you need to collect missing information from the recipient about the sender (for transactions created via notification)
83
- notabene.renderWidget('POST_DEPOSIT');
83
+ ### Embedded Component
84
+
85
+ This will let you embed the component into your existing withdrawal flow.
86
+
87
+ Create an html element to contain the component:
88
+
89
+ ```html
90
+ <div id="nb-withdrawal/>
84
91
  ```
85
92
 
86
- To update the widget as users enter transaction details:
93
+ Instantiate the withdrawal element and mount it using the id from above
87
94
 
88
95
  ```js
89
- notabene.setTransaction({
90
- transactionAsset: 'ETH',
91
- beneficiaryAccountNumber: '0x8d12a197cb00d4747a1fe03395095ce2a5cc6819',
92
- transactionAmount: '2000000000',
93
- });
96
+ const withdrawal = notabene.createWithdrawalAssist(tx, options);
97
+ withdrawal.mount("nb-withdrawal");
94
98
  ```
95
99
 
96
- Once the widget determines the transaction is valid, it will call the `onValidStateChange` callback, to access the transaction details:
100
+ The simplest way to get the result is to use:
97
101
 
98
102
  ```js
99
- const currentTransactionInfo = notabene.tx;
103
+ try {
104
+ const {valid, ivms101} = await withdrawal.completion()
105
+ if (valid) {
106
+ // Submit result to your backend
107
+ }
108
+ } catch (e) {
109
+ console.error(e)
110
+ }
100
111
  ```
101
112
 
102
- ### Supported asset formats
103
-
104
- - `USDC` the simple asset code passed as a `string`, in case different chain (polygon) -> `USDC-POLY`
105
- - `CAIP19` format
106
- ```js
107
- {
108
- caip19: 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'; // for USDC
109
- }
110
- ```
111
- - `coingeckoId` and `network` format
112
- ```js
113
- {
114
- coingeckoId: "usd-coin",
115
- network: "ethereum"
116
- }
117
- ```
113
+ #### Dynamic updates
118
114
 
119
- ---
115
+ To update the component as users enter transaction details:
120
116
 
121
- ### Re-rendering
117
+ ```js
118
+ withdrawal.update({
119
+ asset: 'ETH',
120
+ destination: '0x8d12a197cb00d4747a1fe03395095ce2a5cc6819',
121
+ amountDecimal: 1.12
122
+ });
123
+ ```
122
124
 
123
- **WARNING:** this shouldn't be used often, if you need to change the transaction's initial fields call `setTransaction` again. (This should be used only for tearing down the component).
125
+ To be notified once the validation is completed so you can submit the withdrawal to your back end:
124
126
 
125
- The container of the widget must be in the DOM before calling `destroyWidget` or `renderWidget`.
127
+ ```js
128
+ withdrawal.on('valid', {ivms101} => ...)
129
+ ```
126
130
 
127
- If you need to close and re-render the widget, call the `destroyWidget` method like so:
131
+ To be notified of any errors use:
128
132
 
129
133
  ```js
130
- // Will remove the widget
131
- notabene.destroyWidget();
132
- // Will re-render the widget
133
- notabene.renderWidget();
134
+ withdrawal.on('error',error => ...)
134
135
  ```
135
136
 
136
- Calling the `renderWidget` methods without destroying it first will not work.
137
+ ### Linked Component
138
+
139
+ In some cases, in particular institutional or mobile apps you may prefer to link your customers to the component through an email or redirect the user to it in a mobile app.
140
+
141
+ ```js
142
+ const withdrawal = notabene.createWithdrawalAssist(tx, options, {
143
+ callback: /// a serverside backend url
144
+ redirectUri: // URI of website or mobile app to redirect user to after completion
145
+ });
146
+
147
+ // NodeJS redirect. Link also works in an email.
148
+ res.redirect(withdrawal.url);
149
+ ```
150
+
151
+ Bear in mind that this is a full screen view for your users.
152
+
153
+ The two parameters that should be configured are:
154
+
155
+ - `callback` - a URL for your serverside. On completion this will receive an HTTP POST with the result as a json body and the `authToken` as an `Authorization: Bearer` header.
156
+ - `redirectUri` - the user will be redirected here on completion. The result parameters will be json encoded in the URL fragment. You can use a mobile app schema to intercept these in your mobile app.
157
+
158
+ **Note** for data privacy reasons the callback will be coming from your users web browser and not from our infrastructure, so no static IP is currently possible. Instead please check the `authToken` provided with the request.
159
+
160
+ ## Transaction parameters
161
+
162
+ ### Asset specification
163
+
164
+ The `asset` field the following types of assets specified:
165
+
166
+ - `notabene_asset` code passed as a`string`. See [Notabene Assets Service](https://devx.notabene.id/docs/coins-decimals#assets-service-api).
167
+ - [CAIP-19](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-19.md_) is a chain agnostic format allows you to support the widest amount of assets and blockchains including NFTs.
168
+ - [DTI](https://www.iso.org/standard/80601.html) is the ISO Digital Token Identifier format. See [DTI registry](https://dtif.org/registry-search/) for supported tokens.
169
+
170
+ ### Transaction amount specification
171
+
172
+ Use one of the following
173
+
174
+ - `amountDecimal` A number specifying the amount in decimal format. Eg. `amountDecimal=1.1` would mean 1.1 of for example BTC or ETH.
175
+ - `amountSubunits` A string specifying the amount in the native blockchain subunits eg Satoshi for Bitcoin or wei for Ethereum
176
+
177
+ ### Destination address
178
+
179
+ Specify the beneficiary address as `destination` using one of the following formats:
180
+
181
+ - [CAIP-10](https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md_) is a chain agnostic format allows you to specify the specific blockchain and address
182
+ - [EIP-3770](https://eips.ethereum.org/EIPS/eip-3770) EVM URI
183
+ - [BIP-21](https://en.bitcoin.it/wiki/BIP_0021) Bitcoin URI
184
+ - Native blockchain address
137
185
 
138
186
  ---
139
187
 
@@ -177,13 +225,13 @@ Type | Code | Title | Detail
177
225
 
178
226
  ### Functionality
179
227
 
180
- `transactionTypeAllowed`: `ALL` | `VASP_2_VASP_ONLY` | `SELF_TRANSACTION_ONLY`
228
+ `transactionTypeAllowed`: `ALL` | `VASP_2_VASP_ONLY` | `FIRST_PARTY_ONLY`
181
229
 
182
230
  For limiting the type of transaction destinations you can pass.
183
231
 
184
232
  `ALL`: All transaction destinations are allowed. (DEFAULT)
185
233
  `VASP_2_VASP_ONLY`: Only transaction destinations that are VASPs are allowed.
186
- `SELF_TRANSACTION_ONLY`: Only transaction destinations that the originator owns are allowed.
234
+ `FIRST_PARTY_ONLY`: Only transaction destinations that the originator owns are allowed.
187
235
 
188
236
  ---
189
237
 
@@ -194,6 +242,12 @@ For deciding which ownership proof type you want to use.
194
242
  `SIGNATURE`: The ownership proof will be signed by the originator using a wallet. (DEFAULT)
195
243
  `DECLARATION`: The ownership proof will be declared by the originator using a checkbox.
196
244
 
245
+ ---
246
+
247
+ `counterpartyManualEntry`: `TRUE` | `FALSE`
248
+
249
+ For deciding if you would like to allow your customer to provide a manual counterparty vasp name in the counterparty field.
250
+
197
251
  ### Pass the variables in the configuration
198
252
 
199
253
  ```js
@@ -338,6 +392,7 @@ Possible options and actions:
338
392
  - `DECLARATION` - Falls back to the self declaration flow
339
393
  - `REJECT` - Rejects the transaction and throws an error
340
394
  - The error that will be thrown here will have the following structure
395
+
341
396
  ```js
342
397
  {
343
398
  "type": "WALLET_NOT_SUPPORTED",
@@ -350,6 +405,7 @@ Possible options and actions:
350
405
  ```js
351
406
  fallbacks: [{flow: "WALLET_NOT_SUPPORTED", action: "DECLARATION"}]
352
407
  ```
408
+
353
409
  ---
354
410
 
355
411
  Finally you pass the configuration to a Notabene instance:
@@ -364,6 +420,7 @@ const notabene = new Notabene({
364
420
  fallbacks: [{flow: "WALLET_NOT_SUPPORTED", action: "DECLARATION"}]
365
421
  });
366
422
  ```
423
+
367
424
  ---
368
425
 
369
426
  ### Opt-In Features