@tailor-platform/sdk 1.28.0 → 1.30.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 (64) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/{application-CBJFUKrU.mjs → application-Bf8SUAtR.mjs} +97 -77
  3. package/dist/application-Bf8SUAtR.mjs.map +1 -0
  4. package/dist/{application-WyZetOky.mjs → application-DAQVP9CS.mjs} +3 -3
  5. package/dist/chunk-DEt8GZDa.mjs +8 -0
  6. package/dist/cli/index.mjs +118 -52
  7. package/dist/cli/index.mjs.map +1 -1
  8. package/dist/cli/lib.d.mts +208 -43
  9. package/dist/cli/lib.mjs +26 -28
  10. package/dist/cli/lib.mjs.map +1 -1
  11. package/dist/cli/skills.mjs +1 -1
  12. package/dist/client-CW4Oh3iz.mjs +6 -0
  13. package/dist/client-CZmQBXAY.mjs +16294 -0
  14. package/dist/client-CZmQBXAY.mjs.map +1 -0
  15. package/dist/configure/index.d.mts +4 -4
  16. package/dist/configure/index.mjs +1 -1
  17. package/dist/{crash-report-Cot_9Esm.mjs → crash-report-CYrETw1c.mjs} +2 -2
  18. package/dist/{crash-report-Ju8cQF-l.mjs → crash-report-DizNMVnm.mjs} +3 -3
  19. package/dist/{crash-report-Ju8cQF-l.mjs.map → crash-report-DizNMVnm.mjs.map} +1 -1
  20. package/dist/{env-BuMbIknz.d.mts → env-DiWYe80_.d.mts} +2 -2
  21. package/dist/{index-CbnLNm14.d.mts → index-2WQbf_LH.d.mts} +2 -2
  22. package/dist/{index-cD9sQLTh.d.mts → index-BU7Cd5I4.d.mts} +4 -4
  23. package/dist/{index-B0Lrzywd.d.mts → index-DCEMVfJA.d.mts} +2 -2
  24. package/dist/{index-D1AM_02Y.d.mts → index-HvMUWjvV.d.mts} +2 -2
  25. package/dist/{index-CyapgSFI.d.mts → index-rH_De6hM.d.mts} +2 -2
  26. package/dist/{interceptor-B0d_GrI5.mjs → interceptor-DgQNmwWJ.mjs} +2 -2
  27. package/dist/{interceptor-B0d_GrI5.mjs.map → interceptor-DgQNmwWJ.mjs.map} +1 -1
  28. package/dist/kysely/index.mjs +1 -1
  29. package/dist/{package-json-DHfTiUCS.mjs → package-json-DiZWrkIA.mjs} +1 -1
  30. package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
  31. package/dist/plugin/builtin/enum-constants/index.mjs +1 -1
  32. package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
  33. package/dist/plugin/builtin/file-utils/index.mjs +1 -1
  34. package/dist/plugin/builtin/kysely-type/index.d.mts +1 -1
  35. package/dist/plugin/builtin/kysely-type/index.mjs +1 -1
  36. package/dist/plugin/builtin/seed/index.d.mts +1 -1
  37. package/dist/plugin/builtin/seed/index.mjs +1 -1
  38. package/dist/plugin/index.d.mts +2 -2
  39. package/dist/plugin/index.mjs +1 -1
  40. package/dist/{plugin-D3a0-qe0.d.mts → plugin-C-UdAM8C.d.mts} +2 -2
  41. package/dist/{query-WYq8RvYp.mjs → query-C3oQTLvb.mjs} +670 -132
  42. package/dist/query-C3oQTLvb.mjs.map +1 -0
  43. package/dist/schema-BePzTFBV.mjs.map +1 -1
  44. package/dist/seed/index.mjs +1 -1
  45. package/dist/{telemetry-VvNfsyEE.mjs → telemetry-BSUlYTs-.mjs} +2 -2
  46. package/dist/{telemetry-VvNfsyEE.mjs.map → telemetry-BSUlYTs-.mjs.map} +1 -1
  47. package/dist/telemetry-BtN2l0f1.mjs +4 -0
  48. package/dist/utils/test/index.d.mts +2 -2
  49. package/dist/utils/test/index.mjs +1 -1
  50. package/dist/{workflow.generated-BsgIlrH-.d.mts → workflow.generated-C5wMcCjB.d.mts} +2 -2
  51. package/docs/cli/function.md +1 -1
  52. package/docs/cli/organization.md +426 -0
  53. package/docs/cli/user.md +21 -22
  54. package/docs/cli/workspace.md +0 -7
  55. package/docs/cli-reference.md +32 -12
  56. package/docs/services/executor.md +46 -0
  57. package/package.json +8 -8
  58. package/dist/application-CBJFUKrU.mjs.map +0 -1
  59. package/dist/chunk-Cz-A8uMR.mjs +0 -3
  60. package/dist/client-C2_wgujH.mjs +0 -6
  61. package/dist/client-bTbnbQbB.mjs +0 -957
  62. package/dist/client-bTbnbQbB.mjs.map +0 -1
  63. package/dist/query-WYq8RvYp.mjs.map +0 -1
  64. package/dist/telemetry-BevrwWwF.mjs +0 -4
@@ -1,9 +1,9 @@
1
1
  import { t as db } from "./schema-BePzTFBV.mjs";
2
2
  import { i as symbols, n as logger, r as styles, t as CIPromptError } from "./logger-CqezTedh.mjs";
3
- import { A as AuthInvokerSchema, B as GetApplicationSchemaHealthResponse_ApplicationSchemaHealthStatus, C as FunctionExecution_Status, D as ExecutorTriggerType, E as ExecutorTargetType, F as AuthSCIMAttribute_Uniqueness, G as ApplicationSchemaUpdateAttemptStatus, H as Condition_Operator, I as AuthSCIMConfig_AuthorizationType, K as Subgraph_ServiceType, M as AuthOAuth2Client_GrantType, N as AuthSCIMAttribute_Mutability, O as AuthHookPoint, P as AuthSCIMAttribute_Type, R as TenantProviderConfig_TenantProviderType, S as IdPLang, T as ExecutorJobStatus, U as FilterSchema, V as ConditionSchema, W as PageDirection, _ as TailorDBGQLPermission_Permit, b as TailorDBType_PermitAction, d as userAgent, f as WorkspacePlatformUserRole, g as TailorDBGQLPermission_Operator, h as TailorDBGQLPermission_Action, j as AuthOAuth2Client_ClientType, k as AuthIDPConfig_AuthType, l as platformBaseUrl, m as WorkflowJobExecution_Status, n as fetchAll, p as WorkflowExecution_Status, r as fetchMachineUserToken, s as initOperatorClient, u as resolveStaticWebsiteUrls, v as TailorDBType_Permission_Operator, x as PipelineResolver_OperationType, y as TailorDBType_Permission_Permit, z as UserProfileProviderConfig_UserProfileProviderType } from "./client-bTbnbQbB.mjs";
3
+ import { A as AuthHookPoint, B as TenantProviderConfig_TenantProviderType, C as PipelineResolver_OperationType, D as ExecutorJobStatus, F as AuthSCIMAttribute_Mutability, G as FilterSchema, H as GetApplicationSchemaHealthResponse_ApplicationSchemaHealthStatus, I as AuthSCIMAttribute_Type, J as Subgraph_ServiceType, K as PageDirection, L as AuthSCIMAttribute_Uniqueness, M as AuthInvokerSchema, N as AuthOAuth2Client_ClientType, O as ExecutorTargetType, P as AuthOAuth2Client_GrantType, R as AuthSCIMConfig_AuthorizationType, S as TailorDBType_PermitAction, T as FunctionExecution_Status, U as ConditionSchema, V as UserProfileProviderConfig_UserProfileProviderType, W as Condition_Operator, _ as TailorDBGQLPermission_Action, b as TailorDBType_Permission_Operator, d as platformBaseUrl, f as resolveStaticWebsiteUrls, g as WorkflowJobExecution_Status, h as WorkflowExecution_Status, i as fetchMachineUserToken, j as AuthIDPConfig_AuthType, k as ExecutorTriggerType, l as initOperatorClient, m as WorkspacePlatformUserRole, p as userAgent, q as ApplicationSchemaUpdateAttemptStatus, r as fetchAll, v as TailorDBGQLPermission_Operator, w as IdPLang, x as TailorDBType_Permission_Permit, y as TailorDBGQLPermission_Permit } from "./client-CZmQBXAY.mjs";
4
4
  import { t as readPackageJson } from "./package-json-D3x2nBPB.mjs";
