paste.gg 1.1.4-next.7332cea → 1.1.4-next.8249d8b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -36,7 +36,7 @@ var _PasteGG = class _PasteGG {
36
36
  __privateAdd(this, _url);
37
37
  __privateSet(this, _auth, auth);
38
38
  this.options = Object.assign(defaultOptions, options);
39
- this.version = "v1.1.4-next.7332cea";
39
+ this.version = "v1.1.4-next.8249d8b";
40
40
  __privateSet(this, _url, `${this.options.baseUrl}/v${this.options.version}`);
41
41
  }
42
42
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["stringify"],"mappings":";;;;;;;;;;;;;AAYA,IAAM,cAAiB,GAAA;AAAA,EACnB,OAAS,EAAA,sBAAA;AAAA,EACT,OAAS,EAAA,kBAAA;AAAA,EACT,OAAS,EAAA;AACb,CAAA;AAhBA,IAAA,KAAA,EAAA,IAAA;AAqBA,IAAqB,QAAA,GAArB,MAAqB,QAAQ,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBzB,WAAA,CAAY,IAAe,EAAA,OAAA,GAAmB,cAAgB,EAAA;AAlB9D,IAAS,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AACT,IAAS,YAAA,CAAA,IAAA,EAAA,IAAA,CAAA;AAwBL,IAAA,YAAA,CAAA,IAAA,EAAK,KAAQ,EAAA,IAAA,CAAA;AAOb,IAAA,IAAA,CAAK,OAAU,GAAA,MAAA,CAAO,MAAyB,CAAA,cAAA,EAAgB,OAAO,CAAA;AAOtE,IAAA,IAAA,CAAK,OAAU,GAAA,qBAAA;AAOf,IAAK,YAAA,CAAA,IAAA,EAAA,IAAA,EAAO,GAAG,IAAK,CAAA,OAAA,CAAQ,OAAO,CAAK,EAAA,EAAA,IAAA,CAAK,QAAQ,OAAO,CAAA,CAAA,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AA;AAAA,QACN;AAAA,OACJ;AAEJ,IAAA,OAAO,KAAK,QAAyB,CAAA,QAAA,eAAA,CAAA,QAAA,EAAW,EAAE,CAAA,CAAA,EAAI,MAAM,GAAG,CAAA;AAAA;AACnE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,MAAM,MAAO,CAAA,EAAA,EAAY,OAAwC,EAAA;AAC7D,IAAI,IAAA,CAAC,mBAAK,KAAO,CAAA,EAAA,MAAA;AACb,MAAM,MAAA,IAAI,MAAM,iDAAiD,CAAA;AAErE,IAAA,IAAI,CAAC,OAAA,CAAQ,IAAM,EAAA,OAAA,CAAQ,IAAO,GAAA,IAAA;AAClC,IAAA,OAAO,IAAK,CAAA,QAAA,CAAA,OAAA,cAAwB,CAAW,QAAA,EAAA,EAAE,IAAI,OAAO,CAAA;AAAA;AAEpE,CAAA;AAlMa,KAAA,GAAA,IAAA,OAAA,EAAA;AACA,IAAA,GAAA,IAAA,OAAA,EAAA;AAFgB,MAAA,CAAA,QAAA,EAAA,SAAA,CAAA;AAA7B,IAAqB,OAArB,GAAA","file":"index.cjs","sourcesContent":["import { stringify, type ParsedUrlQueryInput } from \"node:querystring\";\nimport {\n Methods,\n type IHeader,\n type Options,\n type Output,\n type Post,\n type Update,\n type Result,\n type ResultOutput,\n} from \"./interfaces.js\";\n\nconst defaultOptions = {\n baseUrl: \"https://api.paste.gg\",\n mainUrl: \"https://paste.gg\",\n version: 1,\n} satisfies Options;\n\n/**\n * The main class for interacting with the Paste.gg API\n */\nexport default class PasteGG {\n readonly #auth: string;\n readonly #url: string;\n readonly options: Options;\n readonly version: string;\n\n /**\n * Create a new instance of PasteGG\n * @param {string} auth Optional auth key\n * @param {Options} options Options for the paste server\n * @class PasteGG\n * @public\n * @example\n * // If you want to be anonymous\n * const pasteGG = new PasteGG()\n *\n * // If you want to use an api key\n * const pasteGG = new PasteGG(\"apiKeyHere\")\n */\n constructor(auth?: string, options: Options = defaultOptions) {\n /**\n * The auth key\n * @type {string}\n * @private\n * @readonly\n */\n this.#auth = auth;\n /**\n * The options for the paste server\n * @type {Options}\n * @public\n * @readonly\n */\n this.options = Object.assign<Options, Options>(defaultOptions, options);\n /**\n * The version of the API wrapper\n * @type {string}\n * @public\n * @readonly\n */\n this.version = \"v1.1.4-next.7332cea\";\n /**\n * The full URL for the API\n * @type {string}\n * @private\n * @readonly\n */\n this.#url = `${this.options.baseUrl}/v${this.options.version}`;\n }\n\n /**\n * Make a request to the API.\n * @param {keyof typeof Methods} method\n * @param {string} path\n * @param {object} body\n * @param {string} key\n * @returns {Promise<Output<T>>}\n * @private\n */\n private async _request<T = Result>(\n method: keyof typeof Methods,\n path: string,\n body?: object,\n key?: string,\n ): Promise<Output<T>> {\n const headers: IHeader = {};\n if (this.#auth) headers.Authorization = `Key ${this.#auth}`;\n if (key?.length) headers.Authorization = `Key ${key}`;\n if (method !== \"GET\") headers[\"Content-Type\"] = \"application/json\";\n\n let urlPath = `${this.#url}${path}`;\n if (body && method === \"GET\")\n urlPath += `?${stringify(body as ParsedUrlQueryInput)}`;\n\n const res = await fetch(urlPath, {\n method,\n headers,\n body: body && method !== \"GET\" ? JSON.stringify(body) : null,\n });\n\n try {\n return (await res.json()) as Output<T>;\n } catch (e) {\n if (\n e instanceof Error &&\n e.message === \"Unexpected end of JSON input\"\n ) {\n return { status: \"success\", result: null };\n }\n\n return { status: \"error\", error: e.name, message: e.message };\n }\n }\n\n /**\n * Get an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#get-pastesid\n * @param {string} id The ID of the paste.\n * @param {boolean} full Includes the contents of files if true.\n * @returns {Promise<ResultOutput>}\n * @public\n * @example\n * // if you would like to exclude file contents\n * await pasteGG.get(\"idHere\")\n *\n * // If you would like to include file contents\n * await pasteGG.get(\"idHere\", true)\n */\n async get(id: string, full: boolean = false): Promise<Output> {\n if (!id?.length) {\n throw new Error(\"A paste ID is required to use PasteGG#get()\");\n }\n\n return this._request(Methods.GET, `/pastes/${id}`, { full });\n }\n\n /**\n * Create a new paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#post-pastes\n * @param {Post} input The information to create the paste with.\n * @returns {Promise<ResultOutput>}\n * @public\n * @example\n * await pasteGG.post({\n * name: \"Paste name\", // Optional\n * description: \"Paste description\", // Optional\n * expires: \"2020-12-21T02:25:56.428Z\", // Optional (must be a UTC ISO 8601 string)\n * files: [{\n * name: \"file.txt\", // Optional\n * content: {\n * format: \"text\",\n * value: \"This is where the file content will go\"\n * }\n * }]\n * })\n */\n async post(input: Post): Promise<ResultOutput> {\n if (!input) {\n throw new Error(\n \"An input object is required to use PasteGG#post()\",\n );\n }\n\n const res = await this._request(Methods.POST, \"/pastes\", input);\n if (res.status === \"success\")\n res.result.url = `${this.options.mainUrl}/${res.result.id}`;\n return res;\n }\n\n /**\n * Deletes an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#delete-pastesid\n * @param {string} id The ID of the paste to delete.\n * @param {string} [key] Auth key or deletion key (leave blank if you have set the auth key in the constructor)\n * @returns {Promise<Output<null>>}\n * @public\n * @example\n * // Delete with deletion key\n * await pasteGG.delete(\"idHere\", \"deletionKeyHere\")\n *\n * // Delete with auth key if not set in constructor\n * await pasteGG.delete(\"idHere\", \"authKeyHere\")\n *\n * // Leave blank if auth key is in the class constructor\n * await pasteGG.delete(\"idHere\")\n */\n async delete(id: string, key?: string): Promise<Output<null>> {\n if (!this.#auth?.length && !key?.length)\n throw new Error(\n \"An auth key or deletion key is needed to use PasteGG#delete()\",\n );\n\n return this._request(Methods.DELETE, `/pastes/${id}`, null, key);\n }\n\n /**\n * Update an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#patch-pastesid\n * @param {string} id The ID for the paste to update.\n * @param {Update} options The options you wish to update.\n * @returns {Promise<Output<null>>}\n * @public\n * @example\n * await pasteGG.update(\"idHere\", {\n * name: \"new name\", // Optional (if you want to remove the name)\n * description: \"new description\"\n * })\n */\n async update(id: string, options: Update): Promise<Output<null>> {\n if (!this.#auth?.length)\n throw new Error(\"An auth key is required to use PasteGG#update()\");\n\n if (!options.name) options.name = null;\n return this._request(Methods.PATCH, `/pastes/${id}`, options);\n }\n}\n\n/**\n * The header options\n * @typedef {IHeader} IHeader\n * @property {string} [Content-Type] The request content type\n * @property {string} [Authorization] Authorization for the request\n */\n\n/**\n * @typedef {Options} Options\n * @property {string} [baseUrl=https://api.paste.gg] The base URL of the API\n * @property {string} [mainUrl=https://paste.gg] The URL of the main website\n * @property {number} [version=1] The version of the API\n */\n\n/**\n * @typedef {Result} Result\n * @property {string} id The ID of the created paste\n * @property {string} [name] The name of the created paste\n * @property {string} [url] The URL for the result\n * @property {Author} [author] The author of the paste\n * @property {string} [description] The description of the created paste\n * @property {public | unlisted | private} [visibility=unlisted] The visibility of the created paste\n * @property {string} created_at The date the paste was created\n * @property {string} updated_at The date the paste was last updated\n * @property {string} [expires] The date when the paste expires\n * @property {File[]} [files] The files used in the created paste\n * @property {string} [deletion_key] The deletion key of the created paste\n */\n\n/**\n * @typedef {Output} Output\n * @property {\"success\" | \"error\"} status The output status\n * @property {Result} [result] The result data object\n * @property {string} [error] The error key\n * @property {string} [message] The error message\n */\n\n/**\n * @typedef {Post} Post\n * @property {string} [name] The name of the paste\n * @property {string} [description] The description of the paste (must be less than 25 KiB)\n * @property {public | unlisted | private} [visibility=unlisted] The visibility of the paste\n * @property {string} [expires] The expiration date of the paste (must be a UTC ISO 8601 string)\n * @property {FileOut[]} files Array of files to add to the paste (at least one file)\n */\n\n/**\n * @typedef {Author} Author\n * @property {string} [id] The ID of the author\n * @property {string} [username] The username of the author\n * @property {string} [name] The name of the author\n */\n\n/**\n * @typedef {Update} Update\n * @property {string} [name] The new name of the post\n * @property {string} description The new description of the post\n */\n\n/**\n * @typedef {File} File\n * @property {string} id The ID of the file\n * @property {string} name The name of the file\n * @property {string | null} highlight_language The syntax highlighting language used\n */\n\n/**\n * @typedef {Content} Content\n * @property {text | base64 | gzip | xz} format The format of the file\n * @property {string} [highlight_language] The syntax highlighting language to use\n * @property {string} value The value of the file contents\n */\n\n/**\n * @typedef {FileOut} FileOut\n * @property {string} [name] The name of the file\n * @property {Content} content The content of the file\n */\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["stringify"],"mappings":";;;;;;;;;;;;;AAYA,IAAM,cAAiB,GAAA;AAAA,EACnB,OAAS,EAAA,sBAAA;AAAA,EACT,OAAS,EAAA,kBAAA;AAAA,EACT,OAAS,EAAA;AACb,CAAA;AAhBA,IAAA,KAAA,EAAA,IAAA;AAqBA,IAAqB,QAAA,GAArB,MAAqB,QAAQ,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBzB,WAAA,CAAY,IAAe,EAAA,OAAA,GAAmB,cAAgB,EAAA;AAlB9D,IAAS,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AACT,IAAS,YAAA,CAAA,IAAA,EAAA,IAAA,CAAA;AAwBL,IAAA,YAAA,CAAA,IAAA,EAAK,KAAQ,EAAA,IAAA,CAAA;AAOb,IAAA,IAAA,CAAK,OAAU,GAAA,MAAA,CAAO,MAAyB,CAAA,cAAA,EAAgB,OAAO,CAAA;AAOtE,IAAA,IAAA,CAAK,OAAU,GAAA,qBAAA;AAOf,IAAK,YAAA,CAAA,IAAA,EAAA,IAAA,EAAO,GAAG,IAAK,CAAA,OAAA,CAAQ,OAAO,CAAK,EAAA,EAAA,IAAA,CAAK,QAAQ,OAAO,CAAA,CAAA,CAAA;AAAA;AAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAc,QAAA,CACV,MACA,EAAA,IAAA,EACA,MACA,GACkB,EAAA;AAClB,IAAA,MAAM,UAAmB,EAAC;AAC1B,IAAA,IAAI,mBAAK,KAAO,CAAA,EAAA,OAAA,CAAQ,aAAgB,GAAA,CAAA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AAO,CAAA,EAAA,EAAY,OAAwC,EAAA;AAC7D,IAAI,IAAA,CAAC,mBAAK,KAAO,CAAA,EAAA,MAAA;AACb,MAAM,MAAA,IAAI,MAAM,iDAAiD,CAAA;AAErE,IAAA,IAAI,CAAC,OAAA,CAAQ,IAAM,EAAA,OAAA,CAAQ,IAAO,GAAA,IAAA;AAClC,IAAA,OAAO,IAAK,CAAA,QAAA,CAAA,OAAA,cAAwB,CAAW,QAAA,EAAA,EAAE,IAAI,OAAO,CAAA;AAAA;AAEpE,CAAA;AAlMa,KAAA,GAAA,IAAA,OAAA,EAAA;AACA,IAAA,GAAA,IAAA,OAAA,EAAA;AAFgB,MAAA,CAAA,QAAA,EAAA,SAAA,CAAA;AAA7B,IAAqB,OAArB,GAAA","file":"index.cjs","sourcesContent":["import { stringify, type ParsedUrlQueryInput } from \"node:querystring\";\nimport {\n Methods,\n type IHeader,\n type Options,\n type Output,\n type Post,\n type Update,\n type Result,\n type ResultOutput,\n} from \"./interfaces.js\";\n\nconst defaultOptions = {\n baseUrl: \"https://api.paste.gg\",\n mainUrl: \"https://paste.gg\",\n version: 1,\n} satisfies Options;\n\n/**\n * The main class for interacting with the Paste.gg API\n */\nexport default class PasteGG {\n readonly #auth: string;\n readonly #url: string;\n readonly options: Options;\n readonly version: string;\n\n /**\n * Create a new instance of PasteGG\n * @param {string} auth Optional auth key\n * @param {Options} options Options for the paste server\n * @class PasteGG\n * @public\n * @example\n * // If you want to be anonymous\n * const pasteGG = new PasteGG()\n *\n * // If you want to use an api key\n * const pasteGG = new PasteGG(\"apiKeyHere\")\n */\n constructor(auth?: string, options: Options = defaultOptions) {\n /**\n * The auth key\n * @type {string}\n * @private\n * @readonly\n */\n this.#auth = auth;\n /**\n * The options for the paste server\n * @type {Options}\n * @public\n * @readonly\n */\n this.options = Object.assign<Options, Options>(defaultOptions, options);\n /**\n * The version of the API wrapper\n * @type {string}\n * @public\n * @readonly\n */\n this.version = \"v1.1.4-next.8249d8b\";\n /**\n * The full URL for the API\n * @type {string}\n * @private\n * @readonly\n */\n this.#url = `${this.options.baseUrl}/v${this.options.version}`;\n }\n\n /**\n * Make a request to the API.\n * @param {keyof typeof Methods} method\n * @param {string} path\n * @param {object} body\n * @param {string} key\n * @returns {Promise<Output<T>>}\n * @private\n */\n private async _request<T = Result>(\n method: keyof typeof Methods,\n path: string,\n body?: object,\n key?: string,\n ): Promise<Output<T>> {\n const headers: IHeader = {};\n if (this.#auth) headers.Authorization = `Key ${this.#auth}`;\n if (key?.length) headers.Authorization = `Key ${key}`;\n if (method !== \"GET\") headers[\"Content-Type\"] = \"application/json\";\n\n let urlPath = `${this.#url}${path}`;\n if (body && method === \"GET\")\n urlPath += `?${stringify(body as ParsedUrlQueryInput)}`;\n\n const res = await fetch(urlPath, {\n method,\n headers,\n body: body && method !== \"GET\" ? JSON.stringify(body) : null,\n });\n\n try {\n return (await res.json()) as Output<T>;\n } catch (e) {\n if (\n e instanceof Error &&\n e.message === \"Unexpected end of JSON input\"\n ) {\n return { status: \"success\", result: null };\n }\n\n return { status: \"error\", error: e.name, message: e.message };\n }\n }\n\n /**\n * Get an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#get-pastesid\n * @param {string} id The ID of the paste.\n * @param {boolean} full Includes the contents of files if true.\n * @returns {Promise<ResultOutput>}\n * @public\n * @example\n * // if you would like to exclude file contents\n * await pasteGG.get(\"idHere\")\n *\n * // If you would like to include file contents\n * await pasteGG.get(\"idHere\", true)\n */\n async get(id: string, full: boolean = false): Promise<Output> {\n if (!id?.length) {\n throw new Error(\"A paste ID is required to use PasteGG#get()\");\n }\n\n return this._request(Methods.GET, `/pastes/${id}`, { full });\n }\n\n /**\n * Create a new paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#post-pastes\n * @param {Post} input The information to create the paste with.\n * @returns {Promise<ResultOutput>}\n * @public\n * @example\n * await pasteGG.post({\n * name: \"Paste name\", // Optional\n * description: \"Paste description\", // Optional\n * expires: \"2020-12-21T02:25:56.428Z\", // Optional (must be a UTC ISO 8601 string)\n * files: [{\n * name: \"file.txt\", // Optional\n * content: {\n * format: \"text\",\n * value: \"This is where the file content will go\"\n * }\n * }]\n * })\n */\n async post(input: Post): Promise<ResultOutput> {\n if (!input) {\n throw new Error(\n \"An input object is required to use PasteGG#post()\",\n );\n }\n\n const res = await this._request(Methods.POST, \"/pastes\", input);\n if (res.status === \"success\")\n res.result.url = `${this.options.mainUrl}/${res.result.id}`;\n return res;\n }\n\n /**\n * Deletes an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#delete-pastesid\n * @param {string} id The ID of the paste to delete.\n * @param {string} [key] Auth key or deletion key (leave blank if you have set the auth key in the constructor)\n * @returns {Promise<Output<null>>}\n * @public\n * @example\n * // Delete with deletion key\n * await pasteGG.delete(\"idHere\", \"deletionKeyHere\")\n *\n * // Delete with auth key if not set in constructor\n * await pasteGG.delete(\"idHere\", \"authKeyHere\")\n *\n * // Leave blank if auth key is in the class constructor\n * await pasteGG.delete(\"idHere\")\n */\n async delete(id: string, key?: string): Promise<Output<null>> {\n if (!this.#auth?.length && !key?.length)\n throw new Error(\n \"An auth key or deletion key is needed to use PasteGG#delete()\",\n );\n\n return this._request(Methods.DELETE, `/pastes/${id}`, null, key);\n }\n\n /**\n * Update an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#patch-pastesid\n * @param {string} id The ID for the paste to update.\n * @param {Update} options The options you wish to update.\n * @returns {Promise<Output<null>>}\n * @public\n * @example\n * await pasteGG.update(\"idHere\", {\n * name: \"new name\", // Optional (if you want to remove the name)\n * description: \"new description\"\n * })\n */\n async update(id: string, options: Update): Promise<Output<null>> {\n if (!this.#auth?.length)\n throw new Error(\"An auth key is required to use PasteGG#update()\");\n\n if (!options.name) options.name = null;\n return this._request(Methods.PATCH, `/pastes/${id}`, options);\n }\n}\n\n/**\n * The header options\n * @typedef {IHeader} IHeader\n * @property {string} [Content-Type] The request content type\n * @property {string} [Authorization] Authorization for the request\n */\n\n/**\n * @typedef {Options} Options\n * @property {string} [baseUrl=https://api.paste.gg] The base URL of the API\n * @property {string} [mainUrl=https://paste.gg] The URL of the main website\n * @property {number} [version=1] The version of the API\n */\n\n/**\n * @typedef {Result} Result\n * @property {string} id The ID of the created paste\n * @property {string} [name] The name of the created paste\n * @property {string} [url] The URL for the result\n * @property {Author} [author] The author of the paste\n * @property {string} [description] The description of the created paste\n * @property {public | unlisted | private} [visibility=unlisted] The visibility of the created paste\n * @property {string} created_at The date the paste was created\n * @property {string} updated_at The date the paste was last updated\n * @property {string} [expires] The date when the paste expires\n * @property {File[]} [files] The files used in the created paste\n * @property {string} [deletion_key] The deletion key of the created paste\n */\n\n/**\n * @typedef {Output} Output\n * @property {\"success\" | \"error\"} status The output status\n * @property {Result} [result] The result data object\n * @property {string} [error] The error key\n * @property {string} [message] The error message\n */\n\n/**\n * @typedef {Post} Post\n * @property {string} [name] The name of the paste\n * @property {string} [description] The description of the paste (must be less than 25 KiB)\n * @property {public | unlisted | private} [visibility=unlisted] The visibility of the paste\n * @property {string} [expires] The expiration date of the paste (must be a UTC ISO 8601 string)\n * @property {FileOut[]} files Array of files to add to the paste (at least one file)\n */\n\n/**\n * @typedef {Author} Author\n * @property {string} [id] The ID of the author\n * @property {string} [username] The username of the author\n * @property {string} [name] The name of the author\n */\n\n/**\n * @typedef {Update} Update\n * @property {string} [name] The new name of the post\n * @property {string} description The new description of the post\n */\n\n/**\n * @typedef {File} File\n * @property {string} id The ID of the file\n * @property {string} name The name of the file\n * @property {string | null} highlight_language The syntax highlighting language used\n */\n\n/**\n * @typedef {Content} Content\n * @property {text | base64 | gzip | xz} format The format of the file\n * @property {string} [highlight_language] The syntax highlighting language to use\n * @property {string} value The value of the file contents\n */\n\n/**\n * @typedef {FileOut} FileOut\n * @property {string} [name] The name of the file\n * @property {Content} content The content of the file\n */\n"]}
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ var _PasteGG = class _PasteGG {
34
34
  __privateAdd(this, _url);
35
35
  __privateSet(this, _auth, auth);
36
36
  this.options = Object.assign(defaultOptions, options);
37
- this.version = "v1.1.4-next.7332cea";
37
+ this.version = "v1.1.4-next.8249d8b";
38
38
  __privateSet(this, _url, `${this.options.baseUrl}/v${this.options.version}`);
39
39
  }
