@tunasand/sdk 0.0.0-stage → 0.6.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.
- package/CHANGELOG.md +106 -0
- package/README.md +506 -2
- package/dist/analytics.d.ts +1 -0
- package/dist/analytics.js +43 -0
- package/dist/app.d.ts +1 -0
- package/dist/app.js +825 -0
- package/dist/apps-9u4XMi7E.js +114 -0
- package/dist/body.d.ts +1 -0
- package/dist/body.js +455 -0
- package/dist/bridge-DYAYGV7t.js +74 -0
- package/dist/bridge.d.ts +1 -0
- package/dist/bridge.js +189 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +283 -0
- package/dist/client-Derrexwr.js +159 -0
- package/dist/customers-C_vJY2_v.js +84 -0
- package/dist/customers.d.ts +1 -0
- package/dist/customers.js +185 -0
- package/dist/declared-C_GvPiGF.js +397 -0
- package/dist/delivery.d.ts +1 -0
- package/dist/delivery.js +348 -0
- package/dist/dev.d.ts +1 -0
- package/dist/dev.js +93 -0
- package/dist/embed-R-OvDYAw.js +90 -0
- package/dist/errorLabels-BcyRbv_i.js +1510 -0
- package/dist/i18n.d.ts +1 -0
- package/dist/i18n.js +4 -0
- package/dist/integrations.d.ts +1 -0
- package/dist/integrations.js +62 -0
- package/dist/ja-C1HEWWTQ.js +241 -0
- package/dist/ja-C6lX0CeJ.js +213 -0
- package/dist/model-pmXzGX12.js +152 -0
- package/dist/model.d.ts +1 -0
- package/dist/model.js +345 -0
- package/dist/page-E_cYgZx-.js +138 -0
- package/dist/preview.d.ts +1 -0
- package/dist/preview.js +1 -0
- package/dist/profile-D6t1QMQh.js +223 -0
- package/dist/schema-BPHL7Qr-.js +115 -0
- package/dist/schema-UQJWRyfJ.js +995 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +1 -0
- package/dist/src-sazhzYui.js +71 -0
- package/dist/types/access/src/handoff.d.ts +52 -0
- package/dist/types/access/src/index.d.ts +5 -0
- package/dist/types/access/src/jws.d.ts +5 -0
- package/dist/types/access/src/jwt.d.ts +35 -0
- package/dist/types/access/src/oidc.d.ts +50 -0
- package/dist/types/access/src/signed.d.ts +15 -0
- package/dist/types/analytics/src/day.d.ts +2 -0
- package/dist/types/analytics/src/index.d.ts +5 -0
- package/dist/types/analytics/src/schedule.d.ts +2 -0
- package/dist/types/analytics/src/shared.d.ts +21 -0
- package/dist/types/analytics/src/source.d.ts +19 -0
- package/dist/types/analytics/src/store.d.ts +24 -0
- package/dist/types/analytics/src/view.d.ts +33 -0
- package/dist/types/body/src/components.d.ts +25 -0
- package/dist/types/body/src/declared.d.ts +34 -0
- package/dist/types/body/src/derive.d.ts +13 -0
- package/dist/types/body/src/description.d.ts +8 -0
- package/dist/types/body/src/embed.d.ts +16 -0
- package/dist/types/body/src/href.d.ts +4 -0
- package/dist/types/body/src/html.d.ts +30 -0
- package/dist/types/body/src/index.d.ts +19 -0
- package/dist/types/body/src/inline.d.ts +20 -0
- package/dist/types/body/src/labels/en.d.ts +90 -0
- package/dist/types/body/src/labels/ja.d.ts +153 -0
- package/dist/types/body/src/library.d.ts +113 -0
- package/dist/types/body/src/markdown.d.ts +14 -0
- package/dist/types/body/src/normalize.d.ts +5 -0
- package/dist/types/body/src/problems.d.ts +103 -0
- package/dist/types/body/src/profile.d.ts +80 -0
- package/dist/types/body/src/render.d.ts +29 -0
- package/dist/types/body/src/schema.d.ts +6 -0
- package/dist/types/body/src/standard.d.ts +20 -0
- package/dist/types/body/src/types.d.ts +140 -0
- package/dist/types/cms-contract/src/apiKeys.d.ts +41 -0
- package/dist/types/cms-contract/src/app.d.ts +35 -0
- package/dist/types/cms-contract/src/appDependencies.d.ts +265 -0
- package/dist/types/cms-contract/src/appProblems.d.ts +22 -0
- package/dist/types/cms-contract/src/apps.d.ts +195 -0
- package/dist/types/cms-contract/src/assets.d.ts +12 -0
- package/dist/types/cms-contract/src/authorize.d.ts +146 -0
- package/dist/types/cms-contract/src/bridge.d.ts +318 -0
- package/dist/types/cms-contract/src/consents.d.ts +97 -0
- package/dist/types/cms-contract/src/customerLabels.d.ts +33 -0
- package/dist/types/cms-contract/src/customers.d.ts +266 -0
- package/dist/types/cms-contract/src/embeds.d.ts +165 -0
- package/dist/types/cms-contract/src/errorLabels.d.ts +269 -0
- package/dist/types/cms-contract/src/errorLabelsEn.d.ts +228 -0
- package/dist/types/cms-contract/src/errors.d.ts +105 -0
- package/dist/types/cms-contract/src/failureStatus.d.ts +124 -0
- package/dist/types/cms-contract/src/functionLabels.d.ts +5 -0
- package/dist/types/cms-contract/src/functions.d.ts +144 -0
- package/dist/types/cms-contract/src/identifiers.d.ts +117 -0
- package/dist/types/cms-contract/src/import.d.ts +277 -0
- package/dist/types/cms-contract/src/issueLabels.d.ts +435 -0
- package/dist/types/cms-contract/src/issueLabelsEn.d.ts +217 -0
- package/dist/types/cms-contract/src/migration.d.ts +103 -0
- package/dist/types/cms-contract/src/paths.d.ts +23 -0
- package/dist/types/cms-contract/src/permissionLabels.d.ts +8 -0
- package/dist/types/cms-contract/src/permissions.d.ts +77 -0
- package/dist/types/cms-contract/src/problems.d.ts +34 -0
- package/dist/types/cms-contract/src/roles.d.ts +57 -0
- package/dist/types/cms-contract/src/settingProblems.d.ts +13 -0
- package/dist/types/cms-contract/src/settings.d.ts +19 -0
- package/dist/types/cms-contract/src/siteArtifact.d.ts +45 -0
- package/dist/types/cms-contract/src/siteDeclaration.d.ts +70 -0
- package/dist/types/cms-contract/src/transfer.d.ts +57 -0
- package/dist/types/cms-contract/src/views.d.ts +21 -0
- package/dist/types/cms-contract/src/webhookLabels.d.ts +7 -0
- package/dist/types/cms-contract/src/webhooks.d.ts +139 -0
- package/dist/types/i18n/src/index.d.ts +50 -0
- package/dist/types/i18n/src/problems.d.ts +21 -0
- package/dist/types/model/src/asset.d.ts +111 -0
- package/dist/types/model/src/audience.d.ts +38 -0
- package/dist/types/model/src/brand.d.ts +25 -0
- package/dist/types/model/src/capabilities.d.ts +28 -0
- package/dist/types/model/src/changes.d.ts +34 -0
- package/dist/types/model/src/check.d.ts +15 -0
- package/dist/types/model/src/contact.d.ts +22 -0
- package/dist/types/model/src/image.d.ts +38 -0
- package/dist/types/model/src/index.d.ts +26 -0
- package/dist/types/model/src/input.d.ts +26 -0
- package/dist/types/model/src/integrity.d.ts +79 -0
- package/dist/types/model/src/json.d.ts +2 -0
- package/dist/types/model/src/labels/en.d.ts +169 -0
- package/dist/types/model/src/labels/ja.d.ts +198 -0
- package/dist/types/model/src/legacy.d.ts +2 -0
- package/dist/types/model/src/media.d.ts +5 -0
- package/dist/types/model/src/mediaUrl.d.ts +67 -0
- package/dist/types/model/src/model.d.ts +415 -0
- package/dist/types/model/src/page.d.ts +52 -0
- package/dist/types/model/src/problems.d.ts +184 -0
- package/dist/types/model/src/refs.d.ts +27 -0
- package/dist/types/model/src/rules.d.ts +15 -0
- package/dist/types/model/src/schema.d.ts +58 -0
- package/dist/types/model/src/screens.d.ts +76 -0
- package/dist/types/model/src/selfOps.d.ts +30 -0
- package/dist/types/model/src/time.d.ts +25 -0
- package/dist/types/model/src/typesSource.d.ts +8 -0
- package/dist/types/model/src/values.d.ts +24 -0
- package/dist/types/platform/src/defaultModel.d.ts +8 -0
- package/dist/types/sdk/src/analytics.d.ts +2 -0
- package/dist/types/sdk/src/app.d.ts +20 -0
- package/dist/types/sdk/src/body.d.ts +2 -0
- package/dist/types/sdk/src/bridge.d.ts +92 -0
- package/dist/types/sdk/src/cli.d.ts +2 -0
- package/dist/types/sdk/src/customers.d.ts +190 -0
- package/dist/types/sdk/src/delivery/cache.d.ts +18 -0
- package/dist/types/sdk/src/delivery/changes.d.ts +28 -0
- package/dist/types/sdk/src/delivery/client.d.ts +90 -0
- package/dist/types/sdk/src/delivery/fields.d.ts +48 -0
- package/dist/types/sdk/src/delivery/index.d.ts +9 -0
- package/dist/types/sdk/src/delivery/media.d.ts +14 -0
- package/dist/types/sdk/src/delivery/query.d.ts +85 -0
- package/dist/types/sdk/src/delivery/schema.d.ts +19 -0
- package/dist/types/sdk/src/delivery/values.d.ts +82 -0
- package/dist/types/sdk/src/delivery.d.ts +3 -0
- package/dist/types/sdk/src/dev.d.ts +29 -0
- package/dist/types/sdk/src/i18n.d.ts +12 -0
- package/dist/types/sdk/src/integrations.d.ts +33 -0
- package/dist/types/sdk/src/model.d.ts +5 -0
- package/dist/types/sdk/src/preview.d.ts +1 -0
- package/dist/types/sdk/src/schema.d.ts +21 -0
- package/dist/types/sdk/src/site.d.ts +43 -0
- package/dist/typesSource-bO0jFw1I.js +88 -0
- package/package.json +86 -3
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { type SelfApiError, CUSTOMER_EVENTS, type CustomerApiGrant, type CustomerApiError, type CustomerApiResult, type CustomerEventData } from '../../cms-contract/src/customers.js';
|
|
2
|
+
import type { Issue } from '../../cms-contract/src/errors.js';
|
|
3
|
+
import { WEBHOOK_VERSION } from '../../cms-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 '../../cms-contract/src/customers.js';
|
|
6
|
+
export type { Issue, IssueSeverity } from '../../cms-contract/src/errors.js';
|
|
7
|
+
export type { SelfApiError, CustomerApiGrant, CustomerApiError, CustomerApiResult, CustomerCandidateResult, CustomerEventData, CustomerStatus } from '../../cms-contract/src/customers.js';
|
|
8
|
+
export { grantedKeysOf } from '../../model/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("./customers.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("./customers.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("./customers.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("./customers.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 の本文(json の形式、type はイベントの名前、created_at はイベントの日時) */
|
|
182
|
+
export type CustomerEvent = Readonly<{
|
|
183
|
+
version: typeof WEBHOOK_VERSION;
|
|
184
|
+
id: string;
|
|
185
|
+
type: (typeof CUSTOMER_EVENTS)[keyof typeof CUSTOMER_EVENTS];
|
|
186
|
+
created_at: string;
|
|
187
|
+
data: CustomerEventData;
|
|
188
|
+
}>;
|
|
189
|
+
/** 本文が顧客のイベントか(署名の検証の後に使う) */
|
|
190
|
+
export declare function isCustomerEvent(body: unknown): body is CustomerEvent;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Delivery } from './client.js';
|
|
2
|
+
/** Cache API と同じ形の保持の場所(key は URL) */
|
|
3
|
+
export type DeliveryCache = Readonly<{
|
|
4
|
+
match(key: string): Promise<Response | null | undefined>;
|
|
5
|
+
put(key: string, response: Response): Promise<void>;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* 保持つきの配信 API の接続(createDeliveryClient に渡す)
|
|
9
|
+
* - origin: キーの前半(プロジェクトごとに別の値、例: https://<プロジェクト>.tunasand.app)。同じ保持の場所を複数のプロジェクトで使っても混ざらない
|
|
10
|
+
* - freshSec: 呼び出さずに返す秒数(既定は30、CMS のキャッシュの区切りと同じ)
|
|
11
|
+
*/
|
|
12
|
+
export declare function cachedDelivery(delivery: Delivery, { cache, origin, freshSec }: {
|
|
13
|
+
cache: DeliveryCache;
|
|
14
|
+
origin: string;
|
|
15
|
+
freshSec?: number;
|
|
16
|
+
}): Delivery;
|
|
17
|
+
/** メモリの保持の場所(Workers 以外の実行環境向け、maxEntries を超えたら最も古く使用したものから破棄) */
|
|
18
|
+
export declare function memoryDeliveryCache(maxEntries?: number): DeliveryCache;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { DeliveryClient } from './client.js';
|
|
2
|
+
/** 変更の一覧の1件(at は配信 API に現れた日時、`ISO 8601` の UTC、previous_slug はスラッグを変えた記録だけの変更の前のスラッグ) */
|
|
3
|
+
export type Change = Readonly<{
|
|
4
|
+
collection: Readonly<{
|
|
5
|
+
id: string;
|
|
6
|
+
slug: string | null;
|
|
7
|
+
}>;
|
|
8
|
+
id: string;
|
|
9
|
+
slug: string;
|
|
10
|
+
previous_slug?: string;
|
|
11
|
+
change: 'upsert' | 'delete';
|
|
12
|
+
event: 'created' | 'updated' | 'deleted' | 'published' | 'unpublished' | 'snapshot';
|
|
13
|
+
at: string;
|
|
14
|
+
}>;
|
|
15
|
+
/** 変更の一覧の1ページ */
|
|
16
|
+
export type ChangesPage = Readonly<{
|
|
17
|
+
changes: readonly Change[];
|
|
18
|
+
next: string;
|
|
19
|
+
more: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* since から more がなくなるまで読み、ページごとに apply を呼ぶ(戻り値は次回の since)
|
|
23
|
+
* - apply が成功してから次のページへ進む(失敗したら例外で止まり、保存済みの since から再開できる)
|
|
24
|
+
* - 410(保存の期間を過ぎた cursor): DeliveryError、since を null にして全件から取り直す
|
|
25
|
+
*/
|
|
26
|
+
export declare function readChanges(client: Pick<DeliveryClient, 'changes'>, since: string | null, apply: (page: ChangesPage) => Promise<void> | void, { limit }?: {
|
|
27
|
+
limit?: number;
|
|
28
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Collection } from '../../../model/src/index.js';
|
|
2
|
+
import { type ListQuery, type Page } from './query.js';
|
|
3
|
+
import type { ChangesPage } from './changes.js';
|
|
4
|
+
/** 配信 API のパスの前半 */
|
|
5
|
+
export declare const DELIVERY_PATH = "/content/v1";
|
|
6
|
+
/** 配信 API への接続(path は /content/v1 から始まるパスとクエリ) */
|
|
7
|
+
export type Delivery = (path: string, init?: RequestInit) => Promise<Response>;
|
|
8
|
+
/** 一式の経路ごとの結果(body は経路の応答の JSON) */
|
|
9
|
+
export type BundleResult = Readonly<{
|
|
10
|
+
status: number;
|
|
11
|
+
body: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* 一式の取得の結果
|
|
15
|
+
* - notModified: ETag が一致、etag: 応答の ETag、stale: 失敗のため最後に成功した値
|
|
16
|
+
* - partial: 一部の経路が 5xx の一式 x-partial(最後に成功した値や描画の結果として保存しない)
|
|
17
|
+
*/
|
|
18
|
+
export type Prefetched = Readonly<{
|
|
19
|
+
notModified: boolean;
|
|
20
|
+
etag: string | null;
|
|
21
|
+
stale: boolean;
|
|
22
|
+
partial: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
/** エラーの本文の検査の結果の1件(CMS の API の Issue と同じ形。このクライアントは契約のパッケージに依存しない) */
|
|
25
|
+
type Issue = Readonly<{
|
|
26
|
+
path: string;
|
|
27
|
+
code: string;
|
|
28
|
+
message: string;
|
|
29
|
+
params?: Readonly<Record<string, string | number>>;
|
|
30
|
+
severity: 'error' | 'warning';
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* 配信 API の取得の失敗
|
|
34
|
+
* - call: 失敗した経路、status: 応答のステータス
|
|
35
|
+
* - code・params・issues・requestId: エラーの本文({ code, message, params?, issues?, requestId })の値
|
|
36
|
+
* 本文が JSON でなければ undefined
|
|
37
|
+
*/
|
|
38
|
+
export declare class DeliveryError extends Error {
|
|
39
|
+
readonly call: string;
|
|
40
|
+
readonly status: number;
|
|
41
|
+
readonly code: string | undefined;
|
|
42
|
+
readonly params: Readonly<Record<string, unknown>> | undefined;
|
|
43
|
+
readonly issues: readonly Issue[] | undefined;
|
|
44
|
+
readonly requestId: string | undefined;
|
|
45
|
+
constructor(call: string, status: number, body: string);
|
|
46
|
+
}
|
|
47
|
+
/** 配信 API の中のパスとクエリ(一式の path と結果のキー) */
|
|
48
|
+
export declare const subPath: (path: string, params?: Readonly<Record<string, string>>) => string;
|
|
49
|
+
/**
|
|
50
|
+
* 配信 API の読み取り
|
|
51
|
+
* - drafts: 下書き・予約なども含める(プレビュー用、署名は接続の側で付与)
|
|
52
|
+
* - at: 公開の基準の日時(なしは今)
|
|
53
|
+
*/
|
|
54
|
+
export declare function createDeliveryClient(delivery: Delivery, { drafts, at }?: {
|
|
55
|
+
drafts?: boolean;
|
|
56
|
+
at?: string;
|
|
57
|
+
}): {
|
|
58
|
+
find: <T>(path: string, params?: Readonly<Record<string, string>>) => Promise<T | undefined>;
|
|
59
|
+
get: <T>(path: string, params?: Readonly<Record<string, string>>) => Promise<T>;
|
|
60
|
+
page: <I = Readonly<Record<string, unknown>>, T extends Collection = Readonly<{
|
|
61
|
+
id: string;
|
|
62
|
+
slug: string;
|
|
63
|
+
label: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
format?: import("../../../model/src/model.js").ContentFormat;
|
|
66
|
+
publishing?: import("../../../model/src/model.js").Publishing;
|
|
67
|
+
fields: readonly import("../model.js").FieldDef[];
|
|
68
|
+
pages?: readonly import("../model.js").PageDef[];
|
|
69
|
+
counts?: readonly import("../../../model/src/model.js").CountDef[];
|
|
70
|
+
og?: string;
|
|
71
|
+
slugMode?: import("../../../model/src/model.js").SlugMode;
|
|
72
|
+
roles?: import("../../../model/src/model.js").FieldRoles;
|
|
73
|
+
grant?: string;
|
|
74
|
+
private?: boolean;
|
|
75
|
+
unique?: readonly import("../../../model/src/integrity.js").UniqueDef[];
|
|
76
|
+
selfOps?: readonly import("../../../model/src/model.js").SelfOp[];
|
|
77
|
+
retentionDays?: number;
|
|
78
|
+
}>>(path: string, query: ListQuery<T> & Readonly<{
|
|
79
|
+
limit: number;
|
|
80
|
+
}>) => Promise<Page<I>>;
|
|
81
|
+
prefetch: (paths: readonly string[], { ifNoneMatch }?: {
|
|
82
|
+
ifNoneMatch?: string;
|
|
83
|
+
}) => Promise<Prefetched>;
|
|
84
|
+
changes: (since: string | null, { limit }?: {
|
|
85
|
+
limit?: number;
|
|
86
|
+
}) => Promise<ChangesPage>;
|
|
87
|
+
};
|
|
88
|
+
/** 配信 API の読み取り(createDeliveryClient の戻り値) */
|
|
89
|
+
export type DeliveryClient = ReturnType<typeof createDeliveryClient>;
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ContentModel, Collection, FieldDef } from '../../../model/src/index.js';
|
|
2
|
+
import type { GrantedField, FieldsOf, FieldValue, ItemMeta, ItemOf, UndeliveredField } from './values.js';
|
|
3
|
+
type PublicField<T extends Collection> = Exclude<FieldsOf<T>, UndeliveredField>;
|
|
4
|
+
type KeyOf<T extends Collection> = PublicField<T>['key'];
|
|
5
|
+
type RefField<T extends Collection> = Extract<PublicField<T>, {
|
|
6
|
+
type: 'reference';
|
|
7
|
+
}>;
|
|
8
|
+
/** fields に書ける1つの指定(項目の key・id・slug・_meta・*、参照の項目は `key.sub` か `key.*`) */
|
|
9
|
+
export type FieldPath<T extends Collection = Collection> = 'id' | 'slug' | '_meta' | '*' | KeyOf<T> | `${RefField<T>['key']}.${string}`;
|
|
10
|
+
/** 選択に含む最上位の key(`key.sub` は key) */
|
|
11
|
+
type Head<P> = P extends `${infer K}.${string}` ? K : P;
|
|
12
|
+
/** 参照の項目 K の展開の指定(`K.sub` の sub) */
|
|
13
|
+
type SubOf<P, K extends string> = P extends `${K}.${infer S}` ? S : never;
|
|
14
|
+
/** 参照先のコレクション(M がなければ汎用のコレクション) */
|
|
15
|
+
type TargetOf<F extends FieldDef, M> = M extends ContentModel ? (F extends {
|
|
16
|
+
to: infer To;
|
|
17
|
+
} ? Extract<M['collections'][number], {
|
|
18
|
+
id: To;
|
|
19
|
+
}> : never) : never;
|
|
20
|
+
/** 展開した参照先の1件(id・slug と選択した項目、* はすべて) */
|
|
21
|
+
type Expanded<To, S> = [To] extends [never] ? Readonly<{
|
|
22
|
+
id: string;
|
|
23
|
+
slug: string;
|
|
24
|
+
} & Record<string, unknown>> : To extends Collection ? Readonly<{
|
|
25
|
+
id: string;
|
|
26
|
+
slug: string;
|
|
27
|
+
} & ('*' extends S ? Omit<ItemOf<To>, '_meta' | 'id' | 'slug'> : Pick<ItemOf<To>, Extract<S, keyof ItemOf<To>>>)> : never;
|
|
28
|
+
/** 選択した1つの項目の値(展開する参照は参照先の1件、単数は null を含み、複数は配列) */
|
|
29
|
+
type SelectedValue<F extends FieldDef, P, M> = [SubOf<P, F['key']>] extends [never] ? FieldValue<F> : F extends {
|
|
30
|
+
multiple: true;
|
|
31
|
+
} ? readonly Expanded<TargetOf<F, M>, SubOf<P, F['key']>>[] : Expanded<TargetOf<F, M>, SubOf<P, F['key']>> | null;
|
|
32
|
+
/**
|
|
33
|
+
* fields の選択から導く1件の型
|
|
34
|
+
* - T: コレクションの宣言、P: fields の配列の要素(`as const` の配列の `[number]`)、M: 参照先のコレクションを引くコンテンツスキーマ
|
|
35
|
+
*/
|
|
36
|
+
export type Selected<T extends Collection, P extends string, M = never> = Readonly<{
|
|
37
|
+
id: string;
|
|
38
|
+
slug: string;
|
|
39
|
+
} & ('_meta' extends P ? {
|
|
40
|
+
_meta: ItemMeta;
|
|
41
|
+
} : '*' extends P ? {
|
|
42
|
+
_meta: ItemMeta;
|
|
43
|
+
} : unknown) & {
|
|
44
|
+
[F in Exclude<PublicField<T>, GrantedField> as F['key'] extends Head<P> ? F['key'] : '*' extends P ? F['key'] : never]: SelectedValue<F, P, M>;
|
|
45
|
+
} & {
|
|
46
|
+
[F in Extract<PublicField<T>, GrantedField> as F['key'] extends Head<P> ? F['key'] : '*' extends P ? F['key'] : never]?: SelectedValue<F, P, M>;
|
|
47
|
+
}>;
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { cachedDelivery, memoryDeliveryCache, type DeliveryCache } from './cache.js';
|
|
2
|
+
export { readChanges, type Change, type ChangesPage } from './changes.js';
|
|
3
|
+
export { createDeliveryClient, DELIVERY_PATH, DeliveryError, subPath, type BundleResult, type Delivery, type DeliveryClient, type Prefetched } from './client.js';
|
|
4
|
+
export { deliveredImageUrl, mediaOf, type ImageUrl, type MediaOf } from './media.js';
|
|
5
|
+
export { imageParamsOf, parseMediaPath, signMediaUrl, withImageParams, type DeliveredAsset, type ImageParams, type MediaPath } from '../../../model/src/index.js';
|
|
6
|
+
export type { FieldPath, Selected } from './fields.js';
|
|
7
|
+
export { listParams, type ListFilter, type ListQuery, type Page } from './query.js';
|
|
8
|
+
export { createDeliveryClock, fieldOf, limitOf, optionLabels, pagePath, type DeliveryClock } from './schema.js';
|
|
9
|
+
export type { FieldValue, Item, ItemMeta, ItemOf, RecordRef } from './values.js';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CropRect, type Media } from '../../../model/src/index.js';
|
|
2
|
+
/** 配信する画像の URL(元の URL と、元画像の画素での切り抜きの範囲から、配信の側で変換する URL) */
|
|
3
|
+
export type ImageUrl = (src: string, rect?: CropRect) => string;
|
|
4
|
+
/** 配信 URL の画像の切り抜き(クエリ rect、範囲なしは元の URL) */
|
|
5
|
+
export declare const deliveredImageUrl: ImageUrl;
|
|
6
|
+
/** 実体から表示の素材(見つからない実体はなし) */
|
|
7
|
+
export type MediaOf = (asset: unknown) => Media | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* 実体から表示の素材への変換(動画は代わりの画像も)
|
|
10
|
+
* - URL: 実体の url、なしは base/<ID>(base は実体の URL の前半)
|
|
11
|
+
* - 画像の変換: imageUrl で画像(動画の実体は除く)を変換の URL に、url のある実体の既定は deliveredImageUrl、切り抜きは切り抜いた画像の URL・寸法・見せたい点
|
|
12
|
+
* - url も imageUrl もない: 元の画像のまま(手元の開発)
|
|
13
|
+
*/
|
|
14
|
+
export declare function mediaOf(base: string, imageUrl?: ImageUrl): MediaOf;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Collection, FieldDef } from '../../../model/src/index.js';
|
|
2
|
+
import type { FieldPath } from './fields.js';
|
|
3
|
+
import type { GrantedField, FieldsOf, Item, SingleValue, UndeliveredField } from './values.js';
|
|
4
|
+
/** 範囲の指定(両端を含む) */
|
|
5
|
+
type Range<V> = Readonly<{
|
|
6
|
+
gte?: V;
|
|
7
|
+
lte?: V;
|
|
8
|
+
}>;
|
|
9
|
+
type Scalar<F extends FieldDef> = F extends {
|
|
10
|
+
type: 'reference';
|
|
11
|
+
} ? string : NonNullable<SingleValue<F>>;
|
|
12
|
+
/** 演算ごとの値(in は値の配列、exists は値あり・なしの真偽) */
|
|
13
|
+
type Ops<V, O extends FilterOp> = Readonly<{
|
|
14
|
+
[K in O]?: K extends 'in' ? readonly V[] : K extends 'exists' ? boolean : V;
|
|
15
|
+
}>;
|
|
16
|
+
/** 絞り込みの演算(サーバーが実装する範囲) */
|
|
17
|
+
type FilterOp = 'eq' | 'ne' | 'in' | 'gte' | 'lte' | 'begins' | 'exists';
|
|
18
|
+
/** 項目の種類ごとの絞り込みの値(値だけの指定は一致) */
|
|
19
|
+
type FilterValue<F extends FieldDef> = F extends UndeliveredField | GrantedField ? never : F extends {
|
|
20
|
+
type: 'select' | 'reference';
|
|
21
|
+
multiple: true;
|
|
22
|
+
} ? Scalar<F> | Ops<Scalar<F>, 'eq' | 'in'> : F extends {
|
|
23
|
+
multiple: true;
|
|
24
|
+
} ? never : F extends {
|
|
25
|
+
type: 'text';
|
|
26
|
+
} ? string | Ops<string, 'eq' | 'ne' | 'in' | 'begins' | 'exists'> : F extends {
|
|
27
|
+
type: 'select' | 'reference';
|
|
28
|
+
} ? Scalar<F> | Ops<Scalar<F>, 'eq' | 'ne' | 'in' | 'exists'> : F extends {
|
|
29
|
+
type: 'boolean';
|
|
30
|
+
} ? boolean : F extends {
|
|
31
|
+
type: 'number' | 'date';
|
|
32
|
+
} ? Scalar<F> | Ops<Scalar<F>, 'eq' | 'ne' | 'gte' | 'lte' | 'exists'> : F extends {
|
|
33
|
+
type: 'datetime';
|
|
34
|
+
} ? Ops<string, 'gte' | 'lte' | 'exists'> : never;
|
|
35
|
+
/** 並べ替えできる項目の key(単数の文字・数値・日付・日時・選択肢・チェックボックス) */
|
|
36
|
+
type SortableKey<T extends Collection> = FieldsOf<T> extends infer F ? (F extends UndeliveredField | GrantedField | {
|
|
37
|
+
multiple: true;
|
|
38
|
+
} ? never : F extends {
|
|
39
|
+
type: 'text' | 'number' | 'date' | 'datetime' | 'select' | 'boolean';
|
|
40
|
+
key: infer K extends string;
|
|
41
|
+
} ? K : never) : never;
|
|
42
|
+
/** 並べ替えの key(項目・公開日時・作成日時・更新日時・id) */
|
|
43
|
+
type OrderKey<T extends Collection> = SortableKey<T> | 'published_at' | 'created_at' | 'updated_at' | 'id';
|
|
44
|
+
/** 絞り込みの指定(項目の key ごと、公開日時・作成日時・更新日時は範囲) */
|
|
45
|
+
export type ListFilter<T extends Collection = Collection> = Readonly<{
|
|
46
|
+
[F in FieldsOf<T> as [FilterValue<F>] extends [never] ? never : F['key']]?: FilterValue<F>;
|
|
47
|
+
} & {
|
|
48
|
+
published_at?: Range<string>;
|
|
49
|
+
created_at?: Range<string>;
|
|
50
|
+
updated_at?: Range<string>;
|
|
51
|
+
}>;
|
|
52
|
+
/**
|
|
53
|
+
* コレクションの一覧の指定
|
|
54
|
+
* - limit: 1ページの件数(サーバーの上限は100)
|
|
55
|
+
* - cursor: 前のページの next
|
|
56
|
+
* - order: 並べ替えの key の配列(`-` の接頭辞で降順、最後に id を自動で追加)
|
|
57
|
+
* - ids: レコードの id のいずれか(100個まで、順は order の順)
|
|
58
|
+
* - fields: 返す項目と展開する参照(id は常に返す、展開は深さ1)
|
|
59
|
+
* - filter: 項目の key ごとの絞り込み(複数の値の項目は値を含むレコード、ne は値なしのレコードを含む)
|
|
60
|
+
*/
|
|
61
|
+
export type ListQuery<T extends Collection = Collection> = Readonly<{
|
|
62
|
+
limit?: number;
|
|
63
|
+
cursor?: string | null;
|
|
64
|
+
order?: readonly (OrderKey<T> | `-${OrderKey<T>}`)[];
|
|
65
|
+
ids?: readonly string[];
|
|
66
|
+
fields?: readonly FieldPath<T>[];
|
|
67
|
+
filter?: ListFilter<T>;
|
|
68
|
+
}>;
|
|
69
|
+
/** ページ送りの応答(next は次のページの cursor、最後のページは null) */
|
|
70
|
+
export type Page<I = Item> = Readonly<{
|
|
71
|
+
items: readonly I[];
|
|
72
|
+
next: string | null;
|
|
73
|
+
}>;
|
|
74
|
+
/** どのコレクションの一覧の指定も受け取る形(型の検査は ListQuery の側) */
|
|
75
|
+
type QueryShape = Readonly<{
|
|
76
|
+
limit?: number;
|
|
77
|
+
cursor?: string | null;
|
|
78
|
+
order?: readonly string[];
|
|
79
|
+
ids?: readonly string[];
|
|
80
|
+
fields?: readonly string[];
|
|
81
|
+
filter?: Readonly<Record<string, unknown>>;
|
|
82
|
+
}>;
|
|
83
|
+
/** 一覧の指定をクエリの組に(find・get・subPath の params、一式の path に使用、1件の取得の fields にも使用) */
|
|
84
|
+
export declare function listParams(query: QueryShape): Record<string, string>;
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Clock, type ContentModel, type DateString, type FieldDef, type PageRecord } from '../../../model/src/index.js';
|
|
2
|
+
/** 選択肢の項目から表示名の表(値 → 表示名、key はまとまりの中なら `links.kind` の形、選択肢の項目でなければ空) */
|
|
3
|
+
export declare const optionLabels: <K extends string = string>(schema: ContentModel, collection: string, key: string) => Readonly<Record<K, string>>;
|
|
4
|
+
/** コレクションの項目(なければ例外: 導入先の設定の誤り) */
|
|
5
|
+
export declare function fieldOf(schema: ContentModel, collection: string, key: string): FieldDef;
|
|
6
|
+
/** 項目の宣言の上限(宣言がなければ例外) */
|
|
7
|
+
export declare function limitOf(field: FieldDef, name: 'maxItems' | 'maxLength'): number;
|
|
8
|
+
/** ページのパス(コレクションの宣言 pages から、ページのないコレクションは例外) */
|
|
9
|
+
export declare function pagePath(schema: ContentModel, collection: string, record: PageRecord): string;
|
|
10
|
+
/** プロジェクトのタイムゾーンでの日時の変換(表示用の日付と日時の組 dated を含む) */
|
|
11
|
+
export type DeliveryClock = Clock & Readonly<{
|
|
12
|
+
/** 日時の項目から、表示用のタイムゾーンの日付と `ISO 8601` の日時(日時の形でない値はそのまま) */
|
|
13
|
+
dated: (value: string) => Readonly<{
|
|
14
|
+
date: DateString;
|
|
15
|
+
at: string;
|
|
16
|
+
}>;
|
|
17
|
+
}>;
|
|
18
|
+
/** 日時の変換を作成(timeZone はプロジェクトの設定にある IANA の名前) */
|
|
19
|
+
export declare function createDeliveryClock(timeZone: string): DeliveryClock;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Body } from '../../../body/src/index.js';
|
|
2
|
+
import type { Collection, DateString, DeliveredAsset, FieldDef } from '../../../model/src/index.js';
|
|
3
|
+
/** 配信 API の1件の値(id・slug・項目の key・メタ情報 _meta) */
|
|
4
|
+
export type Item = Readonly<Record<string, unknown>>;
|
|
5
|
+
/** 参照の値(参照先のレコードの id とスラッグ、突き合わせは id で) */
|
|
6
|
+
export type RecordRef = Readonly<{
|
|
7
|
+
id: string;
|
|
8
|
+
slug: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** 項目の1つ分の値(複数の値を持つ項目は FieldValue が配列に、query.ts の絞り込みの値と共通) */
|
|
11
|
+
export type SingleValue<F extends FieldDef> = F extends {
|
|
12
|
+
type: 'text' | 'long_text' | 'email' | 'phone' | 'url';
|
|
13
|
+
} ? string : F extends {
|
|
14
|
+
type: 'number';
|
|
15
|
+
} ? number : F extends {
|
|
16
|
+
type: 'boolean';
|
|
17
|
+
} ? boolean : F extends {
|
|
18
|
+
type: 'date';
|
|
19
|
+
} ? DateString : F extends {
|
|
20
|
+
type: 'datetime';
|
|
21
|
+
} ? string : F extends {
|
|
22
|
+
type: 'select';
|
|
23
|
+
options: readonly (infer O extends {
|
|
24
|
+
value: string;
|
|
25
|
+
})[];
|
|
26
|
+
} ? O['value'] : F extends {
|
|
27
|
+
type: 'reference';
|
|
28
|
+
} ? RecordRef : F extends {
|
|
29
|
+
type: 'media';
|
|
30
|
+
} ? DeliveredAsset | null : F extends {
|
|
31
|
+
type: 'rich_text';
|
|
32
|
+
} ? Body<DeliveredAsset | null> : F extends {
|
|
33
|
+
type: 'group';
|
|
34
|
+
fields: readonly (infer G extends FieldDef)[];
|
|
35
|
+
} ? GroupValue<G> : unknown;
|
|
36
|
+
/** まとまりの値(中の項目の key ごと) */
|
|
37
|
+
type GroupValue<G extends FieldDef> = {
|
|
38
|
+
readonly [K in G as K['key']]: FieldValue<K>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* 項目の値(種類ごと: 文字は string、日付は YYYY-MM-DD、日時は `ISO 8601` の UTC、参照は参照先の { id, slug }、メディアは実体、本文は標準のブロック)
|
|
42
|
+
* - multiple の項目: 値の配列
|
|
43
|
+
* - 値なし: null
|
|
44
|
+
*/
|
|
45
|
+
export type FieldValue<F extends FieldDef> = (F extends {
|
|
46
|
+
multiple: true;
|
|
47
|
+
} ? readonly SingleValue<F>[] : SingleValue<F>) | null;
|
|
48
|
+
/** コレクションの項目 */
|
|
49
|
+
export type FieldsOf<T extends Collection> = T['fields'][number];
|
|
50
|
+
/** アクセス権の項目の宣言(旧い印 customersOnly も) */
|
|
51
|
+
export type GrantedField = {
|
|
52
|
+
audience: 'granted';
|
|
53
|
+
} | {
|
|
54
|
+
customersOnly: true;
|
|
55
|
+
};
|
|
56
|
+
/** 配信しない項目の宣言(本人とスタッフ、旧い印 private も) */
|
|
57
|
+
export type UndeliveredField = {
|
|
58
|
+
audience: 'self' | 'staff';
|
|
59
|
+
} | {
|
|
60
|
+
private: true;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* 1件のメタ情報(作成・更新の日時、公開日時は公開の管理があるコレクションだけで未公開は null、日時は `ISO 8601` の UTC)
|
|
64
|
+
* - requires: 顧客の出し分けの宣言があるコレクションだけ。顧客だけの項目を見るのに要る権利の対象のレコードの id で、空は有効な権利を1つでも持つ人
|
|
65
|
+
*/
|
|
66
|
+
export type ItemMeta = Readonly<{
|
|
67
|
+
created_at: string;
|
|
68
|
+
updated_at: string;
|
|
69
|
+
published_at?: string | null;
|
|
70
|
+
requires?: readonly string[];
|
|
71
|
+
}>;
|
|
72
|
+
/** コレクションの宣言から導く1件の値(id・slug・項目の key ごとの値・メタ情報 _meta) */
|
|
73
|
+
export type ItemOf<T extends Collection> = Readonly<{
|
|
74
|
+
id: string;
|
|
75
|
+
slug: string;
|
|
76
|
+
_meta: ItemMeta;
|
|
77
|
+
} & {
|
|
78
|
+
[F in Exclude<FieldsOf<T>, GrantedField> as F['key']]: FieldValue<F>;
|
|
79
|
+
} & {
|
|
80
|
+
[F in Extract<FieldsOf<T>, GrantedField> as F['key']]?: FieldValue<F>;
|
|
81
|
+
}>;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { cachedDelivery, createDeliveryClient, createDeliveryClock, deliveredImageUrl, DELIVERY_PATH, DeliveryError, fieldOf, imageParamsOf, limitOf, listParams, mediaOf, memoryDeliveryCache, optionLabels, pagePath, parseMediaPath, readChanges, signMediaUrl, subPath, withImageParams } from './delivery/index.js';
|
|
2
|
+
export type { Issue, IssueSeverity } from '../../cms-contract/src/errors.js';
|
|
3
|
+
export type { BundleResult, Change, ChangesPage, DeliveredAsset, Delivery, DeliveryCache, DeliveryClient, DeliveryClock, FieldValue, ImageParams, ImageUrl, Item, ItemMeta, ItemOf, FieldPath, ListFilter, ListQuery, MediaOf, MediaPath, Page, Prefetched, RecordRef, Selected } from './delivery/index.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Delivery } from './delivery/index.js';
|
|
2
|
+
/** 記録の1件(記録のファイルの JSON) */
|
|
3
|
+
export type FixtureResponse = Readonly<{
|
|
4
|
+
method: string;
|
|
5
|
+
path: string;
|
|
6
|
+
status: number;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
body: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** 呼び出しの記録のファイル名(メソッド・パス・If-None-Match・本文のハッシュ) */
|
|
11
|
+
export declare const fixtureName: (method: string, path: string, ifNoneMatch?: string, body?: string) => string;
|
|
12
|
+
/** 記録の再生(port Delivery、dir は記録のディレクトリ) */
|
|
13
|
+
export declare function fixtureDelivery(dir: string | URL): Delivery;
|
|
14
|
+
/** 公開の配信 API の中継先(origin はプロジェクトの識別子までの URL、例: <公開の配信 API のオリジン>/demo) */
|
|
15
|
+
export type Upstream = Readonly<{
|
|
16
|
+
origin: string;
|
|
17
|
+
apiKey: string;
|
|
18
|
+
previewSecret?: string;
|
|
19
|
+
}>;
|
|
20
|
+
/** 公開の配信 API への中継(port Delivery、読み取りだけで書き込みの操作は405) */
|
|
21
|
+
export declare function relayDelivery({ origin, apiKey, previewSecret }: Upstream): Delivery;
|
|
22
|
+
/** 手元の配信 API のサーバー(/content/v1/… だけ、失敗は502、戻り値は origin と停止の関数) */
|
|
23
|
+
export declare function serveDelivery(delivery: Delivery, options?: Readonly<{
|
|
24
|
+
port?: number;
|
|
25
|
+
hostname?: string;
|
|
26
|
+
}>): Promise<Readonly<{
|
|
27
|
+
origin: string;
|
|
28
|
+
close: () => Promise<void>;
|
|
29
|
+
}>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { BASE_LOCALE, chooseLocale, createTranslator, formatMessage, LOCALES, problemMessage, problemOf, problemText } from '../../i18n/src/index.js';
|
|
2
|
+
export type { Catalog, Locale, MessageAt, MessageKey, Messages, ParamsArg, ParamsOf, ParamValue, Problem, Translate } from '../../i18n/src/index.js';
|
|
3
|
+
export { ERROR_MESSAGES, errorMessageOf, errorTitle } from '../../cms-contract/src/errorLabels.js';
|
|
4
|
+
export { ERROR_MESSAGES_EN } from '../../cms-contract/src/errorLabelsEn.js';
|
|
5
|
+
export { API_ISSUE_MESSAGES } from '../../cms-contract/src/issueLabels.js';
|
|
6
|
+
export { API_ISSUE_MESSAGES_EN } from '../../cms-contract/src/issueLabelsEn.js';
|
|
7
|
+
export type { ErrorCatalog } from '../../cms-contract/src/errorLabels.js';
|
|
8
|
+
export { importProblemLabel, issueLabel, labelTableProblems, PROBLEM_MESSAGES, PROBLEM_MESSAGES_EN, problemEnglish, problemLabel } from '../../cms-contract/src/problems.js';
|
|
9
|
+
export { MODEL_PROBLEM_MESSAGES } from '../../model/src/labels/ja.js';
|
|
10
|
+
export { MODEL_PROBLEM_MESSAGES_EN } from '../../model/src/labels/en.js';
|
|
11
|
+
export { BODY_PROBLEM_MESSAGES } from '../../body/src/labels/ja.js';
|
|
12
|
+
export { BODY_PROBLEM_MESSAGES_EN } from '../../body/src/labels/en.js';
|