@sprigr/apps-app-sdk 0.17.0 → 0.18.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.ts CHANGED
@@ -1496,6 +1496,19 @@ interface AppApprovalEnvelope {
1496
1496
  * `ApprovalSpec.count`.
1497
1497
  */
1498
1498
  count?: number;
1499
+ /**
1500
+ * What the platform does when nobody can be asked (a schedule, workflow
1501
+ * step or delegation turn). Omitted, the write is withheld unless the
1502
+ * step's standing approval covers it. `'proceed'` runs the granted pass
1503
+ * instead, so the card appears only when a person is on the turn: the
1504
+ * contract the platform's built-in email send gate has always had. Use it
1505
+ * for writes automations legitimately make (sending mail, posting a chat
1506
+ * message); keep the default for deletes, money and bulk writes. Needs a
1507
+ * platform with sprigr-team decision 0160; an older one ignores it and
1508
+ * withholds. Set it through `ApprovalSpec.unattended` when you use the
1509
+ * wrappers.
1510
+ */
1511
+ unattended?: 'proceed';
1499
1512
  }
1500
1513
  /**
1501
1514
  * Platform-stamped marker telling an app that a human approved this call. The
@@ -1562,6 +1575,29 @@ declare function seq(values: unknown): string;
1562
1575
  */
1563
1576
  declare function approvalHash(...parts: Array<string | number | undefined | null>): string;
1564
1577
 
1578
+ /**
1579
+ * Helpers for the text on an approval card for a message send (an email, a
1580
+ * chat post), shared so each mail app does not grow its own copy.
1581
+ *
1582
+ * The card is display only. The grant hash and the arguments the platform
1583
+ * replays on approval (sprigr-team decision 0012) carry the full message, so
1584
+ * shortening the PREVIEW drops nothing that is sent.
1585
+ */
1586
+ /**
1587
+ * Lower-cased addresses from any recipient shape a send tool accepts: an array
1588
+ * of `{ email }` objects or strings, or one string separated by commas or
1589
+ * semicolons. Feed it to `set()` for an order-insensitive hash part.
1590
+ */
1591
+ declare function approvalRecipients(value: unknown): string[];
1592
+ /** Default preview length: enough to recognise the message, short enough not to bury the question. */
1593
+ declare const APPROVAL_PREVIEW_MAX = 600;
1594
+ /**
1595
+ * Plain-text preview of a message body for the card: tags stripped, `&nbsp;`
1596
+ * and runs of whitespace collapsed, and an ellipsis when it is cut so the
1597
+ * reader can tell the preview is not the whole message.
1598
+ */
1599
+ declare function approvalPreview(value: unknown, max?: number): string;
1600
+
1565
1601
  /**
1566
1602
  * Thrown by `undoEnvelope` for a field the platform would reject.
1567
1603
  *
@@ -1720,6 +1756,13 @@ interface ApprovalSpec<P = unknown, E = unknown> {
1720
1756
  * can ever cover it, which is the safe side but not the useful one.
1721
1757
  */
1722
1758
  count?: (args: ToolArgs) => number;
