MCPcopy
hub / github.com/msgbyte/tianji / sendSingleRequest

Function sendSingleRequest

packages/client-sdk/src/application.ts:236–261  ·  view source on GitHub ↗

* Send single request to Tianji application API (fallback when batch is disabled)

(
  serverUrl: string,
  type: 'event' | 'identify',
  payload: ApplicationEventPayload | ApplicationIdentifyPayload
)

Source from the content-addressed store, hash-verified

234 * Send single request to Tianji application API (fallback when batch is disabled)
235 */
236async function sendSingleRequest(
237 serverUrl: string,
238 type: 'event' | 'identify',
239 payload: ApplicationEventPayload | ApplicationIdentifyPayload
240): Promise<void> {
241 try {
242 const response = await fetch(`${serverUrl}/api/application/send`, {
243 method: 'POST',
244 headers: {
245 'Content-Type': 'application/json',
246 },
247 body: JSON.stringify({
248 type,
249 payload,
250 }),
251 });
252
253 if (!response.ok) {
254 const errorText = await response.text();
255 throw new Error(`Failed to send application ${type}: ${errorText}`);
256 }
257 } catch (error) {
258 console.error(`Error sending application ${type}:`, error);
259 return; // As event tracking SDK, should not throw error which maybe cause crash
260 }
261}
262
263/**
264 * Send batch request to Tianji application API

Callers 1

initApplicationFunction · 0.70

Calls 3

errorMethod · 0.80
textMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected