@vm0/cli 9.217.7 → 9.217.9

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 (81) hide show
  1. package/{agent-VPCUNNL3.js → agent-3BD7TETH.js} +4 -4
  2. package/{automation-FPT5NSY3.js → automation-UMODYBQ3.js} +2 -2
  3. package/{banking-YFGMVREA.js → banking-BNH2CVCO.js} +2 -2
  4. package/{chat-NFJJGTRJ.js → chat-NRM6A3FJ.js} +2 -2
  5. package/{chunk-KAC2E4NP.js → chunk-6ZGJLMHV.js} +3 -3
  6. package/{chunk-S6IOT4JU.js → chunk-BBOXEIPR.js} +2 -2
  7. package/{chunk-VMXN6HNW.js → chunk-HQLDHV7V.js} +2 -2
  8. package/{chunk-QU3UUXGM.js → chunk-JQ2AISAA.js} +2 -2
  9. package/{chunk-UIMA34V4.js → chunk-NFC466I6.js} +2 -2
  10. package/{chunk-GMCOHMKD.js → chunk-SU2TAGCK.js} +3 -3
  11. package/{chunk-JOUXZAP3.js → chunk-X2GG5T45.js} +2 -2
  12. package/chunk-X2GG5T45.js.map +1 -0
  13. package/{chunk-MPFX7JBV.js → chunk-X2GL7DNQ.js} +314 -1
  14. package/chunk-X2GL7DNQ.js.map +1 -0
  15. package/{chunk-NCW2TLOK.js → chunk-YHVDFQGM.js} +28 -9
  16. package/{chunk-NCW2TLOK.js.map → chunk-YHVDFQGM.js.map} +1 -1
  17. package/{computer-use-VANQ77E3.js → computer-use-ZT7XHVQL.js} +2 -2
  18. package/{connector-XC3WTOSX.js → connector-RCLD7UYO.js} +3 -3
  19. package/{credit-5SHNEWB5.js → credit-WI5IN47U.js} +2 -2
  20. package/{developer-support-X5QMIYKK.js → developer-support-RQE4MWDH.js} +2 -2
  21. package/{doctor-RWQLYWYD.js → doctor-43S3ELIS.js} +5 -5
  22. package/{generate-JZIKREP7.js → generate-WCZL6ZCV.js} +3 -3
  23. package/{github-EGAIOSFE.js → github-LOS4OIPN.js} +2 -2
  24. package/{goal-EXT2VNDJ.js → goal-C6ABKOCO.js} +2 -2
  25. package/{host-33AEVIZA.js → host-ZISSRQ6R.js} +2 -2
  26. package/index.js +13 -13
  27. package/{logs-DEF7GUVN.js → logs-SF6FBF3I.js} +6 -6
  28. package/{maps-IRRYG772.js → maps-BGYXTHZK.js} +2 -2
  29. package/{model-CYIZEKQ7.js → model-3363G3G7.js} +3 -3
  30. package/{model-provider-B6OPQDRU.js → model-provider-C26NRE3A.js} +3 -3
  31. package/{org-MU5LDZXF.js → org-4HHOKVAO.js} +2 -2
  32. package/package.json +1 -1
  33. package/{phone-HVXEX73Z.js → phone-SVBPUZ35.js} +2 -2
  34. package/{preference-EZEOWKMI.js → preference-BRGTL6CP.js} +2 -2
  35. package/{resource-32WJDVHN.js → resource-KLZMYUD2.js} +2 -2
  36. package/{search-CMFM6SLP.js → search-2Q2NQJLD.js} +6 -6
  37. package/{secret-B3KZG6TX.js → secret-BU6G7J4H.js} +3 -3
  38. package/{slack-MIJTLUGK.js → slack-UGOHWJTY.js} +2 -2
  39. package/{telegram-5D67OCZI.js → telegram-DTKBHSNW.js} +2 -2
  40. package/{variable-PTTIEJHO.js → variable-RAQG5IPA.js} +2 -2
  41. package/{web-263UCCO6.js → web-AXKPHAJ6.js} +2 -2
  42. package/{whoami-5BBAQ7AU.js → whoami-GCESGYZX.js} +4 -4
  43. package/{workflow-QHTVAKSK.js → workflow-VN37UXJT.js} +2 -2
  44. package/zero.js +31 -31
  45. package/chunk-JOUXZAP3.js.map +0 -1
  46. package/chunk-MPFX7JBV.js.map +0 -1
  47. /package/{agent-VPCUNNL3.js.map → agent-3BD7TETH.js.map} +0 -0
  48. /package/{automation-FPT5NSY3.js.map → automation-UMODYBQ3.js.map} +0 -0
  49. /package/{banking-YFGMVREA.js.map → banking-BNH2CVCO.js.map} +0 -0
  50. /package/{chat-NFJJGTRJ.js.map → chat-NRM6A3FJ.js.map} +0 -0
  51. /package/{chunk-KAC2E4NP.js.map → chunk-6ZGJLMHV.js.map} +0 -0
  52. /package/{chunk-S6IOT4JU.js.map → chunk-BBOXEIPR.js.map} +0 -0
  53. /package/{chunk-VMXN6HNW.js.map → chunk-HQLDHV7V.js.map} +0 -0
  54. /package/{chunk-QU3UUXGM.js.map → chunk-JQ2AISAA.js.map} +0 -0
  55. /package/{chunk-UIMA34V4.js.map → chunk-NFC466I6.js.map} +0 -0
  56. /package/{chunk-GMCOHMKD.js.map → chunk-SU2TAGCK.js.map} +0 -0
  57. /package/{computer-use-VANQ77E3.js.map → computer-use-ZT7XHVQL.js.map} +0 -0
  58. /package/{connector-XC3WTOSX.js.map → connector-RCLD7UYO.js.map} +0 -0
  59. /package/{credit-5SHNEWB5.js.map → credit-WI5IN47U.js.map} +0 -0
  60. /package/{developer-support-X5QMIYKK.js.map → developer-support-RQE4MWDH.js.map} +0 -0
  61. /package/{doctor-RWQLYWYD.js.map → doctor-43S3ELIS.js.map} +0 -0
  62. /package/{generate-JZIKREP7.js.map → generate-WCZL6ZCV.js.map} +0 -0
  63. /package/{github-EGAIOSFE.js.map → github-LOS4OIPN.js.map} +0 -0
  64. /package/{goal-EXT2VNDJ.js.map → goal-C6ABKOCO.js.map} +0 -0
  65. /package/{host-33AEVIZA.js.map → host-ZISSRQ6R.js.map} +0 -0
  66. /package/{logs-DEF7GUVN.js.map → logs-SF6FBF3I.js.map} +0 -0
  67. /package/{maps-IRRYG772.js.map → maps-BGYXTHZK.js.map} +0 -0
  68. /package/{model-CYIZEKQ7.js.map → model-3363G3G7.js.map} +0 -0
  69. /package/{model-provider-B6OPQDRU.js.map → model-provider-C26NRE3A.js.map} +0 -0
  70. /package/{org-MU5LDZXF.js.map → org-4HHOKVAO.js.map} +0 -0
  71. /package/{phone-HVXEX73Z.js.map → phone-SVBPUZ35.js.map} +0 -0
  72. /package/{preference-EZEOWKMI.js.map → preference-BRGTL6CP.js.map} +0 -0
  73. /package/{resource-32WJDVHN.js.map → resource-KLZMYUD2.js.map} +0 -0
  74. /package/{search-CMFM6SLP.js.map → search-2Q2NQJLD.js.map} +0 -0
  75. /package/{secret-B3KZG6TX.js.map → secret-BU6G7J4H.js.map} +0 -0
  76. /package/{slack-MIJTLUGK.js.map → slack-UGOHWJTY.js.map} +0 -0
  77. /package/{telegram-5D67OCZI.js.map → telegram-DTKBHSNW.js.map} +0 -0
  78. /package/{variable-PTTIEJHO.js.map → variable-RAQG5IPA.js.map} +0 -0
  79. /package/{web-263UCCO6.js.map → web-AXKPHAJ6.js.map} +0 -0
  80. /package/{whoami-5BBAQ7AU.js.map → whoami-GCESGYZX.js.map} +0 -0
  81. /package/{workflow-QHTVAKSK.js.map → workflow-VN37UXJT.js.map} +0 -0
package/zero.js CHANGED
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from "node:module";
3
3
  const require = __createRequire(import.meta.url);
4
4
  import {
5
5
  configureGlobalProxyFromEnv
6
- } from "./chunk-KAC2E4NP.js";
6
+ } from "./chunk-6ZGJLMHV.js";
7
7
  import {
8
8
  decodeZeroTokenPayload
9
9
  } from "./chunk-LRHXR7JT.js";
@@ -51,56 +51,56 @@ var ZERO_COMMAND_DEFINITIONS = [
51
51
  name: "org",
52
52
  description: "Manage organization settings, members, and providers",
53
53
  load: async () => {
54
- return (await import("./org-MU5LDZXF.js")).zeroOrgCommand;
54
+ return (await import("./org-4HHOKVAO.js")).zeroOrgCommand;
55
55
  }
56
56
  },
57
57
  {
58
58
  name: "model",
59
59
  description: "List available models and model-switching guidance",
60
60
  load: async () => {
61
- return (await import("./model-CYIZEKQ7.js")).zeroModelCommand;
61
+ return (await import("./model-3363G3G7.js")).zeroModelCommand;
62
62
  }
63
63
  },
64
64
  {
65
65
  name: "model-provider",
66
66
  description: "Inspect model provider routing",
67
67
  load: async () => {
68
- return (await import("./model-provider-B6OPQDRU.js")).zeroModelProviderCommand;
68
+ return (await import("./model-provider-C26NRE3A.js")).zeroModelProviderCommand;
69
69
  }
70
70
  },
