@permute/sdk 0.6.0 → 0.7.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.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { PermuteApiError } from './errors.js';
2
2
  import type { BusinessAction, BusinessActionList, ActionCreateRequest, ActionDefinition, ActionDefinitionSaveRequest, ActionDefinitionSaved, ActionRequest, ActionReceipt } from './types.js';
3
- import type { ConnectorSession, ConnectorSessionCreated, ConnectorSessionCreateRequest, Database, AppDraft, AppDraftList, AppCreateRequest, AppUpdateRequest, AppDeleted, AppUploadsRequest, AppUploads, AppSiteSaveRequest, AppGrants, AppGrantSetRequest, AppUploadFile, DatabaseList, DatabaseCreateRequest, DatabaseDefinition, DatabaseDefinitionSaveRequest, DatabaseDefinitionSaved, DatabaseTables, DatabaseTableCreateRequest, DatabaseTableCreated, DatabaseRecords, DatabaseRecordsQuery, DatabaseTransactionRequest, DatabaseTransactionReceipt, WriteSync, WriteSyncCreateRequest, WriteSyncUpdateRequest, WriteSyncDetail, WriteSyncList, WriteSyncDeleted, WriteSyncDestinations, WriteSyncRun, WriteSyncRunList, WriteSyncRunQuery, WriteSyncExecution, ResourceVersionState, ResourceRevisionList, ResourceRevision, ResourceVersionRequest, ResourcePublishRequest, Fact, FactList, FactWriteRequest, SkillList, SkillContent, SkillWriteRequest, KnowledgeWriteResponse, OperationRunGroup, OperationRunQuery, Operation, OperationList, OperationListQuery, OperationSource, OperationSourceUpdateRequest, OperationUpdateRequest, OperationRunRequest, OperationRunStarted, OperationRunList, OperationRunOutput, DataFlow, DataFlowCreateRequest, DataFlowCommandRequest, DataFlowCommandResponse, Workspace, WorkspaceCreateRequest, WorkspaceDeleteResponse, WorkspaceList, WorkspaceUpdateRequest, AnswerRequest, AnswerJobResponse, AnswerResponse, PermuteClientOptions, PermuteRequestOptions, QueryRequest, QueryResponse, SearchRequest, SearchResponse, SourceDetail, CatalogTable, SourceList, CustomDatasetCreateRequest, DatasetDeleteResponse, DatasetResponse, FileDatasetCreateRequest, FileDatasetResponse, DatasetRows, CustomDatasetResponse, DashboardSource, DashboardSourceUpdateRequest } from './types.js';
3
+ import type { ConnectorSession, ConnectorSessionCreated, ConnectorSessionCreateRequest, Database, AppDraft, AppAccess, AppAddressSettings, AppAddressSetRequest, AppAccessSetRequest, AppDraftList, AppCreateRequest, AppUpdateRequest, AppDeleted, AppUploadsRequest, AppUploads, AppSiteSaveRequest, AppSourceFileQuery, AppSourceFileContent, AppGrants, AppGrantSetRequest, AppUploadFile, DatabaseList, DatabaseCreateRequest, DatabaseDefinition, DatabaseDefinitionSaveRequest, DatabaseDefinitionSaved, DatabaseTables, DatabaseTableCreateRequest, DatabaseTableCreated, DatabaseRecords, DatabaseRecordsQuery, DatabaseTransactionRequest, DatabaseTransactionReceipt, WriteSync, WriteSyncCreateRequest, WriteSyncUpdateRequest, WriteSyncDetail, WriteSyncList, WriteSyncDeleted, WriteSyncDestinations, WriteSyncRun, WriteSyncRunList, WriteSyncRunQuery, WriteSyncExecution, ResourceVersionState, ResourceRevisionList, ResourceRevision, ResourceVersionRequest, ResourcePublishRequest, Fact, FactList, FactWriteRequest, SkillList, SkillContent, SkillWriteRequest, KnowledgeWriteResponse, OperationRunGroup, OperationRunQuery, Operation, OperationList, OperationListQuery, OperationSource, OperationSourceUpdateRequest, OperationUpdateRequest, OperationRunRequest, OperationRunStarted, OperationRunList, OperationRunOutput, DataFlow, DataFlowCreateRequest, DataFlowCommandRequest, DataFlowCommandResponse, Workspace, WorkspaceCreateRequest, WorkspaceDeleteResponse, WorkspaceList, WorkspaceUpdateRequest, AnswerRequest, AnswerResponse, PermuteClientOptions, PermuteRequestOptions, QueryRequest, SearchRequest, SourceDetail, CatalogTable, SourceList, CustomDatasetCreateRequest, DatasetDeleteResponse, DatasetResponse, FileDatasetCreateRequest, FileDatasetMetadataCreateRequest, FileDatasetResponse, DatasetRows, CustomDatasetResponse, DashboardSource, DashboardSourceUpdateRequest } from './types.js';
4
4
  type DatasetWriteInput = {
5
5
  tables: Record<string, DatasetRows>;
6
6
  mode: 'replace';
@@ -93,6 +93,10 @@ export declare class PermuteClient {
93
93
  transact(databaseId: string, body: DatabaseTransactionRequest, options?: PermuteRequestOptions): Promise<DatabaseTransactionReceipt>;
94
94
  };
95
95
  readonly apps: {
96
+ address(applicationId: string, options?: PermuteRequestOptions): Promise<AppAddressSettings>;
97
+ setAddress(applicationId: string, body: AppAddressSetRequest, options?: PermuteRequestOptions): Promise<AppAddressSettings>;
98
+ access(applicationId: string, options?: PermuteRequestOptions): Promise<AppAccess>;
99
+ setAccess(applicationId: string, body: AppAccessSetRequest, options?: PermuteRequestOptions): Promise<AppAccess>;
96
100
  listGrants(applicationId: string, options?: PermuteRequestOptions): Promise<AppGrants>;
97
101
  setGrant(applicationId: string, resourceId: string, body: AppGrantSetRequest, options?: PermuteRequestOptions): Promise<AppGrants>;
98
102
  list(options?: PermuteRequestOptions): Promise<AppDraftList>;
@@ -103,6 +107,7 @@ export declare class PermuteClient {
103
107
  prepareUploads(applicationId: string, body: AppUploadsRequest, options?: PermuteRequestOptions): Promise<AppUploads>;
104
108
  uploadFiles(applicationId: string, files: AppUploadFile[], options?: PermuteRequestOptions): Promise<AppUploadsRequest['files']>;
105
109
  saveSite(applicationId: string, body: AppSiteSaveRequest, options?: PermuteRequestOptions): Promise<AppDraft>;
110
+ sourceFile(applicationId: string, query: AppSourceFileQuery, options?: PermuteRequestOptions): Promise<AppSourceFileContent>;
106
111
  };
107
112
  readonly connectorSessions: {
108
113
  create(request: ConnectorSessionCreateRequest, options?: PermuteRequestOptions): Promise<ConnectorSessionCreated>;
@@ -158,6 +163,7 @@ export declare class PermuteClient {
158
163
  };
159
164
  readonly datasets: {
160
165
  create: {
166
+ (request: FileDatasetMetadataCreateRequest, options?: PermuteRequestOptions): Promise<PermuteFileDataset>;
161
167
  (request: CustomDatasetCreateRequest, options?: PermuteRequestOptions): Promise<PermuteDataset>;
162
168
  (request: FileDatasetCreateRequest, options?: PermuteRequestOptions): Promise<PermuteFileDataset>;
163
169
  };
@@ -173,12 +179,122 @@ export declare class PermuteClient {
173
179
  private readonly defaultHeaders;
174
180
  private readonly fetchImpl;
175
181
  constructor(options: PermuteClientOptions);
176
- search(request: SearchRequest, options?: PermuteRequestOptions): Promise<SearchResponse>;
182
+ search: (request: SearchRequest, options?: PermuteRequestOptions) => Promise<{
183
+ items: {
184
+ citation?: {
185
+ [key: string]: unknown;
186
+ };
187
+ content: string;
188
+ metadata?: {
189
+ [key: string]: unknown;
190
+ };
191
+ score?: number;
192
+ sourceId?: string;
193
+ title?: string;
194
+ type: "record" | "document" | "table" | "text_block" | "unknown";
195
+ }[];
196
+ meta: {
197
+ candidateCount?: number;
198
+ reranked: boolean;
199
+ strategy: "semantic";
200
+ totalMs?: number;
201
+ };
202
+ }>;
177
203
  answer(request: AnswerRequest, options?: PermuteRequestOptions): Promise<AnswerResponse>;
178
- answerJobs(request: AnswerRequest, options?: PermuteRequestOptions): Promise<AnswerJobResponse>;
179
- getAnswerJob(answerJobId: string, options?: PermuteRequestOptions): Promise<AnswerJobResponse>;
204
+ answerJobs: (request: AnswerRequest, options?: PermuteRequestOptions) => Promise<{
205
+ answerJobId: string;
206
+ completedAt?: string | null;
207
+ createdAt?: string;
208
+ error?: string;
209
+ pollAfterMs?: number;
210
+ result?: {
211
+ answer: string;
212
+ assumptions?: {
213
+ [key: string]: unknown;
214
+ }[];
215
+ charts?: {
216
+ [key: string]: unknown;
217
+ }[];
218
+ citations: {
219
+ metadata?: {
220
+ [key: string]: unknown;
221
+ };
222
+ ref?: string;
223
+ sourceId?: string;
224
+ title?: string;
225
+ type: "text" | "table" | "web" | "fact";
226
+ url?: string;
227
+ }[];
228
+ confidence?: {
229
+ queryComplexity: "high" | "medium" | "low";
230
+ reason: string;
231
+ score: number;
232
+ };
233
+ followUps?: string[];
234
+ };
235
+ startedAt?: string | null;
236
+ status: "queued" | "running" | "completed" | "failed" | "cancelled";
237
+ updatedAt?: string;
238
+ }>;
239
+ getAnswerJob: (answerJobId: string, options?: PermuteRequestOptions) => Promise<{
240
+ answerJobId: string;
241
+ completedAt?: string | null;
242
+ createdAt?: string;
243
+ error?: string;
244
+ pollAfterMs?: number;
245
+ result?: {
246
+ answer: string;
247
+ assumptions?: {
248
+ [key: string]: unknown;
249
+ }[];
250
+ charts?: {
251
+ [key: string]: unknown;
252
+ }[];
253
+ citations: {
254
+ metadata?: {
255
+ [key: string]: unknown;
256
+ };
257
+ ref?: string;
258
+ sourceId?: string;
259
+ title?: string;
260
+ type: "text" | "table" | "web" | "fact";
261
+ url?: string;
262
+ }[];
263
+ confidence?: {
264
+ queryComplexity: "high" | "medium" | "low";
265
+ reason: string;
266
+ score: number;
267
+ };
268
+ followUps?: string[];
269
+ };
270
+ startedAt?: string | null;
271
+ status: "queued" | "running" | "completed" | "failed" | "cancelled";
272
+ updatedAt?: string;
273
+ }>;
180
274
  withWorkspace(workspaceId: string): PermuteClient;
181
- query(request: QueryRequest, options?: PermuteRequestOptions): Promise<QueryResponse>;
275
+ query: (request: QueryRequest, options?: PermuteRequestOptions) => Promise<{
276
+ columns: {
277
+ name: string;
278
+ type?: string;
279
+ }[];
280
+ executionMs: number;
281
+ queryId: string;
282
+ rowCount: number;
283
+ rows: {
284
+ [key: string]: unknown;
285
+ }[];
286
+ sourceIds: string[];
287
+ sql: string;
288
+ timings?: {
289
+ initializationMs: number;
290
+ sourceLoadMs: number;
291
+ sourceValidationMs: number;
292
+ sqlExecutionMs: number;
293
+ totalMs: number;
294
+ };
295
+ truncated: boolean;
296
+ }>;
297
+ private bindMethod;
182
298
  private request;
183
299
  private validateRequestBody;
184
300
  private validateRequestQuery;
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) {
@@ -293,51 +294,56 @@ export class PermuteClient {
293
294
  this.defaultHeaders = options.headers ?? {};
294
295
  this.fetchImpl = fetchImpl.bind(globalThis);
295
296
  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),
297
+ list: this.bindMethod('resourceRevisionsList', (apiRequest) => (resourceId, options) => apiRequest({ pathParams: { resourceId } }, options)),
298
+ get: this.bindMethod('resourceRevisionsGet', (apiRequest) => (resourceId, revisionId, options) => apiRequest({ pathParams: { resourceId, revisionId } }, options)),
299
+ restore: this.bindMethod('resourceRevisionsRestore', (apiRequest) => (resourceId, revisionId, body, options) => apiRequest({ pathParams: { resourceId, revisionId }, body }, options)),
300
+ publish: this.bindMethod('resourcesPublish', (apiRequest) => (resourceId, body, options) => apiRequest({ pathParams: { resourceId }, body }, options)),
300
301
  };
301
302
  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),
303
+ list: this.bindMethod('factsList', (apiRequest) => (options) => apiRequest({}, options)),
304
+ get: this.bindMethod('factsGet', (apiRequest) => (factId, options) => apiRequest({ pathParams: { factId } }, options)),
305
+ create: this.bindMethod('factsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
306
+ update: this.bindMethod('factsUpdate', (apiRequest) => (factId, body, options) => apiRequest({ pathParams: { factId }, body }, options)),
307
+ delete: this.bindMethod('factsDelete', (apiRequest) => (factId, options) => apiRequest({ pathParams: { factId } }, options)),
307
308
  };
308
309
  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),
310
+ list: this.bindMethod(`${prefix}List`, (apiRequest) => (options) => apiRequest({}, options)),
311
+ get: this.bindMethod(`${prefix}Get`, (apiRequest) => (path, options) => apiRequest({ pathParams: { path } }, options)),
312
+ update: this.bindMethod(`${prefix}Update`, (apiRequest) => (path, body, options) => apiRequest({ pathParams: { path }, body }, options)),
313
+ delete: this.bindMethod(`${prefix}Delete`, (apiRequest) => (path, options) => apiRequest({ pathParams: { path } }, options)),
313
314
  });
