@apicity/tiktok-creative-center 0.0.0-stage → 0.20.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Justin Tanner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # @apicity/tiktok-creative-center
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/@apicity/tiktok-creative-center?color=cb0000)](https://www.npmjs.com/package/@apicity/tiktok-creative-center)
4
+ [![dependencies](https://img.shields.io/badge/dependencies-1-blue)](package.json)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-strict-blue?logo=typescript&logoColor=white)](tsconfig.json)
6
+ [![docs](https://img.shields.io/badge/docs-ads.tiktok.com-blue)](https://ads.tiktok.com/creative/creativeCenter/trends/video)
7
+
8
+ TikTok Creative Center trending videos provider (unofficial, undocumented endpoints).
9
+
10
+ These are unofficial, undocumented endpoints behind TikTok Creative Center's Trending videos page (https://ads.tiktok.com/creative/creativeCenter/trends/video), and TikTok can change or remove them without notice. They need no key. Without a TikTok One session every list holds the top 4 rows of page 1, whatever `page` and `limit` ask, and the client does not support a session cookie. TikTok sends item, author and creator ids as JSON numbers above 2^53, so `itemID`, `authorID` and `creatorID` come back as strings with every digit. Creative Center reports a failure as HTTP 200 with a nonzero `BaseResp.StatusCode`, which rejects with `TiktokCreativeCenterError` (`statusCode`). The overview reports the latest daily, weekly and monthly period ends, the values a list's `periodEndTimestamp` takes. A row's video page is `https://www.tiktok.com/@<handlerName>/video/<itemID>`; `videoURL` is a signed CDN link that expires.
11
+
12
+ Runtime dependencies:
13
+
14
+ - `zod@^4.6.6` — request schemas attached to endpoint methods as `.schema`
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @apicity/tiktok-creative-center
20
+ # or
21
+ pnpm add @apicity/tiktok-creative-center
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ```typescript
27
+ import { createTiktokCreativeCenter } from "@apicity/tiktok-creative-center";
28
+
29
+ const tiktokCreativeCenter = createTiktokCreativeCenter();
30
+ ```
31
+
32
+ ## API Reference
33
+
34
+ 2 endpoints across 1 group. Each method mirrors an upstream URL path.
35
+
36
+ ### ads
37
+
38
+ <details>
39
+ <summary><code>GET</code> <b><code>tiktok-creative-center.ads.creativeOne.report.creativeCenterGetTopContentsList</code></b></summary>
40
+
41
+ <code>GET https://ads.tiktok.com/CreativeOne/Report/CreativeCenterGetTopContentsList{query}</code>
42
+
43
+ Cost tier: <code>cheap</code>
44
+
45
+ [Upstream docs ↗](https://ads.tiktok.com/creative/creativeCenter/trends/video)
46
+
47
+ ```typescript
48
+ const top = await tiktokCreativeCenter.ads.creativeOne.report.creativeCenterGetTopContentsList({
49
+ countryCode: "TH",
50
+ periodDimension: 3,
51
+ periodEndTimestamp: 1792886400,
52
+ orderByMetric: 1,
53
+ });
54
+ ```
55
+
56
+ Source: [`packages/provider/tiktok-creative-center/src/tiktokCreativeCenter.ts`](src/tiktokCreativeCenter.ts)
57
+
58
+ </details>
59
+
60
+ <details>
61
+ <summary><code>GET</code> <b><code>tiktok-creative-center.ads.creativeOne.report.getTopContentsOverview</code></b></summary>
62
+
63
+ <code>GET https://ads.tiktok.com/CreativeOne/Report/GetTopContentsOverview</code>
64
+
65
+ Cost tier: <code>cheap</code>
66
+
67
+ [Upstream docs ↗](https://ads.tiktok.com/creative/creativeCenter/trends/video)
68
+
69
+ ```typescript
70
+ const overview = await tiktokCreativeCenter.ads.creativeOne.report.getTopContentsOverview();
71
+ ```
72
+
73
+ Source: [`packages/provider/tiktok-creative-center/src/tiktokCreativeCenter.ts`](src/tiktokCreativeCenter.ts)
74
+
75
+ </details>
76
+
77
+ Part of the [apicity](https://github.com/justintanner/apicity) monorepo.
78
+
79
+ ## License
80
+
81
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,12 @@
1
+ export interface EndpointExample {
2
+ source: string;
3
+ payload: unknown;
4
+ /** Canonical cost tier of this endpoint (see @apicity/cost). */
5
+ tier: "cheap" | "expensive" | "prohibitive";
6
+ /** Whether an example runner may execute this by default (cheap only). */
7
+ runByDefault: boolean;
8
+ }
9
+ declare const EXAMPLES: Record<string, EndpointExample>;
10
+ export default EXAMPLES;
11
+ export declare function attachExamples<T>(provider: T): T;
12
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/example.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,gEAAgE;IAChE,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,aAAa,CAAC;IAC5C,0EAA0E;IAC1E,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,QAAA,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAsB7C,CAAC;AAEF,eAAe,QAAQ,CAAC;AAOxB,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CA6ChD"}
@@ -0,0 +1,108 @@
1
+ // Auto-generated by `pnpm run gen:examples` — do not edit by hand.
2
+ // Source: tests/recordings/<provider>_*/<test>_*/recording.har, plus static
3
+ // examples for providers that intentionally avoid live-network recordings.
4
+ //
5
+ // Each entry is a green-path payload for one endpoint. `attachExamples`
6
+ // walks the provider tree and hangs the matching entry off each endpoint
7
+ // function as `.example`.
8
+ const EXAMPLES = {
9
+ "GET ads.creativeOne.report.creativeCenterGetTopContentsList": {
10
+ "source": "tiktok-creative-center/top-contents-list-th-weekly-organic",
11
+ "payload": {
12
+ "countryCode": "TH",
13
+ "periodDimension": 3,
14
+ "periodEndTimestamp": 1792886400,
15
+ "orderByMetric": 1,
16
+ "organicOnly": true,
17
+ "contentLabelIDs": "",
18
+ "page": 1,
19
+ "limit": 20
20
+ },
21
+ "tier": "cheap",
22
+ "runByDefault": true
23
+ },
24
+ "GET ads.creativeOne.report.getTopContentsOverview": {
25
+ "source": "static:tiktok-creative-center-overview",
26
+ "payload": {},
27
+ "tier": "cheap",
28
+ "runByDefault": true
29
+ }
30
+ };
31
+ export default EXAMPLES;
32
+ // Walks each "<METHOD> <dotPath>" key onto the provider's tree. Tries the
33
+ // standard `provider.<method>.<dotPath>` shape first, then a few fallbacks
34
+ // to cover providers with non-standard layouts (fal's `.run.` namespace,
35
+ // kie's sub-providers, `free`'s flat root). Returns the same provider for
36
+ // drop-in use as `return attachExamples({ ... });`.
37
+ export function attachExamples(provider) {
38
+ const root = provider;
39
+ const HTTP_KEYS = new Set(["post", "get", "put", "delete", "patch", "head"]);
40
+ for (const [key, example] of Object.entries(EXAMPLES)) {
41
+ const sp = key.indexOf(" ");
42
+ if (sp < 0)
43
+ continue;
44
+ const method = key.slice(0, sp).toLowerCase();
45
+ const segs = key.slice(sp + 1).split(".");
46
+ const candidates = [
47
+ root[method],
48
+ root[method]?.run,
49
+ root,
50
+ ];
51
+ if (segs.length > 1) {
52
+ const sub = root[segs[0]];
53
+ if (sub && typeof sub === "object") {
54
+ const subMethod = sub[method];
55
+ if (subMethod)
56
+ candidates.push({ __nested: subMethod, __segs: segs.slice(1) });
57
+ }
58
+ }
59
+ let attached = false;
60
+ for (const c of candidates) {
61
+ const fn = walkToFn(c, segs);
62
+ if (fn) {
63
+ Object.assign(fn, { example });
64
+ attached = true;
65
+ break;
66
+ }
67
+ }
68
+ if (attached)
69
+ continue;
70
+ for (const k of Object.keys(root)) {
71
+ if (HTTP_KEYS.has(k))
72
+ continue;
73
+ if (!segs.includes(k))
74
+ continue;
75
+ const sub = root[k];
76
+ if (!sub || typeof sub !== "object")
77
+ continue;
78
+ const subMethod = sub[method];
79
+ if (!subMethod)
80
+ continue;
81
+ const fn = walkToFn(subMethod, segs);
82
+ if (fn) {
83
+ Object.assign(fn, { example });
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ return provider;
89
+ }
90
+ function walkToFn(start, segs) {
91
+ if (start && typeof start === "object" && "__nested" in start) {
92
+ const wrapper = start;
93
+ return walkToFn(wrapper.__nested, wrapper.__segs);
94
+ }
95
+ let cur = start;
96
+ for (const seg of segs) {
97
+ if (cur === null || cur === undefined)
98
+ return null;
99
+ const t = typeof cur;
100
+ if (t !== "object" && t !== "function")
101
+ return null;
102
+ cur = cur[seg];
103
+ }
104
+ return typeof cur === "function"
105
+ ? cur
106
+ : null;
107
+ }
108
+ //# sourceMappingURL=example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.js","sourceRoot":"","sources":["../../src/example.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,4EAA4E;AAC5E,2EAA2E;AAC3E,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AAC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SAAS,GAAI,GAA+B,CAAC,MAAM,CAAC,CAAC;YAC3D,IAAI,CAAC,SAAS;gBAAE,SAAS;YACzB,MAAM,EAAE,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YACrC,IAAI,EAAE,EAAE,CAAC;gBACP,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;gBAC/B,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc,EAAE,IAAc;IAC9C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,UAAU,IAAK,KAAgB,EAAE,CAAC;QAC1E,MAAM,OAAO,GAAG,KAAgD,CAAC;QACjE,OAAO,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,CAAC;IACD,IAAI,GAAG,GAAY,KAAK,CAAC;IACzB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACnD,MAAM,CAAC,GAAG,OAAO,GAAG,CAAC;QACrB,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC;QACpD,GAAG,GAAI,GAA+B,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,OAAO,GAAG,KAAK,UAAU;QAC9B,CAAC,CAAE,GAAuC;QAC1C,CAAC,CAAC,IAAI,CAAC;AACX,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { createTiktokCreativeCenter } from "./tiktokCreativeCenter.js";
2
+ export { TiktokCreativeCenterError } from "./types.js";
3
+ export type { TiktokCreativeCenterAdsNamespace, TiktokCreativeCenterAuthorInfo, TiktokCreativeCenterAuthorMetrics, TiktokCreativeCenterBaseResp, TiktokCreativeCenterCover, TiktokCreativeCenterCreativeOneNamespace, TiktokCreativeCenterEntity, TiktokCreativeCenterGetTopContentsListMethod, TiktokCreativeCenterGetTopContentsListRequest, TiktokCreativeCenterGetTopContentsListResponse, TiktokCreativeCenterGetTopContentsOverviewResponse, TiktokCreativeCenterItemInfo, TiktokCreativeCenterItemMetrics, TiktokCreativeCenterOptions, TiktokCreativeCenterOrderByMetric, TiktokCreativeCenterPagination, TiktokCreativeCenterPeriodDimension, TiktokCreativeCenterProvider, TiktokCreativeCenterReportNamespace, } from "./types.js";
4
+ export { TiktokCreativeCenterGetTopContentsListRequestSchema, TiktokCreativeCenterOrderByMetricSchema, TiktokCreativeCenterPeriodDimensionSchema, } from "./zod.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AACpD,YAAY,EACV,gCAAgC,EAChC,8BAA8B,EAC9B,iCAAiC,EACjC,4BAA4B,EAC5B,yBAAyB,EACzB,wCAAwC,EACxC,0BAA0B,EAC1B,4CAA4C,EAC5C,6CAA6C,EAC7C,8CAA8C,EAC9C,kDAAkD,EAClD,4BAA4B,EAC5B,+BAA+B,EAC/B,2BAA2B,EAC3B,iCAAiC,EACjC,8BAA8B,EAC9B,mCAAmC,EACnC,4BAA4B,EAC5B,mCAAmC,GACpC,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,mDAAmD,EACnD,uCAAuC,EACvC,yCAAyC,GAC1C,MAAM,OAAO,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { createTiktokCreativeCenter } from "./tiktokCreativeCenter.js";
2
+ export { TiktokCreativeCenterError } from "./types.js";
3
+ export { TiktokCreativeCenterGetTopContentsListRequestSchema, TiktokCreativeCenterOrderByMetricSchema, TiktokCreativeCenterPeriodDimensionSchema, } from "./zod.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAsBpD,OAAO,EACL,mDAAmD,EACnD,uCAAuC,EACvC,yCAAyC,GAC1C,MAAM,OAAO,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { TiktokCreativeCenterOptions, TiktokCreativeCenterProvider } from "./types.js";
2
+ export declare function createTiktokCreativeCenter(options?: TiktokCreativeCenterOptions): TiktokCreativeCenterProvider;
3
+ //# sourceMappingURL=tiktokCreativeCenter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiktokCreativeCenter.d.ts","sourceRoot":"","sources":["../../src/tiktokCreativeCenter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAIV,2BAA2B,EAC3B,4BAA4B,EAC7B,MAAM,SAAS,CAAC;AAoDjB,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,2BAAgC,GACxC,4BAA4B,CAgH9B"}
@@ -0,0 +1,119 @@
1
+ import { attachExamples } from "./example.js";
2
+ import { TiktokCreativeCenterError } from "./types.js";
3
+ import { TiktokCreativeCenterGetTopContentsListRequestSchema } from "./zod.js";
4
+ const DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36";
5
+ // The page whose data these endpoints serve; Creative Center expects the
6
+ // browser headers that page sends.
7
+ const TRENDS_PAGE = "https://ads.tiktok.com/creative/creativeCenter/trends/video";
8
+ // TikTok sends these ids as JSON numbers above 2^53, which JSON.parse rounds.
9
+ // Quoting them in the raw text keeps every digit. Inside a JSON string the
10
+ // key's quotes are escaped, so only real keys match.
11
+ const LARGE_ID_FIELDS = /"(itemID|authorID|creatorID)"(\s*):(\s*)(-?\d+)/g;
12
+ // A fixed key order, so equal requests build equal URLs.
13
+ const LIST_QUERY_KEYS = [
14
+ "countryCode",
15
+ "periodDimension",
16
+ "periodEndTimestamp",
17
+ "orderByMetric",
18
+ "organicOnly",
19
+ "contentLabelIDs",
20
+ "page",
21
+ "limit",
22
+ ];
23
+ function isEnvelope(value) {
24
+ return typeof value === "object" && value !== null;
25
+ }
26
+ function parseKeepingIds(text) {
27
+ return JSON.parse(text.replace(LARGE_ID_FIELDS, '"$1"$2:$3"$4"'));
28
+ }
29
+ function listQuery(request) {
30
+ const params = new URLSearchParams();
31
+ for (const key of LIST_QUERY_KEYS) {
32
+ const value = request[key];
33
+ if (value !== undefined)
34
+ params.set(key, String(value));
35
+ }
36
+ const search = params.toString();
37
+ return search ? `?${search}` : "";
38
+ }
39
+ export function createTiktokCreativeCenter(options = {}) {
40
+ const baseURL = (options.baseURL ?? "https://ads.tiktok.com").replace(/\/+$/, "");
41
+ const doFetch = options.fetch ?? fetch;
42
+ const timeout = options.timeout ?? 30000;
43
+ const headers = {
44
+ "User-Agent": options.userAgent ?? DEFAULT_USER_AGENT,
45
+ Accept: "application/json, text/plain, */*",
46
+ "Accept-Language": "en-US,en;q=0.9",
47
+ Referer: TRENDS_PAGE,
48
+ };
49
+ async function getRequest(path, signal) {
50
+ const controller = new AbortController();
51
+ const relayAbort = () => controller.abort();
52
+ if (signal?.aborted)
53
+ controller.abort();
54
+ else
55
+ signal?.addEventListener("abort", relayAbort, { once: true });
56
+ const timer = setTimeout(() => controller.abort(), timeout);
57
+ try {
58
+ const response = await doFetch(`${baseURL}${path}`, {
59
+ method: "GET",
60
+ headers,
61
+ signal: controller.signal,
62
+ });
63
+ const raw = await response.text();
64
+ let body = raw;
65
+ try {
66
+ body = parseKeepingIds(raw);
67
+ }
68
+ catch {
69
+ /* Keep non-JSON answers as text. */
70
+ }
71
+ if (!response.ok) {
72
+ throw new TiktokCreativeCenterError(`TikTok Creative Center error ${response.status}: ${raw.slice(0, 200)}`, response.status, body);
73
+ }
74
+ const base = isEnvelope(body) ? body.BaseResp : undefined;
75
+ if (typeof base?.StatusCode !== "number") {
76
+ throw new TiktokCreativeCenterError("TikTok Creative Center answered without BaseResp.StatusCode", response.status, body);
77
+ }
78
+ if (base.StatusCode !== 0) {
79
+ throw new TiktokCreativeCenterError(`TikTok Creative Center error ${base.StatusCode}: ${String(base.StatusMessage)}`, response.status, body, base.StatusCode);
80
+ }
81
+ return body;
82
+ }
83
+ catch (error) {
84
+ if (error instanceof TiktokCreativeCenterError)
85
+ throw error;
86
+ if (signal?.aborted)
87
+ throw new TiktokCreativeCenterError("TikTok Creative Center request aborted by caller", 499);
88
+ if (controller.signal.aborted)
89
+ throw new TiktokCreativeCenterError("TikTok Creative Center request timed out", 408);
90
+ throw new TiktokCreativeCenterError(`TikTok Creative Center request failed: ${error instanceof Error ? error.message : String(error)}`, 500);
91
+ }
92
+ finally {
93
+ clearTimeout(timer);
94
+ signal?.removeEventListener("abort", relayAbort);
95
+ }
96
+ }
97
+ return attachExamples({
98
+ ads: {
99
+ creativeOne: {
100
+ report: {
101
+ // sig-ok: Creative Center's PascalCase path segments become camelCase keys.
102
+ // GET https://ads.tiktok.com/CreativeOne/Report/CreativeCenterGetTopContentsList{query}
103
+ // Docs: https://ads.tiktok.com/creative/creativeCenter/trends/video
104
+ creativeCenterGetTopContentsList: Object.assign(async (request, signal) => {
105
+ const query = listQuery(request);
106
+ return getRequest(`/CreativeOne/Report/CreativeCenterGetTopContentsList${query}`, signal);
107
+ }, { schema: TiktokCreativeCenterGetTopContentsListRequestSchema }),
108
+ // sig-ok: Creative Center's PascalCase path segments become camelCase keys.
109
+ // GET https://ads.tiktok.com/CreativeOne/Report/GetTopContentsOverview
110
+ // Docs: https://ads.tiktok.com/creative/creativeCenter/trends/video
111
+ getTopContentsOverview: async (signal) => {
112
+ return getRequest("/CreativeOne/Report/GetTopContentsOverview", signal);
113
+ },
114
+ },
115
+ },
116
+ },
117
+ });
118
+ }
119
+ //# sourceMappingURL=tiktokCreativeCenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tiktokCreativeCenter.js","sourceRoot":"","sources":["../../src/tiktokCreativeCenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAQpD,OAAO,EAAE,mDAAmD,EAAE,MAAM,OAAO,CAAC;AAE5E,MAAM,kBAAkB,GACtB,iHAAiH,CAAC;AAEpH,yEAAyE;AACzE,mCAAmC;AACnC,MAAM,WAAW,GACf,6DAA6D,CAAC;AAEhE,8EAA8E;AAC9E,2EAA2E;AAC3E,qDAAqD;AACrD,MAAM,eAAe,GAAG,kDAAkD,CAAC;AAE3E,yDAAyD;AACzD,MAAM,eAAe,GAAG;IACtB,aAAa;IACb,iBAAiB;IACjB,oBAAoB;IACpB,eAAe;IACf,aAAa;IACb,iBAAiB;IACjB,MAAM;IACN,OAAO;CACC,CAAC;AAMX,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACrD,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,SAAS,CAChB,OAAsD;IAEtD,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,KAAK,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;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AAC,OAAO;gBAC3B,MAAM,IAAI,yBAAyB,CACjC,0CAA0C,EAC1C,GAAG,CACJ,CAAC;YACJ,MAAM,IAAI,yBAAyB,CACjC,0CAA0C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAClG,GAAG,CACJ,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC;QACpB,GAAG,EAAE;YACH,WAAW,EAAE;gBACX,MAAM,EAAE;oBACN,4EAA4E;oBAC5E,wFAAwF;oBACxF,oEAAoE;oBACpE,gCAAgC,EAAE,MAAM,CAAC,MAAM,CAC7C,KAAK,EACH,OAAsD,EACtD,MAAoB,EACpB,EAAE;wBACF,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;wBACjC,OAAO,UAAU,CACf,uDAAuD,KAAK,EAAE,EAC9D,MAAM,CACP,CAAC;oBACJ,CAAC,EACD,EAAE,MAAM,EAAE,mDAAmD,EAAE,CAChE;oBACD,4EAA4E;oBAC5E,uEAAuE;oBACvE,oEAAoE;oBACpE,sBAAsB,EAAE,KAAK,EAAE,MAAoB,EAAE,EAAE;wBACrD,OAAO,UAAU,CACf,4CAA4C,EAC5C,MAAM,CACP,CAAC;oBACJ,CAAC;iBACF;aACF;SACF;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,132 @@
1
+ import type { z } from "zod";
2
+ import type { TiktokCreativeCenterGetTopContentsListRequestSchema, TiktokCreativeCenterOrderByMetricSchema, TiktokCreativeCenterPeriodDimensionSchema } from "./zod.js";
3
+ /**
4
+ * `status` is the HTTP status, or 408 on timeout, 499 when the caller aborts
5
+ * and 500 when no response arrived. Creative Center also fails with HTTP 200
6
+ * and a nonzero `BaseResp.StatusCode`, which `statusCode` carries.
7
+ */
8
+ export declare class TiktokCreativeCenterError extends Error {
9
+ readonly status: number;
10
+ readonly body?: unknown | undefined;
11
+ readonly statusCode?: number | undefined;
12
+ constructor(message: string, status: number, body?: unknown | undefined, statusCode?: number | undefined);
13
+ }
14
+ export interface TiktokCreativeCenterOptions {
15
+ baseURL?: string;
16
+ timeout?: number;
17
+ fetch?: typeof fetch;
18
+ /** Sent as `User-Agent`; defaults to a desktop Chrome string. */
19
+ userAgent?: string;
20
+ }
21
+ export type TiktokCreativeCenterPeriodDimension = z.infer<typeof TiktokCreativeCenterPeriodDimensionSchema>;
22
+ export type TiktokCreativeCenterOrderByMetric = z.infer<typeof TiktokCreativeCenterOrderByMetricSchema>;
23
+ export type TiktokCreativeCenterGetTopContentsListRequest = z.infer<typeof TiktokCreativeCenterGetTopContentsListRequestSchema>;
24
+ /** `StatusCode` 0 is success; anything else rejects the call. */
25
+ export interface TiktokCreativeCenterBaseResp {
26
+ StatusCode: number;
27
+ StatusMessage: string;
28
+ [key: string]: unknown;
29
+ }
30
+ export interface TiktokCreativeCenterCover {
31
+ format?: string;
32
+ imageUrl?: string;
33
+ [key: string]: unknown;
34
+ }
35
+ export interface TiktokCreativeCenterItemInfo {
36
+ /**
37
+ * A string: TikTok sends the id as a JSON number above 2^53, and the client
38
+ * quotes it before parsing so no digit is lost. The video page is
39
+ * `https://www.tiktok.com/@<handlerName>/video/<itemID>`.
40
+ */
41
+ itemID: string;
42
+ title?: string;
43
+ /** Unix seconds. */
44
+ createTime?: number;
45
+ coverURL?: string;
46
+ coverURLList?: TiktokCreativeCenterCover[];
47
+ /** A signed TikTok CDN MP4 link that expires. */
48
+ videoURL?: string;
49
+ /** A string, for the same reason as `itemID`. */
50
+ authorID?: string;
51
+ /** A string, for the same reason as `itemID`. */
52
+ creatorID?: string;
53
+ contentType?: number;
54
+ [key: string]: unknown;
55
+ }
56
+ export interface TiktokCreativeCenterItemMetrics {
57
+ videoViews?: number;
58
+ videoViewsLifeTime?: number;
59
+ organicVideoViews?: number;
60
+ organicVideoViewsLifeTime?: number;
61
+ engagementRate?: number;
62
+ engagementRateLifeTime?: number;
63
+ sixSecondsVTR?: number;
64
+ sixSecondsVTRLifeTime?: number;
65
+ [key: string]: unknown;
66
+ }
67
+ export interface TiktokCreativeCenterAuthorInfo {
68
+ handlerName?: string;
69
+ nickName?: string;
70
+ avatarURI?: string;
71
+ bio?: string;
72
+ [key: string]: unknown;
73
+ }
74
+ export interface TiktokCreativeCenterAuthorMetrics {
75
+ followers?: number;
76
+ [key: string]: unknown;
77
+ }
78
+ export interface TiktokCreativeCenterEntity {
79
+ itemInfo: TiktokCreativeCenterItemInfo;
80
+ itemMetrics?: TiktokCreativeCenterItemMetrics;
81
+ itemAuthorInfo?: TiktokCreativeCenterAuthorInfo;
82
+ itemAuthorMetrics?: TiktokCreativeCenterAuthorMetrics;
83
+ [key: string]: unknown;
84
+ }
85
+ /** Without a TikTok One session, `page` is 1 and `limit` 4 whatever was asked. */
86
+ export interface TiktokCreativeCenterPagination {
87
+ limit: number;
88
+ page: number;
89
+ pageCount: number;
90
+ totalCount: number;
91
+ hasMore: boolean;
92
+ [key: string]: unknown;
93
+ }
94
+ /**
95
+ * A country or period without a list answers `StatusCode` 0 with neither
96
+ * `entityInfos` nor `pagination`.
97
+ */
98
+ export interface TiktokCreativeCenterGetTopContentsListResponse {
99
+ BaseResp: TiktokCreativeCenterBaseResp;
100
+ entityInfos?: TiktokCreativeCenterEntity[];
101
+ pagination?: TiktokCreativeCenterPagination;
102
+ [key: string]: unknown;
103
+ }
104
+ /**
105
+ * Unix seconds that end the latest daily, weekly and monthly lists: the
106
+ * values `periodEndTimestamp` takes.
107
+ */
108
+ export interface TiktokCreativeCenterGetTopContentsOverviewResponse {
109
+ BaseResp: TiktokCreativeCenterBaseResp;
110
+ lastDailyEndTimestamp?: number;
111
+ lastWeeklyEndTimestamp?: number;
112
+ lastMonthlyEndTimestamp?: number;
113
+ [key: string]: unknown;
114
+ }
115
+ export interface TiktokCreativeCenterGetTopContentsListMethod {
116
+ (request: TiktokCreativeCenterGetTopContentsListRequest, signal?: AbortSignal): Promise<TiktokCreativeCenterGetTopContentsListResponse>;
117
+ schema: typeof TiktokCreativeCenterGetTopContentsListRequestSchema;
118
+ }
119
+ export interface TiktokCreativeCenterReportNamespace {
120
+ creativeCenterGetTopContentsList: TiktokCreativeCenterGetTopContentsListMethod;
121
+ getTopContentsOverview(signal?: AbortSignal): Promise<TiktokCreativeCenterGetTopContentsOverviewResponse>;
122
+ }
123
+ export interface TiktokCreativeCenterCreativeOneNamespace {
124
+ report: TiktokCreativeCenterReportNamespace;
125
+ }
126
+ export interface TiktokCreativeCenterAdsNamespace {
127
+ creativeOne: TiktokCreativeCenterCreativeOneNamespace;
128
+ }
129
+ export interface TiktokCreativeCenterProvider {
130
+ ads: TiktokCreativeCenterAdsNamespace;
131
+ }
132
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EACV,mDAAmD,EACnD,uCAAuC,EACvC,yCAAyC,EAC1C,MAAM,OAAO,CAAC;AAEf;;;;GAIG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;aAGhC,MAAM,EAAE,MAAM;aACd,IAAI,CAAC,EAAE,OAAO;aACd,UAAU,CAAC,EAAE,MAAM;gBAHnC,OAAO,EAAE,MAAM,EACC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,YAAA,EACd,UAAU,CAAC,EAAE,MAAM,YAAA;CAKtC;AAED,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;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AC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,kDAAkD;IACjE,QAAQ,EAAE,4BAA4B,CAAC;IACvC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,4CAA4C;IAC3D,CACE,OAAO,EAAE,6CAA6C,EACtD,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,8CAA8C,CAAC,CAAC;IAC3D,MAAM,EAAE,OAAO,mDAAmD,CAAC;CACpE;AACD,MAAM,WAAW,mCAAmC;IAClD,gCAAgC,EAAE,4CAA4C,CAAC;IAC/E,sBAAsB,CACpB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,kDAAkD,CAAC,CAAC;CAChE;AACD,MAAM,WAAW,wCAAwC;IACvD,MAAM,EAAE,mCAAmC,CAAC;CAC7C;AACD,MAAM,WAAW,gCAAgC;IAC/C,WAAW,EAAE,wCAAwC,CAAC;CACvD;AACD,MAAM,WAAW,4BAA4B;IAC3C,GAAG,EAAE,gCAAgC,CAAC;CACvC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * `status` is the HTTP status, or 408 on timeout, 499 when the caller aborts
3
+ * and 500 when no response arrived. Creative Center also fails with HTTP 200
4
+ * and a nonzero `BaseResp.StatusCode`, which `statusCode` carries.
5
+ */
6
+ export class TiktokCreativeCenterError extends Error {
7
+ status;
8
+ body;
9
+ statusCode;
10
+ constructor(message, status, body, statusCode) {
11
+ super(message);
12
+ this.status = status;
13
+ this.body = body;
14
+ this.statusCode = statusCode;
15
+ this.name = "TiktokCreativeCenterError";
16
+ }
17
+ }
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAGhC;IACA;IACA;IAJlB,YACE,OAAe,EACC,MAAc,EACd,IAAc,EACd,UAAmB;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAU;QACd,eAAU,GAAV,UAAU,CAAS;QAGnC,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ export declare const TiktokCreativeCenterPeriodDimensionSchema: z.ZodLiteral<3 | 1 | 2>;
3
+ export declare const TiktokCreativeCenterOrderByMetricSchema: z.ZodLiteral<3 | 1 | 2>;
4
+ export declare const TiktokCreativeCenterGetTopContentsListRequestSchema: z.ZodObject<{
5
+ countryCode: z.ZodString;
6
+ periodDimension: z.ZodLiteral<3 | 1 | 2>;
7
+ periodEndTimestamp: z.ZodNumber;
8
+ orderByMetric: z.ZodLiteral<3 | 1 | 2>;
9
+ organicOnly: z.ZodOptional<z.ZodBoolean>;
10
+ contentLabelIDs: z.ZodOptional<z.ZodString>;
11
+ page: z.ZodOptional<z.ZodNumber>;
12
+ limit: z.ZodOptional<z.ZodNumber>;
13
+ }, z.core.$strip>;
14
+ //# sourceMappingURL=zod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,yCAAyC,yBAInD,CAAC;AAEJ,eAAO,MAAM,uCAAuC,yBAIjD,CAAC;AAEJ,eAAO,MAAM,mDAAmD;;;;;;;;;iBAkC9D,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { z } from "zod";
2
+ // Every value below was accepted by live calls on 2026-10-28. Creative Center
3
+ // answers any other periodDimension or orderByMetric (0 and 4 were tried), or
4
+ // a request without either, with BaseResp.StatusCode 38014004 "not supported
5
+ // top contents setting".
6
+ export const TiktokCreativeCenterPeriodDimensionSchema = z
7
+ .literal([1, 2, 3])
8
+ .describe("3 for the weekly list, 2 for the monthly list. 1 answered the weekly list on 2026-10-28.");
9
+ export const TiktokCreativeCenterOrderByMetricSchema = z
10
+ .literal([1, 2, 3])
11
+ .describe("1 ranks by video views, 2 by engagement rate, 3 by six-second view-through rate.");
12
+ export const TiktokCreativeCenterGetTopContentsListRequestSchema = z.object({
13
+ countryCode: z
14
+ .string()
15
+ .regex(/^[A-Z]{2}$/)
16
+ .describe("ISO 3166-1 alpha-2 country code, e.g. `TH`. A country without a list answers an empty one."),
17
+ periodDimension: TiktokCreativeCenterPeriodDimensionSchema,
18
+ periodEndTimestamp: z
19
+ .number()
20
+ .int()
21
+ .describe("Unix seconds that end the period, such as lastWeeklyEndTimestamp or lastMonthlyEndTimestamp from ads.creativeOne.report.getTopContentsOverview. A value Creative Center has no list for answers an empty one."),
22
+ orderByMetric: TiktokCreativeCenterOrderByMetricSchema,
23
+ organicOnly: z.boolean().optional().describe("true drops sponsored posts."),
24
+ contentLabelIDs: z
25
+ .string()
26
+ .optional()
27
+ .describe("Content category ids; empty or omitted for all categories."),
28
+ page: z
29
+ .number()
30
+ .int()
31
+ .min(1)
32
+ .optional()
33
+ .describe("Ignored without a TikTok One session: every answer is page 1."),
34
+ limit: z
35
+ .number()
36
+ .int()
37
+ .min(1)
38
+ .optional()
39
+ .describe("Ignored without a TikTok One session: every answer holds 4 rows."),
40
+ });
41
+ //# sourceMappingURL=zod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod.js","sourceRoot":"","sources":["../../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,8EAA8E;AAC9E,8EAA8E;AAC9E,6EAA6E;AAC7E,yBAAyB;AACzB,MAAM,CAAC,MAAM,yCAAyC,GAAG,CAAC;KACvD,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;KAClB,QAAQ,CACP,0FAA0F,CAC3F,CAAC;AAEJ,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC;KACrD,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;KAClB,QAAQ,CACP,kFAAkF,CACnF,CAAC;AAEJ,MAAM,CAAC,MAAM,mDAAmD,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1E,WAAW,EAAE,CAAC;SACX,MAAM,EAAE;SACR,KAAK,CAAC,YAAY,CAAC;SACnB,QAAQ,CACP,4FAA4F,CAC7F;IACH,eAAe,EAAE,yCAAyC;IAC1D,kBAAkB,EAAE,CAAC;SAClB,MAAM,EAAE;SACR,GAAG,EAAE;SACL,QAAQ,CACP,+MAA+M,CAChN;IACH,aAAa,EAAE,uCAAuC;IACtD,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,6BAA6B,CAAC;IAC3E,eAAe,EAAE,CAAC;SACf,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CAAC,4DAA4D,CAAC;IACzE,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,EAAE;SACV,QAAQ,CAAC,+DAA+D,CAAC;IAC5E,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,EAAE;SACV,QAAQ,CACP,kEAAkE,CACnE;CACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@apicity/tiktok-creative-center",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.20.0",
4
+ "description": "TikTok Creative Center trending videos provider (unofficial, undocumented endpoints).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/justintanner/apicity.git",
9
+ "directory": "provider/tiktok-creative-center"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "main": "dist/src/index.js",
16
+ "types": "dist/src/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/src/index.js",
20
+ "types": "./dist/src/index.d.ts"
21
+ },
22
+ "./zod": {
23
+ "import": "./dist/src/zod.js",
24
+ "types": "./dist/src/zod.d.ts"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "zod": "^4.6.6"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "sideEffects": false,
36
+ "keywords": [
37
+ "tiktok",
38
+ "creative-center",
39
+ "trends",
40
+ "social",
41
+ "apicity"
42
+ ],
43
+ "author": "Justin Tanner",
44
+ "engines": {
45
+ "node": ">=18.0.0"
46
+ },
47
+ "homepage": "https://github.com/justintanner/apicity#readme",
48
+ "bugs": {
49
+ "url": "https://github.com/justintanner/apicity/issues"
50
+ },
51
+ "scripts": {
52
+ "build": "tsc -p tsconfig.json && node scripts/dist.mjs"
53
+ }
6
54
  }