@agility/content-fetch 2.0.6 → 2.0.8

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/dist/browser.js CHANGED
@@ -31,7 +31,7 @@
31
31
  let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${locale}`;
32
32
  return urlPath;
33
33
  }
34
- function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, contentLinkDepth, expandAllContentLinks) {
34
+ function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, filterString, contentLinkDepth, expandAllContentLinks) {
35
35
  let url = `/${contentType}/${referenceName}?contentLinkDepth=${contentLinkDepth}&`;
36
36
  filtersLogicOperator = filtersLogicOperator ? ` ${filtersLogicOperator} ` : " AND ";
37
37
  if (sort) {
@@ -53,6 +53,8 @@
53
53
  url += `${filter.property}[${filter.operator}]${filter.value}` + (i < filters.length - 1 ? filtersLogicOperator : "");
54
54
  }
55
55
  url += "&";
56
+ } else if (filterString) {
57
+ url += `filter=${encodeURIComponent(filterString)}&`;
56
58
  }
57
59
  if (expandAllContentLinks) {
58
60
  url += `expandAllContentLinks=${expandAllContentLinks}&`;
@@ -174,7 +176,7 @@
174
176
  requestParams.referenceName = sanitizeReferenceName(requestParams.referenceName);
175
177
  requestParams = { ...defaultParams2, ...requestParams };
176
178
  const req = {
177
- url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.contentLinkDepth, requestParams.expandAllContentLinks),
179
+ url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.filterString, requestParams.contentLinkDepth, requestParams.expandAllContentLinks),
178
180
  method: "get",
179
181
  baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
180
182
  headers: buildAuthHeader(this.config),
@@ -486,7 +488,7 @@
486
488
  //caching disabled by default
487
489
  }
488
490
  };
489
- function buildBaseUrl(guid) {
491
+ function buildBaseUrl(guid, region) {
490
492
  let baseUrlSuffixes = {
491
493
  u: "",
492
494
  c: "-ca",
@@ -496,11 +498,13 @@
496
498
  };
497
499
  let suffix = guid.substr(guid.length - 2, 2);
498
500
  let env = suffix.substr(1);
501
+ if (region) {
502
+ return region === "us" ? `https://api.aglty.io/${guid}` : `https://api-${region}.aglty.io/${guid}`;
503
+ }
499
504
  if (suffix.startsWith("-") && baseUrlSuffixes.hasOwnProperty(env)) {
500
505
  return `https://api${baseUrlSuffixes[env]}.aglty.io/${guid}`;
501
- } else {
502
- return `https://${guid}-api.agilitycms.cloud`;
503
506
  }
507
+ return `https://${guid}-api.agilitycms.cloud`;
504
508
  }
505
509
  function validateConfigParams(configParams) {
506
510
  if (!configParams.guid || configParams.guid.length == 0) {
@@ -523,7 +527,7 @@
523
527
  ...userConfig
524
528
  };
525
529
  if (!config.baseUrl) {
526
- config.baseUrl = buildBaseUrl(config?.guid || "");
530
+ config.baseUrl = buildBaseUrl(config?.guid || "", config?.region);
527
531
  } else {
528
532
  config.requiresGuidInHeaders = true;
529
533
  }
@@ -62,15 +62,51 @@ import { ApiClientInstance } from '../types/Client';
62
62
  * });
63
63
  */
64
64
  export interface ContentListRequestParams {
65
+ /**
66
+ * The unique reference name of the content list you wish to retrieve in the specified language.
67
+ */
65
68
  referenceName: string;
69
+ /**
70
+ * The locale code of the content you want to retrieve.
71
+ */
66
72
  locale?: string;
73
+ /**
74
+ * The language code of the content you want to retrieve.
75
+ * DEPRECATED: Use locale instead.
76
+ */
67
77
  languageCode?: string;
78
+ /**
79
+ * The depth, representing the levels in which you want linked content auto-resolved.
80
+ */
68
81
  contentLinkDepth?: number;
82
+ /**
83
+ * Whether or not to expand entire linked content references, includings lists and items that are rendered in the CMS as Grid or Link.
84
+ */
69
85
  expandAllContentLinks?: boolean;
86
+ /**
87
+ * The number of items to retrieve in this request. Default is 10. Maximum allowed is 250.
88
+ */
70
89
  take?: number;
90
+ /**
91
+ * The number of items to skip from the list. Used for implementing pagination.
92
+ */
71
93
  skip?: number;
94
+ /**
95
+ * The field to sort the results by. Example fields.title or properties.modified.
96
+ */
72
97
  sort?: string;
98
+ /**
99
+ * The direction to sort the results by.
100
+ */
73
101
  direction?: SortDirection;
102
+ /**
103
+ * Option: you can provide a plain text filter string as opposed to an array of filters. This is useful if you have brackets in your filter expression.
104
+ */
105
+ filterString?: string;
106
+ /**
107
+ * Provide an array of filters as opposed to a plain text filter string.
108
+ * If you need advanced filering with brackets, use the filterString operator.
109
+ */
74
110
  filters?: Array<Filter>;
75
111
  filtersLogicOperator?: FilterLogicOperator;
76
112
  }
