@adonis-agora/media-dashboard 6.0.0 → 6.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/CHANGELOG.md +20 -0
- package/dist/define_config.d.ts +16 -0
- package/dist/define_config.d.ts.map +1 -1
- package/dist/define_config.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/provider/media_dashboard_provider.d.ts.map +1 -1
- package/dist/provider/media_dashboard_provider.js +294 -47
- package/dist/provider/media_dashboard_provider.js.map +1 -1
- package/dist/server/auth.d.ts +76 -0
- package/dist/server/auth.d.ts.map +1 -0
- package/dist/server/auth.js +134 -0
- package/dist/server/auth.js.map +1 -0
- package/dist/server/cookie.d.ts +20 -0
- package/dist/server/cookie.d.ts.map +1 -0
- package/dist/server/cookie.js +44 -0
- package/dist/server/cookie.js.map +1 -0
- package/dist/server/object_insights.d.ts +42 -0
- package/dist/server/object_insights.d.ts.map +1 -0
- package/dist/server/object_insights.js +42 -0
- package/dist/server/object_insights.js.map +1 -0
- package/dist/server/service.d.ts +70 -4
- package/dist/server/service.d.ts.map +1 -1
- package/dist/server/service.js +149 -1
- package/dist/server/service.js.map +1 -1
- package/dist/spa/assets/index--0MZJr6W.css +1 -0
- package/dist/spa/assets/index-BtCClrPE.js +83 -0
- package/dist/spa/assets/index-BtCClrPE.js.map +1 -0
- package/dist/spa/index.html +8 -2
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +17 -10
- package/dist/spa/assets/index-BaYNF8Yc.css +0 -1
- package/dist/spa/assets/index-Dhth080j.js +0 -50
- package/dist/spa/assets/index-Dhth080j.js.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** The validated console session decoded from a verified cookie. */
|
|
2
|
+
export interface ConsoleSession {
|
|
3
|
+
/** Stable user id (the session user's `id`). */
|
|
4
|
+
sub: string;
|
|
5
|
+
/** Optional display name. */
|
|
6
|
+
name?: string;
|
|
7
|
+
/** Free-form role strings; the console does not interpret them. */
|
|
8
|
+
roles: string[];
|
|
9
|
+
/** Issued-at, epoch milliseconds. */
|
|
10
|
+
iat: number;
|
|
11
|
+
/** Expiry, epoch milliseconds. */
|
|
12
|
+
exp: number;
|
|
13
|
+
}
|
|
14
|
+
/** The session user a host `login`/`session` hook returns to mint a cookie. */
|
|
15
|
+
export interface ConsoleSessionUser {
|
|
16
|
+
id: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
roles?: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface SignOptions {
|
|
21
|
+
secret: string;
|
|
22
|
+
ttlMs: number;
|
|
23
|
+
/** Injectable clock (epoch ms) for deterministic tests. Defaults to `Date.now()`. */
|
|
24
|
+
now?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface VerifyOptions {
|
|
27
|
+
secret: string;
|
|
28
|
+
now?: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Sign a session into the cookie value `base64url(payload).base64url(hmac)`. Stateless
|
|
32
|
+
* HMAC-SHA256, no store — `node:crypto` only, no JWT dependency.
|
|
33
|
+
*/
|
|
34
|
+
export declare function signSessionCookie(user: ConsoleSessionUser, options: SignOptions): string;
|
|
35
|
+
/**
|
|
36
|
+
* Verify a cookie value and return the session, or `null` for anything tampered, malformed, or
|
|
37
|
+
* expired (past `exp` + a 30s grace). Constant-time signature comparison. NEVER throws — any parse
|
|
38
|
+
* failure yields `null`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function verifySessionCookie(value: string, options: VerifyOptions): ConsoleSession | null;
|
|
41
|
+
/** Host hook for Mode A — validates the host's own auth on the raw AdonisJS request. */
|
|
42
|
+
export type SessionHook = (request: unknown) => Promise<ConsoleSessionUser | null> | ConsoleSessionUser | null;
|
|
43
|
+
/** Host hook for Mode B — validates submitted credentials from the built-in login screen. */
|
|
44
|
+
export type LoginHook = (username: string, password: string) => Promise<ConsoleSessionUser | null> | ConsoleSessionUser | null;
|
|
45
|
+
/** Re-checks a LIVE session when the cookie is slid forward. Return `false` to revoke. */
|
|
46
|
+
export type RevalidateHook = (session: ConsoleSessionUser) => Promise<boolean> | boolean;
|
|
47
|
+
export type AuthMode = 'session' | 'login';
|
|
48
|
+
/** Author-facing `auth` option on `config/media_dashboard.ts`. Mirrors the NestJS console's shape. */
|
|
49
|
+
export interface ConsoleAuthOptions {
|
|
50
|
+
/** REQUIRED HMAC-SHA256 signing key. Missing/empty => boot error (fail closed). */
|
|
51
|
+
secret: string;
|
|
52
|
+
/** Cookie TTL as a duration string (`'8h'`, `'30m'`, `'7d'`). Default `'8h'`. */
|
|
53
|
+
ttl?: string;
|
|
54
|
+
/** Mode A: validate the host's own auth on the raw request. */
|
|
55
|
+
session?: SessionHook;
|
|
56
|
+
/** Mode B: validate credentials from the built-in login screen. */
|
|
57
|
+
login?: LoginHook;
|
|
58
|
+
/** Re-checks the session on sliding renewal. Not a mode — it cannot mint a session on its own. */
|
|
59
|
+
revalidate?: RevalidateHook;
|
|
60
|
+
}
|
|
61
|
+
/** Resolved, validated console-auth config shared by the guard and the auth routes. */
|
|
62
|
+
export interface ResolvedConsoleAuth {
|
|
63
|
+
secret: string;
|
|
64
|
+
ttlMs: number;
|
|
65
|
+
modes: AuthMode[];
|
|
66
|
+
session?: SessionHook;
|
|
67
|
+
login?: LoginHook;
|
|
68
|
+
revalidate?: RevalidateHook;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Validate + resolve the `auth` option. Returns `null` when unconfigured (the console stays open —
|
|
72
|
+
* front it with your own `middleware`). Throws at boot (fail closed) when configured but missing a
|
|
73
|
+
* secret or any hook — the host learns immediately rather than shipping an un-mintable gate.
|
|
74
|
+
*/
|
|
75
|
+
export declare function resolveConsoleAuth(options: ConsoleAuthOptions | undefined): ResolvedConsoleAuth | null;
|
|
76
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +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BAAkB,GAAG,IAAI,CAAC,GAAG,kBAAkB,GAAG,IAAI,CAAC;AAEpE,0FAA0F;AAC1F,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAEzF,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;AAE3C,sGAAsG;AACtG,MAAM,WAAW,kBAAkB;IACjC,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,mEAAmE;IACnE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,kGAAkG;IAClG,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED,uFAAuF;AACvF,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAoBD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,kBAAkB,GAAG,SAAS,GACtC,mBAAmB,GAAG,IAAI,CAmB5B"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Built-in session-cookie login for the dashboard, ported from the NestJS sibling console
|
|
4
|
+
* (`@dudousxd/nestjs-media-dashboard`'s `server/auth/*`) so both ecosystems gate the console the
|
|
5
|
+
* same way. Framework-free by design (no AdonisJS import here) — the provider is the only piece
|
|
6
|
+
* that knows about `HttpContext`/cookies; this module only signs and verifies a stateless
|
|
7
|
+
* HMAC-SHA256 session, exactly as the NestJS version does (same wire format, same TTL/grace rules),
|
|
8
|
+
* so a host running both consoles can share one mental model of "how the console gate works".
|
|
9
|
+
*/
|
|
10
|
+
/** Clock-skew grace applied to `exp` so a marginally-late clock doesn't bounce a valid cookie. */
|
|
11
|
+
const EXP_GRACE_MS = 30_000;
|
|
12
|
+
function base64urlEncode(value) {
|
|
13
|
+
return Buffer.from(value, 'utf8').toString('base64url');
|
|
14
|
+
}
|
|
15
|
+
function base64urlDecode(value) {
|
|
16
|
+
return Buffer.from(value, 'base64url').toString('utf8');
|
|
17
|
+
}
|
|
18
|
+
function hmac(secret, payload) {
|
|
19
|
+
return createHmac('sha256', secret).update(payload).digest('base64url');
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sign a session into the cookie value `base64url(payload).base64url(hmac)`. Stateless
|
|
23
|
+
* HMAC-SHA256, no store — `node:crypto` only, no JWT dependency.
|
|
24
|
+
*/
|
|
25
|
+
export function signSessionCookie(user, options) {
|
|
26
|
+
const issuedAt = options.now ?? Date.now();
|
|
27
|
+
const session = {
|
|
28
|
+
sub: user.id,
|
|
29
|
+
...(user.name !== undefined ? { name: user.name } : {}),
|
|
30
|
+
roles: user.roles ?? [],
|
|
31
|
+
iat: issuedAt,
|
|
32
|
+
exp: issuedAt + options.ttlMs,
|
|
33
|
+
};
|
|
34
|
+
const encodedPayload = base64urlEncode(JSON.stringify(session));
|
|
35
|
+
return `${encodedPayload}.${hmac(options.secret, encodedPayload)}`;
|
|
36
|
+
}
|
|
37
|
+
/** Type guard for the decoded payload shape — defends against tampered/legacy payloads. */
|
|
38
|
+
function isSessionPayload(value) {
|
|
39
|
+
if (typeof value !== 'object' || value === null)
|
|
40
|
+
return false;
|
|
41
|
+
const record = value;
|
|
42
|
+
if (typeof record.sub !== 'string')
|
|
43
|
+
return false;
|
|
44
|
+
if (record.name !== undefined && typeof record.name !== 'string')
|
|
45
|
+
return false;
|
|
46
|
+
if (!Array.isArray(record.roles))
|
|
47
|
+
return false;
|
|
48
|
+
if (!record.roles.every((role) => typeof role === 'string'))
|
|
49
|
+
return false;
|
|
50
|
+
if (typeof record.iat !== 'number' || !Number.isFinite(record.iat))
|
|
51
|
+
return false;
|
|
52
|
+
if (typeof record.exp !== 'number' || !Number.isFinite(record.exp))
|
|
53
|
+
return false;
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Verify a cookie value and return the session, or `null` for anything tampered, malformed, or
|
|
58
|
+
* expired (past `exp` + a 30s grace). Constant-time signature comparison. NEVER throws — any parse
|
|
59
|
+
* failure yields `null`.
|
|
60
|
+
*/
|
|
61
|
+
export function verifySessionCookie(value, options) {
|
|
62
|
+
try {
|
|
63
|
+
const dot = value.indexOf('.');
|
|
64
|
+
if (dot <= 0 || dot === value.length - 1)
|
|
65
|
+
return null;
|
|
66
|
+
const encodedPayload = value.slice(0, dot);
|
|
67
|
+
const provided = Buffer.from(value.slice(dot + 1), 'base64url');
|
|
68
|
+
const expected = Buffer.from(hmac(options.secret, encodedPayload), 'base64url');
|
|
69
|
+
// timingSafeEqual throws on a length mismatch — guard it so a wrong-length (tampered)
|
|
70
|
+
// signature returns null instead of throwing.
|
|
71
|
+
if (provided.length !== expected.length)
|
|
72
|
+
return null;
|
|
73
|
+
if (!timingSafeEqual(provided, expected))
|
|
74
|
+
return null;
|
|
75
|
+
const decoded = JSON.parse(base64urlDecode(encodedPayload));
|
|
76
|
+
if (!isSessionPayload(decoded))
|
|
77
|
+
return null;
|
|
78
|
+
const now = options.now ?? Date.now();
|
|
79
|
+
if (now > decoded.exp + EXP_GRACE_MS)
|
|
80
|
+
return null;
|
|
81
|
+
return decoded;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const DEFAULT_TTL_MS = 8 * 60 * 60 * 1000;
|
|
88
|
+
const DURATION_UNITS = {
|
|
89
|
+
s: 1000,
|
|
90
|
+
m: 60 * 1000,
|
|
91
|
+
h: 60 * 60 * 1000,
|
|
92
|
+
d: 24 * 60 * 60 * 1000,
|
|
93
|
+
};
|
|
94
|
+
/** Parse a `'<number><s|m|h|d>'` duration to ms; falls back to the 8h default on a bad value. */
|
|
95
|
+
function durationToMs(ttl) {
|
|
96
|
+
if (ttl === undefined)
|
|
97
|
+
return DEFAULT_TTL_MS;
|
|
98
|
+
const match = /^(\d+)([smhd])$/.exec(ttl.trim());
|
|
99
|
+
if (!match)
|
|
100
|
+
return DEFAULT_TTL_MS;
|
|
101
|
+
const unit = DURATION_UNITS[match[2] ?? ''];
|
|
102
|
+
if (unit === undefined)
|
|
103
|
+
return DEFAULT_TTL_MS;
|
|
104
|
+
return Number(match[1]) * unit;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Validate + resolve the `auth` option. Returns `null` when unconfigured (the console stays open —
|
|
108
|
+
* front it with your own `middleware`). Throws at boot (fail closed) when configured but missing a
|
|
109
|
+
* secret or any hook — the host learns immediately rather than shipping an un-mintable gate.
|
|
110
|
+
*/
|
|
111
|
+
export function resolveConsoleAuth(options) {
|
|
112
|
+
if (!options)
|
|
113
|
+
return null;
|
|
114
|
+
if (!options.secret) {
|
|
115
|
+
throw new Error('media-dashboard: auth.secret is required when `auth` is configured.');
|
|
116
|
+
}
|
|
117
|
+
const modes = [];
|
|
118
|
+
if (options.session)
|
|
119
|
+
modes.push('session');
|
|
120
|
+
if (options.login)
|
|
121
|
+
modes.push('login');
|
|
122
|
+
if (modes.length === 0) {
|
|
123
|
+
throw new Error('media-dashboard: auth needs a `login` and/or `session` hook.');
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
secret: options.secret,
|
|
127
|
+
ttlMs: durationToMs(options.ttl),
|
|
128
|
+
modes,
|
|
129
|
+
...(options.session ? { session: options.session } : {}),
|
|
130
|
+
...(options.login ? { login: options.login } : {}),
|
|
131
|
+
...(options.revalidate ? { revalidate: options.revalidate } : {}),
|
|
132
|
+
};
|
|
133
|
+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CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAClE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal, framework-free `Cookie`/`Set-Cookie` header codec for the console's session cookie.
|
|
3
|
+
* Deliberately NOT using AdonisJS's own `plainCookie`/`cookie` helpers — this cookie is signed by
|
|
4
|
+
* `./auth.ts` itself (HMAC, matching the NestJS sibling console byte-for-byte), so it needs no
|
|
5
|
+
* further encoding, and writing the header directly keeps `./auth.ts` fully framework-free and
|
|
6
|
+
* trivially unit-testable (same reasoning as the NestJS console's `auth/cookie-header.ts`).
|
|
7
|
+
*/
|
|
8
|
+
export declare const SESSION_COOKIE_NAME = "media_dashboard_session";
|
|
9
|
+
/** Parse a `Cookie` request header into a `{name: value}` map. Malformed pairs are skipped. */
|
|
10
|
+
export declare function parseCookieHeader(header: string | undefined): Record<string, string>;
|
|
11
|
+
export interface SetCookieOptions {
|
|
12
|
+
path: string;
|
|
13
|
+
maxAgeSeconds: number;
|
|
14
|
+
secure: boolean;
|
|
15
|
+
/** When true, serializes an already-expired cookie (clears it) regardless of `maxAgeSeconds`. */
|
|
16
|
+
clear?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Serialize one `Set-Cookie` header value: `HttpOnly`, `SameSite=Lax`, and `Secure` over https. */
|
|
19
|
+
export declare function serializeSetCookie(name: string, value: string, options: SetCookieOptions): string;
|
|
20
|
+
//# sourceMappingURL=cookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.d.ts","sourceRoot":"","sources":["../../src/server/cookie.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,mBAAmB,4BAA4B,CAAC;AAE7D,+FAA+F;AAC/F,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgBpF;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,iGAAiG;IACjG,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,oGAAoG;AACpG,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,MAAM,CASjG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal, framework-free `Cookie`/`Set-Cookie` header codec for the console's session cookie.
|
|
3
|
+
* Deliberately NOT using AdonisJS's own `plainCookie`/`cookie` helpers — this cookie is signed by
|
|
4
|
+
* `./auth.ts` itself (HMAC, matching the NestJS sibling console byte-for-byte), so it needs no
|
|
5
|
+
* further encoding, and writing the header directly keeps `./auth.ts` fully framework-free and
|
|
6
|
+
* trivially unit-testable (same reasoning as the NestJS console's `auth/cookie-header.ts`).
|
|
7
|
+
*/
|
|
8
|
+
export const SESSION_COOKIE_NAME = 'media_dashboard_session';
|
|
9
|
+
/** Parse a `Cookie` request header into a `{name: value}` map. Malformed pairs are skipped. */
|
|
10
|
+
export function parseCookieHeader(header) {
|
|
11
|
+
const cookies = {};
|
|
12
|
+
if (!header)
|
|
13
|
+
return cookies;
|
|
14
|
+
for (const pair of header.split(';')) {
|
|
15
|
+
const eq = pair.indexOf('=');
|
|
16
|
+
if (eq === -1)
|
|
17
|
+
continue;
|
|
18
|
+
const name = pair.slice(0, eq).trim();
|
|
19
|
+
if (!name)
|
|
20
|
+
continue;
|
|
21
|
+
const value = pair.slice(eq + 1).trim();
|
|
22
|
+
try {
|
|
23
|
+
cookies[name] = decodeURIComponent(value);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
cookies[name] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return cookies;
|
|
30
|
+
}
|
|
31
|
+
/** Serialize one `Set-Cookie` header value: `HttpOnly`, `SameSite=Lax`, and `Secure` over https. */
|
|
32
|
+
export function serializeSetCookie(name, value, options) {
|
|
33
|
+
const parts = [`${name}=${encodeURIComponent(value)}`];
|
|
34
|
+
parts.push(`Path=${options.path}`);
|
|
35
|
+
parts.push(`Max-Age=${Math.max(0, Math.floor(options.maxAgeSeconds))}`);
|
|
36
|
+
if (options.clear)
|
|
37
|
+
parts.push('Expires=Thu, 01 Jan 1970 00:00:00 GMT');
|
|
38
|
+
parts.push('HttpOnly');
|
|
39
|
+
parts.push('SameSite=Lax');
|
|
40
|
+
if (options.secure)
|
|
41
|
+
parts.push('Secure');
|
|
42
|
+
return parts.join('; ');
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../src/server/cookie.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D,+FAA+F;AAC/F,MAAM,UAAU,iBAAiB,CAAC,MAA0B;IAC1D,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,CAAC,MAAM;QAAE,OAAO,OAAO,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,EAAE,KAAK,CAAC,CAAC;YAAE,SAAS;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disk object, shown in the console's preview.
|
|
3
|
+
*
|
|
4
|
+
* Ported from the NestJS sibling console's `server/object-insights.ts`. The console can describe a
|
|
5
|
+
* file only as storage sees it: key, size, content type, last modified. Everything that makes the
|
|
6
|
+
* file *mean* something lives in the host — which work order this scan belongs to, which knowledge
|
|
7
|
+
* base indexed it. This is the seam for handing that back: the host registers a provider (via
|
|
8
|
+
* `config/media_dashboard.ts`'s `objectInsights`), the console asks it when an object is previewed
|
|
9
|
+
* and renders whatever comes back.
|
|
10
|
+
*
|
|
11
|
+
* **Data, not components** — same reason as the NestJS side: the console ships as a prebuilt SPA
|
|
12
|
+
* bundle, so a host cannot inject React into it. A provider returns a small structured value the
|
|
13
|
+
* console knows how to render (facts, links, a note).
|
|
14
|
+
*/
|
|
15
|
+
import type { ObjectInsight, ObjectInsightsResponse } from '../types.js';
|
|
16
|
+
export type { ObjectInsight, ObjectInsightFact, ObjectInsightLink, ObjectInsightsResponse, } from '../types.js';
|
|
17
|
+
/** Which object is being described. */
|
|
18
|
+
export interface ObjectInsightContext {
|
|
19
|
+
disk: string;
|
|
20
|
+
key: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A source of {@link ObjectInsight}s, registered by the host in `config/media_dashboard.ts`.
|
|
24
|
+
*
|
|
25
|
+
* `resolve` runs on every preview of every object, so it must be cheap. Return `null` for an object
|
|
26
|
+
* this provider has nothing to say about, and the console renders nothing for it. A provider that
|
|
27
|
+
* throws is skipped (logged by the caller) — annotation must never be able to stop an admin opening
|
|
28
|
+
* a file.
|
|
29
|
+
*/
|
|
30
|
+
export interface ObjectInsightProvider {
|
|
31
|
+
/** Stable identifier, used in the log line when this provider fails. */
|
|
32
|
+
id: string;
|
|
33
|
+
resolve(ctx: ObjectInsightContext): Promise<ObjectInsight | null> | ObjectInsight | null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Drop links the console must not render. A relative href (`/ctrl/...`) always addresses the host's
|
|
37
|
+
* own app and is kept; an absolute one is kept only if it is http(s) (refuses `javascript:`/`data:`).
|
|
38
|
+
*/
|
|
39
|
+
export declare function sanitizeInsight(insight: ObjectInsight): ObjectInsight;
|
|
40
|
+
/** `{ insights: [] }` — what the console renders when no providers are registered. */
|
|
41
|
+
export declare function emptyInsights(): ObjectInsightsResponse;
|
|
42
|
+
//# sourceMappingURL=object_insights.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object_insights.d.ts","sourceRoot":"","sources":["../../src/server/object_insights.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAEzE,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,uCAAuC;AACvC,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,aAAa,GAAG,IAAI,CAAC;CAC1F;AAKD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAcrE;AAED,sFAAsF;AACtF,wBAAgB,aAAa,IAAI,sBAAsB,CAEtD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-supplied context about a disk object, shown in the console's preview.
|
|
3
|
+
*
|
|
4
|
+
* Ported from the NestJS sibling console's `server/object-insights.ts`. The console can describe a
|
|
5
|
+
* file only as storage sees it: key, size, content type, last modified. Everything that makes the
|
|
6
|
+
* file *mean* something lives in the host — which work order this scan belongs to, which knowledge
|
|
7
|
+
* base indexed it. This is the seam for handing that back: the host registers a provider (via
|
|
8
|
+
* `config/media_dashboard.ts`'s `objectInsights`), the console asks it when an object is previewed
|
|
9
|
+
* and renders whatever comes back.
|
|
10
|
+
*
|
|
11
|
+
* **Data, not components** — same reason as the NestJS side: the console ships as a prebuilt SPA
|
|
12
|
+
* bundle, so a host cannot inject React into it. A provider returns a small structured value the
|
|
13
|
+
* console knows how to render (facts, links, a note).
|
|
14
|
+
*/
|
|
15
|
+
/** Schemes an {@link ObjectInsightLink} may point at. Anything else is dropped, not rendered. */
|
|
16
|
+
const SAFE_LINK_SCHEMES = new Set(['http:', 'https:']);
|
|
17
|
+
/**
|
|
18
|
+
* Drop links the console must not render. A relative href (`/ctrl/...`) always addresses the host's
|
|
19
|
+
* own app and is kept; an absolute one is kept only if it is http(s) (refuses `javascript:`/`data:`).
|
|
20
|
+
*/
|
|
21
|
+
export function sanitizeInsight(insight) {
|
|
22
|
+
if (insight.links === undefined)
|
|
23
|
+
return insight;
|
|
24
|
+
const links = insight.links.filter((link) => {
|
|
25
|
+
if (link.href.startsWith('/')) {
|
|
26
|
+
// `//evil.com` is protocol-relative — an absolute URL wearing a relative one's clothes.
|
|
27
|
+
return !link.href.startsWith('//');
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return SAFE_LINK_SCHEMES.has(new URL(link.href).protocol);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return { ...insight, links };
|
|
37
|
+
}
|
|
38
|
+
/** `{ insights: [] }` — what the console renders when no providers are registered. */
|
|
39
|
+
export function emptyInsights() {
|
|
40
|
+
return { insights: [] };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=object_insights.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object_insights.js","sourceRoot":"","sources":["../../src/server/object_insights.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA+BH,iGAAiG;AACjG,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEvD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,OAAsB;IACpD,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAChD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1C,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9B,wFAAwF;YACxF,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,CAAC;YACH,OAAO,iBAAiB,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC5D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,CAAC;AAC/B,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,aAAa;IAC3B,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;AAC1B,CAAC"}
|
package/dist/server/service.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
2
|
+
import type { Disk, MediaListOptions, MediaListPage, MediaRecord, MultipartPart, UploadSession } from '@adonis-agora/media';
|
|
3
|
+
import type { CollectionFilter, CollectionListResponse, CollectionsSummaryResponse, DiskListResponse, MediaDetailResponse, ObjectDetailResponse, ObjectInsightsResponse, ObjectListResponse, Topology, UploadDetailResponse, UploadListResponse } from '../types.js';
|
|
4
|
+
import type { ObjectInsightProvider } from './object_insights.js';
|
|
3
5
|
/** TTL of the signed URLs handed to the browser for object preview/download. */
|
|
4
6
|
export declare const URL_TTL_SECONDS = 300;
|
|
5
7
|
/** Cap on the get→put streaming path used for cross-disk copy/move (drivers can't copy across disks). */
|
|
6
8
|
export declare const MAX_TRANSFER_BYTES: number;
|
|
7
9
|
/** Page size for the flat sweep that recursive folder delete/copy/move paginates over. */
|
|
8
10
|
export declare const FOLDER_SWEEP_LIMIT = 1000;
|
|
11
|
+
/** Page size for the client-side scan behind {@link DashboardService.collectionsSummary}. */
|
|
12
|
+
export declare const COLLECTIONS_SUMMARY_PAGE_SIZE = 200;
|
|
13
|
+
/** Hard cap on records scanned by {@link DashboardService.collectionsSummary} — beyond this the
|
|
14
|
+
* rollup is partial rather than unbounded. */
|
|
15
|
+
export declare const COLLECTIONS_SUMMARY_SCAN_LIMIT = 5000;
|
|
16
|
+
/** Ceiling for a console (direct) upload — buffered in memory, so bounded to protect the process
|
|
17
|
+
* heap. Larger files belong on the resumable (TUS) upload path, not this convenience upload. */
|
|
18
|
+
export declare const MAX_UPLOAD_BYTES: number;
|
|
9
19
|
/** The slice of `MediaManager` the dashboard depends on — kept structural so it's trivial to fake in tests. */
|
|
10
20
|
export interface MediaManagerLike {
|
|
11
21
|
readonly storage: {
|
|
@@ -18,10 +28,17 @@ export interface MediaManagerLike {
|
|
|
18
28
|
disk?: string;
|
|
19
29
|
keyPrefix?: string;
|
|
20
30
|
}): Promise<UploadSession[]>;
|
|
31
|
+
/** Discard an in-flight session (native multipart + buffered parts), then drop its record. */
|
|
32
|
+
abort(id: string): Promise<void>;
|
|
33
|
+
/** All recorded parts for a session (multipart-capable disks); empty for a buffered session. */
|
|
34
|
+
listParts(id: string): Promise<MultipartPart[]>;
|
|
21
35
|
};
|
|
22
|
-
/** The persistence SPI — the console reads stored records via the cross-owner `list
|
|
36
|
+
/** The persistence SPI — the console reads stored records via the cross-owner `list`, and a single
|
|
37
|
+
* record (+ delete) for the record-detail drill-in. */
|
|
23
38
|
readonly store: {
|
|
24
39
|
list(options?: MediaListOptions): Promise<MediaListPage>;
|
|
40
|
+
find(id: string): Promise<MediaRecord | null>;
|
|
41
|
+
delete(id: string): Promise<void>;
|
|
25
42
|
};
|
|
26
43
|
}
|
|
27
44
|
export interface DashboardServiceOptions {
|
|
@@ -44,7 +61,11 @@ export declare class DashboardError extends Error {
|
|
|
44
61
|
export declare class DashboardService {
|
|
45
62
|
private readonly manager;
|
|
46
63
|
private readonly options;
|
|
47
|
-
|
|
64
|
+
/** Host-registered {@link ObjectInsightProvider}s, from `config/media_dashboard.ts`'s `objectInsights`. */
|
|
65
|
+
private readonly insightProviders;
|
|
66
|
+
constructor(manager: MediaManagerLike, options: DashboardServiceOptions,
|
|
67
|
+
/** Host-registered {@link ObjectInsightProvider}s, from `config/media_dashboard.ts`'s `objectInsights`. */
|
|
68
|
+
insightProviders?: ObjectInsightProvider[]);
|
|
48
69
|
/** Coarse capability topology for the SPA to enable/disable affordances. */
|
|
49
70
|
topology(): Topology;
|
|
50
71
|
/** Enumerate the exposed disks with their capabilities (non-extended disks report `list:false`). */
|
|
@@ -57,11 +78,35 @@ export declare class DashboardService {
|
|
|
57
78
|
}): Promise<ObjectListResponse>;
|
|
58
79
|
/** Object metadata + a short-lived signed URL for preview/download. */
|
|
59
80
|
object(diskName: string, key: string): Promise<ObjectDetailResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* The object's raw byte stream plus the metadata the provider needs to serve it inline. Backs the
|
|
83
|
+
* console's same-origin preview proxy so text/PDF render in the browser instead of downloading
|
|
84
|
+
* (and so a CORS-locked bucket is still previewable).
|
|
85
|
+
*/
|
|
86
|
+
objectStream(diskName: string, key: string): Promise<{
|
|
87
|
+
stream: Readable;
|
|
88
|
+
contentType: string;
|
|
89
|
+
size: number;
|
|
90
|
+
}>;
|
|
91
|
+
/**
|
|
92
|
+
* What the HOST knows about this object, from every registered `objectInsights` provider (see
|
|
93
|
+
* `config/media_dashboard.ts`). `{ insights: [] }` when none are registered. A provider that
|
|
94
|
+
* throws is skipped and logged — annotation must never be able to stop an admin opening a file, and
|
|
95
|
+
* providers run concurrently so one host lookup being slow doesn't serialize the others.
|
|
96
|
+
*/
|
|
97
|
+
objectInsights(diskName: string, key: string): Promise<ObjectInsightsResponse>;
|
|
60
98
|
/** In-progress resumable uploads, projected from the session store (empty when unconfigured). */
|
|
61
99
|
uploads(filter?: {
|
|
62
100
|
disk?: string;
|
|
63
101
|
prefix?: string;
|
|
64
102
|
}): Promise<UploadListResponse>;
|
|
103
|
+
/** Full detail (+ recorded parts) of one resumable upload session. */
|
|
104
|
+
uploadDetail(id: string): Promise<UploadDetailResponse>;
|
|
105
|
+
/**
|
|
106
|
+
* Cancels a resumable session: discards its native multipart upload (or buffered parts) and drops
|
|
107
|
+
* its record, so it stops appearing as in-progress. Actions-gated.
|
|
108
|
+
*/
|
|
109
|
+
abortUpload(id: string): Promise<void>;
|
|
65
110
|
/**
|
|
66
111
|
* One cursor-paginated page of stored media-library records across owners/collections, projected to
|
|
67
112
|
* the SPA's {@link MediaEntry}. Delegates to the real {@link MediaStore.list} — no bespoke query.
|
|
@@ -70,6 +115,21 @@ export declare class DashboardService {
|
|
|
70
115
|
cursor?: string;
|
|
71
116
|
limit?: number;
|
|
72
117
|
}): Promise<CollectionListResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Per-collection rollup (record count + total bytes) for the console's collection chips.
|
|
120
|
+
* `MediaStore` has no aggregate query, so this walks `list()` in batches and sums client-side —
|
|
121
|
+
* bounded at {@link COLLECTIONS_SUMMARY_SCAN_LIMIT} records so a very large library degrades to a
|
|
122
|
+
* partial (still useful) summary instead of an unbounded scan.
|
|
123
|
+
*/
|
|
124
|
+
collectionsSummary(): Promise<CollectionsSummaryResponse>;
|
|
125
|
+
/**
|
|
126
|
+
* Full detail of one stored `MediaRecord`, plus signed URLs for its generated conversions. Only
|
|
127
|
+
* conversions carrying a concrete `{disk, path}` artifact get a link — a metadata-only conversion
|
|
128
|
+
* (probe results with no output file) has nothing to preview.
|
|
129
|
+
*/
|
|
130
|
+
mediaRecord(id: string): Promise<MediaDetailResponse>;
|
|
131
|
+
/** Deletes a stored `MediaRecord`. Actions-gated (does not touch its underlying disk object). */
|
|
132
|
+
deleteMediaRecord(id: string): Promise<void>;
|
|
73
133
|
/** Server-side copy (same disk) or streamed cross-disk copy. Original is kept. */
|
|
74
134
|
copy(body: {
|
|
75
135
|
disk: string;
|
|
@@ -89,6 +149,12 @@ export declare class DashboardService {
|
|
|
89
149
|
disk: string;
|
|
90
150
|
keys: string[];
|
|
91
151
|
}): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* Writes an object from a byte stream (a browser upload) — the console's convenience upload,
|
|
154
|
+
* distinct from the resumable TUS path. The caller supplies the full key (prefix + filename).
|
|
155
|
+
* Bounded at {@link MAX_UPLOAD_BYTES} so a runaway upload can't exhaust the process heap. Actions-gated.
|
|
156
|
+
*/
|
|
157
|
+
putObject(diskName: string, key: string, body: AsyncIterable<Uint8Array>, contentType?: string): Promise<void>;
|
|
92
158
|
/**
|
|
93
159
|
* Create a "folder" — a zero-byte marker object at `<prefix>/`, which S3-style delimiter listing
|
|
94
160
|
* surfaces as a navigable folder. Normalizes to exactly one trailing slash (so the key never
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/server/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/server/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EACV,IAAI,EAGJ,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,aAAa,EACb,aAAa,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,gBAAgB,EAChB,sBAAsB,EACtB,0BAA0B,EAE1B,gBAAgB,EAChB,mBAAmB,EAEnB,oBAAoB,EAIpB,sBAAsB,E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