@nhost/stripe-graphql-js 1.3.0-beta7 → 1.3.1
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
//# sourceMappingURL=stripe-graphql-js.cjs.map
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=Object.create,r=Object.defineProperty,t=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,n=(n,i,l)=>(l=null!=n?e(s(n)):{},((e,s,n,i)=>{if(s&&"object"==typeof s||"function"==typeof s)for(var l,p=o(s),c=0,u=p.length;c<u;c++)l=p[c],a.call(e,l)||l===n||r(e,l,{get:(e=>s[e]).bind(null,l),enumerable:!(i=t(s,l))||i.enumerable});return e})(!i&&n&&n.__esModule?l:r(l,"default",{value:n,enumerable:!0}),n));let i=require("@pothos/core");i=n(i,1);let l=require("graphql-scalars"),p=require("jsonwebtoken");p=n(p,1);let c=require("stripe");c=n(c,1);let u=require("graphql-yoga");var E=new i.default({});if(E.queryType(),E.mutationType(),E.addScalarType("JSON",l.GraphQLJSONObject,{}),!process.env.STRIPE_SECRET_KEY)throw new Error("STRIPE_SECRET_KEY env var is not set");new c.default(process.env.STRIPE_SECRET_KEY,{apiVersion:"2022-11-15"});var h=E.toSchema();exports.builder=E,exports.createStripeGraphQLServer=({cors:e,isAllowed:r,graphiql:t,maskedErrors:o=!0}={})=>(0,u.createYoga)({cors:e,graphiql:t,context:e=>{const{request:t}=e,o=(e=>{try{const r=e.headers.get("authorization")?.split(" ")[1];if(!r)return;if(!process.env.NHOST_JWT_SECRET)throw new Error("NHOST_JWT_SECRET env var is not set");const t=JSON.parse(process.env.NHOST_JWT_SECRET);return p.default.verify(r,t.key)["https://hasura.io/jwt/claims"]}catch(r){return}})(t),s=t.headers.get("x-hasura-admin-secret"),a=process.env.NHOST_ADMIN_SECRET,n=t.headers.get("x-nhost-webhook-secret"),i=process.env.NHOST_WEBHOOK_SECRET,l=t.headers.get("x-hasura-role"),c=s===a||"admin"===l&&n===i,u=r||((e,r)=>r.isAdmin);return{...e,isAllowed:u,userClaims:o,isAdmin:c}},schema:h,graphqlEndpoint:"*",maskedErrors:o}),exports.schema=h;
|
|
2
|
+
//# sourceMappingURL=stripe-graphql-js.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"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"}
|
|
1
|
+
{"version":3,"file":"stripe-graphql-js.cjs","names":[],"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"],"mappings":"usBAeA,IAAM,EAAU,IAAI,EAAA,QAsGjB,CAAC,GChHJ,GDkHA,EAAQ,YACR,EAAQ,eAER,EAAQ,cAAc,OAAQ,EAAA,kBAAmB,CAAC,ICrH7C,QAAQ,IAAI,kBACf,MAAM,IAAI,MAAM,wCAGI,IAAI,EAAA,QAAO,QAAQ,IAAI,kBAAsB,CACjE,WAAY,eADd,IC4Ca,EAAS,EAAQ,+DC/CxB,EACJ,OACA,YACA,WACA,gBAAe,GACM,CAAC,KAgDtB,EAAA,EAAA,YATwB,CACtB,OACA,WACA,QAzCe,IACf,MAAM,QAAE,GAAY,EAGd,EFHG,CAAiB,IAC5B,IAGE,MAAM,EAFsB,EAAI,QAAQ,IAAI,kBAEH,MAAM,KAAK,GAEpD,IAAK,EACH,OAGF,IAAK,QAAQ,IAAI,iBACf,MAAM,IAAI,MAAM,uCAGlB,MAAM,EAAY,KAAK,MAAM,QAAQ,IAAI,kBAIzC,OADqB,EAAA,QAAI,OAAO,EAAa,EAAU,KACnC,+BACtB,CAAA,MAAS,GACP,MACF,GElBqB,CAAc,GAG3B,EAAwB,EAAQ,QAAQ,IAAI,yBAC5C,EAAc,QAAQ,IAAI,mBAG1B,EAA+B,EAAQ,QAAQ,IACnD,0BAEI,EAAqB,QAAQ,IAAI,qBACjC,EAAO,EAAQ,QAAQ,IAAI,iBAG3B,EACJ,IAA0B,GAChB,UAAT,GAAoB,IAAiC,EAGlD,EACJ,GAAA,EACE,EAA2B,IACpB,EAAQ,SAInB,MAAO,IACF,EACH,UAAW,EACX,aACA,YAQF,SACA,gBAAiB,IACjB"}
|
|
@@ -1,76 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { createYoga } from "graphql-yoga";
|
|
4
|
-
import jwt from "jsonwebtoken";
|
|
5
|
-
import Stripe from "stripe";
|
|
6
|
-
const builder = new SchemaBuilder({});
|
|
7
|
-
builder.queryType();
|
|
8
|
-
builder.mutationType();
|
|
9
|
-
builder.addScalarType("JSON", GraphQLJSONObject, {});
|
|
10
|
-
if (!process.env["STRIPE_SECRET_KEY"]) {
|
|
11
|
-
throw new Error("STRIPE_SECRET_KEY env var is not set");
|
|
12
|
-
}
|
|
13
|
-
new Stripe(process.env["STRIPE_SECRET_KEY"], {
|
|
14
|
-
apiVersion: "2022-11-15"
|
|
15
|
-
});
|
|
16
|
-
const getUserClaims = (req) => {
|
|
17
|
-
try {
|
|
18
|
-
const authorizationHeader = req.headers.get("authorization");
|
|
19
|
-
const accessToken = authorizationHeader?.split(" ")[1];
|
|
20
|
-
if (!accessToken) {
|
|
21
|
-
return void 0;
|
|
22
|
-
}
|
|
23
|
-
if (!process.env["NHOST_JWT_SECRET"]) {
|
|
24
|
-
throw new Error("NHOST_JWT_SECRET env var is not set");
|
|
25
|
-
}
|
|
26
|
-
const jwtSecret = JSON.parse(process.env["NHOST_JWT_SECRET"]);
|
|
27
|
-
const decodedToken = jwt.verify(accessToken, jwtSecret.key);
|
|
28
|
-
return decodedToken["https://hasura.io/jwt/claims"];
|
|
29
|
-
} catch (_error) {
|
|
30
|
-
return void 0;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const schema = builder.toSchema();
|
|
34
|
-
const createStripeGraphQLServer = ({
|
|
35
|
-
cors,
|
|
36
|
-
isAllowed,
|
|
37
|
-
graphiql,
|
|
38
|
-
maskedErrors = true
|
|
39
|
-
} = {}) => {
|
|
40
|
-
const context = (context2) => {
|
|
41
|
-
const { request } = context2;
|
|
42
|
-
const userClaims = getUserClaims(request);
|
|
43
|
-
const adminSecretFromHeader = request.headers.get("x-hasura-admin-secret");
|
|
44
|
-
const adminSecret = process.env["NHOST_ADMIN_SECRET"];
|
|
45
|
-
const nhostWebhookSecretFromHeader = request.headers.get(
|
|
46
|
-
"x-nhost-webhook-secret"
|
|
47
|
-
);
|
|
48
|
-
const nhostWebhookSecret = process.env["NHOST_WEBHOOK_SECRET"];
|
|
49
|
-
const role = request.headers.get("x-hasura-role");
|
|
50
|
-
const isAdmin = adminSecretFromHeader === adminSecret || role === "admin" && nhostWebhookSecretFromHeader === nhostWebhookSecret;
|
|
51
|
-
const isAllowedFunction = isAllowed || ((_stripeCustomerId, context3) => {
|
|
52
|
-
return context3.isAdmin;
|
|
53
|
-
});
|
|
54
|
-
return {
|
|
55
|
-
...context2,
|
|
56
|
-
isAllowed: isAllowedFunction,
|
|
57
|
-
userClaims,
|
|
58
|
-
isAdmin
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
const yoga = createYoga({
|
|
62
|
-
cors,
|
|
63
|
-
graphiql,
|
|
64
|
-
context,
|
|
65
|
-
schema,
|
|
66
|
-
graphqlEndpoint: "*",
|
|
67
|
-
maskedErrors
|
|
68
|
-
});
|
|
69
|
-
return yoga;
|
|
70
|
-
};
|
|
71
|
-
export {
|
|
72
|
-
builder,
|
|
73
|
-
createStripeGraphQLServer,
|
|
74
|
-
schema
|
|
75
|
-
};
|
|
76
|
-
//# sourceMappingURL=stripe-graphql-js.js.map
|
|
1
|
+
import r from"@pothos/core";import{GraphQLJSONObject as e}from"graphql-scalars";import s from"jsonwebtoken";import o from"stripe";import{createYoga as t}from"graphql-yoga";var a=new r({});if(a.queryType(),a.mutationType(),a.addScalarType("JSON",e,{}),!process.env.STRIPE_SECRET_KEY)throw new Error("STRIPE_SECRET_KEY env var is not set");new o(process.env.STRIPE_SECRET_KEY,{apiVersion:"2022-11-15"});var n=a.toSchema(),i=({cors:r,isAllowed:e,graphiql:o,maskedErrors:a=!0}={})=>t({cors:r,graphiql:o,context:r=>{const{request:o}=r,t=(r=>{try{const e=r.headers.get("authorization")?.split(" ")[1];if(!e)return;if(!process.env.NHOST_JWT_SECRET)throw new Error("NHOST_JWT_SECRET env var is not set");const o=JSON.parse(process.env.NHOST_JWT_SECRET);return s.verify(e,o.key)["https://hasura.io/jwt/claims"]}catch(e){return}})(o),a=o.headers.get("x-hasura-admin-secret"),n=process.env.NHOST_ADMIN_SECRET,i=o.headers.get("x-nhost-webhook-secret"),E=process.env.NHOST_WEBHOOK_SECRET,p=o.headers.get("x-hasura-role"),c=a===n||"admin"===p&&i===E,h=e||((r,e)=>e.isAdmin);return{...r,isAllowed:h,userClaims:t,isAdmin:c}},schema:n,graphqlEndpoint:"*",maskedErrors:a});export{a as builder,i as createStripeGraphQLServer,n as schema};
|
|
2
|
+
//# sourceMappingURL=stripe-graphql-js.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe-graphql-js.js","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":["context"],"mappings":";;;;;AAeA,MAAM,UAAU,IAAI,cAsGjB,CAAA,CAAE;AAEL,QAAQ,UAAA;AACR,QAAQ,aAAA;AAER,QAAQ,cAAc,QAAQ,mBAAmB,EAAE;ACrHnD,IAAI,CAAC,QAAQ,IAAI,mBAAmB,GAAG;AACrC,QAAM,IAAI,MAAM,sCAAsC;AACxD;AAEsB,IAAI,OAAO,QAAQ,IAAI,mBAAmB,GAAG;AAAA,EACjE,YAAY;AACd,CAAC;AAEM,MAAM,gBAAgB,CAAC,QAA+C;AAC3E,MAAI;AACF,UAAM,sBAAsB,IAAI,QAAQ,IAAI,eAAe;AAE3D,UAAM,cAAc,qBAAqB,MAAM,GAAG,EAAE,CAAC;AAErD,QAAI,CAAC,aAAa;AAChB,aAAO;AAAA,IACT;AAEA,QAAI,CAAC,QAAQ,IAAI,kBAAkB,GAAG;AACpC,YAAM,IAAI,MAAM,qCAAqC;AAAA,IACvD;AAEA,UAAM,YAAY,KAAK,MAAM,QAAQ,IAAI,kBAAkB,CAAC;AAG5D,UAAM,eAAe,IAAI,OAAO,aAAa,UAAU,GAAG;AAC1D,WAAO,aAAa,8BAA8B;AAAA,EACpD,SAAS,QAAQ;AACf,WAAO;AAAA,EACT;AACF;ACkBO,MAAM,SAAS,QAAQ,SAAA;AC/C9B,MAAM,4BAA4B,CAAC;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AACjB,IAAuB,OAAO;AAC5B,QAAM,UAAU,CAACA,aAAyC;AACxD,UAAM,EAAE,YAAYA;AAGpB,UAAM,aAAa,cAAc,OAAO;AAGxC,UAAM,wBAAwB,QAAQ,QAAQ,IAAI,uBAAuB;AACzE,UAAM,cAAc,QAAQ,IAAI,oBAAoB;AAGpD,UAAM,+BAA+B,QAAQ,QAAQ;AAAA,MACnD;AAAA,IAAA;AAEF,UAAM,qBAAqB,QAAQ,IAAI,sBAAsB;AAC7D,UAAM,OAAO,QAAQ,QAAQ,IAAI,eAAe;AAGhD,UAAM,UACJ,0BAA0B,eACzB,SAAS,WAAW,iCAAiC;AAGxD,UAAM,oBACJ,cACC,CAAC,mBAA2BA,aAAqB;AAChD,aAAOA,SAAQ;AAAA,IACjB;AAGF,WAAO;AAAA,MACL,GAAGA;AAAAA,MACH,WAAW;AAAA,MACX;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AAEA,QAAM,OAAO,WAAW;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,iBAAiB;AAAA,IACjB;AAAA,EAAA,CACD;AAED,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"stripe-graphql-js.js","names":[],"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"],"mappings":"4KAeA,IAAM,EAAU,IAAI,EAsGjB,CAAC,GChHJ,GDkHA,EAAQ,YACR,EAAQ,eAER,EAAQ,cAAc,OAAQ,EAAmB,CAAC,ICrH7C,QAAQ,IAAI,kBACf,MAAM,IAAI,MAAM,wCAGI,IAAI,EAAO,QAAQ,IAAI,kBAAsB,CACjE,WAAY,eADd,IC4Ca,EAAS,EAAQ,WC/CxB,EAAA,EACJ,OACA,YACA,WACA,gBAAe,GACM,CAAC,IAuCT,EAAW,CACtB,OACA,WACA,QAzCe,IACf,MAAM,QAAE,GAAY,EAGd,EFHG,CAAiB,IAC5B,IAGE,MAAM,EAFsB,EAAI,QAAQ,IAAI,kBAEH,MAAM,KAAK,GAEpD,IAAK,EACH,OAGF,IAAK,QAAQ,IAAI,iBACf,MAAM,IAAI,MAAM,uCAGlB,MAAM,EAAY,KAAK,MAAM,QAAQ,IAAI,kBAIzC,OADqB,EAAI,OAAO,EAAa,EAAU,KACnC,+BACtB,CAAA,MAAS,GACP,MACF,GElBqB,CAAc,GAG3B,EAAwB,EAAQ,QAAQ,IAAI,yBAC5C,EAAc,QAAQ,IAAI,mBAG1B,EAA+B,EAAQ,QAAQ,IACnD,0BAEI,EAAqB,QAAQ,IAAI,qBACjC,EAAO,EAAQ,QAAQ,IAAI,iBAG3B,EACJ,IAA0B,GAChB,UAAT,GAAoB,IAAiC,EAGlD,EACJ,GAAA,EACE,EAA2B,IACpB,EAAQ,SAInB,MAAO,IACF,EACH,UAAW,EACX,aACA,YAQF,SACA,gBAAiB,IACjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nhost/stripe-graphql-js",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Stripe GraphQL API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/stripe-graphql-js.cjs",
|
|
@@ -36,21 +36,20 @@
|
|
|
36
36
|
},
|
|
37
37
|
"sideEffects": false,
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@pothos/core": "^3.41.
|
|
39
|
+
"@pothos/core": "^3.41.2",
|
|
40
40
|
"graphql": "16.8.1",
|
|
41
|
-
"graphql-scalars": "^1.
|
|
41
|
+
"graphql-scalars": "^1.25.0",
|
|
42
42
|
"graphql-yoga": "^5.16.0",
|
|
43
43
|
"jsonwebtoken": "^9.0.3",
|
|
44
44
|
"stripe": "^11.18.0",
|
|
45
45
|
"tslib": "^2.8.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/node": "^20.14.8",
|
|
48
|
+
"@types/jsonwebtoken": "^9.0.10",
|
|
49
|
+
"@types/node": "^20.19.24",
|
|
51
50
|
"rollup": "^4.59.0",
|
|
52
51
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
53
|
-
"terser": "^5.
|
|
52
|
+
"terser": "^5.46.0",
|
|
54
53
|
"typescript": "^5.8.3"
|
|
55
54
|
},
|
|
56
55
|
"scripts": {
|