apps 0.0.1-beta.6 → 0.0.1-beta.7

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.
@@ -1,5 +1,5 @@
1
1
  /** Provider declarations use native Effect schemas. The trusted host interprets them. */
2
- import { Data, Schema } from "effect";
2
+ import { Data, type Effect, Schema } from "effect";
3
3
  import { type AccountId } from "./schema.js";
4
4
  declare const SecretsMethod_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & {
5
5
  readonly _tag: "secrets";
@@ -84,10 +84,54 @@ export declare class OAuth2Method<Response extends Schema.Decoder<unknown>> exte
84
84
  export type AuthMethod = SecretsMethod<Schema.Decoder<unknown>> | OAuth2Method<Schema.Decoder<unknown>>;
85
85
  /** Auth method names are chosen by the provider author. */
86
86
  export type AuthMethods = Readonly<Record<string, AuthMethod>>;
87
- /** A provider declaration. The future host derives its identity from normalized content. */
87
+ /**
88
+ * Upstream identity that a passing account check may report for display. Only these fields are
89
+ * retained; the host never stores raw provider responses.
90
+ */
91
+ export declare const AccountInfo: Schema.Struct<{
92
+ readonly externalId: Schema.optionalKey<Schema.String>;
93
+ readonly displayName: Schema.optionalKey<Schema.String>;
94
+ readonly username: Schema.optionalKey<Schema.String>;
95
+ readonly email: Schema.optionalKey<Schema.String>;
96
+ readonly avatarUrl: Schema.optionalKey<Schema.String>;
97
+ readonly profileUrl: Schema.optionalKey<Schema.String>;
98
+ }>;
99
+ export type AccountInfo = typeof AccountInfo.Type;
100
+ /** A passing account check. Failures are thrown, so there is no failing variant. */
101
+ export declare const AccountCheckResult: Schema.Struct<{
102
+ readonly accountInfo: Schema.optionalKey<Schema.Struct<{
103
+ readonly externalId: Schema.optionalKey<Schema.String>;
104
+ readonly displayName: Schema.optionalKey<Schema.String>;
105
+ readonly username: Schema.optionalKey<Schema.String>;
106
+ readonly email: Schema.optionalKey<Schema.String>;
107
+ readonly avatarUrl: Schema.optionalKey<Schema.String>;
108
+ readonly profileUrl: Schema.optionalKey<Schema.String>;
109
+ }>>;
110
+ }>;
111
+ export type AccountCheckResult = typeof AccountCheckResult.Type;
112
+ /** The account a provider's check verifies, with invocation-owned HTTP and cancellation. */
113
+ export interface AccountCheckContext<Auth extends AuthMethods> {
114
+ readonly account: AccountOfMethods<Auth>;
115
+ readonly fetch: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
116
+ readonly signal: AbortSignal;
117
+ }
118
+ /**
119
+ * A safe authenticated read proving the account works for this app. Returning passes; a thrown
120
+ * `ProviderError` or HTTP status failure classifies the problem. Any other failure, including a
121
+ * timeout, means the check could not verify the account, not that its credentials are bad.
122
+ */
123
+ export interface AccountCheck<Auth extends AuthMethods> {
124
+ run(context: AccountCheckContext<Auth>): Effect.Effect<AccountCheckResult | void, unknown>;
125
+ }
126
+ /** A provider declaration. The host derives its identity from the declaration, never its check. */
88
127
  export declare class Provider<Auth extends AuthMethods> extends Data.Class<{
89
128
  readonly name: string;
90
129
  readonly auth: Auth;
130
+ /**
131
+ * Stored without its method types so a specific provider still fills a general slot. The host
132
+ * binds the account against this provider's methods before running it.
133
+ */
134
+ readonly health?: AccountCheck<AuthMethods>;
91
135
  }> {
92
136
  /** Declare zero or more accounts from this provider without performing I/O. */
93
137
  many(): ManyAccounts<Auth>;
@@ -102,12 +146,14 @@ export declare class ManyAccounts<Auth extends AuthMethods> extends ManyAccounts
102
146
  }
103
147
  /** Infer the data for one method from its native Effect decoder. */
104
148
  export type AuthMethodData<Method> = Method extends SecretsMethod<infer Fields> ? Fields["Type"] : Method extends OAuth2Method<infer Response> ? Response["Type"] : never;
105
- /** One selected account, discriminated by its author-chosen method name. */
106
- export type AccountOf<P> = P extends Provider<infer Auth> ? {
149
+ /** One account for these methods, discriminated by its author-chosen method name. */
150
+ export type AccountOfMethods<Auth extends AuthMethods> = {
107
151
  readonly [Method in keyof Auth & string]: {
108
152
  readonly id: AccountId;
109
153
  readonly method: Method;
110
154
  readonly fields: AuthMethodData<Auth[Method]>;
111
155
  };
112
- }[keyof Auth & string] : never;
156
+ }[keyof Auth & string];
157
+ /** One selected account, discriminated by its author-chosen method name. */
158
+ export type AccountOf<P> = P extends Provider<infer Auth> ? AccountOfMethods<Auth> : never;
113
159
  export {};
@@ -1,6 +1,7 @@
1
1
  /** Pure constructors over the native provider contracts. */
2
2
  import { Effect, Schema } from "effect";
3
- import { type AuthMethods, OAuth2Config, OAuth2Method, Provider, SecretsMethod } from "../contracts/provider.js";
3
+ import { type PromiseMethod } from "./authoring.js";
4
+ import { type AccountCheck, type AuthMethods, OAuth2Config, OAuth2Method, Provider, SecretsMethod } from "../contracts/provider.js";
4
5
  import type { ValidationError } from "../contracts/schema.js";
5
6
  /** Declare a secrets method with an Effect decoder. */
6
7
  export declare const secrets: <Fields extends Schema.Decoder<unknown>>(options: {
@@ -9,8 +10,12 @@ export declare const secrets: <Fields extends Schema.Decoder<unknown>>(options:
9
10
  }) => SecretsMethod<Fields>;
10
11
  /** Validate OAuth endpoints while declaring their app-visible response projection. */
11
12
  export declare const oauth2: <Response extends Schema.Decoder<unknown>>(config: OAuth2Config, response: Response) => Effect.Effect<OAuth2Method<Response>, ValidationError>;
12
- /** Retain the provider and literal method names without registering or authenticating it. */
13
- export declare const defineProvider: <const Auth extends AuthMethods>(options: {
13
+ /** Author options: the account check is an ordinary async function. */
14
+ export interface ProviderOptions<Auth extends AuthMethods> {
14
15
  readonly name: string;
15
16
  readonly auth: Auth;
16
- }) => Provider<Auth>;
17
+ /** Verify a connected account with a safe read, optionally reporting its upstream identity. */
18
+ readonly health?: PromiseMethod<AccountCheck<Auth>["run"]>;
19
+ }
20
+ /** Retain the provider and literal method names without registering or authenticating it. */
21
+ export declare const defineProvider: <const Auth extends AuthMethods>({ health, ...options }: ProviderOptions<Auth>) => Provider<Auth>;
@@ -14,8 +14,8 @@ import { type PromiseMethods } from "./implementation/authoring.js";
14
14
  import { type Fields, type Infer, type ObjectSchema, type Schema } from "./implementation/schema.js";
15
15
  export { type JsonObject, type JsonValue, ValidationError } from "./contracts/schema.js";
16
16
  export { type Fields, type Infer, type ObjectSchema, type ObjectValue, type Schema, array, boolean, json, jsonSchema, literal, number, object, record, string, } from "./implementation/schema.js";
17
- export { type AccountOf, type AuthMethod, type AuthMethodData, type AuthMethods, type ManyAccounts, type OAuth2Config, type Provider, } from "./contracts/provider.js";
18
- export { defineProvider } from "./implementation/provider.js";
17
+ export { type AccountCheckContext, type AccountCheckResult, type AccountInfo, type AccountOf, type AuthMethod, type AuthMethodData, type AuthMethods, type ManyAccounts, type OAuth2Config, type Provider, } from "./contracts/provider.js";
18
+ export { defineProvider, type ProviderOptions } from "./implementation/provider.js";
19
19
  export { accountRouter } from "./implementation/account-router.js";
20
20
  export { router, dynamicRouter, type RouterDeclaration, type RouterChild, type RouterOptions, } from "./implementation/router.js";
21
21
  export type { RouterIcon } from "./contracts/router.js";