priceos 0.0.1

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 ADDED
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/cli.ts
27
+ var import_promises = __toESM(require("fs/promises"), 1);
28
+ var import_node_path = __toESM(require("path"), 1);
29
+ function argValue(args, name) {
30
+ const idx = args.indexOf(name);
31
+ if (idx === -1) return void 0;
32
+ return args[idx + 1];
33
+ }
34
+ function hasFlag(args, name) {
35
+ return args.includes(name);
36
+ }
37
+ function normalizeBaseUrl(baseUrl) {
38
+ return baseUrl.replace(/\/$/, "");
39
+ }
40
+ function printHelp() {
41
+ console.log(`
42
+ priceos sync
43
+
44
+ Generates TypeScript feature access types for your PriceOS workspace.
45
+
46
+ Options:
47
+ --base-url <url> PriceOS API base URL (defaults to env PRICEOS_BASE_URL or https://api.priceos.com)
48
+ --api-key <key> PriceOS API key (defaults to env PRICEOS_API_KEY) [required]
49
+ --out <path> Output .d.ts file (default: src/priceos.d.ts)
50
+ -h, --help Show help
51
+
52
+ Examples:
53
+ priceos sync --api-key sk_test_... --base-url http://localhost:3000
54
+ priceos sync --api-key sk_test_... --out src/priceos.d.ts
55
+ `.trim());
56
+ }
57
+ async function main() {
58
+ const args = process.argv.slice(2);
59
+ if (args.length === 0 || hasFlag(args, "--help") || hasFlag(args, "-h")) {
60
+ printHelp();
61
+ process.exit(args.length === 0 ? 1 : 0);
62
+ }
63
+ const cmd = args[0];
64
+ if (cmd !== "sync") {
65
+ console.error(`Unknown command: ${cmd}`);
66
+ printHelp();
67
+ process.exit(1);
68
+ }
69
+ const baseUrl = argValue(args, "--base-url") ?? process.env.PRICEOS_BASE_URL ?? "https://api.priceos.com";
70
+ const apiKey = argValue(args, "--api-key") ?? process.env.PRICEOS_API_KEY;
71
+ if (!apiKey) {
72
+ console.error("Missing API key. Provide --api-key <key> or set PRICEOS_API_KEY.");
73
+ process.exit(1);
74
+ }
75
+ const outRel = argValue(args, "--out") ?? "src/priceos.d.ts";
76
+ const outPath = import_node_path.default.resolve(process.cwd(), outRel);
77
+ const url = `${normalizeBaseUrl(baseUrl)}/v1/features`;
78
+ const res = await fetch(url, {
79
+ headers: { "x-api-key": apiKey }
80
+ });
81
+ if (!res.ok) {
82
+ const text = await res.text().catch(() => "");
83
+ console.error(`Failed to fetch features: ${res.status} ${res.statusText}
84
+ ${text}`);
85
+ process.exit(1);
86
+ }
87
+ const features = await res.json();
88
+ const typeByKey = /* @__PURE__ */ new Map();
89
+ for (const feature of features ?? []) {
90
+ if (!feature?.featureKey) continue;
91
+ const key = feature.featureKey;
92
+ const nextType = feature.type === "boolean" || feature.type === "limit" ? feature.type : "unknown";
93
+ const currentType = typeByKey.get(key);
94
+ if (!currentType) {
95
+ typeByKey.set(key, nextType);
96
+ continue;
97
+ }
98
+ if (currentType !== nextType) {
99
+ typeByKey.set(key, "unknown");
100
+ }
101
+ }
102
+ const keys = [...typeByKey.keys()].sort();
103
+ const union = keys.length ? keys.map((k) => JSON.stringify(k)).join(" | ") : "never";
104
+ const mapLines = keys.map((key) => {
105
+ const featureType = typeByKey.get(key);
106
+ const accessType = featureType === "boolean" ? "BooleanFeatureAccess" : featureType === "limit" ? "LimitFeatureAccess" : "FeatureAccessEntry";
107
+ return ` ${JSON.stringify(key)}: ${accessType};`;
108
+ });
109
+ const content = `// Auto-generated by PriceOS (priceos sync). Do not edit.
110
+ export type FeatureKey = ${union};
111
+ export type BooleanFeatureAccess = {
112
+ type: "boolean";
113
+ hasAccess: boolean;
114
+ };
115
+ export type LimitFeatureAccess = {
116
+ type: "limit";
117
+ hasAccess: boolean;
118
+ isUnlimited: boolean;
119
+ limit: number | null;
120
+ used: number;
121
+ };
122
+ export type FeatureAccessEntry = BooleanFeatureAccess | LimitFeatureAccess;
123
+ export type FeatureAccessMap = {
124
+ ${mapLines.join("\n")}
125
+ } & Record<string, FeatureAccessEntry>;
126
+ `;
127
+ await import_promises.default.mkdir(import_node_path.default.dirname(outPath), { recursive: true });
128
+ await import_promises.default.writeFile(outPath, content, "utf8");
129
+ console.log(`Generated ${outRel} (${keys.length} feature keys)`);
130
+ }
131
+ main().catch((e) => {
132
+ console.error(e);
133
+ process.exit(1);
134
+ });
135
+ //# sourceMappingURL=cli.cjs.map
@@ -0,0 +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\nfunction normalizeBaseUrl(baseUrl: string) {\n return baseUrl.replace(/\\/$/, \"\");\n}\n\nfunction printHelp() {\n console.log(`\npriceos sync\n\nGenerates TypeScript feature access types for your PriceOS workspace.\n\nOptions:\n --base-url <url> PriceOS API base URL (defaults to env PRICEOS_BASE_URL or https://api.priceos.com)\n --api-key <key> PriceOS API key (defaults to env PRICEOS_API_KEY) [required]\n --out <path> Output .d.ts file (default: src/priceos.d.ts)\n -h, --help Show help\n\nExamples:\n priceos sync --api-key sk_test_... --base-url http://localhost:3000\n priceos sync --api-key sk_test_... --out src/priceos.d.ts\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 baseUrl =\n argValue(args, \"--base-url\") ??\n process.env.PRICEOS_BASE_URL ??\n \"https://api.priceos.com\";\n\n const apiKey =\n argValue(args, \"--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.\");\n process.exit(1);\n }\n\n const outRel = argValue(args, \"--out\") ?? \"src/priceos.d.ts\";\n const outPath = path.resolve(process.cwd(), outRel);\n\n const url = `${normalizeBaseUrl(baseUrl)}/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 ${outRel} (${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,SAAS,iBAAiB,SAAiB;AACzC,SAAO,QAAQ,QAAQ,OAAO,EAAE;AAClC;AAEA,SAAS,YAAY;AACnB,UAAQ,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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package/dist/cli.js ADDED
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import fs from "fs/promises";
5
+ import path from "path";
6
+ function argValue(args, name) {
7
+ const idx = args.indexOf(name);
8
+ if (idx === -1) return void 0;
9
+ return args[idx + 1];
10
+ }
11
+ function hasFlag(args, name) {
12
+ return args.includes(name);
13
+ }
14
+ function normalizeBaseUrl(baseUrl) {
15
+ return baseUrl.replace(/\/$/, "");
16
+ }
17
+ function printHelp() {
18
+ console.log(`
19
+ priceos sync
20
+
21
+ Generates TypeScript feature access types for your PriceOS workspace.
22
+
23
+ Options:
24
+ --base-url <url> PriceOS API base URL (defaults to env PRICEOS_BASE_URL or https://api.priceos.com)
25
+ --api-key <key> PriceOS API key (defaults to env PRICEOS_API_KEY) [required]
26
+ --out <path> Output .d.ts file (default: src/priceos.d.ts)
27
+ -h, --help Show help
28
+
29
+ Examples:
30
+ priceos sync --api-key sk_test_... --base-url http://localhost:3000
31
+ priceos sync --api-key sk_test_... --out src/priceos.d.ts
32
+ `.trim());
33
+ }
34
+ async function main() {
35
+ const args = process.argv.slice(2);
36
+ if (args.length === 0 || hasFlag(args, "--help") || hasFlag(args, "-h")) {
37
+ printHelp();
38
+ process.exit(args.length === 0 ? 1 : 0);
39
+ }
40
+ const cmd = args[0];
41
+ if (cmd !== "sync") {
42
+ console.error(`Unknown command: ${cmd}`);
43
+ printHelp();
44
+ process.exit(1);
45
+ }
46
+ const baseUrl = argValue(args, "--base-url") ?? process.env.PRICEOS_BASE_URL ?? "https://api.priceos.com";
47
+ const apiKey = argValue(args, "--api-key") ?? process.env.PRICEOS_API_KEY;
48
+ if (!apiKey) {
49
+ console.error("Missing API key. Provide --api-key <key> or set PRICEOS_API_KEY.");
50
+ process.exit(1);
51
+ }
52
+ const outRel = argValue(args, "--out") ?? "src/priceos.d.ts";
53
+ const outPath = path.resolve(process.cwd(), outRel);
54
+ const url = `${normalizeBaseUrl(baseUrl)}/v1/features`;
55
+ const res = await fetch(url, {
56
+ headers: { "x-api-key": apiKey }
57
+ });
58
+ if (!res.ok) {
59
+ const text = await res.text().catch(() => "");
60
+ console.error(`Failed to fetch features: ${res.status} ${res.statusText}
61
+ ${text}`);
62
+ process.exit(1);
63
+ }
64
+ const features = await res.json();
65
+ const typeByKey = /* @__PURE__ */ new Map();
66
+ for (const feature of features ?? []) {
67
+ if (!feature?.featureKey) continue;
68
+ const key = feature.featureKey;
69
+ const nextType = feature.type === "boolean" || feature.type === "limit" ? feature.type : "unknown";
70
+ const currentType = typeByKey.get(key);
71
+ if (!currentType) {
72
+ typeByKey.set(key, nextType);
73
+ continue;
74
+ }
75
+ if (currentType !== nextType) {
76
+ typeByKey.set(key, "unknown");
77
+ }
78
+ }
79
+ const keys = [...typeByKey.keys()].sort();
80
+ const union = keys.length ? keys.map((k) => JSON.stringify(k)).join(" | ") : "never";
81
+ const mapLines = keys.map((key) => {
82
+ const featureType = typeByKey.get(key);
83
+ const accessType = featureType === "boolean" ? "BooleanFeatureAccess" : featureType === "limit" ? "LimitFeatureAccess" : "FeatureAccessEntry";
84
+ return ` ${JSON.stringify(key)}: ${accessType};`;
85
+ });
86
+ const content = `// Auto-generated by PriceOS (priceos sync). Do not edit.
87
+ export type FeatureKey = ${union};
88
+ export type BooleanFeatureAccess = {
89
+ type: "boolean";
90
+ hasAccess: boolean;
91
+ };
92
+ export type LimitFeatureAccess = {
93
+ type: "limit";
94
+ hasAccess: boolean;
95
+ isUnlimited: boolean;
96
+ limit: number | null;
97
+ used: number;
98
+ };
99
+ export type FeatureAccessEntry = BooleanFeatureAccess | LimitFeatureAccess;
100
+ export type FeatureAccessMap = {
101
+ ${mapLines.join("\n")}
102
+ } & Record<string, FeatureAccessEntry>;
103
+ `;
104
+ await fs.mkdir(path.dirname(outPath), { recursive: true });
105
+ await fs.writeFile(outPath, content, "utf8");
106
+ console.log(`Generated ${outRel} (${keys.length} feature keys)`);
107
+ }
108
+ main().catch((e) => {
109
+ console.error(e);
110
+ process.exit(1);
111
+ });
112
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +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\nfunction normalizeBaseUrl(baseUrl: string) {\n return baseUrl.replace(/\\/$/, \"\");\n}\n\nfunction printHelp() {\n console.log(`\npriceos sync\n\nGenerates TypeScript feature access types for your PriceOS workspace.\n\nOptions:\n --base-url <url> PriceOS API base URL (defaults to env PRICEOS_BASE_URL or https://api.priceos.com)\n --api-key <key> PriceOS API key (defaults to env PRICEOS_API_KEY) [required]\n --out <path> Output .d.ts file (default: src/priceos.d.ts)\n -h, --help Show help\n\nExamples:\n priceos sync --api-key sk_test_... --base-url http://localhost:3000\n priceos sync --api-key sk_test_... --out src/priceos.d.ts\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 baseUrl =\n argValue(args, \"--base-url\") ??\n process.env.PRICEOS_BASE_URL ??\n \"https://api.priceos.com\";\n\n const apiKey =\n argValue(args, \"--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.\");\n process.exit(1);\n }\n\n const outRel = argValue(args, \"--out\") ?? \"src/priceos.d.ts\";\n const outPath = path.resolve(process.cwd(), outRel);\n\n const url = `${normalizeBaseUrl(baseUrl)}/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 ${outRel} (${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,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AAM,GAAG,UAAU,SAAS,SAAS,MAAM;AAE3C,UAAQ,IAAI,aAAa,MAAM,KAAK,KAAK,MAAM,gBAAgB;AACjE;AAEA,KAAK,EAAE,MAAM,CAAC,MAAM;AAClB,UAAQ,MAAM,CAAC;AACf,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":[]}
package/dist/index.cjs ADDED
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ PriceOSError: () => PriceOSError,
34
+ createHttpClient: () => createHttpClient
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/client.ts
39
+ var import_openapi_fetch = __toESM(require("openapi-fetch"), 1);
40
+ var PriceOSError = class extends Error {
41
+ status;
42
+ details;
43
+ constructor(message, opts) {
44
+ super(message);
45
+ this.name = "PriceOSError";
46
+ this.status = opts?.status;
47
+ this.details = opts?.details;
48
+ }
49
+ };
50
+ function createHttpClient(opts) {
51
+ const baseUrl = opts.baseUrl ?? "https://api.priceos.com";
52
+ const header = { "x-api-key": opts.apiKey };
53
+ const client = (0, import_openapi_fetch.default)({
54
+ baseUrl,
55
+ fetch: opts.fetch,
56
+ headers: {
57
+ "x-api-key": opts.apiKey,
58
+ ...opts.userAgent ? { "user-agent": opts.userAgent } : {}
59
+ }
60
+ });
61
+ return {
62
+ raw: client,
63
+ async getCustomer(customerId) {
64
+ const { data, error, response } = await client.GET("/v1/customer", {
65
+ params: { query: { customerId }, header }
66
+ });
67
+ if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
68
+ return data ?? null;
69
+ },
70
+ async identifyCustomer(input) {
71
+ const { data, error, response } = await client.POST("/v1/customer/identify", {
72
+ params: { header },
73
+ body: input
74
+ });
75
+ if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
76
+ return data ?? null;
77
+ },
78
+ async upsertCustomer(input) {
79
+ const { data, error, response } = await client.PUT("/v1/customer", { params: { header }, body: input });
80
+ if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
81
+ return data;
82
+ },
83
+ async getFeatureAccess(customerId) {
84
+ const { data, error, response } = await client.GET("/v1/feature-access", {
85
+ params: { query: { customerId }, header }
86
+ });
87
+ if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
88
+ return data;
89
+ },
90
+ async trackUsage(input) {
91
+ const { data, error, response } = await client.POST("/v1/usage", { params: { header }, body: input });
92
+ if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
93
+ return data;
94
+ }
95
+ };
96
+ }
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ PriceOSError,
100
+ createHttpClient
101
+ });
102
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export { createHttpClient, PriceOSError } from \"./client\";\nexport type {\n PriceOSOptions,\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 PriceOSOptions = {\n baseUrl?: string;\n apiKey: string;\n fetch?: typeof fetch;\n userAgent?: string;\n};\n\n\n\n// --- Public SDK surface type ---\nexport type PriceOSHttpClient = {\n raw: Client<paths>;\n getCustomer(customerId: string): Promise<GetCustomerResponse | null>;\n identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse | null>;\n upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse>;\n getFeatureAccess(customerId: string): Promise<GetFeatureAccessResponse>;\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 function createHttpClient(opts: PriceOSOptions): PriceOSHttpClient {\n const baseUrl = opts.baseUrl ?? \"https://api.priceos.com\";\n const header = { \"x-api-key\": opts.apiKey };\n\n const client = createClient<paths>({\n baseUrl,\n fetch: opts.fetch,\n headers: {\n \"x-api-key\": opts.apiKey,\n ...(opts.userAgent ? { \"user-agent\": opts.userAgent } : {}),\n },\n });\n\n return {\n raw: client,\n\n async getCustomer(customerId) {\n const { data, error, response } = await client.GET(\"/v1/customer\", {\n params: { query: { customerId }, header },\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data ?? null;\n },\n\n async identifyCustomer(input) {\n const { data, error, response } = await client.POST(\"/v1/customer/identify\", {\n params: { header },\n body: input,\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data ?? null;\n },\n\n async upsertCustomer(input) {\n const { data, error, response } = await client.PUT(\"/v1/customer\", { params: { header }, body: input });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data!;\n },\n\n async getFeatureAccess(customerId) {\n const { data, error, response } = await client.GET(\"/v1/feature-access\", {\n params: { query: { customerId }, header },\n });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data!;\n },\n\n async trackUsage(input) {\n const { data, error, response } = await client.POST(\"/v1/usage\", { params: { header }, body: input });\n if (error) throw new PriceOSError(error.error ?? \"Request failed\", { status: response?.status, details: error });\n return data!;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAAyB;AAkClB,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,SAAS,iBAAiB,MAAyC;AACxE,QAAM,UAAU,KAAK,WAAW;AAChC,QAAM,SAAS,EAAE,aAAa,KAAK,OAAO;AAE1C,QAAM,aAAS,qBAAAA,SAAoB;AAAA,I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