@sprigr/apps-app-sdk 0.4.0 → 0.5.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
@@ -528,6 +528,59 @@ declare function parseActor(args: unknown): Actor | undefined;
528
528
  * treat that as "no caller identity" and fail closed.
529
529
  */
530
530
  declare function actorKey(actor: Actor | undefined): string | null;
531
+ /**
532
+ * Mailbox-owner attribution for one `env.SPRIGR.inbox.append` /
533
+ * `env.SPRIGR.inbox.folders` batch.
534
+ *
535
+ * Exactly ONE of the two fields must be set:
536
+ *
537
+ * - `platformUserId` — OIDC sub of the user whose mailbox the batch was
538
+ * synced from (a personal mailbox connection).
539
+ * - `agentId` — agent id for an agent-keyed connection (a shared /
540
+ * departmental mailbox connected through a shared agent rather than a
541
+ * person).
542
+ *
543
+ * Why this exists: a mail app install is shared by the whole company, and
544
+ * several users can each connect their own mailbox to it. The platform files
545
+ * every appended message under the ONE integration behind the install, so
546
+ * without attribution it cannot tell whose mailbox a batch came from and has
547
+ * historically granted thread visibility to every connected user. Passing
548
+ * `owner` pins each synced thread's visibility to exactly the mailbox owner:
549
+ * user connections stay private to that user, agent-keyed connections stay
550
+ * visible to that agent's audience.
551
+ *
552
+ * This is the OWNER OF THE MAILBOX (the connection identity the app keyed
553
+ * the sync on), NOT the dispatch caller — a scheduled poll has no caller at
554
+ * all yet must still attribute every batch. Populate it from the per-actor
555
+ * connection row the sync loop is iterating, e.g.:
556
+ *
557
+ * const owner = row.sprigr_user_id
558
+ * ? { platformUserId: row.sprigr_user_id }
559
+ * : { agentId: row.sprigr_agent_id };
560
+ * await env.SPRIGR.inbox.append({ channel, messages, owner });
561
+ *
562
+ * Mail apps must send it on EVERY append/folders call (sync poll, push
563
+ * delivery, backfill, folder reports). Batches without it fall back to the
564
+ * platform's legacy integration-level resolution, which on a multi-user
565
+ * install pins nobody (fail closed) rather than everyone.
566
+ *
567
+ * Hosts older than the attribution surface ignore the field entirely, so
568
+ * sending it is always safe.
569
+ */
570
+ interface InboxOwner {
571
+ /** OIDC sub (platform user id) of the mailbox's owner. */
572
+ platformUserId?: string;
573
+ /** Agent id for an agent-keyed (shared-mailbox) connection. */
574
+ agentId?: string;
575
+ }
576
+ /**
577
+ * Inverse of `actorKey`: turn a stored `u:<platformUserId>` / `a:<agentId>`
578
+ * key back into an `InboxOwner`. For apps that persist the connection
579
+ * identity as an actor-key string and need to attribute inbox batches from
580
+ * it. Returns null for null/empty/unrecognised input — callers should treat
581
+ * that as "owner unknown" and omit the field rather than guess.
582
+ */
583
+ declare function ownerFromActorKey(key: string | null | undefined): InboxOwner | null;
531
584
 
