@ghostly-solutions/auth 0.2.1 → 0.2.3

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,13 @@
1
+ Proprietary License
2
+
3
+ Copyright (c) Ghostly Solutions.
4
+ All rights reserved.
5
+
6
+ This repository and all source code, configuration, documentation, and related materials
7
+ are proprietary and confidential unless a separate written agreement states otherwise.
8
+
9
+ No permission is granted to use, copy, modify, distribute, sublicense, publish, or sell
10
+ any part of this repository without prior written authorization from Ghostly Solutions.
11
+
12
+ Third-party components included through declared package managers remain subject to their
13
+ own licenses.
package/README.md CHANGED
@@ -1,13 +1,149 @@
1
1
  # @ghostly-solutions/auth
2
2
 
3
+ ## Purpose
4
+
3
5
  Authentication SDK for Ghostly Solutions products.
4
6
 
5
- The SDK is OAuth redirect + server-owned cookie session. Client code does not process OAuth
6
- callback tokens and does not define auth route handlers.
7
+ This repository contains the npm package that implements a browser-first OAuth redirect flow
8
+ backed by a server-owned cookie session. Client code does not parse callback tokens and does not
9
+ define auth route handlers.
10
+
11
+ Repository type: `lib-repo`.
12
+
13
+ ## Architecture
14
+
15
+ Package entrypoints:
16
+
17
+ - `@ghostly-solutions/auth`: browser/core client
18
+ - `@ghostly-solutions/auth/react`: React provider and session gates
19
+ - `@ghostly-solutions/auth/next`: Next.js server helpers
20
+ - `@ghostly-solutions/auth/extension`: extension-oriented auth helpers
21
+
22
+ The SDK assumes a fixed Ghostly Auth API surface and keeps token handling server-owned.
23
+
24
+ ## Stack
25
+
26
+ - TypeScript
27
+ - tsup
28
+ - Vitest
29
+ - Biome
30
+ - npm
31
+
32
+ ## Build
33
+
34
+ Install and validate:
35
+
36
+ ```bash
37
+ npm ci
38
+ npm run check
39
+ ```
40
+
41
+ Expanded commands:
42
+
43
+ ```bash
44
+ npm run lint
45
+ npm run typecheck
46
+ npm run test
47
+ npm run build
48
+ ```
49
+
50
+ Pack verification:
51
+
52
+ ```bash
53
+ npm pack --dry-run
54
+ ```
55
+
56
+ ## Run
57
+
58
+ This repository does not start a long-running application by default.
59
+
60
+ For local manual exploration:
61
+
62
+ ```bash
63
+ npm run demo
64
+ ```
65
+
66
+ Bun is optional for local demo shortcuts only.
67
+
68
+ ## Config
69
+
70
+ This package is configured by the consuming application at runtime, not by repository-level
71
+ environment files.
72
+
73
+ Core client configuration typically includes:
74
+
75
+ - `apiOrigin`
76
+ - `application`
77
+ - browser callback destination or extension auth hooks, depending on entrypoint
78
+
79
+ ## Dependencies
80
+
81
+ - browser login/logout against Ghostly Auth API
82
+ - session bootstrap for React and Next.js apps
83
+ - server-side session access for Next.js
84
+ - extension auth helpers for tab-based or custom auth flows
85
+
86
+ Peer dependencies:
7
87
 
8
- ## Contract
88
+ - `react >= 18`
89
+ - `react-dom >= 18`
9
90
 
