Skip to content

Commit 89a410b

Browse files
authored
Merge pull request #7 from wantainc/issue/6
add: useGlobalDraftKey parameter
2 parents 3f33206 + 0905ae6 commit 89a410b

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212
},
1313
"author": "Wanta Inc",
1414
"license": "Apache-2.0",
15-
"keywords": ["JavaScript", "node", "SDK", "microCMS"],
15+
"keywords": [
16+
"JavaScript",
17+
"node",
18+
"SDK",
19+
"microCMS"
20+
],
1621
"scripts": {
1722
"build": "rollup -c",
1823
"lint": "eslint ./src",
1924
"lint:fix": "eslint --fix ./src"
2025
},
21-
"files": ["dist"],
26+
"files": [
27+
"dist"
28+
],
2229
"dependencies": {
2330
"node-fetch": "^2.6.1",
2431
"qs": "^6.10.1"

src/createClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ const createClient = ({ serviceDomain, apiKey, globalDraftKey }: ClientParams) =
3030
/**
3131
* Make request
3232
*/
33-
const makeRequest = async <T>({ endpoint, contentId, queries = {} }: MakeRequest): Promise<T> => {
33+
const makeRequest = async <T>({ endpoint, contentId, queries = {}, useGlobalDraftKey = true }: MakeRequest): Promise<T> => {
3434
const queryString = parseQuery(queries);
3535

3636
const baseHeaders = {
3737
headers: { 'X-API-KEY': apiKey },
3838
};
3939

40-
if (globalDraftKey) {
40+
if (globalDraftKey && useGlobalDraftKey) {
4141
Object.assign(baseHeaders.headers, { 'X-GLOBAL-DRAFT-KEY': globalDraftKey });
4242
}
4343

@@ -64,11 +64,11 @@ const createClient = ({ serviceDomain, apiKey, globalDraftKey }: ClientParams) =
6464
/**
6565
* Get API data for microCMS
6666
*/
67-
const get = async <T>({ endpoint, contentId, queries = {} }: GetRequest): Promise<T> => {
67+
const get = async <T>({ endpoint, contentId, queries = {}, useGlobalDraftKey }: GetRequest): Promise<T> => {
6868
if (!endpoint) {
6969
return Promise.reject(new Error('endpoint is required'));
7070
}
71-
return await makeRequest<T>({ endpoint, contentId, queries });
71+
return await makeRequest<T>({ endpoint, contentId, queries, useGlobalDraftKey });
7272
};
7373

7474
return {

src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ export interface MakeRequest {
88
endpoint: string;
99
contentId?: string;
1010
queries?: QueriesType;
11+
useGlobalDraftKey?: boolean;
1112
}
1213

1314
export interface GetRequest {
1415
endpoint: string;
1516
contentId?: string;
1617
queries?: QueriesType;
18+
useGlobalDraftKey?: boolean;
1719
}
1820

1921
type depthNumber = 1 | 2 | 3;

0 commit comments

Comments
 (0)