@colixsystems/widget-sdk 0.340.0 → 0.342.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/README.md +27 -2
- package/dist/cli.js +21 -2
- package/dist/connector-app-operations.cjs +100 -0
- package/dist/connector-credential-entry.cjs +77 -0
- package/dist/connector-template-data.json +186 -0
- package/dist/connector-template.cjs +620 -0
- package/dist/contract.cjs +25 -3
- package/dist/contract.js +25 -3
- package/dist/date-label.cjs +164 -0
- package/dist/date-label.js +150 -0
- package/dist/datetimepicker-format.js +10 -103
- package/dist/hooks.js +8 -2
- package/dist/index.d.ts +43 -0
- package/package.json +7 -2
- package/src/contract.js +25 -3
- package/src/date-label.js +150 -0
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
|
|
|
46
46
|
| **CORE** | `useGeolocation(options)` (optional: options) | `{ latitude, longitude, accuracy, loading, error, getCurrentPosition, backgroundSupported, backgroundWatching, startBackgroundWatch, stopBackgroundWatch }` | `ctx.device.geolocation` — no scope. Capture is IMPERATIVE: call `getCurrentPosition()` from a user gesture (a tap), never on mount. Resolves to `{ latitude, longitude, accuracy }`; rejects with `GeolocationError` (`.code` in `PERMISSION_DENIED \| UNAVAILABLE \| TIMEOUT \| UNSUPPORTED \| INTERNAL`). Identical on web (`navigator.geolocation`) and the Expo export (`expo-location`). **Background watch** — `startBackgroundWatch({ enableHighAccuracy, distanceIntervalMeters, timeIntervalMs })` keeps positions arriving while the app is backgrounded; `stopBackgroundWatch()` releases it. NATIVE-ONLY and opt-in per app: gate the control on `backgroundSupported` (false on web, and in an export whose workspace did not opt in). The watch outlives the widget's mount, and its positions land in the same `latitude`/`longitude`/`accuracy` slots. |
|
|
47
47
|
| **CORE** | `useSpeechToText(options)` (optional: options) | `{ transcript, partial, listening, supported, error, start, stop, abort, reset }` | `ctx.device.speech` — no scope. Dictation with the device's **on-device** recogniser: no audio is uploaded and no AI credit is spent. Capture is IMPERATIVE: call `start()` from a user gesture (a tap), never on mount. `transcript` accumulates finalised speech, `partial` holds the uncommitted guess (needs `options.interimResults`); `stop()` keeps it, `abort()` discards it. Rejects with `SpeechToTextError` (`.code` in `PERMISSION_DENIED \| NO_SPEECH \| LANGUAGE_UNSUPPORTED \| NETWORK \| ABORTED \| UNSUPPORTED \| INTERNAL`). **Gate your mic button on `supported`** — Firefox ships no `SpeechRecognition`. Identical on web (`SpeechRecognition`) and the Expo export (`expo-speech-recognition`). |
|
|
48
48
|
| **CORE** | `useCamera(options)` (optional: options) | `{ asset, loading, error, supported, capture, pick, reset }` | `ctx.device.camera` — no scope. Take a photo (`capture()`) or choose one (`pick()`). Capture is IMPERATIVE: call from a user gesture (a tap), never on mount. Both resolve a normalised `{ uri, name, mimeType, width, height, size, file }`, or **`null` when the user dismisses the picker** — dismissal is not an error, so no `try/catch` is needed on the happy path. Rejects with `CameraError` (`.code` in `PERMISSION_DENIED \| UNSUPPORTED \| INTERNAL`). `asset.file` is already the right upload part for the host, so `fd.append("file", asset.file)` → `ctx.assets.upload(fd)` is ONE code path on both. **Gate your camera button on `supported`.** Identical on web (a live `getUserMedia` preview, phones included; a file input only where getUserMedia is absent) and the Expo export (`expo-image-picker`). |
|
|
49
|
-
| **CORE** | `useI18n()` | `{ t, locale, languages, canSetLocale, setLocale }` | `ctx.i18n` — no scope. `t(key)` resolves the widget-namespaced key (`widget.<id>.<key>`, declared in `manifest.translations`) first, then a **predefined shared key** (`shared.<key>`) when `key` is one of the standard strings (`submit`, `cancel`, `save`, `loading`, …), then the raw key. Use a shared key for an identical default string so it translates once and any per-instance `widget.<id>.<key>` override still wins. `languages` lists the app's active languages (`[{ code, name, is_base }]`); `setLocale(code)` switches the whole app live — saved to a signed-in user's account, kept on the device for a visitor, `null` for the app default. Rejects with `.code` `INVALID_LOCALE` \| `UNSUPPORTED`; `canSetLocale` is false where the host cannot switch (the Builder canvas). |
|
|
49
|
+
| **CORE** | `useI18n()` | `{ t, locale, languages, canSetLocale, setLocale, formatDate }` | `ctx.i18n` — no scope. `t(key)` resolves the widget-namespaced key (`widget.<id>.<key>`, declared in `manifest.translations`) first, then a **predefined shared key** (`shared.<key>`) when `key` is one of the standard strings (`submit`, `cancel`, `save`, `loading`, …), then the raw key. Use a shared key for an identical default string so it translates once and any per-instance `widget.<id>.<key>` override still wins. `languages` lists the app's active languages (`[{ code, name, is_base }]`); `setLocale(code)` switches the whole app live — saved to a signed-in user's account, kept on the device for a visitor, `null` for the app default. Rejects with `.code` `INVALID_LOCALE` \| `UNSUPPORTED`; `canSetLocale` is false where the host cannot switch (the Builder canvas). Show every date with `formatDate(value)`: the app's language with the month named (`Jan 3, 2027`, `3 jan. 2027`), `{ time: true }` adds the time, and a null, empty or unreadable value gives `—` instead of throwing. Without `time`, a value at exactly midnight UTC is read as a calendar date. Never a numeric pattern such as `dd/MM/yyyy`. |
|
|
50
50
|
| **CORE** | `useAppearance()` | `{ mode, preference, canSwitch, setPreference }` | `ctx.appearance` — no scope. `mode` is the palette showing (`light` \| `dark`), `preference` what the app follows (`light` \| `dark` \| `system`). `setPreference(p)` switches the whole app live — saved to a signed-in user's account, kept on the device for a visitor, `null` for the app default. Rejects with `.code` `UNSUPPORTED` \| `INVALID_APPEARANCE`; `canSwitch` is false where the app does not let users switch and on the Builder canvas. |
|
|
51
51
|
| **CORE** | `useTranslate()` | `{ translate, translating, error, language, available }` | `ctx.i18n.translate` — no scope. Machine-translates **user-generated content** (record text, file names, API payloads) into the app user's language; `useI18n().t()` is still the answer for your own copy. `translate(str)` → `Promise<string>`, `translate(str[])` → `Promise<string[]>` in ONE request. Target defaults to the app user's language. Cached per session, per pod, and durably per workspace, so repeat text is free. Limits: 50 segments / 5 000 chars each / 20 000 total. Rejects with `TranslateError`; `available` is false where the host cannot translate. |
|
|
52
52
|
| **CORE** | `useLinkPreview(url)` | `{ preview, loading, error, available }` — `preview` is `{ url, title, description, site_name, image_url } \| null` | `ctx.linkPreviews.get` — no scope. A link's title, description, site name and image, fetched by the platform (the device never contacts the linked site). A page with nothing to show resolves with null fields, not an error — render the plain link. A non-http(s) `url` makes no request. Memoized for up to an hour across widgets; concurrent calls for one URL share a request. `error` is a `LinkPreviewError` (`VALIDATION` \| `AUTH_REQUIRED` \| `RATE_LIMITED` \| `NETWORK` \| `INTERNAL`). `available` is false on a host with no link-preview client |
|
|
@@ -91,7 +91,32 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
91
91
|
|
|
92
92
|
## Status
|
|
93
93
|
|
|
94
|
-
`v0.
|
|
94
|
+
`v0.342.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
95
|
+
|
|
96
|
+
### What's new in 0.342.0 (contract 1.279.0)
|
|
97
|
+
|
|
98
|
+
**`useI18n().formatDate` shows a date in the app's language.** `formatDate(value)` names the month, as the Studio and `<DateTimePicker>` do: `Jan 3, 2027` in an English app, `3 jan. 2027` in a Swedish one. `formatDate(value, { time: true })` adds the time of a date-and-time value; a bare `YYYY-MM-DD` never shows one. It takes an ISO string, a `Date` or a timestamp, keeps a DATE column's `YYYY-MM-DDT00:00:00.000Z` on its calendar day, and returns `—` for a null, empty or unreadable value instead of throwing, so it is also the guard every shown date needs. Without `time`, a value at exactly midnight UTC is read as a calendar date (how a DATE column arrives), so a date-and-time stored at that instant shows its UTC day. It shows the date in the app's language on the web and in the exported app alike (through each platform's own date formatting, so spacing can differ slightly). It formats dates only: a time on its own (a `14:30` text) gives `—`. Use it instead of a fixed pattern such as `dd/MM/yyyy`: `03/01/2027` is 3 January in one country and 1 March in another.
|
|
99
|
+
|
|
100
|
+
```js
|
|
101
|
+
const { t, formatDate } = useI18n();
|
|
102
|
+
<Text>{t("access_ends", "Access ends on")} {formatDate(member.accessEnds)}</Text>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### What's new in 0.341.0 (contract 1.278.0)
|
|
106
|
+
|
|
107
|
+
**A widget ships the REST connectors it calls.** Declare them in the manifest's `connectorTemplates`, the same contract an Action's templates follow, plus `appOperations`: the operations the widget calls with `useConnector(connectorId).call("<operation>", { params, query, body })`. Installing the widget creates each connector in the workspace, callable from the app with exactly those operations, so the installer only adds the credential. A `connectorRef` property that names a template with `template: "<key>"` is bound to that connector when the widget is placed. Until the credential is added, a call rejects `CONNECTOR_SETUP_INCOMPLETE`. A reinstall or an upgrade keeps the installer's credential and creates no second connector. An upgrade that adds or changes an operation, asks its token for more, or moves the connector to another host is not applied to an installed connector, so keep the operations an earlier version listed working.
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
connectorTemplates: [{
|
|
111
|
+
key: "weather", name: "Weather API", baseUrl: "https://api.example.com/v1",
|
|
112
|
+
authType: "apiKey", authConfig: { header_name: "X-Api-Key" },
|
|
113
|
+
appOperations: [{ key: "forecast", method: "GET", path: "/forecast/{city}", query: ["days"] }],
|
|
114
|
+
}],
|
|
115
|
+
requestedScopes: ["connectors.call:*"],
|
|
116
|
+
propertySchema: { weatherApi: { type: "connectorRef", label: "Weather API", template: "weather" } },
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
A template never carries a credential (a token, password, API key value or client secret): `appstudio-widget lint --manifest` and publishing refuse it. Publishing also needs `connectors.call:*` in `requestedScopes`, and a host on the public internet. The validator is exported as `@colixsystems/widget-sdk/connector-template` (CommonJS), the same code the action SDK ships. Additive.
|
|
95
120
|
|
|
96
121
|
### What's new in 0.339.0 (contract 1.277.0)
|
|
97
122
|
|
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
// — REQ-WSDK-DEVKIT local dev server
|
|
6
6
|
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
|
+
import { createRequire } from "node:module";
|
|
8
9
|
import { basename, dirname, resolve } from "node:path";
|
|
9
10
|
import { pathToFileURL } from "node:url";
|
|
10
11
|
import { argv, exit, stderr, stdout } from "node:process";
|
|
@@ -85,6 +86,17 @@ function assetFindings(assets) {
|
|
|
85
86
|
}));
|
|
86
87
|
}
|
|
87
88
|
|
|
89
|
+
const { widgetConnectorTemplateErrors } = createRequire(import.meta.url)("./connector-template.cjs");
|
|
90
|
+
|
|
91
|
+
/** sc-17829 — the manifest's connectorTemplates, checked as publish checks them. */
|
|
92
|
+
function connectorTemplateFindings(manifest) {
|
|
93
|
+
return widgetConnectorTemplateErrors(manifest).map((label) => ({
|
|
94
|
+
rule: "connector-templates",
|
|
95
|
+
severity: "error",
|
|
96
|
+
label,
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
88
100
|
async function loadManifest(path) {
|
|
89
101
|
const abs = resolve(path);
|
|
90
102
|
if (abs.endsWith(".json")) return JSON.parse(readFileSync(abs, "utf8"));
|
|
@@ -152,11 +164,13 @@ async function runLint(rest) {
|
|
|
152
164
|
const editability = manifest
|
|
153
165
|
? lintEditability(manifest, files)
|
|
154
166
|
: { ok: true, findings: [] };
|
|
167
|
+
const connectors = manifest ? connectorTemplateFindings(manifest) : [];
|
|
155
168
|
const all = perFile
|
|
156
169
|
.flatMap(([, r]) => r.findings)
|
|
157
170
|
.concat(bundled)
|
|
158
171
|
.concat(wiring.findings)
|
|
159
|
-
.concat(editability.findings)
|
|
172
|
+
.concat(editability.findings)
|
|
173
|
+
.concat(connectors);
|
|
160
174
|
if (all.length === 0) {
|
|
161
175
|
stdout.write(`${label}: clean\n`);
|
|
162
176
|
exit(0);
|
|
@@ -168,7 +182,8 @@ async function runLint(rest) {
|
|
|
168
182
|
perFile.every(([, r]) => r.ok) &&
|
|
169
183
|
bundled.length === 0 &&
|
|
170
184
|
wiring.ok &&
|
|
171
|
-
editability.ok
|
|
185
|
+
editability.ok &&
|
|
186
|
+
connectors.length === 0;
|
|
172
187
|
const errors = all.filter((f) => f.severity !== "warning").length;
|
|
173
188
|
const stream = ok ? stdout : stderr;
|
|
174
189
|
stream.write(
|
|
@@ -191,6 +206,10 @@ async function runLint(rest) {
|
|
|
191
206
|
stream.write(`manifest.editability:\n`);
|
|
192
207
|
writeFindings(editability.findings, stream);
|
|
193
208
|
}
|
|
209
|
+
if (connectors.length > 0) {
|
|
210
|
+
stream.write("manifest.connectorTemplates:\n");
|
|
211
|
+
writeFindings(connectors, stream);
|
|
212
|
+
}
|
|
194
213
|
exit(ok ? 0 : 1);
|
|
195
214
|
}
|
|
196
215
|
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// sc-15659 — the operations an app widget may call on a REST connector.
|
|
4
|
+
//
|
|
5
|
+
// A connector marked app-callable is reachable from a published app, where
|
|
6
|
+
// every signed-in app user holds the same call. The app never names a method or
|
|
7
|
+
// a path: it names a listed operation and the server builds the request. A path
|
|
8
|
+
// parameter fills one whole segment and can never add one, climb out of the
|
|
9
|
+
// path, or carry a query. One rule for the SDK validator, the publish analyzer
|
|
10
|
+
// and the backend's save path (sc-17829).
|
|
11
|
+
|
|
12
|
+
const DATA = require("./connector-template-data.json");
|
|
13
|
+
|
|
14
|
+
const APP_OPERATION_METHODS = Object.freeze([...DATA.connectorAppOperationMethods]);
|
|
15
|
+
const MAX_APP_OPERATIONS = DATA.connectorAppOperationsMax;
|
|
16
|
+
const MAX_QUERY_NAMES = 20;
|
|
17
|
+
const MAX_PATH_LENGTH = 512;
|
|
18
|
+
|
|
19
|
+
const KEY_RE = /^[A-Za-z][A-Za-z0-9_-]{0,63}$/;
|
|
20
|
+
const PLACEHOLDER_RE = /^\{([A-Za-z_][A-Za-z0-9_]{0,63})\}$/;
|
|
21
|
+
// RFC 3986 pchar, minus anything that could start a query or fragment.
|
|
22
|
+
const LITERAL_SEGMENT_RE = /^[A-Za-z0-9._~!$&'()*+,;=:@%-]+$/;
|
|
23
|
+
// A `%` must start a valid escape, and never an encoded dot, slash or backslash.
|
|
24
|
+
const ESCAPE_RE = /%(?![0-9A-Fa-f]{2})|%2e|%2f|%5c/i;
|
|
25
|
+
const QUERY_NAME_RE = /^[A-Za-z0-9_.[\]-]{1,64}$/;
|
|
26
|
+
|
|
27
|
+
const invalid = (detail) => new Error(`INVALID_APP_OPERATIONS: ${detail}`);
|
|
28
|
+
|
|
29
|
+
function isPlainObject(value) {
|
|
30
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The `{name}` placeholders of an operation path, in order. */
|
|
34
|
+
function appOperationPlaceholders(path) {
|
|
35
|
+
return path.split("/").slice(1).flatMap((segment) => {
|
|
36
|
+
const match = PLACEHOLDER_RE.exec(segment);
|
|
37
|
+
return match ? [match[1]] : [];
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function validatePath(path, key) {
|
|
42
|
+
if (typeof path !== "string" || !path.startsWith("/") || path.length > MAX_PATH_LENGTH) {
|
|
43
|
+
throw invalid(`${key}.path`);
|
|
44
|
+
}
|
|
45
|
+
const segments = path.split("/").slice(1);
|
|
46
|
+
const last = segments.length - 1;
|
|
47
|
+
segments.forEach((segment, index) => {
|
|
48
|
+
// Only the final segment may be empty: "/" or a trailing slash.
|
|
49
|
+
if (segment === "" && index === last) return;
|
|
50
|
+
const literal =
|
|
51
|
+
LITERAL_SEGMENT_RE.test(segment) && !ESCAPE_RE.test(segment) && segment !== "." && segment !== "..";
|
|
52
|
+
if (!literal && !PLACEHOLDER_RE.test(segment)) throw invalid(`${key}.path`);
|
|
53
|
+
});
|
|
54
|
+
const names = appOperationPlaceholders(path);
|
|
55
|
+
if (new Set(names).size !== names.length) throw invalid(`${key}.path`);
|
|
56
|
+
return path;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function validateOperation(raw, index) {
|
|
60
|
+
if (!isPlainObject(raw)) throw invalid(`[${index}]`);
|
|
61
|
+
const key = typeof raw.key === "string" ? raw.key.trim() : "";
|
|
62
|
+
if (!KEY_RE.test(key)) throw invalid(`[${index}].key`);
|
|
63
|
+
const method = String(raw.method ?? "").toUpperCase();
|
|
64
|
+
if (!APP_OPERATION_METHODS.includes(method)) throw invalid(`${key}.method`);
|
|
65
|
+
const path = validatePath(raw.path, key);
|
|
66
|
+
const query = raw.query === undefined || raw.query === null ? [] : raw.query;
|
|
67
|
+
if (
|
|
68
|
+
!Array.isArray(query) ||
|
|
69
|
+
query.length > MAX_QUERY_NAMES ||
|
|
70
|
+
!query.every((name) => typeof name === "string" && QUERY_NAME_RE.test(name)) ||
|
|
71
|
+
new Set(query).size !== query.length
|
|
72
|
+
) {
|
|
73
|
+
throw invalid(`${key}.query`);
|
|
74
|
+
}
|
|
75
|
+
const body = raw.body === true;
|
|
76
|
+
if (body && method === "GET") throw invalid(`${key}.body`);
|
|
77
|
+
return { key, method, path, query, body };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The normalised list a write stores; throws `INVALID_APP_OPERATIONS: <field>`.
|
|
82
|
+
* @param {unknown} raw
|
|
83
|
+
* @returns {Array<{ key: string, method: string, path: string, query: string[], body: boolean }>}
|
|
84
|
+
*/
|
|
85
|
+
function validateAppOperations(raw) {
|
|
86
|
+
if (raw === undefined || raw === null) return [];
|
|
87
|
+
if (!Array.isArray(raw) || raw.length > MAX_APP_OPERATIONS) throw invalid("list");
|
|
88
|
+
const operations = raw.map(validateOperation);
|
|
89
|
+
const keys = operations.map((op) => op.key);
|
|
90
|
+
if (new Set(keys).size !== keys.length) throw invalid("duplicate key");
|
|
91
|
+
return operations;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
module.exports = {
|
|
95
|
+
APP_OPERATION_METHODS,
|
|
96
|
+
MAX_APP_OPERATIONS,
|
|
97
|
+
PLACEHOLDER_RE,
|
|
98
|
+
appOperationPlaceholders,
|
|
99
|
+
validateAppOperations,
|
|
100
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Which connector header, query entry or token-request extra is a credential:
|
|
4
|
+
// the ONE decision, read by the SDK template validator (a manifest never ships
|
|
5
|
+
// one), the backend's save, copy and redaction paths, and the bundle snapshot
|
|
6
|
+
// (sc-12193, sc-17424, sc-17829).
|
|
7
|
+
|
|
8
|
+
/** A key needs this many characters before its shape alone marks it a key. */
|
|
9
|
+
const KEY_SHAPED_MIN_LENGTH = 8;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A value shaped like a key: 8+ characters, no whitespace, letters and
|
|
13
|
+
* digits. Words, flags, versions and codes fail it, so they stay readable.
|
|
14
|
+
* @param {unknown} value
|
|
15
|
+
* @returns {boolean}
|
|
16
|
+
*/
|
|
17
|
+
function isKeyShaped(value) {
|
|
18
|
+
return (
|
|
19
|
+
typeof value === "string" &&
|
|
20
|
+
value.length >= KEY_SHAPED_MIN_LENGTH &&
|
|
21
|
+
!/\s/.test(value) &&
|
|
22
|
+
/\d/.test(value) &&
|
|
23
|
+
/[A-Za-z]/.test(value)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const SENSITIVE_NAME_WORDS = [
|
|
28
|
+
"key", "secret", "token", "auth", "password", "pwd", "signature", "bearer", "subscription", "credential", "session",
|
|
29
|
+
"cookie",
|
|
30
|
+
];
|
|
31
|
+
// Prefix only: `passwd`, `passphrase`; never `passenger` or `passport`.
|
|
32
|
+
const SENSITIVE_NAME_PREFIXES = ["passw", "passphrase"];
|
|
33
|
+
// Whole segments only: `X-Pass`, `X-Sig`; never `signup`, `signal` or `bypass`.
|
|
34
|
+
const SENSITIVE_NAME_SEGMENTS = new Set(["pass", "sig"]);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A header or parameter name that reads as a credential. By segment, so
|
|
38
|
+
* `Ocp-Apim-Subscription-Key`, `apiKey` and `access_token` match while `Accept`
|
|
39
|
+
* and `Content-Type` do not; a word may lead or end a segment (`Authorization`).
|
|
40
|
+
* @param {string} name
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
function hasSensitiveName(name) {
|
|
44
|
+
const segments = name.replace(/([a-z\d])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z\d]+/);
|
|
45
|
+
return segments.some(
|
|
46
|
+
(segment) =>
|
|
47
|
+
SENSITIVE_NAME_SEGMENTS.has(segment) ||
|
|
48
|
+
SENSITIVE_NAME_PREFIXES.some((prefix) => segment.startsWith(prefix)) ||
|
|
49
|
+
SENSITIVE_NAME_WORDS.some((word) => segment.startsWith(word) || segment.endsWith(word)),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Negotiation and client headers: their values never authenticate, so only a name match counts.
|
|
54
|
+
const NON_SECRET_HEADER_NAMES = new Set([
|
|
55
|
+
"accept", "accept-encoding", "accept-language", "cache-control", "content-language", "content-type", "user-agent",
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
// An auth scheme says the rest is a credential, whatever its letters.
|
|
59
|
+
const AUTH_SCHEME = /^(?:bearer|basic|token|apikey)\s+(\S+)$/i;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether an entry is a credential: one marked secret always is, otherwise its
|
|
63
|
+
* name, an auth scheme before 8+ characters, or its shape decides.
|
|
64
|
+
* @param {string} name
|
|
65
|
+
* @param {unknown} value
|
|
66
|
+
* @param {boolean} [markedSecret]
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
function isCredentialEntry(name, value, markedSecret = false) {
|
|
70
|
+
if (typeof value !== "string") return false;
|
|
71
|
+
if (markedSecret || hasSensitiveName(name)) return true;
|
|
72
|
+
if (NON_SECRET_HEADER_NAMES.has(name.toLowerCase())) return false;
|
|
73
|
+
const scheme = AUTH_SCHEME.exec(value.trim());
|
|
74
|
+
return scheme ? scheme[1].length >= KEY_SHAPED_MIN_LENGTH : isKeyShaped(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = { isKeyShaped, hasSensitiveName, isCredentialEntry };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "The connectorTemplates contract shared by Actions and widgets: the REST connectors a manifest ships prefilled and an install provisions. The one source, vendored into @colixsystems/action-sdk and @colixsystems/widget-sdk at build time and read by the backend and the Studio directly.",
|
|
3
|
+
"connectorTemplatesMax": 4,
|
|
4
|
+
"connectorAuthTypes": [
|
|
5
|
+
"none",
|
|
6
|
+
"bearer",
|
|
7
|
+
"basic",
|
|
8
|
+
"apiKey",
|
|
9
|
+
"oauth2_client_credentials",
|
|
10
|
+
"oauth2_authorization_code"
|
|
11
|
+
],
|
|
12
|
+
"_connectorFieldsComment": "connectorSecretFields are the authConfig keys a MANIFEST may never carry — credential material shipped to every workspace. connectorOperatorFields are the keys the installing workspace must supply before the connector can be called; the secret keys are a subset. One source, read by the SDK validator and by the backend's readiness check.",
|
|
13
|
+
"connectorSecretFields": {
|
|
14
|
+
"bearer": ["token"],
|
|
15
|
+
"basic": ["password"],
|
|
16
|
+
"apiKey": ["value"],
|
|
17
|
+
"oauth2_client_credentials": ["client_secret", "private_key_pem"],
|
|
18
|
+
"oauth2_authorization_code": ["client_secret", "private_key_pem"]
|
|
19
|
+
},
|
|
20
|
+
"connectorOperatorFields": {
|
|
21
|
+
"bearer": ["token"],
|
|
22
|
+
"basic": ["username", "password"],
|
|
23
|
+
"apiKey": ["value"],
|
|
24
|
+
"oauth2_client_credentials": ["client_id", "client_secret"],
|
|
25
|
+
"oauth2_authorization_code": ["client_id", "client_secret"]
|
|
26
|
+
},
|
|
27
|
+
"_connectorGrantTypeComment": "Which grant a client-credentials connector requests. Our token request is grant-AGNOSTIC — it posts grant_type plus scope/audience/extra params and the client's credentials — so a vendor grant (idha's `service`, `delegation`) needs no code, and enumerating known vendors would mean a deploy per IdP. This is a HYGIENE guard, not a security control: the request is entirely operator-authored, so a grant we fail to refuse only earns an IdP rejection. What IS refused is a grant needing a per-request credential this mint does not produce — a code, a refresh token, a subject assertion, a backchannel id — because token_extra_params holds only STATIC strings, so such a grant would save cleanly, work once at best, and then fail opaquely forever. `password` is refused for a different reason: ROPC is removed in OAuth 2.1 and token_extra_params is NOT masked on read, so the user's password would be readable by every workspace admin.",
|
|
28
|
+
"connectorDefaultGrantType": "client_credentials",
|
|
29
|
+
"connectorUnbuildableGrantTypes": [
|
|
30
|
+
"authorization_code",
|
|
31
|
+
"refresh_token",
|
|
32
|
+
"password",
|
|
33
|
+
"implicit",
|
|
34
|
+
"urn:ietf:params:oauth:grant-type:device_code",
|
|
35
|
+
"urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
36
|
+
"urn:ietf:params:oauth:grant-type:saml2-bearer",
|
|
37
|
+
"urn:ietf:params:oauth:grant-type:token-exchange",
|
|
38
|
+
"urn:openid:params:grant-type:ciba"
|
|
39
|
+
],
|
|
40
|
+
"_connectorTokenAuthMethodsComment": "How a connector's client authenticates at the token endpoint. The ONE list, read by this SDK's template validator and by the backend's client-assertion module that applies them, so a method can never be accepted by one and unimplemented by the other.",
|
|
41
|
+
"connectorTokenAuthMethods": ["basic", "body", "private_key_jwt"],
|
|
42
|
+
"_connectorOperatorFieldsByAuthMethodComment": "A token_auth_method that changes WHICH credential the workspace owes. private_key_jwt (RFC 7523 §2.2) authenticates with a signed assertion, so it needs the signing key instead of a shared secret — otherwise the readiness check would demand a client_secret such a connector must never have.",
|
|
43
|
+
"connectorOperatorFieldsByAuthMethod": {
|
|
44
|
+
"private_key_jwt": {
|
|
45
|
+
"oauth2_client_credentials": ["client_id", "private_key_pem"],
|
|
46
|
+
"oauth2_authorization_code": ["client_id", "private_key_pem"]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"_connectorTemplateFormatComment": "The shape of a connectorTemplates entry an Action author writes, and the SINGLE source for it: the SDK's template validator reads the fields, the key pattern, the limits and the authConfig keys allowed per auth type, and the Actions agent's prompt renders the same data, so a field the validator accepts is a field the agent is told about. A key in connectorAuthConfigKeys that connectorWorkspaceOwnedFields also names (a client_id, a basic username) is validated but stripped at provisioning: it is the installing workspace's to supply.",
|
|
50
|
+
"connectorTemplateKeyPattern": "^[a-z][a-z0-9_-]{0,63}$",
|
|
51
|
+
"connectorTemplateNameMaxLength": 120,
|
|
52
|
+
"connectorTemplateDescriptionMaxLength": 400,
|
|
53
|
+
"connectorTemplateMaxHeaders": 16,
|
|
54
|
+
"_connectorReservedTokenParamsComment": "Parameter names the token request itself owns: the grant's own fields and the client's credentials. A token_extra_params entry may never carry one, since it would displace the grant or the authentication rather than add to it. The SDK validator refuses them at publish and the backend refuses them on save and skips them on the request.",
|
|
55
|
+
"connectorReservedTokenParams": [
|
|
56
|
+
"grant_type",
|
|
57
|
+
"client_id",
|
|
58
|
+
"client_secret",
|
|
59
|
+
"client_assertion",
|
|
60
|
+
"client_assertion_type",
|
|
61
|
+
"scope",
|
|
62
|
+
"audience",
|
|
63
|
+
"code",
|
|
64
|
+
"redirect_uri",
|
|
65
|
+
"code_verifier",
|
|
66
|
+
"refresh_token"
|
|
67
|
+
],
|
|
68
|
+
"_connectorSecretTokenExtrasComment": "A token request header or parameter that carries a credential is declared SECRET by naming it in the list keyed here, never by a value: the list key maps to the map that carries the value. The manifest may name an entry only in the list, so a secret entry with a value is refused at publish. The installing workspace owes each one, readiness counts it as token_extra_headers.<name> / token_extra_params.<name>, and the backend stores the value encrypted and masks it on read.",
|
|
69
|
+
"connectorSecretTokenExtras": {
|
|
70
|
+
"secret_token_extra_headers": "token_extra_headers",
|
|
71
|
+
"secret_token_extra_params": "token_extra_params"
|
|
72
|
+
},
|
|
73
|
+
"connectorTemplateFields": [
|
|
74
|
+
{
|
|
75
|
+
"name": "key",
|
|
76
|
+
"type": "string",
|
|
77
|
+
"required": true,
|
|
78
|
+
"description": "The connector's stable id within the manifest, unique among its templates. The workspace's connector is matched on it at every reinstall and upgrade, so keep it unchanged once installed. An Action's script calls the connector by it, `connectors.call(\"<key>\", …)`; a widget's connectorRef property names it in `template`."
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"name": "name",
|
|
82
|
+
"type": "string",
|
|
83
|
+
"required": true,
|
|
84
|
+
"description": "The connector's name in the workspace. The operator may rename it."
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"name": "baseUrl",
|
|
88
|
+
"type": "string",
|
|
89
|
+
"required": true,
|
|
90
|
+
"description": "The absolute http(s) URL each call's relative `path` is joined to, e.g. https://api.example.com/v1."
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"name": "authType",
|
|
94
|
+
"type": "string",
|
|
95
|
+
"required": false,
|
|
96
|
+
"description": "How calls authenticate. Defaults to \"none\"."
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"name": "authConfig",
|
|
100
|
+
"type": "object",
|
|
101
|
+
"required": false,
|
|
102
|
+
"description": "The non-secret auth settings, using only the keys allowed for the authType. Never a credential."
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "defaultHeaders",
|
|
106
|
+
"type": "object",
|
|
107
|
+
"required": false,
|
|
108
|
+
"description": "Header name to string value, sent on every call. Never a credential: a header whose name or value reads as one (Authorization, X-Api-Key, a bearer token, a key-shaped value) is refused at publish; send a key with authType apiKey instead."
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"name": "description",
|
|
112
|
+
"type": "string",
|
|
113
|
+
"required": false,
|
|
114
|
+
"description": "Why the Action or widget needs this connector, shown to the operator."
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"name": "appOperations",
|
|
118
|
+
"type": "array",
|
|
119
|
+
"required": false,
|
|
120
|
+
"description": "Widget templates only, and required there: the operations the widget calls with useConnector(connectorId).call(\"<operation key>\", ...), each { key, method, path, query?, body? }. The connector is provisioned app-callable with exactly these operations. A path placeholder such as {id} fills one whole segment. An Action template may not declare it."
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"connectorAuthConfigKeys": {
|
|
124
|
+
"none": [],
|
|
125
|
+
"bearer": [],
|
|
126
|
+
"basic": ["username"],
|
|
127
|
+
"apiKey": ["header_name"],
|
|
128
|
+
"oauth2_client_credentials": [
|
|
129
|
+
"token_url",
|
|
130
|
+
"client_id",
|
|
131
|
+
"scope",
|
|
132
|
+
"audience",
|
|
133
|
+
"grant_type",
|
|
134
|
+
"token_auth_method",
|
|
135
|
+
"assertion_audience",
|
|
136
|
+
"assertion_kid",
|
|
137
|
+
"token_extra_headers",
|
|
138
|
+
"token_extra_params",
|
|
139
|
+
"secret_token_extra_headers",
|
|
140
|
+
"secret_token_extra_params"
|
|
141
|
+
],
|
|
142
|
+
"oauth2_authorization_code": [
|
|
143
|
+
"authorize_url",
|
|
144
|
+
"token_url",
|
|
145
|
+
"client_id",
|
|
146
|
+
"scope",
|
|
147
|
+
"pkce",
|
|
148
|
+
"provider_id",
|
|
149
|
+
"token_auth_method",
|
|
150
|
+
"assertion_audience",
|
|
151
|
+
"assertion_kid",
|
|
152
|
+
"token_extra_headers",
|
|
153
|
+
"token_extra_params",
|
|
154
|
+
"secret_token_extra_headers",
|
|
155
|
+
"secret_token_extra_params",
|
|
156
|
+
"post_consent_mint",
|
|
157
|
+
"account_id_source"
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
"connectorAuthConfigKeyMeanings": {
|
|
161
|
+
"username": "the account name the workspace signs in with",
|
|
162
|
+
"header_name": "the header the API key is sent in, e.g. X-Api-Key",
|
|
163
|
+
"token_url": "the OAuth token endpoint, an absolute http(s) URL; required",
|
|
164
|
+
"authorize_url": "the OAuth consent page, an absolute http(s) URL; required",
|
|
165
|
+
"client_id": "the OAuth client id the workspace registered",
|
|
166
|
+
"scope": "the scope string sent in the token request, exactly as the API documents it",
|
|
167
|
+
"audience": "the audience parameter some token endpoints require",
|
|
168
|
+
"grant_type": "the grant the token request asks for",
|
|
169
|
+
"token_auth_method": "how the client authenticates at the token endpoint",
|
|
170
|
+
"assertion_audience": "private_key_jwt only, and required there: the provider's issuer the signed assertion is addressed to",
|
|
171
|
+
"assertion_kid": "private_key_jwt only: the key id the provider registered for the signing key",
|
|
172
|
+
"token_extra_headers": "header name to fixed non-secret string value, sent on the token request only, never on API calls; stored and shown in the clear, so a credential goes in secret_token_extra_headers instead",
|
|
173
|
+
"token_extra_params": "parameter name to fixed non-secret string value, added to the token request; stored and shown in the clear, so a credential goes in secret_token_extra_params instead",
|
|
174
|
+
"secret_token_extra_headers": "names of token request headers that carry a credential, such as a subscription key: list the names only, never a value; the workspace enters each value on the connector, where it is stored encrypted and shown masked",
|
|
175
|
+
"secret_token_extra_params": "names of token request parameters that carry a credential: list the names only, never a value; the workspace enters each value on the connector, where it is stored encrypted and shown masked",
|
|
176
|
+
"pkce": "\"S256\" or \"none\"",
|
|
177
|
+
"provider_id": "a provider from the platform's connector catalog; leave it out for any other API",
|
|
178
|
+
"post_consent_mint": "how the connector renews after consent: \"refresh_token\" or \"client_credentials\"",
|
|
179
|
+
"account_id_source": "where the provider's account id is read: \"none\", \"token_response:<field>\" or \"jwt_claim:<claim>\"; required when post_consent_mint is \"client_credentials\""
|
|
180
|
+
},
|
|
181
|
+
"_connectorAppOperationsComment": "The operations an app widget may call on an app-callable connector. The ONE rule, read by the SDK template validator, the publish analyzer and the backend's connector save path (connector-app-operations.cjs).",
|
|
182
|
+
"connectorAppOperationMethods": ["GET", "POST", "PUT", "PATCH", "DELETE"],
|
|
183
|
+
"connectorAppOperationsMax": 50,
|
|
184
|
+
"connectorWidgetTemplateExample": "[{ \"key\": \"weather\", \"name\": \"Weather API\", \"baseUrl\": \"https://api.example.com/v1\", \"authType\": \"apiKey\", \"authConfig\": { \"header_name\": \"X-Api-Key\" }, \"appOperations\": [{ \"key\": \"forecast\", \"method\": \"GET\", \"path\": \"/forecast/{city}\", \"query\": [\"days\"] }, { \"key\": \"alerts\", \"method\": \"GET\", \"path\": \"/alerts\" }], \"description\": \"Shows the forecast for the chosen city.\" }]",
|
|
185
|
+
"connectorTemplateExample": "[{ \"key\": \"invoicing\", \"name\": \"Invoicing API\", \"baseUrl\": \"https://api.example.com/v1\", \"authType\": \"oauth2_client_credentials\", \"authConfig\": { \"token_url\": \"https://identity.example.com/connect/token\", \"scope\": \"invoices:read\", \"token_extra_params\": { \"grant_mode\": \"service\" }, \"secret_token_extra_headers\": [\"Ocp-Apim-Subscription-Key\"] }, \"defaultHeaders\": { \"Accept\": \"application/json\" }, \"description\": \"Reads invoices every night.\" }]"
|
|
186
|
+
}
|