{"version":3,"file":"gumroad.mjs","names":[],"sources":["../../../../src/plugins/generic-oauth/providers/gumroad.ts"],"sourcesContent":["import type { OAuth2Tokens, OAuth2UserInfo } from \"@better-auth/core/oauth2\";\nimport { betterFetch } from \"@better-fetch/fetch\";\nimport type { BaseOAuthProviderOptions, GenericOAuthConfig } from \"../index\";\n\nexport interface GumroadOptions extends BaseOAuthProviderOptions {}\n\ninterface GumroadUser {\n\tuser_id: string;\n\tname: string;\n\temail: string;\n\tprofile_url: string;\n}\n\ninterface GumroadProfile {\n\tsuccess: boolean;\n\tuser: GumroadUser;\n}\n\n/**\n * Gumroad OAuth provider helper\n *\n * @example\n * ```ts\n * import { genericOAuth, gumroad } from \"better-auth/plugins/generic-oauth\";\n *\n * export const auth = betterAuth({\n *   plugins: [\n *     genericOAuth({\n *       config: [\n *         gumroad({\n *           clientId: process.env.GUMROAD_CLIENT_ID,\n *           clientSecret: process.env.GUMROAD_CLIENT_SECRET,\n *         }),\n *       ],\n *     }),\n *   ],\n * });\n * ```\n *\n * @see https://app.gumroad.com/oauth\n */\nexport function gumroad(options: GumroadOptions): GenericOAuthConfig {\n\tconst getUserInfo = async (\n\t\ttokens: OAuth2Tokens,\n\t): Promise<OAuth2UserInfo | null> => {\n\t\tconst { data: profile, error } = await betterFetch<GumroadProfile>(\n\t\t\t\"https://api.gumroad.com/v2/user\",\n\t\t\t{\n\t\t\t\tmethod: \"GET\",\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${tokens.accessToken}`,\n\t\t\t\t},\n\t\t\t},\n\t\t);\n\n\t\tif (error || !profile?.success || !profile.user) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn {\n\t\t\tid: profile.user.user_id,\n\t\t\tname: profile.user.name,\n\t\t\temail: profile.user.email,\n\t\t\timage: profile.user.profile_url,\n\t\t\temailVerified: false,\n\t\t};\n\t};\n\n\tconst defaultScopes = [\"view_profile\"];\n\n\treturn {\n\t\tproviderId: \"gumroad\",\n\t\tauthorizationUrl: \"https://gumroad.com/oauth/authorize\",\n\t\ttokenUrl: \"https://api.gumroad.com/oauth/token\",\n\t\tclientId: options.clientId,\n\t\tclientSecret: options.clientSecret,\n\t\tscopes: options.scopes ?? defaultScopes,\n\t\tredirectURI: options.redirectURI,\n\t\tpkce: options.pkce,\n\t\tdisableImplicitSignUp: options.disableImplicitSignUp,\n\t\tdisableSignUp: options.disableSignUp,\n\t\toverrideUserInfo: options.overrideUserInfo,\n\t\tgetUserInfo,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,QAAQ,SAA6C;CACpE,MAAM,cAAc,OACnB,WACoC;EACpC,MAAM,EAAE,MAAM,SAAS,UAAU,MAAM,YACtC,mCACA;GACC,QAAQ;GACR,SAAS,EACR,eAAe,UAAU,OAAO,eAChC;GACD,CACD;AAED,MAAI,SAAS,CAAC,SAAS,WAAW,CAAC,QAAQ,KAC1C,QAAO;AAGR,SAAO;GACN,IAAI,QAAQ,KAAK;GACjB,MAAM,QAAQ,KAAK;GACnB,OAAO,QAAQ,KAAK;GACpB,OAAO,QAAQ,KAAK;GACpB,eAAe;GACf;;AAKF,QAAO;EACN,YAAY;EACZ,kBAAkB;EAClB,UAAU;EACV,UAAU,QAAQ;EAClB,cAAc,QAAQ;EACtB,QAAQ,QAAQ,UARK,CAAC,eAAe;EASrC,aAAa,QAAQ;EACrB,MAAM,QAAQ;EACd,uBAAuB,QAAQ;EAC/B,eAAe,QAAQ;EACvB,kBAAkB,QAAQ;EAC1B;EACA"}