cabalspy-id 0.0.0-stage → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +146 -0
  2. package/LICENSE +21 -0
  3. package/README.md +504 -2
  4. package/dist/api.cjs +74 -0
  5. package/dist/api.cjs.map +1 -0
  6. package/dist/api.d.cts +193 -0
  7. package/dist/api.d.ts +193 -0
  8. package/dist/api.js +74 -0
  9. package/dist/api.js.map +1 -0
  10. package/dist/chunk-A2ZAFAWC.cjs +1 -0
  11. package/dist/chunk-A2ZAFAWC.cjs.map +1 -0
  12. package/dist/chunk-ABFIPCBY.cjs +109 -0
  13. package/dist/chunk-ABFIPCBY.cjs.map +1 -0
  14. package/dist/chunk-CJFIOVBA.js +1 -0
  15. package/dist/chunk-CJFIOVBA.js.map +1 -0
  16. package/dist/chunk-DBYCRBVS.js +400 -0
  17. package/dist/chunk-DBYCRBVS.js.map +1 -0
  18. package/dist/chunk-PKFIMBPW.cjs +444 -0
  19. package/dist/chunk-PKFIMBPW.cjs.map +1 -0
  20. package/dist/chunk-ULEBNY2A.cjs +1301 -0
  21. package/dist/chunk-ULEBNY2A.cjs.map +1 -0
  22. package/dist/chunk-VDFCMYLR.cjs +400 -0
  23. package/dist/chunk-VDFCMYLR.cjs.map +1 -0
  24. package/dist/chunk-VOTYIQAY.js +109 -0
  25. package/dist/chunk-VOTYIQAY.js.map +1 -0
  26. package/dist/chunk-XLBO2RSL.js +1301 -0
  27. package/dist/chunk-XLBO2RSL.js.map +1 -0
  28. package/dist/chunk-Z23B5TY6.js +444 -0
  29. package/dist/chunk-Z23B5TY6.js.map +1 -0
  30. package/dist/index.cjs +105 -0
  31. package/dist/index.cjs.map +1 -0
  32. package/dist/index.d.cts +21 -0
  33. package/dist/index.d.ts +21 -0
  34. package/dist/index.js +105 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/react.cjs +361 -0
  37. package/dist/react.cjs.map +1 -0
  38. package/dist/react.d.cts +315 -0
  39. package/dist/react.d.ts +315 -0
  40. package/dist/react.js +333 -0
  41. package/dist/react.js.map +1 -0
  42. package/dist/thesis.cjs +76 -0
  43. package/dist/thesis.cjs.map +1 -0
  44. package/dist/thesis.d.cts +221 -0
  45. package/dist/thesis.d.ts +221 -0
  46. package/dist/thesis.js +76 -0
  47. package/dist/thesis.js.map +1 -0
  48. package/dist/types-UZeY9n1e.d.cts +689 -0
  49. package/dist/types-UZeY9n1e.d.ts +689 -0
  50. package/dist/users-3DAw88_U.d.cts +767 -0
  51. package/dist/users-B4r33i4O.d.ts +767 -0
  52. package/dist/widget.cjs +233 -0
  53. package/dist/widget.cjs.map +1 -0
  54. package/dist/widget.d.cts +226 -0
  55. package/dist/widget.d.ts +226 -0
  56. package/dist/widget.js +233 -0
  57. package/dist/widget.js.map +1 -0
  58. package/package.json +145 -4
