"use strict";
(() => {
var exports = {};
exports.id = 238;
exports.ids = [238];
exports.modules = {

/***/ 6943:
/***/ ((module) => {

module.exports = require("@brillout/load-module");

/***/ }),

/***/ 1917:
/***/ ((module) => {

module.exports = require("p-retry");

/***/ }),

/***/ 1297:
/***/ ((module) => {

module.exports = require("tinyduration");

/***/ }),

/***/ 9926:
/***/ ((module) => {

module.exports = import("zod");;

/***/ }),

/***/ 6113:
/***/ ((module) => {

module.exports = require("crypto");

/***/ }),

/***/ 3095:
/***/ ((module, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _taskless_next__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4210);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_taskless_next__WEBPACK_IMPORTED_MODULE_0__]);
_taskless_next__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];

/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_taskless_next__WEBPACK_IMPORTED_MODULE_0__/* .createQueue */ .jd)("Sample Queue", "/api/queues/sample", async (job, taskless)=>{
    console.log("Received with metadata", taskless);
    console.log(job);
    // pretend work is being done
    await new Promise((resolve)=>{
        setTimeout(resolve, 100);
    });
    if ((job === null || job === void 0 ? void 0 : job.message) === "force-fail") {
        console.log("Requested a failure condition");
        throw new _taskless_next__WEBPACK_IMPORTED_MODULE_0__/* .JobError */ .Ks("Forced failure of job");
    }
    if ((job === null || job === void 0 ? void 0 : job.message) === "force-503") {
        console.log("Requested a 503 retry condition");
        throw new _taskless_next__WEBPACK_IMPORTED_MODULE_0__/* .JobError */ .Ks("Forced unavailable", {
            retryAfter: 86400
        });
    }
    return {
        success: true,
        metadata: taskless,
        original: job
    };
}, {
    baseUrl: "http://localhost:3001",
    __dangerouslyAllowUnverifiedSignatures: {
        allowed: true
    }
}));

__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

/***/ 4180:
/***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Ks": () => (/* binding */ JobError),
/* harmony export */   "ci": () => (/* binding */ Queue)
/* harmony export */ });
/* unused harmony exports TASKLESS_DEV_ENDPOINT, TASKLESS_ENDPOINT */
/* harmony import */ var _taskless_types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1318);
/* harmony import */ var _taskless_graphinql__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6944);
/* harmony import */ var crypto__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6113);
/* harmony import */ var _brillout_load_module__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(6943);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_taskless_types__WEBPACK_IMPORTED_MODULE_0__]);
_taskless_types__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
// src/constants.ts
var TASKLESS_ENDPOINT = "https://for.taskless.io/api/graphql";
var TASKLESS_DEV_ENDPOINT = "http://localhost:3001/api/graphql";
var IS_PRODUCTION = typeof process.env.TASKLESS_ENV !== "undefined" ? process.env.TASKLESS_ENV === "production" : "production" === "production";
var IS_DEVELOPMENT = typeof process.env.TASKLESS_ENV !== "undefined" ? process.env.TASKLESS_ENV === "development" : "production" === "development";

// src/error.ts
var ResponseError = class extends Error {
  constructor(message) {
    super(message);
    this.type = "ResponseError";
  }
};
var JobError = class extends ResponseError {
  constructor(message, options) {
    super(message);
    this.type = "JobError";
    this.statusCode = 500;
    this.statusMessage = "Internal Server Error";
    this.headers = {};
    if (typeof (options == null ? void 0 : options.retryAfter) !== "undefined") {
      this.headers["retry-after"] = options.retryAfter;
      this.statusCode = 503;
      this.statusMessage = "Unavailable";
    }
  }
};

// src/queue/queue.ts


// src/graphql-helpers/headers.ts
var headersToGql = (h) => {
  if (!h || typeof h === "undefined") {
    return void 0;
  }
  const headers = Object.getOwnPropertyNames(h);
  return headers.map((header) => {
    const value = h[header];
    const valueAsString = typeof value === "string" ? value : typeof value === "number" ? `${value}` : "";
    return {
      name: `${header}`,
      value: `${valueAsString}`
    };
  });
};

// src/net/graphql-client.ts

