@notabene/javascript-sdk 1.32.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 (74) 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/CODEOWNERS +1 -1
  10. package/README.md +128 -70
  11. package/api-extractor.json +434 -0
  12. package/dist/notabene.cjs +1 -0
  13. package/dist/notabene.d.ts +678 -0
  14. package/dist/notabene.js +187 -0
  15. package/dist/tsdoc-metadata.json +11 -0
  16. package/eslint.config.js +24 -0
  17. package/etc/javascript-sdk.api.md +363 -0
  18. package/index.html +137 -0
  19. package/package.json +27 -53
  20. package/src/__tests__/notabene.test.ts +116 -0
  21. package/src/arbitraries.ts +13 -0
  22. package/src/components/EmbeddedComponent.ts +110 -0
  23. package/src/components/__tests__/EmbeddedComponent.test.ts +160 -0
  24. package/src/ivms/types.ts +2 -0
  25. package/src/notabene.ts +173 -279
  26. package/src/types.ts +381 -49
  27. package/src/utils/MessageEventManager.ts +55 -0
  28. package/src/utils/__tests__/MessageEventManager.test.ts +95 -0
  29. package/src/utils/arbitraries.ts +21 -0
  30. package/src/utils/caip.ts +16 -0
  31. package/src/utils/urls.ts +15 -0
  32. package/temp/javascript-sdk.api.json +3509 -0
  33. package/temp/javascript-sdk.api.md +363 -0
  34. package/ts-out/src/__tests__/notabene.test.d.ts +1 -0
  35. package/ts-out/src/__tests__/notabene.test.js +88 -0
  36. package/ts-out/src/arbitraries.d.ts +4 -0
  37. package/ts-out/src/arbitraries.js +8 -0
  38. package/ts-out/src/components/EmbeddedComponent.d.ts +25 -0
  39. package/ts-out/src/components/EmbeddedComponent.js +87 -0
  40. package/ts-out/src/components/__tests__/EmbeddedComponent.test.d.ts +1 -0
  41. package/ts-out/src/components/__tests__/EmbeddedComponent.test.js +132 -0
  42. package/ts-out/src/ivms/types.d.ts +252 -0
  43. package/ts-out/src/ivms/types.js +1 -0
  44. package/ts-out/src/notabene.d.ts +35 -0
  45. package/ts-out/src/notabene.js +59 -0
  46. package/ts-out/src/types.d.ts +357 -0
  47. package/ts-out/src/types.js +85 -0
  48. package/ts-out/src/utils/MessageEventManager.d.ts +12 -0
  49. package/ts-out/src/utils/MessageEventManager.js +45 -0
  50. package/ts-out/src/utils/__tests__/MessageEventManager.test.d.ts +1 -0
  51. package/ts-out/src/utils/__tests__/MessageEventManager.test.js +73 -0
  52. package/ts-out/src/utils/arbitraries.d.ts +6 -0
  53. package/ts-out/src/utils/arbitraries.js +7 -0
  54. package/ts-out/src/utils/caip.d.ts +13 -0
  55. package/ts-out/src/utils/caip.js +15 -0
  56. package/ts-out/src/utils/urls.d.ts +1 -0
  57. package/ts-out/src/utils/urls.js +14 -0
  58. package/ts-out/tsconfig.tsbuildinfo +1 -0
  59. package/tsconfig.json +15 -11
  60. package/tsconfig.tsbuildinfo +1 -0
  61. package/vite.config.js +13 -0
  62. package/.envrc.template +0 -1
  63. package/.eslintignore +0 -3
  64. package/.eslintrc.js +0 -13
  65. package/.nvmrc +0 -1
  66. package/.tool-versions +0 -3
  67. package/dist/es/index.js +0 -1
  68. package/dist/lib/index.js +0 -366
  69. package/jest.config.js +0 -5
  70. package/public/index.html +0 -93
  71. package/public/js/.gitkeep +0 -0
  72. package/src/lib/index.ts +0 -2
  73. package/src/module/index.ts +0 -10
  74. package/src/zoidComponentProps.ts +0 -81
package/src/notabene.ts CHANGED
@@ -1,308 +1,202 @@
1
- // @ts-ignore
2
- import { dom, node } from 'jsx-pragmatic';
3
- import {
4
- FieldsProps,
5
- NonCustodialDeclarationType,
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,
6
20
  Theme,
7
21
  Transaction,
8
- TransactionTypeAllowed,
9
- WidgetType,
10
- Fallback,
11
- OptInFeature,
22
+ TransactionAsset,
23
+ VASP,
24
+ Wallet,
25
+ Withdrawal,
12
26
  } from './types';
13
- // @ts-ignore
14
- import zoid, { destroy } from 'zoid';
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
- 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
+ );
141
135
  }
142
136
 
143
- private handleError(err: any): void {
144
- this.error = err;
145
- if (this.widget && this.popup) {
146
- this.widget.updateProps({
147
- error: err,
148
- });
149
- this.popup.updateProps({
150
- error: err,
151
- });
152
- }
153
- if (!err || !this.config.onError) return;
154
- 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);
155
143
  }