@@ -0,0 +1,233 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkABFIPCBYcjs = require('./chunk-ABFIPCBY.cjs');
4
+
5
+ // src/widget.ts
6
+ var WIDGET_SRC = "https://id.cabalspy.xyz/widget.js";
7
+ var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
8
+ var loaders = /* @__PURE__ */ new Map();
9
+ function loadCabalSpyIDWidget(src = WIDGET_SRC) {
10
+ if (!isBrowser()) return Promise.reject(new Error("CabalSpy ID widget needs a browser"));
11
+ if (_optionalChain([window, 'access', _ => _.CSID, 'optionalAccess', _2 => _2.__loaded])) return Promise.resolve(window.CSID);
12
+ let p = loaders.get(src);
13
+ if (p && !document.querySelector(`script[src="${src}"]`)) {
14
+ loaders.delete(src);
15
+ p = void 0;
16
+ }
17
+ if (!p) {
18
+ p = new Promise((resolve, reject) => {
19
+ const done = () => window.CSID ? resolve(window.CSID) : reject(new Error("widget.js loaded but window.CSID is missing"));
20
+ let script = document.querySelector(`script[src="${src}"]`);
21
+ if (script && window.CSID) return done();
22
+ if (!script) {
23
+ script = document.createElement("script");
24
+ script.src = src;
25
+ script.async = true;
26
+ document.head.appendChild(script);
27
+ }
28
+ script.addEventListener("load", done, { once: true });
29
+ script.addEventListener(
30
+ "error",
31
+ () => {
32
+ loaders.delete(src);
33
+ reject(new Error(`Could not load ${src}`));
34
+ },
35
+ { once: true }
36
+ );
37
+ });
38
+ loaders.set(src, p);
39
+ }
40
+ return p;
41
+ }
42
+ function audOf(idToken) {
43
+ try {
44
+ const part = idToken.split(".")[1].replace(/-/g, "+").replace(/_/g, "/");
45
+ const aud = JSON.parse(atob(part + "=".repeat((4 - part.length % 4) % 4))).aud;
46
+ return Array.isArray(aud) ? aud[0] : aud;
47
+ } catch (e2) {
48
+ return void 0;
49
+ }
50
+ }
51
+ var bool = (v) => v === void 0 ? void 0 : v ? "true" : "false";
52
+ var num = (v) => v === void 0 ? void 0 : String(v);
53
+ function loginButtonAttributes(o) {
54
+ return {
55
+ "data-csid-login": "",
56
+ "data-client-id": o.clientId,
57
+ "data-theme": o.theme,
58
+ "data-color": o.color,
59
+ "data-text-color": o.textColor,
60
+ "data-shape": o.shape,
61
+ "data-size": o.size,
62
+ "data-label": o.label,
63
+ "data-full-width": bool(o.fullWidth),
64
+ "data-show-logo": bool(o.showLogo),
65
+ "data-href": o.href,
66
+ "data-redirect-uri": o.redirectUri,
67
+ "data-scope": Array.isArray(o.scope) ? o.scope.join(" ") : o.scope,
68
+ "data-user": o.user,
69
+ "data-logout-href": o.logoutHref
70
+ };
71
+ }
72
+ function thesisWidgetAttributes(o) {
73
+ if (typeof _optionalChain([o, 'optionalAccess', _3 => _3.clientId]) !== "string" || !o.clientId.trim()) {
74
+ throw new (0, _chunkABFIPCBYcjs.AuthenticationError)(
75
+ "The theses widget needs your instance's public client_id (csid_..., shown in the dashboard next to the API key): { clientId: 'csid_...' }. It is not the API key; never put the API key in a browser.",
76
+ { code: "client_id_required", parameter: "clientId", docs: "https://docs.cabalspy.xyz/cabalspy-id/errors#client_id_required" }
77
+ );
78
+ }
79
+ return {
80
+ "data-csid-thesis": "",
81
+ "data-chain": o.chain,
82
+ "data-mint": o.mint,
83
+ "data-client-id": o.clientId.trim(),
84
+ "data-theme": o.theme,
85
+ "data-scope": o.scope,
86
+ "data-sort": o.sort,
87
+ "data-font": o.font,
88
+ "data-radius": num(o.radius),
89
+ "data-bg": o.bg,
90
+ "data-card": o.card,
91
+ "data-text": o.text,
92
+ "data-muted": o.muted,
93
+ "data-border": o.border,
94
+ "data-accent": o.accent,
95
+ "data-accent-text": o.accentText,
96
+ "data-bull": o.bull,
97
+ "data-bear": o.bear,
98
+ "data-show-header": bool(o.showHeader),
99
+ "data-show-sentiment": bool(o.showSentiment),
100
+ "data-compact": bool(o.compact),
101
+ "data-height": num(o.height)
102
+ };
103
+ }
104
+ function onWidgetEvents(handlers, clientId) {
105
+ if (!isBrowser()) return () => void 0;
106
+ const login = (e) => {
107
+ const d = e.detail;
108
+ const aud = _optionalChain([d, 'optionalAccess', _4 => _4.idToken]) ? audOf(d.idToken) : void 0;
109
+ if (clientId && aud !== void 0 && aud !== clientId) return;
110
+ _optionalChain([handlers, 'access', _5 => _5.onLogin, 'optionalCall', _6 => _6(d)]);
111
+ };
112
+ const logout = (e) => {
113
+ const d = e.detail;
114
+ if (clientId && _optionalChain([d, 'optionalAccess', _7 => _7.clientId]) && d.clientId !== clientId) return;
115
+ _optionalChain([handlers, 'access', _8 => _8.onLogout, 'optionalCall', _9 => _9(d)]);
116
+ };
117
+ const error = (e) => _optionalChain([handlers, 'access', _10 => _10.onError, 'optionalCall', _11 => _11(e.detail)]);
118
+ window.addEventListener("csid:login", login);
119
+ window.addEventListener("csid:logout", logout);
120
+ window.addEventListener("csid:error", error);
121
+ return () => {
122
+ window.removeEventListener("csid:login", login);
123
+ window.removeEventListener("csid:logout", logout);
124
+ window.removeEventListener("csid:error", error);
125
+ };
126
+ }
127
+ function resolveTarget(target) {
128
+ if (!isBrowser()) throw new Error("CabalSpy ID widget needs a browser");
129
+ const el = typeof target === "string" ? document.querySelector(target) : target;
130
+ if (!el) throw new Error(`CabalSpy ID widget: no element matches ${String(target)}`);
131
+ return el;
132
+ }
133
+ function applyAttributes(el, attrs) {
134
+ for (const [k, v] of Object.entries(attrs)) if (v !== void 0) el.setAttribute(k, v);
135
+ }
136
+ function mountWith(target, options, attributes, after, scriptSrc, onLoadError) {
137
+ const host = resolveTarget(target);
138
+ let current = options;
139
+ let el = document.createElement("div");
140
+ const render = () => {
141
+ const next = document.createElement("div");
142
+ applyAttributes(next, attributes(current));
143
+ if (el.parentNode) el.replaceWith(next);
144
+ else host.appendChild(next);
145
+ el = next;
146
+ loadCabalSpyIDWidget(scriptSrc).then(
147
+ (csid) => {
148
+ if (el.isConnected) {
149
+ csid.mount();
150
+ after(csid, current);
151
+ }
152
+ },
153
+ (err) => _optionalChain([onLoadError, 'optionalCall', _12 => _12(err)])
154
+ );
155
+ };
156
+ render();
157
+ return {
158
+ get element() {
159
+ return el;
160
+ },
161
+ update(partial) {
162
+ current = { ...current, ...partial };
163
+ render();
164
+ },
165
+ remove() {
166
+ el.remove();
167
+ }
168
+ };
169
+ }
170
+ function mountLoginButton(target, options) {
171
+ const stop = onWidgetEvents(options, options.clientId);
172
+ const mounted = mountWith(
173
+ target,
174
+ options,
175
+ loginButtonAttributes,
176
+ () => void 0,
177
+ options.scriptSrc,
178
+ (err) => _optionalChain([options, 'access', _13 => _13.onError, 'optionalCall', _14 => _14({ error: "widget_load_failed", description: err.message })])
179
+ );
180
+ return {
181
+ get element() {
182
+ return mounted.element;
183
+ },
184
+ update: (o) => mounted.update(o),
185
+ remove() {
186
+ stop();
187
+ mounted.remove();
188
+ }
189
+ };
190
+ }
191
+ function mountTheses(target, options) {
192
+ return mountWith(
193
+ target,
194
+ options,
195
+ thesisWidgetAttributes,
196
+ (csid) => {
197
+ if (options.accessToken !== void 0) _optionalChain([csid, 'access', _15 => _15.thesis, 'optionalAccess', _16 => _16.setAccessToken, 'call', _17 => _17(options.accessToken)]);
198
+ },
199
+ options.scriptSrc
200
+ );
201
+ }
202
+ async function setThesisAccessToken(token, scriptSrc) {
203
+ const csid = await loadCabalSpyIDWidget(scriptSrc);
204
+ _optionalChain([csid, 'access', _18 => _18.thesis, 'optionalAccess', _19 => _19.setAccessToken, 'call', _20 => _20(token)]);
205
+ }
206
+ async function setThesisSignInHandler(handler, scriptSrc) {
207
+ if (!isBrowser()) return;
208
+ const csid = await loadCabalSpyIDWidget(scriptSrc);
209
+ _optionalChain([csid, 'access', _21 => _21.thesis, 'optionalAccess', _22 => _22.setSignInHandler, 'optionalCall', _23 => _23(handler)]);
210
+ }
211
+ async function startLogin(options, scriptSrc) {
212
+ const csid = await loadCabalSpyIDWidget(scriptSrc);
213
+ await csid.login({
214
+ clientId: options.clientId,
215
+ redirectUri: options.redirectUri,
216
+ scope: Array.isArray(options.scope) ? options.scope.join(" ") : options.scope
217
+ });
218
+ }
219
+
220
+
221
+
222
+
223
+
224
+
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+ exports.WIDGET_SRC = WIDGET_SRC; exports.audOf = audOf; exports.isBrowser = isBrowser; exports.loadCabalSpyIDWidget = loadCabalSpyIDWidget; exports.loginButtonAttributes = loginButtonAttributes; exports.mountLoginButton = mountLoginButton; exports.mountTheses = mountTheses; exports.onWidgetEvents = onWidgetEvents; exports.setThesisAccessToken = setThesisAccessToken; exports.setThesisSignInHandler = setThesisSignInHandler; exports.startLogin = startLogin; exports.thesisWidgetAttributes = thesisWidgetAttributes;
233
+ //# sourceMappingURL=widget.cjs.map
@@ -0,0 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IAAA;AACU,IAAA;AACoC,MAAA;AAC9C,IAAA;AACQ,IAAA;AACV,EAAA;AACF;AAMiE;AACvB,EAAA;AACP,kBAAA;AACnC;AAgBkF;AAC9D,EAAA;AACsB,EAAA;AACD,kBAAA;AACzC;AAMiB;AACyB,EAAA;AACvB,EAAA;AACG,IAAA;AACG,IAAA;AACiB,IAAA;AACvC,EAAA;AACH;ADrPiD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/cabalspy-id-js/cabalspy-id-js/dist/widget.cjs","sourcesContent":[null,"/**\n * CabalSpy ID widgets for any web page (browser only, no framework):\n * the \"Sign in with CabalSpy ID\" button and the token theses widget.\n *\n * import { mountLoginButton, mountTheses } from 'cabalspy-id/widget';\n *\n * mountLoginButton('#login', { clientId: 'csid_…', onLogin: ({ idToken }) => sendToBackend(idToken) });\n * mountTheses('#theses', { chain: 'solana', mint, clientId: 'csid_…', theme: 'dark' });\n *\n * Loads https://id.cabalspy.xyz/widget.js once and maps options to its data-*\n * attributes. React components: `cabalspy-id/react` (also `cabalspy-id/widget/react`).\n */\n\nimport { AuthenticationError } from './errors';\nimport type { CabalSpyIDClaims, Chain, OidcScope } from './types';\n\nexport const WIDGET_SRC = 'https://id.cabalspy.xyz/widget.js';\n\n/** Detail of the widget's `csid:login` event. */\nexport interface CabalSpyIDLogin {\n /** userinfo claims; `limited: true` (anonymous sub) when the platform is over its plan's user limit. */\n user: CabalSpyIDClaims;\n /** Send this to your backend and verify it there. */\n idToken: string;\n accessToken: string;\n /** Seconds. */\n expiresIn: number;\n}\n\nexport interface CabalSpyIDLogoutEvent {\n clientId: string;\n}\n\nexport interface CabalSpyIDErrorEvent {\n error: string;\n description?: string;\n}\n\n/** The signed-in person as the widget remembers them on this device. */\nexport interface CabalSpyIDUserSummary {\n sub: string;\n username?: string;\n name?: string | null;\n picture?: string | null;\n kol_badge?: boolean;\n limited?: boolean;\n}\n\n/** The global the widget defines (window.CSID). */\nexport interface CSIDGlobal {\n __loaded: true;\n user: CabalSpyIDLogin | null;\n mount(): void;\n login(opts: { clientId: string; redirectUri?: string; scope?: string }): Promise<void>;\n setUser(clientId: string, user: CabalSpyIDUserSummary | CabalSpyIDClaims): void;\n signOut(clientId: string): void;\n onLogin(cb: (r: CabalSpyIDLogin) => void): void;\n /** Thesis widgets on the page (data-csid-thesis). */\n thesis?: {\n /** Lets thesis widgets write as this user (access token with the scope \"thesis\"). */\n setAccessToken(token: string | null): void;\n /**\n * Your own sign-in for the widget's \"Sign in to write\" (null removes it).\n * See {@link setThesisSignInHandler}.\n */\n setSignInHandler?(handler: ThesisSignInHandler | null): void;\n clear(): void;\n };\n}\n\n/**\n * Your page's sign-in for thesis widgets: obtain a thesis-capable access token\n * for the person (e.g. your platform's own CabalSpy ID access token with the\n * scope \"thesis\", from your backend), call `setThesisAccessToken(token)` (or\n * `CSID.thesis.setAccessToken(token)`) and resolve `true`; resolve `false` when\n * the person is not signed in.\n */\nexport type ThesisSignInHandler = () => Promise<boolean> | boolean;\n\ndeclare global {\n interface Window {\n CSID?: CSIDGlobal;\n }\n}\n\nexport const isBrowser = () => typeof window !== 'undefined' && typeof document !== 'undefined';\n\nconst loaders = new Map<string, Promise<CSIDGlobal>>();\n\n/** Loads widget.js once per page. Resolves with window.CSID. */\nexport function loadCabalSpyIDWidget(src: string = WIDGET_SRC): Promise<CSIDGlobal> {\n if (!isBrowser()) return Promise.reject(new Error('CabalSpy ID widget needs a browser'));\n if (window.CSID?.__loaded) return Promise.resolve(window.CSID);\n let p = loaders.get(src);\n // The script tag was removed (e.g. by a test or a head manager): load again.\n if (p && !document.querySelector(`script[src=\"${src}\"]`)) {\n loaders.delete(src);\n p = undefined;\n }\n if (!p) {\n p = new Promise<CSIDGlobal>((resolve, reject) => {\n const done = () => (window.CSID ? resolve(window.CSID) : reject(new Error('widget.js loaded but window.CSID is missing')));\n let script = document.querySelector<HTMLScriptElement>(`script[src=\"${src}\"]`);\n if (script && window.CSID) return done();\n if (!script) {\n script = document.createElement('script');\n script.src = src;\n script.async = true;\n document.head.appendChild(script);\n }\n script.addEventListener('load', done, { once: true });\n script.addEventListener(\n 'error',\n () => {\n loaders.delete(src);\n reject(new Error(`Could not load ${src}`));\n },\n { once: true },\n );\n });\n loaders.set(src, p);\n }\n return p;\n}\n\n/** The `aud` of an (unverified) ID token, to route widget events to the right client. */\nexport function audOf(idToken: string): string | undefined {\n try {\n const part = idToken.split('.')[1]!.replace(/-/g, '+').replace(/_/g, '/');\n const aud = (JSON.parse(atob(part + '='.repeat((4 - (part.length % 4)) % 4))) as { aud?: string | string[] }).aud;\n return Array.isArray(aud) ? aud[0] : aud;\n } catch {\n return undefined;\n }\n}\n\nconst bool = (v: boolean | undefined) => (v === undefined ? undefined : v ? 'true' : 'false');\nconst num = (v: number | undefined) => (v === undefined ? undefined : String(v));\n\n// ── options ──────────────────────────────────────────────────────────────────\n\n/** Design and behaviour of the login button. */\nexport interface LoginButtonOptions {\n /** Your instance's client_id (`csid_…`). */\n clientId: string;\n /** Button design overrides; defaults come from the dashboard's button builder. */\n theme?: 'dark' | 'light' | (string & {});\n color?: string;\n textColor?: string;\n shape?: 'square' | 'rounded' | 'pill';\n size?: 'sm' | 'md' | 'lg';\n label?: string;\n fullWidth?: boolean;\n showLogo?: boolean;\n /**\n * Server-side apps: your own login route that starts the OIDC flow with your\n * client secret. Without it, a public client runs PKCE in the browser.\n */\n href?: string;\n /** Browser apps: redirect URI (default: the current page). */\n redirectUri?: string;\n /**\n * Browser apps: requested scopes (default: openid profile). Add `thesis` so\n * the person can write in thesis widgets on your page right after sign-in.\n */\n scope?: string | OidcScope[];\n /** Server-side apps: the signed-in person's `sub`, to show the avatar menu. */\n user?: string;\n /** Server-side apps: where \"Sign out\" goes. */\n logoutHref?: string;\n}\n\n/** Design and data of the token theses widget. */\nexport interface ThesisWidgetOptions {\n /** solana | bnb | base | eth | rh */\n chain: Chain;\n /** Token mint / contract address. */\n mint: string;\n /**\n * Required. Your instance's PUBLIC client_id (`csid_...`, shown in the\n * dashboard next to the API key; not the API key). The widget sends it on\n * every thesis API call; it also loads the design saved in the dashboard (the\n * options below override it), credits posts to your app and enables `scope: 'instance'`.\n */\n clientId: string;\n /** Default: dark */\n theme?: 'dark' | 'light';\n /** `global` (default): theses from every platform. `instance`: only the ones written on your instance. */\n scope?: 'global' | 'instance';\n /** Initial order. Default: new */\n sort?: 'new' | 'top';\n /** Font family, e.g. \"Inter\". */\n font?: string;\n /** Corner radius in px. Default: 12 */\n radius?: number;\n /** Colors (CSS colors, e.g. \"#0d0f12\"). */\n bg?: string;\n card?: string;\n text?: string;\n muted?: string;\n border?: string;\n accent?: string;\n accentText?: string;\n bull?: string;\n bear?: string;\n /** Show the token header. Default: true */\n showHeader?: boolean;\n /** Show the bull/bear sentiment bar. */\n showSentiment?: boolean;\n /** Denser layout. Default: false */\n compact?: boolean;\n /** Initial height in px; the widget then sizes itself to its content. Default: 520 */\n height?: number;\n}\n\n/** The widget's data-* attributes for a login button. */\nexport function loginButtonAttributes(o: LoginButtonOptions): Record<string, string | undefined> {\n return {\n 'data-csid-login': '',\n 'data-client-id': o.clientId,\n 'data-theme': o.theme,\n 'data-color': o.color,\n 'data-text-color': o.textColor,\n 'data-shape': o.shape,\n 'data-size': o.size,\n 'data-label': o.label,\n 'data-full-width': bool(o.fullWidth),\n 'data-show-logo': bool(o.showLogo),\n 'data-href': o.href,\n 'data-redirect-uri': o.redirectUri,\n 'data-scope': Array.isArray(o.scope) ? o.scope.join(' ') : o.scope,\n 'data-user': o.user,\n 'data-logout-href': o.logoutHref,\n };\n}\n\n/** The widget's data-* attributes for a theses widget. Throws `client_id_required` without `clientId`. */\nexport function thesisWidgetAttributes(o: ThesisWidgetOptions): Record<string, string | undefined> {\n if (typeof o?.clientId !== 'string' || !o.clientId.trim()) {\n throw new AuthenticationError(\n \"The theses widget needs your instance's public client_id (csid_..., shown in the dashboard next to the API key): \" +\n \"{ clientId: 'csid_...' }. It is not the API key; never put the API key in a browser.\",\n { code: 'client_id_required', parameter: 'clientId', docs: 'https://docs.cabalspy.xyz/cabalspy-id/errors#client_id_required' },\n );\n }\n return {\n 'data-csid-thesis': '',\n 'data-chain': o.chain,\n 'data-mint': o.mint,\n 'data-client-id': o.clientId.trim(),\n 'data-theme': o.theme,\n 'data-scope': o.scope,\n 'data-sort': o.sort,\n 'data-font': o.font,\n 'data-radius': num(o.radius),\n 'data-bg': o.bg,\n 'data-card': o.card,\n 'data-text': o.text,\n 'data-muted': o.muted,\n 'data-border': o.border,\n 'data-accent': o.accent,\n 'data-accent-text': o.accentText,\n 'data-bull': o.bull,\n 'data-bear': o.bear,\n 'data-show-header': bool(o.showHeader),\n 'data-show-sentiment': bool(o.showSentiment),\n 'data-compact': bool(o.compact),\n 'data-height': num(o.height),\n };\n}\n\n// ── events ───────────────────────────────────────────────────────────────────\n\nexport interface WidgetEventHandlers {\n /** A browser-app login finished (window event `csid:login`). */\n onLogin?: (result: CabalSpyIDLogin) => void;\n /** The person signed out from the menu (window event `csid:logout`). */\n onLogout?: (event: CabalSpyIDLogoutEvent) => void;\n /** The browser flow failed (window event `csid:error`). */\n onError?: (event: CabalSpyIDErrorEvent) => void;\n}\n\n/**\n * Listens to the widget's window events. With `clientId`, logins and logouts of\n * other clients on the same page are ignored. Returns a function that stops listening.\n */\nexport function onWidgetEvents(handlers: WidgetEventHandlers, clientId?: string): () => void {\n if (!isBrowser()) return () => undefined;\n const login = (e: Event) => {\n const d = (e as CustomEvent<CabalSpyIDLogin>).detail;\n const aud = d?.idToken ? audOf(d.idToken) : undefined;\n if (clientId && aud !== undefined && aud !== clientId) return;\n handlers.onLogin?.(d);\n };\n const logout = (e: Event) => {\n const d = (e as CustomEvent<CabalSpyIDLogoutEvent>).detail;\n if (clientId && d?.clientId && d.clientId !== clientId) return;\n handlers.onLogout?.(d);\n };\n const error = (e: Event) => handlers.onError?.((e as CustomEvent<CabalSpyIDErrorEvent>).detail);\n window.addEventListener('csid:login', login);\n window.addEventListener('csid:logout', logout);\n window.addEventListener('csid:error', error);\n return () => {\n window.removeEventListener('csid:login', login);\n window.removeEventListener('csid:logout', logout);\n window.removeEventListener('csid:error', error);\n };\n}\n\n// ── mounting (vanilla) ───────────────────────────────────────────────────────\n\nexport interface MountedWidget<O> {\n /** The element carrying the data-* attributes. */\n readonly element: HTMLElement;\n /** Re-renders with new options (a fresh element, so the widget mounts it again). */\n update(options: Partial<O>): void;\n /** Removes the widget and its event listeners. */\n remove(): void;\n}\n\nfunction resolveTarget(target: Element | string): Element {\n if (!isBrowser()) throw new Error('CabalSpy ID widget needs a browser');\n const el = typeof target === 'string' ? document.querySelector(target) : target;\n if (!el) throw new Error(`CabalSpy ID widget: no element matches ${String(target)}`);\n return el;\n}\n\nfunction applyAttributes(el: HTMLElement, attrs: Record<string, string | undefined>): void {\n for (const [k, v] of Object.entries(attrs)) if (v !== undefined) el.setAttribute(k, v);\n}\n\nfunction mountWith<O>(\n target: Element | string,\n options: O,\n attributes: (o: O) => Record<string, string | undefined>,\n after: (csid: CSIDGlobal, o: O) => void,\n scriptSrc: string | undefined,\n onLoadError?: (err: Error) => void,\n): MountedWidget<O> {\n const host = resolveTarget(target);\n let current = options;\n let el = document.createElement('div');\n const render = () => {\n const next = document.createElement('div');\n applyAttributes(next, attributes(current));\n if (el.parentNode) el.replaceWith(next);\n else host.appendChild(next);\n el = next;\n loadCabalSpyIDWidget(scriptSrc).then(\n (csid) => {\n if (el.isConnected) {\n csid.mount();\n after(csid, current);\n }\n },\n (err: Error) => onLoadError?.(err),\n );\n };\n render();\n return {\n get element() {\n return el;\n },\n update(partial) {\n current = { ...current, ...partial };\n render();\n },\n remove() {\n el.remove();\n },\n };\n}\n\n/**\n * Mounts the \"Sign in with CabalSpy ID\" button into `target` (an element or a\n * CSS selector).\n */\nexport function mountLoginButton(\n target: Element | string,\n options: LoginButtonOptions & WidgetEventHandlers & { scriptSrc?: string },\n): MountedWidget<LoginButtonOptions> {\n const stop = onWidgetEvents(options, options.clientId);\n const mounted = mountWith<LoginButtonOptions>(\n target,\n options,\n loginButtonAttributes,\n () => undefined,\n options.scriptSrc,\n (err) => options.onError?.({ error: 'widget_load_failed', description: err.message }),\n );\n return {\n get element() {\n return mounted.element;\n },\n update: (o) => mounted.update(o),\n remove() {\n stop();\n mounted.remove();\n },\n };\n}\n\n/**\n * Mounts the token theses widget into `target` (an element or a CSS selector).\n * `clientId` (your instance's public client_id) is required. `accessToken`\n * (scope `thesis`) lets the signed-in person write right away.\n */\nexport function mountTheses(\n target: Element | string,\n options: ThesisWidgetOptions & { accessToken?: string | null; scriptSrc?: string },\n): MountedWidget<ThesisWidgetOptions> {\n return mountWith<ThesisWidgetOptions>(\n target,\n options,\n thesisWidgetAttributes,\n (csid) => {\n if (options.accessToken !== undefined) csid.thesis?.setAccessToken(options.accessToken);\n },\n options.scriptSrc,\n );\n}\n\n/**\n * Lets thesis widgets on the page write as this user (an access token with the\n * scope `thesis`), or signs them out with `null`.\n */\nexport async function setThesisAccessToken(token: string | null, scriptSrc?: string): Promise<void> {\n const csid = await loadCabalSpyIDWidget(scriptSrc);\n csid.thesis?.setAccessToken(token);\n}\n\n/**\n * Lets your page handle the thesis widgets' \"Sign in to write\": the widget\n * calls `handler` instead of the page's login button / popup. While a handler\n * is set, the widget treats the page as the source of truth for sign-in (signed\n * out on the page = signed out in the widget). `null` removes it. Waits for\n * widget.js when it is not loaded yet; a no-op on the server.\n *\n * setThesisSignInHandler(async () => {\n * const token = await fetch('/api/csid-thesis-token').then((r) => (r.ok ? r.text() : null));\n * if (!token) return false;\n * await setThesisAccessToken(token);\n * return true;\n * });\n */\nexport async function setThesisSignInHandler(handler: ThesisSignInHandler | null, scriptSrc?: string): Promise<void> {\n if (!isBrowser()) return; // server rendering: nothing to register\n const csid = await loadCabalSpyIDWidget(scriptSrc);\n csid.thesis?.setSignInHandler?.(handler);\n}\n\n/** Starts the browser (public client) login flow. */\nexport async function startLogin(\n options: { clientId: string; redirectUri?: string; scope?: string | OidcScope[] },\n scriptSrc?: string,\n): Promise<void> {\n const csid = await loadCabalSpyIDWidget(scriptSrc);\n await csid.login({\n clientId: options.clientId,\n redirectUri: options.redirectUri,\n scope: Array.isArray(options.scope) ? options.scope.join(' ') : options.scope,\n });\n}\n"]}
@@ -0,0 +1,226 @@
1
+ import { c as CabalSpyIDClaims, O as OidcScope, d as Chain } from './types-UZeY9n1e.cjs';
2
+
3
+ /**
4
+ * CabalSpy ID widgets for any web page (browser only, no framework):
5
+ * the "Sign in with CabalSpy ID" button and the token theses widget.
6
+ *
7
+ * import { mountLoginButton, mountTheses } from 'cabalspy-id/widget';
8
+ *
9
+ * mountLoginButton('#login', { clientId: 'csid_…', onLogin: ({ idToken }) => sendToBackend(idToken) });
10
+ * mountTheses('#theses', { chain: 'solana', mint, clientId: 'csid_…', theme: 'dark' });
11
+ *
12
+ * Loads https://id.cabalspy.xyz/widget.js once and maps options to its data-*
13
+ * attributes. React components: `cabalspy-id/react` (also `cabalspy-id/widget/react`).
14
+ */
15
+
16
+ declare const WIDGET_SRC = "https://id.cabalspy.xyz/widget.js";
17
+ /** Detail of the widget's `csid:login` event. */
18
+ interface CabalSpyIDLogin {
19
+ /** userinfo claims; `limited: true` (anonymous sub) when the platform is over its plan's user limit. */
20
+ user: CabalSpyIDClaims;
21
+ /** Send this to your backend and verify it there. */
22
+ idToken: string;
23
+ accessToken: string;
24
+ /** Seconds. */
25
+ expiresIn: number;
26
+ }
27
+ interface CabalSpyIDLogoutEvent {
28
+ clientId: string;
29
+ }
30
+ interface CabalSpyIDErrorEvent {
31
+ error: string;
32
+ description?: string;
33
+ }
34
+ /** The signed-in person as the widget remembers them on this device. */
35
+ interface CabalSpyIDUserSummary {
36
+ sub: string;
37
+ username?: string;
38
+ name?: string | null;
39
+ picture?: string | null;
40
+ kol_badge?: boolean;
41
+ limited?: boolean;
42
+ }
43
+ /** The global the widget defines (window.CSID). */
44
+ interface CSIDGlobal {
45
+ __loaded: true;
46
+ user: CabalSpyIDLogin | null;
47
+ mount(): void;
48
+ login(opts: {
49
+ clientId: string;
50
+ redirectUri?: string;
51
+ scope?: string;
52
+ }): Promise<void>;
53
+ setUser(clientId: string, user: CabalSpyIDUserSummary | CabalSpyIDClaims): void;
54
+ signOut(clientId: string): void;
55
+ onLogin(cb: (r: CabalSpyIDLogin) => void): void;
56
+ /** Thesis widgets on the page (data-csid-thesis). */
57
+ thesis?: {
58
+ /** Lets thesis widgets write as this user (access token with the scope "thesis"). */
59
+ setAccessToken(token: string | null): void;
60
+ /**
61
+ * Your own sign-in for the widget's "Sign in to write" (null removes it).
62
+ * See {@link setThesisSignInHandler}.
63
+ */
64
+ setSignInHandler?(handler: ThesisSignInHandler | null): void;
65
+ clear(): void;
66
+ };
67
+ }
68
+ /**
69
+ * Your page's sign-in for thesis widgets: obtain a thesis-capable access token
70
+ * for the person (e.g. your platform's own CabalSpy ID access token with the
71
+ * scope "thesis", from your backend), call `setThesisAccessToken(token)` (or
72
+ * `CSID.thesis.setAccessToken(token)`) and resolve `true`; resolve `false` when
73
+ * the person is not signed in.
74
+ */
75
+ type ThesisSignInHandler = () => Promise<boolean> | boolean;
76
+ declare global {
77
+ interface Window {
78
+ CSID?: CSIDGlobal;
79
+ }
80
+ }
81
+ declare const isBrowser: () => boolean;
82
+ /** Loads widget.js once per page. Resolves with window.CSID. */
83
+ declare function loadCabalSpyIDWidget(src?: string): Promise<CSIDGlobal>;
84
+ /** The `aud` of an (unverified) ID token, to route widget events to the right client. */
85
+ declare function audOf(idToken: string): string | undefined;
86
+ /** Design and behaviour of the login button. */
87
+ interface LoginButtonOptions {
88
+ /** Your instance's client_id (`csid_…`). */
89
+ clientId: string;
90
+ /** Button design overrides; defaults come from the dashboard's button builder. */
91
+ theme?: 'dark' | 'light' | (string & {});
92
+ color?: string;
93
+ textColor?: string;
94
+ shape?: 'square' | 'rounded' | 'pill';
95
+ size?: 'sm' | 'md' | 'lg';
96
+ label?: string;
97
+ fullWidth?: boolean;
98
+ showLogo?: boolean;
99
+ /**
100
+ * Server-side apps: your own login route that starts the OIDC flow with your
101
+ * client secret. Without it, a public client runs PKCE in the browser.
102
+ */
103
+ href?: string;
104
+ /** Browser apps: redirect URI (default: the current page). */
105
+ redirectUri?: string;
106
+ /**
107
+ * Browser apps: requested scopes (default: openid profile). Add `thesis` so
108
+ * the person can write in thesis widgets on your page right after sign-in.
109
+ */
110
+ scope?: string | OidcScope[];
111
+ /** Server-side apps: the signed-in person's `sub`, to show the avatar menu. */
112
+ user?: string;
113
+ /** Server-side apps: where "Sign out" goes. */
114
+ logoutHref?: string;
115
+ }
116
+ /** Design and data of the token theses widget. */
117
+ interface ThesisWidgetOptions {
118
+ /** solana | bnb | base | eth | rh */
119
+ chain: Chain;
120
+ /** Token mint / contract address. */
121
+ mint: string;
122
+ /**
123
+ * Required. Your instance's PUBLIC client_id (`csid_...`, shown in the
124
+ * dashboard next to the API key; not the API key). The widget sends it on
125
+ * every thesis API call; it also loads the design saved in the dashboard (the
126
+ * options below override it), credits posts to your app and enables `scope: 'instance'`.
127
+ */
128
+ clientId: string;
129
+ /** Default: dark */
130
+ theme?: 'dark' | 'light';
131
+ /** `global` (default): theses from every platform. `instance`: only the ones written on your instance. */
132
+ scope?: 'global' | 'instance';
133
+ /** Initial order. Default: new */
134
+ sort?: 'new' | 'top';
135
+ /** Font family, e.g. "Inter". */
136
+ font?: string;
137
+ /** Corner radius in px. Default: 12 */
138
+ radius?: number;
139
+ /** Colors (CSS colors, e.g. "#0d0f12"). */
140
+ bg?: string;
141
+ card?: string;
142
+ text?: string;
143
+ muted?: string;
144
+ border?: string;
145
+ accent?: string;
146
+ accentText?: string;
147
+ bull?: string;
148
+ bear?: string;
149
+ /** Show the token header. Default: true */
150
+ showHeader?: boolean;
151
+ /** Show the bull/bear sentiment bar. */
152
+ showSentiment?: boolean;
153
+ /** Denser layout. Default: false */
154
+ compact?: boolean;
155
+ /** Initial height in px; the widget then sizes itself to its content. Default: 520 */
156
+ height?: number;
157
+ }
158
+ /** The widget's data-* attributes for a login button. */
159
+ declare function loginButtonAttributes(o: LoginButtonOptions): Record<string, string | undefined>;
160
+ /** The widget's data-* attributes for a theses widget. Throws `client_id_required` without `clientId`. */
161
+ declare function thesisWidgetAttributes(o: ThesisWidgetOptions): Record<string, string | undefined>;
162
+ interface WidgetEventHandlers {
163
+ /** A browser-app login finished (window event `csid:login`). */
164
+ onLogin?: (result: CabalSpyIDLogin) => void;
165
+ /** The person signed out from the menu (window event `csid:logout`). */
166
+ onLogout?: (event: CabalSpyIDLogoutEvent) => void;
167
+ /** The browser flow failed (window event `csid:error`). */
168
+ onError?: (event: CabalSpyIDErrorEvent) => void;
169
+ }
170
+ /**
171
+ * Listens to the widget's window events. With `clientId`, logins and logouts of
172
+ * other clients on the same page are ignored. Returns a function that stops listening.
173
+ */
174
+ declare function onWidgetEvents(handlers: WidgetEventHandlers, clientId?: string): () => void;
175
+ interface MountedWidget<O> {
176
+ /** The element carrying the data-* attributes. */
177
+ readonly element: HTMLElement;
178
+ /** Re-renders with new options (a fresh element, so the widget mounts it again). */
179
+ update(options: Partial<O>): void;
180
+ /** Removes the widget and its event listeners. */
181
+ remove(): void;
182
+ }
183
+ /**
184
+ * Mounts the "Sign in with CabalSpy ID" button into `target` (an element or a
185
+ * CSS selector).
186
+ */
187
+ declare function mountLoginButton(target: Element | string, options: LoginButtonOptions & WidgetEventHandlers & {
188
+ scriptSrc?: string;
189
+ }): MountedWidget<LoginButtonOptions>;
190
+ /**
191
+ * Mounts the token theses widget into `target` (an element or a CSS selector).
192
+ * `clientId` (your instance's public client_id) is required. `accessToken`
193
+ * (scope `thesis`) lets the signed-in person write right away.
194
+ */
195
+ declare function mountTheses(target: Element | string, options: ThesisWidgetOptions & {
196
+ accessToken?: string | null;
197
+ scriptSrc?: string;
198
+ }): MountedWidget<ThesisWidgetOptions>;
199
+ /**
200
+ * Lets thesis widgets on the page write as this user (an access token with the
201
+ * scope `thesis`), or signs them out with `null`.
202
+ */
203
+ declare function setThesisAccessToken(token: string | null, scriptSrc?: string): Promise<void>;
204
+ /**
205
+ * Lets your page handle the thesis widgets' "Sign in to write": the widget
206
+ * calls `handler` instead of the page's login button / popup. While a handler
207
+ * is set, the widget treats the page as the source of truth for sign-in (signed
208
+ * out on the page = signed out in the widget). `null` removes it. Waits for
209
+ * widget.js when it is not loaded yet; a no-op on the server.
210
+ *
211
+ * setThesisSignInHandler(async () => {
212
+ * const token = await fetch('/api/csid-thesis-token').then((r) => (r.ok ? r.text() : null));
213
+ * if (!token) return false;
214
+ * await setThesisAccessToken(token);
215
+ * return true;
216
+ * });
217
+ */
218
+ declare function setThesisSignInHandler(handler: ThesisSignInHandler | null, scriptSrc?: string): Promise<void>;
219
+ /** Starts the browser (public client) login flow. */
220
+ declare function startLogin(options: {
221
+ clientId: string;
222
+ redirectUri?: string;
223
+ scope?: string | OidcScope[];
224
+ }, scriptSrc?: string): Promise<void>;
225
+
226
+ export { type CSIDGlobal, type CabalSpyIDErrorEvent, type CabalSpyIDLogin, type CabalSpyIDLogoutEvent, type CabalSpyIDUserSummary, type LoginButtonOptions, type MountedWidget, type ThesisSignInHandler, type ThesisWidgetOptions, WIDGET_SRC, type WidgetEventHandlers, audOf, isBrowser, loadCabalSpyIDWidget, loginButtonAttributes, mountLoginButton, mountTheses, onWidgetEvents, setThesisAccessToken, setThesisSignInHandler, startLogin, thesisWidgetAttributes };