@emabuild/shared 0.0.0-stage → 0.1.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 +15 -2
- package/dist/css/css-safe.d.ts +11 -0
- package/dist/css/css-safe.d.ts.map +1 -0
- package/dist/css/css-safe.js +18 -0
- package/dist/css/css-safe.js.map +1 -0
- package/dist/design/body-meta.d.ts +18 -0
- package/dist/design/body-meta.d.ts.map +1 -0
- package/dist/design/body-meta.js +17 -0
- package/dist/design/body-meta.js.map +1 -0
- package/dist/design/rows.d.ts +5 -0
- package/dist/design/rows.d.ts.map +1 -0
- package/dist/design/rows.js +6 -0
- package/dist/design/rows.js.map +1 -0
- package/dist/http/cors.d.ts +15 -0
- package/dist/http/cors.d.ts.map +1 -0
- package/dist/http/cors.js +32 -0
- package/dist/http/cors.js.map +1 -0
- package/dist/http/node-handler.d.ts +16 -0
- package/dist/http/node-handler.d.ts.map +1 -0
- package/dist/http/node-handler.js +117 -0
- package/dist/http/node-handler.js.map +1 -0
- package/dist/images/openverse.d.ts +17 -0
- package/dist/images/openverse.d.ts.map +1 -0
- package/dist/images/openverse.js +48 -0
- package/dist/images/openverse.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +3 -0
- package/dist/node.js.map +1 -0
- package/package.json +42 -3
package/README.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @emabuild/shared
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Internal building blocks shared by the `@emabuild` packages. You normally get it as a dependency of
|
|
4
|
+
`@emabuild/core`, `@emabuild/email-renderer`, `@emabuild/ai` or `@emabuild/export` and do not install it
|
|
5
|
+
directly.
|
|
6
|
+
|
|
7
|
+
| Entry | Contents |
|
|
8
|
+
|---|---|
|
|
9
|
+
| `@emabuild/shared` | Isomorphic helpers: CSS value safety (`cleanCssValue`, `isSafeCssValue`), design metadata (`documentTitle`, `documentLanguage`, `bodyFontWeight`, `allRows`), free-image search (`searchOpenverse`) |
|
|
10
|
+
| `@emabuild/shared/node` | Node adapters: `toNodeHandler` (Fetch handler → Node / Express) and CORS headers |
|
|
11
|
+
|
|
12
|
+
The API follows the other `@emabuild` packages' versions but is not meant to be stable on its own.
|
|
13
|
+
|
|
14
|
+
## License
|
|
15
|
+
|
|
16
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module css-safe
|
|
3
|
+
* Values coming from designs end up inside CSS declarations: strip anything
|
|
4
|
+
* that could close the declaration or the rule (`;`, `{`, `}`), break out of a
|
|
5
|
+
* style attribute or tag (`"`, `<`, `>`) or force precedence (`!important`).
|
|
6
|
+
*/
|
|
7
|
+
/** Cleaned CSS value, or `null` when nothing usable is left */
|
|
8
|
+
export declare function cleanCssValue(value: unknown): string | null;
|
|
9
|
+
/** Whether a value can be used as-is (non-empty and needs no cleaning) */
|
|
10
|
+
export declare function isSafeCssValue(value: unknown): value is string;
|
|
11
|
+
//# sourceMappingURL=css-safe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-safe.d.ts","sourceRoot":"","sources":["../../src/css/css-safe.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAI3D;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module css-safe
|
|
3
|
+
* Values coming from designs end up inside CSS declarations: strip anything
|
|
4
|
+
* that could close the declaration or the rule (`;`, `{`, `}`), break out of a
|
|
5
|
+
* style attribute or tag (`"`, `<`, `>`) or force precedence (`!important`).
|
|
6
|
+
*/
|
|
7
|
+
/** Cleaned CSS value, or `null` when nothing usable is left */
|
|
8
|
+
export function cleanCssValue(value) {
|
|
9
|
+
if (typeof value !== 'string' && typeof value !== 'number')
|
|
10
|
+
return null;
|
|
11
|
+
const v = String(value).replace(/[;{}<>"]/g, '').replace(/!important/gi, '').trim();
|
|
12
|
+
return v || null;
|
|
13
|
+
}
|
|
14
|
+
/** Whether a value can be used as-is (non-empty and needs no cleaning) */
|
|
15
|
+
export function isSafeCssValue(value) {
|
|
16
|
+
return typeof value === 'string' && value.trim() !== '' && cleanCssValue(value) === value.trim();
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=css-safe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-safe.js","sourceRoot":"","sources":["../../src/css/css-safe.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+DAA+D;AAC/D,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACxE,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACpF,OAAO,CAAC,IAAI,IAAI,CAAC;AACnB,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,aAAa,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;AACnG,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module body-meta
|
|
3
|
+
* Document-level metadata read from `body.values`: title, language, font weight.
|
|
4
|
+
* Single source for the email shell, the web shell, the editor export and the
|
|
5
|
+
* headless renderer.
|
|
6
|
+
*/
|
|
7
|
+
import type { BodyValues } from '@emabuild/types';
|
|
8
|
+
type Body = Partial<BodyValues> | undefined;
|
|
9
|
+
/** BCP 47-like language code (`it`, `en-GB`, `zh-Hant`) */
|
|
10
|
+
export declare const isLanguageCode: (v: unknown) => v is string;
|
|
11
|
+
/** `<title>`: explicit export title, else `body.title`, else the subject */
|
|
12
|
+
export declare function documentTitle(body: Body, explicit?: string): string;
|
|
13
|
+
/** `<html lang>` value, or `''` when the design sets none (or an invalid one) */
|
|
14
|
+
export declare function documentLanguage(body: Body): string;
|
|
15
|
+
/** Body font weight as a CSS value (`400`, `bold`…), or `''` */
|
|
16
|
+
export declare function bodyFontWeight(body: Body): string;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=body-meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-meta.d.ts","sourceRoot":"","sources":["../../src/design/body-meta.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,KAAK,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,CAAC;AAG5C,2DAA2D;AAC3D,eAAO,MAAM,cAAc,GAAI,GAAG,OAAO,KAAG,CAAC,IAAI,MAA6E,CAAC;AAE/H,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEnD;AAED,gEAAgE;AAChE,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAGjD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const text = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
2
|
+
/** BCP 47-like language code (`it`, `en-GB`, `zh-Hant`) */
|
|
3
|
+
export const isLanguageCode = (v) => typeof v === 'string' && /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(v);
|
|
4
|
+
/** `<title>`: explicit export title, else `body.title`, else the subject */
|
|
5
|
+
export function documentTitle(body, explicit) {
|
|
6
|
+
return text(explicit) || text(body?.title) || text(body?.subject);
|
|
7
|
+
}
|
|
8
|
+
/** `<html lang>` value, or `''` when the design sets none (or an invalid one) */
|
|
9
|
+
export function documentLanguage(body) {
|
|
10
|
+
return isLanguageCode(body?.language) ? body.language : '';
|
|
11
|
+
}
|
|
12
|
+
/** Body font weight as a CSS value (`400`, `bold`…), or `''` */
|
|
13
|
+
export function bodyFontWeight(body) {
|
|
14
|
+
const w = String(body?.fontWeight ?? '');
|
|
15
|
+
return /^\d{3}$|^(normal|bold)$/.test(w) ? w : '';
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=body-meta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body-meta.js","sourceRoot":"","sources":["../../src/design/body-meta.ts"],"names":[],"mappings":"AASA,MAAM,IAAI,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAErE,2DAA2D;AAC3D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAU,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,kCAAkC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAE/H,4EAA4E;AAC5E,MAAM,UAAU,aAAa,CAAC,IAAU,EAAE,QAAiB;IACzD,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACpE,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,gBAAgB,CAAC,IAAU;IACzC,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAK,CAAC,QAAS,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/D,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,cAAc,CAAC,IAAU;IACvC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC;IACzC,OAAO,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** @module rows — row iteration over every body section */
|
|
2
|
+
import type { EmailDesign, DesignRow } from '@emabuild/types';
|
|
3
|
+
/** All rows of a design in document order: headers, rows, footers */
|
|
4
|
+
export declare function allRows(design: EmailDesign): DesignRow[];
|
|
5
|
+
//# sourceMappingURL=rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rows.d.ts","sourceRoot":"","sources":["../../src/design/rows.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE9D,qEAAqE;AACrE,wBAAgB,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,EAAE,CAGxD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rows.js","sourceRoot":"","sources":["../../src/design/rows.ts"],"names":[],"mappings":"AAGA,qEAAqE;AACrE,MAAM,UAAU,OAAO,CAAC,MAAmB;IACzC,MAAM,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC;IACvB,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module cors
|
|
3
|
+
* CORS headers for the Fetch-style handlers (AI connector, export service).
|
|
4
|
+
*/
|
|
5
|
+
/** Allowed origins: one origin, a list, or `'*'` */
|
|
6
|
+
export type CorsOption = string | string[] | false | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Headers allowing `req`'s origin when it is listed in `cors` (`{}` otherwise).
|
|
9
|
+
* `expose` lists response headers the browser may read (e.g. content-disposition).
|
|
10
|
+
*/
|
|
11
|
+
export declare function corsHeaders(req: Request, cors: CorsOption, options?: {
|
|
12
|
+
methods?: string;
|
|
13
|
+
expose?: string[];
|
|
14
|
+
}): Record<string, string>;
|
|
15
|
+
//# sourceMappingURL=cors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors.d.ts","sourceRoot":"","sources":["../../src/http/cors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oDAAoD;AACpD,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,KAAK,GAAG,SAAS,CAAC;AAE/D;;;GAGG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAiBzI"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module cors
|
|
3
|
+
* CORS headers for the Fetch-style handlers (AI connector, export service).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Headers allowing `req`'s origin when it is listed in `cors` (`{}` otherwise).
|
|
7
|
+
* `expose` lists response headers the browser may read (e.g. content-disposition).
|
|
8
|
+
*/
|
|
9
|
+
export function corsHeaders(req, cors, options = {}) {
|
|
10
|
+
if (!cors)
|
|
11
|
+
return {};
|
|
12
|
+
const origin = req.headers.get('origin');
|
|
13
|
+
const list = Array.isArray(cors) ? cors : [cors];
|
|
14
|
+
let allow = null;
|
|
15
|
+
if (list.includes('*'))
|
|
16
|
+
allow = '*';
|
|
17
|
+
else if (origin && list.includes(origin))
|
|
18
|
+
allow = origin;
|
|
19
|
+
if (!allow)
|
|
20
|
+
return {};
|
|
21
|
+
const headers = {
|
|
22
|
+
'access-control-allow-origin': allow,
|
|
23
|
+
'access-control-allow-methods': options.methods ?? 'POST, OPTIONS',
|
|
24
|
+
'access-control-allow-headers': req.headers.get('access-control-request-headers') ?? 'content-type, authorization',
|
|
25
|
+
...(options.expose?.length ? { 'access-control-expose-headers': options.expose.join(', ') } : {}),
|
|
26
|
+
'access-control-max-age': '86400',
|
|
27
|
+
};
|
|
28
|
+
if (allow !== '*')
|
|
29
|
+
headers.vary = 'Origin';
|
|
30
|
+
return headers;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=cors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../../src/http/cors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,GAAY,EAAE,IAAgB,EAAE,UAAmD,EAAE;IAC/G,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,KAAK,GAAkB,IAAI,CAAC;IAChC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,KAAK,GAAG,GAAG,CAAC;SAC/B,IAAI,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,KAAK,GAAG,MAAM,CAAC;IACzD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,OAAO,GAA2B;QACtC,6BAA6B,EAAE,KAAK;QACpC,8BAA8B,EAAE,OAAO,CAAC,OAAO,IAAI,eAAe;QAClE,8BAA8B,EAAE,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,IAAI,6BAA6B;QAClH,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,+BAA+B,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjG,wBAAwB,EAAE,OAAO;KAClC,CAAC;IACF,IAAI,KAAK,KAAK,GAAG;QAAE,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC;IAC3C,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
/** A Web Fetch style handler */
|
|
3
|
+
export type FetchHandler = (req: Request) => Response | Promise<Response>;
|
|
4
|
+
/** A `node:http` / Express style handler */
|
|
5
|
+
export type NodeHandler = (req: IncomingMessage & {
|
|
6
|
+
body?: unknown;
|
|
7
|
+
originalUrl?: string;
|
|
8
|
+
}, res: ServerResponse, next?: (err?: unknown) => void) => Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Adapts a Web Fetch handler (e.g. `createAIHandler`, `createExportHandler`)
|
|
11
|
+
* to `node:http` / Express `(req, res)`. Response bodies are streamed chunk
|
|
12
|
+
* by chunk (respecting backpressure), and a client disconnect aborts the
|
|
13
|
+
* request signal so the work is cancelled.
|
|
14
|
+
*/
|
|
15
|
+
export declare function toNodeHandler(handler: FetchHandler): NodeHandler;
|
|
16
|
+
//# sourceMappingURL=node-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-handler.d.ts","sourceRoot":"","sources":["../../src/http/node-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEjE,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAE1E,4CAA4C;AAC5C,MAAM,MAAM,WAAW,GAAG,CACxB,GAAG,EAAE,eAAe,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,EAC/D,GAAG,EAAE,cAAc,EACnB,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,KAC3B,OAAO,CAAC,IAAI,CAAC,CAAC;AAuCnB;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,CA2DhE"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
async function readBody(req) {
|
|
2
|
+
const method = (req.method ?? 'GET').toUpperCase();
|
|
3
|
+
if (method === 'GET' || method === 'HEAD' || method === 'OPTIONS')
|
|
4
|
+
return undefined;
|
|
5
|
+
// Body already consumed by a parser middleware (e.g. express.json())
|
|
6
|
+
if (req.body !== undefined) {
|
|
7
|
+
if (typeof req.body === 'string')
|
|
8
|
+
return req.body;
|
|
9
|
+
if (Buffer.isBuffer(req.body))
|
|
10
|
+
return req.body.toString('utf8');
|
|
11
|
+
return JSON.stringify(req.body);
|
|
12
|
+
}
|
|
13
|
+
const chunks = [];
|
|
14
|
+
for await (const chunk of req)
|
|
15
|
+
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
|
|
16
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
17
|
+
}
|
|
18
|
+
/** Resolves when the response can take more data or the connection closes */
|
|
19
|
+
function waitForDrain(res) {
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
const done = () => {
|
|
22
|
+
res.off('drain', done);
|
|
23
|
+
res.off('close', done);
|
|
24
|
+
resolve();
|
|
25
|
+
};
|
|
26
|
+
res.on('drain', done);
|
|
27
|
+
res.on('close', done);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function toHeaders(req) {
|
|
31
|
+
const headers = new Headers();
|
|
32
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
33
|
+
if (value === undefined)
|
|
34
|
+
continue;
|
|
35
|
+
if (Array.isArray(value))
|
|
36
|
+
value.forEach((v) => headers.append(key, v));
|
|
37
|
+
else
|
|
38
|
+
headers.set(key, value);
|
|
39
|
+
}
|
|
40
|
+
return headers;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Adapts a Web Fetch handler (e.g. `createAIHandler`, `createExportHandler`)
|
|
44
|
+
* to `node:http` / Express `(req, res)`. Response bodies are streamed chunk
|
|
45
|
+
* by chunk (respecting backpressure), and a client disconnect aborts the
|
|
46
|
+
* request signal so the work is cancelled.
|
|
47
|
+
*/
|
|
48
|
+
export function toNodeHandler(handler) {
|
|
49
|
+
return async (req, res, next) => {
|
|
50
|
+
const abort = new AbortController();
|
|
51
|
+
const onClose = () => {
|
|
52
|
+
if (!res.writableFinished)
|
|
53
|
+
abort.abort();
|
|
54
|
+
};
|
|
55
|
+
res.on('close', onClose);
|
|
56
|
+
try {
|
|
57
|
+
const host = req.headers.host ?? 'localhost';
|
|
58
|
+
const proto = req.headers['x-forwarded-proto']?.split(',')[0]?.trim() || 'http';
|
|
59
|
+
const url = new URL(req.originalUrl ?? req.url ?? '/', `${proto}://${host}`);
|
|
60
|
+
const body = await readBody(req);
|
|
61
|
+
const request = new Request(url, {
|
|
62
|
+
method: req.method,
|
|
63
|
+
headers: toHeaders(req),
|
|
64
|
+
body,
|
|
65
|
+
signal: abort.signal,
|
|
66
|
+
});
|
|
67
|
+
const response = await handler(request);
|
|
68
|
+
const headers = {};
|
|
69
|
+
response.headers.forEach((value, key) => {
|
|
70
|
+
headers[key] = value;
|
|
71
|
+
});
|
|
72
|
+
const cookies = response.headers.getSetCookie?.();
|
|
73
|
+
if (cookies?.length)
|
|
74
|
+
headers['set-cookie'] = cookies;
|
|
75
|
+
res.writeHead(response.status, headers);
|
|
76
|
+
res.flushHeaders?.();
|
|
77
|
+
if (!response.body) {
|
|
78
|
+
res.end();
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const reader = response.body.getReader();
|
|
82
|
+
try {
|
|
83
|
+
while (true) {
|
|
84
|
+
const { value, done } = await reader.read();
|
|
85
|
+
if (done)
|
|
86
|
+
break;
|
|
87
|
+
if (abort.signal.aborted)
|
|
88
|
+
break;
|
|
89
|
+
if (!res.write(value))
|
|
90
|
+
await waitForDrain(res);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
if (abort.signal.aborted)
|
|
95
|
+
await reader.cancel().catch(() => undefined);
|
|
96
|
+
else
|
|
97
|
+
reader.releaseLock();
|
|
98
|
+
}
|
|
99
|
+
res.end();
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (next)
|
|
103
|
+
return next(err);
|
|
104
|
+
if (!res.headersSent) {
|
|
105
|
+
res.writeHead(500, { 'content-type': 'application/json; charset=utf-8' });
|
|
106
|
+
res.end(JSON.stringify({ error: 'Internal server error' }));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
res.destroy(err instanceof Error ? err : undefined);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
res.off('close', onClose);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=node-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-handler.js","sourceRoot":"","sources":["../../src/http/node-handler.ts"],"names":[],"mappings":"AAYA,KAAK,UAAU,QAAQ,CAAC,GAAyC;IAC/D,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IACnD,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACpF,qEAAqE;IACrE,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC3B,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,GAAG,CAAC,IAAI,CAAC;QAClD,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,OAAO,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;IACD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG;QAAE,MAAM,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAgB,CAAC,CAAC;IAC/G,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC;AAED,6EAA6E;AAC7E,SAAS,YAAY,CAAC,GAAmB;IACvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,IAAI,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AAC,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module openverse
|
|
3
|
+
* Minimal Openverse (api.openverse.org) image search, no API key needed.
|
|
4
|
+
* Defaults to CC0 / public-domain results, which need no attribution.
|
|
5
|
+
* Isomorphic (fetch only): used by the editor's "Free images" picker and the
|
|
6
|
+
* AI `search_images` tool.
|
|
7
|
+
*/
|
|
8
|
+
import type { FreeImage, FreeImageSearchOptions } from '@emabuild/types';
|
|
9
|
+
export interface OpenverseOptions extends FreeImageSearchOptions {
|
|
10
|
+
/** Openverse `license` filter (default "cc0,pdm") */
|
|
11
|
+
licenses?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function searchOpenverse(query: string, options?: OpenverseOptions): Promise<{
|
|
14
|
+
images: FreeImage[];
|
|
15
|
+
hasMore: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=openverse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openverse.d.ts","sourceRoot":"","sources":["../../src/images/openverse.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAMzE,MAAM,WAAW,gBAAiB,SAAQ,sBAAsB;IAC9D,qDAAqD;IACrD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAuCvI"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const API = 'https://api.openverse.org/v1/images/';
|
|
2
|
+
const ASPECT = { landscape: 'wide', portrait: 'tall', square: 'square' };
|
|
3
|
+
const TIMEOUT_MS = 12000;
|
|
4
|
+
export async function searchOpenverse(query, options = {}) {
|
|
5
|
+
const params = new URLSearchParams({
|
|
6
|
+
q: query,
|
|
7
|
+
license: options.licenses ?? 'cc0,pdm',
|
|
8
|
+
page_size: String(Math.min(Math.max(options.count ?? 20, 1), 20)),
|
|
9
|
+
page: String(options.page ?? 1),
|
|
10
|
+
mature: 'false',
|
|
11
|
+
extension: 'jpg,png',
|
|
12
|
+
});
|
|
13
|
+
if (options.orientation)
|
|
14
|
+
params.set('aspect_ratio', ASPECT[options.orientation]);
|
|
15
|
+
// Openverse can be slow: give up after a while instead of hanging the UI
|
|
16
|
+
const ctrl = new AbortController();
|
|
17
|
+
const timer = setTimeout(() => ctrl.abort(), TIMEOUT_MS);
|
|
18
|
+
const onAbort = () => ctrl.abort();
|
|
19
|
+
options.signal?.addEventListener('abort', onAbort);
|
|
20
|
+
try {
|
|
21
|
+
const res = await fetch(`${API}?${params}`, { signal: ctrl.signal });
|
|
22
|
+
if (!res.ok)
|
|
23
|
+
throw new Error(`Openverse ${res.status}`);
|
|
24
|
+
const data = await res.json();
|
|
25
|
+
const images = (data.results ?? []).filter((r) => r.url).map((r) => ({
|
|
26
|
+
url: String(r.url).replace(/^http:/, 'https:'),
|
|
27
|
+
thumbnail: r.thumbnail || r.url,
|
|
28
|
+
width: r.width ?? undefined,
|
|
29
|
+
height: r.height ?? undefined,
|
|
30
|
+
title: r.title || undefined,
|
|
31
|
+
creator: r.creator || undefined,
|
|
32
|
+
license: r.license,
|
|
33
|
+
licenseUrl: r.license_url || undefined,
|
|
34
|
+
landingUrl: r.foreign_landing_url || undefined,
|
|
35
|
+
}));
|
|
36
|
+
return { images, hasMore: (options.page ?? 1) < (data.page_count ?? 1) };
|
|
37
|
+
}
|
|
38
|
+
catch (err) {
|
|
39
|
+
if (ctrl.signal.aborted && !options.signal?.aborted)
|
|
40
|
+
throw new Error('Openverse did not respond in time');
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
clearTimeout(timer);
|
|
45
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=openverse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openverse.js","sourceRoot":"","sources":["../../src/images/openverse.ts"],"names":[],"mappings":"AASA,MAAM,GAAG,GAAG,sCAAsC,CAAC;AACnD,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAW,CAAC;AAClF,MAAM,UAAU,GAAG,KAAK,CAAC;AAOzB,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAa,EAAE,UAA4B,EAAE;IACjF,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;QACjC,CAAC,EAAE,KAAK;QACR,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,SAAS;QACtC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACjE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC;QAC/B,MAAM,EAAE,OAAO;QACf,SAAS,EAAE,SAAS;KACrB,CAAC,CAAC;IACH,IAAI,OAAO,CAAC,WAAW;QAAE,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAEjF,yEAAyE;IACzE,MAAM,IAAI,GAAG,IAAI,eAAe,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,UAAU,CAAC,CAAC;IACzD,MAAM,OAAO,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,C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CAAC,CAAC,EAAE,CAAC;IAC3E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAC1G,MAAM,GAAG,CAAC;IACZ,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,OAAO,CAAC,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @emabuild/shared — internal building blocks shared by the emabuild packages,
|
|
3
|
+
* grouped by scope. Isomorphic entry (browser + Node); Node-only helpers are in
|
|
4
|
+
* `@emabuild/shared/node`.
|
|
5
|
+
*/
|
|
6
|
+
export { corsHeaders, type CorsOption } from './http/cors.js';
|
|
7
|
+
export { searchOpenverse } from './images/openverse.js';
|
|
8
|
+
export { cleanCssValue, isSafeCssValue } from './css/css-safe.js';
|
|
9
|
+
export { allRows } from './design/rows.js';
|
|
10
|
+
export { documentTitle, documentLanguage, bodyFontWeight, isLanguageCode } from './design/body-meta.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @emabuild/shared — internal building blocks shared by the emabuild packages,
|
|
3
|
+
* grouped by scope. Isomorphic entry (browser + Node); Node-only helpers are in
|
|
4
|
+
* `@emabuild/shared/node`.
|
|
5
|
+
*/
|
|
6
|
+
export { corsHeaders } from './http/cors.js';
|
|
7
|
+
export { searchOpenverse } from './images/openverse.js';
|
|
8
|
+
export { cleanCssValue, isSafeCssValue } from './css/css-safe.js';
|
|
9
|
+
export { allRows } from './design/rows.js';
|
|
10
|
+
export { documentTitle, documentLanguage, bodyFontWeight, isLanguageCode } from './design/body-meta.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/node.js
ADDED
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,OAAO,EAAE,aAAa,EAAuC,MAAM,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emabuild/shared",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Internal building blocks shared by the @emabuild packages (HTTP adapters, image search)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./node": {
|
|
15
|
+
"types": "./dist/node.d.ts",
|
|
16
|
+
"import": "./dist/node.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@emabuild/types": "0.6.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.10.0",
|
|
29
|
+
"typescript": "^5.7.0",
|
|
30
|
+
"vitest": "^3.0.0"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18.17"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"dev": "tsc -p tsconfig.json --watch",
|
|
42
|
+
"clean": "rm -rf dist",
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
}
|
|
6
45
|
}
|