@sprigr/apps-app-sdk 0.29.0 → 0.30.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 +61 -1
- package/dist/index.js +17 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3150,6 +3150,30 @@ declare function hasHtmlMarkup(body: string): boolean;
|
|
|
3150
3150
|
*/
|
|
3151
3151
|
declare function emailBodyHtml(body: string): string;
|
|
3152
3152
|
|
|
3153
|
+
/**
|
|
3154
|
+
* The sending person's Inbox signature on mail an app sends as them
|
|
3155
|
+
* (sprigr-team decision 0255): one rule for every mail app, so the
|
|
3156
|
+
* microsoft-365 and google-workspace apps cannot drift apart.
|
|
3157
|
+
*
|
|
3158
|
+
* The platform resolves the person from the dispatch's signed actor
|
|
3159
|
+
* assertion (`env.SPRIGR.me.signature`); this only decides whether to append.
|
|
3160
|
+
* It appends when the bridge offers `me.signature`, the answer is ok and
|
|
3161
|
+
* carries html, the signature belongs to `senderPlatformUserId` (the owner of
|
|
3162
|
+
* the mailbox the mail goes out from), and the body does not already contain
|
|
3163
|
+
* it. The CALLER decides the mailbox: never call this for a shared or
|
|
3164
|
+
* delegated mailbox, nor for mail the Inbox composer wrote (it already seeded
|
|
3165
|
+
* the signature). Any refusal, missing bridge or failure returns the body
|
|
3166
|
+
* unchanged; a signature is never a reason to fail a send.
|
|
3167
|
+
*/
|
|
3168
|
+
|
|
3169
|
+
declare function withSenderSignature(sprigr: {
|
|
3170
|
+
me?: Pick<SprigrMeApi, 'signature'>;
|
|
3171
|
+
} | undefined, args: {
|
|
3172
|
+
html: string;
|
|
3173
|
+
channel: string;
|
|
3174
|
+
senderPlatformUserId: string | undefined;
|
|
3175
|
+
}): Promise<string>;
|
|
3176
|
+
|
|
3153
3177
|
/**
|
|
3154
3178
|
* @sprigr/apps-app-sdk
|
|
3155
3179
|
*
|
|
@@ -3526,6 +3550,42 @@ interface SprigrAssertionsApi {
|
|
|
3526
3550
|
*/
|
|
3527
3551
|
mint(audience: string): Promise<SprigrAssertionMintResult>;
|
|
3528
3552
|
}
|
|
3553
|
+
/** The `error` values {@link SprigrMeApi.signature} can resolve with. */
|
|
3554
|
+
type SprigrMeSignatureError = 'no_person' | 'actor_unverified' | 'invalid' | 'unavailable';
|
|
3555
|
+
/**
|
|
3556
|
+
* The result of {@link SprigrMeApi.signature} (sprigr-team decision 0255).
|
|
3557
|
+
* `ok: true` names the person whose signature it is (`platform_user_id`, a
|
|
3558
|
+
* `usr_` id) and their sanitized HTML signature, or `html: null` when they set
|
|
3559
|
+
* none. `ok: false` is a refusal; the method never rejects.
|
|
3560
|
+
*/
|
|
3561
|
+
type SprigrMeSignatureResult = {
|
|
3562
|
+
ok: true;
|
|
3563
|
+
platform_user_id: string;
|
|
3564
|
+
html: string | null;
|
|
3565
|
+
} | {
|
|
3566
|
+
ok: false;
|
|
3567
|
+
error: SprigrMeSignatureError;
|
|
3568
|
+
message: string;
|
|
3569
|
+
};
|
|
3570
|
+
/**
|
|
3571
|
+
* `env.SPRIGR.me`: reads about the PERSON this dispatch acts for. The platform
|
|
3572
|
+
* resolves the person from the signed actor assertion on the dispatch, which
|
|
3573
|
+
* the bridge forwards itself; nothing an app passes can name another person.
|
|
3574
|
+
*/
|
|
3575
|
+
interface SprigrMeApi {
|
|
3576
|
+
/**
|
|
3577
|
+
* The acting person's Inbox email signature for `channel` (the mail channel
|
|
3578
|
+
* slug, e.g. `'outlook_mail'` or `'google_mail'`): their override for that
|
|
3579
|
+
* channel's family if they set one, else their default. Append it only when
|
|
3580
|
+
* `platform_user_id` owns the mailbox you are sending from (never from a
|
|
3581
|
+
* shared mailbox), and skip it when the body already contains it.
|
|
3582
|
+
* Resolves `no_person` when nobody is acting (a webhook, an agent with no
|
|
3583
|
+
* person behind it, a member who left). Never rejects.
|
|
3584
|
+
*/
|
|
3585
|
+
signature(input: {
|
|
3586
|
+
channel: string;
|
|
3587
|
+
}): Promise<SprigrMeSignatureResult>;
|
|
3588
|
+
}
|
|
3529
3589
|
/**
|
|
3530
3590
|
* Durable app file storage exposed on `env.SPRIGR.files` by the platform
|
|
3531
3591
|
* wrapper (the platform build-runner). Persists bytes into the install's
|
|
@@ -3774,4 +3834,4 @@ interface ExecutionContextLike {
|
|
|
3774
3834
|
}
|
|
3775
3835
|
type HandlerFn<TArgs, TResult> = (args: TArgs, env: Record<string, unknown>, ctx?: ExecutionContextLike) => Promise<TResult>;
|
|
3776
3836
|
|
|
3777
|
-
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 ApprovalCoverage, type ApprovalGateOptions, type ApprovalPreviewFact, type ApprovalPreviewSlot, type ApprovalPreviewSpec, type ApprovalSpec, type ArchiveOfferOptions, type ArchiveOfferRefusal, type CallerKeyResolution, type CaptureJournal, type CompanyTimezoneEnv, type ConfirmCondition, type ConfirmRule, type ConfirmationPolicy, type ConnectCompleteRequest, type ConnectCompleteResult, type D1Like, type D1PreparedStatementLike, DATA_DELETE_MAX_IDS, DATA_PARTIAL_UPDATE_PATH, DEFAULT_EMIT_TIMEOUT_MS, DEFAULT_FILE_READ_TIMEOUT_MS, DEFAULT_LOG_TIMEOUT_MS, DEFAULT_MAX_FILE_BYTES, DEFAULT_MONEY_FIELDS, DEFAULT_WRITE_PREFIXES, type DataClient, type DataIdsOpts, type DataListIdsResult, type DataTransport, type DerivePolicyOptions, type DerivedPolicy, type DispatcherApprovalGate, type DispatcherApprovalOptions, type EmailPreviewInput, type EmitMarketplaceEventOptions, type EmitResult, type EmitTransport, type EncodeStateWithinEnvelopeOptions, type EncodedStateWithinEnvelope, type EventArgs, type ExecutionContextLike, FILE_REF_SOURCES_HELP, type FetchFileResult, type FetchWithRetryOptions, type FileRef, type FileRefContent, type FileRefEnv, FileRefError, type FileRefErrorCode, type FileRefStream, type FileRefVia, type GetAppFileResult, type HandlerFn, INBOX_SEND_CONTRACT_V1, type IdPrefixSpec, type IdSnapshot, 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, OAUTH_STATE_ENVELOPE_MAX_CHARS, type OAuthBouncerSignals, type OAuthState, type OfferUndoArgs, type PartialUpdateDataOptions, type PlatformHostEnv, type PolicyCheckInput, type PolicySource, type PublicBaseUrlEnv, type PurgeResult, type PutAppFileArgs, type PutAppFileResult, type PutAppFileStreamArgs, type ReadFileRefOptions, type RequireApprovalOptions, type ResolveFileRefOptions, type ResolveViewerOptions, type ResolvedFileRef, type RestoreResult, type RestoreSpec, SPRIGR_DATA_MAX_OBJECTS_PER_CALL, SPRIGR_FILE_HOSTS, SPRIGR_LOG_LEVELS, SPRIGR_LOG_LIMITS, type ScheduleArgs, type SmsPreviewInput, type SprigrAssertionMintResult, type SprigrAssertionsApi, 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 SprigrDataWriteTimeoutOpts, 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, WORKSPACE_FILE_HOW_TO, type WebhookArgs, type WfpBridgeEnv, type WfpEmitReply, actorKey, actorRetiredHook, actorTool, agentFileKeyFromUrl, appFileUrl, appKeyFromCallerKey, applyConfirmationPolicies, approvalHash, approvalPreview, approvalRecipients, archiveOfferRefusal, attendedFindings, base64ToBytes, buildConfirmationPolicy, buildMarketplaceWebhookUrl, buildPartialUpdateBody, bytesToBase64, callerKeyRefusal, canEmit, canLog, canPartialUpdate, checkConfirmationPolicy, commonDestructiveVerbs, connectComplete, connectDisconnect, constantTimeEqual, createMarketplaceEmitter, createToolWrappers, decodeState, defineInboxSendHandler, deleteAppFile, deleteSnapshotIds, deriveConfirmationPolicy, describeMissingBridge, dispatcherApproval, emailBodyHtml, emailPreview, emitMarketplaceEvent, encodeState, encodeStateWithinEnvelope, fetchFileAsBase64, fetchFileBytes, fetchWithRetry, fieldsPreview, fullWarning, getAppFile, getCompanyTimezone, hasHtmlMarkup, hmacSha256Hex, installTokenPost, isNotConnectedError, isStagingHost, listAppFiles, logToPlatform, makeDataClient, manifestIsFresh, oauthStateEnvelopeOverhead, offerUndo, openFileRef, overlaySprigr, ownerFromActorKey, parseActor, parseActorRetiredArgs, partialUpdateData, publicBaseUrl, purgeIndexByPrefix, putAppFile, putAppFileStream, randomHex, readFileRef, readableStoredKey, recreatedWarning, refuseWithoutForce, requireApproval, resolveFileRef, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, resolveViewerContext, resolveViewerUserId, runUndoApply, safeCapture, seq, serializeManifest, set, smsPreview, snapshotIndexIds, tool, undoEnvelope, validateLogEntries, validateLogEntry, verifyViewerToken, withSprigrEmitFallback, withSprigrInboxFallback, withSprigrLogFallback };
|
|
3837
|
+
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 ApprovalCoverage, type ApprovalGateOptions, type ApprovalPreviewFact, type ApprovalPreviewSlot, type ApprovalPreviewSpec, type ApprovalSpec, type ArchiveOfferOptions, type ArchiveOfferRefusal, type CallerKeyResolution, type CaptureJournal, type CompanyTimezoneEnv, type ConfirmCondition, type ConfirmRule, type ConfirmationPolicy, type ConnectCompleteRequest, type ConnectCompleteResult, type D1Like, type D1PreparedStatementLike, DATA_DELETE_MAX_IDS, DATA_PARTIAL_UPDATE_PATH, DEFAULT_EMIT_TIMEOUT_MS, DEFAULT_FILE_READ_TIMEOUT_MS, DEFAULT_LOG_TIMEOUT_MS, DEFAULT_MAX_FILE_BYTES, DEFAULT_MONEY_FIELDS, DEFAULT_WRITE_PREFIXES, type DataClient, type DataIdsOpts, type DataListIdsResult, type DataTransport, type DerivePolicyOptions, type DerivedPolicy, type DispatcherApprovalGate, type DispatcherApprovalOptions, type EmailPreviewInput, type EmitMarketplaceEventOptions, type EmitResult, type EmitTransport, type EncodeStateWithinEnvelopeOptions, type EncodedStateWithinEnvelope, type EventArgs, type ExecutionContextLike, FILE_REF_SOURCES_HELP, type FetchFileResult, type FetchWithRetryOptions, type FileRef, type FileRefContent, type FileRefEnv, FileRefError, type FileRefErrorCode, type FileRefStream, type FileRefVia, type GetAppFileResult, type HandlerFn, INBOX_SEND_CONTRACT_V1, type IdPrefixSpec, type IdSnapshot, 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, OAUTH_STATE_ENVELOPE_MAX_CHARS, type OAuthBouncerSignals, type OAuthState, type OfferUndoArgs, type PartialUpdateDataOptions, type PlatformHostEnv, type PolicyCheckInput, type PolicySource, type PublicBaseUrlEnv, type PurgeResult, type PutAppFileArgs, type PutAppFileResult, type PutAppFileStreamArgs, type ReadFileRefOptions, type RequireApprovalOptions, type ResolveFileRefOptions, type ResolveViewerOptions, type ResolvedFileRef, type RestoreResult, type RestoreSpec, SPRIGR_DATA_MAX_OBJECTS_PER_CALL, SPRIGR_FILE_HOSTS, SPRIGR_LOG_LEVELS, SPRIGR_LOG_LIMITS, type ScheduleArgs, type SmsPreviewInput, type SprigrAssertionMintResult, type SprigrAssertionsApi, 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 SprigrDataWriteTimeoutOpts, 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 SprigrMeApi, type SprigrMeSignatureError, type SprigrMeSignatureResult, 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, WORKSPACE_FILE_HOW_TO, type WebhookArgs, type WfpBridgeEnv, type WfpEmitReply, actorKey, actorRetiredHook, actorTool, agentFileKeyFromUrl, appFileUrl, appKeyFromCallerKey, applyConfirmationPolicies, approvalHash, approvalPreview, approvalRecipients, archiveOfferRefusal, attendedFindings, base64ToBytes, buildConfirmationPolicy, buildMarketplaceWebhookUrl, buildPartialUpdateBody, bytesToBase64, callerKeyRefusal, canEmit, canLog, canPartialUpdate, checkConfirmationPolicy, commonDestructiveVerbs, connectComplete, connectDisconnect, constantTimeEqual, createMarketplaceEmitter, createToolWrappers, decodeState, defineInboxSendHandler, deleteAppFile, deleteSnapshotIds, deriveConfirmationPolicy, describeMissingBridge, dispatcherApproval, emailBodyHtml, emailPreview, emitMarketplaceEvent, encodeState, encodeStateWithinEnvelope, fetchFileAsBase64, fetchFileBytes, fetchWithRetry, fieldsPreview, fullWarning, getAppFile, getCompanyTimezone, hasHtmlMarkup, hmacSha256Hex, installTokenPost, isNotConnectedError, isStagingHost, listAppFiles, logToPlatform, makeDataClient, manifestIsFresh, oauthStateEnvelopeOverhead, offerUndo, openFileRef, overlaySprigr, ownerFromActorKey, parseActor, parseActorRetiredArgs, partialUpdateData, publicBaseUrl, purgeIndexByPrefix, putAppFile, putAppFileStream, randomHex, readFileRef, readableStoredKey, recreatedWarning, refuseWithoutForce, requireApproval, resolveFileRef, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, resolveViewerContext, resolveViewerUserId, runUndoApply, safeCapture, seq, serializeManifest, set, smsPreview, snapshotIndexIds, tool, undoEnvelope, validateLogEntries, validateLogEntry, verifyViewerToken, withSenderSignature, withSprigrEmitFallback, withSprigrInboxFallback, withSprigrLogFallback };
|
package/dist/index.js
CHANGED
|
@@ -2318,6 +2318,22 @@ function emailBodyHtml(body) {
|
|
|
2318
2318
|
if (normalized.length === 0) return body;
|
|
2319
2319
|
return normalized.split(/\n[ \t]*\n+/).map((para) => `<p>${escapeHtml(para.replace(/^\n+|\n+$/g, "")).replace(/\n/g, "<br>")}</p>`).join("");
|
|
2320
2320
|
}
|
|
2321
|
+
|
|
2322
|
+
// src/sender-signature.ts
|
|
2323
|
+
async function withSenderSignature(sprigr, args) {
|
|
2324
|
+
const me = sprigr?.me;
|
|
2325
|
+
if (!args.senderPlatformUserId || typeof me?.signature !== "function") return args.html;
|
|
2326
|
+
try {
|
|
2327
|
+
const sig = await me.signature({ channel: args.channel });
|
|
2328
|
+
if (!sig.ok || !sig.html) return args.html;
|
|
2329
|
+
if (sig.platform_user_id !== args.senderPlatformUserId) return args.html;
|
|
2330
|
+
if (args.html.includes(sig.html)) return args.html;
|
|
2331
|
+
return `${args.html}<br><br>-- <br>${sig.html}`;
|
|
2332
|
+
} catch (err) {
|
|
2333
|
+
console.warn("[app-sdk] env.SPRIGR.me.signature failed; sending without a signature:", err instanceof Error ? err.message : err);
|
|
2334
|
+
return args.html;
|
|
2335
|
+
}
|
|
2336
|
+
}
|
|
2321
2337
|
export {
|
|
2322
2338
|
ACTOR_RETIRED_HOOK_TOOL,
|
|
2323
2339
|
ACTOR_RETIRE_REASONS,
|
|
@@ -2446,6 +2462,7 @@ export {
|
|
|
2446
2462
|
validateLogEntries,
|
|
2447
2463
|
validateLogEntry,
|
|
2448
2464
|
verifyViewerToken,
|
|
2465
|
+
withSenderSignature,
|
|
2449
2466
|
withSprigrEmitFallback,
|
|
2450
2467
|
withSprigrInboxFallback,
|
|
2451
2468
|
withSprigrLogFallback
|