@elytracms/studio 0.0.51 → 0.0.53
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/convex/auth.ts +135 -62
- package/convex/invites.ts +77 -0
- package/dist/components/account/account-settings.js +4 -4
- package/dist/components/account/credential-panel.js +1 -1
- package/dist/components/account/self-account-view-source.js +3 -3
- package/dist/components/ai/ai-chat-panel-lazy.js +1 -1
- package/dist/components/ai/ai-chat-panel.js +4 -4
- package/dist/components/ai/ai-cms-panel.js +1 -1
- package/dist/components/ai/proposal-card.js +4 -4
- package/dist/components/ai/translate-document-action.js +1 -1
- package/dist/components/ai/translate-document-dialog.d.ts +1 -1
- package/dist/components/app-views/default-modules.d.ts +3 -3
- package/dist/components/app-views/default-modules.js +20 -20
- package/dist/components/app-views/sidebar.d.ts +1 -1
- package/dist/components/app-views/sidebar.js +2 -2
- package/dist/components/app-views/studio-config.d.ts +1 -1
- package/dist/components/assets/asset-detail.js +9 -9
- package/dist/components/assets/asset-grid.js +7 -7
- package/dist/components/assets/asset-thumb.d.ts +1 -1
- package/dist/components/assets/asset-thumb.js +2 -2
- package/dist/components/assets/assets-collection-view-source.js +3 -3
- package/dist/components/assets/assets-module.js +8 -8
- package/dist/components/assets/assets-store.d.ts +1 -1
- package/dist/components/assets/assets-store.js +1 -1
- package/dist/components/builder/blocks-model.js +1 -1
- package/dist/components/builder/blocks-panel.d.ts +1 -1
- package/dist/components/builder/blocks-panel.js +6 -6
- package/dist/components/builder/canvas.js +11 -11
- package/dist/components/builder/clipboard-actions.js +2 -2
- package/dist/components/builder/composition-field-editor-lazy.d.ts +1 -1
- package/dist/components/builder/composition-field-editor-lazy.js +1 -1
- package/dist/components/builder/composition-field-editor.d.ts +1 -1
- package/dist/components/builder/composition-field-editor.js +9 -9
- package/dist/components/builder/insert-context.d.ts +2 -2
- package/dist/components/builder/insert-context.js +2 -2
- package/dist/components/builder/insert-menu.d.ts +2 -2
- package/dist/components/builder/insert-menu.js +1 -1
- package/dist/components/builder/layout-inspector.js +1 -1
- package/dist/components/builder/page-tree.js +5 -5
- package/dist/components/builder/property-inspector.js +3 -3
- package/dist/components/builder/reuse-context.d.ts +1 -1
- package/dist/components/builder/reuse-context.js +3 -3
- package/dist/components/builder/spacing-handles.js +2 -2
- package/dist/components/cms/asset-picker.js +4 -4
- package/dist/components/cms/bulk-actions.js +1 -1
- package/dist/components/cms/bulk-bar.d.ts +1 -1
- package/dist/components/cms/bulk-bar.js +3 -3
- package/dist/components/cms/cell-edit.js +1 -1
- package/dist/components/cms/cell.js +2 -2
- package/dist/components/cms/cms-index.js +1 -1
- package/dist/components/cms/cms-store.d.ts +2 -2
- package/dist/components/cms/cms-store.js +6 -6
- package/dist/components/cms/collection-table.js +17 -17
- package/dist/components/cms/detail-editor.js +31 -31
- package/dist/components/cms/document-diff-view.js +4 -4
- package/dist/components/cms/editable-cell.d.ts +1 -1
- package/dist/components/cms/editable-cell.js +6 -6
- package/dist/components/cms/field-control.js +15 -15
- package/dist/components/cms/field-renderer.d.ts +2 -2
- package/dist/components/cms/filter-builder.js +3 -3
- package/dist/components/cms/import-export.js +1 -1
- package/dist/components/cms/issues-pane.js +1 -1
- package/dist/components/cms/prop-fields.js +3 -3
- package/dist/components/cms/reference-confirm.js +1 -1
- package/dist/components/cms/relation-picker.js +1 -1
- package/dist/components/cms/rich-text/block-commands.d.ts +1 -1
- package/dist/components/cms/rich-text/component-embed.js +2 -2
- package/dist/components/cms/rich-text/editor.js +8 -8
- package/dist/components/cms/rich-text/embed-inspector.d.ts +1 -1
- package/dist/components/cms/rich-text/embed-inspector.js +2 -2
- package/dist/components/cms/rich-text/embed-picker.js +1 -1
- package/dist/components/cms/rich-text/embed-props.js +1 -1
- package/dist/components/cms/rich-text/extensions.d.ts +1 -1
- package/dist/components/cms/rich-text/extensions.js +4 -4
- package/dist/components/cms/rich-text/index.d.ts +1 -1
- package/dist/components/cms/rich-text/index.js +1 -1
- package/dist/components/cms/rich-text/insert.d.ts +1 -1
- package/dist/components/cms/rich-text/lazy.d.ts +1 -1
- package/dist/components/cms/rich-text/lazy.js +1 -1
- package/dist/components/cms/rich-text/slash-command.js +1 -1
- package/dist/components/cms/rich-text/toolbar.d.ts +1 -1
- package/dist/components/cms/rich-text/toolbar.js +4 -4
- package/dist/components/cms/use-cell-edit.d.ts +1 -1
- package/dist/components/cms/use-cell-edit.js +2 -2
- package/dist/components/cms/use-compare-selection.d.ts +1 -1
- package/dist/components/cms/use-discard-controller.d.ts +1 -1
- package/dist/components/cms/use-discard-controller.js +2 -2
- package/dist/components/cms/use-document-versions.d.ts +1 -1
- package/dist/components/cms/use-document-versions.js +1 -1
- package/dist/components/cms/use-embed-inspector-host.d.ts +1 -1
- package/dist/components/cms/use-published-perspective.d.ts +2 -2
- package/dist/components/cms/use-published-perspective.js +2 -2
- package/dist/components/cms/use-restore-version.js +1 -1
- package/dist/components/cms/version-compare-lazy.js +1 -1
- package/dist/components/cms/version-compare.js +6 -6
- package/dist/components/cms/versions-model.d.ts +1 -1
- package/dist/components/cms/versions-pane.js +5 -5
- package/dist/components/cms/view-bar.js +2 -2
- package/dist/components/collab/collab-context.js +1 -1
- package/dist/components/collection-view/cms-collection-view-source.js +2 -2
- package/dist/components/components/component-preview.js +3 -3
- package/dist/components/components/components-index.js +2 -2
- package/dist/components/components/registry-browser.js +2 -2
- package/dist/components/components/transfer-dialog.js +5 -5
- package/dist/components/components/transfer.js +4 -4
- package/dist/components/current-user-menu.js +2 -2
- package/dist/components/delivery-health-banner.js +2 -2
- package/dist/components/operation-error.js +1 -1
- package/dist/components/project-list.js +5 -5
- package/dist/components/project-session.js +1 -1
- package/dist/components/project-switcher.js +3 -3
- package/dist/components/rail-store-status.js +1 -1
- package/dist/components/redirects/redirects-collection-view-source.js +3 -3
- package/dist/components/redirects/redirects-module.js +6 -6
- package/dist/components/section-nav.js +3 -3
- package/dist/components/section-surface.js +1 -1
- package/dist/components/studio-project-screen.js +7 -7
- package/dist/components/studio-shell.js +9 -9
- package/dist/components/use-hydration-phase.js +1 -1
- package/dist/components/users/users-collection-view-source.js +4 -4
- package/dist/components/users/users-module.js +9 -9
- package/dist/components/workspace-projects.js +1 -1
- package/dist/customization.d.ts +9 -9
- package/dist/customization.js +5 -5
- package/dist/lib/ai/anthropic-provider.d.ts +1 -1
- package/dist/lib/ai/apply-content.d.ts +1 -1
- package/dist/lib/ai/apply-content.js +3 -3
- package/dist/lib/ai/chat-state.d.ts +2 -2
- package/dist/lib/ai/config.d.ts +1 -1
- package/dist/lib/ai/create-flow.d.ts +2 -2
- package/dist/lib/ai/create-flow.js +3 -3
- package/dist/lib/ai/fake-provider.d.ts +1 -1
- package/dist/lib/ai/index.d.ts +15 -15
- package/dist/lib/ai/index.js +15 -15
- package/dist/lib/ai/knowledge.d.ts +1 -1
- package/dist/lib/ai/provenance.d.ts +1 -1
- package/dist/lib/ai/route-provider.d.ts +1 -1
- package/dist/lib/ai/route.d.ts +1 -1
- package/dist/lib/ai/shape.d.ts +1 -1
- package/dist/lib/ai/translate-document.d.ts +1 -1
- package/dist/lib/ai/translate-document.js +3 -3
- package/dist/lib/ai-panel.js +1 -1
- package/dist/lib/assets/index.d.ts +4 -4
- package/dist/lib/assets/index.js +4 -4
- package/dist/lib/assets/upload.d.ts +2 -2
- package/dist/lib/assets/upload.js +2 -2
- package/dist/lib/auth/convex-auth-adapter.d.ts +53 -2
- package/dist/lib/auth/convex-auth-adapter.js +149 -68
- package/dist/lib/auth/convex-auth-adapter.js.map +1 -1
- package/dist/lib/auth/dev-auto-login-adapter.d.ts +1 -1
- package/dist/lib/auth/index.d.ts +9 -9
- package/dist/lib/auth/index.js +10 -10
- package/dist/lib/auth/local-auth-adapter.d.ts +1 -1
- package/dist/lib/auth/route-guard.d.ts +1 -1
- package/dist/lib/auth-errors.d.ts +1 -1
- package/dist/lib/clipboard/index.d.ts +3 -3
- package/dist/lib/clipboard/index.js +3 -3
- package/dist/lib/cms/published-documents.d.ts +1 -1
- package/dist/lib/cms-views/index.d.ts +2 -2
- package/dist/lib/cms-views/index.js +2 -2
- package/dist/lib/collection-view/collection-view-source.d.ts +4 -4
- package/dist/lib/data/collection-content.js +1 -1
- package/dist/lib/data/data-store.js +6 -6
- package/dist/lib/data/index.d.ts +4 -4
- package/dist/lib/data/index.js +4 -4
- package/dist/lib/data/sample-capture.js +4 -4
- package/dist/lib/data/sources-store.d.ts +1 -1
- package/dist/lib/diff-view-preference.js +1 -1
- package/dist/lib/dnd/gap-drag.d.ts +1 -1
- package/dist/lib/i18n/i18n.d.ts +1 -1
- package/dist/lib/i18n/i18n.js +1 -1
- package/dist/lib/i18n/index.d.ts +4 -4
- package/dist/lib/i18n/index.js +3 -3
- package/dist/lib/i18n/messages.en.d.ts +1 -1
- package/dist/lib/i18n/messages.en.js +1 -1
- package/dist/lib/locale/binding-fallback.d.ts +1 -1
- package/dist/lib/locale/binding-fallback.js +2 -2
- package/dist/lib/locale/index.d.ts +6 -6
- package/dist/lib/locale/index.js +6 -6
- package/dist/lib/locale/locale-switcher.js +3 -3
- package/dist/lib/locale/use-studio-locale.js +1 -1
- package/dist/lib/operations/asset-repository.d.ts +1 -1
- package/dist/lib/operations/cms-persistence.d.ts +1 -1
- package/dist/lib/operations/cms-persistence.js +1 -1
- package/dist/lib/operations/index.d.ts +6 -6
- package/dist/lib/operations/index.js +6 -6
- package/dist/lib/operations/session-hydration.d.ts +1 -1
- package/dist/lib/operations/session-hydration.js +1 -1
- package/dist/lib/operations/studio-operations.d.ts +1 -1
- package/dist/lib/operations/studio-operations.js +3 -3
- package/dist/lib/persistence/convex-adapter.js +2 -2
- package/dist/lib/persistence/convex-blob-storage.d.ts +1 -1
- package/dist/lib/persistence/convex-blob-storage.js +1 -1
- package/dist/lib/persistence/deployment-readiness.d.ts +2 -2
- package/dist/lib/persistence/index.d.ts +6 -6
- package/dist/lib/persistence/index.js +7 -7
- package/dist/lib/persona/labels.js +1 -1
- package/dist/lib/query/index.d.ts +2 -2
- package/dist/lib/query/index.js +1 -1
- package/dist/lib/rail.js +1 -1
- package/dist/lib/references/impact.d.ts +1 -1
- package/dist/lib/references/impact.js +1 -1
- package/dist/lib/references/index.d.ts +3 -3
- package/dist/lib/references/index.js +3 -3
- package/dist/lib/references/references-store.d.ts +2 -2
- package/dist/lib/references/references-store.js +3 -3
- package/dist/lib/registry/index.js +2 -2
- package/dist/lib/theme.js +1 -1
- package/dist/lib/webhooks/config.d.ts +1 -1
- package/dist/lib/webhooks/config.js +2 -2
- package/dist/lib/webhooks/dispatcher.js +2 -2
- package/dist/lib/webhooks/index.d.ts +6 -6
- package/dist/lib/webhooks/index.js +4 -4
- package/dist/lib/workspace/index.d.ts +7 -7
- package/dist/lib/workspace/index.js +3 -3
- package/dist/lib/workspace/switcher-source.d.ts +1 -1
- package/dist/router/index.d.ts +1 -1
- package/dist/router/index.js +1 -1
- package/dist/ui/avatar.js +1 -1
- package/dist/ui/badge.js +1 -1
- package/dist/ui/button.js +1 -1
- package/dist/ui/card.js +1 -1
- package/dist/ui/collapsible-section.js +2 -2
- package/dist/ui/dialog.js +1 -1
- package/dist/ui/dropdown-menu.js +1 -1
- package/dist/ui/field.js +1 -1
- package/dist/ui/index.d.ts +19 -19
- package/dist/ui/index.js +19 -19
- package/dist/ui/input.js +1 -1
- package/dist/ui/inspector.js +1 -1
- package/dist/ui/layout.js +1 -1
- package/dist/ui/panel.js +2 -2
- package/dist/ui/popover.js +1 -1
- package/dist/ui/row-item.js +2 -2
- package/dist/ui/segmented-control.js +1 -1
- package/dist/ui/separator.js +1 -1
- package/dist/ui/toolbar.js +2 -2
- package/dist/ui/typography.js +1 -1
- package/package.json +3 -3
- package/dist/components/assets/asset-library.d.ts +0 -14
- package/dist/components/assets/asset-library.js +0 -202
- package/dist/components/assets/asset-library.js.map +0 -1
- package/dist/components/backend-gate.d.ts +0 -19
- package/dist/components/backend-gate.js +0 -64
- package/dist/components/backend-gate.js.map +0 -1
- package/dist/components/builder/composition-scope.d.ts +0 -16
- package/dist/components/builder/composition-scope.js +0 -7
- package/dist/components/builder/composition-scope.js.map +0 -1
- package/dist/components/cms/alias-selector.d.ts +0 -20
- package/dist/components/cms/alias-selector.js +0 -34
- package/dist/components/cms/alias-selector.js.map +0 -1
- package/dist/components/cms/collections-sidebar.d.ts +0 -18
- package/dist/components/cms/collections-sidebar.js +0 -36
- package/dist/components/cms/collections-sidebar.js.map +0 -1
- package/dist/components/cms/new-page-dialog.d.ts +0 -22
- package/dist/components/cms/new-page-dialog.js +0 -42
- package/dist/components/cms/new-page-dialog.js.map +0 -1
- package/dist/components/cms/rich-text/embed-control.d.ts +0 -17
- package/dist/components/cms/rich-text/embed-control.js +0 -62
- package/dist/components/cms/rich-text/embed-control.js.map +0 -1
- package/dist/components/cms/rich-text/image-control.d.ts +0 -16
- package/dist/components/cms/rich-text/image-control.js +0 -36
- package/dist/components/cms/rich-text/image-control.js.map +0 -1
- package/dist/components/components/fixture-runner.d.ts +0 -10
- package/dist/components/components/fixture-runner.js +0 -27
- package/dist/components/components/fixture-runner.js.map +0 -1
- package/dist/components/references/builder-deep-link.d.ts +0 -12
- package/dist/components/references/builder-deep-link.js +0 -53
- package/dist/components/references/builder-deep-link.js.map +0 -1
- package/dist/components/routes/redirect-chain.d.ts +0 -9
- package/dist/components/routes/redirect-chain.js +0 -16
- package/dist/components/routes/redirect-chain.js.map +0 -1
- package/dist/components/routes/redirect-manager.d.ts +0 -13
- package/dist/components/routes/redirect-manager.js +0 -24
- package/dist/components/routes/redirect-manager.js.map +0 -1
- package/dist/components/routes/route-list.d.ts +0 -35
- package/dist/components/routes/route-list.js +0 -69
- package/dist/components/routes/route-list.js.map +0 -1
- package/dist/components/routes/routes-shell.d.ts +0 -14
- package/dist/components/routes/routes-shell.js +0 -68
- package/dist/components/routes/routes-shell.js.map +0 -1
- package/dist/components/sections.d.ts +0 -37
- package/dist/components/sections.js +0 -62
- package/dist/components/sections.js.map +0 -1
- package/dist/components/users/user-search.d.ts +0 -8
- package/dist/components/users/user-search.js +0 -13
- package/dist/components/users/user-search.js.map +0 -1
- package/dist/components/workspace-gate.d.ts +0 -12
- package/dist/components/workspace-gate.js +0 -28
- package/dist/components/workspace-gate.js.map +0 -1
- package/dist/lib/cms-views/views-store.d.ts +0 -70
- package/dist/lib/cms-views/views-store.js +0 -129
- package/dist/lib/cms-views/views-store.js.map +0 -1
- package/dist/lib/operations/graph-commands.d.ts +0 -136
- package/dist/lib/operations/graph-commands.js +0 -85
- package/dist/lib/operations/graph-commands.js.map +0 -1
- package/dist/lib/operations/graph-persistence.d.ts +0 -27
- package/dist/lib/operations/graph-persistence.js +0 -35
- package/dist/lib/operations/graph-persistence.js.map +0 -1
- package/dist/lib/routing/index.d.ts +0 -10
- package/dist/lib/routing/index.js +0 -11
- package/dist/lib/routing/index.js.map +0 -1
- package/dist/lib/routing/routing-analysis.d.ts +0 -26
- package/dist/lib/routing/routing-analysis.js +0 -37
- package/dist/lib/routing/routing-analysis.js.map +0 -1
- package/dist/lib/routing/routing-store.d.ts +0 -50
- package/dist/lib/routing/routing-store.js +0 -72
- package/dist/lib/routing/routing-store.js.map +0 -1
- package/dist/lib/working-graph.d.ts +0 -82
- package/dist/lib/working-graph.js +0 -113
- package/dist/lib/working-graph.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ConvexHttpClient } from 'convex/browser';
|
|
2
|
-
import type { AuthAdapter, AuthSession, ChangePasswordInput, ChangePasswordResult, SignInCredentials, SignInResult, UpdateProfileInput, UpdateProfileResult } from './auth-adapter';
|
|
3
|
-
import type { SessionStore } from './local-auth-adapter';
|
|
2
|
+
import type { AuthAdapter, AuthSession, ChangePasswordInput, ChangePasswordResult, SignInCredentials, SignInResult, UpdateProfileInput, UpdateProfileResult } from './auth-adapter.js';
|
|
3
|
+
import type { SessionStore } from './local-auth-adapter.js';
|
|
4
4
|
/**
|
|
5
5
|
* Classify a thrown sign-in error as a DEPLOYMENT-setup failure rather than a
|
|
6
6
|
* credential problem (EC-257). Matches the Convex Auth signing-path throws:
|
|
@@ -12,6 +12,56 @@ import type { SessionStore } from './local-auth-adapter';
|
|
|
12
12
|
* fallback is the neutral "unavailable" branch (never "password too short").
|
|
13
13
|
*/
|
|
14
14
|
export declare function isDeploymentMisconfigured(message: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Reduce a thrown Convex error to the text used for classification (EC-362).
|
|
17
|
+
*
|
|
18
|
+
* **Read `.data` FIRST, then `.message`** — because a PRODUCTION Convex
|
|
19
|
+
* deployment REDACTS a UDF's thrown-error `.message` to a generic
|
|
20
|
+
* `"[Request ID: …] Server Error"`, but a `ConvexError`'s `.data` payload
|
|
21
|
+
* survives to the client. Proven in the installed `convex@1.42.1` browser
|
|
22
|
+
* client: on an `"error"` response `ConvexHttpClient.action` throws
|
|
23
|
+
* `forwardErrorData(respJSON.errorData, new ConvexError(respJSON.errorMessage))`,
|
|
24
|
+
* and `forwardErrorData` sets `error.data = jsonToConvex(errorData)`
|
|
25
|
+
* (`dist/esm/browser/http_client.js`, ~L388-396 + L459-461). The server keeps
|
|
26
|
+
* `errorData` for a `ConvexError` in prod while redacting `errorMessage`. So the
|
|
27
|
+
* only classifiable text that survives prod is the `.data` of a `ConvexError` —
|
|
28
|
+
* e.g. our invite gate's `ConvexError(NOT_INVITED_REASON)`. On DEV deployments
|
|
29
|
+
* nothing is redacted, so `.message` also carries the token (the regex ladder
|
|
30
|
+
* still matches); non-Convex errors only have a `.message`.
|
|
31
|
+
*
|
|
32
|
+
* Duck-types the `data` property rather than `instanceof ConvexError`: two
|
|
33
|
+
* copies of the `convex` module can coexist under Vite (transformed vs
|
|
34
|
+
* pre-bundled), so `instanceof` can spuriously fail (EC-357). `.data` may be a
|
|
35
|
+
* string (our gates) or a structured object (future gates) — both are folded in.
|
|
36
|
+
*/
|
|
37
|
+
export declare function convexErrorClassifierText(error: unknown): string;
|
|
38
|
+
type SignInFailure = Extract<SignInResult, {
|
|
39
|
+
ok: false;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Pure sign-in/sign-up error classifier (EC-257 / EC-324 / EC-362). Runs the
|
|
43
|
+
* regex ladder over {@link convexErrorClassifierText} output (data-first).
|
|
44
|
+
*
|
|
45
|
+
* Order matters: a DEPLOYMENT-misconfiguration (EC-257) and an uninvited
|
|
46
|
+
* sign-up (EC-324) are each checked BEFORE the credential regex so neither
|
|
47
|
+
* degrades to the lying "password too short". The final fallback is HONEST
|
|
48
|
+
* ("unexpected server error — check the deployment logs"), never "unavailable":
|
|
49
|
+
* on a prod deployment the credential/`InvalidAccountId`/env errors thrown by
|
|
50
|
+
* `@convex-dev/auth` are PLAIN `Error`s (not `ConvexError`s), so prod redacts
|
|
51
|
+
* them to `"Server Error"` with no `.data` and they legitimately land here.
|
|
52
|
+
*/
|
|
53
|
+
export declare function classifySignInError(flow: 'signIn' | 'signUp', text: string): SignInFailure;
|
|
54
|
+
type ChangePasswordFailure = Extract<ChangePasswordResult, {
|
|
55
|
+
ok: false;
|
|
56
|
+
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Pure password-change error classifier (EC-240 H-tail / EC-362). Same
|
|
59
|
+
* data-first text + honest fallback discipline as {@link classifySignInError};
|
|
60
|
+
* `deployment-misconfigured` collapses onto the `unavailable` reason
|
|
61
|
+
* (`ChangePasswordResult` has no dedicated reason for it) with a specific
|
|
62
|
+
* remediation message.
|
|
63
|
+
*/
|
|
64
|
+
export declare function classifyChangePasswordError(text: string): ChangePasswordFailure;
|
|
15
65
|
/**
|
|
16
66
|
* Per-deployment token key (EC-179, vision AD-8). One project per backend, so a
|
|
17
67
|
* session is scoped to its deployment: signing into Aurora's backend must not
|
|
@@ -64,3 +114,4 @@ export declare class ConvexAuthAdapter implements AuthAdapter {
|
|
|
64
114
|
private toUser;
|
|
65
115
|
private clearToken;
|
|
66
116
|
}
|
|
117
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { actionRef, mutationRef, queryRef } from '../persistence/convex-client';
|
|
1
|
+
import { actionRef, mutationRef, queryRef } from '../persistence/convex-client.js';
|
|
2
2
|
/**
|
|
3
3
|
* Convex Auth implementation of the project-owned {@link AuthAdapter}
|
|
4
4
|
* (EC-150). Decision record (also in `convex/auth.ts`): **Convex Auth** over
|
|
@@ -35,6 +35,146 @@ const TOKEN_STORAGE_PREFIX = 'elytra.convex-auth.jwt';
|
|
|
35
35
|
export function isDeploymentMisconfigured(message) {
|
|
36
36
|
return /JWT_PRIVATE_KEY|JWKS|CONVEX_SITE_URL|Missing environment variable|PKCS8|private key/i.test(message);
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Reduce a thrown Convex error to the text used for classification (EC-362).
|
|
40
|
+
*
|
|
41
|
+
* **Read `.data` FIRST, then `.message`** — because a PRODUCTION Convex
|
|
42
|
+
* deployment REDACTS a UDF's thrown-error `.message` to a generic
|
|
43
|
+
* `"[Request ID: …] Server Error"`, but a `ConvexError`'s `.data` payload
|
|
44
|
+
* survives to the client. Proven in the installed `convex@1.42.1` browser
|
|
45
|
+
* client: on an `"error"` response `ConvexHttpClient.action` throws
|
|
46
|
+
* `forwardErrorData(respJSON.errorData, new ConvexError(respJSON.errorMessage))`,
|
|
47
|
+
* and `forwardErrorData` sets `error.data = jsonToConvex(errorData)`
|
|
48
|
+
* (`dist/esm/browser/http_client.js`, ~L388-396 + L459-461). The server keeps
|
|
49
|
+
* `errorData` for a `ConvexError` in prod while redacting `errorMessage`. So the
|
|
50
|
+
* only classifiable text that survives prod is the `.data` of a `ConvexError` —
|
|
51
|
+
* e.g. our invite gate's `ConvexError(NOT_INVITED_REASON)`. On DEV deployments
|
|
52
|
+
* nothing is redacted, so `.message` also carries the token (the regex ladder
|
|
53
|
+
* still matches); non-Convex errors only have a `.message`.
|
|
54
|
+
*
|
|
55
|
+
* Duck-types the `data` property rather than `instanceof ConvexError`: two
|
|
56
|
+
* copies of the `convex` module can coexist under Vite (transformed vs
|
|
57
|
+
* pre-bundled), so `instanceof` can spuriously fail (EC-357). `.data` may be a
|
|
58
|
+
* string (our gates) or a structured object (future gates) — both are folded in.
|
|
59
|
+
*/
|
|
60
|
+
export function convexErrorClassifierText(error) {
|
|
61
|
+
const parts = [];
|
|
62
|
+
if (typeof error === 'object' && error !== null && 'data' in error) {
|
|
63
|
+
const data = error.data;
|
|
64
|
+
if (typeof data === 'string') {
|
|
65
|
+
parts.push(data);
|
|
66
|
+
}
|
|
67
|
+
else if (data !== null && data !== undefined) {
|
|
68
|
+
try {
|
|
69
|
+
parts.push(JSON.stringify(data));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// Non-serializable data (cycles) — ignore; fall back to the message.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (error instanceof Error)
|
|
77
|
+
parts.push(error.message);
|
|
78
|
+
else if (typeof error === 'string')
|
|
79
|
+
parts.push(error);
|
|
80
|
+
if (parts.length === 0)
|
|
81
|
+
parts.push(String(error));
|
|
82
|
+
return parts.join('\n');
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Pure sign-in/sign-up error classifier (EC-257 / EC-324 / EC-362). Runs the
|
|
86
|
+
* regex ladder over {@link convexErrorClassifierText} output (data-first).
|
|
87
|
+
*
|
|
88
|
+
* Order matters: a DEPLOYMENT-misconfiguration (EC-257) and an uninvited
|
|
89
|
+
* sign-up (EC-324) are each checked BEFORE the credential regex so neither
|
|
90
|
+
* degrades to the lying "password too short". The final fallback is HONEST
|
|
91
|
+
* ("unexpected server error — check the deployment logs"), never "unavailable":
|
|
92
|
+
* on a prod deployment the credential/`InvalidAccountId`/env errors thrown by
|
|
93
|
+
* `@convex-dev/auth` are PLAIN `Error`s (not `ConvexError`s), so prod redacts
|
|
94
|
+
* them to `"Server Error"` with no `.data` and they legitimately land here.
|
|
95
|
+
*/
|
|
96
|
+
export function classifySignInError(flow, text) {
|
|
97
|
+
// EC-257: a DEPLOYMENT-misconfiguration — its auth signing key is unset — must be
|
|
98
|
+
// classified FIRST so it never falls through to the lying "password too short".
|
|
99
|
+
// Convex Auth signs the session JWT with the deployment's `JWT_PRIVATE_KEY`
|
|
100
|
+
// (+ `JWKS`/`CONVEX_SITE_URL`); when any is unset (`npx @convex-dev/auth` never
|
|
101
|
+
// run) the `requireEnv`/`importPKCS8` call throws AFTER the password is validated,
|
|
102
|
+
// so EVERY sign-in fails regardless of the password.
|
|
103
|
+
if (isDeploymentMisconfigured(text)) {
|
|
104
|
+
return {
|
|
105
|
+
ok: false,
|
|
106
|
+
reason: 'deployment-misconfigured',
|
|
107
|
+
message: 'This deployment can’t sign you in: its auth signing key is not set. Run `npx @convex-dev/auth` against this deployment, then retry. (The deployment-setup check reports the same.)',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
// EC-324: an uninvited sign-up is rejected server-side (`gateAccountCreation`/
|
|
111
|
+
// `gateSessionCreation` throw `ConvexError(NOT_INVITED_REASON)`, whose `.data`
|
|
112
|
+
// survives to the client even in production). Checked BEFORE the credential regex.
|
|
113
|
+
if (/not-invited|invite-only|invite only/i.test(text)) {
|
|
114
|
+
return {
|
|
115
|
+
ok: false,
|
|
116
|
+
reason: 'not-invited',
|
|
117
|
+
message: 'This deployment is invite-only. Ask an admin to invite your email, then create your account.',
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (flow === 'signUp' && /already|exists|InvalidAccountId/i.test(text)) {
|
|
121
|
+
return {
|
|
122
|
+
ok: false,
|
|
123
|
+
reason: 'account-exists',
|
|
124
|
+
message: 'An account with this email already exists — sign in instead.',
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (/InvalidSecret|InvalidAccountId|credential|password/i.test(text)) {
|
|
128
|
+
return {
|
|
129
|
+
ok: false,
|
|
130
|
+
reason: 'invalid-credentials',
|
|
131
|
+
message: flow === 'signUp'
|
|
132
|
+
? 'That email or password can’t be used (password too short?).'
|
|
133
|
+
: 'Email or password is incorrect.',
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const verb = flow === 'signUp' ? 'Sign-up' : 'Sign-in';
|
|
137
|
+
return {
|
|
138
|
+
ok: false,
|
|
139
|
+
reason: 'unavailable',
|
|
140
|
+
message: `${verb} failed (unexpected server error) — check the deployment logs.`,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Pure password-change error classifier (EC-240 H-tail / EC-362). Same
|
|
145
|
+
* data-first text + honest fallback discipline as {@link classifySignInError};
|
|
146
|
+
* `deployment-misconfigured` collapses onto the `unavailable` reason
|
|
147
|
+
* (`ChangePasswordResult` has no dedicated reason for it) with a specific
|
|
148
|
+
* remediation message.
|
|
149
|
+
*/
|
|
150
|
+
export function classifyChangePasswordError(text) {
|
|
151
|
+
if (isDeploymentMisconfigured(text)) {
|
|
152
|
+
return {
|
|
153
|
+
ok: false,
|
|
154
|
+
reason: 'unavailable',
|
|
155
|
+
message: 'This deployment can’t change your password: its auth signing key is not set. Run `npx @convex-dev/auth`.',
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (/InvalidSecret|InvalidAccountId|current password|incorrect/i.test(text)) {
|
|
159
|
+
return {
|
|
160
|
+
ok: false,
|
|
161
|
+
reason: 'invalid-credentials',
|
|
162
|
+
message: 'Your current password is incorrect.',
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
if (/at least|too short|8 characters|password requirement|weak/i.test(text)) {
|
|
166
|
+
return {
|
|
167
|
+
ok: false,
|
|
168
|
+
reason: 'weak-password',
|
|
169
|
+
message: 'Choose a stronger password (at least 8 characters).',
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
ok: false,
|
|
174
|
+
reason: 'unavailable',
|
|
175
|
+
message: 'Password change failed (unexpected server error) — check the deployment logs.',
|
|
176
|
+
};
|
|
177
|
+
}
|
|
38
178
|
/**
|
|
39
179
|
* Per-deployment token key (EC-179, vision AD-8). One project per backend, so a
|
|
40
180
|
* session is scoped to its deployment: signing into Aurora's backend must not
|
|
@@ -120,50 +260,10 @@ export class ConvexAuthAdapter {
|
|
|
120
260
|
}
|
|
121
261
|
catch (error) {
|
|
122
262
|
// Convex Auth surfaces credential/registration problems as thrown errors.
|
|
123
|
-
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
// (+ `JWKS`/`CONVEX_SITE_URL`); when any is unset (`npx @convex-dev/auth`
|
|
128
|
-
// never run) the `requireEnv`/`importPKCS8` call throws *after* the password
|
|
129
|
-
// is validated, so EVERY sign-in fails regardless of the password. This is
|
|
130
|
-
// the exact footgun that cost hours on the Konditorei proof (2026-06-22).
|
|
131
|
-
if (isDeploymentMisconfigured(message)) {
|
|
132
|
-
return {
|
|
133
|
-
ok: false,
|
|
134
|
-
reason: 'deployment-misconfigured',
|
|
135
|
-
message: 'This deployment can’t sign you in: its auth signing key is not set. Run `npx @convex-dev/auth` against this deployment, then retry. (The deployment-setup check reports the same.)',
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
// EC-324: an uninvited sign-up is rejected server-side (`beforeSessionCreation`
|
|
139
|
-
// throws a `ConvexError('not-invited: …')`, whose data survives to the client
|
|
140
|
-
// even in production). Classified BEFORE the credential regex so it never
|
|
141
|
-
// degrades to "password too short".
|
|
142
|
-
if (/not-invited|invite-only|invite only/i.test(message)) {
|
|
143
|
-
return {
|
|
144
|
-
ok: false,
|
|
145
|
-
reason: 'not-invited',
|
|
146
|
-
message: 'This deployment is invite-only. Ask an admin to invite your email, then create your account.',
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
if (flow === 'signUp' && /already|exists|InvalidAccountId/i.test(message)) {
|
|
150
|
-
return {
|
|
151
|
-
ok: false,
|
|
152
|
-
reason: 'account-exists',
|
|
153
|
-
message: 'An account with this email already exists — sign in instead.',
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
if (/InvalidSecret|InvalidAccountId|credential|password/i.test(message)) {
|
|
157
|
-
return {
|
|
158
|
-
ok: false,
|
|
159
|
-
reason: 'invalid-credentials',
|
|
160
|
-
message: flow === 'signUp'
|
|
161
|
-
? 'That email or password can’t be used (password too short?).'
|
|
162
|
-
: 'Email or password is incorrect.',
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
const verb = flow === 'signUp' ? 'Sign-up' : 'Sign-in';
|
|
166
|
-
return { ok: false, reason: 'unavailable', message: `${verb} is currently unavailable.` };
|
|
263
|
+
// Classify from the DATA-FIRST text (a `ConvexError`'s `.data` survives prod
|
|
264
|
+
// redaction, the redacted `.message` does not — EC-362), then apply the pure
|
|
265
|
+
// regex ladder. See `convexErrorClassifierText` / `classifySignInError`.
|
|
266
|
+
return classifySignInError(flow, convexErrorClassifierText(error));
|
|
167
267
|
}
|
|
168
268
|
if (!result.tokens) {
|
|
169
269
|
return {
|
|
@@ -239,29 +339,10 @@ export class ConvexAuthAdapter {
|
|
|
239
339
|
return { ok: true };
|
|
240
340
|
}
|
|
241
341
|
catch (error) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
reason: 'unavailable',
|
|
247
|
-
message: 'This deployment can’t change your password: its auth signing key is not set. Run `npx @convex-dev/auth`.',
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
if (/InvalidSecret|InvalidAccountId|current password|incorrect/i.test(message)) {
|
|
251
|
-
return {
|
|
252
|
-
ok: false,
|
|
253
|
-
reason: 'invalid-credentials',
|
|
254
|
-
message: 'Your current password is incorrect.',
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
if (/at least|too short|8 characters|password requirement|weak/i.test(message)) {
|
|
258
|
-
return {
|
|
259
|
-
ok: false,
|
|
260
|
-
reason: 'weak-password',
|
|
261
|
-
message: 'Choose a stronger password (at least 8 characters).',
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
return { ok: false, reason: 'unavailable', message: 'Password change is currently unavailable.' };
|
|
342
|
+
// Data-first classification (EC-362): the change-password ACTION runs on the
|
|
343
|
+
// same deployment, so a prod redaction erases the thrown `.message` the same
|
|
344
|
+
// way — read a surviving `ConvexError.data` first.
|
|
345
|
+
return classifyChangePasswordError(convexErrorClassifierText(error));
|
|
265
346
|
}
|
|
266
347
|
}
|
|
267
348
|
toUser(me) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convex-auth-adapter.js","sourceRoot":"","sources":["../../../src/lib/auth/convex-auth-adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAa/E;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,oBAAoB,GAAG,wBAAwB,CAAA;AAErD;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAe;IACvD,OAAO,sFAAsF,CAAC,IAAI,CAChG,OAAO,CACR,CAAA;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,aAAsB;IACpD,OAAO,aAAa,CAAC,CAAC,CAAC,GAAG,oBAAoB,KAAK,aAAa,EAAE,CAAC,CAAC,CAAC,oBAAoB,CAAA;AAC3F,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,aAAqB,EACrB,QAAsB,YAAY,EAAE;IAEpC,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,KAAK,IAAI,CAAA;AAC/D,CAAC;AAYD,SAAS,YAAY;IACnB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,cAAc;QAAE,OAAO,MAAM,CAAC,cAAc,CAAA;IACxF,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;IACxC,OAAO;QACL,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI;QACzC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,E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mutationRef, queryRef } from '../persistence/convex-client'\nimport type {\n AuthAdapter,\n AuthSession,\n ChangePasswordInput,\n ChangePasswordResult,\n SignInCredentials,\n SignInResult,\n UpdateProfileInput,\n UpdateProfileResult,\n} from './auth-adapter'\nimport type { SessionStore } from './local-auth-adapter'\n\n/**\n * Convex Auth implementation of the project-owned {@link AuthAdapter}\n * (EC-150). Decision record (also in `convex/auth.ts`): **Convex Auth** over\n * Clerk — self-contained on the Convex stack, sessions in our own tables, no\n * extra vendor; reachable only through this adapter so a swap stays local.\n *\n * Flow (server side lives in `convex/auth.ts` + `convex/users.ts`):\n * 1. `signIn` calls the `auth:signIn` action with the Password provider\n * (`flow: 'signIn'`); on success Convex returns a JWT + refresh token.\n * 2. The JWT is set on the *shared* Convex client (`client.setAuth`), so every\n * subsequent persistence query/mutation runs authenticated and the\n * server-side `requireRole` guards see the caller.\n * 3. `currentSession` restores the JWT from storage and asks `users:me`.\n * 4. `signOut` calls `auth:signOut` and clears the JWT.\n *\n * v1 scope note: the stored JWT is short-lived and this adapter does not yet\n * run the refresh-token loop (the official `@convex-dev/auth/react` client\n * does); an expired session simply resolves to \"signed out\" and the user signs\n * in again. Live-deployment hardening is EC-156. No live deployment exists in\n * this repo — this file is typecheck-verified and exercised against the local\n * adapter's shared interface.\n */\n\nconst TOKEN_STORAGE_PREFIX = 'elytra.convex-auth.jwt'\n\n/**\n * Classify a thrown sign-in error as a DEPLOYMENT-setup failure rather than a\n * credential problem (EC-257). Matches the Convex Auth signing-path throws:\n * `requireEnv('JWT_PRIVATE_KEY'|'JWKS'|'CONVEX_SITE_URL')` (→ \"Missing environment\n * variable …\") and `importPKCS8` on a malformed key. Deliberately narrow — a genuine\n * wrong-password error carries none of these tokens — and checked BEFORE the credential\n * regex so it always wins. Note: a PRODUCTION deployment redacts non-`ConvexError`\n * messages to a generic \"Server Error\", which this can't match; there the honest\n * fallback is the neutral \"unavailable\" branch (never \"password too short\").\n */\nexport function isDeploymentMisconfigured(message: string): boolean {\n return /JWT_PRIVATE_KEY|JWKS|CONVEX_SITE_URL|Missing environment variable|PKCS8|private key/i.test(\n message,\n )\n}\n\n/**\n * Per-deployment token key (EC-179, vision AD-8). One project per backend, so a\n * session is scoped to its deployment: signing into Aurora's backend must not\n * carry a JWT to Northwind's. Keying the stored token by the deployment URL\n * makes each backend's session independent — switching to a project on a\n * not-yet-authenticated backend reads no token and the guard asks for sign-in.\n * (A future shared external IdP — WorkOS/Clerk — would issue one identity valid\n * on every deployment, collapsing this back to a single session.)\n */\nexport function tokenStorageKey(deploymentUrl?: string): string {\n return deploymentUrl ? `${TOKEN_STORAGE_PREFIX}::${deploymentUrl}` : TOKEN_STORAGE_PREFIX\n}\n\n/**\n * Best-effort \"is there a session for this deployment?\" — a synchronous token\n * presence check used to label per-backend projects in the switcher/launcher\n * (EC-179). It does not validate the token (an expired one still redirects to\n * sign-in on entry); it just answers \"has the user signed into this backend?\".\n */\nexport function hasStoredConvexSession(\n deploymentUrl: string,\n store: SessionStore = defaultStore(),\n): boolean {\n return store.getItem(tokenStorageKey(deploymentUrl)) !== null\n}\n\ninterface SignInActionResult {\n tokens?: { token: string; refreshToken: string } | null\n}\n\ninterface MeResult {\n id: string\n email: string\n name?: string\n}\n\nfunction defaultStore(): SessionStore {\n if (typeof window !== 'undefined' && window.sessionStorage) return window.sessionStorage\n const memory = new Map<string, string>()\n return {\n getItem: (key) => memory.get(key) ?? null,\n setItem: (key, value) => void memory.set(key, value),\n removeItem: (key) => void memory.delete(key),\n }\n}\n\nexport class ConvexAuthAdapter implements AuthAdapter {\n private readonly tokenKey: string\n\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly store: SessionStore = defaultStore(),\n /** Deployment URL the token is scoped to (per-backend sessions, EC-179). */\n deploymentUrl?: string,\n ) {\n this.tokenKey = tokenStorageKey(deploymentUrl)\n }\n\n async currentSession(): Promise<AuthSession | null> {\n const token = this.store.getItem(this.tokenKey)\n if (!token) return null\n this.client.setAuth(token)\n try {\n const me = (await this.client.query(queryRef('users:me'), {})) as MeResult | null\n if (!me) {\n this.clearToken()\n return null\n }\n return { user: this.toUser(me) }\n } catch {\n // Expired/invalid JWT or unreachable backend → treat as signed out.\n this.clearToken()\n return null\n }\n }\n\n async signIn(credentials: SignInCredentials): Promise<SignInResult> {\n return this.authenticate('signIn', credentials)\n }\n\n async signUp(credentials: SignInCredentials): Promise<SignInResult> {\n return this.authenticate('signUp', credentials)\n }\n\n /**\n * Shared password flow (EC-150/EC-179). `signIn` and `signUp` differ only by\n * the Convex Auth `flow` param; both return a token + load `users:me`.\n */\n private async authenticate(\n flow: 'signIn' | 'signUp',\n credentials: SignInCredentials,\n ): Promise<SignInResult> {\n let result: SignInActionResult\n try {\n result = (await this.client.action(actionRef('auth:signIn'), {\n provider: 'password',\n params: {\n email: credentials.email.trim().toLowerCase(),\n password: credentials.password,\n flow,\n },\n })) as SignInActionResult\n } catch (error) {\n // Convex Auth surfaces credential/registration problems as thrown errors.\n const message = error instanceof Error ? error.message : String(error)\n // EC-257: a DEPLOYMENT-misconfiguration — not a credential problem — must be\n // classified FIRST so it never falls through to the lying \"password too short\".\n // Convex Auth signs the session JWT with the deployment's `JWT_PRIVATE_KEY`\n // (+ `JWKS`/`CONVEX_SITE_URL`); when any is unset (`npx @convex-dev/auth`\n // never run) the `requireEnv`/`importPKCS8` call throws *after* the password\n // is validated, so EVERY sign-in fails regardless of the password. This is\n // the exact footgun that cost hours on the Konditorei proof (2026-06-22).\n if (isDeploymentMisconfigured(message)) {\n return {\n ok: false,\n reason: 'deployment-misconfigured',\n message:\n 'This deployment can’t sign you in: its auth signing key is not set. Run `npx @convex-dev/auth` against this deployment, then retry. (The deployment-setup check reports the same.)',\n }\n }\n // EC-324: an uninvited sign-up is rejected server-side (`beforeSessionCreation`\n // throws a `ConvexError('not-invited: …')`, whose data survives to the client\n // even in production). Classified BEFORE the credential regex so it never\n // degrades to \"password too short\".\n if (/not-invited|invite-only|invite only/i.test(message)) {\n return {\n ok: false,\n reason: 'not-invited',\n message:\n 'This deployment is invite-only. Ask an admin to invite your email, then create your account.',\n }\n }\n if (flow === 'signUp' && /already|exists|InvalidAccountId/i.test(message)) {\n return {\n ok: false,\n reason: 'account-exists',\n message: 'An account with this email already exists — sign in instead.',\n }\n }\n if (/InvalidSecret|InvalidAccountId|credential|password/i.test(message)) {\n return {\n ok: false,\n reason: 'invalid-credentials',\n message:\n flow === 'signUp'\n ? 'That email or password can’t be used (password too short?).'\n : 'Email or password is incorrect.',\n }\n }\n const verb = flow === 'signUp' ? 'Sign-up' : 'Sign-in'\n return { ok: false, reason: 'unavailable', message: `${verb} is currently unavailable.` }\n }\n if (!result.tokens) {\n return {\n ok: false,\n reason: 'invalid-credentials',\n message: 'Email or password is incorrect.',\n }\n }\n this.store.setItem(this.tokenKey, result.tokens.token)\n this.client.setAuth(result.tokens.token)\n const me = (await this.client.query(queryRef('users:me'), {})) as MeResult | null\n if (!me) {\n this.clearToken()\n return { ok: false, reason: 'unavailable', message: 'Sign-in is currently unavailable.' }\n }\n return { ok: true, session: { user: this.toUser(me) } }\n }\n\n async signOut(): Promise<void> {\n try {\n await this.client.action(actionRef('auth:signOut'), {})\n } catch {\n // Already signed out / unreachable — clearing local state is what matters.\n }\n this.clearToken()\n }\n\n /**\n * Self-service identity edit (EC-240 H-tail item 2). Patches the caller's OWN\n * auth `users` row (name / avatar) via the self-scoped `users:updateProfile`\n * mutation, then re-reads `users:me` so the returned session carries the new\n * name. Auth-owned fields never flow through the members-rail `users.save`.\n */\n async updateProfile(input: UpdateProfileInput): Promise<UpdateProfileResult> {\n const token = this.store.getItem(this.tokenKey)\n if (!token) {\n return { ok: false, reason: 'not-authenticated', message: 'You are not signed in.' }\n }\n this.client.setAuth(token)\n try {\n await this.client.mutation(mutationRef('users:updateProfile'), {\n ...(input.name !== undefined ? { name: input.name } : {}),\n ...(input.avatar !== undefined ? { avatar: input.avatar } : {}),\n })\n const me = (await this.client.query(queryRef('users:me'), {})) as MeResult | null\n if (!me) {\n return { ok: false, reason: 'unavailable', message: 'Profile update is currently unavailable.' }\n }\n return { ok: true, session: { user: this.toUser(me) } }\n } catch {\n return { ok: false, reason: 'unavailable', message: 'Profile update is currently unavailable.' }\n }\n }\n\n /**\n * Self-service password change (EC-240 H-tail item 3). Delegates entirely to\n * the provider via the self-scoped `users:changePassword` ACTION (which calls\n * Convex Auth's `retrieveAccount` to verify the current password, then\n * `modifyAccountCredentials` to set the new one). **Seam only:** the raw\n * password values are forwarded to the provider and NEVER logged or inspected\n * here.\n */\n async changePassword(input: ChangePasswordInput): Promise<ChangePasswordResult> {\n const token = this.store.getItem(this.tokenKey)\n if (!token) {\n return { ok: false, reason: 'not-authenticated', message: 'You are not signed in.' }\n }\n this.client.setAuth(token)\n try {\n await this.client.action(actionRef('users:changePassword'), {\n currentPassword: input.currentPassword,\n newPassword: input.newPassword,\n })\n return { ok: true }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n if (isDeploymentMisconfigured(message)) {\n return {\n ok: false,\n reason: 'unavailable',\n message:\n 'This deployment can’t change your password: its auth signing key is not set. Run `npx @convex-dev/auth`.',\n }\n }\n if (/InvalidSecret|InvalidAccountId|current password|incorrect/i.test(message)) {\n return {\n ok: false,\n reason: 'invalid-credentials',\n message: 'Your current password is incorrect.',\n }\n }\n if (/at least|too short|8 characters|password requirement|weak/i.test(message)) {\n return {\n ok: false,\n reason: 'weak-password',\n message: 'Choose a stronger password (at least 8 characters).',\n }\n }\n return { ok: false, reason: 'unavailable', message: 'Password change is currently unavailable.' }\n }\n }\n\n private toUser(me: MeResult): AuthSession['user'] {\n return {\n id: me.id,\n email: me.email,\n ...(me.name ? { name: me.name } : {}),\n // No global flags: project creation is config/CLI-owned (AD-11), so there\n // is no in-studio `create-projects` capability. Per-project roles come\n // from `projectMembers`.\n globalFlags: [],\n }\n }\n\n private clearToken(): void {\n this.store.removeItem(this.tokenKey)\n this.client.clearAuth()\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"convex-auth-adapter.js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KAAK,CAAC,WAAW;aAC/B,CAAC,CAAA;YACF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,6EAA6E;YAC7E,6EAA6E;YAC7E,mDAAmD;YACnD,OAAO,2BAA2B,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAA;QACtE,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,EAAY;QACzB,OAAO;YACL,EAAE,EAAE,EAAE,CAAC,EAAE;YACT,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrC,0EAA0E;YAC1E,uEAAuE;YACvE,yBAAyB;YACzB,WAAW,EAAE,EAAE;SAChB,CAAA;IACH,CAAC;IAEO,UAAU;QAChB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACpC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IACzB,CAAC;CACF","sourcesContent":["import type { ConvexHttpClient } from 'convex/browser'\nimport { actionRef, mutationRef, queryRef } from '../persistence/convex-client'\nimport type {\n AuthAdapter,\n AuthSession,\n ChangePasswordInput,\n ChangePasswordResult,\n SignInCredentials,\n SignInResult,\n UpdateProfileInput,\n UpdateProfileResult,\n} from './auth-adapter'\nimport type { SessionStore } from './local-auth-adapter'\n\n/**\n * Convex Auth implementation of the project-owned {@link AuthAdapter}\n * (EC-150). Decision record (also in `convex/auth.ts`): **Convex Auth** over\n * Clerk — self-contained on the Convex stack, sessions in our own tables, no\n * extra vendor; reachable only through this adapter so a swap stays local.\n *\n * Flow (server side lives in `convex/auth.ts` + `convex/users.ts`):\n * 1. `signIn` calls the `auth:signIn` action with the Password provider\n * (`flow: 'signIn'`); on success Convex returns a JWT + refresh token.\n * 2. The JWT is set on the *shared* Convex client (`client.setAuth`), so every\n * subsequent persistence query/mutation runs authenticated and the\n * server-side `requireRole` guards see the caller.\n * 3. `currentSession` restores the JWT from storage and asks `users:me`.\n * 4. `signOut` calls `auth:signOut` and clears the JWT.\n *\n * v1 scope note: the stored JWT is short-lived and this adapter does not yet\n * run the refresh-token loop (the official `@convex-dev/auth/react` client\n * does); an expired session simply resolves to \"signed out\" and the user signs\n * in again. Live-deployment hardening is EC-156. No live deployment exists in\n * this repo — this file is typecheck-verified and exercised against the local\n * adapter's shared interface.\n */\n\nconst TOKEN_STORAGE_PREFIX = 'elytra.convex-auth.jwt'\n\n/**\n * Classify a thrown sign-in error as a DEPLOYMENT-setup failure rather than a\n * credential problem (EC-257). Matches the Convex Auth signing-path throws:\n * `requireEnv('JWT_PRIVATE_KEY'|'JWKS'|'CONVEX_SITE_URL')` (→ \"Missing environment\n * variable …\") and `importPKCS8` on a malformed key. Deliberately narrow — a genuine\n * wrong-password error carries none of these tokens — and checked BEFORE the credential\n * regex so it always wins. Note: a PRODUCTION deployment redacts non-`ConvexError`\n * messages to a generic \"Server Error\", which this can't match; there the honest\n * fallback is the neutral \"unavailable\" branch (never \"password too short\").\n */\nexport function isDeploymentMisconfigured(message: string): boolean {\n return /JWT_PRIVATE_KEY|JWKS|CONVEX_SITE_URL|Missing environment variable|PKCS8|private key/i.test(\n message,\n )\n}\n\n/**\n * Reduce a thrown Convex error to the text used for classification (EC-362).\n *\n * **Read `.data` FIRST, then `.message`** — because a PRODUCTION Convex\n * deployment REDACTS a UDF's thrown-error `.message` to a generic\n * `\"[Request ID: …] Server Error\"`, but a `ConvexError`'s `.data` payload\n * survives to the client. Proven in the installed `convex@1.42.1` browser\n * client: on an `\"error\"` response `ConvexHttpClient.action` throws\n * `forwardErrorData(respJSON.errorData, new ConvexError(respJSON.errorMessage))`,\n * and `forwardErrorData` sets `error.data = jsonToConvex(errorData)`\n * (`dist/esm/browser/http_client.js`, ~L388-396 + L459-461). The server keeps\n * `errorData` for a `ConvexError` in prod while redacting `errorMessage`. So the\n * only classifiable text that survives prod is the `.data` of a `ConvexError` —\n * e.g. our invite gate's `ConvexError(NOT_INVITED_REASON)`. On DEV deployments\n * nothing is redacted, so `.message` also carries the token (the regex ladder\n * still matches); non-Convex errors only have a `.message`.\n *\n * Duck-types the `data` property rather than `instanceof ConvexError`: two\n * copies of the `convex` module can coexist under Vite (transformed vs\n * pre-bundled), so `instanceof` can spuriously fail (EC-357). `.data` may be a\n * string (our gates) or a structured object (future gates) — both are folded in.\n */\nexport function convexErrorClassifierText(error: unknown): string {\n const parts: string[] = []\n if (typeof error === 'object' && error !== null && 'data' in error) {\n const data = (error as { data: unknown }).data\n if (typeof data === 'string') {\n parts.push(data)\n } else if (data !== null && data !== undefined) {\n try {\n parts.push(JSON.stringify(data))\n } catch {\n // Non-serializable data (cycles) — ignore; fall back to the message.\n }\n }\n }\n if (error instanceof Error) parts.push(error.message)\n else if (typeof error === 'string') parts.push(error)\n if (parts.length === 0) parts.push(String(error))\n return parts.join('\\n')\n}\n\ntype SignInFailure = Extract<SignInResult, { ok: false }>\n\n/**\n * Pure sign-in/sign-up error classifier (EC-257 / EC-324 / EC-362). Runs the\n * regex ladder over {@link convexErrorClassifierText} output (data-first).\n *\n * Order matters: a DEPLOYMENT-misconfiguration (EC-257) and an uninvited\n * sign-up (EC-324) are each checked BEFORE the credential regex so neither\n * degrades to the lying \"password too short\". The final fallback is HONEST\n * (\"unexpected server error — check the deployment logs\"), never \"unavailable\":\n * on a prod deployment the credential/`InvalidAccountId`/env errors thrown by\n * `@convex-dev/auth` are PLAIN `Error`s (not `ConvexError`s), so prod redacts\n * them to `\"Server Error\"` with no `.data` and they legitimately land here.\n */\nexport function classifySignInError(flow: 'signIn' | 'signUp', text: string): SignInFailure {\n // EC-257: a DEPLOYMENT-misconfiguration — its auth signing key is unset — must be\n // classified FIRST so it never falls through to the lying \"password too short\".\n // Convex Auth signs the session JWT with the deployment's `JWT_PRIVATE_KEY`\n // (+ `JWKS`/`CONVEX_SITE_URL`); when any is unset (`npx @convex-dev/auth` never\n // run) the `requireEnv`/`importPKCS8` call throws AFTER the password is validated,\n // so EVERY sign-in fails regardless of the password.\n if (isDeploymentMisconfigured(text)) {\n return {\n ok: false,\n reason: 'deployment-misconfigured',\n message:\n 'This deployment can’t sign you in: its auth signing key is not set. Run `npx @convex-dev/auth` against this deployment, then retry. (The deployment-setup check reports the same.)',\n }\n }\n // EC-324: an uninvited sign-up is rejected server-side (`gateAccountCreation`/\n // `gateSessionCreation` throw `ConvexError(NOT_INVITED_REASON)`, whose `.data`\n // survives to the client even in production). Checked BEFORE the credential regex.\n if (/not-invited|invite-only|invite only/i.test(text)) {\n return {\n ok: false,\n reason: 'not-invited',\n message:\n 'This deployment is invite-only. Ask an admin to invite your email, then create your account.',\n }\n }\n if (flow === 'signUp' && /already|exists|InvalidAccountId/i.test(text)) {\n return {\n ok: false,\n reason: 'account-exists',\n message: 'An account with this email already exists — sign in instead.',\n }\n }\n if (/InvalidSecret|InvalidAccountId|credential|password/i.test(text)) {\n return {\n ok: false,\n reason: 'invalid-credentials',\n message:\n flow === 'signUp'\n ? 'That email or password can’t be used (password too short?).'\n : 'Email or password is incorrect.',\n }\n }\n const verb = flow === 'signUp' ? 'Sign-up' : 'Sign-in'\n return {\n ok: false,\n reason: 'unavailable',\n message: `${verb} failed (unexpected server error) — check the deployment logs.`,\n }\n}\n\ntype ChangePasswordFailure = Extract<ChangePasswordResult, { ok: false }>\n\n/**\n * Pure password-change error classifier (EC-240 H-tail / EC-362). Same\n * data-first text + honest fallback discipline as {@link classifySignInError};\n * `deployment-misconfigured` collapses onto the `unavailable` reason\n * (`ChangePasswordResult` has no dedicated reason for it) with a specific\n * remediation message.\n */\nexport function classifyChangePasswordError(text: string): ChangePasswordFailure {\n if (isDeploymentMisconfigured(text)) {\n return {\n ok: false,\n reason: 'unavailable',\n message:\n 'This deployment can’t change your password: its auth signing key is not set. Run `npx @convex-dev/auth`.',\n }\n }\n if (/InvalidSecret|InvalidAccountId|current password|incorrect/i.test(text)) {\n return {\n ok: false,\n reason: 'invalid-credentials',\n message: 'Your current password is incorrect.',\n }\n }\n if (/at least|too short|8 characters|password requirement|weak/i.test(text)) {\n return {\n ok: false,\n reason: 'weak-password',\n message: 'Choose a stronger password (at least 8 characters).',\n }\n }\n return {\n ok: false,\n reason: 'unavailable',\n message: 'Password change failed (unexpected server error) — check the deployment logs.',\n }\n}\n\n/**\n * Per-deployment token key (EC-179, vision AD-8). One project per backend, so a\n * session is scoped to its deployment: signing into Aurora's backend must not\n * carry a JWT to Northwind's. Keying the stored token by the deployment URL\n * makes each backend's session independent — switching to a project on a\n * not-yet-authenticated backend reads no token and the guard asks for sign-in.\n * (A future shared external IdP — WorkOS/Clerk — would issue one identity valid\n * on every deployment, collapsing this back to a single session.)\n */\nexport function tokenStorageKey(deploymentUrl?: string): string {\n return deploymentUrl ? `${TOKEN_STORAGE_PREFIX}::${deploymentUrl}` : TOKEN_STORAGE_PREFIX\n}\n\n/**\n * Best-effort \"is there a session for this deployment?\" — a synchronous token\n * presence check used to label per-backend projects in the switcher/launcher\n * (EC-179). It does not validate the token (an expired one still redirects to\n * sign-in on entry); it just answers \"has the user signed into this backend?\".\n */\nexport function hasStoredConvexSession(\n deploymentUrl: string,\n store: SessionStore = defaultStore(),\n): boolean {\n return store.getItem(tokenStorageKey(deploymentUrl)) !== null\n}\n\ninterface SignInActionResult {\n tokens?: { token: string; refreshToken: string } | null\n}\n\ninterface MeResult {\n id: string\n email: string\n name?: string\n}\n\nfunction defaultStore(): SessionStore {\n if (typeof window !== 'undefined' && window.sessionStorage) return window.sessionStorage\n const memory = new Map<string, string>()\n return {\n getItem: (key) => memory.get(key) ?? null,\n setItem: (key, value) => void memory.set(key, value),\n removeItem: (key) => void memory.delete(key),\n }\n}\n\nexport class ConvexAuthAdapter implements AuthAdapter {\n private readonly tokenKey: string\n\n constructor(\n private readonly client: ConvexHttpClient,\n private readonly store: SessionStore = defaultStore(),\n /** Deployment URL the token is scoped to (per-backend sessions, EC-179). */\n deploymentUrl?: string,\n ) {\n this.tokenKey = tokenStorageKey(deploymentUrl)\n }\n\n async currentSession(): Promise<AuthSession | null> {\n const token = this.store.getItem(this.tokenKey)\n if (!token) return null\n this.client.setAuth(token)\n try {\n const me = (await this.client.query(queryRef('users:me'), {})) as MeResult | null\n if (!me) {\n this.clearToken()\n return null\n }\n return { user: this.toUser(me) }\n } catch {\n // Expired/invalid JWT or unreachable backend → treat as signed out.\n this.clearToken()\n return null\n }\n }\n\n async signIn(credentials: SignInCredentials): Promise<SignInResult> {\n return this.authenticate('signIn', credentials)\n }\n\n async signUp(credentials: SignInCredentials): Promise<SignInResult> {\n return this.authenticate('signUp', credentials)\n }\n\n /**\n * Shared password flow (EC-150/EC-179). `signIn` and `signUp` differ only by\n * the Convex Auth `flow` param; both return a token + load `users:me`.\n */\n private async authenticate(\n flow: 'signIn' | 'signUp',\n credentials: SignInCredentials,\n ): Promise<SignInResult> {\n let result: SignInActionResult\n try {\n result = (await this.client.action(actionRef('auth:signIn'), {\n provider: 'password',\n params: {\n email: credentials.email.trim().toLowerCase(),\n password: credentials.password,\n flow,\n },\n })) as SignInActionResult\n } catch (error) {\n // Convex Auth surfaces credential/registration problems as thrown errors.\n // Classify from the DATA-FIRST text (a `ConvexError`'s `.data` survives prod\n // redaction, the redacted `.message` does not — EC-362), then apply the pure\n // regex ladder. See `convexErrorClassifierText` / `classifySignInError`.\n return classifySignInError(flow, convexErrorClassifierText(error))\n }\n if (!result.tokens) {\n return {\n ok: false,\n reason: 'invalid-credentials',\n message: 'Email or password is incorrect.',\n }\n }\n this.store.setItem(this.tokenKey, result.tokens.token)\n this.client.setAuth(result.tokens.token)\n const me = (await this.client.query(queryRef('users:me'), {})) as MeResult | null\n if (!me) {\n this.clearToken()\n return { ok: false, reason: 'unavailable', message: 'Sign-in is currently unavailable.' }\n }\n return { ok: true, session: { user: this.toUser(me) } }\n }\n\n async signOut(): Promise<void> {\n try {\n await this.client.action(actionRef('auth:signOut'), {})\n } catch {\n // Already signed out / unreachable — clearing local state is what matters.\n }\n this.clearToken()\n }\n\n /**\n * Self-service identity edit (EC-240 H-tail item 2). Patches the caller's OWN\n * auth `users` row (name / avatar) via the self-scoped `users:updateProfile`\n * mutation, then re-reads `users:me` so the returned session carries the new\n * name. Auth-owned fields never flow through the members-rail `users.save`.\n */\n async updateProfile(input: UpdateProfileInput): Promise<UpdateProfileResult> {\n const token = this.store.getItem(this.tokenKey)\n if (!token) {\n return { ok: false, reason: 'not-authenticated', message: 'You are not signed in.' }\n }\n this.client.setAuth(token)\n try {\n await this.client.mutation(mutationRef('users:updateProfile'), {\n ...(input.name !== undefined ? { name: input.name } : {}),\n ...(input.avatar !== undefined ? { avatar: input.avatar } : {}),\n })\n const me = (await this.client.query(queryRef('users:me'), {})) as MeResult | null\n if (!me) {\n return { ok: false, reason: 'unavailable', message: 'Profile update is currently unavailable.' }\n }\n return { ok: true, session: { user: this.toUser(me) } }\n } catch {\n return { ok: false, reason: 'unavailable', message: 'Profile update is currently unavailable.' }\n }\n }\n\n /**\n * Self-service password change (EC-240 H-tail item 3). Delegates entirely to\n * the provider via the self-scoped `users:changePassword` ACTION (which calls\n * Convex Auth's `retrieveAccount` to verify the current password, then\n * `modifyAccountCredentials` to set the new one). **Seam only:** the raw\n * password values are forwarded to the provider and NEVER logged or inspected\n * here.\n */\n async changePassword(input: ChangePasswordInput): Promise<ChangePasswordResult> {\n const token = this.store.getItem(this.tokenKey)\n if (!token) {\n return { ok: false, reason: 'not-authenticated', message: 'You are not signed in.' }\n }\n this.client.setAuth(token)\n try {\n await this.client.action(actionRef('users:changePassword'), {\n currentPassword: input.currentPassword,\n newPassword: input.newPassword,\n })\n return { ok: true }\n } catch (error) {\n // Data-first classification (EC-362): the change-password ACTION runs on the\n // same deployment, so a prod redaction erases the thrown `.message` the same\n // way — read a surviving `ConvexError.data` first.\n return classifyChangePasswordError(convexErrorClassifierText(error))\n }\n }\n\n private toUser(me: MeResult): AuthSession['user'] {\n return {\n id: me.id,\n email: me.email,\n ...(me.name ? { name: me.name } : {}),\n // No global flags: project creation is config/CLI-owned (AD-11), so there\n // is no in-studio `create-projects` capability. Per-project roles come\n // from `projectMembers`.\n globalFlags: [],\n }\n }\n\n private clearToken(): void {\n this.store.removeItem(this.tokenKey)\n this.client.clearAuth()\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthAdapter, AuthSession, ChangePasswordInput, ChangePasswordResult, SignInCredentials, SignInResult, UpdateProfileInput, UpdateProfileResult } from './auth-adapter';
|
|
1
|
+
import type { AuthAdapter, AuthSession, ChangePasswordInput, ChangePasswordResult, SignInCredentials, SignInResult, UpdateProfileInput, UpdateProfileResult } from './auth-adapter.js';
|
|
2
2
|
/**
|
|
3
3
|
* Dev-only unattended-auth decorator (testing de-friction). Wraps any
|
|
4
4
|
* {@link AuthAdapter}: when no session can be restored, it transparently signs
|
package/dist/lib/auth/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { StudioBackendMode } from '../persistence/backend-mode';
|
|
2
|
-
import type { AuthAdapter } from './auth-adapter';
|
|
3
|
-
export type { AuthAdapter, AuthSession, AuthUser, ChangePasswordInput, ChangePasswordResult, SignInCredentials, SignInResult, UpdateProfileInput, UpdateProfileResult, } from './auth-adapter';
|
|
4
|
-
export { LocalAuthAdapter, LOCAL_DEV_CREDENTIALS } from './local-auth-adapter';
|
|
5
|
-
export type { SessionStore } from './local-auth-adapter';
|
|
6
|
-
export { ConvexAuthAdapter } from './convex-auth-adapter';
|
|
7
|
-
export { DevAutoLoginAdapter } from './dev-auto-login-adapter';
|
|
8
|
-
export { SIGN_IN_PATH, isPublicPath, postSignInTarget, resolveRouteGuard, sessionPrincipal, } from './route-guard';
|
|
9
|
-
export type { AuthStatus, RouteGuardDecision } from './route-guard';
|
|
1
|
+
import type { StudioBackendMode } from '../persistence/backend-mode.js';
|
|
2
|
+
import type { AuthAdapter } from './auth-adapter.js';
|
|
3
|
+
export type { AuthAdapter, AuthSession, AuthUser, ChangePasswordInput, ChangePasswordResult, SignInCredentials, SignInResult, UpdateProfileInput, UpdateProfileResult, } from './auth-adapter.js';
|
|
4
|
+
export { LocalAuthAdapter, LOCAL_DEV_CREDENTIALS } from './local-auth-adapter.js';
|
|
5
|
+
export type { SessionStore } from './local-auth-adapter.js';
|
|
6
|
+
export { ConvexAuthAdapter } from './convex-auth-adapter.js';
|
|
7
|
+
export { DevAutoLoginAdapter } from './dev-auto-login-adapter.js';
|
|
8
|
+
export { SIGN_IN_PATH, isPublicPath, postSignInTarget, resolveRouteGuard, sessionPrincipal, } from './route-guard.js';
|
|
9
|
+
export type { AuthStatus, RouteGuardDecision } from './route-guard.js';
|
|
10
10
|
/**
|
|
11
11
|
* Select the auth backend (EC-150/EC-153), mirroring `selectPersistenceAdapter`
|
|
12
12
|
* exactly: Convex mode means Convex Auth (over the same shared client the
|
package/dist/lib/auth/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { getConvexClient } from '../persistence/convex-client';
|
|
2
|
-
import { resolveBackendConfig, resolveDevAutoLogin } from '../persistence/backend-mode';
|
|
3
|
-
import { deploymentUrlForSlug, resolveDeploymentUrl } from '../workspace';
|
|
4
|
-
import { ConvexAuthAdapter, hasStoredConvexSession } from './convex-auth-adapter';
|
|
5
|
-
import { DevAutoLoginAdapter } from './dev-auto-login-adapter';
|
|
6
|
-
import { LocalAuthAdapter } from './local-auth-adapter';
|
|
7
|
-
export { LocalAuthAdapter, LOCAL_DEV_CREDENTIALS } from './local-auth-adapter';
|
|
8
|
-
export { ConvexAuthAdapter } from './convex-auth-adapter';
|
|
9
|
-
export { DevAutoLoginAdapter } from './dev-auto-login-adapter';
|
|
10
|
-
export { SIGN_IN_PATH, isPublicPath, postSignInTarget, resolveRouteGuard, sessionPrincipal, } from './route-guard';
|
|
1
|
+
import { getConvexClient } from '../persistence/convex-client.js';
|
|
2
|
+
import { resolveBackendConfig, resolveDevAutoLogin } from '../persistence/backend-mode.js';
|
|
3
|
+
import { deploymentUrlForSlug, resolveDeploymentUrl } from '../workspace/index.js';
|
|
4
|
+
import { ConvexAuthAdapter, hasStoredConvexSession } from './convex-auth-adapter.js';
|
|
5
|
+
import { DevAutoLoginAdapter } from './dev-auto-login-adapter.js';
|
|
6
|
+
import { LocalAuthAdapter } from './local-auth-adapter.js';
|
|
7
|
+
export { LocalAuthAdapter, LOCAL_DEV_CREDENTIALS } from './local-auth-adapter.js';
|
|
8
|
+
export { ConvexAuthAdapter } from './convex-auth-adapter.js';
|
|
9
|
+
export { DevAutoLoginAdapter } from './dev-auto-login-adapter.js';
|
|
10
|
+
export { SIGN_IN_PATH, isPublicPath, postSignInTarget, resolveRouteGuard, sessionPrincipal, } from './route-guard.js';
|
|
11
11
|
/**
|
|
12
12
|
* Select the auth backend (EC-150/EC-153), mirroring `selectPersistenceAdapter`
|
|
13
13
|
* exactly: Convex mode means Convex Auth (over the same shared client the
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthAdapter, AuthSession, ChangePasswordResult, SignInCredentials, SignInResult, UpdateProfileResult } from './auth-adapter';
|
|
1
|
+
import type { AuthAdapter, AuthSession, ChangePasswordResult, SignInCredentials, SignInResult, UpdateProfileResult } from './auth-adapter.js';
|
|
2
2
|
/**
|
|
3
3
|
* Deterministic local auth (EC-150) for the in-memory persistence mode: the
|
|
4
4
|
* whole sign-in → role-enforcement → sign-out flow works offline, in tests,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Principal } from '@elytracms/core/operations';
|
|
2
|
-
import type { AuthSession } from './auth-adapter';
|
|
2
|
+
import type { AuthSession } from './auth-adapter.js';
|
|
3
3
|
/**
|
|
4
4
|
* Pure route-guard + principal-mapping logic (EC-150), kept free of React and
|
|
5
5
|
* router types so it is unit-testable and deterministic. The `__root` layout
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Studio clipboard helpers (EC-175): paste-target resolution, permissive-paste
|
|
3
3
|
* diffing, and the OS-clipboard transport over the EC-174 fragment format.
|
|
4
4
|
*/
|
|
5
|
-
export * from './paste-target';
|
|
6
|
-
export * from './paste-issues';
|
|
7
|
-
export * from './os-clipboard';
|
|
5
|
+
export * from './paste-target.js';
|
|
6
|
+
export * from './paste-issues.js';
|
|
7
|
+
export * from './os-clipboard.js';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Studio clipboard helpers (EC-175): paste-target resolution, permissive-paste
|
|
3
3
|
* diffing, and the OS-clipboard transport over the EC-174 fragment format.
|
|
4
4
|
*/
|
|
5
|
-
export * from './paste-target';
|
|
6
|
-
export * from './paste-issues';
|
|
7
|
-
export * from './os-clipboard';
|
|
5
|
+
export * from './paste-target.js';
|
|
6
|
+
export * from './paste-issues.js';
|
|
7
|
+
export * from './os-clipboard.js';
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CmsDocument } from '@elytracms/core/cms-core';
|
|
2
|
-
import type { OperationsClient } from '../operations';
|
|
2
|
+
import type { OperationsClient } from '../operations/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* The PUBLISHED-perspective documents of a collection (EC-205, "live = published")
|
|
5
5
|
* — the pinned published snapshot of each currently-published document, keyed by
|
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* (EC-246b) — the DB saved-view store is retired; `view-model.configViewsFor`
|
|
5
5
|
* resolves the named views a collection declares in `cms/`.
|
|
6
6
|
*/
|
|
7
|
-
export * from './view-model';
|
|
8
|
-
export * from './selection';
|
|
7
|
+
export * from './view-model.js';
|
|
8
|
+
export * from './selection.js';
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
* (EC-246b) — the DB saved-view store is retired; `view-model.configViewsFor`
|
|
5
5
|
* resolves the named views a collection declares in `cms/`.
|
|
6
6
|
*/
|
|
7
|
-
export * from './view-model';
|
|
8
|
-
export * from './selection';
|
|
7
|
+
export * from './view-model.js';
|
|
8
|
+
export * from './selection.js';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { CmsDocument, CollectionDef, DocumentRef, DocumentUrl, FieldDef, Locale, LocaleConfig, LocalizedString, RestoreScope } from '@elytracms/core/cms-core';
|
|
2
2
|
import type { CmsValidationIssue } from '@elytracms/core/cms-core';
|
|
3
3
|
import type { OperationError } from '@elytracms/core/operations';
|
|
4
|
-
import type { TableViewState } from '../cms-views/view-model';
|
|
5
|
-
import type { CellCommitInput, CellCommitOutcome } from '../../components/cms/cell-edit';
|
|
6
|
-
import type { BulkAction, BulkReport, BulkSetField } from '../../components/cms/bulk-actions';
|
|
7
|
-
import type { DocumentVersionsView, ImportReport } from '../../components/cms/cms-store';
|
|
4
|
+
import type { TableViewState } from '../cms-views/view-model.js';
|
|
5
|
+
import type { CellCommitInput, CellCommitOutcome } from '../../components/cms/cell-edit.js';
|
|
6
|
+
import type { BulkAction, BulkReport, BulkSetField } from '../../components/cms/bulk-actions.js';
|
|
7
|
+
import type { DocumentVersionsView, ImportReport } from '../../components/cms/cms-store.js';
|
|
8
8
|
/**
|
|
9
9
|
* `CollectionViewSource` — the studio's UNIVERSAL interaction seam (EC-240,
|
|
10
10
|
* vision AD-19).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContentClient, createContentContext, } from '@elytracms/core/content';
|
|
2
2
|
import { documentKey, resolveDocumentTitle, sampleLocaleConfig } from '@elytracms/core/cms-core';
|
|
3
|
-
import { getStudioLocale } from '../locale/locale-store';
|
|
3
|
+
import { getStudioLocale } from '../locale/locale-store.js';
|
|
4
4
|
/**
|
|
5
5
|
* Default (no-session) collection schema: EMPTY. The studio ships no demo content
|
|
6
6
|
* (Oli, 2026-06-19) — with no backend/content session configured, there is nothing
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useReducer, useState } from 'react';
|
|
3
3
|
import { SourceRegistry, captureSample, inferSchema, resolveBinding, resolveCondition, tokensForSchema, } from '@elytracms/core/data-binding';
|
|
4
|
-
import { getStudioOperations } from '../operations';
|
|
4
|
+
import { getStudioOperations } from '../operations/index.js';
|
|
5
5
|
import { useOperationCache, useOperationQuery } from '@elytracms/studio/lib/query';
|
|
6
6
|
import { createRequiredContext } from '@elytracms/studio/lib/required-context';
|
|
7
|
-
import { STUDIO_SYSTEM_COLLECTION_IDS } from '../operations/session-hydration';
|
|
8
|
-
import { resolveDeploymentCollections } from '../workspace';
|
|
9
|
-
import { hasContentSession } from './collection-content';
|
|
10
|
-
import { captureSourceSample, cmsSourceForCollection } from './sample-capture';
|
|
11
|
-
import { deleteDataSource, loadDataSources, saveDataSource } from './sources-store';
|
|
7
|
+
import { STUDIO_SYSTEM_COLLECTION_IDS } from '../operations/session-hydration.js';
|
|
8
|
+
import { resolveDeploymentCollections } from '../workspace/index.js';
|
|
9
|
+
import { hasContentSession } from './collection-content.js';
|
|
10
|
+
import { captureSourceSample, cmsSourceForCollection } from './sample-capture.js';
|
|
11
|
+
import { deleteDataSource, loadDataSources, saveDataSource } from './sources-store.js';
|
|
12
12
|
function upsert(sources, source) {
|
|
13
13
|
const exists = sources.some((s) => s.id === source.id);
|
|
14
14
|
return exists ? sources.map((s) => (s.id === source.id ? source : s)) : [...sources, source];
|
package/dist/lib/data/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './data-store';
|
|
2
|
-
export * from './sample-capture';
|
|
3
|
-
export * from './sources-store';
|
|
4
|
-
export * from './collection-content';
|
|
1
|
+
export * from './data-store.js';
|
|
2
|
+
export * from './sample-capture.js';
|
|
3
|
+
export * from './sources-store.js';
|
|
4
|
+
export * from './collection-content.js';
|
package/dist/lib/data/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './data-store';
|
|
2
|
-
export * from './sample-capture';
|
|
3
|
-
export * from './sources-store';
|
|
4
|
-
export * from './collection-content';
|
|
1
|
+
export * from './data-store.js';
|
|
2
|
+
export * from './sample-capture.js';
|
|
3
|
+
export * from './sources-store.js';
|
|
4
|
+
export * from './collection-content.js';
|
|
5
5
|
// Data providers (EC-167) are imported from './providers' directly: the module
|
|
6
6
|
// exports a `DataProvider` domain type that would collide with the store's
|
|
7
7
|
// `<DataProvider>` React provider in a wildcard barrel.
|