314
315
  this.skills = skillsClient('skills');
315
316
  this.organizationSkills = skillsClient('organizationSkills');
316
317
  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),
318
+ list: this.bindMethod('actionsList', (apiRequest) => (options) => apiRequest({}, options)),
319
+ create: this.bindMethod('actionsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
320
+ get: this.bindMethod('actionsGet', (apiRequest) => (actionId, options) => apiRequest({ pathParams: { actionId } }, options)),
321
+ delete: this.bindMethod('actionsDelete', (apiRequest) => (actionId, options) => apiRequest({ pathParams: { actionId } }, options)),
322
+ definition: this.bindMethod('actionDefinitionGet', (apiRequest) => (actionId, options) => apiRequest({ pathParams: { actionId } }, options)),
323
+ saveDefinition: this.bindMethod('actionDefinitionSave', (apiRequest) => (actionId, body, options) => apiRequest({ pathParams: { actionId }, body }, options)),
324
+ invoke: this.bindMethod('actionsInvoke', (apiRequest) => (actionId, body, options) => apiRequest({ pathParams: { actionId }, body }, options)),
324
325
  };
325
326
  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),
327
+ list: this.bindMethod('databasesList', (apiRequest) => (options) => apiRequest({}, options)),
328
+ create: this.bindMethod('databasesCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
329
+ get: this.bindMethod('databasesGet', (apiRequest) => (databaseId, options) => apiRequest({ pathParams: { databaseId } }, options)),
330
+ delete: this.bindMethod('databasesDelete', (apiRequest) => (databaseId, options) => apiRequest({ pathParams: { databaseId } }, options)),
331
+ definition: this.bindMethod('databaseDefinitionGet', (apiRequest) => (databaseId, options) => apiRequest({ pathParams: { databaseId } }, options)),
332
+ saveDefinition: this.bindMethod('databaseDefinitionSave', (apiRequest) => (databaseId, body, options) => apiRequest({ pathParams: { databaseId }, body }, options)),
333
+ tables: this.bindMethod('databaseTablesList', (apiRequest) => (databaseId, options) => apiRequest({ pathParams: { databaseId } }, options)),
334
+ createTable: this.bindMethod('databaseTablesCreate', (apiRequest) => (databaseId, body, options) => apiRequest({ pathParams: { databaseId }, body }, options)),
335
+ records: this.bindMethod('databaseRecordsList', (apiRequest) => (databaseId, table, query = {}, options) => apiRequest({ pathParams: { databaseId, table }, query }, options)),
336
+ transact: this.bindMethod('databaseTransactionsCreate', (apiRequest) => (databaseId, body, options) => apiRequest({ pathParams: { databaseId }, body }, options)),
336
337
  };
