@xframework/stripe 0.4.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.
@@ -0,0 +1,22 @@
1
+
2
+ > @xframework/stripe@0.4.0 build /home/runner/work/x/x/packages/@xframework/stripe
3
+ > tsup
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.3.5
8
+ CLI Using tsup config: /home/runner/work/x/x/packages/@xframework/stripe/tsup.config.ts
9
+ CLI Target: esnext
10
+ CLI Cleaning output folder
11
+ CJS Build start
12
+ ESM Build start
13
+ ESM dist/index.js 795.00 B
14
+ ESM dist/index.js.map 1.57 KB
15
+ ESM ⚡️ Build success in 37ms
16
+ CJS dist/index.cjs 1.79 KB
17
+ CJS dist/index.cjs.map 1.61 KB
18
+ CJS ⚡️ Build success in 38ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 5048ms
21
+ DTS dist/index.d.cts 540.00 B
22
+ DTS dist/index.d.ts 540.00 B
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @xframework/stripe
2
+
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 98dd8e4: redesign
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [98dd8e4]
12
+ - @xframework/x@0.4.0
package/dist/index.cjs ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ StripeAdapter: () => StripeAdapter
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_adapter = require("@xframework/x/adapter");
27
+ var StripeAdapter = class extends import_adapter.SyncAdapter {
28
+ client;
29
+ webhookSecret;
30
+ constructor({
31
+ client,
32
+ webhookSecret
33
+ }) {
34
+ super();
35
+ this.client = client;
36
+ this.webhookSecret = webhookSecret;
37
+ }
38
+ async handleWebhookRequest(request) {
39
+ const headers = request.headers;
40
+ const body = await request.text();
41
+ const signature = headers.get("stripe-signature");
42
+ if (!signature) {
43
+ throw new Error("missing stripe-signature");
44
+ }
45
+ const event = this.client.webhooks.constructEvent(
46
+ body,
47
+ signature,
48
+ this.webhookSecret
49
+ );
50
+ return event;
51
+ }
52
+ export() {
53
+ return {
54
+ client: this.client
55
+ };
56
+ }
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ StripeAdapter
61
+ });
62
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type Stripe from \"stripe\";\nimport { SyncAdapter } from \"@xframework/x/adapter\";\n\nexport class StripeAdapter<\n UserStripeInstance extends Stripe,\n> extends SyncAdapter<{\n client: UserStripeInstance;\n}> {\n public client: UserStripeInstance;\n private webhookSecret: string;\n\n constructor({\n client,\n webhookSecret,\n }: {\n client: UserStripeInstance;\n webhookSecret: string;\n }) {\n super();\n this.client = client;\n this.webhookSecret = webhookSecret;\n }\n\n async handleWebhookRequest(request: Request) {\n const headers = request.headers;\n const body = await request.text();\n\n const signature = headers.get(\"stripe-signature\");\n\n if (!signature) {\n throw new Error(\"missing stripe-signature\");\n }\n\n const event = this.client.webhooks.constructEvent(\n body,\n signature,\n this.webhookSecret,\n );\n\n return event;\n }\n\n export() {\n return {\n client: this.client,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA4B;AAErB,IAAM,gBAAN,cAEG,2BAEP;AAAA,EACM;AAAA,EACC;AAAA,EAER,YAAY;AAAA,IACV;AAAA,IACA;AAAA,EACF,GAGG;AACD,UAAM;AACN,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACvB;AAAA,EAEA,MAAM,qBAAqB,SAAkB;AAC3C,UAAM,UAAU,QAAQ;AACxB,UAAM,OAAO,MAAM,QAAQ,KAAK;AAEhC,UAAM,YAAY,QAAQ,IAAI,kBAAkB;AAEhD,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AAEA,UAAM,QAAQ,KAAK,OAAO,SAAS;AAAA,MACjC;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IACP;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,SAAS;AACP,WAAO;AAAA,MACL,QAAQ,KAAK;AAAA,IACf;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,19 @@
1
+ import Stripe from 'stripe';
2
+ import { SyncAdapter } from '@xframework/x/adapter';
3
+
4
+ declare class StripeAdapter<UserStripeInstance extends Stripe> extends SyncAdapter<{
5
+ client: UserStripeInstance;
6
+ }> {
7
+ client: UserStripeInstance;
8
+ private webhookSecret;
9
+ constructor({ client, webhookSecret, }: {
10
+ client: UserStripeInstance;
11
+ webhookSecret: string;
12
+ });
13
+ handleWebhookRequest(request: Request): Promise<Stripe.Event>;
14
+ export(): {
15
+ client: UserStripeInstance;
16
+ };
17
+ }
18
+
19
+ export { StripeAdapter };
@@ -0,0 +1,19 @@
1
+ import Stripe from 'stripe';
2
+ import { SyncAdapter } from '@xframework/x/adapter';
3
+
4
+ declare class StripeAdapter<UserStripeInstance extends Stripe> extends SyncAdapter<{
5
+ client: UserStripeInstance;
6
+ }> {
7
+ client: UserStripeInstance;
8
+ private webhookSecret;
9
+ constructor({ client, webhookSecret, }: {
10
+ client: UserStripeInstance;
11
+ webhookSecret: string;
12
+ });
13
+ handleWebhookRequest(request: Request): Promise<Stripe.Event>;
14
+ export(): {
15
+ client: UserStripeInstance;
16
+ };
17
+ }
18
+
19
+ export { StripeAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ // src/index.ts
2
+ import { SyncAdapter } from "@xframework/x/adapter";
3
+ var StripeAdapter = class extends SyncAdapter {
4
+ client;
5
+ webhookSecret;
6
+ constructor({
7
+ client,
8
+ webhookSecret
9
+ }) {
10
+ super();
11
+ this.client = client;
12
+ this.webhookSecret = webhookSecret;
13
+ }
14
+ async handleWebhookRequest(request) {
15
+ const headers = request.headers;
16
+ const body = await request.text();
17
+ const signature = headers.get("stripe-signature");
18
+ if (!signature) {
19
+ throw new Error("missing stripe-signature");
20
+ }
21
+ const event = this.client.webhooks.constructEvent(
22
+ body,
23
+ signature,
24
+ this.webhookSecret
25
+ );
26
+ return event;
27
+ }
28
+ export() {
29
+ return {
30
+ client: this.client
31
+ };
32
+ }
33
+ };
34
+ export {
35
+ StripeAdapter
36
+ };
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type Stripe from \"stripe\";\nimport { SyncAdapter } from \"@xframework/x/adapter\";\n\nexport class StripeAdapter<\n UserStripeInstance extends Stripe,\n> extends SyncAdapter<{\n client: UserStripeInstance;\n}> {\n public client: UserStripeInstance;\n private webhookSecret: string;\n\n constructor({\n client,\n webhookSecret,\n }: {\n client: UserStripeInstance;\n webhookSecret: string;\n }) {\n super();\n this.client = client;\n this.webhookSecret = webhookSecret;\n }\n\n async handleWebhookRequest(request: Request) {\n const headers = request.headers;\n const body = await request.text();\n\n const signature = headers.get(\"stripe-signature\");\n\n if (!signature) {\n throw new Error(\"missing stripe-signature\");\n }\n\n const event = this.client.webhooks.constructEvent(\n body,\n signature,\n this.webhookSecret,\n );\n\n return event;\n }\n\n export() {\n return {\n client: this.client,\n };\n }\n}\n"],"mappings":";AACA,SAAS,mBAAmB;AAErB,IAAM,gBAAN,cAEG,YAEP;AAAA,EACM;AAAA,EACC;AAAA,EAER,YAAY;AAAA,IACV;AAAA,IACA;AAAA,EACF,GAGG;AACD,UAAM;AACN,SAAK,SAAS;AACd,SAAK,gBAAgB;AAAA,EACvB;AAAA,EAEA,MAAM,qBAAqB,SAAkB;AAC3C,UAAM,UAAU,QAAQ;AACxB,UAAM,OAAO,MAAM,QAAQ,KAAK;AAEhC,UAAM,YAAY,QAAQ,IAAI,kBAAkB;AAEhD,QAAI,CAAC,WAAW;AACd,YAAM,IAAI,MAAM,0BAA0B;AAAA,IAC5C;AAEA,UAAM,QAAQ,KAAK,OAAO,SAAS;AAAA,MACjC;AAAA,MACA;AAAA,MACA,KAAK;AAAA,IACP;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,SAAS;AACP,WAAO;AAAA,MACL,QAAQ,KAAK;AAAA,IACf;AAAA,EACF;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@xframework/stripe",
3
+ "version": "0.4.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "require": "./dist/index.cjs",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "dependencies": {
19
+ "@xframework/x": "0.4.0"
20
+ },
21
+ "peerDependencies": {
22
+ "stripe": ">=17.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^20.11.24",
26
+ "tsup": "^8.2.4",
27
+ "typescript": "^5.5.4"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup",
31
+ "dev": "tsup --watch"
32
+ }
33
+ }
@@ -0,0 +1,108 @@
1
+ import Stripe from "stripe";
2
+ import { expect, it, describe, vi } from "vitest";
3
+ import { createX } from "@xframework/x";
4
+ import { StripeAdapter } from "../index";
5
+
6
+ describe("StripeAdapter", () => {
7
+ const mockStripe = new Stripe("test_key", {
8
+ apiVersion: "2025-01-27.acacia",
9
+ });
10
+ const webhookSecret = "whsec_test_secret";
11
+
12
+ it("should properly initialize and export Stripe instance", () => {
13
+ const adapter = new StripeAdapter({
14
+ client: mockStripe,
15
+ webhookSecret,
16
+ });
17
+
18
+ expect(adapter.client).toBe(mockStripe);
19
+ const exported = adapter.export();
20
+ expect(exported.client).toBe(mockStripe);
21
+ });
22
+
23
+ it("should preserve Stripe types", () => {
24
+ const x = createX()
25
+ .syncAdapter(
26
+ "stripe",
27
+ () => new StripeAdapter({ client: mockStripe, webhookSecret }),
28
+ )
29
+ .build();
30
+
31
+ // Type check: verify that the exported client maintains Stripe's type information
32
+ type ClientType = typeof x.stripe.client;
33
+ type ExpectedType = Stripe;
34
+ const _typeCheck: ClientType extends ExpectedType ? true : false = true;
35
+ expect(_typeCheck).toBe(true);
36
+
37
+ // Use x to avoid unused variable warning
38
+ expect(x.stripe.client).toBeDefined();
39
+ });
40
+
41
+ it("should handle webhook requests correctly", async () => {
42
+ const adapter = new StripeAdapter({
43
+ client: mockStripe,
44
+ webhookSecret,
45
+ });
46
+
47
+ // Mock Stripe's constructEvent method
48
+ const mockEvent = {
49
+ type: "payment_intent.succeeded",
50
+ data: { object: { id: "pi_123" } },
51
+ };
52
+
53
+ vi.spyOn(mockStripe.webhooks, "constructEvent").mockReturnValue(
54
+ mockEvent as any,
55
+ );
56
+
57
+ // Create a mock request
58
+ const mockRequest = new Request("https://api.example.com/webhook", {
59
+ method: "POST",
60
+ headers: {
61
+ "stripe-signature": "test_signature",
62
+ },
63
+ body: JSON.stringify({ data: "test" }),
64
+ });
65
+
66
+ const event = await adapter.handleWebhookRequest(mockRequest);
67
+ expect(event).toEqual(mockEvent);
68
+ expect(mockStripe.webhooks.constructEvent).toHaveBeenCalledWith(
69
+ expect.any(String),
70
+ "test_signature",
71
+ webhookSecret,
72
+ );
73
+ });
74
+
75
+ it("should throw error when stripe-signature is missing", async () => {
76
+ const adapter = new StripeAdapter({
77
+ client: mockStripe,
78
+ webhookSecret,
79
+ });
80
+
81
+ // Create a mock request without signature
82
+ const mockRequest = new Request("https://api.example.com/webhook", {
83
+ method: "POST",
84
+ body: JSON.stringify({ data: "test" }),
85
+ });
86
+
87
+ await expect(adapter.handleWebhookRequest(mockRequest)).rejects.toThrow(
88
+ "missing stripe-signature",
89
+ );
90
+ });
91
+
92
+ it("should integrate with X framework", () => {
93
+ const x = createX()
94
+ .syncAdapter(
95
+ "stripe",
96
+ () => new StripeAdapter({ client: mockStripe, webhookSecret }),
97
+ )
98
+ .build();
99
+
100
+ expect(x._.adapters.stripe).toBeInstanceOf(StripeAdapter);
101
+ expect(x.stripe.client).toBe(mockStripe);
102
+
103
+ // Verify that Stripe methods are accessible
104
+ expect(typeof x.stripe.client.paymentIntents.create).toBe("function");
105
+ expect(typeof x.stripe.client.customers.create).toBe("function");
106
+ expect(typeof x.stripe.client.webhooks.constructEvent).toBe("function");
107
+ });
108
+ });
package/src/index.ts ADDED
@@ -0,0 +1,48 @@
1
+ import type Stripe from "stripe";
2
+ import { SyncAdapter } from "@xframework/x/adapter";
3
+
4
+ export class StripeAdapter<
5
+ UserStripeInstance extends Stripe,
6
+ > extends SyncAdapter<{
7
+ client: UserStripeInstance;
8
+ }> {
9
+ public client: UserStripeInstance;
10
+ private webhookSecret: string;
11
+
12
+ constructor({
13
+ client,
14
+ webhookSecret,
15
+ }: {
16
+ client: UserStripeInstance;
17
+ webhookSecret: string;
18
+ }) {
19
+ super();
20
+ this.client = client;
21
+ this.webhookSecret = webhookSecret;
22
+ }
23
+
24
+ async handleWebhookRequest(request: Request) {
25
+ const headers = request.headers;
26
+ const body = await request.text();
27
+
28
+ const signature = headers.get("stripe-signature");
29
+
30
+ if (!signature) {
31
+ throw new Error("missing stripe-signature");
32
+ }
33
+
34
+ const event = this.client.webhooks.constructEvent(
35
+ body,
36
+ signature,
37
+ this.webhookSecret,
38
+ );
39
+
40
+ return event;
41
+ }
42
+
43
+ export() {
44
+ return {
45
+ client: this.client,
46
+ };
47
+ }
48
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "lib": ["ESNext", "DOM"]
6
+ },
7
+ "include": ["src", "tsup.config.ts"],
8
+ "exclude": ["node_modules", "dist"]
9
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { tsupConfig } from "../../../utils/tsup.config";
2
+
3
+ export default tsupConfig;