nodestack-client 2.1.0 → 2.3.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/index.mjs CHANGED
@@ -196,7 +196,6 @@ var BaseService = class {
196
196
  constructor(client) {
197
197
  this.client = client;
198
198
  }
199
- client;
200
199
  send(path, options = {}) {
201
200
  return this.client.send(path, options);
202
201
  }
@@ -208,7 +207,6 @@ var RecordService = class extends BaseService {
208
207
  super(client);
209
208
  this.collectionName = collectionName;
210
209
  }
211
- collectionName;
212
210
  get clientWithRealtime() {
213
211
  return this.client;
214
212
  }
@@ -1292,6 +1290,139 @@ var AppService = class extends BaseService {
1292
1290
  }
1293
1291
  };
1294
1292
 
1293
+ // src/services/FunctionService.ts
1294
+ var FunctionService = class extends BaseService {
1295
+ /**
1296
+ * Invokes a serverless function by name or ID.
1297
+ * Scoped to the client's configured application if specified.
1298
+ */
1299
+ async invoke(name, body, options = {}) {
1300
+ const encodedName = encodeURIComponent(name);
1301
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1302
+ const path = `${appPrefix}/functions/${encodedName}/invoke`;
1303
+ return this.send(path, {
1304
+ method: options.method || "POST",
1305
+ body,
1306
+ ...options
1307
+ });
1308
+ }
1309
+ /**
1310
+ * Fetch all functions configured in the active application scope (requires admin auth).
1311
+ */
1312
+ async getList(options) {
1313
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1314
+ return this.send(`${appPrefix}/functions`, {
1315
+ method: "GET",
1316
+ query: options
1317
+ });
1318
+ }
1319
+ /**
1320
+ * Fetch a single function by ID or name (requires admin auth).
1321
+ */
1322
+ async getOne(idOrName) {
1323
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1324
+ return this.send(`${appPrefix}/functions/${encodeURIComponent(idOrName)}`, {
1325
+ method: "GET"
1326
+ });
1327
+ }
1328
+ /**
1329
+ * Test execute a function in sandboxed runner (requires admin auth).
1330
+ */
1331
+ async test(id, testPayload = {}) {
1332
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1333
+ return this.send(`${appPrefix}/functions/${encodeURIComponent(id)}/test`, {
1334
+ method: "POST",
1335
+ body: testPayload
1336
+ });
1337
+ }
1338
+ };
1339
+
1340
+ // src/services/FlowService.ts
1341
+ var FlowService = class extends BaseService {
1342
+ /**
1343
+ * Triggers or executes a Flow state machine by ID or name.
1344
+ * If wait is true (default), returns the finished FlowExecution object.
1345
+ */
1346
+ async execute(flowIdOrName, input, options = {}) {
1347
+ const encoded = encodeURIComponent(flowIdOrName);
1348
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1349
+ const path = `${appPrefix}/flows/${encoded}/execute`;
1350
+ const wait = options.wait !== false;
1351
+ return this.send(path, {
1352
+ method: "POST",
1353
+ body: input || {},
1354
+ query: { wait: wait ? "true" : "false" },
1355
+ ...options
1356
+ });
1357
+ }
1358
+ /**
1359
+ * Fetch all flows configured in the active application scope (requires admin auth).
1360
+ */
1361
+ async getList(options) {
1362
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1363
+ return this.send(`${appPrefix}/flows`, {
1364
+ method: "GET",
1365
+ query: options
1366
+ });
1367
+ }
1368
+ /**
1369
+ * Fetch a single flow by ID or name (requires admin auth).
1370
+ */
1371
+ async getOne(idOrName) {
1372
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1373
+ return this.send(`${appPrefix}/flows/${encodeURIComponent(idOrName)}`, {
1374
+ method: "GET"
1375
+ });
1376
+ }
1377
+ /**
1378
+ * Fetch executions history for a specific flow or across all flows (requires admin auth).
1379
+ */
1380
+ async getExecutions(options) {
1381
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1382
+ const flowId = options?.flowId ? `/${encodeURIComponent(options.flowId)}/executions` : "/executions";
1383
+ return this.send(
1384
+ `${appPrefix}/flows${flowId}`,
1385
+ {
1386
+ method: "GET",
1387
+ query: options
1388
+ }
1389
+ );
1390
+ }
1391
+ /**
1392
+ * Fetch a single execution record by ID (requires admin auth).
1393
+ */
1394
+ async getExecution(executionId) {
1395
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1396
+ return this.send(
1397
+ `${appPrefix}/flows/executions/${encodeURIComponent(executionId)}`,
1398
+ { method: "GET" }
1399
+ );
1400
+ }
1401
+ /**
1402
+ * Resumes an orphaned or interrupted running flow from its last completed checkpoint.
1403
+ */
1404
+ async resumeExecution(executionId) {
1405
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1406
+ return this.send(
1407
+ `${appPrefix}/flows/executions/${encodeURIComponent(executionId)}/resume`,
1408
+ { method: "POST" }
1409
+ );
1410
+ }
1411
+ /**
1412
+ * Aborts an orphaned running flow gracefully with status: 'aborted'.
1413
+ */
1414
+ async abortExecution(executionId, reason) {
1415
+ const appPrefix = this.client.appSlug ? `/api/apps/${encodeURIComponent(this.client.appSlug)}` : "/api";
1416
+ return this.send(
1417
+ `${appPrefix}/flows/executions/${encodeURIComponent(executionId)}/abort`,
1418
+ {
1419
+ method: "POST",
1420
+ body: { reason }
1421
+ }
1422
+ );
1423
+ }
1424
+ };
1425
+
1295
1426
  // src/Client.ts
1296
1427
  var NodeStackClient = class _NodeStackClient {
1297
1428
  baseUrl;
@@ -1305,6 +1436,8 @@ var NodeStackClient = class _NodeStackClient {
1305
1436
  demo;
1306
1437
  webhooks;
1307
1438
  apps;
1439
+ functions;
1440
+ flows;
1308
1441
  appSlug;
1309
1442
  customFetch;
1310
1443
  defaultHeaders;
@@ -1328,6 +1461,8 @@ var NodeStackClient = class _NodeStackClient {
1328
1461
  this.demo = new DemoService(this);
1329
1462
  this.webhooks = new WebhookService(this);
1330
1463
  this.apps = new AppService(this);
1464
+ this.functions = new FunctionService(this);
1465
+ this.flows = new FlowService(this);
1331
1466
  }
1332
1467
  /**
1333
1468
  * Dynamically configure latency & chaos simulation options for all future requests.
@@ -1618,6 +1753,8 @@ export {
1618
1753
  CollectionService,
1619
1754
  DemoService,
1620
1755
  FileService,
1756
+ FlowService,
1757
+ FunctionService,
1621
1758
  LocalAuthStore,
1622
1759
  MemoryAuthStore,
1623
1760
  NodeStackClient,