snack-sdk 3.8.0 → 3.9.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 +22 -0
- 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 +301 -301
- package/build/Session.js +1172 -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 +185 -185
- package/build/types.js +2 -2
- 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/types.d.ts
CHANGED
|
@@ -1,185 +1,185 @@
|
|
|
1
|
-
import { SDKVersion, SnackDependencies, SnackDependencyVersions, SnackFiles, SnackMissingDependencies } from 'snack-content';
|
|
2
|
-
import { SnackTransport } from './transports';
|
|
3
|
-
/**
|
|
4
|
-
* An error that can optionally hold a file-name and line/column location.
|
|
5
|
-
*/
|
|
6
|
-
export interface SnackError extends Error {
|
|
7
|
-
fileName?: string;
|
|
8
|
-
lineNumber?: number;
|
|
9
|
-
columnNumber?: number;
|
|
10
|
-
}
|
|
11
|
-
export declare type SnackConnectedClientStatus = 'ok' | 'error' | 'reloading';
|
|
12
|
-
/**
|
|
13
|
-
* Client which connected to the Snack.
|
|
14
|
-
*
|
|
15
|
-
* Clients are only able to connect when the Snack is `online`.
|
|
16
|
-
*/
|
|
17
|
-
export declare type SnackConnectedClient = {
|
|
18
|
-
transport: string;
|
|
19
|
-
id: string;
|
|
20
|
-
name: string;
|
|
21
|
-
platform: string;
|
|
22
|
-
status: SnackConnectedClientStatus;
|
|
23
|
-
error?: SnackError;
|
|
24
|
-
previewURL?: string;
|
|
25
|
-
previewTimestamp?: number;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Collection of connected clients.
|
|
29
|
-
*/
|
|
30
|
-
export declare type SnackConnectedClients = {
|
|
31
|
-
[key: string]: SnackConnectedClient;
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* User that is used for communicating with the Expo servers.
|
|
35
|
-
*/
|
|
36
|
-
export declare type SnackUser = {
|
|
37
|
-
sessionSecret?: string;
|
|
38
|
-
accessToken?: string;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Request data to be used with the `sendBeacon` API.
|
|
42
|
-
*/
|
|
43
|
-
export declare type SnackSendBeaconRequest = {
|
|
44
|
-
url: string;
|
|
45
|
-
data: any;
|
|
46
|
-
};
|
|
47
|
-
export declare type SnackListenerSubscription = () => any;
|
|
48
|
-
/**
|
|
49
|
-
* Log data for when a connected client calls one of the
|
|
50
|
-
* `console.[log,info,warn,error]` to log information to the
|
|
51
|
-
* console.
|
|
52
|
-
*/
|
|
53
|
-
export declare type SnackLogEvent = {
|
|
54
|
-
type: 'error' | 'warn' | 'log' | 'info';
|
|
55
|
-
message: string;
|
|
56
|
-
connectedClient?: SnackConnectedClient;
|
|
57
|
-
error?: SnackError;
|
|
58
|
-
};
|
|
59
|
-
export declare type SnackWindowRef = {
|
|
60
|
-
current: Window | null;
|
|
61
|
-
};
|
|
62
|
-
export declare type SnackState = {
|
|
63
|
-
/**
|
|
64
|
-
* Expo SDK version.
|
|
65
|
-
*/
|
|
66
|
-
sdkVersion: SDKVersion;
|
|
67
|
-
/**
|
|
68
|
-
* Files that make up the content (code & assets) of the Snack. There should
|
|
69
|
-
* always be a file called "App.js" or "App.tsx" as the main entry point.
|
|
70
|
-
*/
|
|
71
|
-
files: SnackFiles;
|
|
72
|
-
/**
|
|
73
|
-
* Packages that can be used in the code files. Packages that are pre-loaded
|
|
74
|
-
* by the sdk may be ommited, but it is recommended to add them anyway.
|
|
75
|
-
*/
|
|
76
|
-
dependencies: SnackDependencies;
|
|
77
|
-
/**
|
|
78
|
-
* Optional name. The name is used when saving or downloading the Snack; and is used
|
|
79
|
-
* for the onlineName property.
|
|
80
|
-
*/
|
|
81
|
-
name: string;
|
|
82
|
-
/**
|
|
83
|
-
* Additional description of the Snack. The description is used when saving the Snack
|
|
84
|
-
* and may also be used for searching purposes.
|
|
85
|
-
*/
|
|
86
|
-
description: string;
|
|
87
|
-
/**
|
|
88
|
-
* Collection of dependencies that are missing but are required by one or more of
|
|
89
|
-
* the dependencies.
|
|
90
|
-
*/
|
|
91
|
-
missingDependencies: SnackMissingDependencies;
|
|
92
|
-
/**
|
|
93
|
-
* Collection of packages and versions that are compatible with the selected
|
|
94
|
-
* SDK version. This is similar to using `expo install`, which ensures the latest
|
|
95
|
-
* compatible version is installed.
|
|
96
|
-
*/
|
|
97
|
-
wantedDependencyVersions?: SnackDependencyVersions;
|
|
98
|
-
/**
|
|
99
|
-
* Disabled state. When the Snack is disabled it will not resolve any dependencies
|
|
100
|
-
* or upload any asset files. It also disables the ability to go online.
|
|
101
|
-
*/
|
|
102
|
-
disabled: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* When online is true, Expo clients can connect to the Snack and receive live updates
|
|
105
|
-
* when code or dependencies are changed. It also makes the Snack visible in the
|
|
106
|
-
* "Recently in Development" section of the Expo client.
|
|
107
|
-
*/
|
|
108
|
-
online: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Communication channel ("pubnub") through which live updates are transferred.
|
|
111
|
-
* The communication channel is only used when the Snack is "online".
|
|
112
|
-
*/
|
|
113
|
-
channel: string;
|
|
114
|
-
/**
|
|
115
|
-
* Device-id of the Expo client. When set causes the Snack to be visible in the
|
|
116
|
-
* "Recently in Development" section of the Expo client with that device-id.
|
|
117
|
-
* The device-id is only used when the Snack is "online".
|
|
118
|
-
*/
|
|
119
|
-
deviceId?: string;
|
|
120
|
-
/**
|
|
121
|
-
* Unique experience url which can be used to open the Expo client and connect
|
|
122
|
-
* to the Snack (e.g. "exp://exp.host/@snack/sdk.38.0.0-78173941").
|
|
123
|
-
*/
|
|
124
|
-
url: string;
|
|
125
|
-
/**
|
|
126
|
-
* Name of the Snack as shown in the "Recently in Development" section in the
|
|
127
|
-
* Expo client. The online-name will be empty when the Snack is not "online".
|
|
128
|
-
*/
|
|
129
|
-
onlineName?: string;
|
|
130
|
-
/**
|
|
131
|
-
* A close request that should be send using the browser `sendBeacon` API
|
|
132
|
-
* whenever the browser session is unloaded. This gives the Snack a last opportunity
|
|
133
|
-
* to gracefully close its connections so that the "Recently in Development"
|
|
134
|
-
* section in the Expo client no longer shows the Snack.
|
|
135
|
-
*/
|
|
136
|
-
sendBeaconCloseRequest?: SnackSendBeaconRequest;
|
|
137
|
-
/**
|
|
138
|
-
* @internal
|
|
139
|
-
*/
|
|
140
|
-
transports: {
|
|
141
|
-
[id: string]: SnackTransport;
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Clients that are currently connected.
|
|
145
|
-
*/
|
|
146
|
-
connectedClients: SnackConnectedClients;
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
*/
|
|
150
|
-
user?: SnackUser;
|
|
151
|
-
/**
|
|
152
|
-
* Unsaved status of the Snack. Becomes `true` when the Snack code is changed and
|
|
153
|
-
* `false` whenever the Snack is saved.
|
|
154
|
-
*/
|
|
155
|
-
unsaved: boolean;
|
|
156
|
-
/**
|
|
157
|
-
* Full name of the saved Snack.
|
|
158
|
-
*/
|
|
159
|
-
id?: string;
|
|
160
|
-
/**
|
|
161
|
-
* Id of this version of the saved Snack. Each Snack can have many different versions or revisions, each revision has its own snackId.
|
|
162
|
-
*/
|
|
163
|
-
snackId?: string;
|
|
164
|
-
/**
|
|
165
|
-
* Id of a Snack saved to an account. This id points to the latest version of a Snack revision and associated user.
|
|
166
|
-
*/
|
|
167
|
-
accountSnackId?: string;
|
|
168
|
-
/**
|
|
169
|
-
* URL of the saved Snack.
|
|
170
|
-
* The URL is empty when no save "id" is available.
|
|
171
|
-
*/
|
|
172
|
-
saveURL?: string;
|
|
173
|
-
/**
|
|
174
|
-
* Last saved (non-draft) Expo SDK version.
|
|
175
|
-
*/
|
|
176
|
-
savedSDKVersion?: string;
|
|
177
|
-
/**
|
|
178
|
-
* URL to use to when loading the web-preview in an iframe.
|
|
179
|
-
*
|
|
180
|
-
* Web-preview is supported from SDK 40 and higher.
|
|
181
|
-
* To enable it, set the `webPreviewRef` to the contentWindow
|
|
182
|
-
* of the iframe.
|
|
183
|
-
*/
|
|
184
|
-
webPreviewURL?: string;
|
|
185
|
-
};
|
|
1
|
+
import { SDKVersion, SnackDependencies, SnackDependencyVersions, SnackFiles, SnackMissingDependencies } from 'snack-content';
|
|
2
|
+
import { SnackTransport } from './transports';
|
|
3
|
+
/**
|
|
4
|
+
* An error that can optionally hold a file-name and line/column location.
|
|
5
|
+
*/
|
|
6
|
+
export interface SnackError extends Error {
|
|
7
|
+
fileName?: string;
|
|
8
|
+
lineNumber?: number;
|
|
9
|
+
columnNumber?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare type SnackConnectedClientStatus = 'ok' | 'error' | 'reloading';
|
|
12
|
+
/**
|
|
13
|
+
* Client which connected to the Snack.
|
|
14
|
+
*
|
|
15
|
+
* Clients are only able to connect when the Snack is `online`.
|
|
16
|
+
*/
|
|
17
|
+
export declare type SnackConnectedClient = {
|
|
18
|
+
transport: string;
|
|
19
|
+
id: string;
|
|
20
|
+
name: string;
|
|
21
|
+
platform: string;
|
|
22
|
+
status: SnackConnectedClientStatus;
|
|
23
|
+
error?: SnackError;
|
|
24
|
+
previewURL?: string;
|
|
25
|
+
previewTimestamp?: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Collection of connected clients.
|
|
29
|
+
*/
|
|
30
|
+
export declare type SnackConnectedClients = {
|
|
31
|
+
[key: string]: SnackConnectedClient;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* User that is used for communicating with the Expo servers.
|
|
35
|
+
*/
|
|
36
|
+
export declare type SnackUser = {
|
|
37
|
+
sessionSecret?: string;
|
|
38
|
+
accessToken?: string;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Request data to be used with the `sendBeacon` API.
|
|
42
|
+
*/
|
|
43
|
+
export declare type SnackSendBeaconRequest = {
|
|
44
|
+
url: string;
|
|
45
|
+
data: any;
|
|
46
|
+
};
|
|
47
|
+
export declare type SnackListenerSubscription = () => any;
|
|
48
|
+
/**
|
|
49
|
+
* Log data for when a connected client calls one of the
|
|
50
|
+
* `console.[log,info,warn,error]` to log information to the
|
|
51
|
+
* console.
|
|
52
|
+
*/
|
|
53
|
+
export declare type SnackLogEvent = {
|
|
54
|
+
type: 'error' | 'warn' | 'log' | 'info';
|
|
55
|
+
message: string;
|
|
56
|
+
connectedClient?: SnackConnectedClient;
|
|
57
|
+
error?: SnackError;
|
|
58
|
+
};
|
|
59
|
+
export declare type SnackWindowRef = {
|
|
60
|
+
current: Window | null;
|
|
61
|
+
};
|
|
62
|
+
export declare type SnackState = {
|
|
63
|
+
/**
|
|
64
|
+
* Expo SDK version.
|
|
65
|
+
*/
|
|
66
|
+
sdkVersion: SDKVersion;
|
|
67
|
+
/**
|
|
68
|
+
* Files that make up the content (code & assets) of the Snack. There should
|
|
69
|
+
* always be a file called "App.js" or "App.tsx" as the main entry point.
|
|
70
|
+
*/
|
|
71
|
+
files: SnackFiles;
|
|
72
|
+
/**
|
|
73
|
+
* Packages that can be used in the code files. Packages that are pre-loaded
|
|
74
|
+
* by the sdk may be ommited, but it is recommended to add them anyway.
|
|
75
|
+
*/
|
|
76
|
+
dependencies: SnackDependencies;
|
|
77
|
+
/**
|
|
78
|
+
* Optional name. The name is used when saving or downloading the Snack; and is used
|
|
79
|
+
* for the onlineName property.
|
|
80
|
+
*/
|
|
81
|
+
name: string;
|
|
82
|
+
/**
|
|
83
|
+
* Additional description of the Snack. The description is used when saving the Snack
|
|
84
|
+
* and may also be used for searching purposes.
|
|
85
|
+
*/
|
|
86
|
+
description: string;
|
|
87
|
+
/**
|
|
88
|
+
* Collection of dependencies that are missing but are required by one or more of
|
|
89
|
+
* the dependencies.
|
|
90
|
+
*/
|
|
91
|
+
missingDependencies: SnackMissingDependencies;
|
|
92
|
+
/**
|
|
93
|
+
* Collection of packages and versions that are compatible with the selected
|
|
94
|
+
* SDK version. This is similar to using `expo install`, which ensures the latest
|
|
95
|
+
* compatible version is installed.
|
|
96
|
+
*/
|
|
97
|
+
wantedDependencyVersions?: SnackDependencyVersions;
|
|
98
|
+
/**
|
|
99
|
+
* Disabled state. When the Snack is disabled it will not resolve any dependencies
|
|
100
|
+
* or upload any asset files. It also disables the ability to go online.
|
|
101
|
+
*/
|
|
102
|
+
disabled: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* When online is true, Expo clients can connect to the Snack and receive live updates
|
|
105
|
+
* when code or dependencies are changed. It also makes the Snack visible in the
|
|
106
|
+
* "Recently in Development" section of the Expo client.
|
|
107
|
+
*/
|
|
108
|
+
online: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Communication channel ("pubnub") through which live updates are transferred.
|
|
111
|
+
* The communication channel is only used when the Snack is "online".
|
|
112
|
+
*/
|
|
113
|
+
channel: string;
|
|
114
|
+
/**
|
|
115
|
+
* Device-id of the Expo client. When set causes the Snack to be visible in the
|
|
116
|
+
* "Recently in Development" section of the Expo client with that device-id.
|
|
117
|
+
* The device-id is only used when the Snack is "online".
|
|
118
|
+
*/
|
|
119
|
+
deviceId?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Unique experience url which can be used to open the Expo client and connect
|
|
122
|
+
* to the Snack (e.g. "exp://exp.host/@snack/sdk.38.0.0-78173941").
|
|
123
|
+
*/
|
|
124
|
+
url: string;
|
|
125
|
+
/**
|
|
126
|
+
* Name of the Snack as shown in the "Recently in Development" section in the
|
|
127
|
+
* Expo client. The online-name will be empty when the Snack is not "online".
|
|
128
|
+
*/
|
|
129
|
+
onlineName?: string;
|
|
130
|
+
/**
|
|
131
|
+
* A close request that should be send using the browser `sendBeacon` API
|
|
132
|
+
* whenever the browser session is unloaded. This gives the Snack a last opportunity
|
|
133
|
+
* to gracefully close its connections so that the "Recently in Development"
|
|
134
|
+
* section in the Expo client no longer shows the Snack.
|
|
135
|
+
*/
|
|
136
|
+
sendBeaconCloseRequest?: SnackSendBeaconRequest;
|
|
137
|
+
/**
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
transports: {
|
|
141
|
+
[id: string]: SnackTransport;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Clients that are currently connected.
|
|
145
|
+
*/
|
|
146
|
+
connectedClients: SnackConnectedClients;
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
*/
|
|
150
|
+
user?: SnackUser;
|
|
151
|
+
/**
|
|
152
|
+
* Unsaved status of the Snack. Becomes `true` when the Snack code is changed and
|
|
153
|
+
* `false` whenever the Snack is saved.
|
|
154
|
+
*/
|
|
155
|
+
unsaved: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Full name of the saved Snack.
|
|
158
|
+
*/
|
|
159
|
+
id?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Id of this version of the saved Snack. Each Snack can have many different versions or revisions, each revision has its own snackId.
|
|
162
|
+
*/
|
|
163
|
+
snackId?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Id of a Snack saved to an account. This id points to the latest version of a Snack revision and associated user.
|
|
166
|
+
*/
|
|
167
|
+
accountSnackId?: string;
|
|
168
|
+
/**
|
|
169
|
+
* URL of the saved Snack.
|
|
170
|
+
* The URL is empty when no save "id" is available.
|
|
171
|
+
*/
|
|
172
|
+
saveURL?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Last saved (non-draft) Expo SDK version.
|
|
175
|
+
*/
|
|
176
|
+
savedSDKVersion?: string;
|
|
177
|
+
/**
|
|
178
|
+
* URL to use to when loading the web-preview in an iframe.
|
|
179
|
+
*
|
|
180
|
+
* Web-preview is supported from SDK 40 and higher.
|
|
181
|
+
* To enable it, set the `webPreviewRef` to the contentWindow
|
|
182
|
+
* of the iframe.
|
|
183
|
+
*/
|
|
184
|
+
webPreviewURL?: string;
|
|
185
|
+
};
|
package/build/types.js
CHANGED
|
@@ -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=types.js.map
|
package/build/utils.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { SDKVersion } from 'snack-content';
|
|
2
|
-
import { SnackError, SnackUser } from './types';
|
|
3
|
-
declare const fetch: typeof globalThis.fetch;
|
|
4
|
-
export { fetch };
|
|
5
|
-
export declare function createChannel(channel?: string): string;
|
|
6
|
-
export declare function createURL(host: string, sdkVersion: SDKVersion, channel?: string, id?: string): string;
|
|
7
|
-
export declare function createError(config: {
|
|
8
|
-
message: string;
|
|
9
|
-
name?: string;
|
|
10
|
-
fileName?: string;
|
|
11
|
-
lineNumber?: number;
|
|
12
|
-
columnNumber?: number;
|
|
13
|
-
stack?: string;
|
|
14
|
-
}): SnackError;
|
|
15
|
-
export declare function createUserHeader(user?: SnackUser): {
|
|
16
|
-
[key: string]: string;
|
|
17
|
-
};
|
|
1
|
+
import { SDKVersion } from 'snack-content';
|
|
2
|
+
import { SnackError, SnackUser } from './types';
|
|
3
|
+
declare const fetch: typeof globalThis.fetch;
|
|
4
|
+
export { fetch };
|
|
5
|
+
export declare function createChannel(channel?: string): string;
|
|
6
|
+
export declare function createURL(host: string, sdkVersion: SDKVersion, channel?: string, id?: string): string;
|
|
7
|
+
export declare function createError(config: {
|
|
8
|
+
message: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
fileName?: string;
|
|
11
|
+
lineNumber?: number;
|
|
12
|
+
columnNumber?: number;
|
|
13
|
+
stack?: string;
|
|
14
|
+
}): SnackError;
|
|
15
|
+
export declare function createUserHeader(user?: SnackUser): {
|
|
16
|
+
[key: string]: string;
|
|
17
|
+
};
|
package/build/utils.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createUserHeader = exports.createError = exports.createURL = exports.createChannel = exports.fetch = void 0;
|
|
7
|
-
var fetch_ponyfill_1 = __importDefault(require("fetch-ponyfill"));
|
|
8
|
-
var nanoid_1 = require("nanoid");
|
|
9
|
-
var fetch = fetch_ponyfill_1.default().fetch;
|
|
10
|
-
exports.fetch = fetch;
|
|
11
|
-
// + and - are used as delimiters in the uri, ensure they do not appear in the channel itself
|
|
12
|
-
var VALID_CHANNEL_CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!_';
|
|
13
|
-
var generateChannel = nanoid_1.customAlphabet(VALID_CHANNEL_CHARS, 10);
|
|
14
|
-
function createChannel(channel) {
|
|
15
|
-
channel = channel !== null && channel !== void 0 ? channel : generateChannel();
|
|
16
|
-
if (channel.length < 6) {
|
|
17
|
-
throw new Error('Please use a channel id with more entropy');
|
|
18
|
-
}
|
|
19
|
-
for (var _i = 0, channel_1 = channel; _i < channel_1.length; _i++) {
|
|
20
|
-
var char = channel_1[_i];
|
|
21
|
-
if (VALID_CHANNEL_CHARS.indexOf(char) < 0) {
|
|
22
|
-
throw new Error('Channel id contains invalid characters');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return channel;
|
|
26
|
-
}
|
|
27
|
-
exports.createChannel = createChannel;
|
|
28
|
-
function createURL(host, sdkVersion, channel, id) {
|
|
29
|
-
if (channel) {
|
|
30
|
-
return id
|
|
31
|
-
? id.startsWith('@')
|
|
32
|
-
? "exp://" + host + "/" + id + "+" + channel
|
|
33
|
-
: "exp://" + host + "/@snack/" + id + "+" + channel
|
|
34
|
-
: "exp://" + host + "/@snack/sdk." + sdkVersion + "-" + channel;
|
|
35
|
-
}
|
|
36
|
-
else if (id) {
|
|
37
|
-
return "exp://" + host + "/" + (id.match(/.*\/.*/) ? id : "@snack/" + id);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.createURL = createURL;
|
|
44
|
-
function createError(config) {
|
|
45
|
-
var error = new Error(config.message);
|
|
46
|
-
if (config.name)
|
|
47
|
-
error.name = config.name;
|
|
48
|
-
if (config.fileName)
|
|
49
|
-
error.fileName = config.fileName;
|
|
50
|
-
if (config.lineNumber)
|
|
51
|
-
error.lineNumber = config.lineNumber;
|
|
52
|
-
if (config.columnNumber)
|
|
53
|
-
error.columnNumber = config.columnNumber;
|
|
54
|
-
if (config.stack)
|
|
55
|
-
error.stack = config.stack;
|
|
56
|
-
return error;
|
|
57
|
-
}
|
|
58
|
-
exports.createError = createError;
|
|
59
|
-
function createUserHeader(user) {
|
|
60
|
-
if (user === null || user === void 0 ? void 0 : user.sessionSecret) {
|
|
61
|
-
return { 'Expo-Session': user.sessionSecret };
|
|
62
|
-
}
|
|
63
|
-
if (user === null || user === void 0 ? void 0 : user.accessToken) {
|
|
64
|
-
return { Authorization: "Bearer " + user.accessToken };
|
|
65
|
-
}
|
|
66
|
-
return {};
|
|
67
|
-
}
|
|
68
|
-
exports.createUserHeader = createUserHeader;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createUserHeader = exports.createError = exports.createURL = exports.createChannel = exports.fetch = void 0;
|
|
7
|
+
var fetch_ponyfill_1 = __importDefault(require("fetch-ponyfill"));
|
|
8
|
+
var nanoid_1 = require("nanoid");
|
|
9
|
+
var fetch = fetch_ponyfill_1.default().fetch;
|
|
10
|
+
exports.fetch = fetch;
|
|
11
|
+
// + and - are used as delimiters in the uri, ensure they do not appear in the channel itself
|
|
12
|
+
var VALID_CHANNEL_CHARS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!_';
|
|
13
|
+
var generateChannel = nanoid_1.customAlphabet(VALID_CHANNEL_CHARS, 10);
|
|
14
|
+
function createChannel(channel) {
|
|
15
|
+
channel = channel !== null && channel !== void 0 ? channel : generateChannel();
|
|
16
|
+
if (channel.length < 6) {
|
|
17
|
+
throw new Error('Please use a channel id with more entropy');
|
|
18
|
+
}
|
|
19
|
+
for (var _i = 0, channel_1 = channel; _i < channel_1.length; _i++) {
|
|
20
|
+
var char = channel_1[_i];
|
|
21
|
+
if (VALID_CHANNEL_CHARS.indexOf(char) < 0) {
|
|
22
|
+
throw new Error('Channel id contains invalid characters');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return channel;
|
|
26
|
+
}
|
|
27
|
+
exports.createChannel = createChannel;
|
|
28
|
+
function createURL(host, sdkVersion, channel, id) {
|
|
29
|
+
if (channel) {
|
|
30
|
+
return id
|
|
31
|
+
? id.startsWith('@')
|
|
32
|
+
? "exp://" + host + "/" + id + "+" + channel
|
|
33
|
+
: "exp://" + host + "/@snack/" + id + "+" + channel
|
|
34
|
+
: "exp://" + host + "/@snack/sdk." + sdkVersion + "-" + channel;
|
|
35
|
+
}
|
|
36
|
+
else if (id) {
|
|
37
|
+
return "exp://" + host + "/" + (id.match(/.*\/.*/) ? id : "@snack/" + id);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.createURL = createURL;
|
|
44
|
+
function createError(config) {
|
|
45
|
+
var error = new Error(config.message);
|
|
46
|
+
if (config.name)
|
|
47
|
+
error.name = config.name;
|
|
48
|
+
if (config.fileName)
|
|
49
|
+
error.fileName = config.fileName;
|
|
50
|
+
if (config.lineNumber)
|
|
51
|
+
error.lineNumber = config.lineNumber;
|
|
52
|
+
if (config.columnNumber)
|
|
53
|
+
error.columnNumber = config.columnNumber;
|
|
54
|
+
if (config.stack)
|
|
55
|
+
error.stack = config.stack;
|
|
56
|
+
return error;
|
|
57
|
+
}
|
|
58
|
+
exports.createError = createError;
|
|
59
|
+
function createUserHeader(user) {
|
|
60
|
+
if (user === null || user === void 0 ? void 0 : user.sessionSecret) {
|
|
61
|
+
return { 'Expo-Session': user.sessionSecret };
|
|
62
|
+
}
|
|
63
|
+
if (user === null || user === void 0 ? void 0 : user.accessToken) {
|
|
64
|
+
return { Authorization: "Bearer " + user.accessToken };
|
|
65
|
+
}
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
exports.createUserHeader = createUserHeader;
|
|
69
69
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snack-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "The Expo Snack SDK",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"build",
|
|
9
|
+
"CHANGELOG.md",
|
|
10
|
+
"!**/__fixtures__",
|
|
11
|
+
"!**/__mocks__",
|
|
12
|
+
"!**/__tests__"
|
|
13
|
+
],
|
|
7
14
|
"repository": {
|
|
8
15
|
"type": "git",
|
|
9
16
|
"url": "git+https://github.com/expo/snack.git",
|
|
@@ -39,7 +46,7 @@
|
|
|
39
46
|
"@types/lodash.isequal": "^4.5.5",
|
|
40
47
|
"@types/lodash.mapvalues": "^4.6.6",
|
|
41
48
|
"@types/node-fetch": "^2.5.7",
|
|
42
|
-
"@types/pubnub": "^
|
|
49
|
+
"@types/pubnub": "^7.2.0",
|
|
43
50
|
"@types/semver": "^7.3.4",
|
|
44
51
|
"@types/ua-parser-js": "^0.7.33",
|
|
45
52
|
"@types/validate-npm-package-name": "^3.0.2",
|
|
@@ -59,9 +66,9 @@
|
|
|
59
66
|
"lodash": "^4.17.20",
|
|
60
67
|
"nanoid": "^3.1.20",
|
|
61
68
|
"nullthrows": "^1.1.1",
|
|
62
|
-
"pubnub": "^
|
|
69
|
+
"pubnub": "^7.2.0",
|
|
63
70
|
"semver": "^7.3.4",
|
|
64
|
-
"snack-content": "^1.
|
|
71
|
+
"snack-content": "^1.2.0",
|
|
65
72
|
"ua-parser-js": "^0.7.22",
|
|
66
73
|
"validate-npm-package-name": "^3.0.0"
|
|
67
74
|
}
|