@popgrids/embed 0.0.4 → 1.0.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.
Files changed (49) hide show
  1. package/AGENTS.md +14 -0
  2. package/dist/assets/wordmark-svg.d.ts +7 -0
  3. package/dist/assets/wordmark-svg.d.ts.map +1 -0
  4. package/dist/components/pop-account-switcher.d.ts +31 -0
  5. package/dist/components/pop-account-switcher.d.ts.map +1 -0
  6. package/dist/components/pop-auth-code.d.ts +22 -0
  7. package/dist/components/pop-auth-code.d.ts.map +1 -0
  8. package/dist/components/pop-auth-email.d.ts +18 -0
  9. package/dist/components/pop-auth-email.d.ts.map +1 -0
  10. package/dist/components/pop-auth-join.d.ts +20 -0
  11. package/dist/components/pop-auth-join.d.ts.map +1 -0
  12. package/dist/components/pop-auth-no-code.d.ts +14 -0
  13. package/dist/components/pop-auth-no-code.d.ts.map +1 -0
  14. package/dist/components/pop-auth-panel.d.ts +17 -7
  15. package/dist/components/pop-auth-panel.d.ts.map +1 -1
  16. package/dist/components/pop-button-link.d.ts +43 -0
  17. package/dist/components/pop-button-link.d.ts.map +1 -0
  18. package/dist/components/pop-comment-bar.d.ts +2 -0
  19. package/dist/components/pop-comment-bar.d.ts.map +1 -1
  20. package/dist/components/pop-comment-thread.d.ts.map +1 -1
  21. package/dist/components/pop-comment.d.ts +2 -0
  22. package/dist/components/pop-comment.d.ts.map +1 -1
  23. package/dist/components/pop-feed.d.ts +15 -0
  24. package/dist/components/pop-feed.d.ts.map +1 -1
  25. package/dist/components/pop-grid.d.ts +1 -0
  26. package/dist/components/pop-grid.d.ts.map +1 -1
  27. package/dist/components/refs.d.ts +8 -0
  28. package/dist/components/refs.d.ts.map +1 -0
  29. package/dist/embed.js +2572 -1755
  30. package/dist/embed.js.map +1 -1
  31. package/dist/index.cjs +999 -118
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.ts +1 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1360 -547
  36. package/dist/index.js.map +1 -1
  37. package/dist/lib/backoff.d.ts +11 -0
  38. package/dist/lib/backoff.d.ts.map +1 -0
  39. package/dist/lib/popup-auth.d.ts +10 -4
  40. package/dist/lib/popup-auth.d.ts.map +1 -1
  41. package/dist/store/embed-auth-store.d.ts +201 -0
  42. package/dist/store/embed-auth-store.d.ts.map +1 -0
  43. package/dist/store/grid-store.d.ts +3 -0
  44. package/dist/store/grid-store.d.ts.map +1 -1
  45. package/dist/types/models.d.ts +12 -0
  46. package/dist/types/models.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/dist/store/auth-store.d.ts +0 -8
  49. package/dist/store/auth-store.d.ts.map +0 -1
@@ -0,0 +1,11 @@
1
+ /**
2
+ * "Full jitter" exponential backoff (AWS's exponential-backoff-and-jitter
3
+ * recipe): the delay for a given attempt is a random value between 0 and the
4
+ * exponential ceiling, not the ceiling itself. Pure exponential backoff only
5
+ * bounds how hard one client retries — every client that disconnects at the
6
+ * same instant (a DO/Worker blip, a deploy) computes the identical delay
7
+ * sequence and retries in lockstep waves. Randomizing spreads a correlated
8
+ * mass-reconnect out over time instead of turning it into a thundering herd.
9
+ */
10
+ export declare function reconnectDelayMs(attempt: number, baseMs: number, capMs: number): number;
11
+ //# sourceMappingURL=backoff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../src/lib/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGvF"}
@@ -9,14 +9,20 @@ export declare const AUTH_TIMEOUT_MS: number;
9
9
  export declare class PopupAuthError extends Error {
10
10
  constructor(message: string);
11
11
  }