10
- Fixed API endpoints:
91
+ Package artifacts are built from `src/` and published to npm. `dist/` and tarballs must not be
92
+ committed as release storage.
93
+
94
+ ## CI
95
+
96
+ GitLab CI validates this repository through `.gitlab-ci.yml`.
97
+
98
+ Current pipeline contract:
99
+
100
+ - `validate`: lint + typecheck
101
+ - `test`: unit tests
102
+ - `build`: bundle build + pack verification
103
+ - `release`: tag-driven npm publish gate
104
+
105
+ Green pipeline means:
106
+
107
+ - `npm run lint`
108
+ - `npm run typecheck`
109
+ - `npm run test`
110
+ - `npm run build`
111
+ - `npm pack --dry-run`
112
+
113
+ ## Release
114
+
115
+ The release artifact is the npm package `@ghostly-solutions/auth`.
116
+
117
+ Release path:
118
+
119
+ 1. merge with green CI
120
+ 2. create a semver tag
121
+ 3. let GitLab CI publish through the tag-gated release job
122
+
123
+ Current published version can be verified with:
124
+
125
+ ```bash
126
+ npm view @ghostly-solutions/auth version dist-tags --json
127
+ ```
128
+
129
+ ## Troubleshooting
130
+
131
+ - auth contract mismatch: verify the backend exposes the required `/oauth/*` routes
132
+ - session fetch fails in Next.js: confirm headers are forwarded into `requireNextServerSession`
133
+ - package publish blocked: verify npm auth token and protected branch/tag permissions in GitLab
134
+ - local bundle drift: run `npm run check && npm pack --dry-run`
135
+
136
+ ## Ownership
137
+
138
+ - Repo owners: @kirill
139
+
140
+ ## License
141
+
142
+ See [LICENSE](/home/winicred/ghostly-solutions/@ghostly-solutions__auth/LICENSE). Public package availability does not override repository license terms unless Ghostly Solutions publishes separate licensing terms.
143
+
144
+ ## Runtime Contract
145
+
146
+ The SDK assumes a fixed auth surface on your auth gateway:
11
147
 
12
148
  - `GET /oauth/authorize`
13
149
  - `GET /oauth/callback/provider`
@@ -15,24 +151,34 @@ Fixed API endpoints:
15
151
  - `POST /oauth/refresh`
16
152
  - `POST /oauth/logout`
17
153
 
154
+ If your backend does not expose this contract, the SDK is not a drop-in fit.
155
+
18
156
  ## Install
19
157
 
20
158
  ```bash
21
159
  npm install @ghostly-solutions/auth
22
160
  ```
23
161
 
162
+ Peer dependencies:
163
+
164
+ - `react >= 18`
165
+ - `react-dom >= 18`
166
+
24
167
  ## Core Usage
25
168
 
26
169
  ```ts
27
170
  import { createAuthClient } from "@ghostly-solutions/auth";
28
171
 
29
- const auth = createAuthClient();
172
+ const auth = createAuthClient({
173
+ apiOrigin: "https://api.ghostlysolutions.com",
174
+ application: "admin",
175
+ });
30
176
 
31
177
  await auth.init();
32
178
  const session = await auth.getSession();
33
179
 
34
180
  if (!session) {
35
- auth.login();
181
+ auth.login({ returnTo: window.location.pathname });
36
182
  }
37
183
  ```
38
184
 
@@ -43,10 +189,15 @@ import { AuthProvider, AuthSessionGate } from "@ghostly-solutions/auth/react";
43
189
 
