@permute/sdk 0.6.0 → 0.8.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/client.js CHANGED
@@ -3,6 +3,7 @@ export { PermuteApiError } from './errors.js';
3
3
  import { Ajv } from 'ajv';
4
4
  import { createHash } from 'node:crypto';
5
5
  import { publicApiRoutes } from './generated/runtime-contract.js';
6
+ import { SdkMethodFactory } from './method.js';
6
7
  const DEFAULT_BASE_URL = 'https://api.permute.ai';
7
8
  const DEFAULT_POLL_TIMEOUT_MS = 20 * 60 * 1000;
8
9
  function routeFor(operationId) {
@@ -250,11 +251,14 @@ export class PermuteFileDataset {
250
251
  }
251
252
  }
252
253
  export class PermuteClient {
254
+ permissions;
255
+ accessRequests;
253
256
  revisions;
254
257
  facts;
255
258
  skills;
256
259
  organizationSkills;
257
260
  actions;
261
+ emails;
258
262
  databases;
259
263
  apps;
260
264
  connectorSessions;
@@ -266,17 +270,18 @@ export class PermuteClient {
266
270
  dashboards;
267
271
  datasets;
268
272
  apiKey;
273
+ accessToken;
269
274
  baseUrl;
270
275
  /** Workspace selected for workspace-scoped API operations. */
271
276
  workspaceId;
272
277
  defaultHeaders;
273
278
  fetchImpl;
274
279
  constructor(options) {
275
- if (!options.apiKey) {
280
+ if ((!options.apiKey && !options.accessToken) || (options.apiKey && options.accessToken)) {
276
281
  throw new PermuteApiError({
277
282
  status: 0,
278
283
  code: 'missing_api_key',
279
- message: 'apiKey is required',
284
+ message: 'Provide apiKey or accessToken',
280
285
  });
281
286
  }
282
287
  const fetchImpl = options.fetch ?? globalThis.fetch;
@@ -288,56 +293,85 @@ export class PermuteClient {
288
293
  });
289
294
  }
290
295
  this.apiKey = options.apiKey;
296
+ this.accessToken = options.accessToken;
291
297
  this.baseUrl = options.baseUrl ?? DEFAULT_BASE_URL;
292
298
  this.workspaceId = options.workspaceId;
293
299
  this.defaultHeaders = options.headers ?? {};
294
300
  this.fetchImpl = fetchImpl.bind(globalThis);
301
+ this.permissions = {
302
+ update: this.bindMethod('permissionsUpdate', (request) => (permissionId, body, options) => request({ pathParams: { permissionId }, body }, options)),
303
+ list: this.bindMethod('permissionsList', (request) => (query, options) => request({ query }, options)),
304
+ create: this.bindMethod('permissionsCreate', (request) => (body, options) => request({ body }, options)),
305
+ delete: this.bindMethod('permissionsDelete', (request) => (permissionId, options) => request({ pathParams: { permissionId } }, options)),
306
+ inspect: this.bindMethod('permissionsInspect', (request) => (body, options) => request({ body }, options)),
307
+ };
308
+ this.accessRequests = {
309
+ create: this.bindMethod('accessRequestsCreate', (request) => (body, options) => request({ body }, options)),
310
+ list: this.bindMethod('accessRequestsList', (request) => (query, options) => request({ query }, options)),
311
+ get: this.bindMethod('accessRequestsGet', (request) => (requestId, options) => request({ pathParams: { requestId } }, options)),
312
+ decide: this.bindMethod('accessRequestsDecide', (request) => (requestId, body, options) => request({ pathParams: { requestId }, body }, options)),
313
+ };
295
314
  this.revisions = {
296
- list: (resourceId, options) => this.request('resourceRevisionsList', { pathParams: { resourceId } }, options),
297
- get: (resourceId, revisionId, options) => this.request('resourceRevisionsGet', { pathParams: { resourceId, revisionId } }, options),
298
- restore: (resourceId, revisionId, body, options) => this.request('resourceRevisionsRestore', { pathParams: { resourceId, revisionId }, body }, options),
299
- publish: (resourceId, body, options) => this.request('resourcesPublish', { pathParams: { resourceId }, body }, options),
315
+ list: this.bindMethod('resourceRevisionsList', (apiRequest) => (resourceId, options) => apiRequest({ pathParams: { resourceId } }, options)),
316
+ get: this.bindMethod('resourceRevisionsGet', (apiRequest) => (resourceId, revisionId, options) => apiRequest({ pathParams: { resourceId, revisionId } }, options)),
317
+ restore: this.bindMethod('resourceRevisionsRestore', (apiRequest) => (resourceId, revisionId, body, options) => apiRequest({ pathParams: { resourceId, revisionId }, body }, options)),
318
+ publish: this.bindMethod('resourcesPublish', (apiRequest) => (resourceId, body, options) => apiRequest({ pathParams: { resourceId }, body }, options)),
300
319
  };
301
320
  this.facts = {
302
- list: (options) => this.request('factsList', {}, options),
303
- get: (factId, options) => this.request('factsGet', { pathParams: { factId } }, options),
304
- create: (body, options) => this.request('factsCreate', { body }, options),
305
- update: (factId, body, options) => this.request('factsUpdate', { pathParams: { factId }, body }, options),
306
- delete: (factId, options) => this.request('factsDelete', { pathParams: { factId } }, options),
321
+ list: this.bindMethod('factsList', (apiRequest) => (options) => apiRequest({}, options)),
322
+ get: this.bindMethod('factsGet', (apiRequest) => (factId, options) => apiRequest({ pathParams: { factId } }, options)),
323
+ create: this.bindMethod('factsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
324
+ update: this.bindMethod('factsUpdate', (apiRequest) => (factId, body, options) => apiRequest({ pathParams: { factId }, body }, options)),
325
+ delete: this.bindMethod('factsDelete', (apiRequest) => (factId, options) => apiRequest({ pathParams: { factId } }, options)),
307
326
  };
308
327
  const skillsClient = (prefix) => ({
309
- list: (options) => this.request(`${prefix}List`, {}, options),
310
- get: (path, options) => this.request(`${prefix}Get`, { pathParams: { path } }, options),
311
- update: (path, body, options) => this.request(`${prefix}Update`, { pathParams: { path }, body }, options),
312
- delete: (path, options) => this.request(`${prefix}Delete`, { pathParams: { path } }, options),
328
+ list: this.bindMethod(`${prefix}List`, (apiRequest) => (options) => apiRequest({}, options)),
329
+ get: this.bindMethod(`${prefix}Get`, (apiRequest) => (path, options) => apiRequest({ pathParams: { path } }, options)),
330
+ update: this.bindMethod(`${prefix}Update`, (apiRequest) => (path, body, options) => apiRequest({ pathParams: { path }, body }, options)),
331
+ delete: this.bindMethod(`${prefix}Delete`, (apiRequest) => (path, options) => apiRequest({ pathParams: { path } }, options)),
313
332
  });
314
333
  this.skills = skillsClient('skills');
315
334
  this.organizationSkills = skillsClient('organizationSkills');
316
335
  this.actions = {
317
- list: (options) => this.request('actionsList', {}, options),
318
- create: (body, options) => this.request('actionsCreate', { body }, options),
319
- get: (actionId, options) => this.request('actionsGet', { pathParams: { actionId } }, options),
320
- delete: (actionId, options) => this.request('actionsDelete', { pathParams: { actionId } }, options),
321
- definition: (actionId, options) => this.request('actionDefinitionGet', { pathParams: { actionId } }, options),
322
- saveDefinition: (actionId, body, options) => this.request('actionDefinitionSave', { pathParams: { actionId }, body }, options),
323
- invoke: (actionId, body, options) => this.request('actionsInvoke', { pathParams: { actionId }, body }, options),
336
+ requestPublication: this.bindMethod('actionsPublicationRequestsCreate', (apiRequest) => (actionId, body, options) => apiRequest({ pathParams: { actionId }, body }, options)),
337
+ publicationRequests: this.bindMethod('actionsPublicationRequestsList', (apiRequest) => (actionId, options) => apiRequest({ pathParams: { actionId } }, options)),
338
+ decidePublication: this.bindMethod('actionsPublicationRequestsDecide', (apiRequest) => (actionId, requestId, body, options) => apiRequest({ pathParams: { actionId, requestId }, body }, options)),
339
+ list: this.bindMethod('actionsList', (apiRequest) => (options) => apiRequest({}, options)),
340
+ create: this.bindMethod('actionsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
341
+ get: this.bindMethod('actionsGet', (apiRequest) => (actionId, options) => apiRequest({ pathParams: { actionId } }, options)),
342
+ delete: this.bindMethod('actionsDelete', (apiRequest) => (actionId, options) => apiRequest({ pathParams: { actionId } }, options)),
343
+ definition: this.bindMethod('actionDefinitionGet', (apiRequest) => (actionId, options) => apiRequest({ pathParams: { actionId } }, options)),
344
+ saveDefinition: this.bindMethod('actionDefinitionSave', (apiRequest) => (actionId, body, options) => apiRequest({ pathParams: { actionId }, body }, options)),
345
+ invoke: this.bindMethod('actionsInvoke', (apiRequest) => (actionId, body, options) => apiRequest({ pathParams: { actionId }, body }, options)),
346
+ };
347
+ this.emails = {
348
+ get: this.bindMethod('emailsGet', (request) => (options) => request({}, options)),
349
+ send: this.bindMethod('emailsSend', (request) => (body, options) => request({ body }, options)),
324
350
  };
325
351
  this.databases = {
326
- list: (options) => this.request('databasesList', {}, options),
327
- create: (body, options) => this.request('databasesCreate', { body }, options),
328
- get: (databaseId, options) => this.request('databasesGet', { pathParams: { databaseId } }, options),
329
- delete: (databaseId, options) => this.request('databasesDelete', { pathParams: { databaseId } }, options),
330
- definition: (databaseId, options) => this.request('databaseDefinitionGet', { pathParams: { databaseId } }, options),
331
- saveDefinition: (databaseId, body, options) => this.request('databaseDefinitionSave', { pathParams: { databaseId }, body }, options),
332
- tables: (databaseId, options) => this.request('databaseTablesList', { pathParams: { databaseId } }, options),
333
- createTable: (databaseId, body, options) => this.request('databaseTablesCreate', { pathParams: { databaseId }, body }, options),
334
- records: (databaseId, table, query = {}, options) => this.request('databaseRecordsList', { pathParams: { databaseId, table }, query }, options),
335
- transact: (databaseId, body, options) => this.request('databaseTransactionsCreate', { pathParams: { databaseId }, body }, options),
352
+ list: this.bindMethod('databasesList', (apiRequest) => (options) => apiRequest({}, options)),
353
+ create: this.bindMethod('databasesCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
354
+ get: this.bindMethod('databasesGet', (apiRequest) => (databaseId, options) => apiRequest({ pathParams: { databaseId } }, options)),
355
+ delete: this.bindMethod('databasesDelete', (apiRequest) => (databaseId, options) => apiRequest({ pathParams: { databaseId } }, options)),
356
+ definition: this.bindMethod('databaseDefinitionGet', (apiRequest) => (databaseId, options) => apiRequest({ pathParams: { databaseId } }, options)),
357
+ saveDefinition: this.bindMethod('databaseDefinitionSave', (apiRequest) => (databaseId, body, options) => apiRequest({ pathParams: { databaseId }, body }, options)),
358
+ tables: this.bindMethod('databaseTablesList', (apiRequest) => (databaseId, options) => apiRequest({ pathParams: { databaseId } }, options)),
359
+ createTable: this.bindMethod('databaseTablesCreate', (apiRequest) => (databaseId, body, options) => apiRequest({ pathParams: { databaseId }, body }, options)),
360
+ records: this.bindMethod('databaseRecordsList', (apiRequest) => (databaseId, table, query = {}, options) => apiRequest({ pathParams: { databaseId, table }, query }, options)),
361
+ transact: this.bindMethod('databaseTransactionsCreate', (apiRequest) => (databaseId, body, options) => apiRequest({ pathParams: { databaseId }, body }, options)),
336
362
  };
337
363
  this.apps = {
338
- listGrants: (applicationId, options) => this.request('appsGrantsList', { pathParams: { applicationId } }, options),
339
- setGrant: (applicationId, resourceId, body, options) => this.request('appsGrantsSet', { pathParams: { applicationId, resourceId }, body }, options),
340
- prepareUploads: (applicationId, body, options) => this.request('appsUploadsCreate', { pathParams: { applicationId }, body }, options),
364
+ requestPublication: this.bindMethod('appsPublicationRequestsCreate', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
365
+ publicationRequests: this.bindMethod('appsPublicationRequestsList', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
366
+ decidePublication: this.bindMethod('appsPublicationRequestsDecide', (apiRequest) => (applicationId, requestId, body, options) => apiRequest({ pathParams: { applicationId, requestId }, body }, options)),
367
+ sourceFile: this.bindMethod('appsSourceFileGet', (apiRequest) => (applicationId, query, options) => apiRequest({ pathParams: { applicationId }, query }, options)),
368
+ address: this.bindMethod('appsAddressGet', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
369
+ setAddress: this.bindMethod('appsAddressSet', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
370
+ access: this.bindMethod('appsAccessGet', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
371
+ setAccess: this.bindMethod('appsAccessSet', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
372
+ listGrants: this.bindMethod('appsGrantsList', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
373
+ setGrant: this.bindMethod('appsGrantsSet', (apiRequest) => (applicationId, resourceId, body, options) => apiRequest({ pathParams: { applicationId, resourceId }, body }, options)),
374
+ prepareUploads: this.bindMethod('appsUploadsCreate', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
341
375
  uploadFiles: async (applicationId, files, options) => {
342
376
  const contents = await Promise.all(files.map(async (file) => ({
343
377
  path: file.path,
@@ -373,71 +407,73 @@ export class PermuteClient {
373
407
  }
374
408
  return manifest;
375
409
  },
376
- saveSite: (applicationId, body, options) => this.request('appsSiteUpdate', { pathParams: { applicationId }, body }, options),
377
- list: (options) => this.request('appsList', {}, options),
378
- create: (body, options) => this.request('appsCreate', { body }, options),
379
- get: (applicationId, options) => this.request('appsGet', { pathParams: { applicationId } }, options),
380
- update: (applicationId, body, options) => this.request('appsUpdate', { pathParams: { applicationId }, body }, options),
381
- delete: (applicationId, options) => this.request('appsDelete', { pathParams: { applicationId } }, options),
410
+ saveSite: this.bindMethod('appsSiteUpdate', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
411
+ list: this.bindMethod('appsList', (apiRequest) => (options) => apiRequest({}, options)),
412
+ create: this.bindMethod('appsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
413
+ get: this.bindMethod('appsGet', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
414
+ update: this.bindMethod('appsUpdate', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
415
+ delete: this.bindMethod('appsDelete', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
382
416
  };
383
417
  this.connectorSessions = {
384
- create: (body, options) => this.request('connectorSessionsCreate', { body }, options),
385
- get: (sessionId, options) => this.request('connectorSessionsGet', { pathParams: { sessionId } }, options),
418
+ create: this.bindMethod('connectorSessionsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
419
+ get: this.bindMethod('connectorSessionsGet', (apiRequest) => (sessionId, options) => apiRequest({ pathParams: { sessionId } }, options)),
386
420
  };
387
421
  this.writeSyncs = {
388
- list: (options) => this.request('writeSyncsList', {}, options),
389
- create: (body, options) => this.request('writeSyncsCreate', { body }, options),
390
- get: (writeSyncId, options) => this.request('writeSyncsGet', { pathParams: { writeSyncId } }, options),
391
- update: (writeSyncId, body, options) => this.request('writeSyncsUpdate', { pathParams: { writeSyncId }, body }, options),
392
- delete: (writeSyncId, options) => this.request('writeSyncsDelete', { pathParams: { writeSyncId } }, options),
393
- destinations: (options) => this.request('writeSyncsDestinations', {}, options),
394
- preview: (writeSyncId, options) => this.request('writeSyncsPreview', { pathParams: { writeSyncId } }, options),
395
- pause: (writeSyncId, options) => this.request('writeSyncsPause', { pathParams: { writeSyncId } }, options),
396
- listRuns: (writeSyncId, options) => this.request('writeSyncsListRuns', { pathParams: { writeSyncId } }, options),
397
- getRun: (writeSyncId, runId, query = {}, options) => this.request('writeSyncsGetRun', { pathParams: { writeSyncId, runId }, query }, options),
398
- execute: (writeSyncId, runId, options) => this.request('writeSyncsExecute', { pathParams: { writeSyncId, runId } }, options),
422
+ list: this.bindMethod('writeSyncsList', (apiRequest) => (options) => apiRequest({}, options)),
423
+ create: this.bindMethod('writeSyncsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
424
+ get: this.bindMethod('writeSyncsGet', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
425
+ update: this.bindMethod('writeSyncsUpdate', (apiRequest) => (writeSyncId, body, options) => apiRequest({ pathParams: { writeSyncId }, body }, options)),
426
+ delete: this.bindMethod('writeSyncsDelete', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
427
+ destinations: this.bindMethod('writeSyncsDestinations', (apiRequest) => (options) => apiRequest({}, options)),
428
+ preview: this.bindMethod('writeSyncsPreview', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
429
+ pause: this.bindMethod('writeSyncsPause', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
430
+ listRuns: this.bindMethod('writeSyncsListRuns', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
431
+ getRun: this.bindMethod('writeSyncsGetRun', (apiRequest) => (writeSyncId, runId, query = {}, options) => apiRequest({ pathParams: { writeSyncId, runId }, query }, options)),
432
+ execute: this.bindMethod('writeSyncsExecute', (apiRequest) => (writeSyncId, runId, options) => apiRequest({ pathParams: { writeSyncId, runId } }, options)),
399
433
  };
400
434
  this.workspaces = {
401
- list: (requestOptions) => this.request('workspacesList', {}, requestOptions),
402
- create: (request, requestOptions) => this.request('workspacesCreate', { body: request }, requestOptions),
403
- get: (workspaceId, requestOptions) => this.request('workspacesGet', { pathParams: { workspaceId } }, requestOptions),
404
- update: (workspaceId, request, requestOptions) => this.request('workspacesUpdate', { pathParams: { workspaceId }, body: request }, requestOptions),
405
- delete: (workspaceId, requestOptions) => this.request('workspacesDelete', { pathParams: { workspaceId } }, requestOptions),
435
+ list: this.bindMethod('workspacesList', (apiRequest) => (requestOptions) => apiRequest({}, requestOptions)),
436
+ create: this.bindMethod('workspacesCreate', (apiRequest) => (request, requestOptions) => apiRequest({ body: request }, requestOptions)),
437
+ get: this.bindMethod('workspacesGet', (apiRequest) => (workspaceId, requestOptions) => apiRequest({ pathParams: { workspaceId } }, requestOptions)),
438
+ update: this.bindMethod('workspacesUpdate', (apiRequest) => (workspaceId, request, requestOptions) => apiRequest({ pathParams: { workspaceId }, body: request }, requestOptions)),
439
+ delete: this.bindMethod('workspacesDelete', (apiRequest) => (workspaceId, requestOptions) => apiRequest({ pathParams: { workspaceId } }, requestOptions)),
406
440
  };
407
441
  this.sources = {
408
- list: (requestOptions) => this.request('sourcesList', {}, requestOptions),
409
- get: (sourceId, requestOptions) => this.request('sourcesGet', { pathParams: { sourceId } }, requestOptions),
410
- listTables: async (sourceId, requestOptions) => (await this.request('sourcesGet', {
442
+ list: this.bindMethod('sourcesList', (apiRequest) => (requestOptions) => apiRequest({}, requestOptions)),
443
+ get: this.bindMethod('sourcesGet', (apiRequest) => (sourceId, requestOptions) => apiRequest({ pathParams: { sourceId } }, requestOptions)),
444
+ listTables: this.bindMethod('sourcesGet', (apiRequest) => async (sourceId, requestOptions) => (await apiRequest({
411
445
  pathParams: { sourceId },
412
446
  query: { includeFields: 'false' },
413
- }, requestOptions)).tables,
414
- describeTable: async (sourceId, tableId, requestOptions) => (await this.request('sourcesGet', {
447
+ }, requestOptions)).tables),
448
+ describeTable: this.bindMethod('sourcesGet', (apiRequest) => async (sourceId, tableId, requestOptions) => (await apiRequest({
415
449
  pathParams: { sourceId },
416
450
  query: { tableId },
417
- }, requestOptions)).tables[0],
451
+ }, requestOptions)).tables[0]),
418
452
  };
453
+ const listOperationRuns = this.bindMethod('operationsRunsList', (apiRequest) => (operationId, options) => apiRequest({ pathParams: { operationId } }, options));
454
+ const listWorkflowRuns = this.bindMethod('operationRunsList', (apiRequest) => (query, options) => apiRequest({ query }, options));
419
455
  this.operations = {
420
- list: (query = {}, options) => this.request('operationsList', { query }, options),
421
- get: (operationId, options) => this.request('operationsGet', { pathParams: { operationId } }, options),
422
- update: (operationId, body, options) => this.request('operationsUpdate', { pathParams: { operationId }, body }, options),
423
- getSource: (operationId, options) => this.request('operationsSourceGet', { pathParams: { operationId } }, options),
424
- updateSource: (operationId, body, options) => this.request('operationsSourceUpdate', { pathParams: { operationId }, body }, options),
425
- getRunOutput: (operationId, runId, options) => this.request('operationsRunOutput', { pathParams: { operationId, runId } }, options),
426
- listRuns: ((input, options) => typeof input === 'string'
427
- ? this.request('operationsRunsList', { pathParams: { operationId: input } }, options)
428
- : this.request('operationRunsList', { query: input }, options)),
429
- run: (operationId, body, options) => this.request('operationsRun', { pathParams: { operationId }, body }, options),
456
+ list: this.bindMethod('operationsList', (apiRequest) => (query = {}, options) => apiRequest({ query }, options)),
457
+ get: this.bindMethod('operationsGet', (apiRequest) => (operationId, options) => apiRequest({ pathParams: { operationId } }, options)),
458
+ update: this.bindMethod('operationsUpdate', (apiRequest) => (operationId, body, options) => apiRequest({ pathParams: { operationId }, body }, options)),
459
+ getSource: this.bindMethod('operationsSourceGet', (apiRequest) => (operationId, options) => apiRequest({ pathParams: { operationId } }, options)),
460
+ updateSource: this.bindMethod('operationsSourceUpdate', (apiRequest) => (operationId, body, options) => apiRequest({ pathParams: { operationId }, body }, options)),
461
+ getRunOutput: this.bindMethod('operationsRunOutput', (apiRequest) => (operationId, runId, options) => apiRequest({ pathParams: { operationId, runId } }, options)),
462
+ listRuns: SdkMethodFactory.compose([listOperationRuns, listWorkflowRuns], ((input, options) => typeof input === 'string'
463
+ ? listOperationRuns(input, options)
464
+ : listWorkflowRuns(input, options))),
465
+ run: this.bindMethod('operationsRun', (apiRequest) => (operationId, body, options) => apiRequest({ pathParams: { operationId }, body }, options)),
430
466
  };
431
467
  this.dataFlows = {
432
- create: (body, options) => this.request('dataFlowsCreate', { body }, options),
433
- get: (dataFlowId, options) => this.request('dataFlowsGet', { pathParams: { dataFlowId } }, options),
434
- command: (dataFlowId, body, options) => this.request('dataFlowsCommand', { pathParams: { dataFlowId }, body }, options),
468
+ create: this.bindMethod('dataFlowsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
469
+ get: this.bindMethod('dataFlowsGet', (apiRequest) => (dataFlowId, options) => apiRequest({ pathParams: { dataFlowId } }, options)),
470
+ command: this.bindMethod('dataFlowsCommand', (apiRequest) => (dataFlowId, body, options) => apiRequest({ pathParams: { dataFlowId }, body }, options)),
435
471
  };
436
472
  this.dashboards = {
437
- getSource: (dashboardId, requestOptions) => this.request('dashboardsSourceGet', { pathParams: { dashboardId } }, requestOptions),
438
- updateSource: (dashboardId, request, requestOptions) => this.request('dashboardsSourceUpdate', { pathParams: { dashboardId }, body: request }, requestOptions),
473
+ getSource: this.bindMethod('dashboardsSourceGet', (apiRequest) => (dashboardId, requestOptions) => apiRequest({ pathParams: { dashboardId } }, requestOptions)),
474
+ updateSource: this.bindMethod('dashboardsSourceUpdate', (apiRequest) => (dashboardId, request, requestOptions) => apiRequest({ pathParams: { dashboardId }, body: request }, requestOptions)),
439
475
  };
440
- const readDataset = (datasetId, requestOptions) => this.request('datasetsGet', { pathParams: { datasetId } }, requestOptions);
476
+ const readDataset = this.bindMethod('datasetsGet', (apiRequest) => (datasetId, requestOptions) => apiRequest({ pathParams: { datasetId } }, requestOptions));
441
477
  const writeDatasetTables = async (datasetId, request, requestOptions) => {
442
478
  const encoded = encodeDatasetWrite(request);
443
479
  const body = request.mode === 'replace'
@@ -505,9 +541,9 @@ export class PermuteClient {
505
541
  const wrapDataset = (dataset) => dataset.type === 'custom'
506
542
  ? new PermuteDataset(dataset, writeDatasetTables, readDataset)
507
543
  : new PermuteFileDataset(dataset, readDataset);
508
- const createDataset = async (request, requestOptions) => {
544
+ const createDataset = this.bindMethod('datasetsCreate', (apiRequest) => async (request, requestOptions) => {
509
545
  if (request.type === 'custom') {
510
- const dataset = await this.request('datasetsCreate', { body: request }, requestOptions);
546
+ const dataset = await apiRequest({ body: request }, requestOptions);
511
547
  return new PermuteDataset(requireCustomDataset(dataset), writeDatasetTables, readDataset);
512
548
  }
513
549
  const { data, headers, sizeBytes: declaredSize, ...createRequest } = request;
@@ -524,10 +560,10 @@ export class PermuteClient {
524
560
  throw new PermuteApiError({
525
561
  status: 0,
526
562
  code: 'missing_file_size',
527
- message: 'sizeBytes is required when the SDK cannot determine the upload body size',
563
+ message: 'sizeBytes is required without data or when the upload body size cannot be inferred',
528
564
  });
529
565
  }
530
- const response = await this.request('datasetsCreate', { body: { ...createRequest, sizeBytes } }, requestOptions);
566
+ const response = await apiRequest({ body: { ...createRequest, sizeBytes } }, requestOptions);
531
567
  const dataset = new PermuteFileDataset(requireFileDataset(response), readDataset);
532
568
  const target = dataset.data.upload;
533
569
  if (!target) {
@@ -537,6 +573,8 @@ export class PermuteClient {
537
573
  message: `Dataset ${dataset.id} did not include a file upload target`,
538
574
  });
539
575
  }
576
+ if (data === undefined)
577
+ return dataset;
540
578
  const uploadResponse = await this.fetchImpl(target.url, {
541
579
  method: target.method,
542
580
  headers: { ...headers, ...target.headers },
@@ -551,27 +589,28 @@ export class PermuteClient {
551
589
  });
552
590
  }
553
591
  return dataset;
554
- };
592
+ });
555
593
  this.datasets = {
556
594
  create: createDataset,
557
- getByKey: async (key, requestOptions) => {
558
- const dataset = await this.request('datasetsGetByKey', { query: { key } }, requestOptions);
595
+ getByKey: this.bindMethod('datasetsGetByKey', (apiRequest) => async (key, requestOptions) => {
596
+ const dataset = await apiRequest({ query: { key } }, requestOptions);
559
597
  return wrapDataset(dataset);
560
- },
598
+ }),
561
599
  get: async (datasetId, requestOptions) => {
562
600
  const dataset = await readDataset(datasetId, requestOptions);
563
601
  return wrapDataset(dataset);
564
602
  },
565
- download: async (datasetId, requestOptions) => {
566
- const { url } = await this.request('datasetsDownload', { pathParams: { datasetId } }, requestOptions);
603
+ download: this.bindMethod('datasetsDownload', (apiRequest) => async (datasetId, requestOptions) => {
604
+ const { url } = await apiRequest({ pathParams: { datasetId } }, requestOptions);
567
605
  return url;
568
- },
569
- delete: (datasetId, requestOptions) => this.request('datasetsDelete', { pathParams: { datasetId } }, requestOptions),
606
+ }),
607
+ delete: this.bindMethod('datasetsDelete', (apiRequest) => (datasetId, requestOptions) => apiRequest({ pathParams: { datasetId } }, requestOptions)),
570
608
  };
609
+ this.apps.uploadFiles = SdkMethodFactory.compose([this.apps.prepareUploads], this.apps.uploadFiles);
610
+ this.datasets.get = SdkMethodFactory.compose([readDataset], this.datasets.get);
611
+ this.answer = SdkMethodFactory.compose([this.answerJobs, this.getAnswerJob], this.answer.bind(this));
571
612
  }
572
- async search(request, options) {
573
- return await this.request('searchCreate', { body: request }, options);
574
- }
613
+ search = this.bindMethod('searchCreate', (apiRequest) => (request, options) => apiRequest({ body: request }, options));
575
614
  async answer(request, options) {
576
615
  let job = await this.answerJobs(request, options);
577
616
  const deadline = pollingDeadline(options);
@@ -594,33 +633,31 @@ export class PermuteClient {
594
633
  message: job.error ?? `Answer job ${job.status}`,
595
634
  });
596
635
  }
597
- async answerJobs(request, options) {
598
- return await this.request('answerJobsCreate', { body: request }, options);
599
- }
600
- async getAnswerJob(answerJobId, options) {
601
- return await this.request('answerJobsGet', { pathParams: { answerJobId } }, options);
602
- }
636
+ answerJobs = this.bindMethod('answerJobsCreate', (apiRequest) => (request, options) => apiRequest({ body: request }, options));
637
+ getAnswerJob = this.bindMethod('answerJobsGet', (apiRequest) => (answerJobId, options) => apiRequest({ pathParams: { answerJobId } }, options));
603
638
  withWorkspace(workspaceId) {
604
639
  if (!workspaceId.trim()) {
605
640
  throw new PermuteApiError({ status: 0, code: 'missing_workspace_id', message: 'workspaceId is required' });
606
641
  }
607
642
  return new PermuteClient({
608
643
  apiKey: this.apiKey,
644
+ accessToken: this.accessToken,
609
645
  baseUrl: this.baseUrl,
610
646
  workspaceId,
611
647
  fetch: this.fetchImpl,
612
648
  headers: this.defaultHeaders,
613
649
  });
614
650
  }
615
- async query(request, options) {
616
- return await this.request('queriesCreate', { body: request }, options);
651
+ query = this.bindMethod('queriesCreate', (apiRequest) => (request, options) => apiRequest({ body: request }, options));
652
+ bindMethod(operationId, create) {
653
+ return SdkMethodFactory.create(operationId, create((input, options) => this.request(operationId, input, options)));
617
654
  }
618
655
  async request(operationId, input, options) {
619
656
  const route = routeFor(operationId);
620
657
  const body = this.validateRequestBody(route, operationId, input.body);
621
658
  const query = this.validateRequestQuery(route, operationId, input.query);
622
659
  const headers = {
623
- Authorization: `Bearer ${this.apiKey}`,
660
+ Authorization: `Bearer ${this.accessToken ? await this.accessToken() : this.apiKey}`,
624
661
  ...this.defaultHeaders,
625
662
  ...options?.headers,
626
663
  };
package/dist/deploy.d.ts CHANGED
@@ -1,15 +1,89 @@
1
1
  import type { PermuteClient } from './client.js';
2
- import type { AppSiteSaveRequest, PermuteRequestOptions } from './types.js';
2
+ import type { AppSiteSaveRequest, AppSource, PermuteRequestOptions } from './types.js';
3
3
  export interface DeployAppOptions {
4
4
  appId: string;
5
5
  directory: string;
6
+ /** Original project files and the instructions used to compile directory. */
7
+ source: {
8
+ directory: string;
9
+ build: AppSource['build'];
10
+ };
6
11
  /** Defaults to true. */
7
12
  spa?: boolean;
8
- /** Explicitly approve replacing this exact draft. Omit to require a clean published app. */
9
- expectedDraft?: AppSiteSaveRequest['expectedDraft'];
13
+ /** Token from checkout or a reviewed app draft. Never infer the base of local source from newer remote work. */
14
+ expectedDraft: AppSiteSaveRequest['expectedDraft'];
10
15
  /** Omit to preserve bindings; [] removes them. Revisions must already be published. */
11
16
  actions?: AppSiteSaveRequest['actions'];
12
17
  }
18
+ /** Save a shared source checkpoint without compiling or publishing. */
19
+ export declare function saveAppSource(client: PermuteClient, options: {
20
+ appId: string;
21
+ source: DeployAppOptions['source'];
22
+ expectedDraft: AppSiteSaveRequest['expectedDraft'];
23
+ }, requestOptions?: PermuteRequestOptions): Promise<{
24
+ chat?: {
25
+ enabled: boolean;
26
+ };
27
+ createdAt: string;
28
+ deployment: {
29
+ error: string | null;
30
+ revisionId: string;
31
+ status: 'deploying' | 'live' | 'deleting' | 'failed' | 'deleted';
32
+ url: string;
33
+ } | null;
34
+ description: string;
35
+ draft: {
36
+ revisionId: string;
37
+ sequence: number;
38
+ };
39
+ favicon?: {
40
+ path: string;
41
+ sha256: string;
42
+ size: number;
43
+ } | null;
44
+ id: string;
45
+ login?: {
46
+ header?: string;
47
+ primaryColor?: string;
48
+ secondaryColor?: string;
49
+ sidePanelImage?: {
50
+ path: string;
51
+ sha256: string;
52
+ size: number;
53
+ };
54
+ subheader?: string;
55
+ subtitle?: string;
56
+ title?: string;
57
+ } | null;
58
+ name: string;
59
+ updatedAt: string;
60
+ workspaceId: string;
61
+ }>;
62
+ /** Materialize the draft or an exact historical source revision into a new folder. Never overwrites files. */
63
+ export declare function checkoutApp(client: PermuteClient, options: {
64
+ appId: string;
65
+ directory: string;
66
+ revisionId?: string;
67
+ }, requestOptions?: PermuteRequestOptions): Promise<{
68
+ revisionId: string;
69
+ source: {
70
+ build: {
71
+ command: string;
72
+ outputDirectory: string;
73
+ runtime: string;
74
+ };
75
+ files: {
76
+ executable?: boolean;
77
+ path: string;
78
+ sha256: string;
79
+ size: number;
80
+ }[];
81
+ };
82
+ expectedDraft: {
83
+ revisionId: string;
84
+ sequence: number;
85
+ } | null;
86
+ }>;
13
87
  /** Upload, save, and publish an existing live app. Builds and provisions nothing; never retries mutations. */
14
88
  export declare function deployApp(client: PermuteClient, options: DeployAppOptions, requestOptions?: PermuteRequestOptions): Promise<{
15
89
  url: string;