@atomm-developer/generator-sdk 1.0.10 → 1.0.11

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.
@@ -1,7 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { t as toUtf8, f as fromUtf8 } from "./index-Dhcrx-sO.js";
4
+ import { t as toUtf8, f as fromUtf8 } from "./index-DuQGCcOW.js";
5
5
  class EventStreamSerde {
6
6
  constructor({ marshaller, serializer, deserializer, serdeContext, defaultContentType }) {
7
7
  __publicField(this, "marshaller");
@@ -2627,23 +2627,41 @@ const getBaseURL = (env) => {
2627
2627
  return BASE_URL_MAP[env] ?? BASE_URL_MAP.prod;
2628
2628
  };
2629
2629
  const TOKEN_KEY_PREFIX = "__atomm_sdk_token__";
2630
+ const TOKEN_COOKIE_DOMAIN = "";
2631
+ const TOKEN_COOKIE_PATH = "/";
2632
+ const TOKEN_COOKIE_MAX_AGE_SECONDS = 15 * 24 * 60 * 60;
2630
2633
  const getTokenKey = (appKey) => `${TOKEN_KEY_PREFIX}${appKey}`;
2634
+ const buildCookieBase = () => `Domain=${TOKEN_COOKIE_DOMAIN}; Path=${TOKEN_COOKIE_PATH}; SameSite=Lax`;
2631
2635
  const setToken = (appKey, token) => {
2632
2636
  try {
2633
- localStorage.setItem(getTokenKey(appKey), token);
2637
+ document.cookie = [
2638
+ `${getTokenKey(appKey)}=${encodeURIComponent(token)}`,
2639
+ buildCookieBase(),
2640
+ `Max-Age=${TOKEN_COOKIE_MAX_AGE_SECONDS}`
2641
+ ].join("; ");
2634
2642
  } catch {
2635
2643
  }
2636
2644
  };
2637
2645
  const getToken = (appKey) => {
2638
2646
  try {
2639
- return localStorage.getItem(getTokenKey(appKey)) || "";
2647
+ const tokenKey = getTokenKey(appKey);
2648
+ const tokenPair = document.cookie.split("; ").find((item) => item.startsWith(`${tokenKey}=`));
2649
+ if (!tokenPair) {
2650
+ return "";
2651
+ }
2652
+ return decodeURIComponent(tokenPair.slice(tokenKey.length + 1));
2640
2653
  } catch {
2641
2654
  return "";
2642
2655
  }
2643
2656
  };
2644
2657
  const clearToken = (appKey) => {
2645
2658
  try {
2646
- localStorage.removeItem(getTokenKey(appKey));
2659
+ document.cookie = [
2660
+ `${getTokenKey(appKey)}=`,
2661
+ buildCookieBase(),
2662
+ "Expires=Thu, 01 Jan 1970 00:00:00 GMT",
2663
+ "Max-Age=0"
2664
+ ].join("; ");
2647
2665
  } catch {
2648
2666
  }
2649
2667
  };
@@ -9990,7 +10008,7 @@ class AuthModule {
9990
10008
  // 公开 API
9991
10009
  // ─────────────────────────────────────────────
9992
10010
  /**
9993
- * 获取当前登录状态(同步,读本地缓存)
10011
+ * 获取当前登录状态(同步,读本地 cookie 缓存)
9994
10012
  */
9995
10013
  getStatus() {
9996
10014
  return { ...this._status };
@@ -10003,7 +10021,7 @@ class AuthModule {
10003
10021
  return getToken(this.appKey);
10004
10022
  }
10005
10023
  /**
10006
- * 外部传入 token,同步到本地缓存并刷新登录状态
10024
+ * 外部传入 token,同步到本地 cookie 缓存并刷新登录状态
10007
10025
  */
10008
10026
  async syncToken(token) {
10009
10027
  const normalizedToken = token.trim();
@@ -10069,7 +10087,7 @@ class AuthModule {
10069
10087
  // 内部方法
10070
10088
  // ─────────────────────────────────────────────
10071
10089
  /**
10072
- * 初始化时从 localStorage 恢复登录状态
10090
+ * 初始化时从 cookie 恢复登录状态
10073
10091
  * 如果 token 存在,尝试拉取用户信息验证有效性
10074
10092
  */
10075
10093
  async _restoreFromStorage() {
@@ -12308,7 +12326,7 @@ class HttpProtocol extends SerdeContext {
12308
12326
  });
12309
12327
  }
12310
12328
  async loadEventStreamCapability() {
12311
- const { EventStreamSerde } = await import("./index-Cf2OSJN2.js");
12329
+ const { EventStreamSerde } = await import("./index-DcHLmTaB.js");
12312
12330
  return new EventStreamSerde({
12313
12331
  marshaller: this.getEventStreamMarshaller(),
12314
12332
  serializer: this.serializer,
package/dist/index.d.ts CHANGED
@@ -15,7 +15,7 @@ declare class AuthModule {
15
15
  private _status;
16
16
  constructor(appKey: string, env: SdkEnv, http: AxiosInstance);
17
17
  /**
18
- * 获取当前登录状态(同步,读本地缓存)
18
+ * 获取当前登录状态(同步,读本地 cookie 缓存)
19
19
  */
20
20
  getStatus(): AuthStatus;
21
21
  /**
@@ -24,7 +24,7 @@ declare class AuthModule {
24
24
  */
25
25
  getToken(): string;
26
26
  /**
27
- * 外部传入 token,同步到本地缓存并刷新登录状态
27
+ * 外部传入 token,同步到本地 cookie 缓存并刷新登录状态
28
28
  */
29
29
  syncToken(token: string): Promise<AuthStatus>;
30
30
  /**
@@ -41,7 +41,7 @@ declare class AuthModule {
41
41
  */
42
42
  onChange(callback: AuthChangeCallback): () => void;
43
43
  /**
44
- * 初始化时从 localStorage 恢复登录状态
44
+ * 初始化时从 cookie 恢复登录状态
45
45
  * 如果 token 存在,尝试拉取用户信息验证有效性
46
46
  */
47
47
  private _restoreFromStorage;
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { G, S, T, w } from "./index-Dhcrx-sO.js";
1
+ import { G, S, T, w } from "./index-DuQGCcOW.js";
2
2
  export {
3
3
  G as GeneratorSDK,
4
4
  S as SdkError,