@voyantjs/hono 0.76.0 → 0.77.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.
@@ -0,0 +1,30 @@
1
+ export interface DocumentDownloadEnvelope {
2
+ url: string;
3
+ expiresAt: string | null;
4
+ filename: string | null;
5
+ }
6
+ export type DocumentDownloadResolution = {
7
+ status: "ready";
8
+ download: DocumentDownloadEnvelope;
9
+ } | {
10
+ status: "resolver_not_configured";
11
+ } | {
12
+ status: "not_available";
13
+ };
14
+ export type DocumentDownloadResolverResult = string | {
15
+ url: string;
16
+ expiresAt?: string | null;
17
+ filename?: string | null;
18
+ } | null | undefined;
19
+ export type DocumentDownloadResolver<TBindings = unknown> = (bindings: TBindings, storageKey: string) => Promise<DocumentDownloadResolverResult> | DocumentDownloadResolverResult;
20
+ export interface StoredDocumentReference {
21
+ storageKey?: string | null;
22
+ metadata?: unknown;
23
+ filename?: string | null;
24
+ name?: string | null;
25
+ }
26
+ export declare function resolveStoredDocumentDownload<TBindings = unknown>(reference: StoredDocumentReference, options: {
27
+ bindings: TBindings;
28
+ resolveDocumentDownloadUrl?: DocumentDownloadResolver<TBindings>;
29
+ }): Promise<DocumentDownloadResolution>;
30
+ //# sourceMappingURL=document-download.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-download.d.ts","sourceRoot":"","sources":["../src/document-download.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED,MAAM,MAAM,0BAA0B,GAClC;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,wBAAwB,CAAA;CAAE,GACvD;IAAE,MAAM,EAAE,yBAAyB,CAAA;CAAE,GACrC;IAAE,MAAM,EAAE,eAAe,CAAA;CAAE,CAAA;AAE/B,MAAM,MAAM,8BAA8B,GACtC,MAAM,GACN;IACE,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACzB,GACD,IAAI,GACJ,SAAS,CAAA;AAEb,MAAM,MAAM,wBAAwB,CAAC,SAAS,GAAG,OAAO,IAAI,CAC1D,QAAQ,EAAE,SAAS,EACnB,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,8BAA8B,CAAC,GAAG,8BAA8B,CAAA;AAE7E,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB;AAwGD,wBAAsB,6BAA6B,CAAC,SAAS,GAAG,OAAO,EACrE,SAAS,EAAE,uBAAuB,EAClC,OAAO,EAAE;IACP,QAAQ,EAAE,SAAS,CAAA;IACnB,0BAA0B,CAAC,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAA;CACjE,GACA,OAAO,CAAC,0BAA0B,CAAC,CA2BrC"}
@@ -0,0 +1,102 @@
1
+ function getMetadataRecord(metadata) {
2
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
3
+ return null;
4
+ }
5
+ return metadata;
6
+ }
7
+ function maybeString(value) {
8
+ return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
9
+ }
10
+ function maybeUrl(value) {
11
+ const candidate = maybeString(value);
12
+ return candidate && /^https?:\/\//i.test(candidate) ? candidate : null;
13
+ }
14
+ function maybeIsoString(value) {
15
+ return maybeString(value);
16
+ }
17
+ function filenameFromStorageKey(storageKey) {
18
+ const normalized = maybeString(storageKey);
19
+ if (!normalized) {
20
+ return null;
21
+ }
22
+ return normalized.split("/").filter(Boolean).at(-1) ?? null;
23
+ }
24
+ function getReferenceFilename(reference) {
25
+ const record = getMetadataRecord(reference.metadata);
26
+ return (maybeString(reference.filename) ??
27
+ maybeString(reference.name) ??
28
+ maybeString(record?.filename) ??
29
+ maybeString(record?.fileName) ??
30
+ maybeString(record?.name) ??
31
+ maybeString(record?.originalName) ??
32
+ filenameFromStorageKey(reference.storageKey));
33
+ }
34
+ function getMetadataExpiresAt(metadata) {
35
+ const record = getMetadataRecord(metadata);
36
+ return maybeIsoString(record?.expiresAt) ?? maybeIsoString(record?.expires_at);
37
+ }
38
+ function getFallbackDownload(reference) {
39
+ const record = getMetadataRecord(reference.metadata);
40
+ if (!record) {
41
+ return null;
42
+ }
43
+ const url = maybeUrl(record.url) ?? maybeUrl(record.downloadUrl);
44
+ if (!url) {
45
+ return null;
46
+ }
47
+ return {
48
+ url,
49
+ expiresAt: getMetadataExpiresAt(record),
50
+ filename: getReferenceFilename(reference),
51
+ };
52
+ }
53
+ function normalizeResolverDownload(value, reference) {
54
+ if (typeof value === "string") {
55
+ const url = maybeUrl(value);
56
+ if (!url) {
57
+ return null;
58
+ }
59
+ return {
60
+ url,
61
+ expiresAt: getMetadataExpiresAt(reference.metadata),
62
+ filename: getReferenceFilename(reference),
63
+ };
64
+ }
65
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
66
+ return null;
67
+ }
68
+ const url = maybeUrl(value.url);
69
+ if (!url) {
70
+ return null;
71
+ }
72
+ return {
73
+ url,
74
+ expiresAt: value.expiresAt === undefined
75
+ ? getMetadataExpiresAt(reference.metadata)
76
+ : maybeIsoString(value.expiresAt),
77
+ filename: maybeString(value.filename) ?? getReferenceFilename(reference),
78
+ };
79
+ }
80
+ export async function resolveStoredDocumentDownload(reference, options) {
81
+ let needsResolver = false;
82
+ if (reference.storageKey) {
83
+ if (!options.resolveDocumentDownloadUrl) {
84
+ needsResolver = true;
85
+ }
86
+ else {
87
+ const resolved = await options.resolveDocumentDownloadUrl(options.bindings, reference.storageKey);
88
+ const download = normalizeResolverDownload(resolved, reference);
89
+ if (download) {
90
+ return { status: "ready", download };
91
+ }
92
+ }
93
+ }
94
+ const fallback = getFallbackDownload(reference);
95
+ if (fallback) {
96
+ return { status: "ready", download: fallback };
97
+ }
98
+ if (needsResolver) {
99
+ return { status: "resolver_not_configured" };
100
+ }
101
+ return { status: "not_available" };
102
+ }
package/dist/index.d.ts CHANGED
@@ -2,6 +2,8 @@ export type { VoyantPermission } from "@voyantjs/core";
2
2
  export { createApp } from "./app.js";
