@sprigr/apps-app-sdk 0.15.0 → 0.15.2
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 +24 -2
- package/dist/index.js +33 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1278,6 +1278,13 @@ declare function putAppFile(env: AppFilesEnv, args: PutAppFileArgs): Promise<Put
|
|
|
1278
1278
|
* and (with a `ReadableStream` body) never buffers them whole in the
|
|
1279
1279
|
* isolate — pipe a source `Response.body` directly through for multi-MB
|
|
1280
1280
|
* blobs. Metadata travels in headers; the body is opaque bytes.
|
|
1281
|
+
*
|
|
1282
|
+
* The platform's put-stream route cannot retry a transient R2 fault itself
|
|
1283
|
+
* (its body is spent once read), so a resendable body — `ArrayBuffer` /
|
|
1284
|
+
* `Uint8Array` already in hand, not a `ReadableStream` — gets a bounded
|
|
1285
|
+
* retry here instead. The key is deterministic, so a retry is a full
|
|
1286
|
+
* overwrite, exactly the argument the platform's buffered `put` route makes
|
|
1287
|
+
* for its own retry (wfp-files.ts, sprigr-team).
|
|
1281
1288
|
*/
|
|
1282
1289
|
declare function putAppFileStream(env: AppFilesEnv, args: PutAppFileStreamArgs): Promise<PutAppFileResult>;
|
|
1283
1290
|
/** Mint a signed, time-limited download URL for an app file. */
|
|
@@ -2509,6 +2516,21 @@ interface SprigrDataIndexOpts {
|
|
|
2509
2516
|
/** LOGICAL index name (a `data_indexes` key). See {@link SprigrDataSearchOpts.index}. */
|
|
2510
2517
|
index?: string;
|
|
2511
2518
|
}
|
|
2519
|
+
/** Options for `env.SPRIGR.data.import`. */
|
|
2520
|
+
interface SprigrDataImportOpts extends SprigrDataIndexOpts {
|
|
2521
|
+
/**
|
|
2522
|
+
* Write to the app's reserved ACL file index
|
|
2523
|
+
* (`<companyId>-app-<slug>-acl-files`) instead of its data index. Every
|
|
2524
|
+
* object must then carry `acl_principals`, a non-empty list of valid
|
|
2525
|
+
* principals, or the platform rejects the WHOLE batch. Cannot be combined
|
|
2526
|
+
* with `index` (the platform answers 400
|
|
2527
|
+
* `acl_index_combination_unsupported`), and is refused for apps that
|
|
2528
|
+
* declare `data_indexes`. Reads of that index (`search` / `get` with
|
|
2529
|
+
* `withAcl`) are refused over the install bridge (403 `acl_actor_required`),
|
|
2530
|
+
* so they are not modelled here; `delete` and `partialUpdate` accept it.
|
|
2531
|
+
*/
|
|
2532
|
+
withAcl?: boolean;
|
|
2533
|
+
}
|
|
2512
2534
|
/** Options for `env.SPRIGR.data.partialUpdate`. */
|
|
2513
2535
|
interface SprigrDataPartialUpdateOpts extends SprigrDataIndexOpts {
|
|
2514
2536
|
/**
|
|
@@ -2583,7 +2605,7 @@ interface SprigrDataApi {
|
|
|
2583
2605
|
import(objects: Array<{
|
|
2584
2606
|
objectID: string;
|
|
2585
2607
|
[key: string]: unknown;
|
|
2586
|
-
}>, opts?:
|
|
2608
|
+
}>, opts?: SprigrDataImportOpts): Promise<{
|
|
2587
2609
|
ok: boolean;
|
|
2588
2610
|
indexed: number;
|
|
2589
2611
|
index: string;
|
|
@@ -2898,4 +2920,4 @@ interface ExecutionContextLike {
|
|
|
2898
2920
|
}
|
|
2899
2921
|
type HandlerFn<TArgs, TResult> = (args: TArgs, env: Record<string, unknown>, ctx?: ExecutionContextLike) => Promise<TResult>;
|
|
2900
2922
|
|
|
2901
|
-
export { APPROVAL_GRANTED_KEY, type Actor, 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 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 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, actorTool, appFileUrl, applyConfirmationPolicies, approvalHash, archiveOfferRefusal, base64ToBytes, buildConfirmationPolicy, buildMarketplaceWebhookUrl, buildPartialUpdateBody, bytesToBase64, 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, partialUpdateData, putAppFile, putAppFileStream, randomHex, recreatedWarning, refuseWithoutForce, requireApproval, resolveInstallBridge, resolveOAuthBouncerBase, resolveOAuthBouncerCallbackUrl, resolvePlatformWebhookBase, resolveViewerContext, resolveViewerUserId, runUndoApply, safeCapture, seq, serializeManifest, set, tool, undoEnvelope, validateLogEntries, validateLogEntry, verifyViewerToken, withSprigrEmitFallback, withSprigrInboxFallback, withSprigrLogFallback };
|
|
2923
|
+
export { APPROVAL_GRANTED_KEY, type Actor, 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 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, actorTool, appFileUrl, applyConfirmationPolicies, approvalHash, archiveOfferRefusal, base64ToBytes, buildConfirmationPolicy, buildMarketplaceWebhookUrl, buildPartialUpdateBody, bytesToBase64, 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, partialUpdateData, putAppFile, putAppFileStream, randomHex, 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
|
@@ -893,6 +893,17 @@ function putAppFile(env, args) {
|
|
|
893
893
|
filename: args.filename
|
|
894
894
|
});
|
|
895
895
|
}
|
|
896
|
+
var STREAM_PUT_MAX_ATTEMPTS = 3;
|
|
897
|
+
var STREAM_PUT_BASE_DELAY_MS = 500;
|
|
898
|
+
function isTransientPutStreamFailure(status, message) {
|
|
899
|
+
if (status === 503) return true;
|
|
900
|
+
if (status !== 502) return false;
|
|
901
|
+
const msg = message.toLowerCase();
|
|
902
|
+
return msg.includes("(10001)") || msg.includes("(10043)");
|
|
903
|
+
}
|
|
904
|
+
function sleep2(ms) {
|
|
905
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
906
|
+
}
|
|
896
907
|
async function putAppFileStream(env, args) {
|
|
897
908
|
const token = requireToken(env);
|
|
898
909
|
const headers = {
|
|
@@ -905,14 +916,28 @@ async function putAppFileStream(env, args) {
|
|
|
905
916
|
if (typeof args.contentLength === "number" && Number.isFinite(args.contentLength)) {
|
|
906
917
|
headers["x-app-file-length"] = String(args.contentLength);
|
|
907
918
|
}
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
919
|
+
const resendable = !(args.body instanceof ReadableStream);
|
|
920
|
+
const attempts = resendable ? STREAM_PUT_MAX_ATTEMPTS : 1;
|
|
921
|
+
let lastErr;
|
|
922
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
923
|
+
const res = await fetch(`${platformBase(env)}/internal/wfp/file/put-stream`, {
|
|
924
|
+
method: "POST",
|
|
925
|
+
headers,
|
|
926
|
+
body: args.body,
|
|
927
|
+
// Required by the Workers runtime when sending a streaming request body.
|
|
928
|
+
...args.body instanceof ReadableStream ? { duplex: "half" } : {}
|
|
929
|
+
});
|
|
930
|
+
try {
|
|
931
|
+
return await parseResult(res, "put-stream");
|
|
932
|
+
} catch (err) {
|
|
933
|
+
lastErr = err;
|
|
934
|
+
if (!resendable || attempt === attempts || !(err instanceof AppFilesError) || !isTransientPutStreamFailure(err.status, err.message)) {
|
|
935
|
+
throw err;
|
|
936
|
+
}
|
|
937
|
+
await sleep2(STREAM_PUT_BASE_DELAY_MS * 2 ** (attempt - 1));
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
throw lastErr;
|
|
916
941
|
}
|
|
917
942
|
function appFileUrl(env, args) {
|
|
918
943
|
return call(env, "url", { key: args.key, expiresIn: args.expiresIn });
|