71
71
  {
72
72
  name: "agent",
73
73
  description: "View or manage zero agents",
74
74
  load: async () => {
75
- return (await import("./agent-VPCUNNL3.js")).zeroAgentCommand;
75
+ return (await import("./agent-3BD7TETH.js")).zeroAgentCommand;
76
76
  }
77
77
  },
78
78
  {
79
79
  name: "connector",
80
80
  description: "Check third-party service connections (GitHub, Slack, etc.)",
81
81
  load: async () => {
82
- return (await import("./connector-XC3WTOSX.js")).zeroConnectorCommand;
82
+ return (await import("./connector-RCLD7UYO.js")).zeroConnectorCommand;
83
83
  }
84
84
  },
85
85
  {
86
86
  name: "credit",
87
87
  description: "Create a Stripe checkout link to buy credits",
88
88
  load: async () => {
89
- return (await import("./credit-5SHNEWB5.js")).zeroCreditCommand;
89
+ return (await import("./credit-WI5IN47U.js")).zeroCreditCommand;
90
90
  }
91
91
  },
92
92
  {
93
93
  name: "doctor",
94
94
  description: "Diagnose runtime issues (connector health, permission denials)",
95
95
  load: async () => {
96
- return (await import("./doctor-RWQLYWYD.js")).zeroDoctorCommand;
96
+ return (await import("./doctor-43S3ELIS.js")).zeroDoctorCommand;
97
97
  }
98
98
  },
99
99
  {
100
100
  name: "preference",
101
101
  description: "View or update user preferences (timezone, notifications)",
102
102
  load: async () => {
103
- return (await import("./preference-EZEOWKMI.js")).zeroPreferenceCommand;
103
+ return (await import("./preference-BRGTL6CP.js")).zeroPreferenceCommand;
104
104
  }
105
105
  },
106
106
  {
@@ -114,126 +114,126 @@ var ZERO_COMMAND_DEFINITIONS = [
114
114
  name: "automation",
115
115
  description: "Create or manage scheduled automations",
116
116
  load: async () => {
117
- return (await import("./automation-FPT5NSY3.js")).zeroAutomationCommand;
117
+ return (await import("./automation-UMODYBQ3.js")).zeroAutomationCommand;
118
118
  }
119
119
  },
120
120
  {
121
121
  name: "secret",
122
122
  description: "Read or write secrets (API keys, tokens)",
123
123
  load: async () => {
124
- return (await import("./secret-B3KZG6TX.js")).zeroSecretCommand;
124
+ return (await import("./secret-BU6G7J4H.js")).zeroSecretCommand;
125
125
  }
126
126
  },
127
127
  {
128
128
  name: "github",
129
129
  description: "Upload and download GitHub files",
130
130
  load: async () => {
131
- return (await import("./github-EGAIOSFE.js")).zeroGithubCommand;
131
+ return (await import("./github-LOS4OIPN.js")).zeroGithubCommand;
132
132
  }
133
133
  },
134
134
  {
135
135
  name: "slack",
136
136
  description: "Send messages, upload files, and download files from Slack as the bot",
137
137
  load: async () => {
138
- return (await import("./slack-MIJTLUGK.js")).zeroSlackCommand;
138
+ return (await import("./slack-UGOHWJTY.js")).zeroSlackCommand;
139
139
  }
140
140
  },
141
141
  {
142
142
  name: "telegram",
143
143
  description: "Inspect bots, send messages, upload files, and download files from Telegram",
144
144
  load: async () => {
145
- return (await import("./telegram-5D67OCZI.js")).zeroTelegramCommand;
145
+ return (await import("./telegram-DTKBHSNW.js")).zeroTelegramCommand;
146
146
  }
147
147
  },
148
148
  {
149
149
  name: "phone",
150
150
  description: "Send AgentPhone messages, upload files, and download media",
151
151
  load: async () => {
152
- return (await import("./phone-HVXEX73Z.js")).zeroPhoneCommand;
152
+ return (await import("./phone-SVBPUZ35.js")).zeroPhoneCommand;
153
153
  }
154
154
  },
155
155
  {
156
156
  name: "variable",
157
157
  description: "Read or write non-sensitive configuration values",
158
158
  load: async () => {
159
- return (await import("./variable-PTTIEJHO.js")).zeroVariableCommand;
159
+ return (await import("./variable-RAQG5IPA.js")).zeroVariableCommand;
160
160
  }
161
161
  },
162
162
  {
163
163
  name: "logs",
164
164
  description: "View and search agent run logs",
165
165
  load: async () => {
166
- return (await import("./logs-DEF7GUVN.js")).zeroLogsCommand;
166
+ return (await import("./logs-SF6FBF3I.js")).zeroLogsCommand;
167
167
  }
168
168
  },
169
169
  {
170
170
  name: "search",
171
171
  description: "Search logs, chat, or get a recipe for external sources",
172
172
  load: async () => {
173
- return (await import("./search-CMFM6SLP.js")).zeroSearchCommand;
173
+ return (await import("./search-2Q2NQJLD.js")).zeroSearchCommand;
174
174
  }
175
175
  },
176
176
  {
177
177
  name: "chat",
178
178
  description: "Manage the current web chat thread",
179
179
  load: async () => {
180
- return (await import("./chat-NFJJGTRJ.js")).zeroChatCommand;
180
+ return (await import("./chat-NRM6A3FJ.js")).zeroChatCommand;
181
181
  }
182
182
  },
183
183
  {
184
184
  name: "resource",
185
185
  description: "Pull registry resources from private R2-backed archives",
186
186
  load: async () => {
187
- return (await import("./resource-32WJDVHN.js")).zeroResourceCommand;
187
+ return (await import("./resource-KLZMYUD2.js")).zeroResourceCommand;
188
188
  }
189
189
  },
190
190
  {
191
191
  name: "whoami",
192
192
  description: "Show agent identity, run ID, and capabilities",
193
193
  load: async () => {
194
- return (await import("./whoami-5BBAQ7AU.js")).zeroWhoamiCommand;
194
+ return (await import("./whoami-GCESGYZX.js")).zeroWhoamiCommand;
195
195
  }
196
196
  },
197
197
  {
198
198
  name: "workflow",
199
199
  description: "Manage workflows",
200
200
  load: async () => {
201
- return (await import("./workflow-QHTVAKSK.js")).zeroWorkflowCommand;
201
+ return (await import("./workflow-VN37UXJT.js")).zeroWorkflowCommand;
202
202
  }
203
203
  },
204
204
  {
205
205
  name: "goal",
206
206
  description: "Manage the current thread goal",
207
207
  load: async () => {
208
- return (await import("./goal-EXT2VNDJ.js")).zeroGoalCommand;
208
+ return (await import("./goal-C6ABKOCO.js")).zeroGoalCommand;
209
209
  }
210
210
  },
211
211
  {
212
212
  name: "developer-support",
213
213
  description: "Submit a diagnostic report to the dev team",
214
214
  load: async () => {
215
- return (await import("./developer-support-X5QMIYKK.js")).zeroDeveloperSupportCommand;
215
+ return (await import("./developer-support-RQE4MWDH.js")).zeroDeveloperSupportCommand;
216
216
  }
217
217
  },
218
218
  {
219
219
  name: "computer-use",
220
220
  description: "Desktop app computer use through Zero CLI",
221
221
  load: async () => {
222
- return (await import("./computer-use-VANQ77E3.js")).zeroComputerUseCommand;
222
+ return (await import("./computer-use-ZT7XHVQL.js")).zeroComputerUseCommand;
223
223
  }
224
224
  },
225
225
  {
226
226
  name: "generate",
227
227
  description: "Generate assets via vm0's built-in pipelines or get connector skill-invocation guidance",
228
228
  load: async () => {
229
- return (await import("./generate-JZIKREP7.js")).generateCommand;
229
+ return (await import("./generate-WCZL6ZCV.js")).generateCommand;
230
230
  }
231
231
  },
232
232
  {
233
233
  name: "web",
234
234
  description: "Upload and download files via the web chat endpoint",
235
235
  load: async () => {
236
- return (await import("./web-263UCCO6.js")).zeroWebCommand;
236
+ return (await import("./web-AXKPHAJ6.js")).zeroWebCommand;
237
237
  }
238
238
  },
239
239
  {
@@ -247,21 +247,21 @@ var ZERO_COMMAND_DEFINITIONS = [
247
247
  name: "host",
248
248
  description: "Publish static sites and clone owned hosted site files",
249
249
  load: async () => {
250
- return (await import("./host-33AEVIZA.js")).zeroHostCommand;
250
+ return (await import("./host-ZISSRQ6R.js")).zeroHostCommand;
251
251
  }
252
252
  },
253
253
  {
254
254
  name: "maps",
255
255
  description: "Use managed zero maps services",
256
256
  load: async () => {
257
- return (await import("./maps-IRRYG772.js")).zeroMapsCommand;
257
+ return (await import("./maps-BGYXTHZK.js")).zeroMapsCommand;
258
258
  }
259
259
  },
260
260
  {
261
261
  name: "banking",
262
262
  description: "Use managed zero banking services",
263
263
  load: async () => {
264
- return (await import("./banking-YFGMVREA.js")).zeroBankingCommand;
264
+ return (await import("./banking-BNH2CVCO.js")).zeroBankingCommand;
265
265
  }
266
266
  }
267
267
  ];
@@ -370,7 +370,7 @@ function registerZeroCommands(prog, commands) {
370
370
  var program = new Command();
371
371
  program.name("zero").description(
372
372
  "Zero CLI \u2014 interact with the zero platform from inside the sandbox"
373
- ).version("9.217.7").addHelpText("after", () => {
373
+ ).version("9.217.9").addHelpText("after", () => {
374
374
  return buildZeroHelpText();
375
375
  });
376
376
  if (process.argv[1]?.endsWith("zero.js") || process.argv[1]?.endsWith("zero.ts") || process.argv[1]?.endsWith("zero")) {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../packages/connectors/src/connector-utils.ts"],"sourcesContent":["import {\n CONNECTOR_TYPE_KEYS,\n CONNECTOR_TYPES,\n connectorAuthMethodIdSchema,\n type ConnectorAuthMethodConfig,\n type ConnectorAuthMethodId,\n type ConnectorAuthCodeGrantAuthMethodId,\n type ConnectorDeviceAuthGrantAuthMethodId,\n type ConnectorExternalCodeGrantAuthMethodId,\n type ConnectorAuthMethodIds,\n type ConnectorAuthMethodIdsByAccessKind,\n type ConnectorAuthMethodIdsByGrantKind,\n type ConnectorAuthMethodIdsByRevokeKind,\n type ConnectorTypesByAccessKind,\n type ConnectorTypesByGrantKind,\n type ConnectorTypesByRevokeKind,\n type ConnectorAuthClientConfigForMethod,\n type ConnectorAuthMethodConfigFor,\n type RefreshTokenAccessConnectorType,\n type ConnectorAccessConfig,\n type ConnectorAccessKind,\n type ConnectorAuthCodeCallbackOrigin,\n type ConnectorAuthCodeGrantConfig,\n type ConnectorAuthClientConfig,\n type ConnectorDeviceAuthGrantConfig,\n type ConnectorExternalCodeGrantConfig,\n type ConnectorDeviceAuthStartOptionConfig,\n type ConnectorDeviceAuthStartOptions,\n type ConnectorDeviceAuthStartOptionsConfig,\n type ConnectorEnvBindings,\n type ConnectorGenerationType,\n type ConnectorGrantOutputBindings,\n type ConnectorGrantConfig,\n type ConnectorGrantKind,\n type ConnectorManualGrantFieldConfig,\n type ConnectorPlatformSecretName,\n type ConnectorRefreshTokenInputValueRef,\n type ConnectorRefreshTokenInputBindings,\n type ConnectorRefreshTokenOutputBindings,\n type ConnectorRevokeInputBindings,\n type ConnectorRevokeKind,\n type ConnectorSecretValueRef,\n type ConnectorOutputValueRef,\n type ConnectorVariableValueRef,\n type ConnectorEnvBindingValue,\n type ConnectorType,\n type AuthCodeGrantConnectorType,\n type DeviceAuthGrantConnectorType,\n type ExternalCodeGrantConnectorType,\n type DynamicPublicConnectorAuthClientConfig,\n type StaticConfidentialConnectorAuthClientConfig,\n type StaticPublicConnectorAuthClientConfig,\n} from \"./connectors\";\nimport type { FeatureSwitchKey } from \"./feature-switch-key\";\n\nconst CONNECTOR_AUTH_METHOD_PRIORITY = {\n oauth: 0,\n cli: 1,\n \"api-token\": 2,\n api: 3,\n} as const satisfies Record<ConnectorAuthMethodId, number>;\nconst CONNECTOR_SECRET_REF_PREFIX = \"$secrets.\";\nconst CONNECTOR_VARIABLE_REF_PREFIX = \"$vars.\";\nconst DEFAULT_AUTH_CODE_CALLBACK_ORIGIN: ConnectorAuthCodeCallbackOrigin =\n \"web\";\n\nfunction connectorAuthMethodPriority(\n authMethod: ConnectorAuthMethodId,\n): number {\n return CONNECTOR_AUTH_METHOD_PRIORITY[authMethod];\n}\n\nexport function getConfiguredConnectorAuthMethodIds(\n type: ConnectorType,\n): ConnectorAuthMethodId[] {\n // Configured methods are raw registry entries; callers apply availability filters.\n return Object.keys(CONNECTOR_TYPES[type].authMethods)\n .map((authMethod) => {\n return connectorAuthMethodIdSchema.parse(authMethod);\n })\n .sort((a, b) => {\n const priorityDiff =\n connectorAuthMethodPriority(a) - connectorAuthMethodPriority(b);\n return priorityDiff === 0 ? a.localeCompare(b) : priorityDiff;\n });\n}\n\n/**\n * Connector utility vocabulary:\n *\n * - Available auth methods are user-selectable connection flows after\n * feature-switch and surface policy filtering.\n * - Runtime available connector types are connector types the current server\n * environment can offer as connection candidates.\n * - User connected connector types come from persisted connector rows.\n * - Runtime injection happens later when a run receives environment entries, secrets,\n * variables, and firewall context.\n */\n\n/**\n * Get one auth method config for a connector type.\n */\nexport function getConnectorAuthMethod<\n Type extends ConnectorType,\n Method extends ConnectorAuthMethodIds<Type>,\n>(type: Type, authMethod: Method): ConnectorAuthMethodConfigFor<Type, Method>;\nexport function getConnectorAuthMethod(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthMethodConfig | undefined;\nexport function getConnectorAuthMethod(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthMethodConfig | undefined {\n for (const [methodId, method] of Object.entries(\n CONNECTOR_TYPES[type].authMethods,\n )) {\n if (methodId === authMethod) {\n return method;\n }\n }\n return undefined;\n}\n\nexport function getConnectorAuthMethodIdsForGrantKind<\n Type extends ConnectorType,\n Kind extends ConnectorGrantKind,\n>(\n type: Type,\n grantKind: Kind,\n): ConnectorAuthMethodIdsByGrantKind<Type, Kind>[] {\n return getConfiguredConnectorAuthMethodIds(type).filter(\n (\n authMethod,\n ): authMethod is ConnectorAuthMethodIdsByGrantKind<Type, Kind> => {\n return connectorAuthMethodHasGrantKind(type, authMethod, grantKind);\n },\n );\n}\n\nfunction connectorAuthMethodHasAccessKind<\n Type extends ConnectorType,\n Kind extends ConnectorAccessKind,\n>(\n type: Type,\n authMethod: string,\n accessKind: Kind,\n): authMethod is ConnectorAuthMethodIdsByAccessKind<Type, Kind> {\n return getConnectorAuthMethod(type, authMethod)?.access.kind === accessKind;\n}\n\nexport function getConnectorAuthMethodIdsForAccessKind<\n Type extends ConnectorType,\n Kind extends ConnectorAccessKind,\n>(\n type: Type,\n accessKind: Kind,\n): ConnectorAuthMethodIdsByAccessKind<Type, Kind>[] {\n return getConfiguredConnectorAuthMethodIds(type).filter(\n (\n authMethod,\n ): authMethod is ConnectorAuthMethodIdsByAccessKind<Type, Kind> => {\n return connectorAuthMethodHasAccessKind(type, authMethod, accessKind);\n },\n );\n}\n\nfunction connectorAuthMethodHasRevokeKind<\n Type extends ConnectorType,\n Kind extends ConnectorRevokeKind,\n>(\n type: Type,\n authMethod: string,\n revokeKind: Kind,\n): authMethod is ConnectorAuthMethodIdsByRevokeKind<Type, Kind> {\n return getConnectorAuthMethod(type, authMethod)?.revoke.kind === revokeKind;\n}\n\nexport function getConnectorAuthMethodIdsForRevokeKind<\n Type extends ConnectorType,\n Kind extends ConnectorRevokeKind,\n>(\n type: Type,\n revokeKind: Kind,\n): ConnectorAuthMethodIdsByRevokeKind<Type, Kind>[] {\n return getConfiguredConnectorAuthMethodIds(type).filter(\n (\n authMethod,\n ): authMethod is ConnectorAuthMethodIdsByRevokeKind<Type, Kind> => {\n return connectorAuthMethodHasRevokeKind(type, authMethod, revokeKind);\n },\n );\n}\n\nfunction getManualGrantFields(\n method: ConnectorAuthMethodConfig | undefined,\n): Record<string, ConnectorManualGrantFieldConfig> | undefined {\n if (!method || method.grant.kind !== \"manual\") {\n return undefined;\n }\n return method.grant.fields;\n}\n\nexport interface ConnectorManualGrantFieldNames {\n readonly secrets: readonly string[];\n readonly variables: readonly string[];\n}\n\nfunction manualGrantFieldNames(\n fields: Record<string, ConnectorManualGrantFieldConfig>,\n): ConnectorManualGrantFieldNames {\n const secretNames: string[] = [];\n const variableNames: string[] = [];\n for (const [name, cfg] of Object.entries(fields)) {\n if (cfg.storage === \"variable\") {\n variableNames.push(name);\n } else {\n secretNames.push(name);\n }\n }\n return { secrets: secretNames, variables: variableNames };\n}\n\nexport function getConnectorManualGrantFieldNamesForAuthMethod(\n type: ConnectorType,\n authMethod: string,\n): ConnectorManualGrantFieldNames | null {\n const fields = getManualGrantFields(getConnectorAuthMethod(type, authMethod));\n return fields ? manualGrantFieldNames(fields) : null;\n}\n\nexport function getConnectorManualGrantFieldNames(\n type: ConnectorType,\n): ConnectorManualGrantFieldNames | null {\n const secretNames = new Set<string>();\n const variableNames = new Set<string>();\n for (const authMethod of getConfiguredConnectorAuthMethodIds(type)) {\n const fields = getConnectorManualGrantFieldNamesForAuthMethod(\n type,\n authMethod,\n );\n if (!fields) {\n continue;\n }\n fields.secrets.forEach((name) => {\n secretNames.add(name);\n });\n fields.variables.forEach((name) => {\n variableNames.add(name);\n });\n }\n\n if (secretNames.size === 0 && variableNames.size === 0) {\n return null;\n }\n return { secrets: [...secretNames], variables: [...variableNames] };\n}\n\nfunction connectorAccessEnvBindings(\n access: ConnectorAccessConfig,\n): ConnectorEnvBindings {\n switch (access.kind) {\n case \"static\":\n case \"refresh-token\":\n return access.envBindings;\n case \"none\":\n return {};\n }\n}\n\nfunction connectorAccessRuntimeEnvBindings(\n access: ConnectorAccessConfig,\n): ConnectorRuntimeEnvBindings {\n return connectorRuntimeEnvBindings(connectorAccessEnvBindings(access));\n}\n\nfunction connectorAccessPlatformSecrets(\n access: ConnectorAccessConfig,\n): readonly ConnectorPlatformSecretName[] {\n switch (access.kind) {\n case \"static\":\n case \"refresh-token\":\n return access.platformSecrets ?? [];\n case \"none\":\n return [];\n }\n}\n\nexport type ConnectorAuthMethodAccessMetadata =\n | {\n readonly kind: \"static\";\n readonly envBindings: ConnectorRuntimeEnvBindings;\n readonly platformSecrets: readonly ConnectorPlatformSecretName[];\n }\n | {\n readonly kind: \"refresh-token\";\n readonly inputs: Readonly<\n Record<string, ConnectorRefreshTokenInputMetadata>\n >;\n readonly outputs: Readonly<\n Record<string, ConnectorRefreshTokenOutputMetadata>\n >;\n readonly refreshableSecrets: readonly string[];\n readonly envBindings: ConnectorRuntimeEnvBindings;\n readonly platformSecrets: readonly ConnectorPlatformSecretName[];\n }\n | {\n readonly kind: \"none\";\n readonly envBindings: ConnectorRuntimeEnvBindings;\n readonly platformSecrets: readonly ConnectorPlatformSecretName[];\n };\n\nexport type ConnectorRefreshTokenAccessMetadata = Extract<\n ConnectorAuthMethodAccessMetadata,\n { readonly kind: \"refresh-token\" }\n>;\n\nexport interface ConnectorRefreshTokenInputMetadata {\n readonly valueRef: string;\n readonly source: Extract<\n ConnectorRuntimeBindingSource,\n { readonly kind: \"connector-secret\" | \"connector-variable\" }\n >;\n}\n\nexport interface ConnectorRefreshTokenOutputMetadata {\n readonly valueRef: string;\n readonly target: ConnectorOutputTarget;\n}\n\nexport interface ConnectorRefreshTokenMetadata {\n readonly inputs: Readonly<Record<string, ConnectorRefreshTokenInputMetadata>>;\n readonly outputs: Readonly<\n Record<string, ConnectorRefreshTokenOutputMetadata>\n >;\n readonly refreshableSecrets: readonly string[];\n}\n\nexport interface ConnectorGrantOutputMetadata {\n readonly valueRef: string;\n readonly target: ConnectorOutputTarget;\n}\n\nexport type ConnectorAuthMethodGrantMetadata =\n | {\n readonly kind: \"auth-code\" | \"external-code\" | \"device-auth\";\n readonly outputs: Readonly<Record<string, ConnectorGrantOutputMetadata>>;\n }\n | {\n readonly kind: \"manual\" | \"managed\";\n readonly outputs: Readonly<Record<string, ConnectorGrantOutputMetadata>>;\n };\n\nexport interface ConnectorRevokeInputMetadata {\n readonly valueRef: string;\n readonly secretName: string;\n}\n\nexport type ConnectorAuthMethodRevokeMetadata =\n | {\n readonly kind: \"token-revoke\";\n readonly inputs: Readonly<Record<string, ConnectorRevokeInputMetadata>>;\n }\n | {\n readonly kind: \"none\";\n readonly inputs: Readonly<Record<string, ConnectorRevokeInputMetadata>>;\n };\n\nexport type ConnectorRuntimeBindingSource =\n | {\n readonly kind: \"connector-secret\";\n readonly name: string;\n }\n | {\n readonly kind: \"connector-variable\";\n readonly name: string;\n }\n | {\n readonly kind: \"platform-secret\";\n readonly name: ConnectorPlatformSecretName;\n };\n\nexport type ConnectorOutputTarget =\n | {\n readonly kind: \"connector-secret\";\n readonly name: string;\n }\n | {\n readonly kind: \"connector-variable\";\n readonly name: string;\n };\n\nexport interface ConnectorRuntimeBindingEntry {\n readonly envName: string;\n readonly valueRef: string;\n readonly optional: boolean;\n readonly source: ConnectorRuntimeBindingSource;\n}\n\nexport interface ConnectorAuthMethodRuntimeMetadata {\n readonly storage: {\n readonly secrets: readonly string[];\n readonly variables: readonly string[];\n };\n readonly runtimeBindings: readonly ConnectorRuntimeBindingEntry[];\n}\n\nfunction isConnectorSecretValueRef(\n valueRef: ConnectorOutputValueRef,\n): valueRef is ConnectorSecretValueRef {\n return valueRef.startsWith(CONNECTOR_SECRET_REF_PREFIX);\n}\n\nfunction connectorSecretNameFromValueRef(\n valueRef: ConnectorSecretValueRef,\n): string {\n return valueRef.slice(CONNECTOR_SECRET_REF_PREFIX.length);\n}\n\nfunction connectorVariableNameFromValueRef(\n valueRef: ConnectorVariableValueRef,\n): string {\n return valueRef.slice(CONNECTOR_VARIABLE_REF_PREFIX.length);\n}\n\nfunction connectorRefreshInputMetadata(\n valueRef: ConnectorRefreshTokenInputValueRef,\n): ConnectorRefreshTokenInputMetadata {\n if (isConnectorSecretValueRef(valueRef)) {\n return {\n valueRef,\n source: {\n kind: \"connector-secret\",\n name: connectorSecretNameFromValueRef(valueRef),\n },\n };\n }\n\n const variableName = connectorVariableNameFromValueRef(valueRef);\n return {\n valueRef,\n source: { kind: \"connector-variable\", name: variableName },\n };\n}\n\nfunction connectorRefreshOutputMetadata(\n valueRef: ConnectorOutputValueRef,\n): ConnectorRefreshTokenOutputMetadata {\n return {\n valueRef,\n target: connectorOutputTargetFromValueRef(valueRef),\n };\n}\n\nfunction connectorGrantOutputMetadata(\n valueRef: ConnectorOutputValueRef,\n): ConnectorGrantOutputMetadata {\n return connectorRefreshOutputMetadata(valueRef);\n}\n\nfunction connectorOutputTargetFromValueRef(\n valueRef: ConnectorOutputValueRef,\n): ConnectorOutputTarget {\n if (isConnectorSecretValueRef(valueRef)) {\n return {\n kind: \"connector-secret\",\n name: connectorSecretNameFromValueRef(valueRef),\n };\n }\n\n return {\n kind: \"connector-variable\",\n name: connectorVariableNameFromValueRef(valueRef),\n };\n}\n\nfunction connectorRevokeInputMetadata(\n valueRef: ConnectorSecretValueRef,\n): ConnectorRevokeInputMetadata {\n return { valueRef, secretName: connectorSecretNameFromValueRef(valueRef) };\n}\n\nfunction connectorRefreshMetadata(args: {\n readonly inputs: ConnectorRefreshTokenInputBindings;\n readonly outputs: ConnectorRefreshTokenOutputBindings;\n readonly refreshableSecrets: readonly string[];\n}): ConnectorRefreshTokenMetadata {\n return {\n inputs: Object.fromEntries(\n Object.entries(args.inputs).map(([name, valueRef]) => {\n return [name, connectorRefreshInputMetadata(valueRef)];\n }),\n ),\n outputs: Object.fromEntries(\n Object.entries(args.outputs).map(([name, valueRef]) => {\n return [name, connectorRefreshOutputMetadata(valueRef)];\n }),\n ),\n refreshableSecrets: [...args.refreshableSecrets],\n };\n}\n\nexport function getConnectorAuthMethodAccessMetadata<\n Type extends RefreshTokenAccessConnectorType,\n Method extends ConnectorAuthMethodIdsByAccessKind<Type, \"refresh-token\">,\n>(type: Type, authMethod: Method): ConnectorRefreshTokenAccessMetadata;\nexport function getConnectorAuthMethodAccessMetadata(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthMethodAccessMetadata | undefined;\nexport function getConnectorAuthMethodAccessMetadata(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthMethodAccessMetadata | undefined {\n const method = getConnectorAuthMethod(type, authMethod);\n if (!method) {\n return undefined;\n }\n\n switch (method.access.kind) {\n case \"static\": {\n return {\n kind: \"static\",\n envBindings: connectorAccessRuntimeEnvBindings(method.access),\n platformSecrets: method.access.platformSecrets ?? [],\n };\n }\n case \"refresh-token\":\n return {\n kind: \"refresh-token\",\n ...connectorRefreshMetadata(method.access),\n envBindings: connectorAccessRuntimeEnvBindings(method.access),\n platformSecrets: method.access.platformSecrets ?? [],\n };\n case \"none\":\n return {\n kind: \"none\",\n envBindings: {},\n platformSecrets: [],\n };\n }\n}\n\nfunction connectorGrantOutputMetadataMap(\n outputs: ConnectorGrantOutputBindings,\n): Record<string, ConnectorGrantOutputMetadata> {\n return Object.fromEntries(\n Object.entries(outputs).map(([name, valueRef]) => {\n return [name, connectorGrantOutputMetadata(valueRef)];\n }),\n );\n}\n\nexport function getConnectorAuthMethodGrantMetadata(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthMethodGrantMetadata | undefined {\n const method = getConnectorAuthMethod(type, authMethod);\n if (!method) {\n return undefined;\n }\n\n switch (method.grant.kind) {\n case \"auth-code\":\n case \"external-code\":\n case \"device-auth\":\n return {\n kind: method.grant.kind,\n outputs: connectorGrantOutputMetadataMap(method.grant.outputs),\n };\n case \"manual\":\n case \"managed\":\n return {\n kind: method.grant.kind,\n outputs: {},\n };\n }\n}\n\nexport function getConnectorGrantOutputTarget(\n metadata: ConnectorAuthMethodGrantMetadata,\n outputName: string,\n): ConnectorOutputTarget | undefined {\n return metadata.outputs[outputName]?.target;\n}\n\nfunction connectorRevokeInputMetadataMap(\n inputs: ConnectorRevokeInputBindings,\n): Record<string, ConnectorRevokeInputMetadata> {\n return Object.fromEntries(\n Object.entries(inputs).map(([name, valueRef]) => {\n return [name, connectorRevokeInputMetadata(valueRef)];\n }),\n );\n}\n\nexport function getConnectorAuthMethodRevokeMetadata(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthMethodRevokeMetadata | undefined {\n const method = getConnectorAuthMethod(type, authMethod);\n if (!method) {\n return undefined;\n }\n\n switch (method.revoke.kind) {\n case \"token-revoke\":\n return {\n kind: \"token-revoke\",\n inputs: connectorRevokeInputMetadataMap(method.revoke.inputs),\n };\n case \"none\":\n return {\n kind: \"none\",\n inputs: {},\n };\n }\n}\n\nexport function getConnectorRefreshOutputTarget(\n metadata: ConnectorAuthMethodAccessMetadata,\n outputName: string,\n): ConnectorOutputTarget | undefined {\n return metadata.kind === \"refresh-token\"\n ? metadata.outputs[outputName]?.target\n : undefined;\n}\n\nexport function getConnectorRuntimeBindingSecretName(\n metadata: ConnectorAuthMethodRuntimeMetadata,\n envName: string,\n): string | undefined {\n const binding = metadata.runtimeBindings.find((entry) => {\n return (\n entry.envName === envName && entry.source.kind === \"connector-secret\"\n );\n });\n return binding?.source.kind === \"connector-secret\"\n ? binding.source.name\n : undefined;\n}\n\nexport function connectorRefreshMetadataHasRefreshableSecret(\n metadata: ConnectorAuthMethodAccessMetadata,\n secretName: string,\n): boolean {\n return (\n metadata.kind === \"refresh-token\" &&\n metadata.refreshableSecrets.includes(secretName)\n );\n}\n\nfunction connectorPlatformSecretSource(\n secretName: string,\n platformSecrets: readonly ConnectorPlatformSecretName[],\n): ConnectorPlatformSecretName | undefined {\n return platformSecrets.find((platformSecret) => {\n return platformSecret === secretName;\n });\n}\n\nexport type ConnectorRuntimeEnvBindings = Record<\n string,\n ConnectorRefreshTokenInputValueRef\n>;\n\nfunction connectorEnvBindingValueRef(\n binding: ConnectorEnvBindingValue,\n): ConnectorRefreshTokenInputValueRef {\n return typeof binding === \"string\" ? binding : binding.valueRef;\n}\n\nfunction connectorEnvBindingIsOptional(\n binding: ConnectorEnvBindingValue,\n): boolean {\n return typeof binding === \"string\" ? false : (binding.optional ?? false);\n}\n\nfunction connectorRuntimeEnvBindings(\n envBindings: ConnectorEnvBindings,\n): ConnectorRuntimeEnvBindings {\n return Object.fromEntries(\n Object.entries(envBindings).map(([envName, binding]) => {\n return [envName, connectorEnvBindingValueRef(binding)];\n }),\n );\n}\n\nfunction connectorRuntimeBindingEntries(args: {\n readonly envBindings: ConnectorEnvBindings;\n readonly platformSecrets: readonly ConnectorPlatformSecretName[];\n}): ConnectorRuntimeBindingEntry[] {\n const entries: ConnectorRuntimeBindingEntry[] = [];\n for (const [envName, binding] of Object.entries(args.envBindings)) {\n const valueRef = connectorEnvBindingValueRef(binding);\n const optional = connectorEnvBindingIsOptional(binding);\n if (valueRef.startsWith(CONNECTOR_SECRET_REF_PREFIX)) {\n const secretName = valueRef.slice(CONNECTOR_SECRET_REF_PREFIX.length);\n const platformSecret = connectorPlatformSecretSource(\n secretName,\n args.platformSecrets,\n );\n entries.push({\n envName,\n valueRef,\n optional,\n source: platformSecret\n ? { kind: \"platform-secret\", name: platformSecret }\n : { kind: \"connector-secret\", name: secretName },\n });\n continue;\n }\n\n if (valueRef.startsWith(CONNECTOR_VARIABLE_REF_PREFIX)) {\n entries.push({\n envName,\n valueRef,\n optional,\n source: {\n kind: \"connector-variable\",\n name: valueRef.slice(CONNECTOR_VARIABLE_REF_PREFIX.length),\n },\n });\n }\n }\n return entries;\n}\n\nexport function getConnectorAuthMethodRuntimeMetadata(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthMethodRuntimeMetadata | undefined {\n const method = getConnectorAuthMethod(type, authMethod);\n if (!method) {\n return undefined;\n }\n const platformSecrets = connectorAccessPlatformSecrets(method.access);\n return {\n storage: {\n secrets: [...method.storage.secrets],\n variables: [...method.storage.variables],\n },\n runtimeBindings: connectorRuntimeBindingEntries({\n envBindings: connectorAccessEnvBindings(method.access),\n platformSecrets,\n }),\n };\n}\n\nexport function connectorAuthMethodHasGrantKind<\n Type extends ConnectorType,\n Kind extends ConnectorGrantKind,\n>(\n type: Type,\n authMethod: string,\n grantKind: Kind,\n): authMethod is ConnectorAuthMethodIdsByGrantKind<Type, Kind> {\n const method = getConnectorAuthMethod(type, authMethod);\n return method?.grant.kind === grantKind;\n}\n\nexport interface ConnectorAuthMethodRef {\n readonly type: ConnectorType;\n readonly authMethod: ConnectorAuthMethodId;\n}\n\nexport type ConnectorAuthMethodRefByGrantKind<Kind extends ConnectorGrantKind> =\n {\n readonly [Type in ConnectorTypesByGrantKind<Kind>]: {\n readonly type: Type;\n readonly authMethod: ConnectorAuthMethodIdsByGrantKind<Type, Kind>;\n };\n }[ConnectorTypesByGrantKind<Kind>];\n\nexport type ConnectorAuthMethodRefByAccessKind<\n Kind extends ConnectorAccessKind,\n> = {\n readonly [Type in ConnectorTypesByAccessKind<Kind>]: {\n readonly type: Type;\n readonly authMethod: ConnectorAuthMethodIdsByAccessKind<Type, Kind>;\n };\n}[ConnectorTypesByAccessKind<Kind>];\n\nexport type ConnectorAuthMethodRefByRevokeKind<\n Kind extends ConnectorRevokeKind,\n> = {\n readonly [Type in ConnectorTypesByRevokeKind<Kind>]: {\n readonly type: Type;\n readonly authMethod: ConnectorAuthMethodIdsByRevokeKind<Type, Kind>;\n };\n}[ConnectorTypesByRevokeKind<Kind>];\n\nexport function connectorAuthMethodRefHasGrantKind<\n Kind extends ConnectorGrantKind,\n>(\n authMethodRef: ConnectorAuthMethodRef,\n grantKind: Kind,\n): authMethodRef is ConnectorAuthMethodRefByGrantKind<Kind> {\n return (\n getConnectorAuthMethod(authMethodRef.type, authMethodRef.authMethod)?.grant\n .kind === grantKind\n );\n}\n\nexport function connectorAuthMethodRefHasAccessKind<\n Kind extends ConnectorAccessKind,\n>(\n authMethodRef: ConnectorAuthMethodRef,\n accessKind: Kind,\n): authMethodRef is ConnectorAuthMethodRefByAccessKind<Kind> {\n return (\n getConnectorAuthMethod(authMethodRef.type, authMethodRef.authMethod)?.access\n .kind === accessKind\n );\n}\n\nexport function connectorAuthMethodRefHasRevokeKind<\n Kind extends ConnectorRevokeKind,\n>(\n authMethodRef: ConnectorAuthMethodRef,\n revokeKind: Kind,\n): authMethodRef is ConnectorAuthMethodRefByRevokeKind<Kind> {\n return (\n getConnectorAuthMethod(authMethodRef.type, authMethodRef.authMethod)?.revoke\n .kind === revokeKind\n );\n}\n\nexport function getConnectorAuthMethodAuthCodeGrantConfig<\n Type extends AuthCodeGrantConnectorType,\n>(\n type: Type,\n authMethod: ConnectorAuthCodeGrantAuthMethodId<Type>,\n): ConnectorAuthCodeGrantConfig;\nexport function getConnectorAuthMethodAuthCodeGrantConfig(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthCodeGrantConfig | undefined;\nexport function getConnectorAuthMethodAuthCodeGrantConfig(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthCodeGrantConfig | undefined {\n const grant = getConnectorAuthMethod(type, authMethod)?.grant;\n return grant?.kind === \"auth-code\" ? grant : undefined;\n}\n\nexport function getConnectorAuthMethodAuthCodeCallbackOrigin<\n Type extends AuthCodeGrantConnectorType,\n>(\n type: Type,\n authMethod: ConnectorAuthCodeGrantAuthMethodId<Type>,\n): ConnectorAuthCodeCallbackOrigin;\nexport function getConnectorAuthMethodAuthCodeCallbackOrigin(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthCodeCallbackOrigin | undefined;\nexport function getConnectorAuthMethodAuthCodeCallbackOrigin(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthCodeCallbackOrigin | undefined {\n const grant = getConnectorAuthMethodAuthCodeGrantConfig(type, authMethod);\n if (!grant) {\n return undefined;\n }\n return grant.callbackOrigin ?? DEFAULT_AUTH_CODE_CALLBACK_ORIGIN;\n}\n\nexport function connectorAuthCodeCallbacksUseOnlyApiOrigin(\n type: AuthCodeGrantConnectorType,\n): boolean {\n const authMethods = getConnectorAuthMethodIdsForGrantKind(type, \"auth-code\");\n return authMethods.every((authMethod) => {\n return (\n getConnectorAuthMethodAuthCodeCallbackOrigin(type, authMethod) === \"api\"\n );\n });\n}\n\nexport function getConnectorAuthMethodExternalCodeGrantConfig<\n Type extends ExternalCodeGrantConnectorType,\n>(\n type: Type,\n authMethod: ConnectorExternalCodeGrantAuthMethodId<Type>,\n): ConnectorExternalCodeGrantConfig;\nexport function getConnectorAuthMethodExternalCodeGrantConfig(\n type: ConnectorType,\n authMethod: string,\n): ConnectorExternalCodeGrantConfig | undefined;\nexport function getConnectorAuthMethodExternalCodeGrantConfig(\n type: ConnectorType,\n authMethod: string,\n): ConnectorExternalCodeGrantConfig | undefined {\n const grant = getConnectorAuthMethod(type, authMethod)?.grant;\n return grant?.kind === \"external-code\" ? grant : undefined;\n}\n\nexport function getConnectorAuthMethodDeviceAuthGrantConfig<\n Type extends DeviceAuthGrantConnectorType,\n>(\n type: Type,\n authMethod: ConnectorDeviceAuthGrantAuthMethodId<Type>,\n): ConnectorDeviceAuthGrantConfig;\nexport function getConnectorAuthMethodDeviceAuthGrantConfig(\n type: ConnectorType,\n authMethod: string,\n): ConnectorDeviceAuthGrantConfig | undefined;\nexport function getConnectorAuthMethodDeviceAuthGrantConfig(\n type: ConnectorType,\n authMethod: string,\n): ConnectorDeviceAuthGrantConfig | undefined {\n const grant = getConnectorAuthMethod(type, authMethod)?.grant;\n return grant?.kind === \"device-auth\" ? grant : undefined;\n}\n\nexport function getConnectorAuthMethodDeviceAuthStartOptionsConfig<\n Type extends DeviceAuthGrantConnectorType,\n>(\n type: Type,\n authMethod: ConnectorDeviceAuthGrantAuthMethodId<Type>,\n): ConnectorDeviceAuthStartOptionsConfig | undefined;\nexport function getConnectorAuthMethodDeviceAuthStartOptionsConfig(\n type: ConnectorType,\n authMethod: string,\n): ConnectorDeviceAuthStartOptionsConfig | undefined;\nexport function getConnectorAuthMethodDeviceAuthStartOptionsConfig(\n type: ConnectorType,\n authMethod: string,\n): ConnectorDeviceAuthStartOptionsConfig | undefined {\n return getConnectorAuthMethodDeviceAuthGrantConfig(type, authMethod)\n ?.startOptions;\n}\n\nexport type ConnectorDeviceAuthStartOptionsParseResult =\n | {\n readonly success: true;\n readonly options: ConnectorDeviceAuthStartOptions;\n }\n | {\n readonly success: false;\n readonly message: string;\n };\n\nfunction parseConnectorDeviceAuthStartOption(args: {\n readonly type: ConnectorType;\n readonly authMethod: string;\n readonly optionName: string;\n readonly config: ConnectorDeviceAuthStartOptionConfig;\n readonly requestedValue: string | undefined;\n}): ConnectorDeviceAuthStartOptionsParseResult {\n const value = args.requestedValue ?? args.config.defaultValue;\n if (value === undefined) {\n if (args.config.required) {\n return {\n success: false,\n message: `${args.type} ${args.authMethod} device-auth start option ${args.optionName} is required`,\n };\n }\n return { success: true, options: {} };\n }\n\n switch (args.config.kind) {\n case \"select\": {\n if (\n !args.config.options.some((option) => {\n return option.value === value;\n })\n ) {\n return {\n success: false,\n message: `${args.type} ${args.authMethod} device-auth start option ${args.optionName} must be one of: ${args.config.options\n .map((option) => {\n return option.value;\n })\n .join(\", \")}`,\n };\n }\n return { success: true, options: { [args.optionName]: value } };\n }\n }\n}\n\nfunction connectorDeviceAuthStartOptionValue(\n options: ConnectorDeviceAuthStartOptions | undefined,\n optionName: string,\n): string | undefined {\n if (!options || !Object.hasOwn(options, optionName)) {\n return undefined;\n }\n return options[optionName];\n}\n\nexport function parseConnectorDeviceAuthStartOptions(args: {\n readonly type: ConnectorType;\n readonly authMethod: string;\n readonly options: ConnectorDeviceAuthStartOptions | undefined;\n}): ConnectorDeviceAuthStartOptionsParseResult {\n const configuredOptions = getConnectorAuthMethodDeviceAuthStartOptionsConfig(\n args.type,\n args.authMethod,\n );\n const requestedOptionKeys = Object.keys(args.options ?? {});\n\n if (!configuredOptions || Object.keys(configuredOptions).length === 0) {\n if (requestedOptionKeys.length === 0) {\n return { success: true, options: {} };\n }\n return {\n success: false,\n message: `${args.type} ${args.authMethod} device-auth start options are not supported: ${requestedOptionKeys.join(\", \")}`,\n };\n }\n\n for (const optionName of requestedOptionKeys) {\n if (!Object.hasOwn(configuredOptions, optionName)) {\n return {\n success: false,\n message: `${args.type} ${args.authMethod} device-auth start option ${optionName} is not supported`,\n };\n }\n }\n\n const normalizedOptions: Record<string, string> = {};\n for (const [optionName, config] of Object.entries(configuredOptions)) {\n const parsedOption = parseConnectorDeviceAuthStartOption({\n type: args.type,\n authMethod: args.authMethod,\n optionName,\n config,\n requestedValue: connectorDeviceAuthStartOptionValue(\n args.options,\n optionName,\n ),\n });\n if (!parsedOption.success) {\n return parsedOption;\n }\n for (const [parsedOptionName, parsedOptionValue] of Object.entries(\n parsedOption.options,\n )) {\n normalizedOptions[parsedOptionName] = parsedOptionValue;\n }\n }\n\n return { success: true, options: normalizedOptions };\n}\n\nfunction connectorGrantScopes(\n grant: ConnectorGrantConfig | undefined,\n): readonly string[] {\n switch (grant?.kind) {\n case \"auth-code\":\n case \"external-code\":\n case \"device-auth\":\n return grant.scopes;\n case \"manual\":\n case \"managed\":\n case undefined:\n return [];\n }\n}\n\nexport function getConnectorAuthMethodGrantScopes(\n type: ConnectorType,\n authMethod: string,\n): string[] {\n return [\n ...connectorGrantScopes(getConnectorAuthMethod(type, authMethod)?.grant),\n ];\n}\n\nexport function getConnectorGenerationTypes(\n type: ConnectorType,\n): readonly ConnectorGenerationType[] {\n const config = CONNECTOR_TYPES[type];\n return \"generation\" in config ? (config.generation ?? []) : [];\n}\n\nexport function getConnectorTags(type: ConnectorType): readonly string[] {\n const config = CONNECTOR_TYPES[type];\n return \"tags\" in config ? (config.tags ?? []) : [];\n}\n\nexport type ConnectorFeatureStates =\n | Partial<Record<FeatureSwitchKey, boolean>>\n | null\n | undefined;\n\nexport type ApiAuthMethodPolicy =\n | \"exclude\"\n | \"include\"\n | { readonly includeForTypes: readonly ConnectorType[] };\n\nexport interface AvailableConnectorAuthMethodsOptions {\n readonly apiAuthMethodPolicy?: ApiAuthMethodPolicy;\n}\n\nexport function isConnectorAuthMethodAvailable(\n type: ConnectorType,\n authMethod: ConnectorAuthMethodId,\n featureStates: ConnectorFeatureStates,\n): boolean {\n const method = getConnectorAuthMethod(type, authMethod);\n if (!method) {\n return false;\n }\n if (method.visible === false) {\n return false;\n }\n return !method.featureFlag || !!featureStates?.[method.featureFlag];\n}\n\nfunction shouldIncludeApiAuthMethod(\n type: ConnectorType,\n policy: ApiAuthMethodPolicy | undefined,\n): boolean {\n switch (policy) {\n case \"include\":\n return true;\n case \"exclude\":\n case undefined:\n return false;\n }\n return policy.includeForTypes.includes(type);\n}\n\n/**\n * Return user-selectable connector connection flows for a surface.\n *\n * This includes static visibility, feature-switch, and surface policy filtering.\n * It does not describe persisted connected state.\n */\nexport function getAvailableConnectorAuthMethodIds(\n type: ConnectorType,\n featureStates: ConnectorFeatureStates,\n options: AvailableConnectorAuthMethodsOptions = {},\n): ConnectorAuthMethodId[] {\n const apiAuthMethodPolicy = options.apiAuthMethodPolicy ?? \"exclude\";\n const availableAuthMethodIds: ConnectorAuthMethodId[] = [];\n const configuredAuthMethodIds = getConfiguredConnectorAuthMethodIds(type);\n\n for (const authMethod of configuredAuthMethodIds) {\n const method = getConnectorAuthMethod(type, authMethod);\n switch (method?.grant.kind) {\n case \"managed\": {\n if (!shouldIncludeApiAuthMethod(type, apiAuthMethodPolicy)) {\n continue;\n }\n break;\n }\n case \"auth-code\":\n case \"external-code\":\n case \"device-auth\":\n case \"manual\": {\n break;\n }\n case undefined: {\n continue;\n }\n }\n if (isConnectorAuthMethodAvailable(type, authMethod, featureStates)) {\n availableAuthMethodIds.push(authMethod);\n }\n }\n\n return availableAuthMethodIds;\n}\n\nexport type ConnectorEnvReader = (name: string) => string | undefined;\n\nexport type StaticConfidentialConnectorAuthClient = {\n readonly clientRegistration: \"static\";\n readonly clientType: \"confidential\";\n readonly clientId: string;\n readonly clientSecret: string;\n};\n\nexport type StaticConfidentialConnectorAuthClientIdentity = {\n readonly clientRegistration: \"static\";\n readonly clientType: \"confidential\";\n readonly clientId: string;\n};\n\nexport type StaticPublicConnectorAuthClient = {\n readonly clientRegistration: \"static\";\n readonly clientType: \"public\";\n readonly clientId: string;\n};\n\nexport type DynamicPublicConnectorAuthClient = {\n readonly clientRegistration: \"dynamic\";\n readonly clientType: \"public\";\n};\n\nexport type StaticConnectorAuthClient =\n | StaticConfidentialConnectorAuthClient\n | StaticPublicConnectorAuthClient;\n\nexport type ConnectorAuthClient =\n | StaticConnectorAuthClient\n | DynamicPublicConnectorAuthClient;\n\nexport type ConnectorAuthClientIdentity =\n | StaticConfidentialConnectorAuthClientIdentity\n | StaticPublicConnectorAuthClient\n | DynamicPublicConnectorAuthClient;\n\nexport type ConnectorAuthClientForConfig<\n Client extends ConnectorAuthClientConfig,\n> = Client extends StaticConfidentialConnectorAuthClientConfig\n ? StaticConfidentialConnectorAuthClient\n : Client extends StaticPublicConnectorAuthClientConfig\n ? StaticPublicConnectorAuthClient\n : Client extends DynamicPublicConnectorAuthClientConfig\n ? DynamicPublicConnectorAuthClient\n : never;\n\nexport type ConnectorAuthClientForMethod<\n Type extends ConnectorType,\n Method extends ConnectorAuthMethodIds<Type>,\n> = ConnectorAuthClientForConfig<\n ConnectorAuthClientConfigForMethod<Type, Method>\n>;\n\nexport type ConnectorAuthClientIdentityForConfig<\n Client extends ConnectorAuthClientConfig,\n> = Client extends StaticConfidentialConnectorAuthClientConfig\n ? StaticConfidentialConnectorAuthClientIdentity\n : Client extends StaticPublicConnectorAuthClientConfig\n ? StaticPublicConnectorAuthClient\n : Client extends DynamicPublicConnectorAuthClientConfig\n ? DynamicPublicConnectorAuthClient\n : never;\n\nexport type ConnectorAuthClientIdentityForMethod<\n Type extends ConnectorType,\n Method extends ConnectorAuthMethodIds<Type>,\n> = ConnectorAuthClientIdentityForConfig<\n ConnectorAuthClientConfigForMethod<Type, Method>\n>;\n\nexport type ConnectorResolvedAuthMethodClient<\n Type extends ConnectorType,\n Method extends ConnectorAuthMethodIds<Type>,\n> = {\n readonly type: Type;\n readonly authMethod: Method;\n readonly authClient: ConnectorAuthClientForMethod<Type, Method>;\n};\n\nexport type ConnectorGrantKindWithAuthClient =\n | \"auth-code\"\n | \"external-code\"\n | \"device-auth\";\n\nexport type ConnectorResolvedAuthMethodClientByGrantKind<\n Kind extends ConnectorGrantKindWithAuthClient,\n> = {\n readonly [Type in ConnectorTypesByGrantKind<Kind>]: {\n readonly [Method in ConnectorAuthMethodIdsByGrantKind<\n Type,\n Kind\n >]: ConnectorResolvedAuthMethodClient<Type, Method>;\n }[ConnectorAuthMethodIdsByGrantKind<Type, Kind>];\n}[ConnectorTypesByGrantKind<Kind>];\n\nexport type ConnectorResolvedAuthMethodClientByAccessKind<\n Kind extends \"refresh-token\",\n> = {\n readonly [Type in ConnectorTypesByAccessKind<Kind>]: {\n readonly [Method in ConnectorAuthMethodIdsByAccessKind<\n Type,\n Kind\n >]: ConnectorResolvedAuthMethodClient<Type, Method>;\n }[ConnectorAuthMethodIdsByAccessKind<Type, Kind>];\n}[ConnectorTypesByAccessKind<Kind>];\n\nexport function isStaticConnectorAuthClient(\n authClient: ConnectorAuthClient,\n): authClient is StaticConnectorAuthClient {\n return authClient.clientRegistration === \"static\";\n}\n\nexport function isStaticConfidentialConnectorAuthClient(\n authClient: ConnectorAuthClient,\n): authClient is StaticConfidentialConnectorAuthClient {\n return (\n isStaticConnectorAuthClient(authClient) &&\n authClient.clientType === \"confidential\"\n );\n}\n\nexport function connectorAuthClientIdentity(\n authClient: StaticConfidentialConnectorAuthClient,\n): StaticConfidentialConnectorAuthClientIdentity;\nexport function connectorAuthClientIdentity(\n authClient: StaticPublicConnectorAuthClient,\n): StaticPublicConnectorAuthClient;\nexport function connectorAuthClientIdentity(\n authClient: DynamicPublicConnectorAuthClient,\n): DynamicPublicConnectorAuthClient;\nexport function connectorAuthClientIdentity(\n authClient: ConnectorAuthClient,\n): ConnectorAuthClientIdentity;\nexport function connectorAuthClientIdentity(\n authClient: ConnectorAuthClient,\n): ConnectorAuthClientIdentity {\n switch (authClient.clientRegistration) {\n case \"dynamic\":\n return authClient;\n case \"static\":\n return {\n clientRegistration: \"static\",\n clientType: authClient.clientType,\n clientId: authClient.clientId,\n };\n }\n}\n\nexport function connectorAuthClientIdentityForMethod<\n Type extends ConnectorType,\n Method extends ConnectorAuthMethodIds<Type>,\n>(\n authClient: ConnectorAuthClientForMethod<Type, Method>,\n): ConnectorAuthClientIdentityForMethod<Type, Method> {\n return connectorAuthClientIdentity(\n authClient,\n ) as ConnectorAuthClientIdentityForMethod<Type, Method>;\n}\n\nexport function getConnectorAuthClientConfigForMethod<\n Type extends ConnectorType,\n Method extends ConnectorAuthMethodIds<Type>,\n>(\n type: Type,\n authMethod: Method,\n): ConnectorAuthClientConfigForMethod<Type, Method> | undefined;\nexport function getConnectorAuthClientConfigForMethod(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthClientConfig | undefined;\nexport function getConnectorAuthClientConfigForMethod(\n type: ConnectorType,\n authMethod: string,\n): ConnectorAuthClientConfig | undefined {\n return getConnectorAuthMethod(type, authMethod)?.client;\n}\n\nexport function resolveConnectorAuthClient<\n Client extends ConnectorAuthClientConfig,\n>(\n client: Client,\n readEnv: ConnectorEnvReader,\n): ConnectorAuthClientForConfig<Client> | undefined;\nexport function resolveConnectorAuthClient(\n client: ConnectorAuthClientConfig,\n readEnv: ConnectorEnvReader,\n): ConnectorAuthClient | undefined {\n if (client.clientRegistration === \"dynamic\") {\n return { clientRegistration: \"dynamic\", clientType: \"public\" };\n }\n\n if (\"clientId\" in client) {\n if (client.clientType === \"confidential\") {\n return {\n clientRegistration: \"static\",\n clientType: \"confidential\",\n clientId: client.clientId,\n clientSecret: client.clientSecret,\n };\n }\n return {\n clientRegistration: \"static\",\n clientType: \"public\",\n clientId: client.clientId,\n };\n }\n\n const clientId = readEnv(client.clientIdEnv);\n if (!clientId) {\n return undefined;\n }\n\n if (client.clientType === \"public\") {\n return { clientRegistration: \"static\", clientType: \"public\", clientId };\n }\n\n const clientSecret = readEnv(client.clientSecretEnv);\n if (!clientSecret) {\n return undefined;\n }\n\n return {\n clientRegistration: \"static\",\n clientType: \"confidential\",\n clientId,\n clientSecret,\n };\n}\n\nexport function resolveConnectorAuthClientForMethod<\n Type extends ConnectorType,\n Method extends ConnectorAuthMethodIds<Type>,\n>(\n type: Type,\n authMethod: Method,\n readEnv: ConnectorEnvReader,\n): ConnectorAuthClientForMethod<Type, Method> | undefined;\nexport function resolveConnectorAuthClientForMethod(\n type: ConnectorType,\n authMethod: string,\n readEnv: ConnectorEnvReader,\n): ConnectorAuthClient | undefined;\nexport function resolveConnectorAuthClientForMethod(\n type: ConnectorType,\n authMethod: string,\n readEnv: ConnectorEnvReader,\n): ConnectorAuthClient | undefined {\n const clientConfig = getConnectorAuthClientConfigForMethod(type, authMethod);\n if (!clientConfig) {\n return undefined;\n }\n return resolveConnectorAuthClient(clientConfig, readEnv);\n}\n\ntype AnyConnectorResolvedAuthMethodClient = {\n readonly type: ConnectorType;\n readonly authMethod: ConnectorAuthMethodId;\n readonly authClient: ConnectorAuthClient;\n};\n\nfunction resolveConnectorResolvedAuthMethodClient(\n authMethodRef: ConnectorAuthMethodRef,\n readEnv: ConnectorEnvReader,\n): AnyConnectorResolvedAuthMethodClient | undefined {\n const authClient = resolveConnectorAuthClientForMethod(\n authMethodRef.type,\n authMethodRef.authMethod,\n readEnv,\n );\n if (!authClient) {\n return undefined;\n }\n return {\n type: authMethodRef.type,\n authMethod: authMethodRef.authMethod,\n authClient,\n };\n}\n\nexport function resolveConnectorResolvedAuthMethodClientByGrantKind(\n authMethodRef: ConnectorAuthMethodRefByGrantKind<\"auth-code\">,\n readEnv: ConnectorEnvReader,\n): ConnectorResolvedAuthMethodClientByGrantKind<\"auth-code\"> | undefined;\nexport function resolveConnectorResolvedAuthMethodClientByGrantKind(\n authMethodRef: ConnectorAuthMethodRefByGrantKind<\"external-code\">,\n readEnv: ConnectorEnvReader,\n): ConnectorResolvedAuthMethodClientByGrantKind<\"external-code\"> | undefined;\nexport function resolveConnectorResolvedAuthMethodClientByGrantKind(\n authMethodRef: ConnectorAuthMethodRefByGrantKind<\"device-auth\">,\n readEnv: ConnectorEnvReader,\n): ConnectorResolvedAuthMethodClientByGrantKind<\"device-auth\"> | undefined;\nexport function resolveConnectorResolvedAuthMethodClientByGrantKind(\n authMethodRef: ConnectorAuthMethodRefByGrantKind<ConnectorGrantKindWithAuthClient>,\n readEnv: ConnectorEnvReader,\n): AnyConnectorResolvedAuthMethodClient | undefined {\n return resolveConnectorResolvedAuthMethodClient(authMethodRef, readEnv);\n}\n\nexport function resolveConnectorResolvedAuthMethodClientByAccessKind(\n authMethodRef: ConnectorAuthMethodRefByAccessKind<\"refresh-token\">,\n readEnv: ConnectorEnvReader,\n): ConnectorResolvedAuthMethodClientByAccessKind<\"refresh-token\"> | undefined;\nexport function resolveConnectorResolvedAuthMethodClientByAccessKind(\n authMethodRef: ConnectorAuthMethodRefByAccessKind<\"refresh-token\">,\n readEnv: ConnectorEnvReader,\n): AnyConnectorResolvedAuthMethodClient | undefined {\n return resolveConnectorResolvedAuthMethodClient(authMethodRef, readEnv);\n}\n\nfunction hasRuntimeAvailableAuthMethod(\n readEnv: ConnectorEnvReader,\n type: ConnectorType,\n): boolean {\n for (const authMethod of getConfiguredConnectorAuthMethodIds(type)) {\n const method = getConnectorAuthMethod(type, authMethod);\n switch (method?.grant.kind) {\n case \"auth-code\":\n case \"external-code\":\n case \"device-auth\": {\n if (resolveConnectorAuthClientForMethod(type, authMethod, readEnv)) {\n return true;\n }\n break;\n }\n case \"manual\": {\n return true;\n }\n case \"managed\":\n case undefined: {\n break;\n }\n }\n }\n return false;\n}\n\n/**\n * Return connector types the current runtime can offer as connection candidates.\n *\n * This is not user connected state and it does not evaluate feature switches.\n * It includes connectors with user-entered manual grant methods because they\n * do not require a server auth client, while auth-provider methods require\n * their runtime client env to exist unless their client config is static inline.\n */\nexport function getRuntimeAvailableConnectorTypes(\n readEnv: ConnectorEnvReader,\n): ConnectorType[] {\n const runtimeAvailable = new Set<ConnectorType>();\n\n for (const type of CONNECTOR_TYPE_KEYS) {\n if (hasRuntimeAvailableAuthMethod(readEnv, type)) {\n runtimeAvailable.add(type);\n }\n }\n\n return [...runtimeAvailable].sort();\n}\n\n/**\n * Get connector-owned secret storage names for a specific auth method.\n */\nexport function getConnectorOwnedSecretNames(\n type: ConnectorType,\n authMethod: string,\n): string[] {\n return connectorAuthMethodOwnedSecretNames(\n getConnectorAuthMethod(type, authMethod),\n );\n}\n\n/**\n * Get connector-owned variable storage names for a specific auth method.\n */\nexport function getConnectorOwnedVariableNames(\n type: ConnectorType,\n authMethod: string,\n): string[] {\n return connectorAuthMethodOwnedVariableNames(\n getConnectorAuthMethod(type, authMethod),\n );\n}\n\nfunction connectorAuthMethodOwnedSecretNames(\n method: ConnectorAuthMethodConfig | undefined,\n): string[] {\n return method ? [...method.storage.secrets] : [];\n}\n\nfunction connectorAuthMethodOwnedVariableNames(\n method: ConnectorAuthMethodConfig | undefined,\n): string[] {\n return method ? [...method.storage.variables] : [];\n}\n\n/**\n * Get runtime environment bindings for a specific connector auth method.\n */\nexport function getConnectorAuthMethodEnvBindings(\n type: ConnectorType,\n authMethod: string,\n): ConnectorRuntimeEnvBindings {\n const method = getConnectorAuthMethod(type, authMethod);\n return method ? connectorAccessRuntimeEnvBindings(method.access) : {};\n}\n\nexport interface ConnectorEnvBindingEntry {\n readonly authMethod: ConnectorAuthMethodId;\n readonly envName: string;\n readonly valueRef: string;\n}\n\n/**\n * Get all configured environment binding entries across auth methods.\n *\n * This is for discovery and reverse lookup. Runtime injection must use\n * getConnectorAuthMethodEnvBindings() with the selected auth method.\n */\nexport function getConnectorEnvBindingEntries(\n type: ConnectorType,\n): ConnectorEnvBindingEntry[] {\n const entries: ConnectorEnvBindingEntry[] = [];\n for (const authMethod of getConfiguredConnectorAuthMethodIds(type)) {\n const envBindings = getConnectorAuthMethodEnvBindings(type, authMethod);\n for (const [envName, valueRef] of Object.entries(envBindings)) {\n entries.push({ authMethod, envName, valueRef });\n }\n }\n return entries;\n}\n\nexport interface ConnectorStoredSecretDisplayInfo {\n readonly connectorLabel: string;\n readonly envNames: string[];\n}\n\n/**\n * Diagnostic/display lookup for a stored connector secret name.\n *\n * This reverse-searches registry metadata to explain which runtime env aliases\n * can expose a stored secret. Runtime injection must use selected auth method\n * storage metadata instead.\n */\nexport function getConnectorStoredSecretDisplayInfo(\n secretName: string,\n): ConnectorStoredSecretDisplayInfo | null {\n const allTypes = CONNECTOR_TYPE_KEYS;\n\n for (const type of allTypes) {\n const config = CONNECTOR_TYPES[type];\n\n const found = Object.values(config.authMethods).some((method) => {\n return connectorAuthMethodOwnedSecretNames(method).includes(secretName);\n });\n if (!found) {\n continue;\n }\n\n const envNames = [\n ...new Set(\n getConnectorEnvBindingEntries(type)\n .filter(({ valueRef }) => {\n return valueRef === `$secrets.${secretName}`;\n })\n .map(({ envName }) => {\n return envName;\n }),\n ),\n ];\n\n if (envNames.length > 0) {\n return { connectorLabel: config.label, envNames };\n }\n }\n\n return null;\n}\n\n/**\n * Diagnostic lookup for a runtime env alias declared by connector env bindings.\n *\n * This is for human-facing commands such as CLI doctor; runtime connector\n * behavior must use selected auth method metadata.\n */\nexport function getDiagnosticConnectorTypeForRuntimeEnvName(\n envName: string,\n): ConnectorType | null {\n for (const type of CONNECTOR_TYPE_KEYS) {\n const hasEnvName = getConnectorEnvBindingEntries(type).some((entry) => {\n return entry.envName === envName;\n });\n if (hasEnvName) {\n return type;\n }\n }\n return null;\n}\n\nexport function hasConnectorAuthCodeGrant(\n type: ConnectorType,\n): type is AuthCodeGrantConnectorType {\n return getConnectorAuthMethodIdsForGrantKind(type, \"auth-code\").length > 0;\n}\n\nexport function hasConnectorExternalCodeGrant(\n type: ConnectorType,\n): type is ExternalCodeGrantConnectorType {\n return (\n getConnectorAuthMethodIdsForGrantKind(type, \"external-code\").length > 0\n );\n}\n\nexport function hasConnectorDeviceAuthGrant(\n type: ConnectorType,\n): type is DeviceAuthGrantConnectorType {\n return getConnectorAuthMethodIdsForGrantKind(type, \"device-auth\").length > 0;\n}\n\nfunction hasRequiredGrantScopes(\n requiredScopes: readonly string[],\n storedScopes: string[] | null,\n): boolean {\n if (requiredScopes.length === 0) return true;\n if (!storedScopes) return false;\n const storedSet = new Set(storedScopes);\n return requiredScopes.every((s) => {\n return storedSet.has(s);\n });\n}\n\n/**\n * Compute the diff between currently required scopes and stored scopes for a connector.\n */\nexport interface ScopeDiff {\n addedScopes: string[];\n removedScopes: string[];\n currentScopes: string[];\n storedScopes: string[];\n}\n\nfunction scopeDiff(\n currentScopes: readonly string[],\n storedScopes: string[] | null,\n): ScopeDiff {\n const stored = storedScopes ?? [];\n const storedSet = new Set(stored);\n const currentSet = new Set(currentScopes);\n\n return {\n addedScopes: currentScopes.filter((s) => {\n return !storedSet.has(s);\n }),\n removedScopes: stored.filter((s) => {\n return !currentSet.has(s);\n }),\n currentScopes: [...currentScopes],\n storedScopes: stored,\n };\n}\n\nexport function hasRequiredConnectorAuthMethodScopes(\n connectorType: ConnectorType,\n authMethod: string,\n storedScopes: string[] | null,\n): boolean {\n return hasRequiredGrantScopes(\n getConnectorAuthMethodGrantScopes(connectorType, authMethod),\n storedScopes,\n );\n}\n\nexport function getConnectorAuthMethodScopeDiff(\n connectorType: ConnectorType,\n authMethod: string,\n storedScopes: string[] | null,\n): ScopeDiff {\n return scopeDiff(\n getConnectorAuthMethodGrantScopes(connectorType, authMethod),\n storedScopes,\n );\n}\n"],"mappings":"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","names":[]}