![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@flytio/int-sdk
Advanced tools
Use version at least 1.1.0 -> Read here why
A standard library for integrations in Flyt. The library aims to help to speed up future integrations by extracting common parts. This way in case of any update you don't have to update the code, but only the version of the library. See original proposal.
The library sets up some things for you.
It runs an express server on port 8080 to expose metrics and liveness probe.
/metrics
/healthz
As in version 1.2.x it is now possible to extend the http server with endpoints that might be required by your integration. Look at this section of the documentation for instructions.
It creates a GRPC server and assigns your implementation to its services.
It registers Prometheus metrics and places some counters and histograms (using prom-client package) into the integration calls.
It exports HttpClientFactory that sets interceptors with a logger, and metrics and configures default timeout.
It also exports wrappers for Menu and Ordering services that simplify passing logger and httpInsntace down to the integration so you don't have to think about extracting requestId
from metadata.
You have to create a LoggerFactory
instance that is shared between the integration factory and your implementation. This way you can keep the logs under the same app name. Also you may want to create an httpClient instance using HttpClientFactory
insntace to make use of metrics and logs already set up using interceptors.
import {
IntegrationFactory,
LoggerFactory,
HttpClientFactory,
OrderingServiceWrapper,
OrderingService,
} from '@flytio/int-sdk';
import { MyOrderingImplementation, APP_NAME } from './src/my-class';
// 1. create a logger factory instance
const loggerFactory = new LoggerFactory(APP_NAME);
// 2. use logger factory instance to create http client factory instance
const httpClientFactory = new HttpClientFactory(loggerFactory);
// 3. MyOrderingImplementation implements
// OrderingService exported from @flytio/int-sdk
const myOrdering = new MyOrderingImplementation();
// 4. OrderingServiceWrapper implements
// OrderingGrpcService exported from @flytio/protos
const ordering = new OrderingServiceWrapper(
myOrdering,
loggerFactory,
httpClientFactory,
);
// 5. create an integration
const integration = new IntegrationFactory({
loggerFactory,
appName: APP_NAME,
ordering,
});
// 6. and make grpc server and http server listen
integration.run();
We use prettier to format code before commit (using husky hooks).
For testing we use Jest. Unit tests are placed inside __tests__
directory. Integration tests are placed in __integration-tests__
directory.
The library is distributed as an npm package
and publishing happens automatically through CircleCI after merging to master.
We follow semantic versioning approach. To ensure you bump the version number there is a script to run before you push.
Please update CHANGELOG.md before publishing new version.
It's a factory class that you create once giving the app name and you pass around the instance to create logger instances.
Besides appName
it also accepts config where you can toggle transport types for example when you want to use Console during development.
import { LoggerFactory, TransportType } from '@flytio/int-sdk';
import { APP_NAME } from "./config";
const loggerFactory = new LoggerFactory(APP_NAME, {
useUDP: false,
useConsole: true
});
It's a factory class that you create once giving the loggerFactory instance and you pass around the instance of it to create http client (internally using Axios) instance.
Under the hood it sets up interceptors that log external requests and responses and also metrics.
So whenever you use an http instance it will automatically log the request and response for you
const httpClientFactory = new HttpClientFactory(loggerFactory);
const httpClient = httpClientFactory.getHttpClient(requestId);
const result = await httpClient.get(url);
in logs you're going to see something like
HTTP request: { url: 'http://something.com', headers: {... some headers } }
HTTP response { url: 'http://something.com', data: { ... some payload }}
Since version 1.3.4, we added the ability to specify a default proxy that will be attached to all the requests (or alternatively to just some of them).
ProxyAgentFactory
is included which can be used when an integration requires the ability
to configure HTTP requests to pass through a proxy. It accepts four constructor arguments,
url, port, user and pass. A new httpsProxyAgent
is instantiated in the constructor on
the private httpsProxyAgent
property.
By doing this, every request that you'll make through the httpClient will be forwarder through the proxy.
In order to do this, create a ProxyAgentFactory
and pass it to HttpClientFactory
inside the run-server.ts
file:
const proxyAgentFactory = new ProxyAgentFactory(proxyUrl, proxyPort, proxyUser, proxyPass);
const httpClientFactory = new HttpClientFactory(loggerFactory, proxyAgentFactory);
const ordering = new OrderingServiceWrapper(
new OrderingIntegration(),
loggerFactory,
httpClientFactory,
);
Don't forget to edit your certification test to manually go through the proxy too:
const getProxyAgent = (): httpsProxyAgent => {
return new httpsProxyAgent(`http://${proxyUser}:${proxyPass}@${proxyUrl}:${proxyPort}`);
};
beforeAll(() => {
const axiosConfig: AxiosRequestConfig = {};
if (process.env.NODE_ENV === 'production' || process.env.NOCK_OFF === 'true') {
axiosConfig.httpsAgent = getProxyAgent();
}
httpClient = axios.create(axiosConfig);
});
If you need that only a specific endpoint call goes through the proxy, you can use the ProxyAgentFactory
directly. This factory will contain a method to get the proxy agent that you can apply as httpAgent
or httspAgent
to the axios configuration that will be passed to the request directly:
import { ProxyAgentFactory } from '@flytio/int-sdk';
const proxyAgentFactory = new ProxyAgentFactory(
url,
port,
user,
pass
);
const config = {
httpsAgent: proxyAgentFactory.getHttpsProxyAgent(),
};
axios.post(url, data, config);
With the int-sdk version 1.2 is now possible to extend the http server to run also custom routes needed by integrations.
Please note that this won't publicly expose the route.
You'll also require to: and an ingress host in helm/production/values.yaml
- Add a kong migration (contact the devops team)
- Edit the file
helm/production/values.yaml
to include aningress.host
Currently the only integration that supports this is redcat-ordering, so have a look at it for examples
The extra routes must be defined using the express.Router
component, as defined in the express documentation (search for express.Router in the page) and then passed to the IntegrationFactory
when instantiating the class.
In your integration just add the following code to register the express.Router
component and define a route to handle GET
requests made to the /test
endpoint:
const router = express.Router();
router.get('/test', (req, res) => {
res.status(201);
res.json({ foo: 'bar' });
});
And then simply pass the router
instance when creating the IntegrationFactory
, before running it:
integration = new IntegrationFactory({
ordering: orderingIntegrationInstance,
loggerFactory,
appName: 'test-http-server',
router: router,
});
integration.run();
NOTE: The routes that you'll create in you integration are currently supporting only json body. This is because the json body-parser attached to the express app on its creation, as documented on ADR-05.
FAQs
Standard library used for various integrations
The npm package @flytio/int-sdk receives a total of 0 weekly downloads. As such, @flytio/int-sdk popularity was classified as not popular.
We found that @flytio/int-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.