@yoonion/mimi-seed-mcp 0.23.3 → 0.24.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/assets/agent-guide.md +13 -0
- package/dist/auth/google-auth.d.ts +1 -1
- package/dist/auth/google-auth.js +14 -8
- package/dist/auth/scopes.d.ts +8 -0
- package/dist/auth/scopes.js +16 -4
- package/dist/checks/appstore-submission.d.ts +4 -4
- package/dist/checks/plan.d.ts +2 -2
- package/dist/checks/release-readiness.d.ts +5 -5
- package/dist/checks/risks.d.ts +1 -1
- package/dist/ga4/cli.js +49 -17
- package/dist/ga4/tools.d.ts +7 -2
- package/dist/ga4/tools.js +39 -22
- package/dist/gsc/tools.d.ts +116 -9
- package/dist/gsc/tools.js +93 -17
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.js +24 -21
- package/dist/index.js +6 -2
- package/dist/lib/cli-args.d.ts +1 -1
- package/dist/lib/cli-args.js +10 -2
- package/dist/lib/tool-menu.d.ts +19 -0
- package/dist/lib/tool-menu.js +61 -0
- package/dist/lib/toolsets.d.ts +4 -2
- package/dist/lib/toolsets.js +26 -4
- package/dist/prompts.d.ts +2 -1
- package/dist/prompts.js +20 -9
- package/dist/registers/ga4.js +30 -37
- package/dist/registers/gsc.js +40 -39
- package/dist/resources.js +22 -3
- package/dist/server.js +2 -1
- package/dist/tools-cli.d.ts +2 -0
- package/dist/tools-cli.js +59 -0
- package/dist/video/schemas.d.ts +3 -3
- package/package.json +2 -1
package/assets/agent-guide.md
CHANGED
|
@@ -38,6 +38,18 @@ ToolSearch(query="select:<tool_name>[,<tool_name>...]")
|
|
|
38
38
|
|
|
39
39
|
Use the MCP client's native discovery when tools are deferred. If the required schema is already visible, call the tool directly.
|
|
40
40
|
|
|
41
|
+
### Let the user choose services
|
|
42
|
+
|
|
43
|
+
If the user starts Mimi Seed without a specific task, show the plain-text `mimi-seed://tools/menu` resource
|
|
44
|
+
and ask which services they want to use. The `select-tools` prompt provides the same menu. Accept several
|
|
45
|
+
numbers, service names, or a free-form description. Map the answer to the IDs shown in parentheses and
|
|
46
|
+
ask a short follow-up when the intent is unclear.
|
|
47
|
+
|
|
48
|
+
Read `mimi-seed://tools/menu/{areas}` using the selected comma-separated IDs, for example
|
|
49
|
+
`mimi-seed://tools/menu/ga4,bigquery`. This returns tool names for the selection. Load the tools needed for
|
|
50
|
+
the current step using the host's discovery feature. YouTube video production and uploads have separate
|
|
51
|
+
choices. Keep operation-specific approvals in effect.
|
|
52
|
+
|
|
41
53
|
### Ready-made `select:` batches
|
|
42
54
|
|
|
43
55
|
Use the table to find tool names, then select only the active tools needed for the current step. The table is generated from the full manifest. Check the runtime catalog if this server limits its toolsets.
|
|
@@ -190,6 +202,7 @@ The server can expose only the domains a project needs — set these in the MCP
|
|
|
190
202
|
|----------|---------|
|
|
191
203
|
| `MIMI_SEED_TOOLSETS` | Comma-separated domain keys from `mimi-seed://tools/catalog` (`playstore`, `appstore`, `firebase`, …) and/or groups: `store` (playstore · appstore · android · ai), `google` (firebase · admob · iam · billing · bigquery · ga4 · gsc · googleads), `social` (facebook · instagram · threads · tiktok · youtube), `media` (video · youtube), `build` (ci · jenkins · android), `all`. Unset = everything (default). |
|
|
192
204
|
| `MIMI_SEED_TOOLSETS_EXCLUDE` | Same syntax; removed from the include set. |
|
|
205
|
+
| `MIMI_SEED_TOOLS` | Optional exact tool names for a launcher to supply at startup. Names must be available under the toolset settings. The server registers only the supplied names, including any auth or checks tools explicitly selected. |
|
|
193
206
|
|
|
194
207
|
A few tools also belong to a second toolset: `youtube_upload_video` / `youtube_get_video_status` /
|
|
195
208
|
`youtube_update_video_privacy` (`video` domain) are also in `youtube`, and `jenkins_upload_playstore_sa` (`android`)
|
|
@@ -60,7 +60,7 @@ export declare function createOAuth2Client(clientId: string, clientSecret: strin
|
|
|
60
60
|
* Get authenticated OAuth2 client.
|
|
61
61
|
* Returns null if not authenticated yet.
|
|
62
62
|
*/
|
|
63
|
-
export declare function getAuthenticatedClient(profile?: string): ReturnType<typeof createOAuth2Client> | null;
|
|
63
|
+
export declare function getAuthenticatedClient(profile?: string, expectedTokens?: StoredTokens): ReturnType<typeof createOAuth2Client> | null;
|
|
64
64
|
export declare function getGoogleAuthAttempt(profile?: string): {
|
|
65
65
|
status: "pending" | "succeeded" | "failed";
|
|
66
66
|
expectedChannelId?: string;
|
package/dist/auth/google-auth.js
CHANGED
|
@@ -178,13 +178,18 @@ export function createOAuth2Client(clientId, clientSecret) {
|
|
|
178
178
|
* Get authenticated OAuth2 client.
|
|
179
179
|
* Returns null if not authenticated yet.
|
|
180
180
|
*/
|
|
181
|
-
export function getAuthenticatedClient(profile) {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (!tokens)
|
|
181
|
+
export function getAuthenticatedClient(profile, expectedTokens) {
|
|
182
|
+
const grant = profile === undefined ? undefined : readProfile(profile);
|
|
183
|
+
const creds = profile === undefined ? getStoredCredentials() : grant?.credentials;
|
|
184
|
+
const tokens = profile === undefined ? getStoredTokens() : grant?.tokens;
|
|
185
|
+
if (!creds || !tokens)
|
|
187
186
|
return null;
|
|
187
|
+
// requireAuth가 권한을 확인한 토큰과 실제 요청에 쓰는 토큰이 일치해야 한다.
|
|
188
|
+
if (expectedTokens && (tokens.refresh_token !== expectedTokens.refresh_token ||
|
|
189
|
+
tokens.access_token !== expectedTokens.access_token ||
|
|
190
|
+
tokens.scope !== expectedTokens.scope)) {
|
|
191
|
+
throw new Error('요청을 준비하는 동안 Google 인증이 변경됐습니다. 같은 프로필로 다시 시도하세요.');
|
|
192
|
+
}
|
|
188
193
|
const client = createOAuth2Client(creds.clientId, creds.clientSecret);
|
|
189
194
|
client.setCredentials(tokens);
|
|
190
195
|
// Auto-refresh
|
|
@@ -452,7 +457,8 @@ export function ensureFreshAccessToken(marginMs = 300_000, profile) {
|
|
|
452
457
|
return promise;
|
|
453
458
|
}
|
|
454
459
|
async function ensureFreshAccessTokenOnce(marginMs, profile) {
|
|
455
|
-
const
|
|
460
|
+
const grant = profile === undefined ? undefined : readProfile(profile);
|
|
461
|
+
const tokens = profile === undefined ? getStoredTokens() : grant?.tokens;
|
|
456
462
|
if (!tokens) {
|
|
457
463
|
return {
|
|
458
464
|
status: 'unauthenticated',
|
|
@@ -489,7 +495,7 @@ async function ensureFreshAccessTokenOnce(marginMs, profile) {
|
|
|
489
495
|
// 원격 의존을 최초 1회로 끝낸다. 조회 실패는 raw throw 가 아니라 분류된 에러로 반환.
|
|
490
496
|
let clientId;
|
|
491
497
|
let clientSecret;
|
|
492
|
-
const stored = getStoredCredentials(
|
|
498
|
+
const stored = profile === undefined ? getStoredCredentials() : grant?.credentials;
|
|
493
499
|
if (stored?.clientId && stored?.clientSecret) {
|
|
494
500
|
({ clientId, clientSecret } = stored);
|
|
495
501
|
}
|
package/dist/auth/scopes.d.ts
CHANGED
|
@@ -54,6 +54,11 @@ export declare const AUTH_DOMAINS: {
|
|
|
54
54
|
readonly scopes: readonly ["https://www.googleapis.com/auth/webmasters"];
|
|
55
55
|
readonly summary: "gsc_* — 사이트·사이트맵·검색 성과 (사이트맵 제출 포함)";
|
|
56
56
|
};
|
|
57
|
+
readonly gsc_readonly: {
|
|
58
|
+
readonly label: "Search Console (read-only)";
|
|
59
|
+
readonly scopes: readonly ["https://www.googleapis.com/auth/webmasters.readonly"];
|
|
60
|
+
readonly summary: "사이트·사이트맵·URL 색인 상태·검색 성과 조회";
|
|
61
|
+
};
|
|
57
62
|
readonly ga4: {
|
|
58
63
|
readonly label: "Google Analytics (GA4)";
|
|
59
64
|
readonly scopes: readonly ["https://www.googleapis.com/auth/analytics.edit", "https://www.googleapis.com/auth/analytics.readonly"];
|
|
@@ -79,6 +84,9 @@ export type AuthDomainId = keyof typeof AUTH_DOMAINS;
|
|
|
79
84
|
/** z.enum 등 튜플이 필요한 자리에 쓰는 도메인 id 목록 (선언 순서 유지). */
|
|
80
85
|
export declare const DOMAIN_IDS: [AuthDomainId, ...AuthDomainId[]];
|
|
81
86
|
export declare const CLOUD_PLATFORM_SCOPE: "https://www.googleapis.com/auth/cloud-platform";
|
|
87
|
+
export declare const GSC_WRITE_SCOPE: "https://www.googleapis.com/auth/webmasters";
|
|
88
|
+
export declare const GSC_READONLY_SCOPE: "https://www.googleapis.com/auth/webmasters.readonly";
|
|
89
|
+
export declare const GSC_READ_SCOPES: readonly ["https://www.googleapis.com/auth/webmasters.readonly", "https://www.googleapis.com/auth/webmasters"];
|
|
82
90
|
/** Drive OAuth 경로가 pre-flight 하는 스코프. 도메인 정의에서 파생한다(리터럴 중복 금지). */
|
|
83
91
|
export declare const DRIVE_FILE_SCOPE: "https://www.googleapis.com/auth/drive.file";
|
|
84
92
|
/**
|
package/dist/auth/scopes.js
CHANGED
|
@@ -56,6 +56,11 @@ export const AUTH_DOMAINS = {
|
|
|
56
56
|
scopes: ['https://www.googleapis.com/auth/webmasters'],
|
|
57
57
|
summary: 'gsc_* — 사이트·사이트맵·검색 성과 (사이트맵 제출 포함)',
|
|
58
58
|
},
|
|
59
|
+
gsc_readonly: {
|
|
60
|
+
label: 'Search Console (read-only)',
|
|
61
|
+
scopes: ['https://www.googleapis.com/auth/webmasters.readonly'],
|
|
62
|
+
summary: '사이트·사이트맵·URL 색인 상태·검색 성과 조회',
|
|
63
|
+
},
|
|
59
64
|
ga4: {
|
|
60
65
|
label: 'Google Analytics (GA4)',
|
|
61
66
|
scopes: [
|
|
@@ -92,6 +97,9 @@ export const AUTH_DOMAINS = {
|
|
|
92
97
|
/** z.enum 등 튜플이 필요한 자리에 쓰는 도메인 id 목록 (선언 순서 유지). */
|
|
93
98
|
export const DOMAIN_IDS = Object.keys(AUTH_DOMAINS);
|
|
94
99
|
export const CLOUD_PLATFORM_SCOPE = AUTH_DOMAINS.gcp.scopes[0];
|
|
100
|
+
export const GSC_WRITE_SCOPE = AUTH_DOMAINS.gsc.scopes[0];
|
|
101
|
+
export const GSC_READONLY_SCOPE = AUTH_DOMAINS.gsc_readonly.scopes[0];
|
|
102
|
+
export const GSC_READ_SCOPES = [GSC_READONLY_SCOPE, GSC_WRITE_SCOPE];
|
|
95
103
|
/** Drive OAuth 경로가 pre-flight 하는 스코프. 도메인 정의에서 파생한다(리터럴 중복 금지). */
|
|
96
104
|
export const DRIVE_FILE_SCOPE = AUTH_DOMAINS.drive.scopes[0];
|
|
97
105
|
/**
|
|
@@ -104,8 +112,10 @@ export const DRIVE_FILE_SCOPE = AUTH_DOMAINS.drive.scopes[0];
|
|
|
104
112
|
* 죽는 함정이 된다. auth-scopes.test.ts 가 값과 도메인 포함 여부를 함께 고정한다.
|
|
105
113
|
*/
|
|
106
114
|
export const PLAY_DEVELOPER_REPORTING_SCOPE = AUTH_DOMAINS.playstore.scopes[1];
|
|
107
|
-
function
|
|
108
|
-
|
|
115
|
+
function requestedScopes(domains) {
|
|
116
|
+
const scopes = [...new Set(domains.flatMap((id) => AUTH_DOMAINS[id].scopes))];
|
|
117
|
+
// webmasters already authorizes all Search Console reads.
|
|
118
|
+
return scopes.includes(GSC_WRITE_SCOPE) ? scopes.filter((scope) => scope !== GSC_READONLY_SCOPE) : scopes;
|
|
109
119
|
}
|
|
110
120
|
/**
|
|
111
121
|
* 공백 구분 scope 문자열들의 합집합. tokens.json 의 scope 는 누적(monotonic)이어야 하므로
|
|
@@ -127,7 +137,7 @@ export function mergeScopeStrings(...parts) {
|
|
|
127
137
|
* 도메인 미지정 로그인의 기본값이자, 선택형 도입 전 full-scope 목록과 동일해야 한다
|
|
128
138
|
* (auth-scopes.test.ts 가 고정한다 — 스코프가 소리 없이 빠지면 기존 사용자 도구가 죽는다).
|
|
129
139
|
*/
|
|
130
|
-
export const ALL_SCOPES =
|
|
140
|
+
export const ALL_SCOPES = requestedScopes(DOMAIN_IDS);
|
|
131
141
|
/**
|
|
132
142
|
* 모든 로그인에 함께 싣는 계정 식별 스코프 (비민감 — 동의 화면에 "이메일 주소 보기"만 추가).
|
|
133
143
|
*
|
|
@@ -142,7 +152,7 @@ export const IDENTITY_SCOPES = ['openid', 'https://www.googleapis.com/auth/useri
|
|
|
142
152
|
export function scopesForDomains(domains) {
|
|
143
153
|
if (!domains || domains.length === 0)
|
|
144
154
|
return [...ALL_SCOPES];
|
|
145
|
-
return
|
|
155
|
+
return requestedScopes(domains);
|
|
146
156
|
}
|
|
147
157
|
/** 스코프 하나를 요구하는 도메인들 (INSUFFICIENT_SCOPE 안내에서 "--domains X" 를 채울 때 사용). */
|
|
148
158
|
export function domainsForScope(scope) {
|
|
@@ -169,6 +179,8 @@ export function summarizeGrantedDomains(scopeStr) {
|
|
|
169
179
|
if (scopeStr === undefined)
|
|
170
180
|
return { known: false, granted: [], missing: [] };
|
|
171
181
|
const grantedScopes = new Set(scopeStr.split(' ').filter(Boolean));
|
|
182
|
+
if (grantedScopes.has(GSC_WRITE_SCOPE))
|
|
183
|
+
grantedScopes.add(GSC_READONLY_SCOPE);
|
|
172
184
|
const granted = [];
|
|
173
185
|
const missing = [];
|
|
174
186
|
for (const id of DOMAIN_IDS) {
|
|
@@ -23,7 +23,7 @@ export declare function checkAppStoreSubmission(appId: string, opts?: {
|
|
|
23
23
|
canSubmit: boolean;
|
|
24
24
|
blockingCodes: string[];
|
|
25
25
|
risks: {
|
|
26
|
-
level: "
|
|
26
|
+
level: "info" | "blocker" | "warning";
|
|
27
27
|
code: string;
|
|
28
28
|
title: string;
|
|
29
29
|
detail: string;
|
|
@@ -34,14 +34,14 @@ export declare function checkAppStoreSubmission(appId: string, opts?: {
|
|
|
34
34
|
status: "selected";
|
|
35
35
|
version: import("../appstore/release-target.js").AppStoreVersionCandidate;
|
|
36
36
|
buildRisk: {
|
|
37
|
-
level: "
|
|
37
|
+
level: "info" | "blocker" | "warning";
|
|
38
38
|
code: string;
|
|
39
39
|
title: string;
|
|
40
40
|
detail: string;
|
|
41
41
|
fixUrl?: string | undefined;
|
|
42
42
|
} | undefined;
|
|
43
43
|
versionRisks: {
|
|
44
|
-
level: "
|
|
44
|
+
level: "info" | "blocker" | "warning";
|
|
45
45
|
code: string;
|
|
46
46
|
title: string;
|
|
47
47
|
detail: string;
|
|
@@ -65,7 +65,7 @@ export declare function checkAppStoreSubmission(appId: string, opts?: {
|
|
|
65
65
|
canSubmit: boolean;
|
|
66
66
|
blockingCodes: string[];
|
|
67
67
|
risks: {
|
|
68
|
-
level: "
|
|
68
|
+
level: "info" | "blocker" | "warning";
|
|
69
69
|
code: string;
|
|
70
70
|
title: string;
|
|
71
71
|
detail: string;
|
package/dist/checks/plan.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare function buildPlayStoreReleasePlan(opts: {
|
|
|
34
34
|
canSubmit: boolean;
|
|
35
35
|
blockingCodes: string[];
|
|
36
36
|
risks: {
|
|
37
|
-
level: "
|
|
37
|
+
level: "info" | "blocker" | "warning";
|
|
38
38
|
code: string;
|
|
39
39
|
title: string;
|
|
40
40
|
detail: string;
|
|
@@ -67,7 +67,7 @@ export declare function buildAppStoreReleasePlan(opts: {
|
|
|
67
67
|
canSubmit: boolean;
|
|
68
68
|
blockingCodes: string[];
|
|
69
69
|
risks: {
|
|
70
|
-
level: "
|
|
70
|
+
level: "info" | "blocker" | "warning";
|
|
71
71
|
code: string;
|
|
72
72
|
title: string;
|
|
73
73
|
detail: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
declare const submissionRiskSchema: z.ZodObject<{
|
|
3
3
|
level: z.ZodEnum<{
|
|
4
|
-
warning: "warning";
|
|
5
|
-
blocker: "blocker";
|
|
6
4
|
info: "info";
|
|
5
|
+
blocker: "blocker";
|
|
6
|
+
warning: "warning";
|
|
7
7
|
}>;
|
|
8
8
|
code: z.ZodString;
|
|
9
9
|
title: z.ZodString;
|
|
@@ -55,9 +55,9 @@ export declare const releaseReadinessShape: {
|
|
|
55
55
|
blockingCodes: z.ZodArray<z.ZodString>;
|
|
56
56
|
risks: z.ZodArray<z.ZodObject<{
|
|
57
57
|
level: z.ZodEnum<{
|
|
58
|
-
warning: "warning";
|
|
59
|
-
blocker: "blocker";
|
|
60
58
|
info: "info";
|
|
59
|
+
blocker: "blocker";
|
|
60
|
+
warning: "warning";
|
|
61
61
|
}>;
|
|
62
62
|
code: z.ZodString;
|
|
63
63
|
title: z.ZodString;
|
|
@@ -93,7 +93,7 @@ export declare function releaseReadinessResult(text: string, readiness: ReleaseR
|
|
|
93
93
|
canSubmit: boolean;
|
|
94
94
|
blockingCodes: string[];
|
|
95
95
|
risks: {
|
|
96
|
-
level: "
|
|
96
|
+
level: "info" | "blocker" | "warning";
|
|
97
97
|
code: string;
|
|
98
98
|
title: string;
|
|
99
99
|
detail: string;
|
package/dist/checks/risks.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export declare function checkPlayStoreRisks(auth: OAuth2Client, packageName: str
|
|
|
27
27
|
canSubmit: boolean;
|
|
28
28
|
blockingCodes: string[];
|
|
29
29
|
risks: {
|
|
30
|
-
level: "
|
|
30
|
+
level: "info" | "blocker" | "warning";
|
|
31
31
|
code: string;
|
|
32
32
|
title: string;
|
|
33
33
|
detail: string;
|
package/dist/ga4/cli.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// mimi-seed-ga4 — GA4 Analytics Admin/Data API sub-CLI.
|
|
3
3
|
// 사용자 진입점은 `mimi-seed ga4 <subcommand>` (cli 패키지가 npx 로 이 bin 을 호출).
|
|
4
|
+
import { GOOGLE_PROFILE_ID } from '../auth/google-auth.js';
|
|
4
5
|
import { requireAuth } from '../helpers.js';
|
|
5
6
|
import * as ga4 from './tools.js';
|
|
6
|
-
import { runDomainCli, requireFlag, flag, flagList } from '../lib/cli-args.js';
|
|
7
|
+
import { CliUsageError, runDomainCli, requireFlag, flag, flagList } from '../lib/cli-args.js';
|
|
7
8
|
const HELP = `
|
|
8
9
|
📊 mimi-seed-ga4 — GA4(Google Analytics 4) attach
|
|
9
10
|
|
|
@@ -27,40 +28,71 @@ const HELP = `
|
|
|
27
28
|
|
|
28
29
|
mimi-seed ga4 report --property <id> --start 28daysAgo --end today
|
|
29
30
|
[--dimensions date,country] [--metrics activeUsers,eventCount]
|
|
30
|
-
|
|
31
|
+
[--limit <1-${ga4.GA4_REPORT_MAX_LIMIT}>] [--offset <0부터 시작>]
|
|
32
|
+
GA4 Data API 리포트 (기본 10000행, rowCount 는 전체 행 수)
|
|
33
|
+
페이지 순회는 첫 요청부터 --limit 또는 --offset 0을 지정하세요.
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
모든 명령에서 --profile <id> 로 Google 로그인 프로필을 선택할 수 있습니다.
|
|
36
|
+
목록 조회는 analytics.readonly 또는 analytics.edit, 리포트는 analytics.readonly 또는 analytics,
|
|
37
|
+
생성은 analytics.edit 가 필요합니다. 권한이 없으면 아래 명령으로 로그인하세요.
|
|
38
|
+
mimi-seed auth login --domains ga4 [--profile <id>]
|
|
34
39
|
`;
|
|
40
|
+
function optionalValue(p, name) {
|
|
41
|
+
if (flag(p, name) !== undefined || p.bools.has(name))
|
|
42
|
+
return requireFlag(p, name);
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
function profileFlag(p) {
|
|
46
|
+
const profile = optionalValue(p, 'profile');
|
|
47
|
+
if (profile !== undefined && !GOOGLE_PROFILE_ID.test(profile)) {
|
|
48
|
+
throw new CliUsageError('--profile 은 소문자 또는 숫자로 시작하고 소문자, 숫자, _, - 로 이루어진 1~64자여야 합니다.');
|
|
49
|
+
}
|
|
50
|
+
return profile;
|
|
51
|
+
}
|
|
52
|
+
function integerFlag(p, name, min, max) {
|
|
53
|
+
const value = optionalValue(p, name);
|
|
54
|
+
if (value === undefined)
|
|
55
|
+
return undefined;
|
|
56
|
+
const number = Number(value);
|
|
57
|
+
if (!/^\d+$/.test(value) || number < min || number > max) {
|
|
58
|
+
throw new CliUsageError(`--${name} 는 ${min} 이상 ${max} 이하의 정수여야 합니다.`);
|
|
59
|
+
}
|
|
60
|
+
return number;
|
|
61
|
+
}
|
|
35
62
|
// runDomainCli 는 내부에서 모든 예외를 잡고 항상 process.exit 한다.
|
|
36
63
|
void runDomainCli({
|
|
37
64
|
binName: 'mimi-seed-ga4',
|
|
38
65
|
argv: process.argv.slice(2),
|
|
39
66
|
help: HELP,
|
|
40
67
|
handlers: {
|
|
41
|
-
accounts: async () => ga4.listAccountSummaries(await requireAuth(ga4.
|
|
42
|
-
properties: async (p) => ga4.listProperties(await requireAuth(ga4.
|
|
43
|
-
'create-property': async (p) => ga4.createProperty(await requireAuth(ga4.GA4_SCOPE), {
|
|
68
|
+
accounts: async (p) => ga4.listAccountSummaries(await requireAuth(ga4.GA4_ADMIN_READ_SCOPES, profileFlag(p))),
|
|
69
|
+
properties: async (p) => ga4.listProperties(await requireAuth(ga4.GA4_ADMIN_READ_SCOPES, profileFlag(p)), requireFlag(p, 'account')),
|
|
70
|
+
'create-property': async (p) => ga4.createProperty(await requireAuth(ga4.GA4_SCOPE, profileFlag(p)), {
|
|
44
71
|
accountId: requireFlag(p, 'account'),
|
|
45
72
|
displayName: requireFlag(p, 'name'),
|
|
46
73
|
timeZone: flag(p, 'timezone'),
|
|
47
74
|
currencyCode: flag(p, 'currency'),
|
|
48
75
|
}),
|
|
49
|
-
'create-stream': async (p) => ga4.createDataStream(await requireAuth(ga4.GA4_SCOPE), requireFlag(p, 'property'), {
|
|
76
|
+
'create-stream': async (p) => ga4.createDataStream(await requireAuth(ga4.GA4_SCOPE, profileFlag(p)), requireFlag(p, 'property'), {
|
|
50
77
|
platform: requireFlag(p, 'platform'),
|
|
51
78
|
displayName: requireFlag(p, 'name'),
|
|
52
79
|
defaultUri: flag(p, 'uri'),
|
|
53
80
|
packageName: flag(p, 'package'),
|
|
54
81
|
bundleId: flag(p, 'bundle'),
|
|
55
82
|
}),
|
|
56
|
-
streams: async (p) => ga4.listDataStreams(await requireAuth(ga4.
|
|
57
|
-
report: async (p) =>
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
83
|
+
streams: async (p) => ga4.listDataStreams(await requireAuth(ga4.GA4_ADMIN_READ_SCOPES, profileFlag(p)), requireFlag(p, 'property')),
|
|
84
|
+
report: async (p) => {
|
|
85
|
+
const propertyId = requireFlag(p, 'property');
|
|
86
|
+
const params = {
|
|
87
|
+
startDate: requireFlag(p, 'start'),
|
|
88
|
+
endDate: requireFlag(p, 'end'),
|
|
89
|
+
dimensions: flagList(p, 'dimensions'),
|
|
90
|
+
metrics: flagList(p, 'metrics'),
|
|
91
|
+
limit: integerFlag(p, 'limit', 1, ga4.GA4_REPORT_MAX_LIMIT),
|
|
92
|
+
offset: integerFlag(p, 'offset', 0, Number.MAX_SAFE_INTEGER),
|
|
93
|
+
};
|
|
94
|
+
const auth = await requireAuth(ga4.GA4_REPORT_SCOPES, profileFlag(p));
|
|
95
|
+
return ga4.runReport(auth, propertyId, params);
|
|
96
|
+
},
|
|
65
97
|
},
|
|
66
98
|
});
|
package/dist/ga4/tools.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { OAuth2Client } from 'google-auth-library';
|
|
2
|
-
/** Admin API
|
|
2
|
+
/** Admin API의 생성 호출이 요구하는 스코프. */
|
|
3
3
|
export declare const GA4_SCOPE = "https://www.googleapis.com/auth/analytics.edit";
|
|
4
4
|
/**
|
|
5
|
-
* Data API
|
|
5
|
+
* GA4 읽기 스코프. Data API는 이 스코프와 analytics를 허용한다.
|
|
6
6
|
*
|
|
7
7
|
* ⚠️ analytics.edit 은 **Admin API 전용**이라 Data API 가 받아주지 않는다. 둘을 같은
|
|
8
8
|
* 스코프로 묶으면 pre-flight 는 통과시켜 놓고 구글이 403 을 던져서, "API 가 꺼졌나"로
|
|
@@ -10,6 +10,9 @@ export declare const GA4_SCOPE = "https://www.googleapis.com/auth/analytics.edit
|
|
|
10
10
|
* (2026-07 실사고: 맑음 D1 지표를 뽑으려다 Analytics API 활성화 문제로 오인.)
|
|
11
11
|
*/
|
|
12
12
|
export declare const GA4_DATA_SCOPE = "https://www.googleapis.com/auth/analytics.readonly";
|
|
13
|
+
export declare const GA4_ADMIN_READ_SCOPES: readonly ["https://www.googleapis.com/auth/analytics.readonly", "https://www.googleapis.com/auth/analytics.edit"];
|
|
14
|
+
export declare const GA4_REPORT_SCOPES: readonly ["https://www.googleapis.com/auth/analytics.readonly", "https://www.googleapis.com/auth/analytics"];
|
|
15
|
+
export declare const GA4_REPORT_MAX_LIMIT = 250000;
|
|
13
16
|
export type Ga4Auth = OAuth2Client;
|
|
14
17
|
export type DataStreamPlatform = 'web' | 'android' | 'ios';
|
|
15
18
|
/** '123' | 'accounts/123' → 'accounts/123' */
|
|
@@ -227,5 +230,7 @@ export interface RunReportParams {
|
|
|
227
230
|
endDate: string;
|
|
228
231
|
dimensions?: string[];
|
|
229
232
|
metrics?: string[];
|
|
233
|
+
limit?: number;
|
|
234
|
+
offset?: number;
|
|
230
235
|
}
|
|
231
236
|
export declare function runReport(auth: Ga4Auth, propertyId: string, params: RunReportParams): Promise<import("@googleapis/analyticsdata").analyticsdata_v1beta.Schema$RunReportResponse>;
|
package/dist/ga4/tools.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { google } from '../lib/googleapis-lite.js';
|
|
2
|
+
import { collectPages } from '../lib/paginate.js';
|
|
2
3
|
import { resourceName } from '../lib/resource-id.js';
|
|
3
4
|
/**
|
|
4
5
|
* Google Analytics 4 — Admin API(v1beta) + Data API(v1beta) 래퍼.
|
|
@@ -7,16 +8,16 @@ import { resourceName } from '../lib/resource-id.js';
|
|
|
7
8
|
* enable 하면 GA4 property 가 자동 생성되지만, 그 경로는 property 이름/타임존/통화나
|
|
8
9
|
* web data stream(measurement ID, G-XXXX) 을 제어할 수 없다. 풀 컨트롤이 필요하면 이 모듈을 쓴다.
|
|
9
10
|
*
|
|
10
|
-
* 인증은 mimi-seed OAuth 클라이언트(`requireAuth()`)를
|
|
11
|
-
*
|
|
11
|
+
* 인증은 mimi-seed OAuth 클라이언트(`requireAuth()`)를 사용한다.
|
|
12
|
+
* Admin API 조회는 읽기 또는 수정 스코프, 생성은 수정 스코프가 필요하다.
|
|
12
13
|
*/
|
|
13
14
|
const admin = () => google.analyticsadmin('v1beta');
|
|
14
15
|
const adminAlpha = () => google.analyticsadmin('v1alpha');
|
|
15
16
|
const data = () => google.analyticsdata('v1beta');
|
|
16
|
-
/** Admin API
|
|
17
|
+
/** Admin API의 생성 호출이 요구하는 스코프. */
|
|
17
18
|
export const GA4_SCOPE = 'https://www.googleapis.com/auth/analytics.edit';
|
|
18
19
|
/**
|
|
19
|
-
* Data API
|
|
20
|
+
* GA4 읽기 스코프. Data API는 이 스코프와 analytics를 허용한다.
|
|
20
21
|
*
|
|
21
22
|
* ⚠️ analytics.edit 은 **Admin API 전용**이라 Data API 가 받아주지 않는다. 둘을 같은
|
|
22
23
|
* 스코프로 묶으면 pre-flight 는 통과시켜 놓고 구글이 403 을 던져서, "API 가 꺼졌나"로
|
|
@@ -24,6 +25,9 @@ export const GA4_SCOPE = 'https://www.googleapis.com/auth/analytics.edit';
|
|
|
24
25
|
* (2026-07 실사고: 맑음 D1 지표를 뽑으려다 Analytics API 활성화 문제로 오인.)
|
|
25
26
|
*/
|
|
26
27
|
export const GA4_DATA_SCOPE = 'https://www.googleapis.com/auth/analytics.readonly';
|
|
28
|
+
export const GA4_ADMIN_READ_SCOPES = [GA4_DATA_SCOPE, GA4_SCOPE];
|
|
29
|
+
export const GA4_REPORT_SCOPES = [GA4_DATA_SCOPE, 'https://www.googleapis.com/auth/analytics'];
|
|
30
|
+
export const GA4_REPORT_MAX_LIMIT = 250_000;
|
|
27
31
|
// ─── 경로 정규화 (순수 함수 — 테스트 대상) ───
|
|
28
32
|
/** '123' | 'accounts/123' → 'accounts/123' */
|
|
29
33
|
export function normalizeAccountName(accountId) {
|
|
@@ -100,17 +104,20 @@ export function flattenBigQueryLink(link) {
|
|
|
100
104
|
// ─── 계정/속성 디스커버리 ───
|
|
101
105
|
/** 접근 가능한 GA 계정 + 각 계정의 property 요약. accountId/propertyId 를 찾는 시작점. */
|
|
102
106
|
export async function listAccountSummaries(auth) {
|
|
103
|
-
const
|
|
104
|
-
return
|
|
107
|
+
const { accountSummaries } = admin();
|
|
108
|
+
return collectPages(async (pageToken) => {
|
|
109
|
+
const { data } = await accountSummaries.list({ auth, pageSize: 200, ...(pageToken && { pageToken }) });
|
|
110
|
+
return { items: data.accountSummaries ?? [], nextPageToken: data.nextPageToken };
|
|
111
|
+
});
|
|
105
112
|
}
|
|
106
113
|
/** 계정 하위 GA4 property 목록. accountId: '123' 또는 'accounts/123'. */
|
|
107
114
|
export async function listProperties(auth, accountId) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
pageSize: 200,
|
|
115
|
+
const filter = `parent:${normalizeAccountName(accountId)}`;
|
|
116
|
+
const { properties } = admin();
|
|
117
|
+
return collectPages(async (pageToken) => {
|
|
118
|
+
const { data } = await properties.list({ auth, filter, pageSize: 200, ...(pageToken && { pageToken }) });
|
|
119
|
+
return { items: data.properties ?? [], nextPageToken: data.nextPageToken };
|
|
112
120
|
});
|
|
113
|
-
return res.data.properties ?? [];
|
|
114
121
|
}
|
|
115
122
|
// ─── property / data stream 생성 (attach 핵심) ───
|
|
116
123
|
export async function createProperty(auth, opts) {
|
|
@@ -134,22 +141,24 @@ export async function createDataStream(auth, propertyId, opts) {
|
|
|
134
141
|
return { ...flattenDataStream(res.data), raw: res.data };
|
|
135
142
|
}
|
|
136
143
|
export async function listDataStreams(auth, propertyId) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
pageSize: 200,
|
|
144
|
+
const parent = normalizePropertyName(propertyId);
|
|
145
|
+
const { dataStreams } = admin().properties;
|
|
146
|
+
const streams = await collectPages(async (pageToken) => {
|
|
147
|
+
const { data } = await dataStreams.list({ auth, parent, pageSize: 200, ...(pageToken && { pageToken }) });
|
|
148
|
+
return { items: data.dataStreams ?? [], nextPageToken: data.nextPageToken };
|
|
141
149
|
});
|
|
142
|
-
return
|
|
150
|
+
return streams.map(flattenDataStream);
|
|
143
151
|
}
|
|
144
152
|
// ─── BigQuery export 링크 ───
|
|
145
153
|
/** GA4 property 에 연결된 BigQuery export 링크 목록. */
|
|
146
154
|
export async function listBigQueryLinks(auth, propertyId) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
pageSize: 200,
|
|
155
|
+
const parent = normalizePropertyName(propertyId);
|
|
156
|
+
const { bigQueryLinks } = adminAlpha().properties;
|
|
157
|
+
const links = await collectPages(async (pageToken) => {
|
|
158
|
+
const { data } = await bigQueryLinks.list({ auth, parent, pageSize: 200, ...(pageToken && { pageToken }) });
|
|
159
|
+
return { items: data.bigqueryLinks ?? [], nextPageToken: data.nextPageToken };
|
|
151
160
|
});
|
|
152
|
-
return
|
|
161
|
+
return links.map(flattenBigQueryLink);
|
|
153
162
|
}
|
|
154
163
|
/**
|
|
155
164
|
* 생성 전 계획. GA4 property 는 BigQuery 링크가 이미 있으면 중복 생성을 시도하지 않는다.
|
|
@@ -185,13 +194,21 @@ export async function createBigQueryLink(auth, propertyId, opts) {
|
|
|
185
194
|
};
|
|
186
195
|
}
|
|
187
196
|
export async function runReport(auth, propertyId, params) {
|
|
197
|
+
const dimensions = (params.dimensions ?? []).map((name) => ({ name }));
|
|
198
|
+
const paged = params.limit !== undefined || params.offset !== undefined;
|
|
188
199
|
const res = await data().properties.runReport({
|
|
189
200
|
auth,
|
|
190
201
|
property: normalizePropertyName(propertyId),
|
|
191
202
|
requestBody: {
|
|
192
203
|
dateRanges: [{ startDate: params.startDate, endDate: params.endDate }],
|
|
193
|
-
dimensions
|
|
204
|
+
dimensions,
|
|
194
205
|
metrics: (params.metrics ?? ['activeUsers', 'eventCount']).map((name) => ({ name })),
|
|
206
|
+
// 모든 분류 기준으로 정렬해 페이지 경계에서 순서가 같은 행을 없앤다.
|
|
207
|
+
orderBys: paged && dimensions.length > 0
|
|
208
|
+
? dimensions.map(({ name }) => ({ dimension: { dimensionName: name, orderType: 'ALPHANUMERIC' } }))
|
|
209
|
+
: undefined,
|
|
210
|
+
limit: params.limit?.toString(),
|
|
211
|
+
offset: params.offset?.toString(),
|
|
195
212
|
},
|
|
196
213
|
});
|
|
197
214
|
return res.data;
|