@devopness/sdk-js 2.133.0 → 2.135.0

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.
@@ -63,4 +63,12 @@ export declare class DevopnessApiClient {
63
63
  constructor(options?: ConfigurationOptions);
64
64
  get accessToken(): string;
65
65
  set accessToken(accessToken: string);
66
+ /**
67
+ *
68
+ * @summary Sets the callback function to be executed when the access token expires.
69
+ * @static
70
+ * @param {function(string)} callback - The callback function to be executed.
71
+ * This function should accept a single string parameter representing the expired access token.
72
+ */
73
+ set onTokenExpired(callback: (accessToken: string) => void);
66
74
  }
@@ -68,6 +68,9 @@ class DevopnessApiClient {
68
68
  this.users = new UserService_1.UserService();
69
69
  this.variables = new VariableService_1.VariableService();
70
70
  this.virtualHosts = new VirtualHostService_1.VirtualHostService();
71
+ this.onTokenExpired = () => {
72
+ // do nothing.
73
+ };
71
74
  }
72
75
  get accessToken() {
73
76
  return ApiBaseService_1.ApiBaseService.accessToken;
@@ -84,5 +87,15 @@ class DevopnessApiClient {
84
87
  }
85
88
  ApiBaseService_1.ApiBaseService.accessToken = accessToken;
86
89
  }
90
+ /**
91
+ *
92
+ * @summary Sets the callback function to be executed when the access token expires.
93
+ * @static
94
+ * @param {function(string)} callback - The callback function to be executed.
95
+ * This function should accept a single string parameter representing the expired access token.
96
+ */
97
+ set onTokenExpired(callback) {
98
+ ApiBaseService_1.ApiBaseService.onTokenExpired = callback;
99
+ }
87
100
  }
88
101
  exports.DevopnessApiClient = DevopnessApiClient;
@@ -75,28 +75,10 @@ export interface ApplicationEnvironmentCreate {
75
75
  * @memberof ApplicationEnvironmentCreate
76
76
  */
77
77
  deployments_keep?: number;
78
- /**
79
- * The entrypoint tells devopness how an application should be started and has basically two forms: 1) `File`: if it\'s a simple file name/path a web app will be served using the entrypoint value as its index file. Example: `index.html` 2) `Command`: if a command line instruction is provided as the entrypoint value, it will be handled as the start up command that initializes the application. It will be assumed that the user is an advanced user that knows what she/he is doing, therefore the command specified here will be run - as is - every time the application needs to be started. Must not be greater than 120 characters.
80
- * @type {string}
81
- * @memberof ApplicationEnvironmentCreate
82
- */
83
- entrypoint: string;
84
78
  /**
85
79
  * Indicates command that Devopness must execute to install application dependencies.
86
80
  * @type {string}
87
81
  * @memberof ApplicationEnvironmentCreate
88
82
  */
89
83
  install_dependencies_command?: string;
90
- /**
91
- * Indicates if push to deploy webhooks are enabled for this application. If enabled an app deployment will be automatically triggered when new changes are committed to the `default_branch`.
92
- * @type {boolean}
93
- * @memberof ApplicationEnvironmentCreate
94
- */
95
- push_to_deploy?: boolean;
96
- /**
97
- * Indicates if the application requires a daemon to keep it alive.
98
- * @type {boolean}
99
- * @memberof ApplicationEnvironmentCreate
100
- */
101
- requires_daemon: boolean;
102
84
  }
@@ -71,12 +71,6 @@ export interface ApplicationRelation {
71
71
  * @memberof ApplicationRelation
72
72
  */
73
73
  default_branch: string;
74
- /**
75
- * Indicates if push to deploy webhooks are enabled for this application. If enabled an app deployment will be automatically triggered when new changes are committed to the `default_branch`
76
- * @type {boolean}
77
- * @memberof ApplicationRelation
78
- */
79
- push_to_deploy: boolean;
80
74
  /**
81
75
  * The programming language runtime environment to be used to serve the application. E.g.: if a front-end web app is developed using Node.js, but should be served statically (a SPA application, for instance) then this field value should be `html`.
82
76
  * @type {string}
@@ -101,12 +95,6 @@ export interface ApplicationRelation {
101
95
  * @memberof ApplicationRelation
102
96
  */
103
97
  root_directory: string;
104
- /**
105
- * The application\'s entrypoint
106
- * @type {string}
107
- * @memberof ApplicationRelation
108
- */
109
- entrypoint: string;
110
98
  /**
111
99
  * The number of deployment history, logs and artifacts to keep stored in both devopness servers and user\'s servers. OR The number of deployment artifacts to be retained in the user\'s servers, making it easier and faster to rollback to previous versions
112
100
  * @type {number}
@@ -125,12 +113,6 @@ export interface ApplicationRelation {
125
113
  * @memberof ApplicationRelation
126
114
  */
127
115
  build_command: string | null;
128
- /**
129
- * Indicates if the application requires a daemon to keep it alive
130
- * @type {boolean}
131
- * @memberof ApplicationRelation
132
- */
133
- requires_daemon: boolean;
134
116
  /**
135
117
  *
136
118
  * @type {ApplicationLastDeployments}
@@ -81,28 +81,10 @@ export interface ApplicationUpdate {
81
81
  * @memberof ApplicationUpdate
82
82
  */
83
83
  deployments_keep?: number;
84
- /**
85
- * The entrypoint tells devopness how an application should be started and has basically two forms: 1) `File`: if it\'s a simple file name/path a web app will be served using the entrypoint value as its index file. Example: `index.html` 2) `Command`: if a command line instruction is provided as the entrypoint value, it will be handled as the start up command that initializes the application. It will be assumed that the user is an advanced user that knows what she/he is doing, therefore the command specified here will be run - as is - every time the application needs to be started. Must not be greater than 120 characters.
86
- * @type {string}
87
- * @memberof ApplicationUpdate
88
- */
89
- entrypoint: string;
90
84
  /**
91
85
  * Indicates command that Devopness must execute to install application dependencies.
92
86
  * @type {string}
93
87
  * @memberof ApplicationUpdate
94
88
  */
95
89
  install_dependencies_command?: string;
96
- /**
97
- * Indicates if push to deploy webhooks are enabled for this application. If enabled an app deployment will be automatically triggered when new changes are committed to the `default_branch`.
98
- * @type {boolean}
99
- * @memberof ApplicationUpdate
100
- */
101
- push_to_deploy?: boolean;
102
- /**
103
- * Indicates if the application requires a daemon to keep it alive.
104
- * @type {boolean}
105
- * @memberof ApplicationUpdate
106
- */
107
- requires_daemon: boolean;
108
90
  }
