@notabene/javascript-sdk 1.35.2 → 2.0.0-RC

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 (46) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +498 -268
  3. package/dist/notabene.cjs +1 -0
  4. package/dist/notabene.d.ts +1565 -0
  5. package/dist/notabene.js +343 -0
  6. package/dist/tsdoc-metadata.json +11 -0
  7. package/package.json +50 -63
  8. package/src/__tests__/notabene.test.ts +270 -0
  9. package/src/components/EmbeddedComponent.ts +237 -0
  10. package/src/components/__tests__/EmbeddedComponent.test.ts +530 -0
  11. package/src/ivms/types.ts +232 -152
  12. package/src/locales.ts +47 -0
  13. package/src/notabene.ts +292 -293
  14. package/src/types.ts +1068 -78
  15. package/src/utils/MessageEventManager.ts +115 -0
  16. package/src/utils/__tests__/MessageEventManager.test.ts +119 -0
  17. package/src/utils/__tests__/urls.test.ts +112 -0
  18. package/src/utils/arbitraries.ts +244 -0
  19. package/src/utils/caip.ts +16 -0
  20. package/src/utils/urls.ts +40 -0
  21. package/.editorconfig +0 -10
  22. package/.envrc.template +0 -1
  23. package/.eslintignore +0 -3
  24. package/.eslintrc.js +0 -13
  25. package/.gitlab-ci.yml +0 -74
  26. package/.husky/commit-msg +0 -4
  27. package/.husky/pre-commit +0 -4
  28. package/.husky/pre-push +0 -4
  29. package/.nvmrc +0 -1
  30. package/.prettierrc +0 -4
  31. package/.releaserc.json +0 -16
  32. package/.tool-versions +0 -3
  33. package/.vscode/extensions.json +0 -7
  34. package/.vscode/settings.json +0 -11
  35. package/.yarn/releases/yarn-3.2.2.cjs +0 -783
  36. package/.yarnrc.yml +0 -5
  37. package/CODEOWNERS +0 -1
  38. package/dist/lib/index.js +0 -379
  39. package/jest.config.js +0 -5
  40. package/public/index.html +0 -93
  41. package/src/lib/index.ts +0 -2
  42. package/src/module/index.ts +0 -10
  43. package/src/zoidComponentProps.ts +0 -81
  44. package/tsconfig.json +0 -18
  45. /package/dist/{es/index.js → js/notabene.js} +0 -0
  46. /package/{public/js/.gitkeep → src/arbitraries.ts} +0 -0
