@squiz/dx-common-lib 1.72.3 → 1.72.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.npm/_logs/2026-09-08T06_40_25_662Z-debug-0.log +19 -0
  2. package/CHANGELOG.md +12 -0
  3. package/lib/cloudflare-api/CloudflareApiService.d.ts +16 -0
  4. package/lib/cloudflare-api/CloudflareApiService.js +45 -0
  5. package/lib/cloudflare-api/CloudflareApiService.js.map +1 -0
  6. package/lib/cloudflare-api/CloudflareApiService.spec.d.ts +1 -0
  7. package/lib/cloudflare-api/CloudflareApiService.spec.js +50 -0
  8. package/lib/cloudflare-api/CloudflareApiService.spec.js.map +1 -0
  9. package/lib/cloudflare-service-secret-key-service/getCloudflareServiceSecretService.d.ts +6 -0
  10. package/lib/cloudflare-service-secret-key-service/getCloudflareServiceSecretService.js +8 -0
  11. package/lib/cloudflare-service-secret-key-service/getCloudflareServiceSecretService.js.map +1 -0
  12. package/lib/index.d.ts +3 -0
  13. package/lib/index.js +3 -0
  14. package/lib/index.js.map +1 -1
  15. package/lib/outbound-http/createServiceUserAgent.d.ts +6 -0
  16. package/lib/outbound-http/createServiceUserAgent.js +13 -0
  17. package/lib/outbound-http/createServiceUserAgent.js.map +1 -0
  18. package/lib/outbound-http/createServiceUserAgent.spec.d.ts +1 -0
  19. package/lib/outbound-http/createServiceUserAgent.spec.js +12 -0
  20. package/lib/outbound-http/createServiceUserAgent.spec.js.map +1 -0
  21. package/lib/outbound-http/index.d.ts +2 -0
  22. package/lib/outbound-http/index.js +8 -0
  23. package/lib/outbound-http/index.js.map +1 -0
  24. package/lib/outbound-http/outboundHttp.d.ts +2 -0
  25. package/lib/outbound-http/outboundHttp.js +23 -0
  26. package/lib/outbound-http/outboundHttp.js.map +1 -0
  27. package/lib/outbound-http/outboundHttp.spec.d.ts +1 -0
  28. package/lib/outbound-http/outboundHttp.spec.js +59 -0
  29. package/lib/outbound-http/outboundHttp.spec.js.map +1 -0
  30. package/lib/stream/EventStreamHandler.d.ts +3 -2
  31. package/lib/stream/EventStreamHandler.js.map +1 -1
  32. package/package.json +3 -3
  33. package/src/cloudflare-api/CloudflareApiService.spec.ts +66 -0
  34. package/src/cloudflare-api/CloudflareApiService.ts +61 -0
  35. package/src/cloudflare-service-secret-key-service/getCloudflareServiceSecretService.ts +11 -0
  36. package/src/index.ts +3 -0
  37. package/src/outbound-http/createServiceUserAgent.spec.ts +11 -0
  38. package/src/outbound-http/createServiceUserAgent.ts +9 -0
  39. package/src/outbound-http/index.ts +2 -0
  40. package/src/outbound-http/outboundHttp.spec.ts +69 -0
  41. package/src/outbound-http/outboundHttp.ts +26 -0
  42. package/src/stream/EventStreamHandler.spec.ts +1 -1
  43. package/src/stream/EventStreamHandler.ts +4 -2
  44. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,19 @@
