owosk 0.2.1 → 0.2.3

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 +47 -73
  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
@@ -17,6 +17,9 @@ var GLOBAL_CONFIG_PATH = join(GLOBAL_CONFIG_DIR, "config.json");
17
17
  function getApiUrl(configUrl) {
18
18
  return process.env.OWOSTACK_API_URL || configUrl || "https://sandbox.owostack.com";
19
19
  }
20
+ function getLiveApiUrl(configUrl) {
21
+ return process.env.OWOSTACK_API_LIVE_URL || process.env.OWOSTACK_API_URL || configUrl || "https://api.owostack.com";
22
+ }
20
23
  function getTestApiUrl(configUrl) {
21
24
  return process.env.OWOSTACK_API_TEST_URL || configUrl || "https://sandbox.owostack.com";
22
25
  }
@@ -49,12 +52,15 @@ function getApiKey(cliKey) {
49
52
  import { resolve, isAbsolute, extname } from "path";
50
53
  import { existsSync as existsSync2 } from "fs";
51
54
  import { createJiti } from "jiti";
52
- var jiti = createJiti(import.meta.url);
55
+ var jiti = createJiti(import.meta.url, {
56
+ alias: {
57
+ owostack: import.meta.resolve("owostack")
58
+ }
59
+ });
53
60
  var DEFAULT_CONFIG_NAMES = [
54
61
  "owo.config.ts",
55
62
  "owo.config.js",
56
63
  "owo.config.mjs",
57
- "owo.config.cjs",
58
64
  "owo.config.mts",
59
65
  "owo.config.cts"
60
66
  ];
@@ -98,17 +104,17 @@ async function loadOwostackFromConfig(fullPath) {
98
104
  ` import { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } from "owostack";`
99
105
  );
100
106
  console.error(
101
- ` export default new Owostack({ secretKey: "...", catalog: [...] });
107
+ ` export const owo = new Owostack({ secretKey: "...", catalog: [...] });
102
108
  `
103
109
  );
104
110
  } else {
105
111
  console.error(` Example owo.config.js:
106
112
  `);
107
113
  console.error(
108
- ` const { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } = require("owostack");`
114
+ ` import { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } from "owostack";`
109
115
  );
110
116
  console.error(
111
- ` module.exports = new Owostack({ secretKey: "...", catalog: [...] });
117
+ ` export const owo = new Owostack({ secretKey: "...", catalog: [...] });
112
118
  `
113
119
  );
114
120
  }
@@ -743,7 +749,7 @@ async function runSync(options) {
743
749
  p2.intro(pc3.bgYellow(pc3.black(" sync ")));
744
750
  const configSettings = await loadConfigSettings(options.config);
745
751
  const testUrl = getTestApiUrl(configSettings.environments?.test);
746
- const liveUrl = getApiUrl(configSettings.environments?.live);
752
+ const liveUrl = getLiveApiUrl(configSettings.environments?.live);
747
753
  if (options.prod) {
748
754
  p2.log.step(pc3.magenta("Production Mode: Syncing to PROD environment"));
749
755
  await runSyncSingle({
@@ -751,7 +757,7 @@ async function runSync(options) {
751
757
  dryRun: !!options.dryRun,
752
758
  autoApprove: !!options.yes,
753
759
  apiKey: options.key || "",
754
- apiUrl: configSettings.apiUrl || liveUrl,
760
+ apiUrl: liveUrl,
755
761
  environment: "prod"
756
762
  });
757
763
  } else {
@@ -771,9 +777,9 @@ async function runSync(options) {
771
777
  // src/commands/pull.ts
772
778
  import * as p3 from "@clack/prompts";
773
779
  import pc4 from "picocolors";
774
- import { existsSync as existsSync3, readFileSync as readFileSync2 } from "fs";
780
+ import { existsSync as existsSync3 } from "fs";
775
781
  import { writeFile as writeFile2 } from "fs/promises";
776
- import { join as join2, resolve as resolve2, extname as extname2, isAbsolute as isAbsolute2 } from "path";
782
+ import { resolve as resolve2, extname as extname2, isAbsolute as isAbsolute2 } from "path";
777
783
 
778
784
  // src/lib/generate.ts
779
785
  function slugToIdentifier(slug, used) {
@@ -830,7 +836,6 @@ function slugToIdentifier(slug, used) {
830
836
  }
831
837
  function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProvider, format = "ts") {
832
838
  const isTs = format === "ts";
833
- const isCjs = format === "cjs";
834
839
  const creditSystemSlugs = new Set(creditSystems.map((cs) => cs.slug));
835
840
  const featuresBySlug = /* @__PURE__ */ new Map();
836
841
  for (const plan of plans) {
@@ -876,11 +881,7 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
876
881
  const isEntity = feature.meterType === "non_consumable";
877
882
  const builder = feature.type === "boolean" ? "boolean" : isEntity ? "entity" : "metered";
878
883
  const decl = `${builder}(${JSON.stringify(feature.slug)}${nameArg})`;
879
- if (isCjs) {
880
- featureLines.push(`const ${varName} = ${decl};`);
881
- } else {
882
- featureLines.push(`export const ${varName} = ${decl};`);
883
- }
884
+ featureLines.push(`export const ${varName} = ${decl};`);
884
885
  }
885
886
  const creditSystemLines = [];
886
887
  const creditSystemVars = /* @__PURE__ */ new Map();
@@ -899,11 +900,7 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
899
900
  const decl = `creditSystem(${JSON.stringify(cs.slug)}, {
900
901
  ${configLines.join(",\n ")}
901
902
  })`;
902
- if (isCjs) {
903
- creditSystemLines.push(`const ${varName} = ${decl};`);
904
- } else {
905
- creditSystemLines.push(`export const ${varName} = ${decl};`);
906
- }
903
+ creditSystemLines.push(`export const ${varName} = ${decl};`);
907
904
  }
908
905
  const planLines = [];
909
906
  for (const plan of plans) {
@@ -1024,25 +1021,12 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
1024
1021
  const importParts = ["Owostack", "metered", "boolean"];
1025
1022
  if (hasEntities) importParts.push("entity");
1026
1023
  importParts.push("creditSystem", "creditPack", "plan");
1027
- const imports = isCjs ? `const { ${importParts.join(", ")} } = require("owostack");` : `import { ${importParts.join(", ")} } from "owostack";`;
1024
+ const imports = `import { ${importParts.join(", ")} } from "owostack";`;
1028
1025
  const tsCheck = !isTs ? `// @ts-check` : "";
1029
1026
  const jsDoc = !isTs ? `/** @type {import('owostack').Owostack} */` : "";
1030
- const owoDecl = isCjs ? "const owo =" : "export const owo =";
1027
+ const owoDecl = "export const owo =";
1031
1028
  const secretKey = isTs ? "process.env.OWOSTACK_SECRET_KEY!" : "process.env.OWOSTACK_SECRET_KEY";
1032
1029
  const catalogEntries = [...planLines, ...creditPackLines];
1033
- const footer = isCjs ? `module.exports = { owo, ${Array.from(usedNames).filter(
1034
- (n) => ![
1035
- "Owostack",
1036
- "metered",
1037
- "boolean",
1038
- "entity",
1039
- "creditSystem",
1040
- "creditPack",
1041
- "plan",
1042
- "owo"
1043
- ].includes(n)
1044
- ).join(", ")} };`.replace(", };", " };") : "";
1045
- const finalFooter = isCjs && footer.includes("{ owo, }") ? "module.exports = { owo };" : footer;
1046
1030
  return [
1047
1031
  tsCheck,
1048
1032
  imports,
@@ -1057,30 +1041,21 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
1057
1041
  ` catalog: [`,
1058
1042
  ` ${catalogEntries.join(",\n ")}`,
1059
1043
  ` ],`,
1060
- `});`,
1061
- ``,
1062
- finalFooter
1044
+ `});`
1063
1045
  ].filter(Boolean).join("\n");
1064
1046
  }
1065
1047
 
1066
1048
  // src/commands/pull.ts
1067
- function getProjectInfo() {
1068
- const cwd = process.cwd();
1069
- let isEsm = false;
1070
- try {
1071
- const pkg2 = JSON.parse(readFileSync2(join2(cwd, "package.json"), "utf8"));
1072
- isEsm = pkg2.type === "module";
1073
- } catch {
1074
- }
1075
- return { isEsm };
1076
- }
1077
1049
  function determineFormat(fullPath) {
1078
1050
  const ext = extname2(fullPath);
1079
- const { isEsm } = getProjectInfo();
1080
1051
  if (ext === ".ts" || ext === ".mts" || ext === ".cts") return "ts";
1081
1052
  if (ext === ".mjs") return "esm";
1082
- if (ext === ".cjs") return "cjs";
1083
- if (ext === ".js") return isEsm ? "esm" : "cjs";
1053
+ if (ext === ".cjs") {
1054
+ throw new Error(
1055
+ "CommonJS config files are not supported. Use owo.config.js or owo.config.ts."
1056
+ );
1057
+ }
1058
+ if (ext === ".js") return "esm";
1084
1059
  return "ts";
1085
1060
  }
1086
1061
  async function runPull(options) {
@@ -1101,9 +1076,15 @@ async function runPull(options) {
1101
1076
  const apiKey = getApiKey(options.key);
1102
1077
  const configSettings = await loadConfigSettings(options.config);
1103
1078
  const testUrl = getTestApiUrl(configSettings.environments?.test);
1104
- const liveUrl = getApiUrl(configSettings.environments?.live);
1079
+ const liveUrl = getLiveApiUrl(configSettings.environments?.live);
1105
1080
  const filters = configSettings.filters || {};
1106
- const format = determineFormat(fullPath);
1081
+ let format;
1082
+ try {
1083
+ format = determineFormat(fullPath);
1084
+ } catch (e) {
1085
+ p3.log.error(pc4.red(e.message));
1086
+ process.exit(1);
1087
+ }
1107
1088
  const s = p3.spinner();
1108
1089
  if (options.prod) {
1109
1090
  p3.log.step(pc4.magenta("Production Mode: Pulling from PROD environment"));
@@ -1253,7 +1234,7 @@ async function runDiff(options) {
1253
1234
  const apiKey = getApiKey(options.key);
1254
1235
  const configSettings = await loadConfigSettings(options.config);
1255
1236
  const testUrl = getTestApiUrl(configSettings.environments?.test);
1256
- const liveUrl = getApiUrl(configSettings.environments?.live);
1237
+ const liveUrl = getLiveApiUrl(configSettings.environments?.live);
1257
1238
  const s = p4.spinner();
1258
1239
  if (options.prod) {
1259
1240
  p4.log.step(pc5.magenta("Production Mode: Comparing with PROD environment"));
@@ -1349,9 +1330,9 @@ async function runDiff(options) {
1349
1330
  // src/commands/init.ts
1350
1331
  import * as p6 from "@clack/prompts";
1351
1332
  import pc7 from "picocolors";
1352
- import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
1333
+ import { existsSync as existsSync4 } from "fs";
1353
1334
  import { writeFile as writeFile3 } from "fs/promises";
1354
- import { join as join3, resolve as resolve3, isAbsolute as isAbsolute3, extname as extname3 } from "path";
1335
+ import { join as join2, resolve as resolve3, isAbsolute as isAbsolute3, extname as extname3 } from "path";
1355
1336
 
1356
1337
  // src/lib/connect.ts
1357
1338
  import * as p5 from "@clack/prompts";
@@ -1451,16 +1432,10 @@ async function executeConnectFlow(options) {
1451
1432
  }
1452
1433
 
1453
1434
  // src/commands/init.ts
1454
- function getProjectInfo2() {
1435
+ function getProjectInfo() {
1455
1436
  const cwd = process.cwd();
1456
- const isTs = existsSync4(join3(cwd, "tsconfig.json"));
1457
- let isEsm = false;
1458
- try {
1459
- const pkg2 = JSON.parse(readFileSync3(join3(cwd, "package.json"), "utf8"));
1460
- isEsm = pkg2.type === "module";
1461
- } catch {
1462
- }
1463
- return { isTs, isEsm };
1437
+ const isTs = existsSync4(join2(cwd, "tsconfig.json"));
1438
+ return { isTs };
1464
1439
  }
1465
1440
  async function runInit(options) {
1466
1441
  p6.intro(pc7.bgYellow(pc7.black(" init ")));
@@ -1470,7 +1445,7 @@ async function runInit(options) {
1470
1445
  if (existing) {
1471
1446
  targetPath = existing;
1472
1447
  } else {
1473
- const { isTs } = getProjectInfo2();
1448
+ const { isTs } = getProjectInfo();
1474
1449
  targetPath = isTs ? "owo.config.ts" : "owo.config.js";
1475
1450
  }
1476
1451
  }
@@ -1508,16 +1483,17 @@ async function runInit(options) {
1508
1483
  const plans = await fetchPlans({ apiKey, apiUrl });
1509
1484
  const creditSystems = await fetchCreditSystems(apiKey, apiUrl);
1510
1485
  const ext = extname3(fullPath);
1511
- const { isEsm } = getProjectInfo2();
1512
1486
  let format = "ts";
1513
1487
  if (ext === ".ts" || ext === ".mts" || ext === ".cts") {
1514
1488
  format = "ts";
1515
1489
  } else if (ext === ".mjs") {
1516
1490
  format = "esm";
1517
1491
  } else if (ext === ".cjs") {
1518
- format = "cjs";
1492
+ throw new Error(
1493
+ "CommonJS config files are not supported. Use owo.config.js or owo.config.ts."
1494
+ );
1519
1495
  } else if (ext === ".js") {
1520
- format = isEsm ? "esm" : "cjs";
1496
+ format = "esm";
1521
1497
  }
1522
1498
  const configContent = generateConfig(
1523
1499
  plans,
@@ -1536,9 +1512,7 @@ ${pc7.dim("Credit Systems:")} ${creditSystems.length}`,
1536
1512
  "\u2728 Project Initialized"
1537
1513
  );
1538
1514
  p6.outro(
1539
- pc7.cyan(
1540
- `Next step: Run ${pc7.bold("owosk sync")} to apply your catalog.`
1541
- )
1515
+ pc7.cyan(`Next step: Run ${pc7.bold("owosk sync")} to apply your catalog.`)
1542
1516
  );
1543
1517
  } catch (e) {
1544
1518
  s.stop(pc7.red("Initialization failed"));
@@ -1614,7 +1588,7 @@ async function runValidate(options) {
1614
1588
  }
1615
1589
  const configSettings = await loadConfigSettings(options.config);
1616
1590
  const testUrl = getTestApiUrl(configSettings.environments?.test);
1617
- const liveUrl = getApiUrl(configSettings.environments?.live);
1591
+ const liveUrl = getLiveApiUrl(configSettings.environments?.live);
1618
1592
  const apiKey = getApiKey();
1619
1593
  if (options.prod) {
1620
1594
  p7.log.step(pc8.magenta("Production Mode: Checking PROD environment"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owosk",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "CLI for Owostack - sync catalog, manage billing infrastructure",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {