@qrvey/utils 1.12.0-3 → 1.12.0-4

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,9 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const Request_1 = __importDefault(require("../helpers/Request"));
3
+ const Request_1 = require("../helpers/Request");
7
4
  const CHART_ENDPOINT_1 = require("../constants/CHART_ENDPOINT");
8
5
  const UCHART_ENDPOINT_1 = require("../constants/UCHART_ENDPOINT");
9
6
  const UCHART_PAGINATION_ENDPOINT_1 = require("../constants/UCHART_PAGINATION_ENDPOINT");
@@ -23,7 +20,7 @@ class ChartsApi {
23
20
  data.logic = data.filters;
24
21
  delete data.filters;
25
22
  }
26
- return Request_1.default.post(Object.assign(Object.assign({}, this.config), { endpoint: newEndpoint ? UCHART_ENDPOINT_1.UCHART_ENDPOINT : CHART_ENDPOINT_1.CHART_ENDPOINT, signal }), newEndpoint ? "" : "/results", data);
23
+ return Request_1.Request.post(Object.assign(Object.assign({}, this.config), { endpoint: newEndpoint ? UCHART_ENDPOINT_1.UCHART_ENDPOINT : CHART_ENDPOINT_1.CHART_ENDPOINT, signal }), newEndpoint ? "" : "/results", data);
27
24
  }
28
25
  getResultsPagination(data, ignoreSignal = false) {
29
26
  const signal = ignoreSignal ? undefined : this.createSignal();
@@ -31,7 +28,7 @@ class ChartsApi {
31
28
  data.logic = data.filters;
32
29
  delete data.filters;
33
30
  }
34
- return Request_1.default.post(Object.assign(Object.assign({}, this.config), { endpoint: UCHART_PAGINATION_ENDPOINT_1.UCHART_PAGINATION_ENDPOINT, signal }), "", data);
31
+ return Request_1.Request.post(Object.assign(Object.assign({}, this.config), { endpoint: UCHART_PAGINATION_ENDPOINT_1.UCHART_PAGINATION_ENDPOINT, signal }), "", data);
35
32
  }
36
33
  }
37
34
  exports.default = ChartsApi;
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getAllQrveys = void 0;
7
4
  const QRVEY_ENDPOINT_1 = require("../constants/QRVEY_ENDPOINT");
8
- const Request_1 = __importDefault(require("../helpers/Request"));
5
+ const Request_1 = require("../helpers/Request");
9
6
  /**
10
7
  * Request function for getting Qrveys such as Web Forms and Datasets. Use params for getting precise data
11
8
  * @param config Configuration
12
9
  * @param params Object for getting precise data
13
10
  */
14
11
  function getAllQrveys(config, params) {
15
- return Request_1.default.post(Object.assign(Object.assign({}, config), { endpoint: QRVEY_ENDPOINT_1.QRVEY_ENDPOINT }), "/all", params);
12
+ return Request_1.Request.post(Object.assign(Object.assign({}, config), { endpoint: QRVEY_ENDPOINT_1.QRVEY_ENDPOINT }), "/all", params);
16
13
  }
17
14
  exports.getAllQrveys = getAllQrveys;
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getDatasetColumns = void 0;
7
4
  const CHART_ENDPOINT_1 = require("../constants/CHART_ENDPOINT");
8
- const Request_1 = __importDefault(require("../helpers/Request"));
5
+ const Request_1 = require("../helpers/Request");
9
6
  const BDatasetsToUIDatasets_adapter_1 = require("../adapters/BDatasetsToUIDatasets.adapter");
10
7
  const getDefaultQuestionListOptionsAttributes_1 = require("../helpers/getDefaultQuestionListOptionsAttributes");
11
8
  const localization_1 = require("../../format/localization");
@@ -16,7 +13,7 @@ const localization_1 = require("../../format/localization");
16
13
  */
