@paid-ai/paid-node 1.0.0 → 1.0.1-alpha1
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/cjs/BaseClient.d.ts +4 -17
- package/dist/cjs/BaseClient.js +0 -59
- package/dist/cjs/Client.d.ts +28 -28
- package/dist/cjs/Client.js +52 -11
- package/dist/cjs/api/errors/BadRequestError.js +1 -5
- package/dist/cjs/api/errors/ForbiddenError.js +1 -5
- package/dist/cjs/api/errors/InternalServerError.js +1 -5
- package/dist/cjs/api/errors/NotFoundError.js +1 -5
- package/dist/cjs/api/resources/agents/client/Client.d.ts +23 -22
- package/dist/cjs/api/resources/agents/client/Client.js +158 -55
- package/dist/cjs/api/resources/contacts/client/Client.d.ts +19 -18
- package/dist/cjs/api/resources/contacts/client/Client.js +122 -43
- package/dist/cjs/api/resources/customers/client/Client.d.ts +37 -36
- package/dist/cjs/api/resources/customers/client/Client.js +315 -113
- package/dist/cjs/api/resources/orders/client/Client.d.ts +28 -27
- package/dist/cjs/api/resources/orders/client/Client.js +177 -62
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +9 -8
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +32 -13
- package/dist/cjs/api/resources/plans/client/Client.d.ts +25 -12
- package/dist/cjs/api/resources/plans/client/Client.js +143 -33
- package/dist/cjs/api/resources/products/client/Client.d.ts +23 -22
- package/dist/cjs/api/resources/products/client/Client.js +158 -55
- package/dist/cjs/api/resources/products/client/requests/index.d.ts +1 -1
- package/dist/cjs/api/resources/products/client/requests/index.js +0 -3
- package/dist/cjs/api/resources/traces/client/Client.d.ts +9 -8
- package/dist/cjs/api/resources/traces/client/Client.js +57 -23
- package/dist/cjs/api/resources/usage/client/Client.d.ts +16 -15
- package/dist/cjs/api/resources/usage/client/Client.js +71 -28
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.ts +3 -3
- package/dist/cjs/api/types/PlanWithFeatures.d.ts +34 -0
- package/dist/cjs/api/types/PlanWithFeatures.js +3 -0
- package/dist/cjs/api/types/SignalV2.d.ts +5 -5
- package/dist/cjs/api/types/index.d.ts +1 -0
- package/dist/cjs/api/types/index.js +1 -0
- package/dist/cjs/core/auth/AuthProvider.d.ts +1 -4
- package/dist/cjs/core/auth/BearerToken.d.ts +1 -3
- package/dist/cjs/core/auth/BearerToken.js +6 -7
- package/dist/cjs/core/auth/index.d.ts +0 -1
- package/dist/cjs/core/auth/index.js +1 -3
- package/dist/cjs/core/fetcher/BinaryResponse.d.ts +7 -6
- package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +2 -2
- package/dist/cjs/core/fetcher/Fetcher.d.ts +4 -10
- package/dist/cjs/core/fetcher/Fetcher.js +10 -204
- package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +4 -0
- package/dist/cjs/core/fetcher/ResponseWithBody.js +6 -0
- package/dist/cjs/core/fetcher/getRequestBody.d.ts +1 -1
- package/dist/cjs/core/fetcher/getRequestBody.js +0 -4
- package/dist/cjs/core/fetcher/getResponseBody.js +4 -18
- package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
- package/dist/cjs/core/fetcher/makeRequest.js +2 -0
- package/dist/cjs/core/fetcher/requestWithRetries.js +9 -0
- package/dist/cjs/core/fetcher/signals.d.ts +7 -1
- package/dist/cjs/core/fetcher/signals.js +12 -0
- package/dist/cjs/core/headers.d.ts +2 -2
- package/dist/cjs/core/headers.js +4 -6
- package/dist/cjs/core/index.d.ts +0 -1
- package/dist/cjs/core/index.js +1 -2
- package/dist/cjs/core/runtime/runtime.js +10 -11
- package/dist/cjs/core/url/join.js +1 -0
- package/dist/cjs/errors/PaidError.js +1 -5
- package/dist/cjs/errors/PaidTimeoutError.js +1 -5
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +0 -4
- package/dist/cjs/integrations/adapters/expressjs/index.d.ts +2 -2
- package/dist/cjs/integrations/adapters/expressjs/index.js +2 -1
- package/dist/cjs/integrations/adapters/expressjs/routes.d.ts +16 -0
- package/dist/cjs/integrations/adapters/expressjs/routes.js +28 -0
- package/dist/cjs/integrations/adapters/nextjs/index.d.ts +1 -1
- package/dist/cjs/integrations/adapters/nextjs/index.js +2 -1
- package/dist/cjs/integrations/adapters/nextjs/routes.d.ts +15 -0
- package/dist/cjs/integrations/adapters/nextjs/routes.js +21 -0
- package/dist/cjs/integrations/controllers/index.d.ts +1 -0
- package/dist/cjs/integrations/controllers/index.js +3 -1
- package/dist/cjs/integrations/controllers/orders.js +52 -17
- package/dist/cjs/integrations/controllers/plans.d.ts +50 -0
- package/dist/cjs/integrations/controllers/plans.js +88 -0
- package/dist/cjs/integrations/types.d.ts +5 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.d.mts +4 -17
- package/dist/esm/BaseClient.mjs +1 -24
- package/dist/esm/Client.d.mts +28 -28
- package/dist/esm/Client.mjs +27 -19
- package/dist/esm/api/errors/BadRequestError.mjs +1 -5
- package/dist/esm/api/errors/ForbiddenError.mjs +1 -5
- package/dist/esm/api/errors/InternalServerError.mjs +1 -5
- package/dist/esm/api/errors/NotFoundError.mjs +1 -5
- package/dist/esm/api/resources/agents/client/Client.d.mts +23 -22
- package/dist/esm/api/resources/agents/client/Client.mjs +157 -54
- package/dist/esm/api/resources/contacts/client/Client.d.mts +19 -18
- package/dist/esm/api/resources/contacts/client/Client.mjs +121 -42
- package/dist/esm/api/resources/customers/client/Client.d.mts +37 -36
- package/dist/esm/api/resources/customers/client/Client.mjs +314 -112
- package/dist/esm/api/resources/orders/client/Client.d.mts +28 -27
- package/dist/esm/api/resources/orders/client/Client.mjs +177 -62
- package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +9 -8
- package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +31 -12
- package/dist/esm/api/resources/plans/client/Client.d.mts +25 -12
- package/dist/esm/api/resources/plans/client/Client.mjs +142 -32
- package/dist/esm/api/resources/products/client/Client.d.mts +23 -22
- package/dist/esm/api/resources/products/client/Client.mjs +157 -54
- package/dist/esm/api/resources/products/client/requests/index.d.mts +1 -1
- package/dist/esm/api/resources/products/client/requests/index.mjs +1 -1
- package/dist/esm/api/resources/traces/client/Client.d.mts +9 -8
- package/dist/esm/api/resources/traces/client/Client.mjs +56 -22
- package/dist/esm/api/resources/usage/client/Client.d.mts +16 -15
- package/dist/esm/api/resources/usage/client/Client.mjs +70 -27
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkV2Request.d.mts +3 -3
- package/dist/esm/api/types/PlanWithFeatures.d.mts +34 -0
- package/dist/esm/api/types/PlanWithFeatures.mjs +2 -0
- package/dist/esm/api/types/SignalV2.d.mts +5 -5
- package/dist/esm/api/types/index.d.mts +1 -0
- package/dist/esm/api/types/index.mjs +1 -0
- package/dist/esm/core/auth/AuthProvider.d.mts +1 -4
- package/dist/esm/core/auth/BearerToken.d.mts +1 -3
- package/dist/esm/core/auth/BearerToken.mjs +6 -7
- package/dist/esm/core/auth/index.d.mts +0 -1
- package/dist/esm/core/auth/index.mjs +0 -1
- package/dist/esm/core/fetcher/BinaryResponse.d.mts +7 -6
- package/dist/esm/core/fetcher/EndpointSupplier.d.mts +2 -2
- package/dist/esm/core/fetcher/Fetcher.d.mts +4 -10
- package/dist/esm/core/fetcher/Fetcher.mjs +10 -204
- package/dist/esm/core/fetcher/ResponseWithBody.d.mts +4 -0
- package/dist/esm/core/fetcher/ResponseWithBody.mjs +3 -0
- package/dist/esm/core/fetcher/getRequestBody.d.mts +1 -1
- package/dist/esm/core/fetcher/getRequestBody.mjs +0 -4
- package/dist/esm/core/fetcher/getResponseBody.mjs +4 -18
- package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
- package/dist/esm/core/fetcher/makeRequest.mjs +2 -0
- package/dist/esm/core/fetcher/requestWithRetries.mjs +9 -0
- package/dist/esm/core/fetcher/signals.d.mts +7 -1
- package/dist/esm/core/fetcher/signals.mjs +12 -0
- package/dist/esm/core/headers.d.mts +2 -2
- package/dist/esm/core/headers.mjs +4 -6
- package/dist/esm/core/index.d.mts +0 -1
- package/dist/esm/core/index.mjs +0 -1
- package/dist/esm/core/runtime/runtime.mjs +10 -11
- package/dist/esm/core/url/join.mjs +1 -0
- package/dist/esm/errors/PaidError.mjs +1 -5
- package/dist/esm/errors/PaidTimeoutError.mjs +1 -5
- package/dist/esm/index.d.mts +0 -1
- package/dist/esm/index.mjs +0 -1
- package/dist/esm/integrations/adapters/expressjs/index.d.mts +2 -2
- package/dist/esm/integrations/adapters/expressjs/index.mjs +2 -2
- package/dist/esm/integrations/adapters/expressjs/routes.d.mts +16 -0
- package/dist/esm/integrations/adapters/expressjs/routes.mjs +27 -0
- package/dist/esm/integrations/adapters/nextjs/index.d.mts +1 -1
- package/dist/esm/integrations/adapters/nextjs/index.mjs +1 -1
- package/dist/esm/integrations/adapters/nextjs/routes.d.mts +15 -0
- package/dist/esm/integrations/adapters/nextjs/routes.mjs +20 -0
- package/dist/esm/integrations/controllers/index.d.mts +1 -0
- package/dist/esm/integrations/controllers/index.mjs +1 -0
- package/dist/esm/integrations/controllers/orders.mjs +52 -17
- package/dist/esm/integrations/controllers/plans.d.mts +50 -0
- package/dist/esm/integrations/controllers/plans.mjs +84 -0
- package/dist/esm/integrations/types.d.mts +5 -2
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +38 -7
- package/reference.md +106 -57
- package/dist/cjs/auth/BearerAuthProvider.d.ts +0 -20
- package/dist/cjs/auth/BearerAuthProvider.js +0 -79
- package/dist/cjs/auth/index.d.ts +0 -1
- package/dist/cjs/auth/index.js +0 -5
- package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +0 -5
- package/dist/cjs/core/auth/NoOpAuthProvider.js +0 -9
- package/dist/cjs/core/exports.d.ts +0 -1
- package/dist/cjs/core/exports.js +0 -17
- package/dist/cjs/core/logging/exports.d.ts +0 -18
- package/dist/cjs/core/logging/exports.js +0 -45
- package/dist/cjs/core/logging/index.d.ts +0 -1
- package/dist/cjs/core/logging/index.js +0 -17
- package/dist/cjs/core/logging/logger.d.ts +0 -126
- package/dist/cjs/core/logging/logger.js +0 -144
- package/dist/cjs/errors/handleNonStatusCodeError.d.ts +0 -2
- package/dist/cjs/errors/handleNonStatusCodeError.js +0 -65
- package/dist/cjs/exports.d.ts +0 -1
- package/dist/cjs/exports.js +0 -17
- package/dist/esm/auth/BearerAuthProvider.d.mts +0 -20
- package/dist/esm/auth/BearerAuthProvider.mjs +0 -42
- package/dist/esm/auth/index.d.mts +0 -1
- package/dist/esm/auth/index.mjs +0 -1
- package/dist/esm/core/auth/NoOpAuthProvider.d.mts +0 -5
- package/dist/esm/core/auth/NoOpAuthProvider.mjs +0 -5
- package/dist/esm/core/exports.d.mts +0 -1
- package/dist/esm/core/exports.mjs +0 -1
- package/dist/esm/core/logging/exports.d.mts +0 -18
- package/dist/esm/core/logging/exports.mjs +0 -9
- package/dist/esm/core/logging/index.d.mts +0 -1
- package/dist/esm/core/logging/index.mjs +0 -1
- package/dist/esm/core/logging/logger.d.mts +0 -126
- package/dist/esm/core/logging/logger.mjs +0 -138
- package/dist/esm/errors/handleNonStatusCodeError.d.mts +0 -2
- package/dist/esm/errors/handleNonStatusCodeError.mjs +0 -29
- package/dist/esm/exports.d.mts +0 -1
- package/dist/esm/exports.mjs +0 -1
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.mjs";
|
|
2
|
-
import { type NormalizedClientOptions } from "../../../../BaseClient.mjs";
|
|
3
2
|
import * as core from "../../../../core/index.mjs";
|
|
4
3
|
import * as Paid from "../../../index.mjs";
|
|
5
|
-
export declare namespace
|
|
6
|
-
|
|
4
|
+
export declare namespace Usage {
|
|
5
|
+
interface Options extends BaseClientOptions {
|
|
6
|
+
}
|
|
7
7
|
interface RequestOptions extends BaseRequestOptions {
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
export declare class
|
|
11
|
-
protected readonly _options:
|
|
12
|
-
constructor(
|
|
10
|
+
export declare class Usage {
|
|
11
|
+
protected readonly _options: Usage.Options;
|
|
12
|
+
constructor(_options?: Usage.Options);
|
|
13
13
|
/**
|
|
14
14
|
* DEPRECATED: Use POST /usage/v2/signals/bulk instead for cleaner field names.
|
|
15
15
|
*
|
|
16
16
|
* @param {Paid.UsageRecordBulkRequest} request
|
|
17
|
-
* @param {
|
|
17
|
+
* @param {Usage.RequestOptions} requestOptions - Request-specific configuration.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* await client.usage.recordBulk({
|
|
21
21
|
* signals: [{}, {}, {}]
|
|
22
22
|
* })
|
|
23
23
|
*/
|
|
24
|
-
recordBulk(request?: Paid.UsageRecordBulkRequest, requestOptions?:
|
|
24
|
+
recordBulk(request?: Paid.UsageRecordBulkRequest, requestOptions?: Usage.RequestOptions): core.HttpResponsePromise<void>;
|
|
25
25
|
private __recordBulk;
|
|
26
26
|
/**
|
|
27
27
|
* @param {Paid.UsageRecordBulkV2Request} request
|
|
28
|
-
* @param {
|
|
28
|
+
* @param {Usage.RequestOptions} requestOptions - Request-specific configuration.
|
|
29
29
|
*
|
|
30
30
|
* @throws {@link Paid.BadRequestError}
|
|
31
31
|
*
|
|
@@ -33,15 +33,15 @@ export declare class UsageClient {
|
|
|
33
33
|
* await client.usage.usageRecordBulkV2({
|
|
34
34
|
* signals: [{
|
|
35
35
|
* event_name: "emails_sent",
|
|
36
|
-
* product_id: "
|
|
37
|
-
* customer_id: "
|
|
36
|
+
* product_id: "prod_abc123def",
|
|
37
|
+
* customer_id: "cus_xyz789ghi"
|
|
38
38
|
* }, {
|
|
39
39
|
* event_name: "emails_sent",
|
|
40
40
|
* external_product_id: "acme-product",
|
|
41
41
|
* external_customer_id: "acme-inc"
|
|
42
42
|
* }, {
|
|
43
43
|
* event_name: "meeting_booked",
|
|
44
|
-
* product_id: "
|
|
44
|
+
* product_id: "prod_abc123def",
|
|
45
45
|
* external_customer_id: "acme-inc",
|
|
46
46
|
* data: {
|
|
47
47
|
* "meeting_duration": 30,
|
|
@@ -50,11 +50,11 @@ export declare class UsageClient {
|
|
|
50
50
|
* }]
|
|
51
51
|
* })
|
|
52
52
|
*/
|
|
53
|
-
usageRecordBulkV2(request?: Paid.UsageRecordBulkV2Request, requestOptions?:
|
|
53
|
+
usageRecordBulkV2(request?: Paid.UsageRecordBulkV2Request, requestOptions?: Usage.RequestOptions): core.HttpResponsePromise<void>;
|
|
54
54
|
private __usageRecordBulkV2;
|
|
55
55
|
/**
|
|
56
56
|
* @param {Paid.UsageCheckUsageRequest} request
|
|
57
|
-
* @param {
|
|
57
|
+
* @param {Usage.RequestOptions} requestOptions - Request-specific configuration.
|
|
58
58
|
*
|
|
59
59
|
* @throws {@link Paid.BadRequestError}
|
|
60
60
|
* @throws {@link Paid.NotFoundError}
|
|
@@ -66,6 +66,7 @@ export declare class UsageClient {
|
|
|
66
66
|
* externalProductId: "acme-agent"
|
|
67
67
|
* })
|
|
68
68
|
*/
|
|
69
|
-
checkUsage(request: Paid.UsageCheckUsageRequest, requestOptions?:
|
|
69
|
+
checkUsage(request: Paid.UsageCheckUsageRequest, requestOptions?: Usage.RequestOptions): core.HttpResponsePromise<Paid.UsageCheckUsageResponse>;
|
|
70
70
|
private __checkUsage;
|
|
71
|
+
protected _getAuthorizationHeader(): Promise<string | undefined>;
|
|
71
72
|
}
|
|
@@ -8,22 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
import {
|
|
12
|
-
import { mergeHeaders } from "../../../../core/headers.mjs";
|
|
11
|
+
import { mergeHeaders, mergeOnlyDefinedHeaders } from "../../../../core/headers.mjs";
|
|
13
12
|
import * as core from "../../../../core/index.mjs";
|
|
14
13
|
import * as environments from "../../../../environments.mjs";
|
|
15
|
-
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.mjs";
|
|
16
14
|
import * as errors from "../../../../errors/index.mjs";
|
|
17
15
|
import * as Paid from "../../../index.mjs";
|
|
18
|
-
export class
|
|
19
|
-
constructor(
|
|
20
|
-
this._options =
|
|
16
|
+
export class Usage {
|
|
17
|
+
constructor(_options = {}) {
|
|
18
|
+
this._options = _options;
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
23
21
|
* DEPRECATED: Use POST /usage/v2/signals/bulk instead for cleaner field names.
|
|
24
22
|
*
|
|
25
23
|
* @param {Paid.UsageRecordBulkRequest} request
|
|
26
|
-
* @param {
|
|
24
|
+
* @param {Usage.RequestOptions} requestOptions - Request-specific configuration.
|
|
27
25
|
*
|
|
28
26
|
* @example
|
|
29
27
|
* await client.usage.recordBulk({
|
|
@@ -35,8 +33,8 @@ export class UsageClient {
|
|
|
35
33
|
}
|
|
36
34
|
__recordBulk() {
|
|
37
35
|
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
|
|
38
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
39
|
-
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
37
|
+
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
40
38
|
const _response = yield core.fetcher({
|
|
41
39
|
url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, "usage/signals/bulk"),
|
|
42
40
|
method: "POST",
|
|
@@ -48,8 +46,6 @@ export class UsageClient {
|
|
|
48
46
|
timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
|
|
49
47
|
maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
|
|
50
48
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
51
|
-
fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
|
|
52
|
-
logging: this._options.logging,
|
|
53
49
|
});
|
|
54
50
|
if (_response.ok) {
|
|
55
51
|
return { data: undefined, rawResponse: _response.rawResponse };
|
|
@@ -61,12 +57,26 @@ export class UsageClient {
|
|
|
61
57
|
rawResponse: _response.rawResponse,
|
|
62
58
|
});
|
|
63
59
|
}
|
|
64
|
-
|
|
60
|
+
switch (_response.error.reason) {
|
|
61
|
+
case "non-json":
|
|
62
|
+
throw new errors.PaidError({
|
|
63
|
+
statusCode: _response.error.statusCode,
|
|
64
|
+
body: _response.error.rawBody,
|
|
65
|
+
rawResponse: _response.rawResponse,
|
|
66
|
+
});
|
|
67
|
+
case "timeout":
|
|
68
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /usage/signals/bulk.");
|
|
69
|
+
case "unknown":
|
|
70
|
+
throw new errors.PaidError({
|
|
71
|
+
message: _response.error.errorMessage,
|
|
72
|
+
rawResponse: _response.rawResponse,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
65
75
|
});
|
|
66
76
|
}
|
|
67
77
|
/**
|
|
68
78
|
* @param {Paid.UsageRecordBulkV2Request} request
|
|
69
|
-
* @param {
|
|
79
|
+
* @param {Usage.RequestOptions} requestOptions - Request-specific configuration.
|
|
70
80
|
*
|
|
71
81
|
* @throws {@link Paid.BadRequestError}
|
|
72
82
|
*
|
|
@@ -74,15 +84,15 @@ export class UsageClient {
|
|
|
74
84
|
* await client.usage.usageRecordBulkV2({
|
|
75
85
|
* signals: [{
|
|
76
86
|
* event_name: "emails_sent",
|
|
77
|
-
* product_id: "
|
|
78
|
-
* customer_id: "
|
|
87
|
+
* product_id: "prod_abc123def",
|
|
88
|
+
* customer_id: "cus_xyz789ghi"
|
|
79
89
|
* }, {
|
|
80
90
|
* event_name: "emails_sent",
|
|
81
91
|
* external_product_id: "acme-product",
|
|
82
92
|
* external_customer_id: "acme-inc"
|
|
83
93
|
* }, {
|
|
84
94
|
* event_name: "meeting_booked",
|
|
85
|
-
* product_id: "
|
|
95
|
+
* product_id: "prod_abc123def",
|
|
86
96
|
* external_customer_id: "acme-inc",
|
|
87
97
|
* data: {
|
|
88
98
|
* "meeting_duration": 30,
|
|
@@ -96,8 +106,8 @@ export class UsageClient {
|
|
|
96
106
|
}
|
|
97
107
|
__usageRecordBulkV2() {
|
|
98
108
|
return __awaiter(this, arguments, void 0, function* (request = {}, requestOptions) {
|
|
99
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
100
|
-
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
109
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
110
|
+
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
101
111
|
const _response = yield core.fetcher({
|
|
102
112
|
url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, "usage/v2/signals/bulk"),
|
|
103
113
|
method: "POST",
|
|
@@ -109,8 +119,6 @@ export class UsageClient {
|
|
|
109
119
|
timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
|
|
110
120
|
maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
|
|
111
121
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
112
|
-
fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
|
|
113
|
-
logging: this._options.logging,
|
|
114
122
|
});
|
|
115
123
|
if (_response.ok) {
|
|
116
124
|
return { data: undefined, rawResponse: _response.rawResponse };
|
|
@@ -127,12 +135,26 @@ export class UsageClient {
|
|
|
127
135
|
});
|
|
128
136
|
}
|
|
129
137
|
}
|
|
130
|
-
|
|
138
|
+
switch (_response.error.reason) {
|
|
139
|
+
case "non-json":
|
|
140
|
+
throw new errors.PaidError({
|
|
141
|
+
statusCode: _response.error.statusCode,
|
|
142
|
+
body: _response.error.rawBody,
|
|
143
|
+
rawResponse: _response.rawResponse,
|
|
144
|
+
});
|
|
145
|
+
case "timeout":
|
|
146
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /usage/v2/signals/bulk.");
|
|
147
|
+
case "unknown":
|
|
148
|
+
throw new errors.PaidError({
|
|
149
|
+
message: _response.error.errorMessage,
|
|
150
|
+
rawResponse: _response.rawResponse,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
131
153
|
});
|
|
132
154
|
}
|
|
133
155
|
/**
|
|
134
156
|
* @param {Paid.UsageCheckUsageRequest} request
|
|
135
|
-
* @param {
|
|
157
|
+
* @param {Usage.RequestOptions} requestOptions - Request-specific configuration.
|
|
136
158
|
*
|
|
137
159
|
* @throws {@link Paid.BadRequestError}
|
|
138
160
|
* @throws {@link Paid.NotFoundError}
|
|
@@ -149,8 +171,8 @@ export class UsageClient {
|
|
|
149
171
|
}
|
|
150
172
|
__checkUsage(request, requestOptions) {
|
|
151
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
153
|
-
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
174
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
175
|
+
const _headers = mergeHeaders((_a = this._options) === null || _a === void 0 ? void 0 : _a.headers, mergeOnlyDefinedHeaders({ Authorization: yield this._getAuthorizationHeader() }), requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers);
|
|
154
176
|
const _response = yield core.fetcher({
|
|
155
177
|
url: core.url.join((_c = (_b = (yield core.Supplier.get(this._options.baseUrl))) !== null && _b !== void 0 ? _b : (yield core.Supplier.get(this._options.environment))) !== null && _c !== void 0 ? _c : environments.PaidEnvironment.Production, "usage/check-usage"),
|
|
156
178
|
method: "POST",
|
|
@@ -162,8 +184,6 @@ export class UsageClient {
|
|
|
162
184
|
timeoutMs: ((_f = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _d !== void 0 ? _d : (_e = this._options) === null || _e === void 0 ? void 0 : _e.timeoutInSeconds) !== null && _f !== void 0 ? _f : 60) * 1000,
|
|
163
185
|
maxRetries: (_g = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _g !== void 0 ? _g : (_h = this._options) === null || _h === void 0 ? void 0 : _h.maxRetries,
|
|
164
186
|
abortSignal: requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal,
|
|
165
|
-
fetchFn: (_j = this._options) === null || _j === void 0 ? void 0 : _j.fetch,
|
|
166
|
-
logging: this._options.logging,
|
|
167
187
|
});
|
|
168
188
|
if (_response.ok) {
|
|
169
189
|
return { data: _response.body, rawResponse: _response.rawResponse };
|
|
@@ -184,7 +204,30 @@ export class UsageClient {
|
|
|
184
204
|
});
|
|
185
205
|
}
|
|
186
206
|
}
|
|
187
|
-
|
|
207
|
+
switch (_response.error.reason) {
|
|
208
|
+
case "non-json":
|
|
209
|
+
throw new errors.PaidError({
|
|
210
|
+
statusCode: _response.error.statusCode,
|
|
211
|
+
body: _response.error.rawBody,
|
|
212
|
+
rawResponse: _response.rawResponse,
|
|
213
|
+
});
|
|
214
|
+
case "timeout":
|
|
215
|
+
throw new errors.PaidTimeoutError("Timeout exceeded when calling POST /usage/check-usage.");
|
|
216
|
+
case "unknown":
|
|
217
|
+
throw new errors.PaidError({
|
|
218
|
+
message: _response.error.errorMessage,
|
|
219
|
+
rawResponse: _response.rawResponse,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
_getAuthorizationHeader() {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
const bearer = yield core.Supplier.get(this._options.token);
|
|
227
|
+
if (bearer != null) {
|
|
228
|
+
return `Bearer ${bearer}`;
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
188
231
|
});
|
|
189
232
|
}
|
|
190
233
|
}
|
|
@@ -4,15 +4,15 @@ import type * as Paid from "../../../../index.mjs";
|
|
|
4
4
|
* {
|
|
5
5
|
* signals: [{
|
|
6
6
|
* event_name: "emails_sent",
|
|
7
|
-
* product_id: "
|
|
8
|
-
* customer_id: "
|
|
7
|
+
* product_id: "prod_abc123def",
|
|
8
|
+
* customer_id: "cus_xyz789ghi"
|
|
9
9
|
* }, {
|
|
10
10
|
* event_name: "emails_sent",
|
|
11
11
|
* external_product_id: "acme-product",
|
|
12
12
|
* external_customer_id: "acme-inc"
|
|
13
13
|
* }, {
|
|
14
14
|
* event_name: "meeting_booked",
|
|
15
|
-
* product_id: "
|
|
15
|
+
* product_id: "prod_abc123def",
|
|
16
16
|
* external_customer_id: "acme-inc",
|
|
17
17
|
* data: {
|
|
18
18
|
* "meeting_duration": 30,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plan with its features (product-attribute pairs) for display
|
|
3
|
+
*/
|
|
4
|
+
export interface PlanWithFeatures {
|
|
5
|
+
/** The unique identifier of the plan */
|
|
6
|
+
id: string;
|
|
7
|
+
/** The name of the plan */
|
|
8
|
+
name: string;
|
|
9
|
+
/** The description of the plan */
|
|
10
|
+
description?: string;
|
|
11
|
+
/** When the plan was created */
|
|
12
|
+
createdAt: string;
|
|
13
|
+
/** When the plan was last updated */
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
/** The ID of the next plan in the sequence */
|
|
16
|
+
nextPlanId?: string;
|
|
17
|
+
/** The ID of the previous plan in the sequence */
|
|
18
|
+
prevPlanId?: string;
|
|
19
|
+
/** The features (product-attribute pairs) included in this plan */
|
|
20
|
+
features: PlanWithFeatures.Features.Item[];
|
|
21
|
+
}
|
|
22
|
+
export declare namespace PlanWithFeatures {
|
|
23
|
+
type Features = Features.Item[];
|
|
24
|
+
namespace Features {
|
|
25
|
+
interface Item {
|
|
26
|
+
/** The name of the product */
|
|
27
|
+
productName: string;
|
|
28
|
+
/** The name of the product attribute */
|
|
29
|
+
attributeName: string;
|
|
30
|
+
/** The pricing configuration for this feature */
|
|
31
|
+
pricing: Record<string, unknown>;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* V2 signal schema with clean field names.
|
|
2
|
+
* V2 signal schema with clean field names. IMPORTANT: Exactly one customer ID field (customer_id OR external_customer_id) and exactly one product ID field (product_id OR external_product_id) must be provided per signal.
|
|
3
3
|
*/
|
|
4
4
|
export interface SignalV2 {
|
|
5
5
|
/** The name of the event being tracked */
|
|
6
6
|
event_name: string;
|
|
7
|
-
/** Paid's
|
|
7
|
+
/** Paid's display ID for the product (e.g., prod_abc123). Cannot be used with external_product_id. Either this or external_product_id is required. */
|
|
8
8
|
product_id?: string;
|
|
9
|
-
/** Your system's product ID.
|
|
9
|
+
/** Your system's product ID. Cannot be used with product_id. Either this or product_id is required. */
|
|
10
10
|
external_product_id?: string;
|
|
11
|
-
/** Paid's
|
|
11
|
+
/** Paid's display ID for the customer (e.g., cus_xyz789). Cannot be used with external_customer_id. Either this or external_customer_id is required. */
|
|
12
12
|
customer_id?: string;
|
|
13
|
-
/** Your system's customer ID.
|
|
13
|
+
/** Your system's customer ID. Cannot be used with customer_id. Either this or customer_id is required. */
|
|
14
14
|
external_customer_id?: string;
|
|
15
15
|
/** Optional additional data/metadata for the signal */
|
|
16
16
|
data?: Record<string, unknown>;
|
|
@@ -30,6 +30,7 @@ export * from "./PaginationMeta.mjs";
|
|
|
30
30
|
export * from "./PaymentMethod.mjs";
|
|
31
31
|
export * from "./Plan.mjs";
|
|
32
32
|
export * from "./PlanGroup.mjs";
|
|
33
|
+
export * from "./PlanWithFeatures.mjs";
|
|
33
34
|
export * from "./PricePoint.mjs";
|
|
34
35
|
export * from "./Pricing.mjs";
|
|
35
36
|
export * from "./PricingModelType.mjs";
|
|
@@ -30,6 +30,7 @@ export * from "./PaginationMeta.mjs";
|
|
|
30
30
|
export * from "./PaymentMethod.mjs";
|
|
31
31
|
export * from "./Plan.mjs";
|
|
32
32
|
export * from "./PlanGroup.mjs";
|
|
33
|
+
export * from "./PlanWithFeatures.mjs";
|
|
33
34
|
export * from "./PricePoint.mjs";
|
|
34
35
|
export * from "./Pricing.mjs";
|
|
35
36
|
export * from "./PricingModelType.mjs";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type { EndpointMetadata } from "../fetcher/EndpointMetadata.mjs";
|
|
2
1
|
import type { AuthRequest } from "./AuthRequest.mjs";
|
|
3
2
|
export interface AuthProvider {
|
|
4
|
-
getAuthRequest(
|
|
5
|
-
endpointMetadata?: EndpointMetadata;
|
|
6
|
-
}): Promise<AuthRequest>;
|
|
3
|
+
getAuthRequest(): Promise<AuthRequest>;
|
|
7
4
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export type BearerToken = string;
|
|
2
|
-
declare function toAuthorizationHeader(token: string | undefined): string | undefined;
|
|
3
2
|
export declare const BearerToken: {
|
|
4
|
-
toAuthorizationHeader:
|
|
3
|
+
toAuthorizationHeader: (token: BearerToken | undefined) => string | undefined;
|
|
5
4
|
fromAuthorizationHeader: (header: string) => BearerToken;
|
|
6
5
|
};
|
|
7
|
-
export {};
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;
|
|
2
|
-
function toAuthorizationHeader(token) {
|
|
3
|
-
if (token == null) {
|
|
4
|
-
return undefined;
|
|
5
|
-
}
|
|
6
|
-
return `Bearer ${token}`;
|
|
7
|
-
}
|
|
8
2
|
export const BearerToken = {
|
|
9
|
-
toAuthorizationHeader:
|
|
3
|
+
toAuthorizationHeader: (token) => {
|
|
4
|
+
if (token == null) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return `Bearer ${token}`;
|
|
8
|
+
},
|
|
10
9
|
fromAuthorizationHeader: (header) => {
|
|
11
10
|
return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim();
|
|
12
11
|
},
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import type { ResponseWithBody } from "./ResponseWithBody.mjs";
|
|
1
2
|
export type BinaryResponse = {
|
|
2
3
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */
|
|
3
|
-
bodyUsed:
|
|
4
|
+
bodyUsed: boolean;
|
|
4
5
|
/**
|
|
5
6
|
* Returns a ReadableStream of the response body.
|
|
6
7
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/body)
|
|
7
8
|
*/
|
|
8
|
-
stream: () =>
|
|
9
|
+
stream: () => ReadableStream<Uint8Array>;
|
|
9
10
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */
|
|
10
|
-
arrayBuffer: () =>
|
|
11
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
11
12
|
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
|
|
12
|
-
blob: () =>
|
|
13
|
+
blob: () => Promise<Blob>;
|
|
13
14
|
/**
|
|
14
15
|
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
|
|
15
16
|
* Some versions of the Fetch API may not support this method.
|
|
16
17
|
*/
|
|
17
|
-
bytes?():
|
|
18
|
+
bytes?(): Promise<Uint8Array>;
|
|
18
19
|
};
|
|
19
|
-
export declare function getBinaryResponse(response:
|
|
20
|
+
export declare function getBinaryResponse(response: ResponseWithBody): BinaryResponse;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
2
2
|
import type { Supplier } from "./Supplier.mjs";
|
|
3
3
|
type EndpointSupplierFn<T> = (arg: {
|
|
4
|
-
endpointMetadata
|
|
4
|
+
endpointMetadata: EndpointMetadata;
|
|
5
5
|
}) => T | Promise<T>;
|
|
6
6
|
export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
|
|
7
7
|
export declare const EndpointSupplier: {
|
|
8
8
|
get: <T>(supplier: EndpointSupplier<T>, arg: {
|
|
9
|
-
endpointMetadata
|
|
9
|
+
endpointMetadata: EndpointMetadata;
|
|
10
10
|
}) => Promise<T>;
|
|
11
11
|
};
|
|
12
12
|
export {};
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import { type LogConfig, type Logger } from "../logging/logger.mjs";
|
|
2
1
|
import type { APIResponse } from "./APIResponse.mjs";
|
|
3
2
|
import type { EndpointMetadata } from "./EndpointMetadata.mjs";
|
|
3
|
+
import { EndpointSupplier } from "./EndpointSupplier.mjs";
|
|
4
4
|
export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
|
|
5
5
|
export declare namespace Fetcher {
|
|
6
6
|
interface Args {
|
|
7
7
|
url: string;
|
|
8
8
|
method: string;
|
|
9
9
|
contentType?: string;
|
|
10
|
-
headers?: Record<string,
|
|
10
|
+
headers?: Record<string, string | EndpointSupplier<string | null | undefined> | null | undefined>;
|
|
11
11
|
queryParameters?: Record<string, unknown>;
|
|
12
12
|
body?: unknown;
|
|
13
13
|
timeoutMs?: number;
|
|
14
14
|
maxRetries?: number;
|
|
15
15
|
withCredentials?: boolean;
|
|
16
16
|
abortSignal?: AbortSignal;
|
|
17
|
-
requestType?: "json" | "file" | "bytes"
|
|
17
|
+
requestType?: "json" | "file" | "bytes";
|
|
18
18
|
responseType?: "json" | "blob" | "sse" | "streaming" | "text" | "arrayBuffer" | "binary-response";
|
|
19
19
|
duplex?: "half";
|
|
20
20
|
endpointMetadata?: EndpointMetadata;
|
|
21
|
-
fetchFn?: typeof fetch;
|
|
22
|
-
logging?: LogConfig | Logger;
|
|
23
21
|
}
|
|
24
|
-
type Error = FailedStatusCodeError | NonJsonError |
|
|
22
|
+
type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
|
|
25
23
|
interface FailedStatusCodeError {
|
|
26
24
|
reason: "status-code";
|
|
27
25
|
statusCode: number;
|
|
@@ -32,10 +30,6 @@ export declare namespace Fetcher {
|
|
|
32
30
|
statusCode: number;
|
|
33
31
|
rawBody: string;
|
|
34
32
|
}
|
|
35
|
-
interface BodyIsNullError {
|
|
36
|
-
reason: "body-is-null";
|
|
37
|
-
statusCode: number;
|
|
38
|
-
}
|
|
39
33
|
interface TimeoutError {
|
|
40
34
|
reason: "timeout";
|
|
41
35
|
}
|