@trackunit/iris-app 2.11.11 → 2.13.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/CHANGELOG.md +55 -0
- package/README.md +0 -17
- package/package.json +7 -7
- package/src/generators/preset/files/.agents/skills/browser-testing/SKILL.md +36 -174
- package/src/generators/preset/files/.agents/skills/create-app/SKILL.md +22 -180
- package/src/generators/preset/files/.agents/skills/customfields/SKILL.md +38 -140
- package/src/generators/preset/files/.agents/skills/databricks-unity-catalog/SKILL.md +43 -90
- package/src/generators/preset/files/.agents/skills/graphql/SKILL.md +25 -122
- package/src/generators/preset/files/.agents/skills/graphql-timeseries/SKILL.md +27 -142
- package/src/generators/preset/files/.agents/skills/irisx-app-sdk/SKILL.md +11 -88
- package/src/generators/preset/files/.agents/skills/react-core-hooks/SKILL.md +21 -157
- package/src/generators/preset/files/.agents/skills/set-up-react-map/SKILL.md +8 -18
- package/src/generators/preset/files/.agents/skills/tables-and-sorting/SKILL.md +63 -63
- package/src/generators/preset/files/.agents/skills/widget-extensions/SKILL.md +53 -180
|
@@ -5,144 +5,69 @@ description: Use when storing app data on entities, persisting user input, defin
|
|
|
5
5
|
|
|
6
6
|
# CustomFields
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
CustomFields store extra data on assets, accounts, groups, and sites. They are the primary way to persist IrisX app data, such as user input, preferences, configuration, or custom KPIs. Use them instead of external databases or storage.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## When to Use
|
|
13
|
-
|
|
14
|
-
- Storing user input or preferences
|
|
15
|
-
- Adding metadata to assets/accounts/groups/sites
|
|
16
|
-
- Persisting app-specific configuration
|
|
17
|
-
- Creating custom KPIs or fleet attributes
|
|
18
|
-
|
|
19
|
-
**Not for:** External databases or storage solutions (use CustomFields instead).
|
|
20
|
-
|
|
21
|
-
## Defining Custom Fields
|
|
22
|
-
|
|
23
|
-
### Manifest Configuration
|
|
10
|
+
## Define fields in the manifest
|
|
24
11
|
|
|
25
12
|
```typescript
|
|
26
13
|
customFieldDefinitions: [
|
|
27
14
|
{
|
|
28
15
|
type: 'STRING',
|
|
29
|
-
entityType: 'ASSET',
|
|
16
|
+
entityType: 'ASSET', // ACCOUNT, ASSET, GROUP, or SITE
|
|
30
17
|
key: 'myCustomField',
|
|
31
18
|
translations: [{
|
|
32
19
|
language: 'en',
|
|
33
20
|
title: 'My Custom Field',
|
|
34
21
|
description: 'Description of what this field stores',
|
|
35
22
|
}],
|
|
36
|
-
uiEditable: true,
|
|
37
|
-
uiVisible: true,
|
|
38
|
-
scopeType: 'ACCOUNT'
|
|
23
|
+
uiEditable: true, // default true: editable in the Manager UI
|
|
24
|
+
uiVisible: true, // default true: visible in the Manager UI
|
|
25
|
+
scopeType: 'ACCOUNT',
|
|
39
26
|
}
|
|
40
27
|
]
|
|
41
28
|
```
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
| Property | Description |
|
|
46
|
-
|----------|-------------|
|
|
47
|
-
| `type` | Field data type |
|
|
48
|
-
| `entityType` | `ACCOUNT`, `ASSET`, `GROUP`, or `SITE` |
|
|
49
|
-
| `key` | Programmatic identifier (immutable after creation) |
|
|
50
|
-
| `translations` | UI labels and descriptions |
|
|
51
|
-
| `scopeType` | Data access scope |
|
|
52
|
-
|
|
53
|
-
### Optional Properties
|
|
54
|
-
|
|
55
|
-
| Property | Default | Description |
|
|
56
|
-
|----------|---------|-------------|
|
|
57
|
-
| `uiEditable` | `true` | Can be edited in Manager UI |
|
|
58
|
-
| `uiVisible` | `true` | Visible in Manager UI |
|
|
59
|
-
|
|
60
|
-
## Supported Field Types
|
|
61
|
-
|
|
62
|
-
| Type | Description | Extra Properties |
|
|
63
|
-
|------|-------------|------------------|
|
|
64
|
-
| `BOOLEAN` | True/false values | - |
|
|
65
|
-
| `DATE` | ISO8601 formatted dates | - |
|
|
66
|
-
| `DROPDOWN` | Predefined option lists | `allValues`, `multiSelect`, `valueReplacements` |
|
|
67
|
-
| `EMAIL` | Email addresses with mailto links | - |
|
|
68
|
-
| `NUMBER` | Numeric values | `minimum`, `maximum`, `isInteger`, `unitSi`, `unitUs` |
|
|
69
|
-
| `PHONE_NUMBER` | E.164 formatted phone numbers | - |
|
|
70
|
-
| `STRING` | Free text | `minimumLength`, `maximumLength`, `pattern` |
|
|
71
|
-
| `STRING_LIST` | Array of strings | - |
|
|
72
|
-
| `WEB_ADDRESS` | URLs as clickable links | - |
|
|
73
|
-
| `JSON` | JSON objects | - |
|
|
74
|
-
| `FILE` | File attachments | - |
|
|
75
|
-
| `MONETARY` | Currency values (ISO 4217) | `currency` |
|
|
76
|
-
|
|
77
|
-
## Example Field Definitions
|
|
30
|
+
`type`, `entityType`, `key`, `translations`, and `scopeType` are required. Always give translations a meaningful title and description.
|
|
78
31
|
|
|
79
|
-
|
|
32
|
+
**Keys are immutable** once created, so choose clear, descriptive keys up front. Changing a definition affects all existing data, and custom field changes require app approval and a marketplace submission.
|
|
80
33
|
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
type: 'STRING',
|
|
84
|
-
entityType: 'ASSET',
|
|
85
|
-
key: 'serialNumber',
|
|
86
|
-
translations: [{ language: 'en', title: 'Serial Number', description: 'Asset serial number' }],
|
|
87
|
-
minimumLength: 5,
|
|
88
|
-
maximumLength: 20,
|
|
89
|
-
pattern: '^[A-Z0-9]+$'
|
|
90
|
-
}
|
|
91
|
-
```
|
|
34
|
+
### Types
|
|
92
35
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
36
|
+
| Type | Stores | Extra properties |
|
|
37
|
+
|------|--------|------------------|
|
|
38
|
+
| `BOOLEAN` | True or false | |
|
|
39
|
+
| `DATE` | ISO 8601 dates | |
|
|
40
|
+
| `DROPDOWN` | Predefined options | `allValues`, `multiSelect`, `valueReplacements` |
|
|
41
|
+
| `EMAIL` | Email addresses, shown as mailto links | |
|
|
42
|
+
| `NUMBER` | Numbers | `minimum`, `maximum`, `isInteger`, `unitSi`, `unitUs` |
|
|
43
|
+
| `PHONE_NUMBER` | E.164 phone numbers | |
|
|
44
|
+
| `STRING` | Free text | `minimumLength`, `maximumLength`, `pattern` |
|
|
45
|
+
| `STRING_LIST` | Arrays of strings | |
|
|
46
|
+
| `WEB_ADDRESS` | URLs, shown as links | |
|
|
47
|
+
| `JSON` | JSON objects | |
|
|
48
|
+
| `FILE` | File attachments | |
|
|
49
|
+
| `MONETARY` | ISO 4217 currency values | `currency` |
|
|
107
50
|
|
|
108
|
-
|
|
51
|
+
Use the extra properties for validation, for example:
|
|
109
52
|
|
|
110
53
|
```typescript
|
|
111
|
-
{
|
|
112
|
-
|
|
113
|
-
entityType: 'ASSET',
|
|
114
|
-
key: 'features',
|
|
115
|
-
translations: [{ language: 'en', title: 'Features', description: 'Available features' }],
|
|
116
|
-
allValues: ['GPS', 'Camera', 'Bluetooth', 'WiFi'],
|
|
117
|
-
multiSelect: true
|
|
118
|
-
}
|
|
54
|
+
{ type: 'NUMBER', key: 'fuelCapacity', minimum: 0, maximum: 1000, unitSi: 'L', unitUs: 'gal', /* ... */ }
|
|
55
|
+
{ type: 'DROPDOWN', key: 'features', allValues: ['GPS', 'Camera', 'Bluetooth', 'WiFi'], multiSelect: true, /* ... */ }
|
|
119
56
|
```
|
|
120
57
|
|
|
121
|
-
|
|
58
|
+
### Scopes
|
|
122
59
|
|
|
123
|
-
|
|
|
60
|
+
| `scopeType` | Values are |
|
|
124
61
|
|-------|-------------|
|
|
125
|
-
| `ACCOUNT` |
|
|
126
|
-
| `ACCOUNT_WRITE_GLOBAL_READ` |
|
|
127
|
-
| `GLOBAL` |
|
|
128
|
-
|
|
129
|
-
## Using CustomFields in React
|
|
62
|
+
| `ACCOUNT` | Shared within one account only |
|
|
63
|
+
| `ACCOUNT_WRITE_GLOBAL_READ` | Written by the account, readable by all accounts |
|
|
64
|
+
| `GLOBAL` | Shared between all accounts with access to the entity |
|
|
130
65
|
|
|
131
|
-
|
|
66
|
+
## Read and write in React
|
|
132
67
|
|
|
133
|
-
|
|
134
|
-
import {
|
|
135
|
-
useCustomFieldsValueAndDefinition,
|
|
136
|
-
useUpdateCustomFieldValues
|
|
137
|
-
} from '@trackunit/custom-field-api';
|
|
138
|
-
import { CustomField } from '@trackunit/custom-field-components';
|
|
139
|
-
import { useCurrentUserSystemOfMeasurement } from '@trackunit/react-core-hooks';
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### Basic Implementation
|
|
68
|
+
Use `useUpdateCustomFieldValues` to update several fields at once. Show a loading state while fetching, and handle failed updates.
|
|
143
69
|
|
|
144
70
|
```typescript
|
|
145
|
-
import React from 'react';
|
|
146
71
|
import { useForm } from 'react-hook-form';
|
|
147
72
|
import { Card, CardBody, CardHeader, CardFooter, Button, Spinner } from '@trackunit/react-components';
|
|
148
73
|
import { useCustomFieldsValueAndDefinition, useUpdateCustomFieldValues } from '@trackunit/custom-field-api';
|
|
@@ -153,15 +78,15 @@ const CustomFieldsForm = ({ assetId }: { assetId: string }) => {
|
|
|
153
78
|
const { register, handleSubmit, formState, setValue, control } = useForm({
|
|
154
79
|
shouldUnregister: false,
|
|
155
80
|
});
|
|
156
|
-
|
|
81
|
+
|
|
157
82
|
const { systemOfMeasurement } = useCurrentUserSystemOfMeasurement();
|
|
158
|
-
|
|
83
|
+
|
|
159
84
|
const { fields, loading } = useCustomFieldsValueAndDefinition({
|
|
160
85
|
entityType: "ASSET",
|
|
161
86
|
entityId: assetId,
|
|
162
87
|
systemOfMeasurement: systemOfMeasurement ?? "SI",
|
|
163
88
|
});
|
|
164
|
-
|
|
89
|
+
|
|
165
90
|
const { updateCustomFields, inProgress } = useUpdateCustomFieldValues(
|
|
166
91
|
assetId,
|
|
167
92
|
"ASSET",
|
|
@@ -192,8 +117,8 @@ const CustomFieldsForm = ({ assetId }: { assetId: string }) => {
|
|
|
192
117
|
})}
|
|
193
118
|
</CardBody>
|
|
194
119
|
<CardFooter>
|
|
195
|
-
<Button
|
|
196
|
-
loading={inProgress}
|
|
120
|
+
<Button
|
|
121
|
+
loading={inProgress}
|
|
197
122
|
onClick={handleSubmit(updateCustomFields)}
|
|
198
123
|
>
|
|
199
124
|
{inProgress ? "Saving..." : "Save Changes"}
|
|
@@ -204,33 +129,6 @@ const CustomFieldsForm = ({ assetId }: { assetId: string }) => {
|
|
|
204
129
|
};
|
|
205
130
|
```
|
|
206
131
|
|
|
207
|
-
## Best Practices
|
|
208
|
-
|
|
209
|
-
### Field Design
|
|
210
|
-
- **Use descriptive keys**: Choose clear, descriptive field keys that won't need changing
|
|
211
|
-
- **Add proper translations**: Always provide meaningful titles and descriptions
|
|
212
|
-
- **Set appropriate constraints**: Use min/max values, length limits, and patterns for validation
|
|
213
|
-
|
|
214
|
-
### Performance
|
|
215
|
-
- **Batch updates**: Use `useUpdateCustomFieldValues` to update multiple fields at once
|
|
216
|
-
- **Handle loading states**: Always show loading indicators while fetching data
|
|
217
|
-
- **Error handling**: Implement proper error handling for failed updates
|
|
218
|
-
|
|
219
|
-
### Deployment
|
|
220
|
-
- **Field keys are immutable**: Cannot be changed after creation
|
|
221
|
-
- **Definition updates**: Changing field definitions affects all existing data
|
|
222
|
-
- **Approval process**: Custom field changes require app approval and marketplace submission
|
|
223
|
-
|
|
224
|
-
## Common Mistakes
|
|
225
|
-
|
|
226
|
-
| Mistake | Fix |
|
|
227
|
-
|---------|-----|
|
|
228
|
-
| Changing field key after creation | Keys are immutable; plan carefully upfront |
|
|
229
|
-
| Missing translations | Always provide titles and descriptions for UI |
|
|
230
|
-
| Using external storage | CustomFields are the recommended persistence mechanism |
|
|
231
|
-
| No loading states | Show `<Spinner />` while fetching data |
|
|
232
|
-
| Skipping error handling | Handle failed updates gracefully |
|
|
233
|
-
|
|
234
132
|
## References
|
|
235
133
|
|
|
236
134
|
- [Save Data from Your App](https://developers.trackunit.com/docs/apps-and-extensions/overview/save-data-from-your-app)
|
|
@@ -5,28 +5,24 @@ description: Builds IrisX app features that read or write customer-uploaded or a
|
|
|
5
5
|
|
|
6
6
|
# Databricks Unity Catalog
|
|
7
7
|
|
|
8
|
-
Access Unity Catalog through an IrisX serverside API extension. Never call Databricks
|
|
8
|
+
Access Unity Catalog only through an IrisX serverside API extension. Never call Databricks from browser code or expose Databricks credentials to the client.
|
|
9
9
|
|
|
10
10
|
## Prefer GraphQL for Trackunit data
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
Use the `graphql` and `graphql-timeseries` skills for Trackunit data: machine insights, engine metrics, fuel, operating hours, and other telematics. Use Unity Catalog only for customer-uploaded tables, app-owned analytics tables, or other data GraphQL cannot serve.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
## Whose workspace
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Always select the catalog from the app creator's IrisX workspace. Do not derive a catalog name from an end user's account slug or silently choose a similar name.
|
|
16
|
+
The app always connects to the **app creator's** IrisX analytics workspace, never the invoking user's. That workspace may not contain the user's assets; they appear only if the user's account has shared asset data with the app developer. So do not treat the `irisx` catalog as the source of the user's machine data. The caller may not have IrisX access at all. Their account is only an authorization and row-isolation boundary, and must never control which workspace, catalog, or credentials the app uses.
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
2. For customer-uploaded or app-owned data, execute:
|
|
18
|
+
## Choose and confirm the catalog
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
SHOW CATALOGS
|
|
25
|
-
```
|
|
20
|
+
Never derive a catalog name from the end user's account slug or silently pick a similar name.
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
1. With the Trackunit IrisX Analytics SQL MCP tool (currently `ixa_sql_execute_read_only`), run `SHOW CATALOGS`.
|
|
23
|
+
2. Identify catalogs similar to the app creator's account name.
|
|
24
|
+
3. Ask the user to confirm the catalog before putting it in code or configuration, even when one candidate looks obvious.
|
|
25
|
+
4. Then inspect it with read-only queries:
|
|
30
26
|
|
|
31
27
|
```sql
|
|
32
28
|
SHOW SCHEMAS IN `<catalog>`;
|
|
@@ -35,7 +31,7 @@ DESCRIBE TABLE `<catalog>`.`<schema>`.`<table>`;
|
|
|
35
31
|
SELECT * FROM `<catalog>`.`<schema>`.`<table>` LIMIT 10;
|
|
36
32
|
```
|
|
37
33
|
|
|
38
|
-
Always use fully qualified names. Backticks are
|
|
34
|
+
Always use fully qualified names. Backticks are quoting, not validation: before an identifier reaches code, constrain it to a strict allow-list (for example `/^[A-Za-z0-9_]+$/`) or double any embedded backticks. The MCP tool is for discovery and read-only checks only. It cannot validate writes and is not the app's runtime data path.
|
|
39
35
|
|
|
40
36
|
## Architecture
|
|
41
37
|
|
|
@@ -47,57 +43,40 @@ UI extension
|
|
|
47
43
|
-> confirmed Unity Catalog catalog.schema.table
|
|
48
44
|
```
|
|
49
45
|
|
|
50
|
-
`@<scope>/<app>` is the Iris app ID (
|
|
51
|
-
|
|
52
|
-
- The UI sends the IrisX user token to the invoke route.
|
|
53
|
-
- The serverside extension authenticates the user and account.
|
|
54
|
-
- `@trackunit/serverside-utils` uses app-level secrets to obtain a short-lived token for the app creator's IrisX workspace.
|
|
55
|
-
- Only the serverside extension submits SQL.
|
|
46
|
+
`@<scope>/<app>` is the Iris app ID (the full package name), for example `@trackunit/my-app`. The scope is the npm package scope, not an IrisX or Databricks workspace.
|
|
56
47
|
|
|
57
|
-
|
|
48
|
+
The UI sends the IrisX user token to the invoke route. The serverside extension authenticates the user and account, then uses app-level secrets via `@trackunit/serverside-utils` to get a short-lived token for the app creator's workspace. Only the serverside extension submits SQL.
|
|
58
49
|
|
|
59
50
|
## Create the serverside function
|
|
60
51
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
npx nx g @trackunit/iris-app:extend \
|
|
65
|
-
--name=<feature-api> \
|
|
66
|
-
--app=<app-name> \
|
|
67
|
-
--directory=<feature> \
|
|
68
|
-
--type=SERVERSIDE_API_EXTENSION
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
Add the latest `@trackunit/serverside-utils` and a runtime validation library such as `zod` using the workspace package manager. Ensure the serverside extension's `package.json` lists runtime dependencies.
|
|
72
|
-
|
|
73
|
-
The generator creates a Hono handler, local server, build target, Deno serverside extension manifest, and app-manifest registration. Keep all Databricks code in this extension.
|
|
52
|
+
Create a dedicated extension with the extension command in `AGENTS.md` and `--type=SERVERSIDE_API_EXTENSION`. It generates a Hono handler, local server, build target, Deno manifest, and app manifest registration. Keep all Databricks code in it.
|
|
74
53
|
|
|
75
|
-
|
|
54
|
+
Add the latest `@trackunit/serverside-utils` and a runtime validation library such as `zod`, and list them in the extension's `package.json`.
|
|
76
55
|
|
|
77
|
-
|
|
56
|
+
Ask the user for the exact Databricks hostname before editing the app manifest. They find it by opening **Notebooks** from their **IrisX Library** in Trackunit Manager and copying the hostname from the URL. The user cannot read the `DATABRICKS_HOST` secret. Never guess the hostname or leave a placeholder.
|
|
78
57
|
|
|
79
|
-
|
|
58
|
+
Add that exact hostname as a literal in `cspHeader["connect-src"]` in `iris-app-manifest.ts`. For a serverside extension, `connect-src` is the Deno network sandbox (`--allow-net`), and the default hosts exclude Databricks. Without the entry, token and SQL calls fail after publish, even though local serve (which has no sandbox) works. Wildcards like `*.cloud.databricks.com` are dropped from the serverside allow-list. Adding the host never makes browser calls to Databricks acceptable.
|
|
80
59
|
|
|
81
60
|
## Runtime configuration
|
|
82
61
|
|
|
83
|
-
Trackunit configures these app-level secrets. Read them with `getSecret({ context, secretKey })`.
|
|
62
|
+
Trackunit configures these app-level secrets. Read them with `getSecret({ context, secretKey })`. Never create, invent, or commit values for them, and ask Trackunit to provision any that are missing:
|
|
84
63
|
|
|
85
64
|
- `DATABRICKS_HOST`
|
|
86
65
|
- `DATABRICKS_SQL_WAREHOUSE_ID`
|
|
87
66
|
- `DATABRICKS_CLIENT_ID`
|
|
88
67
|
- `DATABRICKS_CLIENT_SECRET`
|
|
89
68
|
|
|
90
|
-
`getDatabricksAccessToken` reads
|
|
69
|
+
`getDatabricksAccessToken` reads the client ID and secret itself when they are not passed in. Never use account-scoped secrets for this connection.
|
|
91
70
|
|
|
92
|
-
When schema or table names differ by environment, use the platform `SDK_ENVIRONMENT` value (`DEV` / `STAGE` / `PROD`)
|
|
71
|
+
When schema or table names differ by environment, use the platform `SDK_ENVIRONMENT` value (`DEV` / `STAGE` / `PROD`), not a secret.
|
|
93
72
|
|
|
94
|
-
Keep the confirmed catalog and schema
|
|
73
|
+
Keep the confirmed catalog and schema in app-level configuration. Never accept a catalog, schema, table, SQL fragment, or sort expression from a browser request. If an identifier must vary, map a validated enum to an allow-listed identifier.
|
|
95
74
|
|
|
96
|
-
Do not commit local `.env` values.
|
|
75
|
+
Do not commit local `.env` values. Never log tokens, secrets, authorization headers, raw user data, or complete SQL parameters.
|
|
97
76
|
|
|
98
77
|
## Authenticate and connect
|
|
99
78
|
|
|
100
|
-
Use the request `Context
|
|
79
|
+
Use the request `Context`. The platform supplies the Iris app headers that `serverside-utils` needs.
|
|
101
80
|
|
|
102
81
|
```typescript
|
|
103
82
|
import {
|
|
@@ -147,27 +126,18 @@ export async function getConnection(c: Context) {
|
|
|
147
126
|
}
|
|
148
127
|
```
|
|
149
128
|
|
|
150
|
-
|
|
129
|
+
Account isolation is mandatory:
|
|
151
130
|
|
|
152
|
-
- Use the app's existing access
|
|
153
|
-
-
|
|
154
|
-
- Scope every query to the authenticated customer when a table
|
|
155
|
-
- Never trust an account ID, user ID, or ownership field
|
|
156
|
-
- For user-owned mutations, derive the user identity from the verified user token.
|
|
157
|
-
- Always use app-level Databricks host, client credentials, warehouse, catalog, and schema so the app connects to its creator's IrisX workspace. Do not use account-scoped secrets for this connection.
|
|
158
|
-
- Treat the authenticated caller's account only as an authorization and row-isolation boundary. The caller does not need IrisX access and must not control which workspace the app queries.
|
|
131
|
+
- Use the app's existing access control. Do not add a hardcoded account allow-list in the data layer.
|
|
132
|
+
- Enforce the relevant declared scope with `requireScopes`. A token alone does not authorize an operation.
|
|
133
|
+
- Scope every query to the authenticated customer when a table holds several customers.
|
|
134
|
+
- Never trust an account ID, user ID, or ownership field from the browser. For user-owned mutations, take the user identity from the verified token.
|
|
159
135
|
|
|
160
|
-
|
|
136
|
+
You may cache a Databricks token per app deployment and credential identity until shortly before expiry. Enforce tenant isolation on every request regardless.
|
|
161
137
|
|
|
162
138
|
## Execute statements
|
|
163
139
|
|
|
164
|
-
Submit SQL to:
|
|
165
|
-
|
|
166
|
-
```text
|
|
167
|
-
POST https://<DATABRICKS_HOST>/api/2.0/sql/statements
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Use an explicit warehouse, confirmed catalog/schema, bounded wait, inline JSON results, query tags, and a request timeout:
|
|
140
|
+
Submit SQL to `POST https://<DATABRICKS_HOST>/api/2.0/sql/statements` with an explicit warehouse, the confirmed catalog and schema, a bounded wait, inline JSON results, query tags, and a request timeout:
|
|
171
141
|
|
|
172
142
|
```typescript
|
|
173
143
|
const MAX_ROWS = 1_000;
|
|
@@ -201,21 +171,21 @@ const response = await fetch(`https://${host}/api/2.0/sql/statements`, {
|
|
|
201
171
|
});
|
|
202
172
|
```
|
|
203
173
|
|
|
204
|
-
Validate the HTTP response and JSON shape
|
|
174
|
+
Validate the HTTP response and JSON shape, and handle every statement state:
|
|
205
175
|
|
|
206
176
|
- `SUCCEEDED`: map rows using `manifest.schema.columns` and `result.data_array`.
|
|
207
|
-
- `PENDING` or `RUNNING`: poll `GET /api/2.0/sql/statements/<statement_id>` with a bounded deadline and backoff.
|
|
177
|
+
- `PENDING` or `RUNNING`: poll `GET /api/2.0/sql/statements/<statement_id>` with a bounded deadline and backoff. These are not failures.
|
|
208
178
|
- `FAILED`, `CANCELED`, or `CLOSED`: log a sanitized diagnostic and return a stable upstream error.
|
|
209
179
|
|
|
210
|
-
Follow `next_chunk_index`/`next_chunk_internal_link` until all
|
|
180
|
+
Follow `next_chunk_index`/`next_chunk_internal_link` until all inline chunks are read, using `GET /api/2.0/sql/statements/<statement_id>/result/chunks/<chunk_index>`. If `manifest.truncated` is set, reject the result rather than return partial data. Before allowing large exports, use `row_limit` and `byte_limit` or implement external-link retrieval.
|
|
211
181
|
|
|
212
|
-
When the
|
|
182
|
+
When the polling deadline expires, request cancellation with `POST /api/2.0/sql/statements/<statement_id>/cancel`. Cancellation does not prove a write didn't commit: read the final state before retrying, and require idempotency keys or `MERGE` for retryable writes. Retry `429` and transient failures with bounded backoff, but never blindly retry mutations.
|
|
213
183
|
|
|
214
|
-
|
|
184
|
+
Never return Databricks error details or SQL text to the browser.
|
|
215
185
|
|
|
216
186
|
## Build safe SQL
|
|
217
187
|
|
|
218
|
-
Use named
|
|
188
|
+
Use named parameters for every value:
|
|
219
189
|
|
|
220
190
|
```typescript
|
|
221
191
|
const sql = `
|
|
@@ -234,7 +204,7 @@ const parameters = [
|
|
|
234
204
|
];
|
|
235
205
|
```
|
|
236
206
|
|
|
237
|
-
Parameters cannot represent identifiers or
|
|
207
|
+
Parameters cannot represent identifiers or keywords, so implement filters and sorting through exhaustive allow-list mappings. Bound pagination and result sizes.
|
|
238
208
|
|
|
239
209
|
For writes:
|
|
240
210
|
|
|
@@ -248,7 +218,7 @@ For writes:
|
|
|
248
218
|
|
|
249
219
|
## UI integration
|
|
250
220
|
|
|
251
|
-
|
|
221
|
+
Call the invoke route on the current origin with `useToken()`:
|
|
252
222
|
|
|
253
223
|
```typescript
|
|
254
224
|
const { token } = useToken();
|
|
@@ -264,32 +234,15 @@ const response = await fetch(
|
|
|
264
234
|
);
|
|
265
235
|
```
|
|
266
236
|
|
|
267
|
-
|
|
237
|
+
Treat `401` as an expired session, `403` as unavailable for this account, and upstream `502`/`504` as retryable. Cancel stale requests and validate response data before rendering.
|
|
268
238
|
|
|
269
239
|
## Verification
|
|
270
240
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
1. Use the MCP read-only tool to verify the confirmed catalog, schema, table, and sample result.
|
|
274
|
-
2. Unit-test SQL builders, including parameters, tenant predicates, allow-listed sorting, and pagination bounds.
|
|
241
|
+
1. Verify the confirmed catalog, schema, table, and a sample result with the read-only MCP tool.
|
|
242
|
+
2. Unit-test SQL builders: parameters, tenant predicates, allow-listed sorting, and pagination bounds.
|
|
275
243
|
3. Unit-test authentication and account isolation.
|
|
276
244
|
4. Mock Databricks responses for success, pending/polling, timeout, malformed payload, and failure.
|
|
277
|
-
5. Test write authorization, ownership, validation, and idempotent
|
|
245
|
+
5. Test write authorization, ownership, validation, and idempotent retries.
|
|
278
246
|
6. Test UI loading, unauthorized, forbidden, empty, error, and success states.
|
|
279
|
-
7. Run lint, type checking, and focused tests for
|
|
247
|
+
7. Run lint, type checking, and focused tests for the UI and serverside projects.
|
|
280
248
|
8. Confirm `iris-app-manifest.ts` lists the exact Databricks host in `cspHeader["connect-src"]`.
|
|
281
|
-
|
|
282
|
-
## Common mistakes
|
|
283
|
-
|
|
284
|
-
- Guessing a customer catalog instead of listing and confirming it.
|
|
285
|
-
- Using Databricks for Trackunit machine or telematics data that GraphQL already serves (`graphql` / `graphql-timeseries`).
|
|
286
|
-
- Assuming the `irisx` catalog contains the invoking user's assets. The connection is to the app creator's IrisX workspace; the user's data is present only if their account has shared it with the app developer.
|
|
287
|
-
- Calling Databricks from the browser.
|
|
288
|
-
- Treating the read-only MCP tool as the app's runtime data path.
|
|
289
|
-
- Interpolating request values or identifiers into SQL.
|
|
290
|
-
- Querying a shared table without an authenticated tenant predicate.
|
|
291
|
-
- Implementing reads while leaving write endpoints under-authorized.
|
|
292
|
-
- Treating `PENDING` as a permanent failure or polling without a deadline.
|
|
293
|
-
- Returning raw Databricks errors, secrets, or SQL details to the client.
|
|
294
|
-
- Databricks calls fail after publish but work locally: the exact workspace host is missing from `cspHeader["connect-src"]`.
|
|
295
|
-
- Inventing or committing Databricks host, warehouse, or client-credential values. Trackunit configures those secrets.
|