5
- import { S as writePlatformConfig, _ as hashFile, a as loadConfig, b as loadWorkspaceId, d as TailorDBTypeSchema, f as stringifyFunction, g as getDistDir, h as createBundleCache, l as OAuth2ClientSchema, m as loadFilesWithIgnores, n as generatePluginFilesIfNeeded, p as tailorUserMap, r as loadApplication, s as createExecutorService, t as defineApplication, x as readPlatformConfig, y as loadAccessToken } from "./application-CBJFUKrU.mjs";
6
- import { r as withSpan } from "./telemetry-VvNfsyEE.mjs";
5
+ import { S as writePlatformConfig, _ as hashFile, a as loadConfig, b as loadWorkspaceId, d as TailorDBTypeSchema, f as stringifyFunction, g as getDistDir, h as createBundleCache, l as OAuth2ClientSchema, m as loadFilesWithIgnores, n as generatePluginFilesIfNeeded, p as tailorUserMap, r as loadApplication, s as createExecutorService, t as defineApplication, x as readPlatformConfig, y as loadAccessToken } from "./application-Bf8SUAtR.mjs";
6
+ import { r as withSpan } from "./telemetry-BSUlYTs-.mjs";
7
7
  import { arg, createDefineCommand, defineCommand, runCommand } from "politty";
8
8
  import { z } from "zod";
9
9
  import * as fs$1 from "node:fs";
@@ -15,20 +15,20 @@ import { formatDistanceToNowStrict } from "date-fns";
15
15
  import { getBorderCharacters, table } from "table";
16
16
  import { ValueSchema, timestampDate } from "@bufbuild/protobuf/wkt";
17
17
  import { Code, ConnectError } from "@connectrpc/connect";
18
+ import * as crypto from "node:crypto";
19
+ import { createHash } from "node:crypto";
20
+ import { pathToFileURL } from "node:url";
18
21
  import { resolveTSConfig } from "pkg-types";
19
22
  import { tmpdir } from "node:os";
20
23
  import { findUpSync } from "find-up-simple";
21
24
  import ml from "multiline-ts";
22
- import * as crypto from "node:crypto";
23
- import { createHash } from "node:crypto";
24
25
  import * as rolldown from "rolldown";
25
26
  import * as fs from "node:fs/promises";
26
27
  import { glob } from "node:fs/promises";
27
- import { pathToFileURL } from "node:url";
28
28
  import * as inflection from "inflection";
29
29
  import { create, fromJson, toJson } from "@bufbuild/protobuf";
30
30
  import { ExitPromptError } from "@inquirer/core";
31
- import { confirm, input } from "@inquirer/prompts";
31
+ import { confirm, input, password } from "@inquirer/prompts";
32
32
  import { isCI } from "std-env";
33
33
  import ora from "ora";
34
34
  import { setTimeout as setTimeout$1 } from "timers/promises";
@@ -180,6 +180,24 @@ const confirmationArgs = { yes: arg(z.boolean().default(false), {
180
180
  alias: "y",
181
181
  description: "Skip confirmation prompts"
182
182
  }) };
183
+ /**
184
+ * Arguments for commands that require organization context
185
+ */
186
+ const organizationArgs = { "organization-id": arg(z.string(), {
187
+ alias: "o",
188
+ description: "Organization ID",
189
+ env: "TAILOR_PLATFORM_ORGANIZATION_ID",
190
+ completion: { type: "none" }
191
+ }) };
192
+ /**
193
+ * Arguments for commands that require folder context
194
+ */
195
+ const folderArgs = { "folder-id": arg(z.string(), {
196
+ alias: "f",
197
+ description: "Folder ID",
198
+ env: "TAILOR_PLATFORM_FOLDER_ID",
199
+ completion: { type: "none" }
200
+ }) };
183
201
  let verboseMode = false;
184
202
  /**
185
203
  * Returns whether verbose mode is enabled.
@@ -351,28 +369,18 @@ function createCacheStore(config) {
351
369
  const manifest = ensureManifestLoaded();
352
370
  delete manifest.entries[key];
353
371
  }
354
- function storeBundleOutput(cacheKey, sourcePath) {
372
+ function storeBundleContent(cacheKey, content) {
355
373
  const dir = bundlesDir();
356
374
  fs$1.mkdirSync(dir, { recursive: true });
357
- fs$1.copyFileSync(sourcePath, bundlePath(cacheKey));
358
- const mapSource = `${sourcePath}.map`;
359
- const cachedMapPath = `${bundlePath(cacheKey)}.map`;
360
- if (fs$1.existsSync(mapSource)) fs$1.copyFileSync(mapSource, cachedMapPath);
361
- else fs$1.rmSync(cachedMapPath, { force: true });
362
- }
363
- function restoreBundleOutput(cacheKey, targetPath) {
364
- const cached = bundlePath(cacheKey);
365
- const targetDir = path.dirname(targetPath);
366
- fs$1.mkdirSync(targetDir, { recursive: true });
375
+ fs$1.writeFileSync(bundlePath(cacheKey), content, "utf-8");
376
+ }
377
+ function restoreBundleContent(cacheKey) {
367
378
  try {
368
- fs$1.copyFileSync(cached, targetPath);
379
+ return fs$1.readFileSync(bundlePath(cacheKey), "utf-8");
369
380
  } catch (e) {
370
- if (e.code === "ENOENT") return false;
381
+ if (e.code === "ENOENT") return void 0;
371
382
  throw e;
372
383
  }
373
- const cachedMap = `${cached}.map`;
374
- if (fs$1.existsSync(cachedMap)) fs$1.copyFileSync(cachedMap, `${targetPath}.map`);
375
- return true;
376
384
  }
377
385
  function clean() {
378
386
  fs$1.rmSync(config.cacheDir, {
@@ -388,8 +396,8 @@ function createCacheStore(config) {
388
396
  getEntry,
389
397
  setEntry,
390
398
  deleteEntry,
391
- storeBundleOutput,
392
- restoreBundleOutput,
399
+ storeBundleContent,
400
+ restoreBundleContent,
393
401
  clean
394
402
  };
395
403
  }
@@ -405,9 +413,7 @@ function createCacheManager(options) {
405
413
  if (!(options.enabled ?? true)) return {
406
414
  enabled: false,
407
415
  bundleCache: {
408
- tryRestore() {
409
- return false;
410
- },
416
+ tryRestore() {},
411
417
  save() {}
412
418
  },
413
419
  finalize() {}
@@ -1124,74 +1130,70 @@ function authHookFunctionName(authName, hookPoint) {
1124
1130
  return `auth-hook--${authName}--${hookPoint}`;
1125
1131
  }
1126
1132
  /**
1127
- * Collect all function entries from bundled scripts for all services.
1133
+ * Collect all function entries from in-memory bundled scripts for all services.
1128
1134
  * @param application - Application definition
1129
1135
  * @param workflowJobs - Collected workflow jobs from config
1136
+ * @param bundledScripts - In-memory bundled code organized by kind
1130
1137
  * @returns Array of function entries to register
1131
1138
  */
