@settlemint/dalp-sdk 3.1.4-main.32581911907 → 3.1.4-main.32583419224
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/auth.js +1 -1
- package/dist/bundler.js +1 -1
- package/dist/{chunk-d8fp1mkr.js → chunk-cy9b59s6.js} +125 -3
- package/dist/{chunk-vsahxaj9.js → chunk-w22a1b41.js} +1 -1
- package/dist/client/request-compression.d.ts +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/auth.js
CHANGED
package/dist/bundler.js
CHANGED
|
@@ -195,6 +195,127 @@ function serializeDalpQuery(query) {
|
|
|
195
195
|
return search.toString();
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
// src/client/request-compression.ts
|
|
199
|
+
var DALP_SDK_REQUEST_COMPRESSION_MIN_BODY_BYTES = 1024;
|
|
200
|
+
var DALP_SDK_REQUEST_COMPRESSION_MAX_BODY_BYTES = 16777216;
|
|
201
|
+
var NO_BODY_METHODS = new Set(["GET", "HEAD"]);
|
|
202
|
+
function bufferedBodySize(body) {
|
|
203
|
+
if (typeof body === "string") {
|
|
204
|
+
return Buffer.byteLength(body);
|
|
205
|
+
}
|
|
206
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {
|
|
207
|
+
return body.byteLength;
|
|
208
|
+
}
|
|
209
|
+
if (body instanceof Blob) {
|
|
210
|
+
return body.size;
|
|
211
|
+
}
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
function isCompressibleMediaType(contentType) {
|
|
215
|
+
const mediaType = contentType?.split(";")[0]?.trim().toLowerCase();
|
|
216
|
+
if (mediaType === undefined || mediaType === "") {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
return mediaType === "application/json" || mediaType.endsWith("+json") || mediaType.startsWith("text/");
|
|
220
|
+
}
|
|
221
|
+
async function cancelReaderBestEffort(reader) {
|
|
222
|
+
try {
|
|
223
|
+
await reader.cancel();
|
|
224
|
+
} catch {}
|
|
225
|
+
}
|
|
226
|
+
async function readRequestBodyWithinCap(request, maxBodyBytes) {
|
|
227
|
+
let body;
|
|
228
|
+
try {
|
|
229
|
+
const { body: clonedBody } = request.clone();
|
|
230
|
+
body = clonedBody;
|
|
231
|
+
} catch {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (body === null) {
|
|
235
|
+
return Buffer.alloc(0);
|
|
236
|
+
}
|
|
237
|
+
const reader = body.getReader();
|
|
238
|
+
const chunks = [];
|
|
239
|
+
let totalBytes = 0;
|
|
240
|
+
try {
|
|
241
|
+
while (true) {
|
|
242
|
+
const next = await reader.read();
|
|
243
|
+
if (next.done) {
|
|
244
|
+
return Buffer.concat(chunks, totalBytes);
|
|
245
|
+
}
|
|
246
|
+
totalBytes += next.value.byteLength;
|
|
247
|
+
if (totalBytes > maxBodyBytes) {
|
|
248
|
+
cancelReaderBestEffort(reader);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
chunks.push(next.value);
|
|
252
|
+
}
|
|
253
|
+
} catch {
|
|
254
|
+
return;
|
|
255
|
+
} finally {
|
|
256
|
+
reader.releaseLock();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function withRequestBodyCompression(fetchImpl, options) {
|
|
260
|
+
const minBodyBytes = options?.minBodyBytes ?? DALP_SDK_REQUEST_COMPRESSION_MIN_BODY_BYTES;
|
|
261
|
+
const maxBodyBytes = options?.maxBodyBytes ?? DALP_SDK_REQUEST_COMPRESSION_MAX_BODY_BYTES;
|
|
262
|
+
const requestCompressionFetch = async (input, init) => {
|
|
263
|
+
if (init?.compress !== undefined) {
|
|
264
|
+
return fetchImpl(input, init);
|
|
265
|
+
}
|
|
266
|
+
let request;
|
|
267
|
+
if (input instanceof Request) {
|
|
268
|
+
request = init === undefined ? input : new Request(input, init);
|
|
269
|
+
}
|
|
270
|
+
const method = (request?.method ?? init?.method ?? "GET").toUpperCase();
|
|
271
|
+
if (NO_BODY_METHODS.has(method)) {
|
|
272
|
+
return fetchImpl(input, init);
|
|
273
|
+
}
|
|
274
|
+
const headers = new Headers(request?.headers ?? init?.headers);
|
|
275
|
+
if (headers.get("content-encoding") !== null) {
|
|
276
|
+
return fetchImpl(input, init);
|
|
277
|
+
}
|
|
278
|
+
let compress;
|
|
279
|
+
let bufferedRequestBody;
|
|
280
|
+
if (request !== undefined && request.body !== null && isCompressibleMediaType(headers.get("content-type"))) {
|
|
281
|
+
bufferedRequestBody = await readRequestBodyWithinCap(request, maxBodyBytes);
|
|
282
|
+
if (bufferedRequestBody !== undefined && bufferedRequestBody.byteLength >= minBodyBytes) {
|
|
283
|
+
compress = "gzip";
|
|
284
|
+
}
|
|
285
|
+
} else if (init?.body !== null && init?.body !== undefined) {
|
|
286
|
+
const size = bufferedBodySize(init.body);
|
|
287
|
+
if (size !== undefined && size >= minBodyBytes && size <= maxBodyBytes) {
|
|
288
|
+
compress = "gzip";
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (compress === undefined) {
|
|
292
|
+
return fetchImpl(input, init);
|
|
293
|
+
}
|
|
294
|
+
if (request !== undefined && bufferedRequestBody !== undefined) {
|
|
295
|
+
return fetchImpl(request.url, {
|
|
296
|
+
...init,
|
|
297
|
+
body: bufferedRequestBody,
|
|
298
|
+
cache: init?.cache ?? request.cache,
|
|
299
|
+
compress,
|
|
300
|
+
credentials: init?.credentials ?? request.credentials,
|
|
301
|
+
headers: request.headers,
|
|
302
|
+
integrity: init?.integrity ?? request.integrity,
|
|
303
|
+
keepalive: init?.keepalive ?? request.keepalive,
|
|
304
|
+
method: request.method,
|
|
305
|
+
mode: init?.mode ?? request.mode,
|
|
306
|
+
redirect: init?.redirect ?? request.redirect,
|
|
307
|
+
referrer: init?.referrer ?? request.referrer,
|
|
308
|
+
referrerPolicy: init?.referrerPolicy ?? request.referrerPolicy,
|
|
309
|
+
signal: init?.signal ?? request.signal
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
return fetchImpl(input, { ...init, compress });
|
|
313
|
+
};
|
|
314
|
+
return Object.assign(requestCompressionFetch, {
|
|
315
|
+
preconnect: fetchImpl.preconnect
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
198
319
|
// src/client/ssr-fetch.ts
|
|
199
320
|
class DalpSsrSecurityError extends Error {
|
|
200
321
|
name = "DalpSsrSecurityError";
|
|
@@ -331,8 +452,9 @@ function createDalpContextHeaders(context) {
|
|
|
331
452
|
}
|
|
332
453
|
function createDalpClient(options) {
|
|
333
454
|
const baseUrl = normalizeDalpBaseUrl(String(options.baseUrl));
|
|
334
|
-
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
335
455
|
const runtime = options.runtime ?? (globalThis.window === undefined ? "server" : "browser");
|
|
456
|
+
const baseFetch = options.fetch ?? globalThis.fetch;
|
|
457
|
+
const transportFetch = runtime === "browser" ? baseFetch : withRequestBodyCompression(baseFetch);
|
|
336
458
|
const { apiKey: apiKeyOption } = options;
|
|
337
459
|
let apiKey;
|
|
338
460
|
if (apiKeyOption === undefined) {
|
|
@@ -349,10 +471,10 @@ function createDalpClient(options) {
|
|
|
349
471
|
fix: "Keep the API key on the server or CLI process; browser clients authenticate with the session cookie."
|
|
350
472
|
});
|
|
351
473
|
}
|
|
352
|
-
const resolvedFetch = options.ssr === undefined ?
|
|
474
|
+
const resolvedFetch = options.ssr === undefined ? transportFetch : createSsrFetch({
|
|
353
475
|
allowedOrigins: options.ssr.allowedOrigins,
|
|
354
476
|
baseUrl,
|
|
355
|
-
fetch:
|
|
477
|
+
fetch: transportFetch,
|
|
356
478
|
requestHeaders: options.ssr.requestHeaders
|
|
357
479
|
});
|
|
358
480
|
const client = createClient({
|
|
@@ -102,7 +102,7 @@ function createCookieStoreFetch(cookieStore, fetchImpl = globalThis.fetch) {
|
|
|
102
102
|
// package.json
|
|
103
103
|
var package_default = {
|
|
104
104
|
name: "@settlemint/dalp-sdk",
|
|
105
|
-
version: "3.1.4-main.
|
|
105
|
+
version: "3.1.4-main.32583419224",
|
|
106
106
|
private: false,
|
|
107
107
|
description: "Fully typed SDK for the DALP tokenization platform API",
|
|
108
108
|
homepage: "https://settlemint.com",
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { DalpFetch } from "./ssr-fetch.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Request-body compression for DALP server/CLI clients.
|
|
4
|
+
*
|
|
5
|
+
* Bun 1.4 added a `compress` fetch option: it compresses a buffered body
|
|
6
|
+
* before sending and sets `Content-Encoding` on the wire. This wrapper opts
|
|
7
|
+
* eligible outgoing bodies into gzip so big JSON payloads shrink in transit;
|
|
8
|
+
* the receiving DAPI host decodes them at its boundary
|
|
9
|
+
* (`@dapi/server/request-body-decoding`), so callers need no per-route work.
|
|
10
|
+
*
|
|
11
|
+
* Eligibility mirrors what the transport can actually do:
|
|
12
|
+
*
|
|
13
|
+
* - Only body-bearing methods (`GET`/`HEAD` never).
|
|
14
|
+
* - Bodies already carrying `Content-Encoding`, or an explicit caller
|
|
15
|
+
* `compress`, pass through untouched.
|
|
16
|
+
* - With `(url, init)` the body must be one of Bun's buffered types
|
|
17
|
+
* (string, ArrayBuffer, TypedArray/DataView, Blob) and fall inside the
|
|
18
|
+
* size window — gzip framing dominates tiny payloads, and huge explicitly
|
|
19
|
+
* sized bodies stay uncompressed (the DAPI decode cap mirrors this bound).
|
|
20
|
+
* - Streams, `FormData`, and `URLSearchParams` pass through: the transport
|
|
21
|
+
* forwards streaming bodies unchanged.
|
|
22
|
+
* - A `Request` instance is measured through a bounded clone before compression.
|
|
23
|
+
*/
|
|
24
|
+
/** Bodies smaller than this stay uncompressed; gzip framing dominates tiny JSON. */
|
|
25
|
+
export declare const DALP_SDK_REQUEST_COMPRESSION_MIN_BODY_BYTES = 1024;
|
|
26
|
+
/** Explicitly-sized bodies larger than this are sent uncompressed. */
|
|
27
|
+
export declare const DALP_SDK_REQUEST_COMPRESSION_MAX_BODY_BYTES = 16777216;
|
|
28
|
+
/**
|
|
29
|
+
* Bun's `compress` fetch option. bun-types 1.4.0 still types `RequestInit`
|
|
30
|
+
* from lib.dom without it, so the field is declared here and set through one
|
|
31
|
+
* narrow cast at the transport seam.
|
|
32
|
+
*/
|
|
33
|
+
export type FetchRequestCompression = true | "gzip" | "deflate" | "br" | "zstd";
|
|
34
|
+
export interface CompressionRequestInit extends RequestInit {
|
|
35
|
+
readonly compress?: FetchRequestCompression;
|
|
36
|
+
}
|
|
37
|
+
export interface RequestBodyCompressionOptions {
|
|
38
|
+
/** Test seam overriding DALP_SDK_REQUEST_COMPRESSION_MIN_BODY_BYTES. */
|
|
39
|
+
readonly minBodyBytes?: number;
|
|
40
|
+
/** Test seam overriding DALP_SDK_REQUEST_COMPRESSION_MAX_BODY_BYTES. */
|
|
41
|
+
readonly maxBodyBytes?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Wrap a fetch seam so eligible request bodies travel gzip-compressed.
|
|
45
|
+
* Ineligible calls forward the original arguments untouched.
|
|
46
|
+
*/
|
|
47
|
+
export declare function withRequestBodyCompression(fetchImpl: DalpFetch, options?: RequestBodyCompressionOptions): DalpFetch;
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
15
|
export { createDalpClient, createDalpContextHeaders } from "./client/factory.ts";
|
|
16
|
+
export type { CompressionRequestInit } from "./client/request-compression.ts";
|
|
16
17
|
export type { CreateDalpClientOptions, DalpClientContext, DalpSsrOptions } from "./client/factory.ts";
|
|
17
18
|
export { clearConditionalRequestStore } from "./client/conditional-request.ts";
|
|
18
19
|
export { createCookieStoreFetch, makeCookieStore } from "./transport/cookie-store.ts";
|
package/dist/index.js
CHANGED
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
SDK_VERSION,
|
|
4
4
|
createCookieStoreFetch,
|
|
5
5
|
makeCookieStore
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-w22a1b41.js";
|
|
7
7
|
import {
|
|
8
8
|
clearConditionalRequestStore,
|
|
9
9
|
createDalpClient,
|
|
10
10
|
createDalpContextHeaders
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-cy9b59s6.js";
|
|
12
12
|
import"./chunk-w21k7p99.js";
|
|
13
13
|
import {
|
|
14
14
|
SECRET_REDACTION_MARKER,
|
package/package.json
CHANGED