@harnesys/sdk 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +80 -2
- package/dist/addon-context-factory.d.ts +6 -0
- package/dist/addon-context-factory.js +160 -0
- package/dist/addon-context.d.ts +346 -0
- package/dist/addon-context.js +0 -0
- package/dist/define-addon.d.ts +57 -0
- package/dist/define-addon.js +53 -0
- package/dist/families/config.d.ts +14 -0
- package/dist/families/config.js +16 -0
- package/dist/families/content.d.ts +28 -0
- package/dist/families/content.js +19 -0
- package/dist/families/field-spec.d.ts +100 -0
- package/dist/families/field-spec.js +85 -0
- package/dist/families/hook.d.ts +37 -0
- package/dist/families/hook.js +25 -0
- package/dist/families/job.d.ts +45 -0
- package/dist/families/job.js +26 -0
- package/dist/families/json-schema.d.ts +36 -0
- package/dist/families/json-schema.js +101 -0
- package/dist/families/lsp.d.ts +18 -0
- package/dist/families/lsp.js +18 -0
- package/dist/families/mcp.d.ts +18 -0
- package/dist/families/mcp.js +18 -0
- package/dist/families/registry.d.ts +9 -0
- package/dist/families/registry.js +34 -0
- package/dist/families/route.d.ts +38 -0
- package/dist/families/route.js +37 -0
- package/dist/families/source-kind.d.ts +24 -0
- package/dist/families/source-kind.js +21 -0
- package/dist/families/tool-pack.d.ts +68 -0
- package/dist/families/tool-pack.js +57 -0
- package/dist/families/transport.d.ts +52 -0
- package/dist/families/transport.js +29 -0
- package/dist/families/trigger.d.ts +97 -0
- package/dist/families/trigger.js +46 -0
- package/dist/families/view.d.ts +255 -0
- package/dist/families/view.js +87 -0
- package/dist/families/viewer.d.ts +31 -0
- package/dist/families/viewer.js +26 -0
- package/dist/families/worker.d.ts +23 -0
- package/dist/families/worker.js +19 -0
- package/dist/host-client.d.ts +11 -0
- package/dist/host-client.js +30 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +35 -0
- package/dist/manifest/branding.d.ts +14 -0
- package/dist/manifest/branding.js +18 -0
- package/dist/manifest/connections.d.ts +21 -0
- package/dist/manifest/connections.js +10 -0
- package/dist/manifest/json-schema.d.ts +2 -0
- package/dist/manifest/json-schema.js +13 -0
- package/dist/manifest/l10n.d.ts +9 -0
- package/dist/manifest/l10n.js +28 -0
- package/dist/manifest/manifest.d.ts +112 -0
- package/dist/manifest/manifest.js +45 -0
- package/dist/manifest/validate.d.ts +14 -0
- package/dist/manifest/validate.js +144 -0
- package/dist/permissions/permissions.d.ts +31 -0
- package/dist/permissions/permissions.js +53 -0
- package/dist/process-entry.d.ts +26 -0
- package/dist/process-entry.js +146 -0
- package/dist/protocol/envelope.d.ts +115 -0
- package/dist/protocol/envelope.js +72 -0
- package/dist/protocol/error.d.ts +67 -0
- package/dist/protocol/error.js +61 -0
- package/dist/protocol/handshake.d.ts +55 -0
- package/dist/protocol/handshake.js +26 -0
- package/dist/protocol/map.d.ts +1090 -0
- package/dist/protocol/map.js +127 -0
- package/dist/protocol/meta.d.ts +31 -0
- package/dist/protocol/meta.js +14 -0
- package/dist/protocol/method-spec.d.ts +13 -0
- package/dist/protocol/method-spec.js +9 -0
- package/dist/protocol/org-service-methods.d.ts +135 -0
- package/dist/protocol/org-service-methods.js +106 -0
- package/dist/protocol/shared.d.ts +389 -0
- package/dist/protocol/shared.js +231 -0
- package/dist/protocol/source-methods.d.ts +218 -0
- package/dist/protocol/source-methods.js +18 -0
- package/dist/protocol/thread-service-methods.d.ts +50 -0
- package/dist/protocol/thread-service-methods.js +32 -0
- package/dist/runtime.d.ts +25 -0
- package/dist/runtime.js +229 -0
- package/dist/testing/fake-db.d.ts +15 -0
- package/dist/testing/fake-db.js +120 -0
- package/dist/testing/fake-files.d.ts +9 -0
- package/dist/testing/fake-files.js +87 -0
- package/dist/testing/fake-host.d.ts +115 -0
- package/dist/testing/fake-host.js +152 -0
- package/dist/testing/fake-services.d.ts +63 -0
- package/dist/testing/fake-services.js +277 -0
- package/dist/testing/fixtures.d.ts +4 -0
- package/dist/testing/fixtures.js +84 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +2 -0
- package/package.json +66 -4
- package/src/addon-context-factory.ts +236 -0
- package/src/addon-context.ts +313 -0
- package/src/define-addon.ts +178 -0
- package/src/families/config.ts +24 -0
- package/src/families/content.ts +35 -0
- package/src/families/field-spec.ts +175 -0
- package/src/families/hook.ts +34 -0
- package/src/families/job.ts +41 -0
- package/src/families/json-schema.ts +167 -0
- package/src/families/lsp.ts +28 -0
- package/src/families/mcp.ts +28 -0
- package/src/families/registry.ts +44 -0
- package/src/families/route.ts +52 -0
- package/src/families/source-kind.ts +34 -0
- package/src/families/tool-pack.ts +92 -0
- package/src/families/transport.ts +52 -0
- package/src/families/trigger.ts +92 -0
- package/src/families/view.ts +144 -0
- package/src/families/viewer.ts +43 -0
- package/src/families/worker.ts +30 -0
- package/src/host-client.ts +52 -0
- package/src/index.ts +341 -0
- package/src/manifest/branding.ts +24 -0
- package/src/manifest/connections.ts +21 -0
- package/src/manifest/json-schema.ts +24 -0
- package/src/manifest/l10n.ts +39 -0
- package/src/manifest/manifest.ts +94 -0
- package/src/manifest/validate.ts +200 -0
- package/src/permissions/permissions.ts +79 -0
- package/src/process-entry.ts +205 -0
- package/src/protocol/envelope.ts +126 -0
- package/src/protocol/error.ts +81 -0
- package/src/protocol/handshake.ts +43 -0
- package/src/protocol/map.ts +339 -0
- package/src/protocol/meta.ts +26 -0
- package/src/protocol/method-spec.ts +40 -0
- package/src/protocol/org-service-methods.ts +148 -0
- package/src/protocol/shared.ts +345 -0
- package/src/protocol/source-methods.ts +61 -0
- package/src/protocol/thread-service-methods.ts +50 -0
- package/src/runtime.ts +332 -0
- package/src/testing/fake-db.ts +140 -0
- package/src/testing/fake-files.ts +114 -0
- package/src/testing/fake-host.ts +261 -0
- package/src/testing/fake-services.ts +345 -0
- package/src/testing/fixtures.ts +88 -0
- package/src/testing/index.ts +12 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const JSONRPC_VERSION = "2.0";
|
|
3
|
+
export declare const MAX_MESSAGE_BYTES: number;
|
|
4
|
+
export declare const JsonRpcIdSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
5
|
+
export declare const JsonRpcRequestSchema: z.ZodObject<{
|
|
6
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
7
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
8
|
+
method: z.ZodString;
|
|
9
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export declare const JsonRpcNotificationSchema: z.ZodObject<{
|
|
12
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
13
|
+
method: z.ZodString;
|
|
14
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export declare const JsonRpcErrorSchema: z.ZodObject<{
|
|
17
|
+
code: z.ZodNumber;
|
|
18
|
+
message: z.ZodString;
|
|
19
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
reason: z.ZodEnum<{
|
|
21
|
+
invalid_params: "invalid_params";
|
|
22
|
+
invalid_response: "invalid_response";
|
|
23
|
+
permission_denied: "permission_denied";
|
|
24
|
+
not_found: "not_found";
|
|
25
|
+
conflict: "conflict";
|
|
26
|
+
quota_exceeded: "quota_exceeded";
|
|
27
|
+
rate_limited: "rate_limited";
|
|
28
|
+
timeout: "timeout";
|
|
29
|
+
cancelled: "cancelled";
|
|
30
|
+
unavailable: "unavailable";
|
|
31
|
+
unsupported: "unsupported";
|
|
32
|
+
account_failed: "account_failed";
|
|
33
|
+
incompatible_handlers: "incompatible_handlers";
|
|
34
|
+
migration_failed: "migration_failed";
|
|
35
|
+
permission_revoked: "permission_revoked";
|
|
36
|
+
internal: "internal";
|
|
37
|
+
}>;
|
|
38
|
+
retryable: z.ZodBoolean;
|
|
39
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
40
|
+
accountCode: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, z.core.$strip>>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
export declare const JsonRpcResponseSchema: z.ZodObject<{
|
|
44
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
45
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
46
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
|
47
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
48
|
+
code: z.ZodNumber;
|
|
49
|
+
message: z.ZodString;
|
|
50
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
51
|
+
reason: z.ZodEnum<{
|
|
52
|
+
invalid_params: "invalid_params";
|
|
53
|
+
invalid_response: "invalid_response";
|
|
54
|
+
permission_denied: "permission_denied";
|
|
55
|
+
not_found: "not_found";
|
|
56
|
+
conflict: "conflict";
|
|
57
|
+
quota_exceeded: "quota_exceeded";
|
|
58
|
+
rate_limited: "rate_limited";
|
|
59
|
+
timeout: "timeout";
|
|
60
|
+
cancelled: "cancelled";
|
|
61
|
+
unavailable: "unavailable";
|
|
62
|
+
unsupported: "unsupported";
|
|
63
|
+
account_failed: "account_failed";
|
|
64
|
+
incompatible_handlers: "incompatible_handlers";
|
|
65
|
+
migration_failed: "migration_failed";
|
|
66
|
+
permission_revoked: "permission_revoked";
|
|
67
|
+
internal: "internal";
|
|
68
|
+
}>;
|
|
69
|
+
retryable: z.ZodBoolean;
|
|
70
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
71
|
+
accountCode: z.ZodOptional<z.ZodString>;
|
|
72
|
+
}, z.core.$strip>>;
|
|
73
|
+
}, z.core.$strip>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
export type JsonRpcRequest = z.infer<typeof JsonRpcRequestSchema>;
|
|
76
|
+
export type JsonRpcNotification = z.infer<typeof JsonRpcNotificationSchema>;
|
|
77
|
+
export type JsonRpcResponse = z.infer<typeof JsonRpcResponseSchema>;
|
|
78
|
+
export type JsonRpcError = z.infer<typeof JsonRpcErrorSchema>;
|
|
79
|
+
export declare const CancelNotificationSchema: z.ZodObject<{
|
|
80
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
export type CancelNotification = z.infer<typeof CancelNotificationSchema>;
|
|
83
|
+
export declare const ProgressNotificationSchema: z.ZodObject<{
|
|
84
|
+
token: z.ZodString;
|
|
85
|
+
value: z.ZodUnknown;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
export type ProgressNotification = z.infer<typeof ProgressNotificationSchema>;
|
|
88
|
+
export interface OutgoingRequest {
|
|
89
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
90
|
+
id: string | number;
|
|
91
|
+
method: string;
|
|
92
|
+
params?: unknown;
|
|
93
|
+
}
|
|
94
|
+
export interface OutgoingNotification {
|
|
95
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
96
|
+
method: string;
|
|
97
|
+
params?: unknown;
|
|
98
|
+
}
|
|
99
|
+
export interface OutgoingResponse {
|
|
100
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
101
|
+
id: string | number;
|
|
102
|
+
result?: unknown;
|
|
103
|
+
error?: JsonRpcError;
|
|
104
|
+
}
|
|
105
|
+
export declare function request(method: string, id: string | number, params?: unknown): OutgoingRequest;
|
|
106
|
+
export declare function notification(method: string, params?: unknown): OutgoingNotification;
|
|
107
|
+
export declare function response(id: string | number, result: unknown): OutgoingResponse;
|
|
108
|
+
export declare function errorResponse(id: string | number | null, error: JsonRpcError): OutgoingErrorResponse;
|
|
109
|
+
export interface OutgoingErrorResponse {
|
|
110
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
111
|
+
id: string | number | null;
|
|
112
|
+
error: JsonRpcError;
|
|
113
|
+
}
|
|
114
|
+
export declare function encodeMessage(message: OutgoingRequest | OutgoingNotification | OutgoingResponse | OutgoingErrorResponse): string;
|
|
115
|
+
export declare function decodeMessage(line: string): JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AddonErrorDataSchema } from "./error.js";
|
|
3
|
+
export const JSONRPC_VERSION = '2.0';
|
|
4
|
+
export const MAX_MESSAGE_BYTES = 8 * 1024 * 1024;
|
|
5
|
+
export const JsonRpcIdSchema = z.union([z.string(), z.number()]);
|
|
6
|
+
export const JsonRpcRequestSchema = z.object({
|
|
7
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
8
|
+
id: JsonRpcIdSchema,
|
|
9
|
+
method: z.string().min(1),
|
|
10
|
+
params: z.unknown().optional(),
|
|
11
|
+
});
|
|
12
|
+
export const JsonRpcNotificationSchema = z.object({
|
|
13
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
14
|
+
method: z.string().min(1),
|
|
15
|
+
params: z.unknown().optional(),
|
|
16
|
+
});
|
|
17
|
+
export const JsonRpcErrorSchema = z.object({
|
|
18
|
+
code: z.number().int(),
|
|
19
|
+
message: z.string().min(1),
|
|
20
|
+
data: AddonErrorDataSchema.optional(),
|
|
21
|
+
});
|
|
22
|
+
export const JsonRpcResponseSchema = z.object({
|
|
23
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
24
|
+
id: JsonRpcIdSchema,
|
|
25
|
+
result: z.unknown().optional(),
|
|
26
|
+
error: JsonRpcErrorSchema.optional(),
|
|
27
|
+
});
|
|
28
|
+
export const CancelNotificationSchema = z.object({ id: JsonRpcIdSchema });
|
|
29
|
+
export const ProgressNotificationSchema = z.object({
|
|
30
|
+
token: z.string().min(1),
|
|
31
|
+
value: z.unknown(),
|
|
32
|
+
});
|
|
33
|
+
export function request(method, id, params) {
|
|
34
|
+
return { jsonrpc: JSONRPC_VERSION, id, method, params };
|
|
35
|
+
}
|
|
36
|
+
export function notification(method, params) {
|
|
37
|
+
return { jsonrpc: JSONRPC_VERSION, method, params };
|
|
38
|
+
}
|
|
39
|
+
export function response(id, result) {
|
|
40
|
+
return { jsonrpc: JSONRPC_VERSION, id, result };
|
|
41
|
+
}
|
|
42
|
+
export function errorResponse(id, error) {
|
|
43
|
+
return { jsonrpc: JSONRPC_VERSION, id, error };
|
|
44
|
+
}
|
|
45
|
+
export function encodeMessage(message) {
|
|
46
|
+
const line = `${JSON.stringify(message)}\n`;
|
|
47
|
+
const bytes = new TextEncoder().encode(line);
|
|
48
|
+
if (bytes.length > MAX_MESSAGE_BYTES) {
|
|
49
|
+
throw new Error(`message exceeds the ${MAX_MESSAGE_BYTES} byte protocol cap`);
|
|
50
|
+
}
|
|
51
|
+
return line;
|
|
52
|
+
}
|
|
53
|
+
export function decodeMessage(line) {
|
|
54
|
+
const bytes = new TextEncoder().encode(line);
|
|
55
|
+
if (bytes.length > MAX_MESSAGE_BYTES) {
|
|
56
|
+
throw new Error(`message exceeds the ${MAX_MESSAGE_BYTES} byte protocol cap`);
|
|
57
|
+
}
|
|
58
|
+
const parsed = JSON.parse(line);
|
|
59
|
+
const asRequest = JsonRpcRequestSchema.safeParse(parsed);
|
|
60
|
+
if (asRequest.success) {
|
|
61
|
+
return asRequest.data;
|
|
62
|
+
}
|
|
63
|
+
const asNotification = JsonRpcNotificationSchema.safeParse(parsed);
|
|
64
|
+
if (asNotification.success) {
|
|
65
|
+
return asNotification.data;
|
|
66
|
+
}
|
|
67
|
+
const asResponse = JsonRpcResponseSchema.safeParse(parsed);
|
|
68
|
+
if (asResponse.success) {
|
|
69
|
+
return asResponse.data;
|
|
70
|
+
}
|
|
71
|
+
throw new Error('message is not a JSON-RPC 2.0 request, notification or response');
|
|
72
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const AddonErrorReasonSchema: z.ZodEnum<{
|
|
3
|
+
invalid_params: "invalid_params";
|
|
4
|
+
invalid_response: "invalid_response";
|
|
5
|
+
permission_denied: "permission_denied";
|
|
6
|
+
not_found: "not_found";
|
|
7
|
+
conflict: "conflict";
|
|
8
|
+
quota_exceeded: "quota_exceeded";
|
|
9
|
+
rate_limited: "rate_limited";
|
|
10
|
+
timeout: "timeout";
|
|
11
|
+
cancelled: "cancelled";
|
|
12
|
+
unavailable: "unavailable";
|
|
13
|
+
unsupported: "unsupported";
|
|
14
|
+
account_failed: "account_failed";
|
|
15
|
+
incompatible_handlers: "incompatible_handlers";
|
|
16
|
+
migration_failed: "migration_failed";
|
|
17
|
+
permission_revoked: "permission_revoked";
|
|
18
|
+
internal: "internal";
|
|
19
|
+
}>;
|
|
20
|
+
export type AddonErrorReason = z.infer<typeof AddonErrorReasonSchema>;
|
|
21
|
+
export interface AddonErrorData {
|
|
22
|
+
reason: AddonErrorReason;
|
|
23
|
+
retryable: boolean;
|
|
24
|
+
detail?: string;
|
|
25
|
+
accountCode?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare const AddonErrorDataSchema: z.ZodObject<{
|
|
28
|
+
reason: z.ZodEnum<{
|
|
29
|
+
invalid_params: "invalid_params";
|
|
30
|
+
invalid_response: "invalid_response";
|
|
31
|
+
permission_denied: "permission_denied";
|
|
32
|
+
not_found: "not_found";
|
|
33
|
+
conflict: "conflict";
|
|
34
|
+
quota_exceeded: "quota_exceeded";
|
|
35
|
+
rate_limited: "rate_limited";
|
|
36
|
+
timeout: "timeout";
|
|
37
|
+
cancelled: "cancelled";
|
|
38
|
+
unavailable: "unavailable";
|
|
39
|
+
unsupported: "unsupported";
|
|
40
|
+
account_failed: "account_failed";
|
|
41
|
+
incompatible_handlers: "incompatible_handlers";
|
|
42
|
+
migration_failed: "migration_failed";
|
|
43
|
+
permission_revoked: "permission_revoked";
|
|
44
|
+
internal: "internal";
|
|
45
|
+
}>;
|
|
46
|
+
retryable: z.ZodBoolean;
|
|
47
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
48
|
+
accountCode: z.ZodOptional<z.ZodString>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
export declare class AddonError extends Error {
|
|
51
|
+
readonly reason: AddonErrorReason;
|
|
52
|
+
readonly retryable: boolean;
|
|
53
|
+
readonly detail?: string;
|
|
54
|
+
readonly accountCode?: string;
|
|
55
|
+
constructor(reason: AddonErrorReason, options?: {
|
|
56
|
+
retryable?: boolean;
|
|
57
|
+
detail?: string;
|
|
58
|
+
accountCode?: string;
|
|
59
|
+
});
|
|
60
|
+
toData(): AddonErrorData;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Copy-safe detection: the addon dist bundles its own copy of this module, so
|
|
64
|
+
* in-process hosts see errors whose class identity differs from the host's
|
|
65
|
+
* `AddonError`. Detect structurally instead of by `instanceof` alone.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isAddonError(error: unknown): error is AddonError;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const AddonErrorReasonSchema = z.enum([
|
|
3
|
+
'invalid_params',
|
|
4
|
+
'invalid_response',
|
|
5
|
+
'permission_denied',
|
|
6
|
+
'not_found',
|
|
7
|
+
'conflict',
|
|
8
|
+
'quota_exceeded',
|
|
9
|
+
'rate_limited',
|
|
10
|
+
'timeout',
|
|
11
|
+
'cancelled',
|
|
12
|
+
'unavailable',
|
|
13
|
+
'unsupported',
|
|
14
|
+
'account_failed',
|
|
15
|
+
'incompatible_handlers',
|
|
16
|
+
'migration_failed',
|
|
17
|
+
'permission_revoked',
|
|
18
|
+
'internal',
|
|
19
|
+
]);
|
|
20
|
+
export const AddonErrorDataSchema = z.object({
|
|
21
|
+
reason: AddonErrorReasonSchema,
|
|
22
|
+
retryable: z.boolean(),
|
|
23
|
+
detail: z.string().optional(),
|
|
24
|
+
accountCode: z.string().optional(),
|
|
25
|
+
});
|
|
26
|
+
export class AddonError extends Error {
|
|
27
|
+
reason;
|
|
28
|
+
retryable;
|
|
29
|
+
detail;
|
|
30
|
+
accountCode;
|
|
31
|
+
constructor(reason, options) {
|
|
32
|
+
super(options?.detail ?? reason);
|
|
33
|
+
this.name = 'AddonError';
|
|
34
|
+
this.reason = reason;
|
|
35
|
+
this.retryable = options?.retryable ?? false;
|
|
36
|
+
this.detail = options?.detail;
|
|
37
|
+
this.accountCode = options?.accountCode;
|
|
38
|
+
}
|
|
39
|
+
toData() {
|
|
40
|
+
return {
|
|
41
|
+
reason: this.reason,
|
|
42
|
+
retryable: this.retryable,
|
|
43
|
+
detail: this.detail,
|
|
44
|
+
accountCode: this.accountCode,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Copy-safe detection: the addon dist bundles its own copy of this module, so
|
|
50
|
+
* in-process hosts see errors whose class identity differs from the host's
|
|
51
|
+
* `AddonError`. Detect structurally instead of by `instanceof` alone.
|
|
52
|
+
*/
|
|
53
|
+
export function isAddonError(error) {
|
|
54
|
+
if (error instanceof AddonError) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return (error instanceof Error &&
|
|
58
|
+
error.name === 'AddonError' &&
|
|
59
|
+
'reason' in error &&
|
|
60
|
+
typeof error.toData === 'function');
|
|
61
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export interface InitializeParams {
|
|
3
|
+
platform: number;
|
|
4
|
+
host: {
|
|
5
|
+
version: string;
|
|
6
|
+
features: string[];
|
|
7
|
+
};
|
|
8
|
+
instance: {
|
|
9
|
+
orgId: string;
|
|
10
|
+
generation: number;
|
|
11
|
+
dataDir: string;
|
|
12
|
+
locale: string;
|
|
13
|
+
};
|
|
14
|
+
permissions: Array<{
|
|
15
|
+
id: string;
|
|
16
|
+
scope?: Record<string, unknown>;
|
|
17
|
+
}>;
|
|
18
|
+
experimental: string[];
|
|
19
|
+
deprecations: string[];
|
|
20
|
+
}
|
|
21
|
+
export interface InitializeResult {
|
|
22
|
+
addon: {
|
|
23
|
+
id: string;
|
|
24
|
+
version: string;
|
|
25
|
+
};
|
|
26
|
+
handlers: string[];
|
|
27
|
+
deactivateTimeoutMs?: number;
|
|
28
|
+
}
|
|
29
|
+
export declare const InitializeParamsSchema: z.ZodObject<{
|
|
30
|
+
platform: z.ZodNumber;
|
|
31
|
+
host: z.ZodObject<{
|
|
32
|
+
version: z.ZodString;
|
|
33
|
+
features: z.ZodArray<z.ZodString>;
|
|
34
|
+
}, z.core.$strip>;
|
|
35
|
+
instance: z.ZodObject<{
|
|
36
|
+
orgId: z.ZodString;
|
|
37
|
+
generation: z.ZodNumber;
|
|
38
|
+
dataDir: z.ZodString;
|
|
39
|
+
locale: z.ZodString;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
permissions: z.ZodArray<z.ZodObject<{
|
|
42
|
+
id: z.ZodString;
|
|
43
|
+
scope: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
44
|
+
}, z.core.$strip>>;
|
|
45
|
+
experimental: z.ZodArray<z.ZodString>;
|
|
46
|
+
deprecations: z.ZodArray<z.ZodString>;
|
|
47
|
+
}, z.core.$strip>;
|
|
48
|
+
export declare const InitializeResultSchema: z.ZodObject<{
|
|
49
|
+
addon: z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
version: z.ZodString;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
handlers: z.ZodArray<z.ZodString>;
|
|
54
|
+
deactivateTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
55
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { EffectivePermissionSchema } from "../permissions/permissions.js";
|
|
3
|
+
export const InitializeParamsSchema = z.object({
|
|
4
|
+
platform: z.number().int().positive(),
|
|
5
|
+
host: z.object({
|
|
6
|
+
version: z.string().min(1),
|
|
7
|
+
features: z.array(z.string()),
|
|
8
|
+
}),
|
|
9
|
+
instance: z.object({
|
|
10
|
+
orgId: z.string().min(1),
|
|
11
|
+
generation: z.number().int().nonnegative(),
|
|
12
|
+
dataDir: z.string().min(1),
|
|
13
|
+
locale: z.string().min(1),
|
|
14
|
+
}),
|
|
15
|
+
permissions: z.array(EffectivePermissionSchema),
|
|
16
|
+
experimental: z.array(z.string()),
|
|
17
|
+
deprecations: z.array(z.string()),
|
|
18
|
+
});
|
|
19
|
+
export const InitializeResultSchema = z.object({
|
|
20
|
+
addon: z.object({
|
|
21
|
+
id: z.string().min(1),
|
|
22
|
+
version: z.string().min(1),
|
|
23
|
+
}),
|
|
24
|
+
handlers: z.array(z.string()),
|
|
25
|
+
deactivateTimeoutMs: z.number().int().positive().optional(),
|
|
26
|
+
});
|