@s2-dev/streamstore 0.16.0 → 0.16.1

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.
Files changed (156) hide show
  1. package/dist/accessTokens.d.ts +37 -0
  2. package/dist/accessTokens.d.ts.map +1 -0
  3. package/dist/accessTokens.js +74 -0
  4. package/dist/accessTokens.js.map +1 -0
  5. package/dist/basin.d.ts +26 -0
  6. package/dist/basin.d.ts.map +1 -0
  7. package/dist/basin.js +34 -0
  8. package/dist/basin.js.map +1 -0
  9. package/dist/basins.d.ts +53 -0
  10. package/dist/basins.d.ts.map +1 -0
  11. package/dist/basins.js +115 -0
  12. package/dist/basins.js.map +1 -0
  13. package/dist/common.d.ts +44 -0
  14. package/dist/common.d.ts.map +1 -0
  15. package/dist/common.js +2 -0
  16. package/dist/common.js.map +1 -0
  17. package/dist/error.d.ts +28 -0
  18. package/dist/error.d.ts.map +1 -0
  19. package/dist/error.js +43 -0
  20. package/dist/error.js.map +1 -0
  21. package/dist/generated/client/client.gen.d.ts +3 -0
  22. package/dist/generated/client/client.gen.d.ts.map +1 -0
  23. package/dist/generated/client/client.gen.js +205 -0
  24. package/dist/generated/client/client.gen.js.map +1 -0
  25. package/dist/generated/client/index.d.ts +9 -0
  26. package/dist/generated/client/index.d.ts.map +1 -0
  27. package/dist/generated/client/index.js +7 -0
  28. package/dist/generated/client/index.js.map +1 -0
  29. package/dist/generated/client/types.gen.d.ts +125 -0
  30. package/dist/generated/client/types.gen.d.ts.map +1 -0
  31. package/dist/generated/client/types.gen.js +3 -0
  32. package/dist/generated/client/types.gen.js.map +1 -0
  33. package/dist/generated/client/utils.gen.d.ts +34 -0
  34. package/dist/generated/client/utils.gen.d.ts.map +1 -0
  35. package/dist/generated/client/utils.gen.js +231 -0
  36. package/dist/generated/client/utils.gen.js.map +1 -0
  37. package/{src/generated/client.gen.ts → dist/generated/client.gen.d.ts} +3 -8
  38. package/dist/generated/client.gen.d.ts.map +1 -0
  39. package/dist/generated/client.gen.js +6 -0
  40. package/dist/generated/client.gen.js.map +1 -0
  41. package/dist/generated/core/auth.gen.d.ts +19 -0
  42. package/dist/generated/core/auth.gen.d.ts.map +1 -0
  43. package/dist/generated/core/auth.gen.js +15 -0
  44. package/dist/generated/core/auth.gen.js.map +1 -0
  45. package/dist/generated/core/bodySerializer.gen.d.ts +18 -0
  46. package/dist/generated/core/bodySerializer.gen.d.ts.map +1 -0
  47. package/dist/generated/core/bodySerializer.gen.js +58 -0
  48. package/dist/generated/core/bodySerializer.gen.js.map +1 -0
  49. package/dist/generated/core/params.gen.d.ts +34 -0
  50. package/dist/generated/core/params.gen.d.ts.map +1 -0
  51. package/dist/generated/core/params.gen.js +89 -0
  52. package/dist/generated/core/params.gen.js.map +1 -0
  53. package/dist/generated/core/pathSerializer.gen.d.ts +34 -0
  54. package/dist/generated/core/pathSerializer.gen.d.ts.map +1 -0
  55. package/dist/generated/core/pathSerializer.gen.js +115 -0
  56. package/dist/generated/core/pathSerializer.gen.js.map +1 -0
  57. package/dist/generated/core/queryKeySerializer.gen.d.ts +19 -0
  58. package/dist/generated/core/queryKeySerializer.gen.d.ts.map +1 -0
  59. package/dist/generated/core/queryKeySerializer.gen.js +100 -0
  60. package/dist/generated/core/queryKeySerializer.gen.js.map +1 -0
  61. package/dist/generated/core/serverSentEvents.gen.d.ts +72 -0
  62. package/dist/generated/core/serverSentEvents.gen.d.ts.map +1 -0
  63. package/dist/generated/core/serverSentEvents.gen.js +136 -0
  64. package/dist/generated/core/serverSentEvents.gen.js.map +1 -0
  65. package/dist/generated/core/types.gen.d.ts +79 -0
  66. package/dist/generated/core/types.gen.d.ts.map +1 -0
  67. package/dist/generated/core/types.gen.js +3 -0
  68. package/dist/generated/core/types.gen.js.map +1 -0
  69. package/dist/generated/core/utils.gen.d.ts +20 -0
  70. package/dist/generated/core/utils.gen.d.ts.map +1 -0
  71. package/dist/generated/core/utils.gen.js +88 -0
  72. package/dist/generated/core/utils.gen.js.map +1 -0
  73. package/dist/generated/index.d.ts +3 -0
  74. package/dist/generated/index.d.ts.map +1 -0
  75. package/{src/generated/index.ts → dist/generated/index.js} +1 -2
  76. package/dist/generated/index.js.map +1 -0
  77. package/dist/generated/sdk.gen.d.ts +100 -0
  78. package/dist/generated/sdk.gen.d.ts.map +1 -0
  79. package/dist/generated/sdk.gen.js +350 -0
  80. package/dist/generated/sdk.gen.js.map +1 -0
  81. package/{src/generated/types.gen.ts → dist/generated/types.gen.d.ts} +1 -158
  82. package/dist/generated/types.gen.d.ts.map +1 -0
  83. package/dist/generated/types.gen.js +3 -0
  84. package/dist/generated/types.gen.js.map +1 -0
  85. package/dist/index.d.ts +10 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +4 -0
  88. package/dist/index.js.map +1 -0
  89. package/dist/lib/event-stream.d.ts +26 -0
  90. package/dist/lib/event-stream.d.ts.map +1 -0
  91. package/dist/lib/event-stream.js +138 -0
  92. package/dist/lib/event-stream.js.map +1 -0
  93. package/dist/metrics.d.ts +44 -0
  94. package/dist/metrics.d.ts.map +1 -0
  95. package/dist/metrics.js +83 -0
  96. package/dist/metrics.js.map +1 -0
  97. package/dist/s2.d.ts +38 -0
  98. package/dist/s2.d.ts.map +1 -0
  99. package/dist/s2.js +56 -0
  100. package/dist/s2.js.map +1 -0
  101. package/dist/stream.d.ts +156 -0
  102. package/dist/stream.d.ts.map +1 -0
  103. package/dist/stream.js +598 -0
  104. package/dist/stream.js.map +1 -0
  105. package/dist/streams.d.ts +52 -0
  106. package/dist/streams.d.ts.map +1 -0
  107. package/dist/streams.js +114 -0
  108. package/dist/streams.js.map +1 -0
  109. package/dist/utils.d.ts +20 -0
  110. package/dist/utils.d.ts.map +1 -0
  111. package/dist/utils.js +52 -0
  112. package/dist/utils.js.map +1 -0
  113. package/package.json +5 -1
  114. package/.changeset/README.md +0 -8
  115. package/.changeset/config.json +0 -11
  116. package/.claude/settings.local.json +0 -9
  117. package/.github/workflows/ci.yml +0 -59
  118. package/.github/workflows/publish.yml +0 -35
  119. package/CHANGELOG.md +0 -7
  120. package/biome.json +0 -30
  121. package/bun.lock +0 -598
  122. package/examples/append.ts +0 -84
  123. package/examples/kitchen-sink.ts +0 -73
  124. package/examples/read.ts +0 -30
  125. package/openapi-ts.config.ts +0 -7
  126. package/src/accessTokens.ts +0 -100
  127. package/src/basin.ts +0 -43
  128. package/src/basins.ts +0 -154
  129. package/src/common.ts +0 -45
  130. package/src/error.ts +0 -58
  131. package/src/generated/client/client.gen.ts +0 -268
  132. package/src/generated/client/index.ts +0 -26
  133. package/src/generated/client/types.gen.ts +0 -268
  134. package/src/generated/client/utils.gen.ts +0 -331
  135. package/src/generated/core/auth.gen.ts +0 -42
  136. package/src/generated/core/bodySerializer.gen.ts +0 -92
  137. package/src/generated/core/params.gen.ts +0 -153
  138. package/src/generated/core/pathSerializer.gen.ts +0 -181
  139. package/src/generated/core/queryKeySerializer.gen.ts +0 -136
  140. package/src/generated/core/serverSentEvents.gen.ts +0 -264
  141. package/src/generated/core/types.gen.ts +0 -118
  142. package/src/generated/core/utils.gen.ts +0 -143
  143. package/src/generated/sdk.gen.ts +0 -387
  144. package/src/index.ts +0 -66
  145. package/src/lib/event-stream.ts +0 -167
  146. package/src/metrics.ts +0 -106
  147. package/src/s2.ts +0 -65
  148. package/src/stream.ts +0 -791
  149. package/src/streams.ts +0 -156
  150. package/src/tests/appendSession.test.ts +0 -149
  151. package/src/tests/batcher-session.integration.test.ts +0 -80
  152. package/src/tests/batcher.test.ts +0 -216
  153. package/src/tests/index.test.ts +0 -7
  154. package/src/utils.ts +0 -80
  155. package/tsconfig.build.json +0 -10
  156. package/tsconfig.json +0 -31