var GraphQLClient = class extends _taskless_graphinql__WEBPACK_IMPORTED_MODULE_1__/* .GraphQLClient */ .g6 {
  constructor(endpoint, options) {
    const { appId, secret, projectId, queueName, ...rest } = options;
    const credentials = {};
    if (projectId && queueName && secret) {
      credentials["x-taskless-auth-type"] = "project";
      credentials["x-taskless-id"] = projectId;
      credentials["x-taskless-secret"] = secret;
      credentials["x-taskless-role"] = `queue/name:${queueName}`;
    } else if (appId && secret) {
      credentials["x-taskless-app-id"] = appId;
      credentials["x-taskless-secret"] = secret;
    } else if (IS_DEVELOPMENT) {
      console.warn(
        "Missing credentials: either TASKLESS_ID/TASKLESS_SECRET or TASKLESS_APP_ID/TASKLESS_SECRET"
      );
    } else {
      throw new Error(
        "Missing credentials: either TASKLESS_ID/TASKLESS_SECRET or TASKLESS_APP_ID/TASKLESS_SECRET"
      );
    }
    super(endpoint, {
      ...rest,
      headers: {
        ...rest.headers ?? {},
        ...credentials
      }
    });
  }
};

// src/queue/encoder.ts

var strToKey = (str, cipher) => {
  const info = hashMap[cipher] ?? null;
  if (!info) {
    return Buffer.from("");
  }
  return (0,crypto__WEBPACK_IMPORTED_MODULE_2__.createHash)(info).update(Buffer.from(str)).digest();
};
var getCipherInfo = (name) => {
  const cipherInfo = {
    "aes-256-gcm": {
      mode: "gcm",
      name: "id-aes-256-gcm",
      nid: 901,
      ivLength: 12,
      keyLength: 32
    },
    none: void 0
  };
  if (name === "aes-256-gcm") {
    return cipherInfo["aes-256-gcm"];
  }
  return void 0;
};
var hashMap = {
  none: "",
  "aes-256-gcm": "sha256"
};
var sign = (input, secret) => {
  return (0,crypto__WEBPACK_IMPORTED_MODULE_2__.createHmac)("sha256", secret).update(input).digest("base64");
};
var verify = (input, secrets, signature) => {
  for (const s of secrets) {
    if (!s)
      continue;
    const sig = sign(input, s);
    if (sig === signature) {
      return true;
    }
  }
  return false;
};
var encode = (obj, secret) => {
  const algo = "aes-256-gcm";
  const info = getCipherInfo(algo);
  const str = JSON.stringify({
    envelope: obj
  });
  if (!info) {
    throw new Error("Unknown algo: " + algo);
  }
  if (!secret) {
    return {
      transport: {
        ev: 1,
        alg: "none"
      },
      text: str
    };
  }
  const key = strToKey(secret, algo);
  const iv = (0,crypto__WEBPACK_IMPORTED_MODULE_2__.randomBytes)(info.ivLength);
  const authTagLength = 16;
  const cipher = (0,crypto__WEBPACK_IMPORTED_MODULE_2__.createCipheriv)(algo, key, iv, {
    authTagLength
  });
  const ciphered = Buffer.concat([cipher.update(str, "utf-8"), cipher.final()]);
  return {
    transport: {
      ev: 1,
      alg: algo,
      atl: authTagLength,
      at: cipher.getAuthTag().toString("base64"),
      iv: iv.toString("base64")
    },
    text: ciphered.toString("base64")
  };
};
var decodeOne = (text, transport, secret) => {
  const algo = transport.alg;
  if (algo === "none") {
    return text;
  }
  const key = strToKey(secret ?? "", algo);
  const decipher = (0,crypto__WEBPACK_IMPORTED_MODULE_2__.createDecipheriv)(
    algo,
    key,
    Buffer.from(transport.iv, "base64"),
    {
      authTagLength: transport.atl
    }
  );
  decipher.setAuthTag(Buffer.from(transport.at, "base64"));
  const deciphered = Buffer.concat([
    decipher.update(text, "base64"),
    decipher.final()
  ]).toString();
  return deciphered;
};
var decode = (text, transport, secrets) => {
  var _a;
  for (const secret of secrets.concat(void 0)) {
    if (secret === null)
      continue;
    try {
      const result = decodeOne(text, transport, secret);
      return (_a = JSON.parse(result)) == null ? void 0 : _a.envelope;
    } catch (e) {
    }
  }
  throw new Error("No valid decryption keys found");
};

// src/queue/util.ts

