@yellit/core 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +8 -2
- package/dist/config.d.ts +18 -0
- package/dist/config.js +103 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth1.d.ts +36 -0
- package/dist/oauth1.js +63 -0
- package/dist/oauth1.js.map +1 -0
- package/dist/platforms/instagram.d.ts +65 -0
- package/dist/platforms/instagram.js +225 -0
- package/dist/platforms/instagram.js.map +1 -0
- package/dist/platforms/tiktok.d.ts +128 -0
- package/dist/platforms/tiktok.js +472 -0
- package/dist/platforms/tiktok.js.map +1 -0
- package/dist/platforms/x.d.ts +63 -0
- package/dist/platforms/x.js +280 -0
- package/dist/platforms/x.js.map +1 -0
- package/dist/platforms/youtube.d.ts +56 -0
- package/dist/platforms/youtube.js +266 -0
- package/dist/platforms/youtube.js.map +1 -0
- package/dist/staging.d.ts +55 -0
- package/dist/staging.js +105 -0
- package/dist/staging.js.map +1 -0
- package/dist/types.d.ts +111 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +37 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Freddy Montes
|
|
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,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yellit/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Platform adapters, media staging, and shared types used by the [yellit CLI](https://useyellit.com/cli).
|
|
4
|
+
|
|
5
|
+
To publish from a terminal, install `yellit@beta`. The CLI installs this package as a dependency. Core is released alongside the CLI; its API may change before version 1.0.
|
|
6
|
+
|
|
7
|
+
## License
|
|
8
|
+
|
|
9
|
+
MIT. See [LICENSE](LICENSE).
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential + setting resolution.
|
|
3
|
+
*
|
|
4
|
+
* Precedence, highest first:
|
|
5
|
+
* 1. process.env
|
|
6
|
+
* 2. the nearest .env at or above the working directory
|
|
7
|
+
* 3. ~/.config/yellit/config.json
|
|
8
|
+
*
|
|
9
|
+
* Env-first means CI (which sets real env vars) always wins over whatever is
|
|
10
|
+
* on a developer's laptop, while the config file makes local runs possible
|
|
11
|
+
* without exporting anything.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CONFIG_PATH: string;
|
|
14
|
+
export interface Config {
|
|
15
|
+
get(key: string): string | undefined;
|
|
16
|
+
require(key: string): string;
|
|
17
|
+
}
|
|
18
|
+
export declare function loadConfig(cwd?: string): Config;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential + setting resolution.
|
|
3
|
+
*
|
|
4
|
+
* Precedence, highest first:
|
|
5
|
+
* 1. process.env
|
|
6
|
+
* 2. the nearest .env at or above the working directory
|
|
7
|
+
* 3. ~/.config/yellit/config.json
|
|
8
|
+
*
|
|
9
|
+
* Env-first means CI (which sets real env vars) always wins over whatever is
|
|
10
|
+
* on a developer's laptop, while the config file makes local runs possible
|
|
11
|
+
* without exporting anything.
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { dirname, join } from "node:path";
|
|
16
|
+
export const CONFIG_PATH = join(homedir(), ".config", "yellit", "config.json");
|
|
17
|
+
/** Parse a minimal .env: KEY=VALUE, # comments, optional quotes. */
|
|
18
|
+
function parseEnvFile(text) {
|
|
19
|
+
const out = {};
|
|
20
|
+
for (const raw of text.split("\n")) {
|
|
21
|
+
const line = raw.trim();
|
|
22
|
+
if (!line || line.startsWith("#"))
|
|
23
|
+
continue;
|
|
24
|
+
const eq = line.indexOf("=");
|
|
25
|
+
if (eq === -1)
|
|
26
|
+
continue;
|
|
27
|
+
const key = line.slice(0, eq).trim();
|
|
28
|
+
let value = line.slice(eq + 1).trim();
|
|
29
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
30
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
31
|
+
value = value.slice(1, -1);
|
|
32
|
+
}
|
|
33
|
+
if (key)
|
|
34
|
+
out[key] = value;
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function readJsonFile(path) {
|
|
39
|
+
if (!existsSync(path))
|
|
40
|
+
return {};
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
43
|
+
if (!parsed || typeof parsed !== "object")
|
|
44
|
+
return {};
|
|
45
|
+
// Flatten one level so either {IG_USER_ID: x} or {instagram: {userId: x}}
|
|
46
|
+
// styles work; we only care about the flat string values.
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const [k, v] of Object.entries(parsed)) {
|
|
49
|
+
if (typeof v === "string")
|
|
50
|
+
out[k] = v;
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
// A malformed config file shouldn't crash a run that has env vars set.
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Find the nearest `.env` at or above `cwd`, the way git locates its root.
|
|
61
|
+
* Without this, running from a subdirectory of a project silently ignores the
|
|
62
|
+
* `.env` sitting at the top of it — which is the normal layout in a monorepo
|
|
63
|
+
* or any repo where you invoke the CLI from a nested folder.
|
|
64
|
+
*/
|
|
65
|
+
function findDotenv(cwd) {
|
|
66
|
+
let dir = cwd;
|
|
67
|
+
for (;;) {
|
|
68
|
+
const candidate = join(dir, ".env");
|
|
69
|
+
if (existsSync(candidate))
|
|
70
|
+
return candidate;
|
|
71
|
+
const parent = dirname(dir);
|
|
72
|
+
if (parent === dir)
|
|
73
|
+
return undefined;
|
|
74
|
+
dir = parent;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export function loadConfig(cwd = process.cwd()) {
|
|
78
|
+
const fromFile = readJsonFile(CONFIG_PATH);
|
|
79
|
+
const dotenvPath = findDotenv(cwd);
|
|
80
|
+
const fromDotenv = dotenvPath
|
|
81
|
+
? parseEnvFile(readFileSync(dotenvPath, "utf8"))
|
|
82
|
+
: {};
|
|
83
|
+
const layers = [process.env, fromDotenv, fromFile];
|
|
84
|
+
const get = (key) => {
|
|
85
|
+
for (const layer of layers) {
|
|
86
|
+
const v = layer[key];
|
|
87
|
+
if (v !== undefined && v !== "")
|
|
88
|
+
return v;
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
get,
|
|
94
|
+
require(key) {
|
|
95
|
+
const v = get(key);
|
|
96
|
+
if (v === undefined) {
|
|
97
|
+
throw new Error(`Missing ${key}. Set it in the environment, ./.env, or ${CONFIG_PATH}.`);
|
|
98
|
+
}
|
|
99
|
+
return v;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;AAE/E,oEAAoE;AACpE,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,EAAE,KAAK,CAAC,CAAC;YAAE,SAAS;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI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C;YACD,OAAO,CAAC,CAAC;QACX,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything that both the CLI and the hosted server need: the platform
|
|
3
|
+
* adapters, the shapes they speak, and the media staging that Instagram
|
|
4
|
+
* requires.
|
|
5
|
+
*
|
|
6
|
+
* Nothing here may depend on the CLI or the server. Argument parsing lives in
|
|
7
|
+
* @yellit/cli because only the CLI has arguments; HTTP routing and token
|
|
8
|
+
* storage live in the server because only it has users.
|
|
9
|
+
*/
|
|
10
|
+
export { Instagram } from "./platforms/instagram.js";
|
|
11
|
+
export { YouTube } from "./platforms/youtube.js";
|
|
12
|
+
export { X, containsLink } from "./platforms/x.js";
|
|
13
|
+
export { TikTok } from "./platforms/tiktok.js";
|
|
14
|
+
export type { CreatorInfo } from "./platforms/tiktok.js";
|
|
15
|
+
export { authorizationHeader } from "./oauth1.js";
|
|
16
|
+
export type { OAuth1Credentials } from "./oauth1.js";
|
|
17
|
+
export { Staging, needsStaging } from "./staging.js";
|
|
18
|
+
export type { StagedMedia } from "./staging.js";
|
|
19
|
+
export { loadConfig, CONFIG_PATH } from "./config.js";
|
|
20
|
+
/**
|
|
21
|
+
* The server builds a Config from a user's decrypted credentials rather than
|
|
22
|
+
* from disk, so the interface has to be part of the public surface.
|
|
23
|
+
*/
|
|
24
|
+
export type { Config } from "./config.js";
|
|
25
|
+
export { mediaRef } from "./types.js";
|
|
26
|
+
export type { Media, MediaSource, Platform, PostRequest, PostResult, Privacy, TikTokPostOptions, } from "./types.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything that both the CLI and the hosted server need: the platform
|
|
3
|
+
* adapters, the shapes they speak, and the media staging that Instagram
|
|
4
|
+
* requires.
|
|
5
|
+
*
|
|
6
|
+
* Nothing here may depend on the CLI or the server. Argument parsing lives in
|
|
7
|
+
* @yellit/cli because only the CLI has arguments; HTTP routing and token
|
|
8
|
+
* storage live in the server because only it has users.
|
|
9
|
+
*/
|
|
10
|
+
export { Instagram } from "./platforms/instagram.js";
|
|
11
|
+
export { YouTube } from "./platforms/youtube.js";
|
|
12
|
+
export { X, containsLink } from "./platforms/x.js";
|
|
13
|
+
export { TikTok } from "./platforms/tiktok.js";
|
|
14
|
+
export { authorizationHeader } from "./oauth1.js";
|
|
15
|
+
export { Staging, needsStaging } from "./staging.js";
|
|
16
|
+
export { loadConfig, CONFIG_PATH } from "./config.js";
|
|
17
|
+
export { mediaRef } from "./types.js";
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,EAAE,CAAC,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAMtD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/oauth1.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth 1.0a request signing (HMAC-SHA1).
|
|
3
|
+
*
|
|
4
|
+
* X's media upload endpoint is the reason this exists. OAuth 2.0 with a
|
|
5
|
+
* `media.write` scope is documented, but it currently 403s on
|
|
6
|
+
* `/2/media/upload` for many apps, and OAuth 1.0a is the path known to work.
|
|
7
|
+
* It also suits a single-user CLI better: four static credentials, no token
|
|
8
|
+
* refresh, and nothing to persist between runs.
|
|
9
|
+
*
|
|
10
|
+
* The signature covers the HTTP method, the base URL, and every oauth_* and
|
|
11
|
+
* query parameter sorted by key. Request *bodies* are only included when the
|
|
12
|
+
* body is form-encoded — which is why multipart chunk uploads sign only the
|
|
13
|
+
* query string, not the binary payload.
|
|
14
|
+
*/
|
|
15
|
+
export interface OAuth1Credentials {
|
|
16
|
+
consumerKey: string;
|
|
17
|
+
consumerSecret: string;
|
|
18
|
+
accessToken: string;
|
|
19
|
+
accessSecret: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SignOptions {
|
|
22
|
+
method: string;
|
|
23
|
+
/** Base URL with no query string — query params belong in `params`. */
|
|
24
|
+
url: string;
|
|
25
|
+
/** Query and form parameters to include in the signature. */
|
|
26
|
+
params?: Record<string, string>;
|
|
27
|
+
nonce?: string;
|
|
28
|
+
timestamp?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Build the `Authorization: OAuth …` header for one request.
|
|
32
|
+
*
|
|
33
|
+
* `nonce`/`timestamp` are injectable so tests can assert a known signature;
|
|
34
|
+
* in real use they default to a random nonce and the current time.
|
|
35
|
+
*/
|
|
36
|
+
export declare function authorizationHeader(creds: OAuth1Credentials, opts: SignOptions): string;
|
package/dist/oauth1.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth 1.0a request signing (HMAC-SHA1).
|
|
3
|
+
*
|
|
4
|
+
* X's media upload endpoint is the reason this exists. OAuth 2.0 with a
|
|
5
|
+
* `media.write` scope is documented, but it currently 403s on
|
|
6
|
+
* `/2/media/upload` for many apps, and OAuth 1.0a is the path known to work.
|
|
7
|
+
* It also suits a single-user CLI better: four static credentials, no token
|
|
8
|
+
* refresh, and nothing to persist between runs.
|
|
9
|
+
*
|
|
10
|
+
* The signature covers the HTTP method, the base URL, and every oauth_* and
|
|
11
|
+
* query parameter sorted by key. Request *bodies* are only included when the
|
|
12
|
+
* body is form-encoded — which is why multipart chunk uploads sign only the
|
|
13
|
+
* query string, not the binary payload.
|
|
14
|
+
*/
|
|
15
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
16
|
+
/**
|
|
17
|
+
* Percent-encoding per RFC 5849 §3.6. `encodeURIComponent` leaves !*'() alone
|
|
18
|
+
* and OAuth requires them escaped; getting this wrong yields a 401 that looks
|
|
19
|
+
* like bad credentials.
|
|
20
|
+
*/
|
|
21
|
+
function percentEncode(value) {
|
|
22
|
+
return encodeURIComponent(value).replace(/[!*'()]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Build the `Authorization: OAuth …` header for one request.
|
|
26
|
+
*
|
|
27
|
+
* `nonce`/`timestamp` are injectable so tests can assert a known signature;
|
|
28
|
+
* in real use they default to a random nonce and the current time.
|
|
29
|
+
*/
|
|
30
|
+
export function authorizationHeader(creds, opts) {
|
|
31
|
+
const oauthParams = {
|
|
32
|
+
oauth_consumer_key: creds.consumerKey,
|
|
33
|
+
oauth_nonce: opts.nonce ?? randomBytes(16).toString("hex"),
|
|
34
|
+
oauth_signature_method: "HMAC-SHA1",
|
|
35
|
+
oauth_timestamp: opts.timestamp ?? Math.floor(Date.now() / 1000).toString(),
|
|
36
|
+
oauth_token: creds.accessToken,
|
|
37
|
+
oauth_version: "1.0",
|
|
38
|
+
};
|
|
39
|
+
// Every parameter participates in the signature, sorted by encoded key then
|
|
40
|
+
// encoded value.
|
|
41
|
+
const all = { ...(opts.params ?? {}), ...oauthParams };
|
|
42
|
+
const paramString = Object.keys(all)
|
|
43
|
+
.map((k) => [percentEncode(k), percentEncode(all[k])])
|
|
44
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : a[1] < b[1] ? -1 : 1))
|
|
45
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
46
|
+
.join("&");
|
|
47
|
+
const baseString = [
|
|
48
|
+
opts.method.toUpperCase(),
|
|
49
|
+
percentEncode(opts.url),
|
|
50
|
+
percentEncode(paramString),
|
|
51
|
+
].join("&");
|
|
52
|
+
const signingKey = `${percentEncode(creds.consumerSecret)}&${percentEncode(creds.accessSecret)}`;
|
|
53
|
+
const signature = createHmac("sha1", signingKey).update(baseString).digest("base64");
|
|
54
|
+
// Only the oauth_* parameters go in the header; query and form parameters
|
|
55
|
+
// stay where they were.
|
|
56
|
+
const header = { ...oauthParams, oauth_signature: signature };
|
|
57
|
+
return ("OAuth " +
|
|
58
|
+
Object.keys(header)
|
|
59
|
+
.sort()
|
|
60
|
+
.map((k) => `${percentEncode(k)}="${percentEncode(header[k])}"`)
|
|
61
|
+
.join(", "));
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=oauth1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth1.js","sourceRoot":"","sources":["../src/oauth1.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAStD;;;;GAIG;AACH,SAAS,aAAa,CAAC,KAAa;IAClC,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC,OAAO,CACtC,UAAU,EACV,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CACxD,CAAC;AACJ,CAAC;AAYD;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAwB,EACxB,IAAiB;IAEjB,MAAM,WAAW,GAA2B;QAC1C,kBAAkB,EAAE,KAAK,CAAC,WAAW;QACrC,WAAW,EAAE,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC1D,sBAAsB,EAAE,WAAW;QACnC,eA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,CAAC,CAAC;IAEZ,MAAM,UAAU,GAAG,GAAG,aAAa,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,CAAC;IACjG,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAErF,0EAA0E;IAC1E,wBAAwB;IACxB,MAAM,MAAM,GAA2B,EAAE,GAAG,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;IACtF,OAAO,CACL,QAAQ;QACR,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aAChB,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,MAAM,CAAC,CAAC,CAAE,CAAC,GAAG,CAAC;aAChE,IAAI,CAAC,IAAI,CAAC,CACd,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instagram adapter.
|
|
3
|
+
*
|
|
4
|
+
* Publishes via the container flow: create container(s) -> poll to FINISHED ->
|
|
5
|
+
* media_publish. Three shapes are supported: single image, image/video carousel
|
|
6
|
+
* (2-10 items), and Reels.
|
|
7
|
+
*
|
|
8
|
+
* Transport note: this only ever passes `image_url`/`video_url` for Meta to
|
|
9
|
+
* fetch server-side. Binary upload (`upload_type=resumable` against
|
|
10
|
+
* rupload.facebook.com) is documented as Facebook-Login-for-Business only and
|
|
11
|
+
* is not available on graph.instagram.com, so media must already be at a
|
|
12
|
+
* public HTTPS URL.
|
|
13
|
+
*
|
|
14
|
+
* Env: IG_ACCESS_TOKEN (required), IG_USER_ID (required on the Facebook-Page
|
|
15
|
+
* flow; on graph.instagram.com the authed account is addressed as `me`).
|
|
16
|
+
* Optional IG_GRAPH_BASE to target graph.facebook.com/vXX instead.
|
|
17
|
+
*/
|
|
18
|
+
import type { Config } from "../config.js";
|
|
19
|
+
import type { Platform, PostRequest, PostResult } from "../types.js";
|
|
20
|
+
export interface InstagramOptions {
|
|
21
|
+
/** Poll interval in ms. Meta suggests once per minute; images finish faster. */
|
|
22
|
+
pollIntervalMs?: number;
|
|
23
|
+
/** Give up after this long. Meta's own guidance is ~5 minutes. */
|
|
24
|
+
pollTimeoutMs?: number;
|
|
25
|
+
fetchImpl?: typeof fetch;
|
|
26
|
+
log?: (msg: string) => void;
|
|
27
|
+
}
|
|
28
|
+
export declare class Instagram implements Platform {
|
|
29
|
+
readonly name = "instagram";
|
|
30
|
+
readonly needsPublicUrl = true;
|
|
31
|
+
private readonly graph;
|
|
32
|
+
private readonly token;
|
|
33
|
+
private readonly userId;
|
|
34
|
+
private readonly pollIntervalMs;
|
|
35
|
+
private readonly pollTimeoutMs;
|
|
36
|
+
private readonly fetchImpl;
|
|
37
|
+
private readonly log;
|
|
38
|
+
constructor(config: Config, opts?: InstagramOptions);
|
|
39
|
+
/**
|
|
40
|
+
* graph.instagram.com (Instagram Login) addresses the authed account as
|
|
41
|
+
* `me`; the Facebook-Page Graph API needs the numeric IG user id.
|
|
42
|
+
*/
|
|
43
|
+
private get mediaPath();
|
|
44
|
+
validate(req: PostRequest): string[];
|
|
45
|
+
publish(req: PostRequest): Promise<PostResult>;
|
|
46
|
+
/**
|
|
47
|
+
* `validate()` already rejects local paths, so this only guards against a
|
|
48
|
+
* caller that skipped validation — better a clear throw than a silent
|
|
49
|
+
* `undefined` in the request body.
|
|
50
|
+
*/
|
|
51
|
+
private urlOf;
|
|
52
|
+
private createSingleContainer;
|
|
53
|
+
private createReelContainer;
|
|
54
|
+
private createCarouselContainer;
|
|
55
|
+
private childParams;
|
|
56
|
+
private createContainer;
|
|
57
|
+
private publishContainer;
|
|
58
|
+
private post;
|
|
59
|
+
/**
|
|
60
|
+
* Poll a container until FINISHED. Publishing before that returns a 400, so
|
|
61
|
+
* this step is mandatory rather than an optimization. Video containers take
|
|
62
|
+
* substantially longer than images — hence the generous default timeout.
|
|
63
|
+
*/
|
|
64
|
+
private waitFinished;
|
|
65
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instagram adapter.
|
|
3
|
+
*
|
|
4
|
+
* Publishes via the container flow: create container(s) -> poll to FINISHED ->
|
|
5
|
+
* media_publish. Three shapes are supported: single image, image/video carousel
|
|
6
|
+
* (2-10 items), and Reels.
|
|
7
|
+
*
|
|
8
|
+
* Transport note: this only ever passes `image_url`/`video_url` for Meta to
|
|
9
|
+
* fetch server-side. Binary upload (`upload_type=resumable` against
|
|
10
|
+
* rupload.facebook.com) is documented as Facebook-Login-for-Business only and
|
|
11
|
+
* is not available on graph.instagram.com, so media must already be at a
|
|
12
|
+
* public HTTPS URL.
|
|
13
|
+
*
|
|
14
|
+
* Env: IG_ACCESS_TOKEN (required), IG_USER_ID (required on the Facebook-Page
|
|
15
|
+
* flow; on graph.instagram.com the authed account is addressed as `me`).
|
|
16
|
+
* Optional IG_GRAPH_BASE to target graph.facebook.com/vXX instead.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_GRAPH = "https://graph.instagram.com";
|
|
19
|
+
/** Meta's documented ceiling: carousels hold 2-10 items. */
|
|
20
|
+
const CAROUSEL_MIN = 2;
|
|
21
|
+
const CAROUSEL_MAX = 10;
|
|
22
|
+
/** Caption limit Meta documents for published media. */
|
|
23
|
+
const CAPTION_MAX = 2200;
|
|
24
|
+
export class Instagram {
|
|
25
|
+
name = "instagram";
|
|
26
|
+
needsPublicUrl = true;
|
|
27
|
+
graph;
|
|
28
|
+
token;
|
|
29
|
+
userId;
|
|
30
|
+
pollIntervalMs;
|
|
31
|
+
pollTimeoutMs;
|
|
32
|
+
fetchImpl;
|
|
33
|
+
log;
|
|
34
|
+
constructor(config, opts = {}) {
|
|
35
|
+
this.graph = (config.get("IG_GRAPH_BASE") ?? DEFAULT_GRAPH).replace(/\/$/, "");
|
|
36
|
+
this.token = config.require("IG_ACCESS_TOKEN");
|
|
37
|
+
this.userId = config.get("IG_USER_ID");
|
|
38
|
+
this.pollIntervalMs = opts.pollIntervalMs ?? 3_000;
|
|
39
|
+
this.pollTimeoutMs = opts.pollTimeoutMs ?? 300_000;
|
|
40
|
+
this.fetchImpl = opts.fetchImpl ?? fetch;
|
|
41
|
+
this.log = opts.log ?? (() => { });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* graph.instagram.com (Instagram Login) addresses the authed account as
|
|
45
|
+
* `me`; the Facebook-Page Graph API needs the numeric IG user id.
|
|
46
|
+
*/
|
|
47
|
+
get mediaPath() {
|
|
48
|
+
if (this.graph.includes("graph.instagram.com"))
|
|
49
|
+
return "me";
|
|
50
|
+
if (!this.userId) {
|
|
51
|
+
throw new Error("IG_USER_ID is required when IG_GRAPH_BASE points at the Facebook Graph API.");
|
|
52
|
+
}
|
|
53
|
+
return this.userId;
|
|
54
|
+
}
|
|
55
|
+
validate(req) {
|
|
56
|
+
const errors = [];
|
|
57
|
+
if (req.media.length === 0) {
|
|
58
|
+
errors.push("No media given; Instagram needs at least one image or video.");
|
|
59
|
+
}
|
|
60
|
+
if (req.caption.length > CAPTION_MAX) {
|
|
61
|
+
errors.push(`Caption is ${req.caption.length} chars; Instagram allows ${CAPTION_MAX}.`);
|
|
62
|
+
}
|
|
63
|
+
for (const m of req.media) {
|
|
64
|
+
if (m.from === "path") {
|
|
65
|
+
errors.push(`Instagram has no binary upload; media must be at a public HTTPS URL, got a local path: ${m.path}`);
|
|
66
|
+
}
|
|
67
|
+
else if (!m.url.startsWith("https://")) {
|
|
68
|
+
errors.push(`Media URL must be public HTTPS (Meta fetches it server-side): ${m.url}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const videos = req.media.filter((m) => m.kind === "video").length;
|
|
72
|
+
if (req.video) {
|
|
73
|
+
// A Reel is a single video. Reels cannot be carousel children, so
|
|
74
|
+
// there's no "carousel of Reels" to fall back to.
|
|
75
|
+
if (req.media.length !== 1) {
|
|
76
|
+
errors.push(`A Reel is a single video; got ${req.media.length} media items.`);
|
|
77
|
+
}
|
|
78
|
+
if (videos !== 1) {
|
|
79
|
+
errors.push("--reel requires a video (pass --video <url>).");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (req.media.length > 1) {
|
|
83
|
+
if (req.media.length < CAROUSEL_MIN || req.media.length > CAROUSEL_MAX) {
|
|
84
|
+
errors.push(`Carousels hold ${CAROUSEL_MIN}-${CAROUSEL_MAX} items; got ${req.media.length}.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return errors;
|
|
88
|
+
}
|
|
89
|
+
async publish(req) {
|
|
90
|
+
try {
|
|
91
|
+
const containerId = req.video
|
|
92
|
+
? await this.createReelContainer(req)
|
|
93
|
+
: req.media.length === 1
|
|
94
|
+
? await this.createSingleContainer(req)
|
|
95
|
+
: await this.createCarouselContainer(req);
|
|
96
|
+
const id = await this.publishContainer(containerId);
|
|
97
|
+
return { platform: this.name, ok: true, id };
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
return {
|
|
101
|
+
platform: this.name,
|
|
102
|
+
ok: false,
|
|
103
|
+
error: err instanceof Error ? err.message : String(err),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// ---- container creation ----
|
|
108
|
+
/**
|
|
109
|
+
* `validate()` already rejects local paths, so this only guards against a
|
|
110
|
+
* caller that skipped validation — better a clear throw than a silent
|
|
111
|
+
* `undefined` in the request body.
|
|
112
|
+
*/
|
|
113
|
+
urlOf(m) {
|
|
114
|
+
if (m.from !== "url") {
|
|
115
|
+
throw new Error(`Instagram requires a public HTTPS URL; got a local path: ${m.path}`);
|
|
116
|
+
}
|
|
117
|
+
return m.url;
|
|
118
|
+
}
|
|
119
|
+
async createSingleContainer(req) {
|
|
120
|
+
const only = req.media[0];
|
|
121
|
+
const params = { caption: req.caption };
|
|
122
|
+
if (only.kind === "image") {
|
|
123
|
+
params.image_url = this.urlOf(only);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
// A bare video in the feed is still a VIDEO container, not REELS.
|
|
127
|
+
params.media_type = "VIDEO";
|
|
128
|
+
params.video_url = this.urlOf(only);
|
|
129
|
+
}
|
|
130
|
+
const id = await this.createContainer(params);
|
|
131
|
+
await this.waitFinished(id, "media");
|
|
132
|
+
return id;
|
|
133
|
+
}
|
|
134
|
+
async createReelContainer(req) {
|
|
135
|
+
const only = req.media[0];
|
|
136
|
+
const id = await this.createContainer({
|
|
137
|
+
media_type: "REELS",
|
|
138
|
+
video_url: this.urlOf(only),
|
|
139
|
+
caption: req.caption,
|
|
140
|
+
});
|
|
141
|
+
await this.waitFinished(id, "reel");
|
|
142
|
+
return id;
|
|
143
|
+
}
|
|
144
|
+
async createCarouselContainer(req) {
|
|
145
|
+
const childIds = [];
|
|
146
|
+
for (const [i, m] of req.media.entries()) {
|
|
147
|
+
const id = await this.createContainer(this.childParams(m));
|
|
148
|
+
await this.waitFinished(id, `item ${i + 1}/${req.media.length}`);
|
|
149
|
+
childIds.push(id);
|
|
150
|
+
}
|
|
151
|
+
const parentId = await this.createContainer({
|
|
152
|
+
media_type: "CAROUSEL",
|
|
153
|
+
children: childIds.join(","),
|
|
154
|
+
caption: req.caption,
|
|
155
|
+
});
|
|
156
|
+
await this.waitFinished(parentId, "carousel");
|
|
157
|
+
return parentId;
|
|
158
|
+
}
|
|
159
|
+
childParams(m) {
|
|
160
|
+
// Carousel children are plain IMAGE/VIDEO containers — REELS is rejected
|
|
161
|
+
// as a child type by the API.
|
|
162
|
+
const url = this.urlOf(m);
|
|
163
|
+
return m.kind === "image"
|
|
164
|
+
? { image_url: url, is_carousel_item: "true" }
|
|
165
|
+
: { media_type: "VIDEO", video_url: url, is_carousel_item: "true" };
|
|
166
|
+
}
|
|
167
|
+
// ---- graph plumbing ----
|
|
168
|
+
async createContainer(params) {
|
|
169
|
+
const json = await this.post(`${this.mediaPath}/media`, params);
|
|
170
|
+
const id = json.id;
|
|
171
|
+
if (typeof id !== "string") {
|
|
172
|
+
throw new Error(`Container creation returned no id: ${JSON.stringify(json)}`);
|
|
173
|
+
}
|
|
174
|
+
return id;
|
|
175
|
+
}
|
|
176
|
+
async publishContainer(creationId) {
|
|
177
|
+
const json = await this.post(`${this.mediaPath}/media_publish`, {
|
|
178
|
+
creation_id: creationId,
|
|
179
|
+
});
|
|
180
|
+
const id = json.id;
|
|
181
|
+
if (typeof id !== "string") {
|
|
182
|
+
throw new Error(`Publish returned no id: ${JSON.stringify(json)}`);
|
|
183
|
+
}
|
|
184
|
+
return id;
|
|
185
|
+
}
|
|
186
|
+
async post(path, params) {
|
|
187
|
+
const body = new URLSearchParams({ ...params, access_token: this.token });
|
|
188
|
+
const res = await this.fetchImpl(`${this.graph}/${path}`, {
|
|
189
|
+
method: "POST",
|
|
190
|
+
body,
|
|
191
|
+
});
|
|
192
|
+
const json = (await res.json());
|
|
193
|
+
if (!res.ok) {
|
|
194
|
+
throw new Error(`POST ${path} failed (${res.status}): ${JSON.stringify(json)}`);
|
|
195
|
+
}
|
|
196
|
+
return json;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Poll a container until FINISHED. Publishing before that returns a 400, so
|
|
200
|
+
* this step is mandatory rather than an optimization. Video containers take
|
|
201
|
+
* substantially longer than images — hence the generous default timeout.
|
|
202
|
+
*/
|
|
203
|
+
async waitFinished(containerId, label) {
|
|
204
|
+
const deadline = Date.now() + this.pollTimeoutMs;
|
|
205
|
+
let waited = 0;
|
|
206
|
+
for (;;) {
|
|
207
|
+
const url = `${this.graph}/${containerId}?fields=status_code,status&access_token=${encodeURIComponent(this.token)}`;
|
|
208
|
+
const res = await this.fetchImpl(url);
|
|
209
|
+
const json = (await res.json());
|
|
210
|
+
if (json.status_code === "FINISHED") {
|
|
211
|
+
this.log(` ${label}: ready`);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (json.status_code === "ERROR" || json.status_code === "EXPIRED") {
|
|
215
|
+
throw new Error(`Container ${label} (${containerId}) ${json.status_code}: ${json.status ?? "no detail"}`);
|
|
216
|
+
}
|
|
217
|
+
if (Date.now() >= deadline) {
|
|
218
|
+
throw new Error(`Container ${label} (${containerId}) still ${json.status_code ?? "unknown"} after ${Math.round(waited / 1000)}s.`);
|
|
219
|
+
}
|
|
220
|
+
await new Promise((r) => setTimeout(r, this.pollIntervalMs));
|
|
221
|
+
waited += this.pollIntervalMs;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=instagram.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instagram.js","sourceRoot":"","sources":["../../src/platforms/instagram.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,MAAM,aAAa,GAAG,6BAA6B,CAAC;AAEpD,4DAA4D;AAC5D,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB,wDAAwD;AACxD,MAAM,WAAW,GAAG,IAAI,CAAC;AAWzB,MAAM,OAAO,SAAS;IACX,IAAI,GAAG,WAAW,CAAC;IACnB,cAAc,GAAG,IAAI,CAAC;IAEd,KAAK,CAAS;IACd,KAAK,CAAS;IACd,MAAM,CAAqB;IAC3B,cAAc,CAAS;IACvB,aAAa,CAAS;IACtB,SAAS,CAAe;IACxB,GAAG,CAAwB;IAE5C,YAAY,MAAc,EAAE,OAAyB,EAAE;QACrD,IAAI,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,aAAa,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC/E,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,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