github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/web/src/tiltApi.ts (about) 1 import { Moment } from "moment" 2 3 // apiserver's date format time is _extremely_ strict to the point that it requires the full 4 // six-decimal place microsecond precision, e.g. .000Z will be rejected, it must be .000000Z 5 // so use an explicit RFC3339 moment format to ensure it passes 6 export function apiTimeFormat(moment: Moment): string { 7 return moment.format("YYYY-MM-DDTHH:mm:ss.SSSSSSZ") 8 } 9 10 export async function tiltApiPut<T extends { metadata?: Proto.v1ObjectMeta }>( 11 kindPlural: string, 12 subResource: string, 13 obj: T 14 ) { 15 if (!obj.metadata?.name) { 16 throw "object has no name" 17 } 18 const url = `/proxy/apis/tilt.dev/v1alpha1/${kindPlural}/${obj.metadata.name}/${subResource}` 19 const resp = await fetch(url, { 20 method: "PUT", 21 headers: { 22 Accept: "application/json", 23 "Content-Type": "application/json", 24 }, 25 body: JSON.stringify(obj), 26 }) 27 if (resp && resp.status !== 200) { 28 const body = await resp.text() 29 throw `error updating object in api: ${body}` 30 } 31 }