@stripe-sdk/core 1.0.0 → 1.0.2
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 +88 -261
- package/dist/client/index.d.mts +0 -4
- package/dist/client/index.d.ts +0 -4
- package/dist/client/index.js +70 -11
- package/dist/client/index.mjs +71 -12
- package/dist/{index-D8rM_YD4.d.mts → index-BKDJf1Hz.d.mts} +1 -27
- package/dist/{index-D8rM_YD4.d.ts → index-BKDJf1Hz.d.ts} +1 -27
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +601 -231
- package/dist/index.mjs +602 -232
- package/dist/next/index.d.mts +55 -32
- package/dist/next/index.d.ts +55 -32
- package/dist/next/index.js +362 -143
- package/dist/next/index.mjs +362 -143
- package/dist/server/index.d.mts +61 -21
- package/dist/server/index.d.ts +61 -21
- package/dist/server/index.js +546 -237
- package/dist/server/index.mjs +546 -237
- package/dist/server/webhooks/index.d.mts +1 -1
- package/dist/server/webhooks/index.d.ts +1 -1
- package/dist/server/webhooks/index.js +19 -7
- package/dist/server/webhooks/index.mjs +19 -7
- package/package.json +8 -5
- package/dist/client/index.js.map +0 -1
- package/dist/client/index.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/next/index.js.map +0 -1
- package/dist/next/index.mjs.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/index.mjs.map +0 -1
- package/dist/server/webhooks/index.js.map +0 -1
- package/dist/server/webhooks/index.mjs.map +0 -1
package/dist/next/index.d.mts
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
|
-
import { i as CreatePaymentIntentInput, t as SDKResult, c as CreateCheckoutSessionInput, p as CreateSetupIntentInput, f as CreateCustomerInput, k as CreatePortalSessionInput, q as CreateSubscriptionInput, C as CancelSubscriptionInput } from '../index-
|
|
2
|
-
export { A as createNextWebhookHandler, B as createPagesWebhookHandler } from '../index-
|
|
1
|
+
import { i as CreatePaymentIntentInput, t as SDKResult, c as CreateCheckoutSessionInput, p as CreateSetupIntentInput, f as CreateCustomerInput, k as CreatePortalSessionInput, q as CreateSubscriptionInput, C as CancelSubscriptionInput } from '../index-BKDJf1Hz.mjs';
|
|
2
|
+
export { A as createNextWebhookHandler, B as createPagesWebhookHandler } from '../index-BKDJf1Hz.mjs';
|
|
3
3
|
import * as Stripe from 'stripe';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Authorization callback type.
|
|
7
|
+
* Must return true if the request is authorized, or throw an error / return false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
type AuthorizeFn = (request: Request) => Promise<boolean | void>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates authorized server actions for Next.js App Router.
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT: You MUST provide an `authorize` callback that verifies
|
|
14
|
+
* the current user's session/identity before any Stripe operation.
|
|
7
15
|
*
|
|
8
|
-
* Usage in a
|
|
16
|
+
* Usage in a `use server` file:
|
|
9
17
|
* ```ts
|
|
10
18
|
* 'use server';
|
|
11
|
-
* import {
|
|
19
|
+
* import { createActions } from '@stripe-sdk/core/next';
|
|
20
|
+
* import { getServerSession } from 'next-auth';
|
|
12
21
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
22
|
+
* const actions = createActions({
|
|
23
|
+
* authorize: async () => {
|
|
24
|
+
* const session = await getServerSession();
|
|
25
|
+
* if (!session) throw new Error('Unauthorized');
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* export const createPayment = actions.createPaymentIntent;
|
|
18
30
|
* ```
|
|
19
31
|
*/
|
|
20
|
-
declare
|
|
32
|
+
declare function createActions(config: {
|
|
33
|
+
authorize: () => Promise<boolean | void>;
|
|
34
|
+
}): {
|
|
21
35
|
createPaymentIntent: (input: CreatePaymentIntentInput) => Promise<SDKResult<Stripe.Stripe.PaymentIntent>>;
|
|
22
36
|
createCheckoutSession: (input: CreateCheckoutSessionInput) => Promise<SDKResult<Stripe.Stripe.Checkout.Session>>;
|
|
23
37
|
createSetupIntent: (input: CreateSetupIntentInput) => Promise<SDKResult<Stripe.Stripe.SetupIntent>>;
|
|
@@ -27,39 +41,48 @@ declare const actions: {
|
|
|
27
41
|
cancelSubscription: (input: CancelSubscriptionInput) => Promise<SDKResult<Stripe.Stripe.Subscription>>;
|
|
28
42
|
resumeSubscription: (subscriptionId: string) => Promise<SDKResult<Stripe.Stripe.Subscription>>;
|
|
29
43
|
};
|
|
44
|
+
interface RouteOptions<TInput> {
|
|
45
|
+
/**
|
|
46
|
+
* REQUIRED: Authorization callback. Must verify the user's identity.
|
|
47
|
+
* Throw an error or return false to reject the request.
|
|
48
|
+
*/
|
|
49
|
+
authorize: AuthorizeFn;
|
|
50
|
+
/**
|
|
51
|
+
* Optional hook to transform/validate input before creating the resource.
|
|
52
|
+
*/
|
|
53
|
+
beforeCreate?: (input: TInput, request: Request) => Promise<TInput>;
|
|
54
|
+
}
|
|
30
55
|
/**
|
|
31
56
|
* Creates a Next.js API route handler for creating payment intents.
|
|
57
|
+
* Requires an `authorize` callback for authentication.
|
|
32
58
|
*
|
|
33
59
|
* Usage in app/api/create-payment-intent/route.ts:
|
|
34
60
|
* ```ts
|
|
35
61
|
* import { createPaymentIntentRoute } from '@stripe-sdk/core/next';
|
|
36
|
-
*
|
|
62
|
+
* import { getServerSession } from 'next-auth';
|
|
63
|
+
*
|
|
64
|
+
* export const POST = createPaymentIntentRoute({
|
|
65
|
+
* authorize: async (request) => {
|
|
66
|
+
* const session = await getServerSession();
|
|
67
|
+
* if (!session) throw new Error('Unauthorized');
|
|
68
|
+
* },
|
|
69
|
+
* beforeCreate: async (input) => ({
|
|
70
|
+
* ...input,
|
|
71
|
+
* amount: getVerifiedAmount(input),
|
|
72
|
+
* }),
|
|
73
|
+
* });
|
|
37
74
|
* ```
|
|
38
75
|
*/
|
|
39
|
-
declare function createPaymentIntentRoute(options
|
|
40
|
-
beforeCreate?: (input: CreatePaymentIntentInput, request: Request) => Promise<CreatePaymentIntentInput>;
|
|
41
|
-
}): (request: Request) => Promise<Response>;
|
|
76
|
+
declare function createPaymentIntentRoute(options: RouteOptions<CreatePaymentIntentInput>): (request: Request) => Promise<Response>;
|
|
42
77
|
/**
|
|
43
78
|
* Creates a Next.js API route handler for creating checkout sessions.
|
|
44
|
-
*
|
|
45
|
-
* Usage in app/api/create-checkout-session/route.ts:
|
|
46
|
-
* ```ts
|
|
47
|
-
* import { createCheckoutSessionRoute } from '@stripe-sdk/core/next';
|
|
48
|
-
* export const POST = createCheckoutSessionRoute();
|
|
49
|
-
* ```
|
|
79
|
+
* Requires an `authorize` callback for authentication.
|
|
50
80
|
*/
|
|
51
|
-
declare function createCheckoutSessionRoute(options
|
|
52
|
-
beforeCreate?: (input: CreateCheckoutSessionInput, request: Request) => Promise<CreateCheckoutSessionInput>;
|
|
53
|
-
}): (request: Request) => Promise<Response>;
|
|
81
|
+
declare function createCheckoutSessionRoute(options: RouteOptions<CreateCheckoutSessionInput>): (request: Request) => Promise<Response>;
|
|
54
82
|
/**
|
|
55
83
|
* Creates a Next.js API route handler for creating portal sessions.
|
|
56
|
-
*
|
|
57
|
-
* Usage in app/api/create-portal-session/route.ts:
|
|
58
|
-
* ```ts
|
|
59
|
-
* import { createPortalSessionRoute } from '@stripe-sdk/core/next';
|
|
60
|
-
* export const POST = createPortalSessionRoute();
|
|
61
|
-
* ```
|
|
84
|
+
* Requires an `authorize` callback for authentication.
|
|
62
85
|
*/
|
|
63
|
-
declare function createPortalSessionRoute(): (request: Request) => Promise<Response>;
|
|
86
|
+
declare function createPortalSessionRoute(options: RouteOptions<CreatePortalSessionInput>): (request: Request) => Promise<Response>;
|
|
64
87
|
|
|
65
|
-
export {
|
|
88
|
+
export { type AuthorizeFn, createActions, createCheckoutSessionRoute, createPaymentIntentRoute, createPortalSessionRoute };
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,23 +1,37 @@
|
|
|
1
|
-
import { i as CreatePaymentIntentInput, t as SDKResult, c as CreateCheckoutSessionInput, p as CreateSetupIntentInput, f as CreateCustomerInput, k as CreatePortalSessionInput, q as CreateSubscriptionInput, C as CancelSubscriptionInput } from '../index-
|
|
2
|
-
export { A as createNextWebhookHandler, B as createPagesWebhookHandler } from '../index-
|
|
1
|
+
import { i as CreatePaymentIntentInput, t as SDKResult, c as CreateCheckoutSessionInput, p as CreateSetupIntentInput, f as CreateCustomerInput, k as CreatePortalSessionInput, q as CreateSubscriptionInput, C as CancelSubscriptionInput } from '../index-BKDJf1Hz.js';
|
|
2
|
+
export { A as createNextWebhookHandler, B as createPagesWebhookHandler } from '../index-BKDJf1Hz.js';
|
|
3
3
|
import * as Stripe from 'stripe';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Authorization callback type.
|
|
7
|
+
* Must return true if the request is authorized, or throw an error / return false otherwise.
|
|
8
|
+
*/
|
|
9
|
+
type AuthorizeFn = (request: Request) => Promise<boolean | void>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates authorized server actions for Next.js App Router.
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT: You MUST provide an `authorize` callback that verifies
|
|
14
|
+
* the current user's session/identity before any Stripe operation.
|
|
7
15
|
*
|
|
8
|
-
* Usage in a
|
|
16
|
+
* Usage in a `use server` file:
|
|
9
17
|
* ```ts
|
|
10
18
|
* 'use server';
|
|
11
|
-
* import {
|
|
19
|
+
* import { createActions } from '@stripe-sdk/core/next';
|
|
20
|
+
* import { getServerSession } from 'next-auth';
|
|
12
21
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
22
|
+
* const actions = createActions({
|
|
23
|
+
* authorize: async () => {
|
|
24
|
+
* const session = await getServerSession();
|
|
25
|
+
* if (!session) throw new Error('Unauthorized');
|
|
26
|
+
* },
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* export const createPayment = actions.createPaymentIntent;
|
|
18
30
|
* ```
|
|
19
31
|
*/
|
|
20
|
-
declare
|
|
32
|
+
declare function createActions(config: {
|
|
33
|
+
authorize: () => Promise<boolean | void>;
|
|
34
|
+
}): {
|
|
21
35
|
createPaymentIntent: (input: CreatePaymentIntentInput) => Promise<SDKResult<Stripe.Stripe.PaymentIntent>>;
|
|
22
36
|
createCheckoutSession: (input: CreateCheckoutSessionInput) => Promise<SDKResult<Stripe.Stripe.Checkout.Session>>;
|
|
23
37
|
createSetupIntent: (input: CreateSetupIntentInput) => Promise<SDKResult<Stripe.Stripe.SetupIntent>>;
|
|
@@ -27,39 +41,48 @@ declare const actions: {
|
|
|
27
41
|
cancelSubscription: (input: CancelSubscriptionInput) => Promise<SDKResult<Stripe.Stripe.Subscription>>;
|
|
28
42
|
resumeSubscription: (subscriptionId: string) => Promise<SDKResult<Stripe.Stripe.Subscription>>;
|
|
29
43
|
};
|
|
44
|
+
interface RouteOptions<TInput> {
|
|
45
|
+
/**
|
|
46
|
+
* REQUIRED: Authorization callback. Must verify the user's identity.
|
|
47
|
+
* Throw an error or return false to reject the request.
|
|
48
|
+
*/
|
|
49
|
+
authorize: AuthorizeFn;
|
|
50
|
+
/**
|
|
51
|
+
* Optional hook to transform/validate input before creating the resource.
|
|
52
|
+
*/
|
|
53
|
+
beforeCreate?: (input: TInput, request: Request) => Promise<TInput>;
|
|
54
|
+
}
|
|
30
55
|
/**
|
|
31
56
|
* Creates a Next.js API route handler for creating payment intents.
|
|
57
|
+
* Requires an `authorize` callback for authentication.
|
|
32
58
|
*
|
|
33
59
|
* Usage in app/api/create-payment-intent/route.ts:
|
|
34
60
|
* ```ts
|
|
35
61
|
* import { createPaymentIntentRoute } from '@stripe-sdk/core/next';
|
|
36
|
-
*
|
|
62
|
+
* import { getServerSession } from 'next-auth';
|
|
63
|
+
*
|
|
64
|
+
* export const POST = createPaymentIntentRoute({
|
|
65
|
+
* authorize: async (request) => {
|
|
66
|
+
* const session = await getServerSession();
|
|
67
|
+
* if (!session) throw new Error('Unauthorized');
|
|
68
|
+
* },
|
|
69
|
+
* beforeCreate: async (input) => ({
|
|
70
|
+
* ...input,
|
|
71
|
+
* amount: getVerifiedAmount(input),
|
|
72
|
+
* }),
|
|
73
|
+
* });
|
|
37
74
|
* ```
|
|
38
75
|
*/
|
|
39
|
-
declare function createPaymentIntentRoute(options
|
|
40
|
-
beforeCreate?: (input: CreatePaymentIntentInput, request: Request) => Promise<CreatePaymentIntentInput>;
|
|
41
|
-
}): (request: Request) => Promise<Response>;
|
|
76
|
+
declare function createPaymentIntentRoute(options: RouteOptions<CreatePaymentIntentInput>): (request: Request) => Promise<Response>;
|
|
42
77
|
/**
|
|
43
78
|
* Creates a Next.js API route handler for creating checkout sessions.
|
|
44
|
-
*
|
|
45
|
-
* Usage in app/api/create-checkout-session/route.ts:
|
|
46
|
-
* ```ts
|
|
47
|
-
* import { createCheckoutSessionRoute } from '@stripe-sdk/core/next';
|
|
48
|
-
* export const POST = createCheckoutSessionRoute();
|
|
49
|
-
* ```
|
|
79
|
+
* Requires an `authorize` callback for authentication.
|
|
50
80
|
*/
|
|
51
|
-
declare function createCheckoutSessionRoute(options
|
|
52
|
-
beforeCreate?: (input: CreateCheckoutSessionInput, request: Request) => Promise<CreateCheckoutSessionInput>;
|
|
53
|
-
}): (request: Request) => Promise<Response>;
|
|
81
|
+
declare function createCheckoutSessionRoute(options: RouteOptions<CreateCheckoutSessionInput>): (request: Request) => Promise<Response>;
|
|
54
82
|
/**
|
|
55
83
|
* Creates a Next.js API route handler for creating portal sessions.
|
|
56
|
-
*
|
|
57
|
-
* Usage in app/api/create-portal-session/route.ts:
|
|
58
|
-
* ```ts
|
|
59
|
-
* import { createPortalSessionRoute } from '@stripe-sdk/core/next';
|
|
60
|
-
* export const POST = createPortalSessionRoute();
|
|
61
|
-
* ```
|
|
84
|
+
* Requires an `authorize` callback for authentication.
|
|
62
85
|
*/
|
|
63
|
-
declare function createPortalSessionRoute(): (request: Request) => Promise<Response>;
|
|
86
|
+
declare function createPortalSessionRoute(options: RouteOptions<CreatePortalSessionInput>): (request: Request) => Promise<Response>;
|
|
64
87
|
|
|
65
|
-
export {
|
|
88
|
+
export { type AuthorizeFn, createActions, createCheckoutSessionRoute, createPaymentIntentRoute, createPortalSessionRoute };
|