daiso 1.2.3 → 1.2.5

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.
@@ -1,3 +1,4 @@
1
+ import { isValidDtryxRelayUrl } from '../services/dtryx/transport.js';
1
2
  import { isValidOliveyoungRelayUrl } from '../services/oliveyoung/transport.js';
2
3
  function isConfigured(value) {
3
4
  return typeof value === 'string' && value.trim().length > 0;
@@ -11,6 +12,18 @@ export function buildConfigStatus(bindings) {
11
12
  const accessPairValid = (bindings?.OY_ACCESS_CLIENT_ID === undefined &&
12
13
  bindings?.OY_ACCESS_CLIENT_SECRET === undefined) ||
13
14
  accessConfigured;
15
+ const dtryxId = isConfigured(bindings?.DTRYX_ACCESS_CLIENT_ID);
16
+ const dtryxSecret = isConfigured(bindings?.DTRYX_ACCESS_CLIENT_SECRET);
17
+ const dtryx = {
18
+ urlValid: isValidDtryxRelayUrl(bindings?.DTRYX_RELAY_URL),
19
+ tokenConfigured: isConfigured(bindings?.DTRYX_RELAY_TOKEN),
20
+ accessClientIdConfigured: dtryxId,
21
+ accessClientSecretConfigured: dtryxSecret,
22
+ accessConfigured: dtryxId && dtryxSecret,
23
+ accessPairValid: (bindings?.DTRYX_ACCESS_CLIENT_ID === undefined &&
24
+ bindings?.DTRYX_ACCESS_CLIENT_SECRET === undefined) ||
25
+ (dtryxId && dtryxSecret),
26
+ };
14
27
  return {
15
28
  oliveyoungRelay: {
16
29
  configured: urlValid && tokenConfigured && accessPairValid,
@@ -23,6 +36,17 @@ export function buildConfigStatus(bindings) {
23
36
  accessPairValid,
24
37
  usedBy: ['oliveyoung'],
25
38
  },
39
+ dtryxRelay: {
40
+ configured: dtryx.urlValid && dtryx.tokenConfigured && dtryx.accessPairValid,
41
+ urlConfigured: isConfigured(bindings?.DTRYX_RELAY_URL),
42
+ urlValid: dtryx.urlValid,
43
+ tokenConfigured: dtryx.tokenConfigured,
44
+ accessClientIdConfigured: dtryx.accessClientIdConfigured,
45
+ accessClientSecretConfigured: dtryx.accessClientSecretConfigured,
46
+ accessConfigured: dtryx.accessConfigured,
47
+ accessPairValid: dtryx.accessPairValid,
48
+ usedBy: ['dtryx'],
49
+ },
26
50
  googleMapsApiKey: {
27
51
  configured: isConfigured(bindings?.GOOGLE_MAPS_API_KEY),
28
52
  usedBy: ['gs25', 'cu', 'lottemart', 'megabox', 'lottecinema', 'cgv'],
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * 디트릭스 GET API 핸들러
3
3
  */
4
+ import { ServiceError } from '../core/errors.js';
5
+ import { dtryxTransportFromBindings } from '../services/dtryx/transport.js';
4
6
  import { resolveDtryxCinemas } from '../services/dtryx/location.js';
5
7
  import { DTRYX_INVALID_INPUT, hasInvalidDtryxOptions } from '../services/dtryx/validation.js';
6
8
  import { fetchDtryxNowShowing, fetchDtryxPlayDates, fetchDtryxTimetable, toYyyymmdd, } from '../services/dtryx/client.js';
7
- import { errorResponse, successResponse } from './response.js';
9
+ import { errorResponse, serviceErrorResponse, successResponse, } from './response.js';
8
10
  export async function handleDtryxListCinemas(c) {
9
11
  const keyword = c.req.query('keyword') || undefined;
10
12
  const region = c.req.query('region') || undefined;
@@ -45,8 +47,10 @@ export async function handleDtryxListNowShowing(c) {
45
47
  timeout: timeoutMs,
46
48
  };
47
49
  const [movies, playDates] = await Promise.all([
48
- fetchDtryxNowShowing(request),
49
- includePlayDates ? fetchDtryxPlayDates(request) : Promise.resolve([]),
50
+ fetchDtryxNowShowing(request, dtryxTransportFromBindings(c.env)),
51
+ includePlayDates
52
+ ? fetchDtryxPlayDates(request, dtryxTransportFromBindings(c.env))
53
+ : Promise.resolve([]),
50
54
  ]);
51
55
  return successResponse(c, {
52
56
  cinema,
@@ -56,6 +60,8 @@ export async function handleDtryxListNowShowing(c) {
56
60
  }, { total: movies.length });
57
61
  }
58
62
  catch (error) {
63
+ if (error instanceof ServiceError)
64
+ return serviceErrorResponse(c, error, 'now_showing');
59
65
  const message = error instanceof Error ? error.message : '알 수 없는 오류가 발생했습니다.';
60
66
  return errorResponse(c, 'DTRYX_NOW_SHOWING_FAILED', message, 500);
61
67
  }
@@ -82,7 +88,7 @@ export async function handleDtryxGetRemainingSeats(c) {
82
88
  cinemaCode: cinema.cinemaCode,
83
89
  playDate,
84
90
  timeout: timeoutMs,
85
- })));
91
+ }, dtryxTransportFromBindings(c.env))));
86
92
  const failedCinemas = cinemas
