diff --git a/types/chartmogul-node/chartmogul-node-tests.ts b/types/chartmogul-node/chartmogul-node-tests.ts new file mode 100644 index 0000000000..3a09a7597c --- /dev/null +++ b/types/chartmogul-node/chartmogul-node-tests.ts @@ -0,0 +1,277 @@ +import * as ChartMogul from 'chartmogul-node'; + +const config = new ChartMogul.Config("token", "secret", "baseURL"); +config.retries = 10; +config.getAccountToken(); // $ExpectType string +config.getSecretKey(); // $ExpectType string +config.VERSION; // $ExpectType string + +ChartMogul.Ping.ping(config); // $ExpectType Promise + +// $ExpectType Promise +ChartMogul.DataSource.create(config, { + name: "" +}); + +// $ExpectType Promise +ChartMogul.DataSource.retrieve(config, ""); + +// $ExpectType Promise<{}> +ChartMogul.DataSource.destroy(config, ""); + +// $ExpectType Promise +ChartMogul.DataSource.all(config, { + name: "" +}); + +ChartMogul.DataSource.all(config).then(data => { + data.data_sources[0]; // $ExpectType DataSource + data.data_sources[0].name; // $ExpectType string +}); + +// $ExpectType Promise +ChartMogul.Customer.create(config, { + data_source_uuid: "", + name: "", + external_id: "", + attributes: { + tags: ["important", "Prio1"], + custom: [ + {type: "String", key: "channel", value: "Facebook", source: "integration"}, + {type: "Integer", key: "age", value: 18} + ] + } +}); + +// $ExpectType Promise +ChartMogul.Customer.retrieve(config, ""); + +// $ExpectType Promise +ChartMogul.Customer.modify(config, "", {}); + +// $ExpectType Promise<{}> +ChartMogul.Customer.destroy(config, ""); + +// $ExpectType Promise> +ChartMogul.Customer.all(config, { + data_source_uuid: "" +}); + +ChartMogul.Customer.all(config).then(data => { + data.entries[0]; // $ExpectType Customer + data.entries[0].attributes!.stripe!['something']; // $ExpectType any + data.page!; // $ExpectType number +}); + +// $ExpectType Promise> +ChartMogul.Customer.search(config, { + email: "" +}); +// $ExpectType Promise<{}> +ChartMogul.Customer.merge(config, { + from: {customer_uuid: ""}, + into: {customer_uuid: ""} +}); +// $ExpectType Promise +ChartMogul.Customer.attributes(config, ""); + +// $ExpectType Promise +ChartMogul.Plan.create(config, { + data_source_uuid: "", + name: "", + interval_count: 1, + interval_unit: "", + external_id: "" +}); + +// $ExpectType Promise +ChartMogul.Plan.retrieve(config, ""); + +// $ExpectType Promise +ChartMogul.Plan.modify(config, "", { + name: "" +}); + +// $ExpectType Promise<{}> +ChartMogul.Plan.destroy(config, ""); + +ChartMogul.Plan.all(config, { + page: 1 +}).then(data => { + data.plans[0]; // $ExpectType Plan + data.plans[0].name!; // $ExpectType string + data.page!; // $ExpectType number +}); + +// $ExpectType Promise +ChartMogul.Invoice.retrieve(config, ""); + +// $ExpectType Promise +ChartMogul.Invoice.create(config, "", { + invoices: [ + { + external_id: "" + } + ] +}); + +// $ExpectType Promise<{}> +ChartMogul.Invoice.destroy(config, ""); +ChartMogul.Invoice.all(config, { + external_id: "" +}).then(data => { + data.invoices[0]; // $ExpectType Invoice + data.invoices[0].uuid!; // $ExpectType string + data.page!; // $ExpectType number +}); + +ChartMogul.Invoice.all(config, "", { + page: 1 +}).then(data => { + data.customer_uuid!; // $ExpectType string + data.invoices[0]; // $ExpectType Invoice + data.invoices[0].uuid!; // $ExpectType string + data.page!; // $ExpectType number +}); + +// $ExpectType Promise +ChartMogul.Transaction.create(config, "", { + type: "", + date: "", + result: "" +}); + +ChartMogul.Subscription.all(config, "", { + page: 1 +}).then(data => { + data.customer_uuid!; // $ExpectType string + data.subscriptions[0]; // $ExpectType Subscription + data.subscriptions[0].uuid; // $ExpectType string + data.current_page!; // $ExpectType number +}); + +ChartMogul.Subscription.cancel(config, "", { + cancelled_at: "" +}).then(data => { + data.customer_uuid; // $ExpectType string +}); + +// $ExpectType Promise> +ChartMogul.Tag.add(config, "", { + email: "", + tags: [""] +}); + +// $ExpectType Promise +ChartMogul.Tag.add(config, "", { + tags: [""] +}); + +// $ExpectType Promise +ChartMogul.Tag.remove(config, "", { + tags: [""] +}); + +// $ExpectType Promise +ChartMogul.CustomAttribute.add(config, "", { + custom: [ + {type: "", key: "", value: 0} + ] +}); +// $ExpectType Promise> +ChartMogul.CustomAttribute.add(config, "", { + email: "", + custom: [ + {type: "", key: "", value: 0} + ] +}); + +// $ExpectType Promise +ChartMogul.CustomAttribute.update(config, "", { + custom: { + pro: true, + channel: "" + } +}); + +ChartMogul.CustomAttribute.remove(config, "", { + custom: [""] +}).then(data => { + data.custom["key"]; // $ExpectType any +}); + +// $ExpectType Promise +ChartMogul.Metrics.all(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-24', + interval: '', + geo: '', + plans: '' +}); + +// $ExpectType Promise> +ChartMogul.Metrics.mrr(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-01' +}); + +// $ExpectType Promise> +ChartMogul.Metrics.arr(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-01' +}); + +// $ExpectType Promise> +ChartMogul.Metrics.arpa(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-01' +}); + +// $ExpectType Promise> +ChartMogul.Metrics.asp(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-01' +}); + +// $ExpectType Promise> +ChartMogul.Metrics.customerCount(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-01' +}); + +// $ExpectType Promise> +ChartMogul.Metrics.customerChurnRate(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-01', + geo: '', + plans: '' +}); + +// $ExpectType Promise> +ChartMogul.Metrics.mrrChurnRate(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-01' +}); + +ChartMogul.Metrics.ltv(config, { + 'start-date': '2015-01-01', + 'end-date': '2015-11-01' +}).then(data => { + data.entries[0].ltv; // $ExpectType number + data.summary; // $ExpectType Summary + data.summary.current; // $ExpectType number +}); + +// $ExpectType Promise> +ChartMogul.Metrics.Customer.subscriptions(config, "", { + page: 1 +}); + +ChartMogul.Metrics.Customer.activities(config, "", { + page: 1 +}).then(data => { + data.entries; // $ExpectType MetricsActivity[] + data.entries[0]; // $ExpectType MetricsActivity + data.entries[0]['activity-mrr']; // $ExpectType number + data.page!; // $ExpectType number +}); diff --git a/types/chartmogul-node/common.d.ts b/types/chartmogul-node/common.d.ts new file mode 100644 index 0000000000..ced10f98d7 --- /dev/null +++ b/types/chartmogul-node/common.d.ts @@ -0,0 +1,28 @@ +export interface Map { + [key: string]: any +} +export interface CursorParams { + page?: number; + per_page?: number; +} +export type Strings = string[]; + +export interface Cursor { + page?: number; + per_page?: number; + has_more?: boolean; + current_page?: number; + total_pages?: number; +} +export interface Entries extends Cursor { + entries: T[] +} +interface Summary { + current: number; + previous: number; + ['percentage-change']: number; +} +export interface EntriesSummary { + entries: T[]; + summary: Summary; +} \ No newline at end of file diff --git a/types/chartmogul-node/index.d.ts b/types/chartmogul-node/index.d.ts new file mode 100644 index 0000000000..c4bdce5aca --- /dev/null +++ b/types/chartmogul-node/index.d.ts @@ -0,0 +1,410 @@ +// Type definitions for chartmogul-node 1.0 +// Project: https://github.com/chartmogul/chartmogul-node +// Definitions by: ChartMogul +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { Map, Cursor, CursorParams, Strings, Entries, EntriesSummary } from './common'; + +export class Config { + VERSION: string; + API_BASE: string; + retries: number; + + constructor(token: string, secret: string, base?: string); + getAccountToken(): string; + getSecretKey(): string; +} + +export namespace Ping { + function ping(config: Config): Promise; +} + +export namespace DataSource { + interface DataSource { + uuid?: string; + name: string; + created_at?: string; + status?: string; + system?: string; + } + interface DataSources { + data_sources: DataSource[]; + } + interface ListDataSourcesParams { + name?: string; + system?: string; + } + + function create(config: Config, data: DataSource): Promise; + function retrieve(config: Config, uuid: string): Promise; + function destroy(config: Config, uuid: string): Promise<{}>; + function all(config: Config, params?: ListDataSourcesParams): Promise; +} + +export namespace Customer { + interface Customer { + id?: number; + data_source_uuid?: string; + data_source_uuids?: Strings; + uuid?: string; + external_id?: string; + external_ids?: Strings; + name?: string; + email?: string; + status?: string; + ['customer-since']?: string; + attributes?: Attributes; + address?: { + address_zip?: string; + city?: string; + state?: string; + country?: string; + }; + mrr?: number; + arr?: number; + ['billing-system-url']?: string; + ['chartmogul-url']?: string; + ['billing-system-type']?: string; + currency?: string; + ['currency-sign']?: string; + company?: string; + country?: string; + state?: string; + city?: string; + zip?: string; + lead_created_at?: string; + free_trial_started_at?: string; + } + interface NewCustomer { + data_source_uuid: string; + external_id: string; + name: string; + email?: string; + company?: string; + country?: string; + state?: string; + city?: string; + zip?: string; + lead_created_at?: string; + free_trial_started_at?: string; + attributes?: NewAttributes; + } + interface UpdateCustomer { + name?: string; + email?: string; + company?: string; + country?: string; + state?: string; + city?: string; + zip?: string; + lead_created_at?: string; + free_trial_started_at?: string; + attributes?: NewAttributes; + } + interface NewAttributes { + tags?: Strings; + custom?: NewCustomAttributes[]; + } + interface NewCustomAttributes { + type?: string; + key: string; + value: any; + source?: string; + } + interface Attributes { + tags?: Strings; + stripe?: Map; + clearbit?: Map; + custom?: Map; + } + interface ListCustomersParams extends CursorParams { + data_source_uuid?: string; + status?: string; + system?: string; + external_id?: string; + } + interface SearchCustomersParams extends CursorParams { + email: string; + } + interface MergeID { + customer_uuid?: string; + external_id?: string; + } + interface MergeCustomersParams { + from: MergeID; + into: MergeID; + } + + function create(config: Config, data: NewCustomer): Promise; + function retrieve(config: Config, uuid: string): Promise; + function modify(config: Config, uuid: string, data: UpdateCustomer): Promise; + function destroy(config: Config, uuid: string): Promise<{}>; + function all(config: Config, params?: ListCustomersParams): Promise>; + function search(config: Config, params?: SearchCustomersParams): Promise>; + function merge(config: Config, params?: MergeCustomersParams): Promise<{}>; + function attributes(config: Config, uuid: string): Promise; +} + +export namespace Plan { + interface Plan { + uuid?: string; + data_source_uuid?: string; + external_id?: string; + name?: string; + interval_count?: number; + interval_unit?: string; + } + interface ListPlansParams extends CursorParams { + data_source_uuid?: string; + system?: string; + external_id?: string; + } + interface Plans extends Cursor { + plans: Plan[]; + } + + function create(config: Config, data: Plan): Promise; + function retrieve(config: Config, uuid: string): Promise; + function modify(config: Config, uuid: string, data: Plan): Promise; + function destroy(config: Config, uuid: string): Promise<{}>; + function all(config: Config, params?: ListPlansParams): Promise; +} + +export namespace Invoice { + interface Invoice { + uuid?: string; + customer_uuid?: string; + currency?: string; + data_source_uuid?: string; + date?: string; + due_date?: string; + external_id?: string; + line_items?: LineItem[]; + transactions?: Transaction[]; + } + interface LineItem { + uuid?: string; + account_code?: string; + amount_in_cents?: number; + cancelled_at?: string; + description?: string; + discount_amount_in_cents?: number; + discount_code?: string; + external_id?: string; + plan_uuid?: string; + prorated?: boolean; + quantity?: number; + service_period_end?: string; + service_period_start?: string; + subscription_external_id?: string; + subscription_uuid?: string; + tax_amount_in_cents?: number; + transaction_fees_in_cents?: number; + type?: string; + } + interface Transaction { + uuid?: string; + date?: string; + external_id?: string; + result?: string; + type?: string; + } + interface ListInvoicesParams extends CursorParams { + data_source_uuid?: string; + customer_uuid?: string; + external_id?: string; + } + interface Invoices extends Cursor { + customer_uuid?: string; + invoices: Invoice[]; + } + + function create(config: Config, uuid: string, data: { + invoices: Invoice[] + }): Promise; + function retrieve(config: Config, uuid: string): Promise; + function destroy(config: Config, uuid: string): Promise<{}>; + function all(config: Config, uuid: string, params?: ListInvoicesParams): Promise; + function all(config: Config, params?: ListInvoicesParams): Promise; +} + +export namespace Transaction { + interface Transaction { + uuid?: string; + date: string; + external_id?: string; + result: string; + type: string; + } + + function create(config: Config, uuid: string, data: Transaction): Promise; +} + +export namespace Subscription { + interface Subscription { + uuid: string; + external_id: string; + customer_uuid: string; + plan_uuid: string; + cancellation_dates: Strings; + data_source_uuid: string; + } + interface CancelSubscriptionParams { + cancelled_at?: string; + cancellation_dates?: Strings; + } + interface Subscriptions extends Cursor { + customer_uuid?: string; + subscriptions: Subscription[]; + } + + function all(config: Config, uuid: string, data: CursorParams): Promise; + function cancel(config: Config, uuid: string, data: CancelSubscriptionParams): Promise; +} + +export namespace Tag { + interface Tags { + tags: Strings; + } + interface TagsWithEmail { + email: string; + tags: Strings; + } + function add(config: Config, uuid: string, data: TagsWithEmail): Promise>; + function add(config: Config, uuid: string, data: Tags): Promise; + function remove(config: Config, uuid: string, data: Tags): Promise; +} + +export namespace CustomAttribute { + import NewCustomAttributes = Customer.NewCustomAttributes; + + interface CustomAttributes { + custom: Map; + } + function add(config: Config, uuid: string, data: { + email: string; + custom: NewCustomAttributes[]; + }): Promise>; + function add(config: Config, uuid: string, data: { + custom: NewCustomAttributes[]; + }): Promise; + function update(config: Config, uuid: string, data: CustomAttributes): Promise; + function remove(config: Config, uuid: string, data: { + custom: Strings; + }): Promise; +} + +export namespace Metrics { + interface Params extends ParamsNoInterval { + interval?: string; + } + interface ParamsNoInterval { + ['start-date']: string; + ['end-date']: string; + geo?: string; + plans?: string; + } + interface All { + entries: { + date: string; + ['customer-churn-rate']: number; + ['mrr-churn-rate']: number; + ltv: number; + customers: number; + asp: number; + arpa: number; + arr: number; + mrr: number; + }; + } + + interface MRR { + date: string; + mrr: number; + ['mrr-new-business']: number; + ['mrr-expansion']: number; + ['mrr-contraction']: number; + ['mrr-churn']: number; + ['mrr-reactivation']: number; + } + interface ARR { + date: string; + arr: number; + } + interface ARPA { + date: string; + arpa: number; + } + interface ASP { + date: string; + asp: number; + } + interface CustomerCount { + date: string; + customers: number; + } + interface CustomerChurnRate { + date: string; + ['customer-churn-rate']: number; + } + interface MRRChurnRate { + date: string; + ['mrr-churn-rate']: number; + } + interface LTV { + date: string; + ltv: number; + } + + function all(config: Config, params: Params): Promise; + function mrr(config: Config, params: Params): Promise>; + function arr(config: Config, params: Params): Promise>; + function asp(config: Config, params: Params): Promise>; + function arpa(config: Config, params: Params): Promise>; + function customerCount(config: Config, params: Params): Promise>; + function customerChurnRate(config: Config, params: ParamsNoInterval): Promise>; + function mrrChurnRate(config: Config, params: ParamsNoInterval): Promise>; + function ltv(config: Config, params: ParamsNoInterval): Promise>; + + namespace Customer { + interface MetricsSubscription { + id: number; + external_id: string; + plan: string; + quantity: number; + mrr: number; + arr: number; + status: string; + ['billing-cycle']: string; + ['billing-cycle-count']: number; + ['start-date']: string; + ['end-date']: string; + currency: string; + ['currency-sign']: string; + } + interface MetricsActivity { + id: number; + date: string; + ['activity-arr']: number; + ['activity-mrr']: number; + ['activity-mrr-movement']: number; + currency: string; + ['currency-sign']: string; + description: string; + type: string; + } + + function subscriptions(config: Config, uuid: string, params?: CursorParams): Promise>; + function activities(config: Config, uuid: string, params?: CursorParams): Promise>; + } +} + +export class ChartMogulError extends Error { + response: any; + httpStatus: number; +} +export class ConfigurationError extends ChartMogulError {} +export class ForbiddenError extends ChartMogulError {} +export class NotFoundError extends ChartMogulError {} +export class ResourceInvalidError extends ChartMogulError {} +export class SchemaInvalidError extends ChartMogulError {} diff --git a/types/chartmogul-node/tsconfig.json b/types/chartmogul-node/tsconfig.json new file mode 100644 index 0000000000..3b24d48da8 --- /dev/null +++ b/types/chartmogul-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", + "chartmogul-node-tests.ts" + ] +} diff --git a/types/chartmogul-node/tslint.json b/types/chartmogul-node/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/chartmogul-node/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }