canister-export-env.mjs
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠ breaking
1 day ago
| 1 | import fs from 'node:fs'; |
| 2 | import path from 'node:path'; |
| 3 | |
| 4 | /** |
| 5 | * Default public hub canister HTTP base (no trailing slash) from checked-in canister_ids.json. |
| 6 | * Uses the **raw** subdomain so `/api/v1/*` hits the canister's `http_request` handler. |
| 7 | * `https://<id>.icp0.io` (without `raw`) returns 503 for these routes on typical ICP routing. |
| 8 | * @param {string} repoRoot — absolute path to repository root |
| 9 | * @param {string} [relativeJson='hub/icp/canister_ids.json'] |
| 10 | * @returns {string} |
| 11 | */ |
| 12 | export function hubBaseUrlFromCanisterIds(repoRoot, relativeJson = 'hub/icp/canister_ids.json') { |
| 13 | const p = path.join(repoRoot, relativeJson); |
| 14 | const j = JSON.parse(fs.readFileSync(p, 'utf8')); |
| 15 | const id = j.hub?.ic; |
| 16 | if (!id || typeof id !== 'string') { |
| 17 | throw new Error('Missing hub.ic in canister_ids.json'); |
| 18 | } |
| 19 | return `https://${id}.raw.icp0.io`; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Vault ids to export (order preserved). Matches scripts/canister-export-backup.sh. |
| 24 | * @param {NodeJS.ProcessEnv} env |
| 25 | * @returns {string[]} |
| 26 | */ |
| 27 | export function parseBackupVaultIds(env) { |
| 28 | const raw = (env.KNOWTATION_CANISTER_BACKUP_VAULT_IDS ?? '').trim(); |
| 29 | if (raw.length > 0) { |
| 30 | return raw |
| 31 | .split(',') |
| 32 | .map((s) => s.trim()) |
| 33 | .filter(Boolean); |
| 34 | } |
| 35 | const single = (env.KNOWTATION_CANISTER_BACKUP_VAULT_ID ?? '').trim(); |
| 36 | return [single.length > 0 ? single : 'default']; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * S3 key prefix for backup uploads; always ends with `/`. |
| 41 | * If `KNOWTATION_CANISTER_BACKUP_S3_PREFIX` is unset, empty, or whitespace only, uses |
| 42 | * `knowtation-canister-backups/`. (Plain `??` in callers would not treat `""` as missing, |
| 43 | * which made GitHub Actions pass-through empty vars upload to the wrong key and IAM deny.) |
| 44 | * @param {NodeJS.ProcessEnv} env |
| 45 | * @returns {string} |
| 46 | */ |
| 47 | export function resolveBackupS3Prefix(env) { |
| 48 | const raw = (env.KNOWTATION_CANISTER_BACKUP_S3_PREFIX ?? '').trim(); |
| 49 | const base = raw === '' ? 'knowtation-canister-backups' : raw.replace(/\/+$/, ''); |
| 50 | return `${base}/`; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Resolve canister base URL: explicit URL secrets, then repo canister_ids.json. |
| 55 | * @param {NodeJS.ProcessEnv} env |
| 56 | * @param {string} repoRoot |
| 57 | * @returns {string | null} null if no URL and cannot default from disk |
| 58 | */ |
| 59 | export function resolveCanisterBackupBaseUrl(env, repoRoot) { |
| 60 | const direct = |
| 61 | (env.KNOWTATION_CANISTER_URL ?? '').trim() || |
| 62 | (env.KNOWTATION_CANISTER_BACKUP_URL ?? '').trim(); |
| 63 | if (direct) return direct.replace(/\/$/, ''); |
| 64 | if ((env.KNOWTATION_CANISTER_BACKUP_USER_ID ?? '').trim()) { |
| 65 | try { |
| 66 | return hubBaseUrlFromCanisterIds(repoRoot); |
| 67 | } catch { |
| 68 | return null; |
| 69 | } |
| 70 | } |
| 71 | return null; |
| 72 | } |
File History
2 commits
sha256:65ccb454656ea5acdea0a10e559b78bcde1eb6ff753ecc2911bc99d1c3d7cadd
feat(calendar): enforce agent context tiers in retrieval AP…
Human
minor
⚠
1 day ago
sha256:9103f98c89257ed2b01c237cea895dabb3e85ea337dccb1161c175e4422355b6
docs: accept Calendar Events v0 spec with Phase 0 security …
Human
1 day ago