@c-time/frelio-cli 3.0.0 → 3.2.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.
@@ -7,6 +7,7 @@
7
7
  import prompts from 'prompts';
8
8
  import fs from 'node:fs';
9
9
  import path from 'node:path';
10
+ import { randomBytes } from 'node:crypto';
10
11
  import { log, logStep, logSuccess, logError, logWarning } from '../lib/shell.js';
11
12
  import { buildWorkerNames, deriveFromAdminHost, derivePreviewUrl, } from '../lib/templates.js';
12
13
  import { buildResourceLinks } from '../lib/resource-links.js';
@@ -237,6 +238,15 @@ export async function initCommand(options) {
237
238
  logError(s.error);
238
239
  }
239
240
  logSuccess('お問い合わせワーカーのセットアップ完了(deploy は workers/contact で別途実行)');
241
+ // 予約反映のデプロイ失敗 Web Push 通知(issue #298): 同じ共有シークレットを
242
+ // GitHub Actions のリポジトリシークレットにも登録する必要がある(Actions は worker secret を読めない)。
243
+ if (contactInput.adminNotifySecret) {
244
+ log('');
245
+ log(' 🔔 予約反映の失敗通知(Web Push)を使う場合は、以下を GitHub Actions のリポジトリシークレットに登録してください:');
246
+ log(` Name : ADMIN_NOTIFY_SECRET`);
247
+ log(` Value: ${contactInput.adminNotifySecret}`);
248
+ log(' (contact worker には投入済み。値が一致していないと通知は届きません)');
249
+ }
240
250
  }
241
251
  else {
242
252
  logError(contactResult.error);
@@ -719,6 +729,9 @@ async function promptContact(config) {
719
729
  smtp,
720
730
  smtpPass: smtpPrompts.pass || undefined,
721
731
  contentRepoToken: base.contentRepoToken || undefined,
732
+ // 予約反映のデプロイ失敗を Web Push 通知するための共有シークレット(issue #298)。
733
+ // 自動生成し、同じ値を GitHub Actions のリポジトリシークレットにも登録してもらう。
734
+ adminNotifySecret: randomBytes(24).toString('base64url'),
722
735
  };
723
736
  }
