snack-sdk 3.7.0 → 3.8.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/build/DependencyResolver.d.ts +26 -25
  3. package/build/DependencyResolver.js +258 -257
  4. package/build/DependencyResolver.js.map +1 -1
  5. package/build/DevSession.d.ts +20 -20
  6. package/build/DevSession.js +203 -203
  7. package/build/FileUploader.d.ts +23 -22
  8. package/build/FileUploader.js +174 -174
  9. package/build/FileUploader.js.map +1 -1
  10. package/build/Logger.d.ts +11 -11
  11. package/build/Logger.js +33 -33
  12. package/build/Session.d.ts +301 -300
  13. package/build/Session.js +1171 -1171
  14. package/build/Session.js.map +1 -1
  15. package/build/State.d.ts +16 -16
  16. package/build/State.js +90 -90
  17. package/build/State.js.map +1 -1
  18. package/build/WantedVersions.d.ts +17 -16
  19. package/build/WantedVersions.js +93 -96
  20. package/build/WantedVersions.js.map +1 -1
  21. package/build/defaultConfig.d.ts +12 -13
  22. package/build/defaultConfig.js +29 -29
  23. package/build/defaultConfig.js.map +1 -1
  24. package/build/index.d.ts +7 -7
  25. package/build/index.js +30 -30
  26. package/build/index.js.map +1 -1
  27. package/build/transports/CodeMessageBuilder.d.ts +31 -31
  28. package/build/transports/CodeMessageBuilder.js +196 -196
  29. package/build/transports/CodeMessageBuilder.js.map +1 -1
  30. package/build/transports/Protocol.d.ts +64 -64
  31. package/build/transports/Protocol.js +2 -2
  32. package/build/transports/Protocol.js.map +1 -1
  33. package/build/transports/Transport.d.ts +27 -27
  34. package/build/transports/Transport.js +298 -298
  35. package/build/transports/index.d.ts +3 -3
  36. package/build/transports/index.js +22 -22
  37. package/build/transports/types.d.ts +63 -63
  38. package/build/transports/types.js +2 -2
  39. package/build/transports/types.js.map +1 -1
  40. package/build/transports/webPlayer.d.ts +12 -11
  41. package/build/transports/webPlayer.js +70 -70
  42. package/build/transports/webPlayer.js.map +1 -1
  43. package/build/types.d.ts +185 -258
  44. package/build/types.js +2 -2
  45. package/build/types.js.map +1 -1
  46. package/build/utils.d.ts +17 -16
  47. package/build/utils.js +68 -68
  48. package/build/utils.js.map +1 -1
  49. package/package.json +3 -2
  50. package/src/DependencyResolver.ts +11 -7
  51. package/src/FileUploader.ts +3 -1
  52. package/src/Session.ts +9 -6
  53. package/src/State.ts +1 -1
  54. package/src/WantedVersions.ts +3 -2
  55. package/src/defaultConfig.ts +5 -5
  56. package/src/index.ts +37 -9
  57. package/src/transports/CodeMessageBuilder.ts +7 -2
  58. package/src/transports/Protocol.ts +1 -1
  59. package/src/transports/types.ts +2 -1
  60. package/src/transports/webPlayer.ts +3 -1
  61. package/src/types.ts +8 -82
  62. package/src/utils.ts +2 -1
  63. package/build/sdk.d.ts +0 -34
  64. package/build/sdk.js +0 -139
  65. package/build/sdk.js.map +0 -1
  66. package/build/sdks/features.d.ts +0 -9
  67. package/build/sdks/features.js +0 -13
  68. package/build/sdks/features.js.map +0 -1
  69. package/build/sdks/index.d.ts +0 -5
  70. package/build/sdks/index.js +0 -124
  71. package/build/sdks/index.js.map +0 -1
  72. package/build/sdks/types.d.ts +0 -21
  73. package/build/sdks/types.js +0 -3
  74. package/build/sdks/types.js.map +0 -1
  75. package/src/sdk.ts +0 -135
  76. package/src/sdks/features.ts +0 -11
  77. package/src/sdks/index.ts +0 -159
  78. package/src/sdks/types.ts +0 -49
@@ -1,197 +1,197 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getFileDiff = void 0;
18
- var diff_1 = require("diff");
19
- var ua_parser_js_1 = require("ua-parser-js");
20
- var FileUploader_1 = __importDefault(require("../FileUploader"));
21
- var defaultConfig_1 = require("../defaultConfig");
22
- var sdk_1 = require("../sdk");
23
- var SnackIdentityCode = {
24
- files: defaultConfig_1.SnackIdentityState.files,
25
- dependencies: defaultConfig_1.SnackIdentityState.dependencies,
26
- sdkVersion: defaultConfig_1.SnackIdentityState.sdkVersion,
27
- };
28
- function getFileDiff(oldCode, newCode) {
29
- var patch = diff_1.createPatch('code', oldCode, newCode, '', '', {
30
- context: 0,
31
- });
32
- if (patch) {
33
- return patch;
34
- }
35
- else {
36
- throw new Error('Error creating a file diff');
37
- }
38
- }
39
- exports.getFileDiff = getFileDiff;
40
- var PLACEHOLDER_URL = 'https://snack-code-uploads.s3.us-west-1.amazonaws.com/~asset/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
41
- var CodeMessageBuilder = /** @class */ (function () {
42
- function CodeMessageBuilder(options) {
43
- var _this = this;
44
- this.code = SnackIdentityCode;
45
- this.placeholderURLs = {};
46
- this.uploadedURLs = {};
47
- this.onFileUploaded = function (request, resultURL, _error) {
48
- var path = request.path;
49
- delete _this.placeholderURLs[path];
50
- if (resultURL) {
51
- _this.uploadedURLs[path] = resultURL;
52
- if (!Object.keys(_this.placeholderURLs).length) {
53
- var codeMessage = _this.createCodeMessage(_this.code, _this.codeMessage, _this.code);
54
- if (_this.verifyCodeMessageSize(codeMessage)) {
55
- _this.callback(codeMessage, _this.code);
56
- }
57
- }
58
- }
59
- };
60
- this.logger = options.logger;
61
- this.callback = options.callback;
62
- this.verifyCodeMessageSize = options.verifyCodeMessageSize;
63
- this.maxDiffPlaceholder = options.maxDiffPlaceholder;
64
- this.codeUploader = options.apiURL
65
- ? new FileUploader_1.default({
66
- apiURL: options.apiURL,
67
- logger: options.logger,
68
- callback: this.onFileUploaded,
69
- })
70
- : undefined;
71
- }
72
- CodeMessageBuilder.prototype.setCode = function (code) {
73
- var _a, _b, _c;
74
- if (code === this.code) {
75
- return;
76
- }
77
- var prevCode = this.code;
78
- var files = code.files;
79
- this.code = code;
80
- // Cancel any uploads for files that were removed or changed
81
- for (var path in prevCode.files) {
82
- if (prevCode.files[path].contents !== ((_a = files[path]) === null || _a === void 0 ? void 0 : _a.contents)) {
83
- delete this.placeholderURLs[path];
84
- delete this.uploadedURLs[path];
85
- (_b = this.codeUploader) === null || _b === void 0 ? void 0 : _b.remove(path, prevCode.files[path]);
86
- }
87
- }
88
- // Generate code message
89
- var codeMessage = this.createCodeMessage(code, this.codeMessage, prevCode);
90
- this.codeMessage = codeMessage;
91
- // When the code message size is valid and there are no pending
92
- // uploads, then fire the callback immediately
93
- if (this.verifyCodeMessageSize(codeMessage)) {
94
- if (!Object.keys(this.placeholderURLs).length) {
95
- this.callback(codeMessage, code);
96
- }
97
- return;
98
- }
99
- // Upload files if the code message exceeds the limit
100
- // Sort code files by size
101
- if (this.codeUploader) {
102
- var paths = Object.keys(files)
103
- .filter(function (path) { return files[path].type === 'CODE'; })
104
- // @ts-ignore
105
- .sort(function (a, b) { return files[b].contents.length - files[a].contents.length; });
106
- // Upload the largest file
107
- for (var i = 0; i < paths.length; i++) {
108
- var path = paths[i];
109
- if (!this.uploadedURLs[path] && !this.placeholderURLs[path]) {
110
- var file = files[path];
111
- this.placeholderURLs[path] = PLACEHOLDER_URL;
112
- // this.logger?.comm('Uploading file', path, `, ${file.contents.length} bytes ...`);
113
- this.codeUploader.add(path, file);
114
- codeMessage.diff[path] = '';
115
- codeMessage.s3url[path] = this.placeholderURLs[path];
116
- if (this.verifyCodeMessageSize(codeMessage)) {
117
- // Message size is now valid. When the upload completes, it
118
- // will try to call the callback
119
- return;
120
- }
121
- }
122
- }
123
- }
124
- // Message is still too large
125
- (_c = this.logger) === null || _c === void 0 ? void 0 : _c.error('Message size is too large');
126
- };
127
- CodeMessageBuilder.prototype.createCodeMessage = function (code, prevCodeMessage, prevCode) {
128
- var files = code.files, dependencies = code.dependencies, sdkVersion = code.sdkVersion;
129
- var diff = __assign({}, files);
130
- var s3url = {};
131
- for (var path in files) {
132
- var file = files[path];
133
- if (this.uploadedURLs[path] || this.placeholderURLs[path]) {
134
- diff[path] = '';
135
- s3url[path] = this.uploadedURLs[path] || this.placeholderURLs[path];
136
- }
137
- else {
138
- if (file.type === 'CODE') {
139
- if ((prevCodeMessage === null || prevCodeMessage === void 0 ? void 0 : prevCodeMessage.diff[path]) &&
140
- (prevCode === null || prevCode === void 0 ? void 0 : prevCode.files[path].contents) === code.files[path].contents) {
141
- diff[path] = prevCodeMessage.diff[path];
142
- }
143
- else {
144
- if (this.maxDiffPlaceholder && file.contents.length >= this.maxDiffPlaceholder.length) {
145
- diff[path] = this.maxDiffPlaceholder;
146
- }
147
- else {
148
- diff[path] = getFileDiff('', file.contents);
149
- }
150
- }
151
- }
152
- else {
153
- diff[path] = '';
154
- }
155
- if (file.type === 'ASSET' && typeof file.contents === 'string') {
156
- s3url[path] = file.contents;
157
- }
158
- }
159
- }
160
- var deps = {};
161
- for (var name_1 in dependencies) {
162
- var dep = dependencies[name_1];
163
- if (dep.handle && !sdk_1.isModulePreloaded(name_1, sdkVersion)) {
164
- deps[name_1] = {
165
- version: dep.version,
166
- handle: dep.handle,
167
- // Resolved has been replaced by handle. It is still needed for pre SDK 37 runtimes
168
- resolved: dep.handle.substring(dep.handle.lastIndexOf('@') + 1),
169
- };
170
- }
171
- }
172
- var metadata = {
173
- expoSDKVersion: code.sdkVersion,
174
- };
175
- if (typeof navigator !== 'undefined' && navigator.userAgent) {
176
- var ua = new ua_parser_js_1.UAParser(navigator.userAgent).getResult();
177
- metadata.webHostName = window.location.hostname;
178
- metadata.webOSArchitecture = ua.cpu.architecture;
179
- metadata.webOSFamily = ua.os.name;
180
- metadata.webOSVersion = ua.os.version;
181
- metadata.webLayoutEngine = ua.engine.name;
182
- metadata.webDeviceType = ua.device.type;
183
- metadata.webBrowser = ua.browser.name;
184
- metadata.webBrowserVersion = ua.browser.version;
185
- }
186
- return {
187
- type: 'CODE',
188
- diff: diff,
189
- s3url: s3url,
190
- dependencies: deps,
191
- metadata: metadata,
192
- };
193
- };
194
- return CodeMessageBuilder;
195
- }());
196
- exports.default = CodeMessageBuilder;
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 __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getFileDiff = void 0;
18
+ var diff_1 = require("diff");
19
+ var snack_content_1 = require("snack-content");
20
+ var ua_parser_js_1 = require("ua-parser-js");
21
+ var FileUploader_1 = __importDefault(require("../FileUploader"));
22
+ var defaultConfig_1 = require("../defaultConfig");
23
+ var SnackIdentityCode = {
24
+ files: defaultConfig_1.SnackIdentityState.files,
25
+ dependencies: defaultConfig_1.SnackIdentityState.dependencies,
26
+ sdkVersion: defaultConfig_1.SnackIdentityState.sdkVersion,
27
+ };
28
+ function getFileDiff(oldCode, newCode) {
29
+ var patch = diff_1.createPatch('code', oldCode, newCode, '', '', {
30
+ context: 0,
31
+ });
32
+ if (patch) {
33
+ return patch;
34
+ }
35
+ else {
36
+ throw new Error('Error creating a file diff');
37
+ }
38
+ }
39
+ exports.getFileDiff = getFileDiff;
40
+ var PLACEHOLDER_URL = 'https://snack-code-uploads.s3.us-west-1.amazonaws.com/~asset/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
41
+ var CodeMessageBuilder = /** @class */ (function () {
42
+ function CodeMessageBuilder(options) {
43
+ var _this = this;
44
+ this.code = SnackIdentityCode;
45
+ this.placeholderURLs = {};
46
+ this.uploadedURLs = {};
47
+ this.onFileUploaded = function (request, resultURL, _error) {
48
+ var path = request.path;
49
+ delete _this.placeholderURLs[path];
50
+ if (resultURL) {
51
+ _this.uploadedURLs[path] = resultURL;
52
+ if (!Object.keys(_this.placeholderURLs).length) {
53
+ var codeMessage = _this.createCodeMessage(_this.code, _this.codeMessage, _this.code);
54
+ if (_this.verifyCodeMessageSize(codeMessage)) {
55
+ _this.callback(codeMessage, _this.code);
56
+ }
57
+ }
58
+ }
59
+ };
60
+ this.logger = options.logger;
61
+ this.callback = options.callback;
62
+ this.verifyCodeMessageSize = options.verifyCodeMessageSize;
63
+ this.maxDiffPlaceholder = options.maxDiffPlaceholder;
64
+ this.codeUploader = options.apiURL
65
+ ? new FileUploader_1.default({
66
+ apiURL: options.apiURL,
67
+ logger: options.logger,
68
+ callback: this.onFileUploaded,
69
+ })
70
+ : undefined;
71
+ }
72
+ CodeMessageBuilder.prototype.setCode = function (code) {
73
+ var _a, _b, _c;
74
+ if (code === this.code) {
75
+ return;
76
+ }
77
+ var prevCode = this.code;
78
+ var files = code.files;
79
+ this.code = code;
80
+ // Cancel any uploads for files that were removed or changed
81
+ for (var path in prevCode.files) {
82
+ if (prevCode.files[path].contents !== ((_a = files[path]) === null || _a === void 0 ? void 0 : _a.contents)) {
83
+ delete this.placeholderURLs[path];
84
+ delete this.uploadedURLs[path];
85
+ (_b = this.codeUploader) === null || _b === void 0 ? void 0 : _b.remove(path, prevCode.files[path]);
86
+ }
87
+ }
88
+ // Generate code message
89
+ var codeMessage = this.createCodeMessage(code, this.codeMessage, prevCode);
90
+ this.codeMessage = codeMessage;
91
+ // When the code message size is valid and there are no pending
92
+ // uploads, then fire the callback immediately
93
+ if (this.verifyCodeMessageSize(codeMessage)) {
94
+ if (!Object.keys(this.placeholderURLs).length) {
95
+ this.callback(codeMessage, code);
96
+ }
97
+ return;
98
+ }
99
+ // Upload files if the code message exceeds the limit
100
+ // Sort code files by size
101
+ if (this.codeUploader) {
102
+ var paths = Object.keys(files)
103
+ .filter(function (path) { return files[path].type === 'CODE'; })
104
+ // @ts-ignore
105
+ .sort(function (a, b) { return files[b].contents.length - files[a].contents.length; });
106
+ // Upload the largest file
107
+ for (var i = 0; i < paths.length; i++) {
108
+ var path = paths[i];
109
+ if (!this.uploadedURLs[path] && !this.placeholderURLs[path]) {
110
+ var file = files[path];
111
+ this.placeholderURLs[path] = PLACEHOLDER_URL;
112
+ // this.logger?.comm('Uploading file', path, `, ${file.contents.length} bytes ...`);
113
+ this.codeUploader.add(path, file);
114
+ codeMessage.diff[path] = '';
115
+ codeMessage.s3url[path] = this.placeholderURLs[path];
116
+ if (this.verifyCodeMessageSize(codeMessage)) {
117
+ // Message size is now valid. When the upload completes, it
118
+ // will try to call the callback
119
+ return;
120
+ }
121
+ }
122
+ }
123
+ }
124
+ // Message is still too large
125
+ (_c = this.logger) === null || _c === void 0 ? void 0 : _c.error('Message size is too large');
126
+ };
127
+ CodeMessageBuilder.prototype.createCodeMessage = function (code, prevCodeMessage, prevCode) {
128
+ var files = code.files, dependencies = code.dependencies, sdkVersion = code.sdkVersion;
129
+ var diff = __assign({}, files);
130
+ var s3url = {};
131
+ for (var path in files) {
132
+ var file = files[path];
133
+ if (this.uploadedURLs[path] || this.placeholderURLs[path]) {
134
+ diff[path] = '';
135
+ s3url[path] = this.uploadedURLs[path] || this.placeholderURLs[path];
136
+ }
137
+ else {
138
+ if (file.type === 'CODE') {
139
+ if ((prevCodeMessage === null || prevCodeMessage === void 0 ? void 0 : prevCodeMessage.diff[path]) &&
140
+ (prevCode === null || prevCode === void 0 ? void 0 : prevCode.files[path].contents) === code.files[path].contents) {
141
+ diff[path] = prevCodeMessage.diff[path];
142
+ }
143
+ else {
144
+ if (this.maxDiffPlaceholder && file.contents.length >= this.maxDiffPlaceholder.length) {
145
+ diff[path] = this.maxDiffPlaceholder;
146
+ }
147
+ else {
148
+ diff[path] = getFileDiff('', file.contents);
149
+ }
150
+ }
151
+ }
152
+ else {
153
+ diff[path] = '';
154
+ }
155
+ if (file.type === 'ASSET' && typeof file.contents === 'string') {
156
+ s3url[path] = file.contents;
157
+ }
158
+ }
159
+ }
160
+ var deps = {};
161
+ for (var name_1 in dependencies) {
162
+ var dep = dependencies[name_1];
163
+ if (dep.handle && !snack_content_1.isModulePreloaded(name_1, sdkVersion)) {
164
+ deps[name_1] = {
165
+ version: dep.version,
166
+ handle: dep.handle,
167
+ // Resolved has been replaced by handle. It is still needed for pre SDK 37 runtimes
168
+ resolved: dep.handle.substring(dep.handle.lastIndexOf('@') + 1),
169
+ };
170
+ }
171
+ }
172
+ var metadata = {
173
+ expoSDKVersion: code.sdkVersion,
174
+ };
175
+ if (typeof navigator !== 'undefined' && navigator.userAgent) {
176
+ var ua = new ua_parser_js_1.UAParser(navigator.userAgent).getResult();
177
+ metadata.webHostName = window.location.hostname;
178
+ metadata.webOSArchitecture = ua.cpu.architecture;
179
+ metadata.webOSFamily = ua.os.name;
180
+ metadata.webOSVersion = ua.os.version;
181
+ metadata.webLayoutEngine = ua.engine.name;
182
+ metadata.webDeviceType = ua.device.type;
183
+ metadata.webBrowser = ua.browser.name;
184
+ metadata.webBrowserVersion = ua.browser.version;
185
+ }
186
+ return {
187
+ type: 'CODE',
188
+ diff: diff,
189
+ s3url: s3url,
190
+ dependencies: deps,
191
+ metadata: metadata,
192
+ };
193
+ };
194
+ return CodeMessageBuilder;
195
+ }());
196
+ exports.default = CodeMessageBuilder;
197
197
  //# sourceMappingURL=CodeMessageBuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeMessageBuilder.js","sourceRoot":"","sources":["../../src/transports/CodeMessageBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6BAAmC;AACnC,6CAAwC;AAExC,iEAAqE;AAErE,kDAAsD;AACtD,8BAA2C;AAU3C,IAAM,iBAAiB,GAAc;IACnC,KA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EAAE,IAAI,CAAC,UAAU;SAGhC,CAAC;QACF,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,SAAS,EAAE;YAC3D,IAAM,EAAE,GAAG,IAAI,uBAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC;YACzD,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAChD,QAAQ,CAAC,iBAAiB,GAAG,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC;YACjD,QAAQ,CAAC,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;YAClC,QAAQ,CAAC,YAAY,GAAG,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC;YACtC,QAAQ,CAAC,eAAe,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YAC1C,QAAQ,CAAC,aAAa,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YACxC,QAAQ,CAAC,UAAU,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;YACtC,QAAQ,CAAC,iBAAiB,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;SACjD;QAED,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,IAAI,MAAA;YACJ,KAAK,OAAA;YACL,YAAY,EAAE,IAAI;YAClB,QAAQ,UAAA;SACT,CAAC;IACJ,CAAC;IAeH,yBAAC;AAAD,CAAC,AAtLD,IAsLC","sourcesContent":["import { createPatch } from 'diff';\nimport { UAParser } from 'ua-parser-js';\n\nimport FileUploader, { FileUploaderCallback } from '../FileUploader';\nimport { Logger } from '../Logger';\nimport { SnackIdentityState } from '../defaultConfig';\nimport { isModulePreloaded } from '../sdk';\nimport { SnackFiles, SDKVersion, SnackCodeFile, SnackDependencies } from '../types';\nimport { ProtocolCodeMessage, ProtocolCodeMessageDependencies } from './Protocol';\n\nexport type SnackCode = {\n files: SnackFiles;\n dependencies: SnackDependencies;\n sdkVersion: SDKVersion;\n};\n\nconst SnackIdentityCode: SnackCode = {\n files: SnackIdentityState.files,\n dependencies: SnackIdentityState.dependencies,\n sdkVersion: SnackIdentityState.sdkVersion,\n};\n\nexport type CodeMessageBuilderCallback = (codeMessage: ProtocolCodeMessage, code: SnackCode) => any;\n\nexport function getFileDiff(oldCode: string, newCode: string): string {\n const patch = createPatch('code', oldCode, newCode, '', '', {\n context: 0,\n });\n if (patch) {\n return patch;\n } else {\n throw new Error('Error creating a file diff');\n }\n}\n\nconst PLACEHOLDER_URL =\n 'https://snack-code-uploads.s3.us-west-1.amazonaws.com/~asset/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';\n\nexport default class CodeMessageBuilder {\n private callback: CodeMessageBuilderCallback;\n private code: SnackCode = SnackIdentityCode;\n private codeMessage?: ProtocolCodeMessage;\n private logger?: Logger;\n private codeUploader?: FileUploader;\n private maxDiffPlaceholder?: string;\n private placeholderURLs: { [path: string]: string } = {};\n private uploadedURLs: { [path: string]: string } = {};\n private verifyCodeMessageSize: (message: ProtocolCodeMessage) => boolean;\n\n constructor(options: {\n callback: CodeMessageBuilderCallback;\n verifyCodeMessageSize: (message: ProtocolCodeMessage) => boolean;\n apiURL?: string;\n logger?: Logger;\n maxDiffPlaceholder?: string;\n }) {\n this.logger = options.logger;\n this.callback = options.callback;\n this.verifyCodeMessageSize = options.verifyCodeMessageSize;\n this.maxDiffPlaceholder = options.maxDiffPlaceholder;\n this.codeUploader = options.apiURL\n ? new FileUploader({\n apiURL: options.apiURL,\n logger: options.logger,\n callback: this.onFileUploaded,\n })\n : undefined;\n }\n\n setCode(code: SnackCode) {\n if (code === this.code) {\n return;\n }\n\n const prevCode = this.code;\n const { files } = code;\n this.code = code;\n\n // Cancel any uploads for files that were removed or changed\n for (const path in prevCode.files) {\n if (prevCode.files[path].contents !== files[path]?.contents) {\n delete this.placeholderURLs[path];\n delete this.uploadedURLs[path];\n this.codeUploader?.remove(path, prevCode.files[path]);\n }\n }\n\n // Generate code message\n const codeMessage = this.createCodeMessage(code, this.codeMessage, prevCode);\n this.codeMessage = codeMessage;\n\n // When the code message size is valid and there are no pending\n // uploads, then fire the callback immediately\n if (this.verifyCodeMessageSize(codeMessage)) {\n if (!Object.keys(this.placeholderURLs).length) {\n this.callback(codeMessage, code);\n }\n return;\n }\n\n // Upload files if the code message exceeds the limit\n // Sort code files by size\n if (this.codeUploader) {\n const paths = Object.keys(files)\n .filter((path) => files[path].type === 'CODE')\n // @ts-ignore\n .sort((a, b) => files[b].contents.length - files[a].contents.length);\n\n // Upload the largest file\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i];\n if (!this.uploadedURLs[path] && !this.placeholderURLs[path]) {\n const file: SnackCodeFile = files[path] as any;\n this.placeholderURLs[path] = PLACEHOLDER_URL;\n // this.logger?.comm('Uploading file', path, `, ${file.contents.length} bytes ...`);\n this.codeUploader.add(path, file);\n codeMessage.diff[path] = '';\n codeMessage.s3url[path] = this.placeholderURLs[path];\n if (this.verifyCodeMessageSize(codeMessage)) {\n // Message size is now valid. When the upload completes, it\n // will try to call the callback\n return;\n }\n }\n }\n }\n\n // Message is still too large\n this.logger?.error('Message size is too large');\n }\n\n private createCodeMessage(\n code: SnackCode,\n prevCodeMessage?: ProtocolCodeMessage,\n prevCode?: SnackCode\n ): ProtocolCodeMessage {\n const { files, dependencies, sdkVersion } = code;\n\n const diff: any = { ...files };\n const s3url: any = {};\n for (const path in files) {\n const file = files[path];\n if (this.uploadedURLs[path] || this.placeholderURLs[path]) {\n diff[path] = '';\n s3url[path] = this.uploadedURLs[path] || this.placeholderURLs[path];\n } else {\n if (file.type === 'CODE') {\n if (\n prevCodeMessage?.diff[path] &&\n prevCode?.files[path].contents === code.files[path].contents\n ) {\n diff[path] = prevCodeMessage.diff[path];\n } else {\n if (this.maxDiffPlaceholder && file.contents.length >= this.maxDiffPlaceholder.length) {\n diff[path] = this.maxDiffPlaceholder;\n } else {\n diff[path] = getFileDiff('', file.contents);\n }\n }\n } else {\n diff[path] = '';\n }\n if (file.type === 'ASSET' && typeof file.contents === 'string') {\n s3url[path] = file.contents;\n }\n }\n }\n\n const deps: ProtocolCodeMessageDependencies = {};\n for (const name in dependencies) {\n const dep = dependencies[name];\n if (dep.handle && !isModulePreloaded(name, sdkVersion)) {\n deps[name] = {\n version: dep.version,\n handle: dep.handle,\n // Resolved has been replaced by handle. It is still needed for pre SDK 37 runtimes\n resolved: dep.handle.substring(dep.handle.lastIndexOf('@') + 1),\n };\n }\n }\n\n const metadata: any = {\n expoSDKVersion: code.sdkVersion,\n // TODO: restore sdk version field\n // webSnackSDKVersion: require('../../package.json').version,\n };\n if (typeof navigator !== 'undefined' && navigator.userAgent) {\n const ua = new UAParser(navigator.userAgent).getResult();\n metadata.webHostName = window.location.hostname;\n metadata.webOSArchitecture = ua.cpu.architecture;\n metadata.webOSFamily = ua.os.name;\n metadata.webOSVersion = ua.os.version;\n metadata.webLayoutEngine = ua.engine.name;\n metadata.webDeviceType = ua.device.type;\n metadata.webBrowser = ua.browser.name;\n metadata.webBrowserVersion = ua.browser.version;\n }\n\n return {\n type: 'CODE',\n diff,\n s3url,\n dependencies: deps,\n metadata,\n };\n }\n\n private onFileUploaded: FileUploaderCallback = (request, resultURL, _error) => {\n const { path } = request;\n delete this.placeholderURLs[path];\n if (resultURL) {\n this.uploadedURLs[path] = resultURL;\n if (!Object.keys(this.placeholderURLs).length) {\n const codeMessage = this.createCodeMessage(this.code, this.codeMessage, this.code);\n if (this.verifyCodeMessageSize(codeMessage)) {\n this.callback(codeMessage, this.code);\n }\n }\n }\n };\n}\n"]}
1
+ {"version":3,"file":"CodeMessageBuilder.js","sourceRoot":"","sources":["../../src/transports/CodeMessageBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6BAAmC;AACnC,+CAMuB;AACvB,6CAAwC;AAExC,iEAAqE;AAErE,kDAAsD;AAStD,IAAM,iBAAiB,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;YACpB,cAAc,EAAE,IAAI,CAAC,UAAU;SAGhC,CAAC;QACF,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,CAAC,SAAS,EAAE;YAC3D,IAAM,EAAE,GAAG,IAAI,uBAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,CAAC;YACzD,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAChD,QAAQ,CAAC,iBAAiB,GAAG,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC;YACjD,QAAQ,CAAC,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC;YAClC,QAAQ,CAAC,YAAY,GAAG,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC;YACtC,QAAQ,CAAC,eAAe,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YAC1C,QAAQ,CAAC,aAAa,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YACxC,QAAQ,CAAC,UAAU,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;YACtC,QAAQ,CAAC,iBAAiB,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;SACjD;QAED,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,IAAI,MAAA;YACJ,KAAK,OAAA;YACL,YAAY,EAAE,IAAI;YAClB,QAAQ,UAAA;SACT,CAAC;IACJ,CAAC;IAeH,yBAAC;AAAD,CAAC,AAtLD,IAsLC","sourcesContent":["import { createPatch } from 'diff';\nimport {\n SnackFiles,\n SDKVersion,\n SnackCodeFile,\n SnackDependencies,\n isModulePreloaded,\n} from 'snack-content';\nimport { UAParser } from 'ua-parser-js';\n\nimport FileUploader, { FileUploaderCallback } from '../FileUploader';\nimport { Logger } from '../Logger';\nimport { SnackIdentityState } from '../defaultConfig';\nimport { ProtocolCodeMessage, ProtocolCodeMessageDependencies } from './Protocol';\n\nexport type SnackCode = {\n files: SnackFiles;\n dependencies: SnackDependencies;\n sdkVersion: SDKVersion;\n};\n\nconst SnackIdentityCode: SnackCode = {\n files: SnackIdentityState.files,\n dependencies: SnackIdentityState.dependencies,\n sdkVersion: SnackIdentityState.sdkVersion,\n};\n\nexport type CodeMessageBuilderCallback = (codeMessage: ProtocolCodeMessage, code: SnackCode) => any;\n\nexport function getFileDiff(oldCode: string, newCode: string): string {\n const patch = createPatch('code', oldCode, newCode, '', '', {\n context: 0,\n });\n if (patch) {\n return patch;\n } else {\n throw new Error('Error creating a file diff');\n }\n}\n\nconst PLACEHOLDER_URL =\n 'https://snack-code-uploads.s3.us-west-1.amazonaws.com/~asset/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';\n\nexport default class CodeMessageBuilder {\n private callback: CodeMessageBuilderCallback;\n private code: SnackCode = SnackIdentityCode;\n private codeMessage?: ProtocolCodeMessage;\n private logger?: Logger;\n private codeUploader?: FileUploader;\n private maxDiffPlaceholder?: string;\n private placeholderURLs: { [path: string]: string } = {};\n private uploadedURLs: { [path: string]: string } = {};\n private verifyCodeMessageSize: (message: ProtocolCodeMessage) => boolean;\n\n constructor(options: {\n callback: CodeMessageBuilderCallback;\n verifyCodeMessageSize: (message: ProtocolCodeMessage) => boolean;\n apiURL?: string;\n logger?: Logger;\n maxDiffPlaceholder?: string;\n }) {\n this.logger = options.logger;\n this.callback = options.callback;\n this.verifyCodeMessageSize = options.verifyCodeMessageSize;\n this.maxDiffPlaceholder = options.maxDiffPlaceholder;\n this.codeUploader = options.apiURL\n ? new FileUploader({\n apiURL: options.apiURL,\n logger: options.logger,\n callback: this.onFileUploaded,\n })\n : undefined;\n }\n\n setCode(code: SnackCode) {\n if (code === this.code) {\n return;\n }\n\n const prevCode = this.code;\n const { files } = code;\n this.code = code;\n\n // Cancel any uploads for files that were removed or changed\n for (const path in prevCode.files) {\n if (prevCode.files[path].contents !== files[path]?.contents) {\n delete this.placeholderURLs[path];\n delete this.uploadedURLs[path];\n this.codeUploader?.remove(path, prevCode.files[path]);\n }\n }\n\n // Generate code message\n const codeMessage = this.createCodeMessage(code, this.codeMessage, prevCode);\n this.codeMessage = codeMessage;\n\n // When the code message size is valid and there are no pending\n // uploads, then fire the callback immediately\n if (this.verifyCodeMessageSize(codeMessage)) {\n if (!Object.keys(this.placeholderURLs).length) {\n this.callback(codeMessage, code);\n }\n return;\n }\n\n // Upload files if the code message exceeds the limit\n // Sort code files by size\n if (this.codeUploader) {\n const paths = Object.keys(files)\n .filter((path) => files[path].type === 'CODE')\n // @ts-ignore\n .sort((a, b) => files[b].contents.length - files[a].contents.length);\n\n // Upload the largest file\n for (let i = 0; i < paths.length; i++) {\n const path = paths[i];\n if (!this.uploadedURLs[path] && !this.placeholderURLs[path]) {\n const file: SnackCodeFile = files[path] as any;\n this.placeholderURLs[path] = PLACEHOLDER_URL;\n // this.logger?.comm('Uploading file', path, `, ${file.contents.length} bytes ...`);\n this.codeUploader.add(path, file);\n codeMessage.diff[path] = '';\n codeMessage.s3url[path] = this.placeholderURLs[path];\n if (this.verifyCodeMessageSize(codeMessage)) {\n // Message size is now valid. When the upload completes, it\n // will try to call the callback\n return;\n }\n }\n }\n }\n\n // Message is still too large\n this.logger?.error('Message size is too large');\n }\n\n private createCodeMessage(\n code: SnackCode,\n prevCodeMessage?: ProtocolCodeMessage,\n prevCode?: SnackCode\n ): ProtocolCodeMessage {\n const { files, dependencies, sdkVersion } = code;\n\n const diff: any = { ...files };\n const s3url: any = {};\n for (const path in files) {\n const file = files[path];\n if (this.uploadedURLs[path] || this.placeholderURLs[path]) {\n diff[path] = '';\n s3url[path] = this.uploadedURLs[path] || this.placeholderURLs[path];\n } else {\n if (file.type === 'CODE') {\n if (\n prevCodeMessage?.diff[path] &&\n prevCode?.files[path].contents === code.files[path].contents\n ) {\n diff[path] = prevCodeMessage.diff[path];\n } else {\n if (this.maxDiffPlaceholder && file.contents.length >= this.maxDiffPlaceholder.length) {\n diff[path] = this.maxDiffPlaceholder;\n } else {\n diff[path] = getFileDiff('', file.contents);\n }\n }\n } else {\n diff[path] = '';\n }\n if (file.type === 'ASSET' && typeof file.contents === 'string') {\n s3url[path] = file.contents;\n }\n }\n }\n\n const deps: ProtocolCodeMessageDependencies = {};\n for (const name in dependencies) {\n const dep = dependencies[name];\n if (dep.handle && !isModulePreloaded(name, sdkVersion)) {\n deps[name] = {\n version: dep.version,\n handle: dep.handle,\n // Resolved has been replaced by handle. It is still needed for pre SDK 37 runtimes\n resolved: dep.handle.substring(dep.handle.lastIndexOf('@') + 1),\n };\n }\n }\n\n const metadata: any = {\n expoSDKVersion: code.sdkVersion,\n // TODO: restore sdk version field\n // webSnackSDKVersion: require('../../package.json').version,\n };\n if (typeof navigator !== 'undefined' && navigator.userAgent) {\n const ua = new UAParser(navigator.userAgent).getResult();\n metadata.webHostName = window.location.hostname;\n metadata.webOSArchitecture = ua.cpu.architecture;\n metadata.webOSFamily = ua.os.name;\n metadata.webOSVersion = ua.os.version;\n metadata.webLayoutEngine = ua.engine.name;\n metadata.webDeviceType = ua.device.type;\n metadata.webBrowser = ua.browser.name;\n metadata.webBrowserVersion = ua.browser.version;\n }\n\n return {\n type: 'CODE',\n diff,\n s3url,\n dependencies: deps,\n metadata,\n };\n }\n\n private onFileUploaded: FileUploaderCallback = (request, resultURL, _error) => {\n const { path } = request;\n delete this.placeholderURLs[path];\n if (resultURL) {\n this.uploadedURLs[path] = resultURL;\n if (!Object.keys(this.placeholderURLs).length) {\n const codeMessage = this.createCodeMessage(this.code, this.codeMessage, this.code);\n if (this.verifyCodeMessageSize(codeMessage)) {\n this.callback(codeMessage, this.code);\n }\n }\n }\n };\n}\n"]}
@@ -1,64 +1,64 @@
1
- import { SDKVersion } from '../sdks/types';
2
- export declare type Device = {
3
- name: string;
4
- id: string;
5
- platform: string;
6
- };
7
- export declare type ProtocolConsoleMessage = {
8
- type: 'CONSOLE';
9
- device: Device;
10
- method: 'log' | 'error' | 'warn';
11
- payload: any[];
12
- };
13
- export declare type ProtocolErrorMessage = {
14
- type: 'ERROR';
15
- error: string;
16
- device: Device;
17
- };
18
- export declare type ProtocolResendCodeMessage = {
19
- type: 'RESEND_CODE';
20
- device: Device;
21
- };
22
- export declare type ProtocolCodeMessageDependencies = {
23
- [name: string]: {
24
- version: string;
25
- resolved: string;
26
- handle: string;
27
- };
28
- };
29
- export declare type ProtocolCodeMessage = {
30
- type: 'CODE';
31
- diff: {
32
- [path: string]: string;
33
- };
34
- s3url: {
35
- [path: string]: string;
36
- };
37
- dependencies: ProtocolCodeMessageDependencies;
38
- metadata: {
39
- expoSDKVersion: SDKVersion;
40
- webSnackSDKVersion: string;
41
- webHostname?: string;
42
- webOSArchitecture?: string;
43
- webOSFamily?: string;
44
- webOSVersion?: string;
45
- webLayoutEngine?: string;
46
- webDeviceType?: string;
47
- webBrowser?: string;
48
- webBrowserVersion?: string;
49
- webDescription?: string;
50
- };
51
- };
52
- export declare type ProtocolReloadMessage = {
53
- type: 'RELOAD_SNACK';
54
- };
55
- export declare type ProtocolRequestStatusMessage = {
56
- type: 'REQUEST_STATUS';
57
- };
58
- export declare type ProtocolStatusMessage = {
59
- type: 'STATUS_REPORT';
60
- previewLocation: string;
61
- status: 'FAILURE' | 'SUCCESS';
62
- };
63
- export declare type ProtocolOutgoingMessage = ProtocolCodeMessage | ProtocolReloadMessage | ProtocolRequestStatusMessage;
64
- export declare type ProtocolIncomingMessage = ProtocolConsoleMessage | ProtocolErrorMessage | ProtocolResendCodeMessage | ProtocolStatusMessage;
1
+ import { SDKVersion } from 'snack-content';
2
+ export declare type Device = {
3
+ name: string;
4
+ id: string;
5
+ platform: string;
6
+ };
7
+ export declare type ProtocolConsoleMessage = {
8
+ type: 'CONSOLE';
9
+ device: Device;
10
+ method: 'log' | 'error' | 'warn';
11
+ payload: any[];
12
+ };
13
+ export declare type ProtocolErrorMessage = {
14
+ type: 'ERROR';
15
+ error: string;
16
+ device: Device;
17
+ };
18
+ export declare type ProtocolResendCodeMessage = {
19
+ type: 'RESEND_CODE';
20
+ device: Device;
21
+ };
22
+ export declare type ProtocolCodeMessageDependencies = {
23
+ [name: string]: {
24
+ version: string;
25
+ resolved: string;
26
+ handle: string;
27
+ };
28
+ };
29
+ export declare type ProtocolCodeMessage = {
30
+ type: 'CODE';
31
+ diff: {
32
+ [path: string]: string;
33
+ };
34
+ s3url: {
35
+ [path: string]: string;
36
+ };
37
+ dependencies: ProtocolCodeMessageDependencies;
38
+ metadata: {
39
+ expoSDKVersion: SDKVersion;
40
+ webSnackSDKVersion: string;
41
+ webHostname?: string;
42
+ webOSArchitecture?: string;
43
+ webOSFamily?: string;
44
+ webOSVersion?: string;
45
+ webLayoutEngine?: string;
46
+ webDeviceType?: string;
47
+ webBrowser?: string;
48
+ webBrowserVersion?: string;
49
+ webDescription?: string;
50
+ };
51
+ };
52
+ export declare type ProtocolReloadMessage = {
53
+ type: 'RELOAD_SNACK';
54
+ };
55
+ export declare type ProtocolRequestStatusMessage = {
56
+ type: 'REQUEST_STATUS';
57
+ };
58
+ export declare type ProtocolStatusMessage = {
59
+ type: 'STATUS_REPORT';
60
+ previewLocation: string;
61
+ status: 'FAILURE' | 'SUCCESS';
62
+ };
63
+ export declare type ProtocolOutgoingMessage = ProtocolCodeMessage | ProtocolReloadMessage | ProtocolRequestStatusMessage;
64
+ export declare type ProtocolIncomingMessage = ProtocolConsoleMessage | ProtocolErrorMessage | ProtocolResendCodeMessage | ProtocolStatusMessage;
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=Protocol.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Protocol.js","sourceRoot":"","sources":["../../src/transports/Protocol.ts"],"names":[],"mappings":"","sourcesContent":["import { SDKVersion } from '../sdks/types';\n\nexport type Device = {\n name: string;\n id: string;\n platform: string;\n};\n\nexport type ProtocolConsoleMessage = {\n type: 'CONSOLE';\n device: Device;\n method: 'log' | 'error' | 'warn';\n payload: any[];\n};\n\nexport type ProtocolErrorMessage = {\n type: 'ERROR';\n error: string; // e.g. `{message: \"my error\", stack: \"...\"}`\n device: Device;\n};\n\nexport type ProtocolResendCodeMessage = {\n type: 'RESEND_CODE';\n device: Device;\n};\n\nexport type ProtocolCodeMessageDependencies = {\n [name: string]: {\n version: string; // original version\n resolved: string; // resolved version\n handle: string; // snackager handle\n };\n};\n\nexport type ProtocolCodeMessage = {\n type: 'CODE';\n diff: { [path: string]: string };\n s3url: { [path: string]: string };\n dependencies: ProtocolCodeMessageDependencies;\n metadata: {\n expoSDKVersion: SDKVersion;\n webSnackSDKVersion: string;\n webHostname?: string; // window.location.hostname,\n webOSArchitecture?: string; // os.architecture,\n webOSFamily?: string; // os.family,\n webOSVersion?: string; // os.version,\n webLayoutEngine?: string; // platformInfo.layout,\n webDeviceType?: string; // platformInfo.product,\n webBrowser?: string; // platformInfo.name,\n webBrowserVersion?: string; // platformInfo.version,\n webDescription?: string; // platformInfo.description,\n };\n};\n\nexport type ProtocolReloadMessage = {\n type: 'RELOAD_SNACK';\n};\n\nexport type ProtocolRequestStatusMessage = {\n type: 'REQUEST_STATUS';\n};\n\nexport type ProtocolStatusMessage = {\n type: 'STATUS_REPORT';\n previewLocation: string;\n status: 'FAILURE' | 'SUCCESS';\n};\n\nexport type ProtocolOutgoingMessage =\n | ProtocolCodeMessage\n | ProtocolReloadMessage\n | ProtocolRequestStatusMessage;\n\nexport type ProtocolIncomingMessage =\n | ProtocolConsoleMessage\n | ProtocolErrorMessage\n | ProtocolResendCodeMessage\n | ProtocolStatusMessage;\n"]}
1
+ {"version":3,"file":"Protocol.js","sourceRoot":"","sources":["../../src/transports/Protocol.ts"],"names":[],"mappings":"","sourcesContent":["import { SDKVersion } from 'snack-content';\n\nexport type Device = {\n name: string;\n id: string;\n platform: string;\n};\n\nexport type ProtocolConsoleMessage = {\n type: 'CONSOLE';\n device: Device;\n method: 'log' | 'error' | 'warn';\n payload: any[];\n};\n\nexport type ProtocolErrorMessage = {\n type: 'ERROR';\n error: string; // e.g. `{message: \"my error\", stack: \"...\"}`\n device: Device;\n};\n\nexport type ProtocolResendCodeMessage = {\n type: 'RESEND_CODE';\n device: Device;\n};\n\nexport type ProtocolCodeMessageDependencies = {\n [name: string]: {\n version: string; // original version\n resolved: string; // resolved version\n handle: string; // snackager handle\n };\n};\n\nexport type ProtocolCodeMessage = {\n type: 'CODE';\n diff: { [path: string]: string };\n s3url: { [path: string]: string };\n dependencies: ProtocolCodeMessageDependencies;\n metadata: {\n expoSDKVersion: SDKVersion;\n webSnackSDKVersion: string;\n webHostname?: string; // window.location.hostname,\n webOSArchitecture?: string; // os.architecture,\n webOSFamily?: string; // os.family,\n webOSVersion?: string; // os.version,\n webLayoutEngine?: string; // platformInfo.layout,\n webDeviceType?: string; // platformInfo.product,\n webBrowser?: string; // platformInfo.name,\n webBrowserVersion?: string; // platformInfo.version,\n webDescription?: string; // platformInfo.description,\n };\n};\n\nexport type ProtocolReloadMessage = {\n type: 'RELOAD_SNACK';\n};\n\nexport type ProtocolRequestStatusMessage = {\n type: 'REQUEST_STATUS';\n};\n\nexport type ProtocolStatusMessage = {\n type: 'STATUS_REPORT';\n previewLocation: string;\n status: 'FAILURE' | 'SUCCESS';\n};\n\nexport type ProtocolOutgoingMessage =\n | ProtocolCodeMessage\n | ProtocolReloadMessage\n | ProtocolRequestStatusMessage;\n\nexport type ProtocolIncomingMessage =\n | ProtocolConsoleMessage\n | ProtocolErrorMessage\n | ProtocolResendCodeMessage\n | ProtocolStatusMessage;\n"]}