LemonWebCore is a library designed for API requests and user authentication management in web-based projects for different cloud providers such as AWS, Azure, and GCP at LemonCloud.
You can install the LemonWebCore Library via npm:
npm install @lemoncloud/lemon-web-core
The LemonWebCore Library allows you to create and use instances for different cloud providers. Below are the usage examples for WebCoreFactory, AWSWebCore, and AzureWebCore. Please see documentation for more information.
The WebCoreFactory
is used to create instances of AWSWebCore
or AzureWebCore
based on the cloud provider configuration.
import { WebCoreFactory, WebCoreConfig } from '@lemoncloud/lemon-web-core';
const config: WebCoreConfig<'aws'> = {
cloud: 'aws',
project: 'my-aws-project',
oAuthEndpoint: 'https://example.com/oauth',
region: 'us-west-2',
};
const awsWebCore = WebCoreFactory.create(config);
await awsWebCore.init();
const azureConfig: WebCoreConfig<'azure'> = {
cloud: 'azure',
project: 'my-azure-project',
oAuthEndpoint: 'https://example.com/oauth',
};
const azureWebCore = WebCoreFactory.create(azureConfig);
await azureWebCore.init();
The AWSWebCore
class handles AWS-specific web core operations. Here is an example of how to use it:
import { AWSWebCore, WebCoreConfig } from '@lemoncloud/lemon-web-core';
const config: WebCoreConfig<'aws'> = {
cloud: 'aws',
project: 'my-aws-project',
oAuthEndpoint: 'https://example.com/oauth',
region: 'us-west-2',
};
const awsWebCore = new AWSWebCore(config);
// Initialize
await awsWebCore.init();
// Make a signed request
const response = await awsWebCore.signedRequest('GET', 'https://example.com/api/resource');
console.log(response.data);
// Make a signed request with Builder
const example = await awsWebCore
.buildSignedRequest({
method: 'GET',
baseURL: `https://api.lemoncloud.io/v1/oauth`,
})
.setParams({ page: 0 })
.setBody({ date: 'example' })
.execute();
// Check authentication status
const isAuthenticated = await awsWebCore.isAuthenticated();
console.log(isAuthenticated);
The AzureWebCore
class handles Azure-specific web core operations. Here is an example of how to use it:
import { AzureWebCore, WebCoreConfig } from '@lemoncloud/lemon-web-core';
const config: WebCoreConfig<'azure'> = {
cloud: 'azure',
project: 'my-azure-project',
oAuthEndpoint: 'https://example.com/oauth',
};
const azureWebCore = new AzureWebCore(config);
// Initialize
await azureWebCore.init();
// Make a signed request
const response = await azureWebCore.signedRequest('GET', 'https://example.com/api/resource');
console.log(response.data);
// Make a signed request with Builder
const example = await azureWebCore
.buildSignedRequest({
method: 'GET',
baseURL: `https://api.lemoncloud.io/v1/oauth`,
})
.setParams({ page: 0 })
.setBody({ date: 'example' })
.execute();
// Check authentication status
const isAuthenticated = await azureWebCore.isAuthenticated();
console.log(isAuthenticated);
create<T extends WebCoreService>(config: WebCoreConfig<CloudProvider>): T
Creates an instance of AWSWebCore
or AzureWebCore
based on the provided cloud provider configuration.
constructor(config: WebCoreConfig<'aws'>)
Creates an instance of AWSWebCore
with the specified configuration.
init(): Promise<void>
Initializes the AWSWebCore instance.
signedRequest<T>(method: string, url: string, params?: Params, body?: Body, config?: AxiosRequestConfig): Promise<HttpResponse<T>>
Makes a signed HTTP request.
isAuthenticated(): Promise<boolean>
Checks if the user is authenticated.
saveOAuthToken(token: LemonOAuthToken): Promise<void>
Saves the OAuth token.
logout(): Promise<void>
Logs the user out by clearing the OAuth token.
setUseXLemonIdentity(use: boolean): Promise<void>
Sets whether to use the x-lemon-identity header.
constructor(config: WebCoreConfig<'azure'>)
Creates an instance of AzureWebCore
with the specified configuration.
init(): Promise<void>
Initializes the AzureWebCore instance.
signedRequest<T>(method: string, url: string, params?: Params, body?: Body, config?: AxiosRequestConfig): Promise<HttpResponse<T>>
Makes a signed HTTP request.
isAuthenticated(): Promise<boolean>
Checks if the user is authenticated.
saveOAuthToken(token: LemonOAuthToken): Promise<void>
Saves the OAuth token.
logout(): Promise<void>
Logs the user out by clearing the OAuth token.
setUseXLemonIdentity(use: boolean): Promise<void>
Sets whether to use the x-lemon-identity header.
Please follow this guidelines when reporting bugs and feature requests:
Thanks for understanding!
If this project has been helpful to you, I would greatly appreciate it if you could click the Star⭐️ button on this repository!