@kidd-cli/core 0.2.0 → 0.4.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 +2 -3
- package/dist/{config-Db_sjFU-.js → config-D8e5qxLp.js} +5 -17
- package/dist/config-D8e5qxLp.js.map +1 -0
- package/dist/{create-store-D-fQpCql.js → create-store-OHdkm_Yt.js} +3 -4
- package/dist/{create-store-D-fQpCql.js.map → create-store-OHdkm_Yt.js.map} +1 -1
- package/dist/index.d.ts +36 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +297 -73
- 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 +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 +81 -41
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +287 -233
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/http.d.ts +1 -1
- package/dist/middleware/http.js +163 -4
- package/dist/middleware/http.js.map +1 -1
- package/dist/{middleware-BFBKNSPQ.js → middleware-BWnPSRWR.js} +2 -4
- package/dist/{middleware-BFBKNSPQ.js.map → middleware-BWnPSRWR.js.map} +1 -1
- package/dist/{project-DuXgjaa_.js → project-D0g84bZY.js} +4 -8
- package/dist/project-D0g84bZY.js.map +1 -0
- package/dist/{types-C0CYivzY.d.ts → types-D-BxshYM.d.ts} +1 -1
- package/dist/{types-C0CYivzY.d.ts.map → types-D-BxshYM.d.ts.map} +1 -1
- package/dist/{types-BaZ5WqVM.d.ts → types-U73X_oQ_.d.ts} +60 -10
- package/dist/types-U73X_oQ_.d.ts.map +1 -0
- package/package.json +7 -7
- package/dist/config-Db_sjFU-.js.map +0 -1
- package/dist/create-http-client-tZJWlWp1.js +0 -165
- package/dist/create-http-client-tZJWlWp1.js.map +0 -1
- package/dist/project-DuXgjaa_.js.map +0 -1
- package/dist/types-BaZ5WqVM.d.ts.map +0 -1
|
@@ -1,6 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { p as Context, u as Middleware } from "../types-U73X_oQ_.js";
|
|
2
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
|
|
4
25
|
//#region src/middleware/auth/types.d.ts
|
|
5
26
|
/**
|
|
6
27
|
* Bearer token credential — sends `Authorization: Bearer <token>`.
|
|
@@ -112,23 +133,40 @@ interface CustomSourceConfig {
|
|
|
112
133
|
* Discriminated union of all supported credential source configurations.
|
|
113
134
|
* The `source` field acts as the discriminator.
|
|
114
135
|
*/
|
|
115
|
-
type
|
|
136
|
+
type StrategyConfig = EnvSourceConfig | DotenvSourceConfig | FileSourceConfig | OAuthSourceConfig | DeviceCodeSourceConfig | TokenSourceConfig | CustomSourceConfig;
|
|
137
|
+
/**
|
|
138
|
+
* Callback that validates a resolved credential before it is persisted.
|
|
139
|
+
*
|
|
140
|
+
* Returning a successful Result allows the credential to be saved (the
|
|
141
|
+
* returned credential is what gets persisted, so the callback may also
|
|
142
|
+
* enrich or transform it). Returning a failure Result prevents persistence
|
|
143
|
+
* and surfaces the error to the caller.
|
|
144
|
+
*/
|
|
145
|
+
type ValidateCredential = (credential: AuthCredential) => AsyncResult<AuthCredential, AuthError>;
|
|
116
146
|
/**
|
|
117
147
|
* Error returned by {@link AuthContext.login} or {@link AuthContext.logout}
|
|
118
148
|
* when the operation fails.
|
|
119
149
|
*/
|
|
120
150
|
interface AuthError {
|
|
121
|
-
readonly type: "no_credential" | "save_failed" | "remove_failed";
|
|
151
|
+
readonly type: "no_credential" | "save_failed" | "remove_failed" | "validation_failed";
|
|
122
152
|
readonly message: string;
|
|
123
153
|
}
|
|
124
154
|
/**
|
|
155
|
+
* Options accepted by {@link AuthContext.login} to override the default
|
|
156
|
+
* strategy list for a single login attempt.
|
|
157
|
+
*/
|
|
158
|
+
interface LoginOptions {
|
|
159
|
+
readonly strategies?: readonly StrategyConfig[];
|
|
160
|
+
readonly validate?: ValidateCredential;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
125
163
|
* Auth context decorated onto `ctx.auth` by the auth middleware.
|
|
126
164
|
*
|
|
127
165
|
* No credential data is stored directly on the context. Instead, callers
|
|
128
166
|
* use `credential()` to read saved credentials on demand and
|
|
129
167
|
* `authenticated()` to check whether a credential exists without exposing it.
|
|
130
168
|
*
|
|
131
|
-
* `login()` runs the configured interactive
|
|
169
|
+
* `login()` runs the configured interactive strategies (OAuth, prompt,
|
|
132
170
|
* etc.), persists the resulting credential to disk, and returns a
|
|
133
171
|
* {@link AsyncResult}.
|
|
134
172
|
*
|
|
@@ -137,58 +175,46 @@ interface AuthError {
|
|
|
137
175
|
interface AuthContext {
|
|
138
176
|
readonly credential: () => AuthCredential | null;
|
|
139
177
|
readonly authenticated: () => boolean;
|
|
140
|
-
readonly login: () => AsyncResult<AuthCredential, AuthError>;
|
|
178
|
+
readonly login: (options?: LoginOptions) => AsyncResult<AuthCredential, AuthError>;
|
|
141
179
|
readonly logout: () => AsyncResult<string, AuthError>;
|
|
142
180
|
}
|
|
143
181
|
/**
|
|
144
182
|
* Options for the `auth.env()` builder. Omits the `source` discriminator.
|
|
145
183
|
*/
|
|
146
|
-
type
|
|
184
|
+
type EnvStrategyOptions = Omit<EnvSourceConfig, "source">;
|
|
147
185
|
/**
|
|
148
186
|
* Options for the `auth.dotenv()` builder. Omits the `source` discriminator.
|
|
149
187
|
*/
|
|
150
|
-
type
|
|
188
|
+
type DotenvStrategyOptions = Omit<DotenvSourceConfig, "source">;
|
|
151
189
|
/**
|
|
152
190
|
* Options for the `auth.file()` builder. Omits the `source` discriminator.
|
|
153
191
|
*/
|
|
154
|
-
type
|
|
192
|
+
type FileStrategyOptions = Omit<FileSourceConfig, "source">;
|
|
155
193
|
/**
|
|
156
194
|
* Options for the `auth.oauth()` builder. Omits the `source` discriminator.
|
|
157
195
|
*/
|
|
158
|
-
type
|
|
196
|
+
type OAuthStrategyOptions = Omit<OAuthSourceConfig, "source">;
|
|
159
197
|
/**
|
|
160
198
|
* Options for the `auth.deviceCode()` builder. Omits the `source` discriminator.
|
|
161
199
|
*/
|
|
162
|
-
type
|
|
200
|
+
type DeviceCodeStrategyOptions = Omit<DeviceCodeSourceConfig, "source">;
|
|
163
201
|
/**
|
|
164
202
|
* Options for the `auth.token()` builder. Omits the `source` discriminator.
|
|
165
203
|
*/
|
|
166
|
-
type
|
|
204
|
+
type TokenStrategyOptions = Omit<TokenSourceConfig, "source">;
|
|
167
205
|
/**
|
|
168
206
|
* Function signature accepted by `auth.custom()`.
|
|
169
207
|
*/
|
|
170
|
-
type
|
|
171
|
-
/**
|
|
172
|
-
* Configuration for an HTTP client created by the auth middleware.
|
|
173
|
-
*
|
|
174
|
-
* When provided on {@link AuthOptions}, the auth middleware creates an HTTP
|
|
175
|
-
* client with automatic credential header injection and decorates it onto
|
|
176
|
-
* `ctx[namespace]`.
|
|
177
|
-
*/
|
|
178
|
-
interface AuthHttpOptions {
|
|
179
|
-
readonly baseUrl: string;
|
|
180
|
-
readonly namespace: string;
|
|
181
|
-
readonly headers?: Readonly<Record<string, string>>;
|
|
182
|
-
}
|
|
208
|
+
type CustomStrategyFn = () => Promise<AuthCredential | null> | AuthCredential | null;
|
|
183
209
|
/**
|
|
184
210
|
* Options accepted by the `auth()` middleware factory.
|
|
185
211
|
*
|
|
186
|
-
* @property
|
|
187
|
-
* @property
|
|
212
|
+
* @property strategies - Ordered list of credential sources to try via `login()`.
|
|
213
|
+
* @property validate - Optional callback to validate a credential before persisting.
|
|
188
214
|
*/
|
|
189
215
|
interface AuthOptions {
|
|
190
|
-
readonly
|
|
191
|
-
readonly
|
|
216
|
+
readonly strategies: readonly StrategyConfig[];
|
|
217
|
+
readonly validate?: ValidateCredential;
|
|
192
218
|
}
|
|
193
219
|
/**
|
|
194
220
|
* Augments the base {@link Context} with an optional `auth` property.
|
|
@@ -205,27 +231,41 @@ declare module "@kidd-cli/core" {
|
|
|
205
231
|
//#region src/middleware/auth/auth.d.ts
|
|
206
232
|
/**
|
|
207
233
|
* Auth factory interface — callable as a middleware factory and as a
|
|
208
|
-
* namespace for
|
|
234
|
+
* namespace for strategy builder functions.
|
|
209
235
|
*/
|
|
210
236
|
interface AuthFactory {
|
|
211
237
|
(options: AuthOptions): Middleware;
|
|
212
|
-
readonly env: (options?:
|
|
213
|
-
readonly dotenv: (options?:
|
|
214
|
-
readonly file: (options?:
|
|
215
|
-
readonly oauth: (options:
|
|
216
|
-
readonly deviceCode: (options:
|
|
217
|
-
readonly token: (options?:
|
|
218
|
-
readonly apiKey: (options?:
|
|
219
|
-
readonly custom: (
|
|
238
|
+
readonly env: (options?: EnvStrategyOptions) => EnvSourceConfig;
|
|
239
|
+
readonly dotenv: (options?: DotenvStrategyOptions) => DotenvSourceConfig;
|
|
240
|
+
readonly file: (options?: FileStrategyOptions) => FileSourceConfig;
|
|
241
|
+
readonly oauth: (options: OAuthStrategyOptions) => OAuthSourceConfig;
|
|
242
|
+
readonly deviceCode: (options: DeviceCodeStrategyOptions) => DeviceCodeSourceConfig;
|
|
243
|
+
readonly token: (options?: TokenStrategyOptions) => TokenSourceConfig;
|
|
244
|
+
readonly apiKey: (options?: TokenStrategyOptions) => TokenSourceConfig;
|
|
245
|
+
readonly custom: (fn: CustomStrategyFn) => CustomSourceConfig;
|
|
246
|
+
readonly headers: () => (ctx: Context) => Readonly<Record<string, string>>;
|
|
247
|
+
readonly require: (options?: AuthRequireOptions) => Middleware;
|
|
220
248
|
}
|
|
221
249
|
/**
|
|
222
|
-
* Auth middleware factory with
|
|
250
|
+
* Auth middleware factory with strategy builder methods.
|
|
223
251
|
*
|
|
224
|
-
* Use as `auth({
|
|
252
|
+
* Use as `auth({ strategies: [...] })` to create middleware, or use
|
|
225
253
|
* the builder methods (`auth.env()`, `auth.oauth()`, etc.) to construct
|
|
226
|
-
*
|
|
254
|
+
* strategy configs with a cleaner API.
|
|
227
255
|
*/
|
|
228
256
|
declare const auth: AuthFactory;
|
|
229
257
|
//#endregion
|
|
230
|
-
|
|
258
|
+
//#region src/middleware/auth/headers.d.ts
|
|
259
|
+
/**
|
|
260
|
+
* Create a function that resolves auth credentials from `ctx.auth` into HTTP headers.
|
|
261
|
+
*
|
|
262
|
+
* The returned function reads `ctx.auth.credential()` and converts the credential
|
|
263
|
+
* into the appropriate header format using `buildAuthHeaders()`. Returns an empty
|
|
264
|
+
* record when no auth middleware is present or no credential exists.
|
|
265
|
+
*
|
|
266
|
+
* @returns A function that takes a Context and returns auth headers.
|
|
267
|
+
*/
|
|
268
|
+
declare function createAuthHeaders(): (ctx: Context) => Readonly<Record<string, string>>;
|
|
269
|
+
//#endregion
|
|
270
|
+
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, type ValidateCredential, auth, createAuthHeaders, createAuthRequire };
|
|
231
271
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","names":[],"sources":["../../src/middleware/auth/types.ts","../../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;EAAA,SACN,IAAA;EAAA,SACA,QAAA;EAAA,SACA,QAAA;AAAA;;AAHX;;UASiB,gBAAA;EAAA,SACN,IAAA;EAAA,SACA,UAAA;EAAA,SACA,GAAA;AAAA;;;AAHX;UASiB,gBAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA,EAAS,QAAA,CAAS,MAAA;AAAA;;;;;KAOjB,cAAA,GACR,gBAAA,GACA,eAAA,GACA,gBAAA,GACA,gBAAA;;;;UASa,eAAA;EAAA,SACN,MAAA;EAAA,SACA,QAAA;AAAA;;;AAfX;UAqBiB,kBAAA;EAAA,SACN,MAAA;EAAA,SACA,QAAA;EAA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