1132
- function collectFunctionEntries(application, workflowJobs) {
1139
+ function collectFunctionEntries(application, workflowJobs, bundledScripts) {
1133
1140
  const entries = [];
1134
- const distDir = getDistDir();
1135
1141
  for (const app of application.applications) for (const pipeline of app.resolverServices) for (const resolver of Object.values(pipeline.resolvers)) {
1136
- const scriptPath = path.join(distDir, "resolvers", `${resolver.name}.js`);
1137
- try {
1138
- const content = fs$1.readFileSync(scriptPath, "utf-8");
1139
- entries.push({
1140
- name: resolverFunctionName(pipeline.namespace, resolver.name),
1141
- scriptContent: content,
1142
- contentHash: computeContentHash(content),
1143
- description: `Resolver: ${pipeline.namespace}/${resolver.name}`
1144
- });
1145
- } catch {
1146
- logger.warn(`Function file not found: ${scriptPath}`);
1142
+ const content = bundledScripts.resolvers.get(resolver.name);
1143
+ if (!content) {
1144
+ logger.warn(`Bundled code not found for resolver: ${resolver.name}`);
1145
+ continue;
1147
1146
  }
1147
+ entries.push({
1148
+ name: resolverFunctionName(pipeline.namespace, resolver.name),
1149
+ scriptContent: content,
1150
+ contentHash: computeContentHash(content),
1151
+ description: `Resolver: ${pipeline.namespace}/${resolver.name}`
1152
+ });
1148
1153
  }
1149
1154
  if (application.executorService) {
1150
1155
  const executors = application.executorService.executors;
1151
1156
  for (const executor of Object.values(executors)) if (executor.operation.kind === "function" || executor.operation.kind === "jobFunction") {
1152
- const scriptPath = path.join(distDir, "executors", `${executor.name}.js`);
1153
- try {
1154
- const content = fs$1.readFileSync(scriptPath, "utf-8");
1155
- entries.push({
1156
- name: executorFunctionName(executor.name),
1157
- scriptContent: content,
1158
- contentHash: computeContentHash(content),
1159
- description: `Executor: ${executor.name}`
1160
- });
1161
- } catch {
1162
- logger.warn(`Function file not found: ${scriptPath}`);
1157
+ const content = bundledScripts.executors.get(executor.name);
1158
+ if (!content) {
1159
+ logger.warn(`Bundled code not found for executor: ${executor.name}`);
1160
+ continue;
1163
1161
  }
1164
- }
1165
- }
1166
- for (const job of workflowJobs) {
1167
- const scriptPath = path.join(distDir, "workflow-jobs", `${job.name}.js`);
1168
- try {
1169
- const content = fs$1.readFileSync(scriptPath, "utf-8");
1170
1162
  entries.push({
1171
- name: workflowJobFunctionName(job.name),
1163
+ name: executorFunctionName(executor.name),
1172
1164
  scriptContent: content,
1173
1165
  contentHash: computeContentHash(content),
1174
- description: `Workflow job: ${job.name}`
1166
+ description: `Executor: ${executor.name}`
1175
1167
  });
1176
- } catch {
1177
- logger.warn(`Function file not found: ${scriptPath}`);
1178
1168
  }
1179
1169
  }
1170
+ for (const job of workflowJobs) {
1171
+ const content = bundledScripts.workflowJobs.get(job.name);
1172
+ if (!content) {
1173
+ logger.warn(`Bundled code not found for workflow job: ${job.name}`);
1174
+ continue;
1175
+ }
1176
+ entries.push({
1177
+ name: workflowJobFunctionName(job.name),
1178
+ scriptContent: content,
1179
+ contentHash: computeContentHash(content),
1180
+ description: `Workflow job: ${job.name}`
1181
+ });
1182
+ }
1180
1183
  for (const app of application.applications) if (app.authService?.config.hooks?.beforeLogin) {
1181
1184
  const authName = app.authService.config.name;
1182
1185
  const funcName = authHookFunctionName(authName, "before-login");
1183
- const scriptPath = path.join(distDir, "auth-hooks", `${funcName}.js`);
1184
- try {
1185
- const content = fs$1.readFileSync(scriptPath, "utf-8");
1186
- entries.push({
1187
- name: funcName,
1188
- scriptContent: content,
1189
- contentHash: computeContentHash(content),
1190
- description: `Auth hook: ${authName}/before-login`
1191
- });
1192
- } catch {
1193
- logger.warn(`Function file not found: ${scriptPath}`);
1186
+ const content = bundledScripts.authHooks.get(funcName);
1187
+ if (!content) {
1188
+ logger.warn(`Bundled code not found for auth hook: ${funcName}`);
1189
+ continue;
1194
1190
  }
1191
+ entries.push({
1192
+ name: funcName,
1193
+ scriptContent: content,
1194
+ contentHash: computeContentHash(content),
1195
+ description: `Auth hook: ${authName}/before-login`
1196
+ });
1195
1197
  }
1196
1198
  return entries;
1197
1199
  }
@@ -2622,7 +2624,8 @@ function withGuard(fn) {
2622
2624
  }
2623
2625
  const prompt = {
2624
2626
  confirm: withGuard(confirm),
2625
- text: withGuard(input)
2627
+ text: withGuard(input),
2628
+ password: withGuard(password)
2626
2629
  };
2627
2630
 
2628
2631
  //#endregion
@@ -2850,7 +2853,7 @@ async function planExecutor(context) {
2850
2853
  name: executor.name,
2851
2854
  request: {
2852
2855
  workspaceId,
2853
- executor: protoExecutor(application.name, executor, application.env)
2856
+ executor: protoExecutor(application, executor)
2854
2857
  },
2855
2858
  metaRequest
2856
2859
  });
@@ -2859,7 +2862,7 @@ async function planExecutor(context) {
2859
2862
  name: executor.name,
2860
2863
  request: {
2861
2864
  workspaceId,
2862
- executor: protoExecutor(application.name, executor, application.env)
2865
+ executor: protoExecutor(application, executor)
2863
2866
  },
2864
2867
  metaRequest
2865
2868
  });
@@ -2883,7 +2886,26 @@ async function planExecutor(context) {
2883
2886
  resourceOwners
2884
2887
  };
2885
2888
  }
2886
- function protoExecutor(appName, executor, env) {
2889
+ function resolveTailorDBNamespace(application, typeName) {
2890
+ for (const service of application.tailorDBServices) if (service.types[typeName]) return service.namespace;
2891
+ throw new Error(`TailorDB type "${typeName}" not found in any namespace. Available namespaces: ${application.tailorDBServices.map((s) => s.namespace).join(", ")}`);
2892
+ }
2893
+ function resolveResolverNamespace(application, resolverName) {
2894
+ for (const service of application.resolverServices) if (Object.values(service.resolvers).some((r) => r.name === resolverName)) return service.namespace;
2895
+ throw new Error(`Resolver "${resolverName}" not found in any namespace. Available namespaces: ${application.resolverServices.map((s) => s.namespace).join(", ")}`);
2896
+ }
2897
+ function resolveIdpNamespace(application) {
2898
+ if (application.idpServices.length === 0) throw new Error("No IdP service configured");
2899
+ if (application.idpServices.length > 1) throw new Error("Multiple IdP services found; cannot determine which to use for executor trigger");
2900
+ return application.idpServices[0].name;
2901
+ }
2902
+ function resolveAuthNamespace(application) {
2903
+ if (!application.authService) throw new Error("No Auth service configured");
2904
+ return application.authService.parsedConfig.name;
2905
+ }
2906
+ function protoExecutor(application, executor) {
2907
+ const appName = application.name;
2908
+ const env = application.env;
2887
2909
  const trigger = executor.trigger;
2888
2910
  let triggerType;
2889
2911
  let triggerConfig;
@@ -2900,6 +2922,12 @@ function protoExecutor(appName, executor, env) {
2900
2922
  authAccessTokenRefreshed: "auth.access_token.refreshed",
2901
2923
  authAccessTokenRevoked: "auth.access_token.revoked"
2902
2924
  };
2925
+ function typedEventTrigger(typedConfig) {
2926
+ return { config: {
2927
+ case: "event",
2928
+ value: { typedConfig }
2929
+ } };
2930
+ }
2903
2931
  switch (trigger.kind) {
2904
2932
  case "schedule":
2905
2933
  triggerType = ExecutorTriggerType.SCHEDULE;
@@ -2915,23 +2943,27 @@ function protoExecutor(appName, executor, env) {
2915
2943
  case "recordUpdated":
2916
2944
  case "recordDeleted":
2917
2945
  triggerType = ExecutorTriggerType.EVENT;
2918
- triggerConfig = { config: {
2919
- case: "event",
2946
+ triggerConfig = typedEventTrigger({
2947
+ case: "tailordb",
2920
2948
  value: {
2921
- eventType: eventType[trigger.kind],
2922
- condition: { expr: [`args.typeName === "${trigger.typeName}"`, ...trigger.condition ? [`(${stringifyFunction(trigger.condition)})(${argsExpr})`] : []].join(" && ") }
2949
+ eventTypes: [eventType[trigger.kind]],
2950
+ namespaceName: resolveTailorDBNamespace(application, trigger.typeName),
2951
+ typeName: trigger.typeName,
2952
+ ...trigger.condition ? { condition: { expr: `(${stringifyFunction(trigger.condition)})(${argsExpr})` } } : {}
2923
2953
  }
2924
- } };
2954
+ });
2925
2955
  break;
2926
2956
  case "resolverExecuted":
2927
2957
  triggerType = ExecutorTriggerType.EVENT;
2928
- triggerConfig = { config: {
2929
- case: "event",
2958
+ triggerConfig = typedEventTrigger({
2959
+ case: "pipeline",
2930
2960
  value: {
2931
- eventType: eventType[trigger.kind],
2932
- condition: { expr: [`args.resolverName === "${trigger.resolverName}"`, ...trigger.condition ? [`(${stringifyFunction(trigger.condition)})(${argsExpr})`] : []].join(" && ") }
2961
+ eventTypes: [eventType[trigger.kind]],
2962
+ namespaceName: resolveResolverNamespace(application, trigger.resolverName),
2963
+ resolverName: trigger.resolverName,
2964
+ ...trigger.condition ? { condition: { expr: `(${stringifyFunction(trigger.condition)})(${argsExpr})` } } : {}
2933
2965
  }
2934
- } };
2966
+ });
2935
2967
  break;
2936
2968
  case "incomingWebhook":
2937
2969
  triggerType = ExecutorTriggerType.INCOMING_WEBHOOK;
@@ -2943,14 +2975,26 @@ function protoExecutor(appName, executor, env) {
2943
2975
  case "idpUserCreated":
2944
2976
  case "idpUserUpdated":
2945
2977
  case "idpUserDeleted":
2978
+ triggerType = ExecutorTriggerType.EVENT;
2979
+ triggerConfig = typedEventTrigger({
2980
+ case: "idp",
2981
+ value: {
2982
+ eventTypes: [eventType[trigger.kind]],
2983
+ namespaceName: resolveIdpNamespace(application)
2984
+ }
2985
+ });
2986
+ break;
2946
2987
  case "authAccessTokenIssued":
2947
2988
  case "authAccessTokenRefreshed":
2948
2989
  case "authAccessTokenRevoked":
2949
2990
  triggerType = ExecutorTriggerType.EVENT;
2950
- triggerConfig = { config: {
2951
- case: "event",
2952
- value: { eventType: eventType[trigger.kind] }
2953
- } };
2991
+ triggerConfig = typedEventTrigger({
2992
+ case: "auth",
2993
+ value: {
2994
+ eventTypes: [eventType[trigger.kind]],
2995
+ namespaceName: resolveAuthNamespace(application)
2996
+ }
2997
+ });
2954
2998
  break;
2955
2999
  default: throw new Error(`Unknown trigger: ${trigger}`);
2956
3000
  }
@@ -5006,7 +5050,6 @@ async function bundleMigrationScript(sourceFile, namespace, migrationNumber) {
5006
5050
  const outputDir = path.resolve(getDistDir(), "migrations");
5007
5051
  fs$1.mkdirSync(outputDir, { recursive: true });
5008
5052
  const entryPath = path.join(outputDir, `migration_${namespace}_${migrationNumber}.entry.js`);
5009
- const outputPath = path.join(outputDir, `migration_${namespace}_${migrationNumber}.js`);
5010
5053
  const entryContent = ml`
5011
5054
  import { main as _migrationMain } from "${path.resolve(sourceFile).replace(/\\/g, "/")}";
5012
5055
  import { Kysely, TailordbDialect } from "@tailor-platform/sdk/kysely";
@@ -5033,30 +5076,29 @@ async function bundleMigrationScript(sourceFile, namespace, migrationNumber) {
5033
5076
  } catch {
5034
5077
  tsconfig = void 0;
5035
5078
  }
5036
- await rolldown.build(rolldown.defineConfig({
5037
- input: entryPath,
5038
- output: {
5039
- file: outputPath,
5040
- format: "esm",
5041
- sourcemap: false,
5042
- minify: false,
5043
- codeSplitting: false,
5044
- globals: { tailordb: "tailordb" }
5045
- },
5046
- external: ["tailordb"],
5047
- resolve: { conditionNames: ["node", "import"] },
5048
- tsconfig,
5049
- treeshake: {
5050
- moduleSideEffects: false,
5051
- annotations: true,
5052
- unknownGlobalSideEffects: false
5053
- },
5054
- logLevel: "silent"
5055
- }));
5056
5079
  return {
5057
5080
  namespace,
5058
5081
  migrationNumber,
5059
- bundledCode: fs$1.readFileSync(outputPath, "utf-8")
5082
+ bundledCode: (await rolldown.build({
5083
+ input: entryPath,
5084
+ write: false,
5085
+ output: {
5086
+ format: "esm",
5087
+ sourcemap: false,
5088
+ minify: false,
5089
+ codeSplitting: false,
5090
+ globals: { tailordb: "tailordb" }
5091
+ },
5092
+ external: ["tailordb"],
5093
+ resolve: { conditionNames: ["node", "import"] },
5094
+ tsconfig,
5095
+ treeshake: {
5096
+ moduleSideEffects: false,
5097
+ annotations: true,
5098
+ unknownGlobalSideEffects: false
5099
+ },
5100
+ logLevel: "silent"
5101
+ })).output[0].code
5060
5102
  };
5061
5103
  }
5062
5104
 
@@ -6663,12 +6705,12 @@ async function planWorkflow(client, workspaceId, appName, workflows, mainJobDeps
6663
6705
  /**
6664
6706
  * Apply the configured application to the Tailor platform.
6665
6707
  * @param options - Options for apply execution
6666
- * @returns Promise that resolves when apply completes
6708
+ * @returns Promise that resolves to `{ bundledScripts }` when `buildOnly` is true, otherwise void
6667
6709
  */
6668
6710
  async function apply(options) {
6669
6711
  return withSpan("apply", async (rootSpan) => {
6670
6712
  rootSpan.setAttribute("apply.dry_run", options?.dryRun ?? false);
6671
- const { config, application, workflowBuildResult, buildOnly } = await withSpan("build", async () => {
6713
+ const { config, application, workflowBuildResult, bundledScripts, buildOnly } = await withSpan("build", async () => {
6672
6714
  const { config, plugins } = await withSpan("build.loadConfig", () => loadConfig(options?.configPath));
6673
6715
  const dryRun = options?.dryRun ?? false;
6674
6716
  const buildOnly = options?.buildOnly ?? process.env.TAILOR_PLATFORM_SDK_BUILD_ONLY === "true";
@@ -6698,6 +6740,7 @@ async function apply(options) {
6698
6740
  }));
6699
6741
  let application;
6700
6742
  let workflowBuildResult;
6743
+ let bundledScripts;
6701
6744
  try {
6702
6745
  const result = await withSpan("build.loadApplication", () => loadApplication({
6703
6746
  config,
@@ -6706,6 +6749,7 @@ async function apply(options) {
6706
6749
  }));
6707
6750
  application = result.application;
6708
6751
  workflowBuildResult = result.workflowBuildResult;
6752
+ bundledScripts = result.bundledScripts;
6709
6753
  } finally {
6710
6754
  cacheManager.finalize();
6711
6755
  }
@@ -6714,11 +6758,12 @@ async function apply(options) {
6714
6758
  plugins,
6715
6759
  application,
6716
6760
  workflowBuildResult,
6761
+ bundledScripts,
6717
6762
  dryRun,
6718
6763
  buildOnly
6719
6764
  };
6720
6765
  });
6721
- if (buildOnly) return;
6766
+ if (buildOnly) return { bundledScripts };
6722
6767
  const client = await initOperatorClient(await loadAccessToken({
6723
6768
  useProfile: true,
6724
6769
  profile: options?.profile
@@ -6730,7 +6775,7 @@ async function apply(options) {
6730
6775
  rootSpan.setAttribute("app.name", application.name);
6731
6776
  rootSpan.setAttribute("workspace.id", workspaceId);
6732
6777
  const workflowService = application.workflowService;
6733
- const functionEntries = collectFunctionEntries(application, workflowService?.jobs ?? []);
6778
+ const functionEntries = collectFunctionEntries(application, workflowService?.jobs ?? [], bundledScripts);
6734
6779
  const dryRun = options?.dryRun ?? false;
6735
6780
  const yes = options?.yes ?? false;
6736
6781
  const { functionRegistry, tailorDB, staticWebsite, idp, auth, pipeline, app, executor, workflow, secretManager } = await withSpan("plan", async () => {
@@ -7173,7 +7218,7 @@ async function getExecutor(options) {
7173
7218
  throw error;
7174
7219
  }
7175
7220
  }
7176
- const getCommand$3 = defineAppCommand({
7221
+ const getCommand$5 = defineAppCommand({
7177
7222
  name: "get",
7178
7223
  description: "Get executor details",
7179
7224
  args: z.object({
@@ -7649,7 +7694,7 @@ async function getWorkflow(options) {
7649
7694
  throw error;
7650
7695
  }
7651
7696
  }
7652
- const getCommand$2 = defineAppCommand({
7697
+ const getCommand$4 = defineAppCommand({
7653
7698
  name: "get",
7654
7699
  description: "Get workflow details.",
7655
7700
  args: z.object({
@@ -8268,7 +8313,7 @@ async function listExecutors(options) {
8268
8313
  return [executors, nextPageToken];
8269
8314
  })).map((e) => toExecutorListInfo(e));
8270
8315
  }
8271
- const listCommand$6 = defineAppCommand({
8316
+ const listCommand$8 = defineAppCommand({
8272
8317
  name: "list",
8273
8318
  description: "List all executors",
8274
8319
  args: z.object({ ...workspaceArgs }).strict(),
@@ -9469,7 +9514,7 @@ async function listMachineUsers(options) {
9469
9514
  return [machineUsers, nextPageToken];
9470
9515
  })).map(machineUserInfo);
9471
9516
  }
9472
- const listCommand$5 = defineAppCommand({
9517
+ const listCommand$7 = defineAppCommand({
9473
9518
  name: "list",
9474
9519
  description: "List all machine users in the application.",
9475
9520
  args: z.object({ ...deploymentArgs }).strict(),
@@ -9624,7 +9669,7 @@ async function getOAuth2Client(options) {
9624
9669
  throw error;
9625
9670
  }
9626
9671
  }
9627
- const getCommand$1 = defineAppCommand({
9672
+ const getCommand$3 = defineAppCommand({
9628
9673
  name: "get",
9629
9674
  description: "Get OAuth2 client credentials (including client secret).",
9630
9675
  args: z.object({
@@ -9677,7 +9722,7 @@ async function listOAuth2Clients(options) {
9677
9722
  return [oauth2Clients, nextPageToken];
9678
9723
  })).map(toOAuth2ClientInfo);
9679
9724
  }
9680
- const listCommand$4 = defineAppCommand({
9725
+ const listCommand$6 = defineAppCommand({
9681
9726
  name: "list",
9682
9727
  description: "List all OAuth2 clients in the application.",
9683
9728
  args: z.object({ ...deploymentArgs }).strict(),
@@ -9691,6 +9736,501 @@ const listCommand$4 = defineAppCommand({
9691
9736
  }
9692
9737
  });
9693
9738
 
9739
+ //#endregion
9740
+ //#region src/cli/commands/organization/transform.ts
9741
+ const userOrganizationInfo = (org) => ({
9742
+ organizationId: org.organizationId,
9743
+ organizationName: org.organizationName,
9744
+ rootFolderId: org.rootFolderId,
9745
+ rootFolderName: org.rootFolderName,
9746
+ displayName: org.displayName
9747
+ });
9748
+ const organizationInfo = (org) => ({
9749
+ id: org.id,
9750
+ name: org.name,
9751
+ createdAt: formatTimestamp(org.createTime),
9752
+ updatedAt: formatTimestamp(org.updateTime)
9753
+ });
9754
+ const folderListInfo = (folder) => ({
9755
+ id: folder.id,
9756
+ name: folder.name,
9757
+ organizationId: folder.organizationId,
9758
+ parentFolderId: folder.parentFolderId,
9759
+ hasChildren: folder.hasChildren,
9760
+ createdAt: formatTimestamp(folder.createTime)
9761
+ });
9762
+ const folderInfo = (folder) => ({
9763
+ ...folderListInfo(folder),
9764
+ updatedAt: formatTimestamp(folder.updateTime)
9765
+ });
9766
+
9767
+ //#endregion
9768
+ //#region src/cli/commands/organization/folder/create.ts
9769
+ const createFolderOptionsSchema = z.object({
9770
+ organizationId: z.uuid({ message: "organization-id must be a valid UUID" }),
9771
+ parentFolderId: z.string().optional(),
9772
+ name: z.string().min(1, "Name must not be empty")
9773
+ });
9774
+ /**
9775
+ * Create a new folder in an organization.
9776
+ * @param options - Folder creation options
9777
+ * @returns Created folder details
9778
+ */
9779
+ async function createFolder(options) {
9780
+ const result = createFolderOptionsSchema.safeParse(options);
9781
+ if (!result.success) throw new Error(result.error.issues[0].message);
9782
+ const response = await (await initOperatorClient(await loadAccessToken())).createOrganizationFolder({
9783
+ organizationId: result.data.organizationId,
9784
+ parentFolderId: result.data.parentFolderId ?? "",
9785
+ folderName: result.data.name
9786
+ });
9787
+ if (!response.folder) throw new Error("Failed to create folder.");
9788
+ return folderInfo(response.folder);
9789
+ }
9790
+ const createCommand$1 = defineAppCommand({
9791
+ name: "create",
9792
+ description: "Create a new folder in an organization.",
9793
+ args: z.object({
9794
+ ...organizationArgs,
9795
+ "parent-folder-id": arg(z.string().optional(), { description: "Parent folder ID" }),
9796
+ name: arg(z.string(), {
9797
+ alias: "n",
9798
+ description: "Folder name"
9799
+ })
9800
+ }).strict(),
9801
+ run: async (args) => {
9802
+ const folder = await createFolder({
9803
+ organizationId: args["organization-id"],
9804
+ parentFolderId: args["parent-folder-id"],
9805
+ name: args.name
9806
+ });
9807
+ if (!args.json) logger.success(`Folder "${folder.name}" created successfully.`);
9808
+ logger.out(folder);
9809
+ }
9810
+ });
9811
+
9812
+ //#endregion
9813
+ //#region src/cli/commands/organization/folder/delete.ts
9814
+ const deleteFolderOptionsSchema = z.object({
9815
+ organizationId: z.uuid({ message: "organization-id must be a valid UUID" }),
9816
+ folderId: z.uuid({ message: "folder-id must be a valid UUID" })
9817
+ });
9818
+ /**
9819
+ * Delete a folder from an organization.
9820
+ * @param options - Folder deletion options
9821
+ * @returns Promise that resolves when deletion completes
9822
+ */
9823
+ async function deleteFolder(options) {
9824
+ const result = deleteFolderOptionsSchema.safeParse(options);
9825
+ if (!result.success) throw new Error(result.error.issues[0].message);
9826
+ await (await initOperatorClient(await loadAccessToken())).deleteOrganizationFolder({
9827
+ organizationId: result.data.organizationId,
9828
+ folderId: result.data.folderId
9829
+ });
9830
+ }
9831
+ const deleteCommand$1 = defineAppCommand({
9832
+ name: "delete",
9833
+ description: "Delete a folder from an organization.",
9834
+ args: z.object({
9835
+ ...organizationArgs,
9836
+ ...folderArgs,
9837
+ ...confirmationArgs
9838
+ }).strict(),
9839
+ run: async (args) => {
9840
+ const client = await initOperatorClient(await loadAccessToken());
9841
+ let folderName;
9842
+ try {
9843
+ folderName = (await client.getOrganizationFolder({
9844
+ organizationId: args["organization-id"],
9845
+ folderId: args["folder-id"]
9846
+ })).folder?.name;
9847
+ } catch {
9848
+ throw new Error(`Folder "${args["folder-id"]}" not found.`);
9849
+ }
9850
+ if (!args.yes) {
9851
+ if (!await prompt.confirm({ message: `Are you sure you want to delete folder "${folderName}"?` })) {
9852
+ logger.info("Folder deletion cancelled.");
9853
+ return;
9854
+ }
9855
+ }
9856
+ await client.deleteOrganizationFolder({
9857
+ organizationId: args["organization-id"],
9858
+ folderId: args["folder-id"]
9859
+ });
9860
+ logger.success(`Folder "${folderName}" deleted successfully.`);
9861
+ }
9862
+ });
9863
+
9864
+ //#endregion
9865
+ //#region src/cli/commands/organization/folder/get.ts
9866
+ const getFolderOptionsSchema = z.object({
9867
+ organizationId: z.uuid({ message: "organization-id must be a valid UUID" }),
9868
+ folderId: z.uuid({ message: "folder-id must be a valid UUID" })
9869
+ });
9870
+ /**
9871
+ * Get detailed information about a folder.
9872
+ * @param options - Folder get options
9873
+ * @returns Folder details
9874
+ */
9875
+ async function getFolder(options) {
9876
+ const result = getFolderOptionsSchema.safeParse(options);
9877
+ if (!result.success) throw new Error(result.error.issues[0].message);
9878
+ const response = await (await initOperatorClient(await loadAccessToken())).getOrganizationFolder({
9879
+ organizationId: result.data.organizationId,
9880
+ folderId: result.data.folderId
9881
+ });
9882
+ if (!response.folder) throw new Error(`Folder "${result.data.folderId}" not found.`);
9883
+ return folderInfo(response.folder);
9884
+ }
9885
+ const getCommand$2 = defineAppCommand({
9886
+ name: "get",
9887
+ description: "Show detailed information about a folder.",
9888
+ args: z.object({
9889
+ ...organizationArgs,
9890
+ ...folderArgs
9891
+ }).strict(),
9892
+ run: async (args) => {
9893
+ const folder = await getFolder({
9894
+ organizationId: args["organization-id"],
9895
+ folderId: args["folder-id"]
9896
+ });
9897
+ const formattedFolder = args.json ? folder : {
9898
+ ...folder,
9899
+ createdAt: humanizeRelativeTime(folder.createdAt),
9900
+ updatedAt: humanizeRelativeTime(folder.updatedAt)
9901
+ };
9902
+ logger.out(formattedFolder);
9903
+ }
9904
+ });
9905
+
9906
+ //#endregion
9907
+ //#region src/cli/commands/organization/folder/list.ts
9908
+ const listFoldersOptionsSchema = z.object({
9909
+ organizationId: z.uuid({ message: "organization-id must be a valid UUID" }),
9910
+ parentFolderId: z.string().optional(),
9911
+ limit: z.number().int().positive().optional()
9912
+ });
9913
+ /**
9914
+ * List folders in an organization.
9915
+ * @param options - Folder listing options
9916
+ * @returns List of folders
9917
+ */
9918
+ async function listFolders(options) {
9919
+ const result = listFoldersOptionsSchema.safeParse(options);
9920
+ if (!result.success) throw new Error(result.error.issues[0].message);
9921
+ const { organizationId, parentFolderId, limit } = result.data;
9922
+ const hasLimit = limit !== void 0;
9923
+ const client = await initOperatorClient(await loadAccessToken());
9924
+ const results = [];
9925
+ let pageToken = "";
9926
+ while (true) {
9927
+ if (hasLimit && results.length >= limit) break;
9928
+ const remaining = hasLimit ? limit - results.length : void 0;
9929
+ const pageSize = remaining !== void 0 && remaining > 0 ? remaining : void 0;
9930
+ const response = await client.listOrganizationFolders({
9931
+ organizationId,
9932
+ ...parentFolderId ? { parentFolderId } : {},
9933
+ pageToken,
9934
+ ...pageSize !== void 0 ? { pageSize } : {}
9935
+ });
9936
+ const mapped = response.folders.map(folderListInfo);
9937
+ if (remaining !== void 0 && mapped.length > remaining) results.push(...mapped.slice(0, remaining));
9938
+ else results.push(...mapped);
9939
+ if (!response.nextPageToken) break;
9940
+ pageToken = response.nextPageToken;
9941
+ }
9942
+ return results;
9943
+ }
9944
+ const listCommand$5 = defineAppCommand({
9945
+ name: "list",
9946
+ description: "List folders in an organization.",
9947
+ args: z.object({
9948
+ ...organizationArgs,
9949
+ "parent-folder-id": arg(z.string().optional(), { description: "Parent folder ID to list children of" }),
9950
+ limit: arg(positiveIntArg.optional(), {
9951
+ alias: "l",
9952
+ description: "Maximum number of folders to list"
9953
+ })
9954
+ }).strict(),
9955
+ run: async (args) => {
9956
+ const folders = await listFolders({
9957
+ organizationId: args["organization-id"],
9958
+ parentFolderId: args["parent-folder-id"],
9959
+ limit: args.limit
9960
+ });
9961
+ logger.out(folders, { display: { updatedAt: null } });
9962
+ }
9963
+ });
9964
+
9965
+ //#endregion
9966
+ //#region src/cli/commands/organization/folder/update.ts
9967
+ const updateFolderOptionsSchema = z.object({
9968
+ organizationId: z.uuid({ message: "organization-id must be a valid UUID" }),
9969
+ folderId: z.uuid({ message: "folder-id must be a valid UUID" }),
9970
+ name: z.string().min(1, "Name must not be empty")
9971
+ });
9972
+ /**
9973
+ * Update a folder's name.
9974
+ * @param options - Folder update options
9975
+ * @returns Updated folder details
9976
+ */
9977
+ async function updateFolder(options) {
9978
+ const result = updateFolderOptionsSchema.safeParse(options);
9979
+ if (!result.success) throw new Error(result.error.issues[0].message);
9980
+ const response = await (await initOperatorClient(await loadAccessToken())).updateOrganizationFolder({
9981
+ organizationId: result.data.organizationId,
9982
+ folderId: result.data.folderId,
9983
+ folderName: result.data.name
9984
+ });
9985
+ if (!response.folder) throw new Error(`Failed to update folder "${result.data.folderId}".`);
9986
+ return folderInfo(response.folder);
9987
+ }
9988
+ const updateCommand$2 = defineAppCommand({
9989
+ name: "update",
9990
+ description: "Update a folder's name.",
9991
+ args: z.object({
9992
+ ...organizationArgs,
9993
+ ...folderArgs,
9994
+ name: arg(z.string(), {
9995
+ alias: "n",
9996
+ description: "New folder name"
9997
+ })
9998
+ }).strict(),
9999
+ run: async (args) => {
10000
+ const folder = await updateFolder({
10001
+ organizationId: args["organization-id"],
10002
+ folderId: args["folder-id"],
10003
+ name: args.name
10004
+ });
10005
+ if (!args.json) logger.success(`Folder "${folder.name}" updated successfully.`);
10006
+ logger.out(folder);
10007
+ }
10008
+ });
10009
+
10010
+ //#endregion
10011
+ //#region src/cli/commands/organization/get.ts
10012
+ const getOrganizationOptionsSchema = z.object({ organizationId: z.uuid({ message: "organization-id must be a valid UUID" }) });
10013
+ /**
10014
+ * Get detailed information about an organization.
10015
+ * @param options - Organization get options
10016
+ * @returns Organization details
10017
+ */
10018
+ async function getOrganization(options) {
10019
+ const result = getOrganizationOptionsSchema.safeParse(options);
10020
+ if (!result.success) throw new Error(result.error.issues[0].message);
10021
+ const response = await (await initOperatorClient(await loadAccessToken())).getOrganization({ organizationId: result.data.organizationId });
10022
+ if (!response.organization) throw new Error(`Organization "${result.data.organizationId}" not found.`);
10023
+ return organizationInfo(response.organization);
10024
+ }
10025
+ const getCommand$1 = defineAppCommand({
10026
+ name: "get",
10027
+ description: "Show detailed information about an organization.",
10028
+ args: z.object({ ...organizationArgs }).strict(),
10029
+ run: async (args) => {
10030
+ const organization = await getOrganization({ organizationId: args["organization-id"] });
10031
+ const formattedOrganization = args.json ? organization : {
10032
+ ...organization,
10033
+ createdAt: humanizeRelativeTime(organization.createdAt),
10034
+ updatedAt: humanizeRelativeTime(organization.updatedAt)
10035
+ };
10036
+ logger.out(formattedOrganization);
10037
+ }
10038
+ });
10039
+
10040
+ //#endregion
10041
+ //#region src/cli/commands/organization/list.ts
10042
+ /**
10043
+ * List organizations the current user belongs to.
10044
+ * @param options - Organization listing options
10045
+ * @returns List of user organizations
10046
+ */
10047
+ async function listOrganizations(options) {
10048
+ const limit = options?.limit;
10049
+ const { userOrganizations } = await (await initOperatorClient(await loadAccessToken())).listUserOrganizations({});
10050
+ const results = userOrganizations.map(userOrganizationInfo);
10051
+ if (limit !== void 0) return results.slice(0, limit);
10052
+ return results;
10053
+ }
10054
+ const listCommand$4 = defineAppCommand({
10055
+ name: "list",
10056
+ description: "List organizations you belong to.",
10057
+ args: z.object({ limit: arg(positiveIntArg.optional(), {
10058
+ alias: "l",
10059
+ description: "Maximum number of organizations to list"
10060
+ }) }).strict(),
10061
+ run: async (args) => {
10062
+ const organizations = await listOrganizations({ limit: args.limit });
10063
+ logger.out(organizations);
10064
+ }
10065
+ });
10066
+
10067
+ //#endregion
10068
+ //#region src/cli/commands/organization/tree.ts
10069
+ async function fetchChildFolders(client, organizationId, parentFolderId, currentDepth, maxDepth) {
10070
+ if (maxDepth !== void 0 && currentDepth >= maxDepth) return [];
10071
+ const folders = await fetchAll(async (pageToken, maxPageSize) => {
10072
+ const response = await client.listOrganizationFolders({
10073
+ organizationId,
10074
+ parentFolderId,
10075
+ pageToken,
10076
+ pageSize: maxPageSize
10077
+ });
10078
+ return [response.folders, response.nextPageToken];
10079
+ });
10080
+ const nodes = [];
10081
+ for (const folder of folders) {
10082
+ const children = folder.hasChildren ? await fetchChildFolders(client, organizationId, folder.id, currentDepth + 1, maxDepth) : [];
10083
+ nodes.push({
10084
+ name: folder.name,
10085
+ children
10086
+ });
10087
+ }
10088
+ return nodes;
10089
+ }
10090
+ async function buildFolderTreeJson(client, organizationId, parentFolderId, currentDepth, maxDepth) {
10091
+ if (maxDepth !== void 0 && currentDepth >= maxDepth) return [];
10092
+ const folders = await fetchAll(async (pageToken, maxPageSize) => {
10093
+ const response = await client.listOrganizationFolders({
10094
+ organizationId,
10095
+ parentFolderId,
10096
+ pageToken,
10097
+ pageSize: maxPageSize
10098
+ });
10099
+ return [response.folders, response.nextPageToken];
10100
+ });
10101
+ const result = [];
10102
+ for (const folder of folders) {
10103
+ const children = folder.hasChildren ? await buildFolderTreeJson(client, organizationId, folder.id, currentDepth + 1, maxDepth) : [];
10104
+ result.push({
10105
+ id: folder.id,
10106
+ name: folder.name,
10107
+ children
10108
+ });
10109
+ }
10110
+ return result;
10111
+ }
10112
+ function renderTree(nodes, prefix) {
10113
+ let output = "";
10114
+ for (let i = 0; i < nodes.length; i++) {
10115
+ const isLast = i === nodes.length - 1;
10116
+ const connector = isLast ? "└── " : "├── ";
10117
+ const childPrefix = isLast ? " " : "│ ";
10118
+ output += `${prefix}${connector}${nodes[i].name}\n`;
10119
+ if (nodes[i].children.length > 0) output += renderTree(nodes[i].children, prefix + childPrefix);
10120
+ }
10121
+ return output;
10122
+ }
10123
+ async function buildOrgTree(client, org, depth) {
10124
+ const children = await fetchChildFolders(client, org.organizationId, org.rootFolderId, 0, depth);
10125
+ let output = `${org.organizationName}\n`;
10126
+ output += renderTree(children, "");
10127
+ return output;
10128
+ }
10129
+ /**
10130
+ * Display a tree view of organizations and their folder hierarchy.
10131
+ * @param options - Tree display options
10132
+ * @returns Organization tree as structured data
10133
+ */
10134
+ async function organizationTree(options) {
10135
+ const client = await initOperatorClient(await loadAccessToken());
10136
+ let orgs;
10137
+ if (options?.organizationId) {
10138
+ orgs = (await listOrganizations()).filter((o) => o.organizationId === options.organizationId);
10139
+ if (orgs.length === 0) throw new Error(`Organization "${options.organizationId}" not found.`);
10140
+ } else orgs = await listOrganizations();
10141
+ const depth = options?.depth;
10142
+ const jsonResult = [];
10143
+ for (const org of orgs) {
10144
+ const folders = await buildFolderTreeJson(client, org.organizationId, org.rootFolderId, 0, depth);
10145
+ jsonResult.push({
10146
+ organizationId: org.organizationId,
10147
+ organizationName: org.organizationName,
10148
+ folders
10149
+ });
10150
+ }
10151
+ return jsonResult;
10152
+ }
10153
+ const treeCommand = defineAppCommand({
10154
+ name: "tree",
10155
+ description: "Display organization folder hierarchy as a tree.",
10156
+ args: z.object({
10157
+ "organization-id": arg(z.string().optional(), {
10158
+ alias: "o",
10159
+ description: "Organization ID (show all if omitted)",
10160
+ env: "TAILOR_PLATFORM_ORGANIZATION_ID"
10161
+ }),
10162
+ depth: arg(positiveIntArg.optional(), {
10163
+ alias: "d",
10164
+ description: "Maximum folder depth to display"
10165
+ })
10166
+ }).strict(),
10167
+ run: async (args) => {
10168
+ const client = await initOperatorClient(await loadAccessToken());
10169
+ let orgs;
10170
+ if (args["organization-id"]) {
10171
+ orgs = (await listOrganizations()).filter((o) => o.organizationId === args["organization-id"]);
10172
+ if (orgs.length === 0) throw new Error(`Organization "${args["organization-id"]}" not found.`);
10173
+ } else orgs = await listOrganizations();
10174
+ if (args.json) {
10175
+ const jsonResult = [];
10176
+ for (const org of orgs) {
10177
+ const folders = await buildFolderTreeJson(client, org.organizationId, org.rootFolderId, 0, args.depth);
10178
+ jsonResult.push({
10179
+ organizationId: org.organizationId,
10180
+ organizationName: org.organizationName,
10181
+ folders
10182
+ });
10183
+ }
10184
+ logger.out(jsonResult);
10185
+ return;
10186
+ }
10187
+ const trees = [];
10188
+ for (const org of orgs) trees.push(await buildOrgTree(client, org, args.depth));
10189
+ logger.log(trees.join("\n"));
10190
+ }
10191
+ });
10192
+
10193
+ //#endregion
10194
+ //#region src/cli/commands/organization/update.ts
10195
+ const updateOrganizationOptionsSchema = z.object({
10196
+ organizationId: z.uuid({ message: "organization-id must be a valid UUID" }),
10197
+ name: z.string().min(1, "Name must not be empty")
10198
+ });
10199
+ /**
10200
+ * Update an organization's name.
10201
+ * @param options - Organization update options
10202
+ * @returns Updated organization details
10203
+ */
10204
+ async function updateOrganization(options) {
10205
+ const result = updateOrganizationOptionsSchema.safeParse(options);
10206
+ if (!result.success) throw new Error(result.error.issues[0].message);
10207
+ const response = await (await initOperatorClient(await loadAccessToken())).updateOrganization({
10208
+ organizationId: result.data.organizationId,
10209
+ organizationName: result.data.name
10210
+ });
10211
+ if (!response.organization) throw new Error(`Failed to update organization "${result.data.organizationId}".`);
10212
+ return organizationInfo(response.organization);
10213
+ }
10214
+ const updateCommand$1 = defineAppCommand({
10215
+ name: "update",
10216
+ description: "Update an organization's name.",
10217
+ args: z.object({
10218
+ ...organizationArgs,
10219
+ name: arg(z.string(), {
10220
+ alias: "n",
10221
+ description: "New organization name"
10222
+ })
10223
+ }).strict(),
10224
+ run: async (args) => {
10225
+ const organization = await updateOrganization({
10226
+ organizationId: args["organization-id"],
10227
+ name: args.name
10228
+ });
10229
+ if (!args.json) logger.success(`Organization "${organization.name}" updated successfully.`);
10230
+ logger.out(organization);
10231
+ }
10232
+ });
10233
+
9694
10234
  //#endregion
9695
10235
  //#region src/cli/commands/remove.ts
9696
10236
  async function loadOptions$10(options) {
@@ -10425,7 +10965,7 @@ async function generate(options) {
10425
10965
  if (options.init) await handleInitOption(namespacesWithMigrations, options.yes);
10426
10966
  let pluginManager;
10427
10967
  if (plugins.length > 0) pluginManager = new PluginManager(plugins);
10428
- const { defineApplication } = await import("./application-WyZetOky.mjs");
10968
+ const { defineApplication } = await import("./application-DAQVP9CS.mjs");
10429
10969
  const application = defineApplication({
10430
10970
  config,
10431
10971
  pluginManager
@@ -11709,7 +12249,6 @@ async function bundleQueryScript(engine) {
11709
12249
  const outputDir = path.resolve(getDistDir(), "query");
11710
12250
  fs$1.mkdirSync(outputDir, { recursive: true });
11711
12251
  const entryPath = path.join(outputDir, `query_${engine}.entry.ts`);
11712
- const outputPath = path.join(outputDir, `query_${engine}.js`);
11713
12252
  const entryContent = engine === "sql" ? createSqlEntry() : createGqlEntry();
11714
12253
  fs$1.writeFileSync(entryPath, entryContent);
11715
12254
  let tsconfig;
@@ -11718,10 +12257,10 @@ async function bundleQueryScript(engine) {
11718
12257
  } catch {
11719
12258
  tsconfig = void 0;
11720
12259
  }
11721
- await rolldown.build(rolldown.defineConfig({
12260
+ return (await rolldown.build({
11722
12261
  input: entryPath,
12262
+ write: false,
11723
12263
  output: {
11724
- file: outputPath,
11725
12264
  format: "esm",
11726
12265
  sourcemap: false,
11727
12266
  minify: false,
@@ -11737,8 +12276,7 @@ async function bundleQueryScript(engine) {
11737
12276
  unknownGlobalSideEffects: false
11738
12277
  },
11739
12278
  logLevel: "silent"
11740
- }));
11741
- return fs$1.readFileSync(outputPath, "utf-8");
12279
+ })).output[0].code;
11742
12280
  }
11743
12281
 
11744
12282
  //#endregion
@@ -12603,5 +13141,5 @@ function printGqlResult(result, options = {}) {
12603
13141
  }
12604
13142
 
12605
13143
  //#endregion
12606
- export { listExecutors as $, workspaceArgs as $t, truncate as A, getLatestMigrationNumber as At, listOAuth2Clients as B, hasChanges as Bt, listCommand$2 as C, INITIAL_SCHEMA_NUMBER as Ct, resumeWorkflow as D, compareSnapshots as Dt, resumeCommand as E, compareLocalTypesWithSnapshot as Et, showCommand as F, isValidMigrationNumber as Ft, listCommand$5 as G, generateUserTypes as Gt, getOAuth2Client as H, prompt as Ht, logBetaWarning as I, loadDiff as It, listWebhookExecutors as J, defineAppCommand as Jt, listMachineUsers as K, apiCall as Kt, remove as L, reconstructSnapshotFromMigrations as Lt, generate as M, getMigrationFilePath as Mt, generateCommand as N, getMigrationFiles as Nt, listCommand$3 as O, createSnapshotFromLocalTypes as Ot, show as P, getNextMigrationNumber as Pt, listCommand$6 as Q, isVerbose as Qt, removeCommand$1 as R, formatDiffSummary as Rt, listApps as S, DIFF_FILE_NAME as St, healthCommand as T, SCHEMA_FILE_NAME as Tt, getMachineUserToken as U, sdkNameLabelKey as Ut, getCommand$1 as V, getNamespacesWithMigrations as Vt, tokenCommand as W, trnPrefix as Wt, triggerCommand as X, confirmationArgs as Xt, webhookCommand as Y, commonArgs as Yt, triggerExecutor as Z, deploymentArgs as Zt, getWorkspace as _, waitForExecution$1 as _t, updateUser as a, startWorkflow as at, createCommand as b, bundleMigrationScript as bt, listCommand as c, executionsCommand as ct, inviteUser as d, functionExecutionStatusToString as dt, getExecutorJob as et, restoreCommand as f, formatKeyValueTable as ft, getCommand as g, executeScript as gt, listWorkspaces as h, apply as ht, updateCommand as i, startCommand as it, truncateCommand as j, getMigrationDirPath as jt, listWorkflows as k, formatMigrationNumber as kt, listUsers as l, getWorkflowExecution as lt, listCommand$1 as m, getExecutor as mt, queryCommand as n, listExecutorJobs as nt, removeCommand as o, getCommand$2 as ot, restoreWorkspace as p, getCommand$3 as pt, generate$1 as q, apiCommand as qt, isCLIError as r, watchExecutorJob as rt, removeUser as s, getWorkflow as st, query as t, jobsCommand as tt, inviteCommand as u, listWorkflowExecutions as ut, deleteCommand as v, MIGRATION_LABEL_KEY as vt, getAppHealth as w, MIGRATE_FILE_NAME as wt, createWorkspace as x, DB_TYPES_FILE_NAME as xt, deleteWorkspace as y, parseMigrationLabelNumber as yt, listCommand$4 as z, formatMigrationDiff as zt };
12607
- //# sourceMappingURL=query-WYq8RvYp.mjs.map
13144
+ export { deleteCommand$1 as $, isValidMigrationNumber as $t, truncate as A, formatKeyValueTable as At, updateOrganization as B, DIFF_FILE_NAME as Bt, listCommand$2 as C, startWorkflow as Ct, resumeWorkflow as D, getWorkflowExecution as Dt, resumeCommand as E, executionsCommand as Et, showCommand as F, waitForExecution$1 as Ft, getCommand$1 as G, compareSnapshots as Gt, treeCommand as H, MIGRATE_FILE_NAME as Ht, logBetaWarning as I, MIGRATION_LABEL_KEY as It, updateFolder as J, getLatestMigrationNumber as Jt, getOrganization as K, createSnapshotFromLocalTypes as Kt, remove as L, parseMigrationLabelNumber as Lt, generate as M, getExecutor as Mt, generateCommand as N, apply as Nt, listCommand$3 as O, listWorkflowExecutions as Ot, show as P, executeScript as Pt, getFolder as Q, getNextMigrationNumber as Qt, removeCommand$1 as R, bundleMigrationScript as Rt, listApps as S, startCommand as St, healthCommand as T, getWorkflow as Tt, listCommand$4 as U, SCHEMA_FILE_NAME as Ut, organizationTree as V, INITIAL_SCHEMA_NUMBER as Vt, listOrganizations as W, compareLocalTypesWithSnapshot as Wt, listFolders as X, getMigrationFilePath as Xt, listCommand$5 as Y, getMigrationDirPath as Yt, getCommand$2 as Z, getMigrationFiles as Zt, getWorkspace as _, workspaceArgs as _n, listExecutors as _t, updateUser as a, getNamespacesWithMigrations as an, getCommand$3 as at, createCommand as b, listExecutorJobs as bt, listCommand as c, trnPrefix as cn, tokenCommand as ct, inviteUser as d, apiCommand as dn, generate$1 as dt, loadDiff as en, deleteFolder as et, restoreCommand as f, defineAppCommand as fn, listWebhookExecutors as ft, getCommand as g, isVerbose as gn, listCommand$8 as gt, listWorkspaces as h, deploymentArgs as hn, triggerExecutor as ht, updateCommand as i, hasChanges as in, listOAuth2Clients as it, truncateCommand as j, getCommand$5 as jt, listWorkflows as k, functionExecutionStatusToString as kt, listUsers as l, generateUserTypes as ln, listCommand$7 as lt, listCommand$1 as m, confirmationArgs as mn, triggerCommand as mt, queryCommand as n, formatDiffSummary as nn, createFolder as nt, removeCommand as o, prompt as on, getOAuth2Client as ot, restoreWorkspace as p, commonArgs as pn, webhookCommand as pt, updateCommand$2 as q, formatMigrationNumber as qt, isCLIError as r, formatMigrationDiff as rn, listCommand$6 as rt, removeUser as s, sdkNameLabelKey as sn, getMachineUserToken as st, query as t, reconstructSnapshotFromMigrations as tn, createCommand$1 as tt, inviteCommand as u, apiCall as un, listMachineUsers as ut, deleteCommand as v, getExecutorJob as vt, getAppHealth as w, getCommand$4 as wt, createWorkspace as x, watchExecutorJob as xt, deleteWorkspace as y, jobsCommand as yt, updateCommand$1 as z, DB_TYPES_FILE_NAME as zt };
13145
+ //# sourceMappingURL=query-C3oQTLvb.mjs.map