@notabene/javascript-sdk 1.32.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 +114 -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 -277
- package/src/types.ts +435 -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 -366
- 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
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
|
|
2
|
+
import { CMType, HMType, HostMessage, Transaction } from '../../types';
|
|
3
|
+
import EmbeddedComponent from '../EmbeddedComponent';
|
|
4
|
+
|
|
5
|
+
const url = 'https://example.com';
|
|
6
|
+
const parentId = 'parent-container';
|
|
7
|
+
const value: Partial<Transaction> = { amountDecimal: 100 };
|
|
8
|
+
|
|
9
|
+
describe('EmbeddedComponent', () => {
|
|
10
|
+
describe('creation', () => {
|
|
11
|
+
let component: EmbeddedComponent;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
component = new EmbeddedComponent(url, { amountDecimal: 100 });
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('sets value', () => {
|
|
17
|
+
expect(component.value).toStrictEqual(value);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('sets url', () => {
|
|
21
|
+
expect(component.url).toBe(url);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('iframe', () => {
|
|
26
|
+
let document: Document;
|
|
27
|
+
let parentElement: HTMLElement;
|
|
28
|
+
let iframe: HTMLIFrameElement;
|
|
29
|
+
let window: Window;
|
|
30
|
+
let iframeWindow: Window;
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
parentElement = {
|
|
34
|
+
appendChild: vi.fn(),
|
|
35
|
+
} as unknown as HTMLElement;
|
|
36
|
+
|
|
37
|
+
iframe = {
|
|
38
|
+
style: {},
|
|
39
|
+
src: '',
|
|
40
|
+
contentWindow: iframeWindow,
|
|
41
|
+
setAttribute: vi.fn(),
|
|
42
|
+
addEventListener: vi.fn(),
|
|
43
|
+
} as unknown as HTMLIFrameElement;
|
|
44
|
+
|
|
45
|
+
document = {
|
|
46
|
+
createElement: vi.fn().mockReturnValue(iframe),
|
|
47
|
+
querySelector: vi.fn().mockReturnValue(parentElement),
|
|
48
|
+
} as unknown as Document;
|
|
49
|
+
|
|
50
|
+
window = {
|
|
51
|
+
addEventListener: vi.fn(),
|
|
52
|
+
} as unknown as Window;
|
|
53
|
+
|
|
54
|
+
vi.stubGlobal('document', document);
|
|
55
|
+
vi.stubGlobal('window', window);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
vi.unstubAllGlobals();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('mount', () => {
|
|
63
|
+
const component = new EmbeddedComponent(url, value);
|
|
64
|
+
component.mount(parentId);
|
|
65
|
+
expect(iframe?.src).toBe(url);
|
|
66
|
+
expect(parentElement.appendChild).toHaveBeenCalledWith(iframe);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('on', () => {
|
|
70
|
+
const component = new EmbeddedComponent(url, value);
|
|
71
|
+
const messageType = 'customEvent';
|
|
72
|
+
const callback = vi.fn();
|
|
73
|
+
component.on(messageType, callback);
|
|
74
|
+
component.mount(parentId);
|
|
75
|
+
|
|
76
|
+
// Simulate receiving a message of the specified type
|
|
77
|
+
// and assert that the callback is called with the correct payload.
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('off', () => {
|
|
81
|
+
const component = new EmbeddedComponent(url, value);
|
|
82
|
+
const messageType = 'customEvent';
|
|
83
|
+
const callback = vi.fn();
|
|
84
|
+
component.on(messageType, callback);
|
|
85
|
+
|
|
86
|
+
// Simulate receiving a message of the specified type
|
|
87
|
+
// and assert that the callback is called with the correct payload.
|
|
88
|
+
|
|
89
|
+
component.off(messageType, callback);
|
|
90
|
+
|
|
91
|
+
// Simulate receiving another message of the specified type
|
|
92
|
+
// and assert that the callback is not called.
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('connected to iframe', () => {
|
|
96
|
+
let messageHandler: (event: MessageEvent) => void;
|
|
97
|
+
let port: MessagePort;
|
|
98
|
+
let handshake: MessageEvent;
|
|
99
|
+
let component: EmbeddedComponent;
|
|
100
|
+
|
|
101
|
+
beforeEach(() => {
|
|
102
|
+
port = {
|
|
103
|
+
postMessage: vi.fn(),
|
|
104
|
+
start: vi.fn(),
|
|
105
|
+
onmessage: null,
|
|
106
|
+
} as unknown as MessagePort;
|
|
107
|
+
handshake = {
|
|
108
|
+
source: iframe.contentWindow,
|
|
109
|
+
ports: [port],
|
|
110
|
+
} as unknown as MessageEvent;
|
|
111
|
+
window.addEventListener = vi
|
|
112
|
+
.fn()
|
|
113
|
+
.mockImplementation((event, handler) => {
|
|
114
|
+
messageHandler = handler;
|
|
115
|
+
});
|
|
116
|
+
component = new EmbeddedComponent(url, value);
|
|
117
|
+
component.mount(parentId);
|
|
118
|
+
|
|
119
|
+
expect(messageHandler).toBeDefined();
|
|
120
|
+
messageHandler(handshake);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('send', () => {
|
|
124
|
+
const message: HostMessage = {
|
|
125
|
+
type: HMType.UPDATE,
|
|
126
|
+
value: { amountDecimal: 100 },
|
|
127
|
+
};
|
|
128
|
+
component.send(message);
|
|
129
|
+
|
|
130
|
+
// Assert that the message is sent to the embedded component
|
|
131
|
+
// and handled correctly.
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('update', () => {
|
|
135
|
+
const newValue: Partial<Transaction> = { amountDecimal: 200 };
|
|
136
|
+
component.update(newValue);
|
|
137
|
+
|
|
138
|
+
expect(component.value).toBe(newValue);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// TODO not sure this actually does what I want it to do
|
|
142
|
+
test('completion', async () => {
|
|
143
|
+
const response = { valid: true, value: 'completed' };
|
|
144
|
+
expect(port.onmessage).toBeDefined();
|
|
145
|
+
|
|
146
|
+
const promise = component.completion();
|
|
147
|
+
// @ts-expect-error - we've already verified that port exists
|
|
148
|
+
port.onmessage({
|
|
149
|
+
data: { type: CMType.COMPLETE, response },
|
|
150
|
+
} as MessageEvent);
|
|
151
|
+
|
|
152
|
+
promise.then((result) => {
|
|
153
|
+
expect(result).toBe(response);
|
|
154
|
+
});
|
|
155
|
+
return promise;
|
|
156
|
+
// Assert that the completion promise resolves with the expected response.
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
package/src/ivms/types.ts
CHANGED
|
@@ -120,22 +120,38 @@ export type DateAndPlaceOfBirth = {
|
|
|
120
120
|
* Address
|
|
121
121
|
*/
|
|
122
122
|
export type Address = {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
123
|
+
/** Identifies the nature of the address. */
|
|
124
|
+
addressType: AddressTypeCode;
|
|
125
|
+
/** Identification of a division of a large organisation or building. */
|
|
126
|
+
department?: string;
|
|
127
|
+
/** Identification of a sub-division of a large organisation or building. */
|
|
128
|
+
subDepartment?: string;
|
|
129
|
+
/** Name of a street or thoroughfare. */
|
|
130
|
+
streetName?: string;
|
|
131
|
+
/** Number that identifies the position of a building on a street. */
|
|
132
|
+
buildingNumber?: string;
|
|
133
|
+
/** Name of the building or house. */
|
|
134
|
+
buildingName?: string;
|
|
135
|
+
/** Floor or storey within a building. */
|
|
136
|
+
floor?: string;
|
|
137
|
+
/** Numbered box in a post office. */
|
|
138
|
+
postBox?: string;
|
|
139
|
+
/** Building room number. */
|
|
140
|
+
room?: string;
|
|
141
|
+
/** Identifier consisting of a group of letters and/or numbers that is added to a postal address to assist the sorting of mail. */
|
|
142
|
+
postcode?: string;
|
|
143
|
+
/** Name of a built-up area, with defined boundaries, and a local government. */
|
|
144
|
+
townName: string;
|
|
145
|
+
/** Specific location name within the town. */
|
|
146
|
+
townLocationName?: string;
|
|
147
|
+
/** Identifies a subdivision within a country subdivision. */
|
|
148
|
+
districtName?: string;
|
|
149
|
+
/** Identifies a subdivision of a country such as state, region, province. */
|
|
150
|
+
countrySubDivision?: string;
|
|
151
|
+
/** Information that locates and identifies a specific address, presented in free format text. */
|
|
152
|
+
addressLine?: string[];
|
|
153
|
+
/** Nation with its own government. */
|
|
154
|
+
country: string;
|
|
139
155
|
};
|
|
140
156
|
|
|
141
157
|
/**
|
|
@@ -173,12 +189,18 @@ export type NaturalPersonName = {
|
|
|
173
189
|
* NaturalPerson
|
|
174
190
|
*/
|
|
175
191
|
export type NaturalPerson = {
|
|
176
|
-
|
|
192
|
+
/** The distinct words used as identification for an individual. */
|
|
193
|
+
name: NaturalPersonName;
|
|
194
|
+
/** The particulars of a location at which a person may be communicated with. */
|
|
177
195
|
geographicAddress?: Address[];
|
|
196
|
+
/** A distinct identifier used by governments to uniquely identify a natural person. */
|
|
178
197
|
nationalIdentification?: NationalIdentification;
|
|
179
|
-
|
|
198
|
+
/** A distinct identifier that uniquely identifies the person to the institution in context. */
|
|
199
|
+
customerIdentification?: string;
|
|
200
|
+
/** Date and place of birth of a person. */
|
|
180
201
|
dateAndPlaceOfBirth?: DateAndPlaceOfBirth;
|
|
181
|
-
|
|
202
|
+
/** Country in which a person resides (the place of a person's home). */
|
|
203
|
+
countryOfResidence?: string;
|
|
182
204
|
};
|
|
183
205
|
|
|
184
206
|
/**
|
|
@@ -195,8 +217,10 @@ export type LocalLegalPersonNameID = {
|
|
|
195
217
|
* LegalPersonNameID
|
|
196
218
|
*/
|
|
197
219
|
export type LegalPersonNameID = {
|
|
198
|
-
|
|
199
|
-
|
|
220
|
+
/** Name by which the legal person is known. */
|
|
221
|
+
legalPersonName: string;
|
|
222
|
+
/** The nature of the name specified. */
|
|
223
|
+
legalPersonNameIdentifierType: LegalPersonNameTypeCode;
|
|
200
224
|
};
|
|
201
225
|
|
|
202
226
|
/**
|
|
@@ -204,7 +228,7 @@ export type LegalPersonNameID = {
|
|
|
204
228
|
* LegalPersonName
|
|
205
229
|
*/
|
|
206
230
|
export type LegalPersonName = {
|
|
207
|
-
nameIdentifier
|
|
231
|
+
nameIdentifier: LegalPersonNameID[];
|
|
208
232
|
localNameIdentifier?: LocalLegalPersonNameID[];
|
|
209
233
|
phoneticNameIdentifier?: LocalLegalPersonNameID[];
|
|
210
234
|
};
|
|
@@ -214,11 +238,16 @@ export type LegalPersonName = {
|
|
|
214
238
|
* LegalPerson
|
|
215
239
|
*/
|
|
216
240
|
export type LegalPerson = {
|
|
217
|
-
name
|
|
241
|
+
/** The name of the legal person. */
|
|
242
|
+
name: LegalPersonName;
|
|
243
|
+
/** The address of the legal person. */
|
|
218
244
|
geographicAddress?: Address[];
|
|
219
|
-
|
|
245
|
+
/** A distinct identifier that uniquely identifies the person to the institution in context. */
|
|
246
|
+
customerNumber?: string;
|
|
247
|
+
/** A distinct identifier used by governments to uniquely identify a legal person. */
|
|
220
248
|
nationalIdentification?: NationalIdentification;
|
|
221
|
-
|
|
249
|
+
/** The country in which the legal person is registered. */
|
|
250
|
+
countryOfRegistration?: string;
|
|
222
251
|
};
|
|
223
252
|
|
|
224
253
|
/**
|
|
@@ -285,12 +314,26 @@ export type TransferPath = {
|
|
|
285
314
|
* 6.7
|
|
286
315
|
* Data describing the contents of the payload.
|
|
287
316
|
*/
|
|
288
|
-
export
|
|
289
|
-
|
|
290
|
-
|
|
317
|
+
export interface PayloadMetadata {
|
|
318
|
+
/** The method used to map from a national system of writing to Latin script. */
|
|
319
|
+
transliterationMethod?: TransliterationMethodCode[];
|
|
320
|
+
/** The version of IVMS 101 to which the payload complies. */
|
|
321
|
+
payloadVersion: PayloadVersionCode;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* The version of IVMS 101 to which the payload complies.
|
|
325
|
+
*/
|
|
326
|
+
export enum PayloadVersionCode {
|
|
327
|
+
/** Published May 2020 */
|
|
328
|
+
V101 = '101',
|
|
329
|
+
/** Published August 2023 */
|
|
330
|
+
V101_2023 = '101.2023',
|
|
331
|
+
}
|
|
291
332
|
|
|
292
333
|
/**
|
|
293
334
|
* IVMS101 definition
|
|
335
|
+
*
|
|
336
|
+
* @public
|
|
294
337
|
*/
|
|
295
338
|
export type IVMS101 = {
|
|
296
339
|
originator?: Originator;
|