@softr/sdk 0.0.7 → 0.0.10
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/client.d.ts +6 -0
- package/dist/{react.js → client.js} +2 -1
- package/dist/index.d.ts +659 -11
- package/dist/index.js +874 -24
- package/dist/server.d.ts +85 -0
- package/dist/server.js +202 -0
- package/dist/session-Blx62HHJ.js +334 -0
- package/dist/user-D23hwTsf.d.ts +28 -0
- package/dist/vite.d.ts +6 -3
- package/dist/vite.js +28 -2
- package/package.json +6 -5
- package/dist/query-C6022JhD.js +0 -528
- package/dist/react.d.ts +0 -4
- package/dist/tanstack.d.ts +0 -18
- package/dist/tanstack.js +0 -320
- package/dist/types-CjB4xUg-.d.ts +0 -661
package/dist/types-CjB4xUg-.d.ts
DELETED
|
@@ -1,661 +0,0 @@
|
|
|
1
|
-
//#region src/core/query.d.ts
|
|
2
|
-
|
|
3
|
-
type LogicalOperator = "AND" | "OR";
|
|
4
|
-
type FilterOperator = "IS" | "IS_NOT" | "EQUAL" | "NOT_EQUAL" | "IS_EMPTY" | "IS_NOT_EMPTY" | "IS_ONE_OF" | "IS_NONE_OF" | "HAS_ALL_OF" | "HAS_ONE_OF" | "HAS_NONE_OF" | "CONTAINS" | "INLINE_CONTAINS" | "GT" | "LT" | "GTE" | "LTE" | "BETWEEN" | "IS_NOT_BETWEEN" | "DOES_NOT_CONTAINS" | "STARTS_WITH" | "ENDS_WITH";
|
|
5
|
-
type ConditionFieldType = "TEXT" | "BOOLEAN" | "NUMERIC" | "ARRAY" | "DATE";
|
|
6
|
-
interface Filter {
|
|
7
|
-
subject: string;
|
|
8
|
-
operator: FilterOperator;
|
|
9
|
-
value?: unknown;
|
|
10
|
-
type: ConditionFieldType;
|
|
11
|
-
}
|
|
12
|
-
type ConstructableFilter = Filter & {
|
|
13
|
-
[INTERNAL_KIND]: "FILTER";
|
|
14
|
-
};
|
|
15
|
-
type ConstructableFilterGroup = {
|
|
16
|
-
logicalOperator: LogicalOperator;
|
|
17
|
-
filters: Array<ConstructableFilter | ConstructableFilterGroup>;
|
|
18
|
-
[INTERNAL_KIND]: "LOGICAL_GROUP";
|
|
19
|
-
};
|
|
20
|
-
interface SortingOptionItem {
|
|
21
|
-
sortingField: string;
|
|
22
|
-
sortType: "ASC" | "DESC";
|
|
23
|
-
}
|
|
24
|
-
type ConstructableOrderBy = SortingOptionItem & {
|
|
25
|
-
[INTERNAL_KIND]: "ORDER_BY";
|
|
26
|
-
};
|
|
27
|
-
type AnyConstructable = ConstructableFilter | ConstructableFilterGroup;
|
|
28
|
-
declare const INTERNAL_KIND: unique symbol;
|
|
29
|
-
/**
|
|
30
|
-
* Query builder for filter queries. This exist to alleviate the (LLM?) mental overhead. API filter schema is a bit
|
|
31
|
-
* verbose and confusing, even when dealing with very basic queries. So to fall into the pit of success, aim here
|
|
32
|
-
* is to simplify filtering as much as possible.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* single filter
|
|
36
|
-
* ```tsx
|
|
37
|
-
* const query = q.text("title").contains("hello");
|
|
38
|
-
*
|
|
39
|
-
* const json = buildFilterCriteria(query);
|
|
40
|
-
* // result
|
|
41
|
-
* {
|
|
42
|
-
* "filterCriteria": {
|
|
43
|
-
* "filterConditionGroup": {
|
|
44
|
-
* "logicalOperator": "AND"
|
|
45
|
-
* "filterGroups": [{
|
|
46
|
-
* "logicalOperator": "AND",
|
|
47
|
-
* "filters": [{
|
|
48
|
-
* "subject": "title",
|
|
49
|
-
* "type": "TEXT",
|
|
50
|
-
* "operator": "CONTAINS",
|
|
51
|
-
* "value": "hello"
|
|
52
|
-
* }],
|
|
53
|
-
* }]
|
|
54
|
-
* }
|
|
55
|
-
* }
|
|
56
|
-
* }
|
|
57
|
-
*
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* combining multiple filters
|
|
62
|
-
* ```tsx
|
|
63
|
-
* const query = q.and(
|
|
64
|
-
* q.text("title").contains("hello"),
|
|
65
|
-
* q.number("views").is(100),
|
|
66
|
-
* q.or(
|
|
67
|
-
* q.text("author").is("John"),
|
|
68
|
-
* q.boolean("isPublished").is(true)
|
|
69
|
-
* )
|
|
70
|
-
* );
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
declare const q: {
|
|
74
|
-
select<T extends Record<string, string>>(mapping: T): T;
|
|
75
|
-
and(...filters: AnyConstructable[]): ConstructableFilterGroup;
|
|
76
|
-
or(...filters: AnyConstructable[]): ConstructableFilterGroup;
|
|
77
|
-
text(subject: string): {
|
|
78
|
-
is(value: string): {
|
|
79
|
-
operator: "IS";
|
|
80
|
-
value: string;
|
|
81
|
-
subject: string;
|
|
82
|
-
type: "TEXT";
|
|
83
|
-
[INTERNAL_KIND]: "FILTER";
|
|
84
|
-
};
|
|
85
|
-
isNot(value: string): {
|
|
86
|
-
operator: "IS_NOT";
|
|
87
|
-
value: string;
|
|
88
|
-
subject: string;
|
|
89
|
-
type: "TEXT";
|
|
90
|
-
[INTERNAL_KIND]: "FILTER";
|
|
91
|
-
};
|
|
92
|
-
contains(value: string): {
|
|
93
|
-
operator: "CONTAINS";
|
|
94
|
-
value: string;
|
|
95
|
-
subject: string;
|
|
96
|
-
type: "TEXT";
|
|
97
|
-
[INTERNAL_KIND]: "FILTER";
|
|
98
|
-
};
|
|
99
|
-
isOneOf(value: string[]): {
|
|
100
|
-
operator: "IS_ONE_OF";
|
|
101
|
-
value: string[];
|
|
102
|
-
subject: string;
|
|
103
|
-
type: "TEXT";
|
|
104
|
-
[INTERNAL_KIND]: "FILTER";
|
|
105
|
-
};
|
|
106
|
-
isNoneOf(value: string[]): {
|
|
107
|
-
operator: "IS_NONE_OF";
|
|
108
|
-
value: string[];
|
|
109
|
-
subject: string;
|
|
110
|
-
type: "TEXT";
|
|
111
|
-
[INTERNAL_KIND]: "FILTER";
|
|
112
|
-
};
|
|
113
|
-
startsWith(value: string): {
|
|
114
|
-
operator: "STARTS_WITH";
|
|
115
|
-
value: string;
|
|
116
|
-
subject: string;
|
|
117
|
-
type: "TEXT";
|
|
118
|
-
[INTERNAL_KIND]: "FILTER";
|
|
119
|
-
};
|
|
120
|
-
endsWith(value: string): {
|
|
121
|
-
operator: "ENDS_WITH";
|
|
122
|
-
value: string;
|
|
123
|
-
subject: string;
|
|
124
|
-
type: "TEXT";
|
|
125
|
-
[INTERNAL_KIND]: "FILTER";
|
|
126
|
-
};
|
|
127
|
-
hasAllOf(value: string[]): {
|
|
128
|
-
operator: "HAS_ALL_OF";
|
|
129
|
-
value: string[];
|
|
130
|
-
subject: string;
|
|
131
|
-
type: "TEXT";
|
|
132
|
-
[INTERNAL_KIND]: "FILTER";
|
|
133
|
-
};
|
|
134
|
-
isEmpty(): {
|
|
135
|
-
operator: "IS_EMPTY";
|
|
136
|
-
subject: string;
|
|
137
|
-
type: "TEXT";
|
|
138
|
-
[INTERNAL_KIND]: "FILTER";
|
|
139
|
-
};
|
|
140
|
-
isNotEmpty(): {
|
|
141
|
-
operator: "IS_NOT_EMPTY";
|
|
142
|
-
subject: string;
|
|
143
|
-
type: "TEXT";
|
|
144
|
-
[INTERNAL_KIND]: "FILTER";
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
boolean(subject: string): {
|
|
148
|
-
is(value: boolean): {
|
|
149
|
-
operator: "IS";
|
|
150
|
-
value: boolean;
|
|
151
|
-
subject: string;
|
|
152
|
-
type: "BOOLEAN";
|
|
153
|
-
[INTERNAL_KIND]: "FILTER";
|
|
154
|
-
};
|
|
155
|
-
isNot(value: boolean): {
|
|
156
|
-
operator: "IS_NOT";
|
|
157
|
-
value: boolean;
|
|
158
|
-
subject: string;
|
|
159
|
-
type: "BOOLEAN";
|
|
160
|
-
[INTERNAL_KIND]: "FILTER";
|
|
161
|
-
};
|
|
162
|
-
isEmpty(): {
|
|
163
|
-
operator: "IS_EMPTY";
|
|
164
|
-
subject: string;
|
|
165
|
-
type: "BOOLEAN";
|
|
166
|
-
[INTERNAL_KIND]: "FILTER";
|
|
167
|
-
};
|
|
168
|
-
isNotEmpty(): {
|
|
169
|
-
operator: "IS_NOT_EMPTY";
|
|
170
|
-
subject: string;
|
|
171
|
-
type: "BOOLEAN";
|
|
172
|
-
[INTERNAL_KIND]: "FILTER";
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
number(subject: string): {
|
|
176
|
-
is(value: number): {
|
|
177
|
-
operator: "IS";
|
|
178
|
-
value: string;
|
|
179
|
-
subject: string;
|
|
180
|
-
type: "NUMERIC";
|
|
181
|
-
[INTERNAL_KIND]: "FILTER";
|
|
182
|
-
};
|
|
183
|
-
isNot(value: number): {
|
|
184
|
-
operator: "IS_NOT";
|
|
185
|
-
value: string;
|
|
186
|
-
subject: string;
|
|
187
|
-
type: "NUMERIC";
|
|
188
|
-
[INTERNAL_KIND]: "FILTER";
|
|
189
|
-
};
|
|
190
|
-
gt(value: number): {
|
|
191
|
-
operator: "GT";
|
|
192
|
-
value: string;
|
|
193
|
-
subject: string;
|
|
194
|
-
type: "NUMERIC";
|
|
195
|
-
[INTERNAL_KIND]: "FILTER";
|
|
196
|
-
};
|
|
197
|
-
gte(value: number): {
|
|
198
|
-
operator: "GTE";
|
|
199
|
-
value: string;
|
|
200
|
-
subject: string;
|
|
201
|
-
type: "NUMERIC";
|
|
202
|
-
[INTERNAL_KIND]: "FILTER";
|
|
203
|
-
};
|
|
204
|
-
lt(value: number): {
|
|
205
|
-
operator: "LT";
|
|
206
|
-
value: string;
|
|
207
|
-
subject: string;
|
|
208
|
-
type: "NUMERIC";
|
|
209
|
-
[INTERNAL_KIND]: "FILTER";
|
|
210
|
-
};
|
|
211
|
-
lte(value: number): {
|
|
212
|
-
operator: "LTE";
|
|
213
|
-
value: string;
|
|
214
|
-
subject: string;
|
|
215
|
-
type: "NUMERIC";
|
|
216
|
-
[INTERNAL_KIND]: "FILTER";
|
|
217
|
-
};
|
|
218
|
-
between(start: number, end: number): {
|
|
219
|
-
operator: "BETWEEN";
|
|
220
|
-
value: string[];
|
|
221
|
-
subject: string;
|
|
222
|
-
type: "NUMERIC";
|
|
223
|
-
[INTERNAL_KIND]: "FILTER";
|
|
224
|
-
};
|
|
225
|
-
isEmpty(): {
|
|
226
|
-
operator: "IS_EMPTY";
|
|
227
|
-
subject: string;
|
|
228
|
-
type: "NUMERIC";
|
|
229
|
-
[INTERNAL_KIND]: "FILTER";
|
|
230
|
-
};
|
|
231
|
-
isNotEmpty(): {
|
|
232
|
-
operator: "IS_NOT_EMPTY";
|
|
233
|
-
subject: string;
|
|
234
|
-
type: "NUMERIC";
|
|
235
|
-
[INTERNAL_KIND]: "FILTER";
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
array(subject: string): {
|
|
239
|
-
is(value: string[]): {
|
|
240
|
-
operator: "IS";
|
|
241
|
-
value: string[];
|
|
242
|
-
subject: string;
|
|
243
|
-
type: "ARRAY";
|
|
244
|
-
[INTERNAL_KIND]: "FILTER";
|
|
245
|
-
};
|
|
246
|
-
isOneOf(value: string[]): {
|
|
247
|
-
operator: "IS_ONE_OF";
|
|
248
|
-
value: string[];
|
|
249
|
-
subject: string;
|
|
250
|
-
type: "ARRAY";
|
|
251
|
-
[INTERNAL_KIND]: "FILTER";
|
|
252
|
-
};
|
|
253
|
-
isNoneOf(value: string[]): {
|
|
254
|
-
operator: "IS_NONE_OF";
|
|
255
|
-
value: string[];
|
|
256
|
-
subject: string;
|
|
257
|
-
type: "ARRAY";
|
|
258
|
-
[INTERNAL_KIND]: "FILTER";
|
|
259
|
-
};
|
|
260
|
-
hasAllOf(value: string[]): {
|
|
261
|
-
operator: "HAS_ALL_OF";
|
|
262
|
-
value: string[];
|
|
263
|
-
subject: string;
|
|
264
|
-
type: "ARRAY";
|
|
265
|
-
[INTERNAL_KIND]: "FILTER";
|
|
266
|
-
};
|
|
267
|
-
isEmpty(): {
|
|
268
|
-
operator: "IS_EMPTY";
|
|
269
|
-
subject: string;
|
|
270
|
-
type: "ARRAY";
|
|
271
|
-
[INTERNAL_KIND]: "FILTER";
|
|
272
|
-
};
|
|
273
|
-
isNotEmpty(): {
|
|
274
|
-
operator: "IS_NOT_EMPTY";
|
|
275
|
-
subject: string;
|
|
276
|
-
type: "ARRAY";
|
|
277
|
-
[INTERNAL_KIND]: "FILTER";
|
|
278
|
-
};
|
|
279
|
-
};
|
|
280
|
-
date(subject: string): {
|
|
281
|
-
is(value: string): {
|
|
282
|
-
operator: "IS";
|
|
283
|
-
value: string;
|
|
284
|
-
subject: string;
|
|
285
|
-
type: "DATE";
|
|
286
|
-
[INTERNAL_KIND]: "FILTER";
|
|
287
|
-
};
|
|
288
|
-
isNot(value: string): {
|
|
289
|
-
operator: "IS_NOT";
|
|
290
|
-
value: string;
|
|
291
|
-
subject: string;
|
|
292
|
-
type: "DATE";
|
|
293
|
-
[INTERNAL_KIND]: "FILTER";
|
|
294
|
-
};
|
|
295
|
-
gt(value: string): {
|
|
296
|
-
operator: "GT";
|
|
297
|
-
value: string;
|
|
298
|
-
subject: string;
|
|
299
|
-
type: "DATE";
|
|
300
|
-
[INTERNAL_KIND]: "FILTER";
|
|
301
|
-
};
|
|
302
|
-
gte(value: string): {
|
|
303
|
-
operator: "GTE";
|
|
304
|
-
value: string;
|
|
305
|
-
subject: string;
|
|
306
|
-
type: "DATE";
|
|
307
|
-
[INTERNAL_KIND]: "FILTER";
|
|
308
|
-
};
|
|
309
|
-
lt(value: string): {
|
|
310
|
-
operator: "LT";
|
|
311
|
-
value: string;
|
|
312
|
-
subject: string;
|
|
313
|
-
type: "DATE";
|
|
314
|
-
[INTERNAL_KIND]: "FILTER";
|
|
315
|
-
};
|
|
316
|
-
lte(value: string): {
|
|
317
|
-
operator: "LTE";
|
|
318
|
-
value: string;
|
|
319
|
-
subject: string;
|
|
320
|
-
type: "DATE";
|
|
321
|
-
[INTERNAL_KIND]: "FILTER";
|
|
322
|
-
};
|
|
323
|
-
between(start: string, end: string): {
|
|
324
|
-
operator: "BETWEEN";
|
|
325
|
-
value: string[];
|
|
326
|
-
subject: string;
|
|
327
|
-
type: "DATE";
|
|
328
|
-
[INTERNAL_KIND]: "FILTER";
|
|
329
|
-
};
|
|
330
|
-
isNotBetween(start: string, end: string): {
|
|
331
|
-
operator: "IS_NOT_BETWEEN";
|
|
332
|
-
value: string[];
|
|
333
|
-
subject: string;
|
|
334
|
-
type: "DATE";
|
|
335
|
-
[INTERNAL_KIND]: "FILTER";
|
|
336
|
-
};
|
|
337
|
-
isEmpty(): {
|
|
338
|
-
operator: "IS_EMPTY";
|
|
339
|
-
subject: string;
|
|
340
|
-
type: "DATE";
|
|
341
|
-
[INTERNAL_KIND]: "FILTER";
|
|
342
|
-
};
|
|
343
|
-
isNotEmpty(): {
|
|
344
|
-
operator: "IS_NOT_EMPTY";
|
|
345
|
-
subject: string;
|
|
346
|
-
type: "DATE";
|
|
347
|
-
[INTERNAL_KIND]: "FILTER";
|
|
348
|
-
};
|
|
349
|
-
};
|
|
350
|
-
asc(subject: string): ConstructableOrderBy;
|
|
351
|
-
desc(subject: string): ConstructableOrderBy;
|
|
352
|
-
};
|
|
353
|
-
//#endregion
|
|
354
|
-
//#region src/routes/visibility.d.ts
|
|
355
|
-
/**
|
|
356
|
-
* Declare this interface in your app to narrow every group id the SDK takes and
|
|
357
|
-
* returns. Without a declaration, a group id is a plain `string`.
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* declare module "@softr/sdk" {
|
|
361
|
-
* interface SoftrUserGroups {
|
|
362
|
-
* ids:
|
|
363
|
-
* | "b1f2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d"
|
|
364
|
-
* | "f9e8d7c6-5b4a-4938-8271-605f4e3d2c1b"
|
|
365
|
-
* }
|
|
366
|
-
* }
|
|
367
|
-
*/
|
|
368
|
-
interface SoftrUserGroups {}
|
|
369
|
-
/** A Softr user group id, narrowed to your own ids if you declare {@link SoftrUserGroups}. */
|
|
370
|
-
type SoftrUserGroupId = SoftrUserGroups extends {
|
|
371
|
-
ids: infer Id extends string;
|
|
372
|
-
} ? Id : string;
|
|
373
|
-
/**
|
|
374
|
-
* Who may see a route.
|
|
375
|
-
*
|
|
376
|
-
* - `ALL_USERS` — everyone, signed in or not.
|
|
377
|
-
* - `NON_LOGGED_IN_USERS` — signed-out visitors only.
|
|
378
|
-
* - `LOGGED_IN_USERS` — signed-in visitors; with `userGroupIds`, only members of
|
|
379
|
-
* at least one of those groups.
|
|
380
|
-
*/
|
|
381
|
-
type RouteVisibility = {
|
|
382
|
-
userGroup: "ALL_USERS";
|
|
383
|
-
} | {
|
|
384
|
-
userGroup: "NON_LOGGED_IN_USERS";
|
|
385
|
-
} | {
|
|
386
|
-
userGroup: "LOGGED_IN_USERS";
|
|
387
|
-
userGroupIds?: Array<SoftrUserGroupId>;
|
|
388
|
-
};
|
|
389
|
-
/** The signed-in visitor. */
|
|
390
|
-
type User = {
|
|
391
|
-
id: string;
|
|
392
|
-
email: string;
|
|
393
|
-
name: string;
|
|
394
|
-
userGroupIds: Array<SoftrUserGroupId>;
|
|
395
|
-
};
|
|
396
|
-
/** The route context the root route publishes: the visitor, or `null` when signed out. */
|
|
397
|
-
type SoftrContext = {
|
|
398
|
-
user: User | null;
|
|
399
|
-
};
|
|
400
|
-
/**
|
|
401
|
-
* Why a visitor was denied.
|
|
402
|
-
*
|
|
403
|
-
* - `unauthenticated` — the route needs a signed-in visitor and there is none.
|
|
404
|
-
* - `forbidden` — signed in, but in none of the groups the route names.
|
|
405
|
-
* - `alreadySignedIn` — the route is for signed-out visitors only.
|
|
406
|
-
*/
|
|
407
|
-
declare const ACCESS_REASONS: readonly ["unauthenticated", "forbidden", "alreadySignedIn"];
|
|
408
|
-
type AccessReason = (typeof ACCESS_REASONS)[number];
|
|
409
|
-
/**
|
|
410
|
-
* What a guard does when it refuses a visitor: redirect to a path, or throw an
|
|
411
|
-
* {@link AccessError} for the route's `errorComponent` to render. A bare string
|
|
412
|
-
* is shorthand for redirecting there.
|
|
413
|
-
*/
|
|
414
|
-
type AccessBehaviour = string | {
|
|
415
|
-
strategy: "redirect";
|
|
416
|
-
to: string;
|
|
417
|
-
} | {
|
|
418
|
-
strategy: "throw";
|
|
419
|
-
};
|
|
420
|
-
/** Per-reason overrides of the default {@link AccessBehaviour}. */
|
|
421
|
-
type GuardOverrides = Partial<Record<AccessReason, AccessBehaviour>>;
|
|
422
|
-
/** The result of {@link VisibilityHandle.check}: passed, or denied with a reason. */
|
|
423
|
-
type AccessCheck = {
|
|
424
|
-
ok: true;
|
|
425
|
-
} | {
|
|
426
|
-
ok: false;
|
|
427
|
-
reason: AccessReason;
|
|
428
|
-
};
|
|
429
|
-
/**
|
|
430
|
-
* The access error a guard throws. It is plain data, not an `Error` subclass, so
|
|
431
|
-
* take it as `unknown` in an `errorComponent` and narrow it with
|
|
432
|
-
* {@link isAccessError}. It carries the reason and nothing else: the error is
|
|
433
|
-
* serialized into the page, so it never names the groups the route wanted.
|
|
434
|
-
*
|
|
435
|
-
* @example
|
|
436
|
-
* errorComponent: ({ error }: { error: unknown }) =>
|
|
437
|
-
* isAccessError(error) ? <NoAccess /> : <AppError />
|
|
438
|
-
*/
|
|
439
|
-
type AccessError = {
|
|
440
|
-
type: "access_error";
|
|
441
|
-
reason: AccessReason;
|
|
442
|
-
};
|
|
443
|
-
/**
|
|
444
|
-
* True for any access error thrown by a guard, whatever its reason.
|
|
445
|
-
*
|
|
446
|
-
* An access error arrives as `unknown` — hydrated from the page, or thrown by
|
|
447
|
-
* anything else at all — so every field is checked before it is narrowed.
|
|
448
|
-
*/
|
|
449
|
-
declare function isAccessError(error: unknown): error is AccessError;
|
|
450
|
-
/** True for an access error thrown because nobody was signed in. */
|
|
451
|
-
declare function isUnauthenticatedError(error: unknown): error is AccessError;
|
|
452
|
-
/** True for an access error thrown because the visitor was in none of the groups. */
|
|
453
|
-
declare function isForbiddenError(error: unknown): error is AccessError;
|
|
454
|
-
/** True for an access error thrown because a signed-out-only route saw a user. */
|
|
455
|
-
declare function isAlreadySignedInError(error: unknown): error is AccessError;
|
|
456
|
-
type Narrowed<R extends RouteVisibility> = R extends {
|
|
457
|
-
userGroup: "LOGGED_IN_USERS";
|
|
458
|
-
} ? SoftrContext & {
|
|
459
|
-
user: User;
|
|
460
|
-
} : R extends {
|
|
461
|
-
userGroup: "NON_LOGGED_IN_USERS";
|
|
462
|
-
} ? SoftrContext & {
|
|
463
|
-
user: null;
|
|
464
|
-
} : SoftrContext;
|
|
465
|
-
/** The four ways to apply a rule, returned by {@link defineVisibility}. */
|
|
466
|
-
type VisibilityHandle<R extends RouteVisibility = RouteVisibility> = {
|
|
467
|
-
/**
|
|
468
|
-
* A `beforeLoad` handler that denies a visitor who fails the rule.
|
|
469
|
-
*
|
|
470
|
-
* By default an unauthenticated visitor is redirected to `/login`, an already
|
|
471
|
-
* signed-in one to `/`, and a forbidden one gets an {@link AccessError} thrown
|
|
472
|
-
* in place, for the route's `errorComponent` to render. Pass `overrides` to
|
|
473
|
-
* change what any one reason does.
|
|
474
|
-
*
|
|
475
|
-
* @example
|
|
476
|
-
* beforeLoad: visibility.guard({ unauthenticated: "/sign-in" })
|
|
477
|
-
*/
|
|
478
|
-
guard(overrides?: GuardOverrides): (opts: {
|
|
479
|
-
context: SoftrContext;
|
|
480
|
-
}) => void;
|
|
481
|
-
/**
|
|
482
|
-
* Throws the same access error or redirect `guard()` would, for code that
|
|
483
|
-
* needs to run its own checks after the rule.
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* beforeLoad: ({ context }) => {
|
|
487
|
-
* visibility.assert(context)
|
|
488
|
-
* if (context.user.trialExpired) throw redirect({ to: "/renew" })
|
|
489
|
-
* }
|
|
490
|
-
*/
|
|
491
|
-
assert(context: SoftrContext): void;
|
|
492
|
-
/**
|
|
493
|
-
* Whether the visitor passes the rule. Narrows `context.user` where the rule
|
|
494
|
-
* allows it.
|
|
495
|
-
*/
|
|
496
|
-
isAuthorized(context: SoftrContext): context is Narrowed<R>;
|
|
497
|
-
/** The decision and, when a visitor is refused, the reason. Throws nothing. */
|
|
498
|
-
check(context: SoftrContext): AccessCheck;
|
|
499
|
-
};
|
|
500
|
-
/**
|
|
501
|
-
* Declares who may see a route, and returns the handle that enforces it.
|
|
502
|
-
*
|
|
503
|
-
* One call per route file, at module scope: the build reads these declarations
|
|
504
|
-
* to publish the app's route visibility, so the rule must be a literal.
|
|
505
|
-
*
|
|
506
|
-
* @example
|
|
507
|
-
* const visibility = defineVisibility({ userGroup: "LOGGED_IN_USERS" })
|
|
508
|
-
*
|
|
509
|
-
* export const Route = createFileRoute("/about")({
|
|
510
|
-
* beforeLoad: visibility.guard(),
|
|
511
|
-
* component: About,
|
|
512
|
-
* })
|
|
513
|
-
*/
|
|
514
|
-
declare function defineVisibility<const R extends RouteVisibility>(rule: R): VisibilityHandle<R>;
|
|
515
|
-
//#endregion
|
|
516
|
-
//#region src/types.d.ts
|
|
517
|
-
interface SoftrUser {
|
|
518
|
-
id: string;
|
|
519
|
-
email: string;
|
|
520
|
-
name: string;
|
|
521
|
-
userGroupIds: Array<SoftrUserGroupId>;
|
|
522
|
-
}
|
|
523
|
-
interface DatasourcePermissions {
|
|
524
|
-
read: boolean;
|
|
525
|
-
create: boolean;
|
|
526
|
-
update: boolean;
|
|
527
|
-
delete: boolean;
|
|
528
|
-
}
|
|
529
|
-
interface SoftrPermissions {
|
|
530
|
-
datasources: Record<string, DatasourcePermissions>;
|
|
531
|
-
workflows: Record<string, boolean>;
|
|
532
|
-
}
|
|
533
|
-
interface SoftrMe {
|
|
534
|
-
user: SoftrUser | null;
|
|
535
|
-
permissions: SoftrPermissions;
|
|
536
|
-
}
|
|
537
|
-
type GetByIdOptions = {
|
|
538
|
-
id: string;
|
|
539
|
-
where?: never;
|
|
540
|
-
timeZone?: string;
|
|
541
|
-
};
|
|
542
|
-
type GetByWhereOptions = {
|
|
543
|
-
id?: never;
|
|
544
|
-
where: AnyConstructable;
|
|
545
|
-
timeZone?: string;
|
|
546
|
-
};
|
|
547
|
-
type GetOptions = GetByIdOptions | GetByWhereOptions;
|
|
548
|
-
interface ListOptions {
|
|
549
|
-
/**
|
|
550
|
-
* Maps human-readable aliases to Softr field IDs.
|
|
551
|
-
* When provided, returned fields are keyed by alias instead of raw field ID.
|
|
552
|
-
*/
|
|
553
|
-
select?: Record<string, string>;
|
|
554
|
-
where?: AnyConstructable;
|
|
555
|
-
orderBy?: ConstructableOrderBy | ConstructableOrderBy[];
|
|
556
|
-
/**
|
|
557
|
-
* Number of records to return per page. Defaults to 20, max 100.
|
|
558
|
-
*/
|
|
559
|
-
limit?: number;
|
|
560
|
-
/**
|
|
561
|
-
* Offset to start from. Pass the `nextOffset` from a previous result to paginate.
|
|
562
|
-
* Omit or pass `null` to start from the beginning.
|
|
563
|
-
*/
|
|
564
|
-
offset?: number | null;
|
|
565
|
-
/** Override the timezone for this request. */
|
|
566
|
-
timeZone?: string;
|
|
567
|
-
}
|
|
568
|
-
interface ListResult<T = SoftrRecord> {
|
|
569
|
-
records: T[];
|
|
570
|
-
total: number;
|
|
571
|
-
/** Offset to pass as `offset` in the next call, or `null` when there are no more pages. */
|
|
572
|
-
nextOffset: number | null;
|
|
573
|
-
}
|
|
574
|
-
interface SoftrRecord {
|
|
575
|
-
id: string;
|
|
576
|
-
fields: Record<string, unknown>;
|
|
577
|
-
}
|
|
578
|
-
type AggregationFunction = 'SUM' | 'AVG' | 'MAX' | 'MIN' | 'COUNT' | 'DISTINCT';
|
|
579
|
-
interface MetricOptions {
|
|
580
|
-
select?: Record<string, string>;
|
|
581
|
-
where?: AnyConstructable;
|
|
582
|
-
aggregation: AggregationFunction;
|
|
583
|
-
/** Field alias (resolved via select) or raw field ID. Not required for COUNT. */
|
|
584
|
-
field?: string;
|
|
585
|
-
/** Override the timezone for this request. */
|
|
586
|
-
timeZone?: string;
|
|
587
|
-
}
|
|
588
|
-
interface MetricResult {
|
|
589
|
-
value: number | null;
|
|
590
|
-
executionTimestamp: Date;
|
|
591
|
-
}
|
|
592
|
-
interface ChartDataOptions {
|
|
593
|
-
select?: Record<string, string>;
|
|
594
|
-
where?: AnyConstructable;
|
|
595
|
-
/** Field alias (resolved via select) or raw field ID. */
|
|
596
|
-
groupBy: string | string[];
|
|
597
|
-
metrics: Record<string, {
|
|
598
|
-
field?: string;
|
|
599
|
-
aggregation: AggregationFunction;
|
|
600
|
-
}>;
|
|
601
|
-
orderBy?: ConstructableOrderBy;
|
|
602
|
-
/** Override the timezone for this request. */
|
|
603
|
-
timeZone?: string;
|
|
604
|
-
}
|
|
605
|
-
interface ChartDataResult {
|
|
606
|
-
data: Record<string, unknown>[];
|
|
607
|
-
executionTimestamp: Date;
|
|
608
|
-
}
|
|
609
|
-
interface CreateOptions {
|
|
610
|
-
fields: Record<string, unknown>;
|
|
611
|
-
}
|
|
612
|
-
interface UpdateOptions {
|
|
613
|
-
id: string;
|
|
614
|
-
fields: Record<string, unknown>;
|
|
615
|
-
}
|
|
616
|
-
interface DatasourceAPI {
|
|
617
|
-
list(options?: ListOptions): Promise<ListResult>;
|
|
618
|
-
get(options: GetOptions): Promise<SoftrRecord | null>;
|
|
619
|
-
create(options: CreateOptions): Promise<SoftrRecord>;
|
|
620
|
-
update(options: UpdateOptions): Promise<SoftrRecord>;
|
|
621
|
-
delete(id: string): Promise<void>;
|
|
622
|
-
metric(options: MetricOptions): Promise<MetricResult>;
|
|
623
|
-
chartData(options: ChartDataOptions): Promise<ChartDataResult>;
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Proxy fetch for a configured integration (e.g. Google Calendar).
|
|
627
|
-
* Behaves like the native `fetch` API — requests are forwarded through
|
|
628
|
-
* Softr's proxy, which handles authentication with the third-party service.
|
|
629
|
-
*
|
|
630
|
-
* ⚠️ Caveats (same as the vibe block's `useProxyFetch`):
|
|
631
|
-
* - Body must be a string — FormData and other binary types are not supported.
|
|
632
|
-
* - Multi-value headers are flattened.
|
|
633
|
-
*/
|
|
634
|
-
interface IntegrationAPI {
|
|
635
|
-
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
636
|
-
}
|
|
637
|
-
interface WorkflowAPI {
|
|
638
|
-
trigger(payload?: Record<string, unknown>): Promise<void>;
|
|
639
|
-
}
|
|
640
|
-
interface AuthAPI {
|
|
641
|
-
/** Sign in with email and password. Clears the cached me() result. */
|
|
642
|
-
login(credentials: {
|
|
643
|
-
email: string;
|
|
644
|
-
password: string;
|
|
645
|
-
}): Promise<void>;
|
|
646
|
-
/** Sign out the current user. Clears the cached me() result. */
|
|
647
|
-
logout(): Promise<void>;
|
|
648
|
-
}
|
|
649
|
-
interface SoftrSDK {
|
|
650
|
-
/**
|
|
651
|
-
* Fetch the current user and their permissions from /me.
|
|
652
|
-
* Cached for the lifetime of the instance — create a new instance per request on the server.
|
|
653
|
-
*/
|
|
654
|
-
me(): Promise<SoftrMe>;
|
|
655
|
-
auth: AuthAPI;
|
|
656
|
-
datasource(id: string): DatasourceAPI;
|
|
657
|
-
integration(id: string): IntegrationAPI;
|
|
658
|
-
workflow(id: string): WorkflowAPI;
|
|
659
|
-
}
|
|
660
|
-
//#endregion
|
|
661
|
-
export { VisibilityHandle as A, AccessError as C, SoftrUserGroupId as D, SoftrContext as E, isUnauthenticatedError as F, q as I, isAccessError as M, isAlreadySignedInError as N, SoftrUserGroups as O, isForbiddenError as P, AccessCheck as S, RouteVisibility as T, SoftrSDK as _, CreateOptions as a, WorkflowAPI as b, GetOptions as c, ListResult as d, MetricOptions as f, SoftrRecord as g, SoftrPermissions as h, ChartDataResult as i, defineVisibility as j, User as k, IntegrationAPI as l, SoftrMe as m, AuthAPI as n, DatasourceAPI as o, MetricResult as p, ChartDataOptions as r, DatasourcePermissions as s, AggregationFunction as t, ListOptions as u, SoftrUser as v, AccessReason as w, AccessBehaviour as x, UpdateOptions as y };
|