@agility/content-fetch 2.0.13 → 2.0.15-beta.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.
- package/README.md +14 -0
- package/dist/browser.js +14 -0
- package/dist/index.d.ts +3 -1
- package/dist/node.js +14 -0
- package/dist/types/Config.d.ts +7 -0
- package/dist/types/ContentItem.d.ts +3 -0
- package/dist/types/Geo.d.ts +60 -0
- package/dist/types/Page.d.ts +3 -0
- package/dist/types/SEO.d.ts +18 -0
- package/dist/utils.d.ts +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,6 +59,20 @@ const contentItems = await api.getContentItem({
|
|
|
59
59
|
})
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
### Naming the app that makes the requests
|
|
63
|
+
|
|
64
|
+
Set `source` to say which app is calling, so usage can be reported by where it comes from (your production site, a staging site, a mobile app, a build job):
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
const api = agility.getApi({
|
|
68
|
+
guid: "[guid]",
|
|
69
|
+
apiKey: "[your-api-key]",
|
|
70
|
+
source: "prod-website",
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
It is sent on every request as the `Agility-Source` header. It must be at most 64 characters of letters, digits, spaces and `_ . : / -`; anything else throws a `TypeError` from `getApi`. When `source` is not set, no header is sent. It is a label, not a credential: it doesn't change what the API returns or how responses are cached.
|
|
75
|
+
|
|
62
76
|
## Documentation
|
|
63
77
|
|
|
64
78
|
Full documentation for this SDK can be found in our [Agility Fetch JS SDK Reference Doc](https://agilitycms.com/docs/javascript/content-fetch-js-sdk).
|
package/dist/browser.js
CHANGED
|
@@ -98,6 +98,11 @@
|
|
|
98
98
|
}
|
|
99
99
|
return url;
|
|
100
100
|
}
|
|
101
|
+
var SOURCE_HEADER = "Agility-Source";
|
|
102
|
+
var SOURCE_PATTERN = /^[A-Za-z0-9 _.:/-]{0,64}$/;
|
|
103
|
+
function isValidSource(source) {
|
|
104
|
+
return typeof source === "string" && SOURCE_PATTERN.test(source);
|
|
105
|
+
}
|
|
101
106
|
function buildAuthHeader(config) {
|
|
102
107
|
let defaultAuthHeaders = {
|
|
103
108
|
APIKey: config.apiKey,
|
|
@@ -110,6 +115,13 @@
|
|
|
110
115
|
...defaultAuthHeaders,
|
|
111
116
|
...config.headers
|
|
112
117
|
};
|
|
118
|
+
if (typeof config.source === "string" && config.source.length > 0) {
|
|
119
|
+
for (const key of Object.keys(headers)) {
|
|
120
|
+
if (key.toLowerCase() === SOURCE_HEADER.toLowerCase())
|
|
121
|
+
delete headers[key];
|
|
122
|
+
}
|
|
123
|
+
headers[SOURCE_HEADER] = config.source;
|
|
124
|
+
}
|
|
113
125
|
return headers;
|
|
114
126
|
}
|
|
115
127
|
function isHttps(url) {
|
|
@@ -558,6 +570,8 @@
|
|
|
558
570
|
throw new TypeError2("When specifying a cache maxAge, you must set a number value in miliseconds, i.e. 180000 (3 mins).");
|
|
559
571
|
} else if (configParams.baseUrl && !isHttps(configParams.baseUrl)) {
|
|
560
572
|
throw new TypeError2(`When specifying a baseUrl (${configParams.baseUrl}), it must be over HTTPs.`);
|
|
573
|
+
} else if (configParams.source !== void 0 && configParams.source !== null && !isValidSource(configParams.source)) {
|
|
574
|
+
throw new TypeError2('When specifying a source, it must be at most 64 characters of letters, digits, spaces and _ . : / -, i.e. "prod-website".');
|
|
561
575
|
} else {
|
|
562
576
|
return;
|
|
563
577
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,9 @@ import { Filter } from "./types/Filter";
|
|
|
5
5
|
import { Gallery } from "./types/Gallery";
|
|
6
6
|
import { Page } from "./types/Page";
|
|
7
7
|
import { PageScripts } from "./types/PageScripts";
|
|
8
|
+
import { GeoProperties, GeoAi, SchemaType, LlmsInclude, AiCrawl, StructuredData } from "./types/Geo";
|
|
9
|
+
import { SEOProperties, SEORobots } from "./types/SEO";
|
|
8
10
|
import { ApiClientInstance, getApi } from "./api-client";
|
|
9
11
|
import { ContentReference } from "./types/ContentReference";
|
|
10
|
-
export type { ApiClientInstance, Config, ContentItem, ContentList, ContentReference, Filter, Gallery, Page, PageScripts };
|
|
12
|
+
export type { ApiClientInstance, Config, ContentItem, ContentList, ContentReference, Filter, Gallery, Page, PageScripts, GeoProperties, GeoAi, SchemaType, LlmsInclude, AiCrawl, StructuredData, SEOProperties, SEORobots };
|
|
11
13
|
export { getApi };
|
package/dist/node.js
CHANGED
|
@@ -116,6 +116,11 @@ function buildPathUrl(contentType, referenceName, skip, take, sort, direction, f
|
|
|
116
116
|
}
|
|
117
117
|
return url;
|
|
118
118
|
}
|
|
119
|
+
var SOURCE_HEADER = "Agility-Source";
|
|
120
|
+
var SOURCE_PATTERN = /^[A-Za-z0-9 _.:/-]{0,64}$/;
|
|
121
|
+
function isValidSource(source) {
|
|
122
|
+
return typeof source === "string" && SOURCE_PATTERN.test(source);
|
|
123
|
+
}
|
|
119
124
|
function buildAuthHeader(config) {
|
|
120
125
|
let defaultAuthHeaders = {
|
|
121
126
|
APIKey: config.apiKey,
|
|
@@ -128,6 +133,13 @@ function buildAuthHeader(config) {
|
|
|
128
133
|
...defaultAuthHeaders,
|
|
129
134
|
...config.headers
|
|
130
135
|
};
|
|
136
|
+
if (typeof config.source === "string" && config.source.length > 0) {
|
|
137
|
+
for (const key of Object.keys(headers)) {
|
|
138
|
+
if (key.toLowerCase() === SOURCE_HEADER.toLowerCase())
|
|
139
|
+
delete headers[key];
|
|
140
|
+
}
|
|
141
|
+
headers[SOURCE_HEADER] = config.source;
|
|
142
|
+
}
|
|
131
143
|
return headers;
|
|
132
144
|
}
|
|
133
145
|
function isHttps(url) {
|
|
@@ -576,6 +588,8 @@ function validateConfigParams(configParams) {
|
|
|
576
588
|
throw new TypeError2("When specifying a cache maxAge, you must set a number value in miliseconds, i.e. 180000 (3 mins).");
|
|
577
589
|
} else if (configParams.baseUrl && !isHttps(configParams.baseUrl)) {
|
|
578
590
|
throw new TypeError2(`When specifying a baseUrl (${configParams.baseUrl}), it must be over HTTPs.`);
|
|
591
|
+
} else if (configParams.source !== void 0 && configParams.source !== null && !isValidSource(configParams.source)) {
|
|
592
|
+
throw new TypeError2('When specifying a source, it must be at most 64 characters of letters, digits, spaces and _ . : / -, i.e. "prod-website".');
|
|
579
593
|
} else {
|
|
580
594
|
return;
|
|
581
595
|
}
|
package/dist/types/Config.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ export interface Config {
|
|
|
18
18
|
*/
|
|
19
19
|
apiKey?: string | null;
|
|
20
20
|
locale?: string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Names the app making the requests, such as "prod-website", "staging-website" or "ios-app".
|
|
23
|
+
* Sent on every request as the `Agility-Source` header, so API usage can be reported by where it
|
|
24
|
+
* comes from. At most 64 characters of letters, digits, space and `_ . : / -`. Optional: when it
|
|
25
|
+
* is not set (or is ""), no header is sent. It is a label, not a credential.
|
|
26
|
+
*/
|
|
27
|
+
source?: string | null;
|
|
21
28
|
/**
|
|
22
29
|
* Additional headers to include in the request.
|
|
23
30
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SEOProperties } from "./SEO";
|
|
2
|
+
import { GeoProperties } from "./Geo";
|
|
2
3
|
interface ContentItemProperties {
|
|
3
4
|
state: number;
|
|
4
5
|
modified: Date;
|
|
@@ -15,6 +16,7 @@ interface ContentItemProperties {
|
|
|
15
16
|
* @property {ContentItemProperties} properties - The system properties of the content item.
|
|
16
17
|
* @property {Object} fields - A dictionary of the fields and the values of the content item.
|
|
17
18
|
* @property {SEOProperties} seo - Any SEO related fields for the content item. This is only returned for Dynamic Page Items.
|
|
19
|
+
* @property {GeoProperties} [geo] - The item's own GEO / AEO properties (schema.org type, summary, structured data, AI-engine settings). Only items in a list that backs a dynamic page carry it, and it's omitted when the item has none.
|
|
18
20
|
*/
|
|
19
21
|
export interface ContentItem<T = {
|
|
20
22
|
[key: string]: any;
|
|
@@ -23,5 +25,6 @@ export interface ContentItem<T = {
|
|
|
23
25
|
properties: ContentItemProperties;
|
|
24
26
|
fields: T;
|
|
25
27
|
seo?: SEOProperties;
|
|
28
|
+
geo?: GeoProperties;
|
|
26
29
|
}
|
|
27
30
|
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schema.org page type a page describes itself as. Used as the `@type` of the page's
|
|
3
|
+
* WebPage node when JSON-LD is generated.
|
|
4
|
+
* @typedef SchemaType
|
|
5
|
+
* @memberof AgilityFetch.Types
|
|
6
|
+
*/
|
|
7
|
+
export type SchemaType = "WebPage" | "AboutPage" | "ContactPage" | "CollectionPage" | "FAQPage" | "ItemPage" | "ProfilePage";
|
|
8
|
+
/**
|
|
9
|
+
* Whether a page is listed in the site's llms.txt.
|
|
10
|
+
* - `inherit`: follow the page's sitemap visibility.
|
|
11
|
+
* - `include`: always list it.
|
|
12
|
+
* - `exclude`: never list it.
|
|
13
|
+
* @typedef LlmsInclude
|
|
14
|
+
* @memberof AgilityFetch.Types
|
|
15
|
+
*/
|
|
16
|
+
export type LlmsInclude = "inherit" | "include" | "exclude";
|
|
17
|
+
/**
|
|
18
|
+
* Whether AI crawlers may crawl a page.
|
|
19
|
+
* - `inherit`: follow the site's AI-crawler policy.
|
|
20
|
+
* - `block`: disallow this page's path for AI crawlers in robots.txt.
|
|
21
|
+
* @typedef AiCrawl
|
|
22
|
+
* @memberof AgilityFetch.Types
|
|
23
|
+
*/
|
|
24
|
+
export type AiCrawl = "inherit" | "block";
|
|
25
|
+
/**
|
|
26
|
+
* A page's AI-engine settings.
|
|
27
|
+
* @interface GeoAi
|
|
28
|
+
* @memberof AgilityFetch.Types
|
|
29
|
+
* @property {AgilityFetch.Types.LlmsInclude} [llmsInclude] - Whether the page is listed in llms.txt.
|
|
30
|
+
* @property {AgilityFetch.Types.AiCrawl} [crawl] - Whether AI crawlers may crawl the page.
|
|
31
|
+
*/
|
|
32
|
+
export interface GeoAi {
|
|
33
|
+
llmsInclude?: LlmsInclude;
|
|
34
|
+
crawl?: AiCrawl;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* JSON-LD supplied by an editor: a single object (which may hold an `@graph`) or an array of objects.
|
|
38
|
+
* @typedef StructuredData
|
|
39
|
+
* @memberof AgilityFetch.Types
|
|
40
|
+
*/
|
|
41
|
+
export type StructuredData = Record<string, unknown> | Record<string, unknown>[];
|
|
42
|
+
/**
|
|
43
|
+
* The GEO / AEO (generative and answer engine optimization) properties of a **Page**, or of a
|
|
44
|
+
* **Content Item** in a list that backs a dynamic page (the item's own values; how they combine with
|
|
45
|
+
* the dynamic page's is up to the renderer, e.g. `@agility/geo`).
|
|
46
|
+
* Every property is optional, and the API leaves out any property that isn't set.
|
|
47
|
+
* Unknown properties may be added in later versions, so don't treat this shape as closed.
|
|
48
|
+
* @interface GeoProperties
|
|
49
|
+
* @memberof AgilityFetch.Types
|
|
50
|
+
* @property {AgilityFetch.Types.SchemaType} [schemaType] - The schema.org page type (defaults to `WebPage` when not set).
|
|
51
|
+
* @property {string} [summary] - A short, answer-first plain-text summary of the page.
|
|
52
|
+
* @property {AgilityFetch.Types.StructuredData} [structuredData] - Editor-supplied JSON-LD, merged into the page's generated structured data.
|
|
53
|
+
* @property {AgilityFetch.Types.GeoAi} [ai] - The page's AI-engine settings (llms.txt listing, AI-crawler access).
|
|
54
|
+
*/
|
|
55
|
+
export interface GeoProperties {
|
|
56
|
+
schemaType?: SchemaType;
|
|
57
|
+
summary?: string;
|
|
58
|
+
structuredData?: StructuredData;
|
|
59
|
+
ai?: GeoAi;
|
|
60
|
+
}
|
package/dist/types/Page.d.ts
CHANGED
|
@@ -16,12 +16,14 @@
|
|
|
16
16
|
* @property {number} [dynamicItemContentID] - If this page is a dynamic page, then this property will show the associated contentID of the dynamic content item.
|
|
17
17
|
* @property {AgilityFetch.Types.SitemapVisibility} visible - Object that contains properties pertaining to the intended visibility of this page for seo and menus.
|
|
18
18
|
* @property {AgilityFetch.Types.PageScripts} [scripts] - The page's custom head/body scripts, and whether it opts out of the instance's global scripts.
|
|
19
|
+
* @property {AgilityFetch.Types.GeoProperties} [geo] - The page's GEO / AEO properties (schema.org type, summary, structured data, AI-engine settings). Omitted when the page has none.
|
|
19
20
|
*/
|
|
20
21
|
import { ContentZone } from "./ContentZone";
|
|
21
22
|
import { SystemProperties } from "./SystemProperties";
|
|
22
23
|
import { SitemapVisibility } from "./SitemapVisibility";
|
|
23
24
|
import { SEOProperties } from "./SEO";
|
|
24
25
|
import { PageScripts } from "./PageScripts";
|
|
26
|
+
import { GeoProperties } from "./Geo";
|
|
25
27
|
export interface Page {
|
|
26
28
|
pageID: number;
|
|
27
29
|
name: string;
|
|
@@ -40,4 +42,5 @@ export interface Page {
|
|
|
40
42
|
visible: SitemapVisibility;
|
|
41
43
|
seo?: SEOProperties;
|
|
42
44
|
scripts?: PageScripts | null;
|
|
45
|
+
geo?: GeoProperties;
|
|
43
46
|
}
|
package/dist/types/SEO.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The robots directives for a page.
|
|
3
|
+
* @interface SEORobots
|
|
4
|
+
* @property {boolean} [index] - Whether search engines may index the page.
|
|
5
|
+
* @property {boolean} [follow] - Whether search engines may follow the page's links.
|
|
6
|
+
*/
|
|
7
|
+
export interface SEORobots {
|
|
8
|
+
index?: boolean;
|
|
9
|
+
follow?: boolean;
|
|
10
|
+
}
|
|
1
11
|
/**
|
|
2
12
|
* Defines the SEO properties for a content item.
|
|
3
13
|
* @interface SEOProperties
|
|
@@ -6,6 +16,10 @@
|
|
|
6
16
|
* @property {string} metaHTML - The meta HTML for the content item.
|
|
7
17
|
* @property {boolean} menuVisible - Whether the content item should be visible in the menu.
|
|
8
18
|
* @property {boolean} sitemapVisible - Whether the content item should be visible in the sitemap.
|
|
19
|
+
* @property {string} [title] - The page's `<title>`, when it differs from the page title. Pages and dynamic page items; omitted when not set.
|
|
20
|
+
* @property {string} [canonicalUrl] - The page's canonical URL override. Pages and dynamic page items; omitted when not set.
|
|
21
|
+
* @property {SEORobots} [robots] - The page's robots directives. Pages and dynamic page items; omitted when not set.
|
|
22
|
+
* @property {string} [ogImage] - The URL of the page's social share (Open Graph) image. Pages and dynamic page items; omitted when not set.
|
|
9
23
|
*/
|
|
10
24
|
export interface SEOProperties {
|
|
11
25
|
metaDescription: string;
|
|
@@ -13,4 +27,8 @@ export interface SEOProperties {
|
|
|
13
27
|
metaHTML: string;
|
|
14
28
|
menuVisible: boolean;
|
|
15
29
|
sitemapVisible: boolean;
|
|
30
|
+
title?: string;
|
|
31
|
+
canonicalUrl?: string;
|
|
32
|
+
robots?: SEORobots;
|
|
33
|
+
ogImage?: string;
|
|
16
34
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -41,7 +41,10 @@ declare function logDebugDetails({ config, details }: {
|
|
|
41
41
|
}): void;
|
|
42
42
|
declare function buildRequestUrlPath(config: any, locale: any): string;
|
|
43
43
|
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;
|
|
44
|
+
/** The request header that carries the `source` setting. */
|
|
45
|
+
declare const SOURCE_HEADER = "Agility-Source";
|
|
46
|
+
declare function isValidSource(source: unknown): boolean;
|
|
44
47
|
declare function buildAuthHeader(config: any): any;
|
|
45
48
|
declare function isHttps(url: any): boolean;
|
|
46
|
-
export { buildPathUrl, buildAuthHeader, buildRequestUrlPath, isHttps, logError, logDebug, logInfo, logWarning, logDebugDetails, headersToObject };
|
|
49
|
+
export { buildPathUrl, buildAuthHeader, buildRequestUrlPath, isValidSource, SOURCE_HEADER, isHttps, logError, logDebug, logInfo, logWarning, logDebugDetails, headersToObject };
|
|
47
50
|
export type { DebugDetails };
|