npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@1amageek/tradable

v0.27.0

Published

Cloud Firestore model framework for TypeScript - Google

Readme

tradable.ts

Installation

npm add @1amageek/tradable

Usage

You need to implement Tradable Inteface in the object associated with the user.Also, you prepare objects that implement other protocols.

PaymentDelegate

In order to process payment with tradabe it is necessary to implement delegate. This is an example of paying with Stripe.

export const stripe = new Stripe(Config.STRIPE_API_KEY)
export class StripePaymentDelegate implements tradable.TransactionDelegate {

    async payment<U extends tradable.OrderItemProtocol, T extends tradable.OrderProtocol<U>>(currency: tradable.Currency, amount: number, order: T, options: tradable.PaymentOptions) {
        const idempotency_key = order.id
        const data: Stripe.charges.IChargeCreationOptions = {
            amount: order.amount,
            currency: order.currency,
            description: `Charge for user/${order.purchasedBy}`
        }

        if (options) {
            if (options.customer) {
                data.customer = options.customer
            }
            if (options.source) {
                data.source = options.source
            }
        }
        data.customer = Config.STRIPE_CUS_TOKEN
        data.source = Config.STRIPE_CORD_TOKEN

        try {
            const charge = await stripe.charges.create(data, {
                idempotency_key: idempotency_key
            })
            return charge
        } catch (error) {
            console.log(error)
            throw error
        }
    }

    async refund<U extends tradable.OrderItemProtocol, T extends tradable.OrderProtocol<U>>(currency: tradable.Currency, amount: number, order: T, options: tradable.PaymentOptions, reason?: string | undefined) {
        const transactionResults = order.transactionResults
        const transactionResult = transactionResults[transactionResults.length - 1]
        const stripeCharge = transactionResult["stripe"] as Stripe.charges.ICharge
        const charegeID = stripeCharge.id
        const idempotency_key = `refund:${order.id}`

        let data: Stripe.refunds.IRefundCreationOptions = {}
        data.amount = amount
        if (reason) {
            data.reason = reason
        }

        try {
            return await stripe.charges.refund(charegeID, data, {
                idempotency_key: idempotency_key
            })
        } catch (error) {
            throw error
        }
    }

    async partRefund<U extends tradable.OrderItemProtocol, T extends tradable.OrderProtocol<U>>(currency: tradable.Currency, amount: number, order: T, orderItem: U, options: tradable.PaymentOptions, reason?: string | undefined) {
        const transactionResults = order.transactionResults
        const transactionResult = transactionResults[transactionResults.length - 1]

        const stripeCharge = transactionResult["stripe"] as Stripe.charges.ICharge
        const charegeID = stripeCharge.id
        const idempotency_key = `refund:${orderItem.id}`

        let data: Stripe.refunds.IRefundCreationOptions = {}
        data.amount = amount
        if (reason) {
            data.reason = reason
        }

        try {
            return await stripe.charges.refund(charegeID, data, {
                idempotency_key: idempotency_key
            })
        } catch (error) {
            throw error
        }
    }

    async transfer<U extends tradable.OrderItemProtocol, T extends tradable.OrderProtocol<U>,
        V extends tradable.BalanceTransactionProtocol, W extends tradable.AccountProtocol<V>>
        (currency: tradable.Currency, amount: number, order: T, toAccount: W, options: tradable.TransferOptions) {
        const idempotency_key = order.id
        const destination = toAccount.accountInformation['stripe']['id']
        const data: Stripe.transfers.ITransferCreationOptions = {
            amount: order.amount,
            currency: order.currency,
            transfer_group: order.id,
            destination: destination
        }

        try {
            const transfer = await stripe.transfers.create(data, {
                idempotency_key: idempotency_key
            })
            return transfer
        } catch (error) {
            console.log(error)
            throw error
        }
    }

    async transferCancel<U extends tradable.OrderItemProtocol, T extends tradable.OrderProtocol<U>>(currency: tradable.Currency, amount: number, order: T, options: tradable.TransferOptions, reason?: string | undefined) {
        throw new Error("Method not implemented.");
    }

    async payout(currency: tradable.Currency, amount: number, accountID: string, options: tradable.PayoutOptions) {
        throw new Error("Method not implemented.");
    }

    async payoutCancel(currency: tradable.Currency, amount: number, accountID: string, options: tradable.PayoutOptions) {
        throw new Error("Method not implemented.");
    }
}

Tradable

Request implementation of protocol required for trading.

UserProtocol

Request implementation of the protocol of the user who can place an order.

ProductProtocol

Request implementation of protocol of product information.

SKUShardProtocol

Request implementation of SKUShard protocol.

SKUProtocol

Request implementation of SKU protocol.

OrderProtocol

Request implementation of Order protocol.

OrderItemProtocol

Request implementation of OrderItem protocol.