337
338
  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),
339
+ sourceFile: this.bindMethod('appsSourceFileGet', (apiRequest) => (applicationId, query, options) => apiRequest({ pathParams: { applicationId }, query }, options)),
340
+ address: this.bindMethod('appsAddressGet', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
341
+ setAddress: this.bindMethod('appsAddressSet', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
342
+ access: this.bindMethod('appsAccessGet', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
343
+ setAccess: this.bindMethod('appsAccessSet', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
344
+ listGrants: this.bindMethod('appsGrantsList', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
345
+ setGrant: this.bindMethod('appsGrantsSet', (apiRequest) => (applicationId, resourceId, body, options) => apiRequest({ pathParams: { applicationId, resourceId }, body }, options)),
346
+ prepareUploads: this.bindMethod('appsUploadsCreate', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
341
347
  uploadFiles: async (applicationId, files, options) => {
342
348
  const contents = await Promise.all(files.map(async (file) => ({
343
349
  path: file.path,
@@ -373,71 +379,73 @@ export class PermuteClient {
373
379
  }
374
380
  return manifest;
375
381
  },
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),
382
+ saveSite: this.bindMethod('appsSiteUpdate', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
383
+ list: this.bindMethod('appsList', (apiRequest) => (options) => apiRequest({}, options)),
384
+ create: this.bindMethod('appsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
385
+ get: this.bindMethod('appsGet', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
386
+ update: this.bindMethod('appsUpdate', (apiRequest) => (applicationId, body, options) => apiRequest({ pathParams: { applicationId }, body }, options)),
387
+ delete: this.bindMethod('appsDelete', (apiRequest) => (applicationId, options) => apiRequest({ pathParams: { applicationId } }, options)),
382
388
  };
383
389
  this.connectorSessions = {
384
- create: (body, options) => this.request('connectorSessionsCreate', { body }, options),
385
- get: (sessionId, options) => this.request('connectorSessionsGet', { pathParams: { sessionId } }, options),
390
+ create: this.bindMethod('connectorSessionsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
391
+ get: this.bindMethod('connectorSessionsGet', (apiRequest) => (sessionId, options) => apiRequest({ pathParams: { sessionId } }, options)),
386
392
  };
387
393
  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),
394
+ list: this.bindMethod('writeSyncsList', (apiRequest) => (options) => apiRequest({}, options)),
395
+ create: this.bindMethod('writeSyncsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
396
+ get: this.bindMethod('writeSyncsGet', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
397
+ update: this.bindMethod('writeSyncsUpdate', (apiRequest) => (writeSyncId, body, options) => apiRequest({ pathParams: { writeSyncId }, body }, options)),
398
+ delete: this.bindMethod('writeSyncsDelete', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
399
+ destinations: this.bindMethod('writeSyncsDestinations', (apiRequest) => (options) => apiRequest({}, options)),
400
+ preview: this.bindMethod('writeSyncsPreview', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
401
+ pause: this.bindMethod('writeSyncsPause', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
402
+ listRuns: this.bindMethod('writeSyncsListRuns', (apiRequest) => (writeSyncId, options) => apiRequest({ pathParams: { writeSyncId } }, options)),
403
+ getRun: this.bindMethod('writeSyncsGetRun', (apiRequest) => (writeSyncId, runId, query = {}, options) => apiRequest({ pathParams: { writeSyncId, runId }, query }, options)),
404
+ execute: this.bindMethod('writeSyncsExecute', (apiRequest) => (writeSyncId, runId, options) => apiRequest({ pathParams: { writeSyncId, runId } }, options)),
399
405
  };
400
406
  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),
407
+ list: this.bindMethod('workspacesList', (apiRequest) => (requestOptions) => apiRequest({}, requestOptions)),
408
+ create: this.bindMethod('workspacesCreate', (apiRequest) => (request, requestOptions) => apiRequest({ body: request }, requestOptions)),
409
+ get: this.bindMethod('workspacesGet', (apiRequest) => (workspaceId, requestOptions) => apiRequest({ pathParams: { workspaceId } }, requestOptions)),
410
+ update: this.bindMethod('workspacesUpdate', (apiRequest) => (workspaceId, request, requestOptions) => apiRequest({ pathParams: { workspaceId }, body: request }, requestOptions)),
411
+ delete: this.bindMethod('workspacesDelete', (apiRequest) => (workspaceId, requestOptions) => apiRequest({ pathParams: { workspaceId } }, requestOptions)),
406
412
  };
407
413
  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', {
414
+ list: this.bindMethod('sourcesList', (apiRequest) => (requestOptions) => apiRequest({}, requestOptions)),
415
+ get: this.bindMethod('sourcesGet', (apiRequest) => (sourceId, requestOptions) => apiRequest({ pathParams: { sourceId } }, requestOptions)),
416
+ listTables: this.bindMethod('sourcesGet', (apiRequest) => async (sourceId, requestOptions) => (await apiRequest({
411
417
  pathParams: { sourceId },
412
418
  query: { includeFields: 'false' },
413
- }, requestOptions)).tables,
414
- describeTable: async (sourceId, tableId, requestOptions) => (await this.request('sourcesGet', {
419
+ }, requestOptions)).tables),
420
+ describeTable: this.bindMethod('sourcesGet', (apiRequest) => async (sourceId, tableId, requestOptions) => (await apiRequest({
415
421
  pathParams: { sourceId },
416
422
  query: { tableId },
417
- }, requestOptions)).tables[0],
423
+ }, requestOptions)).tables[0]),
418
424
  };
425
+ const listOperationRuns = this.bindMethod('operationsRunsList', (apiRequest) => (operationId, options) => apiRequest({ pathParams: { operationId } }, options));
426
+ const listWorkflowRuns = this.bindMethod('operationRunsList', (apiRequest) => (query, options) => apiRequest({ query }, options));
419
427
  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),
428
+ list: this.bindMethod('operationsList', (apiRequest) => (query = {}, options) => apiRequest({ query }, options)),
429
+ get: this.bindMethod('operationsGet', (apiRequest) => (operationId, options) => apiRequest({ pathParams: { operationId } }, options)),
430
+ update: this.bindMethod('operationsUpdate', (apiRequest) => (operationId, body, options) => apiRequest({ pathParams: { operationId }, body }, options)),
431
+ getSource: this.bindMethod('operationsSourceGet', (apiRequest) => (operationId, options) => apiRequest({ pathParams: { operationId } }, options)),
432
+ updateSource: this.bindMethod('operationsSourceUpdate', (apiRequest) => (operationId, body, options) => apiRequest({ pathParams: { operationId }, body }, options)),
433
+ getRunOutput: this.bindMethod('operationsRunOutput', (apiRequest) => (operationId, runId, options) => apiRequest({ pathParams: { operationId, runId } }, options)),
434
+ listRuns: SdkMethodFactory.compose([listOperationRuns, listWorkflowRuns], ((input, options) => typeof input === 'string'
435
+ ? listOperationRuns(input, options)
436
+ : listWorkflowRuns(input, options))),
437
+ run: this.bindMethod('operationsRun', (apiRequest) => (operationId, body, options) => apiRequest({ pathParams: { operationId }, body }, options)),
430
438
  };
431
439
  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),
440
+ create: this.bindMethod('dataFlowsCreate', (apiRequest) => (body, options) => apiRequest({ body }, options)),
441
+ get: this.bindMethod('dataFlowsGet', (apiRequest) => (dataFlowId, options) => apiRequest({ pathParams: { dataFlowId } }, options)),
442
+ command: this.bindMethod('dataFlowsCommand', (apiRequest) => (dataFlowId, body, options) => apiRequest({ pathParams: { dataFlowId }, body }, options)),
435
443
  };
436
444
  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),
445
+ getSource: this.bindMethod('dashboardsSourceGet', (apiRequest) => (dashboardId, requestOptions) => apiRequest({ pathParams: { dashboardId } }, requestOptions)),
446
+ updateSource: this.bindMethod('dashboardsSourceUpdate', (apiRequest) => (dashboardId, request, requestOptions) => apiRequest({ pathParams: { dashboardId }, body: request }, requestOptions)),
439
447
  };
440
- const readDataset = (datasetId, requestOptions) => this.request('datasetsGet', { pathParams: { datasetId } }, requestOptions);
448
+ const readDataset = this.bindMethod('datasetsGet', (apiRequest) => (datasetId, requestOptions) => apiRequest({ pathParams: { datasetId } }, requestOptions));
441
449
  const writeDatasetTables = async (datasetId, request, requestOptions) => {
442
450
  const encoded = encodeDatasetWrite(request);
443
451
  const body = request.mode === 'replace'
@@ -505,9 +513,9 @@ export class PermuteClient {
505
513
  const wrapDataset = (dataset) => dataset.type === 'custom'
506
514
  ? new PermuteDataset(dataset, writeDatasetTables, readDataset)
507
515
  : new PermuteFileDataset(dataset, readDataset);
508
- const createDataset = async (request, requestOptions) => {
516
+ const createDataset = this.bindMethod('datasetsCreate', (apiRequest) => async (request, requestOptions) => {
509
517
  if (request.type === 'custom') {
510
- const dataset = await this.request('datasetsCreate', { body: request }, requestOptions);
518
+ const dataset = await apiRequest({ body: request }, requestOptions);
511
519
  return new PermuteDataset(requireCustomDataset(dataset), writeDatasetTables, readDataset);
512
520
  }
513
521
  const { data, headers, sizeBytes: declaredSize, ...createRequest } = request;
@@ -524,10 +532,10 @@ export class PermuteClient {
524
532
  throw new PermuteApiError({
525
533
  status: 0,
526
534
  code: 'missing_file_size',
527
- message: 'sizeBytes is required when the SDK cannot determine the upload body size',
535
+ message: 'sizeBytes is required without data or when the upload body size cannot be inferred',
528
536
  });
529
537
  }
530
- const response = await this.request('datasetsCreate', { body: { ...createRequest, sizeBytes } }, requestOptions);
538
+ const response = await apiRequest({ body: { ...createRequest, sizeBytes } }, requestOptions);
531
539
  const dataset = new PermuteFileDataset(requireFileDataset(response), readDataset);
532
540
  const target = dataset.data.upload;
533
541
  if (!target) {
@@ -537,6 +545,8 @@ export class PermuteClient {
537
545
  message: `Dataset ${dataset.id} did not include a file upload target`,
538
546
  });
539
547
  }
548
+ if (data === undefined)
549
+ return dataset;
540
550
  const uploadResponse = await this.fetchImpl(target.url, {
541
551
  method: target.method,
542
552
  headers: { ...headers, ...target.headers },
@@ -551,27 +561,28 @@ export class PermuteClient {
551
561
  });
552
562
  }
553
563
  return dataset;
554
- };
564
+ });
555
565
  this.datasets = {
556
566
  create: createDataset,
557
- getByKey: async (key, requestOptions) => {
558
- const dataset = await this.request('datasetsGetByKey', { query: { key } }, requestOptions);
567
+ getByKey: this.bindMethod('datasetsGetByKey', (apiRequest) => async (key, requestOptions) => {
568
+ const dataset = await apiRequest({ query: { key } }, requestOptions);
559
569
  return wrapDataset(dataset);
560
- },
570
+ }),
561
571
  get: async (datasetId, requestOptions) => {
562
572
  const dataset = await readDataset(datasetId, requestOptions);
563
573
  return wrapDataset(dataset);
564
574
  },
565
- download: async (datasetId, requestOptions) => {
566
- const { url } = await this.request('datasetsDownload', { pathParams: { datasetId } }, requestOptions);
575
+ download: this.bindMethod('datasetsDownload', (apiRequest) => async (datasetId, requestOptions) => {
576
+ const { url } = await apiRequest({ pathParams: { datasetId } }, requestOptions);
567
577
  return url;
568
- },
569
- delete: (datasetId, requestOptions) => this.request('datasetsDelete', { pathParams: { datasetId } }, requestOptions),
578
+ }),
579
+ delete: this.bindMethod('datasetsDelete', (apiRequest) => (datasetId, requestOptions) => apiRequest({ pathParams: { datasetId } }, requestOptions)),
570
580
  };
581
+ this.apps.uploadFiles = SdkMethodFactory.compose([this.apps.prepareUploads], this.apps.uploadFiles);
582
+ this.datasets.get = SdkMethodFactory.compose([readDataset], this.datasets.get);
583
+ this.answer = SdkMethodFactory.compose([this.answerJobs, this.getAnswerJob], this.answer.bind(this));
571
584
  }
572
- async search(request, options) {
573
- return await this.request('searchCreate', { body: request }, options);
574
- }
585
+ search = this.bindMethod('searchCreate', (apiRequest) => (request, options) => apiRequest({ body: request }, options));
575
586
  async answer(request, options) {
576
587
  let job = await this.answerJobs(request, options);
577
588
  const deadline = pollingDeadline(options);
@@ -594,12 +605,8 @@ export class PermuteClient {
594
605
  message: job.error ?? `Answer job ${job.status}`,
595
606
  });
596
607
  }
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
- }
608
+ answerJobs = this.bindMethod('answerJobsCreate', (apiRequest) => (request, options) => apiRequest({ body: request }, options));
609
+ getAnswerJob = this.bindMethod('answerJobsGet', (apiRequest) => (answerJobId, options) => apiRequest({ pathParams: { answerJobId } }, options));
603
610
  withWorkspace(workspaceId) {
604
611
  if (!workspaceId.trim()) {
605
612
  throw new PermuteApiError({ status: 0, code: 'missing_workspace_id', message: 'workspaceId is required' });
@@ -612,8 +619,9 @@ export class PermuteClient {
612
619
  headers: this.defaultHeaders,
613
620
  });
614
621
  }
615
- async query(request, options) {
616
- return await this.request('queriesCreate', { body: request }, options);
622
+ query = this.bindMethod('queriesCreate', (apiRequest) => (request, options) => apiRequest({ body: request }, options));
623
+ bindMethod(operationId, create) {
624
+ return SdkMethodFactory.create(operationId, create((input, options) => this.request(operationId, input, options)));
617
625
  }
618
626
  async request(operationId, input, options) {
619
627
  const route = routeFor(operationId);
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;