@tunasand/sdk 0.8.0 → 0.12.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.
Files changed (221) hide show
  1. package/CHANGELOG.md +137 -0
  2. package/README.md +165 -144
  3. package/dist/analytics.js +183 -109
  4. package/dist/app.js +276 -166
  5. package/dist/apps-BysPfMuR.js +408 -0
  6. package/dist/astro-image.d.ts +1 -0
  7. package/dist/astro-image.js +33 -0
  8. package/dist/astro-server-Bwau8F6d.js +99 -0
  9. package/dist/astro-server.d.ts +1 -0
  10. package/dist/astro-server.js +1 -0
  11. package/dist/astro.d.ts +1 -0
  12. package/dist/astro.js +306 -0
  13. package/dist/bridge-C2Bl-OAF.js +80 -0
  14. package/dist/bridge.js +1 -13
  15. package/dist/build-file-DNi0PHC5.js +31 -0
  16. package/dist/cli.js +6212 -8
  17. package/dist/{client-Derrexwr.js → client-C8STAw9T.js} +43 -24
  18. package/dist/code-N8pBUDbq.js +30 -0
  19. package/dist/code.d.ts +1 -0
  20. package/dist/code.js +1 -0
  21. package/dist/collection-26aglrg6.js +282 -0
  22. package/dist/{declared-DuNMsdXw.js → declared-CE4a61qb.js} +35 -35
  23. package/dist/delivery.js +121 -114
  24. package/dist/dev-operations-Tutwi1On.js +46 -0
  25. package/dist/dev.js +9 -16
  26. package/dist/embeds-DY6O5TrJ.js +29 -0
  27. package/dist/end-users.d.ts +1 -0
  28. package/dist/end-users.js +189 -0
  29. package/dist/endUsers-DODfjnv1.js +77 -0
  30. package/dist/{errorLabels-BgtQ_zUn.js → errorLabels-BK1NJ6Wz.js} +374 -238
  31. package/dist/i18n.js +4 -4
  32. package/dist/ids-DmtIoqBX.js +109 -0
  33. package/dist/integrations.js +95 -24
  34. package/dist/{ja-Du6ooL6i.js → ja-B3lAaOhZ.js} +91 -45
  35. package/dist/{ja-CeHU0EaY.js → ja-axQPxMJ-.js} +3 -3
  36. package/dist/operations-CIB99rIY.js +95 -0
  37. package/dist/operations.d.ts +1 -0
  38. package/dist/operations.js +1 -0
  39. package/dist/{page-Bzrj24sJ.js → page-yo1cw1kW.js} +1 -1
  40. package/dist/paymentPort-p1jV44Zz.js +203 -0
  41. package/dist/preview.js +8 -1
  42. package/dist/{profile-1em_lcxq.js → profile-DBsXLvvI.js} +48 -48
  43. package/dist/rich-text.js +16 -16
  44. package/dist/{schema-WnobuwLg.js → schema-Bs_BUUNv.js} +526 -265
  45. package/dist/schema.js +66 -88
  46. package/dist/types/access/src/handoff.d.ts +19 -14
  47. package/dist/types/access/src/index.d.ts +2 -2
  48. package/dist/types/access/src/jws.d.ts +41 -0
  49. package/dist/types/access/src/oidc.d.ts +12 -2
  50. package/dist/types/access/src/signed.d.ts +0 -2
  51. package/dist/types/adapter-cloudflare/src/eventLog/viewSchema.d.ts +11 -0
  52. package/dist/types/contract/src/accountProfile.d.ts +7 -0
  53. package/dist/types/contract/src/api/define.d.ts +165 -0
  54. package/dist/types/contract/src/apiKeys.d.ts +6 -2
  55. package/dist/types/contract/src/app.d.ts +32 -7
  56. package/dist/types/contract/src/appChannels.d.ts +152 -0
  57. package/dist/types/contract/src/appDefinition.d.ts +11 -5
  58. package/dist/types/contract/src/appDependencies.d.ts +107 -24
  59. package/dist/types/contract/src/appIdentities.d.ts +21 -0
  60. package/dist/types/contract/src/appInbound.d.ts +53 -0
  61. package/dist/types/contract/src/appMail.d.ts +106 -0
  62. package/dist/types/contract/src/appSecrets.d.ts +63 -0
  63. package/dist/types/contract/src/appServer.d.ts +460 -45
  64. package/dist/types/contract/src/approvals.d.ts +1 -1
  65. package/dist/types/contract/src/apps.d.ts +126 -60
  66. package/dist/types/contract/src/auditActions.d.ts +2 -2
  67. package/dist/types/contract/src/auditLabels.d.ts +120 -15
  68. package/dist/types/contract/src/authorize.d.ts +42 -14
  69. package/dist/types/contract/src/bridge.d.ts +35 -36
  70. package/dist/types/contract/src/consents.d.ts +29 -27
  71. package/dist/types/contract/src/deletion.d.ts +18 -0
  72. package/dist/types/contract/src/embeds.d.ts +26 -90
  73. package/dist/types/contract/src/{customerLabels.d.ts → endUserLabels.d.ts} +6 -9
  74. package/dist/types/contract/src/endUsers.d.ts +244 -0
  75. package/dist/types/contract/src/errorLabels.d.ts +67 -37
  76. package/dist/types/contract/src/errorLabelsEn.d.ts +50 -33
  77. package/dist/types/contract/src/errors.d.ts +28 -16
  78. package/dist/types/contract/src/eventSchemas.d.ts +70 -0
  79. package/dist/types/contract/src/eventTraces.d.ts +41 -0
  80. package/dist/types/contract/src/failureStatus.d.ts +14 -22
  81. package/dist/types/contract/src/fieldAccess.d.ts +8 -8
  82. package/dist/types/contract/src/formLabels.d.ts +3 -0
  83. package/dist/types/contract/src/forms.d.ts +4 -0
  84. package/dist/types/contract/src/grants.d.ts +26 -0
  85. package/dist/types/contract/src/headers.d.ts +5 -0
  86. package/dist/types/contract/src/hostingRpc.d.ts +44 -19
  87. package/dist/types/contract/src/identifiers.d.ts +45 -17
  88. package/dist/types/contract/src/ids.d.ts +18 -10
  89. package/dist/types/contract/src/import.d.ts +17 -16
  90. package/dist/types/contract/src/index.d.ts +57 -29
  91. package/dist/types/contract/src/integrationGraph.d.ts +83 -0
  92. package/dist/types/contract/src/issueLabels.d.ts +121 -81
  93. package/dist/types/contract/src/issueLabelsEn.d.ts +61 -41
  94. package/dist/types/contract/src/manage.d.ts +16 -7
  95. package/dist/types/contract/src/manageLabels.d.ts +2 -0
  96. package/dist/types/contract/src/manifestText.d.ts +66 -0
  97. package/dist/types/contract/src/messagePort.d.ts +208 -0
  98. package/dist/types/contract/src/migration.d.ts +2 -2
  99. package/dist/types/contract/src/notices.d.ts +37 -0
  100. package/dist/types/contract/src/operationEffects.d.ts +39 -0
  101. package/dist/types/contract/src/operatorOperations.d.ts +104 -110
  102. package/dist/types/contract/src/outbound.d.ts +29 -0
  103. package/dist/types/contract/src/paths.d.ts +13 -0
  104. package/dist/types/contract/src/paymentPort.d.ts +129 -0
  105. package/dist/types/contract/src/pending.d.ts +2 -0
  106. package/dist/types/contract/src/permissions.d.ts +7 -11
  107. package/dist/types/contract/src/perspective.d.ts +26 -0
  108. package/dist/types/contract/src/powers.d.ts +5 -0
  109. package/dist/types/contract/src/principal.d.ts +127 -56
  110. package/dist/types/contract/src/readPages.d.ts +92 -0
  111. package/dist/types/contract/src/recordLabels.d.ts +6 -0
  112. package/dist/types/contract/src/roles.d.ts +7 -4
  113. package/dist/types/contract/src/ruleLabels.d.ts +16 -0
  114. package/dist/types/contract/src/ruleProblems.d.ts +16 -0
  115. package/dist/types/contract/src/schemaLabels.d.ts +8 -0
  116. package/dist/types/contract/src/settingProblems.d.ts +18 -1
  117. package/dist/types/contract/src/settings.d.ts +5 -7
  118. package/dist/types/contract/src/siteDeclaration.d.ts +7 -7
  119. package/dist/types/contract/src/siteIndex.d.ts +76 -0
  120. package/dist/types/contract/src/transfer.d.ts +1 -1
  121. package/dist/types/contract/src/trial.d.ts +4 -1
  122. package/dist/types/contract/src/versions.d.ts +1 -3
  123. package/dist/types/contract/src/viewEvent.d.ts +0 -9
  124. package/dist/types/contract/src/webhooks.d.ts +24 -3
  125. package/dist/types/contract/src/workflow.d.ts +16 -19
  126. package/dist/types/contract/src/workspaceItems.d.ts +23 -7
  127. package/dist/types/contract/src/workspacePaths.d.ts +1 -1
  128. package/dist/types/rich-text/src/html.d.ts +1 -1
  129. package/dist/types/rich-text/src/index.d.ts +8 -7
  130. package/dist/types/rich-text/src/labels/en.d.ts +1 -1
  131. package/dist/types/rich-text/src/labels/ja.d.ts +2 -2
  132. package/dist/types/rich-text/src/library.d.ts +1 -1
  133. package/dist/types/rich-text/src/media.d.ts +2 -0
  134. package/dist/types/rich-text/src/normalize.d.ts +1 -1
  135. package/dist/types/rich-text/src/problems.d.ts +5 -5
  136. package/dist/types/rich-text/src/profile.d.ts +10 -10
  137. package/dist/types/rich-text/src/render.d.ts +1 -1
  138. package/dist/types/rich-text/src/schema.d.ts +2 -2
  139. package/dist/types/rich-text/src/standard.d.ts +4 -4
  140. package/dist/types/rich-text/src/types.d.ts +2 -2
  141. package/dist/types/schema/src/audience.d.ts +1 -3
  142. package/dist/types/schema/src/capabilities.d.ts +18 -27
  143. package/dist/types/schema/src/changes.d.ts +3 -1
  144. package/dist/types/schema/src/collection.d.ts +142 -111
  145. package/dist/types/schema/src/defaultSchema.d.ts +8 -2
  146. package/dist/types/schema/src/fieldIds.d.ts +18 -0
  147. package/dist/types/schema/src/file.d.ts +24 -11
  148. package/dist/types/schema/src/fileRefs.d.ts +14 -0
  149. package/dist/types/schema/src/fileSignature.d.ts +20 -0
  150. package/dist/types/schema/src/filesCollection.d.ts +7 -0
  151. package/dist/types/schema/src/forms.d.ts +43 -0
  152. package/dist/types/schema/src/imageMetadata.d.ts +9 -0
  153. package/dist/types/schema/src/index.d.ts +19 -10
  154. package/dist/types/schema/src/indexes.d.ts +11 -0
  155. package/dist/types/schema/src/input.d.ts +1 -1
  156. package/dist/types/schema/src/integrity.d.ts +8 -7
  157. package/dist/types/schema/src/kinds.d.ts +26 -0
  158. package/dist/types/schema/src/labels/en.d.ts +89 -46
  159. package/dist/types/schema/src/labels/ja.d.ts +92 -46
  160. package/dist/types/schema/src/mediaUrl.d.ts +26 -33
  161. package/dist/types/schema/src/page.d.ts +4 -4
  162. package/dist/types/schema/src/problems.d.ts +85 -42
  163. package/dist/types/schema/src/refs.d.ts +0 -9
  164. package/dist/types/schema/src/schema.d.ts +17 -12
  165. package/dist/types/schema/src/selfOps.d.ts +20 -19
  166. package/dist/types/schema/src/traits.d.ts +28 -0
  167. package/dist/types/schema/src/typesSource.d.ts +1 -1
  168. package/dist/types/schema/src/values.d.ts +5 -2
  169. package/dist/types/schema/src/widening.d.ts +3 -0
  170. package/dist/types/sdk/src/analytics.d.ts +2 -1
  171. package/dist/types/sdk/src/app.d.ts +43 -14
  172. package/dist/types/sdk/src/astro-image.d.ts +19 -0
  173. package/dist/types/sdk/src/astro-response.d.ts +6 -0
  174. package/dist/types/sdk/src/astro-server.d.ts +16 -0
  175. package/dist/types/sdk/src/astro.d.ts +19 -0
  176. package/dist/types/sdk/src/bridge.d.ts +2 -4
  177. package/dist/types/sdk/src/code.d.ts +61 -0
  178. package/dist/types/sdk/src/delegation.d.ts +13 -3
  179. package/dist/types/sdk/src/delivery/changes.d.ts +4 -4
  180. package/dist/types/sdk/src/delivery/client.d.ts +33 -22
  181. package/dist/types/sdk/src/delivery/fields.d.ts +3 -3
  182. package/dist/types/sdk/src/delivery/index.d.ts +3 -3
  183. package/dist/types/sdk/src/delivery/media.d.ts +5 -8
  184. package/dist/types/sdk/src/delivery/query.d.ts +15 -11
  185. package/dist/types/sdk/src/delivery/schema.d.ts +1 -1
  186. package/dist/types/sdk/src/delivery/values.d.ts +10 -14
  187. package/dist/types/sdk/src/delivery.d.ts +2 -2
  188. package/dist/types/sdk/src/dev-operations.d.ts +20 -0
  189. package/dist/types/sdk/src/dev.d.ts +6 -5
  190. package/dist/types/sdk/src/end-users.d.ts +187 -0
  191. package/dist/types/sdk/src/i18n.d.ts +2 -2
  192. package/dist/types/sdk/src/integrations.d.ts +14 -21
  193. package/dist/types/sdk/src/operations.d.ts +17 -0
  194. package/dist/types/sdk/src/preview.d.ts +2 -1
  195. package/dist/types/sdk/src/rich-text.d.ts +2 -2
  196. package/dist/types/sdk/src/schema.d.ts +1 -1
  197. package/dist/types/sdk/src/site/artifact.d.ts +64 -0
  198. package/dist/types/sdk/src/site/build-file.d.ts +30 -0
  199. package/dist/types/sdk/src/site/check-code.d.ts +14 -0
  200. package/dist/types/sdk/src/site/check-text.d.ts +19 -0
  201. package/dist/types/sdk/src/site/cli.d.ts +52 -0
  202. package/dist/types/sdk/src/site/content-type.d.ts +2 -0
  203. package/dist/types/sdk/src/site/labels.d.ts +14 -0
  204. package/dist/types/sdk/src/types.d.ts +1 -1
  205. package/dist/{types-B77qvqPJ.js → types-CYnY-63C.js} +5 -6
  206. package/dist/types.js +1 -1
  207. package/dist/{typesSource-CWybQYus.js → typesSource-BTA9-rcB.js} +17 -15
  208. package/package.json +32 -6
  209. package/dist/apps-BxnJ1RlU.js +0 -435
  210. package/dist/bridge-DtHw9hS6.js +0 -74
  211. package/dist/collection-BEOxeISR.js +0 -189
  212. package/dist/customers-DTbL0qn6.js +0 -86
  213. package/dist/customers.d.ts +0 -1
  214. package/dist/customers.js +0 -185
  215. package/dist/embeds-B5V54Zur.js +0 -34
  216. package/dist/ids--RF7hGyC.js +0 -36
  217. package/dist/src-sazhzYui.js +0 -71
  218. package/dist/types/contract/src/customers.d.ts +0 -266
  219. package/dist/types/schema/src/legacy.d.ts +0 -2
  220. package/dist/types/schema/src/media.d.ts +0 -5
  221. package/dist/types/sdk/src/customers.d.ts +0 -184
