@aithos/sdk 0.1.0-alpha.3 → 0.1.0-alpha.30
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 +159 -0
- package/dist/src/auth-api.d.ts +105 -0
- package/dist/src/auth-api.js +178 -0
- package/dist/src/auth.d.ts +359 -68
- package/dist/src/auth.js +1035 -69
- package/dist/src/compute.d.ts +221 -9
- package/dist/src/compute.js +293 -16
- package/dist/src/data-schema-contacts-v1.d.ts +14 -0
- package/dist/src/data-schema-contacts-v1.js +28 -0
- package/dist/src/data.d.ts +97 -0
- package/dist/src/data.js +634 -0
- package/dist/src/endpoints.d.ts +9 -0
- package/dist/src/endpoints.js +5 -0
- package/dist/src/ethos.d.ts +202 -1
- package/dist/src/ethos.js +821 -16
- package/dist/src/index.d.ts +15 -6
- package/dist/src/index.js +36 -9
- package/dist/src/internal/delegate-bundle.d.ts +18 -0
- package/dist/src/internal/delegate-bundle.js +94 -0
- package/dist/src/internal/delegate-state.d.ts +45 -0
- package/dist/src/internal/delegate-state.js +120 -0
- package/dist/src/internal/owner-signers.d.ts +78 -0
- package/dist/src/internal/owner-signers.js +179 -0
- package/dist/src/internal/protocol-client-bridge.d.ts +8 -0
- package/dist/src/internal/protocol-client-bridge.js +20 -0
- package/dist/src/internal/recovery-file.d.ts +29 -0
- package/dist/src/internal/recovery-file.js +98 -0
- package/dist/src/internal/signer.d.ts +59 -0
- package/dist/src/internal/signer.js +86 -0
- package/dist/src/key-store.d.ts +128 -0
- package/dist/src/key-store.js +244 -0
- package/dist/src/mandates.d.ts +163 -1
- package/dist/src/mandates.js +286 -8
- package/dist/src/sdk.d.ts +39 -3
- package/dist/src/sdk.js +36 -23
- package/dist/src/session-store.d.ts +58 -0
- package/dist/src/session-store.js +158 -0
- package/dist/src/wallet.d.ts +4 -6
- package/dist/src/wallet.js +18 -8
- package/dist/src/web.d.ts +279 -0
- package/dist/src/web.js +186 -0
- package/dist/test/auth-j3.test.d.ts +2 -0
- package/dist/test/auth-j3.test.js +391 -0
- package/dist/test/compute-delegate-path.test.d.ts +2 -0
- package/dist/test/compute-delegate-path.test.js +183 -0
- package/dist/test/compute.test.js +26 -11
- package/dist/test/endpoints.test.js +20 -1
- package/dist/test/ethos-first-edition.test.d.ts +2 -0
- package/dist/test/ethos-first-edition.test.js +248 -0
- package/dist/test/ethos.test.d.ts +2 -0
- package/dist/test/ethos.test.js +219 -0
- package/dist/test/key-store.test.d.ts +2 -0
- package/dist/test/key-store.test.js +161 -0
- package/dist/test/mandates-compute.test.d.ts +2 -0
- package/dist/test/mandates-compute.test.js +256 -0
- package/dist/test/mandates.test.d.ts +2 -0
- package/dist/test/mandates.test.js +93 -0
- package/dist/test/sdk.test.js +70 -30
- package/dist/test/signer.test.d.ts +2 -0
- package/dist/test/signer.test.js +117 -0
- package/dist/test/signup-bootstrap.test.d.ts +2 -0
- package/dist/test/signup-bootstrap.test.js +222 -0
- package/dist/test/wallet.test.js +20 -9
- package/dist/test/web.test.d.ts +2 -0
- package/dist/test/web.test.js +270 -0
- package/package.json +5 -4
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Copyright 2026 Mathieu Colla
|
|
3
|
+
/* -------------------------------------------------------------------------- */
|
|
4
|
+
/* Storage key & expiration */
|
|
5
|
+
/* -------------------------------------------------------------------------- */
|
|
6
|
+
/**
|
|
7
|
+
* Storage key used by the bundled stores. Apps that want to coexist with
|
|
8
|
+
* other Aithos-aware libs (or that want to scope sessions per-tenant) can
|
|
9
|
+
* pass a custom key via {@link sessionStorageStore} or
|
|
10
|
+
* {@link localStorageStore}.
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_SESSION_STORAGE_KEY = "aithos.session.v1";
|
|
13
|
+
/** Conservative buffer — drop the session 30 s before its `exp` so we
|
|
14
|
+
* don't hand out a token the server is about to reject. */
|
|
15
|
+
const SESSION_EXPIRY_BUFFER_S = 30;
|
|
16
|
+
function isExpired(session, nowSec) {
|
|
17
|
+
return session.exp <= nowSec + SESSION_EXPIRY_BUFFER_S;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate at runtime that an opaque object looks like an `AithosSession`.
|
|
21
|
+
* Storage values come from JSON.parse over user-controlled data — we can't
|
|
22
|
+
* trust them blind. This isn't a security check (the server validates the
|
|
23
|
+
* JWT ; persistence layers don't authenticate themselves) ; it just
|
|
24
|
+
* prevents weird crashes when the storage was tampered with.
|
|
25
|
+
*/
|
|
26
|
+
function isSessionShaped(v) {
|
|
27
|
+
if (typeof v !== "object" || v === null)
|
|
28
|
+
return false;
|
|
29
|
+
const o = v;
|
|
30
|
+
return (typeof o["session"] === "string" &&
|
|
31
|
+
typeof o["exp"] === "number" &&
|
|
32
|
+
typeof o["did"] === "string" &&
|
|
33
|
+
typeof o["handle"] === "string");
|
|
34
|
+
}
|
|
35
|
+
function browserStorageStore(storageRef, opts = {}) {
|
|
36
|
+
const key = opts.key ?? DEFAULT_SESSION_STORAGE_KEY;
|
|
37
|
+
return {
|
|
38
|
+
get() {
|
|
39
|
+
const s = storageRef();
|
|
40
|
+
if (!s)
|
|
41
|
+
return null;
|
|
42
|
+
let raw;
|
|
43
|
+
try {
|
|
44
|
+
raw = s.getItem(key);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
if (!raw)
|
|
50
|
+
return null;
|
|
51
|
+
let parsed;
|
|
52
|
+
try {
|
|
53
|
+
parsed = JSON.parse(raw);
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Corrupted entry — wipe to recover.
|
|
57
|
+
try {
|
|
58
|
+
s.removeItem(key);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
/* ignore */
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (!isSessionShaped(parsed))
|
|
66
|
+
return null;
|
|
67
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
68
|
+
if (isExpired(parsed, nowSec)) {
|
|
69
|
+
// Auto-evict — let the caller see "no session" and re-auth.
|
|
70
|
+
try {
|
|
71
|
+
s.removeItem(key);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
/* ignore */
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return parsed;
|
|
79
|
+
},
|
|
80
|
+
set(session) {
|
|
81
|
+
const s = storageRef();
|
|
82
|
+
if (!s)
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
s.setItem(key, JSON.stringify(session));
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
// Quota exceeded, private mode, etc. — log but don't throw : the
|
|
89
|
+
// sign-in returned successfully, the in-memory session is still
|
|
90
|
+
// usable for this tab.
|
|
91
|
+
// eslint-disable-next-line no-console
|
|
92
|
+
console.warn("[AithosAuth] failed to persist session:", e.message);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
clear() {
|
|
96
|
+
const s = storageRef();
|
|
97
|
+
if (!s)
|
|
98
|
+
return;
|
|
99
|
+
try {
|
|
100
|
+
s.removeItem(key);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
/* ignore */
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function safeStorage(getter) {
|
|
109
|
+
return () => {
|
|
110
|
+
try {
|
|
111
|
+
const s = getter();
|
|
112
|
+
return s ?? null;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Some restricted contexts (sandboxed iframes, file:// URLs) throw
|
|
116
|
+
// on access. Treat them as "no storage available".
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Default web store : `sessionStorage`. The session lives until the tab
|
|
123
|
+
* is closed. Cleared on `signOut()`. Use this when reauthenticating each
|
|
124
|
+
* day is acceptable and reduces blast radius after an XSS.
|
|
125
|
+
*/
|
|
126
|
+
export function sessionStorageStore(opts) {
|
|
127
|
+
return browserStorageStore(safeStorage(() => (typeof sessionStorage !== "undefined" ? sessionStorage : undefined)), opts);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* `localStorage` store. The session persists until the JWT expires or the
|
|
131
|
+
* user explicitly signs out. Higher convenience, larger XSS blast radius.
|
|
132
|
+
*/
|
|
133
|
+
export function localStorageStore(opts) {
|
|
134
|
+
return browserStorageStore(safeStorage(() => (typeof localStorage !== "undefined" ? localStorage : undefined)), opts);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* No-op store. `set` and `clear` discard their input ; `get` always
|
|
138
|
+
* returns null. The default in non-browser contexts (Node, edge runtimes)
|
|
139
|
+
* — apps running there should pass their own store explicitly.
|
|
140
|
+
*/
|
|
141
|
+
export function noopStore() {
|
|
142
|
+
return {
|
|
143
|
+
get: () => null,
|
|
144
|
+
set: () => { },
|
|
145
|
+
clear: () => { },
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Pick a sensible default : `sessionStorage` if the browser environment
|
|
150
|
+
* is available, {@link noopStore} otherwise.
|
|
151
|
+
*/
|
|
152
|
+
export function defaultSessionStore() {
|
|
153
|
+
if (typeof sessionStorage !== "undefined") {
|
|
154
|
+
return sessionStorageStore();
|
|
155
|
+
}
|
|
156
|
+
return noopStore();
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=session-store.js.map
|
package/dist/src/wallet.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { AithosAuth } from "./auth.js";
|
|
2
2
|
import { type AithosSdkEndpoints } from "./endpoints.js";
|
|
3
3
|
/**
|
|
4
4
|
* Canonical credit-pack identifiers. Pricing and microcredit amounts are
|
|
@@ -44,12 +44,10 @@ export interface GetBalanceResult {
|
|
|
44
44
|
readonly exists: boolean;
|
|
45
45
|
}
|
|
46
46
|
export interface WalletNamespaceDeps {
|
|
47
|
-
/**
|
|
48
|
-
readonly
|
|
47
|
+
/** Auth instance — the wallet reads the active owner DID + signing key from here. */
|
|
48
|
+
readonly auth: AithosAuth;
|
|
49
49
|
/** App DID — sent as audit attribution alongside the balance request. */
|
|
50
50
|
readonly appDid: string;
|
|
51
|
-
/** Pre-resolved DID convenience accessor (mirrors identity.did). */
|
|
52
|
-
readonly userDid: string;
|
|
53
51
|
readonly endpoints: AithosSdkEndpoints;
|
|
54
52
|
readonly fetch: typeof fetch;
|
|
55
53
|
}
|
|
@@ -64,7 +62,7 @@ export declare class WalletNamespace {
|
|
|
64
62
|
* hosted URL — the caller is responsible for redirecting the user (e.g.
|
|
65
63
|
* `window.location.href = result.checkoutUrl`).
|
|
66
64
|
*
|
|
67
|
-
* On success, the Stripe webhook will credit
|
|
65
|
+
* On success, the Stripe webhook will credit the user's wallet once the
|
|
68
66
|
* payment clears. Wallet balances are shared across all Aithos apps that
|
|
69
67
|
* use the same DID.
|
|
70
68
|
*/
|
package/dist/src/wallet.js
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
// compute proxy at `${compute}/v1/invoke`. Read-only DDB GetItem on
|
|
14
14
|
// the wallet table, gated by the same signed envelope verification
|
|
15
15
|
// as compute_invoke. Returns the current balance + daily spent.
|
|
16
|
-
import { buildSignedEnvelope
|
|
16
|
+
import { buildSignedEnvelope } from "@aithos/protocol-client";
|
|
17
17
|
import { computeInvokeUrl, walletTopupCheckoutUrl, } from "./endpoints.js";
|
|
18
|
+
import { ownerKeyPair } from "./internal/protocol-client-bridge.js";
|
|
18
19
|
import { AithosSDKError } from "./types.js";
|
|
19
20
|
/**
|
|
20
21
|
* `sdk.wallet` namespace.
|
|
@@ -29,12 +30,16 @@ export class WalletNamespace {
|
|
|
29
30
|
* hosted URL — the caller is responsible for redirecting the user (e.g.
|
|
30
31
|
* `window.location.href = result.checkoutUrl`).
|
|
31
32
|
*
|
|
32
|
-
* On success, the Stripe webhook will credit
|
|
33
|
+
* On success, the Stripe webhook will credit the user's wallet once the
|
|
33
34
|
* payment clears. Wallet balances are shared across all Aithos apps that
|
|
34
35
|
* use the same DID.
|
|
35
36
|
*/
|
|
36
37
|
async createTopupSession(args) {
|
|
37
|
-
const {
|
|
38
|
+
const { auth, endpoints, fetch: fetchImpl } = this.#deps;
|
|
39
|
+
const owner = auth._getOwnerSigners();
|
|
40
|
+
if (!owner || owner.destroyed) {
|
|
41
|
+
throw new AithosSDKError("sdk_no_owner", "no owner signed in; sign in first");
|
|
42
|
+
}
|
|
38
43
|
const url = walletTopupCheckoutUrl(endpoints);
|
|
39
44
|
let res;
|
|
40
45
|
try {
|
|
@@ -42,7 +47,7 @@ export class WalletNamespace {
|
|
|
42
47
|
method: "POST",
|
|
43
48
|
headers: { "content-type": "application/json" },
|
|
44
49
|
body: JSON.stringify({
|
|
45
|
-
user_did:
|
|
50
|
+
user_did: owner.did,
|
|
46
51
|
pack_id: args.packId,
|
|
47
52
|
success_url: args.successUrl,
|
|
48
53
|
cancel_url: args.cancelUrl,
|
|
@@ -88,16 +93,21 @@ export class WalletNamespace {
|
|
|
88
93
|
* envelope-verify failures from the proxy).
|
|
89
94
|
*/
|
|
90
95
|
async getBalance(args = {}) {
|
|
91
|
-
const {
|
|
96
|
+
const { auth, appDid, endpoints, fetch: fetchImpl } = this.#deps;
|
|
97
|
+
const owner = auth._getOwnerSigners();
|
|
98
|
+
if (!owner || owner.destroyed) {
|
|
99
|
+
throw new AithosSDKError("sdk_no_owner", "no owner signed in; sign in first");
|
|
100
|
+
}
|
|
101
|
+
const publicKp = ownerKeyPair(owner, "public");
|
|
92
102
|
const url = computeInvokeUrl(endpoints);
|
|
93
103
|
const params = { app_did: appDid };
|
|
94
104
|
const envelope = buildSignedEnvelope({
|
|
95
|
-
iss:
|
|
105
|
+
iss: owner.did,
|
|
96
106
|
aud: url,
|
|
97
107
|
method: "aithos.wallet_get_balance",
|
|
98
|
-
verificationMethod: `${
|
|
108
|
+
verificationMethod: `${owner.did}#public`,
|
|
99
109
|
params,
|
|
100
|
-
signer:
|
|
110
|
+
signer: publicKp,
|
|
101
111
|
});
|
|
102
112
|
let res;
|
|
103
113
|
try {
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import type { AithosAuth } from "./auth.js";
|
|
2
|
+
import { type AithosSdkEndpoints } from "./endpoints.js";
|
|
3
|
+
/** Opt-in scope a mandate must carry to invoke `aithos.web_extract`. */
|
|
4
|
+
export declare const WEB_EXTRACT_SCOPE: "web.extract";
|
|
5
|
+
export interface ExtractArgs {
|
|
6
|
+
/**
|
|
7
|
+
* Mandate ID under which this call should be attributed.
|
|
8
|
+
*
|
|
9
|
+
* - **Owner sessions**: optional. The SDK uses the owner's own DID
|
|
10
|
+
* as a sentinel "self" mandate id — the proxy skips mandate checks
|
|
11
|
+
* when the envelope is owner-signed.
|
|
12
|
+
* - **Delegate sessions**: required. Must reference the imported
|
|
13
|
+
* mandate bundle the SDK signs with; the proxy enforces the
|
|
14
|
+
* `web.extract` scope.
|
|
15
|
+
*/
|
|
16
|
+
readonly mandateId?: string;
|
|
17
|
+
/** Absolute http(s) URL to extract. */
|
|
18
|
+
readonly url: string;
|
|
19
|
+
/**
|
|
20
|
+
* Playwright `waitUntil` strategy passed straight through to the
|
|
21
|
+
* server-side navigation. Defaults to `"networkidle"` server-side
|
|
22
|
+
* if omitted.
|
|
23
|
+
*/
|
|
24
|
+
readonly waitUntil?: "load" | "domcontentloaded" | "networkidle";
|
|
25
|
+
/** Navigation timeout in ms. Server validates [1000, 60000]. */
|
|
26
|
+
readonly timeoutMs?: number;
|
|
27
|
+
/** Reserved for audit-level deduplication; the proxy currently does not
|
|
28
|
+
* enforce idempotency keys for extractions. */
|
|
29
|
+
readonly idempotencyKey?: string;
|
|
30
|
+
/** Abort signal to cancel the request. */
|
|
31
|
+
readonly signal?: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
export interface ExtractMeta {
|
|
34
|
+
readonly title: string | null;
|
|
35
|
+
readonly description: string | null;
|
|
36
|
+
readonly lang: string | null;
|
|
37
|
+
readonly charset: string | null;
|
|
38
|
+
readonly viewport: string | null;
|
|
39
|
+
readonly canonical: string | null;
|
|
40
|
+
readonly og: Readonly<Record<string, string>>;
|
|
41
|
+
}
|
|
42
|
+
export interface ExtractHeading {
|
|
43
|
+
readonly level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
44
|
+
readonly text: string;
|
|
45
|
+
readonly id: string | null;
|
|
46
|
+
}
|
|
47
|
+
export interface ExtractSection {
|
|
48
|
+
readonly tag: string;
|
|
49
|
+
readonly role: string | null;
|
|
50
|
+
readonly html: string;
|
|
51
|
+
readonly text_len: number;
|
|
52
|
+
}
|
|
53
|
+
export interface ExtractLink {
|
|
54
|
+
readonly label: string;
|
|
55
|
+
readonly href: string;
|
|
56
|
+
readonly internal: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface ExtractImage {
|
|
59
|
+
readonly src: string;
|
|
60
|
+
readonly alt: string | null;
|
|
61
|
+
readonly role: string | null;
|
|
62
|
+
}
|
|
63
|
+
export interface ExtractFormField {
|
|
64
|
+
readonly type: string;
|
|
65
|
+
readonly name: string | null;
|
|
66
|
+
readonly required: boolean;
|
|
67
|
+
}
|
|
68
|
+
export interface ExtractForm {
|
|
69
|
+
readonly action: string | null;
|
|
70
|
+
readonly method: string;
|
|
71
|
+
readonly fields: readonly ExtractFormField[];
|
|
72
|
+
}
|
|
73
|
+
export interface ExtractStructure {
|
|
74
|
+
readonly headings: readonly ExtractHeading[];
|
|
75
|
+
readonly sections: readonly ExtractSection[];
|
|
76
|
+
readonly nav_links: readonly ExtractLink[];
|
|
77
|
+
readonly forms: readonly ExtractForm[];
|
|
78
|
+
}
|
|
79
|
+
export interface ExtractContent {
|
|
80
|
+
readonly main_html: string;
|
|
81
|
+
readonly main_text: string;
|
|
82
|
+
readonly images: readonly ExtractImage[];
|
|
83
|
+
readonly links: {
|
|
84
|
+
readonly internal: readonly ExtractLink[];
|
|
85
|
+
readonly external: readonly ExtractLink[];
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export interface ExtractStyles {
|
|
89
|
+
readonly css: string;
|
|
90
|
+
readonly inline_styles_count: number;
|
|
91
|
+
}
|
|
92
|
+
export interface PaletteEntry {
|
|
93
|
+
readonly hex: string;
|
|
94
|
+
readonly weight: number;
|
|
95
|
+
readonly role: "background" | "text" | "accent" | "other";
|
|
96
|
+
}
|
|
97
|
+
export interface ComponentStyle {
|
|
98
|
+
readonly count: number;
|
|
99
|
+
readonly bg: string | null;
|
|
100
|
+
readonly fg: string | null;
|
|
101
|
+
readonly border: string | null;
|
|
102
|
+
readonly radius: string | null;
|
|
103
|
+
readonly padding: string | null;
|
|
104
|
+
readonly font_size: string | null;
|
|
105
|
+
readonly font_weight: string | null;
|
|
106
|
+
}
|
|
107
|
+
export interface VisualSignature {
|
|
108
|
+
readonly colors: {
|
|
109
|
+
readonly palette: readonly PaletteEntry[];
|
|
110
|
+
readonly background: string | null;
|
|
111
|
+
readonly text: string | null;
|
|
112
|
+
readonly primary: string | null;
|
|
113
|
+
readonly link: string | null;
|
|
114
|
+
};
|
|
115
|
+
readonly typography: {
|
|
116
|
+
readonly heading_font: string | null;
|
|
117
|
+
readonly body_font: string | null;
|
|
118
|
+
readonly size_scale: readonly number[];
|
|
119
|
+
readonly base_size_px: number | null;
|
|
120
|
+
readonly base_line_height: number | null;
|
|
121
|
+
};
|
|
122
|
+
readonly radii: {
|
|
123
|
+
readonly button: string | null;
|
|
124
|
+
readonly input: string | null;
|
|
125
|
+
readonly card: string | null;
|
|
126
|
+
};
|
|
127
|
+
readonly spacing: {
|
|
128
|
+
readonly base_unit_px: number | null;
|
|
129
|
+
readonly common_gaps_px: readonly number[];
|
|
130
|
+
};
|
|
131
|
+
readonly layout: {
|
|
132
|
+
readonly max_content_width_px: number | null;
|
|
133
|
+
readonly mode: "flex" | "grid" | "block" | null;
|
|
134
|
+
};
|
|
135
|
+
readonly components: {
|
|
136
|
+
readonly buttons: readonly ComponentStyle[];
|
|
137
|
+
readonly inputs: readonly ComponentStyle[];
|
|
138
|
+
readonly cards: readonly ComponentStyle[];
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export interface ExtractIconDeclaration {
|
|
142
|
+
/** href as written in the HTML (relative or absolute). */
|
|
143
|
+
readonly href: string;
|
|
144
|
+
/** rel value, lowercased: "icon", "apple-touch-icon", "shortcut icon", ... */
|
|
145
|
+
readonly rel: string;
|
|
146
|
+
/** Declared `sizes` attribute, e.g. "180x180" or "any" or null. */
|
|
147
|
+
readonly sizes: string | null;
|
|
148
|
+
/** Declared mime type, e.g. "image/svg+xml" or null. */
|
|
149
|
+
readonly type: string | null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Logo asset resolved server-side. The Lambda picks the best
|
|
153
|
+
* symbol-only asset available on the page — declared <link rel="icon"|
|
|
154
|
+
* "apple-touch-icon"> declarations + conventional well-known paths
|
|
155
|
+
* (/apple-touch-icon.png, /favicon.svg, /favicon.ico) — in that
|
|
156
|
+
* order of expected quality. Null when nothing resolves.
|
|
157
|
+
*
|
|
158
|
+
* Favicons are symbol-only by construction (no designer ships a
|
|
159
|
+
* wordmark inside a 16-180 px icon), which sidesteps the
|
|
160
|
+
* lockup-vs-symbol problem callers used to handle client-side with
|
|
161
|
+
* a vision model.
|
|
162
|
+
*/
|
|
163
|
+
export interface ExtractLogo {
|
|
164
|
+
/** Absolute URL of the asset that was successfully fetched. */
|
|
165
|
+
readonly url: string;
|
|
166
|
+
/** Which source produced the winner. */
|
|
167
|
+
readonly source: "link-icon-svg" | "link-apple-touch-icon" | "link-icon-large" | "link-icon" | "link-shortcut-icon" | "well-known-apple-180" | "well-known-apple" | "well-known-svg" | "well-known-png-large" | "well-known-ico";
|
|
168
|
+
readonly content_type: string;
|
|
169
|
+
readonly size_bytes: number;
|
|
170
|
+
/** Base64-encoded asset bytes (no `data:` prefix). Build a data
|
|
171
|
+
* URI with `data:${content_type};base64,${base64}`. */
|
|
172
|
+
readonly base64: string;
|
|
173
|
+
}
|
|
174
|
+
export interface ExtractData {
|
|
175
|
+
readonly url: string;
|
|
176
|
+
readonly final_url: string;
|
|
177
|
+
readonly fetched_at: string;
|
|
178
|
+
readonly render_ms: number;
|
|
179
|
+
readonly meta: ExtractMeta;
|
|
180
|
+
readonly structure: ExtractStructure;
|
|
181
|
+
readonly content: ExtractContent;
|
|
182
|
+
readonly styles: ExtractStyles;
|
|
183
|
+
readonly visual_signature: VisualSignature;
|
|
184
|
+
/**
|
|
185
|
+
* Best logo asset resolved by the lambda — null when no
|
|
186
|
+
* <link rel="icon"> declaration and no conventional favicon
|
|
187
|
+
* path produced a usable image. Callers should then let the
|
|
188
|
+
* operator upload the logo manually rather than treat this as
|
|
189
|
+
* a fatal error.
|
|
190
|
+
*/
|
|
191
|
+
readonly logo: ExtractLogo | null;
|
|
192
|
+
}
|
|
193
|
+
export interface ExtractResult {
|
|
194
|
+
/** Cleaned extraction payload. */
|
|
195
|
+
readonly data: ExtractData;
|
|
196
|
+
/** Microcredits charged for this call (1 on success, 0 on refunded failures). */
|
|
197
|
+
readonly creditsCharged: number;
|
|
198
|
+
/** Wallet balance after the (possibly refunded) debit. */
|
|
199
|
+
readonly walletBalance: number;
|
|
200
|
+
/** Audit log id for traceability. */
|
|
201
|
+
readonly auditId: string;
|
|
202
|
+
}
|
|
203
|
+
export interface FetchAssetArgs {
|
|
204
|
+
/** Absolute http(s) URL of the asset to fetch. */
|
|
205
|
+
readonly url: string;
|
|
206
|
+
/** Mandate id under which this call should be attributed. */
|
|
207
|
+
readonly mandateId?: string;
|
|
208
|
+
/** Abort signal. */
|
|
209
|
+
readonly signal?: AbortSignal;
|
|
210
|
+
}
|
|
211
|
+
export interface FetchAssetResult {
|
|
212
|
+
/** Asset payload. */
|
|
213
|
+
readonly data: {
|
|
214
|
+
/** URL we asked the proxy to fetch. */
|
|
215
|
+
readonly url: string;
|
|
216
|
+
/** URL after the proxy followed any redirects. */
|
|
217
|
+
readonly final_url: string;
|
|
218
|
+
/** Content-Type reported by the upstream server. */
|
|
219
|
+
readonly content_type: string;
|
|
220
|
+
/** Size of the fetched body in bytes. */
|
|
221
|
+
readonly size_bytes: number;
|
|
222
|
+
/** Base64-encoded body (no `data:` prefix). Build a data URI
|
|
223
|
+
* with `data:${content_type};base64,${base64}`. */
|
|
224
|
+
readonly base64: string;
|
|
225
|
+
};
|
|
226
|
+
/** Microcredits charged for this call. */
|
|
227
|
+
readonly creditsCharged: number;
|
|
228
|
+
readonly walletBalance: number;
|
|
229
|
+
readonly auditId: string;
|
|
230
|
+
}
|
|
231
|
+
export interface WebNamespaceDeps {
|
|
232
|
+
readonly auth: AithosAuth;
|
|
233
|
+
readonly appDid: string;
|
|
234
|
+
readonly endpoints: AithosSdkEndpoints;
|
|
235
|
+
readonly fetch: typeof fetch;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* `sdk.web` namespace — Aithos's web extraction primitive.
|
|
239
|
+
*
|
|
240
|
+
* Designed so a downstream agent can read the static content of any
|
|
241
|
+
* public page (HTML, purged CSS, computed visual signature) without
|
|
242
|
+
* involving an LLM — saving ~30× over a Bedrock-based extraction in
|
|
243
|
+
* both latency and cost.
|
|
244
|
+
*
|
|
245
|
+
* @throws {AithosSDKError} — same error taxonomy as `sdk.compute`,
|
|
246
|
+
* including `-32071` (insufficient balance with `{required, available}`
|
|
247
|
+
* in `data`) and `-32042` (mandate scope mismatch).
|
|
248
|
+
*/
|
|
249
|
+
export declare class WebNamespace {
|
|
250
|
+
#private;
|
|
251
|
+
constructor(deps: WebNamespaceDeps);
|
|
252
|
+
/**
|
|
253
|
+
* Extract a public webpage. Returns the cleaned HTML, purged CSS and
|
|
254
|
+
* a deterministic visual signature (palette, typography, dominant
|
|
255
|
+
* radii, spacing, layout mode, component digests).
|
|
256
|
+
*/
|
|
257
|
+
extract(args: ExtractArgs): Promise<ExtractResult>;
|
|
258
|
+
/**
|
|
259
|
+
* Fetch a single asset (image / font / css / json …) server-side,
|
|
260
|
+
* bypassing browser CORS. Returns the bytes as base64 + content-type.
|
|
261
|
+
*
|
|
262
|
+
* Use when `fetch(url, {mode: "cors"})` and `<img crossOrigin>`
|
|
263
|
+
* canvas readback both fail because the asset server doesn't return
|
|
264
|
+
* Access-Control-Allow-Origin headers — typical for production
|
|
265
|
+
* sites' logos hosted on the main domain.
|
|
266
|
+
*
|
|
267
|
+
* For the common "logo of a webpage" case the lambda already
|
|
268
|
+
* resolves and embeds the best symbol-only logo in
|
|
269
|
+
* {@link extract}'s `data.logo` field; you only need fetchAsset
|
|
270
|
+
* when extract's logo doesn't fit, when picking up secondary
|
|
271
|
+
* assets (og:image, hero image, document download), or when
|
|
272
|
+
* fetching an asset on a page you haven't extracted.
|
|
273
|
+
*
|
|
274
|
+
* Costs 1 mc per successful fetch, full refund on failure. Server
|
|
275
|
+
* caps: 15 s timeout, 10 MB body, http/https only.
|
|
276
|
+
*/
|
|
277
|
+
fetchAsset(args: FetchAssetArgs): Promise<FetchAssetResult>;
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=web.d.ts.map
|