@@ -0,0 +1,343 @@
1
+ var c = Object.defineProperty;
2
+ var m = (e, t, r) => t in e ? c(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
+ var o = (e, t, r) => m(e, typeof t != "symbol" ? t + "" : t, r);
4
+ var u = /* @__PURE__ */ ((e) => (e.PRIVATE = "WALLET", e.VASP = "VASP", e))(u || {}), E = /* @__PURE__ */ ((e) => (e.NATURAL = "natural", e.LEGAL = "legal", e.SELF = "self", e))(E || {}), f = /* @__PURE__ */ ((e) => (e.EMPTY = "empty", e.VERIFY = "verify", e.PENDING = "pending", e.VERIFIED = "verified", e.BANNED = "banned", e))(f || {}), p = /* @__PURE__ */ ((e) => (e.ASSET = "asset", e.DESTINATION = "destination", e.COUNTERPARTY = "counterparty", e.AGENT = "agent", e))(p || {}), h = /* @__PURE__ */ ((e) => (e.COMPLETE = "complete", e.RESIZE = "resize", e.RESULT = "result", e.READY = "ready", e.INVALID = "invalid", e.ERROR = "error", e.CANCEL = "cancel", e))(h || {}), d = /* @__PURE__ */ ((e) => (e.UPDATE = "update", e.REQUEST_RESPONSE = "requestResponse", e))(d || {}), v = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.FAILED = "rejected", e.FLAGGED = "flagged", e.VERIFIED = "verified", e))(v || {}), g = /* @__PURE__ */ ((e) => (e.SelfDeclaration = "self-declaration", e.SIWE = "siwe", e.SIWX = "siwx", e.EIP191 = "eip-191", e.EIP712 = "eip-712", e.EIP1271 = "eip-1271", e.BIP137 = "bip-137", e.BIP137_XPUB = "xpub", e.ED25519 = "ed25519", e.MicroTransfer = "microtransfer", e.Screenshot = "screenshot", e.Connect = "connect", e))(g || {});
5
+ class I {
6
+ constructor() {
7
+ o(this, "listeners", /* @__PURE__ */ new Map());
8
+ o(this, "port");
9
+ this.handleMessage = this.handleMessage.bind(this);
10
+ }
11
+ /**
12
+ * Sets up the message port for communication.
13
+ *
14
+ * Initializes the MessagePort for receiving messages by setting up the message handler
15
+ * and starting the port.
16
+ *
17
+ * @param port - The MessagePort instance to use for communication
18
+ */
19
+ setPort(t) {
20
+ this.port = t, this.port.onmessage = this.handleMessage, this.port.start();
21
+ }
22
+ /**
23
+ * Registers a callback for a specific message type.
24
+ *
25
+ * When messages of the specified type are received, the callback will be executed
26
+ * with the message data.
27
+ *
28
+ * @param messageType - The type of message to listen for
29
+ * @param callback - The callback function to execute when matching messages are received
30
+
31
+ */
32
+ on(t, r) {
33
+ return this.listeners.has(t) || this.listeners.set(t, /* @__PURE__ */ new Set()), this.listeners.get(t).add(r), () => this.off(t, r);
34
+ }
35
+ /**
36
+ * Removes a callback for a specific message type.
37
+ *
38
+ * If the callback is the last one registered for the message type,
39
+ * the message type entry will be removed entirely.
40
+ *
41
+ * @param messageType - The type of message to remove listener from
42
+ * @param callback - The callback function to remove
43
+ */
44
+ off(t, r) {
45
+ const i = this.listeners.get(t);
46
+ i && (i.delete(r), i.size === 0 && this.listeners.delete(t));
47
+ }
48
+ /**
49
+ * Internal message handler for processing received messages.
50
+ *
51
+ * Validates incoming messages and dispatches them to registered callbacks
52
+ * based on the message type.
53
+ *
54
+ * @param event - The message event containing the component message
55
+ */
56
+ handleMessage(t) {
57
+ const r = t.data;
58
+ if (typeof r == "object" && r !== null && "type" in r) {
59
+ const i = r.type, s = this.listeners.get(i);
60
+ s && s.forEach((n) => n(r));
61
+ }
62
+ }
63
+ /**
64
+ * Sends a message through the message port
65
+ * @param message The host message to send
66
+ */
67
+ send(t) {
68
+ this.port && this.port.postMessage(t);
69
+ }
70
+ }
71
+ class w {
72
+ /**
73
+ * Creates an instance of EmbeddedComponent.
74
+ * @param url - The URL of the embedded component
75
+ * @param value - The initial transaction value
76
+ */
77
+ constructor(t, r, i) {
78
+ o(this, "_url");
79
+ o(this, "_value");
80
+ o(this, "_options");
81
+ o(this, "_errors", []);
82
+ o(this, "iframe");
83
+ o(this, "eventManager");
84
+ o(this, "modal");
85
+ this._url = t, this._value = r, this._options = i, this.eventManager = new I(), this.on(h.INVALID, (s) => {
86
+ s.type === h.INVALID && (this._errors = s.errors, this._value = s.value);
87
+ }), this.on(h.RESIZE, (s) => {
88
+ s.type === h.RESIZE && this.iframe && (this.iframe.style.height = `${s.height}px`);
89
+ });
90
+ }
91
+ /**
92
+ * Gets the URL of the embedded component
93
+ * @returns The URL of the embedded component
94
+ */
95
+ get url() {
96
+ return this._url;
97
+ }
98
+ /**
99
+ * Gets the current transaction value
100
+ * @returns The current transaction value
101
+ */
102
+ get value() {
103
+ return this._value;
104
+ }
105
+ get options() {
106
+ return this._options;
107
+ }
108
+ get errors() {
109
+ return this._errors;
110
+ }
111
+ /**
112
+ * Opens the component URL in the current window
113
+ */
114
+ open() {
115
+ document.location.href = this.url;
116
+ }
117
+ /**
118
+ * Mounts the component to a parent element
119
+ * @param parentId - The ID of the parent element
120
+ * @throws Will throw an error if the parent element is not found
121
+ */
122
+ mount(t) {
123
+ const r = document.querySelector(t);
124
+ if (!r) throw new Error(`parentID ${t} not found`);
125
+ this.embed(r);
126
+ }
127
+ /**
128
+ * Embeds the component into a parent element
129
+ * @param parent - The parent element to embed the component into
130
+ */
131
+ embed(t, r = !1) {
132
+ var i, s;
133
+ this.removeEmbed(), this.iframe = document.createElement("iframe"), this.iframe.src = this.url + (r ? "" : "&embedded=true"), this.iframe.allow = "web-share", this.iframe.style.width = "100%", this.iframe.style.height = "100px", this.iframe.style.border = "none", this.iframe.style.overflow = "hidden", t.appendChild(this.iframe), window.addEventListener("message", (n) => {
134
+ var a, l;
135
+ n.source === ((a = this.iframe) == null ? void 0 : a.contentWindow) && ((l = this.eventManager) == null || l.setPort(n.ports[0]));
136
+ }), (s = (i = this.iframe) == null ? void 0 : i.contentWindow) == null || s.focus();
137
+ }
138
+ removeEmbed() {
139
+ this.iframe && this.iframe.remove();
140
+ }
141
+ /**
142
+ * Sends a message to the embedded component
143
+ * @param message - The message to send
144
+ */
145
+ send(t) {
146
+ this.eventManager.send(t);
147
+ }
148
+ /**
149
+ * Adds an event listener for a specific message type
150
+ * @param messageType - The type of message to listen for
151
+ * @param callback - The callback function to execute when the message is received
152
+ */
153
+ on(t, r) {
154
+ return this.eventManager.on(t, r);
155
+ }
156
+ /**
157
+ * Removes an event listener for a specific message type
158
+ * @param messageType - The type of message to stop listening for
159
+ * @param callback - The callback function to remove
160
+ */
161
+ off(t, r) {
162
+ this.eventManager.off(t, r);
163
+ }
164
+ /**
165
+ * Updates the transaction value and sends an update message to the component
166
+ * @param value - The new transaction value
167
+ */
168
+ update(t, r) {
169
+ this._value = t, r && (this._options = r), this.send({ type: d.UPDATE, value: t, options: this._options });
170
+ }
171
+ /**
172
+ * Waits for the component to complete and returns the transaction response
173
+ * @returns A promise that resolves with the transaction response
174
+ */
175
+ completion() {
176
+ return new Promise((t, r) => {
177
+ let i, s;
178
+ function n() {
179
+ i && i(), s && s();
180
+ }
181
+ i = this.on(h.COMPLETE, (a) => {
182
+ t(a.response), n();
183
+ }), s = this.on("error", (a) => {
184
+ r(new Error(a.message)), n();
185
+ });
186
+ });
187
+ }
188
+ /**
189
+ * Opens the component in a modal dialog
190
+ */
191
+ openModal() {
192
+ return this.modal && this.closeModal(), this.modal = document.createElement("dialog"), this.modal.style.border = "none", this.modal.style.backgroundColor = "white", this.modal.style.maxWidth = "100vw", this.modal.style.maxHeight = "100vh", this.modal.style.width = "600px", this.modal.style.height = "600px", document.body.appendChild(this.modal), this.embed(this.modal, !0), this.on(h.CANCEL, () => {
193
+ this.closeModal();
194
+ }), this.on(h.COMPLETE, () => {
195
+ this.closeModal();
196
+ }), this.modal.showModal(), this.modal.addEventListener("click", () => {
197
+ this.closeModal();
198
+ }), this.completion();
199
+ }
200
+ /**
201
+ * Closes the modal dialog
202
+ *
203
+ */
204
+ closeModal() {
205
+ var t;
206
+ this.modal && ((t = this.modal) == null || t.close(), this.modal.remove(), this.modal = void 0);
207
+ }
208
+ }
209
+ function U(e) {
210
+ return Object.entries(e).map(([t, r]) => {
211
+ if (r == null) return;
212
+ const i = encodeURIComponent(t), s = encodeURIComponent(
213
+ typeof r == "object" ? JSON.stringify(r) : String(r)
214
+ // Use String() to handle all primitive types
215
+ );
216
+ return `${i}=${s}`;
217
+ }).filter((t) => t !== void 0).join("&");
218
+ }
219
+ function b(e) {
220
+ const t = e.slice(1);
221
+ return t ? t.split("&").filter(Boolean).reduce(
222
+ (i, s) => {
223
+ const [n, a] = s.split("=");
224
+ return n && (i[decodeURIComponent(n)] = a ? decodeURIComponent(a) : ""), i;
225
+ },
226
+ {}
227
+ ) : {};
228
+ }
229
+ class A {
230
+ /**
231
+ * Creates a new instance of the Notabene SDK
232
+ *
233
+ * @param config - Configuration options for the Notabene SDK
234
+ */
235
+ constructor(t) {
236
+ o(this, "nodeUrl");
237
+ o(this, "authToken");
238
+ o(this, "uxUrl");
239
+ o(this, "theme");
240
+ o(this, "locale");
241
+ this.uxUrl = t.uxUrl || "https://connect.notabene.id", this.nodeUrl = t.nodeUrl, this.authToken = t.authToken, this.theme = t.theme, this.locale = t.locale;
242
+ }
243
+ /**
244
+ * Generates a URL for a Notabene component
245
+ *
246
+ * @param path - The path of the component
247
+ * @param value - Transaction data
248
+ * @param configuration - Optional transaction configuration
249
+ * @param callbacks - Optional callback configuration
250
+ * @returns component URL
251
+ * @internal
252
+ */
253
+ componentUrl(t, r, i, s) {
254
+ const n = new URL(this.uxUrl);
255
+ n.pathname = t;
256
+ const a = U({
257
+ authToken: this.authToken,
258
+ value: r,
259
+ configuration: i
260
+ });
261
+ return n.hash = a, this.nodeUrl && n.searchParams.set("nodeUrl", this.nodeUrl), this.theme && n.searchParams.set("theme", JSON.stringify(this.theme)), this.locale && n.searchParams.set("locale", this.locale), s && (s.callback && n.searchParams.set("callback_url", s.callback), s.redirectUri && n.searchParams.set("redirect_uri", s.redirectUri)), n.toString();
262
+ }
263
+ /**
264
+ * Creates a new embedded component
265
+ *
266
+ * @param path - The path of the component
267
+ * @param value - Transaction data
268
+ * @param options - Optional transaction options
269
+ * @param callbacks - Optional callback configuration
270
+ * @returns A new EmbeddedComponent instance
271
+ * @internal
272
+ */
273
+ createComponent(t, r, i, s) {
274
+ return new w(
275
+ this.componentUrl(t, r, i, s),
276
+ r,
277
+ i
278
+ );
279
+ }
280
+ /**
281
+ * Creates a withdrawal assist component
282
+ *
283
+ * @param value - Withdrawal transaction data
284
+ * @param options - Optional transaction options
285
+ * @param callbacks - Optional callback configuration
286
+ * @returns A new EmbeddedComponent instance for withdrawal assistance
287
+ */
288
+ createWithdrawalAssist(t, r, i) {
289
+ return this.createComponent(
290
+ "withdrawal-assist",
291
+ t,
292
+ r,
293
+ i
294
+ );
295
+ }
296
+ /**
297
+ * Creates a connect component
298
+ *
299
+ * @param value - Connection request data
300
+ * @param options - Optional transaction options
301
+ * @param callbacks - Optional callback configuration
302
+ * @returns A new EmbeddedComponent instance for connection
303
+ * @alpha
304
+ */
305
+ createConnectWallet(t, r, i) {
306
+ return this.createComponent(
307
+ "connect",
308
+ t,
309
+ r,
310
+ i
311
+ );
312
+ }
313
+ /**
314
+ * Creates a deposit request component
315
+ *
316
+ * @param value - Deposit request data
317
+ * @param options - Optional transaction options
318
+ * @param callbacks - Optional callback configuration
319
+ * @returns A new EmbeddedComponent instance for deposit requests
320
+ * @public
321
+ */
322
+ createDepositRequest(t, r, i) {
323
+ return this.createComponent(
324
+ "deposit-request",
325
+ t,
326
+ r,
327
+ i
328
+ );
329
+ }
330
+ }
331
+ export {
332
+ u as AgentType,
333
+ h as CMType,
334
+ w as EmbeddedComponent,
335
+ d as HMType,
336
+ E as PersonType,
337
+ v as ProofStatus,
338
+ g as ProofTypes,
339
+ f as Status,
340
+ p as ValidationSections,
341
+ b as decodeFragmentToObject,
342
+ A as default
343
+ };
@@ -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.11"
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,73 +9,63 @@
8
9
  },