87
93
  .filter((_, index) => settled[index]?.status === 'rejected')
88
94
  .map((cinema) => cinema.cinemaName || cinema.cinemaCode);
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@
4
4
  * Cloudflare Workers에서 실행되는 플러그인 기반 MCP 서버입니다.
5
5
  * 다이소, 편의점, 백화점 등 다양한 서비스를 확장할 수 있습니다.
6
6
  */
7
+ import { dtryxTransportFromBindings } from './services/dtryx/transport.js';
7
8
  import { Hono } from 'hono';
8
9
  import { cors } from 'hono/cors';
9
10
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
@@ -76,7 +77,7 @@ const createRegistry = (bindings) => {
76
77
  zyteApiKey: bindings?.ZYTE_API_KEY,
77
78
  }),
78
79
  createMegaboxService,
79
- createDtryxService,
80
+ () => createDtryxService(dtryxTransportFromBindings(bindings)),
80
81
  () => createLotteCinemaService({
81
82
  googleMapsApiKey: bindings?.GOOGLE_MAPS_API_KEY,
82
83
  }),
@@ -5,7 +5,11 @@
5
5
  * 공개 조회 엔드포인트이며 별도 인증 키가 필요하지 않습니다.
6
6
  */
7
7
  export const DTRYX_API = {
8
- BASE_URL: 'https://api.dtryx.com:30443',
8
+ /**
9
+ * 두 포트의 공개 조회 응답이 동일함을 확인해 표준 HTTPS 포트를 사용합니다.
10
+ * Worker의 간헐 연결 실패는 양쪽 포트에서 관측되어 별도로 추적합니다(#187).
11
+ */
12
+ BASE_URL: 'https://api.dtryx.com',
9
13
  THIRDPARTY_PATH: '/dtryx/cms/thirdparty/movie',
10
14
  CHANNEL_CODE: 'homepage',
11
15
  ENDPOINTS: {
@@ -3,6 +3,7 @@
3
3
  */
4
4
  import { formatTime, toNumber, toYyyymmdd } from '../../utils/format.js';
5
5
  import { createTimeoutController } from '../../utils/http.js';
6
+ import { hasDtryxRelayOptions, requestDtryxRelay, } from './transport.js';
6
7
  import { DTRYX_API } from './api.js';
7
8
  const DEFAULT_TIMEOUT_MS = 15000;
8
9
  /**
@@ -65,14 +66,20 @@ function buildScheduleId(cinemaCode, playDate, screenCode, showSeq) {
65
66
  return `${playDate}-${cinemaCode}-${screenCode}-${showSeq}`;
66
67
  }
67
68
  /** 상영 회차와 좌석 현황을 조회합니다. */
68
- export async function fetchDtryxTimetable(params) {
69
+ export async function fetchDtryxTimetable(params, options = {}) {
69
70
  const playDate = params.playDate || toYyyymmdd();
70
- const response = await requestDtryx(DTRYX_API.ENDPOINTS.TIMETABLE_LIST, DTRYX_API.WORK_GUIDS.TIMETABLE_LIST, {
71
- BrandCd: params.brandCode,
72
- CinemaCd: params.cinemaCode,
73
- PlaySDT: toDashedDate(playDate),
74
- ImgSize: 'small',
75
- }, params.timeout);
71
+ const response = hasDtryxRelayOptions(options)
72
+ ? await requestDtryxRelay('timetable', {
73
+ brandCode: params.brandCode,
74
+ cinemaCode: params.cinemaCode,
75
+ playDate: toCompactDate(playDate),
76
+ }, options, params.timeout ?? DEFAULT_TIMEOUT_MS)
77
+ : await requestDtryx(DTRYX_API.ENDPOINTS.TIMETABLE_LIST, DTRYX_API.WORK_GUIDS.TIMETABLE_LIST, {
78
+ BrandCd: params.brandCode,
79
+ CinemaCd: params.cinemaCode,
80
+ PlaySDT: toDashedDate(playDate),
81
+ ImgSize: 'small',
82
+ }, params.timeout);
76
83
  return response.Recordset.filter((item) => item.CinemaCd && item.MovieCd && item.ScreenCd).map((item) => {
77
84
  const totalSeats = toNumber(item.TotalSeatCnt);
78
85
  const remainingSeats = toNumber(item.RemainSeatCnt);
@@ -102,12 +109,14 @@ export async function fetchDtryxTimetable(params) {
102
109
  });
103
110
  }
104
111
  /** 예매 가능한 상영 날짜를 조회합니다. */
105
- export async function fetchDtryxPlayDates(params) {
106
- const response = await requestDtryx(DTRYX_API.ENDPOINTS.PLAY_DATE_LIST, DTRYX_API.WORK_GUIDS.PLAY_DATE_LIST, {
107
- BrandCd: params.brandCode,
108
- CinemaCd: params.cinemaCode,
109
- MovieCd: '',
110
- }, params.timeout);
112
+ export async function fetchDtryxPlayDates(params, options = {}) {
113
+ const response = hasDtryxRelayOptions(options)
114
+ ? await requestDtryxRelay('play-dates', { brandCode: params.brandCode, cinemaCode: params.cinemaCode }, options, params.timeout ?? DEFAULT_TIMEOUT_MS)
115
+ : await requestDtryx(DTRYX_API.ENDPOINTS.PLAY_DATE_LIST, DTRYX_API.WORK_GUIDS.PLAY_DATE_LIST, {
116
+ BrandCd: params.brandCode,
117
+ CinemaCd: params.cinemaCode,
118
+ MovieCd: '',
119
+ }, params.timeout);
111
120
  return response.Recordset.filter((item) => item.PlaySDT).map((item) => ({
112
121
  playDate: toCompactDate(item.PlaySDT),
113
122
  hidden: item.HiddenYn === 'Y',
@@ -115,12 +124,14 @@ export async function fetchDtryxPlayDates(params) {
115
124
  }));
116
125
  }
117
126
  /** 현재 상영작 목록을 조회합니다. */
118
- export async function fetchDtryxNowShowing(params) {
119
- const response = await requestDtryx(DTRYX_API.ENDPOINTS.MOVIE_NOW, DTRYX_API.WORK_GUIDS.MOVIE_NOW, {
120
- BrandCd: params.brandCode,
121
- CinemaCd: params.cinemaCode,
122
- ImgSize: 'small',
123
- }, params.timeout);
127
+ export async function fetchDtryxNowShowing(params, options = {}) {
128
+ const response = hasDtryxRelayOptions(options)
129
+ ? await requestDtryxRelay('movies', { brandCode: params.brandCode, cinemaCode: params.cinemaCode }, options, params.timeout ?? DEFAULT_TIMEOUT_MS)
130
+ : await requestDtryx(DTRYX_API.ENDPOINTS.MOVIE_NOW, DTRYX_API.WORK_GUIDS.MOVIE_NOW, {
131
+ BrandCd: params.brandCode,
132
+ CinemaCd: params.cinemaCode,
133
+ ImgSize: 'small',
134
+ }, params.timeout);
124
135
  return response.Recordset.filter((item) => item.MovieCd && item.MovieNm).map((item) => ({
125
136
  movieCode: String(item.MovieCd),
126
137
  movieName: item.MovieNm,
@@ -13,12 +13,20 @@ const DTRYX_METADATA = {
13
13
  description: '디트릭스 예매 플랫폼 기반 독립·예술영화관 목록, 상영작, 상영시간표·잔여 좌석 조회 서비스',
14
14
  };
15
15
  class DtryxService {
16
+ options;
16
17
  metadata = DTRYX_METADATA;
18
+ constructor(options) {
19
+ this.options = options;
20
+ }
17
21
  getTools() {
18
- return [createListCinemasTool(), createListNowShowingTool(), createGetRemainingSeatsTool()];
22
+ return [
23
+ createListCinemasTool(),
24
+ createListNowShowingTool(this.options),
25
+ createGetRemainingSeatsTool(this.options),
26
+ ];
19
27
  }
20
28
  }
21
- export function createDtryxService() {
22
- return new DtryxService();
29
+ export function createDtryxService(options = {}) {
30
+ return new DtryxService(options);
23
31
  }
24
32
  export * from './types.js';
@@ -12,7 +12,7 @@ function matchesMovie(showtime, movieName) {
12
12
  const normalize = (value) => value.replace(/\s+/g, '').toLowerCase();
13
13
  return normalize(showtime.movieName).includes(normalize(movieName));
14
14
  }
15
- async function getRemainingSeats(args) {
15
+ async function getRemainingSeats(args, options) {
16
16
  if (hasInvalidDtryxOptions(args)) {
17
17
  return { isError: true, content: [{ type: 'text', text: DTRYX_INVALID_INPUT }] };
18
18
  }
@@ -37,7 +37,7 @@ async function getRemainingSeats(args) {
37
37
  cinemaCode: cinema.cinemaCode,
38
38
  playDate,
39
39
  timeout: timeoutMs,
40
- })));
40
+ }, options)));
41
41
  const failedCinemas = cinemas
42
42
  .filter((_, index) => settled[index]?.status === 'rejected')
43
43
  .map((cinema) => cinema.cinemaName || cinema.cinemaCode);
@@ -84,7 +84,7 @@ async function getRemainingSeats(args) {
84
84
  ],
85
85
  };
86
86
  }
87
- export function createGetRemainingSeatsTool() {
87
+ export function createGetRemainingSeatsTool(options = {}) {
88
88
  return {
89
89
  name: 'dtryx_get_remaining_seats',
90
90
  metadata: {
@@ -112,6 +112,6 @@ export function createGetRemainingSeatsTool() {
112
112
  .describe('요청 제한 시간(ms, 기본값: 15000)'),
113
113
  },
114
114
  },
115
- handler: ((args) => getRemainingSeats(args)),
115
+ handler: ((args) => getRemainingSeats(args, options)),
116
116
  };
117
117
  }
@@ -5,7 +5,7 @@ import * as z from 'zod';
5
5
  import { DTRYX_INVALID_INPUT, hasInvalidDtryxOptions, dtryxTimeoutSchema } from '../validation.js';
6
6
  import { resolveDtryxCinemas } from '../location.js';
7
7
  import { fetchDtryxNowShowing, fetchDtryxPlayDates } from '../client.js';
8
- async function listNowShowing(args) {
8
+ async function listNowShowing(args, options) {
9
9
  if (hasInvalidDtryxOptions(args)) {
10
10
  return { isError: true, content: [{ type: 'text', text: DTRYX_INVALID_INPUT }] };
11
11
  }
@@ -31,8 +31,8 @@ async function listNowShowing(args) {
31
31
  timeout: timeoutMs,
32
32
  };
33
33
  const [movies, playDates] = await Promise.all([
34
- fetchDtryxNowShowing(request),
35
- includePlayDates ? fetchDtryxPlayDates(request) : Promise.resolve([]),
34
+ fetchDtryxNowShowing(request, options),
35
+ includePlayDates ? fetchDtryxPlayDates(request, options) : Promise.resolve([]),
36
36
  ]);
37
37
  return {
38
38
  content: [
@@ -48,7 +48,7 @@ async function listNowShowing(args) {
48
48
  ],
49
49
  };
50
50
  }
51
- export function createListNowShowingTool() {
51
+ export function createListNowShowingTool(options = {}) {
52
52
  return {
53
53
  name: 'dtryx_list_now_showing',
54
54
  metadata: {
@@ -72,6 +72,6 @@ export function createListNowShowingTool() {
72
72
  .describe('요청 제한 시간(ms, 기본값: 15000)'),
73
73
  },
74
74
  },
75
- handler: ((args) => listNowShowing(args)),
75
+ handler: ((args) => listNowShowing(args, options)),
76
76
  };
77
77
  }
@@ -0,0 +1,89 @@
1
+ /** 디트릭스 전용 중계 설정과 인증 전송입니다. */
2
+ import { ServiceError } from '../../core/errors.js';
3
+ import { createTimeoutController } from '../../utils/http.js';
4
+ export function isValidDtryxRelayUrl(value) {
5
+ if (!value?.trim())
6
+ return false;
7
+ try {
8
+ const url = new URL(value);
9
+ return (!url.username &&
10
+ !url.password &&
11
+ !url.search &&
12
+ !url.hash &&
13
+ (url.protocol === 'https:' ||
14
+ (url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))));
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ }
20
+ /** 바인딩은 요청마다 변환하며 프로세스 전역에 저장하지 않습니다. */
21
+ export function dtryxTransportFromBindings(bindings) {
22
+ return {
23
+ relayUrl: bindings?.DTRYX_RELAY_URL,
24
+ relayToken: bindings?.DTRYX_RELAY_TOKEN,
25
+ accessClientId: bindings?.DTRYX_ACCESS_CLIENT_ID,
26
+ accessClientSecret: bindings?.DTRYX_ACCESS_CLIENT_SECRET,
27
+ };
28
+ }
29
+ export function hasDtryxRelayOptions(options) {
30
+ return Object.values(options).some((value) => value !== undefined);
31
+ }
32
+ export async function requestDtryxRelay(path, body, options, timeout) {
33
+ const { relayUrl, relayToken, accessClientId, accessClientSecret } = options;
34
+ const accessPresent = accessClientId !== undefined || accessClientSecret !== undefined;
35
+ if (!isValidDtryxRelayUrl(relayUrl) ||
36
+ !relayToken?.trim() ||
37
+ (accessPresent && (!accessClientId?.trim() || !accessClientSecret?.trim()))) {
38
+ throw new ServiceError('DTRYX_RELAY_CONFIG_ERROR', '디트릭스 릴레이 URL, 토큰 및 Access 설정을 확인하세요.', 503, false);
39
+ }
40
+ const headers = {
41
+ 'Content-Type': 'application/json',
42
+ Accept: 'application/json',
43
+ Authorization: `Bearer ${relayToken}`,
44
+ };
45
+ if (accessPresent) {
46
+ headers['CF-Access-Client-Id'] = accessClientId;
47
+ headers['CF-Access-Client-Secret'] = accessClientSecret;
48
+ }
49
+ const { controller, timeoutId } = createTimeoutController(timeout);
50
+ try {
51
+ // 리다이렉트를 따라 인증 정보를 다른 호스트에 전달하지 않습니다.
52
+ const response = await fetch(`${relayUrl.replace(/\/$/, '')}/v1/dtryx/${path}`, {
53
+ method: 'POST',
54
+ headers,
55
+ body: JSON.stringify(body),
56
+ redirect: 'manual',
57
+ signal: controller.signal,
58
+ });
59
+ if (response.status !== 200) {
60
+ void response.body?.cancel().catch(() => { });
61
+ const status = response.status;
62
+ const mapped = status === 429 || status === 503 || status === 504 ? status : 502;
63
+ throw new ServiceError('DTRYX_RELAY_FAILED', '디트릭스 릴레이 요청에 실패했습니다.', mapped, status === 429 || status >= 500, status);
64
+ }
65
+ const result = await response.json();
66
+ if (typeof result !== 'object' ||
67
+ result === null ||
68
+ !('RetCode' in result) ||
69
+ result.RetCode !== 'success' ||
70
+ !('Recordset' in result) ||
71
+ !Array.isArray(result.Recordset) ||
72
+ !result.Recordset.every((item) => typeof item === 'object' && item !== null && !Array.isArray(item))) {
73
+ throw new Error('응답 형식 오류');
74
+ }
75
+ return result;
76
+ }
77
+ catch (error) {
78
+ if (error instanceof ServiceError)
79
+ throw error;
80
+ if (controller.signal.aborted) {
81
+ throw new ServiceError('DTRYX_RELAY_TIMEOUT', '디트릭스 릴레이 요청 시간이 초과되었습니다.', 504, true);
82
+ }
83
+ throw new ServiceError('DTRYX_RELAY_FAILED', '디트릭스 릴레이 요청에 실패했습니다.', 502, true);
84
+ }
85
+ finally {
86
+ clearTimeout(timeoutId);
87
+ controller.abort();
88
+ }
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "daiso",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Korean retail and cinema MCP server, CLI, and Codex Skill for Daiso, convenience stores, marts, Olive Young, and theaters",
5
5
  "main": "dist/index.js",
6
6
  "bin": {