-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support fetching payload from paths and URLs * ci: add prepare and tests jobs * ci: make self-test depend on 'tests'' job * test: add cover test * ci: add self test using path payload * ci: add dispatch test for payload url
- Loading branch information
Showing
16 changed files
with
9,633 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PayloadResolver = void 0; | ||
const fs_1 = require("fs"); | ||
const path_1 = require("path"); | ||
const got_1 = require("got"); | ||
const process_1 = require("process"); | ||
const util_1 = require("util"); | ||
class PayloadResolver { | ||
static fromString(payload) { | ||
try { | ||
return JSON.parse(payload); | ||
} | ||
catch (error) { | ||
throw new Error(`An error ocurred while parsing the payload: ${error.message}`); | ||
} | ||
} | ||
static async fromPath(path) { | ||
let content; | ||
try { | ||
const filePath = path_1.resolve(process_1.cwd(), path); | ||
const asyncReadFile = util_1.promisify(fs_1.readFile); | ||
content = await asyncReadFile(filePath, { encoding: 'utf8' }); | ||
} | ||
catch (error) { | ||
throw new Error(`An error ocurred while reading the payload from ${path}: ${error.message}`); | ||
} | ||
try { | ||
return JSON.parse(content); | ||
} | ||
catch (error) { | ||
throw new Error(`An error ocurred while parsing the payload from ${path}: ${error.message}`); | ||
} | ||
} | ||
static async fromUrl(url) { | ||
try { | ||
const response = await got_1.default(url, { responseType: 'json' }); | ||
return response.body; | ||
} | ||
catch (error) { | ||
if (error.name && error.name === 'ParseError') { | ||
throw new Error(`An error ocurred while parsing the payload from ${url}: ${error.message}`); | ||
} | ||
throw new Error(`An error ocurred while fetching the payload from ${url}: ${error.message}`); | ||
} | ||
} | ||
} | ||
exports.PayloadResolver = PayloadResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PayloadType = void 0; | ||
class PayloadType { | ||
constructor(_type) { | ||
this._type = _type; | ||
} | ||
static createFrom(type) { | ||
const allowed = [ | ||
this.STRING, | ||
this.PATH, | ||
this.URL | ||
]; | ||
if (!allowed.includes(type)) { | ||
throw new Error(`[${type}] is an invalid payload type. Valid: ${allowed.join(', ')}`); | ||
} | ||
return new this(type); | ||
} | ||
isString() { | ||
return this._type === PayloadType.STRING; | ||
} | ||
isPath() { | ||
return this._type === PayloadType.PATH; | ||
} | ||
isURL() { | ||
return this._type === PayloadType.URL; | ||
} | ||
get type() { | ||
return this._type; | ||
} | ||
} | ||
exports.PayloadType = PayloadType; | ||
PayloadType.STRING = 'string'; | ||
PayloadType.PATH = 'path'; | ||
PayloadType.URL = 'url'; |
Oops, something went wrong.