@stackone/core 1.3.1 → 1.4.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/index.es.mjs CHANGED
@@ -1 +1 @@
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({blockFunctions:t,block:e})=>t.reduce((async(t,e)=>e({block:await t})),Promise.resolve(e)),i=async({block:t})=>{const e=t?.fieldConfigs?.[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({type:t}){if(t===n.MAP)return i;throw new Error(`Unknown block function: ${t}`)}}const p=({fieldConfigs:t})=>Object.keys(t||{}).reduce(((t,e)=>{const r=c.build({type:e});return t.push(r),t}),[]);export{r as BaseConnector,n as BlockFunctionType,s as REQUEST_BODY_PARAM,o as blockPipe,p as getBlockPipeFunctionsFromConfigs};
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",t.TYPECAST="typecast"}(n||(n={}));const o=async({blockFunctions:t,block:e})=>t.reduce((async(t,e)=>e({block:await t})),Promise.resolve(e)),i=async({block:t})=>{const e=t?.fieldConfigs?.[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({type:t}){if(t===n.MAP)return i;throw new Error(`Unknown block function: ${t}`)}}const p=({fieldConfigs:t})=>Object.keys(t||{}).reduce(((t,e)=>{const r=c.build({type:e});return t.push(r),t}),[]);export{r as BaseConnector,n as BlockFunctionType,s as REQUEST_BODY_PARAM,o as blockPipe,p as getBlockPipeFunctionsFromConfigs};
package/dist/index.js CHANGED
@@ -1 +1 @@
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({block:t})=>{const e=t?.fieldConfigs?.[exports.BlockFunctionType.MAP];if(!e)return t;let r;return r=Array.isArray(t.result)?t.result.map((r=>{const o=(t.providerResponse?.data?.[t.context.resource]).find((t=>t.id===r.id));return s(r,e,o)})):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:o}=t;r[e]&&(s[o]=r[e])})),{...s}};class o{static build({type: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:o,services:n={},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 o=(({params:t,httpOperation:e})=>{const{url:r,method:s}=e;let o=r;const n=[],i=[],a={};let c;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":n.push(`${t}=${r}`);break;case"header":a[t]=r;break;case"cookie":i.push(`${t}=${r}; `);break;case"body":c=r}}));const p=n.length>0?`?${n.join("&")}`:"";return i.length>0&&(a.cookie=i.join("")),{url:`${o}${p}`,method:s,headers:Object.keys(a).length>0?a:void 0,body:c||void 0}})({params:e,httpOperation:s}),{method:n,url:i,headers:a,body:c}=o,{apiKey:p}=r;return{connector:this,input:{operationId:t,params:e},response:await this.httpClient.request({method:n,url:i,headers:{...a,authorization:p},payload:c}),credentials:r}},this.version=r,this.key=s,this.name=o,this.services=n,this.httpOperations=i,this.auth=a,this.proxy=c,this.httpClient=p}},exports.REQUEST_BODY_PARAM="request_body",exports.blockPipe=async({blockFunctions:t,block:e})=>t.reduce((async(t,e)=>e({block:await t})),Promise.resolve(e)),exports.getBlockPipeFunctionsFromConfigs=({fieldConfigs:t})=>Object.keys(t||{}).reduce(((t,e)=>{const r=o.build({type:e});return t.push(r),t}),[]);
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}]};var r;exports.BlockFunctionType=void 0,(r=exports.BlockFunctionType||(exports.BlockFunctionType={})).MAP="map",r.TYPECAST="typecast";const s=async({block:t})=>{const e=t?.fieldConfigs?.[exports.BlockFunctionType.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 o(r,e,s)})):o(t.result,e,t.providerResponse?.data),{...t,result:r}},o=(t,e,r)=>{if(!r)return t;const s={...t};return e.forEach((t=>{const{expression:e,targetFieldKey:o}=t;r[e]&&(s[o]=r[e])})),{...s}};class n{static build({type:t}){if(t===exports.BlockFunctionType.MAP)return s;throw new Error(`Unknown block function: ${t}`)}}exports.BaseConnector=class{constructor({version:r="1",key:s,name:o,services:n={},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 o=(({params:t,httpOperation:e})=>{const{url:r,method:s}=e;let o=r;const n=[],i=[],a={};let c;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":n.push(`${t}=${r}`);break;case"header":a[t]=r;break;case"cookie":i.push(`${t}=${r}; `);break;case"body":c=r}}));const p=n.length>0?`?${n.join("&")}`:"";return i.length>0&&(a.cookie=i.join("")),{url:`${o}${p}`,method:s,headers:Object.keys(a).length>0?a:void 0,body:c||void 0}})({params:e,httpOperation:s}),{method:n,url:i,headers:a,body:c}=o,{apiKey:p}=r;return{connector:this,input:{operationId:t,params:e},response:await this.httpClient.request({method:n,url:i,headers:{...a,authorization:p},payload:c}),credentials:r}},this.version=r,this.key=s,this.name=o,this.services=n,this.httpOperations=i,this.auth=a,this.proxy=c,this.httpClient=p}},exports.REQUEST_BODY_PARAM="request_body",exports.blockPipe=async({blockFunctions:t,block:e})=>t.reduce((async(t,e)=>e({block:await t})),Promise.resolve(e)),exports.getBlockPipeFunctionsFromConfigs=({fieldConfigs:t})=>Object.keys(t||{}).reduce(((t,e)=>{const r=n.build({type:e});return t.push(r),t}),[]);
@@ -1,5 +1,6 @@
1
1
  export declare enum BlockFunctionType {
2
- MAP = "map"
2
+ MAP = "map",
3
+ TYPECAST = "typecast"
3
4
  }
4
5
  export type BlockFunctionArgs = {
5
6
  [BlockFunctionType.MAP]: {
@@ -7,4 +8,8 @@ export type BlockFunctionArgs = {
7
8
  targetFieldKey: string;
8
9
  type: string;
9
10
  };
11
+ [BlockFunctionType.TYPECAST]: {
12
+ targetFieldKey: string;
13
+ type: string;
14
+ };
10
15
  };
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
2
+ export declare const FALLBACK_DATE_FORMATS: string[];
@@ -0,0 +1,17 @@
1
+ export declare const safeParseToString: ({ value, }: {
2
+ value: unknown;
3
+ }) => string | null;
4
+ export declare const safeParseToNumber: ({ value, }: {
5
+ value: unknown;
6
+ }) => number | null;
7
+ export declare const safeParseToBoolean: ({ value, }: {
8
+ value: unknown;
9
+ }) => boolean | null;
10
+ export declare const safeParseToDateTime: ({ value, format, }: {
11
+ value: unknown;
12
+ format?: string | undefined;
13
+ }) => Date | null;
14
+ export declare const safeParseToDateTimeString: ({ value, format, }: {
15
+ value: unknown;
16
+ format?: string | undefined;
17
+ }) => string | null;
@@ -0,0 +1,6 @@
1
+ export declare const typecast: ({ value, type, format, }: {
2
+ value: unknown;
3
+ type: string;
4
+ format?: string | undefined;
5
+ }) => unknown | null;
6
+ export declare const isFieldSupportedType: (type: string) => boolean;
@@ -0,0 +1,2 @@
1
+ import { BlockFunction } from '../../types';
2
+ export declare const typecastBlockFunction: BlockFunction;
@@ -0,0 +1,6 @@
1
+ export declare enum FieldSupportedTypes {
2
+ String = "string",
3
+ Number = "number",
4
+ Boolean = "boolean",
5
+ DateTime = "datetime"
6
+ }
@@ -0,0 +1,7 @@
1
+ export declare const notMissing: <T>(value: T | null | undefined) => value is T;
2
+ export declare const isMissing: <T>(value: T | null | undefined) => boolean;
3
+ export declare const isString: (value: unknown) => value is string;
4
+ export declare const isNumber: (value: unknown) => value is number;
5
+ export declare const isBoolean: (value: unknown) => value is boolean;
6
+ export declare const isDate: (value: unknown) => value is Date;
7
+ export declare const isObject: (value: unknown) => value is Record<string, unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackone/core",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -16,14 +16,15 @@
16
16
  "build": "rollup -c",
17
17
  "lint": "tsc --project tsconfig.json && eslint \"src/**/*.ts\"",
18
18
  "lint:fix": "npm run lint -- --fix",
19
- "test": "vitest run",
20
- "test:watch": "vitest watch",
19
+ "test": "vitest run --silent",
20
+ "test:watch": "vitest watch --silent",
21
21
  "publish-release": "npm publish --access=public"
22
22
  },
23
23
  "keywords": [],
24
24
  "author": "StackOne",
25
25
  "license": "ISC",
26
26
  "dependencies": {
27
- "@stackone/transport": "*"
27
+ "@stackone/transport": "*",
28
+ "date-fns": "^3.4.0"
28
29
  }
29
30
  }