local-lite 2.0.0 → 2.0.2

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.
@@ -1,9 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { cp, mkdir, readdir } from 'node:fs/promises';
2
+ import { cp, mkdir, readdir, readFile } from 'node:fs/promises';
3
+ import { createRequire } from 'node:module';
3
4
  import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
6
+ import vm from 'node:vm';
5
7
 
6
- const skillsRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'skills');
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ const skillsRoot = path.resolve(__dirname, '..', 'skills');
7
10
  const targets = {
8
11
  copilot: '.github/skills',
9
12
  claude: '.claude/skills',
@@ -13,14 +16,15 @@ const targets = {
13
16
  agent: '.agent/skills',
14
17
  };
15
18
 
16
- const usage = `Usage: local-lite install-skills [--target copilot|claude|antigravity|cursor|agent] [--dir <path>] [--force]
19
+ const usage = `Usage:
20
+ local-lite install-skills [--target copilot|claude|antigravity|cursor|agent] [--dir <path>] [--force]
21
+ local-lite db:generate --schema <path> [--tables <path>] [--out <dir>] [--name <name>] [--dialect mysql|postgres|sqlite] [--server-schema <path>] [--dry-run]
17
22
 
18
- Copies the bundled AI skills into your project.
19
- --target copilot (default, .github/skills), claude (.claude/skills), antigravity (.gemini/skills), cursor (.cursor/skills), agent (.agent/skills)
20
- --dir custom destination directory (overrides --target)
21
- --force overwrite existing skill files`;
23
+ Commands:
24
+ install-skills Copy bundled AI skills into your project.
25
+ db:generate Generate incremental SQL migrations from a schema dictionary.`;
22
26
 
23
- function parseArgs(argv) {
27
+ function parseSkillsArgs(argv) {
24
28
  const options = { target: 'copilot', dir: undefined, force: false };
25
29
  for (let i = 0; i < argv.length; i++) {
26
30
  const arg = argv[i];
@@ -37,6 +41,76 @@ function parseArgs(argv) {
37
41
  return options;
38
42
  }
39
43
 
44
+ function parseDbGenArgs(argv) {
45
+ const options = {
46
+ schema: undefined,
47
+ tables: undefined,
48
+ out: 'server/migrations',
49
+ name: 'auto_schema',
50
+ dialect: 'mysql',
51
+ serverSchema: undefined,
52
+ dryRun: false,
53
+ };
54
+ for (let i = 0; i < argv.length; i++) {
55
+ const arg = argv[i];
56
+ if (arg === '--dry-run') options.dryRun = true;
57
+ else if (arg === '--schema') options.schema = argv[++i];
58
+ else if (arg === '--tables') options.tables = argv[++i];
59
+ else if (arg === '--out') options.out = argv[++i];
60
+ else if (arg === '--name') options.name = argv[++i];
61
+ else if (arg === '--dialect') options.dialect = argv[++i];
62
+ else if (arg === '--server-schema') options.serverSchema = argv[++i];
63
+ else if (arg !== '--') throw new Error(`Unknown option: ${arg}`);
64
+ }
65
+ if (!options.schema) {
66
+ throw new Error('--schema <path> is required for db:generate.');
67
+ }
68
+ if (!['mysql', 'postgres', 'sqlite'].includes(options.dialect)) {
69
+ throw new Error(`Unsupported dialect "${options.dialect}". Use mysql, postgres, or sqlite.`);
70
+ }
71
+ return options;
72
+ }
73
+
74
+ async function loadModuleExports(filePath) {
75
+ const absPath = path.resolve(process.cwd(), filePath);
76
+ if (absPath.endsWith('.json')) {
77
+ return JSON.parse(await readFile(absPath, 'utf8'));
78
+ }
79
+ if (!absPath.endsWith('.ts') && !absPath.endsWith('.mts')) {
80
+ return await import(pathToFileURL(absPath).href);
81
+ }
82
+
83
+ try {
84
+ return await import(pathToFileURL(absPath).href);
85
+ } catch {
86
+ const requireFromCwd = createRequire(path.join(process.cwd(), 'package.json'));
87
+ let ts;
88
+ try {
89
+ ts = requireFromCwd('typescript');
90
+ } catch {
91
+ throw new Error(
92
+ `Cannot load TypeScript file "${filePath}". Install "typescript" in your project or pass a .js/.mjs/.json file.`,
93
+ );
94
+ }
95
+ const source = await readFile(absPath, 'utf8');
96
+ const transpiled = ts.transpileModule(source, {
97
+ compilerOptions: {
98
+ module: ts.ModuleKind.CommonJS,
99
+ target: ts.ScriptTarget.ES2022,
100
+ esModuleInterop: true,
101
+ },
102
+ fileName: absPath,
103
+ });
104
+ const moduleObj = { exports: {} };
105
+ const fn = new vm.Script(
106
+ `(function(exports, require, module) {\n${transpiled.outputText}\n})`,
107
+ { filename: absPath },
108
+ );
109
+ fn.runInThisContext()(moduleObj.exports, () => ({}), moduleObj);
110
+ return moduleObj.exports;
111
+ }
112
+ }
113
+
40
114
  async function installSkills(options) {
41
115
  const destination = path.resolve(process.cwd(), options.dir ?? targets[options.target]);
42
116
  await mkdir(destination, { recursive: true });
@@ -51,10 +125,60 @@ async function installSkills(options) {
51
125
  }
52
126
  }
53
127
 
128
+ async function runDbGen(options) {
129
+ const { generateSqlMigration } = await import(
130
+ pathToFileURL(path.resolve(__dirname, '..', 'dist', 'schema', 'index.js')).href
131
+ );
132
+ const schemaExports = await loadModuleExports(options.schema);
133
+ const dictionary =
134
+ schemaExports.SCHEMA_DICTIONARY || schemaExports.default || schemaExports;
135
+
136
+ let tableOrder = [];
137
+ if (options.tables) {
138
+ const tablesExports = await loadModuleExports(options.tables);
139
+ tableOrder = tablesExports.CORE_TABLES || tablesExports.default || [];
140
+ }
141
+
142
+ const result = generateSqlMigration({
143
+ dictionary,
144
+ tableOrder,
145
+ dialect: options.dialect,
146
+ migrationsDir: path.resolve(process.cwd(), options.out),
147
+ name: options.name,
148
+ dryRun: options.dryRun,
149
+ serverSchemaPath: options.serverSchema
150
+ ? path.resolve(process.cwd(), options.serverSchema)
151
+ : undefined,
152
+ });
153
+
154
+ for (const warning of result.warnings) {
155
+ console.warn(`[warn] ${warning}`);
156
+ }
157
+
158
+ if (result.up.length === 0) {
159
+ console.log('No schema changes detected.');
160
+ return;
161
+ }
162
+
163
+ if (options.dryRun) {
164
+ console.log(result.sql);
165
+ return;
166
+ }
167
+
168
+ if (result.migrationPath) {
169
+ console.log(`Generated migration: ${path.relative(process.cwd(), result.migrationPath)}`);
170
+ }
171
+ if (result.serverSchemaPath) {
172
+ console.log(`Updated schema map: ${path.relative(process.cwd(), result.serverSchemaPath)}`);
173
+ }
174
+ }
175
+
54
176
  const [command, ...rest] = process.argv.slice(2);
55
177
  try {
56
178
  if (command === 'install-skills') {
57
- await installSkills(parseArgs(rest));
179
+ await installSkills(parseSkillsArgs(rest));
180
+ } else if (command === 'db:generate') {
181
+ await runDbGen(parseDbGenArgs(rest));
58
182
  } else {
59
183
  console.log(usage);
60
184
  process.exitCode = command && command !== '--help' && command !== '-h' ? 1 : 0;
package/dist/index.d.ts CHANGED
@@ -28,3 +28,4 @@ export * from './kv/index.js';
28
28
  export * from './search/index.js';
29
29
  export * from './storage/index.js';
30
30
  export * from './scheduler/index.js';
31
+ export * from './payments/index.js';
package/dist/index.js CHANGED
@@ -44,3 +44,4 @@ __exportStar(require("./kv/index.js"), exports);
44
44
  __exportStar(require("./search/index.js"), exports);
45
45
  __exportStar(require("./storage/index.js"), exports);
46
46
  __exportStar(require("./scheduler/index.js"), exports);
47
+ __exportStar(require("./payments/index.js"), exports);
@@ -0,0 +1,49 @@
1
+ import type { PaymentProviderAdapter } from './types.js';
2
+ export declare function formatKenyanPhone(phone: string | number): string;
3
+ export interface ManualPaymentAdapterOptions {
4
+ id?: string;
5
+ label?: string;
6
+ description?: string;
7
+ supportedCurrencies?: string[] | '*';
8
+ }
9
+ /**
10
+ * Offline-capable manual payment adapter (cash, bank transfer, cheque, etc.).
11
+ */
12
+ export declare function createManualPaymentAdapter(options?: ManualPaymentAdapterOptions): PaymentProviderAdapter;
13
+ export interface DarajaAdapterOptions {
14
+ consumerKey: string;
15
+ consumerSecret: string;
16
+ shortcode: string;
17
+ passkey: string;
18
+ callbackUrl: string;
19
+ env?: 'sandbox' | 'live' | 'production';
20
+ apiUrl?: string;
21
+ partyB?: string;
22
+ transactionType?: string;
23
+ fetch?: typeof fetch;
24
+ }
25
+ /**
26
+ * Safaricom M-Pesa Daraja STK Push adapter (Kenya / KES).
27
+ */
28
+ export declare function createDarajaAdapter(options: DarajaAdapterOptions): PaymentProviderAdapter;
29
+ export interface PaystackAdapterOptions {
30
+ secretKey: string;
31
+ supportedCurrencies?: string[];
32
+ supportedCountries?: string[] | '*';
33
+ fetch?: typeof fetch;
34
+ }
35
+ /**
36
+ * Paystack Checkout adapter (NGN, GHS, ZAR, KES, USD, etc.).
37
+ */
38
+ export declare function createPaystackAdapter(options: PaystackAdapterOptions): PaymentProviderAdapter;
39
+ export interface StripeCheckoutAdapterOptions {
40
+ secretKey: string;
41
+ webhookSecret?: string;
42
+ supportedCurrencies?: string[] | '*';
43
+ supportedCountries?: string[] | '*';
44
+ fetch?: typeof fetch;
45
+ }
46
+ /**
47
+ * Stripe Checkout Session adapter for global card/wallet/bank payments.
48
+ */
49
+ export declare function createStripeCheckoutAdapter(options: StripeCheckoutAdapterOptions): PaymentProviderAdapter;