@tencent-ai/workbuddy-cloud-sdk 0.1.0-dev.bc6bd2a.202608212343 → 0.1.1-dev.2eb913e.202609082341
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/README.md +28 -0
- package/lib/index.cjs +70 -19
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +77 -13
- package/lib/index.d.ts +77 -13
- package/lib/index.global.js +4 -4
- package/lib/index.global.js.map +1 -1
- package/lib/index.js +70 -19
- package/lib/index.js.map +1 -1
- package/lib/miniprogram.cjs +9752 -0
- package/lib/miniprogram.cjs.map +1 -0
- package/lib/miniprogram.d.cts +6794 -0
- package/lib/miniprogram.d.ts +6794 -0
- package/lib/miniprogram.js +9722 -0
- package/lib/miniprogram.js.map +1 -0
- package/miniprogram_dist/miniprogram.js +14737 -0
- package/package.json +33 -4
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# WorkBuddy Cloud SDK
|
|
2
|
+
|
|
3
|
+
通过 WorkBuddy 云服务的 `publicConfig` 访问 Auth、Database、Storage 和 LLM。
|
|
4
|
+
|
|
5
|
+
## 微信小程序
|
|
6
|
+
|
|
7
|
+
在小程序项目的 `package.json` 所在目录安装依赖:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @tencent-ai/workbuddy-cloud-sdk@dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
然后在微信开发者工具中执行「工具 → 构建 npm」,确认生成
|
|
14
|
+
`miniprogram_npm/@tencent-ai/workbuddy-cloud-sdk/miniprogram.js`,再点击「编译」。
|
|
15
|
+
仅写入 `package.json` 不会安装依赖;升级 SDK 后也需要重新构建 npm。
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const { createMiniProgramWorkBuddyCloud } = require('@tencent-ai/workbuddy-cloud-sdk/miniprogram');
|
|
19
|
+
|
|
20
|
+
const cloud = createMiniProgramWorkBuddyCloud({
|
|
21
|
+
endpoint: publicConfig.endpoint,
|
|
22
|
+
publishableKey: publicConfig.publishableKey,
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
SDK 通过 `package.json#miniprogram` 提供微信专用的 CommonJS `.js` 产物,
|
|
27
|
+
其中已打包运行时依赖。现有 Web / Node 的根入口和 `/miniprogram` 子入口保持不变。
|
|
28
|
+
WorkBuddy H5 预览会注入 SDK,预览成功不能替代微信项目的安装、构建 npm 验证。
|
package/lib/index.cjs
CHANGED
|
@@ -109,11 +109,11 @@ function resolveFetch(candidate) {
|
|
|
109
109
|
__name(resolveFetch, "resolveFetch");
|
|
110
110
|
function resolveRuntimeConfig(options) {
|
|
111
111
|
if (!options || typeof options !== "object") {
|
|
112
|
-
throw new WorkBuddyCloudConfigError("createWorkBuddyCloud requires
|
|
112
|
+
throw new WorkBuddyCloudConfigError("createWorkBuddyCloud requires publishableKey.");
|
|
113
113
|
}
|
|
114
114
|
return Object.freeze({
|
|
115
115
|
endpoint: resolveEndpoint(options.endpoint),
|
|
116
|
-
oauthRelayBaseUrl: normalizeHttpUrl(options.oauthRelayBaseUrl, "oauthRelayBaseUrl"),
|
|
116
|
+
oauthRelayBaseUrl: options.oauthRelayBaseUrl ? normalizeHttpUrl(options.oauthRelayBaseUrl, "oauthRelayBaseUrl") : "",
|
|
117
117
|
publishableKey: normalizePublishableKey(options.publishableKey),
|
|
118
118
|
fetch: resolveFetch(options.fetch)
|
|
119
119
|
});
|
|
@@ -157,6 +157,8 @@ var AUTH_PATHS = {
|
|
|
157
157
|
signInWithProvider: "/v1/signin/with/provider",
|
|
158
158
|
/** 本地续期端点(服务端不转发上游)。 */
|
|
159
159
|
token: "/v1/token",
|
|
160
|
+
/** 小程序微信登录:本地认人后仍需用 custom 票据换取 TCB session。 */
|
|
161
|
+
loginWechat: "/v1/login-wechat",
|
|
160
162
|
signOut: "/v1/user/signout",
|
|
161
163
|
userMe: "/v1/user/me",
|
|
162
164
|
/** 发码。 */
|
|
@@ -582,15 +584,34 @@ var AuthModule = class {
|
|
|
582
584
|
password: credentials.password
|
|
583
585
|
});
|
|
584
586
|
}
|
|
587
|
+
/**
|
|
588
|
+
* 小程序 wx.login 的 code 换 Genie session。
|
|
589
|
+
* 试用与正式是两套独立小程序,必须带当前账号的 appid
|
|
590
|
+
*(`wx.getAccountInfoSync().miniProgram.appId`)。
|
|
591
|
+
*/
|
|
592
|
+
async signInWithWechat(code, appid) {
|
|
593
|
+
if (!code) {
|
|
594
|
+
return fail(badRequest("signInWithWechat requires code"));
|
|
595
|
+
}
|
|
596
|
+
if (!appid) {
|
|
597
|
+
return fail(badRequest("signInWithWechat requires appid"));
|
|
598
|
+
}
|
|
599
|
+
return this.postForSession(AUTH_PATHS.loginWechat, {
|
|
600
|
+
code,
|
|
601
|
+
appid
|
|
602
|
+
});
|
|
603
|
+
}
|
|
585
604
|
/**
|
|
586
605
|
* 注册。
|
|
587
606
|
*
|
|
588
607
|
* 上游要求先完成验证码验证,所以必须带一个 `verificationToken`(来自
|
|
589
608
|
* `verifyOtp`)。只有用户名+密码的注册会被上游明确拒绝。
|
|
609
|
+
*
|
|
610
|
+
* 账号标识用 `email` 或 `phone`(二选一,与发码渠道一致)。
|
|
590
611
|
*/
|
|
591
612
|
async signUp(credentials) {
|
|
592
|
-
if (!credentials.email) {
|
|
593
|
-
return fail(badRequest("signUp requires email"));
|
|
613
|
+
if (!credentials.email && !credentials.phone) {
|
|
614
|
+
return fail(badRequest("signUp requires email or phone"));
|
|
594
615
|
}
|
|
595
616
|
if (!credentials.verificationToken) {
|
|
596
617
|
return fail(badRequest("signUp requires a verificationToken; run sendOtp + verifyOtp first (the provider rejects username+password-only signup)"));
|
|
@@ -598,28 +619,40 @@ var AuthModule = class {
|
|
|
598
619
|
const body = {
|
|
599
620
|
verification_token: credentials.verificationToken
|
|
600
621
|
};
|
|
601
|
-
body.
|
|
622
|
+
if (credentials.phone) body.phone_number = credentials.phone;
|
|
623
|
+
if (credentials.email) body.email = credentials.email;
|
|
602
624
|
if (credentials.password) body.password = credentials.password;
|
|
603
625
|
return this.postForSession(AUTH_PATHS.signUp, body);
|
|
604
626
|
}
|
|
605
627
|
/**
|
|
606
|
-
*
|
|
628
|
+
* 发验证码(邮箱或短信,由 `credentials` 传的字段决定)。
|
|
607
629
|
*
|
|
608
630
|
* 这一步**不产生会话**,只返回一个 `verificationId`。发码由上游完成,
|
|
609
631
|
* 我方不实现发码逻辑。
|
|
610
632
|
*
|
|
611
633
|
* 返回的 `isExistingUser` 决定验码之后走登录还是注册 —— 该判断由上游给出,
|
|
612
634
|
* SDK 不猜。
|
|
635
|
+
*
|
|
636
|
+
* 两条渠道的请求体差异是刻意的(runtime-auth-design §3.1):
|
|
637
|
+
* - 邮箱:`{ email, usage: 'EMAIL' }`
|
|
638
|
+
* - 手机:`{ phone_number, target: 'ANY' }` —— **不带 `usage`**(普通短信登录
|
|
639
|
+
* 发码时省略即可,上游没有对应的短信枚举值),`target: 'ANY'` 表示新老用户
|
|
640
|
+
* 都允许发码。
|
|
613
641
|
*/
|
|
614
642
|
async sendOtp(credentials) {
|
|
615
|
-
|
|
616
|
-
|
|
643
|
+
const body = {};
|
|
644
|
+
if (credentials.phone) {
|
|
645
|
+
body.phone_number = credentials.phone;
|
|
646
|
+
body.target = "ANY";
|
|
647
|
+
} else if (credentials.email) {
|
|
648
|
+
body.email = credentials.email;
|
|
649
|
+
body.usage = "EMAIL";
|
|
650
|
+
if (credentials.emailRedirectTo) {
|
|
651
|
+
body.email_redirect_to = credentials.emailRedirectTo;
|
|
652
|
+
}
|
|
653
|
+
} else {
|
|
654
|
+
return fail(badRequest("sendOtp requires email or phone"));
|
|
617
655
|
}
|
|
618
|
-
const body = {
|
|
619
|
-
email: credentials.email,
|
|
620
|
-
usage: "EMAIL"
|
|
621
|
-
};
|
|
622
|
-
if (credentials.emailRedirectTo) body.email_redirect_to = credentials.emailRedirectTo;
|
|
623
656
|
const res = await this.request(AUTH_PATHS.verification, {
|
|
624
657
|
method: "POST",
|
|
625
658
|
body
|
|
@@ -648,11 +681,13 @@ var AuthModule = class {
|
|
|
648
681
|
verificationId,
|
|
649
682
|
isExistingUser,
|
|
650
683
|
isUser: isExistingUser,
|
|
651
|
-
verify: /* @__PURE__ */ __name(({ token }) => this.verifyOtp({
|
|
684
|
+
verify: /* @__PURE__ */ __name(({ token, password }) => this.verifyOtp({
|
|
652
685
|
verificationId,
|
|
653
686
|
token,
|
|
654
687
|
email: credentials.email,
|
|
655
|
-
|
|
688
|
+
phone: credentials.phone,
|
|
689
|
+
isExistingUser,
|
|
690
|
+
password
|
|
656
691
|
}), "verify")
|
|
657
692
|
});
|
|
658
693
|
}
|
|
@@ -665,10 +700,14 @@ var AuthModule = class {
|
|
|
665
700
|
* 走登录还是注册由 `isExistingUser` 决定(`sendOtp` 的返回值)。刻意不做
|
|
666
701
|
* 「先试登录失败再试注册」的兜底:那会把「密码错」这类真实错误掩盖成一次
|
|
667
702
|
* 莫名的注册尝试。
|
|
703
|
+
*
|
|
704
|
+
* 登录侧邮箱与手机号共用 `username` 字段 —— 上游 `SignInRequest.username`
|
|
705
|
+
* 承载邮箱/手机/用户名三种形态(runtime-auth-design §3.2)。
|
|
668
706
|
*/
|
|
669
707
|
async verifyOtp(params) {
|
|
670
|
-
|
|
671
|
-
|
|
708
|
+
const identifier = params.phone ?? params.email ?? "";
|
|
709
|
+
if (!params.verificationId || !params.token || !identifier) {
|
|
710
|
+
return fail(badRequest("verifyOtp requires verificationId, token and either email or phone"));
|
|
672
711
|
}
|
|
673
712
|
const verified = await this.request(AUTH_PATHS.verificationVerify, {
|
|
674
713
|
method: "POST",
|
|
@@ -687,12 +726,13 @@ var AuthModule = class {
|
|
|
687
726
|
}
|
|
688
727
|
if (params.isExistingUser) {
|
|
689
728
|
return this.postForSession(AUTH_PATHS.signIn, {
|
|
690
|
-
username:
|
|
729
|
+
username: identifier,
|
|
691
730
|
verification_token: verificationToken
|
|
692
731
|
});
|
|
693
732
|
}
|
|
694
733
|
return this.signUp({
|
|
695
734
|
email: params.email,
|
|
735
|
+
phone: params.phone,
|
|
696
736
|
password: params.password ?? "",
|
|
697
737
|
verificationToken
|
|
698
738
|
});
|
|
@@ -709,8 +749,13 @@ var AuthModule = class {
|
|
|
709
749
|
*
|
|
710
750
|
* SDK 不自己跳转(不写 `location.href`):跳转时机应由应用决定 —— 有的要
|
|
711
751
|
* 先存草稿,有的在 iframe 里要开弹窗。返回 url 交调用方处置。
|
|
752
|
+
*
|
|
753
|
+
* @deprecated Google 登录已下线,新应用不应再调用该方法。
|
|
712
754
|
*/
|
|
713
755
|
async signInWithOAuth(options) {
|
|
756
|
+
if (!this.oauthRelayBaseUrl) {
|
|
757
|
+
return fail(badRequest("signInWithOAuth requires oauthRelayBaseUrl"));
|
|
758
|
+
}
|
|
714
759
|
if (options.provider !== "google") {
|
|
715
760
|
return fail(badRequest("signInWithOAuth currently supports only google"));
|
|
716
761
|
}
|
|
@@ -725,6 +770,8 @@ var AuthModule = class {
|
|
|
725
770
|
*
|
|
726
771
|
* 在回调落地页调一次即可。`code` 缺失时返回 `null` 数据而**不是**错误 ——
|
|
727
772
|
* 落地页可能被直接访问(用户收藏了它),那不是失败。
|
|
773
|
+
*
|
|
774
|
+
* @deprecated Google 登录已下线,新应用不应再调用该方法。
|
|
728
775
|
*/
|
|
729
776
|
async handleOAuthCallback(search) {
|
|
730
777
|
const callbackInput = search ?? currentPageSearch();
|
|
@@ -959,7 +1006,11 @@ var AuthModule = class {
|
|
|
959
1006
|
// ------------------------------------------------------------------
|
|
960
1007
|
// 内部
|
|
961
1008
|
// ------------------------------------------------------------------
|
|
962
|
-
/**
|
|
1009
|
+
/**
|
|
1010
|
+
* 拼出平台 Relay 授权地址;state 由 Relay 自己签发、校验并一次性消费。
|
|
1011
|
+
*
|
|
1012
|
+
* @deprecated Google 登录已下线,仅保留给存量应用的回调落地页。
|
|
1013
|
+
*/
|
|
963
1014
|
async startRelayOAuth(options, redirectTo) {
|
|
964
1015
|
const callback = new URL(redirectTo);
|
|
965
1016
|
const relay = new URL(`${this.oauthRelayBaseUrl}/authorize`);
|