@leaflink/stash 48.5.0 → 48.6.0

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/dist/PlaidLink.js CHANGED
@@ -1,6 +1,8 @@
1
- import { defineComponent as y, computed as E, ref as p, openBlock as S, createElementBlock as h, renderSlot as x } from "vue";
2
- import l from "@leaflink/snitch";
3
- const _ = /* @__PURE__ */ y({
1
+ import { defineComponent as m, computed as y, ref as c, openBlock as h, createElementBlock as E, renderSlot as w } from "vue";
2
+ import i from "@leaflink/snitch";
3
+ import x from "./usePlaidLink.js";
4
+ import "./useScriptTag.js";
5
+ const L = /* @__PURE__ */ m({
4
6
  __name: "PlaidLink",
5
7
  props: {
6
8
  initScriptUrl: { default: "https://cdn.plaid.com/link/v2/stable/link-initialize.js" },
@@ -11,67 +13,58 @@ const _ = /* @__PURE__ */ y({
11
13
  createToken: { type: Function, default: void 0 }
12
14
  },
13
15
  emits: ["error", "success", "exit", "load", "event"],
14
- setup(v, { expose: f, emit: n }) {
15
- const t = v, s = E(() => t.storageKey ? t.storageKey : `${window.location.host.split(".").splice(-3).join(".")}-plaid`), i = p(""), a = p(!1), k = (e, r) => {
16
- a.value = !1, e && (l.error(new Error("Plaid: Error trying to link an account"), {
16
+ setup(u, { expose: d, emit: n }) {
17
+ const o = u, s = y(() => o.storageKey ? o.storageKey : `${window.location.host.split(".").splice(-3).join(".")}-plaid`), r = c(!1), p = (e, t) => {
18
+ r.value = !1, e && (i.error(new Error("Plaid: Error trying to link an account"), {
17
19
  tags: { plaid: !0 },
18
20
  extra: { PlaidError: e }
19
- }), n("error", e, r)), sessionStorage.removeItem(s.value), n("exit", r);
20
- }, g = (e, r) => {
21
- a.value = !1, sessionStorage.removeItem(s.value), n("success", e, r);
22
- }, m = (...e) => n("load", ...e), w = (...e) => n("event", ...e);
23
- async function c() {
24
- if (a.value !== !0) {
25
- if (a.value = !0, typeof t.createToken == "function")
21
+ }), n("error", e, t)), sessionStorage.removeItem(s.value), n("exit", t);
22
+ }, f = (e, t) => {
23
+ r.value = !1, sessionStorage.removeItem(s.value), n("success", e, t);
24
+ }, k = (...e) => n("load", ...e), v = (...e) => n("event", ...e), a = c({
25
+ env: o.env,
26
+ onSuccess: f,
27
+ onEvent: v,
28
+ onLoad: k,
29
+ onExit: p
30
+ }), { open: g } = x(a);
31
+ async function l() {
32
+ if (r.value !== !0) {
33
+ if (r.value = !0, typeof o.createToken == "function")
26
34
  try {
27
- const { link_token: e } = await t.createToken();
28
- i.value = e;
35
+ const { link_token: e } = await o.createToken();
36
+ a.value.token = e;
29
37
  } catch (e) {
30
- const r = new Error("Plaid: Error trying to invoke createToken");
31
- l.error(r, {
38
+ const t = new Error("Plaid: Error trying to invoke createToken");
39
+ i.error(t, {
32
40
  tags: { plaid: !0 },
33
41
  extra: { error: e }
34
- }), n("error", r);
42
+ }), n("error", t);
35
43
  }
36
44
  else
37
- t.token && (i.value = t.token);
38
- if (!i.value) {
45
+ o.token && (a.value.token = o.token);
46
+ if (!a.value.token) {
39
47
  const e = new Error("Plaid: link token not found");
40
- l.error(e, { tags: { plaid: !0 } }), n("error", e), a.value = !1;
48
+ i.error(e, { tags: { plaid: !0 } }), n("error", e), r.value = !1;
41
49
  return;
42
50
  }
43
51
  sessionStorage.setItem(
44
52
  s.value,
45
- JSON.stringify({ token: i.value, returnTo: t.returnTo, env: t.env })
46
- ), window.Plaid || await d(), window.Plaid.create({
47
- token: i.value,
48
- env: t.env,
49
- onExit: k,
50
- onSuccess: g,
51
- onEvent: w,
52
- onLoad: m
53
- }).open();
53
+ JSON.stringify({ token: a.value.token, returnTo: o.returnTo, env: o.env })
54
+ ), g();
54
55
  }
55
56
  }
56
- function d() {
57
- return new Promise(function(e, r) {
58
- const u = document.querySelector('script[src="' + t.initScriptUrl + '"]');
59
- u && u.remove();
60
- const o = document.createElement("script");
61
- o.type = "text/javascript", o.async = !0, o.src = t.initScriptUrl, o.addEventListener("load", () => e()), o.addEventListener("error", r), o.addEventListener("abort", r), document.head.appendChild(o);
62
- });
63
- }
64
- return d(), f({
65
- handleClick: c
66
- }), (e, r) => (S(), h("span", {
57
+ return d({
58
+ handleClick: l
59
+ }), (e, t) => (h(), E("span", {
67
60
  "data-test": "stash-plaid-link",
68
- onClick: c
61
+ onClick: l
69
62
  }, [
70
- x(e.$slots, "default", { open: a.value })
63
+ w(e.$slots, "default", { open: r.value })
71
64
  ]));
72
65
  }
73
66
  });
74
67
  export {
75
- _ as default
68
+ L as default
76
69
  };
77
70
  //# sourceMappingURL=PlaidLink.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PlaidLink.js","sources":["../src/components/PlaidLink/PlaidLink.vue"],"sourcesContent":["<script setup lang=\"ts\">\n import logger from '@leaflink/snitch';\n import { Plaid } from 'plaid-link';\n import { computed, ref } from 'vue';\n\n export interface LinkTokenResponse {\n link_token: string;\n /**\n * expiration date in ISO-8601 format\n */\n expiration: string;\n request_id: string;\n }\n\n export interface PlaidLinkProps {\n /**\n * Plaid initialization script url to be used\n */\n initScriptUrl?: string;\n\n /**\n * Key to be used in session storage for OAuth flow\n */\n storageKey?: string;\n\n /**\n * Url to be used to redirect the user from the OAuth flow\n */\n returnTo?: string;\n\n /**\n * Plaid link token\n */\n token?: string;\n\n /**\n * Plaid environment to connect\n */\n env?: Plaid.Environment;\n\n /**\n * Function that returns a link token object to be used with Plaid.\n * `link_token` takes precedence over `token` if informed.\n */\n createToken?: () => Promise<LinkTokenResponse>;\n }\n\n const props = withDefaults(defineProps<PlaidLinkProps>(), {\n initScriptUrl: 'https://cdn.plaid.com/link/v2/stable/link-initialize.js',\n storageKey: undefined,\n returnTo: window.location.href,\n env: 'sandbox',\n token: undefined,\n createToken: undefined,\n });\n\n const internalStorageKey = computed(() => {\n if (props.storageKey) {\n return props.storageKey;\n }\n\n // returns up to the last 3 parts of the host. e.g. for `subdomain.my.domain.com` it will return `my.domain.com`\n const host = window.location.host.split('.').splice(-3).join('.');\n\n return `${host}-plaid`;\n });\n\n const internalToken = ref('');\n\n const emit =\n defineEmits<{\n /**\n * Emitted whenever the exit event contains errors\n */\n (e: 'error', error: Plaid.Error | null | Error, metadata?: Plaid.OnExitMetaData): void;\n /**\n * Emitted whenever the user successfully links an item\n */\n (e: 'success', public_token: string, metadata: Plaid.OnSuccessMetaData): void;\n /**\n * Emitted whenever the user exits the Link flow\n */\n (e: 'exit', metadata: Plaid.OnExitMetaData): void;\n /**\n * Emitted when the Link is ready to be opened\n */\n (e: 'load'): void;\n /**\n * Emitted at specific points during the Link flow\n */\n (e: 'event', eventName: Plaid.EventName, metadata: Plaid.OnEventMetaData): void;\n }>();\n\n const isPlaidModalOpen = ref(false);\n\n const onExit: Plaid.OnExit = (error: Plaid.Error | null, metadata: Plaid.OnExitMetaData) => {\n isPlaidModalOpen.value = false;\n\n if (error) {\n logger.error(new Error('Plaid: Error trying to link an account'), {\n tags: { plaid: true },\n extra: { PlaidError: error },\n });\n emit('error', error, metadata);\n }\n\n sessionStorage.removeItem(internalStorageKey.value);\n\n emit('exit', metadata);\n };\n\n const onSuccess: Plaid.OnSuccess = (public_token: string, metadata: Plaid.OnSuccessMetaData) => {\n isPlaidModalOpen.value = false;\n\n sessionStorage.removeItem(internalStorageKey.value);\n\n emit('success', public_token, metadata);\n };\n\n const onLoad: Plaid.OnLoad = (...args) => emit('load', ...args);\n\n const onEvent: Plaid.OnEvent = (...args) => emit('event', ...args);\n\n async function handleClick() {\n if (isPlaidModalOpen.value === true) {\n return;\n }\n\n isPlaidModalOpen.value = true;\n\n if (typeof props.createToken === 'function') {\n try {\n const { link_token } = await props.createToken();\n\n internalToken.value = link_token;\n } catch (err) {\n const error = new Error('Plaid: Error trying to invoke createToken');\n\n logger.error(error, {\n tags: { plaid: true },\n extra: { error: err },\n });\n\n emit('error', error);\n }\n } else if (props.token) {\n internalToken.value = props.token;\n }\n\n if (!internalToken.value) {\n const error = new Error('Plaid: link token not found');\n\n logger.error(error, { tags: { plaid: true } });\n emit('error', error);\n\n isPlaidModalOpen.value = false;\n\n return;\n }\n\n sessionStorage.setItem(\n internalStorageKey.value,\n JSON.stringify({ token: internalToken.value, returnTo: props.returnTo, env: props.env }),\n );\n\n // Retries Plaid's script initialization if not loaded yet\n if (!window.Plaid) {\n await loadPlaidScript();\n }\n\n window.Plaid.create({\n token: internalToken.value,\n env: props.env,\n onExit,\n onSuccess,\n onEvent,\n onLoad,\n }).open();\n }\n\n function loadPlaidScript() {\n return new Promise<void>(function (resolve, reject) {\n const existingScript = document.querySelector('script[src=\"' + props.initScriptUrl + '\"]');\n\n if (existingScript) {\n existingScript.remove();\n }\n\n const el = document.createElement('script');\n\n el.type = 'text/javascript';\n el.async = true;\n el.src = props.initScriptUrl;\n el.addEventListener('load', () => resolve());\n el.addEventListener('error', reject);\n el.addEventListener('abort', reject);\n document.head.appendChild(el);\n });\n }\n\n loadPlaidScript();\n\n defineExpose({\n handleClick,\n });\n</script>\n\n<template>\n <span data-test=\"stash-plaid-link\" @click=\"handleClick\">\n <!-- @slot Default slot to trigger Plaid's modal -->\n <slot :open=\"isPlaidModalOpen\"></slot>\n </span>\n</template>\n"],"names":["internalStorageKey","computed","props","internalToken","ref","isPlaidModalOpen","onExit","error","metadata","logger","emit","onSuccess","public_token","onLoad","args","onEvent","handleClick","link_token","err","loadPlaidScript","resolve","reject","existingScript","el","__expose"],"mappings":";;;;;;;;;;;;;;iBAwDQA,IAAqBC,EAAS,MAC9BC,EAAM,aACDA,EAAM,aAMR,GAFM,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,OAAO,EAAE,EAAE,KAAK,GAAG,CAElD,QACf,GAEKC,IAAgBC,EAAI,EAAE,GA0BtBC,IAAmBD,EAAI,EAAK,GAE5BE,IAAuB,CAACC,GAA2BC,MAAmC;AAC1F,MAAAH,EAAiB,QAAQ,IAErBE,MACFE,EAAO,MAAM,IAAI,MAAM,wCAAwC,GAAG;AAAA,QAChE,MAAM,EAAE,OAAO,GAAK;AAAA,QACpB,OAAO,EAAE,YAAY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,MAAMiB,EAAgB,GAGxB,OAAO,MAAM,OAAO;AAAA,UAClB,OAAOhB,EAAc;AAAA,UACrB,KAAKD,EAAM;AAAA,UACX,QAAAI;AAAA,UACA,WAAAK;AAAA,UACA,SAAAI;AAAA,UACA,QAAAF;AAAA,QAAA,CACD,EAAE,KAAK;AAAA;AAAA,IACV;AAEA,aAASM,IAAkB;AACzB,aAAO,IAAI,QAAc,SAAUC,GAASC,GAAQ;AAClD,cAAMC,IAAiB,SAAS,cAAc,iBAAiBpB,EAAM,gBAAgB,IAAI;AAEzF,QAAIoB,KACFA,EAAe,OAAO;AAGlB,cAAAC,IAAK,SAAS,cAAc,QAAQ;AAE1C,QAAAA,EAAG,OAAO,mBACVA,EAAG,QAAQ,IACXA,EAAG,MAAMrB,EAAM,eACfqB,EAAG,iBAAiB,QAAQ,MAAMH,EAAS,CAAA,GACxCG,EAAA,iBAAiB,SAASF,CAAM,GAChCE,EAAA,iBAAiB,SAASF,CAAM,GAC1B,SAAA,KAAK,YAAYE,CAAE;AAAA,MAAA,CAC7B;AAAA,IACH;AAEgB,WAAAJ,KAEHK,EAAA;AAAA,MACX,aAAAR;AAAA,IAAA,CACD;;;;;;;;"}
1
+ {"version":3,"file":"PlaidLink.js","sources":["../src/components/PlaidLink/PlaidLink.vue"],"sourcesContent":["<script setup lang=\"ts\">\n import logger from '@leaflink/snitch';\n import { computed, ref } from 'vue';\n\n import { LinkTokenResponse, Plaid } from '../../../types/plaid';\n import usePlaidLink from '../../composables/usePlaidLink/usePlaidLink';\n\n export interface PlaidLinkProps {\n /**\n * @deprecated Plaid does not support other URLs for loading its SDK\n * Plaid initialization script url to be used\n */\n initScriptUrl?: string;\n\n /**\n * Key to be used in session storage for OAuth flow\n */\n storageKey?: string;\n\n /**\n * Url to be used to redirect the user from the OAuth flow\n */\n returnTo?: string;\n\n /**\n * Plaid link token\n */\n token?: string;\n\n /**\n * Plaid environment to connect\n */\n env?: Plaid.Environment;\n\n /**\n * Function that returns a link token object to be used with Plaid.\n * `link_token` takes precedence over `token` if informed.\n */\n createToken?: () => Promise<LinkTokenResponse>;\n }\n\n const props = withDefaults(defineProps<PlaidLinkProps>(), {\n initScriptUrl: 'https://cdn.plaid.com/link/v2/stable/link-initialize.js',\n storageKey: undefined,\n returnTo: window.location.href,\n env: 'sandbox',\n token: undefined,\n createToken: undefined,\n });\n\n const internalStorageKey = computed(() => {\n if (props.storageKey) {\n return props.storageKey;\n }\n\n // returns up to the last 3 parts of the host. e.g. for `subdomain.my.domain.com` it will return `my.domain.com`\n const host = window.location.host.split('.').splice(-3).join('.');\n\n return `${host}-plaid`;\n });\n\n const emit =\n defineEmits<{\n /**\n * Emitted whenever the exit event contains errors\n */\n (e: 'error', error: Plaid.Error | null | Error, metadata?: Plaid.OnExitMetaData): void;\n /**\n * Emitted whenever the user successfully links an item\n */\n (e: 'success', public_token: string, metadata: Plaid.OnSuccessMetaData): void;\n /**\n * Emitted whenever the user exits the Link flow\n */\n (e: 'exit', metadata: Plaid.OnExitMetaData): void;\n /**\n * Emitted when the Link is ready to be opened\n */\n (e: 'load'): void;\n /**\n * Emitted at specific points during the Link flow\n */\n (e: 'event', eventName: Plaid.EventName, metadata: Plaid.OnEventMetaData): void;\n }>();\n\n const isPlaidModalOpen = ref(false);\n\n const onExit: Plaid.OnExit = (error: Plaid.Error | null, metadata: Plaid.OnExitMetaData) => {\n isPlaidModalOpen.value = false;\n\n if (error) {\n logger.error(new Error('Plaid: Error trying to link an account'), {\n tags: { plaid: true },\n extra: { PlaidError: error },\n });\n emit('error', error, metadata);\n }\n\n sessionStorage.removeItem(internalStorageKey.value);\n\n emit('exit', metadata);\n };\n\n const onSuccess: Plaid.OnSuccess = (public_token: string, metadata: Plaid.OnSuccessMetaData) => {\n isPlaidModalOpen.value = false;\n\n sessionStorage.removeItem(internalStorageKey.value);\n\n emit('success', public_token, metadata);\n };\n\n const onLoad: Plaid.OnLoad = (...args) => emit('load', ...args);\n\n const onEvent: Plaid.OnEvent = (...args) => emit('event', ...args);\n\n const plaidLinkOptions = ref<Plaid.CreateConfig>({\n env: props.env,\n onSuccess,\n onEvent,\n onLoad,\n onExit,\n });\n\n const { open: openPlaidLink } = usePlaidLink(plaidLinkOptions);\n\n async function handleClick() {\n if (isPlaidModalOpen.value === true) {\n return;\n }\n\n isPlaidModalOpen.value = true;\n\n if (typeof props.createToken === 'function') {\n try {\n const { link_token } = await props.createToken();\n\n plaidLinkOptions.value.token = link_token;\n } catch (err) {\n const error = new Error('Plaid: Error trying to invoke createToken');\n\n logger.error(error, {\n tags: { plaid: true },\n extra: { error: err },\n });\n\n emit('error', error);\n }\n } else if (props.token) {\n plaidLinkOptions.value.token = props.token;\n }\n\n if (!plaidLinkOptions.value.token) {\n const error = new Error('Plaid: link token not found');\n\n logger.error(error, { tags: { plaid: true } });\n emit('error', error);\n\n isPlaidModalOpen.value = false;\n\n return;\n }\n\n sessionStorage.setItem(\n internalStorageKey.value,\n JSON.stringify({ token: plaidLinkOptions.value.token, returnTo: props.returnTo, env: props.env }),\n );\n\n openPlaidLink();\n }\n\n defineExpose({\n handleClick,\n });\n</script>\n\n<template>\n <span data-test=\"stash-plaid-link\" @click=\"handleClick\">\n <!-- @slot Default slot to trigger Plaid's modal -->\n <slot :open=\"isPlaidModalOpen\"></slot>\n </span>\n</template>\n"],"names":["internalStorageKey","computed","props","isPlaidModalOpen","ref","onExit","error","metadata","logger","emit","onSuccess","public_token","onLoad","args","onEvent","plaidLinkOptions","openPlaidLink","usePlaidLink","handleClick","link_token","err","__expose"],"mappings":";;;;;;;;;;;;;;;;iBAkDQA,IAAqBC,EAAS,MAC9BC,EAAM,aACDA,EAAM,aAMR,GAFM,OAAO,SAAS,KAAK,MAAM,GAAG,EAAE,OAAO,EAAE,EAAE,KAAK,GAAG,CAElD,QACf,GA0BKC,IAAmBC,EAAI,EAAK,GAE5BC,IAAuB,CAACC,GAA2BC,MAAmC;AAC1F,MAAAJ,EAAiB,QAAQ,IAErBG,MACFE,EAAO,MAAM,IA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I,MAAM,6BAA6B;AAE9C,UAAAE,EAAA,MAAMF,GAAO,EAAE,MAAM,EAAE,OAAO,MAAQ,GAC7CG,EAAK,SAASH,CAAK,GAEnBH,EAAiB,QAAQ;AAEzB;AAAA,QACF;AAEe,uBAAA;AAAA,UACbH,EAAmB;AAAA,UACnB,KAAK,UAAU,EAAE,OAAOe,EAAiB,MAAM,OAAO,UAAUb,EAAM,UAAU,KAAKA,EAAM,KAAK;AAAA,QAAA,GAGpFc;;IAChB;AAEa,WAAAK,EAAA;AAAA,MACX,aAAAH;AAAA,IAAA,CACD;;;;;;;;"}
@@ -59,9 +59,9 @@ declare const _default: __VLS_WithTemplateSlots<DefineComponent<__VLS_WithDefaul
59
59
  }>>> & {
60
60
  onLoad?: (() => any) | undefined;
61
61
  onError?: ((error: Error | Plaid.Error | null, metadata?: Plaid.OnExitMetaData | undefined) => any) | undefined;
62
- onSuccess?: ((public_token: string, metadata: Plaid.OnSuccessMetaData) => any) | undefined;
63
62
  onEvent?: ((eventName: Plaid.EventName, metadata: Plaid.OnEventMetaData) => any) | undefined;
64
63
  onExit?: ((metadata: Plaid.OnExitMetaData) => any) | undefined;
64
+ onSuccess?: ((public_token: string, metadata: Plaid.OnSuccessMetaData) => any) | undefined;
65
65
  }, {
66
66
  initScriptUrl: string;
67
67
  storageKey: string;
@@ -78,17 +78,15 @@ export default _default;
78
78
 
79
79
  declare function handleClick(): Promise<void>;
80
80
 
81
- export declare interface LinkTokenResponse {
81
+ declare interface LinkTokenResponse {
82
82
  link_token: string;
83
- /**
84
- * expiration date in ISO-8601 format
85
- */
86
83
  expiration: string;
87
84
  request_id: string;
88
85
  }
89
86
 
90
87
  export declare interface PlaidLinkProps {
91
88
  /**
89
+ * @deprecated Plaid does not support other URLs for loading its SDK
92
90
  * Plaid initialization script url to be used
93
91
  */
94
92
  initScriptUrl?: string;
package/dist/index.d.ts CHANGED
@@ -80,6 +80,12 @@ export declare interface I18nPlugin {
80
80
  t: (key: string, value: string) => string;
81
81
  }
82
82
 
83
+ export declare interface LinkTokenResponse {
84
+ link_token: string;
85
+ expiration: string;
86
+ request_id: string;
87
+ }
88
+
83
89
  declare interface MenusPluginOptions {
84
90
  mountNodeClass?: string;
85
91
  mountNodeId?: string;
@@ -402,4 +408,7 @@ export declare interface UnifiedApiPaginationParams {
402
408
  pageSize?: number;
403
409
  }
404
410
 
411
+
412
+ export * from "plaid-link";
413
+
405
414
  export { }
@@ -0,0 +1,19 @@
1
+ import { ComputedRef } from 'vue';
2
+ import { MaybeRef } from 'vue';
3
+ import { Plaid } from 'plaid-link';
4
+ import { Ref } from 'vue';
5
+
6
+ declare function usePlaidLink(options: MaybeRef<Plaid.CreateConfig>): {
7
+ ready: ComputedRef<boolean>;
8
+ error: Ref<{
9
+ name: string;
10
+ message: string;
11
+ stack?: string | undefined;
12
+ cause?: unknown;
13
+ } | null>;
14
+ open: () => void | undefined;
15
+ exit: (options?: Plaid.ExitOptions) => void | undefined;
16
+ };
17
+ export default usePlaidLink;
18
+
19
+ export { }
@@ -0,0 +1,42 @@
1
+ import { ref as l, watchSyncEffect as c, toValue as f, computed as s, onUnmounted as v } from "vue";
2
+ import p from "./useScriptTag.js";
3
+ const m = "https://cdn.plaid.com/link/v2/stable/link-initialize.js";
4
+ function P(u) {
5
+ const { isLoaded: i, error: r } = p(m), a = l(null), t = l(!1);
6
+ c(() => {
7
+ const e = f(u);
8
+ if (i.value && !(!e.token && !e.receivedRedirectUri)) {
9
+ if (!window.Plaid)
10
+ throw new Error("Error loading Plaid SDK");
11
+ n(), a.value = window.Plaid.create({
12
+ ...e,
13
+ onLoad: () => {
14
+ var o;
15
+ t.value = !0, (o = e.onLoad) == null || o.call(e);
16
+ }
17
+ });
18
+ }
19
+ });
20
+ const d = s(
21
+ () => !r.value && a.value !== null && (i.value || t.value)
22
+ );
23
+ function n() {
24
+ a.value && (a.value.exit({ force: !0 }), a.value.destroy(), t.value = !1);
25
+ }
26
+ return v(n), {
27
+ ready: d,
28
+ error: r,
29
+ open: () => {
30
+ var e;
31
+ return (e = a.value) == null ? void 0 : e.open();
32
+ },
33
+ exit: (e) => {
34
+ var o;
35
+ return (o = a.value) == null ? void 0 : o.exit(e);
36
+ }
37
+ };
38
+ }
39
+ export {
40
+ P as default
41
+ };
42
+ //# sourceMappingURL=usePlaidLink.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlaidLink.js","sources":["../src/composables/usePlaidLink/usePlaidLink.ts"],"sourcesContent":["import { computed, MaybeRef, onUnmounted, ref, toValue, watchSyncEffect } from 'vue';\n\nimport { Plaid } from '../../../types/plaid';\nimport useScriptTag from '../useScriptTag/useScriptTag';\n\nconst PLAID_SDK_URL = 'https://cdn.plaid.com/link/v2/stable/link-initialize.js';\n\nexport default function usePlaidLink(options: MaybeRef<Plaid.CreateConfig>) {\n const { isLoaded: isPlaidScriptLoaded, error } = useScriptTag(PLAID_SDK_URL);\n\n const plaid = ref<Plaid.LinkHandler | null>(null);\n const iframeLoaded = ref(false);\n\n // We want to trigger this as soon as options ref changes\n watchSyncEffect(() => {\n const optionsVal = toValue(options);\n\n if (!isPlaidScriptLoaded.value) {\n return;\n }\n\n if (!optionsVal.token && !optionsVal.receivedRedirectUri) {\n return;\n }\n\n if (!window.Plaid) {\n throw new Error('Error loading Plaid SDK');\n }\n\n // destroy & exit existing instances so we don't\n // have multiple Plaid link modals at the same time\n teardown();\n\n plaid.value = window.Plaid.create({\n ...optionsVal,\n onLoad: () => {\n iframeLoaded.value = true;\n optionsVal.onLoad?.();\n },\n });\n });\n\n const ready = computed(\n () => !error.value && plaid.value !== null && (isPlaidScriptLoaded.value || iframeLoaded.value),\n );\n\n function teardown() {\n if (plaid.value) {\n plaid.value.exit({ force: true });\n plaid.value.destroy();\n\n iframeLoaded.value = false;\n }\n }\n\n onUnmounted(teardown);\n\n return {\n ready,\n error,\n open: () => plaid.value?.open(),\n exit: (options?: Plaid.ExitOptions) => plaid.value?.exit(options),\n };\n}\n"],"names":["PLAID_SDK_URL","usePlaidLink","options","isPlaidScriptLoaded","error","useScriptTag","plaid","ref","iframeLoaded","watchSyncEffect","optionsVal","toValue","teardown","_a","ready","computed","onUnmounted"],"mappings":";;AAKA,MAAMA,IAAgB;AAEtB,SAAwBC,EAAaC,GAAuC;AAC1E,QAAM,EAAE,UAAUC,GAAqB,OAAAC,EAAM,IAAIC,EAAaL,CAAa,GAErEM,IAAQC,EAA8B,IAAI,GAC1CC,IAAeD,EAAI,EAAK;AAG9B,EAAAE,EAAgB,MAAM;AACd,UAAAC,IAAaC,EAAQT,CAAO;AAE9B,QAACC,EAAoB,SAIrB,GAACO,EAAW,SAAS,CAACA,EAAW,sBAIjC;AAAA,UAAA,CAAC,OAAO;AACJ,cAAA,IAAI,MAAM,yBAAyB;AAKlC,MAAAE,KAEHN,EAAA,QAAQ,OAAO,MAAM,OAAO;AAAA,QAChC,GAAGI;AAAA,QACH,QAAQ,MAAM;;AACZ,UAAAF,EAAa,QAAQ,KACrBK,IAAAH,EAAW,WAAX,QAAAG,EAAA,KAAAH;AAAA,QACF;AAAA,MAAA,CACD;AAAA;AAAA,EAAA,CACF;AAED,QAAMI,IAAQC;AAAA,IACZ,MAAM,CAACX,EAAM,SAASE,EAAM,UAAU,SAASH,EAAoB,SAASK,EAAa;AAAA,EAAA;AAG3F,WAASI,IAAW;AAClB,IAAIN,EAAM,UACRA,EAAM,MAAM,KAAK,EAAE,OAAO,GAAM,CAAA,GAChCA,EAAM,MAAM,WAEZE,EAAa,QAAQ;AAAA,EAEzB;AAEA,SAAAQ,EAAYJ,CAAQ,GAEb;AAAA,IACL,OAAAE;AAAA,IACA,OAAAV;AAAA,IACA,MAAM,MAAM;;AAAA,cAAAS,IAAAP,EAAM,UAAN,gBAAAO,EAAa;AAAA;AAAA,IACzB,MAAM,CAACX,MAAgC;;AAAA,cAAAW,IAAAP,EAAM,UAAN,gBAAAO,EAAa,KAAKX;AAAAA;AAAAA,EAAO;AAEpE;"}
@@ -0,0 +1,21 @@
1
+ import { Ref } from 'vue';
2
+
3
+ declare type UseScriptOptions = {
4
+ manual: boolean;
5
+ };
6
+
7
+ declare function useScriptTag(url: string, options?: UseScriptOptions): {
8
+ scriptTag: Ref<HTMLScriptElement | null>;
9
+ load: () => void;
10
+ unload: () => void;
11
+ isLoaded: Ref<boolean>;
12
+ error: Ref<{
13
+ name: string;
14
+ message: string;
15
+ stack?: string | undefined;
16
+ cause?: unknown;
17
+ } | null>;
18
+ };
19
+ export default useScriptTag;
20
+
21
+ export { }
@@ -0,0 +1,19 @@
1
+ import { ref as a, onMounted as i, onUnmounted as v } from "vue";
2
+ function f(r, d = { manual: !1 }) {
3
+ const n = a(null), t = a(!1), o = a(null), l = () => t.value = !0, u = (e) => o.value = e.error;
4
+ function c() {
5
+ let e = document.querySelector(`script[src="${r}"]`);
6
+ e ? t.value = !0 : (t.value = !1, o.value = null, e = document.createElement("script"), e.type = "text/javascript", e.async = !0, e.src = r, e.addEventListener("load", l), e.addEventListener("error", u), document.head.appendChild(e)), n.value = e;
7
+ }
8
+ function s() {
9
+ if (!document)
10
+ return;
11
+ const e = document.querySelector(`script[src="${r}"]`);
12
+ e && (e.removeEventListener("load", l), e.removeEventListener("error", u), document.head.removeChild(e), n.value = null, t.value = !1);
13
+ }
14
+ return d.manual || (i(c), v(s)), { scriptTag: n, load: c, unload: s, isLoaded: t, error: o };
15
+ }
16
+ export {
17
+ f as default
18
+ };
19
+ //# sourceMappingURL=useScriptTag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useScriptTag.js","sources":["../src/composables/useScriptTag/useScriptTag.ts"],"sourcesContent":["import { onMounted, onUnmounted, ref } from 'vue';\n\ntype UseScriptOptions = {\n manual: boolean;\n};\n\nexport default function useScriptTag(url: string, options: UseScriptOptions = { manual: false }) {\n const scriptTag = ref<HTMLScriptElement | null>(null);\n const isLoaded = ref(false);\n const error = ref<Error | null>(null);\n\n const setIsLoaded = () => (isLoaded.value = true);\n const setError = (e: ErrorEvent) => (error.value = e.error);\n\n function loadScript() {\n let el = document.querySelector<HTMLScriptElement>(`script[src=\"${url}\"]`);\n\n if (!el) {\n isLoaded.value = false;\n error.value = null;\n\n el = document.createElement('script');\n\n el.type = 'text/javascript';\n el.async = true;\n el.src = url;\n el.addEventListener('load', setIsLoaded);\n el.addEventListener('error', setError);\n document.head.appendChild(el);\n } else {\n isLoaded.value = true;\n }\n\n scriptTag.value = el;\n }\n\n function unloadScript() {\n if (!document) {\n return;\n }\n\n const elToBeRemoved = document.querySelector<HTMLScriptElement>(`script[src=\"${url}\"]`);\n\n if (elToBeRemoved) {\n elToBeRemoved.removeEventListener('load', setIsLoaded);\n elToBeRemoved.removeEventListener('error', setError);\n\n document.head.removeChild(elToBeRemoved);\n\n scriptTag.value = null;\n isLoaded.value = false;\n }\n }\n\n if (!options.manual) {\n onMounted(loadScript);\n onUnmounted(unloadScript);\n }\n\n return { scriptTag, load: loadScript, unload: unloadScript, isLoaded, error };\n}\n"],"names":["useScriptTag","url","options","scriptTag","ref","isLoaded","error","setIsLoaded","setError","loadScript","el","unloadScript","elToBeRemoved","onMounted","onUnmounted"],"mappings":";AAMA,SAAwBA,EAAaC,GAAaC,IAA4B,EAAE,QAAQ,MAAS;AACzF,QAAAC,IAAYC,EAA8B,IAAI,GAC9CC,IAAWD,EAAI,EAAK,GACpBE,IAAQF,EAAkB,IAAI,GAE9BG,IAAc,MAAOF,EAAS,QAAQ,IACtCG,IAAW,CAAC,MAAmBF,EAAM,QAAQ,EAAE;AAErD,WAASG,IAAa;AACpB,QAAIC,IAAK,SAAS,cAAiC,eAAeT,CAAG,IAAI;AAEzE,IAAKS,IAaHL,EAAS,QAAQ,MAZjBA,EAAS,QAAQ,IACjBC,EAAM,QAAQ,MAETI,IAAA,SAAS,cAAc,QAAQ,GAEpCA,EAAG,OAAO,mBACVA,EAAG,QAAQ,IACXA,EAAG,MAAMT,GACNS,EAAA,iBAAiB,QAAQH,CAAW,GACpCG,EAAA,iBAAiB,SAASF,CAAQ,GAC5B,SAAA,KAAK,YAAYE,CAAE,IAK9BP,EAAU,QAAQO;AAAA,EACpB;AAEA,WAASC,IAAe;AACtB,QAAI,CAAC;AACH;AAGF,UAAMC,IAAgB,SAAS,cAAiC,eAAeX,CAAG,IAAI;AAEtF,IAAIW,MACYA,EAAA,oBAAoB,QAAQL,CAAW,GACvCK,EAAA,oBAAoB,SAASJ,CAAQ,GAE1C,SAAA,KAAK,YAAYI,CAAa,GAEvCT,EAAU,QAAQ,MAClBE,EAAS,QAAQ;AAAA,EAErB;AAEI,SAACH,EAAQ,WACXW,EAAUJ,CAAU,GACpBK,EAAYH,CAAY,IAGnB,EAAE,WAAAR,GAAW,MAAMM,GAAY,QAAQE,GAAc,UAAAN,GAAU,OAAAC;AACxE;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leaflink/stash",
3
- "version": "48.5.0",
3
+ "version": "48.6.0",
4
4
  "description": "LeafLink's design system.",
5
5
  "homepage": "https://stash.leaflink.com",
6
6
  "main": "./dist/index.ts",
package/types/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './address';
2
2
  export * from './colors';
3
3
  export * from './misc';
4
+ export * from './plaid';
4
5
  export * from './statusLevels';
5
6
  export * from './unifiedApi';
package/types/plaid.ts ADDED
@@ -0,0 +1,7 @@
1
+ export interface LinkTokenResponse {
2
+ link_token: string;
3
+ expiration: string; // ISO-8601
4
+ request_id: string;
5
+ }
6
+
7
+ export type * from 'plaid-link';