@tandem-language-exchange/content-store 1.3.1 → 1.3.3

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/shared/lingohub.ts
4
- var defaultLocales = ["en", "fr", "de", "es", "it", "pt-br", "ru", "zh-hans", "zh-hant", "ko", "ja"];
4
+ var defaultLocales = ["en", "fr", "de", "es", "it", "pt-br", "uk", "ru", "zh-hans", "zh-hant", "ko", "ja"];
5
5
  var localeMapping = {
6
6
  ios: {
7
7
  "pt-br": "pt",
@@ -242,4 +242,4 @@ export {
242
242
  defaultLocales,
243
243
  allProjects
244
244
  };
245
- //# sourceMappingURL=chunk-RZLDRXNQ.js.map
245
+ //# sourceMappingURL=chunk-OWL72OTS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/lingohub.ts"],"sourcesContent":["export const defaultLocales = ['en', 'fr', 'de', 'es', 'it', 'pt-br', 'uk', 'ru', 'zh-hans', 'zh-hant', 'ko', 'ja'];\n\nconst localeMapping = {\n ios: {\n 'pt-br': 'pt',\n 'zh-hans': 'zh-Hans',\n 'zh-hant': 'zh-Hant',\n },\n android: {\n 'pt-br': 'pt',\n 'zh-hans': 'zh-Hans-CN',\n 'zh-hant': 'zh-TW',\n },\n};\n\nexport type LingohubResource = {\n resource: string,\n fileName: string;\n type: 'json'|'strings'|'xml';\n localeMapping?: Record<string, string>;\n}\n\nexport const allProjects: Record<string, LingohubResource[]> = {\n 'tandem-(new-website)': [\n {\n resource: 'main',\n fileName: 'Website.[locale].json',\n type: 'json'\n }\n ],\n 'tandem-(website)': [\n {\n resource: 'main',\n fileName: '[locale].json',\n type: 'json'\n },\n {\n resource: 'ai',\n fileName: 'AI.[locale].json',\n type: 'json'\n },\n {\n resource: 'languages',\n fileName: 'languages.[locale].json',\n type: 'json'\n }\n ],\n 'tandem': [\n {\n resource: 'infoplist',\n fileName: 'InfoPlist.[locale].strings',\n type: 'strings',\n localeMapping: localeMapping.ios,\n },\n {\n resource: 'localizable',\n fileName: 'Localizable.[locale].strings',\n type: 'strings',\n localeMapping: localeMapping.ios,\n },\n {\n resource: 'ipad',\n fileName: 'Main_iPad.[locale].strings',\n type: 'strings',\n localeMapping: localeMapping.ios,\n },\n {\n resource: 'main',\n fileName: 'Main.[locale].strings',\n type: 'strings',\n localeMapping: localeMapping.ios,\n }\n ],\n 'tandem-(android)': [\n {\n resource: 'accessibility',\n fileName: 'accessibility_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'call',\n fileName: 'call_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'cert',\n fileName: 'cert_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'chat',\n fileName: 'chat_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'checklist',\n fileName: 'checklist_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'clubs',\n fileName: 'clubs_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'common',\n fileName: 'common_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'community',\n fileName: 'community_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'correction',\n fileName: 'correction_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'country_names',\n fileName: 'country_names.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'emoji',\n fileName: 'emoji_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'errors',\n fileName: 'errors.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'expressions',\n fileName: 'expressions_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'gif',\n fileName: 'gif_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'guidelines',\n fileName: 'guidelines_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'lanuguages',\n fileName: 'languages_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'localizable',\n fileName: 'localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'localizable2',\n fileName: 'localizable2.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'login',\n fileName: 'login_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'myprofile',\n fileName: 'myprofile_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'onb',\n fileName: 'onb_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'parties',\n fileName: 'parties_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'pro',\n fileName: 'pro_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'pro_screen',\n fileName: 'pro_screen_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'push_notification',\n fileName: 'push_notification_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'reporting',\n fileName: 'reporting_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n },\n {\n resource: 'translation',\n fileName: 'translation_localizable.[locale].xml',\n type: 'xml',\n localeMapping: localeMapping.android,\n }\n\n ],\n 'tandem-(web-invites)': [\n {\n resource: 'main',\n fileName: '[locale].json',\n type: 'json'\n }\n ]\n};\n"],"mappings":";;;AAA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EJ;AAAA,EACA,wBAAwB;AAAA,IACpB;AAAA,MACI,UAAU;AAAA,MACV,UAAU;AAAA,MACV,MAAM;AAAA,IACV;AAAA,EACJ;AACJ;","names":[]}
@@ -11,7 +11,7 @@ import {
11
11
  import {
12
12
  allProjects,
13
13
  defaultLocales
14
- } from "./chunk-RZLDRXNQ.js";
14
+ } from "./chunk-OWL72OTS.js";
15
15
 
16
16
  // src/server/adapters/azure/types.ts
17
17
  var AZURE_DEVOPS_PROJECT_KEYS = [
@@ -189,82 +189,6 @@ function pipelineRefForAzure(pipelineEnvironment) {
189
189
  return `refs/heads/${pipelineEnvironment}`;
190
190
  }
191
191
 
192
- // src/shared/content-refresh.ts
193
- import { timingSafeEqual } from "crypto";
194
- async function postContentRefresh(target, url, basicAuth, request) {
195
- try {
196
- const response = await fetch(url, {
197
- method: "POST",
198
- headers: {
199
- Authorization: `Basic ${basicAuth}`,
200
- "Content-Type": "application/json",
201
- Accept: "application/json"
202
- },
203
- body: JSON.stringify(request)
204
- });
205
- const text = await response.text();
206
- let body;
207
- if (text) {
208
- try {
209
- body = JSON.parse(text);
210
- } catch {
211
- body = text;
212
- }
213
- }
214
- return {
215
- target,
216
- ok: response.ok,
217
- status: response.status,
218
- body,
219
- error: response.ok ? void 0 : typeof body === "object" && body !== null && "error" in body ? String(body.error) : `HTTP ${response.status}`
220
- };
221
- } catch (err) {
222
- return {
223
- target,
224
- ok: false,
225
- status: 0,
226
- error: err instanceof Error ? err.message : String(err)
227
- };
228
- }
229
- }
230
-
231
- // src/server/content-refresh-notify.ts
232
- function isContentRefreshEnabledForInstance(instanceEnvironment) {
233
- return normalizeToAzureEnvironment(instanceEnvironment) === "staging";
234
- }
235
- async function notifyContentRefreshTargets(notifyConfig, request, projects) {
236
- if (!notifyConfig.enabled || !notifyConfig.basicAuth) {
237
- return [];
238
- }
239
- const keys = projects ?? AZURE_DEVOPS_PROJECT_KEYS.filter(
240
- (p) => notifyConfig.targets[p]?.url
241
- );
242
- const results = [];
243
- for (const project of keys) {
244
- const url = notifyConfig.targets[project]?.url;
245
- if (!url) {
246
- continue;
247
- }
248
- const result = await postContentRefresh(
249
- project,
250
- url,
251
- notifyConfig.basicAuth,
252
- request
253
- );
254
- results.push(result);
255
- if (result.ok) {
256
- console.log(
257
- `[content-refresh] Notified ${project} (${result.status})`
258
- );
259
- } else {
260
- console.error(
261
- `[content-refresh] Failed to notify ${project}: ${result.error ?? result.status}`
262
- );
263
- }
264
- }
265
- return results;
266
- }
267
-
268
192
  // src/server/config.ts
269
193
  import dotenv from "dotenv";
270
194
 
@@ -520,6 +444,172 @@ var config2 = {
520
444
  }
521
445
  };
522
446
 
447
+ // src/shared/content-refresh.ts
448
+ import { timingSafeEqual } from "crypto";
449
+ async function postContentRefresh(target, url, basicAuth, request) {
450
+ try {
451
+ const response = await fetch(url, {
452
+ method: "POST",
453
+ headers: {
454
+ Authorization: `Basic ${basicAuth}`,
455
+ "Content-Type": "application/json",
456
+ Accept: "application/json"
457
+ },
458
+ body: JSON.stringify(request)
459
+ });
460
+ const text = await response.text();
461
+ let body;
462
+ if (text) {
463
+ try {
464
+ body = JSON.parse(text);
465
+ } catch {
466
+ body = text;
467
+ }
468
+ }
469
+ return {
470
+ target,
471
+ ok: response.ok,
472
+ status: response.status,
473
+ body,
474
+ error: response.ok ? void 0 : typeof body === "object" && body !== null && "error" in body ? String(body.error) : `HTTP ${response.status}`
475
+ };
476
+ } catch (err) {
477
+ return {
478
+ target,
479
+ ok: false,
480
+ status: 0,
481
+ error: err instanceof Error ? err.message : String(err)
482
+ };
483
+ }
484
+ }
485
+
486
+ // src/server/content-refresh-notify.ts
487
+ function isContentRefreshEnabledForInstance(instanceEnvironment) {
488
+ return normalizeToAzureEnvironment(instanceEnvironment) === "staging";
489
+ }
490
+ async function notifyContentRefreshTargets(notifyConfig, request, projects) {
491
+ if (!notifyConfig.enabled || !notifyConfig.basicAuth) {
492
+ return [];
493
+ }
494
+ const keys = projects ?? AZURE_DEVOPS_PROJECT_KEYS.filter(
495
+ (p) => notifyConfig.targets[p]?.url
496
+ );
497
+ const results = [];
498
+ for (const project of keys) {
499
+ const url = notifyConfig.targets[project]?.url;
500
+ if (!url) {
501
+ continue;
502
+ }
503
+ const result = await postContentRefresh(
504
+ project,
505
+ url,
506
+ notifyConfig.basicAuth,
507
+ request
508
+ );
509
+ results.push(result);
510
+ if (result.ok) {
511
+ console.log(
512
+ `[content-refresh] Notified ${project} (${result.status})`
513
+ );
514
+ } else {
515
+ console.error(
516
+ `[content-refresh] Failed to notify ${project}: ${result.error ?? result.status}`
517
+ );
518
+ }
519
+ }
520
+ return results;
521
+ }
522
+ async function notifyClientsAfterCmsSync(result, requestedContentTypes, projects) {
523
+ const { contentRefresh } = config2;
524
+ if (!contentRefresh.enabled) {
525
+ console.log(
526
+ "[content-refresh] Skipped after CMS sync (disabled on this instance; staging/beta only)"
527
+ );
528
+ return [];
529
+ }
530
+ if (!contentRefresh.basicAuth) {
531
+ console.warn(
532
+ "[content-refresh] Skipped after CMS sync (set CONTENT_REFRESH_BASIC_AUTH)"
533
+ );
534
+ return [];
535
+ }
536
+ if (result.errors.length > 0) {
537
+ console.log("[content-refresh] Skipped after CMS sync (sync had errors)");
538
+ return [];
539
+ }
540
+ const types = requestedContentTypes?.length ? requestedContentTypes : result.entries.map((e) => e.contentType);
541
+ if (types.length === 0) {
542
+ console.warn("[content-refresh] Skipped after CMS sync (no content types)");
543
+ return [];
544
+ }
545
+ const targets = projects ?? AZURE_DEVOPS_PROJECT_KEYS.filter(
546
+ (p) => contentRefresh.targets[p]?.url
547
+ );
548
+ if (targets.length === 0) {
549
+ console.warn(
550
+ "[content-refresh] Skipped after CMS sync (no CONTENT_REFRESH_*_URL configured)"
551
+ );
552
+ return [];
553
+ }
554
+ console.log(
555
+ `[content-refresh] Notifying after CMS sync (${result.cms}): ${targets.join(", ")}`
556
+ );
557
+ return notifyContentRefreshTargets(
558
+ contentRefresh,
559
+ {
560
+ scope: "cms",
561
+ cms: result.cms,
562
+ content_types: types
563
+ },
564
+ projects
565
+ );
566
+ }
567
+
568
+ // src/server/adapters/contentful-api-usage.ts
569
+ function emptyContentfulApiUsage() {
570
+ return { cda: 0, cma: 0, cpa: 0 };
571
+ }
572
+ function contentfulApiKindFromHost(host) {
573
+ const h = host.toLowerCase();
574
+ if (h.includes("preview")) {
575
+ return "cpa";
576
+ }
577
+ if (h.includes("api.contentful") || h === "api.contentful.com") {
578
+ return "cma";
579
+ }
580
+ return "cda";
581
+ }
582
+ function totalContentfulApiCalls(usage) {
583
+ return usage.cda + usage.cma + usage.cpa;
584
+ }
585
+ function summariseContentfulApiUsage(usage) {
586
+ const lines = [];
587
+ if (usage.cda > 0) {
588
+ lines.push(`CDA requests: ${usage.cda}`);
589
+ }
590
+ if (usage.cpa > 0) {
591
+ lines.push(`CPA requests: ${usage.cpa}`);
592
+ }
593
+ if (usage.cma > 0) {
594
+ lines.push(`CMA requests: ${usage.cma}`);
595
+ }
596
+ lines.push(`Total contentful API calls: ${totalContentfulApiCalls(usage)}`);
597
+ return lines;
598
+ }
599
+ var ContentfulApiUsageTracker = class {
600
+ kind;
601
+ counts = emptyContentfulApiUsage();
602
+ constructor(host) {
603
+ this.kind = contentfulApiKindFromHost(host);
604
+ }
605
+ recordCall() {
606
+ this.counts[this.kind] += 1;
607
+ }
608
+ snapshot() {
609
+ return { ...this.counts };
610
+ }
611
+ };
612
+
523
613
  // src/server/adapters/contentful.ts
524
614
  import {
525
615
  createClient
@@ -613,6 +703,7 @@ var ContentfulAdapter = class {
613
703
  maxDepth;
614
704
  allowedTypes;
615
705
  retryConfig;
706
+ apiUsage;
616
707
  constructor(cfg2, retryConfig) {
617
708
  this.client = createClient({
618
709
  space: cfg2.spaceId,
@@ -623,10 +714,17 @@ var ContentfulAdapter = class {
623
714
  this.maxDepth = cfg2.maxDepth;
624
715
  this.allowedTypes = cfg2.contentTypes;
625
716
  this.retryConfig = retryConfig;
717
+ this.apiUsage = new ContentfulApiUsageTracker(cfg2.host);
718
+ }
719
+ getContentfulApiUsage() {
720
+ return this.apiUsage.snapshot();
626
721
  }
627
722
  async getContentTypes() {
628
723
  const response = await withRetry(
629
- () => this.client.getContentTypes(),
724
+ () => {
725
+ this.apiUsage.recordCall();
726
+ return this.client.getContentTypes();
727
+ },
630
728
  this.retryConfig
631
729
  );
632
730
  const allTypes = response.items.map((ct) => ct.sys.id);
@@ -656,6 +754,7 @@ var ContentfulAdapter = class {
656
754
  skip,
657
755
  include: includeLevels
658
756
  };
757
+ this.apiUsage.recordCall();
659
758
  const response = await this.client.getEntries(payload);
660
759
  total = response.total;
661
760
  allItems.push(...response.items);
@@ -678,7 +777,10 @@ var ContentfulAdapter = class {
678
777
  let total = 0;
679
778
  do {
680
779
  const response = await withRetry(
681
- () => this.client.getAssets({ limit: this.batchSize, skip }),
780
+ () => {
781
+ this.apiUsage.recordCall();
782
+ return this.client.getAssets({ limit: this.batchSize, skip });
783
+ },
682
784
  this.retryConfig
683
785
  );
684
786
  total = response.total;
@@ -771,6 +873,12 @@ function summariseCmsErrors(result) {
771
873
  (e) => `\u2022 \`${e.contentType}\` \u2014 ${e.error}`
772
874
  );
773
875
  }
876
+ function summariseCmsContentfulApiUsage(result) {
877
+ if (!result.contentfulApiUsage) {
878
+ return [];
879
+ }
880
+ return summariseContentfulApiUsage(result.contentfulApiUsage);
881
+ }
774
882
  function summariseTranslationEntries(entries) {
775
883
  const grouped = /* @__PURE__ */ new Map();
776
884
  for (const e of entries) {
@@ -817,12 +925,19 @@ Starting sync from ${cms} at ${new Date(timestamp * 1e3).toISOString()}`);
817
925
  console.error(` x ${contentType}: ${message}`);
818
926
  }
819
927
  }
928
+ const contentfulApiUsage = adapter.getContentfulApiUsage?.();
929
+ if (contentfulApiUsage) {
930
+ console.log(
931
+ `
932
+ Contentful API calls: ${summariseContentfulApiUsage(contentfulApiUsage).join(", ")}`
933
+ );
934
+ }
820
935
  console.log(
821
936
  `
822
937
  Sync complete: ${entries.length} succeeded, ${errors.length} failed
823
938
  `
824
939
  );
825
- return { cms, timestamp, entries, errors };
940
+ return { cms, timestamp, entries, errors, contentfulApiUsage };
826
941
  }
827
942
  async function syncTranslations(projects, locales) {
828
943
  const store = new ContentStore(config2.s3);
@@ -887,12 +1002,14 @@ export {
887
1002
  triggerPipelineBuild,
888
1003
  formatPipelineRunSummary,
889
1004
  notifyContentRefreshTargets,
1005
+ notifyClientsAfterCmsSync,
890
1006
  nextCronFireAfter,
891
1007
  config2 as config,
892
1008
  summariseCmsEntries,
893
1009
  summariseCmsErrors,
1010
+ summariseCmsContentfulApiUsage,
894
1011
  summariseTranslationEntries,
895
1012
  syncCmsContent,
896
1013
  syncTranslations
897
1014
  };
898
- //# sourceMappingURL=chunk-U73PO7OV.js.map
1015
+ //# sourceMappingURL=chunk-POJRKC4G.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/server/adapters/azure/types.ts","../src/server/adapters/azure/client.ts","../src/server/adapters/azure/pipelines.ts","../src/server/adapters/azure/environment.ts","../src/server/config.ts","../src/server/restrictedCron.ts","../src/shared/content-refresh.ts","../src/server/content-refresh-notify.ts","../src/server/adapters/contentful-api-usage.ts","../src/server/adapters/contentful.ts","../src/server/sync/retry.ts","../src/server/adapters/sanity.ts","../src/server/adapters/index.ts","../src/server/adapters/lingohub.ts","../src/server/sync/engine.ts"],"sourcesContent":["import type { AzurePipelineEnvironment } from './environment';\n\nexport type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';\n\n/** Azure DevOps project name (e.g. `web-site`, `web-app`). */\nexport type AzureDevOpsProjectKey = 'web-site' | 'web-app' | 'web-invites';\n\nexport const AZURE_DEVOPS_PROJECT_KEYS: AzureDevOpsProjectKey[] = [\n 'web-site',\n 'web-app',\n 'web-invites',\n];\n\nexport interface AzurePipelineDefinition {\n id: number;\n refName: string;\n}\n\n/** Pipeline for this content-store instance (one id/ref per ADO project). */\nexport interface AzureProjectConfig {\n pipeline: AzurePipelineDefinition;\n}\n\n/** Credentials and per-project pipeline map for this deployment. */\nexport interface AzureDevOpsConfig {\n organization: string;\n /** Personal access token with pipeline run permissions. */\n pat: string;\n apiVersion: string;\n /** Default when Slack command omits the project argument. */\n defaultProject: AzureDevOpsProjectKey;\n /** Raw `ENVIRONMENT` on this instance (e.g. beta, live). */\n instanceEnvironment: string;\n /** Normalized for Azure (staging | production). */\n pipelineEnvironment: AzurePipelineEnvironment;\n projects: Record<AzureDevOpsProjectKey, AzureProjectConfig>;\n}\n\n/** Connection settings for a single ADO project (used by the HTTP client). */\nexport interface AzureDevOpsClientConfig {\n organization: string;\n project: string;\n pat: string;\n apiVersion: string;\n}\n\nexport interface AzureRequestOptions {\n method?: HttpMethod;\n /**\n * Path under the project, e.g. `/_apis/pipelines/281/runs`.\n * If it starts with `http://` or `https://`, it is used as the full URL.\n */\n path: string;\n query?: Record<string, string | number | boolean | undefined>;\n body?: unknown;\n /** Overrides the default api-version query parameter. */\n apiVersion?: string;\n headers?: Record<string, string>;\n}\n\nexport interface AzureApiErrorBody {\n message?: string;\n typeKey?: string;\n}\n\n/** Subset of the Azure Pipelines run object returned by the Runs API. */\nexport interface PipelineRunResponse {\n id: number;\n name?: string;\n state?: string;\n url?: string;\n createdDate?: string;\n _links?: {\n web?: { href?: string };\n pipeline?: { href?: string };\n };\n}\n\nexport interface TriggerPipelineRunResult {\n project: AzureDevOpsProjectKey;\n instanceEnvironment: string;\n pipelineEnvironment: AzurePipelineEnvironment;\n pipelineId: number;\n refName: string;\n run: PipelineRunResponse;\n}\n","import type {\n AzureApiErrorBody,\n AzureDevOpsClientConfig,\n AzureRequestOptions,\n HttpMethod,\n} from './types';\n\nexport class AzureDevOpsClient {\n private readonly baseUrl: string;\n\n constructor(private readonly config: AzureDevOpsClientConfig) {\n const org = config.organization.replace(/^\\/+|\\/+$/g, '');\n const project = encodeURIComponent(config.project);\n this.baseUrl = `https://dev.azure.com/${org}/${project}`;\n }\n\n /**\n * Call any Azure DevOps REST endpoint under the configured organization and project.\n */\n async request<T>(options: AzureRequestOptions): Promise<T> {\n const {\n method = 'GET',\n path,\n query = {},\n body,\n apiVersion = this.config.apiVersion,\n headers: extraHeaders = {},\n } = options;\n\n if (!this.config.pat) {\n throw new Error(\n 'Azure DevOps is not configured (set AZURE_DEVOPS_ACCESS_TOKEN)',\n );\n }\n\n const url = this.buildUrl(path, { ...query, 'api-version': apiVersion });\n const headers: Record<string, string> = {\n Authorization: this.basicAuthHeader(),\n Accept: 'application/json',\n ...extraHeaders,\n };\n\n const init: RequestInit = { method, headers };\n if (body !== undefined) {\n headers['Content-Type'] = 'application/json';\n init.body = JSON.stringify(body);\n }\n\n const response = await fetch(url, init);\n const text = await response.text();\n let parsed: unknown;\n if (text) {\n try {\n parsed = JSON.parse(text) as unknown;\n } catch {\n parsed = text;\n }\n }\n\n if (!response.ok) {\n const errBody = parsed as AzureApiErrorBody | undefined;\n const detail =\n errBody?.message ??\n (typeof parsed === 'string' ? parsed : JSON.stringify(parsed));\n throw new Error(\n `Azure DevOps ${method} ${path} failed (${response.status}): ${detail}`,\n );\n }\n\n return parsed as T;\n }\n\n private buildUrl(\n path: string,\n query: Record<string, string | number | boolean | undefined>,\n ): string {\n const base = /^https?:\\/\\//i.test(path) ? path : `${this.baseUrl}${path}`;\n const url = new URL(base);\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value));\n }\n }\n return url.toString();\n }\n\n private basicAuthHeader(): string {\n const encoded = Buffer.from(`:${this.config.pat}`).toString('base64');\n return `Basic ${encoded}`;\n }\n}\n\nexport function createAzureDevOpsClient(\n config: AzureDevOpsClientConfig,\n): AzureDevOpsClient {\n return new AzureDevOpsClient(config);\n}\n\nexport type { HttpMethod };\n","import { createAzureDevOpsClient } from './client';\nimport type {\n AzureDevOpsConfig,\n AzureDevOpsProjectKey,\n PipelineRunResponse,\n TriggerPipelineRunResult,\n} from './types';\nimport { AZURE_DEVOPS_PROJECT_KEYS } from './types';\n\nexport function isAzureDevOpsProjectKey(value: string): value is AzureDevOpsProjectKey {\n return (AZURE_DEVOPS_PROJECT_KEYS as string[]).includes(value);\n}\n\nfunction resolveProjectConfig(\n azureConfig: AzureDevOpsConfig,\n project: AzureDevOpsProjectKey,\n) {\n const projectConfig = azureConfig.projects[project];\n if (!projectConfig) {\n throw new Error(`Unknown Azure DevOps project \"${project}\"`);\n }\n return projectConfig;\n}\n\n/**\n * Queue a pipeline run for the given ADO project using this instance's configured pipeline id/ref.\n */\nexport async function triggerPipelineBuild(\n azureConfig: AzureDevOpsConfig,\n project: AzureDevOpsProjectKey,\n variables: Record<string, string> = {},\n): Promise<TriggerPipelineRunResult> {\n const { pipeline } = resolveProjectConfig(azureConfig, project);\n if (!pipeline?.id) {\n throw new Error(\n `No pipeline id configured for project \"${project}\" ` +\n `(instance ENVIRONMENT=${azureConfig.instanceEnvironment}, ` +\n `Azure=${azureConfig.pipelineEnvironment})`,\n );\n }\n\n const client = createAzureDevOpsClient({\n organization: azureConfig.organization,\n project,\n pat: azureConfig.pat,\n apiVersion: azureConfig.apiVersion,\n });\n\n const run = await client.request<PipelineRunResponse>({\n method: 'POST',\n path: `/_apis/pipelines/${pipeline.id}/runs`,\n body: {\n resources: {\n repositories: {\n self: {\n refName: pipeline.refName,\n },\n },\n },\n variables,\n },\n });\n\n return {\n project,\n instanceEnvironment: azureConfig.instanceEnvironment,\n pipelineEnvironment: azureConfig.pipelineEnvironment,\n pipelineId: pipeline.id,\n refName: pipeline.refName,\n run,\n };\n}\n\nexport function formatPipelineRunSummary(result: TriggerPipelineRunResult): string {\n const {\n run,\n project,\n instanceEnvironment,\n pipelineEnvironment,\n pipelineId,\n refName,\n } = result;\n const webUrl = run._links?.web?.href ?? run.url;\n const envLabel =\n instanceEnvironment === pipelineEnvironment\n ? `\\`${pipelineEnvironment}\\``\n : `\\`${instanceEnvironment}\\` → Azure \\`${pipelineEnvironment}\\``;\n const lines = [\n `Environment ${envLabel} — project \\`${project}\\`, pipeline id \\`${pipelineId}\\`, ref \\`${refName}\\``,\n `Run #${run.id}${run.state ? ` — state: \\`${run.state}\\`` : ''}`,\n ];\n if (webUrl) {\n lines.push(`<${webUrl}|Open run in Azure DevOps>`);\n }\n return lines.join('\\n');\n}\n","/**\n * Azure Pipelines only use staging / production naming.\n * Map AWS / shared `ENVIRONMENT` values (beta, live, …) at the adapter boundary.\n */\nexport type AzurePipelineEnvironment = 'staging' | 'production';\n\nconst PRODUCTION_ALIASES = new Set(['production', 'live', 'prod']);\nconst STAGING_ALIASES = new Set(['staging', 'beta', 'development', 'dev', 'local']);\n\n/**\n * Normalize any instance `ENVIRONMENT` value to Azure's staging | production.\n * Unknown values default to staging and log a warning (avoids queuing production by mistake).\n */\nexport function normalizeToAzureEnvironment(\n instanceEnvironment: string,\n): AzurePipelineEnvironment {\n const key = instanceEnvironment.trim().toLowerCase();\n if (!key) {\n console.warn(\n '[azure] Empty ENVIRONMENT; defaulting Azure pipeline environment to staging',\n );\n return 'staging';\n }\n if (PRODUCTION_ALIASES.has(key)) {\n return 'production';\n }\n if (STAGING_ALIASES.has(key)) {\n return 'staging';\n }\n console.warn(\n `[azure] Unrecognized ENVIRONMENT=\"${instanceEnvironment}\"; defaulting Azure pipeline environment to staging`,\n );\n return 'staging';\n}\n\n/** Git ref queued for the pipeline run (always derived from the Azure environment). */\nexport function pipelineRefForAzure(\n pipelineEnvironment: AzurePipelineEnvironment,\n): string {\n return `refs/heads/${pipelineEnvironment}`;\n}\n","import dotenv from 'dotenv';\nimport type { S3Config, CMSProvider } from '../shared/types';\nimport { SharedConfig, config as sharedConfig } from '../shared/config';\nimport type { AzureDevOpsConfig, AzureDevOpsProjectKey } from './adapters/azure';\nimport {\n AZURE_DEVOPS_PROJECT_KEYS,\n normalizeToAzureEnvironment,\n pipelineRefForAzure,\n} from './adapters/azure';\nimport type { AzurePipelineEnvironment } from './adapters/azure';\nimport type { ContentRefreshNotifyConfig } from './content-refresh-notify';\nimport { isContentRefreshEnabledForInstance } from './content-refresh-notify';\nimport { validateScheduleCronExpression } from './restrictedCron';\n\ndotenv.config({ path: '.env.local' });\ndotenv.config();\n\nexport type { CMSProvider, S3Config };\n\nexport interface ContentfulConfig {\n spaceId: string;\n accessToken: string;\n host: string;\n batchSize: number;\n /** Content types to sync. When empty, all content types in the space are synced. */\n contentTypes: string[];\n /** Max nesting depth when unwrapping resolved entries. Deeper references are dropped. */\n maxDepth: number;\n}\n\nexport interface SanityConfig {\n projectId: string;\n dataset: string;\n token: string;\n apiVersion: string;\n}\n\nexport interface LingohubConfig {\n authToken: string;\n workspace: string;\n}\n\nexport interface RetryConfig {\n maxRetries: number;\n baseDelayMs: number;\n maxDelayMs: number;\n}\n\nexport interface RestApiConfig {\n port: number;\n apiToken: string;\n}\n\n/** Background schedule (same behaviour as `content-store sync` in the CLI). */\nexport interface ScheduledCmsJobConfig {\n enabled: boolean;\n /** Two-field cron: minute then hour only. Example: `30 3` or a minute step with star in the hour field. Empty when disabled. */\n cronExpression: string;\n /** When true, run once when the server starts, then on the cron wall clock. */\n runOnStart: boolean;\n syncCms?: CMSProvider;\n syncTypes?: string[];\n}\n\nexport interface ScheduledTranslationJobConfig {\n enabled: boolean;\n cronExpression: string;\n runOnStart: boolean;\n syncProjects?: string[];\n}\n\nfunction readScheduleCronEnv(): {\n scheduleCron: string;\n cmsCronRaw: string;\n translationCronRaw: string;\n} {\n return {\n scheduleCron: (process.env.SCHEDULE_CRON ?? '').trim(),\n cmsCronRaw: (process.env.SCHEDULE_CMS_CRON ?? '').trim(),\n translationCronRaw: (process.env.SCHEDULE_TRANSLATION_CRON ?? '').trim(),\n };\n}\n\nfunction resolveScheduleCron(\n jobSpecific: string,\n globalCron: string,\n jobLabel: string,\n): string | null {\n const raw = jobSpecific || globalCron;\n if (!raw) return null;\n try {\n return validateScheduleCronExpression(raw);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n console.error(`[config] Invalid ${jobLabel} schedule cron: ${msg}`);\n return null;\n }\n}\n\nfunction parseScheduledCmsJobConfig(): ScheduledCmsJobConfig {\n const { scheduleCron, cmsCronRaw } = readScheduleCronEnv();\n const runOnStart =\n (process.env.SCHEDULE_RUN_ON_START ?? 'true').toLowerCase() !== 'false';\n const syncCms = (process.env.SCHEDULE_SYNC_CMS ?? '').trim() as CMSProvider;\n const rawTypes = process.env.SCHEDULE_SYNC_CONTENT_TYPES?.trim();\n const syncTypes = rawTypes\n ? rawTypes.split(',').map((s) => s.trim()).filter(Boolean)\n : undefined;\n\n const resolved = resolveScheduleCron(cmsCronRaw, scheduleCron, 'CMS');\n const cmsOk =\n !!syncCms && (syncCms === 'contentful' || syncCms === 'sanity');\n if (resolved !== null && !cmsOk) {\n console.warn(\n '[config] CMS schedule cron is set but SCHEDULE_SYNC_CMS is missing or not \"contentful\"|\"sanity\"; scheduled CMS sync is disabled.',\n );\n }\n const enabled = resolved !== null && cmsOk;\n\n return {\n enabled,\n cronExpression: resolved ?? '',\n runOnStart,\n syncCms: syncCms || undefined,\n syncTypes,\n };\n}\n\nfunction parseScheduledTranslationJobConfig(): ScheduledTranslationJobConfig {\n const { scheduleCron, translationCronRaw } = readScheduleCronEnv();\n const runOnStart =\n (process.env.SCHEDULE_RUN_ON_START ?? 'true').toLowerCase() !== 'false';\n const rawProjects = process.env.SCHEDULE_SYNC_TRANSLATION_PROJECTS?.trim();\n const syncProjects = rawProjects\n ? rawProjects.split(',').map((s) => s.trim()).filter(Boolean)\n : undefined;\n\n const resolved = resolveScheduleCron(\n translationCronRaw,\n scheduleCron,\n 'translation',\n );\n const enabled = resolved !== null;\n\n return {\n enabled,\n cronExpression: resolved ?? '',\n runOnStart,\n syncProjects,\n };\n}\n\nexport interface SlackConfig {\n enabled: boolean;\n botToken: string;\n signingSecret: string;\n /** Socket Mode app-level token (xapp-…). Required when enabled. */\n appToken: string;\n /** Channel ID or name for async notifications (e.g. sync results). */\n notifyChannel: string;\n /** Slash command name for CMS sync (default `/sync-content`). */\n cmdSyncContent: string;\n /** Slash command name for translation sync (default `/sync-translations`). */\n cmdSyncTranslations: string;\n /** Slash command to queue an Azure Pipelines run (default `/trigger-pipeline`). */\n cmdTriggerBuild: string;\n}\n\nfunction projectEnvSlug(project: AzureDevOpsProjectKey): string {\n return project.toUpperCase().replace(/-/g, '_');\n}\n\nfunction readProjectPipeline(\n project: AzureDevOpsProjectKey,\n pipelineEnvironment: AzurePipelineEnvironment,\n): { id: number; refName: string } {\n const slug = projectEnvSlug(project);\n const id = parseInt(process.env[`AZURE_${slug}_PIPELINE_ID`]?.trim() ?? '0', 10);\n return { id, refName: pipelineRefForAzure(pipelineEnvironment) };\n}\n\nfunction parseAzureDevOpsConfig(\n instanceEnvironment: string,\n): AzureDevOpsConfig & { enabled: boolean } {\n const pipelineEnvironment = normalizeToAzureEnvironment(instanceEnvironment);\n const pat = process.env.AZURE_DEVOPS_ACCESS_TOKEN?.trim() ?? '';\n\n const defaultProjectRaw = (\n process.env.AZURE_DEVOPS_DEFAULT_PROJECT ?? 'web-site'\n ).trim() as AzureDevOpsProjectKey;\n\n const defaultProject = (AZURE_DEVOPS_PROJECT_KEYS as string[]).includes(\n defaultProjectRaw,\n )\n ? defaultProjectRaw\n : 'web-site';\n\n const projects = Object.fromEntries(\n AZURE_DEVOPS_PROJECT_KEYS.map((project) => [\n project,\n { pipeline: readProjectPipeline(project, pipelineEnvironment) },\n ]),\n ) as AzureDevOpsConfig['projects'];\n\n return {\n enabled: pat.length > 0,\n organization: process.env.AZURE_DEVOPS_ORGANIZATION?.trim() || 'tripod-technology',\n pat,\n apiVersion: process.env.AZURE_DEVOPS_API_VERSION?.trim() || '7.1',\n defaultProject,\n instanceEnvironment,\n pipelineEnvironment,\n projects,\n };\n}\n\nfunction readContentRefreshUrl(project: AzureDevOpsProjectKey): string | undefined {\n const slug = projectEnvSlug(project);\n return process.env[`CONTENT_REFRESH_${slug}_URL`]?.trim() || undefined;\n}\n\nfunction parseContentRefreshConfig(\n instanceEnvironment: string,\n): ContentRefreshNotifyConfig {\n const targets = Object.fromEntries(\n AZURE_DEVOPS_PROJECT_KEYS.map((project) => [\n project,\n { url: readContentRefreshUrl(project) },\n ]),\n ) as ContentRefreshNotifyConfig['targets'];\n\n return {\n enabled: isContentRefreshEnabledForInstance(instanceEnvironment),\n basicAuth: process.env.CONTENT_REFRESH_BASIC_AUTH?.trim() ?? '',\n targets,\n };\n}\n\nexport interface ServerConfig {\n contentful: ContentfulConfig;\n sanity: SanityConfig;\n lingohub: LingohubConfig;\n retry: RetryConfig;\n api: RestApiConfig;\n scheduledCmsJob: ScheduledCmsJobConfig;\n scheduledTranslationJob: ScheduledTranslationJobConfig;\n azure: AzureDevOpsConfig & { enabled: boolean };\n contentRefresh: ContentRefreshNotifyConfig;\n slack: SlackConfig;\n}\n\nexport const config: ServerConfig & SharedConfig = {\n ...sharedConfig,\n contentful: {\n spaceId: process.env.CONTENTFUL_SPACE_ID ?? '',\n accessToken: process.env.CONTENTFUL_WEBSITE_TOKEN ?? '',\n host: process.env.CONTENTFUL_HOST ?? 'preview.contentful.com',\n batchSize: 1000,\n maxDepth: 4,\n contentTypes: [\n 'asset','page','longtailPage','customJson','banner','cookieBanner','downloadPage'\n // Add Contentful content type IDs here to limit sync scope.\n ],\n },\n\n sanity: {\n projectId: process.env.SANITY_PROJECT_ID ?? '',\n dataset: process.env.SANITY_DATASET ?? 'main',\n token: process.env.SANITY_API_TOKEN ?? '',\n apiVersion: '2024-01-01',\n },\n\n lingohub: {\n authToken : process.env.LINGOHUB_AUTH_TOKEN ?? '',\n workspace: process.env.LINGOHUB_WORKSPACE ?? '',\n },\n\n retry: {\n maxRetries: parseInt(process.env.RETRY_MAX_RETRIES ?? '5', 10),\n baseDelayMs: parseInt(process.env.RETRY_BASE_DELAY_MS ?? '1000', 10),\n maxDelayMs: parseInt(process.env.RETRY_MAX_DELAY_MS ?? '60000', 10),\n },\n\n api: {\n port: parseInt(process.env.PORT ?? '3030', 10),\n apiToken: process.env.CONTENT_STORE_API_TOKEN ?? '',\n },\n\n scheduledCmsJob: parseScheduledCmsJobConfig(),\n scheduledTranslationJob: parseScheduledTranslationJobConfig(),\n\n azure: parseAzureDevOpsConfig(sharedConfig.environment),\n\n contentRefresh: parseContentRefreshConfig(sharedConfig.environment),\n\n slack: {\n enabled: (process.env.SLACK_BOT_TOKEN ?? '').length > 0,\n botToken: process.env.SLACK_BOT_TOKEN ?? '',\n signingSecret: process.env.SLACK_SIGNING_SECRET ?? '',\n appToken: process.env.SLACK_APP_TOKEN ?? '',\n notifyChannel: process.env.SLACK_NOTIFY_CHANNEL ?? '',\n cmdSyncContent: process.env.SLACK_CMD_SYNC_CONTENT ?? '/sync-content',\n cmdSyncTranslations: process.env.SLACK_CMD_SYNC_TRANSLATIONS ?? '/sync-translations',\n cmdTriggerBuild:\n process.env.SLACK_CMD_TRIGGER_BUILD ?? '/trigger-build',\n },\n};\n","/**\n * Schedule expressions: exactly **two** whitespace-separated fields: minute, then hour\n * (same meaning as the first two fields of standard cron). No day-of-month, month, or\n * day-of-week — those are not accepted.\n *\n * Supported per field: `*`, `n`, `a-b`, steps (asterisk + slash + step), and comma lists.\n * Step must be >= 1.\n */\n\nconst MAX_SEARCH_MINUTES = 366 * 24 * 60;\n\nfunction tokenize(expr: string): string[] {\n return expr\n .trim()\n .split(/\\s+/)\n .map((s) => s.trim())\n .filter(Boolean);\n}\n\n/**\n * Validates that `expr` is exactly two cron fields (minute hour) and returns them\n * as a single normalized string `\"<minute> <hour>\"` for storage and logging.\n */\nexport function validateScheduleCronExpression(expr: string): string {\n const parts = tokenize(expr);\n if (parts.length !== 2) {\n throw new Error(\n `Schedule cron must be exactly two fields (minute hour), whitespace-separated; got ${parts.length} field(s): \"${expr}\"`,\n );\n }\n const minuteSpec = parts[0]!;\n const hourSpec = parts[1]!;\n parseField(minuteSpec, 0, 59, 'minute');\n parseField(hourSpec, 0, 23, 'hour');\n return `${minuteSpec} ${hourSpec}`;\n}\n\nfunction parseField(\n spec: string,\n lo: number,\n hi: number,\n fieldName: string,\n): (n: number) => boolean {\n const subs = spec.split(',').map((s) => s.trim()).filter(Boolean);\n if (subs.length === 0) {\n throw new Error(`Empty ${fieldName} field in cron`);\n }\n const preds = subs.map((sub) => parseSubfield(sub, lo, hi, fieldName));\n return (n: number) => preds.some((p) => p(n));\n}\n\nfunction parseSubfield(\n sub: string,\n lo: number,\n hi: number,\n fieldName: string,\n): (n: number) => boolean {\n if (sub === '*') {\n return () => true;\n }\n if (sub.startsWith('*/')) {\n const step = parseInt(sub.slice(2), 10);\n if (!Number.isFinite(step) || step < 1) {\n throw new Error(`Invalid step in ${fieldName} field: \"${sub}\"`);\n }\n return (n: number) => n >= lo && n <= hi && n % step === 0;\n }\n if (sub.includes('-')) {\n const [a, b] = sub.split('-').map((x) => parseInt(x.trim(), 10));\n if (!Number.isFinite(a) || !Number.isFinite(b)) {\n throw new Error(`Invalid range in ${fieldName} field: \"${sub}\"`);\n }\n if (a < lo || b > hi || a > b) {\n throw new Error(`Range out of bounds in ${fieldName} field: \"${sub}\"`);\n }\n return (n: number) => n >= a && n <= b;\n }\n const v = parseInt(sub, 10);\n if (!Number.isFinite(v) || v < lo || v > hi) {\n throw new Error(`Invalid value in ${fieldName} field: \"${sub}\"`);\n }\n return (n: number) => n === v;\n}\n\nfunction floorToMinuteStart(d: Date): Date {\n const t = new Date(d.getTime());\n t.setSeconds(0, 0);\n return t;\n}\n\nfunction addOneMinute(d: Date): Date {\n const t = new Date(d.getTime());\n t.setMinutes(t.getMinutes() + 1, 0, 0);\n return t;\n}\n\nfunction matchesAtMinuteStart(\n minutePred: (m: number) => boolean,\n hourPred: (h: number) => boolean,\n d: Date,\n): boolean {\n return minutePred(d.getMinutes()) && hourPred(d.getHours());\n}\n\n/**\n * Earliest minute boundary strictly after `after` that satisfies the two-field expression.\n */\nexport function nextCronFireAfter(expr: string, after: Date): Date {\n const parts = tokenize(expr);\n if (parts.length !== 2) {\n throw new Error(\n `nextCronFireAfter expects exactly two fields (minute hour); got ${parts.length}: \"${expr}\"`,\n );\n }\n const minutePred = parseField(parts[0]!, 0, 59, 'minute');\n const hourPred = parseField(parts[1]!, 0, 23, 'hour');\n\n let d = floorToMinuteStart(after);\n if (d.getTime() <= after.getTime()) {\n d = addOneMinute(d);\n }\n\n for (let i = 0; i < MAX_SEARCH_MINUTES; i++) {\n if (matchesAtMinuteStart(minutePred, hourPred, d)) {\n return d;\n }\n d = addOneMinute(d);\n }\n\n throw new Error(`No cron match within ${MAX_SEARCH_MINUTES} minutes for \"${expr}\"`);\n}\n","import { timingSafeEqual } from 'node:crypto';\nimport type { CMSProvider } from './types';\nimport type {\n FetchCmsBundlesOptions,\n FetchTranslationBundlesOptions,\n TranslationBundleInfo,\n} from './bundles';\n\nexport type ContentRefreshScope = 'cms' | 'translations' | 'all';\n\nexport interface ContentRefreshRequest {\n scope?: ContentRefreshScope;\n cms?: CMSProvider;\n content_types?: string[];\n projects?: string[];\n locales?: string[];\n}\n\n/** Defaults applied when the request omits fields (set by the host application). */\nexport interface ContentRefreshDefaults {\n scope?: ContentRefreshScope;\n cms?: CMSProvider;\n contentTypes?: string[];\n translationProjects?: string[];\n locales?: string[];\n}\n\nexport interface ContentRefreshError {\n step: string;\n message: string;\n}\n\nexport interface ContentRefreshResult {\n ok: boolean;\n scope: ContentRefreshScope;\n cmsFiles?: Record<string, string>;\n translationFiles?: TranslationBundleInfo;\n errors: ContentRefreshError[];\n durationMs: number;\n}\n\nexport interface ContentRefreshFetchers {\n fetchCmsBundles: (\n options: FetchCmsBundlesOptions,\n ) => Promise<Record<string, string>>;\n fetchTranslationBundles: (\n options: FetchTranslationBundlesOptions,\n ) => Promise<TranslationBundleInfo>;\n}\n\nexport function resolveContentRefreshScope(\n request: ContentRefreshRequest,\n defaults: ContentRefreshDefaults,\n): ContentRefreshScope {\n return request.scope ?? defaults.scope ?? 'cms';\n}\n\n/** Base64 of `username:password` (value only — prefix with `Basic ` in the header). */\nexport function encodeBasicAuthCredentials(\n username: string,\n password: string,\n): string {\n return Buffer.from(`${username}:${password}`, 'utf8').toString('base64');\n}\n\n/**\n * Validates `Authorization: Basic <base64>` against the expected credentials\n * (base64 of `user:pass`, same as staging site basic auth).\n */\nexport function assertContentRefreshBasicAuth(\n authorizationHeader: string | undefined,\n expectedCredentialsBase64: string,\n): void {\n if (!expectedCredentialsBase64) {\n throw new ContentRefreshAuthError(\n 'Content refresh basic auth is not configured (set CONTENT_REFRESH_BASIC_AUTH)',\n 500,\n );\n }\n if (!authorizationHeader?.startsWith('Basic ')) {\n throw new ContentRefreshAuthError(\n 'Missing or malformed Authorization header (expected Basic)',\n 401,\n );\n }\n const provided = authorizationHeader.slice(6).trim();\n const bufA = new TextEncoder().encode(provided);\n const bufB = new TextEncoder().encode(expectedCredentialsBase64);\n if (bufA.byteLength !== bufB.byteLength || !timingSafeEqual(bufA, bufB)) {\n throw new ContentRefreshAuthError('Invalid basic auth credentials', 403);\n }\n}\n\nexport class ContentRefreshAuthError extends Error {\n constructor(\n message: string,\n readonly statusCode: number,\n ) {\n super(message);\n this.name = 'ContentRefreshAuthError';\n }\n}\n\n/**\n * Pull the latest bundles from S3 into the host app's configured output directory.\n */\nexport async function executeContentRefresh(\n fetchers: ContentRefreshFetchers,\n request: ContentRefreshRequest,\n defaults: ContentRefreshDefaults = {},\n): Promise<ContentRefreshResult> {\n const started = Date.now();\n const scope = resolveContentRefreshScope(request, defaults);\n const errors: ContentRefreshError[] = [];\n let cmsFiles: Record<string, string> | undefined;\n let translationFiles: TranslationBundleInfo | undefined;\n\n if (scope === 'cms' || scope === 'all') {\n const cms = request.cms ?? defaults.cms ?? 'contentful';\n const contentTypes = request.content_types ?? defaults.contentTypes;\n if (!contentTypes?.length) {\n errors.push({\n step: 'cms',\n message: 'content_types (or handler defaults.contentTypes) is required for CMS refresh',\n });\n } else {\n try {\n cmsFiles = await fetchers.fetchCmsBundles({ cms, contentTypes });\n } catch (err) {\n errors.push({\n step: 'cms',\n message: err instanceof Error ? err.message : String(err),\n });\n }\n }\n }\n\n if (scope === 'translations' || scope === 'all') {\n const projects = request.projects ?? defaults.translationProjects;\n if (!projects?.length) {\n errors.push({\n step: 'translations',\n message:\n 'projects (or handler defaults.translationProjects) is required for translation refresh',\n });\n } else {\n const locales = request.locales ?? defaults.locales;\n try {\n const projectMap = Object.fromEntries(\n projects.map((p) => [p, [] as string[]]),\n );\n translationFiles = await fetchers.fetchTranslationBundles({\n projects: projectMap,\n locales,\n });\n } catch (err) {\n errors.push({\n step: 'translations',\n message: err instanceof Error ? err.message : String(err),\n });\n }\n }\n }\n\n return {\n ok: errors.length === 0,\n scope,\n cmsFiles,\n translationFiles,\n errors,\n durationMs: Date.now() - started,\n };\n}\n\nexport interface PostContentRefreshResponse {\n target: string;\n ok: boolean;\n status: number;\n body?: unknown;\n error?: string;\n}\n\n/**\n * Ask a remote application (web-site, web-app, …) to refresh its local content cache.\n */\nexport async function postContentRefresh(\n target: string,\n url: string,\n basicAuth: string,\n request: ContentRefreshRequest,\n): Promise<PostContentRefreshResponse> {\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers: {\n Authorization: `Basic ${basicAuth}`,\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n },\n body: JSON.stringify(request),\n });\n\n const text = await response.text();\n let body: unknown;\n if (text) {\n try {\n body = JSON.parse(text) as unknown;\n } catch {\n body = text;\n }\n }\n\n return {\n target,\n ok: response.ok,\n status: response.status,\n body,\n error: response.ok\n ? undefined\n : typeof body === 'object' && body !== null && 'error' in body\n ? String((body as { error: unknown }).error)\n : `HTTP ${response.status}`,\n };\n } catch (err) {\n return {\n target,\n ok: false,\n status: 0,\n error: err instanceof Error ? err.message : String(err),\n };\n }\n}\n","import type { AzureDevOpsProjectKey } from './adapters/azure';\nimport { AZURE_DEVOPS_PROJECT_KEYS } from './adapters/azure';\nimport { normalizeToAzureEnvironment } from './adapters/azure';\nimport { config, type CMSProvider } from './config';\nimport type { CmsSyncResult } from './sync/engine';\nimport {\n postContentRefresh,\n type ContentRefreshRequest,\n type PostContentRefreshResponse,\n} from '../shared/content-refresh';\n\nexport interface ContentRefreshTargetConfig {\n url?: string;\n}\n\nexport interface ContentRefreshNotifyConfig {\n /** When false, never call client refresh URLs (e.g. production uses pipeline builds). */\n enabled: boolean;\n /** Base64 of `username:password` (no `Basic ` prefix). */\n basicAuth: string;\n targets: Record<AzureDevOpsProjectKey, ContentRefreshTargetConfig>;\n}\n\nexport function isContentRefreshEnabledForInstance(\n instanceEnvironment: string,\n): boolean {\n return normalizeToAzureEnvironment(instanceEnvironment) === 'staging';\n}\n\nexport async function notifyContentRefreshTargets(\n notifyConfig: ContentRefreshNotifyConfig,\n request: ContentRefreshRequest,\n projects?: AzureDevOpsProjectKey[],\n): Promise<PostContentRefreshResponse[]> {\n if (!notifyConfig.enabled || !notifyConfig.basicAuth) {\n return [];\n }\n\n const keys =\n projects ??\n (AZURE_DEVOPS_PROJECT_KEYS.filter(\n (p) => notifyConfig.targets[p]?.url,\n ) as AzureDevOpsProjectKey[]);\n\n const results: PostContentRefreshResponse[] = [];\n\n for (const project of keys) {\n const url = notifyConfig.targets[project]?.url;\n if (!url) {\n continue;\n }\n const result = await postContentRefresh(\n project,\n url,\n notifyConfig.basicAuth,\n request,\n );\n results.push(result);\n if (result.ok) {\n console.log(\n `[content-refresh] Notified ${project} (${result.status})`,\n );\n } else {\n console.error(\n `[content-refresh] Failed to notify ${project}: ${result.error ?? result.status}`,\n );\n }\n }\n\n return results;\n}\n\n/**\n * After a successful CMS sync (Slack, HTTP API, or cron), POST to configured client refresh URLs.\n */\nexport async function notifyClientsAfterCmsSync(\n result: CmsSyncResult,\n requestedContentTypes?: string[],\n projects?: AzureDevOpsProjectKey[],\n): Promise<PostContentRefreshResponse[]> {\n const { contentRefresh } = config;\n\n if (!contentRefresh.enabled) {\n console.log(\n '[content-refresh] Skipped after CMS sync (disabled on this instance; staging/beta only)',\n );\n return [];\n }\n if (!contentRefresh.basicAuth) {\n console.warn(\n '[content-refresh] Skipped after CMS sync (set CONTENT_REFRESH_BASIC_AUTH)',\n );\n return [];\n }\n if (result.errors.length > 0) {\n console.log('[content-refresh] Skipped after CMS sync (sync had errors)');\n return [];\n }\n\n const types = requestedContentTypes?.length\n ? requestedContentTypes\n : result.entries.map((e) => e.contentType);\n if (types.length === 0) {\n console.warn('[content-refresh] Skipped after CMS sync (no content types)');\n return [];\n }\n\n const targets = (\n projects ??\n (AZURE_DEVOPS_PROJECT_KEYS.filter(\n (p) => contentRefresh.targets[p]?.url,\n ) as AzureDevOpsProjectKey[])\n );\n\n if (targets.length === 0) {\n console.warn(\n '[content-refresh] Skipped after CMS sync (no CONTENT_REFRESH_*_URL configured)',\n );\n return [];\n }\n\n console.log(\n `[content-refresh] Notifying after CMS sync (${result.cms}): ${targets.join(', ')}`,\n );\n\n return notifyContentRefreshTargets(\n contentRefresh,\n {\n scope: 'cms',\n cms: result.cms as CMSProvider,\n content_types: types,\n },\n projects,\n );\n}\n","/** Per-API request counts for a single Contentful sync run. */\nexport interface ContentfulApiUsage {\n cda: number;\n cma: number;\n cpa: number;\n}\n\nexport type ContentfulApiKind = keyof ContentfulApiUsage;\n\nexport function emptyContentfulApiUsage(): ContentfulApiUsage {\n return { cda: 0, cma: 0, cpa: 0 };\n}\n\n/** Map Contentful client `host` to CDA / CPA / CMA (one kind per adapter instance). */\nexport function contentfulApiKindFromHost(host: string): ContentfulApiKind {\n const h = host.toLowerCase();\n if (h.includes('preview')) {\n return 'cpa';\n }\n if (h.includes('api.contentful') || h === 'api.contentful.com') {\n return 'cma';\n }\n return 'cda';\n}\n\nexport function totalContentfulApiCalls(usage: ContentfulApiUsage): number {\n return usage.cda + usage.cma + usage.cpa;\n}\n\n/** Slack / log lines for Contentful API usage (omits zero counts except total). */\nexport function summariseContentfulApiUsage(usage: ContentfulApiUsage): string[] {\n const lines: string[] = [];\n if (usage.cda > 0) {\n lines.push(`CDA requests: ${usage.cda}`);\n }\n if (usage.cpa > 0) {\n lines.push(`CPA requests: ${usage.cpa}`);\n }\n if (usage.cma > 0) {\n lines.push(`CMA requests: ${usage.cma}`);\n }\n lines.push(`Total contentful API calls: ${totalContentfulApiCalls(usage)}`);\n return lines;\n}\n\nexport class ContentfulApiUsageTracker {\n private readonly kind: ContentfulApiKind;\n private readonly counts = emptyContentfulApiUsage();\n\n constructor(host: string) {\n this.kind = contentfulApiKindFromHost(host);\n }\n\n recordCall(): void {\n this.counts[this.kind] += 1;\n }\n\n snapshot(): ContentfulApiUsage {\n return { ...this.counts };\n }\n}\n","import {\n createClient,\n type ContentfulClientApi,\n type ContentTypeCollection,\n type AssetCollection,\n} from 'contentful';\nimport type { ContentfulConfig, RetryConfig } from '../config';\nimport type { CMSAdapter, FetchResult } from './types';\nimport {\n type ContentfulApiUsage,\n ContentfulApiUsageTracker,\n} from './contentful-api-usage';\nimport { withRetry } from '../sync/retry';\n\ntype CfCollection = {\n items: CfItem[],\n total: number\n}\n\ntype CfItem = {\n metadata:{\n tags: string[],\n concepts: string[]\n }\n sys:{\n type: string,\n id: string\n space: {\n sys: {\n type: string\n linkType: string\n id: string\n }\n },\n environment: {\n sys: {\n id: string\n type: 'Link',\n linkType: 'Environment'\n }\n },\n contentType: {\n sys: {\n type: 'Link',\n linkType: 'ContentType',\n id: string\n }\n },\n createdBy: {\n sys: {\n type: 'Link',\n linkType: 'User',\n id: string,\n }\n },\n updatedBy: {\n sys: {\n type: 'Link',\n linkType: 'User',\n id: string\n }\n },\n 'revision': number,\n 'createdAt': string,\n 'updatedAt': string,\n 'publishedVersion': string\n },\n fields:{\n [key:string]: unknown\n }\n}\n\n\n/**\n * Recursively unwraps Contentful's { metadata, sys, fields } envelope.\n * `depth` tracks how many entry/asset envelopes deep we are — anything\n * beyond `maxDepth` is dropped to avoid blowing the call stack on\n * circular or extremely deep reference chains.\n *\n * `path` holds objects on the current recursion branch only. That way a\n * shared reference (e.g. the same asset on `image` and `mobileImage`) is\n * unwrapped for each sibling; only true cycles (an object recurring as a\n * descendant of itself) yield `undefined`.\n */\nfunction stripEnvelope(\n value: unknown,\n maxDepth: number,\n depth = 0,\n path = new WeakSet<object>(),\n): unknown {\n if (value === null || typeof value !== 'object') return value;\n\n const obj = value as CfItem;\n\n if (path.has(obj)) return undefined;\n path.add(obj);\n\n try {\n if (Array.isArray(value)) {\n return value.map((item) => stripEnvelope(item, maxDepth, depth, path));\n }\n\n const isEnvelope = 'sys' in obj && 'fields' in obj && typeof obj.fields === 'object';\n\n if (isEnvelope) {\n if (depth >= maxDepth) return undefined;\n\n const fields = obj.fields as Record<string, unknown>;\n const result: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(fields)) {\n result[k] = stripEnvelope(v, maxDepth, depth + 1, path);\n }\n\n const sys = obj.sys;\n if (sys) {\n const existingMeta = result.meta;\n const metaBase =\n typeof existingMeta === 'object' &&\n existingMeta !== null &&\n !Array.isArray(existingMeta)\n ? (existingMeta as Record<string, unknown>)\n : {};\n const _contentType = sys.contentType ? sys.contentType.sys.id : 'Asset'\n result.meta = { ...metaBase, _id: sys.id, _contentType, _updatedAt: sys.updatedAt };\n }\n\n return result;\n }\n\n const result: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(obj)) {\n result[k] = stripEnvelope(v, maxDepth, depth, path);\n }\n return result;\n } finally {\n path.delete(obj);\n }\n}\n\nexport class ContentfulAdapter implements CMSAdapter {\n readonly name = 'contentful';\n private client: ContentfulClientApi<undefined>;\n private batchSize: number;\n private maxDepth: number;\n private allowedTypes: string[];\n private retryConfig: RetryConfig;\n private readonly apiUsage: ContentfulApiUsageTracker;\n\n constructor(cfg: ContentfulConfig, retryConfig: RetryConfig) {\n this.client = createClient({\n space: cfg.spaceId,\n accessToken: cfg.accessToken,\n host: cfg.host,\n });\n this.batchSize = cfg.batchSize;\n this.maxDepth = cfg.maxDepth;\n this.allowedTypes = cfg.contentTypes;\n this.retryConfig = retryConfig;\n this.apiUsage = new ContentfulApiUsageTracker(cfg.host);\n }\n\n getContentfulApiUsage(): ContentfulApiUsage {\n return this.apiUsage.snapshot();\n }\n\n async getContentTypes(): Promise<string[]> {\n const response = await withRetry<ContentTypeCollection>(\n () => {\n this.apiUsage.recordCall();\n return this.client.getContentTypes();\n },\n this.retryConfig,\n );\n\n const allTypes = response.items.map((ct) => ct.sys.id);\n\n if (this.allowedTypes.length > 0) {\n return allTypes.filter((t) => this.allowedTypes.includes(t));\n }\n return allTypes;\n }\n\n /**\n * Fetches every entry for a content type using batched pagination.\n * Contentful caps `getEntries` at 1 000 items per call, so we page through\n * with `skip` until all items are collected.\n *\n * The reserved content type `\"asset\"` fetches from `getAssets()` instead.\n */\n async fetchAll(contentType: string, includeLevels: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 = 4): Promise<FetchResult> {\n if (contentType === 'asset') {\n return this.fetchAllAssets();\n }\n\n const allItems: unknown[] = [];\n let skip = 0;\n let total = 0;\n\n do {\n const payload = {\n content_type: contentType,\n limit: this.batchSize,\n skip,\n include: includeLevels,\n };\n this.apiUsage.recordCall();\n const response = await this.client.getEntries(payload) as unknown as CfCollection;\n total = response.total;\n allItems.push(...response.items);\n skip += response.items.length;\n\n if (total > this.batchSize) {\n console.log(\n ` [contentful] ${contentType}: fetched ${allItems.length}/${total}`,\n );\n }\n } while (skip < total);\n\n return {\n contentType,\n items: allItems.map((item) => stripEnvelope(item, this.maxDepth)),\n total,\n };\n }\n\n private async fetchAllAssets(): Promise<FetchResult> {\n const allItems: unknown[] = [];\n let skip = 0;\n let total = 0;\n\n do {\n const response = await withRetry<AssetCollection>(\n () => {\n this.apiUsage.recordCall();\n return this.client.getAssets({ limit: this.batchSize, skip });\n },\n this.retryConfig,\n );\n total = response.total;\n allItems.push(...response.items);\n skip += response.items.length;\n\n if (total > this.batchSize) {\n console.log(\n ` [contentful] asset: fetched ${allItems.length}/${total}`,\n );\n }\n } while (skip < total);\n\n return {\n contentType: 'asset',\n items: allItems.map((item) => stripEnvelope(item, this.maxDepth)),\n total,\n };\n }\n}\n","import type { RetryConfig } from '../config';\n\n/**\n * Inspects an error to determine if it represents an API rate-limit (HTTP 429).\n * Returns the suggested wait time in ms when available, otherwise `0` to signal\n * that the caller should fall back to computed backoff. Returns `null` when the\n * error is *not* a rate-limit error.\n */\nfunction rateLimitDelayMs(err: unknown): number | null {\n const e = err as Record<string, unknown>;\n\n if (e?.status === 429 || e?.statusCode === 429) {\n const reset = (e?.headers as Record<string, string> | undefined)?.[\n 'x-contentful-ratelimit-reset'\n ];\n return reset ? parseFloat(reset) * 1000 : 0;\n }\n\n const resp = e?.response as Record<string, unknown> | undefined;\n if (resp?.status === 429) {\n const headers = resp?.headers as Record<string, string> | undefined;\n const reset = headers?.['x-contentful-ratelimit-reset'];\n return reset ? parseFloat(reset) * 1000 : 0;\n }\n\n return null;\n}\n\nfunction computeDelay(\n attempt: number,\n baseDelayMs: number,\n maxDelayMs: number,\n): number {\n const exponential = baseDelayMs * Math.pow(2, attempt);\n const jitter = Math.random() * baseDelayMs;\n return Math.min(exponential + jitter, maxDelayMs);\n}\n\n/**\n * Executes `fn` with automatic retry + exponential backoff.\n * Rate-limit (429) responses are handled specially: if the API provides a\n * Retry-After / reset header, that value is respected instead of computed backoff.\n */\nexport async function withRetry<T>(\n fn: () => Promise<T>,\n { maxRetries, baseDelayMs, maxDelayMs }: RetryConfig,\n): Promise<T> {\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n return await fn();\n } catch (err) {\n if (attempt === maxRetries) throw err;\n\n const rlDelay = rateLimitDelayMs(err);\n let delay: number;\n\n if (rlDelay !== null) {\n delay =\n rlDelay > 0 ? rlDelay : computeDelay(attempt, baseDelayMs, maxDelayMs);\n console.warn(\n ` Rate limited (attempt ${attempt + 1}/${maxRetries}). ` +\n `Waiting ${Math.round(delay)}ms…`,\n );\n } else {\n delay = computeDelay(attempt, baseDelayMs, maxDelayMs);\n console.warn(\n ` Request failed (attempt ${attempt + 1}/${maxRetries}): ` +\n `${(err as Error).message}. Retrying in ${Math.round(delay)}ms…`,\n );\n }\n\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n }\n\n throw new Error('withRetry: unreachable');\n}\n","import { createClient, type SanityClient } from '@sanity/client';\nimport type { SanityConfig, RetryConfig } from '../config';\nimport type { CMSAdapter, FetchResult } from './types';\nimport { withRetry } from '../sync/retry';\n\nexport class SanityAdapter implements CMSAdapter {\n readonly name = 'sanity';\n private client: SanityClient;\n private retryConfig: RetryConfig;\n\n constructor(cfg: SanityConfig, retryConfig: RetryConfig) {\n this.client = createClient({\n projectId: cfg.projectId,\n dataset: cfg.dataset,\n token: cfg.token,\n apiVersion: cfg.apiVersion,\n useCdn: false,\n });\n this.retryConfig = retryConfig;\n }\n\n async getContentTypes(): Promise<string[]> {\n const types: string[] = await withRetry(\n () => this.client.fetch('array::unique(*[]._type)'),\n this.retryConfig,\n );\n return types.filter(\n (t) => !t.startsWith('system.') && !t.startsWith('sanity.'),\n );\n }\n\n async fetchAll(contentType: string): Promise<FetchResult> {\n const items: unknown[] = await withRetry(\n () => this.client.fetch('*[_type == $type]', { type: contentType }),\n this.retryConfig,\n );\n\n console.log(` [sanity] ${contentType}: fetched ${items.length} items`);\n return { contentType, items, total: items.length };\n }\n}\n","import { config, type CMSProvider } from '../config';\nimport type { CMSAdapter } from './types';\nimport { ContentfulAdapter } from './contentful';\nimport { SanityAdapter } from './sanity';\n\nexport function createAdapter(cms: CMSProvider): CMSAdapter {\n switch (cms) {\n case 'contentful':\n return new ContentfulAdapter(config.contentful, config.retry);\n case 'sanity':\n return new SanityAdapter(config.sanity, config.retry);\n default:\n throw new Error(`Unknown CMS provider: ${cms as string}`);\n }\n}\n\nexport type { CMSAdapter, FetchResult } from './types';\n","import { config } from '../config';\nimport type { LingohubResource } from '../../shared/lingohub';\n\nconst cfg = config.lingohub;\nconst apiUrl = 'https://api.lingohub.com/v1/' + cfg.workspace + '/projects/';\n\n/**\n * Downloads the raw Lingohub resource body (exact bytes as UTF-8 text).\n * Sync uploads this unmodified to S3; conversion happens at fetch time.\n */\nexport async function fetchLingohubResourceRaw(\n project: string,\n resource: LingohubResource,\n locale: string,\n): Promise<string> {\n const urlForResourceLocalised =\n `${apiUrl}${project}/resources/${resource.fileName}?auth_token=${cfg.authToken}`.replace(\n '[locale]',\n locale,\n );\n const res = await fetch(urlForResourceLocalised, { method: 'GET' });\n if (!res.ok) {\n throw new Error(`Failed to fetch resource \\`${resource.fileName}\\` (${locale}): ${res.status} - ${res.statusText}`);\n }\n return await res.text();\n}\n","import type { ContentfulApiUsage } from '../adapters/contentful-api-usage';\nimport { summariseContentfulApiUsage } from '../adapters/contentful-api-usage';\nimport type { CMSProvider } from '../config';\nimport { config } from '../config';\nimport { createAdapter } from '../adapters';\nimport {buildCmsObjectKey, buildTranslationObjectKey, ContentStore} from '../../shared/s3';\nimport { allProjects, defaultLocales } from '../../shared/lingohub';\nimport { fetchLingohubResourceRaw } from '../adapters/lingohub';\nimport { contentTypeForTranslationKey } from '../../shared/translationResource';\nimport { withRetry } from './retry';\n\nexport interface CmsSyncResultEntry {\n contentType: string;\n itemCount: number;\n objectKey: string;\n}\n\nexport interface CmsSyncResult {\n cms: CMSProvider;\n timestamp: number;\n entries: CmsSyncResultEntry[];\n errors: Array<{ contentType: string; error: string }>;\n /** Present when `cms` is `contentful`; counts each Contentful SDK HTTP request in this run. */\n contentfulApiUsage?: ContentfulApiUsage;\n}\n\nexport interface TranslationSyncResultEntry {\n project: string;\n resource: string;\n locale: string;\n /** UTF-8 byte size of the raw Lingohub file uploaded to S3. */\n itemCount: number;\n objectKey: string;\n}\n\nexport interface TranslationSyncResult {\n timestamp: number;\n entries: TranslationSyncResultEntry[];\n errors: Array<{ locale: string; project: string, error: string }>;\n}\n\nexport function summariseCmsEntries(result: CmsSyncResult): string[] {\n return result.entries.map(\n (e) => `• \\`${e.contentType}\\` — ${e.itemCount} items`,\n );\n}\n\nexport function summariseCmsErrors(result: CmsSyncResult): string[] {\n return result.errors.map(\n (e) => `• \\`${e.contentType}\\` — ${e.error}`,\n );\n}\n\n/** Slack-style lines for Contentful CDA/CPA/CMA request totals (empty when not Contentful). */\nexport function summariseCmsContentfulApiUsage(result: CmsSyncResult): string[] {\n if (!result.contentfulApiUsage) {\n return [];\n }\n return summariseContentfulApiUsage(result.contentfulApiUsage);\n}\n\n/** Group translation sync entries into one summary line per project/resource. */\nexport function summariseTranslationEntries(entries: TranslationSyncResultEntry[]): string[] {\n const grouped = new Map<string, { locales: number; bytes: number }>();\n for (const e of entries) {\n const key = `${e.project} / ${e.resource}`;\n const existing = grouped.get(key);\n if (existing) {\n existing.locales += 1;\n existing.bytes += e.itemCount;\n } else {\n grouped.set(key, { locales: 1, bytes: e.itemCount });\n }\n }\n return [...grouped.entries()].map(\n ([key, { locales, bytes }]) => `• \\`${key}\\` / [${locales} locale${locales === 1 ? '' : 's'}] — ${bytes} bytes`,\n );\n}\n\nexport async function runSync(cms: CMSProvider, contentTypes?: string[], includeLevels?: number){\n await syncCmsContent(cms, contentTypes, includeLevels )\n}\n\nexport async function syncCmsContent(\n cms: CMSProvider,\n contentTypes?: string[],\n includeLevels?: number\n): Promise<CmsSyncResult> {\n const adapter = createAdapter(cms);\n const store = new ContentStore(config.s3);\n const timestamp = Math.floor(Date.now() / 1000);\n\n console.log(`\\nStarting sync from ${cms} at ${new Date(timestamp * 1000).toISOString()}`);\n\n const typesToSync =\n contentTypes && contentTypes.length > 0\n ? contentTypes\n : await adapter.getContentTypes();\n\n console.log(`Content types to sync: ${typesToSync.join(', ')}\\n`);\n\n const entries: CmsSyncResultEntry[] = [];\n const errors: Array<{ contentType: string; error: string }> = [];\n\n for (const contentType of typesToSync) {\n try {\n const result = await adapter.fetchAll(contentType, includeLevels);\n const objectKey = buildCmsObjectKey(cms, contentType);\n await store.upload(objectKey, result.items);\n\n entries.push({\n contentType,\n itemCount: result.total,\n objectKey,\n });\n\n console.log(\n ` + ${contentType}: ${result.total} items -> ${objectKey}`,\n );\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n errors.push({ contentType, error: message });\n console.error(` x ${contentType}: ${message}`);\n }\n }\n\n const contentfulApiUsage = adapter.getContentfulApiUsage?.();\n\n if (contentfulApiUsage) {\n console.log(\n `\\nContentful API calls: ${summariseContentfulApiUsage(contentfulApiUsage).join(', ')}`,\n );\n }\n\n console.log(\n `\\nSync complete: ${entries.length} succeeded, ${errors.length} failed\\n`,\n );\n\n return { cms, timestamp, entries, errors, contentfulApiUsage };\n}\n\nexport async function syncTranslations(projects?: string[], locales?:string[]):Promise<TranslationSyncResult> {\n\n const store = new ContentStore(config.s3);\n const entries: TranslationSyncResultEntry[] = [];\n const errors: Array<{ project: string; locale: string, error: string }> = [];\n const timestamp = Math.floor(Date.now() / 1000);\n if(!locales){\n locales = defaultLocales;\n }\n if(!projects){\n projects = Object.keys(allProjects);\n }\n\n for(const project of projects) {\n const resources = allProjects[project];\n if(!resources){\n console.error(`No resources found for ${project}`);\n continue;\n }\n for(const resource of resources) {\n for(const loc of locales){\n const locale = (resource.localeMapping && resource.localeMapping[loc]) ? resource.localeMapping[loc] : loc;\n try {\n const raw = await withRetry(\n () => fetchLingohubResourceRaw(project, resource, locale),\n config.retry,\n );\n const objectKey = buildTranslationObjectKey(\n project,\n resource.fileName,\n locale,\n );\n await store.uploadRaw(\n objectKey,\n raw,\n contentTypeForTranslationKey(objectKey),\n );\n const byteLength = Buffer.byteLength(raw, 'utf8');\n entries.push({\n project,\n resource: resource.resource,\n locale,\n itemCount: byteLength,\n objectKey,\n });\n\n console.log(\n ` + ${project} - ${locale}: ${byteLength} bytes -> ${objectKey}`,\n );\n }catch(err){\n const message = err instanceof Error ? err.message : String(err);\n errors.push({ project,locale, error: message });\n console.error(` x ${project} - ${locale}: ${message}`);\n }\n }\n }\n }\n\n return { timestamp, entries, errors };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAOO,IAAM,4BAAqD;AAAA,EAChE;AAAA,EACA;AAAA,EACA;AACF;;;ACJO,IAAM,oBAAN,MAAwB;AAAA,EAG7B,YAA6BA,SAAiC;AAAjC,kBAAAA;AAC3B,UAAM,MAAMA,QAA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OAAO;AACtC;","names":["config","config","config","result","cfg","createClient","cfg","createClient","config","config","config"]}
@@ -14,7 +14,7 @@ import {
14
14
  import {
15
15
  allProjects,
16
16
  defaultLocales
17
- } from "./chunk-RZLDRXNQ.js";
17
+ } from "./chunk-OWL72OTS.js";
18
18
 
19
19
  // src/shared/bundles.ts
20
20
  import fs from "fs/promises";
@@ -286,4 +286,4 @@ export {
286
286
  fetchMergedTranslationBundles,
287
287
  queryCmsBundle
288
288
  };
289
- //# sourceMappingURL=chunk-D723FMZ2.js.map
289
+ //# sourceMappingURL=chunk-QQDU3TVQ.js.map
@@ -4,16 +4,18 @@ import {
4
4
  config,
5
5
  formatPipelineRunSummary,
6
6
  isAzureDevOpsProjectKey,
7
+ notifyClientsAfterCmsSync,
8
+ summariseCmsContentfulApiUsage,
7
9
  summariseCmsEntries,
8
10
  summariseCmsErrors,
9
11
  summariseTranslationEntries,
10
12
  syncCmsContent,
11
13
  syncTranslations,
12
14
  triggerPipelineBuild
13
- } from "./chunk-U73PO7OV.js";
15
+ } from "./chunk-POJRKC4G.js";
14
16
  import {
15
17
  allProjects
16
- } from "./chunk-RZLDRXNQ.js";
18
+ } from "./chunk-OWL72OTS.js";
17
19
 
18
20
  // src/server/slack.ts
19
21
  import { App } from "@slack/bolt";
@@ -70,6 +72,24 @@ async function startSlackBot() {
70
72
  if (result.errors.length > 0) {
71
73
  blocks.push("", "*Errors:*", ...summariseCmsErrors(result));
72
74
  }
75
+ const apiUsageLines = summariseCmsContentfulApiUsage(result);
76
+ if (apiUsageLines.length > 0) {
77
+ blocks.push("", ...apiUsageLines);
78
+ }
79
+ const refreshResults = await notifyClientsAfterCmsSync(
80
+ result,
81
+ contentTypes
82
+ );
83
+ if (refreshResults.length > 0) {
84
+ const ok = refreshResults.filter((r) => r.ok).map((r) => r.target);
85
+ const failed = refreshResults.filter((r) => !r.ok).map((r) => r.target);
86
+ if (ok.length > 0) {
87
+ blocks.push("", `*Content refresh:* notified \`${ok.join("`, `")}\``);
88
+ }
89
+ if (failed.length > 0) {
90
+ blocks.push(`*Content refresh failed:* \`${failed.join("`, `")}\``);
91
+ }
92
+ }
73
93
  await respond({ response_type: "in_channel", text: blocks.join("\n") });
74
94
  } catch (err) {
75
95
  const message = err instanceof Error ? err.message : String(err);
@@ -230,4 +250,4 @@ export {
230
250
  notifySlack,
231
251
  startSlackBot
232
252
  };
233
- //# sourceMappingURL=chunk-7I67676Y.js.map
253
+ //# sourceMappingURL=chunk-UQX4THTY.js.map