@open-dy/ai_coding_sdk 1.0.16 → 1.0.18
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/dist/openapi/account/certification.js +1 -0
- package/dist/openapi/account/homepage-data.js +6 -0
- package/dist/openapi/account/mobile-hash.js +1 -0
- package/dist/openapi/account/public-info.js +1 -0
- package/dist/openapi/account/realname.js +1 -0
- package/dist/openapi/business/task.js +1 -0
- package/dist/openapi/content/video-data.js +1 -0
- package/dist/openapi/core.d.ts +33 -0
- package/dist/openapi/core.js +15 -12
- package/dist/openapi/live/room.js +2 -0
- package/dist/openapi/music/collection.js +1 -0
- package/dist/openapi/relation/fans.js +4 -0
- package/dist/openapi/relation/social.js +2 -0
- package/dist/openapi/traffic/web-search.d.ts +36 -0
- package/dist/openapi/traffic/web-search.js +35 -0
- package/package.json +1 -1
- package/dist/ai_platform_llm/permission.d.ts +0 -15
- package/dist/ai_platform_llm/permission.js +0 -44
|
@@ -21,6 +21,7 @@ async function getUserItemData(params, options) {
|
|
|
21
21
|
method: 'GET',
|
|
22
22
|
queryParams: params,
|
|
23
23
|
domain: 'open.douyin.com',
|
|
24
|
+
requiresUserAuth: true,
|
|
24
25
|
}, options);
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
@@ -37,6 +38,7 @@ async function getUserFansData(params, options) {
|
|
|
37
38
|
method: 'GET',
|
|
38
39
|
queryParams: params,
|
|
39
40
|
domain: 'open.douyin.com',
|
|
41
|
+
requiresUserAuth: true,
|
|
40
42
|
}, options);
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
@@ -55,6 +57,7 @@ async function getUserLikeData(params, options) {
|
|
|
55
57
|
method: 'GET',
|
|
56
58
|
queryParams: params,
|
|
57
59
|
domain: 'open.douyin.com',
|
|
60
|
+
requiresUserAuth: true,
|
|
58
61
|
}, options);
|
|
59
62
|
}
|
|
60
63
|
/**
|
|
@@ -73,6 +76,7 @@ async function getUserCommentData(params, options) {
|
|
|
73
76
|
method: 'GET',
|
|
74
77
|
queryParams: params,
|
|
75
78
|
domain: 'open.douyin.com',
|
|
79
|
+
requiresUserAuth: true,
|
|
76
80
|
}, options);
|
|
77
81
|
}
|
|
78
82
|
/**
|
|
@@ -89,6 +93,7 @@ async function getUserShareData(params, options) {
|
|
|
89
93
|
method: 'GET',
|
|
90
94
|
queryParams: params,
|
|
91
95
|
domain: 'open.douyin.com',
|
|
96
|
+
requiresUserAuth: true,
|
|
92
97
|
}, options);
|
|
93
98
|
}
|
|
94
99
|
/**
|
|
@@ -105,5 +110,6 @@ async function getUserProfileData(params, options) {
|
|
|
105
110
|
method: 'GET',
|
|
106
111
|
queryParams: params,
|
|
107
112
|
domain: 'open.douyin.com',
|
|
113
|
+
requiresUserAuth: true,
|
|
108
114
|
}, options);
|
|
109
115
|
}
|
package/dist/openapi/core.d.ts
CHANGED
|
@@ -4,8 +4,41 @@ export interface CallOpenAPIParams {
|
|
|
4
4
|
queryParams?: Record<string, string | number | undefined> | any;
|
|
5
5
|
body?: Record<string, unknown> | any;
|
|
6
6
|
domain?: string;
|
|
7
|
+
/**
|
|
8
|
+
* 当前 OpenAPI 是否需要用户授权。
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* 当该值为 `true` 时:
|
|
12
|
+
* - SDK 会请求 `open.douyin.com`
|
|
13
|
+
* - 需要在 header 中传入用户授权后的 `access-token`
|
|
14
|
+
*
|
|
15
|
+
* 注意这里的 `access-token` 不是 SDK 自动生成的,必须先调用 `auth` 模块
|
|
16
|
+
* (如 `getUserAccessToken` / `refreshUserAccessToken`)获取,再通过 `CallOptions.accessToken`
|
|
17
|
+
* 传入当前 OpenAPI 调用。
|
|
18
|
+
*
|
|
19
|
+
* `access-token` 在有效期内可以缓存并重复使用,不需要每次调用 OpenAPI 都重新生成;
|
|
20
|
+
* 仅在 token 过期或即将过期时,再调用 `auth` 模块相关接口刷新或重新获取。
|
|
21
|
+
*/
|
|
22
|
+
requiresUserAuth?: boolean;
|
|
7
23
|
}
|
|
8
24
|
export interface CallOptions {
|
|
25
|
+
/**
|
|
26
|
+
* 用户授权后的 access_token。
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* 仅对“需要用户授权”的 OpenAPI 生效。该 token 不能由普通上游请求参数直接透传替代,
|
|
30
|
+
* 需要先通过 SDK 的 `auth` 模块完成 OAuth 换 token 后获取。
|
|
31
|
+
*
|
|
32
|
+
* 获取后可在有效期内保存并重复使用,不需要每次调用 OpenAPI 都重新生成;当 token
|
|
33
|
+
* 过期或即将过期时,再调用 `refreshUserAccessToken` 等接口刷新即可。
|
|
34
|
+
*/
|
|
35
|
+
accessToken?: string;
|
|
36
|
+
/**
|
|
37
|
+
* `accessToken` 的兼容别名。
|
|
38
|
+
*
|
|
39
|
+
* @deprecated 请改用 `accessToken`。对于需要用户授权的 OpenAPI,这里传入的值本质上也应当是
|
|
40
|
+
* 用户授权后的 `access_token`,而不是任意上游透传 token。
|
|
41
|
+
*/
|
|
9
42
|
delegateToken?: string;
|
|
10
43
|
logid?: string;
|
|
11
44
|
ppeEnv?: string;
|
package/dist/openapi/core.js
CHANGED
|
@@ -17,10 +17,13 @@ function isCloudEnvironment() {
|
|
|
17
17
|
function getCloudCallDomain(originalDomain) {
|
|
18
18
|
return CLOUD_CALL_DOMAIN_MAP[originalDomain] || originalDomain;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
function shouldUseCloudCall(domain, requiresUserAuth) {
|
|
21
|
+
return isCloudEnvironment() && !requiresUserAuth && domain in CLOUD_CALL_DOMAIN_MAP;
|
|
22
|
+
}
|
|
23
|
+
function buildUrl(path, queryParams, domain = 'open.douyin.com', requiresUserAuth) {
|
|
24
|
+
const useCloudCall = shouldUseCloudCall(domain, requiresUserAuth);
|
|
25
|
+
const finalDomain = useCloudCall ? getCloudCallDomain(domain) : domain;
|
|
26
|
+
const protocol = useCloudCall ? 'http' : 'https';
|
|
24
27
|
const url = new URL(`${protocol}://${finalDomain}${path}`);
|
|
25
28
|
if (queryParams) {
|
|
26
29
|
Object.entries(queryParams).forEach(([key, value]) => {
|
|
@@ -39,12 +42,12 @@ function buildUrl(path, queryParams, domain = 'open.douyin.com') {
|
|
|
39
42
|
function isFormDataBody(body) {
|
|
40
43
|
return typeof FormData !== 'undefined' && body instanceof FormData;
|
|
41
44
|
}
|
|
42
|
-
function buildHeaders(
|
|
45
|
+
function buildHeaders(accessToken, ppeEnv, extraHeaders = {}, body, requiresUserAuth) {
|
|
43
46
|
const headers = isFormDataBody(body)
|
|
44
47
|
? { ...extraHeaders }
|
|
45
48
|
: { 'Content-Type': 'application/json', ...extraHeaders };
|
|
46
|
-
if (!isCloudEnvironment()
|
|
47
|
-
headers['access-token'] =
|
|
49
|
+
if (accessToken && (!isCloudEnvironment() || requiresUserAuth)) {
|
|
50
|
+
headers['access-token'] = accessToken;
|
|
48
51
|
}
|
|
49
52
|
if (ppeEnv) {
|
|
50
53
|
headers['x-tt-env'] = ppeEnv;
|
|
@@ -59,16 +62,16 @@ function maskHeaders(headers) {
|
|
|
59
62
|
};
|
|
60
63
|
}
|
|
61
64
|
async function callOpenAPI(params, options) {
|
|
62
|
-
const { path, method = 'GET', queryParams, body, domain = 'open.douyin.com', } = params;
|
|
63
|
-
const
|
|
65
|
+
const { path, method = 'GET', queryParams, body, domain = 'open.douyin.com', requiresUserAuth, } = params;
|
|
66
|
+
const accessToken = options?.accessToken ?? options?.delegateToken;
|
|
64
67
|
const envPpeEnv = process.env.APP_ENV?.startsWith('ppe_') ? process.env.APP_ENV : undefined;
|
|
65
68
|
const ppeEnv = options?.ppeEnv || envPpeEnv;
|
|
66
69
|
const extraHeaders = options?.logid ? { 'x-tt-logid': options.logid } : {};
|
|
67
|
-
const url = buildUrl(path, queryParams, domain);
|
|
68
|
-
const headers = buildHeaders(
|
|
70
|
+
const url = buildUrl(path, queryParams, domain, requiresUserAuth);
|
|
71
|
+
const headers = buildHeaders(accessToken, ppeEnv, extraHeaders, body, requiresUserAuth);
|
|
69
72
|
console.log(`[OpenAPI] ${method} ${url}`);
|
|
70
73
|
console.log('[OpenAPI] Headers:', maskHeaders(headers), body);
|
|
71
|
-
console.log('[OpenAPI] Is Cloud Environment:', isCloudEnvironment());
|
|
74
|
+
console.log('[OpenAPI] Is Cloud Environment:', isCloudEnvironment(), 'Requires User Auth:', Boolean(requiresUserAuth));
|
|
72
75
|
const requestOptions = {
|
|
73
76
|
method,
|
|
74
77
|
headers,
|
|
@@ -21,6 +21,7 @@ async function getRoomRealTimeData(params, body, options) {
|
|
|
21
21
|
queryParams: params,
|
|
22
22
|
body: body ?? {},
|
|
23
23
|
domain: 'open.douyin.com',
|
|
24
|
+
requiresUserAuth: true,
|
|
24
25
|
}, options);
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
@@ -38,5 +39,6 @@ async function queryRoomData(params, body, options) {
|
|
|
38
39
|
queryParams: params,
|
|
39
40
|
body,
|
|
40
41
|
domain: 'open.douyin.com',
|
|
42
|
+
requiresUserAuth: true,
|
|
41
43
|
}, options);
|
|
42
44
|
}
|
|
@@ -19,6 +19,7 @@ async function getFansSource(params, options) {
|
|
|
19
19
|
method: 'GET',
|
|
20
20
|
queryParams: params,
|
|
21
21
|
domain: 'open.douyin.com',
|
|
22
|
+
requiresUserAuth: true,
|
|
22
23
|
}, options);
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
@@ -35,6 +36,7 @@ async function getFansProfile(params, options) {
|
|
|
35
36
|
method: 'GET',
|
|
36
37
|
queryParams: params,
|
|
37
38
|
domain: 'open.douyin.com',
|
|
39
|
+
requiresUserAuth: true,
|
|
38
40
|
}, options);
|
|
39
41
|
}
|
|
40
42
|
/**
|
|
@@ -51,6 +53,7 @@ async function getUserFansProfile(params, options) {
|
|
|
51
53
|
method: 'GET',
|
|
52
54
|
queryParams: params,
|
|
53
55
|
domain: 'open.douyin.com',
|
|
56
|
+
requiresUserAuth: true,
|
|
54
57
|
}, options);
|
|
55
58
|
}
|
|
56
59
|
/**
|
|
@@ -67,5 +70,6 @@ async function getFansFavourite(params, options) {
|
|
|
67
70
|
method: 'GET',
|
|
68
71
|
queryParams: params,
|
|
69
72
|
domain: 'open.douyin.com',
|
|
73
|
+
requiresUserAuth: true,
|
|
70
74
|
}, options);
|
|
71
75
|
}
|
|
@@ -20,6 +20,7 @@ async function checkFans(params, options) {
|
|
|
20
20
|
method: 'GET',
|
|
21
21
|
queryParams: params,
|
|
22
22
|
domain: 'open.douyin.com',
|
|
23
|
+
requiresUserAuth: true,
|
|
23
24
|
}, options);
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
@@ -36,5 +37,6 @@ async function getFriendList(params, options) {
|
|
|
36
37
|
method: 'GET',
|
|
37
38
|
queryParams: params,
|
|
38
39
|
domain: 'open.douyin.com',
|
|
40
|
+
requiresUserAuth: true,
|
|
39
41
|
}, options);
|
|
40
42
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CallOptions, OpenAPIResponse } from '../core';
|
|
2
|
+
export interface UploadSitemapRequest {
|
|
3
|
+
/** 小程序 app_id */
|
|
4
|
+
app_id: string;
|
|
5
|
+
/** 页面路径列表 */
|
|
6
|
+
page_paths: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface DeleteIndexRequest {
|
|
9
|
+
/** 小程序 app_id */
|
|
10
|
+
app_id: string;
|
|
11
|
+
/** 在控制台显示的文件名称 */
|
|
12
|
+
name: string;
|
|
13
|
+
/** 待删除路径集合 */
|
|
14
|
+
path_list: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface WebSearchOperationResponse {
|
|
17
|
+
err_no: number;
|
|
18
|
+
err_msg: string;
|
|
19
|
+
log_id: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 提交小程序页面路径
|
|
23
|
+
* - Path: `/api/apps/v1/search/upload_sitemap/`
|
|
24
|
+
* - Capability: `ma.web.search`
|
|
25
|
+
* - Scope: `ma.search`
|
|
26
|
+
* - 需要用户授权: `否`
|
|
27
|
+
*/
|
|
28
|
+
export declare function uploadSitemap(params: UploadSitemapRequest, options?: CallOptions): Promise<OpenAPIResponse<WebSearchOperationResponse>>;
|
|
29
|
+
/**
|
|
30
|
+
* 删除索引
|
|
31
|
+
* - Path: `/api/apps/v1/search/delete_index/`
|
|
32
|
+
* - Capability: `ma.web.search`
|
|
33
|
+
* - Scope: `ma.search`
|
|
34
|
+
* - 需要用户授权: `否`
|
|
35
|
+
*/
|
|
36
|
+
export declare function deleteIndex(params: DeleteIndexRequest, options?: CallOptions): Promise<OpenAPIResponse<WebSearchOperationResponse>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uploadSitemap = uploadSitemap;
|
|
4
|
+
exports.deleteIndex = deleteIndex;
|
|
5
|
+
const core_1 = require("../core");
|
|
6
|
+
/**
|
|
7
|
+
* 提交小程序页面路径
|
|
8
|
+
* - Path: `/api/apps/v1/search/upload_sitemap/`
|
|
9
|
+
* - Capability: `ma.web.search`
|
|
10
|
+
* - Scope: `ma.search`
|
|
11
|
+
* - 需要用户授权: `否`
|
|
12
|
+
*/
|
|
13
|
+
async function uploadSitemap(params, options) {
|
|
14
|
+
return (0, core_1.callOpenAPI)({
|
|
15
|
+
path: '/api/apps/v1/search/upload_sitemap/',
|
|
16
|
+
method: 'POST',
|
|
17
|
+
body: params,
|
|
18
|
+
domain: 'open.douyin.com',
|
|
19
|
+
}, options);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 删除索引
|
|
23
|
+
* - Path: `/api/apps/v1/search/delete_index/`
|
|
24
|
+
* - Capability: `ma.web.search`
|
|
25
|
+
* - Scope: `ma.search`
|
|
26
|
+
* - 需要用户授权: `否`
|
|
27
|
+
*/
|
|
28
|
+
async function deleteIndex(params, options) {
|
|
29
|
+
return (0, core_1.callOpenAPI)({
|
|
30
|
+
path: '/api/apps/v1/search/delete_index/',
|
|
31
|
+
method: 'POST',
|
|
32
|
+
body: params,
|
|
33
|
+
domain: 'open.douyin.com',
|
|
34
|
+
}, options);
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AIPlatformCallOptions, CheckMiniProgramModelPermissionRequest, CheckMiniProgramModelPermissionResponse } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* 判断小程序是否有目标模型权限。
|
|
4
|
-
* 这里保留原始响应,避免在未知响应结构上做过度假设。
|
|
5
|
-
*/
|
|
6
|
-
export declare function checkMiniProgramModelPermission(req: CheckMiniProgramModelPermissionRequest, options?: AIPlatformCallOptions): Promise<CheckMiniProgramModelPermissionResponse>;
|
|
7
|
-
/**
|
|
8
|
-
* 基于常见布尔字段做轻量归一化。
|
|
9
|
-
* 如果接口未返回这些字段,则返回 null,让上层自行读取原始响应。
|
|
10
|
-
*/
|
|
11
|
-
export declare function getMiniProgramModelPermissionStatus(response: CheckMiniProgramModelPermissionResponse): boolean | null;
|
|
12
|
-
/**
|
|
13
|
-
* 权限明确为 false 时抛错;响应里没有标准布尔字段时,只返回原始响应。
|
|
14
|
-
*/
|
|
15
|
-
export declare function assertMiniProgramModelPermission(req: CheckMiniProgramModelPermissionRequest, options?: AIPlatformCallOptions): Promise<CheckMiniProgramModelPermissionResponse>;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkMiniProgramModelPermission = checkMiniProgramModelPermission;
|
|
4
|
-
exports.getMiniProgramModelPermissionStatus = getMiniProgramModelPermissionStatus;
|
|
5
|
-
exports.assertMiniProgramModelPermission = assertMiniProgramModelPermission;
|
|
6
|
-
const core_1 = require("./core");
|
|
7
|
-
/**
|
|
8
|
-
* 判断小程序是否有目标模型权限。
|
|
9
|
-
* 这里保留原始响应,避免在未知响应结构上做过度假设。
|
|
10
|
-
*/
|
|
11
|
-
async function checkMiniProgramModelPermission(req, options) {
|
|
12
|
-
return (0, core_1.postMiniProgramModelPermission)(req, options);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* 基于常见布尔字段做轻量归一化。
|
|
16
|
-
* 如果接口未返回这些字段,则返回 null,让上层自行读取原始响应。
|
|
17
|
-
*/
|
|
18
|
-
function getMiniProgramModelPermissionStatus(response) {
|
|
19
|
-
const candidates = [
|
|
20
|
-
response.data?.allowed,
|
|
21
|
-
response.data?.allow,
|
|
22
|
-
response.data?.has_permission,
|
|
23
|
-
response.data?.can_use,
|
|
24
|
-
];
|
|
25
|
-
for (const candidate of candidates) {
|
|
26
|
-
if (typeof candidate === 'boolean') {
|
|
27
|
-
return candidate;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 权限明确为 false 时抛错;响应里没有标准布尔字段时,只返回原始响应。
|
|
34
|
-
*/
|
|
35
|
-
async function assertMiniProgramModelPermission(req, options) {
|
|
36
|
-
const response = await checkMiniProgramModelPermission(req, options);
|
|
37
|
-
const granted = getMiniProgramModelPermissionStatus(response);
|
|
38
|
-
if (granted === false) {
|
|
39
|
-
throw new Error(response.message ||
|
|
40
|
-
response.err_msg ||
|
|
41
|
-
'mini_program_model_permission_denied');
|
|
42
|
-
}
|
|
43
|
-
return response;
|
|
44
|
-
}
|