@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,56 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const REDDIT_OAUTH_SECRET_SCHEMA: z.ZodObject<{
|
|
3
|
+
accessToken: z.ZodString;
|
|
4
|
+
expiresAt: z.ZodNumber;
|
|
5
|
+
refreshToken: z.ZodString;
|
|
6
|
+
tokenType: z.ZodString;
|
|
7
|
+
userAgent: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
export declare const REDDIT_ERROR_TUPLE_SCHEMA: z.ZodTuple<[z.ZodString, z.ZodString, z.ZodNullable<z.ZodString>], null>;
|
|
10
|
+
export declare const REDDIT_JSON_STATUS_SCHEMA: z.ZodObject<{
|
|
11
|
+
json: z.ZodObject<{
|
|
12
|
+
errors: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString, z.ZodNullable<z.ZodString>], null>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export interface RedditRequestOptions<TSchema extends z.ZodType> {
|
|
16
|
+
body?: Record<string, boolean | number | string | undefined>;
|
|
17
|
+
method?: "DELETE" | "GET" | "POST" | "PUT";
|
|
18
|
+
query?: Record<string, boolean | number | string | readonly string[] | null | undefined>;
|
|
19
|
+
responseSchema: TSchema;
|
|
20
|
+
}
|
|
21
|
+
/** Error returned by a rejected Reddit Data API request. */
|
|
22
|
+
export declare class RedditApiError extends Error {
|
|
23
|
+
readonly details: {
|
|
24
|
+
error?: number;
|
|
25
|
+
message?: string;
|
|
26
|
+
reason?: string;
|
|
27
|
+
} | {
|
|
28
|
+
errors: [string, string, null | string][];
|
|
29
|
+
} | {
|
|
30
|
+
response: string;
|
|
31
|
+
};
|
|
32
|
+
readonly retryAfter?: string;
|
|
33
|
+
readonly status: number;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an error from a rejected Reddit response.
|
|
36
|
+
*
|
|
37
|
+
* @param status - HTTP response status.
|
|
38
|
+
* @param details - Parsed Reddit failure details.
|
|
39
|
+
* @param retryAfter - Provider retry delay in seconds, when present.
|
|
40
|
+
*/
|
|
41
|
+
constructor(status: number, details: RedditApiError["details"], retryAfter?: string);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Creates an authenticated Reddit Data API client.
|
|
45
|
+
*
|
|
46
|
+
* @param secret - Stored Reddit OAuth credentials and registered User-Agent.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getRedditApi(secret: unknown): {
|
|
49
|
+
/**
|
|
50
|
+
* Sends one request below Reddit's OAuth API origin.
|
|
51
|
+
*
|
|
52
|
+
* @param path - Relative Reddit API path.
|
|
53
|
+
* @param options - Request method, parameters, and response contract.
|
|
54
|
+
*/
|
|
55
|
+
request<TSchema extends z.ZodType>(path: string, options: RedditRequestOptions<TSchema>): Promise<z.output<TSchema>>;
|
|
56
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
const REDDIT_API_ORIGIN = "https://oauth.reddit.com/";
|
|
3
|
+
const REDDIT_API_URL = new URL(REDDIT_API_ORIGIN);
|
|
4
|
+
export const REDDIT_OAUTH_SECRET_SCHEMA = z.object({
|
|
5
|
+
accessToken: z.string().min(1),
|
|
6
|
+
expiresAt: z.number().int().positive(),
|
|
7
|
+
refreshToken: z.string().min(1),
|
|
8
|
+
tokenType: z.string().min(1),
|
|
9
|
+
userAgent: z.string().min(1),
|
|
10
|
+
});
|
|
11
|
+
const REDDIT_API_ERROR_SCHEMA = z.looseObject({
|
|
12
|
+
error: z.number().int().optional(),
|
|
13
|
+
message: z.string().optional(),
|
|
14
|
+
reason: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
export const REDDIT_ERROR_TUPLE_SCHEMA = z.tuple([
|
|
17
|
+
z.string(),
|
|
18
|
+
z.string(),
|
|
19
|
+
z.string().nullable(),
|
|
20
|
+
]);
|
|
21
|
+
const REDDIT_JSON_ERRORS_SCHEMA = z.looseObject({
|
|
22
|
+
json: z.object({
|
|
23
|
+
errors: REDDIT_ERROR_TUPLE_SCHEMA.array(),
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
export const REDDIT_JSON_STATUS_SCHEMA = z.object({
|
|
27
|
+
json: z.object({ errors: REDDIT_ERROR_TUPLE_SCHEMA.array() }),
|
|
28
|
+
});
|
|
29
|
+
/** Error returned by a rejected Reddit Data API request. */
|
|
30
|
+
export class RedditApiError extends Error {
|
|
31
|
+
details;
|
|
32
|
+
retryAfter;
|
|
33
|
+
status;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an error from a rejected Reddit response.
|
|
36
|
+
*
|
|
37
|
+
* @param status - HTTP response status.
|
|
38
|
+
* @param details - Parsed Reddit failure details.
|
|
39
|
+
* @param retryAfter - Provider retry delay in seconds, when present.
|
|
40
|
+
*/
|
|
41
|
+
constructor(status, details, retryAfter) {
|
|
42
|
+
const jsonError = "errors" in details ? details.errors[0]?.[1] : undefined;
|
|
43
|
+
super(("message" in details
|
|
44
|
+
? (details.message ?? details.reason)
|
|
45
|
+
: undefined) ??
|
|
46
|
+
jsonError ??
|
|
47
|
+
`Reddit API request failed (${status}).`);
|
|
48
|
+
this.name = "RedditApiError";
|
|
49
|
+
this.details = details;
|
|
50
|
+
this.retryAfter = retryAfter;
|
|
51
|
+
this.status = status;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates an authenticated Reddit Data API client.
|
|
56
|
+
*
|
|
57
|
+
* @param secret - Stored Reddit OAuth credentials and registered User-Agent.
|
|
58
|
+
*/
|
|
59
|
+
export function getRedditApi(secret) {
|
|
60
|
+
const credentials = REDDIT_OAUTH_SECRET_SCHEMA.parse(secret);
|
|
61
|
+
return {
|
|
62
|
+
/**
|
|
63
|
+
* Sends one request below Reddit's OAuth API origin.
|
|
64
|
+
*
|
|
65
|
+
* @param path - Relative Reddit API path.
|
|
66
|
+
* @param options - Request method, parameters, and response contract.
|
|
67
|
+
*/
|
|
68
|
+
async request(path, options) {
|
|
69
|
+
const normalizedPath = path.replace(/^\/+/, "");
|
|
70
|
+
if (!normalizedPath ||
|
|
71
|
+
normalizedPath.includes("://") ||
|
|
72
|
+
normalizedPath.includes("\\")) {
|
|
73
|
+
throw new TypeError("Reddit API paths must be relative.");
|
|
74
|
+
}
|
|
75
|
+
const url = new URL(normalizedPath, REDDIT_API_ORIGIN);
|
|
76
|
+
if (url.origin !== REDDIT_API_URL.origin) {
|
|
77
|
+
throw new TypeError("Reddit API paths must remain on oauth.reddit.com.");
|
|
78
|
+
}
|
|
79
|
+
url.searchParams.set("raw_json", "1");
|
|
80
|
+
for (const [key, value] of Object.entries(options.query ?? {})) {
|
|
81
|
+
if (value == null)
|
|
82
|
+
continue;
|
|
83
|
+
url.searchParams.set(key, Array.isArray(value) ? value.join(",") : String(value));
|
|
84
|
+
}
|
|
85
|
+
const headers = new Headers({
|
|
86
|
+
Accept: "application/json",
|
|
87
|
+
Authorization: `${credentials.tokenType} ${credentials.accessToken}`,
|
|
88
|
+
"User-Agent": credentials.userAgent,
|
|
89
|
+
});
|
|
90
|
+
const body = options.body
|
|
91
|
+
? new URLSearchParams(Object.entries(options.body).flatMap(([key, value]) => value === undefined
|
|
92
|
+
? []
|
|
93
|
+
: [[key, String(value)]]))
|
|
94
|
+
: undefined;
|
|
95
|
+
if (body) {
|
|
96
|
+
headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
97
|
+
}
|
|
98
|
+
const response = await fetch(url, {
|
|
99
|
+
body,
|
|
100
|
+
headers,
|
|
101
|
+
method: options.method ?? "GET",
|
|
102
|
+
});
|
|
103
|
+
const text = await response.text();
|
|
104
|
+
const parsed = parseJson(text);
|
|
105
|
+
const jsonErrors = REDDIT_JSON_ERRORS_SCHEMA.safeParse(parsed);
|
|
106
|
+
const retryAfter = response.headers.get("Retry-After") ??
|
|
107
|
+
response.headers.get("X-Ratelimit-Reset") ??
|
|
108
|
+
undefined;
|
|
109
|
+
if (jsonErrors.success && jsonErrors.data.json.errors.length > 0) {
|
|
110
|
+
throw new RedditApiError(response.ok ? 400 : response.status, { errors: jsonErrors.data.json.errors }, retryAfter);
|
|
111
|
+
}
|
|
112
|
+
if (!response.ok) {
|
|
113
|
+
const error = REDDIT_API_ERROR_SCHEMA.safeParse(parsed);
|
|
114
|
+
throw new RedditApiError(response.status, error.success ? error.data : { response: text }, retryAfter);
|
|
115
|
+
}
|
|
116
|
+
const result = options.responseSchema.safeParse(parsed);
|
|
117
|
+
if (!result.success) {
|
|
118
|
+
throw new RedditApiError(response.status, { response: text });
|
|
119
|
+
}
|
|
120
|
+
return result.data;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Parses a provider body while preserving non-JSON failure text. */
|
|
125
|
+
/** @param value - Raw provider response body. */
|
|
126
|
+
function parseJson(value) {
|
|
127
|
+
if (!value)
|
|
128
|
+
return undefined;
|
|
129
|
+
try {
|
|
130
|
+
return JSON.parse(value);
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return value;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
export declare const REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA: z.ZodObject<{
|
|
3
|
+
subreddit: z.ZodString;
|
|
4
|
+
}, z.core.$strip>;
|
|
5
|
+
export declare const REDDIT_ACCOUNT_TRIGGER_CONFIG_SCHEMA: z.ZodObject<{}, z.core.$strip>;
|
|
6
|
+
export declare const REDDIT_SUBREDDIT_EVENT_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
7
|
+
action: z.ZodLiteral<"commentCreated">;
|
|
8
|
+
comment: z.ZodObject<{
|
|
9
|
+
author: z.ZodNullable<z.ZodString>;
|
|
10
|
+
body: z.ZodString;
|
|
11
|
+
createdAt: z.ZodDate;
|
|
12
|
+
depth: z.ZodNumber;
|
|
13
|
+
distinguished: z.ZodNullable<z.ZodEnum<{
|
|
14
|
+
admin: "admin";
|
|
15
|
+
moderator: "moderator";
|
|
16
|
+
special: "special";
|
|
17
|
+
}>>;
|
|
18
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
19
|
+
id: z.ZodString;
|
|
20
|
+
isPostAuthor: z.ZodBoolean;
|
|
21
|
+
isStickied: z.ZodBoolean;
|
|
22
|
+
parentId: z.ZodString;
|
|
23
|
+
permalink: z.ZodURL;
|
|
24
|
+
postId: z.ZodString;
|
|
25
|
+
saved: z.ZodBoolean;
|
|
26
|
+
score: z.ZodNumber;
|
|
27
|
+
shortId: z.ZodString;
|
|
28
|
+
subreddit: z.ZodString;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
31
|
+
action: z.ZodLiteral<"postCreated">;
|
|
32
|
+
post: z.ZodObject<{
|
|
33
|
+
archived: z.ZodBoolean;
|
|
34
|
+
author: z.ZodNullable<z.ZodString>;
|
|
35
|
+
body: z.ZodString;
|
|
36
|
+
commentCount: z.ZodNumber;
|
|
37
|
+
createdAt: z.ZodDate;
|
|
38
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
39
|
+
flair: z.ZodObject<{
|
|
40
|
+
backgroundColor: z.ZodNullable<z.ZodString>;
|
|
41
|
+
cssClass: z.ZodNullable<z.ZodString>;
|
|
42
|
+
templateId: z.ZodNullable<z.ZodString>;
|
|
43
|
+
text: z.ZodNullable<z.ZodString>;
|
|
44
|
+
textColor: z.ZodNullable<z.ZodEnum<{
|
|
45
|
+
dark: "dark";
|
|
46
|
+
light: "light";
|
|
47
|
+
}>>;
|
|
48
|
+
}, z.core.$strip>;
|
|
49
|
+
hidden: z.ZodBoolean;
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
isLocked: z.ZodBoolean;
|
|
52
|
+
isNsfw: z.ZodBoolean;
|
|
53
|
+
isSelfPost: z.ZodBoolean;
|
|
54
|
+
isSpoiler: z.ZodBoolean;
|
|
55
|
+
isStickied: z.ZodBoolean;
|
|
56
|
+
permalink: z.ZodURL;
|
|
57
|
+
saved: z.ZodBoolean;
|
|
58
|
+
score: z.ZodNumber;
|
|
59
|
+
shortId: z.ZodString;
|
|
60
|
+
subreddit: z.ZodString;
|
|
61
|
+
subredditId: z.ZodString;
|
|
62
|
+
title: z.ZodString;
|
|
63
|
+
upvoteRatio: z.ZodNumber;
|
|
64
|
+
url: z.ZodURL;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
}, z.core.$strip>], "action">;
|
|
67
|
+
export declare const REDDIT_INBOX_EVENT_SCHEMA: z.ZodObject<{
|
|
68
|
+
action: z.ZodLiteral<"inboxItemCreated">;
|
|
69
|
+
message: z.ZodObject<{
|
|
70
|
+
author: z.ZodNullable<z.ZodString>;
|
|
71
|
+
body: z.ZodString;
|
|
72
|
+
context: z.ZodString;
|
|
73
|
+
createdAt: z.ZodDate;
|
|
74
|
+
destination: z.ZodString;
|
|
75
|
+
id: z.ZodString;
|
|
76
|
+
isNew: z.ZodBoolean;
|
|
77
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
78
|
+
permalink: z.ZodNullable<z.ZodURL>;
|
|
79
|
+
shortId: z.ZodString;
|
|
80
|
+
subject: z.ZodString;
|
|
81
|
+
subreddit: z.ZodNullable<z.ZodString>;
|
|
82
|
+
wasComment: z.ZodBoolean;
|
|
83
|
+
}, z.core.$strip>;
|
|
84
|
+
}, z.core.$strip>;
|
|
85
|
+
export declare const REDDIT_MOD_QUEUE_EVENT_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
86
|
+
comment: z.ZodObject<{
|
|
87
|
+
author: z.ZodNullable<z.ZodString>;
|
|
88
|
+
body: z.ZodString;
|
|
89
|
+
createdAt: z.ZodDate;
|
|
90
|
+
depth: z.ZodNumber;
|
|
91
|
+
distinguished: z.ZodNullable<z.ZodEnum<{
|
|
92
|
+
admin: "admin";
|
|
93
|
+
moderator: "moderator";
|
|
94
|
+
special: "special";
|
|
95
|
+
}>>;
|
|
96
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
97
|
+
id: z.ZodString;
|
|
98
|
+
isPostAuthor: z.ZodBoolean;
|
|
99
|
+
isStickied: z.ZodBoolean;
|
|
100
|
+
parentId: z.ZodString;
|
|
101
|
+
permalink: z.ZodURL;
|
|
102
|
+
postId: z.ZodString;
|
|
103
|
+
saved: z.ZodBoolean;
|
|
104
|
+
score: z.ZodNumber;
|
|
105
|
+
shortId: z.ZodString;
|
|
106
|
+
subreddit: z.ZodString;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
kind: z.ZodLiteral<"comment">;
|
|
109
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
110
|
+
kind: z.ZodLiteral<"post">;
|
|
111
|
+
post: z.ZodObject<{
|
|
112
|
+
archived: z.ZodBoolean;
|
|
113
|
+
author: z.ZodNullable<z.ZodString>;
|
|
114
|
+
body: z.ZodString;
|
|
115
|
+
commentCount: z.ZodNumber;
|
|
116
|
+
createdAt: z.ZodDate;
|
|
117
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
118
|
+
flair: z.ZodObject<{
|
|
119
|
+
backgroundColor: z.ZodNullable<z.ZodString>;
|
|
120
|
+
cssClass: z.ZodNullable<z.ZodString>;
|
|
121
|
+
templateId: z.ZodNullable<z.ZodString>;
|
|
122
|
+
text: z.ZodNullable<z.ZodString>;
|
|
123
|
+
textColor: z.ZodNullable<z.ZodEnum<{
|
|
124
|
+
dark: "dark";
|
|
125
|
+
light: "light";
|
|
126
|
+
}>>;
|
|
127
|
+
}, z.core.$strip>;
|
|
128
|
+
hidden: z.ZodBoolean;
|
|
129
|
+
id: z.ZodString;
|
|
130
|
+
isLocked: z.ZodBoolean;
|
|
131
|
+
isNsfw: z.ZodBoolean;
|
|
132
|
+
isSelfPost: z.ZodBoolean;
|
|
133
|
+
isSpoiler: z.ZodBoolean;
|
|
134
|
+
isStickied: z.ZodBoolean;
|
|
135
|
+
permalink: z.ZodURL;
|
|
136
|
+
saved: z.ZodBoolean;
|
|
137
|
+
score: z.ZodNumber;
|
|
138
|
+
shortId: z.ZodString;
|
|
139
|
+
subreddit: z.ZodString;
|
|
140
|
+
subredditId: z.ZodString;
|
|
141
|
+
title: z.ZodString;
|
|
142
|
+
upvoteRatio: z.ZodNumber;
|
|
143
|
+
url: z.ZodURL;
|
|
144
|
+
}, z.core.$strip>;
|
|
145
|
+
}, z.core.$strip>], "kind">;
|
|
146
|
+
export declare const redditTriggerContracts: {
|
|
147
|
+
readonly "reddit.inbox.item.received": {
|
|
148
|
+
readonly configSchema: z.ZodObject<{}, z.core.$strip>;
|
|
149
|
+
readonly eventSchema: z.ZodObject<{
|
|
150
|
+
action: z.ZodLiteral<"inboxItemCreated">;
|
|
151
|
+
message: z.ZodObject<{
|
|
152
|
+
author: z.ZodNullable<z.ZodString>;
|
|
153
|
+
body: z.ZodString;
|
|
154
|
+
context: z.ZodString;
|
|
155
|
+
createdAt: z.ZodDate;
|
|
156
|
+
destination: z.ZodString;
|
|
157
|
+
id: z.ZodString;
|
|
158
|
+
isNew: z.ZodBoolean;
|
|
159
|
+
parentId: z.ZodNullable<z.ZodString>;
|
|
160
|
+
permalink: z.ZodNullable<z.ZodURL>;
|
|
161
|
+
shortId: z.ZodString;
|
|
162
|
+
subject: z.ZodString;
|
|
163
|
+
subreddit: z.ZodNullable<z.ZodString>;
|
|
164
|
+
wasComment: z.ZodBoolean;
|
|
165
|
+
}, z.core.$strip>;
|
|
166
|
+
}, z.core.$strip>;
|
|
167
|
+
};
|
|
168
|
+
readonly "reddit.modQueue.item.received": {
|
|
169
|
+
readonly configSchema: z.ZodObject<{
|
|
170
|
+
subreddit: z.ZodString;
|
|
171
|
+
}, z.core.$strip>;
|
|
172
|
+
readonly eventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
173
|
+
comment: z.ZodObject<{
|
|
174
|
+
author: z.ZodNullable<z.ZodString>;
|
|
175
|
+
body: z.ZodString;
|
|
176
|
+
createdAt: z.ZodDate;
|
|
177
|
+
depth: z.ZodNumber;
|
|
178
|
+
distinguished: z.ZodNullable<z.ZodEnum<{
|
|
179
|
+
admin: "admin";
|
|
180
|
+
moderator: "moderator";
|
|
181
|
+
special: "special";
|
|
182
|
+
}>>;
|
|
183
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
184
|
+
id: z.ZodString;
|
|
185
|
+
isPostAuthor: z.ZodBoolean;
|
|
186
|
+
isStickied: z.ZodBoolean;
|
|
187
|
+
parentId: z.ZodString;
|
|
188
|
+
permalink: z.ZodURL;
|
|
189
|
+
postId: z.ZodString;
|
|
190
|
+
saved: z.ZodBoolean;
|
|
191
|
+
score: z.ZodNumber;
|
|
192
|
+
shortId: z.ZodString;
|
|
193
|
+
subreddit: z.ZodString;
|
|
194
|
+
}, z.core.$strip>;
|
|
195
|
+
kind: z.ZodLiteral<"comment">;
|
|
196
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
197
|
+
kind: z.ZodLiteral<"post">;
|
|
198
|
+
post: z.ZodObject<{
|
|
199
|
+
archived: z.ZodBoolean;
|
|
200
|
+
author: z.ZodNullable<z.ZodString>;
|
|
201
|
+
body: z.ZodString;
|
|
202
|
+
commentCount: z.ZodNumber;
|
|
203
|
+
createdAt: z.ZodDate;
|
|
204
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
205
|
+
flair: z.ZodObject<{
|
|
206
|
+
backgroundColor: z.ZodNullable<z.ZodString>;
|
|
207
|
+
cssClass: z.ZodNullable<z.ZodString>;
|
|
208
|
+
templateId: z.ZodNullable<z.ZodString>;
|
|
209
|
+
text: z.ZodNullable<z.ZodString>;
|
|
210
|
+
textColor: z.ZodNullable<z.ZodEnum<{
|
|
211
|
+
dark: "dark";
|
|
212
|
+
light: "light";
|
|
213
|
+
}>>;
|
|
214
|
+
}, z.core.$strip>;
|
|
215
|
+
hidden: z.ZodBoolean;
|
|
216
|
+
id: z.ZodString;
|
|
217
|
+
isLocked: z.ZodBoolean;
|
|
218
|
+
isNsfw: z.ZodBoolean;
|
|
219
|
+
isSelfPost: z.ZodBoolean;
|
|
220
|
+
isSpoiler: z.ZodBoolean;
|
|
221
|
+
isStickied: z.ZodBoolean;
|
|
222
|
+
permalink: z.ZodURL;
|
|
223
|
+
saved: z.ZodBoolean;
|
|
224
|
+
score: z.ZodNumber;
|
|
225
|
+
shortId: z.ZodString;
|
|
226
|
+
subreddit: z.ZodString;
|
|
227
|
+
subredditId: z.ZodString;
|
|
228
|
+
title: z.ZodString;
|
|
229
|
+
upvoteRatio: z.ZodNumber;
|
|
230
|
+
url: z.ZodURL;
|
|
231
|
+
}, z.core.$strip>;
|
|
232
|
+
}, z.core.$strip>], "kind">;
|
|
233
|
+
};
|
|
234
|
+
readonly "reddit.subreddit.comment.created": {
|
|
235
|
+
readonly configSchema: z.ZodObject<{
|
|
236
|
+
subreddit: z.ZodString;
|
|
237
|
+
}, z.core.$strip>;
|
|
238
|
+
readonly eventSchema: z.ZodIntersection<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
239
|
+
action: z.ZodLiteral<"commentCreated">;
|
|
240
|
+
comment: z.ZodObject<{
|
|
241
|
+
author: z.ZodNullable<z.ZodString>;
|
|
242
|
+
body: z.ZodString;
|
|
243
|
+
createdAt: z.ZodDate;
|
|
244
|
+
depth: z.ZodNumber;
|
|
245
|
+
distinguished: z.ZodNullable<z.ZodEnum<{
|
|
246
|
+
admin: "admin";
|
|
247
|
+
moderator: "moderator";
|
|
248
|
+
special: "special";
|
|
249
|
+
}>>;
|
|
250
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
251
|
+
id: z.ZodString;
|
|
252
|
+
isPostAuthor: z.ZodBoolean;
|
|
253
|
+
isStickied: z.ZodBoolean;
|
|
254
|
+
parentId: z.ZodString;
|
|
255
|
+
permalink: z.ZodURL;
|
|
256
|
+
postId: z.ZodString;
|
|
257
|
+
saved: z.ZodBoolean;
|
|
258
|
+
score: z.ZodNumber;
|
|
259
|
+
shortId: z.ZodString;
|
|
260
|
+
subreddit: z.ZodString;
|
|
261
|
+
}, z.core.$strip>;
|
|
262
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
263
|
+
action: z.ZodLiteral<"postCreated">;
|
|
264
|
+
post: z.ZodObject<{
|
|
265
|
+
archived: z.ZodBoolean;
|
|
266
|
+
author: z.ZodNullable<z.ZodString>;
|
|
267
|
+
body: z.ZodString;
|
|
268
|
+
commentCount: z.ZodNumber;
|
|
269
|
+
createdAt: z.ZodDate;
|
|
270
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
271
|
+
flair: z.ZodObject<{
|
|
272
|
+
backgroundColor: z.ZodNullable<z.ZodString>;
|
|
273
|
+
cssClass: z.ZodNullable<z.ZodString>;
|
|
274
|
+
templateId: z.ZodNullable<z.ZodString>;
|
|
275
|
+
text: z.ZodNullable<z.ZodString>;
|
|
276
|
+
textColor: z.ZodNullable<z.ZodEnum<{
|
|
277
|
+
dark: "dark";
|
|
278
|
+
light: "light";
|
|
279
|
+
}>>;
|
|
280
|
+
}, z.core.$strip>;
|
|
281
|
+
hidden: z.ZodBoolean;
|
|
282
|
+
id: z.ZodString;
|
|
283
|
+
isLocked: z.ZodBoolean;
|
|
284
|
+
isNsfw: z.ZodBoolean;
|
|
285
|
+
isSelfPost: z.ZodBoolean;
|
|
286
|
+
isSpoiler: z.ZodBoolean;
|
|
287
|
+
isStickied: z.ZodBoolean;
|
|
288
|
+
permalink: z.ZodURL;
|
|
289
|
+
saved: z.ZodBoolean;
|
|
290
|
+
score: z.ZodNumber;
|
|
291
|
+
shortId: z.ZodString;
|
|
292
|
+
subreddit: z.ZodString;
|
|
293
|
+
subredditId: z.ZodString;
|
|
294
|
+
title: z.ZodString;
|
|
295
|
+
upvoteRatio: z.ZodNumber;
|
|
296
|
+
url: z.ZodURL;
|
|
297
|
+
}, z.core.$strip>;
|
|
298
|
+
}, z.core.$strip>], "action">, z.ZodObject<{
|
|
299
|
+
action: z.ZodLiteral<"commentCreated">;
|
|
300
|
+
}, z.core.$strip>>;
|
|
301
|
+
};
|
|
302
|
+
readonly "reddit.subreddit.event": {
|
|
303
|
+
readonly configSchema: z.ZodObject<{
|
|
304
|
+
subreddit: z.ZodString;
|
|
305
|
+
}, z.core.$strip>;
|
|
306
|
+
readonly eventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
307
|
+
action: z.ZodLiteral<"commentCreated">;
|
|
308
|
+
comment: z.ZodObject<{
|
|
309
|
+
author: z.ZodNullable<z.ZodString>;
|
|
310
|
+
body: z.ZodString;
|
|
311
|
+
createdAt: z.ZodDate;
|
|
312
|
+
depth: z.ZodNumber;
|
|
313
|
+
distinguished: z.ZodNullable<z.ZodEnum<{
|
|
314
|
+
admin: "admin";
|
|
315
|
+
moderator: "moderator";
|
|
316
|
+
special: "special";
|
|
317
|
+
}>>;
|
|
318
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
319
|
+
id: z.ZodString;
|
|
320
|
+
isPostAuthor: z.ZodBoolean;
|
|
321
|
+
isStickied: z.ZodBoolean;
|
|
322
|
+
parentId: z.ZodString;
|
|
323
|
+
permalink: z.ZodURL;
|
|
324
|
+
postId: z.ZodString;
|
|
325
|
+
saved: z.ZodBoolean;
|
|
326
|
+
score: z.ZodNumber;
|
|
327
|
+
shortId: z.ZodString;
|
|
328
|
+
subreddit: z.ZodString;
|
|
329
|
+
}, z.core.$strip>;
|
|
330
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
331
|
+
action: z.ZodLiteral<"postCreated">;
|
|
332
|
+
post: z.ZodObject<{
|
|
333
|
+
archived: z.ZodBoolean;
|
|
334
|
+
author: z.ZodNullable<z.ZodString>;
|
|
335
|
+
body: z.ZodString;
|
|
336
|
+
commentCount: z.ZodNumber;
|
|
337
|
+
createdAt: z.ZodDate;
|
|
338
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
339
|
+
flair: z.ZodObject<{
|
|
340
|
+
backgroundColor: z.ZodNullable<z.ZodString>;
|
|
341
|
+
cssClass: z.ZodNullable<z.ZodString>;
|
|
342
|
+
templateId: z.ZodNullable<z.ZodString>;
|
|
343
|
+
text: z.ZodNullable<z.ZodString>;
|
|
344
|
+
textColor: z.ZodNullable<z.ZodEnum<{
|
|
345
|
+
dark: "dark";
|
|
346
|
+
light: "light";
|
|
347
|
+
}>>;
|
|
348
|
+
}, z.core.$strip>;
|
|
349
|
+
hidden: z.ZodBoolean;
|
|
350
|
+
id: z.ZodString;
|
|
351
|
+
isLocked: z.ZodBoolean;
|
|
352
|
+
isNsfw: z.ZodBoolean;
|
|
353
|
+
isSelfPost: z.ZodBoolean;
|
|
354
|
+
isSpoiler: z.ZodBoolean;
|
|
355
|
+
isStickied: z.ZodBoolean;
|
|
356
|
+
permalink: z.ZodURL;
|
|
357
|
+
saved: z.ZodBoolean;
|
|
358
|
+
score: z.ZodNumber;
|
|
359
|
+
shortId: z.ZodString;
|
|
360
|
+
subreddit: z.ZodString;
|
|
361
|
+
subredditId: z.ZodString;
|
|
362
|
+
title: z.ZodString;
|
|
363
|
+
upvoteRatio: z.ZodNumber;
|
|
364
|
+
url: z.ZodURL;
|
|
365
|
+
}, z.core.$strip>;
|
|
366
|
+
}, z.core.$strip>], "action">;
|
|
367
|
+
};
|
|
368
|
+
readonly "reddit.subreddit.post.created": {
|
|
369
|
+
readonly configSchema: z.ZodObject<{
|
|
370
|
+
subreddit: z.ZodString;
|
|
371
|
+
}, z.core.$strip>;
|
|
372
|
+
readonly eventSchema: z.ZodIntersection<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
373
|
+
action: z.ZodLiteral<"commentCreated">;
|
|
374
|
+
comment: z.ZodObject<{
|
|
375
|
+
author: z.ZodNullable<z.ZodString>;
|
|
376
|
+
body: z.ZodString;
|
|
377
|
+
createdAt: z.ZodDate;
|
|
378
|
+
depth: z.ZodNumber;
|
|
379
|
+
distinguished: z.ZodNullable<z.ZodEnum<{
|
|
380
|
+
admin: "admin";
|
|
381
|
+
moderator: "moderator";
|
|
382
|
+
special: "special";
|
|
383
|
+
}>>;
|
|
384
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
385
|
+
id: z.ZodString;
|
|
386
|
+
isPostAuthor: z.ZodBoolean;
|
|
387
|
+
isStickied: z.ZodBoolean;
|
|
388
|
+
parentId: z.ZodString;
|
|
389
|
+
permalink: z.ZodURL;
|
|
390
|
+
postId: z.ZodString;
|
|
391
|
+
saved: z.ZodBoolean;
|
|
392
|
+
score: z.ZodNumber;
|
|
393
|
+
shortId: z.ZodString;
|
|
394
|
+
subreddit: z.ZodString;
|
|
395
|
+
}, z.core.$strip>;
|
|
396
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
397
|
+
action: z.ZodLiteral<"postCreated">;
|
|
398
|
+
post: z.ZodObject<{
|
|
399
|
+
archived: z.ZodBoolean;
|
|
400
|
+
author: z.ZodNullable<z.ZodString>;
|
|
401
|
+
body: z.ZodString;
|
|
402
|
+
commentCount: z.ZodNumber;
|
|
403
|
+
createdAt: z.ZodDate;
|
|
404
|
+
editedAt: z.ZodNullable<z.ZodDate>;
|
|
405
|
+
flair: z.ZodObject<{
|
|
406
|
+
backgroundColor: z.ZodNullable<z.ZodString>;
|
|
407
|
+
cssClass: z.ZodNullable<z.ZodString>;
|
|
408
|
+
templateId: z.ZodNullable<z.ZodString>;
|
|
409
|
+
text: z.ZodNullable<z.ZodString>;
|
|
410
|
+
textColor: z.ZodNullable<z.ZodEnum<{
|
|
411
|
+
dark: "dark";
|
|
412
|
+
light: "light";
|
|
413
|
+
}>>;
|
|
414
|
+
}, z.core.$strip>;
|
|
415
|
+
hidden: z.ZodBoolean;
|
|
416
|
+
id: z.ZodString;
|
|
417
|
+
isLocked: z.ZodBoolean;
|
|
418
|
+
isNsfw: z.ZodBoolean;
|
|
419
|
+
isSelfPost: z.ZodBoolean;
|
|
420
|
+
isSpoiler: z.ZodBoolean;
|
|
421
|
+
isStickied: z.ZodBoolean;
|
|
422
|
+
permalink: z.ZodURL;
|
|
423
|
+
saved: z.ZodBoolean;
|
|
424
|
+
score: z.ZodNumber;
|
|
425
|
+
shortId: z.ZodString;
|
|
426
|
+
subreddit: z.ZodString;
|
|
427
|
+
subredditId: z.ZodString;
|
|
428
|
+
title: z.ZodString;
|
|
429
|
+
upvoteRatio: z.ZodNumber;
|
|
430
|
+
url: z.ZodURL;
|
|
431
|
+
}, z.core.$strip>;
|
|
432
|
+
}, z.core.$strip>], "action">, z.ZodObject<{
|
|
433
|
+
action: z.ZodLiteral<"postCreated">;
|
|
434
|
+
}, z.core.$strip>>;
|
|
435
|
+
};
|
|
436
|
+
};
|
|
437
|
+
/** Returns broad and semantic event types for one subreddit observation. */
|
|
438
|
+
/** @param event - Normalized post or comment event. */
|
|
439
|
+
export declare function getRedditSubredditEventTypes(event: z.output<typeof REDDIT_SUBREDDIT_EVENT_SCHEMA>): ("reddit.subreddit.post.created" | "reddit.subreddit.comment.created" | "reddit.subreddit.event")[];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { REDDIT_COMMENT_SCHEMA, REDDIT_MESSAGE_SCHEMA, REDDIT_POST_SCHEMA, REDDIT_SUBREDDIT_NAME_SCHEMA, } from "./schemas.js";
|
|
3
|
+
export const REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA = z.object({
|
|
4
|
+
subreddit: REDDIT_SUBREDDIT_NAME_SCHEMA,
|
|
5
|
+
});
|
|
6
|
+
export const REDDIT_ACCOUNT_TRIGGER_CONFIG_SCHEMA = z.object({});
|
|
7
|
+
export const REDDIT_SUBREDDIT_EVENT_SCHEMA = z.discriminatedUnion("action", [
|
|
8
|
+
z.object({
|
|
9
|
+
action: z.literal("commentCreated"),
|
|
10
|
+
comment: REDDIT_COMMENT_SCHEMA,
|
|
11
|
+
}),
|
|
12
|
+
z.object({ action: z.literal("postCreated"), post: REDDIT_POST_SCHEMA }),
|
|
13
|
+
]);
|
|
14
|
+
export const REDDIT_INBOX_EVENT_SCHEMA = z.object({
|
|
15
|
+
action: z.literal("inboxItemCreated"),
|
|
16
|
+
message: REDDIT_MESSAGE_SCHEMA,
|
|
17
|
+
});
|
|
18
|
+
export const REDDIT_MOD_QUEUE_EVENT_SCHEMA = z.discriminatedUnion("kind", [
|
|
19
|
+
z.object({ comment: REDDIT_COMMENT_SCHEMA, kind: z.literal("comment") }),
|
|
20
|
+
z.object({ kind: z.literal("post"), post: REDDIT_POST_SCHEMA }),
|
|
21
|
+
]);
|
|
22
|
+
export const redditTriggerContracts = {
|
|
23
|
+
"reddit.inbox.item.received": {
|
|
24
|
+
configSchema: REDDIT_ACCOUNT_TRIGGER_CONFIG_SCHEMA,
|
|
25
|
+
eventSchema: REDDIT_INBOX_EVENT_SCHEMA,
|
|
26
|
+
},
|
|
27
|
+
"reddit.modQueue.item.received": {
|
|
28
|
+
configSchema: REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA,
|
|
29
|
+
eventSchema: REDDIT_MOD_QUEUE_EVENT_SCHEMA,
|
|
30
|
+
},
|
|
31
|
+
"reddit.subreddit.comment.created": {
|
|
32
|
+
configSchema: REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA,
|
|
33
|
+
eventSchema: REDDIT_SUBREDDIT_EVENT_SCHEMA.and(z.object({ action: z.literal("commentCreated") })),
|
|
34
|
+
},
|
|
35
|
+
"reddit.subreddit.event": {
|
|
36
|
+
configSchema: REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA,
|
|
37
|
+
eventSchema: REDDIT_SUBREDDIT_EVENT_SCHEMA,
|
|
38
|
+
},
|
|
39
|
+
"reddit.subreddit.post.created": {
|
|
40
|
+
configSchema: REDDIT_SUBREDDIT_TRIGGER_CONFIG_SCHEMA,
|
|
41
|
+
eventSchema: REDDIT_SUBREDDIT_EVENT_SCHEMA.and(z.object({ action: z.literal("postCreated") })),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
/** Returns broad and semantic event types for one subreddit observation. */
|
|
45
|
+
/** @param event - Normalized post or comment event. */
|
|
46
|
+
export function getRedditSubredditEventTypes(event) {
|
|
47
|
+
return [
|
|
48
|
+
event.action === "postCreated"
|
|
49
|
+
? "reddit.subreddit.post.created"
|
|
50
|
+
: "reddit.subreddit.comment.created",
|
|
51
|
+
"reddit.subreddit.event",
|
|
52
|
+
];
|
|
53
|
+
}
|