@open-dy/ai_coding_sdk 1.0.22 → 1.0.24
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.
|
@@ -39,6 +39,7 @@ function getAIPlatformGatewayOrigin(appEnv = getAIPlatformAppEnv()) {
|
|
|
39
39
|
if (appEnv === 'DEV') {
|
|
40
40
|
return `https://${OPENAPI_ORIGIN}`;
|
|
41
41
|
}
|
|
42
|
+
// 抖音云环境统一走云代理域名,避免业务侧直连 open.douyin.com。
|
|
42
43
|
const mappedDomain = CLOUD_CALL_DOMAIN_MAP[OPENAPI_ORIGIN] ?? OPENAPI_ORIGIN;
|
|
43
44
|
return `http://${mappedDomain}`;
|
|
44
45
|
}
|
package/dist/auth/core.js
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.callAuthAPI = callAuthAPI;
|
|
4
|
+
const CLOUD_CALL_DOMAIN_MAP = {
|
|
5
|
+
'open.douyin.com': 'open-douyin-com.openapi.dyc.ivolces.com',
|
|
6
|
+
};
|
|
7
|
+
function getCloudEnv() {
|
|
8
|
+
const cloudEnv = process.env.CLOUD_ENV?.trim();
|
|
9
|
+
return cloudEnv ? cloudEnv : undefined;
|
|
10
|
+
}
|
|
11
|
+
function isCloudEnvironment() {
|
|
12
|
+
return process.env.APP_ENV !== 'DEV' || Boolean(getCloudEnv());
|
|
13
|
+
}
|
|
14
|
+
function getCloudCallDomain(originalDomain) {
|
|
15
|
+
return CLOUD_CALL_DOMAIN_MAP[originalDomain] || originalDomain;
|
|
16
|
+
}
|
|
4
17
|
function buildUrl(path, domain = 'open.douyin.com') {
|
|
5
|
-
|
|
18
|
+
const useCloudCall = isCloudEnvironment() && domain in CLOUD_CALL_DOMAIN_MAP;
|
|
19
|
+
const finalDomain = useCloudCall ? getCloudCallDomain(domain) : domain;
|
|
20
|
+
const protocol = useCloudCall ? 'http' : 'https';
|
|
21
|
+
return new URL(`${protocol}://${finalDomain}${path}`).toString();
|
|
6
22
|
}
|
|
7
23
|
function toFormBody(body) {
|
|
8
24
|
if (body instanceof URLSearchParams) {
|
|
@@ -43,6 +59,7 @@ async function callAuthAPI(params, options) {
|
|
|
43
59
|
console.log(`[Auth] ${method} ${url}`);
|
|
44
60
|
console.log('[Auth] Headers:', headers);
|
|
45
61
|
console.log('[Auth] Body:', maskBody(requestBody));
|
|
62
|
+
console.log('[Auth] Is Cloud Environment:', isCloudEnvironment());
|
|
46
63
|
try {
|
|
47
64
|
const response = await fetch(url, {
|
|
48
65
|
method,
|
|
@@ -8,7 +8,7 @@ const core_1 = require("../core");
|
|
|
8
8
|
* - Path: `/dy_open_api/v1/video/pack/`
|
|
9
9
|
* - Capability: `dy.open.aweme.video.pack`
|
|
10
10
|
* - Scope: `aweme.video.pack`
|
|
11
|
-
* - 需要用户授权:
|
|
11
|
+
* - 需要用户授权: 否
|
|
12
12
|
*
|
|
13
13
|
* @remarks 获取视频的基本信息摘要、作者信息、锚点信息等字段,不合规视频会被过滤。
|
|
14
14
|
*/
|
|
@@ -18,6 +18,5 @@ async function getVideoPack(params, options) {
|
|
|
18
18
|
method: 'GET',
|
|
19
19
|
queryParams: params,
|
|
20
20
|
domain: 'open.douyin.com',
|
|
21
|
-
requiresUserAuth: true,
|
|
22
21
|
}, options);
|
|
23
22
|
}
|
package/dist/openapi/core.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface CallOpenAPIParams {
|
|
|
9
9
|
*
|
|
10
10
|
* @remarks
|
|
11
11
|
* 当该值为 `true` 时:
|
|
12
|
-
* -
|
|
12
|
+
* - 云环境下仍然统一走抖音云代理域名
|
|
13
13
|
* - 需要在 header 中传入用户授权后的 `access-token`
|
|
14
14
|
*
|
|
15
15
|
* 注意这里的 `access-token` 不是 SDK 自动生成的,必须先调用 `auth` 模块
|
|
@@ -37,7 +37,7 @@ export interface CallOptions {
|
|
|
37
37
|
* `accessToken` 的兼容别名。
|
|
38
38
|
*
|
|
39
39
|
* @deprecated 请改用 `accessToken`。对于需要用户授权的 OpenAPI,这里传入的值本质上也应当是
|
|
40
|
-
* 用户授权后的 `access_token
|
|
40
|
+
* 用户授权后的 `access_token`,或封闭域入口已获取的 `x-dy-delegatetoken`。
|
|
41
41
|
*/
|
|
42
42
|
delegateToken?: string;
|
|
43
43
|
logid?: string;
|
package/dist/openapi/core.js
CHANGED
|
@@ -17,11 +17,11 @@ function isCloudEnvironment() {
|
|
|
17
17
|
function getCloudCallDomain(originalDomain) {
|
|
18
18
|
return CLOUD_CALL_DOMAIN_MAP[originalDomain] || originalDomain;
|
|
19
19
|
}
|
|
20
|
-
function shouldUseCloudCall(domain
|
|
21
|
-
return isCloudEnvironment() &&
|
|
20
|
+
function shouldUseCloudCall(domain) {
|
|
21
|
+
return isCloudEnvironment() && domain in CLOUD_CALL_DOMAIN_MAP;
|
|
22
22
|
}
|
|
23
|
-
function buildUrl(path, queryParams, domain = 'open.douyin.com'
|
|
24
|
-
const useCloudCall = shouldUseCloudCall(domain
|
|
23
|
+
function buildUrl(path, queryParams, domain = 'open.douyin.com') {
|
|
24
|
+
const useCloudCall = shouldUseCloudCall(domain);
|
|
25
25
|
const finalDomain = useCloudCall ? getCloudCallDomain(domain) : domain;
|
|
26
26
|
const protocol = useCloudCall ? 'http' : 'https';
|
|
27
27
|
const url = new URL(`${protocol}://${finalDomain}${path}`);
|
|
@@ -42,11 +42,11 @@ function buildUrl(path, queryParams, domain = 'open.douyin.com', requiresUserAut
|
|
|
42
42
|
function isFormDataBody(body) {
|
|
43
43
|
return typeof FormData !== 'undefined' && body instanceof FormData;
|
|
44
44
|
}
|
|
45
|
-
function buildHeaders(accessToken, ppeEnv, extraHeaders = {}, body
|
|
45
|
+
function buildHeaders(accessToken, ppeEnv, extraHeaders = {}, body) {
|
|
46
46
|
const headers = isFormDataBody(body)
|
|
47
47
|
? { ...extraHeaders }
|
|
48
48
|
: { 'Content-Type': 'application/json', ...extraHeaders };
|
|
49
|
-
if (accessToken
|
|
49
|
+
if (accessToken) {
|
|
50
50
|
headers['access-token'] = accessToken;
|
|
51
51
|
}
|
|
52
52
|
if (ppeEnv) {
|
|
@@ -98,11 +98,11 @@ async function callOpenAPI(params, options) {
|
|
|
98
98
|
const envPpeEnv = process.env.APP_ENV?.startsWith('ppe_') ? process.env.APP_ENV : undefined;
|
|
99
99
|
const ppeEnv = options?.ppeEnv || envPpeEnv;
|
|
100
100
|
const extraHeaders = options?.logid ? { 'x-tt-logid': options.logid } : {};
|
|
101
|
-
const url = buildUrl(path, queryParams, domain
|
|
102
|
-
const headers = buildHeaders(accessToken, ppeEnv, extraHeaders, body
|
|
101
|
+
const url = buildUrl(path, queryParams, domain);
|
|
102
|
+
const headers = buildHeaders(accessToken, ppeEnv, extraHeaders, body);
|
|
103
103
|
console.log(`[OpenAPI] ${method} ${url}`);
|
|
104
104
|
console.log('[OpenAPI] Headers:', maskHeaders(headers), body);
|
|
105
|
-
console.log('[OpenAPI] Is Cloud Environment:', isCloudEnvironment(), 'Requires User Auth:', Boolean(requiresUserAuth));
|
|
105
|
+
console.log('[OpenAPI] Is Cloud Environment:', isCloudEnvironment(), 'Requires User Auth:', Boolean(requiresUserAuth), 'Has Access Token:', Boolean(accessToken));
|
|
106
106
|
const requestOptions = {
|
|
107
107
|
method,
|
|
108
108
|
headers,
|