diff --git a/asana/asana-tests.ts b/asana/asana-tests.ts
index 30990d42c..464498dcf 100644
--- a/asana/asana-tests.ts
+++ b/asana/asana-tests.ts
@@ -1,6 +1,12 @@
///
+///
import * as asana from 'asana';
let version: string = asana.VERSION;
+let n: asana.auth.BaseBrowserFlow = new asana.auth.BaseBrowserFlow(null);
+
+
+import * as request from 'request';
+
diff --git a/asana/asana.d.ts b/asana/asana.d.ts
index 267814376..1f099878b 100644
--- a/asana/asana.d.ts
+++ b/asana/asana.d.ts
@@ -7,6 +7,10 @@
///
declare module "asana" {
+ import * as Promise from 'bluebird';
+ import {CoreOptions} from 'request';
+ import * as request from 'request';
+
namespace asana {
var Client: ClientStatic;
@@ -24,21 +28,23 @@ declare module "asana" {
* @param {String} [redirectUri] Default redirect URI for this client
* @param {String} [asanaBaseUrl] Base URL for Asana, for debugging
*/
- (dispatcher : any, options : any): asana.Client;
+ (dispatcher: Dispatcher, options?: ClientOptions): asana.Client;
/**
* Creates a new client.
* @param {Object} options Options for specifying the client, see constructor.
*/
- create(options?: any): any;
+ create(options?: ClientOptions): Client;
+ }
+
+ /** Options to configure the client */
+ interface ClientOptions extends DispatcherOptions {
+ clientId?: string;
+ clientSecret?: string;
+ redirectUri?: string;
+ asanaBaseUrl?: string;
}
interface Client {
- /**
- * @param dispatcher
- * @param options
- */
- (dispatcher : any, options : any): Client;
-
/**
* Ensures the client is authorized to make requests. Kicks off the
* configured Oauth flow, if any.
@@ -46,7 +52,7 @@ declare module "asana" {
* @returns {Promise} A promise that resolves to this client when
* authorization is complete.
*/
- authorize(): void;
+ authorize(): Promise;
/**
* Configure the Client to use a user's API Key and then authenticate
@@ -58,7 +64,7 @@ declare module "asana" {
* @param apiKey
* @return
*/
- useBasicAuth(apiKey : string): any;
+ useBasicAuth(apiKey: string): this;
/**
* Configure the client to authenticate using a Personal Access Token.
@@ -68,7 +74,7 @@ declare module "asana" {
* @param accessToken
* @return
*/
- useAccessToken(accessToken : string): any;
+ useAccessToken(accessToken: string): this;
/**
* Configure the client to authenticate via Oauth. Credentials can be
@@ -80,19 +86,68 @@ declare module "asana" {
* @option {Object} [credentials] Credentials to use; no flow required to
* obtain authorization. This object should at a minimum contain an
* `access_token` string field.
- * @return {Client} this
+ * @return {Client} this
* @param options
* @return
*/
- useOauth(options : any): Client;
+ useOauth(options?: auth.OauthAuthenticatorOptions): this;
/**
- * Creates a new client.
- * @param {Object} options Options for specifying the client, see constructor.
- * @param options
- * @return
+ * The internal dispatcher. This is mostly used by the resources but provided
+ * for custom requests to the API or API features that have not yet been added
+ * to the client.
+ * @type {Dispatcher}
*/
- create(options : any): Client;
+ dispatcher: Dispatcher;
+ /**
+ * An instance of the Attachments resource.
+ * @type {Attachments}
+ */
+ attachments: resources.Attachments;
+ /**
+ * An instance of the Events resource.
+ * @type {Events}
+ */
+ events: resources.Events;
+ /**
+ * An instance of the Projects resource.
+ * @type {Projects}
+ */
+ projects: resources.Projects;
+ /**
+ * An instance of the Stories resource.
+ * @type {Stories}
+ */
+ stories: resources.Stories;
+ /**
+ * An instance of the Tags resource.
+ * @type {Tags}
+ */
+ tags: resources.Tags;
+ /**
+ * An instance of the Tasks resource.
+ * @type {Tasks}
+ */
+ tasks: resources.Tasks;
+ /**
+ * An instance of the Teams resource.
+ * @type {Teams}
+ */
+ teams: resources.Teams;
+ /**
+ * An instance of the Users resource.
+ * @type {Users}
+ */
+ users: resources.Users;
+ /**
+ * An instance of the Workspaces resource.
+ * @type {Workspaces}
+ */
+ workspaces: resources.Workspaces;
+ /**
+ * Store off Oauth info.
+ */
+ app: auth.App;
}
var Dispatcher: DispatcherStatic;
@@ -115,7 +170,29 @@ declare module "asana" {
* @option {Number} [requestTimeout] Timeout (in milliseconds) to wait for the
* request to finish.
*/
- new (options : any): Dispatcher;
+ new (options?: DispatcherOptions): Dispatcher;
+
+ /**
+ * Default handler for requests that are considered unauthorized.
+ * Requests that the authenticator try to refresh its credentials if
+ * possible.
+ * @return {Promise} True iff refresh was successful, false if not.
+ * @return
+ */
+ maybeReauthorize(): Promise;
+
+ /**
+ * The relative API path for the current version of the Asana API.
+ * @type {String}
+ */
+ API_PATH : string;
+ }
+
+ interface DispatcherOptions {
+ authenticator?: auth.Authenticator;
+ retryOnRateLimit?: boolean;
+ handleUnauthorized?: () => boolean|Promise;
+ requestTimeout?: string;
}
interface Dispatcher {
@@ -126,7 +203,7 @@ declare module "asana" {
* @param path
* @return
*/
- url(path : string): string;
+ url(path: string): string;
/**
* Configure the authentication mechanism to use.
@@ -134,7 +211,7 @@ declare module "asana" {
* @param authenticator
* @return
*/
- setAuthenticator(authenticator : any): Dispatcher;
+ setAuthenticator(authenticator: auth.Authenticator): this;
/**
* Ensure the dispatcher is authorized to make requests. Call this before
@@ -144,7 +221,7 @@ declare module "asana" {
* there was a problem authorizing.
* @return
*/
- authorize(): any;
+ authorize(): Promise;
/**
* Dispatches a request to the Asana API. The request parameters are passed to
@@ -156,7 +233,7 @@ declare module "asana" {
* @param dispatchOptions?
* @return
*/
- dispatch(params : any, dispatchOptions? : any): any;
+ dispatch(params: any, dispatchOptions?: any): Promise;
/**
* Dispatches a GET request to the Asana API.
@@ -170,7 +247,7 @@ declare module "asana" {
* @param dispatchOptions?
* @return
*/
- get(path : string, query? : any, dispatchOptions? : any): any;
+ get(path: string, query?: any, dispatchOptions?: any): Promise;
/**
* Dispatches a POST request to the Asana API.
@@ -184,7 +261,7 @@ declare module "asana" {
* @param dispatchOptions?
* @return
*/
- post(path : string, data : any, dispatchOptions? : any): any;
+ post(path: string, data: any, dispatchOptions?: any): Promise;
/**
* Dispatches a PUT request to the Asana API.
@@ -198,7 +275,7 @@ declare module "asana" {
* @param dispatchOptions?
* @return
*/
- put(path : string, data : any, dispatchOptions? : any): any;
+ put(path: string, data: any, dispatchOptions?: any): Promise;
/**
* Dispatches a DELETE request to the Asana API.
@@ -210,22 +287,7 @@ declare module "asana" {
* @param dispatchOptions?
* @return
*/
- delete(path : string, dispatchOptions? : any): any;
-
- /**
- * The relative API path for the current version of the Asana API.
- * @type {String}
- */
- API_PATH : string;
-
- /**
- * Default handler for requests that are considered unauthorized.
- * Requests that the authenticator try to refresh its credentials if
- * possible.
- * @return {Promise} True iff refresh was successful, false if not.
- * @return
- */
- maybeReauthorize(): boolean;
+ delete(path: string, dispatchOptions?: any): Promise;
/**
* The base URL for Asana
@@ -245,7 +307,7 @@ declare module "asana" {
* that has a refresh token, and will refresh the current access token.
* @type {Function}
*/
- handleUnauthorized : Function;
+ handleUnauthorized : () => boolean|Promise;
/**
* The amount of time in milliseconds to wait for a request to finish.
@@ -255,6 +317,111 @@ declare module "asana" {
}
namespace auth {
+ var BasicAuthenticator: BasicAuthenticatorStatic;
+
+ interface BasicAuthenticatorStatic {
+ /**
+ * @param apiKey
+ */
+ new (apiKey : string): BasicAuthenticator;
+ }
+
+ interface BasicAuthenticator extends Authenticator {
+ /**
+ * @param {Object} request The request to modify, for the `request` library.
+ * @return {Object} The `request` parameter, modified to include authentication
+ * information using the stored credentials.
+ * @param request
+ * @return
+ */
+ authenticateRequest(request : BasicAuthenticatorRequest): BasicAuthenticatorRequest;
+ }
+
+ interface BasicAuthenticatorRequest {
+ auth : {
+ username : string;
+ password : string;
+ }
+ }
+
+ var OauthAuthenticator: OauthAuthenticatorStatic;
+
+ interface OauthAuthenticatorStatic {
+ /**
+ * Creates an authenticator that uses Oauth for authentication.
+ *
+ * @param {Object} options Configure the authenticator; must specify one
+ * of `flow` or `credentials`.
+ * @option {App} app The app being authenticated for.
+ * @option {OauthFlow} [flow] The flow to use to get credentials
+ * when needed.
+ * @option {String|Object} [credentials] Initial credentials to use. This can
+ * be either the object returned from an access token request (which
+ * contains the token and some other metadata) or just the `access_token`
+ * field.
+ * @constructor
+ */
+ new (options : OauthAuthenticatorOptions): OauthAuthenticator;
+ }
+
+ interface OauthAuthenticatorOptions {
+ flowType?: auth.FlowType;
+ credentials?: Credentials|string;
+ }
+
+ interface Credentials {
+ access_token: string;
+ refresh_token?: string;
+ }
+
+ interface OauthAuthenticator extends Authenticator {
+ /**
+ * @param {Object} request The request to modify, for the `request` library.
+ * @return {Object} The `request` parameter, modified to include authentication
+ * information using the stored credentials.
+ * @param request
+ * @return
+ */
+ authenticateRequest(request : OauthAuthenticatorRequest): OauthAuthenticatorRequest;
+ }
+
+ interface OauthAuthenticatorRequest {
+ /**
+ * When browserify-d, the `auth` component of the `request` library
+ * doesn't work so well, so we just manually set the bearer token instead.
+ */
+ headers : {
+ Authorization : string;
+ }
+ }
+
+ /**
+ * A layer to abstract the differences between using different types of
+ * authentication (Oauth vs. Basic). The Authenticator is responsible for
+ * establishing credentials and applying them to outgoing requests.
+ * @constructor
+ */
+ interface Authenticator {
+ /**
+ * Establishes credentials.
+ *
+ * @return {Promise} Resolves when initial credentials have been
+ * completed and `authenticateRequest` calls can expect to succeed.
+ * @return
+ */
+ establishCredentials(): Promise;
+
+ /**
+ * Attempts to refresh credentials, if possible, given the current credentials.
+ *
+ * @return {Promise} Resolves to `true` if credentials have been successfully
+ * established and `authenticateRequests` can expect to succeed, else
+ * resolves to `false`.
+ * @return
+ */
+ refreshCredentials(): Promise;
+ }
+
var App: AppStatic;
interface AppStatic {
@@ -269,7 +436,13 @@ declare module "asana" {
* @option {String} [asanaBaseUrl] Base URL to use for Asana, for debugging
* @constructor
*/
- new (options : any): App;
+ new (options: AppOptions): App;
+ }
+
+ interface AppOptions extends AsanaAuthorizeUrlOptions {
+ clientId?: string;
+ clientSecret?: string;
+ scope?: string;
}
interface App {
@@ -281,7 +454,7 @@ declare module "asana" {
* @param options
* @return
*/
- asanaAuthorizeUrl(options : any): string;
+ asanaAuthorizeUrl(options?: AsanaAuthorizeUrlOptions): string;
/**
* @param {Object} options Overrides to the app's defaults
@@ -291,7 +464,7 @@ declare module "asana" {
* @param options
* @return
*/
- asanaTokenUrl(options : any): string;
+ asanaTokenUrl(options?: AsanaAuthorizeUrlOptions): string;
/**
* @param {String} code An authorization code obtained via `asanaAuthorizeUrl`.
@@ -305,7 +478,7 @@ declare module "asana" {
* @param options
* @return
*/
- accessTokenFromCode(code : string, options : any): any;
+ accessTokenFromCode(code: string, options?: AsanaAuthorizeUrlOptions): Promise;
/**
* @param {String} refreshToken A refresh token obtained via Oauth.
@@ -318,13 +491,18 @@ declare module "asana" {
* @param options
* @return
*/
- accessTokenFromRefreshToken(refreshToken : string, options : any): any;
+ accessTokenFromRefreshToken(refreshToken: string, options: AsanaAuthorizeUrlOptions): Promise;
scope : string;
asanaBaseUrl : string;
}
+ interface AsanaAuthorizeUrlOptions {
+ redirectUri?: string;
+ asanaBaseUrl?: string;
+ }
+
var OauthError: OauthErrorStatic;
interface OauthErrorStatic {
@@ -336,10 +514,16 @@ declare module "asana" {
* @option {String} [error_description] A description of the error.
* @constructor
*/
- new (options : any): OauthError;
+ new (options: OauthErrorOptions): OauthError;
}
- interface OauthError { }
+ interface OauthErrorOptions {
+ error?: string;
+ error_uri?: string;
+ error_description?: string;
+ }
+
+ interface OauthError extends Error { }
/**
* Auto-detects the type of Oauth flow to use that's appropriate to the
@@ -350,11 +534,11 @@ declare module "asana" {
* @param env
* @return
*/
- function autoDetect(env : any): Function;
+ function autoDetect(env: any): Function;
var RedirectFlow: RedirectFlowStatic;
- interface RedirectFlowStatic {
+ interface RedirectFlowStatic extends FlowType {
/**
* An Oauth flow that runs in the browser and requests user authorization by
* redirecting to an authorization page on Asana, and redirecting back with
@@ -362,57 +546,36 @@ declare module "asana" {
* @param {Object} options See `BaseBrowserFlow` for options.
* @constructor
*/
- new (options : any): RedirectFlow;
+ new (options: any): RedirectFlow;
}
- interface RedirectFlow {
- getStateParam(): void;
-
- /**
- *
- * @param authUrl
- */
- startAuthorization(authUrl : any): void;
-
- finishAuthorization(): void;
- }
+ interface RedirectFlow extends BaseBrowserFlow { }
var PopupFlow: PopupFlowStatic;
- interface PopupFlowStatic {
+ interface PopupFlowStatic extends FlowType {
/**
* An Oauth flow that runs in the browser and requests user authorization by
* popping up a window and prompting the user.
* @param {Object} options See `BaseBrowserFlow` for options.
* @constructor
*/
- new (options : any): PopupFlow;
+ new (options: any): PopupFlow;
}
- interface PopupFlow {
- /**
- * @param authUrl
- * @param state
- */
- startAuthorization(authUrl : any, state : any): void;
-
- /**
- * @return
- */
- finishAuthorization(): any;
-
+ interface PopupFlow extends BaseBrowserFlow {
/**
* @param popupWidth
* @param popupHeight
*/
- _popupParams(popupWidth : number, popupHeight : number): void;
+ _popupParams(popupWidth: number, popupHeight: number): void;
runReceiver(): void;
}
var NativeFlow: NativeFlowStatic;
- interface NativeFlowStatic {
+ interface NativeFlowStatic extends FlowType {
/**
* An Oauth flow that can be run from the console or an app that does
* not have the ability to open and manage a browser on its own.
@@ -424,10 +587,10 @@ declare module "asana" {
* waiting for a line from stdin.
* @constructor
*/
- new (options : any): NativeFlow;
+ new (options: any): NativeFlow;
}
- interface NativeFlow {
+ interface NativeFlow extends Flow {
/**
* Run the Oauth flow, prompting the user to go to the authorization URL
* and enter the code it displays when finished.
@@ -437,12 +600,6 @@ declare module "asana" {
*/
run(): void;
- /**
- * @returns {String} The URL used to authorize the user for the app.
- * @return
- */
- authorizeUrl(): string;
-
/**
* @param {String} code An authorization code obtained via `asanaAuthorizeUrl`.
* @return {Promise