JSPM

@devhsoj/unclesam

0.0.4
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 13
    • Score
      100M100P100Q40933F
    • License MIT

    Unofficial API for sam.gov

    Package Exports

    • @devhsoj/unclesam
    • @devhsoj/unclesam/dist/index.js

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@devhsoj/unclesam) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    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 :)