Skip to content

Commit 5a7107f

Browse files
authoredJun 10, 2025
Merge pull request #90 from contentstack/fix/DX-3038
[DX-3038], fix custom config for graphQL and updated regions
2 parents 879e052 + cecb6e2 commit 5a7107f

File tree

8 files changed

+42
-15
lines changed

8 files changed

+42
-15
lines changed
 

‎package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/types-generator",
3-
"version": "3.1.0",
3+
"version": "3.2.0",
44
"description": "Contentstack type definition generation library",
55
"private": false,
66
"author": "Contentstack",

‎src/constants/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ export const TOKEN_TYPE = {
55
export const REGIONS = {
66
US: "US",
77
EU: "EU",
8+
AWS_NA: "AWS-NA",
9+
AWS_EU: "AWS-EU",
810
AZURE_NA: "AZURE_NA",
911
AZURE_EU: "AZURE_EU",
1012
GCP_NA: "GCP_NA",
13+
GCP_EU: "GCP_EU",
14+
CUSTOM: "CUSTOM",
1115
};

‎src/graphqlTS/index.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export async function graphqlTS({
2222
environment,
2323
branch,
2424
namespace,
25+
host,
2526
}: GraphQLBase) {
2627
try {
2728
if (!token || !apiKey || !environment || !region) {
@@ -34,7 +35,9 @@ export async function graphqlTS({
3435
let config = {
3536
method: "post",
3637
maxBodyLength: Infinity,
37-
url: `${GRAPHQL_REGION_URL_MAPPING[region]}/${apiKey}`,
38+
url: host
39+
? `https://${host}/stacks/${apiKey}`
40+
: `${GRAPHQL_REGION_URL_MAPPING[region]}/${apiKey}`,
3841
headers: {
3942
access_token: token,
4043
branch: "",
@@ -50,10 +53,10 @@ export async function graphqlTS({
5053
config.headers.branch = branch;
5154
}
5255

53-
if (!GRAPHQL_REGION_URL_MAPPING[region]) {
56+
if (!GRAPHQL_REGION_URL_MAPPING[region] && !host) {
5457
throw {
5558
type: "validation",
56-
error_message: `GraphQL content delivery api unavailable for '${region}' region`,
59+
error_message: `GraphQL content delivery api unavailable for '${region}' region and no custom host provided`,
5760
};
5861
}
5962

@@ -80,14 +83,19 @@ export async function graphqlTS({
8083
"Unauthorized: The apiKey, token or environment is not valid.",
8184
};
8285
} else {
83-
let details = '';
84-
if (error.response.data.errors[0]?.extensions?.errors?.[0]?.code === 'SCHEMA_BUILD_ERROR') {
85-
error.response.data.errors[0].extensions.errors[0].details.forEach((element: {error: string}) => {
86-
details += element.error + '\n'
87-
});
86+
let details = "";
87+
if (
88+
error.response.data.errors[0]?.extensions?.errors?.[0]?.code ===
89+
"SCHEMA_BUILD_ERROR"
90+
) {
91+
details = error.response.data.errors[0].extensions.errors[0].details
92+
.map((element: { error: string }) => element.error)
93+
.join("\n");
8894
}
8995
throw {
90-
error_message: details ? details : error.response.data.errors[0]?.extensions?.errors[0].message,
96+
error_message: details
97+
? details
98+
: error.response.data.errors[0]?.extensions?.errors[0].message,
9199
};
92100
}
93101
}

‎src/sdk/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ export const initializeContentstackSdk = ({
1818
return Region.US;
1919
case REGIONS.EU:
2020
return Region.EU;
21+
case REGIONS.AWS_NA:
22+
return Region.US;
23+
case REGIONS.AWS_EU:
24+
return Region.EU;
2125
case REGIONS.AZURE_NA:
2226
return Region.AZURE_NA;
2327
case REGIONS.AZURE_EU:
2428
return Region.AZURE_EU;
2529
case REGIONS.GCP_NA:
2630
return Region.GCP_NA;
31+
case REGIONS.GCP_EU:
32+
return Region.GCP_EU;
2733
default:
2834
isCustomRegion = true;
2935
break;

‎src/types/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
export interface StackConnectionConfig {
22
apiKey: string;
33
token: string;
4-
region: "US" | "EU" | "AZURE_NA" | "AZURE_EU" | "GCP_NA";
4+
region:
5+
| "US"
6+
| "EU"
7+
| "AWS-NA"
8+
| "AWS-EU"
9+
| "AZURE_NA"
10+
| "AZURE_EU"
11+
| "GCP_NA"
12+
| "GCP_EU"
13+
| "CUSTOM";
514
environment: string;
615
branch?: string;
716
host?: string;

‎tests/integration/graphqlTS/graphqlTS.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe("graphqlTS function with errors", () => {
104104
});
105105
} catch (err: any) {
106106
expect(err.error_message).toEqual(
107-
"GraphQL content delivery api unavailable for 'wrong-region' region"
107+
"GraphQL content delivery api unavailable for 'wrong-region' region and no custom host provided"
108108
);
109109
}
110110
});

‎tests/unit/graphqlTS/graphqlTS.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe("graphqlTS function with errors", () => {
137137
});
138138
} catch (err: any) {
139139
expect(err.error_message).toEqual(
140-
"GraphQL content delivery api unavailable for 'wrong-region' region"
140+
"GraphQL content delivery api unavailable for 'wrong-region' region and no custom host provided"
141141
);
142142
}
143143
});

0 commit comments

Comments
 (0)