priceos 0.0.36 → 0.0.38

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 CHANGED
@@ -226,6 +226,7 @@ var PriceOS = class {
226
226
  log;
227
227
  customers;
228
228
  features;
229
+ bonuses;
229
230
  usage;
230
231
  constructor(apiKey, opts = {}) {
231
232
  const logLevel = opts.logLevel ?? "none";
@@ -242,41 +243,42 @@ var PriceOS = class {
242
243
  });
243
244
  this.customers = {
244
245
  get: async (customerId) => {
245
- const { data, error, response } = await this.client.GET("/v1/customer", {
246
- params: { query: { customerId }, header: this.header }
246
+ const { data, error, response } = await this.client.GET("/v1/customers/{customerId}", {
247
+ params: { path: { customerId }, header: this.header }
247
248
  });
248
- if (error) throwRequestError(this.log, error, response, "GET /v1/customer");
249
+ if (error) throwRequestError(this.log, error, response, "GET /v1/customers/{customerId}");
249
250
  return data ?? null;
250
251
  },
251
252
  identify: async (input) => {
252
- const { data, error, response } = await this.client.POST("/v1/customer/identify", {
253
+ const { data, error, response } = await this.client.POST("/v1/customers/identify", {
253
254
  params: { header: this.header },
254
255
  body: input
255
256
  });
256
- if (error) throwRequestError(this.log, error, response, "POST /v1/customer/identify");
257
+ if (error) throwRequestError(this.log, error, response, "POST /v1/customers/identify");
257
258
  return data ?? null;
258
259
  },
259
260
  create: async (input) => {
260
- const { data, error, response } = await this.client.POST("/v1/customer", {
261
+ const { data, error, response } = await this.client.POST("/v1/customers", {
261
262
  params: { header: this.header },
262
263
  body: input
263
264
  });
264
- if (error) throwRequestError(this.log, error, response, "POST /v1/customer");
265
+ if (error) throwRequestError(this.log, error, response, "POST /v1/customers");
265
266
  return data;
266
267
  },
267
268
  update: async (input) => {
268
- const { data, error, response } = await this.client.PUT("/v1/customer", {
269
- params: { header: this.header },
270
- body: input
269
+ const { customerId, ...body } = input;
270
+ const { data, error, response } = await this.client.PUT("/v1/customers/{customerId}", {
271
+ params: { path: { customerId }, header: this.header },
272
+ body
271
273
  });
272
- if (error) throwRequestError(this.log, error, response, "PUT /v1/customer");
274
+ if (error) throwRequestError(this.log, error, response, "PUT /v1/customers/{customerId}");
273
275
  return data;
274
276
  },
275
277
  delete: async (customerId) => {
276
- const { data, error, response } = await this.client.DELETE("/v1/customer", {
277
- params: { query: { customerId }, header: this.header }
278
+ const { data, error, response } = await this.client.DELETE("/v1/customers/{customerId}", {
279
+ params: { path: { customerId }, header: this.header }
278
280
  });
279
- if (error) throwRequestError(this.log, error, response, "DELETE /v1/customer");
281
+ if (error) throwRequestError(this.log, error, response, "DELETE /v1/customers/{customerId}");
280
282
  return data;
281
283
  }
282
284
  };
@@ -289,6 +291,16 @@ var PriceOS = class {
289
291
  return data;
290
292
  }
291
293
  };
294
+ this.bonuses = {
295
+ grant: async (input) => {
296
+ const { data, error, response } = await this.client.POST("/v1/bonuses", {
297
+ params: { header: this.header },
298
+ body: input
299
+ });
300
+ if (error) throwRequestError(this.log, error, response, "POST /v1/bonuses");
301
+ return data;
302
+ }
303
+ };
292
304
  this.usage = {
293
305
  track: async (input) => {
294
306
  const { data, error, response } = await this.client.POST("/v1/usage", {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export { PriceOS, PriceOSError } from \"./client\";\nexport type {\n PriceOSClientOptions,\n PriceOSLogLevel,\n PriceOSCustomersClient,\n PriceOSFeaturesClient,\n PriceOSHttpClient,\n PriceOSUsageClient,\n} from \"./client\";\nexport type {\n CreateCustomerRequest,\n CreateCustomerResponse,\n DeleteUsageEventsBody,\n DeleteUsageEventsResponse,\n DeleteCustomerRequest,\n DeleteCustomerResponse,\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n LimitFeatureKeyFromAccessMap,\n ListUsageEventsBody,\n ListUsageEventsResponse,\n ResetUsageBody,\n ResetUsageResponse,\n UsageEvent,\n TrackUsageBody,\n TrackUsageBatchBody,\n TrackUsageBatchEvent,\n TrackUsageBatchResponse,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n","import createClient from \"openapi-fetch\";\nimport type { Client } from \"openapi-fetch\";\nimport type { paths } from \"./gen/openapi\";\nimport {\n CreateCustomerRequest,\n CreateCustomerResponse,\n DeleteUsageEventsBody,\n DeleteUsageEventsResponse,\n DeleteCustomerResponse,\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n LimitFeatureKeyFromAccessMap,\n ListUsageEventsBody,\n ListUsageEventsResponse,\n ResetUsageBody,\n ResetUsageResponse,\n TrackUsageBody,\n TrackUsageBatchBody,\n TrackUsageBatchResponse,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n\nexport type PriceOSLogLevel = \"none\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n\n// --- Public options ---\nexport type PriceOSClientOptions = {\n logLevel?: PriceOSLogLevel;\n};\n\nconst RATE_LIMIT_STATUS = 429;\nconst MAX_RETRIES = 4;\nconst BASE_DELAY_MS = 250;\nconst BACKOFF_MULTIPLIER = 2;\nconst JITTER_MS = 250;\nconst RETRY_DELAY_CAP_MS = 5_000;\nconst REQUEST_TIMEOUT_MS = 20_000;\n\nconst LOG_LEVELS: Record<PriceOSLogLevel, number> = {\n none: 0,\n error: 1,\n warning: 2,\n info: 3,\n debug: 4,\n};\n\ntype Logger = {\n error: (message: string, details?: Record<string, unknown>) => void;\n warning: (message: string, details?: Record<string, unknown>) => void;\n info: (message: string, details?: Record<string, unknown>) => void;\n debug: (message: string, details?: Record<string, unknown>) => void;\n};\n\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\nconst getRetryDelayMs = (retryCount: number): number => {\n const backoff = BASE_DELAY_MS * Math.pow(BACKOFF_MULTIPLIER, retryCount - 1);\n const jitter = Math.random() * JITTER_MS;\n return Math.min(RETRY_DELAY_CAP_MS, backoff + jitter);\n};\n\nconst createLogger = (logLevel: PriceOSLogLevel): Logger => {\n const shouldLog = (level: PriceOSLogLevel): boolean =>\n logLevel !== \"none\" && LOG_LEVELS[level] <= LOG_LEVELS[logLevel];\n\n const write = (\n level: PriceOSLogLevel,\n message: string,\n details?: Record<string, unknown>\n ): void => {\n if (!shouldLog(level)) return;\n const prefix = `[PriceOS] ${level.toUpperCase()}: ${message}`;\n const payload = details && Object.keys(details).length > 0 ? details : undefined;\n\n switch (level) {\n case \"error\":\n payload ? console.error(prefix, payload) : console.error(prefix);\n return;\n case \"warning\":\n payload ? console.warn(prefix, payload) : console.warn(prefix);\n return;\n case \"info\":\n payload ? console.info(prefix, payload) : console.info(prefix);\n return;\n case \"debug\":\n payload ? console.debug(prefix, payload) : console.debug(prefix);\n return;\n }\n };\n\n return {\n error: (message, details) => write(\"error\", message, details),\n warning: (message, details) => write(\"warning\", message, details),\n info: (message, details) => write(\"info\", message, details),\n debug: (message, details) => write(\"debug\", message, details),\n };\n};\n\nconst getUpstreamSignal = (input: RequestInfo | URL, init?: RequestInit): AbortSignal | undefined => {\n if (init?.signal) return init.signal;\n if (typeof Request !== \"undefined\" && input instanceof Request) return input.signal;\n return undefined;\n};\n\nconst stripSignal = (init?: RequestInit): RequestInit | undefined => {\n if (!init) return undefined;\n const { signal: _signal, ...rest } = init;\n return rest;\n};\n\nconst getRequestDetails = (\n input: RequestInfo | URL,\n init?: RequestInit\n): { method: string; url: string } => {\n const method =\n init?.method ??\n (typeof Request !== \"undefined\" && input instanceof Request ? input.method : \"GET\");\n const url =\n typeof input === \"string\"\n ? input\n : input instanceof URL\n ? input.toString()\n : input.url;\n return { method, url };\n};\n\nconst prepareRetryRequest = async (\n input: RequestInfo | URL,\n init: RequestInit | undefined,\n log: Logger,\n method: string,\n url: string\n): Promise<{ requestInput: RequestInfo | URL; baseInit?: RequestInit; canRetry: boolean }> => {\n if (!(typeof Request !== \"undefined\" && input instanceof Request)) {\n return { requestInput: input, baseInit: stripSignal(init), canRetry: true };\n }\n\n if (input.bodyUsed) {\n log.warning(\"Request body already used; retries disabled\", { method, url });\n return { requestInput: input, baseInit: stripSignal(init), canRetry: false };\n }\n\n let body: BodyInit | undefined = undefined;\n if (method !== \"GET\" && method !== \"HEAD\") {\n try {\n body = await input.clone().arrayBuffer();\n } catch (error) {\n log.warning(\"Unable to clone request body; retries disabled\", { method, url, error });\n return { requestInput: input, baseInit: stripSignal(init), canRetry: false };\n }\n }\n\n const headers = new Headers(input.headers);\n const baseInit = { ...stripSignal(init), method, headers, body };\n return { requestInput: input.url, baseInit, canRetry: true };\n};\n\nconst getErrorMessage = (error: unknown): string => {\n const maybeError = error as { error?: unknown } | null;\n if (maybeError && typeof maybeError.error === \"string\") return maybeError.error;\n return \"Request failed\";\n};\n\nconst throwRequestError = (\n log: Logger,\n error: unknown,\n response: Response | undefined,\n context: string\n): never => {\n log.error(\"Request failed\", { context, status: response?.status, error });\n throw new PriceOSError(getErrorMessage(error), { status: response?.status, details: error });\n};\n\nconst createRetryingFetch = (baseFetch: typeof fetch, log: Logger): typeof fetch => {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const { method, url } = getRequestDetails(input, init);\n const upstreamSignal = getUpstreamSignal(input, init);\n const { requestInput, baseInit, canRetry } = await prepareRetryRequest(\n input,\n init,\n log,\n method,\n url\n );\n let attempt = 0;\n while (true) {\n log.debug(\"Request attempt\", { method, url, attempt: attempt + 1, maxRetries: MAX_RETRIES });\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);\n let removeAbortListener: (() => void) | null = null;\n\n if (upstreamSignal) {\n if (upstreamSignal.aborted) {\n controller.abort();\n } else {\n const onAbort = () => controller.abort();\n upstreamSignal.addEventListener(\"abort\", onAbort);\n removeAbortListener = () => upstreamSignal.removeEventListener(\"abort\", onAbort);\n }\n }\n\n try {\n const requestInit = { ...(baseInit ?? {}), signal: controller.signal };\n const response = await baseFetch(requestInput, requestInit);\n if (response.status !== RATE_LIMIT_STATUS) return response;\n\n const retryAfter = response.headers.get(\"retry-after\") ?? undefined;\n log.warning(\"Rate limit hit (429)\", {\n method,\n url,\n attempt: attempt + 1,\n maxRetries: MAX_RETRIES,\n retryAfter,\n });\n\n if (!canRetry) {\n log.warning(\"Skipping retry because request body is not replayable\", { method, url });\n return response;\n }\n\n if (attempt >= MAX_RETRIES) {\n log.error(\"Rate limit retries exhausted\", { method, url, attempts: attempt + 1 });\n return response;\n }\n\n const delayMs = getRetryDelayMs(attempt + 1);\n log.info(\"Waiting to retry after rate limit\", {\n method,\n url,\n delayMs,\n nextAttempt: attempt + 2,\n maxRetries: MAX_RETRIES,\n });\n await sleep(delayMs);\n attempt += 1;\n } catch (error) {\n if (controller.signal.aborted) {\n const abortedByCaller = upstreamSignal?.aborted ?? false;\n if (abortedByCaller) {\n log.warning(\"Request aborted by caller\", { method, url, attempt: attempt + 1 });\n } else {\n log.error(\"Request timed out\", {\n method,\n url,\n attempt: attempt + 1,\n timeoutMs: REQUEST_TIMEOUT_MS,\n });\n }\n } else {\n log.error(\"Request failed\", { method, url, attempt: attempt + 1, error });\n }\n throw error;\n } finally {\n clearTimeout(timeoutId);\n removeAbortListener?.();\n }\n }\n };\n};\n\nexport type PriceOSCustomersClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n get(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;\n identify(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;\n create(input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>>;\n update(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;\n delete(customerId: string): Promise<DeleteCustomerResponse>;\n};\n\nexport type PriceOSFeaturesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n getAccess(customerId: string): Promise<TFeatureAccessMap>;\n};\n\nexport type PriceOSUsageClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n track(\n input: TrackUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<TrackUsageResponse>;\n reset(\n input: ResetUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<ResetUsageResponse>;\n deleteEvents(\n input: DeleteUsageEventsBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<DeleteUsageEventsResponse>;\n trackBatch(\n input: TrackUsageBatchBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<TrackUsageBatchResponse>;\n listEvents(\n input: ListUsageEventsBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<ListUsageEventsResponse>;\n};\n\n// --- Public SDK surface type ---\nexport type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n customers: PriceOSCustomersClient<TFeatureAccessMap>;\n features: PriceOSFeaturesClient<TFeatureAccessMap>;\n usage: PriceOSUsageClient<TFeatureAccessMap>;\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 private log: Logger;\n customers: PriceOSCustomersClient<TFeatureAccessMap>;\n features: PriceOSFeaturesClient<TFeatureAccessMap>;\n usage: PriceOSUsageClient<TFeatureAccessMap>;\n\n constructor(apiKey: string, opts: PriceOSClientOptions = {}) {\n const logLevel = opts.logLevel ?? \"none\";\n this.log = createLogger(logLevel);\n const baseUrl = \"https://api.priceos.com\";\n this.header = { \"x-api-key\": apiKey };\n const fetchWithRetry = createRetryingFetch(fetch, this.log);\n this.client = createClient<paths>({\n baseUrl,\n fetch: fetchWithRetry,\n headers: {\n \"x-api-key\": apiKey,\n },\n });\n\n this.customers = {\n get: async (customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null> => {\n const { data, error, response } = await this.client.GET(\"/v1/customer\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error) throwRequestError(this.log, error, response, \"GET /v1/customer\");\n return (data ?? null) as GetCustomerResponse<TFeatureAccessMap> | null;\n },\n identify: async (\n input: IdentifyCustomerBody\n ): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null> => {\n const { data, error, response } = await this.client.POST(\"/v1/customer/identify\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/customer/identify\");\n return (data ?? null) as IdentifyCustomerResponse<TFeatureAccessMap> | null;\n },\n create: async (input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>> => {\n const { data, error, response } = await this.client.POST(\"/v1/customer\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/customer\");\n return data! as CreateCustomerResponse<TFeatureAccessMap>;\n },\n update: async (input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>> => {\n const { data, error, response } = await this.client.PUT(\"/v1/customer\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"PUT /v1/customer\");\n return data! as UpdateCustomerResponse<TFeatureAccessMap>;\n },\n delete: async (customerId: string): Promise<DeleteCustomerResponse> => {\n const { data, error, response } = await this.client.DELETE(\"/v1/customer\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error) throwRequestError(this.log, error, response, \"DELETE /v1/customer\");\n return data! as DeleteCustomerResponse;\n },\n };\n\n this.features = {\n getAccess: async (customerId: string): Promise<TFeatureAccessMap> => {\n const { data, error, response } = await this.client.GET(\"/v1/feature-access\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error) throwRequestError(this.log, error, response, \"GET /v1/feature-access\");\n return data! as TFeatureAccessMap;\n },\n };\n\n this.usage = {\n track: async (\n input: TrackUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<TrackUsageResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage\");\n return data!;\n },\n reset: async (\n input: ResetUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<ResetUsageResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage/void\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage/void\");\n return data!;\n },\n deleteEvents: async (\n input: DeleteUsageEventsBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<DeleteUsageEventsResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage/delete\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage/delete\");\n return data!;\n },\n trackBatch: async (\n input: TrackUsageBatchBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<TrackUsageBatchResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage/batch\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage/batch\");\n return data!;\n },\n listEvents: async (\n input: ListUsageEventsBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<ListUsageEventsResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage/events\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage/events\");\n return data!;\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAAyB;AAiCzB,IAAM,oBAAoB;AAC1B,IAAM,cAAc;AACpB,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAC3B,IAAM,YAAY;AAClB,IAAM,qBAAq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,UAAU,uBAAuB;AAC/E,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":["createClient"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts"],"sourcesContent":["export { PriceOS, PriceOSError } from \"./client\";\nexport type {\n PriceOSClientOptions,\n PriceOSLogLevel,\n PriceOSBonusesClient,\n PriceOSCustomersClient,\n PriceOSFeaturesClient,\n PriceOSHttpClient,\n PriceOSUsageClient,\n} from \"./client\";\nexport type {\n CreateCustomerRequest,\n CreateCustomerResponse,\n DeleteUsageEventsBody,\n DeleteUsageEventsResponse,\n DeleteCustomerRequest,\n DeleteCustomerResponse,\n GrantBonusBody,\n GrantBonusResponse,\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n LimitFeatureKeyFromAccessMap,\n ListUsageEventsBody,\n ListUsageEventsResponse,\n ResetUsageBody,\n ResetUsageResponse,\n UsageEvent,\n TrackUsageBody,\n TrackUsageBatchBody,\n TrackUsageBatchEvent,\n TrackUsageBatchResponse,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n","import createClient from \"openapi-fetch\";\nimport type { Client } from \"openapi-fetch\";\nimport type { paths } from \"./gen/openapi\";\nimport {\n CreateCustomerRequest,\n CreateCustomerResponse,\n DeleteUsageEventsBody,\n DeleteUsageEventsResponse,\n DeleteCustomerResponse,\n GrantBonusBody,\n GrantBonusResponse,\n GetCustomerResponse,\n GetFeatureAccessResponse,\n IdentifyCustomerBody,\n IdentifyCustomerResponse,\n LimitFeatureKeyFromAccessMap,\n ListUsageEventsBody,\n ListUsageEventsResponse,\n ResetUsageBody,\n ResetUsageResponse,\n TrackUsageBody,\n TrackUsageBatchBody,\n TrackUsageBatchResponse,\n TrackUsageResponse,\n UpdateCustomerBody,\n UpdateCustomerResponse,\n} from \"./types\";\n\nexport type PriceOSLogLevel = \"none\" | \"error\" | \"warning\" | \"info\" | \"debug\";\n\n// --- Public options ---\nexport type PriceOSClientOptions = {\n logLevel?: PriceOSLogLevel;\n};\n\nconst RATE_LIMIT_STATUS = 429;\nconst MAX_RETRIES = 4;\nconst BASE_DELAY_MS = 250;\nconst BACKOFF_MULTIPLIER = 2;\nconst JITTER_MS = 250;\nconst RETRY_DELAY_CAP_MS = 5_000;\nconst REQUEST_TIMEOUT_MS = 20_000;\n\nconst LOG_LEVELS: Record<PriceOSLogLevel, number> = {\n none: 0,\n error: 1,\n warning: 2,\n info: 3,\n debug: 4,\n};\n\ntype Logger = {\n error: (message: string, details?: Record<string, unknown>) => void;\n warning: (message: string, details?: Record<string, unknown>) => void;\n info: (message: string, details?: Record<string, unknown>) => void;\n debug: (message: string, details?: Record<string, unknown>) => void;\n};\n\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\nconst getRetryDelayMs = (retryCount: number): number => {\n const backoff = BASE_DELAY_MS * Math.pow(BACKOFF_MULTIPLIER, retryCount - 1);\n const jitter = Math.random() * JITTER_MS;\n return Math.min(RETRY_DELAY_CAP_MS, backoff + jitter);\n};\n\nconst createLogger = (logLevel: PriceOSLogLevel): Logger => {\n const shouldLog = (level: PriceOSLogLevel): boolean =>\n logLevel !== \"none\" && LOG_LEVELS[level] <= LOG_LEVELS[logLevel];\n\n const write = (\n level: PriceOSLogLevel,\n message: string,\n details?: Record<string, unknown>\n ): void => {\n if (!shouldLog(level)) return;\n const prefix = `[PriceOS] ${level.toUpperCase()}: ${message}`;\n const payload = details && Object.keys(details).length > 0 ? details : undefined;\n\n switch (level) {\n case \"error\":\n payload ? console.error(prefix, payload) : console.error(prefix);\n return;\n case \"warning\":\n payload ? console.warn(prefix, payload) : console.warn(prefix);\n return;\n case \"info\":\n payload ? console.info(prefix, payload) : console.info(prefix);\n return;\n case \"debug\":\n payload ? console.debug(prefix, payload) : console.debug(prefix);\n return;\n }\n };\n\n return {\n error: (message, details) => write(\"error\", message, details),\n warning: (message, details) => write(\"warning\", message, details),\n info: (message, details) => write(\"info\", message, details),\n debug: (message, details) => write(\"debug\", message, details),\n };\n};\n\nconst getUpstreamSignal = (input: RequestInfo | URL, init?: RequestInit): AbortSignal | undefined => {\n if (init?.signal) return init.signal;\n if (typeof Request !== \"undefined\" && input instanceof Request) return input.signal;\n return undefined;\n};\n\nconst stripSignal = (init?: RequestInit): RequestInit | undefined => {\n if (!init) return undefined;\n const { signal: _signal, ...rest } = init;\n return rest;\n};\n\nconst getRequestDetails = (\n input: RequestInfo | URL,\n init?: RequestInit\n): { method: string; url: string } => {\n const method =\n init?.method ??\n (typeof Request !== \"undefined\" && input instanceof Request ? input.method : \"GET\");\n const url =\n typeof input === \"string\"\n ? input\n : input instanceof URL\n ? input.toString()\n : input.url;\n return { method, url };\n};\n\nconst prepareRetryRequest = async (\n input: RequestInfo | URL,\n init: RequestInit | undefined,\n log: Logger,\n method: string,\n url: string\n): Promise<{ requestInput: RequestInfo | URL; baseInit?: RequestInit; canRetry: boolean }> => {\n if (!(typeof Request !== \"undefined\" && input instanceof Request)) {\n return { requestInput: input, baseInit: stripSignal(init), canRetry: true };\n }\n\n if (input.bodyUsed) {\n log.warning(\"Request body already used; retries disabled\", { method, url });\n return { requestInput: input, baseInit: stripSignal(init), canRetry: false };\n }\n\n let body: BodyInit | undefined = undefined;\n if (method !== \"GET\" && method !== \"HEAD\") {\n try {\n body = await input.clone().arrayBuffer();\n } catch (error) {\n log.warning(\"Unable to clone request body; retries disabled\", { method, url, error });\n return { requestInput: input, baseInit: stripSignal(init), canRetry: false };\n }\n }\n\n const headers = new Headers(input.headers);\n const baseInit = { ...stripSignal(init), method, headers, body };\n return { requestInput: input.url, baseInit, canRetry: true };\n};\n\nconst getErrorMessage = (error: unknown): string => {\n const maybeError = error as { error?: unknown } | null;\n if (maybeError && typeof maybeError.error === \"string\") return maybeError.error;\n return \"Request failed\";\n};\n\nconst throwRequestError = (\n log: Logger,\n error: unknown,\n response: Response | undefined,\n context: string\n): never => {\n log.error(\"Request failed\", { context, status: response?.status, error });\n throw new PriceOSError(getErrorMessage(error), { status: response?.status, details: error });\n};\n\nconst createRetryingFetch = (baseFetch: typeof fetch, log: Logger): typeof fetch => {\n return async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {\n const { method, url } = getRequestDetails(input, init);\n const upstreamSignal = getUpstreamSignal(input, init);\n const { requestInput, baseInit, canRetry } = await prepareRetryRequest(\n input,\n init,\n log,\n method,\n url\n );\n let attempt = 0;\n while (true) {\n log.debug(\"Request attempt\", { method, url, attempt: attempt + 1, maxRetries: MAX_RETRIES });\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);\n let removeAbortListener: (() => void) | null = null;\n\n if (upstreamSignal) {\n if (upstreamSignal.aborted) {\n controller.abort();\n } else {\n const onAbort = () => controller.abort();\n upstreamSignal.addEventListener(\"abort\", onAbort);\n removeAbortListener = () => upstreamSignal.removeEventListener(\"abort\", onAbort);\n }\n }\n\n try {\n const requestInit = { ...(baseInit ?? {}), signal: controller.signal };\n const response = await baseFetch(requestInput, requestInit);\n if (response.status !== RATE_LIMIT_STATUS) return response;\n\n const retryAfter = response.headers.get(\"retry-after\") ?? undefined;\n log.warning(\"Rate limit hit (429)\", {\n method,\n url,\n attempt: attempt + 1,\n maxRetries: MAX_RETRIES,\n retryAfter,\n });\n\n if (!canRetry) {\n log.warning(\"Skipping retry because request body is not replayable\", { method, url });\n return response;\n }\n\n if (attempt >= MAX_RETRIES) {\n log.error(\"Rate limit retries exhausted\", { method, url, attempts: attempt + 1 });\n return response;\n }\n\n const delayMs = getRetryDelayMs(attempt + 1);\n log.info(\"Waiting to retry after rate limit\", {\n method,\n url,\n delayMs,\n nextAttempt: attempt + 2,\n maxRetries: MAX_RETRIES,\n });\n await sleep(delayMs);\n attempt += 1;\n } catch (error) {\n if (controller.signal.aborted) {\n const abortedByCaller = upstreamSignal?.aborted ?? false;\n if (abortedByCaller) {\n log.warning(\"Request aborted by caller\", { method, url, attempt: attempt + 1 });\n } else {\n log.error(\"Request timed out\", {\n method,\n url,\n attempt: attempt + 1,\n timeoutMs: REQUEST_TIMEOUT_MS,\n });\n }\n } else {\n log.error(\"Request failed\", { method, url, attempt: attempt + 1, error });\n }\n throw error;\n } finally {\n clearTimeout(timeoutId);\n removeAbortListener?.();\n }\n }\n };\n};\n\nexport type PriceOSCustomersClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n get(customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null>;\n identify(input: IdentifyCustomerBody): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null>;\n create(input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>>;\n update(input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>>;\n delete(customerId: string): Promise<DeleteCustomerResponse>;\n};\n\nexport type PriceOSFeaturesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n getAccess(customerId: string): Promise<TFeatureAccessMap>;\n};\n\nexport type PriceOSBonusesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n grant(\n input: GrantBonusBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<GrantBonusResponse>;\n};\n\nexport type PriceOSUsageClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n track(\n input: TrackUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<TrackUsageResponse>;\n reset(\n input: ResetUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<ResetUsageResponse>;\n deleteEvents(\n input: DeleteUsageEventsBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<DeleteUsageEventsResponse>;\n trackBatch(\n input: TrackUsageBatchBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<TrackUsageBatchResponse>;\n listEvents(\n input: ListUsageEventsBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<ListUsageEventsResponse>;\n};\n\n// --- Public SDK surface type ---\nexport type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {\n customers: PriceOSCustomersClient<TFeatureAccessMap>;\n features: PriceOSFeaturesClient<TFeatureAccessMap>;\n bonuses: PriceOSBonusesClient<TFeatureAccessMap>;\n usage: PriceOSUsageClient<TFeatureAccessMap>;\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 private log: Logger;\n customers: PriceOSCustomersClient<TFeatureAccessMap>;\n features: PriceOSFeaturesClient<TFeatureAccessMap>;\n bonuses: PriceOSBonusesClient<TFeatureAccessMap>;\n usage: PriceOSUsageClient<TFeatureAccessMap>;\n\n constructor(apiKey: string, opts: PriceOSClientOptions = {}) {\n const logLevel = opts.logLevel ?? \"none\";\n this.log = createLogger(logLevel);\n const baseUrl = \"https://api.priceos.com\";\n this.header = { \"x-api-key\": apiKey };\n const fetchWithRetry = createRetryingFetch(fetch, this.log);\n this.client = createClient<paths>({\n baseUrl,\n fetch: fetchWithRetry,\n headers: {\n \"x-api-key\": apiKey,\n },\n });\n\n this.customers = {\n get: async (customerId: string): Promise<GetCustomerResponse<TFeatureAccessMap> | null> => {\n const { data, error, response } = await this.client.GET(\"/v1/customers/{customerId}\", {\n params: { path: { customerId }, header: this.header },\n });\n if (error) throwRequestError(this.log, error, response, \"GET /v1/customers/{customerId}\");\n return (data ?? null) as GetCustomerResponse<TFeatureAccessMap> | null;\n },\n identify: async (\n input: IdentifyCustomerBody\n ): Promise<IdentifyCustomerResponse<TFeatureAccessMap> | null> => {\n const { data, error, response } = await this.client.POST(\"/v1/customers/identify\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/customers/identify\");\n return (data ?? null) as IdentifyCustomerResponse<TFeatureAccessMap> | null;\n },\n create: async (input: CreateCustomerRequest): Promise<CreateCustomerResponse<TFeatureAccessMap>> => {\n const { data, error, response } = await this.client.POST(\"/v1/customers\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/customers\");\n return data! as CreateCustomerResponse<TFeatureAccessMap>;\n },\n update: async (input: UpdateCustomerBody): Promise<UpdateCustomerResponse<TFeatureAccessMap>> => {\n const { customerId, ...body } = input;\n const { data, error, response } = await this.client.PUT(\"/v1/customers/{customerId}\", {\n params: { path: { customerId }, header: this.header },\n body,\n });\n if (error) throwRequestError(this.log, error, response, \"PUT /v1/customers/{customerId}\");\n return data! as UpdateCustomerResponse<TFeatureAccessMap>;\n },\n delete: async (customerId: string): Promise<DeleteCustomerResponse> => {\n const { data, error, response } = await this.client.DELETE(\"/v1/customers/{customerId}\", {\n params: { path: { customerId }, header: this.header },\n });\n if (error) throwRequestError(this.log, error, response, \"DELETE /v1/customers/{customerId}\");\n return data! as DeleteCustomerResponse;\n },\n };\n\n this.features = {\n getAccess: async (customerId: string): Promise<TFeatureAccessMap> => {\n const { data, error, response } = await this.client.GET(\"/v1/feature-access\", {\n params: { query: { customerId }, header: this.header },\n });\n if (error) throwRequestError(this.log, error, response, \"GET /v1/feature-access\");\n return data! as TFeatureAccessMap;\n },\n };\n\n this.bonuses = {\n grant: async (\n input: GrantBonusBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<GrantBonusResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/bonuses\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/bonuses\");\n return data!;\n },\n };\n\n this.usage = {\n track: async (\n input: TrackUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<TrackUsageResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage\");\n return data!;\n },\n reset: async (\n input: ResetUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<ResetUsageResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage/void\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage/void\");\n return data!;\n },\n deleteEvents: async (\n input: DeleteUsageEventsBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<DeleteUsageEventsResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage/delete\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage/delete\");\n return data!;\n },\n trackBatch: async (\n input: TrackUsageBatchBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<TrackUsageBatchResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage/batch\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage/batch\");\n return data!;\n },\n listEvents: async (\n input: ListUsageEventsBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>\n ): Promise<ListUsageEventsResponse> => {\n const { data, error, response } = await this.client.POST(\"/v1/usage/events\", {\n params: { header: this.header },\n body: input,\n });\n if (error) throwRequestError(this.log, error, response, \"POST /v1/usage/events\");\n return data!;\n },\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,2BAAyB;AAmCzB,IAAM,oBAAoB;AAC1B,IAAM,cAAc;AACpB,IAAM,gBAAgB;AACtB,IAAM,qBAAqB;AAC3B,IAAM,YAAY;AAClB,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAE3B,IAAM,aAA8C;AAAA,EAClD,MAAM;AAAA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mBAAkB,KAAK,KAAK,OAAO,UAAU,sBAAsB;AAC9E,eAAO;AAAA,MACT;AAAA,MACA,YAAY,OACV,UACqC;AACrC,cAAM,EAAE,MAAM,OAAO,SAAS,IAAI,MAAM,KAAK,OAAO,KAAK,oBAAoB;AAAA,UAC3E,QAAQ,EAAE,QAAQ,KAAK,OAAO;AAAA,UAC9B,MAAM;AAAA,QACR,CAAC;AACD,YAAI,MAAO,mBAAkB,KAAK,KAAK,OAAO,UAAU,uBAAuB;AAC/E,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":["createClient"]}
package/dist/index.d.cts CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  interface paths {
7
- "/v1/customer": {
7
+ "/v1/customers/{customerId}": {
8
8
  parameters: {
9
9
  query?: never;
10
10
  header?: never;
@@ -17,15 +17,15 @@ interface paths {
17
17
  */
18
18
  get: {
19
19
  parameters: {
20
- query: {
21
- /** @description Customer ID (internal or Stripe). */
22
- customerId: string;
23
- };
20
+ query?: never;
24
21
  header: {
25
22
  /** @description API key from your PriceOS dashboard. */
26
23
  "x-api-key": string;
27
24
  };
28
- path?: never;
25
+ path: {
26
+ /** @description Customer ID (internal or Stripe). */
27
+ customerId: string;
28
+ };
29
29
  cookie?: never;
30
30
  };
31
31
  requestBody?: never;
@@ -184,14 +184,15 @@ interface paths {
184
184
  /** @description API key from your PriceOS dashboard. */
185
185
  "x-api-key": string;
186
186
  };
187
- path?: never;
187
+ path: {
188
+ /** @description Customer ID (internal or Stripe). */
189
+ customerId: string;
190
+ };
188
191
  cookie?: never;
189
192
  };
190
193
  requestBody: {
191
194
  content: {
192
195
  "application/json": {
193
- /** @description Customer ID (internal or Stripe). */
194
- customerId: string;
195
196
  /** @description Customer name. */
196
197
  name?: string;
197
198
  /** @description Customer email address. */
@@ -357,6 +358,102 @@ interface paths {
357
358
  };
358
359
  };
359
360
  };
361
+ post?: never;
362
+ /**
363
+ * Delete customer
364
+ * @description Delete a customer record.
365
+ */
366
+ delete: {
367
+ parameters: {
368
+ query?: never;
369
+ header: {
370
+ /** @description API key from your PriceOS dashboard. */
371
+ "x-api-key": string;
372
+ };
373
+ path: {
374
+ /** @description Customer ID (internal or Stripe). */
375
+ customerId: string;
376
+ };
377
+ cookie?: never;
378
+ };
379
+ requestBody?: never;
380
+ responses: {
381
+ /** @description Customer deleted */
382
+ 200: {
383
+ headers: {
384
+ [name: string]: unknown;
385
+ };
386
+ content: {
387
+ "application/json": {
388
+ /** @description Deleted customer record ID. */
389
+ id: string;
390
+ };
391
+ };
392
+ };
393
+ /** @description Bad request */
394
+ 400: {
395
+ headers: {
396
+ [name: string]: unknown;
397
+ };
398
+ content: {
399
+ "application/json": {
400
+ /** @description Error message. */
401
+ error: string;
402
+ };
403
+ };
404
+ };
405
+ /** @description Unauthorized */
406
+ 401: {
407
+ headers: {
408
+ [name: string]: unknown;
409
+ };
410
+ content: {
411
+ "application/json": {
412
+ /** @description Error message. */
413
+ error: string;
414
+ };
415
+ };
416
+ };
417
+ /** @description Not found */
418
+ 404: {
419
+ headers: {
420
+ [name: string]: unknown;
421
+ };
422
+ content: {
423
+ "application/json": {
424
+ /** @description Error message. */
425
+ error: string;
426
+ };
427
+ };
428
+ };
429
+ /** @description Server error */
430
+ 500: {
431
+ headers: {
432
+ [name: string]: unknown;
433
+ };
434
+ content: {
435
+ "application/json": {
436
+ /** @description Error message. */
437
+ error: string;
438
+ };
439
+ };
440
+ };
441
+ };
442
+ };
443
+ options?: never;
444
+ head?: never;
445
+ patch?: never;
446
+ trace?: never;
447
+ };
448
+ "/v1/customers": {
449
+ parameters: {
450
+ query?: never;
451
+ header?: never;
452
+ path?: never;
453
+ cookie?: never;
454
+ };
455
+ get?: never;
456
+ put?: never;
360
457
  /**
361
458
  * Create customer
362
459
  * @description Create a customer record.
@@ -541,93 +638,13 @@ interface paths {
541
638
  };
542
639
  };
543
640
  };
544
- /**
545
- * Delete customer
546
- * @description Delete a customer record.
547
- */
548
- delete: {
549
- parameters: {
550
- query: {
551
- /** @description Customer ID (internal or Stripe). */
552
- customerId: string;
553
- };
554
- header: {
555
- /** @description API key from your PriceOS dashboard. */
556
- "x-api-key": string;
557
- };
558
- path?: never;
559
- cookie?: never;
560
- };
561
- requestBody?: never;
562
- responses: {
563
- /** @description Customer deleted */
564
- 200: {
565
- headers: {
566
- [name: string]: unknown;
567
- };
568
- content: {
569
- "application/json": {
570
- /** @description Deleted customer record ID. */
571
- id: string;
572
- };
573
- };
574
- };
575
- /** @description Bad request */
576
- 400: {
577
- headers: {
578
- [name: string]: unknown;
579
- };
580
- content: {
581
- "application/json": {
582
- /** @description Error message. */
583
- error: string;
584
- };
585
- };
586
- };
587
- /** @description Unauthorized */
588
- 401: {
589
- headers: {
590
- [name: string]: unknown;
591
- };
592
- content: {
593
- "application/json": {
594
- /** @description Error message. */
595
- error: string;
596
- };
597
- };
598
- };
599
- /** @description Not found */
600
- 404: {
601
- headers: {
602
- [name: string]: unknown;
603
- };
604
- content: {
605
- "application/json": {
606
- /** @description Error message. */
607
- error: string;
608
- };
609
- };
610
- };
611
- /** @description Server error */
612
- 500: {
613
- headers: {
614
- [name: string]: unknown;
615
- };
616
- content: {
617
- "application/json": {
618
- /** @description Error message. */
619
- error: string;
620
- };
621
- };
622
- };
623
- };
624
- };
641
+ delete?: never;
625
642
  options?: never;
626
643
  head?: never;
627
644
  patch?: never;
628
645
  trace?: never;
629
646
  };
630
- "/v1/customer/identify": {
647
+ "/v1/customers/identify": {
631
648
  parameters: {
632
649
  query?: never;
633
650
  header?: never;
@@ -1164,6 +1181,125 @@ interface paths {
1164
1181
  patch?: never;
1165
1182
  trace?: never;
1166
1183
  };
1184
+ "/v1/bonuses": {
1185
+ parameters: {
1186
+ query?: never;
1187
+ header?: never;
1188
+ path?: never;
1189
+ cookie?: never;
1190
+ };
1191
+ get?: never;
1192
+ put?: never;
1193
+ /**
1194
+ * Grant bonus
1195
+ * @description Grant a one-time bonus amount for a customer feature.
1196
+ */
1197
+ post: {
1198
+ parameters: {
1199
+ query?: never;
1200
+ header: {
1201
+ /** @description API key from your PriceOS dashboard. */
1202
+ "x-api-key": string;
1203
+ };
1204
+ path?: never;
1205
+ cookie?: never;
1206
+ };
1207
+ requestBody: {
1208
+ content: {
1209
+ "application/json": {
1210
+ /** @description Customer ID (internal or Stripe). */
1211
+ customerId: string;
1212
+ /** @description Feature key to grant bonus for. */
1213
+ featureKey: string;
1214
+ /** @description Bonus amount to grant. */
1215
+ amount: number;
1216
+ /** @description Optional Unix timestamp (ms) when the bonus expires. */
1217
+ expiresAt?: number;
1218
+ /** @description Optional reason for the bonus grant. */
1219
+ reason?: string | null;
1220
+ /** @description Optional metadata for the grant (string key/value pairs). */
1221
+ metadata?: {
1222
+ [key: string]: string;
1223
+ };
1224
+ };
1225
+ };
1226
+ };
1227
+ responses: {
1228
+ /** @description Bonus granted */
1229
+ 200: {
1230
+ headers: {
1231
+ [name: string]: unknown;
1232
+ };
1233
+ content: {
1234
+ "application/json": {
1235
+ /**
1236
+ * Format: uuid
1237
+ * @description Bonus grant ID.
1238
+ */
1239
+ grantId: string;
1240
+ /** @description Remaining amount for the newly created grant. */
1241
+ remainingAmount: number;
1242
+ /** @description Total remaining bonus amount for this customer + feature. */
1243
+ counterRemaining: number;
1244
+ };
1245
+ };
1246
+ };
1247
+ /** @description Bad request */
1248
+ 400: {
1249
+ headers: {
1250
+ [name: string]: unknown;
1251
+ };
1252
+ content: {
1253
+ "application/json": {
1254
+ /** @description Error message. */
1255
+ error: string;
1256
+ };
1257
+ };
1258
+ };
1259
+ /** @description Unauthorized */
1260
+ 401: {
1261
+ headers: {
1262
+ [name: string]: unknown;
1263
+ };
1264
+ content: {
1265
+ "application/json": {
1266
+ /** @description Error message. */
1267
+ error: string;
1268
+ };
1269
+ };
1270
+ };
1271
+ /** @description Not found */
1272
+ 404: {
1273
+ headers: {
1274
+ [name: string]: unknown;
1275
+ };
1276
+ content: {
1277
+ "application/json": {
1278
+ /** @description Error message. */
1279
+ error: string;
1280
+ };
1281
+ };
1282
+ };
1283
+ /** @description Server error */
1284
+ 500: {
1285
+ headers: {
1286
+ [name: string]: unknown;
1287
+ };
1288
+ content: {
1289
+ "application/json": {
1290
+ /** @description Error message. */
1291
+ error: string;
1292
+ };
1293
+ };
1294
+ };
1295
+ };
1296
+ };
1297
+ delete?: never;
1298
+ options?: never;
1299
+ head?: never;
1300
+ patch?: never;
1301
+ trace?: never;
1302
+ };
1167
1303
  "/v1/usage/void": {
1168
1304
  parameters: {
1169
1305
  query?: never;
@@ -1685,18 +1821,21 @@ type WithFeatureAccess<T, TFeatureAccessMap> = T extends {
1685
1821
  } ? Omit<T, "featureAccess"> & {
1686
1822
  featureAccess: TFeatureAccessMap;
1687
1823
  } : T;
1688
- type GetCustomerResponseBase = paths["/v1/customer"]["get"]["responses"][200]["content"]["application/json"];
1824
+ type GetCustomerResponseBase = paths["/v1/customers/{customerId}"]["get"]["responses"][200]["content"]["application/json"];
1689
1825
  type GetCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<GetCustomerResponseBase, TFeatureAccessMap>;
1690
- type CreateCustomerRequest = paths["/v1/customer"]["post"]["requestBody"]["content"]["application/json"];
1691
- type CreateCustomerResponseBase = paths["/v1/customer"]["post"]["responses"][201]["content"]["application/json"];
1826
+ type CreateCustomerRequest = paths["/v1/customers"]["post"]["requestBody"]["content"]["application/json"];
1827
+ type CreateCustomerResponseBase = paths["/v1/customers"]["post"]["responses"][201]["content"]["application/json"];
1692
1828
  type CreateCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<CreateCustomerResponseBase, TFeatureAccessMap>;
1693
- type UpdateCustomerBody = paths["/v1/customer"]["put"]["requestBody"]["content"]["application/json"];
1694
- type UpdateCustomerResponseBase = paths["/v1/customer"]["put"]["responses"][200]["content"]["application/json"];
1829
+ type UpdateCustomerBodyBase = paths["/v1/customers/{customerId}"]["put"]["requestBody"]["content"]["application/json"];
1830
+ type UpdateCustomerBody = UpdateCustomerBodyBase & {
1831
+ customerId: string;
1832
+ };
1833
+ type UpdateCustomerResponseBase = paths["/v1/customers/{customerId}"]["put"]["responses"][200]["content"]["application/json"];
1695
1834
  type UpdateCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<UpdateCustomerResponseBase, TFeatureAccessMap>;
1696
- type DeleteCustomerRequest = paths["/v1/customer"]["delete"]["parameters"]["query"];
1697
- type DeleteCustomerResponse = paths["/v1/customer"]["delete"]["responses"][200]["content"]["application/json"];
1698
- type IdentifyCustomerBody = paths["/v1/customer/identify"]["post"]["requestBody"]["content"]["application/json"];
1699
- type IdentifyCustomerResponseBase = paths["/v1/customer/identify"]["post"]["responses"][200]["content"]["application/json"];
1835
+ type DeleteCustomerRequest = paths["/v1/customers/{customerId}"]["delete"]["parameters"]["path"];
1836
+ type DeleteCustomerResponse = paths["/v1/customers/{customerId}"]["delete"]["responses"][200]["content"]["application/json"];
1837
+ type IdentifyCustomerBody = paths["/v1/customers/identify"]["post"]["requestBody"]["content"]["application/json"];
1838
+ type IdentifyCustomerResponseBase = paths["/v1/customers/identify"]["post"]["responses"][200]["content"]["application/json"];
1700
1839
  type IdentifyCustomerResponse<TFeatureAccessMap = GetFeatureAccessResponse> = WithFeatureAccess<IdentifyCustomerResponseBase, TFeatureAccessMap>;
1701
1840
  type GetFeatureAccessResponse = paths["/v1/feature-access"]["get"]["responses"][200]["content"]["application/json"];
1702
1841
  type LimitFeatureKeyFromAccessMap<TFeatureAccessMap> = TFeatureAccessMap extends {
@@ -1711,6 +1850,11 @@ type TrackUsageBody<TFeatureKey extends string = TrackUsageBodyBase["featureKey"
1711
1850
  featureKey: TFeatureKey;
1712
1851
  };
1713
1852
  type TrackUsageResponse = paths["/v1/usage"]["post"]["responses"][200]["content"]["application/json"];
1853
+ type GrantBonusBodyBase = paths["/v1/bonuses"]["post"]["requestBody"]["content"]["application/json"];
1854
+ type GrantBonusBody<TFeatureKey extends string = GrantBonusBodyBase["featureKey"]> = Omit<GrantBonusBodyBase, "featureKey"> & {
1855
+ featureKey: TFeatureKey;
1856
+ };
1857
+ type GrantBonusResponse = paths["/v1/bonuses"]["post"]["responses"][200]["content"]["application/json"];
1714
1858
  type ResetUsageBodyBase = paths["/v1/usage/void"]["post"]["requestBody"]["content"]["application/json"];
1715
1859
  type ResetUsageBody<TFeatureKey extends string = NonNullable<ResetUsageBodyBase["featureKey"]>> = Omit<ResetUsageBodyBase, "featureKey"> & {
1716
1860
  featureKey?: TFeatureKey;
@@ -1751,6 +1895,9 @@ type PriceOSCustomersClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1751
1895
  type PriceOSFeaturesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1752
1896
  getAccess(customerId: string): Promise<TFeatureAccessMap>;
1753
1897
  };
1898
+ type PriceOSBonusesClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1899
+ grant(input: GrantBonusBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>): Promise<GrantBonusResponse>;
1900
+ };
1754
1901
  type PriceOSUsageClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1755
1902
  track(input: TrackUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>): Promise<TrackUsageResponse>;
1756
1903
  reset(input: ResetUsageBody<LimitFeatureKeyFromAccessMap<TFeatureAccessMap>>): Promise<ResetUsageResponse>;
@@ -1761,6 +1908,7 @@ type PriceOSUsageClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1761
1908
  type PriceOSHttpClient<TFeatureAccessMap = GetFeatureAccessResponse> = {
1762
1909
  customers: PriceOSCustomersClient<TFeatureAccessMap>;
1763
1910
  features: PriceOSFeaturesClient<TFeatureAccessMap>;
1911
+ bonuses: PriceOSBonusesClient<TFeatureAccessMap>;
1764
1912
  usage: PriceOSUsageClient<TFeatureAccessMap>;
1765
1913
  };
1766
1914
  declare class PriceOSError extends Error {
@@ -1777,8 +1925,9 @@ declare class PriceOS<TFeatureAccessMap = GetFeatureAccessResponse> implements P
1777
1925
  private log;
1778
1926
  customers: PriceOSCustomersClient<TFeatureAccessMap>;
1779
1927
  features: PriceOSFeaturesClient<TFeatureAccessMap>;
1928
+ bonuses: PriceOSBonusesClient<TFeatureAccessMap>;
1780
1929
  usage: PriceOSUsageClient<TFeatureAccessMap>;
1781
1930
  constructor(apiKey: string, opts?: PriceOSClientOptions);
1782
1931
  }
1783
1932
 
1784
- export { type CreateCustomerRequest, type CreateCustomerResponse, type DeleteCustomerRequest, type DeleteCustomerResponse, type DeleteUsageEventsBody, type DeleteUsageEventsResponse, type GetCustomerResponse, type GetFeatureAccessResponse, type IdentifyCustomerBody, type IdentifyCustomerResponse, type LimitFeatureKeyFromAccessMap, type ListUsageEventsBody, type ListUsageEventsResponse, PriceOS, type PriceOSClientOptions, type PriceOSCustomersClient, PriceOSError, type PriceOSFeaturesClient, type PriceOSHttpClient, type PriceOSLogLevel, type PriceOSUsageClient, type ResetUsageBody, type ResetUsageResponse, type TrackUsageBatchBody, type TrackUsageBatchEvent, type TrackUsageBatchResponse, type TrackUsageBody, type TrackUsageResponse, type UpdateCustomerBody, type UpdateCustomerResponse, type UsageEvent };
1933
+ export { type CreateCustomerRequest, type CreateCustomerResponse, type DeleteCustomerRequest, type DeleteCustomerResponse, type DeleteUsageEventsBody, type DeleteUsageEventsResponse, type GetCustomerResponse, type GetFeatureAccessResponse, type GrantBonusBody, type GrantBonusResponse, type IdentifyCustomerBody, type IdentifyCustomerResponse, type LimitFeatureKeyFromAccessMap, type ListUsageEventsBody, type ListUsageEventsResponse, PriceOS, type PriceOSBonusesClient, type PriceOSClientOptions, type PriceOSCustomersClient, PriceOSError, type PriceOSFeaturesClient, type PriceOSHttpClient, type PriceOSLogLevel, type PriceOSUsageClient, type ResetUsageBody, type ResetUsageResponse, type TrackUsageBatchBody, type TrackUsageBatchEvent, type TrackUsageBatchResponse, type TrackUsageBody, type TrackUsageResponse, type UpdateCustomerBody, type UpdateCustomerResponse, type UsageEvent };