@@ -75,12 +75,6 @@ export interface Application {
75
75
  * @memberof Application
76
76
  */
77
77
  default_branch: string;
78
- /**
79
- * Indicates if push to deploy webhooks are enabled for this application. If enabled an app deployment will be automatically triggered when new changes are committed to the `default_branch`
80
- * @type {boolean}
81
- * @memberof Application
82
- */
83
- push_to_deploy: boolean;
84
78
  /**
85
79
  * The programming language runtime environment to be used to serve the application. E.g.: if a front-end web app is developed using Node.js, but should be served statically (a SPA application, for instance) then this field value should be `html`.
86
80
  * @type {string}
@@ -105,12 +99,6 @@ export interface Application {
105
99
  * @memberof Application
106
100
  */
107
101
  root_directory: string;
108
- /**
109
- * The application\'s entrypoint
110
- * @type {string}
111
- * @memberof Application
112
- */
113
- entrypoint: string;
114
102
  /**
115
103
  * The number of deployment history, logs and artifacts to keep stored in both devopness servers and user\'s servers. OR The number of deployment artifacts to be retained in the user\'s servers, making it easier and faster to rollback to previous versions
116
104
  * @type {number}
@@ -129,12 +117,6 @@ export interface Application {
129
117
  * @memberof Application
130
118
  */
131
119
  build_command: string | null;
132
- /**
133
- * Indicates if the application requires a daemon to keep it alive
134
- * @type {boolean}
135
- * @memberof Application
136
- */
137
- requires_daemon: boolean;
138
120
  /**
139
121
  *
140
122
  * @type {UserRelation}
@@ -11,6 +11,7 @@ export declare class Configuration implements ConfigurationOptions {
11
11
  export declare class ApiBaseService {
12
12
  private api;
13
13
  private static _accessToken;
14
+ private static _onTokenExpired;
14
15
  static configuration: Configuration;
15
16
  private static SDK_VERSION;
16
17
  private defaultAxiosSettings;
@@ -21,6 +22,8 @@ export declare class ApiBaseService {
21
22
  private setupAxiosResponseInterceptors;
22
23
  static get accessToken(): string;
23
24
  static set accessToken(value: string);
25
+ static set onTokenExpired(callback: (accessToken: string) => void);
26
+ protected isTokenExpired(response: AxiosResponse | undefined): boolean;
24
27
  baseURL(): string;
25
28
  protected post<T, B = undefined, R = AxiosResponse<T>>(endpoint: string, data?: B): Promise<R>;
26
29
  protected put<T, B, R = AxiosResponse<T>>(endpoint: string, data?: B): Promise<R>;
@@ -82,6 +82,11 @@ class ApiBaseService {
82
82
  this.api.interceptors.response.use((response) => {
83
83
  return response;
84
84
  }, (error) => {
85
+ if (this.isTokenExpired(error.response)) {
86
+ // access_token is expired
87
+ ApiBaseService._onTokenExpired(ApiBaseService._accessToken);
88
+ return error.response;
89
+ }
85
90
  if (error.response) {
86
91
  // server responded, but with a status code other than 2xx
87
92
  throw new Exceptions_1.ApiError(error);
@@ -102,6 +107,17 @@ class ApiBaseService {
102
107
  static set accessToken(value) {
103
108
  ApiBaseService._accessToken = value;
104
109
  }
110
+ static set onTokenExpired(callback) {
111
+ ApiBaseService._onTokenExpired = callback;
112
+ }
113
+ isTokenExpired(response) {
114
+ var _a, _b;
115
+ if (!ApiBaseService.accessToken) {
116
+ return false;
117
+ }
118
+ const decodedToken = JSON.parse(Buffer.from((_b = (_a = ApiBaseService.accessToken) === null || _a === void 0 ? void 0 : _a.split(".")) === null || _b === void 0 ? void 0 : _b[1], "base64").toString());
119
+ return (response === null || response === void 0 ? void 0 : response.status) === 401 && decodedToken.exp < (new Date().getTime() / 1000);
120
+ }
105
121
  baseURL() {
106
122
  return this.api.defaults.baseURL ? this.api.defaults.baseURL : "";
107
123
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devopness/sdk-js",
3
- "version": "2.133.0",
3
+ "version": "2.135.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },