@ichaingo/token 1.2.8 → 1.3.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/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +48 -45
- package/dist/type.d.ts +1 -1
- package/dist/type.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ITokenManager, ITokenManagerResponse } from './type';
|
|
|
6
6
|
* @param res
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
export declare const setToken: (
|
|
9
|
+
export declare const setToken: (res: ITokenManagerResponse, response?: NextResponse | null) => NextResponse | null;
|
|
10
10
|
export declare const getToken: (key?: string) => string;
|
|
11
11
|
export declare const removeAllToken: () => void;
|
|
12
12
|
export declare const isTokenExpired: () => boolean;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAQ9D;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAQ9D;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,qBAAqB,EAAE,WAAW,YAAY,GAAG,IAAI,KAAG,YAAY,GAAG,IA2CpG,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,WAEpC,CAAA;AAED,eAAO,MAAM,cAAc,YAK1B,CAAA;AAID,eAAO,MAAM,cAAc,eAQ1B,CAAA;AACD,QAAA,MAAM,YAAY,EAAE,aAMnB,CAAA;AACD,eAAe,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
1
|
-
import
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
import t from "js-cookie";
|
|
2
|
+
const o = ".ichaingo.com", n = "/", c = "lax", m = process.env.NODE_ENV === "production", k = (e, i) => {
|
|
3
|
+
let a = t;
|
|
4
|
+
return i && (a = i.cookies), a.set("access_token", e == null ? void 0 : e.access_token, {
|
|
5
|
+
httpOnly: !1,
|
|
6
|
+
maxAge: e == null ? void 0 : e.expires_in,
|
|
7
|
+
domain: o,
|
|
8
|
+
sameSite: c,
|
|
9
|
+
secure: m,
|
|
10
|
+
path: n
|
|
11
|
+
}), a.set("refresh_token", e == null ? void 0 : e.refresh_token, {
|
|
12
|
+
httpOnly: !1,
|
|
13
|
+
maxAge: 3600 * 24 * 7,
|
|
14
|
+
domain: o,
|
|
15
|
+
sameSite: c,
|
|
16
|
+
secure: m,
|
|
17
|
+
path: n
|
|
18
|
+
}), a.set("id_token", e == null ? void 0 : e.id_token, {
|
|
19
|
+
httpOnly: !1,
|
|
20
|
+
maxAge: e == null ? void 0 : e.expires_in,
|
|
21
|
+
domain: o,
|
|
22
|
+
sameSite: c,
|
|
23
|
+
secure: m,
|
|
24
|
+
path: n
|
|
25
|
+
}), a.set("tokenExpire", (Date.now() + (e == null ? void 0 : e.expires_in) * 1e3).toString(), {
|
|
26
|
+
httpOnly: !1,
|
|
27
|
+
maxAge: e == null ? void 0 : e.expires_in,
|
|
28
|
+
domain: o,
|
|
29
|
+
sameSite: c,
|
|
30
|
+
secure: m,
|
|
31
|
+
path: n
|
|
32
|
+
}), i || null;
|
|
33
|
+
}, _ = (e) => t.get(e || "id_token") || "", p = () => {
|
|
34
|
+
t.remove("id_token", { path: n, domain: o }), t.remove("access_token", { path: n, domain: o }), t.remove("refresh_token", { path: n, domain: o }), t.remove("sign_session", { domain: o });
|
|
35
|
+
}, h = (e) => {
|
|
36
|
+
t.remove(e || "id_token", { path: n, domain: o });
|
|
37
|
+
}, d = () => {
|
|
38
|
+
const e = Number(t.get("tokenExpire")), i = t.get("refresh_token");
|
|
39
|
+
return isNaN(e) ? !!i : e - Date.now() < 300 * 1e3;
|
|
37
40
|
}, s = {
|
|
38
|
-
setToken:
|
|
39
|
-
getToken:
|
|
40
|
-
removeAllToken:
|
|
41
|
-
removeTokenByKey:
|
|
42
|
-
isTokenExpired:
|
|
41
|
+
setToken: k,
|
|
42
|
+
getToken: _,
|
|
43
|
+
removeAllToken: p,
|
|
44
|
+
removeTokenByKey: h,
|
|
45
|
+
isTokenExpired: d
|
|
43
46
|
};
|
|
44
47
|
export {
|
|
45
48
|
s as default,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
_ as getToken,
|
|
50
|
+
d as isTokenExpired,
|
|
51
|
+
p as removeAllToken,
|
|
52
|
+
k as setToken
|
|
50
53
|
};
|
package/dist/type.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface ITokenManagerResponse {
|
|
|
7
7
|
token_type: string;
|
|
8
8
|
}
|
|
9
9
|
export interface ITokenManager {
|
|
10
|
-
setToken: (
|
|
10
|
+
setToken: (res: ITokenManagerResponse, response?: NextResponse | null) => NextResponse | null;
|
|
11
11
|
getToken: (key?: string) => string;
|
|
12
12
|
removeAllToken: () => void;
|
|
13
13
|
isTokenExpired: () => boolean;
|
package/dist/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB;AACD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB;AACD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,CAAC,GAAG,EAAE,qBAAqB,EAAE,QAAQ,CAAC,EAAE,YAAY,GAAG,IAAI,KAAK,YAAY,GAAG,IAAI,CAAA;IAC7F,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,MAAM,CAAA;IAClC,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,cAAc,EAAE,MAAM,OAAO,CAAA;IAC7B,gBAAgB,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CACzC"}
|