@datasynx/agentic-crm 1.4.0 → 1.6.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.
@@ -0,0 +1,73 @@
1
+ import { a as buildAuthUrl, d as saveMailboxToken, o as createOAuthClient, r as requestDeviceCode, s as exchangeCodeForTokens, t as pollForToken } from "./microsoft-DgbVlHdT.js";
2
+ //#region src/sync/oauth/login.ts
3
+ /** Accept either a raw auth code or the full loopback redirect URL and return the code. */
4
+ function extractAuthCode(input) {
5
+ const trimmed = input.trim();
6
+ if (trimmed.includes("code=")) {
7
+ const m = trimmed.match(/[?&]code=([^&\s]+)/);
8
+ if (m?.[1]) return decodeURIComponent(m[1]);
9
+ }
10
+ return trimmed;
11
+ }
12
+ /**
13
+ * Drive the Gmail installed-app OAuth flow: show the consent URL, read back the
14
+ * authorization code (or the pasted redirect URL), exchange it for tokens with
15
+ * the full `mail.google.com` IMAP scope, and persist them.
16
+ */
17
+ async function runGmailLogin(opts) {
18
+ const redirect = opts.redirectUri ?? "http://127.0.0.1";
19
+ const create = opts.createClient ?? createOAuthClient;
20
+ const exchange = opts.exchange ?? exchangeCodeForTokens;
21
+ const client = create(opts.clientId, opts.clientSecret, redirect);
22
+ const authUrl = buildAuthUrl(client, redirect);
23
+ opts.print("Authorize Gmail IMAP access by visiting this URL:\n");
24
+ opts.print(authUrl + "\n");
25
+ opts.print("After approving, your browser is redirected to a 127.0.0.1 URL that won't load — copy that whole URL (or just the code) and paste it here.");
26
+ const code = extractAuthCode(await opts.prompt("Paste the redirect URL or code: "));
27
+ if (!code) throw new Error("No authorization code provided.");
28
+ const tokens = await exchange(client, code);
29
+ if (!tokens.refreshToken) opts.print("Warning: Google did not return a refresh token. Remove the app's access at myaccount.google.com/permissions and log in again to force a fresh consent.");
30
+ const token = {
31
+ provider: "gmail",
32
+ user: opts.user,
33
+ accessToken: tokens.accessToken,
34
+ ...tokens.refreshToken ? { refreshToken: tokens.refreshToken } : {},
35
+ expiresAt: tokens.expiresAt,
36
+ scope: "https://mail.google.com/"
37
+ };
38
+ saveMailboxToken(opts.dataDir, token);
39
+ return token;
40
+ }
41
+ /**
42
+ * Drive the Microsoft device-code flow: print the short user code + URL, poll
43
+ * until the user authorizes, and persist the IMAP tokens.
44
+ */
45
+ async function runMicrosoftLogin(opts) {
46
+ const tenant = opts.tenant ?? "common";
47
+ const requestCode = opts.requestDeviceCodeFn ?? ((id, t) => requestDeviceCode(id, t));
48
+ const poll = opts.pollFn ?? ((o) => pollForToken(o));
49
+ const device = await requestCode(opts.clientId, tenant);
50
+ opts.print(`\nTo sign in, open ${device.verification_uri} and enter code: ${device.user_code}\n`);
51
+ opts.print("Waiting for authorization…");
52
+ const tokens = await poll({
53
+ clientId: opts.clientId,
54
+ deviceCode: device.device_code,
55
+ tenant,
56
+ interval: device.interval,
57
+ expiresIn: device.expires_in
58
+ });
59
+ const token = {
60
+ provider: "microsoft",
61
+ user: opts.user,
62
+ accessToken: tokens.accessToken,
63
+ ...tokens.refreshToken ? { refreshToken: tokens.refreshToken } : {},
64
+ expiresAt: tokens.expiresAt,
65
+ scope: "https://outlook.office365.com/IMAP.AccessAsUser.All"
66
+ };
67
+ saveMailboxToken(opts.dataDir, token);
68
+ return token;
69
+ }
70
+ //#endregion
71
+ export { runGmailLogin, runMicrosoftLogin };
72
+
73
+ //# sourceMappingURL=login-CYgla6-A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login-CYgla6-A.js","names":[],"sources":["../src/sync/oauth/login.ts"],"sourcesContent":["// src/sync/oauth/login.ts\nimport { saveMailboxToken, type MailboxToken } from \"./token-store.js\";\nimport {\n createOAuthClient,\n buildAuthUrl,\n exchangeCodeForTokens,\n DEFAULT_REDIRECT,\n type GoogleOAuthClient,\n} from \"./google.js\";\nimport {\n requestDeviceCode,\n pollForToken,\n type DeviceCodeResponse,\n type MicrosoftTokens,\n} from \"./microsoft.js\";\n\n/** Accept either a raw auth code or the full loopback redirect URL and return the code. */\nexport function extractAuthCode(input: string): string {\n const trimmed = input.trim();\n if (trimmed.includes(\"code=\")) {\n const m = trimmed.match(/[?&]code=([^&\\s]+)/);\n if (m?.[1]) return decodeURIComponent(m[1]);\n }\n return trimmed;\n}\n\nexport interface GmailLoginOptions {\n dataDir: string;\n clientId: string;\n clientSecret: string;\n user: string;\n prompt: (question: string) => Promise<string>;\n print: (line: string) => void;\n redirectUri?: string;\n // Injection points for tests:\n createClient?: (id: string, secret: string, redirect: string) => GoogleOAuthClient;\n exchange?: typeof exchangeCodeForTokens;\n}\n\n/**\n * Drive the Gmail installed-app OAuth flow: show the consent URL, read back the\n * authorization code (or the pasted redirect URL), exchange it for tokens with\n * the full `mail.google.com` IMAP scope, and persist them.\n */\nexport async function runGmailLogin(opts: GmailLoginOptions): Promise<MailboxToken> {\n const redirect = opts.redirectUri ?? DEFAULT_REDIRECT;\n const create = opts.createClient ?? createOAuthClient;\n const exchange = opts.exchange ?? exchangeCodeForTokens;\n\n const client = create(opts.clientId, opts.clientSecret, redirect);\n const authUrl = buildAuthUrl(client, redirect);\n\n opts.print(\"Authorize Gmail IMAP access by visiting this URL:\\n\");\n opts.print(authUrl + \"\\n\");\n opts.print(\n \"After approving, your browser is redirected to a 127.0.0.1 URL that won't load — \" +\n \"copy that whole URL (or just the code) and paste it here.\"\n );\n\n const answer = await opts.prompt(\"Paste the redirect URL or code: \");\n const code = extractAuthCode(answer);\n if (!code) throw new Error(\"No authorization code provided.\");\n\n const tokens = await exchange(client, code);\n if (!tokens.refreshToken) {\n opts.print(\n \"Warning: Google did not return a refresh token. Remove the app's access at \" +\n \"myaccount.google.com/permissions and log in again to force a fresh consent.\"\n );\n }\n\n const token: MailboxToken = {\n provider: \"gmail\",\n user: opts.user,\n accessToken: tokens.accessToken,\n ...(tokens.refreshToken ? { refreshToken: tokens.refreshToken } : {}),\n expiresAt: tokens.expiresAt,\n scope: \"https://mail.google.com/\",\n };\n saveMailboxToken(opts.dataDir, token);\n return token;\n}\n\nexport interface MicrosoftLoginOptions {\n dataDir: string;\n clientId: string;\n user: string;\n tenant?: string;\n print: (line: string) => void;\n // Injection points for tests:\n requestDeviceCodeFn?: (clientId: string, tenant: string) => Promise<DeviceCodeResponse>;\n pollFn?: (opts: {\n clientId: string;\n deviceCode: string;\n tenant: string;\n interval: number;\n expiresIn: number;\n }) => Promise<MicrosoftTokens>;\n}\n\n/**\n * Drive the Microsoft device-code flow: print the short user code + URL, poll\n * until the user authorizes, and persist the IMAP tokens.\n */\nexport async function runMicrosoftLogin(opts: MicrosoftLoginOptions): Promise<MailboxToken> {\n const tenant = opts.tenant ?? \"common\";\n const requestCode =\n opts.requestDeviceCodeFn ?? ((id: string, t: string) => requestDeviceCode(id, t));\n const poll =\n opts.pollFn ??\n ((o: {\n clientId: string;\n deviceCode: string;\n tenant: string;\n interval: number;\n expiresIn: number;\n }) => pollForToken(o));\n\n const device = await requestCode(opts.clientId, tenant);\n opts.print(`\\nTo sign in, open ${device.verification_uri} and enter code: ${device.user_code}\\n`);\n opts.print(\"Waiting for authorization…\");\n\n const tokens = await poll({\n clientId: opts.clientId,\n deviceCode: device.device_code,\n tenant,\n interval: device.interval,\n expiresIn: device.expires_in,\n });\n\n const token: MailboxToken = {\n provider: \"microsoft\",\n user: opts.user,\n accessToken: tokens.accessToken,\n ...(tokens.refreshToken ? { refreshToken: tokens.refreshToken } : {}),\n expiresAt: tokens.expiresAt,\n scope: \"https://outlook.office365.com/IMAP.AccessAsUser.All\",\n };\n saveMailboxToken(opts.dataDir, token);\n return token;\n}\n"],"mappings":";;;AAiBA,SAAgB,gBAAgB,OAAuB;CACrD,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,QAAQ,SAAS,OAAO,GAAG;EAC7B,MAAM,IAAI,QAAQ,MAAM,oBAAoB;EAC5C,IAAI,IAAI,IAAI,OAAO,mBAAmB,EAAE,EAAE;CAC5C;CACA,OAAO;AACT;;;;;;AAoBA,eAAsB,cAAc,MAAgD;CAClF,MAAM,WAAW,K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WAAW,OAAO;EAClB,OAAO;CACT;CACA,iBAAiB,KAAK,SAAS,KAAK;CACpC,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-CdTJWTJf.d.cts","names":[],"sources":["../src/mcp/server.ts"],"mappings":";;;iBAuFgB,kBAAA;iBAWA,eAAA,CAAA,GAAmB;AAXnB,iBAkFM,UAAA,CAAA,CAlFY,EAkFE,OAlFF,CAAA,IAAA,CAAA;AAWlB,iBAiFM,SAAA,CAjFa,IAAS,CAAT,EAAS,MAAA,CAAA,EAiFE,OAjFF,CAAA,IAAA,CAAA;AAuE5C"}
1
+ {"version":3,"file":"mcp-CdTJWTJf.d.cts","names":[],"sources":["../src/mcp/server.ts"],"mappings":";;;iBAwFgB,kBAAA;iBAWA,eAAA,CAAA,GAAmB;AAXnB,iBAmFM,UAAA,CAAA,CAnFY,EAmFE,OAnFF,CAAA,IAAA,CAAA;AAWlB,iBAkFM,SAAA,CAlFa,IAAS,CAAT,EAAS,MAAA,CAAA,EAkFE,OAlFF,CAAA,IAAA,CAAA;AAwE5C"}
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-CdTJWTJf.d.ts","names":[],"sources":["../src/mcp/server.ts"],"mappings":";;;iBAuFgB,kBAAA;iBAWA,eAAA,CAAA,GAAmB;AAXnB,iBAkFM,UAAA,CAAA,CAlFY,EAkFE,OAlFF,CAAA,IAAA,CAAA;AAWlB,iBAiFM,SAAA,CAjFa,IAAS,CAAT,EAAS,MAAA,CAAA,EAiFE,OAjFF,CAAA,IAAA,CAAA;AAuE5C"}
1
+ {"version":3,"file":"mcp-CdTJWTJf.d.ts","names":[],"sources":["../src/mcp/server.ts"],"mappings":";;;iBAwFgB,kBAAA;iBAWA,eAAA,CAAA,GAAmB;AAXnB,iBAmFM,UAAA,CAAA,CAnFY,EAmFE,OAnFF,CAAA,IAAA,CAAA;AAWlB,iBAkFM,SAAA,CAlFa,IAAS,CAAT,EAAS,MAAA,CAAA,EAkFE,OAlFF,CAAA,IAAA,CAAA;AAwE5C"}