@jant/core 0.3.46 → 0.3.48

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.
Files changed (110) hide show
  1. package/bin/commands/db/execute-file.js +12 -4
  2. package/bin/commands/db/rehearse.js +2 -2
  3. package/bin/commands/export.js +12 -4
  4. package/bin/commands/import-site.js +60 -267
  5. package/bin/commands/migrate.js +36 -69
  6. package/bin/commands/reset-password.js +10 -4
  7. package/bin/commands/site/export.js +59 -248
  8. package/bin/commands/site/snapshot/export.js +58 -45
  9. package/bin/commands/site/snapshot/import.js +104 -52
  10. package/bin/lib/node-env.js +100 -0
  11. package/bin/lib/runtime-target.js +64 -0
  12. package/bin/lib/site-snapshot.js +185 -54
  13. package/bin/lib/sql-export.js +19 -2
  14. package/dist/app-DU7dpJID.js +6 -0
  15. package/dist/{app-DB-P66E5.js → app-DdnIoX7y.js} +333 -191
  16. package/dist/client/.vite/manifest.json +2 -2
  17. package/dist/client/_assets/client-BoUn7xBo.css +2 -0
  18. package/dist/client/_assets/{client-auth-BLCUje4M.js → client-auth-Ce5WEAVS.js} +102 -49
  19. package/dist/{github-sync-CQ1x271f.js → export-ZBlfKSKm.js} +12 -439
  20. package/dist/github-sync-C593r22F.js +4 -0
  21. package/dist/github-sync-bL1hnx3Q.js +428 -0
  22. package/dist/index.js +3 -2
  23. package/dist/node.js +5 -4
  24. package/package.json +3 -2
  25. package/src/__tests__/helpers/export-fixtures.ts +0 -1
  26. package/src/client/components/__tests__/jant-settings-avatar.test.ts +2 -0
  27. package/src/client/components/__tests__/jant-settings-general.test.ts +70 -0
  28. package/src/client/components/jant-settings-general.ts +164 -22
  29. package/src/client/components/settings-types.ts +4 -6
  30. package/src/client-auth.ts +1 -1
  31. package/src/db/__tests__/demo-canonical-snapshot.test.ts +1 -1
  32. package/src/db/__tests__/migration-rehearsal.test.ts +2 -5
  33. package/src/db/backfills/0004_register_apple_touch_media_rows.sql +65 -0
  34. package/src/db/migrations/0021_thankful_phalanx.sql +16 -0
  35. package/src/db/migrations/meta/0021_snapshot.json +2121 -0
  36. package/src/db/migrations/meta/_journal.json +7 -0
  37. package/src/db/migrations/pg/0019_gray_natasha_romanoff.sql +20 -0
  38. package/src/db/migrations/pg/meta/0019_snapshot.json +2718 -0
  39. package/src/db/migrations/pg/meta/_journal.json +7 -0
  40. package/src/db/pg/schema.ts +21 -26
  41. package/src/db/rehearsal-fixtures/demo-current.json +1 -1
  42. package/src/db/schema.ts +16 -20
  43. package/src/i18n/__tests__/middleware.test.ts +43 -1
  44. package/src/i18n/coverage.generated.ts +17 -0
  45. package/src/i18n/i18n.ts +18 -2
  46. package/src/i18n/index.ts +3 -0
  47. package/src/i18n/locales/settings/en.po +16 -11
  48. package/src/i18n/locales/settings/en.ts +1 -1
  49. package/src/i18n/locales/settings/zh-Hans.po +17 -12
  50. package/src/i18n/locales/settings/zh-Hans.ts +1 -1
  51. package/src/i18n/locales/settings/zh-Hant.po +16 -11
  52. package/src/i18n/locales/settings/zh-Hant.ts +1 -1
  53. package/src/i18n/locales.ts +84 -2
  54. package/src/i18n/middleware.ts +25 -16
  55. package/src/i18n/supported-locales.ts +153 -0
  56. package/src/lib/__tests__/csp-builder.test.ts +19 -2
  57. package/src/lib/__tests__/feed.test.ts +242 -1
  58. package/src/lib/__tests__/post-meta.test.ts +0 -1
  59. package/src/lib/__tests__/view.test.ts +0 -1
  60. package/src/lib/api-posts.ts +9 -7
  61. package/src/lib/csp-builder.ts +28 -10
  62. package/src/lib/feed.ts +153 -3
  63. package/src/middleware/__tests__/secure-headers.test.ts +89 -0
  64. package/src/middleware/auth.ts +1 -1
  65. package/src/middleware/secure-headers.ts +47 -1
  66. package/src/node/__tests__/cli-runtime-target.test.ts +110 -2
  67. package/src/node/__tests__/cli-site-snapshot.test.ts +308 -13
  68. package/src/node/__tests__/cli-site-token-env.test.ts +2 -7
  69. package/src/node/__tests__/cli-snapshot-meta.test.ts +85 -0
  70. package/src/node/__tests__/cli-sql-export.test.ts +49 -0
  71. package/src/node/index.ts +1 -0
  72. package/src/preset.css +8 -2
  73. package/src/routes/api/__tests__/settings.test.ts +3 -2
  74. package/src/routes/api/github-sync.tsx +1 -1
  75. package/src/routes/api/settings.ts +4 -1
  76. package/src/routes/auth/signin.tsx +6 -0
  77. package/src/routes/pages/archive.tsx +4 -2
  78. package/src/services/__tests__/post.test.ts +19 -19
  79. package/src/services/__tests__/search.test.ts +0 -1
  80. package/src/services/__tests__/settings.test.ts +22 -3
  81. package/src/services/bootstrap.ts +7 -3
  82. package/src/services/collection.ts +3 -3
  83. package/src/services/export.ts +0 -3
  84. package/src/services/navigation.ts +0 -2
  85. package/src/services/path.ts +1 -38
  86. package/src/services/post.ts +32 -66
  87. package/src/services/search.ts +0 -6
  88. package/src/services/settings.ts +47 -6
  89. package/src/services/site-admin.ts +6 -1
  90. package/src/styles/ui.css +14 -25
  91. package/src/types/entities.ts +0 -1
  92. package/src/ui/color-themes.ts +1 -1
  93. package/src/ui/dash/settings/GeneralContent.tsx +17 -19
  94. package/src/ui/dash/settings/SettingsRootContent.tsx +17 -28
  95. package/src/ui/feed/NoteCard.tsx +1 -11
  96. package/src/ui/feed/__tests__/timeline-cards.test.ts +1 -1
  97. package/src/ui/pages/PostPage.tsx +2 -0
  98. package/bin/commands/collections.js +0 -268
  99. package/bin/commands/media.js +0 -302
  100. package/bin/commands/posts.js +0 -262
  101. package/bin/commands/search.js +0 -53
  102. package/bin/commands/settings.js +0 -93
  103. package/bin/lib/http-api.js +0 -223
  104. package/bin/lib/media-upload.js +0 -206
  105. package/dist/app-CM7sb3xO.js +0 -5
  106. package/dist/client/_assets/client-DDs6NzB3.css +0 -2
  107. package/src/__tests__/bin/content-cli.test.ts +0 -179
  108. package/src/__tests__/bin/media-cli.test.ts +0 -192
  109. /package/dist/{github-api-BkRWnqMx.js → github-api-Bh0PH3zr.js} +0 -0
  110. /package/dist/{github-app-WeadXMb8.js → github-app-D0GvNnqp.js} +0 -0
