owosk 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +61 -70
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -20,7 +20,7 @@ npx owo --help
20
20
 
21
21
  ### `init`
22
22
 
23
- Initialize a new Owostack project with a default configuration file (`owo.config.ts` or `owo.config.js`).
23
+ Initialize a new Owostack project with a default configuration file (`owo.config.ts` or `owo.config.js`). JavaScript configs use ESM `import`/`export` syntax.
24
24
 
25
25
  ```bash
26
26
  npx owo init
package/dist/index.js CHANGED
@@ -49,12 +49,15 @@ function getApiKey(cliKey) {
49
49
  import { resolve, isAbsolute, extname } from "path";
50
50
  import { existsSync as existsSync2 } from "fs";
51
51
  import { createJiti } from "jiti";
52
- var jiti = createJiti(import.meta.url);
52
+ var jiti = createJiti(import.meta.url, {
53
+ alias: {
54
+ owostack: import.meta.resolve("owostack")
55
+ }
56
+ });
53
57
  var DEFAULT_CONFIG_NAMES = [
54
58
  "owo.config.ts",
55
59
  "owo.config.js",
56
60
  "owo.config.mjs",
57
- "owo.config.cjs",
58
61
  "owo.config.mts",
59
62
  "owo.config.cts"
60
63
  ];
@@ -95,20 +98,20 @@ async function loadOwostackFromConfig(fullPath) {
95
98
  console.error(` Example owo.config.ts:
96
99
  `);
97
100
  console.error(
98
- ` import { Owostack, metered, boolean, plan } from "owostack";`
101
+ ` import { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } from "owostack";`
99
102
  );
100
103
  console.error(
101
- ` export default new Owostack({ secretKey: "...", catalog: [...] });
104
+ ` export const owo = new Owostack({ secretKey: "...", catalog: [...] });
102
105
  `
103
106
  );
