@tailor-platform/sdk 1.27.0 → 1.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/{application-CBJFUKrU.mjs → application-Clwpv84E.mjs} +9 -5
  3. package/dist/application-Clwpv84E.mjs.map +1 -0
  4. package/dist/{application-WyZetOky.mjs → application-Dl1d7w-b.mjs} +3 -3
  5. package/dist/chunk-DEt8GZDa.mjs +8 -0
  6. package/dist/cli/index.mjs +154 -21
  7. package/dist/cli/index.mjs.map +1 -1
  8. package/dist/cli/lib.mjs +5 -5
  9. package/dist/cli/skills.mjs +1 -1
  10. package/dist/client-CW4Oh3iz.mjs +6 -0
  11. package/dist/client-CZmQBXAY.mjs +16294 -0
  12. package/dist/client-CZmQBXAY.mjs.map +1 -0
  13. package/dist/configure/index.mjs +1 -1
  14. package/dist/{crash-report-Cot_9Esm.mjs → crash-report-CYrETw1c.mjs} +2 -2
  15. package/dist/{crash-report-Ju8cQF-l.mjs → crash-report-DizNMVnm.mjs} +3 -3
  16. package/dist/{crash-report-Ju8cQF-l.mjs.map → crash-report-DizNMVnm.mjs.map} +1 -1
  17. package/dist/{interceptor-B0d_GrI5.mjs → interceptor-DgQNmwWJ.mjs} +2 -2
  18. package/dist/{interceptor-B0d_GrI5.mjs.map → interceptor-DgQNmwWJ.mjs.map} +1 -1
  19. package/dist/kysely/index.mjs +1 -1
  20. package/dist/{package-json-DHfTiUCS.mjs → package-json-DiZWrkIA.mjs} +1 -1
  21. package/dist/plugin/builtin/enum-constants/index.mjs +1 -1
  22. package/dist/plugin/builtin/file-utils/index.mjs +1 -1
  23. package/dist/plugin/builtin/kysely-type/index.mjs +1 -1
  24. package/dist/plugin/builtin/seed/index.mjs +1 -1
  25. package/dist/plugin/index.mjs +1 -1
  26. package/dist/{query-CgGbAmUg.mjs → query-B1-hq2Hm.mjs} +70 -28
  27. package/dist/query-B1-hq2Hm.mjs.map +1 -0
  28. package/dist/seed/index.mjs +1 -1
  29. package/dist/{telemetry-VvNfsyEE.mjs → telemetry-BSUlYTs-.mjs} +2 -2
  30. package/dist/{telemetry-VvNfsyEE.mjs.map → telemetry-BSUlYTs-.mjs.map} +1 -1
  31. package/dist/telemetry-BtN2l0f1.mjs +4 -0
  32. package/dist/utils/test/index.mjs +1 -1
  33. package/docs/cli/secret.md +16 -14
  34. package/docs/cli/user.md +21 -22
  35. package/docs/cli/workspace.md +0 -7
  36. package/docs/cli-reference.md +12 -10
  37. package/docs/configuration.md +19 -0
  38. package/docs/services/executor.md +46 -0
  39. package/docs/services/secret.md +81 -0
  40. package/package.json +8 -8
  41. package/dist/application-CBJFUKrU.mjs.map +0 -1
  42. package/dist/chunk-Cz-A8uMR.mjs +0 -3
  43. package/dist/client-C2_wgujH.mjs +0 -6
  44. package/dist/client-bTbnbQbB.mjs +0 -957
  45. package/dist/client-bTbnbQbB.mjs.map +0 -1
  46. package/dist/query-CgGbAmUg.mjs.map +0 -1
  47. package/dist/telemetry-BevrwWwF.mjs +0 -4
@@ -1,9 +1,9 @@
1
- import "./chunk-Cz-A8uMR.mjs";
1
+ import "./chunk-DEt8GZDa.mjs";
2
2
  import "./brand-GZnI4eYb.mjs";
3
3
  import "./logger-CqezTedh.mjs";
4
- import "./client-bTbnbQbB.mjs";
4
+ import "./client-CZmQBXAY.mjs";
5
5
  import "./package-json-D3x2nBPB.mjs";
