@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
@@ -1,71 +0,0 @@
1
- // ../access/src/signed.ts
2
- const enc$1 = new TextEncoder();
3
- /** base64url の復号 */
4
- const decodeBase64Url = (s) => Uint8Array.from(atob(s.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(s.length / 4) * 4, "=")), (c) => c.charCodeAt(0));
5
- /** 経路ごとのヘッダーの名前(署名と主体) */
6
- const SIGNED_HEADERS = {
7
- /** MCP → CMS の署名(鍵は MCP_TOKEN、主体は Authorization のアクセストークン。Worker を通ったことの証明だけで、主体はトークンから CMS が決める) */
8
- mcp: "x-mcp-signature",
9
- /** CMS ⇄ サイトのプレビューと下書きの署名(鍵は PREVIEW_TOKEN) */
10
- preview: "x-preview-signature"
11
- };
12
- const hmacKey$1 = (secret) => crypto.subtle.importKey("raw", enc$1.encode(secret), {
13
- name: "HMAC",
14
- hash: "SHA-256"
15
- }, false, ["sign", "verify"]);
16
- /** 鍵の一覧(空の値を除く) */
17
- const secretsOf = (secret) => (typeof secret === "string" ? [secret] : [...secret ?? []]).filter(Boolean);
18
- /** 封印した値(鍵のどれかで署名が合えば値、署名の不一致・期限切れ・形の誤りは null) */
19
- async function openValue(secret, token, now = Date.now()) {
20
- const [body, sig] = token?.split(".") ?? [];
21
- const secrets = secretsOf(secret);
22
- if (!secrets.length || !body || !sig) return null;
23
- try {
24
- let matched = false;
25
- for (const s of secrets) if (!matched) matched = await crypto.subtle.verify("HMAC", await hmacKey$1(s), decodeBase64Url(sig), enc$1.encode(body));
26
- if (!matched) return null;
27
- const { v, exp } = JSON.parse(new TextDecoder().decode(decodeBase64Url(body)));
28
- return typeof exp === "number" && exp * 1e3 > now ? v : null;
29
- } catch {
30
- return null;
31
- }
32
- }
33
- // ../access/src/jws.ts
34
- const enc = new TextEncoder();
35
- const fromBase64Url = (text) => {
36
- if (!/^[A-Za-z0-9_-]*$/.test(text)) return null;
37
- try {
38
- return Uint8Array.from(atob(text.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(text.length / 4) * 4, "=")), (c) => c.charCodeAt(0));
39
- } catch {
40
- return null;
41
- }
42
- };
43
- const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
44
- const decodePart = (part) => {
45
- const bytes = fromBase64Url(part);
46
- if (!bytes) return null;
47
- try {
48
- const value = JSON.parse(new TextDecoder().decode(bytes));
49
- return isRecord(value) ? value : null;
50
- } catch {
51
- return null;
52
- }
53
- };
54
- const hmacKey = (secret) => crypto.subtle.importKey("raw", enc.encode(secret), {
55
- name: "HMAC",
56
- hash: "SHA-256"
57
- }, false, ["sign", "verify"]);
58
- /** HS256 の JWT のクレーム(鍵のどれかで署名が合えばクレーム、形の誤り、alg の違い、署名の不一致は null。期限などは見ない) */
59
- async function verifyHs256Jwt(secret, token) {
60
- const parts = token?.split(".") ?? [];
61
- if (parts.length !== 3) return null;
62
- const [head, body, sig] = parts;
63
- const header = decodePart(head);
64
- const claims = decodePart(body);
65
- const signature = fromBase64Url(sig);
66
- if (header?.alg !== "HS256" || !claims || !signature) return null;
67
- const data = enc.encode(`${head}.${body}`);
68
- for (const s of (typeof secret === "string" ? [secret] : secret).filter(Boolean)) if (await crypto.subtle.verify("HMAC", await hmacKey(s), signature, data)) return claims;
69
- return null;
70
- }
71
- export { SIGNED_HEADERS as n, openValue as r, verifyHs256Jwt as t };
@@ -1,266 +0,0 @@
1
- import { type ConsentPurpose } from './consents.js';
2
- /** 顧客の設定の表 settings のキー、設定の領域の id */
3
- export declare const CUSTOMERS_SETTINGS_KEY = "customers";
4
- /** 顧客の API の鍵の権限とロールの権限の対象(コレクションの id と重ならない) */
5
- export declare const CUSTOMERS_KEY_TARGET = "@customers";
6
- /** 人の状態(有効・停止・退会)。見られるかはアクセス権が決め、状態は停止と退会で照合と配信のエンドポイントを閉じる */
7
- export declare const CUSTOMER_STATUSES: readonly ["active", "suspended", "closed"];
8
- /** 顧客の状態 */
9
- export type CustomerStatus = (typeof CUSTOMER_STATUSES)[number];
10
- /** 顧客の状態か */
11
- export declare const isCustomerStatus: (v: unknown) => v is CustomerStatus;
12
- /** 権利の出どころ(manual は手動、import は取り込み、installation はインストール) */
13
- export declare const GRANT_SOURCES: readonly ["manual", "import", "installation"];
14
- /** 権利の出どころ */
15
- export type GrantSource = (typeof GRANT_SOURCES)[number];
16
- /** ID トークンの署名の方式(HS256 などの共有の鍵の方式は受け付けない) */
17
- export declare const CUSTOMER_ID_TOKEN_ALGORITHMS: readonly ["ES256", "RS256"];
18
- /** ID トークンの署名の方式 */
19
- export type CustomerIdTokenAlgorithm = (typeof CUSTOMER_ID_TOKEN_ALGORITHMS)[number];
20
- /**
21
- * 本人の証明の発行者(汎用の OIDC)
22
- * - id: 設定の中で一意(英小文字・数字・ハイフン)、label: 表示名
23
- * - issuer・audience: ID トークンの iss と aud、jwksUrl: 公開鍵の一覧の URL
24
- */
25
- export type CustomerProvider = Readonly<{
26
- id: string;
27
- label: string;
28
- issuer: string;
29
- audience: string;
30
- jwksUrl: string;
31
- algorithms: readonly CustomerIdTokenAlgorithm[];
32
- }>;
33
- /** LINE ログインの発行者の既定の値(audience はチャネルの ID) */
34
- export declare const LINE_PROVIDER: {
35
- readonly id: "line";
36
- readonly label: "LINE";
37
- readonly issuer: "https://access.line.me";
38
- readonly jwksUrl: "https://api.line.me/oauth2/v2.1/certs";
39
- readonly algorithms: readonly ["ES256"];
40
- };
41
- /** LINE ログインのチャネルの発行者 */
42
- export declare const lineProvider: (channelId: string) => CustomerProvider;
43
- /** Tunasand のドメイン(鍵の取得先に使えない、その下のホストも) */
44
- export declare const OWN_DOMAINS: readonly ["tunasand.jp", "tunasand.app", "tunasand.site", "tunasandbox.app"];
45
- /** 顧客の設定の値の範囲(graceSec は SDK の障害の間の猶予の秒、closedRetentionDays は退会の保持の日数) */
46
- export declare const CUSTOMERS_LIMITS: {
47
- readonly graceSec: {
48
- readonly min: 0;
49
- readonly max: 86400;
50
- readonly initial: 0;
51
- };
52
- readonly closedRetentionDays: {
53
- readonly min: 1;
54
- readonly max: 3650;
55
- readonly initial: 30;
56
- };
57
- readonly providers: {
58
- readonly max: 10;
59
- };
60
- };
61
- /** 期間の月の値の範囲 */
62
- export declare const GRANT_MONTHS: {
63
- readonly min: 1;
64
- readonly max: 1200;
65
- };
66
- /** 期間の月として使える値か(範囲の中の整数) */
67
- export declare const isGrantMonths: (value: unknown) => value is number;
68
- /** 期間の月からの終了日(開始日 startsOn の months か月後の前日、対応する日がない月はその月の末日) */
69
- export declare function endsOnAfterMonths(startsOn: string, months: number): string;
70
- /**
71
- * 付与の終了日(endsOn は指定で、undefined は省略、null は無期限。months は対象の期間の月で、宣言がないか値が空なら null)
72
- * - 決まらない(省略で期間の月がない)ときは undefined で、呼び出し元は終了日の指定を求める
73
- */
74
- export declare const grantEndsOn: (startsOn: string, endsOn: string | null | undefined, months: unknown) => string | null | undefined;
75
- /** 招待のリンクのコードの置き場所 */
76
- export declare const INVITE_CODE_PLACEHOLDER = "{code}";
77
- /**
78
- * 顧客の設定
79
- * - enabled: 顧客の機能の有効、profileCollection: プロフィールにするコレクションの id(そのコレクションは一意の顧客への参照の項目を1つ持つ)
80
- * - inviteUrl: 紐付けの招待のリンク({code} を含む https の URL、なしはコードだけ)
81
- * - providers: 本人の証明の発行者
82
- * - closedRetentionDays: 退会(closed)から削除までの日数(保持の間はスタッフが戻せる、毎日の処理 customer-deletions が削除)
83
- * - consentPurposes: プロジェクトが宣言する同意の目的(固定の service・marketing に足す、consents.ts)
84
- */
85
- /** ログインした人がだれでも読める顧客の設定の要約(有効か、発行者の id と表示名。ワークスペースの表示の切り替え) */
86
- export type CustomersConfig = Readonly<{
87
- enabled: boolean;
88
- providers: readonly Readonly<{
89
- id: string;
90
- label: string;
91
- }>[];
92
- }>;
93
- /** 顧客の設定の要約 */
94
- export declare const customersConfigOf: (s: Pick<CustomersSettings, "enabled" | "providers">) => CustomersConfig;
95
- export type CustomersSettings = Readonly<{
96
- enabled: boolean;
97
- profileCollection?: string;
98
- inviteUrl?: string;
99
- graceSec: number;
100
- closedRetentionDays: number;
101
- providers: readonly CustomerProvider[];
102
- consentPurposes?: readonly ConsentPurpose[];
103
- }>;
104
- /** 保存のない顧客の設定 */
105
- export declare const DEFAULT_CUSTOMERS_SETTINGS: CustomersSettings;
106
- /** 顧客の設定の問題の文 */
107
- export declare const CUSTOMERS_SETTINGS_ISSUES: {
108
- readonly shape: "顧客の設定の形が不正";
109
- readonly enabled: "有効は真偽";
110
- readonly profileCollection: "プロフィールのコレクションはコレクションの id";
111
- readonly graceSec: `\u7336\u4E88\u306F${number}\u304B\u3089${number}\u306E\u6574\u6570\uFF08\u79D2\uFF09`;
112
- readonly closedRetentionDays: `\u9000\u4F1A\u306E\u4FDD\u6301\u306F${number}\u304B\u3089${number}\u306E\u6574\u6570\uFF08\u65E5\uFF09`;
113
- readonly inviteUrl: `\u62DB\u5F85\u306E\u30EA\u30F3\u30AF\u306F ${string} \u3092\u542B\u3080 https \u306E URL`;
114
- readonly providers: `\u767A\u884C\u8005\u306F${number}\u4EF6\u307E\u3067`;
115
- readonly consentPurposes: `\u540C\u610F\u306E\u76EE\u7684\u306F${number}\u4EF6\u307E\u3067\u3067\u3001key \u306F\u82F1\u5C0F\u6587\u5B57\u3067\u59CB\u307E\u308B\u82F1\u5C0F\u6587\u5B57\u30FB\u6570\u5B57\u30FB_ \u306E32\u6587\u5B57\u307E\u3067\uFF08service \u3068 marketing \u3068\u91CD\u306A\u3089\u306A\u3044\uFF09\u3001\u8868\u793A\u540D\u306F\u7A7A\u3067\u306A\u3044\u6587\u5B57`;
116
- readonly providerId: "発行者の id は英小文字・数字・ハイフンで、設定の中で一意";
117
- readonly providerText: "発行者の表示名、iss、aud は空でない文字";
118
- readonly issuer: "発行者の iss は https の URL";
119
- readonly algorithms: `\u7F72\u540D\u306E\u65B9\u5F0F\u306F ${string} \u304B\u30891\u3064\u4EE5\u4E0A`;
120
- readonly jwksHttps: "公開鍵の取得先は https の URL";
121
- readonly jwksIp: "公開鍵の取得先のホストに IP アドレスは使えない";
122
- readonly jwksOwn: "公開鍵の取得先に Tunasand のドメインは使えない";
123
- };
124
- /** 顧客の設定の問題(path は設定のキー、message は CUSTOMERS_SETTINGS_ISSUES の文) */
125
- export type CustomersSettingsProblem = Readonly<{
126
- path: string;
127
- message: string;
128
- }>;
129
- /** 顧客の設定の検査(省いたキーは既定の値、問題があれば problems) */
130
- export declare function parseCustomersSettings(input: unknown): Readonly<{
131
- value: CustomersSettings;
132
- }> | Readonly<{
133
- problems: readonly CustomersSettingsProblem[];
134
- }>;
135
- /** 顧客のイベントの名前(Webhook) */
136
- export declare const CUSTOMER_EVENTS: {
137
- readonly statusChanged: "customer.status_changed";
138
- readonly deleted: "customer.deleted";
139
- };
140
- /** 顧客のイベントの値(Webhook の本文の data、snake_case)。from・to は前後の状態で、作成の前と削除の後は null */
141
- export type CustomerEventData = Readonly<{
142
- customer_id: string;
143
- from: CustomerStatus | null;
144
- to: CustomerStatus | null;
145
- }>;
146
- /**
147
- * 顧客の API の権利(公開の JSON は snake_case。日付は導入先のタイムゾーンの YYYY-MM-DD、ends_on は含む、null は終わりなし)
148
- * - collection・record: 権利の対象のコレクションとレコードの id とスラッグ(突き合わせは id で)
149
- * - expires_at: 終了日の翌日の0時(導入先のタイムゾーン、ISO 8601)、終わりなしは null
150
- */
151
- export type CustomerApiGrant = Readonly<{
152
- collection: Readonly<{
153
- id: string;
154
- slug: string;
155
- }>;
156
- record: Readonly<{
157
- id: string;
158
- slug: string;
159
- }>;
160
- starts_on: string;
161
- ends_on: string | null;
162
- expires_at?: string | null;
163
- }>;
164
- /**
165
- * 顧客の API の応答(照合・状態の取得・紐付け)
166
- * - customer.version: 状態の版(状態を変えるたびに1上がる)
167
- * - grants: 顧客の状態が active のときだけ、期限切れと開始前も含むすべて(停止と退会は空)
168
- * - today: 導入先のタイムゾーンの今日(権利の判定の基準)、grace_sec: SDK の障害の間の猶予(秒)
169
- */
170
- export type CustomerApiResult = Readonly<{
171
- customer: Readonly<{
172
- id: string;
173
- status: CustomerStatus;
174
- version?: number;
175
- }>;
176
- grants: readonly CustomerApiGrant[];
177
- today: string;
178
- grace_sec?: number;
179
- }>;
180
- /** 友だち追加の候補の作成の応答(created は今回作ったか、紐付けがあれば false でその顧客) */
181
- export type CustomerCandidateResult = Readonly<{
182
- customer: Readonly<{
183
- id: string;
184
- status: CustomerStatus;
185
- }>;
186
- created: boolean;
187
- }>;
188
- /** 顧客の API の業務の失敗のコード(ほかは配信 API の共通のエラー) */
189
- export declare const CUSTOMER_API_ERRORS: readonly ["invalid_id_token", "customer_not_linked", "customer_pending", "not_found", "already_linked", "invalid_invite"];
190
- /** 顧客の API の業務の失敗のコード */
191
- export type CustomerApiError = (typeof CUSTOMER_API_ERRORS)[number];
192
- /**
193
- * 本人のレコードのエンドポイント(#712、/customers/me/<コレクション>)の業務の失敗のコード(SDK が線の上のコードのまま値で返す)
194
- * - not_found: コレクションが操作を受けない・本人がいない・本人のレコードでない、invalid_input: 書けない項目や値の誤り(issues つき)
195
- * - save_unmet: コレクションの保存の規則を満たさない(issues つき)、version_conflict: 版が古い
196
- * - invalid_state: params.reason が customer_inactive(本人が停止か退会)か self_limit(顧客ごとのレコードの数の上限)
197
- * - rate_limited: 人ごとの書き込みかインストールごとの要求の回数の上限
198
- */
199
- export declare const SELF_API_ERRORS: readonly ["not_found", "forbidden", "invalid_input", "save_unmet", "version_conflict", "invalid_state", "rate_limited"];
200
- /** 本人のレコードのエンドポイントの業務の失敗のコード */
201
- export type SelfApiError = (typeof SELF_API_ERRORS)[number];
202
- /** 公開のクライアントの資格の能力(契約だけ、実装は要望の後) */
203
- export type PublicClientCapability = 'verify_with_proof' | 'refresh_token' | 'customer_delivery';
204
- /** ワークスペースの顧客の紐付け(provider は設定の発行者の id、設定にない発行者は null) */
205
- export type CustomerIdentityView = Readonly<{
206
- provider: string | null;
207
- issuer: string;
208
- audience: string;
209
- subject: string;
210
- createdAt: string;
211
- state: 'pending' | 'active';
212
- }>;
213
- /**
214
- * 確認待ちの紐付け(管理者の確認の一覧、#698 M3)
215
- * - grants は人の今と先の権利の数、rows は顧客フィールドでその人を指す行の数(結ぶとその外部 ID のログインで読めるもの)
216
- * - linked は同じ人に同じ発行者の active の紐付けがある(確認は拒まれる)、profile は人の題(プロフィールのレコード)
217
- */
218
- export type PendingIdentityView = CustomerIdentityView & Readonly<{
219
- customerId: string;
220
- customerStatus: CustomerStatus | null;
221
- grants: number;
222
- rows: number;
223
- linked: boolean;
224
- profile: CustomerProfileView;
225
- }>;
226
- /** ワークスペースの顧客のプロフィールのレコード(なければ null) */
227
- export type CustomerProfileView = Readonly<{
228
- collection: string;
229
- id: string;
230
- title: string;
231
- }> | null;
232
- /** ワークスペースの顧客の一覧の1行 */
233
- export type CustomerListItem = Readonly<{
234
- id: string;
235
- status: CustomerStatus;
236
- version: number;
237
- createdAt: string;
238
- identities: readonly CustomerIdentityView[];
239
- profile: CustomerProfileView;
240
- }>;
241
- /** ワークスペースの顧客の権利(installationId は出どころがインストールのときだけ) */
242
- export type CustomerGrantView = Readonly<{
243
- id: string;
244
- targetCollection: string;
245
- targetId: string;
246
- startsOn: string;
247
- endsOn: string | null;
248
- source: GrantSource;
249
- installationId: string | null;
250
- version: number;
251
- }>;
252
- /** ワークスペースの顧客の詳細(targetCollections は権利の対象にできるコレクション、today は導入先の今日、profileCollection はプロフィールのコレクション) */
253
- export type CustomerDetail = Readonly<{
254
- customer: Readonly<{
255
- id: string;
256
- status: CustomerStatus;
257
- version: number;
258
- createdAt: string;
259
- }>;
260
- identities: readonly CustomerIdentityView[];
261
- grants: readonly CustomerGrantView[];
262
- targetCollections: readonly string[];
263
- today: string;
264
- profile: CustomerProfileView;
265
- profileCollection: string | null;
266
- }>;
@@ -1,2 +0,0 @@
1
- /** 古い形のスキーマの JSON を今の形に(形の分からない値はそのまま、検査は parseSchema) */
2
- export declare function normalizeLegacySchema(json: unknown): unknown;
@@ -1,5 +0,0 @@
1
- import type { Collection } from './collection.js';
2
- /** 画像のコレクション */
3
- export declare const IMAGE_TYPE: Collection;
4
- /** 動画のコレクション(配信と再生は最初に使用する場所が決まったときに実装) */
5
- export declare const VIDEO_TYPE: Collection;
@@ -1,184 +0,0 @@
1
- import { type SelfApiError, CUSTOMER_EVENTS, type CustomerApiGrant, type CustomerApiError, type CustomerApiResult, type CustomerEventData } from '../../contract/src/customers.js';
2
- import type { Issue } from '../../contract/src/errors.js';
3
- import type { WebhookMessage } from '../../contract/src/webhooks.js';
4
- import { type Delivery } from './delivery/client.js';
5
- export { SELF_API_ERRORS, CUSTOMER_API_ERRORS, CUSTOMER_EVENTS, CUSTOMER_STATUSES } from '../../contract/src/customers.js';
6
- export type { Issue, IssueSeverity } from '../../contract/src/errors.js';
7
- export type { SelfApiError, CustomerApiGrant, CustomerApiError, CustomerApiResult, CustomerCandidateResult, CustomerEventData, CustomerStatus } from '../../contract/src/customers.js';
8
- export { grantedKeysOf } from '../../schema/src/index.js';
9
- /** 業務の失敗の補足(エラーの本文の params と requestId) */
10
- type FailureDetail = Readonly<{
11
- params?: Readonly<Record<string, unknown>>;
12
- requestId?: string;
13
- }>;
14
- /** 顧客の API の結果(業務の失敗は error のコード、T は成功の値) */
15
- export type CustomerCall<T = CustomerApiResult> = Readonly<{
16
- ok: true;
17
- value: T;
18
- }> | (Readonly<{
19
- ok: false;
20
- error: CustomerApiError;
21
- }> & FailureDetail);
22
- /** 紐付けの入力(招待のコードはワークスペースで発行したもの) */
23
- export type LinkInput = Readonly<{
24
- idToken: string;
25
- inviteCode: string;
26
- }>;
27
- /** 顧客の API の呼び出し(delivery は配信 API への接続、外のサイトは鍵を付けた fetch) */
28
- export declare function createCustomersClient(delivery: Delivery): {
29
- /** LIFF の ID トークンで照合(紐付けがなければ customer_not_linked、確認待ちは customer_pending、検証できなければ invalid_id_token) */
30
- verify: (idToken: string) => Promise<CustomerCall<Readonly<{
31
- customer: Readonly<{
32
- id: string;
33
- status: import("../../contract/src/index.js").CustomerStatus;
34
- version?: number;
35
- }>;
36
- grants: readonly CustomerApiGrant[];
37
- today: string;
38
- grace_sec?: number;
39
- }>>>;
40
- /** 顧客の ID で状態を取り直す(セッションの照合し直し、顧客がいなければ not_found) */
41
- lookup: (customerId: string) => Promise<CustomerCall<Readonly<{
42
- customer: Readonly<{
43
- id: string;
44
- status: import("../../contract/src/index.js").CustomerStatus;
45
- version?: number;
46
- }>;
47
- grants: readonly CustomerApiGrant[];
48
- today: string;
49
- grace_sec?: number;
50
- }>>>;
51
- /** 招待のコードの顧客に ID トークンの本人を紐付ける(紐付け済みは already_linked、招待のコードの誤りは invalid_invite) */
52
- link: ({ idToken, inviteCode }: LinkInput) => Promise<CustomerCall<Readonly<{
53
- customer: Readonly<{
54
- id: string;
55
- status: import("../../contract/src/index.js").CustomerStatus;
56
- version?: number;
57
- }>;
58
- grants: readonly CustomerApiGrant[];
59
- today: string;
60
- grace_sec?: number;
61
- }>>>;
62
- /** 友だち追加の userId で顧客候補を作る(Messaging API の Webhook の署名を確認した後だけ、紐付けがあれば何もしない) */
63
- createCandidate: (userId: string) => Promise<CustomerCall<Readonly<{
64
- customer: Readonly<{
65
- id: string;
66
- status: import("../../contract/src/index.js").CustomerStatus;
67
- }>;
68
- created: boolean;
69
- }>>>;
70
- /** ID トークンの人がアンケート(コレクション type、設問の版 version)に回答済みか */
71
- checkSubmission: (collection: string, idToken: string, version?: string) => Promise<CustomerCall<Readonly<{
72
- submitted: boolean;
73
- }>>>;
74
- };
75
- /** 顧客の API の呼び出し */
76
- export type CustomersClient = ReturnType<typeof createCustomersClient>;
77
- /** 本人のレコードの1件(id、本人が見られる項目、_meta の version は更新の版の条件) */
78
- export type SelfItem = Readonly<{
79
- id: string;
80
- _meta: Readonly<{
81
- created_at: string;
82
- updated_at: string;
83
- version: number;
84
- }>;
85
- }> & Readonly<Record<string, unknown>>;
86
- /** 本人のレコードの一覧の1ページ(next は次のページの cursor、最後のページは null) */
87
- export type SelfPage = Readonly<{
88
- items: readonly SelfItem[];
89
- next: string | null;
90
- }>;
91
- /**
92
- * 本人のレコードのエンドポイントの結果
93
- * (業務の失敗は error のコード、invalid_input と save_unmet は issues つき、invalid_state は params.reason)
94
- */
95
- export type SelfCall<T> = Readonly<{
96
- ok: true;
97
- value: T;
98
- }> | (Readonly<{
99
- ok: false;
100
- error: SelfApiError;
101
- issues?: readonly Issue[];
102
- }> & FailureDetail);
103
- /**
104
- * 本人のレコードのエンドポイントの呼び出し(#712、/content/v1/customers/me/<コレクション>)
105
- * - delivery はインストールのトークンを付けた接続(配信 API の鍵では呼べない)。customerId はサイトが自分で確認した本人
106
- * - query は配信 API の一覧の文法(filter[key]・order・ids・limit・cursor)で、絞れるのは本人が見られる項目だけ
107
- */
108
- export declare function createSelfClient(delivery: Delivery): {
109
- /** 本人のレコードの一覧(コレクション type、本人 customerId) */
110
- list: (collection: string, customerId: string, query?: Readonly<Record<string, string>>) => Promise<SelfCall<Readonly<{
111
- items: readonly SelfItem[];
112
- next: string | null;
113
- }>>>;
114
- /** 作成(同じ組のレコードがあれば作らずに created: false でそのレコードの id) */
115
- create: (collection: string, customerId: string, values: Readonly<Record<string, unknown>>) => Promise<SelfCall<Readonly<{
116
- id: string;
117
- created: boolean;
118
- }>>>;
119
- /** 更新(version は一覧の _meta.version、古ければ version_conflict) */
120
- update: (collection: string, id: string, customerId: string, version: number, values: Readonly<Record<string, unknown>>) => Promise<SelfCall<Readonly<{
121
- version: number;
122
- }>>>;
123
- /** 削除(ごみ箱へ) */
124
- delete: (collection: string, id: string, customerId: string) => Promise<SelfCall<Readonly<{
125
- deleted: true;
126
- }>>>;
127
- };
128
- /** 本人のレコードのエンドポイントの呼び出し */
129
- export type SelfClient = ReturnType<typeof createSelfClient>;
130
- /** 権利の時期(今日 today との比較、日付は YYYY-MM-DD で終了日を含む) */
131
- export type GrantPhase = 'active' | 'upcoming' | 'expired';
132
- /** 権利の時期 */
133
- export declare const grantPhase: (e: Pick<CustomerApiGrant, "starts_on" | "ends_on">, today: string) => GrantPhase;
134
- /**
135
- * 見せてよいかの判定
136
- * - reason: signed_out(照合の結果なし)・suspended・closed・no_grant・unavailable(再照合が失敗し猶予もない)
137
- * - expired は endsOn に最後の終了日、upcoming は startsOn に最初の開始日(SDK の判定の値、線の上の ends_on・starts_on から)
138
- */
139
- export type CustomerAccess = Readonly<{
140
- ok: true;
141
- }> | Readonly<{
142
- ok: false;
143
- reason: 'signed_out' | 'suspended' | 'closed' | 'no_grant' | 'unavailable';
144
- }> | Readonly<{
145
- ok: false;
146
- reason: 'expired';
147
- endsOn: string;
148
- }> | Readonly<{
149
- ok: false;
150
- reason: 'upcoming';
151
- startsOn: string;
152
- }>;
153
- /**
154
- * 顧客だけの項目を見せてよいか
155
- * - requires: 配信の _meta.requires(undefined は顧客の出し分けのないコレクションで誰でも可、空は有効な権利を1つでも持つ人)
156
- * - customer: 照合か状態の取得の結果(ログインしていなければ null)
157
- * - today: 判定の基準の日付(既定は応答の today)
158
- */
159
- export declare function customerAccess(customer: CustomerApiResult | null, requires: readonly string[] | undefined, today?: string | undefined): CustomerAccess;
160
- /** 最後に成功した照合(result は照合か状態の取得の結果、checkedAt はその時刻のミリ秒。再照合が失敗しても更新しない) */
161
- export type CustomerSnapshot = Readonly<{
162
- result: CustomerApiResult;
163
- checkedAt: number;
164
- }>;
165
- /**
166
- * 再照合の失敗に猶予が効くか(Tunasand に届かないか 5xx だけ)
167
- * - failure: 顧客の API の呼び出しが投げた例外か、業務の失敗の結果({ ok: false }、明示の拒否なので効かない)
168
- * - 届かない: fetch の TypeError と時間切れ(TimeoutError)
169
- */
170
- export declare function isTransientFailure(failure: unknown): boolean;
171
- /** 猶予の期限のミリ秒(最後に成功した照合の時刻に応答の grace_sec を足す、grace_sec は0から86400に収める) */
172
- export declare const graceDeadline: (snapshot: CustomerSnapshot) => number;
173
- /**
174
- * 再照合が失敗したときの顧客だけの項目の判定
175
- * - 猶予の間(isTransientFailure で now が graceDeadline より前)は最後の結果で判定し、権利の expires_at は now で効かせる
176
- * - それ以外は unavailable(requires が undefined の型は誰でも可)
177
- */
178
- export declare function graceAccess(last: CustomerSnapshot, failure: unknown, requires: readonly string[] | undefined, now?: number): CustomerAccess;
179
- /** 見せてよくなければアクセス権の項目(keys、grantedKeysOf の値)を除いた1件 */
180
- export declare function visibleItem<T extends Readonly<Record<string, unknown>>>(item: T, access: CustomerAccess, keys: readonly string[]): T;
181
- /** 顧客のイベントの Webhook の本文(type はイベントの名前、timestamp はイベントの日時) */
182
- export type CustomerEvent = WebhookMessage<(typeof CUSTOMER_EVENTS)[keyof typeof CUSTOMER_EVENTS], CustomerEventData>;
183
- /** 本文が顧客のイベントか(署名の検証の後に使う) */
184
- export declare function isCustomerEvent(body: unknown): body is CustomerEvent;