17
14
  function getDatasetColumns(config, qrveyid) {
18
15
  const lang = (0, localization_1.chooseLang)(config);
19
- return Request_1.default.post(Object.assign(Object.assign({}, config), { qrveyid, endpoint: CHART_ENDPOINT_1.CHART_ENDPOINT }), "/question/list", {
16
+ return Request_1.Request.post(Object.assign(Object.assign({}, config), { qrveyid, endpoint: CHART_ENDPOINT_1.CHART_ENDPOINT }), "/question/list", {
20
17
  optionsAttributes: (0, getDefaultQuestionListOptionsAttributes_1.getDefaultQuestionListOptionsAttributes)(),
21
18
  extend: true,
22
19
  }, { lang })
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getDatasetsByIds = void 0;
7
- const Request_1 = __importDefault(require("../helpers/Request"));
4
+ const Request_1 = require("../helpers/Request");
8
5
  const BDatasetsToUIDatasets_adapter_1 = require("../adapters/BDatasetsToUIDatasets.adapter");
9
6
  const isEmpty_1 = require("../../general/mix/isEmpty");
10
7
  const localization_1 = require("../../format/localization");
@@ -18,7 +15,7 @@ const QUESTION_LIST_BULK_ENDPOINT_1 = require("../constants/QUESTION_LIST_BULK_E
18
15
  function getDatasetsByIds(config, qrveyids = []) {
19
16
  if (Array.isArray(qrveyids) && !(0, isEmpty_1.isEmpty)(qrveyids)) {
20
17
  const lang = (0, localization_1.chooseLang)(config);
21
- return Request_1.default.post(Object.assign(Object.assign({}, config), { endpoint: QUESTION_LIST_BULK_ENDPOINT_1.QUESTION_LIST_BULK_ENDPOINT }), "", {
18
+ return Request_1.Request.post(Object.assign(Object.assign({}, config), { endpoint: QUESTION_LIST_BULK_ENDPOINT_1.QUESTION_LIST_BULK_ENDPOINT }), "", {
22
19
  optionsAttributes: (0, getDefaultQuestionListOptionsAttributes_1.getDefaultQuestionListOptionsAttributes)(),
23
20
  qrveyids,
24
21
  }, { lang })
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getModel = void 0;
7
- const Request_1 = __importDefault(require("../helpers/Request"));
4
+ const Request_1 = require("../helpers/Request");
8
5
  const localization_1 = require("../../format/localization");
9
6
  const MODEL_ENDPOINT_1 = require("../constants/MODEL_ENDPOINT");
10
7
  const BModelToUIModel_adapter_1 = require("../adapters/BModelToUIModel.adapter");
11
8
  function getModel(config, params) {
12
9
  const lang = (0, localization_1.chooseLang)(config);
13
10
  const data = { lang, logic: config.logic || [] };
14
- return Request_1.default.post(Object.assign(Object.assign({}, config), { endpoint: MODEL_ENDPOINT_1.ANALYTIQ_ENDPOINT }), "", data, Object.assign(Object.assign({}, params), { lang })).then(BModelToUIModel_adapter_1.BModelToUIModel);
11
+ return Request_1.Request.post(Object.assign(Object.assign({}, config), { endpoint: MODEL_ENDPOINT_1.ANALYTIQ_ENDPOINT }), "", data, Object.assign(Object.assign({}, params), { lang })).then(BModelToUIModel_adapter_1.BModelToUIModel);
15
12
  }
16
13
  exports.getModel = getModel;
@@ -1,4 +1,4 @@
1
- export default class Request {
1
+ export declare class Request {
2
2
  static checkStatus(response: any): Promise<any>;
3
3
  static hasQvToken(config: any): boolean;
4
4
  static getQvToken(config: any): any;
@@ -6,6 +6,7 @@ export default class Request {
6
6
  static hasApiKey(config: any): boolean;
7
7
  static getApiKey(config: any): any;
8
8
  static makeUrl(config: any, url: any, params?: any): string;
9
+ private static getApiUrl;
9
10
  static parseUrl: (url: any, config: any) => string;
10
11
  static requestConfig(reqData: any): any;
11
12
  static resolveRequest(reqData: any): Promise<any>;
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Request = void 0;
12
13
  const numericOffsetToISO_1 = require("../../dates/adapters/numericOffsetToISO");
13
14
  const isEmpty_1 = require("../../general/mix/isEmpty");
14
15
  const getAttribute_1 = require("../../general/object/getAttribute");
@@ -44,18 +45,30 @@ class Request {
44
45
  static makeUrl(config, url, params) {
45
46
  let _url = url;
46
47
  _url += typeof params === "object" ? (0, serialize_1.serialize)(params) : "";
47
- if (config.endpoint) {
48
+ if (!(0, isEmpty_1.isEmpty)(config.endpoint)) {
48
49
  const endpoint = config.endpoint;
49
- const version = `v${endpoint.version || 4}`;
50
- const api = this.hasQvToken(config) || this.hasApiKey(config) ? "devapi" : "api";
50
+ const version = `/v${endpoint.version || 4}`;
51
+ const admin = endpoint.admin ? "/admin" : "";
52
+ const api = Request.getApiUrl(config);
51
53
  const user = (0, getAttribute_1.getAttribute)(config, "user_id") || this.hasQvToken(config)
52
54
  ? "/user/:user_id"
53
55
  : "";
54
- const base = `/${api}/${version}${user}`;
56
+ const base = `${admin}${api}${version}${user}`;
55
57
  _url = (config.domain || "") + base + endpoint.uri + _url;
56
58
  }
57
59
  return this.parseUrl(_url, config);
58
60
  }
61
+ static getApiUrl(config) {
62
+ const endpoint = config.endpoint || {};
63
+ if (endpoint.noApi)
64
+ return "";
65
+ const isDevApi = !(0, isEmpty_1.isEmpty)(endpoint.devApi) && endpoint.devApi;
66
+ return isDevApi ||
67
+ ((0, isEmpty_1.isEmpty)(endpoint.devApi) &&
68
+ (this.hasQvToken(config) || this.hasApiKey(config)))
69
+ ? "/devapi"
70
+ : "/api";
71
+ }
59
72
  static requestConfig(reqData) {
60
73
  const cfg = {
61
74
  method: reqData.type,
@@ -103,5 +116,5 @@ class Request {
103
116
  return this.resolveRequest({ config, url, type: "POST", data, params });
104
117
  }
105
118
  }
119
+ exports.Request = Request;
106
120
  Request.parseUrl = (url, config) => (0, parseUrl_1.parseUrl)(url, (key) => (0, getAttribute_1.getAttribute)(config, key));
107
- exports.default = Request;
@@ -1,4 +1,7 @@
1
1
  export interface IEndpointConfig {
2
+ noApi?: boolean;
3
+ admin?: boolean;
4
+ devApi?: boolean;
2
5
  uri: string;
3
6
  version?: number;
4
7
  }
@@ -1,4 +1,4 @@
1
- import Request from "../helpers/Request";
1
+ import { Request } from "../helpers/Request";
2
2
  import { CHART_ENDPOINT } from "../constants/CHART_ENDPOINT";
3
3
  import { UCHART_ENDPOINT } from "../constants/UCHART_ENDPOINT";
4
4
  import { UCHART_PAGINATION_ENDPOINT } from "../constants/UCHART_PAGINATION_ENDPOINT";
@@ -1,5 +1,5 @@
1
1
  import { QRVEY_ENDPOINT } from "../constants/QRVEY_ENDPOINT";
2
- import Request from "../helpers/Request";
2
+ import { Request } from "../helpers/Request";
3
3
  /**
4
4
  * Request function for getting Qrveys such as Web Forms and Datasets. Use params for getting precise data
5
5
  * @param config Configuration
@@ -1,5 +1,5 @@
1
1
  import { CHART_ENDPOINT } from "../constants/CHART_ENDPOINT";
2
- import Request from "../helpers/Request";
2
+ import { Request } from "../helpers/Request";
3
3
  import { BDatasetsToUIDatasets } from "../adapters/BDatasetsToUIDatasets.adapter";
4
4
  import { getDefaultQuestionListOptionsAttributes } from "../helpers/getDefaultQuestionListOptionsAttributes";
5
5
  import { chooseLang } from "../../format/localization";
@@ -1,4 +1,4 @@
1
- import Request from "../helpers/Request";
1
+ import { Request } from "../helpers/Request";
2
2
  import { BDatasetsToUIDatasets } from "../adapters/BDatasetsToUIDatasets.adapter";
3
3
  import { isEmpty } from "../../general/mix/isEmpty";
4
4
  import { chooseLang } from "../../format/localization";
@@ -1,4 +1,4 @@
1
- import Request from "../helpers/Request";
1
+ import { Request } from "../helpers/Request";
2
2
  import { chooseLang } from "../../format/localization";
3
3
  import { ANALYTIQ_ENDPOINT } from "../constants/MODEL_ENDPOINT";
4
4
  import { BModelToUIModel } from "../adapters/BModelToUIModel.adapter";
@@ -1,4 +1,4 @@
1
- export default class Request {
1
+ export declare class Request {
2
2
  static checkStatus(response: any): Promise<any>;
3
3
  static hasQvToken(config: any): boolean;
4
4
  static getQvToken(config: any): any;
@@ -6,6 +6,7 @@ export default class Request {
6
6
  static hasApiKey(config: any): boolean;
7
7
  static getApiKey(config: any): any;
8
8
  static makeUrl(config: any, url: any, params?: any): string;
9
+ private static getApiUrl;
9
10
  static parseUrl: (url: any, config: any) => string;
10
11
  static requestConfig(reqData: any): any;
11
12
  static resolveRequest(reqData: any): Promise<any>;
@@ -12,7 +12,7 @@ import { isEmpty } from "../../general/mix/isEmpty";
12
12
  import { getAttribute } from "../../general/object/getAttribute";
13
13
  import { serialize } from "../../general/object/serialize";
14
14
  import { parseUrl } from "../../general/string/parseUrl";
15
- class Request {
15
+ export class Request {
16
16
  static checkStatus(response) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  if (!response.ok)
@@ -42,18 +42,30 @@ class Request {
42
42
  static makeUrl(config, url, params) {
43
43
  let _url = url;
44
44
  _url += typeof params === "object" ? serialize(params) : "";
45
- if (config.endpoint) {
45
+ if (!isEmpty(config.endpoint)) {
46
46
  const endpoint = config.endpoint;
47
- const version = `v${endpoint.version || 4}`;
48
- const api = this.hasQvToken(config) || this.hasApiKey(config) ? "devapi" : "api";
47
+ const version = `/v${endpoint.version || 4}`;
48
+ const admin = endpoint.admin ? "/admin" : "";
49
+ const api = Request.getApiUrl(config);
49
50
  const user = getAttribute(config, "user_id") || this.hasQvToken(config)
50
51
  ? "/user/:user_id"
51
52
  : "";
52
- const base = `/${api}/${version}${user}`;
53
+ const base = `${admin}${api}${version}${user}`;
53
54
  _url = (config.domain || "") + base + endpoint.uri + _url;
54
55
  }
55
56
  return this.parseUrl(_url, config);
56
57
  }
58
+ static getApiUrl(config) {
59
+ const endpoint = config.endpoint || {};
60
+ if (endpoint.noApi)
61
+ return "";
62
+ const isDevApi = !isEmpty(endpoint.devApi) && endpoint.devApi;
63
+ return isDevApi ||
64
+ (isEmpty(endpoint.devApi) &&
65
+ (this.hasQvToken(config) || this.hasApiKey(config)))
66
+ ? "/devapi"
67
+ : "/api";
68
+ }
57
69
  static requestConfig(reqData) {
58
70
  const cfg = {
59
71
  method: reqData.type,
@@ -102,4 +114,3 @@ class Request {
102
114
  }
103
115
  }
104
116
  Request.parseUrl = (url, config) => parseUrl(url, (key) => getAttribute(config, key));
105
- export default Request;
@@ -1,4 +1,7 @@
1
1
  export interface IEndpointConfig {
2
+ noApi?: boolean;
3
+ admin?: boolean;
4
+ devApi?: boolean;
2
5
  uri: string;
3
6
  version?: number;
4
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/utils",
3
- "version": "1.12.0-3",
3
+ "version": "1.12.0-4",
4
4
  "description": "Helper, Utils for all Qrvey Projects",
5
5
  "homepage": "https://bitbucket.org/qrvey/qrvey_utils/wiki/Home",
6
6
  "main": "dist/index.js",