@notabene/javascript-sdk 2.0.0-next.2 → 2.0.0-next.21

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 (64) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +289 -233
  3. package/dist/js/notabene.js +1 -0
  4. package/dist/notabene.cjs +1 -1
  5. package/dist/notabene.d.ts +1092 -214
  6. package/dist/notabene.js +284 -113
  7. package/dist/tsdoc-metadata.json +1 -1
  8. package/package.json +36 -26
  9. package/src/__tests__/notabene.test.ts +43 -0
  10. package/src/components/EmbeddedComponent.ts +141 -22
  11. package/src/components/__tests__/EmbeddedComponent.test.ts +73 -20
  12. package/src/ivms/types.ts +230 -152
  13. package/src/locales.ts +47 -0
  14. package/src/notabene.ts +247 -90
  15. package/src/types.ts +769 -152
  16. package/src/utils/MessageEventManager.ts +70 -12
  17. package/src/utils/__tests__/MessageEventManager.test.ts +13 -5
  18. package/src/utils/arbitraries.ts +9 -4
  19. package/.editorconfig +0 -10
  20. package/.gitlab-ci.yml +0 -85
  21. package/.husky/commit-msg +0 -4
  22. package/.husky/pre-commit +0 -4
  23. package/.husky/pre-push +0 -4
  24. package/.prettierrc +0 -4
  25. package/.releaserc.json +0 -16
  26. package/.vscode/extensions.json +0 -3
  27. package/.vscode/settings.json +0 -11
  28. package/.yarn/releases/yarn-berry.cjs +0 -925
  29. package/.yarnrc.yml +0 -3
  30. package/CODEOWNERS +0 -1
  31. package/api-extractor.json +0 -434
  32. package/eslint.config.js +0 -24
  33. package/etc/javascript-sdk.api.md +0 -363
  34. package/index.html +0 -137
  35. package/temp/javascript-sdk.api.json +0 -3509
  36. package/temp/javascript-sdk.api.md +0 -363
  37. package/ts-out/src/__tests__/notabene.test.d.ts +0 -1
  38. package/ts-out/src/__tests__/notabene.test.js +0 -88
  39. package/ts-out/src/arbitraries.d.ts +0 -4
  40. package/ts-out/src/arbitraries.js +0 -8
  41. package/ts-out/src/components/EmbeddedComponent.d.ts +0 -25
  42. package/ts-out/src/components/EmbeddedComponent.js +0 -87
  43. package/ts-out/src/components/__tests__/EmbeddedComponent.test.d.ts +0 -1
  44. package/ts-out/src/components/__tests__/EmbeddedComponent.test.js +0 -132
  45. package/ts-out/src/ivms/types.d.ts +0 -252
  46. package/ts-out/src/ivms/types.js +0 -1
  47. package/ts-out/src/notabene.d.ts +0 -35
  48. package/ts-out/src/notabene.js +0 -59
  49. package/ts-out/src/types.d.ts +0 -357
  50. package/ts-out/src/types.js +0 -85
  51. package/ts-out/src/utils/MessageEventManager.d.ts +0 -12
  52. package/ts-out/src/utils/MessageEventManager.js +0 -45
  53. package/ts-out/src/utils/__tests__/MessageEventManager.test.d.ts +0 -1
  54. package/ts-out/src/utils/__tests__/MessageEventManager.test.js +0 -73
  55. package/ts-out/src/utils/arbitraries.d.ts +0 -6
  56. package/ts-out/src/utils/arbitraries.js +0 -7
  57. package/ts-out/src/utils/caip.d.ts +0 -13
  58. package/ts-out/src/utils/caip.js +0 -15
  59. package/ts-out/src/utils/urls.d.ts +0 -1
  60. package/ts-out/src/utils/urls.js +0 -14
  61. package/ts-out/tsconfig.tsbuildinfo +0 -1
  62. package/tsconfig.json +0 -22
  63. package/tsconfig.tsbuildinfo +0 -1
  64. package/vite.config.js +0 -13
package/src/notabene.ts CHANGED
@@ -1,59 +1,130 @@
1
1
  import EmbeddedComponent from './components/EmbeddedComponent';
