Adjusted the package exports to be easier to consume
This commit is contained in:
parent
27d8892b28
commit
8e7ef263a2
|
@ -38,12 +38,12 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz",
|
||||
"integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
"ms": "2.1.2"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
|
@ -398,12 +398,12 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz",
|
||||
"integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
"ms": "2.1.2"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
|
@ -2416,12 +2416,12 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
|
||||
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz",
|
||||
"integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
"ms": "2.1.2"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
|
@ -4322,9 +4322,9 @@
|
|||
}
|
||||
},
|
||||
"spdx-license-ids": {
|
||||
"version": "3.0.5",
|
||||
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.5.tgz",
|
||||
"integrity": "sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==",
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.6.tgz",
|
||||
"integrity": "sha512-+orQK83kyMva3WyPf59k1+Y525csj5JejicWut55zeTWANuN17qSiSLUXWtzHeNWORSvT7GLDJ/E/XiIWoXBTw==",
|
||||
"dev": true
|
||||
},
|
||||
"split-string": {
|
||||
|
|
|
@ -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