"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
const error_1 = require("@pnpm/error");
const fetch_1 = require("@pnpm/fetch");
const lockfileToAuditTree_1 = require("./lockfileToAuditTree");
__exportStar(require("./types"), exports);
async function audit(lockfile, opts) {
    const auditTree = lockfileToAuditTree_1.default(lockfile, { include: opts.include });
    const registry = opts.registry.endsWith('/') ? opts.registry : `${opts.registry}/`;
    const auditUrl = `${registry}-/npm/v1/security/audits`;
    const res = await fetch_1.default(auditUrl, {
        body: JSON.stringify(auditTree),
        headers: { 'Content-Type': 'application/json' },
        method: 'post',
        retry: opts.retry,
    });
    if (res.status !== 200) {
        throw new error_1.default('AUDIT_BAD_RESPONSE', `The audit endpoint (at ${auditUrl}) responded with ${res.status}: ${await res.text()}`);
    }
    return res.json();
}
exports.default = audit;
//# sourceMappingURL=index.js.map