cloudnode-ts
Advanced tools
Comparing version
@@ -35,7 +35,7 @@ | ||
*/ | ||
#apiVersion = `5.11.3`; | ||
#apiVersion = `5.11.4`; | ||
/** | ||
* Client user agent | ||
*/ | ||
#userAgent = `cloudnode/1.10.2`; | ||
#userAgent = `cloudnode/1.10.3`; | ||
/** | ||
@@ -426,3 +426,3 @@ * Construct a new Cloudnode API client | ||
register: async (username, email, password) => { | ||
return await this.#sendRequest({ "type": "operation", "description": "Create an account and session. After signing up, a welcome e-mail is sent to confirm your e-mail address.\n\n> **Note**: Registering an account can only be performed from residential IP. Proxying this endpoint will likely not work. Creating multiple/alternate accounts is not allowed as per the Terms of Service.", "method": "POST", "path": "/auth/register", "parameters": { "body": { "username": { "description": "The username to use for the account. Must be between 3 and 32 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.", "type": "string", "required": true }, "email": { "description": "The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.", "type": "string", "required": true }, "password": { "description": "The password to use for the account. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.", "type": "string", "required": true } } }, "returns": [{ "status": 201, "type": "{session: string}", "description": "Session token. Also returned in `Set-Cookie` header." }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 403, "type": "Error & {code: \"IP_REJECTED\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { username, email, password }); | ||
return await this.#sendRequest({ "type": "operation", "description": "Create an account and session. After signing up, a welcome e-mail is sent to confirm your e-mail address.\n\n> **Note**: Registering an account can only be performed from residential IP. Proxying this endpoint will likely not work. Creating multiple/alternate accounts is not allowed as per the Terms of Service.", "method": "POST", "path": "/auth/register", "token": null, "parameters": { "body": { "username": { "description": "The username to use for the account. Must be between 3 and 32 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.", "type": "string", "required": true }, "email": { "description": "The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.", "type": "string", "required": true }, "password": { "description": "The password to use for the account. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.", "type": "string", "required": true } } }, "returns": [{ "status": 201, "type": "{session: string}", "description": "Session token. Also returned in `Set-Cookie` header." }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 403, "type": "Error & {code: \"IP_REJECTED\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { username, email, password }); | ||
}, | ||
@@ -444,3 +444,3 @@ /** | ||
login: async (user, password) => { | ||
return await this.#sendRequest({ "type": "operation", "description": "Create a session using user ID/username/e-mail and password.\n\n> **Note**: Logging in can only be performed from residential IP. Proxying this endpoint will likely not work. It is normally not recommended to use this endpoint to gain API access. Instead, create a token from your account to use with the API.", "method": "POST", "path": "/auth/login", "parameters": { "body": { "user": { "description": "User ID (starts with `user_`), username or e-mail address.", "type": "string", "required": true }, "password": { "description": "The password of the account.", "type": "string", "required": true } } }, "returns": [{ "status": 201, "type": "{session: string}", "description": "Session token. Also returned in `Set-Cookie` header." }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 403, "type": "Error & {code: \"IP_REJECTED\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { user, password }); | ||
return await this.#sendRequest({ "type": "operation", "description": "Create a session using user ID/username/e-mail and password.\n\n> **Note**: Logging in can only be performed from residential IP. Proxying this endpoint will likely not work. It is normally not recommended to use this endpoint to gain API access. Instead, create a token from your account to use with the API.", "method": "POST", "path": "/auth/login", "token": null, "parameters": { "body": { "user": { "description": "User ID (starts with `user_`), username or e-mail address.", "type": "string", "required": true }, "password": { "description": "The password of the account.", "type": "string", "required": true } } }, "returns": [{ "status": 201, "type": "{session: string}", "description": "Session token. Also returned in `Set-Cookie` header." }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 403, "type": "Error & {code: \"IP_REJECTED\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { user, password }); | ||
}, | ||
@@ -447,0 +447,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
class Cloudnode{#e;#t;static#r={baseUrl:"https://api.cloudnode.pro/v5/",autoRetry:!0,maxRetryDelay:5,maxRetries:3};#s="5.11.3";#o="cloudnode/1.10.2";constructor(e,t=Cloudnode.#r){const r=Cloudnode.#r;r.baseUrl=t.baseUrl??Cloudnode.#r.baseUrl,r.autoRetry=t.autoRetry??Cloudnode.#r.autoRetry,r.maxRetryDelay=t.maxRetryDelay??Cloudnode.#r.maxRetryDelay,r.maxRetries=t.maxRetries??Cloudnode.#r.maxRetries,this.#e=e,this.#t=r}async#a(e,t,r,s){const o=new URL(e.path.replace(/^\/+/,""),this.#t.baseUrl);for(const[e,r]of Object.entries(t))o.pathname=o.pathname.replaceAll(`/:${e}`,`/${r}`);for(const[e,t]of Object.entries(r))o.searchParams.append(e,t);const a={method:e.method,headers:{}};s&&!["GET","HEAD"].includes(e.method)&&("string"!=typeof s?(a.body=JSON.stringify(s),a.headers["Content-Type"]="application/json"):(a.body=s,a.headers["Content-Type"]="text/plain")),a.headers["User-Agent"]=this.#o,this.#e&&void 0!==e.token&&(a.headers.Authorization=`Bearer ${this.#e}`),void 0!==e.token&&(a.credentials="include");const n=await fetch(o.toString(),a);if(204===n.status)return;const i=await n.text();let u;u=n.headers.get("Content-Type")?.startsWith("application/json")?JSON.parse(i,((e,t)=>/^\d{4}-\d{2}-\d{2}T(?:\d{2}:){2}\d{2}(?:\.\d+)?(?:[a-zA-Z]+|\+\d{2}:\d{2})?$/.test(t)?new Date(t):t)):i;const d=Cloudnode.makeApiResponse(u,new Cloudnode.RawResponse(n,{operation:e,pathParams:t,queryParams:r,body:s}));if(n.ok)return d;throw d}#n(e,t,r,s,o){return new Promise((async(a,n)=>{const i=(u=0)=>{this.#a(e,t,r,s).then((e=>a(e))).catch((e=>{if(o??=this.#t,o.baseUrl??=this.#t.baseUrl,o.autoRetry??=this.#t.autoRetry,o.maxRetries??=this.#t.maxRetries,o.maxRetryDelay??=this.#t.maxRetryDelay,o.autoRetry&&u<o.maxRetries&&e instanceof Cloudnode.R.ApiResponse){const t=e,r=Number(429!==t._response.status?t._response.headers["x-retry-after"]??t._response.headers["retry-after"]:t._response.headers["x-ratelimit-reset"]??t._response.headers["x-rate-limit-reset"]??t._response.headers["ratelimit-reset"]??t._response.headers["rate-limit-reset"]??t._response.headers["retry-after"]??t._response.headers["x-retry-after"]);if(Number.isNaN(r)||r>o.maxRetryDelay)return n(e);setTimeout(i,1e3*Number(r),++u)}else n(e)}))};i(0)}))}#i(e,t){const r=e.split("."),s=t.split("."),o=[r[0]||"0",r[1]||"0"],a=[s[0]||"0",s[1]||"0"];return o[0]!==a[0]?"incompatible":o[1]!==a[1]?"outdated":"compatible"}async checkCompatibility(){const e=await(await fetch(new URL("../",this.#t.baseUrl).toString(),{method:"GET",headers:{"User-Agent":this.#o}})).json();return this.#i(e.version,this.#s)}async getPage(e,t){if(t*e.limit>e.total||t<1)return null;const r=Object.assign({},e._response.request.queryParams);return r.page=t.toString(),await this.#n(e._response.request.operation,e._response.request.pathParams,r,e._response.request.body)}async getNextPage(e){return await this.getPage(e,e.page+1)}async getPreviousPage(e){return await this.getPage(e,e.page-1)}async getAllPages(e){const t=new Array(Math.ceil(e.total/e.limit)).fill(null);t[e.page-1]=!0;const r=t.map(((t,r)=>null!==t||this.getPage(e,r+1))),s=await Promise.all(r.filter((e=>!0!==e)));s.splice(e.page-1,0,e);return{items:s.filter((e=>null!==e)).map((e=>e.items)).flat(),total:e.total,limit:e.limit,page:1}}newsletter={list:async(e=10,t=1)=>await this.#n({type:"operation",description:"List newsletters",method:"GET",path:"/newsletter",parameters:{query:{limit:{description:"The number of newsletters to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"Newsletter[]"},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{}),get:async e=>await this.#n({type:"operation",description:"Get newsletter",method:"GET",path:"/newsletter/:id",parameters:{path:{id:{description:"A newsletter ID",type:"string",required:!0}}},returns:[{status:200,type:"Newsletter"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),subscribe:async(e,t,r)=>await this.#n({type:"operation",description:"Subscribe to newsletter",method:"POST",path:"/newsletter/:id/subscribe",parameters:{path:{id:{description:"A newsletter ID",type:"string",required:!0}},body:{email:{description:"Subscriber's email address",type:"string",required:!0},data:{description:"Additional data that this newsletter requires",type:"Record<string, string | number | boolean>",required:!1}}},returns:[{status:201,type:"NewsletterSubscription"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{email:t,data:r})};newsletters={unsubscribe:async e=>await this.#n({type:"operation",description:"Revoke a subscription (unsubscribe)",method:"POST",path:"/newsletters/unsubscribe",parameters:{body:{subscription:{description:"The ID of the subscription to revoke",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{subscription:e}),listSubscriptions:async(e=10,t=1)=>await this.#n({type:"operation",description:"List subscriptions of the authenticated user",token:"newsletter.subscriptions.list.own",method:"GET",path:"/newsletters/subscriptions",parameters:{query:{limit:{description:"The number of subscriptions to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"DatedNewsletterSubscription[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{})};token={list:async(e=10,t=1,r)=>await this.#n({type:"operation",description:"List tokens of user",token:"tokens.list.own",method:"GET",path:"/token",parameters:{query:{limit:{description:"The number of tokens to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1},internal:{description:"Internal tokens are returned as well if this parameter is present.",type:"any",required:!1}}},returns:[{status:200,type:"PartialToken[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`,internal:`${r}`},{}),create:async(e,t,r)=>await this.#n({type:"operation",description:"Create token",token:"tokens.create.own",method:"POST",path:"/token",parameters:{body:{permissions:{description:"List of permissions to grant to the token. You must already have each of these permissions with your current token.",type:"string[]",required:!0},lifetime:{description:"Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).",type:"number",required:!0},note:{description:"A user-specified note to label the token. Max length: 2⁸ (256) characters.",type:"string",required:!1}}},returns:[{status:201,type:"Token"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{permissions:e,lifetime:t,note:r}),get:async e=>await this.#n({type:"operation",description:"Get token details",token:"tokens.get.own",method:"GET",path:"/token/:id",parameters:{path:{id:{description:"The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0}}},returns:[{status:200,type:"Token"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),revoke:async e=>await this.#n({type:"operation",description:"Revoke token",token:"tokens.revoke.own",method:"DELETE",path:"/token/:id",parameters:{path:{id:{description:"The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.",type:'string | "current"',required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:400,type:'Error & {code: "MODIFICATION_NOT_ALLOWED"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),listRequests:async(e,t=10,r=1)=>await this.#n({type:"operation",description:"Get list of recent requests made with the token",token:"tokens.get.own.requests",method:"GET",path:"/token/:id/requests",parameters:{path:{id:{description:"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0}},query:{limit:{description:"The number of requests to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"ShortRequest[]"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{limit:`${t}`,page:`${r}`},{}),getRequest:async(e,t)=>await this.#n({type:"operation",description:"Get a recent request by ID",token:"tokens.get.own.requests",method:"GET",path:"/token/:id/requests/:request",parameters:{path:{id:{description:"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0},request:{description:"The ID of the request.",type:"string",required:!0}}},returns:[{status:200,type:"Request"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`,request:`${t}`},{},{})};tokens={refresh:async()=>await this.#n({type:"operation",description:"Refresh current token. The token that was used to authenticate the request will be deleted. A new token with a new ID but the same permissions will be created and returned. The lifespan of the new token will be the same as the old one, starting from the time of the request. This operation effectively allows a token to be used indefinitely.",token:"token.refresh",method:"POST",path:"/token/refresh",parameters:{},returns:[{status:201,type:"Token"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{})};auth={register:async(e,t,r)=>await this.#n({type:"operation",description:"Create an account and session. After signing up, a welcome e-mail is sent to confirm your e-mail address.\n\n> **Note**: Registering an account can only be performed from residential IP. Proxying this endpoint will likely not work. Creating multiple/alternate accounts is not allowed as per the Terms of Service.",method:"POST",path:"/auth/register",parameters:{body:{username:{description:"The username to use for the account. Must be between 3 and 32 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.",type:"string",required:!0},email:{description:"The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.",type:"string",required:!0},password:{description:"The password to use for the account. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.",type:"string",required:!0}}},returns:[{status:201,type:"{session: string}",description:"Session token. Also returned in `Set-Cookie` header."},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:403,type:'Error & {code: "IP_REJECTED"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,email:t,password:r}),login:async(e,t)=>await this.#n({type:"operation",description:"Create a session using user ID/username/e-mail and password.\n\n> **Note**: Logging in can only be performed from residential IP. Proxying this endpoint will likely not work. It is normally not recommended to use this endpoint to gain API access. Instead, create a token from your account to use with the API.",method:"POST",path:"/auth/login",parameters:{body:{user:{description:"User ID (starts with `user_`), username or e-mail address.",type:"string",required:!0},password:{description:"The password of the account.",type:"string",required:!0}}},returns:[{status:201,type:"{session: string}",description:"Session token. Also returned in `Set-Cookie` header."},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:403,type:'Error & {code: "IP_REJECTED"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{user:e,password:t})};account={get:async()=>await this.#n({type:"operation",description:"Get account details",token:"account.details",method:"GET",path:"/account",parameters:{},returns:[{status:200,type:"AccountDetails"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),getIdentity:async()=>await this.#n({type:"operation",description:"Get account identity",token:"account.details.identity",method:"GET",path:"/account/identity",parameters:{},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),updateIdentity:async(e,t)=>await this.#n({type:"operation",description:"Update account identity",token:"account.details.identity.update",method:"PATCH",path:"/account/identity",parameters:{body:{username:{description:"Your unique username. Between 3 and 64 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.",type:"string",required:!0},name:{description:"Your full name. Set to `null` to remove.",type:"string | null",required:!1}}},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,name:t}),replaceIdentity:async(e,t)=>await this.#n({type:"operation",description:"Replace account identity",token:"account.details.identity.update",method:"PUT",path:"/account/identity",parameters:{body:{username:{description:"Your unique username. Between 3 and 64 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.",type:"string",required:!0},name:{description:"Your full name. Set to `null` to remove.",type:"string | null",required:!0}}},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,name:t}),listEmails:async()=>await this.#n({type:"operation",description:"List account e-mail addresses",token:"account.details.email.list",method:"GET",path:"/account/email",parameters:{},returns:[{status:200,type:"AccountEmail[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),getEmail:async()=>await this.#n({type:"operation",description:"Get your primary e-mail address",token:"account.details.email",method:"GET",path:"/account/email/primary",parameters:{},returns:[{status:200,type:"DatedPrimaryEmail"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),setEmail:async e=>await this.#n({type:"operation",description:"Set your primary e-mail address",token:"account.details.email.update",method:"PUT",path:"/account/email/primary",parameters:{body:{email:{description:"E-mail address to set as primary.",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{email:e}),changePassword:async(e,t)=>await this.#n({type:"operation",description:"Change account password",token:"account.details.password.update",method:"PUT",path:"/account/password",parameters:{body:{currentPassword:{description:"Your current password.",type:"string",required:!0},newPassword:{description:"The new password. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{currentPassword:e,newPassword:t}),listPermissions:async()=>await this.#n({type:"operation",description:"List account permissions with user-friendly descriptions. Some permissions (such as wildcard ones) may be excluded in this list if they don't have a description.",token:"account.details",method:"GET",path:"/account/permissions",parameters:{},returns:[{status:200,type:"Permission[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{})}}!function(e){let t;e.RawResponse=class{headers;ok;redirected;status;statusText;url;request;constructor(e,t){this.headers=Object.fromEntries([...e.headers.entries()].map((([e,t])=>[e.toLowerCase(),t]))),this.ok=e.ok,this.redirected=e.redirected,this.status=e.status,this.statusText=e.statusText,this.url=new URL(e.url),this.request=t}},function(e){e.ApiResponse=class{#u;constructor(e){this.#u=e}get _response(){return this.#u}}}(t=e.R||(e.R={})),e.makeApiResponse=function(e,r){return Object.assign(new t.ApiResponse(r),e)}}(Cloudnode||(Cloudnode={})); | ||
class Cloudnode{#e;#t;static#r={baseUrl:"https://api.cloudnode.pro/v5/",autoRetry:!0,maxRetryDelay:5,maxRetries:3};#s="5.11.4";#o="cloudnode/1.10.3";constructor(e,t=Cloudnode.#r){const r=Cloudnode.#r;r.baseUrl=t.baseUrl??Cloudnode.#r.baseUrl,r.autoRetry=t.autoRetry??Cloudnode.#r.autoRetry,r.maxRetryDelay=t.maxRetryDelay??Cloudnode.#r.maxRetryDelay,r.maxRetries=t.maxRetries??Cloudnode.#r.maxRetries,this.#e=e,this.#t=r}async#a(e,t,r,s){const o=new URL(e.path.replace(/^\/+/,""),this.#t.baseUrl);for(const[e,r]of Object.entries(t))o.pathname=o.pathname.replaceAll(`/:${e}`,`/${r}`);for(const[e,t]of Object.entries(r))o.searchParams.append(e,t);const a={method:e.method,headers:{}};s&&!["GET","HEAD"].includes(e.method)&&("string"!=typeof s?(a.body=JSON.stringify(s),a.headers["Content-Type"]="application/json"):(a.body=s,a.headers["Content-Type"]="text/plain")),a.headers["User-Agent"]=this.#o,this.#e&&void 0!==e.token&&(a.headers.Authorization=`Bearer ${this.#e}`),void 0!==e.token&&(a.credentials="include");const n=await fetch(o.toString(),a);if(204===n.status)return;const i=await n.text();let u;u=n.headers.get("Content-Type")?.startsWith("application/json")?JSON.parse(i,((e,t)=>/^\d{4}-\d{2}-\d{2}T(?:\d{2}:){2}\d{2}(?:\.\d+)?(?:[a-zA-Z]+|\+\d{2}:\d{2})?$/.test(t)?new Date(t):t)):i;const d=Cloudnode.makeApiResponse(u,new Cloudnode.RawResponse(n,{operation:e,pathParams:t,queryParams:r,body:s}));if(n.ok)return d;throw d}#n(e,t,r,s,o){return new Promise((async(a,n)=>{const i=(u=0)=>{this.#a(e,t,r,s).then((e=>a(e))).catch((e=>{if(o??=this.#t,o.baseUrl??=this.#t.baseUrl,o.autoRetry??=this.#t.autoRetry,o.maxRetries??=this.#t.maxRetries,o.maxRetryDelay??=this.#t.maxRetryDelay,o.autoRetry&&u<o.maxRetries&&e instanceof Cloudnode.R.ApiResponse){const t=e,r=Number(429!==t._response.status?t._response.headers["x-retry-after"]??t._response.headers["retry-after"]:t._response.headers["x-ratelimit-reset"]??t._response.headers["x-rate-limit-reset"]??t._response.headers["ratelimit-reset"]??t._response.headers["rate-limit-reset"]??t._response.headers["retry-after"]??t._response.headers["x-retry-after"]);if(Number.isNaN(r)||r>o.maxRetryDelay)return n(e);setTimeout(i,1e3*Number(r),++u)}else n(e)}))};i(0)}))}#i(e,t){const r=e.split("."),s=t.split("."),o=[r[0]||"0",r[1]||"0"],a=[s[0]||"0",s[1]||"0"];return o[0]!==a[0]?"incompatible":o[1]!==a[1]?"outdated":"compatible"}async checkCompatibility(){const e=await(await fetch(new URL("../",this.#t.baseUrl).toString(),{method:"GET",headers:{"User-Agent":this.#o}})).json();return this.#i(e.version,this.#s)}async getPage(e,t){if(t*e.limit>e.total||t<1)return null;const r=Object.assign({},e._response.request.queryParams);return r.page=t.toString(),await this.#n(e._response.request.operation,e._response.request.pathParams,r,e._response.request.body)}async getNextPage(e){return await this.getPage(e,e.page+1)}async getPreviousPage(e){return await this.getPage(e,e.page-1)}async getAllPages(e){const t=new Array(Math.ceil(e.total/e.limit)).fill(null);t[e.page-1]=!0;const r=t.map(((t,r)=>null!==t||this.getPage(e,r+1))),s=await Promise.all(r.filter((e=>!0!==e)));s.splice(e.page-1,0,e);return{items:s.filter((e=>null!==e)).map((e=>e.items)).flat(),total:e.total,limit:e.limit,page:1}}newsletter={list:async(e=10,t=1)=>await this.#n({type:"operation",description:"List newsletters",method:"GET",path:"/newsletter",parameters:{query:{limit:{description:"The number of newsletters to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"Newsletter[]"},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{}),get:async e=>await this.#n({type:"operation",description:"Get newsletter",method:"GET",path:"/newsletter/:id",parameters:{path:{id:{description:"A newsletter ID",type:"string",required:!0}}},returns:[{status:200,type:"Newsletter"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),subscribe:async(e,t,r)=>await this.#n({type:"operation",description:"Subscribe to newsletter",method:"POST",path:"/newsletter/:id/subscribe",parameters:{path:{id:{description:"A newsletter ID",type:"string",required:!0}},body:{email:{description:"Subscriber's email address",type:"string",required:!0},data:{description:"Additional data that this newsletter requires",type:"Record<string, string | number | boolean>",required:!1}}},returns:[{status:201,type:"NewsletterSubscription"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{email:t,data:r})};newsletters={unsubscribe:async e=>await this.#n({type:"operation",description:"Revoke a subscription (unsubscribe)",method:"POST",path:"/newsletters/unsubscribe",parameters:{body:{subscription:{description:"The ID of the subscription to revoke",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{subscription:e}),listSubscriptions:async(e=10,t=1)=>await this.#n({type:"operation",description:"List subscriptions of the authenticated user",token:"newsletter.subscriptions.list.own",method:"GET",path:"/newsletters/subscriptions",parameters:{query:{limit:{description:"The number of subscriptions to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"DatedNewsletterSubscription[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`},{})};token={list:async(e=10,t=1,r)=>await this.#n({type:"operation",description:"List tokens of user",token:"tokens.list.own",method:"GET",path:"/token",parameters:{query:{limit:{description:"The number of tokens to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1},internal:{description:"Internal tokens are returned as well if this parameter is present.",type:"any",required:!1}}},returns:[{status:200,type:"PartialToken[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{limit:`${e}`,page:`${t}`,internal:`${r}`},{}),create:async(e,t,r)=>await this.#n({type:"operation",description:"Create token",token:"tokens.create.own",method:"POST",path:"/token",parameters:{body:{permissions:{description:"List of permissions to grant to the token. You must already have each of these permissions with your current token.",type:"string[]",required:!0},lifetime:{description:"Lifetime of the token in seconds. If null, the token will never expire (not recommended). Max: 31560000 (1 year). Min: 60 (1 minute).",type:"number",required:!0},note:{description:"A user-specified note to label the token. Max length: 2⁸ (256) characters.",type:"string",required:!1}}},returns:[{status:201,type:"Token"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{permissions:e,lifetime:t,note:r}),get:async e=>await this.#n({type:"operation",description:"Get token details",token:"tokens.get.own",method:"GET",path:"/token/:id",parameters:{path:{id:{description:"The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0}}},returns:[{status:200,type:"Token"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),revoke:async e=>await this.#n({type:"operation",description:"Revoke token",token:"tokens.revoke.own",method:"DELETE",path:"/token/:id",parameters:{path:{id:{description:"The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request.",type:'string | "current"',required:!0}}},returns:[{status:204,type:"void"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:400,type:'Error & {code: "MODIFICATION_NOT_ALLOWED"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{},{}),listRequests:async(e,t=10,r=1)=>await this.#n({type:"operation",description:"Get list of recent requests made with the token",token:"tokens.get.own.requests",method:"GET",path:"/token/:id/requests",parameters:{path:{id:{description:"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0}},query:{limit:{description:"The number of requests to return per page. No more than 50.",default:"10",type:"number",required:!1},page:{description:"The page number. No more than 2³² (4294967296).",default:"1",type:"number",required:!1}}},returns:[{status:200,type:"ShortRequest[]"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`},{limit:`${t}`,page:`${r}`},{}),getRequest:async(e,t)=>await this.#n({type:"operation",description:"Get a recent request by ID",token:"tokens.get.own.requests",method:"GET",path:"/token/:id/requests/:request",parameters:{path:{id:{description:"The ID of the token. Specify `current` to get information about the token that was used to authenticate the request.",type:'string | "current"',required:!0},request:{description:"The ID of the request.",type:"string",required:!0}}},returns:[{status:200,type:"Request"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{id:`${e}`,request:`${t}`},{},{})};tokens={refresh:async()=>await this.#n({type:"operation",description:"Refresh current token. The token that was used to authenticate the request will be deleted. A new token with a new ID but the same permissions will be created and returned. The lifespan of the new token will be the same as the old one, starting from the time of the request. This operation effectively allows a token to be used indefinitely.",token:"token.refresh",method:"POST",path:"/token/refresh",parameters:{},returns:[{status:201,type:"Token"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{})};auth={register:async(e,t,r)=>await this.#n({type:"operation",description:"Create an account and session. After signing up, a welcome e-mail is sent to confirm your e-mail address.\n\n> **Note**: Registering an account can only be performed from residential IP. Proxying this endpoint will likely not work. Creating multiple/alternate accounts is not allowed as per the Terms of Service.",method:"POST",path:"/auth/register",token:null,parameters:{body:{username:{description:"The username to use for the account. Must be between 3 and 32 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.",type:"string",required:!0},email:{description:"The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.",type:"string",required:!0},password:{description:"The password to use for the account. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.",type:"string",required:!0}}},returns:[{status:201,type:"{session: string}",description:"Session token. Also returned in `Set-Cookie` header."},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:403,type:'Error & {code: "IP_REJECTED"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,email:t,password:r}),login:async(e,t)=>await this.#n({type:"operation",description:"Create a session using user ID/username/e-mail and password.\n\n> **Note**: Logging in can only be performed from residential IP. Proxying this endpoint will likely not work. It is normally not recommended to use this endpoint to gain API access. Instead, create a token from your account to use with the API.",method:"POST",path:"/auth/login",token:null,parameters:{body:{user:{description:"User ID (starts with `user_`), username or e-mail address.",type:"string",required:!0},password:{description:"The password of the account.",type:"string",required:!0}}},returns:[{status:201,type:"{session: string}",description:"Session token. Also returned in `Set-Cookie` header."},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:403,type:'Error & {code: "IP_REJECTED"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{user:e,password:t})};account={get:async()=>await this.#n({type:"operation",description:"Get account details",token:"account.details",method:"GET",path:"/account",parameters:{},returns:[{status:200,type:"AccountDetails"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),getIdentity:async()=>await this.#n({type:"operation",description:"Get account identity",token:"account.details.identity",method:"GET",path:"/account/identity",parameters:{},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),updateIdentity:async(e,t)=>await this.#n({type:"operation",description:"Update account identity",token:"account.details.identity.update",method:"PATCH",path:"/account/identity",parameters:{body:{username:{description:"Your unique username. Between 3 and 64 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.",type:"string",required:!0},name:{description:"Your full name. Set to `null` to remove.",type:"string | null",required:!1}}},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,name:t}),replaceIdentity:async(e,t)=>await this.#n({type:"operation",description:"Replace account identity",token:"account.details.identity.update",method:"PUT",path:"/account/identity",parameters:{body:{username:{description:"Your unique username. Between 3 and 64 characters. Only letters, numbers, dashes and underscores. May not start with `user_`.",type:"string",required:!0},name:{description:"Your full name. Set to `null` to remove.",type:"string | null",required:!0}}},returns:[{status:200,type:"AccountIdentity"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{username:e,name:t}),listEmails:async()=>await this.#n({type:"operation",description:"List account e-mail addresses",token:"account.details.email.list",method:"GET",path:"/account/email",parameters:{},returns:[{status:200,type:"AccountEmail[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),getEmail:async()=>await this.#n({type:"operation",description:"Get your primary e-mail address",token:"account.details.email",method:"GET",path:"/account/email/primary",parameters:{},returns:[{status:200,type:"DatedPrimaryEmail"},{status:404,type:'Error & {code: "RESOURCE_NOT_FOUND"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{}),setEmail:async e=>await this.#n({type:"operation",description:"Set your primary e-mail address",token:"account.details.email.update",method:"PUT",path:"/account/email/primary",parameters:{body:{email:{description:"E-mail address to set as primary.",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:409,type:'Error & {code: "CONFLICT"}'},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{email:e}),changePassword:async(e,t)=>await this.#n({type:"operation",description:"Change account password",token:"account.details.password.update",method:"PUT",path:"/account/password",parameters:{body:{currentPassword:{description:"Your current password.",type:"string",required:!0},newPassword:{description:"The new password. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.",type:"string",required:!0}}},returns:[{status:204,type:"void"},{status:422,type:'Error & {code: "INVALID_DATA"}'},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{currentPassword:e,newPassword:t}),listPermissions:async()=>await this.#n({type:"operation",description:"List account permissions with user-friendly descriptions. Some permissions (such as wildcard ones) may be excluded in this list if they don't have a description.",token:"account.details",method:"GET",path:"/account/permissions",parameters:{},returns:[{status:200,type:"Permission[]"},{status:401,type:'Error & {code: "UNAUTHORIZED"}'},{status:403,type:'Error & {code: "NO_PERMISSION"}'},{status:429,type:'Error & {code: "RATE_LIMITED"}'},{status:500,type:'Error & {code: "INTERNAL_SERVER_ERROR"}'},{status:503,type:'Error & {code: "MAINTENANCE"}'}]},{},{},{})}}!function(e){let t;e.RawResponse=class{headers;ok;redirected;status;statusText;url;request;constructor(e,t){this.headers=Object.fromEntries([...e.headers.entries()].map((([e,t])=>[e.toLowerCase(),t]))),this.ok=e.ok,this.redirected=e.redirected,this.status=e.status,this.statusText=e.statusText,this.url=new URL(e.url),this.request=t}},function(e){e.ApiResponse=class{#u;constructor(e){this.#u=e}get _response(){return this.#u}}}(t=e.R||(e.R={})),e.makeApiResponse=function(e,r){return Object.assign(new t.ApiResponse(r),e)}}(Cloudnode||(Cloudnode={})); |
@@ -5,4 +5,4 @@ { | ||
"baseUrl": "https://api.cloudnode.pro/v5/", | ||
"apiVersion": "5.11.3", | ||
"apiVersion": "5.11.4", | ||
"browserSdkUrl": "https://cdn.jsdelivr.net/npm/cloudnode-ts@latest/browser/Cloudnode.min.js" | ||
} |
@@ -72,3 +72,4 @@ import Schema from "./Schema"; | ||
const params: DocSchema.Parameter[] = [...pathParams, ...queryParams, ...bodyParams]; | ||
return new DocSchema.Method(config.instanceName + "." + operation.name, operation.description, params, returns, throws, undefined, config.name, true); | ||
const description = typeof operation.token === "string" ? `${operation.description}${[".", "?", "!"].includes(operation.description.slice(-1)) ? "" : "."} Requires token with scope \`${operation.token}\`.` : operation.description; | ||
return new DocSchema.Method(config.instanceName + "." + operation.name, description, params, returns, throws, undefined, config.name, true); | ||
}); | ||
@@ -75,0 +76,0 @@ mainClass.properties.push(...operationMethods); |
@@ -59,3 +59,3 @@ import Schema from "./Schema"; | ||
function addExtraReturnsToOperation(operation: Schema.Operation): Schema.Operation { | ||
if (operation.token !== undefined) | ||
if (typeof operation.token === "string") | ||
operation.returns.push({ | ||
@@ -62,0 +62,0 @@ status: 401, |
{ | ||
"name": "cloudnode-ts", | ||
"version": "1.10.2", | ||
"version": "1.10.3", | ||
"description": "A client SDK for the Cloudnode API, written in TypeScript. [Documentation](https://github.com/cloudnode-pro/ts-client#documentation)", | ||
@@ -33,3 +33,3 @@ "main": "src/Cloudnode.js", | ||
"listr-inquirer": "^0.1.0", | ||
"listr2": "^5.0.5", | ||
"listr2": "^6.0.4", | ||
"mustache": "^4.2.0", | ||
@@ -36,0 +36,0 @@ "node-fetch": "^3.2.10" |
# Cloudnode API SDK | ||
 | ||
 | ||
 | ||
 | ||
 | ||
@@ -202,3 +202,3 @@  | ||
Change account password | ||
Change account password. Requires token with scope `account.details.password.update`. | ||
@@ -219,3 +219,3 @@ - `currentPassword` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> Your current password. | ||
Get account details | ||
Get account details. Requires token with scope `account.details`. | ||
@@ -234,3 +234,3 @@ | ||
Get your primary e-mail address | ||
Get your primary e-mail address. Requires token with scope `account.details.email`. | ||
@@ -250,3 +250,3 @@ | ||
Get account identity | ||
Get account identity. Requires token with scope `account.details.identity`. | ||
@@ -266,3 +266,3 @@ | ||
List account e-mail addresses | ||
List account e-mail addresses. Requires token with scope `account.details.email.list`. | ||
@@ -281,3 +281,3 @@ | ||
List account permissions with user-friendly descriptions. Some permissions (such as wildcard ones) may be excluded in this list if they don't have a description. | ||
List account permissions with user-friendly descriptions. Some permissions (such as wildcard ones) may be excluded in this list if they don't have a description. Requires token with scope `account.details`. | ||
@@ -296,3 +296,3 @@ | ||
Replace account identity | ||
Replace account identity. Requires token with scope `account.details.identity.update`. | ||
@@ -315,3 +315,3 @@ - `username` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> Your unique username. Between 3 and 64 characters. Only letters, numbers, dashes and underscores. May not start with `user_`. | ||
Set your primary e-mail address | ||
Set your primary e-mail address. Requires token with scope `account.details.email.update`. | ||
@@ -332,3 +332,3 @@ - `email` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> E-mail address to set as primary. | ||
Update account identity | ||
Update account identity. Requires token with scope `account.details.identity.update`. | ||
@@ -429,3 +429,3 @@ - `username` <code>[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> Your unique username. Between 3 and 64 characters. Only letters, numbers, dashes and underscores. May not start with `user_`. | ||
List subscriptions of the authenticated user | ||
List subscriptions of the authenticated user. Requires token with scope `newsletter.subscriptions.list.own`. | ||
@@ -459,3 +459,3 @@ - `limit` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The number of subscriptions to return per page. No more than 50. Default: `10` | ||
Create token | ||
Create token. Requires token with scope `tokens.create.own`. | ||
@@ -477,3 +477,3 @@ - `permissions` <code>[string[]](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)</code> List of permissions to grant to the token. You must already have each of these permissions with your current token. | ||
Get token details | ||
Get token details. Requires token with scope `tokens.get.own`. | ||
@@ -494,3 +494,3 @@ - `id` <code>string | "current"</code> The ID of the token to get. Specify `current` to get information about the token that was used to authenticate the request. | ||
Get a recent request by ID | ||
Get a recent request by ID. Requires token with scope `tokens.get.own.requests`. | ||
@@ -512,3 +512,3 @@ - `id` <code>string | "current"</code> The ID of the token. Specify `current` to get information about the token that was used to authenticate the request. | ||
List tokens of user | ||
List tokens of user. Requires token with scope `tokens.list.own`. | ||
@@ -529,3 +529,3 @@ - `limit` <code>[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)</code> The number of tokens to return per page. No more than 50. Default: `10` | ||
Get list of recent requests made with the token | ||
Get list of recent requests made with the token. Requires token with scope `tokens.get.own.requests`. | ||
@@ -548,3 +548,3 @@ - `id` <code>string | "current"</code> The ID of the token. Specify `current` to get information about the token that was used to authenticate the request. | ||
Revoke token | ||
Revoke token. Requires token with scope `tokens.revoke.own`. | ||
@@ -566,3 +566,3 @@ - `id` <code>string | "current"</code> The ID of the token to revoke. Specify `current` to revoke the token that was used to authenticate the request. | ||
Refresh current token. The token that was used to authenticate the request will be deleted. A new token with a new ID but the same permissions will be created and returned. The lifespan of the new token will be the same as the old one, starting from the time of the request. This operation effectively allows a token to be used indefinitely. | ||
Refresh current token. The token that was used to authenticate the request will be deleted. A new token with a new ID but the same permissions will be created and returned. The lifespan of the new token will be the same as the old one, starting from the time of the request. This operation effectively allows a token to be used indefinitely. Requires token with scope `token.refresh`. | ||
@@ -569,0 +569,0 @@ |
@@ -901,2 +901,3 @@ { | ||
"path": "/auth/register", | ||
"token": null, | ||
"parameters": { | ||
@@ -942,2 +943,3 @@ "body": { | ||
"path": "/auth/login", | ||
"token": null, | ||
"parameters": { | ||
@@ -944,0 +946,0 @@ "body": { |
@@ -35,7 +35,7 @@ import fetch from "node-fetch"; | ||
*/ | ||
#apiVersion = `5.11.3`; | ||
#apiVersion = `5.11.4`; | ||
/** | ||
* Client user agent | ||
*/ | ||
#userAgent = `cloudnode/1.10.2`; | ||
#userAgent = `cloudnode/1.10.3`; | ||
/** | ||
@@ -426,3 +426,3 @@ * Construct a new Cloudnode API client | ||
register: async (username, email, password) => { | ||
return await this.#sendRequest({ "type": "operation", "description": "Create an account and session. After signing up, a welcome e-mail is sent to confirm your e-mail address.\n\n> **Note**: Registering an account can only be performed from residential IP. Proxying this endpoint will likely not work. Creating multiple/alternate accounts is not allowed as per the Terms of Service.", "method": "POST", "path": "/auth/register", "parameters": { "body": { "username": { "description": "The username to use for the account. Must be between 3 and 32 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.", "type": "string", "required": true }, "email": { "description": "The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.", "type": "string", "required": true }, "password": { "description": "The password to use for the account. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.", "type": "string", "required": true } } }, "returns": [{ "status": 201, "type": "{session: string}", "description": "Session token. Also returned in `Set-Cookie` header." }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 403, "type": "Error & {code: \"IP_REJECTED\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { username, email, password }); | ||
return await this.#sendRequest({ "type": "operation", "description": "Create an account and session. After signing up, a welcome e-mail is sent to confirm your e-mail address.\n\n> **Note**: Registering an account can only be performed from residential IP. Proxying this endpoint will likely not work. Creating multiple/alternate accounts is not allowed as per the Terms of Service.", "method": "POST", "path": "/auth/register", "token": null, "parameters": { "body": { "username": { "description": "The username to use for the account. Must be between 3 and 32 characters long. Cannot start with `user_`. May contain only letters, numbers, dashes and underscores. Must be unique.", "type": "string", "required": true }, "email": { "description": "The e-mail address to register. A valid unique non-disposable e-mail that can receive mail is required.", "type": "string", "required": true }, "password": { "description": "The password to use for the account. Must be at least 15 characters, or 8 characters if it contains a mix of letters, numbers and symbols.", "type": "string", "required": true } } }, "returns": [{ "status": 201, "type": "{session: string}", "description": "Session token. Also returned in `Set-Cookie` header." }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 403, "type": "Error & {code: \"IP_REJECTED\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { username, email, password }); | ||
}, | ||
@@ -444,3 +444,3 @@ /** | ||
login: async (user, password) => { | ||
return await this.#sendRequest({ "type": "operation", "description": "Create a session using user ID/username/e-mail and password.\n\n> **Note**: Logging in can only be performed from residential IP. Proxying this endpoint will likely not work. It is normally not recommended to use this endpoint to gain API access. Instead, create a token from your account to use with the API.", "method": "POST", "path": "/auth/login", "parameters": { "body": { "user": { "description": "User ID (starts with `user_`), username or e-mail address.", "type": "string", "required": true }, "password": { "description": "The password of the account.", "type": "string", "required": true } } }, "returns": [{ "status": 201, "type": "{session: string}", "description": "Session token. Also returned in `Set-Cookie` header." }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 403, "type": "Error & {code: \"IP_REJECTED\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { user, password }); | ||
return await this.#sendRequest({ "type": "operation", "description": "Create a session using user ID/username/e-mail and password.\n\n> **Note**: Logging in can only be performed from residential IP. Proxying this endpoint will likely not work. It is normally not recommended to use this endpoint to gain API access. Instead, create a token from your account to use with the API.", "method": "POST", "path": "/auth/login", "token": null, "parameters": { "body": { "user": { "description": "User ID (starts with `user_`), username or e-mail address.", "type": "string", "required": true }, "password": { "description": "The password of the account.", "type": "string", "required": true } } }, "returns": [{ "status": 201, "type": "{session: string}", "description": "Session token. Also returned in `Set-Cookie` header." }, { "status": 422, "type": "Error & {code: \"INVALID_DATA\"}" }, { "status": 403, "type": "Error & {code: \"IP_REJECTED\"}" }, { "status": 429, "type": "Error & {code: \"RATE_LIMITED\"}" }, { "status": 500, "type": "Error & {code: \"INTERNAL_SERVER_ERROR\"}" }, { "status": 503, "type": "Error & {code: \"MAINTENANCE\"}" }] }, {}, {}, { user, password }); | ||
}, | ||
@@ -447,0 +447,0 @@ }; |
Sorry, the diff of this file is too big to display
427663
0.3%5508
0.07%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated