@yoonion/mimi-seed-mcp 0.25.2 → 0.25.4
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 +6 -5
- package/assets/agent-guide.md +29 -5
- package/dist/auth/cli.js +2 -2
- package/dist/auth/constants.d.ts +5 -2
- package/dist/auth/constants.js +17 -10
- package/dist/auth/errors.js +8 -5
- package/dist/auth/google-auth.d.ts +27 -0
- package/dist/auth/google-auth.js +39 -3
- package/dist/core/console-url.d.ts +19 -0
- package/dist/core/console-url.js +61 -0
- package/dist/core/credential-store.js +2 -0
- package/dist/drive/tools.d.ts +0 -1
- package/dist/drive/tools.js +19 -1
- package/dist/i18n/tools-en/android.d.ts +2 -2
- package/dist/i18n/tools-en/android.js +2 -2
- package/dist/i18n/tools-en/jenkins.d.ts +4 -4
- package/dist/i18n/tools-en/jenkins.js +4 -4
- package/dist/instagram/browser-login.js +4 -3
- package/dist/jenkins/credentials.d.ts +7 -3
- package/dist/jenkins/credentials.js +4 -0
- package/dist/jenkins/messages.d.ts +2 -0
- package/dist/jenkins/messages.js +15 -0
- package/dist/lib/human-approval.d.ts +49 -0
- package/dist/lib/human-approval.js +143 -0
- package/dist/lib/package-root.d.ts +5 -0
- package/dist/lib/tool-registrar.d.ts +31 -0
- package/dist/lib/tool-registrar.js +80 -3
- package/dist/registers/android.js +10 -7
- package/dist/registers/auth.js +16 -7
- package/dist/registers/jenkins.js +20 -8
- package/dist/remote-sync.js +13 -4
- package/dist/server.js +2 -1
- package/dist/social/broker-base.d.ts +7 -0
- package/dist/social/broker-base.js +11 -0
- package/dist/social/meta-app-config.d.ts +19 -0
- package/dist/social/meta-app-config.js +83 -0
- package/dist/social/meta-direct-login.d.ts +45 -0
- package/dist/social/meta-direct-login.js +307 -0
- package/dist/social/setup-cli.js +231 -22
- package/dist/threads/browser-login.js +4 -3
- package/npm-shrinkwrap.json +1985 -0
- package/package.json +6 -3
- package/tool-manifest.json +26 -0
package/dist/registers/auth.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import os from 'node:os';
|
|
3
|
-
import { GOOGLE_PROFILE_ID, listGoogleProfiles, getAuthenticatedClient, getGoogleAuthAttempt } from '../auth/google-auth.js';
|
|
3
|
+
import { GOOGLE_PROFILE_ID, listGoogleProfiles, getAuthenticatedClient, getGoogleAuthAttempt, loginOAuthClient, youtubeUploadProfiles } from '../auth/google-auth.js';
|
|
4
4
|
import { verifyYouTubeChannel, YOUTUBE_CHANNEL_ID } from '../auth/youtube-channel.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { androidPackageName } from '../lib/package-name.js';
|
|
@@ -26,6 +26,7 @@ import { resolveSocialConfigTarget } from '../social/profile-store.js';
|
|
|
26
26
|
import { lookupProjectManifest, manifestServiceEntries, } from '#core/project-manifest.js';
|
|
27
27
|
import { textResult } from '../lib/mcp-response.js';
|
|
28
28
|
import { describeToolsets } from '../lib/toolsets.js';
|
|
29
|
+
import { describeApproval } from '../lib/human-approval.js';
|
|
29
30
|
import { findInvalidJsonFiles } from '../lib/json-file.js';
|
|
30
31
|
import { credentialStoreReport } from '#core/credential-store.js';
|
|
31
32
|
import { catalog } from '#core/lang.js';
|
|
@@ -68,7 +69,8 @@ const A = catalog({
|
|
|
68
69
|
oauthMissing: '❌ Google OAuth — 미연결 → mimi_seed_auth_start',
|
|
69
70
|
youtubeUpload: '✅ YouTube — 업로드·상태 관리 권한 연결됨',
|
|
70
71
|
youtubeRead: '✅ YouTube — 채널·영상·성과 읽기 권한 연결됨',
|
|
71
|
-
youtubeMissing: '❌ YouTube — 미연결 → mimi_seed_auth_start(domains=["youtube"]) (선택)',
|
|
72
|
+
youtubeMissing: '❌ YouTube — 미연결 → mimi_seed_auth_start(profile="youtube", domains=["youtube"]) (선택)',
|
|
73
|
+
youtubeProfiles: (list, first) => `✅ YouTube — 업로드 권한 연결됨 (프로필 ${list}) — youtube_* 도구에 profile="${first}" 를 넘기세요`,
|
|
72
74
|
playOk: (count, detail) => `✅ Play Store SA — ${count}개 등록 (${detail})`,
|
|
73
75
|
playBroken: (broken, total, names) => `⚠️ Play Store SA — ${total}개 중 ${broken}개를 읽을 수 없음 (${names}) — 그 패키지는 SA 로 동작하지 않는다. setup_playstore_connection 으로 다시 등록`,
|
|
74
76
|
playMissing: '⚠️ Play Store SA — 미설정 (선택 — 로컬은 OAuth 로 가능, CI/헤드리스는 필수) → setup_playstore_connection',
|
|
@@ -99,7 +101,7 @@ const A = catalog({
|
|
|
99
101
|
reqHeader: (name) => `── ${name} 요구사항 (.mimi-seed.json) ─────────`,
|
|
100
102
|
teamHint: [
|
|
101
103
|
'ℹ️ 팀 공유가 목표라면, 각자 로컬 자격증명을 채우는 대신',
|
|
102
|
-
' 워크스페이스
|
|
104
|
+
' 자체 운영 워크스페이스 초대 → PAT 발급 → 원격 MCP 연결도 가능.',
|
|
103
105
|
],
|
|
104
106
|
},
|
|
105
107
|
// ── mimi_seed_auth_start ──
|
|
@@ -166,7 +168,8 @@ const A = catalog({
|
|
|
166
168
|
oauthMissing: '❌ Google OAuth — not connected → mimi_seed_auth_start',
|
|
167
169
|
youtubeUpload: '✅ YouTube — upload and status management permission connected',
|
|
168
170
|
youtubeRead: '✅ YouTube — channel, video, and performance read permission connected',
|
|
169
|
-
youtubeMissing: '❌ YouTube — not connected → mimi_seed_auth_start(domains=["youtube"]) (optional)',
|
|
171
|
+
youtubeMissing: '❌ YouTube — not connected → mimi_seed_auth_start(profile="youtube", domains=["youtube"]) (optional)',
|
|
172
|
+
youtubeProfiles: (list, first) => `✅ YouTube — upload permission connected (profile ${list}) — pass profile="${first}" to youtube_* tools`,
|
|
170
173
|
playOk: (count, detail) => `✅ Play Store SA — ${count} registered (${detail})`,
|
|
171
174
|
playBroken: (broken, total, names) => `⚠️ Play Store SA — ${broken} of ${total} cannot be read (${names}) — those packages won't work with an SA. Re-register with setup_playstore_connection`,
|
|
172
175
|
playMissing: '⚠️ Play Store SA — not set up (optional — OAuth works locally; required for CI/headless) → setup_playstore_connection',
|
|
@@ -197,7 +200,7 @@ const A = catalog({
|
|
|
197
200
|
reqHeader: (name) => `── ${name} requirements (.mimi-seed.json) ─────────`,
|
|
198
201
|
teamHint: [
|
|
199
202
|
'ℹ️ If the goal is team sharing, instead of each person filling in local credentials,',
|
|
200
|
-
' you can also use
|
|
203
|
+
' you can also use a team-operated workspace invite → PAT issuance → remote MCP connection.',
|
|
201
204
|
],
|
|
202
205
|
},
|
|
203
206
|
start: {
|
|
@@ -332,6 +335,8 @@ export function registerAuthTools(server) {
|
|
|
332
335
|
m.header(PKG_VERSION),
|
|
333
336
|
// 도메인을 꺼 둔 서버에서 "도구가 없다" 를 연결 문제로 오해하지 않게 켜진 toolset 을 밝힌다.
|
|
334
337
|
`🧰 Toolsets: ${describeToolsets(server.toolsets, server.manifest)}`,
|
|
338
|
+
// 승인 게이트가 이 클라이언트에서 실제로 동작하는지 — 설정만 보고는 알 수 없다 (클라이언트 지원에 달림).
|
|
339
|
+
`🛡️ Approval: ${describeApproval(server.approvalStatus())}`,
|
|
335
340
|
'',
|
|
336
341
|
];
|
|
337
342
|
// 1. Google OAuth
|
|
@@ -356,7 +361,11 @@ export function registerAuthTools(server) {
|
|
|
356
361
|
: m.youtubeRead);
|
|
357
362
|
}
|
|
358
363
|
else {
|
|
359
|
-
|
|
364
|
+
// The default login has no YouTube grant, but a named profile (the recommended setup) may.
|
|
365
|
+
const profiles = youtubeUploadProfiles();
|
|
366
|
+
lines.push(profiles.length > 0
|
|
367
|
+
? m.youtubeProfiles(profiles.map((p) => (p.channelTitle ? `${p.profile}: ${p.channelTitle}` : p.profile)).join(', '), profiles[0].profile)
|
|
368
|
+
: m.youtubeMissing);
|
|
360
369
|
}
|
|
361
370
|
// 2. Play Store SA
|
|
362
371
|
const saInfo = listRegisteredServiceAccounts();
|
|
@@ -559,7 +568,7 @@ export function registerAuthTools(server) {
|
|
|
559
568
|
let clientId;
|
|
560
569
|
let clientSecret;
|
|
561
570
|
try {
|
|
562
|
-
({ clientId, clientSecret } = await getMcpOAuthClient());
|
|
571
|
+
({ clientId, clientSecret } = await getMcpOAuthClient(loginOAuthClient(profile)));
|
|
563
572
|
}
|
|
564
573
|
catch (e) {
|
|
565
574
|
const p = classifyError(e, { phase: 'login' });
|
|
@@ -5,7 +5,7 @@ import * as jobs from '../jenkins/jobs.js';
|
|
|
5
5
|
import * as builds from '../jenkins/builds.js';
|
|
6
6
|
import { jsonResult, textResult } from '../lib/mcp-response.js';
|
|
7
7
|
import { SIGNING_SECRET_FIELDS, resolveKeystoreInput, resolveSecretInput } from '../android/keystore-store.js';
|
|
8
|
-
import { ambiguousDefaultIdNote, existingCredentialPreview, jenkinsConfiguredLines, jenkinsNotConfiguredLines, } from '../jenkins/messages.js';
|
|
8
|
+
import { ambiguousDefaultIdNote, existingCredentialPreview, jenkinsConfiguredLines, jenkinsNotConfiguredLines, newCredentialPreview, } from '../jenkins/messages.js';
|
|
9
9
|
import { catalog } from '#core/lang.js';
|
|
10
10
|
const M = catalog({
|
|
11
11
|
corrupt: (file, reason) => `❌ ${file} 이 손상되어 읽을 수 없습니다 (${reason}). 다시 저장하면 새로 씁니다.`,
|
|
@@ -33,6 +33,10 @@ const M = catalog({
|
|
|
33
33
|
jobExists: (job) => `⚠️ Job \`${job}\` already exists. Use jenkins_update_job or call again with overwrite=true.`,
|
|
34
34
|
});
|
|
35
35
|
/** 기존 id 교체 dry-run — 무엇을 덮어쓰게 되는지(id·종류·설명)와 모호한 기본 id 경고를 싣는다. */
|
|
36
|
+
function newPreview(cfg, id, requested) {
|
|
37
|
+
const note = ambiguousDefaultIdNote(id);
|
|
38
|
+
return textResult(newCredentialPreview(id, cfg.url, requested, note ? [note] : []));
|
|
39
|
+
}
|
|
36
40
|
async function existingPreview(cfg, id, requested) {
|
|
37
41
|
const note = ambiguousDefaultIdNote(id);
|
|
38
42
|
return textResult(existingCredentialPreview(id, await creds.inspectCredential(cfg, id), requested, note ? [note] : []));
|
|
@@ -96,8 +100,8 @@ export function registerJenkinsTools(server) {
|
|
|
96
100
|
server.tool('jenkins_create_credential', [
|
|
97
101
|
'Jenkins에 Secret Text credential을 생성하거나 업데이트합니다.',
|
|
98
102
|
'비밀번호, API 키, 앱 시크릿 등 문자열 값에 사용하세요.',
|
|
99
|
-
'
|
|
100
|
-
'
|
|
103
|
+
'confirm 생략/false 면 아무것도 보내지 않고 dry-run 만 반환한다 — 새 id 면 "생성 예정", 같은 id 가 있으면',
|
|
104
|
+
'"이미 존재"(교체하면 되돌릴 수 없음). 사용자 승인 후 같은 인자에 confirm: true 로 재호출.',
|
|
101
105
|
'설정이 없으면 jenkins_status를 먼저 호출하세요.',
|
|
102
106
|
].join(' '), {
|
|
103
107
|
id: z.string().describe('Credential ID (예: my-app-android-key-password)'),
|
|
@@ -111,21 +115,26 @@ export function registerJenkinsTools(server) {
|
|
|
111
115
|
.optional()
|
|
112
116
|
.describe('secret_file 에서 꺼낼 필드 (storePassword / keyPassword / keyAlias)'),
|
|
113
117
|
description: z.string().optional().describe('설명 (선택)'),
|
|
114
|
-
confirm: z.boolean().optional().describe('
|
|
118
|
+
confirm: z.boolean().optional().describe('true 일 때만 Jenkins 로 보낸다 (새 id 생성 또는 기존 값 교체). 생략/false 면 dry-run'),
|
|
115
119
|
}, async ({ id, secret, secret_file, secret_field, description, confirm }) => {
|
|
116
120
|
const value = resolveSecretInput({ secret, secretFile: secret_file, secretField: secret_field });
|
|
117
121
|
const cfg = requireJenkinsConfig();
|
|
118
|
-
const result = await creds.upsertSecretText(cfg, id, value, description ?? '', {
|
|
122
|
+
const result = await creds.upsertSecretText(cfg, id, value, description ?? '', {
|
|
123
|
+
allowReplace: confirm === true,
|
|
124
|
+
dryRun: confirm !== true,
|
|
125
|
+
});
|
|
119
126
|
if (result === 'exists')
|
|
120
127
|
return existingPreview(cfg, id, creds.KIND_STRING);
|
|
128
|
+
if (result === 'new')
|
|
129
|
+
return newPreview(cfg, id, creds.KIND_STRING);
|
|
121
130
|
return textResult(`✅ Jenkins credential ${result}: \`${id}\``);
|
|
122
131
|
});
|
|
123
132
|
// ── 4. Secret File (keystore) ──────────────────────────────────────────────
|
|
124
133
|
server.tool('jenkins_upload_keystore', [
|
|
125
134
|
'Jenkins에 Android keystore 파일을 Secret File credential로 업로드합니다.',
|
|
126
135
|
'keystore_base64에 .jks/.p12 파일을 base64로 인코딩한 값을 전달하세요.',
|
|
127
|
-
'
|
|
128
|
-
'
|
|
136
|
+
'confirm 생략/false 면 아무것도 보내지 않고 dry-run 만 반환한다 — 새 id 면 "생성 예정", 같은 id 가 있으면',
|
|
137
|
+
'"이미 존재"(기존 keystore 를 교체하면 되돌릴 수 없음). 사용자 승인 후 같은 인자에 confirm: true 로 재호출.',
|
|
129
138
|
'설정이 없으면 jenkins_status를 먼저 호출하세요.',
|
|
130
139
|
].join(' '), {
|
|
131
140
|
id: z.string().describe('Credential ID (예: my-app-android-keystore)'),
|
|
@@ -136,15 +145,18 @@ export function registerJenkinsTools(server) {
|
|
|
136
145
|
.describe('권장 — android_generate_keystore 가 만든 keystore 절대경로 (~/.mimi-seed/keystores/ 안만 허용)'),
|
|
137
146
|
file_name: z.string().default('keystore.jks').describe('파일명 (기본: keystore.jks)'),
|
|
138
147
|
description: z.string().optional().describe('설명 (선택)'),
|
|
139
|
-
confirm: z.boolean().optional().describe('
|
|
148
|
+
confirm: z.boolean().optional().describe('true 일 때만 Jenkins 로 보낸다 (새 id 생성 또는 기존 keystore 교체). 생략/false 면 dry-run'),
|
|
140
149
|
}, async ({ id, keystore_base64, keystore_path, file_name, description, confirm }) => {
|
|
141
150
|
const keystore = resolveKeystoreInput({ base64: keystore_base64, path: keystore_path });
|
|
142
151
|
const cfg = requireJenkinsConfig();
|
|
143
152
|
const result = await creds.upsertSecretFile(cfg, id, keystore, file_name, description ?? '', {
|
|
144
153
|
allowReplace: confirm === true,
|
|
154
|
+
dryRun: confirm !== true,
|
|
145
155
|
});
|
|
146
156
|
if (result === 'exists')
|
|
147
157
|
return existingPreview(cfg, id, creds.KIND_FILE);
|
|
158
|
+
if (result === 'new')
|
|
159
|
+
return newPreview(cfg, id, creds.KIND_FILE);
|
|
148
160
|
return textResult(`✅ Jenkins keystore credential ${result}: \`${id}\` (${file_name})`);
|
|
149
161
|
});
|
|
150
162
|
// ── 5. 삭제 ───────────────────────────────────────────────────────────────
|
package/dist/remote-sync.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { consoleBase, consoleBaseProblem, consoleUrl } from '#core/console-url.js';
|
|
1
2
|
import os from 'node:os';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { getAppStoreCredentials } from './appstore/auth.js';
|
|
@@ -26,7 +27,8 @@ const R = catalog({
|
|
|
26
27
|
skippedHeader: (n) => `- 건너뜀: 등록되지 않은 패키지 ${n}개 (playstore_list_service_accounts 로 등록 목록 확인):`,
|
|
27
28
|
oauthNotCopied: '- Google OAuth: 복사하지 않음 (원격 웹에서 별도 동의 필요)',
|
|
28
29
|
previewOnly: '미리보기만 수행했습니다. 원격 저장은 confirm=true일 때만 실행됩니다.',
|
|
29
|
-
noConfig: '원격 연결 정보가 없습니다.
|
|
30
|
+
noConfig: '원격 연결 정보가 없습니다. 팀 콘솔의 MIMI_SEED_WEB_BASE를 설정하고 `mimi-seed init`을 실행하세요.',
|
|
31
|
+
webBaseIgnored: (problem) => `MIMI_SEED_WEB_BASE 는 설정돼 있지만 받아들이지 않았습니다 (${problem}) — 팀 콘솔의 https 루트 주소(경로·?·# 없이)여야 합니다.`,
|
|
30
32
|
untrusted: (reason) => `원격 엔드포인트를 신뢰할 수 없어 전송하지 않았습니다: ${reason}`,
|
|
31
33
|
failed: '실패',
|
|
32
34
|
skippedResult: (name) => `- Play ${name}: 건너뜀 (등록되지 않은 패키지)`,
|
|
@@ -51,7 +53,8 @@ const R = catalog({
|
|
|
51
53
|
skippedHeader: (n) => `- Skipped: ${n} unregistered package(s) (check the registered list with playstore_list_service_accounts):`,
|
|
52
54
|
oauthNotCopied: '- Google OAuth: not copied (requires separate consent on the remote web)',
|
|
53
55
|
previewOnly: 'Preview only. Remote storage runs only with confirm=true.',
|
|
54
|
-
noConfig: 'No remote connection info.
|
|
56
|
+
noConfig: 'No remote connection info. Set MIMI_SEED_WEB_BASE to your team console and run `mimi-seed init`.',
|
|
57
|
+
webBaseIgnored: (problem) => `MIMI_SEED_WEB_BASE is set but was not accepted (${problem}) — it must be the team console's https root address (no path, ? or #).`,
|
|
55
58
|
untrusted: (reason) => `The remote endpoint is not trusted, so nothing was sent: ${reason}`,
|
|
56
59
|
failed: 'failed',
|
|
57
60
|
skippedResult: (name) => `- Play ${name}: skipped (unregistered package)`,
|
|
@@ -61,7 +64,9 @@ const R = catalog({
|
|
|
61
64
|
function getRemoteConfig() {
|
|
62
65
|
const envToken = process.env.MIMI_SEED_TOKEN;
|
|
63
66
|
if (envToken) {
|
|
64
|
-
const webBase = process.env.MIMI_SEED_WEB_BASE
|
|
67
|
+
const webBase = consoleBase(process.env.MIMI_SEED_WEB_BASE);
|
|
68
|
+
if (!webBase)
|
|
69
|
+
return null;
|
|
65
70
|
return { token: envToken, endpoint: `${webBase}/api/mcp`, webBase };
|
|
66
71
|
}
|
|
67
72
|
try {
|
|
@@ -70,6 +75,8 @@ function getRemoteConfig() {
|
|
|
70
75
|
if (!parsed.token || !parsed.endpoint)
|
|
71
76
|
return null;
|
|
72
77
|
const webBase = parsed.webBase ?? parsed.endpoint.replace(/\/api\/mcp\/?$/, '');
|
|
78
|
+
if (!consoleBase(webBase) || !consoleUrl(parsed.endpoint))
|
|
79
|
+
return null;
|
|
73
80
|
return { token: parsed.token, endpoint: parsed.endpoint, webBase };
|
|
74
81
|
}
|
|
75
82
|
catch {
|
|
@@ -197,7 +204,9 @@ export async function syncRemoteCredentials(options, dependencies = defaultDepen
|
|
|
197
204
|
return [...lines, '', m.previewOnly].join('\n');
|
|
198
205
|
}
|
|
199
206
|
if (!config) {
|
|
200
|
-
|
|
207
|
+
// 설정했는데 거부된 값은 "연결 정보 없음" 만으로는 원인을 알 수 없다 — 이유를 함께 보인다.
|
|
208
|
+
const problem = consoleBaseProblem(process.env.MIMI_SEED_WEB_BASE);
|
|
209
|
+
return [...lines, '', ...(problem ? [m.webBaseIgnored(problem)] : []), m.noConfig].join('\n');
|
|
201
210
|
}
|
|
202
211
|
if (!endpoint?.ok) {
|
|
203
212
|
return [...lines, '', m.untrusted(endpoint?.reason)].join('\n');
|
package/dist/server.js
CHANGED
|
@@ -48,6 +48,7 @@ export function buildServer(version, options = {}) {
|
|
|
48
48
|
'If the user starts Mimi Seed without a specific task, show mimi-seed://tools/menu and let them choose one or more services by number, name, or free-form description. Read mimi-seed://tools/menu/{areas} for the selected comma-separated service IDs before loading tools for the task.',
|
|
49
49
|
'For a targeted read, start with the domain tool. Use mimi_seed_status for onboarding, connection diagnostics, or unresolved authentication errors.',
|
|
50
50
|
'For preview-gated writes, get the preview and explicit approval before confirming the same operation.',
|
|
51
|
+
'A confirmed call may also open an approval dialog for the user; if it returns ⛔ (not approved), nothing changed — do not retry, ask the user.',
|
|
51
52
|
].join(' '),
|
|
52
53
|
});
|
|
53
54
|
// 도구는 McpServer 에 직접이 아니라 레지스트라를 거쳐 등록한다 — manifest(SSOT)에서
|
|
@@ -61,7 +62,7 @@ export function buildServer(version, options = {}) {
|
|
|
61
62
|
// 원문은 한국어이고 en 이면 i18n/tools-en 번역표로 바꾼다 (lib/tool-text.ts). 서버 수명 동안 고정이다.
|
|
62
63
|
const toolLang = options.lang ?? resolveLang();
|
|
63
64
|
const translate = toolTextTranslator(toolLang);
|
|
64
|
-
const registrar = createToolRegistrar(server, { manifest, toolsets, translate });
|
|
65
|
+
const registrar = createToolRegistrar(server, { manifest, toolsets, translate, env: options.env ?? process.env });
|
|
65
66
|
registerFirebaseTools(registrar);
|
|
66
67
|
registerAdmobTools(registrar);
|
|
67
68
|
registerPlaystoreTools(registrar);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The team console that brokers Instagram / Threads browser login, or null. One rule for the gate in setup-cli and
|
|
3
|
+
* for the brokers themselves: a console base (origin only — consoleBase) over HTTPS. The CLI also accepts a loopback
|
|
4
|
+
* `http://` console for development, which the broker refuses; when the gate used plain consoleBase, such a value
|
|
5
|
+
* picked the broker path, failed with "configuration", and never fell back to the local login.
|
|
6
|
+
*/
|
|
7
|
+
export declare function socialBrokerBase(value?: string | undefined): string | null;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { consoleBase } from '#core/console-url.js';
|
|
2
|
+
/**
|
|
3
|
+
* The team console that brokers Instagram / Threads browser login, or null. One rule for the gate in setup-cli and
|
|
4
|
+
* for the brokers themselves: a console base (origin only — consoleBase) over HTTPS. The CLI also accepts a loopback
|
|
5
|
+
* `http://` console for development, which the broker refuses; when the gate used plain consoleBase, such a value
|
|
6
|
+
* picked the broker path, failed with "configuration", and never fell back to the local login.
|
|
7
|
+
*/
|
|
8
|
+
export function socialBrokerBase(value = process.env.MIMI_SEED_WEB_BASE) {
|
|
9
|
+
const base = consoleBase(value);
|
|
10
|
+
return base && new URL(base).protocol === 'https:' ? base : null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type MetaLoginPlatform = 'instagram' | 'threads';
|
|
2
|
+
export interface MetaAppConfig {
|
|
3
|
+
appId: string;
|
|
4
|
+
appSecret: string;
|
|
5
|
+
/** Must match a redirect URI registered in the Meta app dashboard exactly. */
|
|
6
|
+
redirectUri: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function metaAppsPath(homeDir?: string): string;
|
|
9
|
+
/** A loopback redirect is captured by a local server; any other HTTPS redirect is pasted back by the user. */
|
|
10
|
+
export declare function isLoopbackRedirect(redirectUri: string): boolean;
|
|
11
|
+
export declare function isValidAppId(value: string): boolean;
|
|
12
|
+
export declare function isValidAppSecret(value: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* HTTPS anywhere, or plain HTTP only on a loopback host with an explicit port (so the local server
|
|
15
|
+
* knows where to listen). No credentials, query, or fragment: Meta compares the URI byte for byte.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isValidRedirectUri(value: string): boolean;
|
|
18
|
+
export declare function loadMetaApp(platform: MetaLoginPlatform, homeDir?: string): MetaAppConfig | null;
|
|
19
|
+
export declare function saveMetaApp(platform: MetaLoginPlatform, config: MetaAppConfig, homeDir?: string): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// The user's own Meta app credentials for broker-free Instagram / Threads browser login.
|
|
2
|
+
//
|
|
3
|
+
// File: ~/.mimi-seed/meta-apps.json (0600) — { instagram?: MetaAppConfig, threads?: MetaAppConfig }.
|
|
4
|
+
// Instagram Login and Threads each have their own app ID and secret inside one Meta app, so they are
|
|
5
|
+
// stored per platform. The app is not per social profile: one app can sign in several accounts.
|
|
6
|
+
// This module is the only writer (one writer per credential file).
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { writeCredentialJson } from '#core/atomic-write.js';
|
|
11
|
+
import { readCredentialFileSync } from '#core/credential-read.js';
|
|
12
|
+
export function metaAppsPath(homeDir = os.homedir()) {
|
|
13
|
+
return path.join(homeDir, '.mimi-seed', 'meta-apps.json');
|
|
14
|
+
}
|
|
15
|
+
const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
|
|
16
|
+
/** A loopback redirect is captured by a local server; any other HTTPS redirect is pasted back by the user. */
|
|
17
|
+
export function isLoopbackRedirect(redirectUri) {
|
|
18
|
+
const url = new URL(redirectUri);
|
|
19
|
+
return url.protocol === 'http:' && LOOPBACK_HOSTS.has(url.hostname) && url.port !== '';
|
|
20
|
+
}
|
|
21
|
+
export function isValidAppId(value) {
|
|
22
|
+
return /^\d{5,32}$/.test(value);
|
|
23
|
+
}
|
|
24
|
+
export function isValidAppSecret(value) {
|
|
25
|
+
return /^[A-Za-z0-9]{16,128}$/.test(value);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* HTTPS anywhere, or plain HTTP only on a loopback host with an explicit port (so the local server
|
|
29
|
+
* knows where to listen). No credentials, query, or fragment: Meta compares the URI byte for byte.
|
|
30
|
+
*/
|
|
31
|
+
export function isValidRedirectUri(value) {
|
|
32
|
+
let url;
|
|
33
|
+
try {
|
|
34
|
+
url = new URL(value);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
} // an unparsable URI is simply not a valid redirect
|
|
39
|
+
if (url.username || url.password || url.search || url.hash)
|
|
40
|
+
return false;
|
|
41
|
+
if (url.protocol === 'https:')
|
|
42
|
+
return true;
|
|
43
|
+
return url.protocol === 'http:' && LOOPBACK_HOSTS.has(url.hostname) && url.port !== '';
|
|
44
|
+
}
|
|
45
|
+
function isValidConfig(value) {
|
|
46
|
+
if (!value || typeof value !== 'object')
|
|
47
|
+
return false;
|
|
48
|
+
const v = value;
|
|
49
|
+
return typeof v.appId === 'string' && isValidAppId(v.appId) &&
|
|
50
|
+
typeof v.appSecret === 'string' && isValidAppSecret(v.appSecret) &&
|
|
51
|
+
typeof v.redirectUri === 'string' && isValidRedirectUri(v.redirectUri);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A missing file is "no app yet". A file that exists but cannot be read is an error, never "empty": treating it
|
|
55
|
+
* as empty would let the next save overwrite the other platform's app. The parse error is not quoted because
|
|
56
|
+
* recent V8 messages include a snippet of the file, which holds the app secret.
|
|
57
|
+
*/
|
|
58
|
+
function readDocument(homeDir) {
|
|
59
|
+
const file = metaAppsPath(homeDir);
|
|
60
|
+
if (!fs.existsSync(file))
|
|
61
|
+
return {};
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = JSON.parse(readCredentialFileSync(file));
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw new Error(`Cannot read ${file}; it was left unchanged. Fix or delete it, then sign in again.`, { cause: error });
|
|
68
|
+
}
|
|
69
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
70
|
+
throw new Error(`${file} is not a JSON object; it was left unchanged. Fix or delete it, then sign in again.`);
|
|
71
|
+
}
|
|
72
|
+
return parsed;
|
|
73
|
+
}
|
|
74
|
+
export function loadMetaApp(platform, homeDir) {
|
|
75
|
+
const entry = readDocument(homeDir)[platform];
|
|
76
|
+
return isValidConfig(entry) ? { appId: entry.appId, appSecret: entry.appSecret, redirectUri: entry.redirectUri } : null;
|
|
77
|
+
}
|
|
78
|
+
export function saveMetaApp(platform, config, homeDir) {
|
|
79
|
+
if (!isValidConfig(config))
|
|
80
|
+
throw new Error(`Invalid ${platform} app settings; nothing was saved.`);
|
|
81
|
+
const doc = readDocument(homeDir);
|
|
82
|
+
writeCredentialJson(metaAppsPath(homeDir), { ...doc, [platform]: config });
|
|
83
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ConnectResult } from '../facebook/setup.js';
|
|
2
|
+
import { type SocialConfigOptions } from './profile-store.js';
|
|
3
|
+
import { type MetaAppConfig, type MetaLoginPlatform } from './meta-app-config.js';
|
|
4
|
+
export type MetaDirectLoginCode = 'configuration' | 'denied' | 'timeout' | 'state' | 'exchange' | 'validation';
|
|
5
|
+
export declare class MetaDirectLoginError extends Error {
|
|
6
|
+
readonly code: MetaDirectLoginCode;
|
|
7
|
+
/** Provider's own reason (e.g. a redirect_uri mismatch), already scrubbed of the code and secret. */
|
|
8
|
+
readonly detail?: string | undefined;
|
|
9
|
+
constructor(code: MetaDirectLoginCode,
|
|
10
|
+
/** Provider's own reason (e.g. a redirect_uri mismatch), already scrubbed of the code and secret. */
|
|
11
|
+
detail?: string | undefined);
|
|
12
|
+
}
|
|
13
|
+
interface ProviderSpec {
|
|
14
|
+
authorizeUrl: string;
|
|
15
|
+
tokenUrl: string;
|
|
16
|
+
longLivedUrl: string;
|
|
17
|
+
longLivedGrant: string;
|
|
18
|
+
scopes: string[];
|
|
19
|
+
}
|
|
20
|
+
/** Scopes cover what the instagram_* / threads_* tools call: account lookup and publishing. */
|
|
21
|
+
export declare const META_LOGIN_PROVIDERS: Record<MetaLoginPlatform, ProviderSpec>;
|
|
22
|
+
export declare function buildAuthorizeUrl(platform: MetaLoginPlatform, app: MetaAppConfig, state: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Extract the authorization code from a pasted redirect URL. The URL must point at the registered redirect
|
|
25
|
+
* (same origin and path) and carry the expected state; a bare code is refused because it cannot be tied to
|
|
26
|
+
* this login attempt.
|
|
27
|
+
*/
|
|
28
|
+
export declare function parsePastedRedirect(input: string, app: MetaAppConfig, state: string): string;
|
|
29
|
+
export interface LongLivedToken {
|
|
30
|
+
accessToken: string;
|
|
31
|
+
expiresInSeconds: number;
|
|
32
|
+
}
|
|
33
|
+
/** code → short-lived token → long-lived token. The code is single-use, so the POST is never retried. */
|
|
34
|
+
export declare function exchangeCode(platform: MetaLoginPlatform, app: MetaAppConfig, code: string): Promise<LongLivedToken>;
|
|
35
|
+
export interface MetaDirectLoginOptions extends SocialConfigOptions {
|
|
36
|
+
app: MetaAppConfig;
|
|
37
|
+
timeoutMs?: number;
|
|
38
|
+
openBrowser?: (url: string) => Promise<void>;
|
|
39
|
+
/** Called with the authorize URL so a CLI can print it when the browser does not open. */
|
|
40
|
+
onUrl?: (url: string) => void;
|
|
41
|
+
/** Paste mode (non-loopback redirect): returns the full redirected URL the user copied. */
|
|
42
|
+
readRedirect?: () => Promise<string>;
|
|
43
|
+
}
|
|
44
|
+
export declare function connectWithMetaApp(platform: MetaLoginPlatform, options: MetaDirectLoginOptions): Promise<ConnectResult>;
|
|
45
|
+
export {};
|