2
2
  import type {
3
3
  Agent,
4
- AgentType,
4
+ BlockchainAddress,
5
+ CAIP10,
6
+ CAIP19,
7
+ CAIP2,
5
8
  CallbackOptions,
9
+ Cancel,
10
+ Completed,
6
11
  ComponentMessage,
12
+ ComponentResponse,
13
+ ConnectionRequest,
7
14
  Counterparty,
15
+ CryptoCredential,
8
16
  DeclarationProof,
17
+ Deposit,
18
+ DepositRequest,
9
19
  Destination,
20
+ DID,
21
+ DTI,
22
+ Error,
23
+ FieldTypes,
10
24
  HostMessage,
25
+ InvalidValue,
11
26
  IVMS101,
27
+ LegalPerson,
28
+ LEI,
12
29
  MicroTransferProof,
30
+ NationalIdentification,
31
+ NaturalPerson,
32
+ NotabeneAsset,
13
33
  OwnershipProof,
14
- PersonType,
15
- ProofStatus,
16
- ProofTypes,
34
+ Ready,
35
+ ResizeRequest,
17
36
  ScreenshotProof,
18
37
  SignatureProof,
19
- Status,
20
38
  Theme,
39
+ ThresholdOptions,
21
40
  Transaction,
22
41
  TransactionAsset,
42
+ TransactionOptions,
43
+ TransactionResponse,
44
+ TravelAddress,
45
+ UpdateValue,
46
+ V1Transaction,
47
+ ValidationError,
23
48
  VASP,
49
+ VASPOptions,
24
50
  Wallet,
25
51
  Withdrawal,
26
52
  } from './types';
27
- import { CMType, TransactionResponse } from './types';
53
+ import {
54
+ AgentType,
55
+ CMType,
56
+ HMType,
57
+ PersonType,
58
+ ProofStatus,
59
+ ProofTypes,
60
+ Status,
61
+ ValidationSections,
62
+ } from './types';
63
+ import { type MessageCallback } from './utils/MessageEventManager';
28
64
  import { encodeObjectToFragment } from './utils/urls';
29
-
65
+ // Must be exported for React Native SDK to use
66
+ export { default as EmbeddedComponent } from './components/EmbeddedComponent';
30
67
  export type {
31
- CMType,
68
+ Agent,
69
+ BlockchainAddress,
70
+ CAIP2,
71
+ CAIP10,
72
+ CAIP19,
73
+ CryptoCredential,
74
+ TravelAddress,
75
+ NotabeneAsset,
76
+ DTI,
77
+ VASPOptions,
78
+ NationalIdentification,
79
+ FieldTypes,
80
+ DID,
81
+ MessageCallback,
82
+ CallbackOptions,
83
+ Cancel,
84
+ Completed,
32
85
  ComponentMessage,
33
- EmbeddedComponent,
86
+ ComponentResponse,
87
+ ConnectionRequest,
88
+ Counterparty,
89
+ DeclarationProof,
90
+ Deposit,
91
+ DepositRequest,
92
+ Destination,
93
+ Error,
34
94
  HostMessage,
95
+ InvalidValue,
96
+ IVMS101,
97
+ LegalPerson,
98
+ LEI,
99
+ MicroTransferProof,
100
+ NaturalPerson,
101
+ OwnershipProof,
102
+ Ready,
103
+ ResizeRequest,
104
+ ScreenshotProof,
105
+ SignatureProof,
35
106
  Theme,
36
- Counterparty,
37
- Withdrawal,
107
+ ThresholdOptions,
38
108
  Transaction,
39
- TransactionResponse,
40
- Destination as destination,
41
109
  TransactionAsset,
42
- SignatureProof,
43
- ScreenshotProof,
44
- MicroTransferProof,
45
- DeclarationProof,
46
- Notabene,
110
+ TransactionOptions,
111
+ TransactionResponse,
112
+ UpdateValue,
113
+ V1Transaction,
114
+ ValidationError,
115
+ VASP,
116
+ Wallet,
117
+ Withdrawal,
118
+ };
119
+ export {
120
+ CMType,
121
+ HMType,
47
122
  ProofStatus,
48
123
  ProofTypes,
49
- IVMS101,
50
124
  PersonType,
51
125
  Status,
52
- VASP,
53
- Wallet,
54
- Agent,
55
126
  AgentType,
56
- OwnershipProof,
127
+ ValidationSections,
57
128
  };
58
129
 
59
130
  /**
@@ -62,38 +133,74 @@ export type {
62
133
  * @public
63
134
  */
64
135
  export interface NotabeneConfig {
65
- nodeUrl: string;
66
- authToken: string;
136
+ /**
137
+ * The URL of the Notabene API node
138
+ */
139
+ nodeUrl?: string;
140
+
141
+ /**
142
+ * The authentication token for the Notabene API
143
+ */
144
+ authToken?: string;
145
+
146
+ /**
147
+ * The URL of the Notabene UX components
148
+ */
67
149
  uxUrl?: string;
150
+
151
+ /**
152
+ * Custom theme configuration for the UX components
153
+ */
68
154
  theme?: Theme;
69
- dictionary?: { [key: string]: string };
70
- }
71
155
 