724
737
  async function promptConfig(options) {
@@ -10,6 +10,7 @@ type SetDomainOptions = {
10
10
  previewUrl?: string;
11
11
  stagingDomain?: string;
12
12
  r2PublicUrl?: string;
13
+ imagePublicUrl?: string;
13
14
  downloadApiUrl?: string;
14
15
  regenStagingHash?: boolean;
15
16
  };
@@ -39,6 +39,7 @@ export async function setDomainCommand(options) {
39
39
  options.previewUrl !== undefined ||
40
40
  options.stagingDomain !== undefined ||
41
41
  options.r2PublicUrl !== undefined ||
42
+ options.imagePublicUrl !== undefined ||
42
43
  options.downloadApiUrl !== undefined;
43
44
  // フラグ検証(指定されたもののみ)
44
45
  if (options.productionUrl !== undefined) {
@@ -55,6 +56,14 @@ export async function setDomainCommand(options) {
55
56
  process.exit(1);
56
57
  }
57
58
  }
59
+ if (options.imagePublicUrl !== undefined) {
60
+ // 空文字は opt-out(独自ドメイン配信を無効化)として許容する
61
+ const c = options.imagePublicUrl === '' ? true : validateR2PublicUrl(options.imagePublicUrl);
62
+ if (c !== true) {
63
+ logError(`--image-public-url: ${c}`);
64
+ process.exit(1);
65
+ }
66
+ }
58
67
  if (options.downloadApiUrl !== undefined) {
59
68
  const c = validateProductionUrl(options.downloadApiUrl);
60
69
  if (c !== true) {
@@ -73,6 +82,8 @@ export async function setDomainCommand(options) {
73
82
  change.stagingDomain = options.stagingDomain;
74
83
  if (options.r2PublicUrl !== undefined)
75
84
  change.r2PublicUrl = options.r2PublicUrl;
85
+ if (options.imagePublicUrl !== undefined)
86
+ change.imagePublicUrl = options.imagePublicUrl;
76
87
  if (options.downloadApiUrl !== undefined)
77
88
  change.downloadApiUrl = options.downloadApiUrl;
78
89
  if (options.regenStagingHash)
@@ -88,6 +99,7 @@ export async function setDomainCommand(options) {
88
99
  log(` 本番 URL : ${current.productionUrl || '(未設定)'}`);
89
100
  log(` プレビュー URL: ${current.previewUrl || '(未設定)'}`);
90
101
  log(` R2 公開 URL : ${current.r2PublicUrl || '(未設定)'}`);
102
+ log(` 画像独自ドメインURL: ${current.imagePublicUrl || '(未設定)'}`);
91
103
  if (downloadOptedIn) {
92
104
  log(` 配信ワーカー URL: ${current.downloadApiUrl || '(未設定)'}`);
93
105
  }
@@ -107,6 +119,13 @@ export async function setDomainCommand(options) {
107
119
  initial: current.r2PublicUrl || '',
108
120
  validate: (v) => validateR2PublicUrl(v),
109
121
  },
122
+ {
123
+ type: 'text',
124
+ name: 'imagePublicUrl',
125
+ message: '画像の独自ドメイン配信 URL(任意・変更しない場合は空欄):',
126
+ initial: current.imagePublicUrl || '',
127
+ validate: (v) => (v === '' ? true : validateR2PublicUrl(v)),
128
+ },
110
129
  // ファイル限定配信ワーカーが opt-in 済みのときだけ聞く(PUBLIC_BASE_URL = downloadApiUrl)
111
130
  {
112
131
  type: downloadOptedIn ? 'text' : null,
@@ -131,6 +150,10 @@ export async function setDomainCommand(options) {
131
150
  if (res.r2PublicUrl && res.r2PublicUrl !== current.r2PublicUrl) {
132
151
  change.r2PublicUrl = res.r2PublicUrl;
133
152
  }
153
+ // 画像独自ドメインURL は空入力での opt-out も許容する(current と異なれば反映)
154
+ if (res.imagePublicUrl !== undefined && res.imagePublicUrl !== (current.imagePublicUrl || '')) {
155
+ change.imagePublicUrl = res.imagePublicUrl;
156
+ }
134
157
  if (res.downloadApiUrl && res.downloadApiUrl !== current.downloadApiUrl) {
135
158
  change.downloadApiUrl = res.downloadApiUrl;
136
159
  }
@@ -154,6 +177,7 @@ export async function setDomainCommand(options) {
154
177
  log(` 本番 URL : ${config.productionUrl || '(未設定)'}`);
155
178
  log(` プレビュー URL: ${config.previewUrl || '(未設定)'}`);
156
179
  log(` R2 公開 URL : ${config.r2PublicUrl || '(未設定)'}`);
180
+ log(` 画像独自ドメインURL: ${config.imagePublicUrl || '(未設定)'}`);
157
181
  if (config.downloadApiUrl) {
158
182
  log(` 配信ワーカー URL: ${config.downloadApiUrl}`);
159
183
  }
@@ -21,6 +21,12 @@ export type ContactSetupInput = {
21
21
  smtpPass?: string;
22
22
  /** 設定 JSON 読み取り用 PAT(contents:read、secret) */
23
23
  contentRepoToken?: string;
24
+ /**
25
+ * 内部通知エンドポイント `/notify/admins` の共有シークレット(secret, issue #298)。
26
+ * 予約反映のデプロイ失敗を GitHub Actions から Web Push 通知するために使う。
27
+ * 同じ値を GitHub Actions のリポジトリシークレット `ADMIN_NOTIFY_SECRET` にも登録する。
28
+ */
29
+ adminNotifySecret?: string;
24
30
  };
25
31
  export type ContactSetupResult = {
26
32
  databaseId: string;
@@ -53,6 +53,7 @@ export function setupContactWorker(projectDir, config, input) {
53
53
  putSecret('TURNSTILE_SECRET', input.turnstileSecret);
54
54
  putSecret('SMTP_PASS', input.smtpPass);
55
55
  putSecret('CONTENT_REPO_TOKEN', input.contentRepoToken);
56
+ putSecret('ADMIN_NOTIFY_SECRET', input.adminNotifySecret);
56
57
  return ok({
57
58
  databaseId: d1.data.databaseId,
58
59
  alreadyExisted: d1.alreadyExisted === true,
@@ -20,6 +20,8 @@ export type DomainChange = {
20
20
  /** 明示指定時は逐語優先 */
21
21
  stagingDomain?: string;
22
22
  r2PublicUrl?: string;
23
+ /** 画像の R2 カスタムドメイン配信ベース URL(任意機能・issue #278)。config.json の imagePublicUrl を更新 */
24
+ imagePublicUrl?: string;
23
25
  siteTitle?: string;
24
26
  /**
25
27
  * ファイル限定配信ワーカー(frelio-file-delivery)の公開 URL(任意機能)。
@@ -52,6 +52,10 @@ export function changeDomain(projectDir, change) {
52
52
  merged.siteTitle = change.siteTitle;
53
53
  if (change.r2PublicUrl !== undefined)
54
54
  merged.r2PublicUrl = change.r2PublicUrl;
55
+ if (change.imagePublicUrl !== undefined) {
56
+ // 独自ドメイン配信ベース URL(任意)。空文字なら opt-out(従来の r2PublicUrl 配信のみに戻す)。
57
+ merged.imagePublicUrl = change.imagePublicUrl.replace(/\/+$/, '');
58
+ }
55
59
  // ファイル限定配信ワーカー(任意): downloadApiUrl(config.json)と PUBLIC_BASE_URL は同値。
56
60
  // 末尾スラッシュを除去して両者を厳密一致させる(wrangler.toml は後段で surgical に更新)。
57
61
  let downloadApiUrl;
package/dist/index.js CHANGED
@@ -58,6 +58,7 @@ program
58
58
  .option('--preview-url <url>', 'New preview URL (overrides derived staging domain)')
59
59
  .option('--staging-domain <domain>', 'New staging domain (verbatim)')
60
60
  .option('--r2-public-url <url>', 'New R2 public URL')
61
+ .option('--image-public-url <url>', 'Image delivery base URL via R2 custom domain (config.json imagePublicUrl; empty to opt out)')
61
62
  .option('--download-api-url <url>', 'New file-delivery worker URL (config.json downloadApiUrl + wrangler PUBLIC_BASE_URL)')
62
63
  .option('--regen-staging-hash', 'Regenerate the staging subdomain hash instead of preserving it')
63
64
  .action(setDomainCommand);
@@ -43,6 +43,8 @@ export function projectConfigToVars(config) {
43
43
  workersSubdomain: config.workersSubdomain ?? '',
44
44
  r2BucketName: config.r2BucketName,
45
45
  r2PublicUrl: config.r2PublicUrl,
46
+ // 画像の R2 カスタムドメイン配信ベース URL(任意機能・issue #278)。再生成時に既存値を保持(未設定時のみ空)。
47
+ imagePublicUrl: config.imagePublicUrl ?? '',
46
48
  ownerUsername: config.ownerUsername,
47
49
  allowedOrigins: buildAllowedOrigins(config),
48
50
  saveTimezone: config.saveTimezone || '+09:00',
@@ -36,6 +36,11 @@ export type ProjectConfig = {
36
36
  downloadApiUrl?: string;
37
37
  r2BucketName: string;
38
38
  r2PublicUrl: string;
39
+ /**
40
+ * 画像を R2 カスタムドメインから直接配信する場合のベース URL(任意機能・issue #278)。
41
+ * 設定の有無が「独自ドメイン配信」の opt-in を兼ねる。未設定なら従来どおり r2PublicUrl 配信のみ。
42
+ */
43
+ imagePublicUrl?: string;
39
44
  /** コンテンツ配信 Worker 名(旧称 pagesProjectName)。 */
40
45
  contentWorkerName: string;
41
46
  /** 管理画面 Worker 名(旧称 adminPagesProjectName)。 */
@@ -212,6 +212,9 @@ export function generateConfigJson(config) {
212
212
  workersSubdomain: config.workersSubdomain ?? '',
213
213
  r2BucketName: config.r2BucketName,
214
214
  r2PublicUrl: config.r2PublicUrl,
215
+ // 画像の R2 カスタムドメイン配信ベース URL(任意機能・issue #278)。再生成時に既存値を保持する
216
+ // (未設定時のみ空)。設定の有無が「独自ドメイン配信」の opt-in を兼ねる。
217
+ imagePublicUrl: config.imagePublicUrl ?? '',
215
218
  // allowedOrigins は productionUrl / previewUrl からの派生値(単一ソース / Issue #24)。
216
219
  // wrangler.admin.toml [vars] の ALLOWED_ORIGINS と同じ buildAllowedOrigins で導出し乖離を防ぐ。
217
220
  allowedOrigins: buildAllowedOrigins(config),
@@ -431,6 +434,15 @@ workers_dev = false
431
434
  # <branch>-<worker>.<subdomain>.workers.dev の安定エイリアスを得る。
432
435
  preview_urls = true
433
436
 
437
+ # Observability(Workers Logs)を明示設定(issue #280。既定任せにしない)。
438
+ # 無料枠 20万イベント/日(保持3日) / 有料 2000万/月まで込み・超過 \$0.60/100万(保持7日)。
439
+ # head_sampling_rate = 取り込み率(0–1, 既定1=100%)。live では /storage/* のみ Worker を経由する
440
+ # ため静的ページ閲覧はログ非対象。低〜中トラフィックなら 1(全件)でも無料枠に収まる想定。
441
+ # 画像配信(/storage)が非常に多いサイトは 0.1 等へ下げて取り込み量(=コスト)を抑制できる。
442
+ [observability]
443
+ enabled = true
444
+ head_sampling_rate = 1
445
+
434
446
  [[r2_buckets]]
435
447
  binding = "R2"
436
448
  bucket_name = "${config.r2BucketName}"
@@ -459,6 +471,14 @@ name = "${config.adminWorkerName}"
459
471
  main = "admin-worker/index.js"
460
472
  compatibility_date = "2024-09-23"
461
473
 
474
+ # Observability(Workers Logs)を明示設定(issue #280。既定任せにしない)。
475
+ # 無料枠 20万イベント/日(保持3日) / 有料 2000万/月まで込み・超過 \$0.60/100万(保持7日)。
476
+ # /api/* と /storage/* のみ Worker を経由(SPA アセットは非経由=ログ非対象)。管理画面は
477
+ # 低トラフィックのため 1(全件)で運用しても無料枠に収まる想定。head_sampling_rate で調整可。
478
+ [observability]
479
+ enabled = true
480
+ head_sampling_rate = 1
481
+
462
482
  [[r2_buckets]]
463
483
  binding = "R2"
464
484
  bucket_name = "${config.r2BucketName}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c-time/frelio-cli",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "description": "Frelio CMS setup CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,8 +23,8 @@
23
23
  "prepublishOnly": "npm run build"
24
24
  },
25
25
  "dependencies": {
26
- "@c-time/frelio-data-json": "^3.0.0",
27
- "@c-time/frelio-gentl": "^3.0.0",
26
+ "@c-time/frelio-data-json": "^3.2.0",
27
+ "@c-time/frelio-gentl": "^3.2.0",
28
28
  "commander": "^13.0.0",
29
29
  "prompts": "^2.4.2",
30
30
  "tar": "^7.0.0"