var resolveJobOptions = (...opts) => {
  let result = _taskless_types__WEBPACK_IMPORTED_MODULE_0__/* .parsers.jobOptions.parse */ .fQ.jobOptions.parse({});
  for (const opt of opts) {
    if (typeof opt === "undefined" || opt === null) {
      continue;
    }
    result = {
      ...result,
      ...opt,
      headers: {
        ...result.headers ?? {},
        ...opt.headers ?? {}
      }
    };
  }
  return result;
};

// src/queue/queue.ts

var firstOf = (unk) => {
  return Array.isArray(unk) ? unk[0] : unk;
};
var Queue = class {
  constructor(args) {
    this.queueOptions = _taskless_types__WEBPACK_IMPORTED_MODULE_0__/* .parsers.queueOptions.parse */ .fQ.queueOptions.parse(args.queueOptions ?? {});
    this.queueName = args.name;
    this.route = args.route;
    this.handler = args.handler;
  }
  packName(name) {
    const s = this.queueOptions.separator ?? "/";
    return Array.isArray(name) ? name.join(s) : `${name}`;
  }
  static wrapPayload(payload, options) {
    const { transport, text } = encode(
      payload,
      (options == null ? void 0 : options.encryptionKey) ?? void 0
    );
    return {
      v: 1,
      transport,
      text,
      signature: sign(text, (options == null ? void 0 : options.secret) ?? "")
    };
  }
  static unwrapPayload(body, options) {
    if (body.v !== 1) {
      throw new Error("Unsupported Taskless Envelope");
    }
    let checked = false;
    let ver = false;
    let payload;
    if ("text" in body) {
      ver = verify(
        body.text,
        [options == null ? void 0 : options.secret, ...(options == null ? void 0 : options.expiredSecrets) ?? []],
        body.signature
      );
      payload = decode(
        body.text,
        body.transport,
        [
          options == null ? void 0 : options.encryptionKey,
          ...(options == null ? void 0 : options.expiredEncryptionKeys) ?? []
        ].filter((t) => t)
      );
      checked = true;
    }
    if (!checked && "json" in body) {
      payload = body.json;
      ver = false;
      checked = true;
    }
    if (!checked || typeof payload === "undefined") {
      throw new TypeError("Unrecognized payload body");
    }
    if (!ver && !(options == null ? void 0 : options.allowUnsigned)) {
      if (!IS_DEVELOPMENT) {
        throw new Error("Signature mismatch");
      } else {
        console.error(
          "Signature mismatch or no signature available. This can happen if you've enqueued a job with one secret, but dequeued the job with another. In production, this will throw an error."
        );
      }
    }
    return { payload, verified: ver };
  }
  resolveRoute() {
    const route = typeof this.route === "function" ? this.route() : this.route ?? "";
    if (route.indexOf("http://") === 0 || route.indexOf("https://") === 0) {
      return route;
    }
    return `${this.queueOptions.baseUrl ?? ""}${route.indexOf("/") === 0 ? route : "/" + route}`;
  }
  getClient() {
    const creds = this.queueOptions.credentials;
    let endpoint = TASKLESS_ENDPOINT;
    if (IS_DEVELOPMENT) {
      endpoint = process.env.TASKLESS_ENDPOINT ?? process.env.TASKLESS_DEV_ENDPOINT ?? TASKLESS_DEV_ENDPOINT;
    } else if (IS_PRODUCTION) {
      endpoint = process.env.TASKLESS_ENDPOINT ?? TASKLESS_ENDPOINT;
    }
    if (typeof creds !== "undefined" && "projectId" in creds) {
      return new GraphQLClient(endpoint, {
        projectId: creds.projectId ?? void 0,
        queueName: this.queueName,
        secret: creds.secret ?? void 0
      });
    }
    if (typeof creds !== "undefined" && "appId" in creds) {
      return new GraphQLClient(endpoint, {
        appId: creds.appId ?? void 0,
        queueName: this.queueName,
        secret: creds.secret ?? void 0
      });
    }
    return new GraphQLClient(endpoint, {
      projectId: void 0,
      queueName: this.queueName,
      secret: void 0
    });
  }
  presetUnwrap(body) {
    var _a, _b, _c;
    return Queue.unwrapPayload(body, {
      allowUnsigned: ((_a = this.queueOptions.__dangerouslyAllowUnverifiedSignatures) == null ? void 0 : _a.allowed) ?? false,
      encryptionKey: this.queueOptions.encryptionKey,
      expiredEncryptionKeys: this.queueOptions.expiredEncryptionKeys,
      secret: (_b = this.queueOptions.credentials) == null ? void 0 : _b.secret,
      expiredSecrets: (_c = this.queueOptions.credentials) == null ? void 0 : _c.expiredSecrets
    });
  }
  presetWrap(payload) {
    var _a;
    return Queue.wrapPayload(payload, {
      encryptionKey: this.queueOptions.encryptionKey,
      secret: (_a = this.queueOptions.credentials) == null ? void 0 : _a.secret
    });
  }
  async receive(functions) {
    const { serializeError } = await (0,_brillout_load_module__WEBPACK_IMPORTED_MODULE_3__.loadModule)(
      "serialize-error"
    );
    const { getBody, getHeaders, send, sendError } = functions;
    if (typeof this.handler === "undefined") {
      await sendError(500, {}, "This Queue was not configured with a handler");
      return;
    }
    const body = await Promise.resolve(getBody());
    const { payload, verified } = this.presetUnwrap(body);
    const h = await getHeaders();
    try {
      const result = await this.handler(payload, {
        queue: firstOf(h["x-taskless-queue"]) ?? null,
        projectId: firstOf(h["x-taskless-id"]) ?? null,
        verified
      });
      await send(JSON.parse(JSON.stringify(result ?? {})));
      return;
    } catch (e) {
      console.error(e);
      const ser = serializeError(e);
      if (e instanceof JobError) {
        await sendError(e.statusCode, e.headers, ser);
      } else {
        await sendError(500, {}, ser);
      }
    }
  }
  async enqueue(name, payload, options) {
    const opts = resolveJobOptions(
      {
        headers: {
          "content-type": "application/json"
        }
      },
      this.queueOptions.defaultJobOptions,
      options
    );
    const client = this.getClient();
    const body = this.presetWrap(payload);
    const resolvedName = this.packName(name);
    let runAt = new Date().toISOString();
    if (opts.runAt instanceof Date) {
      runAt = opts.runAt.toISOString();
    } else if (typeof opts.runAt === "string") {
      runAt = opts.runAt;
    } else if (typeof opts.runAt === "undefined") {
      runAt = void 0;
    }
    const job = await client.request(_taskless_types__WEBPACK_IMPORTED_MODULE_0__/* .graphql.EnqueueJob */ .BX.EnqueueJob, {
      name: resolvedName,
      job: {
        endpoint: this.resolveRoute(),
        method: _taskless_types__WEBPACK_IMPORTED_MODULE_0__/* .graphql.JobMethodEnum.Post */ .BX.JobMethodEnum.Post,
        headers: headersToGql(opts.headers),
        body: JSON.stringify(body),
        retries: opts.retries === 0 ? 0 : opts.retries ?? 0,
        runAt,
        runEvery: opts.runEvery === null ? null : opts.runEvery ?? void 0,
        timezone: opts.timezone === null ? null : opts.timezone ?? void 0
      }
    });
    const resolvedBody = JSON.parse(job.enqueueJob.body ?? "");
    return {
      name: job.enqueueJob.name,
      endpoint: job.enqueueJob.endpoint,
      enabled: job.enqueueJob.enabled === false ? false : true,
      headers: opts.headers,
      payload: this.presetUnwrap(resolvedBody).payload,
      retries: job.enqueueJob.retries,
      runAt: job.enqueueJob.runAt ? new Date(job.enqueueJob.runAt) : void 0,
      runEvery: job.enqueueJob.runEvery ?? null,
      timezone: job.enqueueJob.timezone ?? null
    };
  }
  async cancel(name) {
    const client = this.getClient();
    const resolvedName = this.packName(name);
    const job = await client.request(_taskless_types__WEBPACK_IMPORTED_MODULE_0__/* .graphql.CancelJob */ .BX.CancelJob, {
      name: resolvedName
    });
    if (!job.cancelJob) {
      return null;
    }
    const resolvedBody = JSON.parse(job.cancelJob.body ?? "");
    return {
      name: job.cancelJob.name,
      endpoint: job.cancelJob.endpoint,
      enabled: job.cancelJob.enabled === false ? false : true,
      payload: this.presetUnwrap(resolvedBody).payload,
      retries: job.cancelJob.retries,
      runAt: job.cancelJob.runAt ? new Date(job.cancelJob.runAt) : void 0,
      runEvery: job.cancelJob.runEvery ?? null
    };
  }
};

