summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/node_modules/form-data-encoder/lib
diff options
context:
space:
mode:
Diffstat (limited to 'includes/external/addressbook/node_modules/form-data-encoder/lib')
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/FileLike.js1
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/FormDataEncoder.js134
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/FormDataLike.js1
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/index.js5
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/Headers.js1
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/createBoundary.js9
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/escapeName.js4
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/getStreamIterator.js21
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFile.js8
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFormData.js8
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFunction.js1
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/isPlainObject.js12
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/normalizeValue.js8
-rw-r--r--includes/external/addressbook/node_modules/form-data-encoder/lib/util/proxyHeaders.js14
14 files changed, 227 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/FileLike.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/FileLike.js
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/FileLike.js
@@ -0,0 +1 @@
+export {};
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/FormDataEncoder.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/FormDataEncoder.js
new file mode 100644
index 0000000..eff989a
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/FormDataEncoder.js
@@ -0,0 +1,134 @@
+var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
+ if (kind === "m") throw new TypeError("Private method is not writable");
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
+};
+var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
+};
+var _FormDataEncoder_instances, _FormDataEncoder_CRLF, _FormDataEncoder_CRLF_BYTES, _FormDataEncoder_CRLF_BYTES_LENGTH, _FormDataEncoder_DASHES, _FormDataEncoder_encoder, _FormDataEncoder_footer, _FormDataEncoder_form, _FormDataEncoder_options, _FormDataEncoder_getFieldHeader, _FormDataEncoder_getContentLength;
+import { getStreamIterator } from "./util/getStreamIterator.js";
+import { createBoundary } from "./util/createBoundary.js";
+import { normalizeValue } from "./util/normalizeValue.js";
+import { isPlainObject } from "./util/isPlainObject.js";
+import { proxyHeaders } from "./util/proxyHeaders.js";
+import { isFormData } from "./util/isFormData.js";
+import { escapeName } from "./util/escapeName.js";
+import { isFile } from "./util/isFile.js";
+const defaultOptions = {
+ enableAdditionalHeaders: false
+};
+const readonlyProp = { writable: false, configurable: false };
+export class FormDataEncoder {
+ constructor(form, boundaryOrOptions, options) {
+ _FormDataEncoder_instances.add(this);
+ _FormDataEncoder_CRLF.set(this, "\r\n");
+ _FormDataEncoder_CRLF_BYTES.set(this, void 0);
+ _FormDataEncoder_CRLF_BYTES_LENGTH.set(this, void 0);
+ _FormDataEncoder_DASHES.set(this, "-".repeat(2));
+ _FormDataEncoder_encoder.set(this, new TextEncoder());
+ _FormDataEncoder_footer.set(this, void 0);
+ _FormDataEncoder_form.set(this, void 0);
+ _FormDataEncoder_options.set(this, void 0);
+ if (!isFormData(form)) {
+ throw new TypeError("Expected first argument to be a FormData instance.");
+ }
+ let boundary;
+ if (isPlainObject(boundaryOrOptions)) {
+ options = boundaryOrOptions;
+ }
+ else {
+ boundary = boundaryOrOptions;
+ }
+ if (!boundary) {
+ boundary = createBoundary();
+ }
+ if (typeof boundary !== "string") {
+ throw new TypeError("Expected boundary argument to be a string.");
+ }
+ if (options && !isPlainObject(options)) {
+ throw new TypeError("Expected options argument to be an object.");
+ }
+ __classPrivateFieldSet(this, _FormDataEncoder_form, Array.from(form.entries()), "f");
+ __classPrivateFieldSet(this, _FormDataEncoder_options, { ...defaultOptions, ...options }, "f");
+ __classPrivateFieldSet(this, _FormDataEncoder_CRLF_BYTES, __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f")), "f");
+ __classPrivateFieldSet(this, _FormDataEncoder_CRLF_BYTES_LENGTH, __classPrivateFieldGet(this, _FormDataEncoder_CRLF_BYTES, "f").byteLength, "f");
+ this.boundary = `form-data-boundary-${boundary}`;
+ this.contentType = `multipart/form-data; boundary=${this.boundary}`;
+ __classPrivateFieldSet(this, _FormDataEncoder_footer, __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(`${__classPrivateFieldGet(this, _FormDataEncoder_DASHES, "f")}${this.boundary}${__classPrivateFieldGet(this, _FormDataEncoder_DASHES, "f")}${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f").repeat(2)}`), "f");
+ const headers = {
+ "Content-Type": this.contentType
+ };
+ const contentLength = __classPrivateFieldGet(this, _FormDataEncoder_instances, "m", _FormDataEncoder_getContentLength).call(this);
+ if (contentLength) {
+ this.contentLength = contentLength;
+ headers["Content-Length"] = contentLength;
+ }
+ this.headers = proxyHeaders(Object.freeze(headers));
+ Object.defineProperties(this, {
+ boundary: readonlyProp,
+ contentType: readonlyProp,
+ contentLength: readonlyProp,
+ headers: readonlyProp
+ });
+ }
+ getContentLength() {
+ return this.contentLength == null ? undefined : Number(this.contentLength);
+ }
+ *values() {
+ for (const [name, raw] of __classPrivateFieldGet(this, _FormDataEncoder_form, "f")) {
+ const value = isFile(raw) ? raw : __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(normalizeValue(raw));
+ yield __classPrivateFieldGet(this, _FormDataEncoder_instances, "m", _FormDataEncoder_getFieldHeader).call(this, name, value);
+ yield value;
+ yield __classPrivateFieldGet(this, _FormDataEncoder_CRLF_BYTES, "f");
+ }
+ yield __classPrivateFieldGet(this, _FormDataEncoder_footer, "f");
+ }
+ async *encode() {
+ for (const part of this.values()) {
+ if (isFile(part)) {
+ yield* getStreamIterator(part.stream());
+ }
+ else {
+ yield part;
+ }
+ }
+ }
+ [(_FormDataEncoder_CRLF = new WeakMap(), _FormDataEncoder_CRLF_BYTES = new WeakMap(), _FormDataEncoder_CRLF_BYTES_LENGTH = new WeakMap(), _FormDataEncoder_DASHES = new WeakMap(), _FormDataEncoder_encoder = new WeakMap(), _FormDataEncoder_footer = new WeakMap(), _FormDataEncoder_form = new WeakMap(), _FormDataEncoder_options = new WeakMap(), _FormDataEncoder_instances = new WeakSet(), _FormDataEncoder_getFieldHeader = function _FormDataEncoder_getFieldHeader(name, value) {
+ let header = "";
+ header += `${__classPrivateFieldGet(this, _FormDataEncoder_DASHES, "f")}${this.boundary}${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f")}`;
+ header += `Content-Disposition: form-data; name="${escapeName(name)}"`;
+ if (isFile(value)) {
+ header += `; filename="${escapeName(value.name)}"${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f")}`;
+ header += `Content-Type: ${value.type || "application/octet-stream"}`;
+ }
+ const size = isFile(value) ? value.size : value.byteLength;
+ if (__classPrivateFieldGet(this, _FormDataEncoder_options, "f").enableAdditionalHeaders === true
+ && size != null
+ && !isNaN(size)) {
+ header += `${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f")}Content-Length: ${isFile(value) ? value.size : value.byteLength}`;
+ }
+ return __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(`${header}${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f").repeat(2)}`);
+ }, _FormDataEncoder_getContentLength = function _FormDataEncoder_getContentLength() {
+ let length = 0;
+ for (const [name, raw] of __classPrivateFieldGet(this, _FormDataEncoder_form, "f")) {
+ const value = isFile(raw) ? raw : __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(normalizeValue(raw));
+ const size = isFile(value) ? value.size : value.byteLength;
+ if (size == null || isNaN(size)) {
+ return undefined;
+ }
+ length += __classPrivateFieldGet(this, _FormDataEncoder_instances, "m", _FormDataEncoder_getFieldHeader).call(this, name, value).byteLength;
+ length += size;
+ length += __classPrivateFieldGet(this, _FormDataEncoder_CRLF_BYTES_LENGTH, "f");
+ }
+ return String(length + __classPrivateFieldGet(this, _FormDataEncoder_footer, "f").byteLength);
+ }, Symbol.iterator)]() {
+ return this.values();
+ }
+ [Symbol.asyncIterator]() {
+ return this.encode();
+ }
+}
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/FormDataLike.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/FormDataLike.js
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/FormDataLike.js
@@ -0,0 +1 @@
+export {};
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/index.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/index.js
new file mode 100644
index 0000000..4b0c507
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/index.js
@@ -0,0 +1,5 @@
+export * from "./FormDataEncoder.js";
+export * from "./FileLike.js";
+export * from "./FormDataLike.js";
+export * from "./util/isFile.js";
+export * from "./util/isFormData.js";
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/Headers.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/Headers.js
new file mode 100644
index 0000000..cb0ff5c
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/Headers.js
@@ -0,0 +1 @@
+export {};
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/createBoundary.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/createBoundary.js
new file mode 100644
index 0000000..4ed7434
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/createBoundary.js
@@ -0,0 +1,9 @@
+const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
+export function createBoundary() {
+ let size = 16;
+ let res = "";
+ while (size--) {
+ res += alphabet[(Math.random() * alphabet.length) << 0];
+ }
+ return res;
+}
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/escapeName.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/escapeName.js
new file mode 100644
index 0000000..8b2ce25
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/escapeName.js
@@ -0,0 +1,4 @@
+export const escapeName = (name) => String(name)
+ .replace(/\r/g, "%0D")
+ .replace(/\n/g, "%0A")
+ .replace(/"/g, "%22");
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/getStreamIterator.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/getStreamIterator.js
new file mode 100644
index 0000000..f97676a
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/getStreamIterator.js
@@ -0,0 +1,21 @@
+import { isFunction } from "./isFunction.js";
+const isAsyncIterable = (value) => (isFunction(value[Symbol.asyncIterator]));
+async function* readStream(readable) {
+ const reader = readable.getReader();
+ while (true) {
+ const { done, value } = await reader.read();
+ if (done) {
+ break;
+ }
+ yield value;
+ }
+}
+export const getStreamIterator = (source) => {
+ if (isAsyncIterable(source)) {
+ return source;
+ }
+ if (isFunction(source.getReader)) {
+ return readStream(source);
+ }
+ throw new TypeError("Unsupported data source: Expected either ReadableStream or async iterable.");
+};
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFile.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFile.js
new file mode 100644
index 0000000..eec965d
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFile.js
@@ -0,0 +1,8 @@
+import { isFunction } from "./isFunction.js";
+export const isFile = (value) => Boolean(value
+ && typeof value === "object"
+ && isFunction(value.constructor)
+ && value[Symbol.toStringTag] === "File"
+ && isFunction(value.stream)
+ && value.name != null);
+export const isFileLike = isFile;
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFormData.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFormData.js
new file mode 100644
index 0000000..237419f
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFormData.js
@@ -0,0 +1,8 @@
+import { isFunction } from "./isFunction.js";
+export const isFormData = (value) => Boolean(value
+ && isFunction(value.constructor)
+ && value[Symbol.toStringTag] === "FormData"
+ && isFunction(value.append)
+ && isFunction(value.getAll)
+ && isFunction(value.entries)
+ && isFunction(value[Symbol.iterator]));
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFunction.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFunction.js
new file mode 100644
index 0000000..a8dbdc2
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isFunction.js
@@ -0,0 +1 @@
+export const isFunction = (value) => (typeof value === "function");
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isPlainObject.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isPlainObject.js
new file mode 100644
index 0000000..9f3fb7e
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/isPlainObject.js
@@ -0,0 +1,12 @@
+const getType = (value) => (Object.prototype.toString.call(value).slice(8, -1).toLowerCase());
+export function isPlainObject(value) {
+ if (getType(value) !== "object") {
+ return false;
+ }
+ const pp = Object.getPrototypeOf(value);
+ if (pp === null || pp === undefined) {
+ return true;
+ }
+ const Ctor = pp.constructor && pp.constructor.toString();
+ return Ctor === Object.toString();
+}
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/normalizeValue.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/normalizeValue.js
new file mode 100644
index 0000000..05e058a
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/normalizeValue.js
@@ -0,0 +1,8 @@
+export const normalizeValue = (value) => String(value)
+ .replace(/\r|\n/g, (match, i, str) => {
+ if ((match === "\r" && str[i + 1] !== "\n")
+ || (match === "\n" && str[i - 1] !== "\r")) {
+ return "\r\n";
+ }
+ return match;
+});
diff --git a/includes/external/addressbook/node_modules/form-data-encoder/lib/util/proxyHeaders.js b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/proxyHeaders.js
new file mode 100644
index 0000000..05a4ab3
--- /dev/null
+++ b/includes/external/addressbook/node_modules/form-data-encoder/lib/util/proxyHeaders.js
@@ -0,0 +1,14 @@
+function getProperty(target, prop) {
+ if (typeof prop === "string") {
+ for (const [name, value] of Object.entries(target)) {
+ if (prop.toLowerCase() === name.toLowerCase()) {
+ return value;
+ }
+ }
+ }
+ return undefined;
+}
+export const proxyHeaders = (object) => new Proxy(object, {
+ get: (target, prop) => getProperty(target, prop),
+ has: (target, prop) => getProperty(target, prop) !== undefined
+});