@arv-bedrock/auth-sso 0.3.0 → 0.3.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.
- package/README.md +215 -4
- package/dist/cjs/auth.js +27 -5
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/types/auth.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +6 -1
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/utils/_fetch.d.ts +8 -0
- package/dist/cjs/types/utils/_fetch.d.ts.map +1 -1
- package/dist/cjs/types/utils/constant.d.ts +6 -1
- package/dist/cjs/types/utils/constant.d.ts.map +1 -1
- package/dist/cjs/types/utils/types.d.ts +6 -1
- package/dist/cjs/types/utils/types.d.ts.map +1 -1
- package/dist/cjs/utils/_fetch.js +46 -10
- package/dist/cjs/utils/constant.js +7 -1
- package/dist/esm/auth.js +4 -2
- package/dist/esm/index.mjs +7 -1
- package/dist/esm/types/auth.d.ts.map +1 -1
- package/dist/esm/types/index.d.ts +6 -1
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/utils/_fetch.d.ts +8 -0
- package/dist/esm/types/utils/_fetch.d.ts.map +1 -1
- package/dist/esm/types/utils/constant.d.ts +6 -1
- package/dist/esm/types/utils/constant.d.ts.map +1 -1
- package/dist/esm/types/utils/types.d.ts +6 -1
- package/dist/esm/types/utils/types.d.ts.map +1 -1
- package/dist/esm/utils/_fetch.js +43 -10
- package/dist/esm/utils/constant.js +6 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,216 @@
|
|
|
1
|
-
|
|
1
|
+
# Bedrock Auth Library
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
`@arv-bedrock/auth-sso` is a JavaScript/TypeScript library designed to provide an easy-to-use interface for managing user authentication and account-related functionalities. This library integrates seamlessly with the Bedrock authentication system to streamline your app's security needs.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install the library via npm:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @arv-bedrock/auth-sso
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
### Importing the Library
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import * as BedrockAuth from "@arv-bedrock/auth-sso";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Initialization
|
|
26
|
+
|
|
27
|
+
To initialize the authentication system, provide your credentials and configuration options:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { initBedrockAuth } from "@arv-bedrock/auth-sso";
|
|
31
|
+
|
|
32
|
+
initBedrockAuth({
|
|
33
|
+
authUri: "https://auth.example.com",
|
|
34
|
+
clientId: "your-client-id",
|
|
35
|
+
clientSecret: "your-client-secret",
|
|
36
|
+
userType: "officer", // Optional: officer (default) / citizen
|
|
37
|
+
callback: (errorOrData) => {
|
|
38
|
+
if (errorOrData instanceof Error) {
|
|
39
|
+
console.error("Initialization error:", errorOrData);
|
|
40
|
+
} else {
|
|
41
|
+
console.log("Initialization successful:", errorOrData);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## API Reference
|
|
50
|
+
|
|
51
|
+
### Authentication Methods
|
|
52
|
+
|
|
53
|
+
#### `doLogin(redirectUrl?: string): void`
|
|
54
|
+
Redirects the user to the login page.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
BedrockAuth.doLogin("https://your-app.com/dashboard");
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### `doLogout(redirectUrl?: string): Promise<void>`
|
|
61
|
+
Logs the user out and optionally redirects them to the specified URL.
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
BedrockAuth.doLogout("https://your-app.com");
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### `doRegister(redirectUrl?: string): void`
|
|
68
|
+
Redirects the user to the registration page.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
BedrockAuth.doRegister("https://your-app.com/welcome");
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### `verifyToken(): Promise<ResponseData<[]>>`
|
|
75
|
+
Verifies the validity of the user's token.
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const response = await BedrockAuth.verifyToken();
|
|
79
|
+
console.log("Response:", response);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Profile Management
|
|
83
|
+
|
|
84
|
+
#### `getProfile(): Promise<ResponseData<AuthServiceResponse> | undefined>`
|
|
85
|
+
Fetches the current user's profile.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const profile = await BedrockAuth.getProfile();
|
|
89
|
+
console.log("User profile:", profile);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### `updateProfile(body: UpdateProfile): Promise<ResponseData<[]>>`
|
|
93
|
+
Updates the user's profile.
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const response = await BedrockAuth.updateProfile({ firstName: "First Name", lastName: "Last Name" title: "Mr.", userId: "User Id" });
|
|
97
|
+
console.log("Profile updated.", response);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Account Management
|
|
101
|
+
|
|
102
|
+
#### `doManageAccount(redirectUrl?: string): void`
|
|
103
|
+
Redirects the user to the account management page.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
BedrockAuth.doManageAccount("https://your-app.com/manage-account");
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
#### `disabledAccount(body: DisabledAccount): Promise<ResponseData<[]>>`
|
|
110
|
+
Disables a user account.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
await BedrockAuth.disabledAccount({ userId: "12345", isDisabled: true });
|
|
114
|
+
console.log("Account disabled.");
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Token and Cookie Management
|
|
118
|
+
|
|
119
|
+
#### `setCookie(code: string): Promise<void>`
|
|
120
|
+
Sets an authentication cookie.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
await BedrockAuth.setCookie("auth-code");
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
#### `clearCookie(): Promise<void>`
|
|
127
|
+
Clears the authentication cookie.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
await BedrockAuth.clearCookie();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### `refreshToken(): Promise<ResponseData<RefreshTokenResponse>>`
|
|
134
|
+
Refreshes the authentication token.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const newToken = await BedrockAuth.refreshToken();
|
|
138
|
+
console.log("New token:", newToken);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### `getCode(): Promise<string>`
|
|
142
|
+
Retrieves the authentication code.
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const code = await BedrockAuth.getCode();
|
|
146
|
+
console.log("Auth code:", code);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Invites
|
|
150
|
+
|
|
151
|
+
#### `requestInviting(email: string, duration?: number): Promise<ResponseData<[]>>`
|
|
152
|
+
Sends an invitation email.
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
await BedrockAuth.requestInviting("user@example.com", 7);
|
|
156
|
+
console.log("Invitation sent.");
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Advanced Features
|
|
162
|
+
|
|
163
|
+
#### `doPortal(): void`
|
|
164
|
+
Redirects the user to the authentication portal.
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
BedrockAuth.doPortal();
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### `getRedirectUri(): string`
|
|
171
|
+
Retrieves the current redirect URI.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const redirectUri = BedrockAuth.getRedirectUri();
|
|
175
|
+
console.log("Redirect URI:", redirectUri);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## Type Definitions
|
|
181
|
+
|
|
182
|
+
### `AuthProps`
|
|
183
|
+
Defines the properties required to initialize Bedrock Auth.
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
export type AuthProps = {
|
|
187
|
+
userType?: UserType; // "citizen" | "officer" (default: "officer")
|
|
188
|
+
authUri: string;
|
|
189
|
+
clientId: string;
|
|
190
|
+
clientSecret: string;
|
|
191
|
+
callback: (error?: any) => void;
|
|
192
|
+
};
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### `DisabledAccount`
|
|
196
|
+
Represents the details needed to disable an account.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
export type DisabledAccount = {
|
|
200
|
+
userId: string;
|
|
201
|
+
isDisabled: boolean;
|
|
202
|
+
};
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### `UpdateProfile`
|
|
206
|
+
Defines the structure for updating user profile information.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
export type UpdateProfile = {
|
|
210
|
+
userId: string;
|
|
211
|
+
title: string;
|
|
212
|
+
firstName: string;
|
|
213
|
+
lastName: string;
|
|
214
|
+
picture?: string | undefined | null;
|
|
215
|
+
};
|
|
216
|
+
```
|
package/dist/cjs/auth.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,11 +31,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
32
|
});
|
|
10
33
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const _fetch_1 =
|
|
35
|
+
const _fetch_1 = __importStar(require("./utils/_fetch"));
|
|
16
36
|
const constant_1 = require("./utils/constant");
|
|
17
37
|
class Auth {
|
|
18
38
|
constructor() {
|
|
@@ -104,6 +124,7 @@ class Auth {
|
|
|
104
124
|
}
|
|
105
125
|
init(options) {
|
|
106
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
(0, _fetch_1.setGlobalFetchOptions)(options.reconnection);
|
|
107
128
|
this.userType = options.userType;
|
|
108
129
|
this.authHost = options.authHost;
|
|
109
130
|
this.clientId = options.clientId;
|
|
@@ -250,10 +271,11 @@ class Auth {
|
|
|
250
271
|
}
|
|
251
272
|
updateProfile(body) {
|
|
252
273
|
const query = `${this.queryString}`;
|
|
274
|
+
const picture = (body === null || body === void 0 ? void 0 : body.picture) === undefined ? undefined : body === null || body === void 0 ? void 0 : body.picture;
|
|
253
275
|
const data = {
|
|
254
276
|
first_name: body.firstName,
|
|
255
277
|
last_name: body.lastName,
|
|
256
|
-
picture:
|
|
278
|
+
picture: picture,
|
|
257
279
|
user_id: body.userId,
|
|
258
280
|
title: body.title,
|
|
259
281
|
};
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,12 +14,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.doManageAccount = exports.refreshToken = exports.updateProfile = exports.disabledAccount = exports.requestInviting = exports.verifyToken = exports.getRedirectUri = exports.doPortal = exports.getCode = exports.clearCookie = exports.getProfile = exports.setCookie = exports.doRegister = exports.doLogout = exports.doLogin = exports.initBedrockAuth = void 0;
|
|
16
16
|
const auth_1 = __importDefault(require("./auth"));
|
|
17
|
-
const
|
|
17
|
+
const constant_1 = require("./utils/constant");
|
|
18
|
+
const initBedrockAuth = ({ authUri, clientId, clientSecret, callback, userType, reconnection, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
var _a, _b, _c;
|
|
18
20
|
yield auth_1.default.init({
|
|
19
21
|
authHost: authUri,
|
|
20
22
|
clientId,
|
|
21
23
|
clientSecret,
|
|
22
24
|
userType: userType !== null && userType !== void 0 ? userType : "officer",
|
|
25
|
+
reconnection: {
|
|
26
|
+
attempts: (_a = reconnection === null || reconnection === void 0 ? void 0 : reconnection.attempts) !== null && _a !== void 0 ? _a : constant_1.RECONNECTION.RETRY_COUNT,
|
|
27
|
+
timeout: (_b = reconnection === null || reconnection === void 0 ? void 0 : reconnection.timeout) !== null && _b !== void 0 ? _b : constant_1.RECONNECTION.TIMEOUT,
|
|
28
|
+
delay: (_c = reconnection === null || reconnection === void 0 ? void 0 : reconnection.delay) !== null && _c !== void 0 ? _c : constant_1.RECONNECTION.RETRY_DELAY,
|
|
29
|
+
},
|
|
23
30
|
})
|
|
24
31
|
.then((data) => {
|
|
25
32
|
callback(data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,UAAU,EAEV,eAAe,EAEf,OAAO,EACP,oBAAoB,EACpB,YAAY,EACZ,aAAa,EAEd,MAAM,eAAe,CAAC;AAEvB,cAAM,IAAI;IACR,OAAO,CAAC,QAAQ,CAAW;IAE3B,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,eAAe,CAAS;IAEhC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAa;;IAqB/B,SAAS;IAIF,OAAO;IAKP,cAAc;IAKrB,OAAO,CAAC,cAAc;IAUf,OAAO,CAAC,WAAW,GAAE,MAA6B;IAalD,QAAQ,iBAAwB,MAAM,mBAkB3C;IAEK,UAAU,CAAC,WAAW,GAAE,MAA6B;IAc5D,OAAO,CAAC,gBAAgB;IAQX,IAAI,CAAC,OAAO,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,UAAU,EAEV,eAAe,EAEf,OAAO,EACP,oBAAoB,EACpB,YAAY,EACZ,aAAa,EAEd,MAAM,eAAe,CAAC;AAEvB,cAAM,IAAI;IACR,OAAO,CAAC,QAAQ,CAAW;IAE3B,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,eAAe,CAAS;IAEhC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAa;;IAqB/B,SAAS;IAIF,OAAO;IAKP,cAAc;IAKrB,OAAO,CAAC,cAAc;IAUf,OAAO,CAAC,WAAW,GAAE,MAA6B;IAalD,QAAQ,iBAAwB,MAAM,mBAkB3C;IAEK,UAAU,CAAC,WAAW,GAAE,MAA6B;IAc5D,OAAO,CAAC,gBAAgB;IAQX,IAAI,CAAC,OAAO,EAAE,OAAO;IAkBrB,SAAS,CAAC,IAAI,EAAE,MAAM;YAuBrB,oBAAoB;IAgBlC,OAAO,CAAC,QAAQ;IAIH,aAAa;YAWZ,aAAa;IAqBd,WAAW;IAYX,cAAc;IAYd,UAAU;IA2BhB,QAAQ;IASR,WAAW;IAqBX,eAAe,CACpB,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAuD;IAY5D,aAAa,CAAC,IAAI,EAAE,aAAa;IAqBjC,eAAe,CAAC,IAAI,EAAE,eAAe;IAYrC,YAAY;IAkBZ,eAAe,CAAC,WAAW,CAAC,EAAE,MAAM;CAY5C;AAED,QAAA,MAAM,WAAW,MAAa,CAAC;AAE/B,eAAe,WAAW,CAAC"}
|
|
@@ -4,9 +4,14 @@ export type AuthProps = {
|
|
|
4
4
|
authUri: string;
|
|
5
5
|
clientId: string;
|
|
6
6
|
clientSecret: string;
|
|
7
|
+
reconnection?: {
|
|
8
|
+
attempts?: number;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
delay?: number;
|
|
11
|
+
};
|
|
7
12
|
callback: (error?: any) => void;
|
|
8
13
|
};
|
|
9
|
-
export declare const initBedrockAuth: ({ authUri, clientId, clientSecret, callback, userType, }: AuthProps) => Promise<void>;
|
|
14
|
+
export declare const initBedrockAuth: ({ authUri, clientId, clientSecret, callback, userType, reconnection, }: AuthProps) => Promise<void>;
|
|
10
15
|
export declare const doLogin: (redirectUrl?: string) => void;
|
|
11
16
|
export declare const doLogout: (redirectUrl?: string) => Promise<void>;
|
|
12
17
|
export declare const doRegister: (redirectUrl?: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzE,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,eAAe,2EAOzB,SAAS,kBAmBX,CAAC;AAEF,eAAO,MAAM,OAAO,iBAAkB,MAAM,SAA4B,CAAC;AAEzE,eAAO,MAAM,QAAQ,iBAAkB,MAAM,kBAA6B,CAAC;AAE3E,eAAO,MAAM,UAAU,iBAAkB,MAAM,SAA+B,CAAC;AAE/E,eAAO,MAAM,SAAS,SAAU,MAAM,kBAAuB,CAAC;AAE9D,eAAO,MAAM,UAAU,8GAAwB,CAAC;AAEhD,eAAO,MAAM,WAAW,qBAAyB,CAAC;AAElD,eAAO,MAAM,OAAO,cAAqB,CAAC;AAE1C,eAAO,MAAM,QAAQ,iCAAsB,CAAC;AAE5C,eAAO,MAAM,cAAc,cAA4B,CAAC;AAExD,eAAO,MAAM,WAAW,yDAAyB,CAAC;AAElD,eAAO,MAAM,eAAe,UAAW,MAAM,aAAa,MAAM,sDAC3B,CAAC;AAEtC,eAAO,MAAM,eAAe,SAAU,eAAe,sDAC3B,CAAC;AAE3B,eAAO,MAAM,aAAa,SAAU,aAAa,sDAA2B,CAAC;AAE7E,eAAO,MAAM,YAAY,mGAA0B,CAAC;AAEpD,eAAO,MAAM,eAAe,iBAAkB,MAAM,SACnB,CAAC"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
interface CustomFetchOptions extends RequestInit {
|
|
2
2
|
headers?: HeadersInit;
|
|
3
|
+
retryCount?: number;
|
|
4
|
+
retryDelay?: number;
|
|
5
|
+
timeout?: number;
|
|
3
6
|
}
|
|
7
|
+
export declare function setGlobalFetchOptions(options: {
|
|
8
|
+
attempts: number;
|
|
9
|
+
delay: number;
|
|
10
|
+
timeout: number;
|
|
11
|
+
}): void;
|
|
4
12
|
declare function customFetch<T>(url: string, options?: CustomFetchOptions): Promise<T>;
|
|
5
13
|
export default customFetch;
|
|
6
14
|
//# sourceMappingURL=_fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_fetch.d.ts","sourceRoot":"","sources":["../../../../utils/_fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_fetch.d.ts","sourceRoot":"","sources":["../../../../utils/_fetch.ts"],"names":[],"mappings":"AAUA,UAAU,kBAAmB,SAAQ,WAAW;IAC9C,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,QAIA;AAED,iBAAe,WAAW,CAAC,CAAC,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,CAAC,CAAC,CA8DZ;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -4,5 +4,10 @@ declare const CLIENT_SECRET = "client_secret";
|
|
|
4
4
|
declare const CODE = "code";
|
|
5
5
|
declare const REDIRECT_URI = "redirectUri";
|
|
6
6
|
declare const LOGIN_METHOD_REQUEST = "loginMethod";
|
|
7
|
-
|
|
7
|
+
declare const RECONNECTION: {
|
|
8
|
+
RETRY_COUNT: number;
|
|
9
|
+
RETRY_DELAY: number;
|
|
10
|
+
TIMEOUT: number;
|
|
11
|
+
};
|
|
12
|
+
export { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, OFFICER, RECONNECTION, REDIRECT_URI, };
|
|
8
13
|
//# sourceMappingURL=constant.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../../utils/constant.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,aAAa,kBAAkB,CAAC;AACtC,QAAA,MAAM,IAAI,SAAS,CAAC;AACpB,QAAA,MAAM,YAAY,gBAAgB,CAAC;AACnC,QAAA,MAAM,oBAAoB,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../../utils/constant.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,aAAa,kBAAkB,CAAC;AACtC,QAAA,MAAM,IAAI,SAAS,CAAC;AACpB,QAAA,MAAM,YAAY,gBAAgB,CAAC;AACnC,QAAA,MAAM,oBAAoB,gBAAgB,CAAC;AAC3C,QAAA,MAAM,YAAY;;;;CAIjB,CAAC;AAEF,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACP,YAAY,EACZ,YAAY,GACb,CAAC"}
|
|
@@ -8,6 +8,11 @@ export interface Options {
|
|
|
8
8
|
clientId: string;
|
|
9
9
|
clientSecret: string;
|
|
10
10
|
userType: UserType;
|
|
11
|
+
reconnection: {
|
|
12
|
+
attempts: number;
|
|
13
|
+
timeout: number;
|
|
14
|
+
delay: number;
|
|
15
|
+
};
|
|
11
16
|
}
|
|
12
17
|
export interface ResponseData<T> {
|
|
13
18
|
statusResponse: StatusResponse;
|
|
@@ -60,7 +65,7 @@ export interface UpdateProfile {
|
|
|
60
65
|
title: string;
|
|
61
66
|
firstName: string;
|
|
62
67
|
lastName: string;
|
|
63
|
-
picture?: string;
|
|
68
|
+
picture?: string | null | undefined;
|
|
64
69
|
}
|
|
65
70
|
export interface LoginMethodRequest {
|
|
66
71
|
redirectUri: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEnE,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE7C,MAAM,WAAW,IAAI;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEnE,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE7C,MAAM,WAAW,IAAI;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE;QACZ,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,cAAc,EAAE,cAAc,CAAC;IAC/B,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,sBAAsB,EAAE;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
|
package/dist/cjs/utils/_fetch.js
CHANGED
|
@@ -9,25 +9,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.setGlobalFetchOptions = void 0;
|
|
13
|
+
const constant_1 = require("./constant");
|
|
12
14
|
const defaultHeaders = {
|
|
13
15
|
"Content-Type": "application/json",
|
|
14
16
|
};
|
|
17
|
+
function setGlobalFetchOptions(options) {
|
|
18
|
+
constant_1.RECONNECTION.RETRY_COUNT = options.attempts;
|
|
19
|
+
constant_1.RECONNECTION.RETRY_DELAY = options.delay;
|
|
20
|
+
constant_1.RECONNECTION.TIMEOUT = options.timeout;
|
|
21
|
+
}
|
|
22
|
+
exports.setGlobalFetchOptions = setGlobalFetchOptions;
|
|
15
23
|
function customFetch(url, options = {}) {
|
|
24
|
+
var _a, _b, _c, _d, _e;
|
|
16
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
26
|
const headers = Object.assign(Object.assign({}, defaultHeaders), options.headers);
|
|
18
27
|
const requestOptions = Object.assign(Object.assign({}, options), { credentials: "include", mode: "cors" });
|
|
28
|
+
const maxRetries = (_a = options.retryCount) !== null && _a !== void 0 ? _a : constant_1.RECONNECTION.RETRY_COUNT;
|
|
29
|
+
const retryDelay = (_b = options.retryDelay) !== null && _b !== void 0 ? _b : constant_1.RECONNECTION.RETRY_DELAY;
|
|
30
|
+
const timeout = (_c = options.timeout) !== null && _c !== void 0 ? _c : constant_1.RECONNECTION.TIMEOUT;
|
|
31
|
+
let attempt = 0;
|
|
19
32
|
requestOptions.headers = headers;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
while (attempt < maxRetries) {
|
|
34
|
+
try {
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
37
|
+
requestOptions.signal = controller.signal;
|
|
38
|
+
const response = yield fetch(url, requestOptions);
|
|
39
|
+
clearTimeout(timeoutId);
|
|
40
|
+
let responseData = null;
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
43
|
+
}
|
|
44
|
+
if ((_d = response.headers.get("content-type")) === null || _d === void 0 ? void 0 : _d.includes("application/json")) {
|
|
45
|
+
responseData = yield response.json();
|
|
46
|
+
}
|
|
47
|
+
const statusCode = Number((_e = responseData === null || responseData === void 0 ? void 0 : responseData.statusResponse) === null || _e === void 0 ? void 0 : _e.statusCode);
|
|
48
|
+
if (response.status >= 500 || statusCode >= 500) {
|
|
49
|
+
throw response;
|
|
50
|
+
}
|
|
51
|
+
if (!statusCode || statusCode < 500) {
|
|
52
|
+
return responseData;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
attempt++;
|
|
57
|
+
if (attempt >= maxRetries) {
|
|
58
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
59
|
+
throw new Error(`Timeout - URL: ${url}, Method: ${requestOptions.method}, Params: ${requestOptions}`);
|
|
60
|
+
}
|
|
61
|
+
return error;
|
|
62
|
+
}
|
|
63
|
+
yield new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
64
|
+
}
|
|
30
65
|
}
|
|
66
|
+
throw new Error("Unreachable code");
|
|
31
67
|
});
|
|
32
68
|
}
|
|
33
69
|
exports.default = customFetch;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REDIRECT_URI = exports.OFFICER = exports.LOGIN_METHOD_REQUEST = exports.CODE = exports.CLIENT_SECRET = exports.CITIZEN = void 0;
|
|
3
|
+
exports.REDIRECT_URI = exports.RECONNECTION = exports.OFFICER = exports.LOGIN_METHOD_REQUEST = exports.CODE = exports.CLIENT_SECRET = exports.CITIZEN = void 0;
|
|
4
4
|
const CITIZEN = "citizen";
|
|
5
5
|
exports.CITIZEN = CITIZEN;
|
|
6
6
|
const OFFICER = "officer";
|
|
@@ -13,3 +13,9 @@ const REDIRECT_URI = "redirectUri";
|
|
|
13
13
|
exports.REDIRECT_URI = REDIRECT_URI;
|
|
14
14
|
const LOGIN_METHOD_REQUEST = "loginMethod";
|
|
15
15
|
exports.LOGIN_METHOD_REQUEST = LOGIN_METHOD_REQUEST;
|
|
16
|
+
const RECONNECTION = {
|
|
17
|
+
RETRY_COUNT: 3,
|
|
18
|
+
RETRY_DELAY: 500,
|
|
19
|
+
TIMEOUT: 1000,
|
|
20
|
+
};
|
|
21
|
+
exports.RECONNECTION = RECONNECTION;
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import customFetch from "./utils/_fetch";
|
|
1
|
+
import customFetch, { setGlobalFetchOptions } from "./utils/_fetch";
|
|
2
2
|
import { CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, REDIRECT_URI, } from "./utils/constant";
|
|
3
3
|
class Auth {
|
|
4
4
|
userType;
|
|
@@ -96,6 +96,7 @@ class Auth {
|
|
|
96
96
|
return searchParams.toString();
|
|
97
97
|
}
|
|
98
98
|
async init(options) {
|
|
99
|
+
setGlobalFetchOptions(options.reconnection);
|
|
99
100
|
this.userType = options.userType;
|
|
100
101
|
this.authHost = options.authHost;
|
|
101
102
|
this.clientId = options.clientId;
|
|
@@ -227,10 +228,11 @@ class Auth {
|
|
|
227
228
|
}
|
|
228
229
|
updateProfile(body) {
|
|
229
230
|
const query = `${this.queryString}`;
|
|
231
|
+
const picture = body?.picture === undefined ? undefined : body?.picture;
|
|
230
232
|
const data = {
|
|
231
233
|
first_name: body.firstName,
|
|
232
234
|
last_name: body.lastName,
|
|
233
|
-
picture:
|
|
235
|
+
picture: picture,
|
|
234
236
|
user_id: body.userId,
|
|
235
237
|
title: body.title,
|
|
236
238
|
};
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import BR from "./auth";
|
|
2
|
-
|
|
2
|
+
import { RECONNECTION } from "./utils/constant";
|
|
3
|
+
export const initBedrockAuth = async ({ authUri, clientId, clientSecret, callback, userType, reconnection, }) => {
|
|
3
4
|
await BR.init({
|
|
4
5
|
authHost: authUri,
|
|
5
6
|
clientId,
|
|
6
7
|
clientSecret,
|
|
7
8
|
userType: userType ?? "officer",
|
|
9
|
+
reconnection: {
|
|
10
|
+
attempts: reconnection?.attempts ?? RECONNECTION.RETRY_COUNT,
|
|
11
|
+
timeout: reconnection?.timeout ?? RECONNECTION.TIMEOUT,
|
|
12
|
+
delay: reconnection?.delay ?? RECONNECTION.RETRY_DELAY,
|
|
13
|
+
},
|
|
8
14
|
})
|
|
9
15
|
.then((data) => {
|
|
10
16
|
callback(data);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,UAAU,EAEV,eAAe,EAEf,OAAO,EACP,oBAAoB,EACpB,YAAY,EACZ,aAAa,EAEd,MAAM,eAAe,CAAC;AAEvB,cAAM,IAAI;IACR,OAAO,CAAC,QAAQ,CAAW;IAE3B,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,eAAe,CAAS;IAEhC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAa;;IAqB/B,SAAS;IAIF,OAAO;IAKP,cAAc;IAKrB,OAAO,CAAC,cAAc;IAUf,OAAO,CAAC,WAAW,GAAE,MAA6B;IAalD,QAAQ,iBAAwB,MAAM,mBAkB3C;IAEK,UAAU,CAAC,WAAW,GAAE,MAA6B;IAc5D,OAAO,CAAC,gBAAgB;IAQX,IAAI,CAAC,OAAO,EAAE,OAAO;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,UAAU,EAEV,eAAe,EAEf,OAAO,EACP,oBAAoB,EACpB,YAAY,EACZ,aAAa,EAEd,MAAM,eAAe,CAAC;AAEvB,cAAM,IAAI;IACR,OAAO,CAAC,QAAQ,CAAW;IAE3B,OAAO,CAAC,QAAQ,CAAS;IAEzB,OAAO,CAAC,eAAe,CAAS;IAEhC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAE7B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAa;;IAqB/B,SAAS;IAIF,OAAO;IAKP,cAAc;IAKrB,OAAO,CAAC,cAAc;IAUf,OAAO,CAAC,WAAW,GAAE,MAA6B;IAalD,QAAQ,iBAAwB,MAAM,mBAkB3C;IAEK,UAAU,CAAC,WAAW,GAAE,MAA6B;IAc5D,OAAO,CAAC,gBAAgB;IAQX,IAAI,CAAC,OAAO,EAAE,OAAO;IAkBrB,SAAS,CAAC,IAAI,EAAE,MAAM;YAuBrB,oBAAoB;IAgBlC,OAAO,CAAC,QAAQ;IAIH,aAAa;YAWZ,aAAa;IAqBd,WAAW;IAYX,cAAc;IAYd,UAAU;IA2BhB,QAAQ;IASR,WAAW;IAqBX,eAAe,CACpB,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,MAAuD;IAY5D,aAAa,CAAC,IAAI,EAAE,aAAa;IAqBjC,eAAe,CAAC,IAAI,EAAE,eAAe;IAYrC,YAAY;IAkBZ,eAAe,CAAC,WAAW,CAAC,EAAE,MAAM;CAY5C;AAED,QAAA,MAAM,WAAW,MAAa,CAAC;AAE/B,eAAe,WAAW,CAAC"}
|
|
@@ -4,9 +4,14 @@ export type AuthProps = {
|
|
|
4
4
|
authUri: string;
|
|
5
5
|
clientId: string;
|
|
6
6
|
clientSecret: string;
|
|
7
|
+
reconnection?: {
|
|
8
|
+
attempts?: number;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
delay?: number;
|
|
11
|
+
};
|
|
7
12
|
callback: (error?: any) => void;
|
|
8
13
|
};
|
|
9
|
-
export declare const initBedrockAuth: ({ authUri, clientId, clientSecret, callback, userType, }: AuthProps) => Promise<void>;
|
|
14
|
+
export declare const initBedrockAuth: ({ authUri, clientId, clientSecret, callback, userType, reconnection, }: AuthProps) => Promise<void>;
|
|
10
15
|
export declare const doLogin: (redirectUrl?: string) => void;
|
|
11
16
|
export declare const doLogout: (redirectUrl?: string) => Promise<void>;
|
|
12
17
|
export declare const doRegister: (redirectUrl?: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzE,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,eAAe,2EAOzB,SAAS,kBAmBX,CAAC;AAEF,eAAO,MAAM,OAAO,iBAAkB,MAAM,SAA4B,CAAC;AAEzE,eAAO,MAAM,QAAQ,iBAAkB,MAAM,kBAA6B,CAAC;AAE3E,eAAO,MAAM,UAAU,iBAAkB,MAAM,SAA+B,CAAC;AAE/E,eAAO,MAAM,SAAS,SAAU,MAAM,kBAAuB,CAAC;AAE9D,eAAO,MAAM,UAAU,8GAAwB,CAAC;AAEhD,eAAO,MAAM,WAAW,qBAAyB,CAAC;AAElD,eAAO,MAAM,OAAO,cAAqB,CAAC;AAE1C,eAAO,MAAM,QAAQ,iCAAsB,CAAC;AAE5C,eAAO,MAAM,cAAc,cAA4B,CAAC;AAExD,eAAO,MAAM,WAAW,yDAAyB,CAAC;AAElD,eAAO,MAAM,eAAe,UAAW,MAAM,aAAa,MAAM,sDAC3B,CAAC;AAEtC,eAAO,MAAM,eAAe,SAAU,eAAe,sDAC3B,CAAC;AAE3B,eAAO,MAAM,aAAa,SAAU,aAAa,sDAA2B,CAAC;AAE7E,eAAO,MAAM,YAAY,mGAA0B,CAAC;AAEpD,eAAO,MAAM,eAAe,iBAAkB,MAAM,SACnB,CAAC"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
interface CustomFetchOptions extends RequestInit {
|
|
2
2
|
headers?: HeadersInit;
|
|
3
|
+
retryCount?: number;
|
|
4
|
+
retryDelay?: number;
|
|
5
|
+
timeout?: number;
|
|
3
6
|
}
|
|
7
|
+
export declare function setGlobalFetchOptions(options: {
|
|
8
|
+
attempts: number;
|
|
9
|
+
delay: number;
|
|
10
|
+
timeout: number;
|
|
11
|
+
}): void;
|
|
4
12
|
declare function customFetch<T>(url: string, options?: CustomFetchOptions): Promise<T>;
|
|
5
13
|
export default customFetch;
|
|
6
14
|
//# sourceMappingURL=_fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_fetch.d.ts","sourceRoot":"","sources":["../../../../utils/_fetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_fetch.d.ts","sourceRoot":"","sources":["../../../../utils/_fetch.ts"],"names":[],"mappings":"AAUA,UAAU,kBAAmB,SAAQ,WAAW;IAC9C,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,QAIA;AAED,iBAAe,WAAW,CAAC,CAAC,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,CAAC,CAAC,CA8DZ;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -4,5 +4,10 @@ declare const CLIENT_SECRET = "client_secret";
|
|
|
4
4
|
declare const CODE = "code";
|
|
5
5
|
declare const REDIRECT_URI = "redirectUri";
|
|
6
6
|
declare const LOGIN_METHOD_REQUEST = "loginMethod";
|
|
7
|
-
|
|
7
|
+
declare const RECONNECTION: {
|
|
8
|
+
RETRY_COUNT: number;
|
|
9
|
+
RETRY_DELAY: number;
|
|
10
|
+
TIMEOUT: number;
|
|
11
|
+
};
|
|
12
|
+
export { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, OFFICER, RECONNECTION, REDIRECT_URI, };
|
|
8
13
|
//# sourceMappingURL=constant.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../../utils/constant.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,aAAa,kBAAkB,CAAC;AACtC,QAAA,MAAM,IAAI,SAAS,CAAC;AACpB,QAAA,MAAM,YAAY,gBAAgB,CAAC;AACnC,QAAA,MAAM,oBAAoB,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../../utils/constant.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,OAAO,YAAY,CAAC;AAC1B,QAAA,MAAM,aAAa,kBAAkB,CAAC;AACtC,QAAA,MAAM,IAAI,SAAS,CAAC;AACpB,QAAA,MAAM,YAAY,gBAAgB,CAAC;AACnC,QAAA,MAAM,oBAAoB,gBAAgB,CAAC;AAC3C,QAAA,MAAM,YAAY;;;;CAIjB,CAAC;AAEF,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACP,YAAY,EACZ,YAAY,GACb,CAAC"}
|
|
@@ -8,6 +8,11 @@ export interface Options {
|
|
|
8
8
|
clientId: string;
|
|
9
9
|
clientSecret: string;
|
|
10
10
|
userType: UserType;
|
|
11
|
+
reconnection: {
|
|
12
|
+
attempts: number;
|
|
13
|
+
timeout: number;
|
|
14
|
+
delay: number;
|
|
15
|
+
};
|
|
11
16
|
}
|
|
12
17
|
export interface ResponseData<T> {
|
|
13
18
|
statusResponse: StatusResponse;
|
|
@@ -60,7 +65,7 @@ export interface UpdateProfile {
|
|
|
60
65
|
title: string;
|
|
61
66
|
firstName: string;
|
|
62
67
|
lastName: string;
|
|
63
|
-
picture?: string;
|
|
68
|
+
picture?: string | null | undefined;
|
|
64
69
|
}
|
|
65
70
|
export interface LoginMethodRequest {
|
|
66
71
|
redirectUri: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEnE,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE7C,MAAM,WAAW,IAAI;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../utils/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEnE,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAE7C,MAAM,WAAW,IAAI;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE;QACZ,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,cAAc,EAAE,cAAc,CAAC;IAC/B,IAAI,EAAE,CAAC,CAAC;CACT;AAED,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,OAAO,CAAC;IAClB,sBAAsB,EAAE;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;CACH;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
|
package/dist/esm/utils/_fetch.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { RECONNECTION } from "./constant";
|
|
1
2
|
const defaultHeaders = {
|
|
2
3
|
"Content-Type": "application/json",
|
|
3
4
|
};
|
|
5
|
+
export function setGlobalFetchOptions(options) {
|
|
6
|
+
RECONNECTION.RETRY_COUNT = options.attempts;
|
|
7
|
+
RECONNECTION.RETRY_DELAY = options.delay;
|
|
8
|
+
RECONNECTION.TIMEOUT = options.timeout;
|
|
9
|
+
}
|
|
4
10
|
async function customFetch(url, options = {}) {
|
|
5
11
|
const headers = {
|
|
6
12
|
...defaultHeaders,
|
|
@@ -11,17 +17,44 @@ async function customFetch(url, options = {}) {
|
|
|
11
17
|
credentials: "include",
|
|
12
18
|
mode: "cors",
|
|
13
19
|
};
|
|
20
|
+
const maxRetries = options.retryCount ?? RECONNECTION.RETRY_COUNT;
|
|
21
|
+
const retryDelay = options.retryDelay ?? RECONNECTION.RETRY_DELAY;
|
|
22
|
+
const timeout = options.timeout ?? RECONNECTION.TIMEOUT;
|
|
23
|
+
let attempt = 0;
|
|
14
24
|
requestOptions.headers = headers;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
while (attempt < maxRetries) {
|
|
26
|
+
try {
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
29
|
+
requestOptions.signal = controller.signal;
|
|
30
|
+
const response = await fetch(url, requestOptions);
|
|
31
|
+
clearTimeout(timeoutId);
|
|
32
|
+
let responseData = null;
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
35
|
+
}
|
|
36
|
+
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
37
|
+
responseData = await response.json();
|
|
38
|
+
}
|
|
39
|
+
const statusCode = Number(responseData?.statusResponse?.statusCode);
|
|
40
|
+
if (response.status >= 500 || statusCode >= 500) {
|
|
41
|
+
throw response;
|
|
42
|
+
}
|
|
43
|
+
if (!statusCode || statusCode < 500) {
|
|
44
|
+
return responseData;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
attempt++;
|
|
49
|
+
if (attempt >= maxRetries) {
|
|
50
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
51
|
+
throw new Error(`Timeout - URL: ${url}, Method: ${requestOptions.method}, Params: ${requestOptions}`);
|
|
52
|
+
}
|
|
53
|
+
return error;
|
|
54
|
+
}
|
|
55
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
56
|
+
}
|
|
25
57
|
}
|
|
58
|
+
throw new Error("Unreachable code");
|
|
26
59
|
}
|
|
27
60
|
export default customFetch;
|
|
@@ -4,4 +4,9 @@ const CLIENT_SECRET = "client_secret";
|
|
|
4
4
|
const CODE = "code";
|
|
5
5
|
const REDIRECT_URI = "redirectUri";
|
|
6
6
|
const LOGIN_METHOD_REQUEST = "loginMethod";
|
|
7
|
-
|
|
7
|
+
const RECONNECTION = {
|
|
8
|
+
RETRY_COUNT: 3,
|
|
9
|
+
RETRY_DELAY: 500,
|
|
10
|
+
TIMEOUT: 1000,
|
|
11
|
+
};
|
|
12
|
+
export { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, OFFICER, RECONNECTION, REDIRECT_URI, };
|