cidaas-javascript-sdk 3.1.5 → 4.0.1

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.
@@ -2,71 +2,134 @@
2
2
  exports.__esModule = true;
3
3
  exports.ConsentService = void 0;
4
4
  var Helper_1 = require("./Helper");
5
+ /**
6
+ * Consent Management
7
+ * For the first time login, the user needs to accept the terms and conditions.
8
+ */
5
9
  var ConsentService;
6
10
  (function (ConsentService) {
7
11
  /**
8
- * get user consent details
9
- * @param options
10
- * @returns
11
- */
12
- function getConsentDetailsV2(options) {
12
+ * To get consent details , call **getConsentDetails()**.
13
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/858fbeb51c62b-find-consent-info for more details.
14
+ * @example
15
+ * ```js
16
+ * this.cidaas.getConsentDetails({
17
+ * consent_id: 'consent id',
18
+ * consent_version_id: 'consent version id',
19
+ * sub: 'masked sub'
20
+ * })
21
+ * .then(function (response) {
22
+ * // type your code here
23
+ * })
24
+ * .catch(function (ex) {
25
+ * // your failure code here
26
+ * });
27
+ * ```
28
+ */
29
+ function getConsentDetails(options) {
13
30
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/usage/public/info";
14
- return Helper_1.Helper.createPostPromise(options, _serviceURL, false, "POST");
31
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST");
15
32
  }
16
- ConsentService.getConsentDetailsV2 = getConsentDetailsV2;
33
+ ConsentService.getConsentDetails = getConsentDetails;
17
34
  ;
18
35
  /**
19
- * accept constn v2
20
- * @param options
21
- * @returns
36
+ * To accept consent, call **acceptConsent()**.
37
+ * @example
38
+ * ```js
39
+ * this.cidaas.acceptConsent({
40
+ * client_id: 'your client id',
41
+ * consent_id: 'consent id',
42
+ * consent_version: 'consent version id',
43
+ * sub: 'masked sub'
44
+ * }).then((response) => {
45
+ * // the response will give you details of accepted consent.
46
+ * }).catch((err) => {
47
+ * // your failure code here
48
+ * });
49
+ * ```
22
50
  */
23
- function acceptConsentV2(options) {
51
+ function acceptConsent(options) {
24
52
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/usage/accept";
25
- return Helper_1.Helper.createPostPromise(options, _serviceURL, false, "POST");
53
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST");
26
54
  }
27
- ConsentService.acceptConsentV2 = acceptConsentV2;
55
+ ConsentService.acceptConsent = acceptConsent;
28
56
  ;
29
57
  /**
30
- * get scope consent version details
31
- * @param options
32
- * @returns
58
+ * To get version details of consent, call **getConsentVersionDetails()**.
59
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/7e24ac2113315-get-consent-version-details for more details.
60
+ * @example
61
+ * ```js
62
+ * this.cidaas.getConsentVersionDetails({
63
+ * consentid: 'your consent id',
64
+ * locale: 'browser accept language or custom language',
65
+ * access_token: 'your access token',
66
+ * }).then((response) => {
67
+ * // type your code here
68
+ * }).catch((err) => {
69
+ * // your failure code here
70
+ * });
71
+ * ```
33
72
  */
34
- function getScopeConsentVersionDetailsV2(options) {
35
- var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/versions/details/" + options.scopeid + "?locale=" + options.locale;
36
- return Helper_1.Helper.createPostPromise(undefined, _serviceURL, false, "GET", options.access_token);
73
+ function getConsentVersionDetails(options) {
74
+ var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/v2/consent/versions/details/" + options.consentid + "?locale=" + options.locale;
75
+ return Helper_1.Helper.createHttpPromise(undefined, _serviceURL, false, "GET", options.access_token);
37
76
  }
38
- ConsentService.getScopeConsentVersionDetailsV2 = getScopeConsentVersionDetailsV2;
77
+ ConsentService.getConsentVersionDetails = getConsentVersionDetails;
39
78
  ;
40
79
  /**
41
- * accept scope Consent
42
- * @param options
43
- * @returns
80
+ * To accept scope consent, call **acceptScopeConsent()**.
81
+ * @example
82
+ * ```js
83
+ * this.cidaas.acceptScopeConsent({
84
+ * client_id: 'your client id',
85
+ * sub: 'masked sub',
86
+ * scopes: [your scope consents]
87
+ * });
88
+ * ```
44
89
  */
45
90
  function acceptScopeConsent(options) {
46
91
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/scope/accept";
47
- return Helper_1.Helper.createPostPromise(options, _serviceURL, false, "POST");
92
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST");
48
93
  }
49
94
  ConsentService.acceptScopeConsent = acceptScopeConsent;
50
95
  ;
51
96
  /**
52
- * accept claim Consent
53
- * @param options
54
- * @returns
97
+ * To accept claim consent, call **acceptClaimConsent()**.
98
+ * @example
99
+ * ```js
100
+ * this.cidaas.acceptClaimConsent({
101
+ * client_id: 'your client id',
102
+ * sub: 'masked sub',
103
+ * accepted_claims: [your claim consents]
104
+ * });
105
+ * ```
55
106
  */
56
107
  function acceptClaimConsent(options) {
57
108
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/claim/accept";
58
- return Helper_1.Helper.createPostPromise(options, _serviceURL, false, "POST");
109
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST");
59
110
  }
60
111
  ConsentService.acceptClaimConsent = acceptClaimConsent;
61
112
  ;
62
113
  /**
63
- * revoke claim Consent
64
- * @param options
65
- * @returns
114
+ * To revoke claim consent, call **revokeClaimConsent()**.
115
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/9ae62e98842fe-revoke-user-consent-claim for more details.
116
+ * @example
117
+ * ```js
118
+ * this.cidaas.revokeClaimConsent({
119
+ * access_token: 'your access token',
120
+ * client_id: 'your client id',
121
+ * sub: 'masked sub'
122
+ * revoked_claims: [your claim consents]
123
+ * }).then((response) => {
124
+ * // the response will give you revoked claim consent.
125
+ * }).catch((err) => {
126
+ * // your failure code here
127
+ * });
128
+ * ```
66
129
  */
67
130
  function revokeClaimConsent(options) {
68
131
  var _serviceURL = window.webAuthSettings.authority + "/consent-management-srv/consent/claim/revoke";
69
- return Helper_1.Helper.createPostPromise(options, _serviceURL, false, "POST");
132
+ return Helper_1.Helper.createHttpPromise(options, _serviceURL, false, "POST", options.access_token);
70
133
  }
71
134
  ConsentService.revokeClaimConsent = revokeClaimConsent;
72
135
  ;
@@ -1,4 +1,3 @@
1
- import { UserManagerSettings } from "oidc-client-ts";
2
1
  export interface AcceptResetPasswordEntity {
3
2
  resetRequestId: string;
4
3
  exchangeId: string;
@@ -93,7 +92,6 @@ export interface ChangePasswordEntity {
93
92
  old_password: string;
94
93
  new_password: string;
95
94
  confirm_password: string;
96
- accessToken: string;
97
95
  }
98
96
  export interface FidoSetupEntity {
99
97
  track_id: string;
@@ -191,37 +189,22 @@ export interface IEnrollVerificationSetupRequestEntity {
191
189
  verification_type: string;
192
190
  }
193
191
  export interface IInitVerificationAuthenticationRequestEntity {
194
- q: string;
195
- sub: string;
196
- email: string;
197
- mobile_number: string;
198
- username: string;
199
- client_id: string;
200
- request_id: string;
201
192
  usage_type: string;
202
- medium_id: string;
203
- single_factor_auth: boolean;
204
- push_id: string;
205
- device_id: string;
206
- single_factor_sub_ref: string;
207
- verification_types: string[];
208
- device_fp: string;
209
- provider: string;
210
193
  processingType: string;
211
- trackId: string;
194
+ q?: string;
195
+ sub?: string;
196
+ email?: string;
197
+ mobile_number?: string;
198
+ username?: string;
199
+ client_id?: string;
200
+ request_id: string;
212
201
  type?: string;
213
- verification_type?: string;
214
- }
215
- export interface IMobileEntity {
216
- given_phone: string;
217
- phone: string;
218
- country: string;
219
- dail_code: string;
220
- carrier_type: string;
221
- carrier_name: string;
222
- national_format: string;
223
- international_format: string;
224
- E164_format: string;
202
+ medium_id?: string;
203
+ push_id?: string;
204
+ device_id?: string;
205
+ single_factor_auth?: boolean;
206
+ single_factor_sub_ref?: string;
207
+ trackId?: string;
225
208
  }
226
209
  export interface ISuggestedMFAActionConfig {
227
210
  sub?: string;
@@ -269,12 +252,6 @@ export interface IUserEntity {
269
252
  trackId: string;
270
253
  need_reset_password: boolean;
271
254
  }
272
- export interface IUserGroupMap {
273
- sub: string;
274
- groupId: string;
275
- roles: string[];
276
- appendRole: boolean;
277
- }
278
255
  export interface IUserLinkEntity {
279
256
  master_sub: string;
280
257
  user_name_type: string;
@@ -527,7 +504,13 @@ export interface IChangePasswordEntity {
527
504
  loginSettingsId: string;
528
505
  client_id?: string;
529
506
  }
530
- export interface ICidaasSDKSettings extends UserManagerSettings {
531
- mode?: string;
532
- cidaas_version?: number;
507
+ export interface IUserActivityPayloadEntity {
508
+ sub: string;
509
+ size?: number;
510
+ from?: number;
511
+ descending?: boolean;
512
+ dateFilter: {
513
+ from_date: string;
514
+ to_date: string;
515
+ };
533
516
  }
@@ -15,7 +15,7 @@ export declare class Helper {
15
15
  * @param headers??
16
16
  * @returns
17
17
  */
18
- static createPostPromise(options: any, serviceurl: string, errorResolver: boolean, method: string, access_token?: string, headers?: any): Promise<unknown>;
18
+ static createHttpPromise(options: any, serviceurl: string, errorResolver: boolean, method: string, access_token?: string, headers?: any, formPayload?: FormData): Promise<unknown>;
19
19
  }
20
20
  export declare class CustomException {
21
21
  errorMessage: string;
@@ -35,7 +35,7 @@ var Helper = /** @class */ (function () {
35
35
  * @param headers??
36
36
  * @returns
37
37
  */
38
- Helper.createPostPromise = function (options, serviceurl, errorResolver, method, access_token, headers) {
38
+ Helper.createHttpPromise = function (options, serviceurl, errorResolver, method, access_token, headers, formPayload) {
39
39
  return new Promise(function (resolve, reject) {
40
40
  try {
41
41
  var http = new XMLHttpRequest();
@@ -50,7 +50,9 @@ var Helper = /** @class */ (function () {
50
50
  }
51
51
  };
52
52
  http.open(method, serviceurl, true);
53
- http.setRequestHeader("Content-type", "application/json");
53
+ if (!formPayload) {
54
+ http.setRequestHeader("Content-type", "application/json");
55
+ }
54
56
  if (headers) {
55
57
  for (var key in headers) {
56
58
  if (headers.hasOwnProperty(key)) {
@@ -61,10 +63,23 @@ var Helper = /** @class */ (function () {
61
63
  if (access_token) {
62
64
  http.setRequestHeader("Authorization", "Bearer ".concat(access_token));
63
65
  }
64
- if (window.localeSettings) {
65
- http.setRequestHeader("accept-language", window.localeSettings);
66
+ var acceptlanguage = void 0;
67
+ if (headers === null || headers === void 0 ? void 0 : headers.acceptlanguage) {
68
+ acceptlanguage = headers.acceptlanguage;
69
+ }
70
+ else if (options === null || options === void 0 ? void 0 : options.acceptlanguage) {
71
+ acceptlanguage = options.acceptlanguage;
72
+ }
73
+ else {
74
+ acceptlanguage = window === null || window === void 0 ? void 0 : window.localeSettings;
75
+ }
76
+ if (acceptlanguage) {
77
+ http.setRequestHeader("accept-language", acceptlanguage);
78
+ }
79
+ if (formPayload) {
80
+ http.send(formPayload);
66
81
  }
67
- if (options) {
82
+ else if (options) {
68
83
  http.send(JSON.stringify(options));
69
84
  }
70
85
  else {
@@ -0,0 +1,7 @@
1
+ export declare class JwtHelper {
2
+ static decodeTokenHeader(token: string): any;
3
+ static decodeToken(token: string): any;
4
+ static urlBase64Decode(str: string): string;
5
+ static b64DecodeUnicode(str: any): string;
6
+ static b64decode(str: any): any;
7
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.JwtHelper = void 0;
4
+ var JwtHelper = /** @class */ (function () {
5
+ function JwtHelper() {
6
+ }
7
+ JwtHelper.decodeTokenHeader = function (token) {
8
+ if (token === null) {
9
+ return null;
10
+ }
11
+ var parts = token.split('.');
12
+ if (parts.length !== 3) {
13
+ throw new Error('The inspected token doesn\'t appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.');
14
+ }
15
+ var decoded = this.urlBase64Decode(parts[0]);
16
+ if (!decoded) {
17
+ throw new Error('Cannot decode the token.');
18
+ }
19
+ return JSON.parse(decoded);
20
+ };
21
+ JwtHelper.decodeToken = function (token) {
22
+ if (token === null) {
23
+ return null;
24
+ }
25
+ var parts = token.split('.');
26
+ if (parts.length !== 3) {
27
+ throw new Error('The inspected token doesn\'t appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more.');
28
+ }
29
+ var decoded = this.urlBase64Decode(parts[1]);
30
+ if (!decoded) {
31
+ throw new Error('Cannot decode the token.');
32
+ }
33
+ return JSON.parse(decoded);
34
+ };
35
+ JwtHelper.urlBase64Decode = function (str) {
36
+ var output = str.replace(/-/g, '+').replace(/_/g, '/');
37
+ switch (output.length % 4) {
38
+ case 0: {
39
+ break;
40
+ }
41
+ case 2: {
42
+ output += '==';
43
+ break;
44
+ }
45
+ case 3: {
46
+ output += '=';
47
+ break;
48
+ }
49
+ default: {
50
+ throw new Error('Illegal base64url string!');
51
+ }
52
+ }
53
+ return this.b64DecodeUnicode(output);
54
+ };
55
+ JwtHelper.b64DecodeUnicode = function (str) {
56
+ return decodeURIComponent(Array.prototype.map
57
+ .call(this.b64decode(str), function (c) {
58
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
59
+ })
60
+ .join(''));
61
+ };
62
+ // credits for decoder goes to https://github.com/atk
63
+ JwtHelper.b64decode = function (str) {
64
+ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
65
+ var output = '';
66
+ str = String(str).replace(/=+$/, '');
67
+ if (str.length % 4 === 1) {
68
+ throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");
69
+ }
70
+ for (
71
+ // initialize result and counters
72
+ var bc = 0, bs = void 0, buffer = void 0, idx = 0;
73
+ // get next character
74
+ (buffer = str.charAt(idx++));
75
+ // character found in table? initialize bit storage and add its ascii value;
76
+ ~buffer &&
77
+ ((bs = bc % 4 ? bs * 64 + buffer : buffer),
78
+ // and if not first of each 4 characters,
79
+ // convert the first 8 bits to one ascii character
80
+ bc++ % 4)
81
+ ? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6))))
82
+ : 0) {
83
+ // try to find character in table (0-63, not found => -1)
84
+ buffer = chars.indexOf(buffer);
85
+ }
86
+ return output;
87
+ };
88
+ return JwtHelper;
89
+ }());
90
+ exports.JwtHelper = JwtHelper;
@@ -1,20 +1,29 @@
1
- import { IUserEntity, LoginFormRequestEntity, PhysicalVerificationLoginRequest, LoginFormRequestAsyncEntity, IChangePasswordEntity } from "./Entities";
1
+ import { IUserEntity, LoginFormRequestEntity, PhysicalVerificationLoginRequest, IChangePasswordEntity } from "./Entities";
2
2
  export declare namespace LoginService {
3
3
  /**
4
- * login with username and password
5
- * @param options
6
- */
4
+ * To login with your credentials, call **loginWithCredentials()**. After successful login, this will redirect you to the redirect_url that you mentioned earlier while initialising the sdk.
5
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/5gphdk6vapp56-classic-login#call-login-api for more details.
6
+ * @example
7
+ * ```js
8
+ * cidaas.loginWithCredentials({
9
+ * username: 'xxxx@gmail.com',
10
+ * username_type: 'email',
11
+ * password: '123456',
12
+ * requestId: 'your requestId',
13
+ * });
14
+ * ```
15
+ */
7
16
  function loginWithCredentials(options: LoginFormRequestEntity): void;
8
17
  /**
9
- * login with username and password and return response
10
- * @param options
11
- * @returns
12
- */
13
- function loginWithCredentialsAsynFn(options: LoginFormRequestAsyncEntity): Promise<Response>;
14
- /**
15
- * login with social
16
- * @param options
17
- * @param queryParams
18
+ * To login with social providers, call **loginWithSocial()**. This will redirect you to the facebook login page.
19
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/9mi5uqxhqlsm5-social-login#call-social-login-api for more details
20
+ * @example
21
+ * ```js
22
+ * cidaas.loginWithSocial({
23
+ * provider: 'facebook',
24
+ * requestId: 'your requestId',
25
+ * });
26
+ * ```
18
27
  */
19
28
  function loginWithSocial(options: {
20
29
  provider: string;
@@ -24,9 +33,19 @@ export declare namespace LoginService {
24
33
  device_fp: string;
25
34
  }): void;
26
35
  /**
27
- * with social
28
- * @param options
29
- * @param queryParams
36
+ * To register with social providers, call **registerWithSocial()**. This will redirect you to the facebook login page.
37
+ * @example
38
+ * Note: giving the queryParams is not required.
39
+ * ```js
40
+ * queryParams = {
41
+ * dc: dc,
42
+ * device_fp: device_fp
43
+ *
44
+ * cidaas.registerWithSocial({
45
+ * provider: 'facebook',
46
+ * requestId: 'your requestId',
47
+ * }, queryParams);
48
+ * ```
30
49
  */
31
50
  function registerWithSocial(options: {
32
51
  provider: string;
@@ -36,68 +55,90 @@ export declare namespace LoginService {
36
55
  device_fp: string;
37
56
  }): void;
38
57
  /**
39
- * passwordless login
40
- * @param options
58
+ * To authenticate without using password, call **passwordlessLogin()**.
59
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/k1lwsraxk0rjc-login-passwordless-request for more details.
60
+ * @example
61
+ * ```js
62
+ * cidaas.passwordlessLogin({
63
+ * requestId: 'your requestId',
64
+ * sub: 'your user sub',
65
+ * statusId: 'status id from authenticateMFA()'
66
+ * verificationType: 'your verificationType. e.g. email'
67
+ * });
68
+ * ```
41
69
  */
42
70
  function passwordlessLogin(options: PhysicalVerificationLoginRequest): void;
43
71
  /**
44
- * scope consent continue after token pre check
45
- * @param options
46
- */
47
- function scopeConsentContinue(options: {
48
- track_id: string;
49
- }): void;
50
- /**
51
- * claim consent continue login
52
- * @param options
53
- */
54
- function claimConsentContinue(options: {
55
- track_id: string;
56
- }): void;
57
- /**
58
- * consent continue login
59
- * @param options
72
+ * To continue after Consent acceptance, call **consentContinue()**.
73
+ * @example
74
+ * ```js
75
+ * cidaas.consentContinue({
76
+ * name: 'your consent name',
77
+ * version: 'your consent version',
78
+ * client_id: 'your client id',
79
+ * track_id: 'your track id',
80
+ * sub: 'your sub'
81
+ * });
82
+ * ```
60
83
  */
61
84
  function consentContinue(options: {
62
- client_id: string;
63
- consent_refs: string[];
64
- sub: string;
65
- scopes: string[];
66
- matcher: any;
67
85
  track_id: string;
68
86
  }): void;
69
87
  /**
70
- * mfa continue login
71
- * @param options
88
+ * To continue after MFA completion, call **mfaContinue()**.
89
+ * @example
90
+ * ```js
91
+ * cidaas.mfaContinue({
92
+ * trackingCode: 'your tracking Code',
93
+ * track_id: 'your track id',
94
+ * sub: 'your sub',
95
+ * requestId: 'your request id'
96
+ * });
97
+ * ```
72
98
  */
73
99
  function mfaContinue(options: PhysicalVerificationLoginRequest & {
74
100
  track_id: string;
75
101
  }): void;
76
102
  /**
77
- * change password continue
78
- * @param options
103
+ * to handle changing password by first login attempt after registration, call **firstTimeChangePassword()**.
104
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/fd8f478d96f58-continue-authentication-flow-after-prechecks for more details.
105
+ * @example
106
+ * ```js
107
+ * cidaas.firstTimeChangePassword({
108
+ * sub: 'your sub',
109
+ * old_password: 'your old password',
110
+ * new_password: 'your new password',
111
+ * confirm_password: 'your new password',
112
+ * loginSettingsId: 'loginSettingsId'
113
+ * });
114
+ * ```
79
115
  */
80
116
  function firstTimeChangePassword(options: IChangePasswordEntity): void;
81
117
  /**
82
- * progressiveRegistration
83
- * @param options
84
- * @param headers
85
- * @returns
118
+ * For progressive registration, call **progressiveRegistration()**. While logging in If the API returns 417 with the error message MissingRequiredFields, call the **getMissingFields** to get the list of missing fileds and proceed with progressive registration. In the sample request only the required fields are added, however you must provide the missing fields along with the required fields.
119
+ * Please refer to the api document https://docs.cidaas.com/docs/cidaas-iam/l7sknp2pytryr-progressive-registration for more details.
120
+ * @example
121
+ * ```js
122
+ * const options = {
123
+ * sub: 'your sub',
124
+ * }
125
+ * const headers = {
126
+ * trackId: 'the track id received while logging in',
127
+ * requestId: 'request id of the session',
128
+ * acceptlanguage: 'your locale/browser locale (OPTIONAL)',
129
+ * }
130
+ * cidaas.progressiveRegistration(options, headers)
131
+ * .then(function(response) {
132
+ * // type your code here
133
+ * })
134
+ * .catch(function (ex) {
135
+ * // your failure code here
136
+ * });
137
+ * ```
86
138
  */
87
139
  function progressiveRegistration(options: IUserEntity, headers: {
88
140
  requestId: string;
89
141
  trackId: string;
90
142
  acceptlanguage: string;
91
143
  }): Promise<unknown>;
92
- /**
93
- * loginAfterRegister
94
- * @param options
95
- */
96
- function loginAfterRegister(options: {
97
- device_id?: string;
98
- dc?: string;
99
- rememberMe?: boolean;
100
- trackId?: string;
101
- device_fp?: string;
102
- }): void;
103
144
  }