@treeseed/sdk 0.4.8 → 0.4.10

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 (73) hide show
  1. package/README.md +1 -1
  2. package/dist/control-plane-client.d.ts +45 -0
  3. package/dist/control-plane-client.js +229 -0
  4. package/dist/control-plane.d.ts +94 -0
  5. package/dist/control-plane.js +125 -0
  6. package/dist/d1-store.d.ts +56 -1
  7. package/dist/d1-store.js +132 -0
  8. package/dist/dispatch.d.ts +4 -0
  9. package/dist/dispatch.js +180 -0
  10. package/dist/index.d.ts +14 -2
  11. package/dist/index.js +94 -4
  12. package/dist/operations/services/config-runtime.d.ts +10 -0
  13. package/dist/operations/services/config-runtime.js +62 -4
  14. package/dist/operations/services/deploy.d.ts +95 -3
  15. package/dist/operations/services/deploy.js +351 -10
  16. package/dist/operations/services/github-automation.d.ts +37 -1
  17. package/dist/operations/services/github-automation.js +71 -14
  18. package/dist/operations/services/project-platform.d.ts +835 -0
  19. package/dist/operations/services/project-platform.js +782 -0
  20. package/dist/operations/services/railway-deploy.d.ts +113 -18
  21. package/dist/operations/services/railway-deploy.js +357 -8
  22. package/dist/operations/services/runtime-tools.d.ts +25 -1
  23. package/dist/operations/services/runtime-tools.js +66 -5
  24. package/dist/operations/services/template-registry.d.ts +1 -1
  25. package/dist/operations/services/template-registry.js +17 -3
  26. package/dist/platform/books-data.d.ts +3 -4
  27. package/dist/platform/books-data.js +30 -4
  28. package/dist/platform/contracts.d.ts +56 -4
  29. package/dist/platform/deploy-config.js +109 -4
  30. package/dist/platform/deploy-runtime.d.ts +2 -0
  31. package/dist/platform/deploy-runtime.js +9 -1
  32. package/dist/platform/env.yaml +677 -0
  33. package/dist/platform/environment.js +57 -2
  34. package/dist/platform/plugin.d.ts +8 -0
  35. package/dist/platform/plugins/constants.d.ts +2 -0
  36. package/dist/platform/plugins/constants.js +2 -0
  37. package/dist/platform/plugins/runtime.d.ts +2 -0
  38. package/dist/platform/plugins/runtime.js +9 -1
  39. package/dist/platform/plugins.d.ts +1 -1
  40. package/dist/platform/plugins.js +4 -0
  41. package/dist/platform/published-content-pipeline.d.ts +84 -0
  42. package/dist/platform/published-content-pipeline.js +543 -0
  43. package/dist/platform/published-content.d.ts +223 -0
  44. package/dist/platform/published-content.js +588 -0
  45. package/dist/platform/tenant/runtime-config.d.ts +1 -1
  46. package/dist/platform/tenant/runtime-config.js +34 -1
  47. package/dist/platform/tenant-config.d.ts +2 -1
  48. package/dist/platform/tenant-config.js +17 -1
  49. package/dist/platform/utils/site-config-schema.js +104 -0
  50. package/dist/plugin-default.d.ts +2 -0
  51. package/dist/plugin-default.js +2 -0
  52. package/dist/remote.d.ts +65 -9
  53. package/dist/remote.js +104 -28
  54. package/dist/scripts/check-build-warnings.js +50 -0
  55. package/dist/scripts/config-treeseed.js +7 -0
  56. package/dist/scripts/tenant-workflow-action.js +71 -0
  57. package/dist/sdk-dispatch.d.ts +12 -0
  58. package/dist/sdk-dispatch.js +142 -0
  59. package/dist/sdk-types.d.ts +579 -7
  60. package/dist/sdk-types.js +53 -1
  61. package/dist/sdk.d.ts +17 -1
  62. package/dist/sdk.js +109 -0
  63. package/dist/stores/operational-store.d.ts +22 -2
  64. package/dist/stores/operational-store.js +235 -0
  65. package/dist/template-catalog.js +8 -1
  66. package/dist/treeseed/template-catalog/templates/starter-basic/template/treeseed.site.yaml +20 -0
  67. package/dist/types/cloudflare.d.ts +23 -0
  68. package/dist/workflow/operations.d.ts +12 -3
  69. package/dist/workflow/policy.d.ts +1 -1
  70. package/dist/workflow-state.js +2 -1
  71. package/package.json +7 -2
  72. package/templates/github/deploy.workflow.yml +442 -0
  73. package/templates/github/hosted-project.workflow.yml +77 -0
