@kidd-cli/core 0.1.2 → 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/dist/{config-BvGapuFJ.js → config-D8e5qxLp.js} +63 -80
- package/dist/config-D8e5qxLp.js.map +1 -0
- package/dist/{create-store-BQUX0tAn.js → create-store-OHdkm_Yt.js} +33 -6
- package/dist/create-store-OHdkm_Yt.js.map +1 -0
- package/dist/index.d.ts +50 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -54
- package/dist/index.js.map +1 -1
- package/dist/lib/config.js +3 -4
- package/dist/lib/logger.d.ts +1 -1
- package/dist/lib/logger.js +1 -2
- package/dist/lib/logger.js.map +1 -1
- package/dist/lib/project.d.ts +1 -1
- package/dist/lib/project.d.ts.map +1 -1
- package/dist/lib/project.js +2 -3
- package/dist/lib/store.d.ts +2 -1
- package/dist/lib/store.d.ts.map +1 -1
- package/dist/lib/store.js +3 -4
- package/dist/{logger-BkQQej8h.d.ts → logger-9j49T5da.d.ts} +1 -1
- package/dist/{logger-BkQQej8h.d.ts.map → logger-9j49T5da.d.ts.map} +1 -1
- package/dist/middleware/auth.d.ts +250 -13
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +1008 -428
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/http.d.ts +10 -16
- package/dist/middleware/http.d.ts.map +1 -1
- package/dist/middleware/http.js +53 -94
- package/dist/middleware/http.js.map +1 -1
- package/dist/{middleware-D3psyhYo.js → middleware-BWnPSRWR.js} +14 -5
- package/dist/{middleware-D3psyhYo.js.map → middleware-BWnPSRWR.js.map} +1 -1
- package/dist/{project-NPtYX2ZX.js → project-D0g84bZY.js} +22 -23
- package/dist/project-D0g84bZY.js.map +1 -0
- package/dist/{types-kjpRau0U.d.ts → types-CTvrsrnD.d.ts} +79 -14
- package/dist/types-CTvrsrnD.d.ts.map +1 -0
- package/dist/{types-Cz9h927W.d.ts → types-D-BxshYM.d.ts} +1 -1
- package/dist/{types-Cz9h927W.d.ts.map → types-D-BxshYM.d.ts.map} +1 -1
- package/package.json +9 -16
- package/dist/config-BvGapuFJ.js.map +0 -1
- package/dist/create-store-BQUX0tAn.js.map +0 -1
- package/dist/lib/output.d.ts +0 -62
- package/dist/lib/output.d.ts.map +0 -1
- package/dist/lib/output.js +0 -276
- package/dist/lib/output.js.map +0 -1
- package/dist/lib/prompts.d.ts +0 -24
- package/dist/lib/prompts.d.ts.map +0 -1
- package/dist/lib/prompts.js +0 -3
- package/dist/project-NPtYX2ZX.js.map +0 -1
- package/dist/prompts-lLfUSgd6.js +0 -63
- package/dist/prompts-lLfUSgd6.js.map +0 -1
- package/dist/types-CqKJhsYk.d.ts +0 -135
- package/dist/types-CqKJhsYk.d.ts.map +0 -1
- package/dist/types-DFtYg5uZ.d.ts +0 -26
- package/dist/types-DFtYg5uZ.d.ts.map +0 -1
- package/dist/types-kjpRau0U.d.ts.map +0 -1
package/dist/lib/logger.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as createCliLogger, n as CliLoggerOptions, r as cliLogger, t as CliLogger } from "../logger-
|
|
1
|
+
import { i as createCliLogger, n as CliLoggerOptions, r as cliLogger, t as CliLogger } from "../logger-9j49T5da.js";
|
|
2
2
|
export { CliLogger, CliLoggerOptions, cliLogger, createCliLogger };
|
package/dist/lib/logger.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as clack from "@clack/prompts";
|
|
2
|
-
|
|
3
2
|
//#region src/lib/logger.ts
|
|
4
3
|
/**
|
|
5
4
|
* Create a new {@link CliLogger} instance.
|
|
@@ -49,7 +48,7 @@ function createCliLogger(options = {}) {
|
|
|
49
48
|
* Default logger instance writing to stderr.
|
|
50
49
|
*/
|
|
51
50
|
const cliLogger = createCliLogger();
|
|
52
|
-
|
|
53
51
|
//#endregion
|
|
54
52
|
export { cliLogger, createCliLogger };
|
|
53
|
+
|
|
55
54
|
//# sourceMappingURL=logger.js.map
|
package/dist/lib/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","names":[],"sources":["../../src/lib/logger.ts"],"sourcesContent":["import * as clack from '@clack/prompts'\n\n/**\n * Options for creating a logger instance.\n */\nexport interface CliLoggerOptions {\n /**\n * Writable stream for raw output methods like {@link CliLogger.print} and {@link CliLogger.newline}.\n * Defaults to `process.stderr`.\n */\n readonly output?: NodeJS.WriteStream\n}\n\n/**\n * Structured logger backed by @clack/prompts for terminal UI output.\n */\nexport interface CliLogger {\n /**\n * Log an informational message.\n */\n info(message: string): void\n /**\n * Log a success message.\n */\n success(message: string): void\n /**\n * Log an error message.\n */\n error(message: string): void\n /**\n * Log a warning message.\n */\n warn(message: string): void\n /**\n * Log a step indicator message.\n */\n step(message: string): void\n /**\n * Log a message with an optional custom symbol prefix.\n */\n message(message: string, opts?: { symbol?: string }): void\n /**\n * Print an intro banner with an optional title.\n */\n intro(title?: string): void\n /**\n * Print an outro banner with an optional closing message.\n */\n outro(message?: string): void\n /**\n * Display a boxed note with an optional title.\n */\n note(message?: string, title?: string): void\n /**\n * Write a blank line to the output stream.\n */\n newline(): void\n /**\n * Write raw text followed by a newline to the output stream.\n */\n print(text: string): void\n}\n\n/**\n * Create a new {@link CliLogger} instance.\n *\n * @param options - Logger configuration.\n * @returns A CliLogger wired to the given output stream.\n */\nexport function createCliLogger(options: CliLoggerOptions = {}): CliLogger {\n const output = options.output ?? process.stderr\n\n return {\n error(message: string): void {\n clack.log.error(message)\n },\n info(message: string): void {\n clack.log.info(message)\n },\n intro(title?: string): void {\n clack.intro(title)\n },\n message(message: string, opts?: { symbol?: string }): void {\n clack.log.message(message, opts)\n },\n newline(): void {\n output.write('\\n')\n },\n note(message?: string, title?: string): void {\n clack.note(message, title)\n },\n outro(message?: string): void {\n clack.outro(message)\n },\n print(text: string): void {\n output.write(`${text}\\n`)\n },\n step(message: string): void {\n clack.log.step(message)\n },\n success(message: string): void {\n clack.log.success(message)\n },\n warn(message: string): void {\n clack.log.warn(message)\n },\n }\n}\n\n/**\n * Default logger instance writing to stderr.\n */\nexport const cliLogger: CliLogger = createCliLogger()\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.js","names":[],"sources":["../../src/lib/logger.ts"],"sourcesContent":["import * as clack from '@clack/prompts'\n\n/**\n * Options for creating a logger instance.\n */\nexport interface CliLoggerOptions {\n /**\n * Writable stream for raw output methods like {@link CliLogger.print} and {@link CliLogger.newline}.\n * Defaults to `process.stderr`.\n */\n readonly output?: NodeJS.WriteStream\n}\n\n/**\n * Structured logger backed by @clack/prompts for terminal UI output.\n */\nexport interface CliLogger {\n /**\n * Log an informational message.\n */\n info(message: string): void\n /**\n * Log a success message.\n */\n success(message: string): void\n /**\n * Log an error message.\n */\n error(message: string): void\n /**\n * Log a warning message.\n */\n warn(message: string): void\n /**\n * Log a step indicator message.\n */\n step(message: string): void\n /**\n * Log a message with an optional custom symbol prefix.\n */\n message(message: string, opts?: { symbol?: string }): void\n /**\n * Print an intro banner with an optional title.\n */\n intro(title?: string): void\n /**\n * Print an outro banner with an optional closing message.\n */\n outro(message?: string): void\n /**\n * Display a boxed note with an optional title.\n */\n note(message?: string, title?: string): void\n /**\n * Write a blank line to the output stream.\n */\n newline(): void\n /**\n * Write raw text followed by a newline to the output stream.\n */\n print(text: string): void\n}\n\n/**\n * Create a new {@link CliLogger} instance.\n *\n * @param options - Logger configuration.\n * @returns A CliLogger wired to the given output stream.\n */\nexport function createCliLogger(options: CliLoggerOptions = {}): CliLogger {\n const output = options.output ?? process.stderr\n\n return {\n error(message: string): void {\n clack.log.error(message)\n },\n info(message: string): void {\n clack.log.info(message)\n },\n intro(title?: string): void {\n clack.intro(title)\n },\n message(message: string, opts?: { symbol?: string }): void {\n clack.log.message(message, opts)\n },\n newline(): void {\n output.write('\\n')\n },\n note(message?: string, title?: string): void {\n clack.note(message, title)\n },\n outro(message?: string): void {\n clack.outro(message)\n },\n print(text: string): void {\n output.write(`${text}\\n`)\n },\n step(message: string): void {\n clack.log.step(message)\n },\n success(message: string): void {\n clack.log.success(message)\n },\n warn(message: string): void {\n clack.log.warn(message)\n },\n }\n}\n\n/**\n * Default logger instance writing to stderr.\n */\nexport const cliLogger: CliLogger = createCliLogger()\n"],"mappings":";;;;;;;;AAqEA,SAAgB,gBAAgB,UAA4B,EAAE,EAAa;CACzE,MAAM,SAAS,QAAQ,UAAU,QAAQ;AAEzC,QAAO;EACL,MAAM,SAAuB;AAC3B,SAAM,IAAI,MAAM,QAAQ;;EAE1B,KAAK,SAAuB;AAC1B,SAAM,IAAI,KAAK,QAAQ;;EAEzB,MAAM,OAAsB;AAC1B,SAAM,MAAM,MAAM;;EAEpB,QAAQ,SAAiB,MAAkC;AACzD,SAAM,IAAI,QAAQ,SAAS,KAAK;;EAElC,UAAgB;AACd,UAAO,MAAM,KAAK;;EAEpB,KAAK,SAAkB,OAAsB;AAC3C,SAAM,KAAK,SAAS,MAAM;;EAE5B,MAAM,SAAwB;AAC5B,SAAM,MAAM,QAAQ;;EAEtB,MAAM,MAAoB;AACxB,UAAO,MAAM,GAAG,KAAK,IAAI;;EAE3B,KAAK,SAAuB;AAC1B,SAAM,IAAI,KAAK,QAAQ;;EAEzB,QAAQ,SAAuB;AAC7B,SAAM,IAAI,QAAQ,QAAQ;;EAE5B,KAAK,SAAuB;AAC1B,SAAM,IAAI,KAAK,QAAQ;;EAE1B;;;;;AAMH,MAAa,YAAuB,iBAAiB"}
|
package/dist/lib/project.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","names":[],"sources":["../../src/lib/project/paths.ts","../../src/lib/project/root.ts"],"mappings":";;;;;AAcA;;;;iBAAgB,gBAAA,CAAiB,OAAA;EAAA,SACtB,OAAA;EAAA,SACA,QAAA;AAAA;;AAeX;;;;;iBAAgB,iBAAA,CAAkB,OAAA;EAAA,SAAoB,OAAA;AAAA;;;;;;
|
|
1
|
+
{"version":3,"file":"project.d.ts","names":[],"sources":["../../src/lib/project/paths.ts","../../src/lib/project/root.ts"],"mappings":";;;;;AAcA;;;;iBAAgB,gBAAA,CAAiB,OAAA;EAAA,SACtB,OAAA;EAAA,SACA,QAAA;AAAA;;AAeX;;;;;iBAAgB,iBAAA,CAAkB,OAAA;EAAA,SAAoB,OAAA;AAAA;;;;;;ACftD;;;;;iBD6BgB,WAAA,CAAY,OAAA,EAAS,kBAAA;;;;;AA/BrC;;;;iBCEgB,eAAA,CAAgB,QAAA,YAAmC,WAAA;;;;;ADenE;;iBCqBgB,aAAA,CAAc,QAAA;;;ADP9B;;;;iBCqBgB,iBAAA,CAAkB,QAAA"}
|
package/dist/lib/project.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { a as getParentRepoRoot, i as findProjectRoot, n as resolveLocalPath, o as isInSubmodule, r as resolvePath, t as resolveGlobalPath } from "../project-
|
|
2
|
-
|
|
3
|
-
export { findProjectRoot, getParentRepoRoot, isInSubmodule, resolveGlobalPath, resolveLocalPath, resolvePath };
|
|
1
|
+
import { a as getParentRepoRoot, i as findProjectRoot, n as resolveLocalPath, o as isInSubmodule, r as resolvePath, t as resolveGlobalPath } from "../project-D0g84bZY.js";
|
|
2
|
+
export { findProjectRoot, getParentRepoRoot, isInSubmodule, resolveGlobalPath, resolveLocalPath, resolvePath };
|
package/dist/lib/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as PathSource } from "../types-
|
|
1
|
+
import { t as PathSource } from "../types-D-BxshYM.js";
|
|
2
2
|
import { Result } from "@kidd-cli/utils/fp";
|
|
3
3
|
|
|
4
4
|
//#region src/lib/store/types.d.ts
|
|
@@ -40,6 +40,7 @@ interface FileStore<TData> {
|
|
|
40
40
|
loadRaw(filename: string, options?: LoadOptions): string | null;
|
|
41
41
|
getFilePath(filename: string, options?: LoadOptions): string | null;
|
|
42
42
|
save(filename: string, data: unknown, options?: SaveOptions): Result<string>;
|
|
43
|
+
remove(filename: string, options?: SaveOptions): Result<string>;
|
|
43
44
|
}
|
|
44
45
|
//#endregion
|
|
45
46
|
//#region src/lib/store/create-store.d.ts
|
package/dist/lib/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","names":[],"sources":["../../src/lib/store/types.ts","../../src/lib/store/create-store.ts"],"mappings":";;;;;;AAUA;;;;KAAY,UAAA;AAKZ;;;AAAA,UAAiB,YAAA;EACf,OAAA;EACA,QAAA,GAAW,KAAA;AAAA;;;;UAMI,WAAA;EACf,MAAA,GAAS,UAAA;EACT,QAAA;AAAA;;;;UAMe,WAAA;EACf,MAAA,GAAS,UAAA;EACT,QAAA;AAAA;;;;UAMe,SAAA;EACf,WAAA,CAAY,QAAA;EACZ,YAAA;EACA,IAAA,CAAK,QAAA,UAAkB,OAAA,GAAU,WAAA,GAAc,KAAA;EAC/C,OAAA,CAAQ,QAAA,UAAkB,OAAA,GAAU,WAAA;EACpC,WAAA,CAAY,QAAA,UAAkB,OAAA,GAAU,WAAA;EACxC,IAAA,CAAK,QAAA,UAAkB,IAAA,WAAe,OAAA,GAAU,WAAA,GAAc,MAAA;AAAA;;;;;;
|
|
1
|
+
{"version":3,"file":"store.d.ts","names":[],"sources":["../../src/lib/store/types.ts","../../src/lib/store/create-store.ts"],"mappings":";;;;;;AAUA;;;;KAAY,UAAA;AAKZ;;;AAAA,UAAiB,YAAA;EACf,OAAA;EACA,QAAA,GAAW,KAAA;AAAA;;;;UAMI,WAAA;EACf,MAAA,GAAS,UAAA;EACT,QAAA;AAAA;;;;UAMe,WAAA;EACf,MAAA,GAAS,UAAA;EACT,QAAA;AAAA;;;;UAMe,SAAA;EACf,WAAA,CAAY,QAAA;EACZ,YAAA;EACA,IAAA,CAAK,QAAA,UAAkB,OAAA,GAAU,WAAA,GAAc,KAAA;EAC/C,OAAA,CAAQ,QAAA,UAAkB,OAAA,GAAU,WAAA;EACpC,WAAA,CAAY,QAAA,UAAkB,OAAA,GAAU,WAAA;EACxC,IAAA,CAAK,QAAA,UAAkB,IAAA,WAAe,OAAA,GAAU,WAAA,GAAc,MAAA;EAC9D,MAAA,CAAO,QAAA,UAAkB,OAAA,GAAU,WAAA,GAAc,MAAA;AAAA;;;;;;AApCnD;;;;iBCSgB,WAAA,iBAAA,CAA6B,OAAA,EAAS,YAAA,CAAa,KAAA,IAAS,SAAA,CAAU,KAAA"}
|
package/dist/lib/store.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "../project-
|
|
2
|
-
import { t as createStore } from "../create-store-
|
|
3
|
-
|
|
4
|
-
export { createStore };
|
|
1
|
+
import "../project-D0g84bZY.js";
|
|
2
|
+
import { t as createStore } from "../create-store-OHdkm_Yt.js";
|
|
3
|
+
export { createStore };
|
|
@@ -73,4 +73,4 @@ declare function createCliLogger(options?: CliLoggerOptions): CliLogger;
|
|
|
73
73
|
declare const cliLogger: CliLogger;
|
|
74
74
|
//#endregion
|
|
75
75
|
export { createCliLogger as i, CliLoggerOptions as n, cliLogger as r, CliLogger as t };
|
|
76
|
-
//# sourceMappingURL=logger-
|
|
76
|
+
//# sourceMappingURL=logger-9j49T5da.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-
|
|
1
|
+
{"version":3,"file":"logger-9j49T5da.d.ts","names":[],"sources":["../src/lib/logger.ts"],"mappings":";;AAKA;;UAAiB,gBAAA;EAKU;;;;EAAA,SAAhB,MAAA,GAAS,MAAA,CAAO,WAAA;AAAA;AAM3B;;;AAAA,UAAiB,SAAA;;;;EAIf,IAAA,CAAK,OAAA;;;;EAIL,OAAA,CAAQ,OAAA;;;;EAIR,KAAA,CAAM,OAAA;;;;EAIN,IAAA,CAAK,OAAA;;;;EAIL,IAAA,CAAK,OAAA;;;;EAIL,OAAA,CAAQ,OAAA,UAAiB,IAAA;IAAS,MAAA;EAAA;EA6BpC;;;EAzBE,KAAA,CAAM,KAAA;;;;EAIN,KAAA,CAAM,OAAA;EAqByD;AA2CjE;;EA5DE,IAAA,CAAK,OAAA,WAAkB,KAAA;EA4DD;;;EAxDtB,OAAA;;;;EAIA,KAAA,CAAM,IAAA;AAAA;;;;;;;iBASQ,eAAA,CAAgB,OAAA,GAAS,gBAAA,GAAwB,SAAA;;;;cA2CpD,SAAA,EAAW,SAAA"}
|
|
@@ -1,22 +1,259 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as Middleware, d as Context } from "../types-CTvrsrnD.js";
|
|
2
|
+
import { AsyncResult } from "@kidd-cli/utils/fp";
|
|
3
3
|
|
|
4
|
+
//#region src/middleware/auth/require.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Options for {@link createAuthRequire}.
|
|
7
|
+
*/
|
|
8
|
+
interface AuthRequireOptions {
|
|
9
|
+
readonly message?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create an enforcement middleware that gates on authentication.
|
|
13
|
+
*
|
|
14
|
+
* When `ctx.auth.authenticated()` returns true, the middleware calls
|
|
15
|
+
* `next()`. When not authenticated, it calls `ctx.fail()` with the
|
|
16
|
+
* provided (or default) message. When `ctx.auth` is absent (auth
|
|
17
|
+
* middleware not configured), it calls `ctx.fail()` with an
|
|
18
|
+
* `AUTH_MIDDLEWARE_MISSING` code.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Optional configuration for the require gate.
|
|
21
|
+
* @returns A Middleware that enforces authentication.
|
|
22
|
+
*/
|
|
23
|
+
declare function createAuthRequire(options?: AuthRequireOptions): Middleware;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/middleware/auth/types.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Bearer token credential — sends `Authorization: Bearer <token>`.
|
|
28
|
+
*/
|
|
29
|
+
interface BearerCredential {
|
|
30
|
+
readonly type: "bearer";
|
|
31
|
+
readonly token: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Basic auth credential — sends `Authorization: Basic base64(user:pass)`.
|
|
35
|
+
*/
|
|
36
|
+
interface BasicCredential {
|
|
37
|
+
readonly type: "basic";
|
|
38
|
+
readonly username: string;
|
|
39
|
+
readonly password: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* API key credential — sends the key in a custom header.
|
|
43
|
+
*/
|
|
44
|
+
interface ApiKeyCredential {
|
|
45
|
+
readonly type: "api-key";
|
|
46
|
+
readonly headerName: string;
|
|
47
|
+
readonly key: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Custom credential — sends arbitrary headers.
|
|
51
|
+
*/
|
|
52
|
+
interface CustomCredential {
|
|
53
|
+
readonly type: "custom";
|
|
54
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Discriminated union of all supported auth credential formats.
|
|
58
|
+
* The `type` field acts as the discriminator.
|
|
59
|
+
*/
|
|
60
|
+
type AuthCredential = BearerCredential | BasicCredential | ApiKeyCredential | CustomCredential;
|
|
61
|
+
/**
|
|
62
|
+
* Resolve credentials from environment variables.
|
|
63
|
+
*/
|
|
64
|
+
interface EnvSourceConfig {
|
|
65
|
+
readonly source: "env";
|
|
66
|
+
readonly tokenVar?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve credentials from a `.env` file parsed with dotenv.
|
|
70
|
+
*/
|
|
71
|
+
interface DotenvSourceConfig {
|
|
72
|
+
readonly source: "dotenv";
|
|
73
|
+
readonly tokenVar?: string;
|
|
74
|
+
readonly path?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolve credentials from a JSON file on disk.
|
|
78
|
+
*/
|
|
79
|
+
interface FileSourceConfig {
|
|
80
|
+
readonly source: "file";
|
|
81
|
+
readonly filename?: string;
|
|
82
|
+
readonly dirName?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Resolve credentials via OAuth 2.0 Authorization Code + PKCE (RFC 7636 + RFC 8252).
|
|
86
|
+
*
|
|
87
|
+
* Opens the user's browser to the authorization URL, receives an auth code
|
|
88
|
+
* via GET redirect to a local server, and exchanges it at the token endpoint
|
|
89
|
+
* with a PKCE code verifier.
|
|
90
|
+
*/
|
|
91
|
+
interface OAuthSourceConfig {
|
|
92
|
+
readonly source: "oauth";
|
|
93
|
+
readonly clientId: string;
|
|
94
|
+
readonly authUrl: string;
|
|
95
|
+
readonly tokenUrl: string;
|
|
96
|
+
readonly scopes?: readonly string[];
|
|
97
|
+
readonly port?: number;
|
|
98
|
+
readonly callbackPath?: string;
|
|
99
|
+
readonly timeout?: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Resolve credentials via OAuth 2.0 Device Authorization Grant (RFC 8628).
|
|
103
|
+
*
|
|
104
|
+
* Requests a device code from the authorization server, displays a
|
|
105
|
+
* verification URL and user code, and polls the token endpoint until
|
|
106
|
+
* the user completes authorization.
|
|
107
|
+
*/
|
|
108
|
+
interface DeviceCodeSourceConfig {
|
|
109
|
+
readonly source: "device-code";
|
|
110
|
+
readonly clientId: string;
|
|
111
|
+
readonly deviceAuthUrl: string;
|
|
112
|
+
readonly tokenUrl: string;
|
|
113
|
+
readonly scopes?: readonly string[];
|
|
114
|
+
readonly pollInterval?: number;
|
|
115
|
+
readonly timeout?: number;
|
|
116
|
+
readonly openBrowser?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Resolve credentials by prompting the user interactively.
|
|
120
|
+
*/
|
|
121
|
+
interface TokenSourceConfig {
|
|
122
|
+
readonly source: "token";
|
|
123
|
+
readonly message?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Resolve credentials via a user-supplied function.
|
|
127
|
+
*/
|
|
128
|
+
interface CustomSourceConfig {
|
|
129
|
+
readonly source: "custom";
|
|
130
|
+
readonly resolver: () => Promise<AuthCredential | null> | AuthCredential | null;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Discriminated union of all supported credential source configurations.
|
|
134
|
+
* The `source` field acts as the discriminator.
|
|
135
|
+
*/
|
|
136
|
+
type StrategyConfig = EnvSourceConfig | DotenvSourceConfig | FileSourceConfig | OAuthSourceConfig | DeviceCodeSourceConfig | TokenSourceConfig | CustomSourceConfig;
|
|
137
|
+
/**
|
|
138
|
+
* Error returned by {@link AuthContext.login} or {@link AuthContext.logout}
|
|
139
|
+
* when the operation fails.
|
|
140
|
+
*/
|
|
141
|
+
interface AuthError {
|
|
142
|
+
readonly type: "no_credential" | "save_failed" | "remove_failed";
|
|
143
|
+
readonly message: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Options accepted by {@link AuthContext.login} to override the default
|
|
147
|
+
* strategy list for a single login attempt.
|
|
148
|
+
*/
|
|
149
|
+
interface LoginOptions {
|
|
150
|
+
readonly strategies?: readonly StrategyConfig[];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Auth context decorated onto `ctx.auth` by the auth middleware.
|
|
154
|
+
*
|
|
155
|
+
* No credential data is stored directly on the context. Instead, callers
|
|
156
|
+
* use `credential()` to read saved credentials on demand and
|
|
157
|
+
* `authenticated()` to check whether a credential exists without exposing it.
|
|
158
|
+
*
|
|
159
|
+
* `login()` runs the configured interactive strategies (OAuth, prompt,
|
|
160
|
+
* etc.), persists the resulting credential to disk, and returns a
|
|
161
|
+
* {@link AsyncResult}.
|
|
162
|
+
*
|
|
163
|
+
* `logout()` removes the stored credential from disk.
|
|
164
|
+
*/
|
|
165
|
+
interface AuthContext {
|
|
166
|
+
readonly credential: () => AuthCredential | null;
|
|
167
|
+
readonly authenticated: () => boolean;
|
|
168
|
+
readonly login: (options?: LoginOptions) => AsyncResult<AuthCredential, AuthError>;
|
|
169
|
+
readonly logout: () => AsyncResult<string, AuthError>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Options for the `auth.env()` builder. Omits the `source` discriminator.
|
|
173
|
+
*/
|
|
174
|
+
type EnvStrategyOptions = Omit<EnvSourceConfig, "source">;
|
|
175
|
+
/**
|
|
176
|
+
* Options for the `auth.dotenv()` builder. Omits the `source` discriminator.
|
|
177
|
+
*/
|
|
178
|
+
type DotenvStrategyOptions = Omit<DotenvSourceConfig, "source">;
|
|
179
|
+
/**
|
|
180
|
+
* Options for the `auth.file()` builder. Omits the `source` discriminator.
|
|
181
|
+
*/
|
|
182
|
+
type FileStrategyOptions = Omit<FileSourceConfig, "source">;
|
|
183
|
+
/**
|
|
184
|
+
* Options for the `auth.oauth()` builder. Omits the `source` discriminator.
|
|
185
|
+
*/
|
|
186
|
+
type OAuthStrategyOptions = Omit<OAuthSourceConfig, "source">;
|
|
187
|
+
/**
|
|
188
|
+
* Options for the `auth.deviceCode()` builder. Omits the `source` discriminator.
|
|
189
|
+
*/
|
|
190
|
+
type DeviceCodeStrategyOptions = Omit<DeviceCodeSourceConfig, "source">;
|
|
191
|
+
/**
|
|
192
|
+
* Options for the `auth.token()` builder. Omits the `source` discriminator.
|
|
193
|
+
*/
|
|
194
|
+
type TokenStrategyOptions = Omit<TokenSourceConfig, "source">;
|
|
195
|
+
/**
|
|
196
|
+
* Function signature accepted by `auth.custom()`.
|
|
197
|
+
*/
|
|
198
|
+
type CustomStrategyFn = () => Promise<AuthCredential | null> | AuthCredential | null;
|
|
199
|
+
/**
|
|
200
|
+
* Options accepted by the `auth()` middleware factory.
|
|
201
|
+
*
|
|
202
|
+
* @property strategies - Ordered list of credential sources to try via `login()`.
|
|
203
|
+
*/
|
|
204
|
+
interface AuthOptions {
|
|
205
|
+
readonly strategies: readonly StrategyConfig[];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Augments the base {@link Context} with an optional `auth` property.
|
|
209
|
+
*
|
|
210
|
+
* When a consumer imports `kidd/auth`, this declaration merges `auth`
|
|
211
|
+
* onto `Context` so that `ctx.auth` is typed without manual casting.
|
|
212
|
+
*/
|
|
213
|
+
declare module "@kidd-cli/core" {
|
|
214
|
+
interface Context {
|
|
215
|
+
readonly auth: AuthContext;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
4
219
|
//#region src/middleware/auth/auth.d.ts
|
|
5
220
|
/**
|
|
6
|
-
*
|
|
221
|
+
* Auth factory interface — callable as a middleware factory and as a
|
|
222
|
+
* namespace for strategy builder functions.
|
|
223
|
+
*/
|
|
224
|
+
interface AuthFactory {
|
|
225
|
+
(options: AuthOptions): Middleware;
|
|
226
|
+
readonly env: (options?: EnvStrategyOptions) => EnvSourceConfig;
|
|
227
|
+
readonly dotenv: (options?: DotenvStrategyOptions) => DotenvSourceConfig;
|
|
228
|
+
readonly file: (options?: FileStrategyOptions) => FileSourceConfig;
|
|
229
|
+
readonly oauth: (options: OAuthStrategyOptions) => OAuthSourceConfig;
|
|
230
|
+
readonly deviceCode: (options: DeviceCodeStrategyOptions) => DeviceCodeSourceConfig;
|
|
231
|
+
readonly token: (options?: TokenStrategyOptions) => TokenSourceConfig;
|
|
232
|
+
readonly apiKey: (options?: TokenStrategyOptions) => TokenSourceConfig;
|
|
233
|
+
readonly custom: (fn: CustomStrategyFn) => CustomSourceConfig;
|
|
234
|
+
readonly headers: () => (ctx: Context) => Readonly<Record<string, string>>;
|
|
235
|
+
readonly require: (options?: AuthRequireOptions) => Middleware;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Auth middleware factory with strategy builder methods.
|
|
7
239
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
240
|
+
* Use as `auth({ strategies: [...] })` to create middleware, or use
|
|
241
|
+
* the builder methods (`auth.env()`, `auth.oauth()`, etc.) to construct
|
|
242
|
+
* strategy configs with a cleaner API.
|
|
243
|
+
*/
|
|
244
|
+
declare const auth: AuthFactory;
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/middleware/auth/headers.d.ts
|
|
247
|
+
/**
|
|
248
|
+
* Create a function that resolves auth credentials from `ctx.auth` into HTTP headers.
|
|
12
249
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
250
|
+
* The returned function reads `ctx.auth.credential()` and converts the credential
|
|
251
|
+
* into the appropriate header format using `buildAuthHeaders()`. Returns an empty
|
|
252
|
+
* record when no auth middleware is present or no credential exists.
|
|
15
253
|
*
|
|
16
|
-
* @
|
|
17
|
-
* @returns A Middleware that decorates ctx.auth.
|
|
254
|
+
* @returns A function that takes a Context and returns auth headers.
|
|
18
255
|
*/
|
|
19
|
-
declare function
|
|
256
|
+
declare function createAuthHeaders(): (ctx: Context) => Readonly<Record<string, string>>;
|
|
20
257
|
//#endregion
|
|
21
|
-
export { type AuthContext, type AuthCredential, type AuthOptions, type
|
|
258
|
+
export { type AuthContext, type AuthCredential, type AuthError, type AuthFactory, type AuthOptions, type AuthRequireOptions, type CustomSourceConfig, type CustomStrategyFn, type DeviceCodeSourceConfig, type DeviceCodeStrategyOptions, type DotenvSourceConfig, type DotenvStrategyOptions, type EnvSourceConfig, type EnvStrategyOptions, type FileSourceConfig, type FileStrategyOptions, type LoginOptions, type OAuthSourceConfig, type OAuthStrategyOptions, type StrategyConfig, type TokenSourceConfig, type TokenStrategyOptions, auth, createAuthHeaders, createAuthRequire };
|
|
22
259
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","names":[],"sources":["../../src/middleware/auth/auth.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","names":[],"sources":["../../src/middleware/auth/require.ts","../../src/middleware/auth/types.ts","../../src/middleware/auth/auth.ts","../../src/middleware/auth/headers.ts"],"mappings":";;;;;;;UAciB,kBAAA;EAAA,SACN,OAAA;AAAA;;;AAeX;;;;;;;;;;iBAAgB,iBAAA,CAAkB,OAAA,GAAU,kBAAA,GAAqB,UAAA;;;;;;UCXhD,gBAAA;EAAA,SACN,IAAA;EAAA,SACA,KAAA;AAAA;;;;UAMM,eAAA;EAA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