1
+ 0 verbose cli /usr/local/bin/node /usr/local/bin/npm
2
+ 1 info using npm@10.8.1
3
+ 2 info using node@v22.4.1
4
+ 3 silly config load:file:/usr/local/lib/node_modules/npm/npmrc
5
+ 4 info config found workspace root at /builds/developer-experience/cmp
6
+ 5 silly config load:file:/builds/developer-experience/cmp/.npmrc
7
+ 6 silly config load:file:/home/appuser/.npmrc
8
+ 7 silly config load:file:/usr/local/etc/npmrc
9
+ 8 verbose title npm run compile
10
+ 9 verbose argv "run" "compile"
11
+ 10 verbose logfile logs-max:10 dir:/builds/developer-experience/cmp/packages/dx-common-lib/.npm/_logs/2026-09-08T06_40_25_662Z-
12
+ 11 verbose logfile /builds/developer-experience/cmp/packages/dx-common-lib/.npm/_logs/2026-09-08T06_40_25_662Z-debug-0.log
13
+ 12 silly logfile done cleaning log files
14
+ 13 verbose cwd /builds/developer-experience/cmp/packages/dx-common-lib
15
+ 14 verbose os Linux 6.1.177-224.371.amzn2023.x86_64
16
+ 15 verbose node v22.4.1
17
+ 16 verbose npm v10.8.1
18
+ 17 verbose exit 0
19
+ 18 info ok
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.72.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 20857dc: Add option to delete the worker associated with the component when deleting the componentwq
8
+
9
+ ## 1.72.4
10
+
11
+ ### Patch Changes
12
+
13
+ - aa25b15: Force user-agent to be set for all requests, and fix session parsing bug
14
+
3
15
  ## 1.72.3
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,16 @@
1
+ import { CloudflareServiceSecretKeyService } from '../cloudflare-service-secret-key-service/getCloudflareServiceSecretService';
2
+ export interface CloudflareApiServiceInterface {
3
+ loadApiToken(): Promise<void>;
4
+ deleteDispatchScript(scriptName: string): Promise<void>;
5
+ }
6
+ export type CloudflareApiServiceConfig = {
7
+ accountId: string;
8
+ dispatchNamespace: string;
9
+ apiTokenService: CloudflareServiceSecretKeyService;
10
+ };
11
+ export declare class CloudflareApiService implements CloudflareApiServiceInterface {
12
+ private readonly config;
13
+ constructor(config: CloudflareApiServiceConfig);
14
+ loadApiToken(): Promise<void>;
15
+ deleteDispatchScript(scriptName: string): Promise<void>;
16
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudflareApiService = void 0;
4
+ class CloudflareApiService {
5
+ constructor(config) {
6
+ this.config = config;
7
+ }
8
+ async loadApiToken() {
9
+ await this.config.apiTokenService.loadSecretKey();
10
+ }
11
+ async deleteDispatchScript(scriptName) {
12
+ var _a, _b, _c;
13
+ const apiToken = this.config.apiTokenService.getSecretKey();
14
+ if (!apiToken) {
15
+ throw new Error('Cloudflare API token is not loaded');
16
+ }
17
+ const { accountId, dispatchNamespace } = this.config;
18
+ if (!accountId || !dispatchNamespace) {
19
+ throw new Error('Cloudflare account ID and dispatch namespace must be configured');
20
+ }
21
+ const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/workers/dispatch/namespaces/${dispatchNamespace}/scripts/${encodeURIComponent(scriptName)}`;
22
+ const response = await fetch(url, {
23
+ method: 'DELETE',
24
+ headers: {
25
+ Authorization: `Bearer ${apiToken}`,
26
+ },
27
+ });
28
+ if (response.status === 404) {
29
+ return;
30
+ }
31
+ if (!response.ok) {
32
+ let message = response.statusText;
33
+ try {
34
+ const body = (await response.json());
35
+ message = (_c = (_b = (_a = body.errors) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : message;
36
+ }
37
+ catch {
38
+ // use statusText when response body is not JSON
39
+ }
40
+ throw new Error(`Failed to delete Cloudflare dispatch script: ${message}`);
41
+ }
42
+ }
43
+ }
44
+ exports.CloudflareApiService = CloudflareApiService;
45
+ //# sourceMappingURL=CloudflareApiService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CloudflareApiService.js","sourceRoot":"","sources":["../../src/cloudflare-api/CloudflareApiService.ts"],"names":[],"mappings":";;;AAiBA,MAAa,oBAAoB;IAC/B,YAA6B,MAAkC;QAAlC,WAAM,GAAN,MAAM,CAA4B;IAAG,CAAC;IAEnE,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,UAAkB;;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,YAAY,EAAE,CAAC;QAC5D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC;QACrD,IAAI,CAAC,SAAS,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;QACrF,CAAC;QAED,MAAM,GAAG,GAAG,iDAAiD,SAAS,gCAAgC,iBAAiB,YAAY,kBAAkB,CACnJ,UAAU,CACX,EAAE,CAAC;QACJ,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,QAAQ;YAChB,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,QAAQ,EAAE;aACpC;SACF,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC5B,OAAO;QACT,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,IAAI,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC;YAClC,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA+B,CAAC;gBACnE,OAAO,GAAG,MAAA,MAAA,MAAA,IAAI,CAAC,MAAM,0CAAG,CAAC,CAAC,0CAAE,OAAO,mCAAI,OAAO,CAAC;YACjD,CAAC;YAAC,MAAM,CAAC;gBACP,gDAAgD;YAClD,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,gDAAgD,OAAO,EAAE,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;CACF;AA3CD,oDA2CC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const CloudflareApiService_1 = require("./CloudflareApiService");
4
+ describe('CloudflareApiService', () => {
5
+ const apiTokenService = {
6
+ loadSecretKey: jest.fn().mockResolvedValue(undefined),
7
+ getSecretKey: jest.fn().mockReturnValue('cloudflare-api-token'),
8
+ };
9
+ let service;
10
+ beforeEach(() => {
11
+ jest.mocked(apiTokenService.getSecretKey).mockReturnValue('cloudflare-api-token');
12
+ service = new CloudflareApiService_1.CloudflareApiService({
13
+ accountId: 'account-id',
14
+ dispatchNamespace: 'cmp_development',
15
+ apiTokenService,
16
+ });
17
+ jest.spyOn(global, 'fetch').mockReset();
18
+ });
19
+ afterEach(() => {
20
+ jest.restoreAllMocks();
21
+ });
22
+ it('loads the API token from the secret service', async () => {
23
+ await service.loadApiToken();
24
+ expect(apiTokenService.loadSecretKey).toHaveBeenCalled();
25
+ });
26
+ it('deletes a dispatch namespace script from the Cloudflare API', async () => {
27
+ jest.spyOn(global, 'fetch').mockResolvedValue({ ok: true, status: 200 });
28
+ await service.deleteDispatchScript('tenant__namespace__component__1.0.0');
29
+ expect(fetch).toHaveBeenCalledWith('https://api.cloudflare.com/client/v4/accounts/account-id/workers/dispatch/namespaces/cmp_development/scripts/tenant__namespace__component__1.0.0', {
30
+ method: 'DELETE',
31
+ headers: {
32
+ Authorization: 'Bearer cloudflare-api-token',
33
+ },
34
+ });
35
+ });
36
+ it('treats a 404 response as already deleted', async () => {
37
+ jest.spyOn(global, 'fetch').mockResolvedValue({ ok: false, status: 404, statusText: 'Not Found' });
38
+ await expect(service.deleteDispatchScript('missing-script')).resolves.toBeUndefined();
39
+ });
40
+ it('throws when the Cloudflare API returns an error', async () => {
41
+ jest.spyOn(global, 'fetch').mockResolvedValue({
42
+ ok: false,
43
+ status: 500,
44
+ statusText: 'Internal Server Error',
45
+ json: async () => ({ errors: [{ message: 'Delete failed' }] }),
46
+ });
47
+ await expect(service.deleteDispatchScript('tenant__namespace__component__1.0.0')).rejects.toThrow('Failed to delete Cloudflare dispatch script: Delete failed');
48
+ });
49
+ });
50
+ //# sourceMappingURL=CloudflareApiService.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CloudflareApiService.spec.js","sourceRoot":"","sources":["../../src/cloudflare-api/CloudflareApiService.spec.ts"],"names":[],"mappings":";;AAAA,iEAA8D;AAG9D,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,MAAM,eAAe,GAAsC;QACzD,aAAa,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC;QACrD,YAAY,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,s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C,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,EAAc,CAAC,CAAC;QAE/G,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;IACxF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iDAAiD,EAAE,KAAK,IAAI,EAAE;QAC/D,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,iBAAiB,CAAC;YAC5C,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,GAAG;YACX,UAAU,EAAE,uBAAuB;YACnC,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;SACnD,CAAC,CAAC;QAEf,MAAM,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,qCAAqC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAC/F,4DAA4D,CAC7D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { EdgeComponentsSecretKeyService } from '../edge-components-secret-key-service/EdgeComponentsSecretKeyService';
2
+ export type CloudflareServiceSecretKeyService = EdgeComponentsSecretKeyService;
3
+ export declare function getCloudflareServiceSecretService(config: {
4
+ secretName?: string;
5
+ secretValue?: string;
6
+ }): CloudflareServiceSecretKeyService;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCloudflareServiceSecretService = getCloudflareServiceSecretService;
4
+ const getEdgeComponentsSecretService_1 = require("../edge-components-secret-key-service/getEdgeComponentsSecretService");
5
+ function getCloudflareServiceSecretService(config) {
6
+ return (0, getEdgeComponentsSecretService_1.getEdgeComponentsSecretService)(config);
7
+ }
8
+ //# sourceMappingURL=getCloudflareServiceSecretService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCloudflareServiceSecretService.js","sourceRoot":"","sources":["../../src/cloudflare-service-secret-key-service/getCloudflareServiceSecretService.ts"],"names":[],"mappings":";;AAKA,8EAKC;AATD,yHAAsH;AAItH,SAAgB,iCAAiC,CAAC,MAGjD;IACC,OAAO,IAAA,+DAA8B,EAAC,MAAM,CAAC,CAAC;AAChD,CAAC"}
package/lib/index.d.ts CHANGED
@@ -14,6 +14,8 @@ export * from './edge-components-secret-key-service/DevelopmentEdgeComponentsSec
14
14
  export * from './edge-components-secret-key-service/ProductionEdgeComponentsSecretKeyService';
15
15
  export * from './edge-components-secret-key-service/EdgeComponentsSecretKeyService';
16
16
  export * from './edge-components-secret-key-service/getEdgeComponentsSecretService';
17
+ export * from './cloudflare-service-secret-key-service/getCloudflareServiceSecretService';
18
+ export * from './cloudflare-api/CloudflareApiService';
17
19
  export * from './esi-mac-token-generator/EsiMacTokenGenerator';
18
20
  export * from './secret-api-key-service/SecretApiKeyService';
19
21
  export * from './secret-api-key-service/DevSecretApiKeyService';
@@ -21,3 +23,4 @@ export * from './secret-api-key-service/getSecretApiKeyService';
21
23
  export * from './events/EventBusService';
22
24
  export * from './stream/EventStreamHandler';
23
25
  export * from './stream/StreamUtils';
26
+ export * from './outbound-http';
package/lib/index.js CHANGED
@@ -30,6 +30,8 @@ __exportStar(require("./edge-components-secret-key-service/DevelopmentEdgeCompon
30
30
  __exportStar(require("./edge-components-secret-key-service/ProductionEdgeComponentsSecretKeyService"), exports);
31
31
  __exportStar(require("./edge-components-secret-key-service/EdgeComponentsSecretKeyService"), exports);
32
32
  __exportStar(require("./edge-components-secret-key-service/getEdgeComponentsSecretService"), exports);
33
+ __exportStar(require("./cloudflare-service-secret-key-service/getCloudflareServiceSecretService"), exports);
34
+ __exportStar(require("./cloudflare-api/CloudflareApiService"), exports);
33
35
  __exportStar(require("./esi-mac-token-generator/EsiMacTokenGenerator"), exports);
34
36
  __exportStar(require("./secret-api-key-service/SecretApiKeyService"), exports);
35
37
  __exportStar(require("./secret-api-key-service/DevSecretApiKeyService"), exports);
@@ -37,4 +39,5 @@ __exportStar(require("./secret-api-key-service/getSecretApiKeyService"), exports
37
39
  __exportStar(require("./events/EventBusService"), exports);
38
40
  __exportStar(require("./stream/EventStreamHandler"), exports);
39
41
  __exportStar(require("./stream/StreamUtils"), exports);
42
+ __exportStar(require("./outbound-http"), exports);
40
43
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0CAAwB;AACxB,yCAAuB;AACvB,qDAAmC;AACnC,iEAA+C;AAC/C,+DAA6C;AAC7C,+EAA6D;AAC7D,+EAA6D;AAC7D,gFAA8D;AAC9D,wEAAsD;AACtD,0CAAwB;AACxB,+CAA6B;AAC7B,iHAA+F;AAC/F,gHAA8F;AAC9F,sGAAoF;AACpF,sGAAoF;AACpF,iFAA+D;AAC/D,+EAA6D;AAC7D,kFAAgE;AAChE,kFAAgE;AAChE,2DAAyC;AACzC,8DAA4C;AAC5C,uDAAqC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0CAAwB;AACxB,yCAAuB;AACvB,qDAAmC;AACnC,iEAA+C;AAC/C,+DAA6C;AAC7C,+EAA6D;AAC7D,+EAA6D;AAC7D,gFAA8D;AAC9D,wEAAsD;AACtD,0CAAwB;AACxB,+CAA6B;AAC7B,iHAA+F;AAC/F,gHAA8F;AAC9F,sGAAoF;AACpF,sGAAoF;AACpF,4GAA0F;AAC1F,wEAAsD;AACtD,iFAA+D;AAC/D,+EAA6D;AAC7D,kFAAgE;AAChE,kFAAgE;AAChE,2DAAyC;AACzC,8DAA4C;AAC5C,uDAAqC;AACrC,kDAAgC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Builds a User-Agent string for outbound service-to-service HTTP requests.
3
+ *
4
+ * @param serviceName Service identifier, e.g. `content-api` or `@squiz/content-api`
5
+ */
6
+ export declare function createServiceUserAgent(serviceName: string): string;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createServiceUserAgent = createServiceUserAgent;
4
+ /**
5
+ * Builds a User-Agent string for outbound service-to-service HTTP requests.
6
+ *
7
+ * @param serviceName Service identifier, e.g. `content-api` or `@squiz/content-api`
8
+ */
9
+ function createServiceUserAgent(serviceName) {
10
+ const name = serviceName.replace(/^@squiz\//, '');
11
+ return `Squiz/${name}`;
12
+ }
13
+ //# sourceMappingURL=createServiceUserAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServiceUserAgent.js","sourceRoot":"","sources":["../../src/outbound-http/createServiceUserAgent.ts"],"names":[],"mappings":";;AAKA,wDAGC;AARD;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,WAAmB;IACxD,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAClD,OAAO,SAAS,IAAI,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const createServiceUserAgent_1 = require("./createServiceUserAgent");
4
+ describe('createServiceUserAgent', () => {
5
+ it('returns Squiz/<name> for a scoped package name', () => {
6
+ expect((0, createServiceUserAgent_1.createServiceUserAgent)('@squiz/content-api')).toBe('Squiz/content-api');
7
+ });
8
+ it('returns Squiz/<name> for an unscoped service name', () => {
9
+ expect((0, createServiceUserAgent_1.createServiceUserAgent)('content-api')).toBe('Squiz/content-api');
10
+ });
11
+ });
12
+ //# sourceMappingURL=createServiceUserAgent.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServiceUserAgent.spec.js","sourceRoot":"","sources":["../../src/outbound-http/createServiceUserAgent.spec.ts"],"names":[],"mappings":";;AAAA,qEAAkE;AAElE,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,IAAA,+CAAsB,EAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,CAAC,IAAA,+CAAsB,EAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createServiceUserAgent } from './createServiceUserAgent';
2
+ export { outboundFetch, type OutboundFetchInput } from './outboundHttp';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.outboundFetch = exports.createServiceUserAgent = void 0;
4
+ var createServiceUserAgent_1 = require("./createServiceUserAgent");
5
+ Object.defineProperty(exports, "createServiceUserAgent", { enumerable: true, get: function () { return createServiceUserAgent_1.createServiceUserAgent; } });
6
+ var outboundHttp_1 = require("./outboundHttp");
7
+ Object.defineProperty(exports, "outboundFetch", { enumerable: true, get: function () { return outboundHttp_1.outboundFetch; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/outbound-http/index.ts"],"names":[],"mappings":";;;AAAA,mEAAkE;AAAzD,gIAAA,sBAAsB,OAAA;AAC/B,+CAAwE;AAA/D,6GAAA,aAAa,OAAA"}
@@ -0,0 +1,2 @@
1
+ export type OutboundFetchInput = string | URL | Request;
2
+ export declare function outboundFetch(userAgent: string, input: OutboundFetchInput, init?: RequestInit): Promise<Response>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.outboundFetch = outboundFetch;
4
+ function buildOutboundHeaders(userAgent, input, init) {
5
+ const headers = new Headers();
6
+ if (input instanceof Request) {
7
+ input.headers.forEach((value, key) => {
8
+ headers.set(key, value);
9
+ });
10
+ }
11
+ if (init === null || init === void 0 ? void 0 : init.headers) {
12
+ new Headers(init.headers).forEach((value, key) => {
13
+ headers.set(key, value);
14
+ });
15
+ }
16
+ headers.set('User-Agent', userAgent);
17
+ return headers;
18
+ }
19
+ function outboundFetch(userAgent, input, init) {
20
+ const headers = buildOutboundHeaders(userAgent, input, init);
21
+ return fetch(input, { ...init, headers });
22
+ }
23
+ //# sourceMappingURL=outboundHttp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outboundHttp.js","sourceRoot":"","sources":["../../src/outbound-http/outboundHttp.ts"],"names":[],"mappings":";;AAsBA,sCAGC;AAvBD,SAAS,oBAAoB,CAAC,SAAiB,EAAE,KAAyB,EAAE,IAAkB;IAC5F,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,IAAI,KAAK,YAAY,OAAO,EAAE,CAAC;QAC7B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YACnC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,EAAE,CAAC;QAClB,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC/C,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IAErC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAgB,aAAa,CAAC,SAAiB,EAAE,KAAyB,EAAE,IAAkB;IAC5F,MAAM,OAAO,GAAG,oBAAoB,CAAC,SAAS,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC7D,OAAO,KAAK,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5C,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const outboundHttp_1 = require("./outboundHttp");
4
+ describe('outboundFetch', () => {
5
+ const userAgent = 'Squiz/test-service';
6
+ const originalFetch = global.fetch;
7
+ beforeEach(() => {
8
+ global.fetch = jest.fn().mockResolvedValue(new Response());
9
+ });
10
+ afterEach(() => {
11
+ global.fetch = originalFetch;
12
+ });
13
+ it('adds User-Agent to string URL requests with init headers', async () => {
14
+ await (0, outboundHttp_1.outboundFetch)(userAgent, 'https://example.com/resource', {
15
+ headers: { 'x-api-key': 'secret' },
16
+ });
17
+ const init = global.fetch.mock.calls[0][1];
18
+ const headers = init.headers;
19
+ expect(headers.get('x-api-key')).toBe('secret');
20
+ expect(headers.get('User-Agent')).toBe(userAgent);
21
+ });
22
+ it('preserves headers from a Request input and adds User-Agent', async () => {
23
+ const request = new Request('https://example.com/resource', {
24
+ method: 'GET',
25
+ headers: {
26
+ Authorization: 'Bearer token',
27
+ 'x-dxp-tenant': 'tenant-1',
28
+ },
29
+ });
30
+ await (0, outboundHttp_1.outboundFetch)(userAgent, request);
31
+ const init = global.fetch.mock.calls[0][1];
32
+ const headers = init.headers;
33
+ expect(headers.get('Authorization')).toBe('Bearer token');
34
+ expect(headers.get('x-dxp-tenant')).toBe('tenant-1');
35
+ expect(headers.get('User-Agent')).toBe(userAgent);
36
+ });
37
+ it('merges init headers on top of Request headers without dropping existing values', async () => {
38
+ const request = new Request('https://example.com/resource', {
39
+ headers: { 'x-api-key': 'from-request' },
40
+ });
41
+ await (0, outboundHttp_1.outboundFetch)(userAgent, request, {
42
+ headers: { 'x-dxp-session': 'session-token' },
43
+ });
44
+ const init = global.fetch.mock.calls[0][1];
45
+ const headers = init.headers;
46
+ expect(headers.get('x-api-key')).toBe('from-request');
47
+ expect(headers.get('x-dxp-session')).toBe('session-token');
48
+ expect(headers.get('User-Agent')).toBe(userAgent);
49
+ });
50
+ it('Overrides an explicit User-Agent header', async () => {
51
+ await (0, outboundHttp_1.outboundFetch)(userAgent, 'https://example.com/resource', {
52
+ headers: { 'User-Agent': 'custom-agent' },
53
+ });
54
+ const init = global.fetch.mock.calls[0][1];
55
+ const headers = init.headers;
56
+ expect(headers.get('User-Agent')).toBe(userAgent);
57
+ });
58
+ });
59
+ //# sourceMappingURL=outboundHttp.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outboundHttp.spec.js","sourceRoot":"","sources":["../../src/outbound-http/outboundHttp.spec.ts"],"names":[],"mappings":";;AAAA,iDAA+C;AAE/C,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,MAAM,SAAS,GAAG,oBAAoB,CAAC;IACvC,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC;IAEnC,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,CAAC,KAAK,GAAG,aAAa,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;QACxE,MAAM,IAAA,4BAAa,EAAC,SAAS,EAAE,8BAA8B,EAAE;YAC7D,OAAO,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE;SACnC,CAAC,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Reserved.
4
4
  */
5
- import { DynamoDBStreamEvent, DynamoDBRecord, Context, DynamoDBBatchResponse } from 'aws-lambda';
5
+ import type { DynamoDBStreamEvent, DynamoDBRecord, Context, DynamoDBBatchResponse } from 'aws-lambda';
6
6
  import { Logger } from '@squiz/dx-logger-lib';
7
7
  import { EventBusService } from '../events/EventBusService';
8
8
  export interface EventPayload {
@@ -12,6 +12,7 @@ export interface EventPayload {
12
12
  export type EventMapper = (record: DynamoDBRecord) => Promise<EventPayload[]>;
13
13
  /** Resolves tenant id for publishing; use `record` when tenant is carried on the item rather than derivable from the table ARN. */
14
14
  export type ExtractTenantId = (arn: string, tableServiceIdentifier: string, record: DynamoDBRecord) => string;
15
+ export type EventStreamHandler = (event: DynamoDBStreamEvent, context: Context) => Promise<DynamoDBBatchResponse>;
15
16
  interface EventStreamHandlerConfig<T extends string> {
16
17
  logger: Logger;
17
18
  eventBusService: EventBusService;
@@ -34,5 +35,5 @@ interface EventStreamHandlerConfig<T extends string> {
34
35
  * - Batch event publishing with retry tracking
35
36
  * - Failure reporting for Lambda retry mechanism
36
37
  */
37
- export declare function createEventStreamHandler<T extends string>(config: EventStreamHandlerConfig<T>): (event: DynamoDBStreamEvent, context: Context) => Promise<DynamoDBBatchResponse>;
38
+ export declare function createEventStreamHandler<T extends string>(config: EventStreamHandlerConfig<T>): EventStreamHandler;
38
39
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"EventStreamHandler.js","sourceRoot":"","sources":["../../src/stream/EventStreamHandler.ts"],"names":[],"mappings":";;AAgDA,4DA+IC;AA3JD;;;;;;;;;;;GAWG;AACH,SAAgB,wBAAwB,CAAmB,MAAmC;IAC5F,MAAM,EACJ,MAAM,EACN,eAAe,EACf,sBAAsB,EACtB,mBAAmB,EACnB,OAAO,EACP,eAAe,EACf,SAAS,GAAG,EAAE,GACf,GAAG,MAAM,CAAC;IAEX,SAAS,iBAAiB,CAAC,MAAsB;;QAC/C,MAAM,EAAE,GAAG,MAAA,MAAA,MA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ACH,CAAC,CAAC,CACH,CAAC;QAEF,MAAM,iBAAiB,GAAsC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAC9F,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;YACnB,cAAc,EAAE,cAAc;SAC/B,CAAC,CACH,CAAC;QAEF,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE;YACvC,YAAY,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM;YAClC,aAAa,EAAE,iBAAiB,CAAC,MAAM;YACvC,OAAO,EAAE,sBAAsB;SAChC,CAAC,CAAC;QAEH,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dx-common-lib",
3
- "version": "1.72.3",
3
+ "version": "1.72.5",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "private": false,
@@ -16,7 +16,7 @@
16
16
  "author": "",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
- "@aws-sdk/client-secrets-manager": "^3.946.0",
19
+ "@aws-sdk/client-secrets-manager": "^3.1057.0",
20
20
  "@squiz/dx-logger-lib": "^1.65.1",
21
21
  "archiver": "7.0.1",
22
22
  "escape-string-regexp": "4.0.0",
@@ -26,12 +26,12 @@
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/archiver": "6.0.3",
29
+ "@types/aws-lambda": "^8.10.161",
29
30
  "@types/express": "4.17.23",
30
31
  "@types/fs-extra": "11.0.1",
31
32
  "@types/jest": "28.1.8",
32
33
  "@types/lodash.clonedeep": "4.5.9",
33
34
  "@types/node": "22.10.5",
34
- "aws-lambda": "^1.0.7",
35
35
  "dotenv": "16.6.1",
36
36
  "jest": "29.4.1",
37
37
  "ts-jest": "29.0.5",
@@ -0,0 +1,66 @@
1
+ import { CloudflareApiService } from './CloudflareApiService';
2
+ import { CloudflareServiceSecretKeyService } from '../cloudflare-service-secret-key-service/getCloudflareServiceSecretService';
3
+
4
+ describe('CloudflareApiService', () => {
5
+ const apiTokenService: CloudflareServiceSecretKeyService = {
6
+ loadSecretKey: jest.fn().mockResolvedValue(undefined),
7
+ getSecretKey: jest.fn().mockReturnValue('cloudflare-api-token'),
8
+ };
9
+
10
+ let service: CloudflareApiService;
11
+
12
+ beforeEach(() => {
13
+ jest.mocked(apiTokenService.getSecretKey).mockReturnValue('cloudflare-api-token');
14
+ service = new CloudflareApiService({
15
+ accountId: 'account-id',
16
+ dispatchNamespace: 'cmp_development',
17
+ apiTokenService,
18
+ });
19
+ jest.spyOn(global, 'fetch').mockReset();
20
+ });
21
+
22
+ afterEach(() => {
23
+ jest.restoreAllMocks();
24
+ });
25
+
26
+ it('loads the API token from the secret service', async () => {
27
+ await service.loadApiToken();
28
+
29
+ expect(apiTokenService.loadSecretKey).toHaveBeenCalled();
30
+ });
31
+
32
+ it('deletes a dispatch namespace script from the Cloudflare API', async () => {
33
+ jest.spyOn(global, 'fetch').mockResolvedValue({ ok: true, status: 200 } as Response);
34
+
35
+ await service.deleteDispatchScript('tenant__namespace__component__1.0.0');
36
+
37
+ expect(fetch).toHaveBeenCalledWith(
38
+ 'https://api.cloudflare.com/client/v4/accounts/account-id/workers/dispatch/namespaces/cmp_development/scripts/tenant__namespace__component__1.0.0',
39
+ {
40
+ method: 'DELETE',
41
+ headers: {
42
+ Authorization: 'Bearer cloudflare-api-token',
43
+ },
44
+ },
45
+ );
46
+ });
47
+
48
+ it('treats a 404 response as already deleted', async () => {
49
+ jest.spyOn(global, 'fetch').mockResolvedValue({ ok: false, status: 404, statusText: 'Not Found' } as Response);
50
+
51
+ await expect(service.deleteDispatchScript('missing-script')).resolves.toBeUndefined();
52
+ });
53
+
54
+ it('throws when the Cloudflare API returns an error', async () => {
55
+ jest.spyOn(global, 'fetch').mockResolvedValue({
56
+ ok: false,
57
+ status: 500,
58
+ statusText: 'Internal Server Error',
59
+ json: async () => ({ errors: [{ message: 'Delete failed' }] }),
60
+ } as Response);
61
+
62
+ await expect(service.deleteDispatchScript('tenant__namespace__component__1.0.0')).rejects.toThrow(
63
+ 'Failed to delete Cloudflare dispatch script: Delete failed',
64
+ );
65
+ });
66
+ });
@@ -0,0 +1,61 @@
1
+ import { CloudflareServiceSecretKeyService } from '../cloudflare-service-secret-key-service/getCloudflareServiceSecretService';
2
+
3
+ export interface CloudflareApiServiceInterface {
4
+ loadApiToken(): Promise<void>;
5
+ deleteDispatchScript(scriptName: string): Promise<void>;
6
+ }
7
+
8
+ export type CloudflareApiServiceConfig = {
9
+ accountId: string;
10
+ dispatchNamespace: string;
11
+ apiTokenService: CloudflareServiceSecretKeyService;
12
+ };
13
+
14
+ type CloudflareApiErrorResponse = {
15
+ errors?: { message?: string }[];
16
+ };
17
+
18
+ export class CloudflareApiService implements CloudflareApiServiceInterface {
19
+ constructor(private readonly config: CloudflareApiServiceConfig) {}
20
+
21
+ async loadApiToken(): Promise<void> {
22
+ await this.config.apiTokenService.loadSecretKey();
23
+ }
24
+
25
+ async deleteDispatchScript(scriptName: string): Promise<void> {
26
+ const apiToken = this.config.apiTokenService.getSecretKey();
27
+ if (!apiToken) {
28
+ throw new Error('Cloudflare API token is not loaded');
29
+ }
30
+
31
+ const { accountId, dispatchNamespace } = this.config;
32
+ if (!accountId || !dispatchNamespace) {
33
+ throw new Error('Cloudflare account ID and dispatch namespace must be configured');
34
+ }
35
+
36
+ const url = `https://api.cloudflare.com/client/v4/accounts/${accountId}/workers/dispatch/namespaces/${dispatchNamespace}/scripts/${encodeURIComponent(
37
+ scriptName,
38
+ )}`;
39
+ const response = await fetch(url, {
40
+ method: 'DELETE',
41
+ headers: {
42
+ Authorization: `Bearer ${apiToken}`,
43
+ },
44
+ });
45
+
46
+ if (response.status === 404) {
47
+ return;
48
+ }
49
+
50
+ if (!response.ok) {
51
+ let message = response.statusText;
52
+ try {
53
+ const body = (await response.json()) as CloudflareApiErrorResponse;
54
+ message = body.errors?.[0]?.message ?? message;
55
+ } catch {
56
+ // use statusText when response body is not JSON
57
+ }
58
+ throw new Error(`Failed to delete Cloudflare dispatch script: ${message}`);
59
+ }
60
+ }
61
+ }
@@ -0,0 +1,11 @@
1
+ import { EdgeComponentsSecretKeyService } from '../edge-components-secret-key-service/EdgeComponentsSecretKeyService';
2
+ import { getEdgeComponentsSecretService } from '../edge-components-secret-key-service/getEdgeComponentsSecretService';
3
+
4
+ export type CloudflareServiceSecretKeyService = EdgeComponentsSecretKeyService;
5
+
6
+ export function getCloudflareServiceSecretService(config: {
7
+ secretName?: string;
8
+ secretValue?: string;
9
+ }): CloudflareServiceSecretKeyService {
10
+ return getEdgeComponentsSecretService(config);
11
+ }
package/src/index.ts CHANGED
@@ -14,6 +14,8 @@ export * from './edge-components-secret-key-service/DevelopmentEdgeComponentsSec
14
14
  export * from './edge-components-secret-key-service/ProductionEdgeComponentsSecretKeyService';
15
15
  export * from './edge-components-secret-key-service/EdgeComponentsSecretKeyService';
16
16
  export * from './edge-components-secret-key-service/getEdgeComponentsSecretService';
17
+ export * from './cloudflare-service-secret-key-service/getCloudflareServiceSecretService';
18
+ export * from './cloudflare-api/CloudflareApiService';
17
19
  export * from './esi-mac-token-generator/EsiMacTokenGenerator';
18
20
  export * from './secret-api-key-service/SecretApiKeyService';
19
21
  export * from './secret-api-key-service/DevSecretApiKeyService';
@@ -21,3 +23,4 @@ export * from './secret-api-key-service/getSecretApiKeyService';
21
23
  export * from './events/EventBusService';
22
24
  export * from './stream/EventStreamHandler';
23
25
  export * from './stream/StreamUtils';
26
+ export * from './outbound-http';