@rise-x/apps-sdk 0.11.1 → 0.15.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 (83) hide show
  1. package/README.md +903 -19
  2. package/build/_internal.d.ts +4 -1
  3. package/build/_internal.js +67 -0
  4. package/build/cli/index.d.ts +7 -1
  5. package/build/cli/index.js +68 -14
  6. package/build/cli/scan.d.ts +60 -0
  7. package/build/cli/scan.js +725 -0
  8. package/build/cli/validate.d.ts +33 -0
  9. package/build/cli/validate.js +169 -0
  10. package/build/connectors/agents.d.ts +10 -6
  11. package/build/connectors/agents.js +59 -44
  12. package/build/connectors/attachments.d.ts +51 -0
  13. package/build/connectors/attachments.js +76 -0
  14. package/build/connectors/errors.js +24 -0
  15. package/build/connectors/flows.d.ts +13 -2
  16. package/build/connectors/flows.js +64 -19
  17. package/build/connectors/index.d.ts +5 -1
  18. package/build/connectors/index.js +14 -2
  19. package/build/connectors/integrations.d.ts +29 -0
  20. package/build/connectors/integrations.js +32 -0
  21. package/build/connectors/offline.d.ts +34 -0
  22. package/build/connectors/offline.js +135 -0
  23. package/build/connectors/readPolicy.d.ts +29 -0
  24. package/build/connectors/readPolicy.js +105 -0
  25. package/build/connectors/types.d.ts +75 -0
  26. package/build/connectors/types.js +128 -0
  27. package/build/connectors/vectorStores.d.ts +45 -0
  28. package/build/connectors/vectorStores.js +199 -0
  29. package/build/connectors/work.d.ts +14 -2
  30. package/build/connectors/work.js +43 -19
  31. package/build/dependencies/bound.d.ts +87 -0
  32. package/build/dependencies/bound.js +207 -0
  33. package/build/dependencies/index.d.ts +2 -0
  34. package/build/dependencies/index.js +13 -0
  35. package/build/dependencyRegistry.d.ts +15 -0
  36. package/build/dependencyRegistry.js +28 -0
  37. package/build/index.d.ts +2 -1
  38. package/build/index.js +12 -1
  39. package/build/lifecycle.d.ts +10 -1
  40. package/build/manifest.d.ts +69 -0
  41. package/build/manifest.js +229 -0
  42. package/build/manifestSource.d.ts +27 -0
  43. package/build/manifestSource.js +99 -0
  44. package/build/mockShell.d.ts +2 -0
  45. package/build/mockShell.js +13 -0
  46. package/build/query/client.js +9 -1
  47. package/build/query/dependencies.d.ts +22 -0
  48. package/build/query/dependencies.js +73 -0
  49. package/build/query/flows.d.ts +8 -8
  50. package/build/query/index.d.ts +1 -0
  51. package/build/query/index.js +4 -2
  52. package/build/query/layer.d.ts +9 -9
  53. package/build/query/shared.js +10 -0
  54. package/build/query/work.d.ts +4 -4
  55. package/build/rsbuild/index.d.ts +3 -1
  56. package/build/rsbuild/index.js +35 -1
  57. package/build/rsbuild/riseAppManifestPlugin.d.ts +19 -0
  58. package/build/rsbuild/riseAppManifestPlugin.js +79 -0
  59. package/build/shell/installShellBridge.d.ts +2 -0
  60. package/build/shell/installShellBridge.js +3 -1
  61. package/build/shellBridge.d.ts +233 -1
  62. package/build/shellBridge.js +8 -7
  63. package/build/ui/components/app-frame.d.ts +1 -1
  64. package/build/ui/demo.html +365 -360
  65. package/build/ui/shadcn.css +629 -0
  66. package/build/ui/standalone.js +16 -15
  67. package/build/ui/styles.css +1 -1
  68. package/build/ui/tailwind.css +12 -0
  69. package/build/ui/theme.css +412 -0
  70. package/build/ui/tw-animate.css +1 -0
  71. package/build/webpack/index.d.ts +1 -0
  72. package/build/webpack/index.js +7 -0
  73. package/build/webpack/riseAppManifestPlugin.d.ts +61 -0
  74. package/build/webpack/riseAppManifestPlugin.js +103 -0
  75. package/dependencies/package.json +8 -0
  76. package/package.json +17 -4
  77. package/template/AGENTS.md +34 -4
  78. package/template/README.md +85 -2
  79. package/template/package.json +4 -0
  80. package/template/rise-x-app.json +4 -0
  81. package/template/src/App.tsx +7 -17
  82. package/template/src/styles.css +5 -0
  83. package/webpack/package.json +8 -0
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+ // Runtime access to the app-dependency manifest (see ../manifest.ts).
3
+ //
4
+ // `rise-x-app.json` declares the Rise-X objects an app depends on; the build
5
+ // resolves it for ONE environment and injects the result into the bundle as a
6
+ // compile-time constant (read in ../dependencyRegistry.ts). This module turns
7
+ // that constant into the deps-first surface app code uses:
8
+ //
9
+ // const deps = useAppDependencies();
10
+ // deps.riskFlow.flowOriginId // the raw id, plus kind/label/description
11
+ // deps.riskFlow.work.list({ ... }) // work connector, pre-bound to that flow
12
+ // deps.vesselType.assets.list({ ... }) // assets connector, pre-bound to that type
13
+ // deps.triageAgent.agent.run({ ... }) // agents connector, pre-bound to that agent
14
+ // deps.crmLookup.integration.invoke({ ... }) // integrations connector, pre-bound to that endpoint
15
+ //
16
+ // Every bound method is a one-line delegation to the generic connectors with the
17
+ // ref pre-filled — the generic connectors stay first-class for everything else.
18
+ //
19
+ // The rule this exists to enforce: a GUID literal in app source belongs in
20
+ // rise-x-app.json.
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.bindAppDependencies = bindAppDependencies;
23
+ exports.getAppDependencies = getAppDependencies;
24
+ exports.tryGetAppDependencies = tryGetAppDependencies;
25
+ exports.getAppDependency = getAppDependency;
26
+ exports.useAppDependencies = useAppDependencies;
27
+ const agents_1 = require("../connectors/agents");
28
+ const errors_1 = require("../connectors/errors");
29
+ const assets_1 = require("../connectors/assets");
30
+ const flows_1 = require("../connectors/flows");
31
+ const integrations_1 = require("../connectors/integrations");
32
+ const work_1 = require("../connectors/work");
33
+ const dependencyRegistry_1 = require("../dependencyRegistry");
34
+ // Both v4 search endpoints 400 on a search that doesn't pin `flowOriginId`, and
35
+ // this dependency IS that pin. And-ed with the caller's filter, so a filter
36
+ // already pinned to the same id still works; one pinned to a different id
37
+ // matches nothing. Merged into a top-level `and` rather than nested inside a new
38
+ // one, because the server only takes groups 5 deep.
39
+ function pinFlowOriginId(flowOriginId, filter) {
40
+ const pin = {
41
+ field: "flowOriginId",
42
+ operator: "equals",
43
+ values: [flowOriginId],
44
+ };
45
+ if (!filter)
46
+ return pin;
47
+ return "and" in filter
48
+ ? { and: [pin, ...filter.and] }
49
+ : { and: [pin, filter] };
50
+ }
51
+ function bindFlow(dependency, connectors) {
52
+ const { flowOriginId } = dependency;
53
+ return {
54
+ ...dependency,
55
+ flow: {
56
+ get: (opts) => connectors.flows.get(flowOriginId, opts),
57
+ getConfig: (opts) => connectors.flows.getConfig(flowOriginId, opts),
58
+ },
59
+ work: {
60
+ start: (args) => connectors.work.start({ ...args, flowId: flowOriginId }),
61
+ list: (args) => connectors.work.list({ ...args, flow: flowOriginId }),
62
+ iterate: (args) => connectors.work.iterate({ ...args, flow: flowOriginId }),
63
+ search: (args) => connectors.work.search({
64
+ ...args,
65
+ filter: pinFlowOriginId(flowOriginId, args?.filter),
66
+ }),
67
+ },
68
+ };
69
+ }
70
+ function bindAssetType(dependency, connectors) {
71
+ const { flowOriginId } = dependency;
72
+ return {
73
+ ...dependency,
74
+ assets: {
75
+ list: (args) => connectors.assets.list({ ...args, type: flowOriginId }),
76
+ iterate: (args) => connectors.assets.iterate({ ...args, type: flowOriginId }),
77
+ search: (args) => connectors.assets.search({
78
+ ...args,
79
+ filter: pinFlowOriginId(flowOriginId, args?.filter),
80
+ }),
81
+ quickSearch: (args) => connectors.assets.quickSearch({ ...args, typeOriginId: flowOriginId }),
82
+ create: (args) => connectors.assets.create({ ...args, type: flowOriginId }),
83
+ },
84
+ };
85
+ }
86
+ function bindAgent(dependency, connectors) {
87
+ const { agentId } = dependency;
88
+ return {
89
+ ...dependency,
90
+ agent: {
91
+ get: (opts) => connectors.agents.get(agentId, opts),
92
+ run: (args) => connectors.agents.run({ ...args, agentId }),
93
+ createChat: (args) => connectors.agents.createChat({ ...args, agentId }),
94
+ listChats: (args) => connectors.agents.listChats({ ...args, agentId }),
95
+ },
96
+ };
97
+ }
98
+ function bindIntegration(dependency, connectors) {
99
+ const { integrationId, endpointId } = dependency;
100
+ return {
101
+ ...dependency,
102
+ integration: {
103
+ invoke: (args) => connectors.integrations.invoke({ ...args, integrationId, endpointId }),
104
+ },
105
+ };
106
+ }
107
+ // Exhaustive on purpose: a kind with no case here must fail loudly, because
108
+ // binding it to the nearest surface would pre-fill the wrong id into every call
109
+ // made through it.
110
+ function bindDependency(dependency, connectors) {
111
+ switch (dependency.kind) {
112
+ case "flow":
113
+ return bindFlow(dependency, connectors);
114
+ case "assetType":
115
+ return bindAssetType(dependency, connectors);
116
+ case "agent":
117
+ return bindAgent(dependency, connectors);
118
+ case "integration":
119
+ return bindIntegration(dependency, connectors);
120
+ default: {
121
+ const unbound = dependency;
122
+ throw new errors_1.ConnectorError("INVALID_ARG", `[@rise-x/apps-sdk] app dependency kind ${JSON.stringify(unbound.kind)} has no bound surface — update @rise-x/apps-sdk`);
123
+ }
124
+ }
125
+ }
126
+ // Connectors bound to the live shell bridge — what the accessors use.
127
+ const liveConnectors = {
128
+ flows: flows_1.flows,
129
+ work: work_1.work,
130
+ assets: assets_1.assets,
131
+ agents: agents_1.agents,
132
+ integrations: integrations_1.integrations,
133
+ };
134
+ /**
135
+ * Binds a resolved manifest to the connectors. Internal: the testing seam for
136
+ * the bound delegations, taking injected connectors. Kept off the /dependencies
137
+ * barrel; app code calls getAppDependencies().
138
+ */
139
+ function bindAppDependencies(manifest, connectors = {}) {
140
+ const resolved = { ...liveConnectors, ...connectors };
141
+ // fromEntries, not `bound[alias] = …`: defence in depth against an alias of
142
+ // "__proto__" hitting the inherited setter, even though resolveAppManifest's
143
+ // identifier rule already rejects it (same reason it collects into a Map).
144
+ return Object.fromEntries(Object.entries(manifest.dependencies).map(([alias, dependency]) => [
145
+ alias,
146
+ bindDependency(dependency, resolved),
147
+ ]));
148
+ }
149
+ // ---------------------------------------------------------------------------
150
+ // Accessors
151
+ // ---------------------------------------------------------------------------
152
+ // Keyed on manifest identity, which is also how a re-registration invalidates
153
+ // it: readManifest() hands back a different object.
154
+ let memo = null;
155
+ function missingManifest() {
156
+ return new errors_1.ConnectorError("INVALID_ARG", "[@rise-x/apps-sdk] no app dependency manifest is available. Declare the " +
157
+ "app's dependencies in rise-x-app.json and build through defineAppConfig " +
158
+ "from '@rise-x/apps-sdk/rsbuild' (or RiseAppManifestPlugin from " +
159
+ "'@rise-x/apps-sdk/webpack'); for standalone dev pass `dependencies` to " +
160
+ "createMockShell.");
161
+ }
162
+ /**
163
+ * Every dependency the app declared, bound to the connectors. Throws when no
164
+ * manifest is available. The returned map is stable across calls, so it is safe
165
+ * as a hook/effect dependency.
166
+ *
167
+ * Pass your app's alias map as `T` to get the aliases typed:
168
+ * `getAppDependencies<{ riskFlow: BoundFlowDependency }>()`.
169
+ */
170
+ function getAppDependencies() {
171
+ const manifest = (0, dependencyRegistry_1.readManifest)();
172
+ if (!manifest)
173
+ throw missingManifest();
174
+ if (!memo || memo.manifest !== manifest) {
175
+ memo = { manifest, map: bindAppDependencies(manifest) };
176
+ }
177
+ return memo.map;
178
+ }
179
+ // For optional work like cache warming, where a missing manifest should no-op
180
+ // rather than throw. Internal: /query's prefetch is the only intended caller.
181
+ function tryGetAppDependencies() {
182
+ return (0, dependencyRegistry_1.readManifest)() ? getAppDependencies() : null;
183
+ }
184
+ /** One declared dependency by alias. Throws, naming the known aliases, when it
185
+ * is not declared. */
186
+ function getAppDependency(alias) {
187
+ const all = getAppDependencies();
188
+ // hasOwnProperty, not a truthiness check on all[alias]: an alias of
189
+ // 'toString' or 'constructor' would otherwise resolve to Object.prototype's.
190
+ const declared = Object.prototype.hasOwnProperty.call(all, alias);
191
+ const dependency = declared ? all[alias] : undefined;
192
+ if (!dependency) {
193
+ const aliases = Object.keys(all);
194
+ throw new errors_1.ConnectorError("INVALID_ARG", `[@rise-x/apps-sdk] unknown app dependency '${alias}'. ${aliases.length
195
+ ? `Declared aliases: ${aliases.join(", ")}.`
196
+ : "rise-x-app.json declares no dependencies."}`);
197
+ }
198
+ return dependency;
199
+ }
200
+ /**
201
+ * Hook form of getAppDependencies(). The manifest is a build-time constant, so
202
+ * this holds no state and the result is referentially stable — it is a hook for
203
+ * call-site consistency with useShellUser/useShellEnvironment.
204
+ */
205
+ function useAppDependencies() {
206
+ return getAppDependencies();
207
+ }
@@ -0,0 +1,2 @@
1
+ export { registerAppDependencies } from "../dependencyRegistry";
2
+ export { getAppDependencies, getAppDependency, useAppDependencies, type AppDependency, type AppDependencyMap, type BoundAgentDependency, type BoundAgentSurface, type BoundAssetsSurface, type BoundAssetTypeDependency, type BoundFlowDependency, type BoundFlowSurface, type BoundIntegrationDependency, type BoundIntegrationSurface, type BoundWorkSurface, } from "./bound";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // The public surface of the /dependencies subpath, curated like ../query/index.ts:
3
+ // ./bound also holds the connector injection seam, which is not app API.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.useAppDependencies = exports.getAppDependency = exports.getAppDependencies = exports.registerAppDependencies = void 0;
6
+ // Re-exported so an app reaches everything dependency-related through this one
7
+ // subpath, even though the slot itself lives in a leaf module.
8
+ var dependencyRegistry_1 = require("../dependencyRegistry");
9
+ Object.defineProperty(exports, "registerAppDependencies", { enumerable: true, get: function () { return dependencyRegistry_1.registerAppDependencies; } });
10
+ var bound_1 = require("./bound");
11
+ Object.defineProperty(exports, "getAppDependencies", { enumerable: true, get: function () { return bound_1.getAppDependencies; } });
12
+ Object.defineProperty(exports, "getAppDependency", { enumerable: true, get: function () { return bound_1.getAppDependency; } });
13
+ Object.defineProperty(exports, "useAppDependencies", { enumerable: true, get: function () { return bound_1.useAppDependencies; } });
@@ -0,0 +1,15 @@
1
+ import type { ResolvedAppManifest } from "./manifest";
2
+ declare global {
3
+ var __RISE_APP_MANIFEST__: ResolvedAppManifest | undefined;
4
+ }
5
+ /**
6
+ * Supplies a resolved manifest at runtime, overriding whatever the build
7
+ * injected. For standalone dev (createMockShell's `dependencies` option calls
8
+ * this) and for tests that run outside a bundler. Pass null to clear.
9
+ *
10
+ * Do NOT assign to `globalThis.__RISE_APP_MANIFEST__` instead: inside a build
11
+ * that expression is a compile-time constant, so assigning to it is a syntax
12
+ * error.
13
+ */
14
+ export declare function registerAppDependencies(manifest: ResolvedAppManifest | null): void;
15
+ export declare function readManifest(): ResolvedAppManifest | null;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ // The app-dependency manifest slot: what the build injected, plus the runtime
3
+ // override createMockShell sets. A leaf on purpose: mockShell registers
4
+ // through it, and anything imported here would ride the root barrel into every
5
+ // app bundle. The bound surfaces live in ./dependencies.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.registerAppDependencies = registerAppDependencies;
8
+ exports.readManifest = readManifest;
9
+ // Read ONCE, at module init: under the plugin this is an inlined object literal,
10
+ // so re-reading it per call would hand out a new identity every time and defeat
11
+ // the binding memo in ./dependencies.
12
+ const INJECTED = globalThis.__RISE_APP_MANIFEST__ ?? null;
13
+ let registered = null;
14
+ /**
15
+ * Supplies a resolved manifest at runtime, overriding whatever the build
16
+ * injected. For standalone dev (createMockShell's `dependencies` option calls
17
+ * this) and for tests that run outside a bundler. Pass null to clear.
18
+ *
19
+ * Do NOT assign to `globalThis.__RISE_APP_MANIFEST__` instead: inside a build
20
+ * that expression is a compile-time constant, so assigning to it is a syntax
21
+ * error.
22
+ */
23
+ function registerAppDependencies(manifest) {
24
+ registered = manifest;
25
+ }
26
+ function readManifest() {
27
+ return registered ?? INJECTED;
28
+ }
package/build/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export * from "./shellBridge";
2
2
  export * from "./lifecycle";