package/dist/astro.js ADDED
@@ -0,0 +1,306 @@
1
+ import { n as provideOperations } from "./operations-CIB99rIY.js";
2
+ import { t as BUILD_FILE } from "./build-file-DNi0PHC5.js";
3
+ import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import { basename, dirname, join, posix, relative, resolve, sep } from "node:path";
6
+ import { homedir } from "node:os";
7
+ // src/astro.ts
8
+ const NAME = "@tunasand/sdk/astro";
9
+ const ENTRY = "virtual:tunasand/entry";
10
+ /** 隣の入口のファイル(ビルドの前は .ts、公開の形は .js) */
11
+ const sibling = (name) => fileURLToPath(new URL(`./${name}${import.meta.url.endsWith(".ts") ? ".ts" : ".js"}`, import.meta.url)).split(sep).join("/");
12
+ const SHARP = "astro/assets/services/sharp";
13
+ const MODULE = /\.(?:wasm|bin)(?:\?module)?$/;
14
+ const MARK = "tunasand-module:";
15
+ const fromOf = (id) => `from ${JSON.stringify(id)};`;
16
+ /** 入口のモジュール */
17
+ const entryPlugin = (handlers) => ({
18
+ name: "tunasand:entry",
19
+ resolveId: (id) => id === ENTRY ? `\0${ENTRY}` : null,
20
+ load: (id) => id !== `\0${ENTRY}` ? null : [
21
+ `import { createApp } ${fromOf("astro/app/entrypoint")}`,
22
+ `import { siteCode } ${fromOf(sibling("astro-server"))}`,
23
+ handlers ? `import * as handlers ${fromOf(handlers)}` : "const handlers = {};",
24
+ "export default siteCode(createApp(), handlers);"
25
+ ].join("\n")
26
+ });
27
+ /** コードが import する .wasm と .bin(サーバーのコードでは別のモジュールにし、開発と事前の描画では、その場で読む) */
28
+ function modulesPlugin() {
29
+ let building = false;
30
+ return {
31
+ name: "tunasand:modules",
32
+ enforce: "pre",
33
+ configResolved: (config) => {
34
+ building = config.command === "build";
35
+ },
36
+ async resolveId(id, importer) {
37
+ if (!MODULE.test(id) || this.environment.name === "client") return null;
38
+ const found = await this.resolve(id.replace(/\?module$/, ""), importer, { skipSelf: true });
39
+ if (!found) return null;
40
+ const file = found.id.replace(/\?.*$/, "");
41
+ if (!building || this.environment.name !== "ssr") return `${file}?tunasand-module`;
42
+ const source = readFileSync(file);
43
+ const ref = this.emitFile({
44
+ type: "asset",
45
+ name: basename(file),
46
+ fileName: `modules/${digestName(file, source)}`,
47
+ source
48
+ });
49
+ return {
50
+ id: `${MARK}${this.getFileName(ref)}`,
51
+ external: true
52
+ };
53
+ },
54
+ load(id) {
55
+ if (!id.endsWith("?tunasand-module")) return null;
56
+ const file = id.slice(0, id.lastIndexOf("?"));
57
+ const bytes = `Uint8Array.from(atob(${JSON.stringify(readFileSync(file).toString("base64"))}), (c) => c.charCodeAt(0))`;
58
+ return `export default ${file.endsWith(".wasm") ? `new WebAssembly.Module(${bytes})` : `${bytes}.buffer`};`;
59
+ },
60
+ renderChunk(code, chunk) {
61
+ if (!code.includes(MARK)) return null;
62
+ return {
63
+ code: code.replace(/tunasand-module:([^'"`]+)/g, (_, to) => {
64
+ const path = posix.relative(posix.dirname(chunk.fileName), to);
65
+ return path.startsWith(".") ? path : `./${path}`;
66
+ }),
67
+ map: null
68
+ };
69
+ }
70
+ };
71
+ }
72
+ /** 内容で決まるファイル名 */
73
+ function digestName(file, source) {
74
+ let hash = 14695981039346656037n;
75
+ for (const byte of source) hash = BigInt.asUintN(64, (hash ^ BigInt(byte)) * 1099511628211n);
76
+ const name = basename(file).replace(/[^A-Za-z0-9._-]/g, "_").replace(/^\.+/, "_");
77
+ return `${hash.toString(16).padStart(16, "0")}-${name}`;
78
+ }
79
+ /** サイトのコードが SDK を通さずに async_hooks を使うことを拒む */
80
+ const hooksPlugin = () => ({
81
+ name: "tunasand:async-hooks",
82
+ enforce: "pre",
83
+ resolveId(id, importer) {
84
+ if (!/^(?:node:)?async_hooks$/.test(id)) return null;
85
+ const own = importer?.split("?")[0].split(sep).join("/") ?? "";
86
+ if (own.includes("/node_modules/") || own === sibling("operations") || own.startsWith(`${dirname(sibling("operations"))}/`)) return null;
87
+ return this.error(`${NAME}: ${importer} imports ${id}. Use scopedValue() of @tunasand/sdk/operations`);
88
+ }
89
+ });
90
+ /** Astro の、埋め込まれた鍵を読む文 */
91
+ const KEY_LINE = "const key = decodeKey(serializedManifest.key);";
92
+ const NO_KEY = "const key = Promise.reject(new Error('server_islands_unsupported')); key.catch(() => {});";
93
+ /** サーバーの島を拒み、その鍵を読まないコードにする(鍵は、暗号にも復号にも使えない) */
94
+ function islandsPlugin() {
95
+ let hasIslands;
96
+ let building = false;
97
+ const patched = /* @__PURE__ */ new Set();
98
+ return {
99
+ name: "tunasand:server-islands",
100
+ removed: () => patched.has("ssr"),
101
+ configResolved(config) {
102
+ building = config.command === "build";
103
+ const { api } = config.plugins.find((p) => p.name === "astro:server-islands") ?? {};
104
+ hasIslands = api?.hasServerIslands;
105
+ },
106
+ transform(code, id) {
107
+ if (!building || !id.split("?")[0].endsWith("/astro/dist/core/app/manifest.js")) return null;
108
+ if (!code.includes(KEY_LINE)) return this.error(`${NAME}: this version of Astro reads the server island key in an unknown way. Use a supported version`);
109
+ patched.add(this.environment.name);
110
+ return {
111
+ code: code.replace(KEY_LINE, NO_KEY),
112
+ map: null
113
+ };
114
+ },
115
+ buildEnd() {
116
+ if (!building || this.environment.name === "client") return;
117
+ if (!hasIslands) this.error(`${NAME}: this version of Astro does not tell whether server islands are used. Use a supported version`);
118
+ if (hasIslands()) this.error(`${NAME}: server islands are not supported. Remove server:defer`);
119
+ }
120
+ };
121
+ }
122
+ /** PC のパスを、ファイル名のハッシュを決める前に替える */
123
+ const pathsPlugin = () => {
124
+ let root = "";
125
+ return {
126
+ name: "tunasand:local-paths",
127
+ enforce: "post",
128
+ apply: "build",
129
+ configResolved: (config) => {
130
+ root = resolve(config.root);
131
+ },
132
+ options: (given) => ({
133
+ ...given,
134
+ experimental: {
135
+ ...given.experimental,
136
+ attachDebugInfo: "none"
137
+ }
138
+ }),
139
+ renderChunk(code) {
140
+ const clean = this.environment.name === "prerender" ? code : withoutLocalPaths(code, root);
141
+ return clean === code ? null : {
142
+ code: clean,
143
+ map: null
144
+ };
145
+ }
146
+ };
147
+ };
148
+ const filesUnder = (dir, prefix = "") => readdirSync(`${dir}/${prefix}`, { withFileTypes: true }).flatMap((e) => e.isDirectory() ? filesUnder(dir, `${prefix}${e.name}/`) : [`${prefix}${e.name}`]);
149
+ /** 事前に描画したページの URL のパス */
150
+ const pagePathOf = (pathname) => `/${decodeURI(pathname).replace(/^\/+|\/+$/g, "")}`;
151
+ /** 事前に描画したページのファイルと、その URL のパス */
152
+ function prerenderedPages(files, pathnames) {
153
+ const paths = new Set(pathnames.map(pagePathOf));
154
+ return Object.fromEntries(files.flatMap((file) => {
155
+ if (!file.endsWith(".html")) return [];
156
+ const path = pagePathOf(`/${file}`.replace(/\.html$/, "").replace(/\/index$/, "") || "/");
157
+ return paths.has(path) ? [[file, path]] : [];
158
+ }));
159
+ }
160
+ /** 成果物に残さない PC のパスと、代わりの名前(長いものから) */
161
+ function localPaths(root) {
162
+ let top = root;
163
+ for (let dir = root; dirname(dir) !== dir; dir = dirname(dir)) if (existsSync(join(dir, "package.json"))) top = dir;
164
+ return [
165
+ [root, "/site"],
166
+ [top, "/workspace"],
167
+ [homedir(), "/home"]
168
+ ];
169
+ }
170
+ /** ビルドした PC のパス(利用者の名前を含む)を、固定の名前に替える */
171
+ const withoutLocalPaths = (code, root) => localPaths(root).reduce((text, [dir, name]) => dir.length < 4 ? text : text.replaceAll(pathToFileURL(dir).href, `file://${name}`).replaceAll(dir.split(sep).join("/"), name).replaceAll(dir.replaceAll("\\", "\\\\"), name).replaceAll(dir, name), code);
172
+ const refused = (what, fix) => /* @__PURE__ */ new Error(`${NAME}: ${what}. ${fix}`);
173
+ /** Tunasand のアダプター */
174
+ function tunasand({ handlers, operations, origins, reviewed } = {}) {
175
+ let outDir = "";
176
+ let root = "";
177
+ let build;
178
+ let trailingSlash = "";
179
+ let key = "";
180
+ const islands = islandsPlugin();
181
+ return {
182
+ name: NAME,
183
+ hooks: {
184
+ "astro:config:setup": ({ command, config, updateConfig }) => {
185
+ const own = handlers === void 0 ? null : fileURLToPath(new URL(handlers, config.root)).split(sep).join("/");
186
+ updateConfig({
187
+ vite: {
188
+ plugins: [
189
+ entryPlugin(own),
190
+ modulesPlugin(),
191
+ hooksPlugin(),
192
+ islands,
193
+ pathsPlugin()
194
+ ],
195
+ ...command === "build" && {
196
+ ssr: { target: "webworker" },
197
+ environments: { ssr: {
198
+ resolve: {
199
+ noExternal: true,
200
+ conditions: [
201
+ "worker",
202
+ "module",
203
+ "import",
204
+ "default"
205
+ ]
206
+ },
207
+ build: {
208
+ sourcemap: false,
209
+ rolldownOptions: { output: { codeSplitting: true } }
210
+ }
211
+ } }
212
+ }
213
+ },
214
+ ...command === "build" && "entrypoint" in config.image.service && config.image.service.entrypoint === SHARP && { image: {
215
+ service: {
216
+ build: config.image.service,
217
+ runtime: { entrypoint: sibling("astro-image") }
218
+ },
219
+ endpoint: { entrypoint: sibling("astro-image") }
220
+ } }
221
+ });
222
+ },
223
+ "astro:config:done": ({ config, setAdapter }) => {
224
+ setAdapter({
225
+ name: NAME,
226
+ entrypointResolution: "auto",
227
+ serverEntrypoint: ENTRY,
228
+ adapterFeatures: {
229
+ buildOutput: "server",
230
+ middlewareMode: "classic"
231
+ },
232
+ supportedAstroFeatures: {
233
+ staticOutput: "stable",
234
+ hybridOutput: "stable",
235
+ serverOutput: "stable",
236
+ i18nDomains: "unsupported",
237
+ envGetSecret: "unsupported",
238
+ sharpImageService: {
239
+ support: "limited",
240
+ message: "images are transformed only for prerendered pages",
241
+ suppress: "default"
242
+ }
243
+ }
244
+ });
245
+ ({trailingSlash} = config);
246
+ outDir = fileURLToPath(config.outDir);
247
+ root = resolve(fileURLToPath(config.root));
248
+ build = config.build;
249
+ if (config.session !== false) throw refused("sessions are not available", "Set session: false");
250
+ if (config.site !== void 0) throw refused("the origin must not be in the artifact", "Remove site and read the origin from the request");
251
+ if (config.base !== "/") throw refused("base is not supported", "Remove base");
252
+ const entrypoint = ("build" in config.image.service ? config.image.service.build : config.image.service).entrypoint;
253
+ if (entrypoint !== SHARP && entrypoint !== "astro/assets/services/noop") throw refused(`image.service ${entrypoint} is not supported`, "Images are transformed at build time by sharp. Remove image.service");
254
+ },
255
+ "astro:server:setup": ({ server }) => {
256
+ if (!operations) return;
257
+ server.middlewares.use((_request, response, next) => {
258
+ provideOperations(operations, () => new Promise((resolve) => {
259
+ response.once("close", () => resolve());
260
+ next();
261
+ }));
262
+ });
263
+ },
264
+ "astro:build:ssr": ({ manifest }) => {
265
+ ({key} = manifest);
266
+ manifest.key = "";
267
+ },
268
+ "astro:build:done": ({ pages, logger }) => {
269
+ const client = fileURLToPath(build.client);
270
+ for (const dir of [client, fileURLToPath(build.server)]) {
271
+ const left = filesUnder(dir).find((file) => key === "" || readFileSync(`${dir}/${file}`).includes(key));
272
+ if (left !== void 0 || !islands.removed()) throw refused(`the server island key could not be removed (${left})`, "Use a supported version of Astro");
273
+ }
274
+ const prerendered = prerenderedPages(filesUnder(client), pages.map((p) => p.pathname));
275
+ const errorOf = (status) => Object.values(prerendered).find((path) => path === `/${status}`);
276
+ const plain = Object.values(prerendered).filter((path) => ![
277
+ "/",
278
+ "/404",
279
+ "/500"
280
+ ].includes(path));
281
+ if (trailingSlash === "always" && plain.length > 0) throw refused(`prerendered pages cannot end with a slash (${plain[0]})`, "Set trailingSlash to 'never' or 'ignore'");
282
+ const server = fileURLToPath(build.server);
283
+ for (const file of filesUnder(server).filter((f) => /\.m?js$/.test(f))) {
284
+ const code = readFileSync(`${server}/${file}`, "utf8");
285
+ const clean = withoutLocalPaths(code, root);
286
+ if (clean !== code) writeFileSync(`${server}/${file}`, clean);
287
+ }
288
+ for (const { problem, code, reason } of reviewed ?? []) logger.info(`reviewed (build check only): [${problem}] ${code} (${reason})`);
289
+ const under = (dir) => relative(outDir, dir).split(sep).join("/") || ".";
290
+ const description = {
291
+ version: 1,
292
+ entry: build.serverEntry,
293
+ server: under(server),
294
+ client: under(client),
295
+ pages: prerendered,
296
+ errors: Object.fromEntries(["404", "500"].flatMap((s) => errorOf(s) ? [[s, errorOf(s)]] : [])),
297
+ immutable: [`/${build.assets}/`],
298
+ ...origins && { origins },
299
+ ...reviewed && { reviewed }
300
+ };
301
+ writeFileSync(`${outDir}/${BUILD_FILE}`, `${JSON.stringify(description, null, 2)}\n`);
302
+ }
303
+ }
304
+ };
305
+ }
306
+ export { tunasand as default, prerenderedPages, withoutLocalPaths };
@@ -0,0 +1,80 @@
1
+ import { n as EMBED_UI_SLOTS } from "./embeds-DY6O5TrJ.js";
2
+ // ../contract/src/bridge.ts
3
+ /** メッセージの名前の頭(外に見える識別子、改名はここだけ) */
4
+ const BRIDGE_NAMESPACE = "tunasand.bridge";
5
+ /** 規約の版 */
6
+ const BRIDGE_VERSION = 1;
7
+ /**
8
+ * 画面のトークン(アカウントの資格、設計は docs/specs/auth.md の「画面のトークン」)
9
+ * - 鍵はプロジェクトの鍵(コアだけが秘密鍵を持つ)。公開鍵は発行者のオリジンの jwksPath の JWKS で配り、kid で選ぶ
10
+ * - 方式は鍵の世代ごとの alg。検証は JWKS の鍵の alg に従い、受ける方式を algs の許可の一覧で絞る
11
+ * - アプリのサーバーは手元で検証できるが、画面のトークンで API は呼べない(トークンの交換でアカウントのトークンに替える)
12
+ * - トークンは接頭辞 SECRET_TOKEN_PREFIXES.screenToken と JWS のコンパクトな形。skewSec は検証の時計のずれの許容(秒)
13
+ */
14
+ const SESSION_TOKEN = {
15
+ typ: "tunasand-screen+jwt",
16
+ algs: ["ML-DSA-44"],
17
+ ttlSec: 60,
18
+ skewSec: 10,
19
+ jwksPath: "/.well-known/jwks.json",
20
+ recordsMax: 100
21
+ };
22
+ const isSec = (v) => typeof v === "number" && Number.isFinite(v);
23
+ /**
24
+ * 署名を確認した JWT のクレームが画面のトークンとして合うか、合えばクレーム
25
+ * - 発行者 issuer(公開の API のオリジン)、宛先 clientId(インストール済みアプリの ID)、期間、寿命。時計のずれは skewSec 秒まで
26
+ */
27
+ function sessionTokenClaimsOf(claims, { clientId, issuer }, nowSec) {
28
+ const { iss, aud, sub, env, slot, collection, records, iat, exp } = claims;
29
+ const { skewSec, ttlSec, recordsMax } = SESSION_TOKEN;
30
+ if (iss !== issuer || aud !== clientId || typeof sub !== "string" || typeof env !== "string") return null;
31
+ if (!Object.values(EMBED_UI_SLOTS).includes(slot) || collection !== null && typeof collection !== "string") return null;
32
+ if (!Array.isArray(records) || records.length > recordsMax || !records.every((r) => typeof r === "string")) return null;
33
+ if (!isSec(iat) || !isSec(exp) || iat > nowSec + skewSec || exp <= nowSec - skewSec || exp - iat > ttlSec) return null;
34
+ return {
35
+ iss,
36
+ aud,
37
+ sub,
38
+ env,
39
+ slot,
40
+ collection,
41
+ records,
42
+ iat,
43
+ exp
44
+ };
45
+ }
46
+ /** API の依頼(サーバーのないアプリ)のメソッド */
47
+ const BRIDGE_API_METHODS = [
48
+ "GET",
49
+ "POST",
50
+ "PATCH",
51
+ "DELETE"
52
+ ];
53
+ /**
54
+ * 見た目のトークンの名前(実験的)
55
+ * - ワークスペースの見た目の作り直しで名前と値が変わる。版で固定しないので、アプリは値がないときの既定を持つ
56
+ * - アプリの側では applyTheme が CSS の変数 --theme-<名前> として当てる
57
+ */
58
+ const BRIDGE_THEME_TOKENS = [
59
+ "accent",
60
+ "text",
61
+ "muted",
62
+ "surface",
63
+ "border",
64
+ "radius",
65
+ "font-family",
66
+ "font-size"
67
+ ];
68
+ /** アプリの側の CSS の変数の頭 */
69
+ const BRIDGE_THEME_VAR_PREFIX = "--theme-";
70
+ /** 依頼の失敗の理由 */
71
+ const BRIDGE_ERRORS = [
72
+ "unsupported",
73
+ "invalid",
74
+ "forbidden",
75
+ "rate_limited",
76
+ "failed"
77
+ ];
78
+ /** 名前の頭と版を持つ値か */
79
+ const isBridgeMessage = (data) => !!data && typeof data === "object" && data.ns === "tunasand.bridge" && typeof data.v === "number";
80
+ export { BRIDGE_THEME_VAR_PREFIX as a, isBridgeMessage as c, BRIDGE_THEME_TOKENS as i, sessionTokenClaimsOf as l, BRIDGE_ERRORS as n, BRIDGE_VERSION as o, BRIDGE_NAMESPACE as r, SESSION_TOKEN as s, BRIDGE_API_METHODS as t };
package/dist/bridge.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as BRIDGE_THEME_VAR_PREFIX, c as isBridgeMessage, i as BRIDGE_THEME_TOKENS, n as BRIDGE_ERRORS, o as BRIDGE_VERSION, r as BRIDGE_NAMESPACE, t as BRIDGE_API_METHODS } from "./bridge-DtHw9hS6.js";
1
+ import { a as BRIDGE_THEME_VAR_PREFIX, c as isBridgeMessage, i as BRIDGE_THEME_TOKENS, n as BRIDGE_ERRORS, o as BRIDGE_VERSION, r as BRIDGE_NAMESPACE, t as BRIDGE_API_METHODS } from "./bridge-C2Bl-OAF.js";
2
2
  // src/bridge.ts
