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

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 +137 -0
  18. package/package.json +27 -53
  19. package/src/__tests__/notabene.test.ts +116 -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 +173 -289
  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 +88 -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 +59 -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/src/notabene.ts CHANGED
@@ -1,318 +1,202 @@
1
- // @ts-ignore
2
- import { dom, node } from 'jsx-pragmatic';
3
- // @ts-ignore
4
- import zoid, { destroy } from 'zoid';
5
- import {
6
- Fallback,
7
- FieldsProps,
8
- NonCustodialDeclarationType,
9
- OptInFeature,
1
+ import EmbeddedComponent from './components/EmbeddedComponent';
2
+ import type {
3
+ Agent,
4
+ AgentType,
5
+ CallbackOptions,
6
+ ComponentMessage,
7
+ Counterparty,
8
+ DeclarationProof,
9
+ Destination,
10
+ HostMessage,
11
+ IVMS101,
12
+ MicroTransferProof,
13
+ OwnershipProof,
14
+ PersonType,
15
+ ProofStatus,
16
+ ProofTypes,
17
+ ScreenshotProof,
18
+ SignatureProof,
19
+ Status,
10
20
  Theme,
11
21
  Transaction,
12
- TransactionTypeAllowed,
13
- WidgetType,
22
+ TransactionAsset,
23
+ VASP,
24
+ Wallet,
25
+ Withdrawal,
14
26
  } from './types';
15
- import { popupProps, widgetProps } from './zoidComponentProps';
16
-
17
- interface NotabeneConfig {
18
- widget: string;
19
- container: string;
27
+ import { CMType, TransactionResponse } from './types';
28
+ import { encodeObjectToFragment } from './utils/urls';
29
+
30
+ export type {
31
+ CMType,
32
+ ComponentMessage,
33
+ EmbeddedComponent,
34
+ HostMessage,
35
+ Theme,
36
+ Counterparty,
37
+ Withdrawal,
38
+ Transaction,
39
+ TransactionResponse,
40
+ Destination as destination,
41
+ TransactionAsset,
42
+ SignatureProof,
43
+ ScreenshotProof,
44
+ MicroTransferProof,
45
+ DeclarationProof,
46
+ Notabene,
47
+ ProofStatus,
48
+ ProofTypes,
49
+ IVMS101,
50
+ PersonType,
51
+ Status,
52
+ VASP,
53
+ Wallet,
54
+ Agent,
55
+ AgentType,
56
+ OwnershipProof,
57
+ };
58
+
59
+ /**
60
+ * Configuration for the Notabene SDK
61
+ *
62
+ * @public
63
+ */
64
+ export interface NotabeneConfig {
65
+ nodeUrl: string;
20
66
  authToken: string;
21
- vaspDID: string;
22
- onValidStateChange(isValid: boolean): void;
23
- onError(err: any): void;
67
+ uxUrl?: string;
24
68
  theme?: Theme;
25
69
  dictionary?: { [key: string]: string };
26
- transactionTypeAllowed?: TransactionTypeAllowed;
27
- nonCustodialDeclarationType?: NonCustodialDeclarationType;
28
- beneficiaryDetails?: string[]; // @deprecated beneficiaryDetails - do not delete yet
29
- fieldsProps?: FieldsProps;
30
- fallbacks?: Fallback[];
31
- optInFeatures?: OptInFeature[];
32
70
  }
33
71
 
72
+ /**
73
+ * Primary constructor for Notabene UX elements
74
+ *
75
+ * @public
76
+ */
77
+
34
78
  export default class Notabene {
35
- private widget: zoid.ZoidComponent;
36
- private popup: zoid.ZoidComponent;
37
- private config: NotabeneConfig;
38
- private tx: Transaction | undefined;
39
- private error?: Error;
40
- private widgetRendered: boolean;
41
- private popupRendered: boolean;
42
- private shouldBeDestroyed: boolean;
79
+ private nodeUrl: string;
80
+ private authToken: string;
81
+ private uxUrl: string;
82
+ private theme?: Theme;
83
+ private dictionary?: { [key: string]: string };
43
84
 
44
85
  constructor(config: NotabeneConfig) {
45
- this.config = config;
46
- this.config.nonCustodialDeclarationType =
47
- config.nonCustodialDeclarationType || 'SIGNATURE';
48
- this.config.transactionTypeAllowed = config.transactionTypeAllowed || 'ALL';
49
- this.widgetRendered = false;
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);
86
+ this.uxUrl = config.uxUrl || 'https://ux.notabene.id';
87
+ this.nodeUrl = config.nodeUrl;
88
+ this.authToken = config.authToken;
89
+ this.theme = config.theme;
90
+ this.dictionary = config.dictionary;
65
91
  }
66
92
 
67
- private async _renderWidget(type: WidgetType): Promise<void> {
68
- if (this.widgetRendered) {
69
- console.error(
70
- 'Notabene: Widget already rendered, please destroy it first'
71
- );
72
- this.config.onError(
73
- new Error('Widget already rendered, please destroy it first')
74
- );
75
- return;
76
- }
77
-
78
- this.widget = await this.buildWidget();
79
- this.popup = await this.buildPopup();
80
- this.widget.updateProps({
81
- transaction: this.tx,
82
- type,
83
- });
84
- this.popup.updateProps({
85
- transaction: this.tx,
86
- type,
93
+ public componentUrl(
94
+ path: string,
95
+ value: Partial<Transaction>,
96
+ configuration?: any,
97
+ callbacks?: CallbackOptions,
98
+ ): string {
99
+ const url = new URL(this.uxUrl);
100
+ url.pathname = path;
101
+
102
+ const hash = encodeObjectToFragment({
103
+ authToken: this.authToken,
104
+ value,
105
+ configuration,
87
106
  });
88
- this.popup.hide();
89
- await this.widget.render(this.config.container);
90
- await this.renderPopup();
91
- }
92
-
93
- private async renderPopup(): Promise<void> {
94
- if (!this.popup) return;
107
+ url.hash = hash;
108
+ url.searchParams.set('nodeUrl', this.nodeUrl);
95
109
 
96
- if (!this.popupRendered) {
97
- await this.popup.render(this.config.container);
98
- this.popupRendered = true;
110
+ if (this.theme) {
111
+ url.searchParams.set('theme', JSON.stringify(this.theme));
99
112
  }
100
- }
101
-
102
- public async destroyWidget(): Promise<void> {
103
- if (!this.widgetRendered || !this.popupRendered) {
104
- this.shouldBeDestroyed = true;
105
- return;
113
+ if (this.dictionary) {
114
+ url.searchParams.set('dictionary', JSON.stringify(this.dictionary));
106
115
  }
107
- await destroy();
108
- this.shouldBeDestroyed = false;
109
- this.widgetRendered = false;
110
- this.popupRendered = false;
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
- });
116
+ if (callbacks) {
117
+ if (callbacks.callback)
118
+ url.searchParams.set('callback_url', callbacks.callback);
119
+ if (callbacks.redirectUri)
120
+ url.searchParams.set('redirect_uri', callbacks.redirectUri);
122
121
  }
123
- }
124
-
125
- private cleanUpDestroyedComponents() {
126
- if (!this.shouldBeDestroyed) return;
127
- this.destroyWidget();
128
- }
129
-
130
- private getWidgetUrl(): string {
131
- const url = new URL(this.config.widget);
132
- url.hash = `authToken=${this.config.authToken}`;
133
122
  return url.toString();
134
123
  }
135
124
 
136
- private getAdditionalInfoUrl(): string {
137
- const url = new URL(this.config.widget);
138
- url.search = 'popup=true';
139
- url.hash = `authToken=${this.config.authToken}`;
140
-
141
- return url.toString();
125
+ public createComponent(
126
+ path: string,
127
+ value: Partial<Transaction>,
128
+ options?: any,
129
+ callbacks?: CallbackOptions,
130
+ ) {
131
+ return new EmbeddedComponent(
132
+ this.componentUrl(path, value, options, callbacks),
133
+ value,
134
+ );
142
135
  }
143
136
 
144
- private handleError(err: any): void {
145
- this.error = err;
146
- if (this.widget && this.popup) {
147
- this.widget.updateProps({
148
- error: err,
149
- });
150
- this.popup.updateProps({
151
- error: err,
152
- });
153
- }
154
- if (!err || !this.config.onError) return;
155
- this.config.onError(err);
137
+ public createWithdrawalAssist(
138
+ value: Partial<Withdrawal>,
139
+ options?: any,
140
+ callbacks?: CallbackOptions,
141
+ ) {
142
+ return this.createComponent('withdrawal-assist', value, options, callbacks);
156
143
  }
157
144
 
158
- private buildWidget(): zoid.ZoidComponent {
159
- if (!this.config.authToken) {
160
- console.error('Notabene: authToken is required');
161
- return;
162
- }
163
-
164
- const builtWidget = zoid.create({
165
- tag: 'widget',
166
- url: this.getWidgetUrl(),
167
- dimensions: {
168
- width: '100%',
169
- height: '280px',
145
+ public decodeFragmentToObject(fragment: string): Record<string, string> {
146
+ const pairs = fragment.slice(1).split('&');
147
+ return pairs.reduce(
148
+ (obj, pair) => {
149
+ const [key, value] = pair.split('=');
150
+ obj[decodeURIComponent(key)] = decodeURIComponent(value);
151
+ return obj;
170
152
  },
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;
153
+ {} as Record<string, string>,
154
+ );
213
155
  }
214
156
 
215
- private buildPopup(): zoid.ZoidComponent {
216
- if (!this.config.authToken) {
217
- console.error('Notabene: authToken is required');
218
- return;
219
- }
220
-
221
- const builtPopup = zoid.create({
222
- tag: 'popup',
223
- url: this.getAdditionalInfoUrl(),
224
- children: () => {
225
- return {
226
- Transaction: this.tx,
227
- };
228
- },
229
- dimensions: {
230
- width: '100%',
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;
315
- }
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
+ // }
316
202
  }
317
-
318
- if (window) window.Notabene = Notabene;