@apotech-os/cli 0.7.0 → 0.9.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
@@ -22608,14 +22608,6 @@ var FieldType = /* @__PURE__ */ ((FieldType2) => {
22608
22608
  return FieldType2;
22609
22609
  })(FieldType || {});
22610
22610
  var AppVariableTypeSchema = external_exports.enum(["STRING", "NUMBER", "BOOLEAN", "JSON"]);
22611
- var ApplicationVariableSchema = external_exports.object({
22612
- universalIdentifier: external_exports.string().uuid(),
22613
- name: external_exports.string(),
22614
- description: external_exports.string().optional(),
22615
- type: AppVariableTypeSchema,
22616
- value: external_exports.unknown(),
22617
- isSecret: external_exports.boolean().optional()
22618
- });
22619
22611
  var ServerVariableSchema = external_exports.object({
22620
22612
  universalIdentifier: external_exports.string().uuid(),
22621
22613
  name: external_exports.string(),
@@ -22623,10 +22615,6 @@ var ServerVariableSchema = external_exports.object({
22623
22615
  type: AppVariableTypeSchema,
22624
22616
  isRequired: external_exports.boolean().optional()
22625
22617
  });
22626
- var AppHooksSchema = external_exports.object({
22627
- preInstall: external_exports.string().optional(),
22628
- postInstall: external_exports.string().optional()
22629
- });
22630
22618
  var RelationDefSchema = external_exports.object({
22631
22619
  targetRef: external_exports.string(),
22632
22620
  relationType: external_exports.literal("MANY_TO_ONE"),
@@ -22647,13 +22635,22 @@ var FieldDefSchema = external_exports.object({
22647
22635
  options: external_exports.array(external_exports.string()).optional(),
22648
22636
  relation: RelationDefSchema.optional()
22649
22637
  });
22650
- var IndexDefSchema = external_exports.object({
22638
+ var IndexDefFieldsSchema = external_exports.object({
22651
22639
  universalIdentifier: external_exports.string(),
22652
22640
  // Field names in indexes are subject to the same identifier constraint as FieldDef.name.
22653
22641
  fields: external_exports.array(external_exports.string().regex(FIELD_NAME_REGEX, "index field name must be a valid identifier")).min(1),
22654
22642
  isUnique: external_exports.boolean().optional(),
22655
22643
  aggregateIndex: external_exports.boolean().optional()
22656
22644
  });
22645
+ var IndexDefSchema = IndexDefFieldsSchema.superRefine((index, ctx) => {
22646
+ if (index.isUnique && index.aggregateIndex) {
22647
+ ctx.addIssue({
22648
+ code: "custom",
22649
+ path: ["aggregateIndex"],
22650
+ message: "isUnique and aggregateIndex are mutually exclusive on the same IndexDef"
22651
+ });
22652
+ }
22653
+ });
22657
22654
  var VIEW_FILTER_OPS = [
22658
22655
  "eq",
22659
22656
  "neq",
@@ -22684,11 +22681,15 @@ var ViewDefSchema = external_exports.object({
22684
22681
  sorts: external_exports.array(ViewSortSchema).optional(),
22685
22682
  isDefault: external_exports.boolean().optional()
22686
22683
  });
22684
+ var MAX_FUNCTION_RETRIES = 20;
22687
22685
  var RESERVED_EVENT_PREFIXES = [
22688
22686
  "app-",
22689
22687
  "app.",
22690
22688
  "shopify.",
22691
22689
  "pipedrive.",
22690
+ "klaviyo.",
22691
+ "gorgias.",
22692
+ "platform.",
22692
22693
  "app-record."
22693
22694
  ];
22694
22695
  var CUSTOM_EVENT_NAME_REGEX = /^[a-z][a-z0-9]*([.-][a-z0-9]+)*$/;
@@ -22713,7 +22714,16 @@ var FunctionTriggerSchema = external_exports.discriminatedUnion("type", [
22713
22714
  type: external_exports.literal("httpRoute"),
22714
22715
  path: external_exports.string(),
22715
22716
  method: external_exports.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "ALL"]),
22716
- isAuthRequired: external_exports.boolean().optional()
22717
+ isAuthRequired: external_exports.boolean().optional(),
22718
+ /**
22719
+ * Minimum role the calling session must hold on this app
22720
+ * (contextId = manifest.slug). Defaults to EDITOR — fail-closed, like
22721
+ * `uiInvoke` and for the same reason: the handler runs with the app's FULL
22722
+ * manifest role, not the caller's.
22723
+ * Illegal with `isAuthRequired: false` (webhook mode: there is no session,
22724
+ * the HMAC governs) — rejected by the refinement on FunctionDefSchema.
22725
+ */
22726
+ minRole: external_exports.enum(["VIEWER", "EDITOR", "ADMIN"]).optional()
22717
22727
  }),
22718
22728
  external_exports.object({
22719
22729
  type: external_exports.literal("event"),
@@ -22751,36 +22761,102 @@ var FunctionTriggerSchema = external_exports.discriminatedUnion("type", [
22751
22761
  */
22752
22762
  minRole: external_exports.enum(["VIEWER", "EDITOR", "ADMIN"]).optional(),
22753
22763
  /** Wall-clock budget in ms. Clamped server-side by APP_SYNC_INVOKE_MAX_MS. */
22754
- timeoutMs: external_exports.number().int().min(1e3).max(3e4).optional()
22764
+ timeoutMs: external_exports.number().int().min(1e3).max(3e4).optional(),
22765
+ /**
22766
+ * Bilateral consent (cross-app function calls) — the apps allowed to
22767
+ * invoke this function synchronously with their OWN app token, in
22768
+ * addition to `minRole`-gated human sessions. Entries are `app:<slug>`
22769
+ * for one named app, or the wildcard `'*'` for any installed app.
22770
+ *
22771
+ * Placed on the trigger (next to `minRole`) rather than on the
22772
+ * FunctionDef: both fields answer the same question — "who may reach
22773
+ * this uiInvoke handler" — for two different caller identities (a human
22774
+ * session vs. an app token), so they belong together.
22775
+ *
22776
+ * A caller's own manifest declaring `role.calls` grants it nothing by
22777
+ * itself — only this list does. See `isFunctionExposedTo` and the
22778
+ * consent check in `AppInvokeController`. Optional and additive: an
22779
+ * existing manifest without this field keeps parsing unchanged, and is
22780
+ * treated as exposing the function to no other app.
22781
+ */
22782
+ exposedToApps: external_exports.array(external_exports.string()).optional()
22755
22783
  })
22756
22784
  ]);
22757
- var FunctionDefSchema = external_exports.object({
22785
+ var FunctionDefFieldsSchema = external_exports.object({
22758
22786
  universalIdentifier: external_exports.string(),
22759
22787
  name: external_exports.string(),
22760
22788
  trigger: FunctionTriggerSchema,
22761
22789
  /**
22762
- * P9 — Maximum retry attempts for this function (0 = no retries, fail immediately).
22763
- * Capped by the shared router's maximum (currently 4). When absent the router
22764
- * default of 4 applies.
22790
+ * Maximum retry attempts for this function (0 = no retries, fail immediately).
22791
+ *
22792
+ * NOT capped at PARSING time on purpose: AppManifestSchema is re-parsed against
22793
+ * manifests already persisted in the DB, so a `.max()` here would break boot for
22794
+ * an app published before the ceiling existed. The rule lives in
22795
+ * `checkManifestSemantics` (authoring / publish) plus a defensive clamp when the
22796
+ * Inngest function is built.
22765
22797
  */
22766
- retries: external_exports.number().int().min(0).optional(),
22798
+ retries: external_exports.number().int().min(0).describe(
22799
+ `Retry attempts, 0..${MAX_FUNCTION_RETRIES} (0 = fail on the first error, absent = 4). Each app function runs as its own Inngest function, so this value is honoured natively; Inngest refuses more than ${MAX_FUNCTION_RETRIES}, so a higher value is rejected at publish time.`
22800
+ ).optional(),
22767
22801
  /**
22768
- * P9 — Best-effort concurrency hint for this function.
22769
- *
22770
- * NOTE — DOCUMENTED LIMITATION: Under the shared-router dispatch model the platform
22771
- * cannot attach a per-app-function Inngest concurrency limit because there is no
22772
- * per-app-function Inngest function. This value is stored in the manifest and
22773
- * validated, but is NOT enforced at the Inngest level. A warning is logged at app
22774
- * sync time so operators are aware. Enforcement would require migrating to
22775
- * per-function Inngest registrations, which is out of scope for P9.
22802
+ * Maximum number of concurrent runs of this function. Enforced by Inngest: each
22803
+ * app function is registered as its own Inngest function, which carries this
22804
+ * limit natively.
22776
22805
  */
22777
22806
  concurrency: external_exports.number().int().min(1).optional(),
22778
22807
  /**
22779
- * P9 — Name of an intra-app event or function to fire on terminal failure.
22780
- * Must be a name declared in manifest.emits OR the name of another function in
22781
- * the same app. Cross-manifest validation is enforced by AppSyncService.
22808
+ * Custom EVENT name emitted once when this function fails permanently.
22809
+ * See the `.describe()` below for the full contract.
22810
+ */
22811
+ onFailure: external_exports.string().describe(
22812
+ 'Custom EVENT name emitted once when this function fails permanently. Must be declared in manifest.emits AND be subscribed to by a function of the same app (trigger: { type: "event", name }). Payload: { appSlug, functionName, error }.'
22813
+ ).optional(),
22814
+ /**
22815
+ * Platform end-of-run notification. The platform opens an Inbox alert —
22816
+ * independently of `onFailure`, which stays the APPLICATION channel.
22817
+ * Default: alert on terminal failure / timeout / missing handler, not on success.
22818
+ */
22819
+ notify: external_exports.object({
22820
+ /** Default true. */
22821
+ onFailure: external_exports.boolean().optional(),
22822
+ /** Default false. */
22823
+ onSuccess: external_exports.boolean().optional(),
22824
+ /** Default 'critical' on failure. */
22825
+ severity: external_exports.enum(["info", "warning", "critical"]).optional()
22826
+ }).optional(),
22827
+ /**
22828
+ * Lot 4 — Optional input schema for the two triggers whose payload is caller-
22829
+ * controlled rather than platform-shaped: `uiInvoke` (a browser session) and
22830
+ * `httpRoute` (an external HTTP caller). Reuses the same `FieldDef` vocabulary
22831
+ * as `records[].fields` and `settings.fields` — a deliberate decision to keep
22832
+ * one field vocabulary across the whole contract instead of adding a second,
22833
+ * more expressive free-form JSON Schema surface (see spec "Décisions prises").
22834
+ *
22835
+ * Validated server-side with the existing `fieldDefsToZod` before the handler
22836
+ * runs; a violating payload is rejected `422 INVALID_INPUT` and the handler is
22837
+ * never invoked (apps/api/src/platform-data/app-input-validation.ts).
22838
+ *
22839
+ * Absent on `cron` / `dbEvent` / `event` triggers, whose payload is authored by
22840
+ * the platform, not the app — declaring an input schema there is always a
22841
+ * mistake and is rejected by the refinement below.
22782
22842
  */
22783
- onFailure: external_exports.string().optional()
22843
+ input: external_exports.array(FieldDefSchema).optional()
22844
+ });
22845
+ var FunctionDefSchema = FunctionDefFieldsSchema.superRefine((fn, ctx) => {
22846
+ if (fn.input && fn.trigger.type !== "uiInvoke" && fn.trigger.type !== "httpRoute") {
22847
+ ctx.addIssue({
22848
+ code: "custom",
22849
+ path: ["input"],
22850
+ message: `"input" is only allowed on uiInvoke and httpRoute triggers, not "${fn.trigger.type}"`
22851
+ });
22852
+ }
22853
+ if (fn.trigger.type === "httpRoute" && fn.trigger.isAuthRequired === false && fn.trigger.minRole !== void 0) {
22854
+ ctx.addIssue({
22855
+ code: "custom",
22856
+ path: ["trigger", "minRole"],
22857
+ message: '"minRole" is meaningless on an unauthenticated webhook route (isAuthRequired: false)'
22858
+ });
22859
+ }
22784
22860
  });
22785
22861
  var AppRoleSchema = external_exports.object({
22786
22862
  reads: external_exports.array(external_exports.string()),
@@ -22797,8 +22873,20 @@ var AppRoleSchema = external_exports.object({
22797
22873
  * Absence means the capability is denied (deny-by-default, backward-compatible).
22798
22874
  * P2 approvals will reuse this field.
22799
22875
  */
22800
- capabilities: external_exports.array(external_exports.string()).optional()
22876
+ capabilities: external_exports.array(external_exports.string()).optional(),
22877
+ /**
22878
+ * Cross-app function calls this app INTENDS to make, as `app:<slug>/<functionName>`
22879
+ * refs. Declaring a ref here grants nothing by itself — it only becomes a real
22880
+ * capability when the target function's `uiInvoke` trigger lists this app (or
22881
+ * `'*'`) in its own `exposedToApps`. Same asymmetry as `dbEvent` subscriptions
22882
+ * (P2-10): the caller's self-declaration is necessary but never sufficient.
22883
+ *
22884
+ * Unlike `reads`/`writes`, entries here are EXPECTED to name a foreign app —
22885
+ * `findForeignRoleRefs` does not (and must not) inspect this field.
22886
+ */
22887
+ calls: external_exports.array(external_exports.string()).optional()
22801
22888
  });
22889
+ var UI_ENTRY_REGEX = /^dist\/ui\/[A-Za-z0-9_-]+\.js$/;
22802
22890
  var PageDefSchema = external_exports.object({
22803
22891
  universalIdentifier: external_exports.string().uuid(),
22804
22892
  path: external_exports.string().regex(
@@ -22807,8 +22895,10 @@ var PageDefSchema = external_exports.object({
22807
22895
  ),
22808
22896
  title: external_exports.string(),
22809
22897
  icon: external_exports.string().optional(),
22810
- entry: external_exports.string()
22811
- // relative path inside the tarball, e.g. 'dist/ui/attribution.js'
22898
+ // Relative path inside the tarball, e.g. 'dist/ui/attribution.js'. The CLI
22899
+ // always emits 'dist/ui/<path>.js' for a page — see UI_ENTRY_REGEX above for
22900
+ // why only the shape (not the path/entry cross-check) is enforced here.
22901
+ entry: external_exports.string().regex(UI_ENTRY_REGEX, "page entry must be a 'dist/ui/<name>.js' path")
22812
22902
  });
22813
22903
  var SettingsFieldSchema = external_exports.object({
22814
22904
  key: external_exports.string().regex(/^[a-zA-Z][a-zA-Z0-9_]*$/, "settings key must be a valid identifier"),
@@ -22823,11 +22913,10 @@ var SettingsFieldSchema = external_exports.object({
22823
22913
  var AppSettingsSchema = external_exports.object({
22824
22914
  fields: external_exports.array(SettingsFieldSchema)
22825
22915
  });
22826
- var SETTINGS_ENTRY_REGEX = /^dist\/ui\/[A-Za-z0-9_-]+\.js$/;
22827
22916
  var SettingsPageSchema = external_exports.object({
22828
22917
  universalIdentifier: external_exports.string().uuid(),
22829
22918
  /** Relative path inside the tarball, e.g. 'dist/ui/settings.js'. */
22830
- entry: external_exports.string().regex(SETTINGS_ENTRY_REGEX, "settingsPage entry must be a 'dist/ui/<name>.js' path"),
22919
+ entry: external_exports.string().regex(UI_ENTRY_REGEX, "settingsPage entry must be a 'dist/ui/<name>.js' path"),
22831
22920
  /** Page heading; defaults to "Paramètres" in the shell. */
22832
22921
  title: external_exports.string().optional()
22833
22922
  });
@@ -22855,13 +22944,21 @@ var AppManifestFieldsSchema = external_exports.object({
22855
22944
  // true for spaces with no views yet
22856
22945
  reads: external_exports.array(external_exports.string()),
22857
22946
  // core objects read: ['order']
22858
- hooks: AppHooksSchema.optional(),
22859
- applicationVariables: external_exports.array(ApplicationVariableSchema).optional(),
22947
+ // 0.9.0 breaking change (D28): `hooks` (`preInstall`/`postInstall`) removed —
22948
+ // the feature was undocumented, declared by zero manifest in the repo, and
22949
+ // made install fail whenever it was used (HookRunnerService.run sent an event
22950
+ // no Inngest function ever subscribed to). Because this object is not
22951
+ // `.strict()`, a stored manifest that still carries `hooks` keeps parsing —
22952
+ // the key is simply ignored. No data migration, no pre-flight required.
22860
22953
  serverVariables: external_exports.array(ServerVariableSchema).optional(),
22861
22954
  pages: external_exports.array(PageDefSchema).optional(),
22862
22955
  // #71: React UI pages bundled in the artifact
22863
22956
  uiSdkVersion: external_exports.string().optional(),
22864
22957
  // #85: @apotech-os/ui-sdk version stamped by CLI at build time
22958
+ // UI contract number stamped by the CLI (from ui-sdk's package.json `uiContractVersion`).
22959
+ // Only bumped on breaking changes of the runtime API the shell provides to pages,
22960
+ // so lockstep npm releases don't invalidate installed apps.
22961
+ uiContractVersion: external_exports.number().int().min(1).optional(),
22865
22962
  records: external_exports.array(
22866
22963
  external_exports.object({
22867
22964
  universalIdentifier: external_exports.string().uuid(),
@@ -22877,14 +22974,29 @@ var AppManifestFieldsSchema = external_exports.object({
22877
22974
  icon: external_exports.string().optional(),
22878
22975
  coreRef: external_exports.string().optional(),
22879
22976
  fields: external_exports.array(FieldDefSchema),
22880
- indexes: external_exports.array(IndexDefSchema).max(10).optional()
22977
+ indexes: external_exports.array(IndexDefSchema).max(10).optional(),
22978
+ /**
22979
+ * P2-10 — bilateral consent for cross-app access to this object. ONE
22980
+ * meaning: "this app may observe and read this object" — it governs
22981
+ * every capability built on it, not just its original one:
22982
+ * - a `dbEvent` subscription, via a trigger whose `objectRef` names
22983
+ * it (`app:<this app's slug>/<objectKey>`);
22984
+ * - a direct cross-app record/aggregate READ with another app's
22985
+ * token (`PlatformDataAuthGuard`) — writes are never granted this
22986
+ * way, consent or not.
22987
+ * Entries are `app:<slug>` for one named app, or the wildcard `'*'`
22988
+ * for any installed app.
22989
+ *
22990
+ * A caller's own manifest or request naming this object grants it
22991
+ * nothing by itself — only this list does. See `isObjectExposedTo`.
22992
+ *
22993
+ * Optional and additive: an existing manifest without this field keeps
22994
+ * parsing unchanged, and is treated as exposing the object to no one.
22995
+ */
22996
+ exposedToApps: external_exports.array(external_exports.string()).optional()
22881
22997
  })
22882
22998
  ),
22883
- /** @deprecated Use `records[]` instead — issue #73 migrated all apps to AppRecord. */
22884
- ownsTables: external_exports.array(external_exports.string()).optional(),
22885
22999
  actions: external_exports.array(external_exports.object({ provider: external_exports.string(), action: external_exports.string() })),
22886
- jobs: external_exports.array(external_exports.string()).default([]),
22887
- // deprecated — use functions instead
22888
23000
  functions: external_exports.array(FunctionDefSchema).optional(),
22889
23001
  // Phase 6: typed function declarations
22890
23002
  views: external_exports.array(ViewDefSchema).optional(),
@@ -22975,12 +23087,27 @@ var CoreOrderSchema = external_exports.object({
22975
23087
  });
22976
23088
  var coreOrder = {
22977
23089
  key: "order",
22978
- prismaModel: "AppRecord",
22979
- appRecord: { appSlug: "_core", objectKey: "shopify-order" },
22980
23090
  schema: CoreOrderSchema,
22981
23091
  requiredRole: "VIEWER"
22982
23092
  };
22983
23093
  var CORE_OBJECTS = /* @__PURE__ */ new Map([[coreOrder.key, coreOrder]]);
23094
+ function checkManifestSemantics(manifest) {
23095
+ const errors = [];
23096
+ const emits = manifest.emits ?? [];
23097
+ for (const fn of manifest.functions ?? []) {
23098
+ if (fn.retries !== void 0 && fn.retries > MAX_FUNCTION_RETRIES) {
23099
+ errors.push(
23100
+ `functions."${fn.name}".retries: ${fn.retries} exceeds the platform maximum of ${MAX_FUNCTION_RETRIES}. Inngest refuses a function configured above ${MAX_FUNCTION_RETRIES} retries, so this app's functions would fail to register.`
23101
+ );
23102
+ }
23103
+ if (fn.onFailure !== void 0 && !emits.includes(fn.onFailure)) {
23104
+ errors.push(
23105
+ `functions."${fn.name}".onFailure: "${fn.onFailure}" is not declared in manifest.emits. onFailure travels on the app custom-event bus; naming an integration or platform event would re-invoke that handler with a failure payload.`
23106
+ );
23107
+ }
23108
+ }
23109
+ return errors;
23110
+ }
22984
23111
 
22985
23112
  // src/manifest-build.ts
22986
23113
  var ManifestBuildError = class extends Error {
@@ -23028,6 +23155,13 @@ Ensure the file exists and exports a default AppManifest.`
23028
23155
  const diagnostic = parsed.error.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n");
23029
23156
  throw new ManifestBuildError("Manifest validation failed", diagnostic);
23030
23157
  }
23158
+ const semanticErrors = checkManifestSemantics(parsed.data);
23159
+ if (semanticErrors.length > 0) {
23160
+ throw new ManifestBuildError(
23161
+ "Manifest validation failed",
23162
+ semanticErrors.map((e) => ` ${e}`).join("\n")
23163
+ );
23164
+ }
23031
23165
  return parsed.data;
23032
23166
  } catch (err) {
23033
23167
  if (err instanceof ManifestBuildError) throw err;
@@ -23065,8 +23199,7 @@ async function buildApp(projectRoot, tarball) {
23065
23199
  (0, import_fs4.writeFileSync)(manifestPath, JSON.stringify(stamped, null, 2), "utf8");
23066
23200
  (0, import_fs4.writeFileSync)(checksumPath, checksum2, "utf8");
23067
23201
  const tgzFiles = {
23068
- "manifest.json": stamped,
23069
- checksum: checksum2
23202
+ "manifest.json": stamped
23070
23203
  };
23071
23204
  if (bundleBuffer) {
23072
23205
  tgzFiles["dist/index.js"] = bundleBuffer;
@@ -23197,7 +23330,11 @@ function stampUiSdkVersion(manifest, projectRoot, hasUiBundles) {
23197
23330
  try {
23198
23331
  const pkg = JSON.parse((0, import_fs4.readFileSync)(candidate, "utf8"));
23199
23332
  if (pkg.version) {
23200
- return { ...manifest, uiSdkVersion: pkg.version };
23333
+ return {
23334
+ ...manifest,
23335
+ uiSdkVersion: pkg.version,
23336
+ ...Number.isInteger(pkg.uiContractVersion) ? { uiContractVersion: pkg.uiContractVersion } : {}
23337
+ };
23201
23338
  }
23202
23339
  } catch {
23203
23340
  }