156
+ /**
157
+ * The locale to use for the UX components
158
+ */
159
+ locale?: string;
160
+ }
72
161
  /**
73
162
  * Primary constructor for Notabene UX elements
74
163
  *
164
+ * This class provides methods to create and manage various Notabene components
165
+ * such as withdrawal assist, deposit assist, connect, and deposit request.
166
+ * It also handles URL generation and fragment decoding for these components.
167
+ *
75
168
  * @public
76
169
  */
77
-
78
170
  export default class Notabene {
79
- private nodeUrl: string;
80
- private authToken: string;
171
+ private nodeUrl?: string;
172
+ private authToken?: string;
81
173
  private uxUrl: string;
82
174
  private theme?: Theme;
83
- private dictionary?: { [key: string]: string };
175
+ private locale?: string;
84
176
 
177
+ /**
178
+ * Creates a new instance of the Notabene SDK
179
+ *
180
+ * @param config - Configuration options for the Notabene SDK
181
+ */
85
182
  constructor(config: NotabeneConfig) {
86
- this.uxUrl = config.uxUrl || 'https://ux.notabene.id';
183
+ this.uxUrl = config.uxUrl || 'https://connect.notabene.id';
87
184
  this.nodeUrl = config.nodeUrl;
88
185
  this.authToken = config.authToken;
89
186
  this.theme = config.theme;
90
- this.dictionary = config.dictionary;
187
+ this.locale = config.locale;
91
188
  }
92
189
 
93
- public componentUrl(
190
+ /**
191
+ * Generates a URL for a Notabene component
192
+ *
193
+ * @param path - The path of the component
194
+ * @param value - Transaction data
195
+ * @param configuration - Optional transaction configuration
196
+ * @param callbacks - Optional callback configuration
197
+ * @returns component URL
198
+ * @internal
199
+ */
200
+ componentUrl<V, O>(
94
201
  path: string,
95
- value: Partial<Transaction>,
96
- configuration?: any,
202
+ value: V,
203
+ configuration?: O,
97
204
  callbacks?: CallbackOptions,
98
205
  ): string {
99
206
  const url = new URL(this.uxUrl);
@@ -105,13 +212,13 @@ export default class Notabene {
105
212
  configuration,
106
213
  });
107
214
  url.hash = hash;
108
- url.searchParams.set('nodeUrl', this.nodeUrl);
215
+ if (this.nodeUrl) url.searchParams.set('nodeUrl', this.nodeUrl);
109
216
 
110
217
  if (this.theme) {
111
218
  url.searchParams.set('theme', JSON.stringify(this.theme));
112
219
  }
113
- if (this.dictionary) {
114
- url.searchParams.set('dictionary', JSON.stringify(this.dictionary));
220
+ if (this.locale) {
221
+ url.searchParams.set('locale', this.locale);
115
222
  }
116
223
  if (callbacks) {
117
224
  if (callbacks.callback)
@@ -122,26 +229,122 @@ export default class Notabene {
122
229
  return url.toString();
123
230
  }
124
231
 
125
- public createComponent(
232
+ /**
233
+ * Creates a new embedded component
234
+ *
235
+ * @param path - The path of the component
236
+ * @param value - Transaction data
237
+ * @param options - Optional transaction options
238
+ * @param callbacks - Optional callback configuration
239
+ * @returns A new EmbeddedComponent instance
240
+ * @internal
241
+ */
242
+ createComponent<V, O>(
126
243
  path: string,
127
- value: Partial<Transaction>,
128
- options?: any,
244
+ value: Partial<V>,
245
+ options?: O,
129
246
  callbacks?: CallbackOptions,
130
247
  ) {
131
- return new EmbeddedComponent(
248
+ return new EmbeddedComponent<V, O>(
132
249
  this.componentUrl(path, value, options, callbacks),
133
250
  value,
251
+ options,
134
252
  );
135
253
  }
136
254
 
255
+ /**
256
+ * Creates a withdrawal assist component
257
+ *
258
+ * @param value - Withdrawal transaction data
259
+ * @param options - Optional transaction options
260
+ * @param callbacks - Optional callback configuration
261
+ * @returns A new EmbeddedComponent instance for withdrawal assistance
262
+ */
137
263
  public createWithdrawalAssist(
138
264
  value: Partial<Withdrawal>,
265
+ options?: TransactionOptions,
266
+ callbacks?: CallbackOptions,
267
+ ) {
268
+ return this.createComponent<Withdrawal, TransactionOptions>(
269
+ 'withdrawal-assist',
270
+ value,
271
+ options,
272
+ callbacks,
273
+ );
274
+ }
275
+
276
+ /**
277
+ * Creates a deposit assist component
278
+ *
279
+ * @param value - Deposit transaction data
280
+ * @param options - Optional transaction options
281
+ * @param callbacks - Optional callback configuration
282
+ * @returns A new EmbeddedComponent instance for deposit assistance
283
+ * @alpha
284
+ */
285
+ public createDepositAssist(
286
+ value: Partial<Deposit>,
139
287
  options?: any,
140
288
  callbacks?: CallbackOptions,
141
289
  ) {
142
- return this.createComponent('withdrawal-assist', value, options, callbacks);
290
+ return this.createComponent<Deposit, any>(
291
+ 'deposit-assist',
292
+ value,
293
+ options,
294
+ callbacks,
295
+ );
296
+ }
297
+
298
+ /**
299
+ * Creates a connect component
300
+ *
301
+ * @param value - Connection request data
302
+ * @param options - Optional transaction options
303
+ * @param callbacks - Optional callback configuration
304
+ * @returns A new EmbeddedComponent instance for connection
305
+ * @alpha
306
+ */
307
+ public createConnectWallet(
308
+ value: ConnectionRequest,
309
+ options?: TransactionOptions,
310
+ callbacks?: CallbackOptions,
311
+ ) {
312
+ return this.createComponent<ConnectionRequest, TransactionOptions>(
313
+ 'connect',
314
+ value,
315
+ options,
316
+ callbacks,
317
+ );
318
+ }
319
+
320
+ /**
321
+ * Creates a deposit request component
322
+ *
323
+ * @param value - Deposit request data
324
+ * @param options - Optional transaction options
325
+ * @param callbacks - Optional callback configuration
326
+ * @returns A new EmbeddedComponent instance for deposit requests
327
+ * @public
328
+ */
329
+ public createDepositRequest(
330
+ value: DepositRequest,
331
+ options?: TransactionOptions,
332
+ callbacks?: CallbackOptions,
333
+ ) {
334
+ return this.createComponent<DepositRequest, TransactionOptions>(
335
+ 'deposit-request',
336
+ value,
337
+ options,
338
+ callbacks,
339
+ );
143
340
  }
144
341
 
342
+ /**
343
+ * Decodes a URL fragment into an object
344
+ *
345
+ * @param fragment - The URL fragment to decode
346
+ * @returns An object containing the decoded key-value pairs
347
+ */
145
348
  public decodeFragmentToObject(fragment: string): Record<string, string> {
146
349
  const pairs = fragment.slice(1).split('&');
147
350
  return pairs.reduce(
@@ -153,50 +356,4 @@ export default class Notabene {
153
356
  {} as Record<string, string>,
154
357
  );
155
358
  }
156
-
157
- // private openModal(url: string): void {
158
- // if (this.modal) {
159
- // this.closeModal();
160
- // }
161
- // this.modal = document.createElement('div');
162
- // this.modal.style.position = 'fixed';
163
- // this.modal.style.top = '0';
164
- // this.modal.style.left = '0';
165
- // this.modal.style.width = '100%';
166
- // this.modal.style.height = '100%';
167
- // this.modal.style.backgroundColor = 'rgba(0, 0, 0, 0.5)';
168
- // this.modal.style.display = 'flex';
169
- // this.modal.style.justifyContent = 'center';
170
- // this.modal.style.alignItems = 'center';
171
- // const iframe = document.createElement('iframe');
172
- // iframe.src = url;
173
- // iframe.setAttribute('allowtransparency', 'true');
174
- // // iframe.allowtransparency = true;
175
- // iframe.style.backgroundColor = 'transparent';
176
- // iframe.style.width = '90%';
177
- // iframe.style.height = '90%';
178
- // iframe.style.border = 'none';
179
- // iframe.style.overflow = 'hidden';
180
- // this.modal.appendChild(iframe);
181
- // document.body.appendChild(this.modal);
182
- // this.modal.addEventListener('click', () => {
183
- // console.log('click');
184
- // this.closeModal();
185
- // });
186
- // document.addEventListener('keydown', ({ key }) => {
187
- // console.log(`key: ${key}`);
188
- // if (key === 'Escape') {
189
- // console.log('esc');
190
- // this.closeModal();
191
- // }
192
- // });
193
- // }
194
-
195
- // private closeModal(): void {
196
- // if (this.modal) {
197
- // console.log('this.closeModal');
198
- // this.modal.remove();
199
- // this.modal = undefined;
200
- // }
201
- // }
202
359
  }