@ichaingo/auth 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # auth
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build auth` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test auth` to execute the unit tests via [Vitest](https://vitest.dev/).
@@ -0,0 +1,6 @@
1
+ import { default as LoginApi } from './loginApi';
2
+ import { default as TokenManager } from '@ichaingo/token';
3
+ export declare function logout(): void;
4
+ export declare function fetchUserProfile(refresh?: boolean): Promise<any> | null;
5
+ export { TokenManager, LoginApi };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,YAA0C,MAAM,iBAAiB,CAAA;AACxE,wBAAgB,MAAM,SAwBrB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,UAAQ,uBAc/C;AAED,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAA"}
package/dist/index.mjs ADDED
@@ -0,0 +1,36 @@
1
+ import r from "@ichaingo/request";
2
+ import { default as m } from "./loginApi.mjs";
3
+ import { getToken as a, removeAllToken as i } from "@ichaingo/token";
4
+ import { default as g } from "@ichaingo/token";
5
+ function u() {
6
+ r.get("/connect/logout", {
7
+ params: {
8
+ id_token_hint: a()
9
+ }
10
+ }).then((o) => {
11
+ var t;
12
+ if (((t = o == null ? void 0 : o.status) == null ? void 0 : t.code) === 0) {
13
+ i();
14
+ const e = document.createElement("iframe");
15
+ e.src = `${process.env.NEXT_PUBLIC_AUTH_URL}/en/logout`, window.addEventListener("message", (n) => {
16
+ n.data.type === "logout" && (e.remove(), window.location.pathname.includes("/user-center") ? window.location.replace(process.env.NEXT_PUBLIC_ICHAINGO_SEARCH_BASEURL || "/") : window.location.reload());
17
+ }), e.style.display = "none", document.body.appendChild(e);
18
+ }
19
+ });
20
+ }
21
+ function c(o = !1) {
22
+ if (o)
23
+ return r.get("/v2/users/profile").then((e) => {
24
+ var n;
25
+ if (((n = e == null ? void 0 : e.status) == null ? void 0 : n.code) === 0)
26
+ return e.data;
27
+ });
28
+ const t = localStorage.getItem("userProfile");
29
+ return t ? Promise.resolve(JSON.parse(t)) : null;
30
+ }
31
+ export {
32
+ m as LoginApi,
33
+ g as TokenManager,
34
+ c as fetchUserProfile,
35
+ u as logout
36
+ };
@@ -0,0 +1,4 @@
1
+ import { ILoginApi } from './type';
2
+ declare const loginApi: ILoginApi;
3
+ export default loginApi;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loginApi/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAgB,MAAM,QAAQ,CAAA;AAGhD,QAAA,MAAM,QAAQ,EAAE,SAoBf,CAAA;AACD,eAAe,QAAQ,CAAA"}
@@ -0,0 +1,11 @@
1
+ export interface ILoginApi {
2
+ login: (data: ILoginParams) => Promise<any>;
3
+ getToken: () => void;
4
+ refreshToken: () => Promise<any>;
5
+ }
6
+ export interface ILoginParams {
7
+ email: string;
8
+ password: string;
9
+ [property: string]: any;
10
+ }
11
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/loginApi/type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,YAAY,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;CAClC;AACD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAC;CACzB"}
@@ -0,0 +1,21 @@
1
+ import e from "@ichaingo/request";
2
+ import r from "js-cookie";
3
+ import { getToken as t, removeAllToken as i } from "@ichaingo/token";
4
+ const c = {
5
+ login: (o) => (i(), e.post("/api/login/email", o, {
6
+ baseURL: "/"
7
+ })),
8
+ getToken: () => {
9
+ r.set("Authorization", `Basic ${btoa("search-client:secret-search")}`), window.location.href = `/oauth2/authorize?client_id=search-client&response_type=code&scope=openid%20profile&state=test-state-123&redirect_uri=${window.location.origin}/callback`;
10
+ },
11
+ refreshToken: () => e.get("/refresh/token", {
12
+ params: {
13
+ grant_type: "refresh_token",
14
+ refresh_token: t("refresh_token")
15
+ },
16
+ baseURL: process.env.NEXT_PUBLIC_AUTH_URL
17
+ })
18
+ };
19
+ export {
20
+ c as default
21
+ };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@ichaingo/auth",
3
+ "version": "1.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.mjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "./loginApi": {
16
+ "types": "./dist/loginApi/index.d.ts",
17
+ "import": "./dist/loginApi.mjs",
18
+ "default": "./dist/loginApi.mjs"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "!**/*.tsbuildinfo"
24
+ ],
25
+ "peerDependencies": {
26
+ "js-cookie": "3.0.5",
27
+ "@ichaingo/request": "1.1.0",
28
+ "@ichaingo/token": "1.1.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/js-cookie": "^3.0.6",
32
+ "@types/next": "^9.0.0"
33
+ }
34
+ }