priceos 0.0.4 → 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/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -123
- package/dist/index.d.ts +17 -123
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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<TFeatureAccessMap = GetFeatureAccessResponse> = {\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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AAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QAAQ,SAAS,MAAM,CAAC;AAC/G,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,iBAAiB,YAAoB;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":["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"];
|
|
@@ -1117,9 +1125,9 @@ type PriceOSClientOptions = {
|
|
|
1117
1125
|
userAgent?: string;
|
|
1118
1126
|
};
|
|
1119
1127
|
type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
|
|
1120
|
-
getCustomer(customerId: string): Promise<GetCustomerResponse | null>;
|
|
1121
|
-
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse | null>;
|
|
1122
|
-
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse
|
|
1128
|
+
getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
|
|
1129
|
+
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
|
|
1130
|
+
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
|
|
1123
1131
|
getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
|
|
1124
1132
|
trackUsage(input: TrackUsageBody): Promise<TrackUsageResponse>;
|
|
1125
1133
|
};
|
|
@@ -1135,123 +1143,9 @@ declare class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse> implements P
|
|
|
1135
1143
|
private client;
|
|
1136
1144
|
private header;
|
|
1137
1145
|
constructor(apiKey: string, opts?: PriceOSClientOptions);
|
|
1138
|
-
getCustomer(customerId: string): Promise<
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
name?: string;
|
|
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
|
-
}>;
|
|
1146
|
+
getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
|
|
1147
|
+
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
|
|
1148
|
+
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
|
|
1255
1149
|
getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
|
|
1256
1150
|
trackUsage(input: TrackUsageBody): Promise<{
|
|
1257
1151
|
applied: boolean;
|
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"];
|
|
@@ -1117,9 +1125,9 @@ type PriceOSClientOptions = {
|
|
|
1117
1125
|
userAgent?: string;
|
|
1118
1126
|
};
|
|
1119
1127
|
type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
|
|
1120
|
-
getCustomer(customerId: string): Promise<GetCustomerResponse | null>;
|
|
1121
|
-
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse | null>;
|
|
1122
|
-
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse
|
|
1128
|
+
getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
|
|
1129
|
+
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
|
|
1130
|
+
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
|
|
1123
1131
|
getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
|
|
1124
1132
|
trackUsage(input: TrackUsageBody): Promise<TrackUsageResponse>;
|
|
1125
1133
|
};
|
|
@@ -1135,123 +1143,9 @@ declare class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse> implements P
|
|
|
1135
1143
|
private client;
|
|
1136
1144
|
private header;
|
|
1137
1145
|
constructor(apiKey: string, opts?: PriceOSClientOptions);
|
|
1138
|
-
getCustomer(customerId: string): Promise<
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
name?: string;
|
|
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
|
-
}>;
|
|
1146
|
+
getCustomer(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;
|
|
1147
|
+
identifyCustomer(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;
|
|
1148
|
+
upsertCustomer(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;
|
|
1255
1149
|
getFeatureAccess(customerId: string): Promise<TFeatureAccessMap>;
|
|
1256
1150
|
trackUsage(input: TrackUsageBody): Promise<{
|
|
1257
1151
|
applied: boolean;
|
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 | 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;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,SAAS,aAAoB;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,UAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,KAAK,OAAO,IAAI,gBAAgB;AAAA,MACtE,QAAQ,EAAE,OAAO,EAAE,WAAW,GAAG,QAAQ,KAAK,OAAO;AAAA,IACvD,CAAC;AACD,QAAI,MAAO,OAAM,IAAI,aAAa,MAAM,SAAS,kBAAkB,EAAE,QAAQ,UAAU,QA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