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 +135 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +112 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +102 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1140 -0
- package/dist/index.d.ts +1140 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import createClient from "openapi-fetch";
|
|
3
|
+
var PriceOSError = class extends Error {
|
|
4
|
+
status;
|
|
5
|
+
details;
|
|
6
|
+
constructor(message, opts) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "PriceOSError";
|
|
9
|
+
this.status = opts?.status;
|
|
10
|
+
this.details = opts?.details;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
function createHttpClient(opts) {
|
|
14
|
+
const baseUrl = opts.baseUrl ?? "https://api.priceos.com";
|
|
15
|
+
const header = { "x-api-key": opts.apiKey };
|
|
16
|
+
const client = createClient({
|
|
17
|
+
baseUrl,
|
|
18
|
+
fetch: opts.fetch,
|
|
19
|
+
headers: {
|
|
20
|
+
"x-api-key": opts.apiKey,
|
|
21
|
+
...opts.userAgent ? { "user-agent": opts.userAgent } : {}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
raw: client,
|
|
26
|
+
async getCustomer(customerId) {
|
|
27
|
+
const { data, error, response } = await client.GET("/v1/customer", {
|
|
28
|
+
params: { query: { customerId }, header }
|
|
29
|
+
});
|
|
30
|
+
if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
|
|
31
|
+
return data ?? null;
|
|
32
|
+
},
|
|
33
|
+
async identifyCustomer(input) {
|
|
34
|
+
const { data, error, response } = await client.POST("/v1/customer/identify", {
|
|
35
|
+
params: { header },
|
|
36
|
+
body: input
|
|
37
|
+
});
|
|
38
|
+
if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
|
|
39
|
+
return data ?? null;
|
|
40
|
+
},
|
|
41
|
+
async upsertCustomer(input) {
|
|
42
|
+
const { data, error, response } = await client.PUT("/v1/customer", { params: { header }, body: input });
|
|
43
|
+
if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
|
|
44
|
+
return data;
|
|
45
|
+
},
|
|
46
|
+
async getFeatureAccess(customerId) {
|
|
47
|
+
const { data, error, response } = await client.GET("/v1/feature-access", {
|
|
48
|
+
params: { query: { customerId }, header }
|
|
49
|
+
});
|
|
50
|
+
if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
|
|
51
|
+
return data;
|
|
52
|
+
},
|
|
53
|
+
async trackUsage(input) {
|
|
54
|
+
const { data, error, response } = await client.POST("/v1/usage", { params: { header }, body: input });
|
|
55
|
+
if (error) throw new PriceOSError(error.error ?? "Request failed", { status: response?.status, details: error });
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
PriceOSError,
|
|
62
|
+
createHttpClient
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 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,OAAO,kBAAkB;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,SAAS,aAAoB;AAAA,IACjC;AAAA,IACA,OAAO,KAAK;AAAA,IACZ,SAAS;AAAA,MACP,aAAa,KAAK;AAAA,MAClB,GAAI,KAAK,YAAY,EAAE,cAAc,KAAK,UAAU,IAAI,CAAC;AAAA,IAC3D;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,KAAK;AAAA,IAEL,MAAM,YAAY,YAAY;AAC5B,YAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,OAAO,IAAI,gBAAgB;AAAA,QACjE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO;AAAA,MAC1C,CAAC;AACD,UAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,aAAO,QAAQ;AAAA,IACjB;AAAA,IAEA,MAAM,iBAAiB,OAAO;AAC5B,YAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,OAAO,KAAK,yBAAyB;AAAA,QAC3E,QAAQ,EAAE,OAAO;AAAA,QACjB,MAAM;AAAA,MACR,CAAC;AACD,UAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,aAAO,QAAQ;AAAA,IACjB;AAAA,IAEA,MAAM,eAAe,OAAO;AAC1B,YAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,OAAO,IAAI,gBAAgB,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,MAAM,CAAC;AACtG,UAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,aAAO;AAAA,IACT;AAAA,IAEA,MAAM,iBAAiB,YAAY;AACjC,YAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,OAAO,IAAI,sBAAsB;AAAA,QACvE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO;AAAA,MAC1C,CAAC;AACD,UAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,aAAO;AAAA,IACT;AAAA,IAEA,MAAM,WAAW,OAAO;AACtB,YAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,OAAO,KAAK,aAAa,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,MAAM,CAAC;AACpG,UAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "priceos",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
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",
|
|
22
|
+
"build": "pnpm gen:types && tsup",
|
|
23
|
+
"dev": "pnpm gen:types && tsup src/index.ts --format esm,cjs --dts --watch",
|
|
24
|
+
"lint": "eslint .",
|
|
25
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"openapi-fetch": "^0.15.0"
|
|
29
|
+
},
|
|
30
|
+
"bin": {
|
|
31
|
+
"priceos": "./dist/cli.cjs"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^25.0.10",
|
|
35
|
+
"openapi-typescript": "^7.10.1",
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"tsx": "^4.21.0",
|
|
38
|
+
"typescript": "^5.0.0"
|
|
39
|
+
}
|
|
40
|
+
}
|