-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from apivideo/fix-nodejs-imports
Fix nodejs imports
- Loading branch information
Showing
14 changed files
with
123 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{{>licenseInfo}} | ||
|
||
import HttpClient from "./HttpClient.js"; | ||
{{# apiInfo.apis }}{{^x-client-hidden}} | ||
import {{classFilename}} from './api/{{classFilename}}.js';{{/x-client-hidden}}{{/ apiInfo.apis }} | ||
|
||
{{#models}}{{#model}} | ||
import {{classname}} from './model/{{classname}}.js';{{/model}}{{/models}} | ||
|
||
const PRODUCTION_BASE_URI = "https://ws.api.video"; | ||
const DEFAULT_CHUNK_SIZE = {{ defaultChunkSize }}; | ||
const MIN_CHUNK_SIZE = {{ minChunkSize }}; | ||
const MAX_CHUNK_SIZE = {{ maxChunkSize }}; | ||
|
||
class ApiVideoClient { | ||
private httpClient: HttpClient;{{# apiInfo.apis }}{{^x-client-hidden}} | ||
private _{{classVarName}}: {{classFilename}};{{/x-client-hidden}}{{/ apiInfo.apis }} | ||
|
||
constructor(params: {apiKey?: string, baseUri?: string, chunkSize?: number, applicationName?: string, applicationVersion?: string; sdkName?: string; sdkVersion?: string;}) { | ||
if(params.chunkSize && (params.chunkSize < MIN_CHUNK_SIZE || params.chunkSize > MAX_CHUNK_SIZE)) { | ||
throw new Error("Invalid chunk size value. Must be greater than " + MIN_CHUNK_SIZE + " bytes and lower than " + MAX_CHUNK_SIZE + " bytes."); | ||
} | ||
|
||
this.validateOrigin( | ||
'application', | ||
params.applicationName, | ||
params.applicationVersion | ||
); | ||
|
||
this.validateOrigin('sdk', params.sdkName, params.sdkVersion); | ||
|
||
this.httpClient = new HttpClient({ | ||
...params, | ||
baseUri: params.baseUri || PRODUCTION_BASE_URI, | ||
chunkSize: params.chunkSize || DEFAULT_CHUNK_SIZE, | ||
}) | ||
{{# apiInfo.apis }}{{^x-client-hidden}} | ||
this._{{classVarName}} = new {{classFilename}}(this.httpClient);{{/x-client-hidden}}{{/ apiInfo.apis }} | ||
} | ||
|
||
public async getAccessToken() { | ||
return this.httpClient.getAccessToken(); | ||
} | ||
|
||
{{# apiInfo.apis }}{{^x-client-hidden}} | ||
/** | ||
* Get an {{classFilename}} instance | ||
* @return {{classFilename}} | ||
*/ | ||
public get {{classVarName}}(): {{classFilename}} { | ||
return this._{{classVarName}}; | ||
} | ||
{{/x-client-hidden}}{{/ apiInfo.apis }} | ||
|
||
|
||
private validateOrigin(type: string, name?: string, version?: string) { | ||
if (name && !version) { | ||
throw new Error( | ||
`${type} version is mandatory when ${type} name is set.'` | ||
); | ||
} else if (!name && version) { | ||
throw new Error( | ||
`${type} name is mandatory when ${type} version is set.'` | ||
); | ||
} else if (name && version) { | ||
if (!/^[\w-]{1,50}$/.test(name)) { | ||
throw new Error( | ||
`Invalid ${type} name value. Allowed characters: A-Z, a-z, 0-9, '-', '_'. Max length: 50.` | ||
); | ||
} | ||
|
||
if (!/^\d{1,3}(\.\d{1,3}(\.\d{1,3})?)?$/.test(version)) { | ||
throw new Error( | ||
`Invalid ${type} version value. The version should match the xxx[.yyy][.zzz] pattern.` | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export = ApiVideoClient; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,8 @@ | |
}, | ||
"include": [ | ||
"./src" | ||
], | ||
"exclude": [ | ||
"./src/index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ | |
"target": "es2015" | ||
}, | ||
"include": [ | ||
"./test/" | ||
"./src", | ||
"./test" | ||
], | ||
"exclude": [ | ||
"./src/index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters