@golemio/municipal-libraries 1.3.0 → 1.3.2-dev.1464712295

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.
@@ -1,4 +1,7 @@
1
1
  import { DataSource } from "@golemio/core/dist/integration-engine/datasources";
2
2
  export declare class MunicipalLibrariesDataSourceFactory {
3
- static getDataSource(): DataSource;
3
+ private url;
4
+ constructor();
5
+ getDataSource(): Promise<DataSource>;
6
+ private getHeadersWithCookie;
4
7
  }
@@ -1,22 +1,63 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.MunicipalLibrariesDataSourceFactory = void 0;
4
13
  const _sch_1 = require("../../schema-definitions");
5
- const config_1 = require("@golemio/core/dist/integration-engine/config");
14
+ const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken");
6
15
  const datasources_1 = require("@golemio/core/dist/integration-engine/datasources");
7
16
  const HTTPFetchProtocolStrategy_1 = require("@golemio/core/dist/integration-engine/datasources/protocol-strategy/HTTPFetchProtocolStrategy");
17
+ const Di_1 = require("@golemio/core/dist/integration-engine/ioc/Di");
18
+ const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
8
19
  const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
9
20
  class MunicipalLibrariesDataSourceFactory {
10
- static getDataSource() {
11
- return new datasources_1.DataSource(_sch_1.MunicipalLibraries.datasources.municipalLibrariesDatasource.name, new HTTPFetchProtocolStrategy_1.HTTPFetchProtocolStrategy({
12
- headers: {},
13
- method: "GET",
14
- responseType: "text",
15
- url: config_1.config.datasources.MunicipalLibraries,
16
- }), new datasources_1.XMLDataTypeStrategy({
17
- resultsPath: "pobocky.pobocka",
18
- xml2jsParams: { explicitArray: false, ignoreAttrs: true, trim: true, normalize: true, emptyTag: () => null },
19
- }), new golemio_validator_1.JSONSchemaValidator(_sch_1.MunicipalLibraries.datasources.municipalLibrariesDatasource.name + "Validator", _sch_1.MunicipalLibraries.datasources.municipalLibrariesDatasource.jsonSchema));
21
+ constructor() {
22
+ const simpleConfig = Di_1.IntegrationEngineContainer.resolve(CoreToken_1.CoreToken.SimpleConfig);
23
+ this.url = simpleConfig.getValue("module.MunicipalLibraries");
24
+ }
25
+ getDataSource() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return new datasources_1.DataSource(_sch_1.MunicipalLibraries.datasources.municipalLibrariesDatasource.name, new HTTPFetchProtocolStrategy_1.HTTPFetchProtocolStrategy({
28
+ headers: {
29
+ Cookie: yield this.getHeadersWithCookie(),
30
+ },
31
+ method: "GET",
32
+ responseType: "text",
33
+ url: this.url,
34
+ }), new datasources_1.XMLDataTypeStrategy({
35
+ resultsPath: "pobocky.pobocka",
36
+ xml2jsParams: { explicitArray: false, ignoreAttrs: true, trim: true, normalize: true, emptyTag: () => null },
37
+ }), new golemio_validator_1.JSONSchemaValidator(_sch_1.MunicipalLibraries.datasources.municipalLibrariesDatasource.name + "Validator", _sch_1.MunicipalLibraries.datasources.municipalLibrariesDatasource.jsonSchema));
38
+ });
39
+ }
40
+ getHeadersWithCookie() {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ try {
43
+ const result = yield fetch(this.url, {
44
+ redirect: "manual",
45
+ });
46
+ const result2 = yield fetch(result.headers.get("location"), {
47
+ redirect: "manual",
48
+ headers: {
49
+ Cookie: result.headers.get("set-cookie"),
50
+ },
51
+ });
52
+ const headers = new Headers();
53
+ headers.append("Cookie", result.headers.get("set-cookie"));
54
+ headers.append("Cookie", result2.headers.get("set-cookie"));
55
+ return headers.get("Cookie");
56
+ }
57
+ catch (error) {
58
+ throw new golemio_errors_1.GeneralError("Error while getting headers with cookie", this.constructor.name, error);
59
+ }
60
+ });
20
61
  }
21
62
  }
22
63
  exports.MunicipalLibrariesDataSourceFactory = MunicipalLibrariesDataSourceFactory;
@@ -1 +1 @@
1
- {"version":3,"file":"MunicipalLibrariesDataSource.js","sourceRoot":"","sources":["../../../src/integration-engine/datasources/MunicipalLibrariesDataSource.ts"],"names":[],"mappings":";;;AAAA,mDAA0C;AAC1C,yEAAsE;AACtE,mFAAoG;AACpG,6IAA0I;AAC1I,mFAAkF;AAElF,MAAa,mCAAmC;IACrC,MAAM,CAAC,aAAa;QACvB,OAAO,IAAI,wBAAU,CACjB,yBAAkB,CAAC,WAAW,CAAC,4BAA4B,CAAC,IAAI,EAChE,IAAI,qDAAyB,CAAC;YAC1B,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,KAAK;YACb,YAAY,EAAE,MAAM;YACpB,GAAG,EAAE,eAAM,CAAC,WAAW,CAAC,kBAAkB;SAC7C,CAAC,EACF,IAAI,iCAAmB,CAAC;YACpB,WAAW,EAAE,iBAAiB;YAC9B,YAAY,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE;SAC/G,CAAC,EACF,IAAI,uCAAmB,CACnB,yBAAkB,CAAC,WAAW,CAAC,4BAA4B,CAAC,IAAI,GAAG,WAAW,EAC9E,yBAAkB,CAAC,WAAW,CAAC,4BAA4B,CAAC,UAAU,CACzE,CACJ,CAAC;IACN,CAAC;CACJ;AApBD,kFAoBC"}
1
+ {"version":3,"file":"MunicipalLibrariesDataSource.js","sourceRoot":"","sources":["../../../src/integration-engine/dat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AK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAE,EAAE;oBACzD,QAAQ,EAAE,QAAQ;oBAClB,OAAO,EAAE;wBACL,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAE;qBAC5C;iBACJ,CAAC,CAAC;gBAEH,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;gBAE9B,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAE,CAAC,CAAC;gBAC5D,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAE,CAAC,CAAC;gBAE7D,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;aAChC;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,IAAI,6BAAY,CAAC,yCAAyC,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;aACnG;QACL,CAAC;KAAA;CACJ;AApDD,kFAoDC"}
@@ -2,7 +2,7 @@ import { AbstractEmptyTask } from "@golemio/core/dist/integration-engine";
2
2
  export declare class RefreshDataInDBTask extends AbstractEmptyTask {
3
3
  readonly queueName = "refreshDataInDB";
4
4
  readonly queueTtl: number;
5
- private dataSource;
5
+ private dataSourceFactory;
6
6
  private transformation;
7
7
  private repository;
8
8
  constructor(queuePrefix: string);
@@ -10,22 +10,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.RefreshDataInDBTask = void 0;
13
- const integration_engine_1 = require("@golemio/core/dist/integration-engine");
14
13
  const _ie_1 = require("../..");
15
- const repositories_1 = require("../../repositories");
16
14
  const datasources_1 = require("../../datasources");
15
+ const repositories_1 = require("../../repositories");
16
+ const integration_engine_1 = require("@golemio/core/dist/integration-engine");
17
17
  class RefreshDataInDBTask extends integration_engine_1.AbstractEmptyTask {
18
18
  constructor(queuePrefix) {
19
19
  super(queuePrefix);
20
20
  this.queueName = "refreshDataInDB";
21
21
  this.queueTtl = 59 * 60 * 1000; // 59 minutes
22
- this.dataSource = datasources_1.MunicipalLibrariesDataSourceFactory.getDataSource();
22
+ this.dataSourceFactory = new datasources_1.MunicipalLibrariesDataSourceFactory();
23
23
  this.transformation = new _ie_1.MunicipalLibrariesTransformation();
24
24
  this.repository = new repositories_1.MunicipalLibrariesRepository();
25
25
  }
26
26
  execute() {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
- const data = yield this.dataSource.getAll();
28
+ const dataSource = yield this.dataSourceFactory.getDataSource();
29
+ const data = yield dataSource.getAll();
29
30
  const transformedData = yield this.transformation.transform(data);
30
31
  yield this.repository.saveLibraries(transformedData);
31
32
  const promises = transformedData.libraries.map((data) => {
@@ -1 +1 @@
1
- {"version":3,"file":"RefreshDataInDBTask.js","sourceRoot":"","sources":["../../../../src/integration-engine/workers/tasks/RefreshDataInDBTask.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8EAAwF;AAExF,+BAAuD;AACvD,qDAAgE;AAChE,mDAAsE;AAGtE,MAAa,mBAAoB,SAAQ,sCAAiB;IAQtD,YAAY,WAAmB;QAC3B,KAAK,CAAC,WAAW,CAAC,CAAC;QARP,cAAS,GAAG,iBAAiB,CAAC;QAC9B,aAAQ,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;QAQpD,IAAI,CAAC,UAAU,GAAG,iDAAmC,CAAC,aAAa,EAAE,CAAC;QACtE,IAAI,CAAC,cAAc,GAAG,IAAI,sCAAgC,EAAE,CAAC;QAC7D,IAAI,CAAC,UAAU,GAAG,IAAI,2CAA4B,EAAE,CAAC;IACzD,CAAC;IAEe,OAAO;;YACnB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;YAC5C,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,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAClE,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;YAErD,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAgB,EAAE,EAAE;gBAChE,OAAO,iCAAY,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,EAAE,gBAAgB,EAAE;oBAC1E,EAAE,EAAE,IAAI,CAAC,EAAE;iBACd,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;YACH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChC,CAAC;KAAA;CACJ;AA5BD,kDA4BC"}
@@ -17,6 +17,7 @@ Modul slouží k ukládání a poskytování informací o městských knihovnác
17
17
 
18
18
  - zdroj dat
19
19
  - url: [config.datasources.MunicipalLibraries](https://www.mlp.cz/cz/pobocky/?export=xml)
20
+ - pozor při načtení url proběhne několik přesměrování na doplnění cookies
20
21
  - formát dat
21
22
  - protokol: http
22
23
  - datový typ: json
package/docs/index.md ADDED
@@ -0,0 +1,3 @@
1
+ # @golemio/municipal-libraries
2
+
3
+ This module is intended for use with Golemio services. Refer [here](https://gitlab.com/operator-ict/golemio/code/modules/core/-/blob/development/README.md) for further information on usage, local development and more.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golemio/municipal-libraries",
3
- "version": "1.3.0",
3
+ "version": "1.3.2-dev.1464712295",
4
4
  "description": "Golemio Municipal Libraries Module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "@commitlint/config-conventional": "^11.0.0",
35
35
  "@golemio/city-districts": "1.2.10",
36
36
  "@golemio/cli": "1.5.0",
37
- "@golemio/core": "1.10.3",
37
+ "@golemio/core": "1.14.1",
38
38
  "@golemio/db-common": "1.1.4",
39
39
  "@golemio/eslint-config": "1.1.2",
40
40
  "@types/chai": "4.2.3",