//# sourceMappingURL=index.js.map
__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

/***/ 6944:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {


// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "g6": () => (/* binding */ GraphQLClient)
});

// UNUSED EXPORTS: ClientError, RequestError, request

;// CONCATENATED MODULE: external "isomorphic-unfetch"
const external_isomorphic_unfetch_namespaceObject = require("isomorphic-unfetch");
;// CONCATENATED MODULE: ../graphinql/dist/index.js
// src/error.ts
var RequestError = class extends Error {
};
var ClientError = class extends Error {
  constructor(response, request2) {
    const message = `${ClientError.extractMessage(response)}: ${JSON.stringify({
      response,
      request: request2
    })}`;
    super(message);
    Object.setPrototypeOf(this, ClientError.prototype);
    this.response = response;
    this.request = request2;
    if (typeof Error.captureStackTrace === "function") {
      Error.captureStackTrace(this, ClientError);
    }
  }
  static extractMessage(response) {
    var _a;
    try {
      return ((_a = response.errors) == null ? void 0 : _a[0].message) ?? "Unknown error";
    } catch (e) {
      return `GraphQL Error (Code: ${response.status})`;
    }
  }
};

// src/client.ts

async function request(endpoint, query, variables, options) {
  var _a;
  const { headers, retries } = options ?? {};
  const gqlRequest = {
    query,
    variables: variables ?? {}
  };
  let result;
  const pRetry = ((_a = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 1917, 19))) == null ? void 0 : _a.default) ?? await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 1917, 19));
  try {
    result = await pRetry(
      async () => {
        const r = await external_isomorphic_unfetch_namespaceObject(endpoint, {
          method: "POST",
          headers: {
            ...headers ?? {},
            "content-type": "application/json"
          },
          body: JSON.stringify(gqlRequest)
        });
        const j = await r.json();
        return j;
      },
      {
        retries: typeof retries === "number" ? retries : 5
      }
    );
  } catch (e) {
    const err = new RequestError("Unable to make the request");
    err.original = e;
    throw err;
  }
  if (typeof result === "undefined") {
    throw new RequestError("Unable to parse the response");
  }
  const gqlResponse = {
    data: result.data,
    errors: result.errors,
    extensions: result.extensions,
    ...result
  };
  if (result.errors) {
    throw new ClientError(gqlResponse, gqlRequest);
  }
  return result.data;
}
var GraphQLClient = class {
  constructor(endpoint, options) {
    this.endpoint = endpoint;
    this.options = {
      retries: typeof (options == null ? void 0 : options.retries) === "number" ? options.retries : 5,
      headers: (options == null ? void 0 : options.headers) ?? {}
    };
  }
  request(query, variables, options) {
    const mergedOptions = {
      retries: typeof (options == null ? void 0 : options.retries) === "number" ? options.retries : this.options.retries,
      headers: {
        ...this.options.headers ?? {},
        ...(options == null ? void 0 : options.headers) ?? {}
      }
    };
    return request(this.endpoint, query, variables, mergedOptions);
  }
};