12
+ export declare class PopupAuthCancelledError extends PopupAuthError {
13
+ constructor(message?: string);
14
+ }
15
+ export interface EmbedAuthSuccess {
16
+ user: AuthUser;
17
+ token: string;
18
+ expiresAt: number;
19
+ }
12
20
  export declare const buildEmbedLoginUrl: (apiUrl: string, publicKey: string, returnOrigin: string) => string;
13
21
  export declare const openPopgridsLoginPopup: (apiUrl: string, publicKey: string) => Window;
14
22
  export declare const waitForPopgridsAuth: (apiUrl: string, popup: Window, options?: {
15
- onAuthUser?: (user: AuthUser) => void;
16
- verifySignedIn?: () => Promise<boolean>;
23
+ onAuthSuccess?: (result: EmbedAuthSuccess) => void;
17
24
  }) => Promise<void>;
18
25
  export declare const signInWithPopup: (apiUrl: string, publicKey: string, options?: {
19
- onAuthUser?: (user: AuthUser) => void;
20
- verifySignedIn?: () => Promise<boolean>;
26
+ onAuthSuccess?: (result: EmbedAuthSuccess) => void;
21
27
  }) => Promise<void>;
22
28
  //# sourceMappingURL=popup-auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"popup-auth.d.ts","sourceRoot":"","sources":["../../src/lib/popup-auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,eAAO,MAAM,iBAAiB,mBAAmB,CAAC;AAClD,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,UAAU,kBAAkB,CAAC;AAC1C,eAAO,MAAM,cAAc,+BAA+B,CAAC;AAC3D,eAAO,MAAM,eAAe,QAAgB,CAAC;AAI7C,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,MAAM,EACd,WAAW,MAAM,EACjB,cAAc,MAAM,WAMrB,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,WAYvE,CAAC;AAuCF,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,MAA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YvE,CAAC;AAiDF,eAAO,MAAM,mBAAmB,GAC9B,QAAQ,MAAM,EACd,OAAO,MAAM,EACb,UAAU;IACR,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;CACpD,kBA4EC,CAAC;AAEL,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,EACd,WAAW,MAAM,EACjB,UAAU;IACR,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;CACpD,kBAIF,CAAC"}
