@desplega.ai/agent-swarm 1.119.5 → 1.120.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.
Files changed (137) hide show
  1. package/dist/{actions-xqb0w6as.js → actions-rym7jyg2.js} +5 -5
  2. package/dist/{app-qv9sy539.js → app-ss3a0nfj.js} +3 -3
  3. package/dist/{assistant-54jkns28.js → assistant-8sd2b21b.js} +8 -8
  4. package/dist/{boot-reembed-m3cpwet0.js → boot-reembed-7bs0d0sj.js} +4 -4
  5. package/dist/{boot-reembed-s0mftrn2.js → boot-reembed-eh18r04f.js} +3 -3
  6. package/dist/{boot-scrub-logs-btj144vd.js → boot-scrub-logs-v8ch000n.js} +2 -2
  7. package/dist/{cli-65anxt77.js → cli-0ap79nha.js} +1 -1
  8. package/dist/{cli-4ntm7f2r.js → cli-0kkggfr9.js} +1 -1
  9. package/dist/{cli-rp04sjbc.js → cli-383wyw2f.js} +277 -3
  10. package/dist/{cli-9rrpjvan.js → cli-4cb3p8pj.js} +2 -2
  11. package/dist/cli-84j2vp67.js +791 -0
  12. package/dist/{cli-xv365pmn.js → cli-d2eyq90a.js} +1 -1
  13. package/dist/{cli-tznnqgnf.js → cli-dnx98dwa.js} +477 -188
  14. package/dist/{cli-zn7x1nkq.js → cli-f6c6y7fw.js} +2 -2
  15. package/dist/cli-gad984jj.js +367 -0
  16. package/dist/{cli-5sexkty0.js → cli-gq12jc1m.js} +4 -1
  17. package/dist/{cli-qh6dfg7b.js → cli-j59bj3vs.js} +5 -5
  18. package/dist/{cli-jcp7f17k.js → cli-kyfx7z3d.js} +4 -4
  19. package/dist/{cli-ctdx3h19.js → cli-kyqs14qe.js} +5 -5
  20. package/dist/{cli-m0aghjk5.js → cli-n745f8e5.js} +2 -2
  21. package/dist/{cli-7h1sce5x.js → cli-py8z9bjq.js} +2120 -1530
  22. package/dist/{cli-3brg2qy0.js → cli-sbh0b9r1.js} +2 -2
  23. package/dist/{cli-hc543pgg.js → cli-shdvvj0n.js} +2 -2
  24. package/dist/{cli-w9jp9sc4.js → cli-t91zbm2s.js} +4 -4
  25. package/dist/{cli-wejdajv9.js → cli-th08nm8p.js} +1 -1
  26. package/dist/{cli-hjpdm93t.js → cli-v65h59hn.js} +1 -1
  27. package/dist/{cli-150bvqyw.js → cli-vmhqfnp1.js} +1 -1
  28. package/dist/{cli-wqfxznva.js → cli-w5em21am.js} +3 -3
  29. package/dist/{cli-86fdnerz.js → cli-wwsaj97q.js} +9 -4
  30. package/dist/{cli-4yby3gz2.js → cli-zxeb2qe3.js} +1 -1
  31. package/dist/{cli-sjvxb0ys.js → cli-zxnp21rf.js} +64 -45
  32. package/dist/cli.js +12 -9
  33. package/dist/{commands-jc6a4g7b.js → commands-w1swgcgg.js} +2 -2
  34. package/dist/{db-5gntqs7z.js → db-yv6y0fxw.js} +2 -2
  35. package/dist/{handlers-jtjhcfec.js → handlers-yjyafdwk.js} +8 -8
  36. package/dist/{hook-d3yspdv9.js → hook-6nvc6p19.js} +1 -1
  37. package/dist/{http-vf5qsq5m.js → http-g6j8rc6h.js} +1027 -513
  38. package/dist/{index-be74p0aj.js → index-64th6eqs.js} +9 -9
  39. package/dist/{index-dh8vf4p5.js → index-7betnvg6.js} +7 -7
  40. package/dist/{index-krp5s3s3.js → index-b2rarbkn.js} +10 -10
  41. package/dist/{index-9t676t5s.js → index-cbknx39k.js} +11 -11
  42. package/dist/{keepalive-p5m5d3g9.js → keepalive-j8c99r3m.js} +17 -13
  43. package/dist/{lead-z4z70dn3.js → lead-8xe71m3s.js} +20 -20
  44. package/dist/{maintenance-n67pnrp0.js → maintenance-eqnmrwb2.js} +4 -4
  45. package/dist/{oauth-refresh-sweep-ygx2e3hv.js → oauth-refresh-sweep-c5dy1653.js} +21 -15
  46. package/dist/{onboard-76fn6mr2.js → onboard-4avg01c1.js} +2 -2
  47. package/dist/{otel-impl-d9vmbspk.js → otel-impl-z4cwkp40.js} +1 -1
  48. package/dist/{pricing-refresh-wn1gbbnc.js → pricing-refresh-dts9429d.js} +4 -4
  49. package/dist/{rbac-roles-gzzmwqyj.js → rbac-roles-24cvsejy.js} +3 -3
  50. package/dist/{rbac-roles-xz80cgy4.js → rbac-roles-4f64wch6.js} +4 -4
  51. package/dist/{seed-pricing-yr9dg75w.js → seed-pricing-74ph9wap.js} +3 -3
  52. package/dist/{setup-g15twpgb.js → setup-9q0n8rvd.js} +2 -2
  53. package/dist/{worker-jdsz3va6.js → worker-x7g344z8.js} +20 -20
  54. package/openapi.json +3433 -2657
  55. package/package.json +4 -1
  56. package/src/be/connection-bindings-blob-migration.ts +123 -0
  57. package/src/be/db-queries/mcp-oauth.ts +409 -247
  58. package/src/be/db-queries/oauth.ts +813 -131
  59. package/src/be/db.ts +36 -1
  60. package/src/be/migrations/117_unified_oauth.sql +624 -0
  61. package/src/be/oauth-credential-bindings.ts +48 -14
  62. package/src/be/oauth-encryption-backfill.ts +84 -0
  63. package/src/be/oauth-refresh-sweep.ts +38 -23
  64. package/src/be/script-connections.ts +1130 -163
  65. package/src/be/script-credential-broker.ts +37 -27
  66. package/src/be/vendored-openapi.ts +98 -0
  67. package/src/http/all-routes.ts +1 -0
  68. package/src/http/index.ts +7 -5
  69. package/src/http/mcp-oauth.ts +103 -101
  70. package/src/http/oauth-callback.ts +332 -0
  71. package/src/http/oauth-generic.ts +14 -54
  72. package/src/http/script-connections.ts +651 -170
  73. package/src/http/scripts.ts +4 -2
  74. package/src/http/trackers/jira.ts +22 -34
  75. package/src/http/trackers/linear.ts +21 -36
  76. package/src/http/x.ts +6 -2
  77. package/src/jira/app.ts +12 -6
  78. package/src/jira/oauth.ts +48 -48
  79. package/src/linear/app.ts +44 -2
  80. package/src/linear/oauth.ts +12 -37
  81. package/src/oauth/app-validation.ts +27 -9
  82. package/src/oauth/ensure-mcp-token.ts +1 -0
  83. package/src/oauth/ensure-token.ts +331 -108
  84. package/src/oauth/identity-capture.ts +103 -0
  85. package/src/oauth/keepalive.ts +14 -9
  86. package/src/oauth/presets.ts +242 -0
  87. package/src/oauth/wrapper.ts +197 -76
  88. package/src/rbac/legacy-policy.ts +2 -1
  89. package/src/rbac/permissions.ts +7 -3
  90. package/src/scripts-runtime/credential-broker/broker.ts +51 -8
  91. package/src/scripts-runtime/credential-broker/fetch-patch.ts +30 -3
  92. package/src/scripts-runtime/credential-broker/index.ts +1 -1
  93. package/src/scripts-runtime/credential-broker/types.ts +55 -8
  94. package/src/scripts-runtime/egress-secrets.ts +6 -2
  95. package/src/scripts-runtime/eval-harness.ts +2 -2
  96. package/src/scripts-runtime/executors/types.ts +2 -1
  97. package/src/scripts-runtime/loader.ts +3 -0
  98. package/src/tests/connection-embedded-auth.test.ts +709 -0
  99. package/src/tests/credential-broker.test.ts +123 -125
  100. package/src/tests/db-queries-oauth.test.ts +126 -1
  101. package/src/tests/ensure-token.test.ts +44 -2
  102. package/src/tests/mcp-oauth-manual-client.test.ts +20 -1
  103. package/src/tests/mcp-oauth-queries.test.ts +154 -8
  104. package/src/tests/oauth-access-token-tool.test.ts +37 -1
  105. package/src/tests/oauth-callback-flow.test.ts +534 -0
  106. package/src/tests/oauth-credential-bindings.test.ts +50 -22
  107. package/src/tests/oauth-presets.test.ts +275 -0
  108. package/src/tests/oauth-refresh-failure.test.ts +263 -0
  109. package/src/tests/oauth-refresh-sweep.test.ts +83 -3
  110. package/src/tests/oauth-wrapper.test.ts +77 -55
  111. package/src/tests/rbac-charact-misc-tools.test.ts +60 -0
  112. package/src/tests/rbac-engine.test.ts +2 -1
  113. package/src/tests/script-connections-http.test.ts +356 -11
  114. package/src/tests/script-connections.test.ts +101 -0
  115. package/src/tests/scripts-only-gating.test.ts +93 -31
  116. package/src/tests/spec-base-url.test.ts +266 -0
  117. package/src/tests/status.test.ts +3 -4
  118. package/src/tests/swarm-config-reserved-keys.test.ts +4 -2
  119. package/src/tests/tracker-fold.test.ts +412 -0
  120. package/src/tests/unified-oauth-migration.test.ts +455 -0
  121. package/src/tests/vendored-openapi.test.ts +263 -0
  122. package/src/tools/credential-bindings/tool.ts +232 -77
  123. package/src/tools/oauth-access-token.ts +55 -6
  124. package/src/tools/script-connections/tool.ts +73 -53
  125. package/src/tools/swarm-config/set-config.ts +24 -50
  126. package/src/tracker/types.ts +12 -0
  127. package/src/workflows/executors/swarm-script.ts +6 -2
  128. package/vendored-openapi/README.md +22 -0
  129. package/vendored-openapi/github.json +7759 -0
  130. package/vendored-openapi/gmail.json +393 -0
  131. package/vendored-openapi/jira.json +3396 -0
  132. package/vendored-openapi/linear.json +252 -0
  133. package/vendored-openapi/manifest.json +128 -0
  134. package/vendored-openapi/slack.json +2895 -0
  135. package/dist/cli-0pygq9r1.js +0 -429
  136. package/dist/cli-wbrj97j4.js +0 -393
  137. package/src/scripts-runtime/credential-broker/store.ts +0 -72