@@ -1,206 +0,0 @@
1
- import { basename, extname } from "node:path";
2
- import { readFile } from "node:fs/promises";
3
- import { requestJson, requestRaw, resolveRequestUrl } from "./http-api.js";
4
-
5
- const MIME_TYPES = {
6
- ".avif": "image/avif",
7
- ".csv": "text/csv",
8
- ".gif": "image/gif",
9
- ".heic": "image/heic",
10
- ".jpeg": "image/jpeg",
11
- ".jpg": "image/jpeg",
12
- ".json": "application/json",
13
- ".md": "text/markdown",
14
- ".mov": "video/quicktime",
15
- ".mp3": "audio/mpeg",
16
- ".mp4": "video/mp4",
17
- ".pdf": "application/pdf",
18
- ".png": "image/png",
19
- ".svg": "image/svg+xml",
20
- ".txt": "text/plain",
21
- ".wav": "audio/wav",
22
- ".webm": "video/webm",
23
- ".webp": "image/webp",
24
- };
25
-
26
- function inferContentType(filePath, explicitContentType) {
27
- const trimmed = explicitContentType?.trim();
28
- if (trimmed) {
29
- return trimmed;
30
- }
31
-
32
- const ext = extname(filePath).toLowerCase();
33
- const inferred = MIME_TYPES[ext];
34
- if (inferred) {
35
- return inferred;
36
- }
37
-
38
- throw new Error(
39
- `Couldn't infer a content type for ${filePath}. Pass --content-type explicitly.`,
40
- );
41
- }
42
-
43
- function buildCompletePayload(metadata, parts) {
44
- return {
45
- ...(metadata.width === undefined ? {} : { width: metadata.width }),
46
- ...(metadata.height === undefined ? {} : { height: metadata.height }),
47
- ...(metadata.durationSeconds === undefined
48
- ? {}
49
- : { durationSeconds: metadata.durationSeconds }),
50
- ...(metadata.blurhash === undefined ? {} : { blurhash: metadata.blurhash }),
51
- ...(metadata.waveform === undefined ? {} : { waveform: metadata.waveform }),
52
- ...(metadata.summary === undefined ? {} : { summary: metadata.summary }),
53
- ...(metadata.chars === undefined ? {} : { chars: metadata.chars }),
54
- ...(parts ? { parts } : {}),
55
- };
56
- }
57
-
58
- async function uploadTransportBytes({ fileBytes, siteUrl, token, transport }) {
59
- switch (transport.kind) {
60
- case "relay": {
61
- await requestRaw({
62
- body: fileBytes,
63
- method: "PUT",
64
- token,
65
- url: resolveRequestUrl(siteUrl, transport.url),
66
- });
67
- return undefined;
68
- }
69
- case "put": {
70
- await requestRaw({
71
- body: fileBytes,
72
- headers: transport.headers,
73
- method: transport.method,
74
- url: transport.url,
75
- });
76
- return undefined;
77
- }
78
- case "multipartRelay": {
79
- const parts = [];
80
-
81
- for (
82
- let offset = 0, partNumber = 1;
83
- offset < fileBytes.byteLength;
84
- offset += transport.partSize, partNumber += 1
85
- ) {
86
- const partUrl = new URL(resolveRequestUrl(siteUrl, transport.url));
87
- partUrl.searchParams.set("partNumber", String(partNumber));
88
- const chunk = fileBytes.subarray(offset, offset + transport.partSize);
89
- const { json } = await requestRaw({
90
- body: chunk,
91
- method: "PUT",
92
- token,
93
- url: partUrl.toString(),
94
- });
95
-
96
- parts.push(json);
97
- }
98
-
99
- return parts;
100
- }
101
- default:
102
- throw new Error(`Unsupported upload transport: ${transport.kind}`);
103
- }
104
- }
105
-
106
- export async function uploadMediaFile({
107
- alt,
108
- blurhash,
109
- chars,
110
- contentType,
111
- durationSeconds,
112
- filePath,
113
- height,
114
- posterPath,
115
- siteUrl,
116
- summary,
117
- token,
118
- waveform,
119
- width,
120
- }) {
121
- const fileBytes = await readFile(filePath);
122
- const resolvedContentType = inferContentType(filePath, contentType);
123
- const filename = basename(filePath);
124
- const init = await requestJson({
125
- siteUrl,
126
- path: "/api/uploads/init",
127
- method: "POST",
128
- token,
129
- body: {
130
- filename,
131
- contentType: resolvedContentType,
132
- size: fileBytes.byteLength,
133
- },
134
- });
135
-
136
- if (
137
- !init ||
138
- typeof init !== "object" ||
139
- !("id" in init) ||
140
- !("transport" in init) ||
141
- !init.transport ||
142
- typeof init.transport !== "object" ||
143
- !("kind" in init.transport)
144
- ) {
145
- throw new Error("Upload init returned an unexpected response.");
146
- }
147
-
148
- const parts = await uploadTransportBytes({
149
- fileBytes,
150
- siteUrl,
151
- token,
152
- transport: init.transport,
153
- });
154
-
155
- if (posterPath?.trim()) {
156
- const posterBytes = await readFile(posterPath);
157
- await requestRaw({
158
- body: posterBytes,
159
- method: "PUT",
160
- token,
161
- url: resolveRequestUrl(siteUrl, `/api/uploads/${init.id}/poster`),
162
- });
163
- }
164
-
165
- const complete = await requestJson({
166
- siteUrl,
167
- path: `/api/uploads/${init.id}/complete`,
168
- method: "POST",
169
- token,
170
- body: buildCompletePayload(
171
- {
172
- alt,
173
- blurhash,
174
- chars,
175
- durationSeconds,
176
- height,
177
- summary,
178
- waveform,
179
- width,
180
- },
181
- Array.isArray(parts) ? parts : undefined,
182
- ),
183
- });
184
-
185
- if (!complete || typeof complete !== "object" || !("id" in complete)) {
186
- throw new Error("Upload complete returned an unexpected response.");
187
- }
188
-
189
- if (alt !== undefined) {
190
- return requestJson({
191
- siteUrl,
192
- path: `/api/upload/${complete.id}`,
193
- method: "PATCH",
194
- token,
195
- body: {
196
- alt,
197
- },
198
- });
199
- }
200
-
201
- return requestJson({
202
- siteUrl,
203
- path: `/api/upload/${complete.id}`,
204
- token,
205
- });
206
- }
@@ -1,5 +0,0 @@
1
- import "./url-umUptr5z.js";
2
- import { t as createApp } from "./app-DB-P66E5.js";
3
- import "./github-sync-CQ1x271f.js";
4
- import "./env-CgaH9Mut.js";
5
- export { createApp };