@notabene/javascript-sdk 2.5.0 → 2.5.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.
- package/README.md +62 -2
- package/dist/notabene.cjs +1 -1
- package/dist/notabene.js +96 -95
- package/package.json +1 -1
- package/src/notabene.ts +2 -2
package/README.md
CHANGED
|
@@ -64,6 +64,7 @@ This library is the JavaScript SDK for loading the Notabene UX components in the
|
|
|
64
64
|
- [Field reference](#field-reference)
|
|
65
65
|
- [Locales](#locales)
|
|
66
66
|
- [License](#license)
|
|
67
|
+
- [Theming](#theming)
|
|
67
68
|
|
|
68
69
|
## Installation
|
|
69
70
|
|
|
@@ -198,6 +199,14 @@ To be notified of any validation errors use:
|
|
|
198
199
|
withdrawal.on('error',error => ...)
|
|
199
200
|
```
|
|
200
201
|
|
|
202
|
+
To be notified when the component is Ready:
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
withdrawal.on('ready', ({ type }) => {
|
|
206
|
+
console.log(type === 'ready');
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
201
210
|
Calling `on` returns a function that will allow you to cleanly unsubscribe.
|
|
202
211
|
|
|
203
212
|
```js
|
|
@@ -423,9 +432,43 @@ If any of the required parameters are missing the component will just show the N
|
|
|
423
432
|
If any error occurs, the `error` event is passed containing a message.
|
|
424
433
|
|
|
425
434
|
```ts
|
|
426
|
-
withdrawal.on('error',
|
|
435
|
+
withdrawal.on('error', (error) => ...)
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
An example error object.
|
|
439
|
+
|
|
440
|
+
```ts
|
|
441
|
+
type Error = {
|
|
442
|
+
type: CMType.Error;
|
|
443
|
+
message: string;
|
|
444
|
+
description: string;
|
|
445
|
+
identifier: ErrorIdentifierCode;
|
|
446
|
+
};
|
|
447
|
+
```
|
|
448
|
+
Errors can be handled in this way:
|
|
449
|
+
|
|
450
|
+
```ts
|
|
451
|
+
component.on('error', (error) => {
|
|
452
|
+
if (error.type === CMType.Error) {
|
|
453
|
+
switch (error.identifier) {
|
|
454
|
+
case ErrorIdentifierCode.SERVICE_UNAVAILABLE:
|
|
455
|
+
// handle the error
|
|
456
|
+
break;
|
|
457
|
+
//...
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
});
|
|
427
461
|
```
|
|
428
462
|
|
|
463
|
+
#### Error reference
|
|
464
|
+
|
|
465
|
+
| ErrorIdentifierCode | Description/Message | In Use |
|
|
466
|
+
|--------------------------|----------------------------------------------------------------------------------------------------------|---|
|
|
467
|
+
| SERVICE_UNAVAILABLE | The Notabene service is currently unavailable | ✅ |
|
|
468
|
+
| TOKEN_INVALID | Auth Token is Invalid | ✅ |
|
|
469
|
+
| WALLET_CONNECTION_FAILED | The connection to the wallet service failed, possibly due to network issues or unsupported wallet types. | ✅ |
|
|
470
|
+
| WALLET_NOT_SUPPORTED | The wallet used does not support the required functionality or blockchain. | |
|
|
471
|
+
|
|
429
472
|
## Transaction parameters
|
|
430
473
|
|
|
431
474
|
### Asset specification
|
|
@@ -493,7 +536,7 @@ const options: TransactionOptions = {
|
|
|
493
536
|
amountSubunits: '12344',
|
|
494
537
|
timeout: 86440,
|
|
495
538
|
},
|
|
496
|
-
fallbacks: [ProofTypes.Screenshot, ProofTypes.SelfDeclaration], // js ['screenshot','
|
|
539
|
+
fallbacks: [ProofTypes.Screenshot, ProofTypes.SelfDeclaration], // js ['screenshot','self-declaration']
|
|
497
540
|
deminimis: {
|
|
498
541
|
threshold: 1000,
|
|
499
542
|
currency: 'EUR',
|
|
@@ -729,6 +772,23 @@ const options: TransactionOptions = {
|
|
|
729
772
|
|
|
730
773
|
See [locales](src/locales.ts) for the list of supported locales.
|
|
731
774
|
|
|
775
|
+
## Theming
|
|
776
|
+
|
|
777
|
+
You can optionally theme the UI when creating an instance of `Notabene`
|
|
778
|
+
|
|
779
|
+
```js
|
|
780
|
+
const notabene = new Notabene({
|
|
781
|
+
nodeUrl: 'https://api.notabene.id',
|
|
782
|
+
authToken: 'YOUR_CUSTOMER_TOKEN',
|
|
783
|
+
theme: {
|
|
784
|
+
mode: 'light', // 'light', 'dark'
|
|
785
|
+
primaryColor: '#0a852d',
|
|
786
|
+
secondaryColor: '#f5f7fa',
|
|
787
|
+
fontFamily: 'Montserrat' // Google Fonts Supported
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
```
|
|
791
|
+
|
|
732
792
|
## [License](LICENSE.md)
|
|
733
793
|
|
|
734
794
|
MIT © Notabene Inc.
|
package/dist/notabene.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var L=Object.defineProperty;var A=(e,t,r)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var o=(e,t,r)=>A(e,typeof t!="symbol"?t+"":t,r);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var c=(e=>(e.PRIVATE="WALLET",e.VASP="VASP",e))(c||{}),m=(e=>(e.NATURAL="natural",e.LEGAL="legal",e.SELF="self",e))(m||{}),u=(e=>(e.EMPTY="empty",e.VERIFY="verify",e.PENDING="pending",e.VERIFIED="verified",e.BANNED="banned",e))(u||{}),E=(e=>(e.ALLOWED="allowed",e.PENDING="pending",e))(E||{}),p=(e=>(e.ASSET="asset",e.DESTINATION="destination",e.COUNTERPARTY="counterparty",e.AGENT="agent",e))(p||{}),a=(e=>(e.COMPLETE="complete",e.RESIZE="resize",e.RESULT="result",e.READY="ready",e.INVALID="invalid",e.ERROR="error",e.CANCEL="cancel",e))(a||{}),f=(e=>(e.SERVICE_UNAVAILABLE="SERVICE_UNAVAILABLE",e.WALLET_CONNECTION_FAILED="WALLET_CONNECTION_FAILED",e.WALLET_NOT_SUPPORTED="WALLET_NOT_SUPPORTED",e.TOKEN_INVALID="TOKEN_INVALID",e))(f||{}),d=(e=>(e.UPDATE="update",e.REQUEST_RESPONSE="requestResponse",e))(d||{}),v=(e=>(e.PENDING="pending",e.FAILED="rejected",e.FLAGGED="flagged",e.VERIFIED="verified",e))(v||{}),I=(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.BIP322="bip-322",e.BIP137_XPUB="xpub",e.TIP191="tip-191",e.ED25519="ed25519",e.MicroTransfer="microtransfer",e.Screenshot="screenshot",e.Connect="connect",e))(I||{});class N{constructor(){o(this,"listeners",new Map);o(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(t){this.port=t,this.port.onmessage=this.handleMessage,this.port.start()}on(t,r){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(r),()=>this.off(t,r)}off(t,r){const s=this.listeners.get(t);s&&(s.delete(r),s.size===0&&this.listeners.delete(t))}handleMessage(t){const r=t.data;if(typeof r=="object"&&r!==null&&"type"in r){const s=r.type,i=this.listeners.get(s);i&&i.forEach(n=>n(r))}}send(t){this.port&&this.port.postMessage(t)}}class g{constructor(t,r,s){o(this,"_url");o(this,"_value");o(this,"_options");o(this,"_errors",[]);o(this,"iframe");o(this,"eventManager");o(this,"modal");this._url=t,this._value=r,this._options=s,this.eventManager=new N,this.on(a.INVALID,i=>{i.type===a.INVALID&&(this._errors=i.errors,this._value=i.value)}),this.on(a.RESIZE,i=>{i.type===a.RESIZE&&this.iframe&&(this.iframe.style.height=`${i.height}px`)})}get url(){return this._url}get value(){return this._value}get options(){return this._options}get errors(){return this._errors}open(){document.location.href=this.url}mount(t){const r=document.querySelector(t);if(!r)throw new Error(`parentID ${t} not found`);this.embed(r)}embed(t,r=!1){var s,i;this.removeEmbed(),this.iframe=document.createElement("iframe"),this.iframe.src=this.url+(r?"":"&embedded=true"),this.iframe.allow="web-share; clipboard-write; hid; bluetooth;",this.iframe.style.width="100%",this.iframe.style.height="0px",this.iframe.style.border="none",this.iframe.style.overflow="hidden",this.iframe.scrolling="no",t.appendChild(this.iframe),window.addEventListener("message",n=>{var l,h;n.source===((l=this.iframe)==null?void 0:l.contentWindow)&&((h=this.eventManager)==null||h.setPort(n.ports[0]))}),(i=(s=this.iframe)==null?void 0:s.contentWindow)==null||i.focus()}removeEmbed(){this.iframe&&this.iframe.remove()}send(t){this.eventManager.send(t)}on(t,r){return this.eventManager.on(t,r)}off(t,r){this.eventManager.off(t,r)}update(t,r){this._value=t,r&&(this._options=r),this.send({type:d.UPDATE,value:t,options:this._options})}completion(){return new Promise((t,r)=>{let s,i,n;function l(){s&&s(),i&&i(),n&&n()}s=this.on(a.COMPLETE,h=>{t(h.response),l()}),i=this.on(a.CANCEL,()=>{r(new Error("User cancelled")),l()}),n=this.on("error",h=>{r(new Error(h.message)),l()})})}async openModal(){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);const t=this.on(a.CANCEL,()=>{this.closeModal()}),r=this.on(a.COMPLETE,()=>{this.closeModal()});return this.modal.showModal(),this.modal.addEventListener("click",()=>{this.closeModal()}),this.completion().finally(()=>{t(),r()})}closeModal(){var t;this.modal&&((t=this.modal)==null||t.close(),this.modal.remove(),this.modal=void 0)}async popup(){const t=window.open(this.url,"_blank","popup=true,width=600,height=600");window.addEventListener("message",i=>{var n;i.source===t&&(console.log("received message from popup",i.data),(n=this.eventManager)==null||n.setPort(i.ports[0]))});const r=this.on(a.CANCEL,()=>{t==null||t.close()}),s=this.on(a.COMPLETE,()=>{t==null||t.close()});return this.completion().finally(()=>{r(),s()})}}function w(e){return Object.entries(e).map(([t,r])=>{if(r==null)return;const s=encodeURIComponent(t),i=encodeURIComponent(typeof r=="object"?JSON.stringify(r):String(r));return`${s}=${i}`}).filter(t=>t!==void 0).join("&")}function _(e){const t=e.slice(1);return t?t.split("&").filter(Boolean).reduce((s,i)=>{const[n,l]=i.split("=");return n&&(s[decodeURIComponent(n)]=l?decodeURIComponent(l):""),s},{}):{}}class C{constructor(t){o(this,"nodeUrl");o(this,"authToken");o(this,"uxUrl");o(this,"theme");o(this,"locale");this.uxUrl=t.uxUrl||"https://connect.notabene.id",this.nodeUrl=t.nodeUrl,this.authToken=t.authToken,this.theme=t.theme,this.locale=t.locale}componentUrl(t,r,s,i){const n=new URL(this.uxUrl);n.pathname=t;const l=w({authToken:this.authToken,value:r,configuration:s});return n.hash=l,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),i&&(i.callback&&n.searchParams.set("callback_url",i.callback),i.redirectUri&&n.searchParams.set("redirect_uri",i.redirectUri)),n.toString()}createComponent(t,r,s,i){return new g(this.componentUrl(t,r,s,i),r,s)}createWithdrawalAssist(t,r,s){return this.createComponent("withdrawal-assist",t,r,s)}createConnectWallet(t,r,s){return this.createComponent("connect",t,r,s)}createDepositRequest(t,r,s){return this.createComponent("deposit-request",t,r,s)}createDepositAssist(t,r,s){return this.createComponent("deposit-assist",t,r,s)}}exports.AgentType=c;exports.CMType=a;exports.EmbeddedComponent=g;exports.ErrorIdentifierCode=f;exports.HMType=d;exports.PersonType=m;exports.ProofStatus=v;exports.ProofTypes=I;exports.Status=u;exports.VASPSearchControl=E;exports.ValidationSections=p;exports.decodeFragmentToObject=_;exports.default=C;
|
package/dist/notabene.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var c = Object.defineProperty;
|
|
2
|
-
var m = (
|
|
3
|
-
var o = (
|
|
4
|
-
var u = /* @__PURE__ */ ((
|
|
5
|
-
class
|
|
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.ALLOWED = "allowed", e.PENDING = "pending", e))(p || {}), v = /* @__PURE__ */ ((e) => (e.ASSET = "asset", e.DESTINATION = "destination", e.COUNTERPARTY = "counterparty", e.AGENT = "agent", e))(v || {}), 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 || {}), I = /* @__PURE__ */ ((e) => (e.SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE", e.WALLET_CONNECTION_FAILED = "WALLET_CONNECTION_FAILED", e.WALLET_NOT_SUPPORTED = "WALLET_NOT_SUPPORTED", e.TOKEN_INVALID = "TOKEN_INVALID", e))(I || {}), d = /* @__PURE__ */ ((e) => (e.UPDATE = "update", e.REQUEST_RESPONSE = "requestResponse", e))(d || {}), L = /* @__PURE__ */ ((e) => (e.PENDING = "pending", e.FAILED = "rejected", e.FLAGGED = "flagged", e.VERIFIED = "verified", e))(L || {}), 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.BIP322 = "bip-322", e.BIP137_XPUB = "xpub", e.TIP191 = "tip-191", e.ED25519 = "ed25519", e.MicroTransfer = "microtransfer", e.Screenshot = "screenshot", e.Connect = "connect", e))(g || {});
|
|
5
|
+
class A {
|
|
6
6
|
constructor() {
|
|
7
7
|
o(this, "listeners", /* @__PURE__ */ new Map());
|
|
8
8
|
o(this, "port");
|
|
@@ -16,8 +16,8 @@ class I {
|
|
|
16
16
|
*
|
|
17
17
|
* @param port - The MessagePort instance to use for communication
|
|
18
18
|
*/
|
|
19
|
-
setPort(
|
|
20
|
-
this.port =
|
|
19
|
+
setPort(t) {
|
|
20
|
+
this.port = t, this.port.onmessage = this.handleMessage, this.port.start();
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Registers a callback for a specific message type.
|
|
@@ -29,8 +29,8 @@ class I {
|
|
|
29
29
|
* @param callback - The callback function to execute when matching messages are received
|
|
30
30
|
|
|
31
31
|
*/
|
|
32
|
-
on(
|
|
33
|
-
return this.listeners.has(
|
|
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
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Removes a callback for a specific message type.
|
|
@@ -41,9 +41,9 @@ class I {
|
|
|
41
41
|
* @param messageType - The type of message to remove listener from
|
|
42
42
|
* @param callback - The callback function to remove
|
|
43
43
|
*/
|
|
44
|
-
off(
|
|
45
|
-
const
|
|
46
|
-
|
|
44
|
+
off(t, r) {
|
|
45
|
+
const s = this.listeners.get(t);
|
|
46
|
+
s && (s.delete(r), s.size === 0 && this.listeners.delete(t));
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Internal message handler for processing received messages.
|
|
@@ -53,28 +53,28 @@ class I {
|
|
|
53
53
|
*
|
|
54
54
|
* @param event - The message event containing the component message
|
|
55
55
|
*/
|
|
56
|
-
handleMessage(
|
|
57
|
-
const r =
|
|
56
|
+
handleMessage(t) {
|
|
57
|
+
const r = t.data;
|
|
58
58
|
if (typeof r == "object" && r !== null && "type" in r) {
|
|
59
|
-
const
|
|
60
|
-
|
|
59
|
+
const s = r.type, i = this.listeners.get(s);
|
|
60
|
+
i && i.forEach((n) => n(r));
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Sends a message through the message port
|
|
65
65
|
* @param message The host message to send
|
|
66
66
|
*/
|
|
67
|
-
send(
|
|
68
|
-
this.port && this.port.postMessage(
|
|
67
|
+
send(t) {
|
|
68
|
+
this.port && this.port.postMessage(t);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
class
|
|
71
|
+
class N {
|
|
72
72
|
/**
|
|
73
73
|
* Creates an instance of EmbeddedComponent.
|
|
74
74
|
* @param url - The URL of the embedded component
|
|
75
75
|
* @param value - The initial transaction value
|
|
76
76
|
*/
|
|
77
|
-
constructor(
|
|
77
|
+
constructor(t, r, s) {
|
|
78
78
|
o(this, "_url");
|
|
79
79
|
o(this, "_value");
|
|
80
80
|
o(this, "_options");
|
|
@@ -82,10 +82,10 @@ class C {
|
|
|
82
82
|
o(this, "iframe");
|
|
83
83
|
o(this, "eventManager");
|
|
84
84
|
o(this, "modal");
|
|
85
|
-
this._url =
|
|
86
|
-
|
|
87
|
-
}), this.on(h.RESIZE, (
|
|
88
|
-
|
|
85
|
+
this._url = t, this._value = r, this._options = s, this.eventManager = new A(), this.on(h.INVALID, (i) => {
|
|
86
|
+
i.type === h.INVALID && (this._errors = i.errors, this._value = i.value);
|
|
87
|
+
}), this.on(h.RESIZE, (i) => {
|
|
88
|
+
i.type === h.RESIZE && this.iframe && (this.iframe.style.height = `${i.height}px`);
|
|
89
89
|
});
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
@@ -119,21 +119,21 @@ class C {
|
|
|
119
119
|
* @param parentId - The ID of the parent element
|
|
120
120
|
* @throws Will throw an error if the parent element is not found
|
|
121
121
|
*/
|
|
122
|
-
mount(
|
|
123
|
-
const r = document.querySelector(
|
|
124
|
-
if (!r) throw new Error(`parentID ${
|
|
122
|
+
mount(t) {
|
|
123
|
+
const r = document.querySelector(t);
|
|
124
|
+
if (!r) throw new Error(`parentID ${t} not found`);
|
|
125
125
|
this.embed(r);
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Embeds the component into a parent element
|
|
129
129
|
* @param parent - The parent element to embed the component into
|
|
130
130
|
*/
|
|
131
|
-
embed(
|
|
132
|
-
var
|
|
133
|
-
this.removeEmbed(), this.iframe = document.createElement("iframe"), this.iframe.src = this.url + (r ? "" : "&embedded=true"), this.iframe.allow = "web-share; clipboard-write; hid; bluetooth;", this.iframe.style.width = "100%", this.iframe.style.height = "0px", this.iframe.style.border = "none", this.iframe.style.overflow = "hidden", this.iframe.scrolling = "no",
|
|
131
|
+
embed(t, r = !1) {
|
|
132
|
+
var s, i;
|
|
133
|
+
this.removeEmbed(), this.iframe = document.createElement("iframe"), this.iframe.src = this.url + (r ? "" : "&embedded=true"), this.iframe.allow = "web-share; clipboard-write; hid; bluetooth;", this.iframe.style.width = "100%", this.iframe.style.height = "0px", this.iframe.style.border = "none", this.iframe.style.overflow = "hidden", this.iframe.scrolling = "no", t.appendChild(this.iframe), window.addEventListener("message", (n) => {
|
|
134
134
|
var a, l;
|
|
135
135
|
n.source === ((a = this.iframe) == null ? void 0 : a.contentWindow) && ((l = this.eventManager) == null || l.setPort(n.ports[0]));
|
|
136
|
-
}), (
|
|
136
|
+
}), (i = (s = this.iframe) == null ? void 0 : s.contentWindow) == null || i.focus();
|
|
137
137
|
}
|
|
138
138
|
removeEmbed() {
|
|
139
139
|
this.iframe && this.iframe.remove();
|
|
@@ -142,45 +142,45 @@ class C {
|
|
|
142
142
|
* Sends a message to the embedded component
|
|
143
143
|
* @param message - The message to send
|
|
144
144
|
*/
|
|
145
|
-
send(
|
|
146
|
-
this.eventManager.send(
|
|
145
|
+
send(t) {
|
|
146
|
+
this.eventManager.send(t);
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
149
|
* Adds an event listener for a specific message type
|
|
150
150
|
* @param messageType - The type of message to listen for
|
|
151
151
|
* @param callback - The callback function to execute when the message is received
|
|
152
152
|
*/
|
|
153
|
-
on(
|
|
154
|
-
return this.eventManager.on(
|
|
153
|
+
on(t, r) {
|
|
154
|
+
return this.eventManager.on(t, r);
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
157
|
* Removes an event listener for a specific message type
|
|
158
158
|
* @param messageType - The type of message to stop listening for
|
|
159
159
|
* @param callback - The callback function to remove
|
|
160
160
|
*/
|
|
161
|
-
off(
|
|
162
|
-
this.eventManager.off(
|
|
161
|
+
off(t, r) {
|
|
162
|
+
this.eventManager.off(t, r);
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
165
|
* Updates the transaction value and sends an update message to the component
|
|
166
166
|
* @param value - The new transaction value
|
|
167
167
|
*/
|
|
168
|
-
update(
|
|
169
|
-
this._value =
|
|
168
|
+
update(t, r) {
|
|
169
|
+
this._value = t, r && (this._options = r), this.send({ type: d.UPDATE, value: t, options: this._options });
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
172
172
|
* Waits for the component to complete and returns the transaction response
|
|
173
173
|
* @returns A promise that resolves with the transaction response
|
|
174
174
|
*/
|
|
175
175
|
completion() {
|
|
176
|
-
return new Promise((
|
|
177
|
-
let
|
|
176
|
+
return new Promise((t, r) => {
|
|
177
|
+
let s, i, n;
|
|
178
178
|
function a() {
|
|
179
|
-
|
|
179
|
+
s && s(), i && i(), n && n();
|
|
180
180
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}),
|
|
181
|
+
s = this.on(h.COMPLETE, (l) => {
|
|
182
|
+
t(l.response), a();
|
|
183
|
+
}), i = this.on(h.CANCEL, () => {
|
|
184
184
|
r(new Error("User cancelled")), a();
|
|
185
185
|
}), n = this.on("error", (l) => {
|
|
186
186
|
r(new Error(l.message)), a();
|
|
@@ -192,7 +192,7 @@ class C {
|
|
|
192
192
|
*/
|
|
193
193
|
async openModal() {
|
|
194
194
|
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);
|
|
195
|
-
const
|
|
195
|
+
const t = this.on(h.CANCEL, () => {
|
|
196
196
|
this.closeModal();
|
|
197
197
|
}), r = this.on(h.COMPLETE, () => {
|
|
198
198
|
this.closeModal();
|
|
@@ -200,7 +200,7 @@ class C {
|
|
|
200
200
|
return this.modal.showModal(), this.modal.addEventListener("click", () => {
|
|
201
201
|
this.closeModal();
|
|
202
202
|
}), this.completion().finally(() => {
|
|
203
|
-
|
|
203
|
+
t(), r();
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
@@ -208,8 +208,8 @@ class C {
|
|
|
208
208
|
*
|
|
209
209
|
*/
|
|
210
210
|
closeModal() {
|
|
211
|
-
var
|
|
212
|
-
this.modal && ((
|
|
211
|
+
var t;
|
|
212
|
+
this.modal && ((t = this.modal) == null || t.close(), this.modal.remove(), this.modal = void 0);
|
|
213
213
|
}
|
|
214
214
|
/**
|
|
215
215
|
* Opens the component in a popup window. This may be needed to support many self-hosted wallets
|
|
@@ -218,58 +218,58 @@ class C {
|
|
|
218
218
|
* @see [Cross-Origin-Opener-Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy)
|
|
219
219
|
*/
|
|
220
220
|
async popup() {
|
|
221
|
-
const
|
|
221
|
+
const t = window.open(
|
|
222
222
|
this.url,
|
|
223
223
|
"_blank",
|
|
224
224
|
"popup=true,width=600,height=600"
|
|
225
225
|
);
|
|
226
|
-
window.addEventListener("message", (
|
|
226
|
+
window.addEventListener("message", (i) => {
|
|
227
227
|
var n;
|
|
228
|
-
|
|
228
|
+
i.source === t && (console.log("received message from popup", i.data), (n = this.eventManager) == null || n.setPort(i.ports[0]));
|
|
229
229
|
});
|
|
230
230
|
const r = this.on(h.CANCEL, () => {
|
|
231
|
-
|
|
232
|
-
}),
|
|
233
|
-
|
|
231
|
+
t == null || t.close();
|
|
232
|
+
}), s = this.on(h.COMPLETE, () => {
|
|
233
|
+
t == null || t.close();
|
|
234
234
|
});
|
|
235
235
|
return this.completion().finally(() => {
|
|
236
|
-
r(),
|
|
236
|
+
r(), s();
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
function
|
|
241
|
-
return Object.entries(
|
|
240
|
+
function w(e) {
|
|
241
|
+
return Object.entries(e).map(([t, r]) => {
|
|
242
242
|
if (r == null) return;
|
|
243
|
-
const
|
|
243
|
+
const s = encodeURIComponent(t), i = encodeURIComponent(
|
|
244
244
|
typeof r == "object" ? JSON.stringify(r) : String(r)
|
|
245
245
|
// Use String() to handle all primitive types
|
|
246
246
|
);
|
|
247
|
-
return `${
|
|
248
|
-
}).filter((
|
|
247
|
+
return `${s}=${i}`;
|
|
248
|
+
}).filter((t) => t !== void 0).join("&");
|
|
249
249
|
}
|
|
250
|
-
function
|
|
251
|
-
const
|
|
252
|
-
return
|
|
253
|
-
(
|
|
254
|
-
const [n, a] =
|
|
255
|
-
return n && (
|
|
250
|
+
function U(e) {
|
|
251
|
+
const t = e.slice(1);
|
|
252
|
+
return t ? t.split("&").filter(Boolean).reduce(
|
|
253
|
+
(s, i) => {
|
|
254
|
+
const [n, a] = i.split("=");
|
|
255
|
+
return n && (s[decodeURIComponent(n)] = a ? decodeURIComponent(a) : ""), s;
|
|
256
256
|
},
|
|
257
257
|
{}
|
|
258
258
|
) : {};
|
|
259
259
|
}
|
|
260
|
-
class
|
|
260
|
+
class C {
|
|
261
261
|
/**
|
|
262
262
|
* Creates a new instance of the Notabene SDK
|
|
263
263
|
*
|
|
264
264
|
* @param config - Configuration options for the Notabene SDK
|
|
265
265
|
*/
|
|
266
|
-
constructor(
|
|
266
|
+
constructor(t) {
|
|
267
267
|
o(this, "nodeUrl");
|
|
268
268
|
o(this, "authToken");
|
|
269
269
|
o(this, "uxUrl");
|
|
270
270
|
o(this, "theme");
|
|
271
271
|
o(this, "locale");
|
|
272
|
-
this.uxUrl =
|
|
272
|
+
this.uxUrl = t.uxUrl || "https://connect.notabene.id", this.nodeUrl = t.nodeUrl, this.authToken = t.authToken, this.theme = t.theme, this.locale = t.locale;
|
|
273
273
|
}
|
|
274
274
|
/**
|
|
275
275
|
* Generates a URL for a Notabene component
|
|
@@ -281,15 +281,15 @@ class A {
|
|
|
281
281
|
* @returns component URL
|
|
282
282
|
* @internal
|
|
283
283
|
*/
|
|
284
|
-
componentUrl(
|
|
284
|
+
componentUrl(t, r, s, i) {
|
|
285
285
|
const n = new URL(this.uxUrl);
|
|
286
|
-
n.pathname =
|
|
287
|
-
const a =
|
|
286
|
+
n.pathname = t;
|
|
287
|
+
const a = w({
|
|
288
288
|
authToken: this.authToken,
|
|
289
289
|
value: r,
|
|
290
|
-
configuration:
|
|
290
|
+
configuration: s
|
|
291
291
|
});
|
|
292
|
-
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),
|
|
292
|
+
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), i && (i.callback && n.searchParams.set("callback_url", i.callback), i.redirectUri && n.searchParams.set("redirect_uri", i.redirectUri)), n.toString();
|
|
293
293
|
}
|
|
294
294
|
/**
|
|
295
295
|
* Creates a new embedded component
|
|
@@ -301,11 +301,11 @@ class A {
|
|
|
301
301
|
* @returns A new EmbeddedComponent instance
|
|
302
302
|
* @internal
|
|
303
303
|
*/
|
|
304
|
-
createComponent(
|
|
305
|
-
return new
|
|
306
|
-
this.componentUrl(
|
|
304
|
+
createComponent(t, r, s, i) {
|
|
305
|
+
return new N(
|
|
306
|
+
this.componentUrl(t, r, s, i),
|
|
307
307
|
r,
|
|
308
|
-
|
|
308
|
+
s
|
|
309
309
|
);
|
|
310
310
|
}
|
|
311
311
|
/**
|
|
@@ -316,12 +316,12 @@ class A {
|
|
|
316
316
|
* @param callbacks - Optional callback configuration
|
|
317
317
|
* @returns A new EmbeddedComponent instance for withdrawal assistance
|
|
318
318
|
*/
|
|
319
|
-
createWithdrawalAssist(
|
|
319
|
+
createWithdrawalAssist(t, r, s) {
|
|
320
320
|
return this.createComponent(
|
|
321
321
|
"withdrawal-assist",
|
|
322
|
-
|
|
322
|
+
t,
|
|
323
323
|
r,
|
|
324
|
-
|
|
324
|
+
s
|
|
325
325
|
);
|
|
326
326
|
}
|
|
327
327
|
/**
|
|
@@ -333,12 +333,12 @@ class A {
|
|
|
333
333
|
* @returns A new EmbeddedComponent instance for connection
|
|
334
334
|
* @alpha
|
|
335
335
|
*/
|
|
336
|
-
createConnectWallet(
|
|
336
|
+
createConnectWallet(t, r, s) {
|
|
337
337
|
return this.createComponent(
|
|
338
338
|
"connect",
|
|
339
|
-
|
|
339
|
+
t,
|
|
340
340
|
r,
|
|
341
|
-
|
|
341
|
+
s
|
|
342
342
|
);
|
|
343
343
|
}
|
|
344
344
|
/**
|
|
@@ -350,12 +350,12 @@ class A {
|
|
|
350
350
|
* @returns A new EmbeddedComponent instance for deposit requests
|
|
351
351
|
* @public
|
|
352
352
|
*/
|
|
353
|
-
createDepositRequest(
|
|
353
|
+
createDepositRequest(t, r, s) {
|
|
354
354
|
return this.createComponent(
|
|
355
355
|
"deposit-request",
|
|
356
|
-
|
|
356
|
+
t,
|
|
357
357
|
r,
|
|
358
|
-
|
|
358
|
+
s
|
|
359
359
|
);
|
|
360
360
|
}
|
|
361
361
|
/**
|
|
@@ -367,26 +367,27 @@ class A {
|
|
|
367
367
|
* @returns A new EmbeddedComponent instance for deposit assistance
|
|
368
368
|
* @public
|
|
369
369
|
*/
|
|
370
|
-
createDepositAssist(
|
|
370
|
+
createDepositAssist(t, r, s) {
|
|
371
371
|
return this.createComponent(
|
|
372
372
|
"deposit-assist",
|
|
373
|
-
|
|
373
|
+
t,
|
|
374
374
|
r,
|
|
375
|
-
|
|
375
|
+
s
|
|
376
376
|
);
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
379
|
export {
|
|
380
380
|
u as AgentType,
|
|
381
381
|
h as CMType,
|
|
382
|
-
|
|
382
|
+
N as EmbeddedComponent,
|
|
383
|
+
I as ErrorIdentifierCode,
|
|
383
384
|
d as HMType,
|
|
384
385
|
E as PersonType,
|
|
385
|
-
|
|
386
|
-
|
|
386
|
+
L as ProofStatus,
|
|
387
|
+
g as ProofTypes,
|
|
387
388
|
f as Status,
|
|
388
389
|
p as VASPSearchControl,
|
|
389
390
|
v as ValidationSections,
|
|
390
|
-
|
|
391
|
-
|
|
391
|
+
U as decodeFragmentToObject,
|
|
392
|
+
C as default
|
|
392
393
|
};
|
package/package.json
CHANGED
package/src/notabene.ts
CHANGED
|
@@ -22,7 +22,6 @@ import type {
|
|
|
22
22
|
DID,
|
|
23
23
|
DTI,
|
|
24
24
|
Error,
|
|
25
|
-
ErrorIdentifierCode,
|
|
26
25
|
FieldTypes,
|
|
27
26
|
HostMessage,
|
|
28
27
|
InvalidValue,
|
|
@@ -56,6 +55,7 @@ import type {
|
|
|
56
55
|
import {
|
|
57
56
|
AgentType,
|
|
58
57
|
CMType,
|
|
58
|
+
ErrorIdentifierCode,
|
|
59
59
|
HMType,
|
|
60
60
|
PersonType,
|
|
61
61
|
ProofStatus,
|
|
@@ -72,6 +72,7 @@ export {
|
|
|
72
72
|
AgentType,
|
|
73
73
|
CMType,
|
|
74
74
|
decodeFragmentToObject,
|
|
75
|
+
ErrorIdentifierCode,
|
|
75
76
|
HMType,
|
|
76
77
|
PersonType,
|
|
77
78
|
ProofStatus,
|
|
@@ -101,7 +102,6 @@ export type {
|
|
|
101
102
|
DID,
|
|
102
103
|
DTI,
|
|
103
104
|
Error,
|
|
104
|
-
ErrorIdentifierCode,
|
|
105
105
|
FieldTypes,
|
|
106
106
|
HostMessage,
|
|
107
107
|
InvalidValue,
|