@couch-kit/core 0.8.0 → 0.8.2
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 +12 -0
- package/dist/index.js +8 -3
- package/lib/constants.d.ts +5 -0
- package/lib/constants.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +20 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @couch-kit/core
|
|
2
2
|
|
|
3
|
+
## 0.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#31](https://github.com/faluciano/react-native-couch-kit/pull/31) [`e5178dc`](https://github.com/faluciano/react-native-couch-kit/commit/e5178dc666f95c2893e803f1f290abcfd7db6306) Thanks [@faluciano](https://github.com/faluciano)! - Fall back to legacy player ID derivation when `crypto.subtle` is unavailable (React Native / Hermes). Previously, `derivePlayerId` unconditionally called `crypto.subtle.digest("SHA-256", ...)` which threw in Hermes, silently preventing the JOIN handshake from completing and leaving clients stuck on a loading spinner.
|
|
8
|
+
|
|
9
|
+
## 0.8.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#27](https://github.com/faluciano/react-native-couch-kit/pull/27) [`4976357`](https://github.com/faluciano/react-native-couch-kit/commit/49763573df502e394d5591b73000f48ee711d7a8) Thanks [@faluciano](https://github.com/faluciano)! - Fix WebSocket connection failure caused by path mismatch: the client connected to `ws://host:8082` (root path `/`) while the server only accepted upgrades on `/ws`. Added shared `DEFAULT_WS_PATH` constant to `@couch-kit/core` and use it in both client URL construction and server handler registration.
|
|
14
|
+
|
|
3
15
|
## 0.8.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -161,6 +161,7 @@ var MessageTypes = {
|
|
|
161
161
|
// src/constants.ts
|
|
162
162
|
var DEFAULT_HTTP_PORT = 8080;
|
|
163
163
|
var DEFAULT_WS_PORT_OFFSET = 2;
|
|
164
|
+
var DEFAULT_WS_PATH = "/ws";
|
|
164
165
|
var MAX_FRAME_SIZE = 1024 * 1024;
|
|
165
166
|
var DEFAULT_MAX_RETRIES = 5;
|
|
166
167
|
var DEFAULT_BASE_DELAY = 1000;
|
|
@@ -188,9 +189,12 @@ function isValidSecret(secret) {
|
|
|
188
189
|
return hex.length >= 32 && /^[0-9a-f]+$/i.test(hex);
|
|
189
190
|
}
|
|
190
191
|
async function derivePlayerId(secret) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
if (typeof crypto !== "undefined" && typeof crypto.subtle?.digest === "function") {
|
|
193
|
+
const data = new TextEncoder().encode(secret);
|
|
194
|
+
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
195
|
+
return Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("").slice(0, 16);
|
|
196
|
+
}
|
|
197
|
+
return derivePlayerIdLegacy(secret);
|
|
194
198
|
}
|
|
195
199
|
function derivePlayerIdLegacy(secret) {
|
|
196
200
|
return secret.replace(/-/g, "").slice(0, 16);
|
|
@@ -240,6 +244,7 @@ export {
|
|
|
240
244
|
KEEPALIVE_INTERVAL,
|
|
241
245
|
InternalActionTypes,
|
|
242
246
|
DEFAULT_WS_PORT_OFFSET,
|
|
247
|
+
DEFAULT_WS_PATH,
|
|
243
248
|
DEFAULT_SYNC_INTERVAL,
|
|
244
249
|
DEFAULT_MAX_RETRIES,
|
|
245
250
|
DEFAULT_MAX_DELAY,
|
package/lib/constants.d.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
export declare const DEFAULT_HTTP_PORT = 8080;
|
|
4
4
|
/** Default WebSocket port offset from the HTTP port (skips Metro on +1). */
|
|
5
5
|
export declare const DEFAULT_WS_PORT_OFFSET = 2;
|
|
6
|
+
/** Default WebSocket endpoint path on the host server. */
|
|
7
|
+
export declare const DEFAULT_WS_PATH = "/ws";
|
|
6
8
|
/** @deprecated Not used by Couch Kit internals. Will be removed in the next major version. */
|
|
7
9
|
export declare const MAX_FRAME_SIZE: number;
|
|
8
10
|
/** Default maximum reconnection attempts for the client. */
|
|
@@ -37,6 +39,9 @@ export declare function isValidSecret(secret: string): boolean;
|
|
|
37
39
|
*
|
|
38
40
|
* Takes the first 16 hex characters of the SHA-256 hash, producing
|
|
39
41
|
* a deterministic ID that cannot be reversed to recover the secret.
|
|
42
|
+
*
|
|
43
|
+
* Falls back to {@link derivePlayerIdLegacy} when the Web Crypto API
|
|
44
|
+
* (`crypto.subtle`) is unavailable (e.g. React Native / Hermes).
|
|
40
45
|
*/
|
|
41
46
|
export declare function derivePlayerId(secret: string): Promise<string>;
|
|
42
47
|
/**
|
package/lib/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,wDAAwD;AAExD,oDAAoD;AACpD,eAAO,MAAM,iBAAiB,OAAO,CAAC;AAEtC,4EAA4E;AAC5E,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,8FAA8F;AAC9F,eAAO,MAAM,cAAc,QAAc,CAAC;AAE1C,4DAA4D;AAC5D,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,oEAAoE;AACpE,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC,+DAA+D;AAC/D,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC,4CAA4C;AAC5C,eAAO,MAAM,qBAAqB,OAAO,CAAC;AAE1C,0DAA0D;AAC1D,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,+EAA+E;AAC/E,eAAO,MAAM,0BAA0B,QAAgB,CAAC;AAExD,8FAA8F;AAC9F,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC,8FAA8F;AAC9F,eAAO,MAAM,iBAAiB,QAAQ,CAAC;AAEvC;;;;;GAKG;AACH,wBAAgB,UAAU,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|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -6,6 +6,9 @@ export const DEFAULT_HTTP_PORT = 8080;
|
|
|
6
6
|
/** Default WebSocket port offset from the HTTP port (skips Metro on +1). */
|
|
7
7
|
export const DEFAULT_WS_PORT_OFFSET = 2;
|
|
8
8
|
|
|
9
|
+
/** Default WebSocket endpoint path on the host server. */
|
|
10
|
+
export const DEFAULT_WS_PATH = "/ws";
|
|
11
|
+
|
|
9
12
|
/** @deprecated Not used by Couch Kit internals. Will be removed in the next major version. */
|
|
10
13
|
export const MAX_FRAME_SIZE = 1024 * 1024;
|
|
11
14
|
|
|
@@ -78,14 +81,25 @@ export function isValidSecret(secret: string): boolean {
|
|
|
78
81
|
*
|
|
79
82
|
* Takes the first 16 hex characters of the SHA-256 hash, producing
|
|
80
83
|
* a deterministic ID that cannot be reversed to recover the secret.
|
|
84
|
+
*
|
|
85
|
+
* Falls back to {@link derivePlayerIdLegacy} when the Web Crypto API
|
|
86
|
+
* (`crypto.subtle`) is unavailable (e.g. React Native / Hermes).
|
|
81
87
|
*/
|
|
82
88
|
export async function derivePlayerId(secret: string): Promise<string> {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
.
|
|
88
|
-
.
|
|
89
|
+
if (
|
|
90
|
+
typeof crypto !== "undefined" &&
|
|
91
|
+
typeof crypto.subtle?.digest === "function"
|
|
92
|
+
) {
|
|
93
|
+
const data = new TextEncoder().encode(secret);
|
|
94
|
+
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
95
|
+
return Array.from(new Uint8Array(hash))
|
|
96
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
97
|
+
.join("")
|
|
98
|
+
.slice(0, 16);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Web Crypto unavailable (React Native / Hermes) — fall back to legacy derivation
|
|
102
|
+
return derivePlayerIdLegacy(secret);
|
|
89
103
|
}
|
|
90
104
|
|
|
91
105
|
/**
|