@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.
- package/README.md +118 -36
- package/dist/cjs/Client.d.ts +35 -3
- package/dist/cjs/Client.js +57 -19
- package/dist/cjs/api/errors/InternalServerError.d.ts +9 -0
- package/dist/cjs/api/errors/InternalServerError.js +52 -0
- package/dist/cjs/api/errors/index.d.ts +1 -0
- package/dist/cjs/api/errors/index.js +1 -0
- package/dist/cjs/api/index.d.ts +1 -1
- package/dist/cjs/api/index.js +1 -1
- package/dist/cjs/api/resources/agents/client/Client.d.ts +16 -0
- package/dist/cjs/api/resources/agents/client/Client.js +16 -0
- package/dist/cjs/api/resources/customers/client/Client.d.ts +38 -0
- package/dist/cjs/api/resources/customers/client/Client.js +164 -0
- package/dist/cjs/api/resources/customers/client/requests/CustomerCreate.d.ts +2 -0
- package/dist/cjs/api/resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.d.ts +30 -0
- package/dist/cjs/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.d.ts +30 -0
- package/dist/cjs/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.js +5 -0
- package/dist/cjs/api/resources/customers/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/resources/index.d.ts +8 -1
- package/dist/cjs/api/resources/index.js +9 -2
- package/dist/cjs/api/resources/orders/client/requests/OrderCreate.d.ts +2 -0
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +0 -2
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +0 -2
- package/dist/cjs/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.ts +0 -2
- package/dist/cjs/api/resources/plans/client/Client.d.ts +75 -0
- package/dist/cjs/api/resources/plans/client/Client.js +272 -0
- package/dist/cjs/api/resources/plans/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/plans/client/index.js +17 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansGetUsageRequest.d.ts +35 -0
- package/dist/cjs/api/resources/plans/client/requests/PlansGetUsageRequest.js +5 -0
- package/dist/cjs/api/resources/plans/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/plans/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/plans/index.d.ts +1 -0
- package/dist/cjs/api/resources/plans/index.js +17 -0
- package/dist/cjs/api/resources/products/client/Client.d.ts +109 -0
- package/dist/cjs/api/resources/products/client/Client.js +470 -0
- package/dist/cjs/api/resources/products/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/products/client/index.js +17 -0
- package/dist/cjs/api/resources/products/client/requests/ProductCreate.d.ts +29 -0
- package/dist/cjs/api/resources/products/client/requests/ProductCreate.js +14 -0
- package/dist/cjs/api/resources/products/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/products/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/products/index.d.ts +1 -0
- package/dist/cjs/api/resources/products/index.js +17 -0
- package/dist/cjs/api/resources/traces/client/Client.d.ts +52 -0
- package/dist/cjs/api/resources/traces/client/Client.js +166 -0
- package/dist/cjs/api/resources/traces/client/index.d.ts +1 -0
- package/dist/cjs/api/resources/traces/client/index.js +17 -0
- package/dist/cjs/api/resources/traces/client/requests/GetTracesRequest.d.ts +50 -0
- package/dist/cjs/api/resources/traces/client/requests/GetTracesRequest.js +5 -0
- package/dist/cjs/api/resources/traces/client/requests/index.d.ts +1 -0
- package/dist/cjs/api/resources/traces/client/requests/index.js +2 -0
- package/dist/cjs/api/resources/traces/index.d.ts +1 -0
- package/dist/cjs/api/resources/traces/index.js +17 -0
- package/dist/cjs/api/resources/usage/client/Client.d.ts +47 -0
- package/dist/cjs/api/resources/usage/client/Client.js +146 -0
- package/dist/cjs/api/resources/usage/client/requests/UsageCheckUsageRequest.d.ts +28 -0
- package/dist/cjs/api/resources/usage/client/requests/UsageCheckUsageRequest.js +5 -0
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +29 -0
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.js +5 -0
- package/dist/cjs/api/resources/usage/client/requests/index.d.ts +2 -0
- package/dist/cjs/api/resources/usage/index.d.ts +1 -0
- package/dist/cjs/api/resources/usage/index.js +1 -0
- package/dist/cjs/api/resources/usage/types/UsageCheckUsageResponse.d.ts +17 -0
- package/dist/cjs/api/resources/usage/types/UsageCheckUsageResponse.js +5 -0
- package/dist/cjs/api/resources/usage/types/index.d.ts +1 -0
- package/dist/cjs/api/resources/usage/types/index.js +17 -0
- package/dist/cjs/api/types/CostAmount.d.ts +12 -0
- package/dist/cjs/api/types/CostAmount.js +5 -0
- package/dist/cjs/api/types/CostTrace.d.ts +22 -0
- package/dist/cjs/api/types/CostTrace.js +5 -0
- package/dist/cjs/api/types/CostTracesResponse.d.ts +11 -0
- package/dist/cjs/api/types/CostTracesResponse.js +5 -0
- package/dist/cjs/api/types/Customer.d.ts +2 -0
- package/dist/cjs/api/types/CustomerUpdate.d.ts +2 -0
- package/dist/cjs/api/types/OrderLineAttributeCreateOne.d.ts +4 -0
- package/dist/cjs/api/types/OrderLineAttributeCreateOne.js +5 -0
- package/dist/cjs/api/types/OrderLineCreate.d.ts +10 -4
- package/dist/cjs/api/types/PaginationMeta.d.ts +28 -0
- package/dist/cjs/api/types/PaginationMeta.js +5 -0
- package/dist/cjs/api/types/Plan.d.ts +58 -0
- package/dist/cjs/api/types/Plan.js +5 -0
- package/dist/cjs/api/types/PlanGroup.d.ts +23 -0
- package/dist/cjs/api/types/PlanGroup.js +5 -0
- package/dist/cjs/api/types/Product.d.ts +36 -0
- package/dist/cjs/api/types/Product.js +14 -0
- package/dist/cjs/api/types/ProductUpdate.d.ts +23 -0
- package/dist/cjs/api/types/ProductUpdate.js +14 -0
- package/dist/cjs/api/types/Signal.d.ts +7 -2
- package/dist/cjs/api/types/SignalV2.d.ts +22 -0
- package/dist/cjs/api/types/SignalV2.js +5 -0
- package/dist/cjs/api/types/Trace.d.ts +26 -0
- package/dist/cjs/api/types/Trace.js +5 -0
- package/dist/cjs/api/types/TracesResponse.d.ts +11 -0
- package/dist/cjs/api/types/TracesResponse.js +5 -0
- package/dist/cjs/api/types/UsagePaginationMeta.d.ts +16 -0
- package/dist/cjs/api/types/UsagePaginationMeta.js +5 -0
- package/dist/cjs/api/types/UsageSummariesResponse.d.ts +11 -0
- package/dist/cjs/api/types/UsageSummariesResponse.js +5 -0
- package/dist/cjs/api/types/UsageSummary.d.ts +58 -0
- package/dist/cjs/api/types/UsageSummary.js +5 -0
- package/dist/cjs/api/types/index.d.ts +15 -1
- package/dist/cjs/api/types/index.js +15 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/integrations/adapters/expressjs/base-adapter.d.ts +17 -0
- package/dist/cjs/integrations/adapters/expressjs/base-adapter.js +71 -0
- package/dist/cjs/integrations/adapters/expressjs/index.d.ts +6 -0
- package/dist/cjs/integrations/adapters/expressjs/index.js +20 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +162 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.js +269 -0
- package/dist/cjs/integrations/adapters/nestjs/index.d.ts +7 -0
- package/dist/cjs/integrations/adapters/nestjs/index.js +23 -0
- package/dist/cjs/tracing/autoInstrumentation.d.ts +10 -0
- package/dist/cjs/tracing/autoInstrumentation.js +57 -0
- package/dist/cjs/tracing/index.d.ts +4 -0
- package/dist/cjs/tracing/index.js +12 -0
- package/dist/cjs/tracing/signal.d.ts +18 -1
- package/dist/cjs/tracing/signal.js +29 -13
- package/dist/cjs/tracing/spanProcessor.d.ts +10 -0
- package/dist/cjs/tracing/spanProcessor.js +82 -0
- package/dist/cjs/tracing/tracing.d.ts +12 -6
- package/dist/cjs/tracing/tracing.js +65 -58
- package/dist/cjs/tracing/tracingContext.d.ts +8 -0
- package/dist/cjs/tracing/tracingContext.js +28 -0
- package/dist/cjs/tracing/wrappers/anthropicWrapper.js +11 -7
- package/dist/cjs/tracing/wrappers/langchainCallback.js +11 -7
- package/dist/cjs/tracing/wrappers/mistralWrapper.js +11 -7
- package/dist/cjs/tracing/wrappers/openAiWrapper.js +24 -23
- package/dist/cjs/tracing/wrappers/vercelAIWrapper.js +68 -43
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Client.d.mts +35 -3
- package/dist/esm/Client.mjs +54 -16
- package/dist/esm/api/errors/InternalServerError.d.mts +9 -0
- package/dist/esm/api/errors/InternalServerError.mjs +15 -0
- package/dist/esm/api/errors/index.d.mts +1 -0
- package/dist/esm/api/errors/index.mjs +1 -0
- package/dist/esm/api/index.d.mts +1 -1
- package/dist/esm/api/index.mjs +1 -1
- package/dist/esm/api/resources/agents/client/Client.d.mts +16 -0
- package/dist/esm/api/resources/agents/client/Client.mjs +16 -0
- package/dist/esm/api/resources/customers/client/Client.d.mts +38 -0
- package/dist/esm/api/resources/customers/client/Client.mjs +164 -0
- package/dist/esm/api/resources/customers/client/requests/CustomerCreate.d.mts +2 -0
- package/dist/esm/api/resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.d.mts +30 -0
- package/dist/esm/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.d.mts +30 -0
- package/dist/esm/api/resources/customers/client/requests/CustomersGetUsageByExternalIdRequest.mjs +4 -0
- package/dist/esm/api/resources/customers/client/requests/index.d.mts +2 -0
- package/dist/esm/api/resources/index.d.mts +8 -1
- package/dist/esm/api/resources/index.mjs +8 -1
- package/dist/esm/api/resources/orders/client/requests/OrderCreate.d.mts +2 -0
- package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +0 -2
- package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +0 -2
- package/dist/esm/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.mts +0 -2
- package/dist/esm/api/resources/plans/client/Client.d.mts +75 -0
- package/dist/esm/api/resources/plans/client/Client.mjs +232 -0
- package/dist/esm/api/resources/plans/client/index.d.mts +1 -0
- package/dist/esm/api/resources/plans/client/index.mjs +1 -0
- package/dist/esm/api/resources/plans/client/requests/PlansGetUsageRequest.d.mts +35 -0
- package/dist/esm/api/resources/plans/client/requests/PlansGetUsageRequest.mjs +4 -0
- package/dist/esm/api/resources/plans/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/plans/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/plans/index.d.mts +1 -0
- package/dist/esm/api/resources/plans/index.mjs +1 -0
- package/dist/esm/api/resources/products/client/Client.d.mts +109 -0
- package/dist/esm/api/resources/products/client/Client.mjs +430 -0
- package/dist/esm/api/resources/products/client/index.d.mts +1 -0
- package/dist/esm/api/resources/products/client/index.mjs +1 -0
- package/dist/esm/api/resources/products/client/requests/ProductCreate.d.mts +29 -0
- package/dist/esm/api/resources/products/client/requests/ProductCreate.mjs +11 -0
- package/dist/esm/api/resources/products/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/products/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/products/index.d.mts +1 -0
- package/dist/esm/api/resources/products/index.mjs +1 -0
- package/dist/esm/api/resources/traces/client/Client.d.mts +52 -0
- package/dist/esm/api/resources/traces/client/Client.mjs +126 -0
- package/dist/esm/api/resources/traces/client/index.d.mts +1 -0
- package/dist/esm/api/resources/traces/client/index.mjs +1 -0
- package/dist/esm/api/resources/traces/client/requests/GetTracesRequest.d.mts +50 -0
- package/dist/esm/api/resources/traces/client/requests/GetTracesRequest.mjs +4 -0
- package/dist/esm/api/resources/traces/client/requests/index.d.mts +1 -0
- package/dist/esm/api/resources/traces/client/requests/index.mjs +1 -0
- package/dist/esm/api/resources/traces/index.d.mts +1 -0
- package/dist/esm/api/resources/traces/index.mjs +1 -0
- package/dist/esm/api/resources/usage/client/Client.d.mts +47 -0
- package/dist/esm/api/resources/usage/client/Client.mjs +146 -0
- package/dist/esm/api/resources/usage/client/requests/UsageCheckUsageRequest.d.mts +28 -0
- package/dist/esm/api/resources/usage/client/requests/UsageCheckUsageRequest.mjs +4 -0
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +29 -0
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.mjs +4 -0
- package/dist/esm/api/resources/usage/client/requests/index.d.mts +2 -0
- package/dist/esm/api/resources/usage/index.d.mts +1 -0
- package/dist/esm/api/resources/usage/index.mjs +1 -0
- package/dist/esm/api/resources/usage/types/UsageCheckUsageResponse.d.mts +17 -0
- package/dist/esm/api/resources/usage/types/UsageCheckUsageResponse.mjs +4 -0
- package/dist/esm/api/resources/usage/types/index.d.mts +1 -0
- package/dist/esm/api/resources/usage/types/index.mjs +1 -0
- package/dist/esm/api/types/CostAmount.d.mts +12 -0
- package/dist/esm/api/types/CostAmount.mjs +4 -0
- package/dist/esm/api/types/CostTrace.d.mts +22 -0
- package/dist/esm/api/types/CostTrace.mjs +4 -0
- package/dist/esm/api/types/CostTracesResponse.d.mts +11 -0
- package/dist/esm/api/types/CostTracesResponse.mjs +4 -0
- package/dist/esm/api/types/Customer.d.mts +2 -0
- package/dist/esm/api/types/CustomerUpdate.d.mts +2 -0
- package/dist/esm/api/types/OrderLineAttributeCreateOne.d.mts +4 -0
- package/dist/esm/api/types/OrderLineAttributeCreateOne.mjs +4 -0
- package/dist/esm/api/types/OrderLineCreate.d.mts +10 -4
- package/dist/esm/api/types/PaginationMeta.d.mts +28 -0
- package/dist/esm/api/types/PaginationMeta.mjs +4 -0
- package/dist/esm/api/types/Plan.d.mts +58 -0
- package/dist/esm/api/types/Plan.mjs +4 -0
- package/dist/esm/api/types/PlanGroup.d.mts +23 -0
- package/dist/esm/api/types/PlanGroup.mjs +4 -0
- package/dist/esm/api/types/Product.d.mts +36 -0
- package/dist/esm/api/types/Product.mjs +11 -0
- package/dist/esm/api/types/ProductUpdate.d.mts +23 -0
- package/dist/esm/api/types/ProductUpdate.mjs +11 -0
- package/dist/esm/api/types/Signal.d.mts +7 -2
- package/dist/esm/api/types/SignalV2.d.mts +22 -0
- package/dist/esm/api/types/SignalV2.mjs +4 -0
- package/dist/esm/api/types/Trace.d.mts +26 -0
- package/dist/esm/api/types/Trace.mjs +4 -0
- package/dist/esm/api/types/TracesResponse.d.mts +11 -0
- package/dist/esm/api/types/TracesResponse.mjs +4 -0
- package/dist/esm/api/types/UsagePaginationMeta.d.mts +16 -0
- package/dist/esm/api/types/UsagePaginationMeta.mjs +4 -0
- package/dist/esm/api/types/UsageSummariesResponse.d.mts +11 -0
- package/dist/esm/api/types/UsageSummariesResponse.mjs +4 -0
- package/dist/esm/api/types/UsageSummary.d.mts +58 -0
- package/dist/esm/api/types/UsageSummary.mjs +4 -0
- package/dist/esm/api/types/index.d.mts +15 -1
- package/dist/esm/api/types/index.mjs +15 -1
- package/dist/esm/index.d.mts +1 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/integrations/adapters/expressjs/base-adapter.d.mts +17 -0
- package/dist/esm/integrations/adapters/expressjs/base-adapter.mjs +67 -0
- package/dist/esm/integrations/adapters/expressjs/index.d.mts +6 -0
- package/dist/esm/integrations/adapters/expressjs/index.mjs +6 -0
- package/dist/esm/integrations/adapters/expressjs/routes.d.mts +162 -0
- package/dist/esm/integrations/adapters/expressjs/routes.mjs +258 -0
- package/dist/esm/integrations/adapters/nestjs/index.d.mts +7 -0
- package/dist/esm/integrations/adapters/nestjs/index.mjs +7 -0
- package/dist/esm/tracing/autoInstrumentation.d.mts +10 -0
- package/dist/esm/tracing/autoInstrumentation.mjs +54 -0
- package/dist/esm/tracing/index.d.mts +4 -0
- package/dist/esm/tracing/index.mjs +4 -0
- package/dist/esm/tracing/signal.d.mts +18 -1
- package/dist/esm/tracing/signal.mjs +28 -12
- package/dist/esm/tracing/spanProcessor.d.mts +10 -0
- package/dist/esm/tracing/spanProcessor.mjs +78 -0
- package/dist/esm/tracing/tracing.d.mts +12 -6
- package/dist/esm/tracing/tracing.mjs +59 -52
- package/dist/esm/tracing/tracingContext.d.mts +8 -0
- package/dist/esm/tracing/tracingContext.mjs +23 -0
- package/dist/esm/tracing/wrappers/anthropicWrapper.mjs +11 -7
- package/dist/esm/tracing/wrappers/langchainCallback.mjs +11 -7
- package/dist/esm/tracing/wrappers/mistralWrapper.mjs +11 -7
- package/dist/esm/tracing/wrappers/openAiWrapper.mjs +24 -23
- package/dist/esm/tracing/wrappers/vercelAIWrapper.mjs +68 -43
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +41 -4
- package/reference.md +1147 -153
- package/dist/cjs/api/types/OrderLineAttributeCreate.d.ts +0 -12
- package/dist/esm/api/types/OrderLineAttributeCreate.d.mts +0 -12
- /package/dist/cjs/api/{types/OrderLineAttributeCreate.js → resources/customers/client/requests/CustomersGetCostsByExternalIdRequest.js} +0 -0
- /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,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
|
-
|
|
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 {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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:
|
|
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
|
+
];
|