@agility/management-sdk 0.1.35 → 0.1.36

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.
@@ -40,6 +40,7 @@ exports.ContentMethods = void 0;
40
40
  var clientInstance_1 = require("./clientInstance");
41
41
  var batchMethods_1 = require("./batchMethods");
42
42
  var exception_1 = require("../models/exception");
43
+ var queryString_1 = require("../util/queryString");
43
44
  var ContentMethods = /** @class */ (function () {
44
45
  function ContentMethods(options) {
45
46
  this._options = options;
@@ -370,12 +371,20 @@ var ContentMethods = /** @class */ (function () {
370
371
  };
371
372
  ContentMethods.prototype.getContentItems = function (referenceName, guid, locale, listParams) {
372
373
  return __awaiter(this, void 0, void 0, function () {
373
- var apiPath, resp, err_10;
374
+ var queryParams, apiPath, resp, err_10;
374
375
  return __generator(this, function (_a) {
375
376
  switch (_a.label) {
376
377
  case 0:
377
378
  _a.trys.push([0, 2, , 3]);
378
- apiPath = "".concat(locale, "/list/").concat(referenceName, "?filter=").concat(listParams.filter, "&fields=").concat(listParams.fields, "&sortDirection=").concat(listParams.sortDirection, "&sortField=").concat(listParams.sortField, "&take=").concat(listParams.take, "&skip=").concat(listParams.skip);
379
+ queryParams = (0, queryString_1.buildQueryString)({
380
+ filter: listParams.filter,
381
+ fields: listParams.fields,
382
+ sortDirection: listParams.sortDirection,
383
+ sortField: listParams.sortField,
384
+ take: listParams.take,
385
+ skip: listParams.skip
386
+ });
387
+ apiPath = "".concat(locale, "/list/").concat(referenceName).concat(queryParams);
379
388
  return [4 /*yield*/, this._clientInstance.executeGet(apiPath, guid, this._options.token)];
380
389
  case 1:
381
390
  resp = _a.sent();
@@ -390,13 +399,21 @@ var ContentMethods = /** @class */ (function () {
390
399
  };
391
400
  ContentMethods.prototype.getContentList = function (referenceName_1, guid_1, locale_1, listParams_1) {
392
401
  return __awaiter(this, arguments, void 0, function (referenceName, guid, locale, listParams, filterObject) {
393
- var apiPath, resp, err_11;
402
+ var queryParams, apiPath, resp, err_11;
394
403
  if (filterObject === void 0) { filterObject = null; }
395
404
  return __generator(this, function (_a) {
396
405
  switch (_a.label) {
397
406
  case 0:
398
407
  _a.trys.push([0, 2, , 3]);
399
- apiPath = "".concat(locale, "/list/").concat(referenceName, "?fields=").concat(listParams.fields, "&sortDirection=").concat(listParams.sortDirection, "&sortField=").concat(listParams.sortField, "&take=").concat(listParams.take, "&skip=").concat(listParams.skip, "&showDeleted=").concat(listParams.showDeleted);
408
+ queryParams = (0, queryString_1.buildQueryString)({
409
+ fields: listParams.fields,
410
+ sortDirection: listParams.sortDirection,
411
+ sortField: listParams.sortField,
412
+ take: listParams.take,
413
+ skip: listParams.skip,
414
+ showDeleted: listParams.showDeleted
415
+ });
416
+ apiPath = "".concat(locale, "/list/").concat(referenceName).concat(queryParams);
400
417
  return [4 /*yield*/, this._clientInstance.executePost(apiPath, guid, this._options.token, filterObject)];
401
418
  case 1:
402
419
  resp = _a.sent();
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Builds a query string from an object of parameters.
3
+ * Only includes parameters that have actual values (skips undefined, null, and empty strings).
4
+ *
5
+ * @param params - Object containing key-value pairs for query parameters
6
+ * @returns Query string starting with '?' if parameters exist, empty string otherwise
7
+ */
8
+ export declare function buildQueryString(params: Record<string, any>): string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildQueryString = buildQueryString;
4
+ /**
5
+ * Builds a query string from an object of parameters.
6
+ * Only includes parameters that have actual values (skips undefined, null, and empty strings).
7
+ *
8
+ * @param params - Object containing key-value pairs for query parameters
9
+ * @returns Query string starting with '?' if parameters exist, empty string otherwise
10
+ */
11
+ function buildQueryString(params) {
12
+ var queryParams = [];
13
+ for (var _i = 0, _a = Object.entries(params); _i < _a.length; _i++) {
14
+ var _b = _a[_i], key = _b[0], value = _b[1];
15
+ // Skip undefined and null values
16
+ if (value === undefined || value === null) {
17
+ continue;
18
+ }
19
+ // Skip empty strings
20
+ if (typeof value === 'string' && value === '') {
21
+ continue;
22
+ }
23
+ // Include all other values (numbers including 0, booleans including false, non-empty strings)
24
+ queryParams.push("".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value)));
25
+ }
26
+ return queryParams.length > 0 ? "?".concat(queryParams.join('&')) : '';
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agility/management-sdk",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "description": "Agility CMS Tyescript SDK for Management API.",
5
5
  "repository": {
6
6
  "type": "git",