miragedev-sdk 0.1.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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +393 -0
  3. package/dist/auth/biometric.cjs +85 -0
  4. package/dist/auth/biometric.d.cts +7 -0
  5. package/dist/auth/biometric.d.ts +7 -0
  6. package/dist/auth/biometric.js +81 -0
  7. package/dist/auth/client.cjs +44 -0
  8. package/dist/auth/client.d.cts +12 -0
  9. package/dist/auth/client.d.ts +12 -0
  10. package/dist/auth/client.js +40 -0
  11. package/dist/auth/index.cjs +17 -0
  12. package/dist/auth/index.d.cts +6 -0
  13. package/dist/auth/index.d.ts +6 -0
  14. package/dist/auth/index.js +4 -0
  15. package/dist/auth/middleware.cjs +37 -0
  16. package/dist/auth/middleware.d.cts +10 -0
  17. package/dist/auth/middleware.d.ts +10 -0
  18. package/dist/auth/middleware.js +35 -0
  19. package/dist/auth-BC8JI28z.d.cts +22 -0
  20. package/dist/auth-BC8JI28z.d.ts +22 -0
  21. package/dist/billing/client.cjs +43 -0
  22. package/dist/billing/client.d.cts +11 -0
  23. package/dist/billing/client.d.ts +11 -0
  24. package/dist/billing/client.js +40 -0
  25. package/dist/billing/index.cjs +139 -0
  26. package/dist/billing/index.d.cts +12 -0
  27. package/dist/billing/index.d.ts +12 -0
  28. package/dist/billing/index.js +130 -0
  29. package/dist/billing/mobile.cjs +81 -0
  30. package/dist/billing/mobile.d.cts +17 -0
  31. package/dist/billing/mobile.d.ts +17 -0
  32. package/dist/billing/mobile.js +74 -0
  33. package/dist/billing/webhook.cjs +84 -0
  34. package/dist/billing/webhook.d.cts +19 -0
  35. package/dist/billing/webhook.d.ts +19 -0
  36. package/dist/billing/webhook.js +78 -0
  37. package/dist/billing-Bv2V7KWF.d.cts +23 -0
  38. package/dist/billing-Bv2V7KWF.d.ts +23 -0
  39. package/dist/chunk-5YXI4Q2K.js +13813 -0
  40. package/dist/chunk-75ZPJI57.cjs +9 -0
  41. package/dist/chunk-BW4BLEIM.cjs +18 -0
  42. package/dist/chunk-DZDDLA4G.js +271 -0
  43. package/dist/chunk-E5YC2MHX.cjs +13816 -0
  44. package/dist/chunk-JUTTFY3W.js +16 -0
  45. package/dist/chunk-M26EDKMY.cjs +280 -0
  46. package/dist/chunk-M3DPIKWT.js +23 -0
  47. package/dist/chunk-MLKGABMK.js +7 -0
  48. package/dist/chunk-PHTUPKEM.cjs +26 -0
  49. package/dist/cli/commands/init.cjs +11 -0
  50. package/dist/cli/commands/init.d.cts +3 -0
  51. package/dist/cli/commands/init.d.ts +3 -0
  52. package/dist/cli/commands/init.js +2 -0
  53. package/dist/cli/index.cjs +11 -0
  54. package/dist/cli/index.d.cts +1 -0
  55. package/dist/cli/index.d.ts +1 -0
  56. package/dist/cli/index.js +9 -0
  57. package/dist/email/index.cjs +526 -0
  58. package/dist/email/index.d.cts +6 -0
  59. package/dist/email/index.d.ts +6 -0
  60. package/dist/email/index.js +523 -0
  61. package/dist/email-DZN1-bHa.d.cts +19 -0
  62. package/dist/email-DZN1-bHa.d.ts +19 -0
  63. package/dist/index.cjs +27 -0
  64. package/dist/index.d.cts +23 -0
  65. package/dist/index.d.ts +23 -0
  66. package/dist/index.js +21 -0
  67. package/dist/mobile/index.cjs +101 -0
  68. package/dist/mobile/index.d.cts +15 -0
  69. package/dist/mobile/index.d.ts +15 -0
  70. package/dist/mobile/index.js +96 -0
  71. package/dist/pwa/index.cjs +80 -0
  72. package/dist/pwa/index.d.cts +51 -0
  73. package/dist/pwa/index.d.ts +51 -0
  74. package/dist/pwa/index.js +76 -0
  75. package/package.json +140 -0
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ var chunkE5YC2MHX_cjs = require('../chunk-E5YC2MHX.cjs');
4
+ var chunkBW4BLEIM_cjs = require('../chunk-BW4BLEIM.cjs');
5
+ require('../chunk-75ZPJI57.cjs');
6
+ var Stripe = require('stripe');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var Stripe__default = /*#__PURE__*/_interopDefault(Stripe);
11
+
12
+ async function createMobileCheckout(options) {
13
+ const config = chunkE5YC2MHX_cjs.getConfig();
14
+ if (!config.billing.stripeSecretKey) {
15
+ throw new chunkBW4BLEIM_cjs.MirageDevError("CONFIG_INVALID", "Stripe secret key not configured");
16
+ }
17
+ try {
18
+ const stripe = new Stripe__default.default(config.billing.stripeSecretKey, {
19
+ apiVersion: "2025-12-15.clover"
20
+ });
21
+ const session = await stripe.checkout.sessions.create({
22
+ mode: "subscription",
23
+ line_items: [
24
+ {
25
+ price: options.priceId,
26
+ quantity: 1
27
+ }
28
+ ],
29
+ success_url: options.successUrl,
30
+ cancel_url: options.cancelUrl,
31
+ client_reference_id: options.userId,
32
+ ui_mode: "embedded"
33
+ });
34
+ if (!session.client_secret) {
35
+ throw new Error("No client secret returned from Stripe");
36
+ }
37
+ return { clientSecret: session.client_secret };
38
+ } catch (error) {
39
+ throw new chunkBW4BLEIM_cjs.MirageDevError(
40
+ "BILLING_STRIPE_ERROR",
41
+ `Failed to create mobile checkout: ${error.message}`,
42
+ error
43
+ );
44
+ }
45
+ }
46
+ async function createPaymentIntent(options) {
47
+ const config = chunkE5YC2MHX_cjs.getConfig();
48
+ if (!config.billing.stripeSecretKey) {
49
+ throw new chunkBW4BLEIM_cjs.MirageDevError("CONFIG_INVALID", "Stripe secret key not configured");
50
+ }
51
+ try {
52
+ const stripe = new Stripe__default.default(config.billing.stripeSecretKey, {
53
+ apiVersion: "2025-12-15.clover"
54
+ });
55
+ const paymentIntent = await stripe.paymentIntents.create({
56
+ amount: options.amount,
57
+ currency: options.currency,
58
+ customer: options.customerId,
59
+ automatic_payment_methods: {
60
+ enabled: true
61
+ },
62
+ metadata: options.metadata
63
+ });
64
+ if (!paymentIntent.client_secret) {
65
+ throw new Error("No client secret returned from Stripe");
66
+ }
67
+ return {
68
+ clientSecret: paymentIntent.client_secret,
69
+ paymentIntentId: paymentIntent.id
70
+ };
71
+ } catch (error) {
72
+ throw new chunkBW4BLEIM_cjs.MirageDevError(
73
+ "BILLING_STRIPE_ERROR",
74
+ `Failed to create payment intent: ${error.message}`,
75
+ error
76
+ );
77
+ }
78
+ }
79
+
80
+ exports.createMobileCheckout = createMobileCheckout;
81
+ exports.createPaymentIntent = createPaymentIntent;
@@ -0,0 +1,17 @@
1
+ import { C as CheckoutOptions } from '../billing-Bv2V7KWF.cjs';
2
+
3
+ interface PaymentIntentOptions {
4
+ amount: number;
5
+ currency: string;
6
+ customerId: string;
7
+ metadata?: Record<string, string>;
8
+ }
9
+ declare function createMobileCheckout(options: CheckoutOptions): Promise<{
10
+ clientSecret: string;
11
+ }>;
12
+ declare function createPaymentIntent(options: PaymentIntentOptions): Promise<{
13
+ clientSecret: string;
14
+ paymentIntentId: string;
15
+ }>;
16
+
17
+ export { type PaymentIntentOptions, createMobileCheckout, createPaymentIntent };
@@ -0,0 +1,17 @@
1
+ import { C as CheckoutOptions } from '../billing-Bv2V7KWF.js';
2
+
3
+ interface PaymentIntentOptions {
4
+ amount: number;
5
+ currency: string;
6
+ customerId: string;
7
+ metadata?: Record<string, string>;
8
+ }
9
+ declare function createMobileCheckout(options: CheckoutOptions): Promise<{
10
+ clientSecret: string;
11
+ }>;
12
+ declare function createPaymentIntent(options: PaymentIntentOptions): Promise<{
13
+ clientSecret: string;
14
+ paymentIntentId: string;
15
+ }>;
16
+
17
+ export { type PaymentIntentOptions, createMobileCheckout, createPaymentIntent };
@@ -0,0 +1,74 @@
1
+ import { getConfig } from '../chunk-5YXI4Q2K.js';
2
+ import { MirageDevError } from '../chunk-JUTTFY3W.js';
3
+ import '../chunk-MLKGABMK.js';
4
+ import Stripe from 'stripe';
5
+
6
+ async function createMobileCheckout(options) {
7
+ const config = getConfig();
8
+ if (!config.billing.stripeSecretKey) {
9
+ throw new MirageDevError("CONFIG_INVALID", "Stripe secret key not configured");
10
+ }
11
+ try {
12
+ const stripe = new Stripe(config.billing.stripeSecretKey, {
13
+ apiVersion: "2025-12-15.clover"
14
+ });
15
+ const session = await stripe.checkout.sessions.create({
16
+ mode: "subscription",
17
+ line_items: [
18
+ {
19
+ price: options.priceId,
20
+ quantity: 1
21
+ }
22
+ ],
23
+ success_url: options.successUrl,
24
+ cancel_url: options.cancelUrl,
25
+ client_reference_id: options.userId,
26
+ ui_mode: "embedded"
27
+ });
28
+ if (!session.client_secret) {
29
+ throw new Error("No client secret returned from Stripe");
30
+ }
31
+ return { clientSecret: session.client_secret };
32
+ } catch (error) {
33
+ throw new MirageDevError(
34
+ "BILLING_STRIPE_ERROR",
35
+ `Failed to create mobile checkout: ${error.message}`,
36
+ error
37
+ );
38
+ }
39
+ }
40
+ async function createPaymentIntent(options) {
41
+ const config = getConfig();
42
+ if (!config.billing.stripeSecretKey) {
43
+ throw new MirageDevError("CONFIG_INVALID", "Stripe secret key not configured");
44
+ }
45
+ try {
46
+ const stripe = new Stripe(config.billing.stripeSecretKey, {
47
+ apiVersion: "2025-12-15.clover"
48
+ });
49
+ const paymentIntent = await stripe.paymentIntents.create({
50
+ amount: options.amount,
51
+ currency: options.currency,
52
+ customer: options.customerId,
53
+ automatic_payment_methods: {
54
+ enabled: true
55
+ },
56
+ metadata: options.metadata
57
+ });
58
+ if (!paymentIntent.client_secret) {
59
+ throw new Error("No client secret returned from Stripe");
60
+ }
61
+ return {
62
+ clientSecret: paymentIntent.client_secret,
63
+ paymentIntentId: paymentIntent.id
64
+ };
65
+ } catch (error) {
66
+ throw new MirageDevError(
67
+ "BILLING_STRIPE_ERROR",
68
+ `Failed to create payment intent: ${error.message}`,
69
+ error
70
+ );
71
+ }
72
+ }
73
+
74
+ export { createMobileCheckout, createPaymentIntent };
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ var chunkE5YC2MHX_cjs = require('../chunk-E5YC2MHX.cjs');
4
+ var chunkBW4BLEIM_cjs = require('../chunk-BW4BLEIM.cjs');
5
+ require('../chunk-75ZPJI57.cjs');
6
+ var Stripe = require('stripe');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var Stripe__default = /*#__PURE__*/_interopDefault(Stripe);
11
+
12
+ async function handleWebhook(req, callbacks) {
13
+ const config = chunkE5YC2MHX_cjs.getConfig();
14
+ if (config.billing.provider !== "stripe") {
15
+ return new Response("Only Stripe webhooks supported", { status: 400 });
16
+ }
17
+ if (!config.billing.webhookSecret) {
18
+ throw new chunkBW4BLEIM_cjs.MirageDevError(
19
+ "CONFIG_INVALID",
20
+ "Webhook secret not configured"
21
+ );
22
+ }
23
+ try {
24
+ const body = await req.text();
25
+ const signature = req.headers.get("stripe-signature");
26
+ if (!signature) {
27
+ return new Response("Missing signature", { status: 400 });
28
+ }
29
+ const stripe = new Stripe__default.default(config.billing.stripeSecretKey, {
30
+ apiVersion: "2025-12-15.clover"
31
+ });
32
+ const event = stripe.webhooks.constructEvent(
33
+ body,
34
+ signature,
35
+ config.billing.webhookSecret
36
+ );
37
+ switch (event.type) {
38
+ case "checkout.session.completed": {
39
+ const session = event.data.object;
40
+ if (callbacks.onSubscriptionCreated && session.subscription) {
41
+ await callbacks.onSubscriptionCreated({
42
+ subscriptionId: session.subscription,
43
+ customerId: session.customer,
44
+ userId: session.client_reference_id || void 0
45
+ });
46
+ }
47
+ break;
48
+ }
49
+ case "customer.subscription.deleted": {
50
+ const subscription = event.data.object;
51
+ if (callbacks.onSubscriptionCanceled) {
52
+ await callbacks.onSubscriptionCanceled({
53
+ subscriptionId: subscription.id,
54
+ customerId: subscription.customer
55
+ });
56
+ }
57
+ break;
58
+ }
59
+ case "invoice.paid": {
60
+ const invoice = event.data.object;
61
+ if (callbacks.onInvoicePaid) {
62
+ await callbacks.onInvoicePaid({
63
+ invoiceId: invoice.id,
64
+ customerId: invoice.customer,
65
+ amount: invoice.amount_paid
66
+ });
67
+ }
68
+ break;
69
+ }
70
+ }
71
+ return new Response(JSON.stringify({ received: true }), {
72
+ status: 200,
73
+ headers: { "Content-Type": "application/json" }
74
+ });
75
+ } catch (error) {
76
+ console.error("Webhook error:", error);
77
+ return new Response(
78
+ JSON.stringify({ error: error.message }),
79
+ { status: 400, headers: { "Content-Type": "application/json" } }
80
+ );
81
+ }
82
+ }
83
+
84
+ exports.handleWebhook = handleWebhook;
@@ -0,0 +1,19 @@
1
+ interface WebhookCallbacks {
2
+ onSubscriptionCreated?: (data: {
3
+ subscriptionId: string;
4
+ customerId: string;
5
+ userId?: string;
6
+ }) => Promise<void>;
7
+ onSubscriptionCanceled?: (data: {
8
+ subscriptionId: string;
9
+ customerId: string;
10
+ }) => Promise<void>;
11
+ onInvoicePaid?: (data: {
12
+ invoiceId: string;
13
+ customerId: string;
14
+ amount: number;
15
+ }) => Promise<void>;
16
+ }
17
+ declare function handleWebhook(req: Request, callbacks: WebhookCallbacks): Promise<Response>;
18
+
19
+ export { type WebhookCallbacks, handleWebhook };
@@ -0,0 +1,19 @@
1
+ interface WebhookCallbacks {
2
+ onSubscriptionCreated?: (data: {
3
+ subscriptionId: string;
4
+ customerId: string;
5
+ userId?: string;
6
+ }) => Promise<void>;
7
+ onSubscriptionCanceled?: (data: {
8
+ subscriptionId: string;
9
+ customerId: string;
10
+ }) => Promise<void>;
11
+ onInvoicePaid?: (data: {
12
+ invoiceId: string;
13
+ customerId: string;
14
+ amount: number;
15
+ }) => Promise<void>;
16
+ }
17
+ declare function handleWebhook(req: Request, callbacks: WebhookCallbacks): Promise<Response>;
18
+
19
+ export { type WebhookCallbacks, handleWebhook };
@@ -0,0 +1,78 @@
1
+ import { getConfig } from '../chunk-5YXI4Q2K.js';
2
+ import { MirageDevError } from '../chunk-JUTTFY3W.js';
3
+ import '../chunk-MLKGABMK.js';
4
+ import Stripe from 'stripe';
5
+
6
+ async function handleWebhook(req, callbacks) {
7
+ const config = getConfig();
8
+ if (config.billing.provider !== "stripe") {
9
+ return new Response("Only Stripe webhooks supported", { status: 400 });
10
+ }
11
+ if (!config.billing.webhookSecret) {
12
+ throw new MirageDevError(
13
+ "CONFIG_INVALID",
14
+ "Webhook secret not configured"
15
+ );
16
+ }
17
+ try {
18
+ const body = await req.text();
19
+ const signature = req.headers.get("stripe-signature");
20
+ if (!signature) {
21
+ return new Response("Missing signature", { status: 400 });
22
+ }
23
+ const stripe = new Stripe(config.billing.stripeSecretKey, {
24
+ apiVersion: "2025-12-15.clover"
25
+ });
26
+ const event = stripe.webhooks.constructEvent(
27
+ body,
28
+ signature,
29
+ config.billing.webhookSecret
30
+ );
31
+ switch (event.type) {
32
+ case "checkout.session.completed": {
33
+ const session = event.data.object;
34
+ if (callbacks.onSubscriptionCreated && session.subscription) {
35
+ await callbacks.onSubscriptionCreated({
36
+ subscriptionId: session.subscription,
37
+ customerId: session.customer,
38
+ userId: session.client_reference_id || void 0
39
+ });
40
+ }
41
+ break;
42
+ }
43
+ case "customer.subscription.deleted": {
44
+ const subscription = event.data.object;
45
+ if (callbacks.onSubscriptionCanceled) {
46
+ await callbacks.onSubscriptionCanceled({
47
+ subscriptionId: subscription.id,
48
+ customerId: subscription.customer
49
+ });
50
+ }
51
+ break;
52
+ }
53
+ case "invoice.paid": {
54
+ const invoice = event.data.object;
55
+ if (callbacks.onInvoicePaid) {
56
+ await callbacks.onInvoicePaid({
57
+ invoiceId: invoice.id,
58
+ customerId: invoice.customer,
59
+ amount: invoice.amount_paid
60
+ });
61
+ }
62
+ break;
63
+ }
64
+ }
65
+ return new Response(JSON.stringify({ received: true }), {
66
+ status: 200,
67
+ headers: { "Content-Type": "application/json" }
68
+ });
69
+ } catch (error) {
70
+ console.error("Webhook error:", error);
71
+ return new Response(
72
+ JSON.stringify({ error: error.message }),
73
+ { status: 400, headers: { "Content-Type": "application/json" } }
74
+ );
75
+ }
76
+ }
77
+
78
+ export { handleWebhook };
@@ -0,0 +1,23 @@
1
+ type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'trialing' | 'none';
2
+ type Subscription = {
3
+ id: string;
4
+ status: SubscriptionStatus;
5
+ plan: string;
6
+ currentPeriodEnd: Date | null;
7
+ cancelAtPeriodEnd: boolean;
8
+ };
9
+ type BillingProvider = 'stripe' | 'paddle' | 'lemonsqueezy';
10
+ type BillingConfig = {
11
+ provider: BillingProvider;
12
+ stripeSecretKey?: string;
13
+ webhookSecret?: string;
14
+ };
15
+ type CheckoutOptions = {
16
+ priceId: string;
17
+ userId: string;
18
+ successUrl: string;
19
+ cancelUrl: string;
20
+ metadata?: Record<string, string>;
21
+ };
22
+
23
+ export type { BillingConfig as B, CheckoutOptions as C, Subscription as S, SubscriptionStatus as a, BillingProvider as b };
@@ -0,0 +1,23 @@
1
+ type SubscriptionStatus = 'active' | 'canceled' | 'past_due' | 'trialing' | 'none';
2
+ type Subscription = {
3
+ id: string;
4
+ status: SubscriptionStatus;
5
+ plan: string;
6
+ currentPeriodEnd: Date | null;
7
+ cancelAtPeriodEnd: boolean;
8
+ };
9
+ type BillingProvider = 'stripe' | 'paddle' | 'lemonsqueezy';
10
+ type BillingConfig = {
11
+ provider: BillingProvider;
12
+ stripeSecretKey?: string;
13
+ webhookSecret?: string;
14
+ };
15
+ type CheckoutOptions = {
16
+ priceId: string;
17
+ userId: string;
18
+ successUrl: string;
19
+ cancelUrl: string;
20
+ metadata?: Record<string, string>;
21
+ };
22
+
23
+ export type { BillingConfig as B, CheckoutOptions as C, Subscription as S, SubscriptionStatus as a, BillingProvider as b };