roboto-js 1.5.0 → 1.5.2

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.
@@ -78,6 +78,16 @@ var Roboto = exports["default"] = /*#__PURE__*/function () {
78
78
  Roboto.instance = this;
79
79
  }
80
80
  _createClass(Roboto, [{
81
+ key: "setSiteEnv",
82
+ value: function setSiteEnv(siteEnv) {
83
+ this.api.setSiteEnv(siteEnv);
84
+ }
85
+ }, {
86
+ key: "getSiteEnv",
87
+ value: function getSiteEnv() {
88
+ return this.api.getSiteEnv();
89
+ }
90
+ }, {
81
91
  key: "setAppServiceHost",
82
92
  value: function setAppServiceHost(host) {
83
93
  // DEVELOPMENT
@@ -132,6 +132,16 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
132
132
  this.appServiceHost = host;
133
133
  this.axios.defaults.baseURL = host;
134
134
  }
135
+ }, {
136
+ key: "setSiteEnv",
137
+ value: function setSiteEnv(siteEnv) {
138
+ this.siteEnv = siteEnv;
139
+ }
140
+ }, {
141
+ key: "getSiteEnv",
142
+ value: function getSiteEnv() {
143
+ return this.siteEnv;
144
+ }
135
145
  }, {
136
146
  key: "registerTypedefs",
137
147
  value: function () {
@@ -163,61 +163,67 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
163
163
  key: "uploadFile",
164
164
  value: function uploadFile(file) {
165
165
  var _this2 = this;
166
- var upload = new _tusJsClient.Upload(file, {
167
- endpoint: this._axios.defaults.baseURL + "/file_service/files",
168
- retryDelays: [0, 1000, 3000, 5000],
169
- metadata: {
170
- rbtfileid: this.id,
171
- filename: file.name,
172
- filetype: file.type
173
- },
174
- onError: function onError(error) {
175
- console.error("Failed because:", error);
176
- _this2.emit('error', error);
177
- },
178
- onProgress: function onProgress(bytesUploaded, bytesTotal) {
179
- console.log("File progress", bytesUploaded, bytesTotal);
180
- var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
181
- _this2.setProgress(percentage / 100); // Update progress normalized between 0 and 1
182
- },
183
- onSuccess: function onSuccess() {
184
- console.log("File uploaded to:", upload.url);
166
+ return new Promise(function (resolve, reject) {
167
+ var upload = new _tusJsClient.Upload(file, {
168
+ endpoint: _this2._axios.defaults.baseURL + "/file_service/files",
169
+ retryDelays: [0, 1000, 3000, 5000],
170
+ metadata: {
171
+ rbtfileid: _this2.id,
172
+ filename: file.name,
173
+ filetype: file.type
174
+ },
175
+ onError: function onError(error) {
176
+ console.error("Failed because:", error);
177
+ _this2.emit('error', error);
178
+ reject(error); // Reject the promise on error
179
+ },
180
+ onProgress: function onProgress(bytesUploaded, bytesTotal) {
181
+ var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
182
+ _this2.emit('progress', percentage / 100); // Emit normalized progress
183
+ },
184
+ onSuccess: function onSuccess() {
185
+ //console.log("File uploaded to:", upload.url);
186
+ var m1 = upload.url.match(/\/([^\/]+)$/);
187
+ var remoteId = m1 ? m1[1] : null;
188
+ _this2.setData({
189
+ 'remoteId': remoteId,
190
+ 'remoteSrc': upload.url,
191
+ 'sourceFile': {
192
+ name: upload.file.name,
193
+ size: upload.file.size,
194
+ type: upload.file.type,
195
+ lastModified: upload.file.lastModified
196
+ }
197
+ });
185
198
 
186
- // Remove the `options.endpoint` from the start of the `url`
187
- var m1 = upload.url.match(/\/([^\/]+)$/);
188
- var remoteId = m1 ? m1[1] : null;
189
- _this2.setData({
190
- 'remoteId': remoteId,
191
- 'sourceFile': {
192
- name: upload.file.name,
193
- size: upload.file.size,
194
- type: upload.file.type,
195
- lastModified: upload.file.lastModified
196
- }
197
- });
198
- _this2.save().then(function () {
199
- _this2.emit('success', upload.url);
200
- });
201
- }
202
- });
199
+ // Ensure save is called and finished before resolving the promise
200
+ _this2.save().then(function () {
201
+ _this2.emit('success', upload.url);
202
+ resolve(); // Resolve the promise after save is complete
203
+ })["catch"](function (error) {
204
+ console.error("Save failed:", error);
205
+ reject(error); // Reject the promise if save fails
206
+ });
207
+ }
208
+ });
203
209
 
204
- // Check if there are any previous uploads to continue.
205
- // upload.findPreviousUploads().then(function (previousUploads) {
206
- // // Found previous uploads so we select the first one.
207
- // if (previousUploads.length) {
208
- // upload.resumeFromPreviousUpload(previousUploads[0])
209
- // }
210
+ // Check if there are any previous uploads to continue.
211
+ // upload.findPreviousUploads().then(function (previousUploads) {
212
+ // // Found previous uploads so we select the first one.
213
+ // if (previousUploads.length) {
214
+ // upload.resumeFromPreviousUpload(previousUploads[0])
215
+ // }
210
216
 
211
- // // Start the upload
212
- // upload.start();
213
- // })
214
- upload.start();
217
+ // // Start the upload
218
+ // upload.start();
219
+ // })
220
+ upload.start(); // Start the upload
221
+ });
215
222
  }
216
223
  }, {
217
224
  key: "setProgress",
218
225
  value: function setProgress(newProgress) {
219
226
  this.progress = newProgress;
220
- console.log("Progress: ".concat(this.progress * 100, "%"));
221
227
  this.emit('progress', this.progress); // Emit a progress event
222
228
  }
223
229
  }]);
package/dist/esm/index.js CHANGED
@@ -46,6 +46,12 @@ export default class Roboto {
46
46
  }
47
47
  Roboto.instance = this;
48
48
  }
