Skip to main content

Getting started

  1. Add the @s2-dev/streamstore dependency to your project:
npm add @s2-dev/streamstore
# or
yarn add @s2-dev/streamstore
# or
bun add @s2-dev/streamstore
  1. Generate an access token by logging onto the web console at s2.dev.
  2. Make a request using the SDK client. Set S2_ACCESS_TOKEN in your environment before running the example:
import { AppendRecord, S2 } from "@s2-dev/streamstore";

const s2 = new S2({
  accessToken: process.env.S2_ACCESS_TOKEN!,
});

const basin = s2.basin("my-basin");
const stream = basin.stream("my-stream");

await stream.append([
  AppendRecord.make("Hello, world!", { foo: "bar" }),
  AppendRecord.make(new Uint8Array([1, 2, 3]), { type: "binary" }),
]);

const result = await stream.read({
  seq_num: 0,
  count: 10,
});

for (const record of result.records) {
  console.log("Record:", record.body, "Headers:", record.headers);
}