Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3import { IsoDateTime, TrimmedNonEmptyString } from "./baseSchemas.ts";
4import { ProviderDriverKind, ProviderInstanceId } from "./providerInstance.ts";
5
6export const ProviderSetupInput = Schema.Struct({
7 instanceId: ProviderInstanceId,
8});
9export type ProviderSetupInput = typeof ProviderSetupInput.Type;
10
11const SetupOperationId = TrimmedNonEmptyString.check(Schema.isMaxLength(128));
12
13export const ProviderAuthState = Schema.Struct({
14 instanceId: ProviderInstanceId,
15 phase: Schema.Literals([
16 "idle",
17 "starting",
18 "waiting",
19 "verifying",
20 "succeeded",
21 "failed",
22 "cancelled",
23 ]),
24 flowId: Schema.NullOr(SetupOperationId),
25 authorizationUrl: Schema.NullOr(Schema.String),
26 expiresAt: Schema.NullOr(IsoDateTime),
27 message: Schema.NullOr(Schema.String),
28});
29export type ProviderAuthState = typeof ProviderAuthState.Type;
30
31export const ProviderAuthCompleteInput = Schema.Struct({
32 instanceId: ProviderInstanceId,
33 flowId: SetupOperationId,
34 callbackUrl: TrimmedNonEmptyString.check(Schema.isMaxLength(16_384)),
35});
36export type ProviderAuthCompleteInput = typeof ProviderAuthCompleteInput.Type;
37
38export const ProviderAuthCancelInput = Schema.Struct({
39 instanceId: ProviderInstanceId,
40 flowId: SetupOperationId,
41});
42export type ProviderAuthCancelInput = typeof ProviderAuthCancelInput.Type;
43
44const ByteCount = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
45
46export const ProviderInstallState = Schema.Struct({
47 driver: ProviderDriverKind,
48 operationId: Schema.NullOr(SetupOperationId),
49 phase: Schema.Literals([
50 "idle",
51 "downloading",
52 "extracting",
53 "verifying",
54 "succeeded",
55 "failed",
56 "cancelled",
57 ]),
58 downloadedBytes: ByteCount,
59 totalBytes: Schema.NullOr(ByteCount),
60 version: Schema.NullOr(TrimmedNonEmptyString),
61 installedVersion: Schema.NullOr(TrimmedNonEmptyString),
62 canRemove: Schema.Boolean,
63 message: Schema.NullOr(Schema.String),
64});
65export type ProviderInstallState = typeof ProviderInstallState.Type;
66
67export const ProviderInstallCancelInput = Schema.Struct({
68 instanceId: ProviderInstanceId,
69 operationId: SetupOperationId,
70});
71export type ProviderInstallCancelInput = typeof ProviderInstallCancelInput.Type;
72
73/** Safe setup failure text. Never include OAuth codes, URLs, or native token data. */
74export class ProviderSetupError extends Schema.TaggedError<ProviderSetupError>()(
75 "ProviderSetupError",
76 {
77 instanceId: ProviderInstanceId,
78 operation: Schema.String,
79 detail: Schema.String,
80 cause: Schema.optional(Schema.Defect()),
81 },
82) {
83 override get message(): string {
84 return this.detail;
85 }
86}