Skip to content

Commit 998eef0

Browse files
committed
Revert auto formatting of jsc files.
1 parent ba44dcb commit 998eef0

File tree

7 files changed

+135
-149
lines changed

7 files changed

+135
-149
lines changed

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# This is a template, not a valid YAML file
22
/manifest_template.yml
3+
4+
# We hit compile errors in Apigee if these are auto formatted
5+
# TODO - investigate
6+
/proxies/live/apiproxy/resources/jsc/
7+
/proxies/sandbox/apiproxy/resources/jsc/

proxies/live/apiproxy/resources/jsc/DynamicPayload.js

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,43 @@ var responseContent = context.getVariable("response.content");
33
var response = JSON.parse(responseContent);
44

55
// Set debug message
6-
context.setVariable(
7-
"debugMessage",
8-
"Executing DynamicPayload.js. Parsed Response: " + JSON.stringify(response),
9-
);
6+
context.setVariable("debugMessage", "Executing DynamicPayload.js. Parsed Response: " + JSON.stringify(response));
107

118
var diagnosticsMessage = "";
129

1310
// Check response status code
1411
if (response.issue[0].code === "invalid_resource") {
15-
diagnosticsMessage = "Submitted resource is not valid.";
12+
diagnosticsMessage = "Submitted resource is not valid.";
1613
} else if (response.issue[0].code === "internal_server_error") {
17-
diagnosticsMessage = "Unexpected internal server error.";
14+
diagnosticsMessage = "Unexpected internal server error.";
1815
}
1916
// Build dynamic payload
2017
var dynamicPayload = {
21-
resourceType: "OperationOutcome",
22-
// Replace "id" with the correct property from the response
23-
id: response.id,
24-
meta: {
25-
profile: [
26-
"https://simplifier.net/guide/UKCoreDevelopment2/ProfileUKCore-OperationOutcome",
27-
],
28-
},
29-
issue: [
30-
{
31-
severity: "error",
32-
// Replace "code" and "diagnostics" with correct properties
33-
code: response.issue[0].code,
34-
details: {
35-
coding: [
36-
{
37-
system: "https://fhir.nhs.uk/Codesystem/http-error-codes",
38-
code: response.issue[0].code,
39-
},
40-
],
41-
},
42-
diagnostics: diagnosticsMessage,
18+
"resourceType": "OperationOutcome",
19+
// Replace "id" with the correct property from the response
20+
"id": response.id,
21+
"meta": {
22+
"profile": [
23+
"https://simplifier.net/guide/UKCoreDevelopment2/ProfileUKCore-OperationOutcome"
24+
]
4325
},
44-
],
26+
"issue": [
27+
{
28+
"severity": "error",
29+
// Replace "code" and "diagnostics" with correct properties
30+
"code": response.issue[0].code,
31+
"details": {
32+
"coding": [
33+
{
34+
"system": "https://fhir.nhs.uk/Codesystem/http-error-codes",
35+
"code": response.issue[0].code
36+
}
37+
]
38+
},
39+
"diagnostics": diagnosticsMessage
40+
}
41+
]
4542
};
4643

4744
// Set the dynamic payload as a variable
48-
context.setVariable(
49-
"Javascript_dynamic_response",
50-
JSON.stringify(dynamicPayload),
51-
);
45+
context.setVariable("Javascript_dynamic_response", JSON.stringify(dynamicPayload));
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// extract version from Accept header
22
function extractVersion() {
3-
var acceptHeader = context.getVariable("request.header.Accept");
4-
if (acceptHeader) {
5-
var versionPattern = /application\/fhir\+json;\s*version=(\d+)/i; // 'i' flag for case-insensitivity
6-
var validPattern =
7-
/^(application\/fhir\+json(;|;\s*version=\d+)?|\*\/\*)$/i; // Valid patterns: with or without version, or */*
8-
if (validPattern.test(acceptHeader)) {
9-
var match = acceptHeader.match(versionPattern);
10-
var version = match ? match[1] : "1"; // Default to version 1 if not provided
11-
context.setVariable("version", version);
3+
var acceptHeader = context.getVariable("request.header.Accept");
4+
if (acceptHeader) {
5+
var versionPattern = /application\/fhir\+json;\s*version=(\d+)/i; // 'i' flag for case-insensitivity
6+
var validPattern = /^(application\/fhir\+json(;|;\s*version=\d+)?|\*\/\*)$/i; // Valid patterns: with or without version, or */*
7+
if (validPattern.test(acceptHeader)) {
8+
var match = acceptHeader.match(versionPattern);
9+
var version = match ? match[1] : "1"; // Default to version 1 if not provided
10+
context.setVariable("version", version);
11+
} else {
12+
context.setVariable("invalidAcceptHeader", true);
13+
}
1214
} else {
13-
context.setVariable("invalidAcceptHeader", true);
15+
context.setVariable("version", "1"); // Default to version 1 if Accept header is missing
1416
}
15-
} else {
16-
context.setVariable("version", "1"); // Default to version 1 if Accept header is missing
17-
}
1817
}
1918

2019
extractVersion();
Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,41 @@
1-
const apiproxy_revision = context.getVariable("apiproxy.revision");
1+
const apiproxy_revision = context.getVariable('apiproxy.revision');
22

3-
const healthcheck_status_code = context.getVariable(
4-
"healthcheckResponse.status.code",
5-
);
6-
const healthcheck_request_url = context.getVariable("healthcheckRequest.url");
7-
const healthcheck_failed = context.getVariable(
8-
"servicecallout.ServiceCallout.CallHealthcheckEndpoint.failed",
9-
);
3+
const healthcheck_status_code = context.getVariable('healthcheckResponse.status.code');
4+
const healthcheck_request_url = context.getVariable('healthcheckRequest.url');
5+
const healthcheck_failed = context.getVariable("servicecallout.ServiceCallout.CallHealthcheckEndpoint.failed");
106

117
function json_tryparse(raw) {
12-
try {
13-
return JSON.parse(raw);
14-
} catch (e) {
15-
return raw;
16-
}
8+
try {
9+
return JSON.parse(raw);
10+
}
11+
catch (e) {
12+
return raw;
13+
}
1714
}
1815

19-
const healthcheck_content = json_tryparse(
20-
context.getVariable("healthcheckResponse.content"),
21-
);
22-
const healthcheck_status =
23-
healthcheck_status_code / 100 === 2 ? "pass" : "fail";
24-
const timeout =
25-
healthcheck_status_code === null && healthcheck_failed ? "true" : "false";
16+
const healthcheck_content = json_tryparse(context.getVariable('healthcheckResponse.content'));
17+
const healthcheck_status = (healthcheck_status_code/100 === 2) ? "pass" : "fail";
18+
const timeout = (healthcheck_status_code === null && healthcheck_failed) ? "true" : "false";
2619

27-
const final_status = healthcheck_status !== "pass" ? "fail" : "pass";
20+
const final_status = (healthcheck_status !== "pass") ? "fail" : "pass";
2821

2922
const resp = {
30-
status: final_status,
31-
version: "{{ DEPLOYED_VERSION }}",
32-
revision: apiproxy_revision,
33-
releaseId: "{{ RELEASE_RELEASEID }}",
34-
commitId: "{{ SOURCE_COMMIT_ID }}",
35-
checks: {
36-
healthcheck: {
37-
status: healthcheck_status,
38-
timeout: timeout,
39-
responseCode: healthcheck_status_code,
40-
outcome: healthcheck_content,
41-
links: { self: healthcheck_request_url },
42-
},
43-
},
23+
"status" : final_status,
24+
"version" : "{{ DEPLOYED_VERSION }}" ,
25+
"revision" : apiproxy_revision,
26+
"releaseId" : "{{ RELEASE_RELEASEID }}",
27+
"commitId": "{{ SOURCE_COMMIT_ID }}",
28+
"checks" : {
29+
"healthcheck" : {
30+
"status": healthcheck_status,
31+
"timeout" : timeout,
32+
"responseCode" : healthcheck_status_code,
33+
"outcome": healthcheck_content,
34+
"links" : {"self": healthcheck_request_url}
35+
}
36+
}
4437
};
4538

4639
context.setVariable("status.response", JSON.stringify(resp));
4740
context.setVariable("response.content", JSON.stringify(resp));
48-
context.setVariable("response.header.Content-Type", "application/json");
41+
context.setVariable("response.header.Content-Type", "application/json");
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
// Define the allowed headers
1+
// Define the allowed headers
22
var allowedHeaders = [
3-
"Date",
4-
"Content-Type",
5-
"Content-Length",
6-
"Connection",
7-
"X-Correlation-ID",
8-
"X-Request-ID",
9-
"Accept",
10-
"Strict-Transport-Security",
3+
'Date',
4+
'Content-Type',
5+
'Content-Length',
6+
'Connection',
7+
'X-Correlation-ID',
8+
'X-Request-ID',
9+
'Accept',
10+
'Strict-Transport-Security'
1111
];
1212

13-
var responseHeaders = context.getVariable("response.headers.names");
13+
var responseHeaders = context.getVariable('response.headers.names');
1414

15-
responseHeaders = Array.isArray(responseHeaders) ? responseHeaders : [];
15+
responseHeaders = Array.isArray(responseHeaders) ? responseHeaders :[];
1616

17-
var headersToRemove = responseHeaders.filter(function (header) {
18-
return allowedHeaders.indexOf(header) === -1;
17+
18+
var headersToRemove = responseHeaders.filter(function(header) {
19+
return allowedHeaders.indexOf(header) === -1;
1920
});
2021

21-
var setCookieHeader = context.getVariable("response.header.Set-Cookie");
22+
var setCookieHeader = context.getVariable('response.header.Set-Cookie');
2223

2324
if (setCookieHeader) {
24-
context.removeVariable("response.header.Set-Cookie");
25+
context.removeVariable('response.header.Set-Cookie');
2526
}
2627

27-
context.setVariable("headersToRemove", headersToRemove.join(","));
28+
context.setVariable('headersToRemove', headersToRemove.join(","));

proxies/sandbox/apiproxy/resources/jsc/HealthCheck.SetResponse.js

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,39 @@
1-
const apiproxy_revision = context.getVariable("apiproxy.revision");
1+
const apiproxy_revision = context.getVariable('apiproxy.revision');
22

3-
const healthcheck_status_code = context.getVariable(
4-
"healthcheckResponse.status.code",
5-
);
6-
const healthcheck_request_url = context.getVariable("healthcheckRequest.url");
7-
const healthcheck_failed = context.getVariable(
8-
"servicecallout.ServiceCallout.CallHealthcheckEndpoint.failed",
9-
);
3+
const healthcheck_status_code = context.getVariable('healthcheckResponse.status.code');
4+
const healthcheck_request_url = context.getVariable('healthcheckRequest.url');
5+
const healthcheck_failed = context.getVariable("servicecallout.ServiceCallout.CallHealthcheckEndpoint.failed");
106

117
function json_tryparse(raw) {
12-
try {
13-
return JSON.parse(raw);
14-
} catch (e) {
15-
return raw;
16-
}
8+
try {
9+
return JSON.parse(raw);
10+
}
11+
catch (e) {
12+
return raw;
13+
}
1714
}
1815

19-
const healthcheck_content = json_tryparse(
20-
context.getVariable("healthcheckResponse.content"),
21-
);
22-
const healthcheck_status =
23-
healthcheck_status_code / 100 === 2 ? "pass" : "fail";
24-
const timeout =
25-
healthcheck_status_code === null && healthcheck_failed ? "true" : "false";
16+
const healthcheck_content = json_tryparse(context.getVariable('healthcheckResponse.content'));
17+
const healthcheck_status = (healthcheck_status_code/100 === 2) ? "pass" : "fail";
18+
const timeout = (healthcheck_status_code === null && healthcheck_failed) ? "true" : "false";
2619

27-
const final_status = healthcheck_status !== "pass" ? "fail" : "pass";
20+
const final_status = (healthcheck_status !== "pass") ? "fail" : "pass";
2821

2922
const resp = {
30-
status: final_status,
31-
version: "{{ DEPLOYED_VERSION }}",
32-
revision: apiproxy_revision,
33-
releaseId: "{{ RELEASE_RELEASEID }}",
34-
commitId: "{{ SOURCE_COMMIT_ID }}",
35-
checks: {
36-
healthcheck: {
37-
status: healthcheck_status,
38-
timeout: timeout,
39-
responseCode: healthcheck_status_code,
40-
outcome: healthcheck_content,
41-
links: { self: healthcheck_request_url },
42-
},
43-
},
23+
"status" : final_status,
24+
"version" : "{{ DEPLOYED_VERSION }}" ,
25+
"revision" : apiproxy_revision,
26+
"releaseId" : "{{ RELEASE_RELEASEID }}",
27+
"commitId": "{{ SOURCE_COMMIT_ID }}",
28+
"checks" : {
29+
"healthcheck" : {
30+
"status": healthcheck_status,
31+
"timeout" : timeout,
32+
"responseCode" : healthcheck_status_code,
33+
"outcome": healthcheck_content,
34+
"links" : {"self": healthcheck_request_url}
35+
}
36+
}
4437
};
4538

4639
context.setVariable("status.response", JSON.stringify(resp));
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
// Define the allowed headers
1+
// Define the allowed headers
22
var allowedHeaders = [
3-
"Date",
4-
"Content-Type",
5-
"Content-Length",
6-
"Connection",
7-
"X-Correlation-ID",
8-
"X-Request-ID",
9-
"Accept",
10-
"Strict-Transport-Security",
3+
'Date',
4+
'Content-Type',
5+
'Content-Length',
6+
'Connection',
7+
'X-Correlation-ID',
8+
'X-Request-ID',
9+
'Accept',
10+
'Strict-Transport-Security'
1111
];
1212

13-
var responseHeaders = context.getVariable("response.headers.names");
13+
var responseHeaders = context.getVariable('response.headers.names');
1414

15-
responseHeaders = Array.isArray(responseHeaders) ? responseHeaders : [];
15+
responseHeaders = Array.isArray(responseHeaders) ? responseHeaders :[];
1616

17-
var headersToRemove = responseHeaders.filter(function (header) {
18-
return allowedHeaders.indexOf(header) === -1;
17+
18+
var headersToRemove = responseHeaders.filter(function(header) {
19+
return allowedHeaders.indexOf(header) === -1;
1920
});
2021

21-
var setCookieHeader = context.getVariable("response.header.Set-Cookie");
22+
var setCookieHeader = context.getVariable('response.header.Set-Cookie');
2223

2324
if (setCookieHeader) {
24-
context.removeVariable("response.header.Set-Cookie");
25+
context.removeVariable('response.header.Set-Cookie');
2526
}
2627

27-
context.setVariable("headersToRemove", headersToRemove.join(","));
28+
context.setVariable('headersToRemove', headersToRemove.join(","));

0 commit comments

Comments
 (0)