@notabene/javascript-sdk 2.0.0-next.11 → 2.0.0-next.12
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 +2 -0
- package/dist/notabene.cjs +1 -1
- package/dist/notabene.d.ts +4 -1
- package/dist/notabene.js +17 -17
- package/package.json +1 -1
- package/src/components/EmbeddedComponent.ts +3 -2
- package/src/types.ts +4 -1
package/README.md
CHANGED
|
@@ -258,6 +258,7 @@ const options: TransactionOptions = {
|
|
|
258
258
|
proofs: {
|
|
259
259
|
microTransfer: {
|
|
260
260
|
destination: '0x...',
|
|
261
|
+
amountSubunits: '12344',
|
|
261
262
|
timeout: 86440,
|
|
262
263
|
},
|
|
263
264
|
fallbacks: [ProofTypes.Screenshot, ProofTypes.SelfDeclaration],
|
|
@@ -339,6 +340,7 @@ const options: TransactionOptions = {
|
|
|
339
340
|
proofs: {
|
|
340
341
|
microTransfer: {
|
|
341
342
|
destination: '0x...',
|
|
343
|
+
amountSubunits: '1234',
|
|
342
344
|
timeout: 86440, // Optional timeout in seconds, which is displayed to the user
|
|
343
345
|
},
|
|
344
346
|
fallbacks: [ProofTypes.Screenshot, ProofTypes.SelfDeclaration],
|
package/dist/notabene.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var c=(
|
|
1
|
+
"use strict";var d=Object.defineProperty;var c=(o,e,t)=>e in o?d(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var n=(o,e,t)=>c(o,typeof e!="symbol"?e+"":e,t);var a=(o=>(o.COMPLETE="complete",o.RESIZE="resize",o.RESULT="result",o.READY="ready",o.INVALID="invalid",o.MODAL="openModal",o.ERROR="error",o.CLOSE="closeModal",o.CANCEL="cancel",o))(a||{}),l=(o=>(o.UPDATE="update",o.REQUEST_RESPONSE="requestResponse",o))(l||{});class m{constructor(){n(this,"listeners",new Map);n(this,"port");this.handleMessage=this.handleMessage.bind(this)}setPort(e){this.port=e,this.port.onmessage=this.handleMessage,this.port.start()}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){const s=this.listeners.get(e);s&&(s.delete(t),s.size===0&&this.listeners.delete(e))}handleMessage(e){console.log("received message",e.data);const t=e.data;if(typeof t=="object"&&t!==null&&"type"in t){const s=t.type,r=this.listeners.get(s);r&&r.forEach(i=>i(t))}}send(e){this.port&&this.port.postMessage(e)}}class u{constructor(e,t){n(this,"_url");n(this,"_value");n(this,"_errors",[]);n(this,"iframe");n(this,"eventManager");n(this,"modal");this._url=e,this._value=t,this.eventManager=new m,this.on(a.INVALID,s=>{s.type===a.INVALID&&(this._errors=s.errors,this._value=s.value)}),this.on(a.RESIZE,s=>{s.type===a.RESIZE&&this.iframe&&(this.iframe.style.height=`${s.height}px`)})}get url(){return this._url}get value(){return this._value}get errors(){return this._errors}open(){document.location.href=this.url}mount(e){const t=document.querySelector(e);if(!t)throw new Error(`parentID ${e} not found`);this.embed(t)}embed(e){var t,s;this.iframe=document.createElement("iframe"),this.iframe.src=this.url,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",e.appendChild(this.iframe),window.addEventListener("message",r=>{var i,h;r.source===((i=this.iframe)==null?void 0:i.contentWindow)&&(console.log("received message from iframe",r.data),(h=this.eventManager)==null||h.setPort(r.ports[0]))}),(s=(t=this.iframe)==null?void 0:t.contentWindow)==null||s.focus()}send(e){this.eventManager.send(e)}on(e,t){this.eventManager.on(e,t)}off(e,t){this.eventManager.off(e,t)}update(e){this._value=e,this.send({type:l.UPDATE,value:e})}completion(){return new Promise((e,t)=>{this.on(a.COMPLETE,s=>{e(s.response)}),this.on("error",s=>{t(new Error(s.message))})})}openModal(){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,()=>{this.closeModal()}),this.on(a.CLOSE,()=>{this.closeModal()}),this.on(a.COMPLETE,()=>{this.closeModal()}),this.modal.showModal(),this.modal.addEventListener("click",()=>{this.closeModal()}),this.completion()}closeModal(){var e;this.modal&&(console.log("closeModal"),(e=this.modal)==null||e.close(),this.modal.remove(),this.modal=void 0)}}function f(o){return Object.entries(o).map(([e,t])=>{if(!(e&&t))return;const s=encodeURIComponent(e),r=encodeURIComponent(typeof t=="object"?JSON.stringify(t):t);return`${s}=${r}`}).filter(e=>!!e).join("&")}class p{constructor(e){n(this,"nodeUrl");n(this,"authToken");n(this,"uxUrl");n(this,"theme");n(this,"locale");this.uxUrl=e.uxUrl||"https://connect.notabene.id",this.nodeUrl=e.nodeUrl,this.authToken=e.authToken,this.theme=e.theme,this.locale=e.locale}componentUrl(e,t,s,r){const i=new URL(this.uxUrl);i.pathname=e;const h=f({authToken:this.authToken,value:t,configuration:s});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),r&&(r.callback&&i.searchParams.set("callback_url",r.callback),r.redirectUri&&i.searchParams.set("redirect_uri",r.redirectUri)),i.toString()}createComponent(e,t,s,r){return new u(this.componentUrl(e,t,s,r),t)}createWithdrawalAssist(e,t,s){return this.createComponent("withdrawal-assist",e,t,s)}createDepositAssist(e,t,s){return this.createComponent("deposit-assist",e,t,s)}createConnectWallet(e,t,s){return this.createComponent("connect",e,t,s)}createDepositRequest(e,t,s){return this.createComponent("deposit-request",e,t,s)}decodeFragmentToObject(e){return e.slice(1).split("&").reduce((s,r)=>{const[i,h]=r.split("=");return s[decodeURIComponent(i)]=decodeURIComponent(h),s},{})}}module.exports=p;
|
package/dist/notabene.d.ts
CHANGED
|
@@ -276,7 +276,9 @@ export declare interface DepositRequest extends DepositRequestFields, Transactio
|
|
|
276
276
|
* @public
|
|
277
277
|
*/
|
|
278
278
|
declare type DepositRequestFields = {
|
|
279
|
-
|
|
279
|
+
destination: BlockchainAddress | CAIP10;
|
|
280
|
+
travelAddress?: TravelAddress;
|
|
281
|
+
cryptoCredential?: CryptoCredential;
|
|
280
282
|
};
|
|
281
283
|
|
|
282
284
|
/**
|
|
@@ -1014,6 +1016,7 @@ export declare interface TransactionOptions {
|
|
|
1014
1016
|
proofs?: {
|
|
1015
1017
|
microTransfer?: {
|
|
1016
1018
|
destination: BlockchainAddress;
|
|
1019
|
+
amountSubunits: string;
|
|
1017
1020
|
timeout?: number;
|
|
1018
1021
|
};
|
|
1019
1022
|
fallbacks?: ProofTypes[];
|
package/dist/notabene.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
|
-
var c = (
|
|
3
|
-
var n = (
|
|
4
|
-
var a = /* @__PURE__ */ ((
|
|
2
|
+
var c = (o, e, t) => e in o ? d(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
3
|
+
var n = (o, e, t) => c(o, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
var a = /* @__PURE__ */ ((o) => (o.COMPLETE = "complete", o.RESIZE = "resize", o.RESULT = "result", o.READY = "ready", o.INVALID = "invalid", o.MODAL = "openModal", o.ERROR = "error", o.CLOSE = "closeModal", o.CANCEL = "cancel", o))(a || {}), l = /* @__PURE__ */ ((o) => (o.UPDATE = "update", o.REQUEST_RESPONSE = "requestResponse", o))(l || {});
|
|
5
5
|
class m {
|
|
6
6
|
constructor() {
|
|
7
7
|
n(this, "listeners", /* @__PURE__ */ new Map());
|
|
@@ -22,8 +22,8 @@ class m {
|
|
|
22
22
|
console.log("received message", e.data);
|
|
23
23
|
const t = e.data;
|
|
24
24
|
if (typeof t == "object" && t !== null && "type" in t) {
|
|
25
|
-
const s = t.type,
|
|
26
|
-
|
|
25
|
+
const s = t.type, r = this.listeners.get(s);
|
|
26
|
+
r && r.forEach((i) => i(t));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
// Method to send messages through the port
|
|
@@ -89,9 +89,9 @@ class u {
|
|
|
89
89
|
*/
|
|
90
90
|
embed(e) {
|
|
91
91
|
var t, s;
|
|
92
|
-
this.iframe = document.createElement("iframe"), this.iframe.src = this.url, this.iframe.
|
|
92
|
+
this.iframe = document.createElement("iframe"), this.iframe.src = this.url, 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", e.appendChild(this.iframe), window.addEventListener("message", (r) => {
|
|
93
93
|
var i, h;
|
|
94
|
-
|
|
94
|
+
r.source === ((i = this.iframe) == null ? void 0 : i.contentWindow) && (console.log("received message from iframe", r.data), (h = this.eventManager) == null || h.setPort(r.ports[0]));
|
|
95
95
|
}), (s = (t = this.iframe) == null ? void 0 : t.contentWindow) == null || s.focus();
|
|
96
96
|
}
|
|
97
97
|
/**
|
|
@@ -160,13 +160,13 @@ class u {
|
|
|
160
160
|
this.modal && (console.log("closeModal"), (e = this.modal) == null || e.close(), this.modal.remove(), this.modal = void 0);
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
function f(
|
|
164
|
-
return Object.entries(
|
|
163
|
+
function f(o) {
|
|
164
|
+
return Object.entries(o).map(([e, t]) => {
|
|
165
165
|
if (!(e && t)) return;
|
|
166
|
-
const s = encodeURIComponent(e),
|
|
166
|
+
const s = encodeURIComponent(e), r = encodeURIComponent(
|
|
167
167
|
typeof t == "object" ? JSON.stringify(t) : t
|
|
168
168
|
);
|
|
169
|
-
return `${s}=${
|
|
169
|
+
return `${s}=${r}`;
|
|
170
170
|
}).filter((e) => !!e).join("&");
|
|
171
171
|
}
|
|
172
172
|
class E {
|
|
@@ -193,7 +193,7 @@ class E {
|
|
|
193
193
|
* @returns component URL
|
|
194
194
|
* @internal
|
|
195
195
|
*/
|
|
196
|
-
componentUrl(e, t, s,
|
|
196
|
+
componentUrl(e, t, s, r) {
|
|
197
197
|
const i = new URL(this.uxUrl);
|
|
198
198
|
i.pathname = e;
|
|
199
199
|
const h = f({
|
|
@@ -201,7 +201,7 @@ class E {
|
|
|
201
201
|
value: t,
|
|
202
202
|
configuration: s
|
|
203
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),
|
|
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), r && (r.callback && i.searchParams.set("callback_url", r.callback), r.redirectUri && i.searchParams.set("redirect_uri", r.redirectUri)), i.toString();
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
207
207
|
* Creates a new embedded component
|
|
@@ -213,9 +213,9 @@ class E {
|
|
|
213
213
|
* @returns A new EmbeddedComponent instance
|
|
214
214
|
* @internal
|
|
215
215
|
*/
|
|
216
|
-
createComponent(e, t, s,
|
|
216
|
+
createComponent(e, t, s, r) {
|
|
217
217
|
return new u(
|
|
218
|
-
this.componentUrl(e, t, s,
|
|
218
|
+
this.componentUrl(e, t, s, r),
|
|
219
219
|
t
|
|
220
220
|
);
|
|
221
221
|
}
|
|
@@ -283,8 +283,8 @@ class E {
|
|
|
283
283
|
*/
|
|
284
284
|
decodeFragmentToObject(e) {
|
|
285
285
|
return e.slice(1).split("&").reduce(
|
|
286
|
-
(s,
|
|
287
|
-
const [i, h] =
|
|
286
|
+
(s, r) => {
|
|
287
|
+
const [i, h] = r.split("=");
|
|
288
288
|
return s[decodeURIComponent(i)] = decodeURIComponent(h), s;
|
|
289
289
|
},
|
|
290
290
|
{}
|
package/package.json
CHANGED
|
@@ -94,12 +94,13 @@ export default class EmbeddedComponent<V, R> {
|
|
|
94
94
|
embed(parent: Element) {
|
|
95
95
|
this.iframe = document.createElement('iframe');
|
|
96
96
|
this.iframe.src = this.url;
|
|
97
|
+
this.iframe.allow = 'web-share';
|
|
97
98
|
this.iframe.style.width = '100%';
|
|
98
99
|
this.iframe.style.height = '100px';
|
|
99
100
|
this.iframe.style.border = 'none';
|
|
100
101
|
this.iframe.style.overflow = 'hidden';
|
|
101
|
-
this.iframe.setAttribute('allowtransparency', 'true');
|
|
102
|
-
this.iframe.style.backgroundColor = 'transparent';
|
|
102
|
+
// this.iframe.setAttribute('allowtransparency', 'true');
|
|
103
|
+
// this.iframe.style.backgroundColor = 'transparent';
|
|
103
104
|
parent.appendChild(this.iframe);
|
|
104
105
|
|
|
105
106
|
window.addEventListener('message', (event: MessageEvent) => {
|
package/src/types.ts
CHANGED
|
@@ -296,7 +296,9 @@ type BeneficiaryFields = {
|
|
|
296
296
|
* @public
|
|
297
297
|
*/
|
|
298
298
|
type DepositRequestFields = {
|
|
299
|
-
|
|
299
|
+
destination: BlockchainAddress | CAIP10;
|
|
300
|
+
travelAddress?: TravelAddress;
|
|
301
|
+
cryptoCredential?: CryptoCredential;
|
|
300
302
|
};
|
|
301
303
|
|
|
302
304
|
type RequestID = UUID;
|
|
@@ -440,6 +442,7 @@ export interface TransactionOptions {
|
|
|
440
442
|
proofs?: {
|
|
441
443
|
microTransfer?: {
|
|
442
444
|
destination: BlockchainAddress;
|
|
445
|
+
amountSubunits: string;
|
|
443
446
|
timeout?: number; // Time to verify in seconds
|
|
444
447
|
};
|
|
445
448
|
fallbacks?: ProofTypes[];
|