@installagent/sdk 0.6.0 → 0.7.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.
@@ -0,0 +1,318 @@
1
+ import { execFailureDetail, execFileAsync } from "./exec.js";
2
+ import { describeInspectFailure, gcloudArgs, validateGcpTarget } from "./gcp-inspect.js";
3
+ /**
4
+ * `ia gcp setup` (2026-10-25): bring one Google Cloud project to the state a
5
+ * client build needs — the project itself, billing, the APIs, Service Usage
6
+ * Admin for a team account, and one service account with NO roles.
7
+ *
8
+ * Plan by default: it only reads, then lists each step as `done` (nothing
9
+ * to do), `todo` (with the exact gcloud command), `blocked` (with the
10
+ * reason) or `unknown` (a read failed; not a blocker). `apply: true` runs the
11
+ * todo steps in order and stops at the first failure. Every step is
12
+ * check-then-skip, so a re-run after a failure continues where it stopped.
13
+ * It never deletes, never grants a role to the service account, never
14
+ * grants anything to an address outside installagent.com, and never mints a
15
+ * key (that is `ia secrets mint gcp-service-account-key --to-op`).
16
+ */
17
+ export const GCP_TEAM_DOMAIN = "installagent.com";
18
+ export const SERVICE_USAGE_ADMIN = "roles/serviceusage.serviceUsageAdmin";
19
+ /** A new project ID: 6–30 characters, starts with a letter, no trailing hyphen. */
20
+ const NEW_PROJECT_ID = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
21
+ /** A service-account name: 6–30 characters, same shape. */
22
+ const SA_NAME = /^[a-z][a-z0-9-]{4,28}[a-z0-9]$/;
23
+ const SERVICE = /^[a-z0-9.-]+\.googleapis\.com$/;
24
+ const NUMERIC_ID = /^\d{6,20}$/;
25
+ const BILLING_ID = /^[0-9A-F]{6}-[0-9A-F]{6}-[0-9A-F]{6}$/;
26
+ /** One gcloud command as text a technician can paste, with the forced flags. */
27
+ export function formatGcloud(args) {
28
+ return ["gcloud", ...args].map((a) => (/^[\w@%+=:,./-]+$/.test(a) ? a : `'${a}'`)).join(" ");
29
+ }
30
+ export async function gcpSetup(options) {
31
+ const project = options.project.trim();
32
+ const account = options.account.trim();
33
+ validateGcpTarget(project, account);
34
+ const apis = [
35
+ ...new Set((options.apis?.length ? options.apis : ["gmail.googleapis.com"]).map((a) => a.trim())),
36
+ ];
37
+ for (const api of apis) {
38
+ if (!SERVICE.test(api))
39
+ throw new Error(`invalid API "${api}" — expected e.g. pubsub.googleapis.com`);
40
+ }
41
+ if (options.create) {
42
+ if (!NEW_PROJECT_ID.test(project)) {
43
+ throw new Error(`"${project}" cannot be a new project ID — 6–30 characters: lowercase letters, digits, hyphens`);
44
+ }
45
+ if (!options.organization === !options.folder) {
46
+ throw new Error("--create needs exactly one of --organization <id> or --folder <id> (ia gcp inspect shows the parent)");
47
+ }
48
+ }
49
+ for (const [flag, value] of [
50
+ ["--organization", options.organization],
51
+ ["--folder", options.folder],
52
+ ]) {
53
+ if (value !== undefined && !NUMERIC_ID.test(value))
54
+ throw new Error(`${flag} takes the numeric ID, got "${value}"`);
55
+ }
56
+ if (options.billing !== undefined && !BILLING_ID.test(options.billing)) {
57
+ throw new Error(`--billing takes a billing account ID like 0X0X0X-0X0X0X-0X0X0X, got "${options.billing}"`);
58
+ }
59
+ const grantee = options.grantServiceUsage?.trim().toLowerCase();
60
+ if (grantee !== undefined &&
61
+ !new RegExp(`^[^\\s@]+@${GCP_TEAM_DOMAIN.replace(".", "\\.")}$`).test(grantee)) {
62
+ throw new Error(`--grant-service-usage takes an ${GCP_TEAM_DOMAIN} account only, got "${grantee}"`);
63
+ }
64
+ const saName = options.serviceAccount?.trim();
65
+ if (saName !== undefined && !SA_NAME.test(saName)) {
66
+ throw new Error(`invalid service-account name "${saName}" — 6–30 characters: lowercase letters, digits, hyphens`);
67
+ }
68
+ const exec = options.execFileImpl ?? execFileAsync;
69
+ const args = (a) => gcloudArgs(a, project, account);
70
+ const read = async (a) => (await exec("gcloud", args(a))).stdout;
71
+ // ── Plan: reads only ──────────────────────────────────────────────────
72
+ const steps = [];
73
+ let projectExists = true;
74
+ try {
75
+ await read(["projects", "describe", project, "--format=value(projectId)"]);
76
+ steps.push({ id: "project", title: `Project ${project}`, status: "done", detail: "exists" });
77
+ }
78
+ catch (error) {
79
+ projectExists = false;
80
+ const detail = describeInspectFailure(error, account);
81
+ // gcloud says PERMISSION_DENIED for a project that does not exist too,
82
+ // so "missing" and "not visible" look the same; --create decides.
83
+ if (/login expired|gcloud CLI not found/.test(detail) || !options.create) {
84
+ steps.push({
85
+ id: "project",
86
+ title: `Project ${project}`,
87
+ status: "blocked",
88
+ detail: options.create
89
+ ? detail
90
+ : `not found, or ${account} cannot see it (${detail}). To make it, pass --create with --organization or --folder`,
91
+ });
92
+ }
93
+ else {
94
+ const parent = options.organization
95
+ ? `--organization=${options.organization}`
96
+ : `--folder=${options.folder}`;
97
+ steps.push({
98
+ id: "project",
99
+ title: `Project ${project}`,
100
+ status: "todo",
101
+ command: args([
102
+ "projects",
103
+ "create",
104
+ project,
105
+ parent,
106
+ `--name=${options.name?.trim() || project}`,
107
+ ]),
108
+ detail: "will be created (the ID is global: create fails if anyone has it)",
109
+ });
110
+ }
111
+ }
112
+ const needsBilling = apis.includes("pubsub.googleapis.com");
113
+ if (options.billing || needsBilling) {
114
+ const link = options.billing
115
+ ? args(["billing", "projects", "link", project, `--billing-account=${options.billing}`])
116
+ : undefined;
117
+ let enabled = null;
118
+ let readError = "";
119
+ if (projectExists) {
120
+ try {
121
+ enabled = /true/i.test(await read(["billing", "projects", "describe", project, "--format=value(billingEnabled)"]));
122
+ }
123
+ catch (error) {
124
+ readError = describeInspectFailure(error, account);
125
+ }
126
+ }
127
+ else {
128
+ enabled = false;
129
+ }
130
+ if (enabled) {
131
+ steps.push({ id: "billing", title: "Billing", status: "done", detail: "enabled" });
132
+ }
133
+ else if (enabled === false && link) {
134
+ steps.push({
135
+ id: "billing",
136
+ title: "Billing",
137
+ status: "todo",
138
+ command: link,
139
+ detail: "will be linked",
140
+ });
141
+ }
142
+ else if (enabled === false) {
143
+ steps.push({
144
+ id: "billing",
145
+ title: "Billing",
146
+ status: "blocked",
147
+ detail: "off, and Pub/Sub needs it — pass --billing <billing account ID>",
148
+ });
149
+ }
150
+ else {
151
+ steps.push({
152
+ id: "billing",
153
+ title: "Billing",
154
+ status: link ? "todo" : "unknown",
155
+ command: link,
156
+ detail: `could not read (${readError})${link ? "; will link" : "; Pub/Sub fails to enable if it is off"}`,
157
+ });
158
+ }
159
+ }
160
+ // A failed read enables all of them: enabling an API that is on is a no-op.
161
+ let missing = apis;
162
+ let apisNote = "";
163
+ if (projectExists) {
164
+ try {
165
+ const enabled = (await read(["services", "list", "--enabled", "--format=value(config.name)"]))
166
+ .split("\n")
167
+ .map((l) => l.trim());
168
+ missing = apis.filter((a) => !enabled.includes(a));
169
+ }
170
+ catch (error) {
171
+ apisNote = `could not list enabled APIs (${describeInspectFailure(error, account)}); `;
172
+ }
173
+ }
174
+ steps.push(missing.length
175
+ ? {
176
+ id: "apis",
177
+ title: "APIs",
178
+ status: "todo",
179
+ command: args(["services", "enable", ...missing]),
180
+ detail: `${apisNote}will enable ${missing.join(", ")}`,
181
+ }
182
+ : { id: "apis", title: "APIs", status: "done", detail: `${apis.join(", ")} already on` });
183
+ if (grantee) {
184
+ const member = `user:${grantee}`;
185
+ const grant = args([
186
+ "projects",
187
+ "add-iam-policy-binding",
188
+ project,
189
+ `--member=${member}`,
190
+ `--role=${SERVICE_USAGE_ADMIN}`,
191
+ "--condition=None",
192
+ ]);
193
+ let has = false;
194
+ let readError = "";
195
+ if (projectExists) {
196
+ try {
197
+ const policy = JSON.parse((await read(["projects", "get-iam-policy", project, "--format=json"])) || "{}");
198
+ has = (policy.bindings ?? []).some((b) => b.role === SERVICE_USAGE_ADMIN && (b.members ?? []).includes(member));
199
+ }
200
+ catch (error) {
201
+ readError = describeInspectFailure(error, account);
202
+ }
203
+ }
204
+ steps.push(has
205
+ ? {
206
+ id: "service-usage-admin",
207
+ title: `Service Usage Admin for ${grantee}`,
208
+ status: "done",
209
+ detail: "granted",
210
+ }
211
+ : {
212
+ id: "service-usage-admin",
213
+ title: `Service Usage Admin for ${grantee}`,
214
+ status: "todo",
215
+ command: grant,
216
+ detail: readError
217
+ ? `could not read IAM (${readError}); will grant (no-op if granted)`
218
+ : "will grant",
219
+ });
220
+ }
221
+ if (saName) {
222
+ const email = `${saName}@${project}.iam.gserviceaccount.com`;
223
+ let exists = false;
224
+ if (projectExists) {
225
+ try {
226
+ await read(["iam", "service-accounts", "describe", email, "--format=value(email)"]);
227
+ exists = true;
228
+ }
229
+ catch {
230
+ exists = false;
231
+ }
232
+ }
233
+ steps.push(exists
234
+ ? {
235
+ id: "service-account",
236
+ title: `Service account ${email}`,
237
+ status: "done",
238
+ detail: "exists",
239
+ }
240
+ : {
241
+ id: "service-account",
242
+ title: `Service account ${email}`,
243
+ status: "todo",
244
+ command: args([
245
+ "iam",
246
+ "service-accounts",
247
+ "create",
248
+ saName,
249
+ `--display-name=${saName}`,
250
+ ]),
251
+ detail: "will be created with no roles",
252
+ });
253
+ }
254
+ const blocked = steps.some((s) => s.status === "blocked");
255
+ const todo = steps.some((s) => s.status === "todo");
256
+ const nextSteps = [];
257
+ if (!options.apply || blocked || !todo) {
258
+ if (blocked)
259
+ nextSteps.push("Fix the blocked step(s), then run the plan again.");
260
+ else if (todo)
261
+ nextSteps.push("Read the commands above, then run the same command with --apply.");
262
+ else
263
+ nextSteps.push("Nothing to do — the project is already set up.");
264
+ if (options.apply && blocked)
265
+ nextSteps.push("--apply ran nothing because a step is blocked.");
266
+ return { project, account, applied: false, ok: !blocked, steps, nextSteps };
267
+ }
268
+ // ── Apply: run the todo steps in order, stop at the first failure ─────
269
+ let failed = false;
270
+ for (const step of steps) {
271
+ if (step.status !== "todo" || !step.command)
272
+ continue;
273
+ if (failed) {
274
+ step.status = "skipped";
275
+ continue;
276
+ }
277
+ try {
278
+ await exec("gcloud", step.command);
279
+ step.status = "ran";
280
+ step.detail = ranDetail(step, missing);
281
+ }
282
+ catch (error) {
283
+ failed = true;
284
+ step.status = "failed";
285
+ step.detail = describeApplyFailure(error, account);
286
+ }
287
+ }
288
+ if (failed)
289
+ nextSteps.push("Fix the failed step, then run the same command again: done steps are skipped.");
290
+ else
291
+ nextSteps.push(`Check the result: ia gcp inspect -p ${project} -a ${account}`);
292
+ return { project, account, applied: true, ok: !failed, steps, nextSteps };
293
+ }
294
+ /** What a step that ran did — the plan's detail says "will …". */
295
+ function ranDetail(step, enabledApis) {
296
+ switch (step.id) {
297
+ case "project":
298
+ return "created";
299
+ case "billing":
300
+ return "linked";
301
+ case "apis":
302
+ return `enabled ${enabledApis.join(", ")}`;
303
+ case "service-usage-admin":
304
+ return "granted";
305
+ case "service-account":
306
+ return "created with no roles";
307
+ }
308
+ }
309
+ function describeApplyFailure(error, account) {
310
+ const { detail } = execFailureDetail(error);
311
+ if (/already exists|ALREADY_EXISTS/i.test(detail)) {
312
+ return `already exists — if it is not ours, pick another ID. gcloud said: ${firstLine(detail)}`;
313
+ }
314
+ return describeInspectFailure(error, account);
315
+ }
316
+ function firstLine(text) {
317
+ return (text.split("\n").find((l) => l.trim()) ?? text).trim().slice(0, 300);
318
+ }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { AIRTABLE_API_TOKEN_ENV, buildAssertionClaims, ClientDriveAuthError, typ
7
7
  export { ClientIntakeAuthError, type ClientIntakeInput, type ClientIntakeOptions, type ClientIntakeResult, type ClientIntakeStep, clientIntake, LINEAR_CLIENT_TEAM_ID_ENV, } from "./client-intake.js";
8
8
  export { ClientLinearAuthError, type ClientLinearProjectOptions, clientLinearProject, parseLinearProjectSlugId, type ResolvedClientLinearProject, resolveClientLinearProject, } from "./client-linear.js";
9
9
  export { type ClientLinearCreateIssueInput, type ClientLinearCreateIssueResult, clientLinearCreateIssue, } from "./client-linear-create.js";
10
+ export { GCP_MANIFEST_KEYS, type GcpManifest, type GcpManifestKey, readGcpManifest, readGcpManifestFromRepo, readManifestKey, } from "./client-manifest.js";
10
11
  export { DOCS_SEARCH_TOKEN_ENV, DOCS_SESSION_ENV, type DocsSearchOptions, type DocsSearchResponse, type DocsSearchResult, DocsSessionError, docsSearch, TEAM_DOCS_BASE_URL, } from "./docs-search.js";
11
12
  export { type DoctorCheck, type DoctorOptions, type DoctorResult, type DoctorStatus, doctor, } from "./doctor.js";
12
13
  export { findWorkspaceRoot, type LoadWorkspaceEnvOptions, type LoadWorkspaceEnvResult, loadWorkspaceEnv, parseEnvFile, } from "./env-file.js";
@@ -14,7 +15,10 @@ export { type EnvFillOptions, type EnvFillResult, type EnvFillVarResult, type En
14
15
  export { type EnvPushOptions, type EnvPushResult, type EnvPushVarResult, type EnvPushVarStatus, envPush, } from "./env-push.js";
15
16
  export { ADMIN_ENV_VARS, DEFAULT_TECH_VAULT, ENV_VARS, type EnvVarRole, type EnvVarSource, type EnvVarSpec, type EnvVarTier, envVarRole, envVarsForRole, GEMINI_API_KEY_ENV, INFRA_VAULT, opSecretReference, renderEnvExample, TECH_ENV_VARS, } from "./env-registry.js";
16
17
  export { FATHOM_API_BASE_URL, FATHOM_API_KEY_ENV, FATHOM_INCLUDES, FATHOM_TRIGGERS, type MintFathomWebhookOptions, type MintFathomWebhookResult, mintFathomWebhook, } from "./fathom-webhook.js";
18
+ export { DWD_ADMIN_CONSOLE_URL, dwdAdminText, type GcpDwdOptions, type GcpDwdResult, type GcpDwdStep, gcpDwd, KEY_CREATION_POLICY, normalizeDwdScope, } from "./gcp-dwd.js";
19
+ export { describePolicy, GCP_INSPECT_KEY_APIS, GCP_INSPECT_POLICIES, GCP_KEY_MAX_AGE_DAYS, type GcpApiCaller, type GcpApiCallsInfo, type GcpApisInfo, type GcpIamInfo, type GcpInspectOptions, type GcpInspectResult, type GcpKeyInfo, type GcpPolicyState, type GcpProjectInfo, type GcpSection, type GcpServiceAccountInfo, gcloudArgs, gcpInspect, maskCredential, maskMember, validateGcpTarget, } from "./gcp-inspect.js";
17
20
  export { type ExecFileFn, MINT_HANDOFF_WARNING, type MintGcpServiceAccountKeyOptions, type MintGcpServiceAccountKeyResult, mintGcpServiceAccountKey, } from "./gcp-service-account-key.js";
21
+ export { formatGcloud, GCP_TEAM_DOMAIN, type GcpSetupOptions, type GcpSetupResult, type GcpStep, type GcpStepStatus, gcpSetup, SERVICE_USAGE_ADMIN, } from "./gcp-setup.js";
18
22
  export { DEFAULT_GEMINI_KEY_DISPLAY_NAME, GEMINI_API_TARGET, type MintGeminiApiKeyOptions, type MintGeminiApiKeyResult, mintGeminiApiKey, } from "./gemini-api-key.js";
19
23
  export { type CloneFn, type CloneOptions, gitClone, gitPullFfOnly, type PullFn } from "./git.js";
20
24
  export { GITHUB_TOKEN_FIX, type ResolvedGithubToken, type ResolveGithubTokenOptions, resolveGithubToken, } from "./github-token.js";
@@ -30,6 +34,7 @@ export { applyClientDefaults, clientWorkflowName, DEFAULT_EXECUTION_TIMEOUT_S, D
30
34
  export { type ExtractNodeOutputsOptions, extractNodeOutputs, listN8nExecutions, listNodesRun, type N8nExecutionDetail, type N8nExecutionStatus, type N8nExecutionSummary, type N8nExecutionsInput, type N8nExecutionsOptions, type N8nExecutionsResult, type N8nNodeOutput, unflattenExecutionData, } from "./n8n-executions.js";
31
35
  export { type NewClientOptions, type NewClientResult, newClient, SLUG_PATTERN, } from "./new-client.js";
32
36
  export { opInstallCommand, opInstallFix, opIntegrationFix } from "./op-cli.js";
37
+ export { defaultOpTitle, type MintImpls, type MintToOpOptions, type MintToOpRequest, type MintToOpResult, mintToOnePassword, } from "./op-store.js";
33
38
  export { type PingResult, ping } from "./ping.js";
34
39
  export { detectPlatform, detectPlatformInfo, detectShell, opNeedsAnotherShell, type Platform, type PlatformInfo, type Shell, } from "./platform.js";
35
40
  export { DEFAULT_PORTAL_URL, PORTAL_ADMIN_SECRET_ENV, PORTAL_BUILD_TYPES, PORTAL_PASSWORD_WARNING, PORTAL_SYNC_MAX_DAYS, PORTAL_URL_ENV, type PortalAddUserInput, type PortalAddUserResult, PortalAdminAuthError, type PortalAdminOptions, type PortalAgent, type PortalAgentSyncRow, type PortalBuild, type PortalBuildType, type PortalCreateAgentInput, type PortalCreateBuildInput, type PortalCreateOrgInput, type PortalCreateOrgResult, type PortalListAgentsResult, type PortalListBuildsResult, type PortalListOrgsResult, type PortalOrg, type PortalOrgUser, PortalRequestError, type PortalSetAgentNameInput, type PortalSetAgentNameResult, type PortalSetAgentStatusInput, type PortalSetAgentStatusResult, type PortalSetAgentTriageResult, type PortalSetAgentWorkflowInput, type PortalSetAgentWorkflowResult, type PortalSetBuildStatusInput, type PortalSetDriveFolderResult, type PortalSetPasswordResult, type PortalSetUserInput, type PortalSetUserResult, type PortalSyncRunsResult, type PortalTriageBackfillResult, type PortalTriageProvider, type PortalTriageRecordsPage, portalAddUser, portalBackfillTriageRecords, portalBuildType, portalBuildWorkflowId, portalCreateAgent, portalCreateBuild, portalCreateOrg, portalListAgents, portalListBuilds, portalListOrgs, portalReadTriageRecords, portalSetAgentName, portalSetAgentStatus, portalSetAgentTriage, portalSetAgentWorkflow, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, portalSetDriveFolder, portalSetOrgSlackChannel, portalSetPassword, portalSetUser, portalSyncRuns, validatePortalBuildFields, } from "./portal-admin.js";
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export { AIRTABLE_API_TOKEN_ENV, buildAssertionClaims, ClientDriveAuthError, cli
10
10
  export { ClientIntakeAuthError, clientIntake, LINEAR_CLIENT_TEAM_ID_ENV, } from "./client-intake.js";
11
11
  export { ClientLinearAuthError, clientLinearProject, parseLinearProjectSlugId, resolveClientLinearProject, } from "./client-linear.js";
12
12
  export { clientLinearCreateIssue, } from "./client-linear-create.js";
13
+ export { GCP_MANIFEST_KEYS, readGcpManifest, readGcpManifestFromRepo, readManifestKey, } from "./client-manifest.js";
13
14
  export { DOCS_SEARCH_TOKEN_ENV, DOCS_SESSION_ENV, DocsSessionError, docsSearch, TEAM_DOCS_BASE_URL, } from "./docs-search.js";
14
15
  export { doctor, } from "./doctor.js";
15
16
  export { findWorkspaceRoot, loadWorkspaceEnv, parseEnvFile, } from "./env-file.js";
@@ -17,7 +18,10 @@ export { envFill, } from "./env-fill.js";
17
18
  export { envPush, } from "./env-push.js";
18
19
  export { ADMIN_ENV_VARS, DEFAULT_TECH_VAULT, ENV_VARS, envVarRole, envVarsForRole, GEMINI_API_KEY_ENV, INFRA_VAULT, opSecretReference, renderEnvExample, TECH_ENV_VARS, } from "./env-registry.js";
19
20
  export { FATHOM_API_BASE_URL, FATHOM_API_KEY_ENV, FATHOM_INCLUDES, FATHOM_TRIGGERS, mintFathomWebhook, } from "./fathom-webhook.js";
21
+ export { DWD_ADMIN_CONSOLE_URL, dwdAdminText, gcpDwd, KEY_CREATION_POLICY, normalizeDwdScope, } from "./gcp-dwd.js";
22
+ export { describePolicy, GCP_INSPECT_KEY_APIS, GCP_INSPECT_POLICIES, GCP_KEY_MAX_AGE_DAYS, gcloudArgs, gcpInspect, maskCredential, maskMember, validateGcpTarget, } from "./gcp-inspect.js";
20
23
  export { MINT_HANDOFF_WARNING, mintGcpServiceAccountKey, } from "./gcp-service-account-key.js";
24
+ export { formatGcloud, GCP_TEAM_DOMAIN, gcpSetup, SERVICE_USAGE_ADMIN, } from "./gcp-setup.js";
21
25
  export { DEFAULT_GEMINI_KEY_DISPLAY_NAME, GEMINI_API_TARGET, mintGeminiApiKey, } from "./gemini-api-key.js";
22
26
  export { gitClone, gitPullFfOnly } from "./git.js";
23
27
  export { GITHUB_TOKEN_FIX, resolveGithubToken, } from "./github-token.js";
@@ -33,6 +37,7 @@ export { applyClientDefaults, clientWorkflowName, DEFAULT_EXECUTION_TIMEOUT_S, D
33
37
  export { extractNodeOutputs, listN8nExecutions, listNodesRun, unflattenExecutionData, } from "./n8n-executions.js";
34
38
  export { newClient, SLUG_PATTERN, } from "./new-client.js";
35
39
  export { opInstallCommand, opInstallFix, opIntegrationFix } from "./op-cli.js";
40
+ export { defaultOpTitle, mintToOnePassword, } from "./op-store.js";
36
41
  export { ping } from "./ping.js";
37
42
  export { detectPlatform, detectPlatformInfo, detectShell, opNeedsAnotherShell, } from "./platform.js";
38
43
  export { DEFAULT_PORTAL_URL, PORTAL_ADMIN_SECRET_ENV, PORTAL_BUILD_TYPES, PORTAL_PASSWORD_WARNING, PORTAL_SYNC_MAX_DAYS, PORTAL_URL_ENV, PortalAdminAuthError, PortalRequestError, portalAddUser, portalBackfillTriageRecords, portalBuildType, portalBuildWorkflowId, portalCreateAgent, portalCreateBuild, portalCreateOrg, portalListAgents, portalListBuilds, portalListOrgs, portalReadTriageRecords, portalSetAgentName, portalSetAgentStatus, portalSetAgentTriage, portalSetAgentWorkflow, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, portalSetDriveFolder, portalSetOrgSlackChannel, portalSetPassword, portalSetUser, portalSyncRuns, validatePortalBuildFields, } from "./portal-admin.js";
package/dist/op-cli.d.ts CHANGED
@@ -17,7 +17,21 @@
17
17
  * technician following `brew install` text on Windows loses an hour finding
18
18
  * that out. See platform.ts for why we don't try to tell PowerShell from cmd.
19
19
  */
20
+ import { type ExecFileFn } from "./exec.js";
20
21
  import { type PlatformInfo } from "./platform.js";
22
+ /**
23
+ * True when op is installed and can reach the vaults; otherwise the fix-it step.
24
+ * Shared by `ia env fill`, `ia env push` and `ia secrets mint --to-op`.
25
+ *
26
+ * `op whoami` is the obvious probe but NOT a sufficient one: with the desktop
27
+ * app integration on, op 2.35 answers "account is not signed in" to `whoami`
28
+ * while `op read` and `op vault list` both work — the CLI has no session of its
29
+ * own, and the app authorizes each call. Failing there told a technician to
30
+ * enable an integration that was already enabled, and blocked a command that
31
+ * would have succeeded. So a `whoami` failure falls through to `op vault list`,
32
+ * which also starts the app's sign-in prompt.
33
+ */
34
+ export declare function opReachable(execFileImpl: ExecFileFn, platform: PlatformInfo): Promise<true | string>;
21
35
  /**
22
36
  * How to make `op` authenticate in every shell on this machine. Callers pass
23
37
  * the detected platform; omit it and the running machine is used.
package/dist/op-cli.js CHANGED
@@ -17,7 +17,39 @@
17
17
  * technician following `brew install` text on Windows loses an hour finding
18
18
  * that out. See platform.ts for why we don't try to tell PowerShell from cmd.
19
19
  */
20
+ import { execFailureDetail } from "./exec.js";
20
21
  import { detectPlatformInfo, opNeedsAnotherShell } from "./platform.js";
22
+ /**
23
+ * True when op is installed and can reach the vaults; otherwise the fix-it step.
24
+ * Shared by `ia env fill`, `ia env push` and `ia secrets mint --to-op`.
25
+ *
26
+ * `op whoami` is the obvious probe but NOT a sufficient one: with the desktop
27
+ * app integration on, op 2.35 answers "account is not signed in" to `whoami`
28
+ * while `op read` and `op vault list` both work — the CLI has no session of its
29
+ * own, and the app authorizes each call. Failing there told a technician to
30
+ * enable an integration that was already enabled, and blocked a command that
31
+ * would have succeeded. So a `whoami` failure falls through to `op vault list`,
32
+ * which also starts the app's sign-in prompt.
33
+ */
34
+ export async function opReachable(execFileImpl, platform) {
35
+ try {
36
+ await execFileImpl("op", ["whoami"]);
37
+ return true;
38
+ }
39
+ catch (error) {
40
+ if (execFailureDetail(error).code === "ENOENT")
41
+ return opInstallFix(platform);
42
+ try {
43
+ await execFileImpl("op", ["vault", "list", "--format=json"]);
44
+ return true;
45
+ }
46
+ catch (fallbackError) {
47
+ if (execFailureDetail(fallbackError).code === "ENOENT")
48
+ return opInstallFix(platform);
49
+ return `authenticate the 1Password CLI: ${opIntegrationFix(platform)}`;
50
+ }
51
+ }
52
+ }
21
53
  const V8_NOTE = 'tick "Integrate with 1Password CLI" (v7 has no Developer tab — install v8 from 1password.com/downloads)';
22
54
  const NO_SIGNIN_NOTE = "Don't rely on `op signin` alone — it scopes the session to the one shell that ran it";
23
55
  /**
@@ -28,15 +60,15 @@ export function opIntegrationFix(info = detectPlatformInfo()) {
28
60
  if (opNeedsAnotherShell(info)) {
29
61
  return ("`op` cannot reach the 1Password desktop app from Git Bash — 1Password supports PowerShell only on " +
30
62
  "Windows. Re-run this command in PowerShell. In the 1Password 8 desktop app go to Settings → Developer and " +
31
- `${V8_NOTE}, then \`op whoami\` works in any PowerShell window. ${NO_SIGNIN_NOTE}`);
63
+ `${V8_NOTE}, then \`op vault list\` works in any PowerShell window. ${NO_SIGNIN_NOTE}`);
32
64
  }
33
65
  if (info.platform === "win32") {
34
66
  return ("turn on the desktop app integration (1Password 8 → Settings → Developer → " +
35
- `${V8_NOTE}; Settings → Security → Windows Hello unlock makes it seamless), then \`op whoami\` works in ` +
67
+ `${V8_NOTE}; Settings → Security → Windows Hello unlock makes it seamless), then \`op vault list\` works in ` +
36
68
  `every PowerShell window. ${NO_SIGNIN_NOTE}`);
37
69
  }
38
70
  return ("turn on the desktop app integration (1Password 8 → Settings → Developer → " +
39
- `${V8_NOTE}), then \`op whoami\` works in every shell. ${NO_SIGNIN_NOTE}`);
71
+ `${V8_NOTE}), then \`op vault list\` works in every shell. ${NO_SIGNIN_NOTE}`);
40
72
  }
41
73
  /** Same, prefixed with the install step, for when op isn't on PATH at all. */
42
74
  export function opInstallFix(info = detectPlatformInfo()) {
@@ -0,0 +1,60 @@
1
+ import { type ExecFileFn } from "./exec.js";
2
+ import { type MintFathomWebhookOptions, type MintFathomWebhookResult } from "./fathom-webhook.js";
3
+ import { type MintGcpServiceAccountKeyOptions, type MintGcpServiceAccountKeyResult } from "./gcp-service-account-key.js";
4
+ import { type MintGeminiApiKeyOptions, type MintGeminiApiKeyResult } from "./gemini-api-key.js";
5
+ import { type PlatformInfo } from "./platform.js";
6
+ /**
7
+ * `ia secrets mint … --to-op <vault>` (docs/secrets-minting-plan.md § v2,
8
+ * 2026-10-25): mint a secret and write it straight into a 1Password vault.
9
+ * The secret never reaches stdout, the result object, a log line or an argv
10
+ * (`ps` shows argv to every local user) — it goes to `op` through a 0600 file
11
+ * in a private temp dir that is deleted in the same call.
12
+ *
13
+ * Order is the safety: `op` is checked (installed, signed in, vault visible,
14
+ * title free) BEFORE anything is minted, so the common failures never leave
15
+ * a live secret behind. If the store still fails after the mint, the result
16
+ * is an error that names the exact revoke step — the secret is never printed
17
+ * as a fallback.
18
+ */
19
+ export type MintToOpRequest = ({
20
+ type: "gcp-service-account-key";
21
+ } & Omit<MintGcpServiceAccountKeyOptions, "execFileImpl">) | ({
22
+ type: "gemini-api-key";
23
+ } & Omit<MintGeminiApiKeyOptions, "execFileImpl">) | ({
24
+ type: "fathom-webhook";
25
+ } & Omit<MintFathomWebhookOptions, "fetchImpl">);
26
+ /** The three mints, injectable so tests never call gcloud or Fathom. */
27
+ export interface MintImpls {
28
+ gcp: (o: MintGcpServiceAccountKeyOptions) => Promise<MintGcpServiceAccountKeyResult>;
29
+ gemini: (o: MintGeminiApiKeyOptions) => Promise<MintGeminiApiKeyResult>;
30
+ fathom: (o: MintFathomWebhookOptions) => Promise<MintFathomWebhookResult>;
31
+ }
32
+ export interface MintToOpOptions {
33
+ request: MintToOpRequest;
34
+ /** 1Password vault name, e.g. `client-<slug>` (CLIENT.md `onepassword_vault`). */
35
+ vault: string;
36
+ /** Item title; defaults to `defaultOpTitle(request)`. Must not exist in the vault yet. */
37
+ title?: string;
38
+ /** Injectable for tests; defaults to real `op` via execFile. */
39
+ execFileImpl?: ExecFileFn;
40
+ mints?: Partial<MintImpls>;
41
+ platform?: PlatformInfo;
42
+ }
43
+ export type MintToOpResult = {
44
+ ok: true;
45
+ type: MintToOpRequest["type"];
46
+ vault: string;
47
+ title: string;
48
+ /** `op://<vault>/<title>` — a pointer, not the value. */
49
+ reference: string;
50
+ /** Non-secret facts about what was minted (key id, webhook id, …). */
51
+ details: string[];
52
+ } | {
53
+ ok: false;
54
+ error: string;
55
+ /** Set when a secret WAS minted but not stored: how to revoke it. */
56
+ revoke?: string;
57
+ };
58
+ /** `<project> - gcp-sa-key - <sa name>`, the n8n credential naming shape. */
59
+ export declare function defaultOpTitle(request: MintToOpRequest): string;
60
+ export declare function mintToOnePassword(options: MintToOpOptions): Promise<MintToOpResult>;