Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@totvslabs/carol-app-fe-sdk
Advanced tools
[![Build status](https://badge.buildkite.com/e3758c83d75b85802da1050c70a0aa6d1efc9d00d9a8eab173.svg)](https://buildkite.com/totvslabs/carol-fe-sdk)
SDK to support the development of Carol Apps with Angular.
Starting the development of a new Carol App? Check out our official seed project, that already includes the Carol FE SDK and PO UI preconfigured.
On your current Angular project:
npm install @totvslabs/carol-app-fe-sdk
On your project, change the tsconfig.json
compiler Options to allow import json values in the project.
{
...
"compilerOptions": {
...
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
...
}
For development purposes, a proxy needs to be configured to divert certain URLs to Carol's backend. It is a good practice to call this file proxy.conf.json
and to keep it inside your project's root or src folder.
We want to proxy http calls for paths starting as /api
and /sql
, and for that your proxy file should look like that, replacing the values CAROL_ORGANIZATION_NAME
and CAROL_ENVIRONMENT_NAME
:
{
"carolOrganization": "CAROL_ORGANIZATION_NAME",
"carolEnvironment": "CAROL_ENVIRONMENT_NAME",
"/api/*": {
"target": "https://CAROL_ORGANIZATION_NAME.carol.ai",
"secure": true,
"logLevel": "debug",
"changeOrigin": true
},
"/sql/*": {
"target": "https://api.carol.ai/sql/v1/query",
"secure": true,
"logLevel": "debug",
"changeOrigin": true,
"pathRewrite": {
"^/sql": "/"
}
}
}
After properly setting up your proxy configuration file, you need to point your angular.json
file, with the following entries.
...
"architect": {
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "your-application-name:build",
"proxyConfig": "proxy.conf.json"
},
...
The SDK needs certain parameters to be defined during the app initialization in order to work properly.
In dev mode they are:
In prod mode they are automatically detected from the URL.
The recommended way to do this is through a factory function and then providing it to the APP_INITIALIZER token. Angular will then execute it during the app initialization.
Your app.module.ts
should look like this:
import { NgModule, isDevMode, APP_INITIALIZER } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { BrowserModule } from '@angular/platform-browser';
import { CarolAuthService, CarolSdkModule } from '@totvslabs/carol-app-fe-sdk';
import conf from 'proxy.conf.json';
function appInitializer(carolAuth: CarolAuthService) {
return () =>
isDevMode()
? carolAuth
.setDomain(conf['/api/*'].target)
.setOrganization(conf.carolOrganization)
.setEnvironment(conf.carolEnvironment)
.appStart()
: carolAuth.appStart();
}
@NgModule({
declarations: [],
imports: [
CarolSdkModule,
HttpClientModule,
RouterModule.forRoot([]),
],
providers: [
{
provide: APP_INITIALIZER,
useFactory: appInitializer,
deps: [CarolAuthService],
multi: true
},
]
})
HttpClientModule
and RouterModule
must be imported by the parent applicationNow, when your Angular app starts, it will be already authenticated and ready to communicate with Carol.
Check the available SDK Apis bellow and good coding.
href
propertyThe href
attribute specifies to the browser the base URL for all relative URLs on a page. Carol apps are required to specify this property with the .
value.
<base href=".">
Web apps hosted in the Carol platform are also required to use the HashLocationStrategy.
In your app's main module, you have to declare your routes with an aditional options object describing it:
RouterModule.forRoot(routes, {useHash: true})
The SDK provides scripts to automate the bundling process -- preparing your application accordingly to the structure Carol expects, and to publish it to the platform.
The entire publishing process can be achieved by replacing the build script on your package.json
file with the following:
build: "ng build && npx prepare-bundle --package=@totvslabs/carol-app-fe-sdk && npx upload-bundle --package=@totvslabs/carol-app-fe-sdk"
And then running "npm run build".
The scripts accept several parameters that can be used for automation / QOL purposes:
path
: Relative path to the compiled application's root folder;
path
: Relative path to the prepared .zip bundle;
organization
: The Carol organization name of where your application will be hosted;
environment
: The Carol environment name of where your application will be hosted;
app-name
: Name of the application where your application will be hosted;
username
: Username used to authenticate on the Carol platform;
password
: Password used to authenticate on the Carol platform;
access-token
: Access Token used to authenticate on the platform (alternative to username and password);
connector-id
: Connector ID used to authenticate on the platform is using an API token;
Manual instructions to prepare and publish your Carol Application
Carol expects your project bundle to follow the structure below:
.zip file (the compressed file name doesn't matter)
├── 'site' folder (the folder name MUST be 'site')
│ ├── Your project's files.
│ ├── ...
│ ├── ...
│ ├── ...
Our SDK provides you with a script that automatically organizes this structure for you.
You can execute it by calling npx prepare-bundle --package=@totvslabs/carol-app-fe-sdk
, or prepare-bundle
if you have the SDK installed globally.
The command must be executed in your project's root folder or passing a path
parameter with the relative path to your compiled project.
With your zip file prepared, you can either upload it to carol manually through the platform UI, or use a second script provided by the SDK.
The script can be executed by calling npx upload-bundle --package=@totvslabs/carol-app-fe-sdk
or upload-bundle
if you have the SDK installed globally.
The command must be executed in your project's root folder or passing a path
parameter with the relative path to your zip file.
Runs a SQL query and emits the result once it completes.
Gets the specified page of a previously run SQL query. Requires the queryId which is returned with the result set after running the runSQL method.
Runs a SQL query in a synchronous manner, without pooling. Normally should be avoided as its susceptible to timeouts in bigger queries.
Returns a cached preview of the specified table.
Returns a compilation of all the datamodels in the current environment, its fields and types.
Method to be called when the app is ready to validate and handle the login flow. If in dev mode, organization, environment and domain must be set using the methods described below.
Flag that defines if the app will be using the Carol OAuth login application or if the carol-app will be handling the login flow. Defaults to false.
Defines the organization that will be used by the internal routines of the SDK in dev mode. In production this method can be disregarded as the info will be get from the browser URL.
Defines the environment that will be used by the internal routines of the SDK in dev mode. In production this method can be disregarded as the info will be get from the browser URL.
Defines the domain that will be used by the internal routines of the SDK in dev mode. In production this method can be disregarded as the info will be get from the browser URL.
Defines the current session token. Will handle all the logic related to session tokens such as validating, setting to local storage and adding to an HttpInterceptor. To be used together with selfLogin.
Returns the current organization;
Returns the current environment;
Returns the current domain;
Returns the current session token;
Returns the current value of the selfLogin flag;
Manually creates a Carol Session. To be used together with selfLogin;
Ends the current Carol Session and redirects the user to login. In selfLogin mode the carol-app is responsible for the redirect.
Observable to receive changes about the carol session status.
FAQs
[![Build status](https://badge.buildkite.com/e3758c83d75b85802da1050c70a0aa6d1efc9d00d9a8eab173.svg)](https://buildkite.com/totvslabs/carol-fe-sdk)
We found that @totvslabs/carol-app-fe-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.