6
- import { n as generatePluginFilesIfNeeded, r as loadApplication, t as defineApplication } from "./application-CBJFUKrU.mjs";
6
+ import { n as generatePluginFilesIfNeeded, r as loadApplication, t as defineApplication } from "./application-Clwpv84E.mjs";
7
7
  import "./seed-CWkIDWMb.mjs";
8
8
  import "./file-utils-Bctuzn3x.mjs";
9
9
  import "./kysely-type-B_IecdK9.mjs";
@@ -0,0 +1,8 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region \0rolldown/runtime.js
4
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
5
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
6
+
7
+ //#endregion
8
+ export { __require as n, __commonJSMin as t };
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
- import "../chunk-Cz-A8uMR.mjs";
2
+ import "../chunk-DEt8GZDa.mjs";
3
3
  import "../schema-BePzTFBV.mjs";
4
4
  import "../brand-GZnI4eYb.mjs";
5
5
  import { n as logger, r as styles } from "../logger-CqezTedh.mjs";
6
- import { C as listCommand$10, E as resumeCommand, F as showCommand, Ft as isValidMigrationNumber, G as listCommand$7, Ht as prompt, I as logBetaWarning, It as loadDiff, Jt as commonArgs, Kt as apiCommand, Mt as getMigrationFilePath, N as generateCommand$1, Nt as getMigrationFiles, O as listCommand$9, Q as listCommand$6, Qt as workspaceArgs, R as removeCommand$1, T as healthCommand, Ut as trnPrefix, V as getCommand$2, Vt as getNamespacesWithMigrations, W as tokenCommand, X as triggerCommand, Xt as deploymentArgs, Y as webhookCommand, Yt as confirmationArgs, Zt as isVerbose, b as createCommand$3, c as listCommand$11, ct as executionsCommand, dt as functionExecutionStatusToString, f as restoreCommand, ft as formatKeyValueTable, g as getCommand$4, gt as executeScript, ht as apply, i as updateCommand$2, it as startCommand, j as truncateCommand, kt as formatMigrationNumber, m as listCommand$12, n as queryCommand, o as removeCommand, ot as getCommand$3, pt as getCommand$1, q as generate, qt as defineAppCommand, r as isCLIError, tt as jobsCommand, u as inviteCommand, v as deleteCommand$3, yt as parseMigrationLabelNumber, z as listCommand$8 } from "../query-CgGbAmUg.mjs";
7
- import { A as AuthInvokerSchema, L as PATScope, d as userAgent, i as fetchUserInfo, n as fetchAll, o as initOAuth2Client, s as initOperatorClient, w as FunctionExecution_Type } from "../client-bTbnbQbB.mjs";
6
+ import { $t as workspaceArgs, C as listCommand$10, E as resumeCommand, F as showCommand, Ft as isValidMigrationNumber, G as listCommand$7, Ht as prompt, I as logBetaWarning, It as loadDiff, Jt as defineAppCommand, Mt as getMigrationFilePath, N as generateCommand$1, Nt as getMigrationFiles, O as listCommand$9, Q as listCommand$6, Qt as isVerbose, R as removeCommand$1, T as healthCommand, Ut as sdkNameLabelKey, V as getCommand$2, Vt as getNamespacesWithMigrations, W as tokenCommand, Wt as trnPrefix, X as triggerCommand, Xt as confirmationArgs, Y as webhookCommand, Yt as commonArgs, Zt as deploymentArgs, b as createCommand$3, c as listCommand$11, ct as executionsCommand, dt as functionExecutionStatusToString, f as restoreCommand, ft as formatKeyValueTable, g as getCommand$4, gt as executeScript, ht as apply, i as updateCommand$2, it as startCommand, j as truncateCommand, kt as formatMigrationNumber, m as listCommand$12, n as queryCommand, o as removeCommand, ot as getCommand$3, pt as getCommand$1, q as generate, qt as apiCommand, r as isCLIError, tt as jobsCommand, u as inviteCommand, v as deleteCommand$3, yt as parseMigrationLabelNumber, z as listCommand$8 } from "../query-B1-hq2Hm.mjs";
7
+ import { E as FunctionExecution_Type, M as AuthInvokerSchema, a as fetchPlatformMachineUserToken, c as initOAuth2Client, l as initOperatorClient, n as closeConnectionPool, o as fetchUserInfo, p as userAgent, r as fetchAll, z as PATScope } from "../client-CZmQBXAY.mjs";
8
8
  import { t as readPackageJson } from "../package-json-D3x2nBPB.mjs";
