Skip to content

Commit

Permalink
logstuff
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-bompart committed Feb 6, 2024
1 parent 9b51096 commit ff51ba1
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/ui/atomic/create-atomic/src/fetch-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import {
IManifestResponse,
ISearchInterfaceConfigurationResponse,
} from '@coveo/platform-client';
import {readFileSync} from 'node:fs';
import {homedir} from 'node:os';
import {resolve} from 'node:path';

/**
* @coveo/platform-client's IManifestResponse with simplified configuration
Expand All @@ -17,6 +20,7 @@ export async function fetchPageManifest(
type: 'next-gen' | 'legacy' | 'unknown'
) {
let manifestGetters = [];
await getAndLogNgsp(pageId);
if (type !== 'legacy') {
manifestGetters.push(getNextGenManifest);
}
Expand Down Expand Up @@ -68,3 +72,35 @@ async function getNextGenManifest(
},
});
}

async function getAndLogNgsp(pageId: string) {
const {accessToken, organizationId} = getConfig();
const request = await fetch(
`https://platformstg.cloud.coveo.com/rest/organizations/${organizationId}/searchpage/v1/interfaces/${pageId}/manifest`,
{
headers: {
Authorization: `Bearer ${accessToken}`,
},
method: 'POST',
}
);
console.log('---- Start of NGSP request ----');
console.log(`ok: ${request.ok}`);
console.log(`status: ${request.status}`);
console.log(`statusText: ${request.statusText}`);
console.log(`type: ${request.type}`);
console.log(`url: ${request.url}`);
console.log(`body: ${await request.text()}`);
console.log('---- End of NGSP request ----');
}

export function getConfigFilePath() {
const configsDir = process.platform === 'win32' ? 'AppData/Local' : '.config';
return resolve(homedir(), configsDir, '@coveo', 'cli', 'config.json');
}

export function getConfig() {
const pathToConfig = getConfigFilePath();

return JSON.parse(readFileSync(pathToConfig, {encoding: 'utf-8'}));
}

0 comments on commit ff51ba1

Please sign in to comment.