@sanity/ailf 2.5.0 → 2.6.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.
@@ -164,8 +164,25 @@ export interface ResolvedConfig {
164
164
  captureGcsBucket?: string;
165
165
  /** GCS object prefix for capture uploads (default: "captures/") */
166
166
  captureGcsPrefix?: string;
167
- /** GCS bucket for report artifact uploads — enables ArtifactUploader (D0030) */
167
+ /**
168
+ * GCS bucket for report artifact uploads. Defaults to "ailf-artifacts"
169
+ * at the composition root — only set this to override (e.g., self-hosted
170
+ * deployment with a different bucket). Read access is governed by the
171
+ * gateway's signing credentials, so alternate bucket names require
172
+ * reconfiguring the gateway as well (D0030).
173
+ */
168
174
  artifactGcsBucket?: string;
175
+ /**
176
+ * Controls whether the ArtifactUploader is constructed.
177
+ *
178
+ * - `undefined` (default): auto — construct when credentials are available
179
+ * (ADC for direct GCS, or AILF_API_KEY for gateway-signed URLs).
180
+ * - `true`: force-enable — still a no-op if no credentials are present (P5).
181
+ * - `false`: force-disable — skip artifact upload even when credentials exist.
182
+ *
183
+ * Sourced from AILF_ARTIFACT_UPLOAD env var or `artifactUpload` in ailf.config.ts.
184
+ */
185
+ artifactUpload?: boolean;
169
186
  }
170
187
  /**
171
188
  * Application context — the complete dependency carrier.
@@ -16,7 +16,7 @@ import { fileURLToPath } from "url";
16
16
  import { classifyUrls } from "../pipeline/classify-url.js";
17
17
  import { normalizeMode } from "../pipeline/normalize-mode.js";
18
18
  import { assessImpact, buildReverseMapping, } from "../pipeline/reverse-mapping.js";
19
- import { buildAppContext } from "../orchestration/build-app-context.js";
19
+ import { buildAppContext, parseArtifactUploadEnv, } from "../orchestration/build-app-context.js";
20
20
  import { buildStepSequence } from "../orchestration/build-step-sequence.js";
21
21
  import { orchestratePipeline } from "../orchestration/pipeline-orchestrator.js";
22
22
  import { load } from "js-yaml";
@@ -329,6 +329,7 @@ export async function executePipeline(cliOpts) {
329
329
  config.captureGcsBucket ??= process.env.AILF_CAPTURE_GCS_BUCKET;
330
330
  config.captureGcsPrefix ??= process.env.AILF_CAPTURE_GCS_PREFIX;
331
331
  config.artifactGcsBucket ??= process.env.AILF_GCS_ARTIFACT_BUCKET;
332
+ config.artifactUpload ??= parseArtifactUploadEnv(process.env.AILF_ARTIFACT_UPLOAD);
332
333
  // Create AppContext directly from the merged config so adapters
333
334
  // (especially taskSource) are wired from the file config's
334
335
  // taskSourceType — not from CLI defaults.
@@ -26,8 +26,15 @@ export declare function createAppContext(config: ResolvedConfig): AppContext;
26
26
  /**
27
27
  * Selects an ArtifactUploader implementation based on available credentials.
28
28
  *
29
- * Returns undefined when artifact upload is not configured — the publish
30
- * step skips silently in that case (P5).
29
+ * Selection order:
30
+ * 1. config.artifactUpload === false always skip (explicit opt-out)
31
+ * 2. GOOGLE_APPLICATION_CREDENTIALS or GCLOUD_PROJECT present → direct GCS
32
+ * 3. apiKey + apiUrl present → gateway-signed PUT URL
33
+ * 4. Neither → skip silently (P5)
34
+ *
35
+ * The bucket defaults to DEFAULT_ARTIFACT_BUCKET when not explicitly set —
36
+ * users only need to override for self-hosted deployments with a different
37
+ * bucket (and matching gateway signing credentials).
31
38
  *
32
39
  * Exported for unit-test access; not part of the public package API.
33
40
  */
@@ -83,13 +83,9 @@ export function createAppContext(config) {
83
83
  : fsCollector;
84
84
  }
85
85
  // Report artifact uploader — uploads structured files to GCS at known
86
- // paths for Studio to fetch via signed URLs (D0030).
87
- //
88
- // Selection (W0042):
89
- // 1. Direct GCS upload when ADC env vars are present (CI / GCP runtime)
90
- // 2. API Gateway signed-URL upload when only an AILF API key is present
91
- // (local dev — no GCS credentials needed)
92
- // 3. Skipped silently when neither is configured
86
+ // paths for Studio to fetch via signed URLs (D0030). Auto-detects the
87
+ // right adapter from available credentials; defaults bucket to
88
+ // "ailf-artifacts". Set artifactUpload: false to opt out entirely.
93
89
  const artifactUploader = createArtifactUploader(config, logger);
94
90
  return {
95
91
  artifactUploader,
@@ -120,34 +116,51 @@ function createLogger() {
120
116
  process.env.AILF_VERBOSE === "1",
121
117
  });
122
118
  }