9
- import { S as writePlatformConfig, a as loadConfig, b as loadWorkspaceId, c as ExecutorSchema, g as getDistDir, i as resolveInlineSourcemap, o as WorkflowJobSchema, u as ResolverSchema, v as fetchLatestToken, x as readPlatformConfig, y as loadAccessToken } from "../application-CBJFUKrU.mjs";
9
+ import { S as writePlatformConfig, a as loadConfig, b as loadWorkspaceId, c as ExecutorSchema, g as getDistDir, i as resolveInlineSourcemap, o as WorkflowJobSchema, u as ResolverSchema, v as fetchLatestToken, x as readPlatformConfig, y as loadAccessToken } from "../application-Clwpv84E.mjs";
10
10
  import "../seed-CWkIDWMb.mjs";
11
11
  import "../file-utils-Bctuzn3x.mjs";
12
12
  import "../kysely-type-B_IecdK9.mjs";
13
- import "../telemetry-VvNfsyEE.mjs";
14
- import { a as JSON_FOOTER_MARKER, i as CRASH_LOG_EXTENSION, o as parseCrashReportConfig, r as sendCrashReport, t as initCrashReporting } from "../crash-report-Ju8cQF-l.mjs";
13
+ import "../telemetry-BSUlYTs-.mjs";
14
+ import { a as JSON_FOOTER_MARKER, i as CRASH_LOG_EXTENSION, o as parseCrashReportConfig, r as sendCrashReport, t as initCrashReporting } from "../crash-report-DizNMVnm.mjs";
15
15
  import { createRequire, register } from "node:module";
16
16
  import { arg, defineCommand, runCommand, runMain } from "politty";
17
17
  import { withCompletionCommand } from "politty/completion";
@@ -21,14 +21,14 @@ import * as path from "pathe";
21
21
  import { generateCodeVerifier } from "@badgateway/oauth2-client";
22
22
  import { timestampDate } from "@bufbuild/protobuf/wkt";
23
23
  import { Code, ConnectError } from "@connectrpc/connect";
24
+ import * as http from "node:http";
25
+ import * as crypto from "node:crypto";
26
+ import { pathToFileURL } from "node:url";
24
27
  import { resolveTSConfig } from "pkg-types";
25
28
  import ml from "multiline-ts";
26
- import * as crypto from "node:crypto";
27
29
  import * as rolldown from "rolldown";
28
- import { pathToFileURL } from "node:url";
29
30
  import { create } from "@bufbuild/protobuf";
30
31
  import { spawn, spawnSync } from "node:child_process";
31
- import * as http from "node:http";
32
32
  import open from "open";
33
33
  import * as fs from "fs";
34
34
  import { lookup } from "mime-types";
@@ -51,7 +51,7 @@ const applyCommand = defineAppCommand({
51
51
  "clean-cache": arg(z.boolean().optional(), { description: "Clean the bundle cache before building" })
52
52
  }).strict(),
53
53
  run: async (args) => {
54
- const { initTelemetry } = await import("../telemetry-BevrwWwF.mjs");
54
+ const { initTelemetry } = await import("../telemetry-BtN2l0f1.mjs");
55
55
  await initTelemetry();
56
56
  await apply({
57
57
  workspaceId: args["workspace-id"],
@@ -808,7 +808,7 @@ const generateCommand = defineAppCommand({
808
808
  })
809
809
  }).strict(),
810
810
  run: async (args) => {
811
- const { initTelemetry } = await import("../telemetry-BevrwWwF.mjs");
811
+ const { initTelemetry } = await import("../telemetry-BtN2l0f1.mjs");
812
812
  await initTelemetry();
813
813
  await generate({
814
814
  configPath: args.config,
@@ -935,13 +935,46 @@ const startAuthServer = async () => {
935
935
  });
936
936
  });
937
937
  };
