@paid-ai/paid-node 0.5.0-alpha2 → 0.5.0

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.
Files changed (269) hide show
  1. package/README.md +118 -36
  2. package/dist/cjs/Client.d.ts +35 -3
  3. package/dist/cjs/Client.js +57 -19
  4. package/dist/cjs/api/errors/InternalServerError.d.ts +9 -0
  5. package/dist/cjs/api/errors/InternalServerError.js +52 -0
  6. package/dist/cjs/api/errors/index.d.ts +1 -0
  7. package/dist/cjs/api/errors/index.js +1 -0
  8. package/dist/cjs/api/index.d.ts +1 -1
  9. package/dist/cjs/api/index.js +1 -1
  10. package/dist/cjs/api/resources/agents/client/Client.d.ts +16 -0
  11. package/dist/cjs/api/resources/agents/client/Client.js +16 -0
  12. package/dist/cjs/api/resources/customers/client/Client.d.ts +38 -0
  13. package/dist/cjs/api/resources/customers/client/Client.js +164 -0
  14. package/dist/cjs/api/resources/customers/client/requests/CustomerCreate.d.ts +2 -0
  15. package/dist/cjs/api/resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.d.ts +30 -0
  16. package/dist/cjs/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.d.ts +30 -0
  17. package/dist/cjs/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.js +5 -0
  18. package/dist/cjs/api/resources/customers/client/requests/index.d.ts +2 -0
  19. package/dist/cjs/api/resources/index.d.ts +8 -1
  20. package/dist/cjs/api/resources/index.js +9 -2
  21. package/dist/cjs/api/resources/orders/client/requests/OrderCreate.d.ts +2 -0
  22. package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +0 -2
  23. package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +0 -2
  24. package/dist/cjs/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.ts +0 -2
  25. package/dist/cjs/api/resources/plans/client/Client.d.ts +75 -0
  26. package/dist/cjs/api/resources/plans/client/Client.js +272 -0
  27. package/dist/cjs/api/resources/plans/client/index.d.ts +1 -0
  28. package/dist/cjs/api/resources/plans/client/index.js +17 -0
  29. package/dist/cjs/api/resources/plans/client/requests/PlansGetUsageRequest.d.ts +35 -0
  30. package/dist/cjs/api/resources/plans/client/requests/PlansGetUsageRequest.js +5 -0
  31. package/dist/cjs/api/resources/plans/client/requests/index.d.ts +1 -0
  32. package/dist/cjs/api/resources/plans/client/requests/index.js +2 -0
  33. package/dist/cjs/api/resources/plans/index.d.ts +1 -0
  34. package/dist/cjs/api/resources/plans/index.js +17 -0
  35. package/dist/cjs/api/resources/products/client/Client.d.ts +109 -0
  36. package/dist/cjs/api/resources/products/client/Client.js +470 -0
  37. package/dist/cjs/api/resources/products/client/index.d.ts +1 -0
  38. package/dist/cjs/api/resources/products/client/index.js +17 -0
  39. package/dist/cjs/api/resources/products/client/requests/ProductCreate.d.ts +29 -0
  40. package/dist/cjs/api/resources/products/client/requests/ProductCreate.js +14 -0
  41. package/dist/cjs/api/resources/products/client/requests/index.d.ts +1 -0
  42. package/dist/cjs/api/resources/products/client/requests/index.js +2 -0
  43. package/dist/cjs/api/resources/products/index.d.ts +1 -0
  44. package/dist/cjs/api/resources/products/index.js +17 -0
  45. package/dist/cjs/api/resources/traces/client/Client.d.ts +52 -0
  46. package/dist/cjs/api/resources/traces/client/Client.js +166 -0
  47. package/dist/cjs/api/resources/traces/client/index.d.ts +1 -0
  48. package/dist/cjs/api/resources/traces/client/index.js +17 -0
  49. package/dist/cjs/api/resources/traces/client/requests/GetTracesRequest.d.ts +50 -0
  50. package/dist/cjs/api/resources/traces/client/requests/GetTracesRequest.js +5 -0
  51. package/dist/cjs/api/resources/traces/client/requests/index.d.ts +1 -0
  52. package/dist/cjs/api/resources/traces/client/requests/index.js +2 -0
  53. package/dist/cjs/api/resources/traces/index.d.ts +1 -0
  54. package/dist/cjs/api/resources/traces/index.js +17 -0
  55. package/dist/cjs/api/resources/usage/client/Client.d.ts +47 -0
  56. package/dist/cjs/api/resources/usage/client/Client.js +146 -0
  57. package/dist/cjs/api/resources/usage/client/requests/UsageCheckUsageRequest.d.ts +28 -0
  58. package/dist/cjs/api/resources/usage/client/requests/UsageCheckUsageRequest.js +5 -0
  59. package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +29 -0
  60. package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.js +5 -0
  61. package/dist/cjs/api/resources/usage/client/requests/index.d.ts +2 -0
  62. package/dist/cjs/api/resources/usage/index.d.ts +1 -0
  63. package/dist/cjs/api/resources/usage/index.js +1 -0
  64. package/dist/cjs/api/resources/usage/types/UsageCheckUsageResponse.d.ts +17 -0
  65. package/dist/cjs/api/resources/usage/types/UsageCheckUsageResponse.js +5 -0
  66. package/dist/cjs/api/resources/usage/types/index.d.ts +1 -0
  67. package/dist/cjs/api/resources/usage/types/index.js +17 -0
  68. package/dist/cjs/api/types/CostAmount.d.ts +12 -0
  69. package/dist/cjs/api/types/CostAmount.js +5 -0
  70. package/dist/cjs/api/types/CostTrace.d.ts +22 -0
  71. package/dist/cjs/api/types/CostTrace.js +5 -0
  72. package/dist/cjs/api/types/CostTracesResponse.d.ts +11 -0
  73. package/dist/cjs/api/types/CostTracesResponse.js +5 -0
  74. package/dist/cjs/api/types/Customer.d.ts +2 -0
  75. package/dist/cjs/api/types/CustomerUpdate.d.ts +2 -0
  76. package/dist/cjs/api/types/OrderLineAttributeCreateOne.d.ts +4 -0
  77. package/dist/cjs/api/types/OrderLineAttributeCreateOne.js +5 -0
  78. package/dist/cjs/api/types/OrderLineCreate.d.ts +10 -4
  79. package/dist/cjs/api/types/PaginationMeta.d.ts +28 -0
  80. package/dist/cjs/api/types/PaginationMeta.js +5 -0
  81. package/dist/cjs/api/types/Plan.d.ts +58 -0
  82. package/dist/cjs/api/types/Plan.js +5 -0
  83. package/dist/cjs/api/types/PlanGroup.d.ts +23 -0
  84. package/dist/cjs/api/types/PlanGroup.js +5 -0
  85. package/dist/cjs/api/types/Product.d.ts +36 -0
  86. package/dist/cjs/api/types/Product.js +14 -0
  87. package/dist/cjs/api/types/ProductUpdate.d.ts +23 -0
  88. package/dist/cjs/api/types/ProductUpdate.js +14 -0
  89. package/dist/cjs/api/types/Signal.d.ts +7 -2
  90. package/dist/cjs/api/types/SignalV2.d.ts +22 -0
  91. package/dist/cjs/api/types/SignalV2.js +5 -0
  92. package/dist/cjs/api/types/Trace.d.ts +26 -0
  93. package/dist/cjs/api/types/Trace.js +5 -0
  94. package/dist/cjs/api/types/TracesResponse.d.ts +11 -0
  95. package/dist/cjs/api/types/TracesResponse.js +5 -0
  96. package/dist/cjs/api/types/UsagePaginationMeta.d.ts +16 -0
  97. package/dist/cjs/api/types/UsagePaginationMeta.js +5 -0
  98. package/dist/cjs/api/types/UsageSummariesResponse.d.ts +11 -0
  99. package/dist/cjs/api/types/UsageSummariesResponse.js +5 -0
  100. package/dist/cjs/api/types/UsageSummary.d.ts +58 -0
  101. package/dist/cjs/api/types/UsageSummary.js +5 -0
  102. package/dist/cjs/api/types/index.d.ts +15 -1
  103. package/dist/cjs/api/types/index.js +15 -1
  104. package/dist/cjs/index.d.ts +1 -0
  105. package/dist/cjs/index.js +4 -0
  106. package/dist/cjs/integrations/adapters/expressjs/base-adapter.d.ts +17 -0
  107. package/dist/cjs/integrations/adapters/expressjs/base-adapter.js +71 -0
  108. package/dist/cjs/integrations/adapters/expressjs/index.d.ts +6 -0
  109. package/dist/cjs/integrations/adapters/expressjs/index.js +20 -0
  110. package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +162 -0
  111. package/dist/cjs/integrations/adapters/expressjs/routes.js +269 -0
  112. package/dist/cjs/integrations/adapters/nestjs/index.d.ts +7 -0
  113. package/dist/cjs/integrations/adapters/nestjs/index.js +23 -0
  114. package/dist/cjs/tracing/autoInstrumentation.d.ts +10 -0
  115. package/dist/cjs/tracing/autoInstrumentation.js +57 -0
  116. package/dist/cjs/tracing/index.d.ts +4 -0
  117. package/dist/cjs/tracing/index.js +12 -0
  118. package/dist/cjs/tracing/signal.d.ts +18 -1
  119. package/dist/cjs/tracing/signal.js +29 -13
  120. package/dist/cjs/tracing/spanProcessor.d.ts +10 -0
  121. package/dist/cjs/tracing/spanProcessor.js +82 -0
  122. package/dist/cjs/tracing/tracing.d.ts +12 -6
  123. package/dist/cjs/tracing/tracing.js +65 -58
  124. package/dist/cjs/tracing/tracingContext.d.ts +8 -0
  125. package/dist/cjs/tracing/tracingContext.js +28 -0
  126. package/dist/cjs/tracing/wrappers/anthropicWrapper.js +11 -7
  127. package/dist/cjs/tracing/wrappers/langchainCallback.js +11 -7
  128. package/dist/cjs/tracing/wrappers/mistralWrapper.js +11 -7
  129. package/dist/cjs/tracing/wrappers/openAiWrapper.js +24 -23
  130. package/dist/cjs/tracing/wrappers/vercelAIWrapper.js +68 -43
  131. package/dist/cjs/version.d.ts +1 -1
  132. package/dist/cjs/version.js +1 -1
  133. package/dist/esm/Client.d.mts +35 -3
  134. package/dist/esm/Client.mjs +54 -16
  135. package/dist/esm/api/errors/InternalServerError.d.mts +9 -0
  136. package/dist/esm/api/errors/InternalServerError.mjs +15 -0
  137. package/dist/esm/api/errors/index.d.mts +1 -0
  138. package/dist/esm/api/errors/index.mjs +1 -0
  139. package/dist/esm/api/index.d.mts +1 -1
  140. package/dist/esm/api/index.mjs +1 -1
  141. package/dist/esm/api/resources/agents/client/Client.d.mts +16 -0
  142. package/dist/esm/api/resources/agents/client/Client.mjs +16 -0
  143. package/dist/esm/api/resources/customers/client/Client.d.mts +38 -0
  144. package/dist/esm/api/resources/customers/client/Client.mjs +164 -0
  145. package/dist/esm/api/resources/customers/client/requests/CustomerCreate.d.mts +2 -0
  146. package/dist/esm/api/resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.d.mts +30 -0
  147. package/dist/esm/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.d.mts +30 -0
  148. package/dist/esm/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.mjs +4 -0
  149. package/dist/esm/api/resources/customers/client/requests/index.d.mts +2 -0
  150. package/dist/esm/api/resources/index.d.mts +8 -1
  151. package/dist/esm/api/resources/index.mjs +8 -1
  152. package/dist/esm/api/resources/orders/client/requests/OrderCreate.d.mts +2 -0
  153. package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +0 -2
  154. package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +0 -2
  155. package/dist/esm/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.mts +0 -2
  156. package/dist/esm/api/resources/plans/client/Client.d.mts +75 -0
  157. package/dist/esm/api/resources/plans/client/Client.mjs +232 -0
  158. package/dist/esm/api/resources/plans/client/index.d.mts +1 -0
  159. package/dist/esm/api/resources/plans/client/index.mjs +1 -0
  160. package/dist/esm/api/resources/plans/client/requests/PlansGetUsageRequest.d.mts +35 -0
  161. package/dist/esm/api/resources/plans/client/requests/PlansGetUsageRequest.mjs +4 -0
  162. package/dist/esm/api/resources/plans/client/requests/index.d.mts +1 -0
  163. package/dist/esm/api/resources/plans/client/requests/index.mjs +1 -0
  164. package/dist/esm/api/resources/plans/index.d.mts +1 -0
  165. package/dist/esm/api/resources/plans/index.mjs +1 -0
  166. package/dist/esm/api/resources/products/client/Client.d.mts +109 -0
  167. package/dist/esm/api/resources/products/client/Client.mjs +430 -0
  168. package/dist/esm/api/resources/products/client/index.d.mts +1 -0
  169. package/dist/esm/api/resources/products/client/index.mjs +1 -0
  170. package/dist/esm/api/resources/products/client/requests/ProductCreate.d.mts +29 -0
  171. package/dist/esm/api/resources/products/client/requests/ProductCreate.mjs +11 -0
  172. package/dist/esm/api/resources/products/client/requests/index.d.mts +1 -0
  173. package/dist/esm/api/resources/products/client/requests/index.mjs +1 -0
  174. package/dist/esm/api/resources/products/index.d.mts +1 -0
  175. package/dist/esm/api/resources/products/index.mjs +1 -0
  176. package/dist/esm/api/resources/traces/client/Client.d.mts +52 -0
  177. package/dist/esm/api/resources/traces/client/Client.mjs +126 -0
  178. package/dist/esm/api/resources/traces/client/index.d.mts +1 -0
  179. package/dist/esm/api/resources/traces/client/index.mjs +1 -0
  180. package/dist/esm/api/resources/traces/client/requests/GetTracesRequest.d.mts +50 -0
  181. package/dist/esm/api/resources/traces/client/requests/GetTracesRequest.mjs +4 -0
  182. package/dist/esm/api/resources/traces/client/requests/index.d.mts +1 -0
  183. package/dist/esm/api/resources/traces/client/requests/index.mjs +1 -0
  184. package/dist/esm/api/resources/traces/index.d.mts +1 -0
  185. package/dist/esm/api/resources/traces/index.mjs +1 -0
  186. package/dist/esm/api/resources/usage/client/Client.d.mts +47 -0
  187. package/dist/esm/api/resources/usage/client/Client.mjs +146 -0
  188. package/dist/esm/api/resources/usage/client/requests/UsageCheckUsageRequest.d.mts +28 -0
  189. package/dist/esm/api/resources/usage/client/requests/UsageCheckUsageRequest.mjs +4 -0
  190. package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +29 -0
  191. package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.mjs +4 -0
  192. package/dist/esm/api/resources/usage/client/requests/index.d.mts +2 -0
  193. package/dist/esm/api/resources/usage/index.d.mts +1 -0
  194. package/dist/esm/api/resources/usage/index.mjs +1 -0
  195. package/dist/esm/api/resources/usage/types/UsageCheckUsageResponse.d.mts +17 -0
  196. package/dist/esm/api/resources/usage/types/UsageCheckUsageResponse.mjs +4 -0
  197. package/dist/esm/api/resources/usage/types/index.d.mts +1 -0
  198. package/dist/esm/api/resources/usage/types/index.mjs +1 -0
  199. package/dist/esm/api/types/CostAmount.d.mts +12 -0
  200. package/dist/esm/api/types/CostAmount.mjs +4 -0
  201. package/dist/esm/api/types/CostTrace.d.mts +22 -0
  202. package/dist/esm/api/types/CostTrace.mjs +4 -0
  203. package/dist/esm/api/types/CostTracesResponse.d.mts +11 -0
  204. package/dist/esm/api/types/CostTracesResponse.mjs +4 -0
  205. package/dist/esm/api/types/Customer.d.mts +2 -0
  206. package/dist/esm/api/types/CustomerUpdate.d.mts +2 -0
  207. package/dist/esm/api/types/OrderLineAttributeCreateOne.d.mts +4 -0
  208. package/dist/esm/api/types/OrderLineAttributeCreateOne.mjs +4 -0
  209. package/dist/esm/api/types/OrderLineCreate.d.mts +10 -4
  210. package/dist/esm/api/types/PaginationMeta.d.mts +28 -0
  211. package/dist/esm/api/types/PaginationMeta.mjs +4 -0
  212. package/dist/esm/api/types/Plan.d.mts +58 -0
  213. package/dist/esm/api/types/Plan.mjs +4 -0
  214. package/dist/esm/api/types/PlanGroup.d.mts +23 -0
  215. package/dist/esm/api/types/PlanGroup.mjs +4 -0
  216. package/dist/esm/api/types/Product.d.mts +36 -0
  217. package/dist/esm/api/types/Product.mjs +11 -0
  218. package/dist/esm/api/types/ProductUpdate.d.mts +23 -0
  219. package/dist/esm/api/types/ProductUpdate.mjs +11 -0
  220. package/dist/esm/api/types/Signal.d.mts +7 -2
  221. package/dist/esm/api/types/SignalV2.d.mts +22 -0
  222. package/dist/esm/api/types/SignalV2.mjs +4 -0
  223. package/dist/esm/api/types/Trace.d.mts +26 -0
  224. package/dist/esm/api/types/Trace.mjs +4 -0
  225. package/dist/esm/api/types/TracesResponse.d.mts +11 -0
  226. package/dist/esm/api/types/TracesResponse.mjs +4 -0
  227. package/dist/esm/api/types/UsagePaginationMeta.d.mts +16 -0
  228. package/dist/esm/api/types/UsagePaginationMeta.mjs +4 -0
  229. package/dist/esm/api/types/UsageSummariesResponse.d.mts +11 -0
  230. package/dist/esm/api/types/UsageSummariesResponse.mjs +4 -0
  231. package/dist/esm/api/types/UsageSummary.d.mts +58 -0
  232. package/dist/esm/api/types/UsageSummary.mjs +4 -0
  233. package/dist/esm/api/types/index.d.mts +15 -1
  234. package/dist/esm/api/types/index.mjs +15 -1
  235. package/dist/esm/index.d.mts +1 -0
  236. package/dist/esm/index.mjs +1 -0
  237. package/dist/esm/integrations/adapters/expressjs/base-adapter.d.mts +17 -0
  238. package/dist/esm/integrations/adapters/expressjs/base-adapter.mjs +67 -0
  239. package/dist/esm/integrations/adapters/expressjs/index.d.mts +6 -0
  240. package/dist/esm/integrations/adapters/expressjs/index.mjs +6 -0
  241. package/dist/esm/integrations/adapters/expressjs/routes.d.mts +162 -0
  242. package/dist/esm/integrations/adapters/expressjs/routes.mjs +258 -0
  243. package/dist/esm/integrations/adapters/nestjs/index.d.mts +7 -0
  244. package/dist/esm/integrations/adapters/nestjs/index.mjs +7 -0
  245. package/dist/esm/tracing/autoInstrumentation.d.mts +10 -0
  246. package/dist/esm/tracing/autoInstrumentation.mjs +54 -0
  247. package/dist/esm/tracing/index.d.mts +4 -0
  248. package/dist/esm/tracing/index.mjs +4 -0
  249. package/dist/esm/tracing/signal.d.mts +18 -1
  250. package/dist/esm/tracing/signal.mjs +28 -12
  251. package/dist/esm/tracing/spanProcessor.d.mts +10 -0
  252. package/dist/esm/tracing/spanProcessor.mjs +78 -0
  253. package/dist/esm/tracing/tracing.d.mts +12 -6
  254. package/dist/esm/tracing/tracing.mjs +59 -52
  255. package/dist/esm/tracing/tracingContext.d.mts +8 -0
  256. package/dist/esm/tracing/tracingContext.mjs +23 -0
  257. package/dist/esm/tracing/wrappers/anthropicWrapper.mjs +11 -7
  258. package/dist/esm/tracing/wrappers/langchainCallback.mjs +11 -7
  259. package/dist/esm/tracing/wrappers/mistralWrapper.mjs +11 -7
  260. package/dist/esm/tracing/wrappers/openAiWrapper.mjs +24 -23
  261. package/dist/esm/tracing/wrappers/vercelAIWrapper.mjs +68 -43
  262. package/dist/esm/version.d.mts +1 -1
  263. package/dist/esm/version.mjs +1 -1
  264. package/package.json +41 -4
  265. package/reference.md +1147 -153
  266. package/dist/cjs/api/types/OrderLineAttributeCreate.d.ts +0 -12
  267. package/dist/esm/api/types/OrderLineAttributeCreate.d.mts +0 -12
  268. /package/dist/cjs/api/{types/OrderLineAttributeCreate.js → resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.js} +0 -0
  269. /package/dist/esm/api/{types/OrderLineAttributeCreate.mjs → resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.mjs} +0 -0