//# sourceMappingURL=index.js.map

/***/ }),

/***/ 4210:
/***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Ks": () => (/* reexport safe */ _taskless_client__WEBPACK_IMPORTED_MODULE_0__.Ks),
/* harmony export */   "jd": () => (/* binding */ createQueue)
/* harmony export */ });
/* harmony import */ var _taskless_client__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(4180);
/* harmony import */ var _taskless_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1318);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([_taskless_client__WEBPACK_IMPORTED_MODULE_0__, _taskless_types__WEBPACK_IMPORTED_MODULE_1__]);
([_taskless_client__WEBPACK_IMPORTED_MODULE_0__, _taskless_types__WEBPACK_IMPORTED_MODULE_1__] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);
// src/index.ts



function createQueue(name, route, handler, queueOptions) {
  const t = new _taskless_client__WEBPACK_IMPORTED_MODULE_0__/* .Queue */ .ci({
    name,
    route,
    handler,
    queueOptions
  });
  const handle = async (req, res) => {
    return await t.receive({
      getBody: () => {
        if (_taskless_types__WEBPACK_IMPORTED_MODULE_1__/* .guards.isTasklessBody */ .l8.isTasklessBody(req.body)) {
          return req.body;
        }
        throw new Error("req.body does not match a Taskless payload");
      },
      getHeaders: () => req.headers,
      send: (json) => res.status(200).json(json),
      sendError: (code, headers, json) => {
        res.status(code);
        Object.getOwnPropertyNames(headers).forEach((name2) => {
          res.setHeader(name2, headers[name2] ?? "");
        });
        res.json(json);
      }
    });
  };
  handle.enqueue = (name2, payload, options) => t.enqueue(name2, payload, options);
  handle.cancel = (name2) => t.cancel(name2);
  handle.withQueue = (wrappedHandler) => {
    const q = wrappedHandler;
    q.enqueue = handle.enqueue;
    q.cancel = handle.cancel;
    return q;
  };
  return handle;
}