@@ -2,7 +2,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
2
  import { dirname, relative, resolve } from "node:path";
3
3
  import { spawnSync } from "node:child_process";
4
4
  import { resolveTreeseedEnvironmentRegistry } from "../../platform/environment.js";
5
- import { corePackageRoot, loadCliDeployConfig } from "./runtime-tools.js";
5
+ import { packageRoot, loadCliDeployConfig } from "./runtime-tools.js";
6
6
  function envOrNull(key) {
7
7
  const value = process.env[key];
8
8
  return typeof value === "string" && value.length > 0 ? value : null;
@@ -87,19 +87,50 @@ function requiredGitHubEnvironment(tenantRoot, { scope = "prod", purpose = "save
87
87
  function requiredGitHubSecrets(tenantRoot) {
88
88
  return requiredGitHubEnvironment(tenantRoot).secrets;
89
89
  }
90
- function renderDeployWorkflow({ workingDirectory }) {
90
+ function renderTenantWorkflowActionCommand() {
91
+ return [
92
+ "EXTRA_ARGS=()",
93
+ 'if [[ -n "${TREESEED_WORKFLOW_PROJECT:-}" ]]; then EXTRA_ARGS+=(--project-id "${TREESEED_WORKFLOW_PROJECT}"); fi',
94
+ 'if [[ -n "${TREESEED_WORKFLOW_PREVIEW_ID:-}" ]]; then EXTRA_ARGS+=(--preview-id "${TREESEED_WORKFLOW_PREVIEW_ID}"); fi',
95
+ "if test -f ./packages/sdk/scripts/tenant-workflow-action.ts; then",
96
+ ' node ./packages/sdk/scripts/run-ts.mjs ./packages/sdk/scripts/tenant-workflow-action.ts --action "${TREESEED_WORKFLOW_ACTION}" --environment "${TREESEED_WORKFLOW_ENVIRONMENT}" "${EXTRA_ARGS[@]}"',
97
+ "elif test -f ./node_modules/@treeseed/sdk/dist/scripts/tenant-workflow-action.js; then",
98
+ ' node ./node_modules/@treeseed/sdk/dist/scripts/tenant-workflow-action.js --action "${TREESEED_WORKFLOW_ACTION}" --environment "${TREESEED_WORKFLOW_ENVIRONMENT}" "${EXTRA_ARGS[@]}"',
99
+ "else",
100
+ ' echo "Unable to resolve @treeseed/sdk tenant workflow entrypoint."',
101
+ " exit 1",
102
+ "fi"
103
+ ].join("\n");
104
+ }
105
+ function renderWorkflowTemplate(templateName, { workingDirectory }) {
91
106
  const normalizedWorkingDirectory = workingDirectory && workingDirectory !== "." ? workingDirectory : ".";
92
107
  const workingDirectoryLine = normalizedWorkingDirectory === "." ? "" : ` defaults:
93
108
  run:
94
109
  working-directory: ${normalizedWorkingDirectory}
95
110
  `;
96
- const templatePath = resolve(corePackageRoot, "templates", "github", "deploy.workflow.yml");
111
+ const templatePath = resolve(packageRoot, "templates", "github", templateName);
97
112
  const template = readFileSync(templatePath, "utf8");
98
- return template.replace("__WORKING_DIRECTORY_BLOCK__", workingDirectoryLine).replace(
99
- "__CACHE_DEPENDENCY_PATH__",
113
+ const tenantWorkflowActionCommand = renderTenantWorkflowActionCommand().split("\n").map((line) => ` ${line}`).join("\n");
114
+ return template.split("__WORKING_DIRECTORY_BLOCK__").join(workingDirectoryLine).replace("__TENANT_WORKFLOW_ACTION_COMMAND_BLOCK__", tenantWorkflowActionCommand).split("__CACHE_DEPENDENCY_PATH__").join(
100
115
  normalizedWorkingDirectory === "." ? "package-lock.json" : `${normalizedWorkingDirectory}/package-lock.json`
101
116
  );
102
117
  }
118
+ function renderDeployWorkflow({ workingDirectory }) {
119
+ return renderWorkflowTemplate("deploy.workflow.yml", { workingDirectory });
120
+ }
121
+ function renderHostedProjectWorkflow({ workingDirectory }) {
122
+ return renderWorkflowTemplate("hosted-project.workflow.yml", { workingDirectory });
123
+ }
124
+ function ensureWorkflowFile(tenantRoot, fileName, expected) {
125
+ const workflowPath = resolve(tenantRoot, ".github", "workflows", fileName);
126
+ const current = existsSync(workflowPath) ? readFileSync(workflowPath, "utf8") : null;
127
+ if (current === expected) {
128
+ return { workflowPath, changed: false };
129
+ }
130
+ mkdirSync(dirname(workflowPath), { recursive: true });
131
+ writeFileSync(workflowPath, expected, "utf8");
132
+ return { workflowPath, changed: true };
133
+ }
103
134
  function ensureDeployWorkflow(tenantRoot) {
104
135
  if (isGitHubAutomationStubbed()) {
105
136
  return {
@@ -110,16 +141,38 @@ function ensureDeployWorkflow(tenantRoot) {
110
141
  };
111
142
  }
112
143
  const repositoryRoot = resolveGitRepositoryRoot(tenantRoot);
113
- const workflowPath = resolve(tenantRoot, ".github", "workflows", "deploy.yml");
114
144
  const workingDirectory = relative(repositoryRoot, tenantRoot).replaceAll("\\", "/") || ".";
115
145
  const expected = renderDeployWorkflow({ workingDirectory });
116
- const current = existsSync(workflowPath) ? readFileSync(workflowPath, "utf8") : null;
117
- if (current === expected) {
118
- return { workflowPath, changed: false, workingDirectory };
146
+ return {
147
+ ...ensureWorkflowFile(tenantRoot, "deploy.yml", expected),
148
+ workingDirectory
149
+ };
150
+ }
151
+ function ensureHostedProjectWorkflow(tenantRoot) {
152
+ if (isGitHubAutomationStubbed()) {
153
+ return {
154
+ workflowPath: resolve(tenantRoot, ".github", "workflows", "hosted-project.yml"),
155
+ changed: false,
156
+ workingDirectory: ".",
157
+ mode: "stub"
158
+ };
119
159
  }
120
- mkdirSync(dirname(workflowPath), { recursive: true });
121
- writeFileSync(workflowPath, expected, "utf8");
122
- return { workflowPath, changed: true, workingDirectory };
160
+ const repositoryRoot = resolveGitRepositoryRoot(tenantRoot);
161
+ const workingDirectory = relative(repositoryRoot, tenantRoot).replaceAll("\\", "/") || ".";
162
+ const expected = renderHostedProjectWorkflow({ workingDirectory });
163
+ return {
164
+ ...ensureWorkflowFile(tenantRoot, "hosted-project.yml", expected),
165
+ workingDirectory
166
+ };
167
+ }
168
+ function ensureStandardizedGitHubWorkflows(tenantRoot) {
169
+ const deployConfig = loadCliDeployConfig(tenantRoot);
170
+ const deploy = ensureDeployWorkflow(tenantRoot);
171
+ const workflows = [deploy];
172
+ if ((deployConfig.hosting?.kind ?? "self_hosted_project") === "market_control_plane") {
173
+ workflows.push(ensureHostedProjectWorkflow(tenantRoot));
174
+ }
175
+ return workflows;
123
176
  }
124
177
  function listGitHubSecretNames(repository, tenantRoot) {
125
178
  const result = runGh(["secret", "list", "--repo", repository, "--json", "name"], {
@@ -227,11 +280,12 @@ function ensureGitHubEnvironment(tenantRoot, { dryRun = false, scope = "prod", p
227
280
  };
228
281
  }
229
282
  function ensureGitHubDeployAutomation(tenantRoot, { dryRun = false } = {}) {
230
- const workflow = ensureDeployWorkflow(tenantRoot);
283
+ const workflows = ensureStandardizedGitHubWorkflows(tenantRoot);
231
284
  const environment = ensureGitHubEnvironment(tenantRoot, { dryRun });
232
285
  return {
233
286
  mode: getGitHubAutomationMode(),
234
- workflow,
287
+ workflow: workflows[0],
288
+ workflows,
235
289
  secrets: environment.secrets,
236
290
  variables: environment.variables,
237
291
  environment
@@ -242,6 +296,8 @@ export {
242
296
  ensureGitHubDeployAutomation,
243
297
  ensureGitHubEnvironment,
244
298
  ensureGitHubSecrets,
299
+ ensureHostedProjectWorkflow,
300
+ ensureStandardizedGitHubWorkflows,
245
301
  formatMissingSecretsReport,
246
302
  getGitHubAutomationMode,
247
303
  listGitHubSecretNames,
@@ -249,6 +305,7 @@ export {
249
305
  maybeResolveGitHubRepositorySlug,
250
306
  parseGitHubRepositoryFromRemote,
251
307
  renderDeployWorkflow,
308
+ renderHostedProjectWorkflow,
252
309
  requiredGitHubEnvironment,
253
310
  requiredGitHubSecrets,
254
311
  resolveGitHubRepositorySlug,