@softr/sdk 1.0.1-alpha.0 → 1.1.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 +8 -2
- package/dist/action.d.ts +34 -2
- package/dist/action.js +9 -2
- package/dist/auth/context.js +13 -0
- package/dist/auth/isomorphic.d.ts +6 -6
- package/dist/auth/isomorphic.js +6 -9
- package/dist/auth/methods/authenticator.js +1 -1
- package/dist/auth/methods/code.js +1 -1
- package/dist/auth/methods/emailCode2fa.js +1 -1
- package/dist/auth/methods/magicLink.js +1 -1
- package/dist/auth/methods/password.js +1 -1
- package/dist/auth/methods/passwordLink.js +1 -1
- package/dist/auth/methods/profile.js +1 -1
- package/dist/auth/methods/signup.js +1 -1
- package/dist/auth/methods/social.js +1 -1
- package/dist/auth/session.js +19 -6
- package/dist/datasource/chart.d.ts +1 -1
- package/dist/datasource/chart.js +27 -19
- package/dist/datasource/enforced-filter.d.ts +56 -0
- package/dist/datasource/enforced-filter.js +127 -0
- package/dist/datasource/fields.d.ts +2 -2
- package/dist/datasource/filter.d.ts +9 -2
- package/dist/datasource/filter.js +17 -1
- package/dist/datasource/record.d.ts +1 -1
- package/dist/datasource/record.js +58 -10
- package/dist/default-error-overlay.d.ts +2 -2
- package/dist/fetch.js +1 -15
- package/dist/formatting.d.ts +3 -3
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +1 -1
- package/dist/package.js +1 -1
- package/dist/pwa.d.ts +5 -4
- package/dist/pwa.js +36 -5
- package/package.json +1 -1
- package/skills/softr-sdk/SKILL.md +1 -1
- package/skills/softr-sdk/ai/SKILL.md +1 -1
- package/skills/softr-sdk/auth/SKILL.md +1 -1
- package/skills/softr-sdk/charts-and-metrics/SKILL.md +1 -1
- package/skills/softr-sdk/current-user/SKILL.md +1 -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/push-notifications/SKILL.md +1 -1
- package/skills/softr-sdk/pwa/SKILL.md +7 -7
- 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
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { assert, requireDefined } from "../assertions.js";
|
|
2
|
+
import { softrConfig } from "../softr-config.js";
|
|
3
|
+
import { INTERNAL_KIND, buildFilterCriteria } from "./filter.js";
|
|
4
|
+
import { makeChain } from "./fields.js";
|
|
5
|
+
|
|
6
|
+
//#region src/datasource/enforced-filter.ts
|
|
7
|
+
/** The group levels Studio can show and edit. The root group is level 1. */
|
|
8
|
+
const MAX_LEVELS = 4;
|
|
9
|
+
const USER_TOKEN = /^(?:\{USER:::(EMAIL|EMAIL_DOMAIN)\}|USER:::(.+))$/;
|
|
10
|
+
const DATE_TOKEN = /^(?:PREDEFINED:(?:TODAY|YESTERDAY|TOMORROW)|FIXED_DATE:(?:DAYS_AGO|DAYS_FROM_NOW):\d+)$/;
|
|
11
|
+
/** Anything in the token namespaces. A value here that is no known token is a typo, not data. */
|
|
12
|
+
const TOKEN_LIKE = /^\{?(?:USER|PREDEFINED|FIXED_DATE):/;
|
|
13
|
+
/**
|
|
14
|
+
* Builds the filter that a query declares into the shape a read sends. Subjects stay aliases and
|
|
15
|
+
* tokens stay unresolved: the datasource resolves them on each read.
|
|
16
|
+
*/
|
|
17
|
+
function buildEnforcedFilter(declared, aliases) {
|
|
18
|
+
const root = requireDefined(buildFilterCriteria(toConstructable(declared)).filterConditionGroup);
|
|
19
|
+
const levels = levelsOf(root);
|
|
20
|
+
assert(levels <= MAX_LEVELS, () => `the filter has ${levels} group levels, and Studio shows at most ${MAX_LEVELS}`);
|
|
21
|
+
return { filterConditionGroup: root };
|
|
22
|
+
function toConstructable(node) {
|
|
23
|
+
assert(isObject(node) && Object.keys(node).length > 0, "a filter must be an object with at least one key");
|
|
24
|
+
const members = [];
|
|
25
|
+
for (const [key, value] of Object.entries(node)) if (key === "$and") members.push(...junction(key, value).flatMap((member) => membersOf(member, "AND")));
|
|
26
|
+
else if (key === "$or") members.push(group("OR", junction(key, value).flatMap((member) => membersOf(member, "OR"))));
|
|
27
|
+
else members.push(...conditions(key, value));
|
|
28
|
+
return members.length === 1 ? members[0] : group("AND", members);
|
|
29
|
+
}
|
|
30
|
+
function junction(key, value) {
|
|
31
|
+
assert(Array.isArray(value) && value.length > 0, () => `${key} must be a list of at least one filter`);
|
|
32
|
+
return value.map(toConstructable);
|
|
33
|
+
}
|
|
34
|
+
function conditions(alias, value) {
|
|
35
|
+
assert(aliases.includes(alias), () => `the filter names "${alias}", which is not one of the query's filterFields`);
|
|
36
|
+
assert(isObject(value) && Object.keys(value).length > 0, () => `"${alias}" in the filter needs at least one operator`);
|
|
37
|
+
const chain = makeChain(alias);
|
|
38
|
+
return Object.entries(value).map(([operator, argument]) => {
|
|
39
|
+
assert(Object.hasOwn(chain, operator), () => `"${operator}" on "${alias}" is not a filter operator`);
|
|
40
|
+
const build = chain[operator];
|
|
41
|
+
let values$1 = [argument];
|
|
42
|
+
if (build.length === 0) {
|
|
43
|
+
assert(argument === true, () => `"${operator}" on "${alias}" takes true`);
|
|
44
|
+
values$1 = [];
|
|
45
|
+
} else if (build.length === 2) {
|
|
46
|
+
assert(Array.isArray(argument) && argument.length === 2, () => `"${operator}" on "${alias}" takes a pair`);
|
|
47
|
+
values$1 = argument;
|
|
48
|
+
}
|
|
49
|
+
for (const token of values$1.flat()) {
|
|
50
|
+
const unbraced = typeof token === "string" ? /^\{(USER:::.+)\}$/.exec(token)?.[1] : void 0;
|
|
51
|
+
assert(typeof token !== "string" || !TOKEN_LIKE.test(token) || USER_TOKEN.test(token) || DATE_TOKEN.test(token), () => `"${token}" on "${alias}" is not a known token` + (unbraced === void 0 ? "" : `. Write a field of the visitor without braces: "${unbraced}"`));
|
|
52
|
+
const key = typeof token === "string" ? USER_TOKEN.exec(token)?.[2] : void 0;
|
|
53
|
+
assert(key === void 0 || Object.values(softrConfig().user?.properties ?? {}).includes(key), () => `"${token}" on "${alias}" names a field that softr.json does not declare under user.properties`);
|
|
54
|
+
}
|
|
55
|
+
return build(...values$1);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Whether the filter reads a value of the visitor, so a read has to know who the visitor is. */
|
|
60
|
+
function readsVisitor(group$1) {
|
|
61
|
+
return values(group$1).some((value) => typeof value === "string" && USER_TOKEN.test(value));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The part of the filter that can match rows for this visitor, or `null` when no part can.
|
|
65
|
+
*
|
|
66
|
+
* The datasource resolves each user token from the session. For a visitor with no value, it
|
|
67
|
+
* compares with an empty value, and that matches the wrong rows. So a condition whose user token
|
|
68
|
+
* has no value never goes out. The visitor is signed out, or their row holds nothing there.
|
|
69
|
+
*
|
|
70
|
+
* In an AND group, such a condition makes the group match nothing. In an OR group, only that
|
|
71
|
+
* branch drops out. Either way the visitor reads fewer rows, never more.
|
|
72
|
+
*/
|
|
73
|
+
function filterForVisitor(group$1, visitor) {
|
|
74
|
+
const filters = group$1.filters.filter(filterCanMatch);
|
|
75
|
+
const filterGroups = group$1.filterGroups.flatMap((nested) => filterForVisitor(nested, visitor) ?? []);
|
|
76
|
+
const kept = filters.length + filterGroups.length;
|
|
77
|
+
return (group$1.logicalOperator === "AND" ? kept === group$1.filters.length + group$1.filterGroups.length : kept > 0) ? {
|
|
78
|
+
...group$1,
|
|
79
|
+
filters,
|
|
80
|
+
filterGroups
|
|
81
|
+
} : null;
|
|
82
|
+
function filterCanMatch(filter) {
|
|
83
|
+
if (Array.isArray(filter.value)) return filter.value.every((value) => valueCount(value) > 0);
|
|
84
|
+
return valueCount(filter.value) === 1;
|
|
85
|
+
}
|
|
86
|
+
function valueCount(value) {
|
|
87
|
+
const user = typeof value === "string" ? USER_TOKEN.exec(value) : null;
|
|
88
|
+
if (user === null) return 1;
|
|
89
|
+
return visitor === null ? 0 : userValues(visitor, user[1], user[2]).length;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** `property` is EMAIL or EMAIL_DOMAIN for the braced tokens, and `key` is set for the others. */
|
|
93
|
+
function userValues(visitor, property, key) {
|
|
94
|
+
if (property === "EMAIL") return [visitor.email];
|
|
95
|
+
if (property === "EMAIL_DOMAIN") {
|
|
96
|
+
const domain = visitor.email.slice(visitor.email.indexOf("@") + 1);
|
|
97
|
+
return visitor.email.includes("@") && domain !== "" ? [domain] : [];
|
|
98
|
+
}
|
|
99
|
+
const raw = visitor.field(requireDefined(key));
|
|
100
|
+
return (Array.isArray(raw) ? raw : [raw]).filter((item) => item !== null && item !== void 0 && item !== "");
|
|
101
|
+
}
|
|
102
|
+
function levelsOf(group$1) {
|
|
103
|
+
return 1 + Math.max(0, ...group$1.filterGroups.map(levelsOf));
|
|
104
|
+
}
|
|
105
|
+
function values(group$1) {
|
|
106
|
+
return [...group$1.filters.flatMap((filter) => Array.isArray(filter.value) ? filter.value : [filter.value]), ...group$1.filterGroups.flatMap(values)];
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A member that is itself a group of `logicalOperator` gives its members. So the filter stays as
|
|
110
|
+
* shallow as written.
|
|
111
|
+
*/
|
|
112
|
+
function membersOf(member, logicalOperator) {
|
|
113
|
+
return member[INTERNAL_KIND] === "LOGICAL_GROUP" && member.logicalOperator === logicalOperator ? member.filters : [member];
|
|
114
|
+
}
|
|
115
|
+
function group(logicalOperator, filters) {
|
|
116
|
+
return {
|
|
117
|
+
logicalOperator,
|
|
118
|
+
filters,
|
|
119
|
+
[INTERNAL_KIND]: "LOGICAL_GROUP"
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function isObject(value) {
|
|
123
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//#endregion
|
|
127
|
+
export { buildEnforcedFilter, filterForVisitor, readsVisitor };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldTypeOf, ReadOf, ReadShape, SoftrDatasources } from "../action.js";
|
|
2
1
|
import { AnyConstructable, ConstructableFilter, ConstructableFilterGroup, ConstructableOrderBy } from "./filter.js";
|
|
2
|
+
import { FieldTypeOf, ReadOf, ReadShape, SoftrDatasources } from "../action.js";
|
|
3
3
|
|
|
4
4
|
//#region src/datasource/fields.d.ts
|
|
5
5
|
type EmptyChain = {
|
|
@@ -111,4 +111,4 @@ type SortSet<TRecord> = { [K in keyof TRecord]: {
|
|
|
111
111
|
readonly desc: ConstructableOrderBy;
|
|
112
112
|
} };
|
|
113
113
|
//#endregion
|
|
114
|
-
export { DateFieldType, FieldSet, NumberFieldType, SortSet };
|
|
114
|
+
export { AnyChain, ChainFor, DateFieldType, FieldSet, NumberFieldType, SortSet };
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
//#region src/datasource/filter.d.ts
|
|
2
|
-
|
|
2
|
+
interface FilterCriteria {
|
|
3
|
+
filterConditionGroup?: FilterConditionGroup;
|
|
4
|
+
}
|
|
5
|
+
interface FilterConditionGroup {
|
|
6
|
+
logicalOperator: LogicalOperator;
|
|
7
|
+
filters: Filter[];
|
|
8
|
+
filterGroups: FilterConditionGroup[];
|
|
9
|
+
}
|
|
3
10
|
type LogicalOperator = "AND" | "OR";
|
|
4
11
|
type FilterOperator = "IS" | "IS_NOT" | "EQUAL" | "NOT_EQUAL" | "IS_EMPTY" | "IS_NOT_EMPTY" | "IS_ONE_OF" | "IS_NONE_OF" | "HAS_ALL_OF" | "CONTAINS" | "INLINE_CONTAINS" | "GT" | "LT" | "GTE" | "LTE" | "BETWEEN" | "IS_NOT_BETWEEN" | "DOES_NOT_CONTAINS" | "STARTS_WITH" | "ENDS_WITH";
|
|
5
12
|
type ConditionFieldType = "TEXT" | "BOOLEAN" | "NUMERIC" | "ARRAY" | "DATE";
|
|
@@ -27,4 +34,4 @@ type ConstructableOrderBy = SortingOptionItem & {
|
|
|
27
34
|
type AnyConstructable = ConstructableFilter | ConstructableFilterGroup;
|
|
28
35
|
declare const INTERNAL_KIND: unique symbol;
|
|
29
36
|
//#endregion
|
|
30
|
-
export { AnyConstructable, ConstructableFilter, ConstructableFilterGroup, ConstructableOrderBy };
|
|
37
|
+
export { AnyConstructable, ConstructableFilter, ConstructableFilterGroup, ConstructableOrderBy, FilterCriteria };
|
|
@@ -49,6 +49,22 @@ function buildFilterGroup(logicalOperator, members) {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
+
* Joins groups with AND. An AND group gives its conditions and groups to the join rather than
|
|
53
|
+
* nesting in it, so the join is at most one level deeper than its deepest member.
|
|
54
|
+
*/
|
|
55
|
+
function andGroups(groups) {
|
|
56
|
+
const joined = {
|
|
57
|
+
logicalOperator: "AND",
|
|
58
|
+
filters: [],
|
|
59
|
+
filterGroups: []
|
|
60
|
+
};
|
|
61
|
+
for (const group of groups) if (group.logicalOperator === "AND") {
|
|
62
|
+
joined.filters.push(...group.filters);
|
|
63
|
+
joined.filterGroups.push(...group.filterGroups);
|
|
64
|
+
} else joined.filterGroups.push(group);
|
|
65
|
+
return joined;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
52
68
|
* Converts order-by utility conditions to a format our backend supports
|
|
53
69
|
*
|
|
54
70
|
* @example
|
|
@@ -130,4 +146,4 @@ function isFilter(item) {
|
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
//#endregion
|
|
133
|
-
export { INTERNAL_KIND, buildFilterCriteria, buildOrderBy, dealiasFilterCriteria, dealiasOrderBy };
|
|
149
|
+
export { INTERNAL_KIND, andGroups, buildFilterCriteria, buildOrderBy, dealiasFilterCriteria, dealiasOrderBy };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ActionData, ActionRecord, ActionShape, DatasourceAction, ReadShape } from "../action.js";
|
|
2
1
|
import { AnyConstructable, ConstructableOrderBy } from "./filter.js";
|
|
3
2
|
import { FieldSet, SortSet } from "./fields.js";
|
|
3
|
+
import { ActionData, ActionRecord, ActionShape, DatasourceAction, ReadShape } from "../action.js";
|
|
4
4
|
|
|
5
5
|
//#region src/datasource/record.d.ts
|
|
6
6
|
type GetOptions = {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { assert, panic } from "../assertions.js";
|
|
1
|
+
import { assert, panic, requireDefined } from "../assertions.js";
|
|
2
2
|
import { softrApiUrl } from "../softr-api.js";
|
|
3
3
|
import { fetch } from "../fetch.js";
|
|
4
|
+
import { softrConfig } from "../softr-config.js";
|
|
4
5
|
import { readUserTimezone } from "../cookies.js";
|
|
5
|
-
import { readSessionToken } from "../auth/session.js";
|
|
6
|
-
import {
|
|
7
|
-
import { buildFilterCriteria, buildOrderBy, dealiasFilterCriteria, dealiasOrderBy } from "./filter.js";
|
|
6
|
+
import { readSessionToken, readStandInUser } from "../auth/session.js";
|
|
7
|
+
import { andGroups, buildFilterCriteria, buildOrderBy, dealiasFilterCriteria, dealiasOrderBy } from "./filter.js";
|
|
8
8
|
import { andAll, makeFieldSet, makeSortSet } from "./fields.js";
|
|
9
|
+
import { filterForVisitor, readsVisitor } from "./enforced-filter.js";
|
|
10
|
+
import { isDatasourceAction } from "../action.js";
|
|
11
|
+
import { readSoftrContext } from "../auth/context.js";
|
|
9
12
|
import { getRequestHeader, getRequestUrl } from "@tanstack/react-start/server";
|
|
10
13
|
|
|
11
14
|
//#region src/datasource/record.ts
|
|
@@ -85,10 +88,16 @@ function listRecords(query) {
|
|
|
85
88
|
return builder;
|
|
86
89
|
}
|
|
87
90
|
async function executeList(query, args) {
|
|
88
|
-
const
|
|
91
|
+
const target = resolveTarget(query, "read");
|
|
92
|
+
const { actionId, select } = target;
|
|
89
93
|
const count = Math.min(args.limit ?? 20, MAX_RECORD_COUNT);
|
|
90
94
|
const offset = args.offset ?? null;
|
|
91
|
-
const filterCriteria =
|
|
95
|
+
const filterCriteria = await readFilterCriteria(target, args.filters);
|
|
96
|
+
if (filterCriteria === null) return {
|
|
97
|
+
records: [],
|
|
98
|
+
total: 0,
|
|
99
|
+
nextOffset: null
|
|
100
|
+
};
|
|
92
101
|
const sortingOption = args.orderBy.length ? dealiasOrderBy(buildOrderBy(args.orderBy), select) : void 0;
|
|
93
102
|
const res = await fetch(`${dsUrl(actionId)}/records`, {
|
|
94
103
|
method: "POST",
|
|
@@ -160,8 +169,10 @@ function getRecord(query, options) {
|
|
|
160
169
|
}
|
|
161
170
|
async function executeGet(query, id, filters) {
|
|
162
171
|
assert(id, "a record id must not be empty");
|
|
163
|
-
const
|
|
164
|
-
const
|
|
172
|
+
const target = resolveTarget(query, "read");
|
|
173
|
+
const { actionId, select } = target;
|
|
174
|
+
const filterCriteria = await readFilterCriteria(target, filters);
|
|
175
|
+
if (filterCriteria === null) return null;
|
|
165
176
|
const res = await fetch(`${dsUrl(actionId)}/records/${id}`, {
|
|
166
177
|
method: "POST",
|
|
167
178
|
headers: {
|
|
@@ -266,7 +277,44 @@ function resolveTarget(subject, operation) {
|
|
|
266
277
|
assert(action.resource.operation === operation, () => `action "${action.id}" is declared as ${action.resource.operation}, not ${operation}`);
|
|
267
278
|
return {
|
|
268
279
|
actionId: action.id,
|
|
269
|
-
select: action.resource.fields ?? {}
|
|
280
|
+
select: action.resource.fields ?? {},
|
|
281
|
+
filterFields: action.resource.filterFields,
|
|
282
|
+
filter: action.resource.filter
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The filter a read sends: the query's enforced filter, with its tokens, AND the `where`
|
|
287
|
+
* filters. `null` when the enforced filter matches no rows for this visitor. The read then sends
|
|
288
|
+
* no request and returns nothing.
|
|
289
|
+
*/
|
|
290
|
+
async function readFilterCriteria(target, filters) {
|
|
291
|
+
const groups = [];
|
|
292
|
+
const enforced = target.filter?.filterConditionGroup;
|
|
293
|
+
if (enforced !== void 0) {
|
|
294
|
+
const forVisitor = readsVisitor(enforced) ? filterForVisitor(enforced, await readVisitor()) : enforced;
|
|
295
|
+
if (forVisitor === null) return null;
|
|
296
|
+
groups.push(dealias(forVisitor, requireDefined(target.filterFields, "defineQuery declares filterFields with a filter")));
|
|
297
|
+
}
|
|
298
|
+
const requested = filters.length ? buildFilterCriteria(andAll(filters)).filterConditionGroup : void 0;
|
|
299
|
+
if (requested !== void 0) groups.push(dealias(requested, target.select));
|
|
300
|
+
if (groups.length === 0) return {};
|
|
301
|
+
return { filterConditionGroup: groups.length === 1 ? groups[0] : andGroups(groups) };
|
|
302
|
+
function dealias(group, aliases) {
|
|
303
|
+
return requireDefined(dealiasFilterCriteria({ filterConditionGroup: group }, aliases).filterConditionGroup);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
async function readVisitor() {
|
|
307
|
+
const user = await (readStandInUser() ?? readSoftrContext().user);
|
|
308
|
+
if (user === null) return null;
|
|
309
|
+
const properties = user.properties;
|
|
310
|
+
const aliasOf = new Map(Object.entries(softrConfig().user?.properties ?? {}).map(([alias, fieldId]) => [fieldId, alias]));
|
|
311
|
+
return {
|
|
312
|
+
email: user.email,
|
|
313
|
+
field(key) {
|
|
314
|
+
const alias = aliasOf.get(key);
|
|
315
|
+
assert(alias !== void 0, () => `the enforced filter reads USER:::${key}, a field that softr.json does not declare under user.properties`);
|
|
316
|
+
return properties[alias];
|
|
317
|
+
}
|
|
270
318
|
};
|
|
271
319
|
}
|
|
272
320
|
function aliasFields(fields, aliases) {
|
|
@@ -281,4 +329,4 @@ function dealiasData(data, select) {
|
|
|
281
329
|
}
|
|
282
330
|
|
|
283
331
|
//#endregion
|
|
284
|
-
export { createRecord, deleteRecord, describeFailure, dsUrl, getRecord, listRecords, refererHeader, resolveTarget, updateRecord };
|
|
332
|
+
export { createRecord, deleteRecord, describeFailure, dsUrl, getRecord, listRecords, readFilterCriteria, refererHeader, resolveTarget, updateRecord };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react5 from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/default-error-overlay.d.ts
|
|
4
4
|
type Props = {
|
|
@@ -8,6 +8,6 @@ type Props = {
|
|
|
8
8
|
declare function DefaultErrorOverlay({
|
|
9
9
|
error,
|
|
10
10
|
reset
|
|
11
|
-
}: Props):
|
|
11
|
+
}: Props): react5.JSX.Element;
|
|
12
12
|
//#endregion
|
|
13
13
|
export { DefaultErrorOverlay };
|
package/dist/fetch.js
CHANGED
|
@@ -2,10 +2,8 @@ import { version } from "./package.js";
|
|
|
2
2
|
import { assert, requireDefined } from "./assertions.js";
|
|
3
3
|
import { logger } from "./logger.js";
|
|
4
4
|
import { softrApiUrl } from "./softr-api.js";
|
|
5
|
-
import { getRequestHeader } from "@tanstack/react-start/server";
|
|
6
5
|
|
|
7
6
|
//#region src/fetch.ts
|
|
8
|
-
const CLIENT_IP_HEADER = "x-softr-client-ip";
|
|
9
7
|
const fetch = async (input, init) => {
|
|
10
8
|
const url = input instanceof Request ? input.url : String(input);
|
|
11
9
|
if ([
|
|
@@ -15,10 +13,6 @@ const fetch = async (input, init) => {
|
|
|
15
13
|
].some((base) => url.startsWith(`${base}/`))) {
|
|
16
14
|
const headers = new Headers(init?.headers ?? (input instanceof Request ? input.headers : void 0));
|
|
17
15
|
headers.set("user-agent", `softr-sdk/${version}`);
|
|
18
|
-
headers.delete(CLIENT_IP_HEADER);
|
|
19
|
-
const clientIp = readClientIp();
|
|
20
|
-
const isPlatformCall = url.startsWith(`${softrApiUrl("SOFTR_PLATFORM_API_URL")}/`);
|
|
21
|
-
if (clientIp && isPlatformCall) headers.set(CLIENT_IP_HEADER, clientIp);
|
|
22
16
|
init = {
|
|
23
17
|
...init,
|
|
24
18
|
headers
|
|
@@ -48,7 +42,7 @@ const fetch = async (input, init) => {
|
|
|
48
42
|
* id (`<environment>/<applicationId>/<master number>`) is copied into the signature as is so the verifier can
|
|
49
43
|
* derive the same key.
|
|
50
44
|
*
|
|
51
|
-
* The signature covers the method, authority, path, query and, when sent, the Authorization
|
|
45
|
+
* The signature covers the method, authority, path, query and, when sent, the Authorization header. The body is
|
|
52
46
|
* not covered: TLS protects it in transit, and signing is there to tell the app's own server from anyone holding a
|
|
53
47
|
* user token, which needs no body coverage. So nothing is buffered here and the body streams through as given.
|
|
54
48
|
*/
|
|
@@ -69,7 +63,6 @@ async function sign(input, init) {
|
|
|
69
63
|
};
|
|
70
64
|
const fields = Object.keys(derived);
|
|
71
65
|
if (headers.has("authorization")) fields.push("authorization");
|
|
72
|
-
if (headers.has(CLIENT_IP_HEADER)) fields.push(CLIENT_IP_HEADER);
|
|
73
66
|
const created = Math.floor(Date.now() / 1e3);
|
|
74
67
|
const params = `(${fields.map((field) => `"${field}"`).join(" ")});created=${created};keyid="${keyId}";tag="softr-code-app"`;
|
|
75
68
|
const base = [...fields.map((field) => `"${field}": ${derived[field] ?? requireDefined(headers.get(field), field)}`), `"@signature-params": ${params}`].join("\n");
|
|
@@ -82,13 +75,6 @@ async function sign(input, init) {
|
|
|
82
75
|
headers.set("signature", `softr=:${signature}:`);
|
|
83
76
|
return new Request(request, { headers });
|
|
84
77
|
}
|
|
85
|
-
function readClientIp() {
|
|
86
|
-
try {
|
|
87
|
-
return getRequestHeader("cf-connecting-ip");
|
|
88
|
-
} catch {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
78
|
function base64(bytes) {
|
|
93
79
|
return btoa(String.fromCharCode(...new Uint8Array(bytes)));
|
|
94
80
|
}
|
package/dist/formatting.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import * as
|
|
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
|
-
}):
|
|
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
|
-
}):
|
|
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
|
|
2
|
+
import * as _tanstack_react_start1 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_start1.RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
35
35
|
//#endregion
|
|
36
36
|
export { softrMcpMiddleware };
|
package/dist/mcp.js
CHANGED
|
@@ -3,9 +3,9 @@ import { softrApiUrl } from "./softr-api.js";
|
|
|
3
3
|
import { fetch } from "./fetch.js";
|
|
4
4
|
import { softrConfig } from "./softr-config.js";
|
|
5
5
|
import { sessionConfig } from "./auth/config.js";
|
|
6
|
+
import { makePlatform } from "./auth/platform.js";
|
|
6
7
|
import { readSessionToken, withSessionToken } from "./auth/session.js";
|
|
7
8
|
import { isDatasourceAction } from "./action.js";
|
|
8
|
-
import { makePlatform } from "./auth/platform.js";
|
|
9
9
|
import { ds } from "./datasource/datasource.js";
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
import { createMiddleware } from "@tanstack/react-start";
|
package/dist/package.js
CHANGED
package/dist/pwa.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react3 from "react";
|
|
2
2
|
import "@tanstack/react-start";
|
|
3
3
|
|
|
4
4
|
//#region src/pwa.d.ts
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
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():
|
|
27
|
+
declare function SoftrPwaHead(): react3.FunctionComponentElement<react3.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(
|
|
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
|
|
68
|
-
*
|
|
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,35 @@ 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 ? null : createElement("meta", {
|
|
117
|
+
name: "apple-mobile-web-app-title",
|
|
118
|
+
content: iosHead.name
|
|
119
|
+
}), ...(iosHead?.startupImages ?? []).map((image) => createElement("link", {
|
|
120
|
+
key: image.href,
|
|
121
|
+
rel: "apple-touch-startup-image",
|
|
122
|
+
media: image.media,
|
|
123
|
+
href: image.href
|
|
124
|
+
})));
|
|
94
125
|
}
|
|
95
126
|
const installSchema = pwaSchema.shape.install;
|
|
96
127
|
/**
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ description: >-
|
|
|
13
13
|
metadata:
|
|
14
14
|
type: sub-skill
|
|
15
15
|
library: softr-sdk
|
|
16
|
-
library_version: 1.
|
|
16
|
+
library_version: 1.1.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.
|
|
12
|
+
library_version: 1.1.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.
|
|
12
|
+
library_version: 1.1.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.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.
|
|
10
|
+
library_version: 1.1.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.
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
metadata:
|
|
8
8
|
type: sub-skill
|
|
9
9
|
library: softr-sdk
|
|
10
|
-
library_version: 1.
|
|
10
|
+
library_version: 1.1.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.
|
|
12
|
+
library_version: 1.1.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.
|