@@ -0,0 +1,162 @@
1
+ /**
2
+ * ExpressJS route helpers for Paid SDK
3
+ * These functions create handlers compatible with ExpressJS controllers
4
+ */
5
+ import { Request, Response } from "express";
6
+ import { BaseHandlerConfig } from "../../utils/base-handler.mjs";
7
+ import { OrderOptions } from "../../types.mjs";
8
+ export interface ActivateOrderSyncRouteConfig extends BaseHandlerConfig {
9
+ defaultReturnUrl?: string;
10
+ }
11
+ /**
12
+ * Create an Express handler for synchronous order activation
13
+ *
14
+ * Use this in your Express app to handle order activation with payment.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import express from 'express';
19
+ * import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/express';
20
+ *
21
+ * const app = express();
22
+ * const activateOrderSyncHandler = createActivateOrderSyncRoute();
23
+ *
24
+ * app.post('/paid/payments/activate-order-sync', activateOrderSyncHandler);
25
+ * ```
26
+ *
27
+ * @example With NestJS
28
+ * ```typescript
29
+ * import { Controller, Post, Req, Res } from '@nestjs/common';
30
+ * import { Request, Response } from 'express';
31
+ * import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nestjs';
32
+ *
33
+ * @Controller('paid/payments')
34
+ * export class PaymentsController {
35
+ * private activateOrderSyncHandler = createActivateOrderSyncRoute();
36
+ *
37
+ * @Post('activate-order-sync')
38
+ * async activateOrderSync(@Req() req: Request, @Res() res: Response) {
39
+ * return this.activateOrderSyncHandler(req, res);
40
+ * }
41
+ * }
42
+ * ```
43
+ */
44
+ export declare function createActivateOrderSyncRoute(config?: ActivateOrderSyncRouteConfig): (req: Request, res: Response) => Promise<any>;
45
+ /**
46
+ * Create an Express handler for contact creation
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import express from 'express';
51
+ * import { createContactsRoute } from '@paid-ai/paid-node/integrations/express';
52
+ *
53
+ * const app = express();
54
+ * app.post('/paid/contacts', createContactsRoute());
55
+ * ```
56
+ */
57
+ export declare function createContactsRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
58
+ /**
59
+ * Create an Express handler for fetching customer invoices
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * import express from 'express';
64
+ * import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/express';
65
+ *
66
+ * const app = express();
67
+ * app.get('/paid/customers/:customerExternalId/invoices', createCustomerInvoicesRoute());
68
+ * ```
69
+ */
70
+ export declare function createCustomerInvoicesRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
71
+ /**
72
+ * Create an Express handler for fetching a customer by external ID
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * import express from 'express';
77
+ * import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/express';
78
+ *
79
+ * const app = express();
80
+ * app.get('/paid/customers/:customerExternalId', createGetCustomerRoute());
81
+ * ```
82
+ */
83
+ export declare function createGetCustomerRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
84
+ /**
85
+ * Create an Express handler for customer creation
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * import express from 'express';
90
+ * import { createCustomersRoute } from '@paid-ai/paid-node/integrations/express';
91
+ *
92
+ * const app = express();
93
+ * app.post('/paid/customers', createCustomersRoute());
94
+ * ```
95
+ */
96
+ export declare function createCustomersRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
97
+ export interface OrdersRouteConfig extends BaseHandlerConfig {
98
+ helperOptions?: OrderOptions;
99
+ }
100
+ /**
101
+ * Create an Express handler for order creation
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * import express from 'express';
106
+ * import { createOrdersRoute } from '@paid-ai/paid-node/integrations/express';
107
+ *
108
+ * const app = express();
109
+ * app.post('/paid/orders', createOrdersRoute({ helperOptions: { autoActivate: true } }));
110
+ * ```
111
+ */
112
+ export declare function createOrdersRoute(config?: OrdersRouteConfig): (req: Request, res: Response) => Promise<any>;
113
+ /**
114
+ * Create an Express handler for invoice payment
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * import express from 'express';
119
+ * import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/express';
120
+ *
121
+ * const app = express();
122
+ * app.post('/paid/invoices/:invoiceId/pay', createPayInvoiceRoute());
123
+ * ```
124
+ */
125
+ export declare function createPayInvoiceRoute(config?: BaseHandlerConfig): (req: Request, res: Response) => Promise<any>;
126
+ export interface ProvisioningRouteConfig extends BaseHandlerConfig {
127
+ defaultAgentExternalId?: string;
128
+ orderOptions?: OrderOptions;
129
+ }
130
+ /**
131
+ * Create an Express handler for user provisioning
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * import express from 'express';
136
+ * import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/express';
137
+ *
138
+ * const app = express();
139
+ * app.post('/paid/provision', createProvisioningRoute({
140
+ * defaultAgentExternalId: process.env.PAID_AGENT_ID
141
+ * }));
142
+ * ```
143
+ */
144
+ export declare function createProvisioningRoute(config?: ProvisioningRouteConfig): (req: Request, res: Response) => Promise<any>;
145
+ export interface SetupIntentRouteConfig extends BaseHandlerConfig {
146
+ defaultReturnUrl?: string;
147
+ }
148
+ /**
149
+ * Create an Express handler for setup intent creation
150
+ *
151
+ * @example
152
+ * ```typescript
153
+ * import express from 'express';
154
+ * import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/express';
155
+ *
156
+ * const app = express();
157
+ * app.post('/paid/payments/setup-intent', createSetupIntentRoute({
158
+ * defaultReturnUrl: process.env.APP_URL + '/billing'
159
+ * }));
160
+ * ```
161
+ */
162
+ export declare function createSetupIntentRoute(config?: SetupIntentRouteConfig): (req: Request, res: Response) => Promise<any>;
@@ -0,0 +1,258 @@
1
+ /**
2
+ * ExpressJS route helpers for Paid SDK
3
+ * These functions create handlers compatible with ExpressJS controllers
4
+ */
5
+ import { createExpressJSResponseContext } from "./base-adapter.mjs";
6
+ import { createContactsHandler } from "../../controllers/contacts.mjs";
7
+ import { createCustomerInvoicesHandler } from "../../controllers/invoices.mjs";
8
+ import { createCustomersHandler, createGetCustomerHandler } from "../../controllers/customers.mjs";
9
+ import { createOrdersHandler } from "../../controllers/orders.mjs";
10
+ import { createProvisioningHandler } from "../../controllers/provision-users.mjs";
11
+ import { createActivateOrderSyncHandler, createPayInvoiceHandler, createSetupIntentHandler, } from "../../controllers/billing.mjs";
12
+ /**
13
+ * Helper to extract headers from Express Request
14
+ */
15
+ function extractHeaders(req) {
16
+ const headers = {};
17
+ Object.entries(req.headers).forEach(([key, value]) => {
18
+ if (typeof value === "string") {
19
+ headers[key] = value;
20
+ }
21
+ else if (Array.isArray(value)) {
22
+ headers[key] = value.join(", ");
23
+ }
24
+ });
25
+ return headers;
26
+ }
27
+ /**
28
+ * Create an Express handler for synchronous order activation
29
+ *
30
+ * Use this in your Express app to handle order activation with payment.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * import express from 'express';
35
+ * import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/express';
36
+ *
37
+ * const app = express();
38
+ * const activateOrderSyncHandler = createActivateOrderSyncRoute();
39
+ *
40
+ * app.post('/paid/payments/activate-order-sync', activateOrderSyncHandler);
41
+ * ```
42
+ *
43
+ * @example With NestJS
44
+ * ```typescript
45
+ * import { Controller, Post, Req, Res } from '@nestjs/common';
46
+ * import { Request, Response } from 'express';
47
+ * import { createActivateOrderSyncRoute } from '@paid-ai/paid-node/integrations/nestjs';
48
+ *
49
+ * @Controller('paid/payments')
50
+ * export class PaymentsController {
51
+ * private activateOrderSyncHandler = createActivateOrderSyncRoute();
52
+ *
53
+ * @Post('activate-order-sync')
54
+ * async activateOrderSync(@Req() req: Request, @Res() res: Response) {
55
+ * return this.activateOrderSyncHandler(req, res);
56
+ * }
57
+ * }
58
+ * ```
59
+ */
60
+ export function createActivateOrderSyncRoute(config = {}) {
61
+ const handler = createActivateOrderSyncHandler(config.defaultReturnUrl);
62
+ return (req, res) => {
63
+ return handler({
64
+ body: req.body,
65
+ headers: extractHeaders(req),
66
+ method: "POST",
67
+ params: req.params,
68
+ }, createExpressJSResponseContext(res), config);
69
+ };
70
+ }
71
+ /**
72
+ * Create an Express handler for contact creation
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * import express from 'express';
77
+ * import { createContactsRoute } from '@paid-ai/paid-node/integrations/express';
78
+ *
79
+ * const app = express();
80
+ * app.post('/paid/contacts', createContactsRoute());
81
+ * ```
82
+ */
83
+ export function createContactsRoute(config = {}) {
84
+ const handler = createContactsHandler();
85
+ return (req, res) => {
86
+ return handler({
87
+ body: req.body,
88
+ headers: extractHeaders(req),
89
+ method: "POST",
90
+ params: req.params,
91
+ }, createExpressJSResponseContext(res), config);
92
+ };
93
+ }
94
+ /**
95
+ * Create an Express handler for fetching customer invoices
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * import express from 'express';
100
+ * import { createCustomerInvoicesRoute } from '@paid-ai/paid-node/integrations/express';
101
+ *
102
+ * const app = express();
103
+ * app.get('/paid/customers/:customerExternalId/invoices', createCustomerInvoicesRoute());
104
+ * ```
105
+ */
106
+ export function createCustomerInvoicesRoute(config = {}) {
107
+ const handler = createCustomerInvoicesHandler();
108
+ return (req, res) => {
109
+ return handler({
110
+ body: req.body,
111
+ headers: extractHeaders(req),
112
+ method: "GET",
113
+ params: req.params,
114
+ }, createExpressJSResponseContext(res), config);
115
+ };
116
+ }
117
+ /**
118
+ * Create an Express handler for fetching a customer by external ID
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * import express from 'express';
123
+ * import { createGetCustomerRoute } from '@paid-ai/paid-node/integrations/express';
124
+ *
125
+ * const app = express();
126
+ * app.get('/paid/customers/:customerExternalId', createGetCustomerRoute());
127
+ * ```
128
+ */
129
+ export function createGetCustomerRoute(config = {}) {
130
+ const handler = createGetCustomerHandler();
131
+ return (req, res) => {
132
+ return handler({
133
+ body: req.body,
134
+ headers: extractHeaders(req),
135
+ method: "GET",
136
+ params: req.params,
137
+ }, createExpressJSResponseContext(res), config);
138
+ };
139
+ }
140
+ /**
141
+ * Create an Express handler for customer creation
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * import express from 'express';
146
+ * import { createCustomersRoute } from '@paid-ai/paid-node/integrations/express';
147
+ *
148
+ * const app = express();
149
+ * app.post('/paid/customers', createCustomersRoute());
150
+ * ```
151
+ */
152
+ export function createCustomersRoute(config = {}) {
153
+ const handler = createCustomersHandler();
154
+ return (req, res) => {
155
+ return handler({
156
+ body: req.body,
157
+ headers: extractHeaders(req),
158
+ method: "POST",
159
+ params: req.params,
160
+ }, createExpressJSResponseContext(res), config);
161
+ };
162
+ }
163
+ /**
164
+ * Create an Express handler for order creation
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * import express from 'express';
169
+ * import { createOrdersRoute } from '@paid-ai/paid-node/integrations/express';
170
+ *
171
+ * const app = express();
172
+ * app.post('/paid/orders', createOrdersRoute({ helperOptions: { autoActivate: true } }));
173
+ * ```
174
+ */
175
+ export function createOrdersRoute(config = {}) {
176
+ const handler = createOrdersHandler(config.helperOptions);
177
+ return (req, res) => {
178
+ return handler({
179
+ body: req.body,
180
+ headers: extractHeaders(req),
181
+ method: "POST",
182
+ params: req.params,
183
+ }, createExpressJSResponseContext(res), config);
184
+ };
185
+ }
186
+ /**
187
+ * Create an Express handler for invoice payment
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * import express from 'express';
192
+ * import { createPayInvoiceRoute } from '@paid-ai/paid-node/integrations/express';
193
+ *
194
+ * const app = express();
195
+ * app.post('/paid/invoices/:invoiceId/pay', createPayInvoiceRoute());
196
+ * ```
197
+ */
198
+ export function createPayInvoiceRoute(config = {}) {
199
+ const handler = createPayInvoiceHandler();
200
+ return (req, res) => {
201
+ return handler({
202
+ body: req.body,
203
+ headers: extractHeaders(req),
204
+ method: "POST",
205
+ params: req.params,
206
+ }, createExpressJSResponseContext(res), config);
207
+ };
208
+ }
209
+ /**
210
+ * Create an Express handler for user provisioning
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * import express from 'express';
215
+ * import { createProvisioningRoute } from '@paid-ai/paid-node/integrations/express';
216
+ *
217
+ * const app = express();
218
+ * app.post('/paid/provision', createProvisioningRoute({
219
+ * defaultAgentExternalId: process.env.PAID_AGENT_ID
220
+ * }));
221
+ * ```
222
+ */
223
+ export function createProvisioningRoute(config = {}) {
224
+ const handler = createProvisioningHandler(config.orderOptions, config.defaultAgentExternalId);
225
+ return (req, res) => {
226
+ return handler({
227
+ body: req.body,
228
+ headers: extractHeaders(req),
229
+ method: "POST",
230
+ params: req.params,
231
+ }, createExpressJSResponseContext(res), config);
232
+ };
233
+ }
234
+ /**
235
+ * Create an Express handler for setup intent creation
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * import express from 'express';
240
+ * import { createSetupIntentRoute } from '@paid-ai/paid-node/integrations/express';
241
+ *
242
+ * const app = express();
243
+ * app.post('/paid/payments/setup-intent', createSetupIntentRoute({
244
+ * defaultReturnUrl: process.env.APP_URL + '/billing'
245
+ * }));
246
+ * ```
247
+ */
248
+ export function createSetupIntentRoute(config = {}) {
249
+ const handler = createSetupIntentHandler(config.defaultReturnUrl);
250
+ return (req, res) => {
251
+ return handler({
252
+ body: req.body,
253
+ headers: extractHeaders(req),
254
+ method: "POST",
255
+ params: req.params,
256
+ }, createExpressJSResponseContext(res), config);
257
+ };
258
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * NestJS integration for Paid SDK
3
+ *
4
+ * NestJS uses Express under the hood, so this is a re-export of the Express adapter.
5
+ * All functionality is identical to the Express adapter.
6
+ */
7
+ export * from "../expressjs/index.mjs";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * NestJS integration for Paid SDK
3
+ *
4
+ * NestJS uses Express under the hood, so this is a re-export of the Express adapter.
5
+ * All functionality is identical to the Express adapter.
6
+ */
7
+ export * from "../expressjs/index.mjs";
@@ -0,0 +1,10 @@
1
+ import type * as openai from "openai";
2
+ import type * as anthropic from "@anthropic-ai/sdk";
3
+ import type * as bedrock from "@aws-sdk/client-bedrock-runtime";
4
+ interface SupportedLibraries {
5
+ openai?: typeof openai.OpenAI;
6
+ anthropic?: typeof anthropic.Anthropic;
7
+ bedrock?: typeof bedrock;
8
+ }
9
+ export declare function paidAutoInstrument(libraries?: SupportedLibraries): void;
10
+ export {};
@@ -0,0 +1,54 @@
1
+ import { registerInstrumentations } from "@opentelemetry/instrumentation";
2
+ import { OpenAIInstrumentation } from "@arizeai/openinference-instrumentation-openai";
3
+ import { BedrockInstrumentation } from "@traceloop/instrumentation-bedrock";
4
+ import { AnthropicInstrumentation } from "@arizeai/openinference-instrumentation-anthropic";
5
+ import { getPaidTracerProvider, initializeTracing, logger } from "./tracing";
6
+ let IS_INITIALIZED = false;
7
+ const getInstrumentations = (tracerProvider) => {
8
+ const instrumentations = [
9
+ new OpenAIInstrumentation({ tracerProvider }),
10
+ new AnthropicInstrumentation({ tracerProvider }),
11
+ new BedrockInstrumentation(),
12
+ ];
13
+ return instrumentations;
14
+ };
15
+ const getManualInstrumentations = (tracerProvider, libraries) => {
16
+ const instrumentations = [];
17
+ if (libraries.openai) {
18
+ const openaiInstrumentation = new OpenAIInstrumentation({ tracerProvider });
19
+ instrumentations.push(openaiInstrumentation);
20
+ openaiInstrumentation.manuallyInstrument(libraries.openai);
21
+ }
22
+ if (libraries.anthropic) {
23
+ const anthropicInstrumentation = new AnthropicInstrumentation({ tracerProvider });
24
+ instrumentations.push(anthropicInstrumentation);
25
+ anthropicInstrumentation.manuallyInstrument(libraries.anthropic);
26
+ }
27
+ if (libraries.bedrock) {
28
+ const bedrockInstrumentation = new BedrockInstrumentation();
29
+ instrumentations.push(bedrockInstrumentation);
30
+ bedrockInstrumentation.manuallyInstrument(libraries.bedrock);
31
+ }
32
+ return instrumentations;
33
+ };
34
+ export function paidAutoInstrument(libraries) {
35
+ if (IS_INITIALIZED) {
36
+ logger.info("Auto instrumentation is already initialized");
37
+ return;
38
+ }
39
+ initializeTracing(); // try initializing tracing
40
+ const tracerProvider = getPaidTracerProvider();
41
+ if (!tracerProvider) {
42
+ logger.error("Could not get tracer provider, make sure you ran 'initializeTracing()' or check your environment variables");
43
+ return;
44
+ }
45
+ const isManualInstrumentation = libraries && Object.keys(libraries).length > 0;
46
+ const instrumentations = isManualInstrumentation
47
+ ? getManualInstrumentations(tracerProvider, libraries)
48
+ : getInstrumentations(tracerProvider);
49
+ registerInstrumentations({
50
+ instrumentations,
51
+ tracerProvider,
52
+ });
53
+ IS_INITIALIZED = true;
54
+ }
@@ -0,0 +1,4 @@
1
+ import { getPaidTracer, getPaidTracerProvider, initializeTracing, trace } from "./tracing.mjs";
2
+ import { paidAutoInstrument } from "./autoInstrumentation.mjs";
3
+ import { signal } from "./signal.mjs";
4
+ export { getPaidTracer, getPaidTracerProvider, initializeTracing, trace, signal, paidAutoInstrument };
@@ -0,0 +1,4 @@
1
+ import { getPaidTracer, getPaidTracerProvider, initializeTracing, trace } from "./tracing.mjs";
2
+ import { paidAutoInstrument } from "./autoInstrumentation.mjs";
3
+ import { signal } from "./signal.mjs";
4
+ export { getPaidTracer, getPaidTracerProvider, initializeTracing, trace, signal, paidAutoInstrument };
@@ -1 +1,18 @@
1
- export declare function _signal(eventName: string, enableCostTracing: boolean, data?: Record<string, any>): void;
1
+ /**
2
+ * Sends Paid signal. Needs to be called as part of callback to trace().
3
+ * When enableCostTracing flag is on, signal is associated
4
+ * with cost traces from the same Paid.trace() context.
5
+ *
6
+ * @param eventName - The name of the signal.
7
+ * @param enableCostTracing - Whether to associate this signal with cost traces
8
+ * from the current Paid.trace() context (default: false)
9
+ * @param data - Optional additional data to include with the signal
10
+ *
11
+ * @remarks
12
+ * When enableCostTracing is on, the signal will be associated with cost
13
+ * traces within the same Paid.trace() context.
14
+ * It is advised to only make one call to this function
15
+ * with enableCostTracing per Paid.trace() context.
16
+ * Otherwise, there will be multiple signals that refer to the same costs.
17
+ */
18
+ export declare function signal(eventName: string, enableCostTracing?: boolean, data?: Record<string, any>): void;
@@ -1,21 +1,38 @@
1
1
  import { SpanStatusCode } from "@opentelemetry/api";
2
- import { getCustomerIdStorage, getAgentIdStorage, getTokenStorage } from "./tracing.mjs";
3
- import { paidTracer } from "./tracing.mjs";
4
- export function _signal(eventName, enableCostTracing, data) {
5
- if (!eventName) {
6
- throw new Error("Event name is required for signal.");
2
+ import { getPaidTracer, getToken } from "./tracing.mjs";
3
+ import { getTracingContext } from "./tracingContext.mjs";
4
+ /**
5
+ * Sends Paid signal. Needs to be called as part of callback to trace().
6
+ * When enableCostTracing flag is on, signal is associated
7
+ * with cost traces from the same Paid.trace() context.
8
+ *
9
+ * @param eventName - The name of the signal.
10
+ * @param enableCostTracing - Whether to associate this signal with cost traces
11
+ * from the current Paid.trace() context (default: false)
12
+ * @param data - Optional additional data to include with the signal
13
+ *
14
+ * @remarks
15
+ * When enableCostTracing is on, the signal will be associated with cost
16
+ * traces within the same Paid.trace() context.
17
+ * It is advised to only make one call to this function
18
+ * with enableCostTracing per Paid.trace() context.
19
+ * Otherwise, there will be multiple signals that refer to the same costs.
20
+ */
21
+ export function signal(eventName, enableCostTracing = false, data) {
22
+ const paidTracer = getPaidTracer();
23
+ const token = getToken();
24
+ const { externalCustomerId, externalProductId } = getTracingContext();
25
+ if (!token || !paidTracer) {
26
+ throw new Error(`Tracing is not initialized. Make sure you called 'initializeTracing()'`);
7
27
  }
8
- const externalCustomerId = getCustomerIdStorage();
9
- const externalAgentId = getAgentIdStorage();
10
- const token = getTokenStorage();
11
- if (!externalCustomerId || !externalAgentId || !token) {
12
- throw new Error(`Missing some of: external_customer_id: ${externalCustomerId}, external_agent_id: ${externalAgentId}, or token. Make sure to call signal() within trace()`);
28
+ if (!externalCustomerId || !externalProductId) {
29
+ throw new Error(`Missing some of: external_customer_id: ${externalCustomerId}, external_product_id: ${externalProductId}, or token. Make sure to call signal() within trace()`);
13
30
  }
14
31
  paidTracer.startActiveSpan("trace.signal", (span) => {
15
32
  try {
16
33
  const attributes = {
17
34
  external_customer_id: externalCustomerId,
18
- external_agent_id: externalAgentId,
35
+ external_agent_id: externalProductId,
19
36
  event_name: eventName,
20
37
  token: token,
21
38
  };
@@ -34,7 +51,6 @@ export function _signal(eventName, enableCostTracing, data) {
34
51
  attributes["data"] = JSON.stringify(data);
35
52
  }
36
53
  span.setAttributes(attributes);
37
- // Mark span as successful
38
54
  span.setStatus({ code: SpanStatusCode.OK });
39
55
  }
40
56
  catch (error) {
@@ -0,0 +1,10 @@
1
+ import { Context } from "@opentelemetry/api";
2
+ import { SpanProcessor, Span } from "@opentelemetry/sdk-trace-base";
3
+ export declare class PaidSpanProcessor implements SpanProcessor {
4
+ private static readonly SPAN_NAME_PREFIX;
5
+ private static readonly PROMPT_ATTRIBUTES_SUBSTRINGS;
6
+ onStart(span: Span, _parentContext?: Context): void;
7
+ onEnd(): void;
8
+ shutdown(): Promise<void>;
9
+ forceFlush(): Promise<void>;
10
+ }
@@ -0,0 +1,78 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { getTracingContext } from "./tracingContext.mjs";
11
+ import { getToken } from "./tracing.mjs";
12
+ export class PaidSpanProcessor {
13
+ onStart(span, _parentContext) {
14
+ const { name } = span;
15
+ const { storePrompt, externalCustomerId, externalProductId: externalAgentId } = getTracingContext();
16
+ if (!storePrompt) {
17
+ const originalSetAttribute = span.setAttribute;
18
+ span.setAttribute = function (key, value) {
19
+ const isPromptRelated = PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS.some((substr) => key.includes(substr));
20
+ if (isPromptRelated)
21
+ return this;
22
+ return originalSetAttribute.call(this, key, value);
23
+ };
24
+ const originalSetAttributes = span.setAttributes;
25
+ span.setAttributes = function (attributes) {
26
+ const newAttributes = Object.entries(attributes).reduce((acc, [key, value]) => {
27
+ const isPromptRelated = PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS.some((substr) => key.includes(substr));
28
+ if (isPromptRelated)
29
+ return acc;
30
+ return Object.assign(Object.assign({}, acc), { [key]: value });
31
+ }, {});
32
+ return originalSetAttributes.call(this, newAttributes);
33
+ };
34
+ }
35
+ if (name && !name.startsWith(PaidSpanProcessor.SPAN_NAME_PREFIX)) {
36
+ span.updateName(`${PaidSpanProcessor.SPAN_NAME_PREFIX}${name}`);
37
+ }
38
+ if (externalCustomerId) {
39
+ span.setAttribute("external_customer_id", externalCustomerId);
40
+ }
41
+ if (externalAgentId) {
42
+ span.setAttribute("external_agent_id", externalAgentId);
43
+ }
44
+ const token = getToken();
45
+ if (token) {
46
+ span.setAttribute("token", token);
47
+ }
48
+ }
49
+ onEnd() {
50
+ // mutating this span object doesn't do anything
51
+ // so we achieve filtering within the onStart method by monkey patching
52
+ // setAttribute method
53
+ return;
54
+ }
55
+ shutdown() {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ return;
58
+ });
59
+ }
60
+ forceFlush() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ return;
63
+ });
64
+ }
65
+ }
66
+ PaidSpanProcessor.SPAN_NAME_PREFIX = "paid.trace.";
67
+ PaidSpanProcessor.PROMPT_ATTRIBUTES_SUBSTRINGS = [
68
+ "gen_ai.completion",
69
+ "gen_ai.request.messages",
70
+ "gen_ai.response.messages",
71
+ "llm.output_message",
72
+ "llm.input_message",
73
+ "llm.invocation_parameters",
74
+ "gen_ai.prompt",
75
+ "langchain.prompt",
76
+ "output.value",
77
+ "input.value",
78
+ ];