@cloudpdf/engine 3.0.0-next.1 → 3.0.0-next.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.cjs +62 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -2
- package/dist/index.d.ts +51 -2
- package/dist/index.js +60 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRaster, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
|
|
1
|
+
import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRaster, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, TokenSource as TokenSource$1, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
|
|
2
2
|
import { CdnAccessInfoForApply, DocumentHead, DocumentManifest, LayerScopePlane } from "@embedpdf/engine-core/wire";
|
|
3
3
|
import { SessionEventPublisher } from "@embedpdf/engine-services";
|
|
4
4
|
//#region src/transport/HttpClient.d.ts
|
|
@@ -572,6 +572,55 @@ interface UnverifiedClaims {
|
|
|
572
572
|
}
|
|
573
573
|
declare function decodeUnverifiedClaims(token: string): UnverifiedClaims;
|
|
574
574
|
//#endregion
|
|
575
|
+
//#region src/share.d.ts
|
|
576
|
+
/**
|
|
577
|
+
* Share-session exchange: the client half of the no-backend embed flow.
|
|
578
|
+
*
|
|
579
|
+
* A share token (`shr_…`) is a REFERENCE to a stored grant on the
|
|
580
|
+
* server, not a credential — `exchangeShareToken` trades it for an
|
|
581
|
+
* ordinary short-lived doc JWT, and `shareSessionSource` wraps that in
|
|
582
|
+
* a self-renewing {@link TokenSource}. Because the engine's transport
|
|
583
|
+
* invokes its token source on every request (and SSE reconnects call
|
|
584
|
+
* it again), renewal is nothing more than "exchange again when the
|
|
585
|
+
* cached session is nearly out" — no timers, no listeners.
|
|
586
|
+
*
|
|
587
|
+
* The endpoint requires a browser `Origin` header (the server checks
|
|
588
|
+
* it against the grant's allowlist). Browsers attach it automatically;
|
|
589
|
+
* non-browser callers (tests, SSR) must supply a `fetch` that does.
|
|
590
|
+
*/
|
|
591
|
+
interface ShareSession {
|
|
592
|
+
/** Doc-scoped session JWT carrying the grant's capabilities. */
|
|
593
|
+
token: string;
|
|
594
|
+
docId: string;
|
|
595
|
+
layerName: string;
|
|
596
|
+
/** Unix seconds when `token` expires. */
|
|
597
|
+
expiresAt: number;
|
|
598
|
+
}
|
|
599
|
+
interface ShareExchangeOptions {
|
|
600
|
+
/** Passphrase for protected grants (`SharePasswordRequired` otherwise). */
|
|
601
|
+
password?: string;
|
|
602
|
+
fetch?: typeof globalThis.fetch;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Thrown on a non-OK exchange. `code` is the server's wire code:
|
|
606
|
+
* `SharePasswordRequired` (prompt and retry with a password),
|
|
607
|
+
* `OriginNotAllowed` / `OriginRequired`, `ShareExpired`, `NotFound`
|
|
608
|
+
* (unknown or revoked — indistinguishable by design), or
|
|
609
|
+
* `TooManyRequests`.
|
|
610
|
+
*/
|
|
611
|
+
declare class ShareExchangeError extends Error {
|
|
612
|
+
readonly code: string;
|
|
613
|
+
readonly status: number;
|
|
614
|
+
constructor(code: string, message: string, status: number);
|
|
615
|
+
}
|
|
616
|
+
declare function exchangeShareToken(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions): Promise<ShareSession>;
|
|
617
|
+
/**
|
|
618
|
+
* A caching, self-renewing {@link TokenSource} over the exchange.
|
|
619
|
+
* Concurrent callers share one in-flight exchange; a failed exchange
|
|
620
|
+
* clears it so the next request retries rather than caching the error.
|
|
621
|
+
*/
|
|
622
|
+
declare function shareSessionSource(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions): TokenSource$1;
|
|
623
|
+
//#endregion
|
|
575
624
|
//#region src/index.d.ts
|
|
576
625
|
declare function createCloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
577
626
|
/**
|
|
@@ -596,5 +645,5 @@ declare function createCloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
|
596
645
|
*/
|
|
597
646
|
declare function cloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
598
647
|
//#endregion
|
|
599
|
-
export { AbortError, AbortablePromise, CloudDocumentAnnotationsService, CloudDocumentHandle, CloudDocumentPagesService, CloudEngine, type CloudEngineOptions, CloudMetadataService, CloudPageAnnotationsService, CloudPageGeometryService, CloudPageHandle, CloudPageRenderService, type DocumentAccessInfo, type DocumentAnnotationsService, type DocumentCapabilities, type DocumentHandle, type DocumentIdentity, type DocumentPagesService, type DocumentSecurityService, type DocumentSecurityState, type DocumentUnlockInput, type DocumentUnlockResult, type Engine, EngineError, EngineErrorCode, type EngineFactory, HttpClient, type HttpClientOptions, type MetadataService, type OpenInput, type OpenOptions, type PageAnnotationsService, type PageGeometryService, type PageHandle, type PageRenderService, type PageTextService, type PdfSaveMode, type TokenSource, type UnverifiedClaims, cloudEngine, createCloudEngine, decodeUnverifiedClaims };
|
|
648
|
+
export { AbortError, AbortablePromise, CloudDocumentAnnotationsService, CloudDocumentHandle, CloudDocumentPagesService, CloudEngine, type CloudEngineOptions, CloudMetadataService, CloudPageAnnotationsService, CloudPageGeometryService, CloudPageHandle, CloudPageRenderService, type DocumentAccessInfo, type DocumentAnnotationsService, type DocumentCapabilities, type DocumentHandle, type DocumentIdentity, type DocumentPagesService, type DocumentSecurityService, type DocumentSecurityState, type DocumentUnlockInput, type DocumentUnlockResult, type Engine, EngineError, EngineErrorCode, type EngineFactory, HttpClient, type HttpClientOptions, type MetadataService, type OpenInput, type OpenOptions, type PageAnnotationsService, type PageGeometryService, type PageHandle, type PageRenderService, type PageTextService, type PdfSaveMode, ShareExchangeError, type ShareExchangeOptions, type ShareSession, type TokenSource, type UnverifiedClaims, cloudEngine, createCloudEngine, decodeUnverifiedClaims, exchangeShareToken, shareSessionSource };
|
|
600
649
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRaster, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
|
|
1
|
+
import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRaster, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, TokenSource as TokenSource$1, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
|
|
2
2
|
import { CdnAccessInfoForApply, DocumentHead, DocumentManifest, LayerScopePlane } from "@embedpdf/engine-core/wire";
|
|
3
3
|
import { SessionEventPublisher } from "@embedpdf/engine-services";
|
|
4
4
|
//#region src/transport/HttpClient.d.ts
|
|
@@ -572,6 +572,55 @@ interface UnverifiedClaims {
|
|
|
572
572
|
}
|
|
573
573
|
declare function decodeUnverifiedClaims(token: string): UnverifiedClaims;
|
|
574
574
|
//#endregion
|
|
575
|
+
//#region src/share.d.ts
|
|
576
|
+
/**
|
|
577
|
+
* Share-session exchange: the client half of the no-backend embed flow.
|
|
578
|
+
*
|
|
579
|
+
* A share token (`shr_…`) is a REFERENCE to a stored grant on the
|
|
580
|
+
* server, not a credential — `exchangeShareToken` trades it for an
|
|
581
|
+
* ordinary short-lived doc JWT, and `shareSessionSource` wraps that in
|
|
582
|
+
* a self-renewing {@link TokenSource}. Because the engine's transport
|
|
583
|
+
* invokes its token source on every request (and SSE reconnects call
|
|
584
|
+
* it again), renewal is nothing more than "exchange again when the
|
|
585
|
+
* cached session is nearly out" — no timers, no listeners.
|
|
586
|
+
*
|
|
587
|
+
* The endpoint requires a browser `Origin` header (the server checks
|
|
588
|
+
* it against the grant's allowlist). Browsers attach it automatically;
|
|
589
|
+
* non-browser callers (tests, SSR) must supply a `fetch` that does.
|
|
590
|
+
*/
|
|
591
|
+
interface ShareSession {
|
|
592
|
+
/** Doc-scoped session JWT carrying the grant's capabilities. */
|
|
593
|
+
token: string;
|
|
594
|
+
docId: string;
|
|
595
|
+
layerName: string;
|
|
596
|
+
/** Unix seconds when `token` expires. */
|
|
597
|
+
expiresAt: number;
|
|
598
|
+
}
|
|
599
|
+
interface ShareExchangeOptions {
|
|
600
|
+
/** Passphrase for protected grants (`SharePasswordRequired` otherwise). */
|
|
601
|
+
password?: string;
|
|
602
|
+
fetch?: typeof globalThis.fetch;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Thrown on a non-OK exchange. `code` is the server's wire code:
|
|
606
|
+
* `SharePasswordRequired` (prompt and retry with a password),
|
|
607
|
+
* `OriginNotAllowed` / `OriginRequired`, `ShareExpired`, `NotFound`
|
|
608
|
+
* (unknown or revoked — indistinguishable by design), or
|
|
609
|
+
* `TooManyRequests`.
|
|
610
|
+
*/
|
|
611
|
+
declare class ShareExchangeError extends Error {
|
|
612
|
+
readonly code: string;
|
|
613
|
+
readonly status: number;
|
|
614
|
+
constructor(code: string, message: string, status: number);
|
|
615
|
+
}
|
|
616
|
+
declare function exchangeShareToken(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions): Promise<ShareSession>;
|
|
617
|
+
/**
|
|
618
|
+
* A caching, self-renewing {@link TokenSource} over the exchange.
|
|
619
|
+
* Concurrent callers share one in-flight exchange; a failed exchange
|
|
620
|
+
* clears it so the next request retries rather than caching the error.
|
|
621
|
+
*/
|
|
622
|
+
declare function shareSessionSource(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions): TokenSource$1;
|
|
623
|
+
//#endregion
|
|
575
624
|
//#region src/index.d.ts
|
|
576
625
|
declare function createCloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
577
626
|
/**
|
|
@@ -596,5 +645,5 @@ declare function createCloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
|
596
645
|
*/
|
|
597
646
|
declare function cloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
598
647
|
//#endregion
|
|
599
|
-
export { AbortError, AbortablePromise, CloudDocumentAnnotationsService, CloudDocumentHandle, CloudDocumentPagesService, CloudEngine, type CloudEngineOptions, CloudMetadataService, CloudPageAnnotationsService, CloudPageGeometryService, CloudPageHandle, CloudPageRenderService, type DocumentAccessInfo, type DocumentAnnotationsService, type DocumentCapabilities, type DocumentHandle, type DocumentIdentity, type DocumentPagesService, type DocumentSecurityService, type DocumentSecurityState, type DocumentUnlockInput, type DocumentUnlockResult, type Engine, EngineError, EngineErrorCode, type EngineFactory, HttpClient, type HttpClientOptions, type MetadataService, type OpenInput, type OpenOptions, type PageAnnotationsService, type PageGeometryService, type PageHandle, type PageRenderService, type PageTextService, type PdfSaveMode, type TokenSource, type UnverifiedClaims, cloudEngine, createCloudEngine, decodeUnverifiedClaims };
|
|
648
|
+
export { AbortError, AbortablePromise, CloudDocumentAnnotationsService, CloudDocumentHandle, CloudDocumentPagesService, CloudEngine, type CloudEngineOptions, CloudMetadataService, CloudPageAnnotationsService, CloudPageGeometryService, CloudPageHandle, CloudPageRenderService, type DocumentAccessInfo, type DocumentAnnotationsService, type DocumentCapabilities, type DocumentHandle, type DocumentIdentity, type DocumentPagesService, type DocumentSecurityService, type DocumentSecurityState, type DocumentUnlockInput, type DocumentUnlockResult, type Engine, EngineError, EngineErrorCode, type EngineFactory, HttpClient, type HttpClientOptions, type MetadataService, type OpenInput, type OpenOptions, type PageAnnotationsService, type PageGeometryService, type PageHandle, type PageRenderService, type PageTextService, type PdfSaveMode, ShareExchangeError, type ShareExchangeOptions, type ShareSession, type TokenSource, type UnverifiedClaims, cloudEngine, createCloudEngine, decodeUnverifiedClaims, exchangeShareToken, shareSessionSource };
|
|
600
649
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -2443,6 +2443,65 @@ async function settleLinked(pending, signal) {
|
|
|
2443
2443
|
}
|
|
2444
2444
|
}
|
|
2445
2445
|
//#endregion
|
|
2446
|
+
//#region src/share.ts
|
|
2447
|
+
/**
|
|
2448
|
+
* Thrown on a non-OK exchange. `code` is the server's wire code:
|
|
2449
|
+
* `SharePasswordRequired` (prompt and retry with a password),
|
|
2450
|
+
* `OriginNotAllowed` / `OriginRequired`, `ShareExpired`, `NotFound`
|
|
2451
|
+
* (unknown or revoked — indistinguishable by design), or
|
|
2452
|
+
* `TooManyRequests`.
|
|
2453
|
+
*/
|
|
2454
|
+
var ShareExchangeError = class extends Error {
|
|
2455
|
+
constructor(code, message, status) {
|
|
2456
|
+
super(message);
|
|
2457
|
+
this.code = code;
|
|
2458
|
+
this.status = status;
|
|
2459
|
+
this.name = "ShareExchangeError";
|
|
2460
|
+
}
|
|
2461
|
+
};
|
|
2462
|
+
async function exchangeShareToken(baseUrl, shareToken, opts = {}) {
|
|
2463
|
+
const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl.replace(/\/$/, "")}/v1/share-sessions`, {
|
|
2464
|
+
method: "POST",
|
|
2465
|
+
headers: { "content-type": "application/json" },
|
|
2466
|
+
body: JSON.stringify({
|
|
2467
|
+
shareToken,
|
|
2468
|
+
...opts.password !== void 0 ? { password: opts.password } : {}
|
|
2469
|
+
})
|
|
2470
|
+
});
|
|
2471
|
+
if (!res.ok) {
|
|
2472
|
+
let code = "Unknown";
|
|
2473
|
+
let message = `share exchange failed with status ${res.status}`;
|
|
2474
|
+
try {
|
|
2475
|
+
const payload = await res.json();
|
|
2476
|
+
if (payload.error?.code) code = payload.error.code;
|
|
2477
|
+
if (payload.error?.message) message = payload.error.message;
|
|
2478
|
+
} catch {}
|
|
2479
|
+
throw new ShareExchangeError(code, message, res.status);
|
|
2480
|
+
}
|
|
2481
|
+
return await res.json();
|
|
2482
|
+
}
|
|
2483
|
+
/** Renew this many seconds before `expiresAt` so in-flight requests never race expiry. */
|
|
2484
|
+
const RENEW_MARGIN_SECONDS = 60;
|
|
2485
|
+
/**
|
|
2486
|
+
* A caching, self-renewing {@link TokenSource} over the exchange.
|
|
2487
|
+
* Concurrent callers share one in-flight exchange; a failed exchange
|
|
2488
|
+
* clears it so the next request retries rather than caching the error.
|
|
2489
|
+
*/
|
|
2490
|
+
function shareSessionSource(baseUrl, shareToken, opts = {}) {
|
|
2491
|
+
let session = null;
|
|
2492
|
+
let inflight = null;
|
|
2493
|
+
return async () => {
|
|
2494
|
+
if (session && session.expiresAt - Date.now() / 1e3 > RENEW_MARGIN_SECONDS) return session.token;
|
|
2495
|
+
inflight ?? (inflight = exchangeShareToken(baseUrl, shareToken, opts).then((next) => {
|
|
2496
|
+
session = next;
|
|
2497
|
+
return next.token;
|
|
2498
|
+
}).finally(() => {
|
|
2499
|
+
inflight = null;
|
|
2500
|
+
}));
|
|
2501
|
+
return inflight;
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2504
|
+
//#endregion
|
|
2446
2505
|
//#region src/index.ts
|
|
2447
2506
|
function createCloudEngine(opts) {
|
|
2448
2507
|
return CloudEngine.fromOptions(opts);
|
|
@@ -2471,6 +2530,6 @@ function cloudEngine(opts) {
|
|
|
2471
2530
|
return CloudEngine.fromOptions(opts);
|
|
2472
2531
|
}
|
|
2473
2532
|
//#endregion
|
|
2474
|
-
export { AbortError, AbortablePromise, CloudDocumentAnnotationsService, CloudDocumentHandle, CloudDocumentPagesService, CloudEngine, CloudMetadataService, CloudPageAnnotationsService, CloudPageGeometryService, CloudPageHandle, CloudPageRenderService, EngineError, EngineErrorCode, HttpClient, cloudEngine, createCloudEngine, decodeUnverifiedClaims };
|
|
2533
|
+
export { AbortError, AbortablePromise, CloudDocumentAnnotationsService, CloudDocumentHandle, CloudDocumentPagesService, CloudEngine, CloudMetadataService, CloudPageAnnotationsService, CloudPageGeometryService, CloudPageHandle, CloudPageRenderService, EngineError, EngineErrorCode, HttpClient, ShareExchangeError, cloudEngine, createCloudEngine, decodeUnverifiedClaims, exchangeShareToken, shareSessionSource };
|
|
2475
2534
|
|
|
2476
2535
|
//# sourceMappingURL=index.js.map
|