Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

devhsoj/unclesam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unclesam

unclesam is an unofficial TypeScript API built for querying sam.gov. This package allows you to quickly & easily retrieve government contracts via a modern, typed API.

How to install

Requirements: node/npm

npm i @devhsoj/unclesam

Examples

Querying active contracts matching all words

import { ContractSearch, ContractQueryMode } from 'unclesam';

(async () => {
    const search = new ContractSearch({
        query: ['software', 'network'],
        queryMode: ContractQueryMode.ALL,
        active: true
    });

    // .list() goes through each page recursively (by default, 1000 records at a time) and returns an array of Contract objects
    const contracts = await search.list();

    console.log(contracts); // [{ title: 'Example Title', ... }]
})();

With pagination, retrieve the ten most recently modified contract opportunities containing the word 'defense'

import { ContractSearch, ContractQueryMode, ContractQueryIndex, ContractSearchSortOptions } from 'unclesam';

(async () => {
    // Using the static class method .search() on ContractSearch, allows you to directly interface with the sam.gov paginated API
    const res = await ContractSearch.search({
        page: 0,
        pageSize: 10,
        query: 'defense',
        active: true,
        queryMode: ContractQueryMode.EXACT,
        index: ContractQueryIndex.Opportunities,
        sort: ContractSearchSortOptions.dateModifiedDesc
    });

    // If there is an error on the sam.gov API, output the error
    if (res.error) {
        console.trace(res.error);
    } else {
        if (!res.contracts || res.contracts?.length === 0) {
            console.log('No contracts found!');
        } else {
            console.log(res.contracts);
        }
    }
})();

About

This project was created to get more of an understanding of creating a library in TypeScript :)

Releases

No releases published

Packages

No packages published