@entreprenoid/analytics 0.1.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.
- package/README.md +82 -0
- package/dist/chunk-5NZNPRMN.js +355 -0
- package/dist/chunk-5NZNPRMN.js.map +1 -0
- package/dist/chunk-EVNUKN5A.js +114 -0
- package/dist/chunk-EVNUKN5A.js.map +1 -0
- package/dist/chunk-GKFYGAKF.js +104 -0
- package/dist/chunk-GKFYGAKF.js.map +1 -0
- package/dist/chunk-IHZCOC2U.js +690 -0
- package/dist/chunk-IHZCOC2U.js.map +1 -0
- package/dist/core/breaker.d.ts +33 -0
- package/dist/core/collector.d.ts +40 -0
- package/dist/core/config.d.ts +101 -0
- package/dist/core/encode.d.ts +32 -0
- package/dist/core/queue.d.ts +39 -0
- package/dist/core/safe.d.ts +17 -0
- package/dist/core/transport.d.ts +45 -0
- package/dist/express.cjs +1042 -0
- package/dist/express.cjs.map +1 -0
- package/dist/express.d.ts +51 -0
- package/dist/express.js +4 -0
- package/dist/express.js.map +1 -0
- package/dist/index.cjs +1289 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +801 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.d.ts +90 -0
- package/dist/next.js +4 -0
- package/dist/next.js.map +1 -0
- package/dist/observe/redact.d.ts +58 -0
- package/dist/observe/request.d.ts +57 -0
- package/dist/observe/response.d.ts +24 -0
- package/dist/runtime.d.ts +27 -0
- package/dist/serve/accept.d.ts +7 -0
- package/dist/serve/discovery.d.ts +45 -0
- package/dist/serve/twin.d.ts +102 -0
- package/dist/web.cjs +790 -0
- package/dist/web.cjs.map +1 -0
- package/dist/web.d.ts +43 -0
- package/dist/web.js +4 -0
- package/dist/web.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The markdown twin: the decision, as a pure function.
|
|
3
|
+
*
|
|
4
|
+
* ── Why the decision is separated from the serving ───────────────────────────
|
|
5
|
+
* Two adapters have to make the identical choice, and the choice is the part
|
|
6
|
+
* with consequences -- serve the wrong thing and a human gets a text file
|
|
7
|
+
* instead of a website. One function, one set of tests, two thin call sites.
|
|
8
|
+
*/
|
|
9
|
+
export interface Twin {
|
|
10
|
+
body: string;
|
|
11
|
+
/** Defaults to `text/markdown; charset=utf-8`. */
|
|
12
|
+
contentType?: string;
|
|
13
|
+
etag?: string;
|
|
14
|
+
lastModified?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface TwinOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Find the twin for a normalised path, or return null.
|
|
19
|
+
*
|
|
20
|
+
* ⚠️ **Registered, not derived.** Returning a twin for any path that "looks
|
|
21
|
+
* like" it should have one produces a site where every URL answers, including
|
|
22
|
+
* the typos -- caprail.dev returns a plain 404 for an unregistered `.md`, and
|
|
23
|
+
* that is the behaviour to match.
|
|
24
|
+
*/
|
|
25
|
+
resolve: (path: string) => Twin | null | undefined | Promise<Twin | null | undefined>;
|
|
26
|
+
/** `Cache-Control` for a served twin. Edge-cacheable by default. */
|
|
27
|
+
cacheControl?: string;
|
|
28
|
+
/** Advertise an available twin on the HTML response. Default true. */
|
|
29
|
+
advertise?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Serve `/llms.txt`, `/llms-full.txt` and `/install.md` from the same
|
|
32
|
+
* manifest that serves the twins.
|
|
33
|
+
*
|
|
34
|
+
* ⚠️ Derived, not written: a hand-maintained index is wrong the first time a
|
|
35
|
+
* page is added, and an index listing pages that no longer exist is worse
|
|
36
|
+
* than none -- an agent spends its budget on 404s and concludes the site is
|
|
37
|
+
* broken.
|
|
38
|
+
*/
|
|
39
|
+
discovery?: import("./discovery.js").DiscoveryOptions;
|
|
40
|
+
}
|
|
41
|
+
/** Paths the discovery block answers, when it is configured. */
|
|
42
|
+
export declare const DISCOVERY_PATHS: readonly ["/llms.txt", "/llms-full.txt", "/install.md"];
|
|
43
|
+
export declare const DEFAULT_TWIN_CONTENT_TYPE = "text/markdown; charset=utf-8";
|
|
44
|
+
export declare const DEFAULT_TWIN_CACHE_CONTROL = "public, max-age=3600, s-maxage=86400";
|
|
45
|
+
export type TwinDecision =
|
|
46
|
+
/** Serve the twin for `lookupPath`. */
|
|
47
|
+
{
|
|
48
|
+
action: "serve";
|
|
49
|
+
lookupPath: string;
|
|
50
|
+
reason: "md_path" | "accept_header";
|
|
51
|
+
}
|
|
52
|
+
/** Not ours to answer, but a twin may exist worth advertising. */
|
|
53
|
+
| {
|
|
54
|
+
action: "pass";
|
|
55
|
+
reason: "not_get" | "no_signal";
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Map a request onto a decision. Nothing here touches I/O.
|
|
59
|
+
*
|
|
60
|
+
* Two gates, and only two:
|
|
61
|
+
* 1. the path ends in `.md` -- a distinct resource, no negotiation at all;
|
|
62
|
+
* 2. `Accept` explicitly prefers markdown -- content negotiation, which owes
|
|
63
|
+
* a `Vary: Accept`.
|
|
64
|
+
*
|
|
65
|
+
* ⚠️ Never the User-Agent. See `accept.ts`.
|
|
66
|
+
*/
|
|
67
|
+
export declare function decideTwin(input: {
|
|
68
|
+
method: string;
|
|
69
|
+
path: string;
|
|
70
|
+
accept: string | null | undefined;
|
|
71
|
+
}): TwinDecision;
|
|
72
|
+
/**
|
|
73
|
+
* `/docs/intro.md` -> `/docs/intro`, and `/index.md` -> `/`.
|
|
74
|
+
*
|
|
75
|
+
* The root is the case worth naming: a site's home page has no slug, so its
|
|
76
|
+
* twin is `/index.md` by convention -- the same convention caprail.dev uses.
|
|
77
|
+
*/
|
|
78
|
+
export declare function stripMdSuffix(path: string): string;
|
|
79
|
+
/** `/docs/intro` -> `/docs/intro.md`, and `/` -> `/index.md`. */
|
|
80
|
+
export declare function twinPathFor(path: string): string;
|
|
81
|
+
export interface TwinResponse {
|
|
82
|
+
status: number;
|
|
83
|
+
headers: Record<string, string>;
|
|
84
|
+
body: string;
|
|
85
|
+
}
|
|
86
|
+
export declare function buildTwinResponse(twin: Twin, decision: Extract<TwinDecision, {
|
|
87
|
+
action: "serve";
|
|
88
|
+
}>, options: TwinOptions): TwinResponse;
|
|
89
|
+
/**
|
|
90
|
+
* The advertisement for an available twin, as a `Link` header.
|
|
91
|
+
*
|
|
92
|
+
* ⚠️ **A header, not a tag injected into the HTML.** Caprail puts
|
|
93
|
+
* `<link rel="alternate">` in its own document head, which it can do because it
|
|
94
|
+
* owns the template. A middleware cannot: injecting into the body means
|
|
95
|
+
* buffering and rewriting somebody else's response, which is precisely what
|
|
96
|
+
* this package refuses to do. RFC 8288 makes the header the equivalent, it
|
|
97
|
+
* costs nothing, and it works for JSON and plain text as well as HTML.
|
|
98
|
+
*
|
|
99
|
+
* A customer who also wants the tag can add it to their own template, and
|
|
100
|
+
* should -- some crawlers read one and not the other.
|
|
101
|
+
*/
|
|
102
|
+
export declare function advertiseHeader(path: string): string;
|