priceos 0.0.18 → 0.0.20

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/dist/cli.cjs CHANGED
@@ -60,7 +60,7 @@ async function readEnvFile(filePath) {
60
60
  }
61
61
  function printHelp() {
62
62
  console.log(`
63
- priceos sync
63
+ priceos generate-types
64
64
 
65
65
  Generates TypeScript feature access types for your PriceOS workspace.
66
66
 
@@ -71,8 +71,8 @@ Options:
71
71
  -h, --help Show help
72
72
 
73
73
  Examples:
74
- priceos sync --api-key sk_test_... --out ./priceos.d.ts
75
- priceos sync --api-key sk_test_... --out-dir ./src
74
+ priceos generate-types --api-key sk_test_... --out ./priceos.d.ts
75
+ priceos generate-types --api-key sk_test_... --out-dir ./src
76
76
  `.trim());
77
77
  }
78
78
  async function main() {
@@ -82,7 +82,7 @@ async function main() {
82
82
  process.exit(args.length === 0 ? 1 : 0);
83
83
  }
84
84
  const cmd = args[0];
85
- if (cmd !== "sync") {
85
+ if (cmd !== "generate-types") {
86
86
  console.error(`Unknown command: ${cmd}`);
87
87
  printHelp();
88
88
  process.exit(1);
@@ -131,7 +131,7 @@ ${text}`);
131
131
  const accessType = featureType === "boolean" ? "BooleanFeatureAccess" : featureType === "limit" ? "LimitFeatureAccess" : "FeatureAccessEntry";
132
132
  return ` ${JSON.stringify(key)}: ${accessType};`;
133
133
  });
134
- const content = `// Auto-generated by PriceOS (priceos sync). Do not edit.
134
+ const content = `// Auto-generated by PriceOS (priceos generate-types). Do not edit.
135
135
  export type FeatureKey = ${union};
136
136
  export type BooleanFeatureAccess = {
137
137
  type: "boolean";
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\ntype Feature = { featureKey: string; type?: \"boolean\" | \"limit\" | null };\n\nfunction argValue(args: string[], name: string) {\n const idx = args.indexOf(name);\n if (idx === -1) return undefined;\n return args[idx + 1];\n}\n\nfunction hasFlag(args: string[], name: string) {\n return args.includes(name);\n}\n\nasync function readEnvFile(filePath: string) {\n try {\n const raw = await fs.readFile(filePath, \"utf8\");\n const entries: Record<string, string> = {};\n for (const line of raw.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n const eqIdx = trimmed.indexOf(\"=\");\n if (eqIdx === -1) continue;\n const rawKey = trimmed.slice(0, eqIdx).trim();\n const key = rawKey.startsWith(\"export \") ? rawKey.slice(\"export \".length).trim() : rawKey;\n let value = trimmed.slice(eqIdx + 1).trim();\n if (\n (value.startsWith(\"\\\"\") && value.endsWith(\"\\\"\")) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n if (key) {\n entries[key] = value;\n }\n }\n return entries;\n } catch {\n return {};\n }\n}\n\nfunction printHelp() {\n console.log(`\npriceos sync\n\nGenerates TypeScript feature access types for your PriceOS workspace.\n\nOptions:\n --api-key <key> PriceOS API key (defaults to .env.local, .env, or env PRICEOS_API_KEY) [required]\n --out <path> Output .d.ts file (default: priceos.d.ts in current directory)\n --out-dir <path> Output directory for priceos.d.ts (ignored if --out is set)\n -h, --help Show help\n\nExamples:\n priceos sync --api-key sk_test_... --out ./priceos.d.ts\n priceos sync --api-key sk_test_... --out-dir ./src\n`.trim());\n}\n\nasync function main() {\n const args = process.argv.slice(2);\n\n if (args.length === 0 || hasFlag(args, \"--help\") || hasFlag(args, \"-h\")) {\n printHelp();\n process.exit(args.length === 0 ? 1 : 0);\n }\n\n const cmd = args[0];\n if (cmd !== \"sync\") {\n console.error(`Unknown command: ${cmd}`);\n printHelp();\n process.exit(1);\n }\n\n const envLocal = await readEnvFile(path.resolve(process.cwd(), \".env.local\"));\n const envDefault = await readEnvFile(path.resolve(process.cwd(), \".env\"));\n const apiKey =\n argValue(args, \"--api-key\") ??\n envLocal.PRICEOS_API_KEY ??\n envDefault.PRICEOS_API_KEY ??\n process.env.PRICEOS_API_KEY;\n\n if (!apiKey) {\n console.error(\"Missing API key. Provide --api-key <key> or set PRICEOS_API_KEY in .env.local/.env.\");\n process.exit(1);\n }\n\n const outRel = argValue(args, \"--out\");\n const outDir = argValue(args, \"--out-dir\");\n const outFile = outRel ?? \"priceos.d.ts\";\n const outPath = outDir && !outRel\n ? path.resolve(process.cwd(), outDir, outFile)\n : path.resolve(process.cwd(), outFile);\n const outDisplay = outDir && !outRel ? path.join(outDir, outFile) : outFile;\n\n const url = \"https://api.priceos.com/v1/features\";\n const res = await fetch(url, {\n headers: { \"x-api-key\": apiKey },\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n console.error(`Failed to fetch features: ${res.status} ${res.statusText}\\n${text}`);\n process.exit(1);\n }\n\n const features = (await res.json()) as Feature[];\n const typeByKey = new Map<string, \"boolean\" | \"limit\" | \"unknown\">();\n\n for (const feature of features ?? []) {\n if (!feature?.featureKey) continue;\n const key = feature.featureKey;\n const nextType = feature.type === \"boolean\" || feature.type === \"limit\" ? feature.type : \"unknown\";\n const currentType = typeByKey.get(key);\n if (!currentType) {\n typeByKey.set(key, nextType);\n continue;\n }\n if (currentType !== nextType) {\n typeByKey.set(key, \"unknown\");\n }\n }\n\n const keys = [...typeByKey.keys()].sort();\n const union = keys.length ? keys.map((k) => JSON.stringify(k)).join(\" | \") : \"never\";\n const mapLines = keys.map((key) => {\n const featureType = typeByKey.get(key);\n const accessType =\n featureType === \"boolean\"\n ? \"BooleanFeatureAccess\"\n : featureType === \"limit\"\n ? \"LimitFeatureAccess\"\n : \"FeatureAccessEntry\";\n return ` ${JSON.stringify(key)}: ${accessType};`;\n });\n\n const content = `// Auto-generated by PriceOS (priceos sync). Do not edit.\nexport type FeatureKey = ${union};\nexport type BooleanFeatureAccess = {\n type: \"boolean\";\n hasAccess: boolean;\n};\nexport type LimitFeatureAccess = {\n type: \"limit\";\n hasAccess: boolean;\n isUnlimited: boolean;\n limit: number | null;\n used: number;\n};\nexport type FeatureAccessEntry = BooleanFeatureAccess | LimitFeatureAccess;\nexport type FeatureAccessMap = {\n${mapLines.join(\"\\n\")}\n} & Record<string, FeatureAccessEntry>;\n`;\n\n await fs.mkdir(path.dirname(outPath), { recursive: true });\n await fs.writeFile(outPath, content, \"utf8\");\n\n console.log(`Generated ${outDisplay} (${keys.length} feature keys)`);\n}\n\nmain().catch((e) => {\n console.error(e);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sBAAe;AACf,uBAAiB;AAIjB,SAAS,SAAS,MAAgB,MAAc;AAC9C,QAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,MAAI,QAAQ,GAAI,QAAO;AACvB,SAAO,KAAK,MAAM,CAAC;AACrB;AAEA,SAAS,QAAQ,MAAgB,MAAc;AAC7C,SAAO,KAAK,SAAS,IAAI;AAC3B;AAEA,eAAe,YAAY,UAAkB;AAC3C,MAAI;AACF,UAAM,MAAM,MAAM,gBAAAA,QAAG,SAAS,UAAU,MAAM;AAC9C,UAAM,UAAkC,CAAC;AACzC,eAAW,QAAQ,IAAI,MAAM,OAAO,GAAG;AACrC,YAAM,UAAU,KAAK,KAAK;AAC1B,UAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,EAAG;AACzC,YAAM,QAAQ,QAAQ,QAAQ,GAAG;AACjC,UAAI,UAAU,GAAI;AAClB,YAAM,SAAS,QAAQ,MAAM,GAAG,KAAK,EAAE,KAAK;AAC5C,YAAM,MAAM,OAAO,WAAW,SAAS,IAAI,OAAO,MAAM,UAAU,MAAM,EAAE,KAAK,IAAI;AACnF,UAAI,QAAQ,QAAQ,MAAM,QAAQ,CAAC,EAAE,KAAK;AAC1C,UACG,MAAM,WAAW,GAAI,KAAK,MAAM,SAAS,GAAI,KAC7C,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,GAC5C;AACA,gBAAQ,MAAM,MAAM,GAAG,EAAE;AAAA,MAC3B;AACA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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAc9B,SAAS,KAAK,IAAI,CAAC;AAAA;AAAA;AAInB,QAAM,gBAAAD,QAAG,MAAM,iBAAAC,QAAK,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,QAAM,gBAAAD,QAAG,UAAU,SAAS,SAAS,MAAM;AAE3C,UAAQ,IAAI,aAAa,UAAU,KAAK,KAAK,MAAM,gBAAgB;AACrE;AAEA,KAAK,EAAE,MAAM,CAAC,MAAM;AAClB,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["fs","path"]}
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\ntype Feature = { featureKey: string; type?: \"boolean\" | \"limit\" | null };\n\nfunction argValue(args: string[], name: string) {\n const idx = args.indexOf(name);\n if (idx === -1) return undefined;\n return args[idx + 1];\n}\n\nfunction hasFlag(args: string[], name: string) {\n return args.includes(name);\n}\n\nasync function readEnvFile(filePath: string) {\n try {\n const raw = await fs.readFile(filePath, \"utf8\");\n const entries: Record<string, string> = {};\n for (const line of raw.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n const eqIdx = trimmed.indexOf(\"=\");\n if (eqIdx === -1) continue;\n const rawKey = trimmed.slice(0, eqIdx).trim();\n const key = rawKey.startsWith(\"export \") ? rawKey.slice(\"export \".length).trim() : rawKey;\n let value = trimmed.slice(eqIdx + 1).trim();\n if (\n (value.startsWith(\"\\\"\") && value.endsWith(\"\\\"\")) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n if (key) {\n entries[key] = value;\n }\n }\n return entries;\n } catch {\n return {};\n }\n}\n\nfunction printHelp() {\n console.log(`\npriceos generate-types\n\nGenerates TypeScript feature access types for your PriceOS workspace.\n\nOptions:\n --api-key <key> PriceOS API key (defaults to .env.local, .env, or env PRICEOS_API_KEY) [required]\n --out <path> Output .d.ts file (default: priceos.d.ts in current directory)\n --out-dir <path> Output directory for priceos.d.ts (ignored if --out is set)\n -h, --help Show help\n\nExamples:\n priceos generate-types --api-key sk_test_... --out ./priceos.d.ts\n priceos generate-types --api-key sk_test_... --out-dir ./src\n`.trim());\n}\n\nasync function main() {\n const args = process.argv.slice(2);\n\n if (args.length === 0 || hasFlag(args, \"--help\") || hasFlag(args, \"-h\")) {\n printHelp();\n process.exit(args.length === 0 ? 1 : 0);\n }\n\n const cmd = args[0];\n if (cmd !== \"generate-types\") {\n console.error(`Unknown command: ${cmd}`);\n printHelp();\n process.exit(1);\n }\n\n const envLocal = await readEnvFile(path.resolve(process.cwd(), \".env.local\"));\n const envDefault = await readEnvFile(path.resolve(process.cwd(), \".env\"));\n const apiKey =\n argValue(args, \"--api-key\") ??\n envLocal.PRICEOS_API_KEY ??\n envDefault.PRICEOS_API_KEY ??\n process.env.PRICEOS_API_KEY;\n\n if (!apiKey) {\n console.error(\"Missing API key. Provide --api-key <key> or set PRICEOS_API_KEY in .env.local/.env.\");\n process.exit(1);\n }\n\n const outRel = argValue(args, \"--out\");\n const outDir = argValue(args, \"--out-dir\");\n const outFile = outRel ?? \"priceos.d.ts\";\n const outPath = outDir && !outRel\n ? path.resolve(process.cwd(), outDir, outFile)\n : path.resolve(process.cwd(), outFile);\n const outDisplay = outDir && !outRel ? path.join(outDir, outFile) : outFile;\n\n const url = \"https://api.priceos.com/v1/features\";\n const res = await fetch(url, {\n headers: { \"x-api-key\": apiKey },\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n console.error(`Failed to fetch features: ${res.status} ${res.statusText}\\n${text}`);\n process.exit(1);\n }\n\n const features = (await res.json()) as Feature[];\n const typeByKey = new Map<string, \"boolean\" | \"limit\" | \"unknown\">();\n\n for (const feature of features ?? []) {\n if (!feature?.featureKey) continue;\n const key = feature.featureKey;\n const nextType = feature.type === \"boolean\" || feature.type === \"limit\" ? feature.type : \"unknown\";\n const currentType = typeByKey.get(key);\n if (!currentType) {\n typeByKey.set(key, nextType);\n continue;\n }\n if (currentType !== nextType) {\n typeByKey.set(key, \"unknown\");\n }\n }\n\n const keys = [...typeByKey.keys()].sort();\n const union = keys.length ? keys.map((k) => JSON.stringify(k)).join(\" | \") : \"never\";\n const mapLines = keys.map((key) => {\n const featureType = typeByKey.get(key);\n const accessType =\n featureType === \"boolean\"\n ? \"BooleanFeatureAccess\"\n : featureType === \"limit\"\n ? \"LimitFeatureAccess\"\n : \"FeatureAccessEntry\";\n return ` ${JSON.stringify(key)}: ${accessType};`;\n });\n\n const content = `// Auto-generated by PriceOS (priceos generate-types). Do not edit.\nexport type FeatureKey = ${union};\nexport type BooleanFeatureAccess = {\n type: \"boolean\";\n hasAccess: boolean;\n};\nexport type LimitFeatureAccess = {\n type: \"limit\";\n hasAccess: boolean;\n isUnlimited: boolean;\n limit: number | null;\n used: number;\n};\nexport type FeatureAccessEntry = BooleanFeatureAccess | LimitFeatureAccess;\nexport type FeatureAccessMap = {\n${mapLines.join(\"\\n\")}\n} & Record<string, FeatureAccessEntry>;\n`;\n\n await fs.mkdir(path.dirname(outPath), { recursive: true });\n await fs.writeFile(outPath, content, \"utf8\");\n\n console.log(`Generated ${outDisplay} (${keys.length} feature keys)`);\n}\n\nmain().catch((e) => {\n console.error(e);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,sBAAe;AACf,uBAAiB;AAIjB,SAAS,SAAS,MAAgB,MAAc;AAC9C,QAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,MAAI,QAAQ,GAAI,QAAO;AACvB,SAAO,KAAK,MAAM,CAAC;AACrB;AAEA,SAAS,QAAQ,MAAgB,MAAc;AAC7C,SAAO,KAAK,SAAS,IAAI;AAC3B;AAEA,eAAe,YAAY,UAAkB;AAC3C,MAAI;AACF,UAAM,MAAM,MA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AAc,UAAU,IAAI,GAAG;AACrC,QAAI,CAAC,aAAa;AAChB,gBAAU,IAAI,KAAK,QAAQ;AAC3B;AAAA,IACF;AACA,QAAI,gBAAgB,UAAU;AAC5B,gBAAU,IAAI,KAAK,SAAS;AAAA,IAC9B;AAAA,EACF;AAEA,QAAM,OAAO,CAAC,GAAG,UAAU,KAAK,CAAC,EAAE,KAAK;AACxC,QAAM,QAAQ,KAAK,SAAS,KAAK,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI;AAC7E,QAAM,WAAW,KAAK,IAAI,CAAC,QAAQ;AACjC,UAAM,cAAc,UAAU,IAAI,GAAG;AACrC,UAAM,aACJ,gBAAgB,YACZ,yBACA,gBAAgB,UACd,uBACA;AACR,WAAO,KAAK,KAAK,UAAU,GAAG,CAAC,KAAK,UAAU;AAAA,EAChD,CAAC;AAED,QAAM,UAAU;AAAA,2BACS,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAc9B,SAAS,KAAK,IAAI,CAAC;AAAA;AAAA;AAInB,QAAM,gBAAAD,QAAG,MAAM,iBAAAC,QAAK,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,QAAM,gBAAAD,QAAG,UAAU,SAAS,SAAS,MAAM;AAE3C,UAAQ,IAAI,aAAa,UAAU,KAAK,KAAK,MAAM,gBAAgB;AACrE;AAEA,KAAK,EAAE,MAAM,CAAC,MAAM;AAClB,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["fs","path"]}
package/dist/cli.js CHANGED
@@ -37,7 +37,7 @@ async function readEnvFile(filePath) {
37
37
  }
38
38
  function printHelp() {
39
39
  console.log(`
40
- priceos sync
40
+ priceos generate-types
41
41
 
42
42
  Generates TypeScript feature access types for your PriceOS workspace.
43
43
 
@@ -48,8 +48,8 @@ Options:
48
48
  -h, --help Show help
49
49
 
50
50
  Examples:
51
- priceos sync --api-key sk_test_... --out ./priceos.d.ts
52
- priceos sync --api-key sk_test_... --out-dir ./src
51
+ priceos generate-types --api-key sk_test_... --out ./priceos.d.ts
52
+ priceos generate-types --api-key sk_test_... --out-dir ./src
53
53
  `.trim());
54
54
  }
55
55
  async function main() {
@@ -59,7 +59,7 @@ async function main() {
59
59
  process.exit(args.length === 0 ? 1 : 0);
60
60
  }
61
61
  const cmd = args[0];
62
- if (cmd !== "sync") {
62
+ if (cmd !== "generate-types") {
63
63
  console.error(`Unknown command: ${cmd}`);
64
64
  printHelp();
65
65
  process.exit(1);
@@ -108,7 +108,7 @@ ${text}`);
108
108
  const accessType = featureType === "boolean" ? "BooleanFeatureAccess" : featureType === "limit" ? "LimitFeatureAccess" : "FeatureAccessEntry";
109
109
  return ` ${JSON.stringify(key)}: ${accessType};`;
110
110
  });
111
- const content = `// Auto-generated by PriceOS (priceos sync). Do not edit.
111
+ const content = `// Auto-generated by PriceOS (priceos generate-types). Do not edit.
112
112
  export type FeatureKey = ${union};
113
113
  export type BooleanFeatureAccess = {
114
114
  type: "boolean";
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\ntype Feature = { featureKey: string; type?: \"boolean\" | \"limit\" | null };\n\nfunction argValue(args: string[], name: string) {\n const idx = args.indexOf(name);\n if (idx === -1) return undefined;\n return args[idx + 1];\n}\n\nfunction hasFlag(args: string[], name: string) {\n return args.includes(name);\n}\n\nasync function readEnvFile(filePath: string) {\n try {\n const raw = await fs.readFile(filePath, \"utf8\");\n const entries: Record<string, string> = {};\n for (const line of raw.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n const eqIdx = trimmed.indexOf(\"=\");\n if (eqIdx === -1) continue;\n const rawKey = trimmed.slice(0, eqIdx).trim();\n const key = rawKey.startsWith(\"export \") ? rawKey.slice(\"export \".length).trim() : rawKey;\n let value = trimmed.slice(eqIdx + 1).trim();\n if (\n (value.startsWith(\"\\\"\") && value.endsWith(\"\\\"\")) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n if (key) {\n entries[key] = value;\n }\n }\n return entries;\n } catch {\n return {};\n }\n}\n\nfunction printHelp() {\n console.log(`\npriceos sync\n\nGenerates TypeScript feature access types for your PriceOS workspace.\n\nOptions:\n --api-key <key> PriceOS API key (defaults to .env.local, .env, or env PRICEOS_API_KEY) [required]\n --out <path> Output .d.ts file (default: priceos.d.ts in current directory)\n --out-dir <path> Output directory for priceos.d.ts (ignored if --out is set)\n -h, --help Show help\n\nExamples:\n priceos sync --api-key sk_test_... --out ./priceos.d.ts\n priceos sync --api-key sk_test_... --out-dir ./src\n`.trim());\n}\n\nasync function main() {\n const args = process.argv.slice(2);\n\n if (args.length === 0 || hasFlag(args, \"--help\") || hasFlag(args, \"-h\")) {\n printHelp();\n process.exit(args.length === 0 ? 1 : 0);\n }\n\n const cmd = args[0];\n if (cmd !== \"sync\") {\n console.error(`Unknown command: ${cmd}`);\n printHelp();\n process.exit(1);\n }\n\n const envLocal = await readEnvFile(path.resolve(process.cwd(), \".env.local\"));\n const envDefault = await readEnvFile(path.resolve(process.cwd(), \".env\"));\n const apiKey =\n argValue(args, \"--api-key\") ??\n envLocal.PRICEOS_API_KEY ??\n envDefault.PRICEOS_API_KEY ??\n process.env.PRICEOS_API_KEY;\n\n if (!apiKey) {\n console.error(\"Missing API key. Provide --api-key <key> or set PRICEOS_API_KEY in .env.local/.env.\");\n process.exit(1);\n }\n\n const outRel = argValue(args, \"--out\");\n const outDir = argValue(args, \"--out-dir\");\n const outFile = outRel ?? \"priceos.d.ts\";\n const outPath = outDir && !outRel\n ? path.resolve(process.cwd(), outDir, outFile)\n : path.resolve(process.cwd(), outFile);\n const outDisplay = outDir && !outRel ? path.join(outDir, outFile) : outFile;\n\n const url = \"https://api.priceos.com/v1/features\";\n const res = await fetch(url, {\n headers: { \"x-api-key\": apiKey },\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n console.error(`Failed to fetch features: ${res.status} ${res.statusText}\\n${text}`);\n process.exit(1);\n }\n\n const features = (await res.json()) as Feature[];\n const typeByKey = new Map<string, \"boolean\" | \"limit\" | \"unknown\">();\n\n for (const feature of features ?? []) {\n if (!feature?.featureKey) continue;\n const key = feature.featureKey;\n const nextType = feature.type === \"boolean\" || feature.type === \"limit\" ? feature.type : \"unknown\";\n const currentType = typeByKey.get(key);\n if (!currentType) {\n typeByKey.set(key, nextType);\n continue;\n }\n if (currentType !== nextType) {\n typeByKey.set(key, \"unknown\");\n }\n }\n\n const keys = [...typeByKey.keys()].sort();\n const union = keys.length ? keys.map((k) => JSON.stringify(k)).join(\" | \") : \"never\";\n const mapLines = keys.map((key) => {\n const featureType = typeByKey.get(key);\n const accessType =\n featureType === \"boolean\"\n ? \"BooleanFeatureAccess\"\n : featureType === \"limit\"\n ? \"LimitFeatureAccess\"\n : \"FeatureAccessEntry\";\n return ` ${JSON.stringify(key)}: ${accessType};`;\n });\n\n const content = `// Auto-generated by PriceOS (priceos sync). Do not edit.\nexport type FeatureKey = ${union};\nexport type BooleanFeatureAccess = {\n type: \"boolean\";\n hasAccess: boolean;\n};\nexport type LimitFeatureAccess = {\n type: \"limit\";\n hasAccess: boolean;\n isUnlimited: boolean;\n limit: number | null;\n used: number;\n};\nexport type FeatureAccessEntry = BooleanFeatureAccess | LimitFeatureAccess;\nexport type FeatureAccessMap = {\n${mapLines.join(\"\\n\")}\n} & Record<string, FeatureAccessEntry>;\n`;\n\n await fs.mkdir(path.dirname(outPath), { recursive: true });\n await fs.writeFile(outPath, content, \"utf8\");\n\n console.log(`Generated ${outDisplay} (${keys.length} feature keys)`);\n}\n\nmain().catch((e) => {\n console.error(e);\n process.exit(1);\n});\n"],"mappings":";;;AACA,OAAO,Q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names":[]}
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport fs from \"node:fs/promises\";\nimport path from \"node:path\";\n\ntype Feature = { featureKey: string; type?: \"boolean\" | \"limit\" | null };\n\nfunction argValue(args: string[], name: string) {\n const idx = args.indexOf(name);\n if (idx === -1) return undefined;\n return args[idx + 1];\n}\n\nfunction hasFlag(args: string[], name: string) {\n return args.includes(name);\n}\n\nasync function readEnvFile(filePath: string) {\n try {\n const raw = await fs.readFile(filePath, \"utf8\");\n const entries: Record<string, string> = {};\n for (const line of raw.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith(\"#\")) continue;\n const eqIdx = trimmed.indexOf(\"=\");\n if (eqIdx === -1) continue;\n const rawKey = trimmed.slice(0, eqIdx).trim();\n const key = rawKey.startsWith(\"export \") ? rawKey.slice(\"export \".length).trim() : rawKey;\n let value = trimmed.slice(eqIdx + 1).trim();\n if (\n (value.startsWith(\"\\\"\") && value.endsWith(\"\\\"\")) ||\n (value.startsWith(\"'\") && value.endsWith(\"'\"))\n ) {\n value = value.slice(1, -1);\n }\n if (key) {\n entries[key] = value;\n }\n }\n return entries;\n } catch {\n return {};\n }\n}\n\nfunction printHelp() {\n console.log(`\npriceos generate-types\n\nGenerates TypeScript feature access types for your PriceOS workspace.\n\nOptions:\n --api-key <key> PriceOS API key (defaults to .env.local, .env, or env PRICEOS_API_KEY) [required]\n --out <path> Output .d.ts file (default: priceos.d.ts in current directory)\n --out-dir <path> Output directory for priceos.d.ts (ignored if --out is set)\n -h, --help Show help\n\nExamples:\n priceos generate-types --api-key sk_test_... --out ./priceos.d.ts\n priceos generate-types --api-key sk_test_... --out-dir ./src\n`.trim());\n}\n\nasync function main() {\n const args = process.argv.slice(2);\n\n if (args.length === 0 || hasFlag(args, \"--help\") || hasFlag(args, \"-h\")) {\n printHelp();\n process.exit(args.length === 0 ? 1 : 0);\n }\n\n const cmd = args[0];\n if (cmd !== \"generate-types\") {\n console.error(`Unknown command: ${cmd}`);\n printHelp();\n process.exit(1);\n }\n\n const envLocal = await readEnvFile(path.resolve(process.cwd(), \".env.local\"));\n const envDefault = await readEnvFile(path.resolve(process.cwd(), \".env\"));\n const apiKey =\n argValue(args, \"--api-key\") ??\n envLocal.PRICEOS_API_KEY ??\n envDefault.PRICEOS_API_KEY ??\n process.env.PRICEOS_API_KEY;\n\n if (!apiKey) {\n console.error(\"Missing API key. Provide --api-key <key> or set PRICEOS_API_KEY in .env.local/.env.\");\n process.exit(1);\n }\n\n const outRel = argValue(args, \"--out\");\n const outDir = argValue(args, \"--out-dir\");\n const outFile = outRel ?? \"priceos.d.ts\";\n const outPath = outDir && !outRel\n ? path.resolve(process.cwd(), outDir, outFile)\n : path.resolve(process.cwd(), outFile);\n const outDisplay = outDir && !outRel ? path.join(outDir, outFile) : outFile;\n\n const url = \"https://api.priceos.com/v1/features\";\n const res = await fetch(url, {\n headers: { \"x-api-key\": apiKey },\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n console.error(`Failed to fetch features: ${res.status} ${res.statusText}\\n${text}`);\n process.exit(1);\n }\n\n const features = (await res.json()) as Feature[];\n const typeByKey = new Map<string, \"boolean\" | \"limit\" | \"unknown\">();\n\n for (const feature of features ?? []) {\n if (!feature?.featureKey) continue;\n const key = feature.featureKey;\n const nextType = feature.type === \"boolean\" || feature.type === \"limit\" ? feature.type : \"unknown\";\n const currentType = typeByKey.get(key);\n if (!currentType) {\n typeByKey.set(key, nextType);\n continue;\n }\n if (currentType !== nextType) {\n typeByKey.set(key, \"unknown\");\n }\n }\n\n const keys = [...typeByKey.keys()].sort();\n const union = keys.length ? keys.map((k) => JSON.stringify(k)).join(\" | \") : \"never\";\n const mapLines = keys.map((key) => {\n const featureType = typeByKey.get(key);\n const accessType =\n featureType === \"boolean\"\n ? \"BooleanFeatureAccess\"\n : featureType === \"limit\"\n ? \"LimitFeatureAccess\"\n : \"FeatureAccessEntry\";\n return ` ${JSON.stringify(key)}: ${accessType};`;\n });\n\n const content = `// Auto-generated by PriceOS (priceos generate-types). Do not edit.\nexport type FeatureKey = ${union};\nexport type BooleanFeatureAccess = {\n type: \"boolean\";\n hasAccess: boolean;\n};\nexport type LimitFeatureAccess = {\n type: \"limit\";\n hasAccess: boolean;\n isUnlimited: boolean;\n limit: number | null;\n used: number;\n};\nexport type FeatureAccessEntry = BooleanFeatureAccess | LimitFeatureAccess;\nexport type FeatureAccessMap = {\n${mapLines.join(\"\\n\")}\n} & Record<string, FeatureAccessEntry>;\n`;\n\n await fs.mkdir(path.dirname(outPath), { recursive: true });\n await fs.writeFile(outPath, content, \"utf8\");\n\n console.log(`Generated ${outDisplay} (${keys.length} feature keys)`);\n}\n\nmain().catch((e) => {\n console.error(e);\n process.exit(1);\n});\n"],"mappings":";;;AACA,OAAO,QAAQ;AACf,OAAO,UAAU;AAIjB,SAAS,SAAS,MAAgB,MAAc;AAC9C,QAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,MAAI,QAAQ,GAAI,QAAO;AACvB,SAAO,KAAK,MAAM,CAAC;AACrB;AAEA,SAAS,QAAQ,MAAgB,MAAc;AAC7C,SAAO,KAAK,SAAS,IAAI;AAC3B;AAEA,eAAe,YAAY,UAAkB;AAC3C,MAAI;AACF,UAAM,MAAM,MAAM,GAAG,SAAS,UAAU,MAAM;AAC9C,UAAM,UAAkC,CAAC;AACzC,eAAW,QAAQ,IAAI,MAAM,OAAO,GAAG;AACrC,YAAM,UAAU,KAAK,KAAK;AAC1B,UAAI,CAAC,WAAW,QAAQ,WAAW,GAAG,EAAG;AACzC,YAAM,QAAQ,QAAQ,QAAQ,GAAG;AACjC,UAAI,UAAU,GAAI;AAClB,YAAM,SAAS,QAAQ,MAAM,GAAG,KAAK,EAAE,KAAK;AAC5C,YAAM,MAAM,OAAO,WAAW,SAAS,IAAI,OAAO,MAAM,UAAU,MAAM,EAAE,KAAK,IAAI;AACnF,UAAI,QAAQ,QAAQ,MAAM,QAAQ,CAAC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ACA;AACR,WAAO,KAAK,KAAK,UAAU,GAAG,CAAC,KAAK,UAAU;AAAA,EAChD,CAAC;AAED,QAAM,UAAU;AAAA,2BACS,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAc9B,SAAS,KAAK,IAAI,CAAC;AAAA;AAAA;AAInB,QAAM,GAAG,MAAM,KAAK,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,QAAM,GAAG,UAAU,SAAS,SAAS,MAAM;AAE3C,UAAQ,IAAI,aAAa,UAAU,KAAK,KAAK,MAAM,gBAAgB;AACrE;AAEA,KAAK,EAAE,MAAM,CAAC,MAAM;AAClB,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
package/dist/index.cjs CHANGED
@@ -50,6 +50,9 @@ var PriceOSError = class extends Error {
50
50
  var PriceOS = class {
51
51
  client;
52
52
  header;
53
+ customers;
54
+ features;
55
+ usage;
53
56
  constructor(apiKey, opts = {}) {
54
57
  const baseUrl = opts.baseUrl ?? "https://api.priceos.com";
55
58
  this.header = { "x-api-key": apiKey };
@@ -61,45 +64,72 @@ var PriceOS = class {
61
64
  ...opts.userAgent ? { "user-agent": opts.userAgent } : {}
62
65
  }
63
66
  });
64
- }
65
- async getCustomer(customerId) {
66
- console.log("getcustomers");
67
- const { data, error, response } = await this.client.GET("/v1/customer", {
68
- params: { query: { customerId }, header: this.header }
69
- });
70
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
71
- return data ?? null;
72
- }
73
- async identifyCustomer(input) {
74
- const { data, error, response } = await this.client.POST("/v1/customer/identify", {
75
- params: { header: this.header },
76
- body: input
77
- });
78
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
79
- return data ?? null;
80
- }
81
- async upsertCustomer(input) {
82
- const { data, error, response } = await this.client.PUT("/v1/customer", {
83
- params: { header: this.header },
84
- body: input
85
- });
86
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
87
- return data;
88
- }
89
- async getFeatureAccess(customerId) {
90
- const { data, error, response } = await this.client.GET("/v1/feature-access", {
91
- params: { query: { customerId }, header: this.header }
92
- });
93
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
94
- return data;
95
- }
96
- async trackUsage(input) {
97
- const { data, error, response } = await this.client.POST("/v1/usage", {
98
- params: { header: this.header },
99
- body: input
100
- });
101
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
102
- return data;
67
+ this.customers = {
68
+ get: async (customerId) => {
69
+ const { data, error, response } = await this.client.GET("/v1/customer", {
70
+ params: { query: { customerId }, header: this.header }
71
+ });
72
+ if (error)
73
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
74
+ return data ?? null;
75
+ },
76
+ identify: async (input) => {
77
+ const { data, error, response } = await this.client.POST("/v1/customer/identify", {
78
+ params: { header: this.header },
79
+ body: input
80
+ });
81
+ if (error)
82
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
83
+ return data ?? null;
84
+ },
85
+ create: async (input) => {
86
+ const { data, error, response } = await this.client.POST("/v1/customer", {
87
+ params: { header: this.header },
88
+ body: input
89
+ });
90
+ if (error)
91
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
92
+ return data;
93
+ },
94
+ update: async (input) => {
95
+ const { data, error, response } = await this.client.PUT("/v1/customer", {
96
+ params: { header: this.header },
97
+ body: input
98
+ });
99
+ if (error)
100
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
101
+ return data;
102
+ },
103
+ delete: async (customerId) => {
104
+ const { data, error, response } = await this.client.DELETE("/v1/customer", {
105
+ params: { query: { customerId }, header: this.header }
106
+ });
107
+ if (error)
108
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
109
+ return data;
110
+ }
111
+ };
112
+ this.features = {
113
+ getAccess: async (customerId) => {
114
+ const { data, error, response } = await this.client.GET("/v1/feature-access", {
115
+ params: { query: { customerId }, header: this.header }
116
+ });
117
+ if (error)
118
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
119
+ return data;
120
+ }
121
+ };
122
+ this.usage = {
123
+ track: async (input) => {
124
+ const { data, error, response } = await this.client.POST("/v1/usage", {
125
+ params: { header: this.header },
126
+ body: input
127
+ });
128
+ if (error)
129
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
130
+ return data;
131
+ }
132
+ };
103
133
  }
104
134
  };
105
135
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export { PriceOS, PriceOSError } from \"./client\";\nexport type {\n PriceOSClientOptions,\n PriceOSHttpClient,\n} from \"./client\";\nexport type {\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n TrackUsageBody,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n","import createClient from \"openapi-fetch\";\nimport type { Client } from \"openapi-fetch\";\nimport type { paths } from \"./gen/openapi\";\nimport {\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n TrackUsageBody,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n\n// --- Public options ---\nexport type PriceOSClientOptions = {\n baseUrl?: string;\n fetch?: typeof fetch;\n userAgent?: string;\n};\n\n// --- Public SDK surface type ---\nexport type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;\n identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;\n upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;\n getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;\n trackUsage(input: TrackUsageBody): Promise<TrackUsageResponse>;\n};\n\nexport class PriceOSError extends Error {\n status?: number;\n details?: unknown;\n\n constructor(message: string, opts?: { status?: number; details?: unknown }) {\n super(message);\n this.name = \"PriceOSError\";\n this.status = opts?.status;\n this.details = opts?.details;\n }\n}\n\nexport class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse>\n implements PriceOSHttpClient<TFeatureAccessMap>\n{\n private client: Client<paths>;\n private header: { \"x-api-key\": string };\n\n constructor(apiKey: string, opts: PriceOSClientOptions = {}) {\n const baseUrl = opts.baseUrl ?? \"https://api.priceos.com\";\n this.header = { \"x-api-key\": apiKey };\n this.client = createClient<paths>({\n baseUrl,\n fetch: opts.fetch,\n headers: {\n \"x-api-key\": apiKey,\n ...(opts.userAgent ? { \"user-agent\": opts.userAgent } : {}),\n },\n });\n }\n\n async getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null> {\n console.log(\"getcustomers\")\n const { data, error, response } = await this.client.GET(\"/v1/customer\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return (data ?? null) as GetCustomerResponse<TFeatureAccessMap> | null;\n }\n\n async identifyCustomer(\n input: IdentifyCustomerBody\n ): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null> {\n const { data, error, response } = await this.client.POST(\"/v1/customer/identify\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return (data ?? null) as IdentifyCustomerResponse<TFeatureAccessMap> | null;\n }\n\n async upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>> {\n const { data, error, response } = await this.client.PUT(\"/v1/customer\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as UpdateCustomerResponse<TFeatureAccessMap>;\n }\n\n async getFeatureAccess(customerId: string) {\n const { data, error, response } = await this.client.GET(\"/v1/feature-access\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as TFeatureAccessMap;\n }\n\n async trackUsage(input: TrackUsageBody) {\n const { data, error, response } = await this.client.POST(\"/v1/usage\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data!;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAAyB;AA8BlB,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC;AAAA,EACA;AAAA,EAEA,YAAY,SAAiB,MAA+C;AAC1E,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS,MAAM;AACpB,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;AAEO,IAAM,UAAN,MAEP;AAAA,EACU;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,OAA6B,CAAC,GAAG;AAC3D,UAAM,UAAU,KAAK,WAAW;AAChC,SAAK,SAAS,EAAE,aAAa,OAAO;AACpC,SAAK,aAAS,qBAAAA,SAAoB;AAAA,MAChC;AAAA,MACA,OAAO,KAAK;AAAA,MACZ,SAAS;AAAA,QACP,aAAa;AAAA,QACb,GAAI,KAAK,YAAY,EAAE,cAAc,KAAK,UAAU,IAAI,CAAC;AAAA,MAC3D;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,YAAY,YAA4E;AAC5F,YAAQ,IAAI,cAAc;AAC1B,UAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,KAAK,OAAO,IAAI,gBAAgB;AAAA,MACtE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,QAAQ,KAAK,OAAO;AAAA,IACvD,C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,OAAO;AAAA,MAC9B,MAAM;AAAA,IACR,CAAC;AACD,QAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,WAAO;AAAA,EACT;AACF;","names":["createClient"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export { PriceOS, PriceOSError } from \"./client\";\nexport type {\n PriceOSClientOptions,\n PriceOSCustomersClient,\n PriceOSFeaturesClient,\n PriceOSHttpClient,\n PriceOSUsageClient,\n} from \"./client\";\nexport type {\n CreateCustomerRequest,\n CreateCustomerResponse,\n DeleteCustomerRequest,\n DeleteCustomerResponse,\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n TrackUsageBody,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n","import createClient from \"openapi-fetch\";\nimport type { Client } from \"openapi-fetch\";\nimport type { paths } from \"./gen/openapi\";\nimport {\n CreateCustomerRequest,\n CreateCustomerResponse,\n DeleteCustomerResponse,\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n TrackUsageBody,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n\n// --- Public options ---\nexport type PriceOSClientOptions = {\n baseUrl?: string;\n fetch?: typeof fetch;\n userAgent?: string;\n};\n\nexport type PriceOSCustomersClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n get(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;\n identify(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;\n create(input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>>;\n update(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;\n delete(customerId: string): Promise<DeleteCustomerResponse>;\n};\n\nexport type PriceOSFeaturesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n getAccess(customerId: string): Promise<TFeatureAccessMap>;\n};\n\nexport type PriceOSUsageClient = {\n track(input: TrackUsageBody): Promise<TrackUsageResponse>;\n};\n\n// --- Public SDK surface type ---\nexport type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n customers: PriceOSCustomersClient<TFeatureAccessMap>;\n features: PriceOSFeaturesClient<TFeatureAccessMap>;\n usage: PriceOSUsageClient;\n};\n\nexport class PriceOSError extends Error {\n status?: number;\n details?: unknown;\n\n constructor(message: string, opts?: { status?: number; details?: unknown }) {\n super(message);\n this.name = \"PriceOSError\";\n this.status = opts?.status;\n this.details = opts?.details;\n }\n}\n\nexport class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse>\n implements PriceOSHttpClient<TFeatureAccessMap>\n{\n private client: Client<paths>;\n private header: { \"x-api-key\": string };\n customers: PriceOSCustomersClient<TFeatureAccessMap>;\n features: PriceOSFeaturesClient<TFeatureAccessMap>;\n usage: PriceOSUsageClient;\n\n constructor(apiKey: string, opts: PriceOSClientOptions = {}) {\n const baseUrl = opts.baseUrl ?? \"https://api.priceos.com\";\n this.header = { \"x-api-key\": apiKey };\n this.client = createClient<paths>({\n baseUrl,\n fetch: opts.fetch,\n headers: {\n \"x-api-key\": apiKey,\n ...(opts.userAgent ? { \"user-agent\": opts.userAgent } : {}),\n },\n });\n\n this.customers = {\n get: async (customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null> => {\n const { data, error, response } = await this.client.GET(\"/v1/customer\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return (data ?? null) as GetCustomerResponse<TFeatureAccessMap> | null;\n },\n identify: async (\n input: IdentifyCustomerBody\n ): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null> => {\n const { data, error, response } = await this.client.POST(\"/v1/customer/identify\", {\n params: { header: this.header },\n body: input,\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return (data ?? null) as IdentifyCustomerResponse<TFeatureAccessMap> | null;\n },\n create: async (input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>> => {\n const { data, error, response } = await this.client.POST(\"/v1/customer\", {\n params: { header: this.header },\n body: input,\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as CreateCustomerResponse<TFeatureAccessMap>;\n },\n update: async (input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>> => {\n const { data, error, response } = await this.client.PUT(\"/v1/customer\", {\n params: { header: this.header },\n body: input,\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as UpdateCustomerResponse<TFeatureAccessMap>;\n },\n delete: async (customerId: string): Promise<DeleteCustomerResponse> => {\n const { data, error, response } = await this.client.DELETE(\"/v1/customer\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as DeleteCustomerResponse;\n },\n };\n\n this.features = {\n getAccess: async (customerId: string): Promise<TFeatureAccessMap> => {\n const { data, error, response } = await this.client.GET(\"/v1/feature-access\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as TFeatureAccessMap;\n },\n };\n\n this.usage = {\n track: async (input: TrackUsageBody): Promise<TrackUsageResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage\", {\n params: { header: this.header },\n body: input,\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data!;\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAAyB;AA+ClB,IAAM,eAAN,cAA2B,MA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G,eAAO;AAAA,MACT;AAAA,IACF;AAEA,SAAK,QAAQ;AAAA,MACX,OAAO,OAAO,UAAuD;AACnE,cAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,KAAK,OAAO,KAAK,aAAa;AAAA,UACpE,QAAQ,EAAE,QAAQ,KAAK,OAAO;AAAA,UAC9B,MAAM;AAAA,QACR,CAAC;AACD,YAAI;AACF,gBAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AACtG,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":["createClient"]}
package/dist/index.d.cts CHANGED
@@ -58,17 +58,17 @@ interface paths {
58
58
  id: string;
59
59
  /** @description Product name. */
60
60
  name: string;
61
+ /**
62
+ * @description Stripe subscription status (Stripe customers only).
63
+ * @enum {string}
64
+ */
65
+ status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
61
66
  /** @description Product version number. */
62
67
  version: number;
63
68
  /** @description Custom product metadata (custom products only). */
64
69
  metadata?: {
65
70
  [key: string]: string;
66
71
  };
67
- /**
68
- * @description Stripe subscription status (Stripe customers only).
69
- * @enum {string}
70
- */
71
- status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
72
72
  /** @description Unix timestamp (ms) when the subscription was canceled (Stripe customers only). */
73
73
  canceledAt?: number | null;
74
74
  /** @description Unix timestamp (ms) when the subscription started (Stripe customers only). */
@@ -221,17 +221,17 @@ interface paths {
221
221
  id: string;
222
222
  /** @description Product name. */
223
223
  name: string;
224
+ /**
225
+ * @description Stripe subscription status (Stripe customers only).
226
+ * @enum {string}
227
+ */
228
+ status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
224
229
  /** @description Product version number. */
225
230
  version: number;
226
231
  /** @description Custom product metadata (custom products only). */
227
232
  metadata?: {
228
233
  [key: string]: string;
229
234
  };
230
- /**
231
- * @description Stripe subscription status (Stripe customers only).
232
- * @enum {string}
233
- */
234
- status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
235
235
  /** @description Unix timestamp (ms) when the subscription was canceled (Stripe customers only). */
236
236
  canceledAt?: number | null;
237
237
  /** @description Unix timestamp (ms) when the subscription started (Stripe customers only). */
@@ -396,17 +396,17 @@ interface paths {
396
396
  id: string;
397
397
  /** @description Product name. */
398
398
  name: string;
399
+ /**
400
+ * @description Stripe subscription status (Stripe customers only).
401
+ * @enum {string}
402
+ */
403
+ status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
399
404
  /** @description Product version number. */
400
405
  version: number;
401
406
  /** @description Custom product metadata (custom products only). */
402
407
  metadata?: {
403
408
  [key: string]: string;
404
409
  };
405
- /**
406
- * @description Stripe subscription status (Stripe customers only).
407
- * @enum {string}
408
- */
409
- status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
410
410
  /** @description Unix timestamp (ms) when the subscription was canceled (Stripe customers only). */
411
411
  canceledAt?: number | null;
412
412
  /** @description Unix timestamp (ms) when the subscription started (Stripe customers only). */
@@ -662,17 +662,17 @@ interface paths {
662
662
  id: string;
663
663
  /** @description Product name. */
664
664
  name: string;
665
+ /**
666
+ * @description Stripe subscription status (Stripe customers only).
667
+ * @enum {string}
668
+ */
669
+ status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
665
670
  /** @description Product version number. */
666
671
  version: number;
667
672
  /** @description Custom product metadata (custom products only). */
668
673
  metadata?: {
669
674
  [key: string]: string;
670
675
  };
671
- /**
672
- * @description Stripe subscription status (Stripe customers only).
673
- * @enum {string}
674
- */
675
- status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
676
676
  /** @description Unix timestamp (ms) when the subscription was canceled (Stripe customers only). */
677
677
  canceledAt?: number | null;
678
678
  /** @description Unix timestamp (ms) when the subscription started (Stripe customers only). */
@@ -1133,9 +1133,14 @@ type WithFeatureAccess<T, TFeatureAccessMap> = T extends {
1133
1133
  } : T;
1134
1134
  type GetCustomerResponseBase = paths["/v1/customer"]["get"]["responses"][200]["content"]["application/json"];
1135
1135
  type GetCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<GetCustomerResponseBase, TFeatureAccessMap>;
1136
+ type CreateCustomerRequest = paths["/v1/customer"]["post"]["requestBody"]["content"]["application/json"];
1137
+ type CreateCustomerResponseBase = paths["/v1/customer"]["post"]["responses"][201]["content"]["application/json"];
1138
+ type CreateCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<CreateCustomerResponseBase, TFeatureAccessMap>;
1136
1139
  type UpdateCustomerBody = paths["/v1/customer"]["put"]["requestBody"]["content"]["application/json"];
1137
1140
  type UpdateCustomerResponseBase = paths["/v1/customer"]["put"]["responses"][200]["content"]["application/json"];
1138
1141
  type UpdateCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<UpdateCustomerResponseBase, TFeatureAccessMap>;
1142
+ type DeleteCustomerRequest = paths["/v1/customer"]["delete"]["parameters"]["query"];
1143
+ type DeleteCustomerResponse = paths["/v1/customer"]["delete"]["responses"][200]["content"]["application/json"];
1139
1144
  type IdentifyCustomerBody = paths["/v1/customer/identify"]["post"]["requestBody"]["content"]["application/json"];
1140
1145
  type IdentifyCustomerResponseBase = paths["/v1/customer/identify"]["post"]["responses"][200]["content"]["application/json"];
1141
1146
  type IdentifyCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<IdentifyCustomerResponseBase, TFeatureAccessMap>;
@@ -1148,12 +1153,23 @@ type PriceOSClientOptions = {
1148
1153
  fetch?: typeof fetch;
1149
1154
  userAgent?: string;
1150
1155
  };
1156
+ type PriceOSCustomersClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1157
+ get(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
1158
+ identify(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
1159
+ create(input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>>;
1160
+ update(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
1161
+ delete(customerId: string): Promise<DeleteCustomerResponse>;
1162
+ };
1163
+ type PriceOSFeaturesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1164
+ getAccess(customerId: string): Promise<TFeatureAccessMap>;
1165
+ };
1166
+ type PriceOSUsageClient = {
1167
+ track(input: TrackUsageBody): Promise<TrackUsageResponse>;
1168
+ };
1151
1169
  type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1152
- getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
1153
- identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
1154
- upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
1155
- getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
1156
- trackUsage(input: TrackUsageBody): Promise<TrackUsageResponse>;
1170
+ customers: PriceOSCustomersClient<TFeatureAccessMap>;
1171
+ features: PriceOSFeaturesClient<TFeatureAccessMap>;
1172
+ usage: PriceOSUsageClient;
1157
1173
  };
1158
1174
  declare class PriceOSError extends Error {
1159
1175
  status?: number;
@@ -1166,16 +1182,10 @@ declare class PriceOSError extends Error {
1166
1182
  declare class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse> implements PriceOSHttpClient<TFeatureAccessMap> {
1167
1183
  private client;
1168
1184
  private header;
1185
+ customers: PriceOSCustomersClient<TFeatureAccessMap>;
1186
+ features: PriceOSFeaturesClient<TFeatureAccessMap>;
1187
+ usage: PriceOSUsageClient;
1169
1188
  constructor(apiKey: string, opts?: PriceOSClientOptions);
1170
- getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
1171
- identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
1172
- upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
1173
- getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
1174
- trackUsage(input: TrackUsageBody): Promise<{
1175
- applied: boolean;
1176
- used: number | null;
1177
- reason?: string | null;
1178
- }>;
1179
1189
  }
1180
1190
 
1181
- export { type GetCustomerResponse, type GetFeatureAccessResponse, type IdentifyCustomerBody, type IdentifyCustomerResponse, PriceOS, type PriceOSClientOptions, PriceOSError, type PriceOSHttpClient, type TrackUsageBody, type TrackUsageResponse, type UpdateCustomerBody, type UpdateCustomerResponse };
1191
+ export { type CreateCustomerRequest, type CreateCustomerResponse, type DeleteCustomerRequest, type DeleteCustomerResponse, type GetCustomerResponse, type GetFeatureAccessResponse, type IdentifyCustomerBody, type IdentifyCustomerResponse, PriceOS, type PriceOSClientOptions, type PriceOSCustomersClient, PriceOSError, type PriceOSFeaturesClient, type PriceOSHttpClient, type PriceOSUsageClient, type TrackUsageBody, type TrackUsageResponse, type UpdateCustomerBody, type UpdateCustomerResponse };
package/dist/index.d.ts CHANGED
@@ -58,17 +58,17 @@ interface paths {
58
58
  id: string;
59
59
  /** @description Product name. */
60
60
  name: string;
61
+ /**
62
+ * @description Stripe subscription status (Stripe customers only).
63
+ * @enum {string}
64
+ */
65
+ status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
61
66
  /** @description Product version number. */
62
67
  version: number;
63
68
  /** @description Custom product metadata (custom products only). */
64
69
  metadata?: {
65
70
  [key: string]: string;
66
71
  };
67
- /**
68
- * @description Stripe subscription status (Stripe customers only).
69
- * @enum {string}
70
- */
71
- status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
72
72
  /** @description Unix timestamp (ms) when the subscription was canceled (Stripe customers only). */
73
73
  canceledAt?: number | null;
74
74
  /** @description Unix timestamp (ms) when the subscription started (Stripe customers only). */
@@ -221,17 +221,17 @@ interface paths {
221
221
  id: string;
222
222
  /** @description Product name. */
223
223
  name: string;
224
+ /**
225
+ * @description Stripe subscription status (Stripe customers only).
226
+ * @enum {string}
227
+ */
228
+ status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
224
229
  /** @description Product version number. */
225
230
  version: number;
226
231
  /** @description Custom product metadata (custom products only). */
227
232
  metadata?: {
228
233
  [key: string]: string;
229
234
  };
230
- /**
231
- * @description Stripe subscription status (Stripe customers only).
232
- * @enum {string}
233
- */
234
- status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
235
235
  /** @description Unix timestamp (ms) when the subscription was canceled (Stripe customers only). */
236
236
  canceledAt?: number | null;
237
237
  /** @description Unix timestamp (ms) when the subscription started (Stripe customers only). */
@@ -396,17 +396,17 @@ interface paths {
396
396
  id: string;
397
397
  /** @description Product name. */
398
398
  name: string;
399
+ /**
400
+ * @description Stripe subscription status (Stripe customers only).
401
+ * @enum {string}
402
+ */
403
+ status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
399
404
  /** @description Product version number. */
400
405
  version: number;
401
406
  /** @description Custom product metadata (custom products only). */
402
407
  metadata?: {
403
408
  [key: string]: string;
404
409
  };
405
- /**
406
- * @description Stripe subscription status (Stripe customers only).
407
- * @enum {string}
408
- */
409
- status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
410
410
  /** @description Unix timestamp (ms) when the subscription was canceled (Stripe customers only). */
411
411
  canceledAt?: number | null;
412
412
  /** @description Unix timestamp (ms) when the subscription started (Stripe customers only). */
@@ -662,17 +662,17 @@ interface paths {
662
662
  id: string;
663
663
  /** @description Product name. */
664
664
  name: string;
665
+ /**
666
+ * @description Stripe subscription status (Stripe customers only).
667
+ * @enum {string}
668
+ */
669
+ status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
665
670
  /** @description Product version number. */
666
671
  version: number;
667
672
  /** @description Custom product metadata (custom products only). */
668
673
  metadata?: {
669
674
  [key: string]: string;
670
675
  };
671
- /**
672
- * @description Stripe subscription status (Stripe customers only).
673
- * @enum {string}
674
- */
675
- status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
676
676
  /** @description Unix timestamp (ms) when the subscription was canceled (Stripe customers only). */
677
677
  canceledAt?: number | null;
678
678
  /** @description Unix timestamp (ms) when the subscription started (Stripe customers only). */
@@ -1133,9 +1133,14 @@ type WithFeatureAccess<T, TFeatureAccessMap> = T extends {
1133
1133
  } : T;
1134
1134
  type GetCustomerResponseBase = paths["/v1/customer"]["get"]["responses"][200]["content"]["application/json"];
1135
1135
  type GetCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<GetCustomerResponseBase, TFeatureAccessMap>;
1136
+ type CreateCustomerRequest = paths["/v1/customer"]["post"]["requestBody"]["content"]["application/json"];
1137
+ type CreateCustomerResponseBase = paths["/v1/customer"]["post"]["responses"][201]["content"]["application/json"];
1138
+ type CreateCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<CreateCustomerResponseBase, TFeatureAccessMap>;
1136
1139
  type UpdateCustomerBody = paths["/v1/customer"]["put"]["requestBody"]["content"]["application/json"];
1137
1140
  type UpdateCustomerResponseBase = paths["/v1/customer"]["put"]["responses"][200]["content"]["application/json"];
1138
1141
  type UpdateCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<UpdateCustomerResponseBase, TFeatureAccessMap>;
1142
+ type DeleteCustomerRequest = paths["/v1/customer"]["delete"]["parameters"]["query"];
1143
+ type DeleteCustomerResponse = paths["/v1/customer"]["delete"]["responses"][200]["content"]["application/json"];
1139
1144
  type IdentifyCustomerBody = paths["/v1/customer/identify"]["post"]["requestBody"]["content"]["application/json"];
1140
1145
  type IdentifyCustomerResponseBase = paths["/v1/customer/identify"]["post"]["responses"][200]["content"]["application/json"];
1141
1146
  type IdentifyCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<IdentifyCustomerResponseBase, TFeatureAccessMap>;
@@ -1148,12 +1153,23 @@ type PriceOSClientOptions = {
1148
1153
  fetch?: typeof fetch;
1149
1154
  userAgent?: string;
1150
1155
  };
1156
+ type PriceOSCustomersClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1157
+ get(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
1158
+ identify(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
1159
+ create(input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>>;
1160
+ update(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
1161
+ delete(customerId: string): Promise<DeleteCustomerResponse>;
1162
+ };
1163
+ type PriceOSFeaturesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1164
+ getAccess(customerId: string): Promise<TFeatureAccessMap>;
1165
+ };
1166
+ type PriceOSUsageClient = {
1167
+ track(input: TrackUsageBody): Promise<TrackUsageResponse>;
1168
+ };
1151
1169
  type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1152
- getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
1153
- identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
1154
- upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
1155
- getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
1156
- trackUsage(input: TrackUsageBody): Promise<TrackUsageResponse>;
1170
+ customers: PriceOSCustomersClient<TFeatureAccessMap>;
1171
+ features: PriceOSFeaturesClient<TFeatureAccessMap>;
1172
+ usage: PriceOSUsageClient;
1157
1173
  };
1158
1174
  declare class PriceOSError extends Error {
1159
1175
  status?: number;
@@ -1166,16 +1182,10 @@ declare class PriceOSError extends Error {
1166
1182
  declare class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse> implements PriceOSHttpClient<TFeatureAccessMap> {
1167
1183
  private client;
1168
1184
  private header;
1185
+ customers: PriceOSCustomersClient<TFeatureAccessMap>;
1186
+ features: PriceOSFeaturesClient<TFeatureAccessMap>;
1187
+ usage: PriceOSUsageClient;
1169
1188
  constructor(apiKey: string, opts?: PriceOSClientOptions);
1170
- getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
1171
- identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
1172
- upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
1173
- getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
1174
- trackUsage(input: TrackUsageBody): Promise<{
1175
- applied: boolean;
1176
- used: number | null;
1177
- reason?: string | null;
1178
- }>;
1179
1189
  }
1180
1190
 
1181
- export { type GetCustomerResponse, type GetFeatureAccessResponse, type IdentifyCustomerBody, type IdentifyCustomerResponse, PriceOS, type PriceOSClientOptions, PriceOSError, type PriceOSHttpClient, type TrackUsageBody, type TrackUsageResponse, type UpdateCustomerBody, type UpdateCustomerResponse };
1191
+ export { type CreateCustomerRequest, type CreateCustomerResponse, type DeleteCustomerRequest, type DeleteCustomerResponse, type GetCustomerResponse, type GetFeatureAccessResponse, type IdentifyCustomerBody, type IdentifyCustomerResponse, PriceOS, type PriceOSClientOptions, type PriceOSCustomersClient, PriceOSError, type PriceOSFeaturesClient, type PriceOSHttpClient, type PriceOSUsageClient, type TrackUsageBody, type TrackUsageResponse, type UpdateCustomerBody, type UpdateCustomerResponse };
package/dist/index.js CHANGED
@@ -13,6 +13,9 @@ var PriceOSError = class extends Error {
13
13
  var PriceOS = class {
14
14
  client;
15
15
  header;
16
+ customers;
17
+ features;
18
+ usage;
16
19
  constructor(apiKey, opts = {}) {
17
20
  const baseUrl = opts.baseUrl ?? "https://api.priceos.com";
18
21
  this.header = { "x-api-key": apiKey };
@@ -24,45 +27,72 @@ var PriceOS = class {
24
27
  ...opts.userAgent ? { "user-agent": opts.userAgent } : {}
25
28
  }
26
29
  });
27
- }
28
- async getCustomer(customerId) {
29
- console.log("getcustomers");
30
- const { data, error, response } = await this.client.GET("/v1/customer", {
31
- params: { query: { customerId }, header: this.header }
32
- });
33
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
34
- return data ?? null;
35
- }
36
- async identifyCustomer(input) {
37
- const { data, error, response } = await this.client.POST("/v1/customer/identify", {
38
- params: { header: this.header },
39
- body: input
40
- });
41
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
42
- return data ?? null;
43
- }
44
- async upsertCustomer(input) {
45
- const { data, error, response } = await this.client.PUT("/v1/customer", {
46
- params: { header: this.header },
47
- body: input
48
- });
49
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
50
- return data;
51
- }
52
- async getFeatureAccess(customerId) {
53
- const { data, error, response } = await this.client.GET("/v1/feature-access", {
54
- params: { query: { customerId }, header: this.header }
55
- });
56
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
57
- return data;
58
- }
59
- async trackUsage(input) {
60
- const { data, error, response } = await this.client.POST("/v1/usage", {
61
- params: { header: this.header },
62
- body: input
63
- });
64
- if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
65
- return data;
30
+ this.customers = {
31
+ get: async (customerId) => {
32
+ const { data, error, response } = await this.client.GET("/v1/customer", {
33
+ params: { query: { customerId }, header: this.header }
34
+ });
35
+ if (error)
36
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
37
+ return data ?? null;
38
+ },
39
+ identify: async (input) => {
40
+ const { data, error, response } = await this.client.POST("/v1/customer/identify", {
41
+ params: { header: this.header },
42
+ body: input
43
+ });
44
+ if (error)
45
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
46
+ return data ?? null;
47
+ },
48
+ create: async (input) => {
49
+ const { data, error, response } = await this.client.POST("/v1/customer", {
50
+ params: { header: this.header },
51
+ body: input
52
+ });
53
+ if (error)
54
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
55
+ return data;
56
+ },
57
+ update: async (input) => {
58
+ const { data, error, response } = await this.client.PUT("/v1/customer", {
59
+ params: { header: this.header },
60
+ body: input
61
+ });
62
+ if (error)
63
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
64
+ return data;
65
+ },
66
+ delete: async (customerId) => {
67
+ const { data, error, response } = await this.client.DELETE("/v1/customer", {
68
+ params: { query: { customerId }, header: this.header }
69
+ });
70
+ if (error)
71
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
72
+ return data;
73
+ }
74
+ };
75
+ this.features = {
76
+ getAccess: async (customerId) => {
77
+ const { data, error, response } = await this.client.GET("/v1/feature-access", {
78
+ params: { query: { customerId }, header: this.header }
79
+ });
80
+ if (error)
81
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
82
+ return data;
83
+ }
84
+ };
85
+ this.usage = {
86
+ track: async (input) => {
87
+ const { data, error, response } = await this.client.POST("/v1/usage", {
88
+ params: { header: this.header },
89
+ body: input
90
+ });
91
+ if (error)
92
+ throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
93
+ return data;
94
+ }
95
+ };
66
96
  }
67
97
  };
68
98
  export {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import createClient from \"openapi-fetch\";\nimport type { Client } from \"openapi-fetch\";\nimport type { paths } from \"./gen/openapi\";\nimport {\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n TrackUsageBody,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n\n// --- Public options ---\nexport type PriceOSClientOptions = {\n baseUrl?: string;\n fetch?: typeof fetch;\n userAgent?: string;\n};\n\n// --- Public SDK surface type ---\nexport type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;\n identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;\n upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;\n getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;\n trackUsage(input: TrackUsageBody): Promise<TrackUsageResponse>;\n};\n\nexport class PriceOSError extends Error {\n status?: number;\n details?: unknown;\n\n constructor(message: string, opts?: { status?: number; details?: unknown }) {\n super(message);\n this.name = \"PriceOSError\";\n this.status = opts?.status;\n this.details = opts?.details;\n }\n}\n\nexport class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse>\n implements PriceOSHttpClient<TFeatureAccessMap>\n{\n private client: Client<paths>;\n private header: { \"x-api-key\": string };\n\n constructor(apiKey: string, opts: PriceOSClientOptions = {}) {\n const baseUrl = opts.baseUrl ?? \"https://api.priceos.com\";\n this.header = { \"x-api-key\": apiKey };\n this.client = createClient<paths>({\n baseUrl,\n fetch: opts.fetch,\n headers: {\n \"x-api-key\": apiKey,\n ...(opts.userAgent ? { \"user-agent\": opts.userAgent } : {}),\n },\n });\n }\n\n async getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null> {\n console.log(\"getcustomers\")\n const { data, error, response } = await this.client.GET(\"/v1/customer\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return (data ?? null) as GetCustomerResponse<TFeatureAccessMap> | null;\n }\n\n async identifyCustomer(\n input: IdentifyCustomerBody\n ): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null> {\n const { data, error, response } = await this.client.POST(\"/v1/customer/identify\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return (data ?? null) as IdentifyCustomerResponse<TFeatureAccessMap> | null;\n }\n\n async upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>> {\n const { data, error, response } = await this.client.PUT(\"/v1/customer\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as UpdateCustomerResponse<TFeatureAccessMap>;\n }\n\n async getFeatureAccess(customerId: string) {\n const { data, error, response } = await this.client.GET(\"/v1/feature-access\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as TFeatureAccessMap;\n }\n\n async trackUsage(input: TrackUsageBody) {\n const { data, error, response } = await this.client.POST(\"/v1/usage\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data!;\n }\n}\n"],"mappings":";AAAA,OAAO,kBAAkB;AA8BlB,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC;AAAA,EACA;AAAA,EAEA,YAAY,SAAiB,MAA+C;AAC1E,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS,MAAM;AACpB,SAAK,UAAU,MAAM;AAAA,EACvB;AACF;AAEO,IAAM,UAAN,MAEP;AAAA,EACU;AAAA,EACA;AAAA,EAER,YAAY,QAAgB,OAA6B,CAAC,GAAG;AAC3D,UAAM,UAAU,KAAK,WAAW;AAChC,SAAK,SAAS,EAA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oB;AACzC,UAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,KAAK,OAAO,IAAI,sBAAsB;AAAA,MAC5E,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,QAAQ,KAAK,OAAO;AAAA,IACvD,CAAC;AACD,QAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,WAAW,OAAuB;AACtC,UAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,KAAK,OAAO,KAAK,aAAa;AAAA,MACpE,QAAQ,EAAE,QAAQ,KAAK,OAAO;AAAA,MAC9B,MAAM;AAAA,IACR,CAAC;AACD,QAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,WAAO;AAAA,EACT;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["import createClient from \"openapi-fetch\";\nimport type { Client } from \"openapi-fetch\";\nimport type { paths } from \"./gen/openapi\";\nimport {\n CreateCustomerRequest,\n CreateCustomerResponse,\n DeleteCustomerResponse,\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n TrackUsageBody,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n\n// --- Public options ---\nexport type PriceOSClientOptions = {\n baseUrl?: string;\n fetch?: typeof fetch;\n userAgent?: string;\n};\n\nexport type PriceOSCustomersClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n get(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;\n identify(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;\n create(input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>>;\n update(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;\n delete(customerId: string): Promise<DeleteCustomerResponse>;\n};\n\nexport type PriceOSFeaturesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n getAccess(customerId: string): Promise<TFeatureAccessMap>;\n};\n\nexport type PriceOSUsageClient = {\n track(input: TrackUsageBody): Promise<TrackUsageResponse>;\n};\n\n// --- Public SDK surface type ---\nexport type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n customers: PriceOSCustomersClient<TFeatureAccessMap>;\n features: PriceOSFeaturesClient<TFeatureAccessMap>;\n usage: PriceOSUsageClient;\n};\n\nexport class PriceOSError extends Error {\n status?: number;\n details?: unknown;\n\n constructor(message: string, opts?: { status?: number; details?: unknown }) {\n super(message);\n this.name = \"PriceOSError\";\n this.status = opts?.status;\n this.details = opts?.details;\n }\n}\n\nexport class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse>\n implements PriceOSHttpClient<TFeatureAccessMap>\n{\n private client: Client<paths>;\n private header: { \"x-api-key\": string };\n customers: PriceOSCustomersClient<TFeatureAccessMap>;\n features: PriceOSFeaturesClient<TFeatureAccessMap>;\n usage: PriceOSUsageClient;\n\n constructor(apiKey: string, opts: PriceOSClientOptions = {}) {\n const baseUrl = opts.baseUrl ?? \"https://api.priceos.com\";\n this.header = { \"x-api-key\": apiKey };\n this.client = createClient<paths>({\n baseUrl,\n fetch: opts.fetch,\n headers: {\n \"x-api-key\": apiKey,\n ...(opts.userAgent ? { \"user-agent\": opts.userAgent } : {}),\n },\n });\n\n this.customers = {\n get: async (customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null> => {\n const { data, error, response } = await this.client.GET(\"/v1/customer\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return (data ?? null) as GetCustomerResponse<TFeatureAccessMap> | null;\n },\n identify: async (\n input: IdentifyCustomerBody\n ): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null> => {\n const { data, error, response } = await this.client.POST(\"/v1/customer/identify\", {\n params: { header: this.header },\n body: input,\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return (data ?? null) as IdentifyCustomerResponse<TFeatureAccessMap> | null;\n },\n create: async (input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>> => {\n const { data, error, response } = await this.client.POST(\"/v1/customer\", {\n params: { header: this.header },\n body: input,\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as CreateCustomerResponse<TFeatureAccessMap>;\n },\n update: async (input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>> => {\n const { data, error, response } = await this.client.PUT(\"/v1/customer\", {\n params: { header: this.header },\n body: input,\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as UpdateCustomerResponse<TFeatureAccessMap>;\n },\n delete: async (customerId: string): Promise<DeleteCustomerResponse> => {\n const { data, error, response } = await this.client.DELETE(\"/v1/customer\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as DeleteCustomerResponse;\n },\n };\n\n this.features = {\n getAccess: async (customerId: string): Promise<TFeatureAccessMap> => {\n const { data, error, response } = await this.client.GET(\"/v1/feature-access\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data! as TFeatureAccessMap;\n },\n };\n\n this.usage = {\n track: async (input: TrackUsageBody): Promise<TrackUsageResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage\", {\n params: { header: this.header },\n body: input,\n });\n if (error)\n throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data!;\n },\n };\n }\n}\n"],"mappings":";AAAA,OAAO,kBAAkB;AA+ClB,IAAM,eAAN,cAA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eAAO;AAAA,MACT;AAAA,IACF;AAEA,SAAK,QAAQ;AAAA,MACX,OAAO,OAAO,UAAuD;AACnE,cAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,KAAK,OAAO,KAAK,aAAa;AAAA,UACpE,QAAQ,EAAE,QAAQ,KAAK,OAAO;AAAA,UAC9B,MAAM;AAAA,QACR,CAAC;AACD,YAAI;AACF,gBAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AACtG,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "priceos",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -18,7 +18,7 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "gen:types": "openapi-typescript ../../api/public/openapi.json -o src/gen/openapi.d.ts",
21
- "sync:features": "node --import tsx src/cli.ts sync --out ../playground/src/feature-keys.d.ts",
21
+ "sync:features": "node --import tsx src/cli.ts generate-types --out ../playground/src/feature-keys.d.ts",
22
22
  "build": "pnpm gen:types && tsup",
23
23
  "dev": "pnpm gen:types && tsup src/index.ts --format esm,cjs --dts --watch",
24
24
  "lint": "eslint .",