@scarn/sdk 0.8.20 → 0.8.21

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 (65) hide show
  1. package/dist/auth/api-token-cache.d.ts +24 -0
  2. package/dist/auth/api-token-source.d.ts +39 -0
  3. package/dist/auth/authenticated-fetch.d.ts +10 -0
  4. package/dist/auth/index.d.ts +3 -0
  5. package/dist/auth/index.js +20 -0
  6. package/dist/automations/index.js +4 -4
  7. package/dist/{chunk-pqtd0hr7.js → chunk-08gcnrzh.js} +2 -2
  8. package/dist/{chunk-g4j5cfpc.js → chunk-0he2dx5n.js} +5 -5
  9. package/dist/{chunk-z4smq8qd.js → chunk-59arcerk.js} +1 -1
  10. package/dist/{chunk-46wmsgv7.js → chunk-5say64w8.js} +1 -1
  11. package/dist/{chunk-habmdf89.js → chunk-6p340dd4.js} +1 -1
  12. package/dist/{chunk-19brnwkp.js → chunk-8hsk6f6b.js} +1 -1
  13. package/dist/{chunk-098740f7.js → chunk-8kzaxz52.js} +1 -1
  14. package/dist/{chunk-n3ywwx7n.js → chunk-8tmsvkmj.js} +5 -5
  15. package/dist/{chunk-e0pt5x0e.js → chunk-aph2js2v.js} +5 -5
  16. package/dist/chunk-azss2d1n.js +1036 -0
  17. package/dist/{chunk-t1dq2c2s.js → chunk-gasw078g.js} +5 -5
  18. package/dist/{chunk-0c60x3v8.js → chunk-h1v6w1fh.js} +5 -5
  19. package/dist/{chunk-tr3v83cn.js → chunk-k57h6qke.js} +8 -5
  20. package/dist/{chunk-aemxz9r7.js → chunk-mrzn5tq4.js} +1 -1
  21. package/dist/{chunk-qgkx89eg.js → chunk-nkm31g10.js} +3 -3
  22. package/dist/{chunk-yq0sf8sb.js → chunk-p74r4y6j.js} +13 -13
  23. package/dist/{chunk-a56zc4s5.js → chunk-pwyj6qf3.js} +2 -2
  24. package/dist/{chunk-b9ja6ss5.js → chunk-qt81x1pm.js} +1 -1
  25. package/dist/{chunk-mzj1j0p5.js → chunk-r3sbp2wn.js} +3 -3
  26. package/dist/{chunk-rphfy0fj.js → chunk-vsp708vw.js} +1 -1
  27. package/dist/{chunk-yf15kdte.js → chunk-xhpp6qz8.js} +96 -96
  28. package/dist/{chunk-y34zsgsw.js → chunk-y7ac1t9c.js} +1 -1
  29. package/dist/{chunk-rq5k7m33.js → chunk-y81cr6tp.js} +28 -14
  30. package/dist/{chunk-91f5gm5z.js → chunk-zxzvketc.js} +5 -5
  31. package/dist/client.d.ts +5 -1
  32. package/dist/client.js +2 -2
  33. package/dist/connectors/index.js +4 -4
  34. package/dist/contracts/artifacts.js +2 -2
  35. package/dist/contracts/automation-document/index.js +3 -3
  36. package/dist/contracts/pipeline-document/index.js +2 -2
  37. package/dist/contracts/step-artifact-submissions.js +2 -2
  38. package/dist/contracts/work-item-changes.js +1 -1
  39. package/dist/create-api-client.d.ts +11 -0
  40. package/dist/defaults/index.js +32 -871
  41. package/dist/defaults/load-push-defaults.d.ts +11 -4
  42. package/dist/defaults/project-ref.d.ts +2 -4
  43. package/dist/definitions/automations/automations-client.d.ts +2 -1
  44. package/dist/definitions/automations/index.js +3 -3
  45. package/dist/definitions/environments/environments-client.d.ts +2 -1
  46. package/dist/definitions/environments/index.js +10 -10
  47. package/dist/definitions/pipelines/index.js +3 -3
  48. package/dist/definitions/pipelines/pipeline-definitions-client.d.ts +2 -1
  49. package/dist/definitions/steps/index.js +13 -13
  50. package/dist/definitions/steps/step-definitions-client.d.ts +2 -1
  51. package/dist/definitions/validation/index.js +10 -10
  52. package/dist/devcontainer-config-path.js +2 -2
  53. package/dist/env-vars.js +2 -2
  54. package/dist/environment.js +7 -7
  55. package/dist/health-checks.js +2 -2
  56. package/dist/index.js +20 -20
  57. package/dist/managed-runtimes.js +2 -2
  58. package/dist/opencode-mcp.js +3 -3
  59. package/dist/pipelines/index.js +3 -3
  60. package/dist/push/index.js +42 -41
  61. package/dist/push/push-from-directory.d.ts +6 -1
  62. package/dist/repo-config.js +2 -2
  63. package/dist/resolve-environment.js +8 -8
  64. package/dist/task-plane-client.d.ts +6 -0
  65. package/package.json +6 -2
