@softr/sdk 1.1.2-alpha.0 → 1.2.1-alpha.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @softr/sdk
2
2
 
3
+ ## 1.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - `SoftrPwaHead` now gives iOS the app's home screen name and launch screens, so an installed app opens on its splash screen instead of white and Add to Home Screen suggests the app's name, not the page title. An app already on an iPhone home screen picks this up only after it is removed and added again.
8
+
9
+ ## 1.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - `defineMutation` takes an optional `filter` with its `filterFields` on an update or a delete. `ds.update` and `ds.delete` first check that the record matches the filter. A record that does not match throws "not found", and nothing is written. An update cannot list in `fields` a field that its filter compares with a user token.
14
+
3
15
  ## 1.1.1
4
16
 
5
17
  ### Patch Changes
package/dist/action.d.ts CHANGED
@@ -71,7 +71,7 @@ type DatasourceResource = {
71
71
  datasourceId: SoftrDatasourceId;
72
72
  operation: ActionOperation;
73
73
  fields?: Record<string, string>;
74
- /** The fields that the filter reads, by alias. A read returns only `fields`. */
74
+ /** The fields that the filter reads, by alias. Only `fields` are read or written. */
75
75
  filterFields?: Record<string, string>;
76
76
  /** The enforced filter, keyed by alias, with its tokens unresolved. */
77
77
  filter?: FilterCriteria;
@@ -112,6 +112,16 @@ type DeleteDeclaration<TId extends string, TDatasource$1> = {
112
112
  fields?: never;
113
113
  permissions: ActionPermissions;
114
114
  };
115
+ type FilterDeclaration<TId extends string, TDatasource$1 extends SoftrDatasourceId, TFilterFields extends Record<string, string>> = {
116
+ /** The fields that `filter` reads, by alias. A user can write them only if `fields` lists them too. */
117
+ filterFields?: TFilterFields;
118
+ filter?: EnforcedFilter<{
119
+ id: TId;
120
+ datasourceId: TDatasource$1;
121
+ operation: "read";
122
+ fields: NoInfer<TFilterFields>;
123
+ }>;
124
+ };
115
125
  /**
116
126
  * Declares a read: which datasource, which fields participate, and who may run it.
117
127
  *
@@ -160,6 +170,14 @@ declare function defineQuery<const TId extends string, const TDatasource$1 exten
160
170
  *
161
171
  * The argument must be a static object.
162
172
  *
173
+ * An update or delete can have a `filter`, with the same operators and tokens as in
174
+ * `defineQuery`. Its keys are aliases of `filterFields`. Before each write, `ds` reads the record
175
+ * through the filter. A record that does not match gives a "not found" error, and nothing is
176
+ * written. A condition on a user token matches no record for a visitor who is signed out.
177
+ *
178
+ * An update cannot write a field that its filter compares with a user token, such as an owner.
179
+ * Otherwise a user could give the record to another user.
180
+ *
163
181
  * @example
164
182
  * const closeOrder = defineMutation({
165
183
  * id: "closeOrder",
@@ -180,14 +198,34 @@ declare function defineQuery<const TId extends string, const TDatasource$1 exten
180
198
  * })
181
199
  *
182
200
  * await ds.delete(removeOrder, { id })
201
+ *
202
+ * @example
203
+ * const editMyRequest = defineMutation({
204
+ * id: "editMyRequest",
205
+ * datasourceId: "8f14e45f-ceea-467a-9d0b-2c1a0e3b5d77",
206
+ * operation: "update",
207
+ * fields: { title: "V1StGXR8", details: "Xp2dLh6v" },
208
+ * filterFields: { requesterEmail: "Z7pQm4Kd" },
209
+ * filter: { requesterEmail: { is: "{USER:::EMAIL}" } },
210
+ * permissions: { userGroupTypes: ["LOGGED_IN_USERS"] },
211
+ * })
183
212
  */
184
- declare function defineMutation<const TId extends string, const TDatasource$1 extends SoftrDatasourceId, const TOperation$1 extends "create" | "update", const TFields$1 extends Record<string, FieldIdOf<TDatasource$1, TOperation$1>>>(definition: WriteDeclaration<TId, TDatasource$1, TOperation$1, TFields$1>): DatasourceAction<{
213
+ declare function defineMutation<const TId extends string, const TDatasource$1 extends SoftrDatasourceId, const TFields$1 extends Record<string, FieldIdOf<TDatasource$1, "update">>, const TFilterFields extends Record<string, ReadFieldIdOf<TDatasource$1>> = Record<never, never>>(definition: WriteDeclaration<TId, TDatasource$1, "update", TFields$1> & FilterDeclaration<TId, TDatasource$1, TFilterFields>): DatasourceAction<{
214
+ id: TId;
215
+ datasourceId: TDatasource$1;
216
+ operation: "update";
217
+ fields: TFields$1;
218
+ }>;
219
+ declare function defineMutation<const TId extends string, const TDatasource$1 extends SoftrDatasourceId, const TOperation$1 extends "create" | "update", const TFields$1 extends Record<string, FieldIdOf<TDatasource$1, TOperation$1>>>(definition: WriteDeclaration<TId, TDatasource$1, TOperation$1, TFields$1> & {
220
+ filterFields?: never;
221
+ filter?: never;
222
+ }): DatasourceAction<{
185
223
  id: TId;
186
224
  datasourceId: TDatasource$1;
187
225
  operation: TOperation$1;
188
226
  fields: TFields$1;
189
227
  }>;
190
- declare function defineMutation<const TId extends string, const TDatasource$1 extends SoftrDatasourceId>(definition: DeleteDeclaration<TId, TDatasource$1>): DatasourceAction<{
228
+ declare function defineMutation<const TId extends string, const TDatasource$1 extends SoftrDatasourceId, const TFilterFields extends Record<string, ReadFieldIdOf<TDatasource$1>> = Record<never, never>>(definition: DeleteDeclaration<TId, TDatasource$1> & FilterDeclaration<TId, TDatasource$1, TFilterFields>): DatasourceAction<{
191
229
  id: TId;
192
230
  datasourceId: TDatasource$1;
193
231
  operation: "delete";
package/dist/action.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { assert } from "./assertions.js";
2
- import { buildEnforcedFilter } from "./datasource/enforced-filter.js";
2
+ import { aliasesComparedWithUser, buildEnforcedFilter } from "./datasource/enforced-filter.js";
3
3
 
4
4
  //#region src/action.ts
5
5
  function defineQuery(definition) {
@@ -19,14 +19,24 @@ function defineQuery(definition) {
19
19
  };
20
20
  }
21
21
  function defineMutation(definition) {
22
- const { id, datasourceId, operation, fields, permissions } = definition;
22
+ const { id, datasourceId, operation, fields, filterFields, filter, permissions } = definition;
23
+ assert(filter === void 0 === (filterFields === void 0), () => `defineMutation "${id}": declare filter and filterFields together. The filter names aliases of filterFields.`);
24
+ assert(filter === void 0 || operation === "update" || operation === "delete", () => `defineMutation "${id}": a ${operation} mutation takes no filter. Only an update or a delete has one.`);
25
+ const enforced = filter === void 0 ? void 0 : buildEnforcedFilter(filter, Object.keys(filterFields ?? {}));
26
+ if (operation === "update" && enforced !== void 0) for (const [alias, token] of aliasesComparedWithUser(enforced.filterConditionGroup)) {
27
+ const fieldId = filterFields?.[alias];
28
+ const written = Object.entries(fields ?? {}).find(([, writtenId]) => writtenId === fieldId);
29
+ assert(written === void 0, () => `defineMutation "${id}": "${written?.[0]}" in fields writes ${fieldId}, and the filter compares that field with "${token}". A user could then give the record to another user. Remove "${written?.[0]}" from fields. If some users must reassign records, declare a separate mutation for them, with its own permissions and without this filter.`);
30
+ }
23
31
  return {
24
32
  id,
25
33
  resource: {
26
34
  type: "DATASOURCE",
27
35
  datasourceId,
28
36
  operation,
29
- fields
37
+ fields,
38
+ filterFields,
39
+ filter: enforced
30
40
  },
31
41
  permissions
32
42
  };
@@ -58,6 +58,19 @@ function readStandInUser() {
58
58
  scope.user ??= makePlatform(sessionConfig().applicationId).session(scope.token).then((result) => result.ok ? result.data.user : panic(result.message));
59
59
  return scope.user;
60
60
  }
61
+ /**
62
+ * The visitor, fetched from the platform now and not from the 5-minute session
63
+ * cache. A write checks its filter with this visitor. So a user who just lost a
64
+ * value, for example a team, cannot write through the old one.
65
+ */
66
+ async function readFreshUser() {
67
+ const standIn$1 = readStandInUser();
68
+ if (standIn$1 !== void 0) return standIn$1;
69
+ const token = readSessionToken();
70
+ if (token === null) return null;
71
+ const result = await makePlatform(sessionConfig().applicationId).session(token);
72
+ return result.ok ? result.data.user : panic(result.message);
73
+ }
61
74
  /** The platform token this request carries, or `null`. */
62
75
  function readSessionToken() {
63
76
  const scope = standIn.getStore();
@@ -228,4 +241,4 @@ function openEnvelope(raw, purpose) {
228
241
  }
229
242
 
230
243
  //#endregion
231
- export { clearPendingAuth, clearSession, clearSessionData, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readPendingAuthToken, readSessionData, readSessionToken, readStandInUser, withSessionToken };
244
+ export { clearPendingAuth, clearSession, clearSessionData, makePendingAuthCookie, makeSessionDataCookie, makeSessionTokenCookie, readFreshUser, readPendingAuthToken, readSessionData, readSessionToken, readStandInUser, withSessionToken };
@@ -32,7 +32,7 @@ function buildEnforcedFilter(declared, aliases) {
32
32
  return value.map(toConstructable);
33
33
  }
34
34
  function conditions(alias, value) {
35
- assert(aliases.includes(alias), () => `the filter names "${alias}", which is not one of the query's filterFields`);
35
+ assert(aliases.includes(alias), () => `the filter names "${alias}", which is not one of filterFields`);
36
36
  assert(isObject(value) && Object.keys(value).length > 0, () => `"${alias}" in the filter needs at least one operator`);
37
37
  const chain = makeChain(alias);
38
38
  return Object.entries(value).map(([operator, argument]) => {
@@ -60,6 +60,19 @@ function buildEnforcedFilter(declared, aliases) {
60
60
  function readsVisitor(group$1) {
61
61
  return values(group$1).some((value) => typeof value === "string" && USER_TOKEN.test(value));
62
62
  }
63
+ /** Each alias that the filter compares with a user token, with the first such token. */
64
+ function aliasesComparedWithUser(group$1) {
65
+ const compared = /* @__PURE__ */ new Map();
66
+ visit(group$1);
67
+ return compared;
68
+ function visit({ filters, filterGroups }) {
69
+ for (const filter of filters) {
70
+ const token = (Array.isArray(filter.value) ? filter.value : [filter.value]).find((value) => typeof value === "string" && USER_TOKEN.test(value));
71
+ if (token !== void 0 && !compared.has(filter.subject)) compared.set(filter.subject, token);
72
+ }
73
+ filterGroups.forEach(visit);
74
+ }
75
+ }
63
76
  /**
64
77
  * The part of the filter that can match rows for this visitor, or `null` when no part can.
65
78
  *
@@ -124,4 +137,4 @@ function isObject(value) {
124
137
  }
125
138
 
126
139
  //#endregion
127
- export { buildEnforcedFilter, filterForVisitor, readsVisitor };
140
+ export { aliasesComparedWithUser, buildEnforcedFilter, filterForVisitor, readsVisitor };
@@ -1,3 +1,4 @@
1
+ import "../auth/user.js";
1
2
  import { AnyConstructable, ConstructableOrderBy } from "./filter.js";
2
3
  import { FieldSet, SortSet } from "./fields.js";
3
4
  import { ActionData, ActionRecord, ActionShape, DatasourceAction, ReadShape } from "../action.js";
@@ -3,7 +3,7 @@ import { softrApiUrl } from "../softr-api.js";
3
3
  import { fetch } from "../fetch.js";
4
4
  import { softrConfig } from "../softr-config.js";
5
5
  import { readUserTimezone } from "../cookies.js";
6
- import { readSessionToken, readStandInUser } from "../auth/session.js";
6
+ import { readFreshUser, readSessionToken, readStandInUser } from "../auth/session.js";
7
7
  import { andGroups, buildFilterCriteria, buildOrderBy, dealiasFilterCriteria, dealiasOrderBy } from "./filter.js";
8
8
  import { andAll, makeFieldSet, makeSortSet } from "./fields.js";
9
9
  import { filterForVisitor, readsVisitor } from "./enforced-filter.js";
@@ -211,6 +211,7 @@ async function createRecord(action, options) {
211
211
  method: "POST",
212
212
  headers: {
213
213
  "Content-Type": "application/json",
214
+ "X-User-Timezone": readUserTimezone() ?? "UTC",
214
215
  Authorization: `Bearer ${readSessionToken()}`,
215
216
  ...refererHeader()
216
217
  },
@@ -234,13 +235,16 @@ async function createRecord(action, options) {
234
235
  */
235
236
  async function updateRecord(action, options) {
236
237
  if (!options.id) throw new Error(`datasource update: id must not be empty`);
237
- const { actionId, select } = resolveTarget(action, "update");
238
+ const target = resolveTarget(action, "update");
239
+ const { actionId, select } = target;
240
+ await requireFilterMatch(target, options.id, "update");
238
241
  const data = options.data;
239
242
  const rawFields = dealiasData(data, select);
240
243
  const res = await fetch(`${dsUrl(actionId)}/records/${options.id}`, {
241
244
  method: "PATCH",
242
245
  headers: {
243
246
  "Content-Type": "application/json",
247
+ "X-User-Timezone": readUserTimezone() ?? "UTC",
244
248
  Authorization: `Bearer ${readSessionToken()}`,
245
249
  ...refererHeader()
246
250
  },
@@ -260,10 +264,13 @@ async function updateRecord(action, options) {
260
264
  * await ds.delete(removePost, { id: "record-id" })
261
265
  */
262
266
  async function deleteRecord(action, options) {
263
- const { actionId } = resolveTarget(action, "delete");
267
+ const target = resolveTarget(action, "delete");
268
+ const { actionId } = target;
269
+ await requireFilterMatch(target, options.id, "delete");
264
270
  const res = await fetch(`${dsUrl(actionId)}/records/${options.id}`, {
265
271
  method: "DELETE",
266
272
  headers: {
273
+ "X-User-Timezone": readUserTimezone() ?? "UTC",
267
274
  Authorization: `Bearer ${readSessionToken()}`,
268
275
  ...refererHeader()
269
276
  }
@@ -283,17 +290,62 @@ function resolveTarget(subject, operation) {
283
290
  };
284
291
  }
285
292
  /**
293
+ * The id suffix of the READ action that app-sync declares for each mutation with a filter.
294
+ *
295
+ * Never change it. App-sync ships with the pod, and an app keeps the SDK version it pinned, so the
296
+ * two can differ in age and still must agree.
297
+ */
298
+ const FILTER_CHECK_SUFFIX = "__check";
299
+ /**
300
+ * Before an update or a delete, reads the record through the mutation's filter. It reads with the
301
+ * READ action that app-sync declares for the mutation, because the datasource refuses a read through
302
+ * a write action. A record that does not match throws "not found", and the caller sends no write.
303
+ *
304
+ * The record can still change between this read and the write. Another request can change a field
305
+ * that the filter reads, and a date token can pass midnight. Only the fields that the filter
306
+ * compares with a user token stay out of reach of this mutation, because `defineMutation` keeps
307
+ * them out of `fields`.
308
+ */
309
+ async function requireFilterMatch(target, id, operation) {
310
+ if (target.filter === void 0) return;
311
+ const check = {
312
+ actionId: `${target.actionId}${FILTER_CHECK_SUFFIX}`,
313
+ select: {},
314
+ filterFields: target.filterFields,
315
+ filter: target.filter
316
+ };
317
+ const notFound = () => /* @__PURE__ */ new Error(`datasource ${operation} failed for action "${target.actionId}": record "${id}" not found`);
318
+ const filterCriteria = await readFilterCriteria(check, [], readFreshUser);
319
+ if (filterCriteria === null) throw notFound();
320
+ const res = await fetch(`${dsUrl(check.actionId)}/records/${id}`, {
321
+ method: "POST",
322
+ headers: {
323
+ "Content-Type": "application/json",
324
+ "X-User-Timezone": readUserTimezone() ?? "UTC",
325
+ Authorization: `Bearer ${readSessionToken()}`,
326
+ ...refererHeader()
327
+ },
328
+ body: JSON.stringify({
329
+ options: { userLocale: "en-US" },
330
+ filterCriteria
331
+ })
332
+ });
333
+ if (res.status === 404) throw notFound();
334
+ if (!res.ok) throw new Error(`datasource ${operation} failed for action "${target.actionId}": ${await describeFailure(res)}`);
335
+ if (await res.text() === "") throw notFound();
336
+ }
337
+ /**
286
338
  * The filter a read sends: the query's enforced filter, with its tokens, AND the `where`
287
339
  * filters. `null` when the enforced filter matches no rows for this visitor. The read then sends
288
340
  * no request and returns nothing.
289
341
  */
290
- async function readFilterCriteria(target, filters) {
342
+ async function readFilterCriteria(target, filters, readUser = async () => readStandInUser() ?? readSoftrContext().user) {
291
343
  const groups = [];
292
344
  const enforced = target.filter?.filterConditionGroup;
293
345
  if (enforced !== void 0) {
294
- const forVisitor = readsVisitor(enforced) ? filterForVisitor(enforced, await readVisitor()) : enforced;
346
+ const forVisitor = readsVisitor(enforced) ? filterForVisitor(enforced, toVisitor(await readUser())) : enforced;
295
347
  if (forVisitor === null) return null;
296
- groups.push(dealias(forVisitor, requireDefined(target.filterFields, "defineQuery declares filterFields with a filter")));
348
+ groups.push(dealias(forVisitor, requireDefined(target.filterFields, "an action with a filter declares filterFields")));
297
349
  }
298
350
  const requested = filters.length ? buildFilterCriteria(andAll(filters)).filterConditionGroup : void 0;
299
351
  if (requested !== void 0) groups.push(dealias(requested, target.select));
@@ -303,8 +355,7 @@ async function readFilterCriteria(target, filters) {
303
355
  return requireDefined(dealiasFilterCriteria({ filterConditionGroup: group }, aliases).filterConditionGroup);
304
356
  }
305
357
  }
306
- async function readVisitor() {
307
- const user = await (readStandInUser() ?? readSoftrContext().user);
358
+ function toVisitor(user) {
308
359
  if (user === null) return null;
309
360
  const properties = user.properties;
310
361
  const aliasOf = new Map(Object.entries(softrConfig().user?.properties ?? {}).map(([alias, fieldId]) => [fieldId, alias]));
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import * as react2 from "react";
2
+ import * as react0 from "react";
3
3
  import { ReactNode } from "react";
4
4
 
5
5
  //#region src/formatting.d.ts
@@ -96,7 +96,7 @@ declare function FormattingScope({
96
96
  /** A BCP 47 locale, such as `de-DE`. It drops the app's fixed date format inside the scope. */
97
97
  locale?: string;
98
98
  children?: ReactNode;
99
- }): react2.FunctionComponentElement<react2.ProviderProps<Scope>>;
99
+ }): react0.FunctionComponentElement<react0.ProviderProps<Scope>>;
100
100
  /**
101
101
  * A date in the app's format, safe to render on the server. A timestamp whose
102
102
  * zone is not known yet renders `fallback` until the browser supplies it, so
@@ -118,6 +118,6 @@ declare function FormattedDate({
118
118
  time?: boolean;
119
119
  /** What renders while the visitor's zone is unknown. */
120
120
  fallback?: ReactNode;
121
- }): react2.FunctionComponentElement<react2.FragmentProps> | null;
121
+ }): react0.FunctionComponentElement<react0.FragmentProps> | null;
122
122
  //#endregion
123
123
  export { DateOptions, DateParts, DateSeparator, DateValue, FixedDateFormat, FormattedDate, Formatting, FormattingScope, WeekDay, formatDate, formatDateTime, formatNumber, useFormatting };
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DatasourceAction } from "./action.js";
2
- import * as _tanstack_react_start0 from "@tanstack/react-start";
2
+ import * as _tanstack_react_start8 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): _tanstack_react_start0.RequestMiddlewareAfterServer<{}, undefined, undefined>;
34
+ declare function softrMcpMiddleware(options?: SoftrMcpOptions): _tanstack_react_start8.RequestMiddlewareAfterServer<{}, undefined, undefined>;
35
35
  //#endregion
36
36
  export { softrMcpMiddleware };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "1.1.2-alpha.0";
2
+ var version = "1.2.1-alpha.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/dist/pwa.d.ts CHANGED
@@ -1,11 +1,12 @@
1
- import * as react0 from "react";
1
+ import * as react4 from "react";
2
2
  import "@tanstack/react-start";
3
3
 
4
4
  //#region src/pwa.d.ts
5
5
 
6
6
  /**
7
- * The links that make the app installable: its manifest and its home screen
8
- * icon. Render it once, in `<head>` in the root route's `RootDocument`.
7
+ * The tags that make the app installable: its manifest, its home screen icon,
8
+ * and, while the app is installable, the name and launch screens iOS shows.
9
+ * Render it once, in `<head>` in the root route's `RootDocument`.
9
10
  *
10
11
  * @example
11
12
  * function RootDocument({ children }: { children: React.ReactNode }) {
@@ -23,7 +24,7 @@ import "@tanstack/react-start";
23
24
  * )
24
25
  * }
25
26
  */
26
- declare function SoftrPwaHead(): react0.FunctionComponentElement<react0.FragmentProps>;
27
+ declare function SoftrPwaHead(): react4.FunctionComponentElement<react4.FragmentProps>;
27
28
  type PwaPlatform = "ios" | "android" | "desktop";
28
29
  type PwaInstall = {
29
30
  available: false;
package/dist/pwa.js CHANGED
@@ -18,8 +18,13 @@ const pwaSchema = z.object({
18
18
  install: z.object({
19
19
  name: z.string(),
20
20
  iconUrl: z.string()
21
- })
21
+ }),
22
+ startupImages: z.array(z.object({
23
+ media: z.string(),
24
+ href: z.string()
25
+ })).default([])
22
26
  });
27
+ const iosHeadSchema = pwaSchema.pick({ startupImages: true }).extend({ name: z.string() });
23
28
  let cached;
24
29
  /** The app's PWA, or `null` when it is not installable right now. */
25
30
  function readPwa() {
@@ -49,7 +54,10 @@ function pwaMiddleware() {
49
54
  "content-type": "application/manifest+json",
50
55
  "cache-control": CACHE_CONTROL
51
56
  } });
52
- if (pathname === INSTALL_PATH) return Response.json(pwa.install, { headers: { "cache-control": CACHE_CONTROL } });
57
+ if (pathname === INSTALL_PATH) return Response.json({
58
+ ...pwa.install,
59
+ startupImages: pwa.startupImages
60
+ }, { headers: { "cache-control": CACHE_CONTROL } });
53
61
  try {
54
62
  const iconResponse = await fetch(pwa.install.iconUrl);
55
63
  if (!iconResponse.ok) return new Response(null, { status: 404 });
@@ -64,8 +72,9 @@ function pwaMiddleware() {
64
72
  });
65
73
  }
66
74
  /**
67
- * The links that make the app installable: its manifest and its home screen
68
- * icon. Render it once, in `<head>` in the root route's `RootDocument`.
75
+ * The tags that make the app installable: its manifest, its home screen icon,
76
+ * and, while the app is installable, the name and launch screens iOS shows.
77
+ * Render it once, in `<head>` in the root route's `RootDocument`.
69
78
  *
70
79
  * @example
71
80
  * function RootDocument({ children }: { children: React.ReactNode }) {
@@ -84,13 +93,40 @@ function pwaMiddleware() {
84
93
  * }
85
94
  */
86
95
  function SoftrPwaHead() {
96
+ const [iosHead, setIosHead] = useState(null);
97
+ useEffect(() => {
98
+ if (detectPlatform() !== "ios") return;
99
+ let cancelled = false;
100
+ globalThis.fetch(INSTALL_PATH, { headers: { accept: "application/json" } }).then(async (response) => {
101
+ if (!response.ok) return;
102
+ const parsed = iosHeadSchema.safeParse(await response.json());
103
+ if (!parsed.success || cancelled) return;
104
+ setIosHead(parsed.data);
105
+ }).catch(() => {});
106
+ return () => {
107
+ cancelled = true;
108
+ };
109
+ }, []);
87
110
  return createElement(Fragment, null, createElement("link", {
88
111
  rel: "manifest",
89
112
  href: MANIFEST_PATH
90
113
  }), createElement("link", {
91
114
  rel: "apple-touch-icon",
92
115
  href: ICON_PATH
93
- }));
116
+ }), ...iosHead === null ? [] : [createElement("meta", {
117
+ key: "capable",
118
+ name: "apple-mobile-web-app-capable",
119
+ content: "yes"
120
+ }), createElement("meta", {
121
+ key: "title",
122
+ name: "apple-mobile-web-app-title",
123
+ content: iosHead.name
124
+ })], ...(iosHead?.startupImages ?? []).map((image) => createElement("link", {
125
+ key: image.href,
126
+ rel: "apple-touch-startup-image",
127
+ media: image.media,
128
+ href: image.href
129
+ })));
94
130
  }
95
131
  const installSchema = pwaSchema.shape.install;
96
132
  /**
package/package.json CHANGED
@@ -1,38 +1,16 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "1.1.2-alpha.0",
3
+ "version": "1.2.1-alpha.0",
4
4
  "type": "module",
5
5
  "exports": {
6
- ".": {
7
- "types": "./dist/index.d.ts",
8
- "import": "./dist/index.js"
9
- },
10
- "./client": {
11
- "types": "./dist/client.d.ts",
12
- "import": "./dist/client.js"
13
- },
14
- "./server": {
15
- "types": "./dist/server.d.ts",
16
- "import": "./dist/server.js"
17
- },
18
- "./vite": {
19
- "types": "./dist/vite.d.ts",
20
- "import": "./dist/vite.js"
21
- }
22
- },
23
- "bin": {
24
- "softr-sdk": "./dist/cli.js"
25
- },
26
- "files": [
27
- "dist",
28
- "schema",
29
- "skills",
30
- "!skills/_artifacts",
31
- "CHANGELOG.md"
32
- ],
33
- "publishConfig": {
34
- "access": "public"
35
- },
6
+ ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
7
+ "./client": { "types": "./dist/client.d.ts", "import": "./dist/client.js" },
8
+ "./server": { "types": "./dist/server.d.ts", "import": "./dist/server.js" },
9
+ "./vite": { "types": "./dist/vite.d.ts", "import": "./dist/vite.js" }
10
+ },
11
+ "bin": { "softr-sdk": "./dist/cli.js" },
12
+ "files": ["dist", "schema", "skills", "!skills/_artifacts", "CHANGELOG.md"],
13
+ "publishConfig": { "access": "public" },
36
14
  "scripts": {
37
15
  "build": "tsdown",
38
16
  "test": "node --import ./src/test-utils/setup.ts --test",
@@ -64,9 +42,7 @@
64
42
  "optional": true
65
43
  }
66
44
  },
67
- "keywords": [
68
- "tanstack-intent"
69
- ],
45
+ "keywords": ["tanstack-intent"],
70
46
  "intent": {
71
47
  "version": 1,
72
48
  "repo": "@softr/sdk",
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: core
11
11
  library: softr-sdk
12
- library_version: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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: 1.1.1
16
+ library_version: 1.2.1-alpha.0
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: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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: 1.1.1
10
+ library_version: 1.2.1-alpha.0
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: 1.1.1
11
+ library_version: 1.2.1-alpha.0
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: 1.1.1
10
+ library_version: 1.2.1-alpha.0
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: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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: 1.1.1
12
+ library_version: 1.2.1-alpha.0
13
13
  ---
14
14
 
15
15
  # Push notifications
@@ -2,21 +2,21 @@
2
2
  name: pwa
3
3
  description: >-
4
4
  Let visitors install the app on their home screen: SoftrPwaHead for the
5
- manifest and icon links, usePwaInstall to decide whether to show an install
6
- button and which platform's steps to show, the PwaInstall and PwaPlatform
7
- types, and how to check that the app is installable. The manifest and icon are
8
- already served; never write them.
5
+ manifest, icon, iOS name and launch screen tags, usePwaInstall to decide
6
+ whether to show an install button and which platform's steps to show, the
7
+ PwaInstall and PwaPlatform types, and how to check that the app is
8
+ installable. The manifest and icon are already served; never write them.
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.1.1
12
+ library_version: 1.2.1-alpha.0
13
13
  ---
14
14
 
15
15
  # Installing the app
16
16
 
17
17
  The builder turns installing on in Studio, under Settings → Mobile app, and sets the name, colour and icon there. The app already answers with its manifest and icon once they do. What the app adds is two things: the links that point the browser at them, and a button that tells visitors how to install.
18
18
 
19
- > **CRITICAL**: Never write a web app manifest, icon files, a service worker, or `manifest` / `apple-touch-icon` links of your own, in `public/` or in `head()`. The app already serves them from Studio's settings, and a file of your own shadows those settings.
19
+ > **CRITICAL**: Never write a web app manifest, icon files, a service worker, or `manifest` / `apple-touch-icon` / `apple-touch-startup-image` links or an `apple-mobile-web-app-title` meta of your own, in `public/` or in `head()`. The app already serves them from Studio's settings, and a file or tag of your own shadows those settings.
20
20
  >
21
21
  > **CRITICAL**: Render an install button only while `usePwaInstall()` returns `available: true`. Never show it unconditionally, never cache the answer, never replace the check with your own. Softr can switch installing off for an app, and this check is the only way that reaches the button.
22
22
 
@@ -48,7 +48,7 @@ The builder switches installing on in Studio, and `usePwaInstall()` reads that s
48
48
 
49
49
  ### The links: `<SoftrPwaHead />`
50
50
 
51
- Render it once, in `<head>` next to `<HeadContent />`, in `RootDocument` in `src/routes/__root.tsx`.
51
+ Render it once, in `<head>` next to `<HeadContent />`, in `RootDocument` in `src/routes/__root.tsx`. While the app is installable it also renders the name iOS puts under the home screen icon and the iOS launch screens, so an installed app opens on its own splash screen instead of white.
52
52
 
53
53
  ```tsx
54
54
  function RootDocument({ children }: { children: React.ReactNode }) {
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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: 1.1.1
13
+ library_version: 1.2.1-alpha.0
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: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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: 1.1.1
12
+ library_version: 1.2.1-alpha.0
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.