release(v4.0.2): consumer-strict reader-shape fixes
4.0.1's typecheck gate compiled each package internally against
lib: ["ES2022"]. That doesn't catch types that only fail when
*consumer* code (lib: ["DOM"] + exactOptionalPropertyTypes) tries to
assign a native browser type into one of our locally-defined narrower
types. Dispatch hit one such case in @shade/files inline-threshold.ts.
This release adds a tests/consumer-strict/ smoke project to the
pre-publish gate. It compiles a tiny "as if I were a downstream app"
TS file against:
lib: ["ES2022", "DOM", "DOM.Iterable"]
types: ["bun-types"]
exactOptionalPropertyTypes: true
strict: true
paths → packages/*/src/index.ts
scripts/typecheck-all.ts now runs the smoke after per-package checks.
Both must pass before publish:dry / publish:all proceeds.
### Fixed
- @shade/files inline-threshold.ts: MinimalReader<T> rewritten as the
explicit disjoint union { done:false, value:T } | { done:true,
value?: T | undefined } that's assignable from every native reader
shape (bun, DOM, node:stream/web). Fixes the
"ReadableStreamReadResult is not assignable" Dispatch reported.
- @shade/files streams-bridge (client + server): stash setTimeout
return in a local before .unref?.() via { unref?: () => void } cast.
Fluent .unref?.() failed under lib: ["DOM"] (setTimeout returns
number there).
- @shade/sdk background.ts: same setInterval .unref?.() fix.
Wire-compatible. No API shape changed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
45
tests/consumer-strict/tsconfig.json
Normal file
45
tests/consumer-strict/tsconfig.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"strict": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": true,
|
||||
"noImplicitOverride": true,
|
||||
"exactOptionalPropertyTypes": true,
|
||||
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"noEmit": true,
|
||||
"types": ["bun-types"],
|
||||
"ignoreDeprecations": "6.0",
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@shade/core": ["../../packages/shade-core/src/index.ts"],
|
||||
"@shade/proto": ["../../packages/shade-proto/src/index.ts"],
|
||||
"@shade/crypto-web": ["../../packages/shade-crypto-web/src/index.ts"],
|
||||
"@shade/observability": ["../../packages/shade-observability/src/index.ts"],
|
||||
"@shade/keychain": ["../../packages/shade-keychain/src/index.ts"],
|
||||
"@shade/key-transparency": ["../../packages/shade-key-transparency/src/index.ts"],
|
||||
"@shade/storage-sqlite": ["../../packages/shade-storage-sqlite/src/index.ts"],
|
||||
"@shade/storage-postgres": ["../../packages/shade-storage-postgres/src/index.ts"],
|
||||
"@shade/storage-encrypted": ["../../packages/shade-storage-encrypted/src/index.ts"],
|
||||
"@shade/streams": ["../../packages/shade-streams/src/index.ts"],
|
||||
"@shade/transport": ["../../packages/shade-transport/src/index.ts"],
|
||||
"@shade/transport-bridge": ["../../packages/shade-transport-bridge/src/index.ts"],
|
||||
"@shade/transport-webrtc": ["../../packages/shade-transport-webrtc/src/index.ts"],
|
||||
"@shade/server": ["../../packages/shade-server/src/index.ts"],
|
||||
"@shade/inbox-server": ["../../packages/shade-inbox-server/src/index.ts"],
|
||||
"@shade/inbox": ["../../packages/shade-inbox/src/index.ts"],
|
||||
"@shade/transfer": ["../../packages/shade-transfer/src/index.ts"],
|
||||
"@shade/files": ["../../packages/shade-files/src/index.ts"],
|
||||
"@shade/recovery": ["../../packages/shade-recovery/src/index.ts"],
|
||||
"@shade/observer": ["../../packages/shade-observer/src/index.ts"],
|
||||
"@shade/dashboard": ["../../packages/shade-dashboard/src/index.ts"],
|
||||
"@shade/sdk": ["../../packages/shade-sdk/src/index.ts"],
|
||||
"@shade/widgets": ["../../packages/shade-widgets/src/index.ts"]
|
||||
}
|
||||
},
|
||||
"include": ["./*.ts"]
|
||||
}
|
||||
43
tests/consumer-strict/use-files.ts
Normal file
43
tests/consumer-strict/use-files.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Consumer-strict smoke for `@shade/files`.
|
||||
*
|
||||
* Compiled with `lib: ["ES2022", "DOM"]` + `exactOptionalPropertyTypes` +
|
||||
* `skipLibCheck: false` to mimic a downstream consumer like Dispatch.
|
||||
* Catches the class of bug where our internal narrower types (e.g. a
|
||||
* locally-defined `MinimalReader`) reject native browser types
|
||||
* (e.g. `ReadableStreamDefaultReader`) the consumer would naturally
|
||||
* pass in.
|
||||
*
|
||||
* If this file fails to compile, the published packages will fail in
|
||||
* any consumer's strict tsc — pre-publish gate must catch it.
|
||||
*/
|
||||
import { decideInline, type WriteSource } from '@shade/files';
|
||||
|
||||
declare const blob: Blob;
|
||||
declare const stream: ReadableStream<Uint8Array>;
|
||||
declare const bytes: Uint8Array;
|
||||
|
||||
async function smoke(): Promise<void> {
|
||||
// Each branch of WriteSource must round-trip through decideInline()
|
||||
// when given the natively-typed inputs a browser app would supply.
|
||||
const sources: WriteSource[] = [
|
||||
bytes,
|
||||
blob,
|
||||
stream,
|
||||
{ stream, size: 1024 },
|
||||
{ stream, size: 1024, contentType: 'image/png' },
|
||||
];
|
||||
for (const src of sources) {
|
||||
const decision = await decideInline(src);
|
||||
if (decision.kind === 'streams') {
|
||||
const reader = decision.stream.getReader();
|
||||
const { value, done } = await reader.read();
|
||||
if (!done && value !== undefined) {
|
||||
void value.byteLength;
|
||||
}
|
||||
reader.releaseLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void smoke;
|
||||
42
tests/consumer-strict/use-key-transparency.ts
Normal file
42
tests/consumer-strict/use-key-transparency.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Consumer-strict smoke for `@shade/key-transparency`.
|
||||
*
|
||||
* The package was the source of the 4 noUnusedLocals + the IndexProofWire
|
||||
* privacy bug in 4.0.0. This smoke imports every public type and
|
||||
* exercises the witness-fetcher contract that the SDK plugs into.
|
||||
*/
|
||||
import {
|
||||
LightWitness,
|
||||
type SignedTreeHead,
|
||||
type STHWire,
|
||||
type WitnessFetcher,
|
||||
} from '@shade/key-transparency';
|
||||
|
||||
declare const crypto: import('@shade/core').CryptoProvider;
|
||||
declare const logPublicKey: Uint8Array;
|
||||
|
||||
async function smoke(): Promise<void> {
|
||||
const fetcher: WitnessFetcher = {
|
||||
async fetchLatestSTH(): Promise<STHWire> {
|
||||
const res = await fetch('https://shade.example.com/v1/kt/sth');
|
||||
return (await res.json()) as STHWire;
|
||||
},
|
||||
async fetchConsistencyProof(
|
||||
from: number,
|
||||
to: number,
|
||||
): Promise<{ proof: string[] }> {
|
||||
const res = await fetch(
|
||||
`https://shade.example.com/v1/kt/consistency?from=${from}&to=${to}`,
|
||||
);
|
||||
return (await res.json()) as { proof: string[] };
|
||||
},
|
||||
};
|
||||
const witness = new LightWitness({ crypto, logPublicKey, fetcher });
|
||||
void witness;
|
||||
}
|
||||
|
||||
void smoke;
|
||||
|
||||
// Verify the type is reachable with no `any` leak.
|
||||
declare const sth: SignedTreeHead;
|
||||
void sth.treeSize;
|
||||
50
tests/consumer-strict/use-sdk.ts
Normal file
50
tests/consumer-strict/use-sdk.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Consumer-strict smoke for `@shade/sdk`.
|
||||
*
|
||||
* Exercises the high-level `createShade()` flow + the V3.x opt-in
|
||||
* surfaces (KT, WebRTC, fingerprint gates). Compiles under DOM-lib +
|
||||
* exactOptionalPropertyTypes to flag any private-type leaks like the
|
||||
* `Promise<unknown>` on `fetchLatestSTH` that 4.0.0 shipped.
|
||||
*/
|
||||
import {
|
||||
createShade,
|
||||
type Shade,
|
||||
type ShadeConfig,
|
||||
type ShadeWebRtcConfig,
|
||||
} from '@shade/sdk';
|
||||
|
||||
declare const factory: ShadeWebRtcConfig['factory'];
|
||||
|
||||
async function smoke(): Promise<void> {
|
||||
const config: ShadeConfig = {
|
||||
prekeyServer: 'https://shade.example.com',
|
||||
storage: 'memory',
|
||||
address: 'alice@example.com',
|
||||
keyTransparency: {
|
||||
mode: 'observe-strict',
|
||||
logPublicKey: new Uint8Array(32),
|
||||
},
|
||||
};
|
||||
const shade: Shade = await createShade(config);
|
||||
|
||||
const env = await shade.send('bob', 'hi');
|
||||
void env;
|
||||
|
||||
shade.onMessage(async (from: string, plaintext: string) => {
|
||||
void from;
|
||||
void plaintext;
|
||||
});
|
||||
|
||||
await shade.beforeFirstLargeFile(10 * 1024 * 1024, async (ctx) => {
|
||||
void ctx.peerAddress;
|
||||
void ctx.fingerprint;
|
||||
void ctx.gate;
|
||||
return true;
|
||||
});
|
||||
|
||||
shade.configureWebRTC({ factory });
|
||||
|
||||
void (await shade.fingerprint);
|
||||
}
|
||||
|
||||
void smoke;
|
||||
Reference in New Issue
Block a user