cidaas-javascript-sdk 4.3.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +57 -5
  2. package/README.md +109 -94
  3. package/dist/authentication-service/AuthenticationService.d.ts +140 -0
  4. package/dist/authentication-service/AuthenticationService.js +210 -0
  5. package/dist/{authentication/Authentication.model.d.ts → authentication-service/AuthenticationService.model.d.ts} +18 -12
  6. package/dist/{authentication/Authentication.model.js → authentication-service/AuthenticationService.model.js} +2 -2
  7. package/dist/common/Common.model.d.ts +15 -19
  8. package/dist/common/Common.model.js +17 -17
  9. package/dist/common/ConfigUserProvider.d.ts +10 -0
  10. package/dist/common/ConfigUserProvider.js +28 -0
  11. package/dist/common/Helper.d.ts +7 -0
  12. package/dist/common/Helper.js +19 -0
  13. package/dist/common/User.model.d.ts +0 -4
  14. package/dist/consent-service/ConsentService.d.ts +99 -95
  15. package/dist/consent-service/ConsentService.js +125 -122
  16. package/dist/consent-service/ConsentService.model.d.ts +14 -16
  17. package/dist/device-service/DeviceService.d.ts +49 -0
  18. package/dist/device-service/DeviceService.js +79 -0
  19. package/dist/device-service/DeviceService.model.d.ts +6 -0
  20. package/dist/id-validation-service/IdValidationService.d.ts +28 -0
  21. package/dist/id-validation-service/IdValidationService.js +59 -0
  22. package/dist/id-validation-service/IdValidationService.model.d.ts +8 -0
  23. package/dist/id-validation-service/IdValidationService.model.js +2 -0
  24. package/dist/index.d.ts +22 -3
  25. package/dist/index.js +35 -18
  26. package/dist/login-service/LoginService.d.ts +143 -141
  27. package/dist/login-service/LoginService.js +225 -234
  28. package/dist/login-service/LoginService.model.d.ts +9 -53
  29. package/dist/login-service/LoginService.model.js +1 -1
  30. package/dist/public-service/PublicService.d.ts +57 -0
  31. package/dist/public-service/PublicService.js +73 -0
  32. package/dist/public-service/PublicService.model.d.ts +20 -0
  33. package/dist/public-service/PublicService.model.js +2 -0
  34. package/dist/token-service/TokenService.d.ts +104 -138
  35. package/dist/token-service/TokenService.js +164 -219
  36. package/dist/token-service/TokenService.model.d.ts +3 -44
  37. package/dist/token-service/TokenService.model.js +3 -16
  38. package/dist/user-service/UserService.d.ts +381 -315
  39. package/dist/user-service/UserService.js +552 -426
  40. package/dist/user-service/UserService.model.d.ts +48 -14
  41. package/dist/user-service/UserService.model.js +4 -4
  42. package/dist/verification-service/VerificationService.d.ts +281 -217
  43. package/dist/verification-service/VerificationService.js +343 -281
  44. package/dist/verification-service/VerificationService.model.d.ts +18 -5
  45. package/package.json +6 -4
  46. package/dist/authentication/Authentication.d.ts +0 -139
  47. package/dist/authentication/Authentication.js +0 -186
  48. package/dist/web-auth/WebAuth.d.ts +0 -665
  49. package/dist/web-auth/WebAuth.js +0 -955
  50. package/dist/web-auth/webauth.model.d.ts +0 -66
  51. /package/dist/{web-auth/webauth.model.js → device-service/DeviceService.model.js} +0 -0
@@ -1,451 +1,577 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.userCheckExists = exports.deleteUserAccount = exports.unlinkAccount = exports.getLinkedUsers = exports.completeLinkAccount = exports.initiateLinkAccount = exports.updateProfile = exports.changePassword = exports.registerDeduplication = exports.deduplicationLogin = exports.getDeduplicationDetails = exports.resetPassword = exports.handleResetPassword = exports.initiateResetPassword = exports.getCommunicationStatus = exports.getInviteUserDetails = exports.register = exports.getUserProfile = void 0;
3
+ exports.UserService = void 0;
4
4
  const Helper_1 = require("../common/Helper");
