@midsummer-ai/sdk 0.1.0-staging.3728 → 0.1.0-staging.3734
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/ai/contract.mjs +1 -1
- package/ai/index.d.mts +3 -2
- package/ai/index.mjs +1 -262
- package/ai/stand-in.mjs +1 -62
- package/ai-2Llbc56l.mjs +328 -0
- package/apps.d.mts +0 -15
- package/apps.mjs +19 -2
- package/auth/contract.d.mts +2 -2
- package/auth/contract.mjs +1 -1
- package/auth/index.d.mts +2 -2
- package/auth/index.mjs +1 -1
- package/auth/mail.mjs +2 -2
- package/auth/password.mjs +1 -1
- package/auth/react.d.mts +7 -2
- package/auth/react.mjs +44 -8
- package/auth/stand-in.d.mts +1 -1
- package/{auth-BA5Xdi-4.mjs → auth-BaGXVRYd.mjs} +38 -8
- package/billing/index.mjs +1 -1
- package/client-_Al5bpqX.mjs +877 -0
- package/{client-D3BZs3LA.d.mts → client-oAVg6vn_.d.mts} +64 -20
- package/client.mjs +1 -1
- package/contract.mjs +1 -1
- package/database/client.d.mts +2 -2
- package/database/client.mjs +2 -711
- package/database/react.d.mts +1 -1
- package/database/stand-in.mjs +1 -1
- package/email/client.mjs +1 -1
- package/email/contract.mjs +1 -1
- package/email/inbox.mjs +1 -1
- package/email/index.mjs +1 -1
- package/email/smtp.mjs +1 -1
- package/email/stand-in.mjs +1 -1
- package/{email-ynNo0HqT.mjs → email-DmWG_Ug-.mjs} +16 -2
- package/{engine-DDPJ2CET.mjs → engine-BmiPioJ2.mjs} +13 -2
- package/{here-1plIxb0D.mjs → here-BKjizr_N.mjs} +9 -1
- package/{index-C2Jo3JqT.d.mts → index-C8Ti5raa.d.mts} +2 -2
- package/index.mjs +1 -1
- package/package.json +1 -1
- package/{qr-CBh0LP2_.mjs → qr-Br1sOBmT.mjs} +1 -0
- package/queues/index.mjs +1 -1
- package/s3.mjs +1 -1
- package/socket.mjs +1 -1
- package/{src-BKKy9km-.mjs → src-DgX-tCDn.mjs} +2 -2
- package/storage/files.d.mts +1 -1
- package/storage/files.mjs +2 -2
- package/{store-CLGBhEpO.d.mts → store-Bx4dOx66.d.mts} +1 -1
- package/vector/index.mjs +1 -1
|
@@ -41,7 +41,7 @@ type ConnectOptions = {
|
|
|
41
41
|
} | {
|
|
42
42
|
/** A Database Key, `mdbk_…`: exchanged for a token and the Database's address. */
|
|
43
43
|
readonly key: string;
|
|
44
|
-
/** The platform's API, where a key is exchanged. */
|
|
44
|
+
/** The platform's API, where a key is exchanged: `MIDSUMMER_API` when left out, else the API of the site this package was published for. */
|
|
45
45
|
readonly api?: string;
|
|
46
46
|
} | {
|
|
47
47
|
/** The name the run's Environment binds the Database under: in CI, an Agent's run or `midsummer dev`. */
|
|
@@ -54,32 +54,49 @@ type ConnectOptions = {
|
|
|
54
54
|
/** The name the Environment binds the Database under, such as `main`. */
|
|
55
55
|
readonly binding: string;
|
|
56
56
|
};
|
|
57
|
-
/**
|
|
57
|
+
/** A token for one Database and its address, with when the token stops working. */
|
|
58
|
+
interface DatabaseToken {
|
|
59
|
+
readonly token: string;
|
|
60
|
+
readonly url: string;
|
|
61
|
+
readonly expiresAt: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* What Midsummer hands a Deployment as `context.database`: a token and address for a Database its Environment binds,
|
|
65
|
+
* as the app's server, and (`userToken`) as one of the app's users, for that user's browser.
|
|
66
|
+
*/
|
|
58
67
|
interface BoundDatabases {
|
|
59
|
-
token(binding: string): Promise<
|
|
60
|
-
|
|
61
|
-
readonly url: string;
|
|
62
|
-
readonly expiresAt: number;
|
|
63
|
-
}>;
|
|
68
|
+
token(binding: string): Promise<DatabaseToken>;
|
|
69
|
+
userToken?(binding: string, as: string): Promise<DatabaseToken>;
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
72
|
* A token for one signed-in user of your app, for your server to hand to that user's browser, which connects with
|
|
67
|
-
* it (`@midsummer-ai/sdk/react`'s `DatabaseProvider`, or `connect({ url, token, refresh })`).
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
73
|
+
* it (`signedInDatabase()`, `@midsummer-ai/sdk/react`'s `DatabaseProvider`, or `connect({ url, token, refresh })`).
|
|
74
|
+
* Your server gives the user's id as `as`; your functions see that id as `ctx.auth.subject`. The token
|
|
75
|
+
* runs public functions only, never internal ones. It lasts ten minutes: the browser asks your server again before
|
|
76
|
+
* then. With Auth, `auth.handler` serves it already, at `/api/auth/database-token`.
|
|
71
77
|
*
|
|
78
|
+
* On Midsummer it needs no key: the database is the one the environment binds as `binding` (`main` unless named),
|
|
79
|
+
* in a deployment, a preview (its own copy), a CI run and under `midsummer dev` (the local database) alike. Outside
|
|
80
|
+
* Midsummer, give a database key, whose token runs queries only for a `read` key.
|
|
81
|
+
*
|
|
82
|
+
* app.get("/db-token", async (c) => c.json(await userToken({ as: session.userId })))
|
|
72
83
|
* app.get("/db-token", async (c) => c.json(await userToken({ key: process.env.DATABASE_KEY!, as: session.userId })))
|
|
73
84
|
*/
|
|
74
85
|
declare function userToken(options: {
|
|
75
|
-
readonly key: string;
|
|
76
86
|
readonly as: string;
|
|
87
|
+
readonly binding?: string;
|
|
88
|
+
readonly key?: string;
|
|
77
89
|
readonly api?: string;
|
|
78
|
-
}): Promise<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
90
|
+
}): Promise<DatabaseToken>;
|
|
91
|
+
/**
|
|
92
|
+
* Where the database bound as `binding` (`main` unless named) serves, or the one a key reaches: what a page connects
|
|
93
|
+
* to as no one, as `auth.handler`'s `/api/auth/database-token` returns it to a visitor who isn't signed in.
|
|
94
|
+
*/
|
|
95
|
+
declare function databaseUrl(options?: {
|
|
96
|
+
readonly binding?: string;
|
|
97
|
+
readonly key?: string;
|
|
98
|
+
readonly api?: string;
|
|
99
|
+
}): Promise<string>;
|
|
83
100
|
declare function connect(options: ConnectOptions): Promise<Database>;
|
|
84
101
|
/**
|
|
85
102
|
* What `setAuth` is given: the signed-in user's token from their sign-in provider, or null when no one is
|
|
@@ -101,8 +118,12 @@ interface AuthState {
|
|
|
101
118
|
*/
|
|
102
119
|
declare class DatabaseClient implements Database {
|
|
103
120
|
#private;
|
|
104
|
-
/**
|
|
105
|
-
|
|
121
|
+
/**
|
|
122
|
+
* `url`: where the Database serves, as `midsummer db show` gives it, or the development server's address; or a
|
|
123
|
+
* function that gives it, asked each time the client connects, for a page that learns it from its server. With
|
|
124
|
+
* `fetchToken`, the first connection, made on first use, is signed in with it, as after `setAuth`.
|
|
125
|
+
*/
|
|
126
|
+
constructor(url: string | (() => Promise<string>), fetchToken?: FetchToken);
|
|
106
127
|
/** Signs in with the tokens `fetchToken` gives, now and whenever one is about to expire; `onChange` hears whether the Database took them. */
|
|
107
128
|
setAuth(fetchToken: FetchToken, onChange?: (isAuthenticated: boolean, error?: unknown) => void): void;
|
|
108
129
|
/** Signs out: the client connects again as no one. */
|
|
@@ -120,6 +141,29 @@ declare class DatabaseClient implements Database {
|
|
|
120
141
|
watch<F extends Reference<"query">>(fn: F, args: ArgsOf<F>, onValue: (value: ReturnsOf<F>) => void, onError?: (error: DatabaseError) => void): () => void;
|
|
121
142
|
close(): void;
|
|
122
143
|
}
|
|
144
|
+
/** Where `auth.handler` gives a page the database's address and, for someone signed in, their token. */
|
|
145
|
+
declare const DATABASE_TOKEN_PATH = "/api/auth/database-token";
|
|
146
|
+
/** A `DatabaseClient` that connects as whoever is signed in to the app with Auth. */
|
|
147
|
+
interface SignedInDatabase extends DatabaseClient {
|
|
148
|
+
/** Connects again for whoever is signed in now: call it after someone signs in or out. */
|
|
149
|
+
signedInChanged(): void;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* In the browser of an app whose users sign in with Auth: the database as whoever is signed in, with no key and no
|
|
153
|
+
* route of your own. The database's address and the user's ten-minute token come from your server's `auth.handler`
|
|
154
|
+
* (`GET /api/auth/database-token`), asked again before the token runs out, so it follows a preview's own copy of the
|
|
155
|
+
* database and the local one under `midsummer dev`. Someone not signed in connects as no one. `<AuthProvider
|
|
156
|
+
* database>` makes one and calls `signedInChanged()` for you; elsewhere, call it after a sign-in or a sign-out.
|
|
157
|
+
*
|
|
158
|
+
* const db = signedInDatabase()
|
|
159
|
+
* const notes = await db.query(api.notes.list, {})
|
|
160
|
+
*
|
|
161
|
+
* `url` is where the route is, when your server is on another address: `https://app.example.com/api/auth/database-token`.
|
|
162
|
+
*/
|
|
163
|
+
declare function signedInDatabase(options?: {
|
|
164
|
+
readonly url?: string;
|
|
165
|
+
readonly fetch?: (url: string, init: RequestInit) => Promise<Response>;
|
|
166
|
+
}): SignedInDatabase;
|
|
123
167
|
/**
|
|
124
168
|
* Auth0: the signed-in user's ID token, whose `aud` is your application's client ID, the `applicationID`
|
|
125
169
|
* `db/auth.config.ts` names beside your tenant's `domain`. Give it auth0-react's `getAccessTokenSilently`, or
|
|
@@ -152,4 +196,4 @@ declare function clerk(getToken: (options: {
|
|
|
152
196
|
*/
|
|
153
197
|
declare function oidc(getToken: (forceRefresh: boolean) => Promise<string | null | undefined> | string | null | undefined): FetchToken;
|
|
154
198
|
//#endregion
|
|
155
|
-
export {
|
|
199
|
+
export { oidc as _, DATABASE_TOKEN_PATH as a, DatabaseToken as c, ReturnsOf as d, SignedInDatabase as f, databaseUrl as g, connect as h, ConnectOptions as i, FetchToken as l, clerk as m, AuthState as n, Database as o, auth0 as p, BoundDatabases as r, DatabaseClient as s, ArgsOf as t, Reference as u, signedInDatabase as v, userToken as y };
|
package/client.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as FRAMES_PATH, c as serveSigned, l as signedHttp, o as SOCKET_PATH, s as client } from "./src-
|
|
1
|
+
import { a as FRAMES_PATH, c as serveSigned, l as signedHttp, o as SOCKET_PATH, s as client } from "./src-DgX-tCDn.mjs";
|
|
2
2
|
export { FRAMES_PATH, SOCKET_PATH, client, serveSigned, signedHttp };
|
package/contract.mjs
CHANGED
package/database/client.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { n as DatabaseErrorCode, t as DatabaseError } from "../errors-CnQduDOt.mjs";
|
|
2
|
-
import { a as
|
|
3
|
-
export { ArgsOf, AuthState, BoundDatabases, ConnectOptions, Database, DatabaseClient, DatabaseError, type DatabaseErrorCode, FetchToken, Reference, ReturnsOf, auth0, clerk, connect, oidc, userToken };
|
|
2
|
+
import { _ as oidc, a as DATABASE_TOKEN_PATH, c as DatabaseToken, d as ReturnsOf, f as SignedInDatabase, g as databaseUrl, h as connect, i as ConnectOptions, l as FetchToken, m as clerk, n as AuthState, o as Database, p as auth0, r as BoundDatabases, s as DatabaseClient, t as ArgsOf, u as Reference, v as signedInDatabase, y as userToken } from "../client-oAVg6vn_.mjs";
|
|
3
|
+
export { ArgsOf, AuthState, BoundDatabases, ConnectOptions, DATABASE_TOKEN_PATH, Database, DatabaseClient, DatabaseError, type DatabaseErrorCode, DatabaseToken, FetchToken, Reference, ReturnsOf, SignedInDatabase, auth0, clerk, connect, databaseUrl, oidc, signedInDatabase, userToken };
|