@chainlink/cre-sdk 1.11.0 → 1.12.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/dist/capabilities/errors/error-codes.d.ts +53 -0
- package/dist/capabilities/errors/error-codes.js +71 -0
- package/dist/capabilities/errors/error-serialization.d.ts +5 -0
- package/dist/capabilities/errors/error-serialization.js +18 -0
- package/dist/capabilities/errors/error.d.ts +31 -0
- package/dist/capabilities/errors/error.js +77 -0
- package/dist/capabilities/errors/index.d.ts +3 -0
- package/dist/capabilities/errors/index.js +3 -0
- package/dist/generated/capabilities/networking/http/v1alpha/client_pb.d.ts +45 -0
- package/dist/generated/capabilities/networking/http/v1alpha/client_pb.js +10 -3
- package/dist/sdk/errors.d.ts +1 -0
- package/dist/sdk/errors.js +2 -0
- package/dist/sdk/impl/runtime-impl.js +7 -11
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +1 -0
- package/dist/sdk/utils/capabilities/capability-error.d.ts +4 -0
- package/dist/sdk/utils/capabilities/capability-error.js +4 -0
- package/dist/workflows/standard_tests/capability_errors/test.ts +44 -0
- package/package.json +1 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability error codes are primarily based on gRPC error codes:
|
|
3
|
+
* https://grpc.github.io/grpc/core/md_doc_statuscodes.html
|
|
4
|
+
* Custom error codes specific to this project should start from 100 to avoid
|
|
5
|
+
* conflicts with future gRPC codes. Note: 0 (OK) is intentionally excluded
|
|
6
|
+
* because capability errors must always indicate a failure condition.
|
|
7
|
+
*/
|
|
8
|
+
export type ErrorCode = number;
|
|
9
|
+
/** Sentinel for error code strings that are not recognised. */
|
|
10
|
+
export declare const UnrecognisedErrorCode = -1;
|
|
11
|
+
/** Indicates the operation was canceled (typically by the caller). */
|
|
12
|
+
export declare const Canceled = 1;
|
|
13
|
+
/** Unknown error. */
|
|
14
|
+
export declare const Unknown = 2;
|
|
15
|
+
/** Client specified an invalid argument. */
|
|
16
|
+
export declare const InvalidArgument = 3;
|
|
17
|
+
/** Operation expired before completion. */
|
|
18
|
+
export declare const DeadlineExceeded = 4;
|
|
19
|
+
/** Some requested entity was not found. */
|
|
20
|
+
export declare const NotFound = 5;
|
|
21
|
+
/** An attempt to create an entity failed because one already exists. */
|
|
22
|
+
export declare const AlreadyExists = 6;
|
|
23
|
+
/** The caller does not have permission to execute the specified operation. */
|
|
24
|
+
export declare const PermissionDenied = 7;
|
|
25
|
+
/** Some resource has been exhausted. */
|
|
26
|
+
export declare const ResourceExhausted = 8;
|
|
27
|
+
/** Operation was rejected because the system is not in a state required for execution. */
|
|
28
|
+
export declare const FailedPrecondition = 9;
|
|
29
|
+
/** The operation was aborted, typically due to a concurrency issue. */
|
|
30
|
+
export declare const Aborted = 10;
|
|
31
|
+
/** Operation was attempted past the valid range. */
|
|
32
|
+
export declare const OutOfRange = 11;
|
|
33
|
+
/** Operation is not implemented or not supported/enabled in this service. */
|
|
34
|
+
export declare const Unimplemented = 12;
|
|
35
|
+
/** Some invariants expected by the underlying system have been broken. */
|
|
36
|
+
export declare const Internal = 13;
|
|
37
|
+
/** The service is currently unavailable. */
|
|
38
|
+
export declare const Unavailable = 14;
|
|
39
|
+
/** Unrecoverable data loss or corruption. */
|
|
40
|
+
export declare const DataLoss = 15;
|
|
41
|
+
/** The request does not have valid authentication credentials. */
|
|
42
|
+
export declare const Unauthenticated = 16;
|
|
43
|
+
/** Custom error codes not defined in the gRPC error space. */
|
|
44
|
+
/** Failure to reach consensus. */
|
|
45
|
+
export declare const ConsensusFailed = 100;
|
|
46
|
+
/** A CRE limit breach has occurred. */
|
|
47
|
+
export declare const LimitExceeded = 101;
|
|
48
|
+
/** Not enough observations to enable the operation to complete. */
|
|
49
|
+
export declare const InsufficientObservations = 102;
|
|
50
|
+
/** Returns the string representation of the error code. */
|
|
51
|
+
export declare function errorCodeToStringValue(code: ErrorCode): string;
|
|
52
|
+
/** Converts a string to an error code. */
|
|
53
|
+
export declare function fromErrorCodeString(str: string): ErrorCode;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** Sentinel for error code strings that are not recognised. */
|
|
2
|
+
export const UnrecognisedErrorCode = -1;
|
|
3
|
+
/** Indicates the operation was canceled (typically by the caller). */
|
|
4
|
+
export const Canceled = 1;
|
|
5
|
+
/** Unknown error. */
|
|
6
|
+
export const Unknown = 2;
|
|
7
|
+
/** Client specified an invalid argument. */
|
|
8
|
+
export const InvalidArgument = 3;
|
|
9
|
+
/** Operation expired before completion. */
|
|
10
|
+
export const DeadlineExceeded = 4;
|
|
11
|
+
/** Some requested entity was not found. */
|
|
12
|
+
export const NotFound = 5;
|
|
13
|
+
/** An attempt to create an entity failed because one already exists. */
|
|
14
|
+
export const AlreadyExists = 6;
|
|
15
|
+
/** The caller does not have permission to execute the specified operation. */
|
|
16
|
+
export const PermissionDenied = 7;
|
|
17
|
+
/** Some resource has been exhausted. */
|
|
18
|
+
export const ResourceExhausted = 8;
|
|
19
|
+
/** Operation was rejected because the system is not in a state required for execution. */
|
|
20
|
+
export const FailedPrecondition = 9;
|
|
21
|
+
/** The operation was aborted, typically due to a concurrency issue. */
|
|
22
|
+
export const Aborted = 10;
|
|
23
|
+
/** Operation was attempted past the valid range. */
|
|
24
|
+
export const OutOfRange = 11;
|
|
25
|
+
/** Operation is not implemented or not supported/enabled in this service. */
|
|
26
|
+
export const Unimplemented = 12;
|
|
27
|
+
/** Some invariants expected by the underlying system have been broken. */
|
|
28
|
+
export const Internal = 13;
|
|
29
|
+
/** The service is currently unavailable. */
|
|
30
|
+
export const Unavailable = 14;
|
|
31
|
+
/** Unrecoverable data loss or corruption. */
|
|
32
|
+
export const DataLoss = 15;
|
|
33
|
+
/** The request does not have valid authentication credentials. */
|
|
34
|
+
export const Unauthenticated = 16;
|
|
35
|
+
/** Custom error codes not defined in the gRPC error space. */
|
|
36
|
+
/** Failure to reach consensus. */
|
|
37
|
+
export const ConsensusFailed = 100;
|
|
38
|
+
/** A CRE limit breach has occurred. */
|
|
39
|
+
export const LimitExceeded = 101;
|
|
40
|
+
/** Not enough observations to enable the operation to complete. */
|
|
41
|
+
export const InsufficientObservations = 102;
|
|
42
|
+
const errorCodeToString = new Map([
|
|
43
|
+
[Canceled, 'Canceled'],
|
|
44
|
+
[Unknown, 'Unknown'],
|
|
45
|
+
[InvalidArgument, 'InvalidArgument'],
|
|
46
|
+
[DeadlineExceeded, 'DeadlineExceeded'],
|
|
47
|
+
[NotFound, 'NotFound'],
|
|
48
|
+
[AlreadyExists, 'AlreadyExists'],
|
|
49
|
+
[PermissionDenied, 'PermissionDenied'],
|
|
50
|
+
[ResourceExhausted, 'ResourceExhausted'],
|
|
51
|
+
[FailedPrecondition, 'FailedPrecondition'],
|
|
52
|
+
[Aborted, 'Aborted'],
|
|
53
|
+
[OutOfRange, 'OutOfRange'],
|
|
54
|
+
[Unimplemented, 'Unimplemented'],
|
|
55
|
+
[Internal, 'Internal'],
|
|
56
|
+
[Unavailable, 'Unavailable'],
|
|
57
|
+
[DataLoss, 'DataLoss'],
|
|
58
|
+
[Unauthenticated, 'Unauthenticated'],
|
|
59
|
+
[ConsensusFailed, 'ConsensusFailed'],
|
|
60
|
+
[LimitExceeded, 'LimitExceeded'],
|
|
61
|
+
[InsufficientObservations, 'InsufficientObservations'],
|
|
62
|
+
]);
|
|
63
|
+
const stringToErrorCode = new Map(Array.from(errorCodeToString.entries()).map(([code, name]) => [name, code]));
|
|
64
|
+
/** Returns the string representation of the error code. */
|
|
65
|
+
export function errorCodeToStringValue(code) {
|
|
66
|
+
return errorCodeToString.get(code) ?? 'UnrecognisedErrorCode';
|
|
67
|
+
}
|
|
68
|
+
/** Converts a string to an error code. */
|
|
69
|
+
export function fromErrorCodeString(str) {
|
|
70
|
+
return stringToErrorCode.get(str) ?? UnrecognisedErrorCode;
|
|
71
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CapabilityExecutionError, fromOriginString, fromVisibilityString } from './error';
|
|
2
|
+
import { fromErrorCodeString } from './error-codes';
|
|
3
|
+
const errorMessageSeparator = ':';
|
|
4
|
+
/**
|
|
5
|
+
* Parses errorMsg in the capability error wire format.
|
|
6
|
+
* If errorMsg is not a serialized capability error, a plain Error is returned.
|
|
7
|
+
*/
|
|
8
|
+
export function deserializeErrorFromString(errorMsg) {
|
|
9
|
+
const parts = errorMsg.split(errorMessageSeparator);
|
|
10
|
+
if (parts.length < 4) {
|
|
11
|
+
return new Error(errorMsg);
|
|
12
|
+
}
|
|
13
|
+
const visibility = fromVisibilityString(parts[0]);
|
|
14
|
+
const origin = fromOriginString(parts[1]);
|
|
15
|
+
const errorCode = fromErrorCodeString(parts[2]);
|
|
16
|
+
const detail = parts.slice(3).join(errorMessageSeparator);
|
|
17
|
+
return new CapabilityExecutionError(detail, visibility, origin, errorCode);
|
|
18
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRE capability errors and wire format shared across CRE components.
|
|
3
|
+
* Aligns with github.com/smartcontractkit/chainlink-common/pkg/capabilities/errors.
|
|
4
|
+
*/
|
|
5
|
+
import { type ErrorCode } from './error-codes';
|
|
6
|
+
export type Origin = number;
|
|
7
|
+
/** The error originated from a system issue. */
|
|
8
|
+
export declare const OriginSystem = 0;
|
|
9
|
+
/** The error originated from user input or action. */
|
|
10
|
+
export declare const OriginUser = 1;
|
|
11
|
+
export declare function originToString(origin: Origin): string;
|
|
12
|
+
/** Converts a string to an Origin value. */
|
|
13
|
+
export declare function fromOriginString(s: string): Origin;
|
|
14
|
+
export type Visibility = number;
|
|
15
|
+
/** The full details of the error can be shared across all nodes in the network. */
|
|
16
|
+
export declare const VisibilityPublic = 0;
|
|
17
|
+
/** The error contains sensitive information visible only to the local node. */
|
|
18
|
+
export declare const VisibilityPrivate = 1;
|
|
19
|
+
export declare function visibilityToString(visibility: Visibility): string;
|
|
20
|
+
/** Converts a string to a Visibility value. */
|
|
21
|
+
export declare function fromVisibilityString(s: string): Visibility;
|
|
22
|
+
export declare class CapabilityExecutionError extends Error {
|
|
23
|
+
readonly detail: string;
|
|
24
|
+
readonly visibility: Visibility;
|
|
25
|
+
readonly origin: Origin;
|
|
26
|
+
readonly code: ErrorCode;
|
|
27
|
+
readonly name = "CapabilityExecutionError";
|
|
28
|
+
constructor(detail: string, visibility: Visibility, origin: Origin, code: ErrorCode);
|
|
29
|
+
toString(): string;
|
|
30
|
+
}
|
|
31
|
+
export declare function isCapabilityExecutionError(err: unknown): err is CapabilityExecutionError;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CRE capability errors and wire format shared across CRE components.
|
|
3
|
+
* Aligns with github.com/smartcontractkit/chainlink-common/pkg/capabilities/errors.
|
|
4
|
+
*/
|
|
5
|
+
import { errorCodeToStringValue, UnrecognisedErrorCode } from './error-codes';
|
|
6
|
+
/** The error originated from a system issue. */
|
|
7
|
+
export const OriginSystem = 0;
|
|
8
|
+
/** The error originated from user input or action. */
|
|
9
|
+
export const OriginUser = 1;
|
|
10
|
+
export function originToString(origin) {
|
|
11
|
+
switch (origin) {
|
|
12
|
+
case OriginSystem:
|
|
13
|
+
return 'System';
|
|
14
|
+
case OriginUser:
|
|
15
|
+
return 'User';
|
|
16
|
+
default:
|
|
17
|
+
return 'UnknownOrigin';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Converts a string to an Origin value. */
|
|
21
|
+
export function fromOriginString(s) {
|
|
22
|
+
switch (s) {
|
|
23
|
+
case 'System':
|
|
24
|
+
return OriginSystem;
|
|
25
|
+
case 'User':
|
|
26
|
+
return OriginUser;
|
|
27
|
+
default:
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** The full details of the error can be shared across all nodes in the network. */
|
|
32
|
+
export const VisibilityPublic = 0;
|
|
33
|
+
/** The error contains sensitive information visible only to the local node. */
|
|
34
|
+
export const VisibilityPrivate = 1;
|
|
35
|
+
export function visibilityToString(visibility) {
|
|
36
|
+
switch (visibility) {
|
|
37
|
+
case VisibilityPublic:
|
|
38
|
+
return 'Public';
|
|
39
|
+
case VisibilityPrivate:
|
|
40
|
+
return 'Private';
|
|
41
|
+
default:
|
|
42
|
+
return 'UnknownVisibility';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Converts a string to a Visibility value. */
|
|
46
|
+
export function fromVisibilityString(s) {
|
|
47
|
+
switch (s) {
|
|
48
|
+
case 'Public':
|
|
49
|
+
return VisibilityPublic;
|
|
50
|
+
case 'Private':
|
|
51
|
+
return VisibilityPrivate;
|
|
52
|
+
default:
|
|
53
|
+
return -1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class CapabilityExecutionError extends Error {
|
|
57
|
+
detail;
|
|
58
|
+
visibility;
|
|
59
|
+
origin;
|
|
60
|
+
code;
|
|
61
|
+
name = 'CapabilityExecutionError';
|
|
62
|
+
constructor(detail, visibility, origin, code) {
|
|
63
|
+
super(code === UnrecognisedErrorCode
|
|
64
|
+
? detail
|
|
65
|
+
: `[${code}]${errorCodeToStringValue(code)}: ${detail}`);
|
|
66
|
+
this.detail = detail;
|
|
67
|
+
this.visibility = visibility;
|
|
68
|
+
this.origin = origin;
|
|
69
|
+
this.code = code;
|
|
70
|
+
}
|
|
71
|
+
toString() {
|
|
72
|
+
return this.message;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export function isCapabilityExecutionError(err) {
|
|
76
|
+
return err instanceof CapabilityExecutionError;
|
|
77
|
+
}
|
|
@@ -79,6 +79,43 @@ export type HeaderValuesJson = {
|
|
|
79
79
|
export declare const HeaderValuesSchema: GenMessage<HeaderValues, {
|
|
80
80
|
jsonType: HeaderValuesJson;
|
|
81
81
|
}>;
|
|
82
|
+
/**
|
|
83
|
+
* MtlsAuth represents the private-key/cert pair for mtls auth.
|
|
84
|
+
*
|
|
85
|
+
* @generated from message capabilities.networking.http.v1alpha.MtlsAuth
|
|
86
|
+
*/
|
|
87
|
+
export type MtlsAuth = Message<'capabilities.networking.http.v1alpha.MtlsAuth'> & {
|
|
88
|
+
/**
|
|
89
|
+
* @generated from field: bytes private_key = 1;
|
|
90
|
+
*/
|
|
91
|
+
privateKey: Uint8Array;
|
|
92
|
+
/**
|
|
93
|
+
* @generated from field: bytes certificate = 2;
|
|
94
|
+
*/
|
|
95
|
+
certificate: Uint8Array;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* MtlsAuth represents the private-key/cert pair for mtls auth.
|
|
99
|
+
*
|
|
100
|
+
* @generated from message capabilities.networking.http.v1alpha.MtlsAuth
|
|
101
|
+
*/
|
|
102
|
+
export type MtlsAuthJson = {
|
|
103
|
+
/**
|
|
104
|
+
* @generated from field: bytes private_key = 1;
|
|
105
|
+
*/
|
|
106
|
+
privateKey?: string;
|
|
107
|
+
/**
|
|
108
|
+
* @generated from field: bytes certificate = 2;
|
|
109
|
+
*/
|
|
110
|
+
certificate?: string;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Describes the message capabilities.networking.http.v1alpha.MtlsAuth.
|
|
114
|
+
* Use `create(MtlsAuthSchema)` to create a new message.
|
|
115
|
+
*/
|
|
116
|
+
export declare const MtlsAuthSchema: GenMessage<MtlsAuth, {
|
|
117
|
+
jsonType: MtlsAuthJson;
|
|
118
|
+
}>;
|
|
82
119
|
/**
|
|
83
120
|
* @generated from message capabilities.networking.http.v1alpha.Request
|
|
84
121
|
*/
|
|
@@ -120,6 +157,10 @@ export type Request = Message<'capabilities.networking.http.v1alpha.Request'> &
|
|
|
120
157
|
multiHeaders: {
|
|
121
158
|
[key: string]: HeaderValues;
|
|
122
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* @generated from field: optional capabilities.networking.http.v1alpha.MtlsAuth mtls = 8;
|
|
162
|
+
*/
|
|
163
|
+
mtls?: MtlsAuth;
|
|
123
164
|
};
|
|
124
165
|
/**
|
|
125
166
|
* @generated from message capabilities.networking.http.v1alpha.Request
|
|
@@ -162,6 +203,10 @@ export type RequestJson = {
|
|
|
162
203
|
multiHeaders?: {
|
|
163
204
|
[key: string]: HeaderValuesJson;
|
|
164
205
|
};
|
|
206
|
+
/**
|
|
207
|
+
* @generated from field: optional capabilities.networking.http.v1alpha.MtlsAuth mtls = 8;
|
|
208
|
+
*/
|
|
209
|
+
mtls?: MtlsAuthJson;
|
|
165
210
|
};
|
|
166
211
|
/**
|
|
167
212
|
* Describes the message capabilities.networking.http.v1alpha.Request.
|
|
@@ -9,7 +9,7 @@ import { file_tools_generator_v1alpha_cre_metadata } from '../../../../tools/gen
|
|
|
9
9
|
*/
|
|
10
10
|
export const file_capabilities_networking_http_v1alpha_client =
|
|
11
11
|
/*@__PURE__*/
|
|
12
|
-
fileDesc('
|
|
12
|
+
fileDesc('CjFjYXBhYmlsaXRpZXMvbmV0d29ya2luZy9odHRwL3YxYWxwaGEvY2xpZW50LnByb3RvEiRjYXBhYmlsaXRpZXMubmV0d29ya2luZy5odHRwLnYxYWxwaGEiSgoNQ2FjaGVTZXR0aW5ncxINCgVzdG9yZRgBIAEoCBIqCgdtYXhfYWdlGAIgASgLMhkuZ29vZ2xlLnByb3RvYnVmLkR1cmF0aW9uIh4KDEhlYWRlclZhbHVlcxIOCgZ2YWx1ZXMYASADKAkiNAoITXRsc0F1dGgSEwoLcHJpdmF0ZV9rZXkYASABKAwSEwoLY2VydGlmaWNhdGUYAiABKAwiuwQKB1JlcXVlc3QSCwoDdXJsGAEgASgJEg4KBm1ldGhvZBgCIAEoCRJPCgdoZWFkZXJzGAMgAygLMjouY2FwYWJpbGl0aWVzLm5ldHdvcmtpbmcuaHR0cC52MWFscGhhLlJlcXVlc3QuSGVhZGVyc0VudHJ5QgIYARIMCgRib2R5GAQgASgMEioKB3RpbWVvdXQYBSABKAsyGS5nb29nbGUucHJvdG9idWYuRHVyYXRpb24SSwoOY2FjaGVfc2V0dGluZ3MYBiABKAsyMy5jYXBhYmlsaXRpZXMubmV0d29ya2luZy5odHRwLnYxYWxwaGEuQ2FjaGVTZXR0aW5ncxJWCg1tdWx0aV9oZWFkZXJzGAcgAygLMj8uY2FwYWJpbGl0aWVzLm5ldHdvcmtpbmcuaHR0cC52MWFscGhhLlJlcXVlc3QuTXVsdGlIZWFkZXJzRW50cnkSQQoEbXRscxgIIAEoCzIuLmNhcGFiaWxpdGllcy5uZXR3b3JraW5nLmh0dHAudjFhbHBoYS5NdGxzQXV0aEgAiAEBGi4KDEhlYWRlcnNFbnRyeRILCgNrZXkYASABKAkSDQoFdmFsdWUYAiABKAk6AjgBGmcKEU11bHRpSGVhZGVyc0VudHJ5EgsKA2tleRgBIAEoCRJBCgV2YWx1ZRgCIAEoCzIyLmNhcGFiaWxpdGllcy5uZXR3b3JraW5nLmh0dHAudjFhbHBoYS5IZWFkZXJWYWx1ZXM6AjgBQgcKBV9tdGxzIvECCghSZXNwb25zZRITCgtzdGF0dXNfY29kZRgBIAEoDRJQCgdoZWFkZXJzGAIgAygLMjsuY2FwYWJpbGl0aWVzLm5ldHdvcmtpbmcuaHR0cC52MWFscGhhLlJlc3BvbnNlLkhlYWRlcnNFbnRyeUICGAESDAoEYm9keRgDIAEoDBJXCg1tdWx0aV9oZWFkZXJzGAQgAygLMkAuY2FwYWJpbGl0aWVzLm5ldHdvcmtpbmcuaHR0cC52MWFscGhhLlJlc3BvbnNlLk11bHRpSGVhZGVyc0VudHJ5Gi4KDEhlYWRlcnNFbnRyeRILCgNrZXkYASABKAkSDQoFdmFsdWUYAiABKAk6AjgBGmcKEU11bHRpSGVhZGVyc0VudHJ5EgsKA2tleRgBIAEoCRJBCgV2YWx1ZRgCIAEoCzIyLmNhcGFiaWxpdGllcy5uZXR3b3JraW5nLmh0dHAudjFhbHBoYS5IZWFkZXJWYWx1ZXM6AjgBMpgBCgZDbGllbnQSbAoLU2VuZFJlcXVlc3QSLS5jYXBhYmlsaXRpZXMubmV0d29ya2luZy5odHRwLnYxYWxwaGEuUmVxdWVzdBouLmNhcGFiaWxpdGllcy5uZXR3b3JraW5nLmh0dHAudjFhbHBoYS5SZXNwb25zZRoggrUYHAgCEhhodHRwLWFjdGlvbnNAMS4wLjAtYWxwaGFC6gEKKGNvbS5jYXBhYmlsaXRpZXMubmV0d29ya2luZy5odHRwLnYxYWxwaGFCC0NsaWVudFByb3RvUAGiAgNDTkiqAiRDYXBhYmlsaXRpZXMuTmV0d29ya2luZy5IdHRwLlYxYWxwaGHKAiRDYXBhYmlsaXRpZXNcTmV0d29ya2luZ1xIdHRwXFYxYWxwaGHiAjBDYXBhYmlsaXRpZXNcTmV0d29ya2luZ1xIdHRwXFYxYWxwaGFcR1BCTWV0YWRhdGHqAidDYXBhYmlsaXRpZXM6Ok5ldHdvcmtpbmc6Okh0dHA6OlYxYWxwaGFiBnByb3RvMw', [file_google_protobuf_duration, file_tools_generator_v1alpha_cre_metadata]);
|
|
13
13
|
/**
|
|
14
14
|
* Describes the message capabilities.networking.http.v1alpha.CacheSettings.
|
|
15
15
|
* Use `create(CacheSettingsSchema)` to create a new message.
|
|
@@ -24,20 +24,27 @@ messageDesc(file_capabilities_networking_http_v1alpha_client, 0);
|
|
|
24
24
|
export const HeaderValuesSchema =
|
|
25
25
|
/*@__PURE__*/
|
|
26
26
|
messageDesc(file_capabilities_networking_http_v1alpha_client, 1);
|
|
27
|
+
/**
|
|
28
|
+
* Describes the message capabilities.networking.http.v1alpha.MtlsAuth.
|
|
29
|
+
* Use `create(MtlsAuthSchema)` to create a new message.
|
|
30
|
+
*/
|
|
31
|
+
export const MtlsAuthSchema =
|
|
32
|
+
/*@__PURE__*/
|
|
33
|
+
messageDesc(file_capabilities_networking_http_v1alpha_client, 2);
|
|
27
34
|
/**
|
|
28
35
|
* Describes the message capabilities.networking.http.v1alpha.Request.
|
|
29
36
|
* Use `create(RequestSchema)` to create a new message.
|
|
30
37
|
*/
|
|
31
38
|
export const RequestSchema =
|
|
32
39
|
/*@__PURE__*/
|
|
33
|
-
messageDesc(file_capabilities_networking_http_v1alpha_client,
|
|
40
|
+
messageDesc(file_capabilities_networking_http_v1alpha_client, 3);
|
|
34
41
|
/**
|
|
35
42
|
* Describes the message capabilities.networking.http.v1alpha.Response.
|
|
36
43
|
* Use `create(ResponseSchema)` to create a new message.
|
|
37
44
|
*/
|
|
38
45
|
export const ResponseSchema =
|
|
39
46
|
/*@__PURE__*/
|
|
40
|
-
messageDesc(file_capabilities_networking_http_v1alpha_client,
|
|
47
|
+
messageDesc(file_capabilities_networking_http_v1alpha_client, 4);
|
|
41
48
|
/**
|
|
42
49
|
* @generated from service capabilities.networking.http.v1alpha.Client
|
|
43
50
|
*/
|
package/dist/sdk/errors.d.ts
CHANGED
package/dist/sdk/errors.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// TODO: on the next major version, rename this to CapabilityRuntimeError
|
|
2
|
+
export { CapabilityError as CapabilityRuntimeError } from './utils/capabilities/capability-error';
|
|
1
3
|
export class DonModeError extends Error {
|
|
2
4
|
constructor() {
|
|
3
5
|
super('cannot use Runtime inside RunInNodeMode');
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { create } from '@bufbuild/protobuf';
|
|
2
2
|
import { anyPack, anyUnpack } from '@bufbuild/protobuf/wkt';
|
|
3
|
+
import { deserializeErrorFromString } from '../../capabilities/errors';
|
|
3
4
|
import { AwaitCapabilitiesRequestSchema, AwaitSecretsRequestSchema, CapabilityRequestSchema, GetSecretsRequestSchema, Mode, SecretRequestSchema, SimpleConsensusInputsSchema, } from '../../generated/sdk/v1alpha/sdk_pb';
|
|
4
5
|
import { ConsensusCapability } from '../../generated-sdk/capabilities/internal/consensus/v1alpha/consensus_sdk_gen';
|
|
5
6
|
import { Value, } from '../utils';
|
|
6
|
-
import {
|
|
7
|
-
import { DonModeError, NodeModeError, SecretsError } from '../errors';
|
|
7
|
+
import { CapabilityRuntimeError, DonModeError, NodeModeError, SecretsError } from '../errors';
|
|
8
8
|
const DEFAULT_SECRET_NAMESPACE = 'main';
|
|
9
9
|
/**
|
|
10
10
|
* Base implementation shared by DON and Node runtimes.
|
|
@@ -59,7 +59,7 @@ export class BaseRuntimeImpl {
|
|
|
59
59
|
if (!this.helpers.call(req)) {
|
|
60
60
|
return {
|
|
61
61
|
result: () => {
|
|
62
|
-
throw new
|
|
62
|
+
throw new CapabilityRuntimeError(`Capability '${capabilityId}' not found: the host rejected the call to method '${method}'. Verify the capability ID is correct and the capability is available in this CRE environment`, {
|
|
63
63
|
callbackId,
|
|
64
64
|
method,
|
|
65
65
|
capabilityId,
|
|
@@ -96,7 +96,7 @@ export class BaseRuntimeImpl {
|
|
|
96
96
|
const awaitResponse = this.helpers.await(awaitRequest, this.maxResponseSize);
|
|
97
97
|
const capabilityResponse = awaitResponse.responses[callbackId];
|
|
98
98
|
if (!capabilityResponse) {
|
|
99
|
-
throw new
|
|
99
|
+
throw new CapabilityRuntimeError(`No response found for capability '${capabilityId}' method '${method}' (callback ID ${callbackId}): the host returned a response map that does not contain an entry for this call`, {
|
|
100
100
|
capabilityId,
|
|
101
101
|
method,
|
|
102
102
|
callbackId,
|
|
@@ -109,7 +109,7 @@ export class BaseRuntimeImpl {
|
|
|
109
109
|
return anyUnpack(response.value, outputSchema);
|
|
110
110
|
}
|
|
111
111
|
catch {
|
|
112
|
-
throw new
|
|
112
|
+
throw new CapabilityRuntimeError(`Failed to deserialize response payload for capability '${capabilityId}' method '${method}': the response could not be unpacked into the expected output schema`, {
|
|
113
113
|
capabilityId,
|
|
114
114
|
method,
|
|
115
115
|
callbackId,
|
|
@@ -117,13 +117,9 @@ export class BaseRuntimeImpl {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
case 'error':
|
|
120
|
-
throw
|
|
121
|
-
capabilityId,
|
|
122
|
-
method,
|
|
123
|
-
callbackId,
|
|
124
|
-
});
|
|
120
|
+
throw deserializeErrorFromString(response.value);
|
|
125
121
|
default:
|
|
126
|
-
throw new
|
|
122
|
+
throw new CapabilityRuntimeError(`Unexpected response type '${response.case}' for capability '${capabilityId}' method '${method}': expected 'payload' or 'error'`, {
|
|
127
123
|
capabilityId,
|
|
128
124
|
method,
|
|
129
125
|
callbackId,
|
package/dist/sdk/index.d.ts
CHANGED
package/dist/sdk/index.js
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isCapabilityExecutionError, UnrecognisedErrorCode } from '@cre/capabilities/errors'
|
|
2
|
+
import { BasicActionCapability } from '@cre/generated-sdk/capabilities/internal/basicaction/v1/basicaction_sdk_gen'
|
|
3
|
+
import { BasicCapability as BasicTriggerCapability } from '@cre/generated-sdk/capabilities/internal/basictrigger/v1/basic_sdk_gen'
|
|
4
|
+
import { cre, type Runtime } from '@cre/sdk/cre'
|
|
5
|
+
import { Runner } from '@cre/sdk/wasm'
|
|
6
|
+
|
|
7
|
+
const checkCapabilityErrors = (runtime: Runtime<Uint8Array>) => {
|
|
8
|
+
const basicAction = new BasicActionCapability()
|
|
9
|
+
const input = { inputThing: true }
|
|
10
|
+
|
|
11
|
+
while (true) {
|
|
12
|
+
try {
|
|
13
|
+
const output = basicAction.performAction(runtime, input).result()
|
|
14
|
+
if (output.adaptedThing !== 'Done') {
|
|
15
|
+
throw new Error(`expected Done response, got ${output.adaptedThing}`)
|
|
16
|
+
}
|
|
17
|
+
return 'Done'
|
|
18
|
+
} catch (err) {
|
|
19
|
+
if (!isCapabilityExecutionError(err)) {
|
|
20
|
+
throw new Error(`expected capability error, got ${String(err)}`)
|
|
21
|
+
}
|
|
22
|
+
if (err.code === UnrecognisedErrorCode) {
|
|
23
|
+
throw new Error('expected recognised error code, got UnrecognisedErrorCode')
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const initWorkflow = () => {
|
|
30
|
+
const basicTrigger = new BasicTriggerCapability()
|
|
31
|
+
|
|
32
|
+
return [cre.handler(basicTrigger.trigger({}), checkCapabilityErrors)]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function main() {
|
|
36
|
+
console.log(`TS workflow: standard test: capability errors [${new Date().toISOString()}]`)
|
|
37
|
+
|
|
38
|
+
const runner = await Runner.newRunner<Uint8Array>({
|
|
39
|
+
configParser: (c) => c,
|
|
40
|
+
})
|
|
41
|
+
await runner.run(initWorkflow)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
await main()
|