fresh-squeezy 1.0.95 → 1.0.99
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.
Potentially problematic release.
This version of fresh-squeezy might be problematic. Click here for more details.
package/README.md
CHANGED
|
@@ -18,6 +18,8 @@ npm install fresh-squeezy
|
|
|
18
18
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
|
+
Callbacks are **yours to implement** — `event` delivers typed data, you write the business logic:
|
|
22
|
+
|
|
21
23
|
```typescript
|
|
22
24
|
import { createBilling } from "fresh-squeezy";
|
|
23
25
|
|
|
@@ -26,17 +28,31 @@ const billing = await createBilling({
|
|
|
26
28
|
webhookSecret: process.env.LS_WEBHOOK_SECRET!,
|
|
27
29
|
callbacks: {
|
|
28
30
|
onOrder: async (event, method) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
// event.userId — your internal user ID (the one you pass at checkout)
|
|
32
|
+
// event.email — customer email
|
|
33
|
+
// event.orderId — Lemon Squeezy order ID
|
|
34
|
+
// event.price — amount in cents
|
|
35
|
+
if (method === 'purchase') {
|
|
36
|
+
// e.g. await prisma.user.update({ where: { id: event.userId }, data: { isPro: true } })
|
|
37
|
+
}
|
|
38
|
+
if (method === 'refund') {
|
|
39
|
+
// e.g. await prisma.user.update({ where: { id: event.userId }, data: { isPro: false } })
|
|
40
|
+
}
|
|
31
41
|
},
|
|
32
42
|
onSubscription: async (event, method) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (method === '
|
|
43
|
+
// event.userId — your internal user ID
|
|
44
|
+
// event.subscriptionId — Lemon Squeezy subscription ID
|
|
45
|
+
// event.status — active | cancelled | expired | paused
|
|
46
|
+
if (method === 'created') { /* activate subscription in your DB */ }
|
|
47
|
+
if (method === 'cancelled') { /* mark subscription cancelled */ }
|
|
48
|
+
if (method === 'payment_success') { /* extend access, clear dunning flags */ }
|
|
49
|
+
if (method === 'payment_failed') { /* notify customer, start dunning */ }
|
|
37
50
|
},
|
|
38
51
|
onLicenseKey: async (event, method) => {
|
|
39
|
-
|
|
52
|
+
// event.userId — your internal user ID
|
|
53
|
+
// event.key — the license key string to store and share with the user
|
|
54
|
+
// event.status — active | inactive | expired
|
|
55
|
+
if (method === 'created') { /* store event.key in your DB */ }
|
|
40
56
|
},
|
|
41
57
|
},
|
|
42
58
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-content.d.ts","sourceRoot":"","sources":["../../../../src/wizard/utils/config-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"config-content.d.ts","sourceRoot":"","sources":["../../../../src/wizard/utils/config-content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAoEhE"}
|
|
@@ -12,18 +12,40 @@ export function generateConfigContent(state) {
|
|
|
12
12
|
lines.push(` skipTestEvents: ${state.isSandbox ? 'false' : 'true'},`);
|
|
13
13
|
lines.push(' callbacks: {');
|
|
14
14
|
lines.push(' onOrder: async (event: OrderEvent, method: OrderMethod, meta: WebhookMeta) => {');
|
|
15
|
-
lines.push(' if (meta.isTest) return;
|
|
16
|
-
lines.push('
|
|
17
|
-
lines.push('
|
|
15
|
+
lines.push(' if (meta.isTest) return;');
|
|
16
|
+
lines.push(' // event.userId — your internal user ID (passed at checkout)');
|
|
17
|
+
lines.push(' // event.email — customer email');
|
|
18
|
+
lines.push(' // event.orderId — Lemon Squeezy order ID');
|
|
19
|
+
lines.push(' // event.price — amount in cents');
|
|
20
|
+
lines.push(' if (method === "purchase") {');
|
|
21
|
+
lines.push(' // TODO: grant access — e.g. await prisma.user.update({ where: { id: event.userId }, data: { isPro: true } })');
|
|
22
|
+
lines.push(' console.log("[+] Purchase:", event.orderId, event.email);');
|
|
23
|
+
lines.push(' }');
|
|
24
|
+
lines.push(' if (method === "refund") {');
|
|
25
|
+
lines.push(' // TODO: revoke access — e.g. await prisma.user.update({ where: { id: event.userId }, data: { isPro: false } })');
|
|
26
|
+
lines.push(' console.log("[-] Refund:", event.orderId);');
|
|
27
|
+
lines.push(' }');
|
|
18
28
|
lines.push(' },');
|
|
19
29
|
lines.push(' onSubscription: async (event: AnySubscriptionEvent, method: SubscriptionMethod, meta: WebhookMeta) => {');
|
|
20
30
|
lines.push(' if (meta.isTest) return;');
|
|
21
|
-
lines.push('
|
|
22
|
-
lines.push(' //
|
|
31
|
+
lines.push(' // event.userId — your internal user ID');
|
|
32
|
+
lines.push(' // event.subscriptionId — Lemon Squeezy subscription ID');
|
|
33
|
+
lines.push(' // event.status — active | cancelled | expired | paused');
|
|
34
|
+
lines.push(' // method values: created | updated | cancelled | expired | paused | resumed');
|
|
35
|
+
lines.push(' // payment_success | payment_recovered | payment_failed');
|
|
36
|
+
lines.push(' if (method === "created") { /* TODO: activate subscription */ }');
|
|
37
|
+
lines.push(' if (method === "cancelled") { /* TODO: mark subscription cancelled */ }');
|
|
38
|
+
lines.push(' if (method === "payment_success") { /* TODO: extend access, clear dunning flags */ }');
|
|
39
|
+
lines.push(' if (method === "payment_failed") { /* TODO: notify customer, start dunning */ }');
|
|
40
|
+
lines.push(' console.log("[~] Subscription", method, event.userId);');
|
|
23
41
|
lines.push(' },');
|
|
24
42
|
lines.push(' onLicenseKey: async (event: LicenseKeyEvent, method: LicenseMethod, meta: WebhookMeta) => {');
|
|
25
43
|
lines.push(' if (meta.isTest) return;');
|
|
26
|
-
lines.push('
|
|
44
|
+
lines.push(' // event.userId — your internal user ID');
|
|
45
|
+
lines.push(' // event.key — the license key string to store and share with the user');
|
|
46
|
+
lines.push(' // event.status — active | inactive | expired');
|
|
47
|
+
lines.push(' if (method === "created") { /* TODO: store event.key in your DB */ }');
|
|
48
|
+
lines.push(' console.log("[K] License key", method, event.userId);');
|
|
27
49
|
lines.push(' },');
|
|
28
50
|
lines.push(' },');
|
|
29
51
|
lines.push('};');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-content.js","sourceRoot":"","sources":["../../../../src/wizard/utils/config-content.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,qBAAqB,CAAC,KAAkB;IACtD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CACR,qKAAqK,CACtK,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC;IACvE,KAAK,CAAC,IAAI,CAAC,yBAAyB,MAAM,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClF,KAAK,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IACvE,KAAK,CAAC,IAAI,CAAC,oBAAoB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IACvE,KAAK,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAC/D,KAAK,CAAC,IAAI,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC3E,KAAK,CAAC,IAAI,CAAC,qBAAqB,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;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AAC,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CACxG,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fresh-squeezy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.99",
|
|
4
4
|
"description": "The missing billing layer for Lemon Squeezy. Auto-discover, checkout, webhooks — one function.",
|
|
5
5
|
"author": "Yosef Hayim Sabag <yosefhayim@proton.me>",
|
|
6
6
|
"homepage": "https://github.com/YosefHayim/fresh-squeezy#readme",
|