@@ -2,25 +2,25 @@
2
2
  import {
3
3
  EnvironmentsApiError,
4
4
  createEnvironmentsClient
5
- } from "../chunk-n3ywwx7n.js";
5
+ } from "../chunk-8tmsvkmj.js";
6
6
  import {
7
7
  AutomationsApiError,
8
8
  createAutomationsClient
9
- } from "../chunk-g4j5cfpc.js";
9
+ } from "../chunk-0he2dx5n.js";
10
10
  import {
11
11
  assertValidDefinitionSpecs
12
- } from "../chunk-0c60x3v8.js";
12
+ } from "../chunk-h1v6w1fh.js";
13
13
  import {
14
14
  PipelineDefinitionsApiError,
15
15
  createPipelineDefinitionsClient
16
- } from "../chunk-91f5gm5z.js";
16
+ } from "../chunk-zxzvketc.js";
17
17
  import {
18
18
  createStepDefinitionsClient,
19
19
  stepEnvironmentHandle,
20
20
  toStepSpec
21
- } from "../chunk-yq0sf8sb.js";
22
- import"../chunk-y34zsgsw.js";
23
- import"../chunk-t1dq2c2s.js";
21
+ } from "../chunk-p74r4y6j.js";
22
+ import"../chunk-y7ac1t9c.js";
23
+ import"../chunk-gasw078g.js";
24
24
  import {
25
25
  isEnvironmentHandle,
26
26
  isStepDefinitionSpec,
@@ -28,20 +28,20 @@ import {
28
28
  } from "../chunk-6tra3gw8.js";
29
29
  import"../chunk-xqfj56m9.js";
30
30
  import"../chunk-y11p1q7r.js";
31
- import"../chunk-rphfy0fj.js";
32
- import"../chunk-e0pt5x0e.js";
33
- import"../chunk-098740f7.js";
34
- import"../chunk-46wmsgv7.js";
35
- import"../chunk-qgkx89eg.js";
36
- import"../chunk-pqtd0hr7.js";
37
- import"../chunk-aemxz9r7.js";
38
- import"../chunk-rq5k7m33.js";
31
+ import"../chunk-vsp708vw.js";
32
+ import"../chunk-aph2js2v.js";
33
+ import"../chunk-8kzaxz52.js";
34
+ import"../chunk-5say64w8.js";
35
+ import"../chunk-nkm31g10.js";
36
+ import"../chunk-08gcnrzh.js";
37
+ import"../chunk-mrzn5tq4.js";
38
+ import"../chunk-y81cr6tp.js";
39
39
  import"../chunk-ngy1fdcx.js";
40
- import"../chunk-19brnwkp.js";
40
+ import"../chunk-8hsk6f6b.js";
41
41
  import"../chunk-01nfqm18.js";
42
42
  import {
43
43
  exports_external
44
- } from "../chunk-yf15kdte.js";
44
+ } from "../chunk-xhpp6qz8.js";
45
45
  import"../chunk-y64skrwp.js";
