@stackone/core 1.0.0 → 1.1.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.
@@ -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;
package/dist/index.es.mjs CHANGED
@@ -1 +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};
1
+ import{HttpClient as t}from"@stackone/transport";const e=(t,s="")=>{let r=[];if("object"===t.type&&t.properties){const n=""===s||s.endsWith(".")?s:`${s}.`;for(const s in t.properties)r=r.concat(e(t.properties[s],`${n}${s}`))}else"array"===t.type&&t.items?r=r.concat(e(t.items,`${s}[].`)):r.push({name:s.endsWith(".")?s.slice(0,-1):s,type:t.type,description:t.description});return r};class s{constructor({version:s="1",key:r,name:n,services:o={},httpOperations:i={},auth:a,proxy:p,httpClient:c=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 s=this.getOperation(t).responses;if(!s)return null;const r=(t=>{const e=Object.entries(t).find((([t])=>t.startsWith("2")));return e?e[1]:null})(s);return r&&r.content["application/json"]?.schema?e(r.content["application/json"]?.schema):null},this.callOperation=async({operationId:t,params:e,credentials:s})=>{const r=this.httpOperations?.[t];if(!r)throw new Error(`Operation ${t} not found`);const n=(({params:t,httpOperation:e})=>{const{url:s,method:r}=e;let n=s;const o=[],i=[],a={};let p;Object.entries(t||{}).forEach((([t,s])=>{const r=e.parameters?.[t];if(r)switch(r.in){case"path":n=n.replace(`{${t}}`,s).replace(`:${t}`,s);break;case"query":o.push(`${t}=${s}`);break;case"header":a[t]=s;break;case"cookie":i.push(`${t}=${s}; `);break;case"body":p=s}}));const c=o.length>0?`?${o.join("&")}`:"";return i.length>0&&(a.cookie=i.join("")),{url:`${n}${c}`,method:r,headers:Object.keys(a).length>0?a:void 0,body:p||void 0}})({params:e,httpOperation:r}),{method:o,url:i,headers:a,body:p}=n,{apiKey:c}=s;return{connector:this,input:{operationId:t,params:e},response:await this.httpClient.request({method:o,url:i,headers:{...a,authorization:c},payload:p}),credentials:s}},this.version=s,this.key=r,this.name=n,this.services=o,this.httpOperations=i,this.auth=a,this.proxy=p,this.httpClient=c}}const r="request_body";export{s as BaseConnector,r as REQUEST_BODY_PARAM};
package/dist/index.js CHANGED
@@ -1 +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";
1
+ "use strict";var t=require("@stackone/transport");const e=(t,s="")=>{let r=[];if("object"===t.type&&t.properties){const n=""===s||s.endsWith(".")?s:`${s}.`;for(const s in t.properties)r=r.concat(e(t.properties[s],`${n}${s}`))}else"array"===t.type&&t.items?r=r.concat(e(t.items,`${s}[].`)):r.push({name:s.endsWith(".")?s.slice(0,-1):s,type:t.type,description:t.description});return r};exports.BaseConnector=class{constructor({version:s="1",key:r,name:n,services:o={},httpOperations:i={},auth:a,proxy:p,httpClient:c=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 s=this.getOperation(t).responses;if(!s)return null;const r=(t=>{const e=Object.entries(t).find((([t])=>t.startsWith("2")));return e?e[1]:null})(s);return r&&r.content["application/json"]?.schema?e(r.content["application/json"]?.schema):null},this.callOperation=async({operationId:t,params:e,credentials:s})=>{const r=this.httpOperations?.[t];if(!r)throw new Error(`Operation ${t} not found`);const n=(({params:t,httpOperation:e})=>{const{url:s,method:r}=e;let n=s;const o=[],i=[],a={};let p;Object.entries(t||{}).forEach((([t,s])=>{const r=e.parameters?.[t];if(r)switch(r.in){case"path":n=n.replace(`{${t}}`,s).replace(`:${t}`,s);break;case"query":o.push(`${t}=${s}`);break;case"header":a[t]=s;break;case"cookie":i.push(`${t}=${s}; `);break;case"body":p=s}}));const c=o.length>0?`?${o.join("&")}`:"";return i.length>0&&(a.cookie=i.join("")),{url:`${n}${c}`,method:r,headers:Object.keys(a).length>0?a:void 0,body:p||void 0}})({params:e,httpOperation:r}),{method:o,url:i,headers:a,body:p}=n,{apiKey:c}=s;return{connector:this,input:{operationId:t,params:e},response:await this.httpClient.request({method:o,url:i,headers:{...a,authorization:c},payload:p}),credentials:s}},this.version=s,this.key=r,this.name=n,this.services=o,this.httpOperations=i,this.auth=a,this.proxy=p,this.httpClient=c}},exports.REQUEST_BODY_PARAM="request_body";
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/core",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -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",