@kivel.io/sdk 0.8.0 → 0.9.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/CHANGELOG.md +11 -0
- package/README.md +1 -1
- package/dist/index.d.ts +28 -2
- package/dist/index.js +22 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @kivel.io/sdk
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fde4ed4: Show clear messages and structured details for plan allowances and request rate limits.
|
|
8
|
+
- fde4ed4: Type the usage response, including workspace allowance counters and reset times when the server provides them.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- fde4ed4: Read the machine code from the new `code` field while retaining support for older servers. The HTTP `error` field remains a readable message. Exhausted hosted tool, email, and resource allowances return 402. Request rate limits return 429. Timed limits include `Retry-After`, which the SDK and CLI expose to callers.
|
|
13
|
+
|
|
3
14
|
## 0.8.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ write a local credential file. Do not log responses that contain keys or tokens.
|
|
|
44
44
|
|
|
45
45
|
[Method reference](https://kivel.io/docs/sdk/) ·
|
|
46
46
|
[Agent workflows](https://kivel.io/docs/agent-workflows/) ·
|
|
47
|
-
[Plan limits](https://kivel.io/
|
|
47
|
+
[Plan limits](https://kivel.io/pricing/)
|
|
48
48
|
|
|
49
49
|
Licensed under Apache-2.0. Support: support@kivel.io.
|
|
50
50
|
|
package/dist/index.d.ts
CHANGED
|
@@ -51,13 +51,39 @@ export interface Execution {
|
|
|
51
51
|
resetsAt: string;
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
+
export interface KivelUsage {
|
|
55
|
+
plan: 'anonymous' | 'free' | 'pro' | 'team';
|
|
56
|
+
limits: Record<string, unknown>;
|
|
57
|
+
runsToday: number;
|
|
58
|
+
resetsAt: string;
|
|
59
|
+
period?: {
|
|
60
|
+
start: string;
|
|
61
|
+
end: string;
|
|
62
|
+
};
|
|
63
|
+
items?: {
|
|
64
|
+
key: string;
|
|
65
|
+
label: string;
|
|
66
|
+
unit: 'count' | 'bytes';
|
|
67
|
+
used: number;
|
|
68
|
+
max: number;
|
|
69
|
+
resetsAt?: string;
|
|
70
|
+
}[];
|
|
71
|
+
}
|
|
72
|
+
export interface KivelLimitDetails {
|
|
73
|
+
code: 'limit_reached' | 'rate_limited';
|
|
74
|
+
limit: string;
|
|
75
|
+
used?: number;
|
|
76
|
+
max?: number;
|
|
77
|
+
plan?: KivelUsage['plan'];
|
|
78
|
+
}
|
|
54
79
|
export declare class KivelError extends Error {
|
|
55
80
|
readonly status: number;
|
|
56
81
|
readonly requestId?: string | undefined;
|
|
57
82
|
readonly retryAfter?: number | undefined;
|
|
58
83
|
readonly requiredPlan?: string | undefined;
|
|
59
84
|
readonly upgradeUrl?: string | undefined;
|
|
60
|
-
|
|
85
|
+
readonly limitDetails?: KivelLimitDetails | undefined;
|
|
86
|
+
constructor(message: string, status: number, requestId?: string | undefined, retryAfter?: number | undefined, requiredPlan?: string | undefined, upgradeUrl?: string | undefined, limitDetails?: KivelLimitDetails | undefined);
|
|
61
87
|
}
|
|
62
88
|
export declare class Kivel {
|
|
63
89
|
private options;
|
|
@@ -355,7 +381,7 @@ export declare class Kivel {
|
|
|
355
381
|
inboxDeliveries(id: string, token?: string): Promise<unknown>;
|
|
356
382
|
private waitTimeout;
|
|
357
383
|
private waitQuery;
|
|
358
|
-
usage(): Promise<
|
|
384
|
+
usage(): Promise<KivelUsage>;
|
|
359
385
|
resources(): Promise<unknown>;
|
|
360
386
|
/** Senders can POST to webhookUrl without credentials by default. Inspection stays private.
|
|
361
387
|
* Set visibility to private to require X-Access-Token on incoming webhooks. */
|
package/dist/index.js
CHANGED
|
@@ -5,13 +5,15 @@ export class KivelError extends Error {
|
|
|
5
5
|
retryAfter;
|
|
6
6
|
requiredPlan;
|
|
7
7
|
upgradeUrl;
|
|
8
|
-
|
|
8
|
+
limitDetails;
|
|
9
|
+
constructor(message, status, requestId, retryAfter, requiredPlan, upgradeUrl, limitDetails) {
|
|
9
10
|
super(message);
|
|
10
11
|
this.status = status;
|
|
11
12
|
this.requestId = requestId;
|
|
12
13
|
this.retryAfter = retryAfter;
|
|
13
14
|
this.requiredPlan = requiredPlan;
|
|
14
15
|
this.upgradeUrl = upgradeUrl;
|
|
16
|
+
this.limitDetails = limitDetails;
|
|
15
17
|
this.name = 'KivelError';
|
|
16
18
|
}
|
|
17
19
|
}
|
|
@@ -85,23 +87,25 @@ export class Kivel {
|
|
|
85
87
|
throw new KivelError('The server returned an invalid response.', response.status, response.headers.get('x-request-id') ?? undefined);
|
|
86
88
|
}
|
|
87
89
|
if (!response.ok) {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
typeof
|
|
92
|
-
?
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
?
|
|
104
|
-
:
|
|
90
|
+
const error = value && typeof value === 'object' ? value : {};
|
|
91
|
+
const code = error.code ?? error.error;
|
|
92
|
+
const details = (code === 'limit_reached' || code === 'rate_limited') &&
|
|
93
|
+
typeof error.limit === 'string'
|
|
94
|
+
? {
|
|
95
|
+
code,
|
|
96
|
+
limit: error.limit,
|
|
97
|
+
...(typeof error.used === 'number' ? { used: error.used } : {}),
|
|
98
|
+
...(typeof error.max === 'number' ? { max: error.max } : {}),
|
|
99
|
+
...(['anonymous', 'free', 'pro', 'team'].some((plan) => plan === error.plan)
|
|
100
|
+
? { plan: error.plan }
|
|
101
|
+
: {}),
|
|
102
|
+
}
|
|
103
|
+
: undefined;
|
|
104
|
+
throw new KivelError(typeof error.message === 'string'
|
|
105
|
+
? error.message
|
|
106
|
+
: typeof error.error === 'string'
|
|
107
|
+
? error.error
|
|
108
|
+
: `Request failed (${response.status}).`, response.status, response.headers.get('x-request-id') ?? undefined, Number(response.headers.get('retry-after')) || undefined, typeof error.requiredPlan === 'string' ? error.requiredPlan : undefined, typeof error.upgradeUrl === 'string' ? error.upgradeUrl : undefined, details);
|
|
105
109
|
}
|
|
106
110
|
return value;
|
|
107
111
|
}
|