@withone/connect 0.12.0 → 0.12.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 +51 -266
- package/dist/button.d.ts +5 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/react.cjs.js +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.esm.js +1 -1
- package/dist/vue.cjs.js +1 -1
- package/dist/vue.esm.js +1 -1
- package/package.json +1 -1
- package/skills/one-connect/SKILL.md +66 -143
- package/src/button.ts +27 -12
- package/src/index.ts +5 -1
- package/src/react.ts +16 -9
- package/src/vue.ts +12 -5
package/dist/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e="one_connect",t="one_connect_error",n={declined:"You cancelled the connection.",expired:"The connection attempt expired. Please try again.",failed:"The connection could not be completed. Please try again."};function o(o){const i=new URLSearchParams(o),r=i.get(e);if("success"===r)return{status:r};if("error"!==r)return null;const a=i.get(t),l=null!==(s=a)&&Object.prototype.hasOwnProperty.call(n,s)?a:"failed";var s;return{status:r,code:l,message:n[l]}}const i=[e,t,"one_connect_message"];function r(e){const t=new URLSearchParams(e);return i.some(e=>t.has(e))}let a,l=!1,s=!1,c=!1;const d=[];function p(){return u()}function u(){return"undefined"==typeof window?null:(void 0===a&&(a=o(window.location.search),(a||r(window.location.search))&&function(){const e=()=>{r(window.location.search)&&window.history.replaceState(window.history.state,"",function(e){const t=new URLSearchParams(e.search);for(const e of i)t.delete(e);const n=t.toString();return`${e.pathname}${n?`?${n}`:""}${e.hash}`}(window.location))};e();for(const t of[50,500,2e3])window.setTimeout(e,t)}()),a)}function h(e){let t=e,n=!1;const o={deliver:e=>{try{var n,o,i,r,a,l;"success"===e.status?null===(n=(o=t).onSuccess)||void 0===n||n.call(o):null===(i=(r=t).onError)||void 0===i||i.call(r,null!==(a=e.message)&&void 0!==a?a:"",null!==(l=e.code)&&void 0!==l?l:"failed")}catch{}},restored:()=>{if(n){n=!1;try{var e,o;null===(e=(o=t).onCancel)||void 0===e||e.call(o)}catch{}}}};return"undefined"!=typeof window&&(d.push(o),c||"undefined"==typeof window||(c=!0,window.addEventListener("pageshow",e=>{if(e.persisted)for(const e of[...d])e.restored()})),function(){if(l||s)return;const e=u();e&&(s=!0,window.setTimeout(()=>{s=!1;const t=d[0];t&&!l&&(l=!0,t.deliver(e))},0))}()),{open:()=>{"undefined"!=typeof window&&(n=!0,window.location.assign((e=>{var t;const n=null!==(t=e.connectTheme)&&void 0!==t?t:e.appTheme;try{const t=new URL(e.authorizeUrl,window.location.origin);return n&&(t.hash=`one_theme=${n}`),t.toString()}catch{return e.authorizeUrl}})(t)))},update:e=>{t=e},destroy:()=>{const e=d.indexOf(o);e>=0&&d.splice(e,1)}}}const C=e=>h(e);function f(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t);if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function b(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const g={"cal-com":"Cal.com","click-up":"ClickUp",clickup:"ClickUp",docusign:"DocuSign",elevenlabs:"ElevenLabs","fireflies-ai":"Fireflies.ai",github:"GitHub",gitlab:"GitLab",hubspot:"HubSpot","linked-in":"LinkedIn",linkedin:"LinkedIn","one-drive":"OneDrive",onedrive:"OneDrive",openai:"OpenAI","otter-ai":"Otter.ai",paypal:"PayPal",posthog:"PostHog",quickbooks:"QuickBooks",sharepoint:"SharePoint","spotify-web":"Spotify",teams:"Microsoft Teams","telegram-bot":"Telegram","whatsapp-business":"WhatsApp Business",woocommerce:"WooCommerce",x:"X","youtube-data":"YouTube",youtube:"YouTube"};function v(e){var t;return null!==(t=g[e])&&void 0!==t?t:e.split(/[-_]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function m(e){return e?`https://assets.withone.ai/connectors/${e}.svg`:""}function x(e){var t,n,o,i;const r="string"==typeof e?{slug:e}:e,a=null!==(t=r.slug)&&void 0!==t&&t.trim()?b(r.slug):null!==(n=r.name)&&void 0!==n&&n.trim()?b(r.name):"";return a?{slug:a,name:(null===(o=r.name)||void 0===o?void 0:o.trim())||v(a),imageUrl:(null===(i=r.imageUrl)||void 0===i?void 0:i.trim())||m(a)}:null}function w(e){const t=null==e?void 0:e.trim();if(!t)return[];if(t.startsWith("["))try{const e=JSON.parse(t);return Array.isArray(e)?e.filter(e=>"string"==typeof e||"object"==typeof e&&null!==e):[]}catch{return[]}return t.split(",").map(e=>e.trim()).filter(Boolean)}const y="#CCFF00",k="#0A0C0B",S="#FFFFFF",A=`\n:host{display:inline-block;vertical-align:middle;max-width:100%}\n:host([data-full-width]),:host([data-variant="block"]){display:block}\n.b{all:unset;box-sizing:border-box;position:relative;display:inline-flex;align-items:center;gap:var(--gap);\n max-width:100%;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent;\n font-family:var(--one-connect-font,inherit);font-size:var(--fs);font-weight:500;line-height:1.2;letter-spacing:-.01em;\n padding:var(--pad);border-radius:var(--one-connect-radius,12px);background:var(--bg);color:var(--fg);\n box-shadow:var(--shadow);transition:box-shadow .2s var(--ease),background-color .2s var(--ease),opacity .2s var(--ease)}\n.b[data-full-width]{display:flex;width:100%;justify-content:center}\n.b:focus-visible{outline:2px solid var(--ring);outline-offset:2px}\n.b:hover{box-shadow:var(--shadow-hover)}\n.b[disabled]{cursor:not-allowed;opacity:.5;box-shadow:none}\n.b[aria-busy="true"]{cursor:progress}\n.b{--ease:cubic-bezier(.2,.9,.25,1)}\n.b[data-size="sm"]{--fs:13px;--pad:8px 12px 8px 10px;--gap:8px;--chip:18px;--logo:12px}\n.b[data-size="md"]{--fs:14.5px;--pad:12px 16px 12px 14px;--gap:12px;--chip:22px;--logo:14px}\n.b[data-size="lg"]{--fs:16px;--pad:14px 20px 14px 16px;--gap:12px;--chip:26px;--logo:16px}\n.b[data-theme="light"],.b[data-theme="auto"]{--ink-bg:${k};--ink-fg:${S};--surface:${S};--surface-fg:${k};\n --muted:#5B6560;--line:#D5DAD7;--ring:${k};--shadow-base:0 1px 2px rgba(10,12,11,.08),0 4px 14px rgba(10,12,11,.06);\n --shadow-strong:0 1px 2px rgba(10,12,11,.12),0 6px 18px rgba(10,12,11,.1)}\n.b[data-theme="dark"]{--ink-bg:#F2F5F3;--ink-fg:${k};--surface:#101312;--surface-fg:#F2F5F3;\n --muted:#9AA39E;--line:#2A302D;--ring:${y};--shadow-base:0 1px 2px rgba(0,0,0,.4),0 8px 24px rgba(0,0,0,.35);\n --shadow-strong:0 1px 2px rgba(0,0,0,.5),0 10px 28px rgba(0,0,0,.45)}\n@media (prefers-color-scheme:dark){.b[data-theme="auto"]{--ink-bg:#F2F5F3;--ink-fg:${k};--surface:#101312;--surface-fg:#F2F5F3;\n --muted:#9AA39E;--line:#2A302D;--ring:${y};--shadow-base:0 1px 2px rgba(0,0,0,.4),0 8px 24px rgba(0,0,0,.35);\n --shadow-strong:0 1px 2px rgba(0,0,0,.5),0 10px 28px rgba(0,0,0,.45)}}\n.b[data-variant="default"]{--bg:var(--ink-bg);--fg:var(--ink-fg);--shadow:var(--shadow-base);--shadow-hover:var(--shadow-strong)}\n.b[data-variant="accent"]{--bg:var(--one-connect-accent,${y});--fg:var(--one-connect-accent-fg,${k});\n --shadow:0 1px 2px rgba(10,12,11,.1);--shadow-hover:0 1px 2px rgba(10,12,11,.12),0 6px 18px rgba(10,12,11,.12)}\n.b[data-variant="block"]{--bg:var(--surface);--fg:var(--surface-fg);--shadow:inset 0 0 0 1px var(--line);\n --shadow-hover:inset 0 0 0 1px var(--muted);flex-direction:column;align-items:stretch;gap:0;\n width:100%;max-width:420px;text-align:left;padding:16px;border-radius:var(--one-connect-radius,14px)}\n.b[data-variant="block"][data-full-width]{max-width:none}\n.stack{display:inline-flex;align-items:center;flex-shrink:0}\n.chip{width:var(--chip);height:var(--chip);border-radius:6px;display:grid;place-items:center;overflow:hidden;\n margin-left:-7px;position:relative;background:${S};color:${k};box-shadow:0 0 0 1.5px var(--bg);\n transition:margin-left .28s var(--ease)}\n.chip:first-child{margin-left:0}\n.b[data-variant="block"] .chip{box-shadow:0 0 0 1.5px var(--bg),0 0 0 2.5px var(--line)}\n.chip img{width:var(--logo);height:var(--logo);display:block;object-fit:contain}\n.chip.more,.chip.letter{font:500 9px/1 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:-.02em}\n.chip.letter{font-size:10px;font-weight:600}\n.b:hover .chip{margin-left:-2px}.b:hover .chip:first-child{margin-left:0}\n.label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.icon{display:inline-flex;flex-shrink:0}\n.arrow{opacity:.55;transition:transform .2s var(--ease),opacity .2s var(--ease)}\n.b:hover .arrow{transform:translateX(2px);opacity:.85}\n.spinner{width:16px;height:16px;border-radius:50%;border:2px solid currentColor;border-top-color:transparent;\n opacity:.7;animation:spin .7s linear infinite;flex-shrink:0}\n@keyframes spin{to{transform:rotate(360deg)}}\n.top{display:flex;align-items:center;justify-content:space-between;gap:12px}\n.title{font-size:15px;font-weight:600;letter-spacing:-.01em}\n.sub{font-size:13px;line-height:1.5;margin-top:6px;font-weight:400;color:var(--muted)}\n.foot{margin-top:14px;padding-top:12px;display:flex;align-items:center;gap:6px;font-size:11px;font-weight:400;\n color:var(--muted);border-top:1px solid var(--line)}\n.lockup{display:inline-flex;color:var(--surface-fg)}\n.sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}\n@media (prefers-reduced-motion:reduce){.b,.chip,.arrow{transition:none}.spinner{animation-duration:1.6s}}\n@media (forced-colors:active){.b{border:1px solid ButtonText}.b:focus-visible{outline-color:Highlight}}\n`;let L=null;function E(e){const t=e.trim().toLowerCase(),n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/.exec(t);if(n){const e=3===n[1].length?n[1].replace(/./g,"$&$&"):n[1];return[0,2,4].map(t=>parseInt(e.slice(t,t+2),16))}const o=/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/.exec(t);return o?[Number(o[1]),Number(o[2]),Number(o[3])]:null}const $=([e,t,n])=>{const o=e=>{const t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return.2126*o(e)+.7152*o(t)+.0722*o(n)};function z(e){const t=function(e){const t=E(e);if(t)return t;try{const t=document.createElement("canvas").getContext("2d");return t?(t.fillStyle="#000",t.fillStyle=e,E(String(t.fillStyle))):null}catch{return null}}(e);if(!t)return k;const n=$(t);return 1.05/(n+.05)>(n+.05)/($([10,12,11])+.05)?S:k}const F=(e,t,n)=>{const o=document.createElement(e);return t&&(o.className=t),void 0!==n&&(o.textContent=n),o},M=(e,t="icon")=>{const n=F("span",t);return n.innerHTML=e,n};function T(e){const t=(null!=(n=e.platforms)?n:[]).map(x).filter(e=>null!==e);var n;if(0===t.length)return null;const o=F("span","stack");o.setAttribute("aria-hidden","true");for(const e of t.slice(0,3)){const t=F("span","chip");t.title=e.name;const n=F("img");n.alt="",n.decoding="async",n.src=e.imageUrl,n.addEventListener("error",()=>{n.remove(),t.classList.add("letter"),t.textContent=e.name.charAt(0).toUpperCase()}),t.appendChild(n),o.appendChild(t)}const i=t.length-3;return i>0&&o.appendChild(F("span","chip more",`+${i}`)),o}const P=(e,t)=>{var n;return{authorizeUrl:e.authorizeUrl,connectTheme:null!==(n=e.connectTheme)&&void 0!==n?n:e.appTheme,...t}};function U(e,t){var n;const o=null!==(n=e.shadowRoot)&&void 0!==n?n:e.attachShadow({mode:"open"});!function(e){if("undefined"!=typeof CSSStyleSheet&&"replaceSync"in CSSStyleSheet.prototype&&"adoptedStyleSheets"in e)try{return L||(L=new CSSStyleSheet,L.replaceSync(A)),void(e.adoptedStyleSheets=[L])}catch{}const t=document.createElement("style");t.textContent=A,e.appendChild(t)}(o);let i=t,r=!1,a=!1,l=null;const s=F("button","b");s.type="button",s.setAttribute("part","button");const c=F("span","sr");c.setAttribute("role","status"),c.setAttribute("aria-live","polite"),o.append(s,c);const d=()=>{return r?"connecting":void 0!==i.connected?i.connected?"connected":"idle":"success"===(null===(e=p())||void 0===e?void 0:e.status)?"connected":"idle";var e},u={onSuccess:()=>{var e,t;return null===(e=(t=i).onSuccess)||void 0===e?void 0:e.call(t)},onError:(e,t)=>{var n,o;return null===(n=(o=i).onError)||void 0===n?void 0:n.call(o,e,t)},onCancel:()=>{var e,t;r=!1,f(),null===(e=(t=i).onCancel)||void 0===e||e.call(t)}},C=h(P(i,u)),f=()=>{var t,n,o,r,p;if(a)return;const u=d(),h=null!==(t=i.variant)&&void 0!==t?t:"default",C="connecting"===u?"Connecting…":"connected"===u?null!==(n=i.connectedLabel)&&void 0!==n?n:"Connected":null!==(o=i.label)&&void 0!==o?o:"Connect your apps";if("accent"===h){var f;const t=(null===(f=i.accentColor)||void 0===f?void 0:f.trim())||y;e.style.setProperty("--one-connect-accent",t),e.style.setProperty("--one-connect-accent-fg",z(t))}else e.style.removeProperty("--one-connect-accent"),e.style.removeProperty("--one-connect-accent-fg");e.toggleAttribute("data-full-width",Boolean(i.fullWidth)),e.setAttribute("data-variant",h),s.dataset.variant=h,s.dataset.size=null!==(r=i.size)&&void 0!==r?r:"md",s.dataset.theme=null!==(p=i.theme)&&void 0!==p?p:"light",s.dataset.state=u,s.toggleAttribute("data-full-width",Boolean(i.fullWidth)),s.disabled=Boolean(i.disabled),s.setAttribute("aria-busy",String("connecting"===u)),"connecting"===u?s.setAttribute("aria-disabled","true"):s.removeAttribute("aria-disabled");const b="idle"===u?T(i):null,g="connecting"===u?F("span","spinner"):"connected"===u?M('<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3 8.5l3.5 3.5L13 5"/></svg>'):b;if(s.replaceChildren(),s.removeAttribute("aria-labelledby"),s.removeAttribute("aria-describedby"),"block"===h){const e=F("span","top"),t=F("span","title",C);if(t.id="one-connect-title",t.setAttribute("part","label"),e.appendChild(t),g&&e.appendChild(g),s.appendChild(e),s.setAttribute("aria-labelledby",t.id),i.description){const e=F("span","sub",i.description);e.id="one-connect-description",s.appendChild(e),s.setAttribute("aria-describedby",e.id)}const n=F("span","foot");n.setAttribute("aria-hidden","true"),n.append(F("span","","Secured by"),M('<svg viewBox="0 0 3152 990" width="35" height="11" fill="none" aria-hidden="true" focusable="false"><path d="M1698.02 793.203C1525.75 793.203 1401 666.834 1401 495.102C1401 323.909 1524.67 197 1698.02 197C1870.83 197 1996.12 323.909 1996.12 495.102C1996.12 666.834 1869.75 793.203 1698.02 793.203ZM1698.02 694.916C1801.71 694.916 1884.88 615.53 1884.88 495.102C1884.88 374.133 1801.71 295.827 1698.02 295.827C1594.87 295.827 1511.71 373.053 1511.71 495.102C1511.71 616.61 1595.41 694.916 1698.02 694.916Z" fill="currentColor"/><path d="M2326.71 197.54C2480.62 197.54 2565.95 289.887 2565.95 467.56V779.702H2455.24V468.64C2455.24 361.172 2411.5 292.587 2308.35 292.587C2217.63 292.587 2140.4 356.852 2140.4 484.841V779.702H2030.77V211.041H2140.4V272.065C2185.76 225.082 2248.41 197.54 2326.71 197.54Z" fill="currentColor"/><path d="M3151.98 493.481C3151.98 514.003 3150.36 520.483 3148.74 529.124H2700.51C2715.63 637.672 2794.47 686.815 2922.46 686.815C3031.01 686.815 3099.6 650.633 3116.88 643.072V747.84C3100.68 755.4 3023.45 793.203 2908.96 793.203C2699.97 793.203 2588.18 661.434 2588.18 497.802C2588.18 332.55 2702.67 197 2871.7 197C3031.55 197 3151.98 317.969 3151.98 493.481ZM2876.02 300.688C2784.75 300.688 2720.49 345.511 2702.67 434.617H3050.45C3034.79 344.971 2967.29 300.688 2876.02 300.688Z" fill="currentColor"/><path d="M537.494 782.175C641.011 827.7 767.922 858.83 880.501 839.875C983.155 822.599 1069.64 764.946 1094.39 659.271C1114.47 573.493 1088.54 481.273 1047.27 405.311C983.124 287.246 874.768 183.791 759.847 114.657C644.926 45.5225 507.181 -5.02605 372.102 0.398669C289.698 3.69665 205.938 26.536 146.544 85.6685C112.069 119.989 88.3818 171.231 83.1266 219.823C78.1642 265.64 84.3749 310.317 99.8478 354.007C168.243 547.14 354.009 701.467 537.51 782.191L537.494 782.175ZM751.956 818.053C583.05 796.2 415.7 707.108 292.472 593.004C222.536 528.246 159.366 444.979 125.985 355.471C102.961 293.734 96.3956 223.367 122.41 161.969C137.158 127.14 160.367 98.244 190.743 75.9133C275.581 13.5752 395.819 6.99464 495.977 26.8596C608.848 49.252 713.875 99.4615 806.712 166.515C907.085 239.025 999.537 339.922 1048.42 454.627C1072.45 511.001 1083.99 570.103 1075.64 630.869C1067.38 690.957 1034.57 742.353 983.987 775.379C917.626 818.715 830.861 828.255 751.972 818.053H751.956Z" fill="currentColor"/><path d="M1103.27 661.228C1086.68 755.313 1024.9 818.622 934.021 848.69C821.751 885.846 685.146 860.263 576.251 818.915C452.515 771.942 340.336 699.91 245.157 607.813C209.002 572.83 177.255 534.456 148.837 493.031C100.384 422.402 61.7024 335.19 65.8326 248.071C68.2213 197.769 83.987 159.241 111.403 116.938C45.8289 171.308 31.404 262.511 47.1543 342.002C53.4728 373.841 62.9815 403.23 76.528 432.958C100.338 485.202 130.914 532.992 167.747 577.238C255.452 682.573 367.83 765.13 491.073 824.124C614.317 883.118 769.307 920.691 900.471 889.128C985.788 868.601 1061.47 816.095 1090.83 730.856C1098.18 708.71 1104.61 686.564 1103.25 661.244L1103.27 661.228Z" fill="currentColor"/><path d="M883.297 963.502C923.15 947.074 960.877 926.022 988.309 893.967C954.265 917.839 920.931 934.807 882.403 944.993C751.747 979.53 595.123 942.589 474.731 886.57C422.102 862.082 372.617 834.018 325.181 800.591C205.128 715.984 89.4825 597.996 36.7762 458.756C20.2092 414.973 11.7793 370.404 11.5327 323.739C11.4249 302.641 15.4627 283.747 19.0226 263.004C-2.52219 310.486 -3.66265 380.915 5.21419 431.617C32.0605 584.881 147.151 721.146 266.988 813.983C343.443 873.224 436.403 924.913 528.424 954.672C620.444 984.431 713.851 999.426 808.491 983.598C834.459 979.252 858.362 973.781 883.297 963.502Z" fill="currentColor"/><path d="M1045.09 830.737C1053.55 816.158 1061.75 802.95 1066.99 787.061C1043.75 824.541 1013.3 854.408 974.29 874.982C947.752 888.991 920.228 899.27 890.577 905.219C864.578 910.428 839.673 914.481 812.781 914.851C739.716 915.852 668.717 903.092 599.459 880.854C418.686 822.8 238.422 697.6 127.985 543.165C94.8819 496.87 68.8679 447.847 50.7135 394.031C28.1978 324.45 25.7782 258.69 53.4104 189.078C36.1345 211.825 26.9956 237.793 20.4151 264.916C18.3654 282.732 14.713 299.345 15.0828 317.561C15.9613 360.774 23.5436 402.692 38.477 443.562C73.1522 538.464 134.936 621.869 207.368 691.913C307.34 788.587 426.762 862.268 558.127 907.993C689.491 953.718 871.975 973.768 992.614 885.446C1013.28 870.312 1029.39 851.773 1045.07 830.752L1045.09 830.737Z" fill="currentColor"/><path d="M552.552 745.664C671.079 797.831 835.825 835.526 954.768 769.12C999.137 744.354 1031.99 705.626 1047.99 657.312C1086.75 540.264 1020.28 405.817 947.124 315.631C855.536 202.745 729.688 114.516 592.76 66.0323C506.349 35.4412 418.968 22.0797 328.211 37.46C262.313 48.6177 195.29 81.7054 157.563 138.234C118.912 196.133 115.891 270.785 136.758 335.882C176.519 459.926 276.769 570.763 381.01 646.277C434.995 685.391 491.662 718.864 552.567 745.664H552.552ZM210.162 422.955C199.898 402.381 189.141 382.701 184.733 360.385C182.267 347.918 184.625 333.477 184.564 320.64C184.44 293.223 194.072 269.059 209.992 247.93C219.609 235.17 229.456 224.844 243.018 215.906C341.218 151.179 476.051 175.991 576.763 223.904C661.971 264.435 737.394 321.534 796.11 395.862C836.919 447.52 871.193 513.634 880.502 579.501C888.238 634.272 873.243 695.485 826.763 729.189C807.853 742.905 785.045 751.721 761.728 755.974C721.921 763.217 688.802 758.008 649.565 748.916C594.27 736.094 542.488 715.212 492.279 688.889C441.977 662.521 396.745 631.483 353.008 595.436C314.372 563.597 280.252 537.845 248.458 498.007L248.274 497.837L221.504 461.945L211.379 445.84C194.103 418.408 177.398 391.346 165.238 361.202C151.291 326.604 142.676 291.852 143.678 254.279C146.19 160.564 203.766 96.7467 290.238 67.82C434.394 19.5985 611.561 79.4246 735.298 157.636C825.099 214.411 904.435 286.581 963.321 375.134C989.767 414.894 1010.42 456.998 1023.78 502.646C1049.84 591.66 1036.79 685.884 957.404 742.659C890.257 790.68 785.6 793.146 707.295 776.486C680.403 769.736 654.065 766.007 629.222 754.818C732.107 783.93 882.397 797.723 963.938 715.35C990.599 688.412 1007.55 656.218 1013.75 618.537C1020.87 575.232 1016.12 531.634 1002.62 489.931C985.498 437.071 956.34 384.026 922.405 340.289C876.911 281.665 823.188 230.531 762.468 187.981C681.112 130.975 588.783 88.887 490.799 71.0872C425.595 59.2514 349.463 60.4072 287.557 85.0959C256.441 97.5019 228.501 114.5 205.924 138.85C158.303 190.2 147.176 256.036 161.539 323.383C166.856 348.334 175.456 371.296 185.596 394.737C194.488 415.295 222.676 461.883 236.022 477.649L226.729 456.196L210.162 423.001V422.955ZM832.342 286.936C756.904 211.544 666.44 154.076 564.896 120.249C526.553 107.473 487.948 99.4899 447.648 96.084C401.26 92.1696 356.167 96.7313 312.215 111.341C222.337 141.208 169.399 217.277 175.255 312.333C177.567 324.847 179.555 335.774 180.603 348.503C152.971 264.944 174.454 175.236 251.356 125.581C310.797 87.2072 387.39 78.2071 456.694 86.7603C503.714 92.5549 555.387 106.656 599.078 124.317C706.016 167.546 800.764 234.615 876.741 321.395C912.002 361.664 942.085 405.756 963.876 454.532C996.779 528.166 1011.85 610.046 965.895 681.369C952.379 702.359 935.427 718.818 914.283 731.871C884.432 747.421 852.947 758.671 818.872 761.06C839.523 755.959 859.404 750.981 878.637 740.424C929.186 717.061 964.601 671.567 974.818 616.488C987.671 547.245 964.693 475.429 930.881 415.357C903.834 367.305 871.471 326.049 832.311 286.905L832.342 286.936ZM890.673 420.18C861.623 370.387 825.515 327.621 783.288 287.999C721.659 230.161 650.028 185.345 570.598 156.033C513.623 135.013 454.506 124.394 393.786 128.108C353.316 130.59 315.728 139.867 280.498 159.516C245.268 179.166 216.819 204.918 201.023 240.394L188.617 268.242C204.583 180.445 278.325 132.054 361.931 119.355C412.757 111.634 462.658 116.643 512.421 129.048C596.905 150.116 674.1 189.923 743.45 242.028C816.607 296.999 885.526 373.531 924.578 456.982C949.713 510.675 965.094 571.61 949.837 630.234C939.018 671.768 912.511 706.566 875.308 727.987C847.013 744.292 816.191 754.679 783.242 758.101C825.915 745.926 863.75 731.917 895.327 698.799C913.512 679.72 926.535 657.62 933.054 631.714C951.347 558.989 927.49 483.274 890.642 420.134L890.673 420.18ZM726.19 279.369C625.678 198.799 493.404 141.917 362.655 156.973C343.854 159.131 326.547 164.17 308.639 169.195C301.18 171.29 295.201 177.732 286.493 176.253C378.313 130.081 492.063 149.545 583.143 188.119C684.102 230.87 775.952 302.825 840.664 391.069C871.794 433.527 895.805 479.652 909.506 530.386C918.382 563.273 920.232 596.654 911.941 629.294C905.622 654.153 895.481 677.778 875.786 694.9C893.987 666.327 905.452 637.693 907.086 604.128C908.72 570.562 903.141 536.565 891.567 503.57C861.392 417.53 797.066 336.19 726.205 279.384L726.19 279.369Z" fill="currentColor"/></svg>',"lockup")),s.appendChild(n)}else{g&&s.appendChild(g);const e=F("span","label",C);e.setAttribute("part","label"),s.appendChild(e),"idle"===u&&s.appendChild(M('<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M6 3l5 5-5 5"/></svg>',"icon arrow"))}var v,m;v=u,null!==l?v!==l&&(l=v,c.textContent="connecting"===v?"Connecting to One…":"connected"===v?null!==(m=i.connectedLabel)&&void 0!==m?m:"Connected":""):l=v};return s.addEventListener("click",()=>{a||i.disabled||r||(r=!0,f(),C.open())}),f(),{update:e=>{i=e,C.update(P(i,u)),f()},destroy:()=>{a=!0,C.destroy(),o.replaceChildren()}}}function Z(e,t){const n=document.createElement("span");n.className="one-connect",e.appendChild(n);const o=U(n,t);return{update:o.update,destroy:()=>{o.destroy(),n.remove()}}}const B=["authorize-url","platforms","connected","disabled","variant","size","full-width","theme","connect-theme","app-theme","accent-color","label","connected-label","description"];function H(e,t,n){const o=e.getAttribute(t);return o&&n.includes(o)?o:void 0}const j=(e,t)=>e.hasAttribute(t)?"false"!==e.getAttribute(t):void 0;function O(){if("undefined"!=typeof window&&"undefined"!=typeof customElements&&!customElements.get("one-connect-button")){class e extends HTMLElement{constructor(...e){super(...e),f(this,"onSuccess",null),f(this,"onError",null),f(this,"onCancel",null),f(this,"handle",null)}connectedCallback(){this.sync()}disconnectedCallback(){var e;null===(e=this.handle)||void 0===e||e.destroy(),this.handle=null}attributeChangedCallback(){this.isConnected&&this.sync()}props(e){var t,n,o,i,r;return{authorizeUrl:e,platforms:w(this.getAttribute("platforms")),connected:j(this,"connected"),disabled:j(this,"disabled"),variant:H(this,"variant",["default","accent","block"]),size:H(this,"size",["sm","md","lg"]),fullWidth:j(this,"full-width"),theme:H(this,"theme",["light","dark","auto"]),connectTheme:null!==(t=H(this,"connect-theme",["light","dark"]))&&void 0!==t?t:H(this,"app-theme",["light","dark"]),accentColor:null!==(n=this.getAttribute("accent-color"))&&void 0!==n?n:void 0,label:null!==(o=this.getAttribute("label"))&&void 0!==o?o:void 0,connectedLabel:null!==(i=this.getAttribute("connected-label"))&&void 0!==i?i:void 0,description:null!==(r=this.getAttribute("description"))&&void 0!==r?r:void 0,onSuccess:()=>{var e;null===(e=this.onSuccess)||void 0===e||e.call(this),this.dispatchEvent(new CustomEvent("success"))},onError:(e,t)=>{var n;null===(n=this.onError)||void 0===n||n.call(this,e,t),this.dispatchEvent(new CustomEvent("error",{detail:{message:e,code:t}}))},onCancel:()=>{var e;null===(e=this.onCancel)||void 0===e||e.call(this),this.dispatchEvent(new CustomEvent("cancel"))}}}sync(){const e=this.getAttribute("authorize-url");var t;if(!e)return null===(t=this.handle)||void 0===t||t.destroy(),void(this.handle=null);const n=this.props(e);this.handle?this.handle.update(n):this.handle=U(this,n)}}f(e,"observedAttributes",[...B]),customElements.define("one-connect-button",e)}}O();export{h as createConnectFlow,Z as mountConnectButton,p as readConnectReturn,O as registerConnectButton,C as useOneConnect};
|
|
1
|
+
const e="one_connect",t="one_connect_error",n={declined:"You cancelled the connection.",expired:"The connection attempt expired. Please try again.",failed:"The connection could not be completed. Please try again."};function o(o){const i=new URLSearchParams(o),r=i.get(e);if("success"===r)return{status:r};if("error"!==r)return null;const a=i.get(t),l=null!==(s=a)&&Object.prototype.hasOwnProperty.call(n,s)?a:"failed";var s;return{status:r,code:l,message:n[l]}}const i=[e,t,"one_connect_message"];function r(e){const t=new URLSearchParams(e);return i.some(e=>t.has(e))}let a,l=!1,s=!1,c=!1;const d=[];function u(){return p()}function p(){return"undefined"==typeof window?null:(void 0===a&&(a=o(window.location.search),(a||r(window.location.search))&&function(){const e=()=>{r(window.location.search)&&window.history.replaceState(window.history.state,"",function(e){const t=new URLSearchParams(e.search);for(const e of i)t.delete(e);const n=t.toString();return`${e.pathname}${n?`?${n}`:""}${e.hash}`}(window.location))};e();for(const t of[50,500,2e3])window.setTimeout(e,t)}()),a)}function h(e){let t=e,n=!1;const o={deliver:e=>{try{var n,o,i,r,a,l;"success"===e.status?null===(n=(o=t).onSuccess)||void 0===n||n.call(o):null===(i=(r=t).onError)||void 0===i||i.call(r,null!==(a=e.message)&&void 0!==a?a:"",null!==(l=e.code)&&void 0!==l?l:"failed")}catch{}},restored:()=>{if(n){n=!1;try{var e,o;null===(e=(o=t).onCancel)||void 0===e||e.call(o)}catch{}}}};return"undefined"!=typeof window&&(d.push(o),c||"undefined"==typeof window||(c=!0,window.addEventListener("pageshow",e=>{if(e.persisted)for(const e of[...d])e.restored()})),function(){if(l||s)return;const e=p();e&&(s=!0,window.setTimeout(()=>{s=!1;const t=d[0];t&&!l&&(l=!0,t.deliver(e))},0))}()),{open:()=>{"undefined"!=typeof window&&(n=!0,window.location.assign((e=>{var t;const n=null!==(t=e.connectTheme)&&void 0!==t?t:e.appTheme;try{const t=new URL(e.authorizeUrl,window.location.origin);return n&&(t.hash=`one_theme=${n}`),t.toString()}catch{return e.authorizeUrl}})(t)))},update:e=>{t=e},destroy:()=>{const e=d.indexOf(o);e>=0&&d.splice(e,1)}}}const C=e=>h(e);function f(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t);if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function b(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const g={"cal-com":"Cal.com","click-up":"ClickUp",clickup:"ClickUp",docusign:"DocuSign",elevenlabs:"ElevenLabs","fireflies-ai":"Fireflies.ai",github:"GitHub",gitlab:"GitLab",hubspot:"HubSpot","linked-in":"LinkedIn",linkedin:"LinkedIn","one-drive":"OneDrive",onedrive:"OneDrive",openai:"OpenAI","otter-ai":"Otter.ai",paypal:"PayPal",posthog:"PostHog",quickbooks:"QuickBooks",sharepoint:"SharePoint","spotify-web":"Spotify",teams:"Microsoft Teams","telegram-bot":"Telegram","whatsapp-business":"WhatsApp Business",woocommerce:"WooCommerce",x:"X","youtube-data":"YouTube",youtube:"YouTube"};function v(e){var t;return null!==(t=g[e])&&void 0!==t?t:e.split(/[-_]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}function m(e){return e?`https://assets.withone.ai/connectors/${e}.svg`:""}function x(e){var t,n,o,i;const r="string"==typeof e?{slug:e}:e,a=null!==(t=r.slug)&&void 0!==t&&t.trim()?b(r.slug):null!==(n=r.name)&&void 0!==n&&n.trim()?b(r.name):"";return a?{slug:a,name:(null===(o=r.name)||void 0===o?void 0:o.trim())||v(a),imageUrl:(null===(i=r.imageUrl)||void 0===i?void 0:i.trim())||m(a)}:null}function w(e){const t=null==e?void 0:e.trim();if(!t)return[];if(t.startsWith("["))try{const e=JSON.parse(t);return Array.isArray(e)?e.filter(e=>"string"==typeof e||"object"==typeof e&&null!==e):[]}catch{return[]}return t.split(",").map(e=>e.trim()).filter(Boolean)}const y="#CCFF00",k="#0A0C0B",S="#FFFFFF",A=`\n:host{display:inline-block;vertical-align:middle;max-width:100%}\n:host([data-full-width]),:host([full-width]:not([full-width="false"])),\n:host([data-variant="block"]),:host([variant="block"]){display:block;width:100%}\n.b{all:unset;box-sizing:border-box;position:relative;display:inline-flex;align-items:center;gap:var(--gap);\n max-width:100%;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent;\n font-family:var(--one-connect-font,inherit);font-size:var(--fs);font-weight:500;line-height:1.2;letter-spacing:-.01em;\n padding:var(--pad);border-radius:var(--one-connect-radius,12px);background:var(--bg);color:var(--fg);\n box-shadow:var(--shadow);transition:box-shadow .2s var(--ease),background-color .2s var(--ease),opacity .2s var(--ease)}\n.b[data-full-width]{display:flex;width:100%;justify-content:center}\n.b:focus-visible{outline:2px solid var(--ring);outline-offset:2px}\n.b:hover{box-shadow:var(--shadow-hover)}\n.b[disabled]{cursor:not-allowed;opacity:.5;box-shadow:none}\n.b[aria-busy="true"]{cursor:progress}\n.b{--ease:cubic-bezier(.2,.9,.25,1)}\n.b[data-size="sm"]{--fs:13px;--pad:8px 12px 8px 10px;--gap:8px;--chip:18px;--logo:12px}\n.b[data-size="md"]{--fs:14.5px;--pad:12px 16px 12px 14px;--gap:12px;--chip:22px;--logo:14px}\n.b[data-size="lg"]{--fs:16px;--pad:14px 20px 14px 16px;--gap:12px;--chip:26px;--logo:16px}\n.b[data-theme="light"],.b[data-theme="auto"]{--ink-bg:${k};--ink-fg:${S};--surface:${S};--surface-fg:${k};\n --muted:#5B6560;--line:#D5DAD7;--ring:${k};--shadow-base:0 1px 2px rgba(10,12,11,.08),0 4px 14px rgba(10,12,11,.06);\n --shadow-strong:0 1px 2px rgba(10,12,11,.12),0 6px 18px rgba(10,12,11,.1)}\n.b[data-theme="dark"]{--ink-bg:#F2F5F3;--ink-fg:${k};--surface:#101312;--surface-fg:#F2F5F3;\n --muted:#9AA39E;--line:#2A302D;--ring:${y};--shadow-base:0 1px 2px rgba(0,0,0,.4),0 8px 24px rgba(0,0,0,.35);\n --shadow-strong:0 1px 2px rgba(0,0,0,.5),0 10px 28px rgba(0,0,0,.45)}\n@media (prefers-color-scheme:dark){.b[data-theme="auto"]{--ink-bg:#F2F5F3;--ink-fg:${k};--surface:#101312;--surface-fg:#F2F5F3;\n --muted:#9AA39E;--line:#2A302D;--ring:${y};--shadow-base:0 1px 2px rgba(0,0,0,.4),0 8px 24px rgba(0,0,0,.35);\n --shadow-strong:0 1px 2px rgba(0,0,0,.5),0 10px 28px rgba(0,0,0,.45)}}\n.b[data-variant="default"]{--bg:var(--ink-bg);--fg:var(--ink-fg);--shadow:var(--shadow-base);--shadow-hover:var(--shadow-strong)}\n.b[data-variant="accent"]{--bg:var(--one-connect-accent,${y});--fg:var(--one-connect-accent-fg,${k});\n --shadow:0 1px 2px rgba(10,12,11,.1);--shadow-hover:0 1px 2px rgba(10,12,11,.12),0 6px 18px rgba(10,12,11,.12)}\n.b[data-variant="block"]{--bg:var(--surface);--fg:var(--surface-fg);--shadow:inset 0 0 0 1px var(--line);\n --shadow-hover:inset 0 0 0 1px var(--muted);flex-direction:column;align-items:stretch;gap:0;\n width:100%;max-width:420px;text-align:left;padding:16px;border-radius:var(--one-connect-radius,14px)}\n.b[data-variant="block"][data-full-width]{max-width:none}\n.stack{display:inline-flex;align-items:center;flex-shrink:0}\n.chip{width:var(--chip);height:var(--chip);border-radius:6px;display:grid;place-items:center;overflow:hidden;\n margin-left:-7px;position:relative;background:${S};color:${k};box-shadow:0 0 0 1.5px var(--bg);\n transition:margin-left .28s var(--ease)}\n.chip:first-child{margin-left:0}\n.b[data-variant="block"] .chip{box-shadow:0 0 0 1.5px var(--bg),0 0 0 2.5px var(--line)}\n.chip img{width:var(--logo);height:var(--logo);display:block;object-fit:contain}\n.chip.more,.chip.letter{font:500 9px/1 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:-.02em}\n.chip.letter{font-size:10px;font-weight:600}\n.b:hover .chip{margin-left:-2px}.b:hover .chip:first-child{margin-left:0}\n.label{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.icon{display:inline-flex;flex-shrink:0}\n.arrow{opacity:.55;transition:transform .2s var(--ease),opacity .2s var(--ease)}\n.b:hover .arrow{transform:translateX(2px);opacity:.85}\n.spinner{width:16px;height:16px;border-radius:50%;border:2px solid currentColor;border-top-color:transparent;\n opacity:.7;animation:spin .7s linear infinite;flex-shrink:0}\n@keyframes spin{to{transform:rotate(360deg)}}\n.top{display:flex;align-items:center;justify-content:space-between;gap:12px}\n.title{font-size:15px;font-weight:600;letter-spacing:-.01em}\n.sub{font-size:13px;line-height:1.5;margin-top:6px;font-weight:400;color:var(--muted)}\n.foot{margin-top:14px;padding-top:12px;display:flex;align-items:center;gap:6px;font-size:11px;font-weight:400;\n color:var(--muted);border-top:1px solid var(--line)}\n.lockup{display:inline-flex;color:var(--surface-fg)}\n.sr{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}\n@media (prefers-reduced-motion:reduce){.b,.chip,.arrow{transition:none}.spinner{animation-duration:1.6s}}\n@media (forced-colors:active){.b{border:1px solid ButtonText}.b:focus-visible{outline-color:Highlight}}\n`;let L=null;function E(e){const t=e.trim().toLowerCase(),n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/.exec(t);if(n){const e=3===n[1].length?n[1].replace(/./g,"$&$&"):n[1];return[0,2,4].map(t=>parseInt(e.slice(t,t+2),16))}const o=/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/.exec(t);return o?[Number(o[1]),Number(o[2]),Number(o[3])]:null}const $=([e,t,n])=>{const o=e=>{const t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4};return.2126*o(e)+.7152*o(t)+.0722*o(n)};function z(e){const t=function(e){const t=E(e);if(t)return t;try{const t=document.createElement("canvas").getContext("2d");return t?(t.fillStyle="#000",t.fillStyle=e,E(String(t.fillStyle))):null}catch{return null}}(e);if(!t)return k;const n=$(t);return 1.05/(n+.05)>(n+.05)/($([10,12,11])+.05)?S:k}const F=(e,t,n)=>{const o=document.createElement(e);return t&&(o.className=t),void 0!==n&&(o.textContent=n),o},M=(e,t="icon")=>{const n=F("span",t);return n.innerHTML=e,n};function T(e){const t=(null!=(n=e.platforms)?n:[]).map(x).filter(e=>null!==e);var n;if(0===t.length)return null;const o=F("span","stack");o.setAttribute("aria-hidden","true");for(const e of t.slice(0,3)){const t=F("span","chip");t.title=e.name;const n=F("img");n.alt="",n.decoding="async",n.src=e.imageUrl,n.addEventListener("error",()=>{n.remove(),t.classList.add("letter"),t.textContent=e.name.charAt(0).toUpperCase()}),t.appendChild(n),o.appendChild(t)}const i=t.length-3;return i>0&&o.appendChild(F("span","chip more",`+${i}`)),o}const P=(e,t)=>{var n;return{authorizeUrl:e.authorizeUrl,connectTheme:null!==(n=e.connectTheme)&&void 0!==n?n:e.appTheme,...t}};function U(e,t){var n;const o=null!==(n=e.shadowRoot)&&void 0!==n?n:e.attachShadow({mode:"open"});!function(e){if("undefined"!=typeof CSSStyleSheet&&"replaceSync"in CSSStyleSheet.prototype&&"adoptedStyleSheets"in e)try{return L||(L=new CSSStyleSheet,L.replaceSync(A)),void(e.adoptedStyleSheets=[L])}catch{}const t=document.createElement("style");t.textContent=A,e.appendChild(t)}(o);let i=t,r=!1,a=!1,l=null;const s=F("button","b");s.type="button",s.setAttribute("part","button");const c=F("span","sr");c.setAttribute("role","status"),c.setAttribute("aria-live","polite"),o.append(s,c);const d=()=>{return r?"connecting":void 0!==i.connected?i.connected?"connected":"idle":"success"===(null===(e=u())||void 0===e?void 0:e.status)?"connected":"idle";var e},p={onSuccess:()=>{var e,t;return null===(e=(t=i).onSuccess)||void 0===e?void 0:e.call(t)},onError:(e,t)=>{var n,o;return null===(n=(o=i).onError)||void 0===n?void 0:n.call(o,e,t)},onCancel:()=>{var e,t;r=!1,f(),null===(e=(t=i).onCancel)||void 0===e||e.call(t)}},C=h(P(i,p)),f=()=>{var e,t,n,o,r;if(a)return;const u=d(),p=null!==(e=i.variant)&&void 0!==e?e:"default",h="connecting"===u?"Connecting…":"connected"===u?null!==(t=i.connectedLabel)&&void 0!==t?t:"Connected":null!==(n=i.label)&&void 0!==n?n:"Connect your apps";if("accent"===p){var C;const e=(null===(C=i.accentColor)||void 0===C?void 0:C.trim())||y;s.style.setProperty("--one-connect-accent",e),s.style.setProperty("--one-connect-accent-fg",z(e))}else s.style.removeProperty("--one-connect-accent"),s.style.removeProperty("--one-connect-accent-fg");s.dataset.variant=p,s.dataset.size=null!==(o=i.size)&&void 0!==o?o:"md",s.dataset.theme=null!==(r=i.theme)&&void 0!==r?r:"light",s.dataset.state=u,s.toggleAttribute("data-full-width",Boolean(i.fullWidth)),s.disabled=Boolean(i.disabled),s.setAttribute("aria-busy",String("connecting"===u)),"connecting"===u?s.setAttribute("aria-disabled","true"):s.removeAttribute("aria-disabled");const f="idle"===u?T(i):null,b="connecting"===u?F("span","spinner"):"connected"===u?M('<svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M3 8.5l3.5 3.5L13 5"/></svg>'):f;if(s.replaceChildren(),s.removeAttribute("aria-labelledby"),s.removeAttribute("aria-describedby"),"block"===p){const e=F("span","top"),t=F("span","title",h);if(t.id="one-connect-title",t.setAttribute("part","label"),e.appendChild(t),b&&e.appendChild(b),s.appendChild(e),s.setAttribute("aria-labelledby",t.id),i.description){const e=F("span","sub",i.description);e.id="one-connect-description",s.appendChild(e),s.setAttribute("aria-describedby",e.id)}const n=F("span","foot");n.setAttribute("aria-hidden","true"),n.append(F("span","","Secured by"),M('<svg viewBox="0 0 3152 990" width="35" height="11" fill="none" aria-hidden="true" focusable="false"><path d="M1698.02 793.203C1525.75 793.203 1401 666.834 1401 495.102C1401 323.909 1524.67 197 1698.02 197C1870.83 197 1996.12 323.909 1996.12 495.102C1996.12 666.834 1869.75 793.203 1698.02 793.203ZM1698.02 694.916C1801.71 694.916 1884.88 615.53 1884.88 495.102C1884.88 374.133 1801.71 295.827 1698.02 295.827C1594.87 295.827 1511.71 373.053 1511.71 495.102C1511.71 616.61 1595.41 694.916 1698.02 694.916Z" fill="currentColor"/><path d="M2326.71 197.54C2480.62 197.54 2565.95 289.887 2565.95 467.56V779.702H2455.24V468.64C2455.24 361.172 2411.5 292.587 2308.35 292.587C2217.63 292.587 2140.4 356.852 2140.4 484.841V779.702H2030.77V211.041H2140.4V272.065C2185.76 225.082 2248.41 197.54 2326.71 197.54Z" fill="currentColor"/><path d="M3151.98 493.481C3151.98 514.003 3150.36 520.483 3148.74 529.124H2700.51C2715.63 637.672 2794.47 686.815 2922.46 686.815C3031.01 686.815 3099.6 650.633 3116.88 643.072V747.84C3100.68 755.4 3023.45 793.203 2908.96 793.203C2699.97 793.203 2588.18 661.434 2588.18 497.802C2588.18 332.55 2702.67 197 2871.7 197C3031.55 197 3151.98 317.969 3151.98 493.481ZM2876.02 300.688C2784.75 300.688 2720.49 345.511 2702.67 434.617H3050.45C3034.79 344.971 2967.29 300.688 2876.02 300.688Z" fill="currentColor"/><path d="M537.494 782.175C641.011 827.7 767.922 858.83 880.501 839.875C983.155 822.599 1069.64 764.946 1094.39 659.271C1114.47 573.493 1088.54 481.273 1047.27 405.311C983.124 287.246 874.768 183.791 759.847 114.657C644.926 45.5225 507.181 -5.02605 372.102 0.398669C289.698 3.69665 205.938 26.536 146.544 85.6685C112.069 119.989 88.3818 171.231 83.1266 219.823C78.1642 265.64 84.3749 310.317 99.8478 354.007C168.243 547.14 354.009 701.467 537.51 782.191L537.494 782.175ZM751.956 818.053C583.05 796.2 415.7 707.108 292.472 593.004C222.536 528.246 159.366 444.979 125.985 355.471C102.961 293.734 96.3956 223.367 122.41 161.969C137.158 127.14 160.367 98.244 190.743 75.9133C275.581 13.5752 395.819 6.99464 495.977 26.8596C608.848 49.252 713.875 99.4615 806.712 166.515C907.085 239.025 999.537 339.922 1048.42 454.627C1072.45 511.001 1083.99 570.103 1075.64 630.869C1067.38 690.957 1034.57 742.353 983.987 775.379C917.626 818.715 830.861 828.255 751.972 818.053H751.956Z" fill="currentColor"/><path d="M1103.27 661.228C1086.68 755.313 1024.9 818.622 934.021 848.69C821.751 885.846 685.146 860.263 576.251 818.915C452.515 771.942 340.336 699.91 245.157 607.813C209.002 572.83 177.255 534.456 148.837 493.031C100.384 422.402 61.7024 335.19 65.8326 248.071C68.2213 197.769 83.987 159.241 111.403 116.938C45.8289 171.308 31.404 262.511 47.1543 342.002C53.4728 373.841 62.9815 403.23 76.528 432.958C100.338 485.202 130.914 532.992 167.747 577.238C255.452 682.573 367.83 765.13 491.073 824.124C614.317 883.118 769.307 920.691 900.471 889.128C985.788 868.601 1061.47 816.095 1090.83 730.856C1098.18 708.71 1104.61 686.564 1103.25 661.244L1103.27 661.228Z" fill="currentColor"/><path d="M883.297 963.502C923.15 947.074 960.877 926.022 988.309 893.967C954.265 917.839 920.931 934.807 882.403 944.993C751.747 979.53 595.123 942.589 474.731 886.57C422.102 862.082 372.617 834.018 325.181 800.591C205.128 715.984 89.4825 597.996 36.7762 458.756C20.2092 414.973 11.7793 370.404 11.5327 323.739C11.4249 302.641 15.4627 283.747 19.0226 263.004C-2.52219 310.486 -3.66265 380.915 5.21419 431.617C32.0605 584.881 147.151 721.146 266.988 813.983C343.443 873.224 436.403 924.913 528.424 954.672C620.444 984.431 713.851 999.426 808.491 983.598C834.459 979.252 858.362 973.781 883.297 963.502Z" fill="currentColor"/><path d="M1045.09 830.737C1053.55 816.158 1061.75 802.95 1066.99 787.061C1043.75 824.541 1013.3 854.408 974.29 874.982C947.752 888.991 920.228 899.27 890.577 905.219C864.578 910.428 839.673 914.481 812.781 914.851C739.716 915.852 668.717 903.092 599.459 880.854C418.686 822.8 238.422 697.6 127.985 543.165C94.8819 496.87 68.8679 447.847 50.7135 394.031C28.1978 324.45 25.7782 258.69 53.4104 189.078C36.1345 211.825 26.9956 237.793 20.4151 264.916C18.3654 282.732 14.713 299.345 15.0828 317.561C15.9613 360.774 23.5436 402.692 38.477 443.562C73.1522 538.464 134.936 621.869 207.368 691.913C307.34 788.587 426.762 862.268 558.127 907.993C689.491 953.718 871.975 973.768 992.614 885.446C1013.28 870.312 1029.39 851.773 1045.07 830.752L1045.09 830.737Z" fill="currentColor"/><path d="M552.552 745.664C671.079 797.831 835.825 835.526 954.768 769.12C999.137 744.354 1031.99 705.626 1047.99 657.312C1086.75 540.264 1020.28 405.817 947.124 315.631C855.536 202.745 729.688 114.516 592.76 66.0323C506.349 35.4412 418.968 22.0797 328.211 37.46C262.313 48.6177 195.29 81.7054 157.563 138.234C118.912 196.133 115.891 270.785 136.758 335.882C176.519 459.926 276.769 570.763 381.01 646.277C434.995 685.391 491.662 718.864 552.567 745.664H552.552ZM210.162 422.955C199.898 402.381 189.141 382.701 184.733 360.385C182.267 347.918 184.625 333.477 184.564 320.64C184.44 293.223 194.072 269.059 209.992 247.93C219.609 235.17 229.456 224.844 243.018 215.906C341.218 151.179 476.051 175.991 576.763 223.904C661.971 264.435 737.394 321.534 796.11 395.862C836.919 447.52 871.193 513.634 880.502 579.501C888.238 634.272 873.243 695.485 826.763 729.189C807.853 742.905 785.045 751.721 761.728 755.974C721.921 763.217 688.802 758.008 649.565 748.916C594.27 736.094 542.488 715.212 492.279 688.889C441.977 662.521 396.745 631.483 353.008 595.436C314.372 563.597 280.252 537.845 248.458 498.007L248.274 497.837L221.504 461.945L211.379 445.84C194.103 418.408 177.398 391.346 165.238 361.202C151.291 326.604 142.676 291.852 143.678 254.279C146.19 160.564 203.766 96.7467 290.238 67.82C434.394 19.5985 611.561 79.4246 735.298 157.636C825.099 214.411 904.435 286.581 963.321 375.134C989.767 414.894 1010.42 456.998 1023.78 502.646C1049.84 591.66 1036.79 685.884 957.404 742.659C890.257 790.68 785.6 793.146 707.295 776.486C680.403 769.736 654.065 766.007 629.222 754.818C732.107 783.93 882.397 797.723 963.938 715.35C990.599 688.412 1007.55 656.218 1013.75 618.537C1020.87 575.232 1016.12 531.634 1002.62 489.931C985.498 437.071 956.34 384.026 922.405 340.289C876.911 281.665 823.188 230.531 762.468 187.981C681.112 130.975 588.783 88.887 490.799 71.0872C425.595 59.2514 349.463 60.4072 287.557 85.0959C256.441 97.5019 228.501 114.5 205.924 138.85C158.303 190.2 147.176 256.036 161.539 323.383C166.856 348.334 175.456 371.296 185.596 394.737C194.488 415.295 222.676 461.883 236.022 477.649L226.729 456.196L210.162 423.001V422.955ZM832.342 286.936C756.904 211.544 666.44 154.076 564.896 120.249C526.553 107.473 487.948 99.4899 447.648 96.084C401.26 92.1696 356.167 96.7313 312.215 111.341C222.337 141.208 169.399 217.277 175.255 312.333C177.567 324.847 179.555 335.774 180.603 348.503C152.971 264.944 174.454 175.236 251.356 125.581C310.797 87.2072 387.39 78.2071 456.694 86.7603C503.714 92.5549 555.387 106.656 599.078 124.317C706.016 167.546 800.764 234.615 876.741 321.395C912.002 361.664 942.085 405.756 963.876 454.532C996.779 528.166 1011.85 610.046 965.895 681.369C952.379 702.359 935.427 718.818 914.283 731.871C884.432 747.421 852.947 758.671 818.872 761.06C839.523 755.959 859.404 750.981 878.637 740.424C929.186 717.061 964.601 671.567 974.818 616.488C987.671 547.245 964.693 475.429 930.881 415.357C903.834 367.305 871.471 326.049 832.311 286.905L832.342 286.936ZM890.673 420.18C861.623 370.387 825.515 327.621 783.288 287.999C721.659 230.161 650.028 185.345 570.598 156.033C513.623 135.013 454.506 124.394 393.786 128.108C353.316 130.59 315.728 139.867 280.498 159.516C245.268 179.166 216.819 204.918 201.023 240.394L188.617 268.242C204.583 180.445 278.325 132.054 361.931 119.355C412.757 111.634 462.658 116.643 512.421 129.048C596.905 150.116 674.1 189.923 743.45 242.028C816.607 296.999 885.526 373.531 924.578 456.982C949.713 510.675 965.094 571.61 949.837 630.234C939.018 671.768 912.511 706.566 875.308 727.987C847.013 744.292 816.191 754.679 783.242 758.101C825.915 745.926 863.75 731.917 895.327 698.799C913.512 679.72 926.535 657.62 933.054 631.714C951.347 558.989 927.49 483.274 890.642 420.134L890.673 420.18ZM726.19 279.369C625.678 198.799 493.404 141.917 362.655 156.973C343.854 159.131 326.547 164.17 308.639 169.195C301.18 171.29 295.201 177.732 286.493 176.253C378.313 130.081 492.063 149.545 583.143 188.119C684.102 230.87 775.952 302.825 840.664 391.069C871.794 433.527 895.805 479.652 909.506 530.386C918.382 563.273 920.232 596.654 911.941 629.294C905.622 654.153 895.481 677.778 875.786 694.9C893.987 666.327 905.452 637.693 907.086 604.128C908.72 570.562 903.141 536.565 891.567 503.57C861.392 417.53 797.066 336.19 726.205 279.384L726.19 279.369Z" fill="currentColor"/></svg>',"lockup")),s.appendChild(n)}else{b&&s.appendChild(b);const e=F("span","label",h);e.setAttribute("part","label"),s.appendChild(e),"idle"===u&&s.appendChild(M('<svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M6 3l5 5-5 5"/></svg>',"icon arrow"))}var g,v;g=u,null!==l?g!==l&&(l=g,c.textContent="connecting"===g?"Connecting to One…":"connected"===g?null!==(v=i.connectedLabel)&&void 0!==v?v:"Connected":""):l=g};return s.addEventListener("click",()=>{a||i.disabled||r||(r=!0,f(),C.open())}),f(),{update:e=>{i=e,C.update(P(i,p)),f()},destroy:()=>{a=!0,C.destroy(),o.replaceChildren()}}}function Z(e,t){const n=document.createElement("span");n.className="one-connect";const o=e=>{var t;n.setAttribute("data-variant",null!==(t=e.variant)&&void 0!==t?t:"default"),n.toggleAttribute("data-full-width",Boolean(e.fullWidth))};o(t),e.appendChild(n);const i=U(n,t);return{update:e=>{o(e),i.update(e)},destroy:()=>{i.destroy(),n.remove()}}}const B=["authorize-url","platforms","connected","disabled","variant","size","full-width","theme","connect-theme","app-theme","accent-color","label","connected-label","description"];function H(e,t,n){const o=e.getAttribute(t);return o&&n.includes(o)?o:void 0}const j=(e,t)=>e.hasAttribute(t)?"false"!==e.getAttribute(t):void 0;function O(){if("undefined"!=typeof window&&"undefined"!=typeof customElements&&!customElements.get("one-connect-button")){class e extends HTMLElement{constructor(...e){super(...e),f(this,"onSuccess",null),f(this,"onError",null),f(this,"onCancel",null),f(this,"handle",null)}connectedCallback(){this.sync()}disconnectedCallback(){var e;null===(e=this.handle)||void 0===e||e.destroy(),this.handle=null}attributeChangedCallback(){this.isConnected&&this.sync()}props(e){var t,n,o,i,r;return{authorizeUrl:e,platforms:w(this.getAttribute("platforms")),connected:j(this,"connected"),disabled:j(this,"disabled"),variant:H(this,"variant",["default","accent","block"]),size:H(this,"size",["sm","md","lg"]),fullWidth:j(this,"full-width"),theme:H(this,"theme",["light","dark","auto"]),connectTheme:null!==(t=H(this,"connect-theme",["light","dark"]))&&void 0!==t?t:H(this,"app-theme",["light","dark"]),accentColor:null!==(n=this.getAttribute("accent-color"))&&void 0!==n?n:void 0,label:null!==(o=this.getAttribute("label"))&&void 0!==o?o:void 0,connectedLabel:null!==(i=this.getAttribute("connected-label"))&&void 0!==i?i:void 0,description:null!==(r=this.getAttribute("description"))&&void 0!==r?r:void 0,onSuccess:()=>{var e;null===(e=this.onSuccess)||void 0===e||e.call(this),this.dispatchEvent(new CustomEvent("success"))},onError:(e,t)=>{var n;null===(n=this.onError)||void 0===n||n.call(this,e,t),this.dispatchEvent(new CustomEvent("error",{detail:{message:e,code:t}}))},onCancel:()=>{var e;null===(e=this.onCancel)||void 0===e||e.call(this),this.dispatchEvent(new CustomEvent("cancel"))}}}sync(){const e=this.getAttribute("authorize-url");var t;if(!e)return null===(t=this.handle)||void 0===t||t.destroy(),void(this.handle=null);const n=this.props(e);this.handle?this.handle.update(n):this.handle=U(this,n)}}f(e,"observedAttributes",[...B]),customElements.define("one-connect-button",e)}}O();export{h as createConnectFlow,Z as mountConnectButton,u as readConnectReturn,O as registerConnectButton,U as renderConnectButton,C as useOneConnect};
|
package/dist/react.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var e=require("react"),
|
|
2
|
+
"use strict";var e=require("react"),n=require("@withone/connect");const r=e=>{var n,r;return JSON.stringify([e.authorizeUrl,null!==(n=e.platforms)&&void 0!==n?n:[],e.connected,e.disabled,e.variant,e.size,e.fullWidth,e.theme,null!==(r=e.connectTheme)&&void 0!==r?r:e.appTheme,e.accentColor,e.label,e.connectedLabel,e.description])};exports.ConnectButton=function(t){var u;const c=e.useRef(null),l=e.useRef(null),o=e.useRef(""),s=e.useRef(t);s.current=t;const a=()=>({...s.current,onSuccess:()=>{var e,n;return null===(e=(n=s.current).onSuccess)||void 0===e?void 0:e.call(n)},onError:(e,n)=>{var r,t;return null===(r=(t=s.current).onError)||void 0===r?void 0:r.call(t,e,n)},onCancel:()=>{var e,n;return null===(e=(n=s.current).onCancel)||void 0===e?void 0:e.call(n)}});e.useEffect(()=>{if(c.current)return l.current=n.renderConnectButton(c.current,a()),o.current=r(s.current),()=>{var e;null===(e=l.current)||void 0===e||e.destroy(),l.current=null}},[]);const i=r(t);return e.useEffect(()=>{l.current&&i!==o.current&&(o.current=i,l.current.update(a()))},[i]),e.createElement("span",{ref:c,className:t.className?`one-connect ${t.className}`:"one-connect",style:t.style,"data-variant":null!==(u=t.variant)&&void 0!==u?u:"default","data-full-width":t.fullWidth?"":void 0})},exports.useOneConnect=function(r){const[t,u]=e.useState("idle"),[c,l]=e.useState(null),o=e.useRef(r);o.current=r;const s=e.useRef(null),a=()=>({...o.current,onSuccess:()=>{var e,n;return null===(e=(n=o.current).onSuccess)||void 0===e?void 0:e.call(n)},onError:(e,n)=>{var r,t;return null===(r=(t=o.current).onError)||void 0===r?void 0:r.call(t,e,n)},onCancel:()=>{var e,n;u("idle"),null===(e=(n=o.current).onCancel)||void 0===e||e.call(n)}});return e.useEffect(()=>{const e=n.createConnectFlow(a());s.current=e;const r=n.readConnectReturn();if("success"===(null==r?void 0:r.status))u("connected");else if("error"===(null==r?void 0:r.status)){var t,c;u("error"),l({message:null!==(t=r.message)&&void 0!==t?t:"",code:null!==(c=r.code)&&void 0!==c?c:"failed"})}return()=>{e.destroy(),s.current=null}},[]),e.useEffect(()=>{var e;null===(e=s.current)||void 0===e||e.update(a())}),{open:e.useCallback(()=>{s.current&&(l(null),u("connecting"),s.current.open())},[]),status:t,error:c}};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CSSProperties, ReactElement } from "react";
|
|
2
2
|
import { type ConnectButtonProps as ConnectButtonCoreProps, type ConnectFailureCode, type OneConnectFlowOptions } from "@withone/connect";
|
|
3
3
|
export interface ConnectButtonProps extends ConnectButtonCoreProps {
|
|
4
|
-
/** On the
|
|
4
|
+
/** On the host element, `<span class="one-connect">`. */
|
|
5
5
|
className?: string;
|
|
6
6
|
style?: CSSProperties;
|
|
7
7
|
}
|
package/dist/react.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{useRef as r,useEffect as n,createElement as e,useState as t,useCallback as
|
|
2
|
+
import{useRef as r,useEffect as n,createElement as e,useState as t,useCallback as l}from"react";import{renderConnectButton as c,createConnectFlow as o,readConnectReturn as u}from"@withone/connect";const a=r=>{var n,e;return JSON.stringify([r.authorizeUrl,null!==(n=r.platforms)&&void 0!==n?n:[],r.connected,r.disabled,r.variant,r.size,r.fullWidth,r.theme,null!==(e=r.connectTheme)&&void 0!==e?e:r.appTheme,r.accentColor,r.label,r.connectedLabel,r.description])};function i(t){var l;const o=r(null),u=r(null),i=r(""),s=r(t);s.current=t;const d=()=>({...s.current,onSuccess:()=>{var r,n;return null===(r=(n=s.current).onSuccess)||void 0===r?void 0:r.call(n)},onError:(r,n)=>{var e,t;return null===(e=(t=s.current).onError)||void 0===e?void 0:e.call(t,r,n)},onCancel:()=>{var r,n;return null===(r=(n=s.current).onCancel)||void 0===r?void 0:r.call(n)}});n(()=>{if(o.current)return u.current=c(o.current,d()),i.current=a(s.current),()=>{var r;null===(r=u.current)||void 0===r||r.destroy(),u.current=null}},[]);const v=a(t);return n(()=>{u.current&&v!==i.current&&(i.current=v,u.current.update(d()))},[v]),e("span",{ref:o,className:t.className?`one-connect ${t.className}`:"one-connect",style:t.style,"data-variant":null!==(l=t.variant)&&void 0!==l?l:"default","data-full-width":t.fullWidth?"":void 0})}function s(e){const[c,a]=t("idle"),[i,s]=t(null),d=r(e);d.current=e;const v=r(null),f=()=>({...d.current,onSuccess:()=>{var r,n;return null===(r=(n=d.current).onSuccess)||void 0===r?void 0:r.call(n)},onError:(r,n)=>{var e,t;return null===(e=(t=d.current).onError)||void 0===e?void 0:e.call(t,r,n)},onCancel:()=>{var r,n;a("idle"),null===(r=(n=d.current).onCancel)||void 0===r||r.call(n)}});n(()=>{const r=o(f());v.current=r;const n=u();if("success"===(null==n?void 0:n.status))a("connected");else if("error"===(null==n?void 0:n.status)){var e,t;a("error"),s({message:null!==(e=n.message)&&void 0!==e?e:"",code:null!==(t=n.code)&&void 0!==t?t:"failed"})}return()=>{r.destroy(),v.current=null}},[]),n(()=>{var r;null===(r=v.current)||void 0===r||r.update(f())});return{open:l(()=>{v.current&&(s(null),a("connecting"),v.current.open())},[]),status:c,error:i}}export{i as ConnectButton,s as useOneConnect};
|
package/dist/vue.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("vue"),t=require("@withone/connect");const n={type:Boolean,default:void 0},o=e.defineComponent({name:"OneConnectButton",props:{authorizeUrl:{type:String,required:!0},platforms:{type:Array,default:void 0},connected:n,disabled:n,variant:{type:String,default:void 0},size:{type:String,default:void 0},fullWidth:n,theme:{type:String,default:void 0},connectTheme:{type:String,default:void 0},appTheme:{type:String,default:void 0},accentColor:{type:String,default:void 0},label:{type:String,default:void 0},connectedLabel:{type:String,default:void 0},description:{type:String,default:void 0}},emits:{success:()=>!0,error:(e,t)=>"string"==typeof e&&"string"==typeof t,cancel:()=>!0},setup(n,{emit:o}){const r=e.ref(null);let i=null;const
|
|
1
|
+
"use strict";var e=require("vue"),t=require("@withone/connect");const n={type:Boolean,default:void 0},o=e.defineComponent({name:"OneConnectButton",props:{authorizeUrl:{type:String,required:!0},platforms:{type:Array,default:void 0},connected:n,disabled:n,variant:{type:String,default:void 0},size:{type:String,default:void 0},fullWidth:n,theme:{type:String,default:void 0},connectTheme:{type:String,default:void 0},appTheme:{type:String,default:void 0},accentColor:{type:String,default:void 0},label:{type:String,default:void 0},connectedLabel:{type:String,default:void 0},description:{type:String,default:void 0}},emits:{success:()=>!0,error:(e,t)=>"string"==typeof e&&"string"==typeof t,cancel:()=>!0},setup(n,{emit:o}){const r=e.ref(null);let i=null;const a=()=>({...n,onSuccess:()=>o("success"),onError:(e,t)=>o("error",e,t),onCancel:()=>o("cancel")});return e.onMounted(()=>{r.value&&(i=t.renderConnectButton(r.value,a()))}),e.watch(()=>({...n}),()=>{var e;return null===(e=i)||void 0===e?void 0:e.update(a())},{deep:!0}),e.onBeforeUnmount(()=>{var e;null===(e=i)||void 0===e||e.destroy(),i=null}),()=>{var t;return e.h("span",{ref:r,class:"one-connect","data-variant":null!==(t=n.variant)&&void 0!==t?t:"default","data-full-width":n.fullWidth?"":void 0})}}});exports.ConnectButton=o;
|
package/dist/vue.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{defineComponent as e,ref as t,onMounted as n,watch as o,onBeforeUnmount as r,h as i}from"vue";import{
|
|
1
|
+
import{defineComponent as e,ref as t,onMounted as n,watch as o,onBeforeUnmount as r,h as i}from"vue";import{renderConnectButton as l}from"@withone/connect";const a={type:Boolean,default:void 0},d=e({name:"OneConnectButton",props:{authorizeUrl:{type:String,required:!0},platforms:{type:Array,default:void 0},connected:a,disabled:a,variant:{type:String,default:void 0},size:{type:String,default:void 0},fullWidth:a,theme:{type:String,default:void 0},connectTheme:{type:String,default:void 0},appTheme:{type:String,default:void 0},accentColor:{type:String,default:void 0},label:{type:String,default:void 0},connectedLabel:{type:String,default:void 0},description:{type:String,default:void 0}},emits:{success:()=>!0,error:(e,t)=>"string"==typeof e&&"string"==typeof t,cancel:()=>!0},setup(e,{emit:a}){const d=t(null);let u=null;const c=()=>({...e,onSuccess:()=>a("success"),onError:(e,t)=>a("error",e,t),onCancel:()=>a("cancel")});return n(()=>{d.value&&(u=l(d.value,c()))}),o(()=>({...e}),()=>{var e;return null===(e=u)||void 0===e?void 0:e.update(c())},{deep:!0}),r(()=>{var e;null===(e=u)||void 0===e||e.destroy(),u=null}),()=>{var t;return i("span",{ref:d,class:"one-connect","data-variant":null!==(t=e.variant)&&void 0!==t?t:"default","data-full-width":e.fullWidth?"":void 0})}}});export{d as ConnectButton};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@withone/connect",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "One Connect for your app: the button your users press, the two backend routes as one import, and a server client that calls One with the grant. Users keep their connections in One; your app holds only what they granted.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -6,51 +6,40 @@ description: Add One Connect to an application so its users can grant the app sc
|
|
|
6
6
|
# One Connect
|
|
7
7
|
|
|
8
8
|
You are adding One Connect to this application. Its users will grant the app
|
|
9
|
-
scoped, revocable access to their own
|
|
10
|
-
|
|
11
|
-
calls you make with the grant.
|
|
9
|
+
scoped, revocable access to their own tools. The package does the OAuth work;
|
|
10
|
+
you wire three things: a button, two routes, and the calls made with the grant.
|
|
12
11
|
|
|
13
12
|
```
|
|
14
|
-
Browser Your backend
|
|
15
|
-
<ConnectButton> ------> GET /api/one/authorize ---302--->
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
<------ SDK reads the param and fires onSuccess
|
|
21
|
-
Later: oneConnect.runAction(userId, ...) -> /v1/passthrough, grant enforced by One
|
|
13
|
+
Browser Your backend One
|
|
14
|
+
<ConnectButton> ------> GET /api/one/authorize ---302---> hosted page: sign in, pick tools, set access
|
|
15
|
+
GET /api/one/callback <--302---- ?code&state
|
|
16
|
+
stores the tokens, redirects home
|
|
17
|
+
<------ onSuccess fires
|
|
18
|
+
Later: oneConnect.runAction(userId, ...) -> One, grant enforced
|
|
22
19
|
```
|
|
23
20
|
|
|
24
|
-
Secrets and tokens
|
|
21
|
+
Secrets and tokens stay on the server.
|
|
25
22
|
|
|
26
|
-
## 1 -
|
|
23
|
+
## 1 - Ask the human for these
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
New app. Confidential client. The secret is shown once.
|
|
25
|
+
They create the app in the One dashboard: Developers -> Connect -> New app.
|
|
30
26
|
|
|
31
27
|
| Value | Notes |
|
|
32
28
|
|---|---|
|
|
33
|
-
| `ONE_CLIENT_ID` |
|
|
34
|
-
| `ONE_CLIENT_SECRET` |
|
|
35
|
-
|
|
|
36
|
-
| `ONE_PERMISSION_SET`
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
Two facts to tell the human:
|
|
40
|
-
|
|
41
|
-
- The app can show its users one line saying why it asks. It is set on the
|
|
42
|
-
app in the dashboard, not sent by this package.
|
|
43
|
-
- Users can change or revoke the grant from their One dashboard at any time.
|
|
44
|
-
Treat a `401` from One as "ask the user to reconnect", never as a bug.
|
|
29
|
+
| `ONE_CLIENT_ID` | From the app. |
|
|
30
|
+
| `ONE_CLIENT_SECRET` | Starts with `one_secret_`. Shown once. |
|
|
31
|
+
| Redirect URI | Registered on the app. Must match the callback route exactly, e.g. `http://localhost:3000/api/one/callback`. |
|
|
32
|
+
| `ONE_PERMISSION_SET` | Optional. The tools and access levels to ask for. |
|
|
33
|
+
| `ONE_API_URL` | Optional. Production when unset; `https://development-api.withone.ai` for the development dashboard. |
|
|
45
34
|
|
|
46
35
|
## 2 - Environment (server only)
|
|
47
36
|
|
|
48
37
|
```bash
|
|
49
38
|
ONE_CLIENT_ID=...
|
|
50
39
|
ONE_CLIENT_SECRET=one_secret_...
|
|
51
|
-
ONE_REDIRECT_URI=https://yourapp.com/api/one/callback
|
|
52
|
-
ONE_PERMISSION_SET=...
|
|
53
|
-
ONE_API_URL
|
|
40
|
+
ONE_REDIRECT_URI=https://yourapp.com/api/one/callback
|
|
41
|
+
ONE_PERMISSION_SET=... # optional
|
|
42
|
+
ONE_API_URL=... # optional
|
|
54
43
|
```
|
|
55
44
|
|
|
56
45
|
## 3 - Install and create the client
|
|
@@ -70,30 +59,22 @@ export const oneConnect = createOneConnect({
|
|
|
70
59
|
permissionSet: process.env.ONE_PERMISSION_SET,
|
|
71
60
|
oneApiUrl: process.env.ONE_API_URL,
|
|
72
61
|
tokenStore: {
|
|
73
|
-
saveTokens: (userId, tokens) => /*
|
|
74
|
-
loadTokens: (userId) => /* read; null when
|
|
75
|
-
clearTokens: (userId
|
|
76
|
-
// Required when the app runs more than one process (serverless, several instances, a worker):
|
|
77
|
-
withLock: (userId, run) => /* run() while holding a per-user lock all processes share, e.g. pg_advisory_xact_lock */,
|
|
62
|
+
saveTokens: (userId, tokens) => /* save in the app's database, encrypted */,
|
|
63
|
+
loadTokens: (userId) => /* read; null when never connected */,
|
|
64
|
+
clearTokens: (userId) => /* delete */,
|
|
78
65
|
},
|
|
79
66
|
});
|
|
80
67
|
```
|
|
81
68
|
|
|
82
|
-
|
|
83
|
-
id as the key. Implement the store on whatever the app already uses; do not
|
|
84
|
-
add a database for it.
|
|
69
|
+
Use the app's own user id as the key and the database it already has.
|
|
85
70
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
together disconnect the user. The README's "Tokens" section has a Postgres
|
|
90
|
-
version. For background work, call `refreshIfExpiring(userId, { withinMs })`:
|
|
91
|
-
every few minutes with a window of minutes to keep access tokens warm, and
|
|
92
|
-
once a day with a window of days so idle users' 30-day refresh tokens renew.
|
|
71
|
+
If the app runs more than one server process or a background worker, also
|
|
72
|
+
add `withLock: (userId, run) => ...`, which runs `run()` while holding a
|
|
73
|
+
per-user lock all processes share (for example a Postgres advisory lock).
|
|
93
74
|
|
|
94
75
|
## 4 - The two routes
|
|
95
76
|
|
|
96
|
-
Next.js App Router (also Remix, SvelteKit, Hono, Bun
|
|
77
|
+
Next.js App Router (also Remix, SvelteKit, Hono, Bun):
|
|
97
78
|
|
|
98
79
|
```ts
|
|
99
80
|
// app/api/one/[action]/route.ts
|
|
@@ -101,87 +82,44 @@ import { createOneConnectRoutes } from "@withone/connect/next";
|
|
|
101
82
|
import { oneConnect } from "@/lib/one";
|
|
102
83
|
|
|
103
84
|
export const { GET } = createOneConnectRoutes(oneConnect, {
|
|
104
|
-
identifyUser: async (request) => /*
|
|
105
|
-
loginHintFor: async (request) => /* their email,
|
|
106
|
-
signInUrl: "/login",
|
|
107
|
-
});
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
That file serves `/api/one/authorize` and `/api/one/callback`.
|
|
111
|
-
|
|
112
|
-
Express, Fastify, Koa, plain Node:
|
|
113
|
-
|
|
114
|
-
```ts
|
|
115
|
-
import { createOneConnectHandlers } from "@withone/connect/node";
|
|
116
|
-
import { oneConnect } from "./one";
|
|
117
|
-
|
|
118
|
-
const { authorize, callback } = createOneConnectHandlers(oneConnect, {
|
|
119
|
-
identifyUser: (request) => /* user id or null */,
|
|
85
|
+
identifyUser: async (request) => /* the signed-in user's id, or null */,
|
|
86
|
+
loginHintFor: async (request) => /* their email, optional */,
|
|
87
|
+
signInUrl: "/login",
|
|
120
88
|
});
|
|
121
|
-
app.get("/api/one/authorize", authorize);
|
|
122
|
-
app.get("/api/one/callback", callback);
|
|
123
89
|
```
|
|
124
90
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
redirect to `/` with `?one_connect=success` or
|
|
129
|
-
`?one_connect=error&one_connect_error=declined|expired|failed` (a code, never
|
|
130
|
-
free text: the SDK shows fixed text for it). Pass `returnTo` to
|
|
131
|
-
`createOneConnect` to land somewhere else.
|
|
91
|
+
Express or plain Node: `createOneConnectHandlers(oneConnect, { identifyUser })`
|
|
92
|
+
from `@withone/connect/node`, mounted at `/api/one/authorize` and
|
|
93
|
+
`/api/one/callback`.
|
|
132
94
|
|
|
133
95
|
## 5 - The button
|
|
134
96
|
|
|
135
97
|
```tsx
|
|
136
|
-
import { ConnectButton } from "@withone/connect/react";
|
|
98
|
+
import { ConnectButton } from "@withone/connect/react";
|
|
137
99
|
|
|
138
100
|
<ConnectButton
|
|
139
101
|
authorizeUrl="/api/one/authorize"
|
|
140
|
-
platforms={["
|
|
141
|
-
connected={hasGrant}
|
|
142
|
-
onSuccess={() => { /* refetch app state
|
|
143
|
-
onError={(message
|
|
102
|
+
platforms={["gmail", "stripe"]} // connector slugs
|
|
103
|
+
connected={hasGrant} // from the server: await oneConnect.isConnected(userId)
|
|
104
|
+
onSuccess={() => { /* refetch app state */ }}
|
|
105
|
+
onError={(message) => { /* show message */ }}
|
|
144
106
|
/>
|
|
145
107
|
```
|
|
146
108
|
|
|
147
|
-
|
|
148
|
-
("sm" | "md" | "lg"), `fullWidth`, `theme` ("light" | "dark" | "auto"),
|
|
149
|
-
`
|
|
150
|
-
`description` (block), `onCancel` (user pressed Back on One's page).
|
|
151
|
-
|
|
152
|
-
Always pass `connected` from the server. Without it the button forgets after
|
|
153
|
-
a reload and asks the user to connect again.
|
|
154
|
-
|
|
155
|
-
Vue: `import { ConnectButton } from "@withone/connect/vue"` with the same props
|
|
156
|
-
in kebab case (`authorize-url`, `:connected`), and `@success`, `@error`,
|
|
157
|
-
`@cancel`. Svelte: `import { connectButton } from "@withone/connect/svelte"`
|
|
158
|
-
as `use:connectButton={{ authorizeUrl, platforms, connected, onSuccess }}`.
|
|
159
|
-
Anything else: `import "@withone/connect"` registers
|
|
160
|
-
`<one-connect-button authorize-url="/api/one/authorize" platforms="stripe, notion" connected>`,
|
|
161
|
-
which dispatches `success`, `error` (detail `{ message, code }`) and `cancel`.
|
|
162
|
-
A custom button in React: `const { open, status, error } = useOneConnect({ authorizeUrl })`
|
|
163
|
-
from `@withone/connect/react`. Elsewhere: `createConnectFlow({ authorizeUrl, onSuccess, onError }).open`.
|
|
164
|
-
|
|
165
|
-
The button renders in a shadow root with a constructed stylesheet, so it
|
|
166
|
-
works under a strict CSP. Allow `https://assets.withone.ai` in `img-src` for
|
|
167
|
-
the logos. Style it with `--one-connect-font`, `--one-connect-radius` and
|
|
168
|
-
`::part(button)`; do not wrap it in extra styling divs.
|
|
169
|
-
|
|
170
|
-
The flow is a same-tab redirect. The outcome is read once per page load:
|
|
171
|
-
every button shows it, and the callbacks fire once, on the first button
|
|
172
|
-
still mounted.
|
|
109
|
+
Optional props: `variant` ("default" | "accent" | "block"), `accentColor`,
|
|
110
|
+
`size` ("sm" | "md" | "lg"), `fullWidth`, `theme` ("light" | "dark" | "auto"),
|
|
111
|
+
`label`, `description`, `disabled`.
|
|
173
112
|
|
|
174
|
-
|
|
113
|
+
Vue: `@withone/connect/vue`, same props. Svelte: `use:connectButton` from
|
|
114
|
+
`@withone/connect/svelte`. Anything else: `import "@withone/connect"` and use
|
|
115
|
+
`<one-connect-button authorize-url="/api/one/authorize" platforms="gmail, stripe">`.
|
|
116
|
+
A custom button in React: `useOneConnect({ authorizeUrl })` returns `{ open, status }`.
|
|
175
117
|
|
|
176
|
-
|
|
118
|
+
## 6 - Calling One with the grant
|
|
177
119
|
|
|
178
120
|
```ts
|
|
179
|
-
const connections = await oneConnect.listConnections(userId);
|
|
180
|
-
// [{
|
|
181
|
-
// access.policy: "full" | "methods" (+ methods: ["GET", ...]) | "actions" (+ actions: [{ actionId, title, method }])
|
|
182
|
-
|
|
183
|
-
const actions = await oneConnect.listActions(userId, "gmail");
|
|
184
|
-
// [{ _id, title, method, path }] - what exists, not what is permitted
|
|
121
|
+
const connections = await oneConnect.listConnections(userId); // [{ key, platform, access }]
|
|
122
|
+
const actions = await oneConnect.listActions(userId, "gmail"); // [{ _id, title, method, path }]
|
|
185
123
|
|
|
186
124
|
const reply = await oneConnect.runAction(userId, {
|
|
187
125
|
connectionKey: connection.key,
|
|
@@ -190,41 +128,26 @@ const reply = await oneConnect.runAction(userId, {
|
|
|
190
128
|
path: action.path,
|
|
191
129
|
body: payload,
|
|
192
130
|
});
|
|
193
|
-
// { status, ok,
|
|
131
|
+
// { status, ok, data }
|
|
194
132
|
```
|
|
195
133
|
|
|
196
|
-
`
|
|
197
|
-
|
|
198
|
-
`oneConnect.fetch(userId, "/connections", init)`.
|
|
199
|
-
|
|
200
|
-
`OneConnectError` codes: `not_connected` (no tokens stored), `refresh_failed`
|
|
201
|
-
(One declared the grant dead: revoked, expired or reused; the tokens were
|
|
202
|
-
cleared; ask the user to connect again), `request_failed` (One answered with
|
|
203
|
-
an error or could not be reached; `status` carries it; during a refresh the
|
|
204
|
-
tokens are KEPT, so retry later rather than asking the user to reconnect).
|
|
205
|
-
|
|
206
|
-
To ask users for more tools later, edit the app's permission set in the
|
|
207
|
-
dashboard. The next Connect shows only the new tools as "needs one more
|
|
208
|
-
connection" and the callback stores the new pair; no code change.
|
|
134
|
+
A `403` means the call is outside what the user granted. Do not retry it.
|
|
135
|
+
A `refresh_failed` error means the grant ended; ask the user to connect again.
|
|
209
136
|
|
|
210
137
|
## 7 - Rules
|
|
211
138
|
|
|
212
|
-
- Never put the secret in
|
|
213
|
-
- Store tokens encrypted, keyed by the app's user.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
3. `runAction` on an action inside the grant reaches the provider; one outside
|
|
228
|
-
it returns `blockedByGrant: true`.
|
|
229
|
-
4. Revoking the app from the user's One dashboard makes the next call throw
|
|
230
|
-
`refresh_failed` or return `401`, and the app shows its reconnect prompt.
|
|
139
|
+
- Never put the client secret in browser code, logs or error reports.
|
|
140
|
+
- Store tokens encrypted, keyed by the app's user.
|
|
141
|
+
- The registered redirect URI and `ONE_REDIRECT_URI` must be identical.
|
|
142
|
+
- Do not build a completion page; the callback redirect is the completion.
|
|
143
|
+
- Do not write OAuth steps by hand; use the package.
|
|
144
|
+
|
|
145
|
+
## 8 - Done when
|
|
146
|
+
|
|
147
|
+
1. The button leads to One's page; after signing in and authorizing, the user
|
|
148
|
+
lands back in the app and `onSuccess` fires.
|
|
149
|
+
2. `listConnections` returns only the granted connections.
|
|
150
|
+
3. `runAction` works for an action inside the grant and returns `403` for
|
|
151
|
+
one outside it.
|
|
152
|
+
4. After the user revokes the app in their One dashboard, the app asks them
|
|
153
|
+
to connect again.
|
package/src/button.ts
CHANGED
|
@@ -31,7 +31,8 @@ const WHITE = "#FFFFFF";
|
|
|
31
31
|
|
|
32
32
|
const STYLES = `
|
|
33
33
|
:host{display:inline-block;vertical-align:middle;max-width:100%}
|
|
34
|
-
:host([data-full-width]),:host([
|
|
34
|
+
:host([data-full-width]),:host([full-width]:not([full-width="false"])),
|
|
35
|
+
:host([data-variant="block"]),:host([variant="block"]){display:block;width:100%}
|
|
35
36
|
.b{all:unset;box-sizing:border-box;position:relative;display:inline-flex;align-items:center;gap:var(--gap);
|
|
36
37
|
max-width:100%;cursor:pointer;user-select:none;-webkit-tap-highlight-color:transparent;
|
|
37
38
|
font-family:var(--one-connect-font,inherit);font-size:var(--fs);font-weight:500;line-height:1.2;letter-spacing:-.01em;
|
|
@@ -234,8 +235,11 @@ const flowOptions = (
|
|
|
234
235
|
});
|
|
235
236
|
|
|
236
237
|
/**
|
|
237
|
-
* Draws the button inside
|
|
238
|
-
*
|
|
238
|
+
* Draws the button inside the shadow root of an element you render, for
|
|
239
|
+
* wrappers that own their host (React, Vue). Nothing is written to the
|
|
240
|
+
* host's own attributes. For the layout rules, give the host
|
|
241
|
+
* `data-variant="<variant>"` and, for fullWidth, `data-full-width`;
|
|
242
|
+
* `mountConnectButton` does that for you.
|
|
239
243
|
*/
|
|
240
244
|
export function renderConnectButton(
|
|
241
245
|
host: HTMLElement,
|
|
@@ -307,18 +311,21 @@ export function renderConnectButton(
|
|
|
307
311
|
? (props.connectedLabel ?? "Connected")
|
|
308
312
|
: (props.label ?? "Connect your apps");
|
|
309
313
|
|
|
310
|
-
// Colour props travel as custom properties on the
|
|
311
|
-
// the CSSOM: allowed under a strict CSP,
|
|
314
|
+
// Colour props travel as custom properties on the button inside the
|
|
315
|
+
// shadow root, set through the CSSOM: allowed under a strict CSP, and
|
|
316
|
+
// never written to the host, whose attributes belong to whoever
|
|
317
|
+
// rendered it (a server-rendered page must hydrate unchanged).
|
|
312
318
|
if (variant === "accent") {
|
|
313
319
|
const accent = props.accentColor?.trim() || LIME;
|
|
314
|
-
|
|
315
|
-
|
|
320
|
+
button.style.setProperty("--one-connect-accent", accent);
|
|
321
|
+
button.style.setProperty(
|
|
322
|
+
"--one-connect-accent-fg",
|
|
323
|
+
readableTextOn(accent),
|
|
324
|
+
);
|
|
316
325
|
} else {
|
|
317
|
-
|
|
318
|
-
|
|
326
|
+
button.style.removeProperty("--one-connect-accent");
|
|
327
|
+
button.style.removeProperty("--one-connect-accent-fg");
|
|
319
328
|
}
|
|
320
|
-
host.toggleAttribute("data-full-width", Boolean(props.fullWidth));
|
|
321
|
-
host.setAttribute("data-variant", variant);
|
|
322
329
|
|
|
323
330
|
button.dataset.variant = variant;
|
|
324
331
|
button.dataset.size = props.size ?? "md";
|
|
@@ -408,10 +415,18 @@ export function mountConnectButton(
|
|
|
408
415
|
): ConnectButtonHandle {
|
|
409
416
|
const host = document.createElement("span");
|
|
410
417
|
host.className = "one-connect";
|
|
418
|
+
const layout = (next: ConnectButtonProps) => {
|
|
419
|
+
host.setAttribute("data-variant", next.variant ?? "default");
|
|
420
|
+
host.toggleAttribute("data-full-width", Boolean(next.fullWidth));
|
|
421
|
+
};
|
|
422
|
+
layout(props);
|
|
411
423
|
container.appendChild(host);
|
|
412
424
|
const handle = renderConnectButton(host, props);
|
|
413
425
|
return {
|
|
414
|
-
update:
|
|
426
|
+
update: (next) => {
|
|
427
|
+
layout(next);
|
|
428
|
+
handle.update(next);
|
|
429
|
+
},
|
|
415
430
|
destroy: () => {
|
|
416
431
|
handle.destroy();
|
|
417
432
|
host.remove();
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { createConnectFlow, readConnectReturn, useOneConnect } from "./flow";
|
|
2
|
-
export {
|
|
2
|
+
export {
|
|
3
|
+
mountConnectButton,
|
|
4
|
+
registerConnectButton,
|
|
5
|
+
renderConnectButton,
|
|
6
|
+
} from "./button";
|
|
3
7
|
export type {
|
|
4
8
|
ConnectButtonHandle,
|
|
5
9
|
ConnectButtonPlatform,
|