@eyeseetea/d2-logger 1.2.0-beta.2 → 1.2.0-beta.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.
package/README.md CHANGED
@@ -13,16 +13,23 @@ There are three types of logger output:
13
13
  Therefore, the following configuration will be passed to the logger:
14
14
 
15
15
  ```typescript
16
- import { initLogger, ProgramLogger } from "@eyeseetea/d2-logger";
16
+ import { initLogger, ProgramLogger, LoggerD2ApiOptions } from "@eyeseetea/d2-logger";
17
17
 
18
- const logger: ProgramLogger = await initLogger({
19
- type: "program",
20
- debug: true,
18
+ const d2ApiOptions: LoggerD2ApiOptions = {
21
19
  baseUrl: "https://play.dhis2.org/40.2.2",
22
20
  auth: {
23
21
  username: "admin",
24
22
  password: "district",
25
23
  },
24
+ // backend?: "xhr" | "fetch"
25
+ // apiVersion?: number
26
+ // timeout?: number
27
+ };
28
+
29
+ const logger: ProgramLogger = await initLogger({
30
+ type: "program",
31
+ debug: true,
32
+ d2ApiOptions: d2ApiOptions,
26
33
  organisationUnitId: "", // Organisation unit Id where the program is registered
27
34
  programId: "", // Event program Id where register the logs as events
28
35
  dataElements: {
@@ -34,6 +41,7 @@ There are three types of logger output:
34
41
 
35
42
  Notice:
36
43
 
44
+ - `d2ApiOptions` corresponds to the `D2ApiOptions` type exported by `@eyeseetea/d2-logger`.
37
45
  - Please note that `auth` is not mandatory if it's used in the DHIS2 app instead of in a script.
38
46
  - If `debug` is `true`, then in addition to registering the logs in the DHIS2 program, they will also be displayed on the console.
39
47
 
@@ -93,21 +101,28 @@ There are three types of logger output:
93
101
 
94
102
  3. Using a DHIS2 tracker program to register the logs as events:
95
103
 
96
- You will need to have and existing tracker program in DHIS2. In order to be able to log the log type (Error", "Warn", "Success", "Info" and "Debug") in the event, it would be necessary to create a data element and assign it to the program stages, and then add this data element id to the configuration.
104
+ You will need to have and existing tracker program in DHIS2. In order to be able to log the log type (Error", "Warn", "Success", "Info" and "Debug") in the event, it would be necessary to create a data element and assign it to the repeatable program stages, and then add this data element id to the configuration.
97
105
 
98
106
  Therefore, the following configuration will be passed to the logger:
99
107
 
100
108
  ```typescript
101
- import { initLogger, TrackerProgramLogger } from "@eyeseetea/d2-logger";
109
+ import { initLogger, TrackerProgramLogger, LoggerD2ApiOptions } from "@eyeseetea/d2-logger";
102
110
 
