yichong-canva2 1.4.0 → 2.1.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.
@@ -1,49 +1,78 @@
1
+ /**
2
+ * 账户服务返回的状态及 Provider 派生字段。首次登录前允许为空,使用嵌套字段前需判断是否存在。
3
+ * jwt 用于 AI 接口;账户 passport 由 Provider 私有保存,不放在此公开对象中。
4
+ */
1
5
  export interface UserStatus {
6
+ /** 账户服务颁发的 AI 接口 JWT;不同于 Canva 身份 token 和账户服务的 passport。 */
2
7
  jwt?: string;
8
+ /** 后端附带的鉴权时间信息,SDK 原样保留;仅读取这些值不会自动刷新 JWT。 */
3
9
  api_auth?: {
4
10
  time: number;
5
11
  expire_at: number;
6
12
  };
13
+ /** 系统账户资料;登录/刷新轮询以取得 profile 作为账户就绪条件。 */
7
14
  profile?: {
15
+ /** 我们系统的用户 ID,作为通用请求参数 uid;不是 Canva 的 userId。 */
8
16
  id: string;
9
17
  username: string;
10
18
  email: string;
11
19
  avatar: string;
20
+ /** 后端账户资料中的原始 token 字段;新 AI API 鉴权使用外层 jwt。 */
12
21
  token: string;
13
22
  from_app: string;
14
23
  expire_at: number;
24
+ /** 账户配置的免费与月度上限;对应已用量在 subscription 中。 */
15
25
  usage_limits: {
26
+ /** 免费额度基数;值为 -1 时 Provider 视作免费无限使用。 */
16
27
  free_limit: number;
28
+ /** 月额度上限;值为 -1 时对外额度 getter 用 null 表示无限。 */
17
29
  monthly_usage_limit: number;
18
30
  };
19
31
  };
32
+ /** 个人订阅和额度计数;字段保留后端命名,避免把积分余额和月用量混为一谈。 */
20
33
  subscription?: {
34
+ /** Provider 根据详情和 ends_at 派生 isSubscribed;无详情通常按非订阅处理。 */
21
35
  detail?: {
36
+ /** 后端提供的到期时间;Provider 用 Date 比较,无到期值时视作持续有效。 */
22
37
  ends_at: string | null | number;
38
+ /** 后端套餐名称;Provider 只按 month/year/free 关键词派生展示用 planName。 */
23
39
  name: string;
24
40
  };
41
+ /** 后端可返回此值,Provider 也会根据详情写回派生状态。 */
25
42
  is_subscribed?: boolean;
43
+ /** 积分/免费次数字段;normal 模式下负值按 free_limit + free_cnt 计算余额。 */
26
44
  free_cnt?: number;
45
+ /** 当前月已使用额度,不是剩余额度。 */
27
46
  monthly_usage_cnt?: number;
47
+ /** 已使用的免费额度,server_credits 模式用于计算免费用户余额。 */
28
48
  free_usage_cnt?: number;
49
+ /** 后端试用标记,保留数字形态;SDK 不将它转换为布尔值。 */
29
50
  on_trial?: number;
30
51
  };
52
+ /** 团队订阅原始数据;当前订阅派生逻辑只在个人 subscription.detail 存在时检查此字段。 */
31
53
  team_subscription?: {
32
54
  detail: {
33
55
  name: string;
34
56
  ends_at: string | null | number;
35
57
  };
36
58
  };
59
+ /** 历史云盘授权数据,Provider 原样保留;不是 AI 接口鉴权来源。 */
37
60
  drive?: {
38
61
  fresh_token: string;
39
62
  };
63
+ /** Canva 验证服务返回的用户 ID,作为 platform_uid;不同于 profile.id。 */
40
64
  userId?: string;
65
+ /** Provider 派生的展示标签;不能用标签代替实际订阅有效性或额度检查。 */
41
66
  planName?: 'Free' | 'Pro Monthly plan' | 'Pro Yearly plan' | 'Premium';
42
67
  }
68
+ /** 历史应用读取的全局兼容字段;新组件应使用 useYiChongCanva,避免直接依赖 window。 */
43
69
  declare global {
44
70
  interface Window {
71
+ /** 历史轮询入口;该旧声明未描述 Promise,完整参数与返回类型以 client.pollUserStatus 为准。 */
45
72
  pollUserSubscribe: () => void;
73
+ /** 从 Canva SDK 获得的身份 token,仅用于换取 Canva 用户身份。 */
46
74
  g_canva_token: string;
75
+ /** 初次登录写入的 JWT 兼容副本;后续刷新不依赖此字段,新 API 使用 Provider 内部状态。 */
47
76
  g_token: string;
48
77
  }
49
78
  }
