From cdfc8e91cb222ed735cbc20eeaec0214432b9877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Vatle?= Date: Wed, 15 May 2019 00:45:52 +0300 Subject: [PATCH] [coinbase-commerce-node] Add type definitions for coinbase-commerce-node (#35415) * 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. --- .../coinbase-commerce-node-tests.ts | 316 +++++++++ types/coinbase-commerce-node/index.d.ts | 607 ++++++++++++++++++ types/coinbase-commerce-node/tsconfig.json | 23 + types/coinbase-commerce-node/tslint.json | 6 + 4 files changed, 952 insertions(+) create mode 100644 types/coinbase-commerce-node/coinbase-commerce-node-tests.ts create mode 100644 types/coinbase-commerce-node/index.d.ts create mode 100644 types/coinbase-commerce-node/tsconfig.json create mode 100644 types/coinbase-commerce-node/tslint.json diff --git a/types/coinbase-commerce-node/coinbase-commerce-node-tests.ts b/types/coinbase-commerce-node/coinbase-commerce-node-tests.ts new file mode 100644 index 0000000000..ed9ae55528 --- /dev/null +++ b/types/coinbase-commerce-node/coinbase-commerce-node-tests.ts @@ -0,0 +1,316 @@ +import { + Pagination, + ChargeResource, + CheckoutResource, + CreateCheckout, + Client, + EventResource, + CreateCharge, + resources as Resource +} from 'coinbase-commerce-node'; + +const Checkout = Resource.Checkout; +const Charge = Resource.Charge; +const Event = Resource.Event; +const Webhook = Resource.Webhook; + +/** + * Initialize client. + */ +Client.init('some-api-key', 'http://example.com', 'v0.0.1', 2000); + +/** + * Prebuilt example request + * + * @link https://commerce.coinbase.com/docs/api/#create-a-charge + */ +const chargeCreateExample: CreateCharge = { + name: 'The Sovereign Individual', + description: 'Mastering the Transition to the Information Age', + local_price: { + amount: '100.00', + currency: 'USD' + }, + pricing_type: 'fixed_price', + metadata: { + customer_id: 'id_1005', + customer_name: 'Satoshi Nakamoto' + }, + redirect_url: 'https://charge/completed/page', + cancel_url: 'https://charge/canceled/page', +}; + +/** + * Prebuilt example response. + * + * @link https://commerce.coinbase.com/docs/api/#charge-resource + */ +const chargeResponseExample: ChargeResource = { + id: 'f765421f2-1451-fafb-a513-aac6c819fba9', + resource: 'charge', + code: '66BEOV2A', + name: 'The Sovereign Individual', + description: 'Mastering the Transition to the Information Age', + logo_url: 'https://commerce.coinbase.com/charges/ybjknds.png', + hosted_url: 'https://commerce.coinbase.com/charges/66BEOV2A', + created_at: '2017-01-31T20:49:02Z', + expires_at: '2017-01-31T21:49:02Z', + confirmed_at: '2017-01-31T20:50:02Z', + checkout: { + id: 'a76721f2-1611-48fb-a513-aac6c819a9d6' + }, + timeline: [ + { + time: '2017-01-31T20:49:02Z', + status: 'NEW' + }, + { + time: '2017-01-31T20:50:02Z', + status: 'PENDING' + }, + { + time: '2017-01-31T20:50:02Z', + status: 'CONFIRMED' + }, + { + time: '2017-01-31T20:50:02Z', + status: 'UNRESOLVED', + context: 'UNDERPAID' + }, + { + time: '2017-01-31T20:50:02Z', + status: 'RESOLVED' + } + ], + metadata: {}, + pricing_type: 'fixed_price', + pricing: { + local: { amount: '100.00', currency: 'USD' }, + bitcoin: { amount: '1.00', currency: 'BTC' }, + ethereum: { amount: '10.00', currency: 'ETH' } + }, + payments: [ + { + network: 'ethereum', + transaction_id: '0xe02fead885c3e4019945428ed54d094247bada2d0ac41b08fce7ce137bf29587', + status: 'CONFIRMED', + value: { + local: { amount: '100.0', currency: 'USD' }, + crypto: { amount: '10.00', currency: 'ETH' } + }, + block: { + height: 100, + hash: '0xe02fead885c3e4019945428ed54d094247bada2d0ac41b08fce7ce137bf29587', + confirmations_accumulated: 8, + confirmations_required: 2 + } + } + ], + addresses: { + bitcoin: 'mymZkiXhQNd6VWWG7VGSVdDX9bKmviti3U', + ethereum: '0x419f91df39951fd4e8acc8f1874b01c0c78ceba6' + } +}; + +/** + * Create an example charge and fetch the same charge by its ID. + */ +Charge.create(chargeCreateExample).then((response: Resource.Charge) => { + return Charge.retrieve(response.id); +}).then((response) => { + const id: string = response.id; + const resource: 'charge' = response.resource; +}); + +/** + * List out all available charges. + */ +Charge.list({}).then(([list, paginationInfo]) => { + const results: number = paginationInfo.total; + + list.forEach((entry) => { + const id: string = entry.id; + const resource: 'charge' = entry.resource; + }); +}); + +/** + * Fetch all available charges. + */ +Charge.all({}).then((list) => { + list.forEach((entry) => { + const id: string = entry.id; + const resource: 'charge' = entry.resource; + }); +}); + +/** + * insert, save, update and delete a Charge resource. + */ +new Charge(chargeCreateExample).insert().then((charge) => { + const resource: 'charge' = charge.resource; + charge.name = 'some-new-name'; + + return charge.save(); +}).then((charge) => { + const resource: 'charge' = charge.resource; + charge.description = 'some-new-description'; + + return charge.update(); +}).then((charge) => { + const resource: 'charge' = charge.resource; + + return charge.delete(); +}).then((charge) => { + const resource: 'charge' = charge.resource; +}); + +/** + * Checkout create example. + * + * @link https://commerce.coinbase.com/docs/api/#create-a-checkout + */ +const checkoutCreateExample: CreateCheckout = { + name: 'The Sovereign Individual', + description: 'Mastering the Transition to the Information Age', + local_price: { + amount: '100.00', + currency: 'USD' + }, + pricing_type: 'fixed_price', + requested_info: ['email'] +}; + +/** + * Checkout resource example + * + * @link https://commerce.coinbase.com/docs/api/#checkout-resource + */ +const checkoutResponseExample: CheckoutResource = { + id: '30934862-d980-46cb-9402-43c81b0cabd5', + resource: 'checkout', + name: 'The Sovereign Individual', + description: 'Mastering the Transition to the Information Age', + logo_url: 'https://commerce.coinbase.com/charges/ybjknds.png', + requested_info: ['name', 'email'], + pricing_type: 'fixed_price', + local_price: { + amount: '100.0', + currency: 'USD' + } +}; + +/** + * Create, get and update and delete a Checkout resource. + */ +Checkout.create(checkoutCreateExample).then((response: Resource.Checkout) => { + return Checkout.retrieve(response.id); +}).then((response) => { + return Checkout.updateById(response.id, { name: 'some-name', description: 'some-description' }); +}).then((response) => { + return Checkout.deleteById(response.id); +}); + +/** + * insert, save, update and delete a Checkout resource. + */ +new Checkout(checkoutCreateExample).insert().then((checkout) => { + const resource: 'checkout' = checkout.resource; + checkout.name = 'some-new-name'; + + return checkout.save(); +}).then((checkout) => { + const resource: 'checkout' = checkout.resource; + checkout.description = 'some-new-description'; + + return checkout.update(); +}).then((checkout) => { + const resource: 'checkout' = checkout.resource; + + return checkout.delete(); +}).then((checkout) => { + const resource: 'checkout' = checkout.resource; +}); + +/** + * List out all available checkouts. + */ +Checkout.list({}).then(([list, paginationInfo]) => { + const results: number = paginationInfo.total; + + list.forEach((entry) => { + const id: string = entry.id; + const resource: 'checkout' = entry.resource; + }); +}); + +/** + * Fetch all available checkouts. + */ +Checkout.all({}).then((list) => { + list.forEach((entry) => { + const id: string = entry.id; + const resource: 'checkout' = entry.resource; + }); +}); + +/** + * Event resource. + * + * @link https://commerce.coinbase.com/docs/api/#event-resource + */ +const eventResponseExample: EventResource = { + id: '24934862-d980-46cb-9402-43c81b0cdba6', + resource: 'event', + type: 'charge:created', + api_version: '2018-03-22', + created_at: '2017-01-31T20:49:02Z', + data: chargeResponseExample, +}; + +/** + * Retrieve an event by ID. + */ +Event.retrieve(eventResponseExample.id).then((event) => { + const type: 'event' = event.resource; +}); + +/** + * Get a paginated list of events. + */ +Event.list({}).then(([events, paginationInfo]) => { + const type: 'event' = events[0].resource; + const results: number = paginationInfo.total; +}); + +/** + * Fetch all available events. + */ +Event.all({}).then((events) => { + const type: 'event' = events[0].resource; +}); + +/** + * Pagination example. + * + * @link https://commerce.coinbase.com/docs/api/#pagination + */ +const paginationExample: Pagination = { + order: 'desc', + starting_after: null, + ending_before: null, + total: 25, + yielded: 20, + limit: 20, + previous_uri: null, + next_uri: 'https://api.commerce.coinbase.com/checkouts?limit=20&starting_after=fb6721f2-1622-48f0-b713-aac6c819b67a', + cursor_range: ['a76721f2-1611-48fb-a513-aac6c819a9d6', 'fb6721f2-1622-48f0-b713-aac6c819b67a'] +}; + +/** + * Verify a signature header. + * + * @link https://github.com/coinbase/coinbase-commerce-node#verify-signature-header + */ +// tslint:disable-next-line:void-return no-void-expression +const shouldBeVoid: void = Webhook.verifySigHeader(JSON.stringify(eventResponseExample), 'some-signature', 'my-secret'); diff --git a/types/coinbase-commerce-node/index.d.ts b/types/coinbase-commerce-node/index.d.ts new file mode 100644 index 0000000000..c73ec1f7f9 --- /dev/null +++ b/types/coinbase-commerce-node/index.d.ts @@ -0,0 +1,607 @@ +// Type definitions for coinbase-commerce-node 1.0 +// Project: https://github.com/coinbase/coinbase-commerce-node +// Definitions by: Jørgen Vatle +// 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 = Pick>; + +/** + * Node callback + */ +type Callback = (error: any, response: T) => void; + +/** + * Pagination callback. + */ +type PaginationCallback = (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; +}; + +/** + * Key-value object. + */ +interface KeyVal { + [key: string]: any; +} + +/** + * Price object. + */ +interface Price { + amount: string; + currency: Currency; +} + +/** + * Pricing object. + */ +interface Pricing extends CryptoPricing { + local: Price; +} + +/** + * 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 { + 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; +} + +/** + * 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; + crypto: Price; + }; + block: { + height: number; + hash: string; + confirmations_accumulated: number; + confirmations_required: number; + } + }>; + + /** + * Set of addresses associated with the charge. + */ + addresses: Partial>; +} + +/** + * 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; + +/** + * 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; +} + +/** + * 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 { + /** + * 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): Promise; + + /** + * Delete the current resource. + */ + delete(callback?: Callback): Promise; + + /** + * Save new resource to Coinbase Commerce. + */ + insert(callback?: Callback): Promise; + + /** + * Update the current resource. + */ + update(callback?: Callback): Promise; + } + + /** + * Merge CreateACharge with Charge class. + */ + interface Charge extends ChargeResource {} + + /** + * Charge Class + * + * @link https://github.com/coinbase/coinbase-commerce-node#charges + */ + class Charge extends Resource { + /** + * Create a charge. + */ + static create(chargeData: CreateCharge, callback?: Callback): Promise; + + /** + * List charges. + */ + static list(paginationOptions: PaginationRequest, callback?: PaginationCallback): Promise<[Charge[], Pagination]>; + + /** + * Fetch all charges. + */ + static all(paginationOptions: PaginationRequest, callback?: Callback): Promise; + + /** + * Retrieve a charge by ID. + */ + static retrieve(chargeId: ChargeResource['id'], callback?: Callback): Promise; + } + + /** + * Merge CheckoutResource with Checkout class. + */ + interface Checkout extends CheckoutResource {} + + /** + * Checkout class. + * + * @link https://github.com/coinbase/coinbase-commerce-node#checkouts + */ + class Checkout extends Resource { + /** + * Create a checkout. + */ + static create(checkoutData: CreateCheckout, callback?: Callback): Promise; + + /** + * List checkouts. + */ + static list(paginationOptions: PaginationRequest, callback?: PaginationCallback): Promise<[Checkout[], Pagination]>; + + /** + * Fetch all checkouts. + */ + static all(paginationOptions: PaginationRequest, callback?: Callback): Promise; + + /** + * Retrieve a checkout by ID. + */ + static retrieve(checkoutId: CheckoutResource['id'], callback?: Callback): Promise; + + /** + * Update a checkout by ID. + */ + static updateById(checkoutId: CheckoutResource['id'], update: UpdateCheckout, callback?: Callback): Promise; + + /** + * Delete a checkout by ID. + */ + static deleteById(checkoutId: CheckoutResource['id'], callback?: Callback): Promise; + } + + /** + * Merge EventResource with Event class. + */ + interface Event extends EventResource {} + + /** + * Event class. + * + * @link https://github.com/coinbase/coinbase-commerce-node#events + */ + class Event extends Resource { + /** + * Retrieve a event by ID. + */ + static retrieve(eventId: EventResource['id'], callback?: Callback): Promise; + + /** + * List events. + */ + static list(paginationOptions: PaginationRequest, callback?: PaginationCallback): Promise<[Event[], Pagination]>; + + /** + * Fetch all events. + */ + static all(paginationOptions: PaginationRequest, callback?: Callback): Promise; + } + + /** + * 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, +}; diff --git a/types/coinbase-commerce-node/tsconfig.json b/types/coinbase-commerce-node/tsconfig.json new file mode 100644 index 0000000000..6323cf1ae6 --- /dev/null +++ b/types/coinbase-commerce-node/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "coinbase-commerce-node-tests.ts" + ] +} diff --git a/types/coinbase-commerce-node/tslint.json b/types/coinbase-commerce-node/tslint.json new file mode 100644 index 0000000000..4f44991c3c --- /dev/null +++ b/types/coinbase-commerce-node/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "no-empty-interface": false + } +}