//# sourceMappingURL=index.js.map
__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ }),

/***/ 1318:
/***/ ((__webpack_module__, __webpack_exports__, __webpack_require__) => {

__webpack_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "BX": () => (/* binding */ schema_exports),
/* harmony export */   "fQ": () => (/* binding */ parsers),
/* harmony export */   "l8": () => (/* binding */ guards)
/* harmony export */ });
/* harmony import */ var zod__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9926);
/* harmony import */ var tinyduration__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(1297);
var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([zod__WEBPACK_IMPORTED_MODULE_0__]);
zod__WEBPACK_IMPORTED_MODULE_0__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
var __defProp = Object.defineProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};

// src/ciphers.ts

var AES256GCM = zod__WEBPACK_IMPORTED_MODULE_0__.z.literal("aes-256-gcm");
var NONE = zod__WEBPACK_IMPORTED_MODULE_0__.z.literal("none");
var supportedCiper = zod__WEBPACK_IMPORTED_MODULE_0__.z.union([NONE, AES256GCM]);
var cipherAes256Gcm = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  alg: AES256GCM,
  atl: zod__WEBPACK_IMPORTED_MODULE_0__.z.number(),
  at: zod__WEBPACK_IMPORTED_MODULE_0__.z.string(),
  iv: zod__WEBPACK_IMPORTED_MODULE_0__.z.string()
});
var cipherNone = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  alg: NONE
});
var cipherEnvelope = zod__WEBPACK_IMPORTED_MODULE_0__.z.union([cipherNone, cipherAes256Gcm]);

// src/job.ts


var jobHeaders = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  "x-taskless-application": zod__WEBPACK_IMPORTED_MODULE_0__.z.string().optional(),
  "x-taskless-organization": zod__WEBPACK_IMPORTED_MODULE_0__.z.string().optional(),
  "x-taskless-attempt": zod__WEBPACK_IMPORTED_MODULE_0__.z.string().optional()
});
var jobIdentifierPrimitive = zod__WEBPACK_IMPORTED_MODULE_0__.z.union([zod__WEBPACK_IMPORTED_MODULE_0__.z.string(), zod__WEBPACK_IMPORTED_MODULE_0__.z.number()]);
var jobIdentifier = zod__WEBPACK_IMPORTED_MODULE_0__.z.union([
  jobIdentifierPrimitive,
  zod__WEBPACK_IMPORTED_MODULE_0__.z.array(jobIdentifierPrimitive)
]);
var dateOrIsoDate = zod__WEBPACK_IMPORTED_MODULE_0__.z.union([zod__WEBPACK_IMPORTED_MODULE_0__.z.date(), zod__WEBPACK_IMPORTED_MODULE_0__.z.string()]).transform((arg) => {
  if (arg instanceof Date) {
    return arg;
  }
  if (typeof arg === "string") {
    const d = new Date(arg);
    if (!isNaN(d.getTime())) {
      return d;
    }
  }
  return void 0;
});
var duration = zod__WEBPACK_IMPORTED_MODULE_0__.z.string().transform((arg, ctx) => {
  if (typeof arg === "string") {
    try {
      (0,tinyduration__WEBPACK_IMPORTED_MODULE_1__.parse)(arg);
      return arg;
    } catch {
      ctx.addIssue({
        code: zod__WEBPACK_IMPORTED_MODULE_0__.z.ZodIssueCode.custom,
        message: `"${arg}" is not a valid ISO-8601 Duration`
      });
      return zod__WEBPACK_IMPORTED_MODULE_0__.z.NEVER;
    }
  }
  return void 0;
});
var jobOptions = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  headers: jobHeaders.passthrough().optional(),
  retries: zod__WEBPACK_IMPORTED_MODULE_0__.z.number().optional().default(5),
  runAt: dateOrIsoDate.nullable().optional(),
  runEvery: duration.nullable().optional(),
  timezone: zod__WEBPACK_IMPORTED_MODULE_0__.z.string().nullable().optional()
});
var jobMetadata = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  queue: zod__WEBPACK_IMPORTED_MODULE_0__.z.string().nullable(),
  projectId: zod__WEBPACK_IMPORTED_MODULE_0__.z.string().nullable(),
  verified: zod__WEBPACK_IMPORTED_MODULE_0__.z.boolean()
});
var job = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  name: zod__WEBPACK_IMPORTED_MODULE_0__.z.string(),
  endpoint: zod__WEBPACK_IMPORTED_MODULE_0__.z.string(),
  headers: jobHeaders.optional(),
  enabled: zod__WEBPACK_IMPORTED_MODULE_0__.z.boolean(),
  retries: zod__WEBPACK_IMPORTED_MODULE_0__.z.number(),
  runAt: dateOrIsoDate,
  runEvery: duration.nullable(),
  timezone: zod__WEBPACK_IMPORTED_MODULE_0__.z.string().nullable().optional(),
  payload: zod__WEBPACK_IMPORTED_MODULE_0__.z.unknown()
});

