orange-auth 1.2.0 → 1.3.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.
Files changed (63) hide show
  1. package/COPYING +674 -0
  2. package/README.md +81 -124
  3. package/dist/IProvider-BH8TjziQ.d.mts +461 -0
  4. package/dist/IProvider-BH8TjziQ.d.mts.map +1 -0
  5. package/dist/client.d.ts +470 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +19 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/index-D-dMFhOD.d.mts +55 -0
  10. package/dist/index-D-dMFhOD.d.mts.map +1 -0
  11. package/dist/index-DjPz5vTX.d.mts +37 -0
  12. package/dist/index-DjPz5vTX.d.mts.map +1 -0
  13. package/dist/index.d.mts +70 -0
  14. package/dist/index.d.mts.map +1 -0
  15. package/dist/index.mjs +19 -0
  16. package/dist/index.mjs.map +1 -0
  17. package/dist/providers.d.mts +20 -0
  18. package/dist/providers.mjs +19 -0
  19. package/dist/providers.mjs.map +1 -0
  20. package/dist/strategies.d.mts +20 -0
  21. package/dist/strategies.mjs +19 -0
  22. package/dist/strategies.mjs.map +1 -0
  23. package/package.json +53 -31
  24. package/LICENSE +0 -21
  25. package/dist/@types/globals.d.ts +0 -97
  26. package/dist/@types/globals.d.ts.map +0 -1
  27. package/dist/@types/globals.js +0 -1
  28. package/dist/@types/internals.d.ts +0 -13
  29. package/dist/@types/internals.d.ts.map +0 -1
  30. package/dist/@types/internals.js +0 -1
  31. package/dist/functions/index.d.ts +0 -3
  32. package/dist/functions/index.d.ts.map +0 -1
  33. package/dist/functions/index.js +0 -2
  34. package/dist/functions/jwt.d.ts +0 -11
  35. package/dist/functions/jwt.d.ts.map +0 -1
  36. package/dist/functions/jwt.js +0 -20
  37. package/dist/functions/urlencodedToJson.d.ts +0 -2
  38. package/dist/functions/urlencodedToJson.d.ts.map +0 -1
  39. package/dist/functions/urlencodedToJson.js +0 -8
  40. package/dist/index.d.ts +0 -5
  41. package/dist/index.d.ts.map +0 -1
  42. package/dist/index.js +0 -4
  43. package/dist/lib.d.ts +0 -46
  44. package/dist/lib.d.ts.map +0 -1
  45. package/dist/lib.js +0 -161
  46. package/dist/providers/Credentials.d.ts +0 -33
  47. package/dist/providers/Credentials.d.ts.map +0 -1
  48. package/dist/providers/Credentials.js +0 -42
  49. package/dist/providers/IProvider.d.ts +0 -29
  50. package/dist/providers/IProvider.d.ts.map +0 -1
  51. package/dist/providers/IProvider.js +0 -20
  52. package/dist/providers/index.d.ts +0 -3
  53. package/dist/providers/index.d.ts.map +0 -1
  54. package/dist/providers/index.js +0 -2
  55. package/dist/strategies/IStrategy.d.ts +0 -48
  56. package/dist/strategies/IStrategy.d.ts.map +0 -1
  57. package/dist/strategies/IStrategy.js +0 -11
  58. package/dist/strategies/index.d.ts +0 -3
  59. package/dist/strategies/index.d.ts.map +0 -1
  60. package/dist/strategies/index.js +0 -2
  61. package/dist/strategies/jwt.d.ts +0 -19
  62. package/dist/strategies/jwt.d.ts.map +0 -1
  63. package/dist/strategies/jwt.js +0 -51
