@sudoplatform/sudo-user 11.1.0 → 12.0.2

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 (112) hide show
  1. package/cjs/client/apiClient.js +149 -0
  2. package/cjs/client/apiClient.js.map +1 -0
  3. package/cjs/core/api-key-names.js +12 -0
  4. package/cjs/core/api-key-names.js.map +1 -0
  5. package/cjs/core/auth-store.js +92 -0
  6. package/cjs/core/auth-store.js.map +1 -0
  7. package/cjs/core/crypto.js +3 -0
  8. package/cjs/core/crypto.js.map +1 -0
  9. package/cjs/core/key-manager.js +113 -0
  10. package/cjs/core/key-manager.js.map +1 -0
  11. package/cjs/core/protected-store.js +3 -0
  12. package/cjs/core/protected-store.js.map +1 -0
  13. package/cjs/core/publisher.js +3 -0
  14. package/cjs/core/publisher.js.map +1 -0
  15. package/cjs/core/sdk-config.js +61 -0
  16. package/cjs/core/sdk-config.js.map +1 -0
  17. package/cjs/core/subscriber.js +3 -0
  18. package/cjs/core/subscriber.js.map +1 -0
  19. package/cjs/gen/graphql-types.js +105 -0
  20. package/cjs/gen/graphql-types.js.map +1 -0
  21. package/cjs/index.js +13 -0
  22. package/cjs/index.js.map +1 -0
  23. package/cjs/runtimes/browser/browser-crypto.js +10 -0
  24. package/cjs/runtimes/browser/browser-crypto.js.map +1 -0
  25. package/cjs/runtimes/node/node-crypto.js +9 -0
  26. package/cjs/runtimes/node/node-crypto.js.map +1 -0
  27. package/cjs/sdk.js +9 -0
  28. package/cjs/sdk.js.map +1 -0
  29. package/cjs/user/auth-provider.js +116 -0
  30. package/cjs/user/auth-provider.js.map +1 -0
  31. package/cjs/user/auth.js +136 -0
  32. package/cjs/user/auth.js.map +1 -0
  33. package/cjs/user/error.js +33 -0
  34. package/cjs/user/error.js.map +1 -0
  35. package/cjs/user/identity-provider.js +245 -0
  36. package/cjs/user/identity-provider.js.map +1 -0
  37. package/cjs/user/user-client-interface.js +3 -0
  38. package/cjs/user/user-client-interface.js.map +1 -0
  39. package/cjs/user/user-client.js +440 -0
  40. package/cjs/user/user-client.js.map +1 -0
  41. package/cjs/user/user-key-names.js +10 -0
  42. package/cjs/user/user-key-names.js.map +1 -0
  43. package/cjs/utils/resolvable-promise.js +20 -0
  44. package/cjs/utils/resolvable-promise.js.map +1 -0
  45. package/lib/client/apiClient.js +135 -180
  46. package/lib/client/apiClient.js.map +1 -0
  47. package/lib/core/api-key-names.js +8 -14
  48. package/lib/core/api-key-names.js.map +1 -0
  49. package/lib/core/auth-store.js +82 -138
  50. package/lib/core/auth-store.js.map +1 -0
  51. package/lib/core/crypto.js +2 -5
  52. package/lib/core/crypto.js.map +1 -0
  53. package/lib/core/key-manager.js +98 -148
  54. package/lib/core/key-manager.js.map +1 -0
  55. package/lib/core/protected-store.js +2 -5
  56. package/lib/core/protected-store.js.map +1 -0
  57. package/lib/core/publisher.js +2 -5
  58. package/lib/core/publisher.js.map +1 -0
  59. package/lib/core/sdk-config.js +56 -56
  60. package/lib/core/sdk-config.js.map +1 -0
  61. package/lib/core/subscriber.js +2 -5
  62. package/lib/core/subscriber.js.map +1 -0
  63. package/lib/gen/graphql-types.js +96 -135
  64. package/lib/gen/graphql-types.js.map +1 -0
  65. package/lib/index.js +6 -67
  66. package/lib/index.js.map +1 -0
  67. package/lib/runtimes/browser/browser-crypto.js +6 -14
  68. package/lib/runtimes/browser/browser-crypto.js.map +1 -0
  69. package/lib/runtimes/node/node-crypto.js +5 -11
  70. package/lib/runtimes/node/node-crypto.js.map +1 -0
  71. package/lib/sdk.js +6 -18
  72. package/lib/sdk.js.map +1 -0
  73. package/lib/user/auth-provider.js +81 -131
  74. package/lib/user/auth-provider.js.map +1 -0
  75. package/lib/user/auth.js +127 -179
  76. package/lib/user/auth.js.map +1 -0
  77. package/lib/user/error.js +15 -33
  78. package/lib/user/error.js.map +1 -0
  79. package/lib/user/identity-provider.js +228 -254
  80. package/lib/user/identity-provider.js.map +1 -0
  81. package/lib/user/user-client-interface.js +2 -5
  82. package/lib/user/user-client-interface.js.map +1 -0
  83. package/lib/user/user-client.js +423 -510
  84. package/lib/user/user-client.js.map +1 -0
  85. package/lib/user/user-key-names.js +6 -12
  86. package/lib/user/user-key-names.js.map +1 -0
  87. package/lib/utils/resolvable-promise.js +13 -19
  88. package/lib/utils/resolvable-promise.js.map +1 -0
  89. package/package.json +36 -28
  90. package/{lib → types}/client/apiClient.d.ts +0 -0
  91. package/{lib → types}/core/api-key-names.d.ts +0 -0
  92. package/{lib → types}/core/auth-store.d.ts +0 -0
  93. package/{lib → types}/core/crypto.d.ts +0 -0
  94. package/{lib → types}/core/key-manager.d.ts +0 -0
  95. package/types/core/protected-store.d.ts +5 -0
  96. package/{lib → types}/core/publisher.d.ts +0 -0
  97. package/{lib → types}/core/sdk-config.d.ts +0 -0
  98. package/{lib → types}/core/subscriber.d.ts +0 -0
  99. package/{lib → types}/gen/graphql-types.d.ts +0 -0
  100. package/{lib → types}/index.d.ts +0 -0
  101. package/{lib/runtimes/node/node-crypto.d.ts → types/runtimes/browser/browser-crypto.d.ts} +0 -0
  102. package/types/runtimes/node/node-crypto.d.ts +2 -0
  103. package/{lib → types}/sdk.d.ts +0 -0
  104. package/{lib → types}/user/auth-provider.d.ts +0 -0
  105. package/{lib → types}/user/auth.d.ts +0 -0
  106. package/{lib → types}/user/error.d.ts +0 -0
  107. package/{lib → types}/user/identity-provider.d.ts +0 -0
  108. package/{lib → types}/user/user-client-interface.d.ts +0 -0
  109. package/{lib → types}/user/user-client.d.ts +0 -0
  110. package/{lib → types}/user/user-key-names.d.ts +0 -0
  111. package/{lib → types}/utils/resolvable-promise.d.ts +0 -0
  112. package/types/redux-offline/index.d.ts +0 -4
