@gokiteam/goki-dev-client 0.2.2

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.
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /**
3
+ * @gokiteam/goki-dev - Helper Utilities
4
+ *
5
+ * Common test helpers and utilities
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.waitFor = waitFor;
9
+ exports.sleep = sleep;
10
+ exports.verifyAcrossServices = verifyAcrossServices;
11
+ exports.findErrorLogs = findErrorLogs;
12
+ exports.createTestContext = createTestContext;
13
+ exports.runTest = runTest;
14
+ const client_1 = require("./client");
15
+ /**
16
+ * Wait for async operation with custom polling
17
+ */
18
+ async function waitFor(predicate, options = {}) {
19
+ const timeout = options.timeout || 5000;
20
+ const interval = options.interval || 100;
21
+ const start = Date.now();
22
+ while (Date.now() - start < timeout) {
23
+ const result = await predicate();
24
+ if (result !== null) {
25
+ return result;
26
+ }
27
+ await new Promise(resolve => setTimeout(resolve, interval));
28
+ }
29
+ throw new Error(options.timeoutMessage || `Timeout after ${timeout}ms`);
30
+ }
31
+ /**
32
+ * Sleep for specified milliseconds
33
+ */
34
+ function sleep(ms) {
35
+ return new Promise(resolve => setTimeout(resolve, ms));
36
+ }
37
+ async function verifyAcrossServices(client, traceId, expectations) {
38
+ const results = {};
39
+ // Database verification
40
+ if (expectations.database) {
41
+ const dbResult = await client.postgres.query({
42
+ ...expectations.database,
43
+ traceId
44
+ });
45
+ results.database = dbResult.rows;
46
+ }
47
+ // Redis verification
48
+ if (expectations.redis) {
49
+ const redisResult = await client.redis.get({ key: expectations.redis.key, traceId });
50
+ results.redis = redisResult.value ? JSON.parse(redisResult.value) : null;
51
+ }
52
+ // Pub/Sub verification
53
+ if (expectations.pubsub) {
54
+ const pubsubResult = await client.pubsub.getMessages({ filter: expectations.pubsub.filter, traceId });
55
+ results.pubsub = pubsubResult.messages;
56
+ }
57
+ // Firestore verification
58
+ if (expectations.firestore) {
59
+ const firestoreResult = await client.firestore.getDocument({
60
+ collection: expectations.firestore.collection,
61
+ documentId: expectations.firestore.documentId,
62
+ traceId
63
+ });
64
+ results.firestore = firestoreResult.document;
65
+ }
66
+ // Logging verification
67
+ if (expectations.logging) {
68
+ const logsResult = await client.logging.getByTrace({ traceId });
69
+ results.logs = logsResult.entries;
70
+ }
71
+ return results;
72
+ }
73
+ /**
74
+ * Find error logs in a trace
75
+ */
76
+ async function findErrorLogs(client, traceId) {
77
+ const logs = await client.logging.getByTrace({ traceId });
78
+ return logs.entries.filter((e) => e.severity === 'ERROR' || e.severity === 'CRITICAL');
79
+ }
80
+ async function createTestContext(clientConfig) {
81
+ const client = new client_1.DevToolsClient(clientConfig);
82
+ const traceId = client.generateTraceId('test');
83
+ const cleanup = [];
84
+ return {
85
+ client,
86
+ traceId,
87
+ cleanup
88
+ };
89
+ }
90
+ async function runTest(name, testFn, clientConfig) {
91
+ console.log(`\nRunning: ${name}`);
92
+ const ctx = await createTestContext(clientConfig);
93
+ try {
94
+ await testFn(ctx);
95
+ console.log(`Passed: ${name}`);
96
+ }
97
+ catch (error) {
98
+ console.error(`Failed: ${name}`);
99
+ console.error(error);
100
+ // Export data on failure
101
+ try {
102
+ const exportData = await ctx.client.platform.export({ traceId: ctx.traceId });
103
+ console.log(`Test data exported for debugging`);
104
+ console.log(JSON.stringify(exportData, null, 2));
105
+ }
106
+ catch (exportError) {
107
+ console.error('Failed to export data:', exportError);
108
+ }
109
+ throw error;
110
+ }
111
+ finally {
112
+ // Run cleanup
113
+ for (const cleanupFn of ctx.cleanup) {
114
+ try {
115
+ await cleanupFn();
116
+ }
117
+ catch (error) {
118
+ console.error('Cleanup error:', error);
119
+ }
120
+ }
121
+ }
122
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * @gokiteam/goki-dev-client - Client SDK
3
+ *
4
+ * HTTP client for interacting with the Goki Developer Tools platform.
5
+ *
6
+ * @example Simple usage (singleton)
7
+ * ```typescript
8
+ * import { devTools } from '@gokiteam/goki-dev-client'
9
+ *
10
+ * const traceId = devTools.generateTraceId('user-login-test')
11
+ *
12
+ * // Wait for message
13
+ * const message = await devTools.pubsub.waitForMessage({
14
+ * filter: {
15
+ * topic: 'user-events',
16
+ * predicate: {
17
+ * jsonPath: '$.event',
18
+ * operator: 'equals',
19
+ * value: 'user-login'
20
+ * }
21
+ * },
22
+ * timeout: 5000,
23
+ * traceId
24
+ * })
25
+ *
26
+ * // Verify logs
27
+ * const errors = await devTools.logging.assertNoErrors({ traceId })
28
+ * ```
29
+ *
30
+ * @example Advanced usage (custom instance)
31
+ * ```typescript
32
+ * import { DevToolsClient } from '@gokiteam/goki-dev-client'
33
+ *
34
+ * const devTools = new DevToolsClient({
35
+ * baseUrl: 'http://custom-host:9000',
36
+ * timeout: 60000
37
+ * })
38
+ * ```
39
+ */
40
+ export { DevToolsClient } from './client';
41
+ export * from './types';
42
+ export * from './helpers';
43
+ import { DevToolsClient } from './client';
44
+ /**
45
+ * Default singleton instance of DevToolsClient
46
+ *
47
+ * Configured from environment variables:
48
+ * - DEV_TOOLS_BASE: Base URL (default: http://localhost:9000)
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { devTools } from '@gokiteam/goki-dev-client'
53
+ *
54
+ * const traceId = devTools.generateTraceId('test')
55
+ * const message = await devTools.pubsub.waitForMessage({ ... })
56
+ * const logs = await devTools.logging.getByTrace({ traceId })
57
+ * ```
58
+ */
59
+ export declare const devTools: DevToolsClient;
package/dist/index.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * @gokiteam/goki-dev-client - Client SDK
4
+ *
5
+ * HTTP client for interacting with the Goki Developer Tools platform.
6
+ *
7
+ * @example Simple usage (singleton)
8
+ * ```typescript
9
+ * import { devTools } from '@gokiteam/goki-dev-client'
10
+ *
11
+ * const traceId = devTools.generateTraceId('user-login-test')
12
+ *
13
+ * // Wait for message
14
+ * const message = await devTools.pubsub.waitForMessage({
15
+ * filter: {
16
+ * topic: 'user-events',
17
+ * predicate: {
18
+ * jsonPath: '$.event',
19
+ * operator: 'equals',
20
+ * value: 'user-login'
21
+ * }
22
+ * },
23
+ * timeout: 5000,
24
+ * traceId
25
+ * })
26
+ *
27
+ * // Verify logs
28
+ * const errors = await devTools.logging.assertNoErrors({ traceId })
29
+ * ```
30
+ *
31
+ * @example Advanced usage (custom instance)
32
+ * ```typescript
33
+ * import { DevToolsClient } from '@gokiteam/goki-dev-client'
34
+ *
35
+ * const devTools = new DevToolsClient({
36
+ * baseUrl: 'http://custom-host:9000',
37
+ * timeout: 60000
38
+ * })
39
+ * ```
40
+ */
41
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
42
+ if (k2 === undefined) k2 = k;
43
+ var desc = Object.getOwnPropertyDescriptor(m, k);
44
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
45
+ desc = { enumerable: true, get: function() { return m[k]; } };
46
+ }
47
+ Object.defineProperty(o, k2, desc);
48
+ }) : (function(o, m, k, k2) {
49
+ if (k2 === undefined) k2 = k;
50
+ o[k2] = m[k];
51
+ }));
52
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
53
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
54
+ };
55
+ Object.defineProperty(exports, "__esModule", { value: true });
56
+ exports.devTools = exports.DevToolsClient = void 0;
57
+ var client_1 = require("./client");
58
+ Object.defineProperty(exports, "DevToolsClient", { enumerable: true, get: function () { return client_1.DevToolsClient; } });
59
+ __exportStar(require("./types"), exports);
60
+ __exportStar(require("./helpers"), exports);
61
+ // Export default singleton instance for convenience
62
+ const client_2 = require("./client");
63
+ /**
64
+ * Default singleton instance of DevToolsClient
65
+ *
66
+ * Configured from environment variables:
67
+ * - DEV_TOOLS_BASE: Base URL (default: http://localhost:9000)
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import { devTools } from '@gokiteam/goki-dev-client'
72
+ *
73
+ * const traceId = devTools.generateTraceId('test')
74
+ * const message = await devTools.pubsub.waitForMessage({ ... })
75
+ * const logs = await devTools.logging.getByTrace({ traceId })
76
+ * ```
77
+ */
78
+ exports.devTools = new client_2.DevToolsClient();
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,339 @@
1
+ /**
2
+ * @gokiteam/goki-dev - Type Definitions
3
+ *
4
+ * TypeScript types for the Goki Developer Tools Client SDK
5
+ */
6
+ export interface StandardResponse<T = any> {
7
+ success: boolean;
8
+ status: number;
9
+ message: string;
10
+ data: T & {
11
+ traceId: string;
12
+ };
13
+ }
14
+ export interface PageOptions {
15
+ limit?: number;
16
+ offset?: number;
17
+ }
18
+ export interface TimeRange {
19
+ start: string;
20
+ end: string;
21
+ }
22
+ export interface PubSubMessage {
23
+ id: string;
24
+ message_id: string;
25
+ data: string;
26
+ attributes?: Record<string, string>;
27
+ ordering_key?: string;
28
+ publish_time: string;
29
+ topic: string;
30
+ sender?: string;
31
+ view_count: number;
32
+ last_viewed_at?: number;
33
+ created_at: number;
34
+ }
35
+ export interface PubSubTopic {
36
+ name: string;
37
+ labels?: Record<string, string>;
38
+ }
39
+ export interface PubSubSubscription {
40
+ name: string;
41
+ topic: string;
42
+ ackDeadlineSeconds: number;
43
+ pushConfig?: Record<string, any>;
44
+ }
45
+ export interface PubSubHistoryFilter {
46
+ topic?: string;
47
+ sender?: string;
48
+ timeRange?: TimeRange;
49
+ }
50
+ export type LogSeverity = 'DEFAULT' | 'DEBUG' | 'INFO' | 'NOTICE' | 'WARNING' | 'ERROR' | 'CRITICAL' | 'ALERT' | 'EMERGENCY';
51
+ export interface LogEntry {
52
+ logName: string;
53
+ resource: {
54
+ type: string;
55
+ labels: Record<string, string>;
56
+ };
57
+ timestamp: string;
58
+ severity: LogSeverity;
59
+ textPayload?: string;
60
+ jsonPayload?: Record<string, any>;
61
+ trace?: string;
62
+ insertId: string;
63
+ }
64
+ export interface LogFilter {
65
+ service?: string;
66
+ severity?: LogSeverity[];
67
+ timeRange?: TimeRange;
68
+ }
69
+ export interface PostgresQueryRequest {
70
+ database: string;
71
+ query: string;
72
+ params?: any[];
73
+ traceId?: string;
74
+ }
75
+ export interface PostgresQueryResponse {
76
+ rows: any[];
77
+ rowCount: number;
78
+ traceId: string;
79
+ }
80
+ export interface RedisKey {
81
+ key: string;
82
+ type: string;
83
+ ttl: number;
84
+ }
85
+ export interface RedisValue {
86
+ key: string;
87
+ type: string;
88
+ value: string;
89
+ ttl: number;
90
+ }
91
+ export interface FirestoreDocument {
92
+ id: string;
93
+ data: Record<string, any>;
94
+ }
95
+ export interface FirestoreQuery {
96
+ field: string;
97
+ op: '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'not-in' | 'array-contains';
98
+ value: any;
99
+ }
100
+ export interface FirestoreWhereClause {
101
+ field: string;
102
+ operator: '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'not-in' | 'array-contains';
103
+ value: any;
104
+ }
105
+ export interface DeleteByQueryRequest {
106
+ collection: string;
107
+ where: FirestoreWhereClause;
108
+ traceId?: string;
109
+ }
110
+ export interface DeleteByQueryResponse {
111
+ deletedCount: number;
112
+ traceId: string;
113
+ }
114
+ export interface DeleteByPrefixRequest {
115
+ collection: string;
116
+ prefix: string;
117
+ traceId?: string;
118
+ }
119
+ export interface DeleteByPrefixResponse {
120
+ deletedCount: number;
121
+ traceId: string;
122
+ }
123
+ export interface DeleteBatchRequest {
124
+ collection: string;
125
+ documentIds: string[];
126
+ traceId?: string;
127
+ }
128
+ export interface DeleteBatchResponse {
129
+ deletedCount: number;
130
+ failedIds: string[];
131
+ traceId: string;
132
+ }
133
+ export interface MqttClientInfo {
134
+ clientId: string;
135
+ connected: boolean;
136
+ connectedAt: string;
137
+ subscriptions: string[];
138
+ }
139
+ export interface MqttMessage {
140
+ clientId: string;
141
+ topic: string;
142
+ payload: string;
143
+ qos: 0 | 1 | 2;
144
+ timestamp: string;
145
+ }
146
+ export interface WaitForMessageRequest {
147
+ filter: {
148
+ topic: string;
149
+ predicate?: {
150
+ jsonPath: string;
151
+ operator: 'equals' | 'notEquals' | 'contains' | 'greaterThan' | 'lessThan';
152
+ value: any;
153
+ };
154
+ sender?: string;
155
+ };
156
+ timeout?: number;
157
+ traceId?: string;
158
+ }
159
+ export interface WaitForMessageResponse {
160
+ message: PubSubMessage;
161
+ foundAt: number;
162
+ traceId: string;
163
+ }
164
+ export interface WaitForLogRequest {
165
+ filter: {
166
+ traceId?: string;
167
+ service?: string;
168
+ severity?: LogSeverity;
169
+ textContains?: string;
170
+ };
171
+ timeout?: number;
172
+ traceId?: string;
173
+ }
174
+ export interface WaitForLogResponse {
175
+ entry: LogEntry;
176
+ foundAt: number;
177
+ traceId: string;
178
+ }
179
+ export interface WaitForConditionRequest {
180
+ type: 'postgres' | 'redis' | 'firestore';
181
+ condition: {
182
+ database?: string;
183
+ query?: string;
184
+ params?: any[];
185
+ key?: string;
186
+ collection?: string;
187
+ documentId?: string;
188
+ expect: Record<string, any>;
189
+ };
190
+ timeout?: number;
191
+ pollInterval?: number;
192
+ traceId?: string;
193
+ }
194
+ export interface WaitForConditionResponse {
195
+ met: boolean;
196
+ foundAt: number;
197
+ actualValue?: any;
198
+ traceId: string;
199
+ }
200
+ export interface AssertMessagePublishedRequest {
201
+ filter: {
202
+ topic: string;
203
+ since?: string;
204
+ dataContains?: string;
205
+ attributesMatch?: Record<string, string>;
206
+ };
207
+ traceId?: string;
208
+ }
209
+ export interface AssertMessagePublishedResponse {
210
+ found: boolean;
211
+ count: number;
212
+ firstMatch?: Partial<PubSubMessage>;
213
+ traceId: string;
214
+ }
215
+ export interface AssertNoErrorsRequest {
216
+ traceId: string;
217
+ sinceTimestamp?: string;
218
+ }
219
+ export interface AssertNoErrorsResponse {
220
+ hasErrors: boolean;
221
+ errorCount: number;
222
+ criticalCount: number;
223
+ errors?: Partial<LogEntry>[];
224
+ traceId: string;
225
+ }
226
+ export interface ClearServiceDataRequest {
227
+ services: ('pubsub' | 'logging' | 'mqtt' | 'redis' | 'postgres' | 'firestore')[];
228
+ keepSystemData?: boolean;
229
+ traceId?: string;
230
+ }
231
+ export interface ClearServiceDataResponse {
232
+ cleared: Record<string, number>;
233
+ traceId: string;
234
+ }
235
+ export interface SchedulerTickRequest {
236
+ traceId?: string;
237
+ }
238
+ export interface SchedulerTickResponse {
239
+ tickTime: string;
240
+ published: boolean;
241
+ traceId: string;
242
+ }
243
+ export interface PlatformStats {
244
+ topics: number;
245
+ subscriptions: number;
246
+ messages: number;
247
+ logEntries: number;
248
+ mqttClients: number;
249
+ mqttMessages: number;
250
+ }
251
+ export interface ExportData {
252
+ pubsub: {
253
+ topics: PubSubTopic[];
254
+ subscriptions: PubSubSubscription[];
255
+ messages: PubSubMessage[];
256
+ };
257
+ logging: {
258
+ entries: LogEntry[];
259
+ };
260
+ mqtt: {
261
+ clients: MqttClientInfo[];
262
+ messages: MqttMessage[];
263
+ };
264
+ }
265
+ export interface DockerContainer {
266
+ name: string;
267
+ containerName: string;
268
+ displayName: string;
269
+ description: string;
270
+ status: 'running' | 'stopped' | 'created' | 'restarting' | 'paused' | 'unknown';
271
+ statusText: string;
272
+ uptime: string | null;
273
+ ports: number | null;
274
+ image: string;
275
+ capabilities: {
276
+ canStart: boolean;
277
+ canStop: boolean;
278
+ canRestart: boolean;
279
+ };
280
+ }
281
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
282
+ export interface HttpTrafficEntry {
283
+ _id: string;
284
+ method: string;
285
+ targetUrl: string;
286
+ targetHost: string | null;
287
+ targetPath: string | null;
288
+ queryParams: string | null;
289
+ requestHeaders: string | null;
290
+ requestBody: string | null;
291
+ requestCookies: string | null;
292
+ contentType: string | null;
293
+ statusCode: number | null;
294
+ responseHeaders: string | null;
295
+ responseBody: string | null;
296
+ responseContentType: string | null;
297
+ responseTimeMs: number | null;
298
+ startedAt: string;
299
+ completedAt: string | null;
300
+ sourceService: string | null;
301
+ error: string | null;
302
+ traceId: string | null;
303
+ createdAt: string;
304
+ }
305
+ export interface HttpTrafficFilter {
306
+ method?: HttpMethod;
307
+ targetHost?: string;
308
+ sourceService?: string;
309
+ statusCode?: number;
310
+ traceId?: string;
311
+ since?: string;
312
+ until?: string;
313
+ }
314
+ export interface HttpTrafficWaitFilter {
315
+ method?: HttpMethod;
316
+ targetHost?: string;
317
+ sourceService?: string;
318
+ statusCode?: number;
319
+ traceId?: string;
320
+ pathContains?: string;
321
+ }
322
+ export interface HttpTrafficStats {
323
+ total: number;
324
+ errorCount: number;
325
+ errorRate: string;
326
+ avgResponseTimeMs: number;
327
+ byMethod: {
328
+ method: string;
329
+ count: number;
330
+ }[];
331
+ byHost: {
332
+ source_service: string | null;
333
+ count: number;
334
+ }[];
335
+ byStatus: {
336
+ status_code: number | null;
337
+ count: number;
338
+ }[];
339
+ }
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ /**
3
+ * @gokiteam/goki-dev - Type Definitions
4
+ *
5
+ * TypeScript types for the Goki Developer Tools Client SDK
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@gokiteam/goki-dev-client",
3
+ "version": "0.2.2",
4
+ "description": "Client SDK for Goki Developer Tools platform",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist/"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsc && echo '{\"type\":\"commonjs\"}' > dist/package.json",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "keywords": [
23
+ "goki",
24
+ "dev-tools",
25
+ "client",
26
+ "sdk"
27
+ ],
28
+ "author": "Goki Team",
29
+ "license": "UNLICENSED",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "dependencies": {
34
+ "axios": "^1.6.0"
35
+ },
36
+ "devDependencies": {
37
+ "typescript": "^5.9.3"
38
+ }
39
+ }