49
+ setSiteEnv(siteEnv) {
50
+ this.api.setSiteEnv(siteEnv);
51
+ }
52
+ getSiteEnv() {
53
+ return this.api.getSiteEnv();
54
+ }
49
55
  setAppServiceHost(host) {
50
56
  // DEVELOPMENT
51
57
  host = this._stripHttpsForDomains(host, ['localhost']);
@@ -61,6 +61,12 @@ export default class RbtApi {
61
61
  this.appServiceHost = host;
62
62
  this.axios.defaults.baseURL = host;
63
63
  }
64
+ setSiteEnv(siteEnv) {
65
+ this.siteEnv = siteEnv;
66
+ }
67
+ getSiteEnv() {
68
+ return this.siteEnv;
69
+ }
64
70
  async registerTypedefs(typedefs) {
65
71
  try {
66
72
  const response = await this.axios.post('/api/doctree/registerTypedefs', [{
@@ -71,59 +71,65 @@ export default class RbtFile extends EventEmitter {
71
71
  }
72
72
  }
73
73
  uploadFile(file) {
74
- const upload = new Upload(file, {
75
- endpoint: this._axios.defaults.baseURL + "/file_service/files",
76
- retryDelays: [0, 1000, 3000, 5000],
77
- metadata: {
78
- rbtfileid: this.id,
79
- filename: file.name,
80
- filetype: file.type
81
- },
82
- onError: error => {
83
- console.error("Failed because:", error);
84
- this.emit('error', error);
85
- },
86
- onProgress: (bytesUploaded, bytesTotal) => {
87
- console.log("File progress", bytesUploaded, bytesTotal);
88
- const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
89
- this.setProgress(percentage / 100); // Update progress normalized between 0 and 1
90
- },
91
- onSuccess: () => {
92
- console.log("File uploaded to:", upload.url);
74
+ return new Promise((resolve, reject) => {
75
+ const upload = new Upload(file, {
76
+ endpoint: this._axios.defaults.baseURL + "/file_service/files",
77
+ retryDelays: [0, 1000, 3000, 5000],
78
+ metadata: {
79
+ rbtfileid: this.id,
80
+ filename: file.name,
81
+ filetype: file.type
82
+ },
83
+ onError: error => {
84
+ console.error("Failed because:", error);
85
+ this.emit('error', error);
86
+ reject(error); // Reject the promise on error
87
+ },
88
+ onProgress: (bytesUploaded, bytesTotal) => {
89
+ const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
90
+ this.emit('progress', percentage / 100); // Emit normalized progress
91
+ },
92
+ onSuccess: () => {
93
+ //console.log("File uploaded to:", upload.url);
94
+ const m1 = upload.url.match(/\/([^\/]+)$/);
95
+ const remoteId = m1 ? m1[1] : null;
96
+ this.setData({
97
+ 'remoteId': remoteId,
98
+ 'remoteSrc': upload.url,
99
+ 'sourceFile': {
100
+ name: upload.file.name,
101
+ size: upload.file.size,
102
+ type: upload.file.type,
103
+ lastModified: upload.file.lastModified
104
+ }
105
+ });
93
106
 
94
- // Remove the `options.endpoint` from the start of the `url`
95
- const m1 = upload.url.match(/\/([^\/]+)$/);
96
- const remoteId = m1 ? m1[1] : null;
97
- this.setData({
98
- 'remoteId': remoteId,
99
- 'sourceFile': {
100
- name: upload.file.name,
101
- size: upload.file.size,
102
- type: upload.file.type,
103
- lastModified: upload.file.lastModified
104
- }
105
- });
106
- this.save().then(() => {
107
- this.emit('success', upload.url);
108
- });
109
- }
110
- });
107
+ // Ensure save is called and finished before resolving the promise
108
+ this.save().then(() => {
109
+ this.emit('success', upload.url);
110
+ resolve(); // Resolve the promise after save is complete
111
+ }).catch(error => {
112
+ console.error("Save failed:", error);
113
+ reject(error); // Reject the promise if save fails
114
+ });
115
+ }
116
+ });
111
117
 
112
- // Check if there are any previous uploads to continue.
113
- // upload.findPreviousUploads().then(function (previousUploads) {
114
- // // Found previous uploads so we select the first one.
115
- // if (previousUploads.length) {
116
- // upload.resumeFromPreviousUpload(previousUploads[0])
117
- // }
118
+ // Check if there are any previous uploads to continue.
119
+ // upload.findPreviousUploads().then(function (previousUploads) {
120
+ // // Found previous uploads so we select the first one.
121
+ // if (previousUploads.length) {
122
+ // upload.resumeFromPreviousUpload(previousUploads[0])
123
+ // }
118
124
 
119
- // // Start the upload
120
- // upload.start();
121
- // })
122
- upload.start();
125
+ // // Start the upload
126
+ // upload.start();
127
+ // })
128
+ upload.start(); // Start the upload
129
+ });
123
130
  }
124
131
  setProgress(newProgress) {
125
132
  this.progress = newProgress;
126
- console.log(`Progress: ${this.progress * 100}%`);
127
133
  this.emit('progress', this.progress); // Emit a progress event
128
134
  }
129
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/index.js CHANGED
@@ -54,6 +54,15 @@ export default class Roboto{
54
54
 
55
55
  }
56
56
 
57
+ setSiteEnv(siteEnv){
58
+ this.api.setSiteEnv(siteEnv);
59
+ }
60
+
61
+
62
+ getSiteEnv(){
63
+ return this.api.getSiteEnv();
64
+ }
65
+
57
66
  setAppServiceHost(host){
58
67
 
59
68
  // DEVELOPMENT
package/src/rbt_api.js CHANGED
@@ -70,6 +70,18 @@ export default class RbtApi {
70
70
 
71
71
  }
72
72
 
73
+ setSiteEnv(siteEnv){
74
+
75
+ this.siteEnv = siteEnv;
76
+
77
+ }
78
+
79
+ getSiteEnv(){
80
+
81
+ return this.siteEnv;
82
+
83
+ }
84
+
73
85
 
74
86
  async registerTypedefs(typedefs){
75
87
 
package/src/rbt_file.js CHANGED
@@ -85,45 +85,51 @@ export default class RbtFile extends EventEmitter {
85
85
  }
86
86
 
87
87
  uploadFile(file) {
88
+ return new Promise((resolve, reject) => {
89
+ const upload = new Upload(file, {
90
+ endpoint: this._axios.defaults.baseURL + "/file_service/files",
91
+ retryDelays: [0, 1000, 3000, 5000],
92
+ metadata: {
93
+ rbtfileid: this.id,
94
+ filename: file.name,
95
+ filetype: file.type,
96
+ },
97
+ onError: error => {
98
+ console.error("Failed because:", error);
99
+ this.emit('error', error);
100
+ reject(error); // Reject the promise on error
101
+ },
102
+ onProgress: (bytesUploaded, bytesTotal) => {
103
+ const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
104
+ this.emit('progress', percentage / 100); // Emit normalized progress
105
+ },
106
+ onSuccess: () => {
107
+ //console.log("File uploaded to:", upload.url);
108
+ const m1 = upload.url.match(/\/([^\/]+)$/);
109
+ const remoteId = m1 ? m1[1] : null;
110
+
111
+ this.setData({
112
+ 'remoteId': remoteId,
113
+ 'remoteSrc': upload.url,
114
+ 'sourceFile': {
115
+ name: upload.file.name,
116
+ size: upload.file.size,
117
+ type: upload.file.type,
118
+ lastModified: upload.file.lastModified,
119
+ }
120
+ });
121
+
122
+ // Ensure save is called and finished before resolving the promise
123
+ this.save().then(() => {
124
+ this.emit('success', upload.url);
125
+ resolve(); // Resolve the promise after save is complete
126
+ }).catch(error => {
127
+ console.error("Save failed:", error);
128
+ reject(error); // Reject the promise if save fails
129
+ });
130
+ }
131
+ });
88
132
 
89
- const upload = new Upload(file, {
90
- endpoint: this._axios.defaults.baseURL+"/file_service/files",
91
- retryDelays: [0, 1000, 3000, 5000],
92
- metadata: {
93
- rbtfileid: this.id,
94
- filename: file.name,
95
- filetype: file.type,
96
- },
97
- onError: error => {
98
- console.error("Failed because:", error);
99
- this.emit('error', error);
100
- },
101
- onProgress: (bytesUploaded, bytesTotal) => {
102
- console.log("File progress", bytesUploaded, bytesTotal);
103
- const percentage = (bytesUploaded / bytesTotal * 100).toFixed(2);
104
- this.setProgress(percentage / 100); // Update progress normalized between 0 and 1
105
- },
106
- onSuccess: () => {
107
- console.log("File uploaded to:", upload.url);
108
-
109
- // Remove the `options.endpoint` from the start of the `url`
110
- const m1 = upload.url.match(/\/([^\/]+)$/);
111
- const remoteId = m1 ? m1[1] : null;
112
-
113
- this.setData({
114
- 'remoteId': remoteId,
115
- 'sourceFile': {
116
- name: upload.file.name,
117
- size: upload.file.size,
118
- type: upload.file.type,
119
- lastModified: upload.file.lastModified,
120
- }
121
- });
122
- this.save().then(() => {
123
- this.emit('success', upload.url);
124
- });
125
- }
126
- });
127
133
 
128
134
  // Check if there are any previous uploads to continue.
129
135
  // upload.findPreviousUploads().then(function (previousUploads) {
@@ -135,12 +141,14 @@ export default class RbtFile extends EventEmitter {
135
141
  // // Start the upload
136
142
  // upload.start();
137
143
  // })
138
- upload.start();
144
+ upload.start(); // Start the upload
145
+ });
139
146
  }
140
147
 
148
+
149
+
141
150
  setProgress(newProgress) {
142
151
  this.progress = newProgress;
143
- console.log(`Progress: ${this.progress * 100}%`);
144
152
  this.emit('progress', this.progress); // Emit a progress event
145
153
  }
146
154
  }