adport 0.8.0 → 0.10.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/dist/analytics-HSICLNTZ.js +56 -0
- package/dist/analytics-HSICLNTZ.js.map +1 -0
- package/dist/{chunk-PFXNOLYI.js → chunk-JSWZBPDJ.js} +12 -7
- package/dist/chunk-JSWZBPDJ.js.map +1 -0
- package/dist/{google-ULSSOSIA.js → google-YGSPHPHA.js} +23 -11
- package/dist/google-YGSPHPHA.js.map +1 -0
- package/dist/gtm-LUOYKU3F.js +58 -0
- package/dist/gtm-LUOYKU3F.js.map +1 -0
- package/dist/index.js +118 -30
- package/dist/index.js.map +1 -1
- package/dist/{microsoft-IXYBD4GY.js → microsoft-H7NMN7NX.js} +2 -2
- package/dist/openai-NQMATWUO.js +24 -0
- package/dist/openai-NQMATWUO.js.map +1 -0
- package/dist/{pinterest-EHR7Q4UM.js → pinterest-OZBETZSI.js} +7 -5
- package/dist/pinterest-OZBETZSI.js.map +1 -0
- package/dist/{reddit-OUGHWGWV.js → reddit-JNFXOIFY.js} +14 -6
- package/dist/reddit-JNFXOIFY.js.map +1 -0
- package/dist/{snapchat-MCEUPY2Y.js → snapchat-FRJTXF3Y.js} +2 -2
- package/dist/{spotify-WXJ6Y2ZG.js → spotify-KH4EXFM6.js} +2 -2
- package/package.json +21 -18
- package/dist/chunk-PFXNOLYI.js.map +0 -1
- package/dist/google-ULSSOSIA.js.map +0 -1
- package/dist/pinterest-EHR7Q4UM.js.map +0 -1
- package/dist/reddit-OUGHWGWV.js.map +0 -1
- /package/dist/{microsoft-IXYBD4GY.js.map → microsoft-H7NMN7NX.js.map} +0 -0
- /package/dist/{snapchat-MCEUPY2Y.js.map → snapchat-FRJTXF3Y.js.map} +0 -0
- /package/dist/{spotify-WXJ6Y2ZG.js.map → spotify-KH4EXFM6.js.map} +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildGoogleAuthUrl,
|
|
3
|
+
exchangeCodeForTokens,
|
|
4
|
+
generateOAuthState,
|
|
5
|
+
generatePkce,
|
|
6
|
+
openInBrowser,
|
|
7
|
+
startLoopbackServer
|
|
8
|
+
} from "./chunk-JSWZBPDJ.js";
|
|
9
|
+
import {
|
|
10
|
+
printLocalConnectionIntro,
|
|
11
|
+
printLocalConnectionSaved
|
|
12
|
+
} from "./chunk-OPRADP2V.js";
|
|
13
|
+
|
|
14
|
+
// src/connect/analytics.ts
|
|
15
|
+
import readline from "readline/promises";
|
|
16
|
+
import { AdportError, CredentialStore, GA4_SCOPES, GSC_SCOPES } from "@adport/core";
|
|
17
|
+
import { AnalyticsClient, Ga4Provider, SearchConsoleProvider } from "@adport/provider-analytics";
|
|
18
|
+
async function connectAnalytics(provider, input) {
|
|
19
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout }), store = new CredentialStore();
|
|
20
|
+
const title = provider === "ga4" ? "Google Analytics 4" : "Google Search Console", prefix = provider.toUpperCase();
|
|
21
|
+
try {
|
|
22
|
+
printLocalConnectionIntro(input.io, title);
|
|
23
|
+
input.io.out(provider === "ga4" ? "Enable Google Analytics Data API and Google Analytics Admin API in your Google project." : "Enable Google Search Console API in your Google project.");
|
|
24
|
+
input.io.out("Use an OAuth Desktop app client. This connection requests read-only access.");
|
|
25
|
+
const existing = (await store.get(provider))?.data;
|
|
26
|
+
const clientId = (await rl.question("OAuth client ID (Enter to reuse stored/environment): ")).trim() || existing?.client_id || process.env[`${prefix}_CLIENT_ID`] || "";
|
|
27
|
+
const clientSecret = (clientId === existing?.client_id ? existing.client_secret : void 0) || process.env[`${prefix}_CLIENT_SECRET`] || "";
|
|
28
|
+
if (!clientId || !clientSecret) throw new AdportError("INVALID_INPUT", `Set ${prefix}_CLIENT_SECRET securely in your terminal and provide the OAuth client ID.`);
|
|
29
|
+
const pkce = generatePkce(), state = generateOAuthState(), loopback = await startLoopbackServer("127.0.0.1", state);
|
|
30
|
+
let timeout, refreshToken;
|
|
31
|
+
try {
|
|
32
|
+
const url = buildGoogleAuthUrl(clientId, loopback.redirectUri, pkce.challenge, state, false, provider === "ga4" ? GA4_SCOPES : GSC_SCOPES);
|
|
33
|
+
input.io.out(`Authorize ${title}:
|
|
34
|
+
${url}`);
|
|
35
|
+
if (input.openBrowser) openInBrowser(url);
|
|
36
|
+
const code = await Promise.race([loopback.waitForCode, new Promise((_resolve, reject) => {
|
|
37
|
+
timeout = setTimeout(() => reject(new Error("Analytics authorization timed out after five minutes.")), 3e5);
|
|
38
|
+
})]);
|
|
39
|
+
({ refreshToken } = await exchangeCodeForTokens({ clientId, clientSecret, code, redirectUri: loopback.redirectUri, codeVerifier: pkce.verifier }));
|
|
40
|
+
} finally {
|
|
41
|
+
clearTimeout(timeout);
|
|
42
|
+
loopback.close();
|
|
43
|
+
}
|
|
44
|
+
const client = new AnalyticsClient({ clientId, clientSecret, refreshToken });
|
|
45
|
+
const accounts = await (provider === "ga4" ? new Ga4Provider(client) : new SearchConsoleProvider(client)).listAccounts();
|
|
46
|
+
await store.set({ provider, source: "byo", data: { client_id: clientId, client_secret: clientSecret, refresh_token: refreshToken } });
|
|
47
|
+
input.io.out(`Connected: ${accounts.length} accessible ${title} properties.`);
|
|
48
|
+
printLocalConnectionSaved(input.io);
|
|
49
|
+
} finally {
|
|
50
|
+
rl.close();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
connectAnalytics
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=analytics-HSICLNTZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/connect/analytics.ts"],"sourcesContent":["import readline from 'node:readline/promises';\nimport { AdportError, CredentialStore, GA4_SCOPES, GSC_SCOPES } from '@adport/core';\nimport { AnalyticsClient, Ga4Provider, SearchConsoleProvider } from '@adport/provider-analytics';\nimport type { ProgramIO } from '../program.js';\nimport { printLocalConnectionIntro, printLocalConnectionSaved } from './local.js';\nimport { buildGoogleAuthUrl, exchangeCodeForTokens, generateOAuthState, generatePkce, openInBrowser, startLoopbackServer } from './oauth.js';\n\nexport async function connectAnalytics(provider: 'ga4' | 'gsc', input: { openBrowser: boolean; io: ProgramIO }): Promise<void> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout }), store = new CredentialStore();\n const title = provider === 'ga4' ? 'Google Analytics 4' : 'Google Search Console', prefix = provider.toUpperCase();\n try {\n printLocalConnectionIntro(input.io, title);\n input.io.out(provider === 'ga4' ? 'Enable Google Analytics Data API and Google Analytics Admin API in your Google project.' : 'Enable Google Search Console API in your Google project.');\n input.io.out('Use an OAuth Desktop app client. This connection requests read-only access.');\n const existing = (await store.get(provider))?.data;\n const clientId = (await rl.question('OAuth client ID (Enter to reuse stored/environment): ')).trim() || existing?.client_id || process.env[`${prefix}_CLIENT_ID`] || '';\n const clientSecret = (clientId === existing?.client_id ? existing.client_secret : undefined) || process.env[`${prefix}_CLIENT_SECRET`] || '';\n if (!clientId || !clientSecret) throw new AdportError('INVALID_INPUT', `Set ${prefix}_CLIENT_SECRET securely in your terminal and provide the OAuth client ID.`);\n const pkce = generatePkce(), state = generateOAuthState(), loopback = await startLoopbackServer('127.0.0.1', state);\n let timeout: ReturnType<typeof setTimeout> | undefined, refreshToken: string;\n try {\n const url = buildGoogleAuthUrl(clientId, loopback.redirectUri, pkce.challenge, state, false, provider === 'ga4' ? GA4_SCOPES : GSC_SCOPES);\n input.io.out(`Authorize ${title}:\\n ${url}`); if (input.openBrowser) openInBrowser(url);\n const code = await Promise.race([loopback.waitForCode, new Promise<never>((_resolve, reject) => {\n timeout = setTimeout(() => reject(new Error('Analytics authorization timed out after five minutes.')), 300_000);\n })]);\n ({ refreshToken } = await exchangeCodeForTokens({ clientId, clientSecret, code, redirectUri: loopback.redirectUri, codeVerifier: pkce.verifier }));\n } finally { clearTimeout(timeout); loopback.close(); }\n const client = new AnalyticsClient({ clientId, clientSecret, refreshToken });\n const accounts = await (provider === 'ga4' ? new Ga4Provider(client) : new SearchConsoleProvider(client)).listAccounts();\n await store.set({ provider, source: 'byo', data: { client_id: clientId, client_secret: clientSecret, refresh_token: refreshToken } });\n input.io.out(`Connected: ${accounts.length} accessible ${title} properties.`); printLocalConnectionSaved(input.io);\n } finally { rl.close(); }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,OAAO,cAAc;AACrB,SAAS,aAAa,iBAAiB,YAAY,kBAAkB;AACrE,SAAS,iBAAiB,aAAa,6BAA6B;AAKpE,eAAsB,iBAAiB,UAAyB,OAA+D;AAC7H,QAAM,KAAK,SAAS,gBAAgB,EAAE,OAAO,QAAQ,OAAO,QAAQ,QAAQ,OAAO,CAAC,GAAG,QAAQ,IAAI,gBAAgB;AACnH,QAAM,QAAQ,aAAa,QAAQ,uBAAuB,yBAAyB,SAAS,SAAS,YAAY;AACjH,MAAI;AACF,8BAA0B,MAAM,IAAI,KAAK;AACzC,UAAM,GAAG,IAAI,aAAa,QAAQ,4FAA4F,0DAA0D;AACxL,UAAM,GAAG,IAAI,6EAA6E;AAC1F,UAAM,YAAY,MAAM,MAAM,IAAI,QAAQ,IAAI;AAC9C,UAAM,YAAY,MAAM,GAAG,SAAS,uDAAuD,GAAG,KAAK,KAAK,UAAU,aAAa,QAAQ,IAAI,GAAG,MAAM,YAAY,KAAK;AACrK,UAAM,gBAAgB,aAAa,UAAU,YAAY,SAAS,gBAAgB,WAAc,QAAQ,IAAI,GAAG,MAAM,gBAAgB,KAAK;AAC1I,QAAI,CAAC,YAAY,CAAC,aAAc,OAAM,IAAI,YAAY,iBAAiB,OAAO,MAAM,2EAA2E;AAC/J,UAAM,OAAO,aAAa,GAAG,QAAQ,mBAAmB,GAAG,WAAW,MAAM,oBAAoB,aAAa,KAAK;AAClH,QAAI,SAAoD;AACxD,QAAI;AACF,YAAM,MAAM,mBAAmB,UAAU,SAAS,aAAa,KAAK,WAAW,OAAO,OAAO,aAAa,QAAQ,aAAa,UAAU;AACzI,YAAM,GAAG,IAAI,aAAa,KAAK;AAAA,IAAQ,GAAG,EAAE;AAAG,UAAI,MAAM,YAAa,eAAc,GAAG;AACvF,YAAM,OAAO,MAAM,QAAQ,KAAK,CAAC,SAAS,aAAa,IAAI,QAAe,CAAC,UAAU,WAAW;AAC9F,kBAAU,WAAW,MAAM,OAAO,IAAI,MAAM,uDAAuD,CAAC,GAAG,GAAO;AAAA,MAChH,CAAC,CAAC,CAAC;AACH,OAAC,EAAE,aAAa,IAAI,MAAM,sBAAsB,EAAE,UAAU,cAAc,MAAM,aAAa,SAAS,aAAa,cAAc,KAAK,SAAS,CAAC;AAAA,IAClJ,UAAE;AAAU,mBAAa,OAAO;AAAG,eAAS,MAAM;AAAA,IAAG;AACrD,UAAM,SAAS,IAAI,gBAAgB,EAAE,UAAU,cAAc,aAAa,CAAC;AAC3E,UAAM,WAAW,OAAO,aAAa,QAAQ,IAAI,YAAY,MAAM,IAAI,IAAI,sBAAsB,MAAM,GAAG,aAAa;AACvH,UAAM,MAAM,IAAI,EAAE,UAAU,QAAQ,OAAO,MAAM,EAAE,WAAW,UAAU,eAAe,cAAc,eAAe,aAAa,EAAE,CAAC;AACpI,UAAM,GAAG,IAAI,cAAc,SAAS,MAAM,eAAe,KAAK,cAAc;AAAG,8BAA0B,MAAM,EAAE;AAAA,EACnH,UAAE;AAAU,OAAG,MAAM;AAAA,EAAG;AAC1B;","names":[]}
|
|
@@ -3,17 +3,19 @@ import { createHash, randomBytes } from "crypto";
|
|
|
3
3
|
import http from "http";
|
|
4
4
|
import { spawn } from "child_process";
|
|
5
5
|
import { AdportError } from "@adport/core";
|
|
6
|
+
import { GOOGLE_DATA_MANAGER_SCOPE } from "@adport/provider-google";
|
|
6
7
|
var GOOGLE_ADS_SCOPE = "https://www.googleapis.com/auth/adwords";
|
|
7
8
|
var AUTH_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
8
9
|
var TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
|
|
9
|
-
function buildGoogleAuthUrl(clientId, redirectUri, codeChallenge, state) {
|
|
10
|
+
function buildGoogleAuthUrl(clientId, redirectUri, codeChallenge, state, dataManager = false, scopes) {
|
|
10
11
|
const params = new URLSearchParams({
|
|
11
12
|
client_id: clientId,
|
|
12
13
|
redirect_uri: redirectUri,
|
|
13
14
|
response_type: "code",
|
|
14
|
-
scope: GOOGLE_ADS_SCOPE,
|
|
15
|
+
scope: (scopes ?? [GOOGLE_ADS_SCOPE, ...dataManager ? [GOOGLE_DATA_MANAGER_SCOPE] : []]).join(" "),
|
|
15
16
|
access_type: "offline",
|
|
16
17
|
prompt: "consent",
|
|
18
|
+
include_granted_scopes: "false",
|
|
17
19
|
code_challenge: codeChallenge,
|
|
18
20
|
code_challenge_method: "S256",
|
|
19
21
|
state
|
|
@@ -94,14 +96,15 @@ async function startLoopbackServer(redirectHostname = "127.0.0.1", expectedState
|
|
|
94
96
|
var REDDIT_AUTHORIZE = "https://www.reddit.com/api/v1/authorize";
|
|
95
97
|
var REDDIT_TOKEN = "https://www.reddit.com/api/v1/access_token";
|
|
96
98
|
var REDDIT_ADS_SCOPES = "adsread,adsedit,adsdatadeletion";
|
|
97
|
-
|
|
99
|
+
var REDDIT_CONVERSIONS_SCOPE = "adsconversions";
|
|
100
|
+
function buildRedditAuthUrl(clientId, redirectUri, state, conversions = false) {
|
|
98
101
|
const params = new URLSearchParams({
|
|
99
102
|
client_id: clientId,
|
|
100
103
|
response_type: "code",
|
|
101
104
|
state,
|
|
102
105
|
redirect_uri: redirectUri,
|
|
103
106
|
duration: "permanent",
|
|
104
|
-
scope: REDDIT_ADS_SCOPES
|
|
107
|
+
scope: conversions ? `${REDDIT_ADS_SCOPES},${REDDIT_CONVERSIONS_SCOPE}` : REDDIT_ADS_SCOPES
|
|
105
108
|
});
|
|
106
109
|
return `${REDDIT_AUTHORIZE}?${params}`;
|
|
107
110
|
}
|
|
@@ -123,10 +126,12 @@ async function exchangeRedditCode(input, fetchImpl = fetch) {
|
|
|
123
126
|
if (!response.ok || !data.refresh_token) {
|
|
124
127
|
throw new AdportError(
|
|
125
128
|
"PROVIDER_ERROR",
|
|
126
|
-
`Reddit OAuth exchange failed
|
|
127
|
-
data
|
|
129
|
+
`Reddit OAuth exchange failed (HTTP ${response.status}): no usable refresh token. The previous connection was kept.`
|
|
128
130
|
);
|
|
129
131
|
}
|
|
132
|
+
if (input.conversions && !String(data.scope ?? "").split(/[\s,]+/).includes(REDDIT_CONVERSIONS_SCOPE)) {
|
|
133
|
+
throw new AdportError("PROVIDER_ERROR", "Reddit did not grant adsconversions. Check that your Reddit app may request it; the previous connection was kept.");
|
|
134
|
+
}
|
|
130
135
|
return { refreshToken: data.refresh_token };
|
|
131
136
|
}
|
|
132
137
|
var MS_AUTHORIZE = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
|
|
@@ -203,4 +208,4 @@ export {
|
|
|
203
208
|
exchangeMicrosoftCode,
|
|
204
209
|
openInBrowser
|
|
205
210
|
};
|
|
206
|
-
//# sourceMappingURL=chunk-
|
|
211
|
+
//# sourceMappingURL=chunk-JSWZBPDJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/connect/oauth.ts"],"sourcesContent":["import { createHash, randomBytes } from 'node:crypto';\nimport http from 'node:http';\nimport { spawn } from 'node:child_process';\nimport { AdportError } from '@adport/core';\nimport { GOOGLE_DATA_MANAGER_SCOPE } from '@adport/provider-google';\n\nexport const GOOGLE_ADS_SCOPE = 'https://www.googleapis.com/auth/adwords';\nconst AUTH_ENDPOINT = 'https://accounts.google.com/o/oauth2/v2/auth';\nconst TOKEN_ENDPOINT = 'https://oauth2.googleapis.com/token';\n\nexport function buildGoogleAuthUrl(\n clientId: string,\n redirectUri: string,\n codeChallenge: string,\n state: string,\n dataManager = false,\n scopes?: readonly string[],\n): string {\n const params = new URLSearchParams({\n client_id: clientId,\n redirect_uri: redirectUri,\n response_type: 'code',\n scope: (scopes ?? [GOOGLE_ADS_SCOPE, ...(dataManager ? [GOOGLE_DATA_MANAGER_SCOPE] : [])]).join(' '),\n access_type: 'offline',\n prompt: 'consent',\n include_granted_scopes: 'false',\n code_challenge: codeChallenge,\n code_challenge_method: 'S256',\n state,\n });\n return `${AUTH_ENDPOINT}?${params}`;\n}\n\nexport async function exchangeCodeForTokens(\n input: { clientId: string; clientSecret: string; code: string; redirectUri: string; codeVerifier: string },\n fetchImpl: typeof fetch = fetch,\n): Promise<{ refreshToken: string; accessToken: string }> {\n const response = await fetchImpl(TOKEN_ENDPOINT, {\n method: 'POST',\n headers: { 'content-type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n client_id: input.clientId,\n client_secret: input.clientSecret,\n code: input.code,\n redirect_uri: input.redirectUri,\n grant_type: 'authorization_code',\n code_verifier: input.codeVerifier,\n }),\n });\n const data = (await response.json()) as { refresh_token?: string; access_token?: string; error?: string };\n if (!response.ok || !data.refresh_token || !data.access_token) {\n throw new AdportError(\n 'PROVIDER_ERROR',\n `OAuth code exchange failed${data.error ? ` (${data.error})` : ''}. ` +\n 'If no refresh_token was returned, revoke the app at myaccount.google.com/permissions and retry.',\n data,\n );\n }\n return { refreshToken: data.refresh_token, accessToken: data.access_token };\n}\n\n/** Parse a downloaded OAuth client JSON (client_secret_*.json, \"installed\" or \"web\"). */\nexport function parseClientSecretJson(text: string): { clientId: string; clientSecret: string } {\n const parsed = JSON.parse(text) as {\n installed?: { client_id: string; client_secret: string };\n web?: { client_id: string; client_secret: string };\n };\n const entry = parsed.installed ?? parsed.web;\n if (!entry?.client_id || !entry?.client_secret) {\n throw new AdportError('INVALID_INPUT', 'Not a valid OAuth client JSON (expected \"installed\" or \"web\" key).');\n }\n return { clientId: entry.client_id, clientSecret: entry.client_secret };\n}\n\nexport interface LoopbackServer {\n redirectUri: string;\n /** Resolves with the authorization code once Google redirects back. */\n waitForCode: Promise<string>;\n close: () => void;\n}\n\n/** Loopback listener for the OAuth redirect — the desktop-app flow's return path. */\nexport async function startLoopbackServer(\n redirectHostname: '127.0.0.1' | 'localhost' = '127.0.0.1',\n expectedState?: string,\n port = 0,\n callbackPath = '',\n): Promise<LoopbackServer> {\n let resolveCode!: (code: string) => void;\n let rejectCode!: (err: Error) => void;\n const waitForCode = new Promise<string>((resolve, reject) => {\n resolveCode = resolve;\n rejectCode = reject;\n });\n\n const server = http.createServer((req, res) => {\n const url = new URL(req.url ?? '/', 'http://127.0.0.1');\n const code = url.searchParams.get('code');\n const error = url.searchParams.get('error');\n const state = url.searchParams.get('state');\n if (expectedState && state !== expectedState) {\n res.writeHead(400, { 'content-type': 'text/html; charset=utf-8' });\n res.end('<h2>Authorization failed</h2><p>OAuth state validation failed. Return to the terminal and retry.</p>');\n rejectCode(new AdportError('PROVIDER_ERROR', 'OAuth state validation failed. Retry the connection.'));\n return;\n }\n res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });\n res.end(\n code\n ? '<h2>adport is connected.</h2><p>You can close this tab and return to the terminal.</p>'\n : `<h2>Authorization failed${error ? `: ${escapeHtml(error)}` : ''}</h2><p>Return to the terminal and retry.</p>`,\n );\n if (code) resolveCode(code);\n else if (error) rejectCode(new Error(`OAuth authorization failed: ${error}`));\n });\n\n await new Promise<void>((resolve, reject) => {\n server.once('error', reject);\n server.listen(port, '127.0.0.1', () => {\n server.off('error', reject);\n resolve();\n });\n });\n const address = server.address();\n if (!address || typeof address === 'string') throw new Error('Loopback server failed to bind');\n return {\n redirectUri: `http://${redirectHostname}:${address.port}${callbackPath}`,\n waitForCode,\n close: () => server.close(),\n };\n}\n\n// ---- Reddit Ads API (confidential web app + permanent refresh token) -------\n\nconst REDDIT_AUTHORIZE = 'https://www.reddit.com/api/v1/authorize';\nconst REDDIT_TOKEN = 'https://www.reddit.com/api/v1/access_token';\nexport const REDDIT_ADS_SCOPES = 'adsread,adsedit,adsdatadeletion';\nexport const REDDIT_CONVERSIONS_SCOPE = 'adsconversions';\n\nexport function buildRedditAuthUrl(clientId: string, redirectUri: string, state: string, conversions = false): string {\n const params = new URLSearchParams({\n client_id: clientId,\n response_type: 'code',\n state,\n redirect_uri: redirectUri,\n duration: 'permanent',\n scope: conversions ? `${REDDIT_ADS_SCOPES},${REDDIT_CONVERSIONS_SCOPE}` : REDDIT_ADS_SCOPES,\n });\n return `${REDDIT_AUTHORIZE}?${params}`;\n}\n\nexport async function exchangeRedditCode(\n input: { clientId: string; clientSecret: string; code: string; redirectUri: string; userAgent: string; conversions?: boolean },\n fetchImpl: typeof fetch = fetch,\n): Promise<{ refreshToken: string }> {\n const response = await fetchImpl(REDDIT_TOKEN, {\n method: 'POST',\n headers: {\n authorization: `Basic ${Buffer.from(`${input.clientId}:${input.clientSecret}`).toString('base64')}`,\n 'content-type': 'application/x-www-form-urlencoded',\n 'user-agent': input.userAgent,\n },\n body: new URLSearchParams({\n grant_type: 'authorization_code',\n code: input.code.replace(/#_$/, ''),\n redirect_uri: input.redirectUri,\n }),\n });\n const data = (await response.json()) as { refresh_token?: string; error?: string; message?: string; scope?: string };\n if (!response.ok || !data.refresh_token) {\n throw new AdportError(\n 'PROVIDER_ERROR',\n `Reddit OAuth exchange failed (HTTP ${response.status}): no usable refresh token. The previous connection was kept.`,\n );\n }\n if (input.conversions && !String(data.scope ?? '').split(/[\\s,]+/).includes(REDDIT_CONVERSIONS_SCOPE)) {\n throw new AdportError('PROVIDER_ERROR', 'Reddit did not grant adsconversions. Check that your Reddit app may request it; the previous connection was kept.');\n }\n return { refreshToken: data.refresh_token };\n}\n\n// ---- Microsoft identity platform (public client + PKCE) ---------------------\n\nconst MS_AUTHORIZE = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize';\nconst MS_TOKEN = 'https://login.microsoftonline.com/common/oauth2/v2.0/token';\nexport const MS_ADS_SCOPE = 'openid profile https://ads.microsoft.com/msads.manage offline_access';\n\nexport function generatePkce(): { verifier: string; challenge: string } {\n const verifier = randomBytes(32).toString('base64url');\n const challenge = createHash('sha256').update(verifier).digest('base64url');\n return { verifier, challenge };\n}\n\nexport function generateOAuthState(): string {\n return randomBytes(32).toString('base64url');\n}\n\nexport function buildMicrosoftAuthUrl(clientId: string, redirectUri: string, challenge: string, state: string): string {\n const params = new URLSearchParams({\n client_id: clientId,\n response_type: 'code',\n redirect_uri: redirectUri,\n scope: MS_ADS_SCOPE,\n code_challenge: challenge,\n code_challenge_method: 'S256',\n prompt: 'login',\n state,\n });\n return `${MS_AUTHORIZE}?${params}`;\n}\n\nexport async function exchangeMicrosoftCode(\n input: { clientId: string; code: string; redirectUri: string; codeVerifier: string },\n fetchImpl: typeof fetch = fetch,\n): Promise<{ refreshToken: string }> {\n const response = await fetchImpl(MS_TOKEN, {\n method: 'POST',\n headers: { 'content-type': 'application/x-www-form-urlencoded' },\n body: new URLSearchParams({\n client_id: input.clientId,\n scope: 'https://ads.microsoft.com/msads.manage offline_access',\n code: input.code,\n redirect_uri: input.redirectUri,\n grant_type: 'authorization_code',\n code_verifier: input.codeVerifier,\n }),\n });\n const data = (await response.json()) as { refresh_token?: string; error?: string; error_description?: string };\n if (!response.ok || !data.refresh_token) {\n throw new AdportError(\n 'PROVIDER_ERROR',\n `Microsoft OAuth exchange failed${data.error ? ` (${data.error})` : ''}: ${data.error_description ?? ''}`,\n data,\n );\n }\n return { refreshToken: data.refresh_token };\n}\n\nexport function openInBrowser(url: string): void {\n const [cmd, args] =\n process.platform === 'darwin'\n ? ['open', [url]]\n : process.platform === 'win32'\n ? ['cmd', ['/c', 'start', '', url]]\n : ['xdg-open', [url]];\n spawn(cmd as string, args as string[], { detached: true, stdio: 'ignore' }).unref();\n}\n\nfunction escapeHtml(value: string): string {\n return value.replace(/[&<>\"']/g, (char) => ({\n '&': '&',\n '<': '<',\n '>': '>',\n '\"': '"',\n \"'\": ''',\n })[char]!);\n}\n"],"mappings":";AAAA,SAAS,YAAY,mBAAmB;AACxC,OAAO,UAAU;AACjB,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAC5B,SAAS,iCAAiC;AAEnC,IAAM,mBAAmB;AAChC,IAAM,gBAAgB;AACtB,IAAM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AK,cAAc;AAC5C;AAEO,SAAS,cAAc,KAAmB;AAC/C,QAAM,CAAC,KAAK,IAAI,IACd,QAAQ,aAAa,WACjB,CAAC,QAAQ,CAAC,GAAG,CAAC,IACd,QAAQ,aAAa,UACnB,CAAC,OAAO,CAAC,MAAM,SAAS,IAAI,GAAG,CAAC,IAChC,CAAC,YAAY,CAAC,GAAG,CAAC;AAC1B,QAAM,KAAe,MAAkB,EAAE,UAAU,MAAM,OAAO,SAAS,CAAC,EAAE,MAAM;AACpF;AAEA,SAAS,WAAW,OAAuB;AACzC,SAAO,MAAM,QAAQ,YAAY,CAAC,UAAU;AAAA,IAC1C,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,EACP,GAAG,IAAI,CAAE;AACX;","names":[]}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
openInBrowser,
|
|
7
7
|
parseClientSecretJson,
|
|
8
8
|
startLoopbackServer
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JSWZBPDJ.js";
|
|
10
10
|
import {
|
|
11
11
|
printLocalConnectionIntro,
|
|
12
12
|
printLocalConnectionSaved
|
|
@@ -20,11 +20,15 @@ import readline from "readline/promises";
|
|
|
20
20
|
import YAML from "yaml";
|
|
21
21
|
import { CredentialStore } from "@adport/core";
|
|
22
22
|
import { GoogleAdsRestClient } from "@adport/provider-google";
|
|
23
|
-
async function connectGoogle({ openBrowser, io }) {
|
|
23
|
+
async function connectGoogle({ openBrowser, dataManager = false, io }) {
|
|
24
24
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
25
25
|
const store = new CredentialStore();
|
|
26
26
|
try {
|
|
27
27
|
printLocalConnectionIntro(io, "Google Ads");
|
|
28
|
+
if (dataManager) {
|
|
29
|
+
io.out("Data Manager is explicitly requested: OAuth will also request the datamanager scope for conversion ingestion.");
|
|
30
|
+
io.out("Enable Data Manager API in the same Google Cloud project first. Existing grants are unchanged until you approve consent.");
|
|
31
|
+
}
|
|
28
32
|
io.out('Google may show "Google has not verified this app" for a private/unverified');
|
|
29
33
|
io.out("OAuth project. The developer shown will be your project contact. That warning");
|
|
30
34
|
io.out("is expected for BYO personal use; a verified Adport screen is Cloud-only.");
|
|
@@ -39,7 +43,8 @@ async function connectGoogle({ openBrowser, io }) {
|
|
|
39
43
|
existing.data.client_id,
|
|
40
44
|
existing.data.client_secret,
|
|
41
45
|
openBrowser,
|
|
42
|
-
io
|
|
46
|
+
io,
|
|
47
|
+
dataManager
|
|
43
48
|
);
|
|
44
49
|
await verifyAndSave(
|
|
45
50
|
{
|
|
@@ -49,7 +54,8 @@ async function connectGoogle({ openBrowser, io }) {
|
|
|
49
54
|
loginCustomerId: existing.data.login_customer_id || void 0
|
|
50
55
|
},
|
|
51
56
|
store,
|
|
52
|
-
io
|
|
57
|
+
io,
|
|
58
|
+
dataManager
|
|
53
59
|
);
|
|
54
60
|
return;
|
|
55
61
|
}
|
|
@@ -65,6 +71,7 @@ async function connectGoogle({ openBrowser, io }) {
|
|
|
65
71
|
let creds;
|
|
66
72
|
if (imported) {
|
|
67
73
|
creds = imported;
|
|
74
|
+
if (dataManager && (await new GoogleAdsRestClient(creds).dataManagerAccess()).scope_status !== "GRANTED") creds.refreshToken = await runOAuthFlow(creds.clientId, creds.clientSecret, openBrowser, io, true);
|
|
68
75
|
} else {
|
|
69
76
|
let clientId = "";
|
|
70
77
|
let clientSecret = "";
|
|
@@ -83,22 +90,22 @@ async function connectGoogle({ openBrowser, io }) {
|
|
|
83
90
|
return;
|
|
84
91
|
}
|
|
85
92
|
const loginCustomerId = (await rl.question("Manager (MCC) customer id for login-customer-id (Enter to skip): ")).trim() || void 0;
|
|
86
|
-
const refreshToken = await runOAuthFlow(clientId, clientSecret, openBrowser, io);
|
|
93
|
+
const refreshToken = await runOAuthFlow(clientId, clientSecret, openBrowser, io, dataManager);
|
|
87
94
|
creds = { clientId, clientSecret, refreshToken, loginCustomerId };
|
|
88
95
|
}
|
|
89
|
-
await verifyAndSave(creds, store, io);
|
|
96
|
+
await verifyAndSave(creds, store, io, dataManager);
|
|
90
97
|
} finally {
|
|
91
98
|
rl.close();
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
|
-
async function runOAuthFlow(clientId, clientSecret, openBrowser, io) {
|
|
101
|
+
async function runOAuthFlow(clientId, clientSecret, openBrowser, io, dataManager = false) {
|
|
95
102
|
io.out("");
|
|
96
|
-
io.out(
|
|
103
|
+
io.out(`Starting the OAuth flow (scopes: Google Ads${dataManager ? " + Data Manager" : ""}). A browser window should open;`);
|
|
97
104
|
io.out("sign in with the Google account that can access your ad accounts.");
|
|
98
105
|
const pkce = generatePkce();
|
|
99
106
|
const state = generateOAuthState();
|
|
100
107
|
const loopback = await startLoopbackServer("127.0.0.1", state);
|
|
101
|
-
const authUrl = buildGoogleAuthUrl(clientId, loopback.redirectUri, pkce.challenge, state);
|
|
108
|
+
const authUrl = buildGoogleAuthUrl(clientId, loopback.redirectUri, pkce.challenge, state, dataManager);
|
|
102
109
|
if (openBrowser) {
|
|
103
110
|
openInBrowser(authUrl);
|
|
104
111
|
io.out(`If the browser did not open, visit:
|
|
@@ -121,10 +128,15 @@ async function runOAuthFlow(clientId, clientSecret, openBrowser, io) {
|
|
|
121
128
|
loopback.close();
|
|
122
129
|
}
|
|
123
130
|
}
|
|
124
|
-
async function verifyAndSave(creds, store, io) {
|
|
131
|
+
async function verifyAndSave(creds, store, io, dataManager = false) {
|
|
125
132
|
io.out("Verifying access\u2026");
|
|
126
133
|
const client = new GoogleAdsRestClient(creds);
|
|
127
134
|
const customers = await client.listAccessibleCustomers();
|
|
135
|
+
if (dataManager) {
|
|
136
|
+
const access = await client.dataManagerAccess();
|
|
137
|
+
if (access.scope_status === "MISSING") throw new Error("Data Manager scope was not granted. The previous stored connection has been preserved.");
|
|
138
|
+
io.out(`Data Manager OAuth scope: ${access.scope_status}. API enablement and native event eligibility are checked during validate-only previews.`);
|
|
139
|
+
}
|
|
128
140
|
await store.set({
|
|
129
141
|
provider: "google",
|
|
130
142
|
source: "byo",
|
|
@@ -183,4 +195,4 @@ function expandHome(p) {
|
|
|
183
195
|
export {
|
|
184
196
|
connectGoogle
|
|
185
197
|
};
|
|
186
|
-
//# sourceMappingURL=google-
|
|
198
|
+
//# sourceMappingURL=google-YGSPHPHA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/connect/google.ts"],"sourcesContent":["import { promises as fs } from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\nimport readline from 'node:readline/promises';\nimport YAML from 'yaml';\nimport { CredentialStore } from '@adport/core';\nimport { GoogleAdsRestClient, type GoogleCredentials } from '@adport/provider-google';\nimport type { ProgramIO } from '../program.js';\nimport {\n buildGoogleAuthUrl,\n exchangeCodeForTokens,\n generateOAuthState,\n generatePkce,\n openInBrowser,\n parseClientSecretJson,\n startLoopbackServer,\n} from './oauth.js';\nimport { printLocalConnectionIntro, printLocalConnectionSaved } from './local.js';\n\nexport interface ConnectGoogleOptions {\n openBrowser: boolean;\n dataManager?: boolean;\n io: ProgramIO;\n}\n\n/**\n * Guided Google Ads connection using Cloud project API access and OAuth.\n */\nexport async function connectGoogle({ openBrowser, dataManager = false, io }: ConnectGoogleOptions): Promise<void> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n const store = new CredentialStore();\n try {\n printLocalConnectionIntro(io, 'Google Ads');\n if (dataManager) {\n io.out('Data Manager is explicitly requested: OAuth will also request the datamanager scope for conversion ingestion.');\n io.out('Enable Data Manager API in the same Google Cloud project first. Existing grants are unchanged until you approve consent.');\n }\n io.out('Google may show \"Google has not verified this app\" for a private/unverified');\n io.out('OAuth project. The developer shown will be your project contact. That warning');\n io.out('is expected for BYO personal use; a verified Adport screen is Cloud-only.');\n io.out('');\n // Re-auth fast path: keep the stored OAuth client and\n // only redo the browser consent (covers expired/revoked refresh tokens).\n const existing = await store.get('google');\n if (existing?.data.client_id && existing.data.client_secret) {\n const answer = (\n await rl.question(\n 'Existing Google connection found. Re-authorize with the same OAuth client? [Y/n] ',\n )\n )\n .trim()\n .toLowerCase();\n if (answer !== 'n' && answer !== 'no') {\n const refreshToken = await runOAuthFlow(\n existing.data.client_id,\n existing.data.client_secret,\n openBrowser,\n io,\n dataManager,\n );\n await verifyAndSave(\n {\n clientId: existing.data.client_id,\n clientSecret: existing.data.client_secret,\n refreshToken,\n loginCustomerId: existing.data.login_customer_id || undefined,\n },\n store,\n io,\n dataManager,\n );\n return;\n }\n }\n\n io.out('Connecting Google Ads. You need (the wizard guides each step):');\n io.out(' 1. A Google Cloud project with Google Ads API access: https://console.cloud.google.com/apis/api/googleads.googleapis.com/overview');\n io.out(' For production accounts, the project needs Explorer, Basic, or Standard access.');\n io.out(' 2. An OAuth \"Desktop app\" client in that project: https://console.cloud.google.com/apis/credentials');\n io.out(' Enable Google Ads API; choose External; add yourself as a test user.');\n io.out(' Suggested private app name: \"Adport Local – <your organization>\".');\n io.out('');\n\n // Fast path: import an existing google-ads.yaml (the ecosystem convention).\n const imported = await tryImportGoogleAdsYaml(rl, io);\n let creds: GoogleCredentials;\n if (imported) {\n creds = imported;\n if (dataManager && (await new GoogleAdsRestClient(creds).dataManagerAccess()).scope_status !== 'GRANTED') creds.refreshToken = await runOAuthFlow(creds.clientId, creds.clientSecret, openBrowser, io, true);\n } else {\n let clientId = '';\n let clientSecret = '';\n const secretPath = (\n await rl.question('Path to downloaded client_secret_*.json (or press Enter to type id/secret manually): ')\n ).trim();\n if (secretPath) {\n const parsed = parseClientSecretJson(await fs.readFile(expandHome(secretPath), 'utf8'));\n clientId = parsed.clientId;\n clientSecret = parsed.clientSecret;\n } else {\n clientId = (await rl.question('OAuth client id: ')).trim();\n clientSecret = (await rl.question('OAuth client secret: ')).trim();\n }\n\n if (!clientId || !clientSecret) {\n io.err('Missing OAuth client credentials — aborting.');\n process.exitCode = 1;\n return;\n }\n\n const loginCustomerId =\n (await rl.question('Manager (MCC) customer id for login-customer-id (Enter to skip): ')).trim() || undefined;\n\n const refreshToken = await runOAuthFlow(clientId, clientSecret, openBrowser, io, dataManager);\n creds = { clientId, clientSecret, refreshToken, loginCustomerId };\n }\n\n await verifyAndSave(creds, store, io, dataManager);\n } finally {\n rl.close();\n }\n}\n\nasync function runOAuthFlow(\n clientId: string,\n clientSecret: string,\n openBrowser: boolean,\n io: ProgramIO,\n dataManager = false,\n): Promise<string> {\n io.out('');\n io.out(`Starting the OAuth flow (scopes: Google Ads${dataManager ? ' + Data Manager' : ''}). A browser window should open;`);\n io.out('sign in with the Google account that can access your ad accounts.');\n const pkce = generatePkce();\n const state = generateOAuthState();\n const loopback = await startLoopbackServer('127.0.0.1', state);\n const authUrl = buildGoogleAuthUrl(clientId, loopback.redirectUri, pkce.challenge, state, dataManager);\n if (openBrowser) {\n openInBrowser(authUrl);\n io.out(`If the browser did not open, visit:\\n ${authUrl}`);\n } else {\n io.out(`Open this URL in a browser on this machine (or SSH port-forward the shown port):\\n ${authUrl}`);\n }\n try {\n const code = await loopback.waitForCode;\n const tokens = await exchangeCodeForTokens({\n clientId,\n clientSecret,\n code,\n redirectUri: loopback.redirectUri,\n codeVerifier: pkce.verifier,\n });\n return tokens.refreshToken;\n } finally {\n loopback.close();\n }\n}\n\nasync function verifyAndSave(creds: GoogleCredentials, store: CredentialStore, io: ProgramIO, dataManager = false): Promise<void> {\n io.out('Verifying access…');\n const client = new GoogleAdsRestClient(creds);\n const customers = await client.listAccessibleCustomers();\n if (dataManager) {\n const access = await client.dataManagerAccess();\n if (access.scope_status === 'MISSING') throw new Error('Data Manager scope was not granted. The previous stored connection has been preserved.');\n io.out(`Data Manager OAuth scope: ${access.scope_status}. API enablement and native event eligibility are checked during validate-only previews.`);\n }\n await store.set({\n provider: 'google',\n source: 'byo',\n data: {\n client_id: creds.clientId,\n client_secret: creds.clientSecret,\n refresh_token: creds.refreshToken,\n ...(creds.loginCustomerId ? { login_customer_id: creds.loginCustomerId } : {}),\n },\n });\n io.out('');\n io.out(`✓ Connected. ${customers.length} accessible customer id(s): ${customers.join(', ')}`);\n printLocalConnectionSaved(io);\n io.out('');\n io.out('If this token expires again in ~7 days: your OAuth consent screen is in \"Testing\"');\n io.out('status — set it to \"In production\" at console.cloud.google.com/apis/credentials/consent');\n io.out('(no verification needed for your own use; refresh tokens then stop expiring weekly).');\n io.out('');\n io.out('Try: adport accounts · adport report --provider google · adport mcp');\n}\n\nasync function tryImportGoogleAdsYaml(\n rl: readline.Interface,\n io: ProgramIO,\n): Promise<GoogleCredentials | undefined> {\n const candidates = [\n process.env.GOOGLE_ADS_CONFIGURATION_FILE_PATH,\n path.join(os.homedir(), 'google-ads.yaml'),\n ].filter((p): p is string => Boolean(p));\n for (const candidate of candidates) {\n let raw: string;\n try {\n raw = await fs.readFile(candidate, 'utf8');\n } catch {\n continue;\n }\n const parsed = YAML.parse(raw) as Record<string, unknown> | null;\n const clientId = str(parsed?.client_id);\n const clientSecret = str(parsed?.client_secret);\n const refreshToken = str(parsed?.refresh_token);\n if (!clientId || !clientSecret || !refreshToken) continue;\n const answer = (await rl.question(`Found ${candidate} — import it? [Y/n] `)).trim().toLowerCase();\n if (answer === 'n' || answer === 'no') continue;\n io.out(`Importing credentials from ${candidate}.`);\n return {\n clientId,\n clientSecret,\n refreshToken,\n loginCustomerId: str(parsed?.login_customer_id) || undefined,\n };\n }\n return undefined;\n}\n\nfunction str(value: unknown): string {\n return value === undefined || value === null ? '' : String(value);\n}\n\nfunction expandHome(p: string): string {\n return p.startsWith('~/') ? path.join(os.homedir(), p.slice(2)) : p;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAA,SAAS,YAAY,UAAU;AAC/B,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,cAAc;AACrB,OAAO,UAAU;AACjB,SAAS,uBAAuB;AAChC,SAAS,2BAAmD;AAsB5D,eAAsB,cAAc,EAAE,aAAa,cAAc,OAAO,GAAG,GAAwC;AACjH,QAAM,KAAK,SAAS,gB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AG,QAAQ,GAAG,iBAAiB;AAAA,EAC3C,EAAE,OAAO,CAAC,MAAmB,QAAQ,CAAC,CAAC;AACvC,aAAW,aAAa,YAAY;AAClC,QAAI;AACJ,QAAI;AACF,YAAM,MAAM,GAAG,SAAS,WAAW,MAAM;AAAA,IAC3C,QAAQ;AACN;AAAA,IACF;AACA,UAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,UAAM,WAAW,IAAI,QAAQ,SAAS;AACtC,UAAM,eAAe,IAAI,QAAQ,aAAa;AAC9C,UAAM,eAAe,IAAI,QAAQ,aAAa;AAC9C,QAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,aAAc;AACjD,UAAM,UAAU,MAAM,GAAG,SAAS,SAAS,SAAS,2BAAsB,GAAG,KAAK,EAAE,YAAY;AAChG,QAAI,WAAW,OAAO,WAAW,KAAM;AACvC,OAAG,IAAI,8BAA8B,SAAS,GAAG;AACjD,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,iBAAiB,IAAI,QAAQ,iBAAiB,KAAK;AAAA,IACrD;AAAA,EACF;AACA,SAAO;AACT;AAEA,SAAS,IAAI,OAAwB;AACnC,SAAO,UAAU,UAAa,UAAU,OAAO,KAAK,OAAO,KAAK;AAClE;AAEA,SAAS,WAAW,GAAmB;AACrC,SAAO,EAAE,WAAW,IAAI,IAAI,KAAK,KAAK,GAAG,QAAQ,GAAG,EAAE,MAAM,CAAC,CAAC,IAAI;AACpE;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildGoogleAuthUrl,
|
|
3
|
+
exchangeCodeForTokens,
|
|
4
|
+
generateOAuthState,
|
|
5
|
+
generatePkce,
|
|
6
|
+
openInBrowser,
|
|
7
|
+
startLoopbackServer
|
|
8
|
+
} from "./chunk-JSWZBPDJ.js";
|
|
9
|
+
import {
|
|
10
|
+
printLocalConnectionIntro,
|
|
11
|
+
printLocalConnectionSaved
|
|
12
|
+
} from "./chunk-OPRADP2V.js";
|
|
13
|
+
|
|
14
|
+
// src/connect/gtm.ts
|
|
15
|
+
import readline from "readline/promises";
|
|
16
|
+
import { AdportError, CredentialStore, GTM_SCOPES } from "@adport/core";
|
|
17
|
+
import { GtmClient, GtmProvider } from "@adport/provider-gtm";
|
|
18
|
+
async function connectGtm(input) {
|
|
19
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
20
|
+
const store = new CredentialStore();
|
|
21
|
+
try {
|
|
22
|
+
printLocalConnectionIntro(input.io, "Google Tag Manager");
|
|
23
|
+
input.io.out("Enable Tag Manager API in your Google Cloud project and create an OAuth Desktop app client.");
|
|
24
|
+
input.io.out("This flow requests container editing, version creation and publishing. Every change uses preview/apply.");
|
|
25
|
+
const existing = (await store.get("gtm"))?.data;
|
|
26
|
+
const clientId = (await rl.question("OAuth client ID (Enter to reuse stored/environment): ")).trim() || existing?.client_id || process.env.GTM_CLIENT_ID || "";
|
|
27
|
+
const clientSecret = existing?.client_secret || process.env.GTM_CLIENT_SECRET || "";
|
|
28
|
+
if (!clientId || !clientSecret) throw new AdportError("INVALID_INPUT", "Set GTM_CLIENT_SECRET securely in your terminal and provide the OAuth client ID.");
|
|
29
|
+
const pkce = generatePkce();
|
|
30
|
+
const state = generateOAuthState();
|
|
31
|
+
const loopback = await startLoopbackServer("127.0.0.1", state);
|
|
32
|
+
let timeout;
|
|
33
|
+
let refreshToken;
|
|
34
|
+
try {
|
|
35
|
+
const authUrl = buildGoogleAuthUrl(clientId, loopback.redirectUri, pkce.challenge, state, false, GTM_SCOPES);
|
|
36
|
+
input.io.out(`Authorize your Google Tag Manager connection:
|
|
37
|
+
${authUrl}`);
|
|
38
|
+
if (input.openBrowser) openInBrowser(authUrl);
|
|
39
|
+
const code = await Promise.race([loopback.waitForCode, new Promise((_resolve, reject) => {
|
|
40
|
+
timeout = setTimeout(() => reject(new Error("GTM authorization timed out after five minutes.")), 3e5);
|
|
41
|
+
})]);
|
|
42
|
+
({ refreshToken } = await exchangeCodeForTokens({ clientId, clientSecret, code, redirectUri: loopback.redirectUri, codeVerifier: pkce.verifier }));
|
|
43
|
+
} finally {
|
|
44
|
+
clearTimeout(timeout);
|
|
45
|
+
loopback.close();
|
|
46
|
+
}
|
|
47
|
+
const accounts = await new GtmProvider(new GtmClient({ clientId, clientSecret, refreshToken })).listAccounts();
|
|
48
|
+
await store.set({ provider: "gtm", source: "byo", data: { client_id: clientId, client_secret: clientSecret, refresh_token: refreshToken } });
|
|
49
|
+
input.io.out(`Connected: ${accounts.length} accessible Google Tag Manager account(s).`);
|
|
50
|
+
printLocalConnectionSaved(input.io);
|
|
51
|
+
} finally {
|
|
52
|
+
rl.close();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
connectGtm
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=gtm-LUOYKU3F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/connect/gtm.ts"],"sourcesContent":["import readline from 'node:readline/promises';\nimport { AdportError, CredentialStore, GTM_SCOPES } from '@adport/core';\nimport { GtmClient, GtmProvider } from '@adport/provider-gtm';\nimport type { ProgramIO } from '../program.js';\nimport { printLocalConnectionIntro, printLocalConnectionSaved } from './local.js';\nimport { buildGoogleAuthUrl, exchangeCodeForTokens, generateOAuthState, generatePkce, openInBrowser, startLoopbackServer } from './oauth.js';\n\nexport async function connectGtm(input: { openBrowser: boolean; io: ProgramIO }): Promise<void> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n const store = new CredentialStore();\n try {\n printLocalConnectionIntro(input.io, 'Google Tag Manager');\n input.io.out('Enable Tag Manager API in your Google Cloud project and create an OAuth Desktop app client.');\n input.io.out('This flow requests container editing, version creation and publishing. Every change uses preview/apply.');\n const existing = (await store.get('gtm'))?.data;\n const clientId = (await rl.question('OAuth client ID (Enter to reuse stored/environment): ')).trim() || existing?.client_id || process.env.GTM_CLIENT_ID || '';\n const clientSecret = existing?.client_secret || process.env.GTM_CLIENT_SECRET || '';\n if (!clientId || !clientSecret) throw new AdportError('INVALID_INPUT', 'Set GTM_CLIENT_SECRET securely in your terminal and provide the OAuth client ID.');\n const pkce = generatePkce();\n const state = generateOAuthState();\n const loopback = await startLoopbackServer('127.0.0.1', state);\n let timeout: ReturnType<typeof setTimeout> | undefined;\n let refreshToken: string;\n try {\n const authUrl = buildGoogleAuthUrl(clientId, loopback.redirectUri, pkce.challenge, state, false, GTM_SCOPES);\n input.io.out(`Authorize your Google Tag Manager connection:\\n ${authUrl}`);\n if (input.openBrowser) openInBrowser(authUrl);\n const code = await Promise.race([loopback.waitForCode, new Promise<never>((_resolve, reject) => {\n timeout = setTimeout(() => reject(new Error('GTM authorization timed out after five minutes.')), 300_000);\n })]);\n ({ refreshToken } = await exchangeCodeForTokens({ clientId, clientSecret, code, redirectUri: loopback.redirectUri, codeVerifier: pkce.verifier }));\n } finally { clearTimeout(timeout); loopback.close(); }\n const accounts = await new GtmProvider(new GtmClient({ clientId, clientSecret, refreshToken })).listAccounts();\n await store.set({ provider: 'gtm', source: 'byo', data: { client_id: clientId, client_secret: clientSecret, refresh_token: refreshToken } });\n input.io.out(`Connected: ${accounts.length} accessible Google Tag Manager account(s).`);\n printLocalConnectionSaved(input.io);\n } finally { rl.close(); }\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,OAAO,cAAc;AACrB,SAAS,aAAa,iBAAiB,kBAAkB;AACzD,SAAS,WAAW,mBAAmB;AAKvC,eAAsB,WAAW,OAA+D;AAC9F,QAAM,KAAK,SAAS,gBAAgB,EAAE,OAAO,QAAQ,OAAO,QAAQ,QAAQ,OAAO,CAAC;AACpF,QAAM,QAAQ,IAAI,gBAAgB;AAClC,MAAI;AACF,8BAA0B,MAAM,IAAI,oBAAoB;AACxD,UAAM,GAAG,IAAI,6FAA6F;AAC1G,UAAM,GAAG,IAAI,yGAAyG;AACtH,UAAM,YAAY,MAAM,MAAM,IAAI,KAAK,IAAI;AAC3C,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