Skip to content

Commit 3c139d0

Browse files
committed
Stack instance initialization issue resolved
1 parent 044aa1c commit 3c139d0

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/core/stack.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export default class Stack {
5050
this.config = config;
5151
this.cachePolicy = CacheProvider.policies.IGNORE_CACHE;
5252
this.provider = CacheProvider.providers('localstorage');
53+
console.error(stack_arguments.length);
54+
5355
switch (stack_arguments.length) {
5456
case 1:
5557
if (typeof stack_arguments[0] === "object" && typeof stack_arguments[0].api_key === "string" && typeof stack_arguments[0].delivery_token === "string" && typeof stack_arguments[0].environment === "string") {
@@ -62,7 +64,36 @@ export default class Stack {
6264
} else {
6365
console.error("Kindly provide valid object parameters. The specified API Key, Delivery Token, or Environment Name is invalid.");
6466
}
65-
case 3, 4, 5:
67+
case 3:
68+
if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") {
69+
this.headers = {
70+
api_key: stack_arguments[0],
71+
access_token: stack_arguments[1]
72+
};
73+
this.environment = stack_arguments[2];
74+
return this;
75+
} else {
76+
console.error("Kindly provide valid string parameters.");
77+
}
78+
case 4:
79+
if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") {
80+
this.headers = {
81+
api_key: stack_arguments[0],
82+
access_token: stack_arguments[1]
83+
};
84+
this.environment = stack_arguments[2];
85+
return this;
86+
} else {
87+
console.error("Kindly provide valid string parameters.");
88+
}
89+
if (stack_arguments[3]) {
90+
if(typeof stack_arguments[3] === "string" && stack_arguments[3].region !== "us" && stack_arguments[3].region === "eu") {
91+
config['host'] = stack_arguments[0].region+"-"+"cdn.contentstack.com";
92+
} else if (typeof stack_arguments[3] === 'object') {
93+
this.fetchOptions = stack_arguments[3]
94+
}
95+
}
96+
case 5:
6697
if (typeof stack_arguments[0] === "string" && typeof stack_arguments[1] === "string" && typeof stack_arguments[2] === "string") {
6798
this.headers = {
6899
api_key: stack_arguments[0],
@@ -80,7 +111,6 @@ export default class Stack {
80111
this.fetchOptions = stack_arguments[3]
81112
}
82113
}
83-
84114
if (stack_arguments[4] && typeof stack_arguments[4] === 'object') {
85115
this.fetchOptions = stack_arguments[3]
86116
}

0 commit comments

Comments
 (0)