@dapplelight/signet-lib 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +233 -2
- package/dist/analytics/index.d.ts +35 -0
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/index.js +104 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/api/client.d.ts +24 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +123 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/codes.d.ts +4 -0
- package/dist/api/codes.d.ts.map +1 -0
- package/dist/api/codes.js +24 -0
- package/dist/api/codes.js.map +1 -0
- package/dist/api/contract.d.ts +12 -0
- package/dist/api/contract.d.ts.map +1 -0
- package/dist/api/contract.js +7 -0
- package/dist/api/contract.js.map +1 -0
- package/dist/api/copy.d.ts +13 -0
- package/dist/api/copy.d.ts.map +1 -0
- package/dist/api/copy.js +87 -0
- package/dist/api/copy.js.map +1 -0
- package/dist/api/errors.d.ts +20 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +33 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/query-client.d.ts +19 -0
- package/dist/api/query-client.d.ts.map +1 -0
- package/dist/api/query-client.js +52 -0
- package/dist/api/query-client.js.map +1 -0
- package/dist/crypto/index.d.ts +10 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +85 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/form/index.d.ts +26 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +73 -0
- package/dist/form/index.js.map +1 -0
- package/dist/format/date.d.ts +14 -0
- package/dist/format/date.d.ts.map +1 -0
- package/dist/format/date.js +109 -0
- package/dist/format/date.js.map +1 -0
- package/dist/format/index.d.ts +10 -0
- package/dist/format/index.d.ts.map +1 -0
- package/dist/format/index.js +113 -0
- package/dist/format/index.js.map +1 -0
- package/package.json +79 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The Signet authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,234 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dapplelight/signet-lib
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Client primitives. The API layer, because six products hand-rolled one.
|
|
4
|
+
|
|
5
|
+
## What the audit found
|
|
6
|
+
|
|
7
|
+
`lib/api.ts` or `services/api.ts` existed in six families. None shared an error
|
|
8
|
+
convention, and reading them turned up two real bugs rather than mere
|
|
9
|
+
duplication:
|
|
10
|
+
|
|
11
|
+
| Product | Lines | State |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| app-j | 123 | own conventions |
|
|
14
|
+
| app-c | 88 | handled non-JSON and 204 correctly; errors untyped (`Error` with `.status` bolted on) |
|
|
15
|
+
| app-a | 59 | typed `ApiError`/`AuthError`, considered retry policy — **but custom headers silently dropped Content-Type** |
|
|
16
|
+
| app-d | 49 | **no `res.ok` check on 5 of 9 endpoints** — a 500 HTML page reached `res.json()` |
|
|
17
|
+
| dhairya11 | 23 | minimal |
|
|
18
|
+
| app-b | 2 | stub |
|
|
19
|
+
|
|
20
|
+
## The contract
|
|
21
|
+
|
|
22
|
+
Errors are enveloped, successes are not:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
{ success: false, error: string, code?: string, details?: { formErrors, fieldErrors }, requestId?: string }
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`error` is human text; branch on `code`, never on `error`. Every error the
|
|
29
|
+
server kit raises itself has one (`VALIDATION_FAILED`, `RATE_LIMITED`,
|
|
30
|
+
`INTERNAL_ERROR`, …). `requestId` is present when the server runs the
|
|
31
|
+
`requestId` middleware, and `ApiError.requestId` falls back to the
|
|
32
|
+
`X-Request-Id` header, so a user's report can be traced to the log line.
|
|
33
|
+
|
|
34
|
+
`client.send(path, init)` sends with the configured headers and credentials and
|
|
35
|
+
turns a 401 into `AuthError`, but returns every other Response untouched —
|
|
36
|
+
status, `redirected`, `url` — for a flow that follows a redirect and checks
|
|
37
|
+
where it landed. `toApiError(res)` turns a failed Response into the same
|
|
38
|
+
`ApiError` the other methods throw.
|
|
39
|
+
|
|
40
|
+
`ApiError.retryAfter` is the seconds until a retry can succeed, when the server
|
|
41
|
+
said so (a 429 from `rateLimit` does): from `Retry-After`, else `RateLimit-Reset`,
|
|
42
|
+
else `X-RateLimit-Reset`. Use it to say "try again in 30 seconds".
|
|
43
|
+
|
|
44
|
+
`ERROR_CODES` (and `type ErrorCode`) lists every code the server kit emits, so
|
|
45
|
+
an app's user-facing copy can be checked by the compiler rather than a test:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import type { ErrorCode } from "@dapplelight/signet-lib/api"
|
|
49
|
+
const copy = { ...appCopy, RATE_LIMITED: "Slow down a little." } satisfies Record<ErrorCode | AppErrorCode, string>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`DEFAULT_ERROR_COPY` gives every one of those codes plain, product-neutral copy
|
|
53
|
+
(`{ title, detail, action }`), so an app writes copy only for its own codes and
|
|
54
|
+
the few it wants to phrase differently:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { DEFAULT_ERROR_COPY, errorCopy, type ErrorCode, type ErrorCopy } from "@dapplelight/signet-lib/api"
|
|
58
|
+
|
|
59
|
+
export const COPY = {
|
|
60
|
+
...DEFAULT_ERROR_COPY,
|
|
61
|
+
RATE_LIMITED: { title: "Easy there", detail: "Search again shortly.", action: "wait" },
|
|
62
|
+
PROVIDER_UNAVAILABLE: { title: "Store unavailable", detail: "Try another store.", action: "go_back" },
|
|
63
|
+
} satisfies Record<ErrorCode | AppErrorCode, ErrorCopy>
|
|
64
|
+
|
|
65
|
+
const { title, detail, action } = errorCopy(err.code, COPY) // unknown code -> INTERNAL_ERROR's copy
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`action` is one of `retry`, `wait`, `edit`, `sign_in`, `go_back`; pair `wait`
|
|
69
|
+
with `ApiError.retryAfter`. Need a product action? `ErrorCopy` is generic:
|
|
70
|
+
`satisfies Record<ErrorCode | AppErrorCode, ErrorCopy<ErrorAction | "new_search">>`,
|
|
71
|
+
and the spread defaults still fit. A new Signet code arrives with its default; a
|
|
72
|
+
new app code fails the build until it has copy.
|
|
73
|
+
|
|
74
|
+
Codes are UPPER_SNAKE, except `invalid_token` and `insufficient_scope`, whose
|
|
75
|
+
spelling RFC 6750 fixes. The server test fails if the server emits a code the
|
|
76
|
+
list is missing.
|
|
77
|
+
|
|
78
|
+
Asymmetric on purpose — it matches what app-a already serves, so existing routes
|
|
79
|
+
adopt it without rewriting, and success payloads stay directly usable with no
|
|
80
|
+
unwrapping at the call site.
|
|
81
|
+
|
|
82
|
+
`@dapplelight/signet-server/http` writes exactly what `@dapplelight/signet-lib/api` parses.
|
|
83
|
+
|
|
84
|
+
## Use
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { createApiClient, ApiError, AuthError } from "@dapplelight/signet-lib/api"
|
|
88
|
+
|
|
89
|
+
export const api = createApiClient({
|
|
90
|
+
baseUrl: "/api",
|
|
91
|
+
onAuthError: () => { window.location.href = "/login" },
|
|
92
|
+
headers: async () => ({ Authorization: `Bearer ${await getToken()}` }),
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
await api.get<Transaction[]>("/transactions" + qs({ from, to, q: search }))
|
|
96
|
+
await api.post<Transaction>("/transactions", body)
|
|
97
|
+
await api.postForm<ImportResult>("/import", formData)
|
|
98
|
+
const pdf = await api.raw("/receipt/42/pdf")
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Validation errors arrive structured, not as a JSON string inside a message:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
catch (e) {
|
|
105
|
+
if (e instanceof ApiError && e.code === "VALIDATION_FAILED") {
|
|
106
|
+
setFieldErrors(e.details?.fieldErrors ?? {})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### TanStack Query
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { queryDefaults, onAuthErrorRedirect } from "@dapplelight/signet-lib/api/query-client"
|
|
115
|
+
|
|
116
|
+
const client = new QueryClient({ defaultOptions: queryDefaults() })
|
|
117
|
+
onAuthErrorRedirect(client, () => { window.location.href = "/login" })
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`AuthError` is never retried — retrying a 401 only delays the redirect and fires
|
|
121
|
+
more requests at a dead session. A burst of parallel 401s redirects once.
|
|
122
|
+
|
|
123
|
+
Only transient failures are retried: network errors, 5xx, 408 and 429. A 400,
|
|
124
|
+
403, 404 or 422 fails identically every time, so retrying it only delays the
|
|
125
|
+
error. A 429 waits the server's `Retry-After`. Pass `shouldRetry` to change
|
|
126
|
+
the filter, `maxRetries` to change the count.
|
|
127
|
+
|
|
128
|
+
## Fixed here
|
|
129
|
+
|
|
130
|
+
- **Every response checks `res.ok`.** ipl skipped it on 5 of 9 endpoints.
|
|
131
|
+
- **Caller headers extend the defaults instead of replacing them.** app-a spread
|
|
132
|
+
caller options after the computed headers, so any custom header dropped
|
|
133
|
+
Content-Type. FormData still correctly sends none, so the browser sets the
|
|
134
|
+
multipart boundary.
|
|
135
|
+
- **Error bodies are read once as text, then parsed.** Calling `res.json()`
|
|
136
|
+
first consumes the stream, so a `res.text()` fallback comes back empty and the
|
|
137
|
+
real message is lost. This one was caught by the test suite, in this package's
|
|
138
|
+
own first draft.
|
|
139
|
+
- **204 and non-JSON bodies return undefined** instead of throwing a parse
|
|
140
|
+
error. app-c had this; app-a did not.
|
|
141
|
+
- **A non-JSON error body is never the message.** A Cloudflare 502 is a whole
|
|
142
|
+
HTML page, and it reached a toast as `err.message`. The message is the
|
|
143
|
+
envelope's `error`, else a bare string `error`, else a bare string `message`,
|
|
144
|
+
else `"Request failed (502 Bad Gateway)"` (`"(HTTP 502)"` without status
|
|
145
|
+
text). `ApiError.body` holds JSON only, so it is undefined for HTML or plain
|
|
146
|
+
text; use `client.send()` to read such a body.
|
|
147
|
+
|
|
148
|
+
## Test
|
|
149
|
+
|
|
150
|
+
`bun run test` — 26 assertions, with `fetch` stubbed. Covers each bug above.
|
|
151
|
+
|
|
152
|
+
## Format
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
import { createCurrencyFormatter, createCompactCurrencyFormatter } from "@dapplelight/signet-lib/format"
|
|
156
|
+
|
|
157
|
+
const money = createCurrencyFormatter("INR", "en-IN")
|
|
158
|
+
money(1234) // ₹1,234
|
|
159
|
+
money(1234.5, true) // ₹1,234.50
|
|
160
|
+
|
|
161
|
+
const compact = createCompactCurrencyFormatter("INR", "en-IN")
|
|
162
|
+
compact(1_200_000) // ₹12L
|
|
163
|
+
compact(35_000_000) // ₹3.5Cr
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
`Intl` compact notation renders 12 lakh as "₹1.2M", which is wrong for Indian
|
|
167
|
+
numbering. Locales using the lakh/crore system get that scale; every other
|
|
168
|
+
locale falls through to `Intl`. Detection is by locale, not by currency — the
|
|
169
|
+
earlier version hardcoded it to INR.
|
|
170
|
+
|
|
171
|
+
Dates use `Intl` throughout. app-a pulled in `date-fns` for what the platform
|
|
172
|
+
already does.
|
|
173
|
+
|
|
174
|
+
### Date arithmetic
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
import { addDays, addMonths, startOfMonth, endOfMonth, differenceInCalendarDays } from "@dapplelight/signet-lib/format"
|
|
178
|
+
|
|
179
|
+
addMonths(new Date(2026, 0, 31), 1) // Feb 28 2026 (Feb 29 in a leap year)
|
|
180
|
+
addDays(today, -7) // a week ago, same time of day
|
|
181
|
+
const range = [startOfMonth(d), endOfMonth(d)] // 00:00:00.000 → 23:59:59.999
|
|
182
|
+
differenceInCalendarDays(new Date(2026, 2, 9), new Date(2026, 2, 8)) // 1, even on a 23-hour DST day
|
|
183
|
+
startOfYear(d) // Jan 1st, 00:00:00.000
|
|
184
|
+
|
|
185
|
+
toDateOnly(new Date(2024, 11, 25, 23, 30)) // "2024-12-25", the local calendar date
|
|
186
|
+
parseDateOnly("2024-12-25") // local midnight on 25 Dec
|
|
187
|
+
parseDateOnly("2025-02-30") // invalid Date, not rolled into March
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`addDays`, `addMonths`, `startOfDay`, `startOfMonth`, `startOfYear`, `endOfMonth`,
|
|
191
|
+
`differenceInCalendarDays`, `isSameDay` and `isSameMonth` cover what app-a kept
|
|
192
|
+
`date-fns` for. They behave like date-fns' defaults: local time, a `Date` or
|
|
193
|
+
epoch ms in, a new `Date` out, the input never mutated. `addMonths` clamps to
|
|
194
|
+
the end of a shorter month. `differenceInCalendarDays` compares calendar dates,
|
|
195
|
+
not milliseconds / 86,400,000, which floors a spring-forward day to 0. Amounts
|
|
196
|
+
may be negative; fractions truncate. An invalid date gives an invalid Date, NaN
|
|
197
|
+
or false rather than throwing.
|
|
198
|
+
|
|
199
|
+
`toDateOnly` and `parseDateOnly` convert between a local calendar date and a
|
|
200
|
+
"YYYY-MM-DD" string, for date inputs, query strings and date-only API fields.
|
|
201
|
+
`new Date("2024-12-25")` is UTC midnight, which is 24 Dec anywhere west of UTC;
|
|
202
|
+
`parseDateOnly` gives local midnight, and returns an invalid Date for any other
|
|
203
|
+
shape or for an impossible date. `toDateOnly` gives "" for an invalid date. The
|
|
204
|
+
date formatters (`createDateFormatter`, `createDateShortFormatter`,
|
|
205
|
+
`createDateTimeFormatter`, `createRelativeTimeFormatter`) read a date-only
|
|
206
|
+
string the same way; a string with a time or zone parses as before.
|
|
207
|
+
|
|
208
|
+
## Crypto: fail-closed field decryption
|
|
209
|
+
|
|
210
|
+
For apps that encrypt user data on the client (app-a's private mode). You
|
|
211
|
+
bring `decrypt`; `decryptFields` enforces the rule that is easy to get wrong:
|
|
212
|
+
a field that should be ciphertext and does not decrypt becomes `null`, never
|
|
213
|
+
passes through.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import { decryptFields } from "@dapplelight/signet-lib/crypto"
|
|
217
|
+
|
|
218
|
+
const { data, undecrypted } = await decryptFields(
|
|
219
|
+
payload,
|
|
220
|
+
["transactions.description", "transactions.merchant.cleanName"],
|
|
221
|
+
{
|
|
222
|
+
decrypt: (ct) => decryptField(ct, key),
|
|
223
|
+
// Optional. Return false only for values that are certainly legacy plaintext.
|
|
224
|
+
isCiphertext: (v) => looksLikeAesGcmBase64(v),
|
|
225
|
+
},
|
|
226
|
+
)
|
|
227
|
+
// undecrypted: ["transactions.3.description", ...] (empty when all decrypted)
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
- Paths are dot-separated; arrays are walked without an index.
|
|
231
|
+
- With no `isCiphertext`, every non-empty string at a path is treated as
|
|
232
|
+
ciphertext. A throwing `isCiphertext` also counts as ciphertext.
|
|
233
|
+
- Never throws, never mutates the input. A shared object decrypts under every
|
|
234
|
+
reference.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type EventProps = Record<string, string | number | boolean | null | undefined>;
|
|
2
|
+
export type AnalyticsEvent = {
|
|
3
|
+
name: string;
|
|
4
|
+
props?: EventProps;
|
|
5
|
+
ts: number;
|
|
6
|
+
};
|
|
7
|
+
export type Transport = (events: AnalyticsEvent[]) => void | Promise<void>;
|
|
8
|
+
export type AnalyticsConfig = {
|
|
9
|
+
transport?: Transport;
|
|
10
|
+
batchSize?: number;
|
|
11
|
+
flushIntervalMs?: number;
|
|
12
|
+
respectDoNotTrack?: boolean;
|
|
13
|
+
optOutKey?: string;
|
|
14
|
+
};
|
|
15
|
+
export declare function beaconTransport(url: string): Transport;
|
|
16
|
+
export declare function createAnalytics(config?: AnalyticsConfig): {
|
|
17
|
+
track: (name: string, props?: EventProps) => void;
|
|
18
|
+
flush: () => void;
|
|
19
|
+
pageview: (path?: string) => void;
|
|
20
|
+
optOut: () => void;
|
|
21
|
+
optIn: () => void;
|
|
22
|
+
readonly isOptedOut: boolean;
|
|
23
|
+
readonly pending: number;
|
|
24
|
+
};
|
|
25
|
+
export type Analytics = ReturnType<typeof createAnalytics>;
|
|
26
|
+
export declare const noopAnalytics: {
|
|
27
|
+
track: (name: string, props?: EventProps) => void;
|
|
28
|
+
flush: () => void;
|
|
29
|
+
pageview: (path?: string) => void;
|
|
30
|
+
optOut: () => void;
|
|
31
|
+
optIn: () => void;
|
|
32
|
+
readonly isOptedOut: boolean;
|
|
33
|
+
readonly pending: number;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/analytics/index.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC,CAAA;AAErF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,UAAU,CAAA;IAElB,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAE1E,MAAM,MAAM,eAAe,GAAG;IAE5B,SAAS,CAAC,EAAE,SAAS,CAAA;IAErB,SAAS,CAAC,EAAE,MAAM,CAAA;IAElB,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAE3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAaD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAmBtD;AAED,wBAAgB,eAAe,CAAC,MAAM,GAAE,eAAoB;kBAqCrC,MAAM,UAAU,UAAU;;sBAkB3B,MAAM;;;;;EA4B3B;AAED,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAA;AAG1D,eAAO,MAAM,aAAa;kBAnDH,MAAM,UAAU,UAAU;;sBAkB3B,MAAM;;;;;CAiCkB,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
function readStoredOptOut(key) {
|
|
2
|
+
try {
|
|
3
|
+
const v = localStorage.getItem(key);
|
|
4
|
+
return v === "1" ? true : v === null ? null : false;
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function beaconTransport(url) {
|
|
11
|
+
return (events) => {
|
|
12
|
+
const body = JSON.stringify({ events });
|
|
13
|
+
try {
|
|
14
|
+
if (typeof navigator !== "undefined" && navigator.sendBeacon) {
|
|
15
|
+
navigator.sendBeacon(url, new Blob([body], { type: "application/json" }));
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
}
|
|
21
|
+
void fetch(url, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: { "Content-Type": "application/json" },
|
|
24
|
+
body,
|
|
25
|
+
keepalive: true,
|
|
26
|
+
}).catch(() => { });
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function createAnalytics(config = {}) {
|
|
30
|
+
const batchSize = config.batchSize ?? 10;
|
|
31
|
+
const flushIntervalMs = config.flushIntervalMs ?? 5000;
|
|
32
|
+
const optOutKey = config.optOutKey ?? "signet-analytics-optout";
|
|
33
|
+
let queue = [];
|
|
34
|
+
let timer = null;
|
|
35
|
+
let optedOut = readStoredOptOut(optOutKey) ?? false;
|
|
36
|
+
const dntSaysNo = () => config.respectDoNotTrack !== false &&
|
|
37
|
+
typeof navigator !== "undefined" &&
|
|
38
|
+
navigator.doNotTrack === "1";
|
|
39
|
+
const suppressed = () => optedOut || dntSaysNo();
|
|
40
|
+
const flush = () => {
|
|
41
|
+
if (timer) {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
timer = null;
|
|
44
|
+
}
|
|
45
|
+
if (!queue.length || !config.transport) {
|
|
46
|
+
queue = [];
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const batch = queue;
|
|
50
|
+
queue = [];
|
|
51
|
+
try {
|
|
52
|
+
void config.transport(batch);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const track = (name, props) => {
|
|
58
|
+
if (!config.transport || suppressed())
|
|
59
|
+
return;
|
|
60
|
+
queue.push({ name, props, ts: Date.now() });
|
|
61
|
+
if (queue.length >= batchSize)
|
|
62
|
+
return flush();
|
|
63
|
+
if (!timer)
|
|
64
|
+
timer = setTimeout(flush, flushIntervalMs);
|
|
65
|
+
};
|
|
66
|
+
if (typeof document !== "undefined") {
|
|
67
|
+
document.addEventListener("visibilitychange", () => {
|
|
68
|
+
if (document.visibilityState === "hidden")
|
|
69
|
+
flush();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
track,
|
|
74
|
+
flush,
|
|
75
|
+
pageview: (path) => track("pageview", {
|
|
76
|
+
path: path ?? (typeof location !== "undefined" ? location.pathname : undefined),
|
|
77
|
+
referrer: typeof document !== "undefined" ? document.referrer || undefined : undefined,
|
|
78
|
+
}),
|
|
79
|
+
optOut: () => {
|
|
80
|
+
optedOut = true;
|
|
81
|
+
queue = [];
|
|
82
|
+
try {
|
|
83
|
+
localStorage.setItem(optOutKey, "1");
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
optIn: () => {
|
|
89
|
+
optedOut = false;
|
|
90
|
+
try {
|
|
91
|
+
localStorage.removeItem(optOutKey);
|
|
92
|
+
}
|
|
93
|
+
catch { }
|
|
94
|
+
},
|
|
95
|
+
get isOptedOut() {
|
|
96
|
+
return suppressed();
|
|
97
|
+
},
|
|
98
|
+
get pending() {
|
|
99
|
+
return queue.length;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export const noopAnalytics = createAnalytics();
|
|
104
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/analytics/index.ts"],"names":[],"mappings":"AAoCA,SAAS,gBAAgB,CAAC,GAAW;IACnC,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,CAA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
|
+
credentials?: RequestCredentials;
|
|
5
|
+
headers?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
6
|
+
onAuthError?: (error: AuthError) => void;
|
|
7
|
+
};
|
|
8
|
+
export type QueryValue = string | number | boolean | null | undefined;
|
|
9
|
+
export declare function qs(params: Record<string, QueryValue>): string;
|
|
10
|
+
export declare function createApiClient(opts?: ApiClientOptions): {
|
|
11
|
+
request: <T>(path: string, init?: RequestInit, isForm?: boolean) => Promise<T>;
|
|
12
|
+
get: <T>(path: string, init?: RequestInit) => Promise<T>;
|
|
13
|
+
post: <T>(path: string, body?: unknown, init?: RequestInit) => Promise<T>;
|
|
14
|
+
put: <T>(path: string, body?: unknown, init?: RequestInit) => Promise<T>;
|
|
15
|
+
patch: <T>(path: string, body?: unknown, init?: RequestInit) => Promise<T>;
|
|
16
|
+
delete: <T>(path: string, body?: unknown, init?: RequestInit) => Promise<T>;
|
|
17
|
+
postForm: <T>(path: string, body: FormData, init?: RequestInit) => Promise<T>;
|
|
18
|
+
send: (path: string, init?: RequestInit) => Promise<Response>;
|
|
19
|
+
raw: (path: string, init?: RequestInit) => Promise<Response>;
|
|
20
|
+
};
|
|
21
|
+
export type ApiClient = ReturnType<typeof createApiClient>;
|
|
22
|
+
export declare function retryAfterSeconds(headers: Headers, now?: number): number | undefined;
|
|
23
|
+
export declare function toApiError(res: Response): Promise<ApiError>;
|
|
24
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,MAAM,gBAAgB,GAAG;IAE7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAEhC,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,G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
function mergeHeaders(...sources) {
|
|
4
|
+
const out = new Headers();
|
|
5
|
+
for (const src of sources)
|
|
6
|
+
for (const [k, v] of new Headers(src ?? {}))
|
|
7
|
+
out.set(k, v);
|
|
8
|
+
return out;
|
|
9
|
+
}
|
|
10
|
+
const isJson = (contentType) => !!contentType && /[/+]json\b/i.test(contentType);
|
|
11
|
+
async function toAuthError(res) {
|
|
12
|
+
const err = await toApiError(res);
|
|
13
|
+
return new AuthError(err.code || err.body ? err.message : undefined, err.code, err.body);
|
|
14
|
+
}
|
|
15
|
+
export function qs(params) {
|
|
16
|
+
const search = new URLSearchParams();
|
|
17
|
+
for (const [k, v] of Object.entries(params)) {
|
|
18
|
+
if (v === undefined || v === null || v === "")
|
|
19
|
+
continue;
|
|
20
|
+
search.set(k, String(v));
|
|
21
|
+
}
|
|
22
|
+
const s = search.toString();
|
|
23
|
+
return s ? `?${s}` : "";
|
|
24
|
+
}
|
|
25
|
+
export function createApiClient(opts = {}) {
|
|
26
|
+
const baseUrl = (opts.baseUrl ?? "").replace(/\/$/, "");
|
|
27
|
+
async function send(path, init = {}) {
|
|
28
|
+
const extra = (await opts.headers?.()) ?? {};
|
|
29
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
30
|
+
credentials: opts.credentials ?? "include",
|
|
31
|
+
...init,
|
|
32
|
+
headers: mergeHeaders(extra, init.headers),
|
|
33
|
+
});
|
|
34
|
+
if (res.status === 401) {
|
|
35
|
+
const err = await toAuthError(res);
|
|
36
|
+
opts.onAuthError?.(err);
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
return res;
|
|
40
|
+
}
|
|
41
|
+
async function request(path, init = {}, isForm = false) {
|
|
42
|
+
const extra = (await opts.headers?.()) ?? {};
|
|
43
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
44
|
+
credentials: opts.credentials ?? "include",
|
|
45
|
+
...init,
|
|
46
|
+
headers: mergeHeaders(isForm ? {} : { "Content-Type": "application/json" }, extra, init.headers),
|
|
47
|
+
});
|
|
48
|
+
if (res.status === 401) {
|
|
49
|
+
const err = await toAuthError(res);
|
|
50
|
+
opts.onAuthError?.(err);
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
if (!res.ok)
|
|
54
|
+
throw await toApiError(res);
|
|
55
|
+
if (res.status === 204)
|
|
56
|
+
return undefined;
|
|
57
|
+
const text = await res.text();
|
|
58
|
+
if (!text)
|
|
59
|
+
return undefined;
|
|
60
|
+
if (!isJson(res.headers.get("content-type"))) {
|
|
61
|
+
throw new ApiError(`Expected JSON, got ${res.headers.get("content-type") ?? "no content type"}`, res.status);
|
|
62
|
+
}
|
|
63
|
+
return JSON.parse(text);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
request,
|
|
67
|
+
get: (path, init) => request(path, { ...init, method: "GET" }),
|
|
68
|
+
post: (path, body, init) => request(path, { ...init, method: "POST", body: JSON.stringify(body ?? {}) }),
|
|
69
|
+
put: (path, body, init) => request(path, { ...init, method: "PUT", body: JSON.stringify(body ?? {}) }),
|
|
70
|
+
patch: (path, body, init) => request(path, { ...init, method: "PATCH", body: JSON.stringify(body ?? {}) }),
|
|
71
|
+
delete: (path, body, init) => request(path, {
|
|
72
|
+
...init,
|
|
73
|
+
method: "DELETE",
|
|
74
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
75
|
+
}),
|
|
76
|
+
postForm: (path, body, init) => request(path, { ...init, method: "POST", body }, true),
|
|
77
|
+
send,
|
|
78
|
+
raw: async (path, init) => {
|
|
79
|
+
const res = await send(path, init);
|
|
80
|
+
if (!res.ok)
|
|
81
|
+
throw await toApiError(res);
|
|
82
|
+
return res;
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function retryAfterSeconds(headers, now = Date.now()) {
|
|
87
|
+
const ra = headers.get("retry-after");
|
|
88
|
+
if (ra) {
|
|
89
|
+
if (/^\d+$/.test(ra.trim()))
|
|
90
|
+
return Number(ra);
|
|
91
|
+
const at = Date.parse(ra);
|
|
92
|
+
if (!Number.isNaN(at))
|
|
93
|
+
return Math.max(0, Math.ceil((at - now) / 1000));
|
|
94
|
+
}
|
|
95
|
+
const reset = headers.get("ratelimit-reset");
|
|
96
|
+
if (reset && /^\d+$/.test(reset.trim()))
|
|
97
|
+
return Number(reset);
|
|
98
|
+
const epoch = headers.get("x-ratelimit-reset");
|
|
99
|
+
if (epoch && /^\d+$/.test(epoch.trim()))
|
|
100
|
+
return Math.max(0, Number(epoch) - Math.floor(now / 1000));
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
export async function toApiError(res) {
|
|
104
|
+
const text = await res.text().catch(() => "");
|
|
105
|
+
let body;
|
|
106
|
+
try {
|
|
107
|
+
body = text ? JSON.parse(text) : undefined;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
}
|
|
111
|
+
const headerId = res.headers.get("x-request-id") ?? undefined;
|
|
112
|
+
const retry = retryAfterSeconds(res.headers);
|
|
113
|
+
if (isErrorEnvelope(body)) {
|
|
114
|
+
return new ApiError(body.error, res.status, body.code, body.details, body.requestId ?? headerId, retry, body);
|
|
115
|
+
}
|
|
116
|
+
const field = (k) => body && typeof body === "object" && typeof body[k] === "string"
|
|
117
|
+
? body[k]
|
|
118
|
+
: undefined;
|
|
119
|
+
const bareError = field("error") ?? field("message");
|
|
120
|
+
return new ApiError(bareError ||
|
|
121
|
+
`Request failed (${res.statusText ? `${res.status} ${res.statusText}` : `HTTP ${res.status}`})`, res.status, undefined, undefined, headerId, retry, body);
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAkBjD,SA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_FAILED", "INVALID_JSON", "RATE_LIMITED", "RATE_LIMIT_UNAVAILABLE", "INTERNAL_ERROR", "BAD_REQUEST", "UNAUTHORIZED", "FORBIDDEN", "NOT_FOUND", "METHOD_NOT_ALLOWED", "CONFLICT", "GONE", "PAYLOAD_TOO_LARGE", "UNPROCESSABLE", "HTTP_ERROR", "INVALID_PAYLOAD", "invalid_token", "insufficient_scope"];
|
|
2
|
+
export type ErrorCode = (typeof ERROR_CODES)[number];
|
|
3
|
+
export declare function isErrorCode(v: unknown): v is ErrorCode;
|
|
4
|
+
//# sourceMappingURL=codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.d.ts","sourceRoot":"","sources":["../../src/api/codes.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,WAAW,YAEtB,mBAAmB,EACnB,cAAc,EAEd,cAAc,EACd,wBAAwB,EAExB,gBAAgB,EAEhB,aAAa,EACb,cAAc,EACd,WAAW,EACX,WAAW,EACX,oBAAoB,EACpB,UAAU,EACV,MAAM,EACN,mBAAmB,EACnB,eAAe,EACf,YAAY,EAEZ,iBAAiB,EAEjB,eAAe,EACf,oBAAoB,CACZ,CAAA;AAEV,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAA;AAEpD,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,SAAS,CAEtD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const ERROR_CODES = [
|
|
2
|
+
"VALIDATION_FAILED",
|
|
3
|
+
"INVALID_JSON",
|
|
4
|
+
"RATE_LIMITED",
|
|
5
|
+
"RATE_LIMIT_UNAVAILABLE",
|
|
6
|
+
"INTERNAL_ERROR",
|
|
7
|
+
"BAD_REQUEST",
|
|
8
|
+
"UNAUTHORIZED",
|
|
9
|
+
"FORBIDDEN",
|
|
10
|
+
"NOT_FOUND",
|
|
11
|
+
"METHOD_NOT_ALLOWED",
|
|
12
|
+
"CONFLICT",
|
|
13
|
+
"GONE",
|
|
14
|
+
"PAYLOAD_TOO_LARGE",
|
|
15
|
+
"UNPROCESSABLE",
|
|
16
|
+
"HTTP_ERROR",
|
|
17
|
+
"INVALID_PAYLOAD",
|
|
18
|
+
"invalid_token",
|
|
19
|
+
"insufficient_scope",
|
|
20
|
+
];
|
|
21
|
+
export function isErrorCode(v) {
|
|
22
|
+
return typeof v === "string" && ERROR_CODES.includes(v);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codes.js","sourceRoot":"","sources":["../../src/api/codes.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,WAAW,GAAG;IAEzB,mBAAmB;IACnB,cAAc;IAEd,cAAc;IACd,wBAAwB;IAExB,gBAAgB;IAEhB,aAAa;IACb,cAAc;IACd,WAAW;IACX,WAAW;IACX,oBAAoB;IACpB,UAAU;IACV,MAAM;IACN,mBAAmB;IACnB,eAAe;IACf,YAAY;IAEZ,iBAAiB;IAEjB,eAAe;IACf,oBAAoB;CACZ,CAAA;AAIV,MAAM,UAAU,WAAW,CAAC,CAAU;IACpC,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAK,WAAiC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;AAChF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type ErrorEnvelope = {
|
|
2
|
+
success: false;
|
|
3
|
+
error: string;
|
|
4
|
+
code?: string;
|
|
5
|
+
details?: {
|
|
6
|
+
formErrors: string[];
|
|
7
|
+
fieldErrors: Record<string, string[]>;
|
|
8
|
+
};
|
|
9
|
+
requestId?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function isErrorEnvelope(v: unknown): v is ErrorEnvelope;
|
|
12
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/api/contract.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,KAAK,CAAA;IAEd,KAAK,EAAE,MAAM,CAAA;IAEb,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,OAAO,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,EAAE,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;KAAE,CAAA;IAEzE,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,aAAa,CAO9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/api/contract.ts"],"names":[],"mappings":"AAqBA,MAAM,UAAU,eAAe,CAAC,CAAU;IACxC,OAAO,CACL,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACT,CAA2B,CAAC,OAAO,KAAK,KAAK;QAC9C,OAAQ,CAAyB,CAAC,KAAK,KAAK,QAAQ,CACrD,CAAA;AACH,CAAC"}
|