@yongdall/user-cookie 0.6.2 → 0.6.4

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/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@yongdall/user-cookie",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "dependencies": {
5
- "@yongdall/http": "^0.6.2",
6
- "@yongdall/core": "^0.6.2",
7
- "@yongdall/user-status-token": "^0.6.2"
5
+ "@yongdall/http": "^0.6.4",
6
+ "@yongdall/core": "^0.6.4"
8
7
  }
9
8
  }
package/yongdall/user.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { existUser } from "@yongdall/core";
2
- import * as UserStatusToken from "@yongdall/user-status-token";
1
+ import { IdentityToken, existUser } from "@yongdall/core";
3
2
  import { k99Context } from "@yongdall/http";
4
3
 
5
4
  //#region plugins/user-cookie/yongdall/user.mts
@@ -11,7 +10,7 @@ const get = async () => {
11
10
  if (ctx.requestHeaders.get("X-Cookie-Auth")?.trim().toLowerCase() === "disabled") return null;
12
11
  const cookie = ctx.cookies[userLoggedCookie];
13
12
  if (!cookie) return null;
14
- const userInfo = await UserStatusToken.parse(cookie, cookieTime);
13
+ const userInfo = await IdentityToken.parse(cookie, cookieTime);
15
14
  if (!userInfo) {
16
15
  ctx.clearCookie(userLoggedCookie, {
17
16
  httpOnly: true,
@@ -21,7 +20,7 @@ const get = async () => {
21
20
  }
22
21
  const [userId, percent] = userInfo;
23
22
  if (!existUser(userId)) return null;
24
- if (percent > 2 / 3) ctx.setCookie(userLoggedCookie, await UserStatusToken.create(userId), {
23
+ if (percent > 2 / 3) ctx.setCookie(userLoggedCookie, await IdentityToken.create(userId), {
25
24
  httpOnly: true,
26
25
  path: "/"
27
26
  });
@@ -31,7 +30,7 @@ const set = async (userId) => {
31
30
  if (!userId) return null;
32
31
  const ctx = k99Context();
33
32
  if (!ctx) return null;
34
- ctx.setCookie(userLoggedCookie, await UserStatusToken.create(userId), {
33
+ ctx.setCookie(userLoggedCookie, await IdentityToken.create(userId), {
35
34
  httpOnly: true,
36
35
  path: "/"
37
36
  });
@@ -42,7 +41,7 @@ const login = async (userId) => {
42
41
  const ctx = k99Context();
43
42
  if (!ctx) return null;
44
43
  if (ctx.requestHeaders.get("X-Cookie-Auth")?.trim().toLowerCase() === "disabled") return null;
45
- ctx.setCookie(userLoggedCookie, await UserStatusToken.create(userId), {
44
+ ctx.setCookie(userLoggedCookie, await IdentityToken.create(userId), {
46
45
  httpOnly: true,
47
46
  path: "/"
48
47
  });
@@ -1 +1 @@
1
- {"version":3,"file":"user.mjs","names":[],"sources":["../../../plugins/user-cookie/yongdall/user.mts"],"sourcesContent":["import type { UserManager } from '@yongdall/core'\n\nimport { existUser } from '@yongdall/core';\nimport * as UserStatusToken from '@yongdall/user-status-token';\n\nimport { k99Context } from '@yongdall/http';\n\nconst userLoggedCookie = 'user-logged-token';\nconst cookieTime = 24 * 60 * 60 * 1000;\n\nexport const get: UserManager['get'] = async () => {\n\tconst ctx = k99Context();\n\tif (!ctx) { return null; }\n\tconst cookieAuth = ctx.requestHeaders.get('X-Cookie-Auth')?.trim().toLowerCase()\n\tif (cookieAuth === 'disabled') { return null; }\n\tconst cookie = ctx.cookies[userLoggedCookie];\n\tif (!cookie) { return null; }\n\tconst userInfo = await UserStatusToken.parse(cookie, cookieTime);\n\tif (!userInfo) { ctx.clearCookie(userLoggedCookie, { httpOnly: true, path: '/' }); return null; }\n\tconst [userId, percent] = userInfo;\n\tif (!existUser(userId)) { return null; }\n\tif (percent > 2 / 3) { ctx.setCookie(userLoggedCookie, await UserStatusToken.create(userId), { httpOnly: true, path: '/' }); }\n\treturn userId;\n};\n\nexport const set: UserManager['set'] = async (userId) => {\n\tif (!userId) { return null; }\n\tconst ctx = k99Context();\n\tif (!ctx) { return null; }\n\tctx.setCookie(userLoggedCookie, await UserStatusToken.create(userId), { httpOnly: true, path: '/' });\n\treturn true;\n};\n\nexport const login: UserManager['login'] = async (userId) => {\n\tif (!userId) { return null; }\n\tconst ctx = k99Context();\n\tif (!ctx) { return null; }\n\tconst cookieAuth = ctx.requestHeaders.get('X-Cookie-Auth')?.trim().toLowerCase()\n\tif (cookieAuth === 'disabled') { return null; }\n\tctx.setCookie(userLoggedCookie, await UserStatusToken.create(userId), { httpOnly: true, path: '/' });\n\treturn true;\n};\n\nexport const exit: UserManager['exit'] = () => {\n\tconst ctx = k99Context();\n\tif (!ctx) { return null; }\n\tctx.clearCookie(userLoggedCookie, { httpOnly: true, path: '/' });\n\treturn null;\n};\n"],"mappings":";;;;;AAOA,MAAM,mBAAmB;AACzB,MAAM,aAAa,OAAU,KAAK;AAElC,MAAa,MAA0B,YAAY;CAClD,MAAM,MAAM,YAAY;AACxB,KAAI,CAAC,IAAO,QAAO;AAEnB,KADmB,IAAI,eAAe,IAAI,gBAAgB,EAAE,MAAM,CAAC,aAAa,KAC7D,WAAc,QAAO;CACxC,MAAM,SAAS,IAAI,QAAQ;AAC3B,KAAI,CAAC,OAAU,QAAO;CACtB,MAAM,WAAW,MAAM,gBAAgB,MAAM,QAAQ,WAAW;AAChE,KAAI,CAAC,UAAU;AAAE,MAAI,YAAY,kBAAkB;GAAE,UAAU;GAAM,MAAM;GAAK,CAAC;AAAE,SAAO;;CAC1F,MAAM,CAAC,QAAQ,WAAW;AAC1B,KAAI,CAAC,UAAU,OAAO,CAAI,QAAO;AACjC,KAAI,UAAU,IAAI,EAAK,KAAI,UAAU,kBAAkB,MAAM,gBAAgB,OAAO,OAAO,EAAE;EAAE,UAAU;EAAM,MAAM;EAAK,CAAC;AAC3H,QAAO;;AAGR,MAAa,MAA0B,OAAO,WAAW;AACxD,KAAI,CAAC,OAAU,QAAO;CACtB,MAAM,MAAM,YAAY;AACxB,KAAI,CAAC,IAAO,QAAO;AACnB,KAAI,UAAU,kBAAkB,MAAM,gBAAgB,OAAO,OAAO,EAAE;EAAE,UAAU;EAAM,MAAM;EAAK,CAAC;AACpG,QAAO;;AAGR,MAAa,QAA8B,OAAO,WAAW;AAC5D,KAAI,CAAC,OAAU,QAAO;CACtB,MAAM,MAAM,YAAY;AACxB,KAAI,CAAC,IAAO,QAAO;AAEnB,KADmB,IAAI,eAAe,IAAI,gBAAgB,EAAE,MAAM,CAAC,aAAa,KAC7D,WAAc,QAAO;AACxC,KAAI,UAAU,kBAAkB,MAAM,gBAAgB,OAAO,OAAO,EAAE;EAAE,UAAU;EAAM,MAAM;EAAK,CAAC;AACpG,QAAO;;AAGR,MAAa,aAAkC;CAC9C,MAAM,MAAM,YAAY;AACxB,KAAI,CAAC,IAAO,QAAO;AACnB,KAAI,YAAY,kBAAkB;EAAE,UAAU;EAAM,MAAM;EAAK,CAAC;AAChE,QAAO"}
1
+ {"version":3,"file":"user.mjs","names":[],"sources":["../../../plugins/user-cookie/yongdall/user.mts"],"sourcesContent":["import type { UserManager } from '@yongdall/core'\n\nimport { existUser, IdentityToken } from '@yongdall/core';\n\nimport { k99Context } from '@yongdall/http';\n\nconst userLoggedCookie = 'user-logged-token';\nconst cookieTime = 24 * 60 * 60 * 1000;\n\nexport const get: UserManager['get'] = async () => {\n\tconst ctx = k99Context();\n\tif (!ctx) { return null; }\n\tconst cookieAuth = ctx.requestHeaders.get('X-Cookie-Auth')?.trim().toLowerCase()\n\tif (cookieAuth === 'disabled') { return null; }\n\tconst cookie = ctx.cookies[userLoggedCookie];\n\tif (!cookie) { return null; }\n\tconst userInfo = await IdentityToken.parse(cookie, cookieTime);\n\tif (!userInfo) { ctx.clearCookie(userLoggedCookie, { httpOnly: true, path: '/' }); return null; }\n\tconst [userId, percent] = userInfo;\n\tif (!existUser(userId)) { return null; }\n\tif (percent > 2 / 3) { ctx.setCookie(userLoggedCookie, await IdentityToken.create(userId), { httpOnly: true, path: '/' }); }\n\treturn userId;\n};\n\nexport const set: UserManager['set'] = async (userId) => {\n\tif (!userId) { return null; }\n\tconst ctx = k99Context();\n\tif (!ctx) { return null; }\n\tctx.setCookie(userLoggedCookie, await IdentityToken.create(userId), { httpOnly: true, path: '/' });\n\treturn true;\n};\n\nexport const login: UserManager['login'] = async (userId) => {\n\tif (!userId) { return null; }\n\tconst ctx = k99Context();\n\tif (!ctx) { return null; }\n\tconst cookieAuth = ctx.requestHeaders.get('X-Cookie-Auth')?.trim().toLowerCase()\n\tif (cookieAuth === 'disabled') { return null; }\n\tctx.setCookie(userLoggedCookie, await IdentityToken.create(userId), { httpOnly: true, path: '/' });\n\treturn true;\n};\n\nexport const exit: UserManager['exit'] = () => {\n\tconst ctx = k99Context();\n\tif (!ctx) { return null; }\n\tctx.clearCookie(userLoggedCookie, { httpOnly: true, path: '/' });\n\treturn null;\n};\n"],"mappings":";;;;AAMA,MAAM,mBAAmB;AACzB,MAAM,aAAa,OAAU,KAAK;AAElC,MAAa,MAA0B,YAAY;CAClD,MAAM,MAAM,YAAY;AACxB,KAAI,CAAC,IAAO,QAAO;AAEnB,KADmB,IAAI,eAAe,IAAI,gBAAgB,EAAE,MAAM,CAAC,aAAa,KAC7D,WAAc,QAAO;CACxC,MAAM,SAAS,IAAI,QAAQ;AAC3B,KAAI,CAAC,OAAU,QAAO;CACtB,MAAM,WAAW,MAAM,cAAc,MAAM,QAAQ,WAAW;AAC9D,KAAI,CAAC,UAAU;AAAE,MAAI,YAAY,kBAAkB;GAAE,UAAU;GAAM,MAAM;GAAK,CAAC;AAAE,SAAO;;CAC1F,MAAM,CAAC,QAAQ,WAAW;AAC1B,KAAI,CAAC,UAAU,OAAO,CAAI,QAAO;AACjC,KAAI,UAAU,IAAI,EAAK,KAAI,UAAU,kBAAkB,MAAM,cAAc,OAAO,OAAO,EAAE;EAAE,UAAU;EAAM,MAAM;EAAK,CAAC;AACzH,QAAO;;AAGR,MAAa,MAA0B,OAAO,WAAW;AACxD,KAAI,CAAC,OAAU,QAAO;CACtB,MAAM,MAAM,YAAY;AACxB,KAAI,CAAC,IAAO,QAAO;AACnB,KAAI,UAAU,kBAAkB,MAAM,cAAc,OAAO,OAAO,EAAE;EAAE,UAAU;EAAM,MAAM;EAAK,CAAC;AAClG,QAAO;;AAGR,MAAa,QAA8B,OAAO,WAAW;AAC5D,KAAI,CAAC,OAAU,QAAO;CACtB,MAAM,MAAM,YAAY;AACxB,KAAI,CAAC,IAAO,QAAO;AAEnB,KADmB,IAAI,eAAe,IAAI,gBAAgB,EAAE,MAAM,CAAC,aAAa,KAC7D,WAAc,QAAO;AACxC,KAAI,UAAU,kBAAkB,MAAM,cAAc,OAAO,OAAO,EAAE;EAAE,UAAU;EAAM,MAAM;EAAK,CAAC;AAClG,QAAO;;AAGR,MAAa,aAAkC;CAC9C,MAAM,MAAM,YAAY;AACxB,KAAI,CAAC,IAAO,QAAO;AACnB,KAAI,YAAY,kBAAkB;EAAE,UAAU;EAAM,MAAM;EAAK,CAAC;AAChE,QAAO"}