@ambasada/village 0.8.1 → 0.8.2
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/client.d.ts +1 -1
- package/dist/define.d.ts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +36 -673
- package/dist/receipt.d.ts +1 -1
- package/dist/webhook.d.ts +1 -1
- package/package.json +5 -3
- package/dist/sdk/apps.d.ts +0 -110
- package/dist/sdk/auth.d.ts +0 -132
- package/dist/sdk/client.d.ts +0 -106
- package/dist/sdk/define.d.ts +0 -19
- package/dist/sdk/errors.d.ts +0 -94
- package/dist/sdk/headers.d.ts +0 -3
- package/dist/sdk/platform.d.ts +0 -20
- package/dist/sdk/types.d.ts +0 -40
package/dist/receipt.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* by the village, committing to the buyer, seller, offering, amount and the SHA-256 of the exact body.
|
|
4
4
|
* The seller checks it offline against `<api>/.well-known/jwks.json` (cached), no round-trip.
|
|
5
5
|
*/
|
|
6
|
-
import { type HeaderSource, type Jwk } from "
|
|
6
|
+
import { type HeaderSource, type Jwk } from "@ambasada/sdk/platform";
|
|
7
7
|
import type { CheckoutReceiptClaims, ReceiptClaims } from "./types.js";
|
|
8
8
|
export declare const RECEIPT_HEADER = "x-village-receipt";
|
|
9
9
|
export type KeySource = Jwk[] | (() => Promise<Jwk[]>);
|
package/dist/webhook.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* This module wraps the protocol functions with the SDK's error type and event shape.
|
|
10
10
|
*/
|
|
11
|
-
import { type HeaderSource } from "
|
|
11
|
+
import { type HeaderSource } from "@ambasada/sdk/platform";
|
|
12
12
|
import type { WebhookEvent } from "./types.js";
|
|
13
13
|
/** The three Standard Webhooks headers. */
|
|
14
14
|
export declare const WEBHOOK_HEADERS: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ambasada/village",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "The Hack A Ton add-on for Ambasada apps: TON checkout, receipts, offerings, LLM, the agent, the market; CLI commands and the local bank.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,14 +26,16 @@
|
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">=22"
|
|
28
28
|
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@ambasada/sdk": "^0.8.2"
|
|
31
|
+
},
|
|
29
32
|
"devDependencies": {
|
|
30
33
|
"@types/node": "^22.20.5",
|
|
31
34
|
"esbuild": "^0.28.2",
|
|
32
35
|
"typescript": "~5.9.3",
|
|
33
36
|
"vitest": "^4.1.12",
|
|
34
37
|
"@ambasada/protocol": "0.1.0",
|
|
35
|
-
"@ambasada/
|
|
36
|
-
"@ambasada/cli": "0.8.1"
|
|
38
|
+
"@ambasada/cli": "0.8.2"
|
|
37
39
|
},
|
|
38
40
|
"author": "CENTYSO (https://centyso.com)",
|
|
39
41
|
"homepage": "https://ambasada.id",
|
package/dist/sdk/apps.d.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Notifications for every mini app (docs/MINI-APPS.md §7). The hub tells your app who turned notifications
|
|
3
|
-
* on through a signed webhook; you keep `token ↔ your user` and send with that token:
|
|
4
|
-
*
|
|
5
|
-
* POST /api/ambasada/webhook → const event = await ambasada.apps.verifyWebhook(req) // AppEvent
|
|
6
|
-
* if (event.event === "notifications_enabled") save(event.user, event.token)
|
|
7
|
-
* anywhere → await ambasada.apps.notify({ notification_id, title, body, url, tokens: [token] })
|
|
8
|
-
*
|
|
9
|
-
* The app secret signs both directions: `AMBASADA_APP_SECRET` (the deploy injects it on ambasada.dev; the hub
|
|
10
|
-
* dashboard shows it for apps hosted elsewhere; `ambasada dev` sets a fake one and plays the hub).
|
|
11
|
-
* WebCrypto only; the wire format is in @ambasada/protocol (packages/protocol/src/apps.ts).
|
|
12
|
-
*/
|
|
13
|
-
import type { HeaderSource } from "./headers.js";
|
|
14
|
-
export declare const APP_SIGNATURE_HEADER = "x-ambasada-signature";
|
|
15
|
-
export declare const APP_TIMESTAMP_HEADER = "x-ambasada-timestamp";
|
|
16
|
-
export type AppEventType = "notifications_enabled" | "notifications_disabled" | "app_added" | "app_removed" | "ping";
|
|
17
|
-
/** What the hub POSTs to your webhook. `token` comes with notifications_enabled (and app_added when notifications are on). */
|
|
18
|
-
export type AppEvent = {
|
|
19
|
-
event: "notifications_enabled";
|
|
20
|
-
app: string;
|
|
21
|
-
token: string;
|
|
22
|
-
user: string;
|
|
23
|
-
at: string;
|
|
24
|
-
} | {
|
|
25
|
-
event: "notifications_disabled";
|
|
26
|
-
app: string;
|
|
27
|
-
user: string;
|
|
28
|
-
token?: string;
|
|
29
|
-
at: string;
|
|
30
|
-
} | {
|
|
31
|
-
event: "app_added";
|
|
32
|
-
app: string;
|
|
33
|
-
user: string;
|
|
34
|
-
token?: string;
|
|
35
|
-
at: string;
|
|
36
|
-
} | {
|
|
37
|
-
event: "app_removed";
|
|
38
|
-
app: string;
|
|
39
|
-
user: string;
|
|
40
|
-
token?: string;
|
|
41
|
-
at: string;
|
|
42
|
-
} | {
|
|
43
|
-
event: "ping";
|
|
44
|
-
app: string;
|
|
45
|
-
at: string;
|
|
46
|
-
};
|
|
47
|
-
export type NotificationCategory = "transactional" | "social" | "marketing";
|
|
48
|
-
export interface AppNotifyInput {
|
|
49
|
-
/** ≤ 128; (person, id) is deduped by the hub for 24 h. */
|
|
50
|
-
notification_id: string;
|
|
51
|
-
/** ≤ 40: the whole headline. */
|
|
52
|
-
title: string;
|
|
53
|
-
/** ≤ 140. */
|
|
54
|
-
body: string;
|
|
55
|
-
/** A path on your app (`/orders/184`) or a URL on its origin. */
|
|
56
|
-
url: string;
|
|
57
|
-
/** Notification tokens from `notifications_enabled`, ≤ 100 per call. */
|
|
58
|
-
tokens?: string[];
|
|
59
|
-
/** Ambasada user ids, for Verified apps with the identity scope. */
|
|
60
|
-
users?: string[];
|
|
61
|
-
/** Default "transactional", the only one Listed apps may send. */
|
|
62
|
-
category?: NotificationCategory;
|
|
63
|
-
/** Replaces an earlier unread push with the same key. */
|
|
64
|
-
collapse_key?: string;
|
|
65
|
-
ttl_seconds?: number;
|
|
66
|
-
}
|
|
67
|
-
export interface AppNotifyResult {
|
|
68
|
-
sent: string[];
|
|
69
|
-
/** Gone (the person turned notifications off or removed the app): forget them. */
|
|
70
|
-
invalid: string[];
|
|
71
|
-
rate_limited: string[];
|
|
72
|
-
}
|
|
73
|
-
/** The `x-ambasada-signature` value for a delivery (`v1=<hex>`): for tests and your own fake hub. */
|
|
74
|
-
export declare const signAppWebhook: (secret: string, timestamp: number, body: string) => Promise<string>;
|
|
75
|
-
/** Timestamp + signature headers for `body`, as the hub sends them. */
|
|
76
|
-
export declare const appWebhookHeaders: (secret: string, body: string, timestamp?: number) => Promise<Record<string, string>>;
|
|
77
|
-
export interface AppsConfig {
|
|
78
|
-
/** `AMBASADA_APP_SECRET`. */
|
|
79
|
-
appSecret?: string;
|
|
80
|
-
/** `AMBASADA_HUB_URL`, else https://hub.ambasada.id. */
|
|
81
|
-
hubUrl?: string;
|
|
82
|
-
/** Your app's origin, for the same-origin `url` rule: `AMBASADA_APP_ORIGIN`, else `PUBLIC_URL`. */
|
|
83
|
-
origin?: string;
|
|
84
|
-
fetch?: typeof fetch;
|
|
85
|
-
}
|
|
86
|
-
/** A fetch `Request`, or the raw body and headers exactly as received. */
|
|
87
|
-
export type WebhookInput = Request | {
|
|
88
|
-
body: string | Uint8Array;
|
|
89
|
-
headers: HeaderSource;
|
|
90
|
-
};
|
|
91
|
-
export declare class AmbasadaApps {
|
|
92
|
-
private readonly config;
|
|
93
|
-
constructor(config: () => AppsConfig);
|
|
94
|
-
/** True when the app has its secret (hosted on ambasada.dev, `ambasada dev`, or set by hand). */
|
|
95
|
-
get configured(): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Verifies a webhook from the hub (signature, 5-minute window) and returns the event, or throws
|
|
98
|
-
* `WebhookInvalidError` (answer it with `error.toResponse()`, a 400). Read nothing from the request before.
|
|
99
|
-
*/
|
|
100
|
-
verifyWebhook(input: WebhookInput, secret?: string, options?: {
|
|
101
|
-
toleranceSeconds?: number;
|
|
102
|
-
now?: number;
|
|
103
|
-
}): Promise<AppEvent>;
|
|
104
|
-
/**
|
|
105
|
-
* Sends a push to the people behind `tokens` (or `users`, for Verified apps with `identity`) through the hub.
|
|
106
|
-
* Checks the limits first (title ≤ 40, body ≤ 140, id ≤ 128, ≤ 100 recipients, `url` on your origin) and
|
|
107
|
-
* throws `AmbasadaError("INVALID_REQUEST")` before sending anything. Tokens in `invalid` are gone: forget them.
|
|
108
|
-
*/
|
|
109
|
-
notify(input: AppNotifyInput): Promise<AppNotifyResult>;
|
|
110
|
-
}
|
package/dist/sdk/auth.d.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* "Sign in with Ambasada" (docs/AUTH.md): OAuth 2.0 authorization code + PKCE against Ambasada ID,
|
|
3
|
-
* for products hosted at https://<slug>.ambasada.dev. The deploy injects AMBASADA_AUTH_CLIENT_ID,
|
|
4
|
-
* AMBASADA_AUTH_CLIENT_SECRET and AMBASADA_AUTH_ISSUER; `ambasada dev` injects fake ones that point at
|
|
5
|
-
* the mock. Four fetch handlers, WebCrypto only, no dependencies:
|
|
6
|
-
*
|
|
7
|
-
* GET /api/auth/login → return ambasada.auth.login(req, { returnTo: "/" })
|
|
8
|
-
* GET /api/auth/callback → return ambasada.auth.callback(req)
|
|
9
|
-
* GET /api/auth/logout → return ambasada.auth.logout(req)
|
|
10
|
-
* anywhere → const user = await ambasada.auth.user(req) // AmbasadaUser | null
|
|
11
|
-
*
|
|
12
|
-
* The session is an HttpOnly cookie holding the signed public profile (HMAC-SHA256 under a key
|
|
13
|
-
* derived from the client secret), host-only (`__Host-` on https), so no other *.ambasada.dev product
|
|
14
|
-
* can read, set or forge it. No access token is kept.
|
|
15
|
-
*
|
|
16
|
-
* Silent sign-in inside the Ambasada app (docs/MINI-APPS.md §5): the page asks the shell for a short-lived
|
|
17
|
-
* token (`auth.getToken()` from @ambasada/miniapp) and POSTs it here; the same session cookie comes back:
|
|
18
|
-
*
|
|
19
|
-
* POST /api/auth/shell { token } → return ambasada.auth.shell(req) // { user } + cookie
|
|
20
|
-
* anywhere → const who = await ambasada.auth.verifyShellToken(token) // { user_id, name, avatar }
|
|
21
|
-
*/
|
|
22
|
-
/** The person signed in, as `GET /v1/auth/profile` returns them. */
|
|
23
|
-
export interface AmbasadaUser {
|
|
24
|
-
/** Ambasada ID user id (`user_…`): stable, use it as your user key. */
|
|
25
|
-
id: string;
|
|
26
|
-
name: string | null;
|
|
27
|
-
avatar_url: string | null;
|
|
28
|
-
/** Has the builder flag on their Ambasada ID. */
|
|
29
|
-
builder: boolean;
|
|
30
|
-
builder_since: string | null;
|
|
31
|
-
member_since: string | null;
|
|
32
|
-
/** Their pass at the current event, if any. */
|
|
33
|
-
pass: "builder" | "visitor" | "staff" | null;
|
|
34
|
-
/** Only when you asked for it (`login(req, { email: true })`) and they agreed. */
|
|
35
|
-
email?: string | null;
|
|
36
|
-
}
|
|
37
|
-
export interface AuthConfig {
|
|
38
|
-
clientId?: string;
|
|
39
|
-
clientSecret?: string;
|
|
40
|
-
issuer?: string;
|
|
41
|
-
/** Who a shell token must be for (`aud`): your app id and origin. The request's origin is added in `shell()`. */
|
|
42
|
-
audiences?: string[];
|
|
43
|
-
/** The hub, for the full profile behind a shell token (`/api/apps/profile`). */
|
|
44
|
-
hubUrl?: string;
|
|
45
|
-
/** Where `/v1/auth/profile` lives (the Ambasada API). */
|
|
46
|
-
apiUrl: string;
|
|
47
|
-
/** Your public origin if the Worker sees another host (behind a proxy). Default: the request's origin. */
|
|
48
|
-
publicUrl?: string;
|
|
49
|
-
fetch?: typeof fetch;
|
|
50
|
-
}
|
|
51
|
-
export interface LoginOptions {
|
|
52
|
-
/** Path on your site to land on after signing in (default "/"). Only same-site paths are honored. */
|
|
53
|
-
returnTo?: string;
|
|
54
|
-
/** Also ask for their email (the consent screen says so). */
|
|
55
|
-
email?: boolean;
|
|
56
|
-
}
|
|
57
|
-
export declare const AUTH_PATHS: {
|
|
58
|
-
readonly login: "/api/auth/login";
|
|
59
|
-
readonly callback: "/api/auth/callback";
|
|
60
|
-
readonly logout: "/api/auth/logout";
|
|
61
|
-
readonly shell: "/api/auth/shell";
|
|
62
|
-
};
|
|
63
|
-
/** How long a sign-in lasts (the cookie holds a profile snapshot; signing in again refreshes it). */
|
|
64
|
-
export declare const SESSION_TTL_S: number;
|
|
65
|
-
export declare function b64url(bytes: Uint8Array): string;
|
|
66
|
-
/** PKCE (RFC 7636): a random verifier and its S256 challenge. */
|
|
67
|
-
export declare function pkce(): Promise<{
|
|
68
|
-
verifier: string;
|
|
69
|
-
challenge: string;
|
|
70
|
-
}>;
|
|
71
|
-
export declare function pkceChallenge(verifier: string): Promise<string>;
|
|
72
|
-
/** `<payload>.<signature>`, both base64url; the payload is JSON with `exp` (seconds). */
|
|
73
|
-
export declare function signCookie(secret: string, purpose: string, payload: Record<string, unknown>): Promise<string>;
|
|
74
|
-
/** The payload if the signature is ours and it has not expired; null otherwise. */
|
|
75
|
-
export declare function verifyCookie<T extends {
|
|
76
|
-
exp: number;
|
|
77
|
-
}>(secret: string, purpose: string, value: string | null | undefined, now?: number): Promise<T | null>;
|
|
78
|
-
/** A fetch `Request`, or anything with its headers (Next: `{ headers: await headers() }`). */
|
|
79
|
-
export type WithHeaders = Pick<Request, "headers">;
|
|
80
|
-
export declare function readCookie(req: WithHeaders, name: string): string | null;
|
|
81
|
-
/**
|
|
82
|
-
* A relative path on this site, or "/". No open redirects: "//evil", "/\\evil", "https://…" are refused, and so is
|
|
83
|
-
* any control character (browsers drop tabs and newlines, so "/\t/evil" would become "//evil").
|
|
84
|
-
*/
|
|
85
|
-
export declare function safeReturnTo(value: string | null | undefined): string;
|
|
86
|
-
/** Who a verified shell token is for. Name and avatar are what Ambasada ID had when the shell minted it. */
|
|
87
|
-
export interface ShellUser {
|
|
88
|
-
user_id: string;
|
|
89
|
-
name: string | null;
|
|
90
|
-
avatar: string | null;
|
|
91
|
-
}
|
|
92
|
-
/** JWKS cache per issuer: 1 hour, refreshed once early when a token names a key we don't have. */
|
|
93
|
-
export declare const JWKS_TTL_MS = 3600000;
|
|
94
|
-
/** For tests. */
|
|
95
|
-
export declare function clearJwksCache(): void;
|
|
96
|
-
export declare class AmbasadaAuth {
|
|
97
|
-
private readonly config;
|
|
98
|
-
constructor(config: () => AuthConfig);
|
|
99
|
-
/** True when the product has credentials (hosted on ambasada.dev, or `ambasada dev`). */
|
|
100
|
-
get configured(): boolean;
|
|
101
|
-
private settings;
|
|
102
|
-
/** Redirects to Ambasada ID (consent screen) with PKCE; a short-lived signed cookie holds the state. */
|
|
103
|
-
login(req: Request, options?: LoginOptions): Promise<Response>;
|
|
104
|
-
/**
|
|
105
|
-
* Ambasada ID sends the person back here: checks the state, exchanges the code (with the PKCE
|
|
106
|
-
* verifier and the client secret), reads their profile from the Ambasada API, sets the session cookie
|
|
107
|
-
* and redirects to `returnTo`. A refused consent goes back to `returnTo` signed out.
|
|
108
|
-
*/
|
|
109
|
-
callback(req: Request): Promise<Response>;
|
|
110
|
-
/** Whoever is signed in on this request, or null (also null when sign-in is not set up). */
|
|
111
|
-
user(req: WithHeaders): Promise<AmbasadaUser | null>;
|
|
112
|
-
/**
|
|
113
|
-
* Verifies a shell token (Clerk JWT template `ambasada-miniapp`, RS256, 60 s) against
|
|
114
|
-
* `<AMBASADA_AUTH_ISSUER>/.well-known/jwks.json` (cached 1 h): signature, expiry, issuer, and that its `aud`
|
|
115
|
-
* is this app (its id or origin). Returns who it is, or throws `AmbasadaError("UNAUTHORIZED")`.
|
|
116
|
-
*/
|
|
117
|
-
verifyShellToken(token: string, options?: {
|
|
118
|
-
audience?: string | string[];
|
|
119
|
-
now?: number;
|
|
120
|
-
}): Promise<ShellUser>;
|
|
121
|
-
/**
|
|
122
|
-
* Silent sign-in: `POST /api/auth/shell` with `{ "token": "<auth.getToken() token>" }` (or `Authorization: Bearer`).
|
|
123
|
-
* Verifies it, reads the full profile from the hub (falling back to what the token carries) and sets the same
|
|
124
|
-
* session cookie as `callback()`, so a person signed in inside the app and one signed in on the web look the same.
|
|
125
|
-
* Answers `{ user }`.
|
|
126
|
-
*/
|
|
127
|
-
shell(req: Request): Promise<Response>;
|
|
128
|
-
/** Clears the session and redirects to `returnTo` (default "/"). Signs out of this product only. */
|
|
129
|
-
logout(req: Request, options?: {
|
|
130
|
-
returnTo?: string;
|
|
131
|
-
}): Response;
|
|
132
|
-
}
|
package/dist/sdk/client.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { AmbasadaApps } from "./apps.js";
|
|
2
|
-
import { AmbasadaAuth } from "./auth.js";
|
|
3
|
-
import type { FileOptions, Jwk, StoredFile, StoreList, StoreWrite } from "./types.js";
|
|
4
|
-
export declare const DEFAULT_API_URL = "https://api.ambasada.dev";
|
|
5
|
-
export interface AmbasadaOptions {
|
|
6
|
-
/** Project key (`vk_…` from developer.ambasada.dev, or `ambasada login`). Default: `AMBASADA_API_KEY`. */
|
|
7
|
-
apiKey?: string;
|
|
8
|
-
/** Default: `AMBASADA_API_URL`, else https://api.ambasada.dev. `ambasada dev` serves http://localhost:8788. */
|
|
9
|
-
apiUrl?: string;
|
|
10
|
-
/** Your app's id. Default: `AMBASADA_APP_ID`, else looked up once with the API key. */
|
|
11
|
-
project?: string;
|
|
12
|
-
/** Signing keys; default: `<apiUrl>/.well-known/jwks.json`, cached 10 minutes. */
|
|
13
|
-
keys?: Jwk[] | (() => Promise<Jwk[]>);
|
|
14
|
-
/** Custom fetch (tests, proxies). */
|
|
15
|
-
fetch?: typeof fetch;
|
|
16
|
-
/** Per-request timeout in ms (default 45 s). */
|
|
17
|
-
timeoutMs?: number;
|
|
18
|
-
/** Extra env source, e.g. a Worker's `env`. Default: `process.env` where it exists. */
|
|
19
|
-
env?: Record<string, unknown>;
|
|
20
|
-
/** Sign in with Ambasada credentials. Default: `AMBASADA_AUTH_CLIENT_ID`, `_CLIENT_SECRET`, `_ISSUER`, and `PUBLIC_URL`. */
|
|
21
|
-
auth?: {
|
|
22
|
-
clientId?: string;
|
|
23
|
-
clientSecret?: string;
|
|
24
|
-
issuer?: string;
|
|
25
|
-
publicUrl?: string;
|
|
26
|
-
};
|
|
27
|
-
/** Mini-app platform (notifications). Default: `AMBASADA_APP_SECRET`, `AMBASADA_HUB_URL`, `AMBASADA_APP_ORIGIN` (else `PUBLIC_URL`). */
|
|
28
|
-
app?: {
|
|
29
|
-
secret?: string;
|
|
30
|
-
hubUrl?: string;
|
|
31
|
-
origin?: string;
|
|
32
|
-
id?: string;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export type Method = "GET" | "POST" | "PUT" | "DELETE";
|
|
36
|
-
export interface RequestOptions {
|
|
37
|
-
body?: unknown;
|
|
38
|
-
raw?: NonNullable<RequestInit["body"]>;
|
|
39
|
-
headers?: Record<string, string | undefined>;
|
|
40
|
-
query?: Record<string, string | number | undefined>;
|
|
41
|
-
auth?: boolean;
|
|
42
|
-
signal?: AbortSignal;
|
|
43
|
-
/** Retry once on a network error (only safe with an idempotency key). */
|
|
44
|
-
retry?: boolean;
|
|
45
|
-
}
|
|
46
|
-
export interface RawResponse {
|
|
47
|
-
status: number;
|
|
48
|
-
headers: Headers;
|
|
49
|
-
json: unknown;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* The Ambasada client. `import { ambasada } from "@ambasada/sdk"` gives one configured from the
|
|
53
|
-
* environment; `createAmbasada({ env })` makes another (e.g. from a Worker's `env`).
|
|
54
|
-
*/
|
|
55
|
-
export declare class Ambasada {
|
|
56
|
-
protected readonly options: AmbasadaOptions;
|
|
57
|
-
private keyLoader?;
|
|
58
|
-
private projectPromise?;
|
|
59
|
-
constructor(options?: AmbasadaOptions);
|
|
60
|
-
protected env(name: string): string | undefined;
|
|
61
|
-
get apiUrl(): string;
|
|
62
|
-
protected get apiKey(): string;
|
|
63
|
-
/**
|
|
64
|
-
* Sign in with Ambasada (docs/AUTH.md): `login(req)`, `callback(req)`, `user(req)`, `logout(req)`.
|
|
65
|
-
* Credentials come with the deploy to ambasada.dev, and from `ambasada dev` locally.
|
|
66
|
-
*/
|
|
67
|
-
readonly auth: AmbasadaAuth;
|
|
68
|
-
private get appOrigin();
|
|
69
|
-
private get hubUrl();
|
|
70
|
-
/**
|
|
71
|
-
* The mini-app platform (docs/MINI-APPS.md §7): `verifyWebhook(req)` for the hub's app events and
|
|
72
|
-
* `notify({ … })` to push to people who turned notifications on. Uses `AMBASADA_APP_SECRET`.
|
|
73
|
-
*/
|
|
74
|
-
readonly apps: AmbasadaApps;
|
|
75
|
-
protected send(method: Method, path: string, opts?: RequestOptions): Promise<RawResponse>;
|
|
76
|
-
protected call<T>(method: Method, path: string, opts?: RequestOptions): Promise<T>;
|
|
77
|
-
/** Your app's id (from options, `AMBASADA_APP_ID`, or the project the API key belongs to). */
|
|
78
|
-
project(): Promise<string>;
|
|
79
|
-
/** The API's signing keys (`/.well-known/jwks.json`, cached). */
|
|
80
|
-
keys(): Promise<Jwk[]>;
|
|
81
|
-
readonly files: {
|
|
82
|
-
/**
|
|
83
|
-
* Stores bytes, a Blob, or a URL to copy (`POST /v1/files`). Returns a public URL. For an app's own
|
|
84
|
-
* uploads prefer its bucket, `env.FILES` (docs/STORAGE.md).
|
|
85
|
-
*/
|
|
86
|
-
put: (data: Uint8Array | ArrayBuffer | Blob | string, options?: FileOptions) => Promise<StoredFile>;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Your project's JSON key-value store (`/v1/store`): 1 MB per project (keys + values), free. For more,
|
|
90
|
-
* use the app's own D1, KV and R2 (docs/STORAGE.md).
|
|
91
|
-
*/
|
|
92
|
-
readonly store: {
|
|
93
|
-
/** The value, or null when the key is not set. */
|
|
94
|
-
get: <T = unknown>(key: string) => Promise<T | null>;
|
|
95
|
-
/** Saves any JSON value (fails with INVALID_REQUEST when the store would pass 1 MB). */
|
|
96
|
-
set: (key: string, value: unknown) => Promise<StoreWrite>;
|
|
97
|
-
/** `set` under its other name. */
|
|
98
|
-
put: (key: string, value: unknown) => Promise<StoreWrite>;
|
|
99
|
-
/** True when the key existed. */
|
|
100
|
-
delete: (key: string) => Promise<boolean>;
|
|
101
|
-
/** Keys (up to 1000, optionally under a prefix) and how much of the 1 MB is used. */
|
|
102
|
-
list: (prefix?: string) => Promise<StoreList>;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
export declare function cachedKeys(load: () => Promise<Jwk[]>, ttlMs?: number): () => Promise<Jwk[]>;
|
|
106
|
-
export declare function createAmbasada(options?: AmbasadaOptions): Ambasada;
|
package/dist/sdk/define.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `ambasada.config.ts` (docs/PLATFORM.md §3). Types and checks only; the CLI reads the values
|
|
3
|
-
* (`ambasada dev`, `deploy`, `link`, `check`). Add-ons add their own keys (the village: `idea`, `offerings`, `agent`).
|
|
4
|
-
*/
|
|
5
|
-
export interface AppConfig {
|
|
6
|
-
/** The app's slug (lowercase): it lives at https://<id>.ambasada.dev. */
|
|
7
|
-
id: string;
|
|
8
|
-
/** Display name. */
|
|
9
|
-
name: string;
|
|
10
|
-
/** One line about the app: the manifest's subtitle and description (`ambasada init` writes them from it). */
|
|
11
|
-
description?: string;
|
|
12
|
-
/** Where the app runs; `ambasada link` sets it when you host elsewhere. */
|
|
13
|
-
product?: {
|
|
14
|
-
url?: string;
|
|
15
|
-
};
|
|
16
|
-
/** Add-ons to load besides the ones found in node_modules (package names, e.g. "@ambasada/village"). */
|
|
17
|
-
addons?: string[];
|
|
18
|
-
}
|
|
19
|
-
export declare function defineApp<T extends AppConfig>(config: T): T;
|
package/dist/sdk/errors.d.ts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Typed errors. Every Ambasada API failure is `{ "error": { "code", "message", ... } }` with a code
|
|
3
|
-
* from `@ambasada/protocol` (packages/protocol/src/errors.ts); the SDK turns it into an `AmbasadaError`
|
|
4
|
-
* with the same `code`, so you branch on `error.code` instead of parsing messages:
|
|
5
|
-
*
|
|
6
|
-
* try { await ambasada.store.set("settings", value) }
|
|
7
|
-
* catch (e) { if (isAmbasadaError(e, "INVALID_REQUEST")) … }
|
|
8
|
-
*
|
|
9
|
-
* The list mirrors the protocol (a unit test keeps them in sync), plus codes the in-flight API
|
|
10
|
-
* streams add (checkout, utilities, agent) and a few SDK-side ones (`NETWORK`, `CONFIG`,
|
|
11
|
-
* `RECEIPT_INVALID`, `WEBHOOK_INVALID`).
|
|
12
|
-
*/
|
|
13
|
-
export declare const ERROR_STATUS: {
|
|
14
|
-
readonly INSUFFICIENT_FUNDS: 402;
|
|
15
|
-
readonly OFFLINE: 503;
|
|
16
|
-
readonly TIMEOUT: 504;
|
|
17
|
-
readonly SCHEMA_INVALID: 502;
|
|
18
|
-
readonly CAP_BUYER_HOURLY: 429;
|
|
19
|
-
readonly CAP_SELLER_RATE: 429;
|
|
20
|
-
readonly DEAL_EXHAUSTED: 409;
|
|
21
|
-
readonly DEPTH_EXCEEDED: 422;
|
|
22
|
-
readonly BUDGET_EXCEEDED: 402;
|
|
23
|
-
readonly UPSTREAM_ERROR: 502;
|
|
24
|
-
readonly PRICE_ABOVE_MAX: 409;
|
|
25
|
-
readonly SELF_PURCHASE: 403;
|
|
26
|
-
readonly INVALID_REQUEST: 400;
|
|
27
|
-
readonly UNAUTHORIZED: 401;
|
|
28
|
-
readonly NOT_FOUND: 404;
|
|
29
|
-
readonly CONFLICT: 409;
|
|
30
|
-
readonly IDEMPOTENCY_CONFLICT: 422;
|
|
31
|
-
readonly IDEMPOTENCY_IN_PROGRESS: 409;
|
|
32
|
-
readonly HOLD_NOT_ACTIVE: 409;
|
|
33
|
-
readonly INTERNAL: 500;
|
|
34
|
-
readonly CAP_PER_PAYMENT: 403;
|
|
35
|
-
readonly CAP_BUYER_DAILY: 429;
|
|
36
|
-
readonly CAP_PAYEE_DAILY: 429;
|
|
37
|
-
readonly CAP_VISITOR_DAILY: 429;
|
|
38
|
-
readonly APPROVAL_REQUIRED: 403;
|
|
39
|
-
readonly APPROVAL_INVALID: 403;
|
|
40
|
-
readonly APPROVALS_PENDING: 429;
|
|
41
|
-
readonly PROVIDER_BUDGET: 503;
|
|
42
|
-
readonly PROVIDER_DENIED: 502;
|
|
43
|
-
readonly FROZEN: 403;
|
|
44
|
-
readonly CAP_INBOX_RATE: 429;
|
|
45
|
-
readonly NETWORK: 0;
|
|
46
|
-
readonly CONFIG: 0;
|
|
47
|
-
readonly RECEIPT_INVALID: 402;
|
|
48
|
-
readonly WEBHOOK_INVALID: 400;
|
|
49
|
-
};
|
|
50
|
-
/** A known error code. Servers may add codes before the SDK knows them, so `code` is `ErrorCode | string`. */
|
|
51
|
-
export type ErrorCode = keyof typeof ERROR_STATUS;
|
|
52
|
-
export interface ErrorDetails {
|
|
53
|
-
/** Present on Pay errors once a call id was assigned. */
|
|
54
|
-
call_id?: string;
|
|
55
|
-
/** Always false on Pay errors: a failed call never moves money. */
|
|
56
|
-
charged?: false;
|
|
57
|
-
/** True when funds had been held for the call and were released. */
|
|
58
|
-
refunded?: boolean;
|
|
59
|
-
/** HTTP status the seller returned, for UPSTREAM_ERROR / SCHEMA_INVALID. */
|
|
60
|
-
upstream_status?: number;
|
|
61
|
-
/** APPROVAL_REQUIRED: retry with `{ approval: approvalId }` once the team approved it. */
|
|
62
|
-
approval_id?: string;
|
|
63
|
-
[key: string]: unknown;
|
|
64
|
-
}
|
|
65
|
-
export declare class AmbasadaError extends Error {
|
|
66
|
-
readonly code: ErrorCode | (string & {});
|
|
67
|
-
/** HTTP status (0 when the request never got an answer). */
|
|
68
|
-
readonly status: number;
|
|
69
|
-
readonly details: ErrorDetails;
|
|
70
|
-
constructor(code: ErrorCode | (string & {}), message: string, status?: number, details?: ErrorDetails);
|
|
71
|
-
/** `instanceof AmbasadaError` holds across bundled copies; subclasses keep the usual prototype check. */
|
|
72
|
-
static [Symbol.hasInstance](value: unknown): boolean;
|
|
73
|
-
get callId(): string | undefined;
|
|
74
|
-
get refunded(): boolean;
|
|
75
|
-
get approvalId(): string | undefined;
|
|
76
|
-
/** The wire shape, e.g. to pass an error on from your own endpoint. */
|
|
77
|
-
toJSON(): {
|
|
78
|
-
error: {
|
|
79
|
-
code: string;
|
|
80
|
-
message: string;
|
|
81
|
-
} & ErrorDetails;
|
|
82
|
-
};
|
|
83
|
-
/** A `Response` with the wire shape and status (402 for receipt problems). */
|
|
84
|
-
toResponse(): Response;
|
|
85
|
-
}
|
|
86
|
-
export type WebhookFailure = "missing_headers" | "bad_timestamp" | "too_old" | "too_new" | "bad_signature" | "bad_secret" | "bad_body";
|
|
87
|
-
/** A signed webhook (app events, payments) failed its check. */
|
|
88
|
-
export declare class WebhookInvalidError extends AmbasadaError {
|
|
89
|
-
readonly reason: WebhookFailure;
|
|
90
|
-
constructor(reason: WebhookFailure, message: string);
|
|
91
|
-
}
|
|
92
|
-
export declare function isAmbasadaError(value: unknown, code?: ErrorCode | (string & {})): value is AmbasadaError;
|
|
93
|
-
/** Builds an AmbasadaError from an API response body (or a non-JSON failure). */
|
|
94
|
-
export declare function errorFromResponse(status: number, body: unknown, fallback: string): AmbasadaError;
|
package/dist/sdk/headers.d.ts
DELETED
package/dist/sdk/platform.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The platform surface of @ambasada/sdk, without the 0.7 village names (`index.ts` adds those).
|
|
3
|
-
* `@ambasada/village` builds on this module.
|
|
4
|
-
*/
|
|
5
|
-
import { Ambasada } from "./client.js";
|
|
6
|
-
export { Ambasada, createAmbasada, DEFAULT_API_URL } from "./client.js";
|
|
7
|
-
export type { AmbasadaOptions } from "./client.js";
|
|
8
|
-
export * from "./errors.js";
|
|
9
|
-
export type * from "./types.js";
|
|
10
|
-
export { getHeader } from "./headers.js";
|
|
11
|
-
export type { HeaderSource } from "./headers.js";
|
|
12
|
-
export { defineApp } from "./define.js";
|
|
13
|
-
export type { AppConfig } from "./define.js";
|
|
14
|
-
export { AmbasadaAuth, AUTH_PATHS, JWKS_TTL_MS, SESSION_TTL_S } from "./auth.js";
|
|
15
|
-
export type { AmbasadaUser, AuthConfig, LoginOptions, ShellUser, WithHeaders } from "./auth.js";
|
|
16
|
-
export { AmbasadaApps, APP_SIGNATURE_HEADER, APP_TIMESTAMP_HEADER, appWebhookHeaders, signAppWebhook } from "./apps.js";
|
|
17
|
-
export type { AppEvent, AppEventType, AppNotifyInput, AppNotifyResult, AppsConfig, NotificationCategory, WebhookInput } from "./apps.js";
|
|
18
|
-
/** The default client, configured from the environment at call time. */
|
|
19
|
-
export declare const ambasada: Ambasada;
|
|
20
|
-
export default ambasada;
|
package/dist/sdk/types.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/** Wire types of the platform API. */
|
|
2
|
-
/** Ed25519 public key as served by `/.well-known/jwks.json`. */
|
|
3
|
-
export interface Jwk {
|
|
4
|
-
kty: "OKP";
|
|
5
|
-
crv: "Ed25519";
|
|
6
|
-
x: string;
|
|
7
|
-
d?: string;
|
|
8
|
-
kid?: string;
|
|
9
|
-
alg?: "EdDSA";
|
|
10
|
-
use?: "sig";
|
|
11
|
-
}
|
|
12
|
-
export interface FileOptions {
|
|
13
|
-
contentType?: string;
|
|
14
|
-
ttlSeconds?: number;
|
|
15
|
-
}
|
|
16
|
-
/** `POST /v1/files`. */
|
|
17
|
-
export interface StoredFile {
|
|
18
|
-
id: string;
|
|
19
|
-
url: string;
|
|
20
|
-
size?: number;
|
|
21
|
-
content_type?: string;
|
|
22
|
-
cost?: number;
|
|
23
|
-
call_id?: string;
|
|
24
|
-
}
|
|
25
|
-
export interface StoreKey {
|
|
26
|
-
key: string;
|
|
27
|
-
size: number;
|
|
28
|
-
updated_at: string;
|
|
29
|
-
}
|
|
30
|
-
export interface StoreList {
|
|
31
|
-
keys: StoreKey[];
|
|
32
|
-
used_bytes: number;
|
|
33
|
-
limit_bytes: number;
|
|
34
|
-
}
|
|
35
|
-
export interface StoreWrite {
|
|
36
|
-
key: string;
|
|
37
|
-
size: number;
|
|
38
|
-
used_bytes: number;
|
|
39
|
-
limit_bytes: number;
|
|
40
|
-
}
|