@softr/sdk 0.0.97 → 0.0.98

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.
@@ -7,7 +7,10 @@ import { Permissions } from "./permissions.js";
7
7
  type Session = {
8
8
  /** The visitor, or `null` when signed out. */
9
9
  user: User | null;
10
- /** The visitor's global data restrictions. An escape hatch; the SDK already checks them. */
10
+ /**
11
+ * The visitor's global data restrictions. An escape hatch; the SDK already checks them.
12
+ * @deprecated Always empty.
13
+ */
11
14
  permissions: Permissions;
12
15
  };
13
16
  /**
@@ -42,6 +42,7 @@ function softrAuthMiddleware() {
42
42
  ]).server(async ({ next }) => {
43
43
  async function getSession() {
44
44
  const token = readSessionToken();
45
+ if (token === null) return { user: null };
45
46
  if (process.env.NODE_ENV === "production") {
46
47
  const cached = readSessionData(token);
47
48
  if (cached !== null) return cached;
@@ -49,7 +50,7 @@ function softrAuthMiddleware() {
49
50
  const result = await makePlatform(sessionConfig().applicationId).session(token);
50
51
  if (!result.ok) panic(result.message);
51
52
  const session = result.data;
52
- if (token !== null && session.user === null) {
53
+ if (session.user === null) {
53
54
  clearSession();
54
55
  return session;
55
56
  }
@@ -46,10 +46,7 @@ async function confirmAuthenticatorSetup(details) {
46
46
  throw new Error(`${result.message}. Check SOFTR_APPLICATION_ID and that the app allows an authenticator app.`);
47
47
  }
48
48
  const { session, backupCodes } = result.data;
49
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
50
- user: session.user,
51
- permissions: session.permissions
52
- }, session.jwt)]);
49
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
53
50
  clearPendingAuth();
54
51
  return {
55
52
  success: true,
@@ -75,10 +72,7 @@ async function skipAuthenticatorSetup() {
75
72
  }
76
73
  const { session } = result.data;
77
74
  assert(session, "Expected a session from skipping setup, but got none");
78
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
79
- user: session.user,
80
- permissions: session.permissions
81
- }, session.jwt)]);
75
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
82
76
  clearPendingAuth();
83
77
  return {
84
78
  success: true,
@@ -101,10 +95,7 @@ async function verifyAuthenticator(credentials) {
101
95
  }
102
96
  const { session } = result.data;
103
97
  assert(session, "Expected a session from verification, but got none");
104
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
105
- user: session.user,
106
- permissions: session.permissions
107
- }, session.jwt)]);
98
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
108
99
  clearPendingAuth();
109
100
  return {
110
101
  success: true,
@@ -56,10 +56,7 @@ async function signInWithCode(credentials) {
56
56
  }
57
57
  const { session } = result.data;
58
58
  assert(session, "Expected a session from sign-in, but got none");
59
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
60
- user: session.user,
61
- permissions: session.permissions
62
- }, session.jwt)]);
59
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
63
60
  clearPendingAuth();
64
61
  return {
65
62
  success: true,
@@ -36,10 +36,7 @@ async function verifyEmailCode(details) {
36
36
  }
37
37
  const { session } = result.data;
38
38
  assert(session, "Expected a session from verification, but got none");
39
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
40
- user: session.user,
41
- permissions: session.permissions
42
- }, session.jwt)]);
39
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
43
40
  clearPendingAuth();
44
41
  return {
45
42
  success: true,
@@ -36,10 +36,7 @@ async function signInWithMagicLink(credentials) {
36
36
  }
37
37
  const { session } = result.data;
38
38
  assert(session, "Expected a session from magic-link sign-in, but got none");
39
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
40
- user: session.user,
41
- permissions: session.permissions
42
- }, session.jwt)]);
39
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
43
40
  return {
44
41
  success: true,
45
42
  data: {
@@ -40,10 +40,7 @@ async function signIn(credentials) {
40
40
  }
41
41
  const { session } = result.data;
42
42
  assert(session, "Expected a session from sign-in, but got none");
43
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
44
- user: session.user,
45
- permissions: session.permissions
46
- }, session.jwt)]);
43
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
47
44
  clearPendingAuth();
48
45
  return {
49
46
  success: true,
@@ -68,10 +68,7 @@ async function setPasswordWithLink(details) {
68
68
  }
69
69
  const { session } = result.data;
70
70
  assert(session, "Expected a session from setting a password, but got none");
71
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
72
- user: session.user,
73
- permissions: session.permissions
74
- }, session.jwt)]);
71
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
75
72
  clearPendingAuth();
76
73
  return {
77
74
  success: true,
@@ -66,10 +66,7 @@ async function confirmSignUp(details) {
66
66
  }
67
67
  const { session } = result.data;
68
68
  assert(session, "Expected a session from sign-up, but got none");
69
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
70
- user: session.user,
71
- permissions: session.permissions
72
- }, session.jwt)]);
69
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
73
70
  clearPendingAuth();
74
71
  return {
75
72
  success: true,
@@ -41,10 +41,7 @@ async function signInWithGoogle(credentials) {
41
41
  }
42
42
  const { session } = result.data;
43
43
  assert(session, "Expected a session from Google sign-in, but got none");
44
- writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({
45
- user: session.user,
46
- permissions: session.permissions
47
- }, session.jwt)]);
44
+ writeCookies([...makeSessionTokenCookie(session.jwt), makeSessionDataCookie({ user: session.user }, session.jwt)]);
48
45
  clearPendingAuth();
49
46
  return {
50
47
  success: true,
@@ -1,7 +1,4 @@
1
- import { z } from "zod";
2
-
3
1
  //#region src/auth/permissions.d.ts
4
-
5
2
  /**
6
3
  * What the visitor may do in this app, as the platform sees it.
7
4
  *
@@ -2,7 +2,6 @@ import { assert, panic } from "../assertions.js";
2
2
  import { softrApiUrl } from "../softr-api.js";
3
3
  import { fetch } from "../fetch.js";
4
4
  import { softrConfig } from "../softr-config.js";
5
- import { permissionsSchema } from "./permissions.js";
6
5
  import { z } from "zod";
7
6
 
8
7
  //#region src/auth/platform.ts
@@ -61,10 +60,7 @@ function makePlatform(applicationId) {
61
60
  const result = await request(`/v1/vibe/applications/${applicationId}/users/session${withAttributes}`, {
62
61
  method: "GET",
63
62
  token
64
- }, z.object({
65
- user: userSchema.nullable(),
66
- permissions: permissionsSchema
67
- }));
63
+ }, z.object({ user: userSchema.nullable() }));
68
64
  if (result.status === 404) panic(`Application ${applicationId} not found. Check SOFTR_APPLICATION_ID.`);
69
65
  return result;
70
66
  },
@@ -75,8 +71,7 @@ function makePlatform(applicationId) {
75
71
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
76
72
  session: z.object({
77
73
  jwt: z.string(),
78
- user: userSchema,
79
- permissions: permissionsSchema
74
+ user: userSchema
80
75
  }).nullish(),
81
76
  mfa: z.object({
82
77
  action: z.enum([
@@ -96,8 +91,7 @@ function makePlatform(applicationId) {
96
91
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
97
92
  session: z.object({
98
93
  jwt: z.string(),
99
- user: userSchema,
100
- permissions: permissionsSchema
94
+ user: userSchema
101
95
  }).nullish(),
102
96
  mfa: z.object({
103
97
  action: z.enum([
@@ -123,8 +117,7 @@ function makePlatform(applicationId) {
123
117
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
124
118
  session: z.object({
125
119
  jwt: z.string(),
126
- user: userSchema,
127
- permissions: permissionsSchema
120
+ user: userSchema
128
121
  }).nullish(),
129
122
  mfa: z.object({
130
123
  action: z.enum([
@@ -142,8 +135,7 @@ function makePlatform(applicationId) {
142
135
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
143
136
  session: z.object({
144
137
  jwt: z.string(),
145
- user: userSchema,
146
- permissions: permissionsSchema
138
+ user: userSchema
147
139
  }).nullish(),
148
140
  mfa: z.object({
149
141
  action: z.enum([
@@ -161,8 +153,7 @@ function makePlatform(applicationId) {
161
153
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
162
154
  session: z.object({
163
155
  jwt: z.string(),
164
- user: userSchema,
165
- permissions: permissionsSchema
156
+ user: userSchema
166
157
  }).nullish(),
167
158
  mfa: z.object({
168
159
  action: z.enum([
@@ -188,8 +179,7 @@ function makePlatform(applicationId) {
188
179
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
189
180
  session: z.object({
190
181
  jwt: z.string(),
191
- user: userSchema,
192
- permissions: permissionsSchema
182
+ user: userSchema
193
183
  }).nullish(),
194
184
  mfa: z.object({
195
185
  action: z.enum([
@@ -211,8 +201,7 @@ function makePlatform(applicationId) {
211
201
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
212
202
  session: z.object({
213
203
  jwt: z.string(),
214
- user: userSchema,
215
- permissions: permissionsSchema
204
+ user: userSchema
216
205
  }).nullish(),
217
206
  mfa: z.object({
218
207
  action: z.enum([
@@ -230,8 +219,7 @@ function makePlatform(applicationId) {
230
219
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
231
220
  session: z.object({
232
221
  jwt: z.string(),
233
- user: userSchema,
234
- permissions: permissionsSchema
222
+ user: userSchema
235
223
  }).nullish(),
236
224
  mfa: z.object({
237
225
  action: z.enum([
@@ -256,8 +244,7 @@ function makePlatform(applicationId) {
256
244
  }, z.object({
257
245
  session: z.object({
258
246
  jwt: z.string(),
259
- user: userSchema,
260
- permissions: permissionsSchema
247
+ user: userSchema
261
248
  }),
262
249
  backupCodes: z.array(z.string())
263
250
  })),
@@ -268,8 +255,7 @@ function makePlatform(applicationId) {
268
255
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
269
256
  session: z.object({
270
257
  jwt: z.string(),
271
- user: userSchema,
272
- permissions: permissionsSchema
258
+ user: userSchema
273
259
  }).nullish(),
274
260
  mfa: z.object({
275
261
  action: z.enum([
@@ -288,8 +274,7 @@ function makePlatform(applicationId) {
288
274
  status: z.enum(["AUTHENTICATED", "MFA_REQUIRED"]),
289
275
  session: z.object({
290
276
  jwt: z.string(),
291
- user: userSchema,
292
- permissions: permissionsSchema
277
+ user: userSchema
293
278
  }).nullish(),
294
279
  mfa: z.object({
295
280
  action: z.enum([
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.97";
2
+ var version = "0.0.98";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "0.0.97",
3
+ "version": "0.0.98",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: core
11
11
  library: softr-sdk
12
- library_version: 0.0.97
12
+ library_version: 0.0.98
13
13
  ---
14
14
 
15
15
  # Softr SDK core
@@ -13,7 +13,7 @@ description: >-
13
13
  metadata:
14
14
  type: sub-skill
15
15
  library: softr-sdk
16
- library_version: 0.0.97
16
+ library_version: 0.0.98
17
17
  ---
18
18
 
19
19
  **Boundary.** `ai` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineAiAction` 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.97
12
+ library_version: 0.0.98
13
13
  ---
14
14
 
15
15
  **Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.97
12
+ library_version: 0.0.98
13
13
  ---
14
14
 
15
15
  **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.97
12
+ library_version: 0.0.98
13
13
  ---
14
14
 
15
15
  # The current user
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 0.0.97
10
+ library_version: 0.0.98
11
11
  ---
12
12
 
13
13
  **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.
@@ -8,7 +8,7 @@ description: >-
8
8
  metadata:
9
9
  type: sub-skill
10
10
  library: softr-sdk
11
- library_version: 0.0.97
11
+ library_version: 0.0.98
12
12
  ---
13
13
 
14
14
  # Dates, times and numbers
@@ -7,7 +7,7 @@ description: >-
7
7
  metadata:
8
8
  type: sub-skill
9
9
  library: softr-sdk
10
- library_version: 0.0.97
10
+ library_version: 0.0.98
11
11
  ---
12
12
 
13
13
  **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.97
12
+ library_version: 0.0.98
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.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.97
12
+ library_version: 0.0.98
13
13
  ---
14
14
 
15
15
  # Installing the app
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.97
12
+ library_version: 0.0.98
13
13
  ---
14
14
 
15
15
  **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.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 0.0.97
13
+ library_version: 0.0.98
14
14
  ---
15
15
 
16
16
  **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.97
12
+ library_version: 0.0.98
13
13
  ---
14
14
 
15
15
  **Boundary.** `Audience` and `defineVisibility` come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.97
12
+ library_version: 0.0.98
13
13
  ---
14
14
 
15
15
  **Boundary.** `definePage`, `pageHead`, the access functions and the error predicates come from `@softr/sdk` and work anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.97
12
+ library_version: 0.0.98
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.
@@ -1,13 +0,0 @@
1
- import { z } from "zod";
2
-
3
- //#region src/auth/permissions.ts
4
- const datasourcePermissionsSchema = z.object({
5
- read: z.boolean(),
6
- create: z.boolean(),
7
- update: z.boolean(),
8
- delete: z.boolean()
9
- });
10
- const permissionsSchema = z.object({ datasources: z.record(z.string(), datasourcePermissionsSchema) });
11
-
12
- //#endregion
13
- export { permissionsSchema };