payload-rest-client
Version:
A typesafe rest api client for the payload cms.
25 lines • 859 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createCustomEndpoints = void 0;
const fetch_1 = require("./fetch");
const qs_1 = require("./qs");
const createCustomEndpoints = (options) => {
if (!options.customEndpoints) {
return undefined;
}
const fetch = (0, fetch_1.fetchFactory)(options);
return Object.entries(options.customEndpoints).reduce((ce, [name, factory]) => ({
...ce,
[name]: (input) => {
const path = factory.path(input.params);
return fetch({
method: factory.method,
path,
qs: (0, qs_1.createQueryString)(input.query),
body: input.body,
});
},
}), {});
};
exports.createCustomEndpoints = createCustomEndpoints;
//# sourceMappingURL=customEndpoints.js.map