Skip to content

Commit

Permalink
Check if ontology RID starts with "ri." (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihalbhatnagar authored Oct 7, 2024
1 parent 5e78575 commit d927a1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/few-apes-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@osdk/shared.test": patch
"@osdk/client": patch
---

Throws error in createClient when passed an invalid ontology RID
12 changes: 12 additions & 0 deletions packages/client/src/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ export function createClientInternal(
options: { logger?: Logger } | undefined = undefined,
fetchFn: typeof globalThis.fetch = fetch,
): Client {
if (typeof ontologyRid === "string") {
if (!ontologyRid.startsWith("ri.")) {
throw new Error("Invalid ontology RID");
}
} else {
ontologyRid.then((ontologyRid) => {
if (!ontologyRid.startsWith("ri.")) {
throw new Error("Invalid ontology RID");
}
});
}

const clientCtx: MinimalClient = createMinimalClient(
{ ontologyRid },
baseUrl,
Expand Down
2 changes: 1 addition & 1 deletion packages/shared.test/src/mock-ontology/mockOntology.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const updateTask: ActionDef$updateTask = {

export const MockOntology = {
metadata: {
ontologyRid: "",
ontologyRid: "ri.filler",
ontologyApiName: "Ontology",
userAgent: "typescript-sdk/0.0.0 osdk-cli/0.0.0",
},
Expand Down

0 comments on commit d927a1d

Please sign in to comment.