@nhost/stripe-graphql-js 0.0.8 → 1.0.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.
- package/README.md +4 -174
- package/dist/schema/stripe.js +6 -6
- package/dist/schema/stripe.js.map +1 -1
- package/dist/server.d.ts +2 -5
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +6 -3
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<h1 align="center"
|
|
2
|
-
<h2 align="center"
|
|
1
|
+
<h1 align="center">Stripe GraphQL API</h1>
|
|
2
|
+
<h2 align="center">@nhost/stripe-graphql-js</h2>
|
|
3
3
|
|
|
4
4
|
<p align="center">
|
|
5
5
|
<img alt="npm" src="https://img.shields.io/npm/v/@nhost/stripe-graphql-js">
|
|
@@ -9,179 +9,9 @@
|
|
|
9
9
|
</a>
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## Documentation
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
query {
|
|
16
|
-
stripe {
|
|
17
|
-
customer(id: "cus_xxx" {
|
|
18
|
-
id
|
|
19
|
-
name
|
|
20
|
-
invoices {
|
|
21
|
-
data {
|
|
22
|
-
id
|
|
23
|
-
created
|
|
24
|
-
paid
|
|
25
|
-
hostedInvoiceUrl
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
You can also add the Stripe GraphQL API as a Hasura Remote Schema and connect data from your database and Stripe. This allows you to request data from your database and Stripe in a single GraphQL query:
|
|
34
|
-
|
|
35
|
-
```graphql
|
|
36
|
-
query {
|
|
37
|
-
users {
|
|
38
|
-
# User in your database
|
|
39
|
-
id
|
|
40
|
-
displayName
|
|
41
|
-
userData {
|
|
42
|
-
stripeCustomerId # Customer's Stripe Customer Id
|
|
43
|
-
stripeCustomer {
|
|
44
|
-
# Data from Stripe
|
|
45
|
-
id
|
|
46
|
-
name
|
|
47
|
-
paymentMethods {
|
|
48
|
-
id
|
|
49
|
-
card {
|
|
50
|
-
brand
|
|
51
|
-
last4
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
## Install
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
npm install @nhost/stripe-graphql-js
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Quick Start
|
|
67
|
-
|
|
68
|
-
### Serverless Function Setup
|
|
69
|
-
|
|
70
|
-
Create a new [Serverless Function](https://docs.nhost.io/platform/serverless-functions) `functions/graphql/stripe.ts`:
|
|
71
|
-
|
|
72
|
-
```js
|
|
73
|
-
import { createStripeGraphQLServer } from '@nhost/stripe-graphql-js'
|
|
74
|
-
|
|
75
|
-
const server = createStripeGraphQLServer()
|
|
76
|
-
|
|
77
|
-
export default server
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
> You can run the Stripe GraphQL API in any JS environment because it's built using [GraphQL Yoga](https://github.com/dotansimha/graphql-yoga).
|
|
81
|
-
|
|
82
|
-
### Stripe Secret Key
|
|
83
|
-
|
|
84
|
-
Add `STRIPE_SECRET_KEY` as an environment variable. If you're using Nhost, add `STRIPE_SECRET_KEY` to `.env.development` like this:
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
STRIPE_SECRET_KEY=sk_test_xxx
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
Learn more about [Stripe API keys](https://stripe.com/docs/keys#obtain-api-keys).
|
|
91
|
-
|
|
92
|
-
### Start Nhost
|
|
93
|
-
|
|
94
|
-
```
|
|
95
|
-
nhost up
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
Learn more about the [Nhost CLI](https://docs.nhost.io/platform/cli).
|
|
99
|
-
|
|
100
|
-
### Test
|
|
101
|
-
|
|
102
|
-
Test the Stripe GraphQL API in the browser:
|
|
103
|
-
|
|
104
|
-
[http://localhost:1337/v1/functions/graphql/stripe](http://localhost:1337/v1/functions/graphql/stripe)
|
|
105
|
-
|
|
106
|
-
### Remote Schema
|
|
107
|
-
|
|
108
|
-
Add the Stripe GraphQL API as a Remote Schema in Hasura.
|
|
109
|
-
|
|
110
|
-
**URL**
|
|
111
|
-
|
|
112
|
-
```
|
|
113
|
-
{{NHOST_BACKEND_URL}}/v1/functions/graphql/stripe
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
**Headers**
|
|
117
|
-
|
|
118
|
-
```
|
|
119
|
-
x-nhost-webhook-secret: NHOST_WEBHOOK_SECRET (from env var)
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-

|
|
123
|
-
|
|
124
|
-
## Permissions
|
|
125
|
-
|
|
126
|
-
Here's a minimal example without any custom permissions. Only requests using the `x-hasura-admin-secret` header will work:
|
|
127
|
-
|
|
128
|
-
```js
|
|
129
|
-
const server = createStripeGraphQLServer()
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
For more granular permissions, you can pass an `isAllowed` function to the `createStripeGraphQLServer`. The `isAllowed` function takes a `stripeCustomerId` and [`context`](#context) as parameters and runs every time the GraphQL server makes a request to Stripe to get or modify data for a specific Stripe customer.
|
|
133
|
-
|
|
134
|
-
Here is an example of an `isAllowed` function:
|
|
135
|
-
|
|
136
|
-
```js
|
|
137
|
-
|
|
138
|
-
const isAllowed = (stripeCustomerId: string, context: Context) => {
|
|
139
|
-
const { isAdmin, userClaims } = context
|
|
140
|
-
|
|
141
|
-
// allow requests if it has a valid `x-hasura-admin-secret`
|
|
142
|
-
if (isAdmin) {
|
|
143
|
-
return true
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// get user id
|
|
147
|
-
const userId = userClaims['x-hasura-user-id']
|
|
148
|
-
|
|
149
|
-
// check if user is signed in
|
|
150
|
-
if (!userId) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// get more user information from the database
|
|
155
|
-
const { user } = await gqlSDK.getUser({
|
|
156
|
-
id: userId,
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
if (!user) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// check if the user is part of a workspace with the `stripeCustomerId`
|
|
164
|
-
return user.workspaceMembers
|
|
165
|
-
.some((workspaceMember) => {
|
|
166
|
-
return workspaceMember.workspace.stripeCustomerId === stripeCustomerId;
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Context
|
|
173
|
-
|
|
174
|
-
The `context` object contains:
|
|
175
|
-
|
|
176
|
-
- `userClaims` - verified JWT claims from the user's access token.
|
|
177
|
-
- `isAdmin` - `true` if the request was made using a valid `x-hasura-admin-secret` header.
|
|
178
|
-
- `request` - [Fetch API Request object](https://developer.mozilla.org/en-US/docs/Web/API/Request) that represents the incoming HTTP request in platform-independent way. It can be useful for accessing headers to authenticate a user
|
|
179
|
-
- `query` - the DocumentNode that was parsed from the GraphQL query string
|
|
180
|
-
- `operationName` - the operation name selected from the incoming query
|
|
181
|
-
- `variables` - the variables that were defined in the query
|
|
182
|
-
- `extensions` - the extensions that were received from the client
|
|
183
|
-
|
|
184
|
-
Read more about the [default context from GraphQL Yoga](https://www.the-guild.dev/graphql/yoga-server/docs/features/context#default-context).
|
|
14
|
+
[https://docs.nhost.io/graphql/remote-schemas/stripe](https://docs.nhost.io/graphql/remote-schemas/stripe).
|
|
185
15
|
|
|
186
16
|
## Development
|
|
187
17
|
|
package/dist/schema/stripe.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const
|
|
12
|
+
const graphql_1 = require("graphql");
|
|
13
13
|
const builder_1 = require("../builder");
|
|
14
14
|
const utils_1 = require("../utils");
|
|
15
15
|
builder_1.builder.objectType('Stripe', {
|
|
@@ -19,7 +19,7 @@ builder_1.builder.objectType('Stripe', {
|
|
|
19
19
|
resolve: (_parent, _, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
20
|
const { isAdmin } = context;
|
|
21
21
|
if (!isAdmin)
|
|
22
|
-
throw new
|
|
22
|
+
throw new graphql_1.GraphQLError('Not allowed');
|
|
23
23
|
const connectedAccounts = yield utils_1.stripe.accounts.list();
|
|
24
24
|
return connectedAccounts;
|
|
25
25
|
})
|
|
@@ -34,7 +34,7 @@ builder_1.builder.objectType('Stripe', {
|
|
|
34
34
|
resolve: (_parent, { id }, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
const { isAdmin } = context;
|
|
36
36
|
if (!isAdmin)
|
|
37
|
-
throw new
|
|
37
|
+
throw new graphql_1.GraphQLError('Not allowed');
|
|
38
38
|
const connectedAccount = yield utils_1.stripe.accounts.retrieve(id);
|
|
39
39
|
return connectedAccount;
|
|
40
40
|
})
|
|
@@ -49,11 +49,11 @@ builder_1.builder.objectType('Stripe', {
|
|
|
49
49
|
resolve: (_parent, { id }, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
50
|
const { isAllowed } = context;
|
|
51
51
|
if (!(yield isAllowed(id, context))) {
|
|
52
|
-
throw new
|
|
52
|
+
throw new graphql_1.GraphQLError('Not allowed');
|
|
53
53
|
}
|
|
54
54
|
const customer = yield utils_1.stripe.customers.retrieve(id);
|
|
55
55
|
if (customer.deleted) {
|
|
56
|
-
throw new
|
|
56
|
+
throw new graphql_1.GraphQLError('The Stripe customer is deleted');
|
|
57
57
|
}
|
|
58
58
|
return customer;
|
|
59
59
|
})
|
|
@@ -119,7 +119,7 @@ builder_1.builder.objectType('StripeMutations', {
|
|
|
119
119
|
resolve: (_, { customer, configuration, locale, returnUrl }, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
120
120
|
const { isAllowed } = context;
|
|
121
121
|
if (!(yield isAllowed(customer, context))) {
|
|
122
|
-
throw new
|
|
122
|
+
throw new graphql_1.GraphQLError('Not allowed');
|
|
123
123
|
}
|
|
124
124
|
const session = yield utils_1.stripe.billingPortal.sessions.create({
|
|
125
125
|
customer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../src/schema/stripe.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,
|
|
1
|
+
{"version":3,"file":"stripe.js","sourceRoot":"","sources":["../../src/schema/stripe.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA,qCAAsC;AAEtC,wCAAoC;AACpC,oCAAiC;AAEjC,iBAAO,CAAC,UAAU,CAAC,QAAQ,EAAE;IAC3B,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACd,iBAAiB,EAAE,CAAC,CAAC,KAAK,CAAC;YACzB,IAAI,EAAE,yBAAyB;YAC/B,OAAO,EAAE,CAAO,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE;gBACrC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;gBAE3B,IAAI,CAAC,OAAO;oBAAE,MAAM,IAAI,sBAAY,CAAC,aAAa,CAAC,CAAA;gBAEnD,MAAM,iBAAiB,GAAG,MAAM,cAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;gBAEtD,OAAO,iBAAiB,CAAA;YAC1B,CAAC,CAAA;SACF,CAAC;QACF,gBAAgB,EAAE,CAAC,CAAC,KAAK,CAAC;YACxB,IAAI,EAAE,wBAAwB;YAC9B,IAAI,EAAE;gBACJ,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;oBACf,QAAQ,EAAE,IAAI;iBACf,CAAC;aACH;YACD,OAA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OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;KACpB,CAAC;CACH,CAAC,CAAC,CAAA;AAEH,iBAAO,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC7B,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC;QACd,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;KACpB,CAAC;CACH,CAAC,CAAC,CAAA"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { schema } from './schema';
|
|
3
|
-
import {
|
|
4
|
-
declare const createStripeGraphQLServer: (params?: CreateServerProps) => import("
|
|
5
|
-
req: import("http").IncomingMessage;
|
|
6
|
-
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
7
|
-
}, Context, {}>;
|
|
3
|
+
import { CreateServerProps } from './types';
|
|
4
|
+
declare const createStripeGraphQLServer: (params?: CreateServerProps) => import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
|
|
8
5
|
export { createStripeGraphQLServer, schema };
|
|
9
6
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAW,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAGpD,QAAA,MAAM,yBAAyB,YAAa,iBAAiB,uGAkD5D,CAAA;AAED,OAAO,EAAE,yBAAyB,EAAE,MAAM,EAAE,CAAA"}
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.schema = exports.createStripeGraphQLServer = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_http_1 = require("node:http");
|
|
5
|
+
const graphql_yoga_1 = require("graphql-yoga");
|
|
5
6
|
const schema_1 = require("./schema");
|
|
6
7
|
Object.defineProperty(exports, "schema", { enumerable: true, get: function () { return schema_1.schema; } });
|
|
7
8
|
const utils_1 = require("./utils");
|
|
@@ -32,12 +33,14 @@ const createStripeGraphQLServer = (params) => {
|
|
|
32
33
|
return Object.assign(Object.assign({}, context), { isAllowed: isAllowedFunction, userClaims,
|
|
33
34
|
isAdmin });
|
|
34
35
|
};
|
|
35
|
-
|
|
36
|
+
const yoga = (0, graphql_yoga_1.createYoga)({
|
|
36
37
|
cors,
|
|
37
38
|
graphiql,
|
|
38
39
|
context,
|
|
39
|
-
schema: schema_1.schema
|
|
40
|
+
schema: schema_1.schema,
|
|
41
|
+
graphqlEndpoint: '*'
|
|
40
42
|
});
|
|
43
|
+
return (0, node_http_1.createServer)(yoga);
|
|
41
44
|
};
|
|
42
45
|
exports.createStripeGraphQLServer = createStripeGraphQLServer;
|
|
43
46
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AACxC,+CAA6D;AAE7D,qCAAiC;AAwDG,uFAxD3B,eAAM,OAwD2B;AAtD1C,mCAAuC;AAEvC,MAAM,yBAAyB,GAAG,CAAC,MAA0B,EAAE,EAAE;IAC/D,MAAM,IAAI,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAA;IACzB,MAAM,SAAS,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAA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AC,CAAA;AAC3B,CAAC,CAAA;AAEQ,8DAAyB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type Stripe from 'stripe';
|
|
2
|
-
import type { CORSOptions, YogaInitialContext } from '
|
|
2
|
+
import type { CORSOptions, YogaInitialContext } from 'graphql-yoga';
|
|
3
3
|
export declare type StripeGraphQLContext = {
|
|
4
4
|
isAllowed: (stripeCustomerId: string, context: Context) => boolean | Promise<boolean>;
|
|
5
5
|
userClaims?: UserHasuraClaims;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAEhC,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAA;AAEhC,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEnE,oBAAY,oBAAoB,GAAG;IACjC,SAAS,EAAE,CAAC,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACrF,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,oBAAY,OAAO,GAAG,kBAAkB,GAAG,oBAAoB,CAAA;AAE/D,oBAAY,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,WAAW,CAAA;IAClB,SAAS,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACtF,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAID,oBAAY,mBAAmB,GAAG,MAAM,CAAC,aAAa,GAAG;IACvD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB,CAAA;AAED,oBAAY,kBAAkB,GAAG,MAAM,CAAC,YAAY,GAAG;IACrD,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B,CAAA;AAED,oBAAY,aAAa,GAAG,MAAM,CAAC,OAAO,GAAG;IAC3C,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,sBAAsB,EAAE,mBAAmB,GAAG,IAAI,CAAA;IAClD,cAAc,EAAE,GAAG,CAAA;CACpB,CAAA;AAED,oBAAY,mBAAmB,GAAG,MAAM,CAAC,aAAa,GAAG;IACvD,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,GAAG;IACzC,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B,CAAA;AAED,oBAAY,gBAAgB,GAAG;IAC7B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,uBAAuB,EAAE,MAAM,CAAA;IAC/B,wBAAwB,EAAE,MAAM,EAAE,CAAA;CACnC,GAAG;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB,CAAA"}
|
package/dist/utils.js
CHANGED
|
@@ -10,7 +10,7 @@ if (!process.env.STRIPE_SECRET_KEY) {
|
|
|
10
10
|
throw new Error('STRIPE_SECRET_KEY env var is not set');
|
|
11
11
|
}
|
|
12
12
|
exports.stripe = new stripe_1.default(process.env.STRIPE_SECRET_KEY, {
|
|
13
|
-
apiVersion: '2022-
|
|
13
|
+
apiVersion: '2022-11-15'
|
|
14
14
|
});
|
|
15
15
|
const getUserClaims = (req) => {
|
|
16
16
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nhost/stripe-graphql-js",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Stripe GraphQL API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -28,19 +28,19 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@graphql-yoga/node": "^2.13.13",
|
|
32
31
|
"@pothos/core": "^3.21.0",
|
|
33
32
|
"graphql": "16.6.0",
|
|
34
33
|
"graphql-scalars": "^1.18.0",
|
|
34
|
+
"graphql-yoga": "^3.4.0",
|
|
35
35
|
"jsonwebtoken": "^9.0.0",
|
|
36
|
-
"stripe": "^
|
|
36
|
+
"stripe": "^11.8.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/jsonwebtoken": "^9.0.0",
|
|
40
40
|
"@types/node": "^18.11.9",
|
|
41
41
|
"dotenv": "^16.0.3",
|
|
42
42
|
"ts-node-dev": "^2.0.0",
|
|
43
|
-
"typescript": "^4.
|
|
43
|
+
"typescript": "^4.7.4"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"dev": "NODE_ENV=development ts-node-dev -r dotenv/config dev/server.ts",
|