UNPKG

@hijiriishi/piece-myjvn

Version:

This package is an Activepieces piece for integrating with MyJVM. Information on vulnerabilities and countermeasures for software used in Japan, provided through the MyJVN API.

98 lines 4.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProductList = void 0; const tslib_1 = require("tslib"); const pieces_framework_1 = require("@activepieces/pieces-framework"); const pieces_common_1 = require("@activepieces/pieces-common"); const pieces_common_2 = require("@activepieces/pieces-common"); const common_1 = require("../common"); const xml2js_1 = require("xml2js"); const zod_1 = require("zod"); exports.getProductList = (0, pieces_framework_1.createAction)({ name: 'get-productlist', displayName: 'Get Product List', description: 'fetch the list of Product names.', props: { startItem: pieces_framework_1.Property.Number({ displayName: 'startItem', description: 'Start entry index (1 or greater))', required: false, defaultValue: 1 }), maxCountItem: pieces_framework_1.Property.Number({ displayName: 'maxCountItem', description: 'Number of Entries to Retrieve (1 to 10000)', required: false, defaultValue: 10000 }), cpeName: pieces_framework_1.Property.Array({ displayName: 'cpeNames', description: 'CPE Product Name (Format: cpe:/{part}:{vendor}:{product})', required: false, defaultValue: [], }), vendorId: pieces_framework_1.Property.Array({ displayName: 'vendorIds', description: 'vendorId', required: false, defaultValue: [], }), productId: pieces_framework_1.Property.Array({ displayName: 'productIds', description: 'productId', required: false, defaultValue: [], }), keyword: pieces_framework_1.Property.ShortText({ displayName: 'keyword', description: 'Keyword for partial match search of vendor name', required: false, }), lang: common_1.myjvnCommon.lang, ft: common_1.myjvnCommon.ft, }, run(context) { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield pieces_common_2.propsValidation.validateZod(context.propsValue, { startItem: zod_1.z.number().min(1, 'startItem (1 or greater)').optional(), maxCountItem: zod_1.z.number().min(1).max(10000, 'maxCountItem (1 to 10000)').optional(), }); const { startItem, maxCountItem, cpeName, vendorId, productId, keyword, lang, ft } = context.propsValue; const payload = new URLSearchParams({ method: 'getProductList', feed: 'hnd', }); if (startItem) payload.append('startItem', startItem.toString()); if (maxCountItem) payload.append('maxCountItem', maxCountItem.toString()); if (cpeName && cpeName.length > 0) payload.append('cpeName', cpeName.join('+')); if (vendorId && vendorId.length > 0) payload.append('vendorId', vendorId.join('+')); if (productId && productId.length > 0) payload.append('productId', productId.join('+')); if (keyword) payload.append('keyword', keyword); if (lang) payload.append('lang', lang); const res = yield pieces_common_1.httpClient.sendRequest({ method: pieces_common_1.HttpMethod.POST, url: common_1.myjvnCommon.baseUrl, headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: payload.toString(), }); if (ft === 'json') { const parser = new xml2js_1.Parser({ explicitArray: false }); const jsonData = yield parser.parseStringPromise(res.body); return jsonData; } else { return res.body; } }); }, }); //# sourceMappingURL=get-productlist.js.map