Skip to content

Commit 9550da0

Browse files
committed
X-MICROCMS-API-KEY対応
1 parent da842e9 commit 9550da0

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

src/createClient.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const API_VERSION = 'v1';
2323
/**
2424
* Initialize SDK Client
2525
*/
26-
export const createClient = ({ serviceDomain, apiKey, globalDraftKey }: MicroCMSClient) => {
26+
export const createClient = ({ serviceDomain, apiKey }: MicroCMSClient) => {
2727
if (!serviceDomain || !apiKey) {
2828
throw new Error('parameter is required (check serviceDomain and apiKey)');
2929
}
@@ -44,17 +44,13 @@ export const createClient = ({ serviceDomain, apiKey, globalDraftKey }: MicroCMS
4444
endpoint,
4545
contentId,
4646
queries = {},
47-
useGlobalDraftKey = true,
4847
}: MakeRequest): Promise<T> => {
4948
const queryString = parseQuery(queries);
5049

5150
const baseHeaders = {
52-
headers: { 'X-API-KEY': apiKey },
51+
headers: { 'X-MICROCMS-API-KEY': apiKey },
5352
};
5453

55-
if (globalDraftKey && useGlobalDraftKey) {
56-
Object.assign(baseHeaders.headers, { 'X-GLOBAL-DRAFT-KEY': globalDraftKey });
57-
}
5854

5955
const url = `${baseUrl}/${endpoint}${contentId ? `/${contentId}` : ''}${
6056
queryString ? `?${queryString}` : ''
@@ -90,12 +86,11 @@ export const createClient = ({ serviceDomain, apiKey, globalDraftKey }: MicroCMS
9086
endpoint,
9187
contentId,
9288
queries = {},
93-
useGlobalDraftKey,
9489
}: GetRequest): Promise<T> => {
9590
if (!endpoint) {
9691
return Promise.reject(new Error('endpoint is required'));
9792
}
98-
return await makeRequest<T>({ endpoint, contentId, queries, useGlobalDraftKey });
93+
return await makeRequest<T>({ endpoint, contentId, queries });
9994
};
10095

10196
/**
@@ -104,12 +99,11 @@ export const createClient = ({ serviceDomain, apiKey, globalDraftKey }: MicroCMS
10499
const getList = async <T = any>({
105100
endpoint,
106101
queries = {},
107-
useGlobalDraftKey,
108102
}: GetListRequest): Promise<MicroCMSListResponse<T>> => {
109103
if (!endpoint) {
110104
return Promise.reject(new Error('endpoint is required'));
111105
}
112-
return await makeRequest<MicroCMSListResponse<T>>({ endpoint, queries, useGlobalDraftKey });
106+
return await makeRequest<MicroCMSListResponse<T>>({ endpoint, queries });
113107
};
114108

115109
/**
@@ -119,7 +113,6 @@ export const createClient = ({ serviceDomain, apiKey, globalDraftKey }: MicroCMS
119113
endpoint,
120114
contentId,
121115
queries = {},
122-
useGlobalDraftKey,
123116
}: GetListDetailRequest): Promise<T & MicroCMSListContent> => {
124117
if (!endpoint) {
125118
return Promise.reject(new Error('endpoint is required'));
@@ -128,7 +121,6 @@ export const createClient = ({ serviceDomain, apiKey, globalDraftKey }: MicroCMS
128121
endpoint,
129122
contentId,
130123
queries,
131-
useGlobalDraftKey,
132124
});
133125
};
134126

@@ -138,15 +130,13 @@ export const createClient = ({ serviceDomain, apiKey, globalDraftKey }: MicroCMS
138130
const getObject = async <T = any>({
139131
endpoint,
140132
queries = {},
141-
useGlobalDraftKey,
142133
}: GetObjectRequest): Promise<T & MicroCMSObjectContent> => {
143134
if (!endpoint) {
144135
return Promise.reject(new Error('endpoint is required'));
145136
}
146137
return await makeRequest<T & MicroCMSObjectContent>({
147138
endpoint,
148139
queries,
149-
useGlobalDraftKey,
150140
});
151141
};
152142

src/types.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
export interface MicroCMSClient {
55
serviceDomain: string;
66
apiKey: string;
7-
globalDraftKey?: string;
87
}
98

109
type depthNumber = 1 | 2 | 3;
@@ -77,31 +76,26 @@ export interface MakeRequest {
7776
endpoint: string;
7877
contentId?: string;
7978
queries?: MicroCMSQueries;
80-
useGlobalDraftKey?: boolean;
8179
}
8280

8381
export interface GetRequest {
8482
endpoint: string;
8583
contentId?: string;
8684
queries?: MicroCMSQueries;
87-
useGlobalDraftKey?: boolean;
8885
}
8986

9087
export interface GetListDetailRequest {
9188
endpoint: string;
9289
contentId: string;
9390
queries?: MicroCMSQueries;
94-
useGlobalDraftKey?: boolean;
9591
}
9692

9793
export interface GetListRequest {
9894
endpoint: string;
9995
queries?: MicroCMSQueries;
100-
useGlobalDraftKey?: boolean;
10196
}
10297

10398
export interface GetObjectRequest {
10499
endpoint: string;
105100
queries?: MicroCMSQueries;
106-
useGlobalDraftKey?: boolean;
107101
}

0 commit comments

Comments
 (0)