@ichaingo/token 1.2.9 → 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 CHANGED
@@ -6,7 +6,7 @@ import { ITokenManager, ITokenManagerResponse } from './type';
6
6
  * @param res
7
7
  * @returns
8
8
  */
9
- export declare const setToken: (response: NextResponse, res: ITokenManagerResponse) => NextResponse;
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;
@@ -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,UAAU,YAAY,EAAE,KAAK,qBAAqB,KAAG,YAoC7E,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"}
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 n from "js-cookie";
2
- const t = ".ichaingo.com", i = "/", a = "lax", c = process.env.NODE_ENV === "production", m = (o, e) => (o.cookies.set("access_token", e == null ? void 0 : e.access_token, {
3
- httpOnly: !1,
4
- maxAge: e == null ? void 0 : e.expires_in,
5
- domain: t,
6
- sameSite: a,
7
- secure: c,
8
- path: i
9
- }), o.cookies.set("refresh_token", e == null ? void 0 : e.refresh_token, {
10
- httpOnly: !1,
11
- maxAge: 3600 * 24 * 7,
12
- domain: t,
13
- sameSite: a,
14
- secure: c,
15
- path: i
16
- }), o.cookies.set("id_token", e == null ? void 0 : e.id_token, {
17
- httpOnly: !1,
18
- maxAge: e == null ? void 0 : e.expires_in,
19
- domain: t,
20
- sameSite: a,
21
- secure: c,
22
- path: i
23
- }), o.cookies.set("tokenExpire", (Date.now() + (e == null ? void 0 : e.expires_in) * 1e3).toString(), {
24
- httpOnly: !1,
25
- maxAge: e == null ? void 0 : e.expires_in,
26
- domain: t,
27
- sameSite: a,
28
- secure: c,
29
- path: i
30
- }), o), k = (o) => n.get(o || "id_token") || "", _ = () => {
31
- n.remove("id_token", { path: i, domain: t }), n.remove("access_token", { path: i, domain: t }), n.remove("refresh_token", { path: i, domain: t }), n.remove("sign_session", { domain: t });
32
- }, p = (o) => {
33
- n.remove(o || "id_token", { path: i, domain: t });
34
- }, h = () => {
35
- const o = Number(n.get("tokenExpire")), e = n.get("refresh_token");
36
- return isNaN(o) ? !!e : o - Date.now() < 300 * 1e3;
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: m,
39
- getToken: k,
40
- removeAllToken: _,
41
- removeTokenByKey: p,
42
- isTokenExpired: h
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
- k as getToken,
47
- h as isTokenExpired,
48
- _ as removeAllToken,
49
- m as setToken
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: (response: NextResponse, res: ITokenManagerResponse) => NextResponse;
10
+ setToken: (res: ITokenManagerResponse, response?: NextResponse | null) => NextResponse | null;
11
11
  getToken: (key?: string) => string;
12
12
  removeAllToken: () => void;
13
13
  isTokenExpired: () => boolean;
@@ -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,QAAQ,EAAE,YAAY,EAAE,GAAG,EAAE,qBAAqB,KAAK,YAAY,CAAA;IAC9E,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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ichaingo/token",
3
- "version": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",