@notabene/javascript-sdk 2.0.0-next.9 → 2.0.1
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.
- package/LICENSE.md +21 -0
- package/README.md +477 -111
- package/dist/js/notabene.js +1 -0
- package/dist/notabene.cjs +1 -1
- package/dist/notabene.js +286 -110
- package/package.json +34 -25
- package/src/__tests__/notabene.test.ts +113 -2
- package/src/arbitraries.ts +0 -13
- package/src/components/EmbeddedComponent.ts +125 -63
- package/src/components/__tests__/EmbeddedComponent.test.ts +402 -32
- package/src/ivms/types.ts +177 -140
- package/src/locales.ts +48 -0
- package/src/notabene.ts +199 -63
- package/src/types.ts +773 -150
- package/src/utils/MessageEventManager.ts +70 -9
- package/src/utils/__tests__/MessageEventManager.test.ts +29 -5
- package/src/utils/__tests__/urls.test.ts +112 -0
- package/src/utils/arbitraries.ts +219 -1
- package/src/utils/urls.ts +30 -5
- package/dist/notabene.d.ts +0 -780
- package/dist/tsdoc-metadata.json +0 -11
package/src/notabene.ts
CHANGED
|
@@ -1,65 +1,133 @@
|
|
|
1
1
|
import EmbeddedComponent from './components/EmbeddedComponent';
|
|
2
2
|
import type {
|
|
3
3
|
Agent,
|
|
4
|
-
|
|
4
|
+
BlockchainAddress,
|
|
5
|
+
CAIP10,
|
|
6
|
+
CAIP19,
|
|
7
|
+
CAIP2,
|
|
5
8
|
CallbackOptions,
|
|
9
|
+
Cancel,
|
|
10
|
+
Completed,
|
|
6
11
|
ComponentMessage,
|
|
12
|
+
ComponentResponse,
|
|
13
|
+
ConnectionOptions,
|
|
14
|
+
ConnectionRequest,
|
|
7
15
|
Counterparty,
|
|
16
|
+
CryptoCredential,
|
|
8
17
|
DeclarationProof,
|
|
9
18
|
Deposit,
|
|
10
19
|
DepositRequest,
|
|
20
|
+
DepositRequestOptions,
|
|
11
21
|
Destination,
|
|
22
|
+
DID,
|
|
23
|
+
DTI,
|
|
24
|
+
Error,
|
|
25
|
+
FieldTypes,
|
|
12
26
|
HostMessage,
|
|
27
|
+
InvalidValue,
|
|
13
28
|
IVMS101,
|
|
29
|
+
LegalPerson,
|
|
30
|
+
LEI,
|
|
14
31
|
MicroTransferProof,
|
|
32
|
+
NationalIdentification,
|
|
33
|
+
NaturalPerson,
|
|
34
|
+
NotabeneAsset,
|
|
15
35
|
OwnershipProof,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
ProofTypes,
|
|
36
|
+
Ready,
|
|
37
|
+
ResizeRequest,
|
|
19
38
|
ScreenshotProof,
|
|
20
39
|
SignatureProof,
|
|
21
|
-
Status,
|
|
22
40
|
Theme,
|
|
41
|
+
ThresholdOptions,
|
|
23
42
|
Transaction,
|
|
24
43
|
TransactionAsset,
|
|
25
44
|
TransactionOptions,
|
|
45
|
+
TransactionResponse,
|
|
46
|
+
TravelAddress,
|
|
47
|
+
UpdateValue,
|
|
48
|
+
V1Transaction,
|
|
49
|
+
ValidationError,
|
|
26
50
|
VASP,
|
|
51
|
+
VASPOptions,
|
|
27
52
|
Wallet,
|
|
28
53
|
Withdrawal,
|
|
29
54
|
} from './types';
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
export type {
|
|
55
|
+
import {
|
|
56
|
+
AgentType,
|
|
34
57
|
CMType,
|
|
58
|
+
HMType,
|
|
59
|
+
PersonType,
|
|
60
|
+
ProofStatus,
|
|
61
|
+
ProofTypes,
|
|
62
|
+
Status,
|
|
63
|
+
ValidationSections,
|
|
64
|
+
} from './types';
|
|
65
|
+
import { type MessageCallback } from './utils/MessageEventManager';
|
|
66
|
+
import { decodeFragmentToObject, encodeObjectToFragment } from './utils/urls';
|
|
67
|
+
// Must be exported for React Native SDK to use
|
|
68
|
+
export { default as EmbeddedComponent } from './components/EmbeddedComponent';
|
|
69
|
+
export type {
|
|
70
|
+
Agent,
|
|
71
|
+
BlockchainAddress,
|
|
72
|
+
CAIP2,
|
|
73
|
+
CAIP10,
|
|
74
|
+
CAIP19,
|
|
75
|
+
CryptoCredential,
|
|
76
|
+
TravelAddress,
|
|
77
|
+
NotabeneAsset,
|
|
78
|
+
DTI,
|
|
79
|
+
VASPOptions,
|
|
80
|
+
NationalIdentification,
|
|
81
|
+
FieldTypes,
|
|
82
|
+
DID,
|
|
83
|
+
MessageCallback,
|
|
84
|
+
CallbackOptions,
|
|
85
|
+
Cancel,
|
|
86
|
+
Completed,
|
|
35
87
|
ComponentMessage,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Theme,
|
|
88
|
+
ComponentResponse,
|
|
89
|
+
ConnectionRequest,
|
|
39
90
|
Counterparty,
|
|
40
|
-
|
|
91
|
+
DeclarationProof,
|
|
41
92
|
Deposit,
|
|
42
|
-
Transaction,
|
|
43
93
|
DepositRequest,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
94
|
+
Destination,
|
|
95
|
+
Error,
|
|
96
|
+
HostMessage,
|
|
97
|
+
InvalidValue,
|
|
98
|
+
IVMS101,
|
|
99
|
+
LegalPerson,
|
|
100
|
+
LEI,
|
|
49
101
|
MicroTransferProof,
|
|
50
|
-
|
|
51
|
-
|
|
102
|
+
NaturalPerson,
|
|
103
|
+
OwnershipProof,
|
|
104
|
+
Ready,
|
|
105
|
+
ResizeRequest,
|
|
106
|
+
ScreenshotProof,
|
|
107
|
+
SignatureProof,
|
|
108
|
+
Theme,
|
|
109
|
+
ThresholdOptions,
|
|
110
|
+
Transaction,
|
|
111
|
+
TransactionAsset,
|
|
112
|
+
TransactionOptions,
|
|
113
|
+
TransactionResponse,
|
|
114
|
+
UpdateValue,
|
|
115
|
+
V1Transaction,
|
|
116
|
+
ValidationError,
|
|
117
|
+
VASP,
|
|
118
|
+
Wallet,
|
|
119
|
+
Withdrawal,
|
|
120
|
+
};
|
|
121
|
+
export {
|
|
122
|
+
CMType,
|
|
123
|
+
HMType,
|
|
52
124
|
ProofStatus,
|
|
53
125
|
ProofTypes,
|
|
54
|
-
IVMS101,
|
|
55
126
|
PersonType,
|
|
56
127
|
Status,
|
|
57
|
-
VASP,
|
|
58
|
-
Wallet,
|
|
59
|
-
Agent,
|
|
60
128
|
AgentType,
|
|
61
|
-
|
|
62
|
-
|
|
129
|
+
ValidationSections,
|
|
130
|
+
decodeFragmentToObject,
|
|
63
131
|
};
|
|
64
132
|
|
|
65
133
|
/**
|
|
@@ -68,19 +136,40 @@ export type {
|
|
|
68
136
|
* @public
|
|
69
137
|
*/
|
|
70
138
|
export interface NotabeneConfig {
|
|
139
|
+
/**
|
|
140
|
+
* The URL of the Notabene API node
|
|
141
|
+
*/
|
|
71
142
|
nodeUrl?: string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The authentication token for the Notabene API
|
|
146
|
+
*/
|
|
72
147
|
authToken?: string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The URL of the Notabene UX components
|
|
151
|
+
*/
|
|
73
152
|
uxUrl?: string;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Custom theme configuration for the UX components
|
|
156
|
+
*/
|
|
74
157
|
theme?: Theme;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The locale to use for the UX components
|
|
161
|
+
*/
|
|
75
162
|
locale?: string;
|
|
76
163
|
}
|
|
77
|
-
|
|
78
164
|
/**
|
|
79
165
|
* Primary constructor for Notabene UX elements
|
|
80
166
|
*
|
|
167
|
+
* This class provides methods to create and manage various Notabene components
|
|
168
|
+
* such as withdrawal assist, deposit assist, connect, and deposit request.
|
|
169
|
+
* It also handles URL generation and fragment decoding for these components.
|
|
170
|
+
*
|
|
81
171
|
* @public
|
|
82
172
|
*/
|
|
83
|
-
|
|
84
173
|
export default class Notabene {
|
|
85
174
|
private nodeUrl?: string;
|
|
86
175
|
private authToken?: string;
|
|
@@ -88,6 +177,11 @@ export default class Notabene {
|
|
|
88
177
|
private theme?: Theme;
|
|
89
178
|
private locale?: string;
|
|
90
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Creates a new instance of the Notabene SDK
|
|
182
|
+
*
|
|
183
|
+
* @param config - Configuration options for the Notabene SDK
|
|
184
|
+
*/
|
|
91
185
|
constructor(config: NotabeneConfig) {
|
|
92
186
|
this.uxUrl = config.uxUrl || 'https://connect.notabene.id';
|
|
93
187
|
this.nodeUrl = config.nodeUrl;
|
|
@@ -96,10 +190,20 @@ export default class Notabene {
|
|
|
96
190
|
this.locale = config.locale;
|
|
97
191
|
}
|
|
98
192
|
|
|
99
|
-
|
|
193
|
+
/**
|
|
194
|
+
* Generates a URL for a Notabene component
|
|
195
|
+
*
|
|
196
|
+
* @param path - The path of the component
|
|
197
|
+
* @param value - Transaction data
|
|
198
|
+
* @param configuration - Optional transaction configuration
|
|
199
|
+
* @param callbacks - Optional callback configuration
|
|
200
|
+
* @returns component URL
|
|
201
|
+
* @internal
|
|
202
|
+
*/
|
|
203
|
+
componentUrl<V, O>(
|
|
100
204
|
path: string,
|
|
101
|
-
value:
|
|
102
|
-
configuration?:
|
|
205
|
+
value: V,
|
|
206
|
+
configuration?: O,
|
|
103
207
|
callbacks?: CallbackOptions,
|
|
104
208
|
): string {
|
|
105
209
|
const url = new URL(this.uxUrl);
|
|
@@ -128,59 +232,91 @@ export default class Notabene {
|
|
|
128
232
|
return url.toString();
|
|
129
233
|
}
|
|
130
234
|
|
|
131
|
-
|
|
235
|
+
/**
|
|
236
|
+
* Creates a new embedded component
|
|
237
|
+
*
|
|
238
|
+
* @param path - The path of the component
|
|
239
|
+
* @param value - Transaction data
|
|
240
|
+
* @param options - Optional transaction options
|
|
241
|
+
* @param callbacks - Optional callback configuration
|
|
242
|
+
* @returns A new EmbeddedComponent instance
|
|
243
|
+
* @internal
|
|
244
|
+
*/
|
|
245
|
+
createComponent<V, O>(
|
|
132
246
|
path: string,
|
|
133
|
-
value: Partial<
|
|
134
|
-
options?:
|
|
247
|
+
value: Partial<V>,
|
|
248
|
+
options?: O,
|
|
135
249
|
callbacks?: CallbackOptions,
|
|
136
250
|
) {
|
|
137
|
-
return new EmbeddedComponent(
|
|
251
|
+
return new EmbeddedComponent<V, O>(
|
|
138
252
|
this.componentUrl(path, value, options, callbacks),
|
|
139
253
|
value,
|
|
254
|
+
options,
|
|
140
255
|
);
|
|
141
256
|
}
|
|
142
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Creates a withdrawal assist component
|
|
260
|
+
*
|
|
261
|
+
* @param value - Withdrawal transaction data
|
|
262
|
+
* @param options - Optional transaction options
|
|
263
|
+
* @param callbacks - Optional callback configuration
|
|
264
|
+
* @returns A new EmbeddedComponent instance for withdrawal assistance
|
|
265
|
+
*/
|
|
143
266
|
public createWithdrawalAssist(
|
|
144
267
|
value: Partial<Withdrawal>,
|
|
145
268
|
options?: TransactionOptions,
|
|
146
269
|
callbacks?: CallbackOptions,
|
|
147
270
|
) {
|
|
148
|
-
return this.createComponent
|
|
271
|
+
return this.createComponent<Withdrawal, TransactionOptions>(
|
|
272
|
+
'withdrawal-assist',
|
|
273
|
+
value,
|
|
274
|
+
options,
|
|
275
|
+
callbacks,
|
|
276
|
+
);
|
|
149
277
|
}
|
|
150
278
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
279
|
+
/**
|
|
280
|
+
* Creates a connect component
|
|
281
|
+
*
|
|
282
|
+
* @param value - Connection request data
|
|
283
|
+
* @param options - Optional transaction options
|
|
284
|
+
* @param callbacks - Optional callback configuration
|
|
285
|
+
* @returns A new EmbeddedComponent instance for connection
|
|
286
|
+
* @alpha
|
|
287
|
+
*/
|
|
288
|
+
public createConnectWallet(
|
|
289
|
+
value: ConnectionRequest,
|
|
290
|
+
options?: ConnectionOptions,
|
|
154
291
|
callbacks?: CallbackOptions,
|
|
155
292
|
) {
|
|
156
|
-
return this.createComponent
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
callbacks?: CallbackOptions,
|
|
163
|
-
) {
|
|
164
|
-
return this.createComponent('connect', value, options, callbacks);
|
|
293
|
+
return this.createComponent<ConnectionRequest, ConnectionOptions>(
|
|
294
|
+
'connect',
|
|
295
|
+
value,
|
|
296
|
+
options,
|
|
297
|
+
callbacks,
|
|
298
|
+
);
|
|
165
299
|
}
|
|
166
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Creates a deposit request component
|
|
303
|
+
*
|
|
304
|
+
* @param value - Deposit request data
|
|
305
|
+
* @param options - Optional transaction options
|
|
306
|
+
* @param callbacks - Optional callback configuration
|
|
307
|
+
* @returns A new EmbeddedComponent instance for deposit requests
|
|
308
|
+
* @public
|
|
309
|
+
*/
|
|
167
310
|
public createDepositRequest(
|
|
168
|
-
value:
|
|
169
|
-
options?:
|
|
311
|
+
value: DepositRequest,
|
|
312
|
+
options?: DepositRequestOptions,
|
|
170
313
|
callbacks?: CallbackOptions,
|
|
171
314
|
) {
|
|
172
|
-
return this.createComponent
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return pairs.reduce(
|
|
178
|
-
(obj, pair) => {
|
|
179
|
-
const [key, value] = pair.split('=');
|
|
180
|
-
obj[decodeURIComponent(key)] = decodeURIComponent(value);
|
|
181
|
-
return obj;
|
|
182
|
-
},
|
|
183
|
-
{} as Record<string, string>,
|
|
315
|
+
return this.createComponent<DepositRequest, DepositRequestOptions>(
|
|
316
|
+
'deposit-request',
|
|
317
|
+
value,
|
|
318
|
+
options,
|
|
319
|
+
callbacks,
|
|
184
320
|
);
|
|
185
321
|
}
|
|
186
322
|
}
|