11"use strict" ;
2- var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
3- return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
4- } ;
52Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
63exports . Rekor = void 0 ;
74/*
@@ -19,37 +16,31 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1916See the License for the specific language governing permissions and
2017limitations under the License.
2118*/
22- const make_fetch_happen_1 = __importDefault ( require ( "make-fetch-happen" ) ) ;
23- const util_1 = require ( "../util" ) ;
24- const error_1 = require ( "./error" ) ;
19+ const fetch_1 = require ( "./fetch" ) ;
2520/**
2621 * Rekor API client.
2722 */
2823class Rekor {
2924 constructor ( options ) {
30- this . fetch = make_fetch_happen_1 . default . defaults ( {
31- retry : options . retry ,
32- timeout : options . timeout ,
33- headers : {
34- Accept : 'application/json' ,
35- 'User-Agent' : util_1 . ua . getUserAgent ( ) ,
36- } ,
37- } ) ;
38- this . baseUrl = options . baseURL ;
25+ this . options = options ;
3926 }
4027 /**
4128 * Create a new entry in the Rekor log.
4229 * @param propsedEntry {ProposedEntry} Data to create a new entry
4330 * @returns {Promise<Entry> } The created entry
4431 */
4532 async createEntry ( propsedEntry ) {
46- const url = `${ this . baseUrl } /api/v1/log/entries` ;
47- const response = await this . fetch ( url , {
48- method : 'POST' ,
49- headers : { 'Content-Type' : 'application/json' } ,
33+ const { baseURL, timeout, retry } = this . options ;
34+ const url = `${ baseURL } /api/v1/log/entries` ;
35+ const response = await ( 0 , fetch_1 . fetchWithRetry ) ( url , {
36+ headers : {
37+ 'Content-Type' : 'application/json' ,
38+ Accept : 'application/json' ,
39+ } ,
5040 body : JSON . stringify ( propsedEntry ) ,
41+ timeout,
42+ retry,
5143 } ) ;
52- await ( 0 , error_1 . checkStatus ) ( response ) ;
5344 const data = await response . json ( ) ;
5445 return entryFromResponse ( data ) ;
5546 }
@@ -59,44 +50,18 @@ class Rekor {
5950 * @returns {Promise<Entry> } The retrieved entry
6051 */
6152 async getEntry ( uuid ) {
62- const url = `${ this . baseUrl } /api/v1/log/entries/${ uuid } ` ;
63- const response = await this . fetch ( url ) ;
64- await ( 0 , error_1 . checkStatus ) ( response ) ;
65- const data = await response . json ( ) ;
66- return entryFromResponse ( data ) ;
67- }
68- /**
69- * Search the Rekor log index for entries matching the given query.
70- * @param opts {SearchIndex} Options to search the Rekor log
71- * @returns {Promise<string[]> } UUIDs of matching entries
72- */
73- async searchIndex ( opts ) {
74- const url = `${ this . baseUrl } /api/v1/index/retrieve` ;
75- const response = await this . fetch ( url , {
76- method : 'POST' ,
77- body : JSON . stringify ( opts ) ,
78- headers : { 'Content-Type' : 'application/json' } ,
53+ const { baseURL, timeout, retry } = this . options ;
54+ const url = `${ baseURL } /api/v1/log/entries/${ uuid } ` ;
55+ const response = await ( 0 , fetch_1 . fetchWithRetry ) ( url , {
56+ method : 'GET' ,
57+ headers : {
58+ Accept : 'application/json' ,
59+ } ,
60+ timeout,
61+ retry,
7962 } ) ;
80- await ( 0 , error_1 . checkStatus ) ( response ) ;
8163 const data = await response . json ( ) ;
82- return data ;
83- }
84- /**
85- * Search the Rekor logs for matching the given query.
86- * @param opts {SearchLogQuery} Query to search the Rekor log
87- * @returns {Promise<Entry[]> } List of matching entries
88- */
89- async searchLog ( opts ) {
90- const url = `${ this . baseUrl } /api/v1/log/entries/retrieve` ;
91- const response = await this . fetch ( url , {
92- method : 'POST' ,
93- body : JSON . stringify ( opts ) ,
94- headers : { 'Content-Type' : 'application/json' } ,
95- } ) ;
96- await ( 0 , error_1 . checkStatus ) ( response ) ;
97- const rawData = await response . json ( ) ;
98- const data = rawData . map ( ( d ) => entryFromResponse ( d ) ) ;
99- return data ;
64+ return entryFromResponse ( data ) ;
10065 }
10166}
10267exports . Rekor = Rekor ;
0 commit comments