@@ -1,190 +1,145 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ApiClient = void 0;
7
-
8
- var _awsAppsync = require("aws-appsync");
9
-
10
- var _graphqlTypes = require("../gen/graphql-types");
11
-
12
- var _sudoCommon = require("@sudoplatform/sudo-common");
13
-
14
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
-
1
+ import { AWSAppSyncClient, AUTH_TYPE } from 'aws-appsync';
2
+ import { DeregisterDocument, RegisterFederatedIdDocument, GlobalSignOutDocument, } from '../gen/graphql-types';
3
+ import { NotSignedInError, FatalError, ServiceError, UnknownGraphQLError, NotAuthorizedError, } from '@sudoplatform/sudo-common';
16
4
  /**
17
5
  * AppSync wrapper to use to invoke Identity Service APIs.
18
6
  */
19
- class ApiClient {
20
- constructor(region, graphqlUrl, sudoUserClient, logger) {
21
- _defineProperty(this, "client", void 0);
22
-
23
- _defineProperty(this, "region", void 0);
24
-
25
- _defineProperty(this, "graphqlUrl", void 0);
26
-
27
- _defineProperty(this, "sudoUserClient", void 0);
28
-
29
- _defineProperty(this, "logger", void 0);
30
-
31
- this.region = region;
32
- this.graphqlUrl = graphqlUrl;
33
- this.sudoUserClient = sudoUserClient;
34
- this.logger = logger;
35
- this.client = new _awsAppsync.AWSAppSyncClient({
36
- url: graphqlUrl,
37
- region: region,
38
- auth: {
39
- type: _awsAppsync.AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
40
- jwtToken: async () => await sudoUserClient.getLatestAuthToken()
41
- },
42
- disableOffline: true
43
- });
44
- }
45
-
46
- async deregister() {
47
- if (!(await this.sudoUserClient.isSignedIn())) {
48
- throw new _sudoCommon.NotSignedInError();
7
+ export class ApiClient {
8
+ constructor(region, graphqlUrl, sudoUserClient, logger) {
9
+ this.region = region;
10
+ this.graphqlUrl = graphqlUrl;
11
+ this.sudoUserClient = sudoUserClient;
12
+ this.logger = logger;
13
+ this.client = new AWSAppSyncClient({
14
+ url: graphqlUrl,
15
+ region: region,
16
+ auth: {
17
+ type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
18
+ jwtToken: async () => await sudoUserClient.getLatestAuthToken(),
19
+ },
20
+ disableOffline: true,
21
+ });
49
22
  }
50
-
51
- let result;
52
-
53
- try {
54
- result = await this.client.mutate({
55
- mutation: _graphqlTypes.DeregisterDocument,
56
- fetchPolicy: 'no-cache'
57
- });
58
- } catch (err) {
59
- const apolloError = err;
60
- const error = apolloError.graphQLErrors?.[0];
61
-
62
- if (error) {
63
- throw this.graphQLErrorsToClientError(error);
64
- } else {
65
- throw new _sudoCommon.UnknownGraphQLError(err);
66
- }
23
+ async deregister() {
24
+ if (!(await this.sudoUserClient.isSignedIn())) {
25
+ throw new NotSignedInError();
26
+ }
27
+ let result;
28
+ try {
29
+ result = await this.client.mutate({
30
+ mutation: DeregisterDocument,
31
+ fetchPolicy: 'no-cache',
32
+ });
33
+ }
34
+ catch (err) {
35
+ const apolloError = err;
36
+ const error = apolloError.graphQLErrors?.[0];
37
+ if (error) {
38
+ throw this.graphQLErrorsToClientError(error);
39
+ }
40
+ else {
41
+ throw new UnknownGraphQLError(err);
42
+ }
43
+ }
44
+ const error = result.errors?.[0];
45
+ if (error) {
46
+ throw this.graphQLErrorsToClientError(error);
47
+ }
48
+ if (result.data) {
49
+ return { success: result.data.deregister?.success ? true : false };
50
+ }
51
+ else {
52
+ throw new FatalError('deregister did not return any result.');
53
+ }
67
54
  }
68
-
69
- const error = result.errors?.[0];
70
-
71
- if (error) {
72
- throw this.graphQLErrorsToClientError(error);
55
+ async globalSignOut() {
56
+ if (!(await this.sudoUserClient.isSignedIn())) {
57
+ throw new NotSignedInError();
58
+ }
59
+ let result;
60
+ try {
61
+ result = await this.client.mutate({
62
+ mutation: GlobalSignOutDocument,
63
+ fetchPolicy: 'no-cache',
64
+ });
65
+ }
66
+ catch (err) {
67
+ const apolloError = err;
68
+ const error = apolloError.graphQLErrors?.[0];
69
+ if (error) {
70
+ throw this.graphQLErrorsToClientError(error);
71
+ }
72
+ else {
73
+ throw new UnknownGraphQLError(err);
74
+ }
75
+ }
76
+ const error = result.errors?.[0];
77
+ if (error) {
78
+ throw this.graphQLErrorsToClientError(error);
79
+ }
80
+ if (result.data) {
81
+ return { success: result.data.globalSignOut?.success ? true : false };
82
+ }
83
+ else {
84
+ throw new FatalError('globalSignOut did not return any result.');
85
+ }
73
86
  }
74
-
75
- if (result.data) {
76
- return {
77
- success: result.data.deregister?.success ? true : false
78
- };
79
- } else {
80
- throw new _sudoCommon.FatalError('deregister did not return any result.');
87
+ async registerFederatedId(input) {
88
+ let result;
89
+ try {
90
+ result = await this.client.mutate({
91
+ mutation: RegisterFederatedIdDocument,
92
+ variables: { input },
93
+ fetchPolicy: 'no-cache',
94
+ });
95
+ }
96
+ catch (err) {
97
+ const apolloError = err;
98
+ const error = apolloError.graphQLErrors?.[0];
99
+ if (error) {
100
+ throw this.graphQLErrorsToClientError(error);
101
+ }
102
+ else {
103
+ throw new UnknownGraphQLError(err);
104
+ }
105
+ }
106
+ const error = result.errors?.[0];
107
+ if (error) {
108
+ throw this.graphQLErrorsToClientError(error);
109
+ }
110
+ const identityId = result.data?.registerFederatedId?.identityId;
111
+ if (identityId) {
112
+ return {
113
+ identityId,
114
+ };
115
+ }
116
+ else {
117
+ throw new FatalError('registerFederatedId did not return expected result.');
118
+ }
81
119
  }
82
- }
83
-
84
- async globalSignOut() {
85
- if (!(await this.sudoUserClient.isSignedIn())) {
86
- throw new _sudoCommon.NotSignedInError();
120
+ reset() {
121
+ this.client.clearStore();
122
+ this.client = new AWSAppSyncClient({
123
+ url: this.graphqlUrl,
124
+ region: this.region,
125
+ auth: {
126
+ type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
127
+ jwtToken: async () => await this.sudoUserClient.getLatestAuthToken(),
128
+ },
129
+ disableOffline: true,
130
+ });
87
131
  }
88
-
89
- let result;
90
-
91
- try {
92
- result = await this.client.mutate({
93
- mutation: _graphqlTypes.GlobalSignOutDocument,
94
- fetchPolicy: 'no-cache'
95
- });
96
- } catch (err) {
97
- const apolloError = err;
98
- const error = apolloError.graphQLErrors?.[0];
99
-
100
- if (error) {
101
- throw this.graphQLErrorsToClientError(error);
102
- } else {
103
- throw new _sudoCommon.UnknownGraphQLError(err);
104
- }
132
+ graphQLErrorsToClientError(error) {
133
+ this.logger.error('GraphQL call failed.', { error });
134
+ if (error.errorType === 'sudoplatform.ServiceError') {
135
+ return new ServiceError(error.message);
136
+ }
137
+ else if (error.errorType === 'sudoplatform.identity.TokenValidationError') {
138
+ return new NotAuthorizedError();
139
+ }
140
+ else {
141
+ return new UnknownGraphQLError(error);
142
+ }
105
143
  }
106
-
107
- const error = result.errors?.[0];
108
-
109
- if (error) {
110
- throw this.graphQLErrorsToClientError(error);
111
- }
112
-
113
- if (result.data) {
114
- return {
115
- success: result.data.globalSignOut?.success ? true : false
116
- };
117
- } else {
118
- throw new _sudoCommon.FatalError('globalSignOut did not return any result.');
119
- }
120
- }
121
-
122
- async registerFederatedId(input) {
123
- let result;
124
-
125
- try {
126
- result = await this.client.mutate({
127
- mutation: _graphqlTypes.RegisterFederatedIdDocument,
128
- variables: {
129
- input
130
- },
131
- fetchPolicy: 'no-cache'
132
- });
133
- } catch (err) {
134
- const apolloError = err;
135
- const error = apolloError.graphQLErrors?.[0];
136
-
137
- if (error) {
138
- throw this.graphQLErrorsToClientError(error);
139
- } else {
140
- throw new _sudoCommon.UnknownGraphQLError(err);
141
- }
142
- }
143
-
144
- const error = result.errors?.[0];
145
-
146
- if (error) {
147
- throw this.graphQLErrorsToClientError(error);
148
- }
149
-
150
- const identityId = result.data?.registerFederatedId?.identityId;
151
-
152
- if (identityId) {
153
- return {
154
- identityId
155
- };
156
- } else {
157
- throw new _sudoCommon.FatalError('registerFederatedId did not return expected result.');
158
- }
159
- }
160
-
161
- reset() {
162
- this.client.clearStore();
163
- this.client = new _awsAppsync.AWSAppSyncClient({
164
- url: this.graphqlUrl,
165
- region: this.region,
166
- auth: {
167
- type: _awsAppsync.AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
168
- jwtToken: async () => await this.sudoUserClient.getLatestAuthToken()
169
- },
170
- disableOffline: true
171
- });
172
- }
173
-
174
- graphQLErrorsToClientError(error) {
175
- this.logger.error('GraphQL call failed.', {
176
- error
177
- });
178
-
179
- if (error.errorType === 'sudoplatform.ServiceError') {
180
- return new _sudoCommon.ServiceError(error.message);
181
- } else if (error.errorType === 'sudoplatform.identity.TokenValidationError') {
182
- return new _sudoCommon.NotAuthorizedError();
183
- } else {
184
- return new _sudoCommon.UnknownGraphQLError(error);
185
- }
186
- }
187
-
188
144
  }
189
-
190
- exports.ApiClient = ApiClient;
145
+ //# sourceMappingURL=apiClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiClient.js","sourceRoot":"","sources":["../../src/client/apiClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EAEL,kBAAkB,EAElB,2BAA2B,EAG3B,qBAAqB,GACtB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,mBAAmB,EAGnB,kBAAkB,GACnB,MAAM,2BAA2B,CAAA;AAIlC;;GAEG;AACH,MAAM,OAAO,SAAS;IAOpB,YACE,MAAc,EACd,UAAkB,EAClB,cAA8B,EAC9B,MAAc;QAEd,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QAEpB,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAgB,CAAC;YACjC,GAAG,EAAE,UAAU;YACf,MAAM,EAAE,MAAM;YACd,IAAI,EAAE;gBACJ,IAAI,EAAE,SAAS,CAAC,yBAAyB;gBACzC,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,cAAc,CAAC,kBAAkB,EAAE;aAChE;YACD,cAAc,EAAE,IAAI;SACrB,CAAC,CAAA;IACJ,CAAC;IAEM,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AAA;SACtC;IACH,CAAC;CACF"}
@@ -1,15 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.apiKeyNames = void 0;
7
- const apiKeyNames = {
8
- idToken: 'idToken',
9
- accessToken: 'accessToken',
10
- refreshToken: 'refreshToken',
11
- tokenExpiry: 'tokenExpiry',
12
- refreshTokenExpiry: 'refreshTokenExpiry',
13
- userId: 'LastAuthUser'
1
+ export const apiKeyNames = {
2
+ idToken: 'idToken',
3
+ accessToken: 'accessToken',
4
+ refreshToken: 'refreshToken',
5
+ tokenExpiry: 'tokenExpiry',
6
+ refreshTokenExpiry: 'refreshTokenExpiry',
7
+ userId: 'LastAuthUser',
14
8
  };
15
- exports.apiKeyNames = apiKeyNames;
9
+ //# sourceMappingURL=api-key-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key-names.js","sourceRoot":"","sources":["../../src/core/api-key-names.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,SAAS;IAClB,WAAW,EAAE,aAAa;IAC1B,YAAY,EAAE,cAAc;IAC5B,WAAW,EAAE,aAAa;IAC1B,kBAAkB,EAAE,oBAAoB;IACxC,MAAM,EAAE,cAAc;CACvB,CAAA"}
@@ -1,144 +1,88 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.AuthenticationStore = void 0;
7
-
8
- var JWT = _interopRequireWildcard(require("jsonwebtoken"));
9
-
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
-
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
-
14
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
-
16
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
17
-
18
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
19
-
20
- function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
21
-
22
- function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
23
-
24
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
25
-
26
- function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
27
-
28
- function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
29
-
30
- var _secrets = /*#__PURE__*/new WeakMap();
31
-
1
+ var _AuthenticationStore_secrets;
2
+ import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
+ import * as JWT from 'jsonwebtoken';
32
4
  /**
33
5
  * Stores authentication details such as tokens and username
34
6
  */
35
- class AuthenticationStore {
36
- constructor() {
37
- _classPrivateFieldInitSpec(this, _secrets, {
38
- writable: true,
39
- value: {}
40
- });
41
-
42
- _defineProperty(this, "subscribers", []);
43
- }
44
-
45
- /** Adds a secret into private _secrets object */
46
- async addSecret(keyId, secret) {
47
- const key = keyId.substr(keyId.lastIndexOf('.') + 1);
48
- _classPrivateFieldGet(this, _secrets)[key] = secret;
49
- }
50
- /**
51
- * Adds a string value into authentication store
52
- */
53
-
54
-
55
- async setItem(keyId, value) {
56
- const key = keyId.substr(keyId.lastIndexOf('.') + 1);
57
-
58
- if (key === 'idToken') {
59
- // Store the token expiry
60
- const decoded = JWT.decode(value, {
61
- complete: true
62
- });
63
-
64
- if (decoded) {
65
- const tokenExpiry = decoded.payload['exp'];
66
- await this.addSecret('tokenExpiry', {
67
- type: 'string',
68
- value: tokenExpiry
69
- });
70
- }
7
+ export class AuthenticationStore {
8
+ constructor() {
9
+ /** Do not expose these directly */
10
+ // eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
11
+ _AuthenticationStore_secrets.set(this, {});
12
+ this.subscribers = [];
71
13
  }
72
-
73
- await this.addSecret(key, {
74
- type: 'string',
75
- value
76
- });
77
- await this.notifySubscribers(key);
78
- }
79
- /**
80
- * Returns a string value from authentication store
81
- */
82
-
83
-
84
- getItem(keyId) {
85
- const key = keyId.substr(keyId.lastIndexOf('.') + 1);
86
-
87
- const secret = _classPrivateFieldGet(this, _secrets)[key];
88
-
89
- return secret?.type === 'string' ? secret.value : undefined;
90
- }
91
- /**
92
- * Removes a secret
93
- */
94
-
95
-
96
- removeItem(keyId) {
97
- const key = keyId.substr(keyId.lastIndexOf('.') + 1);
98
- delete _classPrivateFieldGet(this, _secrets)[key];
99
- }
100
- /**
101
- * Clears all secrets
102
- */
103
-
104
-
105
- reset() {
106
- _classPrivateFieldSet(this, _secrets, {});
107
- }
108
- /**
109
- * Register a subscriber to be notified when items are added
110
- *
111
- * @param subscriber a subscriber to be notified when items are added
112
- */
113
-
114
-
115
- async subscribe(subscriber) {
116
- this.subscribers.push(subscriber);
117
- }
118
- /**
119
- * Remove a subscriber from the list of subscribers
120
- *
121
- * @param subscriber the subscriber to be removed
122
- */
123
-
124
-
125
- async unsubscribe(subscriber) {
126
- const index = this.subscribers.indexOf(subscriber);
127
- this.subscribers.splice(index, 1);
128
- }
129
- /**
130
- * Notify all subscribers that a change event was triggered for a specific item
131
- *
132
- * @param itemName the name of the item that changed
133
- */
134
-
135
-
136
- async notifySubscribers(itemName) {
137
- for (const subscriber of this.subscribers) {
138
- subscriber.update(itemName);
14
+ /** Adds a secret into private _secrets object */
15
+ async addSecret(keyId, secret) {
16
+ const key = keyId.substr(keyId.lastIndexOf('.') + 1);
17
+ __classPrivateFieldGet(this, _AuthenticationStore_secrets, "f")[key] = secret;
18
+ }
19
+ /**
20
+ * Adds a string value into authentication store
21
+ */
22
+ async setItem(keyId, value) {
23
+ const key = keyId.substr(keyId.lastIndexOf('.') + 1);
24
+ if (key === 'idToken') {
25
+ // Store the token expiry
26
+ const decoded = JWT.decode(value, { complete: true });
27
+ if (decoded) {
28
+ const tokenExpiry = decoded.payload['exp'];
29
+ await this.addSecret('tokenExpiry', {
30
+ type: 'string',
31
+ value: tokenExpiry,
32
+ });
33
+ }
34
+ }
35
+ await this.addSecret(key, { type: 'string', value });
36
+ await this.notifySubscribers(key);
37
+ }
38
+ /**
39
+ * Returns a string value from authentication store
40
+ */
41
+ getItem(keyId) {
42
+ const key = keyId.substr(keyId.lastIndexOf('.') + 1);
43
+ const secret = __classPrivateFieldGet(this, _AuthenticationStore_secrets, "f")[key];
44
+ return secret?.type === 'string' ? secret.value : undefined;
45
+ }
46
+ /**
47
+ * Removes a secret
48
+ */
49
+ removeItem(keyId) {
50
+ const key = keyId.substr(keyId.lastIndexOf('.') + 1);
51
+ delete __classPrivateFieldGet(this, _AuthenticationStore_secrets, "f")[key];
52
+ }
53
+ /**
54
+ * Clears all secrets
55
+ */
56
+ reset() {
57
+ __classPrivateFieldSet(this, _AuthenticationStore_secrets, {}, "f");
58
+ }
59
+ /**
60
+ * Register a subscriber to be notified when items are added
61
+ *
62
+ * @param subscriber a subscriber to be notified when items are added
63
+ */
64
+ async subscribe(subscriber) {
65
+ this.subscribers.push(subscriber);
66
+ }
67
+ /**
68
+ * Remove a subscriber from the list of subscribers
69
+ *
70
+ * @param subscriber the subscriber to be removed
71
+ */
72
+ async unsubscribe(subscriber) {
73
+ const index = this.subscribers.indexOf(subscriber);
74
+ this.subscribers.splice(index, 1);
75
+ }
76
+ /**
77
+ * Notify all subscribers that a change event was triggered for a specific item
78
+ *
79
+ * @param itemName the name of the item that changed
80
+ */
81
+ async notifySubscribers(itemName) {
82
+ for (const subscriber of this.subscribers) {
83
+ subscriber.update(itemName);
84
+ }
139
85
  }
140
- }
141
-
142
86
  }
143
-
144
- exports.AuthenticationStore = AuthenticationStore;
87
+ _AuthenticationStore_secrets = new WeakMap();
88
+ //# sourceMappingURL=auth-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-store.js","sourceRoot":"","sources":["../../src/core/auth-store.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAcnC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAAhC;QACE,mCAAmC;QACnC,0EAA0E;QAC1E,uCAAmC,EAAE,EAAA;QACrC,gBAAW,GAAiB,EAAE,CAAA;IAiFhC,CAAC;IA/EC,iDAAiD;IACzC,KAAK,CAAC,SAAS,CAAC,KAAa,EAAE,MAAc;QACnD,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QACpD,uBAAA,IAAI,oCAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;IAC7B,CA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CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IAED;;OAEG;IACI,KAAK;QACV,uBAAA,IAAI,gCAAY,EAAE,MAAA,CAAA;IACpB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,SAAS,CAAC,UAAsB;QAC3C,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACnC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,WAAW,CAAC,UAAsB;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAClD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IACnC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB,CAAC,QAAgB;QACtC,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE;YACzC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;SAC5B;IACH,CAAC;CACF"}
@@ -1,5 +1,2 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ export {};
2
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/core/crypto.ts"],"names":[],"mappings":""}