3
3
  export { useShellUser, useShellEnvironment, useShellNavigate } from "./hooks";
4
4
  export { getShell, getShellAi, getShellApi, getShellApiV4, getShellEnvironment, getShellUser, } from "./accessors";
5
- export { createMockShell, type CreateMockShellOptions, type MockShellFixtures, } from "./mockShell";
5
+ export { createMockShell, isMockShell, type CreateMockShellOptions, type MockShellFixtures, } from "./mockShell";
6
6
  export { registerTopBarActions, type TopBarAction } from "./topBar";
7
+ export { APP_DEPENDENCY_KINDS, APP_MANIFEST_FILENAME, DEFAULT_APP_ENVIRONMENT, resolveAppManifest, type AgentAppDependencySource, type AgentEnvironmentIds, type AppDependencyKind, type AppDependencySource, type AppManifestSource, type AssetTypeAppDependencySource, type FlowAppDependencySource, type FlowOriginEnvironmentIds, type IntegrationAppDependencySource, type IntegrationEnvironmentIds, type ResolvedAgentDependency, type ResolvedAppDependency, type ResolvedAppManifest, type ResolvedAssetTypeDependency, type ResolvedFlowDependency, type ResolvedIntegrationDependency, } from "./manifest";
package/build/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.registerTopBarActions = exports.createMockShell = exports.getShellUser = exports.getShellEnvironment = exports.getShellApiV4 = exports.getShellApi = exports.getShellAi = exports.getShell = exports.useShellNavigate = exports.useShellEnvironment = exports.useShellUser = void 0;
17
+ exports.resolveAppManifest = exports.DEFAULT_APP_ENVIRONMENT = exports.APP_MANIFEST_FILENAME = exports.APP_DEPENDENCY_KINDS = exports.registerTopBarActions = exports.isMockShell = exports.createMockShell = exports.getShellUser = exports.getShellEnvironment = exports.getShellApiV4 = exports.getShellApi = exports.getShellAi = exports.getShell = exports.useShellNavigate = exports.useShellEnvironment = exports.useShellUser = void 0;
18
18
  __exportStar(require("./shellBridge"), exports);
