@powersync/management-client 0.0.0-dev.85b697f3

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/index.js ADDED
@@ -0,0 +1,411 @@
1
+ import * as sdk from '@journeyapps-labs/common-sdk';
2
+ import { routes } from '@powersync/management-types';
3
+ const dev = routes.DEV_ROUTES;
4
+ const manage = routes.MANAGE_ROUTES;
5
+ const general = routes.GENERAL_ROUTES;
6
+ const report = routes.REPORT_ROUTES;
7
+ export class PowerSyncManagementClient extends sdk.SDKClient {
8
+ /**
9
+ * Lists all PowerSync instances for a given organization and application.
10
+ *
11
+ * @returns Promise resolving to a list of instances with their IDs, names, config status, and deployability
12
+ * @example
13
+ * ```typescript
14
+ * const response = await client.listInstances({
15
+ * org_id: 'org-123',
16
+ * app_id: 'app-456'
17
+ * });
18
+ * console.log(response.instances); // Array of instance objects
19
+ * ```
20
+ */
21
+ listInstances = this.createEndpoint({
22
+ path: manage.LIST
23
+ });
24
+ /**
25
+ * Creates a new PowerSync instance.
26
+ *
27
+ * @returns Promise resolving to the created instance ID
28
+ * @example
29
+ * ```typescript
30
+ * const response = await client.createInstance({
31
+ * org_id: 'org-123',
32
+ * app_id: 'app-456',
33
+ * name: 'my-instance',
34
+ * region: 'us'
35
+ * });
36
+ * console.log(response.id); // The new instance ID
37
+ * ```
38
+ */
39
+ createInstance = this.createEndpoint({
40
+ path: manage.CREATE
41
+ });
42
+ /**
43
+ * Destroys a PowerSync instance. This is a permanent operation.
44
+ *
45
+ * @returns Promise resolving to the destroyed instance ID and optional operation ID
46
+ * @example
47
+ * ```typescript
48
+ * const response = await client.destroyInstance({
49
+ * org_id: 'org-123',
50
+ * app_id: 'app-456',
51
+ * id: 'instance-789'
52
+ * });
53
+ * console.log(response.id); // The destroyed instance ID
54
+ * ```
55
+ */
56
+ destroyInstance = this.createEndpoint({
57
+ path: manage.DESTROY
58
+ });
59
+ /**
60
+ * Deactivates a PowerSync instance without destroying it.
61
+ *
62
+ * @returns Promise resolving to the deactivated instance ID and optional operation ID
63
+ * @example
64
+ * ```typescript
65
+ * const response = await client.deactivateInstance({
66
+ * org_id: 'org-123',
67
+ * app_id: 'app-456',
68
+ * id: 'instance-789'
69
+ * });
70
+ * console.log(response.id); // The deactivated instance ID
71
+ * ```
72
+ */
73
+ deactivateInstance = this.createEndpoint({
74
+ path: manage.DEACTIVATE
75
+ });
76
+ /**
77
+ * Deploys a PowerSync instance with the specified configuration.
78
+ *
79
+ * @returns Promise resolving to the instance ID and operation ID for tracking deployment
80
+ * @example
81
+ * ```typescript
82
+ * const response = await client.deployInstance({
83
+ * org_id: 'org-123',
84
+ * app_id: 'app-456',
85
+ * id: 'instance-789',
86
+ * name: 'my-instance',
87
+ * config: {
88
+ * region: 'us',
89
+ * replication: {
90
+ * connections: [/* connection config *\/]
91
+ * }
92
+ * },
93
+ * sync_rules: 'SELECT * FROM users',
94
+ * program_version: {
95
+ * channel: 'stable',
96
+ * version_range: '^1.0.0'
97
+ * }
98
+ * });
99
+ * console.log(response.operation_id); // Track deployment progress
100
+ * ```
101
+ */
102
+ deployInstance = this.createEndpoint({
103
+ path: manage.DEPLOY
104
+ });
105
+ /**
106
+ * Retrieves the configuration for a PowerSync instance.
107
+ * This endpoint is retryable.
108
+ *
109
+ * @returns Promise resolving to the instance configuration including config, sync_rules, and program_version
110
+ * @example
111
+ * ```typescript
112
+ * const response = await client.getInstanceConfig({
113
+ * org_id: 'org-123',
114
+ * app_id: 'app-456',
115
+ * id: 'instance-789'
116
+ * });
117
+ * console.log(response.config); // The instance configuration
118
+ * console.log(response.sync_rules); // The sync rules
119
+ * ```
120
+ */
121
+ getInstanceConfig = this.createEndpoint({
122
+ path: manage.CONFIG,
123
+ retryable: true
124
+ });
125
+ /**
126
+ * Gets the provisioning status and deployment operations for a PowerSync instance.
127
+ * This endpoint is retryable.
128
+ *
129
+ * @returns Promise resolving to instance status including provisioned flag, operations array, and optional instance_url
130
+ * @example
131
+ * ```typescript
132
+ * const response = await client.getInstanceStatus({
133
+ * org_id: 'org-123',
134
+ * app_id: 'app-456',
135
+ * id: 'instance-789'
136
+ * });
137
+ * console.log(response.provisioned); // true if instance is provisioned
138
+ * console.log(response.operations); // Array of deployment operations
139
+ * ```
140
+ */
141
+ getInstanceStatus = this.createEndpoint({
142
+ path: manage.STATUS,
143
+ retryable: true
144
+ });
145
+ /**
146
+ * Gets diagnostic information for a PowerSync instance.
147
+ * Only works if the instance is already provisioned.
148
+ * This endpoint is retryable.
149
+ *
150
+ * @returns Promise resolving to diagnostic information
151
+ * @example
152
+ * ```typescript
153
+ * const response = await client.getInstanceDiagnostics({
154
+ * org_id: 'org-123',
155
+ * app_id: 'app-456',
156
+ * id: 'instance-789'
157
+ * });
158
+ * // Diagnostic information about the instance
159
+ * ```
160
+ */
161
+ getInstanceDiagnostics = this.createEndpoint({
162
+ path: manage.DIAGNOSTICS,
163
+ retryable: true
164
+ });
165
+ /**
166
+ * Triggers a compaction operation on a PowerSync instance.
167
+ *
168
+ * @returns Promise resolving to the instance ID and optional operation ID
169
+ * @example
170
+ * ```typescript
171
+ * const response = await client.compact({
172
+ * org_id: 'org-123',
173
+ * app_id: 'app-456',
174
+ * id: 'instance-789'
175
+ * });
176
+ * console.log(response.operation_id); // Track compaction progress
177
+ * ```
178
+ */
179
+ compact = this.createEndpoint({
180
+ path: manage.COMPACT
181
+ });
182
+ /**
183
+ * Tests a database connection without deploying an instance.
184
+ * Validates connectivity and configuration for the specified connection.
185
+ *
186
+ * @returns Promise resolving to connection test results including success status, connection details, and optional configuration details
187
+ * @example
188
+ * ```typescript
189
+ * const response = await client.testConnection({
190
+ * org_id: 'org-123',
191
+ * app_id: 'app-456',
192
+ * connection: {
193
+ * type: 'postgres',
194
+ * uri: 'postgresql://user:pass@host:5432/db'
195
+ * }
196
+ * });
197
+ * console.log(response.success); // true if connection test passed
198
+ * console.log(response.connection.reachable); // true if TCP connection works
199
+ * ```
200
+ */
201
+ testConnection = this.createEndpoint({
202
+ path: dev.TEST_CONNECTION
203
+ });
204
+ /**
205
+ * Gets the database schema for a PowerSync instance.
206
+ * Only works if the instance is already provisioned.
207
+ * This endpoint is retryable.
208
+ *
209
+ * @returns Promise resolving to the instance schema including connections, tables, and columns
210
+ * @example
211
+ * ```typescript
212
+ * const response = await client.getInstanceSchema({
213
+ * org_id: 'org-123',
214
+ * app_id: 'app-456',
215
+ * id: 'instance-789'
216
+ * });
217
+ * console.log(response.connections); // Array of connection schemas
218
+ * ```
219
+ */
220
+ getInstanceSchema = this.createEndpoint({
221
+ path: dev.GET_SCHEMA,
222
+ retryable: true
223
+ });
224
+ /**
225
+ * Executes SQL queries on a PowerSync instance.
226
+ * Only works if the instance is already provisioned.
227
+ *
228
+ * @returns Promise resolving to SQL execution results
229
+ * @example
230
+ * ```typescript
231
+ * const response = await client.executeSql({
232
+ * org_id: 'org-123',
233
+ * app_id: 'app-456',
234
+ * id: 'instance-789',
235
+ * sql: 'SELECT * FROM users WHERE id = ?',
236
+ * parameters: ['user-123']
237
+ * });
238
+ * // SQL query results
239
+ * ```
240
+ */
241
+ executeSql = this.createEndpoint({
242
+ path: dev.EXECUTE_SQL
243
+ });
244
+ /**
245
+ * Validates sync rules for a PowerSync instance.
246
+ * Only works if the instance is already provisioned.
247
+ *
248
+ * @returns Promise resolving to validation results
249
+ * @example
250
+ * ```typescript
251
+ * const response = await client.validateSyncRules({
252
+ * org_id: 'org-123',
253
+ * app_id: 'app-456',
254
+ * id: 'instance-789',
255
+ * sync_rules: 'SELECT * FROM users'
256
+ * });
257
+ * // Validation results
258
+ * ```
259
+ */
260
+ validateSyncRules = this.createEndpoint({
261
+ path: dev.VALIDATE_SYNC_RULES
262
+ });
263
+ /**
264
+ * Reprocesses sync rules for a PowerSync instance.
265
+ * Only works if the instance is already provisioned.
266
+ *
267
+ * @returns Promise resolving to reprocessing results
268
+ * @example
269
+ * ```typescript
270
+ * const response = await client.reprocessSyncRules({
271
+ * org_id: 'org-123',
272
+ * app_id: 'app-456',
273
+ * id: 'instance-789',
274
+ * sync_rules: 'SELECT * FROM users'
275
+ * });
276
+ * // Reprocessing results
277
+ * ```
278
+ */
279
+ reprocessSyncRules = this.createEndpoint({
280
+ path: dev.REPROCESS_SYNC_RULES
281
+ });
282
+ /**
283
+ * Generates a development token for a PowerSync instance.
284
+ *
285
+ * @returns Promise resolving to the generated JWT token
286
+ * @example
287
+ * ```typescript
288
+ * const response = await client.generateDevToken({
289
+ * org_id: 'org-123',
290
+ * app_id: 'app-456',
291
+ * id: 'instance-789',
292
+ * subject: 'user-123',
293
+ * expiresInSeconds: 3600
294
+ * });
295
+ * console.log(response.token); // The JWT token
296
+ * ```
297
+ */
298
+ generateDevToken = this.createEndpoint({
299
+ path: dev.GENERATE_DEV_TOKEN
300
+ });
301
+ /**
302
+ * Lists available regions for PowerSync deployments.
303
+ * Returns region information including IP addresses for whitelisting.
304
+ *
305
+ * @returns Promise resolving to a list of regions with their names, deployability status, and IP addresses
306
+ * @example
307
+ * ```typescript
308
+ * const response = await client.listRegions({});
309
+ * console.log(response.regions); // Array of region objects with IPs for whitelisting
310
+ * ```
311
+ */
312
+ listRegions = this.createEndpoint({
313
+ path: general.LIST_REGIONS,
314
+ method: 'get'
315
+ });
316
+ /**
317
+ * Lists available PowerSync program versions for a channel.
318
+ *
319
+ * @returns Promise resolving to an array of versions with their status (current, available, or deprecated)
320
+ * @example
321
+ * ```typescript
322
+ * const response = await client.listVersionsV({
323
+ * channel: 'stable'
324
+ * });
325
+ * console.log(response); // Array of version objects with status
326
+ * ```
327
+ */
328
+ listVersions = this.createEndpoint({
329
+ path: general.LIST_VERSIONS_V2
330
+ });
331
+ /**
332
+ * Gets client connection reports for a PowerSync instance within a date range.
333
+ *
334
+ * @returns Promise resolving to connection report data including user counts and SDK breakdowns
335
+ * @example
336
+ * ```typescript
337
+ * const response = await client.getClientConnectionReports({
338
+ * org_id: 'org-123',
339
+ * app_id: 'app-456',
340
+ * id: 'instance-789',
341
+ * start: '2024-01-01T00:00:00Z',
342
+ * end: '2024-01-31T23:59:59Z'
343
+ * });
344
+ * console.log(response.users); // Total number of users
345
+ * console.log(response.sdks); // Array of SDK connection reports
346
+ * ```
347
+ */
348
+ getClientConnectionReports = this.createEndpoint({
349
+ path: report.GET_CLIENT_CONNECTION_DATA
350
+ });
351
+ /**
352
+ * Gets currently connected clients for a PowerSync instance.
353
+ *
354
+ * @returns Promise resolving to current connection data including user counts and SDK breakdowns
355
+ * @example
356
+ * ```typescript
357
+ * const response = await client.getConnectedClients({
358
+ * org_id: 'org-123',
359
+ * app_id: 'app-456',
360
+ * id: 'instance-789'
361
+ * });
362
+ * console.log(response.users); // Number of currently connected users
363
+ * console.log(response.sdks); // Array of current SDK connections
364
+ * ```
365
+ */
366
+ getConnectedClients = this.createEndpoint({
367
+ path: report.GET_CURRENT_CONNECTIONS
368
+ });
369
+ /**
370
+ * Gets paginated general client connection analytics for a PowerSync instance.
371
+ * Returns connection events including connect/disconnect times, user agents, and SDK information.
372
+ *
373
+ * @returns Promise resolving to paginated connection analytics events. Also includes a `paginate` method for iterating through all pages.
374
+ * @example
375
+ * ```typescript
376
+ * // Single page request
377
+ * const response = await client.getGeneralClientConnectionAnalytics({
378
+ * org_id: 'org-123',
379
+ * app_id: 'app-456',
380
+ * id: 'instance-789',
381
+ * date_range: {
382
+ * start: '2024-01-01T00:00:00Z',
383
+ * end: '2024-01-31T23:59:59Z'
384
+ * },
385
+ * limit: 100
386
+ * });
387
+ * console.log(response.items); // Array of connection events
388
+ * console.log(response.total); // Total number of events
389
+ * console.log(response.more); // true if there are more pages
390
+ * console.log(response.cursor); // cursor for the next page
391
+ *
392
+ * // Iterate through all pages
393
+ * for await (const page of client.getGeneralClientConnectionAnalytics.paginate({
394
+ * org_id: 'org-123',
395
+ * app_id: 'app-456',
396
+ * id: 'instance-789',
397
+ * date_range: {
398
+ * start: '2024-01-01T00:00:00Z',
399
+ * end: '2024-01-31T23:59:59Z'
400
+ * },
401
+ * limit: 100
402
+ * })) {
403
+ * console.log(page.items); // Process each page
404
+ * }
405
+ * ```
406
+ */
407
+ getGeneralClientConnectionAnalytics = sdk.createPaginatedEndpoint(this.createEndpoint({
408
+ path: report.GET_GENERAL_CLIENT_ANALYTICS
409
+ }));
410
+ }
411
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC;AAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;AACpC,MAAM,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,MAAM,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;AAEpC,MAAM,OAAO,yBAA2E,SAAQ,GAAG,CAAC,SAAY;IAC9G;;;;;;;;;;;;OAYG;IACH,aAAa,GAAG,IAAI,CAAC,cAAc,CAA4D;QAC7F,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC,CAAC;IAEH;;;;;;;;;;;;;;OAcG;IACH,cAAc,GAAG,IAAI,CAAC,cAAc,CAA8D;QAChG,IAAI,EAAE,MAAM,CAAC,MAAM;KACpB,CAAC,CAAC;IAEH;;;;;;;;;;;;;OAaG;IACH,eAAe,GAAG,IAAI,CAAC,cAAc,CAAgE;QACnG,IAAI,EAAE,MAAM,CAAC,OAAO;KACrB,CAAC,CAAC;IAEH;;;;;;;;;;;;;OAaG;IACH,kBAAkB,GAAG,IAAI,CAAC,cAAc,CAAsE;QAC5G,IAAI,EAAE,MAAM,CAAC,UAAU;KACxB,CAAC,CAAC;IAEH;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,cAAc,GAAG,IAAI,CAAC,cAAc,CAA8D;QAChG,IAAI,EAAE,MAAM,CAAC,MAAM;KACpB,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AAC,oBAAoB;KAC/B,CAAC,CAAC;IAEH;;;;;;;;;;;;;;;OAeG;IACH,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAkE;QACtG,IAAI,EAAE,GAAG,CAAC,kBAAkB;KAC7B,CAAC,CAAC;IAEH;;;;;;;;;;OAUG;IACH,WAAW,GAAG,IAAI,CAAC,cAAc,CAAmC;QAClE,IAAI,EAAE,OAAO,CAAC,YAAY;QAC1B,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;IAEH;;;;;;;;;;;OAWG;IACH,YAAY,GAAG,IAAI,CAAC,cAAc,CAA8D;QAC9F,IAAI,EAAE,OAAO,CAAC,gBAAgB;KAC/B,CAAC,CAAC;IAEH;;;;;;;;;;;;;;;;OAgBG;IACH,0BAA0B,GAAG,IAAI,CAAC,cAAc,CAG9C;QACA,IAAI,EAAE,MAAM,CAAC,0BAA0B;KACxC,CAAC,CAAC;IAEH;;;;;;;;;;;;;;OAcG;IACH,mBAAmB,GAAG,IAAI,CAAC,cAAc,CAA2E;QAClH,IAAI,EAAE,MAAM,CAAC,uBAAuB;KACrC,CAAC,CAAC;IAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,mCAAmC,GAAG,GAAG,CAAC,uBAAuB,CAC/D,IAAI,CAAC,cAAc,CAAyF;QAC1G,IAAI,EAAE,MAAM,CAAC,4BAA4B;KAC1C,CAAC,CACH,CAAC;CACH"}
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@powersync/management-client",
3
+ "version": "0.0.0-dev.85b697f3",
4
+ "description": "A TypeScript client for the PowerSync Management Service API",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "license": "FSL-1.1-ALv2",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "files": [
13
+ "dist/**/*"
14
+ ],
15
+ "keywords": [],
16
+ "author": "POWERSYNC",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+ssh://git@github.com/journeyapps-platform/powersync.git",
20
+ "directory": "public-packages/client"
21
+ },
22
+ "dependencies": {
23
+ "@journeyapps-labs/common-sdk": "^1.0.2",
24
+ "@powersync/management-types": "0.0.0-dev.85b697f3"
25
+ },
26
+ "devDependencies": {
27
+ "@types/json-schema": "^7.0.15"
28
+ },
29
+ "scripts": {
30
+ "build": "tsc -b",
31
+ "clean": "rm -rf ./dist && tsc -b --clean"
32
+ }
33
+ }