All files / src/modules stewardship.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 3833x   33x 33x   33x               33x 1x             33x       1x   1x           1x   1x    
import { Types } from 'cafe-utility'
import type { BeeRequestOptions } from '../types'
import { http } from '../utils/http'
import { BatchId, Reference } from '../utils/typed-bytes'
 
const stewardshipEndpoint = 'stewardship'
 
/**
 * Reupload locally pinned data
 * @param requestOptions Options for making requests
 * @param reference
 * @throws BeeResponseError if not locally pinned or invalid data
 */
export async function reupload(requestOptions: BeeRequestOptions, stamp: BatchId, reference: Reference): Promise<void> {
  await http(requestOptions, {
    method: 'put',
    url: `${stewardshipEndpoint}/${reference}`,
    headers: { 'swarm-postage-batch-id': stamp.toHex() },
  })
}
 
export async function isRetrievable(
  requestOptions: BeeRequestOptions,
  reference: Reference | Uint8Array | string,
): Promise<boolean> {
  reference = new Reference(reference)
 
  const response = await http<unknown>(requestOptions, {
    method: 'get',
    responseType: 'json',
    url: `${stewardshipEndpoint}/${reference}`,
  })
 
  const body = Types.asObject(response.data, { name: 'response.data' })
 
  return Types.asBoolean(body.isRetrievable, { name: 'isRetrievable' })
}