@midsummer-ai/sdk 0.1.0-staging.4525 → 0.1.0-staging.4531
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/auth/contract.d.mts +1 -1
- package/auth/contract.mjs +1 -1
- package/auth/impersonate.d.mts +2 -33
- package/auth/impersonate.mjs +8 -2
- package/auth/index.d.mts +2 -1
- package/auth/index.mjs +2 -1
- package/{auth-BH2Lfguc.mjs → auth-Dp3oUiLB.mjs} +2 -3
- package/here-C2jhTheQ.mjs +1 -1
- package/impersonate-C7SoVmew.d.mts +39 -0
- package/{index-BmjcZfRb.d.mts → index-CkBabhgi.d.mts} +1 -3
- package/package.json +1 -1
package/auth/contract.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as AuthStore } from "../store-B3KJ3e83.mjs";
|
|
2
2
|
import { SignInMail } from "./mail.mjs";
|
|
3
|
-
import { a as Auth } from "../index-
|
|
3
|
+
import { a as Auth } from "../index-CkBabhgi.mjs";
|
|
4
4
|
//#region src/auth/contract.d.ts
|
|
5
5
|
interface AuthHarness {
|
|
6
6
|
/** Sign-in over a store with no users, made with `scopes: CONTRACT_SCOPES`. */
|
package/auth/contract.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { s as AuthError } from "../auth-Dp3oUiLB.mjs";
|
|
2
2
|
import { d as SETTINGS_TTL_MS, n as LIMIT_WINDOW_MS, t as LIMITS } from "../guard-VPI6xq4z.mjs";
|
|
3
3
|
import { IMPERSONATION_TOKEN_MS, startImpersonation } from "./impersonate.mjs";
|
|
4
4
|
//#region src/auth/contract.ts
|
package/auth/impersonate.d.mts
CHANGED
|
@@ -1,33 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* "Sign in as": how the platform lets a project's owner open the app as one of its users. The platform makes a
|
|
4
|
-
* one-time token with `startImpersonation`, writes `row` into the app's `authVerifications` (through `auth.create`),
|
|
5
|
-
* and gives the owner `path` on the app's address to open. The app's sign-in uses the token once, within a minute,
|
|
6
|
-
* and makes a session for the user that says who opened it (`impersonatedBy`) and ends by itself.
|
|
7
|
-
*
|
|
8
|
-
* const started = await startImpersonation({ userId, by: "Ada Lovelace (ada@acme.dev)", reason: "Checking a bug report", now: Date.now() })
|
|
9
|
-
* await rows.call("create", { model: "authVerifications", data: started.row })
|
|
10
|
-
* return { url: `${environmentOrigin}${started.path}` }
|
|
11
|
-
*/
|
|
12
|
-
/** How long the token works once made, in ms. */
|
|
13
|
-
declare const IMPERSONATION_TOKEN_MS = 60000;
|
|
14
|
-
/** A token's row id: what `authVerifications.identifier` keeps for it, never the token itself. */
|
|
15
|
-
declare function impersonationIdentifier(token: string): Promise<string>;
|
|
16
|
-
/** A new "sign in as" for `userId`: the token's path to open, and the row that lets it in once. Throws for a reason that isn't 1 to 200 characters. */
|
|
17
|
-
declare function startImpersonation(input: {
|
|
18
|
-
readonly userId: string;
|
|
19
|
-
readonly by: string;
|
|
20
|
-
readonly reason: string;
|
|
21
|
-
readonly now: number;
|
|
22
|
-
}): Promise<{
|
|
23
|
-
readonly path: string;
|
|
24
|
-
readonly row: {
|
|
25
|
-
readonly identifier: string;
|
|
26
|
-
readonly value: string;
|
|
27
|
-
readonly expiresAt: number;
|
|
28
|
-
readonly createdAt: number;
|
|
29
|
-
readonly updatedAt: number;
|
|
30
|
-
};
|
|
31
|
-
}>;
|
|
32
|
-
//#endregion
|
|
33
|
-
export { IMPERSONATION_TOKEN_MS, impersonationIdentifier, startImpersonation };
|
|
1
|
+
import { i as startImpersonation, n as IMPERSONATION_TOKEN_MS, r as impersonationIdentifier, t as IMPERSONATION_S } from "../impersonate-C7SoVmew.mjs";
|
|
2
|
+
export { IMPERSONATION_S, IMPERSONATION_TOKEN_MS, impersonationIdentifier, startImpersonation };
|
package/auth/impersonate.mjs
CHANGED
|
@@ -11,13 +11,18 @@
|
|
|
11
11
|
*/
|
|
12
12
|
/** How long the token works once made, in ms. */
|
|
13
13
|
const IMPERSONATION_TOKEN_MS = 6e4;
|
|
14
|
+
/** How long a session the token made lasts, in seconds: it is never renewed. */
|
|
15
|
+
const IMPERSONATION_S = 1800;
|
|
14
16
|
const hex = (bytes) => [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
15
17
|
const base64url = (bytes) => btoa(String.fromCharCode(...bytes)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
16
18
|
/** A token's row id: what `authVerifications.identifier` keeps for it, never the token itself. */
|
|
17
19
|
async function impersonationIdentifier(token) {
|
|
18
20
|
return `impersonate:${hex(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(token))))}`;
|
|
19
21
|
}
|
|
20
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* A new "sign in as" for `userId`: the token's path to open, the row that lets it in once, and how long the session it
|
|
24
|
+
* makes lasts, in ms. Throws for a reason that isn't 1 to 200 characters.
|
|
25
|
+
*/
|
|
21
26
|
async function startImpersonation(input) {
|
|
22
27
|
const reason = input.reason.trim(), by = input.by.trim();
|
|
23
28
|
if (!reason || reason.length > 200) throw new Error("Say why you're signing in as them, in 1 to 200 characters.");
|
|
@@ -25,6 +30,7 @@ async function startImpersonation(input) {
|
|
|
25
30
|
const token = base64url(crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)));
|
|
26
31
|
return {
|
|
27
32
|
path: `/api/auth/impersonate?token=${token}`,
|
|
33
|
+
sessionMs: IMPERSONATION_S * 1e3,
|
|
28
34
|
row: {
|
|
29
35
|
identifier: await impersonationIdentifier(token),
|
|
30
36
|
value: JSON.stringify({
|
|
@@ -39,4 +45,4 @@ async function startImpersonation(input) {
|
|
|
39
45
|
};
|
|
40
46
|
}
|
|
41
47
|
//#endregion
|
|
42
|
-
export { IMPERSONATION_TOKEN_MS, impersonationIdentifier, startImpersonation };
|
|
48
|
+
export { IMPERSONATION_S, IMPERSONATION_TOKEN_MS, impersonationIdentifier, startImpersonation };
|
package/auth/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { n as AuthStore, r as databaseStore, t as AuthCall } from "../store-B3KJ3e83.mjs";
|
|
2
2
|
import { i as SignUpPolicy, n as CaptchaProvider, r as PublicSettings, t as AuthSettings } from "../settings-Dz3irtlu.mjs";
|
|
3
3
|
import { SignInMail, SignInMailKind, checkSignInMail, signInWords } from "./mail.mjs";
|
|
4
|
-
import { _ as
|
|
4
|
+
import { _ as AuthEventBatch, a as Auth, c as AuthUserRecord, d as SignedInAgent, f as auth, g as AuthEvent, h as AuthErrorCode, i as AgentKey, l as SESSION_CACHE_S, m as AuthError, n as AUTH_ROUTES, o as AuthOptions, p as createAuth, r as AgentGrant, s as AuthUser, t as AUTH_PATH, u as SignedIn, v as AuthEventType, y as EventSend } from "../index-CkBabhgi.mjs";
|
|
5
|
+
import { t as IMPERSONATION_S } from "../impersonate-C7SoVmew.mjs";
|
|
5
6
|
import { i as authFiles } from "../files-CLuPkXhj.mjs";
|
|
6
7
|
export { AUTH_PATH, AUTH_ROUTES, AgentGrant, AgentKey, Auth, type AuthCall, AuthError, type AuthErrorCode, type AuthEvent, type AuthEventBatch, type AuthEventType, AuthOptions, type AuthSettings, type AuthStore, AuthUser, AuthUserRecord, type CaptchaProvider, type EventSend, IMPERSONATION_S, type PublicSettings, SESSION_CACHE_S, type SignInMail, type SignInMailKind, type SignUpPolicy, SignedIn, SignedInAgent, auth, authFiles, checkSignInMail, createAuth, databaseStore, signInWords };
|
package/auth/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as createAuth, i as auth, n as AUTH_ROUTES, o as databaseStore, r as SESSION_CACHE_S, s as AuthError, t as AUTH_PATH } from "../auth-Dp3oUiLB.mjs";
|
|
2
2
|
import { checkSignInMail, signInWords } from "./mail.mjs";
|
|
3
3
|
import { n as authFiles } from "../files-ZySaprII.mjs";
|
|
4
|
+
import { IMPERSONATION_S } from "./impersonate.mjs";
|
|
4
5
|
export { AUTH_PATH, AUTH_ROUTES, AuthError, IMPERSONATION_S, SESSION_CACHE_S, auth, authFiles, checkSignInMail, createAuth, databaseStore, signInWords };
|
|
@@ -8,6 +8,7 @@ import { standIn } from "./auth/stand-in.mjs";
|
|
|
8
8
|
import { a as WORDS, c as deviceOf, i as CAPTCHA_WIDGETS, l as screenName, n as textOn, o as ago, r as GEIST_WOFF2, s as defaultAppName, t as authCss, u as setupKeyOf } from "./style-DXd-0Cxo.mjs";
|
|
9
9
|
import { _ as challenge, a as leakedPassword, b as remembering, c as refusal, f as mayJoin, g as agentOfKey, i as guard, l as verifyHuman, m as settingsReader, o as ourWords, p as publicSettings, r as REFUSALS, s as rateLimiter, u as JoinRefused, v as consentPage, x as resourceOf, y as credentialOf } from "./guard-VPI6xq4z.mjs";
|
|
10
10
|
import { i as iconSvg, n as qrSvg } from "./qr-BySxqLW6.mjs";
|
|
11
|
+
import { IMPERSONATION_S } from "./auth/impersonate.mjs";
|
|
11
12
|
//#region src/auth/errors.ts
|
|
12
13
|
var AuthError = class extends Error {
|
|
13
14
|
code;
|
|
@@ -1110,8 +1111,6 @@ const AUTH_PATH = "/api/auth";
|
|
|
1110
1111
|
const CALL_TOKEN_PATH = "/call-token";
|
|
1111
1112
|
/** How long a session is kept in its cookie before its row is read again, in seconds. */
|
|
1112
1113
|
const SESSION_CACHE_S = 300;
|
|
1113
|
-
/** How long a session the platform's "sign in as" makes lasts, in seconds. */
|
|
1114
|
-
const IMPERSONATION_S = 1800;
|
|
1115
1114
|
/**
|
|
1116
1115
|
* Sign-in's own routes under `AUTH_PATH`, the ones the docs promise: each runs the engine's path under it (`engine`)
|
|
1117
1116
|
* and returns Midsummer's shape (`routed`). The engine's other paths serve the browser client and aren't promised.
|
|
@@ -2054,4 +2053,4 @@ function createAuth(options = {}) {
|
|
|
2054
2053
|
/** Sign-in for this deployment, set up from its environment. */
|
|
2055
2054
|
const auth = createAuth();
|
|
2056
2055
|
//#endregion
|
|
2057
|
-
export {
|
|
2056
|
+
export { createAuth as a, auth as i, AUTH_ROUTES as n, databaseStore as o, SESSION_CACHE_S as r, AuthError as s, AUTH_PATH as t };
|
package/here-C2jhTheQ.mjs
CHANGED
|
@@ -12,7 +12,7 @@ function processEnv() {
|
|
|
12
12
|
* This package's version: `0.0.0-dev` here, and in a published package the version it was published at, which the
|
|
13
13
|
* release writes in its place as it stages the package (`stampSdk` in `scripts/release/packages.ts`).
|
|
14
14
|
*/
|
|
15
|
-
const SDK_VERSION = "0.1.0-staging.
|
|
15
|
+
const SDK_VERSION = "0.1.0-staging.4531";
|
|
16
16
|
/**
|
|
17
17
|
* The header that tells Midsummer which client made each of this package's calls: `Midsummer-Client: sdk/<version>
|
|
18
18
|
* <part>`, `part` the product whose client it is (`database`, `storage`, `queues`, ...), so the platform counts which
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/auth/impersonate.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* "Sign in as": how the platform lets a project's owner open the app as one of its users. The platform makes a
|
|
4
|
+
* one-time token with `startImpersonation`, writes `row` into the app's `authVerifications` (through `auth.create`),
|
|
5
|
+
* and gives the owner `path` on the app's address to open. The app's sign-in uses the token once, within a minute,
|
|
6
|
+
* and makes a session for the user that says who opened it (`impersonatedBy`) and ends by itself.
|
|
7
|
+
*
|
|
8
|
+
* const started = await startImpersonation({ userId, by: "Ada Lovelace (ada@acme.dev)", reason: "Checking a bug report", now: Date.now() })
|
|
9
|
+
* await rows.call("create", { model: "authVerifications", data: started.row })
|
|
10
|
+
* return { url: `${environmentOrigin}${started.path}` }
|
|
11
|
+
*/
|
|
12
|
+
/** How long the token works once made, in ms. */
|
|
13
|
+
declare const IMPERSONATION_TOKEN_MS = 60000;
|
|
14
|
+
/** How long a session the token made lasts, in seconds: it is never renewed. */
|
|
15
|
+
declare const IMPERSONATION_S: number;
|
|
16
|
+
/** A token's row id: what `authVerifications.identifier` keeps for it, never the token itself. */
|
|
17
|
+
declare function impersonationIdentifier(token: string): Promise<string>;
|
|
18
|
+
/**
|
|
19
|
+
* A new "sign in as" for `userId`: the token's path to open, the row that lets it in once, and how long the session it
|
|
20
|
+
* makes lasts, in ms. Throws for a reason that isn't 1 to 200 characters.
|
|
21
|
+
*/
|
|
22
|
+
declare function startImpersonation(input: {
|
|
23
|
+
readonly userId: string;
|
|
24
|
+
readonly by: string;
|
|
25
|
+
readonly reason: string;
|
|
26
|
+
readonly now: number;
|
|
27
|
+
}): Promise<{
|
|
28
|
+
readonly path: string;
|
|
29
|
+
readonly sessionMs: number;
|
|
30
|
+
readonly row: {
|
|
31
|
+
readonly identifier: string;
|
|
32
|
+
readonly value: string;
|
|
33
|
+
readonly expiresAt: number;
|
|
34
|
+
readonly createdAt: number;
|
|
35
|
+
readonly updatedAt: number;
|
|
36
|
+
};
|
|
37
|
+
}>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { startImpersonation as i, IMPERSONATION_TOKEN_MS as n, impersonationIdentifier as r, IMPERSONATION_S as t };
|
|
@@ -87,8 +87,6 @@ declare class AuthError extends Error {
|
|
|
87
87
|
declare const AUTH_PATH = "/api/auth";
|
|
88
88
|
/** How long a session is kept in its cookie before its row is read again, in seconds. */
|
|
89
89
|
declare const SESSION_CACHE_S: number;
|
|
90
|
-
/** How long a session the platform's "sign in as" makes lasts, in seconds. */
|
|
91
|
-
declare const IMPERSONATION_S: number;
|
|
92
90
|
/**
|
|
93
91
|
* Sign-in's own routes under `AUTH_PATH`, the ones the docs promise: each runs the engine's path under it (`engine`)
|
|
94
92
|
* and returns Midsummer's shape (`routed`). The engine's other paths serve the browser client and aren't promised.
|
|
@@ -307,4 +305,4 @@ declare function createAuth(options?: AuthOptions): Auth;
|
|
|
307
305
|
/** Sign-in for this deployment, set up from its environment. */
|
|
308
306
|
declare const auth: Auth;
|
|
309
307
|
//#endregion
|
|
310
|
-
export {
|
|
308
|
+
export { AuthEventBatch as _, Auth as a, AuthUserRecord as c, SignedInAgent as d, auth as f, AuthEvent as g, AuthErrorCode as h, AgentKey as i, SESSION_CACHE_S as l, AuthError as m, AUTH_ROUTES as n, AuthOptions as o, createAuth as p, AgentGrant as r, AuthUser as s, AUTH_PATH as t, SignedIn as u, AuthEventType as v, EventSend as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midsummer-ai/sdk",
|
|
3
|
-
"version": "0.1.0-staging.
|
|
3
|
+
"version": "0.1.0-staging.4531",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Midsummer's handles for an app's code: its Database, Storage, Queues, Vector DB, AI, Email and Agents, with stand-ins for tests.",
|