Skip to content

Commit fbb144d

Browse files
committed
createUri changes due to new portal experience
1 parent 3147e41 commit fbb144d

File tree

3 files changed

+41
-60
lines changed

3 files changed

+41
-60
lines changed

src/collections/client.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,9 @@ export class Client {
156156

157157
export class AstraDB extends Client {
158158
constructor(...args: any[]) {
159-
// token: string, path: string
160-
if (args.length === 2) {
161-
let endpoint = args[1];
162-
endpoint += "/api/json/v1";
163-
endpoint += "/default_keyspace";
164-
super(endpoint, "default_keyspace", { isAstra: true, applicationToken: args[0] });
165-
} else {
166-
// token: string, dbId: string, region: string, keyspace?: string
167-
const keyspaceName = args[3] || "default_keyspace";
168-
const endpoint = createAstraUri(args[1], args[2], keyspaceName);
169-
super(endpoint, keyspaceName, { isAstra: true, applicationToken: args[0] });
170-
}
159+
// token: string, API EndPoint: string, keyspace?: string
160+
const keyspaceName = args[2] || "default_keyspace";
161+
const endpoint = createAstraUri(args[1], keyspaceName);
162+
super(endpoint, keyspaceName, { isAstra: true, applicationToken: args[0] });
171163
}
172164
}

src/collections/utils.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ export function getKeyspaceName(pathFromUrl?: string | null) {
7777

7878
/**
7979
* Create an Astra connection URI while connecting to Astra JSON API
80-
* @param databaseId the database id of the Astra database
81-
* @param region the region of the Astra database
80+
* @param apiEndPoint the API EndPoint of the Astra database
8281
* @param keyspace the keyspace to connect to
8382
* @param applicationToken an Astra application token
8483
* @param baseApiPath baseAPI path defaults to /api/json/v1
@@ -87,17 +86,14 @@ export function getKeyspaceName(pathFromUrl?: string | null) {
8786
* @returns URL as string
8887
*/
8988
export function createAstraUri(
90-
databaseId: string,
91-
region: string,
89+
apiEndPoint: string,
9290
keyspace: string,
9391
applicationToken?: string,
9492
baseApiPath?: string,
9593
logLevel?: string,
9694
authHeaderName?: string,
9795
) {
98-
const uri = new url.URL(
99-
`https://${databaseId}-${region}.apps.astra.datastax.com`,
100-
);
96+
const uri = new url.URL(apiEndPoint);
10197
let contextPath = "";
10298
contextPath += baseApiPath ? `/${baseApiPath}` : "/api/json/v1";
10399
contextPath += `/${keyspace}`;

tests/collections/utils.test.ts

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,55 @@
1414

1515
import assert from "assert";
1616
import { createAstraUri } from "@/src/collections/utils";
17+
import {AstraDB, Client} from "@/src/collections";
1718

1819
describe("Utils test", () => {
19-
it("createProdAstraUri", () => {
20-
const dbIdUUID = "ddd5843c-3dea-11ee-be56-0242ac120002";
21-
const uri: string = createAstraUri(dbIdUUID, "us-east1", "testks1");
20+
it("ClientBaseUriTest", () => {
21+
const apiEndPoint = "https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com";
22+
const astraDb = new AstraDB("myToken",apiEndPoint,"testks1");
2223
assert.strictEqual(
23-
uri,
24-
"https://" +
25-
dbIdUUID +
26-
"-us-east1.apps.astra.datastax.com/api/json/v1/testks1",
24+
astraDb.httpClient.baseUrl,
25+
"https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com/api/json/v1/testks1",
2726
);
2827
});
29-
it("createProdAstraUriWithToken", () => {
30-
const dbIdUUID = "ddd5843c-3dea-11ee-be56-0242ac120002";
31-
const uri: string = createAstraUri(
32-
dbIdUUID,
33-
"us-east1",
34-
"testks1",
35-
"myToken",
28+
it("ClientBaseUriTestDefaultKeyspace", () => {
29+
const apiEndPoint = "https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com";
30+
const astraDb = new AstraDB("myToken",apiEndPoint);
31+
assert.strictEqual(
32+
astraDb.httpClient.baseUrl,
33+
"https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com/api/json/v1/default_keyspace",
3634
);
35+
});
36+
it("createProdAstraUri", () => {
37+
const apiEndPoint = "https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com";
38+
const uri: string = createAstraUri( apiEndPoint, "testks1");
3739
assert.strictEqual(
3840
uri,
39-
"https://" +
40-
dbIdUUID +
41-
"-us-east1.apps.astra.datastax.com/api/json/v1/testks1?applicationToken=myToken",
41+
"https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com/api/json/v1/testks1",
4242
);
4343
});
44-
it("createProdAstraUriWithTokenAndProdEnum", () => {
45-
const dbIdUUID = "ddd5843c-3dea-11ee-be56-0242ac120002";
46-
const uri: string = createAstraUri(
47-
dbIdUUID,
48-
"us-east1",
49-
"testks1",
50-
"myToken",
51-
);
44+
it("createProdAstraUriWithToken", () => {
45+
const apiEndPoint = "https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com";
46+
const uri: string = createAstraUri( apiEndPoint, "testks1", "myToken");
5247
assert.strictEqual(
53-
uri,
54-
"https://" +
55-
dbIdUUID +
56-
"-us-east1.apps.astra.datastax.com/api/json/v1/testks1?applicationToken=myToken",
48+
uri,
49+
"https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com/api/json/v1/testks1?applicationToken=myToken",
5750
);
5851
});
52+
it("createProdAstraUriWithTokenAndProdEnum", () => {
53+
const apiEndPoint = "https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com";
54+
const uri: string = createAstraUri( apiEndPoint, "testks1", "myToken");
55+
assert.strictEqual(
56+
uri,
57+
"https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com/api/json/v1/testks1?applicationToken=myToken",
58+
);
59+
});
5960
it("createProdAstraUriWithTokenAndProdEnumWithBaseAPIPath", () => {
60-
const dbIdUUID = "ddd5843c-3dea-11ee-be56-0242ac120002";
61-
const uri: string = createAstraUri(
62-
dbIdUUID,
63-
"us-east1",
64-
"testks1",
65-
"myToken",
66-
"apis",
67-
);
61+
const apiEndPoint = "https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com";
62+
const uri: string = createAstraUri( apiEndPoint, "testks1", "myToken","apis");
6863
assert.strictEqual(
69-
uri,
70-
"https://" +
71-
dbIdUUID +
72-
"-us-east1.apps.astra.datastax.com/apis/testks1?applicationToken=myToken",
64+
uri,
65+
"https://a5cf1913-b80b-4f44-ab9f-a8b1c98469d0-ap-south-1.apps.astra.datastax.com/apis/testks1?applicationToken=myToken",
7366
);
7467
});
7568
});

0 commit comments

Comments
 (0)