@feathersjs/authentication-client 5.0.0-pre.9 → 5.0.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/CHANGELOG.md +179 -257
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/lib/core.d.ts +50 -2
- package/lib/core.js +68 -21
- package/lib/core.js.map +1 -1
- package/lib/hooks/authentication.js +5 -3
- package/lib/hooks/authentication.js.map +1 -1
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/populate-header.js.map +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/index.js +7 -6
- package/lib/index.js.map +1 -1
- package/lib/storage.js +1 -1
- package/lib/storage.js.map +1 -1
- package/package.json +24 -23
- package/src/core.ts +162 -118
- package/src/hooks/authentication.ts +19 -11
- package/src/hooks/index.ts +2 -2
- package/src/hooks/populate-header.ts +18 -11
- package/src/index.ts +36 -34
- package/src/storage.ts +23 -23
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @feathersjs/authentication-client
|
|
2
2
|
|
|
3
3
|
[](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
|
|
4
|
-
[](https://david-dm.org/feathersjs/feathers?path=packages/authentication-client)
|
|
5
4
|
[](https://www.npmjs.com/package/@feathersjs/authentication-client)
|
|
5
|
+
[](https://discord.gg/qa8kez8QBx)
|
|
6
6
|
|
|
7
7
|
> Feathers authentication client
|
|
8
8
|
|
|
@@ -18,6 +18,6 @@ Refer to the [Feathers authentication client API documentation](https://docs.fea
|
|
|
18
18
|
|
|
19
19
|
## License
|
|
20
20
|
|
|
21
|
-
Copyright (c)
|
|
21
|
+
Copyright (c) 2023 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
|
|
22
22
|
|
|
23
23
|
Licensed under the [MIT license](LICENSE).
|
package/lib/core.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FeathersError } from '@feathersjs/errors';
|
|
|
2
2
|
import { Application, Params } from '@feathersjs/feathers';
|
|
3
3
|
import { AuthenticationRequest, AuthenticationResult } from '@feathersjs/authentication';
|
|
4
4
|
import { Storage } from './storage';
|
|
5
|
-
export
|
|
5
|
+
export type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient;
|
|
6
6
|
export interface AuthenticationClientOptions {
|
|
7
7
|
storage: Storage;
|
|
8
8
|
header: string;
|
|
@@ -19,16 +19,64 @@ export declare class AuthenticationClient {
|
|
|
19
19
|
authenticated: boolean;
|
|
20
20
|
options: AuthenticationClientOptions;
|
|
21
21
|
constructor(app: Application, options: AuthenticationClientOptions);
|
|
22
|
-
get service(): import("@feathersjs/feathers").FeathersService<Application<any, any>, import("@feathersjs/feathers").Service<any, Partial<any
|
|
22
|
+
get service(): import("@feathersjs/feathers").FeathersService<Application<any, any>, import("@feathersjs/feathers").Service<any, Partial<any>, Params<import("@feathersjs/feathers").Query>, Partial<Partial<any>>>>;
|
|
23
23
|
get storage(): Storage;
|
|
24
24
|
handleSocket(socket: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* Parse the access token or authentication error from the window location hash. Will remove it from the hash
|
|
27
|
+
* if found.
|
|
28
|
+
*
|
|
29
|
+
* @param location The window location
|
|
30
|
+
* @returns The access token if available, will throw an error if found, otherwise null
|
|
31
|
+
*/
|
|
25
32
|
getFromLocation(location: Location): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Set the access token in storage.
|
|
35
|
+
*
|
|
36
|
+
* @param accessToken The access token to set
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
26
39
|
setAccessToken(accessToken: string): any;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the access token from storage or the window location hash.
|
|
42
|
+
*
|
|
43
|
+
* @returns The access token from storage or location hash
|
|
44
|
+
*/
|
|
27
45
|
getAccessToken(): Promise<string | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Remove the access token from storage
|
|
48
|
+
* @returns The removed access token
|
|
49
|
+
*/
|
|
28
50
|
removeAccessToken(): any;
|
|
51
|
+
/**
|
|
52
|
+
* Reset the internal authentication state. Usually not necessary to call directly.
|
|
53
|
+
*
|
|
54
|
+
* @returns null
|
|
55
|
+
*/
|
|
29
56
|
reset(): Promise<any>;
|
|
30
57
|
handleError(error: FeathersError, type: 'authenticate' | 'logout'): any;
|
|
58
|
+
/**
|
|
59
|
+
* Try to reauthenticate using the token from storage. Will do nothing if already authenticated unless
|
|
60
|
+
* `force` is true.
|
|
61
|
+
*
|
|
62
|
+
* @param force force reauthentication with the server
|
|
63
|
+
* @param strategy The name of the strategy to use. Defaults to `options.jwtStrategy`
|
|
64
|
+
* @returns The reauthentication result
|
|
65
|
+
*/
|
|
31
66
|
reAuthenticate(force?: boolean, strategy?: string): Promise<AuthenticationResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Authenticate using a specific strategy and data.
|
|
69
|
+
*
|
|
70
|
+
* @param authentication The authentication data
|
|
71
|
+
* @param params Additional parameters
|
|
72
|
+
* @returns The authentication result
|
|
73
|
+
*/
|
|
32
74
|
authenticate(authentication?: AuthenticationRequest, params?: Params): Promise<AuthenticationResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Log out the current user and remove their token. Will do nothing
|
|
77
|
+
* if not authenticated.
|
|
78
|
+
*
|
|
79
|
+
* @returns The log out result.
|
|
80
|
+
*/
|
|
33
81
|
logout(): Promise<AuthenticationResult | null>;
|
|
34
82
|
}
|
package/lib/core.js
CHANGED
|
@@ -36,18 +36,21 @@ class AuthenticationClient {
|
|
|
36
36
|
return this.app.get('storage');
|
|
37
37
|
}
|
|
38
38
|
handleSocket(socket) {
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// has been called explicitly first
|
|
46
|
-
// Force reauthentication with the server
|
|
47
|
-
.then(() => this.authenticated ? this.reAuthenticate(true) : null);
|
|
48
|
-
this.app.set('authentication', authPromise);
|
|
39
|
+
// When the socket disconnects and we are still authenticated, try to reauthenticate right away
|
|
40
|
+
// the websocket connection will handle timeouts and retries
|
|
41
|
+
socket.on('disconnect', () => {
|
|
42
|
+
if (this.authenticated) {
|
|
43
|
+
this.reAuthenticate(true);
|
|
44
|
+
}
|
|
49
45
|
});
|
|
50
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse the access token or authentication error from the window location hash. Will remove it from the hash
|
|
49
|
+
* if found.
|
|
50
|
+
*
|
|
51
|
+
* @param location The window location
|
|
52
|
+
* @returns The access token if available, will throw an error if found, otherwise null
|
|
53
|
+
*/
|
|
51
54
|
getFromLocation(location) {
|
|
52
55
|
const [accessToken, tokenRegex] = getMatch(location, this.options.locationKey);
|
|
53
56
|
if (accessToken !== null) {
|
|
@@ -61,69 +64,113 @@ class AuthenticationClient {
|
|
|
61
64
|
}
|
|
62
65
|
return Promise.resolve(null);
|
|
63
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Set the access token in storage.
|
|
69
|
+
*
|
|
70
|
+
* @param accessToken The access token to set
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
64
73
|
setAccessToken(accessToken) {
|
|
65
74
|
return this.storage.setItem(this.options.storageKey, accessToken);
|
|
66
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns the access token from storage or the window location hash.
|
|
78
|
+
*
|
|
79
|
+
* @returns The access token from storage or location hash
|
|
80
|
+
*/
|
|
67
81
|
getAccessToken() {
|
|
68
|
-
return this.storage.getItem(this.options.storageKey)
|
|
69
|
-
.then((accessToken) => {
|
|
82
|
+
return this.storage.getItem(this.options.storageKey).then((accessToken) => {
|
|
70
83
|
if (!accessToken && typeof window !== 'undefined' && window.location) {
|
|
71
84
|
return this.getFromLocation(window.location);
|
|
72
85
|
}
|
|
73
86
|
return accessToken || null;
|
|
74
87
|
});
|
|
75
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Remove the access token from storage
|
|
91
|
+
* @returns The removed access token
|
|
92
|
+
*/
|
|
76
93
|
removeAccessToken() {
|
|
77
94
|
return this.storage.removeItem(this.options.storageKey);
|
|
78
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Reset the internal authentication state. Usually not necessary to call directly.
|
|
98
|
+
*
|
|
99
|
+
* @returns null
|
|
100
|
+
*/
|
|
79
101
|
reset() {
|
|
80
102
|
this.app.set('authentication', null);
|
|
81
103
|
this.authenticated = false;
|
|
82
104
|
return Promise.resolve(null);
|
|
83
105
|
}
|
|
84
106
|
handleError(error, type) {
|
|
85
|
-
|
|
107
|
+
// For NotAuthenticated, PaymentError, Forbidden, NotFound, MethodNotAllowed, NotAcceptable
|
|
108
|
+
// errors, remove the access token
|
|
109
|
+
if (error.code > 400 && error.code < 408) {
|
|
86
110
|
const promise = this.removeAccessToken().then(() => this.reset());
|
|
87
111
|
return type === 'logout' ? promise : promise.then(() => Promise.reject(error));
|
|
88
112
|
}
|
|
89
|
-
return Promise.reject(error);
|
|
113
|
+
return this.reset().then(() => Promise.reject(error));
|
|
90
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Try to reauthenticate using the token from storage. Will do nothing if already authenticated unless
|
|
117
|
+
* `force` is true.
|
|
118
|
+
*
|
|
119
|
+
* @param force force reauthentication with the server
|
|
120
|
+
* @param strategy The name of the strategy to use. Defaults to `options.jwtStrategy`
|
|
121
|
+
* @returns The reauthentication result
|
|
122
|
+
*/
|
|
91
123
|
reAuthenticate(force = false, strategy) {
|
|
92
124
|
// Either returns the authentication state or
|
|
93
125
|
// tries to re-authenticate with the stored JWT and strategy
|
|
94
|
-
|
|
126
|
+
let authPromise = this.app.get('authentication');
|
|
95
127
|
if (!authPromise || force === true) {
|
|
96
|
-
|
|
128
|
+
authPromise = this.getAccessToken().then((accessToken) => {
|
|
97
129
|
if (!accessToken) {
|
|
98
|
-
|
|
130
|
+
return this.handleError(new errors_1.NotAuthenticated('No accessToken found in storage'), 'authenticate');
|
|
99
131
|
}
|
|
100
132
|
return this.authenticate({
|
|
101
133
|
strategy: strategy || this.options.jwtStrategy,
|
|
102
134
|
accessToken
|
|
103
135
|
});
|
|
104
136
|
});
|
|
137
|
+
this.app.set('authentication', authPromise);
|
|
105
138
|
}
|
|
106
139
|
return authPromise;
|
|
107
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Authenticate using a specific strategy and data.
|
|
143
|
+
*
|
|
144
|
+
* @param authentication The authentication data
|
|
145
|
+
* @param params Additional parameters
|
|
146
|
+
* @returns The authentication result
|
|
147
|
+
*/
|
|
108
148
|
authenticate(authentication, params) {
|
|
109
149
|
if (!authentication) {
|
|
110
150
|
return this.reAuthenticate();
|
|
111
151
|
}
|
|
112
|
-
const promise = this.service
|
|
152
|
+
const promise = this.service
|
|
153
|
+
.create(authentication, params)
|
|
113
154
|
.then((authResult) => {
|
|
114
155
|
const { accessToken } = authResult;
|
|
115
156
|
this.authenticated = true;
|
|
116
157
|
this.app.emit('login', authResult);
|
|
117
158
|
this.app.emit('authenticated', authResult);
|
|
118
159
|
return this.setAccessToken(accessToken).then(() => authResult);
|
|
119
|
-
})
|
|
160
|
+
})
|
|
161
|
+
.catch((error) => this.handleError(error, 'authenticate'));
|
|
120
162
|
this.app.set('authentication', promise);
|
|
121
163
|
return promise;
|
|
122
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Log out the current user and remove their token. Will do nothing
|
|
167
|
+
* if not authenticated.
|
|
168
|
+
*
|
|
169
|
+
* @returns The log out result.
|
|
170
|
+
*/
|
|
123
171
|
logout() {
|
|
124
172
|
return Promise.resolve(this.app.get('authentication'))
|
|
125
|
-
.then(() => this.service.remove(null)
|
|
126
|
-
.then((authResult) => this.removeAccessToken()
|
|
173
|
+
.then(() => this.service.remove(null).then((authResult) => this.removeAccessToken()
|
|
127
174
|
.then(() => this.reset())
|
|
128
175
|
.then(() => {
|
|
129
176
|
this.app.emit('logout', authResult);
|
package/lib/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/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AC;CACF;AA1MD,oDA0MC"}
|
|
@@ -5,14 +5,16 @@ const commons_1 = require("@feathersjs/commons");
|
|
|
5
5
|
const authentication = () => {
|
|
6
6
|
return (context, next) => {
|
|
7
7
|
const { app, params, path, method, app: { authentication: service } } = context;
|
|
8
|
-
if (commons_1.stripSlashes(service.options.path) === path && method === 'create') {
|
|
8
|
+
if ((0, commons_1.stripSlashes)(service.options.path) === path && method === 'create') {
|
|
9
9
|
return next();
|
|
10
10
|
}
|
|
11
|
-
return Promise.resolve(app.get('authentication'))
|
|
11
|
+
return Promise.resolve(app.get('authentication'))
|
|
12
|
+
.then((authResult) => {
|
|
12
13
|
if (authResult) {
|
|
13
14
|
context.params = Object.assign({}, authResult, params);
|
|
14
15
|
}
|
|
15
|
-
})
|
|
16
|
+
})
|
|
17
|
+
.then(next);
|
|
16
18
|
};
|
|
17
19
|
};
|
|
18
20
|
exports.authentication = authentication;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/hooks/authentication.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/hooks/authentication.ts"],"names":[],"mappings":";;;AACA,iDAAkD;AAE3C,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,CAAC,OAAoB,EAAE,IAAkB,EAAE,EAAE;QAClD,MAAM,EACJ,GAAG,EACH,MAAM,EACN,IAAI,EACJ,MAAM,EACN,GAAG,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,EACjC,GAAG,OAAO,CAAA;QAEX,IAAI,IAAA,sBAAY,EAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,MAAM,KAAK,QAAQ,EAAE;YACtE,OAAO,IAAI,EAAE,CAAA;SACd;QAED,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;aAC9C,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE;YACnB,IAAI,UAAU,EAAE;gBACd,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;aACvD;QACH,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AAtBY,QAAA,cAAc,kBAsB1B"}
|
package/lib/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAAxC,gHAAA,cAAc,OAAA;AACvB,qDAAkD;AAAzC,iHAAA,cAAc,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"populate-header.js","sourceRoot":"","sources":["../../src/hooks/populate-header.ts"],"names":[],"mappings":";;;AAEO,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,CAAC,OAAoB,EAAE,IAAkB,EAAE,EAAE;QAClD,MAAM,
|
|
1
|
+
{"version":3,"file":"populate-header.js","sourceRoot":"","sources":["../../src/hooks/populate-header.ts"],"names":[],"mappings":";;;AAEO,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,CAAC,OAAoB,EAAE,IAAkB,EAAE,EAAE;QAClD,MAAM,EACJ,GAAG,EACH,MAAM,EAAE,EAAE,WAAW,EAAE,EACxB,GAAG,OAAO,CAAA;QACX,MAAM,cAAc,GAAG,GAAG,CAAC,cAAc,CAAA;QAEzC,+BAA+B;QAC/B,IAAI,GAAG,CAAC,IAAI,IAAI,WAAW,EAAE;YAC3B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,OAAO,CAAA;YACjD,MAAM,UAAU,GAAG,GAAG,MAAM,IAAI,WAAW,EAAE,CAAA;YAE7C,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CACpC,EAAE,EACF;gBACE,CAAC,MAAM,CAAC,EAAE,UAAU;aACrB,EACD,OAAO,CAAC,MAAM,CAAC,OAAO,CACvB,CAAA;SACF;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA;AAxBY,QAAA,cAAc,kBAwB1B"}
|
package/lib/index.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import * as hooks from './hooks';
|
|
|
3
3
|
import { Application } from '@feathersjs/feathers';
|
|
4
4
|
import { Storage, MemoryStorage, StorageWrapper } from './storage';
|
|
5
5
|
declare module '@feathersjs/feathers/lib/declarations' {
|
|
6
|
-
interface Application<
|
|
7
|
-
io
|
|
6
|
+
interface Application<Services, Settings> {
|
|
7
|
+
io: any;
|
|
8
8
|
rest?: any;
|
|
9
9
|
authentication: AuthenticationClient;
|
|
10
10
|
authenticate: AuthenticationClient['authenticate'];
|
|
@@ -14,7 +14,7 @@ declare module '@feathersjs/feathers/lib/declarations' {
|
|
|
14
14
|
}
|
|
15
15
|
export declare const getDefaultStorage: () => MemoryStorage | StorageWrapper;
|
|
16
16
|
export { AuthenticationClient, AuthenticationClientOptions, Storage, MemoryStorage, hooks };
|
|
17
|
-
export
|
|
17
|
+
export type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient;
|
|
18
18
|
export declare const defaultStorage: Storage;
|
|
19
19
|
export declare const defaults: AuthenticationClientOptions;
|
|
20
20
|
declare const init: (_options?: Partial<AuthenticationClientOptions>) => (app: Application) => void;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -34,7 +38,7 @@ const getDefaultStorage = () => {
|
|
|
34
38
|
return new storage_1.MemoryStorage();
|
|
35
39
|
};
|
|
36
40
|
exports.getDefaultStorage = getDefaultStorage;
|
|
37
|
-
exports.defaultStorage = exports.getDefaultStorage();
|
|
41
|
+
exports.defaultStorage = (0, exports.getDefaultStorage)();
|
|
38
42
|
exports.defaults = {
|
|
39
43
|
header: 'Authorization',
|
|
40
44
|
scheme: 'Bearer',
|
|
@@ -55,10 +59,7 @@ const init = (_options = {}) => {
|
|
|
55
59
|
app.authenticate = authentication.authenticate.bind(authentication);
|
|
56
60
|
app.reAuthenticate = authentication.reAuthenticate.bind(authentication);
|
|
57
61
|
app.logout = authentication.logout.bind(authentication);
|
|
58
|
-
app.hooks([
|
|
59
|
-
hooks.authentication(),
|
|
60
|
-
hooks.populateHeader()
|
|
61
|
-
]);
|
|
62
|
+
app.hooks([hooks.authentication(), hooks.populateHeader()]);
|
|
62
63
|
};
|
|
63
64
|
};
|
|
64
65
|
exports.default = init;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA0E;AA0BjE,qGA1BA,2BAAoB,OA0BA;AAzB7B,+CAAgC;AAyBoD,sBAAK;AAvBzF,uCAAkE;AAuBG,8FAvBnD,uBAAa,OAuBmD;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AC,cAAc,EAAE,CAAC,CAAC,CAAA;IAC7D,CAAC,CAAA;AACH,CAAC,CAAA;AAED,kBAAe,IAAI,CAAA;AAEnB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;CACrD"}
|
package/lib/storage.js
CHANGED
package/lib/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":";;;AAMA,MAAa,aAAa;IAGxB;QACE,IAAI,CAAC,KAAK,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":";;;AAMA,MAAa,aAAa;IAGxB;QACE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;IACjB,CAAC;IAED,OAAO,CAAC,GAAW;QACjB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IACzC,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,KAAU;QAC7B,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,CAAA;IACnD,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAE7B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAEtB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;CACF;AAtBD,sCAsBC;AAED,MAAa,cAAc;IAGzB,YAAY,OAAY;QACtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAED,OAAO,CAAC,GAAW;QACjB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;IACnD,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,KAAU;QAC7B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;IACtD,CAAC;CACF;AAlBD,wCAkBC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/authentication-client",
|
|
3
3
|
"description": "The authentication plugin for feathers-client",
|
|
4
|
-
"version": "5.0.0
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git://github.com/feathersjs/feathers.git"
|
|
19
|
+
"url": "git://github.com/feathersjs/feathers.git",
|
|
20
|
+
"directory": "packages/authentication-client"
|
|
20
21
|
},
|
|
21
22
|
"author": {
|
|
22
23
|
"name": "Feathers contributors",
|
|
@@ -41,9 +42,9 @@
|
|
|
41
42
|
],
|
|
42
43
|
"scripts": {
|
|
43
44
|
"prepublish": "npm run compile",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
45
|
+
"pack": "npm pack --pack-destination ../generators/test/build",
|
|
46
|
+
"compile": "shx rm -rf lib/ && tsc && npm run pack",
|
|
47
|
+
"test": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
|
|
47
48
|
},
|
|
48
49
|
"directories": {
|
|
49
50
|
"lib": "lib"
|
|
@@ -52,25 +53,25 @@
|
|
|
52
53
|
"access": "public"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@feathersjs/authentication": "^5.0.0
|
|
56
|
-
"@feathersjs/commons": "^5.0.0
|
|
57
|
-
"@feathersjs/errors": "^5.0.0
|
|
58
|
-
"@feathersjs/feathers": "^5.0.0
|
|
56
|
+
"@feathersjs/authentication": "^5.0.0",
|
|
57
|
+
"@feathersjs/commons": "^5.0.0",
|
|
58
|
+
"@feathersjs/errors": "^5.0.0",
|
|
59
|
+
"@feathersjs/feathers": "^5.0.0"
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
|
-
"@feathersjs/authentication-local": "^5.0.0
|
|
62
|
-
"@feathersjs/express": "^5.0.0
|
|
63
|
-
"@feathersjs/memory": "^5.0.0
|
|
64
|
-
"@feathersjs/rest-client": "^5.0.0
|
|
65
|
-
"@feathersjs/socketio": "^5.0.0
|
|
66
|
-
"@feathersjs/socketio-client": "^5.0.0
|
|
67
|
-
"@types/mocha": "^
|
|
68
|
-
"@types/node": "^
|
|
69
|
-
"axios": "^
|
|
70
|
-
"mocha": "^
|
|
71
|
-
"shx": "^0.3.
|
|
72
|
-
"ts-node": "^10.1
|
|
73
|
-
"typescript": "^4.
|
|
62
|
+
"@feathersjs/authentication-local": "^5.0.0",
|
|
63
|
+
"@feathersjs/express": "^5.0.0",
|
|
64
|
+
"@feathersjs/memory": "^5.0.0",
|
|
65
|
+
"@feathersjs/rest-client": "^5.0.0",
|
|
66
|
+
"@feathersjs/socketio": "^5.0.0",
|
|
67
|
+
"@feathersjs/socketio-client": "^5.0.0",
|
|
68
|
+
"@types/mocha": "^10.0.1",
|
|
69
|
+
"@types/node": "^18.14.1",
|
|
70
|
+
"axios": "^1.3.4",
|
|
71
|
+
"mocha": "^10.2.0",
|
|
72
|
+
"shx": "^0.3.4",
|
|
73
|
+
"ts-node": "^10.9.1",
|
|
74
|
+
"typescript": "^4.9.5"
|
|
74
75
|
},
|
|
75
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "90caf635aec850550b9d37bea2762af959d9e8d5"
|
|
76
77
|
}
|