@@ -0,0 +1,201 @@
1
+ import { AuthUser, OrgOption } from '../types/models.js';
2
+ export type EmbedAuthView = "idle" | "email" | "code" | "no-code";
3
+ /**
4
+ * Owns auth state for one `<pop-grid>` instance — registered per-element
5
+ * (see registry.ts) rather than as a page-global singleton, so multiple
6
+ * widgets with different publicKeys on the same page don't share identity.
7
+ */
8
+ export declare class EmbedAuthStore {
9
+ readonly apiUrl: string;
10
+ readonly publicKey: string;
11
+ currentUser: import('@preact/signals-core').Signal<AuthUser | null>;
12
+ authError: import('@preact/signals-core').Signal<string | null>;
13
+ /** Label for the notice's button (it always just dismisses the notice). Set via showAuthError. */
14
+ authErrorAction: import('@preact/signals-core').Signal<string>;
15
+ /**
16
+ * Bumped each time the visitor dismisses the notice (vs. it clearing on its
17
+ * own, e.g. the panel closing) so the auth cards can hand focus back to
18
+ * their field — the notice made everything under it inert until now.
19
+ */
20
+ authNoticeDismissals: import('@preact/signals-core').Signal<number>;
21
+ /**
22
+ * When set, the notice is a rate-limit wait: its button becomes a
23
+ * countdown to this timestamp and the notice dismisses itself at zero.
24
+ */
25
+ authErrorRetryAt: import('@preact/signals-core').Signal<number | null>;
26
+ authPending: import('@preact/signals-core').Signal<boolean>;
27
+ /**
28
+ * Accounts the signed-in visitor can comment as (see switchOrganization) —
29
+ * populated after sign-in, independent of which one is currently active.
30
+ * The *active* account syncs across every same-browser tab (they share one
31
+ * token — see ADR 0011); this list itself doesn't need to, since it's the
32
+ * same accounts regardless of which is active.
33
+ */
34
+ organizations: import('@preact/signals-core').Signal<OrgOption[]>;
35
+ /** True while an organizations fetch is in flight — drives the switcher's spinner. */
36
+ organizationsLoading: import('@preact/signals-core').Signal<boolean>;
37
+ /**
38
+ * Inline email+OTP sign-in state (see pop-auth-panel.ts). Kept separate
39
+ * from authPending/authError above, which stay owned by the OAuth popup
40
+ * flow (requestSignIn) — the two flows can be mid-progress independently.
41
+ */
42
+ authView: import('@preact/signals-core').Signal<EmbedAuthView>;
43
+ otpEmail: import('@preact/signals-core').Signal<string>;
44
+ otpPending: import('@preact/signals-core').Signal<boolean>;
45
+ otpError: import('@preact/signals-core').Signal<string | null>;
46
+ otpExpiresAt: import('@preact/signals-core').Signal<number | null>;
47
+ private session;
48
+ private authSocket;
49
+ private authReconnectAttempt;
50
+ private authReconnectTimer;
51
+ private destroyed;
52
+ private onStorageEvent;
53
+ /**
54
+ * Every live store on this page. The `storage` event never fires in the
55
+ * document that made the write, so two grids with the same publicKey on
56
+ * one page (which share a localStorage key) would otherwise never hear
57
+ * about each other's sign-in or sign-out until reload — see notifySiblings.
58
+ */
59
+ private static instances;
60
+ private static syncing;
61
+ /** Applies a session change made elsewhere — another tab (storage event) or another grid on this page (notifySiblings). */
62
+ private applyExternalChange;
63
+ /** Pushes a local session change to other grids on this page sharing our publicKey. */
64
+ private notifySiblings;
65
+ constructor(opts: {
66
+ apiUrl: string;
67
+ publicKey: string;
68
+ });
69
+ /** Closes the auth channel, cancels any pending reconnect, and stops listening for cross-tab changes — call from the owning element's disconnectedCallback. */
70
+ destroy(): void;
71
+ private readStoredSession;
72
+ /**
73
+ * Just the storage write, no side effects — for keeping the persisted
74
+ * session in sync with a sliding-expiry renewal (checkSession) without
75
+ * redoing loadOrganizations/reconnecting the auth channel for what's
76
+ * still the same identity. writeStoredSession (below) is for an actual
77
+ * sign-in (new or adopted from another tab), where those side effects
78
+ * are the point.
79
+ */
80
+ private persistSession;
81
+ private writeStoredSession;
82
+ private clearStoredSession;
83
+ /**
84
+ * Current token, or null if missing/expired (clearing state — and, if we
85
+ * were signed in, showing the "you were signed out" message — as a side
86
+ * effect of expiry). This is a local-only check against the last
87
+ * `expiresAt` this tab persisted: if the credential was actually renewed
88
+ * from a *different*, still-open tab/device while this one sat closed
89
+ * past its own locally-known expiry, this can call it expired a little
90
+ * early rather than re-confirming with the server — an occasional,
91
+ * low-stakes extra sign-in prompt, traded for not hitting the server on
92
+ * every single token read just to double-check a locally-expired date.
93
+ */
94
+ private get token();
95
+ /**
96
+ * Attaches the stored token (if any) and returns the response as-is — no
97
+ * retry-via-popup. Use for reads that should silently show "signed out"
98
+ * on 401 rather than interrupting the visitor (grid/comments GET, session
99
+ * check, WS connect-ticket mint — the last of which must also work for
100
+ * anonymous/signed-out visitors).
101
+ */
102
+ fetchWithToken(path: string, init?: RequestInit): Promise<Response>;
103
+ /**
104
+ * Same as fetchWithToken, but on a 401 prompts sign-in inline (the
105
+ * visitor's already looking at the open panel, mid-action — that's
106
+ * exactly what triggered this) and retries once. Use only for actions the
107
+ * visitor just explicitly initiated (post/edit/delete/flag a comment) —
108
+ * never for passive/background reads, since this interrupts them with a
109
+ * prompt.
110
+ *
111
+ * The request being retried already has whatever the visitor typed baked
112
+ * into it (e.g. postComment captures the comment body into the request
113
+ * before this ever runs) — requestInlineSignIn() only has to get them
114
+ * back to a valid session; it doesn't need to preserve or restore
115
+ * anything itself for the retry to pick up right where they left off.
116
+ */
117
+ authorizedFetch(path: string, init?: RequestInit): Promise<Response>;
118
+ private readError;
119
+ /** Transitions from the idle "Join the Conversation" state into the inline email form. */
120
+ startEmailSignIn(): void;
121
+ backToIdle(): void;
122
+ backToEmail(): void;
123
+ /**
124
+ * The code can no longer be used: drop back to the email step to request a
125
+ * new one. otpEmail is kept (in memory only) so the email field can be
126
+ * prefilled rather than making the visitor retype it.
127
+ */
128
+ expireOtp(): void;
129
+ /** One step back from the no-code help card, to the code entry it was opened from. */
130
+ backToCode(): void;
131
+ showNoCode(): void;
132
+ /** Sends (or resends) a sign-in code to `email`. No token yet — the visitor isn't signed in. */
133
+ sendOtp(email: string): Promise<boolean>;
134
+ resendOtp(): Promise<boolean>;
135
+ /** Verifies `code` against the in-progress email and, on success, signs the visitor in. */
136
+ verifyOtp(code: string): Promise<boolean>;
137
+ requestSignIn(): Promise<boolean>;
138
+ /**
139
+ * Resolves the promise a pending requestInlineSignIn() call is awaiting —
140
+ * set while one's in progress, called from verifyOtp()'s success path
141
+ * (true) and backToIdle() (false, abandoned). Not a public method: it's
142
+ * the completion half of requestInlineSignIn(), nothing else should call it.
143
+ */
144
+ private resolveInlineSignIn;
145
+ private inlineSignInPromise;
146
+ /**
147
+ * Reactive re-auth for authorizedFetch(): puts the widget into the inline
148
+ * sign-in flow (the panel's already open — that's what triggered this,
149
+ * mid-write) and waits for it to resolve, rather than opening the OAuth
150
+ * popup the way the old checkSession-driven path did. Concurrent callers
151
+ * (e.g. two writes racing into a 401 around the same time) join the same
152
+ * pending prompt instead of each resetting it back to the email step.
153
+ */
154
+ requestInlineSignIn(): Promise<boolean>;
155
+ private showAuthError;
156
+ /** A 429: show the wait as a countdown (see authErrorRetryAt) instead of letting the visitor hammer the endpoint. */
157
+ private showRateLimited;
158
+ dismissAuthError(): void;
159
+ clearAuthError(): void;
160
+ /**
161
+ * Fetches the accounts the signed-in visitor can comment as (for the
162
+ * switcher UI) — lazily: called on demand when the switcher's dropdown
163
+ * opens (pop-account-switcher.ts), not proactively on sign-in or page
164
+ * load. Once populated, `organizations` acts as its own cache — callers
165
+ * should check `organizations.value.length === 0` before calling this
166
+ * rather than calling it unconditionally, which also means a prior
167
+ * failed attempt gets retried the next time the dropdown opens rather
168
+ * than being stuck empty forever.
169
+ */
170
+ loadOrganizations(): Promise<void>;
171
+ /**
172
+ * Switches which account this widget's comments post as. Doesn't touch or
173
+ * read the main app's active org — but the api key itself (and thus which
174
+ * account it's scoped to server-side) is the same one every same-browser
175
+ * tab shares via localStorage (see ADR 0009), so a switch here already
176
+ * changes every other tab's underlying identity whether we tell them or
177
+ * not. persistSession below keeps their displayed state honest via the
178
+ * same native `storage` event sign-in already propagates through — see
179
+ * ADR 0011, which corrects ADR 0008's original "switching stays local"
180
+ * framing now that the token itself is shared.
181
+ */
182
+ switchOrganization(organizationId: string): Promise<boolean>;
183
+ /** Signs this identity out everywhere (main app + every other widget), not just this one. */
184
+ signOutEverywhere(): Promise<boolean>;
185
+ /** Shared cleanup for every way this widget learns it's signed out: a pushed session.revoked, a 401 from an authed call, an expired remembered sign-in, or the visitor's own sign-out. */
186
+ private handleSignedOut;
187
+ /**
188
+ * Opens the auth-only push channel — and, as its one other job, the sole
189
+ * point that verifies the token server-side and applies the sliding
190
+ * renewal (see docs/adr/0009 and 0010). Not called on construction:
191
+ * pop-feed.ts calls this once the panel first opens, since that's the
192
+ * first moment the widget actually needs to know anything about auth
193
+ * beyond what's already cached locally (the collapsed pill shows other
194
+ * commenters, never the current visitor's own identity). Safe to call
195
+ * repeatedly — no-ops once a socket is already open.
196
+ */
197
+ connectAuthChannel(): Promise<void>;
198
+ private scheduleAuthReconnect;
199
+ private closeAuthChannel;
200
+ }
201
+ //# sourceMappingURL=embed-auth-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embed-auth-store.d.ts","sourceRoot":"","sources":["../../src/store/embed-auth-store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAgB,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAmC5E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAElE;;;;GAIG;AACH,qBAAa,cAAc;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,WAAW,yDAAiC;IAC5C,SAAS,uDAA+B;IACxC,kGAAkG;IAClG,eAAe,gDAAiC;IAChD;;;;OAIG;IACH,oBAAoB,gDAAa;IAC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UAAU,IAAI,IAAI;IAWlB,WAAW,IAAI,IAAI;IAKnB;;;;OAIG;IACH,SAAS,IAAI,IAAI;IAMjB,sFAAsF;IACtF,UAAU,IAAI,IAAI;IAIlB,UAAU,IAAI,IAAI;IAIlB,gGAAgG;IAC1F,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoCxC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAKnC,2FAA2F;IACrF,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAmDzC,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;IAsBvC;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB,CAA6C;IACxE,OAAO,CAAC,mBAAmB,CAAiC;IAE5D;;;;;;;OAOG;IACH,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC;IAgBvC,OAAO,CAAC,aAAa;IAWrB,qHAAqH;IACrH,OAAO,CAAC,eAAe;IAQvB,gBAAgB,IAAI,IAAI;IAKxB,cAAc,IAAI,IAAI;IAItB;;;;;;;;;OASG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BxC;;;;;;;;;;OAUG;IACG,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqBlE,6FAA6F;IACvF,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAe3C,0LAA0L;IAC1L,OAAO,CAAC,eAAe;IAWvB;;;;;;;;;OASG;IACG,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IA0FzC,OAAO,CAAC,qBAAqB;IAc7B,OAAO,CAAC,gBAAgB;CAezB"}
@@ -1,4 +1,5 @@
1
1
  import { Comment, CommentAuthor, Grid } from '../types/models.js';
