singularity-core 0.9.0 → 0.14.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.
@@ -0,0 +1,53 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.5.15/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true
7
+ },
8
+ "files": {
9
+ "ignoreUnknown": false
10
+ },
11
+ "formatter": {
12
+ "enabled": true,
13
+ "indentStyle": "tab"
14
+ },
15
+ "linter": {
16
+ "enabled": true,
17
+ "rules": {
18
+ "preset": "recommended"
19
+ }
20
+ },
21
+ "javascript": {
22
+ "formatter": {
23
+ "quoteStyle": "double"
24
+ }
25
+ },
26
+ "assist": {
27
+ "enabled": true,
28
+ "actions": {
29
+ "source": {
30
+ "organizeImports": "on"
31
+ }
32
+ }
33
+ },
34
+ "css": {
35
+ "parser": {
36
+ "tailwindDirectives": true
37
+ }
38
+ },
39
+ "overrides": [
40
+ {
41
+ "includes": ["**/src/lib/api/v*.d.ts", "**/routeTree.gen.ts"],
42
+ "formatter": {
43
+ "enabled": false
44
+ },
45
+ "linter": {
46
+ "enabled": false
47
+ },
48
+ "assist": {
49
+ "enabled": false
50
+ }
51
+ }
52
+ ]
53
+ }
package/dist/api/v1.d.ts CHANGED
@@ -218,7 +218,9 @@ export interface paths {
218
218
  };
219
219
  get: {
220
220
  parameters: {
221
- query?: never;
221
+ query?: {
222
+ Category?: string;
223
+ };
222
224
  header?: never;
223
225
  path?: never;
224
226
  cookie?: never;
@@ -253,7 +255,9 @@ export interface paths {
253
255
  };
254
256
  get: {
255
257
  parameters: {
256
- query?: never;
258
+ query?: {
259
+ Author?: string;
260
+ };
257
261
  header?: never;
258
262
  path?: never;
259
263
  cookie?: never;
@@ -398,10 +402,13 @@ export interface paths {
398
402
  get: {
399
403
  parameters: {
400
404
  query?: {
401
- Author?: string;
402
- Category?: string;
405
+ Author?: string[];
406
+ Category?: string[];
403
407
  OnlyWithImages?: boolean;
404
408
  Page?: number;
409
+ Search?: string;
410
+ /** @description Possible values: Newest, Oldest, TitleAsc, TitleDesc */
411
+ Sort?: components["schemas"]["PostSort"];
405
412
  Take?: number;
406
413
  };
407
414
  header?: never;
@@ -416,7 +423,7 @@ export interface paths {
416
423
  [name: string]: unknown;
417
424
  };
418
425
  content: {
419
- "application/json": components["schemas"]["PostResponsePagedResponse"];
426
+ "application/json": components["schemas"]["PostSummaryResponsePagedResponse"];
420
427
  };
421
428
  };
422
429
  /** @description Internal Server Error */
@@ -436,6 +443,99 @@ export interface paths {
436
443
  patch?: never;
437
444
  trace?: never;
438
445
  };
446
+ "/api/v1/blog/writer/posts": {
447
+ parameters: {
448
+ query?: never;
449
+ header?: never;
450
+ path?: never;
451
+ cookie?: never;
452
+ };
453
+ get: {
454
+ parameters: {
455
+ query?: {
456
+ Page?: number;
457
+ Take?: number;
458
+ };
459
+ header?: never;
460
+ path?: never;
461
+ cookie?: never;
462
+ };
463
+ requestBody?: never;
464
+ responses: {
465
+ /** @description OK */
466
+ 200: {
467
+ headers: {
468
+ [name: string]: unknown;
469
+ };
470
+ content: {
471
+ "application/json": components["schemas"]["PostSummaryResponsePagedResponse"];
472
+ };
473
+ };
474
+ };
475
+ };
476
+ put?: never;
477
+ post?: never;
478
+ delete?: never;
479
+ options?: never;
480
+ head?: never;
481
+ patch?: never;
482
+ trace?: never;
483
+ };
484
+ "/api/v1/blog/writer/posts/{id}": {
485
+ parameters: {
486
+ query?: never;
487
+ header?: never;
488
+ path?: never;
489
+ cookie?: never;
490
+ };
491
+ get?: never;
492
+ put: {
493
+ parameters: {
494
+ query?: never;
495
+ header?: never;
496
+ path: {
497
+ id: number;
498
+ };
499
+ cookie?: never;
500
+ };
501
+ requestBody: {
502
+ content: {
503
+ "application/json": components["schemas"]["PostUpdateRequest"];
504
+ };
505
+ };
506
+ responses: {
507
+ /** @description OK */
508
+ 200: {
509
+ headers: {
510
+ [name: string]: unknown;
511
+ };
512
+ content: {
513
+ "application/json": components["schemas"]["PostResponse"];
514
+ };
515
+ };
516
+ /** @description Bad Request */
517
+ 400: {
518
+ headers: {
519
+ [name: string]: unknown;
520
+ };
521
+ content?: never;
522
+ };
523
+ /** @description Not Found */
524
+ 404: {
525
+ headers: {
526
+ [name: string]: unknown;
527
+ };
528
+ content?: never;
529
+ };
530
+ };
531
+ };
532
+ post?: never;
533
+ delete?: never;
534
+ options?: never;
535
+ head?: never;
536
+ patch?: never;
537
+ trace?: never;
538
+ };
439
539
  "/api/v1/codiv/demo/scenario": {
440
540
  parameters: {
441
541
  query?: never;
@@ -470,6 +570,13 @@ export interface paths {
470
570
  };
471
571
  content?: never;
472
572
  };
573
+ /** @description Too Many Requests */
574
+ 429: {
575
+ headers: {
576
+ [name: string]: unknown;
577
+ };
578
+ content?: never;
579
+ };
473
580
  /** @description Internal Server Error */
474
581
  500: {
475
582
  headers: {
@@ -565,6 +672,13 @@ export interface paths {
565
672
  };
566
673
  content?: never;
567
674
  };
675
+ /** @description Too Many Requests */
676
+ 429: {
677
+ headers: {
678
+ [name: string]: unknown;
679
+ };
680
+ content?: never;
681
+ };
568
682
  /** @description Internal Server Error */
569
683
  500: {
570
684
  headers: {
@@ -804,6 +918,64 @@ export interface paths {
804
918
  patch?: never;
805
919
  trace?: never;
806
920
  };
921
+ "/api/v1/contact": {
922
+ parameters: {
923
+ query?: never;
924
+ header?: never;
925
+ path?: never;
926
+ cookie?: never;
927
+ };
928
+ get?: never;
929
+ put?: never;
930
+ post: {
931
+ parameters: {
932
+ query?: never;
933
+ header?: never;
934
+ path?: never;
935
+ cookie?: never;
936
+ };
937
+ requestBody: {
938
+ content: {
939
+ "application/json": components["schemas"]["SendContactMessageRequest"];
940
+ };
941
+ };
942
+ responses: {
943
+ /** @description No Content */
944
+ 204: {
945
+ headers: {
946
+ [name: string]: unknown;
947
+ };
948
+ content?: never;
949
+ };
950
+ /** @description Bad Request */
951
+ 400: {
952
+ headers: {
953
+ [name: string]: unknown;
954
+ };
955
+ content?: never;
956
+ };
957
+ /** @description Too Many Requests */
958
+ 429: {
959
+ headers: {
960
+ [name: string]: unknown;
961
+ };
962
+ content?: never;
963
+ };
964
+ /** @description Service Unavailable */
965
+ 503: {
966
+ headers: {
967
+ [name: string]: unknown;
968
+ };
969
+ content?: never;
970
+ };
971
+ };
972
+ };
973
+ delete?: never;
974
+ options?: never;
975
+ head?: never;
976
+ patch?: never;
977
+ trace?: never;
978
+ };
807
979
  "/api/v1/image/{id}": {
808
980
  parameters: {
809
981
  query?: never;
@@ -1136,6 +1308,13 @@ export interface paths {
1136
1308
  };
1137
1309
  content?: never;
1138
1310
  };
1311
+ /** @description Too Many Requests */
1312
+ 429: {
1313
+ headers: {
1314
+ [name: string]: unknown;
1315
+ };
1316
+ content?: never;
1317
+ };
1139
1318
  };
1140
1319
  };
1141
1320
  delete?: never;
@@ -1180,6 +1359,13 @@ export interface paths {
1180
1359
  };
1181
1360
  content?: never;
1182
1361
  };
1362
+ /** @description Too Many Requests */
1363
+ 429: {
1364
+ headers: {
1365
+ [name: string]: unknown;
1366
+ };
1367
+ content?: never;
1368
+ };
1183
1369
  };
1184
1370
  };
1185
1371
  delete?: never;
@@ -1525,99 +1711,6 @@ export interface paths {
1525
1711
  patch?: never;
1526
1712
  trace?: never;
1527
1713
  };
1528
- "/api/v1/writer/posts": {
1529
- parameters: {
1530
- query?: never;
1531
- header?: never;
1532
- path?: never;
1533
- cookie?: never;
1534
- };
1535
- get: {
1536
- parameters: {
1537
- query?: {
1538
- Page?: number;
1539
- Take?: number;
1540
- };
1541
- header?: never;
1542
- path?: never;
1543
- cookie?: never;
1544
- };
1545
- requestBody?: never;
1546
- responses: {
1547
- /** @description OK */
1548
- 200: {
1549
- headers: {
1550
- [name: string]: unknown;
1551
- };
1552
- content: {
1553
- "application/json": components["schemas"]["PostResponsePagedResponse"];
1554
- };
1555
- };
1556
- };
1557
- };
1558
- put?: never;
1559
- post?: never;
1560
- delete?: never;
1561
- options?: never;
1562
- head?: never;
1563
- patch?: never;
1564
- trace?: never;
1565
- };
1566
- "/api/v1/writer/posts/{id}": {
1567
- parameters: {
1568
- query?: never;
1569
- header?: never;
1570
- path?: never;
1571
- cookie?: never;
1572
- };
1573
- get?: never;
1574
- put: {
1575
- parameters: {
1576
- query?: never;
1577
- header?: never;
1578
- path: {
1579
- id: number;
1580
- };
1581
- cookie?: never;
1582
- };
1583
- requestBody: {
1584
- content: {
1585
- "application/json": components["schemas"]["PostUpdateRequest"];
1586
- };
1587
- };
1588
- responses: {
1589
- /** @description OK */
1590
- 200: {
1591
- headers: {
1592
- [name: string]: unknown;
1593
- };
1594
- content: {
1595
- "application/json": components["schemas"]["PostResponse"];
1596
- };
1597
- };
1598
- /** @description Bad Request */
1599
- 400: {
1600
- headers: {
1601
- [name: string]: unknown;
1602
- };
1603
- content?: never;
1604
- };
1605
- /** @description Not Found */
1606
- 404: {
1607
- headers: {
1608
- [name: string]: unknown;
1609
- };
1610
- content?: never;
1611
- };
1612
- };
1613
- };
1614
- post?: never;
1615
- delete?: never;
1616
- options?: never;
1617
- head?: never;
1618
- patch?: never;
1619
- trace?: never;
1620
- };
1621
1714
  }
1622
1715
  export type webhooks = Record<string, never>;
1623
1716
  export interface components {
@@ -1626,8 +1719,8 @@ export interface components {
1626
1719
  /** Format: uuid */
1627
1720
  parentCommentId?: string | null;
1628
1721
  /** Format: int32 */
1629
- postId?: number;
1630
- text?: string | null;
1722
+ postId: number;
1723
+ text: string;
1631
1724
  };
1632
1725
  AuthedUserResponse: {
1633
1726
  accessToken?: string | null;
@@ -1875,7 +1968,6 @@ export interface components {
1875
1968
  /** Format: int32 */
1876
1969
  id?: number;
1877
1970
  };
1878
- /** @description `IsDeleted`: removed by its author or an admin but kept for its replies; `Text` is empty. */
1879
1971
  GetPostCommentsResponse: {
1880
1972
  /** Format: date-time */
1881
1973
  createdAt?: string;
@@ -1890,7 +1982,6 @@ export interface components {
1890
1982
  userId?: string | null;
1891
1983
  username?: string | null;
1892
1984
  };
1893
- /** @description One page of a list. `Page` is zero-based; `Total` counts every row. */
1894
1985
  GetPostCommentsResponsePagedResponse: {
1895
1986
  items?: components["schemas"]["GetPostCommentsResponse"][] | null;
1896
1987
  /** Format: int32 */
@@ -1923,10 +2014,9 @@ export interface components {
1923
2014
  shortName?: string | null;
1924
2015
  };
1925
2016
  LoginRequest: {
1926
- password?: string | null;
1927
- username?: string | null;
2017
+ password: string;
2018
+ username: string;
1928
2019
  };
1929
- /** @description The session to end. Without a token (body or cookie) every session of the user ends. */
1930
2020
  LogoutRequest: {
1931
2021
  /** Format: uuid */
1932
2022
  refreshToken?: string | null;
@@ -1948,7 +2038,6 @@ export interface components {
1948
2038
  count?: number;
1949
2039
  name?: string | null;
1950
2040
  };
1951
- /** @description The post's picture. Add `w` and `h` to `Url` to get a size. */
1952
2041
  PostImageResponse: {
1953
2042
  /** Format: double */
1954
2043
  focusX?: number;
@@ -1985,9 +2074,34 @@ export interface components {
1985
2074
  /** Format: uuid */
1986
2075
  writerUserId?: string | null;
1987
2076
  };
1988
- /** @description One page of a list. `Page` is zero-based; `Total` counts every row. */
1989
- PostResponsePagedResponse: {
1990
- items?: components["schemas"]["PostResponse"][] | null;
2077
+ /**
2078
+ * @description Possible values: Newest, Oldest, TitleAsc, TitleDesc
2079
+ * @enum {string}
2080
+ */
2081
+ PostSort: "Newest" | "Oldest" | "TitleAsc" | "TitleDesc";
2082
+ PostSummaryResponse: {
2083
+ author?: string | null;
2084
+ /** Format: int32 */
2085
+ authorId?: number | null;
2086
+ /** Format: date-time */
2087
+ date?: string | null;
2088
+ excerpt?: string | null;
2089
+ /** Format: date-span */
2090
+ expectedTimeToRead?: string;
2091
+ /** Format: int32 */
2092
+ id?: number;
2093
+ image?: components["schemas"]["PostImageResponse"];
2094
+ imageCategory?: string | null;
2095
+ /** Format: int32 */
2096
+ likeCount?: number;
2097
+ likedByMe?: boolean;
2098
+ title?: string | null;
2099
+ unsplashImage?: string | null;
2100
+ /** Format: uuid */
2101
+ writerUserId?: string | null;
2102
+ };
2103
+ PostSummaryResponsePagedResponse: {
2104
+ items?: components["schemas"]["PostSummaryResponse"][] | null;
1991
2105
  /** Format: int32 */
1992
2106
  page?: number;
1993
2107
  /** Format: int32 */
@@ -1998,16 +2112,20 @@ export interface components {
1998
2112
  PostUpdateRequest: {
1999
2113
  content?: string | null;
2000
2114
  excerpt?: string | null;
2001
- title?: string | null;
2115
+ title: string;
2002
2116
  unsplashImage?: string | null;
2003
2117
  };
2004
- /** @description `RefreshToken` may be empty when the refresh cookie carries it. */
2005
2118
  RefreshRequest: {
2006
2119
  /** Format: uuid */
2007
2120
  refreshToken?: string;
2008
2121
  /** Format: uuid */
2009
2122
  userId?: string;
2010
2123
  };
2124
+ SendContactMessageRequest: {
2125
+ email?: string | null;
2126
+ message?: string | null;
2127
+ name?: string | null;
2128
+ };
2011
2129
  SendToolChatMessageRequest: {
2012
2130
  messages?: components["schemas"]["ToolChatMessageRequest"][] | null;
2013
2131
  };
@@ -2113,10 +2231,10 @@ export interface components {
2113
2231
  signature?: string | null;
2114
2232
  };
2115
2233
  /**
2116
- * @description Possible values: ADMIN, WRITER, USER
2234
+ * @description Possible values: ADMIN, BLOG_WRITER, BLOG_USER
2117
2235
  * @enum {string}
2118
2236
  */
2119
- UserRole: "ADMIN" | "WRITER" | "USER";
2237
+ UserRole: "ADMIN" | "BLOG_WRITER" | "BLOG_USER";
2120
2238
  };
2121
2239
  responses: never;
2122
2240
  parameters: never;
@@ -2176,5 +2294,6 @@ type ReadonlyArray<T> = [
2176
2294
  ] extends [
2177
2295
  unknown[]
2178
2296
  ] ? Readonly<Exclude<T, undefined>> : Readonly<Exclude<T, undefined>[]>;
2297
+ export declare const postSortValues: ReadonlyArray<FlattenedDeepRequired<components>["schemas"]["PostSort"]>;
2179
2298
  export declare const userRoleValues: ReadonlyArray<FlattenedDeepRequired<components>["schemas"]["UserRole"]>;
2180
2299
  export {};
package/dist/api/v1.js CHANGED
@@ -2,4 +2,5 @@
2
2
  * This file was auto-generated by openapi-typescript.
3
3
  * Do not make direct changes to the file.
4
4
  */
5
- export const userRoleValues = ["ADMIN", "WRITER", "USER"];
5
+ export const postSortValues = ["Newest", "Oldest", "TitleAsc", "TitleDesc"];
6
+ export const userRoleValues = ["ADMIN", "BLOG_WRITER", "BLOG_USER"];
@@ -9,17 +9,24 @@ export declare const USER_ROLES: readonly UserRole[];
9
9
  export declare const UserRoleEnum: { readonly [Role in UserRole]: Role; };
10
10
  export declare const UserRoleEnumSchema: z.ZodEnum<{
11
11
  ADMIN: "ADMIN";
12
- WRITER: "WRITER";
13
- USER: "USER";
12
+ BLOG_WRITER: "BLOG_WRITER";
13
+ BLOG_USER: "BLOG_USER";
14
14
  }>;
15
15
  export type EntityWithRoles = {
16
16
  roles?: UserRoles;
17
17
  } | null | undefined;
18
+ /**
19
+ * True when the entity holds `role`, or ADMIN: admin is global and passes
20
+ * every site's role checks, as it does in the API.
21
+ */
18
22
  export declare function hasRoleAccess(entity: EntityWithRoles, role: UserRole): boolean;
23
+ /** ADMIN: the admin app, and every site's features. */
19
24
  export declare function hasAdminAccess(entity: EntityWithRoles): boolean;
20
- export declare function hasWriterAccess(entity: EntityWithRoles): boolean;
21
- /** Admin or writer — can access the dashboard area. */
22
- export declare function hasDashboardAccess(entity: EntityWithRoles): boolean;
25
+ /**
26
+ * True when no roles are required, or the entity holds one of them or ADMIN.
27
+ * Site roles start with the site's name (`BLOG_WRITER`); list each one a
28
+ * feature accepts, ADMIN never needs listing.
29
+ */
23
30
  export declare function hasRequiredRoles(entity: EntityWithRoles, requiredRoles: UserRoles): boolean;
24
31
  export declare const isValidRole: (role: string) => role is UserRole;
25
32
  /**
@@ -5,25 +5,28 @@ export const USER_ROLES = userRoleValues;
5
5
  /** Each role by name, e.g. `UserRoleEnum.ADMIN === "ADMIN"`. */
6
6
  export const UserRoleEnum = Object.fromEntries(USER_ROLES.map((role) => [role, role]));
7
7
  export const UserRoleEnumSchema = z.enum(USER_ROLES);
8
+ /**
9
+ * True when the entity holds `role`, or ADMIN: admin is global and passes
10
+ * every site's role checks, as it does in the API.
11
+ */
8
12
  export function hasRoleAccess(entity, role) {
9
- return entity?.roles?.includes(role) ?? false;
13
+ return hasRequiredRoles(entity, [role]);
10
14
  }
15
+ /** ADMIN: the admin app, and every site's features. */
11
16
  export function hasAdminAccess(entity) {
12
- return hasRoleAccess(entity, UserRoleEnum.ADMIN);
13
- }
14
- export function hasWriterAccess(entity) {
15
- return hasRoleAccess(entity, UserRoleEnum.WRITER);
16
- }
17
- /** Admin or writer — can access the dashboard area. */
18
- export function hasDashboardAccess(entity) {
19
- return hasAdminAccess(entity) || hasWriterAccess(entity);
17
+ return entity?.roles?.includes(UserRoleEnum.ADMIN) ?? false;
20
18
  }
19
+ /**
20
+ * True when no roles are required, or the entity holds one of them or ADMIN.
21
+ * Site roles start with the site's name (`BLOG_WRITER`); list each one a
22
+ * feature accepts, ADMIN never needs listing.
23
+ */
21
24
  export function hasRequiredRoles(entity, requiredRoles) {
22
25
  if (!requiredRoles || requiredRoles.length === 0)
23
26
  return true;
24
- if (!entity?.roles)
25
- return false;
26
- return requiredRoles.some((role) => entity?.roles?.includes(role));
27
+ if (hasAdminAccess(entity))
28
+ return true;
29
+ return requiredRoles.some((role) => entity?.roles?.includes(role) ?? false);
27
30
  }
28
31
  export const isValidRole = (role) => {
29
32
  return USER_ROLES.includes(role);
@@ -14,13 +14,17 @@ export declare function createAuthClient(options: {
14
14
  }): AuthClient;
15
15
  export type CookieSessionOptions = {
16
16
  client: AuthClient;
17
- /** Cookie names are `<prefix>_access_token`, `_refresh_token` and `_user_id`. */
17
+ /**
18
+ * Cookie names are `<prefix>_access_token`, `_refresh_token` and
19
+ * `_user_id`, at path `/` with no Domain, so every app on the same host that
20
+ * passes the same prefix shares one sign-in: signing in or out in one signs
21
+ * in or out in all of them.
22
+ */
18
23
  cookiePrefix: string;
19
- /** Defaults to `/`. Apps sharing a domain need distinct prefixes or paths. */
20
- cookiePath?: string;
21
24
  /**
22
- * Roles a login must have, any one of them. Other accounts are refused and
23
- * the API session the login opened is closed again.
25
+ * Roles a login through this app must have, any one of them (ADMIN always
26
+ * passes). Other accounts are refused and the API session the login opened
27
+ * is closed again; a session already signed in through another app is kept.
24
28
  */
25
29
  loginRoles?: UserRoles;
26
30
  /** Error message for a login without `loginRoles`. */
@@ -41,7 +45,7 @@ export type ServerSession = Session & {
41
45
  * API itself, so no client code needs the tokens. Call only from server code
42
46
  * (server functions, middleware, loaders' server side).
43
47
  */
44
- export declare function createCookieSession({ client, cookiePrefix, cookiePath, loginRoles, loginRolesError, secure, }: CookieSessionOptions): {
48
+ export declare function createCookieSession({ client, cookiePrefix, loginRoles, loginRolesError, secure, }: CookieSessionOptions): {
45
49
  login: (username: string, password: string) => Promise<import("./index.js").PublicSession | null>;
46
50
  logout: () => Promise<{
47
51
  success: boolean;
@@ -74,7 +74,7 @@ function toSession(accessToken, userId, refreshToken) {
74
74
  * API itself, so no client code needs the tokens. Call only from server code
75
75
  * (server functions, middleware, loaders' server side).
76
76
  */
77
- export function createCookieSession({ client, cookiePrefix, cookiePath = "/", loginRoles = [], loginRolesError = "Access denied", secure = true, }) {
77
+ export function createCookieSession({ client, cookiePrefix, loginRoles = [], loginRolesError = "Access denied", secure = true, }) {
78
78
  const accessTokenCookie = `${cookiePrefix}_access_token`;
79
79
  const refreshTokenCookie = `${cookiePrefix}_refresh_token`;
80
80
  const userIdCookie = `${cookiePrefix}_user_id`;
@@ -83,7 +83,7 @@ export function createCookieSession({ client, cookiePrefix, cookiePath = "/", lo
83
83
  httpOnly: true,
84
84
  secure,
85
85
  sameSite: "lax",
86
- path: cookiePath,
86
+ path: "/",
87
87
  maxAge,
88
88
  };
89
89
  }
@@ -1,5 +1,7 @@
1
1
  /** A `text/plain` response, e.g. for robots.txt or security.txt routes. */
2
2
  export declare function plainTextResponse(body: string): Response;
3
+ /** An `application/xml` response, e.g. for a sitemap.xml route. */
4
+ export declare function xmlResponse(body: string): Response;
3
5
  /**
4
6
  * The visitor's IP as nginx saw it: `X-Real-IP`, else the last
5
7
  * `X-Forwarded-For` hop.
@@ -4,6 +4,12 @@ export function plainTextResponse(body) {
4
4
  headers: { "Content-Type": "text/plain; charset=utf-8" },
5
5
  });
6
6
  }
7
+ /** An `application/xml` response, e.g. for a sitemap.xml route. */
8
+ export function xmlResponse(body) {
9
+ return new Response(body, {
10
+ headers: { "Content-Type": "application/xml; charset=utf-8" },
11
+ });
12
+ }
7
13
  /**
8
14
  * The visitor's IP as nginx saw it: `X-Real-IP`, else the last
9
15
  * `X-Forwarded-For` hop.
@@ -28,6 +28,19 @@ export declare function toListParams(query: ListQuery): {
28
28
  Take: number | undefined;
29
29
  Search: string | undefined;
30
30
  };
31
+ /**
32
+ * A `ListQuery` as a server function validator: `page` and `take` are int32,
33
+ * and `take` stops at the API's largest page. Unknown keys are stripped.
34
+ */
35
+ export declare const ListQuerySchema: z.ZodObject<{
36
+ page: z.ZodOptional<z.ZodInt32>;
37
+ take: z.ZodOptional<z.ZodInt32>;
38
+ search: z.ZodOptional<z.ZodString>;
39
+ }, z.core.$strip>;
40
+ /** An id in the API's `{id:int}` routes (posts, images, authors, categories). */
41
+ export declare const IntIdSchema: z.ZodInt32;
42
+ /** An id in the API's `{id:guid}` routes (users, comments, generation jobs). */
43
+ export declare const GuidIdSchema: z.ZodGUID;
31
44
  /**
32
45
  * `?page=&search=` for server-paged lists. `page` is zero-based and omitted on
33
46
  * the first page; `search` filters the whole list on the API. A value that
@@ -33,6 +33,19 @@ export function pageCount(page) {
33
33
  export function toListParams(query) {
34
34
  return { Page: query.page, Take: query.take, Search: query.search };
35
35
  }
36
+ /**
37
+ * A `ListQuery` as a server function validator: `page` and `take` are int32,
38
+ * and `take` stops at the API's largest page. Unknown keys are stripped.
39
+ */
40
+ export const ListQuerySchema = z.object({
41
+ page: z.int32().min(0).optional(),
42
+ take: z.int32().min(1).max(MAX_PAGE_TAKE).optional(),
43
+ search: z.string().optional(),
44
+ });
45
+ /** An id in the API's `{id:int}` routes (posts, images, authors, categories). */
46
+ export const IntIdSchema = z.int32().positive();
47
+ /** An id in the API's `{id:guid}` routes (users, comments, generation jobs). */
48
+ export const GuidIdSchema = z.guid();
36
49
  /**
37
50
  * `?page=&search=` for server-paged lists. `page` is zero-based and omitted on
38
51
  * the first page; `search` filters the whole list on the API. A value that
@@ -36,3 +36,9 @@ export type RobotsTxtOptions = {
36
36
  };
37
37
  /** robots.txt for one user agent. Serve with `plainTextResponse`. */
38
38
  export declare function buildRobotsTxt({ userAgent, allow, disallow, sitemap, }: RobotsTxtOptions): string;
39
+ /**
40
+ * sitemap.xml listing each absolute URL once, in the order given. Serve with
41
+ * `xmlResponse`. It has no `lastmod`: a date that is not the page's real last
42
+ * change is worse than none.
43
+ */
44
+ export declare function buildSitemapXml(urls: string[]): string;
package/dist/seo/index.js CHANGED
@@ -37,3 +37,24 @@ export function buildRobotsTxt({ userAgent = "*", allow = [], disallow = [], sit
37
37
  "",
38
38
  ].join("\n");
39
39
  }
40
+ const xmlEntities = {
41
+ "&": "&amp;",
42
+ "<": "&lt;",
43
+ ">": "&gt;",
44
+ '"': "&quot;",
45
+ "'": "&apos;",
46
+ };
47
+ /**
48
+ * sitemap.xml listing each absolute URL once, in the order given. Serve with
49
+ * `xmlResponse`. It has no `lastmod`: a date that is not the page's real last
50
+ * change is worse than none.
51
+ */
52
+ export function buildSitemapXml(urls) {
53
+ return [
54
+ '<?xml version="1.0" encoding="UTF-8"?>',
55
+ '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
56
+ ...[...new Set(urls)].map((url) => `\t<url><loc>${url.replace(/[&<>"']/g, (char) => xmlEntities[char] ?? char)}</loc></url>`),
57
+ "</urlset>",
58
+ "",
59
+ ].join("\n");
60
+ }
package/package.json CHANGED
@@ -1,146 +1,150 @@
1
1
  {
2
- "name": "singularity-core",
3
- "version": "0.9.0",
4
- "description": "Shared non-UI code for Singularity TanStack Start apps: auth sessions, API client middleware, API schemas, paging, route data, images, formatting, HTTP helpers, theme, cookie notice, SEO, security headers and telemetry.",
5
- "type": "module",
6
- "author": "Filip",
7
- "license": "MIT",
8
- "files": [
9
- "dist"
10
- ],
11
- "sideEffects": false,
12
- "engines": {
13
- "node": ">=26.0.0 <27.0.0",
14
- "pnpm": ">=12.0.0 <13.0.0"
15
- },
16
- "exports": {
17
- "./auth": {
18
- "types": "./dist/auth/index.d.ts",
19
- "import": "./dist/auth/index.js"
20
- },
21
- "./auth/server": {
22
- "types": "./dist/auth/server.d.ts",
23
- "import": "./dist/auth/server.js"
24
- },
25
- "./api": {
26
- "types": "./dist/api/index.d.ts",
27
- "import": "./dist/api/index.js"
28
- },
29
- "./api/server": {
30
- "types": "./dist/api/server.d.ts",
31
- "import": "./dist/api/server.js"
32
- },
33
- "./paging": {
34
- "types": "./dist/paging/index.d.ts",
35
- "import": "./dist/paging/index.js"
36
- },
37
- "./paging/react": {
38
- "types": "./dist/paging/react.d.ts",
39
- "import": "./dist/paging/react.js"
40
- },
41
- "./router/react": {
42
- "types": "./dist/router/react.d.ts",
43
- "import": "./dist/router/react.js"
44
- },
45
- "./cookie-notice/server": {
46
- "types": "./dist/cookie-notice/server.d.ts",
47
- "import": "./dist/cookie-notice/server.js"
48
- },
49
- "./theme": {
50
- "types": "./dist/theme/index.d.ts",
51
- "import": "./dist/theme/index.js"
52
- },
53
- "./theme/server": {
54
- "types": "./dist/theme/server.d.ts",
55
- "import": "./dist/theme/server.js"
56
- },
57
- "./theme/react": {
58
- "types": "./dist/theme/react.d.ts",
59
- "import": "./dist/theme/react.js"
60
- },
61
- "./schema": {
62
- "types": "./dist/schema/index.d.ts",
63
- "import": "./dist/schema/index.js"
64
- },
65
- "./seo": {
66
- "types": "./dist/seo/index.d.ts",
67
- "import": "./dist/seo/index.js"
68
- },
69
- "./security": {
70
- "types": "./dist/security/index.d.ts",
71
- "import": "./dist/security/index.js"
72
- },
73
- "./telemetry": {
74
- "types": "./dist/telemetry/index.d.ts",
75
- "import": "./dist/telemetry/index.js"
76
- },
77
- "./images": {
78
- "types": "./dist/images/index.d.ts",
79
- "import": "./dist/images/index.js"
80
- },
81
- "./format": {
82
- "types": "./dist/format/index.d.ts",
83
- "import": "./dist/format/index.js"
84
- },
85
- "./http": {
86
- "types": "./dist/http/index.d.ts",
87
- "import": "./dist/http/index.js"
88
- },
89
- "./package.json": "./package.json"
90
- },
91
- "peerDependencies": {
92
- "@tanstack/react-router": "^1.170.0",
93
- "@tanstack/react-start": "^1.168.0",
94
- "jose": "^6.0.0",
95
- "openapi-fetch": "^0.17.0",
96
- "react": "^19.0.0",
97
- "zod": "^4.0.0"
98
- },
99
- "peerDependenciesMeta": {
100
- "@tanstack/react-router": {
101
- "optional": true
102
- },
103
- "@tanstack/react-start": {
104
- "optional": true
105
- },
106
- "jose": {
107
- "optional": true
108
- },
109
- "openapi-fetch": {
110
- "optional": true
111
- },
112
- "react": {
113
- "optional": true
114
- }
115
- },
116
- "devDependencies": {
117
- "@biomejs/biome": "2.5.15",
118
- "@tanstack/react-router": "1.170.42",
119
- "@tanstack/react-start": "1.168.61",
120
- "@types/node": "26.6.5",
121
- "@types/react": "19.3.0",
122
- "@types/react-dom": "19.3.0",
123
- "happy-dom": "20.11.13",
124
- "jose": "6.2.12",
125
- "openapi-fetch": "0.17.0",
126
- "openapi-typescript": "7.13.0",
127
- "react": "19.3.0",
128
- "react-dom": "19.3.0",
129
- "typescript": "6.0.3",
130
- "vitest": "5.0.3",
131
- "zod": "4.6.5"
132
- },
133
- "scripts": {
134
- "build": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
135
- "typecheck": "tsc --noEmit",
136
- "test": "vitest run",
137
- "test:watch": "vitest",
138
- "openapi-dev-types": "openapi-typescript http://localhost:5268/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
139
- "openapi-types": "openapi-typescript https://api.filion.se/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
140
- "check": "biome check",
141
- "verify": "pnpm run typecheck && pnpm run check && pnpm run test",
142
- "biome:check": "biome check --write",
143
- "biome:lint": "biome lint --fix",
144
- "biome:format": "biome format --write"
145
- }
146
- }
2
+ "name": "singularity-core",
3
+ "version": "0.14.0",
4
+ "description": "Shared non-UI code for Singularity TanStack Start apps: auth sessions, API client middleware, API schemas, paging, route data, images, formatting, HTTP helpers, theme, cookie notice, SEO, security headers and telemetry.",
5
+ "type": "module",
6
+ "author": "Filip",
7
+ "license": "MIT",
8
+ "files": [
9
+ "dist",
10
+ "config"
11
+ ],
12
+ "sideEffects": false,
13
+ "packageManager": "pnpm@12.3.4",
14
+ "engines": {
15
+ "node": ">=26.0.0 <27.0.0",
16
+ "pnpm": ">=12.0.0 <13.0.0"
17
+ },
18
+ "exports": {
19
+ "./auth": {
20
+ "types": "./dist/auth/index.d.ts",
21
+ "import": "./dist/auth/index.js"
22
+ },
23
+ "./auth/server": {
24
+ "types": "./dist/auth/server.d.ts",
25
+ "import": "./dist/auth/server.js"
26
+ },
27
+ "./api": {
28
+ "types": "./dist/api/index.d.ts",
29
+ "import": "./dist/api/index.js"
30
+ },
31
+ "./api/server": {
32
+ "types": "./dist/api/server.d.ts",
33
+ "import": "./dist/api/server.js"
34
+ },
35
+ "./paging": {
36
+ "types": "./dist/paging/index.d.ts",
37
+ "import": "./dist/paging/index.js"
38
+ },
39
+ "./paging/react": {
40
+ "types": "./dist/paging/react.d.ts",
41
+ "import": "./dist/paging/react.js"
42
+ },
43
+ "./router/react": {
44
+ "types": "./dist/router/react.d.ts",
45
+ "import": "./dist/router/react.js"
46
+ },
47
+ "./cookie-notice/server": {
48
+ "types": "./dist/cookie-notice/server.d.ts",
49
+ "import": "./dist/cookie-notice/server.js"
50
+ },
51
+ "./theme": {
52
+ "types": "./dist/theme/index.d.ts",
53
+ "import": "./dist/theme/index.js"
54
+ },
55
+ "./theme/server": {
56
+ "types": "./dist/theme/server.d.ts",
57
+ "import": "./dist/theme/server.js"
58
+ },
59
+ "./theme/react": {
60
+ "types": "./dist/theme/react.d.ts",
61
+ "import": "./dist/theme/react.js"
62
+ },
63
+ "./schema": {
64
+ "types": "./dist/schema/index.d.ts",
65
+ "import": "./dist/schema/index.js"
66
+ },
67
+ "./seo": {
68
+ "types": "./dist/seo/index.d.ts",
69
+ "import": "./dist/seo/index.js"
70
+ },
71
+ "./security": {
72
+ "types": "./dist/security/index.d.ts",
73
+ "import": "./dist/security/index.js"
74
+ },
75
+ "./telemetry": {
76
+ "types": "./dist/telemetry/index.d.ts",
77
+ "import": "./dist/telemetry/index.js"
78
+ },
79
+ "./images": {
80
+ "types": "./dist/images/index.d.ts",
81
+ "import": "./dist/images/index.js"
82
+ },
83
+ "./format": {
84
+ "types": "./dist/format/index.d.ts",
85
+ "import": "./dist/format/index.js"
86
+ },
87
+ "./http": {
88
+ "types": "./dist/http/index.d.ts",
89
+ "import": "./dist/http/index.js"
90
+ },
91
+ "./biome": "./config/biome-app.json",
92
+ "./package.json": "./package.json"
93
+ },
94
+ "scripts": {
95
+ "build": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json",
96
+ "typecheck": "tsc --noEmit",
97
+ "test": "vitest run",
98
+ "test:watch": "vitest",
99
+ "openapi-dev-types": "openapi-typescript http://localhost:5268/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
100
+ "openapi-types": "openapi-typescript https://api.filion.se/swagger/v1/swagger.json -o ./src/api/v1.ts --alphabetize --default-non-nullable --enum-values",
101
+ "prepack": "pnpm build",
102
+ "check": "biome check",
103
+ "verify": "pnpm run typecheck && pnpm run check && pnpm run test",
104
+ "biome:check": "biome check --write",
105
+ "biome:lint": "biome lint --fix",
106
+ "biome:format": "biome format --write"
107
+ },
108
+ "peerDependencies": {
109
+ "@tanstack/react-router": "^1.170.0",
110
+ "@tanstack/react-start": "^1.168.0",
111
+ "jose": "^6.0.0",
112
+ "openapi-fetch": "^0.17.0",
113
+ "react": "^19.0.0",
114
+ "zod": "^4.0.0"
115
+ },
116
+ "peerDependenciesMeta": {
117
+ "@tanstack/react-router": {
118
+ "optional": true
119
+ },
120
+ "@tanstack/react-start": {
121
+ "optional": true
122
+ },
123
+ "jose": {
124
+ "optional": true
125
+ },
126
+ "openapi-fetch": {
127
+ "optional": true
128
+ },
129
+ "react": {
130
+ "optional": true
131
+ }
132
+ },
133
+ "devDependencies": {
134
+ "@biomejs/biome": "2.5.15",
135
+ "@tanstack/react-router": "1.170.46",
136
+ "@tanstack/react-start": "1.169.4",
137
+ "@types/node": "26.6.6",
138
+ "@types/react": "19.3.0",
139
+ "@types/react-dom": "19.3.0",
140
+ "happy-dom": "20.14.6",
141
+ "jose": "6.2.13",
142
+ "openapi-fetch": "0.17.0",
143
+ "openapi-typescript": "7.13.0",
144
+ "react": "19.3.1",
145
+ "react-dom": "19.3.1",
146
+ "typescript": "6.0.3",
147
+ "vitest": "5.0.5",
148
+ "zod": "4.6.7"
149
+ }
150
+ }