40
40
  /**
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAYA,IAAM,cAAiB,GAAA;AAAA,EACnB,OAAS,EAAA,sBAAA;AAAA,EACT,OAAS,EAAA,kBAAA;AAAA,EACT,OAAS,EAAA;AACb,CAAA;AAhBA,IAAA,KAAA,EAAA,IAAA;AAqBA,IAAqB,QAAA,GAArB,MAAqB,QAAQ,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBzB,WAAA,CAAY,IAAe,EAAA,OAAA,GAAmB,cAAgB,EAAA;AAlB9D,IAAS,YAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AACT,IAAS,YAAA,CAAA,IAAA,EAAA,IAAA,CAAA;AAwBL,IAAA,YAAA,CAAA,IAAA,EAAK,KAAQ,EAAA,IAAA,CAAA;AAOb,IAAA,IAAA,CAAK,OAAU,GAAA,MAAA,CAAO,MAAyB,CAAA,cAAA,EAAgB,OAAO,CAAA;AAOtE,IAAA,IAAA,CAAK,OAAU,GAAA,qBAAA;AAOf,IAAK,YAAA,CAAA,IAAA,EAAA,IAAA,EAAO,GAAG,IAAK,CAAA,OAAA,CAAQ,OAAO,CAAK,EAAA,EAAA,IAAA,CAAK,QAAQ,OAAO,CAAA,CAAA,CAAA;AAAA;AAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAc,QAAA,CACV,MACA,EAAA,IAAA,EACA,MACA,GACkB,EAAA;AAClB,IAAA,MAAM,UAAmB,EAAC;AAC1B,IAAA,IAAI,mBAAK,KAAO,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AA;AAAA;AAAA;AAAA;AAAA,EAeA,MAAM,MAAO,CAAA,EAAA,EAAY,OAAwC,EAAA;AAC7D,IAAI,IAAA,CAAC,mBAAK,KAAO,CAAA,EAAA,MAAA;AACb,MAAM,MAAA,IAAI,MAAM,iDAAiD,CAAA;AAErE,IAAA,IAAI,CAAC,OAAA,CAAQ,IAAM,EAAA,OAAA,CAAQ,IAAO,GAAA,IAAA;AAClC,IAAA,OAAO,IAAK,CAAA,QAAA,CAAA,OAAA,cAAwB,CAAW,QAAA,EAAA,EAAE,IAAI,OAAO,CAAA;AAAA;AAEpE,CAAA;AAlMa,KAAA,GAAA,IAAA,OAAA,EAAA;AACA,IAAA,GAAA,IAAA,OAAA,EAAA;AAFgB,MAAA,CAAA,QAAA,EAAA,SAAA,CAAA;AAA7B,IAAqB,OAArB,GAAA","file":"index.js","sourcesContent":["import { stringify, type ParsedUrlQueryInput } from \"node:querystring\";\nimport {\n Methods,\n type IHeader,\n type Options,\n type Output,\n type Post,\n type Update,\n type Result,\n type ResultOutput,\n} from \"./interfaces.js\";\n\nconst defaultOptions = {\n baseUrl: \"https://api.paste.gg\",\n mainUrl: \"https://paste.gg\",\n version: 1,\n} satisfies Options;\n\n/**\n * The main class for interacting with the Paste.gg API\n */\nexport default class PasteGG {\n readonly #auth: string;\n readonly #url: string;\n readonly options: Options;\n readonly version: string;\n\n /**\n * Create a new instance of PasteGG\n * @param {string} auth Optional auth key\n * @param {Options} options Options for the paste server\n * @class PasteGG\n * @public\n * @example\n * // If you want to be anonymous\n * const pasteGG = new PasteGG()\n *\n * // If you want to use an api key\n * const pasteGG = new PasteGG(\"apiKeyHere\")\n */\n constructor(auth?: string, options: Options = defaultOptions) {\n /**\n * The auth key\n * @type {string}\n * @private\n * @readonly\n */\n this.#auth = auth;\n /**\n * The options for the paste server\n * @type {Options}\n * @public\n * @readonly\n */\n this.options = Object.assign<Options, Options>(defaultOptions, options);\n /**\n * The version of the API wrapper\n * @type {string}\n * @public\n * @readonly\n */\n this.version = \"v1.1.4-next.7332cea\";\n /**\n * The full URL for the API\n * @type {string}\n * @private\n * @readonly\n */\n this.#url = `${this.options.baseUrl}/v${this.options.version}`;\n }\n\n /**\n * Make a request to the API.\n * @param {keyof typeof Methods} method\n * @param {string} path\n * @param {object} body\n * @param {string} key\n * @returns {Promise<Output<T>>}\n * @private\n */\n private async _request<T = Result>(\n method: keyof typeof Methods,\n path: string,\n body?: object,\n key?: string,\n ): Promise<Output<T>> {\n const headers: IHeader = {};\n if (this.#auth) headers.Authorization = `Key ${this.#auth}`;\n if (key?.length) headers.Authorization = `Key ${key}`;\n if (method !== \"GET\") headers[\"Content-Type\"] = \"application/json\";\n\n let urlPath = `${this.#url}${path}`;\n if (body && method === \"GET\")\n urlPath += `?${stringify(body as ParsedUrlQueryInput)}`;\n\n const res = await fetch(urlPath, {\n method,\n headers,\n body: body && method !== \"GET\" ? JSON.stringify(body) : null,\n });\n\n try {\n return (await res.json()) as Output<T>;\n } catch (e) {\n if (\n e instanceof Error &&\n e.message === \"Unexpected end of JSON input\"\n ) {\n return { status: \"success\", result: null };\n }\n\n return { status: \"error\", error: e.name, message: e.message };\n }\n }\n\n /**\n * Get an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#get-pastesid\n * @param {string} id The ID of the paste.\n * @param {boolean} full Includes the contents of files if true.\n * @returns {Promise<ResultOutput>}\n * @public\n * @example\n * // if you would like to exclude file contents\n * await pasteGG.get(\"idHere\")\n *\n * // If you would like to include file contents\n * await pasteGG.get(\"idHere\", true)\n */\n async get(id: string, full: boolean = false): Promise<Output> {\n if (!id?.length) {\n throw new Error(\"A paste ID is required to use PasteGG#get()\");\n }\n\n return this._request(Methods.GET, `/pastes/${id}`, { full });\n }\n\n /**\n * Create a new paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#post-pastes\n * @param {Post} input The information to create the paste with.\n * @returns {Promise<ResultOutput>}\n * @public\n * @example\n * await pasteGG.post({\n * name: \"Paste name\", // Optional\n * description: \"Paste description\", // Optional\n * expires: \"2020-12-21T02:25:56.428Z\", // Optional (must be a UTC ISO 8601 string)\n * files: [{\n * name: \"file.txt\", // Optional\n * content: {\n * format: \"text\",\n * value: \"This is where the file content will go\"\n * }\n * }]\n * })\n */\n async post(input: Post): Promise<ResultOutput> {\n if (!input) {\n throw new Error(\n \"An input object is required to use PasteGG#post()\",\n );\n }\n\n const res = await this._request(Methods.POST, \"/pastes\", input);\n if (res.status === \"success\")\n res.result.url = `${this.options.mainUrl}/${res.result.id}`;\n return res;\n }\n\n /**\n * Deletes an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#delete-pastesid\n * @param {string} id The ID of the paste to delete.\n * @param {string} [key] Auth key or deletion key (leave blank if you have set the auth key in the constructor)\n * @returns {Promise<Output<null>>}\n * @public\n * @example\n * // Delete with deletion key\n * await pasteGG.delete(\"idHere\", \"deletionKeyHere\")\n *\n * // Delete with auth key if not set in constructor\n * await pasteGG.delete(\"idHere\", \"authKeyHere\")\n *\n * // Leave blank if auth key is in the class constructor\n * await pasteGG.delete(\"idHere\")\n */\n async delete(id: string, key?: string): Promise<Output<null>> {\n if (!this.#auth?.length && !key?.length)\n throw new Error(\n \"An auth key or deletion key is needed to use PasteGG#delete()\",\n );\n\n return this._request(Methods.DELETE, `/pastes/${id}`, null, key);\n }\n\n /**\n * Update an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#patch-pastesid\n * @param {string} id The ID for the paste to update.\n * @param {Update} options The options you wish to update.\n * @returns {Promise<Output<null>>}\n * @public\n * @example\n * await pasteGG.update(\"idHere\", {\n * name: \"new name\", // Optional (if you want to remove the name)\n * description: \"new description\"\n * })\n */\n async update(id: string, options: Update): Promise<Output<null>> {\n if (!this.#auth?.length)\n throw new Error(\"An auth key is required to use PasteGG#update()\");\n\n if (!options.name) options.name = null;\n return this._request(Methods.PATCH, `/pastes/${id}`, options);\n }\n}\n\n/**\n * The header options\n * @typedef {IHeader} IHeader\n * @property {string} [Content-Type] The request content type\n * @property {string} [Authorization] Authorization for the request\n */\n\n/**\n * @typedef {Options} Options\n * @property {string} [baseUrl=https://api.paste.gg] The base URL of the API\n * @property {string} [mainUrl=https://paste.gg] The URL of the main website\n * @property {number} [version=1] The version of the API\n */\n\n/**\n * @typedef {Result} Result\n * @property {string} id The ID of the created paste\n * @property {string} [name] The name of the created paste\n * @property {string} [url] The URL for the result\n * @property {Author} [author] The author of the paste\n * @property {string} [description] The description of the created paste\n * @property {public | unlisted | private} [visibility=unlisted] The visibility of the created paste\n * @property {string} created_at The date the paste was created\n * @property {string} updated_at The date the paste was last updated\n * @property {string} [expires] The date when the paste expires\n * @property {File[]} [files] The files used in the created paste\n * @property {string} [deletion_key] The deletion key of the created paste\n */\n\n/**\n * @typedef {Output} Output\n * @property {\"success\" | \"error\"} status The output status\n * @property {Result} [result] The result data object\n * @property {string} [error] The error key\n * @property {string} [message] The error message\n */\n\n/**\n * @typedef {Post} Post\n * @property {string} [name] The name of the paste\n * @property {string} [description] The description of the paste (must be less than 25 KiB)\n * @property {public | unlisted | private} [visibility=unlisted] The visibility of the paste\n * @property {string} [expires] The expiration date of the paste (must be a UTC ISO 8601 string)\n * @property {FileOut[]} files Array of files to add to the paste (at least one file)\n */\n\n/**\n * @typedef {Author} Author\n * @property {string} [id] The ID of the author\n * @property {string} [username] The username of the author\n * @property {string} [name] The name of the author\n */\n\n/**\n * @typedef {Update} Update\n * @property {string} [name] The new name of the post\n * @property {string} description The new description of the post\n */\n\n/**\n * @typedef {File} File\n * @property {string} id The ID of the file\n * @property {string} name The name of the file\n * @property {string | null} highlight_language The syntax highlighting language used\n */\n\n/**\n * @typedef {Content} Content\n * @property {text | base64 | gzip | xz} format The format of the file\n * @property {string} [highlight_language] The syntax highlighting language to use\n * @property {string} value The value of the file contents\n */\n\n/**\n * @typedef {FileOut} FileOut\n * @property {string} [name] The name of the file\n * @property {Content} content The content of the file\n */\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;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AAA;AAClC,IAAA,OAAO,IAAK,CAAA,QAAA,CAAA,OAAA,cAAwB,CAAW,QAAA,EAAA,EAAE,IAAI,OAAO,CAAA;AAAA;AAEpE,CAAA;AAlMa,KAAA,GAAA,IAAA,OAAA,EAAA;AACA,IAAA,GAAA,IAAA,OAAA,EAAA;AAFgB,MAAA,CAAA,QAAA,EAAA,SAAA,CAAA;AAA7B,IAAqB,OAArB,GAAA","file":"index.js","sourcesContent":["import { stringify, type ParsedUrlQueryInput } from \"node:querystring\";\nimport {\n Methods,\n type IHeader,\n type Options,\n type Output,\n type Post,\n type Update,\n type Result,\n type ResultOutput,\n} from \"./interfaces.js\";\n\nconst defaultOptions = {\n baseUrl: \"https://api.paste.gg\",\n mainUrl: \"https://paste.gg\",\n version: 1,\n} satisfies Options;\n\n/**\n * The main class for interacting with the Paste.gg API\n */\nexport default class PasteGG {\n readonly #auth: string;\n readonly #url: string;\n readonly options: Options;\n readonly version: string;\n\n /**\n * Create a new instance of PasteGG\n * @param {string} auth Optional auth key\n * @param {Options} options Options for the paste server\n * @class PasteGG\n * @public\n * @example\n * // If you want to be anonymous\n * const pasteGG = new PasteGG()\n *\n * // If you want to use an api key\n * const pasteGG = new PasteGG(\"apiKeyHere\")\n */\n constructor(auth?: string, options: Options = defaultOptions) {\n /**\n * The auth key\n * @type {string}\n * @private\n * @readonly\n */\n this.#auth = auth;\n /**\n * The options for the paste server\n * @type {Options}\n * @public\n * @readonly\n */\n this.options = Object.assign<Options, Options>(defaultOptions, options);\n /**\n * The version of the API wrapper\n * @type {string}\n * @public\n * @readonly\n */\n this.version = \"v1.1.4-next.8249d8b\";\n /**\n * The full URL for the API\n * @type {string}\n * @private\n * @readonly\n */\n this.#url = `${this.options.baseUrl}/v${this.options.version}`;\n }\n\n /**\n * Make a request to the API.\n * @param {keyof typeof Methods} method\n * @param {string} path\n * @param {object} body\n * @param {string} key\n * @returns {Promise<Output<T>>}\n * @private\n */\n private async _request<T = Result>(\n method: keyof typeof Methods,\n path: string,\n body?: object,\n key?: string,\n ): Promise<Output<T>> {\n const headers: IHeader = {};\n if (this.#auth) headers.Authorization = `Key ${this.#auth}`;\n if (key?.length) headers.Authorization = `Key ${key}`;\n if (method !== \"GET\") headers[\"Content-Type\"] = \"application/json\";\n\n let urlPath = `${this.#url}${path}`;\n if (body && method === \"GET\")\n urlPath += `?${stringify(body as ParsedUrlQueryInput)}`;\n\n const res = await fetch(urlPath, {\n method,\n headers,\n body: body && method !== \"GET\" ? JSON.stringify(body) : null,\n });\n\n try {\n return (await res.json()) as Output<T>;\n } catch (e) {\n if (\n e instanceof Error &&\n e.message === \"Unexpected end of JSON input\"\n ) {\n return { status: \"success\", result: null };\n }\n\n return { status: \"error\", error: e.name, message: e.message };\n }\n }\n\n /**\n * Get an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#get-pastesid\n * @param {string} id The ID of the paste.\n * @param {boolean} full Includes the contents of files if true.\n * @returns {Promise<ResultOutput>}\n * @public\n * @example\n * // if you would like to exclude file contents\n * await pasteGG.get(\"idHere\")\n *\n * // If you would like to include file contents\n * await pasteGG.get(\"idHere\", true)\n */\n async get(id: string, full: boolean = false): Promise<Output> {\n if (!id?.length) {\n throw new Error(\"A paste ID is required to use PasteGG#get()\");\n }\n\n return this._request(Methods.GET, `/pastes/${id}`, { full });\n }\n\n /**\n * Create a new paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#post-pastes\n * @param {Post} input The information to create the paste with.\n * @returns {Promise<ResultOutput>}\n * @public\n * @example\n * await pasteGG.post({\n * name: \"Paste name\", // Optional\n * description: \"Paste description\", // Optional\n * expires: \"2020-12-21T02:25:56.428Z\", // Optional (must be a UTC ISO 8601 string)\n * files: [{\n * name: \"file.txt\", // Optional\n * content: {\n * format: \"text\",\n * value: \"This is where the file content will go\"\n * }\n * }]\n * })\n */\n async post(input: Post): Promise<ResultOutput> {\n if (!input) {\n throw new Error(\n \"An input object is required to use PasteGG#post()\",\n );\n }\n\n const res = await this._request(Methods.POST, \"/pastes\", input);\n if (res.status === \"success\")\n res.result.url = `${this.options.mainUrl}/${res.result.id}`;\n return res;\n }\n\n /**\n * Deletes an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#delete-pastesid\n * @param {string} id The ID of the paste to delete.\n * @param {string} [key] Auth key or deletion key (leave blank if you have set the auth key in the constructor)\n * @returns {Promise<Output<null>>}\n * @public\n * @example\n * // Delete with deletion key\n * await pasteGG.delete(\"idHere\", \"deletionKeyHere\")\n *\n * // Delete with auth key if not set in constructor\n * await pasteGG.delete(\"idHere\", \"authKeyHere\")\n *\n * // Leave blank if auth key is in the class constructor\n * await pasteGG.delete(\"idHere\")\n */\n async delete(id: string, key?: string): Promise<Output<null>> {\n if (!this.#auth?.length && !key?.length)\n throw new Error(\n \"An auth key or deletion key is needed to use PasteGG#delete()\",\n );\n\n return this._request(Methods.DELETE, `/pastes/${id}`, null, key);\n }\n\n /**\n * Update an existing paste.\n * @see https://github.com/ascclemens/paste/blob/master/api.md#patch-pastesid\n * @param {string} id The ID for the paste to update.\n * @param {Update} options The options you wish to update.\n * @returns {Promise<Output<null>>}\n * @public\n * @example\n * await pasteGG.update(\"idHere\", {\n * name: \"new name\", // Optional (if you want to remove the name)\n * description: \"new description\"\n * })\n */\n async update(id: string, options: Update): Promise<Output<null>> {\n if (!this.#auth?.length)\n throw new Error(\"An auth key is required to use PasteGG#update()\");\n\n if (!options.name) options.name = null;\n return this._request(Methods.PATCH, `/pastes/${id}`, options);\n }\n}\n\n/**\n * The header options\n * @typedef {IHeader} IHeader\n * @property {string} [Content-Type] The request content type\n * @property {string} [Authorization] Authorization for the request\n */\n\n/**\n * @typedef {Options} Options\n * @property {string} [baseUrl=https://api.paste.gg] The base URL of the API\n * @property {string} [mainUrl=https://paste.gg] The URL of the main website\n * @property {number} [version=1] The version of the API\n */\n\n/**\n * @typedef {Result} Result\n * @property {string} id The ID of the created paste\n * @property {string} [name] The name of the created paste\n * @property {string} [url] The URL for the result\n * @property {Author} [author] The author of the paste\n * @property {string} [description] The description of the created paste\n * @property {public | unlisted | private} [visibility=unlisted] The visibility of the created paste\n * @property {string} created_at The date the paste was created\n * @property {string} updated_at The date the paste was last updated\n * @property {string} [expires] The date when the paste expires\n * @property {File[]} [files] The files used in the created paste\n * @property {string} [deletion_key] The deletion key of the created paste\n */\n\n/**\n * @typedef {Output} Output\n * @property {\"success\" | \"error\"} status The output status\n * @property {Result} [result] The result data object\n * @property {string} [error] The error key\n * @property {string} [message] The error message\n */\n\n/**\n * @typedef {Post} Post\n * @property {string} [name] The name of the paste\n * @property {string} [description] The description of the paste (must be less than 25 KiB)\n * @property {public | unlisted | private} [visibility=unlisted] The visibility of the paste\n * @property {string} [expires] The expiration date of the paste (must be a UTC ISO 8601 string)\n * @property {FileOut[]} files Array of files to add to the paste (at least one file)\n */\n\n/**\n * @typedef {Author} Author\n * @property {string} [id] The ID of the author\n * @property {string} [username] The username of the author\n * @property {string} [name] The name of the author\n */\n\n/**\n * @typedef {Update} Update\n * @property {string} [name] The new name of the post\n * @property {string} description The new description of the post\n */\n\n/**\n * @typedef {File} File\n * @property {string} id The ID of the file\n * @property {string} name The name of the file\n * @property {string | null} highlight_language The syntax highlighting language used\n */\n\n/**\n * @typedef {Content} Content\n * @property {text | base64 | gzip | xz} format The format of the file\n * @property {string} [highlight_language] The syntax highlighting language to use\n * @property {string} value The value of the file contents\n */\n\n/**\n * @typedef {FileOut} FileOut\n * @property {string} [name] The name of the file\n * @property {Content} content The content of the file\n */\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "paste.gg",
3
- "version": "1.1.4-next.7332cea",
3
+ "version": "1.1.4-next.8249d8b",
4
4
  "description": "An easy-to-use library for interacting with the Paste.GG API. Contains examples, strong JSDocs, TypeScript types, and support for Node.js 12+. Works in both JavaScript and TypeScript.",
5
5
  "license": "MIT",
6
6
  "author": "Seren_Modz 21",
@@ -44,7 +44,7 @@
44
44
  "@commitlint/config-conventional": "^20.2.0",
45
45
  "@favware/cliff-jumper": "^6.0.0",
46
46
  "@favware/npm-deprecate": "^2.0.0",
47
- "@types/node": "^24.10.3",
47
+ "@types/node": "^24.10.4",
48
48
  "esbuild-plugin-version-injector": "^1.2.1",
49
49
  "prettier": "^3.7.4",
50
50
  "pretty-quick": "^4.2.2",