@@ -0,0 +1,470 @@
1
+ /*
2
+ Orange Auth, a simple modular auth library
3
+ Copyright (C) 2026 Mathieu Dery
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ //#region node_modules/type-fest/source/primitive.d.ts
19
+ /**
20
+ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
21
+
22
+ @category Type
23
+ */
24
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
25
+ //#endregion
26
+ //#region node_modules/type-fest/source/is-never.d.ts
27
+ /**
28
+ Returns a boolean for whether the given type is `never`.
29
+
30
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
31
+ @link https://stackoverflow.com/a/53984913/10292952
32
+ @link https://www.zhenghao.io/posts/ts-never
33
+
34
+ Useful in type utilities, such as checking if something does not occur.
35
+
36
+ @example
37
+ ```
38
+ import type {IsNever, And} from 'type-fest';
39
+
40
+ type A = IsNever<never>;
41
+ //=> true
42
+
43
+ type B = IsNever<any>;
44
+ //=> false
45
+
46
+ type C = IsNever<unknown>;
47
+ //=> false
48
+
49
+ type D = IsNever<never[]>;
50
+ //=> false
51
+
52
+ type E = IsNever<object>;
53
+ //=> false
54
+
55
+ type F = IsNever<string>;
56
+ //=> false
57
+ ```
58
+
59
+ @example
60
+ ```
61
+ import type {IsNever} from 'type-fest';
62
+
63
+ type IsTrue<T> = T extends true ? true : false;
64
+
65
+ // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
66
+ type A = IsTrue<never>;
67
+ //=> never
68
+
69
+ // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
70
+ type IsTrueFixed<T> =
71
+ IsNever<T> extends true ? false : T extends true ? true : false;
72
+
73
+ type B = IsTrueFixed<never>;
74
+ //=> false
75
+ ```
76
+
77
+ @category Type Guard
78
+ @category Utilities
79
+ */
80
+ type IsNever<T> = [T] extends [never] ? true : false;
81
+ //#endregion
82
+ //#region node_modules/type-fest/source/internal/type.d.ts
83
+ /**
84
+ Matches any primitive, `void`, `Date`, or `RegExp` value.
85
+ */
86
+ type BuiltIns = Primitive | void | Date | RegExp;
87
+ /**
88
+ Test if the given function has multiple call signatures.
89
+
90
+ Needed to handle the case of a single call signature with properties.
91
+
92
+ Multiple call signatures cannot currently be supported due to a TypeScript limitation.
93
+ @see https://github.com/microsoft/TypeScript/issues/29732
94
+ */
95
+ type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
96
+ (...arguments_: infer A): unknown;
97
+ (...arguments_: infer B): unknown;
98
+ } ? B extends A ? A extends B ? false : true : true : false;
99
+ //#endregion
100
+ //#region node_modules/type-fest/source/simplify.d.ts
101
+ /**
102
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
103
+
104
+ @example
105
+ ```
106
+ import type {Simplify} from 'type-fest';
107
+
108
+ type PositionProps = {
109
+ top: number;
110
+ left: number;
111
+ };
112
+
113
+ type SizeProps = {
114
+ width: number;
115
+ height: number;
116
+ };
117
+
118
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
119
+ type Props = Simplify<PositionProps & SizeProps>;
120
+ ```
121
+
122
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
123
+
124
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
125
+
126
+ @example
127
+ ```
128
+ import type {Simplify} from 'type-fest';
129
+
130
+ interface SomeInterface {
131
+ foo: number;
132
+ bar?: string;
133
+ baz: number | undefined;
134
+ }
135
+
136
+ type SomeType = {
137
+ foo: number;
138
+ bar?: string;
139
+ baz: number | undefined;
140
+ };
141
+
142
+ const literal = {foo: 123, bar: 'hello', baz: 456};
143
+ const someType: SomeType = literal;
144
+ const someInterface: SomeInterface = literal;
145
+
146
+ declare function fn(object: Record<string, unknown>): void;
147
+
148
+ fn(literal); // Good: literal object type is sealed
149
+ fn(someType); // Good: type is sealed
150
+ // @ts-expect-error
151
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
152
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
153
+ ```
154
+
155
+ @link https://github.com/microsoft/TypeScript/issues/15300
156
+ @see {@link SimplifyDeep}
157
+ @category Object
158
+ */
159
+ type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
160
+ //#endregion
161
+ //#region node_modules/type-fest/source/required-deep.d.ts
162
+ /**
163
+ Create a type from another type with all keys and nested keys set to required.
164
+
165
+ Use-cases:
166
+ - Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified.
167
+ - Modeling the resulting type after a deep merge with a set of defaults.
168
+
169
+ @example
170
+ ```
171
+ import type {RequiredDeep} from 'type-fest';
172
+
173
+ type Settings = {
174
+ textEditor?: {
175
+ fontSize?: number;
176
+ fontColor?: string;
177
+ fontWeight?: number | undefined;
178
+ };
179
+ autocomplete?: boolean;
180
+ autosave?: boolean | undefined;
181
+ };
182
+
183
+ type RequiredSettings = RequiredDeep<Settings>;
184
+ //=> {
185
+ // textEditor: {
186
+ // fontSize: number;
187
+ // fontColor: string;
188
+ // fontWeight: number | undefined;
189
+ // };
190
+ // autocomplete: boolean;
191
+ // autosave: boolean | undefined;
192
+ // }
193
+ ```
194
+
195
+ Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
196
+
197
+ @category Utilities
198
+ @category Object
199
+ @category Array
200
+ @category Set
201
+ @category Map
202
+ */
203
+ type RequiredDeep<T> = T extends BuiltIns ? T : T extends Map<infer KeyType, infer ValueType> ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends Set<infer ItemType> ? Set<RequiredDeep<ItemType>> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends ReadonlySet<infer ItemType> ? ReadonlySet<RequiredDeep<ItemType>> : T extends WeakMap<infer KeyType, infer ValueType> ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends WeakSet<infer ItemType> ? WeakSet<RequiredDeep<ItemType>> : T extends Promise<infer ValueType> ? Promise<RequiredDeep<ValueType>> : T extends ((...arguments_: any[]) => unknown) ? IsNever<keyof T> extends true ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & RequiredObjectDeep<T> : T extends object ? Simplify<RequiredObjectDeep<T>> // `Simplify` to prevent `RequiredObjectDeep` from appearing in the resulting type
204
+ : unknown;
205
+ type RequiredObjectDeep<ObjectType extends object> = { [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]> };
206
+ //#endregion
207
+ //#region packages/orange-auth/@types/internals.d.ts
208
+ type ConfigOptsRequired = RequiredDeep<Omit<ConfigOptionsProps, "basePath" | "callbacks" | "cookieSettings">>;
209
+ /**
210
+ * Internally used version of the options
211
+ */
212
+ type ConfigOptions = ConfigOptsRequired & {
213
+ cookieSettings: NonNullable<ConfigOptionsProps["cookieSettings"]>;
214
+ callbacks?: ConfigOptionsProps["callbacks"];
215
+ };
216
+ //#endregion
217
+ //#region packages/orange-auth/providers/IProvider.d.ts
218
+ /**
219
+ * Providers are used to implement certain services (E.g. facebook, github, credentials) as login methods.
220
+ * Every provider should inherit from this.
221
+ */
222
+ declare abstract class IProvider {
223
+ /**
224
+ * This is used to map a callback to a provider.
225
+ */
226
+ private readonly __ID;
227
+ constructor(ID: string);
228
+ /**
229
+ * The provider ID.
230
+ */
231
+ get ID(): string;
232
+ /**
233
+ * Login function. This is used to call all the login flows of each provider.
234
+ * For now, the request's body **MUST** be JSON.
235
+ * @param req The request object.
236
+ * @param globalCfg The global auth config.
237
+ */
238
+ abstract logIn(req: Request, globalCfg: ConfigOptions): Promise<{
239
+ session: Session;
240
+ token: string;
241
+ } | null>;
242
+ }
243
+ //#endregion
244
+ //#region packages/orange-auth/strategies/IStrategy.d.ts
245
+ /**
246
+ * Strategies callbacks
247
+ */
248
+ type Callbacks = Partial<{
249
+ /**
250
+ * Pre-serialization callback. This can be used to add some steps to this process.
251
+ * @param session The session to be serialized.
252
+ * @returns A boolean representing if the serialization should occur.
253
+ */
254
+ serialize: (session: Session) => MaybePromise<boolean>;
255
+ /**
256
+ * Post-deserialization callback. This can be used to add some validation to this process.
257
+ * @param session The token that was deserialized.
258
+ * @returns A boolean representing if the deserialization is valid.
259
+ */
260
+ deserialize: (token: string, session: Session) => MaybePromise<boolean>;
261
+ }>;
262
+ /**
263
+ * A strategy is used to handle the creation, validation and accessing a user's session.
264
+ */
265
+ declare abstract class IStrategy {
266
+ protected callbacks: Callbacks;
267
+ constructor(callbacks: Callbacks);
268
+ /**
269
+ * Handles how a session token is generated.
270
+ * @param session The validated session object.
271
+ * @param globalCfg The global auth config.
272
+ * @returns A newly generated token that will be sent as a cookie.
273
+ */
274
+ abstract serialize(session: Session, globalCfg: ConfigOptions): Promise<string>;
275
+ /**
276
+ * Handles how a token is validated and deserialized into a session object.
277
+ * @param token A user's token.
278
+ * @param globalCfg The global auth config.
279
+ * @returns A user's session if validated and found, else `null`.
280
+ */
281
+ abstract deserialize(token: string, globalCfg: ConfigOptions): Promise<Session | null>;
282
+ /**
283
+ * Handles how a session is destroyed when a user is logging out.
284
+ * @param req The request object.
285
+ * @param globalCfg The global auth config.
286
+ */
287
+ abstract logOut(req: Request, globalCfg: ConfigOptions): Promise<void>;
288
+ }
289
+ //#endregion
290
+ //#region packages/orange-auth/@types/cookies.d.ts
291
+ interface CookieOptions {
292
+ /**
293
+ * Specifies the `number` (in seconds) to be the value for the [`Max-Age` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.2).
294
+ *
295
+ * The [cookie storage model specification](https://tools.ietf.org/html/rfc6265#section-5.3) states that if both `expires` and
296
+ * `maxAge` are set, then `maxAge` takes precedence, but it is possible not all clients by obey this,
297
+ * so if both are set, they should point to the same date and time.
298
+ */
299
+ maxAge?: number;
300
+ /**
301
+ * Specifies the `Date` object to be the value for the [`Expires` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.1).
302
+ * When no expiration is set, clients consider this a "non-persistent cookie" and delete it when the current session is over.
303
+ *
304
+ * The [cookie storage model specification](https://tools.ietf.org/html/rfc6265#section-5.3) states that if both `expires` and
305
+ * `maxAge` are set, then `maxAge` takes precedence, but it is possible not all clients by obey this,
306
+ * so if both are set, they should point to the same date and time.
307
+ */
308
+ expires?: Date;
309
+ /**
310
+ * Specifies the value for the [`Domain` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.3).
311
+ * When no domain is set, clients consider the cookie to apply to the current domain only.
312
+ */
313
+ domain?: string;
314
+ /**
315
+ * Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
316
+ * When no path is set, the path is considered the ["default path"](https://tools.ietf.org/html/rfc6265#section-5.1.4).
317
+ */
318
+ path?: string;
319
+ /**
320
+ * Enables the [`HttpOnly` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.6).
321
+ * When enabled, clients will not allow client-side JavaScript to see the cookie in `document.cookie`.
322
+ */
323
+ httpOnly?: boolean;
324
+ /**
325
+ * Enables the [`Secure` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.5).
326
+ * When enabled, clients will only send the cookie back if the browser has an HTTPS connection.
327
+ */
328
+ secure?: boolean;
329
+ /**
330
+ * Enables the [`Partitioned` `Set-Cookie` attribute](https://tools.ietf.org/html/draft-cutler-httpbis-partitioned-cookies/).
331
+ * When enabled, clients will only send the cookie back when the current domain _and_ top-level domain matches.
332
+ *
333
+ * This is an attribute that has not yet been fully standardized, and may change in the future.
334
+ * This also means clients may ignore this attribute until they understand it. More information
335
+ * about can be found in [the proposal](https://github.com/privacycg/CHIPS).
336
+ */
337
+ partitioned?: boolean;
338
+ /**
339
+ * Specifies the value for the [`Priority` `Set-Cookie` attribute](https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1).
340
+ *
341
+ * - `'low'` will set the `Priority` attribute to `Low`.
342
+ * - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
343
+ * - `'high'` will set the `Priority` attribute to `High`.
344
+ *
345
+ * More information about priority levels can be found in [the specification](https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1).
346
+ */
347
+ priority?: "low" | "medium" | "high";
348
+ /**
349
+ * Specifies the value for the [`SameSite` `Set-Cookie` attribute](https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-09#section-5.4.7).
350
+ *
351
+ * - `true` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
352
+ * - `'lax'` will set the `SameSite` attribute to `Lax` for lax same site enforcement.
353
+ * - `'none'` will set the `SameSite` attribute to `None` for an explicit cross-site cookie.
354
+ * - `'strict'` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
355
+ *
356
+ * More information about enforcement levels can be found in [the specification](https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-09#section-5.4.7).
357
+ */
358
+ sameSite?: "lax" | "strict" | "none";
359
+ }
360
+ //#endregion
361
+ //#region packages/orange-auth/@types/globals.d.ts
362
+ /**
363
+ * This is a Promise, or not...
364
+ */
365
+ type MaybePromise<T> = T | Promise<T>;
366
+ /**
367
+ * General session type. This should be augmented to include your session's fields.
368
+ */
369
+ interface Session extends Record<string, unknown> {
370
+ id: string;
371
+ }
372
+ /**
373
+ * Parameters for the custom callbacks
374
+ */
375
+ type CallbackParams = {
376
+ /**
377
+ * The current token
378
+ */
379
+ token: string;
380
+ /**
381
+ * The current deserialized token
382
+ */
383
+ session: Session;
384
+ /**
385
+ * TThe request's headers
386
+ */
387
+ headers: Headers;
388
+ };
389
+ /**
390
+ * Auth Configuration props.
391
+ */
392
+ type ConfigOptionsProps = Readonly<{
393
+ /**
394
+ * All the available providers.
395
+ * If multiple instance of a single provider are used, the order does matter.
396
+ */
397
+ providers: IProvider[];
398
+ /**
399
+ * Your secret key.
400
+ */
401
+ secret: string;
402
+ /**
403
+ * A custom name for the cookie.
404
+ * Otherwise, the default name will be `orange.auth`
405
+ */
406
+ cookieName?: string;
407
+ /**
408
+ * The strategy to be used.
409
+ */
410
+ strategy: IStrategy;
411
+ /**
412
+ * This should be the url path that your auth is set up on.
413
+ * @example
414
+ * ```js
415
+ * const app = express();
416
+ *
417
+ * const { handler } = CreateAuth({
418
+ * basePath: "/api/auth",
419
+ * ...
420
+ * });
421
+ *
422
+ * app.all("/api/auth/*", createHandler(handler)());
423
+ * ```
424
+ */
425
+ basePath: string;
426
+ /**
427
+ * Cookie serialization options. see [MDN Cookie](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Cookies)
428
+ */
429
+ cookieSettings?: CookieOptions;
430
+ /**
431
+ * Custom callbacks
432
+ */
433
+ callbacks?: {
434
+ /**
435
+ * Custom login callback. This is ran after logging in with the provider.
436
+ * This can accept 2 return types: a boolean that indicates if the login is valid,
437
+ * or a url which will redirect the user.
438
+ * @param params An object containing the token, session and headers of a request.
439
+ * @returns a boolean that indicates if the login is valid,
440
+ * or a url which will redirect the user.
441
+ */
442
+ login?: (params: CallbackParams) => MaybePromise<boolean | string>;
443
+ /**
444
+ * Custom logout callback. This is ran before logging out with the strategy.
445
+ * @param params An object containing the token, session and headers of a request.
446
+ * @returns Nothing, or an empty promise.
447
+ */
448
+ logout?: (params: CallbackParams) => MaybePromise<void>;
449
+ };
450
+ }>;
451
+ //#endregion
452
+ //#region packages/client/@types/globals.d.ts
453
+ type ClientConfigOptions = Pick<ConfigOptionsProps, "basePath" | "cookieName"> & {
454
+ providers: IProvider["ID"][];
455
+ };
456
+ //#endregion
457
+ //#region packages/client/index.d.ts
458
+ type LogInProps = {
459
+ credentials: Record<"email" | "password", string>;
460
+ };
461
+ type Opts = Partial<{
462
+ callbackUrl: string;
463
+ }>;
464
+ declare function createAuthClient(options: ClientConfigOptions): {
465
+ logIn: <T extends keyof LogInProps>(provider: T, credentials: LogInProps[T], opts?: Opts) => Promise<void>;
466
+ logOut: (opts?: Opts) => Promise<void>;
467
+ };
468
+ //#endregion
469
+ export { type ClientConfigOptions, createAuthClient };
470
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":["Primitive","IsNever","T","If","IsAny","IsNever","Primitive","UnknownArray","BuiltIns","Date","RegExp","NonRecursiveType","Function","Promise","arguments_","MapsSetsOrArrays","ReadonlyMap","WeakKey","WeakMap","ReadonlySet","WeakSet","IsBothExtends","BaseType","FirstType","SecondType","HasMultipleCallSignatures","T","A","B","IsNotFalse","IsPrimitive","Not","IfNotAnyOrNever","IfAny","IfNever","IsAnyOrNever","IsExactOptionalPropertyTypesEnabled","Simplify","T","KeyType","BuiltIns","HasMultipleCallSignatures","IsNever","Simplify","RequiredDeep","T","Map","KeyType","ValueType","Set","ItemType","ReadonlyMap","ReadonlySet","WeakMap","WeakSet","Promise","Parameters","ReturnType","RequiredObjectDeep","arguments_","ObjectType"],"sources":["../node_modules/type-fest/source/primitive.d.ts","../node_modules/type-fest/source/is-never.d.ts","../node_modules/type-fest/source/internal/type.d.ts","../node_modules/type-fest/source/simplify.d.ts","../node_modules/type-fest/source/required-deep.d.ts","../packages/orange-auth/@types/internals.ts","../packages/orange-auth/providers/IProvider.ts","../packages/orange-auth/strategies/IStrategy.ts","../packages/orange-auth/@types/cookies.ts","../packages/orange-auth/@types/globals.ts","../packages/client/@types/globals.ts","../packages/client/index.ts"],"x_google_ignoreList":[0,1,2,3,4],"mappings":";;;;;;;;;;;;;;;;;;;AAKA;;;;KAAYA,SAAAA;;;;AAAZ;;;;;;;;ACgDA;;;;;;;;AC5CA;;;;;;;;;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;ACoBA;;;KFLYC,OAAAA,OAAcC,CAAAA;;;;;;KC5CdM,QAAAA,GAAWF,SAAAA,UAAmBG,IAAAA,GAAOC,MAAAA;AA6BjD;;;;;;;;AAAA,KAAYe,yBAAAA,eAAwCX,UAAAA,uBACnDY,CAAAA;EAAAA,IAAeZ,UAAAA;E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you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ function e(e){async function t(t,n,r){if(!(await fetch(`${e.basePath}/login/${t}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)})).ok)throw Error(`INVALID_CREDENTIALS`);r?.callbackUrl&&window.location.replace(r.callbackUrl)}async function n(t){if(!(await fetch(`${e.basePath}/logout/credentials`,{method:`POST`})).ok)throw Error(`SERVER_ERROR`);t?.callbackUrl&&window.location.replace(t.callbackUrl)}return{logIn:t,logOut:n}}export{e as createAuthClient};
19
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../packages/client/index.ts"],"sourcesContent":["import type { ClientConfigOptions } from \"./@types/globals\";\n\ntype LogInProps = {\n credentials: Record<\"email\" | \"password\", string>;\n};\n\ntype Opts = Partial<{ callbackUrl: string }>;\n\nfunction createAuthClient(options: ClientConfigOptions) {\n async function logIn<T extends keyof LogInProps>(provider: T, credentials: LogInProps[T], opts?: Opts) {\n const res = await fetch(`${options.basePath}/login/${provider}`, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(credentials),\n });\n\n if (!res.ok) {\n throw new Error(\"INVALID_CREDENTIALS\");\n }\n\n if (opts?.callbackUrl) {\n window.location.replace(opts.callbackUrl);\n }\n }\n\n async function logOut(opts?: Opts) {\n const res = await fetch(`${options.basePath}/logout/credentials`, {\n method: \"POST\",\n });\n\n if (!res.ok) {\n throw new Error(\"SERVER_ERROR\");\n }\n\n if (opts?.callbackUrl) {\n window.location.replace(opts.callbackUrl);\n }\n }\n\n return {\n logIn,\n logOut,\n };\n}\n\nexport { createAuthClient };\nexport type { ClientConfigOptions };\n"],"mappings":";;;;;;;;;;;;;;;;;AAQA,SAAS,EAAiB,EAA8B,CACpD,eAAe,EAAkC,EAAa,EAA4B,EAAa,CAOnG,GAAI,EANQ,MAAM,MAAM,GAAG,EAAQ,SAAS,SAAS,IAAY,CAC7D,OAAQ,OACR,QAAS,CAAE,eAAgB,mBAAoB,CAC/C,KAAM,KAAK,UAAU,EAAY,CACpC,CAAC,EAEO,GACL,MAAU,MAAM,sBAAsB,CAGtC,GAAM,aACN,OAAO,SAAS,QAAQ,EAAK,YAAY,CAIjD,eAAe,EAAO,EAAa,CAK/B,GAAI,EAJQ,MAAM,MAAM,GAAG,EAAQ,SAAS,qBAAsB,CAC9D,OAAQ,OACX,CAAC,EAEO,GACL,MAAU,MAAM,eAAe,CAG/B,GAAM,aACN,OAAO,SAAS,QAAQ,EAAK,YAAY,CAIjD,MAAO,CACH,QACA,SACH"}
@@ -0,0 +1,55 @@
1
+ /*
2
+ Orange Auth, a simple modular auth library
3
+ Copyright (C) 2026 Mathieu Dery
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ import { a as Session, i as MaybePromise, l as ConfigOptions, n as IProvider } from "./IProvider-BH8TjziQ.mjs";
19
+
20
+ //#region packages/orange-auth/providers/Credentials.d.ts
21
+ /**
22
+ * Configuration options of the Credentials provider
23
+ */
24
+ type CredentialsConfig<TCredentials extends string> = Readonly<{
25
+ /**
26
+ * The name of this provider, should not be changed unless you are
27
+ * using multiple instance of the same provider.
28
+ */
29
+ name?: "credentials" | (string & {});
30
+ /**
31
+ * The available fields coming from the request containing credentials.
32
+ */
33
+ credentials: TCredentials[];
34
+ /**
35
+ * Function that gets called when a user tries to login.
36
+ * This is where you should look inside your database for the user.
37
+ * @param credentials An object containing the credentials from the request's body.
38
+ * @returns A session object if a user is found, or `null`.
39
+ */
40
+ authorize: (credentials: Record<TCredentials, string>) => MaybePromise<Session | null>;
41
+ }>;
42
+ /**
43
+ * Provider used to login a user using basic credentials.
44
+ */
45
+ declare class Credentials<TCredentials extends string = string> extends IProvider {
46
+ private config;
47
+ constructor(config: CredentialsConfig<TCredentials>);
48
+ logIn(req: Request, globalCfg: ConfigOptions): Promise<{
49
+ session: Session;
50
+ token: string;
51
+ } | null>;
52
+ }
53
+ //#endregion
54
+ export { CredentialsConfig as n, Credentials as t };
55
+ //# sourceMappingURL=index-D-dMFhOD.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-D-dMFhOD.d.mts","names":[],"sources":["../packages/orange-auth/providers/Credentials.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;AAQA;;;AAAA,KAAY,iBAAA,gCAAiD,QAAA;EAgBzB;;;;EAXhC,IAAA;EALiE;;;EASjE,WAAA,EAAa,YAAA;EAJb;;;;;;EAWA,SAAA,GAAY,WAAA,EAAa,MAAA,CAAO,YAAA,cAA0B,YAAA,CAAa,OAAA;AAAA;;;;cAM9D,WAAA,+CAA0D,SAAA;EAAA,QAC3D,MAAA;cAEI,MAAA,EAAQ,iBAAA,CAAkB,YAAA;EAKhB,KAAA,CAClB,GAAA,EAAK,OAAA,EACL,SAAA,EAAW,aAAA,GACZ,OAAA;IAAU,OAAA,EAAS,OAAA;IAAS,KAAA;EAAA;AAAA"}
@@ -0,0 +1,37 @@
1
+ /*
2
+ Orange Auth, a simple modular auth library
3
+ Copyright (C) 2026 Mathieu Dery
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ import { a as Session, c as IStrategy, l as ConfigOptions, s as Callbacks } from "./IProvider-BH8TjziQ.mjs";
19
+ import { SignOptions } from "jsonwebtoken";
20
+
21
+ //#region packages/orange-auth/strategies/jwt.d.ts
22
+ /**
23
+ * Basic JWT strategy
24
+ */
25
+ declare class JWT extends IStrategy {
26
+ /**
27
+ * Forwarded standard JWT options
28
+ */
29
+ private signOptions;
30
+ constructor(options?: SignOptions, callbacks?: Callbacks);
31
+ serialize(session: Session, globalCfg: ConfigOptions): Promise<string>;
32
+ deserialize(token: string, globalCfg: ConfigOptions): Promise<Session | null>;
33
+ logOut(): Promise<void>;
34
+ }
35
+ //#endregion
36
+ export { JWT as t };
37
+ //# sourceMappingURL=index-DjPz5vTX.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-DjPz5vTX.d.mts","names":[],"sources":["../packages/orange-auth/strategies/jwt.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAKwD;;;AAAA,cAKlD,GAAA,SAAY,SAAA;EAMqD;;;EAAA,QAF3D,WAAA;cAEI,OAAA,GAAS,WAAA,EAAmC,SAAA,GAAW,SAAA;EAM7C,SAAA,CAAU,OAAA,EAAS,OAAA,EAAS,SAAA,EAAW,aAAA,GAAgB,OAAA;EAY7D,WAAA,CAAY,KAAA,UAAe,SAAA,EAAW,aAAA,GAAgB,OAAA,CAAQ,OAAA;EAS9D,MAAA,CAAA,GAAU,OAAA;AAAA"}
@@ -0,0 +1,70 @@
1
+ /*
2
+ Orange Auth, a simple modular auth library
3
+ Copyright (C) 2026 Mathieu Dery
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+ import { a as Session, c as IStrategy, i as MaybePromise, n as IProvider, o as CookieOptions, r as ConfigOptionsProps, u as Maybe } from "./IProvider-BH8TjziQ.mjs";
19
+ import "./index-DjPz5vTX.mjs";
20
+ import * as _universal_middleware_core0 from "@universal-middleware/core";
21
+
22
+ //#region packages/orange-auth/lib.d.ts
23
+ /**
24
+ * Initializes the auth. This should be called once per backend.
25
+ * @param req Something that has a `headers` field; either a Headers instance, or just a plain object.
26
+ * @returns A session if found and valid, or `null`.
27
+ */
28
+ declare const CreateAuth: (config: Readonly<{
29
+ providers: IProvider[];
30
+ secret: string;
31
+ cookieName?: string;
32
+ strategy: IStrategy;
33
+ basePath: string;
34
+ cookieSettings?: CookieOptions;
35
+ callbacks?: {
36
+ login?: (params: {
37
+ token: string;
38
+ session: Session;
39
+ headers: Headers;
40
+ }) => MaybePromise<boolean | string>;
41
+ logout?: (params: {
42
+ token: string;
43
+ session: Session;
44
+ headers: Headers;
45
+ }) => MaybePromise<void>;
46
+ };
47
+ }>) => {
48
+ /**
49
+ * Universal handler route. You can use this with the `createHandler()` method
50
+ * @returns
51
+ */
52
+ handler: () => (req: Request, _: Universal.Context, runtime: _universal_middleware_core0.RuntimeAdapter) => Promise<Response>;
53
+ clientConfig: {
54
+ basePath: string;
55
+ providers: string[];
56
+ cookieName: string;
57
+ };
58
+ /**
59
+ * Deserialize a user's session.
60
+ * @param globalCfg The global auth config
61
+ * @param req An object having a headers field
62
+ * @returns A user's token and session, if found and valid
63
+ */
64
+ getSession: (req: {
65
+ headers: Maybe<Headers | Record<string, string>>;
66
+ }) => Promise<Session | null>;
67
+ };
68
+ //#endregion
69
+ export { ConfigOptionsProps, CreateAuth, MaybePromise, Session };
70
+ //# sourceMappingURL=index.d.mts.map