@financial-times/cp-content-pipeline-schema 2.2.0 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/lib/datasources/capi.d.ts +3 -2
- package/lib/datasources/capi.js +2 -2
- package/lib/datasources/capi.js.map +1 -1
- package/lib/datasources/instrumented.d.ts +5 -4
- package/lib/datasources/instrumented.js +27 -33
- package/lib/datasources/instrumented.js.map +1 -1
- package/lib/datasources/origami-image.d.ts +3 -2
- package/lib/datasources/origami-image.js +2 -2
- package/lib/datasources/origami-image.js.map +1 -1
- package/lib/datasources/twitter.d.ts +2 -2
- package/lib/datasources/twitter.js +2 -2
- package/lib/datasources/twitter.js.map +1 -1
- package/package.json +2 -2
- package/queries/article.graphql +3 -0
- package/src/datasources/capi.ts +5 -3
- package/src/datasources/instrumented.ts +44 -58
- package/src/datasources/origami-image.ts +8 -4
- package/src/datasources/twitter.ts +10 -4
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.2.2](https://github.com/Financial-Times/cp-content-pipeline/compare/cp-content-pipeline-schema-v2.2.1...cp-content-pipeline-schema-v2.2.2) (2024-03-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* retrieve indicators also when querying only a liveblogpost ([0c9da88](https://github.com/Financial-Times/cp-content-pipeline/commit/0c9da8885ec0b3052fbdd18ae3f77acf3c3582c3))
|
|
9
|
+
|
|
10
|
+
## [2.2.1](https://github.com/Financial-Times/cp-content-pipeline/compare/cp-content-pipeline-schema-v2.2.0...cp-content-pipeline-schema-v2.2.1) (2024-02-29)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* revert CPP-1702 fix datasource metrics when requests time out ([02f7aad](https://github.com/Financial-Times/cp-content-pipeline/commit/02f7aad09c42ae0c69d8a57f3b6520bb7e2f7909))
|
|
16
|
+
|
|
3
17
|
## [2.2.0](https://github.com/Financial-Times/cp-content-pipeline/compare/cp-content-pipeline-schema-v2.1.0...cp-content-pipeline-schema-v2.2.0) (2024-02-29)
|
|
4
18
|
|
|
5
19
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { WillSendRequestOptions } from '@apollo/datasource-rest';
|
|
1
2
|
import { CapiResponse } from '../model/CapiResponse';
|
|
2
3
|
import { InstrumentedRESTDataSource } from './instrumented';
|
|
3
4
|
import { CapiPerson } from '../types/internal-content';
|
|
4
|
-
import {
|
|
5
|
+
import { CacheOptions } from '@apollo/datasource-rest/dist/RESTDataSource';
|
|
5
6
|
export declare class CapiDataSource extends InstrumentedRESTDataSource {
|
|
6
7
|
baseURL: string;
|
|
7
8
|
capiKey: string;
|
|
@@ -11,7 +12,7 @@ export declare class CapiDataSource extends InstrumentedRESTDataSource {
|
|
|
11
12
|
abortController: AbortController;
|
|
12
13
|
timeout: ReturnType<typeof setTimeout> | undefined;
|
|
13
14
|
nextNotificationLink?: string;
|
|
14
|
-
willSendRequest(
|
|
15
|
+
willSendRequest(request: WillSendRequestOptions): void;
|
|
15
16
|
protected cacheOptionsFor(url: string): CacheOptions | undefined;
|
|
16
17
|
getContent(uuid: string, packageContainer?: CapiResponse): Promise<CapiResponse>;
|
|
17
18
|
getPerson(uuid: string): Promise<CapiPerson>;
|
package/lib/datasources/capi.js
CHANGED
|
@@ -20,8 +20,8 @@ class CapiDataSource extends instrumented_1.InstrumentedRESTDataSource {
|
|
|
20
20
|
this.abortController = new AbortController();
|
|
21
21
|
this.timeout = undefined;
|
|
22
22
|
}
|
|
23
|
-
willSendRequest(
|
|
24
|
-
super.willSendRequest(
|
|
23
|
+
willSendRequest(request) {
|
|
24
|
+
super.willSendRequest(request);
|
|
25
25
|
request.headers['x-api-key'] = this.capiKey;
|
|
26
26
|
request.signal = this.abortController.signal;
|
|
27
27
|
this.timeout = setTimeout(() => this.abortController.abort(), REQUEST_TIMEOUT);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capi.js","sourceRoot":"","sources":["../../src/datasources/capi.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"capi.js","sourceRoot":"","sources":["../../src/datasources/capi.ts"],"names":[],"mappings":";;;AACA,wDAAoD;AACpD,iDAA2D;AAG3D,2DAGuC;AAGvC,MAAM,eAAe,GAAG,IAAI,CAAA,CAAC,YAAY;AAEzC,MAAa,cAAe,SAAQ,yCAA0B;IAA9D;;QACE,YAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,uBAAuB,CAAA;QACzD,YAAO,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAA;QACxC,oBAAe,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB;YAC7C,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;YACzC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA,CAAC,UAAU;QACnC,mBAAc,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB;YAC3C,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;YACxC,CAAC,CAAC,GAAG,CAAA,CAAC,aAAa;QAErB,uBAAkB,GAAG,CAAC,QAAQ,CAAC,CAAA;QAE/B,oBAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QACvC,YAAO,GAA8C,SAAS,CAAA;IAiEhE,CAAC;IA7DU,eAAe,CAAC,OAA+B;QACtD,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QAE9B,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,OAAO,CAAA;QAC3C,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,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AAA;SACZ;IACH,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAY;QAC1B,IAAI;YACF,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,CAAA;SACxC;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,KAAK,YAAY,KAAK,EAAE;gBAC1B,MAAM,IAAI,yBAAgB,CAAC;oBACzB,KAAK,EAAE,KAAK;oBACZ,IAAI,EAAE,8BAA8B;iBACrC,CAAC,CAAA;aACH;YAED,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;CACF;AA9ED,wCA8EC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WillSendRequestOptions, RESTDataSource, RequestOptions } from '@apollo/datasource-rest';
|
|
2
|
+
import type { FetcherResponse } from '@apollo/utils.fetcher';
|
|
2
3
|
import { QueryContext } from '..';
|
|
3
4
|
import { BaseDataSource, BaseDataSourceOptions } from './base';
|
|
4
5
|
export declare class InstrumentedRESTDataSource extends RESTDataSource implements BaseDataSource {
|
|
@@ -7,7 +8,7 @@ export declare class InstrumentedRESTDataSource extends RESTDataSource implement
|
|
|
7
8
|
context: QueryContext;
|
|
8
9
|
constructor({ cache, context }: BaseDataSourceOptions);
|
|
9
10
|
get cachePrefix(): string;
|
|
10
|
-
willSendRequest(
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
willSendRequest(request: WillSendRequestOptions): void;
|
|
12
|
+
trace<TResult>(url: URL, request: WillSendRequestOptions, fn: () => Promise<TResult>): Promise<TResult>;
|
|
13
|
+
didReceiveResponse<TResult>(response: FetcherResponse, request: RequestOptions): Promise<TResult>;
|
|
13
14
|
}
|
|
@@ -22,50 +22,44 @@ class InstrumentedRESTDataSource extends datasource_rest_1.RESTDataSource {
|
|
|
22
22
|
get cachePrefix() {
|
|
23
23
|
return this.constructor.name.replace(/DataSource$/, '').toLowerCase();
|
|
24
24
|
}
|
|
25
|
-
willSendRequest(
|
|
25
|
+
willSendRequest(request) {
|
|
26
26
|
request.headers['user-agent'] = `cp-content-pipeline-api/${this.context.versions.api} cp-content-pipeline-schema/${this.context.versions.schema} `;
|
|
27
|
-
if (this.context.requestId && !this.context.contentRequestedOnce) {
|
|
28
|
-
request.headers['x-request-id'] = this.context.requestId;
|
|
29
|
-
}
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
async throwIfResponseIsError() { }
|
|
34
|
-
async fetch(path, incomingRequest) {
|
|
35
|
-
const startTime = process.hrtime.bigint();
|
|
28
|
+
async trace(url, request, fn) {
|
|
29
|
+
this.startTime = process.hrtime.bigint();
|
|
36
30
|
this.context.metrics?.count(`graphql.datasource.${this.constructor.name}.request.count`, 1);
|
|
37
31
|
this.context.logger.info({
|
|
38
32
|
event: 'REQUEST_DATASOURCE',
|
|
39
33
|
datasource: this.constructor.name,
|
|
40
34
|
request: {
|
|
41
35
|
id: this.context.requestId,
|
|
42
|
-
url:
|
|
43
|
-
method:
|
|
36
|
+
url: url.href,
|
|
37
|
+
method: request.method,
|
|
44
38
|
},
|
|
45
39
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
40
|
+
if (this.context.requestId && !this.context.contentRequestedOnce) {
|
|
41
|
+
request.headers['x-request-id'] = this.context.requestId;
|
|
42
|
+
}
|
|
43
|
+
return fn();
|
|
44
|
+
}
|
|
45
|
+
async didReceiveResponse(response, request) {
|
|
46
|
+
// this.startTime will definitely have been set by willSendRequest, but no way of encoding that in types
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
48
|
+
const duration = (process.hrtime.bigint() - this.startTime) / BigInt(1e6);
|
|
49
|
+
this.context.metrics?.count(`graphql.datasource.${this.constructor.name}.response.${response.status}.count`, 1);
|
|
50
|
+
this.context.metrics?.count(`graphql.datasource.${this.constructor.name}.response.${response.status}.time`, Number(duration));
|
|
51
|
+
if (response.ok) {
|
|
52
|
+
return super.didReceiveResponse(response, request);
|
|
61
53
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
else {
|
|
55
|
+
const body = await this.parseBody(response);
|
|
56
|
+
throw new errors_1.UpstreamServiceError({
|
|
57
|
+
message: `${response.status}: ${response.statusText} from ${this.constructor.name}`,
|
|
58
|
+
statusCode: response.status,
|
|
59
|
+
relatesToSystems: this.backendSystemCodes,
|
|
60
|
+
url: response.url,
|
|
61
|
+
body,
|
|
62
|
+
});
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumented.js","sourceRoot":"","sources":["../../src/datasources/instrumented.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"instrumented.js","sourceRoot":"","sources":["../../src/datasources/instrumented.ts"],"names":[],"mappings":";;;AAAA,6DAIgC;AAEhC,qEAAoE;AAEpE,2DAAqE;AAErE,0CAAmD;AAGnD,MAAa,0BACX,SAAQ,gCAAc;IAOtB,YAAY,EAAE,KAAK,EAAE,OAAO,EAAyB;QACnD,MAAM,YAAY,GAAG,IAAI,4CAAsB,CAC7C,IAAA,0BAAkB,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,EAC9D,sEAAsE,CAAC,yCAAyC;SACjH,CAAA;QAED,KAAK,CAAC;YACJ,KAAK,EAAE,YAAY;SACpB,CAAC,CAAA;QAXJ,uBAAkB,GAAa,EAAE,CAAA;QAa/B,+BAA+B;QAC/B,4DAA4D;QAC5D,QAAQ;QACR,YAAY,CAAC,QAAQ,CAAC,GAAG,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ACtB,QAAyB,EACzB,OAAuB;QAEvB,wGAAwG;QACxG,oEAAoE;QACpE,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,SAAU,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;QAE1E,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CACzB,sBAAsB,IAAI,CAAC,WAAW,CAAC,IAAI,aAAa,QAAQ,CAAC,MAAM,QAAQ,EAC/E,CAAC,CACF,CAAA;QACD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,CACzB,sBAAsB,IAAI,CAAC,WAAW,CAAC,IAAI,aAAa,QAAQ,CAAC,MAAM,OAAO,EAC9E,MAAM,CAAC,QAAQ,CAAC,CACjB,CAAA;QAED,IAAI,QAAQ,CAAC,EAAE,EAAE;YACf,OAAO,KAAK,CAAC,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;SACnD;aAAM;YACL,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAA;YAE3C,MAAM,IAAI,6BAAoB,CAAC;gBAC7B,OAAO,EAAE,GAAG,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE;gBACnF,UAAU,EAAE,QAAQ,CAAC,MAAM;gBAC3B,gBAAgB,EAAE,IAAI,CAAC,kBAAkB;gBACzC,GAAG,EAAE,QAAQ,CAAC,GAAG;gBACjB,IAAI;aACL,CAAC,CAAA;SACH;IACH,CAAC;CACF;AA9FD,gEA8FC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { WillSendRequestOptions } from '@apollo/datasource-rest';
|
|
1
2
|
import { InstrumentedRESTDataSource } from './instrumented';
|
|
2
|
-
import {
|
|
3
|
+
import { CacheOptions } from '@apollo/datasource-rest/dist/RESTDataSource';
|
|
3
4
|
export declare class OrigamiImageDataSource extends InstrumentedRESTDataSource {
|
|
4
5
|
baseURL: string;
|
|
5
6
|
backendSystemCodes: string[];
|
|
6
7
|
abortController: AbortController;
|
|
7
8
|
timeout: ReturnType<typeof setTimeout> | undefined;
|
|
8
9
|
imageMetadataCacheTTL: number;
|
|
9
|
-
willSendRequest(
|
|
10
|
+
willSendRequest(request: WillSendRequestOptions): void;
|
|
10
11
|
protected cacheOptionsFor(): CacheOptions;
|
|
11
12
|
getImageMetadata(url: string): Promise<{
|
|
12
13
|
width: number;
|
|
@@ -15,8 +15,8 @@ class OrigamiImageDataSource extends instrumented_1.InstrumentedRESTDataSource {
|
|
|
15
15
|
? parseInt(process.env.IMAGE_METADATA_CACHE_TTL)
|
|
16
16
|
: 60 * 60 * 24 * 7; // 1 week
|
|
17
17
|
}
|
|
18
|
-
willSendRequest(
|
|
19
|
-
super.willSendRequest(
|
|
18
|
+
willSendRequest(request) {
|
|
19
|
+
super.willSendRequest(request);
|
|
20
20
|
request.signal = this.abortController.signal;
|
|
21
21
|
this.timeout = setTimeout(() => this.abortController.abort(), REQUEST_TIMEOUT);
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"origami-image.js","sourceRoot":"","sources":["../../src/datasources/origami-image.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"origami-image.js","sourceRoot":"","sources":["../../src/datasources/origami-image.ts"],"names":[],"mappings":";;;AACA,2DAGuC;AACvC,iDAA2D;AAG3D,MAAM,eAAe,GAAG,IAAI,CAAA,CAAC,YAAY;AAEzC,MAAa,sBAAuB,SAAQ,yCAA0B;IAAtE;;QACE,YAAO,GAAG,+CAA+C,CAAA;QACzD,uBAAkB,GAAG,CAAC,0BAA0B,CAAC,CAAA;QAEjD,oBAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QACvC,YAAO,GAA8C,SAAS,CAAA;QAE9D,0BAAqB,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB;YAC1D,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|
|
1
|
+
import { CacheOptions, WillSendRequestOptions } from '@apollo/datasource-rest/dist/RESTDataSource';
|
|
2
2
|
import { InstrumentedRESTDataSource } from './instrumented';
|
|
3
3
|
export declare class TwitterDataSource extends InstrumentedRESTDataSource {
|
|
4
4
|
baseURL: string;
|
|
5
5
|
backendSystemCodes: string[];
|
|
6
6
|
abortController: AbortController;
|
|
7
7
|
timeout: ReturnType<typeof setTimeout> | undefined;
|
|
8
|
-
willSendRequest(
|
|
8
|
+
willSendRequest(request: WillSendRequestOptions): void;
|
|
9
9
|
getTweet(tweetUrl: string): Promise<any>;
|
|
10
10
|
cacheOptionsFor(): CacheOptions;
|
|
11
11
|
}
|
|
@@ -12,8 +12,8 @@ class TwitterDataSource extends instrumented_1.InstrumentedRESTDataSource {
|
|
|
12
12
|
this.abortController = new AbortController();
|
|
13
13
|
this.timeout = undefined;
|
|
14
14
|
}
|
|
15
|
-
willSendRequest(
|
|
16
|
-
super.willSendRequest(
|
|
15
|
+
willSendRequest(request) {
|
|
16
|
+
super.willSendRequest(request);
|
|
17
17
|
request.signal = this.abortController.signal;
|
|
18
18
|
this.timeout = setTimeout(() => this.abortController.abort(), REQUEST_TIMEOUT);
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"twitter.js","sourceRoot":"","sources":["../../src/datasources/twitter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"twitter.js","sourceRoot":"","sources":["../../src/datasources/twitter.ts"],"names":[],"mappings":";;;AAIA,2DAGuC;AACvC,iDAA2D;AAE3D,MAAM,eAAe,GAAG,IAAI,CAAA,CAAC,YAAY;AACzC,MAAa,iBAAkB,SAAQ,yCAA0B;IAAjE;;QACE,YAAO,GAAG,6BAA6B,CAAA;QACvC,uBAAkB,GAAG,CAAC,oBAAoB,CAAC,CAAA;QAE3C,oBAAe,GAAG,IAAI,eAAe,EAAE,CAAA;QACvC,YAAO,GAA8C,SAAS,CAAA;IAyChE,CAAC;IAvCU,eAAe,CAAC,OAA+B;QACtD,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;QAE9B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAA;QAC5C,IAAI,CAAC,OAAO,GAAG,UAAU,CACvB,GAAG,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,EAClC,eAAe,CAChB,CAAA;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,QAAgB;QAC7B,IAAI;YACF,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,eAAe,QAAQ,mBAAmB,CAAC,CAAA;YAExE,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBAC1B,IAAI,CAAC,OAAO,GAAG,SAAS,CAAA;aACzB;YAED,OAAO,KAAK,CAAA;SACb;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;gBACzD,MAAM,IAAI,6BAAoB,CAAC;oBAC7B,IAAI,EAAE,4BAA4B;oBAClC,OAAO,EAAE,2CAA2C,eAAe,8BAA8B;oBACjG,UAAU,EAAE,GAAG;oBACf,gBAAgB,EAAE,IAAI,CAAC,kBAAkB;iBAC1C,CAAC,CAAA;aACH;YAED,MAAM,KAAK,CAAA;SACZ;IACH,CAAC;IAED,eAAe;QACb,iFAAiF;QACjF,oFAAoF;QACpF,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAA;IACtB,CAAC;CACF;AA9CD,8CA8CC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@financial-times/cp-content-pipeline-schema",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/Financial-Times/cp-content-pipeline#readme",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@apollo/datasource-rest": "^
|
|
21
|
+
"@apollo/datasource-rest": "^4.3.2",
|
|
22
22
|
"@apollo/utils.keyvaluecache": "^1.0.1",
|
|
23
23
|
"@dotcom-reliability-kit/errors": "^2.0.0",
|
|
24
24
|
"@dotcom-reliability-kit/log-error": "^2.0.0",
|
package/queries/article.graphql
CHANGED
package/src/datasources/capi.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import { WillSendRequestOptions } from '@apollo/datasource-rest'
|
|
1
2
|
import { CapiResponse } from '../model/CapiResponse'
|
|
2
3
|
import { InstrumentedRESTDataSource } from './instrumented'
|
|
3
4
|
import { CapiPerson } from '../types/internal-content'
|
|
4
|
-
import {
|
|
5
|
+
import { CacheOptions } from '@apollo/datasource-rest/dist/RESTDataSource'
|
|
5
6
|
import {
|
|
6
7
|
OperationalError,
|
|
7
8
|
UpstreamServiceError,
|
|
8
9
|
} from '@dotcom-reliability-kit/errors'
|
|
10
|
+
import { uuidFromUrl } from '../helpers/metadata'
|
|
9
11
|
|
|
10
12
|
const REQUEST_TIMEOUT = 5000 // 5 seconds
|
|
11
13
|
|
|
@@ -26,8 +28,8 @@ export class CapiDataSource extends InstrumentedRESTDataSource {
|
|
|
26
28
|
|
|
27
29
|
nextNotificationLink?: string
|
|
28
30
|
|
|
29
|
-
override willSendRequest(
|
|
30
|
-
super.willSendRequest(
|
|
31
|
+
override willSendRequest(request: WillSendRequestOptions) {
|
|
32
|
+
super.willSendRequest(request)
|
|
31
33
|
|
|
32
34
|
request.headers['x-api-key'] = this.capiKey
|
|
33
35
|
request.signal = this.abortController.signal
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
WillSendRequestOptions,
|
|
2
3
|
RESTDataSource,
|
|
3
|
-
|
|
4
|
-
DataSourceFetchResult,
|
|
5
|
-
DataSourceRequest,
|
|
6
|
-
AugmentedRequest,
|
|
4
|
+
RequestOptions,
|
|
7
5
|
} from '@apollo/datasource-rest'
|
|
6
|
+
import type { FetcherResponse } from '@apollo/utils.fetcher'
|
|
8
7
|
import { PrefixingKeyValueCache } from '@apollo/utils.keyvaluecache'
|
|
9
8
|
import { SerializedRequest } from '@dotcom-reliability-kit/serialize-request'
|
|
10
9
|
import { UpstreamServiceError } from '@dotcom-reliability-kit/errors'
|
|
@@ -41,82 +40,69 @@ export class InstrumentedRESTDataSource
|
|
|
41
40
|
return this.constructor.name.replace(/DataSource$/, '').toLowerCase()
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
override willSendRequest(
|
|
43
|
+
override willSendRequest(request: WillSendRequestOptions): void {
|
|
45
44
|
request.headers[
|
|
46
45
|
'user-agent'
|
|
47
46
|
] = `cp-content-pipeline-api/${this.context.versions.api} cp-content-pipeline-schema/${this.context.versions.schema} `
|
|
48
|
-
|
|
49
|
-
if (this.context.requestId && !this.context.contentRequestedOnce) {
|
|
50
|
-
request.headers['x-request-id'] = this.context.requestId
|
|
51
|
-
}
|
|
52
47
|
}
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
incomingRequest?: DataSourceRequest<CacheOptions>
|
|
61
|
-
): Promise<DataSourceFetchResult<TResult>> {
|
|
62
|
-
const startTime = process.hrtime.bigint()
|
|
49
|
+
override async trace<TResult>(
|
|
50
|
+
url: URL,
|
|
51
|
+
request: WillSendRequestOptions,
|
|
52
|
+
fn: () => Promise<TResult>
|
|
53
|
+
): Promise<TResult> {
|
|
54
|
+
this.startTime = process.hrtime.bigint()
|
|
63
55
|
|
|
64
56
|
this.context.metrics?.count(
|
|
65
57
|
`graphql.datasource.${this.constructor.name}.request.count`,
|
|
66
58
|
1
|
|
67
59
|
)
|
|
68
|
-
|
|
69
60
|
this.context.logger.info({
|
|
70
61
|
event: 'REQUEST_DATASOURCE',
|
|
71
62
|
datasource: this.constructor.name,
|
|
72
63
|
request: {
|
|
73
64
|
id: this.context.requestId,
|
|
74
|
-
url:
|
|
75
|
-
method:
|
|
65
|
+
url: url.href,
|
|
66
|
+
method: request.method,
|
|
76
67
|
} as SerializedRequest,
|
|
77
68
|
})
|
|
78
69
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.context.metrics?.count(
|
|
84
|
-
`graphql.datasource.${this.constructor.name}.response.${result.response.status}.count`,
|
|
85
|
-
1
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
this.context.metrics?.count(
|
|
89
|
-
`graphql.datasource.${this.constructor.name}.response.${result.response.status}.time`,
|
|
90
|
-
Number(duration)
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
if (!result.response.ok) {
|
|
94
|
-
throw new UpstreamServiceError({
|
|
95
|
-
message: `${result.response.status}: ${result.response.statusText} from ${this.constructor.name}`,
|
|
96
|
-
statusCode: result.response.status,
|
|
97
|
-
relatesToSystems: this.backendSystemCodes,
|
|
98
|
-
url: result.response.url,
|
|
99
|
-
body: result.parsedBody,
|
|
100
|
-
})
|
|
101
|
-
}
|
|
70
|
+
if (this.context.requestId && !this.context.contentRequestedOnce) {
|
|
71
|
+
request.headers['x-request-id'] = this.context.requestId
|
|
72
|
+
}
|
|
102
73
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (error instanceof Error && error.name === 'AbortError') {
|
|
106
|
-
const duration = (process.hrtime.bigint() - startTime) / BigInt(1e6)
|
|
74
|
+
return fn()
|
|
75
|
+
}
|
|
107
76
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
77
|
+
async didReceiveResponse<TResult>(
|
|
78
|
+
response: FetcherResponse,
|
|
79
|
+
request: RequestOptions
|
|
80
|
+
): Promise<TResult> {
|
|
81
|
+
// this.startTime will definitely have been set by willSendRequest, but no way of encoding that in types
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
83
|
+
const duration = (process.hrtime.bigint() - this.startTime!) / BigInt(1e6)
|
|
112
84
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
85
|
+
this.context.metrics?.count(
|
|
86
|
+
`graphql.datasource.${this.constructor.name}.response.${response.status}.count`,
|
|
87
|
+
1
|
|
88
|
+
)
|
|
89
|
+
this.context.metrics?.count(
|
|
90
|
+
`graphql.datasource.${this.constructor.name}.response.${response.status}.time`,
|
|
91
|
+
Number(duration)
|
|
92
|
+
)
|
|
118
93
|
|
|
119
|
-
|
|
94
|
+
if (response.ok) {
|
|
95
|
+
return super.didReceiveResponse(response, request)
|
|
96
|
+
} else {
|
|
97
|
+
const body = await this.parseBody(response)
|
|
98
|
+
|
|
99
|
+
throw new UpstreamServiceError({
|
|
100
|
+
message: `${response.status}: ${response.statusText} from ${this.constructor.name}`,
|
|
101
|
+
statusCode: response.status,
|
|
102
|
+
relatesToSystems: this.backendSystemCodes,
|
|
103
|
+
url: response.url,
|
|
104
|
+
body,
|
|
105
|
+
})
|
|
120
106
|
}
|
|
121
107
|
}
|
|
122
108
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { WillSendRequestOptions } from '@apollo/datasource-rest'
|
|
2
|
+
import {
|
|
3
|
+
OperationalError,
|
|
4
|
+
UpstreamServiceError,
|
|
5
|
+
} from '@dotcom-reliability-kit/errors'
|
|
2
6
|
import { InstrumentedRESTDataSource } from './instrumented'
|
|
3
|
-
import {
|
|
7
|
+
import { CacheOptions } from '@apollo/datasource-rest/dist/RESTDataSource'
|
|
4
8
|
|
|
5
9
|
const REQUEST_TIMEOUT = 5000 // 5 seconds
|
|
6
10
|
|
|
@@ -15,8 +19,8 @@ export class OrigamiImageDataSource extends InstrumentedRESTDataSource {
|
|
|
15
19
|
? parseInt(process.env.IMAGE_METADATA_CACHE_TTL)
|
|
16
20
|
: 60 * 60 * 24 * 7 // 1 week
|
|
17
21
|
|
|
18
|
-
override willSendRequest(
|
|
19
|
-
super.willSendRequest(
|
|
22
|
+
override willSendRequest(request: WillSendRequestOptions) {
|
|
23
|
+
super.willSendRequest(request)
|
|
20
24
|
|
|
21
25
|
request.signal = this.abortController.signal
|
|
22
26
|
this.timeout = setTimeout(
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
CacheOptions,
|
|
3
|
+
WillSendRequestOptions,
|
|
4
|
+
} from '@apollo/datasource-rest/dist/RESTDataSource'
|
|
5
|
+
import {
|
|
6
|
+
OperationalError,
|
|
7
|
+
UpstreamServiceError,
|
|
8
|
+
} from '@dotcom-reliability-kit/errors'
|
|
3
9
|
import { InstrumentedRESTDataSource } from './instrumented'
|
|
4
10
|
|
|
5
11
|
const REQUEST_TIMEOUT = 5000 // 5 seconds
|
|
@@ -10,8 +16,8 @@ export class TwitterDataSource extends InstrumentedRESTDataSource {
|
|
|
10
16
|
abortController = new AbortController()
|
|
11
17
|
timeout: ReturnType<typeof setTimeout> | undefined = undefined
|
|
12
18
|
|
|
13
|
-
override willSendRequest(
|
|
14
|
-
super.willSendRequest(
|
|
19
|
+
override willSendRequest(request: WillSendRequestOptions) {
|
|
20
|
+
super.willSendRequest(request)
|
|
15
21
|
|
|
16
22
|
request.signal = this.abortController.signal
|
|
17
23
|
this.timeout = setTimeout(
|