19
19
  __exportStar(require("./lifecycle"), exports);
20
20
  var hooks_1 = require("./hooks");
@@ -30,5 +30,16 @@ Object.defineProperty(exports, "getShellEnvironment", { enumerable: true, get: f
30
30
  Object.defineProperty(exports, "getShellUser", { enumerable: true, get: function () { return accessors_1.getShellUser; } });
31
31
  var mockShell_1 = require("./mockShell");
32
32
  Object.defineProperty(exports, "createMockShell", { enumerable: true, get: function () { return mockShell_1.createMockShell; } });
33
+ Object.defineProperty(exports, "isMockShell", { enumerable: true, get: function () { return mockShell_1.isMockShell; } });
33
34
  var topBar_1 = require("./topBar");
34
35
  Object.defineProperty(exports, "registerTopBarActions", { enumerable: true, get: function () { return topBar_1.registerTopBarActions; } });
36
+ // The app-dependency RUNTIME (useAppDependencies and the bound surfaces) is
37
+ // deliberately absent from this barrel — it lives on the /dependencies subpath,
38
+ // because it binds the connector layer and that layer must not ride the root
39
+ // barrel into an app that only imports a shell hook. The manifest types below
40
+ // stay here: they are types and a validator, and pull in no connector.
41
+ var manifest_1 = require("./manifest");
42
+ Object.defineProperty(exports, "APP_DEPENDENCY_KINDS", { enumerable: true, get: function () { return manifest_1.APP_DEPENDENCY_KINDS; } });
43
+ Object.defineProperty(exports, "APP_MANIFEST_FILENAME", { enumerable: true, get: function () { return manifest_1.APP_MANIFEST_FILENAME; } });
44
+ Object.defineProperty(exports, "DEFAULT_APP_ENVIRONMENT", { enumerable: true, get: function () { return manifest_1.DEFAULT_APP_ENVIRONMENT; } });
45
+ Object.defineProperty(exports, "resolveAppManifest", { enumerable: true, get: function () { return manifest_1.resolveAppManifest; } });
@@ -1,4 +1,4 @@
1
- import type { ShellEnvironment, ShellUser } from './shellBridge';
1
+ import type { OfflineApi, ShellEnvironment, ShellUser } from './shellBridge';
2
2
  export declare const LIFECYCLE_MODULE_NAME = "./lifecycle";
3
3
  export interface AppManifestSnapshot {
4
4
  id: string;
@@ -10,14 +10,23 @@ export interface LifecycleContext {
10
10
  user: ShellUser | null;
11
11
  environment: ShellEnvironment | null;
12
12
  }
13
+ export interface OfflineDownloadTools {
14
+ offline: OfflineApi;
15
+ reportProgress: (progress: {
16
+ processed: number;
17
+ total: number;
18
+ }) => void;
19
+ }
13
20
  export type InstallHook = (ctx: LifecycleContext) => void | Promise<void>;
14
21
  export type UninstallHook = (ctx: LifecycleContext) => void | Promise<void>;
15
22
  export type UpdateHook = (ctx: LifecycleContext, change: {
16
23
  from: string;
17
24
  to: string;
18
25
  }) => void | Promise<void>;
26
+ export type OfflineDownloadHook = (ctx: LifecycleContext, tools: OfflineDownloadTools) => void | Promise<void>;
19
27
  export interface LifecycleModule {
20
28
  onInstall?: InstallHook;
21
29
  onUninstall?: UninstallHook;
22
30
  onUpdate?: UpdateHook;
31
+ onOfflineDownload?: OfflineDownloadHook;
23
32
  }
@@ -0,0 +1,69 @@
1
+ export declare const APP_MANIFEST_FILENAME = "rise-x-app.json";
2
+ export declare const DEFAULT_APP_ENVIRONMENT = "test";
3
+ export declare const APP_DEPENDENCY_KINDS: readonly ["flow", "assetType", "agent", "integration"];
4
+ export type AppDependencyKind = typeof APP_DEPENDENCY_KINDS[number];
5
+ export interface FlowOriginEnvironmentIds {
6
+ flowOriginId: string;
7
+ }
8
+ export interface AgentEnvironmentIds {
9
+ agentId: string;
10
+ }
11
+ export interface IntegrationEnvironmentIds {
12
+ integrationId: string;
13
+ endpointId: string;
14
+ }
15
+ interface AppDependencyMeta {
16
+ label?: string;
17
+ description?: string;
18
+ }
19
+ export interface FlowAppDependencySource extends AppDependencyMeta {
20
+ kind: "flow";
21
+ ids: Record<string, FlowOriginEnvironmentIds>;
22
+ }
23
+ export interface AssetTypeAppDependencySource extends AppDependencyMeta {
24
+ kind: "assetType";
25
+ ids: Record<string, FlowOriginEnvironmentIds>;
26
+ }
27
+ export interface AgentAppDependencySource extends AppDependencyMeta {
28
+ kind: "agent";
29
+ ids: Record<string, AgentEnvironmentIds>;
30
+ }
31
+ export interface IntegrationAppDependencySource extends AppDependencyMeta {
32
+ kind: "integration";
33
+ ids: Record<string, IntegrationEnvironmentIds>;
34
+ }
35
+ export type AppDependencySource = FlowAppDependencySource | AssetTypeAppDependencySource | AgentAppDependencySource | IntegrationAppDependencySource;
36
+ export interface AppManifestSource {
37
+ environments: string[];
38
+ dependencies: Record<string, AppDependencySource>;
39
+ }
40
+ export interface ResolvedFlowDependency extends AppDependencyMeta {
41
+ kind: "flow";
42
+ flowOriginId: string;
43
+ }
44
+ export interface ResolvedAssetTypeDependency extends AppDependencyMeta {
45
+ kind: "assetType";
46
+ flowOriginId: string;
47
+ }
48
+ export interface ResolvedAgentDependency extends AppDependencyMeta {
49
+ kind: "agent";
50
+ agentId: string;
51
+ }
52
+ export interface ResolvedIntegrationDependency extends AppDependencyMeta {
53
+ kind: "integration";
54
+ integrationId: string;
55
+ endpointId: string;
56
+ }
57
+ export type ResolvedAppDependency = ResolvedFlowDependency | ResolvedAssetTypeDependency | ResolvedAgentDependency | ResolvedIntegrationDependency;
58
+ export interface ResolvedAppManifest {
59
+ environment: string;
60
+ dependencies: Record<string, ResolvedAppDependency>;
61
+ }
62
+ /** Shared with the CLI: the same "is this a JSON object" question. */
63
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
64
+ /**
65
+ * Validates a parsed `rise-x-app.json` and collapses it to the single
66
+ * environment named by `environment`. Throws with every problem it found.
67
+ */
68
+ export declare function resolveAppManifest(source: unknown, environment: string): ResolvedAppManifest;
69
+ export {};
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ // The app-dependency manifest.
3
+ //
4
+ // An app project declares the Rise-X objects it depends on in a
5
+ // `rise-x-app.json` at its root, keyed by a stable alias and carrying one id
6
+ // per environment. At build time ONE environment is selected and a resolved,
7
+ // single-environment copy is emitted into the bundle — so a deployed zip can
8
+ // never carry another environment's ids.
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.APP_DEPENDENCY_KINDS = exports.DEFAULT_APP_ENVIRONMENT = exports.APP_MANIFEST_FILENAME = void 0;
11
+ exports.isRecord = isRecord;
12
+ exports.resolveAppManifest = resolveAppManifest;
13
+ exports.APP_MANIFEST_FILENAME = "rise-x-app.json";
14
+ // Used when neither the plugin options nor APP_ENV name an environment.
15
+ exports.DEFAULT_APP_ENVIRONMENT = "test";
16
+ // Authoring casing. The API reads these case-insensitively and serializes the
17
+ // enum back as Flow / AssetType / Agent / Integration, which is what the
18
+ // shells' types mirror.
19
+ exports.APP_DEPENDENCY_KINDS = [
20
+ "flow",
21
+ "assetType",
22
+ "agent",
23
+ "integration",
24
+ ];
25
+ // Deliberately version-agnostic: these ids are minted by the backend, and
26
+ // rejecting a valid id over a version nibble would be worse than accepting a
27
+ // non-v4 GUID.
28
+ const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
29
+ // The per-environment id field(s) each kind is addressed by, in declaration
30
+ // (and resolved-output) order. Every other kind takes exactly one; integration
31
+ // takes two, since the integration id alone does not name a callable endpoint.
32
+ const ID_FIELDS_BY_KIND = {
33
+ flow: ["flowOriginId"],
34
+ assetType: ["flowOriginId"],
35
+ agent: ["agentId"],
36
+ integration: ["integrationId", "endpointId"],
37
+ };
38
+ // Doubles as the allow-list: an id field belonging to another kind is a
39
+ // mismatch, not an extra to ignore.
40
+ const ID_FIELDS = [...new Set(Object.values(ID_FIELDS_BY_KIND).flat())];
41
+ // These limits mirror AppDependencyManifestReader on the deploy side. Anything
42
+ // it rejects has to fail the build too, or the mistake surfaces as a server-side
43
+ // deploy rejection long after the developer left the file.
44
+ const MAX_DEPENDENCIES = 100;
45
+ const MAX_LABEL_LENGTH = 200;
46
+ const MAX_DESCRIPTION_LENGTH = 1000;
47
+ // An environment name and an alias share one shape: 1-64 of these, starting
48
+ // with a letter or digit. Rendered straight into API responses, hence the
49
+ // allow-list rather than a blocklist.
50
+ const IDENTIFIER = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
51
+ // The reader's IsDisallowedCharacter: controls (Cc), formats (Cf), and the line
52
+ // and paragraph separators (Zl, Zp). A CR or LF in stored text could forge a
53
+ // line wherever an app response is later rendered as plain text.
54
+ const DISALLOWED_CHAR = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}]/u;
55
+ const IDENTIFIER_RULE = "must be 1-64 characters of letters, digits, '.', '-' or '_', starting with a letter or digit";
56
+ // Guid.TryParse accepts it, so the reader rejects it by name.
57
+ const GUID_EMPTY = "00000000-0000-0000-0000-000000000000";
58
+ /** Shared with the CLI: the same "is this a JSON object" question. */
59
+ function isRecord(value) {
60
+ return typeof value === "object" && value !== null && !Array.isArray(value);
61
+ }
62
+ function isStringArray(value) {
63
+ return Array.isArray(value) && value.every((v) => typeof v === "string");
64
+ }
65
+ function isAppDependencyKind(value) {
66
+ return exports.APP_DEPENDENCY_KINDS.includes(value);
67
+ }
68
+ // Mirrors the reader's ReadBoundedText: both fields are stored on the app and
69
+ // echoed into every app response, so they are capped and kept to one line.
70
+ function boundedText(alias, field, value, max) {
71
+ if (value === undefined)
72
+ return null;
73
+ if (value.length > max) {
74
+ return `"${alias}": "${field}" must be ${max} characters or fewer`;
75
+ }
76
+ if (DISALLOWED_CHAR.test(value)) {
77
+ return `"${alias}": "${field}" contains a control character`;
78
+ }
79
+ return null;
80
+ }
81
+ function fail(problems) {
82
+ throw new Error(`${exports.APP_MANIFEST_FILENAME} is invalid:\n` +
83
+ problems.map((problem) => ` - ${problem}`).join("\n"));
84
+ }
85
+ /**
86
+ * Validates a parsed `rise-x-app.json` and collapses it to the single
87
+ * environment named by `environment`. Throws with every problem it found.
88
+ */
89
+ function resolveAppManifest(source, environment) {
90
+ if (!isRecord(source)) {
91
+ fail(["expected a JSON object at the top level"]);
92
+ }
93
+ const environments = source.environments;
94
+ if (!isStringArray(environments) || environments.length === 0) {
95
+ fail(['"environments" must be a non-empty array of environment names']);
96
+ }
97
+ // A blank name falls through to the identifier rule below, which names it.
98
+ const badEnvironment = environments.find((name) => !IDENTIFIER.test(name));
99
+ if (badEnvironment !== undefined) {
100
+ fail([`environment ${JSON.stringify(badEnvironment)} ${IDENTIFIER_RULE}`]);
101
+ }
102
+ if (!environments.includes(environment)) {
103
+ fail([
104
+ `unknown environment "${environment}" — declared environments: ${environments.join(", ")}`,
105
+ ]);
106
+ }
107
+ // Absent means "declares nothing"; an explicit null is a malformed shape.
108
+ const dependencies = source.dependencies === undefined ? {} : source.dependencies;
109
+ if (!isRecord(dependencies)) {
110
+ fail(['"dependencies" must be a JSON object keyed by dependency alias']);
111
+ }
112
+ const entries = Object.entries(dependencies);
113
+ const problems = [];
114
+ // A Map, not an object literal: the identifier rule already rejects
115
+ // "__proto__", so this is defence in depth against an alias that would hit
116
+ // the inherited setter and drop the dependency silently.
117
+ const resolved = new Map();
118
+ // Case-insensitive, because the deploy side folds the alias keyspace that way:
119
+ // two aliases differing only by case become indistinguishable relationship
120
+ // edges on the app document, so it rejects them.
121
+ const seenAliases = new Set();
122
+ if (entries.length > MAX_DEPENDENCIES) {
123
+ problems.push(`"dependencies" declares ${entries.length} dependencies — ${MAX_DEPENDENCIES} is the supported maximum`);
124
+ }
125
+ for (const [alias, entry] of entries) {
126
+ if (alias.trim() === "") {
127
+ problems.push("a dependency alias is empty");
128
+ continue;
129
+ }
130
+ if (!IDENTIFIER.test(alias)) {
131
+ problems.push(`${JSON.stringify(alias)}: alias ${IDENTIFIER_RULE}`);
132
+ continue;
133
+ }
134
+ const aliasKey = alias.toLowerCase();
135
+ if (seenAliases.has(aliasKey)) {
136
+ problems.push(`"${alias}": alias is declared more than once — aliases are compared ignoring case`);
137
+ continue;
138
+ }
139
+ seenAliases.add(aliasKey);
140
+ if (!isRecord(entry)) {
141
+ problems.push(`"${alias}": must be a JSON object`);
142
+ continue;
143
+ }
144
+ const { kind, label, description, ids } = entry;
145
+ if (!isAppDependencyKind(kind)) {
146
+ problems.push(`"${alias}": "kind" must be one of ${exports.APP_DEPENDENCY_KINDS.join(" | ")} (got ${JSON.stringify(kind)})`);
147
+ continue;
148
+ }
149
+ if (label !== undefined && typeof label !== "string") {
150
+ problems.push(`"${alias}": "label" must be a string`);
151
+ continue;
152
+ }
153
+ if (description !== undefined && typeof description !== "string") {
154
+ problems.push(`"${alias}": "description" must be a string`);
155
+ continue;
156
+ }
157
+ const textProblem = boundedText(alias, "label", label, MAX_LABEL_LENGTH) ??
158
+ boundedText(alias, "description", description, MAX_DESCRIPTION_LENGTH);
159
+ if (textProblem) {
160
+ problems.push(textProblem);
161
+ continue;
162
+ }
163
+ if (!isRecord(ids)) {
164
+ problems.push(`"${alias}": "ids" must be a JSON object keyed by environment name`);
165
+ continue;
166
+ }
167
+ // A typo'd environment key would otherwise only surface as a missing id on
168
+ // the day that environment is built, so flag it on every build.
169
+ for (const name of Object.keys(ids)) {
170
+ if (!environments.includes(name)) {
171
+ problems.push(`"${alias}": "ids" names undeclared environment "${name}" — add it to "environments" or remove it`);
172
+ }
173
+ }
174
+ const envIds = ids[environment];
175
+ if (!isRecord(envIds)) {
176
+ problems.push(`"${alias}": no ids for environment "${environment}"`);
177
+ continue;
178
+ }
179
+ const idFields = ID_FIELDS_BY_KIND[kind];
180
+ // An agent given a flowOriginId (or a flow given an agentId) names an object
181
+ // the shell cannot address, so say which field(s) the kind takes rather than
182
+ // reporting the right one as merely missing.
183
+ const foreign = ID_FIELDS.find((field) => !idFields.includes(field) && field in envIds);
184
+ if (foreign) {
185
+ const wanted = idFields.map((field) => `"${field}"`).join(" and ");
186
+ problems.push(`"${alias}": "${foreign}" is not valid for kind "${kind}" — environment "${environment}" must supply ${wanted}`);
187
+ continue;
188
+ }
189
+ // Collected together (not one-problem-and-stop) so a dependency missing
190
+ // both of a multi-field kind's ids is reported in one pass, not one build
191
+ // per missing field.
192
+ const ids2 = {};
193
+ let hasIdProblem = false;
194
+ for (const field of idFields) {
195
+ const id = envIds[field];
196
+ if (typeof id !== "string" || !GUID.test(id)) {
197
+ problems.push(`"${alias}": "${field}" for environment "${environment}" must be a GUID (got ${JSON.stringify(id)})`);
198
+ hasIdProblem = true;
199
+ continue;
200
+ }
201
+ if (id.toLowerCase() === GUID_EMPTY) {
202
+ problems.push(`"${alias}": "${field}" for environment "${environment}" is the empty GUID`);
203
+ hasIdProblem = true;
204
+ continue;
205
+ }
206
+ ids2[field] = id;
207
+ }
208
+ if (hasIdProblem)
209
+ continue;
210
+ // Key order mirrors the documented resolved shape — the emitted file is
211
+ // read by humans as well as the backend — with the id field(s) last, in
212
+ // ID_FIELDS_BY_KIND's declared order.
213
+ const meta = {
214
+ ...(label !== undefined ? { label } : {}),
215
+ ...(description !== undefined ? { description } : {}),
216
+ };
217
+ // Cast: the fields collected are exactly the kind's own ID_FIELDS_BY_KIND
218
+ // entry (validated above), which is what makes this a ResolvedAppDependency
219
+ // of the matching kind — TS cannot see that from a dynamically-built object.
220
+ resolved.set(alias, {
221
+ kind,
222
+ ...meta,
223
+ ...ids2,
224
+ });
225
+ }
226
+ if (problems.length > 0)
227
+ fail(problems);
228
+ return { environment, dependencies: Object.fromEntries(resolved) };
229
+ }
@@ -0,0 +1,27 @@
1
+ import { type ResolvedAppManifest } from "./manifest";
2
+ export declare const MANIFEST_GLOBAL_EXPRESSION = "globalThis.__RISE_APP_MANIFEST__";
3
+ export declare function appManifestPath(context: string): string;
4
+ /**
5
+ * The environment to resolve for: an explicit value, else APP_ENV, else the
6
+ * default.
7
+ */
8
+ export declare function targetAppEnvironment(explicit?: string): string;
9
+ /**
10
+ * The parsed, unvalidated `rise-x-app.json`, or null when the app declares none.
11
+ * Wrapped, because a file holding the literal `null` is a manifest that has to
12
+ * fail validation, not an absent one.
13
+ *
14
+ * Validating against more than one environment works from the source rather than
15
+ * a resolved copy, so this reads and parses the file once.
16
+ */
17
+ export declare function readAppManifestSource(sourcePath: string): {
18
+ source: unknown;
19
+ } | null;
20
+ /**
21
+ * Null when the app declares no manifest; throws the resolver's error when it
22
+ * declares an invalid one.
23
+ */
24
+ export declare function readResolvedAppManifest(sourcePath: string, environment: string): ResolvedAppManifest | null;
25
+ /** The bytes emitted as `dist/rise-x-app.json` — read by the backend, and by
26
+ * humans reading a deployed zip. */
27
+ export declare function formatResolvedAppManifest(resolved: ResolvedAppManifest): string;