@airdraft/plugin-auth 0.1.0 → 0.1.1
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 +34 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/withAutoAuth.d.ts +28 -0
- package/dist/withAutoAuth.d.ts.map +1 -0
- package/dist/withAutoAuth.js +61 -0
- package/dist/withAutoAuth.js.map +1 -0
- package/package.json +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
### [0.1.1](https://github.com/aevrHQ/airdraft/compare/plugin-auth@v0.1.0...plugin-auth@v0.1.1) (2026-05-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add Next.js app detection and prompt for app directory in init commands ([2ed1afd](https://github.com/aevrHQ/airdraft/commit/2ed1afdd1ba3142fd50a9bfd4133f01c2ad22ae9))
|
|
11
|
+
* add schema editor plugin and GitHub schema adapter for managing airdraft.schema.json ([46fd7f2](https://github.com/aevrHQ/airdraft/commit/46fd7f271afe8bc562d5f2fe72b94390cb257161))
|
|
12
|
+
* add versioning and changelog support for all packages ([d6c85df](https://github.com/aevrHQ/airdraft/commit/d6c85dfed37f11c42151c93b49a80ede90699616))
|
|
13
|
+
* **cli,core,docs:** implement local filesystem mode with enhanced initialization and error handling ([1848408](https://github.com/aevrHQ/airdraft/commit/1848408738ee3d2bfa0ef532e6dec7a3beef0fb1))
|
|
14
|
+
* **cli:** add CMS client template and optional blog scaffolding to initialization ([cf7bda8](https://github.com/aevrHQ/airdraft/commit/cf7bda8137777aa319acd8edf55fb2cd718a9cd1))
|
|
15
|
+
* **cli:** enhance project initialization templates with schema path support ([a3b20c9](https://github.com/aevrHQ/airdraft/commit/a3b20c9d0dbf0e23594079f1685be8d688e7779b))
|
|
16
|
+
* **client:** add convenience methods for listing and retrieving entries ([c48e3f6](https://github.com/aevrHQ/airdraft/commit/c48e3f6848772bf1ed860785e1e3f9eadffb5ddc))
|
|
17
|
+
* **content:** update content package with new field components and type changes ([e1bd5fa](https://github.com/aevrHQ/airdraft/commit/e1bd5fa8af9b2903024c39a0fa945e49f87754d3))
|
|
18
|
+
* enhance media input components and add scoped media adapter for project isolation ([e599cf2](https://github.com/aevrHQ/airdraft/commit/e599cf2c488cf73164d1cb7b1ce479d6005cf923))
|
|
19
|
+
* implement terminal UI helpers for improved user interaction ([0e0dca4](https://github.com/aevrHQ/airdraft/commit/0e0dca4a4e06196abea22e99c9a350fdd202a948))
|
|
20
|
+
* **react-ui:** add CMSAdmin component and update related files for new admin functionality ([50f1459](https://github.com/aevrHQ/airdraft/commit/50f14598c268823615f61428ee1e0e399c610630))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* improve error handling for missing schema file in buildProjectHandler ([4c3d318](https://github.com/aevrHQ/airdraft/commit/4c3d3184c9c454062fd2d9b33fb0593d5e91b71c))
|
|
26
|
+
* update cloud package version to 0.1.4 and enhance audit log persistence logic ([e1fb0e5](https://github.com/aevrHQ/airdraft/commit/e1fb0e5509c7f95c4e659495bcdbd1339da20cea))
|
|
27
|
+
* update package versions and enhance schema cache handling ([7f4f395](https://github.com/aevrHQ/airdraft/commit/7f4f39572168b4e75dd6f1d756ebd5ef2d7ddbe1))
|
|
28
|
+
* update schema URL from airdraft.dev to airdraft.space ([dbace6e](https://github.com/aevrHQ/airdraft/commit/dbace6e13334f915feace70661810d5dc919f69b))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Documentation
|
|
32
|
+
|
|
33
|
+
* add Releasing & Publishing section to README ([132193b](https://github.com/aevrHQ/airdraft/commit/132193bebff585ad3223ccb82176c30615f21443))
|
|
34
|
+
|
|
35
|
+
# Changelog
|
|
36
|
+
|
|
3
37
|
All notable changes to `@airdraft/plugin-auth` will be documented here.
|
|
4
38
|
|
|
5
39
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { withAuth, getRequestUser } from './withAuth.js';
|
|
2
|
+
export { withAutoAuth } from './withAutoAuth.js';
|
|
3
|
+
export type { WithAutoAuthOptions } from './withAutoAuth.js';
|
|
2
4
|
export type { WithAuthOptions, AuthProvider, AuthUser, Role, RolePermissions, RouteHandlerDef } from './types.js';
|
|
3
5
|
export { ROLE_PERMISSIONS, can } from './types.js';
|
|
4
6
|
export { UserStore } from './UserStore.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACxD,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjH,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAC5D,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AACjH,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,YAAY,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAA;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { withAuth, getRequestUser } from './withAuth.js';
|
|
2
|
+
export { withAutoAuth } from './withAutoAuth.js';
|
|
2
3
|
export { ROLE_PERMISSIONS, can } from './types.js';
|
|
3
4
|
export { UserStore } from './UserStore.js';
|
|
4
5
|
export { CredentialsProvider } from './CredentialsProvider.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGhD,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAE9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Plugin } from '@airdraft/core';
|
|
2
|
+
export interface WithAutoAuthOptions {
|
|
3
|
+
/**
|
|
4
|
+
* URL path suffixes that bypass auth entirely.
|
|
5
|
+
* Default: ['/schema', '/openapi.json']
|
|
6
|
+
*/
|
|
7
|
+
publicPaths?: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Builds an auth plugin automatically from environment variables — no
|
|
11
|
+
* boilerplate required in `airdraft.config.ts`.
|
|
12
|
+
*
|
|
13
|
+
* Resolution order:
|
|
14
|
+
* - `AIRDRAFT_JWT_SECRET` + `CMS_API_KEY` → CredentialsProvider accepting
|
|
15
|
+
* both cookie sessions and the API key as a Bearer / x-api-key header.
|
|
16
|
+
* - `AIRDRAFT_JWT_SECRET` only → CredentialsProvider (email/password).
|
|
17
|
+
* - `CMS_API_KEY` only → simple single-key inline provider.
|
|
18
|
+
* - Neither set → returns `null` (CMS API is unprotected — local dev only).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { withAutoAuth } from '@airdraft/plugin-auth'
|
|
23
|
+
*
|
|
24
|
+
* plugins: [withAutoAuth() ?? []] // spread-safe null
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function withAutoAuth(options?: WithAutoAuthOptions): Plugin | null;
|
|
28
|
+
//# sourceMappingURL=withAutoAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAutoAuth.d.ts","sourceRoot":"","sources":["../src/withAutoAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAM5C,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,GAAG,IAAI,CAyC7E"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CredentialsProvider } from './CredentialsProvider.js';
|
|
2
|
+
import { UserStore } from './UserStore.js';
|
|
3
|
+
import { withAuth } from './withAuth.js';
|
|
4
|
+
/**
|
|
5
|
+
* Builds an auth plugin automatically from environment variables — no
|
|
6
|
+
* boilerplate required in `airdraft.config.ts`.
|
|
7
|
+
*
|
|
8
|
+
* Resolution order:
|
|
9
|
+
* - `AIRDRAFT_JWT_SECRET` + `CMS_API_KEY` → CredentialsProvider accepting
|
|
10
|
+
* both cookie sessions and the API key as a Bearer / x-api-key header.
|
|
11
|
+
* - `AIRDRAFT_JWT_SECRET` only → CredentialsProvider (email/password).
|
|
12
|
+
* - `CMS_API_KEY` only → simple single-key inline provider.
|
|
13
|
+
* - Neither set → returns `null` (CMS API is unprotected — local dev only).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { withAutoAuth } from '@airdraft/plugin-auth'
|
|
18
|
+
*
|
|
19
|
+
* plugins: [withAutoAuth() ?? []] // spread-safe null
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export function withAutoAuth(options = {}) {
|
|
23
|
+
const jwtSecret = process.env.AIRDRAFT_JWT_SECRET;
|
|
24
|
+
const apiKey = process.env.CMS_API_KEY;
|
|
25
|
+
const publicPaths = options.publicPaths ?? ['/schema', '/openapi.json'];
|
|
26
|
+
if (!jwtSecret && !apiKey)
|
|
27
|
+
return null;
|
|
28
|
+
if (jwtSecret) {
|
|
29
|
+
const credProvider = CredentialsProvider({ userStore: UserStore.json(), secret: jwtSecret });
|
|
30
|
+
const provider = apiKey
|
|
31
|
+
? {
|
|
32
|
+
verify: async (req) => {
|
|
33
|
+
const bearer = req.headers.get('authorization') ?? '';
|
|
34
|
+
const token = bearer.startsWith('Bearer ')
|
|
35
|
+
? bearer.slice(7)
|
|
36
|
+
: (req.headers.get('x-api-key') ?? null);
|
|
37
|
+
if (token === apiKey)
|
|
38
|
+
return { id: 'api-key', email: 'api@local', role: 'admin' };
|
|
39
|
+
return credProvider.verify(req);
|
|
40
|
+
},
|
|
41
|
+
handlers: credProvider.handlers,
|
|
42
|
+
refresh: credProvider.refresh,
|
|
43
|
+
}
|
|
44
|
+
: credProvider;
|
|
45
|
+
return withAuth({ provider, publicPaths });
|
|
46
|
+
}
|
|
47
|
+
// API key only
|
|
48
|
+
return withAuth({
|
|
49
|
+
provider: {
|
|
50
|
+
async verify(req) {
|
|
51
|
+
const bearer = req.headers.get('authorization') ?? '';
|
|
52
|
+
const token = bearer.startsWith('Bearer ')
|
|
53
|
+
? bearer.slice(7)
|
|
54
|
+
: (req.headers.get('x-api-key') ?? null);
|
|
55
|
+
return token === apiKey ? { id: 'api-key', email: 'api@local', role: 'admin' } : null;
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
publicPaths,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=withAutoAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withAutoAuth.js","sourceRoot":"","sources":["../src/withAutoAuth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAUxC;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,YAAY,CAAC,UAA+B,EAAE;IAC5D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAA;IACjD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;IACtC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,CAAA;IAEvE,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAEtC,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,YAAY,GAAG,mBAAmB,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAA;QAE5F,MAAM,QAAQ,GAAiB,MAAM;YACnC,CAAC,CAAC;gBACE,MAAM,EAAE,KAAK,EAAE,GAAY,EAA4B,EAAE;oBACvD,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,CAAA;oBACrD,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC;wBACxC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;wBACjB,CAA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
|
|
4
4
|
"description": "Airdraft auth plugin — GitHub OAuth, email/password providers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"files": [
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"CHANGELOG.md"
|
|
18
|
+
],
|
|
15
19
|
"scripts": {
|
|
16
20
|
"build": "tsc",
|
|
17
21
|
"dev": "tsc --watch",
|
|
@@ -25,7 +29,9 @@
|
|
|
25
29
|
"release:minor": "standard-version --release-as minor",
|
|
26
30
|
"release:major": "standard-version --release-as major"
|
|
27
31
|
},
|
|
28
|
-
"publishConfig": {
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
29
35
|
"license": "MIT",
|
|
30
36
|
"devDependencies": {
|
|
31
37
|
"@types/node": "^20.0.0",
|
|
@@ -38,5 +44,7 @@
|
|
|
38
44
|
"@airdraft/core": "*",
|
|
39
45
|
"@airdraft/auth": "*"
|
|
40
46
|
},
|
|
41
|
-
"engines": {
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
}
|
|
42
50
|
}
|