938
+ async function loginAsMachineUser(args) {
939
+ const clientSecret = args.clientSecret ?? await prompt.password({ message: "Client secret" });
940
+ const tokens = await fetchPlatformMachineUserToken(args.clientId, clientSecret);
941
+ const pfConfig = readPlatformConfig();
942
+ pfConfig.users = {
943
+ ...pfConfig.users,
944
+ [args.clientId]: {
945
+ access_token: tokens.accessToken,
946
+ token_expires_at: new Date(tokens.expiresAt).toISOString()
947
+ }
948
+ };
949
+ pfConfig.current_user = args.clientId;
950
+ writePlatformConfig(pfConfig);
951
+ }
938
952
  const loginCommand = defineAppCommand({
939
953
  name: "login",
940
954
  description: "Login to Tailor Platform.",
941
- args: z.object({}).strict(),
942
- run: async () => {
943
- await startAuthServer();
955
+ args: z.xor([z.object({}).strict().describe("User Login"), z.object({
956
+ machineuser: arg(z.literal(true), {
957
+ description: "Login as a platform machine user.",
958
+ required: true
959
+ }),
960
+ "client-id": arg(z.string(), {
961
+ description: "Client ID",
962
+ env: "TAILOR_PLATFORM_MACHINE_USER_CLIENT_ID",
963
+ required: true
964
+ }),
965
+ "client-secret": arg(z.string().optional(), {
966
+ description: "Client secret",
967
+ env: "TAILOR_PLATFORM_MACHINE_USER_CLIENT_SECRET"
968
+ })
969
+ }).strict().describe("Machine User Login")]),
970
+ run: async (args) => {
971
+ if ("machineuser" in args && args.machineuser) await loginAsMachineUser({
972
+ clientId: args.clientId,
973
+ clientSecret: args.clientSecret
974
+ });
975
+ else await startAuthServer();
944
976
  logger.success("Successfully logged in to Tailor Platform.");
977
+ await closeConnectionPool();
945
978
  }
946
979
  });
947
980
 
@@ -958,11 +991,13 @@ const logoutCommand = defineAppCommand({
958
991
  logger.info("You are not logged in.");
959
992
  return;
960
993
  }
961
- initOAuth2Client().revoke({
994
+ const client = initOAuth2Client();
995
+ const tokenTypeHint = tokens.refresh_token ? "refresh_token" : "access_token";
996
+ client.revoke({
962
997
  accessToken: tokens.access_token,
963
- refreshToken: tokens.refresh_token,
998
+ refreshToken: tokens.refresh_token ?? null,
964
999
  expiresAt: Date.parse(tokens.token_expires_at)
965
- }, "refresh_token");
1000
+ }, tokenTypeHint);
966
1001
  delete pfConfig.users[pfConfig.current_user];
967
1002
  pfConfig.current_user = null;
968
1003
  writePlatformConfig(pfConfig);
@@ -1209,6 +1244,57 @@ const secretValueArgs = {
1209
1244
  })
1210
1245
  };
1211
1246
 
