@diagc/cli 0.2.0 → 0.3.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/assets/studio/assets/index-Dd7ULnMP.css +1 -0
- package/assets/studio/assets/index-DyhpmyEM.js +108 -0
- package/assets/studio/index.html +2 -2
- package/assets/viewer/index.html +32 -32
- package/dist/includes.d.ts +9 -0
- package/dist/includes.js +40 -3
- package/package.json +2 -2
- package/assets/studio/assets/index-BomRAAuh.js +0 -108
- package/assets/studio/assets/index-Jz5ydoCD.css +0 -1
package/dist/includes.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { IncludeSource } from '@diagc/core';
|
|
2
|
+
export declare const AUTH_TOKENS_ENV = "DIAGC_AUTH_TOKENS";
|
|
3
|
+
/**
|
|
4
|
+
* Credentials for private include hosts, in Deno's `DENO_AUTH_TOKENS` format:
|
|
5
|
+
* `;`-separated `token@host` (sent as a bearer token) or `user:pass@host`
|
|
6
|
+
* (basic auth), the host with its port when it has one. Keyed by `URL.host`,
|
|
7
|
+
* so a credential only ever reaches the host it names. Malformed entries are
|
|
8
|
+
* skipped rather than failing a compile that may not need them.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseAuthTokens(raw: string | undefined): Map<string, string>;
|
|
2
11
|
/** diagc's include IO: http(s) URLs via fetch, everything else via the
|
|
3
12
|
* filesystem relative to the declaring file. Returns the canonical resolved
|
|
4
13
|
* ref so compose can detect cycles across mixed URL/path chains. */
|
package/dist/includes.js
CHANGED
|
@@ -1,15 +1,52 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
const isHttp = (s) => /^https?:\/\//.test(s);
|
|
4
|
+
export const AUTH_TOKENS_ENV = 'DIAGC_AUTH_TOKENS';
|
|
5
|
+
/**
|
|
6
|
+
* Credentials for private include hosts, in Deno's `DENO_AUTH_TOKENS` format:
|
|
7
|
+
* `;`-separated `token@host` (sent as a bearer token) or `user:pass@host`
|
|
8
|
+
* (basic auth), the host with its port when it has one. Keyed by `URL.host`,
|
|
9
|
+
* so a credential only ever reaches the host it names. Malformed entries are
|
|
10
|
+
* skipped rather than failing a compile that may not need them.
|
|
11
|
+
*/
|
|
12
|
+
export function parseAuthTokens(raw) {
|
|
13
|
+
const out = new Map();
|
|
14
|
+
for (const entry of (raw ?? '').split(';').map((e) => e.trim())) {
|
|
15
|
+
const at = entry.lastIndexOf('@');
|
|
16
|
+
if (at <= 0)
|
|
17
|
+
continue;
|
|
18
|
+
const secret = entry.slice(0, at);
|
|
19
|
+
const host = entry.slice(at + 1).toLowerCase();
|
|
20
|
+
if (host === '')
|
|
21
|
+
continue;
|
|
22
|
+
out.set(host, secret.includes(':') ? `Basic ${Buffer.from(secret).toString('base64')}` : `Bearer ${secret}`);
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
/** The Authorization header for `url`, if one is configured for its host. Only
|
|
27
|
+
* over https: a token sent over plain http is a token handed to the network. */
|
|
28
|
+
function authFor(url) {
|
|
29
|
+
if (url.protocol !== 'https:')
|
|
30
|
+
return undefined;
|
|
31
|
+
return parseAuthTokens(process.env[AUTH_TOKENS_ENV]).get(url.host);
|
|
32
|
+
}
|
|
4
33
|
/** diagc's include IO: http(s) URLs via fetch, everything else via the
|
|
5
34
|
* filesystem relative to the declaring file. Returns the canonical resolved
|
|
6
35
|
* ref so compose can detect cycles across mixed URL/path chains. */
|
|
7
36
|
export async function resolveInclude(spec, fromRef) {
|
|
8
37
|
if (isHttp(spec) || isHttp(fromRef)) {
|
|
9
38
|
const url = isHttp(spec) ? spec : new URL(spec, fromRef).href;
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
39
|
+
const auth = authFor(new URL(url));
|
|
40
|
+
// fetch drops Authorization on a cross-origin redirect, so a raw host that
|
|
41
|
+
// bounces to a CDN does not take the token with it
|
|
42
|
+
const res = await fetch(url, auth !== undefined ? { headers: { authorization: auth } } : undefined);
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
// private hosts answer 404 as often as 401/403, so hint on all three
|
|
45
|
+
const hint = auth === undefined && [401, 403, 404].includes(res.status)
|
|
46
|
+
? ` — if the host is private, set ${AUTH_TOKENS_ENV}=<token>@${new URL(url).host}`
|
|
47
|
+
: '';
|
|
48
|
+
throw new Error(`HTTP ${res.status} fetching ${url}${hint}`);
|
|
49
|
+
}
|
|
13
50
|
return { model: (await res.json()), ref: url };
|
|
14
51
|
}
|
|
15
52
|
const file = path.resolve(path.dirname(fromRef), spec);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diagc/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"author": "Bogdan Frankovskyi",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"fast-glob": "^3.3.0",
|
|
45
45
|
"jiti": "^2.0.0",
|
|
46
46
|
"playwright-core": "^1.62.0",
|
|
47
|
-
"@diagc/core": "0.
|
|
47
|
+
"@diagc/core": "0.3.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|