@@ -43,7 +43,8 @@ const processResponse = (res, verbose = false) => {
4343 * @param {string } options - Optional. An object of domain check options, or a string
4444 * @param {string } options.userAgentIdentifier - Optional. A string representing the app, site, or organisation that is making the request.
4545 * @param {string } options.verbose - Optional. A boolean indicating whether to return verbose results.
46- * @param {string } options.url - Optional. A string representing the URL of the carbon.txt validator endpoint.
46+ * @param {string } options.customValidator - Optional. A string representing the URL of the carbon.txt validator endpoint.
47+ * @param {string } options.apiKey - Optional. A string representing the API key to use for the request.
4748 */
4849
4950export async function check ( domain , options ) {
@@ -53,12 +54,22 @@ export async function check(domain, options) {
5354
5455 const agentId = options ?. userAgentIdentifier ;
5556 const verbose = options ?. verbose || false ;
57+ const apiKey = options ?. apiKey || null ;
58+
59+ if ( ! apiKey ) {
60+ throw new Error ( "A valid API key is required." ) ;
61+ }
62+
5663 const validatorUrl =
57- options ?. url || "https://carbon-txt-api.greenweb.org/api/validate/domain/" ;
64+ options ?. customValidator ||
65+ "https://carbon-txt-api.greenweb.org/api/validate/domain/" ;
5866
5967 try {
6068 const req = await fetch ( validatorUrl , {
61- headers : getApiRequestHeaders ( agentId ) ,
69+ headers : {
70+ ...getApiRequestHeaders ( agentId ) ,
71+ "x-api-key" : apiKey ,
72+ } ,
6273 method : "POST" ,
6374 body : JSON . stringify ( { domain } ) ,
6475 } ) ;
0 commit comments