MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / registerEndpoint

Method registerEndpoint

packages/cli/src/utils/triggerApi.ts:147–201  ·  view source on GitHub ↗
(options: CreateEndpointOptions)

Source from the content-addressed store, hash-verified

145 }
146
147 async registerEndpoint(options: CreateEndpointOptions): Promise<EndpointResponse> {
148 const response = await fetch(`${this.baseUrl}/api/v1/endpoints`, {
149 method: "POST",
150 headers: {
151 "Content-Type": "application/json",
152 Authorization: `Bearer ${this.apiKey}`,
153 },
154 body: JSON.stringify(options),
155 });
156
157 if (!response.ok) {
158 const rawBody = await response.text();
159
160 if (typeof rawBody === "string") {
161 const rawJson = safeJsonParse(rawBody);
162
163 if (!rawJson) {
164 return {
165 ok: false,
166 error: "An unknown issue occurred when registering with Trigger.dev",
167 retryable: true,
168 };
169 }
170
171 const parsedJson = z.object({ error: z.string() }).safeParse(rawJson);
172
173 if (!parsedJson.success) {
174 return {
175 ok: false,
176 error: "An unknown issue occurred when registering with Trigger.dev",
177 retryable: true,
178 };
179 }
180
181 return {
182 ok: false,
183 error: parsedJson.data.error,
184 retryable: RETRYABLE_PATTERN.test(parsedJson.data.error),
185 };
186 } else {
187 return {
188 ok: false,
189 error: "An unknown issue occurred when registering with Trigger.dev",
190 retryable: true,
191 };
192 }
193 }
194
195 const data = await response.json();
196
197 return {
198 ok: true,
199 data: data as any as EndpointData,
200 };
201 }
202
203 async getEndpointIndex(indexId: string) {
204 const response = await fetch(`${this.baseUrl}/api/v1/endpointindex/${indexId}`, {

Callers 1

refreshEndpointFunction · 0.45

Calls 5

testMethod · 0.80
jsonMethod · 0.80
fetchFunction · 0.70
safeJsonParseFunction · 0.70
textMethod · 0.65

Tested by

no test coverage detected