-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport.ts
More file actions
203 lines (183 loc) · 5.3 KB
/
export.ts
File metadata and controls
203 lines (183 loc) · 5.3 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import { z } from "zod";
import { IterableDateTimeSchema } from "./common.js";
/**
* Export operation schemas and types
*/
export const GetExportJobsParamsSchema = z.object({
jobState: z
.string()
.optional()
.describe(
"Filter results to only include jobs in the specified state (enqueued, queued, running, completed, failed, cancelled, cancelling)"
),
});
export const GetExportFilesParamsSchema = z.object({
jobId: z
.number()
.describe("The ID of the export job (returned from startExportJob)"),
startAfter: z
.string()
.optional()
.describe(
"Skip file names up to and including this value. Use for paginating over the files in the export (e.g., 'file-1679086247925.csv')"
),
});
export const StartExportJobParamsSchema = z.object({
dataTypeName: z
.enum([
"emailSend",
"emailOpen",
"emailClick",
"hostedUnsubscribeClick",
"emailComplaint",
"emailBounce",
"emailSendSkip",
"pushSend",
"pushOpen",
"pushUninstall",
"pushBounce",
"pushSendSkip",
"inAppSend",
"inAppOpen",
"inAppClick",
"inAppClose",
"inAppDelete",
"inAppDelivery",
"inAppSendSkip",
"inAppRecall",
"inboxSession",
"inboxMessageImpression",
"smsSend",
"smsBounce",
"smsClick",
"smsReceived",
"smsSendSkip",
"webPushSend",
"webPushClick",
"webPushSendSkip",
"rcsSend",
"rcsSendSkip",
"emailSubscribe",
"emailUnSubscribe",
"purchase",
"customEvent",
"user",
"smsUsageInfo",
"embeddedSend",
"embeddedSendSkip",
"embeddedClick",
"embeddedReceived",
"embeddedImpression",
"embeddedSession",
"anonSession",
"journeyExit",
"whatsAppBounce",
"whatsAppClick",
"whatsAppReceived",
"whatsAppSeen",
"whatsAppSend",
"whatsAppSendSkip",
"whatsAppUsageInfo",
])
.describe(
"Data type name to export (e.g., 'user' for user data, 'emailSend' for email send events)"
),
outputFormat: z
.enum(["text/csv", "application/x-json-stream"])
.describe("Output format"),
startDateTime: IterableDateTimeSchema.optional().describe(
"Export events occurring or users updated after date and time inclusive"
),
endDateTime: IterableDateTimeSchema.optional().describe(
"Export events occurring or users updated before date and time exclusive"
),
campaignId: z
.number()
.optional()
.describe("Only export data from this campaign"),
delimiter: z.string().optional().describe("CSV file delimiter"),
omitFields: z
.string()
.optional()
.describe("Fields to omit from the export (comma separated)"),
onlyFields: z
.string()
.optional()
.describe("Only include these fields in the export (comma separated)"),
});
export const CancelExportJobParamsSchema = z.object({
jobId: z
.number()
.describe(
"The ID of the export job to cancel (returned from startExportJob)"
),
});
export type GetExportJobsParams = z.infer<typeof GetExportJobsParamsSchema>;
export type GetExportFilesParams = z.infer<typeof GetExportFilesParamsSchema>;
export type StartExportJobParams = z.infer<typeof StartExportJobParamsSchema>;
export type CancelExportJobParams = z.infer<typeof CancelExportJobParamsSchema>;
// Export job state enum - API uses PlayLowercaseJsonEnum so values are lowercase
export const ExportJobStateSchema = z.enum([
"enqueued",
"running",
"completed",
"failed",
"cancelling",
]);
// Export job schema - matches JobModel from API docs
export const ExportJobSchema = z.object({
id: z.number(),
dataTypeName: z.string(),
jobState: ExportJobStateSchema,
scheduledStartTime: z.string().optional(),
endTime: z.string().optional(),
bytesExported: z.number().optional(),
});
export type ExportJob = z.infer<typeof ExportJobSchema>;
export const StartExportJobResponseSchema = z.object({
jobId: z.number(),
message: z.string().optional(),
});
export type StartExportJobResponse = z.infer<
typeof StartExportJobResponseSchema
>;
// Response schema for getExportJobs
export const GetExportJobsResponseSchema = z.object({
jobs: z.array(ExportJobSchema),
});
export type GetExportJobsResponse = z.infer<typeof GetExportJobsResponseSchema>;
/**
* Individual export file with download URL
* Each file is up to 10MB in size
*/
export const ExportFileAndUrlSchema = z.object({
file: z.string(),
url: z.string(),
});
export type ExportFileAndUrl = z.infer<typeof ExportFileAndUrlSchema>;
/**
* Response from getExportFiles containing job status and file download URLs
* Files are added to the list as the export job runs
*/
export const GetExportFilesResponseSchema = z.object({
exportTruncated: z.boolean(),
files: z.array(ExportFileAndUrlSchema),
jobId: z.number(),
jobState: ExportJobStateSchema,
});
export type GetExportFilesResponse = z.infer<
typeof GetExportFilesResponseSchema
>;
/**
* Response from cancelExportJob
* The cancel endpoint returns a simple success response
*/
export const CancelExportJobResponseSchema = z
.object({
msg: z.string().optional(),
code: z.string().optional(),
})
.passthrough(); // Allow additional fields
export type CancelExportJobResponse = z.infer<
typeof CancelExportJobResponseSchema
>;