@@ -1,84 +0,0 @@
1
- import { AppendRecord, S2 } from "../src";
2
-
3
- const s2 = new S2({
4
- accessToken: process.env.S2_ACCESS_TOKEN!,
5
- });
6
-
7
- const basins = await s2.basins.list();
8
- if (!basins.basins[0]) {
9
- throw new Error("No basin found");
10
- }
11
- const basin = s2.basin(basins.basins[0].name);
12
- const streams = await basin.streams.list();
13
- if (streams.streams[0]) {
14
- const stream = basin.stream(streams.streams[0].name);
15
- // Create an append session
16
- const session = await stream.appendSession();
17
-
18
- // Create a batcher with options
19
- const batcher = session.makeBatcher({
20
- lingerDuration: 20, // 20ms
21
- maxBatchSize: 10,
22
- });
23
-
24
- // Submit individual records to the batcher
25
- // These will be batched and sent automatically
26
- // Now returns promises that resolve when acks are received
27
- const promise1 = batcher.submit(AppendRecord.make("record 1"));
28
- const promise2 = batcher.submit(AppendRecord.make("record 2"));
29
- const promise3 = batcher.submit([
30
- AppendRecord.make("record 3"),
31
- AppendRecord.make("record 4"),
32
- ]);
33
-
34
- // You can also submit directly to the session (bypasses batching)
35
- const urgentPromise = session.submit(AppendRecord.make("urgent record"));
36
-
37
- // The batcher will continue batching
38
- const promise4 = batcher.submit(AppendRecord.make("record 5"));
39
-
40
- // Wait for all acks to come back
41
- const allAcks = await Promise.all([
42
- promise1,
43
- promise2,
44
- promise3,
45
- urgentPromise,
46
- promise4,
47
- ]);
48
- console.log("All records acknowledged:", allAcks);
49
-
50
- // Flush and close the batcher
51
- batcher.flush();
52
- await batcher.close();
53
-
54
- // Close the session (waits for all appends to complete)
55
- await session.close();
56
-
57
- // You can also use the acks stream to track acknowledgements
58
- const session2 = await stream.appendSession();
59
- const acks = session2.acks();
60
-
61
- // Read acks in parallel with submitting
62
- (async () => {
63
- for await (const ack of acks) {
64
- console.log("Received ack:", ack);
65
- }
66
- })();
67
-
68
- const ack = await session2.submit([{ body: "test" }]);
69
- console.log("Single record ack:", ack);
70
-
71
- await session2.close();
72
-
73
- // Example: Error handling with promises
74
- const session3 = await stream.appendSession();
75
- try {
76
- const errorPromise = session3.submit([{ body: "will fail" }]);
77
- // If there's an error (e.g., network issue, validation error),
78
- // the promise will reject
79
- await errorPromise;
80
- } catch (error) {
81
- console.error("Append failed:", error);
82
- }
83
- await session3.close();
84
- }
@@ -1,73 +0,0 @@
1
- import { AppendRecord, S2 } from "../src";
2
-
3
- const s2 = new S2({
4
- accessToken: process.env.S2_ACCESS_TOKEN!,
5
- });
6
-
7
- const basins = await s2.basins.list();
8
- console.log(
9
- "basins",
10
- basins.basins.map((basin) => basin.name),
11
- );
12
- if (!basins.basins[0]) {
13
- throw new Error("No basin found");
14
- }
15
- const basin = s2.basin(basins.basins[0].name);
16
- const streams = await basin.streams.list();
17
- const streamResults = await Promise.all(
18
- streams.streams.map((stream) =>
19
- basin.streams.getConfig({ stream: stream.name }),
20
- ),
21
- );
22
- console.log("streams", streamResults);
23
-
24
- if (streams.streams[0]) {
25
- console.log("reading stream", streams.streams[0].name);
26
- const stream = basin.stream(streams.streams[0].name);
27
- const stringRead = await stream.read({
28
- count: 5,
29
- seq_num: 0,
30
- });
31
- console.log(
32
- "read",
33
- stringRead.records?.[0]?.body,
34
- stringRead.records?.[0]?.headers,
35
- );
36
- const bytesRead = await stream.read({ as: "bytes", count: 5, seq_num: 0 });
37
- console.log(
38
- "read bytes",
39
- bytesRead.records?.[0]?.body,
40
- bytesRead.records?.[0]?.headers,
41
- );
42
-
43
- const append = await stream.append([
44
- AppendRecord.make("Hello, world!", {
45
- foo: "bar",
46
- }),
47
- AppendRecord.make(new Uint8Array([1, 2, 3]), {
48
- foo: "bar",
49
- }),
50
- AppendRecord.make(new Uint8Array([1, 2, 3]), [
51
- [new TextEncoder().encode("foo"), new TextEncoder().encode("bar")],
52
- [new TextEncoder().encode("baz"), "bak"],
53
- ["qux", new TextEncoder().encode("quux")],
54
- ]),
55
- AppendRecord.fence("my-fence"),
56
- AppendRecord.trim(0),
57
- AppendRecord.command("foo"),
58
- // still can just make by hand:
59
- {
60
- body: "hello, world!",
61
- headers: [["foo", "bar"]],
62
- timestamp: new Date().getTime(),
63
- },
64
- ]);
65
- console.log("append", append);
66
- const readSession = await stream.readSession({
67
- clamp: true,
68
- tail_offset: 10,
69
- });
70
- for await (const record of readSession) {
71
- console.log("record", record);
72
- }
73
- }
package/examples/read.ts DELETED
@@ -1,30 +0,0 @@
1
- import { S2 } from "../src";
2
-
3
- const s2 = new S2({
4
- accessToken: process.env.S2_ACCESS_TOKEN!,
5
- });
6
-
7
- const basins = await s2.basins.list();
8
- if (!basins.basins[0]) {
9
- throw new Error("No basin found");
10
- }
11
- const basin = s2.basin(basins.basins[0].name);
12
- const streams = await basin.streams.list();
13
- if (streams.streams[0]) {
14
- const stream = basin.stream(streams.streams[0].name);
15
- console.log(
16
- `reading s2://${basins.basins[0].name}/${streams.streams[0].name}`,
17
- );
18
-
19
- const readSession = await stream.readSession({
20
- tail_offset: 5,
21
- wait: 10, // wait up to 10 seconds for new records
22
- as: "bytes",
23
- });
24
-
25
- for await (const record of readSession) {
26
- console.log(`[seq ${record.seq_num}] ${record.body}`);
27
- console.log("new tail", readSession.streamPosition?.seq_num);
28
- }
29
- console.log("Done reading");
30
- }
@@ -1,7 +0,0 @@
1
- import { defineConfig } from "@hey-api/openapi-ts";
2
-
3
- export default defineConfig({
4
- input:
5
- "https://raw.githubusercontent.com/s2-streamstore/s2-protos/refs/heads/main/s2/v1/openapi.json", // sign up at app.heyapi.dev
6
- output: "src/generated",
7
- });
@@ -1,100 +0,0 @@
1
- import type { DataToObject, S2RequestOptions } from "./common";
2
- import { S2Error } from "./error";
3
- import {
4
- type IssueAccessTokenData,
5
- issueAccessToken,
6
- type ListAccessTokensData,
7
- listAccessTokens,
8
- type RevokeAccessTokenData,
9
- revokeAccessToken,
10
- } from "./generated";
11
- import type { Client } from "./generated/client/types.gen";
12
-
13
- export interface ListAccessTokensArgs
14
- extends DataToObject<ListAccessTokensData> {}
15
- export interface IssueAccessTokenArgs
16
- extends DataToObject<IssueAccessTokenData> {}
17
- export interface RevokeAccessTokenArgs
18
- extends DataToObject<RevokeAccessTokenData> {}
19
-
20
- export class S2AccessTokens {
21
- readonly client: Client;
22
-
23
- constructor(client: Client) {
24
- this.client = client;
25
- }
26
-
27
- /**
28
- * List access tokens.
29
- *
30
- * @param args.prefix Filter to IDs beginning with this prefix
31
- * @param args.start_after Filter to IDs lexicographically after this value
32
- * @param args.limit Max results (up to 1000)
33
- */
34
- public async list(args?: ListAccessTokensArgs, options?: S2RequestOptions) {
35
- const response = await listAccessTokens({
36
- client: this.client,
37
- query: args,
38
- ...options,
39
- });
40
-
41
- if (response.error) {
42
- throw new S2Error({
43
- message: response.error.message,
44
- code: response.error.code ?? undefined,
45
- status: response.response.status,
46
- });
47
- }
48
-
49
- return response.data;
50
- }
51
-
52
- /**
53
- * Issue a new access token.
54
- *
55
- * @param args.id Unique token ID (1-96 bytes)
56
- * @param args.scope Token scope (operations and resource sets)
57
- * @param args.auto_prefix_streams Namespace stream names by configured prefix scope
58
- * @param args.expires_at Expiration in ISO 8601; defaults to requestor's token expiry
59
- */
60
- public async issue(args: IssueAccessTokenArgs, options?: S2RequestOptions) {
61
- const response = await issueAccessToken({
62
- client: this.client,
63
- body: args,
64
- ...options,
65
- });
66
-
67
- if (response.error) {
68
- throw new S2Error({
69
- message: response.error.message,
70
- code: response.error.code ?? undefined,
71
- status: response.response.status,
72
- });
73
- }
74
-
75
- return response.data;
76
- }
77
-
78
- /**
79
- * Revoke an access token by ID.
80
- *
81
- * @param args.id Token ID to revoke
82
- */
83
- public async revoke(args: RevokeAccessTokenArgs, options?: S2RequestOptions) {
84
- const response = await revokeAccessToken({
85
- client: this.client,
86
- path: args,
87
- ...options,
88
- });
89
-
90
- if (response.error) {
91
- throw new S2Error({
92
- message: response.error.message,
93
- code: response.error.code ?? undefined,
94
- status: response.response.status,
95
- });
96
- }
97
-
98
- return response.data;
99
- }
100
- }
package/src/basin.ts DELETED
@@ -1,43 +0,0 @@
1
- import { Redacted } from "effect";
2
- import { createClient, createConfig } from "./generated/client";
3
- import type { Client } from "./generated/client/types.gen";
4
- import { S2Stream } from "./stream";
5
- import { S2Streams } from "./streams";
6
-
7
- export class S2Basin {
8
- private readonly client: Client;
9
- private readonly accessToken: Redacted.Redacted;
10
-
11
- public readonly name: string;
12
- public readonly streams: S2Streams;
13
-
14
- /**
15
- * Create a basin-scoped client that talks to `https://{basin}.b.aws.s2.dev/v1`.
16
- *
17
- * Use this to work with streams inside a single basin.
18
- * @param name Basin name
19
- * @param accessToken Redacted access token from the parent `S2` client
20
- */
21
- constructor(
22
- name: string,
23
- options: { accessToken: Redacted.Redacted; baseUrl: string },
24
- ) {
25
- this.name = name;
26
- this.accessToken = options.accessToken;
27
- this.client = createClient(
28
- createConfig({
29
- baseUrl: options.baseUrl,
30
- auth: () => Redacted.value(this.accessToken),
31
- }),
32
- );
33
- this.streams = new S2Streams(this.client);
34
- }
35
-
36
- /**
37
- * Create a stream-scoped helper bound to `this` basin.
38
- * @param name Stream name
39
- */
40
- public stream(name: string) {
41
- return new S2Stream(name, this.client);
42
- }
43
- }
package/src/basins.ts DELETED
@@ -1,154 +0,0 @@
1
- import type { DataToObject, S2RequestOptions } from "./common";
2
- import { S2Error } from "./error";
3
- import {
4
- type CreateBasinData,
5
- createBasin,
6
- type DeleteBasinData,
7
- deleteBasin,
8
- type GetBasinConfigData,
9
- getBasinConfig,
10
- type ListBasinsData,
11
- listBasins,
12
- type ReconfigureBasinData,
13
- reconfigureBasin,
14
- } from "./generated";
15
- import type { Client } from "./generated/client/types.gen";
16
-
17
- export interface ListBasinsArgs extends DataToObject<ListBasinsData> {}
18
- export interface CreateBasinArgs extends DataToObject<CreateBasinData> {}
19
- export interface GetBasinConfigArgs extends DataToObject<GetBasinConfigData> {}
20
- export interface DeleteBasinArgs extends DataToObject<DeleteBasinData> {}
21
- export interface ReconfigureBasinArgs
22
- extends DataToObject<ReconfigureBasinData> {}
23
-
24
- export class S2Basins {
25
- private readonly client: Client;
26
-
27
- constructor(client: Client) {
28
- this.client = client;
29
- }
30
-
31
- /**
32
- * List basins.
33
- *
34
- * @param args.prefix Return basins whose names start with the given prefix
35
- * @param args.start_after Name to start after (for pagination)
36
- * @param args.limit Max results (up to 1000)
37
- */
38
- public async list(args?: ListBasinsArgs, options?: S2RequestOptions) {
39
- const response = await listBasins({
40
- client: this.client,
41
- query: args,
42
- ...options,
43
- });
44
-
45
- if (response.error) {
46
- throw new S2Error({
47
- message: response.error.message,
48
- code: response.error.code ?? undefined,
49
- status: response.response.status,
50
- });
51
- }
52
-
53
- return response.data;
54
- }
55
-
56
- /**
57
- * Create a basin.
58
- *
59
- * @param args.basin Globally unique basin name (8-48 chars, lowercase letters, numbers, hyphens; cannot begin or end with a hyphen)
60
- * @param args.config Optional basin configuration (e.g. default stream config)
61
- * @param args.scope Basin scope
62
- */
63
- public async create(args: CreateBasinArgs, options?: S2RequestOptions) {
64
- const response = await createBasin({
65
- client: this.client,
66
- body: args,
67
- ...options,
68
- });
69
-
70
- if (response.error) {
71
- throw new S2Error({
72
- message: response.error.message,
73
- code: response.error.code ?? undefined,
74
- status: response.response.status,
75
- });
76
- }
77
-
78
- return response.data;
79
- }
80
-
81
- /**
82
- * Get basin configuration.
83
- *
84
- * @param args.basin Basin name
85
- */
86
- public async getConfig(args: GetBasinConfigArgs, options?: S2RequestOptions) {
87
- const response = await getBasinConfig({
88
- client: this.client,
89
- path: args,
90
- ...options,
91
- });
92
-
93
- if (response.error) {
94
- throw new S2Error({
95
- message: response.error.message,
96
- code: response.error.code ?? undefined,
97
- status: response.response.status,
98
- });
99
- }
100
-
101
- return response.data;
102
- }
103
-
104
- /**
105
- * Delete a basin.
106
- *
107
- * @param args.basin Basin name
108
- */
109
- public async delete(args: DeleteBasinArgs, options?: S2RequestOptions) {
110
- const response = await deleteBasin({
111
- client: this.client,
112
- path: args,
113
- ...options,
114
- });
115
-
116
- if (response.error) {
117
- throw new S2Error({
118
- message: response.error.message,
119
- code: response.error.code ?? undefined,
120
- status: response.response.status,
121
- });
122
- }
123
-
124
- return response.data;
125
- }
126
-
127
- /**
128
- * Reconfigure a basin.
129
- *
130
- * @param args.basin Basin name
131
- * @param args.body Configuration fields to change (e.g. default stream config)
132
- */
133
- public async reconfigure(
134
- args: ReconfigureBasinArgs,
135
- options?: S2RequestOptions,
136
- ) {
137
- const response = await reconfigureBasin({
138
- client: this.client,
139
- path: args,
140
- body: args,
141
- ...options,
142
- });
143
-
144
- if (response.error) {
145
- throw new S2Error({
146
- message: response.error.message,
147
- code: response.error.code ?? undefined,
148
- status: response.response.status,
149
- });
150
- }
151
-
152
- return response.data;
153
- }
154
- }
package/src/common.ts DELETED
@@ -1,45 +0,0 @@
1
- /**
2
- * Configuration for constructing the top-level `S2` client.
3
- *
4
- * - The client authenticates using a Bearer access token on every request.
5
- */
6
- export type S2ClientOptions = {
7
- /**
8
- * Access token used for HTTP Bearer authentication.
9
- * Typically obtained via your S2 account or created using `s2.accessTokens.issue`.
10
- */
11
- accessToken: string;
12
- /**
13
- * Base URL for the S2 API.
14
- * Defaults to `https://aws.s2.dev`.
15
- */
16
- baseUrl?: string;
17
- /**
18
- * Function to make a basin-specific base URL.
19
- * Defaults to `https://{basin}.b.aws.s2.dev`.
20
- */
21
- makeBasinBaseUrl?: (basin: string) => string;
22
- };
23
-
24
- /**
25
- * Per-request options that apply to all SDK operations.
26
- */
27
- export type S2RequestOptions = {
28
- /**
29
- * Optional abort signal to cancel the underlying HTTP request.
30
- */
31
- signal?: AbortSignal;
32
- };
33
-
34
- /**
35
- * Helper type that flattens an endpoint's `body`, `path` and `query` into a
36
- * single object. This lets public methods accept one coherent argument object
37
- * instead of three separate bags.
38
- */
39
- export type DataToObject<T> = (T extends { body?: infer B }
40
- ? B extends undefined | never
41
- ? {}
42
- : B
43
- : {}) &
44
- (T extends { path?: infer P } ? (P extends undefined | never ? {} : P) : {}) &
45
- (T extends { query?: infer Q } ? (Q extends undefined | never ? {} : Q) : {});
package/src/error.ts DELETED
@@ -1,58 +0,0 @@
1
- /**
2
- * Rich error type used by the SDK to surface HTTP and protocol errors.
3
- *
4
- * - `code` is the service error code when available.
5
- * - `status` is the HTTP status code.
6
- * - `data` may include structured error details (e.g. for conditional failures).
7
- */
8
- export class S2Error extends Error {
9
- public readonly code?: string;
10
- public readonly status?: number;
11
- public readonly data?: Record<string, unknown>;
12
-
13
- constructor({
14
- message,
15
- code,
16
- status,
17
- data,
18
- }: {
19
- /** Human-readable error message. */
20
- message: string;
21
- code?: string;
22
- status?: number;
23
- /** Additional error details when available. */
24
- data?: Record<string, unknown>;
25
- }) {
26
- // Include full data in the error message for better visibility
27
- const dataStr = data ? `\nData: ${JSON.stringify(data, null, 2)}` : "";
28
- super(`${message}${dataStr}`);
29
- this.code = code;
30
- this.status = status;
31
- this.data = data;
32
- this.name = "S2Error";
33
- }
34
-
35
- public toString() {
36
- return `${this.message} (code: ${this.code}, status: ${this.status}, data: ${JSON.stringify(this.data, null, 2)})`;
37
- }
38
-
39
- public toJSON() {
40
- return {
41
- message: this.message,
42
- code: this.code,
43
- status: this.status,
44
- data: this.data,
45
- };
46
- }
47
-
48
- public [Symbol.for("nodejs.util.inspect.custom")]() {
49
- return {
50
- name: "S2Error",
51
- message: this.message,
52
- code: this.code,
53
- status: this.status,
54
- data: this.data,
55
- stack: this.stack,
56
- };
57
- }
58
- }