@agility/content-fetch 2.0.9 → 2.1.0

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.
Files changed (43) hide show
  1. package/.env +76 -0
  2. package/.github/workflows/ci-cd.yml +96 -0
  3. package/build.js +2 -0
  4. package/dist/api-client.d.ts +2 -2
  5. package/dist/browser.js +623 -564
  6. package/dist/methods/getContentItem.d.ts +12 -3
  7. package/dist/methods/getContentList.d.ts +18 -6
  8. package/dist/methods/getGallery.d.ts +12 -3
  9. package/dist/methods/getPage.d.ts +12 -3
  10. package/dist/methods/getPageByPath.d.ts +12 -3
  11. package/dist/methods/getSitemapFlat.d.ts +12 -3
  12. package/dist/methods/getSitemapNested.d.ts +12 -3
  13. package/dist/methods/getSyncContent.d.ts +12 -3
  14. package/dist/methods/getSyncPages.d.ts +12 -3
  15. package/dist/methods/getUrlRedirections.d.ts +12 -3
  16. package/dist/node.js +125 -67
  17. package/dist/types/Config.d.ts +5 -0
  18. package/dist/types/generated/index.d.ts +53 -0
  19. package/dist/types/generated/v1.d.ts +1336 -0
  20. package/dist/types/generated/v2.d.ts +1052 -0
  21. package/dist/types/index.d.ts +61 -4
  22. package/dist/types/sdk/Client.d.ts +12 -0
  23. package/dist/types/sdk/Config.d.ts +49 -0
  24. package/dist/types/sdk/EnvConfig.d.ts +6 -0
  25. package/dist/types/sdk/Filter.d.ts +14 -0
  26. package/dist/types/sdk/FilterLogicOperator.d.ts +17 -0
  27. package/dist/types/sdk/FilterOperator.d.ts +34 -0
  28. package/dist/types/sdk/SortDirection.d.ts +17 -0
  29. package/dist/types/sdk/errors/Errors.d.ts +22 -0
  30. package/dist/types/sdk/index.d.ts +18 -0
  31. package/dist/types/v2/ContentItem.d.ts +27 -0
  32. package/dist/types/v2/ContentZone.d.ts +14 -0
  33. package/dist/types/v2/MediaItem.d.ts +20 -0
  34. package/dist/types/v2/MediaItemMetaData.d.ts +17 -0
  35. package/dist/types/v2/Page.d.ts +40 -0
  36. package/dist/types/v2/SEO.d.ts +16 -0
  37. package/dist/types/v2/SitemapVisibility.d.ts +11 -0
  38. package/dist/types/v2/SystemProperties.d.ts +15 -0
  39. package/dist/types/v2/index.d.ts +26 -0
  40. package/dist/utils.d.ts +1 -1
  41. package/jest.integration.config.js +19 -0
  42. package/jest.unit.config.js +25 -0
  43. package/package.json +31 -10
