@emilgroup/translation-sdk-node 1.1.0 → 1.1.1-beta.10

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/api.ts CHANGED
@@ -24,8 +24,10 @@ import FormData from 'form-data'
24
24
  import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common';
25
25
  // @ts-ignore
26
26
  import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base';
27
+ import { DefaultApi } from './api';
27
28
  import { TranslationApi } from './api';
28
29
 
29
30
 
31
+ export * from './api/default-api';
30
32
  export * from './api/translation-api';
31
33
 
package/base.ts CHANGED
@@ -41,13 +41,25 @@ export const COLLECTION_FORMATS = {
41
41
 
42
42
  export interface LoginClass {
43
43
  accessToken: string;
44
- permissions: Array<string>;
44
+ permissions: string;
45
+ }
46
+
47
+ export interface SwitchWorkspaceRequest {
48
+ username: string;
49
+ targetWorkspace: string;
50
+ }
51
+
52
+ export interface SwitchWorkspaceResponseClass {
53
+ accessToken: string;
54
+ permissions: string;
45
55
  }
46
56
 
47
57
  export enum Environment {
48
58
  Production = 'https://apiv2.emil.de',
49
59
  Test = 'https://apiv2-test.emil.de',
60
+ Staging = 'https://apiv2-staging.emil.de',
50
61
  Development = 'https://apiv2-dev.emil.de',
62
+ ProductionZurich = 'https://eu-central-2.apiv2.emil.de',
51
63
  }
52
64
 
53
65
  let _retry_count = 0
@@ -92,13 +104,13 @@ export class BaseAPI {
92
104
  this.attachInterceptor(axios);
93
105
  }
94
106
 
95
- async initialize(env: Environment = Environment.Production) {
107
+ async initialize(env: Environment = Environment.Production, targetWorkspace?: string) {
96
108
  this.configuration.basePath = env;
97
109
 
98
110
  await this.loadCredentials();
99
111
 
100
112
  if (this.username) {
101
- await this.authorize(this.username, this.password);
113
+ await this.authorize(this.username, this.password, targetWorkspace);
102
114
  this.password = null; // to avoid keeping password loaded in memory.
103
115
  }
104
116
  }
@@ -148,7 +160,7 @@ export class BaseAPI {
148
160
  this.configuration.basePath = env;
149
161
  }
150
162
 
151
- async authorize(username: string, password: string): Promise<void> {
163
+ async authorize(username: string, password: string, targetWorkspace?: string): Promise<void> {
152
164
  const options: AxiosRequestConfig = {
153
165
  method: 'POST',
154
166
  url: `${this.configuration.basePath}/authservice/v1/login`,
@@ -168,6 +180,37 @@ export class BaseAPI {
168
180
 
169
181
  const refreshToken = this.extractRefreshToken(response)
170
182
  this.configuration.refreshToken = refreshToken;
183
+
184
+ // Switch workspace if provided
185
+ if (targetWorkspace) {
186
+ await this.switchWorkspace(targetWorkspace);
187
+ }
188
+ }
189
+ async switchWorkspace(targetWorkspace: string): Promise<void> {
190
+ const options: AxiosRequestConfig = {
191
+ method: 'POST',
192
+ url: `${this.configuration.basePath}/authservice/v1/workspaces/switch`,
193
+ headers: {
194
+ 'Content-Type': 'application/json',
195
+ 'Authorization': `Bearer ${this.configuration.accessToken}`,
196
+ 'Cookie': this.configuration.refreshToken,
197
+ },
198
+ data: {
199
+ username: this.configuration.username,
200
+ targetWorkspace,
201
+ } as SwitchWorkspaceRequest,
202
+ withCredentials: true,
203
+ };
204
+
205
+ const response = await globalAxios.request<SwitchWorkspaceResponseClass>(options);
206
+
207
+ const { data: { accessToken } } = response;
208
+ this.configuration.accessToken = `Bearer ${accessToken}`;
209
+
210
+ const refreshToken = this.extractRefreshToken(response);
211
+ if (refreshToken) {
212
+ this.configuration.refreshToken = refreshToken;
213
+ }
171
214
  }
172
215
 
173
216
  async refreshTokenInternal(): Promise<string> {
@@ -223,7 +266,7 @@ export class BaseAPI {
223
266
  const tokenString = await this.refreshTokenInternal();
224
267
  const accessToken = `Bearer ${tokenString}`;
225
268
 
226
- originalConfig.headers['Authorization'] = `Bearer ${accessToken}`
269
+ originalConfig.headers['Authorization'] = accessToken;
227
270
 
228
271
  this.configuration.accessToken = accessToken;
229
272
 
@@ -276,7 +319,7 @@ export class BaseAPI {
276
319
  * @extends {Error}
277
320
  */
278
321
  export class RequiredError extends Error {
279
- name: "RequiredError" = "RequiredError";
322
+ override name: "RequiredError" = "RequiredError";
280
323
  constructor(public field: string, msg?: string) {
281
324
  super(msg);
282
325
  }
package/common.ts CHANGED
@@ -66,7 +66,7 @@ export const setBearerAuthToObject = async function (object: any, configuration?
66
66
  const accessToken = typeof configuration.accessToken === 'function'
67
67
  ? await configuration.accessToken()
68
68
  : await configuration.accessToken;
69
- object["Authorization"] = "Bearer " + accessToken;
69
+ object["Authorization"] = configuration.getBearerToken(accessToken);
70
70
  }
71
71
  }
72
72
 
@@ -79,7 +79,7 @@ export const setOAuthToObject = async function (object: any, name: string, scope
79
79
  const localVarAccessTokenValue = typeof configuration.accessToken === 'function'
80
80
  ? await configuration.accessToken(name, scopes)
81
81
  : await configuration.accessToken;
82
- object["Authorization"] = "Bearer " + localVarAccessTokenValue;
82
+ object["Authorization"] = configuration.getBearerToken(localVarAccessTokenValue);
83
83
  }
84
84
  }
85
85
 
package/configuration.ts CHANGED
@@ -106,4 +106,13 @@ export class Configuration {
106
106
  const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
107
107
  return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
108
108
  }
109
+
110
+ /**
111
+ * Returns "Bearer" token.
112
+ * @param token - access token.
113
+ * @return Bearer token.
114
+ */
115
+ public getBearerToken(token?: string): string {
116
+ return ('' + token).startsWith("Bearer") ? token : "Bearer " + token;
117
+ }
109
118
  }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * EMIL TranslationService
3
+ * The EMIL TranslationService API description
4
+ *
5
+ * The version of the OpenAPI document: 1.0
6
+ * Contact: kontakt@emil.de
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
13
+ import { Configuration } from '../configuration';
14
+ import { RequestArgs, BaseAPI } from '../base';
15
+ import { InlineResponse200 } from '../models';
16
+ /**
17
+ * DefaultApi - axios parameter creator
18
+ * @export
19
+ */
20
+ export declare const DefaultApiAxiosParamCreator: (configuration?: Configuration) => {
21
+ /**
22
+ * Returns the health status of the translation service. This endpoint is used to monitor the operational status of the translation service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
23
+ * @summary Health Check
24
+ * @param {*} [options] Override http request option.
25
+ * @throws {RequiredError}
26
+ */
27
+ check: (options?: AxiosRequestConfig) => Promise<RequestArgs>;
28
+ };
29
+ /**
30
+ * DefaultApi - functional programming interface
31
+ * @export
32
+ */
33
+ export declare const DefaultApiFp: (configuration?: Configuration) => {
34
+ /**
35
+ * Returns the health status of the translation service. This endpoint is used to monitor the operational status of the translation service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
36
+ * @summary Health Check
37
+ * @param {*} [options] Override http request option.
38
+ * @throws {RequiredError}
39
+ */
40
+ check(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<InlineResponse200>>;
41
+ };
42
+ /**
43
+ * DefaultApi - factory interface
44
+ * @export
45
+ */
46
+ export declare const DefaultApiFactory: (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) => {
47
+ /**
48
+ * Returns the health status of the translation service. This endpoint is used to monitor the operational status of the translation service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
49
+ * @summary Health Check
50
+ * @param {*} [options] Override http request option.
51
+ * @throws {RequiredError}
52
+ */
53
+ check(options?: any): AxiosPromise<InlineResponse200>;
54
+ };
55
+ /**
56
+ * DefaultApi - object-oriented interface
57
+ * @export
58
+ * @class DefaultApi
59
+ * @extends {BaseAPI}
60
+ */
61
+ export declare class DefaultApi extends BaseAPI {
62
+ /**
63
+ * Returns the health status of the translation service. This endpoint is used to monitor the operational status of the translation service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
64
+ * @summary Health Check
65
+ * @param {*} [options] Override http request option.
66
+ * @throws {RequiredError}
67
+ * @memberof DefaultApi
68
+ */
69
+ check(options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<InlineResponse200, any, {}>>;
70
+ }
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ /**
5
+ * EMIL TranslationService
6
+ * The EMIL TranslationService API description
7
+ *
8
+ * The version of the OpenAPI document: 1.0
9
+ * Contact: kontakt@emil.de
10
+ *
11
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
12
+ * https://openapi-generator.tech
13
+ * Do not edit the class manually.
14
+ */
15
+ var __extends = (this && this.__extends) || (function () {
16
+ var extendStatics = function (d, b) {
17
+ extendStatics = Object.setPrototypeOf ||
18
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
19
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
20
+ return extendStatics(d, b);
21
+ };
22
+ return function (d, b) {
23
+ if (typeof b !== "function" && b !== null)
24
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
25
+ extendStatics(d, b);
26
+ function __() { this.constructor = d; }
27
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
28
+ };
29
+ })();
30
+ var __assign = (this && this.__assign) || function () {
31
+ __assign = Object.assign || function(t) {
32
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
33
+ s = arguments[i];
34
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
35
+ t[p] = s[p];
36
+ }
37
+ return t;
38
+ };
39
+ return __assign.apply(this, arguments);
40
+ };
41
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
42
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
43
+ return new (P || (P = Promise))(function (resolve, reject) {
44
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
45
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
46
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
47
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
48
+ });
49
+ };
50
+ var __generator = (this && this.__generator) || function (thisArg, body) {
51
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
52
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
53
+ function verb(n) { return function (v) { return step([n, v]); }; }
54
+ function step(op) {
55
+ if (f) throw new TypeError("Generator is already executing.");
56
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
57
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
58
+ if (y = 0, t) op = [op[0] & 2, t.value];
59
+ switch (op[0]) {
60
+ case 0: case 1: t = op; break;
61
+ case 4: _.label++; return { value: op[1], done: false };
62
+ case 5: _.label++; y = op[1]; op = [0]; continue;
63
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
64
+ default:
65
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
66
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
67
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
68
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
69
+ if (t[2]) _.ops.pop();
70
+ _.trys.pop(); continue;
71
+ }
72
+ op = body.call(thisArg, _);
73
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
74
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
75
+ }
76
+ };
77
+ var __importDefault = (this && this.__importDefault) || function (mod) {
78
+ return (mod && mod.__esModule) ? mod : { "default": mod };
79
+ };
80
+ Object.defineProperty(exports, "__esModule", { value: true });
81
+ exports.DefaultApi = exports.DefaultApiFactory = exports.DefaultApiFp = exports.DefaultApiAxiosParamCreator = void 0;
82
+ var axios_1 = __importDefault(require("axios"));
83
+ // Some imports not used depending on template conditions
84
+ // @ts-ignore
85
+ var common_1 = require("../common");
86
+ // @ts-ignore
87
+ var base_1 = require("../base");
88
+ // URLSearchParams not necessarily used
89
+ // @ts-ignore
90
+ var url_1 = require("url");
91
+ var FormData = require('form-data');
92
+ /**
93
+ * DefaultApi - axios parameter creator
94
+ * @export
95
+ */
96
+ var DefaultApiAxiosParamCreator = function (configuration) {
97
+ var _this = this;
98
+ return {
99
+ /**
100
+ * Returns the health status of the translation service. This endpoint is used to monitor the operational status of the translation service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
101
+ * @summary Health Check
102
+ * @param {*} [options] Override http request option.
103
+ * @throws {RequiredError}
104
+ */
105
+ check: function (options) {
106
+ if (options === void 0) { options = {}; }
107
+ return __awaiter(_this, void 0, void 0, function () {
108
+ var localVarPath, localVarUrlObj, baseOptions, baseAccessToken, localVarRequestOptions, localVarHeaderParameter, localVarQueryParameter, headersFromBaseOptions;
109
+ return __generator(this, function (_a) {
110
+ localVarPath = "/translationservice/health";
111
+ localVarUrlObj = new url_1.URL(localVarPath, common_1.DUMMY_BASE_URL);
112
+ if (configuration) {
113
+ baseOptions = configuration.baseOptions;
114
+ baseAccessToken = configuration.accessToken;
115
+ }
116
+ localVarRequestOptions = __assign(__assign({ method: 'GET' }, baseOptions), options);
117
+ localVarHeaderParameter = {};
118
+ localVarQueryParameter = {};
119
+ (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
120
+ headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
121
+ localVarRequestOptions.headers = __assign(__assign(__assign({}, localVarHeaderParameter), headersFromBaseOptions), options.headers);
122
+ return [2 /*return*/, {
123
+ url: (0, common_1.toPathString)(localVarUrlObj),
124
+ options: localVarRequestOptions,
125
+ }];
126
+ });
127
+ });
128
+ },
129
+ };
130
+ };
131
+ exports.DefaultApiAxiosParamCreator = DefaultApiAxiosParamCreator;
132
+ /**
133
+ * DefaultApi - functional programming interface
134
+ * @export
135
+ */
136
+ var DefaultApiFp = function (configuration) {
137
+ var localVarAxiosParamCreator = (0, exports.DefaultApiAxiosParamCreator)(configuration);
138
+ return {
139
+ /**
140
+ * Returns the health status of the translation service. This endpoint is used to monitor the operational status of the translation service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
141
+ * @summary Health Check
142
+ * @param {*} [options] Override http request option.
143
+ * @throws {RequiredError}
144
+ */
145
+ check: function (options) {
146
+ return __awaiter(this, void 0, void 0, function () {
147
+ var localVarAxiosArgs;
148
+ return __generator(this, function (_a) {
149
+ switch (_a.label) {
150
+ case 0: return [4 /*yield*/, localVarAxiosParamCreator.check(options)];
151
+ case 1:
152
+ localVarAxiosArgs = _a.sent();
153
+ return [2 /*return*/, (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration)];
154
+ }
155
+ });
156
+ });
157
+ },
158
+ };
159
+ };
160
+ exports.DefaultApiFp = DefaultApiFp;
161
+ /**
162
+ * DefaultApi - factory interface
163
+ * @export
164
+ */
165
+ var DefaultApiFactory = function (configuration, basePath, axios) {
166
+ var localVarFp = (0, exports.DefaultApiFp)(configuration);
167
+ return {
168
+ /**
169
+ * Returns the health status of the translation service. This endpoint is used to monitor the operational status of the translation service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
170
+ * @summary Health Check
171
+ * @param {*} [options] Override http request option.
172
+ * @throws {RequiredError}
173
+ */
174
+ check: function (options) {
175
+ return localVarFp.check(options).then(function (request) { return request(axios, basePath); });
176
+ },
177
+ };
178
+ };
179
+ exports.DefaultApiFactory = DefaultApiFactory;
180
+ /**
181
+ * DefaultApi - object-oriented interface
182
+ * @export
183
+ * @class DefaultApi
184
+ * @extends {BaseAPI}
185
+ */
186
+ var DefaultApi = /** @class */ (function (_super) {
187
+ __extends(DefaultApi, _super);
188
+ function DefaultApi() {
189
+ return _super !== null && _super.apply(this, arguments) || this;
190
+ }
191
+ /**
192
+ * Returns the health status of the translation service. This endpoint is used to monitor the operational status of the translation service. It typically returns a simple status indicator, such as \'UP\' or \'OK\', confirming that the service is operational and available.
193
+ * @summary Health Check
194
+ * @param {*} [options] Override http request option.
195
+ * @throws {RequiredError}
196
+ * @memberof DefaultApi
197
+ */
198
+ DefaultApi.prototype.check = function (options) {
199
+ var _this = this;
200
+ return (0, exports.DefaultApiFp)(this.configuration).check(options).then(function (request) { return request(_this.axios, _this.basePath); });
201
+ };
202
+ return DefaultApi;
203
+ }(base_1.BaseAPI));
204
+ exports.DefaultApi = DefaultApi;