expandai 0.0.2 → 0.0.3
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/README.md +42 -5
- package/build/dts/ApiClient.d.ts +128 -194
- package/build/dts/ApiClient.d.ts.map +1 -1
- package/build/dts/Auth/Domain.d.ts +95 -0
- package/build/dts/Auth/Domain.d.ts.map +1 -0
- package/build/dts/Auth/ManualAuthorization.d.ts +107 -0
- package/build/dts/Auth/ManualAuthorization.d.ts.map +1 -0
- package/build/dts/Auth/PendingInit.d.ts +35 -0
- package/build/dts/Auth/PendingInit.d.ts.map +1 -0
- package/build/dts/Auth/Pkce.d.ts +10 -0
- package/build/dts/Auth/Pkce.d.ts.map +1 -0
- package/build/dts/Auth/SetupGrantAuthorization.d.ts +34 -0
- package/build/dts/Auth/SetupGrantAuthorization.d.ts.map +1 -0
- package/build/dts/Authentication.d.ts +10 -9
- package/build/dts/Authentication.d.ts.map +1 -1
- package/build/dts/BrowserOAuth.d.ts +7 -7
- package/build/dts/BrowserOAuth.d.ts.map +1 -1
- package/build/dts/CommandPath.d.ts +2 -0
- package/build/dts/CommandPath.d.ts.map +1 -0
- package/build/dts/Commands/Fetch.d.ts.map +1 -1
- package/build/dts/Commands/Hook.d.ts +5 -5
- package/build/dts/Commands/Init.d.ts +55 -0
- package/build/dts/Commands/Init.d.ts.map +1 -0
- package/build/dts/Commands/Mcp.d.ts +6 -6
- package/build/dts/Commands/Search.d.ts.map +1 -1
- package/build/dts/Commands/Skill.d.ts +4 -4
- package/build/dts/Commands/Status.d.ts +27 -0
- package/build/dts/Commands/Status.d.ts.map +1 -0
- package/build/dts/Commands/Telemetry.d.ts +7 -0
- package/build/dts/Commands/Telemetry.d.ts.map +1 -0
- package/build/dts/Commands/Uninstall.d.ts +4 -4
- package/build/dts/Config.d.ts +108 -17
- package/build/dts/Config.d.ts.map +1 -1
- package/build/dts/Hook/SnapshotNote.d.ts +8 -4
- package/build/dts/Hook/SnapshotNote.d.ts.map +1 -1
- package/build/dts/Init/ClaudeAdapter.d.ts +61 -0
- package/build/dts/Init/ClaudeAdapter.d.ts.map +1 -0
- package/build/dts/Init/ClaudeProfile.d.ts +78 -0
- package/build/dts/Init/ClaudeProfile.d.ts.map +1 -0
- package/build/dts/Init/Domain.d.ts +139 -0
- package/build/dts/Init/Domain.d.ts.map +1 -0
- package/build/dts/Init/HarnessAdapter.d.ts +33 -0
- package/build/dts/Init/HarnessAdapter.d.ts.map +1 -0
- package/build/dts/Init/HarnessDetector.d.ts +19 -0
- package/build/dts/Init/HarnessDetector.d.ts.map +1 -0
- package/build/dts/Init/HarnessRegistry.d.ts +50 -0
- package/build/dts/Init/HarnessRegistry.d.ts.map +1 -0
- package/build/dts/Init/MutationTransaction.d.ts +96 -0
- package/build/dts/Init/MutationTransaction.d.ts.map +1 -0
- package/build/dts/Init/Service.d.ts +72 -0
- package/build/dts/Init/Service.d.ts.map +1 -0
- package/build/dts/Init/StandardAdapters.d.ts +42 -0
- package/build/dts/Init/StandardAdapters.d.ts.map +1 -0
- package/build/dts/Init/Status.d.ts +149 -0
- package/build/dts/Init/Status.d.ts.map +1 -0
- package/build/dts/Install/Claude/Hook.d.ts +85 -25
- package/build/dts/Install/Claude/Hook.d.ts.map +1 -1
- package/build/dts/Install/Claude/Mcp.d.ts +21 -18
- package/build/dts/Install/Claude/Mcp.d.ts.map +1 -1
- package/build/dts/Install/Claude/Skill.d.ts +14 -15
- package/build/dts/Install/Claude/Skill.d.ts.map +1 -1
- package/build/dts/Install/Codex/Mcp.d.ts +14 -8
- package/build/dts/Install/Codex/Mcp.d.ts.map +1 -1
- package/build/dts/Install/Codex/Skill.d.ts +4 -2
- package/build/dts/Install/Codex/Skill.d.ts.map +1 -1
- package/build/dts/Install/Cursor/Mcp.d.ts +13 -13
- package/build/dts/Install/Cursor/Mcp.d.ts.map +1 -1
- package/build/dts/Install/Cursor/Skill.d.ts +4 -2
- package/build/dts/Install/Cursor/Skill.d.ts.map +1 -1
- package/build/dts/Install/Domain.d.ts +35 -5
- package/build/dts/Install/Domain.d.ts.map +1 -1
- package/build/dts/Install/Hook.d.ts +4 -4
- package/build/dts/Install/Hook.d.ts.map +1 -1
- package/build/dts/Install/Mcp.d.ts +5 -5
- package/build/dts/Install/Mcp.d.ts.map +1 -1
- package/build/dts/Install/Opencode/Hook.d.ts +4 -3
- package/build/dts/Install/Opencode/Hook.d.ts.map +1 -1
- package/build/dts/Install/Opencode/Mcp.d.ts +11 -11
- package/build/dts/Install/Opencode/Mcp.d.ts.map +1 -1
- package/build/dts/Install/Opencode/Skill.d.ts +4 -2
- package/build/dts/Install/Opencode/Skill.d.ts.map +1 -1
- package/build/dts/Install/Skill.d.ts +3 -3
- package/build/dts/Install/Uninstall.d.ts +6 -6
- package/build/dts/Install/Uninstall.d.ts.map +1 -1
- package/build/dts/MarkdownAnsi.d.ts +29 -0
- package/build/dts/MarkdownAnsi.d.ts.map +1 -0
- package/build/dts/Mcp/ExpandDocs.d.ts +17 -5
- package/build/dts/Mcp/ExpandDocs.d.ts.map +1 -1
- package/build/dts/Mcp/Server.d.ts +1 -1
- package/build/dts/Mcp/Server.d.ts.map +1 -1
- package/build/dts/Mcp/tools/Citations.d.ts +100 -71
- package/build/dts/Mcp/tools/Citations.d.ts.map +1 -1
- package/build/dts/Mcp/tools/Fetch.d.ts +16 -15
- package/build/dts/Mcp/tools/Fetch.d.ts.map +1 -1
- package/build/dts/SecureFile.d.ts +23 -0
- package/build/dts/SecureFile.d.ts.map +1 -0
- package/build/dts/Snippets.d.ts +11 -12
- package/build/dts/Snippets.d.ts.map +1 -1
- package/build/dts/Telemetry.d.ts +30 -0
- package/build/dts/Telemetry.d.ts.map +1 -0
- package/build/dts/Version.d.ts +2 -0
- package/build/dts/Version.d.ts.map +1 -0
- package/build/dts/Xdg.d.ts +11 -0
- package/build/dts/Xdg.d.ts.map +1 -0
- package/build/esm/ApiClient.js +133 -10
- package/build/esm/ApiClient.js.map +1 -1
- package/build/esm/Auth/Domain.js +56 -0
- package/build/esm/Auth/Domain.js.map +1 -0
- package/build/esm/Auth/ManualAuthorization.js +253 -0
- package/build/esm/Auth/ManualAuthorization.js.map +1 -0
- package/build/esm/Auth/PendingInit.js +267 -0
- package/build/esm/Auth/PendingInit.js.map +1 -0
- package/build/esm/Auth/Pkce.js +23 -0
- package/build/esm/Auth/Pkce.js.map +1 -0
- package/build/esm/Auth/SetupGrantAuthorization.js +91 -0
- package/build/esm/Auth/SetupGrantAuthorization.js.map +1 -0
- package/build/esm/Authentication.js +38 -7
- package/build/esm/Authentication.js.map +1 -1
- package/build/esm/BrowserOAuth.js +7 -10
- package/build/esm/BrowserOAuth.js.map +1 -1
- package/build/esm/CommandPath.js +31 -0
- package/build/esm/CommandPath.js.map +1 -0
- package/build/esm/Commands/Fetch.js +30 -6
- package/build/esm/Commands/Fetch.js.map +1 -1
- package/build/esm/Commands/Init.js +371 -0
- package/build/esm/Commands/Init.js.map +1 -0
- package/build/esm/Commands/Search.js +6 -3
- package/build/esm/Commands/Search.js.map +1 -1
- package/build/esm/Commands/Status.js +186 -0
- package/build/esm/Commands/Status.js.map +1 -0
- package/build/esm/Commands/Telemetry.js +23 -0
- package/build/esm/Commands/Telemetry.js.map +1 -0
- package/build/esm/Config.js +502 -28
- package/build/esm/Config.js.map +1 -1
- package/build/esm/Hook/Claude.js +1 -1
- package/build/esm/Hook/Claude.js.map +1 -1
- package/build/esm/Hook/SnapshotNote.js +54 -7
- package/build/esm/Hook/SnapshotNote.js.map +1 -1
- package/build/esm/Init/ClaudeAdapter.js +137 -0
- package/build/esm/Init/ClaudeAdapter.js.map +1 -0
- package/build/esm/Init/ClaudeProfile.js +380 -0
- package/build/esm/Init/ClaudeProfile.js.map +1 -0
- package/build/esm/Init/Domain.js +118 -0
- package/build/esm/Init/Domain.js.map +1 -0
- package/build/esm/Init/HarnessAdapter.js +21 -0
- package/build/esm/Init/HarnessAdapter.js.map +1 -0
- package/build/esm/Init/HarnessDetector.js +65 -0
- package/build/esm/Init/HarnessDetector.js.map +1 -0
- package/build/esm/Init/HarnessRegistry.js +58 -0
- package/build/esm/Init/HarnessRegistry.js.map +1 -0
- package/build/esm/Init/MutationTransaction.js +494 -0
- package/build/esm/Init/MutationTransaction.js.map +1 -0
- package/build/esm/Init/Service.js +319 -0
- package/build/esm/Init/Service.js.map +1 -0
- package/build/esm/Init/StandardAdapters.js +116 -0
- package/build/esm/Init/StandardAdapters.js.map +1 -0
- package/build/esm/Init/Status.js +215 -0
- package/build/esm/Init/Status.js.map +1 -0
- package/build/esm/Install/Claude/Hook.js +182 -50
- package/build/esm/Install/Claude/Hook.js.map +1 -1
- package/build/esm/Install/Claude/Mcp.js +56 -26
- package/build/esm/Install/Claude/Mcp.js.map +1 -1
- package/build/esm/Install/Claude/Skill.js +49 -27
- package/build/esm/Install/Claude/Skill.js.map +1 -1
- package/build/esm/Install/Codex/Mcp.js +9 -4
- package/build/esm/Install/Codex/Mcp.js.map +1 -1
- package/build/esm/Install/Codex/Skill.js +4 -1
- package/build/esm/Install/Codex/Skill.js.map +1 -1
- package/build/esm/Install/Cursor/Mcp.js +7 -4
- package/build/esm/Install/Cursor/Mcp.js.map +1 -1
- package/build/esm/Install/Cursor/Skill.js +4 -1
- package/build/esm/Install/Cursor/Skill.js.map +1 -1
- package/build/esm/Install/Domain.js +60 -3
- package/build/esm/Install/Domain.js.map +1 -1
- package/build/esm/Install/Hook.js.map +1 -1
- package/build/esm/Install/Mcp.js +1 -1
- package/build/esm/Install/Mcp.js.map +1 -1
- package/build/esm/Install/Opencode/Hook.js +1 -1
- package/build/esm/Install/Opencode/Hook.js.map +1 -1
- package/build/esm/Install/Opencode/Mcp.js +6 -3
- package/build/esm/Install/Opencode/Mcp.js.map +1 -1
- package/build/esm/Install/Opencode/Skill.js +4 -1
- package/build/esm/Install/Opencode/Skill.js.map +1 -1
- package/build/esm/Install/Opencode/expandai-webfetch.js +27 -9
- package/build/esm/Install/Skill.js.map +1 -1
- package/build/esm/Install/Uninstall.js +2 -2
- package/build/esm/Install/Uninstall.js.map +1 -1
- package/build/esm/MarkdownAnsi.js +142 -0
- package/build/esm/MarkdownAnsi.js.map +1 -0
- package/build/esm/Mcp/ExpandDocs.js +44 -52
- package/build/esm/Mcp/ExpandDocs.js.map +1 -1
- package/build/esm/Mcp/RequestHeaders.js.map +1 -1
- package/build/esm/Mcp/Server.js +2 -1
- package/build/esm/Mcp/Server.js.map +1 -1
- package/build/esm/Mcp/tools/Citations.js +109 -8
- package/build/esm/Mcp/tools/Citations.js.map +1 -1
- package/build/esm/Mcp/tools/Fetch.js +36 -12
- package/build/esm/Mcp/tools/Fetch.js.map +1 -1
- package/build/esm/SecureFile.js +36 -0
- package/build/esm/SecureFile.js.map +1 -0
- package/build/esm/Snippets.js +12 -1
- package/build/esm/Snippets.js.map +1 -1
- package/build/esm/Telemetry.js +157 -0
- package/build/esm/Telemetry.js.map +1 -0
- package/build/esm/Version.js +4 -0
- package/build/esm/Version.js.map +1 -0
- package/build/esm/Xdg.js +15 -0
- package/build/esm/Xdg.js.map +1 -0
- package/build/esm/main.js +122 -14
- package/build/esm/main.js.map +1 -1
- package/build/skills/expandai/SKILL.md +26 -3
- package/package.json +4 -4
- package/src/ApiClient.ts +206 -13
- package/src/Auth/Domain.ts +63 -0
- package/src/Auth/ManualAuthorization.ts +296 -0
- package/src/Auth/PendingInit.ts +338 -0
- package/src/Auth/Pkce.ts +26 -0
- package/src/Auth/SetupGrantAuthorization.ts +116 -0
- package/src/Authentication.ts +49 -11
- package/src/BrowserOAuth.ts +10 -12
- package/src/CommandPath.ts +30 -0
- package/src/Commands/Fetch.ts +42 -11
- package/src/Commands/Init.ts +489 -0
- package/src/Commands/Search.ts +8 -3
- package/src/Commands/Status.ts +228 -0
- package/src/Commands/Telemetry.ts +42 -0
- package/src/Config.ts +695 -50
- package/src/Hook/Claude.ts +1 -1
- package/src/Hook/SnapshotNote.ts +55 -7
- package/src/Init/ClaudeAdapter.ts +191 -0
- package/src/Init/ClaudeProfile.ts +496 -0
- package/src/Init/Domain.ts +153 -0
- package/src/Init/HarnessAdapter.ts +35 -0
- package/src/Init/HarnessDetector.ts +77 -0
- package/src/Init/HarnessRegistry.ts +87 -0
- package/src/Init/MutationTransaction.ts +747 -0
- package/src/Init/Service.ts +385 -0
- package/src/Init/StandardAdapters.ts +141 -0
- package/src/Init/Status.ts +253 -0
- package/src/Install/Claude/Hook.ts +234 -81
- package/src/Install/Claude/Mcp.ts +80 -33
- package/src/Install/Claude/Skill.ts +70 -37
- package/src/Install/Codex/Mcp.ts +14 -9
- package/src/Install/Codex/Skill.ts +9 -5
- package/src/Install/Cursor/Mcp.ts +12 -9
- package/src/Install/Cursor/Skill.ts +9 -5
- package/src/Install/Domain.ts +77 -4
- package/src/Install/Hook.ts +3 -3
- package/src/Install/Mcp.ts +6 -6
- package/src/Install/Opencode/Hook.ts +5 -5
- package/src/Install/Opencode/Mcp.ts +11 -8
- package/src/Install/Opencode/Skill.ts +9 -5
- package/src/Install/Opencode/expandai-webfetch.js +27 -9
- package/src/Install/Skill.ts +3 -3
- package/src/Install/Uninstall.ts +3 -3
- package/src/MarkdownAnsi.ts +162 -0
- package/src/Mcp/ExpandDocs.ts +46 -55
- package/src/Mcp/Server.ts +2 -1
- package/src/Mcp/tools/Citations.ts +117 -8
- package/src/Mcp/tools/Fetch.ts +40 -14
- package/src/SecureFile.ts +70 -0
- package/src/Snippets.ts +19 -12
- package/src/Telemetry.ts +186 -0
- package/src/Version.ts +3 -0
- package/src/Xdg.ts +18 -0
- package/src/main.ts +171 -12
- package/build/dts/DeviceAuth.d.ts +0 -87
- package/build/dts/DeviceAuth.d.ts.map +0 -1
- package/build/esm/DeviceAuth.js +0 -127
- package/build/esm/DeviceAuth.js.map +0 -1
- package/src/DeviceAuth.ts +0 -193
package/src/DeviceAuth.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { HttpClient, HttpClientRequest, HttpClientResponse } from '@effect/platform'
|
|
2
|
-
import { NodeHttpClient } from '@effect/platform-node'
|
|
3
|
-
import { DateTime, Duration, Effect, Inspectable, Match, Option, Redacted, Ref, Schema, String } from 'effect'
|
|
4
|
-
import { ConfigManager, OAuthConfig } from './Config.js'
|
|
5
|
-
|
|
6
|
-
const FormattedUserCode = Schema.transform(Schema.String, Schema.String, {
|
|
7
|
-
strict: true,
|
|
8
|
-
decode: (raw) => {
|
|
9
|
-
const upper = String.toUpperCase(raw)
|
|
10
|
-
return upper.length > 4 ? `${String.takeLeft(upper, 4)}-${String.takeRight(upper, upper.length - 4)}` : upper
|
|
11
|
-
},
|
|
12
|
-
encode: (formatted) => formatted.replace('-', ''),
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
const DurationFromSeconds = Schema.transform(Schema.Number, Schema.DurationFromSelf, {
|
|
16
|
-
strict: true,
|
|
17
|
-
decode: Duration.seconds,
|
|
18
|
-
encode: Duration.toSeconds,
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
export class DeviceCodeResponse extends Schema.Class<DeviceCodeResponse>('DeviceCodeResponse')({
|
|
22
|
-
device_code: Schema.String,
|
|
23
|
-
user_code: FormattedUserCode,
|
|
24
|
-
verification_uri: Schema.String,
|
|
25
|
-
verification_uri_complete: Schema.String,
|
|
26
|
-
expires_in: DurationFromSeconds,
|
|
27
|
-
interval: DurationFromSeconds,
|
|
28
|
-
}) {}
|
|
29
|
-
|
|
30
|
-
export class TokenResponse extends Schema.Class<TokenResponse>('TokenResponse')({
|
|
31
|
-
access_token: Schema.String,
|
|
32
|
-
expires_in: DurationFromSeconds,
|
|
33
|
-
token_type: Schema.String,
|
|
34
|
-
scope: Schema.optional(Schema.String),
|
|
35
|
-
}) {}
|
|
36
|
-
|
|
37
|
-
export class DeviceAuthRequestFailed extends Schema.TaggedError<DeviceAuthRequestFailed>()('DeviceAuthRequestFailed', {
|
|
38
|
-
endpoint: Schema.String,
|
|
39
|
-
error: Schema.Defect,
|
|
40
|
-
status: Schema.optional(Schema.Number),
|
|
41
|
-
}) {
|
|
42
|
-
get message() {
|
|
43
|
-
return `Device auth request to ${this.endpoint} failed${this.status ? ` (${this.status})` : ''}: ${Inspectable.format(this.error)}`
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export class DeviceAuthorizationDenied extends Schema.TaggedError<DeviceAuthorizationDenied>()(
|
|
48
|
-
'DeviceAuthorizationDenied',
|
|
49
|
-
{},
|
|
50
|
-
) {
|
|
51
|
-
get message() {
|
|
52
|
-
return 'Authorization was denied by the user'
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class DeviceAuthorizationExpired extends Schema.TaggedError<DeviceAuthorizationExpired>()(
|
|
57
|
-
'DeviceAuthorizationExpired',
|
|
58
|
-
{},
|
|
59
|
-
) {
|
|
60
|
-
get message() {
|
|
61
|
-
return 'Device authorization code expired'
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const CLIENT_ID = 'expandai-cli'
|
|
66
|
-
|
|
67
|
-
export class DeviceAuthService extends Effect.Service<DeviceAuthService>()('@expandai/cli/DeviceAuthService', {
|
|
68
|
-
dependencies: [NodeHttpClient.layer, ConfigManager.Default],
|
|
69
|
-
effect: Effect.gen(function* () {
|
|
70
|
-
const httpClient = yield* HttpClient.HttpClient
|
|
71
|
-
const configManager = yield* ConfigManager
|
|
72
|
-
const apiUrl = yield* configManager.getApiUrl()
|
|
73
|
-
|
|
74
|
-
const requestDeviceCode = Effect.fn('DeviceAuthService.requestDeviceCode')(function* () {
|
|
75
|
-
const DEVICE_AUTH_CODE_ENDPOINT = '/api/auth/device/code'
|
|
76
|
-
|
|
77
|
-
const request = yield* HttpClientRequest.post(new URL(DEVICE_AUTH_CODE_ENDPOINT, apiUrl)).pipe(
|
|
78
|
-
HttpClientRequest.bodyJson({ client_id: CLIENT_ID }),
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
return yield* httpClient.execute(request).pipe(
|
|
82
|
-
Effect.flatMap(HttpClientResponse.schemaBodyJson(DeviceCodeResponse)),
|
|
83
|
-
Effect.mapError(
|
|
84
|
-
(error) =>
|
|
85
|
-
new DeviceAuthRequestFailed({
|
|
86
|
-
endpoint: DEVICE_AUTH_CODE_ENDPOINT,
|
|
87
|
-
error,
|
|
88
|
-
}),
|
|
89
|
-
),
|
|
90
|
-
)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
const pollForToken = Effect.fn('DeviceAuthService.pollForToken')(function* (
|
|
94
|
-
deviceCode: string,
|
|
95
|
-
interval: Duration.Duration,
|
|
96
|
-
expiresIn: Duration.Duration,
|
|
97
|
-
) {
|
|
98
|
-
const DEVICE_AUTH_TOKEN_ENDPOINT = '/api/auth/device/token'
|
|
99
|
-
// RFC 8628 §3.5: on `slow_down`, the polling interval MUST be increased by 5
|
|
100
|
-
// seconds for this and all subsequent requests.
|
|
101
|
-
const SLOW_DOWN_BUMP = Duration.seconds(5)
|
|
102
|
-
const intervalRef = yield* Ref.make(interval)
|
|
103
|
-
|
|
104
|
-
const PollErrorBody = Schema.Struct({
|
|
105
|
-
error: Schema.String,
|
|
106
|
-
error_description: Schema.optional(Schema.String),
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
// better-auth's `deviceAuthorization` plugin accepts JSON; RFC 8628 §3.4
|
|
110
|
-
// would normally require `application/x-www-form-urlencoded`. If we ever
|
|
111
|
-
// target a non-better-auth server, switch to `HttpClientRequest.bodyUrlParams`.
|
|
112
|
-
const singlePoll = HttpClientRequest.post(new URL(DEVICE_AUTH_TOKEN_ENDPOINT, apiUrl)).pipe(
|
|
113
|
-
HttpClientRequest.bodyJson({
|
|
114
|
-
grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
|
|
115
|
-
device_code: deviceCode,
|
|
116
|
-
client_id: CLIENT_ID,
|
|
117
|
-
}),
|
|
118
|
-
Effect.flatMap(httpClient.execute),
|
|
119
|
-
Effect.flatMap(
|
|
120
|
-
HttpClientResponse.matchStatus({
|
|
121
|
-
'200': (response) =>
|
|
122
|
-
HttpClientResponse.schemaBodyJson(TokenResponse)(response).pipe(Effect.map(Option.some)),
|
|
123
|
-
orElse: (response) =>
|
|
124
|
-
HttpClientResponse.schemaBodyJson(PollErrorBody)(response).pipe(
|
|
125
|
-
Effect.flatMap(({ error, error_description }) =>
|
|
126
|
-
Match.value(error).pipe(
|
|
127
|
-
Match.when('authorization_pending', () =>
|
|
128
|
-
Ref.get(intervalRef).pipe(Effect.flatMap(Effect.sleep), Effect.as(Option.none<TokenResponse>())),
|
|
129
|
-
),
|
|
130
|
-
Match.when('slow_down', () =>
|
|
131
|
-
Ref.updateAndGet(intervalRef, (current) => Duration.sum(current, SLOW_DOWN_BUMP)).pipe(
|
|
132
|
-
Effect.flatMap(Effect.sleep),
|
|
133
|
-
Effect.as(Option.none<TokenResponse>()),
|
|
134
|
-
),
|
|
135
|
-
),
|
|
136
|
-
Match.when('access_denied', () => Effect.fail(new DeviceAuthorizationDenied())),
|
|
137
|
-
Match.when('expired_token', () => Effect.fail(new DeviceAuthorizationExpired())),
|
|
138
|
-
Match.orElse(() =>
|
|
139
|
-
Effect.fail(
|
|
140
|
-
new DeviceAuthRequestFailed({
|
|
141
|
-
endpoint: DEVICE_AUTH_TOKEN_ENDPOINT,
|
|
142
|
-
status: response.status,
|
|
143
|
-
error: error_description ?? error,
|
|
144
|
-
}),
|
|
145
|
-
),
|
|
146
|
-
),
|
|
147
|
-
),
|
|
148
|
-
),
|
|
149
|
-
),
|
|
150
|
-
}),
|
|
151
|
-
),
|
|
152
|
-
Effect.catchTags({
|
|
153
|
-
RequestError: (error) => new DeviceAuthRequestFailed({ endpoint: DEVICE_AUTH_TOKEN_ENDPOINT, error }),
|
|
154
|
-
ResponseError: (error) => new DeviceAuthRequestFailed({ endpoint: DEVICE_AUTH_TOKEN_ENDPOINT, error }),
|
|
155
|
-
HttpBodyError: (error) => new DeviceAuthRequestFailed({ endpoint: DEVICE_AUTH_TOKEN_ENDPOINT, error }),
|
|
156
|
-
ParseError: (error) => new DeviceAuthRequestFailed({ endpoint: DEVICE_AUTH_TOKEN_ENDPOINT, error }),
|
|
157
|
-
}),
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
const result = yield* Effect.repeat(singlePoll, { until: Option.isSome }).pipe(
|
|
161
|
-
Effect.timeoutFail({
|
|
162
|
-
duration: expiresIn,
|
|
163
|
-
onTimeout: () => new DeviceAuthorizationExpired(),
|
|
164
|
-
}),
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
return yield* Option.match(result, {
|
|
168
|
-
onNone: () => new DeviceAuthorizationExpired(),
|
|
169
|
-
onSome: Effect.succeed,
|
|
170
|
-
})
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
// INFO: better-auth's `deviceAuthorization` plugin issues access tokens
|
|
174
|
-
// with no refresh flow — `/api/auth/device/token` only accepts
|
|
175
|
-
// `grant_type=urn:ietf:params:oauth:grant-type:device_code`. Refresh is
|
|
176
|
-
// not part of the auth surface we're using, so we don't persist the
|
|
177
|
-
// refresh_token at all; ApiClient pre-empts the post-expiry 401 with
|
|
178
|
-
// `OAuthTokenExpired` and asks the user to re-login.
|
|
179
|
-
const saveToken = Effect.fn('DeviceAuthService.saveToken')(function* (tokenResponse: TokenResponse) {
|
|
180
|
-
const now = yield* DateTime.now
|
|
181
|
-
const expiresAt = DateTime.addDuration(now, tokenResponse.expires_in)
|
|
182
|
-
|
|
183
|
-
yield* configManager.updateConfig({
|
|
184
|
-
authMethod: OAuthConfig.make({
|
|
185
|
-
accessToken: Redacted.make(tokenResponse.access_token),
|
|
186
|
-
expiresAt,
|
|
187
|
-
}),
|
|
188
|
-
})
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
return { requestDeviceCode, pollForToken, saveToken } as const
|
|
192
|
-
}),
|
|
193
|
-
}) {}
|