Adjusted the package exports to be easier to consume
This commit is contained in:
parent
27d8892b28
commit
8e7ef263a2
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,2 @@
|
|||
export { withBasicAuth, withOAuth } from './utils';
|
||||
|
||||
export { AxiosClient } from './axios-client';
|
||||
export { AxiosOAuthInterceptor } from './axios-oauth-interceptor';
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
import { AxiosClient } from './axios-client';
|
||||
import { AxiosOAuthInterceptor } from './axios-oauth-interceptor';
|
||||
|
||||
/**
|
||||
* Creates a new axios client instance prepared for basic auth.
|
||||
*
|
||||
* @param {string} apiURL
|
||||
* @param {string} username
|
||||
* @param {string} password
|
||||
* @return {AxiosClient} An Axios client configured for OAuth requests.
|
||||
*/
|
||||
export function withBasicAuth( apiURL: string, username: string, password: string ): AxiosClient {
|
||||
return new AxiosClient(
|
||||
{
|
||||
baseURL: apiURL,
|
||||
auth: { username, password },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new axios client instance prepared for oauth.
|
||||
*
|
||||
* @param {string} apiURL
|
||||
* @param {string} consumerKey
|
||||
* @param {string} consumerSecret
|
||||
* @return {AxiosClient} An Axios client configured for OAuth requests.
|
||||
*/
|
||||
export function withOAuth( apiURL: string, consumerKey: string, consumerSecret: string ): AxiosClient {
|
||||
return new AxiosClient(
|
||||
{ baseURL: apiURL },
|
||||
[ new AxiosOAuthInterceptor( consumerKey, consumerSecret ) ],
|
||||
);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
import { HTTPClient } from './http-client';
|
||||
import { AxiosClient, AxiosOAuthInterceptor } from './axios';
|
||||
|
||||
/**
|
||||
* A class for generating HTTPClient instances with desired configurations.
|
||||
*/
|
||||
export class HTTPClientFactory {
|
||||
/**
|
||||
* Creates a new client instance prepared for basic auth.
|
||||
*
|
||||
* @param {string} apiURL
|
||||
* @param {string} username
|
||||
* @param {string} password
|
||||
* @return {HTTPClient} An HTTP client configured for OAuth requests.
|
||||
*/
|
||||
public static withBasicAuth( apiURL: string, username: string, password: string ): HTTPClient {
|
||||
return new AxiosClient(
|
||||
{
|
||||
baseURL: apiURL,
|
||||
auth: { username, password },
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new client instance prepared for oauth.
|
||||
*
|
||||
* @param {string} apiURL
|
||||
* @param {string} consumerKey
|
||||
* @param {string} consumerSecret
|
||||
* @return {HTTPClient} An HTTP client configured for OAuth requests.
|
||||
*/
|
||||
public static withOAuth( apiURL: string, consumerKey: string, consumerSecret: string ): HTTPClient {
|
||||
return new AxiosClient(
|
||||
{ baseURL: apiURL },
|
||||
[ new AxiosOAuthInterceptor( consumerKey, consumerSecret ) ],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,2 +1,3 @@
|
|||
export { HTTPResponse } from './http-client';
|
||||
export type { HTTPClient } from './http-client';
|
||||
export { HTTPClientFactory } from './http-client-factory';
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
export { HTTPClientFactory } from './http';
|
||||
export * from './models';
|
|
@ -31,6 +31,6 @@ export class SimpleProduct extends AbstractProduct {
|
|||
* @return {AsyncFactory} The new factory instance.
|
||||
*/
|
||||
public static factory( repository: ModelRepository< SimpleProduct > ): AsyncFactory< SimpleProduct > {
|
||||
return simpleProductFactory( repository.create );
|
||||
return simpleProductFactory( ( data ) => repository.create( data ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,12 +14,14 @@ function restCreate( httpClient: HTTPClient ): CreateFn< SimpleProduct > {
|
|||
'/wc/v3/products',
|
||||
{
|
||||
name: properties.name,
|
||||
regular_price: properties.regularPrice,
|
||||
},
|
||||
);
|
||||
|
||||
return Promise.resolve( new SimpleProduct( {
|
||||
id: response.data.id,
|
||||
name: response.data.name,
|
||||
regularPrice: response.data.regular_price,
|
||||
} ) );
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
"compilerOptions": {
|
||||
"types": [ "node", "jest", "faker", "axios", "moxios", "create-hmac" ],
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
"outDir": "dist",
|
||||
"target": "es5"
|
||||
},
|
||||
"include": [ "src/" ]
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"composite": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"emitDeclarationOnly": false,
|
||||
"isolatedModules": true,
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
|
|
Loading…
Reference in New Issue