@get-enlace/express 0.0.1

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,23 @@
1
+ import express from 'express';
2
+ import { type SpecSource } from './specLoader.js';
3
+ export interface EnlaceOptions {
4
+ /** A file/URL path or an already-parsed object — the only input this needs is a valid OpenAPI 3.x document, however it's produced or served. */
5
+ spec: SpecSource;
6
+ }
7
+ /**
8
+ * Mounts the Enlace canvas.
9
+ *
10
+ * app.use('/enlace', enlace({ spec }))
11
+ *
12
+ * This adapter's job is deliberately small — per ARCHITECTURE.md's MVP
13
+ * model, execution runs entirely client-side in @get-enlace/ui, so there's
14
+ * no `/api/run` or `/api/credentials` here at all. All this does is:
15
+ * - serve the raw OpenAPI document (parsed into an Operation[] list
16
+ * client-side, not here — see @get-enlace/ui's engine/specParser.ts)
17
+ * - serve the built UI bundle
18
+ *
19
+ * This package is testing/dev scaffolding for this repo right now — it's
20
+ * destined for extraction into a separate `enlace-js` monorepo (alongside
21
+ * enlace-nest, enlace-fastify, etc.) once that split is real.
22
+ */
23
+ export declare function enlace(options: EnlaceOptions): express.Router;
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ import express from 'express';
2
+ import path from 'node:path';
3
+ import { createRequire } from 'node:module';
4
+ import { loadSpec } from './specLoader.js';
5
+ const require = createRequire(import.meta.url);
6
+ /**
7
+ * Mounts the Enlace canvas.
8
+ *
9
+ * app.use('/enlace', enlace({ spec }))
10
+ *
11
+ * This adapter's job is deliberately small — per ARCHITECTURE.md's MVP
12
+ * model, execution runs entirely client-side in @get-enlace/ui, so there's
13
+ * no `/api/run` or `/api/credentials` here at all. All this does is:
14
+ * - serve the raw OpenAPI document (parsed into an Operation[] list
15
+ * client-side, not here — see @get-enlace/ui's engine/specParser.ts)
16
+ * - serve the built UI bundle
17
+ *
18
+ * This package is testing/dev scaffolding for this repo right now — it's
19
+ * destined for extraction into a separate `enlace-js` monorepo (alongside
20
+ * enlace-nest, enlace-fastify, etc.) once that split is real.
21
+ */
22
+ export function enlace(options) {
23
+ const router = express.Router();
24
+ // Read fresh on each request, not cached — matches the "not stored, read
25
+ // fresh each load" rule from ARCHITECTURE.md §4.
26
+ router.get('/api/spec', (_req, res) => {
27
+ res.json(loadSpec(options.spec));
28
+ });
29
+ // Static canvas UI bundle. Resolved via Node's own module resolution
30
+ // against the installed `@get-enlace/ui` package (a real dependency, see
31
+ // package.json) — not a relative path into this monorepo — so this works
32
+ // identically whether `@get-enlace/ui` got here via an npm workspace
33
+ // symlink (local dev) or a real `node_modules` install (anyone who
34
+ // installs @get-enlace/express on its own). There's nothing to copy or
35
+ // build into this package itself; the bundle lives wherever
36
+ // @get-enlace/ui's own "files" field ships it (dist/), and it must
37
+ // already be built (`npm run build --workspace @get-enlace/ui`) before
38
+ // this resolves.
39
+ const uiPackageJson = require.resolve('@get-enlace/ui/package.json');
40
+ const uiDist = path.join(path.dirname(uiPackageJson), 'dist');
41
+ router.use(express.static(uiDist));
42
+ return router;
43
+ }
@@ -0,0 +1,6 @@
1
+ export type SpecSource = string | Record<string, any>;
2
+ /**
3
+ * Reads an OpenAPI 3.x document from a file/URL path or accepts an already-
4
+ * parsed object directly.
5
+ */
6
+ export declare function loadSpec(source: SpecSource): Record<string, any>;
@@ -0,0 +1,17 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { extname } from 'node:path';
3
+ import yaml from 'js-yaml';
4
+ /**
5
+ * Reads an OpenAPI 3.x document from a file/URL path or accepts an already-
6
+ * parsed object directly.
7
+ */
8
+ export function loadSpec(source) {
9
+ if (typeof source !== 'string')
10
+ return source;
11
+ const raw = readFileSync(source, 'utf-8');
12
+ const ext = extname(source);
13
+ if (ext === '.yaml' || ext === '.yml') {
14
+ return yaml.load(raw);
15
+ }
16
+ return JSON.parse(raw);
17
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@get-enlace/express",
3
+ "private": false,
4
+ "version": "0.0.1",
5
+ "description": "Simple Express adapter for @get-enlace/ui. Early dev preview: no persistence yet (serves the spec + UI bundle only), install via the `dev` dist-tag on GitHub Packages.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/get-enlace/enlace-js.git",
10
+ "directory": "packages/enlace-express"
11
+ },
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "publishConfig": {
25
+ "registry": "https://npm.pkg.github.com"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc -p tsconfig.json",
29
+ "typecheck": "tsc -p tsconfig.json --noEmit",
30
+ "test": "vitest run"
31
+ },
32
+ "peerDependencies": {
33
+ "express": "^4.17.0 || ^5.0.0"
34
+ },
35
+ "dependencies": {
36
+ "@get-enlace/ui": "0.0.1",
37
+ "js-yaml": "^4.1.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/express": "^4.17.21",
41
+ "@types/js-yaml": "^4.0.9",
42
+ "@types/node": "^20.14.0",
43
+ "@types/supertest": "^7.2.1",
44
+ "express": "^4.19.2",
45
+ "supertest": "^7.2.2",
46
+ "typescript": "^5.5.4",
47
+ "vitest": "^4.1.11"
48
+ }
49
+ }