119
+ /**
120
+ * Shared GCS bucket for report artifacts. Matches the gateway default at
121
+ * packages/api/src/routes/artifacts.ts — both sides assume ailf-artifacts
122
+ * unless explicitly overridden. The gateway's signing credentials are scoped
123
+ * to this bucket, so alternate names require reconfiguring the gateway.
124
+ */
125
+ const DEFAULT_ARTIFACT_BUCKET = "ailf-artifacts";
123
126
  /**
124
127
  * Selects an ArtifactUploader implementation based on available credentials.
125
128
  *
126
- * Returns undefined when artifact upload is not configured — the publish
127
- * step skips silently in that case (P5).
129
+ * Selection order:
130
+ * 1. config.artifactUpload === false always skip (explicit opt-out)
131
+ * 2. GOOGLE_APPLICATION_CREDENTIALS or GCLOUD_PROJECT present → direct GCS
132
+ * 3. apiKey + apiUrl present → gateway-signed PUT URL
133
+ * 4. Neither → skip silently (P5)
134
+ *
135
+ * The bucket defaults to DEFAULT_ARTIFACT_BUCKET when not explicitly set —
136
+ * users only need to override for self-hosted deployments with a different
137
+ * bucket (and matching gateway signing credentials).
128
138
  *
129
139
  * Exported for unit-test access; not part of the public package API.
130
140
  */
131
141
  export function createArtifactUploader(config, logger) {
132
- if (!config.artifactGcsBucket)
142
+ if (config.artifactUpload === false) {
143
+ logger.debug("Artifact upload explicitly disabled via artifactUpload=false");
133
144
  return undefined;
145
+ }
146
+ const bucket = config.artifactGcsBucket ?? DEFAULT_ARTIFACT_BUCKET;
134
147
  // CI / GCP runtime — direct GCS upload (fastest, no extra hop).
135
148
  // We treat the presence of either env var as the user opting in to ADC.
136
149
  const hasGcsCredentials = Boolean(process.env.GOOGLE_APPLICATION_CREDENTIALS || process.env.GCLOUD_PROJECT);
137
150
  if (hasGcsCredentials) {
138
- logger.debug("Artifact uploader: GcsReportArtifactUploader (direct GCS via ADC)");
139
- return new GcsReportArtifactUploader({ bucket: config.artifactGcsBucket });
151
+ logger.debug(`Artifact uploader: GcsReportArtifactUploader (direct GCS via ADC, bucket=${bucket})`);
152
+ return new GcsReportArtifactUploader({ bucket });
140
153
  }
141
154
  // Local dev — request signed PUT URLs from the API gateway, no GCS creds needed.
142
155
  if (config.apiKey && config.apiUrl) {
143
- logger.debug(`Artifact uploader: ApiGatewayArtifactUploader (signed URL via ${config.apiUrl})`);
156
+ logger.debug(`Artifact uploader: ApiGatewayArtifactUploader (signed URL via ${config.apiUrl}, bucket=${bucket})`);
144
157
  return new ApiGatewayArtifactUploader({
145
158
  apiBaseUrl: config.apiUrl,
146
159
  apiKey: config.apiKey,
147
- bucket: config.artifactGcsBucket,
160
+ bucket,
148
161
  });
149
162
  }
150
- logger.debug("Artifact upload skipped: AILF_GCS_ARTIFACT_BUCKET set but no GCS credentials or AILF_API_KEY available");
163
+ logger.debug("Artifact upload skipped: no GCS credentials or AILF_API_KEY available");
151
164
  return undefined;
152
165
  }
153
166
  function createCache(config) {
@@ -18,6 +18,14 @@ import type { ResolvedOptions } from "../commands/pipeline-action.js";
18
18
  * are derived (e.g., areas from areaOption).
19
19
  */
20
20
  export declare function mapToResolvedConfig(opts: ResolvedOptions, rootDir: string): ResolvedConfig;
21
+ /**
22
+ * Parse the AILF_ARTIFACT_UPLOAD env var into a tri-state.
23
+ *
24
+ * - "0" | "false" → false (force-disable)
25
+ * - "1" | "true" → true (force-enable; still a no-op without credentials)
26
+ * - unset | other → undefined (auto-detect from credentials)
27
+ */
28
+ export declare function parseArtifactUploadEnv(value: string | undefined): boolean | undefined;
21
29
  /**
22
30
  * Build an AppContext from legacy ResolvedOptions.
23
31
  *
@@ -85,8 +85,26 @@ export function mapToResolvedConfig(opts, rootDir) {
85
85
  captureGcsBucket: process.env.AILF_CAPTURE_GCS_BUCKET,
86
86
  captureGcsPrefix: process.env.AILF_CAPTURE_GCS_PREFIX,
87
87
  artifactGcsBucket: process.env.AILF_GCS_ARTIFACT_BUCKET,
88
+ artifactUpload: parseArtifactUploadEnv(process.env.AILF_ARTIFACT_UPLOAD),
88
89
  };
89
90
  }
91
+ /**
92
+ * Parse the AILF_ARTIFACT_UPLOAD env var into a tri-state.
93
+ *
94
+ * - "0" | "false" → false (force-disable)
95
+ * - "1" | "true" → true (force-enable; still a no-op without credentials)
96
+ * - unset | other → undefined (auto-detect from credentials)
97
+ */
98
+ export function parseArtifactUploadEnv(value) {
99
+ if (value === undefined)
100
+ return undefined;
101
+ const normalized = value.trim().toLowerCase();
102
+ if (normalized === "0" || normalized === "false")
103
+ return false;
104
+ if (normalized === "1" || normalized === "true")
105
+ return true;
106
+ return undefined;
107
+ }
90
108
  /**
91
109
  * Build an AppContext from legacy ResolvedOptions.
92
110
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ailf",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"