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,16 @@
1
+ // src/errors.ts
2
+ var MirageDevError = class _MirageDevError extends Error {
3
+ code;
4
+ details;
5
+ constructor(code, message, details) {
6
+ super(message);
7
+ this.name = "MirageDevError";
8
+ this.code = code;
9
+ this.details = details;
10
+ if (Error.captureStackTrace) {
11
+ Error.captureStackTrace(this, _MirageDevError);
12
+ }
13
+ }
14
+ };
15
+
16
+ export { MirageDevError };
@@ -0,0 +1,280 @@
1
+ 'use strict';
2
+
3
+ var inquirer = require('inquirer');
4
+ var chalk = require('chalk');
5
+ var ora = require('ora');
6
+ var fs = require('fs/promises');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
11
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
12
+ var ora__default = /*#__PURE__*/_interopDefault(ora);
13
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
14
+
15
+ // cli/commands/init.ts
16
+ async function initCommand() {
17
+ console.log(chalk__default.default.blue.bold("\n\u{1F680} MirageDev SDK Setup\n"));
18
+ const answers = await inquirer__default.default.prompt([
19
+ {
20
+ type: "list",
21
+ name: "authProvider",
22
+ message: "Choose your auth provider:",
23
+ choices: [
24
+ { name: "NextAuth.js", value: "nextauth" },
25
+ { name: "Clerk", value: "clerk" },
26
+ { name: "Supabase Auth", value: "supabase" }
27
+ ],
28
+ default: "nextauth"
29
+ },
30
+ {
31
+ type: "list",
32
+ name: "billingProvider",
33
+ message: "Choose your billing provider:",
34
+ choices: [
35
+ { name: "Stripe", value: "stripe" },
36
+ { name: "Paddle", value: "paddle" },
37
+ { name: "LemonSqueezy", value: "lemonsqueezy" }
38
+ ],
39
+ default: "stripe"
40
+ },
41
+ {
42
+ type: "list",
43
+ name: "emailProvider",
44
+ message: "Choose your email provider:",
45
+ choices: [
46
+ { name: "Resend", value: "resend" },
47
+ { name: "SendGrid", value: "sendgrid" },
48
+ { name: "Postmark", value: "postmark" }
49
+ ],
50
+ default: "resend"
51
+ },
52
+ {
53
+ type: "checkbox",
54
+ name: "features",
55
+ message: "Select additional features:",
56
+ choices: [
57
+ { name: "PWA Support", value: "pwa", checked: true },
58
+ { name: "Biometric Auth", value: "biometric", checked: false },
59
+ { name: "Mobile Optimizations", value: "mobile", checked: true }
60
+ ]
61
+ }
62
+ ]);
63
+ const spinner = ora__default.default("Generating configuration files...").start();
64
+ try {
65
+ await generateConfigFile(answers);
66
+ await generateEnvTemplate(answers);
67
+ await generateInitFile(answers);
68
+ await generateAgentRules(answers);
69
+ spinner.succeed(chalk__default.default.green("Configuration files created!"));
70
+ console.log(chalk__default.default.cyan("\n\u{1F4DD} Next steps:\n"));
71
+ console.log("1. Fill in your API keys in .env.local");
72
+ console.log("2. Import and call initMirageDev() in your app");
73
+ console.log("3. Start building your SAAS! \u{1F389}\n");
74
+ console.log(chalk__default.default.gray("Documentation: https://github.com/yourusername/miragedev-sdk\n"));
75
+ } catch (error) {
76
+ spinner.fail(chalk__default.default.red("Failed to generate files"));
77
+ console.error(error);
78
+ process.exit(1);
79
+ }
80
+ }
81
+ async function generateConfigFile(answers) {
82
+ const config = `// MirageDev SDK Configuration
83
+ import { initMirageDev } from 'miragedev-sdk'
84
+
85
+ export function initializeMirageDev() {
86
+ initMirageDev({
87
+ auth: {
88
+ provider: '${answers.authProvider}',
89
+ sessionSecret: process.env.AUTH_SECRET!,
90
+ },
91
+ billing: {
92
+ provider: '${answers.billingProvider}',
93
+ ${answers.billingProvider === "stripe" ? "stripeSecretKey: process.env.STRIPE_SECRET_KEY!," : ""}
94
+ webhookSecret: process.env.${answers.billingProvider.toUpperCase()}_WEBHOOK_SECRET!,
95
+ },
96
+ email: {
97
+ provider: '${answers.emailProvider}',
98
+ apiKey: process.env.${answers.emailProvider.toUpperCase()}_API_KEY!,
99
+ from: process.env.EMAIL_FROM!,
100
+ },
101
+ })
102
+ }
103
+ `;
104
+ await fs__default.default.writeFile("miragedev.config.ts", config, "utf-8");
105
+ }
106
+ async function generateEnvTemplate(answers) {
107
+ const env = `# MirageDev SDK Environment Variables
108
+
109
+ # Auth
110
+ AUTH_SECRET=your-secret-key-here
111
+
112
+ # Billing (${answers.billingProvider})
113
+ ${answers.billingProvider === "stripe" ? "STRIPE_SECRET_KEY=sk_test_xxx" : ""}
114
+ ${answers.billingProvider.toUpperCase()}_WEBHOOK_SECRET=whsec_xxx
115
+
116
+ # Email (${answers.emailProvider})
117
+ ${answers.emailProvider.toUpperCase()}_API_KEY=your-api-key-here
118
+ EMAIL_FROM=noreply@yourapp.com
119
+ `;
120
+ const envPath = ".env.local.example";
121
+ await fs__default.default.writeFile(envPath, env, "utf-8");
122
+ }
123
+ async function generateInitFile(answers) {
124
+ const hasFeature = (feature) => answers.features.includes(feature);
125
+ const imports = [];
126
+ const setup = [];
127
+ if (hasFeature("pwa")) {
128
+ imports.push("import { configurePWA } from 'miragedev-sdk/pwa'");
129
+ setup.push(`
130
+ // PWA Configuration
131
+ export const pwaConfig = configurePWA({
132
+ name: 'Your App Name',
133
+ theme: '#000000',
134
+ offline: { enabled: true, pages: ['/'] }
135
+ })`);
136
+ }
137
+ const content = `// MirageDev SDK Initialization
138
+ import { initializeMirageDev } from './miragedev.config'
139
+ ${imports.join("\n")}
140
+
141
+ // Initialize SDK
142
+ initializeMirageDev()
143
+
144
+ ${setup.join("\n\n")}
145
+ `;
146
+ await fs__default.default.writeFile("miragedev.init.ts", content, "utf-8");
147
+ }
148
+ async function generateAgentRules(answers) {
149
+ const modules = ["auth", "billing", "email"];
150
+ if (answers.features.includes("pwa")) modules.push("pwa");
151
+ if (answers.features.includes("mobile")) modules.push("mobile");
152
+ if (answers.features.includes("biometric")) modules.push("auth/biometric");
153
+ const content = `# AI Agent Instructions
154
+
155
+ > **For AI Assistants (GitHub Copilot, OpenCode, Cursor, etc.):**
156
+ > This project uses **MirageDev SDK**. Always prefer SDK functions over manual implementations.
157
+
158
+ ## Installed SDK Modules
159
+
160
+ ${modules.map((mod) => `- \`miragedev-sdk/${mod}\` - ${getModuleDescription(mod)}`).join("\n")}
161
+
162
+ ## Configuration
163
+
164
+ - **Auth Provider:** ${answers.authProvider}
165
+ - **Billing Provider:** ${answers.billingProvider}
166
+ - **Email Provider:** ${answers.emailProvider}
167
+ ${answers.features.includes("pwa") ? "- **PWA:** Enabled" : ""}
168
+ ${answers.features.includes("biometric") ? "- **Biometric Auth:** Enabled" : ""}
169
+ ${answers.features.includes("mobile") ? "- **Mobile Optimizations:** Enabled" : ""}
170
+
171
+ ## Code Generation Rules
172
+
173
+ ### \u2705 DO: Use MirageDev SDK
174
+
175
+ When developer needs authentication:
176
+ \`\`\`typescript
177
+ // \u2705 CORRECT
178
+ import { requireAuth } from 'miragedev-sdk/auth'
179
+
180
+ export default async function Page() {
181
+ const session = await requireAuth()
182
+ return <div>Hello {session.user.name}</div>
183
+ }
184
+ \`\`\`
185
+
186
+ When developer needs billing:
187
+ \`\`\`typescript
188
+ // \u2705 CORRECT
189
+ import { createCheckout } from 'miragedev-sdk/billing'
190
+
191
+ const { url } = await createCheckout({
192
+ priceId: 'price_xxx',
193
+ userId: session.user.id,
194
+ successUrl: '/success',
195
+ cancelUrl: '/cancel',
196
+ })
197
+ \`\`\`
198
+
199
+ When developer needs email:
200
+ \`\`\`typescript
201
+ // \u2705 CORRECT
202
+ import { sendTemplateEmail } from 'miragedev-sdk/email'
203
+
204
+ await sendTemplateEmail({
205
+ to: user.email,
206
+ template: 'welcome',
207
+ data: { userName: user.name }
208
+ })
209
+ \`\`\`
210
+
211
+ ### \u274C DON'T: Manual Implementation
212
+
213
+ \`\`\`typescript
214
+ // \u274C WRONG - Don't do this when SDK exists
215
+ import Stripe from 'stripe'
216
+ const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
217
+ // ... manual implementation
218
+ \`\`\`
219
+
220
+ ## Discovery & Documentation
221
+
222
+ - **JSDoc Examples:** Every SDK function has \`@example\` tags - read them!
223
+ - **TypeScript Types:** Check types for exact parameters
224
+ - **Full Docs:** See \`node_modules/miragedev-sdk/README.md\`
225
+ - **Examples:** Check SDK's \`examples/\` directory for patterns
226
+
227
+ ## Module Reference
228
+
229
+ ### Authentication (\`miragedev-sdk/auth\`)
230
+ - \`requireAuth()\` - Server-side, throws if not authenticated
231
+ - \`getSession()\` - Server-side, returns session or null
232
+ - \`useSession()\` - Client hook from \`/auth/client\`
233
+ - \`authMiddleware()\` - Next.js middleware from \`/auth/middleware\`
234
+ ${answers.features.includes("biometric") ? "- `enableBiometric()`, `signInWithBiometric()` - from `/auth/biometric`" : ""}
235
+
236
+ ### Billing (\`miragedev-sdk/billing\`)
237
+ - \`createCheckout()\` - Create Stripe checkout session
238
+ - \`createPortal()\` - Create billing portal session
239
+ - \`getSubscription()\` - Get subscription status
240
+ - \`handleWebhook()\` - Process Stripe webhooks from \`/billing/webhook\`
241
+ - \`useSubscription()\` - Client hook from \`/billing/client\`
242
+
243
+ ### Email (\`miragedev-sdk/email\`)
244
+ - \`sendEmail()\` - Send basic email
245
+ - \`sendTemplateEmail()\` - Send with template (welcome, reset-password, etc)
246
+
247
+ ${answers.features.includes("pwa") ? `### PWA (\`miragedev-sdk/pwa\`)
248
+ - \`configurePWA()\` - Generate manifest and service worker` : ""}
249
+
250
+ ${answers.features.includes("mobile") ? `### Mobile (\`miragedev-sdk/mobile\`)
251
+ - \`useNetworkStatus()\` - Online/offline detection
252
+ - \`useInstallPrompt()\` - PWA install prompt
253
+ - \`useNotifications()\` - Push notifications
254
+ - \`usePullToRefresh()\` - Pull-to-refresh gesture` : ""}
255
+
256
+ ## Important Notes
257
+
258
+ 1. SDK is already initialized in \`miragedev.config.ts\`
259
+ 2. All async SDK functions should be wrapped in try/catch
260
+ 3. SDK throws \`MirageDevError\` with error codes - handle them
261
+ 4. For NEW features not in SDK, implement normally - but check SDK first!
262
+
263
+ ---
264
+ *Generated by MirageDev SDK CLI - Updated when you add new modules*
265
+ `;
266
+ await fs__default.default.writeFile("AGENTS.md", content, "utf-8");
267
+ }
268
+ function getModuleDescription(module) {
269
+ const descriptions = {
270
+ "auth": "requireAuth(), getSession(), middleware",
271
+ "auth/biometric": "enableBiometric(), signInWithBiometric()",
272
+ "billing": "createCheckout(), createPortal(), webhooks",
273
+ "email": "sendEmail(), sendTemplateEmail() with 5 templates",
274
+ "pwa": "configurePWA(), manifest + service worker",
275
+ "mobile": "useNetworkStatus(), useInstallPrompt(), etc"
276
+ };
277
+ return descriptions[module] || "Available functions";
278
+ }
279
+
280
+ exports.initCommand = initCommand;
@@ -0,0 +1,23 @@
1
+ import { getConfig } from './chunk-5YXI4Q2K.js';
2
+ import { MirageDevError } from './chunk-JUTTFY3W.js';
3
+
4
+ // src/auth/index.ts
5
+ async function getSession() {
6
+ const config = getConfig();
7
+ if (config.auth.provider === "nextauth") {
8
+ return null;
9
+ }
10
+ return null;
11
+ }
12
+ async function requireAuth() {
13
+ const session = await getSession();
14
+ if (!session) {
15
+ throw new MirageDevError(
16
+ "AUTH_REQUIRED",
17
+ "Authentication required. Please sign in to access this resource."
18
+ );
19
+ }
20
+ return session;
21
+ }
22
+
23
+ export { getSession, requireAuth };
@@ -0,0 +1,7 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export { __export };
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ var chunkE5YC2MHX_cjs = require('./chunk-E5YC2MHX.cjs');
4
+ var chunkBW4BLEIM_cjs = require('./chunk-BW4BLEIM.cjs');
5
+
6
+ // src/auth/index.ts
7
+ async function getSession() {
8
+ const config = chunkE5YC2MHX_cjs.getConfig();
9
+ if (config.auth.provider === "nextauth") {
10
+ return null;
11
+ }
12
+ return null;
13
+ }
14
+ async function requireAuth() {
15
+ const session = await getSession();
16
+ if (!session) {
17
+ throw new chunkBW4BLEIM_cjs.MirageDevError(
18
+ "AUTH_REQUIRED",
19
+ "Authentication required. Please sign in to access this resource."
20
+ );
21
+ }
22
+ return session;
23
+ }
24
+
25
+ exports.getSession = getSession;
26
+ exports.requireAuth = requireAuth;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ var chunkM26EDKMY_cjs = require('../../chunk-M26EDKMY.cjs');
4
+ require('../../chunk-75ZPJI57.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, "initCommand", {
9
+ enumerable: true,
10
+ get: function () { return chunkM26EDKMY_cjs.initCommand; }
11
+ });
@@ -0,0 +1,3 @@
1
+ declare function initCommand(): Promise<void>;
2
+
3
+ export { initCommand };
@@ -0,0 +1,3 @@
1
+ declare function initCommand(): Promise<void>;
2
+
3
+ export { initCommand };
@@ -0,0 +1,2 @@
1
+ export { initCommand } from '../../chunk-DZDDLA4G.js';
2
+ import '../../chunk-MLKGABMK.js';
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var chunkM26EDKMY_cjs = require('../chunk-M26EDKMY.cjs');
5
+ require('../chunk-75ZPJI57.cjs');
6
+ var commander = require('commander');
7
+
8
+ var program = new commander.Command();
9
+ program.name("miragedev").description("MirageDev SDK CLI - Build SAAS apps faster").version("0.1.0");
10
+ program.command("init").description("Initialize MirageDev SDK in your project").action(chunkM26EDKMY_cjs.initCommand);
11
+ program.parse();
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ import { initCommand } from '../chunk-DZDDLA4G.js';
3
+ import '../chunk-MLKGABMK.js';
4
+ import { Command } from 'commander';
5
+
6
+ var program = new Command();
7
+ program.name("miragedev").description("MirageDev SDK CLI - Build SAAS apps faster").version("0.1.0");
8
+ program.command("init").description("Initialize MirageDev SDK in your project").action(initCommand);
9
+ program.parse();