532
585
  /**
533
586
  * App-scoped R2 file storage (platform feature, 2026-06).
@@ -939,4 +992,4 @@ interface ExecutionContextLike {
939
992
  }
940
993
  type HandlerFn<TArgs, TResult> = (args: TArgs, env: Record<string, unknown>, ctx?: ExecutionContextLike) => Promise<TResult>;
941
994
 
942
- export { type Actor, type AppFileListItem, type AppFileUrlArgs, type AppFileUrlResult, type AppFilesEnv, type D1Like, type D1PreparedStatementLike, DEFAULT_EMIT_TIMEOUT_MS, DEFAULT_MAX_FILE_BYTES, type EmitMarketplaceEventOptions, type EmitResult, type EmitTransport, type EventArgs, type ExecutionContextLike, type FetchFileResult, type FetchWithRetryOptions, type GetAppFileResult, type HandlerFn, type InstallBridge, type MarketplaceEventEmitOpts, type MarketplaceEventSourceIntegration, type OAuthBouncerSignals, type OAuthState, type PlatformHostEnv, type PutAppFileArgs, type PutAppFileResult, type PutAppFileStreamArgs, type ScheduleArgs, type SprigrDataApi, type SprigrDataSearchOpts, type SprigrDataSearchResult, type SprigrFilesApi, type SprigrFilesApiWithEdit, type SprigrFilesCreateInput, type SprigrFilesCreateResult, type SprigrFilesEditInput, type SprigrFilesEditResult, type SprigrFilesJobResult, type WebhookArgs, type WfpBridgeEnv, type WfpEmitReply, actorKey, appFileUrl, base64ToBytes, buildMarketplaceWebhookUrl, bytesToBase64, canEmit, constantTimeEqual, createMarketplaceEmitter, decodeState, deleteAppFile, describeMissingBridge, emitMarketplaceEvent, encodeState, fetchFileAsBase64, fetchFileBytes, fetchWithRetry, getAppFile, hmacSha256Hex, installTokenPost, isStagingHost, listAppFiles, overlaySprigr, parseActor, putAppFile, putAppFileStream, randomHex, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, withSprigrEmitFallback };
995
+ export { type Actor, type AppFileListItem, type AppFileUrlArgs, type AppFileUrlResult, type AppFilesEnv, type D1Like, type D1PreparedStatementLike, DEFAULT_EMIT_TIMEOUT_MS, DEFAULT_MAX_FILE_BYTES, type EmitMarketplaceEventOptions, type EmitResult, type EmitTransport, type EventArgs, type ExecutionContextLike, type FetchFileResult, type FetchWithRetryOptions, type GetAppFileResult, type HandlerFn, type InboxOwner, type InstallBridge, type MarketplaceEventEmitOpts, type MarketplaceEventSourceIntegration, type OAuthBouncerSignals, type OAuthState, type PlatformHostEnv, type PutAppFileArgs, type PutAppFileResult, type PutAppFileStreamArgs, type ScheduleArgs, type SprigrDataApi, type SprigrDataSearchOpts, type SprigrDataSearchResult, type SprigrFilesApi, type SprigrFilesApiWithEdit, type SprigrFilesCreateInput, type SprigrFilesCreateResult, type SprigrFilesEditInput, type SprigrFilesEditResult, type SprigrFilesJobResult, type WebhookArgs, type WfpBridgeEnv, type WfpEmitReply, actorKey, appFileUrl, base64ToBytes, buildMarketplaceWebhookUrl, bytesToBase64, canEmit, constantTimeEqual, createMarketplaceEmitter, decodeState, deleteAppFile, describeMissingBridge, emitMarketplaceEvent, encodeState, fetchFileAsBase64, fetchFileBytes, fetchWithRetry, getAppFile, hmacSha256Hex, installTokenPost, isStagingHost, listAppFiles, overlaySprigr, ownerFromActorKey, parseActor, putAppFile, putAppFileStream, randomHex, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, withSprigrEmitFallback };
package/dist/index.js CHANGED
@@ -332,6 +332,12 @@ function actorKey(actor) {
332
332
  if (actor.agentId) return `a:${actor.agentId}`;
333
333
  return null;
334
334
  }
335
+ function ownerFromActorKey(key) {
336
+ if (!key) return null;
337
+ if (key.startsWith("u:") && key.length > 2) return { platformUserId: key.slice(2) };
338
+ if (key.startsWith("a:") && key.length > 2) return { agentId: key.slice(2) };
339
+ return null;
340
+ }
335
341
 
336
342
  // src/app-files.ts
337
343
  var DEFAULT_PLATFORM_BASE = "https://webhooks.sprigr.com";
@@ -444,6 +450,7 @@ export {
444
450
  isStagingHost,
445
451
  listAppFiles,
446
452
  overlaySprigr,
453
+ ownerFromActorKey,
447
454
  parseActor,
448
455
  putAppFile,
449
456
  putAppFileStream,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprigr/apps-app-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",