pusher-js 7.4.1 → 7.6.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/.github/workflows/release_pr.yml +3 -1
- package/.github/workflows/run-tests.yml +27 -3
- package/CHANGELOG.md +8 -0
- package/Makefile +1 -0
- package/README.md +11 -3
- package/dist/node/pusher.js +139 -28
- package/dist/node/pusher.js.map +1 -1
- package/dist/react-native/pusher.js +5 -5
- package/dist/react-native/pusher.js.map +1 -1
- package/dist/web/pusher-with-encryption.js +83 -9
- package/dist/web/pusher-with-encryption.js.map +1 -1
- package/dist/web/pusher-with-encryption.min.js +2 -2
- package/dist/web/pusher-with-encryption.min.js.map +1 -1
- package/dist/web/pusher.js +83 -9
- package/dist/web/pusher.js.map +1 -1
- package/dist/web/pusher.min.js +2 -2
- package/dist/web/pusher.min.js.map +1 -1
- package/dist/worker/pusher-with-encryption.worker.js +81 -8
- package/dist/worker/pusher-with-encryption.worker.js.map +1 -1
- package/dist/worker/pusher-with-encryption.worker.min.js +2 -2
- package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -1
- package/dist/worker/pusher.worker.js +81 -8
- package/dist/worker/pusher.worker.js.map +1 -1
- package/dist/worker/pusher.worker.min.js +2 -2
- package/dist/worker/pusher.worker.min.js.map +1 -1
- package/integration_tests_server/index.js +176 -0
- package/integration_tests_server/package-lock.json +1177 -0
- package/integration_tests_server/package.json +15 -0
- package/package.json +6 -5
- package/spec/config/karma/config.common.js +1 -2
- package/spec/javascripts/helpers/node/integration.js +2 -2
- package/spec/javascripts/helpers/web/integration.js +2 -2
- package/spec/javascripts/integration/core/cluster_config_spec.js +1 -1
- package/spec/javascripts/integration/core/pusher_spec/test_builder.js +13 -43
- package/spec/javascripts/integration/web/dom/jsonp_spec.js +2 -2
- package/spec/javascripts/unit/core/config_spec.js +91 -3
- package/spec/javascripts/unit/core/connection/connection_manager_spec.js +11 -1
- package/spec/javascripts/unit/core/http/http_request_spec.js +0 -6
- package/spec/javascripts/unit/core/transports/transport_connection_spec.js +5 -0
- package/spec/javascripts/unit/core/utils/timers_spec.js +0 -4
- package/spec/javascripts/unit/core/watchlist_spec.js +48 -0
- package/spec/javascripts/unit/core_with_runtime/auth/channel_authorizer_spec.js +82 -0
- package/spec/javascripts/unit/core_with_runtime/auth/user_authorizer_spec.js +76 -0
- package/spec/javascripts/unit/web/pusher_authorizer_spec.js +28 -0
- package/spec/javascripts/unit/worker/channel_authorizer_spec.js +46 -0
- package/src/core/auth/channel_authorizer.ts +14 -3
- package/src/core/auth/options.ts +4 -0
- package/src/core/auth/user_authenticator.ts +14 -3
- package/src/core/pusher.ts +0 -1
- package/src/core/user.ts +5 -0
- package/src/core/watchlist.ts +31 -0
- package/src/runtimes/isomorphic/auth/xhr_auth.ts +6 -0
- package/src/runtimes/web/auth/jsonp_auth.ts +4 -1
- package/src/runtimes/worker/auth/fetch_auth.ts +7 -0
- package/types/src/core/auth/options.d.ts +4 -0
- package/types/src/core/user.d.ts +2 -0
- package/types/src/core/watchlist.d.ts +8 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const Pusher = require("pusher");
|
|
2
|
+
const express = require('express');
|
|
3
|
+
|
|
4
|
+
function decode_base64(data) {
|
|
5
|
+
return Buffer.from(data, 'base64').toString('ascii');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function decode(data) {
|
|
9
|
+
const str = decode_base64(data);
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(str);
|
|
12
|
+
} catch(e) {
|
|
13
|
+
return str;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function auth(pusher, channel_name, socket_id) {
|
|
18
|
+
const channel_data = {
|
|
19
|
+
user_id: socket_id,
|
|
20
|
+
user_info: {
|
|
21
|
+
name: `Integration ${socket_id}`,
|
|
22
|
+
email: `integration-${socket_id}@example.com`
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return pusher.authorizeChannel(socket_id, channel_name, channel_data);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function start_app(port, pusher_config) {
|
|
29
|
+
const app = express();
|
|
30
|
+
|
|
31
|
+
app.use(express.json());
|
|
32
|
+
app.use(express.urlencoded({extended: true}));
|
|
33
|
+
|
|
34
|
+
const pusher = new Pusher(pusher_config);
|
|
35
|
+
|
|
36
|
+
app.options('/auth', (req, res) => {
|
|
37
|
+
res.set({
|
|
38
|
+
'Allow': 'GET,POST,OPTIONS',
|
|
39
|
+
'Access-Control-Allow-Origin': '*',
|
|
40
|
+
'Access-Control-Allow-Headers': 'Accepts,Content-Type'
|
|
41
|
+
});
|
|
42
|
+
res.sendStatus(200);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
app.post('/auth', (req, res) => {
|
|
46
|
+
const channel_name = req.body.channel_name;
|
|
47
|
+
const socket_id = req.body.socket_id;
|
|
48
|
+
res.set({
|
|
49
|
+
'Allow': 'GET,POST,OPTIONS',
|
|
50
|
+
'Access-Control-Allow-Origin': '*',
|
|
51
|
+
'Access-Control-Allow-Headers': 'Accepts,Content-Type',
|
|
52
|
+
'Content-Type': 'application/json'
|
|
53
|
+
});
|
|
54
|
+
res.send(auth(pusher, channel_name, socket_id));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// jsonp auth
|
|
58
|
+
app.get('/auth', (req, res) => {
|
|
59
|
+
const channel_name = req.query.channel_name;
|
|
60
|
+
const socket_id = req.query.socket_id;
|
|
61
|
+
const callback = req.query.callback;
|
|
62
|
+
const auth_response = auth(pusher, channel_name, socket_id);
|
|
63
|
+
res.set('Content-Type','text/javascript');
|
|
64
|
+
res.send(callback + "(" + JSON.stringify(auth_response) + ")");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// triggering messages
|
|
68
|
+
app.get('/send/:jsonp_id', (req, res) => {
|
|
69
|
+
const channel = decode_base64(req.query.channel);
|
|
70
|
+
const event = decode_base64(req.query.event);
|
|
71
|
+
const data = JSON.parse(base_decode64(req.query.data));
|
|
72
|
+
const socket_id = decode_base64(req.query.socket_id || "");
|
|
73
|
+
|
|
74
|
+
pusher.trigger(channel, event, data);
|
|
75
|
+
|
|
76
|
+
res.set('Content-Type', 'text/javascript');
|
|
77
|
+
res.send(`Pusher.JSONP.receive(${req.params.jsonp_id}, null, {});`)
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// triggering messages
|
|
81
|
+
// pusher-js 2.2 JSONP API
|
|
82
|
+
app.get('/v2/send/:jsonp_id', (req, res) => {
|
|
83
|
+
const channel = decode_base64(req.query.channel);
|
|
84
|
+
const event = decode_base64(req.query.event);
|
|
85
|
+
const data = JSON.parse(decode_base64(req.query.data));
|
|
86
|
+
const socket_id = decode_base64(req.query.socket_id || "");
|
|
87
|
+
|
|
88
|
+
pusher.trigger(channel, event, data);
|
|
89
|
+
|
|
90
|
+
res.set({
|
|
91
|
+
'Access-Control-Allow-Origin': '*',
|
|
92
|
+
'Content-Type': 'text/javascript'
|
|
93
|
+
});
|
|
94
|
+
res.send(`Pusher.Integration.ScriptReceivers[${req.params.jsonp_id}](null, {});`)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// JSONP echo
|
|
98
|
+
app.get('/jsonp/echo/:id', (req, res) => {
|
|
99
|
+
const decoded_params =
|
|
100
|
+
Object.keys(req.query)
|
|
101
|
+
.filter(key => !["id", "receiver", "splat", "captures"].includes(key))
|
|
102
|
+
.reduce((obj, key) => {
|
|
103
|
+
obj[key] = decode(req.query[key]);
|
|
104
|
+
return obj;
|
|
105
|
+
}, {});
|
|
106
|
+
|
|
107
|
+
const receiver = params.hasOwnProperty("receiver") ? decode(params["receiver"]) : "Pusher.JSONP.receive";
|
|
108
|
+
|
|
109
|
+
res.set({
|
|
110
|
+
'Content-Type': 'text/javascript; charset=utf-8',
|
|
111
|
+
'Cache-Control': 'private, max-age=0, must-revalidate'
|
|
112
|
+
});
|
|
113
|
+
res.send(`${receiver}(${req.params.id}, null, ${JSON.stringify(decoded_params)});`)
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// JSONP echo
|
|
117
|
+
// pusher-js 2.2 JSONP API
|
|
118
|
+
app.get('/v2/jsonp/echo/:id', (req, res) => {
|
|
119
|
+
const decoded_params =
|
|
120
|
+
Object.keys(req.query)
|
|
121
|
+
.filter(key => !["id", "splat", "captures"].includes(key))
|
|
122
|
+
.reduce((obj, key) => {
|
|
123
|
+
obj[key] = decode(req.query[key]);
|
|
124
|
+
return obj;
|
|
125
|
+
}, {});
|
|
126
|
+
|
|
127
|
+
res.set({
|
|
128
|
+
'Content-Type': 'text/javascript; charset=utf-8',
|
|
129
|
+
'Cache-Control': 'private, max-age=0, must-revalidate'
|
|
130
|
+
});
|
|
131
|
+
res.send(`Pusher.ScriptReceivers[${req.params.id}](null, ${JSON.stringify(decoded_params)});`)
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ScriptRequest echo
|
|
135
|
+
app.get('/v2/script_request/echo', (req, res) => {
|
|
136
|
+
const decoded_params =
|
|
137
|
+
Object.keys(req.query)
|
|
138
|
+
.filter(key => !["id", "receiver", "splat", "captures"].includes(key))
|
|
139
|
+
.reduce((obj, key) => {
|
|
140
|
+
obj[key] = req.query[key];
|
|
141
|
+
return obj;
|
|
142
|
+
}, {});
|
|
143
|
+
|
|
144
|
+
res.set({
|
|
145
|
+
'Content-Type': 'text/javascript; charset=utf-8',
|
|
146
|
+
'Cache-Control': 'private, max-age=0, must-revalidate'
|
|
147
|
+
});
|
|
148
|
+
res.send(`${req.query.receiver}(null, ${JSON.stringify(decoded_params)});`);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
app.get( '/jsonp/500/:id', (req, res) => {
|
|
152
|
+
res.sendStatus(500);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
app.get( '/jsonp/404/:id', (req, res) => {
|
|
156
|
+
res.sendStatus(404);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
app.listen(port, () => {
|
|
160
|
+
console.log(`Integration tests auth server listening on port ${port}`);
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
start_app(3000, {
|
|
165
|
+
appId: process.env.INTEGRATION_TESTS_APP_MT1_APP_ID,
|
|
166
|
+
key: process.env.INTEGRATION_TESTS_APP_MT1_KEY,
|
|
167
|
+
secret: process.env.INTEGRATION_TESTS_APP_MT1_SECRET,
|
|
168
|
+
cluster: "mt1",
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
start_app(3001, {
|
|
172
|
+
appId: process.env.INTEGRATION_TESTS_APP_EU_APP_ID,
|
|
173
|
+
key: process.env.INTEGRATION_TESTS_APP_EU_KEY,
|
|
174
|
+
secret: process.env.INTEGRATION_TESTS_APP_EU_SECRET,
|
|
175
|
+
cluster: "eu"
|
|
176
|
+
});
|