@porulle/cli 0.1.0 → 0.6.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/dist/commands/api-key.d.ts +8 -0
- package/dist/commands/api-key.d.ts.map +1 -1
- package/dist/commands/api-key.js +38 -3
- package/dist/commands/import.d.ts.map +1 -1
- package/dist/commands/import.js +24 -6
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +31 -0
- package/dist/index.js +0 -0
- package/package.json +17 -15
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 unified-commerce-engine contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -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
|
|
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"}
|
package/dist/commands/api-key.js
CHANGED
|
@@ -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
|
-
//
|
|
108
|
-
|
|
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
|
|
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":"
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../../src/commands/import.ts"],"names":[],"mappings":"AAyKA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuLxB,CAAC"}
|
package/dist/commands/import.js
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
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/dist/commands/init.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
interface PackageJsonShape {
|
|
2
|
+
name?: string;
|
|
3
|
+
version?: string;
|
|
4
|
+
[key: string]: unknown;
|
|
5
|
+
}
|
|
6
|
+
export declare function pinPorulleDependencies(pkg: PackageJsonShape, version: string): void;
|
|
1
7
|
export declare const initCommand: import("citty").CommandDef<{
|
|
2
8
|
projectName: {
|
|
3
9
|
type: "positional";
|
|
@@ -9,4 +15,5 @@ export declare const initCommand: import("citty").CommandDef<{
|
|
|
9
15
|
default: string;
|
|
10
16
|
};
|
|
11
17
|
}>;
|
|
18
|
+
export {};
|
|
12
19
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAUA,UAAU,gBAAgB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAaD,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,gBAAgB,EACrB,OAAO,EAAE,MAAM,GACd,IAAI,CAWN;AASD,eAAO,MAAM,WAAW;;;;;;;;;;EAmDtB,CAAC"}
|
package/dist/commands/init.js
CHANGED
|
@@ -6,6 +6,33 @@ import consola from "consola";
|
|
|
6
6
|
import { downloadTemplate } from "giget";
|
|
7
7
|
import { copyDir, readJson, writeJson } from "../utils.js";
|
|
8
8
|
const currentDir = fileURLToPath(new URL(".", import.meta.url));
|
|
9
|
+
const DEP_SECTIONS = [
|
|
10
|
+
"dependencies",
|
|
11
|
+
"devDependencies",
|
|
12
|
+
"peerDependencies",
|
|
13
|
+
"optionalDependencies",
|
|
14
|
+
];
|
|
15
|
+
// Scaffolded projects must pin @porulle/* to the version of the CLI that
|
|
16
|
+
// created them: the packages are a fixed-version group, so the running CLI's
|
|
17
|
+
// own version is the correct, coherent target. A literal range baked into the
|
|
18
|
+
// template would go stale on every release.
|
|
19
|
+
export function pinPorulleDependencies(pkg, version) {
|
|
20
|
+
for (const section of DEP_SECTIONS) {
|
|
21
|
+
const deps = pkg[section];
|
|
22
|
+
if (!deps || typeof deps !== "object")
|
|
23
|
+
continue;
|
|
24
|
+
const record = deps;
|
|
25
|
+
for (const name of Object.keys(record)) {
|
|
26
|
+
if (name.startsWith("@porulle/")) {
|
|
27
|
+
record[name] = `^${version}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function readCliVersion() {
|
|
33
|
+
const pkg = await readJson(resolve(currentDir, "../../package.json"));
|
|
34
|
+
return pkg.version;
|
|
35
|
+
}
|
|
9
36
|
export const initCommand = defineCommand({
|
|
10
37
|
meta: {
|
|
11
38
|
name: "init",
|
|
@@ -41,6 +68,10 @@ export const initCommand = defineCommand({
|
|
|
41
68
|
if (existsSync(packageJsonPath)) {
|
|
42
69
|
const pkg = await readJson(packageJsonPath);
|
|
43
70
|
pkg.name = projectName;
|
|
71
|
+
const cliVersion = await readCliVersion();
|
|
72
|
+
if (cliVersion) {
|
|
73
|
+
pinPorulleDependencies(pkg, cliVersion);
|
|
74
|
+
}
|
|
44
75
|
await writeJson(packageJsonPath, pkg);
|
|
45
76
|
}
|
|
46
77
|
consola.success(`Project created at ${destination}`);
|
package/dist/index.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@porulle/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"unifiedcommerce": "./dist/index.js"
|
|
8
8
|
},
|
|
9
|
-
"scripts": {
|
|
10
|
-
"build": "rm -rf dist tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json",
|
|
11
|
-
"check-types": "tsc --noEmit",
|
|
12
|
-
"lint": "eslint . --max-warnings 1000",
|
|
13
|
-
"test": "vitest run"
|
|
14
|
-
},
|
|
15
9
|
"dependencies": {
|
|
16
10
|
"postgres": "^3.4.7",
|
|
17
|
-
"@porulle/import-flat": "workspace:*",
|
|
18
|
-
"@porulle/import-shopify": "workspace:*",
|
|
19
|
-
"@porulle/import-woocommerce": "workspace:*",
|
|
20
11
|
"citty": "^0.1.6",
|
|
21
12
|
"consola": "^3.4.2",
|
|
22
13
|
"giget": "^2.0.0"
|
|
23
14
|
},
|
|
15
|
+
"optionalDependencies": {
|
|
16
|
+
"@porulle/import-woocommerce": "0.6.0",
|
|
17
|
+
"@porulle/import-shopify": "0.6.0",
|
|
18
|
+
"@porulle/import-flat": "0.6.0"
|
|
19
|
+
},
|
|
24
20
|
"devDependencies": {
|
|
25
21
|
"@electric-sql/pglite": "0.4.5",
|
|
26
22
|
"@electric-sql/pglite-socket": "^0.1.5",
|
|
27
|
-
"@repo/eslint-config": "*",
|
|
28
|
-
"@repo/typescript-config": "*",
|
|
29
23
|
"@types/node": "^24.5.2",
|
|
30
24
|
"drizzle-kit": "^0.31.9",
|
|
31
25
|
"eslint": "^9.39.1",
|
|
32
26
|
"typescript": "5.9.2",
|
|
33
|
-
"vitest": "^3.2.4"
|
|
27
|
+
"vitest": "^3.2.4",
|
|
28
|
+
"@porulle/eslint-config": "0.1.0",
|
|
29
|
+
"@porulle/typescript-config": "0.1.0"
|
|
34
30
|
},
|
|
35
31
|
"publishConfig": {
|
|
36
32
|
"access": "public"
|
|
@@ -49,5 +45,11 @@
|
|
|
49
45
|
"url": "git+https://github.com/asyncdotengineering/porulle.git",
|
|
50
46
|
"directory": "packages/cli"
|
|
51
47
|
},
|
|
52
|
-
"author": "Porulle contributors"
|
|
53
|
-
|
|
48
|
+
"author": "Porulle contributors",
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "rm -rf dist tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json",
|
|
51
|
+
"check-types": "tsc --noEmit",
|
|
52
|
+
"lint": "eslint . --max-warnings 1000",
|
|
53
|
+
"test": "vitest run"
|
|
54
|
+
}
|
|
55
|
+
}
|