// src/queue.ts

var credentialsByAppId = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  appId: zod__WEBPACK_IMPORTED_MODULE_0__.z.string(),
  secret: zod__WEBPACK_IMPORTED_MODULE_0__.z.union([zod__WEBPACK_IMPORTED_MODULE_0__.z.string(), zod__WEBPACK_IMPORTED_MODULE_0__.z["null"]()]).optional().default(() => process.env.TASKLESS_APP_SECRET ?? null),
  expiredSecrets: zod__WEBPACK_IMPORTED_MODULE_0__.z.array(zod__WEBPACK_IMPORTED_MODULE_0__.z.string()).optional().default(
    () => process.env.TASKLESS_PREVIOUS_APP_SECRETS ? process.env.TASKLESS_PREVIOUS_APP_SECRETS.split(",").map(
      (s) => s.trim()
    ) : []
  )
});
var credentialsByProjectId = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  projectId: zod__WEBPACK_IMPORTED_MODULE_0__.z.string(),
  secret: zod__WEBPACK_IMPORTED_MODULE_0__.z.union([zod__WEBPACK_IMPORTED_MODULE_0__.z.string(), zod__WEBPACK_IMPORTED_MODULE_0__.z["null"]()]).optional().default(() => process.env.TASKLESS_SECRET ?? null),
  expiredSecrets: zod__WEBPACK_IMPORTED_MODULE_0__.z.array(zod__WEBPACK_IMPORTED_MODULE_0__.z.string()).optional().default(
    () => process.env.TASKLESS_PREVIOUS_SECRETS ? process.env.TASKLESS_PREVIOUS_SECRETS.split(",").map((s) => s.trim()) : []
  )
});
var queueOptions = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  baseUrl: zod__WEBPACK_IMPORTED_MODULE_0__.z.union([zod__WEBPACK_IMPORTED_MODULE_0__.z.string(), zod__WEBPACK_IMPORTED_MODULE_0__.z["null"]()]).optional().default(() => process.env.TASKLESS_BASE_URL ?? null),
  separator: zod__WEBPACK_IMPORTED_MODULE_0__.z.string().optional().default("/"),
  credentials: zod__WEBPACK_IMPORTED_MODULE_0__.z.union([credentialsByAppId, credentialsByProjectId]).optional().default(() => {
    const isModern = typeof process.env.TASKLESS_ID !== "undefined";
    if (isModern) {
      return credentialsByProjectId.parse({
        projectId: process.env.TASKLESS_ID ?? "00000000-0000-0000-0000-000000000000"
      });
    } else {
      return credentialsByAppId.parse({
        appId: process.env.TASKLESS_APP_ID ?? "00000000-0000-0000-0000-000000000000"
      });
    }
  }),
  encryptionKey: zod__WEBPACK_IMPORTED_MODULE_0__.z.union([zod__WEBPACK_IMPORTED_MODULE_0__.z.string(), zod__WEBPACK_IMPORTED_MODULE_0__.z["null"]()]).optional().default(() => process.env.TASKLESS_ENCRYPTION_KEY ?? null),
  expiredEncryptionKeys: zod__WEBPACK_IMPORTED_MODULE_0__.z.array(zod__WEBPACK_IMPORTED_MODULE_0__.z.string()).optional().default(
    () => process.env.TASKLESS_PREVIOUS_ENCRYPTION_KEYS ? process.env.TASKLESS_PREVIOUS_ENCRYPTION_KEYS.split(",").map(
      (s) => s.trim()
    ) : []
  ),
  defaultJobOptions: jobOptions.optional().default(() => jobOptions.parse({})),
  __dangerouslyAllowUnverifiedSignatures: zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
    allowed: zod__WEBPACK_IMPORTED_MODULE_0__.z.boolean()
  }).optional()
});

