@qlever-llc/trellis-svelte 0.10.12 → 0.10.14
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/dist/components/TrellisContextProvider.svelte.d.ts +11 -0
- package/dist/components/TrellisProvider.svelte +1 -1
- package/dist/components/TrellisProvider.svelte.d.ts +6 -0
- package/dist/components/TrellisProvider.types.d.ts +13 -0
- package/dist/context.d.ts +81 -0
- package/dist/device_activation.d.ts +6 -0
- package/dist/device_activation_controller.d.ts +69 -0
- package/dist/index.d.ts +6 -0
- package/dist/internal/activation_view.d.ts +49 -0
- package/dist/internal/callback_state.d.ts +9 -0
- package/dist/internal/portal_url.d.ts +13 -0
- package/dist/portal_flow.d.ts +17 -0
- package/package.json +7 -5
- package/src/components/TrellisProvider.svelte +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Component, Snippet } from "svelte";
|
|
2
|
+
import type { TrellisAppOwner, TrellisContextClient } from "../context.js";
|
|
3
|
+
|
|
4
|
+
type TrellisContextProviderProps = {
|
|
5
|
+
trellisApp: TrellisAppOwner;
|
|
6
|
+
trellis: TrellisContextClient;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
declare const TrellisContextProvider: Component<TrellisContextProviderProps>;
|
|
11
|
+
export default TrellisContextProvider;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
TrellisClient,
|
|
5
5
|
type ClientAuthOptions,
|
|
6
6
|
type ConnectedTrellisClient,
|
|
7
|
-
} from "@qlever-llc/trellis";
|
|
7
|
+
} from "@qlever-llc/trellis/browser";
|
|
8
8
|
import { onMount } from "svelte";
|
|
9
9
|
import type { TrellisContractLike } from "../context.js";
|
|
10
10
|
import { resolveTrellisAppUrl } from "../context.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Component } from "svelte";
|
|
2
|
+
import type { TrellisProviderProps } from "./TrellisProvider.types.js";
|
|
3
|
+
|
|
4
|
+
/** Svelte component that connects a Trellis app and provides context to children. */
|
|
5
|
+
declare const TrellisProvider: Component<TrellisProviderProps>;
|
|
6
|
+
export default TrellisProvider;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ClientAuthOptions, ClientAuthRequiredContext, ClientOpts } from "@qlever-llc/trellis";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { TrellisAppOwner, TrellisContractLike } from "../context.js";
|
|
4
|
+
/** Props accepted by the Svelte Trellis provider component. */
|
|
5
|
+
export type TrellisProviderProps<TContract extends TrellisContractLike = TrellisContractLike> = {
|
|
6
|
+
trellisApp: TrellisAppOwner<TContract>;
|
|
7
|
+
auth?: ClientAuthOptions;
|
|
8
|
+
client?: ClientOpts;
|
|
9
|
+
children: Snippet;
|
|
10
|
+
loading?: Snippet;
|
|
11
|
+
error?: Snippet<[unknown]>;
|
|
12
|
+
onAuthRequired?: (loginUrl: string, context: ClientAuthRequiredContext) => void | Promise<void>;
|
|
13
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ClientTrellis, RuntimeStateStoresForContract, TrellisAPI, TrellisConnection, TrellisConnectionStatus, TrellisContractV1 } from "@qlever-llc/trellis";
|
|
2
|
+
/** Minimal contract shape required to create a typed Trellis Svelte app context. */
|
|
3
|
+
export type TrellisContractLike<TA extends TrellisAPI = TrellisAPI> = {
|
|
4
|
+
CONTRACT: TrellisContractV1;
|
|
5
|
+
CONTRACT_DIGEST: string;
|
|
6
|
+
API: {
|
|
7
|
+
trellis?: TA;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
type TrellisApiFor<TContract extends TrellisContractLike> = NonNullable<TContract["API"]["trellis"]> extends TrellisAPI ? NonNullable<TContract["API"]["trellis"]> : TrellisAPI;
|
|
11
|
+
/** Real connected Trellis client type exposed by a Svelte app context. */
|
|
12
|
+
export type TrellisClientFor<TContract extends TrellisContractLike> = ClientTrellis<TrellisApiFor<TContract>, RuntimeStateStoresForContract<TContract>>;
|
|
13
|
+
/** Minimal client surface required for Trellis Svelte context clients. */
|
|
14
|
+
export type TrellisContextClient = {
|
|
15
|
+
readonly connection: TrellisConnection;
|
|
16
|
+
};
|
|
17
|
+
/** URL value accepted by a Trellis Svelte app owner. */
|
|
18
|
+
export type TrellisAppUrl = string | URL;
|
|
19
|
+
/**
|
|
20
|
+
* Trellis URL configuration for a Svelte app owner.
|
|
21
|
+
*
|
|
22
|
+
* A function resolver supports apps whose Trellis instance is selected at
|
|
23
|
+
* runtime. Returning `undefined` means no instance is currently available.
|
|
24
|
+
*/
|
|
25
|
+
export type TrellisAppUrlResolver = TrellisAppUrl | (() => TrellisAppUrl | undefined);
|
|
26
|
+
/** Options used to create a Trellis Svelte app owner. */
|
|
27
|
+
export type CreateTrellisAppOptions<TContract extends TrellisContractLike = TrellisContractLike> = {
|
|
28
|
+
/** Contract used by this app context and by `TrellisProvider` connections. */
|
|
29
|
+
contract: TContract;
|
|
30
|
+
/** Trellis URL, or a resolver for runtime-selected Trellis URLs. */
|
|
31
|
+
trellisUrl: TrellisAppUrlResolver;
|
|
32
|
+
};
|
|
33
|
+
/** Resolves a Trellis app URL config to the string shape required by the client. */
|
|
34
|
+
export declare function resolveTrellisAppUrl(trellisUrl: TrellisAppUrlResolver): string | undefined;
|
|
35
|
+
/** Svelte-reactive adapter around a framework-neutral Trellis connection. */
|
|
36
|
+
export declare class SvelteTrellisConnection {
|
|
37
|
+
#private;
|
|
38
|
+
/** Creates a reactive connection adapter for a connected Trellis runtime. */
|
|
39
|
+
constructor(connection: TrellisConnection);
|
|
40
|
+
/** Latest connection status, reactive when read by Svelte effects or markup. */
|
|
41
|
+
get status(): TrellisConnectionStatus;
|
|
42
|
+
/** Closes the underlying Trellis runtime connection. */
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
declare const trellisAppOwnerBrand: unique symbol;
|
|
46
|
+
/** Minimal branded app owner surface accepted by the Trellis Svelte provider. */
|
|
47
|
+
export type TrellisAppOwner<TContract extends TrellisContractLike = TrellisContractLike> = {
|
|
48
|
+
readonly contract: TContract;
|
|
49
|
+
readonly trellisUrl: TrellisAppUrlResolver;
|
|
50
|
+
readonly [trellisAppOwnerBrand]: true;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Public app-scoped typed Svelte context owner for a Trellis browser app.
|
|
54
|
+
*
|
|
55
|
+
* `TClient` is a type-only facade over the runtime client that `TrellisProvider`
|
|
56
|
+
* installs. Use it with generated client facade types for the same contract.
|
|
57
|
+
*/
|
|
58
|
+
export interface TrellisApp<TContract extends TrellisContractLike = TrellisContractLike, TClient extends TrellisContextClient = TrellisClientFor<TContract>> extends TrellisAppOwner<TContract> {
|
|
59
|
+
/** Contract used by this app context and by `TrellisProvider` connections. */
|
|
60
|
+
readonly contract: TContract;
|
|
61
|
+
/** Trellis URL configuration used by `TrellisProvider` connections. */
|
|
62
|
+
readonly trellisUrl: TrellisAppUrlResolver;
|
|
63
|
+
/** Returns the contract-typed connected Trellis client from Svelte context synchronously. */
|
|
64
|
+
getTrellis(): TClient;
|
|
65
|
+
/** Returns a Svelte-reactive adapter for the real Trellis connection. */
|
|
66
|
+
getConnection(): SvelteTrellisConnection;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates an app-scoped typed Svelte context owner for a Trellis contract and URL.
|
|
70
|
+
*
|
|
71
|
+
* The optional `TClient` type parameter is a type-only facade over the connected
|
|
72
|
+
* runtime client. It should be a generated client facade for `options.contract`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function createTrellisApp<TContract extends TrellisContractLike, TClient extends TrellisContextClient = TrellisClientFor<TContract>>(options: CreateTrellisAppOptions<TContract>): TrellisApp<TContract, TClient>;
|
|
75
|
+
/**
|
|
76
|
+
* Internal provider helper that synchronously installs connected Trellis context.
|
|
77
|
+
*
|
|
78
|
+
* This is intentionally not exported from `src/index.ts`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function provideConnectedTrellisContext(app: TrellisAppOwner, trellis: TrellisContextClient): void;
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type DeviceActivationControllerConfig, DeviceActivationControllerCore } from "./device_activation_controller.js";
|
|
2
|
+
export type { DeviceActivationAuth, DeviceActivationClient, DeviceActivationControllerConfig, DeviceActivationOperationRef, } from "./device_activation_controller.js";
|
|
3
|
+
export declare class DeviceActivationController extends DeviceActivationControllerCore {
|
|
4
|
+
constructor(config: DeviceActivationControllerConfig);
|
|
5
|
+
}
|
|
6
|
+
export declare function createDeviceActivationController(config: DeviceActivationControllerConfig): DeviceActivationController;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { BaseError } from "@qlever-llc/result";
|
|
2
|
+
import type { AsyncResult } from "@qlever-llc/result";
|
|
3
|
+
import type { AuthResolveDeviceUserAuthoritiesOutput, AuthResolveDeviceUserAuthoritiesProgress } from "@qlever-llc/trellis/auth";
|
|
4
|
+
import type { OperationEvent, TerminalOperation } from "@qlever-llc/trellis";
|
|
5
|
+
import { type StorageLike } from "./internal/callback_state.js";
|
|
6
|
+
import { type DeviceActivationConnectAuthUrlState } from "./internal/portal_url.js";
|
|
7
|
+
import { type DeviceActivationView } from "./internal/activation_view.js";
|
|
8
|
+
export type DeviceActivationSignInOptions = {
|
|
9
|
+
redirectTo?: string;
|
|
10
|
+
landingPath?: string;
|
|
11
|
+
context?: unknown;
|
|
12
|
+
};
|
|
13
|
+
export type DeviceActivationBindResult = {
|
|
14
|
+
status: "bound";
|
|
15
|
+
} | {
|
|
16
|
+
status: "approval_denied";
|
|
17
|
+
} | {
|
|
18
|
+
status: "approval_required";
|
|
19
|
+
} | {
|
|
20
|
+
status: "insufficient_capabilities";
|
|
21
|
+
missingCapabilities: string[];
|
|
22
|
+
} | {
|
|
23
|
+
status: "error";
|
|
24
|
+
message: string;
|
|
25
|
+
};
|
|
26
|
+
export type DeviceActivationAuth = {
|
|
27
|
+
init(): Promise<unknown>;
|
|
28
|
+
handleCallback(callbackUrl: string): Promise<DeviceActivationBindResult | null>;
|
|
29
|
+
signIn(options?: DeviceActivationSignInOptions): Promise<never>;
|
|
30
|
+
};
|
|
31
|
+
export type DeviceActivationControllerConfig = {
|
|
32
|
+
authState: DeviceActivationAuth;
|
|
33
|
+
createClient(authUrlState: DeviceActivationConnectAuthUrlState): Promise<DeviceActivationClient>;
|
|
34
|
+
getUrl?: () => URL;
|
|
35
|
+
replaceUrl?: (url: string) => void;
|
|
36
|
+
sessionStorage?: StorageLike;
|
|
37
|
+
createCallbackToken?: () => string;
|
|
38
|
+
};
|
|
39
|
+
export type DeviceActivationOperationRef = {
|
|
40
|
+
watch(): AsyncResult<AsyncIterable<OperationEvent<AuthResolveDeviceUserAuthoritiesProgress, AuthResolveDeviceUserAuthoritiesOutput>>, BaseError>;
|
|
41
|
+
wait(): AsyncResult<TerminalOperation<AuthResolveDeviceUserAuthoritiesProgress, AuthResolveDeviceUserAuthoritiesOutput>, BaseError>;
|
|
42
|
+
};
|
|
43
|
+
export type DeviceActivationClient = {
|
|
44
|
+
activateDevice(input: {
|
|
45
|
+
flowId: string;
|
|
46
|
+
}): Promise<DeviceActivationOperationRef>;
|
|
47
|
+
};
|
|
48
|
+
export type DeviceActivationState = {
|
|
49
|
+
loading: boolean;
|
|
50
|
+
requestPending: boolean;
|
|
51
|
+
authError: string | null;
|
|
52
|
+
view: DeviceActivationView | null;
|
|
53
|
+
flowId: string | null;
|
|
54
|
+
};
|
|
55
|
+
export declare function createInitialDeviceActivationState(): DeviceActivationState;
|
|
56
|
+
export declare class DeviceActivationControllerCore {
|
|
57
|
+
#private;
|
|
58
|
+
protected readonly state: DeviceActivationState;
|
|
59
|
+
constructor(config: DeviceActivationControllerConfig, state?: DeviceActivationState);
|
|
60
|
+
get loading(): boolean;
|
|
61
|
+
get requestPending(): boolean;
|
|
62
|
+
get authError(): string | null;
|
|
63
|
+
get view(): DeviceActivationView | null;
|
|
64
|
+
get flowId(): string | null;
|
|
65
|
+
load(): Promise<void>;
|
|
66
|
+
stop(): void;
|
|
67
|
+
signIn(): Promise<void>;
|
|
68
|
+
requestActivation(): Promise<void>;
|
|
69
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as TrellisProvider } from "./components/TrellisProvider.svelte";
|
|
2
|
+
export type { TrellisProviderProps } from "./components/TrellisProvider.types.js";
|
|
3
|
+
export type { CreateTrellisAppOptions, SvelteTrellisConnection, TrellisApp, TrellisAppOwner, TrellisAppUrl, TrellisAppUrlResolver, TrellisClientFor, TrellisContextClient, TrellisContractLike, } from "./context.js";
|
|
4
|
+
export { createTrellisApp, resolveTrellisAppUrl } from "./context.js";
|
|
5
|
+
export { createDeviceActivationController, type DeviceActivationAuth, type DeviceActivationClient, DeviceActivationController, type DeviceActivationControllerConfig, type DeviceActivationOperationRef, } from "./device_activation.js";
|
|
6
|
+
export { createPortalFlow, type CreatePortalFlowConfig, PortalFlowController, } from "./portal_flow.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AuthResolveDeviceUserAuthoritiesOutput } from "@qlever-llc/trellis/auth";
|
|
2
|
+
import type { TerminalOperation } from "@qlever-llc/trellis";
|
|
3
|
+
type DeviceActivationProgressInput = {
|
|
4
|
+
instanceId: string;
|
|
5
|
+
deploymentId: string;
|
|
6
|
+
reviewId: string;
|
|
7
|
+
requestedAt: string | Date;
|
|
8
|
+
};
|
|
9
|
+
export type DeviceActivationView = {
|
|
10
|
+
mode: "sign_in_required";
|
|
11
|
+
flowId: string;
|
|
12
|
+
} | {
|
|
13
|
+
mode: "ready";
|
|
14
|
+
flowId: string;
|
|
15
|
+
} | {
|
|
16
|
+
mode: "pending_review";
|
|
17
|
+
flowId: string;
|
|
18
|
+
instanceId: string;
|
|
19
|
+
deploymentId: string;
|
|
20
|
+
reviewId: string;
|
|
21
|
+
requestedAt: string;
|
|
22
|
+
} | {
|
|
23
|
+
mode: "activated";
|
|
24
|
+
flowId: string;
|
|
25
|
+
instanceId: string;
|
|
26
|
+
deploymentId: string;
|
|
27
|
+
activatedAt: string;
|
|
28
|
+
confirmationCode?: string;
|
|
29
|
+
} | {
|
|
30
|
+
mode: "rejected";
|
|
31
|
+
flowId: string;
|
|
32
|
+
reason?: string;
|
|
33
|
+
} | {
|
|
34
|
+
mode: "expired";
|
|
35
|
+
flowId: string;
|
|
36
|
+
reason: string;
|
|
37
|
+
} | {
|
|
38
|
+
mode: "invalid_flow";
|
|
39
|
+
reason: string;
|
|
40
|
+
flowId?: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function createDeviceActivationReadyView(flowId: string): DeviceActivationView;
|
|
43
|
+
export declare function createDeviceActivationSignInRequiredView(flowId: string): DeviceActivationView;
|
|
44
|
+
export declare function createInvalidDeviceActivationView(reason: string, flowId?: string): DeviceActivationView;
|
|
45
|
+
export declare function mapDeviceActivationOutput(flowId: string, result: AuthResolveDeviceUserAuthoritiesOutput): DeviceActivationView;
|
|
46
|
+
export declare function mapDeviceActivationProgress(flowId: string, progress: DeviceActivationProgressInput): DeviceActivationView;
|
|
47
|
+
export declare function mapDeviceActivationFailure(flowId: string, error: unknown): DeviceActivationView | null;
|
|
48
|
+
export declare function mapDeviceActivationTerminal(flowId: string, terminal: TerminalOperation<unknown, AuthResolveDeviceUserAuthoritiesOutput>): DeviceActivationView | null;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type DeviceActivationCallbackState = {
|
|
2
|
+
flowId: string;
|
|
3
|
+
callbackToken: string;
|
|
4
|
+
};
|
|
5
|
+
export type StorageLike = Pick<Storage, "getItem" | "setItem" | "removeItem">;
|
|
6
|
+
export declare function getPreservedDeviceActivationCallbackState(storage: StorageLike): DeviceActivationCallbackState | null;
|
|
7
|
+
export declare function preserveDeviceActivationCallbackState(storage: StorageLike, nextState: DeviceActivationCallbackState): void;
|
|
8
|
+
export declare function clearPreservedDeviceActivationCallbackState(storage: StorageLike): void;
|
|
9
|
+
export declare function isDeviceActivationAuthCallback(currentUrl: URL, preservedState: DeviceActivationCallbackState | null): boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DeviceActivationCallbackState } from "./callback_state.js";
|
|
2
|
+
export type DeviceActivationConnectAuthUrlState = {
|
|
3
|
+
currentUrl: URL;
|
|
4
|
+
redirectTo: string;
|
|
5
|
+
};
|
|
6
|
+
export type DeviceActivationUrlState = {
|
|
7
|
+
flowId: string | null;
|
|
8
|
+
isAuthCallback: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function buildDeviceActivationCallbackPath(currentUrl: URL, callbackToken: string): string;
|
|
11
|
+
export declare function buildDeviceActivationConnectAuthUrlState(currentUrl: URL): DeviceActivationConnectAuthUrlState;
|
|
12
|
+
export declare function cleanupDeviceActivationCallbackUrl(currentUrl: URL, flowId: string | null): string | null;
|
|
13
|
+
export declare function resolveDeviceActivationUrlState(currentUrl: URL, preservedState: DeviceActivationCallbackState | null): DeviceActivationUrlState;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type AuthConfig, type BrowserPortalFlowState as PortalFlowState } from "@qlever-llc/trellis/auth/browser";
|
|
2
|
+
export type CreatePortalFlowConfig = AuthConfig & {
|
|
3
|
+
getUrl?: () => URL;
|
|
4
|
+
};
|
|
5
|
+
export declare class PortalFlowController {
|
|
6
|
+
#private;
|
|
7
|
+
flowId: string | null;
|
|
8
|
+
state: PortalFlowState | null;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
error: string | null;
|
|
11
|
+
constructor(config: CreatePortalFlowConfig);
|
|
12
|
+
load(): Promise<PortalFlowState | null>;
|
|
13
|
+
providerUrl(providerId: string): string;
|
|
14
|
+
approve(): Promise<PortalFlowState | null>;
|
|
15
|
+
deny(): Promise<PortalFlowState | null>;
|
|
16
|
+
}
|
|
17
|
+
export declare function createPortalFlow(config: CreatePortalFlowConfig): PortalFlowController;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qlever-llc/trellis-svelte",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Svelte components and state helpers for Trellis browser applications.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -20,18 +20,20 @@
|
|
|
20
20
|
"src",
|
|
21
21
|
"README.md"
|
|
22
22
|
],
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
23
24
|
"exports": {
|
|
24
25
|
".": {
|
|
25
|
-
"types": "./
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
26
27
|
"svelte": "./dist/index.js",
|
|
27
28
|
"default": "./dist/index.js"
|
|
28
29
|
}
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
32
|
"@nats-io/nats-core": "^3.3.1",
|
|
32
|
-
"@qlever-llc/result": "^0.10.
|
|
33
|
-
"@qlever-llc/trellis": "^0.10.
|
|
34
|
-
"typebox": "^1.0.15"
|
|
33
|
+
"@qlever-llc/result": "^0.10.14",
|
|
34
|
+
"@qlever-llc/trellis": "^0.10.14",
|
|
35
|
+
"typebox": "^1.0.15",
|
|
36
|
+
"ulid": "^3.0.2"
|
|
35
37
|
},
|
|
36
38
|
"peerDependencies": {
|
|
37
39
|
"svelte": "^5.0.0"
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
TrellisClient,
|
|
5
5
|
type ClientAuthOptions,
|
|
6
6
|
type ConnectedTrellisClient,
|
|
7
|
-
} from "@qlever-llc/trellis";
|
|
7
|
+
} from "@qlever-llc/trellis/browser";
|
|
8
8
|
import { onMount } from "svelte";
|
|
9
9
|
import type { TrellisContractLike } from "../context.svelte.ts";
|
|
10
10
|
import { resolveTrellisAppUrl } from "../context.svelte.ts";
|