103
- const logger: TrackerProgramLogger = await initLogger({
104
- type: "trackerProgram",
105
- debug: true,
111
+ const d2ApiOptions: LoggerD2ApiOptions = {
106
112
  baseUrl: "https://play.dhis2.org/40.2.2",
107
113
  auth: {
108
114
  username: "admin",
109
115
  password: "district",
110
116
  },
117
+ // backend?: "xhr" | "fetch"
118
+ // apiVersion?: number
119
+ // timeout?: number
120
+ };
121
+
122
+ const logger: TrackerProgramLogger = await initLogger({
123
+ type: "trackerProgram",
124
+ debug: true,
125
+ d2ApiOptions: d2ApiOptions,
111
126
  trackerProgramId: "", // Tracker program Id where register the logs as events
112
127
  messageTypeId: "", // Id of the data element which is the types of log
113
128
  });
@@ -8,8 +8,8 @@ var ProgramD2Repository = /** @class */ (function () {
8
8
  function ProgramD2Repository() {
9
9
  }
10
10
  ProgramD2Repository.prototype.checkConfig = function (config) {
11
- var baseUrl = config.baseUrl, auth = config.auth, programId = config.programId, dataElements = config.dataElements;
12
- var d2Api = new d2_api_1.D2Api({ baseUrl: baseUrl, auth: auth });
11
+ var d2ApiOptions = config.d2ApiOptions, programId = config.programId, dataElements = config.dataElements;
12
+ var d2Api = new d2_api_1.D2Api(d2ApiOptions);
13
13
  return this.checkProgramIsOk(d2Api, programId, dataElements).flatMap(function (programIsOk) {
14
14
  if (programIsOk) {
15
15
  return Future_1.Future.success(programIsOk);
@@ -57,8 +57,8 @@ var TRACKER_IMPORT_JOB = "TRACKER_IMPORT_JOB";
57
57
  var EVENT_PROGRAM_STATUS = "COMPLETED";
58
58
  var ProgramLoggerD2Repository = /** @class */ (function () {
59
59
  function ProgramLoggerD2Repository(config, d2ProgramStage) {
60
- var baseUrl = config.baseUrl, auth = config.auth, programId = config.programId, dataElements = config.dataElements, organisationUnitId = config.organisationUnitId;
61
- this.api = new d2_api_1.D2Api({ baseUrl: baseUrl, auth: auth });
60
+ var d2ApiOptions = config.d2ApiOptions, programId = config.programId, dataElements = config.dataElements, organisationUnitId = config.organisationUnitId;
61
+ this.api = new d2_api_1.D2Api(d2ApiOptions);
62
62
  this.programId = programId;
63
63
  this.messageId = dataElements.messageId;
64
64
  this.messageTypeId = dataElements.messageTypeId;
@@ -71,7 +71,7 @@ var ProgramLoggerD2Repository = /** @class */ (function () {
71
71
  return __generator(this, function (_a) {
72
72
  switch (_a.label) {
73
73
  case 0:
74
- api = new d2_api_1.D2Api({ baseUrl: config.baseUrl, auth: config.auth });
74
+ api = new d2_api_1.D2Api(config.d2ApiOptions);
75
75
  return [4 /*yield*/, ProgramLoggerD2Repository.getProgramStage(api, config.programId)
76
76
  .toPromise()
77
77
  .catch(function (error) {
@@ -8,8 +8,8 @@ var TrackerProgramD2Repository = /** @class */ (function () {
8
8
  function TrackerProgramD2Repository() {
9
9
  }
10
10
  TrackerProgramD2Repository.prototype.checkConfig = function (config) {
11
- var baseUrl = config.baseUrl, auth = config.auth, trackerProgramId = config.trackerProgramId;
12
- var d2Api = new d2_api_1.D2Api({ baseUrl: baseUrl, auth: auth });
11
+ var d2ApiOptions = config.d2ApiOptions, trackerProgramId = config.trackerProgramId;
12
+ var d2Api = new d2_api_1.D2Api(d2ApiOptions);
13
13
  return (0, api_futures_1.apiToFuture)(d2Api.models.programs.get({
14
14
  fields: trackerProgramFields,
15
15
  filter: { id: { eq: trackerProgramId } },
@@ -30,8 +30,8 @@ var TRACKER_EVENT_DEFAULT_STATUS = "ACTIVE";
30
30
  var TRACKER_ORG_UNIT_ALL_MODE = "ALL";
31
31
  var TrackerProgramLoggerD2Repository = /** @class */ (function () {
32
32
  function TrackerProgramLoggerD2Repository(config) {
33
- var baseUrl = config.baseUrl, auth = config.auth, trackerProgramId = config.trackerProgramId, messageTypeId = config.messageTypeId;
34
- this.api = new d2_api_1.D2Api({ baseUrl: baseUrl, auth: auth });
33
+ var d2ApiOptions = config.d2ApiOptions, trackerProgramId = config.trackerProgramId, messageTypeId = config.messageTypeId;
34
+ this.api = new d2_api_1.D2Api(d2ApiOptions);
35
35
  this.trackerProgramId = trackerProgramId;
36
36
  this.messageTypeId = messageTypeId;
37
37
  }
@@ -76,10 +76,7 @@ var TrackerProgramLoggerD2Repository = /** @class */ (function () {
76
76
  enrollment: enrollmentId,
77
77
  })).flatMap(function (response) {
78
78
  var _a;
79
- // Temporal fix while we wait for PR#156 to be merged in d2-api
80
- // https://github.com/EyeSeeTea/d2-api/pull/156
81
- var newResponse = response;
82
- var instances = newResponse.instances || newResponse.enrollments;
79
+ var instances = response.instances;
83
80
  var orgUnitId = (_a = instances[0]) === null || _a === void 0 ? void 0 : _a.orgUnit;
84
81
  if (orgUnitId) {
85
82
  return Future_1.Future.success(orgUnitId);
@@ -1,3 +1,4 @@
1
+ import { D2ApiOptions } from "../../types/d2-api";
1
2
  import { Maybe } from "../../utils/ts-utils";
2
3
  import { Id } from "./Base";
3
4
  interface LoggerConfigBase {
@@ -9,24 +10,18 @@ export interface ConsoleLoggerConfig extends LoggerConfigBase {
9
10
  }
10
11
  export interface ProgramLoggerConfig extends LoggerConfigBase {
11
12
  type: "program";
12
- baseUrl: string;
13
- auth: Maybe<Auth>;
13
+ d2ApiOptions: D2ApiOptions;
14
14
  programId: Id;
15
15
  dataElements: DataElements;
16
16
  organisationUnitId: Id;
17
17
  }
18
- type Auth = {
19
- username: string;
20
- password: string;
21
- };
22
18
  export type DataElements = {
23
19
  messageId: Id;
24
20
  messageTypeId: Id;
25
21
  };
26
22
  export interface TrackerProgramLoggerConfig extends LoggerConfigBase {
27
23
  type: "trackerProgram";
28
- baseUrl: string;
29
- auth: Maybe<Auth>;
24
+ d2ApiOptions: D2ApiOptions;
30
25
  trackerProgramId: Id;
31
26
  messageTypeId: Maybe<Id>;
32
27
  }
package/index.d.ts CHANGED
@@ -32,4 +32,6 @@ type LoggerType = {
32
32
  console: ConsoleLogger;
33
33
  };
34
34
  declare function initLogger<Config extends LoggerConfig>(config: Config): Promise<LoggerType[Config["type"]]>;
35
- export { ConsoleLogger, ProgramLogger, TrackerProgramLogger, initLogger, BatchLogContent };
35
+ export type { D2ApiOptions as LoggerD2ApiOptions } from "./types/d2-api";
36
+ export type { BatchLogContent };
37
+ export { ConsoleLogger, ProgramLogger, TrackerProgramLogger, initLogger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eyeseetea/d2-logger",
3
- "version": "1.2.0-beta.2",
3
+ "version": "1.2.0-beta.3",
4
4
  "description": "DHIS2 library that allows a certain application to register logs as events in a DHIS2 event program, tracker program or simply display logs on the console.",
5
5
  "author": "EyeSeeTea team <info@eyeseetea.com>",
6
6
  "license": "GPL-3.0",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.5.4",
30
- "@eyeseetea/d2-api": "1.14.0",
30
+ "@eyeseetea/d2-api": "1.20.0",
31
31
  "cmd-ts": "0.13.0",
32
32
  "real-cancellable-promise": "^1.1.2",
33
33
  "typed-immutable-map": "0.2.0"
@@ -83,7 +83,7 @@ function getCommand() {
83
83
  }),
84
84
  },
85
85
  handler: function (args) { return __awaiter(_this, void 0, void 0, function () {
86
- var url, auth, orgUnitId, programId, messageTypeId, messageId, debug, logger, api, info, e_1;
86
+ var url, auth, orgUnitId, programId, messageTypeId, messageId, debug, d2ApiOptions, logger, api, info, e_1;
87
87
  return __generator(this, function (_a) {
88
88
  switch (_a.label) {
89
89
  case 0:
@@ -91,11 +91,15 @@ function getCommand() {
91
91
  _a.label = 1;
92
92
  case 1:
93
93
  _a.trys.push([1, 5, , 6]);
94
+ d2ApiOptions = {
95
+ baseUrl: url,
96
+ auth: auth,
97
+ backend: "xhr",
98
+ };
94
99
  return [4 /*yield*/, (0, __1.initLogger)({
95
100
  type: "program",
96
101
  debug: debug,
97
- baseUrl: url,
98
- auth: auth,
102
+ d2ApiOptions: d2ApiOptions,
99
103
  organisationUnitId: orgUnitId,
100
104
  programId: programId,
101
105
  dataElements: {
@@ -93,7 +93,7 @@ function getCommand() {
93
93
  }),
94
94
  },
95
95
  handler: function (args) { return __awaiter(_this, void 0, void 0, function () {
96
- var url, auth, trackerProgramId, trackedEntityId, programStageId, enrollmentId, messageTypeId, messageId, debug, logger, api, info, e_1;
96
+ var url, auth, trackerProgramId, trackedEntityId, programStageId, enrollmentId, messageTypeId, messageId, debug, d2ApiOptions, logger, api, info, e_1;
97
97
  return __generator(this, function (_a) {
98
98
  switch (_a.label) {
99
99
  case 0:
@@ -101,11 +101,15 @@ function getCommand() {
101
101
  _a.label = 1;
102
102
  case 1:
103
103
  _a.trys.push([1, 4, , 5]);
104
+ d2ApiOptions = {
105
+ baseUrl: url,
106
+ auth: auth,
107
+ backend: "xhr",
108
+ };
104
109
  return [4 /*yield*/, (0, __1.initLogger)({
105
110
  type: "trackerProgram",
106
111
  debug: debug,
107
- baseUrl: url,
108
- auth: auth,
112
+ d2ApiOptions: d2ApiOptions,
109
113
  trackerProgramId: trackerProgramId,
110
114
  messageTypeId: messageTypeId,
111
115
  })];
package/scripts/common.js CHANGED
@@ -59,7 +59,7 @@ function getD2ApiFromArgs(args) {
59
59
  var _a = args.auth
60
60
  ? { baseUrl: args.url, auth: args.auth }
61
61
  : getApiOptionsFromUrl(args.url), baseUrl = _a.baseUrl, auth = _a.auth;
62
- return new d2_api_1.D2Api({ baseUrl: baseUrl, auth: auth });
62
+ return new d2_api_1.D2Api({ baseUrl: baseUrl, auth: auth, backend: "xhr" });
63
63
  }
64
64
  exports.getD2ApiFromArgs = getD2ApiFromArgs;
65
65
  function getApiUrlOption(options) {
package/types/d2-api.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { CancelableResponse } from "@eyeseetea/d2-api";
2
- export { D2Api } from "@eyeseetea/d2-api/2.36";
3
- export type { MetadataPick } from "@eyeseetea/d2-api/2.36";
4
- export type { D2TrackerEvent, DataValue } from "@eyeseetea/d2-api/api/trackerEvents";
2
+ export { D2Api } from "@eyeseetea/d2-api/2.40";
3
+ export type { MetadataPick } from "@eyeseetea/d2-api/2.40";
4
+ export type { D2TrackerEventToPost, DataValue } from "@eyeseetea/d2-api/api/trackerEvents";
5
+ export type { D2ApiOptions } from "@eyeseetea/d2-api/api/d2Api";
package/types/d2-api.js CHANGED
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.D2Api = exports.CancelableResponse = void 0;
4
4
  var d2_api_1 = require("@eyeseetea/d2-api");
5
5
  Object.defineProperty(exports, "CancelableResponse", { enumerable: true, get: function () { return d2_api_1.CancelableResponse; } });
6
- var _2_36_1 = require("@eyeseetea/d2-api/2.36");
7
- Object.defineProperty(exports, "D2Api", { enumerable: true, get: function () { return _2_36_1.D2Api; } });
6
+ var _2_40_1 = require("@eyeseetea/d2-api/2.40");
7
+ Object.defineProperty(exports, "D2Api", { enumerable: true, get: function () { return _2_40_1.D2Api; } });