1759
+ /**
1760
+ * `'proceed'`: ask only when a person is on the turn, and let an unattended
1761
+ * run (schedule, workflow step, delegation) do the write. Omit to withhold
1762
+ * unattended writes unless a standing approval covers them. See
1763
+ * `AppApprovalEnvelope.unattended`.
1764
+ */
1765
+ unattended?: 'proceed';
1723
1766
  /**
1724
1767
  * Overrides the gate's `resolveConnection` for THIS spec only; the gate's
1725
1768
  * value stays the default for every spec that omits it.
@@ -3100,4 +3143,4 @@ interface ExecutionContextLike {
3100
3143
  }
3101
3144
  type HandlerFn<TArgs, TResult> = (args: TArgs, env: Record<string, unknown>, ctx?: ExecutionContextLike) => Promise<TResult>;
3102
3145
 
3103
- export { ACTOR_RETIRED_HOOK_TOOL, ACTOR_RETIRE_REASONS, APPROVAL_GRANTED_KEY, APP_FILES_ROOT, APP_OWNER_SEGMENT, type Actor, type ActorRetireReason, type ActorRetired, type ActorRetiredHookBody, type ActorRetiredResult, type AppApprovalEnvelope, type AppFileListItem, type AppFileUrlArgs, type AppFileUrlResult, type AppFilesEnv, type AppToolEffectsDeclaration, type AppUndoEnvelope, type ApplyPoliciesOptions, type ApprovalGateOptions, type ApprovalSpec, type ArchiveOfferOptions, type ArchiveOfferRefusal, type CallerKeyResolution, type CaptureJournal, type ConfirmCondition, type ConfirmRule, type ConfirmationPolicy, type ConnectCompleteRequest, type ConnectCompleteResult, type D1Like, type D1PreparedStatementLike, DATA_PARTIAL_UPDATE_PATH, DEFAULT_EMIT_TIMEOUT_MS, DEFAULT_LOG_TIMEOUT_MS, DEFAULT_MAX_FILE_BYTES, DEFAULT_MONEY_FIELDS, DEFAULT_WRITE_PREFIXES, type DerivePolicyOptions, type DerivedPolicy, type DispatcherApprovalGate, type DispatcherApprovalOptions, type EmitMarketplaceEventOptions, type EmitResult, type EmitTransport, type EventArgs, type ExecutionContextLike, type FetchFileResult, type FetchWithRetryOptions, type GetAppFileResult, type HandlerFn, INBOX_SEND_CONTRACT_V1, type InboxAddress, type InboxAppendRequest, type InboxAppendResult, type InboxChannelDeclaration, type InboxFoldersRequest, type InboxFoldersResult, type InboxOwner, type InboxSendConnection, type InboxSendHandlerImpl, InboxSendRefusal, type InboxSendSupports, type InboxSendV1Args, type InboxSendV1Result, type InstallBridge, InvalidUndoEnvelopeError, type JournalRowLike, type LogToPlatformOptions, type ManifestDispatchBlock, type ManifestLike, type ManifestToolLike, type MarketplaceEventEmitOpts, type MarketplaceEventSourceIntegration, NotConnectedError, type OAuthBouncerSignals, type OAuthState, type OfferUndoArgs, type PartialUpdateDataOptions, type PlatformHostEnv, type PolicyCheckInput, type PolicySource, type PutAppFileArgs, type PutAppFileResult, type PutAppFileStreamArgs, type RequireApprovalOptions, type ResolveViewerOptions, type RestoreResult, type RestoreSpec, SPRIGR_DATA_MAX_OBJECTS_PER_CALL, SPRIGR_LOG_LEVELS, SPRIGR_LOG_LIMITS, type ScheduleArgs, type SprigrDataAggregationCell, type SprigrDataAggregationResult, type SprigrDataAggregationSpec, type SprigrDataApi, type SprigrDataImportOpts, type SprigrDataIndexOpts, type SprigrDataPartialUpdateBody, type SprigrDataPartialUpdateOpts, type SprigrDataPartialUpdateResult, type SprigrDataPatch, type SprigrDataSearchOpts, type SprigrDataSearchResult, SprigrDataValidationError, type SprigrFilesApi, type SprigrFilesApiWithEdit, type SprigrFilesCreateInput, type SprigrFilesCreateResult, type SprigrFilesEditInput, type SprigrFilesEditResult, type SprigrFilesJobResult, type SprigrFilesListItem, type SprigrFilesListResult, type SprigrInboxApi, type SprigrLogEntry, type SprigrLogFn, type SprigrLogLevel, type SprigrLogResult, SprigrLogValidationError, type SyncedAttachment, type SyncedMessage, type ToolArgs, type ToolHandler, type ToolResult, type ToolWrapperOptions, UNIT_SEP, type UndoApplyOptions, type UndoApplyResult, type UndoCaptureSpec, type UndoFidelity, VIEWER_ANONYMOUS, VIEWER_CONTEXT_HEADER, VIEWER_PLATFORM_USER_ID_HEADER, VIEWER_ROLE_HEADER, VIEWER_USER_ID_HEADER, type VerbRule, type ViewerContext, type ViewerContextFailure, type ViewerContextVerification, type ViewerEnv, type WebhookArgs, type WfpBridgeEnv, type WfpEmitReply, actorKey, actorRetiredHook, actorTool, agentFileKeyFromUrl, appFileUrl, appKeyFromCallerKey, applyConfirmationPolicies, approvalHash, archiveOfferRefusal, base64ToBytes, buildConfirmationPolicy, buildMarketplaceWebhookUrl, buildPartialUpdateBody, bytesToBase64, callerKeyRefusal, canEmit, canLog, canPartialUpdate, checkConfirmationPolicy, commonDestructiveVerbs, connectComplete, connectDisconnect, constantTimeEqual, createMarketplaceEmitter, createToolWrappers, decodeState, defineInboxSendHandler, deleteAppFile, deriveConfirmationPolicy, describeMissingBridge, dispatcherApproval, emitMarketplaceEvent, encodeState, fetchFileAsBase64, fetchFileBytes, fetchWithRetry, fullWarning, getAppFile, hmacSha256Hex, installTokenPost, isNotConnectedError, isStagingHost, listAppFiles, logToPlatform, manifestIsFresh, offerUndo, overlaySprigr, ownerFromActorKey, parseActor, parseActorRetiredArgs, partialUpdateData, putAppFile, putAppFileStream, randomHex, readableStoredKey, recreatedWarning, refuseWithoutForce, requireApproval, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, resolveViewerContext, resolveViewerUserId, runUndoApply, safeCapture, seq, serializeManifest, set, tool, undoEnvelope, validateLogEntries, validateLogEntry, verifyViewerToken, withSprigrEmitFallback, withSprigrInboxFallback, withSprigrLogFallback };
3146
+ export { ACTOR_RETIRED_HOOK_TOOL, ACTOR_RETIRE_REASONS, APPROVAL_GRANTED_KEY, APPROVAL_PREVIEW_MAX, APP_FILES_ROOT, APP_OWNER_SEGMENT, type Actor, type ActorRetireReason, type ActorRetired, type ActorRetiredHookBody, type ActorRetiredResult, type AppApprovalEnvelope, type AppFileListItem, type AppFileUrlArgs, type AppFileUrlResult, type AppFilesEnv, type AppToolEffectsDeclaration, type AppUndoEnvelope, type ApplyPoliciesOptions, type ApprovalGateOptions, type ApprovalSpec, type ArchiveOfferOptions, type ArchiveOfferRefusal, type CallerKeyResolution, type CaptureJournal, type ConfirmCondition, type ConfirmRule, type ConfirmationPolicy, type ConnectCompleteRequest, type ConnectCompleteResult, type D1Like, type D1PreparedStatementLike, DATA_PARTIAL_UPDATE_PATH, DEFAULT_EMIT_TIMEOUT_MS, DEFAULT_LOG_TIMEOUT_MS, DEFAULT_MAX_FILE_BYTES, DEFAULT_MONEY_FIELDS, DEFAULT_WRITE_PREFIXES, type DerivePolicyOptions, type DerivedPolicy, type DispatcherApprovalGate, type DispatcherApprovalOptions, type EmitMarketplaceEventOptions, type EmitResult, type EmitTransport, type EventArgs, type ExecutionContextLike, type FetchFileResult, type FetchWithRetryOptions, type GetAppFileResult, type HandlerFn, INBOX_SEND_CONTRACT_V1, type InboxAddress, type InboxAppendRequest, type InboxAppendResult, type InboxChannelDeclaration, type InboxFoldersRequest, type InboxFoldersResult, type InboxOwner, type InboxSendConnection, type InboxSendHandlerImpl, InboxSendRefusal, type InboxSendSupports, type InboxSendV1Args, type InboxSendV1Result, type InstallBridge, InvalidUndoEnvelopeError, type JournalRowLike, type LogToPlatformOptions, type ManifestDispatchBlock, type ManifestLike, type ManifestToolLike, type MarketplaceEventEmitOpts, type MarketplaceEventSourceIntegration, NotConnectedError, type OAuthBouncerSignals, type OAuthState, type OfferUndoArgs, type PartialUpdateDataOptions, type PlatformHostEnv, type PolicyCheckInput, type PolicySource, type PutAppFileArgs, type PutAppFileResult, type PutAppFileStreamArgs, type RequireApprovalOptions, type ResolveViewerOptions, type RestoreResult, type RestoreSpec, SPRIGR_DATA_MAX_OBJECTS_PER_CALL, SPRIGR_LOG_LEVELS, SPRIGR_LOG_LIMITS, type ScheduleArgs, type SprigrDataAggregationCell, type SprigrDataAggregationResult, type SprigrDataAggregationSpec, type SprigrDataApi, type SprigrDataImportOpts, type SprigrDataIndexOpts, type SprigrDataPartialUpdateBody, type SprigrDataPartialUpdateOpts, type SprigrDataPartialUpdateResult, type SprigrDataPatch, type SprigrDataSearchOpts, type SprigrDataSearchResult, SprigrDataValidationError, type SprigrFilesApi, type SprigrFilesApiWithEdit, type SprigrFilesCreateInput, type SprigrFilesCreateResult, type SprigrFilesEditInput, type SprigrFilesEditResult, type SprigrFilesJobResult, type SprigrFilesListItem, type SprigrFilesListResult, type SprigrInboxApi, type SprigrLogEntry, type SprigrLogFn, type SprigrLogLevel, type SprigrLogResult, SprigrLogValidationError, type SyncedAttachment, type SyncedMessage, type ToolArgs, type ToolHandler, type ToolResult, type ToolWrapperOptions, UNIT_SEP, type UndoApplyOptions, type UndoApplyResult, type UndoCaptureSpec, type UndoFidelity, VIEWER_ANONYMOUS, VIEWER_CONTEXT_HEADER, VIEWER_PLATFORM_USER_ID_HEADER, VIEWER_ROLE_HEADER, VIEWER_USER_ID_HEADER, type VerbRule, type ViewerContext, type ViewerContextFailure, type ViewerContextVerification, type ViewerEnv, type WebhookArgs, type WfpBridgeEnv, type WfpEmitReply, actorKey, actorRetiredHook, actorTool, agentFileKeyFromUrl, appFileUrl, appKeyFromCallerKey, applyConfirmationPolicies, approvalHash, approvalPreview, approvalRecipients, archiveOfferRefusal, base64ToBytes, buildConfirmationPolicy, buildMarketplaceWebhookUrl, buildPartialUpdateBody, bytesToBase64, callerKeyRefusal, canEmit, canLog, canPartialUpdate, checkConfirmationPolicy, commonDestructiveVerbs, connectComplete, connectDisconnect, constantTimeEqual, createMarketplaceEmitter, createToolWrappers, decodeState, defineInboxSendHandler, deleteAppFile, deriveConfirmationPolicy, describeMissingBridge, dispatcherApproval, emitMarketplaceEvent, encodeState, fetchFileAsBase64, fetchFileBytes, fetchWithRetry, fullWarning, getAppFile, hmacSha256Hex, installTokenPost, isNotConnectedError, isStagingHost, listAppFiles, logToPlatform, manifestIsFresh, offerUndo, overlaySprigr, ownerFromActorKey, parseActor, parseActorRetiredArgs, partialUpdateData, putAppFile, putAppFileStream, randomHex, readableStoredKey, recreatedWarning, refuseWithoutForce, requireApproval, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, resolveViewerContext, resolveViewerUserId, runUndoApply, safeCapture, seq, serializeManifest, set, tool, undoEnvelope, validateLogEntries, validateLogEntry, verifyViewerToken, withSprigrEmitFallback, withSprigrInboxFallback, withSprigrLogFallback };
package/dist/index.js CHANGED
@@ -1037,6 +1037,32 @@ function approvalHash(...parts) {
1037
1037
  return parts.map((p) => p === void 0 || p === null ? "" : String(p)).join(UNIT_SEP);
1038
1038
  }
1039
1039
 
1040
+ // src/write-protection/approval-card.ts
1041
+ function approvalRecipients(value) {
1042
+ const out = [];
1043
+ const add = (s) => {
1044
+ if (typeof s !== "string") return;
1045
+ for (const part of s.split(/[,;]/)) {
1046
+ const t = part.trim().toLowerCase();
1047
+ if (t) out.push(t);
1048
+ }
1049
+ };
1050
+ if (Array.isArray(value)) {
1051
+ for (const item of value) {
1052
+ if (item && typeof item === "object") add(item.email);
1053
+ else add(item);
1054
+ }
1055
+ } else {
1056
+ add(value);
1057
+ }
1058
+ return out;
1059
+ }
1060
+ var APPROVAL_PREVIEW_MAX = 600;
1061
+ function approvalPreview(value, max = APPROVAL_PREVIEW_MAX) {
1062
+ const text = (typeof value === "string" ? value : "").replace(/<[^>]*>/g, " ").replace(/&nbsp;/g, " ").replace(/\s+/g, " ").trim();
1063
+ return text.length > max ? `${text.slice(0, max)}\u2026` : text;
1064
+ }
1065
+
1040
1066
  // src/write-protection/undo-envelope.ts
1041
1067
  var InvalidUndoEnvelopeError = class extends Error {
1042
1068
  constructor(message) {
@@ -1187,7 +1213,8 @@ async function askPass(name, spec, params, env, opts, hashPrefix) {
1187
1213
  _approval: {
1188
1214
  ...spec.describe(target, params, connection),
1189
1215
  hash: approvalHash(...hashPrefix, rawId, connection, ...extra),
1190
- ...count !== void 0 ? { count } : {}
1216
+ ...count !== void 0 ? { count } : {},
1217
+ ...spec.unattended === "proceed" ? { unattended: "proceed" } : {}
1191
1218
  }
1192
1219
  };
1193
1220
  }
@@ -1764,6 +1791,7 @@ export {
1764
1791
  ACTOR_RETIRED_HOOK_TOOL,
1765
1792
  ACTOR_RETIRE_REASONS,
1766
1793
  APPROVAL_GRANTED_KEY,
1794
+ APPROVAL_PREVIEW_MAX,
1767
1795
  APP_FILES_ROOT,
1768
1796
  APP_OWNER_SEGMENT,
1769
1797
  DATA_PARTIAL_UPDATE_PATH,
@@ -1795,6 +1823,8 @@ export {
1795
1823
  appKeyFromCallerKey,
1796
1824
  applyConfirmationPolicies,
1797
1825
  approvalHash,
1826
+ approvalPreview,
1827
+ approvalRecipients,
1798
1828
  archiveOfferRefusal,
1799
1829
  base64ToBytes,
1800
1830
  buildConfirmationPolicy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprigr/apps-app-sdk",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",