ThingWorx Flow > ThingWorx Flow SDK > ThingWorx Flow SDK 개요
ThingWorx Flow SDK 개요
모든 커넥터 모듈에는 ThingWorx Flow 커넥터 SDK(예: ptc-flow-sdk)가 포함되어야 합니다. init 명령을 실행하면 이 모듈이 이미 포함된 package.json 파일이 생성됩니다.
ThingWorx Flow 서버는 flow-sdk를 사용하여 커넥터를 로드하고 커넥터에 포함된 연결, 작업, 트리거 및 조회에 액세스합니다.
ThingWorx Flow 커넥터 SDK는 커넥터 사용을 위해 다음 API도 제공합니다.
로깅
커넥터 내의 모든 로깅은 SDK에 제공된 로깅 API를 사용하여 기록되어야 합니다. 이렇게 해야 문제점을 효과적으로 디버깅할 수 있습니다. 로깅 API에 액세스하려면 소스 파일 맨 위의 node js 코드에 다음 줄을 추가합니다.
const logger = require('ptc-flow-sdk').getLogger('module-name')
위의 모듈 이름을 작업, 트리거, 조회 등의 이름으로 바꿉니다.
로거에는 4개의 메소드인 debug, error, warn, info가 있습니다. 상황에 따라 적절한 메소드를 사용합니다.
로그 문은 문자열과 JSON 객체를 로깅할 수 있습니다.
CustomFilters
CustomFilters는 JSON, 문자열 또는 숫자의 배열을 필터링하기 위한 도우미 API입니다. CustomFilters를 사용하여 작업 또는 트리거에 제공된 입력을 필터링할 수 있습니다. customFilters는 두 단계의 프로세스로 사용합니다. 첫 번째 단계는 아래와 같이 입력 스키마에 customFilters 속성을 만드는 것입니다. 이 작업을 수행해야 사용자가 GUI에서 연산자 및 피연산자를 선택할 수 있습니다.
"input": {
"type": "object",
"title": "Select Trigger",
"properties": {
"customFilters": {
"type": "array",
"title": "Custom Filters",
"items": {
"type": "object",
"title": "filter",
"properties": {
"input": {
"type": "string",
"title": "Input",
"minLength": 1
},
"operator": {
"type": "string",
"title": "Condition",
"enum": [
"Equals",
"Equals(Number)",
"GreaterThan",
"LessThan",
"Contains",
"DoesNotContains",
"matches",
"isNull",
"isEmpty",
"isNumber",
"isObject",
"isArray",
"isBoolean",
"isDate",
"isUndefined"
]
},
"expected": {
"type": "string",
"title": "Expected",
"minLength": 1
}
}
}
}
}
두 번째 단계는 CustomFilters API의 filter 메소드를 사용하는 것입니다. CustomFilters를 사용하기 위한 코드 조각은 다음과 같습니다.
//add the first line of the code to the top of the node js script
const customFilters = require('ptc-flow-sdk').CustomFilters;
function execute (input, options, output) {
run(input, options, function (err, data) {
if (err || !data) {
return output(err || 'empty')
}
customFilters.filter(input.customFilters, data, output
})
}
위의 코드 조각에서 run 메소드는 데이터 배열을 반환하는 http 호출과 같은 몇 가지 코드를 실행합니다. input.customFilters는 워크플로를 설계하는 동안 사용자가 이전에 선택한 필터링 기준입니다. output은 필터링 결과와 함께 호출될 콜백 함수입니다.
helper
helper 객체에는 다수의 유틸리티 JavaScript 메소드가 있습니다.
toStr(obj) - 객체를 문자열로 변환합니다.
toISO(str) - 문자열 또는 문자열의 밀리초 표현을 ISO 형식 문자열로 변환합니다.
toNumber(obj) - 문자열을 숫자로 변환합니다.
clone() - 객체의 단순 복사를 수행합니다.
deepClone() - 객체의 전체 복사를 수행합니다.
mix(a,b) - ab 객체를 결합하여 ab 둘 다의 속성이 포함된 새 객체를 반환합니다.
도움이 되셨나요?