@@ -0,0 +1,791 @@
1
+ import {
2
+ decryptSecret,
3
+ encryptSecret,
4
+ getDb,
5
+ getEncryptionKey,
6
+ init_crypto,
7
+ init_date_utils,
8
+ init_db,
9
+ normalizeDateRequired
10
+ } from "./cli-383wyw2f.js";
11
+
12
+ // src/be/db-queries/oauth.ts
13
+ init_crypto();
14
+ init_date_utils();
15
+ init_db();
16
+ function parseScopeList(value) {
17
+ try {
18
+ const parsed = JSON.parse(value);
19
+ if (Array.isArray(parsed)) {
20
+ return parsed.filter((item) => typeof item === "string");
21
+ }
22
+ } catch {}
23
+ return value.split(",").map((scope) => scope.trim()).filter(Boolean);
24
+ }
25
+ function storeScopeList(value) {
26
+ return JSON.stringify(Array.isArray(value) ? value : parseScopeList(value));
27
+ }
28
+ function parseObject(value) {
29
+ try {
30
+ const parsed = JSON.parse(value || "{}");
31
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
32
+ } catch {
33
+ return {};
34
+ }
35
+ }
36
+ function storageMetadata(metadata) {
37
+ const parsed = parseObject(metadata);
38
+ const extraParams = parsed.extraParams && typeof parsed.extraParams === "object" && !Array.isArray(parsed.extraParams) ? parsed.extraParams : null;
39
+ const tokenAuthStyle = parsed.tokenAuthStyle === "basic" ? "basic" : "body";
40
+ const tokenBodyFormat = parsed.tokenBodyFormat === "json" ? "json" : "form";
41
+ const revocationUrl = typeof parsed.revocationUrl === "string" ? parsed.revocationUrl : null;
42
+ const hasLiftedFields = [
43
+ "extraParams",
44
+ "tokenAuthStyle",
45
+ "tokenBodyFormat",
46
+ "revocationUrl"
47
+ ].some((key) => Object.hasOwn(parsed, key));
48
+ if (hasLiftedFields) {
49
+ delete parsed.extraParams;
50
+ delete parsed.tokenAuthStyle;
51
+ delete parsed.tokenBodyFormat;
52
+ delete parsed.revocationUrl;
53
+ }
54
+ return {
55
+ metadata: hasLiftedFields ? JSON.stringify(parsed) : metadata,
56
+ extraParamsJson: extraParams ? JSON.stringify(extraParams) : null,
57
+ tokenAuthStyle,
58
+ tokenBodyFormat,
59
+ revocationUrl
60
+ };
61
+ }
62
+ function normalizeOAuthApp(row) {
63
+ const encrypted = row.clientSecretEncrypted === 1;
64
+ return {
65
+ ...row,
66
+ clientSecret: row.clientSecret == null ? "" : encrypted ? decryptSecret(row.clientSecret, getEncryptionKey()) : row.clientSecret,
67
+ clientSecretEncrypted: encrypted,
68
+ scopes: parseScopeList(row.scopes).join(","),
69
+ requiresRefreshTokenRotation: row.requiresRefreshTokenRotation === 1,
70
+ createdAt: normalizeDateRequired(row.createdAt),
71
+ updatedAt: normalizeDateRequired(row.updatedAt)
72
+ };
73
+ }
74
+ function normalizeAuthorization(row) {
75
+ const encrypted = row.tokensEncrypted === 1;
76
+ const key = encrypted ? getEncryptionKey() : null;
77
+ return {
78
+ ...row,
79
+ accessToken: key ? decryptSecret(row.accessToken, key) : row.accessToken,
80
+ refreshToken: row.refreshToken == null ? null : key ? decryptSecret(row.refreshToken, key) : row.refreshToken,
81
+ tokensEncrypted: encrypted,
82
+ createdAt: normalizeDateRequired(row.createdAt),
83
+ updatedAt: normalizeDateRequired(row.updatedAt)
84
+ };
85
+ }
86
+ function rawOAuthAppByProvider(provider) {
87
+ return getDb().query(`SELECT * FROM oauth_apps
88
+ WHERE provider = ? AND mcpServerId IS NULL
89
+ ORDER BY createdAt ASC, id ASC
90
+ LIMIT 1`).get(provider);
91
+ }
92
+ function rawOAuthAppById(id) {
93
+ return getDb().query("SELECT * FROM oauth_apps WHERE id = ? AND mcpServerId IS NULL").get(id);
94
+ }
95
+ function rawDefaultAuthorizationForApp(appId) {
96
+ return getDb().query("SELECT * FROM oauth_authorizations WHERE appId = ? AND label = 'default'").get(appId);
97
+ }
98
+ function rawDefaultAuthorizationForProvider(provider) {
99
+ return getDb().query(`SELECT z.*
100
+ FROM oauth_authorizations z
101
+ JOIN oauth_apps a ON a.id = z.appId
102
+ WHERE a.provider = ? AND a.mcpServerId IS NULL AND z.label = 'default'
103
+ ORDER BY a.createdAt ASC, a.id ASC
104
+ LIMIT 1`).get(provider);
105
+ }
106
+ function getDefaultAuthorizationIdForProvider(provider) {
107
+ return rawDefaultAuthorizationForProvider(provider)?.id ?? null;
108
+ }
109
+ function getOAuthApp(provider) {
110
+ const row = rawOAuthAppByProvider(provider);
111
+ return row ? normalizeOAuthApp(row) : null;
112
+ }
113
+ function getOAuthAppById(id) {
114
+ const row = getDb().query("SELECT * FROM oauth_apps WHERE id = ?").get(id);
115
+ return row ? normalizeOAuthApp(row) : null;
116
+ }
117
+ function getOAuthAppIdByProvider(provider) {
118
+ return rawOAuthAppByProvider(provider)?.id ?? null;
119
+ }
120
+ function writeOAuthApp(existing, provider, data) {
121
+ const metadataProvided = data.metadata !== undefined;
122
+ const lifted = metadataProvided ? storageMetadata(data.metadata) : null;
123
+ const encryptedSecret = encryptSecret(data.clientSecret, getEncryptionKey());
124
+ const scopeSeparator = data.scopeSeparator ?? existing?.scopeSeparator ?? (provider === "linear" ? "," : " ");
125
+ const rotation = data.requiresRefreshTokenRotation ?? (existing ? existing.requiresRefreshTokenRotation === 1 : provider === "jira");
126
+ const tokenAuthStyle = data.tokenAuthStyle ?? lifted?.tokenAuthStyle ?? existing?.tokenAuthStyle ?? "body";
127
+ const tokenBodyFormat = data.tokenBodyFormat ?? lifted?.tokenBodyFormat ?? existing?.tokenBodyFormat ?? "form";
128
+ const extraParamsJson = data.extraParams !== undefined ? data.extraParams == null ? null : JSON.stringify(data.extraParams) : lifted ? lifted.extraParamsJson : existing?.extraParamsJson ?? null;
129
+ const revocationUrl = data.revocationUrl !== undefined ? data.revocationUrl : lifted ? lifted.revocationUrl : existing?.revocationUrl ?? null;
130
+ if (existing) {
131
+ getDb().query(`UPDATE oauth_apps SET
132
+ displayName = ?, clientId = ?, clientSecret = ?, clientSecretEncrypted = 1,
133
+ authorizeUrl = ?, tokenUrl = ?, revocationUrl = ?, userinfoUrl = ?,
134
+ redirectUri = ?, scopes = ?, scopeSeparator = ?, tokenAuthStyle = ?,
135
+ tokenBodyFormat = ?, requiresRefreshTokenRotation = ?, extraParamsJson = ?,
136
+ source = ?, metadata = ?, updatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
137
+ WHERE id = ?`).run(data.displayName !== undefined ? data.displayName : existing.displayName, data.clientId, encryptedSecret, data.authorizeUrl, data.tokenUrl, revocationUrl, data.userinfoUrl !== undefined ? data.userinfoUrl : existing.userinfoUrl, data.redirectUri, storeScopeList(data.scopes), scopeSeparator, tokenAuthStyle, tokenBodyFormat, rotation ? 1 : 0, extraParamsJson, data.source ?? existing.source, lifted?.metadata ?? existing.metadata, existing.id);
138
+ return existing.id;
139
+ }
140
+ const inserted = getDb().query(`INSERT INTO oauth_apps (
141
+ provider, displayName, clientId, clientSecret, clientSecretEncrypted,
142
+ authorizeUrl, tokenUrl, revocationUrl, userinfoUrl, redirectUri, scopes,
143
+ scopeSeparator, tokenAuthStyle, tokenBodyFormat,
144
+ requiresRefreshTokenRotation, extraParamsJson, source, metadata
145
+ ) VALUES (?, ?, ?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
146
+ RETURNING id`).get(provider, data.displayName ?? null, data.clientId, encryptedSecret, data.authorizeUrl, data.tokenUrl, revocationUrl, data.userinfoUrl ?? null, data.redirectUri, storeScopeList(data.scopes), scopeSeparator, tokenAuthStyle, tokenBodyFormat, rotation ? 1 : 0, extraParamsJson, data.source ?? "manual", lifted?.metadata ?? "{}");
147
+ return inserted.id;
148
+ }
149
+ function createOAuthApp(provider, data) {
150
+ return writeOAuthApp(null, provider, data);
151
+ }
152
+ function updateOAuthAppById(id, data) {
153
+ const existing = rawOAuthAppById(id);
154
+ if (!existing) {
155
+ throw new Error(`OAuth app ${id} not found.`);
156
+ }
157
+ writeOAuthApp(existing, existing.provider, data);
158
+ }
159
+ function upsertOAuthApp(provider, data) {
160
+ writeOAuthApp(rawOAuthAppByProvider(provider), provider, data);
161
+ }
162
+ function listAuthorizationsForApp(appId) {
163
+ const rows = getDb().query("SELECT * FROM oauth_authorizations WHERE appId = ? ORDER BY createdAt ASC, id ASC").all(appId);
164
+ return rows.map(normalizeAuthorization);
165
+ }
166
+ function getAuthorizationById(id) {
167
+ const row = getDb().query("SELECT * FROM oauth_authorizations WHERE id = ?").get(id);
168
+ return row ? normalizeAuthorization(row) : null;
169
+ }
170
+ function upsertAuthorization(data) {
171
+ const label = data.label ?? "default";
172
+ const existing = data.id ? getAuthorizationById(data.id) : listAuthorizationsForApp(data.appId).find((row) => row.label === label);
173
+ const key = getEncryptionKey();
174
+ const accessToken = encryptSecret(data.accessToken, key);
175
+ const refreshToken = data.refreshToken === undefined ? undefined : data.refreshToken == null ? null : encryptSecret(data.refreshToken, key);
176
+ if (existing) {
177
+ getDb().query(`UPDATE oauth_authorizations SET
178
+ userId = ?, accountEmail = ?, identityJson = ?, accessToken = ?,
179
+ refreshToken = ?, tokenType = ?, expiresAt = ?, scope = ?,
180
+ tokensEncrypted = 1, tokenVersion = tokenVersion + 1, status = ?,
181
+ lastErrorMessage = ?, lastRefreshedAt = ?, connectedByUserId = ?,
182
+ updatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
183
+ WHERE id = ?`).run(data.userId !== undefined ? data.userId : existing.userId, data.accountEmail !== undefined ? data.accountEmail : existing.accountEmail, data.identityJson !== undefined ? data.identityJson : existing.identityJson, accessToken, refreshToken === undefined ? existing.refreshToken == null ? null : encryptSecret(existing.refreshToken, key) : refreshToken, data.tokenType ?? existing.tokenType, data.expiresAt !== undefined ? data.expiresAt : existing.expiresAt, data.scope !== undefined ? data.scope : existing.scope, data.status ?? existing.status, data.lastErrorMessage !== undefined ? data.lastErrorMessage : existing.lastErrorMessage, data.lastRefreshedAt !== undefined ? data.lastRefreshedAt : existing.lastRefreshedAt, data.connectedByUserId !== undefined ? data.connectedByUserId : existing.connectedByUserId, existing.id);
184
+ return getAuthorizationById(existing.id);
185
+ }
186
+ const id = data.id ?? crypto.randomUUID();
187
+ getDb().query(`INSERT INTO oauth_authorizations (
188
+ id, appId, label, userId, accountEmail, identityJson,
189
+ accessToken, refreshToken, tokenType, expiresAt, scope,
190
+ tokensEncrypted, tokenVersion, status, lastErrorMessage,
191
+ lastRefreshedAt, connectedByUserId
192
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, 1, ?, ?, ?, ?)`).run(id, data.appId, label, data.userId ?? null, data.accountEmail ?? null, data.identityJson ?? null, accessToken, refreshToken ?? null, data.tokenType ?? "Bearer", data.expiresAt ?? null, data.scope ?? null, data.status ?? "active", data.lastErrorMessage ?? null, data.lastRefreshedAt ?? null, data.connectedByUserId ?? null);
193
+ return getAuthorizationById(id);
194
+ }
195
+ function updateAuthorizationTokens(id, data) {
196
+ const existing = getAuthorizationById(id);
197
+ if (!existing)
198
+ return null;
199
+ const expectedVersion = data.expectedTokenVersion ?? existing.tokenVersion;
200
+ const key = getEncryptionKey();
201
+ const encryptedRefresh = data.refreshToken === undefined ? existing.refreshToken == null ? null : encryptSecret(existing.refreshToken, key) : data.refreshToken == null ? null : encryptSecret(data.refreshToken, key);
202
+ const result = getDb().query(`UPDATE oauth_authorizations SET
203
+ accessToken = ?, refreshToken = ?, expiresAt = ?, scope = ?,
204
+ tokensEncrypted = 1, tokenVersion = tokenVersion + 1,
205
+ status = 'active', lastErrorMessage = NULL,
206
+ lastRefreshedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now'),
207
+ updatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
208
+ WHERE id = ? AND tokenVersion = ?`).run(encryptSecret(data.accessToken, key), encryptedRefresh, data.expiresAt !== undefined ? data.expiresAt : existing.expiresAt, data.scope !== undefined ? data.scope : existing.scope, id, expectedVersion);
209
+ return result.changes === 1 ? getAuthorizationById(id) : null;
210
+ }
211
+ function updateAuthorizationIdentity(id, data) {
212
+ getDb().query(`UPDATE oauth_authorizations SET
213
+ accountEmail = ?, identityJson = ?,
214
+ updatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
215
+ WHERE id = ?`).run(data.accountEmail ?? null, data.identityJson ?? null, id);
216
+ }
217
+ function deleteAuthorizationById(id) {
218
+ const result = getDb().query("DELETE FROM oauth_authorizations WHERE id = ?").run(id);
219
+ return result.changes > 0;
220
+ }
221
+ function deleteAuthorizationsForApp(appId) {
222
+ return getDb().query("DELETE FROM oauth_authorizations WHERE appId = ?").run(appId).changes;
223
+ }
224
+ var OAUTH_PENDING_TTL_MS = 10 * 60 * 1000;
225
+ function createOAuthPending(input) {
226
+ getDb().query(`INSERT INTO oauth_pending (
227
+ state, appId, label, flow, codeVerifier, nonce,
228
+ redirectUri, finalRedirect, userId, contextJson
229
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(input.state, input.appId, input.label ?? "default", input.flow ?? "generic", encryptSecret(input.codeVerifier, getEncryptionKey()), input.nonce ?? null, input.redirectUri, input.finalRedirect ?? null, input.userId ?? null, input.contextJson ?? "{}");
230
+ }
231
+ function consumeOAuthPending(state) {
232
+ return getDb().transaction(() => {
233
+ const row = getDb().query(`SELECT state, appId, label, flow, codeVerifier, nonce, redirectUri,
234
+ finalRedirect, userId, contextJson, createdAt
235
+ FROM oauth_pending
236
+ WHERE state = ? AND flow IN ('generic', 'tracker')`).get(state);
237
+ if (!row)
238
+ return null;
239
+ getDb().query("DELETE FROM oauth_pending WHERE state = ?").run(state);
240
+ const createdAt = normalizeDateRequired(row.createdAt);
241
+ const createdMs = new Date(createdAt).getTime();
242
+ if (Number.isNaN(createdMs) || Date.now() - createdMs > OAUTH_PENDING_TTL_MS) {
243
+ return null;
244
+ }
245
+ return {
246
+ ...row,
247
+ codeVerifier: decryptSecret(row.codeVerifier, getEncryptionKey()),
248
+ createdAt
249
+ };
250
+ })();
251
+ }
252
+ function gcOAuthPending(olderThanMs = 10 * 60 * 1000) {
253
+ const cutoff = new Date(Date.now() - olderThanMs).toISOString();
254
+ return getDb().query("DELETE FROM oauth_pending WHERE flow IN ('generic', 'tracker') AND createdAt < ?").run(cutoff).changes;
255
+ }
256
+ function markAuthorizationRefreshFailed(id, message) {
257
+ const result = getDb().query(`UPDATE oauth_authorizations SET
258
+ status = 'refresh-failed', lastErrorMessage = ?,
259
+ updatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
260
+ WHERE id = ? AND status != 'revoked'`).run(message, id);
261
+ return result.changes === 1 ? getAuthorizationById(id) : null;
262
+ }
263
+ function getOAuthTokens(provider) {
264
+ const row = rawDefaultAuthorizationForProvider(provider);
265
+ if (!row)
266
+ return null;
267
+ const authorization = normalizeAuthorization(row);
268
+ if (authorization.status === "revoked")
269
+ return null;
270
+ return {
271
+ id: authorization.id,
272
+ provider,
273
+ accessToken: authorization.accessToken,
274
+ refreshToken: authorization.refreshToken,
275
+ expiresAt: authorization.expiresAt ?? "",
276
+ scope: authorization.scope,
277
+ tokenVersion: authorization.tokenVersion,
278
+ createdAt: authorization.createdAt,
279
+ updatedAt: authorization.updatedAt
280
+ };
281
+ }
282
+ function listAuthorizationSweepRows() {
283
+ const rows = getDb().query(`SELECT z.id AS authorizationId,
284
+ z.appId AS appId,
285
+ a.provider AS provider,
286
+ z.label AS label,
287
+ z.status AS status,
288
+ CASE WHEN z.refreshToken IS NOT NULL AND z.refreshToken != '' THEN 1 ELSE 0 END AS hasRefreshToken,
289
+ COALESCE(z.expiresAt, '') AS expiresAt,
290
+ z.updatedAt AS updatedAt
291
+ FROM oauth_authorizations z
292
+ JOIN oauth_apps a ON a.id = z.appId
293
+ WHERE a.mcpServerId IS NULL
294
+ ORDER BY a.provider ASC, z.label ASC`).all();
295
+ return rows.map((row) => ({
296
+ authorizationId: row.authorizationId,
297
+ appId: row.appId,
298
+ provider: row.provider,
299
+ label: row.label,
300
+ status: row.status,
301
+ hasRefreshToken: row.hasRefreshToken === 1,
302
+ expiresAt: normalizeDateRequired(row.expiresAt),
303
+ updatedAt: normalizeDateRequired(row.updatedAt)
304
+ }));
305
+ }
306
+ function listKeepAliveAuthorizations() {
307
+ const rows = getDb().query(`SELECT z.id AS authorizationId,
308
+ z.appId AS appId,
309
+ a.provider AS provider,
310
+ z.label AS label,
311
+ a.displayName AS displayName
312
+ FROM oauth_authorizations z
313
+ JOIN oauth_apps a ON a.id = z.appId
314
+ WHERE a.mcpServerId IS NULL
315
+ AND z.status = 'active'
316
+ AND z.refreshToken IS NOT NULL AND z.refreshToken != ''
317
+ AND (
318
+ a.requiresRefreshTokenRotation = 1
319
+ OR (json_valid(a.metadata) = 1 AND json_extract(a.metadata, '$.keepAlive') IN (1, 'true'))
320
+ )
321
+ ORDER BY a.provider ASC, z.label ASC`).all();
322
+ return rows.map((row) => ({
323
+ authorizationId: row.authorizationId,
324
+ appId: row.appId,
325
+ provider: row.provider,
326
+ label: row.label,
327
+ displayName: row.displayName
328
+ }));
329
+ }
330
+ function deleteOAuthTokens(provider) {
331
+ const app = rawOAuthAppByProvider(provider);
332
+ if (!app)
333
+ return;
334
+ const existing = rawDefaultAuthorizationForApp(app.id);
335
+ if (!existing)
336
+ return;
337
+ getDb().query(`UPDATE oauth_authorizations SET
338
+ accessToken = ?, refreshToken = NULL, expiresAt = NULL, scope = NULL,
339
+ tokensEncrypted = 1, tokenVersion = tokenVersion + 1,
340
+ status = 'revoked', lastErrorMessage = NULL, lastRefreshedAt = NULL,
341
+ updatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
342
+ WHERE id = ?`).run(encryptSecret("", getEncryptionKey()), existing.id);
343
+ }
344
+ function acquireOAuthRefreshLock(lockKey, ttlMs) {
345
+ const owner = crypto.randomUUID();
346
+ const now = Date.now();
347
+ const expiresAt = new Date(now + ttlMs).toISOString();
348
+ const nowIso = new Date(now).toISOString();
349
+ getDb().query(`INSERT INTO oauth_refresh_locks (lockKey, owner, expiresAt, createdAt, updatedAt)
350
+ VALUES (?, ?, ?, ?, ?)
351
+ ON CONFLICT(lockKey) DO UPDATE SET
352
+ owner = excluded.owner,
353
+ expiresAt = excluded.expiresAt,
354
+ updatedAt = excluded.updatedAt
355
+ WHERE oauth_refresh_locks.expiresAt <= ?`).run(lockKey, owner, expiresAt, nowIso, nowIso, nowIso);
356
+ const row = getDb().query("SELECT owner FROM oauth_refresh_locks WHERE lockKey = ?").get(lockKey);
357
+ return row?.owner === owner ? owner : null;
358
+ }
359
+ function releaseOAuthRefreshLock(lockKey, owner) {
360
+ getDb().query("DELETE FROM oauth_refresh_locks WHERE lockKey = ? AND owner = ?").run(lockKey, owner);
361
+ }
362
+
363
+ // node_modules/oauth4webapi/build/index.js
364
+ var USER_AGENT;
365
+ if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
366
+ const NAME = "oauth4webapi";
367
+ const VERSION = "v3.8.5";
368
+ USER_AGENT = `${NAME}/${VERSION}`;
369
+ }
370
+ var ERR_INVALID_ARG_VALUE = "ERR_INVALID_ARG_VALUE";
371
+ var ERR_INVALID_ARG_TYPE = "ERR_INVALID_ARG_TYPE";
372
+ function CodedTypeError(message, code, cause) {
373
+ const err = new TypeError(message, { cause });
374
+ Object.assign(err, { code });
375
+ return err;
376
+ }
377
+ var allowInsecureRequests = Symbol();
378
+ var clockSkew = Symbol();
379
+ var clockTolerance = Symbol();
380
+ var customFetch = Symbol();
381
+ var modifyAssertion = Symbol();
382
+ var jweDecrypt = Symbol();
383
+ var jwksCache = Symbol();
384
+ var encoder = new TextEncoder;
385
+ var decoder = new TextDecoder;
386
+ function buf(input) {
387
+ if (typeof input === "string") {
388
+ return encoder.encode(input);
389
+ }
390
+ return decoder.decode(input);
391
+ }
392
+ var encodeBase64Url;
393
+ if (Uint8Array.prototype.toBase64) {
394
+ encodeBase64Url = (input) => {
395
+ if (input instanceof ArrayBuffer) {
396
+ input = new Uint8Array(input);
397
+ }
398
+ return input.toBase64({ alphabet: "base64url", omitPadding: true });
399
+ };
400
+ } else {
401
+ const CHUNK_SIZE = 32768;
402
+ encodeBase64Url = (input) => {
403
+ if (input instanceof ArrayBuffer) {
404
+ input = new Uint8Array(input);
405
+ }
406
+ const arr = [];
407
+ for (let i = 0;i < input.byteLength; i += CHUNK_SIZE) {
408
+ arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
409
+ }
410
+ return btoa(arr.join("")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
411
+ };
412
+ }
413
+ var decodeBase64Url;
414
+ if (Uint8Array.fromBase64) {
415
+ decodeBase64Url = (input) => {
416
+ try {
417
+ return Uint8Array.fromBase64(input, { alphabet: "base64url" });
418
+ } catch (cause) {
419
+ throw CodedTypeError("The input to be decoded is not correctly encoded.", ERR_INVALID_ARG_VALUE, cause);
420
+ }
421
+ };
422
+ } else {
423
+ decodeBase64Url = (input) => {
424
+ try {
425
+ const binary = atob(input.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, ""));
426
+ const bytes = new Uint8Array(binary.length);
427
+ for (let i = 0;i < binary.length; i++) {
428
+ bytes[i] = binary.charCodeAt(i);
429
+ }
430
+ return bytes;
431
+ } catch (cause) {
432
+ throw CodedTypeError("The input to be decoded is not correctly encoded.", ERR_INVALID_ARG_VALUE, cause);
433
+ }
434
+ };
435
+ }
436
+ function b64u(input) {
437
+ if (typeof input === "string") {
438
+ return decodeBase64Url(input);
439
+ }
440
+ return encodeBase64Url(input);
441
+ }
442
+
443
+ class UnsupportedOperationError extends Error {
444
+ code;
445
+ constructor(message, options) {
446
+ super(message, options);
447
+ this.name = this.constructor.name;
448
+ this.code = UNSUPPORTED_OPERATION;
449
+ Error.captureStackTrace?.(this, this.constructor);
450
+ }
451
+ }
452
+
453
+ class OperationProcessingError extends Error {
454
+ code;
455
+ constructor(message, options) {
456
+ super(message, options);
457
+ this.name = this.constructor.name;
458
+ if (options?.code) {
459
+ this.code = options?.code;
460
+ }
461
+ Error.captureStackTrace?.(this, this.constructor);
462
+ }
463
+ }
464
+ function OPE(message, code, cause) {
465
+ return new OperationProcessingError(message, { code, cause });
466
+ }
467
+ async function calculateJwkThumbprint(jwk) {
468
+ let components;
469
+ switch (jwk.kty) {
470
+ case "EC":
471
+ components = {
472
+ crv: jwk.crv,
473
+ kty: jwk.kty,
474
+ x: jwk.x,
475
+ y: jwk.y
476
+ };
477
+ break;
478
+ case "OKP":
479
+ components = {
480
+ crv: jwk.crv,
481
+ kty: jwk.kty,
482
+ x: jwk.x
483
+ };
484
+ break;
485
+ case "AKP":
486
+ components = {
487
+ alg: jwk.alg,
488
+ kty: jwk.kty,
489
+ pub: jwk.pub
490
+ };
491
+ break;
492
+ case "RSA":
493
+ components = {
494
+ e: jwk.e,
495
+ kty: jwk.kty,
496
+ n: jwk.n
497
+ };
498
+ break;
499
+ default:
500
+ throw new UnsupportedOperationError("unsupported JWK key type", { cause: jwk });
501
+ }
502
+ return b64u(await crypto.subtle.digest("SHA-256", buf(JSON.stringify(components))));
503
+ }
504
+ function assertCryptoKey(key, it) {
505
+ if (!(key instanceof CryptoKey)) {
506
+ throw CodedTypeError(`${it} must be a CryptoKey`, ERR_INVALID_ARG_TYPE);
507
+ }
508
+ }
509
+ function assertPrivateKey(key, it) {
510
+ assertCryptoKey(key, it);
511
+ if (key.type !== "private") {
512
+ throw CodedTypeError(`${it} must be a private CryptoKey`, ERR_INVALID_ARG_VALUE);
513
+ }
514
+ }
515
+ function assertPublicKey(key, it) {
516
+ assertCryptoKey(key, it);
517
+ if (key.type !== "public") {
518
+ throw CodedTypeError(`${it} must be a public CryptoKey`, ERR_INVALID_ARG_VALUE);
519
+ }
520
+ }
521
+ function assertString(input, it, code, cause) {
522
+ try {
523
+ if (typeof input !== "string") {
524
+ throw CodedTypeError(`${it} must be a string`, ERR_INVALID_ARG_TYPE, cause);
525
+ }
526
+ if (input.length === 0) {
527
+ throw CodedTypeError(`${it} must not be empty`, ERR_INVALID_ARG_VALUE, cause);
528
+ }
529
+ } catch (err) {
530
+ if (code) {
531
+ throw OPE(err.message, code, cause);
532
+ }
533
+ throw err;
534
+ }
535
+ }
536
+ function randomBytes() {
537
+ return b64u(crypto.getRandomValues(new Uint8Array(32)));
538
+ }
539
+ function generateRandomCodeVerifier() {
540
+ return randomBytes();
541
+ }
542
+ function generateRandomState() {
543
+ return randomBytes();
544
+ }
545
+ async function calculatePKCECodeChallenge(codeVerifier) {
546
+ assertString(codeVerifier, "codeVerifier");
547
+ return b64u(await crypto.subtle.digest("SHA-256", buf(codeVerifier)));
548
+ }
549
+ function psAlg(key) {
550
+ switch (key.algorithm.hash.name) {
551
+ case "SHA-256":
552
+ return "PS256";
553
+ case "SHA-384":
554
+ return "PS384";
555
+ case "SHA-512":
556
+ return "PS512";
557
+ default:
558
+ throw new UnsupportedOperationError("unsupported RsaHashedKeyAlgorithm hash name", {
559
+ cause: key
560
+ });
561
+ }
562
+ }
563
+ function rsAlg(key) {
564
+ switch (key.algorithm.hash.name) {
565
+ case "SHA-256":
566
+ return "RS256";
567
+ case "SHA-384":
568
+ return "RS384";
569
+ case "SHA-512":
570
+ return "RS512";
571
+ default:
572
+ throw new UnsupportedOperationError("unsupported RsaHashedKeyAlgorithm hash name", {
573
+ cause: key
574
+ });
575
+ }
576
+ }
577
+ function esAlg(key) {
578
+ switch (key.algorithm.namedCurve) {
579
+ case "P-256":
580
+ return "ES256";
581
+ case "P-384":
582
+ return "ES384";
583
+ case "P-521":
584
+ return "ES512";
585
+ default:
586
+ throw new UnsupportedOperationError("unsupported EcKeyAlgorithm namedCurve", { cause: key });
587
+ }
588
+ }
589
+ function keyToJws(key) {
590
+ switch (key.algorithm.name) {
591
+ case "RSA-PSS":
592
+ return psAlg(key);
593
+ case "RSASSA-PKCS1-v1_5":
594
+ return rsAlg(key);
595
+ case "ECDSA":
596
+ return esAlg(key);
597
+ case "Ed25519":
598
+ case "ML-DSA-44":
599
+ case "ML-DSA-65":
600
+ case "ML-DSA-87":
601
+ return key.algorithm.name;
602
+ case "EdDSA":
603
+ return "Ed25519";
604
+ default:
605
+ throw new UnsupportedOperationError("unsupported CryptoKey algorithm name", { cause: key });
606
+ }
607
+ }
608
+ function getClockSkew(client) {
609
+ const skew = client?.[clockSkew];
610
+ return typeof skew === "number" && Number.isFinite(skew) ? skew : 0;
611
+ }
612
+ function epochTime() {
613
+ return Math.floor(Date.now() / 1000);
614
+ }
615
+ async function signJwt(header, payload, key) {
616
+ if (!key.usages.includes("sign")) {
617
+ throw CodedTypeError('CryptoKey instances used for signing assertions must include "sign" in their "usages"', ERR_INVALID_ARG_VALUE);
618
+ }
619
+ const input = `${b64u(buf(JSON.stringify(header)))}.${b64u(buf(JSON.stringify(payload)))}`;
620
+ const signature = b64u(await crypto.subtle.sign(keyToSubtle(key), key, buf(input)));
621
+ return `${input}.${signature}`;
622
+ }
623
+ var jwkCache;
624
+ async function getSetPublicJwkCache(key, alg) {
625
+ const { kty, e, n, x, y, crv, pub } = await crypto.subtle.exportKey("jwk", key);
626
+ const jwk = { kty, e, n, x, y, crv, pub };
627
+ if (kty === "AKP")
628
+ jwk.alg = alg;
629
+ jwkCache.set(key, jwk);
630
+ return jwk;
631
+ }
632
+ async function publicJwk(key, alg) {
633
+ jwkCache ||= new WeakMap;
634
+ return jwkCache.get(key) || getSetPublicJwkCache(key, alg);
635
+ }
636
+ var URLParse = URL.parse ? (url, base) => URL.parse(url, base) : (url, base) => {
637
+ try {
638
+ return new URL(url, base);
639
+ } catch {
640
+ return null;
641
+ }
642
+ };
643
+ class DPoPHandler {
644
+ #header;
645
+ #privateKey;
646
+ #publicKey;
647
+ #clockSkew;
648
+ #modifyAssertion;
649
+ #map;
650
+ #jkt;
651
+ constructor(client, keyPair, options) {
652
+ assertPrivateKey(keyPair?.privateKey, '"DPoP.privateKey"');
653
+ assertPublicKey(keyPair?.publicKey, '"DPoP.publicKey"');
654
+ if (!keyPair.publicKey.extractable) {
655
+ throw CodedTypeError('"DPoP.publicKey.extractable" must be true', ERR_INVALID_ARG_VALUE);
656
+ }
657
+ this.#modifyAssertion = options?.[modifyAssertion];
658
+ this.#clockSkew = getClockSkew(client);
659
+ this.#privateKey = keyPair.privateKey;
660
+ this.#publicKey = keyPair.publicKey;
661
+ branded.add(this);
662
+ }
663
+ #get(key) {
664
+ this.#map ||= new Map;
665
+ let item = this.#map.get(key);
666
+ if (item) {
667
+ this.#map.delete(key);
668
+ this.#map.set(key, item);
669
+ }
670
+ return item;
671
+ }
672
+ #set(key, val) {
673
+ this.#map ||= new Map;
674
+ this.#map.delete(key);
675
+ if (this.#map.size === 100) {
676
+ this.#map.delete(this.#map.keys().next().value);
677
+ }
678
+ this.#map.set(key, val);
679
+ }
680
+ async calculateThumbprint() {
681
+ if (!this.#jkt) {
682
+ const jwk = await crypto.subtle.exportKey("jwk", this.#publicKey);
683
+ this.#jkt ||= await calculateJwkThumbprint(jwk);
684
+ }
685
+ return this.#jkt;
686
+ }
687
+ async addProof(url, headers, htm, accessToken) {
688
+ const alg = keyToJws(this.#privateKey);
689
+ this.#header ||= {
690
+ alg,
691
+ typ: "dpop+jwt",
692
+ jwk: await publicJwk(this.#publicKey, alg)
693
+ };
694
+ const nonce = this.#get(url.origin);
695
+ const now = epochTime() + this.#clockSkew;
696
+ const payload = {
697
+ iat: now,
698
+ jti: randomBytes(),
699
+ htm,
700
+ nonce,
701
+ htu: `${url.origin}${url.pathname}`,
702
+ ath: accessToken ? b64u(await crypto.subtle.digest("SHA-256", buf(accessToken))) : undefined
703
+ };
704
+ this.#modifyAssertion?.(this.#header, payload);
705
+ headers.set("dpop", await signJwt(this.#header, payload, this.#privateKey));
706
+ }
707
+ cacheNonce(response, url) {
708
+ try {
709
+ const nonce = response.headers.get("dpop-nonce");
710
+ if (nonce) {
711
+ this.#set(url.origin, nonce);
712
+ }
713
+ } catch {}
714
+ }
715
+ }
716
+ var tokenMatch = "[a-zA-Z0-9!#$%&\\'\\*\\+\\-\\.\\^_`\\|~]+";
717
+ var token68Match = "[a-zA-Z0-9\\-\\._\\~\\+\\/]+={0,2}";
718
+ var quotedMatch = '"((?:[^"\\\\]|\\\\[\\s\\S])*)"';
719
+ var quotedParamMatcher = "(" + tokenMatch + ")\\s*=\\s*" + quotedMatch;
720
+ var paramMatcher = "(" + tokenMatch + ")\\s*=\\s*(" + tokenMatch + ")";
721
+ var schemeRE = new RegExp("^[,\\s]*(" + tokenMatch + ")");
722
+ var quotedParamRE = new RegExp("^[,\\s]*" + quotedParamMatcher + "[,\\s]*(.*)");
723
+ var unquotedParamRE = new RegExp("^[,\\s]*" + paramMatcher + "[,\\s]*(.*)");
724
+ var token68ParamRE = new RegExp("^(" + token68Match + ")(?:$|[,\\s])(.*)");
725
+ var skipSubjectCheck = Symbol();
726
+ var idTokenClaims = new WeakMap;
727
+ var jwtRefs = new WeakMap;
728
+ var branded = new WeakSet;
729
+ var nopkce = Symbol();
730
+ var expectNoNonce = Symbol();
731
+ var skipAuthTimeCheck = Symbol();
732
+ var UNSUPPORTED_OPERATION = "OAUTH_UNSUPPORTED_OPERATION";
733
+ function checkRsaKeyAlgorithm(key) {
734
+ const { algorithm } = key;
735
+ if (typeof algorithm.modulusLength !== "number" || algorithm.modulusLength < 2048) {
736
+ throw new UnsupportedOperationError(`unsupported ${algorithm.name} modulusLength`, {
737
+ cause: key
738
+ });
739
+ }
740
+ }
741
+ function ecdsaHashName(key) {
742
+ const { algorithm } = key;
743
+ switch (algorithm.namedCurve) {
744
+ case "P-256":
745
+ return "SHA-256";
746
+ case "P-384":
747
+ return "SHA-384";
748
+ case "P-521":
749
+ return "SHA-512";
750
+ default:
751
+ throw new UnsupportedOperationError("unsupported ECDSA namedCurve", { cause: key });
752
+ }
753
+ }
754
+ function keyToSubtle(key) {
755
+ switch (key.algorithm.name) {
756
+ case "ECDSA":
757
+ return {
758
+ name: key.algorithm.name,
759
+ hash: ecdsaHashName(key)
760
+ };
761
+ case "RSA-PSS": {
762
+ checkRsaKeyAlgorithm(key);
763
+ switch (key.algorithm.hash.name) {
764
+ case "SHA-256":
765
+ case "SHA-384":
766
+ case "SHA-512":
767
+ return {
768
+ name: key.algorithm.name,
769
+ saltLength: parseInt(key.algorithm.hash.name.slice(-3), 10) >> 3
770
+ };
771
+ default:
772
+ throw new UnsupportedOperationError("unsupported RSA-PSS hash name", { cause: key });
773
+ }
774
+ }
775
+ case "RSASSA-PKCS1-v1_5":
776
+ checkRsaKeyAlgorithm(key);
777
+ return key.algorithm.name;
778
+ case "ML-DSA-44":
779
+ case "ML-DSA-65":
780
+ case "ML-DSA-87":
781
+ case "Ed25519":
782
+ return key.algorithm.name;
783
+ }
784
+ throw new UnsupportedOperationError("unsupported CryptoKey algorithm name", { cause: key });
785
+ }
786
+ var skipStateCheck = Symbol();
787
+ var expectNoState = Symbol();
788
+ var _nodiscoverycheck = Symbol();
789
+ var _expectedIssuer = Symbol();
790
+
791
+ export { getDefaultAuthorizationIdForProvider, getOAuthApp, getOAuthAppById, getOAuthAppIdByProvider, createOAuthApp, updateOAuthAppById, upsertOAuthApp, listAuthorizationsForApp, getAuthorizationById, upsertAuthorization, updateAuthorizationTokens, updateAuthorizationIdentity, deleteAuthorizationById, deleteAuthorizationsForApp, createOAuthPending, consumeOAuthPending, gcOAuthPending, markAuthorizationRefreshFailed, getOAuthTokens, listAuthorizationSweepRows, listKeepAliveAuthorizations, deleteOAuthTokens, acquireOAuthRefreshLock, releaseOAuthRefreshLock, generateRandomCodeVerifier, generateRandomState, calculatePKCECodeChallenge };