@@ -1,4 +1,5 @@
1
- import { ApiClientInstance } from '../types/Client';
1
+ import { ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
2
3
  /**
3
4
  * Gets the details of a content item by their Content ID.
4
5
  * @memberof AgilityFetch.Client.Content
@@ -30,7 +31,6 @@ import { ApiClientInstance } from '../types/Client';
30
31
  * });
31
32
  *
32
33
  */
33
- import { ContentItem } from '../types/ContentItem';
34
34
  export interface ContentItemRequestParams {
35
35
  contentID: number;
36
36
  locale?: string;
@@ -38,5 +38,14 @@ export interface ContentItemRequestParams {
38
38
  contentLinkDepth?: number;
39
39
  expandAllContentLinks?: boolean;
40
40
  }
41
- declare function getContentItem<T>(this: ApiClientInstance, requestParams: ContentItemRequestParams): Promise<ContentItem<T>>;
41
+ declare function getContentItem(this: ApiClientInstance & {
42
+ config: {
43
+ apiVersion: 'v1';
44
+ };
45
+ }, requestParams: ContentItemRequestParams): Promise<ApiTypes.V1.ContentItem>;
46
+ declare function getContentItem(this: ApiClientInstance & {
47
+ config: {
48
+ apiVersion: 'v2';
49
+ };
50
+ }, requestParams: ContentItemRequestParams): Promise<ApiTypes.V2.ContentItem>;
42
51
  export default getContentItem;
@@ -1,8 +1,5 @@
1
- import { Filter } from '../types/Filter';
2
- import { FilterLogicOperator } from '../types/FilterLogicOperator';
3
- import { SortDirection } from '../types/SortDirection';
4
- import { ContentList } from '../types/ContentList';
5
- import { ApiClientInstance } from '../types/Client';
1
+ import { Filter, FilterLogicOperator, SortDirection, ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
6
3
  /**
7
4
  * Retrieves a list of content items by reference name.
8
5
  * @memberof AgilityFetch.Client.Content
@@ -16,6 +13,7 @@ import { ApiClientInstance } from '../types/Client';
16
13
  * @param {number} [requestParams.skip] - The number of items to skip from the list. Default is **0**. Used for implementing pagination.
17
14
  * @param {string} [requestParams.sort] - The field to sort the results by. Example **fields.title** or **properties.modified**.
18
15
  * @param {AgilityFetch.Types.SortDirection} [requestParams.direction] - The direction to sort the results by.
16
+ * @param {string} [requestParams.fields] - A comma separated list of the fields to return. Example **fields.title,fields.description**.
19
17
  * @param {Array.<AgilityFetch.Types.Filter>} [requestParams.filters] - The collection of filters to filter the results by.
20
18
  * @param {AgilityFetch.Types.FilterLogicOperator} [requestParams.filtersLogicOperator] - The logic operator to combine multiple filters.
21
19
  * @returns {Promise<AgilityFetch.Types.ContentList>} - Returns a list of content items.
@@ -48,6 +46,7 @@ import { ApiClientInstance } from '../types/Client';
48
46
  * locale: 'en-us',
49
47
  * take: 50,
50
48
  * skip: 0,
49
+ * fields: 'fields.title,fields.description,properties.modified',
51
50
  * filters: [
52
51
  * {property: 'fields.title', operator: api.types.FilterOperators.EQUAL_TO, value: '"How this site works"'},
53
52
  * {property: 'fields.details', operator: api.types.FilterOperators.LIKE, value: '"Lorem ipsum dolar"'}
@@ -99,6 +98,10 @@ export interface ContentListRequestParams {
99
98
  * The direction to sort the results by.
100
99
  */
101
100
  direction?: SortDirection;
101
+ /**
102
+ * A comma separated list of the fields to return.
103
+ */
104
+ fields?: string;
102
105
  /**
103
106
  * 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
107
  */
@@ -110,5 +113,14 @@ export interface ContentListRequestParams {
110
113
  filters?: Array<Filter>;
111
114
  filtersLogicOperator?: FilterLogicOperator;
112
115
  }
113
- declare function getContentList(this: ApiClientInstance, requestParams: ContentListRequestParams): Promise<ContentList>;
116
+ declare function getContentList(this: ApiClientInstance & {
117
+ config: {
118
+ apiVersion: 'v1';
119
+ };
120
+ }, requestParams: ContentListRequestParams): Promise<ApiTypes.V1.ContentList>;
121
+ declare function getContentList(this: ApiClientInstance & {
122
+ config: {
123
+ apiVersion: 'v2';
124
+ };
125
+ }, requestParams: ContentListRequestParams): Promise<ApiTypes.V2.ContentList>;
114
126
  export default getContentList;
@@ -1,5 +1,5 @@
1
- import { Gallery } from '../types/Gallery';
2
- import { ApiClientInstance } from '../types/Client';
1
+ import { ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
3
3
  /**
4
4
  * Gets the details of a gallery by their Gallery ID.
5
5
  * @memberof AgilityFetch.Client.Media
@@ -29,5 +29,14 @@ import { ApiClientInstance } from '../types/Client';
29
29
  export interface GalleryRequestParams {
30
30
  galleryID: number;
31
31
  }
32
- declare function getGallery(this: ApiClientInstance, requestParams: GalleryRequestParams): Promise<Gallery>;
32
+ declare function getGallery(this: ApiClientInstance & {
33
+ config: {
34
+ apiVersion: 'v1';
35
+ };
36
+ }, requestParams: GalleryRequestParams): Promise<ApiTypes.V1.Gallery>;
37
+ declare function getGallery(this: ApiClientInstance & {
38
+ config: {
39
+ apiVersion: 'v2';
40
+ };
41
+ }, requestParams: GalleryRequestParams): Promise<ApiTypes.V2.Gallery>;
33
42
  export default getGallery;
@@ -1,5 +1,5 @@
1
- import { Page } from '../types/Page';
2
- import { ApiClientInstance } from '../types/Client';
1
+ import { ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
3
3
  /**
4
4
  * Gets the details of a page by its Page ID.
5
5
  * @memberof AgilityFetch.Client.Pages
@@ -37,5 +37,14 @@ export interface PageRequestParams {
37
37
  contentLinkDepth?: number;
38
38
  languageCode?: string;
39
39
  }
40
- declare function getPage(this: ApiClientInstance, requestParams: PageRequestParams): Promise<Page>;
40
+ declare function getPage(this: ApiClientInstance & {
41
+ config: {
42
+ apiVersion: 'v1';
43
+ };
44
+ }, requestParams: PageRequestParams): Promise<ApiTypes.V1.Page>;
45
+ declare function getPage(this: ApiClientInstance & {
46
+ config: {
47
+ apiVersion: 'v2';
48
+ };
49
+ }, requestParams: PageRequestParams): Promise<ApiTypes.V2.Page>;
41
50
  export default getPage;
@@ -1,5 +1,5 @@
1
- import { Page } from "../types/Page";
2
- import { ApiClientInstance } from "../types/Client";
1
+ import { ApiClientInstance } from "../types/sdk";
2
+ import { ApiTypes } from "../types/generated";
3
3
  /**
4
4
  * Gets the details of a page by its Page ID.
5
5
  * @memberof AgilityFetch.Client.Pages
@@ -38,5 +38,14 @@ export interface PageByPathRequestParams {
38
38
  contentLinkDepth?: number;
39
39
  languageCode?: string;
40
40
  }
41
- declare function getPageByPath(this: ApiClientInstance, requestParams: PageByPathRequestParams): Promise<Page>;
41
+ declare function getPageByPath(this: ApiClientInstance & {
42
+ config: {
43
+ apiVersion: 'v1';
44
+ };
45
+ }, requestParams: PageByPathRequestParams): Promise<ApiTypes.V1.Page>;
46
+ declare function getPageByPath(this: ApiClientInstance & {
47
+ config: {
48
+ apiVersion: 'v2';
49
+ };
50
+ }, requestParams: PageByPathRequestParams): Promise<ApiTypes.V2.Page>;
42
51
  export default getPageByPath;
@@ -1,5 +1,5 @@
1
- import { SitemapFlat } from '../types/SitemapFlat';
2
- import { ApiClientInstance } from '../types/Client';
1
+ import { ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
3
3
  /**
4
4
  * The sitemap, returned in a flat list, where the dictionary key is the page path. This method is ideal for page routing.
5
5
  * @memberof AgilityFetch.Client.Pages
@@ -33,5 +33,14 @@ export interface SitemapFlatRequestParams {
33
33
  locale?: string;
34
34
  languageCode?: string;
35
35
  }
36
- declare function getSitemapFlat(this: ApiClientInstance, requestParams: SitemapFlatRequestParams): Promise<SitemapFlat>;
36
+ declare function getSitemapFlat(this: ApiClientInstance & {
37
+ config: {
38
+ apiVersion: 'v1';
39
+ };
40
+ }, requestParams: SitemapFlatRequestParams): Promise<ApiTypes.V1.SitemapFlat>;
41
+ declare function getSitemapFlat(this: ApiClientInstance & {
42
+ config: {
43
+ apiVersion: 'v2';
44
+ };
45
+ }, requestParams: SitemapFlatRequestParams): Promise<ApiTypes.V2.SitemapFlat>;
37
46
  export default getSitemapFlat;
@@ -1,5 +1,5 @@
1
- import { SitemapNested } from '../types/SitemapNested';
2
- import { ApiClientInstance } from '../types/Client';
1
+ import { ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
3
3
  /**
4
4
  * Gets the sitemap as an array in a nested format, ideal for generating menus.
5
5
  * @memberof AgilityFetch.Client.Pages
@@ -33,5 +33,14 @@ export interface SitemapNestedRequestParams {
33
33
  locale?: string;
34
34
  languageCode?: string;
35
35
  }
36
- declare function getSitemapNested(this: ApiClientInstance, requestParams: SitemapNestedRequestParams): Promise<SitemapNested>;
36
+ declare function getSitemapNested(this: ApiClientInstance & {
37
+ config: {
38
+ apiVersion: 'v1';
39
+ };
40
+ }, requestParams: SitemapNestedRequestParams): Promise<ApiTypes.V1.SitemapNested>;
41
+ declare function getSitemapNested(this: ApiClientInstance & {
42
+ config: {
43
+ apiVersion: 'v2';
44
+ };
45
+ }, requestParams: SitemapNestedRequestParams): Promise<ApiTypes.V2.SitemapNested>;
37
46
  export default getSitemapNested;
@@ -1,5 +1,5 @@
1
- import { SyncContent } from '../types/SyncContent';
2
- import { ApiClientInstance } from '../types/Client';
1
+ import { ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
3
3
  /**
4
4
  * Retrieves a list of content items that need to be synced based on the provided sync content items token, and returns the next sync token.
5
5
  * @memberof AgilityFetch.Client.Sync
@@ -39,5 +39,14 @@ export interface SyncContentRequestParams {
39
39
  pageSize?: number;
40
40
  languageCode?: string;
41
41
  }
42
- declare function getSyncContent(this: ApiClientInstance, requestParams: SyncContentRequestParams): Promise<SyncContent>;
42
+ declare function getSyncContent(this: ApiClientInstance & {
43
+ config: {
44
+ apiVersion: 'v1';
45
+ };
46
+ }, requestParams: SyncContentRequestParams): Promise<ApiTypes.V1.ContentItemSync>;
47
+ declare function getSyncContent(this: ApiClientInstance & {
48
+ config: {
49
+ apiVersion: 'v2';
50
+ };
51
+ }, requestParams: SyncContentRequestParams): Promise<ApiTypes.V2.ContentItemSync>;
43
52
  export default getSyncContent;
@@ -1,5 +1,5 @@
1
- import { Page } from '../types/Page';
2
- import { ApiClientInstance } from '../types/Client';
1
+ import { ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
3
3
  /**
4
4
  * Retrieves a list of pages that need to be synced based on the provided sync pages token, and returns the next sync token.
5
5
  * @memberof AgilityFetch.Client.Sync
@@ -39,5 +39,14 @@ export interface SyncPagesRequestParams {
39
39
  pageSize?: number;
40
40
  languageCode?: string;
41
41
  }
42
- declare function getSyncPages(this: ApiClientInstance, requestParams: SyncPagesRequestParams): Promise<Page>;
42
+ declare function getSyncPages(this: ApiClientInstance & {
43
+ config: {
44
+ apiVersion: 'v1';
45
+ };
46
+ }, requestParams: SyncPagesRequestParams): Promise<ApiTypes.V1.PageSync>;
47
+ declare function getSyncPages(this: ApiClientInstance & {
48
+ config: {
49
+ apiVersion: 'v2';
50
+ };
51
+ }, requestParams: SyncPagesRequestParams): Promise<ApiTypes.V2.PageSync>;
43
52
  export default getSyncPages;
@@ -1,5 +1,5 @@
1
- import { Gallery } from '../types/Gallery';
2
- import { ApiClientInstance } from '../types/Client';
1
+ import { ApiClientInstance } from '../types/sdk';
2
+ import { ApiTypes } from '../types/generated';
3
3
  /**
4
4
  * Gets the details of a gallery by their Gallery ID.
5
5
  * @memberof AgilityFetch.Client.Pages
@@ -31,5 +31,14 @@ import { ApiClientInstance } from '../types/Client';
31
31
  export interface UrlRedirectionsRequestParams {
32
32
  lastAccessDate?: Date | null;
33
33
  }
34
- declare function getUrlRedirections(this: ApiClientInstance, requestParams: UrlRedirectionsRequestParams): Promise<Gallery>;
34
+ declare function getUrlRedirections(this: ApiClientInstance & {
35
+ config: {
36
+ apiVersion: 'v1';
37
+ };
38
+ }, requestParams: UrlRedirectionsRequestParams): Promise<ApiTypes.V1.UrlRedirection[]>;
39
+ declare function getUrlRedirections(this: ApiClientInstance & {
40
+ config: {
41
+ apiVersion: 'v2';
42
+ };
43
+ }, requestParams: UrlRedirectionsRequestParams): Promise<ApiTypes.V2.UrlRedirection[]>;
35
44
  export default getUrlRedirections;
package/dist/node.js CHANGED
@@ -17,27 +17,24 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
19
  // src/index.ts
20
- var src_exports = {};
21
- __export(src_exports, {
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
22
  getApi: () => getApi
23
23
  });
24
- module.exports = __toCommonJS(src_exports);
24
+ module.exports = __toCommonJS(index_exports);
25
25
 
26
26
  // src/utils.ts
27
27
  function logDebug({ config, message }) {
28
- if (config.logLevel !== "debug" && !config.debug)
29
- return;
28
+ if (config.logLevel !== "debug" && !config.debug) return;
30
29
  console.log("\x1B[33m%s\x1B[0m", message);
31
30
  }
32
31
  function logInfo({ config, message }) {
33
- if (config.logLevel !== "debug" && config.logLevel !== "info")
34
- return;
32
+ if (config.logLevel !== "debug" && config.logLevel !== "info") return;
35
33
  console.log("\x1B[33m%s\x1B[0m", message);
36
34
  }
37
35
  function logError({ config, message }) {
38
- if (config.logLevel === "silent")
39
- return;
40
- console.error("\x1B[41m%s\x1B[0m", message);
36
+ if (config.logLevel === "silent") return;
37
+ console.log(message);
41
38
  }
42
39
  function buildRequestUrlPath(config, locale) {
43
40
  let apiFetchOrPreview = "";
@@ -49,9 +46,12 @@ function buildRequestUrlPath(config, locale) {
49
46
  let urlPath = `${config.baseUrl}/${apiFetchOrPreview}/${locale}`;
50
47
  return urlPath;
51
48
  }
52
- function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, filterString, contentLinkDepth, expandAllContentLinks) {
49
+ function buildPathUrl(contentType, referenceName, skip, take, sort, direction, filters, filtersLogicOperator, filterString, contentLinkDepth, expandAllContentLinks, fields) {
53
50
  let url = `/${contentType}/${referenceName}?contentLinkDepth=${contentLinkDepth}&`;
54
51
  filtersLogicOperator = filtersLogicOperator ? ` ${filtersLogicOperator} ` : " AND ";
52
+ if (fields) {
53
+ url += `fields=${encodeURIComponent(fields)}&`;
54
+ }
55
55
  if (sort) {
56
56
  url += `sort=${sort}&`;
57
57
  if (direction) {
@@ -100,7 +100,61 @@ function isHttps(url) {
100
100
  return true;
101
101
  }
102
102
 
103
- // src/types/errors/Errors.ts
103
+ // src/types/sdk/FilterOperator.ts
104
+ var FilterOperators = /* @__PURE__ */ ((FilterOperators2) => {
105
+ FilterOperators2["EQUAL_TO"] = "eq";
106
+ FilterOperators2["NOT_EQUAL_TO"] = "ne";
107
+ FilterOperators2["LESS_THAN"] = "lt";
108
+ FilterOperators2["LESS_THAN_OR_EQUAL_TO"] = "lte";
109
+ FilterOperators2["GREATER_THAN"] = "gt";
110
+ FilterOperators2["GREATER_THAN_OR_EQUAL_TO"] = "gte";
111
+ FilterOperators2["RANGE"] = "range";
112
+ FilterOperators2["LIKE"] = "like";
113
+ FilterOperators2["IN"] = "in";
114
+ FilterOperators2["CONTAINS"] = "contains";
115
+ return FilterOperators2;
116
+ })(FilterOperators || {});
117
+ var FilterOperator_default = FilterOperators;
118
+
119
+ // src/types/sdk/FilterLogicOperator.ts
120
+ var FilterLogicOperators = /* @__PURE__ */ ((FilterLogicOperators2) => {
121
+ FilterLogicOperators2["AND"] = "AND";
122
+ FilterLogicOperators2["OR"] = "OR";
123
+ return FilterLogicOperators2;
124
+ })(FilterLogicOperators || {});
125
+
126
+ // src/types/sdk/SortDirection.ts
127
+ var SortDirections = /* @__PURE__ */ ((SortDirections2) => {
128
+ SortDirections2["ASC"] = "asc";
129
+ SortDirections2["DESC"] = "desc";
130
+ return SortDirections2;
131
+ })(SortDirections || {});
132
+
133
+ // src/types/sdk/errors/Errors.ts
134
+ var EvalError = class extends Error {
135
+ constructor(message, asserter = void 0) {
136
+ super(message);
137
+ Error.captureStackTrace?.(this, asserter || this.constructor);
138
+ }
139
+ };
140
+ var RangeError = class extends Error {
141
+ constructor(message, asserter = void 0) {
142
+ super(message);
143
+ Error.captureStackTrace?.(this, asserter || this.constructor);
144
+ }
145
+ };
146
+ var ReferenceError2 = class extends Error {
147
+ constructor(message, asserter = void 0) {
148
+ super(message);
149
+ Error.captureStackTrace?.(this, asserter || this.constructor);
150
+ }
151
+ };
152
+ var SyntaxError = class extends Error {
153
+ constructor(message, asserter = void 0) {
154
+ super(message);
155
+ Error.captureStackTrace?.(this, asserter || this.constructor);
156
+ }
157
+ };
104
158
  var TypeError2 = class extends Error {
105
159
  /**
106
160
  * @param {string} message The error message
@@ -111,6 +165,12 @@ var TypeError2 = class extends Error {
111
165
  Error.captureStackTrace?.(this, asserter || this.constructor);
112
166
  }
113
167
  };
168
+ var URIError = class extends Error {
169
+ constructor(message, asserter = void 0) {
170
+ super(message);
171
+ Error.captureStackTrace?.(this, asserter || this.constructor);
172
+ }
173
+ };
114
174
 
115
175
  // src/methods/getSitemapFlat.ts
116
176
  function getSitemapFlat(requestParams) {
@@ -194,7 +254,7 @@ function getContentList(requestParams) {
194
254
  requestParams.referenceName = sanitizeReferenceName(requestParams.referenceName);
195
255
  requestParams = { ...defaultParams2, ...requestParams };
196
256
  const req = {
197
- url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.filterString, requestParams.contentLinkDepth, requestParams.expandAllContentLinks),
257
+ url: buildPathUrl("list", requestParams.referenceName, requestParams.skip, requestParams.take, requestParams.sort, requestParams.direction, requestParams.filters, requestParams.filtersLogicOperator, requestParams.filterString, requestParams.contentLinkDepth, requestParams.expandAllContentLinks, requestParams.fields),
198
258
  method: "get",
199
259
  baseURL: buildRequestUrlPath(this.config, requestParams.locale ? requestParams.locale : requestParams.languageCode),
200
260
  headers: buildAuthHeader(this.config),
@@ -447,9 +507,9 @@ function getSyncPages(requestParams) {
447
507
  }
448
508
  function validateRequestParams10(requestParams) {
449
509
  if (!requestParams.languageCode && !requestParams.locale) {
450
- throw new TypeError("You must include a locale in your request params.");
510
+ throw new TypeError2("You must include a locale in your request params.");
451
511
  } else if (requestParams.syncToken == void 0 || requestParams.syncToken == null) {
452
- throw new TypeError("You must include a syncToken value your request params. Use zero (0) to start a new sync.");
512
+ throw new TypeError2("You must include a syncToken value your request params. Use zero (0) to start a new sync.");
453
513
  } else {
454
514
  return;
455
515
  }
@@ -459,40 +519,36 @@ var getSyncPages_default = getSyncPages;
459
519
  // src/types/index.ts
460
520
  var types_exports = {};
461
521
  __export(types_exports, {
522
+ EvalError: () => EvalError,
462
523
  FilterLogicOperators: () => FilterLogicOperators,
463
524
  FilterOperators: () => FilterOperator_default,
464
- SortDirections: () => SortDirections
525
+ RangeError: () => RangeError,
526
+ ReferenceError: () => ReferenceError2,
527
+ SortDirections: () => SortDirections,
528
+ SyntaxError: () => SyntaxError,
529
+ TypeError: () => TypeError2,
530
+ URIError: () => URIError,
531
+ V1: () => v1_exports,
532
+ V2: () => v2_exports
465
533
  });
466
534
 
467
- // src/types/FilterOperator.ts
468
- var FilterOperators = /* @__PURE__ */ ((FilterOperators2) => {
469
- FilterOperators2["EQUAL_TO"] = "eq";
470
- FilterOperators2["NOT_EQUAL_TO"] = "ne";
471
- FilterOperators2["LESS_THAN"] = "lt";
472
- FilterOperators2["LESS_THAN_OR_EQUAL_TO"] = "lte";
473
- FilterOperators2["GREATER_THAN"] = "gt";
474
- FilterOperators2["GREATER_THAN_OR_EQUAL_TO"] = "gte";
475
- FilterOperators2["RANGE"] = "range";
476
- FilterOperators2["LIKE"] = "like";
477
- FilterOperators2["IN"] = "in";
478
- FilterOperators2["CONTAINS"] = "contains";
479
- return FilterOperators2;
480
- })(FilterOperators || {});
481
- var FilterOperator_default = FilterOperators;
535
+ // src/types/generated/v1.ts
536
+ var v1_exports = {};
482
537
 
483
- // src/types/FilterLogicOperator.ts
484
- var FilterLogicOperators = /* @__PURE__ */ ((FilterLogicOperators2) => {
485
- FilterLogicOperators2["AND"] = "AND";
486
- FilterLogicOperators2["OR"] = "OR";
487
- return FilterLogicOperators2;
488
- })(FilterLogicOperators || {});
538
+ // src/types/generated/v2.ts
539
+ var v2_exports = {};
489
540
 
490
- // src/types/SortDirection.ts
491
- var SortDirections = /* @__PURE__ */ ((SortDirections2) => {
492
- SortDirections2["ASC"] = "asc";
493
- SortDirections2["DESC"] = "desc";
494
- return SortDirections2;
495
- })(SortDirections || {});
541
+ // src/types/errors/Errors.ts
542
+ var TypeError3 = class extends Error {
543
+ /**
544
+ * @param {string} message The error message
545
+ * @param {Function} [asserter] The assertion function that threw the error. Removes stack-trace noise if provided.
546
+ */
547
+ constructor(message, asserter) {
548
+ super(message);
549
+ Error.captureStackTrace?.(this, asserter || this.constructor);
550
+ }
551
+ };
496
552
 
497
553
  // src/api-client.ts
498
554
  var defaultConfig = {
@@ -501,6 +557,8 @@ var defaultConfig = {
501
557
  guid: null,
502
558
  apiKey: null,
503
559
  locale: null,
560
+ apiVersion: "v2",
561
+ // Default to v2 for better types and modern API
504
562
  headers: {},
505
563
  requiresGuidInHeaders: false,
506
564
  logLevel: "warn",
@@ -510,31 +568,36 @@ var defaultConfig = {
510
568
  //caching disabled by default
511
569
  }
512
570
  };
513
- function buildBaseUrl(guid) {
514
- let baseUrlSuffixes = {
571
+ function buildBaseUrl(guid, apiVersion) {
572
+ const baseUrlSuffixes = {
515
573
  u: "",
516
574
  c: "-ca",
517
575
  e: "-eu",
518
576
  a: "-aus",
519
- d: "-dev"
577
+ d: "-dev",
578
+ us2: "-usa2"
520
579
  };
521
- let suffix = guid.substr(guid.length - 2, 2);
522
- let env = suffix.substr(1);
523
- if (suffix.startsWith("-") && baseUrlSuffixes.hasOwnProperty(env)) {
524
- return `https://api${baseUrlSuffixes[env]}.aglty.io/${guid}`;
525
- } else {
526
- return `https://${guid}-api.agilitycms.cloud`;
580
+ const versionPath = apiVersion === "v2" ? "/v2" : "";
581
+ const match = guid.match(/-(us2|[ucead])$/);
582
+ if (match) {
583
+ const env = match[1];
584
+ if (baseUrlSuffixes.hasOwnProperty(env)) {
585
+ const url2 = `https://api${baseUrlSuffixes[env]}.aglty.io${versionPath}/${guid}`;
586
+ return url2;
587
+ }
527
588
  }
589
+ const url = `https://api-dev.aglty.io${versionPath}/${guid}`;
590
+ return url;
528
591
  }
529
592
  function validateConfigParams(configParams) {
530
593
  if (!configParams.guid || configParams.guid.length == 0) {
531
- throw new TypeError2("You must provide a guid.");
594
+ throw new TypeError3("You must provide a guid.");
532
595
  } else if (!configParams.apiKey || configParams.apiKey.length == 0) {
533
- throw new TypeError2("You must provide an access token.");
596
+ throw new TypeError3("You must provide an access token.");
534
597
  } else if (configParams.caching && isNaN(configParams.caching.maxAge)) {
535
- throw new TypeError2("When specifying a cache maxAge, you must set a number value in miliseconds, i.e. 180000 (3 mins).");
598
+ throw new TypeError3("When specifying a cache maxAge, you must set a number value in miliseconds, i.e. 180000 (3 mins).");
536
599
  } else if (configParams.baseUrl && !isHttps(configParams.baseUrl)) {
537
- throw new TypeError2(`When specifying a baseUrl (${configParams.baseUrl}), it must be over HTTPs.`);
600
+ throw new TypeError3(`When specifying a baseUrl (${configParams.baseUrl}), it must be over HTTPs.`);
538
601
  } else {
539
602
  return;
540
603
  }
@@ -547,7 +610,7 @@ var ApiClient = class {
547
610
  ...userConfig
548
611
  };
549
612
  if (!config.baseUrl) {
550
- config.baseUrl = buildBaseUrl(config?.guid || "");
613
+ config.baseUrl = buildBaseUrl(config?.guid || "", config.apiVersion);
551
614
  } else {
552
615
  config.requiresGuidInHeaders = true;
553
616
  }
@@ -586,9 +649,9 @@ var ApiClient = class {
586
649
  //the function that actually makes ALL our requests
587
650
  async makeRequest(reqConfig) {
588
651
  const isPreview = !!this.config.isPreview;
589
- logDebug({ config: this.config, message: `AgilityCMS Fetch API LOG: ${reqConfig.baseURL}${reqConfig.url}` });
652
+ const fullUrl = `${reqConfig.baseURL}${reqConfig.url}`;
653
+ logDebug({ config: this.config, message: `AgilityCMS Fetch API LOG: ${fullUrl}` });
590
654
  try {
591
- const fullUrl = `${reqConfig.baseURL}${reqConfig.url}`;
592
655
  let init = {
593
656
  ...this.config.fetchConfig,
594
657
  method: "GET",
@@ -604,8 +667,9 @@ var ApiClient = class {
604
667
  }
605
668
  const response = await fetch(fullUrl, init);
606
669
  if (!response.ok) {
670
+ const fullErrorUrl = `${reqConfig.baseURL}${reqConfig.url}`;
607
671
  if (response.status === 404) {
608
- logInfo({ config: this.config, message: `AgilityCMS Fetch API: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
672
+ logInfo({ config: this.config, message: `AgilityCMS Fetch API: Request returned a ${response.status} response for ${fullErrorUrl}. ${response.statusText}` });
609
673
  return;
610
674
  }
611
675
  logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
@@ -623,15 +687,9 @@ var ApiClient = class {
623
687
  };
624
688
  function getApi(config) {
625
689
  validateConfigParams(config);
626
- if (!config.fetchConfig)
627
- config.fetchConfig = {};
690
+ if (!config.fetchConfig) config.fetchConfig = {};
628
691
  return new ApiClient(config);
629
692
  }
630
-
631
- // src/index.ts
632
- module.exports = {
633
- getApi
634
- };
635
693
  // Annotate the CommonJS export names for ESM import in node:
636
694
  0 && (module.exports = {
637
695
  getApi
@@ -18,6 +18,11 @@ export interface Config {
18
18
  */
19
19
  apiKey?: string | null;
20
20
  locale?: string | null;
21
+ /**
22
+ * The API version to use. 'v1' uses legacy string-based data types, 'v2' uses proper data types.
23
+ * Default is 'v2'. Specify 'v1' only if you need legacy compatibility.
24
+ */
25
+ apiVersion?: 'v1' | 'v2';
21
26
  /**
22
27
  * Additional headers to include in the request.
23
28
  */