3
3
  /** 依頼の失敗(code は理由) */
4
4
  var BridgeRequestError = class extends Error {
@@ -79,10 +79,6 @@ function bridgeOf(port, initial, hostOrigin, win, autoResize) {
79
79
  }
80
80
  if (m.kind !== "event" || typeof m.name !== "string") return;
81
81
  const name = m.name;
82
- if (name === "context") context = {
83
- ...context,
84
- ...m.data
85
- };
86
82
  if (name === "theme") context = {
87
83
  ...context,
88
84
  theme: m.data
@@ -163,14 +159,6 @@ function bridgeOf(port, initial, hostOrigin, win, autoResize) {
163
159
  })).confirmed,
164
160
  open: async (url) => (await request("open", { url })).opened,
165
161
  setValues: async (values) => (await request("setValues", { values })).applied,
166
- refreshContext: async () => {
167
- const next = await request("refreshContext", {});
168
- context = {
169
- ...context,
170
- ...next
171
- };
172
- return next;
173
- },
174
162
  openDialog: async (opts = {}) => (await request("openDialog", opts)).result,
175
163
  closeDialog: async (result) => void await request("closeDialog", { result }),
176
164
  displayNames: async (ids) => (await request("displayNames", { ids })).names,
@@ -0,0 +1,31 @@
1
+ // src/site/build-file.ts
2
+ const BUILD_FILE = "tunasand-build.json";
3
+ const KEYS = [
4
+ "version",
5
+ "entry",
6
+ "server",
7
+ "client",
8
+ "pages",
9
+ "errors",
10
+ "immutable",
11
+ "origins",
12
+ "reviewed"
13
+ ];
14
+ const isStrings = (v) => v === void 0 || Array.isArray(v) && v.every((s) => typeof s === "string" && s !== "");
15
+ const isMap = (v) => v === void 0 || typeof v === "object" && v !== null && !Array.isArray(v) && Object.values(v).every((s) => typeof s === "string");
16
+ const REVIEW_KEYS = [
17
+ "problem",
18
+ "code",
19
+ "reason"
20
+ ];
21
+ const isReviews = (v) => v === void 0 || Array.isArray(v) && v.every((r) => isMap(r) && typeof r === "object" && Object.keys(r).sort().join() === [...REVIEW_KEYS].sort().join() && Object.values(r).every((s) => s.trim() !== ""));
22
+ const isInside = (v) => typeof v === "string" && v !== "" && !/^[/\\]|^[A-Za-z]:|\\/.test(v) && !v.split("/").includes("..");
23
+ /** 読んだ値(正しくなければ null) */
24
+ function siteBuildOf(value) {
25
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
26
+ const b = value;
27
+ if (Object.keys(b).some((k) => !KEYS.includes(k)) || b.version !== 1) return null;
28
+ if (![b.entry, b.server].every(isInside) || b.client !== void 0 && !isInside(b.client)) return null;
29
+ return isMap(b.pages) && isMap(b.errors) && isStrings(b.immutable) && isStrings(b.origins) && isReviews(b.reviewed) ? value : null;
30
+ }
31
+ export { siteBuildOf as n, BUILD_FILE as t };