@stackone/core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # @stackone/open-api
2
+
3
+ ## Description
4
+
5
+ This package contains all the core functionalities and abstractions used by StackOne products.
6
+
7
+ This package uses the tech stack provided by the **Connect Monorepo** global setup. Please check the [root README](../../README.md) for more information.
8
+
9
+ ## Requirements
10
+
11
+ Please check the [root README](../../README.md) for requirements.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ # install dependencies
17
+ $ npm run install
18
+ ```
19
+
20
+ ## Available commands
21
+
22
+ ```bash
23
+ # clean build output
24
+ $ npm run clean
25
+ ```
26
+
27
+ ```bash
28
+ # build package
29
+ $ npm run build
30
+ ```
31
+
32
+ ```bash
33
+ # run tests
34
+ $ npm run test
35
+ ```
36
+
37
+ ```bash
38
+ # run tests on watch mode
39
+ $ npm run test:watch
40
+ ```
41
+
42
+ ```bash
43
+ # run linter
44
+ $ npm run lint
45
+ ```
46
+
47
+ ```bash
48
+ # run linter and try to fix any error
49
+ $ npm run lint:fix
50
+ ```
@@ -0,0 +1,39 @@
1
+ import { IHttpClient } from '@stackone/transport';
2
+ import { Bundle, HttpOperation, HttpOperations, IConnector, Operation, Service } from './types';
3
+ export declare abstract class BaseConnector implements IConnector {
4
+ protected httpClient: IHttpClient;
5
+ version: string;
6
+ key: string;
7
+ name: string;
8
+ services: {
9
+ ats?: Service | undefined;
10
+ crm?: Service | undefined;
11
+ hris?: Service | undefined;
12
+ marketing?: Service | undefined;
13
+ };
14
+ httpOperations?: HttpOperations;
15
+ auth?: unknown;
16
+ proxy?: Operation;
17
+ constructor({ version, key, name, services, httpOperations, auth, proxy, httpClient, }: {
18
+ version?: string;
19
+ key: string;
20
+ name: string;
21
+ services?: {
22
+ ats?: Service | undefined;
23
+ crm?: Service | undefined;
24
+ hris?: Service | undefined;
25
+ marketing?: Service | undefined;
26
+ };
27
+ httpOperations?: HttpOperations;
28
+ auth?: unknown;
29
+ proxy?: Operation;
30
+ httpClient?: IHttpClient;
31
+ });
32
+ listOperations: () => string[];
33
+ getOperation: (operationId: string) => HttpOperation;
34
+ callOperation: ({ operationId, params, credentials, }: {
35
+ operationId: string;
36
+ params?: Record<string, unknown> | undefined;
37
+ credentials?: unknown;
38
+ }) => Promise<Bundle>;
39
+ }
@@ -0,0 +1 @@
1
+ export declare const REQUEST_BODY_PARAM = "request_body";
@@ -0,0 +1,3 @@
1
+ export { IConnector, HttpOperations, HttpParameter, HttpParameterLocation, HttpParameterType, } from './types';
2
+ export { BaseConnector } from './baseConnector';
3
+ export { REQUEST_BODY_PARAM } from './constants';
@@ -0,0 +1 @@
1
+ import{HttpClient as t}from"@stackone/transport";class e{constructor({version:e="1",key:r,name:s,services:o={},httpOperations:a={},auth:i,proxy:n,httpClient:h=new t}){this.listOperations=()=>Object.keys(this.httpOperations||{}),this.getOperation=t=>{const e=this.httpOperations?.[t];if(!e)throw new Error(`Operation ${t} not found`);return e},this.callOperation=async({operationId:t,params:e,credentials:r})=>{const s=this.httpOperations?.[t];if(!s)throw new Error(`Operation ${t} not found`);const o=(({params:t,httpOperation:e})=>{const{url:r,method:s}=e;let o=r;const a=[],i=[],n={};let h;Object.entries(t||{}).forEach((([t,r])=>{const s=e.parameters?.[t];if(s)switch(s.in){case"path":o=o.replace(`{${t}}`,r).replace(`:${t}`,r);break;case"query":a.push(`${t}=${r}`);break;case"header":n[t]=r;break;case"cookie":i.push(`${t}=${r}; `);break;case"body":h=r}}));const p=a.length>0?`?${a.join("&")}`:"";return i.length>0&&(n.cookie=i.join("")),{url:`${o}${p}`,method:s,headers:Object.keys(n).length>0?n:void 0,body:h||void 0}})({params:e,httpOperation:s}),{method:a,url:i,headers:n,body:h}=o,{apiKey:p}=r;return{connector:this,input:{operationId:t,params:e},response:await this.httpClient.request({method:a,url:i,headers:{...n,authorization:p},payload:h}),credentials:r}},this.version=e,this.key=r,this.name=s,this.services=o,this.httpOperations=a,this.auth=i,this.proxy=n,this.httpClient=h}}const r="request_body";export{e as BaseConnector,r as REQUEST_BODY_PARAM};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var t=require("@stackone/transport");exports.BaseConnector=class{constructor({version:e="1",key:r,name:s,services:o={},httpOperations:a={},auth:i,proxy:n,httpClient:h=new t.HttpClient}){this.listOperations=()=>Object.keys(this.httpOperations||{}),this.getOperation=t=>{const e=this.httpOperations?.[t];if(!e)throw new Error(`Operation ${t} not found`);return e},this.callOperation=async({operationId:t,params:e,credentials:r})=>{const s=this.httpOperations?.[t];if(!s)throw new Error(`Operation ${t} not found`);const o=(({params:t,httpOperation:e})=>{const{url:r,method:s}=e;let o=r;const a=[],i=[],n={};let h;Object.entries(t||{}).forEach((([t,r])=>{const s=e.parameters?.[t];if(s)switch(s.in){case"path":o=o.replace(`{${t}}`,r).replace(`:${t}`,r);break;case"query":a.push(`${t}=${r}`);break;case"header":n[t]=r;break;case"cookie":i.push(`${t}=${r}; `);break;case"body":h=r}}));const p=a.length>0?`?${a.join("&")}`:"";return i.length>0&&(n.cookie=i.join("")),{url:`${o}${p}`,method:s,headers:Object.keys(n).length>0?n:void 0,body:h||void 0}})({params:e,httpOperation:s}),{method:a,url:i,headers:n,body:h}=o,{apiKey:p}=r;return{connector:this,input:{operationId:t,params:e},response:await this.httpClient.request({method:a,url:i,headers:{...n,authorization:p},payload:h}),credentials:r}},this.version=e,this.key=r,this.name=s,this.services=o,this.httpOperations=a,this.auth=i,this.proxy=n,this.httpClient=h}},exports.REQUEST_BODY_PARAM="request_body";
@@ -0,0 +1,11 @@
1
+ import { HttpMethod } from '@stackone/transport';
2
+ import { HttpOperation } from './types';
3
+ export declare const mapParametersToHttpRequest: ({ params, httpOperation, }: {
4
+ params?: Record<string, unknown> | undefined;
5
+ httpOperation: HttpOperation;
6
+ }) => {
7
+ url: string;
8
+ method: HttpMethod;
9
+ headers?: Record<string, unknown> | undefined;
10
+ body?: Record<string, unknown> | undefined;
11
+ };
@@ -0,0 +1,64 @@
1
+ import { IHttpClient, HttpResponse, HttpMethod } from '@stackone/transport';
2
+ export type RequestParameters = {
3
+ id?: string | number;
4
+ body?: Record<string, unknown>;
5
+ [key: string]: unknown;
6
+ };
7
+ export type Operation = ({ input, credentials, getHttpClient, }: {
8
+ input: RequestParameters;
9
+ credentials?: unknown;
10
+ getHttpClient?: () => Promise<IHttpClient>;
11
+ }) => Promise<Bundle>;
12
+ export interface Resource {
13
+ [key: string]: Operation | Resource;
14
+ }
15
+ export interface Service {
16
+ [key: string]: Resource;
17
+ }
18
+ export type Bundle = {
19
+ connector: IConnector;
20
+ input: RequestParameters;
21
+ credentials: unknown;
22
+ url?: string;
23
+ response?: HttpResponse;
24
+ };
25
+ export type AuthenticationConfig = {
26
+ [authentication: string]: Environment;
27
+ };
28
+ export type Environment = {
29
+ default: AuthenticationConfig;
30
+ production: AuthenticationConfig;
31
+ } & {
32
+ [environment: string]: AuthenticationConfig;
33
+ };
34
+ export type HttpParameterLocation = 'path' | 'query' | 'header' | 'cookie' | 'body';
35
+ export type HttpParameterType = 'boolean' | 'object' | 'number' | 'string' | 'integer';
36
+ export interface HttpParameter {
37
+ in: HttpParameterLocation;
38
+ type: HttpParameterType;
39
+ isArray?: boolean;
40
+ }
41
+ export type HttpOperation = {
42
+ url: string;
43
+ method: HttpMethod;
44
+ parameters?: {
45
+ [key: string]: HttpParameter;
46
+ };
47
+ };
48
+ export type HttpOperations = {
49
+ [key: string]: HttpOperation;
50
+ };
51
+ export interface IConnector {
52
+ version: string;
53
+ key: string;
54
+ name: string;
55
+ services: {
56
+ ats?: Service;
57
+ crm?: Service;
58
+ hris?: Service;
59
+ marketing?: Service;
60
+ };
61
+ httpOperations?: HttpOperations;
62
+ auth?: unknown;
63
+ proxy?: Operation;
64
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@stackone/core",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.es.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "package.json",
11
+ "README.md"
12
+ ],
13
+ "scripts": {
14
+ "clean": "rimraf dist",
15
+ "prebuild": "npm run clean",
16
+ "build": "rollup -c",
17
+ "lint": "tsc --project tsconfig.json && eslint \"src/**/*.ts\"",
18
+ "lint:fix": "npm run lint -- --fix",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest watch",
21
+ "publish": "npm publish --access=public"
22
+ },
23
+ "keywords": [],
24
+ "author": "StackOne",
25
+ "license": "ISC",
26
+ "dependencies": {
27
+ "@stackone/transport": "*"
28
+ }
29
+ }