1247
+ //#endregion
1248
+ //#region src/cli/commands/secret/check-vault-managed.ts
1249
+ /**
1250
+ * Check if a vault is managed by defineSecretManager() and warn the user.
1251
+ * Returns management status and metadata needed for releasing ownership.
1252
+ * @param params - Check parameters
1253
+ * @returns Management status, TRN, and existing labels
1254
+ */
1255
+ async function checkVaultManaged(params) {
1256
+ const { client, workspaceId, vaultName } = params;
1257
+ const trn = `${trnPrefix(workspaceId)}:vault:${vaultName}`;
1258
+ const notManaged = {
1259
+ isManaged: false,
1260
+ trn,
1261
+ existingLabels: {}
1262
+ };
1263
+ let owner;
1264
+ let allLabels = {};
1265
+ try {
1266
+ const { metadata } = await client.getMetadata({ trn });
1267
+ allLabels = metadata?.labels ?? {};
1268
+ owner = allLabels[sdkNameLabelKey];
1269
+ } catch {
1270
+ return notManaged;
1271
+ }
1272
+ if (!owner) return notManaged;
1273
+ logger.warn(`Vault "${vaultName}" is managed by defineSecretManager() in tailor.config.ts (owner: "${owner}"). Changes made via CLI may conflict with the config on the next apply.`);
1274
+ return {
1275
+ isManaged: true,
1276
+ trn,
1277
+ existingLabels: allLabels
1278
+ };
1279
+ }
1280
+ /**
1281
+ * Release ownership of a managed vault by removing SDK labels from metadata.
1282
+ * Call this after the user has confirmed they want to proceed with a CLI operation on a managed vault.
1283
+ * @param params - Client, TRN, and existing labels from checkVaultManaged result
1284
+ * @param params.client
1285
+ * @param params.trn
1286
+ * @param params.existingLabels
1287
+ */
1288
+ async function releaseVaultOwnership(params) {
1289
+ const { client, trn, existingLabels } = params;
1290
+ const { [sdkNameLabelKey]: _, "sdk-version": __, ...remainingLabels } = existingLabels;
1291
+ await client.setMetadata({
1292
+ trn,
1293
+ labels: remainingLabels
1294
+ });
1295
+ logger.info("Config ownership has been removed from this vault. Remove it from defineSecretManager() in your config to prevent the next apply from re-claiming it.");
1296
+ }
1297
+
1212
1298
  //#endregion
1213
1299
  //#region src/cli/commands/secret/create.ts
