export type SidetreeCreateOperation = {type?: 'create' | undefined, suffix_data?: string | undefined, delta?: string | undefined}; export type SidetreeUpdateOperation = {type?: 'update' | undefined, did_suffix?: string | undefined, update_reveal_value?: string | undefined, delta?: string | undefined, signed_data?: string | undefined}; export type SidetreeRecoverOperation = {type?: 'recover' | undefined, did_suffix?: string | undefined, recovery_reveal_value?: string | undefined, delta?: string | undefined, signed_data?: string | undefined}; export type SidetreeDeactivateOperation = {type?: 'deactivate' | undefined, did_suffix?: string | undefined, recovery_reveal_value?: string | undefined, signed_data?: string | undefined}; export type CreateApiOperationsArgs = {body: SidetreeCreateOperation | SidetreeUpdateOperation | SidetreeRecoverOperation | SidetreeDeactivateOperation}; export type CreateApiOperationsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Writes an Operation to Sidetree. * * POST /operations */ export const createApiOperations = async (args: CreateApiOperationsArgs, options?: CreateApiOperationsOptions) => { const {baseUrl = "https://virtserver.swaggerhub.com/sidetree/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/operations${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };