corona-warn-app
Version:
A corona-warn-app API client
127 lines (126 loc) • 5.8 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DiagnosisKeysAPI = void 0;
class DiagnosisKeysAPI {
constructor(apiClient) {
this.apiClient = apiClient;
}
/**
* Get all countries for which diagnosis keys are available.
* @returns countries in ISO-3166 format (e.g. `["DE", "FR"]`)
*/
getCountries() {
return __awaiter(this, void 0, void 0, function* () {
const endpoint = `/diagnosis-keys/country`;
const { data } = yield this.apiClient.get(endpoint);
return data;
});
}
/**
* Get all dates for which diagnosis keys are available.
* @param country An ISO 3166-1 alpha-2 country key (e.g. `DE`).
*
* Gives a list of all dates for which diagnosis keys are available for a
* specific country. For Germany, this would return a list of dates for the
* past 14 days (if all of them contain diagnosis keys).
*/
getDatesByCountry(country) {
return __awaiter(this, void 0, void 0, function* () {
const endpoint = `/diagnosis-keys/country/${country}/date`;
const { data } = yield this.apiClient.get(endpoint);
return data;
});
}
/**
* Get all hours of a specific date for which diagnosis keys are available.
* @param country An ISO 3166-1 alpha-2 country key (e.g. `DE`).
* @param date An ISO-8601 date descriptor (e.g. `2020-05-01`).
* Server time zone is UTC.
*
* Gives a list of all hours (0-23) of a specific date for which diagnosis
* keys are available for a specific country. For the current date, a list
* containing the respective numbers/hours for which data is available
* (e.g. 0-17) will be returned. If the date is outside of the 14-day window,
* or in the future, an HTTP error code will be returned.
*/
getHoursByDate(country, date) {
return __awaiter(this, void 0, void 0, function* () {
const endpoint = `/diagnosis-keys/country/${country}/date/${date}/hour`;
const { data } = yield this.apiClient.get(endpoint);
return data;
});
}
/**
* Get all diagnosis keys for a specific date.
* @param country An ISO 3166-1 alpha-2 country key (e.g. `DE`).
* @param date An ISO-8601 date descriptor (e.g. `2020-05-01`).
* Server time zone is UTC.
*
* Gives all diagnosis keys for a specific country on a specific date. If
* there are no diagnosis keys available for that date (but the date is still
* within the 14-day window), a signed payload with an empty list of diagnosis
* keys will be returned. If the date is outside of the 14-day window, or in
* the future, an HTTP error code will be returned.
*/
getKeysByDate(country, date) {
return __awaiter(this, void 0, void 0, function* () {
const endpoint = `/diagnosis-keys/country/${country}/date/${date}`;
const { data } = yield this.apiClient.get(endpoint, {
headers: { Accept: 'application/zip' },
responseType: 'arraybuffer',
});
return data;
});
}
/**
* Get all diagnosis keys for a specific hour on a specific date.
* @param country An ISO 3166-1 alpha-2 country key (e.g. `DE`).
* @param hour An integer number between 0 and 23.
* Server time zone is UTC.
*
* Gives all diagnosis keys for a specific country on a specific date within
* a specific hour. If there are no diagnosis keys available for the hour (but
* the date is still within the 14-day window), a signed payload with an empty
* list of diagnosis keys will be returned. If the date is outside of the
* 14-day window, or in the future, or an hour > 23 was requested, an HTTP
* error code will be returned.
*/
getKeysByHour(country, date, hour) {
return __awaiter(this, void 0, void 0, function* () {
const endpoint = `/diagnosis-keys/country/${country}/date/${date}/hour/${hour}`;
const { data } = yield this.apiClient.get(endpoint, {
headers: { Accept: 'application/zip' },
responseType: 'arraybuffer',
});
return data;
});
}
/**
* Post diagnosis keys.
* @param keys A collection of temporary exposure keys.
* @param cwaAuthorization TAN code associated with this diagnosis key submission.
* @param cwaFake Requests with a value of "0" will be fully processed. Any other
* value indicates that this request shall be handled as a "fake" request.
*/
postKeys(keys, cwaAuthorization, cwaFake) {
return __awaiter(this, void 0, void 0, function* () {
const endpoint = '/diagnosis-keys';
yield this.apiClient.post(endpoint, keys, {
headers: {
'cwa-authorization': cwaAuthorization,
'cwa-fake': cwaFake,
},
});
});
}
}
exports.DiagnosisKeysAPI = DiagnosisKeysAPI;