@atomm-developer/generator-sdk 1.0.10 → 1.0.12

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.
@@ -2627,23 +2627,39 @@ 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 = ".atomm.com";
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
+ void appKey;
2648
+ const cookies2 = document.cookie.split(";").map((part) => part.trim()).filter(Boolean);
2649
+ const utokenEntry = cookies2.find((part) => part.startsWith("utoken="));
2650
+ return utokenEntry ? decodeURIComponent(utokenEntry.slice("utoken=".length)) : "";
2640
2651
  } catch {
2641
2652
  return "";
2642
2653
  }
2643
2654
  };
2644
2655
  const clearToken = (appKey) => {
2645
2656
  try {
2646
- localStorage.removeItem(getTokenKey(appKey));
2657
+ document.cookie = [
2658
+ `${getTokenKey(appKey)}=`,
2659
+ buildCookieBase(),
2660
+ "Expires=Thu, 01 Jan 1970 00:00:00 GMT",
2661
+ "Max-Age=0"
2662
+ ].join("; ");
2647
2663
  } catch {
2648
2664
  }
2649
2665
  };
@@ -9990,7 +10006,7 @@ class AuthModule {
9990
10006
  // 公开 API
9991
10007
  // ─────────────────────────────────────────────
9992
10008
  /**
9993
- * 获取当前登录状态(同步,读本地缓存)
10009
+ * 获取当前登录状态(同步,读本地 cookie 缓存)
9994
10010
  */
9995
10011
  getStatus() {
9996
10012
  return { ...this._status };
@@ -10003,7 +10019,7 @@ class AuthModule {
10003
10019
  return getToken(this.appKey);
10004
10020
  }
10005
10021
  /**
10006
- * 外部传入 token,同步到本地缓存并刷新登录状态
10022
+ * 外部传入 token,同步到本地 cookie 缓存并刷新登录状态
10007
10023
  */
10008
10024
  async syncToken(token) {
10009
10025
  const normalizedToken = token.trim();
@@ -10069,7 +10085,7 @@ class AuthModule {
10069
10085
  // 内部方法
10070
10086
  // ─────────────────────────────────────────────
10071
10087
  /**
10072
- * 初始化时从 localStorage 恢复登录状态
10088
+ * 初始化时从 cookie 恢复登录状态
10073
10089
  * 如果 token 存在,尝试拉取用户信息验证有效性
10074
10090
  */
10075
10091
  async _restoreFromStorage() {
@@ -12308,7 +12324,7 @@ class HttpProtocol extends SerdeContext {
12308
12324
  });
12309
12325
  }
12310
12326
  async loadEventStreamCapability() {
12311
- const { EventStreamSerde } = await import("./index-Cf2OSJN2.js");
12327
+ const { EventStreamSerde } = await import("./index-C-L7AXBe.js");
12312
12328
  return new EventStreamSerde({
12313
12329
  marshaller: this.getEventStreamMarshaller(),
12314
12330
  serializer: this.serializer,
@@ -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-Bqy069_f.js";
5
5
  class EventStreamSerde {
6
6
  constructor({ marshaller, serializer, deserializer, serdeContext, defaultContentType }) {
7
7
  __publicField(this, "marshaller");
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-Bqy069_f.js";
2
2
  export {
3
3
  G as GeneratorSDK,
4
4
  S as SdkError,