snack-sdk 3.8.0 → 3.10.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.
- package/CHANGELOG.md +27 -1
- package/build/DependencyResolver.d.ts +26 -26
- package/build/DependencyResolver.js +258 -258
- package/build/DevSession.d.ts +20 -20
- package/build/DevSession.js +203 -203
- package/build/FileUploader.d.ts +23 -23
- package/build/FileUploader.js +174 -174
- package/build/Logger.d.ts +11 -11
- package/build/Logger.js +33 -33
- package/build/Session.d.ts +305 -301
- package/build/Session.js +1198 -1171
- package/build/Session.js.map +1 -1
- package/build/State.d.ts +16 -16
- package/build/State.js +90 -90
- package/build/WantedVersions.d.ts +40 -17
- package/build/WantedVersions.js +156 -93
- package/build/WantedVersions.js.map +1 -1
- package/build/defaultConfig.d.ts +12 -12
- package/build/defaultConfig.js +29 -29
- package/build/index.d.ts +7 -7
- package/build/index.js +30 -30
- package/build/transports/CodeMessageBuilder.d.ts +31 -31
- package/build/transports/CodeMessageBuilder.js +196 -196
- package/build/transports/Protocol.d.ts +64 -64
- package/build/transports/Protocol.js +2 -2
- package/build/transports/Transport.d.ts +28 -27
- package/build/transports/Transport.js +303 -298
- package/build/transports/Transport.js.map +1 -1
- package/build/transports/index.d.ts +3 -3
- package/build/transports/index.js +22 -22
- package/build/transports/types.d.ts +63 -63
- package/build/transports/types.js +2 -2
- package/build/transports/webPlayer.d.ts +12 -12
- package/build/transports/webPlayer.js +70 -70
- package/build/types.d.ts +189 -185
- package/build/types.js +2 -2
- package/build/types.js.map +1 -1
- package/build/utils.d.ts +17 -17
- package/build/utils.js +68 -68
- package/package.json +11 -4
- package/src/DependencyResolver.ts +0 -218
- package/src/DevSession.ts +0 -159
- package/src/FileUploader.ts +0 -135
- package/src/Logger.ts +0 -33
- package/src/Session.ts +0 -1293
- package/src/State.ts +0 -98
- package/src/WantedVersions.ts +0 -57
- package/src/defaultConfig.ts +0 -33
- package/src/index.ts +0 -59
- package/src/transports/CodeMessageBuilder.ts +0 -226
- package/src/transports/Protocol.ts +0 -78
- package/src/transports/Transport.ts +0 -270
- package/src/transports/index.ts +0 -8
- package/src/transports/types.ts +0 -89
- package/src/transports/webPlayer.ts +0 -93
- package/src/types.ts +0 -223
- package/src/utils.ts +0 -71
- package/tsconfig.json +0 -28
package/build/DevSession.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { Logger } from './Logger';
|
|
2
|
-
import { SnackState, SnackSendBeaconRequest } from './types';
|
|
3
|
-
export default class DevSession {
|
|
4
|
-
private apiURL;
|
|
5
|
-
private logger?;
|
|
6
|
-
private onSendBeaconCloseRequest;
|
|
7
|
-
private notifyInterval;
|
|
8
|
-
private notifyTimer?;
|
|
9
|
-
private focusedAt?;
|
|
10
|
-
constructor(options: {
|
|
11
|
-
apiURL: string;
|
|
12
|
-
logger?: Logger;
|
|
13
|
-
onSendBeaconCloseRequest: (request: SnackSendBeaconRequest) => any;
|
|
14
|
-
});
|
|
15
|
-
setState(state: SnackState, prevState: SnackState): void;
|
|
16
|
-
setFocus(state: SnackState): void;
|
|
17
|
-
private getRequest;
|
|
18
|
-
private notify;
|
|
19
|
-
private close;
|
|
20
|
-
}
|
|
1
|
+
import { Logger } from './Logger';
|
|
2
|
+
import { SnackState, SnackSendBeaconRequest } from './types';
|
|
3
|
+
export default class DevSession {
|
|
4
|
+
private apiURL;
|
|
5
|
+
private logger?;
|
|
6
|
+
private onSendBeaconCloseRequest;
|
|
7
|
+
private notifyInterval;
|
|
8
|
+
private notifyTimer?;
|
|
9
|
+
private focusedAt?;
|
|
10
|
+
constructor(options: {
|
|
11
|
+
apiURL: string;
|
|
12
|
+
logger?: Logger;
|
|
13
|
+
onSendBeaconCloseRequest: (request: SnackSendBeaconRequest) => any;
|
|
14
|
+
});
|
|
15
|
+
setState(state: SnackState, prevState: SnackState): void;
|
|
16
|
+
setFocus(state: SnackState): void;
|
|
17
|
+
private getRequest;
|
|
18
|
+
private notify;
|
|
19
|
+
private close;
|
|
20
|
+
}
|
package/build/DevSession.js
CHANGED
|
@@ -1,204 +1,204 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
-
var t = {};
|
|
51
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
-
t[p] = s[p];
|
|
53
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
-
t[p[i]] = s[p[i]];
|
|
57
|
-
}
|
|
58
|
-
return t;
|
|
59
|
-
};
|
|
60
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
-
var utils_1 = require("./utils");
|
|
62
|
-
var DevSession = /** @class */ (function () {
|
|
63
|
-
function DevSession(options) {
|
|
64
|
-
this.notifyInterval = 40000;
|
|
65
|
-
this.apiURL = options.apiURL;
|
|
66
|
-
this.logger = options.logger;
|
|
67
|
-
this.onSendBeaconCloseRequest = options.onSendBeaconCloseRequest;
|
|
68
|
-
}
|
|
69
|
-
DevSession.prototype.setState = function (state, prevState) {
|
|
70
|
-
// Notify or close the session , when either:
|
|
71
|
-
// 1. session-url has changed
|
|
72
|
-
// 2. user has changed
|
|
73
|
-
// 3. device-id has hanged
|
|
74
|
-
// Close
|
|
75
|
-
var isCloseUser = prevState.user &&
|
|
76
|
-
(!state.online || state.url !== prevState.url || state.user !== prevState.user);
|
|
77
|
-
var isCloseDevice = prevState.deviceId &&
|
|
78
|
-
(!state.online || state.url !== prevState.url || state.deviceId !== prevState.deviceId);
|
|
79
|
-
if (prevState.online && (isCloseUser || isCloseDevice)) {
|
|
80
|
-
this.close(prevState.url, isCloseUser ? prevState.user : undefined, isCloseDevice ? prevState.deviceId : undefined);
|
|
81
|
-
}
|
|
82
|
-
// Notify
|
|
83
|
-
if (state.user !== prevState.user ||
|
|
84
|
-
state.online !== prevState.online ||
|
|
85
|
-
state.url !== prevState.url ||
|
|
86
|
-
state.deviceId !== prevState.deviceId ||
|
|
87
|
-
state.onlineName !== prevState.onlineName) {
|
|
88
|
-
this.notify(state);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
DevSession.prototype.setFocus = function (state) {
|
|
92
|
-
this.notify(state, true);
|
|
93
|
-
};
|
|
94
|
-
DevSession.prototype.getRequest = function (close, user, deviceId) {
|
|
95
|
-
var suffix = deviceId ? "?deviceId=" + deviceId : '';
|
|
96
|
-
var endpoint = close ? 'notify-close' : 'notify-alive';
|
|
97
|
-
var url = this.apiURL + "/--/api/v2/development-sessions/" + endpoint + suffix;
|
|
98
|
-
return {
|
|
99
|
-
url: url,
|
|
100
|
-
method: 'post',
|
|
101
|
-
headers: __assign({ 'Content-Type': 'application/json' }, utils_1.createUserHeader(user)),
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
DevSession.prototype.notify = function (state, setFocus) {
|
|
105
|
-
var _a, _b;
|
|
106
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
-
var user, online, onlineURL, deviceId, onlineName, _c, url, data, response, json, e_1;
|
|
108
|
-
var _this = this;
|
|
109
|
-
return __generator(this, function (_d) {
|
|
110
|
-
switch (_d.label) {
|
|
111
|
-
case 0:
|
|
112
|
-
user = state.user, online = state.online, onlineURL = state.url, deviceId = state.deviceId, onlineName = state.onlineName;
|
|
113
|
-
if (this.notifyTimer) {
|
|
114
|
-
clearTimeout(this.notifyTimer);
|
|
115
|
-
this.notifyTimer = undefined;
|
|
116
|
-
}
|
|
117
|
-
if (!online || (!user && !deviceId)) {
|
|
118
|
-
this.focusedAt = undefined;
|
|
119
|
-
return [2 /*return*/];
|
|
120
|
-
}
|
|
121
|
-
if (!this.focusedAt || setFocus) {
|
|
122
|
-
this.focusedAt = Date.now();
|
|
123
|
-
}
|
|
124
|
-
if (!this.notifyTimer) {
|
|
125
|
-
this.notifyTimer = setTimeout(function () { return _this.notify(state); }, this.notifyInterval);
|
|
126
|
-
}
|
|
127
|
-
_d.label = 1;
|
|
128
|
-
case 1:
|
|
129
|
-
_d.trys.push([1, 4, , 5]);
|
|
130
|
-
_c = this.getRequest(false, user, deviceId), url = _c.url, data = __rest(_c, ["url"]);
|
|
131
|
-
return [4 /*yield*/, utils_1.fetch(url, __assign(__assign({}, data), { body: JSON.stringify({
|
|
132
|
-
data: {
|
|
133
|
-
session: {
|
|
134
|
-
description: onlineName,
|
|
135
|
-
hostname: 'snack',
|
|
136
|
-
config: {},
|
|
137
|
-
url: onlineURL,
|
|
138
|
-
source: 'snack',
|
|
139
|
-
openedAt: this.focusedAt,
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
}) }))];
|
|
143
|
-
case 2:
|
|
144
|
-
response = _d.sent();
|
|
145
|
-
if (!response.ok) {
|
|
146
|
-
throw Error(response.statusText);
|
|
147
|
-
}
|
|
148
|
-
return [4 /*yield*/, response.json()];
|
|
149
|
-
case 3:
|
|
150
|
-
json = _d.sent();
|
|
151
|
-
this.onSendBeaconCloseRequest({
|
|
152
|
-
url: this.getRequest(true, undefined, deviceId).url,
|
|
153
|
-
data: new Blob([
|
|
154
|
-
JSON.stringify(__assign({ session: {
|
|
155
|
-
url: onlineURL,
|
|
156
|
-
} }, (((_a = json.data) === null || _a === void 0 ? void 0 : _a.auth) ? {
|
|
157
|
-
auth: json.data.auth,
|
|
158
|
-
}
|
|
159
|
-
: {}))),
|
|
160
|
-
], { type: 'text/plain' }),
|
|
161
|
-
});
|
|
162
|
-
return [3 /*break*/, 5];
|
|
163
|
-
case 4:
|
|
164
|
-
e_1 = _d.sent();
|
|
165
|
-
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error('Failed to advertise', e_1);
|
|
166
|
-
return [3 /*break*/, 5];
|
|
167
|
-
case 5: return [2 /*return*/];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
DevSession.prototype.close = function (onlineURL, user, deviceId) {
|
|
173
|
-
var _a;
|
|
174
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
-
var _b, url, data, response, e_2;
|
|
176
|
-
return __generator(this, function (_c) {
|
|
177
|
-
switch (_c.label) {
|
|
178
|
-
case 0:
|
|
179
|
-
_c.trys.push([0, 2, , 3]);
|
|
180
|
-
_b = this.getRequest(true, user, deviceId), url = _b.url, data = __rest(_b, ["url"]);
|
|
181
|
-
return [4 /*yield*/, utils_1.fetch(url, __assign(__assign({}, data), { body: JSON.stringify({
|
|
182
|
-
session: {
|
|
183
|
-
url: onlineURL,
|
|
184
|
-
},
|
|
185
|
-
}) }))];
|
|
186
|
-
case 1:
|
|
187
|
-
response = _c.sent();
|
|
188
|
-
if (!response.ok) {
|
|
189
|
-
throw Error(response.statusText);
|
|
190
|
-
}
|
|
191
|
-
return [3 /*break*/, 3];
|
|
192
|
-
case 2:
|
|
193
|
-
e_2 = _c.sent();
|
|
194
|
-
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error('Failed to advertise close', e_2);
|
|
195
|
-
return [3 /*break*/, 3];
|
|
196
|
-
case 3: return [2 /*return*/];
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
};
|
|
201
|
-
return DevSession;
|
|
202
|
-
}());
|
|
203
|
-
exports.default = DevSession;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
+
t[p] = s[p];
|
|
53
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
+
t[p[i]] = s[p[i]];
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
};
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
var utils_1 = require("./utils");
|
|
62
|
+
var DevSession = /** @class */ (function () {
|
|
63
|
+
function DevSession(options) {
|
|
64
|
+
this.notifyInterval = 40000;
|
|
65
|
+
this.apiURL = options.apiURL;
|
|
66
|
+
this.logger = options.logger;
|
|
67
|
+
this.onSendBeaconCloseRequest = options.onSendBeaconCloseRequest;
|
|
68
|
+
}
|
|
69
|
+
DevSession.prototype.setState = function (state, prevState) {
|
|
70
|
+
// Notify or close the session , when either:
|
|
71
|
+
// 1. session-url has changed
|
|
72
|
+
// 2. user has changed
|
|
73
|
+
// 3. device-id has hanged
|
|
74
|
+
// Close
|
|
75
|
+
var isCloseUser = prevState.user &&
|
|
76
|
+
(!state.online || state.url !== prevState.url || state.user !== prevState.user);
|
|
77
|
+
var isCloseDevice = prevState.deviceId &&
|
|
78
|
+
(!state.online || state.url !== prevState.url || state.deviceId !== prevState.deviceId);
|
|
79
|
+
if (prevState.online && (isCloseUser || isCloseDevice)) {
|
|
80
|
+
this.close(prevState.url, isCloseUser ? prevState.user : undefined, isCloseDevice ? prevState.deviceId : undefined);
|
|
81
|
+
}
|
|
82
|
+
// Notify
|
|
83
|
+
if (state.user !== prevState.user ||
|
|
84
|
+
state.online !== prevState.online ||
|
|
85
|
+
state.url !== prevState.url ||
|
|
86
|
+
state.deviceId !== prevState.deviceId ||
|
|
87
|
+
state.onlineName !== prevState.onlineName) {
|
|
88
|
+
this.notify(state);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
DevSession.prototype.setFocus = function (state) {
|
|
92
|
+
this.notify(state, true);
|
|
93
|
+
};
|
|
94
|
+
DevSession.prototype.getRequest = function (close, user, deviceId) {
|
|
95
|
+
var suffix = deviceId ? "?deviceId=" + deviceId : '';
|
|
96
|
+
var endpoint = close ? 'notify-close' : 'notify-alive';
|
|
97
|
+
var url = this.apiURL + "/--/api/v2/development-sessions/" + endpoint + suffix;
|
|
98
|
+
return {
|
|
99
|
+
url: url,
|
|
100
|
+
method: 'post',
|
|
101
|
+
headers: __assign({ 'Content-Type': 'application/json' }, utils_1.createUserHeader(user)),
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
DevSession.prototype.notify = function (state, setFocus) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var user, online, onlineURL, deviceId, onlineName, _c, url, data, response, json, e_1;
|
|
108
|
+
var _this = this;
|
|
109
|
+
return __generator(this, function (_d) {
|
|
110
|
+
switch (_d.label) {
|
|
111
|
+
case 0:
|
|
112
|
+
user = state.user, online = state.online, onlineURL = state.url, deviceId = state.deviceId, onlineName = state.onlineName;
|
|
113
|
+
if (this.notifyTimer) {
|
|
114
|
+
clearTimeout(this.notifyTimer);
|
|
115
|
+
this.notifyTimer = undefined;
|
|
116
|
+
}
|
|
117
|
+
if (!online || (!user && !deviceId)) {
|
|
118
|
+
this.focusedAt = undefined;
|
|
119
|
+
return [2 /*return*/];
|
|
120
|
+
}
|
|
121
|
+
if (!this.focusedAt || setFocus) {
|
|
122
|
+
this.focusedAt = Date.now();
|
|
123
|
+
}
|
|
124
|
+
if (!this.notifyTimer) {
|
|
125
|
+
this.notifyTimer = setTimeout(function () { return _this.notify(state); }, this.notifyInterval);
|
|
126
|
+
}
|
|
127
|
+
_d.label = 1;
|
|
128
|
+
case 1:
|
|
129
|
+
_d.trys.push([1, 4, , 5]);
|
|
130
|
+
_c = this.getRequest(false, user, deviceId), url = _c.url, data = __rest(_c, ["url"]);
|
|
131
|
+
return [4 /*yield*/, utils_1.fetch(url, __assign(__assign({}, data), { body: JSON.stringify({
|
|
132
|
+
data: {
|
|
133
|
+
session: {
|
|
134
|
+
description: onlineName,
|
|
135
|
+
hostname: 'snack',
|
|
136
|
+
config: {},
|
|
137
|
+
url: onlineURL,
|
|
138
|
+
source: 'snack',
|
|
139
|
+
openedAt: this.focusedAt,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
}) }))];
|
|
143
|
+
case 2:
|
|
144
|
+
response = _d.sent();
|
|
145
|
+
if (!response.ok) {
|
|
146
|
+
throw Error(response.statusText);
|
|
147
|
+
}
|
|
148
|
+
return [4 /*yield*/, response.json()];
|
|
149
|
+
case 3:
|
|
150
|
+
json = _d.sent();
|
|
151
|
+
this.onSendBeaconCloseRequest({
|
|
152
|
+
url: this.getRequest(true, undefined, deviceId).url,
|
|
153
|
+
data: new Blob([
|
|
154
|
+
JSON.stringify(__assign({ session: {
|
|
155
|
+
url: onlineURL,
|
|
156
|
+
} }, (((_a = json.data) === null || _a === void 0 ? void 0 : _a.auth) ? {
|
|
157
|
+
auth: json.data.auth,
|
|
158
|
+
}
|
|
159
|
+
: {}))),
|
|
160
|
+
], { type: 'text/plain' }),
|
|
161
|
+
});
|
|
162
|
+
return [3 /*break*/, 5];
|
|
163
|
+
case 4:
|
|
164
|
+
e_1 = _d.sent();
|
|
165
|
+
(_b = this.logger) === null || _b === void 0 ? void 0 : _b.error('Failed to advertise', e_1);
|
|
166
|
+
return [3 /*break*/, 5];
|
|
167
|
+
case 5: return [2 /*return*/];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
DevSession.prototype.close = function (onlineURL, user, deviceId) {
|
|
173
|
+
var _a;
|
|
174
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
175
|
+
var _b, url, data, response, e_2;
|
|
176
|
+
return __generator(this, function (_c) {
|
|
177
|
+
switch (_c.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
_c.trys.push([0, 2, , 3]);
|
|
180
|
+
_b = this.getRequest(true, user, deviceId), url = _b.url, data = __rest(_b, ["url"]);
|
|
181
|
+
return [4 /*yield*/, utils_1.fetch(url, __assign(__assign({}, data), { body: JSON.stringify({
|
|
182
|
+
session: {
|
|
183
|
+
url: onlineURL,
|
|
184
|
+
},
|
|
185
|
+
}) }))];
|
|
186
|
+
case 1:
|
|
187
|
+
response = _c.sent();
|
|
188
|
+
if (!response.ok) {
|
|
189
|
+
throw Error(response.statusText);
|
|
190
|
+
}
|
|
191
|
+
return [3 /*break*/, 3];
|
|
192
|
+
case 2:
|
|
193
|
+
e_2 = _c.sent();
|
|
194
|
+
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.error('Failed to advertise close', e_2);
|
|
195
|
+
return [3 /*break*/, 3];
|
|
196
|
+
case 3: return [2 /*return*/];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
return DevSession;
|
|
202
|
+
}());
|
|
203
|
+
exports.default = DevSession;
|
|
204
204
|
//# sourceMappingURL=DevSession.js.map
|
package/build/FileUploader.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { SnackFile } from 'snack-content';
|
|
2
|
-
import { Logger } from './Logger';
|
|
3
|
-
import { SnackError } from './types';
|
|
4
|
-
export declare type FileUploaderRequest = {
|
|
5
|
-
path: string;
|
|
6
|
-
file: SnackFile;
|
|
7
|
-
};
|
|
8
|
-
export declare type FileUploaderCallback = (request: FileUploaderRequest, resultURL?: string, error?: SnackError) => any;
|
|
9
|
-
export default class FileUploader {
|
|
10
|
-
private apiURL;
|
|
11
|
-
private logger?;
|
|
12
|
-
private status;
|
|
13
|
-
private callback;
|
|
14
|
-
constructor(options: {
|
|
15
|
-
apiURL: string;
|
|
16
|
-
callback: FileUploaderCallback;
|
|
17
|
-
logger?: Logger;
|
|
18
|
-
});
|
|
19
|
-
add(path: string, file: SnackFile): Promise<any>;
|
|
20
|
-
remove(path: string, file?: SnackFile): void;
|
|
21
|
-
waitForCompletion(): Promise<void>;
|
|
22
|
-
private upload;
|
|
23
|
-
}
|
|
1
|
+
import { SnackFile } from 'snack-content';
|
|
2
|
+
import { Logger } from './Logger';
|
|
3
|
+
import { SnackError } from './types';
|
|
4
|
+
export declare type FileUploaderRequest = {
|
|
5
|
+
path: string;
|
|
6
|
+
file: SnackFile;
|
|
7
|
+
};
|
|
8
|
+
export declare type FileUploaderCallback = (request: FileUploaderRequest, resultURL?: string, error?: SnackError) => any;
|
|
9
|
+
export default class FileUploader {
|
|
10
|
+
private apiURL;
|
|
11
|
+
private logger?;
|
|
12
|
+
private status;
|
|
13
|
+
private callback;
|
|
14
|
+
constructor(options: {
|
|
15
|
+
apiURL: string;
|
|
16
|
+
callback: FileUploaderCallback;
|
|
17
|
+
logger?: Logger;
|
|
18
|
+
});
|
|
19
|
+
add(path: string, file: SnackFile): Promise<any>;
|
|
20
|
+
remove(path: string, file?: SnackFile): void;
|
|
21
|
+
waitForCompletion(): Promise<void>;
|
|
22
|
+
private upload;
|
|
23
|
+
}
|