-
Notifications
You must be signed in to change notification settings - Fork 0
/
automaticTransferRegistrationCreated.ts
44 lines (40 loc) · 1.1 KB
/
automaticTransferRegistrationCreated.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import * as z from 'zod'
import { extract } from './extract'
import { Parser } from './parser'
/**
* 自動振込サービスのご確認
*/
const automaticTransferRegistrationCreatedSchema = z.object({
type: z.literal('automaticTransferRegistrationCreated'),
/**
* 振込名称
*/
name: z.string(),
/**
* 振込指定日
*
* 例: "月末日"や"25日"など
*/
transferDate: z.string(),
})
export type AutomaticTransferRegistrationCreated = z.infer<
typeof automaticTransferRegistrationCreatedSchema
>
export const automaticTransferRegistrationCreatedParser: Parser<AutomaticTransferRegistrationCreated> = ({
subject,
text,
}) => {
if (subject !== '自動振込サービスのご確認') {
return
}
const name = extract(text, /振込名称:(?<name>.+)/)
.map(_ => _.name)
.pop()
const transferDate = extract(text, /振込指定日:(?<transferDate>.+)/)
.map(_ => _.transferDate)
.pop()
if (typeof name === 'string' && typeof transferDate === 'string') {
return { type: 'automaticTransferRegistrationCreated', name, transferDate }
}
return
}