9
10
  "author": "Notabene <developers@notabene.id>",
10
11
  "license": "MIT",
11
- "version": "1.35.2",
12
- "main": "dist/index.js",
13
- "packageManager": "yarn@3.2.2",
12
+ "version": "2.0.0-RC",
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
- "targets": {
16
- "es": {
17
- "source": "src/module/index.ts",
18
- "isLibrary": false,
19
- "context": "browser",
20
- "outputFormat": "esmodule"
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",
25
+ "prepare": "husky install",
26
+ "dev": "vite",
27
+ "preview": "vite preview",
37
28
  "watch": "parcel watch",
38
- "dev": "sirv --dev --port 3002 public",
39
29
  "build:dev": "yarn build && yarn dev",
40
- "build": "yarn build:clean && yarn build:compile",
41
- "build:clean": "rimraf dist/ .parcel-cache/",
42
- "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 ",
43
32
  "lint": "eslint .",
44
- "test": "jest --passWithNoTests --runInBand",
45
- "release": "semantic-release"
33
+ "format": "prettier --write .",
34
+ "test": "vitest",
35
+ "coverage": "vitest run --coverage --coverage.extension=.ts",
36
+ "release": "semantic-release",
37
+ "publish": "yarn build && npm publish --tag next"
46
38
  },
47
39
  "devDependencies": {
48
- "@commitlint/cli": "^16.2.1",
49
- "@commitlint/config-conventional": "^16.2.1",
50
- "@parcel/packager-ts": "^2.5.0",
51
- "@parcel/transformer-typescript-types": "^2.5.0",
40
+ "@commitlint/cli": "^19.5.0",
41
+ "@commitlint/config-conventional": "^19.5.0",
42
+ "@eslint/js": "^9.13.0",
43
+ "@fast-check/vitest": "^0.1.3",
44
+ "@microsoft/api-extractor": "^7.47.11",
52
45
  "@semantic-release/git": "^10.0.1",
53
- "@semantic-release/gitlab": "^9.3.0",
54
- "@semantic-release/npm": "^9.0.1",
55
- "@types/jest": "^27.5.1",
56
- "@typescript-eslint/eslint-plugin": "^5.26.0",
57
- "@typescript-eslint/parser": "^5.26.0",
58
- "buffer": "^6.0.3",
59
- "eslint": "^8.16.0",
60
- "eslint-config-prettier": "^8.4.0",
61
- "eslint-config-standard": "^16.0.3",
62
- "eslint-plugin-import": "^2.25.4",
63
- "eslint-plugin-node": "^11.1.0",
64
- "eslint-plugin-prettier": "^4.0.0",
65
- "eslint-plugin-promise": "^6.0.0",
66
- "husky": "^7.0.4",
67
- "jest": "^28.1.0",
68
- "lint-staged": "^12.3.4",
69
- "organize-imports-cli": "^0.9.0",
70
- "parcel": "^2.5.0",
71
- "prettier": "^2.6.2",
72
- "process": "^0.11.10",
73
- "rimraf": "^3.0.2",
74
- "semantic-release": "^19.0.2",
75
- "sirv-cli": "^2.0.2",
76
- "ts-jest": "^28.0.3",
77
- "typescript": "^4.7.2"
46
+ "@semantic-release/gitlab": "^13.2.1",
47
+ "@semantic-release/npm": "^12.0.1",
48
+ "@typescript-eslint/eslint-plugin": "^8.11.0",
49
+ "@typescript-eslint/parser": "^8.11.0",
50
+ "@vitest/coverage-v8": "2.1.3",
51
+ "eslint": "^9.13.0",
52
+ "eslint-config-prettier": "^9.1.0",
53
+ "eslint-plugin-prettier": "^5.2.1",
54
+ "fast-check": "^3.22.0",
55
+ "globals": "^15.11.0",
56
+ "husky": "^9.1.6",
57
+ "jsdom": "^25.0.1",
58
+ "lint-staged": "^15.2.10",
59
+ "organize-imports-cli": "^0.10.0",
60
+ "prettier": "^3.3.3",
61
+ "rimraf": "^6.0.1",
62
+ "semantic-release": "^24.1.3",
63
+ "typedoc": "^0.26.10",
64
+ "typedoc-plugin-markdown": "^4.2.9",
65
+ "typescript": "^5.6.3",
66
+ "typescript-eslint": "^8.11.0",
67
+ "vite": "^5.4.10",
68
+ "vitest": "^2.1.3"
78
69
  },
79
70
  "lint-staged": {
80
71
  "*.ts": [
@@ -86,9 +77,5 @@
86
77
  "extends": [
87
78
  "@commitlint/config-conventional"
88
79
  ]
89
- },
90
- "dependencies": {
91
- "jsx-pragmatic": "^2.0.22",
92
- "zoid": "^9.0.86"
93
80
  }
94
81
  }