2
+ import { EmbedAuthStore } from './embed-auth-store.js';
2
3
  /**
3
4
  * The five visual settings a `<pop-grid>` can override live via
4
5
  * `data-align`/`data-layout`/`data-position`/`data-icon`/`data-preview-count`
@@ -14,6 +15,7 @@ export declare class GridStore {
14
15
  readonly pageUrl: string;
15
16
  readonly externalId: string | null;
16
17
  readonly previewCount = 3;
18
+ private readonly authStore;
17
19
  /** The grid last fetched from the API — never read directly outside this
18
20
  * class; `grid` (below) is the override-aware value every consumer uses. */
19
21
  private _fetchedGrid;
@@ -44,6 +46,7 @@ export declare class GridStore {
44
46
  publicKey: string;
45
47
  pageUrl: string;
46
48
  externalId?: string | null;
49
+ authStore: EmbedAuthStore;
47
50
  });
48
51
  /** Replaces the current override set wholesale (not a per-key merge) —
49
52
  * called with every override attribute `<pop-grid>` currently has set, so
@@ -1 +1 @@
1
- {"version":3,"file":"grid-store.d.ts","sourceRoot":"","sources":["../../src/store/grid-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAqBvE;;;;;;;GAOG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CACjC,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,GAAG,cAAc,CAAC,CACtE,CAAC;AAUF,qBAAa,SAAS;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,YAAY,KAAyB;IAE9C;gFAC4E;IAC5E,OAAO,CAAC,YAAY,CAA6B;IACjD,yEAAyE;IACzE,OAAO,CAAC,UAAU,CAA6B;IAE/C;;uCAEmC;IACnC,IAAI,6DAAkF;IACtF,QAAQ,mDAAyB;IACjC,OAAO,iDAAgB;IACvB,KAAK,uDAA+B;IACpC,IAAI,iDAAiB;IACrB,UAAU,uDAA+B;IACzC,gBAAgB,uDAA+B;IAC/C,kBAAkB,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C;KAC3B;IAQD;;;sEAGkE;IAClE,YAAY,CAAC,SAAS,EAAE,aAAa,GAAG,IAAI;IAI5C,+EAA+E;IAC/E,OAAO,CAAC,cAAc;IAQtB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE;IAYjC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAoCxB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAkClF,OAAO,IAAI,IAAI;YAkBD,eAAe;IAoF7B,OAAO,CAAC,iBAAiB;IAczB,OAAO,CAAC,aAAa;IAUf,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAuBrE,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAezD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAStD,OAAO,CAAC,mBAAmB;CAG5B"}
@@ -44,4 +44,16 @@ export interface AuthUser {
44
44
  email: string;
45
45
  image: string | null;
46
46
  }
47
+ /** What's persisted to sessionStorage after a successful embed sign-in. */
48
+ export interface EmbedSession {
49
+ token: string;
50
+ expiresAt: number;
51
+ user: AuthUser;
52
+ }
53
+ /** One account the signed-in visitor can comment as — see EmbedAuthStore.organizations. */
54
+ export interface OrgOption {
55
+ id: string;
56
+ name: string;
57
+ image: string | null;
58
+ }
47
59
  //# sourceMappingURL=models.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/types/models.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACr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C;IACzC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC7C,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3B,QAAQ,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACxC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,2EAA2E;AAC3E,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED,2FAA2F;AAC3F,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@popgrids/embed",
