wirejs-resources 0.1.2-alpha → 0.1.3-alpha
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/lib/adapters/context.js +3 -3
- package/lib/index.js +2 -1
- package/lib/registry.js +13 -0
- package/lib/resources/secret.js +2 -2
- package/lib/services/authentication.js +12 -10
- package/package.json +1 -1
package/lib/adapters/context.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { registry } from "../registry";
|
|
2
2
|
|
|
3
3
|
const contextWrappers = new Set();
|
|
4
4
|
|
|
@@ -76,7 +76,7 @@ export function requiresContext(fnOrNS) {
|
|
|
76
76
|
|
|
77
77
|
export class Context {
|
|
78
78
|
/**
|
|
79
|
-
* @type {CookieJar} cookies
|
|
79
|
+
* @type {typeof registry['CookieJar']} cookies
|
|
80
80
|
*/
|
|
81
81
|
cookies;
|
|
82
82
|
|
|
@@ -87,7 +87,7 @@ export class Context {
|
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* @param {{
|
|
90
|
-
* cookies: CookieJar;
|
|
90
|
+
* cookies: typeof registry['CookieJar'];
|
|
91
91
|
* location: URL;
|
|
92
92
|
* }}
|
|
93
93
|
*/
|
package/lib/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export { FileService } from './services/file.js';
|
|
|
2
2
|
export { AuthenticationService } from './services/authentication.js';
|
|
3
3
|
export { CookieJar } from './adapters/cookie-jar.js';
|
|
4
4
|
export { withContext, requiresContext, Context } from './adapters/context.js';
|
|
5
|
-
export { Resource } from './resource.js';
|
|
5
|
+
export { Resource } from './resource.js';
|
|
6
|
+
export { registry } from './registry.js';
|
package/lib/registry.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Context } from './adapters/context.js';
|
|
2
|
+
import { CookieJar } from './adapters/cookie-jar.js';
|
|
3
|
+
import { Secret } from './resources/secret.js';
|
|
4
|
+
import { AuthenticationService } from './services/authentication.js'
|
|
5
|
+
import { FileService } from './services/file.js';
|
|
6
|
+
|
|
7
|
+
export const registry = /** @type {const} **/ ({
|
|
8
|
+
Context,
|
|
9
|
+
CookieJar,
|
|
10
|
+
Secret,
|
|
11
|
+
AuthenticationService,
|
|
12
|
+
FileService
|
|
13
|
+
});
|
package/lib/resources/secret.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import crypto from 'crypto';
|
|
2
2
|
import { Resource } from '../resource.js';
|
|
3
|
-
import {
|
|
3
|
+
import { registry } from '../registry.js';
|
|
4
4
|
|
|
5
5
|
const FILENAME = 'secret';
|
|
6
6
|
|
|
@@ -21,7 +21,7 @@ export class Secret extends Resource {
|
|
|
21
21
|
*/
|
|
22
22
|
constructor(scope, id) {
|
|
23
23
|
super(scope, id);
|
|
24
|
-
this.#fileService = new FileService(this, 'files');
|
|
24
|
+
this.#fileService = new registry.FileService(this, 'files');
|
|
25
25
|
|
|
26
26
|
this.#initPromise = this.#fileService.write(
|
|
27
27
|
FILENAME,
|
|
@@ -3,10 +3,8 @@ import { scrypt, randomBytes } from 'crypto';
|
|
|
3
3
|
import * as jose from 'jose';
|
|
4
4
|
|
|
5
5
|
import { Resource } from '../resource.js';
|
|
6
|
-
import { Secret } from '../resources/secret.js';
|
|
7
|
-
import { FileService } from './file.js';
|
|
8
|
-
import { CookieJar } from '../adapters/cookie-jar.js';
|
|
9
6
|
import { withContext } from '../adapters/context.js';
|
|
7
|
+
import { registry } from '../registry.js';
|
|
10
8
|
|
|
11
9
|
|
|
12
10
|
/**
|
|
@@ -36,6 +34,8 @@ async function verifyHash(password, passwordHash) {
|
|
|
36
34
|
return rehashed === passwordHash;
|
|
37
35
|
}
|
|
38
36
|
|
|
37
|
+
// #region types
|
|
38
|
+
|
|
39
39
|
/**
|
|
40
40
|
* @typedef {{
|
|
41
41
|
* id: string;
|
|
@@ -99,6 +99,8 @@ async function verifyHash(password, passwordHash) {
|
|
|
99
99
|
* @property {string} [cookie] - The name of the cookie to use to store the authentication state JWT.
|
|
100
100
|
*/
|
|
101
101
|
|
|
102
|
+
// #endregion
|
|
103
|
+
|
|
102
104
|
const ONE_WEEK = 7 * 24 * 60 * 60; // days * hours/day * minutes/hour * seconds/minute
|
|
103
105
|
|
|
104
106
|
export class AuthenticationService extends Resource {
|
|
@@ -107,7 +109,7 @@ export class AuthenticationService extends Resource {
|
|
|
107
109
|
#cookieName;
|
|
108
110
|
|
|
109
111
|
/**
|
|
110
|
-
* @type {Secret}
|
|
112
|
+
* @type {typeof registry['Secret']}
|
|
111
113
|
*/
|
|
112
114
|
#rawSigningSecret;
|
|
113
115
|
|
|
@@ -131,8 +133,8 @@ export class AuthenticationService extends Resource {
|
|
|
131
133
|
this.#keepalive = !!keepalive;
|
|
132
134
|
this.#cookieName = cookie ?? 'identity';
|
|
133
135
|
|
|
134
|
-
this.#rawSigningSecret = new Secret(this, 'jwt-signing-secret');
|
|
135
|
-
const fileService = new FileService(this, 'files');
|
|
136
|
+
this.#rawSigningSecret = new registry.Secret(this, 'jwt-signing-secret');
|
|
137
|
+
const fileService = new registry.FileService(this, 'files');
|
|
136
138
|
|
|
137
139
|
this.#users = {
|
|
138
140
|
id,
|
|
@@ -192,7 +194,7 @@ export class AuthenticationService extends Resource {
|
|
|
192
194
|
}
|
|
193
195
|
|
|
194
196
|
/**
|
|
195
|
-
* @param {CookieJar} cookies
|
|
197
|
+
* @param {typeof registry['CookieJar']} cookies
|
|
196
198
|
* @returns {Promise<AuthenticationBaseState>}
|
|
197
199
|
*/
|
|
198
200
|
async getBaseState(cookies) {
|
|
@@ -223,7 +225,7 @@ export class AuthenticationService extends Resource {
|
|
|
223
225
|
}
|
|
224
226
|
|
|
225
227
|
/**
|
|
226
|
-
* @param {CookieJar} cookies
|
|
228
|
+
* @param {typeof registry['CookieJar']} cookies
|
|
227
229
|
* @returns {Promise<AuthenticationState>}
|
|
228
230
|
*/
|
|
229
231
|
async getState(cookies) {
|
|
@@ -291,7 +293,7 @@ export class AuthenticationService extends Resource {
|
|
|
291
293
|
|
|
292
294
|
/**
|
|
293
295
|
*
|
|
294
|
-
* @param {CookieJar} cookies
|
|
296
|
+
* @param {typeof registry['CookieJar']} cookies
|
|
295
297
|
* @param {string | undefined} [user]
|
|
296
298
|
*/
|
|
297
299
|
async setBaseState(cookies, user) {
|
|
@@ -336,7 +338,7 @@ export class AuthenticationService extends Resource {
|
|
|
336
338
|
}
|
|
337
339
|
|
|
338
340
|
/**
|
|
339
|
-
* @param {CookieJar} cookies
|
|
341
|
+
* @param {typeof registry['CookieJar']} cookies
|
|
340
342
|
* @param {PerformActionParameter} params
|
|
341
343
|
* @returns {Promise<AuthenticationState | { errors: AuthenticationError[] }>}
|
|
342
344
|
*/
|