@things-factory/integration-data-go-kr 10.1.234 → 10.1.241
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/dist-server/engine/connector/data-go-kr-client.d.ts +1 -1
- package/dist-server/engine/connector/data-go-kr-client.js +17 -0
- package/dist-server/engine/connector/data-go-kr-client.js.map +1 -1
- package/dist-server/engine/connector/data-go-kr-connector.js +1 -1
- package/dist-server/engine/connector/data-go-kr-connector.js.map +1 -1
- package/dist-server/engine/spec/index.d.ts +1 -0
- package/dist-server/engine/spec/index.js +3 -0
- package/dist-server/engine/spec/index.js.map +1 -1
- package/dist-server/engine/spec/special-day/index.d.ts +4 -0
- package/dist-server/engine/spec/special-day/index.js +9 -0
- package/dist-server/engine/spec/special-day/index.js.map +1 -0
- package/dist-server/engine/spec/special-day/special-day.d.ts +7 -0
- package/dist-server/engine/spec/special-day/special-day.js +28 -0
- package/dist-server/engine/spec/special-day/special-day.js.map +1 -0
- package/dist-server/engine/task/index.d.ts +1 -0
- package/dist-server/engine/task/index.js +1 -0
- package/dist-server/engine/task/index.js.map +1 -1
- package/dist-server/engine/task/special-day/index.d.ts +26 -0
- package/dist-server/engine/task/special-day/index.js +32 -0
- package/dist-server/engine/task/special-day/index.js.map +1 -0
- package/dist-server/engine/task/special-day/rest-days.d.ts +12 -0
- package/dist-server/engine/task/special-day/rest-days.js +26 -0
- package/dist-server/engine/task/special-day/rest-days.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/server/engine/connector/data-go-kr-client.ts +23 -1
- package/server/engine/connector/data-go-kr-connector.ts +1 -1
- package/server/engine/spec/index.ts +3 -0
- package/server/engine/spec/special-day/index.ts +4 -0
- package/server/engine/spec/special-day/special-day.ts +26 -0
- package/server/engine/task/index.ts +1 -0
- package/server/engine/task/special-day/index.ts +38 -0
- package/server/engine/task/special-day/rest-days.ts +19 -0
- package/test/data-go-kr-client.test.ts +43 -0
- package/test/rest-days.test.ts +20 -0
- package/translations/en.json +1 -1
- package/translations/es.json +1 -1
- package/translations/ja.json +1 -1
- package/translations/ko.json +1 -1
- package/translations/ms.json +1 -1
- package/translations/zh.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-data-go-kr",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.241",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"things-factory": true,
|
|
6
6
|
"author": "heartyoh <heartyoh@hatiolab.com>",
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
"build": "tsc --p tsconfig.json",
|
|
20
20
|
"build:server": "npm run clean:server && tsc",
|
|
21
21
|
"clean:server": "rm -rf dist-server",
|
|
22
|
-
"clean": "npm run clean:server"
|
|
22
|
+
"clean": "npm run clean:server",
|
|
23
|
+
"test": "node --test test/*.test.ts"
|
|
23
24
|
},
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@things-factory/integration-base": "^10.1.
|
|
26
|
+
"@things-factory/integration-base": "^10.1.241"
|
|
26
27
|
},
|
|
27
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "d7fe2e1a1eb7c02cb21b897da26d385df014f908"
|
|
28
29
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataGoKrResponse } from '../types'
|
|
1
|
+
import type { DataGoKrResponse } from '../types'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 공공데이터포털(data.go.kr) 공용 HTTP 클라이언트.
|
|
@@ -32,6 +32,17 @@ export class DataGoKrClient {
|
|
|
32
32
|
/* Encoding 키(%2B 포함)를 붙여넣어도 Decoding 키처럼 동작하도록 정규화.
|
|
33
33
|
base64 키는 `%` 를 포함하지 않으므로 raw Decoding 키는 영향 없음. */
|
|
34
34
|
this.serviceKey = normalizeServiceKey(options.serviceKey.trim())
|
|
35
|
+
/*
|
|
36
|
+
* A service key is letters, digits and + / = (the Decoding key; the Encoding key decodes to it). Anything else - a
|
|
37
|
+
* JSON answer or a page pasted whole - is said at connect, not later as 「등록되지 않은 서비스키」 (the user,
|
|
38
|
+
* 2026-10-31). The value itself is never said.
|
|
39
|
+
*/
|
|
40
|
+
if (!/^[A-Za-z0-9+/=]+$/.test(this.serviceKey)) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`the data.go.kr service key is not a key (${this.serviceKey.length} characters, with characters a key does not have) - ` +
|
|
43
|
+
`paste only the general authentication key (Decoding or Encoding) from data.go.kr My Page`
|
|
44
|
+
)
|
|
45
|
+
}
|
|
35
46
|
this.origin = resolveOrigin(options.origin)
|
|
36
47
|
}
|
|
37
48
|
|
|
@@ -65,6 +76,17 @@ export class DataGoKrClient {
|
|
|
65
76
|
.map(([k, v]) => `${k}=${v}`)
|
|
66
77
|
.join(' ')
|
|
67
78
|
|
|
79
|
+
/*
|
|
80
|
+
* A web page is not an Open API answer: the endpoint names a site (https://data.go.kr is the portal), not the API
|
|
81
|
+
* origin. Said as that, not as the page's HTML (the user, 2026-10-31).
|
|
82
|
+
*/
|
|
83
|
+
if (/^\s*<(!doctype html|html)/i.test(raw)) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`data.go.kr ${servicePath}: ${this.origin} answered a web page (${response.status}), not the Open API - ` +
|
|
86
|
+
`leave the connection's endpoint empty or set it to ${DEFAULT_ORIGIN}`
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
68
90
|
if (!response.ok) {
|
|
69
91
|
throw new Error(
|
|
70
92
|
`data.go.kr ${servicePath} failed (${response.status}): ${raw.slice(0, 300)} — params: ${nonSensitiveParams}`
|
|
@@ -5,12 +5,14 @@ import * as buildingLedger from './building-ledger'
|
|
|
5
5
|
import * as buildingPermit from './building-permit'
|
|
6
6
|
import * as housingPermit from './housing-permit'
|
|
7
7
|
import * as weather from './weather'
|
|
8
|
+
import * as specialDay from './special-day'
|
|
8
9
|
|
|
9
10
|
export * from './types'
|
|
10
11
|
export * from './building-ledger'
|
|
11
12
|
export * from './building-permit'
|
|
12
13
|
export * from './housing-permit'
|
|
13
14
|
export * from './weather'
|
|
15
|
+
export * from './special-day'
|
|
14
16
|
|
|
15
17
|
const services = new Map<string, ServiceSpec>()
|
|
16
18
|
|
|
@@ -38,6 +40,7 @@ registerDomain(buildingLedger)
|
|
|
38
40
|
registerDomain(buildingPermit)
|
|
39
41
|
registerDomain(housingPermit)
|
|
40
42
|
registerDomain(weather)
|
|
43
|
+
registerDomain(specialDay)
|
|
41
44
|
|
|
42
45
|
export const SpecRegistry = {
|
|
43
46
|
/** 등록된 모든 서비스 스펙을 반환. */
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ServiceSpec } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 한국천문연구원_특일 정보 (data.go.kr 데이터셋 15012690).
|
|
5
|
+
*
|
|
6
|
+
* 공휴일(`getRestDeInfo`)은 대체공휴일 · 임시공휴일을 포함한다. 근무일 캘린더가 이것으로 국가 공휴일을 채운다(ADR-0179).
|
|
7
|
+
*/
|
|
8
|
+
export const KasiSpecialDayService: ServiceSpec = {
|
|
9
|
+
serviceId: 'B090041/openapi/service/SpcdeInfoService',
|
|
10
|
+
label: '한국천문연구원_특일 정보',
|
|
11
|
+
description: '공휴일 · 국경일 · 기념일 · 24절기 · 잡절. 연도(와 월) 기준.',
|
|
12
|
+
homepage: 'https://www.data.go.kr/data/15012690/openapi.do',
|
|
13
|
+
operations: {
|
|
14
|
+
getRestDeInfo: {
|
|
15
|
+
operationId: 'getRestDeInfo',
|
|
16
|
+
label: '공휴일 정보 조회',
|
|
17
|
+
description: '그 해(와 월)의 공휴일. 대체공휴일 · 임시공휴일 포함.',
|
|
18
|
+
params: [
|
|
19
|
+
{ name: 'solYear', label: 'label.year', required: true, length: 4, description: '연도 YYYY', example: '2026' },
|
|
20
|
+
{ name: 'solMonth', label: 'label.month', pad: 2, description: '월 MM. 비우면 그 해 전체', example: '10' }
|
|
21
|
+
],
|
|
22
|
+
responseNotes: 'items.item: { dateKind, dateName, isHoliday: "Y"|"N", locdate: YYYYMMDD(number), seq }. numOfRows 를 50 이상으로 잡는다.',
|
|
23
|
+
externalDocsUrl: 'https://www.data.go.kr/data/15012690/openapi.do'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ConnectionManager, Context, TaskRegistry, evaluateTemplate } from '@things-factory/integration-base'
|
|
2
|
+
|
|
3
|
+
import { DataGoKrConnectionInstance } from '../../connector/data-go-kr-connector'
|
|
4
|
+
import { KasiSpecialDayService } from '../../spec/special-day/special-day'
|
|
5
|
+
import { restDaysOf } from './rest-days'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 한 해의 국가 공휴일 (`getRestDeInfo`) — 근무일 캘린더가 받는 모양 `{ year, days: [{ day, name }] }` 으로 준다(ADR-0179).
|
|
9
|
+
*
|
|
10
|
+
* 입력: `year` (비우면 올해). 시나리오는 다음 단계에서 `local-graphql-mutate` 로 calendar 의
|
|
11
|
+
* `savePublicHolidays(year, days)` 를 부른다.
|
|
12
|
+
*/
|
|
13
|
+
async function RestDaysTask(step, context: Context): Promise<{ data: { year: number; days: { day: string; name: string }[] } }> {
|
|
14
|
+
const { connection: connectionName, params } = step
|
|
15
|
+
const { domain, user, data, variables, lng, logger } = context
|
|
16
|
+
|
|
17
|
+
const instance: DataGoKrConnectionInstance = await ConnectionManager.getConnectionInstanceByName(domain, connectionName)
|
|
18
|
+
if (!instance?.client) throw new Error(`data-go-kr connection '${connectionName}' is not established.`)
|
|
19
|
+
|
|
20
|
+
const scope = { domain, user, lng, data, variables, console }
|
|
21
|
+
const given = params?.year === undefined || params?.year === null || params?.year === '' ? '' : String(evaluateTemplate(String(params.year), scope)).trim()
|
|
22
|
+
const year = given ? Number(given) : new Date().getFullYear()
|
|
23
|
+
if (!Number.isInteger(year) || year < 1900 || year > 2999) throw new Error(`data-go-kr-rest-days: '${given}' is not a year`)
|
|
24
|
+
|
|
25
|
+
const servicePath = `${KasiSpecialDayService.serviceId}/getRestDeInfo`
|
|
26
|
+
logger?.info?.(`[data-go-kr] ${servicePath} solYear=${year}`)
|
|
27
|
+
const items = await instance.client.getItems<any>(servicePath, { solYear: year, numOfRows: 100, pageNo: 1 })
|
|
28
|
+
|
|
29
|
+
return { data: { year, days: restDaysOf(items, year) } }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
RestDaysTask.parameterSpec = [{ type: 'string', name: 'year', label: 'label.year', placeholder: '예) 2026 — 비우면 올해' }]
|
|
33
|
+
|
|
34
|
+
RestDaysTask.help = 'integration/task/data-go-kr-rest-days'
|
|
35
|
+
|
|
36
|
+
TaskRegistry.registerTaskHandler('data-go-kr-rest-days', RestDaysTask)
|
|
37
|
+
|
|
38
|
+
export default RestDaysTask
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The holidays of a `getRestDeInfo` answer, as a calendar takes them (calendar `savePublicHolidays`, ADR-0179):
|
|
3
|
+
* the days marked as holidays, each once a name, in day order. Pure: the test loads it bare.
|
|
4
|
+
*/
|
|
5
|
+
export function restDaysOf(items: readonly { locdate?: number | string; dateName?: string; isHoliday?: string }[], year: number): { day: string; name: string }[] {
|
|
6
|
+
const seen = new Set<string>()
|
|
7
|
+
const days: { day: string; name: string }[] = []
|
|
8
|
+
for (const item of items) {
|
|
9
|
+
if (item.isHoliday !== 'Y') continue
|
|
10
|
+
const text = String(item.locdate ?? '')
|
|
11
|
+
if (!/^\d{8}$/.test(text) || !text.startsWith(String(year))) continue
|
|
12
|
+
const day = `${text.slice(0, 4)}-${text.slice(4, 6)}-${text.slice(6, 8)}`
|
|
13
|
+
const name = String(item.dateName ?? '').trim()
|
|
14
|
+
if (!name || seen.has(`${day} ${name}`)) continue
|
|
15
|
+
seen.add(`${day} ${name}`)
|
|
16
|
+
days.push({ day, name })
|
|
17
|
+
}
|
|
18
|
+
return days.sort((a, b) => a.day.localeCompare(b.day))
|
|
19
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { DataGoKrClient } from '../server/engine/connector/data-go-kr-client.ts'
|
|
5
|
+
|
|
6
|
+
const PATH = 'B090041/openapi/service/SpcdeInfoService/getRestDeInfo'
|
|
7
|
+
|
|
8
|
+
function answering(status: number, body: string) {
|
|
9
|
+
const asked: string[] = []
|
|
10
|
+
globalThis.fetch = (async (url: string) => {
|
|
11
|
+
asked.push(url)
|
|
12
|
+
return new Response(body, { status })
|
|
13
|
+
}) as any
|
|
14
|
+
return asked
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('an endpoint that names a web site is said as that, not as the page it sent back', async () => {
|
|
18
|
+
answering(404, '\n\n <!doctype html>\n<html lang="ko"><head><meta charset="UTF-8"></head></html>')
|
|
19
|
+
const client = new DataGoKrClient({ serviceKey: 'k', origin: 'https://data.go.kr' })
|
|
20
|
+
|
|
21
|
+
await assert.rejects(client.get(PATH, { solYear: 2026 }), (error: Error) => {
|
|
22
|
+
assert.match(error.message, /https:\/\/data\.go\.kr answered a web page \(404\), not the Open API/)
|
|
23
|
+
assert.match(error.message, /leave the connection's endpoint empty or set it to https:\/\/apis\.data\.go\.kr/)
|
|
24
|
+
assert.doesNotMatch(error.message, /<html/)
|
|
25
|
+
return true
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('an empty endpoint asks the Open API origin', async () => {
|
|
30
|
+
const asked = answering(200, JSON.stringify({ response: { header: { resultCode: '00', resultMsg: 'OK' }, body: { items: '' } } }))
|
|
31
|
+
await new DataGoKrClient({ serviceKey: 'k' }).get(PATH, { solYear: 2026 })
|
|
32
|
+
|
|
33
|
+
assert.equal(new URL(asked[0]).origin, 'https://apis.data.go.kr')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
test('a pasted text that is not a service key is refused at connect, without saying the value', () => {
|
|
37
|
+
assert.throws(
|
|
38
|
+
() => new DataGoKrClient({ serviceKey: '[ { "serviceKey": "abc" } ]' }),
|
|
39
|
+
(error: Error) => /is not a key/.test(error.message) && !error.message.includes('abc')
|
|
40
|
+
)
|
|
41
|
+
assert.doesNotThrow(() => new DataGoKrClient({ serviceKey: 'Ab+9/xyz==' }))
|
|
42
|
+
assert.doesNotThrow(() => new DataGoKrClient({ serviceKey: 'Ab%2B9%2Fxyz%3D%3D' }))
|
|
43
|
+
})
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
|
|
4
|
+
import { restDaysOf } from '../server/engine/task/special-day/rest-days.ts'
|
|
5
|
+
|
|
6
|
+
test('the holidays of a getRestDeInfo answer: holidays only, each once, in day order, of the year asked', () => {
|
|
7
|
+
const items = [
|
|
8
|
+
{ dateKind: '01', dateName: '한글날', isHoliday: 'Y', locdate: 20261009, seq: 1 },
|
|
9
|
+
{ dateKind: '01', dateName: '개천절', isHoliday: 'Y', locdate: 20261003, seq: 1 },
|
|
10
|
+
{ dateKind: '01', dateName: '대체공휴일', isHoliday: 'Y', locdate: '20261005', seq: 1 },
|
|
11
|
+
{ dateKind: '01', dateName: '국군의 날', isHoliday: 'N', locdate: 20261001, seq: 1 },
|
|
12
|
+
{ dateKind: '01', dateName: '개천절', isHoliday: 'Y', locdate: 20261003, seq: 2 },
|
|
13
|
+
{ dateKind: '01', dateName: '신정', isHoliday: 'Y', locdate: 20270101, seq: 1 }
|
|
14
|
+
]
|
|
15
|
+
assert.deepEqual(restDaysOf(items, 2026), [
|
|
16
|
+
{ day: '2026-10-03', name: '개천절' },
|
|
17
|
+
{ day: '2026-10-05', name: '대체공휴일' },
|
|
18
|
+
{ day: '2026-10-09', name: '한글날' }
|
|
19
|
+
])
|
|
20
|
+
})
|
package/translations/en.json
CHANGED
package/translations/es.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"label.service-key": "Clave de servicio
|
|
2
|
+
"label.service-key": "Clave de servicio del portal de datos públicos",
|
|
3
3
|
"label.operation-ref": "Referencia de operación",
|
|
4
4
|
"label.operation-params": "Parámetros de operación",
|
|
5
5
|
"label.sigungu-cd": "Código de Sigungu",
|
package/translations/ja.json
CHANGED
package/translations/ko.json
CHANGED
package/translations/ms.json
CHANGED
package/translations/zh.json
CHANGED