@ekanos/sdk 0.1.1 → 0.1.2

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 (2) hide show
  1. package/eslint.preset.mjs +375 -0
  2. package/package.json +9 -7
@@ -0,0 +1,375 @@
1
+ /**
2
+ * @ekanos/sdk/eslint — the capability ESLint preset ("R5").
3
+ *
4
+ * This is a SECURITY CONTROL, not a style preset. Partner integration code
5
+ * runs UNSANDBOXED, in-process, inside the host: the generated
6
+ * `partner-integration-bootstrap.ts` statically imports each partner package,
7
+ * so a partner module graph evaluates with full host authority before any
8
+ * validation runs (see the "Trust model (F1, accepted T1)" header in
9
+ * `apps/web/scripts/generate-partner-integration-bootstrap.ts`).
10
+ *
11
+ * The accepted T1 trust tier rests on exactly two controls:
12
+ *
13
+ * 1. the promotion gate — a human reads the SOURCE before it is built, and
14
+ * 2. THIS PRESET — which bans the escapes that route around the capability
15
+ * layer, so "reads the source" is a tractable review rather than an
16
+ * invitation to spot `globalThis.fetch` by eye.
17
+ *
18
+ * Runtime SANDBOXING of handlers is the deferred T3 tier. Until it exists,
19
+ * every rule below is load-bearing. Docs: `docs/devex/sdk-export-map.md`
20
+ * (review outcome F1), `docs/devex/adversarial-review-2026-08-30.md`.
21
+ *
22
+ * ── Why it lives here ────────────────────────────────────────────────────
23
+ * A partner already installs `@ekanos/sdk`, so the control ships with the
24
+ * surface it protects and versions in lockstep with it: the day `ctx.fetch`
25
+ * grows a documented client-side twin, the fetch rule relaxes in the same
26
+ * release. It is dependency-free — every rule below is core ESLint — so it
27
+ * adds nothing to the SDK's build, `api-report`, or `pack:test`.
28
+ *
29
+ * ── Usage (a partner's eslint.config.mjs) ────────────────────────────────
30
+ *
31
+ * import capabilityPreset from '@ekanos/sdk/eslint';
32
+ *
33
+ * export default [
34
+ * ...someBaseConfig,
35
+ * ...capabilityPreset,
36
+ * ];
37
+ *
38
+ * ── Inline disables do not work, by design ───────────────────────────────
39
+ * The preset sets `linterOptions.noInlineConfig` over the source glob, so
40
+ * `// eslint-disable-next-line` cannot silence these rules from partner
41
+ * source — otherwise the control would be opt-out by the very code it
42
+ * constrains. A genuine exception must be a FILE-SCOPED OVERRIDE in the
43
+ * package's own `eslint.config.mjs`, where a reviewer reads it. Both
44
+ * exceptions currently granted in this repo live in the example packages'
45
+ * configs and are recorded there with the reason.
46
+ */
47
+
48
+ /**
49
+ * Glob for partner integration SOURCE. Build tooling — `vitest.config.ts`,
50
+ * `eslint.config.mjs`, `tsup.config.ts` — is deliberately OUT of scope: it
51
+ * runs on the partner's build machine, never in the host process, and it
52
+ * legitimately imports `node:path`/`node:url`. Narrowing the preset to source
53
+ * is what keeps it free of the false positives that get a control disabled.
54
+ */
55
+ const SOURCE_GLOB = ['src/**/*.ts', 'src/**/*.tsx'];
56
+
57
+ const CTX_FETCH_REMEDIATION =
58
+ 'Use `ctx.fetch` from the capability context (`IntegrationContext`) instead, ' +
59
+ "and declare every origin you call in your integration's `egress` " +
60
+ 'allowlist — `defineIntegration({ egress: [...] })`. `ctx.fetch` refuses an ' +
61
+ 'undeclared origin before any I/O, re-checks every redirect hop, and pins ' +
62
+ 'the vetted IP addresses so an allowlisted hostname cannot be rebound to a ' +
63
+ 'host-internal address. A global fetch has none of that, so it is an egress ' +
64
+ 'bypass. Widening `egress` is a reviewed security-posture change, not a ' +
65
+ 'config tweak.';
66
+
67
+ const CTX_SECRETS_REMEDIATION =
68
+ 'Use `ctx.secrets.get(name)` from the capability context instead, and ' +
69
+ "declare the credential in your integration's activation schema. The host " +
70
+ "process environment holds the platform's own credentials — it is not your " +
71
+ 'configuration store, and reading it is how an integration gets a secret it ' +
72
+ 'was never granted.';
73
+
74
+ /**
75
+ * Node builtins a partner integration must never reach, each with the
76
+ * capability that replaces it. Every entry is listed twice — bare and
77
+ * `node:`-prefixed — because both resolve.
78
+ *
79
+ * This is an explicit list rather than a blanket `node:*` ban on purpose: the
80
+ * SDK surface is isomorphic, and `node:crypto`/`node:url`-shaped imports are
81
+ * neither an escape nor worth training a partner to reach for a disable
82
+ * comment over. The generic escape hatch — a computed dynamic `import()` — is
83
+ * closed separately in `no-restricted-syntax` below, so the list cannot be
84
+ * routed around by building the specifier at runtime.
85
+ */
86
+ const BANNED_MODULES = [
87
+ {
88
+ names: ['fs', 'node:fs', 'fs/promises', 'node:fs/promises'],
89
+ message:
90
+ 'The host filesystem is not part of the capability surface. Use ' +
91
+ '`ctx.storage.account` / `ctx.storage.user` for integration state — it ' +
92
+ 'is scoped to the account the request is authorized for, quota-bounded, ' +
93
+ 'and schema-validated. Filesystem access reads and writes host state ' +
94
+ 'that no account owns.',
95
+ },
96
+ {
97
+ names: ['child_process', 'node:child_process'],
98
+ message:
99
+ 'Spawning a process escapes every capability control at once. There is ' +
100
+ 'no replacement: an integration is data-in / data-out. If you need work ' +
101
+ "the SDK cannot express, raise it as an SDK gap in your integration's " +
102
+ 'README rather than shelling out.',
103
+ },
104
+ {
105
+ names: [
106
+ 'net',
107
+ 'node:net',
108
+ 'tls',
109
+ 'node:tls',
110
+ 'dgram',
111
+ 'node:dgram',
112
+ 'http',
113
+ 'node:http',
114
+ 'https',
115
+ 'node:https',
116
+ 'http2',
117
+ 'node:http2',
118
+ ],
119
+ message:
120
+ 'Raw sockets and the `http`/`https` clients bypass the egress allowlist ' +
121
+ 'and its address guard entirely. ' +
122
+ CTX_FETCH_REMEDIATION,
123
+ },
124
+ {
125
+ names: ['dns', 'node:dns', 'dns/promises', 'node:dns/promises'],
126
+ message:
127
+ 'Resolving hostnames yourself is the first half of a DNS-rebinding ' +
128
+ 'egress bypass — `ctx.fetch` resolves ONCE and pins the vetted ' +
129
+ 'addresses precisely so that a name cannot resolve differently between ' +
130
+ 'the check and the connection. ' +
131
+ CTX_FETCH_REMEDIATION,
132
+ },
133
+ {
134
+ names: ['worker_threads', 'node:worker_threads'],
135
+ message:
136
+ 'A worker thread runs on a path where the capability context does not ' +
137
+ 'exist, so nothing inside it can reach `ctx.fetch`, `ctx.secrets` or ' +
138
+ '`ctx.storage`. Do the work in the handler, with `ctx`, and let the ' +
139
+ 'host own concurrency — batch or paginate rather than fanning out.',
140
+ },
141
+ {
142
+ names: ['vm', 'node:vm'],
143
+ message:
144
+ '`vm` executes code from a string, which makes the source a reviewer ' +
145
+ 'reads no longer the code that runs — the assumption the T1 trust tier ' +
146
+ 'is built on. Write the logic as source.',
147
+ },
148
+ {
149
+ names: ['module', 'node:module'],
150
+ message:
151
+ '`node:module` (`createRequire`) is a loader escape hatch: it resolves ' +
152
+ 'modules this preset bans by name at runtime. Use a static `import` of ' +
153
+ 'a package you declare in `dependencies`.',
154
+ },
155
+ {
156
+ names: ['process', 'node:process'],
157
+ message:
158
+ 'Importing `process` reaches the host environment. ' +
159
+ CTX_SECRETS_REMEDIATION,
160
+ },
161
+ {
162
+ names: ['os', 'node:os'],
163
+ message:
164
+ '`node:os` reports the host machine — hostname, users, network ' +
165
+ 'interfaces, home directories. None of it describes the account your ' +
166
+ 'integration is running for, and all of it is host reconnaissance. ' +
167
+ 'Read what you need from the capability context instead: ' +
168
+ '`ctx.accountId` for who this run is for, `ctx.storage` for state you ' +
169
+ 'persisted, `ctx.logger` for diagnostics.',
170
+ },
171
+ {
172
+ names: ['undici', 'node-fetch', 'axios', 'got', 'superagent', 'request'],
173
+ message:
174
+ 'A third-party HTTP client issues requests the egress allowlist never ' +
175
+ 'sees, which is the same bypass as a global `fetch` with an extra ' +
176
+ 'dependency. ' +
177
+ CTX_FETCH_REMEDIATION,
178
+ },
179
+ {
180
+ names: ['react-i18next'],
181
+ importNames: ['Trans'],
182
+ message:
183
+ 'Use `Trans` from `@ekanos/ui/trans` instead — it is wired to the ' +
184
+ "host's i18n instance, so your strings resolve against the same " +
185
+ 'namespaces and language the surrounding page already loaded.',
186
+ },
187
+ ];
188
+
189
+ /** Globals that reach the network without passing through `ctx.fetch`. */
190
+ const EGRESS_GLOBALS = ['fetch', 'XMLHttpRequest', 'WebSocket', 'EventSource'];
191
+
192
+ /** Objects a `globalThis.fetch`-style member access can hide behind. */
193
+ const GLOBAL_OBJECTS = 'globalThis|window|self|global';
194
+
195
+ /** Members of those objects that are the very escapes banned as bare globals. */
196
+ const GLOBAL_ESCAPE_MEMBERS =
197
+ 'fetch|XMLHttpRequest|WebSocket|EventSource|process|eval|require|Function';
198
+
199
+ /**
200
+ * `@kit/*` is checked with a PATTERN rather than a path so every subpath is
201
+ * covered (`@kit/ui/badge`, `@kit/next/actions`, …). This is the rule that
202
+ * catches, at lint time in the partner's own editor, the failure that
203
+ * otherwise surfaces as an unresolvable module at install time — which is
204
+ * exactly how our own reference example turned out to be unbuildable outside
205
+ * the monorepo.
206
+ */
207
+ const KIT_PATTERN = {
208
+ group: ['@kit/*', '@kit/*/**'],
209
+ message:
210
+ '`@kit/*` packages are workspace-internal to the Fusion monorepo and do ' +
211
+ 'not exist on any registry, so this import cannot resolve for anyone ' +
212
+ 'outside it — including in the clean-room build your submission is gated ' +
213
+ 'on. Import UI primitives from `@ekanos/ui/*` (badge, button, card, form, ' +
214
+ 'input, select, icon, utils, …), integration surfaces from `@ekanos/sdk` ' +
215
+ 'and its `/components`, `/hooks`, `/mcp`, `/context`, `/integration` ' +
216
+ 'entrypoints, and nothing else from the host.',
217
+ };
218
+
219
+ const SUPABASE_PATTERN = {
220
+ group: ['@supabase/*', '@supabase/*/**'],
221
+ message:
222
+ 'A direct Supabase client talks to the database with whatever key it is ' +
223
+ 'given, outside the account scoping and RLS the host applies for you. Use ' +
224
+ '`ctx.storage.account` / `ctx.storage.user` for integration state — ' +
225
+ 'authorized for the account in the request and validated against your ' +
226
+ 'declared schema.',
227
+ };
228
+
229
+ /** Flattens BANNED_MODULES into `no-restricted-imports` `paths` entries. */
230
+ function bannedPaths() {
231
+ return BANNED_MODULES.flatMap((entry) =>
232
+ entry.names.map((name) => ({
233
+ name,
234
+ message: entry.message,
235
+ ...(entry.importNames ? { importNames: entry.importNames } : {}),
236
+ })),
237
+ );
238
+ }
239
+
240
+ /**
241
+ * The rules, exported separately so a consumer can compose them into its own
242
+ * config block (a different `files` glob, say) without re-deriving them.
243
+ */
244
+ export const capabilityRules = {
245
+ /**
246
+ * Bare global references only. ESLint resolves scope first, so a parameter
247
+ * or local named `fetch` — the SDK's own `IntegrationFetch` injection
248
+ * pattern, `getJson(fetch, url)` — is NOT reported. That is the intended
249
+ * shape: pass the mediated fetch in as a value.
250
+ */
251
+ 'no-restricted-globals': [
252
+ 'error',
253
+ ...EGRESS_GLOBALS.map((name) => ({
254
+ name,
255
+ message: `\`${name}\` reaches the network outside the capability layer. ${CTX_FETCH_REMEDIATION}`,
256
+ })),
257
+ {
258
+ name: 'process',
259
+ message: `\`process\` (including \`process.env\`) is host state, not integration state. ${CTX_SECRETS_REMEDIATION}`,
260
+ },
261
+ {
262
+ name: 'require',
263
+ message:
264
+ '`require` resolves modules at runtime, so no reviewer and no import ' +
265
+ 'rule can see what is actually loaded. Use a static `import` of a ' +
266
+ 'package declared in `dependencies`.',
267
+ },
268
+ {
269
+ name: 'eval',
270
+ message:
271
+ '`eval` runs code built at runtime, so the source a reviewer reads ' +
272
+ 'stops being the code that runs — and human review of source is half ' +
273
+ 'of what makes running your integration in-process acceptable. Write ' +
274
+ 'the logic as source.',
275
+ },
276
+ ],
277
+
278
+ 'no-restricted-imports': [
279
+ 'error',
280
+ { paths: bannedPaths(), patterns: [KIT_PATTERN, SUPABASE_PATTERN] },
281
+ ],
282
+
283
+ 'no-restricted-syntax': [
284
+ 'error',
285
+ {
286
+ // Closes the hole in no-restricted-globals: that rule resolves
287
+ // identifiers, so `globalThis.fetch` (a member access, not a global
288
+ // reference) is invisible to it.
289
+ selector: `MemberExpression[object.name=/^(${GLOBAL_OBJECTS})$/][property.name=/^(${GLOBAL_ESCAPE_MEMBERS})$/]`,
290
+ message:
291
+ 'Reaching an escape through the global object is the same bypass as ' +
292
+ 'naming it directly, and it is how a capability control gets routed ' +
293
+ 'around without tripping an import rule. Use the capability context: ' +
294
+ '`ctx.fetch` for network calls (with the origin declared in `egress`) ' +
295
+ 'and `ctx.secrets` for credentials.',
296
+ },
297
+ {
298
+ // Computed-string member access, e.g. `globalThis['fetch']`.
299
+ selector: `MemberExpression[computed=true][object.name=/^(${GLOBAL_OBJECTS})$/]`,
300
+ message:
301
+ 'Indexing the global object with a computed key hides which global is ' +
302
+ 'being reached, which defeats every rule in this preset. Reference ' +
303
+ 'what you need directly, through the capability context — `ctx.fetch` ' +
304
+ 'for network calls, `ctx.secrets` for credentials, `ctx.storage` for ' +
305
+ 'state.',
306
+ },
307
+ {
308
+ selector: 'NewExpression[callee.name="Function"]',
309
+ message:
310
+ '`new Function` compiles code from a string — the same problem as ' +
311
+ '`eval`: the source under review is no longer the code that runs. ' +
312
+ 'Write the logic as source.',
313
+ },
314
+ {
315
+ selector: 'CallExpression[callee.name="Function"]',
316
+ message:
317
+ '`Function(...)` compiles code from a string — the same problem as ' +
318
+ '`eval`: the source under review is no longer the code that runs. ' +
319
+ 'Write the logic as source.',
320
+ },
321
+ {
322
+ // The generic route around no-restricted-imports: build the specifier
323
+ // at runtime and the import rule has nothing to match.
324
+ selector: 'ImportExpression[source.type!="Literal"]',
325
+ message:
326
+ 'A dynamic `import()` with a computed specifier hides what is loaded ' +
327
+ 'from both the import rules and the human promotion review. Use a ' +
328
+ 'static `import`, or `import("literal-specifier")` if you genuinely ' +
329
+ 'need lazy loading.',
330
+ },
331
+ {
332
+ // `no-restricted-imports` does not inspect dynamic import specifiers,
333
+ // so the banned module list is re-applied to literal ones here.
334
+ selector:
335
+ 'ImportExpression[source.value=/^(node:)?(fs|child_process|net|tls|dgram|dns|http|https|http2|worker_threads|vm|module|process|os)$/]',
336
+ message:
337
+ 'This Node builtin is banned for integration code whether it is ' +
338
+ 'imported statically or dynamically — a dynamic `import()` of it is ' +
339
+ 'the same capability escape. See the static-import message for the ' +
340
+ 'capability that replaces it (`ctx.fetch`, `ctx.secrets`, ' +
341
+ '`ctx.storage`).',
342
+ },
343
+ {
344
+ // The `/promises` faces of the same builtins. Split out because a `/`
345
+ // cannot appear inside an esquery regex-literal attribute value.
346
+ selector:
347
+ 'ImportExpression[source.value=/^(node:)?(fs|dns)\\u002Fpromises$/]',
348
+ message:
349
+ 'This Node builtin is banned for integration code whether it is ' +
350
+ 'imported statically or dynamically. Use `ctx.storage` for state and ' +
351
+ '`ctx.fetch` for network calls.',
352
+ },
353
+ ],
354
+ };
355
+
356
+ /**
357
+ * The preset. Spread it AFTER any base config: it deliberately replaces a
358
+ * base `no-restricted-imports` / `no-restricted-globals` /
359
+ * `no-restricted-syntax` setting rather than merging with it (flat config does
360
+ * not merge rule options), and it re-states the one entry the Fusion base
361
+ * config carries — `react-i18next`'s `Trans` — in its partner-correct form.
362
+ */
363
+ export default [
364
+ {
365
+ name: '@ekanos/sdk/eslint:capabilities',
366
+ files: SOURCE_GLOB,
367
+ linterOptions: {
368
+ // A control the constrained code can switch off is not a control.
369
+ // Exceptions belong in the consumer's config, where review sees them.
370
+ // See the header.
371
+ noInlineConfig: true,
372
+ },
373
+ rules: capabilityRules,
374
+ },
375
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekanos/sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "The official SDK for building Ekanos integrations.",
6
6
  "license": "MIT",
@@ -13,7 +13,8 @@
13
13
  "files": [
14
14
  "dist",
15
15
  "README.md",
16
- "LICENSE"
16
+ "LICENSE",
17
+ "eslint.preset.mjs"
17
18
  ],
18
19
  "exports": {
19
20
  ".": {
@@ -43,7 +44,8 @@
43
44
  "./integration": {
44
45
  "types": "./dist/integration/index.d.ts",
45
46
  "default": "./dist/integration/index.js"
46
- }
47
+ },
48
+ "./eslint": "./eslint.preset.mjs"
47
49
  },
48
50
  "publishConfig": {
49
51
  "access": "public"
@@ -51,8 +53,8 @@
51
53
  "dependencies": {
52
54
  "@supabase/supabase-js": "2.87.1",
53
55
  "server-only": "^0.0.1",
54
- "@ekanos/integration-schema": "0.1.1",
55
- "@ekanos/ui": "0.1.1"
56
+ "@ekanos/integration-schema": "0.1.2",
57
+ "@ekanos/ui": "0.1.2"
56
58
  },
57
59
  "peerDependencies": {
58
60
  "@hookform/resolvers": "^5.2.2",
@@ -72,9 +74,9 @@
72
74
  "typescript": "^5.9.3",
73
75
  "vitest": "4.1.10",
74
76
  "zod": "^3.25.74",
75
- "@kit/eslint-config": "0.2.0",
76
77
  "@kit/prettier-config": "0.1.0",
77
- "@kit/tsconfig": "0.1.0"
78
+ "@kit/tsconfig": "0.1.0",
79
+ "@kit/eslint-config": "0.2.0"
78
80
  },
79
81
  "prettier": "@kit/prettier-config",
80
82
  "typesVersions": {