@efaj/pulumi-dynamic-stripe 0.0.2-bfb0df3 → 0.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 +4 -19
- package/dist/StripePaymentLink.js +2 -2
- package/dist/StripePrice.js +2 -2
- package/dist/StripeProduct.js +3 -3
- package/jest.config.js +5 -0
- package/package.json +6 -4
- package/tests/index.test.ts +19 -20
- package/vitest.config.ts +0 -7
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# pulumi-dynamic-stripe
|
|
2
2
|
|
|
3
|
-

|
|
4
|
+

|
|
5
5
|
[](https://app.fossa.com/projects/git%2Bgithub.com%2Fefaj%2Fpulumi-dynamic-stripe?ref=badge_shield)
|
|
6
6
|
|
|
7
7
|
A native Pulumi Dynamic Provider for Stripe.
|
|
@@ -28,7 +28,7 @@ Contributions to add more dynamic providers for other Stripe resources are highl
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
npm install
|
|
31
|
+
npm install pulumi-dynamic-stripe
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## Usage
|
|
@@ -37,7 +37,7 @@ Here is a full example of provisioning a Product, attaching a Price to it, and g
|
|
|
37
37
|
|
|
38
38
|
```typescript
|
|
39
39
|
import * as pulumi from "@pulumi/pulumi";
|
|
40
|
-
import { Product, Price, PaymentLink } from "
|
|
40
|
+
import { Product, Price, PaymentLink } from "pulumi-dynamic-stripe";
|
|
41
41
|
|
|
42
42
|
const config = new pulumi.Config();
|
|
43
43
|
const stripeApiKey = config.requireSecret("stripeApiKey");
|
|
@@ -71,18 +71,3 @@ export const paymentUrl = premiumPaymentLink.url;
|
|
|
71
71
|
## How it works
|
|
72
72
|
|
|
73
73
|
Behind the scenes, this library defines custom Pulumi Dynamic Resource Providers that implement the CRUD operations for Stripe entities via the `@pulumi/pulumi` and `stripe` Node packages.
|
|
74
|
-
|
|
75
|
-
## Development
|
|
76
|
-
|
|
77
|
-
If you wish to contribute or build the project locally, please use the provided `Makefile`.
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
# Install dependencies
|
|
81
|
-
make install
|
|
82
|
-
|
|
83
|
-
# Build the TypeScript source
|
|
84
|
-
make build
|
|
85
|
-
|
|
86
|
-
# Run the Vitest test suite
|
|
87
|
-
make test
|
|
88
|
-
```
|
|
@@ -41,7 +41,7 @@ const pulumi = __importStar(require("@pulumi/pulumi"));
|
|
|
41
41
|
const stripe_1 = __importDefault(require("stripe"));
|
|
42
42
|
class StripePaymentLinkProvider {
|
|
43
43
|
async create(inputs) {
|
|
44
|
-
const stripe = new stripe_1.default(inputs.apiKey);
|
|
44
|
+
const stripe = new stripe_1.default(inputs.apiKey, { apiVersion: '2022-11-15' });
|
|
45
45
|
const paymentLink = await stripe.paymentLinks.create({
|
|
46
46
|
line_items: [{
|
|
47
47
|
price: inputs.priceId,
|
|
@@ -93,7 +93,7 @@ class StripePaymentLinkProvider {
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
async delete(id, props) {
|
|
96
|
-
const stripe = new stripe_1.default(props.apiKey);
|
|
96
|
+
const stripe = new stripe_1.default(props.apiKey, { apiVersion: '2022-11-15' });
|
|
97
97
|
await stripe.paymentLinks.update(id, { active: false });
|
|
98
98
|
}
|
|
99
99
|
}
|
package/dist/StripePrice.js
CHANGED
|
@@ -41,7 +41,7 @@ const pulumi = __importStar(require("@pulumi/pulumi"));
|
|
|
41
41
|
const stripe_1 = __importDefault(require("stripe"));
|
|
42
42
|
class StripePriceProvider {
|
|
43
43
|
async create(inputs) {
|
|
44
|
-
const stripe = new stripe_1.default(inputs.apiKey);
|
|
44
|
+
const stripe = new stripe_1.default(inputs.apiKey, { apiVersion: '2022-11-15' });
|
|
45
45
|
const price = await stripe.prices.create({
|
|
46
46
|
product: inputs.productId,
|
|
47
47
|
unit_amount: inputs.unitAmount,
|
|
@@ -71,7 +71,7 @@ class StripePriceProvider {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
async delete(id, props) {
|
|
74
|
-
const stripe = new stripe_1.default(props.apiKey);
|
|
74
|
+
const stripe = new stripe_1.default(props.apiKey, { apiVersion: '2022-11-15' });
|
|
75
75
|
await stripe.prices.update(id, { active: false });
|
|
76
76
|
}
|
|
77
77
|
}
|
package/dist/StripeProduct.js
CHANGED
|
@@ -41,7 +41,7 @@ const pulumi = __importStar(require("@pulumi/pulumi"));
|
|
|
41
41
|
const stripe_1 = __importDefault(require("stripe"));
|
|
42
42
|
class StripeProductProvider {
|
|
43
43
|
async create(inputs) {
|
|
44
|
-
const stripe = new stripe_1.default(inputs.apiKey);
|
|
44
|
+
const stripe = new stripe_1.default(inputs.apiKey, { apiVersion: '2022-11-15' });
|
|
45
45
|
const product = await stripe.products.create({
|
|
46
46
|
name: inputs.name,
|
|
47
47
|
description: inputs.description,
|
|
@@ -71,7 +71,7 @@ class StripeProductProvider {
|
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
73
|
async update(id, olds, news) {
|
|
74
|
-
const stripe = new stripe_1.default(news.apiKey);
|
|
74
|
+
const stripe = new stripe_1.default(news.apiKey, { apiVersion: '2022-11-15' });
|
|
75
75
|
await stripe.products.update(id, {
|
|
76
76
|
name: news.name,
|
|
77
77
|
description: news.description,
|
|
@@ -85,7 +85,7 @@ class StripeProductProvider {
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
async delete(id, props) {
|
|
88
|
-
const stripe = new stripe_1.default(props.apiKey);
|
|
88
|
+
const stripe = new stripe_1.default(props.apiKey, { apiVersion: '2022-11-15' });
|
|
89
89
|
await stripe.products.update(id, { active: false });
|
|
90
90
|
}
|
|
91
91
|
}
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@efaj/pulumi-dynamic-stripe",
|
|
3
|
-
"version": "0.0.2
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "A Pulumi Dynamic Provider for Stripe, supporting modern features like Payment Links.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pulumi",
|
|
@@ -22,15 +22,17 @@
|
|
|
22
22
|
"scripts": {
|
|
23
23
|
"build": "tsc",
|
|
24
24
|
"prepare": "tsc",
|
|
25
|
-
"test": "
|
|
25
|
+
"test": "jest"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@pulumi/pulumi": "^3.259.0",
|
|
29
29
|
"stripe": "^22.6.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
+
"@types/jest": "^30.0.0",
|
|
32
33
|
"@types/node": "^26.4.0",
|
|
33
|
-
"
|
|
34
|
+
"jest": "^30.4.2",
|
|
35
|
+
"ts-jest": "^29.4.12",
|
|
34
36
|
"typescript": "^6.0.3"
|
|
35
37
|
}
|
|
36
|
-
}
|
|
38
|
+
}
|
package/tests/index.test.ts
CHANGED
|
@@ -1,33 +1,32 @@
|
|
|
1
1
|
import { StripePaymentLinkProvider, StripeProductProvider, StripePriceProvider } from "../src/index";
|
|
2
2
|
import Stripe from "stripe";
|
|
3
|
-
import { describe, it, expect,
|
|
4
|
-
import type { Mock } from 'vitest';
|
|
3
|
+
import { describe, it, expect, jest, beforeEach } from '@jest/globals';
|
|
5
4
|
|
|
6
5
|
// Mock the Stripe SDK
|
|
7
|
-
|
|
6
|
+
jest.mock("stripe");
|
|
8
7
|
|
|
9
|
-
const MockedStripe = Stripe as
|
|
8
|
+
const MockedStripe = Stripe as jest.MockedClass<typeof Stripe>;
|
|
10
9
|
|
|
11
10
|
describe("Stripe Providers", () => {
|
|
12
|
-
let mockPaymentLinksCreate: Mock<any>;
|
|
13
|
-
let mockPaymentLinksUpdate: Mock<any>;
|
|
14
|
-
let mockProductsCreate: Mock<any>;
|
|
15
|
-
let mockProductsUpdate: Mock<any>;
|
|
16
|
-
let mockPricesCreate: Mock<any>;
|
|
17
|
-
let mockPricesUpdate: Mock<any>;
|
|
11
|
+
let mockPaymentLinksCreate: jest.Mock<any>;
|
|
12
|
+
let mockPaymentLinksUpdate: jest.Mock<any>;
|
|
13
|
+
let mockProductsCreate: jest.Mock<any>;
|
|
14
|
+
let mockProductsUpdate: jest.Mock<any>;
|
|
15
|
+
let mockPricesCreate: jest.Mock<any>;
|
|
16
|
+
let mockPricesUpdate: jest.Mock<any>;
|
|
18
17
|
|
|
19
18
|
beforeEach(() => {
|
|
20
19
|
// Reset mocks before each test
|
|
21
|
-
|
|
20
|
+
jest.clearAllMocks();
|
|
22
21
|
|
|
23
|
-
mockPaymentLinksCreate =
|
|
24
|
-
mockPaymentLinksUpdate =
|
|
22
|
+
mockPaymentLinksCreate = jest.fn<any>().mockResolvedValue({ id: "plink_123", url: "https://stripe.com/plink_123" } as any);
|
|
23
|
+
mockPaymentLinksUpdate = jest.fn<any>().mockResolvedValue({ id: "plink_123" } as any);
|
|
25
24
|
|
|
26
|
-
mockProductsCreate =
|
|
27
|
-
mockProductsUpdate =
|
|
25
|
+
mockProductsCreate = jest.fn<any>().mockResolvedValue({ id: "prod_123" } as any);
|
|
26
|
+
mockProductsUpdate = jest.fn<any>().mockResolvedValue({ id: "prod_123" } as any);
|
|
28
27
|
|
|
29
|
-
mockPricesCreate =
|
|
30
|
-
mockPricesUpdate =
|
|
28
|
+
mockPricesCreate = jest.fn<any>().mockResolvedValue({ id: "price_123" } as any);
|
|
29
|
+
mockPricesUpdate = jest.fn<any>().mockResolvedValue({ id: "price_123" } as any);
|
|
31
30
|
|
|
32
31
|
// Setup the mocked Stripe instance's internal resource objects
|
|
33
32
|
MockedStripe.mockImplementation(() => {
|
|
@@ -103,7 +102,7 @@ describe("Stripe Providers", () => {
|
|
|
103
102
|
expect(result.outs?.paymentLinkId).toBe("plink_123");
|
|
104
103
|
expect(result.outs?.url).toBe("https://stripe.com/plink_123");
|
|
105
104
|
|
|
106
|
-
expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey);
|
|
105
|
+
expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey, { apiVersion: '2022-11-15' as any });
|
|
107
106
|
expect(mockPaymentLinksCreate).toHaveBeenCalledWith(expectedPayload);
|
|
108
107
|
});
|
|
109
108
|
});
|
|
@@ -188,7 +187,7 @@ describe("Stripe Providers", () => {
|
|
|
188
187
|
expect(result.id).toBe("prod_123");
|
|
189
188
|
expect(result.outs?.productId).toBe("prod_123");
|
|
190
189
|
|
|
191
|
-
expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey);
|
|
190
|
+
expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey, { apiVersion: '2022-11-15' as any });
|
|
192
191
|
expect(mockProductsCreate).toHaveBeenCalledWith(expectedPayload);
|
|
193
192
|
});
|
|
194
193
|
});
|
|
@@ -275,7 +274,7 @@ describe("Stripe Providers", () => {
|
|
|
275
274
|
expect(result.id).toBe("price_123");
|
|
276
275
|
expect(result.outs?.priceId).toBe("price_123");
|
|
277
276
|
|
|
278
|
-
expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey);
|
|
277
|
+
expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey, { apiVersion: '2022-11-15' as any });
|
|
279
278
|
expect(mockPricesCreate).toHaveBeenCalledWith(expectedPayload);
|
|
280
279
|
});
|
|
281
280
|
});
|