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