@uru-intelligence/app 1.0.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.
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Every type this package publishes.
3
+ *
4
+ * Declarations only — no runtime code. This module exists so the wire layer
5
+ * (`transport.ts`), the Dataset layer (`datasets.ts`) and the public barrel
6
+ * (`index.ts`) can all name the same shapes without any of them importing
7
+ * another. Before this split, `transport.ts` and `datasets.ts` imported from
8
+ * `./index`, and the cycle was paid for by exporting four internal helpers from
9
+ * the barrel. Publishing turns barrel exports into permanent promises, so the
10
+ * cycle was broken instead of documented.
11
+ *
12
+ * The only edge out of this module is a type-only import of the damper options
13
+ * from `./dampers.js`, which imports nothing.
14
+ */
15
+ import type { UruRunawayDamperOptions } from './dampers.js';
16
+ /** The kinds of capability a Uru app can declare and this client can invoke. */
17
+ export type UruAppRuntimeCapabilityType = 'query' | 'action' | 'job' | 'endpoint' | 'server_function';
18
+ /**
19
+ * Normalized lifecycle state of one invocation.
20
+ *
21
+ * Widened to `| string` at every use site: the server owns this vocabulary and
22
+ * may add a state before this package knows about it, and a client that threw
23
+ * on an unrecognised state would break on a backend deploy.
24
+ */
25
+ export type UruAppRuntimeState = 'idle' | 'queued' | 'running' | 'polling' | 'cached' | 'stale' | 'refreshing' | 'refreshed' | 'succeeded' | 'failed' | 'rate_limited' | 'budget_blocked' | 'service_unavailable' | 'canceled';
26
+ /** Lifecycle transitions reported to `onEvent` / `onStatus`. */
27
+ export type UruAppRuntimeEventType = 'started' | 'status' | 'completed' | 'failed' | 'canceled';
28
+ /** One lifecycle notification for an in-flight invocation. */
29
+ export interface UruAppRuntimeEvent<TResult = unknown> {
30
+ type: UruAppRuntimeEventType;
31
+ state: UruAppRuntimeState | string;
32
+ deploymentId: string;
33
+ capabilityType?: UruAppRuntimeCapabilityType | string | undefined;
34
+ capabilityName?: string | undefined;
35
+ executionId?: string | null | undefined;
36
+ requestId?: string | null | undefined;
37
+ result?: TResult | null;
38
+ error?: string | null | undefined;
39
+ retryAfterSeconds?: number | null | undefined;
40
+ cacheStatus?: string | null | undefined;
41
+ diagnostics?: Record<string, unknown> | undefined;
42
+ }
43
+ /** Per-call options accepted by every capability method. */
44
+ export interface UruAppRuntimeInvocationOptions {
45
+ idempotencyKey?: string;
46
+ timeoutMs?: number;
47
+ forceRefresh?: boolean;
48
+ requestId?: string;
49
+ onEvent?: (event: UruAppRuntimeEvent) => void;
50
+ onStatus?: (event: UruAppRuntimeEvent) => void;
51
+ }
52
+ /** The normalized envelope every capability invocation resolves to. */
53
+ export interface UruAppRuntimeInvocationResponse<TResult = unknown> {
54
+ ok: boolean;
55
+ status: 'succeeded' | 'running' | 'failed' | string;
56
+ state: UruAppRuntimeState | string;
57
+ deploymentId: string;
58
+ capabilityType: UruAppRuntimeCapabilityType | string;
59
+ capabilityName: string;
60
+ result?: TResult | null;
61
+ executionId?: string | null;
62
+ pending: boolean;
63
+ diagnostics: Record<string, unknown>;
64
+ }
65
+ /** The normalized envelope a job-status poll resolves to. */
66
+ export interface UruAppRuntimeExecutionStatus<TResult = unknown> {
67
+ success?: boolean;
68
+ pending?: boolean;
69
+ result?: TResult | null;
70
+ error?: string | null;
71
+ state?: UruAppRuntimeState | string;
72
+ status?: string | null;
73
+ executionId?: string | null;
74
+ statusUrl?: string | null;
75
+ retryAfterSeconds?: number | null;
76
+ cacheStatus?: string | null;
77
+ executor?: string | null;
78
+ executorKind?: string | null;
79
+ }
80
+ /** The capability-invocation client returned by `createUruAppRuntimeClient`. */
81
+ export interface UruAppRuntimeClient {
82
+ query<TResult = unknown>(name: string, input?: Record<string, unknown>, options?: UruAppRuntimeInvocationOptions): Promise<UruAppRuntimeInvocationResponse<TResult>>;
83
+ action<TResult = unknown>(name: string, input?: Record<string, unknown>, options?: UruAppRuntimeInvocationOptions): Promise<UruAppRuntimeInvocationResponse<TResult>>;
84
+ job<TResult = unknown>(name: string, input?: Record<string, unknown>, options?: UruAppRuntimeInvocationOptions): Promise<UruAppRuntimeInvocationResponse<TResult>>;
85
+ endpoint<TResult = unknown>(name: string, input?: Record<string, unknown>, options?: UruAppRuntimeInvocationOptions): Promise<UruAppRuntimeInvocationResponse<TResult>>;
86
+ serverFunction<TResult = unknown>(name: string, input?: Record<string, unknown>, options?: UruAppRuntimeInvocationOptions): Promise<UruAppRuntimeInvocationResponse<TResult>>;
87
+ jobStatus<TResult = unknown>(executionId: string, options?: UruAppRuntimeInvocationOptions): Promise<UruAppRuntimeExecutionStatus<TResult>>;
88
+ cancelJob(executionId: string, options?: UruAppRuntimeInvocationOptions): Promise<UruAppRuntimeInvocationResponse>;
89
+ }
90
+ /** Comparison operators accepted by a Dataset `where` clause. */
91
+ export type UruDatasetWhereOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'ilike' | 'in' | 'nin' | 'is_null';
92
+ /** One server-side filter condition. */
93
+ export interface UruDatasetWhereClause {
94
+ field: string;
95
+ op: UruDatasetWhereOperator | string;
96
+ value?: unknown;
97
+ }
98
+ /** One server-side sort condition. */
99
+ export interface UruDatasetSortClause {
100
+ field: string;
101
+ direction: 'asc' | 'desc';
102
+ }
103
+ /**
104
+ * A server-side Dataset read.
105
+ *
106
+ * Filtering, sorting, pagination and aggregation are evaluated by the platform,
107
+ * not in the app: a view that computes a total from one fetched page reports a
108
+ * number that is wrong as soon as the Dataset outgrows that page.
109
+ */
110
+ export interface UruDatasetQuery {
111
+ limit?: number;
112
+ offset?: number;
113
+ includeTotal?: boolean;
114
+ includeDeleted?: boolean;
115
+ select?: readonly string[];
116
+ search?: string;
117
+ filter?: Record<string, unknown>;
118
+ where?: readonly UruDatasetWhereClause[];
119
+ sort?: readonly UruDatasetSortClause[];
120
+ aggregate?: Record<string, unknown>;
121
+ before?: string;
122
+ cursor?: string;
123
+ }
124
+ /** One page of Dataset rows, plus the total when `includeTotal` asked for it. */
125
+ export interface UruDatasetRowsResult<TRow extends Record<string, unknown> = Record<string, unknown>> {
126
+ rows: TRow[];
127
+ total?: number | null;
128
+ source_meta?: Record<string, unknown> | null;
129
+ }
130
+ /** One Dataset row. Column types are the Dataset's, so values stay `unknown`. */
131
+ export type UruDatasetRow = Record<string, unknown>;
132
+ /** The envelope every Dataset write resolves to. */
133
+ export interface UruDatasetMutationResult<TResult = unknown> {
134
+ ok: boolean;
135
+ operation: string;
136
+ deploymentId?: string;
137
+ datasetId?: string | null;
138
+ result: TResult;
139
+ diagnostics?: Record<string, unknown>;
140
+ }
141
+ /** Bounds and targets for a `datasets.sqlWrite` statement. */
142
+ export interface UruDatasetSqlWriteOptions {
143
+ /**
144
+ * The Datasets the statement may write. Each entry is either a Dataset id or
145
+ * a declared capability name; a UUID is always read as an id, never as a
146
+ * name. Every target must be granted to this deployment and manage-access
147
+ * gated for the binder. At most 100 unique entries.
148
+ */
149
+ datasetIds: readonly string[];
150
+ maxRows?: number;
151
+ maxAffected?: number;
152
+ timeoutMs?: number;
153
+ }
154
+ /** The Dataset read/write surface hung off a server context. */
155
+ export interface UruDatasetsContext {
156
+ queryRows: <TRow extends Record<string, unknown> = Record<string, unknown>>(datasetRef: string, query?: UruDatasetQuery) => Promise<UruDatasetRowsResult<TRow>>;
157
+ insertRows: <TResult = unknown>(datasetRef: string, rows: readonly UruDatasetRow[]) => Promise<UruDatasetMutationResult<TResult>>;
158
+ upsertRows: <TResult = unknown>(datasetRef: string, rows: readonly UruDatasetRow[]) => Promise<UruDatasetMutationResult<TResult>>;
159
+ deleteRows: <TResult = unknown>(datasetRef: string, rowIds: readonly string[]) => Promise<UruDatasetMutationResult<TResult>>;
160
+ restoreRows: <TResult = unknown>(datasetRef: string, rowIds: readonly string[]) => Promise<UruDatasetMutationResult<TResult>>;
161
+ sqlWrite: <TResult = unknown>(sql: string, options: UruDatasetSqlWriteOptions) => Promise<UruDatasetMutationResult<TResult>>;
162
+ }
163
+ /** Everything a Uru server runtime hands an app. */
164
+ export interface UruServerContext {
165
+ datasets: UruDatasetsContext;
166
+ app: UruAppRuntimeClient;
167
+ actions: {
168
+ run: <TResult = unknown>(name: string, input?: Record<string, unknown>, options?: UruAppRuntimeInvocationOptions) => Promise<TResult>;
169
+ };
170
+ jobs: {
171
+ start: <TResult = unknown>(name: string, input?: Record<string, unknown>, options?: UruAppRuntimeInvocationOptions) => Promise<UruAppRuntimeInvocationResponse<TResult>>;
172
+ };
173
+ secrets: {
174
+ has: (name: string) => boolean;
175
+ get: (name: string) => string;
176
+ };
177
+ }
178
+ /**
179
+ * The environment a Uru provider runtime injects.
180
+ *
181
+ * The three named bindings are required by `createUruServerContext`; the index
182
+ * signature is how an app's own declared secrets arrive alongside them.
183
+ */
184
+ export interface UruProviderRuntimeEnvironment {
185
+ [key: string]: string | undefined;
186
+ URU_DEPLOYMENT_ID?: string | undefined;
187
+ URU_RUNTIME_API_BASE?: string | undefined;
188
+ URU_RUNTIME_TOKEN?: string | undefined;
189
+ }
190
+ /** Options for `createUruServerContext`. */
191
+ export interface CreateUruServerContextOptions {
192
+ /** Override the `fetch` used for every call. Defaults to `globalThis.fetch`. */
193
+ fetch?: typeof fetch;
194
+ }
195
+ /** Options for `createUruAppRuntimeClient`. */
196
+ export interface CreateUruAppRuntimeClientOptions {
197
+ deploymentId: string;
198
+ baseUrl?: string;
199
+ runtimeBasePath?: string;
200
+ publicPageSlug?: string;
201
+ providerRuntime?: boolean;
202
+ fetch?: typeof fetch;
203
+ headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
204
+ /**
205
+ * Client-side runaway dampers (P2 cost-safety). Every field defaults; pass
206
+ * `{ defaultIdempotencyKeys: false }` to opt out of the auto idempotency key,
207
+ * or `{ maxRateLimitRetries: 0 }` to opt out of 429 backoff. See
208
+ * {@link UruRunawayDamperOptions}.
209
+ */
210
+ dampers?: UruRunawayDamperOptions;
211
+ }
package/dist/types.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Every type this package publishes.
3
+ *
4
+ * Declarations only — no runtime code. This module exists so the wire layer
5
+ * (`transport.ts`), the Dataset layer (`datasets.ts`) and the public barrel
6
+ * (`index.ts`) can all name the same shapes without any of them importing
7
+ * another. Before this split, `transport.ts` and `datasets.ts` imported from
8
+ * `./index`, and the cycle was paid for by exporting four internal helpers from
9
+ * the barrel. Publishing turns barrel exports into permanent promises, so the
10
+ * cycle was broken instead of documented.
11
+ *
12
+ * The only edge out of this module is a type-only import of the damper options
13
+ * from `./dampers.js`, which imports nothing.
14
+ */
15
+ export {};
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@uru-intelligence/app",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "description": "Runtime client for Uru Gems: capability calls, Datasets, jobs and secrets",
6
+ "keywords": [
7
+ "uru",
8
+ "gem",
9
+ "runtime",
10
+ "sdk"
11
+ ],
12
+ "license": "SEE LICENSE IN LICENSE",
13
+ "homepage": "https://github.com/Ignition-Forward/uru-workspace-platform/tree/development/packages/app#readme",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/Ignition-Forward/uru-workspace-platform.git",
17
+ "directory": "packages/app"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/Ignition-Forward/uru-workspace-platform/issues"
21
+ },
22
+ "type": "module",
23
+ "sideEffects": false,
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ },
29
+ "./package.json": "./package.json"
30
+ },
31
+ "main": "./dist/index.js",
32
+ "types": "./dist/index.d.ts",
33
+ "files": [
34
+ "dist",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.build.json",
40
+ "clean": "rm -rf dist",
41
+ "prepack": "bun run clean && bun run build",
42
+ "type-check": "tsc --noEmit",
43
+ "lint": "oxlint . --type-aware",
44
+ "lint:fix": "oxlint . --type-aware --fix",
45
+ "test": "bun test",
46
+ "test:unit": "bun test",
47
+ "check:package": "node ../../scripts/checks/check-app-package-publishable.mjs",
48
+ "check:node-floor": "node ../../scripts/checks/check-app-package-node-floor.mjs"
49
+ },
50
+ "packageManager": "bun@1.3.13",
51
+ "engines": {
52
+ "node": ">=22.12.0"
53
+ },
54
+ "devDependencies": {
55
+ "publint": "0.3.24",
56
+ "typescript": "7.0.2"
57
+ },
58
+ "publishConfig": {
59
+ "access": "public",
60
+ "provenance": false
61
+ }
62
+ }