@withone/connect 0.8.3 → 0.10.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/README.md +156 -370
- package/dist/button.d.ts +9 -10
- package/dist/constants.d.ts +8 -4
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.esm.js +1 -1
- package/dist/next.cjs.js +104 -0
- package/dist/next.d.ts +36 -0
- package/dist/next.esm.js +98 -0
- package/dist/node.cjs.js +69 -0
- package/dist/node.d.ts +33 -0
- package/dist/node.esm.js +67 -0
- package/dist/platforms.d.ts +21 -0
- package/dist/react.cjs.js +1 -1
- package/dist/react.d.ts +2 -19
- package/dist/react.esm.js +1 -1
- package/dist/return.d.ts +11 -0
- package/dist/server/index.cjs.js +349 -0
- package/dist/server/index.d.ts +32 -0
- package/dist/server/index.esm.js +344 -0
- package/dist/server/oauth.d.ts +24 -0
- package/dist/server/types.d.ts +136 -0
- package/dist/svelte.cjs.js +1 -1
- package/dist/svelte.d.ts +14 -4
- package/dist/svelte.esm.js +1 -1
- package/dist/types.d.ts +78 -0
- package/dist/useOneConnect.d.ts +13 -2
- package/dist/vue.cjs.js +1 -1
- package/dist/vue.d.ts +19 -26
- package/dist/vue.esm.js +1 -1
- package/dist/wrapper-options.d.ts +20 -16
- package/package.json +37 -15
- package/skills/one-connect/SKILL.md +194 -0
- package/src/button.ts +115 -167
- package/src/constants.ts +10 -4
- package/src/index.ts +17 -2
- package/src/next.ts +133 -0
- package/src/node.ts +107 -0
- package/src/platforms.ts +89 -0
- package/src/react.ts +23 -66
- package/src/return.ts +30 -0
- package/src/server/index.ts +382 -0
- package/src/server/oauth.ts +98 -0
- package/src/server/types.ts +155 -0
- package/src/svelte.ts +15 -15
- package/src/types.ts +84 -0
- package/src/useOneConnect.ts +36 -69
- package/src/vue.ts +23 -30
- package/src/wrapper-options.ts +45 -25
- package/dist/index.umd.js +0 -1
- package/dist/types/index.d.ts +0 -92
- package/src/react-types.d.ts +0 -23
- package/src/svelte-types.d.ts +0 -27
- package/src/types/index.d.ts +0 -92
- package/src/vue-types.d.ts +0 -16
package/src/button.ts
CHANGED
|
@@ -1,80 +1,70 @@
|
|
|
1
|
+
import { normalizePlatforms, parsePlatformsAttribute } from "./platforms";
|
|
1
2
|
import { useOneConnect } from "./useOneConnect";
|
|
2
3
|
import type {
|
|
3
4
|
ConnectButtonHandle,
|
|
4
5
|
ConnectButtonOptions,
|
|
6
|
+
ConnectButtonState,
|
|
5
7
|
OneConnectHandle,
|
|
6
8
|
} from "./types";
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* the same way. Zero dependencies, zero One URLs — provider icons are
|
|
14
|
-
* passed in by the consumer.
|
|
11
|
+
* The pre-built trigger for the connect flow. Optional: `useOneConnect`
|
|
12
|
+
* with any element remains fully supported. Framework-agnostic: it
|
|
13
|
+
* renders real DOM into a container, so React, Vue, Svelte and plain
|
|
14
|
+
* HTML all mount it the same way.
|
|
15
15
|
*
|
|
16
|
-
* The button owns the flow wiring: click opens the
|
|
17
|
-
* turns "Connecting
|
|
18
|
-
*
|
|
19
|
-
* verb never changes).
|
|
16
|
+
* The button owns the flow wiring: a click opens the flow, the label
|
|
17
|
+
* turns "Connecting" while the tab is away, and lands on "Connected"
|
|
18
|
+
* when the return carries a success.
|
|
20
19
|
*/
|
|
21
20
|
|
|
22
21
|
const STYLE_ID = "one-connect-button-styles";
|
|
23
22
|
const EASE = "cubic-bezier(.2,.9,.25,1)";
|
|
23
|
+
const MAX_VISIBLE_CHIPS = 3;
|
|
24
|
+
|
|
25
|
+
/** One's palette (see the Clockwork design system): lime is the brand
|
|
26
|
+
* call-to-action, spring is success, carbon is the ink. */
|
|
27
|
+
const LIME = "#CCFF00";
|
|
28
|
+
const SPRING = "#3FE3A5";
|
|
29
|
+
const CARBON = "#0A0C0B";
|
|
24
30
|
|
|
25
31
|
interface Palette {
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
buttonBackground: string;
|
|
33
|
+
buttonForeground: string;
|
|
28
34
|
surface: string;
|
|
29
|
-
|
|
35
|
+
foreground: string;
|
|
30
36
|
muted: string;
|
|
31
37
|
line: string;
|
|
32
38
|
shadow: string;
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
const LIGHT: Palette = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
surface: "#
|
|
39
|
-
|
|
42
|
+
buttonBackground: CARBON,
|
|
43
|
+
buttonForeground: "#FFFFFF",
|
|
44
|
+
surface: "#FFFFFF",
|
|
45
|
+
foreground: CARBON,
|
|
40
46
|
muted: "#6B7280",
|
|
41
47
|
line: "#D1D5DB",
|
|
42
48
|
shadow: "0 1px 2px rgba(10,12,11,.08), 0 4px 14px rgba(10,12,11,.06)",
|
|
43
49
|
};
|
|
44
50
|
|
|
45
51
|
const DARK: Palette = {
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
buttonBackground: "#F2F5F3",
|
|
53
|
+
buttonForeground: CARBON,
|
|
48
54
|
surface: "#101312",
|
|
49
|
-
|
|
55
|
+
foreground: "#F2F5F3",
|
|
50
56
|
muted: "#8A938E",
|
|
51
57
|
line: "#2A302D",
|
|
52
58
|
shadow: "0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35)",
|
|
53
59
|
};
|
|
54
60
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* falls back to the first letter if a name has no matching asset. */
|
|
63
|
-
function logoUrlFromName(name: string): string {
|
|
64
|
-
const slug = name
|
|
65
|
-
.trim()
|
|
66
|
-
.toLowerCase()
|
|
67
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
68
|
-
.replace(/^-+|-+$/g, "");
|
|
69
|
-
return slug
|
|
70
|
-
? `https://assets.withone.ai/connectors/${slug}.svg`
|
|
71
|
-
: "";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** The One ring mark — same glyph the card footer pairs with the
|
|
75
|
-
* wordmark. Inline so the SDK stays free of One URLs. */
|
|
76
|
-
const ONE_MARK_SVG =
|
|
77
|
-
'<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2.4" style="flex-shrink:0"><circle cx="12" cy="12" r="8.5"/></svg>';
|
|
61
|
+
/** One's lockup — the mark and the wordmark as one asset, every fill set
|
|
62
|
+
* to `currentColor` so a single copy works on either palette. Inlined
|
|
63
|
+
* rather than fetched: this is the trust mark, and it has to draw even
|
|
64
|
+
* behind a strict content policy or offline. Source:
|
|
65
|
+
* core-ui/public/logo/logo-full-dark.svg (viewBox 3152x990). */
|
|
66
|
+
const ONE_LOCKUP_SVG =
|
|
67
|
+
'<svg viewBox="0 0 3152 990" width="35" height="11" fill="none" aria-hidden="true" style="flex-shrink:0;display:block"><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>';
|
|
78
68
|
const ARROW_SVG =
|
|
79
69
|
'<svg class="owcb-arrow" width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M6 3l5 5-5 5"/></svg>';
|
|
80
70
|
const TICK_SVG =
|
|
@@ -92,16 +82,17 @@ function ensureStyles(): void {
|
|
|
92
82
|
`.owcb:focus-visible{outline:2px solid ${SPRING};outline-offset:3px}`,
|
|
93
83
|
".owcb[disabled]{cursor:default;opacity:.75;transform:none}",
|
|
94
84
|
".owcb-stack{display:inline-flex;align-items:center;flex-shrink:0}",
|
|
95
|
-
`.owcb-chip{width:22px;height:22px;border-radius:6px;display:grid;place-items:center;overflow:hidden;margin-left:-7px;transition:margin-left .28s ${EASE};position:relative}`,
|
|
85
|
+
`.owcb-chip{width:22px;height:22px;border-radius:6px;display:grid;place-items:center;overflow:hidden;margin-left:-7px;transition:margin-left .28s ${EASE};position:relative;background:#FFFFFF}`,
|
|
96
86
|
".owcb-chip:first-child{margin-left:0}",
|
|
97
87
|
".owcb-chip img{width:14px;height:14px;display:block;object-fit:contain}",
|
|
98
|
-
|
|
88
|
+
`.owcb-chip.owcb-more{font-family:ui-monospace,monospace;font-size:9px;font-weight:500;letter-spacing:-.02em;color:${CARBON}}`,
|
|
89
|
+
`.owcb-chip.owcb-letter{font:600 10px ui-monospace,monospace;color:${CARBON}}`,
|
|
99
90
|
".owcb:hover .owcb-chip{margin-left:-2px}",
|
|
100
91
|
".owcb:hover .owcb-chip:first-child{margin-left:0}",
|
|
101
92
|
".owcb-label{white-space:nowrap}",
|
|
102
93
|
`.owcb-arrow{opacity:.5;transition:transform .2s ${EASE},opacity .2s ${EASE}}`,
|
|
103
94
|
".owcb:hover .owcb-arrow{transform:translateX(2px);opacity:.8}",
|
|
104
|
-
|
|
95
|
+
".owcb-spinner{width:16px;height:16px;border-radius:50%;border:2px solid currentColor;border-top-color:transparent;opacity:.7;animation:owcb-spin .7s linear infinite}",
|
|
105
96
|
"@keyframes owcb-spin{to{transform:rotate(360deg)}}",
|
|
106
97
|
".owcb.owcb-block{display:flex;flex-direction:column;align-items:stretch;width:100%;max-width:420px;text-align:left;padding:16px;border-radius:14px;gap:0}",
|
|
107
98
|
".owcb-block-top{display:flex;align-items:center;justify-content:space-between;gap:12px}",
|
|
@@ -116,53 +107,35 @@ function ensureStyles(): void {
|
|
|
116
107
|
function buildStack(
|
|
117
108
|
options: ConnectButtonOptions,
|
|
118
109
|
chipRing: string,
|
|
119
|
-
moreColor: string,
|
|
120
110
|
): HTMLElement | null {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const MAX_VISIBLE_CHIPS = 3;
|
|
124
|
-
const platforms = options.platforms ?? [];
|
|
125
|
-
if (platforms.length === 0 && !options.moreCount) return null;
|
|
111
|
+
const platforms = normalizePlatforms(options.platforms);
|
|
112
|
+
if (platforms.length === 0) return null;
|
|
126
113
|
const stack = document.createElement("span");
|
|
127
114
|
stack.className = "owcb-stack";
|
|
128
115
|
stack.setAttribute("aria-hidden", "true");
|
|
129
116
|
for (const platform of platforms.slice(0, MAX_VISIBLE_CHIPS)) {
|
|
130
117
|
const chip = document.createElement("span");
|
|
131
118
|
chip.className = "owcb-chip";
|
|
132
|
-
chip.
|
|
119
|
+
chip.title = platform.name;
|
|
133
120
|
chip.style.boxShadow = `0 0 0 1.5px ${chipRing}`;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
121
|
+
const img = document.createElement("img");
|
|
122
|
+
img.alt = "";
|
|
123
|
+
img.src = platform.imageUrl;
|
|
124
|
+
img.addEventListener("error", () => {
|
|
125
|
+
img.remove();
|
|
126
|
+
chip.classList.add("owcb-letter");
|
|
138
127
|
chip.textContent = platform.name.charAt(0).toUpperCase();
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
};
|
|
142
|
-
const src = platform.imageUrl ?? logoUrlFromName(platform.name);
|
|
143
|
-
if (src) {
|
|
144
|
-
const img = document.createElement("img");
|
|
145
|
-
img.alt = "";
|
|
146
|
-
img.src = src;
|
|
147
|
-
img.addEventListener("error", () => {
|
|
148
|
-
img.remove();
|
|
149
|
-
letterFallback();
|
|
150
|
-
});
|
|
151
|
-
chip.appendChild(img);
|
|
152
|
-
} else {
|
|
153
|
-
letterFallback();
|
|
154
|
-
}
|
|
128
|
+
});
|
|
129
|
+
chip.appendChild(img);
|
|
155
130
|
stack.appendChild(chip);
|
|
156
131
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
132
|
+
// Only ever the apps the caller listed beyond the first three: the chip
|
|
133
|
+
// can never claim a number that has nothing to do with them.
|
|
134
|
+
const extra = Math.max(0, platforms.length - MAX_VISIBLE_CHIPS);
|
|
160
135
|
if (extra > 0) {
|
|
161
136
|
const more = document.createElement("span");
|
|
162
137
|
more.className = "owcb-chip owcb-more";
|
|
163
|
-
more.style.background = "#ffffff";
|
|
164
138
|
more.style.boxShadow = `0 0 0 1.5px ${chipRing}`;
|
|
165
|
-
more.style.color = moreColor;
|
|
166
139
|
more.textContent = `+${extra}`;
|
|
167
140
|
stack.appendChild(more);
|
|
168
141
|
}
|
|
@@ -178,23 +151,20 @@ export const mountConnectButton = (
|
|
|
178
151
|
const palette = options.theme === "dark" ? DARK : LIGHT;
|
|
179
152
|
const variant = options.variant ?? "default";
|
|
180
153
|
const label = options.label ?? "Connect your apps";
|
|
154
|
+
const connectedLabel = options.connectedLabel ?? "Connected";
|
|
181
155
|
|
|
182
|
-
let state:
|
|
156
|
+
let state: ConnectButtonState = "idle";
|
|
183
157
|
let destroyed = false;
|
|
184
158
|
|
|
185
|
-
const
|
|
159
|
+
const flow: OneConnectHandle = useOneConnect({
|
|
186
160
|
...options.connect,
|
|
187
161
|
onSuccess: () => {
|
|
188
162
|
setState("connected");
|
|
189
163
|
options.connect.onSuccess?.();
|
|
190
164
|
},
|
|
191
|
-
onError: (
|
|
165
|
+
onError: (message) => {
|
|
192
166
|
setState("idle");
|
|
193
|
-
options.connect.onError?.(
|
|
194
|
-
},
|
|
195
|
-
onClose: () => {
|
|
196
|
-
setState("idle");
|
|
197
|
-
options.connect.onClose?.();
|
|
167
|
+
options.connect.onError?.(message);
|
|
198
168
|
},
|
|
199
169
|
});
|
|
200
170
|
|
|
@@ -202,52 +172,54 @@ export const mountConnectButton = (
|
|
|
202
172
|
button.type = "button";
|
|
203
173
|
button.className = variant === "block" ? "owcb owcb-block" : "owcb";
|
|
204
174
|
button.addEventListener("click", () => {
|
|
205
|
-
if (state
|
|
175
|
+
if (state === "connecting") return;
|
|
206
176
|
setState("connecting");
|
|
207
|
-
|
|
177
|
+
flow.open();
|
|
208
178
|
});
|
|
209
179
|
|
|
180
|
+
const titleFor = (): string =>
|
|
181
|
+
state === "connecting"
|
|
182
|
+
? "Connecting…"
|
|
183
|
+
: state === "connected"
|
|
184
|
+
? connectedLabel
|
|
185
|
+
: label;
|
|
186
|
+
|
|
210
187
|
const paint = () => {
|
|
211
188
|
const accent = variant === "accent";
|
|
212
189
|
const block = variant === "block";
|
|
213
|
-
const
|
|
190
|
+
const background = block
|
|
214
191
|
? palette.surface
|
|
215
192
|
: accent
|
|
216
193
|
? (options.accentColor ?? LIME)
|
|
217
|
-
: palette.
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
button.style.color = state === "connected" && !block ? CARBON :
|
|
194
|
+
: palette.buttonBackground;
|
|
195
|
+
const foreground = block
|
|
196
|
+
? palette.foreground
|
|
197
|
+
: accent
|
|
198
|
+
? CARBON
|
|
199
|
+
: palette.buttonForeground;
|
|
200
|
+
const chipRing = block ? palette.surface : background;
|
|
201
|
+
|
|
202
|
+
button.style.background =
|
|
203
|
+
state === "connected" && !block ? SPRING : background;
|
|
204
|
+
button.style.color = state === "connected" && !block ? CARBON : foreground;
|
|
228
205
|
button.style.boxShadow = block
|
|
229
206
|
? `inset 0 0 0 1px ${palette.line}`
|
|
230
207
|
: state === "connected"
|
|
231
208
|
? "none"
|
|
232
209
|
: accent
|
|
233
|
-
? `0 1px 2px rgba(10,12,11,.1), 0 6px 20px ${
|
|
210
|
+
? `0 1px 2px rgba(10,12,11,.1), 0 6px 20px ${options.accentColor ?? LIME}38`
|
|
234
211
|
: palette.shadow;
|
|
235
212
|
button.disabled = state === "connecting";
|
|
236
213
|
button.innerHTML = "";
|
|
237
214
|
|
|
238
|
-
const stack = buildStack(options, chipRing
|
|
215
|
+
const stack = buildStack(options, chipRing);
|
|
239
216
|
|
|
240
217
|
if (block) {
|
|
241
218
|
const top = document.createElement("span");
|
|
242
219
|
top.className = "owcb-block-top";
|
|
243
220
|
const title = document.createElement("span");
|
|
244
221
|
title.className = "owcb-block-title";
|
|
245
|
-
title.textContent =
|
|
246
|
-
state === "connecting"
|
|
247
|
-
? "Connecting…"
|
|
248
|
-
: state === "connected"
|
|
249
|
-
? (options.connectedLabel ?? "Connected")
|
|
250
|
-
: label;
|
|
222
|
+
title.textContent = titleFor();
|
|
251
223
|
top.appendChild(title);
|
|
252
224
|
if (state === "connecting") {
|
|
253
225
|
const spinner = document.createElement("span");
|
|
@@ -264,17 +236,13 @@ export const mountConnectButton = (
|
|
|
264
236
|
sub.textContent = options.description;
|
|
265
237
|
button.appendChild(sub);
|
|
266
238
|
}
|
|
267
|
-
// Mirrors the card/overlay footer strip: "Secured by" + ring mark
|
|
268
|
-
// + "one" wordmark, so the button and the surface it opens read as
|
|
269
|
-
// the same product.
|
|
270
239
|
const foot = document.createElement("span");
|
|
271
240
|
foot.className = "owcb-block-foot";
|
|
272
241
|
foot.style.color = palette.muted;
|
|
273
242
|
foot.style.borderTop = `1px solid ${palette.line}`;
|
|
274
243
|
foot.innerHTML =
|
|
275
244
|
`<span style="font-size:11px;color:${palette.muted}">Secured by</span>` +
|
|
276
|
-
`<span style="display:inline-flex;color:${palette.
|
|
277
|
-
`<span style="font-size:12px;font-weight:600;letter-spacing:-0.02em;color:${palette.fg}">one</span>`;
|
|
245
|
+
`<span style="display:inline-flex;color:${palette.foreground}">${ONE_LOCKUP_SVG}</span>`;
|
|
278
246
|
button.appendChild(foot);
|
|
279
247
|
return;
|
|
280
248
|
}
|
|
@@ -294,12 +262,7 @@ export const mountConnectButton = (
|
|
|
294
262
|
|
|
295
263
|
const text = document.createElement("span");
|
|
296
264
|
text.className = "owcb-label";
|
|
297
|
-
text.textContent =
|
|
298
|
-
state === "connecting"
|
|
299
|
-
? "Connecting…"
|
|
300
|
-
: state === "connected"
|
|
301
|
-
? (options.connectedLabel ?? "Connected")
|
|
302
|
-
: label;
|
|
265
|
+
text.textContent = titleFor();
|
|
303
266
|
button.appendChild(text);
|
|
304
267
|
|
|
305
268
|
if (state === "idle") {
|
|
@@ -310,7 +273,7 @@ export const mountConnectButton = (
|
|
|
310
273
|
}
|
|
311
274
|
};
|
|
312
275
|
|
|
313
|
-
const setState = (next:
|
|
276
|
+
const setState = (next: ConnectButtonState) => {
|
|
314
277
|
if (destroyed) return;
|
|
315
278
|
state = next;
|
|
316
279
|
paint();
|
|
@@ -323,26 +286,24 @@ export const mountConnectButton = (
|
|
|
323
286
|
setState,
|
|
324
287
|
destroy: () => {
|
|
325
288
|
destroyed = true;
|
|
326
|
-
handle.close({ keepResult: true });
|
|
327
289
|
button.remove();
|
|
328
290
|
},
|
|
329
291
|
};
|
|
330
292
|
};
|
|
331
293
|
|
|
332
294
|
/**
|
|
333
|
-
* <one-connect-button
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* (Next.js SSR) never touches HTMLElement.
|
|
295
|
+
* <one-connect-button>: one tag for any framework. The element wires the
|
|
296
|
+
* whole flow from its attributes and manages Connect, Connecting and
|
|
297
|
+
* Connected. Registered automatically in the browser on import; defined
|
|
298
|
+
* inside a function so importing this module on a server never touches
|
|
299
|
+
* HTMLElement.
|
|
339
300
|
*
|
|
340
301
|
* Attributes: authorize-url (required), app-theme, label, variant,
|
|
341
|
-
* theme, platforms (
|
|
302
|
+
* theme, platforms ("stripe, notion" or a JSON array),
|
|
342
303
|
* description, accent-color, connected-label.
|
|
343
|
-
* Events: "success"
|
|
344
|
-
*
|
|
345
|
-
*
|
|
304
|
+
* Events: "success" and "error" (detail: message), plus the matching
|
|
305
|
+
* onSuccess and onError function properties that React 19, Vue and
|
|
306
|
+
* Svelte set naturally as props.
|
|
346
307
|
*/
|
|
347
308
|
export function registerConnectButton(): void {
|
|
348
309
|
if (typeof window === "undefined" || typeof customElements === "undefined")
|
|
@@ -357,15 +318,13 @@ export function registerConnectButton(): void {
|
|
|
357
318
|
"variant",
|
|
358
319
|
"theme",
|
|
359
320
|
"platforms",
|
|
360
|
-
"more-count",
|
|
361
321
|
"description",
|
|
362
322
|
"accent-color",
|
|
363
323
|
"connected-label",
|
|
364
324
|
];
|
|
365
325
|
|
|
366
326
|
onSuccess: (() => void) | null = null;
|
|
367
|
-
onError: ((
|
|
368
|
-
onClose: (() => void) | null = null;
|
|
327
|
+
onError: ((message: string) => void) | null = null;
|
|
369
328
|
|
|
370
329
|
private handle: ConnectButtonHandle | null = null;
|
|
371
330
|
|
|
@@ -386,49 +345,25 @@ export function registerConnectButton(): void {
|
|
|
386
345
|
this.handle?.destroy();
|
|
387
346
|
this.handle = null;
|
|
388
347
|
const authorizeUrl = this.getAttribute("authorize-url");
|
|
389
|
-
if (!authorizeUrl) return;
|
|
390
|
-
|
|
391
|
-
let platforms: ConnectButtonOptions["platforms"];
|
|
392
|
-
const rawPlatforms = this.getAttribute("platforms");
|
|
393
|
-
if (rawPlatforms) {
|
|
394
|
-
try {
|
|
395
|
-
const parsed = JSON.parse(rawPlatforms) as unknown;
|
|
396
|
-
if (Array.isArray(parsed)) platforms = parsed;
|
|
397
|
-
} catch {
|
|
398
|
-
/* malformed platforms JSON — render without chips */
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const moreCountRaw = this.getAttribute("more-count");
|
|
403
|
-
const moreCount = moreCountRaw ? parseInt(moreCountRaw, 10) : undefined;
|
|
348
|
+
if (!authorizeUrl) return;
|
|
404
349
|
|
|
405
350
|
this.handle = mountConnectButton(this, {
|
|
406
351
|
connect: {
|
|
407
|
-
|
|
408
|
-
appTheme:
|
|
409
|
-
(this.getAttribute("app-theme") as "light" | "dark" | null) ??
|
|
410
|
-
undefined,
|
|
352
|
+
authorizeUrl,
|
|
353
|
+
appTheme: attributeAs(this, "app-theme", ["light", "dark"]),
|
|
411
354
|
onSuccess: () => {
|
|
412
355
|
this.onSuccess?.();
|
|
413
356
|
this.dispatchEvent(new CustomEvent("success"));
|
|
414
357
|
},
|
|
415
|
-
onError: (
|
|
416
|
-
this.onError?.(
|
|
417
|
-
this.dispatchEvent(new CustomEvent("error", { detail:
|
|
418
|
-
},
|
|
419
|
-
onClose: () => {
|
|
420
|
-
this.onClose?.();
|
|
421
|
-
this.dispatchEvent(new CustomEvent("close"));
|
|
358
|
+
onError: (message) => {
|
|
359
|
+
this.onError?.(message);
|
|
360
|
+
this.dispatchEvent(new CustomEvent("error", { detail: message }));
|
|
422
361
|
},
|
|
423
362
|
},
|
|
424
363
|
label: this.getAttribute("label") ?? undefined,
|
|
425
|
-
variant:
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
theme:
|
|
429
|
-
(this.getAttribute("theme") as "light" | "dark" | null) ?? undefined,
|
|
430
|
-
platforms,
|
|
431
|
-
moreCount: Number.isFinite(moreCount) ? moreCount : undefined,
|
|
364
|
+
variant: attributeAs(this, "variant", ["default", "accent", "block"]),
|
|
365
|
+
theme: attributeAs(this, "theme", ["light", "dark"]),
|
|
366
|
+
platforms: parsePlatformsAttribute(this.getAttribute("platforms")),
|
|
432
367
|
description: this.getAttribute("description") ?? undefined,
|
|
433
368
|
accentColor: this.getAttribute("accent-color") ?? undefined,
|
|
434
369
|
connectedLabel: this.getAttribute("connected-label") ?? undefined,
|
|
@@ -439,4 +374,17 @@ export function registerConnectButton(): void {
|
|
|
439
374
|
customElements.define("one-connect-button", OneConnectButtonElement);
|
|
440
375
|
}
|
|
441
376
|
|
|
377
|
+
/** An attribute narrowed to a known set of values; anything else is
|
|
378
|
+
* treated as unset rather than passed through. */
|
|
379
|
+
function attributeAs<T extends string>(
|
|
380
|
+
element: HTMLElement,
|
|
381
|
+
name: string,
|
|
382
|
+
allowed: readonly T[],
|
|
383
|
+
): T | undefined {
|
|
384
|
+
const value = element.getAttribute(name);
|
|
385
|
+
return value && (allowed as readonly string[]).includes(value)
|
|
386
|
+
? (value as T)
|
|
387
|
+
: undefined;
|
|
388
|
+
}
|
|
389
|
+
|
|
442
390
|
registerConnectButton();
|
package/src/constants.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
/** Query params the
|
|
2
|
-
*
|
|
3
|
-
*
|
|
1
|
+
/** Query params the app's callback route puts on its final redirect.
|
|
2
|
+
* The SDK reads them off the page URL when the tab comes home, so
|
|
3
|
+
* there is no completion page to build. */
|
|
4
4
|
export const RETURN_STATUS_PARAM = "one_connect";
|
|
5
5
|
export const RETURN_MESSAGE_PARAM = "one_connect_message";
|
|
6
6
|
|
|
7
7
|
/** Fragment key on the authorize URL carrying the app-chosen theme.
|
|
8
8
|
* A fragment never reaches any server and survives the whole redirect
|
|
9
|
-
* chain, so the
|
|
9
|
+
* chain, so the app's backend forwards nothing. */
|
|
10
10
|
export const THEME_PARAM = "one_theme";
|
|
11
|
+
|
|
12
|
+
/** One's connector logos, by slug. */
|
|
13
|
+
export const CONNECTOR_ASSETS_URL = "https://assets.withone.ai/connectors";
|
|
14
|
+
|
|
15
|
+
/** One's production API. Point `oneApiUrl` elsewhere for development. */
|
|
16
|
+
export const DEFAULT_ONE_API_URL = "https://api.withone.ai";
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
export { useOneConnect } from "./useOneConnect";
|
|
2
2
|
export { mountConnectButton, registerConnectButton } from "./button";
|
|
3
|
+
export {
|
|
4
|
+
optionsFromProps,
|
|
5
|
+
propsIdentity,
|
|
6
|
+
type ConnectButtonProps,
|
|
7
|
+
type ConnectButtonCallbacks,
|
|
8
|
+
} from "./wrapper-options";
|
|
9
|
+
export {
|
|
10
|
+
normalizePlatform,
|
|
11
|
+
normalizePlatforms,
|
|
12
|
+
parsePlatformsAttribute,
|
|
13
|
+
} from "./platforms";
|
|
3
14
|
export type {
|
|
4
|
-
|
|
15
|
+
OneConnectOptions,
|
|
5
16
|
OneConnectHandle,
|
|
6
|
-
|
|
17
|
+
OneConnectReturn,
|
|
18
|
+
OneConnectTheme,
|
|
7
19
|
ConnectButtonOptions,
|
|
8
20
|
ConnectButtonPlatform,
|
|
21
|
+
ConnectButtonPlatformInput,
|
|
22
|
+
ConnectButtonVariant,
|
|
23
|
+
ConnectButtonState,
|
|
9
24
|
ConnectButtonHandle,
|
|
10
25
|
} from "./types";
|