@arv-bedrock/auth-sso 0.2.3 → 0.2.5
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 +5 -1
- package/dist/cjs/auth.js +49 -39
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/types/auth.d.ts +4 -66
- package/dist/cjs/types/auth.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +6 -3
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/utils/_fetch.d.ts.map +1 -0
- package/dist/cjs/types/utils/constant.d.ts.map +1 -0
- package/dist/cjs/types/utils/enum.d.ts +16 -0
- package/dist/cjs/types/utils/enum.d.ts.map +1 -0
- package/dist/cjs/types/utils/types.d.ts +67 -0
- package/dist/cjs/types/utils/types.d.ts.map +1 -0
- package/dist/cjs/{_fetch.js → utils/_fetch.js} +4 -4
- package/dist/cjs/utils/enum.js +21 -0
- package/dist/cjs/utils/types.js +2 -0
- package/dist/esm/auth.js +49 -38
- package/dist/esm/index.mjs +5 -2
- package/dist/esm/types/auth.d.ts +4 -66
- package/dist/esm/types/auth.d.ts.map +1 -1
- package/dist/esm/types/index.d.ts +6 -3
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/utils/_fetch.d.ts.map +1 -0
- package/dist/esm/types/utils/constant.d.ts.map +1 -0
- package/dist/esm/types/utils/enum.d.ts +16 -0
- package/dist/esm/types/utils/enum.d.ts.map +1 -0
- package/dist/esm/types/utils/types.d.ts +67 -0
- package/dist/esm/types/utils/types.d.ts.map +1 -0
- package/dist/esm/{_fetch.js → utils/_fetch.js} +5 -5
- package/dist/esm/utils/enum.js +18 -0
- package/dist/esm/utils/types.js +1 -0
- package/package.json +2 -2
- package/dist/cjs/types/_fetch.d.ts.map +0 -1
- package/dist/cjs/types/constant.d.ts.map +0 -1
- package/dist/esm/types/_fetch.d.ts.map +0 -1
- package/dist/esm/types/constant.d.ts.map +0 -1
- /package/dist/cjs/types/{_fetch.d.ts → utils/_fetch.d.ts} +0 -0
- /package/dist/cjs/types/{constant.d.ts → utils/constant.d.ts} +0 -0
- /package/dist/cjs/{constant.js → utils/constant.js} +0 -0
- /package/dist/esm/types/{_fetch.d.ts → utils/_fetch.d.ts} +0 -0
- /package/dist/esm/types/{constant.d.ts → utils/constant.d.ts} +0 -0
- /package/dist/esm/{constant.js → utils/constant.js} +0 -0
package/README.md
CHANGED
package/dist/cjs/auth.js
CHANGED
|
@@ -12,27 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const constant_1 = require("./constant");
|
|
18
|
-
var TypeAccount;
|
|
19
|
-
(function (TypeAccount) {
|
|
20
|
-
TypeAccount["EMAIL"] = "email";
|
|
21
|
-
TypeAccount["PHONE_NUMBER"] = "phone_number";
|
|
22
|
-
TypeAccount["USERNAME"] = "username";
|
|
23
|
-
TypeAccount["LINE"] = "line";
|
|
24
|
-
TypeAccount["LINE_OA"] = "line_oa";
|
|
25
|
-
})(TypeAccount = exports.TypeAccount || (exports.TypeAccount = {}));
|
|
26
|
-
var AccountProviders;
|
|
27
|
-
(function (AccountProviders) {
|
|
28
|
-
AccountProviders["EMAIL"] = "email";
|
|
29
|
-
AccountProviders["GOOGEL"] = "google";
|
|
30
|
-
})(AccountProviders = exports.AccountProviders || (exports.AccountProviders = {}));
|
|
31
|
-
var UserStatus;
|
|
32
|
-
(function (UserStatus) {
|
|
33
|
-
UserStatus["ACTIVE"] = "active";
|
|
34
|
-
UserStatus["INACTIVE"] = "inactive";
|
|
35
|
-
})(UserStatus = exports.UserStatus || (exports.UserStatus = {}));
|
|
15
|
+
const _fetch_1 = __importDefault(require("./utils/_fetch"));
|
|
16
|
+
const constant_1 = require("./utils/constant");
|
|
36
17
|
class Auth {
|
|
37
18
|
constructor() {
|
|
38
19
|
this.doLogout = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -44,31 +25,33 @@ class Auth {
|
|
|
44
25
|
this.doLogin();
|
|
45
26
|
}
|
|
46
27
|
});
|
|
47
|
-
this.userType =
|
|
48
|
-
this.authHost =
|
|
49
|
-
this.clientId =
|
|
50
|
-
this.clientSecret =
|
|
51
|
-
this.defaultCallback =
|
|
52
|
-
this.queryString =
|
|
53
|
-
this.clientInit = { logoutUrl:
|
|
28
|
+
this.userType = "officer";
|
|
29
|
+
this.authHost = "";
|
|
30
|
+
this.clientId = "";
|
|
31
|
+
this.clientSecret = "";
|
|
32
|
+
this.defaultCallback = "";
|
|
33
|
+
this.queryString = "";
|
|
34
|
+
this.clientInit = { logoutUrl: "", portalHomeUrl: "", isPortal: false };
|
|
54
35
|
}
|
|
55
36
|
isCitizen() {
|
|
56
|
-
return this.userType ===
|
|
37
|
+
return this.userType === "citizen";
|
|
57
38
|
}
|
|
58
39
|
getCode() {
|
|
59
40
|
const params = new URLSearchParams(window.location.search);
|
|
60
|
-
return params.get(constant_1.CODE) ||
|
|
41
|
+
return params.get(constant_1.CODE) || "";
|
|
61
42
|
}
|
|
62
43
|
getRedirectUri() {
|
|
63
44
|
const params = new URLSearchParams(window.location.search);
|
|
64
|
-
return params.get(constant_1.REDIRECT_URI) ||
|
|
45
|
+
return params.get(constant_1.REDIRECT_URI) || "";
|
|
65
46
|
}
|
|
66
47
|
removeUrlParam(key) {
|
|
67
48
|
const params = new URLSearchParams(window.location.search);
|
|
68
49
|
params.delete(key);
|
|
69
50
|
const { pathname } = window.location;
|
|
70
|
-
const replaceURL = params.toString()
|
|
71
|
-
|
|
51
|
+
const replaceURL = params.toString()
|
|
52
|
+
? `${pathname}?${params.toString()}`
|
|
53
|
+
: pathname;
|
|
54
|
+
window.history.replaceState({}, "", replaceURL);
|
|
72
55
|
}
|
|
73
56
|
doLogin(redirectUrl = this.defaultCallback) {
|
|
74
57
|
let url = new URL(redirectUrl, window.location.origin).toString();
|
|
@@ -112,7 +95,7 @@ class Auth {
|
|
|
112
95
|
user_type: this.userType,
|
|
113
96
|
});
|
|
114
97
|
const res = yield this.getClientInit();
|
|
115
|
-
if (res.statusResponse.statusCode !=
|
|
98
|
+
if (res.statusResponse.statusCode != "200") {
|
|
116
99
|
return this.doLogin();
|
|
117
100
|
}
|
|
118
101
|
this.clientInit = res.data;
|
|
@@ -123,11 +106,11 @@ class Auth {
|
|
|
123
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
124
107
|
const codeParam = `${constant_1.CODE}=${code}`;
|
|
125
108
|
yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}&${codeParam}`, {
|
|
126
|
-
method:
|
|
109
|
+
method: "POST",
|
|
127
110
|
body: JSON.stringify({ code }),
|
|
128
111
|
});
|
|
129
112
|
this.removeUrlParam(constant_1.CODE);
|
|
130
|
-
const shouldDoLoginMethod = this.getParam(constant_1.LOGIN_METHOD_REQUEST) ==
|
|
113
|
+
const shouldDoLoginMethod = this.getParam(constant_1.LOGIN_METHOD_REQUEST) == "true";
|
|
131
114
|
if (shouldDoLoginMethod) {
|
|
132
115
|
yield this.doLoginMethodReqeust();
|
|
133
116
|
}
|
|
@@ -164,7 +147,7 @@ class Auth {
|
|
|
164
147
|
clearCookie() {
|
|
165
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
166
149
|
yield (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}`, {
|
|
167
|
-
method:
|
|
150
|
+
method: "DELETE",
|
|
168
151
|
});
|
|
169
152
|
});
|
|
170
153
|
}
|
|
@@ -177,7 +160,7 @@ class Auth {
|
|
|
177
160
|
return profile;
|
|
178
161
|
}
|
|
179
162
|
catch (error) {
|
|
180
|
-
console.log(
|
|
163
|
+
console.log("error", error);
|
|
181
164
|
}
|
|
182
165
|
});
|
|
183
166
|
}
|
|
@@ -189,7 +172,34 @@ class Auth {
|
|
|
189
172
|
}
|
|
190
173
|
verifyToken() {
|
|
191
174
|
return (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/verifyToken?${this.queryString}`, {
|
|
192
|
-
method:
|
|
175
|
+
method: "POST",
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
requestInviting(email) {
|
|
179
|
+
const query = `${this.queryString}&email=${email}`;
|
|
180
|
+
return (0, _fetch_1.default)(`${this.authHost}/api/v1/register/invite?${query}`, {
|
|
181
|
+
method: "GET",
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
updateProfile(body) {
|
|
185
|
+
const query = `${this.queryString}`;
|
|
186
|
+
const data = {
|
|
187
|
+
first_name: body.firstName,
|
|
188
|
+
last_name: body.lastName,
|
|
189
|
+
picture: body.picture,
|
|
190
|
+
user_id: body.userId,
|
|
191
|
+
title: body.title,
|
|
192
|
+
};
|
|
193
|
+
return (0, _fetch_1.default)(`${this.authHost}/api/v1/ums/profile?${query}`, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
body: JSON.stringify(Object.assign({}, data)),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
disabledAccount(body) {
|
|
199
|
+
const query = `${this.queryString}`;
|
|
200
|
+
return (0, _fetch_1.default)(`${this.authHost}/api/v1/oauth/disableAccount?${query}`, {
|
|
201
|
+
method: "POST",
|
|
202
|
+
body: JSON.stringify(Object.assign({}, body)),
|
|
193
203
|
});
|
|
194
204
|
}
|
|
195
205
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.verifyToken = exports.getRedirectUri = exports.doPortal = exports.getCode = exports.clearCookie = exports.getProfile = exports.setCookie = exports.doRegister = exports.doLogout = exports.doLogin = exports.initBedrockAuth = void 0;
|
|
6
|
+
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;
|
|
7
7
|
const auth_1 = __importDefault(require("./auth"));
|
|
8
8
|
const initBedrockAuth = ({ authUri, clientId, clientSecret, callback, userType, }) => {
|
|
9
9
|
auth_1.default.init({
|
|
10
10
|
authHost: authUri,
|
|
11
11
|
clientId,
|
|
12
12
|
clientSecret,
|
|
13
|
-
userType: userType !== null && userType !== void 0 ? userType :
|
|
13
|
+
userType: userType !== null && userType !== void 0 ? userType : "officer",
|
|
14
14
|
})
|
|
15
15
|
.then((data) => {
|
|
16
16
|
callback(data);
|
|
@@ -41,3 +41,9 @@ const getRedirectUri = () => auth_1.default.getRedirectUri();
|
|
|
41
41
|
exports.getRedirectUri = getRedirectUri;
|
|
42
42
|
const verifyToken = () => auth_1.default.verifyToken();
|
|
43
43
|
exports.verifyToken = verifyToken;
|
|
44
|
+
const requestInviting = (email) => auth_1.default.requestInviting(email);
|
|
45
|
+
exports.requestInviting = requestInviting;
|
|
46
|
+
const disabledAccount = (body) => auth_1.default.disabledAccount(body);
|
|
47
|
+
exports.disabledAccount = disabledAccount;
|
|
48
|
+
const updateProfile = (body) => auth_1.default.updateProfile(body);
|
|
49
|
+
exports.updateProfile = updateProfile;
|
package/dist/cjs/types/auth.d.ts
CHANGED
|
@@ -1,69 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
interface Options {
|
|
3
|
-
authHost: string;
|
|
4
|
-
clientId: string;
|
|
5
|
-
clientSecret: string;
|
|
6
|
-
userType: UserType;
|
|
7
|
-
}
|
|
8
|
-
export interface ResponseData<T> {
|
|
9
|
-
statusResponse: StatusResponse;
|
|
10
|
-
data: T;
|
|
11
|
-
}
|
|
12
|
-
export interface StatusResponse {
|
|
13
|
-
statusCode: string;
|
|
14
|
-
statusDesc: string;
|
|
15
|
-
messageCode: string;
|
|
16
|
-
messageTH: string;
|
|
17
|
-
messageEN: string;
|
|
18
|
-
}
|
|
19
|
-
export interface AuthServiceResponse {
|
|
20
|
-
id: string;
|
|
21
|
-
title: string;
|
|
22
|
-
firstName: string;
|
|
23
|
-
lastName: string;
|
|
24
|
-
phoneNumber: string;
|
|
25
|
-
picture: string | null;
|
|
26
|
-
status: UserStatus;
|
|
27
|
-
accounts: Accounts[];
|
|
28
|
-
}
|
|
29
|
-
export interface Accounts {
|
|
30
|
-
account: string;
|
|
31
|
-
provider: AccountProviders;
|
|
32
|
-
type: TypeAccount;
|
|
33
|
-
status: UserStatus;
|
|
34
|
-
}
|
|
35
|
-
export declare enum TypeAccount {
|
|
36
|
-
EMAIL = "email",
|
|
37
|
-
PHONE_NUMBER = "phone_number",
|
|
38
|
-
USERNAME = "username",
|
|
39
|
-
LINE = "line",
|
|
40
|
-
LINE_OA = "line_oa"
|
|
41
|
-
}
|
|
42
|
-
export declare enum AccountProviders {
|
|
43
|
-
EMAIL = "email",
|
|
44
|
-
GOOGEL = "google"
|
|
45
|
-
}
|
|
46
|
-
export declare enum UserStatus {
|
|
47
|
-
ACTIVE = "active",
|
|
48
|
-
INACTIVE = "inactive"
|
|
49
|
-
}
|
|
50
|
-
export interface AuthServiceRequest {
|
|
51
|
-
access_token: string;
|
|
52
|
-
refresh_token?: string;
|
|
53
|
-
home_url?: string;
|
|
54
|
-
}
|
|
55
|
-
export interface ClientInfo {
|
|
56
|
-
url: string;
|
|
57
|
-
isPortal: boolean;
|
|
58
|
-
}
|
|
59
|
-
export interface ClientInit {
|
|
60
|
-
logoutUrl: string;
|
|
61
|
-
portalHomeUrl: string;
|
|
62
|
-
isPortal: boolean;
|
|
63
|
-
}
|
|
64
|
-
export interface LoginMethodRequest {
|
|
65
|
-
redirectUri: string;
|
|
66
|
-
}
|
|
1
|
+
import { AuthServiceResponse, ClientInfo, ClientInit, DisabledAccount, Options, ResponseData, UpdateProfile } from "./utils/types";
|
|
67
2
|
declare class Auth {
|
|
68
3
|
private userType;
|
|
69
4
|
private authHost;
|
|
@@ -91,6 +26,9 @@ declare class Auth {
|
|
|
91
26
|
getProfile(): Promise<AuthServiceResponse | undefined>;
|
|
92
27
|
doPortal(): Promise<void> | undefined;
|
|
93
28
|
verifyToken(): Promise<ResponseData<[]>>;
|
|
29
|
+
requestInviting(email: string): Promise<ResponseData<[]>>;
|
|
30
|
+
updateProfile(body: UpdateProfile): Promise<ResponseData<[]>>;
|
|
31
|
+
disabledAccount(body: DisabledAccount): Promise<ResponseData<[]>>;
|
|
94
32
|
}
|
|
95
33
|
declare const bedRockAuth: Auth;
|
|
96
34
|
export default bedRockAuth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,UAAU,EAEV,eAAe,EAEf,OAAO,EACP,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;;IAY/B,SAAS;IAIF,OAAO;IAKP,cAAc;IAKrB,OAAO,CAAC,cAAc;IAUf,OAAO,CAAC,WAAW,GAAE,MAA6B;IAalD,QAAQ,sBAOb;IAEK,UAAU,CAAC,WAAW,GAAE,MAA6B;IAc5D,OAAO,CAAC,gBAAgB;IAQX,IAAI,CAAC,OAAO,EAAE,OAAO;IAkBrB,SAAS,CAAC,IAAI,EAAE,MAAM;YAiBrB,oBAAoB;IAalC,OAAO,CAAC,QAAQ;IAIH,aAAa;YAOZ,aAAa;IAQd,WAAW;IASX,UAAU;IAahB,QAAQ;IASR,WAAW;IASX,eAAe,CAAC,KAAK,EAAE,MAAM;IAU7B,aAAa,CAAC,IAAI,EAAE,aAAa;IAoBjC,eAAe,CAAC,IAAI,EAAE,eAAe;CAW7C;AAED,QAAA,MAAM,WAAW,MAAa,CAAC;AAE/B,eAAe,WAAW,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserType } from
|
|
1
|
+
import { DisabledAccount, UpdateProfile, UserType } from "./utils/types";
|
|
2
2
|
export type AuthProps = {
|
|
3
3
|
userType?: UserType;
|
|
4
4
|
authUri: string;
|
|
@@ -11,10 +11,13 @@ export declare const doLogin: (redirectUrl?: string) => void;
|
|
|
11
11
|
export declare const doLogout: () => Promise<void>;
|
|
12
12
|
export declare const doRegister: (redirectUrl?: string) => void;
|
|
13
13
|
export declare const setCookie: (code: string) => Promise<void>;
|
|
14
|
-
export declare const getProfile: () => Promise<import("./
|
|
14
|
+
export declare const getProfile: () => Promise<import("./utils/types").AuthServiceResponse | undefined>;
|
|
15
15
|
export declare const clearCookie: () => Promise<void>;
|
|
16
16
|
export declare const getCode: () => string;
|
|
17
17
|
export declare const doPortal: () => Promise<void> | undefined;
|
|
18
18
|
export declare const getRedirectUri: () => string;
|
|
19
|
-
export declare const verifyToken: () => Promise<import("./
|
|
19
|
+
export declare const verifyToken: () => Promise<import("./utils/types").ResponseData<[]>>;
|
|
20
|
+
export declare const requestInviting: (email: string) => Promise<import("./utils/types").ResponseData<[]>>;
|
|
21
|
+
export declare const disabledAccount: (body: DisabledAccount) => Promise<import("./utils/types").ResponseData<[]>>;
|
|
22
|
+
export declare const updateProfile: (body: UpdateProfile) => Promise<import("./utils/types").ResponseData<[]>>;
|
|
20
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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":"AACA,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,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,eAAe,6DAMzB,SAAS,SAcX,CAAC;AAEF,eAAO,MAAM,OAAO,iBAAkB,MAAM,SAA4B,CAAC;AAEzE,eAAO,MAAM,QAAQ,qBAAsB,CAAC;AAE5C,eAAO,MAAM,UAAU,iBAAkB,MAAM,SAA+B,CAAC;AAE/E,eAAO,MAAM,SAAS,SAAU,MAAM,kBAAuB,CAAC;AAE9D,eAAO,MAAM,UAAU,wEAAwB,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,sDAA8B,CAAC;AAE5E,eAAO,MAAM,eAAe,SAAU,eAAe,sDAC3B,CAAC;AAE3B,eAAO,MAAM,aAAa,SAAU,aAAa,sDAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_fetch.d.ts","sourceRoot":"","sources":["../../../../utils/_fetch.ts"],"names":[],"mappings":"AAQA,UAAU,kBAAmB,SAAQ,WAAW;IAC9C,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,iBAAe,WAAW,CAAC,CAAC,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,CAAC,CAAC,CA0BZ;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +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;AAE3C,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACP,YAAY,GACb,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare enum TypeAccount {
|
|
2
|
+
EMAIL = "email",
|
|
3
|
+
PHONE_NUMBER = "phone_number",
|
|
4
|
+
USERNAME = "username",
|
|
5
|
+
LINE = "line",
|
|
6
|
+
LINE_OA = "line_oa"
|
|
7
|
+
}
|
|
8
|
+
export declare enum AccountProviders {
|
|
9
|
+
EMAIL = "email",
|
|
10
|
+
GOOGEL = "google"
|
|
11
|
+
}
|
|
12
|
+
export declare enum UserStatus {
|
|
13
|
+
ACTIVE = "active",
|
|
14
|
+
INACTIVE = "inactive"
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../../utils/enum.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED,oBAAY,gBAAgB;IAC1B,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED,oBAAY,UAAU;IACpB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AccountProviders, TypeAccount, UserStatus } from "./enum";
|
|
2
|
+
export type UserType = "citizen" | "officer";
|
|
3
|
+
export interface Data {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Options {
|
|
7
|
+
authHost: string;
|
|
8
|
+
clientId: string;
|
|
9
|
+
clientSecret: string;
|
|
10
|
+
userType: UserType;
|
|
11
|
+
}
|
|
12
|
+
export interface ResponseData<T> {
|
|
13
|
+
statusResponse: StatusResponse;
|
|
14
|
+
data: T;
|
|
15
|
+
}
|
|
16
|
+
export interface StatusResponse {
|
|
17
|
+
statusCode: string;
|
|
18
|
+
statusDesc: string;
|
|
19
|
+
messageCode: string;
|
|
20
|
+
messageTH: string;
|
|
21
|
+
messageEN: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AuthServiceResponse {
|
|
24
|
+
id: string;
|
|
25
|
+
title: string;
|
|
26
|
+
firstName: string;
|
|
27
|
+
lastName: string;
|
|
28
|
+
phoneNumber: string;
|
|
29
|
+
picture: string | null;
|
|
30
|
+
status: UserStatus;
|
|
31
|
+
accounts: Accounts[];
|
|
32
|
+
}
|
|
33
|
+
export interface Accounts {
|
|
34
|
+
account: string;
|
|
35
|
+
provider: AccountProviders;
|
|
36
|
+
type: TypeAccount;
|
|
37
|
+
status: UserStatus;
|
|
38
|
+
}
|
|
39
|
+
export interface AuthServiceRequest {
|
|
40
|
+
access_token: string;
|
|
41
|
+
refresh_token?: string;
|
|
42
|
+
home_url?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ClientInfo {
|
|
45
|
+
url: string;
|
|
46
|
+
isPortal: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface ClientInit {
|
|
49
|
+
logoutUrl: string;
|
|
50
|
+
portalHomeUrl: string;
|
|
51
|
+
isPortal: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface UpdateProfile {
|
|
54
|
+
userId: string;
|
|
55
|
+
title: string;
|
|
56
|
+
firstName: string;
|
|
57
|
+
lastName: string;
|
|
58
|
+
picture: string;
|
|
59
|
+
}
|
|
60
|
+
export interface LoginMethodRequest {
|
|
61
|
+
redirectUri: string;
|
|
62
|
+
}
|
|
63
|
+
export interface DisabledAccount {
|
|
64
|
+
userId: string;
|
|
65
|
+
isDisabled: boolean;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;CACpB;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;CACnB;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,EAAE,MAAM,CAAC;CACjB;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"}
|
|
@@ -10,19 +10,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const defaultHeaders = {
|
|
13
|
-
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
14
|
};
|
|
15
15
|
function customFetch(url, options = {}) {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
17
|
const headers = Object.assign(Object.assign({}, defaultHeaders), options.headers);
|
|
18
|
-
const requestOptions = Object.assign(Object.assign({}, options), { credentials:
|
|
18
|
+
const requestOptions = Object.assign(Object.assign({}, options), { credentials: "include", mode: "cors" });
|
|
19
19
|
requestOptions.headers = headers;
|
|
20
20
|
const response = yield fetch(`${url}`, requestOptions);
|
|
21
21
|
if (!response.ok) {
|
|
22
22
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
23
23
|
}
|
|
24
|
-
const contentType = response.headers.get(
|
|
25
|
-
if (contentType && contentType.includes(
|
|
24
|
+
const contentType = response.headers.get("content-type");
|
|
25
|
+
if (contentType && contentType.includes("application/json")) {
|
|
26
26
|
return response.json();
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UserStatus = exports.AccountProviders = exports.TypeAccount = void 0;
|
|
4
|
+
var TypeAccount;
|
|
5
|
+
(function (TypeAccount) {
|
|
6
|
+
TypeAccount["EMAIL"] = "email";
|
|
7
|
+
TypeAccount["PHONE_NUMBER"] = "phone_number";
|
|
8
|
+
TypeAccount["USERNAME"] = "username";
|
|
9
|
+
TypeAccount["LINE"] = "line";
|
|
10
|
+
TypeAccount["LINE_OA"] = "line_oa";
|
|
11
|
+
})(TypeAccount = exports.TypeAccount || (exports.TypeAccount = {}));
|
|
12
|
+
var AccountProviders;
|
|
13
|
+
(function (AccountProviders) {
|
|
14
|
+
AccountProviders["EMAIL"] = "email";
|
|
15
|
+
AccountProviders["GOOGEL"] = "google";
|
|
16
|
+
})(AccountProviders = exports.AccountProviders || (exports.AccountProviders = {}));
|
|
17
|
+
var UserStatus;
|
|
18
|
+
(function (UserStatus) {
|
|
19
|
+
UserStatus["ACTIVE"] = "active";
|
|
20
|
+
UserStatus["INACTIVE"] = "inactive";
|
|
21
|
+
})(UserStatus = exports.UserStatus || (exports.UserStatus = {}));
|
package/dist/esm/auth.js
CHANGED
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
import customFetch from
|
|
2
|
-
import { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, REDIRECT_URI } from
|
|
3
|
-
export var TypeAccount;
|
|
4
|
-
(function (TypeAccount) {
|
|
5
|
-
TypeAccount["EMAIL"] = "email";
|
|
6
|
-
TypeAccount["PHONE_NUMBER"] = "phone_number";
|
|
7
|
-
TypeAccount["USERNAME"] = "username";
|
|
8
|
-
TypeAccount["LINE"] = "line";
|
|
9
|
-
TypeAccount["LINE_OA"] = "line_oa";
|
|
10
|
-
})(TypeAccount || (TypeAccount = {}));
|
|
11
|
-
export var AccountProviders;
|
|
12
|
-
(function (AccountProviders) {
|
|
13
|
-
AccountProviders["EMAIL"] = "email";
|
|
14
|
-
AccountProviders["GOOGEL"] = "google";
|
|
15
|
-
})(AccountProviders || (AccountProviders = {}));
|
|
16
|
-
export var UserStatus;
|
|
17
|
-
(function (UserStatus) {
|
|
18
|
-
UserStatus["ACTIVE"] = "active";
|
|
19
|
-
UserStatus["INACTIVE"] = "inactive";
|
|
20
|
-
})(UserStatus || (UserStatus = {}));
|
|
1
|
+
import customFetch from "./utils/_fetch";
|
|
2
|
+
import { CITIZEN, CLIENT_SECRET, CODE, LOGIN_METHOD_REQUEST, REDIRECT_URI, } from "./utils/constant";
|
|
21
3
|
class Auth {
|
|
22
4
|
userType;
|
|
23
5
|
authHost;
|
|
@@ -27,31 +9,33 @@ class Auth {
|
|
|
27
9
|
queryString;
|
|
28
10
|
clientInit;
|
|
29
11
|
constructor() {
|
|
30
|
-
this.userType =
|
|
31
|
-
this.authHost =
|
|
32
|
-
this.clientId =
|
|
33
|
-
this.clientSecret =
|
|
34
|
-
this.defaultCallback =
|
|
35
|
-
this.queryString =
|
|
36
|
-
this.clientInit = { logoutUrl:
|
|
12
|
+
this.userType = "officer";
|
|
13
|
+
this.authHost = "";
|
|
14
|
+
this.clientId = "";
|
|
15
|
+
this.clientSecret = "";
|
|
16
|
+
this.defaultCallback = "";
|
|
17
|
+
this.queryString = "";
|
|
18
|
+
this.clientInit = { logoutUrl: "", portalHomeUrl: "", isPortal: false };
|
|
37
19
|
}
|
|
38
20
|
isCitizen() {
|
|
39
|
-
return this.userType ===
|
|
21
|
+
return this.userType === "citizen";
|
|
40
22
|
}
|
|
41
23
|
getCode() {
|
|
42
24
|
const params = new URLSearchParams(window.location.search);
|
|
43
|
-
return params.get(CODE) ||
|
|
25
|
+
return params.get(CODE) || "";
|
|
44
26
|
}
|
|
45
27
|
getRedirectUri() {
|
|
46
28
|
const params = new URLSearchParams(window.location.search);
|
|
47
|
-
return params.get(REDIRECT_URI) ||
|
|
29
|
+
return params.get(REDIRECT_URI) || "";
|
|
48
30
|
}
|
|
49
31
|
removeUrlParam(key) {
|
|
50
32
|
const params = new URLSearchParams(window.location.search);
|
|
51
33
|
params.delete(key);
|
|
52
34
|
const { pathname } = window.location;
|
|
53
|
-
const replaceURL = params.toString()
|
|
54
|
-
|
|
35
|
+
const replaceURL = params.toString()
|
|
36
|
+
? `${pathname}?${params.toString()}`
|
|
37
|
+
: pathname;
|
|
38
|
+
window.history.replaceState({}, "", replaceURL);
|
|
55
39
|
}
|
|
56
40
|
doLogin(redirectUrl = this.defaultCallback) {
|
|
57
41
|
let url = new URL(redirectUrl, window.location.origin).toString();
|
|
@@ -103,7 +87,7 @@ class Auth {
|
|
|
103
87
|
user_type: this.userType,
|
|
104
88
|
});
|
|
105
89
|
const res = await this.getClientInit();
|
|
106
|
-
if (res.statusResponse.statusCode !=
|
|
90
|
+
if (res.statusResponse.statusCode != "200") {
|
|
107
91
|
return this.doLogin();
|
|
108
92
|
}
|
|
109
93
|
this.clientInit = res.data;
|
|
@@ -112,11 +96,11 @@ class Auth {
|
|
|
112
96
|
async setCookie(code) {
|
|
113
97
|
const codeParam = `${CODE}=${code}`;
|
|
114
98
|
await customFetch(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}&${codeParam}`, {
|
|
115
|
-
method:
|
|
99
|
+
method: "POST",
|
|
116
100
|
body: JSON.stringify({ code }),
|
|
117
101
|
});
|
|
118
102
|
this.removeUrlParam(CODE);
|
|
119
|
-
const shouldDoLoginMethod = this.getParam(LOGIN_METHOD_REQUEST) ==
|
|
103
|
+
const shouldDoLoginMethod = this.getParam(LOGIN_METHOD_REQUEST) == "true";
|
|
120
104
|
if (shouldDoLoginMethod) {
|
|
121
105
|
await this.doLoginMethodReqeust();
|
|
122
106
|
}
|
|
@@ -145,7 +129,7 @@ class Auth {
|
|
|
145
129
|
}
|
|
146
130
|
async clearCookie() {
|
|
147
131
|
await customFetch(`${this.authHost}/api/v1/oauth/cookies?${this.queryString}`, {
|
|
148
|
-
method:
|
|
132
|
+
method: "DELETE",
|
|
149
133
|
});
|
|
150
134
|
}
|
|
151
135
|
async getProfile() {
|
|
@@ -156,7 +140,7 @@ class Auth {
|
|
|
156
140
|
return profile;
|
|
157
141
|
}
|
|
158
142
|
catch (error) {
|
|
159
|
-
console.log(
|
|
143
|
+
console.log("error", error);
|
|
160
144
|
}
|
|
161
145
|
}
|
|
162
146
|
doPortal() {
|
|
@@ -167,7 +151,34 @@ class Auth {
|
|
|
167
151
|
}
|
|
168
152
|
verifyToken() {
|
|
169
153
|
return customFetch(`${this.authHost}/api/v1/oauth/verifyToken?${this.queryString}`, {
|
|
170
|
-
method:
|
|
154
|
+
method: "POST",
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
requestInviting(email) {
|
|
158
|
+
const query = `${this.queryString}&email=${email}`;
|
|
159
|
+
return customFetch(`${this.authHost}/api/v1/register/invite?${query}`, {
|
|
160
|
+
method: "GET",
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
updateProfile(body) {
|
|
164
|
+
const query = `${this.queryString}`;
|
|
165
|
+
const data = {
|
|
166
|
+
first_name: body.firstName,
|
|
167
|
+
last_name: body.lastName,
|
|
168
|
+
picture: body.picture,
|
|
169
|
+
user_id: body.userId,
|
|
170
|
+
title: body.title,
|
|
171
|
+
};
|
|
172
|
+
return customFetch(`${this.authHost}/api/v1/ums/profile?${query}`, {
|
|
173
|
+
method: "POST",
|
|
174
|
+
body: JSON.stringify({ ...data }),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
disabledAccount(body) {
|
|
178
|
+
const query = `${this.queryString}`;
|
|
179
|
+
return customFetch(`${this.authHost}/api/v1/oauth/disableAccount?${query}`, {
|
|
180
|
+
method: "POST",
|
|
181
|
+
body: JSON.stringify({ ...body }),
|
|
171
182
|
});
|
|
172
183
|
}
|
|
173
184
|
}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import BR from
|
|
1
|
+
import BR from "./auth";
|
|
2
2
|
export const initBedrockAuth = ({ authUri, clientId, clientSecret, callback, userType, }) => {
|
|
3
3
|
BR.init({
|
|
4
4
|
authHost: authUri,
|
|
5
5
|
clientId,
|
|
6
6
|
clientSecret,
|
|
7
|
-
userType: userType ??
|
|
7
|
+
userType: userType ?? "officer",
|
|
8
8
|
})
|
|
9
9
|
.then((data) => {
|
|
10
10
|
callback(data);
|
|
@@ -24,3 +24,6 @@ export const getCode = () => BR.getCode();
|
|
|
24
24
|
export const doPortal = () => BR.doPortal();
|
|
25
25
|
export const getRedirectUri = () => BR.getRedirectUri();
|
|
26
26
|
export const verifyToken = () => BR.verifyToken();
|
|
27
|
+
export const requestInviting = (email) => BR.requestInviting(email);
|
|
28
|
+
export const disabledAccount = (body) => BR.disabledAccount(body);
|
|
29
|
+
export const updateProfile = (body) => BR.updateProfile(body);
|
package/dist/esm/types/auth.d.ts
CHANGED
|
@@ -1,69 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
interface Options {
|
|
3
|
-
authHost: string;
|
|
4
|
-
clientId: string;
|
|
5
|
-
clientSecret: string;
|
|
6
|
-
userType: UserType;
|
|
7
|
-
}
|
|
8
|
-
export interface ResponseData<T> {
|
|
9
|
-
statusResponse: StatusResponse;
|
|
10
|
-
data: T;
|
|
11
|
-
}
|
|
12
|
-
export interface StatusResponse {
|
|
13
|
-
statusCode: string;
|
|
14
|
-
statusDesc: string;
|
|
15
|
-
messageCode: string;
|
|
16
|
-
messageTH: string;
|
|
17
|
-
messageEN: string;
|
|
18
|
-
}
|
|
19
|
-
export interface AuthServiceResponse {
|
|
20
|
-
id: string;
|
|
21
|
-
title: string;
|
|
22
|
-
firstName: string;
|
|
23
|
-
lastName: string;
|
|
24
|
-
phoneNumber: string;
|
|
25
|
-
picture: string | null;
|
|
26
|
-
status: UserStatus;
|
|
27
|
-
accounts: Accounts[];
|
|
28
|
-
}
|
|
29
|
-
export interface Accounts {
|
|
30
|
-
account: string;
|
|
31
|
-
provider: AccountProviders;
|
|
32
|
-
type: TypeAccount;
|
|
33
|
-
status: UserStatus;
|
|
34
|
-
}
|
|
35
|
-
export declare enum TypeAccount {
|
|
36
|
-
EMAIL = "email",
|
|
37
|
-
PHONE_NUMBER = "phone_number",
|
|
38
|
-
USERNAME = "username",
|
|
39
|
-
LINE = "line",
|
|
40
|
-
LINE_OA = "line_oa"
|
|
41
|
-
}
|
|
42
|
-
export declare enum AccountProviders {
|
|
43
|
-
EMAIL = "email",
|
|
44
|
-
GOOGEL = "google"
|
|
45
|
-
}
|
|
46
|
-
export declare enum UserStatus {
|
|
47
|
-
ACTIVE = "active",
|
|
48
|
-
INACTIVE = "inactive"
|
|
49
|
-
}
|
|
50
|
-
export interface AuthServiceRequest {
|
|
51
|
-
access_token: string;
|
|
52
|
-
refresh_token?: string;
|
|
53
|
-
home_url?: string;
|
|
54
|
-
}
|
|
55
|
-
export interface ClientInfo {
|
|
56
|
-
url: string;
|
|
57
|
-
isPortal: boolean;
|
|
58
|
-
}
|
|
59
|
-
export interface ClientInit {
|
|
60
|
-
logoutUrl: string;
|
|
61
|
-
portalHomeUrl: string;
|
|
62
|
-
isPortal: boolean;
|
|
63
|
-
}
|
|
64
|
-
export interface LoginMethodRequest {
|
|
65
|
-
redirectUri: string;
|
|
66
|
-
}
|
|
1
|
+
import { AuthServiceResponse, ClientInfo, ClientInit, DisabledAccount, Options, ResponseData, UpdateProfile } from "./utils/types";
|
|
67
2
|
declare class Auth {
|
|
68
3
|
private userType;
|
|
69
4
|
private authHost;
|
|
@@ -91,6 +26,9 @@ declare class Auth {
|
|
|
91
26
|
getProfile(): Promise<AuthServiceResponse | undefined>;
|
|
92
27
|
doPortal(): Promise<void> | undefined;
|
|
93
28
|
verifyToken(): Promise<ResponseData<[]>>;
|
|
29
|
+
requestInviting(email: string): Promise<ResponseData<[]>>;
|
|
30
|
+
updateProfile(body: UpdateProfile): Promise<ResponseData<[]>>;
|
|
31
|
+
disabledAccount(body: DisabledAccount): Promise<ResponseData<[]>>;
|
|
94
32
|
}
|
|
95
33
|
declare const bedRockAuth: Auth;
|
|
96
34
|
export default bedRockAuth;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../auth.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,UAAU,EAEV,eAAe,EAEf,OAAO,EACP,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;;IAY/B,SAAS;IAIF,OAAO;IAKP,cAAc;IAKrB,OAAO,CAAC,cAAc;IAUf,OAAO,CAAC,WAAW,GAAE,MAA6B;IAalD,QAAQ,sBAOb;IAEK,UAAU,CAAC,WAAW,GAAE,MAA6B;IAc5D,OAAO,CAAC,gBAAgB;IAQX,IAAI,CAAC,OAAO,EAAE,OAAO;IAkBrB,SAAS,CAAC,IAAI,EAAE,MAAM;YAiBrB,oBAAoB;IAalC,OAAO,CAAC,QAAQ;IAIH,aAAa;YAOZ,aAAa;IAQd,WAAW;IASX,UAAU;IAahB,QAAQ;IASR,WAAW;IASX,eAAe,CAAC,KAAK,EAAE,MAAM;IAU7B,aAAa,CAAC,IAAI,EAAE,aAAa;IAoBjC,eAAe,CAAC,IAAI,EAAE,eAAe;CAW7C;AAED,QAAA,MAAM,WAAW,MAAa,CAAC;AAE/B,eAAe,WAAW,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserType } from
|
|
1
|
+
import { DisabledAccount, UpdateProfile, UserType } from "./utils/types";
|
|
2
2
|
export type AuthProps = {
|
|
3
3
|
userType?: UserType;
|
|
4
4
|
authUri: string;
|
|
@@ -11,10 +11,13 @@ export declare const doLogin: (redirectUrl?: string) => void;
|
|
|
11
11
|
export declare const doLogout: () => Promise<void>;
|
|
12
12
|
export declare const doRegister: (redirectUrl?: string) => void;
|
|
13
13
|
export declare const setCookie: (code: string) => Promise<void>;
|
|
14
|
-
export declare const getProfile: () => Promise<import("./
|
|
14
|
+
export declare const getProfile: () => Promise<import("./utils/types").AuthServiceResponse | undefined>;
|
|
15
15
|
export declare const clearCookie: () => Promise<void>;
|
|
16
16
|
export declare const getCode: () => string;
|
|
17
17
|
export declare const doPortal: () => Promise<void> | undefined;
|
|
18
18
|
export declare const getRedirectUri: () => string;
|
|
19
|
-
export declare const verifyToken: () => Promise<import("./
|
|
19
|
+
export declare const verifyToken: () => Promise<import("./utils/types").ResponseData<[]>>;
|
|
20
|
+
export declare const requestInviting: (email: string) => Promise<import("./utils/types").ResponseData<[]>>;
|
|
21
|
+
export declare const disabledAccount: (body: DisabledAccount) => Promise<import("./utils/types").ResponseData<[]>>;
|
|
22
|
+
export declare const updateProfile: (body: UpdateProfile) => Promise<import("./utils/types").ResponseData<[]>>;
|
|
20
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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":"AACA,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,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,eAAO,MAAM,eAAe,6DAMzB,SAAS,SAcX,CAAC;AAEF,eAAO,MAAM,OAAO,iBAAkB,MAAM,SAA4B,CAAC;AAEzE,eAAO,MAAM,QAAQ,qBAAsB,CAAC;AAE5C,eAAO,MAAM,UAAU,iBAAkB,MAAM,SAA+B,CAAC;AAE/E,eAAO,MAAM,SAAS,SAAU,MAAM,kBAAuB,CAAC;AAE9D,eAAO,MAAM,UAAU,wEAAwB,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,sDAA8B,CAAC;AAE5E,eAAO,MAAM,eAAe,SAAU,eAAe,sDAC3B,CAAC;AAE3B,eAAO,MAAM,aAAa,SAAU,aAAa,sDAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_fetch.d.ts","sourceRoot":"","sources":["../../../../utils/_fetch.ts"],"names":[],"mappings":"AAQA,UAAU,kBAAmB,SAAQ,WAAW;IAC9C,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED,iBAAe,WAAW,CAAC,CAAC,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,CAAC,CAAC,CA0BZ;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +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;AAE3C,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACP,YAAY,GACb,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare enum TypeAccount {
|
|
2
|
+
EMAIL = "email",
|
|
3
|
+
PHONE_NUMBER = "phone_number",
|
|
4
|
+
USERNAME = "username",
|
|
5
|
+
LINE = "line",
|
|
6
|
+
LINE_OA = "line_oa"
|
|
7
|
+
}
|
|
8
|
+
export declare enum AccountProviders {
|
|
9
|
+
EMAIL = "email",
|
|
10
|
+
GOOGEL = "google"
|
|
11
|
+
}
|
|
12
|
+
export declare enum UserStatus {
|
|
13
|
+
ACTIVE = "active",
|
|
14
|
+
INACTIVE = "inactive"
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=enum.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../../utils/enum.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,YAAY,iBAAiB;IAC7B,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED,oBAAY,gBAAgB;IAC1B,KAAK,UAAU;IACf,MAAM,WAAW;CAClB;AAED,oBAAY,UAAU;IACpB,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AccountProviders, TypeAccount, UserStatus } from "./enum";
|
|
2
|
+
export type UserType = "citizen" | "officer";
|
|
3
|
+
export interface Data {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Options {
|
|
7
|
+
authHost: string;
|
|
8
|
+
clientId: string;
|
|
9
|
+
clientSecret: string;
|
|
10
|
+
userType: UserType;
|
|
11
|
+
}
|
|
12
|
+
export interface ResponseData<T> {
|
|
13
|
+
statusResponse: StatusResponse;
|
|
14
|
+
data: T;
|
|
15
|
+
}
|
|
16
|
+
export interface StatusResponse {
|
|
17
|
+
statusCode: string;
|
|
18
|
+
statusDesc: string;
|
|
19
|
+
messageCode: string;
|
|
20
|
+
messageTH: string;
|
|
21
|
+
messageEN: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AuthServiceResponse {
|
|
24
|
+
id: string;
|
|
25
|
+
title: string;
|
|
26
|
+
firstName: string;
|
|
27
|
+
lastName: string;
|
|
28
|
+
phoneNumber: string;
|
|
29
|
+
picture: string | null;
|
|
30
|
+
status: UserStatus;
|
|
31
|
+
accounts: Accounts[];
|
|
32
|
+
}
|
|
33
|
+
export interface Accounts {
|
|
34
|
+
account: string;
|
|
35
|
+
provider: AccountProviders;
|
|
36
|
+
type: TypeAccount;
|
|
37
|
+
status: UserStatus;
|
|
38
|
+
}
|
|
39
|
+
export interface AuthServiceRequest {
|
|
40
|
+
access_token: string;
|
|
41
|
+
refresh_token?: string;
|
|
42
|
+
home_url?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface ClientInfo {
|
|
45
|
+
url: string;
|
|
46
|
+
isPortal: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface ClientInit {
|
|
49
|
+
logoutUrl: string;
|
|
50
|
+
portalHomeUrl: string;
|
|
51
|
+
isPortal: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface UpdateProfile {
|
|
54
|
+
userId: string;
|
|
55
|
+
title: string;
|
|
56
|
+
firstName: string;
|
|
57
|
+
lastName: string;
|
|
58
|
+
picture: string;
|
|
59
|
+
}
|
|
60
|
+
export interface LoginMethodRequest {
|
|
61
|
+
redirectUri: string;
|
|
62
|
+
}
|
|
63
|
+
export interface DisabledAccount {
|
|
64
|
+
userId: string;
|
|
65
|
+
isDisabled: boolean;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;CACpB;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;CACnB;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,EAAE,MAAM,CAAC;CACjB;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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const defaultHeaders = {
|
|
2
|
-
|
|
2
|
+
"Content-Type": "application/json",
|
|
3
3
|
};
|
|
4
4
|
async function customFetch(url, options = {}) {
|
|
5
5
|
const headers = {
|
|
@@ -8,16 +8,16 @@ async function customFetch(url, options = {}) {
|
|
|
8
8
|
};
|
|
9
9
|
const requestOptions = {
|
|
10
10
|
...options,
|
|
11
|
-
credentials:
|
|
12
|
-
mode: "cors"
|
|
11
|
+
credentials: "include",
|
|
12
|
+
mode: "cors",
|
|
13
13
|
};
|
|
14
14
|
requestOptions.headers = headers;
|
|
15
15
|
const response = await fetch(`${url}`, requestOptions);
|
|
16
16
|
if (!response.ok) {
|
|
17
17
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
18
18
|
}
|
|
19
|
-
const contentType = response.headers.get(
|
|
20
|
-
if (contentType && contentType.includes(
|
|
19
|
+
const contentType = response.headers.get("content-type");
|
|
20
|
+
if (contentType && contentType.includes("application/json")) {
|
|
21
21
|
return response.json();
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export var TypeAccount;
|
|
2
|
+
(function (TypeAccount) {
|
|
3
|
+
TypeAccount["EMAIL"] = "email";
|
|
4
|
+
TypeAccount["PHONE_NUMBER"] = "phone_number";
|
|
5
|
+
TypeAccount["USERNAME"] = "username";
|
|
6
|
+
TypeAccount["LINE"] = "line";
|
|
7
|
+
TypeAccount["LINE_OA"] = "line_oa";
|
|
8
|
+
})(TypeAccount || (TypeAccount = {}));
|
|
9
|
+
export var AccountProviders;
|
|
10
|
+
(function (AccountProviders) {
|
|
11
|
+
AccountProviders["EMAIL"] = "email";
|
|
12
|
+
AccountProviders["GOOGEL"] = "google";
|
|
13
|
+
})(AccountProviders || (AccountProviders = {}));
|
|
14
|
+
export var UserStatus;
|
|
15
|
+
(function (UserStatus) {
|
|
16
|
+
UserStatus["ACTIVE"] = "active";
|
|
17
|
+
UserStatus["INACTIVE"] = "inactive";
|
|
18
|
+
})(UserStatus || (UserStatus = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arv-bedrock/auth-sso",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"types": "./dist/cjs/types/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -45,4 +45,4 @@
|
|
|
45
45
|
"semantic-release": "^20.0.2",
|
|
46
46
|
"tcs": "^10.0.2"
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_fetch.d.ts","sourceRoot":"","sources":["../../../_fetch.ts"],"names":[],"mappings":"AAQA,UAAU,kBAAmB,SAAQ,WAAW;IAC5C,OAAO,CAAC,EAAE,WAAW,CAAC;CACzB;AAED,iBAAe,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,CAAC,CAAC,CA2BvF;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../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;AAE3C,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACP,YAAY,GACb,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_fetch.d.ts","sourceRoot":"","sources":["../../../_fetch.ts"],"names":[],"mappings":"AAQA,UAAU,kBAAmB,SAAQ,WAAW;IAC5C,OAAO,CAAC,EAAE,WAAW,CAAC;CACzB;AAED,iBAAe,WAAW,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,CAAC,CAAC,CA2BvF;AAED,eAAe,WAAW,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../../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;AAE3C,OAAO,EACL,OAAO,EACP,aAAa,EACb,IAAI,EACJ,oBAAoB,EACpB,OAAO,EACP,YAAY,GACb,CAAC"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|