priceos 0.0.3 → 0.0.5
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 +3 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -138
- package/dist/index.d.ts +21 -138
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -46,12 +46,12 @@ Generates TypeScript feature access types for your PriceOS workspace.
|
|
|
46
46
|
Options:
|
|
47
47
|
--base-url <url> PriceOS API base URL (defaults to env PRICEOS_BASE_URL or https://api.priceos.com)
|
|
48
48
|
--api-key <key> PriceOS API key (defaults to env PRICEOS_API_KEY) [required]
|
|
49
|
-
--out <path> Output .d.ts file (default:
|
|
49
|
+
--out <path> Output .d.ts file (default: priceos.d.ts in current directory)
|
|
50
50
|
-h, --help Show help
|
|
51
51
|
|
|
52
52
|
Examples:
|
|
53
53
|
priceos sync --api-key sk_test_... --base-url http://localhost:3000
|
|
54
|
-
priceos sync --api-key sk_test_... --out
|
|
54
|
+
priceos sync --api-key sk_test_... --out ./priceos.d.ts
|
|
55
55
|
`.trim());
|
|
56
56
|
}
|
|
57
57
|
async function main() {
|
|
@@ -72,7 +72,7 @@ async function main() {
|
|
|
72
72
|
console.error("Missing API key. Provide --api-key <key> or set PRICEOS_API_KEY.");
|
|
73
73
|
process.exit(1);
|
|
74
74
|
}
|
|
75
|
-
const outRel = argValue(args, "--out") ?? "
|
|
75
|
+
const outRel = argValue(args, "--out") ?? "priceos.d.ts";
|
|
76
76
|
const outPath = import_node_path.default.resolve(process.cwd(), outRel);
|
|
77
77
|
const url = `${normalizeBaseUrl(baseUrl)}/v1/features`;
|
|
78
78
|
const res = await fetch(url, {
|
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\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:
|
|
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: priceos.d.ts in current directory)\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 ./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\") ?? \"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;AAAA;AAAA;AAAA;AAAA;AAAA,EAcZ,KAAK,CAAC;AACR;AAEA,eAAe,OAAO;AACpB,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,MAAI,KAAK,WAAW,KAAK,QAAQ,MAAM,QAAQ,KAAK,QAAQ,MAAM,IAAI,GAAG;AACvE,cAAU;AACV,YAAQ,KAAK,KAAK,WAAW,IAAI,IAAI,CAAC;AAAA,EACxC;AAEA,QAAM,MAAM,KAAK,CAAC;AAClB,MAAI,QAAQ,QAAQ;AAClB,YAAQ,MAAM,oBAAoB,GAAG,EAAE;AACvC,cAAU;AACV,YAAQ,KAAK,CAAC;AAAA,EAChB;AA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AK,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,gBAAAC,QAAG,MAAM,iBAAAD,QAAK,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,QAAM,gBAAAC,QAAG,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":["path","fs"]}
|
package/dist/cli.js
CHANGED
|
@@ -23,12 +23,12 @@ Generates TypeScript feature access types for your PriceOS workspace.
|
|
|
23
23
|
Options:
|
|
24
24
|
--base-url <url> PriceOS API base URL (defaults to env PRICEOS_BASE_URL or https://api.priceos.com)
|
|
25
25
|
--api-key <key> PriceOS API key (defaults to env PRICEOS_API_KEY) [required]
|
|
26
|
-
--out <path> Output .d.ts file (default:
|
|
26
|
+
--out <path> Output .d.ts file (default: priceos.d.ts in current directory)
|
|
27
27
|
-h, --help Show help
|
|
28
28
|
|
|
29
29
|
Examples:
|
|
30
30
|
priceos sync --api-key sk_test_... --base-url http://localhost:3000
|
|
31
|
-
priceos sync --api-key sk_test_... --out
|
|
31
|
+
priceos sync --api-key sk_test_... --out ./priceos.d.ts
|
|
32
32
|
`.trim());
|
|
33
33
|
}
|
|
34
34
|
async function main() {
|
|
@@ -49,7 +49,7 @@ async function main() {
|
|
|
49
49
|
console.error("Missing API key. Provide --api-key <key> or set PRICEOS_API_KEY.");
|
|
50
50
|
process.exit(1);
|
|
51
51
|
}
|
|
52
|
-
const outRel = argValue(args, "--out") ?? "
|
|
52
|
+
const outRel = argValue(args, "--out") ?? "priceos.d.ts";
|
|
53
53
|
const outPath = path.resolve(process.cwd(), outRel);
|
|
54
54
|
const url = `${normalizeBaseUrl(baseUrl)}/v1/features`;
|
|
55
55
|
const res = await fetch(url, {
|
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\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:
|
|
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: priceos.d.ts in current directory)\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 ./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\") ?? \"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,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;AAAA;AAAA;AAAA;AAAA;AAAA,EA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Aa,QAAQ,SAAS,UAAU,QAAQ,OAAO;AACzF,UAAM,cAAc,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,GAAG,MAAM,KAAK,QAAQ,OAAO,GAAG,EAAE,WAAW,KAAK,CAAC;AACzD,QAAM,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.map
CHANGED
|
@@ -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 = {\n getCustomer(customerId: string): Promise<GetCustomerResponse | null>;\n identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse | null>;\n upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse
|
|
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 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;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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":["createClient"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1102,11 +1102,19 @@ interface paths {
|
|
|
1102
1102
|
};
|
|
1103
1103
|
}
|
|
1104
1104
|
|
|
1105
|
-
type
|
|
1105
|
+
type WithFeatureAccess<T, TFeatureAccessMap> = T extends {
|
|
1106
|
+
featureAccess: unknown;
|
|
1107
|
+
} ? Omit<T, "featureAccess"> & {
|
|
1108
|
+
featureAccess: TFeatureAccessMap;
|
|
1109
|
+
} : T;
|
|
1110
|
+
type GetCustomerResponseBase = paths["/v1/customer"]["get"]["responses"][200]["content"]["application/json"];
|
|
1111
|
+
type GetCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<GetCustomerResponseBase, TFeatureAccessMap>;
|
|
1106
1112
|
type UpdateCustomerBody = paths["/v1/customer"]["put"]["requestBody"]["content"]["application/json"];
|
|
1107
|
-
type
|
|
1113
|
+
type UpdateCustomerResponseBase = paths["/v1/customer"]["put"]["responses"][200]["content"]["application/json"];
|
|
1114
|
+
type UpdateCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<UpdateCustomerResponseBase, TFeatureAccessMap>;
|
|
1108
1115
|
type IdentifyCustomerBody = paths["/v1/customer/identify"]["post"]["requestBody"]["content"]["application/json"];
|
|
1109
|
-
type
|
|
1116
|
+
type IdentifyCustomerResponseBase = paths["/v1/customer/identify"]["post"]["responses"][200]["content"]["application/json"];
|
|
1117
|
+
type IdentifyCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<IdentifyCustomerResponseBase, TFeatureAccessMap>;
|
|
1110
1118
|
type GetFeatureAccessResponse = paths["/v1/feature-access"]["get"]["responses"][200]["content"]["application/json"];
|
|
1111
1119
|
type TrackUsageBody = paths["/v1/usage"]["post"]["requestBody"]["content"]["application/json"];
|
|
1112
1120
|
type TrackUsageResponse = paths["/v1/usage"]["post"]["responses"][200]["content"]["application/json"];
|
|
@@ -1116,11 +1124,11 @@ type PriceOSClientOptions = {
|
|
|
1116
1124
|
fetch?: typeof fetch;
|
|
1117
1125
|
userAgent?: string;
|
|
1118
1126
|
};
|
|
1119
|
-
type PriceOSHttpClient = {
|
|
1120
|
-
getCustomer(customerId: string): Promise<GetCustomerResponse | null>;
|
|
1121
|
-
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse | null>;
|
|
1122
|
-
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse
|
|
1123
|
-
getFeatureAccess(customerId: string): Promise<
|
|
1127
|
+
type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
|
|
1128
|
+
getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
|
|
1129
|
+
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
|
|
1130
|
+
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
|
|
1131
|
+
getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
|
|
1124
1132
|
trackUsage(input: TrackUsageBody): Promise<TrackUsageResponse>;
|
|
1125
1133
|
};
|
|
1126
1134
|
declare class PriceOSError extends Error {
|
|
@@ -1131,139 +1139,14 @@ declare class PriceOSError extends Error {
|
|
|
1131
1139
|
details?: unknown;
|
|
1132
1140
|
});
|
|
1133
1141
|
}
|
|
1134
|
-
declare class PriceOS implements PriceOSHttpClient {
|
|
1142
|
+
declare class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse> implements PriceOSHttpClient<TFeatureAccessMap> {
|
|
1135
1143
|
private client;
|
|
1136
1144
|
private header;
|
|
1137
1145
|
constructor(apiKey: string, opts?: PriceOSClientOptions);
|
|
1138
|
-
getCustomer(customerId: string): Promise<
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
email?: string;
|
|
1143
|
-
enviroment: "test" | "live";
|
|
1144
|
-
products: {
|
|
1145
|
-
id: string;
|
|
1146
|
-
name: string;
|
|
1147
|
-
version: number;
|
|
1148
|
-
status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
|
|
1149
|
-
canceledAt?: number | null;
|
|
1150
|
-
startedAt?: number;
|
|
1151
|
-
currentPeriodStart?: number;
|
|
1152
|
-
currentPeriodEnd?: number;
|
|
1153
|
-
prices?: {
|
|
1154
|
-
stripePriceId: string;
|
|
1155
|
-
quantity: number;
|
|
1156
|
-
currency: string;
|
|
1157
|
-
unitAmount: number;
|
|
1158
|
-
recurringInterval: string | null;
|
|
1159
|
-
isActive: boolean;
|
|
1160
|
-
isDefault: boolean;
|
|
1161
|
-
recurringIntervalCount: number;
|
|
1162
|
-
}[];
|
|
1163
|
-
}[];
|
|
1164
|
-
featureAccess: {
|
|
1165
|
-
[key: string]: {
|
|
1166
|
-
type: "boolean";
|
|
1167
|
-
hasAccess: boolean;
|
|
1168
|
-
} | {
|
|
1169
|
-
type: "limit";
|
|
1170
|
-
hasAccess: boolean;
|
|
1171
|
-
isUnlimited: boolean;
|
|
1172
|
-
limit: number | null;
|
|
1173
|
-
used: number;
|
|
1174
|
-
};
|
|
1175
|
-
};
|
|
1176
|
-
} | null>;
|
|
1177
|
-
identifyCustomer(input: IdentifyCustomerBody): Promise<{
|
|
1178
|
-
customerId?: string;
|
|
1179
|
-
stripeCustomerId?: string;
|
|
1180
|
-
name?: string;
|
|
1181
|
-
email?: string;
|
|
1182
|
-
enviroment: "test" | "live";
|
|
1183
|
-
products: {
|
|
1184
|
-
id: string;
|
|
1185
|
-
name: string;
|
|
1186
|
-
version: number;
|
|
1187
|
-
status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
|
|
1188
|
-
canceledAt?: number | null;
|
|
1189
|
-
startedAt?: number;
|
|
1190
|
-
currentPeriodStart?: number;
|
|
1191
|
-
currentPeriodEnd?: number;
|
|
1192
|
-
prices?: {
|
|
1193
|
-
stripePriceId: string;
|
|
1194
|
-
quantity: number;
|
|
1195
|
-
currency: string;
|
|
1196
|
-
unitAmount: number;
|
|
1197
|
-
recurringInterval: string | null;
|
|
1198
|
-
isActive: boolean;
|
|
1199
|
-
isDefault: boolean;
|
|
1200
|
-
recurringIntervalCount: number;
|
|
1201
|
-
}[];
|
|
1202
|
-
}[];
|
|
1203
|
-
featureAccess: {
|
|
1204
|
-
[key: string]: {
|
|
1205
|
-
type: "boolean";
|
|
1206
|
-
hasAccess: boolean;
|
|
1207
|
-
} | {
|
|
1208
|
-
type: "limit";
|
|
1209
|
-
hasAccess: boolean;
|
|
1210
|
-
isUnlimited: boolean;
|
|
1211
|
-
limit: number | null;
|
|
1212
|
-
used: number;
|
|
1213
|
-
};
|
|
1214
|
-
};
|
|
1215
|
-
}>;
|
|
1216
|
-
upsertCustomer(input: UpdateCustomerBody): Promise<{
|
|
1217
|
-
customerId?: string;
|
|
1218
|
-
stripeCustomerId?: string;
|
|
1219
|
-
name?: string;
|
|
1220
|
-
email?: string;
|
|
1221
|
-
enviroment: "test" | "live";
|
|
1222
|
-
products: {
|
|
1223
|
-
id: string;
|
|
1224
|
-
name: string;
|
|
1225
|
-
version: number;
|
|
1226
|
-
status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
|
|
1227
|
-
canceledAt?: number | null;
|
|
1228
|
-
startedAt?: number;
|
|
1229
|
-
currentPeriodStart?: number;
|
|
1230
|
-
currentPeriodEnd?: number;
|
|
1231
|
-
prices?: {
|
|
1232
|
-
stripePriceId: string;
|
|
1233
|
-
quantity: number;
|
|
1234
|
-
currency: string;
|
|
1235
|
-
unitAmount: number;
|
|
1236
|
-
recurringInterval: string | null;
|
|
1237
|
-
isActive: boolean;
|
|
1238
|
-
isDefault: boolean;
|
|
1239
|
-
recurringIntervalCount: number;
|
|
1240
|
-
}[];
|
|
1241
|
-
}[];
|
|
1242
|
-
featureAccess: {
|
|
1243
|
-
[key: string]: {
|
|
1244
|
-
type: "boolean";
|
|
1245
|
-
hasAccess: boolean;
|
|
1246
|
-
} | {
|
|
1247
|
-
type: "limit";
|
|
1248
|
-
hasAccess: boolean;
|
|
1249
|
-
isUnlimited: boolean;
|
|
1250
|
-
limit: number | null;
|
|
1251
|
-
used: number;
|
|
1252
|
-
};
|
|
1253
|
-
};
|
|
1254
|
-
}>;
|
|
1255
|
-
getFeatureAccess(customerId: string): Promise<{
|
|
1256
|
-
[key: string]: {
|
|
1257
|
-
type: "boolean";
|
|
1258
|
-
hasAccess: boolean;
|
|
1259
|
-
} | {
|
|
1260
|
-
type: "limit";
|
|
1261
|
-
hasAccess: boolean;
|
|
1262
|
-
isUnlimited: boolean;
|
|
1263
|
-
limit: number | null;
|
|
1264
|
-
used: number;
|
|
1265
|
-
};
|
|
1266
|
-
}>;
|
|
1146
|
+
getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
|
|
1147
|
+
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
|
|
1148
|
+
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
|
|
1149
|
+
getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
|
|
1267
1150
|
trackUsage(input: TrackUsageBody): Promise<{
|
|
1268
1151
|
applied: boolean;
|
|
1269
1152
|
used: number | null;
|
package/dist/index.d.ts
CHANGED
|
@@ -1102,11 +1102,19 @@ interface paths {
|
|
|
1102
1102
|
};
|
|
1103
1103
|
}
|
|
1104
1104
|
|
|
1105
|
-
type
|
|
1105
|
+
type WithFeatureAccess<T, TFeatureAccessMap> = T extends {
|
|
1106
|
+
featureAccess: unknown;
|
|
1107
|
+
} ? Omit<T, "featureAccess"> & {
|
|
1108
|
+
featureAccess: TFeatureAccessMap;
|
|
1109
|
+
} : T;
|
|
1110
|
+
type GetCustomerResponseBase = paths["/v1/customer"]["get"]["responses"][200]["content"]["application/json"];
|
|
1111
|
+
type GetCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<GetCustomerResponseBase, TFeatureAccessMap>;
|
|
1106
1112
|
type UpdateCustomerBody = paths["/v1/customer"]["put"]["requestBody"]["content"]["application/json"];
|
|
1107
|
-
type
|
|
1113
|
+
type UpdateCustomerResponseBase = paths["/v1/customer"]["put"]["responses"][200]["content"]["application/json"];
|
|
1114
|
+
type UpdateCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<UpdateCustomerResponseBase, TFeatureAccessMap>;
|
|
1108
1115
|
type IdentifyCustomerBody = paths["/v1/customer/identify"]["post"]["requestBody"]["content"]["application/json"];
|
|
1109
|
-
type
|
|
1116
|
+
type IdentifyCustomerResponseBase = paths["/v1/customer/identify"]["post"]["responses"][200]["content"]["application/json"];
|
|
1117
|
+
type IdentifyCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<IdentifyCustomerResponseBase, TFeatureAccessMap>;
|
|
1110
1118
|
type GetFeatureAccessResponse = paths["/v1/feature-access"]["get"]["responses"][200]["content"]["application/json"];
|
|
1111
1119
|
type TrackUsageBody = paths["/v1/usage"]["post"]["requestBody"]["content"]["application/json"];
|
|
1112
1120
|
type TrackUsageResponse = paths["/v1/usage"]["post"]["responses"][200]["content"]["application/json"];
|
|
@@ -1116,11 +1124,11 @@ type PriceOSClientOptions = {
|
|
|
1116
1124
|
fetch?: typeof fetch;
|
|
1117
1125
|
userAgent?: string;
|
|
1118
1126
|
};
|
|
1119
|
-
type PriceOSHttpClient = {
|
|
1120
|
-
getCustomer(customerId: string): Promise<GetCustomerResponse | null>;
|
|
1121
|
-
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse | null>;
|
|
1122
|
-
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse
|
|
1123
|
-
getFeatureAccess(customerId: string): Promise<
|
|
1127
|
+
type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
|
|
1128
|
+
getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
|
|
1129
|
+
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
|
|
1130
|
+
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
|
|
1131
|
+
getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
|
|
1124
1132
|
trackUsage(input: TrackUsageBody): Promise<TrackUsageResponse>;
|
|
1125
1133
|
};
|
|
1126
1134
|
declare class PriceOSError extends Error {
|
|
@@ -1131,139 +1139,14 @@ declare class PriceOSError extends Error {
|
|
|
1131
1139
|
details?: unknown;
|
|
1132
1140
|
});
|
|
1133
1141
|
}
|
|
1134
|
-
declare class PriceOS implements PriceOSHttpClient {
|
|
1142
|
+
declare class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse> implements PriceOSHttpClient<TFeatureAccessMap> {
|
|
1135
1143
|
private client;
|
|
1136
1144
|
private header;
|
|
1137
1145
|
constructor(apiKey: string, opts?: PriceOSClientOptions);
|
|
1138
|
-
getCustomer(customerId: string): Promise<
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
email?: string;
|
|
1143
|
-
enviroment: "test" | "live";
|
|
1144
|
-
products: {
|
|
1145
|
-
id: string;
|
|
1146
|
-
name: string;
|
|
1147
|
-
version: number;
|
|
1148
|
-
status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
|
|
1149
|
-
canceledAt?: number | null;
|
|
1150
|
-
startedAt?: number;
|
|
1151
|
-
currentPeriodStart?: number;
|
|
1152
|
-
currentPeriodEnd?: number;
|
|
1153
|
-
prices?: {
|
|
1154
|
-
stripePriceId: string;
|
|
1155
|
-
quantity: number;
|
|
1156
|
-
currency: string;
|
|
1157
|
-
unitAmount: number;
|
|
1158
|
-
recurringInterval: string | null;
|
|
1159
|
-
isActive: boolean;
|
|
1160
|
-
isDefault: boolean;
|
|
1161
|
-
recurringIntervalCount: number;
|
|
1162
|
-
}[];
|
|
1163
|
-
}[];
|
|
1164
|
-
featureAccess: {
|
|
1165
|
-
[key: string]: {
|
|
1166
|
-
type: "boolean";
|
|
1167
|
-
hasAccess: boolean;
|
|
1168
|
-
} | {
|
|
1169
|
-
type: "limit";
|
|
1170
|
-
hasAccess: boolean;
|
|
1171
|
-
isUnlimited: boolean;
|
|
1172
|
-
limit: number | null;
|
|
1173
|
-
used: number;
|
|
1174
|
-
};
|
|
1175
|
-
};
|
|
1176
|
-
} | null>;
|
|
1177
|
-
identifyCustomer(input: IdentifyCustomerBody): Promise<{
|
|
1178
|
-
customerId?: string;
|
|
1179
|
-
stripeCustomerId?: string;
|
|
1180
|
-
name?: string;
|
|
1181
|
-
email?: string;
|
|
1182
|
-
enviroment: "test" | "live";
|
|
1183
|
-
products: {
|
|
1184
|
-
id: string;
|
|
1185
|
-
name: string;
|
|
1186
|
-
version: number;
|
|
1187
|
-
status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
|
|
1188
|
-
canceledAt?: number | null;
|
|
1189
|
-
startedAt?: number;
|
|
1190
|
-
currentPeriodStart?: number;
|
|
1191
|
-
currentPeriodEnd?: number;
|
|
1192
|
-
prices?: {
|
|
1193
|
-
stripePriceId: string;
|
|
1194
|
-
quantity: number;
|
|
1195
|
-
currency: string;
|
|
1196
|
-
unitAmount: number;
|
|
1197
|
-
recurringInterval: string | null;
|
|
1198
|
-
isActive: boolean;
|
|
1199
|
-
isDefault: boolean;
|
|
1200
|
-
recurringIntervalCount: number;
|
|
1201
|
-
}[];
|
|
1202
|
-
}[];
|
|
1203
|
-
featureAccess: {
|
|
1204
|
-
[key: string]: {
|
|
1205
|
-
type: "boolean";
|
|
1206
|
-
hasAccess: boolean;
|
|
1207
|
-
} | {
|
|
1208
|
-
type: "limit";
|
|
1209
|
-
hasAccess: boolean;
|
|
1210
|
-
isUnlimited: boolean;
|
|
1211
|
-
limit: number | null;
|
|
1212
|
-
used: number;
|
|
1213
|
-
};
|
|
1214
|
-
};
|
|
1215
|
-
}>;
|
|
1216
|
-
upsertCustomer(input: UpdateCustomerBody): Promise<{
|
|
1217
|
-
customerId?: string;
|
|
1218
|
-
stripeCustomerId?: string;
|
|
1219
|
-
name?: string;
|
|
1220
|
-
email?: string;
|
|
1221
|
-
enviroment: "test" | "live";
|
|
1222
|
-
products: {
|
|
1223
|
-
id: string;
|
|
1224
|
-
name: string;
|
|
1225
|
-
version: number;
|
|
1226
|
-
status?: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "paused" | "unpaid" | "canceled";
|
|
1227
|
-
canceledAt?: number | null;
|
|
1228
|
-
startedAt?: number;
|
|
1229
|
-
currentPeriodStart?: number;
|
|
1230
|
-
currentPeriodEnd?: number;
|
|
1231
|
-
prices?: {
|
|
1232
|
-
stripePriceId: string;
|
|
1233
|
-
quantity: number;
|
|
1234
|
-
currency: string;
|
|
1235
|
-
unitAmount: number;
|
|
1236
|
-
recurringInterval: string | null;
|
|
1237
|
-
isActive: boolean;
|
|
1238
|
-
isDefault: boolean;
|
|
1239
|
-
recurringIntervalCount: number;
|
|
1240
|
-
}[];
|
|
1241
|
-
}[];
|
|
1242
|
-
featureAccess: {
|
|
1243
|
-
[key: string]: {
|
|
1244
|
-
type: "boolean";
|
|
1245
|
-
hasAccess: boolean;
|
|
1246
|
-
} | {
|
|
1247
|
-
type: "limit";
|
|
1248
|
-
hasAccess: boolean;
|
|
1249
|
-
isUnlimited: boolean;
|
|
1250
|
-
limit: number | null;
|
|
1251
|
-
used: number;
|
|
1252
|
-
};
|
|
1253
|
-
};
|
|
1254
|
-
}>;
|
|
1255
|
-
getFeatureAccess(customerId: string): Promise<{
|
|
1256
|
-
[key: string]: {
|
|
1257
|
-
type: "boolean";
|
|
1258
|
-
hasAccess: boolean;
|
|
1259
|
-
} | {
|
|
1260
|
-
type: "limit";
|
|
1261
|
-
hasAccess: boolean;
|
|
1262
|
-
isUnlimited: boolean;
|
|
1263
|
-
limit: number | null;
|
|
1264
|
-
used: number;
|
|
1265
|
-
};
|
|
1266
|
-
}>;
|
|
1146
|
+
getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
|
|
1147
|
+
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
|
|
1148
|
+
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
|
|
1149
|
+
getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
|
|
1267
1150
|
trackUsage(input: TrackUsageBody): Promise<{
|
|
1268
1151
|
applied: boolean;
|
|
1269
1152
|
used: number | null;
|
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 = {\n getCustomer(customerId: string): Promise<GetCustomerResponse | null>;\n identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse | null>;\n upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse
|
|
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 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;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