@vocalstack/js-sdk 1.0.12 → 1.0.13
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/RestApi.js +1 -0
- package/dist/VocalStackApi.d.ts +1 -0
- package/dist/VocalStackApi.js +1 -0
- package/dist/WebsocketApi.js +0 -6
- package/dist/esm/ApiVersion.d.ts +2 -0
- package/dist/esm/ApiVersion.js +28 -0
- package/dist/esm/RestApi.js +3 -1
- package/dist/esm/version.d.ts +1 -0
- package/dist/esm/version.js +1 -0
- package/package.json +3 -2
package/dist/RestApi.js
CHANGED
package/dist/VocalStackApi.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const VOCALSTACK_API_SERVER = "https://api.vocalstack.com";
|
|
|
6
6
|
export declare class VocalStackApi {
|
|
7
7
|
protected headers: Record<string, string>;
|
|
8
8
|
protected apiServer: string;
|
|
9
|
+
protected apiVersion: string;
|
|
9
10
|
constructor(config: Configuration);
|
|
10
11
|
protected _rest(): RestApi;
|
|
11
12
|
protected _ws(): WebSocketsApi;
|
package/dist/VocalStackApi.js
CHANGED
|
@@ -7,6 +7,7 @@ const generics_zod_1 = require("./generics.zod");
|
|
|
7
7
|
exports.VOCALSTACK_API_SERVER = 'https://api.vocalstack.com';
|
|
8
8
|
class VocalStackApi {
|
|
9
9
|
constructor(config) {
|
|
10
|
+
this.apiVersion = '1.0.7';
|
|
10
11
|
const { apiServer, headers } = this.buildConfiguration(config);
|
|
11
12
|
this.apiServer = apiServer;
|
|
12
13
|
this.headers = headers;
|
package/dist/WebsocketApi.js
CHANGED
|
@@ -27,12 +27,6 @@ class WebSocketsApi {
|
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
29
|
// Node.js environment: use "ws" package where WebSocket is not available
|
|
30
|
-
console.log('!!!!!!!');
|
|
31
|
-
console.log('!!!!!!!');
|
|
32
|
-
console.log('!!!!!!!');
|
|
33
|
-
console.log('!!!!!!!');
|
|
34
|
-
console.log('!!!!!!!');
|
|
35
|
-
console.log('!!!!!!!');
|
|
36
30
|
this.WebSocketClass = require('ws').WebSocket;
|
|
37
31
|
}
|
|
38
32
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export const EXPECTED_VOCALSTACK_API_VERSION = '1.0.7';
|
|
2
|
+
export const verifyApiVersion = (actualVersion, discontinued = false) => {
|
|
3
|
+
if (!actualVersion) {
|
|
4
|
+
throw new Error('VocalStack API version is missing.');
|
|
5
|
+
}
|
|
6
|
+
if (discontinued) {
|
|
7
|
+
throw Error(`The VocalStack API has undergone a new release (v.${actualVersion}) and no longer supports this SDK. Please update the SDK to the latest version by running 'npm update @vocalstack/js-sdk'.`);
|
|
8
|
+
}
|
|
9
|
+
const [major, minor, patch] = parseVersion(actualVersion);
|
|
10
|
+
const [expectedMajor, expectedMinor, expectedPatch] = EXPECTED_VOCALSTACK_API_VERSION.split('.').map((v) => parseInt(v, 10));
|
|
11
|
+
if (major < expectedMajor ||
|
|
12
|
+
(major === expectedMajor && minor < expectedMinor) ||
|
|
13
|
+
(major === expectedMajor && minor === expectedMinor && patch < expectedPatch)) {
|
|
14
|
+
throw new Error(`VocalStack API version ${actualVersion} is lower than that expected by this SDK. Expected version >= ${EXPECTED_VOCALSTACK_API_VERSION}`);
|
|
15
|
+
}
|
|
16
|
+
if (major > expectedMajor || (major === expectedMajor && minor > expectedMinor)) {
|
|
17
|
+
const type = major > expectedMajor ? 'major' : 'minor';
|
|
18
|
+
console[type === 'major' ? 'error' : 'warn'](`The VocalStack API has undergone a new ${type} release (v.${actualVersion}). Your SDK version may not support all new API features. Consider updating by running 'npm update @vocalstack/js-sdk'.`);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
function parseVersion(version) {
|
|
22
|
+
const regex = /^\d+\.\d+\.\d+$/;
|
|
23
|
+
if (!regex.test(version)) {
|
|
24
|
+
throw new Error(`Invalid version format: ${version}. Expected format "major.minor.patch" with numeric segments.`);
|
|
25
|
+
}
|
|
26
|
+
const segments = version.split('.').map((v) => parseInt(v, 10));
|
|
27
|
+
return [segments[0], segments[1], segments[2]];
|
|
28
|
+
}
|
package/dist/esm/RestApi.js
CHANGED
|
@@ -18,6 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
+
import { verifyApiVersion, EXPECTED_VOCALSTACK_API_VERSION } from './ApiVersion';
|
|
21
22
|
export class RestApi {
|
|
22
23
|
constructor(apiServer, headers) {
|
|
23
24
|
this.apiServer = apiServer;
|
|
@@ -54,13 +55,14 @@ export class RestApi {
|
|
|
54
55
|
const fixedPath = path.startsWith('/') ? path.slice(1) : path;
|
|
55
56
|
const _a = options || {}, { json } = _a, fetchOptions = __rest(_a, ["json"]);
|
|
56
57
|
const body = json ? JSON.stringify(json) : undefined;
|
|
57
|
-
const headers = Object.assign({}, this.headers);
|
|
58
|
+
const headers = Object.assign(Object.assign({}, this.headers), { 'X-Expected-API-Version': EXPECTED_VOCALSTACK_API_VERSION });
|
|
58
59
|
if (body) {
|
|
59
60
|
headers['Content-Type'] = 'application/json';
|
|
60
61
|
}
|
|
61
62
|
const response = yield fetch(`${this.apiServer}/${fixedPath}`, Object.assign({ method,
|
|
62
63
|
headers,
|
|
63
64
|
body }, fetchOptions));
|
|
65
|
+
verifyApiVersion(response.headers.get('X-API-Version'), response.headers.get('X-API-Version-Discontinued') === '1');
|
|
64
66
|
return this.respond(response);
|
|
65
67
|
}
|
|
66
68
|
catch (e) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "1.0.12";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '1.0.12';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vocalstack/js-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "A JavaScript API Client and SDK for VocalStack",
|
|
5
5
|
"author": "VocalStack",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"module": "./dist/esm/index.js",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"lint": "eslint",
|
|
19
|
-
"build": "rm -rf ./dist && npm i && tsc && tsc -p tsconfig.esm.json",
|
|
19
|
+
"build": "rm -rf ./dist && npm i && npm run version && tsc && tsc -p tsconfig.esm.json",
|
|
20
|
+
"version": "node ./scripts/generate-version.js",
|
|
20
21
|
"docs": "rm -rf ./documentation && npm run --prefix ./../website script:docs -- $(node -e \"console.log(process.cwd())\")",
|
|
21
22
|
"prepublish": "npm run docs",
|
|
22
23
|
"prepare": "tsc -p tsconfig.esm.json"
|