Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an API to list cortexes; fix content tests; use fully-qualified Pulumi env names #55

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
"dev": "node --watch -r ts-node/register index.ts",
"run": "npm run build && node index.js",
"test": "vitest",
"test:package:dev": "npm run build && pulumi env run npm-test node ./test-package.js",
"test:package:dev": "npm run build && pulumi env run cortexclick/default/npm-test node ./test-package.js",
"test:package:ci": "npm run build && node ./test-package.js",
"test:fast": "vitest run --exclude src/content.test.ts",
"test:dev": "CORTEX_API_URL=http://localhost:3001 pulumi env run npm-test npm run test",
"test:dev": "CORTEX_API_URL=http://localhost:3001 pulumi env run cortexclick/default/npm-test npm run test",
"test:ci": "vitest run",
"test:prod": "pulumi env run npm-test npm run test",
"test:fast:dev": "CORTEX_API_URL=http://localhost:3001 pulumi env run npm-test npm run test:fast",
"test:fast:prod": "pulumi env run npm-test npm run test:fast",
"test:indexers:dev": "CORTEX_API_URL=http://localhost:3001 pulumi env run npm-test vitest indexers.test.ts",
"test:scraping:dev": "RUN_SCRAPER_TESTS=true CORTEX_API_URL=https://api-dev.cortexclick.com pulumi env run npm-test vitest scraping.test.ts",
"test:scraping:prod": "RUN_SCRAPER_TESTS=true CORTEX_API_URL=https://api.cortexclick.com pulumi env run npm-test vitest scraping.test.ts"
"test:fast:dev": "CORTEX_API_URL=http://localhost:3001 pulumi env run cortexclick/default/npm-test npm run test:fast",
"test:fast:prod": "pulumi env run cortexclick/default/npm-test npm run test:fast",
"test:indexers:dev": "CORTEX_API_URL=http://localhost:3001 pulumi env run cortexclick/default/npm-test vitest indexers.test.ts",
"test:scraping:dev": "RUN_SCRAPER_TESTS=true CORTEX_API_URL=https://api-dev.cortexclick.com pulumi env run cortexclick/default/npm-test vitest scraping.test.ts",
"test:scraping:prod": "RUN_SCRAPER_TESTS=true CORTEX_API_URL=https://api.cortexclick.com pulumi env run cortexclick/default/npm-test vitest scraping.test.ts"
},
"keywords": [],
"author": "",
Expand Down
14 changes: 10 additions & 4 deletions src/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ export class Catalog {
};
const getRes = await apiClient.GET(`/catalogs/${name}`);
let res: Response;
if (getRes.status !== 200) {
if (getRes.status === 200) {
res = await apiClient.PUT(`/catalogs/${name}`, config);
} else if (getRes.status === 404) {
res = await apiClient.POST("/catalogs", createConfig);
} else {
res = await apiClient.PUT(`/catalogs/${name}`, config);
const message =
getRes.status === 400 ? await getRes.text() : getRes.statusText;
throw new Error(`Failed to configure catalog: ${message}`);
}

if (res.status > 201) {
throw new Error(`Failed to configure catalog: ${res.statusText}`);
const message = res.status === 400 ? await res.text() : res.statusText;
throw new Error(`Failed to configure catalog: ${message}`);
}
return new Catalog(config, apiClient, name);
}
Expand Down Expand Up @@ -197,7 +202,8 @@ export class Catalog {
}

if (res.status > 202) {
throw new Error(`Failed to upsert documents: ${res.statusText}`);
const message = res.status === 400 ? await res.text() : res.statusText;
throw new Error(`Failed to upsert documents: ${message}`);
}

const body = await res.json();
Expand Down
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export class CortexClient {
return Cortex.get(this.apiClient, name);
}

async listCortexes(): Promise<Cortex[]> {
return Cortex.list(this.apiClient);
}

async configureCortex(name: string, opts: CortexConfig): Promise<Cortex> {
return Cortex.configure(this.apiClient, name, opts);
}
Expand Down
Loading