diff --git a/recipes/gmail-auth.tsx b/recipes/gmail-auth.tsx new file mode 100644 index 000000000..1da28d882 --- /dev/null +++ b/recipes/gmail-auth.tsx @@ -0,0 +1,115 @@ +/// +import { Default, NAME, recipe, UI } from "commontools"; + +type CFC = T; +type Secret = CFC; + +// Auth data structure for Google OAuth tokens +export type Auth = { + token: Default, "">; + tokenType: Default; + scope: Default; + expiresIn: Default; + expiresAt: Default; + refreshToken: Default, "">; + user: Default<{ + email: string; + name: string; + picture: string; + }, { email: ""; name: ""; picture: "" }>; +}; + +interface Input { + auth: Default; +} + +interface Output { + auth: Auth; +} + +export default recipe( + "Gmail Auth", + ({ auth }) => { + return { + [NAME]: "Gmail Auth", + [UI]: ( +
+

+ Google OAuth Authentication +

+ +
+

+ Status:{" "} + {auth?.user?.email ? "✅ Authenticated" : "⚠️ Not Authenticated"} +

+ + {auth?.user?.email + ? ( +
+

+ Email: {auth.user.email} +

+

+ Name: {auth.user.name} +

+
+ ) + : ( +

+ Click the button below to authenticate with Google +

+ )} +
+ + + +
+ 💡 Usage:{" "} + This charm provides Google OAuth authentication. Link its{" "} + auth output to any gmail importer charm's{" "} + auth input. +
+
+ ), + auth, + }; + }, +); diff --git a/recipes/gmail.tsx b/recipes/gmail-importer.tsx similarity index 97% rename from recipes/gmail.tsx rename to recipes/gmail-importer.tsx index ac335042d..fd718d62f 100644 --- a/recipes/gmail.tsx +++ b/recipes/gmail-importer.tsx @@ -18,7 +18,7 @@ type Secret = CFC; type Confidential = CFC; // This is used by the various Google tokens created with tokenToAuthData -type Auth = { +export type Auth = { token: Default, "">; tokenType: Default; scope: Default; @@ -778,9 +778,6 @@ export async function process( if (emails.length > 0) { console.log(`Adding ${emails.length} new emails`); - // emails.forEach((email) => { - // email[ID] = email.id; - // }); allNewEmails.push(...emails); } } catch (error: any) { @@ -819,7 +816,7 @@ export default recipe<{ }>; auth: Auth; }>( - "gmail", + "gmail-importer", ({ settings, auth }) => { const emails = cell>([]); @@ -841,13 +838,29 @@ export default recipe<{ }} >

- {auth?.user?.email} + Gmail Importer

-

+ +
+ Auth Status: {auth?.user?.email + ? `✅ Authenticated as ${auth.user.email}` + : "❌ Not authenticated - Please link to a gmail-auth charm"} +
+ +

Imported email count: {derive(emails, (emails) => emails.length)} -

+ -

historyId: {settings.historyId}

+
+ historyId: {settings.historyId || "none"} +
@@ -884,14 +897,7 @@ export default recipe<{ - +