@notabene/javascript-sdk 1.34.0 → 2.0.0-next.11
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 +319 -261
- package/dist/notabene.cjs +1 -0
- package/dist/notabene.d.ts +1136 -0
- package/dist/notabene.js +296 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +45 -62
- package/src/__tests__/notabene.test.ts +159 -0
- package/src/arbitraries.ts +13 -0
- package/src/components/EmbeddedComponent.ts +217 -0
- package/src/components/__tests__/EmbeddedComponent.test.ts +188 -0
- package/src/ivms/types.ts +232 -152
- package/src/notabene.ts +264 -284
- package/src/types.ts +609 -78
- 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/dist/notabene.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
var d = Object.defineProperty;
|
|
2
|
+
var c = (r, e, t) => e in r ? d(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var n = (r, e, t) => c(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
var a = /* @__PURE__ */ ((r) => (r.COMPLETE = "complete", r.RESIZE = "resize", r.RESULT = "result", r.READY = "ready", r.INVALID = "invalid", r.MODAL = "openModal", r.ERROR = "error", r.CLOSE = "closeModal", r.CANCEL = "cancel", r))(a || {}), l = /* @__PURE__ */ ((r) => (r.UPDATE = "update", r.REQUEST_RESPONSE = "requestResponse", r))(l || {});
|
|
5
|
+
class m {
|
|
6
|
+
constructor() {
|
|
7
|
+
n(this, "listeners", /* @__PURE__ */ new Map());
|
|
8
|
+
n(this, "port");
|
|
9
|
+
this.handleMessage = this.handleMessage.bind(this);
|
|
10
|
+
}
|
|
11
|
+
setPort(e) {
|
|
12
|
+
this.port = e, this.port.onmessage = this.handleMessage, this.port.start();
|
|
13
|
+
}
|
|
14
|
+
on(e, t) {
|
|
15
|
+
this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(t);
|
|
16
|
+
}
|
|
17
|
+
off(e, t) {
|
|
18
|
+
const s = this.listeners.get(e);
|
|
19
|
+
s && (s.delete(t), s.size === 0 && this.listeners.delete(e));
|
|
20
|
+
}
|
|
21
|
+
handleMessage(e) {
|
|
22
|
+
console.log("received message", e.data);
|
|
23
|
+
const t = e.data;
|
|
24
|
+
if (typeof t == "object" && t !== null && "type" in t) {
|
|
25
|
+
const s = t.type, o = this.listeners.get(s);
|
|
26
|
+
o && o.forEach((i) => i(t));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Method to send messages through the port
|
|
30
|
+
send(e) {
|
|
31
|
+
this.port && this.port.postMessage(e);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class u {
|
|
35
|
+
/**
|
|
36
|
+
* Creates an instance of EmbeddedComponent.
|
|
37
|
+
* @param url - The URL of the embedded component
|
|
38
|
+
* @param value - The initial transaction value
|
|
39
|
+
*/
|
|
40
|
+
constructor(e, t) {
|
|
41
|
+
n(this, "_url");
|
|
42
|
+
n(this, "_value");
|
|
43
|
+
n(this, "_errors", []);
|
|
44
|
+
n(this, "iframe");
|
|
45
|
+
n(this, "eventManager");
|
|
46
|
+
n(this, "modal");
|
|
47
|
+
this._url = e, this._value = t, this.eventManager = new m(), this.on(a.INVALID, (s) => {
|
|
48
|
+
s.type === a.INVALID && (this._errors = s.errors, this._value = s.value);
|
|
49
|
+
}), this.on(a.RESIZE, (s) => {
|
|
50
|
+
s.type === a.RESIZE && this.iframe && (this.iframe.style.height = `${s.height}px`);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the URL of the embedded component
|
|
55
|
+
* @returns The URL of the embedded component
|
|
56
|
+
*/
|
|
57
|
+
get url() {
|
|
58
|
+
return this._url;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets the current transaction value
|
|
62
|
+
* @returns The current transaction value
|
|
63
|
+
*/
|
|
64
|
+
get value() {
|
|
65
|
+
return this._value;
|
|
66
|
+
}
|
|
67
|
+
get errors() {
|
|
68
|
+
return this._errors;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Opens the component URL in the current window
|
|
72
|
+
*/
|
|
73
|
+
open() {
|
|
74
|
+
document.location.href = this.url;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Mounts the component to a parent element
|
|
78
|
+
* @param parentId - The ID of the parent element
|
|
79
|
+
* @throws Will throw an error if the parent element is not found
|
|
80
|
+
*/
|
|
81
|
+
mount(e) {
|
|
82
|
+
const t = document.querySelector(e);
|
|
83
|
+
if (!t) throw new Error(`parentID ${e} not found`);
|
|
84
|
+
this.embed(t);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Embeds the component into a parent element
|
|
88
|
+
* @param parent - The parent element to embed the component into
|
|
89
|
+
*/
|
|
90
|
+
embed(e) {
|
|
91
|
+
var t, s;
|
|
92
|
+
this.iframe = document.createElement("iframe"), this.iframe.src = this.url, this.iframe.style.width = "100%", this.iframe.style.height = "100px", this.iframe.style.border = "none", this.iframe.style.overflow = "hidden", this.iframe.setAttribute("allowtransparency", "true"), this.iframe.style.backgroundColor = "transparent", e.appendChild(this.iframe), window.addEventListener("message", (o) => {
|
|
93
|
+
var i, h;
|
|
94
|
+
o.source === ((i = this.iframe) == null ? void 0 : i.contentWindow) && (console.log("received message from iframe", o.data), (h = this.eventManager) == null || h.setPort(o.ports[0]));
|
|
95
|
+
}), (s = (t = this.iframe) == null ? void 0 : t.contentWindow) == null || s.focus();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Sends a message to the embedded component
|
|
99
|
+
* @param message - The message to send
|
|
100
|
+
*/
|
|
101
|
+
send(e) {
|
|
102
|
+
this.eventManager.send(e);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Adds an event listener for a specific message type
|
|
106
|
+
* @param messageType - The type of message to listen for
|
|
107
|
+
* @param callback - The callback function to execute when the message is received
|
|
108
|
+
*/
|
|
109
|
+
on(e, t) {
|
|
110
|
+
this.eventManager.on(e, t);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Removes an event listener for a specific message type
|
|
114
|
+
* @param messageType - The type of message to stop listening for
|
|
115
|
+
* @param callback - The callback function to remove
|
|
116
|
+
*/
|
|
117
|
+
off(e, t) {
|
|
118
|
+
this.eventManager.off(e, t);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Updates the transaction value and sends an update message to the component
|
|
122
|
+
* @param value - The new transaction value
|
|
123
|
+
*/
|
|
124
|
+
update(e) {
|
|
125
|
+
this._value = e, this.send({ type: l.UPDATE, value: e });
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Waits for the component to complete and returns the transaction response
|
|
129
|
+
* @returns A promise that resolves with the transaction response
|
|
130
|
+
*/
|
|
131
|
+
completion() {
|
|
132
|
+
return new Promise((e, t) => {
|
|
133
|
+
this.on(a.COMPLETE, (s) => {
|
|
134
|
+
e(s.response);
|
|
135
|
+
}), this.on("error", (s) => {
|
|
136
|
+
t(new Error(s.message));
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Opens the component in a modal dialog
|
|
142
|
+
*/
|
|
143
|
+
openModal() {
|
|
144
|
+
return this.modal && this.closeModal(), this.modal = document.createElement("dialog"), this.modal.style.border = "none", this.modal.style.backgroundColor = "transparent", this.modal.style.maxWidth = "100vw", this.modal.style.maxHeight = "100vh", this.modal.style.width = "600px", this.modal.style.height = "800px", document.body.appendChild(this.modal), this.embed(this.modal), this.on(a.CANCEL, () => {
|
|
145
|
+
this.closeModal();
|
|
146
|
+
}), this.on(a.CLOSE, () => {
|
|
147
|
+
this.closeModal();
|
|
148
|
+
}), this.on(a.COMPLETE, () => {
|
|
149
|
+
this.closeModal();
|
|
150
|
+
}), this.modal.showModal(), this.modal.addEventListener("click", () => {
|
|
151
|
+
this.closeModal();
|
|
152
|
+
}), this.completion();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Closes the modal dialog
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
closeModal() {
|
|
159
|
+
var e;
|
|
160
|
+
this.modal && (console.log("closeModal"), (e = this.modal) == null || e.close(), this.modal.remove(), this.modal = void 0);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function f(r) {
|
|
164
|
+
return Object.entries(r).map(([e, t]) => {
|
|
165
|
+
if (!(e && t)) return;
|
|
166
|
+
const s = encodeURIComponent(e), o = encodeURIComponent(
|
|
167
|
+
typeof t == "object" ? JSON.stringify(t) : t
|
|
168
|
+
);
|
|
169
|
+
return `${s}=${o}`;
|
|
170
|
+
}).filter((e) => !!e).join("&");
|
|
171
|
+
}
|
|
172
|
+
class E {
|
|
173
|
+
/**
|
|
174
|
+
* Creates a new instance of the Notabene SDK
|
|
175
|
+
*
|
|
176
|
+
* @param config - Configuration options for the Notabene SDK
|
|
177
|
+
*/
|
|
178
|
+
constructor(e) {
|
|
179
|
+
n(this, "nodeUrl");
|
|
180
|
+
n(this, "authToken");
|
|
181
|
+
n(this, "uxUrl");
|
|
182
|
+
n(this, "theme");
|
|
183
|
+
n(this, "locale");
|
|
184
|
+
this.uxUrl = e.uxUrl || "https://connect.notabene.id", this.nodeUrl = e.nodeUrl, this.authToken = e.authToken, this.theme = e.theme, this.locale = e.locale;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Generates a URL for a Notabene component
|
|
188
|
+
*
|
|
189
|
+
* @param path - The path of the component
|
|
190
|
+
* @param value - Transaction data
|
|
191
|
+
* @param configuration - Optional transaction configuration
|
|
192
|
+
* @param callbacks - Optional callback configuration
|
|
193
|
+
* @returns component URL
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
componentUrl(e, t, s, o) {
|
|
197
|
+
const i = new URL(this.uxUrl);
|
|
198
|
+
i.pathname = e;
|
|
199
|
+
const h = f({
|
|
200
|
+
authToken: this.authToken,
|
|
201
|
+
value: t,
|
|
202
|
+
configuration: s
|
|
203
|
+
});
|
|
204
|
+
return i.hash = h, this.nodeUrl && i.searchParams.set("nodeUrl", this.nodeUrl), this.theme && i.searchParams.set("theme", JSON.stringify(this.theme)), this.locale && i.searchParams.set("locale", this.locale), o && (o.callback && i.searchParams.set("callback_url", o.callback), o.redirectUri && i.searchParams.set("redirect_uri", o.redirectUri)), i.toString();
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Creates a new embedded component
|
|
208
|
+
*
|
|
209
|
+
* @param path - The path of the component
|
|
210
|
+
* @param value - Transaction data
|
|
211
|
+
* @param options - Optional transaction options
|
|
212
|
+
* @param callbacks - Optional callback configuration
|
|
213
|
+
* @returns A new EmbeddedComponent instance
|
|
214
|
+
* @internal
|
|
215
|
+
*/
|
|
216
|
+
createComponent(e, t, s, o) {
|
|
217
|
+
return new u(
|
|
218
|
+
this.componentUrl(e, t, s, o),
|
|
219
|
+
t
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Creates a withdrawal assist component
|
|
224
|
+
*
|
|
225
|
+
* @param value - Withdrawal transaction data
|
|
226
|
+
* @param options - Optional transaction options
|
|
227
|
+
* @param callbacks - Optional callback configuration
|
|
228
|
+
* @returns A new EmbeddedComponent instance for withdrawal assistance
|
|
229
|
+
*/
|
|
230
|
+
createWithdrawalAssist(e, t, s) {
|
|
231
|
+
return this.createComponent("withdrawal-assist", e, t, s);
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Creates a deposit assist component
|
|
235
|
+
*
|
|
236
|
+
* @param value - Deposit transaction data
|
|
237
|
+
* @param options - Optional transaction options
|
|
238
|
+
* @param callbacks - Optional callback configuration
|
|
239
|
+
* @returns A new EmbeddedComponent instance for deposit assistance
|
|
240
|
+
* @alpha
|
|
241
|
+
*/
|
|
242
|
+
createDepositAssist(e, t, s) {
|
|
243
|
+
return this.createComponent(
|
|
244
|
+
"deposit-assist",
|
|
245
|
+
e,
|
|
246
|
+
t,
|
|
247
|
+
s
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Creates a connect component
|
|
252
|
+
*
|
|
253
|
+
* @param value - Connection request data
|
|
254
|
+
* @param options - Optional transaction options
|
|
255
|
+
* @param callbacks - Optional callback configuration
|
|
256
|
+
* @returns A new EmbeddedComponent instance for connection
|
|
257
|
+
*/
|
|
258
|
+
createConnectWallet(e, t, s) {
|
|
259
|
+
return this.createComponent(
|
|
260
|
+
"connect",
|
|
261
|
+
e,
|
|
262
|
+
t,
|
|
263
|
+
s
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Creates a deposit request component
|
|
268
|
+
*
|
|
269
|
+
* @param value - Deposit request data
|
|
270
|
+
* @param options - Optional transaction options
|
|
271
|
+
* @param callbacks - Optional callback configuration
|
|
272
|
+
* @returns A new EmbeddedComponent instance for deposit requests
|
|
273
|
+
* @alpha
|
|
274
|
+
*/
|
|
275
|
+
createDepositRequest(e, t, s) {
|
|
276
|
+
return this.createComponent("deposit-request", e, t, s);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Decodes a URL fragment into an object
|
|
280
|
+
*
|
|
281
|
+
* @param fragment - The URL fragment to decode
|
|
282
|
+
* @returns An object containing the decoded key-value pairs
|
|
283
|
+
*/
|
|
284
|
+
decodeFragmentToObject(e) {
|
|
285
|
+
return e.slice(1).split("&").reduce(
|
|
286
|
+
(s, o) => {
|
|
287
|
+
const [i, h] = o.split("=");
|
|
288
|
+
return s[decodeURIComponent(i)] = decodeURIComponent(h), s;
|
|
289
|
+
},
|
|
290
|
+
{}
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
export {
|
|
295
|
+
E as default
|
|
296
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.47.9"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@notabene/javascript-sdk",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"description": "JavaScript SDK for Notabene",
|
|
4
5
|
"homepage": "https://gitlab.com/notabene/open-source/javascript-sdk",
|
|
5
6
|
"repository": {
|
|
@@ -8,74 +9,60 @@
|
|
|
8
9
|
},
|
|
9
10
|
"author": "Notabene <developers@notabene.id>",
|
|
10
11
|
"license": "MIT",
|
|
11
|
-
"version": "
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"version": "2.0.0-next.11",
|
|
13
|
+
"source": "src/notabene.ts",
|
|
14
|
+
"main": "dist/notabene.js",
|
|
15
|
+
"types": "dist/notabene.d.ts",
|
|
14
16
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
},
|
|
22
|
-
"lib": {
|
|
23
|
-
"source": "src/lib/index.ts",
|
|
24
|
-
"isLibrary": true,
|
|
25
|
-
"context": "node",
|
|
26
|
-
"outputFormat": "commonjs"
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"publishConfig": {
|
|
30
|
-
"access": "public"
|
|
31
|
-
},
|
|
32
|
-
"alias": {
|
|
33
|
-
"process": false,
|
|
34
|
-
"buffer": false
|
|
35
|
-
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"src",
|
|
20
|
+
"package.json",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
36
23
|
"scripts": {
|
|
24
|
+
"docs": "typedoc --options typedoc.json",
|
|
37
25
|
"prepare": "husky install",
|
|
26
|
+
"dev": "vite",
|
|
27
|
+
"preview": "vite preview",
|
|
38
28
|
"watch": "parcel watch",
|
|
39
|
-
"dev": "sirv --dev --port 3002 public",
|
|
40
29
|
"build:dev": "yarn build && yarn dev",
|
|
41
|
-
"build": "
|
|
42
|
-
"build
|
|
43
|
-
"build:compile": "parcel build --no-source-maps && cp dist/es/index.js public/js/notabene.js",
|
|
30
|
+
"build:clean": "rimraf dist/ ts-out",
|
|
31
|
+
"build": "yarn lint && vite build && tsc && api-extractor run && yarn docs ",
|
|
44
32
|
"lint": "eslint .",
|
|
45
|
-
"test": "
|
|
46
|
-
"release": "semantic-release"
|
|
33
|
+
"test": "vitest",
|
|
34
|
+
"release": "semantic-release",
|
|
35
|
+
"publish": "yarn build && npm publish --tag next"
|
|
47
36
|
},
|
|
48
37
|
"devDependencies": {
|
|
49
|
-
"@commitlint/cli": "^
|
|
50
|
-
"@commitlint/config-conventional": "^
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
38
|
+
"@commitlint/cli": "^19.5.0",
|
|
39
|
+
"@commitlint/config-conventional": "^19.5.0",
|
|
40
|
+
"@eslint/js": "^9.10.0",
|
|
41
|
+
"@fast-check/vitest": "^0.1.3",
|
|
42
|
+
"@microsoft/api-extractor": "^7.47.9",
|
|
53
43
|
"@semantic-release/git": "^10.0.1",
|
|
54
|
-
"@semantic-release/gitlab": "^9.
|
|
55
|
-
"@semantic-release/npm": "^9.0.
|
|
56
|
-
"@
|
|
57
|
-
"@typescript-eslint/
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"eslint": "^
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"eslint-plugin-import": "^2.25.4",
|
|
64
|
-
"eslint-plugin-node": "^11.1.0",
|
|
65
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
66
|
-
"eslint-plugin-promise": "^6.0.0",
|
|
44
|
+
"@semantic-release/gitlab": "^9.5.1",
|
|
45
|
+
"@semantic-release/npm": "^9.0.2",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^8.6.0",
|
|
47
|
+
"@typescript-eslint/parser": "^8.6.0",
|
|
48
|
+
"eslint": "^9.10.0",
|
|
49
|
+
"eslint-config-prettier": "^9.1.0",
|
|
50
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
51
|
+
"fast-check": "^3.22.0",
|
|
52
|
+
"globals": "^15.9.0",
|
|
67
53
|
"husky": "^7.0.4",
|
|
68
|
-
"
|
|
69
|
-
"lint-staged": "^12.
|
|
54
|
+
"jsdom": "^25.0.0",
|
|
55
|
+
"lint-staged": "^12.5.0",
|
|
70
56
|
"organize-imports-cli": "^0.9.0",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
57
|
+
"prettier": "^3.3.3",
|
|
58
|
+
"rimraf": "^6.0.1",
|
|
59
|
+
"semantic-release": "^24.1.1",
|
|
60
|
+
"typedoc": "^0.26.7",
|
|
61
|
+
"typedoc-plugin-markdown": "^4.2.7",
|
|
62
|
+
"typescript": "^5.6.2",
|
|
63
|
+
"typescript-eslint": "^8.6.0",
|
|
64
|
+
"vite": "^5.4.6",
|
|
65
|
+
"vitest": "^2.1.1"
|
|
79
66
|
},
|
|
80
67
|
"lint-staged": {
|
|
81
68
|
"*.ts": [
|
|
@@ -87,9 +74,5 @@
|
|
|
87
74
|
"extends": [
|
|
88
75
|
"@commitlint/config-conventional"
|
|
89
76
|
]
|
|
90
|
-
},
|
|
91
|
-
"dependencies": {
|
|
92
|
-
"jsx-pragmatic": "^2.0.22",
|
|
93
|
-
"zoid": "^9.0.86"
|
|
94
77
|
}
|
|
95
|
-
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { fc, test } from '@fast-check/vitest';
|
|
2
|
+
import { describe } from 'vitest';
|
|
3
|
+
import { abitraryCallbackOptions, arbitraryComponent } from '../arbitraries';
|
|
4
|
+
import Notabene from '../notabene';
|
|
5
|
+
import { arbitraryLocale } from '../utils/arbitraries';
|
|
6
|
+
|
|
7
|
+
describe('Notabene', () => {
|
|
8
|
+
describe('defaults', () => {
|
|
9
|
+
test.prop([
|
|
10
|
+
fc.string({ minLength: 3 }),
|
|
11
|
+
fc.webUrl(),
|
|
12
|
+
arbitraryComponent(),
|
|
13
|
+
fc.object(),
|
|
14
|
+
])(
|
|
15
|
+
'Should set the correct values',
|
|
16
|
+
(authToken, nodeUrl, component, value) => {
|
|
17
|
+
const notabene = new Notabene({
|
|
18
|
+
nodeUrl,
|
|
19
|
+
authToken,
|
|
20
|
+
});
|
|
21
|
+
const url = new URL(notabene.componentUrl(component, value));
|
|
22
|
+
return (
|
|
23
|
+
url.hash ===
|
|
24
|
+
`#authToken=${encodeURIComponent(authToken)}&value=${encodeURIComponent(JSON.stringify(value))}` &&
|
|
25
|
+
url.searchParams.get('nodeUrl') === nodeUrl &&
|
|
26
|
+
url.pathname === `/${component}`
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('locale', () => {
|
|
33
|
+
test.prop([
|
|
34
|
+
fc.string({ minLength: 3 }),
|
|
35
|
+
fc.webUrl(),
|
|
36
|
+
arbitraryComponent(),
|
|
37
|
+
fc.object(),
|
|
38
|
+
arbitraryLocale(),
|
|
39
|
+
])(
|
|
40
|
+
'Should set the correct values',
|
|
41
|
+
(authToken, nodeUrl, component, value, locale) => {
|
|
42
|
+
const notabene = new Notabene({
|
|
43
|
+
nodeUrl,
|
|
44
|
+
authToken,
|
|
45
|
+
locale,
|
|
46
|
+
});
|
|
47
|
+
const url = new URL(notabene.componentUrl(component, value));
|
|
48
|
+
return (
|
|
49
|
+
url.hash ===
|
|
50
|
+
`#authToken=${encodeURIComponent(authToken)}&value=${encodeURIComponent(JSON.stringify(value))}` &&
|
|
51
|
+
url.searchParams.get('nodeUrl') === nodeUrl &&
|
|
52
|
+
url.searchParams.get('locale') === locale &&
|
|
53
|
+
url.pathname === `/${component}`
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('minimal', () => {
|
|
60
|
+
test.prop([arbitraryComponent(), fc.object()])(
|
|
61
|
+
'Should set the correct values',
|
|
62
|
+
(component, value) => {
|
|
63
|
+
const notabene = new Notabene({});
|
|
64
|
+
const url = new URL(notabene.componentUrl(component, value));
|
|
65
|
+
return (
|
|
66
|
+
url.hash === `#value=${encodeURIComponent(JSON.stringify(value))}` &&
|
|
67
|
+
url.hostname === 'connect.notabene.id' &&
|
|
68
|
+
url.pathname === `/${component}`
|
|
69
|
+
);
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe('with uxUrl', () => {
|
|
75
|
+
test.prop([
|
|
76
|
+
fc.string({ minLength: 3 }),
|
|
77
|
+
fc.webUrl(),
|
|
78
|
+
arbitraryComponent(),
|
|
79
|
+
fc.webAuthority(),
|
|
80
|
+
fc.object(),
|
|
81
|
+
])(
|
|
82
|
+
'Should set the correct values',
|
|
83
|
+
(authToken, nodeUrl, component, uxAuthority, value) => {
|
|
84
|
+
const notabene = new Notabene({
|
|
85
|
+
nodeUrl,
|
|
86
|
+
authToken,
|
|
87
|
+
uxUrl: `https://${uxAuthority}`,
|
|
88
|
+
});
|
|
89
|
+
const url = new URL(notabene.componentUrl(component, value));
|
|
90
|
+
const [domain, port] = uxAuthority.split(':');
|
|
91
|
+
return (
|
|
92
|
+
url.hostname === domain &&
|
|
93
|
+
url.port === (port || '') &&
|
|
94
|
+
url.hash ===
|
|
95
|
+
`#authToken=${encodeURIComponent(authToken)}&value=${encodeURIComponent(JSON.stringify(value))}` &&
|
|
96
|
+
url.searchParams.get('nodeUrl') === nodeUrl &&
|
|
97
|
+
url.pathname === `/${component}`
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('with value and configuration', () => {
|
|
104
|
+
test.prop([
|
|
105
|
+
fc.string({ minLength: 3 }),
|
|
106
|
+
fc.webUrl(),
|
|
107
|
+
arbitraryComponent(),
|
|
108
|
+
fc.object(),
|
|
109
|
+
fc.object(),
|
|
110
|
+
])(
|
|
111
|
+
'Should set the correct values',
|
|
112
|
+
(authToken, nodeUrl, component, value, configuration) => {
|
|
113
|
+
const notabene = new Notabene({
|
|
114
|
+
nodeUrl,
|
|
115
|
+
authToken,
|
|
116
|
+
});
|
|
117
|
+
const url = new URL(
|
|
118
|
+
notabene.componentUrl(component, value, configuration),
|
|
119
|
+
);
|
|
120
|
+
return (
|
|
121
|
+
url.hash ===
|
|
122
|
+
`#authToken=${encodeURIComponent(authToken)}&value=${encodeURIComponent(JSON.stringify(value))}&configuration=${encodeURIComponent(JSON.stringify(configuration))}` &&
|
|
123
|
+
url.searchParams.get('nodeUrl') === nodeUrl &&
|
|
124
|
+
url.pathname === `/${component}`
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('with value and configuration', () => {
|
|
131
|
+
test.prop([
|
|
132
|
+
fc.string({ minLength: 3 }),
|
|
133
|
+
fc.webUrl(),
|
|
134
|
+
arbitraryComponent(),
|
|
135
|
+
fc.object(),
|
|
136
|
+
fc.object(),
|
|
137
|
+
abitraryCallbackOptions(),
|
|
138
|
+
])(
|
|
139
|
+
'Should set the correct values',
|
|
140
|
+
(authToken, nodeUrl, component, value, configuration, callbacks) => {
|
|
141
|
+
const notabene = new Notabene({
|
|
142
|
+
nodeUrl,
|
|
143
|
+
authToken,
|
|
144
|
+
});
|
|
145
|
+
const url = new URL(
|
|
146
|
+
notabene.componentUrl(component, value, configuration, callbacks),
|
|
147
|
+
);
|
|
148
|
+
return (
|
|
149
|
+
url.hash ===
|
|
150
|
+
`#authToken=${encodeURIComponent(authToken)}&value=${encodeURIComponent(JSON.stringify(value))}&configuration=${encodeURIComponent(JSON.stringify(configuration))}` &&
|
|
151
|
+
url.searchParams.get('nodeUrl') === nodeUrl &&
|
|
152
|
+
url.pathname === `/${component}` &&
|
|
153
|
+
url.searchParams.get('callback_url') === callbacks.callback &&
|
|
154
|
+
url.searchParams.get('redirect_uri') === callbacks.redirectUri
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fc from 'fast-check';
|
|
2
|
+
import { CallbackOptions } from './types';
|
|
3
|
+
|
|
4
|
+
const COMPONENT_MATCHER = /^[a-z0-9-_]+$/;
|
|
5
|
+
// Arbitraries
|
|
6
|
+
export const arbitraryComponent = (): fc.Arbitrary<string> =>
|
|
7
|
+
fc.stringMatching(COMPONENT_MATCHER);
|
|
8
|
+
|
|
9
|
+
export const abitraryCallbackOptions = (): fc.Arbitrary<CallbackOptions> =>
|
|
10
|
+
fc.record({
|
|
11
|
+
callback: fc.webUrl(),
|
|
12
|
+
redirectUri: fc.webUrl(),
|
|
13
|
+
});
|