@stackone/core 1.19.0 → 1.20.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 +1 -1
- package/dist/index.js +1 -1
- package/dist/types/blocks/types.d.ts +0 -22
- package/dist/types/index.d.ts +0 -2
- package/dist/types/stepFunctions/mapFields/mapFieldsStepFunction.d.ts +1 -1
- package/dist/types/stepFunctions/types.d.ts +0 -1
- package/dist/types/steps/types.d.ts +2 -3
- package/package.json +3 -4
- package/dist/types/stepFunctions/getFieldMappingStepFunctions.d.ts +0 -5
- package/dist/types/stepFunctions/map/mapStepFunction.d.ts +0 -2
- package/dist/types/steps/stepsRunners.d.ts +0 -6
package/dist/index.es.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{evaluate as e}from"@stackone/expressions";import{isDate as r,isString as t,isBoolean as n,isNumber as s,isObject as u,isMissing as i,notMissing as o}from"@stackone/utils";import*as a from"date-fns";var l;!function(e){e.TYPECAST="typecast",e.MAP_FIELDS="map_fields"}(l||(l={}));const d=async({block:e})=>{const r=e?.fieldConfigs,t=[],n=e.steps;if(!r||"disabled"===e?.debug?.custom_mappings||!n)return e;let s;if(Array.isArray(e.result)){const u=e.result.length;s=e.result.map(((e,s)=>{const i=c(n,u,s),o=y(e,r,i);return t.push(...o.errors||[]),o.record}))}else{const u=y(e.result,r,n);s=u.record,t.push(...u.errors||[])}const u={output:{data:s},errors:Object.keys(t).length>0?t:void 0};return{...e,result:s,steps:{...n,[l.MAP_FIELDS.toString()]:u}}},c=(e,r,t)=>Object.entries(e).reduce(((e,[n,s])=>{const u=s?.output?.data;return Array.isArray(u)&&u.length===r?e[n]={output:{data:u[t]}}:e[n]=s,e}),{}),y=(e,r,t)=>{if(!e||!t)return{record:e};const n={unified:{...e},..."object"==typeof t?t:{}},s={},u=[],i={...e};for(const t of r){const{error:r,value:o}=f(n,e.id,t);r?u.push(r):t.isUnified?i[t.targetFieldKey]=o:s[t.targetFieldKey]=o}return{record:{...i,unified_custom_fields:Object.keys(s).length>0?s:void 0},errors:u.length>0?u:void 0}},f=(r,t,n)=>{const{expression:s,targetFieldKey:u}=n;if(!s)return{error:{message:"Expression is empty",id:t,targetField:u}};let i;try{i=e(s,r)}catch(e){return{error:{message:"Invalid expression",id:t,targetField:u}}}return void 0===i?{error:{message:"Expression returned no value",id:t,targetField:u}}:{value:i}},m="yyyy-MM-dd",p=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],g=({value:e})=>{const r=a.parseISO(e);if(a.isValid(r))return r;const t=new Date;for(const r of p){const n=a.parse(e,r,t);if(a.isValid(n))return n.setUTCHours(0,0,0,0),n}return null},v=({value:e,format:n=m})=>{const s=(({value:e,format:n=m})=>{if(r(e))return e;if(!t(e))return null;try{const r=a.parse(e,n,new Date);return a.isValid(r)?r:g({value:e})}catch(e){return null}})({value:e,format:n});return s?s.toISOString():null};var M;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(M||(M={}));const b=({value:e,type:o,format:a})=>{if(i(e))return null;switch(o){case M.String:return(({value:e})=>t(e)?e:r(e)?e.toISOString():u(e)?JSON.stringify(e):String(e))({value:e});case M.Number:return(({value:e})=>{if(s(e))return e;if(r(e))return null;const t=Number(e);return isNaN(t)?null:t})({value:e});case M.Boolean:return(({value:e})=>n(e)?e:"false"!==e&&"0"!==e&&0!==e&&Boolean(e))({value:e});case M.DateTimeString:return v({value:e,format:a});default:return e}},S=async({block:e})=>{const r=e?.fieldConfigs;if(!r||"disabled"===e?.debug?.custom_mappings)return e;let t;return t=Array.isArray(e.result)?e.result.map((e=>_(e,r))):_(e.result,r),{...e,result:t}},_=(e,r)=>{const t={...e};return r.forEach((r=>{const{targetFieldKey:n,type:s}=r;(e=>Object.values(M).includes(e))(s)&&(r.isUnified&&o(t[n])?t[n]=b({value:e[n],type:s}):t.unified_custom_fields&&o(t.unified_custom_fields?.[n])&&(t.unified_custom_fields[n]=b({value:e.unified_custom_fields?.[n],type:s})))})),{...t}},h={build({functionName:e}){switch(e){case l.TYPECAST:return S;case l.MAP_FIELDS:return d;default:throw new Error(`Unknown step function: ${e}`)}}};export{l as StepFunctionName,h as StepFunctionsFactory};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
1
|
+
"use strict";var e=require("@stackone/expressions"),t=require("@stackone/utils");function r(e){var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var n,s=r(require("date-fns"));exports.StepFunctionName=void 0,(n=exports.StepFunctionName||(exports.StepFunctionName={})).TYPECAST="typecast",n.MAP_FIELDS="map_fields";const i=async({block:e})=>{const t=e?.fieldConfigs,r=[],n=e.steps;if(!t||"disabled"===e?.debug?.custom_mappings||!n)return e;let s;if(Array.isArray(e.result)){const i=e.result.length;s=e.result.map(((e,s)=>{const a=u(n,i,s),l=o(e,t,a);return r.push(...l.errors||[]),l.record}))}else{const i=o(e.result,t,n);s=i.record,r.push(...i.errors||[])}const i={output:{data:s},errors:Object.keys(r).length>0?r:void 0};return{...e,result:s,steps:{...n,[exports.StepFunctionName.MAP_FIELDS.toString()]:i}}},u=(e,t,r)=>Object.entries(e).reduce(((e,[n,s])=>{const i=s?.output?.data;return Array.isArray(i)&&i.length===t?e[n]={output:{data:i[r]}}:e[n]=s,e}),{}),o=(e,t,r)=>{if(!e||!r)return{record:e};const n={unified:{...e},..."object"==typeof r?r:{}},s={},i=[],u={...e};for(const r of t){const{error:t,value:o}=a(n,e.id,r);t?i.push(t):r.isUnified?u[r.targetFieldKey]=o:s[r.targetFieldKey]=o}return{record:{...u,unified_custom_fields:Object.keys(s).length>0?s:void 0},errors:i.length>0?i:void 0}},a=(t,r,n)=>{const{expression:s,targetFieldKey:i}=n;if(!s)return{error:{message:"Expression is empty",id:r,targetField:i}};let u;try{u=e.evaluate(s,t)}catch(e){return{error:{message:"Invalid expression",id:r,targetField:i}}}return void 0===u?{error:{message:"Expression returned no value",id:r,targetField:i}}:{value:u}},l="yyyy-MM-dd",c=["yyyy-MM-dd","yyyy/MM/dd","dd/MM/yyyy","dd-MM-yyyy","yyyy-dd-MM","yyyy/dd/MM","MM/dd/yyyy","MM-dd-yyyy"],d=({value:e})=>{const t=s.parseISO(e);if(s.isValid(t))return t;const r=new Date;for(const t of c){const n=s.parse(e,t,r);if(s.isValid(n))return n.setUTCHours(0,0,0,0),n}return null},y=({value:e,format:r=l})=>{const n=(({value:e,format:r=l})=>{if(t.isDate(e))return e;if(!t.isString(e))return null;try{const t=s.parse(e,r,new Date);return s.isValid(t)?t:d({value:e})}catch(e){return null}})({value:e,format:r});return n?n.toISOString():null};var f;!function(e){e.String="string",e.Number="number",e.Boolean="boolean",e.DateTimeString="datetime_string"}(f||(f={}));const p=({value:e,type:r,format:n})=>{if(t.isMissing(e))return null;switch(r){case f.String:return(({value:e})=>t.isString(e)?e:t.isDate(e)?e.toISOString():t.isObject(e)?JSON.stringify(e):String(e))({value:e});case f.Number:return(({value:e})=>{if(t.isNumber(e))return e;if(t.isDate(e))return null;const r=Number(e);return isNaN(r)?null:r})({value:e});case f.Boolean:return(({value:e})=>t.isBoolean(e)?e:"false"!==e&&"0"!==e&&0!==e&&Boolean(e))({value:e});case f.DateTimeString:return y({value:e,format:n});default:return e}},g=async({block:e})=>{const t=e?.fieldConfigs;if(!t||"disabled"===e?.debug?.custom_mappings)return e;let r;return r=Array.isArray(e.result)?e.result.map((e=>m(e,t))):m(e.result,t),{...e,result:r}},m=(e,r)=>{const n={...e};return r.forEach((r=>{const{targetFieldKey:s,type:i}=r;(e=>Object.values(f).includes(e))(i)&&(r.isUnified&&t.notMissing(n[s])?n[s]=p({value:e[s],type:i}):n.unified_custom_fields&&t.notMissing(n.unified_custom_fields?.[s])&&(n.unified_custom_fields[s]=p({value:e.unified_custom_fields?.[s],type:i})))})),{...n}},v={build({functionName:e}){switch(e){case exports.StepFunctionName.TYPECAST:return g;case exports.StepFunctionName.MAP_FIELDS:return i;default:throw new Error(`Unknown step function: ${e}`)}}};exports.StepFunctionsFactory=v;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { HttpMethod } from '@stackone/transport';
|
|
2
1
|
import type { StepsSnapshots } from '../steps/types';
|
|
3
2
|
export type Block = {
|
|
4
3
|
fieldConfigs?: FieldConfig[];
|
|
@@ -6,8 +5,6 @@ export type Block = {
|
|
|
6
5
|
context: BlockContext;
|
|
7
6
|
debug?: DebugParams;
|
|
8
7
|
steps?: StepsSnapshots;
|
|
9
|
-
customMappingErrors?: FieldMappingError[];
|
|
10
|
-
providerData?: ProviderData;
|
|
11
8
|
};
|
|
12
9
|
export type BlockContext = {
|
|
13
10
|
projectSecureId: string;
|
|
@@ -36,22 +33,3 @@ export type FieldConfig = {
|
|
|
36
33
|
export type DebugParams = {
|
|
37
34
|
custom_mappings?: 'disabled' | 'enabled';
|
|
38
35
|
};
|
|
39
|
-
export type ProviderData = {
|
|
40
|
-
[key: string]: ProviderDataObject;
|
|
41
|
-
};
|
|
42
|
-
export type ProviderDataObject<T = unknown> = {
|
|
43
|
-
[key: string]: T | ProviderDataRequestDetails;
|
|
44
|
-
request_details: ProviderDataRequestDetails;
|
|
45
|
-
};
|
|
46
|
-
export type ProviderDataRequestDetails = {
|
|
47
|
-
method: HttpMethod;
|
|
48
|
-
url: string;
|
|
49
|
-
body?: {
|
|
50
|
-
[key: string]: string | number | boolean;
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
export type FieldMappingError = {
|
|
54
|
-
id?: string;
|
|
55
|
-
message: string;
|
|
56
|
-
targetField: string;
|
|
57
|
-
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export { Block, BlockIndexedRecord, BlockContext, FieldConfig, } from './blocks/types';
|
|
2
2
|
export { StepFunction, StepFunctionParams, StepFunctionName } from './stepFunctions/types';
|
|
3
3
|
export { StepsSnapshots } from './steps/types';
|
|
4
|
-
export { stepsBasicPipeRunner } from './steps/stepsRunners';
|
|
5
|
-
export { getFieldMappingStepFunctions } from './stepFunctions/getFieldMappingStepFunctions';
|
|
6
4
|
export { StepFunctionsFactory } from './stepFunctions/factory';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { StepFunction } from '../types';
|
|
2
2
|
export declare const mapFieldsStepFunction: StepFunction;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export type StepSnapshot = {
|
|
2
|
-
output
|
|
2
|
+
output?: {
|
|
3
3
|
data: unknown;
|
|
4
|
-
matcher?: string;
|
|
5
4
|
};
|
|
6
5
|
errors?: StepError[];
|
|
7
6
|
};
|
|
@@ -9,5 +8,5 @@ export type StepsSnapshots = {
|
|
|
9
8
|
[key: string]: StepSnapshot;
|
|
10
9
|
};
|
|
11
10
|
export type StepError = {
|
|
12
|
-
|
|
11
|
+
[key: string]: unknown;
|
|
13
12
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackone/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.es.mjs",
|
|
@@ -32,11 +32,10 @@
|
|
|
32
32
|
"author": "StackOne",
|
|
33
33
|
"license": "ISC",
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@stackone/expressions": "*",
|
|
35
36
|
"@stackone/transport": "*",
|
|
36
37
|
"@stackone/utils": "*",
|
|
37
|
-
"
|
|
38
|
-
"date-fns": "^3.4.0",
|
|
39
|
-
"jsonpath": "^1.1.1"
|
|
38
|
+
"date-fns": "^3.4.0"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@types/jsonpath": "^0.2.4"
|