@softr/sdk 0.0.70 → 0.0.72
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/auth/isomorphic.d.ts +1 -1
- package/dist/auth/isomorphic.js +6 -1
- package/dist/auth/methods/profile.d.ts +26 -0
- package/dist/auth/methods/profile.js +52 -0
- package/dist/auth/methods/utils.d.ts +1 -1
- package/dist/auth/platform.js +9 -2
- package/dist/auth/server.d.ts +2 -0
- package/dist/auth/server.js +2 -0
- package/dist/auth/session.js +11 -1
- package/dist/auth/user.d.ts +4 -0
- package/dist/auth/user.js +3 -1
- package/dist/favicon.js +37 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/mcp.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/{visibility → route}/audience.d.ts +1 -1
- package/dist/{visibility → route}/audience.js +1 -1
- package/dist/{visibility → route}/page.d.ts +1 -1
- package/dist/{visibility → route}/page.js +1 -1
- package/dist/{visibility → route}/route.d.ts +1 -1
- package/dist/{visibility → route}/route.js +1 -1
- package/dist/{visibility → route}/visibility.d.ts +1 -1
- package/dist/{visibility → route}/visibility.js +1 -1
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +29 -10
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
- package/skills/softr-sdk/current-user/SKILL.md +3 -1
- package/skills/softr-sdk/file-uploads/SKILL.md +1 -1
- package/skills/softr-sdk/formatting/SKILL.md +1 -1
- package/skills/softr-sdk/integrations/SKILL.md +1 -1
- package/skills/softr-sdk/mcp/SKILL.md +1 -1
- package/skills/softr-sdk/pwa/SKILL.md +1 -1
- package/skills/softr-sdk/record-mutations/SKILL.md +1 -1
- package/skills/softr-sdk/record-queries/SKILL.md +1 -1
- package/skills/softr-sdk/region-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/routes-and-visibility/SKILL.md +1 -1
- package/skills/softr-sdk/workflows/SKILL.md +1 -1
|
@@ -21,7 +21,7 @@ import * as _tanstack_react_start0 from "@tanstack/react-start";
|
|
|
21
21
|
* requestMiddleware: [softrAuthMiddleware()],
|
|
22
22
|
* }))
|
|
23
23
|
*/
|
|
24
|
-
declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
|
|
24
|
+
declare function softrAuthMiddleware(): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, readonly [_tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>, _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>], {
|
|
25
25
|
user: User | null;
|
|
26
26
|
permissions: Permissions;
|
|
27
27
|
formatting: Formatting;
|
package/dist/auth/isomorphic.js
CHANGED
|
@@ -8,6 +8,7 @@ import { readLocaleSettings } from "../locale-settings.js";
|
|
|
8
8
|
import { settings } from "./methods/settings.js";
|
|
9
9
|
import { bootErrorMiddleware } from "../boot-error.js";
|
|
10
10
|
import { pwaMiddleware } from "../pwa.js";
|
|
11
|
+
import { faviconMiddleware } from "../favicon.js";
|
|
11
12
|
import { createContext, useContext } from "react";
|
|
12
13
|
import { createMiddleware, createServerFn, getGlobalStartContext } from "@tanstack/react-start";
|
|
13
14
|
import { getRequestHeader } from "@tanstack/react-start/server";
|
|
@@ -29,7 +30,11 @@ import { jsx } from "react/jsx-runtime";
|
|
|
29
30
|
* }))
|
|
30
31
|
*/
|
|
31
32
|
function softrAuthMiddleware() {
|
|
32
|
-
return createMiddleware({ type: "request" }).middleware([
|
|
33
|
+
return createMiddleware({ type: "request" }).middleware([
|
|
34
|
+
bootErrorMiddleware(),
|
|
35
|
+
pwaMiddleware(),
|
|
36
|
+
faviconMiddleware()
|
|
37
|
+
]).server(async ({ next }) => {
|
|
33
38
|
async function getSession() {
|
|
34
39
|
const token = readSessionToken();
|
|
35
40
|
if (process.env.NODE_ENV === "production") {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { User } from "../user.js";
|
|
2
|
+
import { AuthError, Result } from "./utils.js";
|
|
3
|
+
|
|
4
|
+
//#region src/auth/methods/profile.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Changes the signed-in visitor's own name, photo, or both. A field left out
|
|
8
|
+
* stays as it is, and `avatar: null` removes the photo.
|
|
9
|
+
*
|
|
10
|
+
* The photo can change only where `user.avatarEditable` is true. Elsewhere a
|
|
11
|
+
* photo answers `avatarNotSupported`, so hide the photo controls instead.
|
|
12
|
+
*
|
|
13
|
+
* Answers with the visitor as they are now. The page keeps showing what it
|
|
14
|
+
* loaded until its route context loads again, so call `router.invalidate()`
|
|
15
|
+
* after a success.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const result = await auth.updateProfile({ fullName: 'Ann Lee' })
|
|
19
|
+
* const result = await auth.updateProfile({ avatar: file })
|
|
20
|
+
*/
|
|
21
|
+
declare function updateProfile(changes: {
|
|
22
|
+
fullName?: string;
|
|
23
|
+
avatar?: File | null;
|
|
24
|
+
}): Promise<Result<User, AuthError>>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { updateProfile };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { assert, panic } from "../../assertions.js";
|
|
2
|
+
import { sessionConfig } from "../config.js";
|
|
3
|
+
import { clearSessionData, readSessionToken } from "../session.js";
|
|
4
|
+
import { makePlatform } from "../platform.js";
|
|
5
|
+
import { authError } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
//#region src/auth/methods/profile.ts
|
|
8
|
+
/**
|
|
9
|
+
* Changes the signed-in visitor's own name, photo, or both. A field left out
|
|
10
|
+
* stays as it is, and `avatar: null` removes the photo.
|
|
11
|
+
*
|
|
12
|
+
* The photo can change only where `user.avatarEditable` is true. Elsewhere a
|
|
13
|
+
* photo answers `avatarNotSupported`, so hide the photo controls instead.
|
|
14
|
+
*
|
|
15
|
+
* Answers with the visitor as they are now. The page keeps showing what it
|
|
16
|
+
* loaded until its route context loads again, so call `router.invalidate()`
|
|
17
|
+
* after a success.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const result = await auth.updateProfile({ fullName: 'Ann Lee' })
|
|
21
|
+
* const result = await auth.updateProfile({ avatar: file })
|
|
22
|
+
*/
|
|
23
|
+
async function updateProfile(changes) {
|
|
24
|
+
assert(changes.fullName !== void 0 || changes.avatar !== void 0, "updateProfile needs a name or a photo to change");
|
|
25
|
+
const token = readSessionToken();
|
|
26
|
+
if (token === null) return authError("notAuthenticated", "Nobody is signed in.");
|
|
27
|
+
const form = new FormData();
|
|
28
|
+
if (changes.fullName !== void 0) form.set("fullName", changes.fullName);
|
|
29
|
+
if (changes.avatar === null) form.set("removeAvatar", "true");
|
|
30
|
+
if (changes.avatar) form.set("avatar", changes.avatar);
|
|
31
|
+
const result = await makePlatform(sessionConfig().applicationId).updateProfile(token, form);
|
|
32
|
+
if (!result.ok) {
|
|
33
|
+
switch (result.status) {
|
|
34
|
+
case 400: return authError("invalidName", result.message);
|
|
35
|
+
case 401: return authError("notAuthenticated", result.message);
|
|
36
|
+
case 409: return authError("avatarNotSupported", result.message);
|
|
37
|
+
case 413: return authError("fileTooLarge", result.message);
|
|
38
|
+
case 415: return authError("notAnImage", result.message);
|
|
39
|
+
case 429: return authError("tooManyAttempts", result.message);
|
|
40
|
+
}
|
|
41
|
+
if (result.status >= 500) panic(`Expected the profile to update, but got ${result.status}: ` + result.message);
|
|
42
|
+
throw new Error(`${result.message}. Check SOFTR_APPLICATION_ID.`);
|
|
43
|
+
}
|
|
44
|
+
clearSessionData();
|
|
45
|
+
return {
|
|
46
|
+
success: true,
|
|
47
|
+
data: result.data
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { updateProfile };
|
|
@@ -10,6 +10,6 @@ type AuthError = {
|
|
|
10
10
|
code: AuthErrorCode;
|
|
11
11
|
message: string;
|
|
12
12
|
};
|
|
13
|
-
type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "notAuthenticated" | "emailDomainNotAllowed" | "linkExpired";
|
|
13
|
+
type AuthErrorCode = "invalidCredentials" | "tooManyAttempts" | "emailTaken" | "invalidDetails" | "invalidCode" | "notAuthenticated" | "emailDomainNotAllowed" | "linkExpired" | "invalidName" | "fileTooLarge" | "notAnImage" | "avatarNotSupported";
|
|
14
14
|
//#endregion
|
|
15
15
|
export { AuthError, Result };
|
package/dist/auth/platform.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { panic } from "../assertions.js";
|
|
1
|
+
import { assert, panic } from "../assertions.js";
|
|
2
2
|
import { fetch } from "../fetch.js";
|
|
3
3
|
import { permissionsSchema } from "./permissions.js";
|
|
4
4
|
import { sessionConfig } from "./config.js";
|
|
@@ -267,6 +267,11 @@ function makePlatform(applicationId) {
|
|
|
267
267
|
token,
|
|
268
268
|
json: { code }
|
|
269
269
|
}, z.null()),
|
|
270
|
+
updateProfile: (token, form) => request(`/v1/vibe/applications/${applicationId}/users/me/profile`, {
|
|
271
|
+
method: "PATCH",
|
|
272
|
+
token,
|
|
273
|
+
form
|
|
274
|
+
}, userSchema),
|
|
270
275
|
signOut: (token) => request(`/v1/applications/${applicationId}/users/sign-out`, {
|
|
271
276
|
method: "POST",
|
|
272
277
|
token
|
|
@@ -275,6 +280,7 @@ function makePlatform(applicationId) {
|
|
|
275
280
|
}
|
|
276
281
|
const errorSchema = z.object({ message: z.string() });
|
|
277
282
|
async function request(path, init, schema, parse = (response$1) => response$1.json()) {
|
|
283
|
+
assert(init.json === void 0 || init.form === void 0, "A platform request carries a JSON body or a form, not both");
|
|
278
284
|
const response = await fetch(`${await platformApiUrl()}${path}`, {
|
|
279
285
|
method: init.method,
|
|
280
286
|
headers: {
|
|
@@ -282,7 +288,8 @@ async function request(path, init, schema, parse = (response$1) => response$1.js
|
|
|
282
288
|
...init.json === void 0 ? {} : { "content-type": "application/json" },
|
|
283
289
|
...init.token ? { authorization: `Bearer ${init.token}` } : {}
|
|
284
290
|
},
|
|
285
|
-
...init.json === void 0 ? {} : { body: JSON.stringify(init.json) }
|
|
291
|
+
...init.json === void 0 ? {} : { body: JSON.stringify(init.json) },
|
|
292
|
+
...init.form === void 0 ? {} : { body: init.form }
|
|
286
293
|
});
|
|
287
294
|
if (!response.ok) {
|
|
288
295
|
const error = errorSchema.safeParse(await response.json().catch(() => null));
|
package/dist/auth/server.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { checkPasswordLink, requestPasswordReset, setPasswordWithLink } from "./
|
|
|
6
6
|
import { settings } from "./methods/settings.js";
|
|
7
7
|
import { confirmSignUp, signUp } from "./methods/signup.js";
|
|
8
8
|
import { signInWithGoogle } from "./methods/social.js";
|
|
9
|
+
import { updateProfile } from "./methods/profile.js";
|
|
9
10
|
import { currentUserRow } from "./current-user-row.js";
|
|
10
11
|
import "@tanstack/react-start/server-only";
|
|
11
12
|
|
|
@@ -34,6 +35,7 @@ declare const auth: {
|
|
|
34
35
|
resetAuthenticator: typeof resetAuthenticator;
|
|
35
36
|
removeAuthenticator: typeof removeAuthenticator;
|
|
36
37
|
settings: typeof settings;
|
|
38
|
+
updateProfile: typeof updateProfile;
|
|
37
39
|
currentUserRow: typeof currentUserRow;
|
|
38
40
|
};
|
|
39
41
|
//#endregion
|
package/dist/auth/server.js
CHANGED
|
@@ -6,6 +6,7 @@ import { signIn, signOut } from "./methods/password.js";
|
|
|
6
6
|
import { checkPasswordLink, requestPasswordReset, setPasswordWithLink } from "./methods/passwordLink.js";
|
|
7
7
|
import { confirmSignUp, signUp } from "./methods/signup.js";
|
|
8
8
|
import { signInWithGoogle } from "./methods/social.js";
|
|
9
|
+
import { updateProfile } from "./methods/profile.js";
|
|
9
10
|
import { currentUserRow } from "./current-user-row.js";
|
|
10
11
|
import "@tanstack/react-start/server-only";
|
|
11
12
|
|
|
@@ -33,6 +34,7 @@ const auth = {
|
|
|
33
34
|
resetAuthenticator,
|
|
34
35
|
removeAuthenticator,
|
|
35
36
|
settings,
|
|
37
|
+
updateProfile,
|
|
36
38
|
currentUserRow
|
|
37
39
|
};
|
|
38
40
|
|
package/dist/auth/session.js
CHANGED
|
@@ -118,6 +118,16 @@ function clearSession() {
|
|
|
118
118
|
PENDING_AUTH
|
|
119
119
|
]);
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Drops the cached visitor and leaves the session signed in, so the next
|
|
123
|
+
* request needing a visitor re-reads one from the platform.
|
|
124
|
+
*
|
|
125
|
+
* For a mutation to what the visitor's own record holds — their name, their
|
|
126
|
+
* groups — which the cache would otherwise answer stale for up to five minutes.
|
|
127
|
+
*/
|
|
128
|
+
function clearSessionData() {
|
|
129
|
+
clearCookies([SESSION_DATA]);
|
|
130
|
+
}
|
|
121
131
|
const standInToken = new AsyncLocalStorage();
|
|
122
132
|
const sessionDataSchema = z.object({
|
|
123
133
|
user: userSchema.nullable(),
|
|
@@ -210,4 +220,4 @@ function openEnvelope(raw, purpose) {
|
|
|
210
220
|
}
|
|
211
221
|
|
|
212
222
|
//#endregion
|
|
213
|
-
export { clearPendingAuth, clearSession, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken, readSessionData, readSessionToken, withSessionToken };
|
|
223
|
+
export { clearPendingAuth, clearSession, clearSessionData, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken, readSessionData, readSessionToken, withSessionToken };
|
package/dist/auth/user.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ type User = {
|
|
|
19
19
|
email: string;
|
|
20
20
|
fullName: string;
|
|
21
21
|
userGroupIds: Array<SoftrUserGroupId>;
|
|
22
|
+
/** Their photo, or `null` when they have none. Show their initials then. */
|
|
23
|
+
avatarUrl: string | null;
|
|
24
|
+
/** Whether `auth.updateProfile` can change their photo in this app. */
|
|
25
|
+
avatarEditable: boolean;
|
|
22
26
|
};
|
|
23
27
|
//#endregion
|
|
24
28
|
export { SoftrUserGroupId, SoftrUserGroups, User };
|
package/dist/auth/user.js
CHANGED
|
@@ -5,7 +5,9 @@ const userSchema = z.object({
|
|
|
5
5
|
id: z.string(),
|
|
6
6
|
email: z.string(),
|
|
7
7
|
fullName: z.string(),
|
|
8
|
-
userGroupIds: z.array(z.string())
|
|
8
|
+
userGroupIds: z.array(z.string()),
|
|
9
|
+
avatarUrl: z.string().nullable().default(null),
|
|
10
|
+
avatarEditable: z.boolean().default(false)
|
|
9
11
|
});
|
|
10
12
|
|
|
11
13
|
//#endregion
|
package/dist/favicon.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { logger } from "./logger.js";
|
|
2
|
+
import { fetch } from "./fetch.js";
|
|
3
|
+
import { createMiddleware } from "@tanstack/react-start";
|
|
4
|
+
|
|
5
|
+
//#region src/favicon.ts
|
|
6
|
+
const FAVICON_PATH = "/favicon.ico";
|
|
7
|
+
const DEFAULT_FAVICON_URL = "https://assets.softr-files.com/assets/images/favicon.ico";
|
|
8
|
+
const CACHE_CONTROL = "public, max-age=86400";
|
|
9
|
+
/**
|
|
10
|
+
* Serves the default Softr favicon at `/favicon.ico`. Every other request
|
|
11
|
+
* passes through untouched.
|
|
12
|
+
*
|
|
13
|
+
* Proxied, not redirected: some clients do not follow a redirect for an icon.
|
|
14
|
+
*
|
|
15
|
+
* Static files come before request middleware, both in the Vite dev server and
|
|
16
|
+
* on Cloudflare. So an app with its own `public/favicon.ico` keeps it, and this
|
|
17
|
+
* answers only when the app has none.
|
|
18
|
+
*/
|
|
19
|
+
function faviconMiddleware() {
|
|
20
|
+
return createMiddleware({ type: "request" }).server(async ({ next, pathname }) => {
|
|
21
|
+
if (pathname !== FAVICON_PATH) return next();
|
|
22
|
+
try {
|
|
23
|
+
const iconResponse = await fetch(DEFAULT_FAVICON_URL);
|
|
24
|
+
if (!iconResponse.ok) return new Response(null, { status: 404 });
|
|
25
|
+
return new Response(iconResponse.body, { headers: {
|
|
26
|
+
"content-type": "image/x-icon",
|
|
27
|
+
"cache-control": CACHE_CONTROL
|
|
28
|
+
} });
|
|
29
|
+
} catch (error) {
|
|
30
|
+
logger.warn("Could not fetch the default favicon:", error);
|
|
31
|
+
return new Response(null, { status: 404 });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { faviconMiddleware };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { FileItem, useFileUpload } from "./core/use-file-upload.js";
|
|
|
5
5
|
import { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting } from "./formatting.js";
|
|
6
6
|
import { SoftrContext } from "./auth/context.js";
|
|
7
7
|
import { AuthSettings } from "./auth/platform.js";
|
|
8
|
-
import { checkAccess, defineVisibility, isAuthorized } from "./
|
|
9
|
-
import { Page, PageSettings, definePage, pageHead } from "./
|
|
10
|
-
import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./
|
|
8
|
+
import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.js";
|
|
9
|
+
import { Page, PageSettings, definePage, pageHead } from "./route/page.js";
|
|
10
|
+
import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
|
|
11
11
|
import { toReturnPath } from "./auth/returnPath.js";
|
|
12
12
|
import { AuthOptions, AuthSettingsProvider, getAuthSettings, getSoftrContext, initialSoftrContext, softrAuthMiddleware, useAuthSettings, useCurrentUser } from "./auth/isomorphic.js";
|
|
13
13
|
import { softrMcpMiddleware } from "./mcp.js";
|
|
@@ -16,5 +16,5 @@ import { useOverrides } from "./core/use-overrides.js";
|
|
|
16
16
|
import { useUserTimezone } from "./timezone.js";
|
|
17
17
|
import { PwaInstall, PwaPlatform, SoftrPwaHead, usePwaInstall } from "./pwa.js";
|
|
18
18
|
import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
19
|
-
import { Audience } from "./
|
|
19
|
+
import { Audience } from "./route/audience.js";
|
|
20
20
|
export { type ActionPermissions, Audience, type AuthOptions, type AuthSettings, AuthSettingsProvider, type DateOptions, type DateParts, type DateSeparator, type DateValue, DefaultErrorOverlay, type FieldShape, type FileAttachment, type FileItem, type FixedDateFormat, FormattedDate, type Formatting, FormattingScope, type Page, type PageSettings, type PwaInstall, type PwaPlatform, type SoftrContext, type SoftrDatasources, type SoftrFieldRegistry, SoftrPwaHead, type SoftrUserGroupId, type SoftrUserGroups, type User, type WeekDay, assertRouteAccess, checkAccess, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useFileUpload } from "./core/use-file-upload.js";
|
|
2
2
|
import { defineIntegration, defineMutation, defineQuery, defineWorkflow } from "./action.js";
|
|
3
|
-
import { checkAccess, defineVisibility, isAuthorized } from "./
|
|
4
|
-
import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./
|
|
5
|
-
import { definePage, pageHead } from "./
|
|
3
|
+
import { checkAccess, defineVisibility, isAuthorized } from "./route/visibility.js";
|
|
4
|
+
import { assertRouteAccess, guardRoute, isAccessError, isAlreadyAuthenticatedError, isForbiddenError, isUnauthenticatedError } from "./route/route.js";
|
|
5
|
+
import { definePage, pageHead } from "./route/page.js";
|
|
6
6
|
import { toReturnPath } from "./auth/returnPath.js";
|
|
7
7
|
import { FormattedDate, FormattingScope, formatDate, formatDateTime, formatNumber, useFormatting } from "./formatting.js";
|
|
8
8
|
import { SoftrPwaHead, usePwaInstall } from "./pwa.js";
|
|
@@ -12,6 +12,6 @@ import { fieldShape, formatDuration, formatField, formatValue, registerSoftrFiel
|
|
|
12
12
|
import { useOverrides } from "./core/use-overrides.js";
|
|
13
13
|
import { useUserTimezone } from "./timezone.js";
|
|
14
14
|
import { DefaultErrorOverlay } from "./default-error-overlay.js";
|
|
15
|
-
import { Audience } from "./
|
|
15
|
+
import { Audience } from "./route/audience.js";
|
|
16
16
|
|
|
17
17
|
export { Audience, AuthSettingsProvider, DefaultErrorOverlay, FormattedDate, FormattingScope, SoftrPwaHead, assertRouteAccess, checkAccess, defineIntegration, defineMutation, definePage, defineQuery, defineVisibility, defineWorkflow, fieldShape, formatDate, formatDateTime, formatDuration, formatField, formatNumber, formatValue, getAuthSettings, getSoftrContext, guardRoute, initialSoftrContext, isAccessError, isAlreadyAuthenticatedError, isAuthorized, isForbiddenError, isUnauthenticatedError, pageHead, registerSoftrFields, softrAuthMiddleware, softrMcpMiddleware, toReturnPath, useAuthSettings, useCurrentUser, useFileUpload, useFormatting, useOverrides, usePwaInstall, useUserTimezone };
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DatasourceAction } from "./action.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _tanstack_react_start5 from "@tanstack/react-start";
|
|
3
3
|
|
|
4
4
|
//#region src/mcp.d.ts
|
|
5
5
|
|
|
@@ -31,6 +31,6 @@ type SoftrMcpOptions = {
|
|
|
31
31
|
* ],
|
|
32
32
|
* }))
|
|
33
33
|
*/
|
|
34
|
-
declare function softrMcpMiddleware(options?: SoftrMcpOptions):
|
|
34
|
+
declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start5.RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
35
35
|
//#endregion
|
|
36
36
|
export { softrMcpMiddleware };
|
package/dist/package.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { checkAccess } from "./visibility.js";
|
|
2
2
|
import { useCurrentUser } from "../auth/isomorphic.js";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/route/audience.tsx
|
|
5
5
|
/**
|
|
6
6
|
* Renders `children` to the visitors a rule admits, and `fallback` to the rest.
|
|
7
7
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { VisibilityRule } from "./visibility.js";
|
|
2
2
|
import { AnyRouteMatch } from "@tanstack/react-router";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/route/page.d.ts
|
|
5
5
|
/** The part of TanStack's `head` context a page setting can read. */
|
|
6
6
|
type HeadContext = {
|
|
7
7
|
match: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AccessContext, AccessReason, Narrowed, VisibilityRule } from "./visibility.js";
|
|
2
2
|
import { Page, PageSettings } from "./page.js";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/route/route.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* What a guard does when it denies a visitor: redirect to a path, or throw an
|
|
@@ -3,7 +3,7 @@ import { ACCESS_REASONS, checkRule } from "./visibility.js";
|
|
|
3
3
|
import { softrConfig } from "../softr-config.js";
|
|
4
4
|
import { redirect } from "@tanstack/react-router";
|
|
5
5
|
|
|
6
|
-
//#region src/
|
|
6
|
+
//#region src/route/route.ts
|
|
7
7
|
function isAccessReason(value) {
|
|
8
8
|
return ACCESS_REASONS.some((reason) => reason === value);
|
|
9
9
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SoftrUserGroupId, User } from "../auth/user.js";
|
|
2
2
|
import { SoftrContext } from "../auth/context.js";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/route/visibility.d.ts
|
|
5
5
|
type AudienceSet = readonly ["NON_LOGGED_IN_USERS"] | readonly ["LOGGED_IN_USERS"] | readonly ["NON_LOGGED_IN_USERS", "LOGGED_IN_USERS"] | readonly ["LOGGED_IN_USERS", "NON_LOGGED_IN_USERS"];
|
|
6
6
|
/**
|
|
7
7
|
* Who may see a route or region. `customGroups` narrows only the
|
package/package.json
CHANGED
|
@@ -7,19 +7,18 @@ description: >-
|
|
|
7
7
|
sign-in (verifyAuthenticator, startAuthenticatorSetup,
|
|
8
8
|
confirmAuthenticatorSetup, skipAuthenticatorSetup) and the ones that change an
|
|
9
9
|
authenticator from a settings page (sendAuthenticatorResetCode,
|
|
10
|
-
resetAuthenticator, removeAuthenticator), the
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
and
|
|
14
|
-
with and its
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
signing in.
|
|
10
|
+
resetAuthenticator, removeAuthenticator), updateProfile for the visitor's own
|
|
11
|
+
name and photo, the emailed password links (requestPasswordReset,
|
|
12
|
+
checkPasswordLink, setPasswordWithLink), and getAuthSettings,
|
|
13
|
+
AuthSettingsProvider and useAuthSettings for which sign-in and sign-up methods
|
|
14
|
+
the app has enabled. Covers the Result shape they answer with and its error
|
|
15
|
+
codes (invalidCredentials, emailTaken, notAuthenticated, notAnImage and the
|
|
16
|
+
rest), the two-step sign-up, why a successful sign-in does not always mean the
|
|
17
|
+
visitor is signed in, and toReturnPath for where to land after signing in.
|
|
19
18
|
metadata:
|
|
20
19
|
type: sub-skill
|
|
21
20
|
library: softr-sdk
|
|
22
|
-
library_version: 0.0.
|
|
21
|
+
library_version: 0.0.71
|
|
23
22
|
---
|
|
24
23
|
|
|
25
24
|
**Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
|
|
@@ -82,6 +81,12 @@ Changing an authenticator from a settings page:
|
|
|
82
81
|
| `auth.resetAuthenticator({ code })` | Unpairs the app, so a new one can be enrolled |
|
|
83
82
|
| `auth.removeAuthenticator({ code })` | Turns the authenticator off |
|
|
84
83
|
|
|
84
|
+
Changing the visitor's own profile:
|
|
85
|
+
|
|
86
|
+
| Call | Does |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `auth.updateProfile({ fullName?, avatar? })` | Changes their name, their photo, or both. `avatar: null` removes the photo |
|
|
89
|
+
|
|
85
90
|
## Setup
|
|
86
91
|
|
|
87
92
|
`auth` is server-only, so every call sits inside a `createServerFn` handler:
|
|
@@ -451,6 +456,20 @@ All three need a signed-in visitor and answer `notAuthenticated` when there is n
|
|
|
451
456
|
|
|
452
457
|
After a reset, enrol the new app with `startAuthenticatorSetup` and `confirmAuthenticatorSetup`, which is also where the new backup codes come from. After a removal, an app that requires an authenticator asks the visitor to set one up again on their next sign-in.
|
|
453
458
|
|
|
459
|
+
### Changing the visitor's name and photo
|
|
460
|
+
|
|
461
|
+
```ts
|
|
462
|
+
const result = await auth.updateProfile({ fullName: 'Ann Lee' })
|
|
463
|
+
const result = await auth.updateProfile({ avatar: file }) // a File from an <input type="file">
|
|
464
|
+
const result = await auth.updateProfile({ avatar: null }) // removes the photo
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
It answers with the updated `User`. Pass the file through a server function that takes `FormData`. The photo must be a PNG, JPEG or GIF of at most 5 MB, or it answers `notAnImage` or `fileTooLarge`. A blank or unacceptable name answers `invalidName`.
|
|
468
|
+
|
|
469
|
+
Only some apps can store a photo. Show the photo controls only when `user.avatarEditable` is true; elsewhere a photo answers `avatarNotSupported`.
|
|
470
|
+
|
|
471
|
+
The page keeps showing the old name and photo until its route context loads again, so call `router.invalidate()` after a success.
|
|
472
|
+
|
|
454
473
|
## References
|
|
455
474
|
|
|
456
475
|
- [current-user/SKILL.md](../current-user/SKILL.md): reading the visitor these calls establish
|
|
@@ -12,7 +12,7 @@ description: >-
|
|
|
12
12
|
metadata:
|
|
13
13
|
type: sub-skill
|
|
14
14
|
library: softr-sdk
|
|
15
|
-
library_version: 0.0.
|
|
15
|
+
library_version: 0.0.71
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.71
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
# The current user
|
|
@@ -31,6 +31,8 @@ type User = {
|
|
|
31
31
|
email: string
|
|
32
32
|
fullName: string
|
|
33
33
|
userGroupIds: Array<SoftrUserGroupId> // the app's own group ids
|
|
34
|
+
avatarUrl: string | null // their photo; show their initials when null
|
|
35
|
+
avatarEditable: boolean // whether auth.updateProfile can change the photo
|
|
34
36
|
}
|
|
35
37
|
```
|
|
36
38
|
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 0.0.
|
|
13
|
+
library_version: 0.0.71
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk` and run in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
|
|
@@ -10,7 +10,7 @@ description: >-
|
|
|
10
10
|
metadata:
|
|
11
11
|
type: sub-skill
|
|
12
12
|
library: softr-sdk
|
|
13
|
-
library_version: 0.0.
|
|
13
|
+
library_version: 0.0.71
|
|
14
14
|
---
|
|
15
15
|
|
|
16
16
|
**Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.71
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `softrMcpMiddleware` lives on `@softr/sdk` and is registered once, in `src/start.ts`. The actions you hand it are the same `defineQuery` / `defineMutation` values the app's own pages use — declared wherever they already live, not duplicated for MCP.
|
|
@@ -11,7 +11,7 @@ description: >-
|
|
|
11
11
|
metadata:
|
|
12
12
|
type: sub-skill
|
|
13
13
|
library: softr-sdk
|
|
14
|
-
library_version: 0.0.
|
|
14
|
+
library_version: 0.0.71
|
|
15
15
|
---
|
|
16
16
|
|
|
17
17
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineMutation` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 0.0.
|
|
16
|
+
library_version: 0.0.71
|
|
17
17
|
---
|
|
18
18
|
|
|
19
19
|
**Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. The same holds for any helper that calls `ds`: declare it inside the handler. A function at module level that calls `ds` keeps the server-only import in the browser bundle, and every page stops loading until it moves. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere.
|
|
@@ -9,7 +9,7 @@ description: >-
|
|
|
9
9
|
metadata:
|
|
10
10
|
type: sub-skill
|
|
11
11
|
library: softr-sdk
|
|
12
|
-
library_version: 0.0.
|
|
12
|
+
library_version: 0.0.71
|
|
13
13
|
---
|
|
14
14
|
|
|
15
15
|
**Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere.
|