@kognitivedev/cloud-platforms 0.2.29
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/.turbo/turbo-build.log +2 -0
- package/.turbo/turbo-test.log +11 -0
- package/CHANGELOG.md +12 -0
- package/dist/client.d.ts +15 -0
- package/dist/client.js +150 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/types.d.ts +117 -0
- package/dist/types.js +2 -0
- package/dist/validation.d.ts +23 -0
- package/dist/validation.js +199 -0
- package/package.json +44 -0
- package/src/__tests__/client.test.ts +144 -0
- package/src/client.ts +211 -0
- package/src/index.ts +22 -0
- package/src/types.ts +135 -0
- package/src/validation.ts +221 -0
- package/tsconfig.json +17 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ConnectLinkResult,
|
|
3
|
+
PlatformAction,
|
|
4
|
+
PlatformActionResult,
|
|
5
|
+
PlatformCatalog,
|
|
6
|
+
PlatformConnection,
|
|
7
|
+
PlatformToolkit,
|
|
8
|
+
PlatformToolConnection,
|
|
9
|
+
PlatformToolDefinition,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
export class CloudPlatformsValidationError extends Error {
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly expected: string;
|
|
15
|
+
readonly actual: unknown;
|
|
16
|
+
|
|
17
|
+
constructor(path: string, expected: string, actual: unknown) {
|
|
18
|
+
super(`${path} must be ${expected}`);
|
|
19
|
+
this.name = "CloudPlatformsValidationError";
|
|
20
|
+
this.path = path;
|
|
21
|
+
this.expected = expected;
|
|
22
|
+
this.actual = actual;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type PlainObject = Record<string, unknown>;
|
|
27
|
+
|
|
28
|
+
export function isPlainObject(value: unknown): value is PlainObject {
|
|
29
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const prototype = Object.getPrototypeOf(value);
|
|
33
|
+
return prototype === Object.prototype || prototype === null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function cloneUnknown<T>(value: T): T {
|
|
37
|
+
if (Array.isArray(value)) {
|
|
38
|
+
return value.map((entry) => cloneUnknown(entry)) as T;
|
|
39
|
+
}
|
|
40
|
+
if (isPlainObject(value)) {
|
|
41
|
+
const cloned: Record<string, unknown> = {};
|
|
42
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
43
|
+
cloned[key] = cloneUnknown(entry);
|
|
44
|
+
}
|
|
45
|
+
return cloned as T;
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function invalid(path: string, expected: string, actual: unknown): never {
|
|
51
|
+
throw new CloudPlatformsValidationError(path, expected, actual);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function expectObject(value: unknown, path: string): PlainObject {
|
|
55
|
+
if (!isPlainObject(value)) {
|
|
56
|
+
invalid(path, "an object", value);
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function expectArray(value: unknown, path: string): unknown[] {
|
|
62
|
+
if (!Array.isArray(value)) {
|
|
63
|
+
invalid(path, "an array", value);
|
|
64
|
+
}
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function expectString(value: unknown, path: string): string {
|
|
69
|
+
if (typeof value !== "string") {
|
|
70
|
+
invalid(path, "a string", value);
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function expectBoolean(value: unknown, path: string): boolean {
|
|
76
|
+
if (typeof value !== "boolean") {
|
|
77
|
+
invalid(path, "a boolean", value);
|
|
78
|
+
}
|
|
79
|
+
return value;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function expectNullableString(value: unknown, path: string): string | null {
|
|
83
|
+
if (value === null) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return expectString(value, path);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function expectRecord(value: unknown, path: string): Record<string, unknown> {
|
|
90
|
+
return cloneUnknown(expectObject(value, path));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function expectStringArray(value: unknown, path: string): string[] {
|
|
94
|
+
return expectArray(value, path).map((entry, index) => expectString(entry, `${path}[${index}]`));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function optionalStringArray(value: unknown, path: string): string[] | undefined {
|
|
98
|
+
if (value === undefined) {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return expectStringArray(value, path);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function decodeToolkit(value: unknown, path: string): PlatformToolkit {
|
|
105
|
+
const object = expectObject(value, path);
|
|
106
|
+
return {
|
|
107
|
+
id: expectString(object.id, `${path}.id`),
|
|
108
|
+
slug: expectString(object.slug, `${path}.slug`),
|
|
109
|
+
name: expectString(object.name, `${path}.name`),
|
|
110
|
+
description: expectNullableString(object.description, `${path}.description`),
|
|
111
|
+
iconUrl: expectNullableString(object.iconUrl, `${path}.iconUrl`),
|
|
112
|
+
categories: expectStringArray(object.categories, `${path}.categories`),
|
|
113
|
+
managedAuthSchemes: expectStringArray(object.managedAuthSchemes, `${path}.managedAuthSchemes`),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function decodeAction(value: unknown, path: string): PlatformAction {
|
|
118
|
+
const object = expectObject(value, path);
|
|
119
|
+
return {
|
|
120
|
+
id: expectString(object.id, `${path}.id`),
|
|
121
|
+
slug: expectString(object.slug, `${path}.slug`),
|
|
122
|
+
toolkitSlug: expectString(object.toolkitSlug, `${path}.toolkitSlug`),
|
|
123
|
+
name: expectString(object.name, `${path}.name`),
|
|
124
|
+
description: expectNullableString(object.description, `${path}.description`),
|
|
125
|
+
version: expectNullableString(object.version, `${path}.version`),
|
|
126
|
+
inputSchema: expectRecord(object.inputSchema, `${path}.inputSchema`),
|
|
127
|
+
outputSchema: expectRecord(object.outputSchema, `${path}.outputSchema`),
|
|
128
|
+
tags: expectStringArray(object.tags, `${path}.tags`),
|
|
129
|
+
isDangerous: expectBoolean(object.isDangerous, `${path}.isDangerous`),
|
|
130
|
+
requireApproval: expectBoolean(object.requireApproval, `${path}.requireApproval`),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function decodeConnection(value: unknown, path: string): PlatformConnection {
|
|
135
|
+
const object = expectObject(value, path);
|
|
136
|
+
return {
|
|
137
|
+
id: expectString(object.id, `${path}.id`),
|
|
138
|
+
toolkitSlug: expectString(object.toolkitSlug, `${path}.toolkitSlug`),
|
|
139
|
+
alias: expectNullableString(object.alias, `${path}.alias`),
|
|
140
|
+
displayName: expectNullableString(object.displayName, `${path}.displayName`),
|
|
141
|
+
status: expectString(object.status, `${path}.status`),
|
|
142
|
+
externalAccountLabel: expectNullableString(object.externalAccountLabel, `${path}.externalAccountLabel`),
|
|
143
|
+
metadata: expectRecord(object.metadata, `${path}.metadata`),
|
|
144
|
+
createdAt: expectString(object.createdAt, `${path}.createdAt`),
|
|
145
|
+
updatedAt: expectString(object.updatedAt, `${path}.updatedAt`),
|
|
146
|
+
lastSyncedAt: expectString(object.lastSyncedAt, `${path}.lastSyncedAt`),
|
|
147
|
+
lastVerifiedAt: expectNullableString(object.lastVerifiedAt, `${path}.lastVerifiedAt`),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function decodeCatalog(value: unknown, path = "catalog"): PlatformCatalog {
|
|
152
|
+
const object = expectObject(value, path);
|
|
153
|
+
return {
|
|
154
|
+
toolkits: expectArray(object.toolkits, `${path}.toolkits`).map((entry, index) => decodeToolkit(entry, `${path}.toolkits[${index}]`)),
|
|
155
|
+
actions: expectArray(object.actions, `${path}.actions`).map((entry, index) => decodeAction(entry, `${path}.actions[${index}]`)),
|
|
156
|
+
lastSyncedAt: expectNullableString(object.lastSyncedAt, `${path}.lastSyncedAt`),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function decodeConnectionsEnvelope(value: unknown): PlatformConnection[] {
|
|
161
|
+
const object = expectObject(value, "response");
|
|
162
|
+
return expectArray(object.connections, "response.connections").map((entry, index) => decodeConnection(entry, `response.connections[${index}]`));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function decodeActionsEnvelope(value: unknown): PlatformAction[] {
|
|
166
|
+
const object = expectObject(value, "response");
|
|
167
|
+
return expectArray(object.actions, "response.actions").map((entry, index) => decodeAction(entry, `response.actions[${index}]`));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function decodeToolConnection(value: unknown, path: string): PlatformToolConnection {
|
|
171
|
+
const object = expectObject(value, path);
|
|
172
|
+
return {
|
|
173
|
+
id: expectString(object.id, `${path}.id`),
|
|
174
|
+
label: expectString(object.label, `${path}.label`),
|
|
175
|
+
toolkitSlug: expectString(object.toolkitSlug, `${path}.toolkitSlug`),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function decodeToolDefinition(value: unknown, path: string): PlatformToolDefinition {
|
|
180
|
+
const object = expectObject(value, path);
|
|
181
|
+
return {
|
|
182
|
+
id: expectString(object.id, `${path}.id`),
|
|
183
|
+
actionSlug: expectString(object.actionSlug, `${path}.actionSlug`),
|
|
184
|
+
toolkitSlug: expectString(object.toolkitSlug, `${path}.toolkitSlug`),
|
|
185
|
+
name: expectString(object.name, `${path}.name`),
|
|
186
|
+
description: expectString(object.description, `${path}.description`),
|
|
187
|
+
inputSchema: expectRecord(object.inputSchema, `${path}.inputSchema`),
|
|
188
|
+
outputSchema: expectRecord(object.outputSchema, `${path}.outputSchema`),
|
|
189
|
+
requireApproval: expectBoolean(object.requireApproval, `${path}.requireApproval`),
|
|
190
|
+
connections: expectArray(object.connections, `${path}.connections`).map((entry, index) => decodeToolConnection(entry, `${path}.connections[${index}]`)),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function decodeToolsEnvelope(value: unknown): PlatformToolDefinition[] {
|
|
195
|
+
const object = expectObject(value, "response");
|
|
196
|
+
return expectArray(object.tools, "response.tools").map((entry, index) => decodeToolDefinition(entry, `response.tools[${index}]`));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function decodeConnectLink(value: unknown): ConnectLinkResult {
|
|
200
|
+
const object = expectObject(value, "response");
|
|
201
|
+
return {
|
|
202
|
+
toolkitSlug: expectString(object.toolkitSlug, "response.toolkitSlug"),
|
|
203
|
+
connectionRequestId: expectString(object.connectionRequestId, "response.connectionRequestId"),
|
|
204
|
+
redirectUrl: expectString(object.redirectUrl, "response.redirectUrl"),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function decodeActionResult(value: unknown): PlatformActionResult {
|
|
209
|
+
const object = expectObject(value, "response");
|
|
210
|
+
return {
|
|
211
|
+
actionSlug: expectString(object.actionSlug, "response.actionSlug"),
|
|
212
|
+
toolkitSlug: expectString(object.toolkitSlug, "response.toolkitSlug"),
|
|
213
|
+
connectionId: expectString(object.connectionId, "response.connectionId"),
|
|
214
|
+
version: expectNullableString(object.version, "response.version"),
|
|
215
|
+
result: cloneUnknown(object.result),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function validateOptionalStringArray(value: unknown, path: string): string[] | undefined {
|
|
220
|
+
return optionalStringArray(value, path);
|
|
221
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"rootDir": "src",
|
|
6
|
+
"outDir": "dist",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"noEmit": false,
|
|
9
|
+
"incremental": false
|
|
10
|
+
},
|
|
11
|
+
"include": [
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"exclude": [
|
|
15
|
+
"src/__tests__"
|
|
16
|
+
]
|
|
17
|
+
}
|