@apotech-os/cli 0.2.0 → 0.3.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.
package/dist/index.js CHANGED
@@ -22631,7 +22631,10 @@ var RelationDefSchema = external_exports.object({
22631
22631
  var FIELD_NAME_REGEX = /^[a-zA-Z][a-zA-Z0-9_]*$/;
22632
22632
  var FieldDefSchema = external_exports.object({
22633
22633
  universalIdentifier: external_exports.string().uuid(),
22634
- name: external_exports.string().regex(FIELD_NAME_REGEX, "field name must be a valid identifier (letters, digits, underscore; start with a letter)"),
22634
+ name: external_exports.string().regex(
22635
+ FIELD_NAME_REGEX,
22636
+ "field name must be a valid identifier (letters, digits, underscore; start with a letter)"
22637
+ ),
22635
22638
  type: external_exports.nativeEnum(FieldType),
22636
22639
  label: external_exports.string(),
22637
22640
  description: external_exports.string().optional(),
@@ -22644,7 +22647,8 @@ var IndexDefSchema = external_exports.object({
22644
22647
  universalIdentifier: external_exports.string(),
22645
22648
  // Field names in indexes are subject to the same identifier constraint as FieldDef.name.
22646
22649
  fields: external_exports.array(external_exports.string().regex(FIELD_NAME_REGEX, "index field name must be a valid identifier")).min(1),
22647
- isUnique: external_exports.boolean().optional()
22650
+ isUnique: external_exports.boolean().optional(),
22651
+ aggregateIndex: external_exports.boolean().optional()
22648
22652
  });
22649
22653
  var ViewFilterSchema = external_exports.object({
22650
22654
  field: external_exports.string(),
@@ -22664,10 +22668,23 @@ var ViewDefSchema = external_exports.object({
22664
22668
  sorts: external_exports.array(ViewSortSchema).optional(),
22665
22669
  isDefault: external_exports.boolean().optional()
22666
22670
  });
22667
- var ALLOWED_INTEGRATION_EVENTS = [
22668
- "shopify.order.placed",
22669
- "pipedrive.entity.changed"
22671
+ var RESERVED_EVENT_PREFIXES = [
22672
+ "app-",
22673
+ "app.",
22674
+ "shopify.",
22675
+ "pipedrive.",
22676
+ "app-record."
22670
22677
  ];
22678
+ var CUSTOM_EVENT_NAME_REGEX = /^[a-z][a-z0-9]*([.-][a-z0-9]+)*$/;
22679
+ var CustomEventNameSchema = external_exports.string().regex(
22680
+ CUSTOM_EVENT_NAME_REGEX,
22681
+ 'event name must be lowercase dotted-segments (e.g. "order.fulfilled")'
22682
+ ).refine(
22683
+ (name) => !RESERVED_EVENT_PREFIXES.some((prefix) => name.startsWith(prefix)),
22684
+ {
22685
+ message: `event name starts with a reserved prefix (${RESERVED_EVENT_PREFIXES.join(", ")})`
22686
+ }
22687
+ );
22671
22688
  var FunctionTriggerSchema = external_exports.discriminatedUnion("type", [
22672
22689
  external_exports.object({
22673
22690
  type: external_exports.literal("cron"),
@@ -22687,14 +22704,44 @@ var FunctionTriggerSchema = external_exports.discriminatedUnion("type", [
22687
22704
  }),
22688
22705
  external_exports.object({
22689
22706
  type: external_exports.literal("event"),
22690
- /** Integration event name. Must be in ALLOWED_INTEGRATION_EVENTS. */
22691
- name: external_exports.enum(ALLOWED_INTEGRATION_EVENTS)
22707
+ /**
22708
+ * Event name for function triggers. Accepts:
22709
+ * - Integration events from ALLOWED_INTEGRATION_EVENTS (e.g. 'shopify.order.placed')
22710
+ * - Custom events declared in the same manifest's `emits` array (e.g. 'order.fulfilled')
22711
+ *
22712
+ * Cross-manifest validation (custom name ∈ manifest.emits) is enforced by
22713
+ * AppSyncService.validateManifestConstraints, not here in the Zod schema.
22714
+ */
22715
+ name: external_exports.string()
22692
22716
  })
22693
22717
  ]);
22694
22718
  var FunctionDefSchema = external_exports.object({
22695
22719
  universalIdentifier: external_exports.string(),
22696
22720
  name: external_exports.string(),
22697
- trigger: FunctionTriggerSchema
22721
+ trigger: FunctionTriggerSchema,
22722
+ /**
22723
+ * P9 — Maximum retry attempts for this function (0 = no retries, fail immediately).
22724
+ * Capped by the shared router's maximum (currently 4). When absent the router
22725
+ * default of 4 applies.
22726
+ */
22727
+ retries: external_exports.number().int().min(0).optional(),
22728
+ /**
22729
+ * P9 — Best-effort concurrency hint for this function.
22730
+ *
22731
+ * NOTE — DOCUMENTED LIMITATION: Under the shared-router dispatch model the platform
22732
+ * cannot attach a per-app-function Inngest concurrency limit because there is no
22733
+ * per-app-function Inngest function. This value is stored in the manifest and
22734
+ * validated, but is NOT enforced at the Inngest level. A warning is logged at app
22735
+ * sync time so operators are aware. Enforcement would require migrating to
22736
+ * per-function Inngest registrations, which is out of scope for P9.
22737
+ */
22738
+ concurrency: external_exports.number().int().min(1).optional(),
22739
+ /**
22740
+ * P9 — Name of an intra-app event or function to fire on terminal failure.
22741
+ * Must be a name declared in manifest.emits OR the name of another function in
22742
+ * the same app. Cross-manifest validation is enforced by AppSyncService.
22743
+ */
22744
+ onFailure: external_exports.string().optional()
22698
22745
  });
22699
22746
  var AppRoleSchema = external_exports.object({
22700
22747
  reads: external_exports.array(external_exports.string()),
@@ -22704,16 +22751,48 @@ var AppRoleSchema = external_exports.object({
22704
22751
  * action: '*' grants access to all actions for the provider (wildcard).
22705
22752
  * provider: 'llm' with action: 'complete' grants LLM access.
22706
22753
  */
22707
- actions: external_exports.array(external_exports.object({ provider: external_exports.string(), action: external_exports.string() }))
22754
+ actions: external_exports.array(external_exports.object({ provider: external_exports.string(), action: external_exports.string() })),
22755
+ /**
22756
+ * Framework primitive capabilities granted to the app token.
22757
+ * Each string is a capability name, e.g. 'inbox'.
22758
+ * Absence means the capability is denied (deny-by-default, backward-compatible).
22759
+ * P2 approvals will reuse this field.
22760
+ */
22761
+ capabilities: external_exports.array(external_exports.string()).optional()
22708
22762
  });
22709
22763
  var PageDefSchema = external_exports.object({
22710
22764
  universalIdentifier: external_exports.string().uuid(),
22711
- path: external_exports.string().regex(/^[a-zA-Z0-9_-]+$/, "page path must be a simple slug (letters, digits, hyphens, underscores)"),
22765
+ path: external_exports.string().regex(
22766
+ /^[a-zA-Z0-9_-]+$/,
22767
+ "page path must be a simple slug (letters, digits, hyphens, underscores)"
22768
+ ),
22712
22769
  title: external_exports.string(),
22713
22770
  icon: external_exports.string().optional(),
22714
22771
  entry: external_exports.string()
22715
22772
  // relative path inside the tarball, e.g. 'dist/ui/attribution.js'
22716
22773
  });
22774
+ var SettingsFieldSchema = external_exports.object({
22775
+ key: external_exports.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/, "settings key must be a valid identifier"),
22776
+ type: external_exports.enum(["string", "number", "boolean", "select", "json"]),
22777
+ label: external_exports.string(),
22778
+ default: external_exports.unknown().optional(),
22779
+ options: external_exports.array(external_exports.string()).optional(),
22780
+ /** `secret: false` is the only allowed value — omitted is equivalent to false.
22781
+ * True is rejected so that secret values cannot accidentally land in settings. */
22782
+ secret: external_exports.literal(false).optional()
22783
+ });
22784
+ var AppSettingsSchema = external_exports.object({
22785
+ fields: external_exports.array(SettingsFieldSchema)
22786
+ });
22787
+ var PROMPT_NAME_REGEX = /^[a-z][a-z0-9]*([.\-/][a-z0-9]+)*$/;
22788
+ var PromptDefSchema = external_exports.object({
22789
+ name: external_exports.string().regex(
22790
+ PROMPT_NAME_REGEX,
22791
+ "prompt name must be lowercase segments separated by dots, hyphens, or slashes"
22792
+ ),
22793
+ template: external_exports.string(),
22794
+ labels: external_exports.array(external_exports.string()).optional()
22795
+ });
22717
22796
  var AppManifestSchema = external_exports.object({
22718
22797
  universalIdentifier: external_exports.string().uuid(),
22719
22798
  slug: external_exports.string().regex(/^[a-z][a-z0-9-]*$/),
@@ -22741,7 +22820,10 @@ var AppManifestSchema = external_exports.object({
22741
22820
  universalIdentifier: external_exports.string().uuid(),
22742
22821
  // objectKey allows letters, digits, hyphens, dots (e.g. 'shopify-order.v1', 'product').
22743
22822
  // Bars SQL-injection chars: no quotes, semicolons, spaces, or control chars.
22744
- objectKey: external_exports.string().regex(/^[a-zA-Z][a-zA-Z0-9._-]*$/, "objectKey must start with a letter and contain only letters, digits, hyphens, dots"),
22823
+ objectKey: external_exports.string().regex(
22824
+ /^[a-zA-Z][a-zA-Z0-9._-]*$/,
22825
+ "objectKey must start with a letter and contain only letters, digits, hyphens, dots"
22826
+ ),
22745
22827
  labelSingular: external_exports.string(),
22746
22828
  labelPlural: external_exports.string(),
22747
22829
  description: external_exports.string().optional(),
@@ -22777,7 +22859,23 @@ var AppManifestSchema = external_exports.object({
22777
22859
  targetRef: external_exports.string(),
22778
22860
  fields: external_exports.array(FieldDefSchema)
22779
22861
  })
22780
- ).optional()
22862
+ ).optional(),
22863
+ /** P7 — Per-app settings schema. Optional; manifests without this field still validate. */
22864
+ settings: AppSettingsSchema.optional(),
22865
+ /**
22866
+ * P3 — Managed prompt definitions seeded to Langfuse on app install/sync.
22867
+ * Each entry creates or versions a prompt in Langfuse under the given name.
22868
+ * Optional; absence is backward-compatible.
22869
+ */
22870
+ prompts: external_exports.array(PromptDefSchema).optional(),
22871
+ /**
22872
+ * P5 — Custom events this app is allowed to emit via ctx.api.events.send().
22873
+ * Each name must match the safe dotted-lowercase pattern and must not start
22874
+ * with a reserved prefix (app-, shopify., pipedrive., app-record.).
22875
+ * Functions declaring trigger: { type: 'event', name } must use a name that
22876
+ * is either in ALLOWED_INTEGRATION_EVENTS or in this emits array.
22877
+ */
22878
+ emits: external_exports.array(CustomEventNameSchema).optional()
22781
22879
  });
22782
22880
  var ShopifyOrderV1Schema = external_exports.object({
22783
22881
  id: external_exports.string(),
@@ -22803,9 +22901,7 @@ var shopifyOrderV1 = {
22803
22901
  schema: ShopifyOrderV1Schema,
22804
22902
  requiredRole: "VIEWER"
22805
22903
  };
22806
- var CORE_OBJECTS = /* @__PURE__ */ new Map([
22807
- [shopifyOrderV1.key, shopifyOrderV1]
22808
- ]);
22904
+ var CORE_OBJECTS = /* @__PURE__ */ new Map([[shopifyOrderV1.key, shopifyOrderV1]]);
22809
22905
 
22810
22906
  // src/manifest-build.ts
22811
22907
  var ManifestBuildError = class extends Error {
@@ -22891,7 +22987,7 @@ async function buildApp(projectRoot, tarball) {
22891
22987
  (0, import_fs4.writeFileSync)(checksumPath, checksum2, "utf8");
22892
22988
  const tgzFiles = {
22893
22989
  "manifest.json": stamped,
22894
- "checksum": checksum2
22990
+ checksum: checksum2
22895
22991
  };
22896
22992
  if (bundleBuffer) {
22897
22993
  tgzFiles["dist/index.js"] = bundleBuffer;
@@ -22903,13 +22999,33 @@ async function buildApp(projectRoot, tarball) {
22903
22999
  tarballPath = (0, import_path2.join)(outputDir, `${manifest.slug}-${manifest.version}.tgz`);
22904
23000
  (0, import_fs4.writeFileSync)(tarballPath, tgzContent);
22905
23001
  tarballChecksum = (0, import_crypto.createHash)("sha256").update(tgzContent).digest("hex");
22906
- return { manifest: stamped, outputDir, manifestPath, checksumPath, checksum: checksum2, tarballPath, tarballChecksum, hasBundle, uiPageCount };
23002
+ return {
23003
+ manifest: stamped,
23004
+ outputDir,
23005
+ manifestPath,
23006
+ checksumPath,
23007
+ checksum: checksum2,
23008
+ tarballPath,
23009
+ tarballChecksum,
23010
+ hasBundle,
23011
+ uiPageCount
23012
+ };
22907
23013
  }
22908
23014
  const serialized = JSON.stringify(manifest);
22909
23015
  const checksum = (0, import_crypto.createHash)("sha256").update(serialized).digest("hex");
22910
23016
  (0, import_fs4.writeFileSync)(manifestPath, JSON.stringify(manifest, null, 2), "utf8");
22911
23017
  (0, import_fs4.writeFileSync)(checksumPath, checksum, "utf8");
22912
- return { manifest, outputDir, manifestPath, checksumPath, checksum, tarballPath, tarballChecksum, hasBundle, uiPageCount };
23018
+ return {
23019
+ manifest,
23020
+ outputDir,
23021
+ manifestPath,
23022
+ checksumPath,
23023
+ checksum,
23024
+ tarballPath,
23025
+ tarballChecksum,
23026
+ hasBundle,
23027
+ uiPageCount
23028
+ };
22913
23029
  }
22914
23030
  async function compileBundleIfExists(projectRoot, outputDir) {
22915
23031
  const entryPoint = (0, import_path2.join)(projectRoot, "src", "index.ts");
@@ -22935,7 +23051,13 @@ async function compileBundleIfExists(projectRoot, outputDir) {
22935
23051
  async function compileUiPages(projectRoot, outputDir, pages) {
22936
23052
  const result = /* @__PURE__ */ new Map();
22937
23053
  if (pages.length === 0) return result;
22938
- const UI_EXTERNALS = ["react", "react-dom", "react-dom/client", "react/jsx-runtime", "@apotech-os/ui-sdk"];
23054
+ const UI_EXTERNALS = [
23055
+ "react",
23056
+ "react-dom",
23057
+ "react-dom/client",
23058
+ "react/jsx-runtime",
23059
+ "@apotech-os/ui-sdk"
23060
+ ];
22939
23061
  for (const page of pages) {
22940
23062
  const entryPoint = (0, import_path2.join)(projectRoot, "src", "ui", `${page.path}.tsx`);
22941
23063
  if (!(0, import_fs4.existsSync)(entryPoint)) continue;
@@ -23007,7 +23129,9 @@ function buildTarHeader(name, size) {
23007
23129
  Buffer.from("0000000\0").copy(header, 108);
23008
23130
  Buffer.from("0000000\0").copy(header, 116);
23009
23131
  Buffer.from(size.toString(8).padStart(11, "0") + " ").copy(header, 124);
23010
- Buffer.from(Math.floor(Date.now() / 1e3).toString(8).padStart(11, "0") + " ").copy(header, 136);
23132
+ Buffer.from(
23133
+ Math.floor(Date.now() / 1e3).toString(8).padStart(11, "0") + " "
23134
+ ).copy(header, 136);
23011
23135
  header[156] = 48;
23012
23136
  Buffer.from("ustar\0").copy(header, 257);
23013
23137
  Buffer.from("00").copy(header, 263);
@@ -23108,10 +23232,14 @@ function renderPlan(response) {
23108
23232
  const symbol2 = OP_SYMBOL[action.op];
23109
23233
  const label = OP_LABEL[action.op];
23110
23234
  const marker = action.destructive ? " [destructive]" : "";
23111
- lines.push(` ${symbol2} ${label} ${action.entityType} "${action.name}" (${action.universalIdentifier})${marker}`);
23235
+ lines.push(
23236
+ ` ${symbol2} ${label} ${action.entityType} "${action.name}" (${action.universalIdentifier})${marker}`
23237
+ );
23112
23238
  if (action.changes) {
23113
23239
  for (const change of action.changes) {
23114
- lines.push(` ${change.attribute}: ${JSON.stringify(change.from)} \u2192 ${JSON.stringify(change.to)}`);
23240
+ lines.push(
23241
+ ` ${change.attribute}: ${JSON.stringify(change.from)} \u2192 ${JSON.stringify(change.to)}`
23242
+ );
23115
23243
  }
23116
23244
  }
23117
23245
  }
@@ -23150,7 +23278,9 @@ function listRemotes() {
23150
23278
  function storeApiKey(remoteName, key) {
23151
23279
  const data = readFile();
23152
23280
  if (!data.remotes[remoteName]) {
23153
- throw new Error(`Remote "${remoteName}" not found. Add it first with: apotech-os remote add --url <url> --as ${remoteName}`);
23281
+ throw new Error(
23282
+ `Remote "${remoteName}" not found. Add it first with: apotech-os remote add --url <url> --as ${remoteName}`
23283
+ );
23154
23284
  }
23155
23285
  data.credentials[remoteName] = key;
23156
23286
  writeFile(data);
@@ -23159,7 +23289,9 @@ function getRemoteUrl(remoteName) {
23159
23289
  const data = readFile();
23160
23290
  const remote = data.remotes[remoteName];
23161
23291
  if (!remote) {
23162
- throw new Error(`Remote "${remoteName}" not found. Add it first with: apotech-os remote add --url <url> --as ${remoteName}`);
23292
+ throw new Error(
23293
+ `Remote "${remoteName}" not found. Add it first with: apotech-os remote add --url <url> --as ${remoteName}`
23294
+ );
23163
23295
  }
23164
23296
  return remote.url;
23165
23297
  }
@@ -23220,7 +23352,9 @@ function buildDevCommand() {
23220
23352
  console.log(renderPlan(response));
23221
23353
  }
23222
23354
  if (response.applied) {
23223
- console.log(`[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] Synced (${response.summary.toAdd}+${response.summary.toChange}~${response.summary.toDestroy}-)`);
23355
+ console.log(
23356
+ `[${(/* @__PURE__ */ new Date()).toLocaleTimeString()}] Synced (${response.summary.toAdd}+${response.summary.toChange}~${response.summary.toDestroy}-)`
23357
+ );
23224
23358
  }
23225
23359
  await tryDevReload(projectRoot, baseUrl, apiKey, manifest.slug);
23226
23360
  } catch (err) {
@@ -23239,13 +23373,18 @@ function buildDevCommand() {
23239
23373
  } catch {
23240
23374
  return;
23241
23375
  }
23242
- if (!buildOutput.tarballPath || !buildOutput.tarballChecksum || !buildOutput.hasBundle) return;
23376
+ if (!buildOutput.tarballPath || !buildOutput.tarballChecksum || !buildOutput.hasBundle)
23377
+ return;
23243
23378
  const tarball = (0, import_fs6.readFileSync)(buildOutput.tarballPath);
23244
23379
  const checksum = (0, import_crypto2.createHash)("sha256").update(tarball).digest("hex");
23245
23380
  const url2 = `${serverUrl.replace(/\/$/, "")}/platform/apps/${encodeURIComponent(slug)}/dev-reload`;
23246
23381
  const form = new FormData();
23247
23382
  form.append("metadata", JSON.stringify({ slug, version: "dev", checksum }));
23248
- form.append("artifact", new Blob([tarball], { type: "application/gzip" }), `${slug}-dev.tgz`);
23383
+ form.append(
23384
+ "artifact",
23385
+ new Blob([tarball], { type: "application/gzip" }),
23386
+ `${slug}-dev.tgz`
23387
+ );
23249
23388
  const headers = {};
23250
23389
  if (key) headers["Authorization"] = `Bearer ${key}`;
23251
23390
  try {
@@ -23295,15 +23434,19 @@ function buildDevCommand() {
23295
23434
 
23296
23435
  // src/commands/plan.ts
23297
23436
  function buildPlanCommand() {
23298
- return new Command("plan").description("Compute a diff plan (zero writes)").option("--remote <name>", "Named remote server to target").action(async (opts) => {
23437
+ return new Command("plan").description("Compute a diff plan (zero writes)").option("--remote <name>", "Named remote server to target").option("--json", "Output JSON instead of human-readable text").action(async (opts) => {
23299
23438
  const projectRoot = process.cwd();
23300
23439
  let manifest;
23301
23440
  try {
23302
23441
  manifest = await buildManifest(projectRoot);
23303
23442
  } catch (err) {
23304
23443
  if (err instanceof ManifestBuildError) {
23305
- console.error(`[MANIFEST_BUILD_FAILED] ${err.message}`);
23306
- console.error(err.diagnostic);
23444
+ if (opts.json) {
23445
+ console.log(JSON.stringify({ ok: false, error: err.code, diagnostic: err.diagnostic }));
23446
+ } else {
23447
+ console.error(`[MANIFEST_BUILD_FAILED] ${err.message}`);
23448
+ console.error(err.diagnostic);
23449
+ }
23307
23450
  process.exit(1);
23308
23451
  }
23309
23452
  throw err;
@@ -23312,10 +23455,18 @@ function buildPlanCommand() {
23312
23455
  const apiKey = resolveApiKey(opts.remote);
23313
23456
  try {
23314
23457
  const response = await syncManifest({ baseUrl, apiKey, manifest, mode: "plan" });
23315
- console.log(renderPlan(response));
23458
+ if (opts.json) {
23459
+ console.log(JSON.stringify(response));
23460
+ } else {
23461
+ console.log(renderPlan(response));
23462
+ }
23316
23463
  } catch (err) {
23317
23464
  if (err instanceof ApiError) {
23318
- console.error(`Server error (${err.status}): ${err.message}`);
23465
+ if (opts.json) {
23466
+ console.log(JSON.stringify({ ok: false, status: err.status, error: err.message }));
23467
+ } else {
23468
+ console.error(`Server error (${err.status}): ${err.message}`);
23469
+ }
23319
23470
  process.exit(1);
23320
23471
  }
23321
23472
  throw err;
@@ -23528,7 +23679,9 @@ function buildPublishCommand() {
23528
23679
  } catch (err) {
23529
23680
  if (err instanceof ApiError) {
23530
23681
  if (opts.json) {
23531
- console.log(JSON.stringify({ error: String(err.status), message: err.message, body: err.body }));
23682
+ console.log(
23683
+ JSON.stringify({ error: String(err.status), message: err.message, body: err.body })
23684
+ );
23532
23685
  } else {
23533
23686
  console.error(`Server error (${err.status}): ${err.message}`);
23534
23687
  }