@porulle/cli 0.1.0 → 0.5.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.
@@ -13,6 +13,14 @@ export declare const apiKeyCreateCommand: import("citty").CommandDef<{
13
13
  type: "string";
14
14
  description: string;
15
15
  };
16
+ ttl: {
17
+ type: "string";
18
+ description: string;
19
+ };
20
+ user: {
21
+ type: "string";
22
+ description: string;
23
+ };
16
24
  "save-env": {
17
25
  type: "boolean";
18
26
  description: string;
@@ -1 +1 @@
1
- {"version":3,"file":"api-key.d.ts","sourceRoot":"","sources":["../../src/commands/api-key.ts"],"names":[],"mappings":"AAgGA,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;EAyH9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;EA+B5B,CAAC;AAEH,eAAO,MAAM,aAAa,qDASxB,CAAC"}
1
+ {"version":3,"file":"api-key.d.ts","sourceRoot":"","sources":["../../src/commands/api-key.ts"],"names":[],"mappings":"AAgGA,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+J9B,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;EA+B5B,CAAC;AAEH,eAAO,MAAM,aAAa,qDASxB,CAAC"}
@@ -69,6 +69,14 @@ export const apiKeyCreateCommand = defineCommand({
69
69
  type: "string",
70
70
  description: "Key name (default: scope name)",
71
71
  },
72
+ ttl: {
73
+ type: "string",
74
+ description: "Time-to-live in seconds (Better Auth minExpiresIn is 1 day = 86400)",
75
+ },
76
+ user: {
77
+ type: "string",
78
+ description: "Bind the key to a specific user id (default: an ops admin user)",
79
+ },
72
80
  "save-env": {
73
81
  type: "boolean",
74
82
  description: "Save key to .env.local",
@@ -104,14 +112,29 @@ export const apiKeyCreateCommand = defineCommand({
104
112
  process.exit(1);
105
113
  }
106
114
  console.log(`Creating ${args.scope} API key...`);
107
- // Find or create an admin user for key ownership
108
- const userId = await findOrCreateAdminUser(app, config);
115
+ // Optional TTL Better Auth enforces a 1-day minimum (minExpiresIn).
116
+ let expiresIn;
117
+ if (args.ttl) {
118
+ const ttl = Number(args.ttl);
119
+ if (!Number.isFinite(ttl) || ttl <= 0) {
120
+ console.error("--ttl must be a positive number of seconds.");
121
+ process.exit(1);
122
+ }
123
+ if (ttl < 86400) {
124
+ console.error("--ttl must be at least 86400 seconds (1 day) — Better Auth minExpiresIn.");
125
+ process.exit(1);
126
+ }
127
+ expiresIn = ttl;
128
+ }
129
+ // Bind to the requested user, or find/create an ops admin for ownership.
130
+ const userId = args.user ?? (await findOrCreateAdminUser(app, config));
109
131
  const result = await auth.api.createApiKey({
110
132
  body: {
111
133
  configId: args.scope,
112
134
  userId,
113
135
  name: args.name ?? `${args.scope}-key`,
114
136
  permissions: scopeDef.permissions,
137
+ ...(expiresIn ? { expiresIn } : {}),
115
138
  ...(scopeDef.rateLimit
116
139
  ? {
117
140
  rateLimitEnabled: true,
@@ -155,8 +178,20 @@ export const apiKeyCreateCommand = defineCommand({
155
178
  }
156
179
  console.log(` Saved to: .env.local as ${varName}`);
157
180
  }
181
+ if (expiresIn) {
182
+ console.log(` Expires in: ${expiresIn}s`);
183
+ }
184
+ console.log(` Owner: ${userId}`);
185
+ console.log("");
186
+ console.log(" ── Use it ──────────────────────────────────────────────");
187
+ console.log(` curl -H "x-api-key: ${result.key}" http://localhost:4000/api/health`);
188
+ console.log(" ── Revoke it ───────────────────────────────────────────");
189
+ console.log(` curl -X DELETE -H "x-api-key: ${result.key}" \\`);
190
+ console.log(` http://localhost:4000/api/api-keys/${result.id}`);
191
+ console.log(" ────────────────────────────────────────────────────────");
158
192
  console.log("");
159
- console.log("This is the only time the full key is shown. Store it securely.");
193
+ console.log("This is the only time the full key is shown Better Auth hashes it");
194
+ console.log("at rest. Copy it now; if you lose it, mint a new one.");
160
195
  process.exit(0);
161
196
  },
162
197
  });
@@ -1 +1 @@
1
- {"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/commands/import.ts"],"names":[],"mappings":"AAwJA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2KxB,CAAC"}
1
+ {"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/commands/import.ts"],"names":[],"mappings":"AAyKA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuLxB,CAAC"}
@@ -2,12 +2,27 @@ import { readFile } from "node:fs/promises";
2
2
  import { extname, resolve } from "node:path";
3
3
  import { defineCommand } from "citty";
4
4
  import consola from "consola";
5
- // @ts-ignore — missing type declarations
6
- import { importFlat } from "@porulle/import-flat";
7
- // @ts-ignore missing type declarations
8
- import { importShopifyCatalog } from "@porulle/import-shopify";
9
- // @ts-ignore missing type declarations
10
- import { importWooCommerceCatalog } from "@porulle/import-woocommerce";
5
+ /**
6
+ * The import adapters (`@porulle/import-flat`, `@porulle/import-shopify`,
7
+ * `@porulle/import-woocommerce`) are optional dependencies, loaded on demand
8
+ * only when the matching `import` source is invoked. This keeps the CLI
9
+ * installable and bootable even when the adapters aren't present, instead of
10
+ * the whole CLI failing to load when a single optional package is missing.
11
+ */
12
+ async function loadImporter(pkg, named) {
13
+ let mod;
14
+ try {
15
+ mod = (await import(pkg));
16
+ }
17
+ catch {
18
+ throw new Error(`The "${pkg}" import adapter is not installed. Install it to use this importer:\n bun add ${pkg}`);
19
+ }
20
+ const fn = mod[named];
21
+ if (typeof fn !== "function") {
22
+ throw new Error(`"${pkg}" did not export "${named}".`);
23
+ }
24
+ return fn;
25
+ }
11
26
  function toBaseUrl(raw) {
12
27
  return (raw ?? "http://localhost:3000").replace(/\/$/, "");
13
28
  }
@@ -146,6 +161,7 @@ export const importCommand = defineCommand({
146
161
  customers = parsed.customers;
147
162
  }
148
163
  }
164
+ const importShopifyCatalog = await loadImporter("@porulle/import-shopify", "importShopifyCatalog");
149
165
  const imported = await importShopifyCatalog({
150
166
  target,
151
167
  ...(args.storeUrl ? { storeUrl: String(args.storeUrl) } : {}),
@@ -179,6 +195,7 @@ export const importCommand = defineCommand({
179
195
  customers = parsed.customers;
180
196
  }
181
197
  }
198
+ const importWooCommerceCatalog = await loadImporter("@porulle/import-woocommerce", "importWooCommerceCatalog");
182
199
  const imported = await importWooCommerceCatalog({
183
200
  target,
184
201
  ...(args.storeUrl ? { storeUrl: String(args.storeUrl) } : {}),
@@ -214,6 +231,7 @@ export const importCommand = defineCommand({
214
231
  const inputPath = resolve(process.cwd(), String(args.input));
215
232
  const raw = await readFile(inputPath, "utf8");
216
233
  const extension = extname(inputPath).toLowerCase();
234
+ const importFlat = await loadImporter("@porulle/import-flat", "importFlat");
217
235
  const imported = await importFlat({
218
236
  mapping: mappingParsed,
219
237
  target: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porulle/cli",
3
- "version": "0.1.0",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,18 +14,20 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "postgres": "^3.4.7",
17
- "@porulle/import-flat": "workspace:*",
18
- "@porulle/import-shopify": "workspace:*",
19
- "@porulle/import-woocommerce": "workspace:*",
20
17
  "citty": "^0.1.6",
21
18
  "consola": "^3.4.2",
22
19
  "giget": "^2.0.0"
23
20
  },
21
+ "optionalDependencies": {
22
+ "@porulle/import-flat": "^0.5.0",
23
+ "@porulle/import-shopify": "^0.5.0",
24
+ "@porulle/import-woocommerce": "^0.5.0"
25
+ },
24
26
  "devDependencies": {
25
27
  "@electric-sql/pglite": "0.4.5",
26
28
  "@electric-sql/pglite-socket": "^0.1.5",
27
- "@repo/eslint-config": "*",
28
- "@repo/typescript-config": "*",
29
+ "@porulle/eslint-config": "*",
30
+ "@porulle/typescript-config": "*",
29
31
  "@types/node": "^24.5.2",
30
32
  "drizzle-kit": "^0.31.9",
31
33
  "eslint": "^9.39.1",