3
3
  export type { SessionAuthContext } from "./auth/index.js";
4
4
  export { extractBearerToken, generateNumericCode, randomBytesHex, requireUserId, sha256Base64Url, sha256Hex, unsignCookie, verifySession, } from "./auth/index.js";
5
+ export type { DocumentDownloadEnvelope, DocumentDownloadResolution, DocumentDownloadResolver, DocumentDownloadResolverResult, StoredDocumentReference, } from "./document-download.js";
6
+ export { resolveStoredDocumentDownload } from "./document-download.js";
5
7
  export { consoleLoggerProvider, cors, DEFAULT_IDEMPOTENCY_TTL_MS, db, errorBoundary, handleApiError, type IdempotencyKeyOptions, idempotencyKey, LIVE_LIMITS, logger, purgeExpiredIdempotencyKeys, rateLimit, requestId, requireActor, requireAuth, requirePermission, } from "./middleware/index.js";
6
8
  export type { HonoExtension, HonoModule } from "./module.js";
7
9
  export type { ExpandedHonoBundles, ExpandedHonoPlugins, HonoBundle, HonoPlugin, } from "./plugin.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzD,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,eAAe,EACf,SAAS,EACT,YAAY,EACZ,aAAa,GACd,MAAM,iBAAiB,CAAA;AAC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EACjB,wBAAwB,EACxB,aAAa,EACb,qBAAqB,EACrB,UAAU,EACV,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,iBAAiB,CAAA"}
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { createApp } from "./app.js";
2
2
  export { extractBearerToken, generateNumericCode, randomBytesHex, requireUserId, sha256Base64Url, sha256Hex, unsignCookie, verifySession, } from "./auth/index.js";
3
+ export { resolveStoredDocumentDownload } from "./document-download.js";
3
4
  export { consoleLoggerProvider, cors, DEFAULT_IDEMPOTENCY_TTL_MS, db, errorBoundary, handleApiError, idempotencyKey, LIVE_LIMITS, logger, purgeExpiredIdempotencyKeys, rateLimit, requestId, requireActor, requireAuth, requirePermission, } from "./middleware/index.js";
4
5
  export { defineHonoBundle, defineHonoPlugin, expandHonoBundles, expandHonoPlugins, } from "./plugin.js";
5
6
  export { createPublicCapabilityToken, extractPublicCapabilityToken, serializePublicCapabilityCookie, verifyPublicCapabilityToken, } from "./public-capability.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/hono",
3
- "version": "0.76.0",
3
+ "version": "0.77.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -24,6 +24,11 @@
24
24
  "import": "./dist/plugin.js",
25
25
  "default": "./dist/plugin.js"
26
26
  },
27
+ "./document-download": {
28
+ "types": "./dist/document-download.d.ts",
29
+ "import": "./dist/document-download.js",
30
+ "default": "./dist/document-download.js"
31
+ },
27
32
  "./types": {
28
33
  "types": "./dist/types.d.ts",
29
34
  "import": "./dist/types.js",
@@ -94,18 +99,18 @@
94
99
  "drizzle-orm": "^0.45.2",
95
100
  "hono": "^4.12.10",
96
101
  "zod": "^4.3.6",
97
- "@voyantjs/core": "0.76.0",
98
- "@voyantjs/db": "0.76.0",
99
- "@voyantjs/types": "0.76.0",
100
- "@voyantjs/utils": "0.76.0",
101
- "@voyantjs/workflows": "0.76.0"
102
+ "@voyantjs/core": "0.77.0",
103
+ "@voyantjs/db": "0.77.0",
104
+ "@voyantjs/types": "0.77.0",
105
+ "@voyantjs/utils": "0.77.0",
106
+ "@voyantjs/workflows": "0.77.0"
102
107
  },
103
108
  "devDependencies": {
104
109
  "@cloudflare/workers-types": "^4.20260426.1",
105
110
  "typescript": "^6.0.2",
106
111
  "vitest": "^4.1.2",
107
112
  "@voyantjs/voyant-typescript-config": "0.1.0",
108
- "@voyantjs/workflows-orchestrator": "0.76.0"
113
+ "@voyantjs/workflows-orchestrator": "0.77.0"
109
114
  },
110
115
  "files": [
111
116
  "dist"