1214
1300
  const createSecretCommand = defineAppCommand({
@@ -1216,7 +1302,8 @@ const createSecretCommand = defineAppCommand({
1216
1302
  description: "Create a secret in a vault.",
1217
1303
  args: z.object({
1218
1304
  ...workspaceArgs,
1219
- ...secretValueArgs
1305
+ ...secretValueArgs,
1306
+ ...confirmationArgs
1220
1307
  }).strict(),
1221
1308
  run: async (args) => {
1222
1309
  const client = await initOperatorClient(await loadAccessToken({
@@ -1227,6 +1314,17 @@ const createSecretCommand = defineAppCommand({
1227
1314
  workspaceId: args["workspace-id"],
1228
1315
  profile: args.profile
1229
1316
  });
1317
+ const managed = await checkVaultManaged({
1318
+ client,
1319
+ workspaceId,
1320
+ vaultName: args["vault-name"]
1321
+ });
1322
+ if (managed.isManaged && !args.yes) {
1323
+ if (!await prompt.confirm({
1324
+ message: "Do you want to proceed?",
1325
+ default: false
1326
+ })) return;
1327
+ }
1230
1328
  try {
1231
1329
  await client.createSecretManagerSecret({
1232
1330
  workspaceId,
@@ -1241,6 +1339,10 @@ const createSecretCommand = defineAppCommand({
1241
1339
  }
1242
1340
  throw error;
1243
1341
  }
1342
+ if (managed.isManaged) await releaseVaultOwnership({
1343
+ client,
1344
+ ...managed
1345
+ });
1244
1346
  logger.success(`Secret: ${args.name} created in vault: ${args["vault-name"]}`);
1245
1347
  }
1246
1348
  });
@@ -1264,6 +1366,11 @@ const deleteSecretCommand = defineAppCommand({
1264
1366
  workspaceId: args["workspace-id"],
1265
1367
  profile: args.profile
1266
1368
  });
1369
+ const managed = await checkVaultManaged({
1370
+ client,
1371
+ workspaceId,
1372
+ vaultName: args["vault-name"]
1373
+ });
1267
1374
  if (!args.yes) {
1268
1375
  if (await prompt.text({ message: `Enter the secret name to confirm deletion ("${args.name}"):` }) !== args.name) {
1269
1376
  logger.info("Secret deletion cancelled.");
@@ -1280,6 +1387,10 @@ const deleteSecretCommand = defineAppCommand({
1280
1387
  if (error instanceof ConnectError && error.code === Code.NotFound) throw new Error(`Secret "${args.name}" not found in vault "${args["vault-name"]}".`);
1281
1388
  throw error;
1282
1389
  }
1390
+ if (managed.isManaged) await releaseVaultOwnership({
1391
+ client,
1392
+ ...managed
1393
+ });
1283
1394
  logger.success(`Secret: ${args.name} deleted from vault: ${args["vault-name"]}`);
1284
1395
  }
1285
1396
  });
@@ -1346,7 +1457,8 @@ const updateSecretCommand = defineAppCommand({
1346
1457
  description: "Update a secret in a vault.",
1347
1458
  args: z.object({
1348
1459
  ...workspaceArgs,
1349
- ...secretValueArgs
1460
+ ...secretValueArgs,
1461
+ ...confirmationArgs
1350
1462
  }).strict(),
1351
1463
  run: async (args) => {
1352
1464
  const client = await initOperatorClient(await loadAccessToken({
@@ -1357,6 +1469,17 @@ const updateSecretCommand = defineAppCommand({
1357
1469
  workspaceId: args["workspace-id"],
1358
1470
  profile: args.profile
1359
1471
  });
1472
+ const managed = await checkVaultManaged({
1473
+ client,
1474
+ workspaceId,
1475
+ vaultName: args["vault-name"]
1476
+ });
1477
+ if (managed.isManaged && !args.yes) {
1478
+ if (!await prompt.confirm({
1479
+ message: "Do you want to proceed?",
1480
+ default: false
1481
+ })) return;
1482
+ }
1360
1483
  try {
1361
1484
  await client.updateSecretManagerSecret({
1362
1485
  workspaceId,
@@ -1368,6 +1491,10 @@ const updateSecretCommand = defineAppCommand({
1368
1491
  if (error instanceof ConnectError && error.code === Code.NotFound) throw new Error(`Secret "${args.name}" not found in vault "${args["vault-name"]}".`);
1369
1492
  throw error;
1370
1493
  }
1494
+ if (managed.isManaged) await releaseVaultOwnership({
1495
+ client,
1496
+ ...managed
1497
+ });
1371
1498
  logger.success(`Secret: ${args.name} updated in vault: ${args["vault-name"]}`);
1372
1499
  }
1373
1500
  });
@@ -1429,6 +1556,11 @@ const deleteCommand$1 = defineAppCommand({
1429
1556
  workspaceId: args["workspace-id"],
1430
1557
  profile: args.profile
1431
1558
  });
1559
+ const managed = await checkVaultManaged({
1560
+ client,
1561
+ workspaceId,
1562
+ vaultName: args.name
1563
+ });
1432
1564
  if (!args.yes) {
1433
1565
  if (await prompt.text({ message: `Enter the vault name to confirm deletion ("${args.name}"):` }) !== args.name) {
1434
1566
  logger.info("Vault deletion cancelled.");
@@ -1444,6 +1576,7 @@ const deleteCommand$1 = defineAppCommand({
1444
1576
  if (error instanceof ConnectError && error.code === Code.NotFound) throw new Error(`Vault "${args.name}" not found.`);
1445
1577
  throw error;
1446
1578
  }
1579
+ if (managed.isManaged) logger.info("Remove this vault from defineSecretManager() in your config to prevent the next apply from re-creating it.");
1447
1580
  logger.success(`Vault: ${args.name} deleted`);
1448
1581
  }
1449
1582
  });
@@ -3082,11 +3215,11 @@ runMain(mainCommand, {
3082
3215
  if (isVerbose() && error.stack) logger.debug(`\nStack trace:\n${error.stack}`);
3083
3216
  } else logger.error(`Unknown error: ${error}`);
3084
3217
  if (!isCLIError(error) && (!(error instanceof Error) || error instanceof TypeError || error instanceof RangeError)) {
3085
- const { reportCrash } = await import("../crash-report-Cot_9Esm.mjs");
3218
+ const { reportCrash } = await import("../crash-report-CYrETw1c.mjs");
3086
3219
  await reportCrash(error, "handledError");
3087
3220
  }
3088
3221
  }
3089
- const { shutdownTelemetry } = await import("../telemetry-BevrwWwF.mjs");
3222
+ const { shutdownTelemetry } = await import("../telemetry-BtN2l0f1.mjs");
3090
3223
  await shutdownTelemetry();
3091
3224
  }
3092
3225
  });