Skip to content

Commit 4a079ef

Browse files
author
williamd5
authored
Merge pull request #51 from cloudnode-pro/next
Bump API version to 5.11.2
2 parents 0c7a932 + d4afe7d commit 4a079ef

File tree

10 files changed

+2205
-45
lines changed

10 files changed

+2205
-45
lines changed

README.md

Lines changed: 320 additions & 11 deletions
Large diffs are not rendered by default.

browser/Cloudnode.js

Lines changed: 205 additions & 6 deletions
Large diffs are not rendered by default.

browser/Cloudnode.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "Cloudnode",
33
"instanceName": "cloudnode",
44
"baseUrl": "https://api.cloudnode.pro/v5/",
5-
"apiVersion": "5.10.1",
5+
"apiVersion": "5.11.2",
66
"browserSdkUrl": "https://cdn.jsdelivr.net/npm/cloudnode-ts@latest/browser/Cloudnode.min.js"
77
}

gen/docs.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,35 @@ export function generateDocSchema (schema: Schema, config: Config, pkg: Package)
7878
new DocSchema.Parameter("token", "string", "API token to use for requests", false),
7979
new DocSchema.Parameter("options", `Partial<${config.name}.Options>`, "API client options", false, `{baseUrl: "${config.baseUrl}", autoRetry: true, maxRetryDelay: 5, maxRetries: 3}`)
8080
], undefined, []));
81-
always.push(new DocSchema.Method(`${config.name}.getPage<T>`, "Get another page of paginated results", [
81+
always.push(new DocSchema.Method(`${config.instanceName}.getPage<T>`, "Get another page of paginated results", [
8282
new DocSchema.Parameter("response", `${config.name}.ApiResponse<${config.name}.PaginatedData<T>>`, "Response to get a different page of", true),
8383
new DocSchema.Parameter("page", "number", "Page to get", true)
8484
], {
8585
type: `Promise<${config.name}.ApiResponse<${config.name}.PaginatedData<T>> | null>`,
8686
description: "The new page or null if the page is out of bounds"
8787
}, [{type: `${config.name}.Error`, description: "Error returned by the API"}]));
88-
always.push(new DocSchema.Method(`${config.name}.getNextPage<T>`, "Get next page of paginated results", [
88+
always.push(new DocSchema.Method(`${config.instanceName}.getNextPage<T>`, "Get next page of paginated results", [
8989
new DocSchema.Parameter("response", `${config.name}.ApiResponse<${config.name}.PaginatedData<T>>`, "Response to get the next page of", true)
9090
], {
9191
type: `Promise<${config.name}.ApiResponse<${config.name}.PaginatedData<T>> | null>`,
9292
description: "The next page or null if this is the last page"
9393
}, [{type: `${config.name}.Error`, description: "Error returned by the API"}]));
94-
always.push(new DocSchema.Method(`${config.name}.getPreviousPage<T>`, "Get previous page of paginated results", [
94+
always.push(new DocSchema.Method(`${config.instanceName}.getPreviousPage<T>`, "Get previous page of paginated results", [
9595
new DocSchema.Parameter("response", `${config.name}.ApiResponse<${config.name}.PaginatedData<T>>`, "Response to get the previous page of", true)
9696
], {
9797
type: `Promise<${config.name}.ApiResponse<${config.name}.PaginatedData<T>> | null>`,
9898
description: "The previous page or null if this is the first page"
9999
}, [{type: `${config.name}.Error`, description: "Error returned by the API"}]));
100-
always.push(new DocSchema.Method(`${config.name}.getAllPages<T>`, "Get all other pages of paginated results and return the complete data\n> **Warning:** Depending on the amount of data, this can take a long time and use a lot of memory.", [
100+
always.push(new DocSchema.Method(`${config.instanceName}.getAllPages<T>`, "Get all other pages of paginated results and return the complete data\n> **Warning:** Depending on the amount of data, this can take a long time and use a lot of memory.", [
101101
new DocSchema.Parameter("response", `${config.name}.ApiResponse<${config.name}.PaginatedData<T>>`, "Response to get all pages of", true)
102102
], {
103103
type: `Promise<${config.name}.PaginatedData<T>>`,
104104
description: "All of the data in 1 page"
105105
}, [{type: `${config.name}.Error`, description: "Error returned by the API"}]));
106+
always.push(new DocSchema.Method(`${config.instanceName}.checkCompatibility`, "Check compatibility with the API", [], {
107+
type: `Promise<"compatible" | "outdated" | "incompatible">`,
108+
description: "`compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)"
109+
}, []));
106110
mainClass.properties.unshift(...always);
107111
mainNamespace.properties.sort((a, b) => a.displayName.localeCompare(b.displayName));
108112

gen/templates/main.mustache

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,27 @@ class {{config.name}} {
3535
maxRetries: 3
3636
};
3737

38+
/**
39+
* API version
40+
*/
41+
readonly #apiVersion = `{{config.apiVersion}}`;
42+
43+
/**
44+
* Client user agent
45+
*/
46+
readonly #userAgent = `{{config.instanceName}}/{{pkg.version}}`;
47+
3848
/**
3949
* Construct a new {{config.name}} API client
4050
* @param token API token to use for requests
4151
* @param [options] Options for the API client
4252
*/
4353
public constructor(token?: string, options: Partial<{{config.name}}.Options> = {{config.name}}.#defaultOptions) {
4454
const fullOptions = {{config.name}}.#defaultOptions;
45-
fullOptions.baseUrl = fullOptions.baseUrl ?? {{config.name}}.#defaultOptions.baseUrl;
46-
fullOptions.autoRetry = fullOptions.autoRetry ?? {{config.name}}.#defaultOptions.autoRetry;
47-
fullOptions.maxRetryDelay = fullOptions.maxRetryDelay ?? {{config.name}}.#defaultOptions.maxRetryDelay;
48-
fullOptions.maxRetries = fullOptions.maxRetries ?? {{config.name}}.#defaultOptions.maxRetries;
55+
fullOptions.baseUrl = options.baseUrl ?? {{config.name}}.#defaultOptions.baseUrl;
56+
fullOptions.autoRetry = options.autoRetry ?? {{config.name}}.#defaultOptions.autoRetry;
57+
fullOptions.maxRetryDelay = options.maxRetryDelay ?? {{config.name}}.#defaultOptions.maxRetryDelay;
58+
fullOptions.maxRetries = options.maxRetries ?? {{config.name}}.#defaultOptions.maxRetries;
4959

5060
this.#token = token;
5161
this.#options = fullOptions;
@@ -80,6 +90,9 @@ class {{config.name}} {
8090
options.headers["Content-Type"] = "text/plain";
8191
}
8292
}
93+
94+
options.headers["User-Agent"] = this.#userAgent;
95+
8396
if (this.#token && operation.token !== undefined)
8497
options.headers["Authorization"] = `Bearer ${this.#token}`;
8598
if (operation.token !== undefined)
@@ -136,6 +149,37 @@ class {{config.name}} {
136149
});
137150
}
138151

152+
/**
153+
* Compare versions to determine compatibility
154+
* @param a First version
155+
* @param b Second version
156+
*/
157+
#compareVersions(a: string, b: string): "compatible" | "outdated" | "incompatible" {
158+
const partsA = a.split(".");
159+
const partsB = b.split(".");
160+
161+
const verA = [partsA[0] || "0", partsA[1] || "0"];
162+
const verB = [partsB[0] || "0", partsB[1] || "0"];
163+
164+
if (verA[0] !== verB[0]) return "incompatible";
165+
if (verA[1] !== verB[1]) return "outdated";
166+
return "compatible";
167+
}
168+
169+
/**
170+
* Check compatibility with the API
171+
* @returns `compatible` - versions are fully compatible (only patch version may differ), `outdated` - compatible, but new features unavailable (minor version differs), `incompatible` - breaking changes (major version differs)
172+
*/
173+
public async checkCompatibility() {
174+
const data: any = await (await fetch(new URL("../", this.#options.baseUrl).toString(), {
175+
method: "GET",
176+
headers: {
177+
"User-Agent": this.#userAgent
178+
}
179+
})).json();
180+
return this.#compareVersions(data.version, this.#apiVersion);
181+
}
182+
139183
/**
140184
* Get another page of paginated results
141185
* @param response Response to get a different page of

0 commit comments

Comments
 (0)