5
- /**
6
- * To get the user profile information by using cidaas internal api, call **getUserProfile()**.
7
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/2zfvjx3vtq6g6-get-user-info for more details.
8
- * @example
9
- * ```js
10
- * const options = {
11
- * access_token: 'your access token'
12
- * }
13
- * cidaas.getUserProfile(options)
14
- * .then(function () {
15
- * // the response will give you user profile information.
16
- * }).catch(function (ex) {
17
- * // your failure code here
18
- * });
19
- * ```
20
- */
21
- function getUserProfile(options) {
22
- if (!options.access_token) {
23
- throw new Helper_1.CustomException("access_token cannot be empty", 417);
5
+ class UserService {
6
+ constructor(configUserProvider) {
7
+ this.config = configUserProvider.getConfig();
8
+ this.userManager = configUserProvider.getUserManager();
24
9
  }
25
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/userinfo";
26
- return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, undefined, "GET", options.access_token);
27
- }
28
- exports.getUserProfile = getUserProfile;
29
- /**
30
- * To register user, call **register()**. This method will create a new user.
31
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/427632e587203-register-a-new-user for more details.
32
- * Note: Only requestId in the headers is required.
33
- * @example
34
- * ```js
35
- * const headers = {
36
- * requestId: 'your_received_requestId',
37
- * captcha: 'captcha',
38
- * acceptlanguage: 'acceptlanguage',
39
- * bot_captcha_response: 'bot_captcha_response'
40
- * };
41
- *
42
- * cidaas.register({
43
- * email: 'xxx123@xxx.com',
44
- * given_name: 'xxxxx',
45
- * family_name: 'yyyyy',
46
- * password: '123456',
47
- * password_echo: '123456',
48
- * provider: 'your provider', // FACEBOOK, GOOGLE, SELF
49
- * acceptlanguage: 'your locale' // optional example: de-de, en-US
50
- * }, headers).then(function (response) {
51
- * // the response will give you client registration details.
52
- * }).catch(function(ex) {
53
- * // your failure code here
54
- * });
55
- *```
56
- */
57
- function register(options, headers) {
58
- let _serviceURL = window.webAuthSettings.authority + "/users-srv/register";
59
- if (options.invite_id) {
60
- _serviceURL = _serviceURL + "?invite_id=" + options.invite_id;
10
+ /**
11
+ * To get the user profile information by using cidaas internal api, call **getUserProfile()**.
12
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/2zfvjx3vtq6g6-get-user-info for more details.
13
+ * @example
14
+ * ```js
15
+ * cidaasUserService.getUserProfile()
16
+ * .then(function () {
17
+ * // the response will give you user profile information.
18
+ * }).catch(function (ex) {
19
+ * // your failure code here
20
+ * });
21
+ * ```
22
+ */
23
+ getUserProfile(options) {
24
+ const _serviceURL = this.config.authority + "/users-srv/userinfo";
25
+ if (options === null || options === void 0 ? void 0 : options.access_token) {
26
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, undefined, "GET", options.access_token);
27
+ }
28
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
29
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, undefined, "GET", accessToken);
30
+ });
61
31
  }