@@ -53,7 +82,8 @@ declare global {
53
82
  * 语义:打开外部定价页后进入一段有 TTL 的轮询会话 ——
54
83
  * 快阶段每 fastIntervalMs 拉一次 status,持续 fastPhaseMs 后降频到 slowIntervalMs,
55
84
  * 检测到「相对打开定价页前基线」的订阅/额度变化即成功;
56
- * 会话满 sessionTtlMs 或手动 stopCurrentPolling() 时补拉一次 status 后 resolve。
85
+ * 在轮次之间发现 sessionTtlMs 到期,或手动 stopCurrentPolling() 后,补拉一次 status 再 resolve。
86
+ * 已发出的请求不会因 TTL 或停止操作而被取消;返回状态仍需检查,resolve 本身不表示支付成功。
57
87
  * 注意:回到 Canva 侧栏(focus / visibilitychange)不会终止会话 ——
58
88
  * Canva 拿不到定价页关闭事件,回侧栏往往表示定价页还开着。
59
89
  */
@@ -64,9 +94,12 @@ export interface CheckoutSessionOptions {
64
94
  fastPhaseMs?: number;
65
95
  /** 慢阶段轮询间隔,默认 15000ms */
66
96
  slowIntervalMs?: number;
67
- /** 会话总时长(TTL),默认 300000ms(5 分钟),到期补刷一次并 resolve */
97
+ /** 轮询调度时长(TTL),默认 300000ms(5 分钟);不限制单次在途请求,结束后另有补刷等待。 */
68
98
  sessionTtlMs?: number;
69
99
  }
100
+ /** 本地模拟模式:noTest 使用真实数据;其余分别模拟高积分、有效年订阅、已过期年订阅。 */
70
101
  export type TestMode = 'noTest' | 'credits' | 'subscribed' | 'expired';
102
+ /** 历史余额计算模式;server_credits 使用服务端用量字段和 maxAvailablePoints 派生本地余额。 */
71
103
  export type Mode = 'normal' | 'server_credits';
104
+ /** canUseLimit 的本地判断原因;不是后端错误码。undefined 表示没有拒绝原因。 */
72
105
  export type canUseError = 'userStatus_error' | 'monthly_usage_limit' | 'no_credits' | undefined;
@@ -1,27 +1,33 @@
1
1
  import { CommonRequestContext } from '../../../api/request';
2
2
  /**
3
- * 由token和appId获取用户唯一的id
4
- * @param token canva颁发的token
5
- * @param appId 当前应用的appId
6
- * @returns
3
+ * 将 Canva 身份 token 和应用 ID 交给验证服务,读取 verified.userId。
4
+ * 返回的是 Canva 平台身份,不能与账户服务 profile.id 混用;此请求尚不需要 AI JWT。
5
+ * @param token Canva SDK 当前颁发的用户 token。
6
+ * @param appId 当前 Canva 应用 ID。
7
+ * @param context 登录阶段已知的通用参数和当前语言;身份未验证前可能没有 uid/platform_uid。
8
+ * @returns 验证服务的原始 JSON,结构校验由调用方读取 verified.userId 时体现。
7
9
  */
8
10
  declare function getUserIds(token: string, appId: string, context: CommonRequestContext): Promise<any>;
9
11
  /**
10
- * 利用id登录用户
11
- * @param userId 获取到的用户唯一id
12
+ * 用已验证的 Canva ID 登录产品对应的账户;接口可能建立该应用的账户关系。
13
+ * @param userId Canva 用户 ID,写入请求体 canva_id。
14
+ * @param productName 后端渠道路径片段,必须与应用登记值一致。
15
+ * @returns 账户服务原始 JSON;此处不会把响应转成新的 ApiResponse/ApiError 约定。
12
16
  */
13
17
  declare function handleUserLoginByCanvaId(userId: string, productName: string, context: CommonRequestContext): Promise<any>;
14
18
  /**
15
- * 由id获取通行证
16
- * @param userId
17
- * @param appName
18
- * @returns
19
+ * 获取账户服务 passport,供 status 和消费请求的 X-Access-Ticket 使用。
20
+ * 优先读取 localStorage 缓存;缓存键历史上只包含 Canva userId,不包含 productName。
21
+ * 此处不主动检查过期;后续 status 缺少 profile 时,getUserProfile 会删除缓存再申请。
22
+ *
23
+ * imgkits 使用不带产品前缀的历史路径,其余产品使用产品前缀。
24
+ * @returns 命中缓存时仅返回 { data: { passport } };网络请求时返回原始 JSON 并缓存 passport。
19
25
  */
20
26
  declare function getPassport(userId: string, productName: string, context: CommonRequestContext): Promise<any>;
21
27
  /**
22
- * 由通行证获取用户信息
23
- * @param passport
24
- * @returns
28
+ * 以账户 passport 读取产品状态,响应 data 包含 profile、subscription 和 AI 请求用的 jwt。
29
+ * @param passport 账户票据;不是 Canva token,也不是 status 响应中的 jwt。
30
+ * @returns 账户服务原始 JSON;轮询层负责判断 data.profile 是否已就绪。
25
31
  */
26
32
  declare function getUserStatusByPassport(passport: string, productName: string, context: CommonRequestContext): Promise<any>;
27
33
  declare const apis: {
@@ -1,8 +1,11 @@
1
1
  import { CommonRequestContext } from '../../../api/request';
2
2
  /**
3
- * 请求json数据
4
- * @param option RequestInit & { url: string }
5
- * @returns
3
+ * 登录/账户旧协议的轻量请求层,与新 API 的 postApi 错误处理约定分开保留。
4
+ * 提供 context 时补充通用查询参数和 Accept-Language;不会自行添加 JWT 或 passport,凭据由调用方传入。
5
+ *
6
+ * @param option 完整 URL 和 fetch 选项;可由调用方传 signal,但此层不会创建超时或自动重试。
7
+ * @returns res.json() 的原始结果。HTTP 非 2xx 也会尝试解析,不检查 success/code;
8
+ * 网络错误或 JSON 解析失败直接 reject,交给登录轮询层处理,不转换成 ApiError。
6
9
  */
7
10
  declare const requestUrl: (option: RequestInit & {
8
11
  url: string;
@@ -1,16 +1,25 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { UserStatus } from '../interface';
3
3
  /**
4
- * @interface 登录组件props
4
+ * 旧登录组件的兼容类型;当前公开入口使用 YiChongCanvaProviderProps。
5
+ * 保留旧类型形状便于历史代码引用,不表示 Provider 会读取同名的 onLogin 参数。
5
6
  */
6
7
  export interface UseCanvaLoginProps {
8
+ /** 旧登录组件使用的账户就绪回调。 */
7
9
  onLogin?: (user: UserStatus) => void;
10
+ /** Canva 应用 ID,用于平台身份验证。 */
8
11
  appId: string;
12
+ /** 旧组件包裹的子节点。 */
9
13
  children?: ReactNode;
14
+ /** 后端产品渠道。 */
10
15
  productName: string;
11
16
  }
17
+ /** 历史登录 Context 声明;当前 useYiChongCanva 的完整能力见 YiChongCanvaContextType。 */
12
18
  export interface CanvaLoginContextProps {
19
+ /** 历史账户快照,未登录时可能为空。 */
13
20
  userStatus?: UserStatus;
21
+ /** Canva 平台用户 ID。 */
14
22
  userId?: string;
23
+ /** 旧版用于接收登录回调的接口;当前 Provider 使用 onUpdateUserStatus。 */
15
24
  onLogin?: (userStatus: (userStatus: UserStatus) => void) => void;
16
25
  }
@@ -1,5 +1,12 @@
1
1
  import { UserStatus } from './../interface';
2
2
  import { CommonRequestContext } from '../../api/request';
3
+ /**
4
+ * Canva token → Canva userId → 应用账户登录 → passport/status,最终返回完整账户快照。
5
+ * window.userId 已存在时沿用历史缓存,跳过 token 验证及 canvaid-login,直接读取账户状态。
6
+ *
7
+ * 成功后写入 window.g_token 兼容字段;passport 经内部回调交给 Provider,不混入公开 userStatus。
8
+ * 登录过程中任何异常都会转换成普通 Error("login failed"),此层不会保留原始接口错误详情。
9
+ */
3
10
  export declare function handleLogin({ appId, productName, onPassport, getRequestContext, }: LoginProps): Promise<UserStatus>;
4
11
  /**
5
12
  * 订阅比较基线:打开定价页「之前」的用户状态快照。
@@ -8,8 +15,11 @@ export declare function handleLogin({ appId, productName, onPassport, getRequest
8
15
  * 且 detail 为 undefined 时会误判成功(1.1.26 的现网 bug)。
9
16
  */
10
17
  export interface SubscribeBaseline {
18
+ /** 开始检查前的积分字段;缺失为 null,与 0 区分。 */
11
19
  free_cnt: number | null;
20
+ /** 订阅详情的序列化快照;无详情统一为 null,便于判断是否发生变化。 */
12
21
  detailJson: string | null;
22
+ /** 开始检查前的可用额度;无限额或无法用于数值比较时为 null。 */
13
23
  available: number | null;
14
24
  }
15
25
  /**
@@ -21,17 +31,18 @@ export interface SubscribeBaseline {
21
31
  export declare function takeSubscribeBaseline(userStatus: UserStatus): SubscribeBaseline;
22
32
  /**
23
33
  * 用「原始响应体」计算可用额度的纯函数。
24
- * 不要用 Provider 的 getLimitUsage():它读的是 React state,轮询期间不会更新。
34
+ * 不要用 Provider 的 getLimitUsage():它读的是 React state,无法代表本轮尚未合并的原始响应。
25
35
  * 口径对齐 Provider:订阅生效 = 月额度剩余(clamp 到 >=0)+ 积分;否则 = 积分。
26
- * monthly_usage_limit 为 -1(无限额度)时返回 null。
36
+ * monthly_usage_limit <= -1(无限额度)时返回 null。本函数仅比较个人订阅,不读取团队订阅。
27
37
  */
28
38
  export declare function computeAvailableLimit(userStatus: UserStatus): number | null;
29
39
  /**
30
- * 默认的「相对基线是否已付费/到账」判断(对齐 Chrome 插件 loopSubscribe 思路):
40
+ * 默认的「相对基线账户是否变化」判断,用于决定何时结束支付状态检查:
31
41
  * 1. subscription.detail 出现或变化(订阅、换套餐、续费改 ends_at,JSON 全量比较)
32
42
  * 2. free_cnt 变多(买积分包;只认「增加」——会话中在侧栏消耗积分导致的减少不算成功)
33
43
  * 3. 可用额度比基线变大(月订用户 free_cnt 常为 0,只盯它会把会话打满)
34
- * 注意:monthly_usage_cnt 自增(用量上报)不构成成功。
44
+ * 注意:monthly_usage_cnt 自增(用量上报)不构成成功;详情删除等变化也会返回 true,
45
+ * 因而此结果只表示需要更新账户视图,不是支付服务发出的交易成功确认。
35
46
  */
36
47
  export declare function isSubscribeChanged(current: UserStatus, baseline: SubscribeBaseline): boolean;
37
48
  /**
@@ -39,40 +50,65 @@ export declare function isSubscribeChanged(current: UserStatus, baseline: Subscr
39
50
  *
40
51
  * 两种模式(isSubscribe 区分):
41
52
  * - isSubscribe = false(handleLogin / refreshUserStatus):拿到带 profile 的
42
- * userStatus 立刻 successCallback 并返回,行为与 1.1.26 一致
43
- * (1.1.26 会在 finally 里多睡一轮 3s 才 resolve,属实现缺陷,已去掉;请求次数不变)。
53
+ * userStatus 立刻调用 successCallback 并返回,无需等待订阅变化。
44
54
  * - isSubscribe = true(结账会话):相对 baseline 检测订阅/额度变化,变了才成功。
45
55
  * 未传 baseline 时保持旧语义:用第一轮成功响应拍快照(但 detail 快照 bug 已修)。
46
56
  *
47
57
  * 结束方式:
48
58
  * 1. 成功:successCallback + return userStatus
49
- * 2. 手动停止(onStop 交出的函数被调用):打断等待中的 sleep,return undefined(不算失败)
59
+ * 2. 手动停止(onStop 交出的函数被调用):打断 sleep,退出循环后 return undefined;
60
+ * 已发出的请求仍可能先满足成功条件并返回账户状态
50
61
  * 3. maxCount 次数耗尽或 maxDurationMs 到期:failCallback + throw
62
+ *
63
+ * 时长/停止条件在请求之间检查,不取消在途 fetch。首次申请 passport 在轮询 try/catch 之外,
64
+ * 它若失败会直接 reject;status 请求失败则消耗一轮后继续尝试,直到次数或时长预算耗尽。
51
65
  */
52
66
  export declare function getUserProfile({ maxCount, interval, maxDurationMs, productName, userId, successCallback, failCallback, isSubscribe, baseline, isChanged, onStop, onPassport, getRequestContext, }: UserProfileProps): Promise<UserStatus | undefined>;
67
+ /** 内部账户读取/支付轮询配置;应用通常通过 client.refreshUserStatus 或 pollUserStatus 使用。 */
53
68
  export interface UserProfileProps {
69
+ /** status 尝试次数上限,默认 50;passport 请求另行发生,不包含在此计数内。 */
54
70
  maxCount?: number;
71
+ /** 两轮 status 之间的等待毫秒数,默认 3000;函数形式在每轮计算,用于支付快慢阶段切换。 */
55
72
  interval?: number | (() => number);
73
+ /** 从函数开始计算的轮询预算;默认仅受 maxCount 限制,不会打断已发出的 HTTP 请求。 */
56
74
  maxDurationMs?: number;
75
+ /** 后端登记的产品渠道,用于账户接口路径和请求上下文。 */
57
76
  productName: string;
77
+ /** Canva 用户 ID;系统用户 ID 从 status.profile.id 取得。 */
58
78
  userId: string;
79
+ /** 达到本次模式的成功条件后调用;入参尚未由此函数补写 Canva userId。 */
59
80
  successCallback?: (userStatus: UserStatus) => void;
81
+ /** 轮询预算耗尽时调用;手动停止或首次 passport 请求失败不会走此回调。 */
60
82
  failCallback?: () => void;
83
+ /** false=profile 就绪即可返回;true=持续检查相对 baseline 的订阅/额度变化,默认 false。 */
61
84
  isSubscribe?: boolean;
85
+ /** 支付前快照;提供后不被第一轮覆盖,省略时首个有效 status 仅用于建立快照。 */
62
86
  baseline?: SubscribeBaseline;
87
+ /** 订阅模式的自定义结束判定;省略时使用 isSubscribeChanged。 */
63
88
  isChanged?: (current: UserStatus, baseline: SubscribeBaseline) => boolean;
89
+ /** 取得停止调度函数;能立即唤醒 sleep,但不会取消 status/passport 网络请求。 */
64
90
  onStop?: (fn: () => void) => void;
91
+ /** status 具有 profile 后传出已验证可用的账户票据、Canva ID 和系统 ID,供 Provider 私有缓存。 */
65
92
  onPassport?: (passport: string, userId: string, uid: string) => void;
93
+ /** 每次账户请求读取最新语言/身份上下文,避免轮询闭包捕获过期值。 */
66
94
  getRequestContext?: () => CommonRequestContext;
67
95
  }
96
+ /** 内部登录参数;callback 和 requestConfig 为保留字段,当前 handleLogin 不读取它们。 */
68
97
  export interface LoginProps {
98
+ /** 历史兼容声明;当前登录结果由 Promise 返回,此回调不被调用。 */
69
99
  callback?: (state: LoginState) => void;
100
+ /** Canva 应用 ID,用于 token 验证。 */
70
101
  appId: string;
102
+ /** 后端登记的产品渠道。 */
71
103
  productName: string;
104
+ /** 历史兼容声明;当前不透传到 getUserProfile。 */
72
105
  requestConfig?: UserProfileProps;
106
+ /** 转交账户 passport 的内部回调。 */
73
107
  onPassport?: UserProfileProps["onPassport"];
108
+ /** 转交各登录阶段使用的实时请求上下文。 */
74
109
  getRequestContext?: UserProfileProps["getRequestContext"];
75
110
  }
111
+ /** 旧阶段式登录回调的数据类型,保留兼容声明;当前 handleLogin 不发出此类事件。 */
76
112
  export interface LoginState {
77
113
  status: "finish" | "error" | "start" | "user_id";
78
114
  data?: {
@@ -1,46 +1,61 @@
1
1
  import { default as React } from 'react';
2
2
  import { Mode, TestMode, UserStatus } from './interface';
3
3
  /**
4
- * @interface 参数
5
- * @property {React.ReactNode} children 子节点
6
- * @property {string} appId 应用ID
7
- * @property {string} productName 产品名称
8
- * @property {(userStatus: UserStatus) => void} onUpdateUserStatus 用户状态更新回调, 一般可以不用
9
- * @property {number} freeTimes 免费次数, 默认为1
10
- * @property {string} baseUrl 服务器地址
11
- * @property {boolean} autoLogin 自动登录, 默认为true
4
+ * 应用入口的账户与 API 配置。不同服务有独立根地址,修改其中一个不会自动改写其他服务地址。
5
+ * productName 应使用后端登记的应用渠道名称,而不是界面中可随意修改的标题。
12
6
  */
13
7
  export interface YiChongCanvaProviderProps {
8
+ /** 被包裹的业务组件;这些后代组件可通过 useYiChongCanva 读取账户和调用接口。 */
14
9
  children?: React.ReactNode;
10
+ /** Canva 应用 ID,用于验证 Canva 身份,并组成远程应用版本配置键 canva_<appId>。 */
15
11
  appId: string;
12
+ /** 后端应用渠道,影响登录路径、app_channel、X-Access-Channel 和定价页路径。 */
16
13
  productName: string;
14
+ /** 登录、成功刷新、支付检查发现变化时回调;接收该次响应,手动 updateUserStatus 不触发。 */
17
15
  onUpdateUserStatus?: (userStatus: UserStatus) => void;
16
+ /** 账户扣费地址(含所需应用路径),无默认值;登录/status 仍使用固定 usa.imgkits.com 地址。 */
18
17
  baseUrl: string;
19
- /** 预测与文本审核接口地址;baseUrl 仍用于原有账户扣费接口。 */
18
+ /** 预测与文本审核服务根地址,默认 https://api.imgkits.com;不覆盖账户、上传或 Chat 地址。 */
20
19
  apiBaseUrl?: string;
21
20
  /** 内容提取服务根地址,默认 https://ai.imgkits.com。 */
22
21
  contentBaseUrl?: string;
23
- /** R2 签名服务根地址,默认 https://ai.imgkits.com。 */
22
+ /** 大模型 Chat 服务根地址,默认 https://ai.imgkits.com。 */
23
+ chatBaseUrl?: string;
24
+ /** 既有 Cloudflare R2 签名/分片接口根地址,默认 https://ai.imgkits.com。 */
24
25
  uploadBaseUrl?: string;
25
- /** 每次 API 请求读取当前界面语言,默认使用浏览器语言。 */
26
+ /** 每次请求获取当前语言,用于 Accept-Language;缺省回退到浏览器语言,不要固定捕获过期语言。 */
26
27
  getLocale?: () => string;
28
+ /** 默认 true,挂载后自动登录;false 时由 client.handleLogin/manualLogin 显式启动。 */
27
29
  autoLogin?: boolean;
30
+ /** 初始模拟模式,默认 noTest;挂载 effect 会将开发环境设为 credits、其他环境设为 noTest。 */
28
31
  testMode?: TestMode;
32
+ /** 应用自身的数字发布版本(不是 npm 包版本);与远程版本比较以判断审核/测试阶段,运行时默认 1。 */
29
33
  version: number;
34
+ /** 本地余额计算模式,默认 normal;server_credits 按账户类型结合服务端用量计算。 */
30
35
  mode?: Mode;
36
+ /** server_credits 模式下订阅用户余额计算的总额度,默认 1;不是后端月限额的覆盖配置。 */
31
37
  maxAvailablePoints?: number;
38
+ /** 自动登录失败后的额外重试次数,默认 3;首次请求不计入,重试间隔 3 秒。 */
32
39
  retry?: number;
33
40
  }
34
41
  /**
35
- * YiChongCanvaProvider 全局登录,积分等方法提供
36
- * @param {object} params0
37
- * @param {children} params0.children 子元素
38
- * @param {string} params0.appId 应用id
39
- * @param {string} params0.productName 产品名称
40
- * @param {Function} params0.onUpdateUserStatus 用户信息更新后的回调
41
- * @param {string} params0.baseUrl 链接
42
- * @param {boolean} params0.autoLogin 是否自动登录
43
- * @param {string} params0.mode 测试模式
44
- * @returns
42
+ * 在应用入口包裹一次,为后代组件提供登录、账户额度、支付检查和后端同名 API。
43
+ *
44
+ * 登录流程依赖 Canva SDK、window 和 localStorage,应在 Canva 浏览器应用中使用。
45
+ * AI 请求使用 userStatus.jwt;账户消费使用登录过程中取得的私有 passport,两种凭据不可互换。
46
+ * Provider 只提供业务原语:生成/上传 API 不会顺带扣费,应用自行组织审核、生成和消费的先后关系。
47
+ *
48
+ * @example
49
+ * // 入口包裹已有的 App;替换为自己的 Canva App ID 和后端登记的渠道。
50
+ * <YiChongCanvaProvider
51
+ * appId="YOUR_CANVA_APP_ID"
52
+ * productName="your_channel"
53
+ * baseUrl="https://usa.imgkits.com/your_channel"
54
+ * version={1}
55
+ * >
56
+ * <App />
57
+ * </YiChongCanvaProvider>
58
+ * // App 或其子组件内:const client = useYiChongCanva();
59
+ * // 账号就绪后,直接调用 client.createSpecifyPrediction({ owner, name, input })。
45
60
  */
46
- export declare const YiChongCanvaProvider: ({ children, appId, productName, onUpdateUserStatus, baseUrl, apiBaseUrl, contentBaseUrl, uploadBaseUrl, getLocale, autoLogin, testMode: _testMode, version, mode, retry, maxAvailablePoints, }: YiChongCanvaProviderProps) => React.JSX.Element;
61
+ export declare const YiChongCanvaProvider: ({ children, appId, productName, onUpdateUserStatus, baseUrl, apiBaseUrl, contentBaseUrl, chatBaseUrl, uploadBaseUrl, getLocale, autoLogin, testMode: _testMode, version, mode, retry, maxAvailablePoints, }: YiChongCanvaProviderProps) => React.JSX.Element;
@@ -1,6 +1,9 @@
1
1
  import { YiChongCanvaContextType } from './context';
2
2
  /**
3
- * 全局钩子,用于获取上下文
4
- * @returns
3
+ * 在 React 函数组件或自定义 Hook 中读取最近一层 YiChongCanvaProvider。
4
+ * Provider 应在应用入口包裹业务组件;从返回的 client 直接调用后端同名方法即可。
5
+ *
6
+ * @returns 账户状态及 API 客户端。状态会触发组件重渲染,调用 API 时会使用最新的账户凭据。
7
+ * @remarks 缺少 Provider 时当前 Context 有默认对象:账户字段为空,后端 API 调用拒绝 provider_missing。
5
8
  */
6
9
  export declare const useYiChongCanva: () => YiChongCanvaContextType;
@@ -1,5 +1,11 @@
1
1
  import { CommonRequestContext } from '../api/request';
2
+ /** 远程配置中的应用数字版本,用于 Provider 判断审核/测试阶段,不是 npm 包的语义版本。 */
2
3
  export interface AppVersion {
3
4
  version: number;
4
5
  }
6
+ /**
7
+ * 从账户服务站点配置读取版本;Provider 使用 canva_<appId> 作为 key。
8
+ * success=false 时运行时返回空对象,Provider 会对缺少数字 version 的情况按非测试处理。
9
+ * 网络失败或配置 value 不是有效 JSON 时会 reject;此函数不重试、不缓存,也不归一化为 ApiError。
10
+ */
5
11
  export declare function getAppVersion(key: string, context?: CommonRequestContext): Promise<AppVersion>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yichong-canva2",
3
- "version": "1.4.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -24,8 +24,8 @@
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@canva/user": ">=2.1.0",
27
- "react": ">=18",
28
- "react-dom": ">=18"
27
+ "react": "^19.0.0",
28
+ "react-dom": "^19.0.0"
29
29
  },
30
30
  "dependencies": {
31
31
  "lodash": "^4.17.21"
@@ -42,9 +42,9 @@
42
42
  "eslint-plugin-react-hooks": "^5.1.0",
43
43
  "eslint-plugin-react-refresh": "^0.4.19",
44
44
  "globals": "^15.15.0",
45
- "react": "18.3.1",
46
- "react-dom": "18.3.1",
47
- "react-test-renderer": "18.3.1",
45
+ "react": "19.3.0",
46
+ "react-dom": "19.3.0",
47
+ "react-test-renderer": "19.3.0",
48
48
  "rollup-plugin-terser": "^7.0.2",
49
49
  "typescript": "~5.7.3",
50
50
  "typescript-eslint": "^8.24.1",