156
144
 
157
- private buildWidget(): zoid.ZoidComponent {
158
- if (!this.config.authToken) {
159
- console.error('Notabene: authToken is required');
160
- return;
161
- }
162
-
163
- const builtWidget = zoid.create({
164
- tag: 'widget',
165
- url: this.getWidgetUrl(),
166
- dimensions: {
167
- width: '100%',
168
- 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;
169
152
  },
170
- props: widgetProps,
171
- })({
172
- vaspDID: this.config.vaspDID,
173
- transaction: {},
174
- theme: this.config.theme,
175
- dictionary: this.config.dictionary,
176
- transactionTypeAllowed: this.config.transactionTypeAllowed,
177
- nonCustodialDeclarationType: this.config.nonCustodialDeclarationType,
178
- beneficiaryDetails: this.config.beneficiaryDetails,
179
- fieldsProps: this.config.fieldsProps,
180
- fallbacks: this.config.fallbacks,
181
- optInFeatures: this.config.optInFeatures,
182
- onRequireAdditionalInformation: () => {
183
- this.popup.updateProps({
184
- popupOpen: true,
185
- });
186
- this.popup.show();
187
- },
188
- onValidStateChange: (isValid: boolean) => {
189
- this.config.onValidStateChange(isValid);
190
- },
191
- error: this.error,
192
- onError: (err: any) => {
193
- this.handleError(err);
194
- console.debug('Notabene: Error handler called');
195
- },
196
- storeTransaction: (tx: Transaction) => {
197
- this.setTransaction(tx);
198
- },
199
- });
200
-
201
- builtWidget.event.on(zoid.EVENT.RENDERED, () => {
202
- this.widgetRendered = true;
203
- this.cleanUpDestroyedComponents();
204
- });
205
-
206
- return builtWidget;
153
+ {} as Record<string, string>,
154
+ );
207
155
  }
208
156
 
209
- private buildPopup(): zoid.ZoidComponent {
210
- if (!this.config.authToken) {
211
- console.error('Notabene: authToken is required');
212
- return;
213
- }
214
-
215
- const builtPopup = zoid.create({
216
- tag: 'popup',
217
- url: this.getAdditionalInfoUrl(),
218
- children: () => {
219
- return {
220
- Transaction: this.tx,
221
- };
222
- },
223
- dimensions: {
224
- width: '100%',
225
- height: '100%',
226
- },
227
- props: popupProps,
228
- containerTemplate: ({ uid, doc, frame, prerenderFrame }: any) => {
229
- return node(
230
- 'div',
231
- { id: uid, class: 'nb-container' },
232
- node(
233
- 'style',
234
- null,
235
- `
236
- #${uid}.container {
237
- border: 5px solid red;
238
- }
239
- .nb-overlay {
240
- position: fixed;
241
- width: 100vw;
242
- height: 100vh;
243
- top: 0;
244
- left: 0;
245
- display: flex;
246
- align-items: center;
247
- justify-content: center;
248
- background-color: rgba(0,0,0,0.5);
249
- }
250
- .nb-popup {
251
- width: 100%;
252
- height: 100%;
253
- }
254
- .nb-preloader {
255
- display: none;
256
- }
257
- `
258
- ),
259
- node(
260
- 'div',
261
- { class: 'nb-overlay' },
262
- node('node', { el: frame, class: 'nb-popup' }),
263
- node('node', { el: prerenderFrame, class: 'nb-preloader' })
264
- )
265
- ).render(dom({ doc }));
266
- },
267
- })({
268
- vaspDID: this.config.vaspDID,
269
- transaction: this.tx,
270
- beneficiaryDetails: this.config.beneficiaryDetails,
271
- fieldsProps: this.config.fieldsProps,
272
- storeTransaction: (tx: Transaction) => {
273
- this.setTransaction(tx);
274
- console.debug('Notabene: Transaction stored');
275
- },
276
- close: () => {
277
- this.popup.close();
278
- console.debug('Notabene: Popup closing');
279
- },
280
- setPopupOpen: (isOpen: boolean) => {
281
- this.popup.updateProps({
282
- popupOpen: isOpen,
283
- });
284
- },
285
- error: this.error,
286
- onError: (err: any) => {
287
- this.handleError(err);
288
- console.debug('Notabene: Error handler called');
289
- },
290
- popupOpen: false,
291
- theme: this.config.theme,
292
- dictionary: this.config.dictionary,
293
- transactionTypeAllowed: this.config.transactionTypeAllowed,
294
- nonCustodialDeclarationType: this.config.nonCustodialDeclarationType,
295
- fallbacks: this.config.fallbacks,
296
- optInFeatures: this.config.optInFeatures,
297
- });
298
-
299
- builtPopup.event.on(zoid.EVENT.RENDERED, () => {
300
- this.popupRendered = true;
301
- this.cleanUpDestroyedComponents();
302
- });
303
-
304
- return builtPopup;
305
- }
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
+ // }
306
202
  }
307
-
308
- if (window) window.Notabene = Notabene;