@vardario/cognito-client 0.1.3 → 0.1.4

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.
@@ -1,210 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- require("isomorphic-fetch");
51
- var testcontainers_1 = require("testcontainers");
52
- var cognito_client_1 = require("./cognito-client");
53
- var session_storage_1 = require("./session-storage");
54
- var test_utils_1 = require("./test-utils");
55
- describe('Cognito Client', function () {
56
- var cognitoClient;
57
- var container;
58
- var sessionStorage = new session_storage_1.MemorySessionStorage();
59
- var oAuth2 = {
60
- cognitoDomain: 'http://localhost',
61
- redirectUrl: 'http://localhost',
62
- responseType: 'code',
63
- scopes: ['email openid'],
64
- };
65
- var userPoolConfig = {
66
- userPoolClientId: '',
67
- userPoolId: '',
68
- };
69
- beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
70
- var cognitoPort, cognitoEndpoint;
71
- return __generator(this, function (_a) {
72
- switch (_a.label) {
73
- case 0:
74
- cognitoPort = 9229;
75
- return [4 /*yield*/, new testcontainers_1.GenericContainer('jagregory/cognito-local').withExposedPorts(cognitoPort).start()];
76
- case 1:
77
- container = _a.sent();
78
- cognitoEndpoint = "http://localhost:".concat(container.getMappedPort(cognitoPort));
79
- return [4 /*yield*/, (0, test_utils_1.setupCognito)(cognitoEndpoint)];
80
- case 2:
81
- userPoolConfig = _a.sent();
82
- cognitoClient = new cognito_client_1.CognitoClient({
83
- userPoolId: userPoolConfig.userPoolId,
84
- userPoolClientId: userPoolConfig.userPoolClientId,
85
- sessionStorage: sessionStorage,
86
- endpoint: cognitoEndpoint,
87
- oAuth2: oAuth2,
88
- });
89
- return [2 /*return*/];
90
- }
91
- });
92
- }); });
93
- beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
94
- var error_1;
95
- return __generator(this, function (_a) {
96
- switch (_a.label) {
97
- case 0:
98
- _a.trys.push([0, 2, , 3]);
99
- return [4 /*yield*/, cognitoClient.signOut()];
100
- case 1:
101
- _a.sent();
102
- return [3 /*break*/, 3];
103
- case 2:
104
- error_1 = _a.sent();
105
- return [3 /*break*/, 3];
106
- case 3: return [2 /*return*/];
107
- }
108
- });
109
- }); });
110
- afterAll(function () { return __awaiter(void 0, void 0, void 0, function () {
111
- return __generator(this, function (_a) {
112
- switch (_a.label) {
113
- case 0: return [4 /*yield*/, container.stop()];
114
- case 1:
115
- _a.sent();
116
- return [2 /*return*/];
117
- }
118
- });
119
- }); });
120
- test('authenticateUser', function () { return __awaiter(void 0, void 0, void 0, function () {
121
- var session, _a, _b, newSession;
122
- return __generator(this, function (_c) {
123
- switch (_c.label) {
124
- case 0: return [4 /*yield*/, cognitoClient.authenticateUser(test_utils_1.user.email, test_utils_1.user.password)];
125
- case 1:
126
- session = _c.sent();
127
- _b = (_a = expect(session)).toEqual;
128
- return [4 /*yield*/, cognitoClient.getSession()];
129
- case 2:
130
- _b.apply(_a, [_c.sent()]);
131
- //Simulate session expiring
132
- sessionStorage.setSession(__assign(__assign({}, session), { expiresIn: 0 }));
133
- return [4 /*yield*/, cognitoClient.getSession()];
134
- case 3:
135
- newSession = _c.sent();
136
- expect(newSession).not.toEqual(session);
137
- return [2 /*return*/];
138
- }
139
- });
140
- }); });
141
- test('authenticateUserSrp: TODO', function () { return __awaiter(void 0, void 0, void 0, function () {
142
- return __generator(this, function (_a) {
143
- // TODO: Currently SRP auth is not supported through cognito-local
144
- // const session = await cognitoClient.authenticateUserSrp(user.name, user.password);
145
- // expect(session).toEqual(await cognitoClient.getSession());
146
- expect(true).toBe(true);
147
- return [2 /*return*/];
148
- });
149
- }); });
150
- test('signUp', function () { return __awaiter(void 0, void 0, void 0, function () {
151
- var _a, id, confirmed;
152
- return __generator(this, function (_b) {
153
- switch (_b.label) {
154
- case 0: return [4 /*yield*/, cognitoClient.signUp(test_utils_1.newUser.email, test_utils_1.newUser.password, [
155
- { Name: 'givenName', Value: test_utils_1.newUser.givenName },
156
- { Name: 'familyName', Value: test_utils_1.newUser.familyName },
157
- ])];
158
- case 1:
159
- _a = _b.sent(), id = _a.id, confirmed = _a.confirmed;
160
- expect(id).toBeDefined();
161
- expect(confirmed).toBe(false);
162
- return [2 /*return*/];
163
- }
164
- });
165
- }); });
166
- test('changePassword', function () { return __awaiter(void 0, void 0, void 0, function () {
167
- var newPassword;
168
- return __generator(this, function (_a) {
169
- switch (_a.label) {
170
- case 0:
171
- newPassword = 'newPassword';
172
- expect(cognitoClient.changePassword(test_utils_1.user.password, newPassword)).rejects.toThrow();
173
- return [4 /*yield*/, cognitoClient.authenticateUser(test_utils_1.user.email, test_utils_1.user.password)];
174
- case 1:
175
- _a.sent();
176
- return [4 /*yield*/, cognitoClient.changePassword(test_utils_1.user.password, newPassword)];
177
- case 2:
178
- _a.sent();
179
- return [4 /*yield*/, cognitoClient.signOut()];
180
- case 3:
181
- _a.sent();
182
- expect(cognitoClient.authenticateUser(test_utils_1.user.email, test_utils_1.user.password)).rejects.toThrow();
183
- return [4 /*yield*/, cognitoClient.authenticateUser(test_utils_1.user.email, 'newPassword')];
184
- case 4:
185
- _a.sent();
186
- return [2 /*return*/];
187
- }
188
- });
189
- }); });
190
- test('generateOAuthSignInUrl', function () {
191
- var _test = function (cb, identityProvider) {
192
- var hostedUIUrl = cognitoClient.generateOAuthSignInUrl(identityProvider);
193
- var searchParams = new URL(hostedUIUrl).searchParams;
194
- expect(searchParams.get('redirect_uri')).toBe(oAuth2.redirectUrl);
195
- expect(searchParams.get('response_type')).toBe(oAuth2.responseType);
196
- expect(searchParams.get('client_id')).toBe(userPoolConfig.userPoolClientId);
197
- expect(searchParams.get('scope')).toBe(oAuth2.scopes.join(' '));
198
- expect(searchParams.get('state')).toBeDefined();
199
- expect(searchParams.get('code_challenge')).toBeDefined();
200
- expect(searchParams.get('code_challenge_method')).toBe('S256');
201
- cb(searchParams);
202
- };
203
- _test(function (searchParams) {
204
- expect(searchParams.get('identity_provider')).toBeNull();
205
- });
206
- _test(function (searchParams) {
207
- expect(searchParams.get('identity_provider')).toBe(cognito_client_1.CognitoIdentityProvider.Apple);
208
- }, cognito_client_1.CognitoIdentityProvider.Apple);
209
- });
210
- });
package/lib/error.d.ts DELETED
@@ -1,55 +0,0 @@
1
- /**
2
- * Possible Authentications errors
3
- */
4
- export declare enum AuthError {
5
- /**
6
- * User already confirmed
7
- */
8
- UserConfirmedAlready = "user_confirmed_already",
9
- /**
10
- * User Profile does not exists.
11
- */
12
- UserDoesNotExist = "user_does_not_exist",
13
- /**
14
- * User Profile does not exists.
15
- */
16
- UserAlreadyExists = "user_already_exists",
17
- /**
18
- * Password was wrong.
19
- */
20
- EmailOrPasswordWrong = "email_or_password_wrong",
21
- /**
22
- * Rate limit exceeded.
23
- */
24
- LimitExceededException = "limit_exceeded_exception",
25
- /**
26
- * User needs to be authenticated.
27
- */
28
- UserNotAuthenticated = "user_not_authenticated",
29
- /**
30
- * The user tried to many times wiht the wrong password
31
- */
32
- PasswordAttempsExceeded = "password_attemps_exceeded",
33
- /**
34
- * User E-Mail needs to be verified.
35
- */
36
- UserEmailNotVerified = "user_email_not_verified",
37
- /**
38
- * Unknown auth error happened.
39
- */
40
- Unknown = "unknown"
41
- }
42
- export declare class AuthException extends Error {
43
- readonly authError: AuthError;
44
- constructor(message: string, authError: AuthError);
45
- }
46
- export declare enum ErrorCode {
47
- UserNotFoundException = "UserNotFoundException",
48
- NotAuthorizedException = "NotAuthorizedException",
49
- LimitExceededException = "LimitExceededException"
50
- }
51
- export interface CognitoAuthErrorResponse {
52
- __type: ErrorCode;
53
- message: string;
54
- }
55
- export declare function getAuthError(errorResponse: CognitoAuthErrorResponse): AuthException;
package/lib/error.js DELETED
@@ -1,93 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.getAuthError = exports.ErrorCode = exports.AuthException = exports.AuthError = void 0;
19
- /**
20
- * Possible Authentications errors
21
- */
22
- var AuthError;
23
- (function (AuthError) {
24
- /**
25
- * User already confirmed
26
- */
27
- AuthError["UserConfirmedAlready"] = "user_confirmed_already";
28
- /**
29
- * User Profile does not exists.
30
- */
31
- AuthError["UserDoesNotExist"] = "user_does_not_exist";
32
- /**
33
- * User Profile does not exists.
34
- */
35
- AuthError["UserAlreadyExists"] = "user_already_exists";
36
- /**
37
- * Password was wrong.
38
- */
39
- AuthError["EmailOrPasswordWrong"] = "email_or_password_wrong";
40
- /**
41
- * Rate limit exceeded.
42
- */
43
- AuthError["LimitExceededException"] = "limit_exceeded_exception";
44
- /**
45
- * User needs to be authenticated.
46
- */
47
- AuthError["UserNotAuthenticated"] = "user_not_authenticated";
48
- /**
49
- * The user tried to many times wiht the wrong password
50
- */
51
- AuthError["PasswordAttempsExceeded"] = "password_attemps_exceeded";
52
- /**
53
- * User E-Mail needs to be verified.
54
- */
55
- AuthError["UserEmailNotVerified"] = "user_email_not_verified";
56
- /**
57
- * Unknown auth error happened.
58
- */
59
- AuthError["Unknown"] = "unknown";
60
- })(AuthError = exports.AuthError || (exports.AuthError = {}));
61
- var AuthException = /** @class */ (function (_super) {
62
- __extends(AuthException, _super);
63
- function AuthException(message, authError) {
64
- var _this = _super.call(this, message) || this;
65
- _this.authError = authError;
66
- return _this;
67
- }
68
- return AuthException;
69
- }(Error));
70
- exports.AuthException = AuthException;
71
- var ErrorCode;
72
- (function (ErrorCode) {
73
- ErrorCode["UserNotFoundException"] = "UserNotFoundException";
74
- ErrorCode["NotAuthorizedException"] = "NotAuthorizedException";
75
- ErrorCode["LimitExceededException"] = "LimitExceededException";
76
- })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
77
- function getAuthError(errorResponse) {
78
- var mapping = {
79
- 'UserNotFoundException:User cannot be confirmed. Current status is CONFIRMED': AuthError.UserConfirmedAlready,
80
- 'NotAuthorizedException:Incorrect username or password.': AuthError.EmailOrPasswordWrong,
81
- 'LimitExceededException:Attempt limit exceeded, please try after some time.': AuthError.LimitExceededException,
82
- 'UserNotFoundException:Username/client id combination not found.': AuthError.UserDoesNotExist,
83
- 'UserNotFoundException:User does not exist.': AuthError.UserDoesNotExist,
84
- 'NotAuthorizedException:Password attempts exceeded': AuthError.PasswordAttempsExceeded,
85
- 'UsernameExistsException:An account with the given email already exists.': AuthError.UserAlreadyExists,
86
- 'InvalidParameterException:Cannot reset password for the user as there is no registered/verified email or phone_number': AuthError.UserEmailNotVerified,
87
- 'UserNotConfirmedException:User is not confirmed.': AuthError.UserEmailNotVerified,
88
- };
89
- var message = "".concat(errorResponse.__type, ":").concat(errorResponse.message);
90
- var authError = mapping[message] || AuthError.Unknown;
91
- return new AuthException(message, authError);
92
- }
93
- exports.getAuthError = getAuthError;
package/lib/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './cognito-client';
2
- export * from './error';
3
- export * from './session-storage';
package/lib/index.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./cognito-client"), exports);
18
- __exportStar(require("./error"), exports);
19
- __exportStar(require("./session-storage"), exports);
@@ -1,21 +0,0 @@
1
- import { CookieProps } from '@vardario/cookies';
2
- import { Session } from '../../cognito-client';
3
- import { OAuthVerificationParams, SessionStorage } from '../session-storage';
4
- export interface CookieSessionStorageProps extends CookieProps {
5
- cookieName: string;
6
- }
7
- /**
8
- * Cookies based session storage.
9
- * This session storage works also across sub domains.
10
- */
11
- export declare class CookieSessionStorage extends SessionStorage {
12
- private readonly props;
13
- private readonly oAuthParamCookieName;
14
- private readonly sessionCookieName;
15
- private readonly cookies;
16
- constructor(props: CookieSessionStorageProps);
17
- getSession(): Session | undefined;
18
- setSession(session: Session | undefined): void;
19
- getOauthVerificationParams(): OAuthVerificationParams | undefined;
20
- setOauthVerificationParams(oAuthParams: OAuthVerificationParams): void;
21
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.CookieSessionStorage = void 0;
19
- var cookies_1 = require("@vardario/cookies");
20
- var session_storage_1 = require("../session-storage");
21
- /**
22
- * Cookies based session storage.
23
- * This session storage works also across sub domains.
24
- */
25
- var CookieSessionStorage = /** @class */ (function (_super) {
26
- __extends(CookieSessionStorage, _super);
27
- function CookieSessionStorage(props) {
28
- var _this = this;
29
- var _a, _b, _c, _d;
30
- _this = _super.call(this) || this;
31
- _this.props = {
32
- domain: props.domain,
33
- path: (_a = props.path) !== null && _a !== void 0 ? _a : '/',
34
- expires: (_b = props.expires) !== null && _b !== void 0 ? _b : 365,
35
- secure: (_c = props.secure) !== null && _c !== void 0 ? _c : true,
36
- sameSite: (_d = props.sameSite) !== null && _d !== void 0 ? _d : 'None',
37
- cookieName: props.cookieName,
38
- };
39
- _this.cookies = new cookies_1.Cookies(_this.props);
40
- _this.sessionCookieName = "".concat(props.cookieName);
41
- _this.oAuthParamCookieName = "".concat(props.cookieName, "_oauth");
42
- return _this;
43
- }
44
- CookieSessionStorage.prototype.getSession = function () {
45
- var session = this.cookies.getCookie(this.sessionCookieName);
46
- if (session === undefined) {
47
- return undefined;
48
- }
49
- return JSON.parse(session);
50
- };
51
- CookieSessionStorage.prototype.setSession = function (session) {
52
- this.cookies.setCookie(this.sessionCookieName, JSON.stringify(session));
53
- };
54
- CookieSessionStorage.prototype.getOauthVerificationParams = function () {
55
- var oAuthParams = this.cookies.getCookie(this.oAuthParamCookieName);
56
- if (oAuthParams === undefined) {
57
- return undefined;
58
- }
59
- return JSON.parse(oAuthParams);
60
- };
61
- CookieSessionStorage.prototype.setOauthVerificationParams = function (oAuthParams) {
62
- this.cookies.setCookie(this.oAuthParamCookieName, JSON.stringify(oAuthParams));
63
- };
64
- return CookieSessionStorage;
65
- }(session_storage_1.SessionStorage));
66
- exports.CookieSessionStorage = CookieSessionStorage;
@@ -1 +0,0 @@
1
- export * from './cookie-session-storage';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./cookie-session-storage"), exports);
@@ -1,4 +0,0 @@
1
- export * from './cookie-session-storage';
2
- export * from './local-storage-session-storage';
3
- export * from './memory-session-storage';
4
- export * from './session-storage';
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
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);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./cookie-session-storage"), exports);
18
- __exportStar(require("./local-storage-session-storage"), exports);
19
- __exportStar(require("./memory-session-storage"), exports);
20
- __exportStar(require("./session-storage"), exports);
@@ -1,20 +0,0 @@
1
- import { Session } from '../cognito-client';
2
- import { OAuthVerificationParams, SessionStorage } from './session-storage';
3
- export interface LocalStorageSessionStorageProps {
4
- storageName: string;
5
- }
6
- /**
7
- * LocalStorage based session storage.
8
- * This session storage works only one domain at a time.
9
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
10
- * Use @see CookieSessionStorage for a session storage, which
11
- * can span across sub domains as well.
12
- */
13
- export declare class LocalStorageSessionStorage extends SessionStorage {
14
- private readonly props;
15
- constructor(props: LocalStorageSessionStorageProps);
16
- getSession(): Session | undefined;
17
- setSession(session: Session | undefined): void;
18
- setOauthVerificationParams(oAuthParams: OAuthVerificationParams): void;
19
- getOauthVerificationParams(): OAuthVerificationParams | undefined;
20
- }
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.LocalStorageSessionStorage = void 0;
19
- var session_storage_1 = require("./session-storage");
20
- /**
21
- * LocalStorage based session storage.
22
- * This session storage works only one domain at a time.
23
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
24
- * Use @see CookieSessionStorage for a session storage, which
25
- * can span across sub domains as well.
26
- */
27
- var LocalStorageSessionStorage = /** @class */ (function (_super) {
28
- __extends(LocalStorageSessionStorage, _super);
29
- function LocalStorageSessionStorage(props) {
30
- var _this = _super.call(this) || this;
31
- _this.props = props;
32
- return _this;
33
- }
34
- LocalStorageSessionStorage.prototype.getSession = function () {
35
- var payload = window.localStorage.getItem(this.props.storageName);
36
- if (payload === null) {
37
- return undefined;
38
- }
39
- return JSON.parse(payload);
40
- };
41
- LocalStorageSessionStorage.prototype.setSession = function (session) {
42
- if (session === undefined) {
43
- window.localStorage.removeItem(this.props.storageName);
44
- return;
45
- }
46
- window.localStorage.setItem(this.props.storageName, JSON.stringify(session));
47
- };
48
- LocalStorageSessionStorage.prototype.setOauthVerificationParams = function (oAuthParams) {
49
- window.localStorage.setItem("".concat(this.props.storageName, "_oauth"), JSON.stringify(oAuthParams));
50
- };
51
- LocalStorageSessionStorage.prototype.getOauthVerificationParams = function () {
52
- var payload = window.localStorage.getItem("".concat(this.props.storageName, "_oauth"));
53
- if (payload === null) {
54
- return undefined;
55
- }
56
- return JSON.parse(payload);
57
- };
58
- return LocalStorageSessionStorage;
59
- }(session_storage_1.SessionStorage));
60
- exports.LocalStorageSessionStorage = LocalStorageSessionStorage;
@@ -1,13 +0,0 @@
1
- import { Session } from '../cognito-client';
2
- import { OAuthVerificationParams, SessionStorage } from './session-storage';
3
- /**
4
- * In-memory based session storage. Useful for testing.
5
- */
6
- export declare class MemorySessionStorage extends SessionStorage {
7
- private session?;
8
- private oAuthVerificationParams?;
9
- getSession(): Session | undefined;
10
- setSession(session: Session | undefined): void;
11
- getOauthVerificationParams(): OAuthVerificationParams | undefined;
12
- setOauthVerificationParams(oAuthParams: OAuthVerificationParams): void;
13
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.MemorySessionStorage = void 0;
19
- var session_storage_1 = require("./session-storage");
20
- /**
21
- * In-memory based session storage. Useful for testing.
22
- */
23
- var MemorySessionStorage = /** @class */ (function (_super) {
24
- __extends(MemorySessionStorage, _super);
25
- function MemorySessionStorage() {
26
- return _super !== null && _super.apply(this, arguments) || this;
27
- }
28
- MemorySessionStorage.prototype.getSession = function () {
29
- return this.session;
30
- };
31
- MemorySessionStorage.prototype.setSession = function (session) {
32
- this.session = session;
33
- };
34
- MemorySessionStorage.prototype.getOauthVerificationParams = function () {
35
- return this.oAuthVerificationParams;
36
- };
37
- MemorySessionStorage.prototype.setOauthVerificationParams = function (oAuthParams) {
38
- this.oAuthVerificationParams = oAuthParams;
39
- };
40
- return MemorySessionStorage;
41
- }(session_storage_1.SessionStorage));
42
- exports.MemorySessionStorage = MemorySessionStorage;