package/dist/node.js CHANGED
@@ -49,7 +49,7 @@ function buildRequestUrlPath(config, locale) {
49
49
  let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${locale}`;
50
50
  return urlPath;
51
51
  }
52
- function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, contentLinkDepth, expandAllContentLinks) {
52
+ function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, filterString, contentLinkDepth, expandAllContentLinks) {
53
53
  let url = `/${contentType}/${referenceName}?contentLinkDepth=${contentLinkDepth}&`;
54
54
  filtersLogicOperator = filtersLogicOperator ? ` ${filtersLogicOperator} ` : " AND ";
55
55
  if (sort) {
@@ -71,6 +71,8 @@ function buildPathUrl(contentType, referenceName, skip, take, sort, direction, f
71
71
  url += `${filter.property}[${filter.operator}]${filter.value}` + (i < filters.length - 1 ? filtersLogicOperator : "");
72
72
  }
73
73
  url += "&";
74
+ } else if (filterString) {
75
+ url += `filter=${encodeURIComponent(filterString)}&`;
74
76
  }
75
77
  if (expandAllContentLinks) {
76
78
  url += `expandAllContentLinks=${expandAllContentLinks}&`;
@@ -192,7 +194,7 @@ function getContentList(requestParams) {
192
194
  requestParams.referenceName = sanitizeReferenceName(requestParams.referenceName);
193
195
  requestParams = { ...defaultParams2, ...requestParams };
194
196
  const req = {
195
- url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.contentLinkDepth, requestParams.expandAllContentLinks),
197
+ url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.filterString, requestParams.contentLinkDepth, requestParams.expandAllContentLinks),
196
198
  method: "get",
197
199
  baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
198
200
  headers: buildAuthHeader(this.config),
@@ -504,7 +506,7 @@ var defaultConfig = {
504
506
  //caching disabled by default
505
507
  }
506
508
  };
507
- function buildBaseUrl(guid) {
509
+ function buildBaseUrl(guid, region) {
508
510
  let baseUrlSuffixes = {
509
511
  u: "",
510
512
  c: "-ca",
@@ -514,11 +516,13 @@ function buildBaseUrl(guid) {
514
516
  };
515
517
  let suffix = guid.substr(guid.length - 2, 2);
516
518
  let env = suffix.substr(1);
519
+ if (region) {
520
+ return region === "us" ? `https://api.aglty.io/${guid}` : `https://api-${region}.aglty.io/${guid}`;
521
+ }
517
522
  if (suffix.startsWith("-") && baseUrlSuffixes.hasOwnProperty(env)) {
518
523
  return `https://api${baseUrlSuffixes[env]}.aglty.io/${guid}`;
519
- } else {
520
- return `https://${guid}-api.agilitycms.cloud`;
521
524
  }
525
+ return `https://${guid}-api.agilitycms.cloud`;
522
526
  }
523
527
  function validateConfigParams(configParams) {
524
528
  if (!configParams.guid || configParams.guid.length == 0) {
@@ -541,7 +545,7 @@ var ApiClient = class {
541
545
  ...userConfig
542
546
  };
543
547
  if (!config.baseUrl) {
544
- config.baseUrl = buildBaseUrl(config?.guid || "");
548
+ config.baseUrl = buildBaseUrl(config?.guid || "", config?.region);
545
549
  } else {
546
550
  config.requiresGuidInHeaders = true;
547
551
  }
@@ -4,6 +4,10 @@ export interface Config {
4
4
  * This is mostly used for testing purposes.
5
5
  */
6
6
  baseUrl?: string | null;
7
+ /**
8
+ * Optional region for those guids which are missing a region. Use this to override.
9
+ */
10
+ region?: "ca" | "eu" | "us" | "aus" | "dev";
7
11
  /**
8
12
  * If true, the API will use the Preview API. If false, it will use the Fetch API. Default is false.
9
13
  * Make sure the API Key provided matches this value.
package/dist/utils.d.ts CHANGED
@@ -8,7 +8,7 @@ declare function logInfo({ config, message }: LogProps): void;
8
8
  declare function logWarning({ config, message }: LogProps): void;
9
9
  declare function logError({ config, message }: LogProps): void;
10
10
  declare function buildRequestUrlPath(config: any, locale: any): string;
11
- declare function buildPathUrl(contentType: any, referenceName: any, skip: any, take: any, sort: any, direction: any, filters: any, filtersLogicOperator: any, contentLinkDepth: any, expandAllContentLinks: any): string;
11
+ declare function buildPathUrl(contentType: any, referenceName: any, skip: any, take: any, sort: any, direction: any, filters: any, filtersLogicOperator: any, filterString: any, contentLinkDepth: any, expandAllContentLinks: any): string;
12
12
  declare function buildAuthHeader(config: any): any;
13
13
  declare function isHttps(url: any): boolean;
14
14
  export { buildPathUrl, buildAuthHeader, buildRequestUrlPath, isHttps, logError, logDebug, logInfo, logWarning };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agility/content-fetch",
3
- "version": "2.0.6",
4
- "description": "JavaScript library for the Agility Fetch API (node and browser)",
3
+ "version": "2.0.8",
4
+ "description": "JS/TS library for the Agility Fetch API",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/agility/agility-content-fetch-js-sdk.git"