@dual-os/sdk 0.0.0-stage → 0.8.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -0
- package/README.md +19 -2
- package/dist/Action.d.ts +201 -0
- package/dist/Action.d.ts.map +1 -0
- package/dist/Action.js +172 -0
- package/dist/Action.js.map +1 -0
- package/dist/AgentChannel.d.ts +1717 -0
- package/dist/AgentChannel.d.ts.map +1 -0
- package/dist/AgentChannel.js +708 -0
- package/dist/AgentChannel.js.map +1 -0
- package/dist/AgentChannelConformance.d.ts +1543 -0
- package/dist/AgentChannelConformance.d.ts.map +1 -0
- package/dist/AgentChannelConformance.js +163 -0
- package/dist/AgentChannelConformance.js.map +1 -0
- package/dist/AgentChannelRuntime.d.ts +78 -0
- package/dist/AgentChannelRuntime.d.ts.map +1 -0
- package/dist/AgentChannelRuntime.js +270 -0
- package/dist/AgentChannelRuntime.js.map +1 -0
- package/dist/AiProvider.d.ts +132 -0
- package/dist/AiProvider.d.ts.map +1 -0
- package/dist/AiProvider.js +100 -0
- package/dist/AiProvider.js.map +1 -0
- package/dist/AuthMethod.d.ts +381 -0
- package/dist/AuthMethod.d.ts.map +1 -0
- package/dist/AuthMethod.js +225 -0
- package/dist/AuthMethod.js.map +1 -0
- package/dist/AuthMethodBinding.d.ts +77 -0
- package/dist/AuthMethodBinding.d.ts.map +1 -0
- package/dist/AuthMethodBinding.js +31 -0
- package/dist/AuthMethodBinding.js.map +1 -0
- package/dist/AuthMethodExecution.d.ts +223 -0
- package/dist/AuthMethodExecution.d.ts.map +1 -0
- package/dist/AuthMethodExecution.js +277 -0
- package/dist/AuthMethodExecution.js.map +1 -0
- package/dist/ConnectionResolver.d.ts +219 -0
- package/dist/ConnectionResolver.d.ts.map +1 -0
- package/dist/ConnectionResolver.js +153 -0
- package/dist/ConnectionResolver.js.map +1 -0
- package/dist/DefinitionError.d.ts +67 -0
- package/dist/DefinitionError.d.ts.map +1 -0
- package/dist/DefinitionError.js +82 -0
- package/dist/DefinitionError.js.map +1 -0
- package/dist/DualRegistry.d.ts +71 -0
- package/dist/DualRegistry.d.ts.map +1 -0
- package/dist/DualRegistry.js +96 -0
- package/dist/DualRegistry.js.map +1 -0
- package/dist/DualRuntime.d.ts +279 -0
- package/dist/DualRuntime.d.ts.map +1 -0
- package/dist/DualRuntime.js +311 -0
- package/dist/DualRuntime.js.map +1 -0
- package/dist/Files.d.ts +80 -0
- package/dist/Files.d.ts.map +1 -0
- package/dist/Files.js +66 -0
- package/dist/Files.js.map +1 -0
- package/dist/Group.d.ts +106 -0
- package/dist/Group.d.ts.map +1 -0
- package/dist/Group.js +86 -0
- package/dist/Group.js.map +1 -0
- package/dist/Http.d.ts +342 -0
- package/dist/Http.d.ts.map +1 -0
- package/dist/Http.js +677 -0
- package/dist/Http.js.map +1 -0
- package/dist/Mcp.d.ts +109 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +176 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/OAuth2TokenRefresher.d.ts +18 -0
- package/dist/OAuth2TokenRefresher.d.ts.map +1 -0
- package/dist/OAuth2TokenRefresher.js +19 -0
- package/dist/OAuth2TokenRefresher.js.map +1 -0
- package/dist/OAuthFlow.d.ts +71 -0
- package/dist/OAuthFlow.d.ts.map +1 -0
- package/dist/OAuthFlow.js +488 -0
- package/dist/OAuthFlow.js.map +1 -0
- package/dist/Plugin.d.ts +383 -0
- package/dist/Plugin.d.ts.map +1 -0
- package/dist/Plugin.js +249 -0
- package/dist/Plugin.js.map +1 -0
- package/dist/PluginRuntime.d.ts +3186 -0
- package/dist/PluginRuntime.d.ts.map +1 -0
- package/dist/PluginRuntime.js +331 -0
- package/dist/PluginRuntime.js.map +1 -0
- package/dist/Runner.d.ts +1 -0
- package/dist/Runner.js +124 -0
- package/dist/Runner.js.map +1 -0
- package/dist/ToolFile.d.ts +23 -0
- package/dist/ToolFile.d.ts.map +1 -0
- package/dist/ToolFile.js +33 -0
- package/dist/ToolFile.js.map +1 -0
- package/dist/Trigger.d.ts +358 -0
- package/dist/Trigger.d.ts.map +1 -0
- package/dist/Trigger.js +287 -0
- package/dist/Trigger.js.map +1 -0
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +24 -0
- package/dist/internal/auth-context.d.ts +23 -0
- package/dist/internal/auth-context.d.ts.map +1 -0
- package/dist/internal/auth-context.js +1 -0
- package/dist/internal/auth-execution.d.ts +27 -0
- package/dist/internal/auth-execution.d.ts.map +1 -0
- package/dist/internal/auth-execution.js +66 -0
- package/dist/internal/auth-execution.js.map +1 -0
- package/dist/internal/auth-runtime.d.ts +5 -0
- package/dist/internal/auth-runtime.d.ts.map +1 -0
- package/dist/internal/auth-runtime.js +16 -0
- package/dist/internal/auth-runtime.js.map +1 -0
- package/dist/internal/capabilities.d.ts +24 -0
- package/dist/internal/capabilities.d.ts.map +1 -0
- package/dist/internal/capabilities.js +22 -0
- package/dist/internal/capabilities.js.map +1 -0
- package/dist/internal/children.d.ts +34 -0
- package/dist/internal/children.d.ts.map +1 -0
- package/dist/internal/children.js +53 -0
- package/dist/internal/children.js.map +1 -0
- package/dist/internal/collection-utils.d.ts +4 -0
- package/dist/internal/collection-utils.d.ts.map +1 -0
- package/dist/internal/collection-utils.js +6 -0
- package/dist/internal/collection-utils.js.map +1 -0
- package/dist/internal/dual/actions.d.ts +33 -0
- package/dist/internal/dual/actions.d.ts.map +1 -0
- package/dist/internal/dual/actions.js +26 -0
- package/dist/internal/dual/actions.js.map +1 -0
- package/dist/internal/dual/invoke.d.ts +63 -0
- package/dist/internal/dual/invoke.d.ts.map +1 -0
- package/dist/internal/dual/invoke.js +75 -0
- package/dist/internal/dual/invoke.js.map +1 -0
- package/dist/internal/dual/registry.d.ts +125 -0
- package/dist/internal/dual/registry.d.ts.map +1 -0
- package/dist/internal/dual/registry.js +172 -0
- package/dist/internal/dual/registry.js.map +1 -0
- package/dist/internal/dual/triggers.d.ts +29 -0
- package/dist/internal/dual/triggers.d.ts.map +1 -0
- package/dist/internal/dual/triggers.js +26 -0
- package/dist/internal/dual/triggers.js.map +1 -0
- package/dist/internal/handler-context.d.ts +9 -0
- package/dist/internal/handler-context.d.ts.map +1 -0
- package/dist/internal/handler-context.js +31 -0
- package/dist/internal/handler-context.js.map +1 -0
- package/dist/internal/identifier.d.ts +6 -0
- package/dist/internal/identifier.d.ts.map +1 -0
- package/dist/internal/identifier.js +28 -0
- package/dist/internal/identifier.js.map +1 -0
- package/dist/internal/plugin-handlers.d.ts +38 -0
- package/dist/internal/plugin-handlers.d.ts.map +1 -0
- package/dist/internal/plugin-handlers.js +52 -0
- package/dist/internal/plugin-handlers.js.map +1 -0
- package/dist/internal/proto.d.ts +7 -0
- package/dist/internal/proto.d.ts.map +1 -0
- package/dist/internal/proto.js +10 -0
- package/dist/internal/proto.js.map +1 -0
- package/dist/internal/schema-runtime.d.ts +6 -0
- package/dist/internal/schema-runtime.d.ts.map +1 -0
- package/dist/internal/schema-runtime.js +10 -0
- package/dist/internal/schema-runtime.js.map +1 -0
- package/dist/internal/trigger-runtime-shared.d.ts +41 -0
- package/dist/internal/trigger-runtime-shared.d.ts.map +1 -0
- package/dist/internal/trigger-runtime-shared.js +132 -0
- package/dist/internal/trigger-runtime-shared.js.map +1 -0
- package/dist/internal/trigger-runtime.d.ts +12 -0
- package/dist/internal/trigger-runtime.d.ts.map +1 -0
- package/dist/internal/trigger-runtime.js +95 -0
- package/dist/internal/trigger-runtime.js.map +1 -0
- package/dist/internal/types.d.ts +7 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +1 -0
- package/dist/remote-runtime.d.ts +585 -0
- package/dist/remote-runtime.d.ts.map +1 -0
- package/dist/remote-runtime.js +367 -0
- package/dist/remote-runtime.js.map +1 -0
- package/package.json +55 -4
- package/src/Action.ts +370 -0
- package/src/AgentChannel.ts +860 -0
- package/src/AgentChannelConformance.ts +124 -0
- package/src/AgentChannelRuntime.ts +616 -0
- package/src/AiProvider.ts +255 -0
- package/src/AuthMethod.ts +954 -0
- package/src/AuthMethodBinding.ts +112 -0
- package/src/AuthMethodExecution.ts +542 -0
- package/src/ConnectionResolver.ts +265 -0
- package/src/DefinitionError.ts +115 -0
- package/src/DualRegistry.ts +152 -0
- package/src/DualRuntime.ts +1081 -0
- package/src/Files.ts +89 -0
- package/src/Group.ts +292 -0
- package/src/Http.ts +1205 -0
- package/src/Mcp.ts +299 -0
- package/src/OAuth2TokenRefresher.ts +22 -0
- package/src/OAuthFlow.ts +874 -0
- package/src/Plugin.ts +912 -0
- package/src/PluginRuntime.ts +414 -0
- package/src/Runner.ts +248 -0
- package/src/ToolFile.ts +28 -0
- package/src/Trigger.ts +722 -0
- package/src/index.ts +158 -0
- package/src/internal/auth-context.ts +27 -0
- package/src/internal/auth-execution.ts +241 -0
- package/src/internal/auth-runtime.ts +20 -0
- package/src/internal/capabilities.ts +55 -0
- package/src/internal/children.ts +126 -0
- package/src/internal/collection-utils.ts +8 -0
- package/src/internal/dual/actions.ts +116 -0
- package/src/internal/dual/invoke.ts +307 -0
- package/src/internal/dual/registry.ts +340 -0
- package/src/internal/dual/triggers.ts +128 -0
- package/src/internal/handler-context.ts +57 -0
- package/src/internal/identifier.ts +27 -0
- package/src/internal/plugin-handlers.ts +146 -0
- package/src/internal/proto.ts +8 -0
- package/src/internal/schema-runtime.ts +15 -0
- package/src/internal/trigger-runtime-shared.ts +449 -0
- package/src/internal/trigger-runtime.ts +223 -0
- package/src/internal/types.ts +12 -0
- package/src/remote-runtime.ts +469 -0
|
@@ -0,0 +1,954 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical auth-method definition builders and types for the Dual SDK.
|
|
3
|
+
*
|
|
4
|
+
* Providers own auth methods shared by all actions and triggers under them.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.0.0
|
|
7
|
+
*/
|
|
8
|
+
import { Function as Func, Predicate, Schema } from "effect";
|
|
9
|
+
import type { Config, Effect, Pipeable } from "effect";
|
|
10
|
+
|
|
11
|
+
import type * as Types from "effect/Types";
|
|
12
|
+
|
|
13
|
+
import { validateIdentifier } from "./internal/identifier.ts";
|
|
14
|
+
import { PipeableProto } from "./internal/proto.ts";
|
|
15
|
+
import type * as OAuth2TokenRefresher from "./OAuth2TokenRefresher.ts";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @since 0.0.0
|
|
19
|
+
* @category type ids
|
|
20
|
+
*/
|
|
21
|
+
export const TypeId = "@dual-os/sdk/AuthMethod" as const;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @since 0.0.0
|
|
25
|
+
* @category type ids
|
|
26
|
+
*/
|
|
27
|
+
export type TypeId = typeof TypeId;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Phantom inference slot for the hook requirements union.
|
|
31
|
+
*
|
|
32
|
+
* Unlike the schema parameters, hook requirements only occur inside optional
|
|
33
|
+
* hook signatures, which TypeScript cannot reliably infer through; this slot
|
|
34
|
+
* gives the {@link Requirements} extractor a stable inference site.
|
|
35
|
+
*
|
|
36
|
+
* One union instead of per-hook parameters on purpose: in practice a method's
|
|
37
|
+
* dependencies are provided once at the plugin/app definition (for example a
|
|
38
|
+
* Gmail client layer), not separately per hook, and every consumption path
|
|
39
|
+
* (invoke, trigger phases, credential lifecycle, `DualRuntime.toLayer`) must demand
|
|
40
|
+
* the same set so none of them can silently under-require.
|
|
41
|
+
*
|
|
42
|
+
* @since 0.0.0
|
|
43
|
+
* @category models
|
|
44
|
+
*/
|
|
45
|
+
export interface RequirementsVariance<out Requirements> {
|
|
46
|
+
readonly _Requirements: Types.Covariant<Requirements>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Constraint type for working with any {@link AuthMethod}.
|
|
51
|
+
*
|
|
52
|
+
* @since 0.0.0
|
|
53
|
+
* @category type-level
|
|
54
|
+
*/
|
|
55
|
+
export interface Any extends Pipeable.Pipeable {
|
|
56
|
+
readonly [TypeId]: RequirementsVariance<any>;
|
|
57
|
+
readonly identifier: string;
|
|
58
|
+
readonly name: string | undefined;
|
|
59
|
+
readonly description: string | undefined;
|
|
60
|
+
readonly kind: AuthMethodKind;
|
|
61
|
+
readonly setup: Schema.Top | undefined;
|
|
62
|
+
readonly input: Schema.Top | undefined;
|
|
63
|
+
readonly material: Schema.Top;
|
|
64
|
+
readonly value: Schema.Top;
|
|
65
|
+
readonly schema: Schema.Top;
|
|
66
|
+
readonly prepare: unknown;
|
|
67
|
+
readonly refresh: unknown;
|
|
68
|
+
readonly resolve: unknown;
|
|
69
|
+
readonly display: unknown;
|
|
70
|
+
readonly test: unknown;
|
|
71
|
+
readonly oauth2: OAuth2Setup<Schema.Top, any, any> | undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @since 0.0.0 @category models */
|
|
75
|
+
export type AuthMethodKind = "form" | "oauth2" | "custom";
|
|
76
|
+
|
|
77
|
+
/** @since 0.0.0 @category type-level */
|
|
78
|
+
export type SchemaType<SchemaDef extends Schema.Top | undefined> = SchemaDef extends Schema.Top
|
|
79
|
+
? Schema.Schema.Type<SchemaDef>
|
|
80
|
+
: undefined;
|
|
81
|
+
|
|
82
|
+
/** @since 0.0.0 @category hooks */
|
|
83
|
+
export interface HookContext<Setup = undefined> {
|
|
84
|
+
readonly setup: Setup;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** @since 0.0.0 @category hooks */
|
|
88
|
+
export type MaybeEffect<Value, Error = never, Requirements = never> =
|
|
89
|
+
| Value
|
|
90
|
+
| Effect.Effect<Value, Error, Requirements>;
|
|
91
|
+
|
|
92
|
+
/** @since 0.0.0 @category hooks */
|
|
93
|
+
export type PrepareHook<Input, Material, Error = never, Requirements = never, Setup = undefined> = (
|
|
94
|
+
input: Input,
|
|
95
|
+
context: HookContext<Setup>,
|
|
96
|
+
) => MaybeEffect<Material, Error, Requirements>;
|
|
97
|
+
|
|
98
|
+
/** @since 0.0.0 @category hooks */
|
|
99
|
+
export type RefreshReason = "before-use" | "forced";
|
|
100
|
+
|
|
101
|
+
/** @since 0.0.0 @category hooks */
|
|
102
|
+
export interface RefreshContext<Setup = undefined> extends HookContext<Setup> {
|
|
103
|
+
readonly now: number;
|
|
104
|
+
readonly minValidityMs: number;
|
|
105
|
+
readonly reason: RefreshReason;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @since 0.0.0 @category hooks */
|
|
109
|
+
export type RefreshHook<Material, Error = never, Requirements = never, Setup = undefined> = (
|
|
110
|
+
material: Material,
|
|
111
|
+
context: RefreshContext<Setup>,
|
|
112
|
+
) => MaybeEffect<Material | undefined, Error, Requirements>;
|
|
113
|
+
|
|
114
|
+
/** @since 0.0.0 @category hooks */
|
|
115
|
+
export type ResolveHook<Material, Value, Error = never, Requirements = never, Setup = undefined> = (
|
|
116
|
+
material: Material,
|
|
117
|
+
context: HookContext<Setup>,
|
|
118
|
+
) => MaybeEffect<Value, Error, Requirements>;
|
|
119
|
+
|
|
120
|
+
/** @since 0.0.0 @category models */
|
|
121
|
+
export interface Display {
|
|
122
|
+
readonly label?: string;
|
|
123
|
+
readonly description?: string;
|
|
124
|
+
readonly metadata?: Record<string, unknown>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** @since 0.0.0 @category hooks */
|
|
128
|
+
export type DisplayHook<Material, Error = never, Requirements = never, Setup = undefined> = (
|
|
129
|
+
material: Material,
|
|
130
|
+
context: HookContext<Setup>,
|
|
131
|
+
) => MaybeEffect<Display, Error, Requirements>;
|
|
132
|
+
|
|
133
|
+
/** @since 0.0.0 @category models */
|
|
134
|
+
export interface TestResult {
|
|
135
|
+
readonly ok: boolean;
|
|
136
|
+
readonly message?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** @since 0.0.0 @category errors */
|
|
140
|
+
export class ExpectedOAuth2MethodError extends Schema.TaggedError<ExpectedOAuth2MethodError>()(
|
|
141
|
+
"ExpectedOAuth2MethodError",
|
|
142
|
+
{ methodIdentifier: Schema.String },
|
|
143
|
+
) {}
|
|
144
|
+
|
|
145
|
+
/** @since 0.0.0 @category hooks */
|
|
146
|
+
export type TestHook<Material, Error = never, Requirements = never, Setup = undefined> = (
|
|
147
|
+
material: Material,
|
|
148
|
+
context: HookContext<Setup>,
|
|
149
|
+
) => MaybeEffect<TestResult, Error, Requirements>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Options used to create an {@link AuthMethod}.
|
|
153
|
+
*
|
|
154
|
+
* @since 0.0.0
|
|
155
|
+
* @category models
|
|
156
|
+
*/
|
|
157
|
+
export interface AuthMethodOptions<ValueSchema extends Schema.Top> {
|
|
158
|
+
readonly name?: string;
|
|
159
|
+
readonly description?: string;
|
|
160
|
+
readonly schema: ValueSchema;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** @since 0.0.0 @category models */
|
|
164
|
+
export interface FormOptions<
|
|
165
|
+
ValueSchema extends Schema.Top,
|
|
166
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
167
|
+
> extends AuthMethodOptions<ValueSchema> {
|
|
168
|
+
readonly setup?: SetupSchema;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** @since 0.0.0 @category models */
|
|
172
|
+
export interface AuthOptionsWithoutMaterial<
|
|
173
|
+
InputSchema extends Schema.Top,
|
|
174
|
+
ValueSchema extends Schema.Top = InputSchema,
|
|
175
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
176
|
+
PrepareRequirements = never,
|
|
177
|
+
RefreshRequirements = never,
|
|
178
|
+
ResolveRequirements = never,
|
|
179
|
+
DisplayRequirements = never,
|
|
180
|
+
TestRequirements = never,
|
|
181
|
+
> {
|
|
182
|
+
readonly name?: string;
|
|
183
|
+
readonly description?: string;
|
|
184
|
+
readonly setup?: SetupSchema;
|
|
185
|
+
readonly input: InputSchema;
|
|
186
|
+
readonly material?: undefined;
|
|
187
|
+
readonly value?: ValueSchema;
|
|
188
|
+
readonly prepare?: PrepareHook<
|
|
189
|
+
SchemaType<InputSchema>,
|
|
190
|
+
SchemaType<InputSchema>,
|
|
191
|
+
any,
|
|
192
|
+
PrepareRequirements,
|
|
193
|
+
SchemaType<SetupSchema>
|
|
194
|
+
>;
|
|
195
|
+
readonly refresh?: RefreshHook<
|
|
196
|
+
SchemaType<InputSchema>,
|
|
197
|
+
any,
|
|
198
|
+
RefreshRequirements,
|
|
199
|
+
SchemaType<SetupSchema>
|
|
200
|
+
>;
|
|
201
|
+
readonly resolve?: ResolveHook<
|
|
202
|
+
SchemaType<InputSchema>,
|
|
203
|
+
Schema.Schema.Type<ValueSchema>,
|
|
204
|
+
any,
|
|
205
|
+
ResolveRequirements,
|
|
206
|
+
SchemaType<SetupSchema>
|
|
207
|
+
>;
|
|
208
|
+
readonly display?: DisplayHook<
|
|
209
|
+
SchemaType<InputSchema>,
|
|
210
|
+
any,
|
|
211
|
+
DisplayRequirements,
|
|
212
|
+
SchemaType<SetupSchema>
|
|
213
|
+
>;
|
|
214
|
+
readonly test?: TestHook<SchemaType<InputSchema>, any, TestRequirements, SchemaType<SetupSchema>>;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** @since 0.0.0 @category models */
|
|
218
|
+
export interface AuthOptionsWithMaterial<
|
|
219
|
+
InputSchema extends Schema.Top | undefined,
|
|
220
|
+
MaterialSchema extends Schema.Top,
|
|
221
|
+
ValueSchema extends Schema.Top = MaterialSchema,
|
|
222
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
223
|
+
PrepareRequirements = never,
|
|
224
|
+
RefreshRequirements = never,
|
|
225
|
+
ResolveRequirements = never,
|
|
226
|
+
DisplayRequirements = never,
|
|
227
|
+
TestRequirements = never,
|
|
228
|
+
> {
|
|
229
|
+
readonly name?: string;
|
|
230
|
+
readonly description?: string;
|
|
231
|
+
readonly setup?: SetupSchema;
|
|
232
|
+
readonly input: InputSchema;
|
|
233
|
+
readonly material: MaterialSchema;
|
|
234
|
+
readonly value?: ValueSchema;
|
|
235
|
+
readonly prepare?: PrepareHook<
|
|
236
|
+
SchemaType<InputSchema>,
|
|
237
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
238
|
+
any,
|
|
239
|
+
PrepareRequirements,
|
|
240
|
+
SchemaType<SetupSchema>
|
|
241
|
+
>;
|
|
242
|
+
readonly refresh?: RefreshHook<
|
|
243
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
244
|
+
any,
|
|
245
|
+
RefreshRequirements,
|
|
246
|
+
SchemaType<SetupSchema>
|
|
247
|
+
>;
|
|
248
|
+
readonly resolve?: ResolveHook<
|
|
249
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
250
|
+
Schema.Schema.Type<ValueSchema>,
|
|
251
|
+
any,
|
|
252
|
+
ResolveRequirements,
|
|
253
|
+
SchemaType<SetupSchema>
|
|
254
|
+
>;
|
|
255
|
+
readonly display?: DisplayHook<
|
|
256
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
257
|
+
any,
|
|
258
|
+
DisplayRequirements,
|
|
259
|
+
SchemaType<SetupSchema>
|
|
260
|
+
>;
|
|
261
|
+
readonly test?: TestHook<
|
|
262
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
263
|
+
any,
|
|
264
|
+
TestRequirements,
|
|
265
|
+
SchemaType<SetupSchema>
|
|
266
|
+
>;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** @since 0.0.0 @category models */
|
|
270
|
+
export interface OAuth2ClientConfig {
|
|
271
|
+
readonly clientId: string | Config.Config<string>;
|
|
272
|
+
readonly clientSecret?: string | Config.Config<string>;
|
|
273
|
+
readonly authentication?: "basic" | "post" | "none";
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** @since 0.0.0 @category hooks */
|
|
277
|
+
export type OAuth2ClientHook<Setup> = (context: HookContext<Setup>) => OAuth2ClientConfig;
|
|
278
|
+
|
|
279
|
+
/** @since 0.0.0 @category models */
|
|
280
|
+
export type OAuth2Client<Setup = undefined> = OAuth2ClientConfig | OAuth2ClientHook<Setup>;
|
|
281
|
+
|
|
282
|
+
/** @since 0.0.0 @category hooks */
|
|
283
|
+
export type OAuth2EndpointHook<Setup> = (context: HookContext<Setup>) => string;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* An OAuth2 endpoint, fixed or derived from the setup.
|
|
287
|
+
*
|
|
288
|
+
* Providers that host one instance per customer — a Microsoft tenant, a
|
|
289
|
+
* self-hosted GitLab — cannot name their endpoints until the connection's setup
|
|
290
|
+
* says which instance it is.
|
|
291
|
+
*
|
|
292
|
+
* @since 0.0.0
|
|
293
|
+
* @category models
|
|
294
|
+
*/
|
|
295
|
+
export type OAuth2Endpoint<Setup = undefined> = string | OAuth2EndpointHook<Setup>;
|
|
296
|
+
|
|
297
|
+
/** @since 0.0.0 @category models */
|
|
298
|
+
export type OAuth2ParamsHook<Setup> = (
|
|
299
|
+
context: HookContext<Setup>,
|
|
300
|
+
) => Readonly<Record<string, string>>;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Query parameters added to the authorization or token request, fixed or
|
|
304
|
+
* derived from the setup — the same freedom the endpoints have. A provider
|
|
305
|
+
* that knows which account a connection is for can say so in the request
|
|
306
|
+
* instead of leaving the choice to whatever session the browser carries.
|
|
307
|
+
*
|
|
308
|
+
* @since 0.0.0 @category models
|
|
309
|
+
*/
|
|
310
|
+
export type OAuth2Params<Setup = undefined> =
|
|
311
|
+
| Readonly<Record<string, string>>
|
|
312
|
+
| OAuth2ParamsHook<Setup>;
|
|
313
|
+
|
|
314
|
+
/** @since 0.0.0 @category hooks */
|
|
315
|
+
export type OAuth2HeadersHook<SetupValue> = (
|
|
316
|
+
context: HookContext<SetupValue>,
|
|
317
|
+
) => Readonly<Record<string, string>>;
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Provider headers for token exchange and refresh, fixed or derived from setup.
|
|
321
|
+
* Hosts must reject invalid headers and case-insensitive overrides of client
|
|
322
|
+
* authentication and transport headers. Keep values out of authorization URLs,
|
|
323
|
+
* public metadata, logs, and errors.
|
|
324
|
+
*
|
|
325
|
+
* @since 0.0.0 @category models
|
|
326
|
+
*/
|
|
327
|
+
export type OAuth2Headers<SetupValue = HookContext["setup"]> =
|
|
328
|
+
| Readonly<Record<string, string>>
|
|
329
|
+
| OAuth2HeadersHook<SetupValue>;
|
|
330
|
+
|
|
331
|
+
/** @since 0.0.0 @category schemas */
|
|
332
|
+
export const OAuth2ProviderTokenResponse = Schema.Struct({
|
|
333
|
+
access_token: Schema.optional(Schema.String),
|
|
334
|
+
expires_at: Schema.optional(Schema.String),
|
|
335
|
+
expires_in: Schema.optional(Schema.Union([Schema.Number, Schema.String])),
|
|
336
|
+
refresh_token: Schema.optional(Schema.String),
|
|
337
|
+
scope: Schema.optional(Schema.String),
|
|
338
|
+
token_type: Schema.optional(Schema.String),
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
/** @since 0.0.0 @category models */
|
|
342
|
+
export type OAuth2ProviderTokenResponse = typeof OAuth2ProviderTokenResponse.Type;
|
|
343
|
+
|
|
344
|
+
/** @since 0.0.0 @category schemas */
|
|
345
|
+
export const OAuth2TokenResponse = Schema.Struct({
|
|
346
|
+
accessToken: Schema.String,
|
|
347
|
+
expiresAt: Schema.optional(Schema.Number),
|
|
348
|
+
expiresIn: Schema.optional(Schema.Number),
|
|
349
|
+
raw: Schema.Record(Schema.String, Schema.Unknown),
|
|
350
|
+
refreshToken: Schema.optional(Schema.String),
|
|
351
|
+
scope: Schema.optional(Schema.String),
|
|
352
|
+
tokenType: Schema.optional(Schema.String),
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
/** @since 0.0.0 @category models */
|
|
356
|
+
export type OAuth2TokenResponse = typeof OAuth2TokenResponse.Type;
|
|
357
|
+
|
|
358
|
+
/** @since 0.0.0 @category errors */
|
|
359
|
+
export class OAuth2RefreshTokenUnavailableError extends Schema.TaggedError<OAuth2RefreshTokenUnavailableError>()(
|
|
360
|
+
"OAuth2RefreshTokenUnavailableError",
|
|
361
|
+
{ methodIdentifier: Schema.String },
|
|
362
|
+
) {}
|
|
363
|
+
|
|
364
|
+
/** @since 0.0.0 @category errors */
|
|
365
|
+
export const AuthMethodHookOperation = Schema.Literals([
|
|
366
|
+
"prepare",
|
|
367
|
+
"refresh",
|
|
368
|
+
"prepareOAuth2Tokens",
|
|
369
|
+
"resolve",
|
|
370
|
+
"display",
|
|
371
|
+
"test",
|
|
372
|
+
"oauth2TokenRefresh",
|
|
373
|
+
]);
|
|
374
|
+
|
|
375
|
+
/** @since 0.0.0 @category errors */
|
|
376
|
+
export type AuthMethodHookOperation = typeof AuthMethodHookOperation.Type;
|
|
377
|
+
|
|
378
|
+
/** @since 0.0.0 @category errors */
|
|
379
|
+
export class AuthMethodHookError extends Schema.TaggedError<AuthMethodHookError>()(
|
|
380
|
+
"AuthMethodHookError",
|
|
381
|
+
{ cause: Schema.Defect(), methodIdentifier: Schema.String, operation: AuthMethodHookOperation },
|
|
382
|
+
) {}
|
|
383
|
+
|
|
384
|
+
/** @since 0.0.0 @category schemas */
|
|
385
|
+
export const OAuth2TokenMaterial = Schema.Struct({
|
|
386
|
+
accessToken: Schema.String,
|
|
387
|
+
expiresAt: Schema.optional(Schema.Number),
|
|
388
|
+
expiresIn: Schema.optional(Schema.Number),
|
|
389
|
+
raw: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
390
|
+
refreshToken: Schema.optional(Schema.String),
|
|
391
|
+
scope: Schema.optional(Schema.String),
|
|
392
|
+
tokenType: Schema.optional(Schema.String),
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
/** @since 0.0.0 @category models */
|
|
396
|
+
export interface OAuth2Setup<
|
|
397
|
+
MaterialSchema extends Schema.Top,
|
|
398
|
+
Setup = undefined,
|
|
399
|
+
TokenRequirements = never,
|
|
400
|
+
> {
|
|
401
|
+
readonly scopes: readonly string[];
|
|
402
|
+
readonly client: OAuth2Client<Setup>;
|
|
403
|
+
readonly discoveryUrl?: OAuth2Endpoint<Setup>;
|
|
404
|
+
readonly authorizationUrl?: OAuth2Endpoint<Setup>;
|
|
405
|
+
readonly tokenUrl?: OAuth2Endpoint<Setup>;
|
|
406
|
+
readonly pkce?: boolean;
|
|
407
|
+
readonly authorizationParams?: OAuth2Params<Setup>;
|
|
408
|
+
readonly tokenParams?: OAuth2Params<Setup>;
|
|
409
|
+
readonly tokenHeaders?: OAuth2Headers<Setup>;
|
|
410
|
+
/** Token request body encoding. Standard OAuth2 methods use form encoding. */
|
|
411
|
+
readonly tokenRequestEncoding?: "form" | "json";
|
|
412
|
+
/** Decode a provider response into the standard token fields before host normalization. */
|
|
413
|
+
readonly tokenResponse?: Schema.Decoder<OAuth2ProviderTokenResponse>;
|
|
414
|
+
readonly fromTokens?: PrepareHook<
|
|
415
|
+
OAuth2TokenResponse,
|
|
416
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
417
|
+
any,
|
|
418
|
+
TokenRequirements,
|
|
419
|
+
Setup
|
|
420
|
+
>;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** @since 0.0.0 @category models */
|
|
424
|
+
export interface OAuth2Options<
|
|
425
|
+
MaterialSchema extends Schema.Top,
|
|
426
|
+
ValueSchema extends Schema.Top = MaterialSchema,
|
|
427
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
428
|
+
TokenRequirements = never,
|
|
429
|
+
ResolveRequirements = never,
|
|
430
|
+
DisplayRequirements = never,
|
|
431
|
+
TestRequirements = never,
|
|
432
|
+
> extends OAuth2Setup<MaterialSchema, SchemaType<SetupSchema>, TokenRequirements> {
|
|
433
|
+
readonly name?: string;
|
|
434
|
+
readonly description?: string;
|
|
435
|
+
readonly setup?: SetupSchema;
|
|
436
|
+
readonly material: MaterialSchema;
|
|
437
|
+
readonly value?: ValueSchema;
|
|
438
|
+
readonly fromTokens?: PrepareHook<
|
|
439
|
+
OAuth2TokenResponse,
|
|
440
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
441
|
+
any,
|
|
442
|
+
TokenRequirements,
|
|
443
|
+
SchemaType<SetupSchema>
|
|
444
|
+
>;
|
|
445
|
+
readonly resolve?: ResolveHook<
|
|
446
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
447
|
+
Schema.Schema.Type<ValueSchema>,
|
|
448
|
+
any,
|
|
449
|
+
ResolveRequirements,
|
|
450
|
+
SchemaType<SetupSchema>
|
|
451
|
+
>;
|
|
452
|
+
readonly display?: DisplayHook<
|
|
453
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
454
|
+
any,
|
|
455
|
+
DisplayRequirements,
|
|
456
|
+
SchemaType<SetupSchema>
|
|
457
|
+
>;
|
|
458
|
+
readonly test?: TestHook<
|
|
459
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
460
|
+
any,
|
|
461
|
+
TestRequirements,
|
|
462
|
+
SchemaType<SetupSchema>
|
|
463
|
+
>;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* A typed provider-owned auth method definition.
|
|
468
|
+
*
|
|
469
|
+
* @since 0.0.0
|
|
470
|
+
* @category models
|
|
471
|
+
*/
|
|
472
|
+
export interface AuthMethod<
|
|
473
|
+
out Identifier extends string = string,
|
|
474
|
+
out SetupSchema extends Schema.Top | undefined = Schema.Top | undefined,
|
|
475
|
+
out InputSchema extends Schema.Top | undefined = Schema.Top | undefined,
|
|
476
|
+
out MaterialSchema extends Schema.Top = Schema.Top,
|
|
477
|
+
out ValueSchema extends Schema.Top = Schema.Top,
|
|
478
|
+
out Requirements = never,
|
|
479
|
+
>
|
|
480
|
+
extends Pipeable.Pipeable {
|
|
481
|
+
readonly [TypeId]: RequirementsVariance<Requirements>;
|
|
482
|
+
readonly identifier: Identifier;
|
|
483
|
+
readonly name: string | undefined;
|
|
484
|
+
readonly description: string | undefined;
|
|
485
|
+
readonly kind: AuthMethodKind;
|
|
486
|
+
readonly setup: SetupSchema;
|
|
487
|
+
readonly input: InputSchema;
|
|
488
|
+
readonly material: MaterialSchema;
|
|
489
|
+
readonly value: ValueSchema;
|
|
490
|
+
/** Runtime value schema retained for concise action/trigger typing. */
|
|
491
|
+
readonly schema: ValueSchema;
|
|
492
|
+
readonly prepare:
|
|
493
|
+
| PrepareHook<
|
|
494
|
+
SchemaType<InputSchema>,
|
|
495
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
496
|
+
any,
|
|
497
|
+
Requirements,
|
|
498
|
+
SchemaType<SetupSchema>
|
|
499
|
+
>
|
|
500
|
+
| undefined;
|
|
501
|
+
readonly refresh:
|
|
502
|
+
| RefreshHook<Schema.Schema.Type<MaterialSchema>, any, Requirements, SchemaType<SetupSchema>>
|
|
503
|
+
| undefined;
|
|
504
|
+
readonly resolve:
|
|
505
|
+
| ResolveHook<
|
|
506
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
507
|
+
Schema.Schema.Type<ValueSchema>,
|
|
508
|
+
any,
|
|
509
|
+
Requirements,
|
|
510
|
+
SchemaType<SetupSchema>
|
|
511
|
+
>
|
|
512
|
+
| undefined;
|
|
513
|
+
readonly display:
|
|
514
|
+
| DisplayHook<Schema.Schema.Type<MaterialSchema>, any, Requirements, SchemaType<SetupSchema>>
|
|
515
|
+
| undefined;
|
|
516
|
+
readonly test:
|
|
517
|
+
| TestHook<Schema.Schema.Type<MaterialSchema>, any, Requirements, SchemaType<SetupSchema>>
|
|
518
|
+
| undefined;
|
|
519
|
+
readonly oauth2: OAuth2Setup<MaterialSchema, SchemaType<SetupSchema>, Requirements> | undefined;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
const Proto = { ...PipeableProto, [TypeId]: { _Requirements: Func.identity } };
|
|
523
|
+
|
|
524
|
+
const makeAuthMethod = <
|
|
525
|
+
const Identifier extends string,
|
|
526
|
+
SetupSchema extends Schema.Top | undefined,
|
|
527
|
+
InputSchema extends Schema.Top | undefined,
|
|
528
|
+
MaterialSchema extends Schema.Top,
|
|
529
|
+
ValueSchema extends Schema.Top,
|
|
530
|
+
TokenRequirements = never,
|
|
531
|
+
RefreshRequirements = never,
|
|
532
|
+
PrepareRequirements = never,
|
|
533
|
+
ResolveRequirements = never,
|
|
534
|
+
DisplayRequirements = never,
|
|
535
|
+
TestRequirements = never,
|
|
536
|
+
>(
|
|
537
|
+
identifier: Identifier,
|
|
538
|
+
options: {
|
|
539
|
+
readonly name: string | undefined;
|
|
540
|
+
readonly description: string | undefined;
|
|
541
|
+
readonly kind: AuthMethodKind;
|
|
542
|
+
readonly setup: SetupSchema;
|
|
543
|
+
readonly input: InputSchema;
|
|
544
|
+
readonly material: MaterialSchema;
|
|
545
|
+
readonly value: ValueSchema;
|
|
546
|
+
readonly prepare:
|
|
547
|
+
| PrepareHook<
|
|
548
|
+
SchemaType<InputSchema>,
|
|
549
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
550
|
+
any,
|
|
551
|
+
PrepareRequirements,
|
|
552
|
+
SchemaType<SetupSchema>
|
|
553
|
+
>
|
|
554
|
+
| undefined;
|
|
555
|
+
readonly refresh:
|
|
556
|
+
| RefreshHook<
|
|
557
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
558
|
+
any,
|
|
559
|
+
RefreshRequirements,
|
|
560
|
+
SchemaType<SetupSchema>
|
|
561
|
+
>
|
|
562
|
+
| undefined;
|
|
563
|
+
readonly resolve:
|
|
564
|
+
| ResolveHook<
|
|
565
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
566
|
+
Schema.Schema.Type<ValueSchema>,
|
|
567
|
+
any,
|
|
568
|
+
ResolveRequirements,
|
|
569
|
+
SchemaType<SetupSchema>
|
|
570
|
+
>
|
|
571
|
+
| undefined;
|
|
572
|
+
readonly display:
|
|
573
|
+
| DisplayHook<
|
|
574
|
+
Schema.Schema.Type<MaterialSchema>,
|
|
575
|
+
any,
|
|
576
|
+
DisplayRequirements,
|
|
577
|
+
SchemaType<SetupSchema>
|
|
578
|
+
>
|
|
579
|
+
| undefined;
|
|
580
|
+
readonly test:
|
|
581
|
+
| TestHook<Schema.Schema.Type<MaterialSchema>, any, TestRequirements, SchemaType<SetupSchema>>
|
|
582
|
+
| undefined;
|
|
583
|
+
readonly oauth2:
|
|
584
|
+
| OAuth2Setup<MaterialSchema, SchemaType<SetupSchema>, TokenRequirements>
|
|
585
|
+
| undefined;
|
|
586
|
+
},
|
|
587
|
+
): AuthMethod<
|
|
588
|
+
Identifier,
|
|
589
|
+
SetupSchema,
|
|
590
|
+
InputSchema,
|
|
591
|
+
MaterialSchema,
|
|
592
|
+
ValueSchema,
|
|
593
|
+
| TokenRequirements
|
|
594
|
+
| RefreshRequirements
|
|
595
|
+
| PrepareRequirements
|
|
596
|
+
| ResolveRequirements
|
|
597
|
+
| DisplayRequirements
|
|
598
|
+
| TestRequirements
|
|
599
|
+
> => {
|
|
600
|
+
validateIdentifier("auth-method", identifier);
|
|
601
|
+
|
|
602
|
+
return Object.assign(Object.create(Proto), {
|
|
603
|
+
description: options.description,
|
|
604
|
+
display: options.display,
|
|
605
|
+
identifier,
|
|
606
|
+
input: options.input,
|
|
607
|
+
kind: options.kind,
|
|
608
|
+
material: options.material,
|
|
609
|
+
name: options.name,
|
|
610
|
+
oauth2: options.oauth2,
|
|
611
|
+
prepare: options.prepare,
|
|
612
|
+
refresh: options.refresh,
|
|
613
|
+
resolve: options.resolve,
|
|
614
|
+
schema: options.value,
|
|
615
|
+
setup: options.setup,
|
|
616
|
+
test: options.test,
|
|
617
|
+
value: options.value,
|
|
618
|
+
});
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* Create an {@link AuthMethod} definition.
|
|
623
|
+
*
|
|
624
|
+
* @since 0.0.0
|
|
625
|
+
* @category constructors
|
|
626
|
+
*/
|
|
627
|
+
export const make = <
|
|
628
|
+
const Identifier extends string,
|
|
629
|
+
ValueSchema extends Schema.Top,
|
|
630
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
631
|
+
>(
|
|
632
|
+
identifier: Identifier,
|
|
633
|
+
options: FormOptions<ValueSchema, SetupSchema>,
|
|
634
|
+
): AuthMethod<Identifier, SetupSchema, ValueSchema, ValueSchema, ValueSchema> =>
|
|
635
|
+
form(identifier, options);
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Create a simple form auth method where input, stored material, and runtime value share one schema.
|
|
639
|
+
*
|
|
640
|
+
* @since 0.0.0
|
|
641
|
+
* @category constructors
|
|
642
|
+
*/
|
|
643
|
+
export const form = <
|
|
644
|
+
const Identifier extends string,
|
|
645
|
+
ValueSchema extends Schema.Top,
|
|
646
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
647
|
+
>(
|
|
648
|
+
identifier: Identifier,
|
|
649
|
+
options: FormOptions<ValueSchema, SetupSchema>,
|
|
650
|
+
): AuthMethod<Identifier, SetupSchema, ValueSchema, ValueSchema, ValueSchema> =>
|
|
651
|
+
makeAuthMethod(identifier, {
|
|
652
|
+
description: options.description,
|
|
653
|
+
display: undefined,
|
|
654
|
+
input: options.schema,
|
|
655
|
+
kind: "form",
|
|
656
|
+
material: options.schema,
|
|
657
|
+
name: options.name,
|
|
658
|
+
oauth2: undefined,
|
|
659
|
+
prepare: undefined,
|
|
660
|
+
refresh: undefined,
|
|
661
|
+
resolve: undefined,
|
|
662
|
+
setup: options.setup as SetupSchema,
|
|
663
|
+
test: undefined,
|
|
664
|
+
value: options.schema,
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Create a custom auth setup method.
|
|
669
|
+
*
|
|
670
|
+
* @since 0.0.0
|
|
671
|
+
* @category constructors
|
|
672
|
+
*/
|
|
673
|
+
export function auth<
|
|
674
|
+
const Identifier extends string,
|
|
675
|
+
InputSchema extends Schema.Top,
|
|
676
|
+
ValueSchema extends Schema.Top = InputSchema,
|
|
677
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
678
|
+
PrepareRequirements = never,
|
|
679
|
+
RefreshRequirements = never,
|
|
680
|
+
ResolveRequirements = never,
|
|
681
|
+
DisplayRequirements = never,
|
|
682
|
+
TestRequirements = never,
|
|
683
|
+
>(
|
|
684
|
+
identifier: Identifier,
|
|
685
|
+
options: AuthOptionsWithoutMaterial<
|
|
686
|
+
InputSchema,
|
|
687
|
+
ValueSchema,
|
|
688
|
+
SetupSchema,
|
|
689
|
+
PrepareRequirements,
|
|
690
|
+
RefreshRequirements,
|
|
691
|
+
ResolveRequirements,
|
|
692
|
+
DisplayRequirements,
|
|
693
|
+
TestRequirements
|
|
694
|
+
>,
|
|
695
|
+
): AuthMethod<
|
|
696
|
+
Identifier,
|
|
697
|
+
SetupSchema,
|
|
698
|
+
InputSchema,
|
|
699
|
+
InputSchema,
|
|
700
|
+
ValueSchema,
|
|
701
|
+
| PrepareRequirements
|
|
702
|
+
| RefreshRequirements
|
|
703
|
+
| ResolveRequirements
|
|
704
|
+
| DisplayRequirements
|
|
705
|
+
| TestRequirements
|
|
706
|
+
>;
|
|
707
|
+
export function auth<
|
|
708
|
+
const Identifier extends string,
|
|
709
|
+
InputSchema extends Schema.Top | undefined,
|
|
710
|
+
MaterialSchema extends Schema.Top,
|
|
711
|
+
ValueSchema extends Schema.Top = MaterialSchema,
|
|
712
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
713
|
+
PrepareRequirements = never,
|
|
714
|
+
RefreshRequirements = never,
|
|
715
|
+
ResolveRequirements = never,
|
|
716
|
+
DisplayRequirements = never,
|
|
717
|
+
TestRequirements = never,
|
|
718
|
+
>(
|
|
719
|
+
identifier: Identifier,
|
|
720
|
+
options: AuthOptionsWithMaterial<
|
|
721
|
+
InputSchema,
|
|
722
|
+
MaterialSchema,
|
|
723
|
+
ValueSchema,
|
|
724
|
+
SetupSchema,
|
|
725
|
+
PrepareRequirements,
|
|
726
|
+
RefreshRequirements,
|
|
727
|
+
ResolveRequirements,
|
|
728
|
+
DisplayRequirements,
|
|
729
|
+
TestRequirements
|
|
730
|
+
>,
|
|
731
|
+
): AuthMethod<
|
|
732
|
+
Identifier,
|
|
733
|
+
SetupSchema,
|
|
734
|
+
InputSchema,
|
|
735
|
+
MaterialSchema,
|
|
736
|
+
ValueSchema,
|
|
737
|
+
| PrepareRequirements
|
|
738
|
+
| RefreshRequirements
|
|
739
|
+
| ResolveRequirements
|
|
740
|
+
| DisplayRequirements
|
|
741
|
+
| TestRequirements
|
|
742
|
+
>;
|
|
743
|
+
export function auth(
|
|
744
|
+
identifier: string,
|
|
745
|
+
options:
|
|
746
|
+
| AuthOptionsWithoutMaterial<Schema.Top, Schema.Top, any, any, any, any, any, any>
|
|
747
|
+
| AuthOptionsWithMaterial<
|
|
748
|
+
Schema.Top | undefined,
|
|
749
|
+
Schema.Top,
|
|
750
|
+
Schema.Top,
|
|
751
|
+
any,
|
|
752
|
+
any,
|
|
753
|
+
any,
|
|
754
|
+
any,
|
|
755
|
+
any,
|
|
756
|
+
any
|
|
757
|
+
>,
|
|
758
|
+
): Any {
|
|
759
|
+
const material = options.material ?? options.input;
|
|
760
|
+
if (material === undefined) {
|
|
761
|
+
throw new Error(`auth method "${identifier}" requires material when input is omitted`);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
return makeAuthMethod(identifier, {
|
|
765
|
+
description: options.description,
|
|
766
|
+
display: options.display,
|
|
767
|
+
input: options.input,
|
|
768
|
+
kind: "custom",
|
|
769
|
+
material,
|
|
770
|
+
name: options.name,
|
|
771
|
+
oauth2: undefined,
|
|
772
|
+
prepare: options.prepare,
|
|
773
|
+
refresh: options.refresh,
|
|
774
|
+
resolve: options.resolve,
|
|
775
|
+
setup: options.setup,
|
|
776
|
+
test: options.test,
|
|
777
|
+
value: options.value ?? material,
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* Create an OAuth2 auth method over the same setup primitive.
|
|
783
|
+
*
|
|
784
|
+
* OAuth2 has no submitted form input; the platform owns the browser redirect,
|
|
785
|
+
* callback, state/PKCE, and token exchange before storing mapped material.
|
|
786
|
+
*
|
|
787
|
+
* @since 0.0.0
|
|
788
|
+
* @category constructors
|
|
789
|
+
*/
|
|
790
|
+
export const oauth2 = <
|
|
791
|
+
const Identifier extends string,
|
|
792
|
+
MaterialSchema extends Schema.Top,
|
|
793
|
+
ValueSchema extends Schema.Top = MaterialSchema,
|
|
794
|
+
SetupSchema extends Schema.Top | undefined = undefined,
|
|
795
|
+
TokenRequirements = never,
|
|
796
|
+
ResolveRequirements = never,
|
|
797
|
+
DisplayRequirements = never,
|
|
798
|
+
TestRequirements = never,
|
|
799
|
+
>(
|
|
800
|
+
identifier: Identifier,
|
|
801
|
+
options: OAuth2Options<
|
|
802
|
+
MaterialSchema,
|
|
803
|
+
ValueSchema,
|
|
804
|
+
SetupSchema,
|
|
805
|
+
TokenRequirements,
|
|
806
|
+
ResolveRequirements,
|
|
807
|
+
DisplayRequirements,
|
|
808
|
+
TestRequirements
|
|
809
|
+
>,
|
|
810
|
+
): AuthMethod<
|
|
811
|
+
Identifier,
|
|
812
|
+
SetupSchema,
|
|
813
|
+
undefined,
|
|
814
|
+
MaterialSchema,
|
|
815
|
+
ValueSchema,
|
|
816
|
+
// The built-in oauth2 refresh path needs the token refresher service and
|
|
817
|
+
// re-decodes refreshed material, so those join the user hook requirements.
|
|
818
|
+
| OAuth2TokenRefresher.Service
|
|
819
|
+
| Schema.Codec.DecodingServices<MaterialSchema>
|
|
820
|
+
| TokenRequirements
|
|
821
|
+
| ResolveRequirements
|
|
822
|
+
| DisplayRequirements
|
|
823
|
+
| TestRequirements
|
|
824
|
+
> => {
|
|
825
|
+
const oauth2Setup: OAuth2Setup<MaterialSchema, SchemaType<SetupSchema>, TokenRequirements> = {
|
|
826
|
+
client: options.client,
|
|
827
|
+
scopes: options.scopes,
|
|
828
|
+
...(options.discoveryUrl === undefined ? {} : { discoveryUrl: options.discoveryUrl }),
|
|
829
|
+
...(options.authorizationUrl === undefined
|
|
830
|
+
? {}
|
|
831
|
+
: { authorizationUrl: options.authorizationUrl }),
|
|
832
|
+
...(options.tokenUrl === undefined ? {} : { tokenUrl: options.tokenUrl }),
|
|
833
|
+
...(options.pkce === undefined ? {} : { pkce: options.pkce }),
|
|
834
|
+
...(options.authorizationParams === undefined
|
|
835
|
+
? {}
|
|
836
|
+
: { authorizationParams: options.authorizationParams }),
|
|
837
|
+
...(options.tokenParams === undefined ? {} : { tokenParams: options.tokenParams }),
|
|
838
|
+
...(options.tokenHeaders === undefined ? {} : { tokenHeaders: options.tokenHeaders }),
|
|
839
|
+
...(options.tokenRequestEncoding === undefined
|
|
840
|
+
? {}
|
|
841
|
+
: { tokenRequestEncoding: options.tokenRequestEncoding }),
|
|
842
|
+
...(options.tokenResponse === undefined ? {} : { tokenResponse: options.tokenResponse }),
|
|
843
|
+
...(options.fromTokens === undefined ? {} : { fromTokens: options.fromTokens }),
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
return makeAuthMethod(identifier, {
|
|
847
|
+
description: options.description,
|
|
848
|
+
display: options.display,
|
|
849
|
+
input: undefined,
|
|
850
|
+
kind: "oauth2",
|
|
851
|
+
material: options.material,
|
|
852
|
+
name: options.name,
|
|
853
|
+
oauth2: oauth2Setup,
|
|
854
|
+
prepare: undefined,
|
|
855
|
+
refresh: undefined,
|
|
856
|
+
resolve: options.resolve,
|
|
857
|
+
setup: options.setup as SetupSchema,
|
|
858
|
+
test: options.test,
|
|
859
|
+
value: (options.value ?? options.material) as ValueSchema,
|
|
860
|
+
});
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Check if a value is an {@link AuthMethod}.
|
|
865
|
+
*
|
|
866
|
+
* @since 0.0.0
|
|
867
|
+
* @category guards
|
|
868
|
+
*/
|
|
869
|
+
export const isAuthMethod = (u: unknown): u is Any => Predicate.hasProperty(u, TypeId);
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Resolved value type carried by a {@link AuthMethod}.
|
|
873
|
+
*
|
|
874
|
+
* @since 0.0.0
|
|
875
|
+
* @category type-level
|
|
876
|
+
*/
|
|
877
|
+
export type Value<Method extends Any> = Schema.Schema.Type<ValueSchema<Method>>;
|
|
878
|
+
|
|
879
|
+
/** @since 0.0.0 @category type-level */
|
|
880
|
+
export type Setup<Method extends Any> = SchemaType<SetupSchema<Method>>;
|
|
881
|
+
|
|
882
|
+
/**
|
|
883
|
+
* Submitted setup input type carried by an {@link AuthMethod}.
|
|
884
|
+
*
|
|
885
|
+
* @since 0.0.0
|
|
886
|
+
* @category type-level
|
|
887
|
+
*/
|
|
888
|
+
export type Input<Method extends Any> = SchemaType<InputSchema<Method>>;
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Encrypted stored material type carried by an {@link AuthMethod}.
|
|
892
|
+
*
|
|
893
|
+
* @since 0.0.0
|
|
894
|
+
* @category type-level
|
|
895
|
+
*/
|
|
896
|
+
export type Material<Method extends Any> = Schema.Schema.Type<MaterialSchema<Method>>;
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Schema type carried by a {@link AuthMethod}.
|
|
900
|
+
*
|
|
901
|
+
* @since 0.0.0
|
|
902
|
+
* @category type-level
|
|
903
|
+
*/
|
|
904
|
+
export type ValueSchema<Method extends Any> = Method["value"];
|
|
905
|
+
|
|
906
|
+
/** @since 0.0.0 @category type-level */
|
|
907
|
+
export type SetupSchema<Method extends Any> = Method["setup"];
|
|
908
|
+
|
|
909
|
+
/** @since 0.0.0 @category type-level */
|
|
910
|
+
export type InputSchema<Method extends Any> = Method["input"];
|
|
911
|
+
|
|
912
|
+
/** @since 0.0.0 @category type-level */
|
|
913
|
+
export type MaterialSchema<Method extends Any> = Method["material"];
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Services required by the method's hooks, as one union.
|
|
917
|
+
*
|
|
918
|
+
* @since 0.0.0
|
|
919
|
+
* @category type-level
|
|
920
|
+
*/
|
|
921
|
+
export type Requirements<Method extends Any> = Types.Covariant.Type<
|
|
922
|
+
Method[TypeId]["_Requirements"]
|
|
923
|
+
>;
|
|
924
|
+
|
|
925
|
+
// Compatibility exports keep the original AuthMethod namespace intact while
|
|
926
|
+
// focused callers can import each runtime module directly.
|
|
927
|
+
export {
|
|
928
|
+
type Binding,
|
|
929
|
+
type BindingFor,
|
|
930
|
+
type BindingForMethod,
|
|
931
|
+
type MatchCases,
|
|
932
|
+
type Context,
|
|
933
|
+
makeBinding,
|
|
934
|
+
isBindingForMethod,
|
|
935
|
+
} from "./AuthMethodBinding.ts";
|
|
936
|
+
export {
|
|
937
|
+
decodeValue,
|
|
938
|
+
decodeSetup,
|
|
939
|
+
decodeInput,
|
|
940
|
+
decodeMaterial,
|
|
941
|
+
prepareDecoded,
|
|
942
|
+
prepareUnknown,
|
|
943
|
+
prepare,
|
|
944
|
+
refreshDecoded,
|
|
945
|
+
refreshUnknown,
|
|
946
|
+
prepareOAuth2Tokens,
|
|
947
|
+
resolveDecoded,
|
|
948
|
+
resolve,
|
|
949
|
+
resolveUnknown,
|
|
950
|
+
display,
|
|
951
|
+
test,
|
|
952
|
+
} from "./AuthMethodExecution.ts";
|
|
953
|
+
export { Service } from "./OAuth2TokenRefresher.ts";
|
|
954
|
+
export * as OAuth2TokenRefresher from "./OAuth2TokenRefresher.ts";
|