@nsshunt/stsoauth2plugin 0.0.3

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 (49) hide show
  1. package/.eslintrc.json +27 -0
  2. package/.github/dependabot.yml +13 -0
  3. package/.github/workflows/npm-publish.yml +54 -0
  4. package/LICENSE +21 -0
  5. package/README.md +1 -0
  6. package/babel.config.json +6 -0
  7. package/build.sh +29 -0
  8. package/dist/Utils/CryptoUtils.js +32 -0
  9. package/dist/Utils/CryptoUtils.js.map +1 -0
  10. package/dist/Utils/QueryParams.js +49 -0
  11. package/dist/Utils/QueryParams.js.map +1 -0
  12. package/dist/index.js +3 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/index.test.js +8 -0
  15. package/dist/index.test.js.map +1 -0
  16. package/dist/stsStorage.js +152 -0
  17. package/dist/stsStorage.js.map +1 -0
  18. package/dist/stsoauth2manager.js +327 -0
  19. package/dist/stsoauth2manager.js.map +1 -0
  20. package/dist/stsoauth2types.js +29 -0
  21. package/dist/stsoauth2types.js.map +1 -0
  22. package/dist/stsoauth2worker.js +553 -0
  23. package/dist/stsoauth2worker.js.map +1 -0
  24. package/package.json +43 -0
  25. package/src/Utils/CryptoUtils.ts +32 -0
  26. package/src/Utils/QueryParams.ts +48 -0
  27. package/src/index.test.ts +10 -0
  28. package/src/index.ts +3 -0
  29. package/src/stsStorage.ts +158 -0
  30. package/src/stsoauth2manager.ts +350 -0
  31. package/src/stsoauth2types.ts +108 -0
  32. package/src/stsoauth2worker.ts +542 -0
  33. package/tsconfig.json +31 -0
  34. package/types/Utils/CryptoUtils.d.ts +7 -0
  35. package/types/Utils/CryptoUtils.d.ts.map +1 -0
  36. package/types/Utils/QueryParams.d.ts +8 -0
  37. package/types/Utils/QueryParams.d.ts.map +1 -0
  38. package/types/index.d.ts +3 -0
  39. package/types/index.d.ts.map +1 -0
  40. package/types/index.test.d.ts +1 -0
  41. package/types/index.test.d.ts.map +1 -0
  42. package/types/stsStorage.d.ts +22 -0
  43. package/types/stsStorage.d.ts.map +1 -0
  44. package/types/stsoauth2manager.d.ts +5 -0
  45. package/types/stsoauth2manager.d.ts.map +1 -0
  46. package/types/stsoauth2types.d.ts +89 -0
  47. package/types/stsoauth2types.d.ts.map +1 -0
  48. package/types/stsoauth2worker.d.ts +2 -0
  49. package/types/stsoauth2worker.d.ts.map +1 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "env": {
3
+ "browser": true,
4
+ "es2021": true,
5
+ "node": true,
6
+ "jest": true
7
+ },
8
+ "extends": [
9
+ "eslint:recommended",
10
+ "plugin:@typescript-eslint/recommended"
11
+ ],
12
+ "parser": "@typescript-eslint/parser",
13
+ "parserOptions": {
14
+ "ecmaVersion": "latest",
15
+ "sourceType": "module"
16
+ },
17
+ "plugins": [
18
+ "@typescript-eslint"
19
+ ],
20
+ "ignorePatterns": ["temp.js", "**/k6scripts/*.js", "**/public/*", "**/dist/*", "**/types/*"],
21
+ "rules": {
22
+ "indent": ["error", "tab"],
23
+ //"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
24
+ "no-mixed-spaces-and-tabs": 0, // disable rule
25
+ "@typescript-eslint/no-var-requires": "warn"
26
+ }
27
+ }
@@ -0,0 +1,13 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+ #
6
+ # https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
7
+
8
+ version: 2
9
+ updates:
10
+ - package-ecosystem: "npm" # See documentation for possible values
11
+ directory: "/" # Location of package manifests
12
+ schedule:
13
+ interval: "monthly"
@@ -0,0 +1,54 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
+
4
+ name: Node.js Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+ push:
10
+ branches: [ main ]
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: actions/setup-node@v2
18
+ with:
19
+ node-version: 18
20
+ - run: npm ci
21
+ - run: npm run lint
22
+ - run: npm test
23
+
24
+ publish-npm:
25
+ needs: build
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@v2
29
+ - uses: actions/setup-node@v2
30
+ with:
31
+ node-version: 18
32
+ registry-url: https://registry.npmjs.org/
33
+ - run: npm ci
34
+ - run: npm run build
35
+ - run: npm publish --access public
36
+ env:
37
+ NODE_AUTH_TOKEN: ${{secrets.npm_token}}
38
+
39
+ # publish-gpr:
40
+ # needs: build
41
+ # runs-on: ubuntu-latest
42
+ # permissions:
43
+ # contents: read
44
+ # packages: write
45
+ # steps:
46
+ # - uses: actions/checkout@v2
47
+ # - uses: actions/setup-node@v2
48
+ # with:
49
+ # node-version: 17
50
+ # registry-url: https://npm.pkg.github.com/
51
+ # - run: npm ci
52
+ # - run: npm publish
53
+ # env:
54
+ # NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 nsshunt
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.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # stsoauth2plugin
@@ -0,0 +1,6 @@
1
+ {
2
+ "presets": [
3
+ ["@babel/preset-env", {"targets": {"node": "current"}}],
4
+ "@babel/preset-typescript"
5
+ ]
6
+ }
package/build.sh ADDED
@@ -0,0 +1,29 @@
1
+ #!/bin/sh
2
+ rm -rf dist
3
+ rm -rf types
4
+ npm run build
5
+ RESULT=$?
6
+ if [ $RESULT -eq 0 ]; then
7
+ echo success build
8
+ npm run lint
9
+ RESULT=$?
10
+ if [ $RESULT -eq 0 ]; then
11
+ echo success lint
12
+ npm run test
13
+ RESULT=$?
14
+ if [ $RESULT -eq 0 ]; then
15
+ echo success test
16
+ git commit -a -m "changed"
17
+ npm version patch
18
+ npm i
19
+ git commit -a -m "changed"
20
+ git push
21
+ else
22
+ echo failed test
23
+ fi
24
+ else
25
+ echo failed lint
26
+ fi
27
+ else
28
+ echo failed build
29
+ fi
@@ -0,0 +1,32 @@
1
+ export class CryptoUtils {
2
+ constructor() {
3
+ this.DigestMessage = async function (message) {
4
+ const encoder = new TextEncoder();
5
+ const data = encoder.encode(message);
6
+ const hashBuffer = await crypto.subtle.digest('SHA-256', data);
7
+ const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
8
+ //let b64 = window.btoa(String.fromCharCode(...hashArray));
9
+ const b64 = btoa(String.fromCharCode(...hashArray)); // Use below if a HEX string is required
10
+ // const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
11
+ return b64;
12
+ };
13
+ this.CreateRandomString = (size = 43) => {
14
+ //const randomValues = Array.from(window.crypto.getRandomValues(new Uint8Array(size)))
15
+ const randomValues = Array.from(crypto.getRandomValues(new Uint8Array(size)));
16
+ //let b64 = window.btoa(String.fromCharCode(...randomValues));
17
+ const b64 = btoa(String.fromCharCode(...randomValues));
18
+ return b64;
19
+ //return randomValues.toString('base64');
20
+ };
21
+ this.CreateRandomStringEx = () => {
22
+ const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.';
23
+ let random = '';
24
+ //const randomValues = Array.from(window.crypto.getRandomValues(new Uint8Array(43)));
25
+ const randomValues = Array.from(crypto.getRandomValues(new Uint8Array(43)));
26
+ randomValues.forEach(v => (random += charset[v % charset.length]));
27
+ return random;
28
+ };
29
+ }
30
+ }
31
+ export default CryptoUtils;
32
+ //# sourceMappingURL=CryptoUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CryptoUtils.js","sourceRoot":"","sources":["../../src/Utils/CryptoUtils.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAW;IAAxB;QACC,kBAAa,GAAG,KAAK,WAAW,OAAO;YACtC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;YAClC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACrC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,+BAA+B;YACzF,2DAA2D;YAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA,wCAAwC;YAC5F,+GAA+G;YAC/G,OAAO,GAAG,CAAC;QACZ,CAAC,CAAA;QAED,uBAAkB,GAAG,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE;YAClC,sFAAsF;YACtF,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YAC7E,8DAA8D;YAC9D,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC;YACvD,OAAO,GAAG,CAAC;YACX,yCAAyC;QAC1C,CAAC,CAAA;QAED,yBAAoB,GAAG,GAAG,EAAE;YAC3B,MAAM,OAAO,GAAG,oEAAoE,CAAC;YACrF,IAAI,MAAM,GAAG,EAAE,CAAC;YAChB,qFAAqF;YACrF,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC5E,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACnE,OAAO,MAAM,CAAC;QACf,CAAC,CAAA;IACF,CAAC;CAAA;AAED,eAAe,WAAW,CAAA"}
@@ -0,0 +1,49 @@
1
+ // https://github.com/auth0/auth0-spa-js/blob/1de6427f81a8c5b005e9b6d10b9efb1e73542528/static/index.html
2
+ // https://stackoverflow.com/questions/12446317/change-url-without-redirecting-using-javascript
3
+ class QueryParams {
4
+ constructor() {
5
+ this.DecodeQueryParams = (params) => {
6
+ const retObj = {};
7
+ const arr = Object.keys(params)
8
+ .filter(k => typeof params[k] !== 'undefined')
9
+ .map(k => {
10
+ retObj[decodeURIComponent(k)] = decodeURIComponent(params[k]);
11
+ });
12
+ return retObj;
13
+ };
14
+ this.CreateQueryParams = (params) => {
15
+ return Object.keys(params)
16
+ .filter(k => typeof params[k] !== 'undefined')
17
+ .map(k => {
18
+ if (Array.isArray(params[k])) {
19
+ return encodeURIComponent(k) + '=' + encodeURIComponent(params[k].join(' '));
20
+ }
21
+ else {
22
+ return encodeURIComponent(k) + '=' + encodeURIComponent(params[k]);
23
+ }
24
+ })
25
+ .join('&');
26
+ };
27
+ this._GetQueryParams = (param) => {
28
+ let retVal = {};
29
+ const uri = param.split("?");
30
+ if (uri.length == 2) {
31
+ const vars = uri[1].split("&");
32
+ const getVars = {};
33
+ let tmp = "";
34
+ vars.forEach(function (v) {
35
+ tmp = v.split("=");
36
+ if (tmp.length == 2)
37
+ getVars[tmp[0]] = tmp[1];
38
+ });
39
+ retVal = this.DecodeQueryParams(getVars);
40
+ }
41
+ return retVal;
42
+ };
43
+ this.GetQueryParams = () => {
44
+ return this._GetQueryParams(window.location.href);
45
+ };
46
+ }
47
+ }
48
+ export default QueryParams;
49
+ //# sourceMappingURL=QueryParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryParams.js","sourceRoot":"","sources":["../../src/Utils/QueryParams.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,+FAA+F;AAC/F,MAAM,WAAW;IAAjB;QACC,sBAAiB,GAAG,CAAC,MAAM,EAAE,EAAE;YAC9B,MAAM,MAAM,GAAG,EAAG,CAAC;YACnB,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;iBAC7B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC;iBAC7C,GAAG,CAAC,CAAC,CAAC,EAAE;gBACR,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/D,CAAC,CAAC,CAAC;YACJ,OAAO,MAAM,CAAC;QACf,CAAC,CAAA;QAED,sBAAiB,GAAG,CAAC,MAAM,EAAE,EAAE;YAC9B,OAAO,M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AC,OAAO,CAAC,CAAC;aACzC;YACD,OAAO,MAAM,CAAC;QACf,CAAC,CAAA;QAED,mBAAc,GAAG,GAAG,EAAE;YACrB,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnD,CAAC,CAAA;IACF,CAAC;CAAA;AAED,eAAe,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './stsoauth2types';
2
+ export * from './stsoauth2manager';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,oBAAoB,CAAA"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ describe("Test Latency Controller", () => {
3
+ test('Testing Module', async () => {
4
+ expect.assertions(1);
5
+ expect(1).toEqual(1);
6
+ });
7
+ });
8
+ //# sourceMappingURL=index.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../src/index.test.ts"],"names":[],"mappings":";AACA,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IAExC,IAAI,CAAC,gBAAgB,EAAE,KAAK,IAAI,EAAE;QAEjC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACrB,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC"}
@@ -0,0 +1,152 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _MemoryStorage_store, _ClientStorageFactory_storage;
13
+ import Debug from "debug";
14
+ const debug = Debug(`proc:${process.pid}:storage.ts`);
15
+ import * as Cookies from 'es-cookie';
16
+ export var ClientStorageType;
17
+ (function (ClientStorageType) {
18
+ ClientStorageType["LOCAL_STORAGE"] = "LocalStorage";
19
+ ClientStorageType["SESSION_STORAGE"] = "SessionStorage";
20
+ ClientStorageType["COOKIE_STORAGE"] = "CookieStorage";
21
+ ClientStorageType["MEMORY_STORAGE"] = "MemoryStorage"; //@@ todo
22
+ })(ClientStorageType || (ClientStorageType = {}));
23
+ class CookieStorage {
24
+ constructor() {
25
+ this.get = (key) => {
26
+ const raw = Cookies.get(key);
27
+ if (raw) {
28
+ return JSON.parse(raw);
29
+ }
30
+ else {
31
+ return null;
32
+ }
33
+ };
34
+ this.set = (key, value, options = {}) => {
35
+ let cookieAttributes = {};
36
+ if ('https:' === window.location.protocol) {
37
+ cookieAttributes = {
38
+ secure: true,
39
+ sameSite: 'none'
40
+ };
41
+ }
42
+ if (options && options.daysUntilExpire) {
43
+ cookieAttributes.expires = options.daysUntilExpire;
44
+ }
45
+ else {
46
+ cookieAttributes.expires = 1;
47
+ }
48
+ debug(`CookieStorage.set: key: ${key}, value: [${value}]`);
49
+ Cookies.set(key, JSON.stringify(value), cookieAttributes);
50
+ };
51
+ this.remove = (key) => {
52
+ Cookies.remove(key);
53
+ };
54
+ }
55
+ }
56
+ class SessionStorage {
57
+ constructor() {
58
+ this.get = (key) => {
59
+ const value = sessionStorage.getItem(key);
60
+ if (typeof value === 'undefined') {
61
+ return null;
62
+ }
63
+ if (value === null) {
64
+ return null;
65
+ }
66
+ return JSON.parse(value);
67
+ };
68
+ this.set = (key, value) => {
69
+ debug(`SessionStorage.set: key: ${key}, value: [${value}]`);
70
+ sessionStorage.setItem(key, JSON.stringify(value));
71
+ };
72
+ this.remove = (key) => {
73
+ sessionStorage.removeItem(key);
74
+ };
75
+ }
76
+ }
77
+ class LocalStorage {
78
+ constructor() {
79
+ this.get = (key) => {
80
+ const value = localStorage.getItem(key);
81
+ if (typeof value === 'undefined') {
82
+ return null;
83
+ }
84
+ if (value === null) {
85
+ return null;
86
+ }
87
+ return JSON.parse(value);
88
+ };
89
+ this.set = (key, value) => {
90
+ debug(`LocalStorage.set: key: ${key}, value: [${value}]`);
91
+ localStorage.setItem(key, JSON.stringify(value));
92
+ };
93
+ this.remove = (key) => {
94
+ localStorage.removeItem(key);
95
+ };
96
+ }
97
+ }
98
+ class MemoryStorage {
99
+ constructor() {
100
+ _MemoryStorage_store.set(this, {});
101
+ this.get = (key) => {
102
+ const value = __classPrivateFieldGet(this, _MemoryStorage_store, "f")[key];
103
+ if (typeof value === 'undefined') {
104
+ return null;
105
+ }
106
+ if (value === null) {
107
+ return null;
108
+ }
109
+ return value;
110
+ };
111
+ this.set = (key, value) => {
112
+ debug(`MemoryStorage.set: key: ${key}, value: [${value}]`);
113
+ __classPrivateFieldGet(this, _MemoryStorage_store, "f")[key] = value;
114
+ };
115
+ this.remove = (key) => {
116
+ delete __classPrivateFieldGet(this, _MemoryStorage_store, "f")[key];
117
+ };
118
+ }
119
+ }
120
+ _MemoryStorage_store = new WeakMap();
121
+ export class ClientStorageOptions {
122
+ constructor() {
123
+ this.clientStorageType = ClientStorageType.MEMORY_STORAGE;
124
+ }
125
+ }
126
+ export class ClientStorageFactory {
127
+ constructor(options) {
128
+ _ClientStorageFactory_storage.set(this, null);
129
+ switch (options.clientStorageType) {
130
+ case ClientStorageType.SESSION_STORAGE:
131
+ __classPrivateFieldSet(this, _ClientStorageFactory_storage, new SessionStorage(), "f");
132
+ break;
133
+ case ClientStorageType.LOCAL_STORAGE:
134
+ __classPrivateFieldSet(this, _ClientStorageFactory_storage, new LocalStorage(), "f");
135
+ break;
136
+ case ClientStorageType.COOKIE_STORAGE:
137
+ __classPrivateFieldSet(this, _ClientStorageFactory_storage, new CookieStorage(), "f");
138
+ break;
139
+ case ClientStorageType.MEMORY_STORAGE:
140
+ __classPrivateFieldSet(this, _ClientStorageFactory_storage, new MemoryStorage(), "f");
141
+ break;
142
+ default:
143
+ throw new Error(`Unknown [${options.clientStorageType}] storage type.`);
144
+ }
145
+ return;
146
+ }
147
+ GetStorage() {
148
+ return __classPrivateFieldGet(this, _ClientStorageFactory_storage, "f");
149
+ }
150
+ }
151
+ _ClientStorageFactory_storage = new WeakMap();
152
+ //# sourceMappingURL=stsStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stsStorage.js","sourceRoot":"","sources":["../src/stsStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,OAAO,CAAC,GAAG,aAAa,CAAC,CAAC;AAEtD,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AASrC,MAAM,CAAN,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC5B,mDAA8B,CAAA;IAC9B,uDAAkC,CAAA;IAClC,qDAAgC,CAAA;IAChC,qDAAgC,CAAA,CAAC,SAAS;AAC3C,CAAC,EALW,iBAAiB,KAAjB,iBAAiB,QAK5B;AAED,MAAM,aAAa;IAAnB;QAEC,QAAG,GAAG,CAAC,GAAW,EAAK,EAAE;YACxB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,GAAG,EAAE;gBACR,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;aACvB;iBA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