@cloudpdf/engine 3.0.0-next.3 → 3.0.0-next.4
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 +116 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -6
- package/dist/index.d.ts +29 -6
- package/dist/index.js +116 -63
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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,
|
|
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, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, 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";
|
|
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
|
|
@@ -48,12 +48,21 @@ interface HttpFileResponse {
|
|
|
48
48
|
headers: Headers;
|
|
49
49
|
}
|
|
50
50
|
declare class HttpClient {
|
|
51
|
-
private readonly
|
|
51
|
+
private readonly base;
|
|
52
52
|
private readonly tokenFn;
|
|
53
53
|
private readonly fetchFn;
|
|
54
54
|
private readonly sessionId;
|
|
55
55
|
private cdnBinding;
|
|
56
56
|
constructor(opts: HttpClientOptions);
|
|
57
|
+
/** Normalized server base URL (no trailing slash). */
|
|
58
|
+
get baseUrl(): string;
|
|
59
|
+
/**
|
|
60
|
+
* The fetch implementation this client sends requests through (injected
|
|
61
|
+
* or global). Exposed so sibling transports spawned per-open — the
|
|
62
|
+
* share-session exchange, most of all — ride the same fetch the engine
|
|
63
|
+
* was configured with (test doubles, SSR `Origin`-attaching wrappers).
|
|
64
|
+
*/
|
|
65
|
+
get fetchImpl(): typeof globalThis.fetch;
|
|
57
66
|
/**
|
|
58
67
|
* Return a clone of this client bound to a different bearer. Used
|
|
59
68
|
* by `CloudEngine.open` to mint a per-handle client carrying the
|
|
@@ -579,7 +588,7 @@ declare function decodeUnverifiedClaims(token: string): UnverifiedClaims;
|
|
|
579
588
|
* A share token (`shr_…`) is a REFERENCE to a stored grant on the
|
|
580
589
|
* server, not a credential — `exchangeShareToken` trades it for an
|
|
581
590
|
* ordinary short-lived doc JWT, and `shareSessionSource` wraps that in
|
|
582
|
-
* a self-renewing
|
|
591
|
+
* a self-renewing token source. Because the engine's transport
|
|
583
592
|
* invokes its token source on every request (and SSE reconnects call
|
|
584
593
|
* it again), renewal is nothing more than "exchange again when the
|
|
585
594
|
* cached session is nearly out" — no timers, no listeners.
|
|
@@ -615,11 +624,25 @@ declare class ShareExchangeError extends Error {
|
|
|
615
624
|
}
|
|
616
625
|
declare function exchangeShareToken(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions): Promise<ShareSession>;
|
|
617
626
|
/**
|
|
618
|
-
*
|
|
627
|
+
* Lift a {@link ShareExchangeError} into the engine's error taxonomy, so
|
|
628
|
+
* `open({ kind: 'share' })` and every later renewal fail with the same
|
|
629
|
+
* `EngineError` family as all other engine calls. The wire code and HTTP
|
|
630
|
+
* status survive in `details`; the original error rides as `cause`.
|
|
631
|
+
*
|
|
632
|
+
* `SharePasswordRequired` gets its own engine code — it is the one outcome
|
|
633
|
+
* callers branch on programmatically (prompt for the grant passphrase and
|
|
634
|
+
* retry). Everything else maps by meaning, with the HTTP status as the
|
|
635
|
+
* fallback discriminator.
|
|
636
|
+
*/
|
|
637
|
+
declare function engineErrorFromShareExchange(error: ShareExchangeError): EngineError$1;
|
|
638
|
+
/**
|
|
639
|
+
* A caching, self-renewing token source over the exchange — the callable
|
|
640
|
+
* member of the engine's `TokenSource` union, assignable wherever one is
|
|
641
|
+
* taken.
|
|
619
642
|
* Concurrent callers share one in-flight exchange; a failed exchange
|
|
620
643
|
* clears it so the next request retries rather than caching the error.
|
|
621
644
|
*/
|
|
622
|
-
declare function shareSessionSource(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions):
|
|
645
|
+
declare function shareSessionSource(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions): () => Promise<string>;
|
|
623
646
|
//#endregion
|
|
624
647
|
//#region src/index.d.ts
|
|
625
648
|
declare function createCloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
@@ -645,5 +668,5 @@ declare function createCloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
|
645
668
|
*/
|
|
646
669
|
declare function cloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
647
670
|
//#endregion
|
|
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 };
|
|
671
|
+
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 OpenInputShare, 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, engineErrorFromShareExchange, exchangeShareToken, shareSessionSource };
|
|
649
672
|
//# 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,
|
|
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, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, 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";
|
|
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
|
|
@@ -48,12 +48,21 @@ interface HttpFileResponse {
|
|
|
48
48
|
headers: Headers;
|
|
49
49
|
}
|
|
50
50
|
declare class HttpClient {
|
|
51
|
-
private readonly
|
|
51
|
+
private readonly base;
|
|
52
52
|
private readonly tokenFn;
|
|
53
53
|
private readonly fetchFn;
|
|
54
54
|
private readonly sessionId;
|
|
55
55
|
private cdnBinding;
|
|
56
56
|
constructor(opts: HttpClientOptions);
|
|
57
|
+
/** Normalized server base URL (no trailing slash). */
|
|
58
|
+
get baseUrl(): string;
|
|
59
|
+
/**
|
|
60
|
+
* The fetch implementation this client sends requests through (injected
|
|
61
|
+
* or global). Exposed so sibling transports spawned per-open — the
|
|
62
|
+
* share-session exchange, most of all — ride the same fetch the engine
|
|
63
|
+
* was configured with (test doubles, SSR `Origin`-attaching wrappers).
|
|
64
|
+
*/
|
|
65
|
+
get fetchImpl(): typeof globalThis.fetch;
|
|
57
66
|
/**
|
|
58
67
|
* Return a clone of this client bound to a different bearer. Used
|
|
59
68
|
* by `CloudEngine.open` to mint a per-handle client carrying the
|
|
@@ -579,7 +588,7 @@ declare function decodeUnverifiedClaims(token: string): UnverifiedClaims;
|
|
|
579
588
|
* A share token (`shr_…`) is a REFERENCE to a stored grant on the
|
|
580
589
|
* server, not a credential — `exchangeShareToken` trades it for an
|
|
581
590
|
* ordinary short-lived doc JWT, and `shareSessionSource` wraps that in
|
|
582
|
-
* a self-renewing
|
|
591
|
+
* a self-renewing token source. Because the engine's transport
|
|
583
592
|
* invokes its token source on every request (and SSE reconnects call
|
|
584
593
|
* it again), renewal is nothing more than "exchange again when the
|
|
585
594
|
* cached session is nearly out" — no timers, no listeners.
|
|
@@ -615,11 +624,25 @@ declare class ShareExchangeError extends Error {
|
|
|
615
624
|
}
|
|
616
625
|
declare function exchangeShareToken(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions): Promise<ShareSession>;
|
|
617
626
|
/**
|
|
618
|
-
*
|
|
627
|
+
* Lift a {@link ShareExchangeError} into the engine's error taxonomy, so
|
|
628
|
+
* `open({ kind: 'share' })` and every later renewal fail with the same
|
|
629
|
+
* `EngineError` family as all other engine calls. The wire code and HTTP
|
|
630
|
+
* status survive in `details`; the original error rides as `cause`.
|
|
631
|
+
*
|
|
632
|
+
* `SharePasswordRequired` gets its own engine code — it is the one outcome
|
|
633
|
+
* callers branch on programmatically (prompt for the grant passphrase and
|
|
634
|
+
* retry). Everything else maps by meaning, with the HTTP status as the
|
|
635
|
+
* fallback discriminator.
|
|
636
|
+
*/
|
|
637
|
+
declare function engineErrorFromShareExchange(error: ShareExchangeError): EngineError$1;
|
|
638
|
+
/**
|
|
639
|
+
* A caching, self-renewing token source over the exchange — the callable
|
|
640
|
+
* member of the engine's `TokenSource` union, assignable wherever one is
|
|
641
|
+
* taken.
|
|
619
642
|
* Concurrent callers share one in-flight exchange; a failed exchange
|
|
620
643
|
* clears it so the next request retries rather than caching the error.
|
|
621
644
|
*/
|
|
622
|
-
declare function shareSessionSource(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions):
|
|
645
|
+
declare function shareSessionSource(baseUrl: string, shareToken: string, opts?: ShareExchangeOptions): () => Promise<string>;
|
|
623
646
|
//#endregion
|
|
624
647
|
//#region src/index.d.ts
|
|
625
648
|
declare function createCloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
@@ -645,5 +668,5 @@ declare function createCloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
|
645
668
|
*/
|
|
646
669
|
declare function cloudEngine(opts: CloudEngineOptions): CloudEngine;
|
|
647
670
|
//#endregion
|
|
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 };
|
|
671
|
+
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 OpenInputShare, 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, engineErrorFromShareExchange, exchangeShareToken, shareSessionSource };
|
|
649
672
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1955,20 +1955,114 @@ function awaitSignal(promise, signal) {
|
|
|
1955
1955
|
});
|
|
1956
1956
|
}
|
|
1957
1957
|
//#endregion
|
|
1958
|
+
//#region src/share.ts
|
|
1959
|
+
/**
|
|
1960
|
+
* Thrown on a non-OK exchange. `code` is the server's wire code:
|
|
1961
|
+
* `SharePasswordRequired` (prompt and retry with a password),
|
|
1962
|
+
* `OriginNotAllowed` / `OriginRequired`, `ShareExpired`, `NotFound`
|
|
1963
|
+
* (unknown or revoked — indistinguishable by design), or
|
|
1964
|
+
* `TooManyRequests`.
|
|
1965
|
+
*/
|
|
1966
|
+
var ShareExchangeError = class extends Error {
|
|
1967
|
+
constructor(code, message, status) {
|
|
1968
|
+
super(message);
|
|
1969
|
+
this.code = code;
|
|
1970
|
+
this.status = status;
|
|
1971
|
+
this.name = "ShareExchangeError";
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
async function exchangeShareToken(baseUrl, shareToken, opts = {}) {
|
|
1975
|
+
const res = await (opts.fetch ?? globalThis.fetch)(`${baseUrl.replace(/\/$/, "")}/v1/share-sessions`, {
|
|
1976
|
+
method: "POST",
|
|
1977
|
+
headers: { "content-type": "application/json" },
|
|
1978
|
+
body: JSON.stringify({
|
|
1979
|
+
shareToken,
|
|
1980
|
+
...opts.password !== void 0 ? { password: opts.password } : {}
|
|
1981
|
+
})
|
|
1982
|
+
});
|
|
1983
|
+
if (!res.ok) {
|
|
1984
|
+
let code = "Unknown";
|
|
1985
|
+
let message = `share exchange failed with status ${res.status}`;
|
|
1986
|
+
try {
|
|
1987
|
+
const payload = await res.json();
|
|
1988
|
+
if (payload.error?.code) code = payload.error.code;
|
|
1989
|
+
if (payload.error?.message) message = payload.error.message;
|
|
1990
|
+
} catch {}
|
|
1991
|
+
throw new ShareExchangeError(code, message, res.status);
|
|
1992
|
+
}
|
|
1993
|
+
return await res.json();
|
|
1994
|
+
}
|
|
1995
|
+
/**
|
|
1996
|
+
* Lift a {@link ShareExchangeError} into the engine's error taxonomy, so
|
|
1997
|
+
* `open({ kind: 'share' })` and every later renewal fail with the same
|
|
1998
|
+
* `EngineError` family as all other engine calls. The wire code and HTTP
|
|
1999
|
+
* status survive in `details`; the original error rides as `cause`.
|
|
2000
|
+
*
|
|
2001
|
+
* `SharePasswordRequired` gets its own engine code — it is the one outcome
|
|
2002
|
+
* callers branch on programmatically (prompt for the grant passphrase and
|
|
2003
|
+
* retry). Everything else maps by meaning, with the HTTP status as the
|
|
2004
|
+
* fallback discriminator.
|
|
2005
|
+
*/
|
|
2006
|
+
function engineErrorFromShareExchange(error) {
|
|
2007
|
+
return new EngineError$1(error.code === "SharePasswordRequired" ? EngineErrorCode$1.SharePasswordRequired : error.code === "NotFound" ? EngineErrorCode$1.NotFound : error.code === "ShareExpired" || error.code === "OriginNotAllowed" || error.code === "OriginRequired" ? EngineErrorCode$1.Forbidden : error.status === 401 ? EngineErrorCode$1.Unauthenticated : error.status === 400 ? EngineErrorCode$1.InvalidArg : EngineErrorCode$1.Unknown, `share exchange failed: ${error.message}`, {
|
|
2008
|
+
details: {
|
|
2009
|
+
shareCode: error.code,
|
|
2010
|
+
status: error.status
|
|
2011
|
+
},
|
|
2012
|
+
cause: error
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
/** Renew this many seconds before `expiresAt` so in-flight requests never race expiry. */
|
|
2016
|
+
const RENEW_MARGIN_SECONDS = 60;
|
|
2017
|
+
/**
|
|
2018
|
+
* A caching, self-renewing token source over the exchange — the callable
|
|
2019
|
+
* member of the engine's `TokenSource` union, assignable wherever one is
|
|
2020
|
+
* taken.
|
|
2021
|
+
* Concurrent callers share one in-flight exchange; a failed exchange
|
|
2022
|
+
* clears it so the next request retries rather than caching the error.
|
|
2023
|
+
*/
|
|
2024
|
+
function shareSessionSource(baseUrl, shareToken, opts = {}) {
|
|
2025
|
+
let session = null;
|
|
2026
|
+
let inflight = null;
|
|
2027
|
+
return async () => {
|
|
2028
|
+
if (session && session.expiresAt - Date.now() / 1e3 > RENEW_MARGIN_SECONDS) return session.token;
|
|
2029
|
+
inflight ?? (inflight = exchangeShareToken(baseUrl, shareToken, opts).then((next) => {
|
|
2030
|
+
session = next;
|
|
2031
|
+
return next.token;
|
|
2032
|
+
}).finally(() => {
|
|
2033
|
+
inflight = null;
|
|
2034
|
+
}));
|
|
2035
|
+
return inflight;
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
//#endregion
|
|
1958
2039
|
//#region src/transport/HttpClient.ts
|
|
1959
2040
|
var HttpClient = class HttpClient {
|
|
1960
2041
|
constructor(opts) {
|
|
1961
|
-
_defineProperty(this, "
|
|
2042
|
+
_defineProperty(this, "base", void 0);
|
|
1962
2043
|
_defineProperty(this, "tokenFn", void 0);
|
|
1963
2044
|
_defineProperty(this, "fetchFn", void 0);
|
|
1964
2045
|
_defineProperty(this, "sessionId", void 0);
|
|
1965
2046
|
_defineProperty(this, "cdnBinding", null);
|
|
1966
|
-
this.
|
|
2047
|
+
this.base = opts.baseUrl.replace(/\/$/, "");
|
|
1967
2048
|
const token = opts.token;
|
|
1968
2049
|
this.tokenFn = token === void 0 ? null : typeof token === "function" ? token : () => token;
|
|
1969
2050
|
this.sessionId = opts.sessionId ?? null;
|
|
1970
2051
|
this.fetchFn = opts.fetch ?? globalThis.fetch.bind(globalThis);
|
|
1971
2052
|
}
|
|
2053
|
+
/** Normalized server base URL (no trailing slash). */
|
|
2054
|
+
get baseUrl() {
|
|
2055
|
+
return this.base;
|
|
2056
|
+
}
|
|
2057
|
+
/**
|
|
2058
|
+
* The fetch implementation this client sends requests through (injected
|
|
2059
|
+
* or global). Exposed so sibling transports spawned per-open — the
|
|
2060
|
+
* share-session exchange, most of all — ride the same fetch the engine
|
|
2061
|
+
* was configured with (test doubles, SSR `Origin`-attaching wrappers).
|
|
2062
|
+
*/
|
|
2063
|
+
get fetchImpl() {
|
|
2064
|
+
return this.fetchFn;
|
|
2065
|
+
}
|
|
1972
2066
|
/**
|
|
1973
2067
|
* Return a clone of this client bound to a different bearer. Used
|
|
1974
2068
|
* by `CloudEngine.open` to mint a per-handle client carrying the
|
|
@@ -2340,6 +2434,24 @@ var CloudEngine = class CloudEngine {
|
|
|
2340
2434
|
options?.scope;
|
|
2341
2435
|
options?.identity;
|
|
2342
2436
|
const effectivePassword = options && "password" in options ? options.password ?? null : input.password ?? null;
|
|
2437
|
+
if (input.kind === "share") {
|
|
2438
|
+
const raw = shareSessionSource(this.http.baseUrl, input.shareToken, {
|
|
2439
|
+
...input.sharePassword !== void 0 ? { password: input.sharePassword } : {},
|
|
2440
|
+
fetch: this.http.fetchImpl
|
|
2441
|
+
});
|
|
2442
|
+
const token = async () => {
|
|
2443
|
+
try {
|
|
2444
|
+
return await raw();
|
|
2445
|
+
} catch (error) {
|
|
2446
|
+
throw error instanceof ShareExchangeError ? engineErrorFromShareExchange(error) : error;
|
|
2447
|
+
}
|
|
2448
|
+
};
|
|
2449
|
+
return this.open({
|
|
2450
|
+
kind: "token",
|
|
2451
|
+
token,
|
|
2452
|
+
password: input.password ?? null
|
|
2453
|
+
}, options);
|
|
2454
|
+
}
|
|
2343
2455
|
if (input.kind === "token") {
|
|
2344
2456
|
const tokenSource = input.token;
|
|
2345
2457
|
return AbortablePromise$1.run(async (signal) => {
|
|
@@ -2376,7 +2488,7 @@ var CloudEngine = class CloudEngine {
|
|
|
2376
2488
|
return handle;
|
|
2377
2489
|
});
|
|
2378
2490
|
}
|
|
2379
|
-
return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.InvalidArg, `cloud engine supports OpenInput.kind === 'token' or '
|
|
2491
|
+
return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.InvalidArg, `cloud engine supports OpenInput.kind === 'token', 'id', or 'share' (got '${input.kind}')`));
|
|
2380
2492
|
}
|
|
2381
2493
|
destroy() {
|
|
2382
2494
|
if (this.destroyed) return AbortablePromise$1.resolveValue(void 0);
|
|
@@ -2443,65 +2555,6 @@ async function settleLinked(pending, signal) {
|
|
|
2443
2555
|
}
|
|
2444
2556
|
}
|
|
2445
2557
|
//#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
|
|
2505
2558
|
//#region src/index.ts
|
|
2506
2559
|
function createCloudEngine(opts) {
|
|
2507
2560
|
return CloudEngine.fromOptions(opts);
|
|
@@ -2530,6 +2583,6 @@ function cloudEngine(opts) {
|
|
|
2530
2583
|
return CloudEngine.fromOptions(opts);
|
|
2531
2584
|
}
|
|
2532
2585
|
//#endregion
|
|
2533
|
-
export { AbortError, AbortablePromise, CloudDocumentAnnotationsService, CloudDocumentHandle, CloudDocumentPagesService, CloudEngine, CloudMetadataService, CloudPageAnnotationsService, CloudPageGeometryService, CloudPageHandle, CloudPageRenderService, EngineError, EngineErrorCode, HttpClient, ShareExchangeError, cloudEngine, createCloudEngine, decodeUnverifiedClaims, exchangeShareToken, shareSessionSource };
|
|
2586
|
+
export { AbortError, AbortablePromise, CloudDocumentAnnotationsService, CloudDocumentHandle, CloudDocumentPagesService, CloudEngine, CloudMetadataService, CloudPageAnnotationsService, CloudPageGeometryService, CloudPageHandle, CloudPageRenderService, EngineError, EngineErrorCode, HttpClient, ShareExchangeError, cloudEngine, createCloudEngine, decodeUnverifiedClaims, engineErrorFromShareExchange, exchangeShareToken, shareSessionSource };
|
|
2534
2587
|
|
|
2535
2588
|
//# sourceMappingURL=index.js.map
|