46
46
 
47
47
  // src/push/collect-definitions.ts
@@ -261,42 +261,42 @@ async function pushFromDirectory(dir, opts) {
261
261
  const log = opts.log ?? ((msg) => {
262
262
  console.warn(msg);
263
263
  });
264
- const headers = { Authorization: `Bearer ${opts.accessToken}` };
264
+ const clientOptions = { fetch: opts.fetch };
265
265
  const { steps, environments } = await collectDefinitionsFromDirectory(dir);
266
266
  const built = collectBuiltDocuments(dir);
267
267
  const documents = built.filter((file) => file.kind === "pipeline");
268
268
  const automations = built.filter((file) => file.kind === "automation").sort((a, b) => Number(a.document["scope"] === "project") - Number(b.document["scope"] === "project"));
269
269
  log(`Found ${String(environments.length)} environment(s), ${String(steps.length)} step(s), ${String(documents.length)} pipeline document(s) and ${String(automations.length)} automation document(s).`);
270
270
  assertValidDefinitionSpecs(steps);
271
- const environmentsClient = createEnvironmentsClient(opts.baseUrl);
272
- await assertNamedEnvironmentsExist(steps, environments, opts.projectId, headers, environmentsClient);
271
+ const environmentsClient = createEnvironmentsClient(opts.baseUrl, clientOptions);
272
+ await assertNamedEnvironmentsExist(steps, environments, opts.projectId, environmentsClient);
273
273
  const publishedEnvironments = [];
274
274
  const unchangedEnvironments = [];
275
275
  for (const environment of environments) {
276
- const published = await publishEnvironment(environment, opts.projectId, headers, environmentsClient, log);
276
+ const published = await publishEnvironment(environment, opts.projectId, environmentsClient, log);
277
277
  (published ? publishedEnvironments : unchangedEnvironments).push(environment.name);
278
278
  }
279
- const stepsClient = createStepDefinitionsClient(opts.baseUrl);
279
+ const stepsClient = createStepDefinitionsClient(opts.baseUrl, clientOptions);
280
280
  for (const spec of steps) {
281
- await stepsClient.upsertFromSpec(opts.projectId, spec, { headers });
281
+ await stepsClient.upsertFromSpec(opts.projectId, spec);
282
282
  log(`\u2713 step ${spec.key} v${String(spec.version)} \u2192 upserted`);
283
283
  }
284
- const pipelinesClient = createPipelineDefinitionsClient(opts.baseUrl);
284
+ const pipelinesClient = createPipelineDefinitionsClient(opts.baseUrl, clientOptions);
285
285
  const publishedPipelines = [];
286
286
  const unchangedPipelines = [];
287
287
  if (documents.length > 0) {
288
- const serverPipelines = await pipelinesClient.listByProjectId(opts.projectId, { headers });
288
+ const serverPipelines = await pipelinesClient.listByProjectId(opts.projectId);
289
289
  const idByKey = new Map(serverPipelines.map((p) => [p.key, p.id]));
290
290
  for (const document of documents) {
291
- const published = await publishPipelineDocument(document, idByKey.get(document.key), opts.projectId, headers, pipelinesClient, log);
291
+ const published = await publishPipelineDocument(document, idByKey.get(document.key), opts.projectId, pipelinesClient, log);
292
292
  (published ? publishedPipelines : unchangedPipelines).push(document.key);
293
293
  }
294
294
  }
295
- const automationsClient = createAutomationsClient(opts.baseUrl);
295
+ const automationsClient = createAutomationsClient(opts.baseUrl, clientOptions);
296
296
  const publishedAutomations = [];
297
297
  const unchangedAutomations = [];
298
298
  for (const document of automations) {
299
- const published = await publishAutomationDocument(document, opts.projectId, headers, automationsClient, log);
299
+ const published = await publishAutomationDocument(document, opts.projectId, automationsClient, log);
300
300
  (published ? publishedAutomations : unchangedAutomations).push(document.key);
301
301
  }
302
302
  return {
@@ -309,7 +309,7 @@ async function pushFromDirectory(dir, opts) {
309
309
  unchangedAutomations
310
310
  };
311
311
  }
312
- async function assertNamedEnvironmentsExist(steps, environments, projectId, headers, environmentsClient) {
312
+ async function assertNamedEnvironmentsExist(steps, environments, projectId, environmentsClient) {
313
313
  const local = new Set(environments.map((environment) => environment.name));
314
314
  const stepsByMissingName = new Map;
315
315
  for (const step of steps) {
@@ -325,7 +325,7 @@ async function assertNamedEnvironmentsExist(steps, environments, projectId, head
325
325
  }
326
326
  if (stepsByMissingName.size === 0)
327
327
  return;
328
- const onServer = new Set((await environmentsClient.listByProjectId(projectId, { headers })).map((environment) => environment.name));
328
+ const onServer = new Set((await environmentsClient.listByProjectId(projectId)).map((environment) => environment.name));
329
329
  const unknown = [...stepsByMissingName].filter(([name]) => !onServer.has(name));
330
330
  if (unknown.length === 0)
331
331
  return;
@@ -336,11 +336,9 @@ async function assertNamedEnvironmentsExist(steps, environments, projectId, head
336
336
  ].join(`
337
337
  `));
338
338
  }
339
- async function publishEnvironment({ name, content, sourceFile }, projectId, headers, environmentsClient, log) {
339
+ async function publishEnvironment({ name, content, sourceFile }, projectId, environmentsClient, log) {
340
340
  try {
341
- const result = await environmentsClient.publish(projectId, name, content, {
342
- headers
343
- });
341
+ const result = await environmentsClient.publish(projectId, name, content);
344
342
  const version = String(result.version.version);
345
343
  log(result.published ? `\u2713 environment ${name} v${version} \u2192 published (${sourceFile})` : `\u2713 environment ${name} v${version} \u2192 unchanged (${sourceFile})`);
346
344
  return result.published;
@@ -355,14 +353,19 @@ async function publishEnvironment({ name, content, sourceFile }, projectId, head
355
353
  `), { cause: error });
356
354
  }
357
355
  }
358
- async function publishPipelineDocument({ file, key, title, document }, pipelineDefinitionId, projectId, headers, pipelinesClient, log) {
356
+ async function publishPipelineDocument({ file, key, title, document }, pipelineDefinitionId, projectId, pipelinesClient, log) {
359
357
  try {
360
358
  if (pipelineDefinitionId === undefined) {
361
- await pipelinesClient.create({ projectId, key, name: title ?? key, document }, { headers });
359
+ await pipelinesClient.create({
360
+ projectId,
361
+ key,
362
+ name: title ?? key,
363
+ document
364
+ });
362
365
  log(`\u2713 pipeline ${key} \u2192 created and published (${file})`);
363
366
  return true;
364
367
  }
365
- const result = await pipelinesClient.publishVersion(pipelineDefinitionId, document, { headers });
368
+ const result = await pipelinesClient.publishVersion(pipelineDefinitionId, document);
366
369
  const version = String(result.version.version);
367
370
  log(result.published ? `\u2713 pipeline ${key} v${version} \u2192 published (${file})` : `\u2713 pipeline ${key} v${version} \u2192 unchanged (${file})`);
368
371
  return result.published;
@@ -370,11 +373,9 @@ async function publishPipelineDocument({ file, key, title, document }, pipelineD
370
373
  rethrowPublishError(file, error);
371
374
  }
372
375
  }
373
- async function publishAutomationDocument({ file, key, document }, projectId, headers, automationsClient, log) {
376
+ async function publishAutomationDocument({ file, key, document }, projectId, automationsClient, log) {
374
377
  try {
375
- const result = await automationsClient.publish(projectId, key, document, {
376
- headers
377
- });
378
+ const result = await automationsClient.publish(projectId, key, document);
378
379
  const latest = latestVersionSchema.safeParse(result.automation.latestVersion);
379
380
  const version = latest.success ? ` v${String(latest.data.version)}` : "";
380
381
  log(result.published ? `\u2713 automation ${key}${version} \u2192 published (${file})` : `\u2713 automation ${key}${version} \u2192 unchanged (${file})`);
@@ -1,7 +1,12 @@
1
+ import type { FetchLike } from "../auth";
1
2
  export interface PushFromDirectoryOptions {
2
3
  baseUrl: string;
3
4
  projectId: string;
4
- accessToken: string;
5
+ /**
6
+ * Authenticates every request, e.g. the `fetch` from `loadPushDefaults` or
7
+ * one from `createAuthenticatedFetch`.
8
+ */
9
+ fetch: FetchLike;
5
10
  /** Override the logger; defaults to console.log. */
6
11
  log?: (message: string) => void;
7
12
  }
@@ -20,8 +20,8 @@ import {
20
20
  repoGitCredentialsSchema,
21
21
  repoWorkBranchSchema,
22
22
  resolveRepoConfig
23
- } from "./chunk-rphfy0fj.js";
24
- import"./chunk-yf15kdte.js";
23
+ } from "./chunk-vsp708vw.js";
24
+ import"./chunk-xhpp6qz8.js";
25
25
  import"./chunk-y64skrwp.js";
26
26
  export {
27
27
  MAX_REPO_BASE_BRANCH_LENGTH,
@@ -3,14 +3,14 @@ import {
3
3
  readEnvironmentDefinition,
4
4
  resolveEnvironment,
5
5
  resolveEnvironmentDefinition
6
- } from "./chunk-mzj1j0p5.js";
7
- import"./chunk-e0pt5x0e.js";
8
- import"./chunk-098740f7.js";
9
- import"./chunk-46wmsgv7.js";
10
- import"./chunk-qgkx89eg.js";
11
- import"./chunk-pqtd0hr7.js";
12
- import"./chunk-aemxz9r7.js";
13
- import"./chunk-yf15kdte.js";
6
+ } from "./chunk-r3sbp2wn.js";
7
+ import"./chunk-aph2js2v.js";
8
+ import"./chunk-8kzaxz52.js";
9
+ import"./chunk-5say64w8.js";
10
+ import"./chunk-nkm31g10.js";
11
+ import"./chunk-08gcnrzh.js";
12
+ import"./chunk-mrzn5tq4.js";
13
+ import"./chunk-xhpp6qz8.js";
14
14
  import"./chunk-y64skrwp.js";
15
15
  export {
16
16
  readEnvironmentDefinition,
@@ -13,6 +13,12 @@ export type TaskPlaneClientOptions = {
13
13
  requestHeaders?: (() => Promise<Record<string, string>> | Record<string, string>) | undefined;
14
14
  /** Sees every response before it is parsed; throwing fails the call. */
15
15
  onResponse?: ((response: Response) => Promise<void> | void) | undefined;
16
+ /**
17
+ * Replaces `fetch` for every request, e.g. one from `createAuthenticatedFetch`.
18
+ * An error it throws (a failed token mint, a network error) fails the call
19
+ * as is.
20
+ */
21
+ fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>) | undefined;
16
22
  };
17
23
  /**
18
24
  * Worker-facing client for the task-run plane (`/api/task-runs/...`): claiming,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@scarn/sdk",
4
- "version": "0.8.20",
4
+ "version": "0.8.21",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
@@ -72,6 +72,10 @@
72
72
  "import": "./dist/defaults/index.js",
73
73
  "types": "./dist/defaults/index.d.ts"
74
74
  },
75
+ "./auth": {
76
+ "import": "./dist/auth/index.js",
77
+ "types": "./dist/auth/index.d.ts"
78
+ },
75
79
  "./push": {
76
80
  "import": "./dist/push/index.js",
77
81
  "types": "./dist/push/index.d.ts"
@@ -161,6 +165,6 @@
161
165
  "@hey-api/openapi-ts": "^0.90.10",
162
166
  "@opencode/client": "2.1.4",
163
167
  "bun-types": "^1.4.0",
164
- "zod": "^4.3.6"
168
+ "zod": "^4.6.7"
165
169
  }
166
170
  }