@settlemint/dalp-sdk 2.1.7-main.25919151678 → 2.1.7-main.25919242147

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.js CHANGED
@@ -1,6 +1,3 @@
1
- import {
2
- fetchWithAttemptHeader
3
- } from "./chunk-213v5nej.js";
4
1
  import {
5
2
  __commonJS,
6
3
  __toESM
@@ -770,6 +767,56 @@ import { createORPCClient } from "@orpc/client";
770
767
  import { RequestValidationPlugin, ResponseValidationPlugin } from "@orpc/contract/plugins";
771
768
  import { OpenAPILink } from "@orpc/openapi-client/fetch";
772
769
 
770
+ // ../../packages/dalp/api-contract/src/helpers/attempt-header.ts
771
+ var ATTEMPT_TTL_MS = 60000;
772
+ var attemptByKey = new Map;
773
+ function buildAttemptKey(url, method, bodyKey) {
774
+ return `${method} ${url}|${bodyKey}`;
775
+ }
776
+ function bodyInitKey(body) {
777
+ return typeof body === "string" ? body.slice(0, 256) : "";
778
+ }
779
+ async function requestBodyKey(request) {
780
+ if (request.body === null) {
781
+ return "";
782
+ }
783
+ const body = await request.clone().text();
784
+ return body.slice(0, 256);
785
+ }
786
+ function nextAttempt(key, now = Date.now()) {
787
+ for (const [k, v] of attemptByKey) {
788
+ if (v.expiresAt < now) {
789
+ attemptByKey.delete(k);
790
+ }
791
+ }
792
+ const existing = attemptByKey.get(key);
793
+ const attempt = (existing?.attempt ?? 0) + 1;
794
+ attemptByKey.set(key, { attempt, expiresAt: now + ATTEMPT_TTL_MS });
795
+ return attempt;
796
+ }
797
+ function clearAttempt(key) {
798
+ attemptByKey.delete(key);
799
+ }
800
+ function appendAttempt(source, attempt) {
801
+ const headers = new Headers(source);
802
+ headers.set("X-Dalp-Attempt", String(attempt));
803
+ return headers;
804
+ }
805
+ async function fetchWithAttemptHeader(request, init, innerFetch) {
806
+ const url = request instanceof Request ? request.url : String(request);
807
+ const method = (request instanceof Request ? request.method : init?.method) ?? "GET";
808
+ const bodyKey = request instanceof Request ? await requestBodyKey(request) : bodyInitKey(init?.body ?? null);
809
+ const key = buildAttemptKey(url, method, bodyKey);
810
+ const attempt = nextAttempt(key);
811
+ const augmentedRequest = request instanceof Request ? new Request(request, { headers: appendAttempt(request.headers, attempt) }) : request;
812
+ const augmentedInit = request instanceof Request ? init : { ...init, headers: appendAttempt(init?.headers, attempt) };
813
+ const response = await innerFetch(augmentedRequest, augmentedInit);
814
+ if (response.ok) {
815
+ clearAttempt(key);
816
+ }
817
+ return response;
818
+ }
819
+
773
820
  // ../../packages/core/validation/src/role-requirement.ts
774
821
  import { z } from "zod";
775
822
  var RoleRequirementSchema = z.lazy(() => z.union([
@@ -31080,7 +31127,7 @@ function normalizeDalpBaseUrl(url) {
31080
31127
  // package.json
31081
31128
  var package_default = {
31082
31129
  name: "@settlemint/dalp-sdk",
31083
- version: "2.1.7-main.25919151678",
31130
+ version: "2.1.7-main.25919242147",
31084
31131
  private: false,
31085
31132
  description: "Fully typed SDK for the DALP tokenization platform API",
31086
31133
  homepage: "https://settlemint.com",
@@ -31095,7 +31142,6 @@ var package_default = {
31095
31142
  },
31096
31143
  files: [
31097
31144
  "dist",
31098
- "src/attempt-header.ts",
31099
31145
  "README.md",
31100
31146
  "LICENSE"
31101
31147
  ],
@@ -31107,12 +31153,6 @@ var package_default = {
31107
31153
  import: "./dist/index.js",
31108
31154
  default: "./dist/index.js"
31109
31155
  },
31110
- "./attempt-header": {
31111
- types: "./src/attempt-header.ts",
31112
- bun: "./src/attempt-header.ts",
31113
- import: "./dist/attempt-header.js",
31114
- default: "./dist/attempt-header.js"
31115
- },
31116
31156
  "./types": {
31117
31157
  types: "./dist/types.d.ts",
31118
31158
  import: "./dist/types.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@settlemint/dalp-sdk",
3
- "version": "2.1.7-main.25919151678",
3
+ "version": "2.1.7-main.25919242147",
4
4
  "private": false,
5
5
  "description": "Fully typed SDK for the DALP tokenization platform API",
6
6
  "homepage": "https://settlemint.com",
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "files": [
17
17
  "dist",
18
- "src/attempt-header.ts",
19
18
  "README.md",
20
19
  "LICENSE"
21
20
  ],
@@ -27,12 +26,6 @@
27
26
  "import": "./dist/index.js",
28
27
  "default": "./dist/index.js"
29
28
  },
30
- "./attempt-header": {
31
- "types": "./src/attempt-header.ts",
32
- "bun": "./src/attempt-header.ts",
33
- "import": "./dist/attempt-header.js",
34
- "default": "./dist/attempt-header.js"
35
- },
36
29
  "./types": {
37
30
  "types": "./dist/types.d.ts",
38
31
  "import": "./dist/types.js",
@@ -1,4 +0,0 @@
1
- export declare function fetchWithAttemptHeader(request: RequestInfo | URL, init: RequestInit | undefined, innerFetch: (req: RequestInfo | URL, init?: RequestInit) => Promise<Response>): Promise<Response>;
2
- /** Test-only: reset the in-memory attempt tracker between cases. */
3
- export declare function __resetAttemptTrackerForTests(): void;
4
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXR0ZW1wdC1oZWFkZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9hdHRlbXB0LWhlYWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFxREEsd0JBQXNCLHNCQUFzQixDQUMxQyxPQUFPLEVBQUUsV0FBVyxHQUFHLEdBQUcsRUFDMUIsSUFBSSxFQUFFLFdBQVcsR0FBRyxTQUFTLEVBQzdCLFVBQVUsRUFBRSxDQUFDLEdBQUcsRUFBRSxXQUFXLEdBQUcsR0FBRyxFQUFFLElBQUksQ0FBQyxFQUFFLFdBQVcsS0FBSyxPQUFPLENBQUMsUUFBUSxDQUFDLEdBQzVFLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0FtQm5CO0FBRUQsb0VBQW9FO0FBQ3BFLHdCQUFnQiw2QkFBNkIsSUFBSSxJQUFJLENBRXBEIn0=
@@ -1 +0,0 @@
1
- {"version":3,"file":"attempt-header.d.ts","sourceRoot":"","sources":["../src/attempt-header.ts"],"names":[],"mappings":"AAqDA,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,WAAW,GAAG,GAAG,EAC1B,IAAI,EAAE,WAAW,GAAG,SAAS,EAC7B,UAAU,EAAE,CAAC,GAAG,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,GAC5E,OAAO,CAAC,QAAQ,CAAC,CAmBnB;AAED,oEAAoE;AACpE,wBAAgB,6BAA6B,IAAI,IAAI,CAEpD"}
@@ -1,9 +0,0 @@
1
- import {
2
- __resetAttemptTrackerForTests,
3
- fetchWithAttemptHeader
4
- } from "./chunk-213v5nej.js";
5
- import"./chunk-xm8h1dzh.js";
6
- export {
7
- fetchWithAttemptHeader,
8
- __resetAttemptTrackerForTests
9
- };
@@ -1,54 +0,0 @@
1
- // src/attempt-header.ts
2
- var ATTEMPT_TTL_MS = 60000;
3
- var attemptByKey = new Map;
4
- function buildAttemptKey(url, method, bodyKey) {
5
- return `${method} ${url}|${bodyKey}`;
6
- }
7
- function bodyInitKey(body) {
8
- return typeof body === "string" ? body.slice(0, 256) : "";
9
- }
10
- async function requestBodyKey(request) {
11
- if (request.body === null) {
12
- return "";
13
- }
14
- const body = await request.clone().text();
15
- return body.slice(0, 256);
16
- }
17
- function nextAttempt(key, now = Date.now()) {
18
- for (const [k, v] of attemptByKey) {
19
- if (v.expiresAt < now) {
20
- attemptByKey.delete(k);
21
- }
22
- }
23
- const existing = attemptByKey.get(key);
24
- const attempt = (existing?.attempt ?? 0) + 1;
25
- attemptByKey.set(key, { attempt, expiresAt: now + ATTEMPT_TTL_MS });
26
- return attempt;
27
- }
28
- function clearAttempt(key) {
29
- attemptByKey.delete(key);
30
- }
31
- function appendAttempt(source, attempt) {
32
- const headers = new Headers(source);
33
- headers.set("X-Dalp-Attempt", String(attempt));
34
- return headers;
35
- }
36
- async function fetchWithAttemptHeader(request, init, innerFetch) {
37
- const url = request instanceof Request ? request.url : String(request);
38
- const method = (request instanceof Request ? request.method : init?.method) ?? "GET";
39
- const bodyKey = request instanceof Request ? await requestBodyKey(request) : bodyInitKey(init?.body ?? null);
40
- const key = buildAttemptKey(url, method, bodyKey);
41
- const attempt = nextAttempt(key);
42
- const augmentedRequest = request instanceof Request ? new Request(request, { headers: appendAttempt(request.headers, attempt) }) : request;
43
- const augmentedInit = request instanceof Request ? init : { ...init, headers: appendAttempt(init?.headers, attempt) };
44
- const response = await innerFetch(augmentedRequest, augmentedInit);
45
- if (response.ok) {
46
- clearAttempt(key);
47
- }
48
- return response;
49
- }
50
- function __resetAttemptTrackerForTests() {
51
- attemptByKey.clear();
52
- }
53
-
54
- export { fetchWithAttemptHeader, __resetAttemptTrackerForTests };
@@ -1,82 +0,0 @@
1
- /**
2
- * X-Dalp-Attempt header injection for the SDK fetch wrapper.
3
- *
4
- * The SDK does not retry by itself — retries come from the caller (TanStack
5
- * Query in dapp, manual retry loops in scripts). The link can't see the
6
- * caller's retry counter, so we content-key the request (URL + method +
7
- * truncated body) and increment a local counter. Matching keys within
8
- * `ATTEMPT_TTL_MS` surface as `attempt > 1`. Strictly best-effort: this
9
- * powers the dapi `is_retry` observability label, not any correctness path.
10
- * @module
11
- */
12
- const ATTEMPT_TTL_MS = 60_000;
13
- const attemptByKey = new Map<string, { attempt: number; expiresAt: number }>();
14
-
15
- function buildAttemptKey(url: string, method: string, bodyKey: string): string {
16
- return `${method} ${url}|${bodyKey}`;
17
- }
18
-
19
- function bodyInitKey(body: BodyInit | null | undefined): string {
20
- return typeof body === "string" ? body.slice(0, 256) : "";
21
- }
22
-
23
- async function requestBodyKey(request: Request): Promise<string> {
24
- if (request.body === null) {
25
- return "";
26
- }
27
-
28
- const body = await request.clone().text();
29
- return body.slice(0, 256);
30
- }
31
-
32
- function nextAttempt(key: string, now = Date.now()): number {
33
- for (const [k, v] of attemptByKey) {
34
- if (v.expiresAt < now) {
35
- attemptByKey.delete(k);
36
- }
37
- }
38
- const existing = attemptByKey.get(key);
39
- const attempt = (existing?.attempt ?? 0) + 1;
40
- attemptByKey.set(key, { attempt, expiresAt: now + ATTEMPT_TTL_MS });
41
- return attempt;
42
- }
43
-
44
- function clearAttempt(key: string): void {
45
- attemptByKey.delete(key);
46
- }
47
-
48
- function appendAttempt(source: HeadersInit | undefined, attempt: number): Headers {
49
- const headers = new Headers(source);
50
- headers.set("X-Dalp-Attempt", String(attempt));
51
- return headers;
52
- }
53
-
54
- export async function fetchWithAttemptHeader(
55
- request: RequestInfo | URL,
56
- init: RequestInit | undefined,
57
- innerFetch: (req: RequestInfo | URL, init?: RequestInit) => Promise<Response>
58
- ): Promise<Response> {
59
- const url = request instanceof Request ? request.url : String(request);
60
- const method = (request instanceof Request ? request.method : init?.method) ?? "GET";
61
- const bodyKey = request instanceof Request ? await requestBodyKey(request) : bodyInitKey(init?.body ?? null);
62
- const key = buildAttemptKey(url, method, bodyKey);
63
- const attempt = nextAttempt(key);
64
-
65
- // When the link hands us a Request, the downstream fetch reads headers off
66
- // the Request itself and discards init.headers — clone with the attempt
67
- // header injected so it actually leaves the wire.
68
- const augmentedRequest =
69
- request instanceof Request ? new Request(request, { headers: appendAttempt(request.headers, attempt) }) : request;
70
- const augmentedInit = request instanceof Request ? init : { ...init, headers: appendAttempt(init?.headers, attempt) };
71
-
72
- const response = await innerFetch(augmentedRequest, augmentedInit);
73
- if (response.ok) {
74
- clearAttempt(key);
75
- }
76
- return response;
77
- }
78
-
79
- /** Test-only: reset the in-memory attempt tracker between cases. */
80
- export function __resetAttemptTrackerForTests(): void {
81
- attemptByKey.clear();
82
- }