@automate.ax/integration-contracts 0.125.0 → 0.126.0
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/reddit/api.d.ts +56 -0
- package/dist/reddit/api.js +135 -0
- package/dist/reddit/events.d.ts +439 -0
- package/dist/reddit/events.js +53 -0
- package/dist/reddit/index.d.ts +3 -0
- package/dist/reddit/index.js +3 -0
- package/dist/reddit/schemas.d.ts +816 -0
- package/dist/reddit/schemas.js +398 -0
- package/dist/triggers.d.ts +2 -1
- package/package.json +8 -2
- package/src/reddit/api.ts +183 -0
- package/src/reddit/events.ts +68 -0
- package/src/reddit/index.ts +3 -0
- package/src/reddit/schemas.ts +442 -0
- package/src/triggers.ts +2 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
import {
|
|
3
|
+
REDDIT_COMMENT_SCHEMA,
|
|
4
|
+
REDDIT_MESSAGE_SCHEMA,
|
|
5
|
+
REDDIT_POST_SCHEMA,
|
|
6
|
+
REDDIT_SUBREDDIT_NAME_SCHEMA,
|
|
7
|
+
} from "./schemas"
|
|
8
|
+
|
|
9
|
+
export const REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA = z.object({
|
|
10
|
+
subreddit: REDDIT_SUBREDDIT_NAME_SCHEMA,
|
|
11
|
+
})
|
|
12
|
+
export const REDDIT_ACCOUNT_TRIGGER_CONFIG_SCHEMA = z.object({})
|
|
13
|
+
|
|
14
|
+
export const REDDIT_SUBREDDIT_EVENT_SCHEMA = z.discriminatedUnion("action", [
|
|
15
|
+
z.object({
|
|
16
|
+
action: z.literal("commentCreated"),
|
|
17
|
+
comment: REDDIT_COMMENT_SCHEMA,
|
|
18
|
+
}),
|
|
19
|
+
z.object({ action: z.literal("postCreated"), post: REDDIT_POST_SCHEMA }),
|
|
20
|
+
])
|
|
21
|
+
export const REDDIT_INBOX_EVENT_SCHEMA = z.object({
|
|
22
|
+
action: z.literal("inboxItemCreated"),
|
|
23
|
+
message: REDDIT_MESSAGE_SCHEMA,
|
|
24
|
+
})
|
|
25
|
+
export const REDDIT_MOD_QUEUE_EVENT_SCHEMA = z.discriminatedUnion("kind", [
|
|
26
|
+
z.object({ comment: REDDIT_COMMENT_SCHEMA, kind: z.literal("comment") }),
|
|
27
|
+
z.object({ kind: z.literal("post"), post: REDDIT_POST_SCHEMA }),
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
export const redditTriggerContracts = {
|
|
31
|
+
"reddit.inbox.item.received": {
|
|
32
|
+
configSchema: REDDIT_ACCOUNT_TRIGGER_CONFIG_SCHEMA,
|
|
33
|
+
eventSchema: REDDIT_INBOX_EVENT_SCHEMA,
|
|
34
|
+
},
|
|
35
|
+
"reddit.modQueue.item.received": {
|
|
36
|
+
configSchema: REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA,
|
|
37
|
+
eventSchema: REDDIT_MOD_QUEUE_EVENT_SCHEMA,
|
|
38
|
+
},
|
|
39
|
+
"reddit.subreddit.comment.created": {
|
|
40
|
+
configSchema: REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA,
|
|
41
|
+
eventSchema: REDDIT_SUBREDDIT_EVENT_SCHEMA.and(
|
|
42
|
+
z.object({ action: z.literal("commentCreated") }),
|
|
43
|
+
),
|
|
44
|
+
},
|
|
45
|
+
"reddit.subreddit.event": {
|
|
46
|
+
configSchema: REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA,
|
|
47
|
+
eventSchema: REDDIT_SUBREDDIT_EVENT_SCHEMA,
|
|
48
|
+
},
|
|
49
|
+
"reddit.subreddit.post.created": {
|
|
50
|
+
configSchema: REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA,
|
|
51
|
+
eventSchema: REDDIT_SUBREDDIT_EVENT_SCHEMA.and(
|
|
52
|
+
z.object({ action: z.literal("postCreated") }),
|
|
53
|
+
),
|
|
54
|
+
},
|
|
55
|
+
} as const
|
|
56
|
+
|
|
57
|
+
/** Returns broad and semantic event types for one subreddit observation. */
|
|
58
|
+
/** @param event - Normalized post or comment event. */
|
|
59
|
+
export function getRedditSubredditEventTypes(
|
|
60
|
+
event: z.output<typeof REDDIT_SUBREDDIT_EVENT_SCHEMA>,
|
|
61
|
+
) {
|
|
62
|
+
return [
|
|
63
|
+
event.action === "postCreated"
|
|
64
|
+
? ("reddit.subreddit.post.created" as const)
|
|
65
|
+
: ("reddit.subreddit.comment.created" as const),
|
|
66
|
+
"reddit.subreddit.event" as const,
|
|
67
|
+
]
|
|
68
|
+
}
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import * as z from "zod"
|
|
2
|
+
|
|
3
|
+
const REDDIT_ORIGIN = "https://www.reddit.com"
|
|
4
|
+
const REDDIT_EDITED_SCHEMA = z.union([z.literal(false), z.number()])
|
|
5
|
+
|
|
6
|
+
export const REDDIT_THING_ID_SCHEMA = z
|
|
7
|
+
.string()
|
|
8
|
+
.regex(/^t[1345]_[a-z0-9]+$/i, "Expected a Reddit thing fullname.")
|
|
9
|
+
export const REDDIT_POST_ID_SCHEMA = z
|
|
10
|
+
.string()
|
|
11
|
+
.regex(/^t3_[a-z0-9]+$/i, "Expected a Reddit post fullname.")
|
|
12
|
+
export const REDDIT_CONTENT_ID_SCHEMA = z
|
|
13
|
+
.string()
|
|
14
|
+
.regex(/^t[13]_[a-z0-9]+$/i, "Expected a Reddit post or comment fullname.")
|
|
15
|
+
export const REDDIT_INBOX_ID_SCHEMA = z
|
|
16
|
+
.string()
|
|
17
|
+
.regex(/^t[14]_[a-z0-9]+$/i, "Expected a Reddit inbox item fullname.")
|
|
18
|
+
export const REDDIT_SUBREDDIT_NAME_SCHEMA = z
|
|
19
|
+
.string()
|
|
20
|
+
.trim()
|
|
21
|
+
.regex(/^[A-Za-z0-9_]{2,21}$/, "Expected a Reddit subreddit name.")
|
|
22
|
+
export const REDDIT_USERNAME_SCHEMA = z
|
|
23
|
+
.string()
|
|
24
|
+
.trim()
|
|
25
|
+
.regex(/^[A-Za-z0-9_-]{3,20}$/, "Expected a Reddit username.")
|
|
26
|
+
|
|
27
|
+
export const REDDIT_FLAIR_SCHEMA = z.object({
|
|
28
|
+
backgroundColor: z.string().nullable(),
|
|
29
|
+
cssClass: z.string().nullable(),
|
|
30
|
+
templateId: z.string().nullable(),
|
|
31
|
+
text: z.string().nullable(),
|
|
32
|
+
textColor: z.enum(["dark", "light"]).nullable(),
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export const REDDIT_POST_SCHEMA = z.object({
|
|
36
|
+
archived: z.boolean(),
|
|
37
|
+
author: z.string().nullable(),
|
|
38
|
+
body: z.string(),
|
|
39
|
+
commentCount: z.number().int().nonnegative(),
|
|
40
|
+
createdAt: z.date(),
|
|
41
|
+
editedAt: z.date().nullable(),
|
|
42
|
+
flair: REDDIT_FLAIR_SCHEMA,
|
|
43
|
+
hidden: z.boolean(),
|
|
44
|
+
id: REDDIT_POST_ID_SCHEMA,
|
|
45
|
+
isLocked: z.boolean(),
|
|
46
|
+
isNsfw: z.boolean(),
|
|
47
|
+
isSelfPost: z.boolean(),
|
|
48
|
+
isSpoiler: z.boolean(),
|
|
49
|
+
isStickied: z.boolean(),
|
|
50
|
+
permalink: z.url(),
|
|
51
|
+
saved: z.boolean(),
|
|
52
|
+
score: z.number().int(),
|
|
53
|
+
shortId: z.string().min(1),
|
|
54
|
+
subreddit: z.string(),
|
|
55
|
+
subredditId: z.string(),
|
|
56
|
+
title: z.string(),
|
|
57
|
+
upvoteRatio: z.number().min(0).max(1),
|
|
58
|
+
url: z.url(),
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
export const REDDIT_COMMENT_SCHEMA = z.object({
|
|
62
|
+
author: z.string().nullable(),
|
|
63
|
+
body: z.string(),
|
|
64
|
+
createdAt: z.date(),
|
|
65
|
+
depth: z.number().int().nonnegative(),
|
|
66
|
+
distinguished: z.enum(["admin", "moderator", "special"]).nullable(),
|
|
67
|
+
editedAt: z.date().nullable(),
|
|
68
|
+
id: z.string().regex(/^t1_[a-z0-9]+$/i),
|
|
69
|
+
isPostAuthor: z.boolean(),
|
|
70
|
+
isStickied: z.boolean(),
|
|
71
|
+
parentId: REDDIT_THING_ID_SCHEMA,
|
|
72
|
+
permalink: z.url(),
|
|
73
|
+
postId: REDDIT_POST_ID_SCHEMA,
|
|
74
|
+
saved: z.boolean(),
|
|
75
|
+
score: z.number().int(),
|
|
76
|
+
shortId: z.string().min(1),
|
|
77
|
+
subreddit: z.string(),
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
export const REDDIT_MESSAGE_SCHEMA = z.object({
|
|
81
|
+
author: z.string().nullable(),
|
|
82
|
+
body: z.string(),
|
|
83
|
+
context: z.string(),
|
|
84
|
+
createdAt: z.date(),
|
|
85
|
+
destination: z.string(),
|
|
86
|
+
id: REDDIT_INBOX_ID_SCHEMA,
|
|
87
|
+
isNew: z.boolean(),
|
|
88
|
+
parentId: z.string().nullable(),
|
|
89
|
+
permalink: z.url().nullable(),
|
|
90
|
+
shortId: z.string().min(1),
|
|
91
|
+
subject: z.string(),
|
|
92
|
+
subreddit: z.string().nullable(),
|
|
93
|
+
wasComment: z.boolean(),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
export const REDDIT_SUBREDDIT_SCHEMA = z.object({
|
|
97
|
+
activeUserCount: z.number().int().nonnegative().nullable(),
|
|
98
|
+
createdAt: z.date(),
|
|
99
|
+
description: z.string(),
|
|
100
|
+
displayName: z.string(),
|
|
101
|
+
id: z.string().regex(/^t5_[a-z0-9]+$/i),
|
|
102
|
+
isNsfw: z.boolean(),
|
|
103
|
+
name: z.string(),
|
|
104
|
+
publicDescription: z.string(),
|
|
105
|
+
subscribers: z.number().int().nonnegative(),
|
|
106
|
+
title: z.string(),
|
|
107
|
+
url: z.url(),
|
|
108
|
+
userIsSubscriber: z.boolean(),
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
export const REDDIT_PROFILE_SCHEMA = z.object({
|
|
112
|
+
commentKarma: z.number().int(),
|
|
113
|
+
createdAt: z.date(),
|
|
114
|
+
hasVerifiedEmail: z.boolean().nullable(),
|
|
115
|
+
id: z.string().min(1),
|
|
116
|
+
isEmployee: z.boolean(),
|
|
117
|
+
isModerator: z.boolean(),
|
|
118
|
+
linkKarma: z.number().int(),
|
|
119
|
+
username: z.string(),
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
export const REDDIT_PAGE_INFO_SCHEMA = z.object({
|
|
123
|
+
after: z.string().nullable(),
|
|
124
|
+
before: z.string().nullable(),
|
|
125
|
+
})
|
|
126
|
+
export const REDDIT_POST_PAGE_SCHEMA = z.object({
|
|
127
|
+
pageInfo: REDDIT_PAGE_INFO_SCHEMA,
|
|
128
|
+
posts: REDDIT_POST_SCHEMA.array(),
|
|
129
|
+
})
|
|
130
|
+
export const REDDIT_CONTENT_PAGE_SCHEMA = z.object({
|
|
131
|
+
content: z.union([REDDIT_POST_SCHEMA, REDDIT_COMMENT_SCHEMA]).array(),
|
|
132
|
+
pageInfo: REDDIT_PAGE_INFO_SCHEMA,
|
|
133
|
+
})
|
|
134
|
+
export const REDDIT_MESSAGE_PAGE_SCHEMA = z.object({
|
|
135
|
+
messages: REDDIT_MESSAGE_SCHEMA.array(),
|
|
136
|
+
pageInfo: REDDIT_PAGE_INFO_SCHEMA,
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
export const REDDIT_POST_FLAIR_TEMPLATE_SCHEMA = z.object({
|
|
140
|
+
backgroundColor: z.string(),
|
|
141
|
+
cssClass: z.string(),
|
|
142
|
+
id: z.string(),
|
|
143
|
+
isEditable: z.boolean(),
|
|
144
|
+
text: z.string(),
|
|
145
|
+
textColor: z.enum(["dark", "light"]),
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
export const REDDIT_PROVIDER_PROFILE_SCHEMA = z.looseObject({
|
|
149
|
+
comment_karma: z.number().int(),
|
|
150
|
+
created_utc: z.number(),
|
|
151
|
+
has_verified_email: z.boolean().nullable(),
|
|
152
|
+
id: z.string().min(1),
|
|
153
|
+
is_employee: z.boolean(),
|
|
154
|
+
is_mod: z.boolean(),
|
|
155
|
+
link_karma: z.number().int(),
|
|
156
|
+
name: z.string(),
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
export const REDDIT_PROVIDER_POST_SCHEMA = z.looseObject({
|
|
160
|
+
archived: z.boolean().default(false),
|
|
161
|
+
author: z.string().nullable().catch(null),
|
|
162
|
+
created_utc: z.number(),
|
|
163
|
+
edited: REDDIT_EDITED_SCHEMA.catch(false),
|
|
164
|
+
hidden: z.boolean().default(false),
|
|
165
|
+
id: z.string().min(1),
|
|
166
|
+
is_self: z.boolean().default(false),
|
|
167
|
+
link_flair_background_color: z.string().nullable().catch(null),
|
|
168
|
+
link_flair_css_class: z.string().nullable().catch(null),
|
|
169
|
+
link_flair_template_id: z.string().nullable().catch(null),
|
|
170
|
+
link_flair_text: z.string().nullable().catch(null),
|
|
171
|
+
link_flair_text_color: z.enum(["dark", "light"]).nullable().catch(null),
|
|
172
|
+
locked: z.boolean().default(false),
|
|
173
|
+
name: REDDIT_POST_ID_SCHEMA,
|
|
174
|
+
num_comments: z.number().int().nonnegative().default(0),
|
|
175
|
+
over_18: z.boolean().default(false),
|
|
176
|
+
permalink: z.string(),
|
|
177
|
+
saved: z.boolean().default(false),
|
|
178
|
+
score: z.number().int().default(0),
|
|
179
|
+
selftext: z.string().default(""),
|
|
180
|
+
spoiler: z.boolean().default(false),
|
|
181
|
+
stickied: z.boolean().default(false),
|
|
182
|
+
subreddit: z.string(),
|
|
183
|
+
subreddit_id: z.string(),
|
|
184
|
+
title: z.string(),
|
|
185
|
+
upvote_ratio: z.number().min(0).max(1).default(0),
|
|
186
|
+
url: z.string(),
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
export const REDDIT_PROVIDER_COMMENT_SCHEMA = z.looseObject({
|
|
190
|
+
author: z.string().nullable().catch(null),
|
|
191
|
+
body: z.string().default(""),
|
|
192
|
+
created_utc: z.number(),
|
|
193
|
+
depth: z.number().int().nonnegative().default(0),
|
|
194
|
+
distinguished: z
|
|
195
|
+
.enum(["admin", "moderator", "special"])
|
|
196
|
+
.nullable()
|
|
197
|
+
.catch(null),
|
|
198
|
+
edited: REDDIT_EDITED_SCHEMA.catch(false),
|
|
199
|
+
id: z.string().min(1),
|
|
200
|
+
is_submitter: z.boolean().default(false),
|
|
201
|
+
link_id: REDDIT_POST_ID_SCHEMA,
|
|
202
|
+
name: z.string().regex(/^t1_[a-z0-9]+$/i),
|
|
203
|
+
parent_id: REDDIT_THING_ID_SCHEMA,
|
|
204
|
+
permalink: z.string(),
|
|
205
|
+
saved: z.boolean().default(false),
|
|
206
|
+
score: z.number().int().default(0),
|
|
207
|
+
stickied: z.boolean().default(false),
|
|
208
|
+
subreddit: z.string(),
|
|
209
|
+
})
|
|
210
|
+
|
|
211
|
+
export const REDDIT_PROVIDER_MESSAGE_SCHEMA = z.looseObject({
|
|
212
|
+
author: z.string().nullable().catch(null),
|
|
213
|
+
body: z.string().default(""),
|
|
214
|
+
context: z.string().default(""),
|
|
215
|
+
created_utc: z.number(),
|
|
216
|
+
dest: z.string().default(""),
|
|
217
|
+
id: z.string().min(1),
|
|
218
|
+
name: REDDIT_INBOX_ID_SCHEMA,
|
|
219
|
+
new: z.boolean().default(false),
|
|
220
|
+
parent_id: z.string().nullable().catch(null),
|
|
221
|
+
permalink: z.string().nullable().catch(null),
|
|
222
|
+
subject: z.string().default(""),
|
|
223
|
+
subreddit: z.string().nullable().catch(null),
|
|
224
|
+
was_comment: z.boolean().default(false),
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
export const REDDIT_PROVIDER_SUBREDDIT_SCHEMA = z.looseObject({
|
|
228
|
+
active_user_count: z.number().int().nonnegative().nullable().catch(null),
|
|
229
|
+
created_utc: z.number(),
|
|
230
|
+
description: z.string().default(""),
|
|
231
|
+
display_name: z.string(),
|
|
232
|
+
display_name_prefixed: z.string(),
|
|
233
|
+
name: z.string().regex(/^t5_[a-z0-9]+$/i),
|
|
234
|
+
over18: z.boolean().default(false),
|
|
235
|
+
public_description: z.string().default(""),
|
|
236
|
+
subscribers: z.number().int().nonnegative().default(0),
|
|
237
|
+
title: z.string(),
|
|
238
|
+
url: z.string(),
|
|
239
|
+
user_is_subscriber: z.boolean().nullable().catch(null),
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
export const REDDIT_PROVIDER_POST_THING_SCHEMA = z.object({
|
|
243
|
+
data: REDDIT_PROVIDER_POST_SCHEMA,
|
|
244
|
+
kind: z.literal("t3"),
|
|
245
|
+
})
|
|
246
|
+
export const REDDIT_PROVIDER_COMMENT_THING_SCHEMA = z.object({
|
|
247
|
+
data: REDDIT_PROVIDER_COMMENT_SCHEMA,
|
|
248
|
+
kind: z.literal("t1"),
|
|
249
|
+
})
|
|
250
|
+
export const REDDIT_PROVIDER_MESSAGE_THING_SCHEMA = z.object({
|
|
251
|
+
data: REDDIT_PROVIDER_MESSAGE_SCHEMA,
|
|
252
|
+
kind: z.literal("t4"),
|
|
253
|
+
})
|
|
254
|
+
export const REDDIT_PROVIDER_INBOX_THING_SCHEMA = z.union([
|
|
255
|
+
REDDIT_PROVIDER_MESSAGE_THING_SCHEMA,
|
|
256
|
+
z.object({
|
|
257
|
+
data: REDDIT_PROVIDER_MESSAGE_SCHEMA,
|
|
258
|
+
kind: z.literal("t1"),
|
|
259
|
+
}),
|
|
260
|
+
])
|
|
261
|
+
export const REDDIT_PROVIDER_SUBREDDIT_THING_SCHEMA = z.object({
|
|
262
|
+
data: REDDIT_PROVIDER_SUBREDDIT_SCHEMA,
|
|
263
|
+
kind: z.literal("t5"),
|
|
264
|
+
})
|
|
265
|
+
export const REDDIT_PROVIDER_CONTENT_THING_SCHEMA = z.union([
|
|
266
|
+
REDDIT_PROVIDER_POST_THING_SCHEMA,
|
|
267
|
+
REDDIT_PROVIDER_COMMENT_THING_SCHEMA,
|
|
268
|
+
])
|
|
269
|
+
|
|
270
|
+
/** Builds one provider listing schema with exact child contracts. */
|
|
271
|
+
/** @param childSchema - Schema for one listing child. */
|
|
272
|
+
export function redditProviderListingSchema<TSchema extends z.ZodType>(
|
|
273
|
+
childSchema: TSchema,
|
|
274
|
+
) {
|
|
275
|
+
return z.object({
|
|
276
|
+
data: z.object({
|
|
277
|
+
after: z.string().nullable(),
|
|
278
|
+
before: z.string().nullable(),
|
|
279
|
+
children: childSchema.array(),
|
|
280
|
+
}),
|
|
281
|
+
kind: z.literal("Listing"),
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export const REDDIT_PROVIDER_POST_LISTING_SCHEMA = redditProviderListingSchema(
|
|
286
|
+
REDDIT_PROVIDER_POST_THING_SCHEMA,
|
|
287
|
+
)
|
|
288
|
+
export const REDDIT_PROVIDER_CONTENT_LISTING_SCHEMA =
|
|
289
|
+
redditProviderListingSchema(REDDIT_PROVIDER_CONTENT_THING_SCHEMA)
|
|
290
|
+
export const REDDIT_PROVIDER_MESSAGE_LISTING_SCHEMA =
|
|
291
|
+
redditProviderListingSchema(REDDIT_PROVIDER_INBOX_THING_SCHEMA)
|
|
292
|
+
|
|
293
|
+
export const REDDIT_PROVIDER_FLAIR_TEMPLATE_SCHEMA = z.looseObject({
|
|
294
|
+
background_color: z.string().default(""),
|
|
295
|
+
css_class: z.string().default(""),
|
|
296
|
+
flair_template_id: z.string(),
|
|
297
|
+
flair_text_editable: z.boolean().default(false),
|
|
298
|
+
flair_text: z.string().default(""),
|
|
299
|
+
text_color: z.enum(["dark", "light"]).default("dark"),
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
/** Converts a Reddit provider post into the stable public post shape. */
|
|
303
|
+
/** @param post - Parsed provider post. */
|
|
304
|
+
export function toRedditPost(
|
|
305
|
+
post: z.output<typeof REDDIT_PROVIDER_POST_SCHEMA>,
|
|
306
|
+
) {
|
|
307
|
+
return REDDIT_POST_SCHEMA.parse({
|
|
308
|
+
archived: post.archived,
|
|
309
|
+
author: post.author,
|
|
310
|
+
body: post.selftext,
|
|
311
|
+
commentCount: post.num_comments,
|
|
312
|
+
createdAt: new Date(post.created_utc * 1_000),
|
|
313
|
+
editedAt: post.edited === false ? null : new Date(post.edited * 1_000),
|
|
314
|
+
flair: {
|
|
315
|
+
backgroundColor: post.link_flair_background_color,
|
|
316
|
+
cssClass: post.link_flair_css_class,
|
|
317
|
+
templateId: post.link_flair_template_id,
|
|
318
|
+
text: post.link_flair_text,
|
|
319
|
+
textColor: post.link_flair_text_color,
|
|
320
|
+
},
|
|
321
|
+
hidden: post.hidden,
|
|
322
|
+
id: post.name,
|
|
323
|
+
isLocked: post.locked,
|
|
324
|
+
isNsfw: post.over_18,
|
|
325
|
+
isSelfPost: post.is_self,
|
|
326
|
+
isSpoiler: post.spoiler,
|
|
327
|
+
isStickied: post.stickied,
|
|
328
|
+
permalink: new URL(post.permalink, REDDIT_ORIGIN).toString(),
|
|
329
|
+
saved: post.saved,
|
|
330
|
+
score: post.score,
|
|
331
|
+
shortId: post.id,
|
|
332
|
+
subreddit: post.subreddit,
|
|
333
|
+
subredditId: post.subreddit_id,
|
|
334
|
+
title: post.title,
|
|
335
|
+
upvoteRatio: post.upvote_ratio,
|
|
336
|
+
url: new URL(post.url, REDDIT_ORIGIN).toString(),
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** Converts a Reddit provider comment into the stable public comment shape. */
|
|
341
|
+
/** @param comment - Parsed provider comment. */
|
|
342
|
+
export function toRedditComment(
|
|
343
|
+
comment: z.output<typeof REDDIT_PROVIDER_COMMENT_SCHEMA>,
|
|
344
|
+
) {
|
|
345
|
+
return REDDIT_COMMENT_SCHEMA.parse({
|
|
346
|
+
author: comment.author,
|
|
347
|
+
body: comment.body,
|
|
348
|
+
createdAt: new Date(comment.created_utc * 1_000),
|
|
349
|
+
depth: comment.depth,
|
|
350
|
+
distinguished: comment.distinguished,
|
|
351
|
+
editedAt:
|
|
352
|
+
comment.edited === false ? null : new Date(comment.edited * 1_000),
|
|
353
|
+
id: comment.name,
|
|
354
|
+
isPostAuthor: comment.is_submitter,
|
|
355
|
+
isStickied: comment.stickied,
|
|
356
|
+
parentId: comment.parent_id,
|
|
357
|
+
permalink: new URL(comment.permalink, REDDIT_ORIGIN).toString(),
|
|
358
|
+
postId: comment.link_id,
|
|
359
|
+
saved: comment.saved,
|
|
360
|
+
score: comment.score,
|
|
361
|
+
shortId: comment.id,
|
|
362
|
+
subreddit: comment.subreddit,
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Converts a Reddit inbox record into the stable public message shape. */
|
|
367
|
+
/** @param message - Parsed provider inbox record. */
|
|
368
|
+
export function toRedditMessage(
|
|
369
|
+
message: z.output<typeof REDDIT_PROVIDER_MESSAGE_SCHEMA>,
|
|
370
|
+
) {
|
|
371
|
+
return REDDIT_MESSAGE_SCHEMA.parse({
|
|
372
|
+
author: message.author,
|
|
373
|
+
body: message.body,
|
|
374
|
+
context: message.context,
|
|
375
|
+
createdAt: new Date(message.created_utc * 1_000),
|
|
376
|
+
destination: message.dest,
|
|
377
|
+
id: message.name,
|
|
378
|
+
isNew: message.new,
|
|
379
|
+
parentId: message.parent_id,
|
|
380
|
+
permalink: message.permalink
|
|
381
|
+
? new URL(message.permalink, REDDIT_ORIGIN).toString()
|
|
382
|
+
: null,
|
|
383
|
+
shortId: message.id,
|
|
384
|
+
subject: message.subject,
|
|
385
|
+
subreddit: message.subreddit,
|
|
386
|
+
wasComment: message.was_comment,
|
|
387
|
+
})
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** Converts a Reddit subreddit thing into the stable public shape. */
|
|
391
|
+
/** @param subreddit - Parsed provider subreddit. */
|
|
392
|
+
export function toRedditSubreddit(
|
|
393
|
+
subreddit: z.output<typeof REDDIT_PROVIDER_SUBREDDIT_SCHEMA>,
|
|
394
|
+
) {
|
|
395
|
+
return REDDIT_SUBREDDIT_SCHEMA.parse({
|
|
396
|
+
activeUserCount: subreddit.active_user_count,
|
|
397
|
+
createdAt: new Date(subreddit.created_utc * 1_000),
|
|
398
|
+
description: subreddit.description,
|
|
399
|
+
displayName: subreddit.display_name,
|
|
400
|
+
id: subreddit.name,
|
|
401
|
+
isNsfw: subreddit.over18,
|
|
402
|
+
name: subreddit.display_name_prefixed,
|
|
403
|
+
publicDescription: subreddit.public_description,
|
|
404
|
+
subscribers: subreddit.subscribers,
|
|
405
|
+
title: subreddit.title,
|
|
406
|
+
url: new URL(subreddit.url, REDDIT_ORIGIN).toString(),
|
|
407
|
+
userIsSubscriber: subreddit.user_is_subscriber ?? false,
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/** Converts a Reddit identity response into the stable public profile shape. */
|
|
412
|
+
/** @param profile - Parsed provider identity. */
|
|
413
|
+
export function toRedditProfile(
|
|
414
|
+
profile: z.output<typeof REDDIT_PROVIDER_PROFILE_SCHEMA>,
|
|
415
|
+
) {
|
|
416
|
+
return REDDIT_PROFILE_SCHEMA.parse({
|
|
417
|
+
commentKarma: profile.comment_karma,
|
|
418
|
+
createdAt: new Date(profile.created_utc * 1_000),
|
|
419
|
+
hasVerifiedEmail: profile.has_verified_email,
|
|
420
|
+
id: profile.id,
|
|
421
|
+
isEmployee: profile.is_employee,
|
|
422
|
+
isModerator: profile.is_mod,
|
|
423
|
+
linkKarma: profile.link_karma,
|
|
424
|
+
username: profile.name,
|
|
425
|
+
})
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** Converts provider listing cursors into stable public pagination metadata. */
|
|
429
|
+
/**
|
|
430
|
+
* @param listing - Parsed provider listing.
|
|
431
|
+
* @param listing.data - Provider listing data.
|
|
432
|
+
* @param listing.data.after - Forward cursor.
|
|
433
|
+
* @param listing.data.before - Backward cursor.
|
|
434
|
+
*/
|
|
435
|
+
export function toRedditPageInfo(listing: {
|
|
436
|
+
data: { after: string | null; before: string | null }
|
|
437
|
+
}) {
|
|
438
|
+
return REDDIT_PAGE_INFO_SCHEMA.parse({
|
|
439
|
+
after: listing.data.after,
|
|
440
|
+
before: listing.data.before,
|
|
441
|
+
})
|
|
442
|
+
}
|
package/src/triggers.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { linearTriggerContracts } from "./linear"
|
|
|
18
18
|
import type { millionVerifierTriggerContracts } from "./millionverifier"
|
|
19
19
|
import type { notionTriggerContracts } from "./notion"
|
|
20
20
|
import type { outlookTriggerContracts } from "./outlook"
|
|
21
|
+
import type { redditTriggerContracts } from "./reddit"
|
|
21
22
|
import type { resendTriggerContracts } from "./resend"
|
|
22
23
|
import type { slackTriggerContracts } from "./slack"
|
|
23
24
|
import type { stripeTriggerContracts } from "./stripe"
|
|
@@ -48,6 +49,7 @@ export type TriggerContractMap = typeof airtableTriggerContracts &
|
|
|
48
49
|
typeof millionVerifierTriggerContracts &
|
|
49
50
|
typeof notionTriggerContracts &
|
|
50
51
|
typeof outlookTriggerContracts &
|
|
52
|
+
typeof redditTriggerContracts &
|
|
51
53
|
typeof resendTriggerContracts &
|
|
52
54
|
typeof slackTriggerContracts &
|
|
53
55
|
typeof stripeTriggerContracts &
|