62
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", undefined, headers);
63
- }
64
- exports.register = register;
65
- /**
66
- * to get information about invitation details, call **getInviteUserDetails()**. This API allows to retrieve invitation details and prefill the registration form.
67
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/0b5efa5a2db5d-prefill-the-user-invitation for more details.
68
- * Minimum cidaas version to use latest api is v3.100
69
- * @example
70
- * ```js
71
- * const options = {
72
- * invite_id: 'id of user invitation'
73
- * callLatestAPI: 'true' // call latest api if parameter is given. By default, the older api will be called
74
- * }
75
- * cidaas.getInviteUserDetails(options)
76
- * .then(function () {
77
- * // the response will give you information about the invitation.
78
- * }).catch(function (ex) {
79
- * // your failure code here
80
- * });
81
- * ```
82
- */
83
- function getInviteUserDetails(options, headers) {
84
- let _serviceURL = "";
85
- if (options.callLatestAPI) {
86
- _serviceURL = window.webAuthSettings.authority + "/useractions-srv/invitations/" + options.invite_id;
32
+ /**
33
+ * To handle registration, first you need the registration fields. To get the registration fields, call **getRegistrationSetup()**. This will return the fields that has to be needed while registration.
34
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/4eae72956f65a-registration-field-setup for more details.
35
+ * @example
36
+ * ```js
37
+ * cidaasUserService.getRegistrationSetup({
38
+ * requestId: 'your requestId',
39
+ * acceptlanguage: 'your locale' // optional example: de-de, en-US
40
+ * }).then(function (resp) {
41
+ * // the response will give you fields that are required.
42
+ * }).catch(function(ex) {
43
+ * // your failure code here
44
+ * });
45
+ * ```
46
+ */
47
+ getRegistrationSetup(options) {
48
+ const serviceURL = this.config.authority + '/registration-setup-srv/public/list?acceptlanguage=' + options.acceptlanguage + '&requestId=' + options.requestId;
49
+ return Helper_1.Helper.createHttpPromise(undefined, serviceURL, false, 'GET');
87
50
  }
88
- else {
89
- _serviceURL = window.webAuthSettings.authority + "/users-srv/invite/info/" + options.invite_id;
51
+ /**
52
+ * To register user, call **register()**. This method will create a new user.
53
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/427632e587203-register-a-new-user for more details.
54
+ * Note: Only requestId in the headers is required.
55
+ * @example
56
+ * ```js
57
+ * const headers = {
58
+ * requestId: 'your_received_requestId',
59
+ * captcha: 'captcha',
60
+ * acceptlanguage: 'acceptlanguage',
61
+ * bot_captcha_response: 'bot_captcha_response'
62
+ * };
63
+ *
64
+ * cidaasUserService.register({
65
+ * email: 'xxx123@xxx.com',
66
+ * given_name: 'xxxxx',
67
+ * family_name: 'yyyyy',
68
+ * password: '123456',
69
+ * password_echo: '123456',
70
+ * provider: 'your provider', // FACEBOOK, GOOGLE, SELF
71
+ * acceptlanguage: 'your locale' // optional example: de-de, en-US
72
+ * }, headers).then(function (response) {
73
+ * // the response will give you client registration details.
74
+ * }).catch(function(ex) {
75
+ * // your failure code here
76
+ * });
77
+ *```
78
+ */
79
+ register(options, headers) {
80
+ let _serviceURL = this.config.authority + "/users-srv/register";
81
+ if (options.invite_id) {
82
+ _serviceURL = _serviceURL + "?invite_id=" + options.invite_id;
83
+ }
84
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", undefined, headers);
90
85
  }
91
- return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", undefined, headers);
92
- }
93
- exports.getInviteUserDetails = getInviteUserDetails;
94
- /**
95
- * Once registration successful, verify the account based on the flow. To get the details, call **getCommunicationStatus()**.
96
- * @example
97
- * ```js
98
- * cidaas.getCommunicationStatus({
99
- * sub: 'your sub', // which you will get on the registration response
100
- * }).then(function (response) {
101
- * // the response will give you account details once its verified.
102
- * }).catch(function(ex) {
103
- * // your failure code here
104
- * });
105
- * ```
106
- */
107
- function getCommunicationStatus(options, headers) {
108
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/user/communication/status/" + options.sub;
109
- return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", undefined, headers);
110
- }
111
- exports.getCommunicationStatus = getCommunicationStatus;
112
- /**
113
- * To initiate the password resetting, call **initiateResetPassword()**. This will send verification code to your email or mobile based on the resetMedium you mentioned.
114
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/6b29bac6002f4-initiate-password-reset for more details.
115
- * @example
116
- * ```js
117
- * cidaas.initiateResetPassword({
118
- * email: 'xxxxxx@xxx.com',
119
- * processingType: ProcessingType.CODE,
120
- * requestId: 'your requestId',
121
- * resetMedium: ResetMedium.EMAIL
122
- * }).then(function (response) {
123
- * // the response will give you password reset details.
124
- * }).catch(function(ex) {
125
- * // your failure code here
126
- * });
127
- * ```
128
- */
129
- function initiateResetPassword(options, headers) {
130
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/resetpassword/initiate";
131
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", undefined, headers);
132
- }
133
- exports.initiateResetPassword = initiateResetPassword;
134
- /**
135
- * To handle the reset password by entering the verification code you received, call **handleResetPassword()**. This will check if your verification code was valid or not, and allows you to proceed to the next step.
136
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/3t8ztokeb7cfz-handle-reset-password for more details.
137
- * @example
138
- * ```js
139
- * const handleResponseAsJson = 'true if the response need to be handled the old way (as json). In the current handling, the response information will be given as query parameter in redirect url.';
140
- * cidaas.handleResetPassword({
141
- * code: 'your code in email or sms or ivr',
142
- * resetRequestId: 'your resetRequestId' // which you will get on initiate reset password response
143
- * }, handleResponseAsJson).then(function (response) {
144
- * // the response will give you valid verification code.
145
- * }).catch(function(ex) {
146
- * // your failure code here
147
- * });
148
- * ```
149
- */
150
- function handleResetPassword(options, handleResponseAsJson, headers) {
151
- try {
152
- const url = window.webAuthSettings.authority + "/users-srv/resetpassword/validatecode";
153
- if (!handleResponseAsJson) {
154
- // current handling will redirect and give query parameters
155
- const form = Helper_1.Helper.createForm(url, options);
156
- document.body.appendChild(form);
157
- form.submit();
86
+ /**
87
+ * to get information about invitation details, call **getInviteUserDetails()**. This API allows to retrieve invitation details and prefill the registration form.
88
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/0b5efa5a2db5d-prefill-the-user-invitation for more details.
89
+ * Minimum cidaas version to use latest api is v3.100
90
+ * @example
91
+ * ```js
92
+ * const options = {
93
+ * invite_id: 'id of user invitation'
94
+ * callLatestAPI: 'true' // call latest api if parameter is given. By default, the older api will be called
95
+ * }
96
+ * cidaasUserService.getInviteUserDetails(options)
97
+ * .then(function () {
98
+ * // the response will give you information about the invitation.
99
+ * }).catch(function (ex) {
100
+ * // your failure code here
101
+ * });
102
+ * ```
103
+ */
104
+ getInviteUserDetails(options, headers) {
105
+ let _serviceURL = "";
106
+ if (options.callLatestAPI) {
107
+ _serviceURL = this.config.authority + "/useractions-srv/invitations/" + options.invite_id;
158
108
  }
159
109
  else {
160
- // older cidaas service handling return json object
161
- return Helper_1.Helper.createHttpPromise(options, url, false, "POST", undefined, headers);
110
+ _serviceURL = this.config.authority + "/users-srv/invite/info/" + options.invite_id;
162
111
  }
112
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", undefined, headers);
163
113
  }
164
- catch (ex) {
165
- throw new Helper_1.CustomException(String(ex), 417);
114
+ /**
115
+ * Once registration successful, verify the account based on the flow. To get the details, call **getCommunicationStatus()**.
116
+ * @example
117
+ * ```js
118
+ * cidaasUserService.getCommunicationStatus({
119
+ * sub: 'your sub', // which you will get on the registration response
120
+ * }).then(function (response) {
121
+ * // the response will give you account details once its verified.
122
+ * }).catch(function(ex) {
123
+ * // your failure code here
124
+ * });
125
+ * ```
126
+ */
127
+ getCommunicationStatus(options, headers) {
128
+ const _serviceURL = this.config.authority + "/users-srv/user/communication/status/" + options.sub;
129
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", undefined, headers);
166
130
  }
167
- }
168
- exports.handleResetPassword = handleResetPassword;
169
- /**
170
- * To finish reseting the password, call **resetPassword()**. This will allow you to change your password.
171
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/qa9ny0gkzlf6y-accept-reset-password for more details.
172
- * @example
173
- * ```js
174
- * const handleResponseAsJson = 'true if the response need to be handled the old way (as json). In the current handling, user will be redirected to success page after successful reset password.';
175
- * cidaas.resetPassword({
176
- * password: '123456',
177
- * confirmPassword: '123456',
178
- * exchangeId: 'your exchangeId', // which you will get on handle reset password response
179
- * resetRequestId: 'your resetRequestId' // which you will get on handle reset password response
180
- * }).then(function (response) {
181
- * // the response will give you reset password details.
182
- * }).catch(function(ex) {
183
- * // your failure code here
184
- * });
185
- * ```
186
- */
187
- function resetPassword(options, handleResponseAsJson, headers) {
188
- const url = window.webAuthSettings.authority + "/users-srv/resetpassword/accept";
189
- try {
190
- if (!handleResponseAsJson) {
191
- // current handling will redirect and give query parameters
192
- const form = Helper_1.Helper.createForm(url, options);
131
+ /**
132
+ * To initiate the password resetting, call **initiateResetPassword()**. This will send verification code to your email or mobile based on the resetMedium you mentioned.
133
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/6b29bac6002f4-initiate-password-reset for more details.
134
+ * @example
135
+ * ```js
136
+ * cidaasUserService.initiateResetPassword({
137
+ * email: 'xxxxxx@xxx.com',
138
+ * processingType: ProcessingType.Code,
139
+ * requestId: 'your requestId',
140
+ * resetMedium: ResetMedium.Email
141
+ * }).then(function (response) {
142
+ * // the response will give you password reset details.
143
+ * }).catch(function(ex) {
144
+ * // your failure code here
145
+ * });
146
+ * ```
147
+ */
148
+ initiateResetPassword(options, headers) {
149
+ const _serviceURL = this.config.authority + "/users-srv/resetpassword/initiate";
150
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", undefined, headers);
151
+ }
152
+ /**
153
+ * To handle the reset password by entering the verification code you received, call **handleResetPassword()**. This will check if your verification code was valid or not, and allows you to proceed to the next step.
154
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/3t8ztokeb7cfz-handle-reset-password for more details.
155
+ * @example
156
+ * ```js
157
+ * const handleResponseAsJson = 'true if the response need to be handled the old way (as json). In the current handling, the response information will be given as query parameter in redirect url.';
158
+ * cidaasUserService.handleResetPassword({
159
+ * code: 'your code in email or sms or ivr',
160
+ * resetRequestId: 'your resetRequestId' // which you will get on initiate reset password response
161
+ * }, handleResponseAsJson).then(function (response) {
162
+ * // the response will give you valid verification code.
163
+ * }).catch(function(ex) {
164
+ * // your failure code here
165
+ * });
166
+ * ```
167
+ */
168
+ handleResetPassword(options, handleResponseAsJson, headers) {
169
+ try {
170
+ const url = this.config.authority + "/users-srv/resetpassword/validatecode";
171
+ if (!handleResponseAsJson) {
172
+ // current handling will redirect and give query parameters
173
+ const form = Helper_1.Helper.createForm(url, options);
174
+ document.body.appendChild(form);
175
+ form.submit();
176
+ }
177
+ else {
178
+ // older cidaas service handling return json object
179
+ return Helper_1.Helper.createHttpPromise(options, url, false, "POST", undefined, headers);
180
+ }
181
+ }
182
+ catch (ex) {
183
+ throw new Helper_1.CustomException(String(ex), 417);
184
+ }
185
+ }
186
+ /**
187
+ * To finish reseting the password, call **resetPassword()**. This will allow you to change your password.
188
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/qa9ny0gkzlf6y-accept-reset-password for more details.
189
+ * @example
190
+ * ```js
191
+ * const handleResponseAsJson = 'true if the response need to be handled the old way (as json). In the current handling, user will be redirected to success page after successful reset password.';
192
+ * cidaasUserService.resetPassword({
193
+ * password: '123456',
194
+ * confirmPassword: '123456',
195
+ * exchangeId: 'your exchangeId', // which you will get on handle reset password response
196
+ * resetRequestId: 'your resetRequestId' // which you will get on handle reset password response
197
+ * }).then(function (response) {
198
+ * // the response will give you reset password details.
199
+ * }).catch(function(ex) {
200
+ * // your failure code here
201
+ * });
202
+ * ```
203
+ */
204
+ resetPassword(options, handleResponseAsJson, headers) {
205
+ const url = this.config.authority + "/users-srv/resetpassword/accept";
206
+ try {
207
+ if (!handleResponseAsJson) {
208
+ // current handling will redirect and give query parameters
209
+ const form = Helper_1.Helper.createForm(url, options);
210
+ document.body.appendChild(form);
211
+ form.submit();
212
+ }
213
+ else {
214
+ // older cidaas service handling return json object
215
+ return Helper_1.Helper.createHttpPromise(options, url, false, "POST", undefined, headers);
216
+ }
217
+ }
218
+ catch (ex) {
219
+ throw new Helper_1.CustomException(String(ex), 417);
220
+ }
221
+ }
222
+ /**
223
+ * To get the list of existing users in deduplication, call **getDeduplicationDetails()**.
224
+ * @example
225
+ * ```js
226
+ * cidaasUserService.getDeduplicationDetails({
227
+ * track_id: 'your track id'
228
+ * }).then((response) => {
229
+ * // the response will give you deduplication details of users.
230
+ * }).catch((err) => {
231
+ * // your failure code here
232
+ * });
233
+ * ```
234
+ */
235
+ getDeduplicationDetails(options, headers) {
236
+ const _serviceURL = this.config.authority + "/users-srv/deduplication/info/" + options.trackId;
237
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "GET", undefined, headers);
238
+ }
239
+ /**
240
+ * To use the existing users in deduplication, you need to call **deduplicationLogin()**.
241
+ * @example
242
+ * ```js
243
+ * cidaasUserService.deduplicationLogin({
244
+ * sub: 'your sub',
245
+ * requestId: 'request id from deduplication initialisation after register',
246
+ * trackId: 'track id from deduplication initialisation after register'
247
+ * })
248
+ * ```
249
+ */
250
+ deduplicationLogin(options) {
251
+ try {
252
+ const url = this.config.authority + "/users-srv/deduplication/login/redirection?trackId=" + options.trackId + "&requestId=" + options.requestId + "&sub=" + options.sub;
253
+ const form = Helper_1.Helper.createForm(url, {});
193
254
  document.body.appendChild(form);
194
255
  form.submit();
195
256
  }
196
- else {
197
- // older cidaas service handling return json object
198
- return Helper_1.Helper.createHttpPromise(options, url, false, "POST", undefined, headers);
257
+ catch (ex) {
258
+ throw new Helper_1.CustomException(String(ex), 417);
199
259
  }
200
260
  }
201
- catch (ex) {
202
- throw new Helper_1.CustomException(String(ex), 417);
261
+ /**
262
+ * To register new user in deduplication, call **registerDeduplication()**.
263
+ * @example
264
+ * ```js
265
+ * cidaasUserService.registerDeduplication({
266
+ * track_id: 'track id from deduplication initialisation after register',
267
+ * }).then((response) => {
268
+ * // the response will give you new registered deduplication user.
269
+ * }).catch((err) => {
270
+ * // your failure code here
271
+ * });
272
+ * ```
273
+ */
274
+ registerDeduplication(options, headers) {
275
+ const _serviceURL = this.config.authority + "/users-srv/deduplication/register/" + options.trackId;
276
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, undefined, "POST", undefined, headers);
203
277
  }
204
- }
205
- exports.resetPassword = resetPassword;
206
- /**
207
- * To get the list of existing users in deduplication, call **getDeduplicationDetails()**.
208
- * @example
209
- * ```js
210
- * this.cidaas.getDeduplicationDetails({
211
- * track_id: 'your track id'
212
- * }).then((response) => {
213
- * // the response will give you deduplication details of users.
214
- * }).catch((err) => {
215
- * // your failure code here
216
- * });
217
- * ```
218
- */
219
- function getDeduplicationDetails(options, headers) {
220
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/deduplication/info/" + options.trackId;
221
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "GET", undefined, headers);
222
- }
223
- exports.getDeduplicationDetails = getDeduplicationDetails;
224
- /**
225
- * To use the existing users in deduplication, you need to call **deduplicationLogin()**.
226
- * @example
227
- * ```js
228
- * this.cidaas.deduplicationLogin({
229
- * sub: 'your sub',
230
- * requestId: 'request id from deduplication initialisation after register',
231
- * trackId: 'track id from deduplication initialisation after register'
232
- * })
233
- * ```
234
- */
235
- function deduplicationLogin(options) {
236
- try {
237
- const url = window.webAuthSettings.authority + "/users-srv/deduplication/login/redirection?trackId=" + options.trackId + "&requestId=" + options.requestId + "&sub=" + options.sub;
238
- const form = Helper_1.Helper.createForm(url, {});
239
- document.body.appendChild(form);
240
- form.submit();
278
+ /**
279
+ * To change the password, call **changePassword()**. This will allow you to change your password.
280
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/8221883241464-change-password for more details.
281
+ * @example
282
+ * ```js
283
+ * cidaasUserService.changePassword({
284
+ * old_password: 'your old password',
285
+ * new_password: 'your new password',
286
+ * confirm_password: 'your new password',
287
+ * sub: 'your sub',
288
+ * })
289
+ * .then(function () {
290
+ * // your success code
291
+ * }).catch(function (ex) {
292
+ * // your failure code
293
+ * });
294
+ * ```
295
+ */
296
+ changePassword(options, access_token) {
297
+ const _serviceURL = this.config.authority + "/users-srv/changepassword";
298
+ if (access_token) {
299
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", access_token);
300
+ }
301
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
302
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", accessToken);
303
+ });
241
304
  }
242
- catch (ex) {
243
- throw new Helper_1.CustomException(String(ex), 417);
305
+ /**
306
+ * To update the user profile information, call **updateProfile()**.
307
+ * After updating the user profile, the information in user storage won't be automatically updated.
308
+ * To get the latest user profile information, you will need to call **getUserProfile()**.
309
+ * To update the user storage, you will need to call **renewToken()** to generate latest tokens (access token, id token, refresh token) & user informations.
310
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/i3uqnxcpxr19r-update-user-profile for more details.
311
+ * @example
312
+ * ```js
313
+ * cidaasUserService.updateProfile({
314
+ * family_name: 'Doe',
315
+ * given_name: 'John',
316
+ * provider: 'self',
317
+ * acceptlanguage: 'your locale' // optional example: de-de, en-US
318
+ * }, 'your sub' ).then(function () {
319
+ * // the response will give you updated user profile info.
320
+ * }).catch(function (ex) {
321
+ * // your failure code here
322
+ * });
323
+ * ```
324
+ */
325
+ updateProfile(options, sub, access_token) {
326
+ const _serviceURL = this.config.authority + "/users-srv/user/profile/" + sub;
327
+ if (access_token) {
328
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "PUT", access_token);
329
+ }
330
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
331
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "PUT", accessToken);
332
+ });
244
333
  }
245
- }
246
- exports.deduplicationLogin = deduplicationLogin;
247
- /**
248
- * To register new user in deduplication, call **registerDeduplication()**.
249
- * @example
250
- * ```js
251
- * this.cidaas.registerDeduplication({
252
- * track_id: 'track id from deduplication initialisation after register',
253
- * }).then((response) => {
254
- * // the response will give you new registered deduplication user.
255
- * }).catch((err) => {
256
- * // your failure code here
257
- * });
258
- * ```
259
- */
260
- function registerDeduplication(options, headers) {
261
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/deduplication/register/" + options.trackId;
262
- return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, undefined, "POST", undefined, headers);
263
- }
264
- exports.registerDeduplication = registerDeduplication;
265
- /**
266
- * To change the password, call **changePassword()**. This will allow you to change your password.
267
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/8221883241464-change-password for more details.
268
- * @example
269
- * ```js
270
- * cidaas.changePassword({
271
- * old_password: 'your old password',
272
- * new_password: 'your new password',
273
- * confirm_password: 'your new password',
274
- * sub: 'your sub',
275
- * }, 'your access token')
276
- * .then(function () {
277
- * // your success code
278
- * }).catch(function (ex) {
279
- * // your failure code
280
- * });
281
- * ```
282
- */
283
- function changePassword(options, access_token) {
284
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/changepassword";
285
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", access_token);
286
- }
287
- exports.changePassword = changePassword;
288
- /**
289
- * To update the user profile information, call **updateProfile()**.
290
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/i3uqnxcpxr19r-update-user-profile for more details.
291
- * @example
292
- * ```js
293
- * cidaas.updateProfile({
294
- * family_name: 'Doe',
295
- * given_name: 'John',
296
- * provider: 'self',
297
- * acceptlanguage: 'your locale' // optional example: de-de, en-US
298
- * }, 'your access token', 'your sub').then(function () {
299
- * // the response will give you updated user profile info.
300
- * }).catch(function (ex) {
301
- * // your failure code here
302
- * });
303
- * ```
304
- */
305
- function updateProfile(options, access_token, sub) {
306
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/user/profile/" + sub;
307
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "PUT", access_token);
308
- }
309
- exports.updateProfile = updateProfile;
310
- /**
311
- * To initiate account linking, call **initiateLinkAccount()**.
312
- * @example
313
- * ```js
314
- * const options = {
315
- * master_sub: 'sub of the user who initiates the user link',
316
- * user_name_to_link: 'username of the user which should get linked',
317
- * user_name_type: 'type of user name to link. E.g. email'
318
- * }
319
- * const access_token = 'your access token'
320
- * this.cidaas.initiateLinkAccount(options, access_token).then((response) => {
321
- * // your success code
322
- * }).catch((err) => {
323
- * // your failure code here
324
- * });
325
- * ```
326
- */
327
- function initiateLinkAccount(options, access_token) {
328
- options.user_name_type = 'email';
329
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/user/link/initiate";
330
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", access_token);
331
- }
332
- exports.initiateLinkAccount = initiateLinkAccount;
333
- /**
334
- * To complete account linking, call **completeLinkAccount()**.
335
- * @example
336
- * ```js
337
- * const options = {
338
- * code: 'code which is sent to account to be linked',
339
- * link_request_id: 'comes from initiateLinkAccount'
340
- * }
341
- * const access_token = 'your access token'
342
- * this.cidaas.completeLinkAccount(options, access_token).then((response) => {
343
- * // your success code
344
- * }).catch((err) => {
345
- * // your failure code here
346
- * });
347
- * ```
348
- */
349
- function completeLinkAccount(options, access_token) {
350
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/user/link/complete";
351
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", access_token);
352
- }
353
- exports.completeLinkAccount = completeLinkAccount;
354
- /**
355
- * To get all the linked accounts, call **getLinkedUsers()**.
356
- * @example
357
- * ```js
358
- * const acccess_token= 'your access token';
359
- * const sub = 'your sub';
360
- *
361
- * cidaas.getLinkedUsers(access_token, sub)
362
- * .then(function (response) {
363
- * // type your code here
364
- * })
365
- * .catch(function (ex) {
366
- * // your failure code here
367
- * });
368
- * ```
369
- */
370
- function getLinkedUsers(access_token, sub) {
371
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/userinfo/social/" + sub;
372
- return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", access_token);
373
- }
374
- exports.getLinkedUsers = getLinkedUsers;
375
- /**
376
- * To unlink an account for a user, call **unlinkAccount()**.
377
- * @example
378
- * ```js
379
- * const acccess_token= "your access token";
380
- * const identityId = "comes from getLinkedUsers";
381
- *
382
- * cidaas.unlinkAccount(access_token, identityId)
383
- * .then(function (response) {
384
- * // type your code here
385
- * })
386
- * .catch(function (ex) {
387
- * // your failure code here
388
- * });
389
- * ```
390
- */
391
- function unlinkAccount(access_token, identityId) {
392
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/user/unlink/" + identityId;
393
- return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "POST", access_token);
394
- }
395
- exports.unlinkAccount = unlinkAccount;
396
- /**
397
- * To delete the user account directly in the application, call **deleteUserAccount()**.
398
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/x133xdifl1sx9-schedule-user-deletion for more details.
399
- * @example
400
- * ```js
401
- * options = {
402
- * access_token: "your access token",
403
- * sub: "your sub"
404
- * }
405
- *
406
- * cidaas.deleteUserAccount(options).then(function (response) {
407
- * // your success code
408
- * }).catch(function(ex) {
409
- * // your failure code here
410
- * });
411
- * ```
412
- */
413
- function deleteUserAccount(options) {
414
- const _serviceURL = window.webAuthSettings.authority + "/users-srv/user/unregister/scheduler/schedule/" + options.sub;
415
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, undefined, "POST", options.access_token);
416
- }
417
- exports.deleteUserAccount = deleteUserAccount;
418
- /**
419
- * To check if user exists, call **userCheckExists()**.
420
- * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/4yh82qism78xf-find-user-by-identifier for more details.
421
- * @example
422
- * options = {
423
- * requestId: "your request id",
424
- * email: "your email"
425
- * }
426
- *
427
- * cidaas.userCheckExists(options).then(function (response) {
428
- * // your success code
429
- * }).catch(function(ex) {
430
- * // your failure code here
431
- * });
432
- * ```
433
- */
434
- function userCheckExists(options, headers) {
435
- let queryParameter = '';
436
- if (options.webfinger || options.rememberMe) {
437
- queryParameter += '?';
438
- if (options.webfinger) {
439
- queryParameter += 'webfinger=' + options.webfinger;
440
- if (options.rememberMe) {
441
- queryParameter += '&rememberMe=' + options.rememberMe;
334
+ /**
335
+ * To initiate account linking, call **initiateLinkAccount()**.
336
+ * @example
337
+ * ```js
338
+ * const options = {
339
+ * master_sub: 'sub of the user who initiates the user link',
340
+ * user_name_to_link: 'username of the user which should get linked',
341
+ * user_name_type: 'type of user name to link. E.g. email'
342
+ * }
343
+ * cidaasUserService.initiateLinkAccount(options).then((response) => {
344
+ * // your success code
345
+ * }).catch((err) => {
346
+ * // your failure code here
347
+ * });
348
+ * ```
349
+ */
350
+ initiateLinkAccount(options, access_token) {
351
+ options.user_name_type = 'email';
352
+ const _serviceURL = this.config.authority + "/users-srv/user/link/initiate";
353
+ if (access_token) {
354
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", access_token);
355
+ }
356
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
357
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", accessToken);
358
+ });
359
+ }
360
+ /**
361
+ * To complete account linking, call **completeLinkAccount()**.
362
+ * @example
363
+ * ```js
364
+ * const options = {
365
+ * code: 'code which is sent to account to be linked',
366
+ * link_request_id: 'comes from initiateLinkAccount'
367
+ * }
368
+ * cidaasUserService.completeLinkAccount(options).then((response) => {
369
+ * // your success code
370
+ * }).catch((err) => {
371
+ * // your failure code here
372
+ * });
373
+ * ```
374
+ */
375
+ completeLinkAccount(options, access_token) {
376
+ const _serviceURL = this.config.authority + "/users-srv/user/link/complete";
377
+ if (access_token) {
378
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", access_token);
379
+ }
380
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
381
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", accessToken);
382
+ });
383
+ }
384
+ /**
385
+ * To get all the linked accounts, call **getLinkedUsers()**.
386
+ * @example
387
+ * ```js
388
+ * const sub = 'your sub';
389
+ *
390
+ * cidaasUserService.getLinkedUsers(sub)
391
+ * .then(function (response) {
392
+ * // type your code here
393
+ * })
394
+ * .catch(function (ex) {
395
+ * // your failure code here
396
+ * });
397
+ * ```
398
+ */
399
+ getLinkedUsers(sub, access_token) {
400
+ const _serviceURL = this.config.authority + "/users-srv/userinfo/social/" + sub;
401
+ if (access_token) {
402
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", access_token);
403
+ }
404
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
405
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", accessToken);
406
+ });
407
+ }
408
+ /**
409
+ * To unlink an account for a user, call **unlinkAccount()**.
410
+ * @example
411
+ * ```js
412
+ * const identityId = "comes from getLinkedUsers";
413
+ *
414
+ * cidaasUserService.unlinkAccount(undefined, identityId)
415
+ * .then(function (response) {
416
+ * // type your code here
417
+ * })
418
+ * .catch(function (ex) {
419
+ * // your failure code here
420
+ * });
421
+ * ```
422
+ */
423
+ unlinkAccount(access_token, identityId) {
424
+ if (!identityId) {
425
+ throw new Helper_1.CustomException("identityId cannot be empty", 417);
426
+ }
427
+ const _serviceURL = this.config.authority + "/users-srv/user/unlink/" + identityId;
428
+ if (access_token) {
429
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "POST", access_token);
430
+ }
431
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
432
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "POST", accessToken);
433
+ });
434
+ }
435
+ /**
436
+ * To delete the user account directly in the application, call **deleteUserAccount()**.
437
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/x133xdifl1sx9-schedule-user-deletion for more details.
438
+ * @example
439
+ * ```js
440
+ * options = {
441
+ * sub: "your sub"
442
+ * }
443
+ *
444
+ * cidaasUserService.deleteUserAccount(options).then(function (response) {
445
+ * // your success code
446
+ * }).catch(function(ex) {
447
+ * // your failure code here
448
+ * });
449
+ * ```
450
+ */
451
+ deleteUserAccount(options) {
452
+ const _serviceURL = this.config.authority + "/users-srv/user/unregister/scheduler/schedule/" + options.sub;
453
+ if (options.access_token) {
454
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, undefined, "POST", options.access_token);
455
+ }
456
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
457
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, undefined, "POST", accessToken);
458
+ });
459
+ }
460
+ /**
461
+ * To check if user exists, call **userCheckExists()**.
462
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/4yh82qism78xf-find-user-by-identifier for more details.
463
+ * @example
464
+ * options = {
465
+ * requestId: "your request id",
466
+ * email: "your email"
467
+ * }
468
+ *
469
+ * cidaasUserService.userCheckExists(options).then(function (response) {
470
+ * // your success code
471
+ * }).catch(function(ex) {
472
+ * // your failure code here
473
+ * });
474
+ * ```
475
+ */
476
+ userCheckExists(options, headers) {
477
+ let queryParameter = '';
478
+ if (options.webfinger || options.rememberMe) {
479
+ queryParameter += '?';
480
+ if (options.webfinger) {
481
+ queryParameter += 'webfinger=' + options.webfinger;
482
+ if (options.rememberMe) {
483
+ queryParameter += '&rememberMe=' + options.rememberMe;
484
+ }
485
+ }
486
+ else if (options.rememberMe) {
487
+ queryParameter += 'rememberMe=' + options.rememberMe;
442
488
  }
443
489
  }
444
- else if (options.rememberMe) {
445
- queryParameter += 'rememberMe=' + options.rememberMe;
490
+ const _serviceURL = this.config.authority + "/useractions-srv/userexistence/" + options.requestId + queryParameter;
491
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, undefined, "POST", undefined, headers);
492
+ }
493
+ /**
494
+ * To get user activities, call **getUserActivities()**.
495
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/346141453781e-get-user-activities for more details.
496
+ * @example
497
+ * ```js
498
+ * const options = {
499
+ * sub: 'your sub',
500
+ * dateFilter: {
501
+ * from_date: 'date in UTC format',
502
+ * to:date: 'date in UTC format'
503
+ * }
504
+ * };
505
+ * cidaasUserService.getUserActivities(options).then(function (resp) {
506
+ * // your success code
507
+ * }).catch(function(ex) {
508
+ * // your failure code
509
+ * });
510
+ * ```
511
+ */
512
+ getUserActivities(options, access_token) {
513
+ const serviceURL = this.config.authority + '/activity-streams-srv/user-activities';
514
+ if (access_token) {
515
+ return Helper_1.Helper.createHttpPromise(options, serviceURL, false, 'POST', access_token);
516
+ }
517
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
518
+ return Helper_1.Helper.createHttpPromise(options, serviceURL, false, 'POST', accessToken);
519
+ });
520
+ }
521
+ /**
522
+ * To change profile image, call **updateProfileImage()**.
523
+ * @example
524
+ * ```js
525
+ * const options = {
526
+ * image_key: 'id for your image e.g. user sub',
527
+ * photo: yourImageFile,
528
+ * filename: 'name of your image file'
529
+ * };
530
+ * cidaasUserService.updateProfileImage(options).then(function (resp) {
531
+ * // your success code
532
+ * }).catch(function(ex) {
533
+ * // your failure code
534
+ * });
535
+ * ```
536
+ */
537
+ updateProfileImage(options, access_token) {
538
+ const serviceURL = this.config.authority + "/image-srv/profile/upload";
539
+ const form = document.createElement('form');
540
+ form.action = serviceURL;
541
+ form.method = 'POST';
542
+ const image_key = document.createElement('input');
543
+ image_key.setAttribute('type', 'hidden');
544
+ image_key.setAttribute('name', 'image_key');
545
+ form.appendChild(image_key);
546
+ const photo = document.createElement('input');
547
+ photo.setAttribute('type', 'file');
548
+ photo.setAttribute('hidden', 'true');
549
+ photo.setAttribute("name", "photo");
550
+ form.appendChild(photo);
551
+ const formdata = new FormData(form);
552
+ formdata.set('image_key', options.image_key);
553
+ formdata.set('photo', options.photo, options.filename);
554
+ if (access_token) {
555
+ return Helper_1.Helper.createHttpPromise(options, serviceURL, undefined, 'POST', access_token, null, formdata);
446
556
  }
557
+ return Helper_1.Helper.getAccessTokenFromUserStorage(this.userManager).then((accessToken) => {
558
+ return Helper_1.Helper.createHttpPromise(options, serviceURL, undefined, 'POST', accessToken, null, formdata);
559
+ });
560
+ }
561
+ /**
562
+ * To run predefined action after enrollment, call userActionOnEnrollment()
563
+ * @param options
564
+ * @param trackId
565
+ * @example
566
+ * ```js
567
+ * const options = {
568
+ * action: 'predefined action'
569
+ * };
570
+ * cidaasUserService.userActionOnEnrollment(options, 'trackId');
571
+ */
572
+ userActionOnEnrollment(options, trackId) {
573
+ const serviceURL = this.config.authority + '/auth-actions-srv/validation/' + trackId;
574
+ return Helper_1.Helper.createHttpPromise(options, serviceURL, false, 'POST');
447
575
  }
448
- const _serviceURL = window.webAuthSettings.authority + "/useractions-srv/userexistence/" + options.requestId + queryParameter;
449
- return Helper_1.Helper.createHttpPromise(options, _serviceURL, undefined, "POST", undefined, headers);
450
576
  }
451
- exports.userCheckExists = userCheckExists;
577
+ exports.UserService = UserService;