Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/lib-js-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {default: request} = axios
export interface SyncanoClientOptions {
host?: string
token?: string
apiVersion?: string
transformResponse?: (response: axios.AxiosResponse) => void
}

Expand All @@ -24,6 +25,7 @@ export default class SyncanoClient {
*/
public instanceName?: string
private host?: string
private apiVersion?: string
private transformResponse?: (response: axios.AxiosResponse) => any
private DEFAULT_HEADERS = {
'Content-Type': 'application/json'
Expand All @@ -33,7 +35,8 @@ export default class SyncanoClient {
instanceName: string,
options: SyncanoClientOptions = {}
) {
this.host = options.host || 'syncano.space'
this.host = options.host || 'api.syncano.io'
this.apiVersion = options.apiVersion || 'v3'
this.token = options.token
this.transformResponse = options.transformResponse
this.instanceName = instanceName
Expand All @@ -51,7 +54,8 @@ export default class SyncanoClient {
} = {
protocol: 'https'
}): string {
let baseURL = `${options.protocol}://${this.instanceName}.${this.host}/${path}/`
let baseURL = `${options.protocol}://${this.host}`
baseURL = `${baseURL}/${this.apiVersion}/instances/${this.instanceName}/endpoints/sockets/${path}/`
if (path.startsWith('http') || path.startsWith('/')) {
baseURL = path
}
Expand Down Expand Up @@ -84,7 +88,7 @@ export default class SyncanoClient {
public get(endpoint: string, params?: object, options?: axios.AxiosRequestConfig) {
this.checkInstanceName()

return request.get(this.url(endpoint), this.options({params, ...options})).then(this.transform)
return request.get(this.url(endpoint), this.options({params: params || {}, ...options})).then(this.transform)
}

/**
Expand All @@ -98,7 +102,7 @@ export default class SyncanoClient {
public patch(endpoint: string, data?: any, options?: axios.AxiosRequestConfig) {
this.checkInstanceName()

return request.patch(this.url(endpoint), data, this.options(options)).then(this.transform)
return request.patch(this.url(endpoint), data || {}, this.options(options)).then(this.transform)
}

/**
Expand All @@ -112,7 +116,7 @@ export default class SyncanoClient {
public post(endpoint: string, data?: any, options?: axios.AxiosRequestConfig) {
this.checkInstanceName()

return request.post(this.url(endpoint), data, this.options(options)).then(this.transform)
return request.post(this.url(endpoint), data || {}, this.options(options)).then(this.transform)
}

/**
Expand All @@ -126,7 +130,7 @@ export default class SyncanoClient {
public put(endpoint: string, data?: any, options?: axios.AxiosRequestConfig) {
this.checkInstanceName()

return request.put(this.url(endpoint), data, this.options(options)).then(this.transform)
return request.put(this.url(endpoint), data || {}, this.options(options)).then(this.transform)
}

/**
Expand All @@ -140,7 +144,7 @@ export default class SyncanoClient {
public delete(endpoint: string, params?: object, options?: axios.AxiosRequestConfig) {
this.checkInstanceName()

return request.delete(this.url(endpoint), this.options({params, ...options})).then(this.transform)
return request.delete(this.url(endpoint), this.options({params: params || {}, ...options})).then(this.transform)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-js-core/src/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class Endpoint extends QueryBuilder {
_url (endpoint) {
const {instanceName} = this.instance

return `${this._getInstanceURL(instanceName)}/endpoints/sockets/${endpoint}/`
return `${this._getInstanceURL(instanceName, 'v3')}/endpoints/sockets/${endpoint}/`
}

_parseBody (body) {
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-js-core/test/unit/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ chai.should()

describe('Endpoint', () => {
const instanceName = 'testInstance'
const testEndpoint = `/v2/instances/${instanceName}/endpoints/sockets/socket/endpoint/`
const testEndpoint = `/v3/instances/${instanceName}/endpoints/sockets/socket/endpoint/`
let api
let endpoint

Expand Down
2 changes: 1 addition & 1 deletion packages/tests/e2e/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Client', function () {
.cwd(path.join(testsLocation, testInstance))

before(() => {
client = new Syncano(testInstance, {host: 'syncano.link'})
client = new Syncano(testInstance, {host: 'api.syncano.rocks'})
assert.isObject(client)

return createProject(testInstance, projectTestTemplate)
Expand Down