44
190
  export function App() {
45
191
  return (
46
- <AuthProvider>
192
+ <AuthProvider
193
+ apiOrigin="https://api.ghostlysolutions.com"
194
+ application="admin"
195
+ >
47
196
  <AuthSessionGate
48
197
  loading={<div>Loading...</div>}
49
- unauthorized={({ login }) => <button onClick={() => login()}>Sign in</button>}
198
+ unauthorized={({ login }) => (
199
+ <button onClick={() => login({ returnTo: "/" })}>Sign in</button>
200
+ )}
50
201
  authorized={(session) => <div>{session.email}</div>}
51
202
  />
52
203
  </AuthProvider>
@@ -56,6 +207,8 @@ export function App() {
56
207
 
57
208
  ## Next.js Usage
58
209
 
210
+ Use the server helpers to resolve the current session from request headers.
211
+
59
212
  ```ts
60
213
  import { requireNextServerSession } from "@ghostly-solutions/auth/next";
61
214
 
@@ -65,13 +218,11 @@ export async function getServerData(headers: Headers) {
65
218
  apiOrigin: "https://api.ghostlysolutions.com",
66
219
  });
67
220
 
68
- return {
69
- actorId: session.id,
70
- };
221
+ return { actorId: session.id };
71
222
  }
72
223
  ```
73
224
 
74
- No Next route handlers are required.
225
+ No Next.js route handlers are required.
75
226
 
76
227
  ## Extension Usage
77
228
 
@@ -80,26 +231,14 @@ import { createExtensionAuthClient } from "@ghostly-solutions/auth/extension";
80
231
 
81
232
  const auth = createExtensionAuthClient({
82
233
  apiOrigin: "https://api.ghostlysolutions.com",
83
- launchWebAuthFlow: async ({ authorizeUrl }) => {
84
- // chrome.identity.launchWebAuthFlow(...) wrapper
85
- await openAuthWindow(authorizeUrl);
86
- },
234
+ application: "ghostguard-extension",
87
235
  });
88
236
 
89
- await auth.loginWithWebAuthFlow();
90
- ```
91
-
92
- ## Development
93
-
94
- ```bash
95
- npm run lint
96
- npm run typecheck
97
- npm run test
98
- npm run build
237
+ await auth.login({
238
+ returnTo: "/",
239
+ });
99
240
  ```
100
241
 
101
- Bun is optional for local shortcuts (`bun run ...`).
102
-
103
242
  ## Documentation
104
243
 
105
244
  - [Docs Index](./docs/index.md)
@@ -1,16 +1,52 @@
1
- import { A as AuthClient, L as LoginOptions } from './auth-client-Cdkp07ii.js';
1
+ import { G as GhostlySession, A as AuthClient, L as LoginOptions } from './auth-client-Cdkp07ii.js';
2
2
 
3
3
  interface LaunchWebAuthFlowPayload {
4
4
  authorizeUrl: string;
5
5
  }
6
+ interface OpenAuthorizePagePayload {
7
+ authorizeUrl: string;
8
+ }
9
+ type PersistAccessToken = (token: ExtensionStoredAccessToken | null) => Promise<void> | void;
10
+ type ResolveSessionId = () => Promise<string | null>;
11
+ type RestoreAccessToken = (() => Promise<ExtensionStoredAccessToken | null>) | (() => ExtensionStoredAccessToken | null);
12
+ interface ExtensionAccessToken {
13
+ accessToken: string;
14
+ application: string;
15
+ expiresAt: string | null;
16
+ session: GhostlySession | null;
17
+ tokenType: string;
18
+ }
19
+ interface ExtensionAccessTokenRequestOptions {
20
+ forceRefresh?: boolean;
21
+ }
22
+ interface ExtensionStoredAccessToken extends ExtensionAccessToken {
23
+ }
6
24
  interface ExtensionAuthClientOptions {
7
25
  apiOrigin: string;
8
26
  application?: string;
9
- launchWebAuthFlow: (payload: LaunchWebAuthFlowPayload) => Promise<void>;
27
+ defaultReturnToPath?: string;
28
+ clearSessionId?: () => Promise<void> | void;
29
+ launchWebAuthFlow?: (payload: LaunchWebAuthFlowPayload) => Promise<void>;
30
+ openAuthorizePage?: (payload: OpenAuthorizePagePayload) => Promise<void>;
31
+ persistAccessToken?: PersistAccessToken;
32
+ resolveSessionId?: ResolveSessionId;
33
+ restoreAccessToken?: RestoreAccessToken;
10
34
  }
11
35
  interface ExtensionAuthClient extends AuthClient {
36
+ getAccessToken(options?: ExtensionAccessTokenRequestOptions): Promise<ExtensionAccessToken | null>;
37
+ loginWithTabFlow(options?: LoginOptions): Promise<void>;
12
38
  loginWithWebAuthFlow(options?: LoginOptions): Promise<void>;
13
39
  }
14
- declare function createExtensionAuthClient(options: ExtensionAuthClientOptions): ExtensionAuthClient;
40
+ declare function createCustomExtensionAuthClient(options: ExtensionAuthClientOptions): ExtensionAuthClient;
41
+
42
+ interface ChromeExtensionAuthClientOptions extends Omit<ExtensionAuthClientOptions, "clearSessionId" | "openAuthorizePage" | "persistAccessToken" | "resolveSessionId" | "restoreAccessToken"> {
43
+ accessTokenStorageKey?: string;
44
+ sessionCookieName?: string;
45
+ sessionStorageKey?: string;
46
+ tokenExpiresAtStorageKey?: string;
47
+ }
48
+ declare function createChromeExtensionAuthClient(options: ChromeExtensionAuthClientOptions): ExtensionAuthClient;
49
+
50
+ declare function createExtensionAuthClient(options: ExtensionAuthClientOptions | ChromeExtensionAuthClientOptions): ExtensionAuthClient;
15
51
 
16
- export { type ExtensionAuthClient, type ExtensionAuthClientOptions, createExtensionAuthClient };
52
+ export { type ChromeExtensionAuthClientOptions, type ExtensionAccessToken, type ExtensionAccessTokenRequestOptions, type ExtensionAuthClient, type ExtensionAuthClientOptions, type ExtensionStoredAccessToken, createChromeExtensionAuthClient, createCustomExtensionAuthClient, createExtensionAuthClient };