@tryghost/adapter-base-sso 0.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013-2026 Ghost Foundation
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @tryghost/adapter-base-sso
2
+
3
+ The adapter-base-sso package for Ghost.
4
+
5
+ ## Develop
6
+
7
+ This is a workspace package in the Ghost monorepo. From the repo root:
8
+
9
+ ```bash
10
+ pnpm --filter @tryghost/adapter-base-sso build # compile to build/ with tsc (ESM)
11
+ pnpm --filter @tryghost/adapter-base-sso test # type-check + unit tests
12
+ pnpm --filter @tryghost/adapter-base-sso dev # rebuild on change
13
+ ```
14
+
15
+ In-monorepo consumers resolve this package via the `source` export condition
16
+ (raw `src/*.ts`, no build needed in dev/test). Production and any published
17
+ tarball use the compiled `build/` output.
18
+
19
+ This package is ESM-only and compiled with `tsc` (`module: nodenext`). Relative
20
+ imports in `src/` must carry an explicit extension; write the real `.ts` one —
21
+ `import {x} from './x.ts'` — and `tsc` rewrites it to `.js` on emit
22
+ (`rewriteRelativeImportExtensions`).
23
+
24
+ `ghost/core` is CommonJS but consumes this package via `require()`, which works
25
+ on Ghost's Node version (22.13+/24) through Node's `require(esm)` support. That
26
+ support has one hard constraint: **no top-level `await`** anywhere in this
27
+ package's module graph — it makes the graph async and `require()` of it throws
28
+ `ERR_REQUIRE_ASYNC_MODULE`. Keep module-level initialization synchronous. (An
29
+ ESLint rule enforces this.)
@@ -0,0 +1,50 @@
1
+ import type { Request } from 'express';
2
+ export interface User {
3
+ id: string;
4
+ email: string;
5
+ }
6
+ /**
7
+ * A small set of user lookups that Ghost injects into the SSO adapter, so that
8
+ * adapter implementations can resolve users without reaching into Ghost's model
9
+ * layer directly.
10
+ *
11
+ * Ghost core provides the implementation (backed by the User model) via
12
+ * `SSOBase.setUserRepository`; adapter implementations consume it through the
13
+ * protected `getUserByEmail` / `getOwnerUser` helpers on `SSOBase`.
14
+ */
15
+ export interface UserRepository {
16
+ /** Look up a single user by their email address, or `null` if none exists. */
17
+ getByEmail(email: string): Promise<User | null>;
18
+ /** Look up the site owner user, or `null` if none exists. */
19
+ getOwner(): Promise<User | null>;
20
+ }
21
+ export interface SSOAdapter<Token, Lookup> {
22
+ getRequestCredentials(request: Request): Promise<Token | null>;
23
+ getIdentityFromCredentials(credentials: Token): Promise<Lookup | null>;
24
+ getUserForIdentity(identity: Lookup): Promise<User | null>;
25
+ }
26
+ export declare abstract class SSOBase<Token, Lookup> implements SSOAdapter<Token, Lookup> {
27
+ #private;
28
+ readonly requiredFns: readonly ['getRequestCredentials', 'getIdentityFromCredentials', 'getUserForIdentity'];
29
+ constructor();
30
+ /**
31
+ * Inject the user repository. Ghost core calls this after constructing the
32
+ * adapter, supplying an implementation backed by the User model. Adapter
33
+ * implementations should not call this themselves.
34
+ */
35
+ setUserRepository(userRepository: UserRepository): void;
36
+ /**
37
+ * Look up a single user by email. Available to adapter implementations so
38
+ * they can resolve users without depending on Ghost's model layer.
39
+ */
40
+ protected getUserByEmail(email: string): Promise<User | null>;
41
+ /**
42
+ * Look up the site owner user. Available to adapter implementations so they
43
+ * can resolve the owner without depending on Ghost's model layer.
44
+ */
45
+ protected getOwnerUser(): Promise<User | null>;
46
+ abstract getRequestCredentials(request: Request): Promise<Token | null>;
47
+ abstract getIdentityFromCredentials(credentials: Token): Promise<Lookup | null>;
48
+ abstract getUserForIdentity(identity: Lookup): Promise<User | null>;
49
+ }
50
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,SAAS,CAAC;AAGrC,MAAM,WAAW,IAAI;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAc;IAC3B,8EAA8E;IAC9E,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAChD,6DAA6D;IAC7D,QAAQ,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU,CAAC,KAAK,EAAE,MAAM;IACrC,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IAC/D,0BAA0B,CAAC,WAAW,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;CAC9D;AAED,8BAAsB,OAAO,CAAC,KAAK,EAAE,MAAM,CAAE,YAAW,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC;;IAC7E,SAAiB,WAAW,EAAE,SAAS,CAAC,uBAAuB,EAAE,4BAA4B,EAAE,oBAAoB,CAAC,CAAC;IAIrH,cAKC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,cAAc,EAAE,cAAc,GAAG,IAAI,CAEtD;IAWD;;;OAGG;IACH,UAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAElE;IAED;;;OAGG;IACH,UAAgB,YAAY,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAEnD;IAED,QAAQ,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACxE,QAAQ,CAAC,0BAA0B,CAAC,WAAW,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChF,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;CACvE"}
package/build/base.js ADDED
@@ -0,0 +1,41 @@
1
+ import errors from '@tryghost/errors';
2
+ export class SSOBase {
3
+ #userRepository = null;
4
+ constructor() {
5
+ Object.defineProperty(this, 'requiredFns', {
6
+ value: Object.freeze(['getRequestCredentials', 'getIdentityFromCredentials', 'getUserForIdentity']),
7
+ writable: false,
8
+ });
9
+ }
10
+ /**
11
+ * Inject the user repository. Ghost core calls this after constructing the
12
+ * adapter, supplying an implementation backed by the User model. Adapter
13
+ * implementations should not call this themselves.
14
+ */
15
+ setUserRepository(userRepository) {
16
+ this.#userRepository = userRepository;
17
+ }
18
+ get #users() {
19
+ if (!this.#userRepository) {
20
+ throw new errors.IncorrectUsageError({
21
+ message: 'SSO adapter has no user repository configured. Ghost must call setUserRepository() before the adapter is used.'
22
+ });
23
+ }
24
+ return this.#userRepository;
25
+ }
26
+ /**
27
+ * Look up a single user by email. Available to adapter implementations so
28
+ * they can resolve users without depending on Ghost's model layer.
29
+ */
30
+ async getUserByEmail(email) {
31
+ return this.#users.getByEmail(email);
32
+ }
33
+ /**
34
+ * Look up the site owner user. Available to adapter implementations so they
35
+ * can resolve the owner without depending on Ghost's model layer.
36
+ */
37
+ async getOwnerUser() {
38
+ return this.#users.getOwner();
39
+ }
40
+ }
41
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AA6BtC,MAAM,OAAgB,OAAO;IAGzB,eAAe,GAA0B,IAAI,CAAC;IAE9C;QACI,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE;YACvC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,uBAAuB,EAAE,4BAA4B,EAAE,oBAAoB,CAAC,CAAC;YACnG,QAAQ,EAAE,KAAK;SAClB,CAAC,CAAC;IACP,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,cAA8B;QAC5C,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;IAC1C,CAAC;IAED,IAAI,MAAM;QACN,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;YACxB,MAAM,IAAI,MAAM,CAAC,mBAAmB,CAAC;gBACjC,OAAO,EAAE,gHAAgH;aAC5H,CAAC,CAAC;QACP,CAAC;QACD,OAAO,IAAI,CAAC,eAAe,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,cAAc,CAAC,KAAa;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,YAAY;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClC,CAAC;CAKJ"}
@@ -0,0 +1,2 @@
1
+ export * from './base.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
package/build/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './base.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@tryghost/adapter-base-sso",
3
+ "version": "0.1.0",
4
+ "description": "The adapter-base-sso package for Ghost.",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/TryGhost/Ghost.git",
9
+ "directory": "packages/adapters/sso-base"
10
+ },
11
+ "author": "Ghost Foundation",
12
+ "license": "MIT",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./build/index.d.ts",
16
+ "default": "./build/index.js"
17
+ }
18
+ },
19
+ "main": "build/index.js",
20
+ "types": "build/index.d.ts",
21
+ "files": [
22
+ "build"
23
+ ],
24
+ "dependencies": {
25
+ "@tryghost/errors": "1.3.13"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc",
29
+ "test:unit": "NODE_ENV=testing vitest run --coverage",
30
+ "test": "pnpm run '/^test:/'",
31
+ "test:types": "tsc --noEmit -p test/tsconfig.json",
32
+ "lint:code": "eslint src/ --cache",
33
+ "lint:test": "eslint test/ --cache",
34
+ "lint": "pnpm run '/^lint:/'"
35
+ }
36
+ }