// src/tasklessBody.ts


// src/json.ts

var literal = zod__WEBPACK_IMPORTED_MODULE_0__.z.union([zod__WEBPACK_IMPORTED_MODULE_0__.z.string(), zod__WEBPACK_IMPORTED_MODULE_0__.z.number(), zod__WEBPACK_IMPORTED_MODULE_0__.z.boolean(), zod__WEBPACK_IMPORTED_MODULE_0__.z["null"]()]);
var json = zod__WEBPACK_IMPORTED_MODULE_0__.z.lazy(
  () => zod__WEBPACK_IMPORTED_MODULE_0__.z.union([literal, zod__WEBPACK_IMPORTED_MODULE_0__.z.array(json), zod__WEBPACK_IMPORTED_MODULE_0__.z.record(json)])
);

// src/tasklessBody.ts
var transport = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  ev: zod__WEBPACK_IMPORTED_MODULE_0__.z.literal(1),
  alg: supportedCiper
}).and(cipherEnvelope);
var signedTextPayload = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  text: zod__WEBPACK_IMPORTED_MODULE_0__.z.string(),
  signature: zod__WEBPACK_IMPORTED_MODULE_0__.z.string().optional()
});
var unsignedJsonPayload = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  json
});
var tasklessBody = zod__WEBPACK_IMPORTED_MODULE_0__.z.object({
  v: zod__WEBPACK_IMPORTED_MODULE_0__.z.number(),
  transport
}).and(zod__WEBPACK_IMPORTED_MODULE_0__.z.union([signedTextPayload, unsignedJsonPayload]));

// src/__generated__/schema.ts
var schema_exports = {};
__export(schema_exports, {
  CancelJob: () => CancelJob,
  EnqueueJob: () => EnqueueJob,
  JobMethodEnum: () => JobMethodEnum,
  OrderByEnum: () => OrderByEnum
});
var JobMethodEnum = /* @__PURE__ */ ((JobMethodEnum2) => {
  JobMethodEnum2["Get"] = "GET";
  JobMethodEnum2["Post"] = "POST";
  return JobMethodEnum2;
})(JobMethodEnum || {});
var OrderByEnum = /* @__PURE__ */ ((OrderByEnum2) => {
  OrderByEnum2["Asc"] = "asc";
  OrderByEnum2["Desc"] = "desc";
  return OrderByEnum2;
})(OrderByEnum || {});
var EnqueueJob = `
    mutation enqueueJob($name: String!, $job: EnqueueJobInputType!) {
  enqueueJob(name: $name, job: $job) {
    id
    name
    enabled
    endpoint
    headers
    body
    retries
    runAt
    runEvery
    timezone
  }
}
    `;
var CancelJob = `
    mutation cancelJob($name: String!) {
  cancelJob(name: $name) {
    id
    name
    enabled
    endpoint
    headers
    body
    retries
    runAt
    runEvery
    timezone
  }
}
    `;

// src/index.ts
var parsers = {
  json,
  job,
  jobOptions,
  queueOptions,
  tasklessBody
};
var guards = {
  isCipherEnvelope: (v) => {
    return cipherEnvelope.safeParse(v).success;
  },
  isJob: (v) => {
    return job.safeParse(v).success;
  },
  isTasklessBody: (v) => {
    return tasklessBody.safeParse(v).success;
  },
  isTransport: (v) => {
    return transport.safeParse(v).success;
  }
};

//# sourceMappingURL=index.js.map
__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } });

/***/ })

};
;

// load runtime
var __webpack_require__ = require("../../../webpack-api-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = (__webpack_exec__(3095));
module.exports = __webpack_exports__;

})();