@notabene/javascript-sdk 1.34.0 → 2.0.0-next.10
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/README.md +113 -231
- package/dist/notabene.cjs +1 -0
- package/dist/notabene.d.ts +780 -0
- package/dist/notabene.js +173 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +38 -59
- package/src/__tests__/notabene.test.ts +159 -0
- package/src/arbitraries.ts +13 -0
- package/src/components/EmbeddedComponent.ts +185 -0
- package/src/components/__tests__/EmbeddedComponent.test.ts +160 -0
- package/src/ivms/types.ts +71 -28
- package/src/notabene.ts +155 -287
- package/src/types.ts +434 -67
- package/src/utils/MessageEventManager.ts +54 -0
- package/src/utils/__tests__/MessageEventManager.test.ts +95 -0
- package/src/utils/arbitraries.ts +26 -0
- package/src/utils/caip.ts +16 -0
- package/src/utils/urls.ts +15 -0
- package/.editorconfig +0 -10
- package/.envrc.template +0 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -13
- package/.gitlab-ci.yml +0 -74
- package/.husky/commit-msg +0 -4
- package/.husky/pre-commit +0 -4
- package/.husky/pre-push +0 -4
- package/.nvmrc +0 -1
- package/.prettierrc +0 -4
- package/.releaserc.json +0 -16
- package/.tool-versions +0 -3
- package/.vscode/extensions.json +0 -7
- package/.vscode/settings.json +0 -11
- package/CODEOWNERS +0 -1
- package/dist/es/index.js +0 -1
- package/dist/lib/index.js +0 -376
- package/jest.config.js +0 -5
- package/public/index.html +0 -93
- package/public/js/.gitkeep +0 -0
- package/src/lib/index.ts +0 -2
- package/src/module/index.ts +0 -10
- package/src/zoidComponentProps.ts +0 -81
- package/tsconfig.json +0 -18
package/src/notabene.ts
CHANGED
|
@@ -1,318 +1,186 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import EmbeddedComponent from './components/EmbeddedComponent';
|
|
2
|
+
import type {
|
|
3
|
+
Agent,
|
|
4
|
+
AgentType,
|
|
5
|
+
CallbackOptions,
|
|
6
|
+
ComponentMessage,
|
|
7
|
+
Counterparty,
|
|
8
|
+
DeclarationProof,
|
|
9
|
+
Deposit,
|
|
10
|
+
DepositRequest,
|
|
11
|
+
Destination,
|
|
12
|
+
HostMessage,
|
|
13
|
+
IVMS101,
|
|
14
|
+
MicroTransferProof,
|
|
15
|
+
OwnershipProof,
|
|
16
|
+
PersonType,
|
|
17
|
+
ProofStatus,
|
|
18
|
+
ProofTypes,
|
|
19
|
+
ScreenshotProof,
|
|
20
|
+
SignatureProof,
|
|
21
|
+
Status,
|
|
10
22
|
Theme,
|
|
11
23
|
Transaction,
|
|
12
|
-
|
|
13
|
-
|
|
24
|
+
TransactionAsset,
|
|
25
|
+
TransactionOptions,
|
|
26
|
+
VASP,
|
|
27
|
+
Wallet,
|
|
28
|
+
Withdrawal,
|
|
14
29
|
} from './types';
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
import { CMType, TransactionResponse } from './types';
|
|
31
|
+
import { encodeObjectToFragment } from './utils/urls';
|
|
32
|
+
|
|
33
|
+
export type {
|
|
34
|
+
CMType,
|
|
35
|
+
ComponentMessage,
|
|
36
|
+
EmbeddedComponent,
|
|
37
|
+
HostMessage,
|
|
38
|
+
Theme,
|
|
39
|
+
Counterparty,
|
|
40
|
+
Withdrawal,
|
|
41
|
+
Deposit,
|
|
42
|
+
Transaction,
|
|
43
|
+
DepositRequest,
|
|
44
|
+
TransactionResponse,
|
|
45
|
+
Destination as destination,
|
|
46
|
+
TransactionAsset,
|
|
47
|
+
SignatureProof,
|
|
48
|
+
ScreenshotProof,
|
|
49
|
+
MicroTransferProof,
|
|
50
|
+
DeclarationProof,
|
|
51
|
+
Notabene,
|
|
52
|
+
ProofStatus,
|
|
53
|
+
ProofTypes,
|
|
54
|
+
IVMS101,
|
|
55
|
+
PersonType,
|
|
56
|
+
Status,
|
|
57
|
+
VASP,
|
|
58
|
+
Wallet,
|
|
59
|
+
Agent,
|
|
60
|
+
AgentType,
|
|
61
|
+
OwnershipProof,
|
|
62
|
+
TransactionOptions,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Configuration for the Notabene SDK
|
|
67
|
+
*
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
export interface NotabeneConfig {
|
|
71
|
+
nodeUrl?: string;
|
|
72
|
+
authToken?: string;
|
|
73
|
+
uxUrl?: string;
|
|
24
74
|
theme?: Theme;
|
|
25
|
-
|
|
26
|
-
transactionTypeAllowed?: TransactionTypeAllowed;
|
|
27
|
-
nonCustodialDeclarationType?: NonCustodialDeclarationType;
|
|
28
|
-
beneficiaryDetails?: string[]; // @deprecated beneficiaryDetails - do not delete yet
|
|
29
|
-
fieldsProps?: FieldsProps;
|
|
30
|
-
fallbacks?: Fallback[];
|
|
31
|
-
optInFeatures?: OptInFeature[];
|
|
75
|
+
locale?: string;
|
|
32
76
|
}
|
|
33
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Primary constructor for Notabene UX elements
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
|
|
34
84
|
export default class Notabene {
|
|
35
|
-
private
|
|
36
|
-
private
|
|
37
|
-
private
|
|
38
|
-
private
|
|
39
|
-
private
|
|
40
|
-
private widgetRendered: boolean;
|
|
41
|
-
private popupRendered: boolean;
|
|
42
|
-
private shouldBeDestroyed: boolean;
|
|
85
|
+
private nodeUrl?: string;
|
|
86
|
+
private authToken?: string;
|
|
87
|
+
private uxUrl: string;
|
|
88
|
+
private theme?: Theme;
|
|
89
|
+
private locale?: string;
|
|
43
90
|
|
|
44
91
|
constructor(config: NotabeneConfig) {
|
|
45
|
-
this.
|
|
46
|
-
this.config.
|
|
47
|
-
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.shouldBeDestroyed = false;
|
|
51
|
-
this.popupRendered = false;
|
|
52
|
-
this.config.fallbacks = this.config.fallbacks || [
|
|
53
|
-
{ flow: 'WALLET_NOT_SUPPORTED', action: 'DECLARATION' },
|
|
54
|
-
];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Renders a new widget
|
|
59
|
-
* @param type - the type of widget to render
|
|
60
|
-
*/
|
|
61
|
-
public async renderWidget(
|
|
62
|
-
type: WidgetType = WidgetType.WITHDRAWAL
|
|
63
|
-
): Promise<void> {
|
|
64
|
-
this._renderWidget(type);
|
|
92
|
+
this.uxUrl = config.uxUrl || 'https://connect.notabene.id';
|
|
93
|
+
this.nodeUrl = config.nodeUrl;
|
|
94
|
+
this.authToken = config.authToken;
|
|
95
|
+
this.theme = config.theme;
|
|
96
|
+
this.locale = config.locale;
|
|
65
97
|
}
|
|
66
98
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this.widget.updateProps({
|
|
81
|
-
transaction: this.tx,
|
|
82
|
-
type,
|
|
83
|
-
});
|
|
84
|
-
this.popup.updateProps({
|
|
85
|
-
transaction: this.tx,
|
|
86
|
-
type,
|
|
99
|
+
public componentUrl(
|
|
100
|
+
path: string,
|
|
101
|
+
value: Partial<Transaction>,
|
|
102
|
+
configuration?: TransactionOptions,
|
|
103
|
+
callbacks?: CallbackOptions,
|
|
104
|
+
): string {
|
|
105
|
+
const url = new URL(this.uxUrl);
|
|
106
|
+
url.pathname = path;
|
|
107
|
+
|
|
108
|
+
const hash = encodeObjectToFragment({
|
|
109
|
+
authToken: this.authToken,
|
|
110
|
+
value,
|
|
111
|
+
configuration,
|
|
87
112
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
await this.renderPopup();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private async renderPopup(): Promise<void> {
|
|
94
|
-
if (!this.popup) return;
|
|
113
|
+
url.hash = hash;
|
|
114
|
+
if (this.nodeUrl) url.searchParams.set('nodeUrl', this.nodeUrl);
|
|
95
115
|
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
this.popupRendered = true;
|
|
116
|
+
if (this.theme) {
|
|
117
|
+
url.searchParams.set('theme', JSON.stringify(this.theme));
|
|
99
118
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
public async destroyWidget(): Promise<void> {
|
|
103
|
-
if (!this.widgetRendered || !this.popupRendered) {
|
|
104
|
-
this.shouldBeDestroyed = true;
|
|
105
|
-
return;
|
|
119
|
+
if (this.locale) {
|
|
120
|
+
url.searchParams.set('locale', this.locale);
|
|
106
121
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
public setTransaction(tx: Transaction) {
|
|
114
|
-
this.tx = tx;
|
|
115
|
-
if (this.widgetRendered) {
|
|
116
|
-
this.widget.updateProps({
|
|
117
|
-
transaction: tx,
|
|
118
|
-
});
|
|
119
|
-
this.popup.updateProps({
|
|
120
|
-
transaction: tx,
|
|
121
|
-
});
|
|
122
|
+
if (callbacks) {
|
|
123
|
+
if (callbacks.callback)
|
|
124
|
+
url.searchParams.set('callback_url', callbacks.callback);
|
|
125
|
+
if (callbacks.redirectUri)
|
|
126
|
+
url.searchParams.set('redirect_uri', callbacks.redirectUri);
|
|
122
127
|
}
|
|
128
|
+
return url.toString();
|
|
123
129
|
}
|
|
124
130
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
131
|
+
public createComponent(
|
|
132
|
+
path: string,
|
|
133
|
+
value: Partial<Transaction>,
|
|
134
|
+
options?: TransactionOptions,
|
|
135
|
+
callbacks?: CallbackOptions,
|
|
136
|
+
) {
|
|
137
|
+
return new EmbeddedComponent(
|
|
138
|
+
this.componentUrl(path, value, options, callbacks),
|
|
139
|
+
value,
|
|
140
|
+
);
|
|
128
141
|
}
|
|
129
142
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
143
|
+
public createWithdrawalAssist(
|
|
144
|
+
value: Partial<Withdrawal>,
|
|
145
|
+
options?: TransactionOptions,
|
|
146
|
+
callbacks?: CallbackOptions,
|
|
147
|
+
) {
|
|
148
|
+
return this.createComponent('withdrawal-assist', value, options, callbacks);
|
|
134
149
|
}
|
|
135
150
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return
|
|
151
|
+
public createDepositAssist(
|
|
152
|
+
value: Partial<Deposit>,
|
|
153
|
+
options?: any,
|
|
154
|
+
callbacks?: CallbackOptions,
|
|
155
|
+
) {
|
|
156
|
+
return this.createComponent('deposit-assist', value, options, callbacks);
|
|
142
157
|
}
|
|
143
158
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.popup.updateProps({
|
|
151
|
-
error: err,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
if (!err || !this.config.onError) return;
|
|
155
|
-
this.config.onError(err);
|
|
159
|
+
public createConnect(
|
|
160
|
+
value: Partial<Withdrawal>,
|
|
161
|
+
options?: TransactionOptions,
|
|
162
|
+
callbacks?: CallbackOptions,
|
|
163
|
+
) {
|
|
164
|
+
return this.createComponent('connect', value, options, callbacks);
|
|
156
165
|
}
|
|
157
166
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const builtWidget = zoid.create({
|
|
165
|
-
tag: 'widget',
|
|
166
|
-
url: this.getWidgetUrl(),
|
|
167
|
-
dimensions: {
|
|
168
|
-
width: '100%',
|
|
169
|
-
height: '280px',
|
|
170
|
-
},
|
|
171
|
-
attributes: {
|
|
172
|
-
iframe: {
|
|
173
|
-
allow: 'usb *;bluetooth *',
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
props: widgetProps,
|
|
177
|
-
})({
|
|
178
|
-
vaspDID: this.config.vaspDID,
|
|
179
|
-
transaction: {},
|
|
180
|
-
theme: this.config.theme,
|
|
181
|
-
dictionary: this.config.dictionary,
|
|
182
|
-
transactionTypeAllowed: this.config.transactionTypeAllowed,
|
|
183
|
-
nonCustodialDeclarationType: this.config.nonCustodialDeclarationType,
|
|
184
|
-
beneficiaryDetails: this.config.beneficiaryDetails,
|
|
185
|
-
fieldsProps: this.config.fieldsProps,
|
|
186
|
-
fallbacks: this.config.fallbacks,
|
|
187
|
-
optInFeatures: this.config.optInFeatures,
|
|
188
|
-
onRequireAdditionalInformation: () => {
|
|
189
|
-
this.popup.updateProps({
|
|
190
|
-
popupOpen: true,
|
|
191
|
-
});
|
|
192
|
-
this.popup.show();
|
|
193
|
-
},
|
|
194
|
-
onValidStateChange: (isValid: boolean) => {
|
|
195
|
-
this.config.onValidStateChange(isValid);
|
|
196
|
-
},
|
|
197
|
-
error: this.error,
|
|
198
|
-
onError: (err: any) => {
|
|
199
|
-
this.handleError(err);
|
|
200
|
-
console.debug('Notabene: Error handler called');
|
|
201
|
-
},
|
|
202
|
-
storeTransaction: (tx: Transaction) => {
|
|
203
|
-
this.setTransaction(tx);
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
builtWidget.event.on(zoid.EVENT.RENDERED, () => {
|
|
208
|
-
this.widgetRendered = true;
|
|
209
|
-
this.cleanUpDestroyedComponents();
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
return builtWidget;
|
|
167
|
+
public createDepositRequest(
|
|
168
|
+
value: Partial<DepositRequest>,
|
|
169
|
+
options?: TransactionOptions,
|
|
170
|
+
callbacks?: CallbackOptions,
|
|
171
|
+
) {
|
|
172
|
+
return this.createComponent('deposit-request', value, options, callbacks);
|
|
213
173
|
}
|
|
214
174
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
tag: 'popup',
|
|
223
|
-
url: this.getAdditionalInfoUrl(),
|
|
224
|
-
children: () => {
|
|
225
|
-
return {
|
|
226
|
-
Transaction: this.tx,
|
|
227
|
-
};
|
|
175
|
+
public decodeFragmentToObject(fragment: string): Record<string, string> {
|
|
176
|
+
const pairs = fragment.slice(1).split('&');
|
|
177
|
+
return pairs.reduce(
|
|
178
|
+
(obj, pair) => {
|
|
179
|
+
const [key, value] = pair.split('=');
|
|
180
|
+
obj[decodeURIComponent(key)] = decodeURIComponent(value);
|
|
181
|
+
return obj;
|
|
228
182
|
},
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
height: '100%',
|
|
232
|
-
},
|
|
233
|
-
attributes: {
|
|
234
|
-
iframe: {
|
|
235
|
-
allow: 'usb *;bluetooth *',
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
props: popupProps,
|
|
239
|
-
containerTemplate: ({ uid, doc, frame, prerenderFrame }: any) => {
|
|
240
|
-
return node(
|
|
241
|
-
'div',
|
|
242
|
-
{ id: uid, class: 'nb-container' },
|
|
243
|
-
node(
|
|
244
|
-
'style',
|
|
245
|
-
null,
|
|
246
|
-
`
|
|
247
|
-
#${uid}.container {
|
|
248
|
-
border: 5px solid red;
|
|
249
|
-
}
|
|
250
|
-
.nb-overlay {
|
|
251
|
-
position: fixed;
|
|
252
|
-
width: 100vw;
|
|
253
|
-
height: 100vh;
|
|
254
|
-
top: 0;
|
|
255
|
-
left: 0;
|
|
256
|
-
display: flex;
|
|
257
|
-
align-items: center;
|
|
258
|
-
justify-content: center;
|
|
259
|
-
background-color: rgba(0,0,0,0.5);
|
|
260
|
-
}
|
|
261
|
-
.nb-popup {
|
|
262
|
-
width: 100%;
|
|
263
|
-
height: 100%;
|
|
264
|
-
}
|
|
265
|
-
.nb-preloader {
|
|
266
|
-
display: none;
|
|
267
|
-
}
|
|
268
|
-
`
|
|
269
|
-
),
|
|
270
|
-
node(
|
|
271
|
-
'div',
|
|
272
|
-
{ class: 'nb-overlay' },
|
|
273
|
-
node('node', { el: frame, class: 'nb-popup' }),
|
|
274
|
-
node('node', { el: prerenderFrame, class: 'nb-preloader' })
|
|
275
|
-
)
|
|
276
|
-
).render(dom({ doc }));
|
|
277
|
-
},
|
|
278
|
-
})({
|
|
279
|
-
vaspDID: this.config.vaspDID,
|
|
280
|
-
transaction: this.tx,
|
|
281
|
-
beneficiaryDetails: this.config.beneficiaryDetails,
|
|
282
|
-
fieldsProps: this.config.fieldsProps,
|
|
283
|
-
storeTransaction: (tx: Transaction) => {
|
|
284
|
-
this.setTransaction(tx);
|
|
285
|
-
console.debug('Notabene: Transaction stored');
|
|
286
|
-
},
|
|
287
|
-
close: () => {
|
|
288
|
-
this.popup.close();
|
|
289
|
-
console.debug('Notabene: Popup closing');
|
|
290
|
-
},
|
|
291
|
-
setPopupOpen: (isOpen: boolean) => {
|
|
292
|
-
this.popup.updateProps({
|
|
293
|
-
popupOpen: isOpen,
|
|
294
|
-
});
|
|
295
|
-
},
|
|
296
|
-
error: this.error,
|
|
297
|
-
onError: (err: any) => {
|
|
298
|
-
this.handleError(err);
|
|
299
|
-
console.debug('Notabene: Error handler called');
|
|
300
|
-
},
|
|
301
|
-
popupOpen: false,
|
|
302
|
-
theme: this.config.theme,
|
|
303
|
-
dictionary: this.config.dictionary,
|
|
304
|
-
transactionTypeAllowed: this.config.transactionTypeAllowed,
|
|
305
|
-
nonCustodialDeclarationType: this.config.nonCustodialDeclarationType,
|
|
306
|
-
fallbacks: this.config.fallbacks,
|
|
307
|
-
optInFeatures: this.config.optInFeatures,
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
builtPopup.event.on(zoid.EVENT.RENDERED, () => {
|
|
311
|
-
this.popupRendered = true;
|
|
312
|
-
this.cleanUpDestroyedComponents();
|
|
313
|
-
});
|
|
314
|
-
return builtPopup;
|
|
183
|
+
{} as Record<string, string>,
|
|
184
|
+
);
|
|
315
185
|
}
|
|
316
186
|
}
|
|
317
|
-
|
|
318
|
-
if (window) window.Notabene = Notabene;
|