3
3
  "description": "PopGrids embeddable discussion widget",
4
- "version": "0.0.4",
4
+ "version": "1.0.0",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "PopGrids",
@@ -1,8 +0,0 @@
1
- import { AuthUser } from '../types/models.js';
2
- export declare const currentUser: import('@preact/signals-core').Signal<AuthUser | null>;
3
- export declare const authError: import('@preact/signals-core').Signal<string | null>;
4
- export declare const authPending: import('@preact/signals-core').Signal<boolean>;
5
- export declare function checkSession(apiUrl: string, publicKey: string, delays?: number[]): Promise<boolean>;
6
- export declare function requestSignIn(apiUrl: string, publicKey: string): Promise<boolean>;
7
- export declare function clearAuthError(): void;
8
- //# sourceMappingURL=auth-store.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth-store.d.ts","sourceRoot":"","sources":["../../src/store/auth-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,eAAO,MAAM,WAAW,wDAAgC,CAAC;AACzD,eAAO,MAAM,SAAS,sDAA8B,CAAC;AACrD,eAAO,MAAM,WAAW,gDAAgB,CAAC;AAKzC,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,MAAM,GAAE,MAAM,EAA4B,GACzC,OAAO,CAAC,OAAO,CAAC,CAsClB;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC,CAwBlB;AAED,wBAAgB,cAAc,IAAI,IAAI,CAErC"}