@objectstack/rest 4.0.5 → 4.1.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.d.cts CHANGED
@@ -221,7 +221,12 @@ declare class RestServer {
221
221
  private defaultProjectIdProvider?;
222
222
  private authServiceProvider?;
223
223
  private objectQLProvider?;
224
- constructor(server: IHttpServer, protocol: ObjectStackProtocol, config?: RestServerConfig, kernelManager?: RestKernelManager, envRegistry?: RestEnvRegistry, defaultProjectIdProvider?: () => string | undefined, authServiceProvider?: (projectId?: string) => Promise<any | undefined>, objectQLProvider?: (projectId?: string) => Promise<any | undefined>);
224
+ private emailServiceProvider?;
225
+ private sharingServiceProvider?;
226
+ private reportsServiceProvider?;
227
+ private approvalsServiceProvider?;
228
+ private sharingRulesServiceProvider?;
229
+ constructor(server: IHttpServer, protocol: ObjectStackProtocol, config?: RestServerConfig, kernelManager?: RestKernelManager, envRegistry?: RestEnvRegistry, defaultProjectIdProvider?: () => string | undefined, authServiceProvider?: (projectId?: string) => Promise<any | undefined>, objectQLProvider?: (projectId?: string) => Promise<any | undefined>, emailServiceProvider?: (projectId?: string) => Promise<any | undefined>, sharingServiceProvider?: (projectId?: string) => Promise<any | undefined>, reportsServiceProvider?: (projectId?: string) => Promise<any | undefined>, approvalsServiceProvider?: (projectId?: string) => Promise<any | undefined>, sharingRulesServiceProvider?: (projectId?: string) => Promise<any | undefined>);
225
230
  /**
226
231
  * Resolve the protocol for a given request. When `projectId` is present
227
232
  * and a KernelManager is wired, fetch the per-project kernel's
@@ -257,6 +262,16 @@ declare class RestServer {
257
262
  * does not own per-app translation bundles.
258
263
  */
259
264
  private resolveI18nService;
265
+ /**
266
+ * Reject anonymous requests with HTTP 401 when `api.requireAuth` is set.
267
+ * Returns `true` if the response was sent and the caller should stop
268
+ * processing. Returns `false` to continue.
269
+ *
270
+ * The check is intentionally narrow: only `context?.userId` counts as
271
+ * "authenticated". `isSystem` flags are never set on inbound HTTP
272
+ * requests (they're internal-only), so they cannot bypass this gate.
273
+ */
274
+ private enforceAuth;
260
275
  /**
261
276
  * Resolve the request's execution context (RBAC/RLS/FLS) by looking up
262
277
  * the better-auth session via the project's `auth` service. Returns
@@ -339,6 +354,112 @@ declare class RestServer {
339
354
  * Register CRUD endpoints for data operations
340
355
  */
341
356
  private registerCrudEndpoints;
357
+ /**
358
+ * Register object-specific action endpoints that don't fit the
359
+ * generic CRUD shape. These are domain operations (Salesforce
360
+ * convertLead, etc.) where the protocol implementation does its own
361
+ * multi-record orchestration and we just need a thin HTTP route.
362
+ *
363
+ * POST {basePath}/data/lead/:id/convert — M10.6 lead conversion.
364
+ */
365
+ private registerDataActionEndpoints;
366
+ /**
367
+ * Register global cross-object search endpoint (M10.5).
368
+ * GET {basePath}/search?q=acme&objects=lead,account&limit=20&perObject=5
369
+ */
370
+ private registerSearchEndpoints;
371
+ /**
372
+ * Register email endpoints (M11.B1 / M10.7).
373
+ *
374
+ * POST {basePath}/email/send — send a transactional email via the
375
+ * `IEmailService` provider registered by EmailServicePlugin. Returns
376
+ * 501 when no provider is wired so deployments without email
377
+ * configured fail cleanly.
378
+ *
379
+ * Request body:
380
+ * {
381
+ * to: "a@b.com" | ["a@b.com", { name, address }],
382
+ * from?: ..., cc?: ..., bcc?: ..., replyTo?: ...,
383
+ * subject: string,
384
+ * text?: string, html?: string, // at least one required
385
+ * attachments?: [{ filename, content, contentType?, cid? }],
386
+ * headers?: { [name]: value },
387
+ * relatedObject?: string, relatedId?: string,
388
+ * }
389
+ */
390
+ private registerEmailEndpoints;
391
+ /**
392
+ * Register record-level sharing endpoints (M11.C17).
393
+ *
394
+ * Surfaces `ISharingService` over HTTP so the UI can list, create
395
+ * and revoke per-record grants without going through ObjectQL. The
396
+ * three routes mirror the share-management drawer in Salesforce /
397
+ * ServiceNow:
398
+ *
399
+ * GET {basePath}/data/:object/:id/shares
400
+ * POST {basePath}/data/:object/:id/shares
401
+ * DELETE {basePath}/data/:object/:id/shares/:shareId
402
+ *
403
+ * All three resolve via `sharingServiceProvider`; routes return 501
404
+ * when no sharing service is configured so a deployment without the
405
+ * `@objectstack/plugin-sharing` plugin fails cleanly.
406
+ */
407
+ private registerSharingEndpoints;
408
+ /**
409
+ * Register sharing-rule endpoints (M10.17). Mirrors the existing
410
+ * sharing endpoints but operates on `sys_sharing_rule` rows.
411
+ *
412
+ * GET {basePath}/sharing/rules?object=&activeOnly=
413
+ * POST {basePath}/sharing/rules
414
+ * GET {basePath}/sharing/rules/:idOrName
415
+ * DELETE {basePath}/sharing/rules/:idOrName
416
+ * POST {basePath}/sharing/rules/:idOrName/evaluate
417
+ *
418
+ * Returns 501 when no sharing-rule service is configured.
419
+ */
420
+ private registerSharingRuleEndpoints;
421
+ /**
422
+ * Register saved-report + scheduled-digest endpoints (M11.C16).
423
+ *
424
+ * Surfaces `IReportService` over HTTP so the UI can build,
425
+ * run, and schedule reports without dropping to ObjectQL. Routes
426
+ * live at the top of the API surface (alongside `/approvals` and
427
+ * `/sharing`) — reports are a tenant-wide capability, not a record
428
+ * on a specific CRUD object:
429
+ *
430
+ * GET {basePath}/reports?object=&ownerId=
431
+ * POST {basePath}/reports
432
+ * GET {basePath}/reports/:id
433
+ * DELETE {basePath}/reports/:id
434
+ * POST {basePath}/reports/:id/run
435
+ * POST {basePath}/reports/:id/schedule
436
+ * GET {basePath}/reports/:id/schedules
437
+ * DELETE {basePath}/reports/schedules/:scheduleId
438
+ *
439
+ * All routes return 501 when `reportsServiceProvider` is unset so
440
+ * a deployment without `@objectstack/plugin-reports` fails cleanly.
441
+ */
442
+ private registerReportsEndpoints;
443
+ /**
444
+ * Register approval engine endpoints.
445
+ *
446
+ * Routes (all under {basePath}/approvals):
447
+ * GET /processes — list approval processes
448
+ * POST /processes — upsert (defineProcess)
449
+ * GET /processes/:id — get by id or name
450
+ * DELETE /processes/:id — delete process
451
+ * POST /requests — submit
452
+ * GET /requests — list (filters: status, object, recordId, approverId, submitterId)
453
+ * GET /requests/:id — get request
454
+ * POST /requests/:id/approve — approve current step
455
+ * POST /requests/:id/reject — reject current step
456
+ * POST /requests/:id/recall — recall (submitter only)
457
+ * GET /requests/:id/actions — audit trail
458
+ *
459
+ * Returns 501 when `approvalsServiceProvider` is unset so deployments
460
+ * without `@objectstack/plugin-approvals` fail cleanly.
461
+ */
462
+ private registerApprovalsEndpoints;
342
463
  /**
343
464
  * Register batch operation endpoints
344
465
  */
package/dist/index.d.ts CHANGED
@@ -221,7 +221,12 @@ declare class RestServer {
221
221
  private defaultProjectIdProvider?;
222
222
  private authServiceProvider?;
223
223
  private objectQLProvider?;
224
- constructor(server: IHttpServer, protocol: ObjectStackProtocol, config?: RestServerConfig, kernelManager?: RestKernelManager, envRegistry?: RestEnvRegistry, defaultProjectIdProvider?: () => string | undefined, authServiceProvider?: (projectId?: string) => Promise<any | undefined>, objectQLProvider?: (projectId?: string) => Promise<any | undefined>);
224
+ private emailServiceProvider?;
225
+ private sharingServiceProvider?;
226
+ private reportsServiceProvider?;
227
+ private approvalsServiceProvider?;
228
+ private sharingRulesServiceProvider?;
229
+ constructor(server: IHttpServer, protocol: ObjectStackProtocol, config?: RestServerConfig, kernelManager?: RestKernelManager, envRegistry?: RestEnvRegistry, defaultProjectIdProvider?: () => string | undefined, authServiceProvider?: (projectId?: string) => Promise<any | undefined>, objectQLProvider?: (projectId?: string) => Promise<any | undefined>, emailServiceProvider?: (projectId?: string) => Promise<any | undefined>, sharingServiceProvider?: (projectId?: string) => Promise<any | undefined>, reportsServiceProvider?: (projectId?: string) => Promise<any | undefined>, approvalsServiceProvider?: (projectId?: string) => Promise<any | undefined>, sharingRulesServiceProvider?: (projectId?: string) => Promise<any | undefined>);
225
230
  /**
226
231
  * Resolve the protocol for a given request. When `projectId` is present
227
232
  * and a KernelManager is wired, fetch the per-project kernel's
@@ -257,6 +262,16 @@ declare class RestServer {
257
262
  * does not own per-app translation bundles.
258
263
  */
259
264
  private resolveI18nService;
265
+ /**
266
+ * Reject anonymous requests with HTTP 401 when `api.requireAuth` is set.
267
+ * Returns `true` if the response was sent and the caller should stop
268
+ * processing. Returns `false` to continue.
269
+ *
270
+ * The check is intentionally narrow: only `context?.userId` counts as
271
+ * "authenticated". `isSystem` flags are never set on inbound HTTP
272
+ * requests (they're internal-only), so they cannot bypass this gate.
273
+ */
274
+ private enforceAuth;
260
275
  /**
261
276
  * Resolve the request's execution context (RBAC/RLS/FLS) by looking up
262
277
  * the better-auth session via the project's `auth` service. Returns
@@ -339,6 +354,112 @@ declare class RestServer {
339
354
  * Register CRUD endpoints for data operations
340
355
  */
341
356
  private registerCrudEndpoints;
357
+ /**
358
+ * Register object-specific action endpoints that don't fit the
359
+ * generic CRUD shape. These are domain operations (Salesforce
360
+ * convertLead, etc.) where the protocol implementation does its own
361
+ * multi-record orchestration and we just need a thin HTTP route.
362
+ *
363
+ * POST {basePath}/data/lead/:id/convert — M10.6 lead conversion.
364
+ */
365
+ private registerDataActionEndpoints;
366
+ /**
367
+ * Register global cross-object search endpoint (M10.5).
368
+ * GET {basePath}/search?q=acme&objects=lead,account&limit=20&perObject=5
369
+ */
370
+ private registerSearchEndpoints;
371
+ /**
372
+ * Register email endpoints (M11.B1 / M10.7).
373
+ *
374
+ * POST {basePath}/email/send — send a transactional email via the
375
+ * `IEmailService` provider registered by EmailServicePlugin. Returns
376
+ * 501 when no provider is wired so deployments without email
377
+ * configured fail cleanly.
378
+ *
379
+ * Request body:
380
+ * {
381
+ * to: "a@b.com" | ["a@b.com", { name, address }],
382
+ * from?: ..., cc?: ..., bcc?: ..., replyTo?: ...,
383
+ * subject: string,
384
+ * text?: string, html?: string, // at least one required
385
+ * attachments?: [{ filename, content, contentType?, cid? }],
386
+ * headers?: { [name]: value },
387
+ * relatedObject?: string, relatedId?: string,
388
+ * }
389
+ */
390
+ private registerEmailEndpoints;
391
+ /**
392
+ * Register record-level sharing endpoints (M11.C17).
393
+ *
394
+ * Surfaces `ISharingService` over HTTP so the UI can list, create
395
+ * and revoke per-record grants without going through ObjectQL. The
396
+ * three routes mirror the share-management drawer in Salesforce /
397
+ * ServiceNow:
398
+ *
399
+ * GET {basePath}/data/:object/:id/shares
400
+ * POST {basePath}/data/:object/:id/shares
401
+ * DELETE {basePath}/data/:object/:id/shares/:shareId
402
+ *
403
+ * All three resolve via `sharingServiceProvider`; routes return 501
404
+ * when no sharing service is configured so a deployment without the
405
+ * `@objectstack/plugin-sharing` plugin fails cleanly.
406
+ */
407
+ private registerSharingEndpoints;
408
+ /**
409
+ * Register sharing-rule endpoints (M10.17). Mirrors the existing
410
+ * sharing endpoints but operates on `sys_sharing_rule` rows.
411
+ *
412
+ * GET {basePath}/sharing/rules?object=&activeOnly=
413
+ * POST {basePath}/sharing/rules
414
+ * GET {basePath}/sharing/rules/:idOrName
415
+ * DELETE {basePath}/sharing/rules/:idOrName
416
+ * POST {basePath}/sharing/rules/:idOrName/evaluate
417
+ *
418
+ * Returns 501 when no sharing-rule service is configured.
419
+ */
420
+ private registerSharingRuleEndpoints;
421
+ /**
422
+ * Register saved-report + scheduled-digest endpoints (M11.C16).
423
+ *
424
+ * Surfaces `IReportService` over HTTP so the UI can build,
425
+ * run, and schedule reports without dropping to ObjectQL. Routes
426
+ * live at the top of the API surface (alongside `/approvals` and
427
+ * `/sharing`) — reports are a tenant-wide capability, not a record
428
+ * on a specific CRUD object:
429
+ *
430
+ * GET {basePath}/reports?object=&ownerId=
431
+ * POST {basePath}/reports
432
+ * GET {basePath}/reports/:id
433
+ * DELETE {basePath}/reports/:id
434
+ * POST {basePath}/reports/:id/run
435
+ * POST {basePath}/reports/:id/schedule
436
+ * GET {basePath}/reports/:id/schedules
437
+ * DELETE {basePath}/reports/schedules/:scheduleId
438
+ *
439
+ * All routes return 501 when `reportsServiceProvider` is unset so
440
+ * a deployment without `@objectstack/plugin-reports` fails cleanly.
441
+ */
442
+ private registerReportsEndpoints;
443
+ /**
444
+ * Register approval engine endpoints.
445
+ *
446
+ * Routes (all under {basePath}/approvals):
447
+ * GET /processes — list approval processes
448
+ * POST /processes — upsert (defineProcess)
449
+ * GET /processes/:id — get by id or name
450
+ * DELETE /processes/:id — delete process
451
+ * POST /requests — submit
452
+ * GET /requests — list (filters: status, object, recordId, approverId, submitterId)
453
+ * GET /requests/:id — get request
454
+ * POST /requests/:id/approve — approve current step
455
+ * POST /requests/:id/reject — reject current step
456
+ * POST /requests/:id/recall — recall (submitter only)
457
+ * GET /requests/:id/actions — audit trail
458
+ *
459
+ * Returns 501 when `approvalsServiceProvider` is unset so deployments
460
+ * without `@objectstack/plugin-approvals` fail cleanly.
461
+ */
462
+ private registerApprovalsEndpoints;
342
463
  /**
343
464
  * Register batch operation endpoints
344
465
  */