-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
32 lines (27 loc) · 1.17 KB
/
Copy pathindex.ts
File metadata and controls
32 lines (27 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {rawExecuteQuery, type ExecuteQueryOptions} from "@datocms/cda-client";
import {randomUUID} from "node:crypto";
const query = `
query MyQuery {
exampleModel {
title
}
}
`;
(async () => {
const uuid = randomUUID();
const randomInt = Math.floor(Math.random() * 100);
const referer = `https://www.example${randomInt}.com/${uuid}/test?uuid=${uuid}&staticParam=test`; // Query strings are seemingly stripped by us?
const queryOptions:ExecuteQueryOptions = {
token: process.env.DATOCMS_API_TOKEN, // From https://cda-query-referer.admin.datocms.com/project_settings/access_tokens/398768/edit
referer: referer, // This works
requestInitOptions: {
// referrer: 'https://www.fake.com' // This does nothing, apparently...
},
fetchFn: (url: RequestInfo | URL, init: RequestInit) => {
console.log(`init.referrer: ${init.referrer}`); // This seems like a useless param? Maybe a mis-typing?
console.log("Actual HTTP headers:", {...init.headers, Authorization: 'redacted'});
return fetch(url, init);
},
}
await rawExecuteQuery(query,queryOptions);
})()