104
107
  } else {
105
108
  console.error(` Example owo.config.js:
106
109
  `);
107
110
  console.error(
108
- ` const { Owostack, metered, boolean, plan } = require("owostack");`
111
+ ` import { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } from "owostack";`
109
112
  );
110
113
  console.error(
111
- ` module.exports = new Owostack({ secretKey: "...", catalog: [...] });
114
+ ` export const owo = new Owostack({ secretKey: "...", catalog: [...] });
112
115
  `
113
116
  );
114
117
  }
@@ -771,9 +774,9 @@ async function runSync(options) {
771
774
  // src/commands/pull.ts
772
775
  import * as p3 from "@clack/prompts";
773
776
  import pc4 from "picocolors";
774
- import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
777
+ import { existsSync as existsSync3 } from "fs";
775
778
  import { writeFile as writeFile2 } from "fs/promises";
776
- import { join as join2, resolve as resolve2, extname as extname2, isAbsolute as isAbsolute2 } from "path";
779
+ import { resolve as resolve2, extname as extname2, isAbsolute as isAbsolute2 } from "path";
777
780
 
778
781
  // src/lib/generate.ts
779
782
  function slugToIdentifier(slug, used) {
@@ -830,9 +833,7 @@ function slugToIdentifier(slug, used) {
830
833
  }
831
834
  function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProvider, format = "ts") {
832
835
  const isTs = format === "ts";
833
- const isCjs = format === "cjs";
834
836
  const creditSystemSlugs = new Set(creditSystems.map((cs) => cs.slug));
835
- const creditSystemBySlug = new Map(creditSystems.map((cs) => [cs.slug, cs]));
836
837
  const featuresBySlug = /* @__PURE__ */ new Map();
837
838
  for (const plan of plans) {
838
839
  for (const f of plan.features || []) {
@@ -858,7 +859,16 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
858
859
  }
859
860
  }
860
861
  }
861
- const usedNames = /* @__PURE__ */ new Set();
862
+ const usedNames = /* @__PURE__ */ new Set([
863
+ "Owostack",
864
+ "metered",
865
+ "boolean",
866
+ "entity",
867
+ "creditSystem",
868
+ "creditPack",
869
+ "plan",
870
+ "owo"
871
+ ]);
862
872
  const featureVars = /* @__PURE__ */ new Map();
863
873
  const featureLines = [];
864
874
  for (const feature of featuresBySlug.values()) {
@@ -868,36 +878,26 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
868
878
  const isEntity = feature.meterType === "non_consumable";
869
879
  const builder = feature.type === "boolean" ? "boolean" : isEntity ? "entity" : "metered";
870
880
  const decl = `${builder}(${JSON.stringify(feature.slug)}${nameArg})`;
871
- if (isCjs) {
872
- featureLines.push(`const ${varName} = ${decl};`);
873
- featureLines.push(`exports.${varName} = ${varName};`);
874
- } else {
875
- featureLines.push(`export const ${varName} = ${decl};`);
876
- }
881
+ featureLines.push(`export const ${varName} = ${decl};`);
877
882
  }
878
883
  const creditSystemLines = [];
879
884
  const creditSystemVars = /* @__PURE__ */ new Map();
880
885
  for (const cs of creditSystems) {
881
886
  const varName = slugToIdentifier(cs.slug, usedNames);
882
887
  creditSystemVars.set(cs.slug, varName);
883
- const nameArg = cs.name ? `name: ${JSON.stringify(cs.name)}` : "";
884
- const descArg = cs.description ? `description: ${JSON.stringify(cs.description)}` : "";
888
+ const configLines = [];
889
+ if (cs.name) configLines.push(`name: ${JSON.stringify(cs.name)}`);
890
+ if (cs.description)
891
+ configLines.push(`description: ${JSON.stringify(cs.description)}`);
885
892
  const featureEntries = (cs.features || []).map((f) => {
886
893
  const childVar = featureVars.get(f.feature) || f.feature;
887
894
  return `${childVar}(${f.creditCost})`;
888
895
  });
889
- const optsParts = [
890
- nameArg,
891
- descArg,
892
- `features: [${featureEntries.join(", ")}]`
893
- ].filter(Boolean);
894
- const decl = `creditSystem(${JSON.stringify(cs.slug)}, { ${optsParts.join(", ")} })`;
895
- if (isCjs) {
896
- creditSystemLines.push(`const ${varName} = ${decl};`);
897
- creditSystemLines.push(`exports.${varName} = ${varName};`);
898
- } else {
899
- creditSystemLines.push(`export const ${varName} = ${decl};`);
900
- }
896
+ configLines.push(`features: [${featureEntries.join(", ")}]`);
897
+ const decl = `creditSystem(${JSON.stringify(cs.slug)}, {
898
+ ${configLines.join(",\n ")}
899
+ })`;
900
+ creditSystemLines.push(`export const ${varName} = ${decl};`);
901
901
  }
902
902
  const planLines = [];
903
903
  for (const plan of plans) {
@@ -1018,50 +1018,41 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
1018
1018
  const importParts = ["Owostack", "metered", "boolean"];
1019
1019
  if (hasEntities) importParts.push("entity");
1020
1020
  importParts.push("creditSystem", "creditPack", "plan");
1021
- const imports = isCjs ? `const { ${importParts.join(", ")} } = require("owostack");` : `import { ${importParts.join(", ")} } from "owostack";`;
1021
+ const imports = `import { ${importParts.join(", ")} } from "owostack";`;
1022
1022
  const tsCheck = !isTs ? `// @ts-check` : "";
1023
1023
  const jsDoc = !isTs ? `/** @type {import('owostack').Owostack} */` : "";
1024
- const owoDecl = isCjs ? "exports.owo =" : "export const owo =";
1024
+ const owoDecl = "export const owo =";
1025
1025
  const secretKey = isTs ? "process.env.OWOSTACK_SECRET_KEY!" : "process.env.OWOSTACK_SECRET_KEY";
1026
+ const catalogEntries = [...planLines, ...creditPackLines];
1026
1027
  return [
1027
1028
  tsCheck,
1028
1029
  imports,
1029
1030
  ``,
1030
1031
  ...featureLines,
1031
1032
  ...hasCreditSystems ? ["", ...creditSystemLines] : [],
1032
- ...hasCreditPacks ? ["", ...creditPackLines] : [],
1033
1033
  ``,
1034
1034
  jsDoc,
1035
1035
  `${owoDecl} new Owostack({`,
1036
1036
  ` secretKey: ${secretKey},`,
1037
1037
  providerLine,
1038
1038
  ` catalog: [`,
1039
- ` ${planLines.join(",\n ")}${hasCreditPacks ? "," : ""}`,
1040
- ...hasCreditPacks ? [` ${creditPackLines.join(",\n ")}`] : [],
1039
+ ` ${catalogEntries.join(",\n ")}`,
1041
1040
  ` ],`,
1042
- `});`,
1043
- ``
1041
+ `});`
1044
1042
  ].filter(Boolean).join("\n");
1045
1043
  }
1046
1044
 
1047
1045
  // src/commands/pull.ts
1048
- function getProjectInfo() {
1049
- const cwd = process.cwd();
1050
- let isEsm = false;
1051
- try {
1052
- const pkg2 = JSON.parse(readFileSync2(join2(cwd, "package.json"), "utf8"));
1053
- isEsm = pkg2.type === "module";
1054
- } catch {
1055
- }
1056
- return { isEsm };
1057
- }
1058
1046
  function determineFormat(fullPath) {
1059
1047
  const ext = extname2(fullPath);
1060
- const { isEsm } = getProjectInfo();
1061
1048
  if (ext === ".ts" || ext === ".mts" || ext === ".cts") return "ts";
1062
1049
  if (ext === ".mjs") return "esm";
1063
- if (ext === ".cjs") return "cjs";
1064
- if (ext === ".js") return isEsm ? "esm" : "cjs";
1050
+ if (ext === ".cjs") {
1051
+ throw new Error(
1052
+ "CommonJS config files are not supported. Use owo.config.js or owo.config.ts."
1053
+ );
1054
+ }
1055
+ if (ext === ".js") return "esm";
1065
1056
  return "ts";
1066
1057
  }
1067
1058
  async function runPull(options) {
@@ -1084,7 +1075,13 @@ async function runPull(options) {
1084
1075
  const testUrl = getTestApiUrl(configSettings.environments?.test);
1085
1076
  const liveUrl = getApiUrl(configSettings.environments?.live);
1086
1077
  const filters = configSettings.filters || {};
1087
- const format = determineFormat(fullPath);
1078
+ let format;
1079
+ try {
1080
+ format = determineFormat(fullPath);
1081
+ } catch (e) {
1082
+ p3.log.error(pc4.red(e.message));
1083
+ process.exit(1);
1084
+ }
1088
1085
  const s = p3.spinner();
1089
1086
  if (options.prod) {
1090
1087
  p3.log.step(pc4.magenta("Production Mode: Pulling from PROD environment"));
@@ -1330,9 +1327,9 @@ async function runDiff(options) {
1330
1327
  // src/commands/init.ts
1331
1328
  import * as p6 from "@clack/prompts";
1332
1329
  import pc7 from "picocolors";
1333
- import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
1330
+ import { existsSync as existsSync4 } from "fs";
1334
1331
  import { writeFile as writeFile3 } from "fs/promises";
1335
- import { join as join3, resolve as resolve3, isAbsolute as isAbsolute3, extname as extname3 } from "path";
1332
+ import { join as join2, resolve as resolve3, isAbsolute as isAbsolute3, extname as extname3 } from "path";
1336
1333
 
1337
1334
  // src/lib/connect.ts
1338
1335
  import * as p5 from "@clack/prompts";
@@ -1432,16 +1429,10 @@ async function executeConnectFlow(options) {
1432
1429
  }
1433
1430
 
1434
1431
  // src/commands/init.ts
1435
- function getProjectInfo2() {
1432
+ function getProjectInfo() {
1436
1433
  const cwd = process.cwd();
1437
- const isTs = existsSync4(join3(cwd, "tsconfig.json"));
1438
- let isEsm = false;
1439
- try {
1440
- const pkg2 = JSON.parse(readFileSync3(join3(cwd, "package.json"), "utf8"));
1441
- isEsm = pkg2.type === "module";
1442
- } catch {
1443
- }
1444
- return { isTs, isEsm };
1434
+ const isTs = existsSync4(join2(cwd, "tsconfig.json"));
1435
+ return { isTs };
1445
1436
  }
1446
1437
  async function runInit(options) {
1447
1438
  p6.intro(pc7.bgYellow(pc7.black(" init ")));
@@ -1451,7 +1442,7 @@ async function runInit(options) {
1451
1442
  if (existing) {
1452
1443
  targetPath = existing;
1453
1444
  } else {
1454
- const { isTs } = getProjectInfo2();
1445
+ const { isTs } = getProjectInfo();
1455
1446
  targetPath = isTs ? "owo.config.ts" : "owo.config.js";
1456
1447
  }
1457
1448
  }
@@ -1489,20 +1480,22 @@ async function runInit(options) {
1489
1480
  const plans = await fetchPlans({ apiKey, apiUrl });
1490
1481
  const creditSystems = await fetchCreditSystems(apiKey, apiUrl);
1491
1482
  const ext = extname3(fullPath);
1492
- const { isEsm } = getProjectInfo2();
1493
1483
  let format = "ts";
1494
1484
  if (ext === ".ts" || ext === ".mts" || ext === ".cts") {
1495
1485
  format = "ts";
1496
1486
  } else if (ext === ".mjs") {
1497
1487
  format = "esm";
1498
1488
  } else if (ext === ".cjs") {
1499
- format = "cjs";
1489
+ throw new Error(
1490
+ "CommonJS config files are not supported. Use owo.config.js or owo.config.ts."
1491
+ );
1500
1492
  } else if (ext === ".js") {
1501
- format = isEsm ? "esm" : "cjs";
1493
+ format = "esm";
1502
1494
  }
1503
1495
  const configContent = generateConfig(
1504
1496
  plans,
1505
1497
  creditSystems,
1498
+ [],
1506
1499
  void 0,
1507
1500
  format
1508
1501
  );
@@ -1516,9 +1509,7 @@ ${pc7.dim("Credit Systems:")} ${creditSystems.length}`,
1516
1509
  "\u2728 Project Initialized"
1517
1510
  );
1518
1511
  p6.outro(
1519
- pc7.cyan(
1520
- `Next step: Run ${pc7.bold("owostack sync")} to apply your catalog.`
1521
- )
1512
+ pc7.cyan(`Next step: Run ${pc7.bold("owosk sync")} to apply your catalog.`)
1522
1513
  );
1523
1514
  } catch (e) {
1524
1515
  s.stop(pc7.red("Initialization failed"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owosk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "CLI for Owostack - sync catalog, manage billing infrastructure",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {