{"version":3,"file":"stripe-graphql-js.cjs","sources":["../src/builder.ts","../src/utils.ts","../src/schema/index.ts","../src/server.ts"],"sourcesContent":["import SchemaBuilder from '@pothos/core';\nimport { GraphQLJSONObject } from 'graphql-scalars';\nimport type Stripe from 'stripe';\n\nimport type {\n  Context,\n  StripeCharge,\n  StripeInvoice,\n  StripePaymentIntent,\n  StripePaymentMethod,\n  StripeSubscription,\n} from './types';\n\n// TODO: Make sure we either use Type or Types (e.g. StripePaymentMethodTypes or StripePaymentMethodType ) everywhere\n\nconst builder = new SchemaBuilder<{\n  Scalars: {\n    JSON: {\n      Output: unknown;\n      Input: JSON;\n    };\n  };\n  Objects: {\n    // biome-ignore lint/complexity/noBannedTypes: Pothos requires {} for empty object types in schema builder\n    Stripe: {};\n    // biome-ignore lint/complexity/noBannedTypes: Pothos requires {} for empty object types in schema builder\n    StripeMutations: {};\n\n    // CUSTOMER\n    StripeCustomers: Stripe.ApiList<Stripe.Customer>;\n    StripeCustomer: Stripe.Customer;\n    StripeCustomerShipping: Stripe.Customer.Shipping;\n    StripeCustomerTax: Stripe.Customer.Tax;\n    StripeCustomerTaxAutomaticTax: Stripe.Customer.Tax.AutomaticTax;\n    StripeCustomerTaxLocation: Stripe.Customer.Tax.Location;\n\n    // ADDRESS\n    StripeAddress: Stripe.Address;\n\n    // PAYMENT METHOD\n    StripePaymentMethods: Stripe.ApiList<StripePaymentMethod>;\n    StripePaymentMethod: StripePaymentMethod;\n    StripeCustomerListPaymentMethodsParamsType: Stripe.CustomerListPaymentMethodsParams.Type;\n    StripePaymentMethodBillingDetails: Stripe.PaymentMethod.BillingDetails;\n    StripePaymentMethodTypes: Stripe.PaymentMethod.Type;\n\n    // PAYMENT METHOD CARD\n    StripePaymentMethodCard: Stripe.PaymentMethod.Card;\n    StripePaymentMethodCardChecks: Stripe.PaymentMethod.Card.Checks;\n    StripePaymentMethodCardNetworks: Stripe.PaymentMethod.Card.Networks;\n    StripePaymentMethodCardThreeDSecureUsage: Stripe.PaymentMethod.Card.ThreeDSecureUsage;\n    StripePaymentMethodCardWallet: Stripe.PaymentMethod.Card.Wallet;\n    StripePaymentMethodCardWalletMasterpass: Stripe.PaymentMethod.Card.Wallet.Masterpass;\n    StripePaymentMethodCardWalletType: Stripe.PaymentMethod.Card.Wallet.Type;\n    StripePaymentMethodCardWalletVisaMasterpass: Stripe.PaymentMethod.Card.Wallet.Masterpass;\n    StripePaymentMethodCardWalletVisaCheckout: Stripe.PaymentMethod.Card.Wallet.VisaCheckout;\n\n    // SUBSCRIPTION\n    StripeSubscriptions: Stripe.ApiList<StripeSubscription>;\n    StripeSubscription: StripeSubscription;\n    StripeSubscriptionStatus: Stripe.Subscription.Status;\n    StripeSubscriptionItems: Stripe.ApiList<Stripe.SubscriptionItem>;\n    StripeSubscriptionItem: Stripe.SubscriptionItem;\n    StripeSubscriptionItemBillingThresholds: Stripe.SubscriptionItem.BillingThresholds;\n    StripeSubscriptionAutomaticTax: Stripe.Subscription.AutomaticTax;\n    StripeSubscriptionBillingThresholds: Stripe.Subscription.BillingThresholds;\n    StripeSubscriptionPauseCollection: Stripe.Subscription.PauseCollection;\n\n    // INVOICE\n    StripeInvoice: StripeInvoice;\n    StripeInvoices: Stripe.ApiList<StripeInvoice>;\n    // StripeInvoceAccountTaxIds: Array<string | Stripe.TaxId | Stripe.DeletedTaxId> | null\n    StripeInvoiceAutomaticTax: Stripe.Invoice.AutomaticTax;\n    StripeInvoiceCustomField: Stripe.Invoice.CustomField;\n    StripeInvoiceCustomerShipping: Stripe.Invoice.CustomerShipping;\n    StripeInvoiceCustomerTaxId: Stripe.Invoice.CustomerTaxId;\n    StripeInvoiceRenderingOptions: Stripe.Invoice.RenderingOptions;\n    StripeInvoiceStatusTransitions: Stripe.Invoice.StatusTransitions;\n\n    // INVOICE LINE ITEM\n    StripeInvoiceLineItems: Stripe.ApiList<Stripe.InvoiceLineItem>;\n    StripeInvoiceLineItem: Stripe.InvoiceLineItem;\n    StripeInvoiceLineItemPeriod: Stripe.InvoiceLineItem.Period;\n    StripeInvoiceLineItemTaxAmount: Stripe.InvoiceLineItem.TaxAmount;\n\n    // PRICE\n    StripePrice: Stripe.Price;\n\n    // PLAN\n    StripePlan: Stripe.Plan;\n    StripePlanTransformUsage: Stripe.Plan.TransformUsage;\n\n    // PRODUCT\n    StripeProduct: Stripe.Product;\n\n    // TAX RATES\n    StripeTaxRate: Stripe.TaxRate;\n\n    // TEST CLOCK\n    StripeTestClock: Stripe.TestHelpers.TestClock;\n\n    // BILLING PORTAL\n    StripeBillingPortalSession: Stripe.BillingPortal.Session;\n\n    // PAYMENT INTENT\n    StripePaymentIntent: StripePaymentIntent;\n    StripePaymentIntents: Stripe.ApiList<StripePaymentIntent>;\n\n    // CHARGES\n    StripeCharge: StripeCharge;\n    StripeCharges: Stripe.ApiList<StripeCharge>;\n\n    // CONNECTED ACCOUNTS\n    StripeConnectedAccount: Stripe.Account;\n    StripeConnectedAccounts: Stripe.ApiList<Stripe.Account>;\n  };\n  Context: Context;\n}>({});\n\nbuilder.queryType();\nbuilder.mutationType();\n\nbuilder.addScalarType('JSON', GraphQLJSONObject, {});\n\nexport { builder };\n","import jwt from 'jsonwebtoken';\nimport Stripe from 'stripe';\n\nimport type { UserHasuraClaims } from './types';\n\nif (!process.env['STRIPE_SECRET_KEY']) {\n  throw new Error('STRIPE_SECRET_KEY env var is not set');\n}\n\nexport const stripe = new Stripe(process.env['STRIPE_SECRET_KEY'], {\n  apiVersion: '2022-11-15',\n});\n\nexport const getUserClaims = (req: Request): UserHasuraClaims | undefined => {\n  try {\n    const authorizationHeader = req.headers.get('authorization');\n\n    const accessToken = authorizationHeader?.split(' ')[1];\n\n    if (!accessToken) {\n      return undefined;\n    }\n\n    if (!process.env['NHOST_JWT_SECRET']) {\n      throw new Error('NHOST_JWT_SECRET env var is not set');\n    }\n\n    const jwtSecret = JSON.parse(process.env['NHOST_JWT_SECRET']);\n\n    // biome-ignore lint/suspicious/noExplicitAny: JWT decode returns unknown structure\n    const decodedToken = jwt.verify(accessToken, jwtSecret.key) as any;\n    return decodedToken['https://hasura.io/jwt/claims'] as UserHasuraClaims;\n  } catch (_error) {\n    return undefined;\n  }\n};\n","import './address';\nimport './customer';\nimport './customers';\nimport './customer-shipping';\nimport './customer-tax';\nimport './customer-tax-location';\nimport './payment-methods';\nimport './payment-method';\nimport './payment-method-billing-details';\nimport './payment-method-card';\nimport './payment-method-card-checks';\nimport './payment-method-card-networks';\nimport './payment-method-card-three-d-secure-usage';\nimport './payment-method-card-wallet-masterpass';\nimport './payment-method-card-wallet-visa-checkout';\nimport './payment-method-card-wallet';\nimport './stripe';\nimport './subscriptions';\nimport './subscription';\nimport './subscription-items';\nimport './subscription-item';\nimport './subscription-item-billing-thresholds';\nimport './subscription-automatic-tax';\nimport './subscription-billing-thresholds';\nimport './subscription-pause-collection';\nimport './invoices';\nimport './invoice';\nimport './invoice-automatic-tax';\nimport './invoice-custom-field';\nimport './invoice-customer-shipping';\nimport './invoice-customer-tax-id';\nimport './invoice-line-items';\nimport './invoice-line-item';\nimport './invoice-line-item-period';\nimport './invoice-line-item-tax-amount';\nimport './invoice-rendering-options';\nimport './invoice-status-transitions';\nimport './plan';\nimport './plan-transform-usage';\nimport './price';\nimport './product';\nimport './tax-rate';\nimport './test-clock';\nimport './billing-portal-session';\nimport './payment-intent';\nimport './payment-intents';\nimport './charges';\nimport './charge';\nimport './connectedAccount';\nimport './connectedAccounts';\n\nimport { builder } from '../builder';\n\nexport const schema = builder.toSchema();\n","import { createYoga, type YogaInitialContext } from 'graphql-yoga';\n\nimport { schema } from './schema';\nimport type { Context, CreateServerProps } from './types';\nimport { getUserClaims } from './utils';\n\nconst createStripeGraphQLServer = ({\n  cors,\n  isAllowed,\n  graphiql,\n  maskedErrors = true,\n}: CreateServerProps = {}) => {\n  const context = (context: YogaInitialContext): Context => {\n    const { request } = context;\n\n    // user id\n    const userClaims = getUserClaims(request);\n\n    // check if using correct `x-hasura-admin-secret` header\n    const adminSecretFromHeader = request.headers.get('x-hasura-admin-secret');\n    const adminSecret = process.env['NHOST_ADMIN_SECRET'];\n\n    // check if the request is from Hasura\n    const nhostWebhookSecretFromHeader = request.headers.get(\n      'x-nhost-webhook-secret',\n    );\n    const nhostWebhookSecret = process.env['NHOST_WEBHOOK_SECRET'];\n    const role = request.headers.get('x-hasura-role');\n\n    // variables\n    const isAdmin =\n      adminSecretFromHeader === adminSecret ||\n      (role === 'admin' && nhostWebhookSecretFromHeader === nhostWebhookSecret);\n\n    // if no isAllowed function is provided, we will allow admin requests\n    const isAllowedFunction =\n      isAllowed ||\n      ((_stripeCustomerId: string, context: Context) => {\n        return context.isAdmin;\n      });\n\n    // return\n    return {\n      ...context,\n      isAllowed: isAllowedFunction,\n      userClaims,\n      isAdmin,\n    };\n  };\n\n  const yoga = createYoga({\n    cors,\n    graphiql,\n    context,\n    schema,\n    graphqlEndpoint: '*',\n    maskedErrors,\n  });\n\n  return yoga;\n};\n\nexport { createStripeGraphQLServer, schema };\n"],"names":["builder","SchemaBuilder","queryType","mutationType","addScalarType","GraphQLJSONObject","process","env","Error","Stripe","apiVersion","schema","toSchema","cors","isAllowed","graphiql","maskedErrors","createYoga","context","request","userClaims","req","authorizationHeader","headers","get","accessToken","split","jwtSecret","JSON","parse","jwt","verify","key","_error","getUserClaims","adminSecretFromHeader","adminSecret","nhostWebhookSecretFromHeader","nhostWebhookSecret","role","isAdmin","isAllowedFunction","_stripeCustomerId","graphqlEndpoint"],"mappings":"qNAeMA,EAAU,IAAIC,EAsGjB,CAAA,GChHH,GDkHAD,EAAQE,YACRF,EAAQG,eAERH,EAAQI,cAAc,OAAQC,EAAAA,kBAAmB,KCrH5CC,QAAQC,IAAuB,kBAClC,MAAM,IAAIC,MAAM,wCAGI,IAAIC,EAAOH,QAAQC,IAAuB,kBAAG,CACjEG,WAAY,eAGP,MCwCMC,EAASX,EAAQY,+DC/CI,EAChCC,OACAC,YACAC,WACAC,gBAAe,GACM,KAuCRC,EAAAA,WAAW,CACtBJ,OACAE,WACAG,QAzCeA,IACf,MAAMC,QAAEA,GAAYD,EAGdE,EFHmB,CAACC,IAC5B,IACE,MAAMC,EAAsBD,EAAIE,QAAQC,IAAI,iBAEtCC,EAAcH,GAAqBI,MAAM,KAAK,GAEpD,IAAKD,EACH,OAGF,IAAKnB,QAAQC,IAAsB,iBACjC,MAAM,IAAIC,MAAM,uCAGlB,MAAMmB,EAAYC,KAAKC,MAAMvB,QAAQC,IAAsB,kBAI3D,OADqBuB,EAAIC,OAAON,EAAaE,EAAUK,KACnC,+BACtB,OAASC,GACP,MACF,GElBqBC,CAAcf,GAG3BgB,EAAwBhB,EAAQI,QAAQC,IAAI,yBAC5CY,EAAc9B,QAAQC,IAAwB,mBAG9C8B,EAA+BlB,EAAQI,QAAQC,IACnD,0BAEIc,EAAqBhC,QAAQC,IAA0B,qBACvDgC,EAAOpB,EAAQI,QAAQC,IAAI,iBAG3BgB,EACJL,IAA0BC,GAChB,UAATG,GAAoBF,IAAiCC,EAGlDG,EACJ3B,GAAA,EACE4B,EAA2BxB,IACpBA,EAAQsB,SAInB,MAAO,IACFtB,EACHJ,UAAW2B,EACXrB,aACAoB,YAQF7B,SACAgC,gBAAiB,IACjB3B"}