@feathersjs/authentication-client 5.0.0-pre.10

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
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Feathers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @feathersjs/authentication-client
2
+
3
+ [![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
4
+ [![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/authentication-client)](https://david-dm.org/feathersjs/feathers?path=packages/authentication-client)
5
+ [![Download Status](https://img.shields.io/npm/dm/@feathersjs/authentication-client.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/authentication-client)
6
+
7
+ > Feathers authentication client
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ npm install @feathersjs/authentication-client --save
13
+ ```
14
+
15
+ ## Documentation
16
+
17
+ Refer to the [Feathers authentication client API documentation](https://docs.feathersjs.com/api/authentication/client.html) for more details.
18
+
19
+ ## License
20
+
21
+ Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
22
+
23
+ Licensed under the [MIT license](LICENSE).
package/lib/core.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { FeathersError } from '@feathersjs/errors';
2
+ import { Application, Params } from '@feathersjs/feathers';
3
+ import { AuthenticationRequest, AuthenticationResult } from '@feathersjs/authentication';
4
+ import { Storage } from './storage';
5
+ export declare type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient;
6
+ export interface AuthenticationClientOptions {
7
+ storage: Storage;
8
+ header: string;
9
+ scheme: string;
10
+ storageKey: string;
11
+ locationKey: string;
12
+ locationErrorKey: string;
13
+ jwtStrategy: string;
14
+ path: string;
15
+ Authentication: ClientConstructor;
16
+ }
17
+ export declare class AuthenticationClient {
18
+ app: Application;
19
+ authenticated: boolean;
20
+ options: AuthenticationClientOptions;
21
+ constructor(app: Application, options: AuthenticationClientOptions);
22
+ get service(): import("@feathersjs/feathers").FeathersService<Application<any, any>, import("@feathersjs/feathers").Service<any, Partial<any>>>;
23
+ get storage(): Storage;
24
+ handleSocket(socket: any): void;
25
+ getFromLocation(location: Location): Promise<any>;
26
+ setAccessToken(accessToken: string): any;
27
+ getAccessToken(): Promise<string | null>;
28
+ removeAccessToken(): any;
29
+ reset(): Promise<any>;
30
+ handleError(error: FeathersError, type: 'authenticate' | 'logout'): any;
31
+ reAuthenticate(force?: boolean, strategy?: string): Promise<AuthenticationResult>;
32
+ authenticate(authentication?: AuthenticationRequest, params?: Params): Promise<AuthenticationResult>;
33
+ logout(): Promise<AuthenticationResult | null>;
34
+ }
package/lib/core.js ADDED
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthenticationClient = void 0;
4
+ const errors_1 = require("@feathersjs/errors");
5
+ const storage_1 = require("./storage");
6
+ class OauthError extends errors_1.FeathersError {
7
+ constructor(message, data) {
8
+ super(message, 'OauthError', 401, 'oauth-error', data);
9
+ }
10
+ }
11
+ const getMatch = (location, key) => {
12
+ const regex = new RegExp(`(?:\&?)${key}=([^&]*)`);
13
+ const match = location.hash ? location.hash.match(regex) : null;
14
+ if (match !== null) {
15
+ const [, value] = match;
16
+ return [value, regex];
17
+ }
18
+ return [null, regex];
19
+ };
20
+ class AuthenticationClient {
21
+ constructor(app, options) {
22
+ const socket = app.io;
23
+ const storage = new storage_1.StorageWrapper(app.get('storage') || options.storage);
24
+ this.app = app;
25
+ this.options = options;
26
+ this.authenticated = false;
27
+ this.app.set('storage', storage);
28
+ if (socket) {
29
+ this.handleSocket(socket);
30
+ }
31
+ }
32
+ get service() {
33
+ return this.app.service(this.options.path);
34
+ }
35
+ get storage() {
36
+ return this.app.get('storage');
37
+ }
38
+ handleSocket(socket) {
39
+ // Connection events happen on every reconnect
40
+ const connected = this.app.io ? 'connect' : 'open';
41
+ const disconnected = this.app.io ? 'disconnect' : 'disconnection';
42
+ socket.on(disconnected, () => {
43
+ const authPromise = new Promise(resolve => socket.once(connected, (data) => resolve(data)))
44
+ // Only reconnect when `reAuthenticate()` or `authenticate()`
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);
49
+ });
50
+ }
51
+ getFromLocation(location) {
52
+ const [accessToken, tokenRegex] = getMatch(location, this.options.locationKey);
53
+ if (accessToken !== null) {
54
+ location.hash = location.hash.replace(tokenRegex, '');
55
+ return Promise.resolve(accessToken);
56
+ }
57
+ const [message, errorRegex] = getMatch(location, this.options.locationErrorKey);
58
+ if (message !== null) {
59
+ location.hash = location.hash.replace(errorRegex, '');
60
+ return Promise.reject(new OauthError(decodeURIComponent(message)));
61
+ }
62
+ return Promise.resolve(null);
63
+ }
64
+ setAccessToken(accessToken) {
65
+ return this.storage.setItem(this.options.storageKey, accessToken);
66
+ }
67
+ getAccessToken() {
68
+ return this.storage.getItem(this.options.storageKey)
69
+ .then((accessToken) => {
70
+ if (!accessToken && typeof window !== 'undefined' && window.location) {
71
+ return this.getFromLocation(window.location);
72
+ }
73
+ return accessToken || null;
74
+ });
75
+ }
76
+ removeAccessToken() {
77
+ return this.storage.removeItem(this.options.storageKey);
78
+ }
79
+ reset() {
80
+ this.app.set('authentication', null);
81
+ this.authenticated = false;
82
+ return Promise.resolve(null);
83
+ }
84
+ handleError(error, type) {
85
+ if (error.code === 401 || error.code === 403) {
86
+ const promise = this.removeAccessToken().then(() => this.reset());
87
+ return type === 'logout' ? promise : promise.then(() => Promise.reject(error));
88
+ }
89
+ return Promise.reject(error);
90
+ }
91
+ reAuthenticate(force = false, strategy) {
92
+ // Either returns the authentication state or
93
+ // tries to re-authenticate with the stored JWT and strategy
94
+ const authPromise = this.app.get('authentication');
95
+ if (!authPromise || force === true) {
96
+ return this.getAccessToken().then(accessToken => {
97
+ if (!accessToken) {
98
+ throw new errors_1.NotAuthenticated('No accessToken found in storage');
99
+ }
100
+ return this.authenticate({
101
+ strategy: strategy || this.options.jwtStrategy,
102
+ accessToken
103
+ });
104
+ });
105
+ }
106
+ return authPromise;
107
+ }
108
+ authenticate(authentication, params) {
109
+ if (!authentication) {
110
+ return this.reAuthenticate();
111
+ }
112
+ const promise = this.service.create(authentication, params)
113
+ .then((authResult) => {
114
+ const { accessToken } = authResult;
115
+ this.authenticated = true;
116
+ this.app.emit('login', authResult);
117
+ this.app.emit('authenticated', authResult);
118
+ return this.setAccessToken(accessToken).then(() => authResult);
119
+ }).catch((error) => this.handleError(error, 'authenticate'));
120
+ this.app.set('authentication', promise);
121
+ return promise;
122
+ }
123
+ logout() {
124
+ return Promise.resolve(this.app.get('authentication'))
125
+ .then(() => this.service.remove(null)
126
+ .then((authResult) => this.removeAccessToken()
127
+ .then(() => this.reset())
128
+ .then(() => {
129
+ this.app.emit('logout', authResult);
130
+ return authResult;
131
+ })))
132
+ .catch((error) => this.handleError(error, 'logout'));
133
+ }
134
+ }
135
+ exports.AuthenticationClient = AuthenticationClient;
136
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;AAAA,+CAAqE;AAGrE,uCAAoD;AAEpD,MAAM,UAAW,SAAQ,sBAAa;IACpC,YAAa,OAAe,EAAE,IAAU;QACtC,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;IACzD,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,CAAC,QAAkB,EAAE,GAAW,EAAsB,EAAE;IACvE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC,CAAC;IAClD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEhE,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,MAAM,CAAE,AAAD,EAAG,KAAK,CAAE,GAAG,KAAK,CAAC;QAE1B,OAAO,CAAE,KAAK,EAAE,KAAK,CAAE,CAAC;KACzB;IAED,OAAO,CAAE,IAAI,EAAE,KAAK,CAAE,CAAC;AACzB,CAAC,CAAC;AAiBF,MAAa,oBAAoB;IAK/B,YAAa,GAAgB,EAAE,OAAoC;QACjE,MAAM,MAAM,GAAG,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,OAAO,GAAG,IAAI,wBAAc,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;QAE1E,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAA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,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE;aACjE,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;aACxB,IAAI,CAAC,GAAG,EAAE;YACT,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;YAEpC,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC,CACH,CAAC;aACD,KAAK,CAAC,CAAC,KAAoB,EAAE,EAAE,CAC9B,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAClC,CAAC;IACN,CAAC;CACF;AAhKD,oDAgKC"}
@@ -0,0 +1,2 @@
1
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
2
+ export declare const authentication: () => (context: HookContext, next: NextFunction) => Promise<any>;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authentication = void 0;
4
+ const commons_1 = require("@feathersjs/commons");
5
+ const authentication = () => {
6
+ return (context, next) => {
7
+ const { app, params, path, method, app: { authentication: service } } = context;
8
+ if ((0, commons_1.stripSlashes)(service.options.path) === path && method === 'create') {
9
+ return next();
10
+ }
11
+ return Promise.resolve(app.get('authentication')).then(authResult => {
12
+ if (authResult) {
13
+ context.params = Object.assign({}, authResult, params);
14
+ }
15
+ }).then(next);
16
+ };
17
+ };
18
+ exports.authentication = authentication;
19
+ //# sourceMappingURL=authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.js","sourceRoot":"","sources":["../../src/hooks/authentication.ts"],"names":[],"mappings":";;;AACA,iDAAmD;AAE5C,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,CAAC,OAAoB,EAAE,IAAkB,EAAE,EAAE;QAClD,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC;QAEhF,IAAI,IAAA,sBAAY,EAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,MAAM,KAAK,QAAQ,EAAE;YACtE,OAAO,IAAI,EAAE,CAAC;SACf;QAED,OAAO,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YAClE,IAAI,UAAU,EAAE;gBACd,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;aACxD;QACH,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,cAAc,kBAczB"}
@@ -0,0 +1,2 @@
1
+ export { authentication } from './authentication';
2
+ export { populateHeader } from './populate-header';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.populateHeader = exports.authentication = void 0;
4
+ var authentication_1 = require("./authentication");
5
+ Object.defineProperty(exports, "authentication", { enumerable: true, get: function () { return authentication_1.authentication; } });
6
+ var populate_header_1 = require("./populate-header");
7
+ Object.defineProperty(exports, "populateHeader", { enumerable: true, get: function () { return populate_header_1.populateHeader; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;AAAA,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA"}
@@ -0,0 +1,2 @@
1
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
2
+ export declare const populateHeader: () => (context: HookContext, next: NextFunction) => Promise<any>;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.populateHeader = void 0;
4
+ const populateHeader = () => {
5
+ return (context, next) => {
6
+ const { app, params: { accessToken } } = context;
7
+ const authentication = app.authentication;
8
+ // Set REST header if necessary
9
+ if (app.rest && accessToken) {
10
+ const { scheme, header } = authentication.options;
11
+ const authHeader = `${scheme} ${accessToken}`;
12
+ context.params.headers = Object.assign({}, {
13
+ [header]: authHeader
14
+ }, context.params.headers);
15
+ }
16
+ return next();
17
+ };
18
+ };
19
+ exports.populateHeader = populateHeader;
20
+ //# sourceMappingURL=populate-header.js.map
@@ -0,0 +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,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,GAAG,OAAO,CAAC;QACjD,MAAM,cAAc,GAAG,GAAG,CAAC,cAAc,CAAC;QAE1C,+BAA+B;QAC/B,IAAI,GAAG,CAAC,IAAI,IAAI,WAAW,EAAE;YAC3B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,OAAO,CAAC;YAClD,MAAM,UAAU,GAAG,GAAG,MAAM,IAAI,WAAW,EAAE,CAAC;YAE9C,OAAO,CAAC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE;gBACzC,CAAC,MAAM,CAAC,EAAE,UAAU;aACrB,EAAE,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SAC5B;QAED,OAAO,IAAI,EAAE,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC,CAAC;AAjBW,QAAA,cAAc,kBAiBzB"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { AuthenticationClient, AuthenticationClientOptions } from './core';
2
+ import * as hooks from './hooks';
3
+ import { Application } from '@feathersjs/feathers';
4
+ import { Storage, MemoryStorage, StorageWrapper } from './storage';
5
+ declare module '@feathersjs/feathers/lib/declarations' {
6
+ interface Application<ServiceTypes, AppSettings> {
7
+ io?: any;
8
+ rest?: any;
9
+ authentication: AuthenticationClient;
10
+ authenticate: AuthenticationClient['authenticate'];
11
+ reAuthenticate: AuthenticationClient['reAuthenticate'];
12
+ logout: AuthenticationClient['logout'];
13
+ }
14
+ }
15
+ export declare const getDefaultStorage: () => MemoryStorage | StorageWrapper;
16
+ export { AuthenticationClient, AuthenticationClientOptions, Storage, MemoryStorage, hooks };
17
+ export declare type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient;
18
+ export declare const defaultStorage: Storage;
19
+ export declare const defaults: AuthenticationClientOptions;
20
+ declare const init: (_options?: Partial<AuthenticationClientOptions>) => (app: Application) => void;
21
+ export default init;
package/lib/index.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.defaults = exports.defaultStorage = exports.hooks = exports.MemoryStorage = exports.AuthenticationClient = exports.getDefaultStorage = void 0;
23
+ const core_1 = require("./core");
24
+ Object.defineProperty(exports, "AuthenticationClient", { enumerable: true, get: function () { return core_1.AuthenticationClient; } });
25
+ const hooks = __importStar(require("./hooks"));
26
+ exports.hooks = hooks;
27
+ const storage_1 = require("./storage");
28
+ Object.defineProperty(exports, "MemoryStorage", { enumerable: true, get: function () { return storage_1.MemoryStorage; } });
29
+ const getDefaultStorage = () => {
30
+ try {
31
+ return new storage_1.StorageWrapper(window.localStorage);
32
+ }
33
+ catch (error) { }
34
+ return new storage_1.MemoryStorage();
35
+ };
36
+ exports.getDefaultStorage = getDefaultStorage;
37
+ exports.defaultStorage = (0, exports.getDefaultStorage)();
38
+ exports.defaults = {
39
+ header: 'Authorization',
40
+ scheme: 'Bearer',
41
+ storageKey: 'feathers-jwt',
42
+ locationKey: 'access_token',
43
+ locationErrorKey: 'error',
44
+ jwtStrategy: 'jwt',
45
+ path: '/authentication',
46
+ Authentication: core_1.AuthenticationClient,
47
+ storage: exports.defaultStorage
48
+ };
49
+ const init = (_options = {}) => {
50
+ const options = Object.assign({}, exports.defaults, _options);
51
+ const { Authentication } = options;
52
+ return (app) => {
53
+ const authentication = new Authentication(app, options);
54
+ app.authentication = authentication;
55
+ app.authenticate = authentication.authenticate.bind(authentication);
56
+ app.reAuthenticate = authentication.reAuthenticate.bind(authentication);
57
+ app.logout = authentication.logout.bind(authentication);
58
+ app.hooks([
59
+ hooks.authentication(),
60
+ hooks.populateHeader()
61
+ ]);
62
+ };
63
+ };
64
+ exports.default = init;
65
+ if (typeof module !== 'undefined') {
66
+ module.exports = Object.assign(init, module.exports);
67
+ }
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA2E;AAwBlE,qGAxBA,2BAAoB,OAwBA;AAvB7B,+CAAiC;AAuBmD,sBAAK;AArBzF,uCAAmE;AAqBE,8FArBnD,uBAAa,OAqBmD;AAR3E,MAAM,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;SACvB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,IAAI,CAAC;AAEpB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACtD"}
@@ -0,0 +1,21 @@
1
+ export interface Storage {
2
+ getItem(key: string): any;
3
+ setItem?(key: string, value: any): any;
4
+ removeItem?(key: string): any;
5
+ }
6
+ export declare class MemoryStorage implements Storage {
7
+ store: {
8
+ [key: string]: any;
9
+ };
10
+ constructor();
11
+ getItem(key: string): Promise<any>;
12
+ setItem(key: string, value: any): Promise<any>;
13
+ removeItem(key: string): Promise<any>;
14
+ }
15
+ export declare class StorageWrapper implements Storage {
16
+ storage: any;
17
+ constructor(storage: any);
18
+ getItem(key: string): Promise<any>;
19
+ setItem(key: string, value: any): Promise<any>;
20
+ removeItem(key: string): Promise<any>;
21
+ }
package/lib/storage.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StorageWrapper = exports.MemoryStorage = void 0;
4
+ class MemoryStorage {
5
+ constructor() {
6
+ this.store = {};
7
+ }
8
+ getItem(key) {
9
+ return Promise.resolve(this.store[key]);
10
+ }
11
+ setItem(key, value) {
12
+ return Promise.resolve(this.store[key] = value);
13
+ }
14
+ removeItem(key) {
15
+ const value = this.store[key];
16
+ delete this.store[key];
17
+ return Promise.resolve(value);
18
+ }
19
+ }
20
+ exports.MemoryStorage = MemoryStorage;
21
+ class StorageWrapper {
22
+ constructor(storage) {
23
+ this.storage = storage;
24
+ }
25
+ getItem(key) {
26
+ return Promise.resolve(this.storage.getItem(key));
27
+ }
28
+ setItem(key, value) {
29
+ return Promise.resolve(this.storage.setItem(key, value));
30
+ }
31
+ removeItem(key) {
32
+ return Promise.resolve(this.storage.removeItem(key));
33
+ }
34
+ }
35
+ exports.StorageWrapper = StorageWrapper;
36
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":";;;AAMA,MAAa,aAAa;IAGxB;QACE,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IAClB,CAAC;IAED,OAAO,CAAE,GAAW;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,CAAE,GAAW,EAAE,KAAU;QAC9B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAClD,CAAC;IAED,UAAU,CAAE,GAAW;QACrB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAE9B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEvB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AAtBD,sCAsBC;AAED,MAAa,cAAc;IAGzB,YAAa,OAAY;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,OAAO,CAAE,GAAW;QAClB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,CAAE,GAAW,EAAE,KAAU;QAC9B,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,UAAU,CAAE,GAAW;QACrB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;CACF;AAlBD,wCAkBC"}
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@feathersjs/authentication-client",
3
+ "description": "The authentication plugin for feathers-client",
4
+ "version": "5.0.0-pre.10",
5
+ "homepage": "https://feathersjs.com",
6
+ "main": "lib/",
7
+ "types": "lib/",
8
+ "keywords": [
9
+ "feathers",
10
+ "feathers-plugin"
11
+ ],
12
+ "license": "MIT",
13
+ "funding": {
14
+ "type": "github",
15
+ "url": "https://github.com/sponsors/daffl"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git://github.com/feathersjs/feathers.git"
20
+ },
21
+ "author": {
22
+ "name": "Feathers contributors",
23
+ "email": "hello@feathersjs.com",
24
+ "url": "https://feathersjs.com"
25
+ },
26
+ "contributors": [],
27
+ "bugs": {
28
+ "url": "https://github.com/feathersjs/feathers/issues"
29
+ },
30
+ "engines": {
31
+ "node": ">= 12"
32
+ },
33
+ "files": [
34
+ "CHANGELOG.md",
35
+ "LICENSE",
36
+ "README.md",
37
+ "src/**",
38
+ "lib/**",
39
+ "*.d.ts",
40
+ "*.js"
41
+ ],
42
+ "scripts": {
43
+ "prepublish": "npm run compile",
44
+ "compile": "shx rm -rf lib/ && tsc",
45
+ "test": "npm run compile && npm run mocha",
46
+ "mocha": "mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
47
+ },
48
+ "directories": {
49
+ "lib": "lib"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public"
53
+ },
54
+ "dependencies": {
55
+ "@feathersjs/authentication": "^5.0.0-pre.10",
56
+ "@feathersjs/commons": "^5.0.0-pre.10",
57
+ "@feathersjs/errors": "^5.0.0-pre.10",
58
+ "@feathersjs/feathers": "^5.0.0-pre.10"
59
+ },
60
+ "devDependencies": {
61
+ "@feathersjs/authentication-local": "^5.0.0-pre.10",
62
+ "@feathersjs/express": "^5.0.0-pre.10",
63
+ "@feathersjs/memory": "^5.0.0-pre.10",
64
+ "@feathersjs/rest-client": "^5.0.0-pre.10",
65
+ "@feathersjs/socketio": "^5.0.0-pre.10",
66
+ "@feathersjs/socketio-client": "^5.0.0-pre.10",
67
+ "@types/mocha": "^9.0.0",
68
+ "@types/node": "^16.9.4",
69
+ "axios": "^0.21.4",
70
+ "mocha": "^9.1.1",
71
+ "shx": "^0.3.3",
72
+ "ts-node": "^10.2.1",
73
+ "typescript": "^4.4.3"
74
+ },
75
+ "gitHead": "a9f7865cce8db2305b7c0d2ef4a165c2724034ef"
76
+ }