daiso 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -4
- package/dist/api/actionsProxy.js +111 -21
- package/dist/api/configStatus.js +5 -1
- package/dist/api/gs25Handlers.js +45 -10
- package/dist/api/healthChecks.js +50 -9
- package/dist/api/placesHandlers.js +44 -0
- package/dist/api/routes/healthRoutes.js +1 -1
- package/dist/api/routes/placesRoutes.js +9 -0
- package/dist/cli/commandOptions.js +64 -6
- package/dist/cli/commands/convenience.js +20 -0
- package/dist/cli.js +3 -1
- package/dist/cliHelp.js +14 -6
- package/dist/cliRenderer.js +9 -2
- package/dist/core/registry.js +21 -2
- package/dist/index.js +17 -3
- package/dist/pages/openapiFullSpec.js +3 -0
- package/dist/pages/openapiSpecActions.js +308 -42
- package/dist/pages/openapiSpecPathsPlaces.js +85 -0
- package/dist/pages/promptReferenceText.js +3 -0
- package/dist/pages/promptRetailCinemaText.js +22 -1
- package/dist/services/gs25/api.js +3 -0
- package/dist/services/gs25/client.js +211 -35
- package/dist/services/gs25/index.js +11 -3
- package/dist/services/gs25/tools/checkInventory.js +39 -12
- package/dist/services/gs25/tools/findNearbyStores.js +19 -5
- package/dist/services/gs25/tools/searchProducts.js +11 -4
- package/dist/services/oliveyoung/client.js +90 -41
- package/dist/services/places/client.js +116 -0
- package/dist/services/places/index.js +23 -0
- package/dist/services/places/tools/searchNearby.js +56 -0
- package/dist/services/places/types.js +1 -0
- package/dist/utils/zyte.js +45 -18
- package/openapi.json +19 -0
- package/openapi.yaml +13 -0
- package/package.json +3 -2
|
@@ -2,12 +2,21 @@
|
|
|
2
2
|
* GS25 API 클라이언트
|
|
3
3
|
*/
|
|
4
4
|
/* c8 ignore start */
|
|
5
|
-
import { fetchJson } from '../../utils/http.js';
|
|
5
|
+
import { fetchJson, fetchWithTimeout, HttpError } from '../../utils/http.js';
|
|
6
|
+
import { decodeZyteHttpBody, requestByZyte } from '../../utils/zyte.js';
|
|
6
7
|
import { GS25_API } from './api.js';
|
|
7
8
|
import { normalizeStore, toNumber } from './storeUtils.js';
|
|
8
9
|
export { attachDistanceToGs25Stores, calculateDistanceM, extractGs25ProductCandidates, filterGs25StoresByKeyword, selectGs25StoresForKeyword, sortGs25Stores, } from './storeUtils.js';
|
|
9
10
|
const GS25_DEFAULT_HEADERS = {
|
|
10
11
|
Accept: 'application/json, text/plain, */*',
|
|
12
|
+
'Accept-Language': 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7',
|
|
13
|
+
'User-Agent': 'Mozilla/5.0 (Linux; Android 15; SM-S928N) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/124.0 Mobile Safari/537.36',
|
|
14
|
+
Origin: 'https://woodongs.com',
|
|
15
|
+
Referer: 'https://woodongs.com/',
|
|
16
|
+
};
|
|
17
|
+
const GS25_TOTAL_SEARCH_HEADERS = {
|
|
18
|
+
...GS25_DEFAULT_HEADERS,
|
|
19
|
+
'Content-Type': 'application/json',
|
|
11
20
|
};
|
|
12
21
|
const GS25_DEFAULT_FETCH_OPTIONS = {
|
|
13
22
|
retries: 1,
|
|
@@ -15,6 +24,107 @@ const GS25_DEFAULT_FETCH_OPTIONS = {
|
|
|
15
24
|
};
|
|
16
25
|
const GS25_STORES_CACHE_TTL_MS = 60 * 5 * 1000;
|
|
17
26
|
const gs25StoresCache = new Map();
|
|
27
|
+
function extractGs25WebCsrfToken(html) {
|
|
28
|
+
return (html.match(/name="CSRFToken"\s+value="([^"]+)"/)?.[1] ||
|
|
29
|
+
html.match(/ACC\.config\.CSRFToken\s*=\s*"([^"]+)"/)?.[1] ||
|
|
30
|
+
null);
|
|
31
|
+
}
|
|
32
|
+
function extractGs25WebCookieHeader(headers) {
|
|
33
|
+
const setCookie = headers.get('set-cookie') || '';
|
|
34
|
+
const jsessionId = setCookie.match(/JSESSIONID=[^;,\s]+/)?.[0];
|
|
35
|
+
return jsessionId;
|
|
36
|
+
}
|
|
37
|
+
function parseGs25WebLocationResponse(body) {
|
|
38
|
+
if (typeof body === 'string') {
|
|
39
|
+
return JSON.parse(body);
|
|
40
|
+
}
|
|
41
|
+
return body;
|
|
42
|
+
}
|
|
43
|
+
function normalizeGs25WebStore(raw) {
|
|
44
|
+
const propertyNames = (raw.offeringService || []).filter((item) => item.trim().length > 0);
|
|
45
|
+
return {
|
|
46
|
+
storeCode: raw.shopCode || '',
|
|
47
|
+
storeName: raw.shopName || '',
|
|
48
|
+
address: raw.address || '',
|
|
49
|
+
phone: '',
|
|
50
|
+
latitude: toNumber(raw.longs),
|
|
51
|
+
longitude: toNumber(raw.lat),
|
|
52
|
+
serviceCode: '01',
|
|
53
|
+
realStockQuantity: 0,
|
|
54
|
+
pickupStockQuantity: 0,
|
|
55
|
+
deliveryStockQuantity: 0,
|
|
56
|
+
isSoldOut: false,
|
|
57
|
+
searchItemName: '',
|
|
58
|
+
searchItemSellPrice: null,
|
|
59
|
+
propertyNames,
|
|
60
|
+
properties: propertyNames.map((name) => ({
|
|
61
|
+
code: name,
|
|
62
|
+
name,
|
|
63
|
+
type: 'service',
|
|
64
|
+
imageUrl: '',
|
|
65
|
+
})),
|
|
66
|
+
distanceM: null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
async function fetchGs25StoreStock(url, options) {
|
|
70
|
+
try {
|
|
71
|
+
return await fetchJson(url, {
|
|
72
|
+
...GS25_DEFAULT_FETCH_OPTIONS,
|
|
73
|
+
method: 'GET',
|
|
74
|
+
timeout: options.timeout,
|
|
75
|
+
headers: GS25_DEFAULT_HEADERS,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
const zyteApiKey = options.zyteApiKey?.trim();
|
|
80
|
+
if (!(error instanceof HttpError) || error.status !== 403 || !zyteApiKey) {
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
const result = await requestByZyte({
|
|
84
|
+
apiKey: zyteApiKey,
|
|
85
|
+
url,
|
|
86
|
+
method: 'GET',
|
|
87
|
+
timeout: options.timeout,
|
|
88
|
+
retries: 1,
|
|
89
|
+
headers: Object.entries(GS25_DEFAULT_HEADERS).map(([name, value]) => ({ name, value })),
|
|
90
|
+
});
|
|
91
|
+
return decodeZyteHttpBody(result);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async function fetchGs25TotalSearchResponse(query, options) {
|
|
95
|
+
const { timeout = 20000 } = options;
|
|
96
|
+
const endpoint = new URL(GS25_API.TOTAL_SEARCH_PATH, GS25_API.APIGW_BASE_URL);
|
|
97
|
+
const bodyText = JSON.stringify({ query });
|
|
98
|
+
try {
|
|
99
|
+
return await fetchJson(endpoint.toString(), {
|
|
100
|
+
...GS25_DEFAULT_FETCH_OPTIONS,
|
|
101
|
+
method: 'POST',
|
|
102
|
+
retryUnsafeMethods: true,
|
|
103
|
+
timeout,
|
|
104
|
+
headers: GS25_TOTAL_SEARCH_HEADERS,
|
|
105
|
+
body: bodyText,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
const zyteApiKey = options.zyteApiKey?.trim();
|
|
110
|
+
if (!(error instanceof HttpError) || error.status !== 403 || !zyteApiKey) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
const result = await requestByZyte({
|
|
114
|
+
apiKey: zyteApiKey,
|
|
115
|
+
url: endpoint.toString(),
|
|
116
|
+
method: 'POST',
|
|
117
|
+
timeout,
|
|
118
|
+
retries: 1,
|
|
119
|
+
headers: Object.entries(GS25_TOTAL_SEARCH_HEADERS).map(([name, value]) => ({
|
|
120
|
+
name,
|
|
121
|
+
value,
|
|
122
|
+
})),
|
|
123
|
+
bodyText,
|
|
124
|
+
});
|
|
125
|
+
return decodeZyteHttpBody(result);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
18
128
|
function buildCacheKey(params) {
|
|
19
129
|
return [
|
|
20
130
|
params.serviceCode,
|
|
@@ -59,8 +169,94 @@ export async function geocodeGs25Address(address, options = {}) {
|
|
|
59
169
|
}
|
|
60
170
|
return { latitude, longitude };
|
|
61
171
|
}
|
|
172
|
+
export async function fetchGs25WebStores(keyword, options = {}) {
|
|
173
|
+
const query = keyword.trim();
|
|
174
|
+
if (query.length === 0) {
|
|
175
|
+
return { totalCount: 0, stores: [] };
|
|
176
|
+
}
|
|
177
|
+
const { timeout = 20000 } = options;
|
|
178
|
+
const locationsUrl = new URL(GS25_API.WEB_LOCATIONS_PATH, GS25_API.WEB_BASE_URL);
|
|
179
|
+
const locationsResponse = await fetchWithTimeout(locationsUrl.toString(), {
|
|
180
|
+
...GS25_DEFAULT_FETCH_OPTIONS,
|
|
181
|
+
method: 'GET',
|
|
182
|
+
timeout,
|
|
183
|
+
headers: {
|
|
184
|
+
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
185
|
+
'Accept-Language': GS25_DEFAULT_HEADERS['Accept-Language'],
|
|
186
|
+
'User-Agent': GS25_DEFAULT_HEADERS['User-Agent'],
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
if (!locationsResponse.ok) {
|
|
190
|
+
throw new HttpError(locationsResponse.status, locationsResponse.statusText, await locationsResponse.text());
|
|
191
|
+
}
|
|
192
|
+
const html = await locationsResponse.text();
|
|
193
|
+
const csrfToken = extractGs25WebCsrfToken(html);
|
|
194
|
+
if (!csrfToken) {
|
|
195
|
+
throw new Error('GS25 웹 매장 검색 CSRF 토큰을 찾을 수 없습니다.');
|
|
196
|
+
}
|
|
197
|
+
const form = new URLSearchParams({
|
|
198
|
+
pageNum: '1',
|
|
199
|
+
pageSize: '50',
|
|
200
|
+
searchShopName: query,
|
|
201
|
+
searchSido: '',
|
|
202
|
+
searchGugun: '',
|
|
203
|
+
searchDong: '',
|
|
204
|
+
searchType: '',
|
|
205
|
+
searchTypeService: '0',
|
|
206
|
+
searchTypeToto: '0',
|
|
207
|
+
searchTypeCafe25: '0',
|
|
208
|
+
searchTypeInstant: '0',
|
|
209
|
+
searchTypeDrug: '0',
|
|
210
|
+
searchTypeSelf25: '0',
|
|
211
|
+
searchTypePost: '0',
|
|
212
|
+
searchTypeATM: '0',
|
|
213
|
+
searchTypeWithdrawal: '0',
|
|
214
|
+
searchTypeTaxrefund: '0',
|
|
215
|
+
searchTypeSmartAtm: '0',
|
|
216
|
+
searchTypeSelfCookingUtensils: '0',
|
|
217
|
+
searchTypeDeliveryService: '0',
|
|
218
|
+
searchTypeParcelService: '0',
|
|
219
|
+
searchTypePotatoes: '0',
|
|
220
|
+
searchTypeCardiacDefi: '0',
|
|
221
|
+
searchTypeFishShapedBun: '0',
|
|
222
|
+
searchTypeWine25: '0',
|
|
223
|
+
searchTypeGoPizza: '0',
|
|
224
|
+
searchTypeSpiritWine: '0',
|
|
225
|
+
searchTypeFreshGanghw: '0',
|
|
226
|
+
searchTypeMusinsa: '0',
|
|
227
|
+
searchTypePosa: '0',
|
|
228
|
+
});
|
|
229
|
+
const locationListUrl = new URL(GS25_API.WEB_LOCATION_LIST_PATH, GS25_API.WEB_BASE_URL);
|
|
230
|
+
locationListUrl.searchParams.set('CSRFToken', csrfToken);
|
|
231
|
+
const cookieHeader = extractGs25WebCookieHeader(locationsResponse.headers);
|
|
232
|
+
const body = parseGs25WebLocationResponse(await fetchJson(locationListUrl.toString(), {
|
|
233
|
+
...GS25_DEFAULT_FETCH_OPTIONS,
|
|
234
|
+
method: 'POST',
|
|
235
|
+
retryUnsafeMethods: true,
|
|
236
|
+
timeout,
|
|
237
|
+
headers: {
|
|
238
|
+
Accept: 'application/json, text/javascript, */*; q=0.01',
|
|
239
|
+
'Accept-Language': GS25_DEFAULT_HEADERS['Accept-Language'],
|
|
240
|
+
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
|
241
|
+
Referer: locationsUrl.toString(),
|
|
242
|
+
'User-Agent': GS25_DEFAULT_HEADERS['User-Agent'],
|
|
243
|
+
'X-Requested-With': 'XMLHttpRequest',
|
|
244
|
+
...(cookieHeader ? { Cookie: cookieHeader } : {}),
|
|
245
|
+
},
|
|
246
|
+
body: form.toString(),
|
|
247
|
+
}));
|
|
248
|
+
const stores = (body.results || [])
|
|
249
|
+
.map(normalizeGs25WebStore)
|
|
250
|
+
.filter((store) => store.storeCode.length > 0);
|
|
251
|
+
return {
|
|
252
|
+
totalCount: typeof body.pagination?.totalNumberOfResults === 'number'
|
|
253
|
+
? body.pagination.totalNumberOfResults
|
|
254
|
+
: stores.length,
|
|
255
|
+
stores,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
62
258
|
export async function fetchGs25Stores(params = {}, options = {}) {
|
|
63
|
-
const { serviceCode = '01', keyword = '', itemCode = '', storeCode = '', realTimeStockYn = 'Y', latitude, longitude, pageNumber
|
|
259
|
+
const { serviceCode = '01', keyword = '', itemCode = '', storeCode = '', realTimeStockYn = 'Y', latitude, longitude, pageNumber, pageCount, useCache = true, } = params;
|
|
64
260
|
const { timeout = 20000 } = options;
|
|
65
261
|
const cacheKey = buildCacheKey({
|
|
66
262
|
serviceCode,
|
|
@@ -82,9 +278,13 @@ export async function fetchGs25Stores(params = {}, options = {}) {
|
|
|
82
278
|
}
|
|
83
279
|
const endpoint = new URL(GS25_API.STORE_STOCK_PATH, GS25_API.BFF_BASE_URL);
|
|
84
280
|
endpoint.searchParams.set('serviceCode', serviceCode);
|
|
85
|
-
endpoint.searchParams.set('pageNumber', String(pageNumber));
|
|
86
|
-
endpoint.searchParams.set('pageCount', String(pageCount));
|
|
87
281
|
endpoint.searchParams.set('realTimeStockYn', realTimeStockYn);
|
|
282
|
+
if (typeof pageNumber === 'number' && Number.isFinite(pageNumber)) {
|
|
283
|
+
endpoint.searchParams.set('pageNumber', String(Math.trunc(pageNumber)));
|
|
284
|
+
}
|
|
285
|
+
if (typeof pageCount === 'number' && Number.isFinite(pageCount)) {
|
|
286
|
+
endpoint.searchParams.set('pageCount', String(Math.trunc(pageCount)));
|
|
287
|
+
}
|
|
88
288
|
// itemCode가 있으면 itemCode 사용, 없으면 keyword 사용
|
|
89
289
|
// 주의: itemCode 사용 시 좌표도 필수
|
|
90
290
|
if (itemCode.trim().length > 0) {
|
|
@@ -113,13 +313,13 @@ export async function fetchGs25Stores(params = {}, options = {}) {
|
|
|
113
313
|
endpoint.searchParams.set('isSuperDlvyStoreSelected', 'N');
|
|
114
314
|
endpoint.searchParams.set('isGs25DlvyStoreSelected', 'N');
|
|
115
315
|
}
|
|
116
|
-
const body = await
|
|
117
|
-
...GS25_DEFAULT_FETCH_OPTIONS,
|
|
118
|
-
method: 'GET',
|
|
316
|
+
const body = await fetchGs25StoreStock(endpoint.toString(), {
|
|
119
317
|
timeout,
|
|
120
|
-
|
|
318
|
+
zyteApiKey: options.zyteApiKey,
|
|
121
319
|
});
|
|
122
|
-
const stores = (body.stores || [])
|
|
320
|
+
const stores = (body.stores || [])
|
|
321
|
+
.map(normalizeStore)
|
|
322
|
+
.filter((store) => store.storeCode.length > 0);
|
|
123
323
|
if (useCache) {
|
|
124
324
|
gs25StoresCache.set(cacheKey, {
|
|
125
325
|
stores,
|
|
@@ -137,19 +337,7 @@ export async function fetchGs25NormalizedKeyword(keyword, options = {}) {
|
|
|
137
337
|
if (query.length === 0) {
|
|
138
338
|
return null;
|
|
139
339
|
}
|
|
140
|
-
const
|
|
141
|
-
const endpoint = new URL(GS25_API.TOTAL_SEARCH_PATH, GS25_API.APIGW_BASE_URL);
|
|
142
|
-
const body = await fetchJson(endpoint.toString(), {
|
|
143
|
-
...GS25_DEFAULT_FETCH_OPTIONS,
|
|
144
|
-
method: 'POST',
|
|
145
|
-
retryUnsafeMethods: true,
|
|
146
|
-
timeout,
|
|
147
|
-
headers: {
|
|
148
|
-
Accept: 'application/json, text/plain, */*',
|
|
149
|
-
'Content-Type': 'application/json',
|
|
150
|
-
},
|
|
151
|
-
body: JSON.stringify({ query }),
|
|
152
|
-
});
|
|
340
|
+
const body = await fetchGs25TotalSearchResponse(query, options);
|
|
153
341
|
const normalizedKeyword = body.SearchQueryResult?.keywordInfo?.keyword?.trim() || '';
|
|
154
342
|
const normalizedSearchKeyword = body.SearchQueryResult?.keywordInfo?.searchKeyword?.trim() || '';
|
|
155
343
|
if (normalizedKeyword.length === 0 && normalizedSearchKeyword.length === 0) {
|
|
@@ -169,19 +357,7 @@ export async function fetchGs25SearchProducts(keyword, options = {}) {
|
|
|
169
357
|
if (query.length === 0) {
|
|
170
358
|
return [];
|
|
171
359
|
}
|
|
172
|
-
const
|
|
173
|
-
const endpoint = new URL(GS25_API.TOTAL_SEARCH_PATH, GS25_API.APIGW_BASE_URL);
|
|
174
|
-
const body = await fetchJson(endpoint.toString(), {
|
|
175
|
-
...GS25_DEFAULT_FETCH_OPTIONS,
|
|
176
|
-
method: 'POST',
|
|
177
|
-
retryUnsafeMethods: true,
|
|
178
|
-
timeout,
|
|
179
|
-
headers: {
|
|
180
|
-
Accept: 'application/json, text/plain, */*',
|
|
181
|
-
'Content-Type': 'application/json',
|
|
182
|
-
},
|
|
183
|
-
body: JSON.stringify({ query }),
|
|
184
|
-
});
|
|
360
|
+
const body = await fetchGs25TotalSearchResponse(query, options);
|
|
185
361
|
const products = [];
|
|
186
362
|
const collections = body.SearchQueryResult?.Collection || [];
|
|
187
363
|
for (const collection of collections) {
|
|
@@ -11,12 +11,20 @@ const GS25_METADATA = {
|
|
|
11
11
|
description: 'GS25 매장 탐색, 상품 키워드 검색, 재고 조회 서비스',
|
|
12
12
|
};
|
|
13
13
|
class Gs25Service {
|
|
14
|
+
options;
|
|
14
15
|
metadata = GS25_METADATA;
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
15
19
|
getTools() {
|
|
16
|
-
return [
|
|
20
|
+
return [
|
|
21
|
+
createFindNearbyStoresTool(this.options.googleMapsApiKey, this.options.zyteApiKey),
|
|
22
|
+
createSearchProductsTool(this.options.zyteApiKey),
|
|
23
|
+
createCheckInventoryTool(this.options.googleMapsApiKey, this.options.zyteApiKey),
|
|
24
|
+
];
|
|
17
25
|
}
|
|
18
26
|
}
|
|
19
|
-
export function createGs25Service() {
|
|
20
|
-
return new Gs25Service();
|
|
27
|
+
export function createGs25Service(options = {}) {
|
|
28
|
+
return new Gs25Service(options);
|
|
21
29
|
}
|
|
22
30
|
export * from './types.js';
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
/* c8 ignore start */
|
|
5
5
|
import * as z from 'zod';
|
|
6
6
|
import { attachDistanceToGs25Stores, fetchGs25SearchProducts, fetchGs25Stores, filterGs25StoresByKeyword, geocodeGs25Address, selectGs25StoresForKeyword, sortGs25Stores, } from '../client.js';
|
|
7
|
+
function getProcessEnvValue(name) {
|
|
8
|
+
return typeof process !== 'undefined' ? process.env[name] : undefined;
|
|
9
|
+
}
|
|
7
10
|
async function checkInventory(args) {
|
|
8
|
-
const { keyword, itemCode: providedItemCode, latitude, longitude, storeKeyword = '', serviceCode = '01', storeLimit = 20, timeoutMs = 20000, } = args;
|
|
11
|
+
const { keyword, itemCode: providedItemCode, latitude, longitude, storeKeyword = '', serviceCode = '01', storeLimit = 20, timeoutMs = 20000, googleMapsApiKey = getProcessEnvValue('GOOGLE_MAPS_API_KEY'), zyteApiKey = getProcessEnvValue('ZYTE_API_KEY'), } = args;
|
|
9
12
|
if (!keyword || keyword.trim().length === 0) {
|
|
10
13
|
throw new Error('상품 검색어(keyword)를 입력해주세요.');
|
|
11
14
|
}
|
|
@@ -21,13 +24,13 @@ async function checkInventory(args) {
|
|
|
21
24
|
serviceCode,
|
|
22
25
|
}, {
|
|
23
26
|
timeout: timeoutMs,
|
|
27
|
+
zyteApiKey,
|
|
24
28
|
});
|
|
25
|
-
const firstAddress = filterGs25StoresByKeyword(baseStores.stores, storeKeyword).find((store) => store.address.trim().length > 0)
|
|
26
|
-
?.address || '';
|
|
29
|
+
const firstAddress = filterGs25StoresByKeyword(baseStores.stores, storeKeyword).find((store) => store.address.trim().length > 0)?.address || '';
|
|
27
30
|
if (firstAddress.length > 0) {
|
|
28
31
|
const geocoded = await geocodeGs25Address(firstAddress, {
|
|
29
32
|
timeout: timeoutMs,
|
|
30
|
-
googleMapsApiKey
|
|
33
|
+
googleMapsApiKey,
|
|
31
34
|
});
|
|
32
35
|
if (geocoded) {
|
|
33
36
|
resolvedLatitude = geocoded.latitude;
|
|
@@ -57,11 +60,15 @@ async function checkInventory(args) {
|
|
|
57
60
|
useCache: false,
|
|
58
61
|
}, {
|
|
59
62
|
timeout: timeoutMs,
|
|
63
|
+
zyteApiKey,
|
|
60
64
|
});
|
|
61
65
|
}
|
|
62
66
|
else {
|
|
63
67
|
// itemCode가 없으면 totalSearch API로 키워드 → itemCode 변환
|
|
64
|
-
const searchProducts = await fetchGs25SearchProducts(keyword, {
|
|
68
|
+
const searchProducts = await fetchGs25SearchProducts(keyword, {
|
|
69
|
+
timeout: timeoutMs,
|
|
70
|
+
zyteApiKey,
|
|
71
|
+
});
|
|
65
72
|
firstProduct = searchProducts.find((p) => p.itemCode.length > 0);
|
|
66
73
|
if (firstProduct) {
|
|
67
74
|
resolvedItemCode = firstProduct.itemCode;
|
|
@@ -75,6 +82,7 @@ async function checkInventory(args) {
|
|
|
75
82
|
useCache: false,
|
|
76
83
|
}, {
|
|
77
84
|
timeout: timeoutMs,
|
|
85
|
+
zyteApiKey,
|
|
78
86
|
});
|
|
79
87
|
}
|
|
80
88
|
else {
|
|
@@ -88,6 +96,7 @@ async function checkInventory(args) {
|
|
|
88
96
|
useCache: false,
|
|
89
97
|
}, {
|
|
90
98
|
timeout: timeoutMs,
|
|
99
|
+
zyteApiKey,
|
|
91
100
|
});
|
|
92
101
|
}
|
|
93
102
|
}
|
|
@@ -101,7 +110,8 @@ async function checkInventory(args) {
|
|
|
101
110
|
const totalStockQuantity = filteredByStoreKeyword.reduce((sum, item) => sum + Math.max(item.realStockQuantity, 0), 0);
|
|
102
111
|
// searchProducts에서 상품 정보 사용
|
|
103
112
|
const firstProductName = firstProduct?.itemName || firstProduct?.shortItemName || null;
|
|
104
|
-
const firstProductPrice = filteredByStoreKeyword.find((item) => item.searchItemSellPrice !== null)?.searchItemSellPrice ??
|
|
113
|
+
const firstProductPrice = filteredByStoreKeyword.find((item) => item.searchItemSellPrice !== null)?.searchItemSellPrice ??
|
|
114
|
+
null;
|
|
105
115
|
return {
|
|
106
116
|
content: [
|
|
107
117
|
{
|
|
@@ -137,7 +147,7 @@ async function checkInventory(args) {
|
|
|
137
147
|
],
|
|
138
148
|
};
|
|
139
149
|
}
|
|
140
|
-
export function createCheckInventoryTool() {
|
|
150
|
+
export function createCheckInventoryTool(googleMapsApiKey, zyteApiKey) {
|
|
141
151
|
return {
|
|
142
152
|
name: 'gs25_check_inventory',
|
|
143
153
|
metadata: {
|
|
@@ -149,15 +159,32 @@ export function createCheckInventoryTool() {
|
|
|
149
159
|
.string()
|
|
150
160
|
.optional()
|
|
151
161
|
.describe('상품 코드 (gs25_search_products로 조회한 정확한 코드, 제공 시 keyword 검색 건너뜀)'),
|
|
152
|
-
latitude: z
|
|
153
|
-
|
|
154
|
-
|
|
162
|
+
latitude: z
|
|
163
|
+
.number()
|
|
164
|
+
.optional()
|
|
165
|
+
.describe('위도 (선택, 미입력 시 storeKeyword 지오코딩 시도)'),
|
|
166
|
+
longitude: z
|
|
167
|
+
.number()
|
|
168
|
+
.optional()
|
|
169
|
+
.describe('경도 (선택, 미입력 시 storeKeyword 지오코딩 시도)'),
|
|
170
|
+
storeKeyword: z
|
|
171
|
+
.string()
|
|
172
|
+
.optional()
|
|
173
|
+
.describe('매장명/주소 키워드 필터 (예: 강남, 안산 중앙역)'),
|
|
155
174
|
serviceCode: z.string().optional().default('01').describe('서비스 코드 (기본값: 01=GS25)'),
|
|
156
175
|
storeLimit: z.number().optional().default(20).describe('반환할 매장 수 (기본값: 20)'),
|
|
157
|
-
timeoutMs: z
|
|
176
|
+
timeoutMs: z
|
|
177
|
+
.number()
|
|
178
|
+
.optional()
|
|
179
|
+
.default(20000)
|
|
180
|
+
.describe('요청 제한 시간(ms, 기본값: 20000)'),
|
|
158
181
|
},
|
|
159
182
|
},
|
|
160
|
-
handler: checkInventory
|
|
183
|
+
handler: ((args) => checkInventory({
|
|
184
|
+
...args,
|
|
185
|
+
googleMapsApiKey: args.googleMapsApiKey || googleMapsApiKey,
|
|
186
|
+
zyteApiKey: args.zyteApiKey || zyteApiKey,
|
|
187
|
+
})),
|
|
161
188
|
};
|
|
162
189
|
}
|
|
163
190
|
/* c8 ignore stop */
|
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
import * as z from 'zod';
|
|
5
5
|
import { attachDistanceToGs25Stores, fetchGs25Stores, geocodeGs25Address, selectGs25StoresForKeyword, sortGs25Stores, } from '../client.js';
|
|
6
6
|
const FALLBACK_STORE_LOOKUP_ITEM_CODE = '8801117752804';
|
|
7
|
+
function getProcessEnvValue(name) {
|
|
8
|
+
/* c8 ignore next -- Node 테스트와 CLI 런타임은 process를 제공하며, Worker에는 API에서 키를 주입합니다. */
|
|
9
|
+
return typeof process !== 'undefined' ? process.env[name] : undefined;
|
|
10
|
+
}
|
|
7
11
|
async function findNearbyStores(args) {
|
|
8
|
-
const { latitude, longitude, keyword = '', serviceCode = '01', limit = 20, timeoutMs = 20000, } = args;
|
|
12
|
+
const { latitude, longitude, keyword = '', serviceCode = '01', limit = 20, timeoutMs = 20000, googleMapsApiKey = getProcessEnvValue('GOOGLE_MAPS_API_KEY'), zyteApiKey = getProcessEnvValue('ZYTE_API_KEY'), } = args;
|
|
9
13
|
let resolvedLatitude = latitude;
|
|
10
14
|
let resolvedLongitude = longitude;
|
|
11
15
|
let geocodeUsed = false;
|
|
@@ -13,7 +17,7 @@ async function findNearbyStores(args) {
|
|
|
13
17
|
keyword.trim().length > 0) {
|
|
14
18
|
const geocoded = await geocodeGs25Address(keyword, {
|
|
15
19
|
timeout: timeoutMs,
|
|
16
|
-
googleMapsApiKey
|
|
20
|
+
googleMapsApiKey,
|
|
17
21
|
});
|
|
18
22
|
if (geocoded) {
|
|
19
23
|
resolvedLatitude = geocoded.latitude;
|
|
@@ -27,6 +31,7 @@ async function findNearbyStores(args) {
|
|
|
27
31
|
longitude: resolvedLongitude,
|
|
28
32
|
}, {
|
|
29
33
|
timeout: timeoutMs,
|
|
34
|
+
zyteApiKey,
|
|
30
35
|
});
|
|
31
36
|
let fallbackUsed = false;
|
|
32
37
|
if (result.stores.length === 0 &&
|
|
@@ -42,6 +47,7 @@ async function findNearbyStores(args) {
|
|
|
42
47
|
useCache: false,
|
|
43
48
|
}, {
|
|
44
49
|
timeout: timeoutMs,
|
|
50
|
+
zyteApiKey,
|
|
45
51
|
});
|
|
46
52
|
if (fallbackResult.stores.length > 0) {
|
|
47
53
|
result = fallbackResult;
|
|
@@ -83,7 +89,7 @@ async function findNearbyStores(args) {
|
|
|
83
89
|
],
|
|
84
90
|
};
|
|
85
91
|
}
|
|
86
|
-
export function createFindNearbyStoresTool() {
|
|
92
|
+
export function createFindNearbyStoresTool(googleMapsApiKey, zyteApiKey) {
|
|
87
93
|
return {
|
|
88
94
|
name: 'gs25_find_nearby_stores',
|
|
89
95
|
metadata: {
|
|
@@ -95,9 +101,17 @@ export function createFindNearbyStoresTool() {
|
|
|
95
101
|
keyword: z.string().optional().describe('매장명/주소 키워드 (예: 강남, 안산 중앙역)'),
|
|
96
102
|
serviceCode: z.string().optional().default('01').describe('서비스 코드 (기본값: 01=GS25)'),
|
|
97
103
|
limit: z.number().optional().default(20).describe('반환할 최대 매장 수 (기본값: 20)'),
|
|
98
|
-
timeoutMs: z
|
|
104
|
+
timeoutMs: z
|
|
105
|
+
.number()
|
|
106
|
+
.optional()
|
|
107
|
+
.default(20000)
|
|
108
|
+
.describe('요청 제한 시간(ms, 기본값: 20000)'),
|
|
99
109
|
},
|
|
100
110
|
},
|
|
101
|
-
handler: findNearbyStores
|
|
111
|
+
handler: ((args) => findNearbyStores({
|
|
112
|
+
...args,
|
|
113
|
+
googleMapsApiKey: args.googleMapsApiKey || googleMapsApiKey,
|
|
114
|
+
zyteApiKey: args.zyteApiKey || zyteApiKey,
|
|
115
|
+
})),
|
|
102
116
|
};
|
|
103
117
|
}
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as z from 'zod';
|
|
5
5
|
import { fetchGs25SearchProducts } from '../client.js';
|
|
6
|
+
function getProcessEnvValue(name) {
|
|
7
|
+
if (typeof process !== 'undefined') {
|
|
8
|
+
return process.env[name];
|
|
9
|
+
}
|
|
10
|
+
/* c8 ignore next -- process가 없는 런타임 방어 분기 */
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
6
13
|
function buildTextResponse(payload) {
|
|
7
14
|
return {
|
|
8
15
|
content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }],
|
|
@@ -10,11 +17,11 @@ function buildTextResponse(payload) {
|
|
|
10
17
|
};
|
|
11
18
|
}
|
|
12
19
|
async function searchProducts(args) {
|
|
13
|
-
const { keyword, limit = 20, timeoutMs = 20000 } = args;
|
|
20
|
+
const { keyword, limit = 20, timeoutMs = 20000, zyteApiKey = getProcessEnvValue('ZYTE_API_KEY'), } = args;
|
|
14
21
|
if (!keyword || keyword.trim().length === 0) {
|
|
15
22
|
throw new Error('상품 검색어(keyword)를 입력해주세요.');
|
|
16
23
|
}
|
|
17
|
-
const products = await fetchGs25SearchProducts(keyword, { timeout: timeoutMs });
|
|
24
|
+
const products = await fetchGs25SearchProducts(keyword, { timeout: timeoutMs, zyteApiKey });
|
|
18
25
|
const limitedProducts = products.slice(0, limit);
|
|
19
26
|
const payload = {
|
|
20
27
|
keyword,
|
|
@@ -39,7 +46,7 @@ const searchProductsOutputSchema = {
|
|
|
39
46
|
products: z.array(z.unknown()).describe('GS25 상품 검색 결과'),
|
|
40
47
|
note: z.string().describe('후속 재고 조회 안내'),
|
|
41
48
|
};
|
|
42
|
-
export function createSearchProductsTool() {
|
|
49
|
+
export function createSearchProductsTool(zyteApiKey) {
|
|
43
50
|
return {
|
|
44
51
|
name: 'gs25_search_products',
|
|
45
52
|
metadata: {
|
|
@@ -52,6 +59,6 @@ export function createSearchProductsTool() {
|
|
|
52
59
|
},
|
|
53
60
|
outputSchema: searchProductsOutputSchema,
|
|
54
61
|
},
|
|
55
|
-
handler: searchProducts,
|
|
62
|
+
handler: ((args) => searchProducts({ ...args, zyteApiKey: zyteApiKey ?? args.zyteApiKey })),
|
|
56
63
|
};
|
|
57
64
|
}
|