@stackone/core 1.0.0 → 1.2.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/dist/baseConnector.d.ts +2 -1
- package/dist/blocks/blockFunctionsConfigs.d.ts +2 -0
- package/dist/blocks/blockFunctionsFactory.d.ts +5 -0
- package/dist/blocks/blockPipe.d.ts +2 -0
- package/dist/blocks/functions/functionsDirectoryTypes.d.ts +10 -0
- package/dist/blocks/functions/map/mapBlockFunction.d.ts +2 -0
- package/dist/blocks/types.d.ts +24 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/responseMetaData.d.ts +3 -0
- package/dist/types.d.ts +25 -0
- package/package.json +3 -3
package/dist/baseConnector.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IHttpClient } from '@stackone/transport';
|
|
2
|
-
import { Bundle, HttpOperation, HttpOperations, IConnector, Operation, Service } from './types';
|
|
2
|
+
import { Bundle, HttpOperation, HttpOperations, IConnector, Operation, ResponseFieldMetaData, Service } from './types';
|
|
3
3
|
export declare abstract class BaseConnector implements IConnector {
|
|
4
4
|
protected httpClient: IHttpClient;
|
|
5
5
|
version: string;
|
|
@@ -31,6 +31,7 @@ export declare abstract class BaseConnector implements IConnector {
|
|
|
31
31
|
});
|
|
32
32
|
listOperations: () => string[];
|
|
33
33
|
getOperation: (operationId: string) => HttpOperation;
|
|
34
|
+
getOperationResponseFieldsMetadata: (operationId: string) => ResponseFieldMetaData[] | null;
|
|
34
35
|
callOperation: ({ operationId, params, credentials, }: {
|
|
35
36
|
operationId: string;
|
|
36
37
|
params?: Record<string, unknown> | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HttpResponse } from '@stackone/transport';
|
|
2
|
+
import { BlockFunctionType } from './functions/functionsDirectoryTypes';
|
|
3
|
+
export type Block = {
|
|
4
|
+
configs?: BlockFieldConfigs;
|
|
5
|
+
providerResponse?: HttpResponse;
|
|
6
|
+
result?: BlockIndexedRecord[] | BlockIndexedRecord;
|
|
7
|
+
context: BlockContext;
|
|
8
|
+
};
|
|
9
|
+
export type BlockContext = {
|
|
10
|
+
projectSecureId: string;
|
|
11
|
+
accountSecureId: string;
|
|
12
|
+
connector: string;
|
|
13
|
+
service: string;
|
|
14
|
+
resource: string;
|
|
15
|
+
operationType: string;
|
|
16
|
+
};
|
|
17
|
+
export type BlockFieldConfigs = {
|
|
18
|
+
[K in BlockFunctionType]?: unknown;
|
|
19
|
+
};
|
|
20
|
+
export type BlockIndexedRecord = {
|
|
21
|
+
id: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
export type BlockFunction = (block: Readonly<Block>) => Promise<Block>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export { IConnector, HttpOperations, HttpParameter, HttpParameterLocation, HttpParameterType, } from './types';
|
|
2
2
|
export { BaseConnector } from './baseConnector';
|
|
3
3
|
export { REQUEST_BODY_PARAM } from './constants';
|
|
4
|
+
export { Block, BlockFunction, BlockIndexedRecord, BlockContext, BlockFieldConfigs, } from './blocks/types';
|
|
5
|
+
export { BlockFunctionType } from './blocks/functions/functionsDirectoryTypes';
|
|
6
|
+
export { blockPipe } from './blocks/blockPipe';
|
|
7
|
+
export { getBlockPipeFunctionsFromConfig } from './blocks/blockFunctionsConfigs';
|
package/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HttpClient as t}from"@stackone/transport";
|
|
1
|
+
import{HttpClient as t}from"@stackone/transport";const e=(t,r="")=>{if("object"===t.type&&t.properties){const s=""===r||r.endsWith(".")?r:`${r}.`;return Object.entries(t.properties).flatMap((([t,r])=>e(r,`${s}${t}`)))}return"array"===t.type&&t.items?e(t.items,`${r}[].`):[{name:r.endsWith(".")?r.slice(0,-1):r,type:t.type,description:t.description}]};class r{constructor({version:r="1",key:s,name:n,services:o={},httpOperations:i={},auth:a,proxy:c,httpClient:p=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.getOperationResponseFieldsMetadata=t=>{const r=this.getOperation(t).responses;if(!r)return null;const s=(t=>{const e=Object.entries(t).find((([t])=>t.startsWith("2")));return e?e[1]:null})(r);return s&&s.content["application/json"]?.schema?e(s.content["application/json"]?.schema):null},this.callOperation=async({operationId:t,params:e,credentials:r})=>{const s=this.httpOperations?.[t];if(!s)throw new Error(`Operation ${t} not found`);const n=(({params:t,httpOperation:e})=>{const{url:r,method:s}=e;let n=r;const o=[],i=[],a={};let c;Object.entries(t||{}).forEach((([t,r])=>{const s=e.parameters?.[t];if(s)switch(s.in){case"path":n=n.replace(`{${t}}`,r).replace(`:${t}`,r);break;case"query":o.push(`${t}=${r}`);break;case"header":a[t]=r;break;case"cookie":i.push(`${t}=${r}; `);break;case"body":c=r}}));const p=o.length>0?`?${o.join("&")}`:"";return i.length>0&&(a.cookie=i.join("")),{url:`${n}${p}`,method:s,headers:Object.keys(a).length>0?a:void 0,body:c||void 0}})({params:e,httpOperation:s}),{method:o,url:i,headers:a,body:c}=n,{apiKey:p}=r;return{connector:this,input:{operationId:t,params:e},response:await this.httpClient.request({method:o,url:i,headers:{...a,authorization:p},payload:c}),credentials:r}},this.version=r,this.key=s,this.name=n,this.services=o,this.httpOperations=i,this.auth=a,this.proxy=c,this.httpClient=p}}const s="request_body";var n;!function(t){t.MAP="map"}(n||(n={}));const o=async(t,e)=>t.reduce((async(t,e)=>e(await t)),Promise.resolve(e)),i=async t=>{const e=t?.configs?.[n.MAP];if(!e)return t;let r;return r=Array.isArray(t.result)?t.result.map((r=>{const s=(t.providerResponse?.data?.[t.context.resource]).find((t=>t.id===r.id));return a(r,e,s)})):a(t.result,e,t.providerResponse?.data),{...t,result:r}},a=(t,e,r)=>{if(!r)return t;const s={...t};return e.forEach((t=>{const{expression:e,targetFieldKey:n}=t;r[e]&&(s[n]=r[e])})),{...s}};class c{static build(t){if(t===n.MAP)return i;throw new Error(`Unknown block function: ${t}`)}}const p=t=>Object.keys(t||{}).reduce(((t,e)=>{const r=c.build(e);return t.push(r),t}),[]);export{r as BaseConnector,n as BlockFunctionType,s as REQUEST_BODY_PARAM,o as blockPipe,p as getBlockPipeFunctionsFromConfig};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("@stackone/transport");exports.BaseConnector=class{constructor({version:
|
|
1
|
+
"use strict";var t=require("@stackone/transport");const e=(t,r="")=>{if("object"===t.type&&t.properties){const s=""===r||r.endsWith(".")?r:`${r}.`;return Object.entries(t.properties).flatMap((([t,r])=>e(r,`${s}${t}`)))}return"array"===t.type&&t.items?e(t.items,`${r}[].`):[{name:r.endsWith(".")?r.slice(0,-1):r,type:t.type,description:t.description}]};exports.BlockFunctionType=void 0,(exports.BlockFunctionType||(exports.BlockFunctionType={})).MAP="map";const r=async t=>{const e=t?.configs?.[exports.BlockFunctionType.MAP];if(!e)return t;let r;return r=Array.isArray(t.result)?t.result.map((r=>{const n=(t.providerResponse?.data?.[t.context.resource]).find((t=>t.id===r.id));return s(r,e,n)})):s(t.result,e,t.providerResponse?.data),{...t,result:r}},s=(t,e,r)=>{if(!r)return t;const s={...t};return e.forEach((t=>{const{expression:e,targetFieldKey:n}=t;r[e]&&(s[n]=r[e])})),{...s}};class n{static build(t){if(t===exports.BlockFunctionType.MAP)return r;throw new Error(`Unknown block function: ${t}`)}}exports.BaseConnector=class{constructor({version:r="1",key:s,name:n,services:o={},httpOperations:i={},auth:a,proxy:c,httpClient:p=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.getOperationResponseFieldsMetadata=t=>{const r=this.getOperation(t).responses;if(!r)return null;const s=(t=>{const e=Object.entries(t).find((([t])=>t.startsWith("2")));return e?e[1]:null})(r);return s&&s.content["application/json"]?.schema?e(s.content["application/json"]?.schema):null},this.callOperation=async({operationId:t,params:e,credentials:r})=>{const s=this.httpOperations?.[t];if(!s)throw new Error(`Operation ${t} not found`);const n=(({params:t,httpOperation:e})=>{const{url:r,method:s}=e;let n=r;const o=[],i=[],a={};let c;Object.entries(t||{}).forEach((([t,r])=>{const s=e.parameters?.[t];if(s)switch(s.in){case"path":n=n.replace(`{${t}}`,r).replace(`:${t}`,r);break;case"query":o.push(`${t}=${r}`);break;case"header":a[t]=r;break;case"cookie":i.push(`${t}=${r}; `);break;case"body":c=r}}));const p=o.length>0?`?${o.join("&")}`:"";return i.length>0&&(a.cookie=i.join("")),{url:`${n}${p}`,method:s,headers:Object.keys(a).length>0?a:void 0,body:c||void 0}})({params:e,httpOperation:s}),{method:o,url:i,headers:a,body:c}=n,{apiKey:p}=r;return{connector:this,input:{operationId:t,params:e},response:await this.httpClient.request({method:o,url:i,headers:{...a,authorization:p},payload:c}),credentials:r}},this.version=r,this.key=s,this.name=n,this.services=o,this.httpOperations=i,this.auth=a,this.proxy=c,this.httpClient=p}},exports.REQUEST_BODY_PARAM="request_body",exports.blockPipe=async(t,e)=>t.reduce((async(t,e)=>e(await t)),Promise.resolve(e)),exports.getBlockPipeFunctionsFromConfig=t=>Object.keys(t||{}).reduce(((t,e)=>{const r=n.build(e);return t.push(r),t}),[]);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { HttpParameterSchema, HttpResponses, HttpSchemaResponse, ResponseFieldMetaData } from './types';
|
|
2
|
+
export declare const getSuccessfulResponse: (responses: HttpResponses) => HttpSchemaResponse | null;
|
|
3
|
+
export declare const getResponseFieldsMetaData: (schema: HttpParameterSchema, parentFieldKey?: string) => ResponseFieldMetaData[];
|
package/dist/types.d.ts
CHANGED
|
@@ -38,12 +38,37 @@ export interface HttpParameter {
|
|
|
38
38
|
type: HttpParameterType;
|
|
39
39
|
isArray?: boolean;
|
|
40
40
|
}
|
|
41
|
+
export type HttpResponses = {
|
|
42
|
+
[key: string]: HttpSchemaResponse;
|
|
43
|
+
};
|
|
44
|
+
export type HttpSchemaResponse = {
|
|
45
|
+
description: string;
|
|
46
|
+
content: {
|
|
47
|
+
[key: string]: {
|
|
48
|
+
schema: HttpParameterSchema;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export type HttpParameterSchema = {
|
|
53
|
+
type: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
properties?: {
|
|
56
|
+
[key: string]: HttpParameterSchema;
|
|
57
|
+
};
|
|
58
|
+
items?: HttpParameterSchema;
|
|
59
|
+
};
|
|
60
|
+
export type ResponseFieldMetaData = {
|
|
61
|
+
name: string;
|
|
62
|
+
type: HttpParameterType;
|
|
63
|
+
description?: string;
|
|
64
|
+
};
|
|
41
65
|
export type HttpOperation = {
|
|
42
66
|
url: string;
|
|
43
67
|
method: HttpMethod;
|
|
44
68
|
parameters?: {
|
|
45
69
|
[key: string]: HttpParameter;
|
|
46
70
|
};
|
|
71
|
+
responses: HttpResponses;
|
|
47
72
|
};
|
|
48
73
|
export type HttpOperations = {
|
|
49
74
|
[key: string]: HttpOperation;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
9
|
"dist",
|
|
10
10
|
"package.json",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"lint:fix": "npm run lint -- --fix",
|
|
19
19
|
"test": "vitest run",
|
|
20
20
|
"test:watch": "vitest watch",
|
|
21
|
-
"publish": "npm publish --access=public"
|
|
21
|
+
"publish-release": "npm publish --access=public"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [],
|
|
24
24
|
"author": "StackOne",
|