snack-sdk 3.9.0 → 4.0.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 +18 -8
- package/build/Session.d.ts +9 -3
- package/build/Session.js +61 -34
- package/build/Session.js.map +1 -1
- package/build/defaultConfig.d.ts +2 -0
- package/build/defaultConfig.js +3 -1
- package/build/defaultConfig.js.map +1 -1
- package/build/transports/CompositeTransport.d.ts +8 -0
- package/build/transports/CompositeTransport.js +33 -0
- package/build/transports/CompositeTransport.js.map +1 -0
- package/build/transports/CompositedTransport.d.ts +8 -0
- package/build/transports/CompositedTransport.js +33 -0
- package/build/transports/CompositedTransport.js.map +1 -0
- package/build/transports/ConnectionMetricsEmitter.d.ts +23 -0
- package/build/transports/ConnectionMetricsEmitter.js +49 -0
- package/build/transports/ConnectionMetricsEmitter.js.map +1 -0
- package/build/transports/TrafficMirroringTransport.d.ts +8 -0
- package/build/transports/TrafficMirroringTransport.js +33 -0
- package/build/transports/TrafficMirroringTransport.js.map +1 -0
- package/build/transports/TransportImplBase.d.ts +51 -0
- package/build/transports/TransportImplBase.js +231 -0
- package/build/transports/TransportImplBase.js.map +1 -0
- package/build/transports/TransportImplComposited.d.ts +8 -0
- package/build/transports/TransportImplComposited.js +33 -0
- package/build/transports/TransportImplComposited.js.map +1 -0
- package/build/transports/TransportImplPubNub.d.ts +15 -0
- package/build/transports/TransportImplPubNub.js +169 -0
- package/build/transports/TransportImplPubNub.js.map +1 -0
- package/build/transports/TransportImplSocketIO.d.ts +18 -0
- package/build/transports/TransportImplSocketIO.js +122 -0
- package/build/transports/TransportImplSocketIO.js.map +1 -0
- package/build/transports/TransportImplWebPlayer.d.ts +23 -0
- package/build/transports/TransportImplWebPlayer.js +128 -0
- package/build/transports/TransportImplWebPlayer.js.map +1 -0
- package/build/transports/index.d.ts +3 -0
- package/build/transports/index.js +11 -3
- package/build/transports/index.js.map +1 -1
- package/build/transports/types.d.ts +2 -3
- package/build/transports/types.js.map +1 -1
- package/build/transports/webPlayer.d.ts +1 -2
- package/build/transports/webPlayer.js +5 -57
- package/build/transports/webPlayer.js.map +1 -1
- package/build/types.d.ts +5 -1
- package/build/types.js.map +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,18 +4,28 @@
|
|
|
4
4
|
|
|
5
5
|
### 🛠 Breaking changes
|
|
6
6
|
|
|
7
|
+
- Replace the default transport from PubNub to SnackPub ([#376](https://github.com/expo/snack/pull/376), [#417](https://github.com/expo/snack/pull/417) by [@kudo](https://github.com/kudo)). To load SDK 45/46/47 snacks in Expo Go, you need to update your snack-sdk version to this version or a newer version that is compatible with the latest Expo Go snack runtime. There are no other migrations required.
|
|
8
|
+
|
|
9
|
+
## 3.10.0 - 2023-02-14
|
|
10
|
+
|
|
11
|
+
### 🛠 Breaking changes
|
|
12
|
+
|
|
13
|
+
- Dropped Expo SDK 44 ([#360](https://github.com/expo/snack/pull/360) by [@bycedric](https://github.com/byCedric))
|
|
14
|
+
|
|
7
15
|
### 🎉 New features
|
|
8
16
|
|
|
17
|
+
- Upgrade to Expo SDK 47 ([#360](https://github.com/expo/snack/pull/360) by [@bycedric](https://github.com/byCedric))
|
|
18
|
+
|
|
9
19
|
### 🐛 Bug fixes
|
|
10
20
|
|
|
11
21
|
## 3.9.0 - 2022-08-03
|
|
12
22
|
|
|
13
23
|
### 🎉 New features
|
|
14
24
|
|
|
15
|
-
- Upgrade to Expo SDK 46 stable ([#337](https://github.com/expo/snack/pull/337)
|
|
16
|
-
- Add versioned endpoints for modules ([#334](https://github.com/expo/snack/pull/334)
|
|
17
|
-
- Upgrade pubnub to 7.2.0 ([#332](https://github.com/expo/snack/pull/332)
|
|
18
|
-
- Upgrade Snack to Expo SDK 45 ([#290](https://github.com/expo/snack/pull/290)
|
|
25
|
+
- Upgrade to Expo SDK 46 stable ([#337](https://github.com/expo/snack/pull/337) by [@bycedric](https://github.com/byCedric))
|
|
26
|
+
- Add versioned endpoints for modules ([#334](https://github.com/expo/snack/pull/334) by [@bycedric](https://github.com/byCedric))
|
|
27
|
+
- Upgrade pubnub to 7.2.0 ([#332](https://github.com/expo/snack/pull/332) by [@bycedric](https://github.com/byCedric))
|
|
28
|
+
- Upgrade Snack to Expo SDK 45 ([#290](https://github.com/expo/snack/pull/290) by [@danstepanov](https://github.com/danstepanov))
|
|
19
29
|
|
|
20
30
|
## 3.8.0 - 2022-04-20
|
|
21
31
|
|
|
@@ -25,16 +35,16 @@
|
|
|
25
35
|
|
|
26
36
|
### 🎉 New features
|
|
27
37
|
|
|
28
|
-
- Prepare snack-sdk and snack-content for SDK 44 ([#277](https://github.com/expo/snack/pull/277)
|
|
29
|
-
- Split out code related to Snack project definitions into `snack-content` ([#251](https://github.com/expo/snack/pull/251)
|
|
30
|
-
- Upgrade Snack to Expo SDK 44 ([#243](https://github.com/expo/snack/pull/243)
|
|
38
|
+
- Prepare snack-sdk and snack-content for SDK 44 ([#277](https://github.com/expo/snack/pull/277) by [@bycedric](https://github.com/byCedric))
|
|
39
|
+
- Split out code related to Snack project definitions into `snack-content` ([#251](https://github.com/expo/snack/pull/251) by [@ide](https://github.com/ide))
|
|
40
|
+
- Upgrade Snack to Expo SDK 44 ([#243](https://github.com/expo/snack/pull/243) by [@bycedric](https://github.com/byCedric))
|
|
31
41
|
|
|
32
42
|
## 3.7.0 — 2021-12-17
|
|
33
43
|
|
|
34
44
|
### 🎉 New features
|
|
35
45
|
|
|
36
46
|
- `SnackState` & `SnackOptions` include `snackId` and `accountSnackId` for tracking snacks, rather than only full name (id).
|
|
37
|
-
- `saveAsync` additionally returns `snackId` and `accountSnackId`.
|
|
47
|
+
- `saveAsync` additionally returns `snackId` and `accountSnackId`.
|
|
38
48
|
|
|
39
49
|
## 3.6.0 — 2021-10-29
|
|
40
50
|
|
package/build/Session.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare type SnackOptions = {
|
|
|
8
8
|
dependencies?: SnackDependencies;
|
|
9
9
|
files?: SnackFiles;
|
|
10
10
|
apiURL?: string;
|
|
11
|
+
snackpubURL?: string | undefined;
|
|
11
12
|
host?: string;
|
|
12
13
|
snackagerURL?: string;
|
|
13
14
|
verbose?: boolean;
|
|
@@ -39,9 +40,11 @@ export default class Snack {
|
|
|
39
40
|
private state;
|
|
40
41
|
private stateListeners;
|
|
41
42
|
private logListeners;
|
|
43
|
+
private readonly options;
|
|
42
44
|
private readonly createTransport;
|
|
43
45
|
private readonly logger?;
|
|
44
46
|
private readonly apiURL;
|
|
47
|
+
private readonly snackpubURL;
|
|
45
48
|
private readonly host;
|
|
46
49
|
private readonly dependencyResolver;
|
|
47
50
|
private readonly fileUploader;
|
|
@@ -51,7 +54,6 @@ export default class Snack {
|
|
|
51
54
|
private codeChangesTimer;
|
|
52
55
|
private readonly reloadTimeout;
|
|
53
56
|
private readonly previewTimeout;
|
|
54
|
-
private readonly webPlayerURL;
|
|
55
57
|
private pruneConnectionsTimer;
|
|
56
58
|
private readonly transportListeners;
|
|
57
59
|
constructor(options: SnackOptions);
|
|
@@ -93,7 +95,7 @@ export default class Snack {
|
|
|
93
95
|
/**
|
|
94
96
|
* Sets the delay that is used before sending code updates to the connected clients.
|
|
95
97
|
* Use this method to set the "debounce" timeout to use for sending code changes
|
|
96
|
-
* over
|
|
98
|
+
* over pubsub.
|
|
97
99
|
*
|
|
98
100
|
* ```
|
|
99
101
|
* -1 = Disable automatic sending of code changes (use `sendCodeChanges` to trigger the send)
|
|
@@ -104,6 +106,10 @@ export default class Snack {
|
|
|
104
106
|
* @param delay Timeout in milliseconds (or -1 to disable automatic code updates)
|
|
105
107
|
*/
|
|
106
108
|
setCodeChangesDelay(delay: number): void;
|
|
109
|
+
/**
|
|
110
|
+
* Update the `webPlayerURL` which serves the webPlayer runtime.
|
|
111
|
+
*/
|
|
112
|
+
setWebPlayerURL(webPlayerURL: string | null): void;
|
|
107
113
|
/**
|
|
108
114
|
* Sends any pending code changes to the connected clients.
|
|
109
115
|
* No changes are send if all clients are already up to date.
|
|
@@ -254,7 +260,7 @@ export default class Snack {
|
|
|
254
260
|
/**
|
|
255
261
|
* Makes the Snack available online.
|
|
256
262
|
*
|
|
257
|
-
* When online, a
|
|
263
|
+
* When online, a pubsub channel is created to which clients can
|
|
258
264
|
* connect.
|
|
259
265
|
*/
|
|
260
266
|
setOnline(enabled: boolean): void;
|
package/build/Session.js
CHANGED
|
@@ -85,7 +85,7 @@ var utils_1 = require("./utils");
|
|
|
85
85
|
var Snack = /** @class */ (function () {
|
|
86
86
|
function Snack(options) {
|
|
87
87
|
var _this = this;
|
|
88
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
88
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
89
89
|
this.stateListeners = new Set();
|
|
90
90
|
this.logListeners = new Set();
|
|
91
91
|
this.transportListeners = {};
|
|
@@ -192,39 +192,41 @@ var Snack = /** @class */ (function () {
|
|
|
192
192
|
var channel = utils_1.createChannel(options.channel);
|
|
193
193
|
var sdkVersion = snack_content_1.validateSDKVersion((_a = options.sdkVersion) !== null && _a !== void 0 ? _a : defaultConfig_1.default.sdkVersion);
|
|
194
194
|
var dependencies = options.dependencies ? __assign({}, options.dependencies) : {};
|
|
195
|
+
this.options = options;
|
|
195
196
|
this.apiURL = (_b = options.apiURL) !== null && _b !== void 0 ? _b : defaultConfig_1.default.apiURL;
|
|
196
|
-
this.
|
|
197
|
+
this.snackpubURL = (_c = options.snackpubURL) !== null && _c !== void 0 ? _c : defaultConfig_1.default.snackpubURL;
|
|
198
|
+
this.host = (_d = options.host) !== null && _d !== void 0 ? _d : new URL(this.apiURL).host;
|
|
197
199
|
this.logger = options.verbose ? Logger_1.createLogger(true) : undefined;
|
|
198
|
-
this.codeChangesDelay = (
|
|
199
|
-
this.reloadTimeout = (
|
|
200
|
-
this.previewTimeout = (
|
|
201
|
-
this.createTransport = (
|
|
202
|
-
|
|
203
|
-
var transports = (
|
|
200
|
+
this.codeChangesDelay = (_e = options.codeChangesDelay) !== null && _e !== void 0 ? _e : 0;
|
|
201
|
+
this.reloadTimeout = (_f = options.reloadTimeout) !== null && _f !== void 0 ? _f : 0;
|
|
202
|
+
this.previewTimeout = (_g = options.previewTimeout) !== null && _g !== void 0 ? _g : 10000;
|
|
203
|
+
this.createTransport = (_h = options.createTransport) !== null && _h !== void 0 ? _h : transports_1.createTransport;
|
|
204
|
+
var webPlayerURL = (_j = options.webPlayerURL) !== null && _j !== void 0 ? _j : defaultConfig_1.default.webPlayerURL;
|
|
205
|
+
var transports = (_k = options.transports) !== null && _k !== void 0 ? _k : {};
|
|
204
206
|
if (options.online) {
|
|
205
|
-
transports = State.addObject(transports, '
|
|
206
|
-
name: '
|
|
207
|
+
transports = State.addObject(transports, 'pubsub', this.createTransport({
|
|
208
|
+
name: 'pubsub',
|
|
207
209
|
channel: channel,
|
|
208
210
|
verbose: options.verbose,
|
|
209
211
|
apiURL: this.apiURL,
|
|
212
|
+
snackpubURL: this.snackpubURL,
|
|
210
213
|
}));
|
|
211
214
|
}
|
|
212
215
|
if (options.webPreviewRef) {
|
|
213
216
|
transports = State.addObject(transports, 'webplayer', webPlayer_1.createWebPlayerTransport({
|
|
214
217
|
ref: options.webPreviewRef,
|
|
215
218
|
verbose: options.verbose,
|
|
216
|
-
createTransport: this.createTransport,
|
|
217
219
|
window: nullthrows_1.default(typeof window !== 'undefined' ? window : global),
|
|
218
|
-
webPlayerURL:
|
|
220
|
+
webPlayerURL: webPlayerURL,
|
|
219
221
|
}));
|
|
220
222
|
}
|
|
221
223
|
this.state = this.updateDerivedState({
|
|
222
224
|
disabled: !!options.disabled,
|
|
223
225
|
unsaved: false,
|
|
224
|
-
name: (
|
|
225
|
-
description: (
|
|
226
|
+
name: (_l = options.name) !== null && _l !== void 0 ? _l : '',
|
|
227
|
+
description: (_m = options.description) !== null && _m !== void 0 ? _m : '',
|
|
226
228
|
sdkVersion: sdkVersion,
|
|
227
|
-
files: (
|
|
229
|
+
files: (_o = options.files) !== null && _o !== void 0 ? _o : {},
|
|
228
230
|
dependencies: dependencies,
|
|
229
231
|
missingDependencies: DependencyResolver_1.getMissingDependencies(dependencies, sdkVersion),
|
|
230
232
|
connectedClients: {},
|
|
@@ -239,6 +241,7 @@ var Snack = /** @class */ (function () {
|
|
|
239
241
|
deviceId: options.deviceId,
|
|
240
242
|
snackId: options.snackId,
|
|
241
243
|
accountSnackId: options.accountSnackId,
|
|
244
|
+
webPlayerURL: webPlayerURL,
|
|
242
245
|
}, defaultConfig_1.SnackIdentityState);
|
|
243
246
|
this.state.unsaved = false;
|
|
244
247
|
this.wantedDependencyVersions = new WantedVersions_1.WantedDependencyVersions({
|
|
@@ -247,7 +250,7 @@ var Snack = /** @class */ (function () {
|
|
|
247
250
|
callback: this.onWantedDependencyVersions,
|
|
248
251
|
});
|
|
249
252
|
this.dependencyResolver = new DependencyResolver_1.default({
|
|
250
|
-
snackagerURL: (
|
|
253
|
+
snackagerURL: (_p = options.snackagerURL) !== null && _p !== void 0 ? _p : defaultConfig_1.default.snackagerURL,
|
|
251
254
|
logger: this.logger,
|
|
252
255
|
callback: this.onDependencyResolved,
|
|
253
256
|
});
|
|
@@ -261,7 +264,7 @@ var Snack = /** @class */ (function () {
|
|
|
261
264
|
logger: this.logger,
|
|
262
265
|
onSendBeaconCloseRequest: this.onDevSessionSendBeaconCloseRequest,
|
|
263
266
|
});
|
|
264
|
-
(
|
|
267
|
+
(_q = this.logger) === null || _q === void 0 ? void 0 : _q.info('Snack created', this.getState());
|
|
265
268
|
this.onStateChanged(this.state, defaultConfig_1.SnackIdentityState);
|
|
266
269
|
}
|
|
267
270
|
//
|
|
@@ -325,7 +328,7 @@ var Snack = /** @class */ (function () {
|
|
|
325
328
|
/**
|
|
326
329
|
* Sets the delay that is used before sending code updates to the connected clients.
|
|
327
330
|
* Use this method to set the "debounce" timeout to use for sending code changes
|
|
328
|
-
* over
|
|
331
|
+
* over pubsub.
|
|
329
332
|
*
|
|
330
333
|
* ```
|
|
331
334
|
* -1 = Disable automatic sending of code changes (use `sendCodeChanges` to trigger the send)
|
|
@@ -341,6 +344,26 @@ var Snack = /** @class */ (function () {
|
|
|
341
344
|
this._sendCodeChangesDebounced(this.state);
|
|
342
345
|
}
|
|
343
346
|
};
|
|
347
|
+
/**
|
|
348
|
+
* Update the `webPlayerURL` which serves the webPlayer runtime.
|
|
349
|
+
*/
|
|
350
|
+
Snack.prototype.setWebPlayerURL = function (webPlayerURL) {
|
|
351
|
+
var _this = this;
|
|
352
|
+
this.setState(function (state) {
|
|
353
|
+
var newWebPlayerURL = webPlayerURL !== null && webPlayerURL !== void 0 ? webPlayerURL : defaultConfig_1.default.webPlayerURL;
|
|
354
|
+
if (state.webPlayerURL !== newWebPlayerURL && _this.options.webPreviewRef) {
|
|
355
|
+
var transports = state.transports;
|
|
356
|
+
transports = State.addObject(transports, 'webplayer', webPlayer_1.createWebPlayerTransport({
|
|
357
|
+
ref: _this.options.webPreviewRef,
|
|
358
|
+
verbose: _this.options.verbose,
|
|
359
|
+
window: nullthrows_1.default(typeof window !== 'undefined' ? window : global),
|
|
360
|
+
webPlayerURL: newWebPlayerURL,
|
|
361
|
+
}));
|
|
362
|
+
return { webPlayerURL: newWebPlayerURL, transports: transports };
|
|
363
|
+
}
|
|
364
|
+
return null;
|
|
365
|
+
});
|
|
366
|
+
};
|
|
344
367
|
/**
|
|
345
368
|
* Sends any pending code changes to the connected clients.
|
|
346
369
|
* No changes are send if all clients are already up to date.
|
|
@@ -834,31 +857,32 @@ var Snack = /** @class */ (function () {
|
|
|
834
857
|
/**
|
|
835
858
|
* Makes the Snack available online.
|
|
836
859
|
*
|
|
837
|
-
* When online, a
|
|
860
|
+
* When online, a pubsub channel is created to which clients can
|
|
838
861
|
* connect.
|
|
839
862
|
*/
|
|
840
863
|
Snack.prototype.setOnline = function (enabled) {
|
|
841
864
|
var _this = this;
|
|
842
865
|
return this.setState(function (state) {
|
|
843
|
-
if (enabled && !state.transports['
|
|
866
|
+
if (enabled && !state.transports['pubsub']) {
|
|
844
867
|
return {
|
|
845
|
-
transports: State.addObject(state.transports, '
|
|
846
|
-
name: '
|
|
868
|
+
transports: State.addObject(state.transports, 'pubsub', _this.createTransport({
|
|
869
|
+
name: 'pubsub',
|
|
847
870
|
apiURL: _this.apiURL,
|
|
871
|
+
snackpubURL: _this.snackpubURL,
|
|
848
872
|
channel: state.channel,
|
|
849
873
|
verbose: !!_this.logger,
|
|
850
874
|
})),
|
|
851
875
|
};
|
|
852
876
|
}
|
|
853
|
-
else if (!enabled && state.transports['
|
|
877
|
+
else if (!enabled && state.transports['pubsub']) {
|
|
854
878
|
var connectedClients = state.connectedClients;
|
|
855
879
|
for (var key in state.connectedClients) {
|
|
856
|
-
if (state.connectedClients[key].transport === '
|
|
880
|
+
if (state.connectedClients[key].transport === 'pubsub') {
|
|
857
881
|
connectedClients = State.removeObject(connectedClients, key);
|
|
858
882
|
}
|
|
859
883
|
}
|
|
860
884
|
return {
|
|
861
|
-
transports: State.removeObject(state.transports, '
|
|
885
|
+
transports: State.removeObject(state.transports, 'pubsub'),
|
|
862
886
|
connectedClients: connectedClients,
|
|
863
887
|
};
|
|
864
888
|
}
|
|
@@ -875,17 +899,20 @@ var Snack = /** @class */ (function () {
|
|
|
875
899
|
id !== prevState.id ||
|
|
876
900
|
name !== prevState.name ||
|
|
877
901
|
savedSDKVersion !== prevState.savedSDKVersion) {
|
|
878
|
-
state.online = !!transports['
|
|
902
|
+
state.online = !!transports['pubsub'] && !disabled;
|
|
879
903
|
state.url = utils_1.createURL(this.host, sdkVersion, channel, savedSDKVersion && savedSDKVersion !== sdkVersion ? undefined : id);
|
|
880
904
|
state.onlineName = "" + (name || 'Unnamed Snack');
|
|
881
905
|
}
|
|
882
906
|
};
|
|
883
907
|
Snack.prototype.updateDerivedWebPreviewState = function (state, prevState) {
|
|
884
|
-
var transports = state.transports, sdkVersion = state.sdkVersion, url = state.url;
|
|
885
|
-
if ((url && !prevState.url) ||
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
908
|
+
var transports = state.transports, sdkVersion = state.sdkVersion, url = state.url, webPlayerURL = state.webPlayerURL;
|
|
909
|
+
if ((url && !prevState.url) ||
|
|
910
|
+
sdkVersion !== prevState.sdkVersion ||
|
|
911
|
+
webPlayerURL !== prevState.webPlayerURL) {
|
|
912
|
+
state.webPreviewURL =
|
|
913
|
+
transports['webplayer'] && webPlayerURL
|
|
914
|
+
? webPlayer_1.getWebPlayerIFrameURL(webPlayerURL, sdkVersion, url, !!this.logger)
|
|
915
|
+
: undefined;
|
|
889
916
|
}
|
|
890
917
|
};
|
|
891
918
|
//
|
|
@@ -1102,13 +1129,13 @@ var Snack = /** @class */ (function () {
|
|
|
1102
1129
|
case 'STATUS_REPORT':
|
|
1103
1130
|
this.onStatusReportMessageReceived(connectedClientId, message);
|
|
1104
1131
|
break;
|
|
1105
|
-
// @ts-ignore: CODE is echoed by
|
|
1132
|
+
// @ts-ignore: CODE is echoed by pubsub, we ignore it
|
|
1106
1133
|
case 'CODE':
|
|
1107
1134
|
break;
|
|
1108
|
-
// @ts-ignore: RELOAD_SNACK is echoed by
|
|
1135
|
+
// @ts-ignore: RELOAD_SNACK is echoed by pubsub, we ignore it
|
|
1109
1136
|
case 'RELOAD_SNACK':
|
|
1110
1137
|
break;
|
|
1111
|
-
// @ts-ignore: REQUEST_STATUS is echoed by
|
|
1138
|
+
// @ts-ignore: REQUEST_STATUS is echoed by pubsub, we ignore it
|
|
1112
1139
|
case 'REQUEST_STATUS':
|
|
1113
1140
|
break;
|
|
1114
1141
|
default:
|