mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* Add tsconfig for 'coinbase-commerce-node' * Add coinbase-commerce-node type index. * Define init() method of CoinbaseCommerceNode client. * Add JSDoc to CoinbaseCommerceNode Client object. * Define scope for init() method of Client class. * Define CoinbaseCommerceNode Charge resource. * Define scope of save() method in CoinbaseCommerceNode Charge resource. * Add static create() method to CoinbaseCommerce Charge resource. * Export Charge resource in CoinbaseCommerceNode. * Add JSDoc to CoinbaseCommerce CreateAChargeResponse. * Remove 'ETC' from CryptoCurrency types in CoinbaseCommerce. * Correct GitHub link for ChargeResource JSDoc in CoinbaseCommerceNode. * Correct GitHub link for ChargeResource JSDoc in CoinbaseCommerceNode. * Add ChargeResource interface to CoinbaseCommerceNode. * Assign ChargeResource to Charge promises in CoinbaseCommerceNode. * Define response type for Charge callbacks in CoinbaseCommerceNode. * Add static list() method to CoinbaseCommerceNode Charge module. * Correct type for search arg in CoinbaseCommerceNode Charge list method. * Add retrieve() method to CoinbaseCommerceNode Charge resource. * Make promisified method callbacks optional in CoinbaseCommerceNode Charge resource. * Add all() method to CoinbaseCommerceNode Charge resource. * Abstract CoinbaseCommerceNode Charge resource to dedicated Resource interface. * Add tslint config to coinbase-commerce-node. * Make init() method of CoinbaseCommerceNode Client static. * Update Charge and Resource declarations for CoinbaseCommerceNode. * Add CoinbaseCommerceNode tests. * Correct formatting of coinbase-commerce-node tsconfig. * Correct type of local_price in coinbase-commerce-node. * Register CryptoPricing and addresses as partials in coinbase-commerce-node. * Correct payments.network type in coinbase-commerce-node. * Correct payments.value type in coinbase-commerce-node. * Add JSDoc to exampleReesponse in coinbase-commerce-node-tests. * Rename charge creation interface in coinbase-commerce-node. * Set local pricing type to FiatCurrency in coinbase-commerce-node. * Add CreateCheckout interface to coinbase-commerce-node. * Make CoinbaseCommerceNode requested_info property of CreateCheckout optional. * Add CheckoutResource interface to CoinbaseCommerceNode. * Add Checkout class to CoinbaseCommerceNode resources. * Add static updateById() method to CoinbaseCommerceNode Checkout resource. * Add static deleteById() method to CoinbaseCommerceNode Checkout resource. * Make callbacks of CoinbaseCommerceNode Checkout updateById and deleteById methods optional. * Add dynamic delete() method to CoinbaseCommerceNode Resource class. * Update return type of delete() method in CoinbaseCommerceNode Resource class. * Add insert() method to CoinbaseCommerceNode Resource class. * Add update() method to CoinbaseCommerceNode Resource class. * Add checkout create and checkout resource examples to CoinbaseCommerceNodeTests. * Assert that CoinbaseCommerceNode can create, get, update and delete Checkout resources. * Correct return types of Checkout and Charge resources of CoinbaseCommerceNode. * Correct declaration merging for Checkout and Charge resources in CoinbaseCommerceNode. * Correct type declarations for create responses in CoinbaseCommerceNode. * Export Pagination type in CoinbaseCommerceNode. * Test CoinbaseCommerceNode pagination. * Correct formatting of pagination example in CoinbaseCommerceNode tests. * Correct Pick<> in CoinbaseCommerceNode Pagination type. * Correct key name of previous URI in CoinbaseCommerceNode Pagination interface. * Test resource all() methods in CoinbaseCommerceNode. * Test CoinbaseCommerceNode resource object methods. * Update class JSDoc links in CoinbaseCommerceNode. * Add Event resource to CoinbaseCommerceNode. * Add Event tests to CoinbaseCommerceNode. * Merge EventResource with Event class in CoinbaseCommerceNode. * Correct CoinbaseCommerceNode event pagination tests. * Add JSDocs to CoinbaseCommerceNode event tests. * Correct data property type of CoinbaseCommerceNode EventResource. * Extend ChargeResource with CreateCharge interface in CoinbaseCommerceNode. * Define optional properties of ChargeResource in CoinbaseCommerceNode. * Add EXPIRED payment status type to CoinbaseCommerceNode. * Update eventResponseExample object in CoinbaseCommerceNode tests. * Add Webhook resource to CoinbaseCommerceNode. * Test Webhook verifySigHeader method in CoinbaseCommerceNode. * Disable "no-empty-interface" TSLint inspection for CoinbaseCommerceNode. * Correct TSLint errors in coinbase-commerce-node. * Disable no-void-expression for verifySigHeader() test in CoinbaseCommerceNode. * Set required TypeScript version to 2.8 for CoinbaseCommerceNode. * Register conditionally required local_price property for CreateCheckout and CreateCharge interfaces in CoinbaseCommerceNode. * Make 'local_price' optional for UpdateCheckout type in CoinbaseCommerceNode. * Remove 'local_price' property from CoinbaseCommerceNode ChargeBase. * Rename 'ChargeBase' to 'BaseCharge' in CoinbaseCommerceNode. * Use 'CreateCharge' not 'BaseCharge' for CoinbaseCommerceNode Charge class. * Move 'local_price' of BaseCheckout to CheckoutResource in CoinbaseCommerceNode. * Omit 'pricing_type' from CreateCheckout in UpdateCheckout type for CoinbaseCommerceNode. * Extend possible CoinbaseCommerceNode timeline context values.
608 lines
12 KiB
TypeScript
608 lines
12 KiB
TypeScript
// Type definitions for coinbase-commerce-node 1.0
|
|
// Project: https://github.com/coinbase/coinbase-commerce-node
|
|
// Definitions by: Jørgen Vatle <https://github.com/JorgenVatle>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
// TypeScript Version: 2.8
|
|
|
|
/**
|
|
* Client request options.
|
|
*/
|
|
interface Options {
|
|
url: string;
|
|
body: string;
|
|
method: 'GET' | 'POST' | 'DELETE' | 'PUT';
|
|
timeout: number;
|
|
headers: {
|
|
[key: string]: any;
|
|
'Content-Type': 'application/json';
|
|
'Accept': 'application/json';
|
|
'User-Agent': string;
|
|
'X-CC-Api-Key': string;
|
|
'X-CC-Version': string;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Omit a property from the given type.
|
|
*/
|
|
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
|
|
/**
|
|
* Node callback
|
|
*/
|
|
type Callback<T> = (error: any, response: T) => void;
|
|
|
|
/**
|
|
* Pagination callback.
|
|
*/
|
|
type PaginationCallback<T> = (error: any, response: T[], pagination: Pagination) => void;
|
|
|
|
/**
|
|
* Fiat currency.
|
|
*/
|
|
type FiatCurrency = 'USD' | 'GBP' | 'EUR' | string;
|
|
|
|
/**
|
|
* Crypto currency.
|
|
*/
|
|
type CryptoCurrency = 'BTC' | 'ETH' | 'BCH' | 'LTC';
|
|
|
|
/**
|
|
* Full crypto currency name.
|
|
*/
|
|
type CryptoName = 'bitcoin' | 'ethereum' | 'bitcoincash' | 'litecoin';
|
|
|
|
/**
|
|
* Pricing type.
|
|
*/
|
|
type PricingType = 'no_price' | 'fixed_price';
|
|
|
|
/**
|
|
* Timestamp string.
|
|
* ISO 8601
|
|
*/
|
|
type Timestamp = string;
|
|
|
|
/**
|
|
* Payment status.
|
|
*/
|
|
type PaymentStatus = 'NEW' | 'PENDING' | 'CONFIRMED' | 'UNRESOLVED' | 'RESOLVED' | 'EXPIRED';
|
|
|
|
/**
|
|
* Crypto pricing object.
|
|
*/
|
|
type CryptoPricing = {
|
|
[key in CryptoName]?: Price<CryptoCurrency>;
|
|
};
|
|
|
|
/**
|
|
* Key-value object.
|
|
*/
|
|
interface KeyVal {
|
|
[key: string]: any;
|
|
}
|
|
|
|
/**
|
|
* Price object.
|
|
*/
|
|
interface Price<Currency = CryptoCurrency | FiatCurrency> {
|
|
amount: string;
|
|
currency: Currency;
|
|
}
|
|
|
|
/**
|
|
* Pricing object.
|
|
*/
|
|
interface Pricing extends CryptoPricing {
|
|
local: Price<FiatCurrency>;
|
|
}
|
|
|
|
/**
|
|
* Pagination request.
|
|
*
|
|
* @link https://commerce.coinbase.com/docs/api/#pagination
|
|
*/
|
|
interface PaginationRequest {
|
|
/**
|
|
* Order of resources in the response.
|
|
*
|
|
* default: desc
|
|
*/
|
|
order?: 'asc' | 'desc';
|
|
|
|
/**
|
|
* Number of results per call.
|
|
*
|
|
* Accepted values: 0 - 100
|
|
* Default: 25
|
|
*/
|
|
limit?: number;
|
|
|
|
/**
|
|
* A cursor for use in pagination.
|
|
* This is a resource ID that defines your place in the list.
|
|
*/
|
|
starting_after?: string | null;
|
|
|
|
/**
|
|
* A cursor for use in pagination.
|
|
* This is a resource ID that defines your place in the list.
|
|
*/
|
|
ending_before?: string | null;
|
|
}
|
|
|
|
/**
|
|
* Pagination response.
|
|
*
|
|
* @link https://commerce.coinbase.com/docs/api/#pagination
|
|
*/
|
|
interface Pagination extends Pick<PaginationRequest, 'order' | 'starting_after' | 'ending_before' | 'limit'> {
|
|
total: number;
|
|
yielded: number;
|
|
previous_uri: null | string;
|
|
next_uri: null | string;
|
|
cursor_range: [string, string];
|
|
}
|
|
|
|
/**
|
|
* No price resource.
|
|
*/
|
|
interface NoPrice {
|
|
/**
|
|
* Pricing type.
|
|
*/
|
|
pricing_type: 'no_price';
|
|
}
|
|
|
|
/**
|
|
* Fixed price resource.
|
|
*/
|
|
interface FixedPrice {
|
|
/**
|
|
* Pricing type
|
|
*/
|
|
pricing_type: 'fixed_price';
|
|
|
|
/**
|
|
* Local price in fiat currency.
|
|
*/
|
|
local_price: Price<FiatCurrency>;
|
|
}
|
|
|
|
/**
|
|
* Base charge properties.
|
|
*/
|
|
interface BaseCharge {
|
|
/**
|
|
* Charge name.
|
|
* 100 characters or less.
|
|
*/
|
|
name: string;
|
|
|
|
/**
|
|
* More detailed description of the charge.
|
|
* 200 characters or less.
|
|
*/
|
|
description: string;
|
|
|
|
/**
|
|
* Charge pricing type.
|
|
*/
|
|
pricing_type: PricingType;
|
|
|
|
/**
|
|
* Optional key value pairs for your own use.
|
|
*/
|
|
metadata?: KeyVal;
|
|
|
|
/**
|
|
* Redirect the user to this URL on completion.
|
|
*/
|
|
redirect_url?: string;
|
|
|
|
/**
|
|
* Redirect the user to this URL on cancel.
|
|
*/
|
|
cancel_url?: string;
|
|
}
|
|
|
|
/**
|
|
* Create a charge.
|
|
*
|
|
* @link https://commerce.coinbase.com/docs/api/#charge-resource
|
|
*/
|
|
type CreateCharge = BaseCharge & (FixedPrice | NoPrice);
|
|
|
|
/**
|
|
* Charge creation response.
|
|
*
|
|
* @link https://commerce.coinbase.com/docs/api/#charge-resource
|
|
*/
|
|
interface ChargeResource extends BaseCharge {
|
|
/**
|
|
* Charge UUID
|
|
*/
|
|
id: string;
|
|
|
|
/**
|
|
* Resource name.
|
|
*/
|
|
resource: 'charge';
|
|
|
|
/**
|
|
* User fiendly primary key.
|
|
*/
|
|
code: string;
|
|
|
|
/**
|
|
* Charge image URL.
|
|
*/
|
|
logo_url?: string;
|
|
|
|
/**
|
|
* Hosted charge URL.
|
|
*/
|
|
hosted_url: string;
|
|
|
|
/**
|
|
* Charge creation time.
|
|
*/
|
|
created_at: Timestamp;
|
|
|
|
/**
|
|
* Charge expiration time.
|
|
*/
|
|
expires_at: Timestamp;
|
|
|
|
/**
|
|
* Charge confirmation time.
|
|
*/
|
|
confirmed_at?: Timestamp;
|
|
|
|
/**
|
|
* Associated checkout resource.
|
|
*/
|
|
checkout?: {
|
|
id: string;
|
|
};
|
|
|
|
/**
|
|
* Array of status update objects.
|
|
*/
|
|
timeline: Array<{
|
|
/**
|
|
* Timeline entry timestamp.
|
|
*/
|
|
time: Timestamp;
|
|
|
|
/**
|
|
* Timeline entry status.
|
|
*/
|
|
status: PaymentStatus;
|
|
|
|
/**
|
|
* Timeline entry context.
|
|
*/
|
|
context?: 'UNDERPAID' | 'OVERPAID' | 'DELAYED' | 'MULTIPLE' | 'MANUAL' | 'OTHER';
|
|
}>;
|
|
|
|
/**
|
|
* Charge metadata provided by you, the developer.
|
|
*/
|
|
metadata: KeyVal;
|
|
|
|
/**
|
|
* Charge price information object.
|
|
*/
|
|
pricing: Pricing;
|
|
|
|
/**
|
|
* Array of charge payment objects.
|
|
*/
|
|
payments: Array<{
|
|
network: CryptoName;
|
|
transaction_id: string;
|
|
status: PaymentStatus;
|
|
value: {
|
|
local: Price<FiatCurrency>;
|
|
crypto: Price<CryptoCurrency>;
|
|
};
|
|
block: {
|
|
height: number;
|
|
hash: string;
|
|
confirmations_accumulated: number;
|
|
confirmations_required: number;
|
|
}
|
|
}>;
|
|
|
|
/**
|
|
* Set of addresses associated with the charge.
|
|
*/
|
|
addresses: Partial<Record<CryptoName, string>>;
|
|
}
|
|
|
|
/**
|
|
* Base checkout properties.
|
|
*/
|
|
interface BaseCheckout {
|
|
/**
|
|
* Checkout name.
|
|
* 100 characters or less.
|
|
*/
|
|
name: string;
|
|
|
|
/**
|
|
* More detailed description.
|
|
* 200 characters or less.
|
|
*/
|
|
description: string;
|
|
|
|
/**
|
|
* Checkout pricing type.
|
|
*/
|
|
pricing_type: PricingType;
|
|
|
|
/**
|
|
* Information to collect from the customer.
|
|
*/
|
|
requested_info?: Array<'email' | 'name'>;
|
|
}
|
|
|
|
/**
|
|
* Create a checkout.
|
|
*
|
|
* @link https://commerce.coinbase.com/docs/api/#create-a-checkout
|
|
*/
|
|
type CreateCheckout = BaseCheckout & (FixedPrice | NoPrice);
|
|
|
|
/**
|
|
* Update a checkout resource.
|
|
*
|
|
* @link https://commerce.coinbase.com/docs/api/#update-a-checkout
|
|
*/
|
|
type UpdateCheckout = Omit<CreateCheckout, 'pricing_type'>;
|
|
|
|
/**
|
|
* Checkout Resource.
|
|
*
|
|
* @link https://commerce.coinbase.com/docs/api/#checkout-resource
|
|
*/
|
|
interface CheckoutResource extends BaseCheckout {
|
|
/**
|
|
* Checkout UUID.
|
|
*/
|
|
id: string;
|
|
|
|
/**
|
|
* Resource name.
|
|
*/
|
|
resource: 'checkout';
|
|
|
|
/**
|
|
* Checkout image URL.
|
|
*/
|
|
logo_url?: string;
|
|
|
|
/**
|
|
* Price in local fiat currency.
|
|
*/
|
|
local_price?: Price<FiatCurrency>;
|
|
}
|
|
|
|
/**
|
|
* Event Resource.
|
|
*
|
|
* @link
|
|
*/
|
|
interface EventResource {
|
|
/**
|
|
* Event UUID.
|
|
*/
|
|
id: string;
|
|
|
|
/**
|
|
* Resource name.
|
|
*/
|
|
resource: 'event';
|
|
|
|
/**
|
|
* Event type.
|
|
*/
|
|
type: 'charge:created' | 'charge:confirmed' | 'charge:failed' | 'charge:delayed' | 'charge:pending';
|
|
|
|
/**
|
|
* Event creation time.
|
|
*/
|
|
created_at: Timestamp;
|
|
|
|
/**
|
|
* API version of the `data` payload.
|
|
*/
|
|
api_version: string;
|
|
|
|
/**
|
|
* Event Payload.
|
|
* Resource of the associated object at the time of the event.
|
|
*/
|
|
data: ChargeResource | CheckoutResource;
|
|
}
|
|
|
|
/**
|
|
* Coinbase-Commerce-Node entry point.
|
|
*
|
|
* @link https://github.com/coinbase/coinbase-commerce-node#usage
|
|
*/
|
|
export namespace Client {
|
|
/**
|
|
* Setup client.
|
|
*/
|
|
function init(apiKey: string, baseApiUrl?: string, apiVersion?: string, timeout?: number): Options;
|
|
}
|
|
|
|
export namespace resources {
|
|
/**
|
|
* Resource object
|
|
* All coinbase-commerce-node resources implement the following static methods.
|
|
*
|
|
* @link https://github.com/coinbase/coinbase-commerce-node#documentation
|
|
*/
|
|
abstract class Resource<Request> {
|
|
/**
|
|
* Charge constructor.
|
|
*/
|
|
constructor(data: Request);
|
|
|
|
/**
|
|
* Save the current resource.
|
|
* Creates a new resource if it doesn't already exist in Coinbase Commerce's systems.
|
|
*/
|
|
save(callback?: Callback<this>): Promise<this>;
|
|
|
|
/**
|
|
* Delete the current resource.
|
|
*/
|
|
delete(callback?: Callback<this>): Promise<this>;
|
|
|
|
/**
|
|
* Save new resource to Coinbase Commerce.
|
|
*/
|
|
insert(callback?: Callback<this>): Promise<this>;
|
|
|
|
/**
|
|
* Update the current resource.
|
|
*/
|
|
update(callback?: Callback<this>): Promise<this>;
|
|
}
|
|
|
|
/**
|
|
* Merge CreateACharge with Charge class.
|
|
*/
|
|
interface Charge extends ChargeResource {}
|
|
|
|
/**
|
|
* Charge Class
|
|
*
|
|
* @link https://github.com/coinbase/coinbase-commerce-node#charges
|
|
*/
|
|
class Charge extends Resource<CreateCharge> {
|
|
/**
|
|
* Create a charge.
|
|
*/
|
|
static create(chargeData: CreateCharge, callback?: Callback<Charge>): Promise<Charge>;
|
|
|
|
/**
|
|
* List charges.
|
|
*/
|
|
static list(paginationOptions: PaginationRequest, callback?: PaginationCallback<Charge>): Promise<[Charge[], Pagination]>;
|
|
|
|
/**
|
|
* Fetch all charges.
|
|
*/
|
|
static all(paginationOptions: PaginationRequest, callback?: Callback<Charge[]>): Promise<Charge[]>;
|
|
|
|
/**
|
|
* Retrieve a charge by ID.
|
|
*/
|
|
static retrieve(chargeId: ChargeResource['id'], callback?: Callback<Charge>): Promise<Charge>;
|
|
}
|
|
|
|
/**
|
|
* Merge CheckoutResource with Checkout class.
|
|
*/
|
|
interface Checkout extends CheckoutResource {}
|
|
|
|
/**
|
|
* Checkout class.
|
|
*
|
|
* @link https://github.com/coinbase/coinbase-commerce-node#checkouts
|
|
*/
|
|
class Checkout extends Resource<CreateCheckout> {
|
|
/**
|
|
* Create a checkout.
|
|
*/
|
|
static create(checkoutData: CreateCheckout, callback?: Callback<Checkout>): Promise<Checkout>;
|
|
|
|
/**
|
|
* List checkouts.
|
|
*/
|
|
static list(paginationOptions: PaginationRequest, callback?: PaginationCallback<Checkout>): Promise<[Checkout[], Pagination]>;
|
|
|
|
/**
|
|
* Fetch all checkouts.
|
|
*/
|
|
static all(paginationOptions: PaginationRequest, callback?: Callback<Checkout[]>): Promise<Checkout[]>;
|
|
|
|
/**
|
|
* Retrieve a checkout by ID.
|
|
*/
|
|
static retrieve(checkoutId: CheckoutResource['id'], callback?: Callback<Checkout>): Promise<Checkout>;
|
|
|
|
/**
|
|
* Update a checkout by ID.
|
|
*/
|
|
static updateById(checkoutId: CheckoutResource['id'], update: UpdateCheckout, callback?: Callback<Checkout>): Promise<Checkout>;
|
|
|
|
/**
|
|
* Delete a checkout by ID.
|
|
*/
|
|
static deleteById(checkoutId: CheckoutResource['id'], callback?: Callback<Checkout>): Promise<Checkout>;
|
|
}
|
|
|
|
/**
|
|
* Merge EventResource with Event class.
|
|
*/
|
|
interface Event extends EventResource {}
|
|
|
|
/**
|
|
* Event class.
|
|
*
|
|
* @link https://github.com/coinbase/coinbase-commerce-node#events
|
|
*/
|
|
class Event extends Resource<EventResource> {
|
|
/**
|
|
* Retrieve a event by ID.
|
|
*/
|
|
static retrieve(eventId: EventResource['id'], callback?: Callback<Event>): Promise<Event>;
|
|
|
|
/**
|
|
* List events.
|
|
*/
|
|
static list(paginationOptions: PaginationRequest, callback?: PaginationCallback<Event>): Promise<[Event[], Pagination]>;
|
|
|
|
/**
|
|
* Fetch all events.
|
|
*/
|
|
static all(paginationOptions: PaginationRequest, callback?: Callback<Event[]>): Promise<Event[]>;
|
|
}
|
|
|
|
/**
|
|
* Webhook class.
|
|
*
|
|
* @link https://github.com/coinbase/coinbase-commerce-node#webhooks
|
|
*/
|
|
namespace Webhook {
|
|
/**
|
|
* Verify a signature header.
|
|
*
|
|
* @link https://github.com/coinbase/coinbase-commerce-node#verify-signature-header
|
|
*/
|
|
function verifySigHeader(rawBody: string, signature: string, sharedSecret: string): void;
|
|
}
|
|
|
|
export {
|
|
Webhook,
|
|
Event,
|
|
Charge,
|
|
Checkout,
|
|
};
|
|
}
|
|
|
|
export {
|
|
Pagination,
|
|
ChargeResource,
|
|
CheckoutResource,
|
|
CreateCheckout,
|
|
EventResource,
|
|
CreateCharge,
|
|
};
|