@s2-dev/streamstore 0.3.1 → 0.3.7

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/endpoints.d.ts ADDED
@@ -0,0 +1,67 @@
1
+ type Authority = string;
2
+ type BasinName = string;
3
+ /**
4
+ * S2 cloud environment to connect with.
5
+ */
6
+ export declare enum S2Cloud {
7
+ /** S2 running on AWS */
8
+ Aws = "aws"
9
+ }
10
+ /**
11
+ * Endpoint for connecting to an S2 basin.
12
+ */
13
+ export declare enum BasinEndpointKind {
14
+ ParentZone = "ParentZone",
15
+ Direct = "Direct"
16
+ }
17
+ export type BasinEndpoint = {
18
+ kind: BasinEndpointKind.ParentZone;
19
+ authority: Authority;
20
+ } | {
21
+ kind: BasinEndpointKind.Direct;
22
+ authority: Authority;
23
+ };
24
+ /**
25
+ * Endpoints for the S2 environment.
26
+ *
27
+ * You can find the S2 endpoints in our [documentation](https://s2.dev/docs/interface/endpoints)
28
+ */
29
+ export declare class S2Endpoints {
30
+ /** Used by `AccountService` requests */
31
+ account: Authority;
32
+ /** Used by `BasinService` and `StreamService` requests */
33
+ basin: BasinEndpoint;
34
+ constructor(account: Authority, basin: BasinEndpoint);
35
+ /**
36
+ * Get S2 endpoints for the specified cloud.
37
+ */
38
+ static forCloud(cloud: S2Cloud): S2Endpoints;
39
+ /**
40
+ * Get S2 endpoints for the specified cell.
41
+ */
42
+ static forCell(cloud: S2Cloud, cellId: string): S2Endpoints;
43
+ /**
44
+ * Get S2 endpoints from environment variables.
45
+ *
46
+ * The following environment variables are used:
47
+ * - `S2_CLOUD`: Valid S2 cloud name. Defaults to AWS.
48
+ * - `S2_ACCOUNT_ENDPOINT`: Overrides the account endpoint.
49
+ * - `S2_BASIN_ENDPOINT`: Overrides the basin endpoint. The prefix `"{basin}."` indicates the
50
+ * basin endpoint is `ParentZone` else `Direct`.
51
+ */
52
+ static fromEnv(): S2Endpoints;
53
+ }
54
+ /**
55
+ * Client kind for different S2 services
56
+ */
57
+ export type ClientKind = {
58
+ kind: 'Account';
59
+ } | {
60
+ kind: 'Basin';
61
+ basin: BasinName;
62
+ };
63
+ export declare const ClientKind: {
64
+ toAuthority(kind: ClientKind, endpoints: S2Endpoints): Authority;
65
+ };
66
+ export {};
67
+ //# sourceMappingURL=endpoints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["src/endpoints.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,MAAM,CAAC;AAGxB,KAAK,SAAS,GAAG,MAAM,CAAC;AAExB;;GAEG;AACH,oBAAY,OAAO;IACf,wBAAwB;IACxB,GAAG,QAAQ;CACd;AAED;;GAEG;AACH,oBAAY,iBAAiB;IACzB,UAAU,eAAe;IACzB,MAAM,WAAW;CACpB;AAED,MAAM,MAAM,aAAa,GAAG;IACxB,IAAI,EAAE,iBAAiB,CAAC,UAAU,CAAC;IACnC,SAAS,EAAE,SAAS,CAAC;CACxB,GAAG;IACA,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE,SAAS,CAAC;CACxB,CAAC;AASF;;;;GAIG;AACH,qBAAa,WAAW;IACpB,wCAAwC;IACjC,OAAO,EAAE,SAAS,CAAC;IAC1B,0DAA0D;IACnD,KAAK,EAAE,aAAa,CAAC;gBAEhB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,aAAa;IAKpD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW;IAW5C;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW;IAW3D;;;;;;;;OAQG;IACH,MAAM,CAAC,OAAO,IAAI,WAAW;CA8ChC;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAChB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,SAAS,CAAA;CAAE,CAAC;AAE1C,eAAO,MAAM,UAAU;sBACD,UAAU,aAAa,WAAW,GAAG,SAAS;CAanE,CAAC"}
package/endpoints.js ADDED
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientKind = exports.S2Endpoints = exports.BasinEndpointKind = exports.S2Cloud = void 0;
4
+ /**
5
+ * S2 cloud environment to connect with.
6
+ */
7
+ var S2Cloud;
8
+ (function (S2Cloud) {
9
+ /** S2 running on AWS */
10
+ S2Cloud["Aws"] = "aws";
11
+ })(S2Cloud || (exports.S2Cloud = S2Cloud = {}));
12
+ /**
13
+ * Endpoint for connecting to an S2 basin.
14
+ */
15
+ var BasinEndpointKind;
16
+ (function (BasinEndpointKind) {
17
+ BasinEndpointKind["ParentZone"] = "ParentZone";
18
+ BasinEndpointKind["Direct"] = "Direct";
19
+ })(BasinEndpointKind || (exports.BasinEndpointKind = BasinEndpointKind = {}));
20
+ class S2EndpointError extends Error {
21
+ constructor(message) {
22
+ super(message);
23
+ this.name = 'S2EndpointError';
24
+ }
25
+ }
26
+ /**
27
+ * Endpoints for the S2 environment.
28
+ *
29
+ * You can find the S2 endpoints in our [documentation](https://s2.dev/docs/interface/endpoints)
30
+ */
31
+ class S2Endpoints {
32
+ constructor(account, basin) {
33
+ this.account = account;
34
+ this.basin = basin;
35
+ }
36
+ /**
37
+ * Get S2 endpoints for the specified cloud.
38
+ */
39
+ static forCloud(cloud) {
40
+ const authority = `${cloud}.s2.dev`;
41
+ return new S2Endpoints(authority, {
42
+ kind: BasinEndpointKind.ParentZone,
43
+ authority: `b.${cloud}.s2.dev`
44
+ });
45
+ }
46
+ /**
47
+ * Get S2 endpoints for the specified cell.
48
+ */
49
+ static forCell(cloud, cellId) {
50
+ const cellEndpoint = `${cellId}.o.${cloud}.s2.dev`;
51
+ return new S2Endpoints(cellEndpoint, {
52
+ kind: BasinEndpointKind.Direct,
53
+ authority: cellEndpoint
54
+ });
55
+ }
56
+ /**
57
+ * Get S2 endpoints from environment variables.
58
+ *
59
+ * The following environment variables are used:
60
+ * - `S2_CLOUD`: Valid S2 cloud name. Defaults to AWS.
61
+ * - `S2_ACCOUNT_ENDPOINT`: Overrides the account endpoint.
62
+ * - `S2_BASIN_ENDPOINT`: Overrides the basin endpoint. The prefix `"{basin}."` indicates the
63
+ * basin endpoint is `ParentZone` else `Direct`.
64
+ */
65
+ static fromEnv() {
66
+ let cloud;
67
+ try {
68
+ const cloudEnv = process.env['S2_CLOUD'] || S2Cloud.Aws;
69
+ if (Object.values(S2Cloud).includes(cloudEnv)) {
70
+ cloud = cloudEnv;
71
+ }
72
+ else {
73
+ throw new S2EndpointError(`Invalid S2_CLOUD: ${cloudEnv}`);
74
+ }
75
+ }
76
+ catch (err) {
77
+ const error = err;
78
+ throw new S2EndpointError(`Invalid S2_CLOUD: ${error.message}`);
79
+ }
80
+ const endpoints = S2Endpoints.forCloud(cloud);
81
+ const accountEndpoint = process.env['S2_ACCOUNT_ENDPOINT'];
82
+ if (accountEndpoint !== undefined) {
83
+ if (typeof accountEndpoint !== 'string') {
84
+ throw new S2EndpointError('Invalid S2_ACCOUNT_ENDPOINT: not string');
85
+ }
86
+ endpoints.account = accountEndpoint;
87
+ }
88
+ const basinEndpoint = process.env['S2_BASIN_ENDPOINT'];
89
+ if (basinEndpoint !== undefined) {
90
+ if (typeof basinEndpoint !== 'string') {
91
+ throw new S2EndpointError('Invalid S2_BASIN_ENDPOINT: not string');
92
+ }
93
+ if (basinEndpoint.startsWith('{basin}.')) {
94
+ const parentZone = basinEndpoint.substring(7);
95
+ endpoints.basin = {
96
+ kind: BasinEndpointKind.ParentZone,
97
+ authority: parentZone
98
+ };
99
+ }
100
+ else {
101
+ endpoints.basin = {
102
+ kind: BasinEndpointKind.Direct,
103
+ authority: basinEndpoint
104
+ };
105
+ }
106
+ }
107
+ return endpoints;
108
+ }
109
+ }
110
+ exports.S2Endpoints = S2Endpoints;
111
+ exports.ClientKind = {
112
+ toAuthority(kind, endpoints) {
113
+ switch (kind.kind) {
114
+ case 'Account':
115
+ return endpoints.account;
116
+ case 'Basin':
117
+ switch (endpoints.basin.kind) {
118
+ case BasinEndpointKind.ParentZone:
119
+ return `${kind.basin}.${endpoints.basin.authority}`;
120
+ case BasinEndpointKind.Direct:
121
+ return endpoints.basin.authority;
122
+ }
123
+ }
124
+ }
125
+ };
126
+ //# sourceMappingURL=endpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoints.js","sourceRoot":"","sources":["src/endpoints.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,wBAAwB;IACxB,sBAAW,CAAA;AACf,CAAC,EAHW,OAAO,uBAAP,OAAO,QAGlB;AAED;;GAEG;AACH,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IACzB,8CAAyB,CAAA;IACzB,sCAAiB,CAAA;AACrB,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B;AAUD,MAAM,eAAgB,SAAQ,KAAK;IAC/B,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAClC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAa,WAAW;IAMpB,YAAY,OAAkB,EAAE,KAAoB;QAChD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAc;QAC1B,MAAM,SAAS,GAAG,GAAG,KAAK,SAAS,CAAC;QACpC,OAAO,IAAI,WAAW,CAClB,SAAS,EACT;YACI,IAAI,EAAE,iBAAiB,CAAC,UAAU;YAClC,SAAS,EAAE,KAAK,KAAK,SAAS;SACjC,CACJ,CAAC;IACN,CAAC;IAED;;OAEG;IACH,MAAM,CAA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AS,EAAE,CAAC;YAC9B,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE,CAAC;gBACpC,MAAM,IAAI,eAAe,CAAC,uCAAuC,CAAC,CAAC;YACvE,CAAC;YAED,IAAI,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBACvC,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBAC9C,SAAS,CAAC,KAAK,GAAG;oBACd,IAAI,EAAE,iBAAiB,CAAC,UAAU;oBAClC,SAAS,EAAE,UAAU;iBACxB,CAAC;YACN,CAAC;iBAAM,CAAC;gBACJ,SAAS,CAAC,KAAK,GAAG;oBACd,IAAI,EAAE,iBAAiB,CAAC,MAAM;oBAC9B,SAAS,EAAE,aAAa;iBAC3B,CAAC;YACN,CAAC;QACL,CAAC;QAED,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AA9FD,kCA8FC;AASY,QAAA,UAAU,GAAG;IACtB,WAAW,CAAC,IAAgB,EAAE,SAAsB;QAChD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAChB,KAAK,SAAS;gBACV,OAAO,SAAS,CAAC,OAAO,CAAC;YAC7B,KAAK,OAAO;gBACR,QAAQ,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;oBAC3B,KAAK,iBAAiB,CAAC,UAAU;wBAC7B,OAAO,GAAG,IAAI,CAAC,KAAK,IAAI,SAAS,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;oBACxD,KAAK,iBAAiB,CAAC,MAAM;wBACzB,OAAO,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC;gBACzC,CAAC;QACT,CAAC;IACL,CAAC;CACJ,CAAC"}
package/index.extras.d.ts CHANGED
@@ -1,25 +1,31 @@
1
1
  import { AppendOutput, BasinConfig, BasinInfo, CheckTailResponse, CreateBasinRequest, CreateStreamRequest, Output, ReadResponse, StreamConfig, StreamInfo } from "./models/components";
2
2
  import { ListBasinsRequest, ListBasinsResponse, ListStreamsRequest, ListStreamsResponse, ReadRequest as ReadRequestInner, AppendRequest as AppendRequestInner } from "./models/operations";
3
3
  import { PageIterator } from "./types";
4
- import { EventStream } from "./lib/event-streams";
5
- export type ReadRequest = Omit<ReadRequestInner, 'stream'>;
6
- export type AppendRequest = Omit<AppendRequestInner, 'stream'>;
4
+ import { S2Endpoints } from "./endpoints";
5
+ export type ReadRequest = Omit<ReadRequestInner, "stream">;
6
+ export type AppendRequest = Omit<AppendRequestInner, "stream">;
7
7
  export type { GetBasinConfigRequest, ListBasinsRequest, ListBasinsResponse, ListStreamsRequest, ListStreamsResponse, ReconfigureBasinRequest, } from "./models/operations";
8
- export type { BasinConfig, BasinInfo, CheckTailResponse, CreateBasinRequest, CreateStreamRequest, Output, ReadResponse, StreamConfig, StreamInfo } from "./models/components";
9
- export declare function genS2RequestToken(): string;
8
+ export type { BasinConfig, BasinInfo, CheckTailResponse, CreateBasinRequest, CreateStreamRequest, Output, ReadResponse, StreamConfig, StreamInfo, } from "./models/components";
9
+ export * from "./endpoints";
10
+ export type S2ClientConfig = {
11
+ authToken?: string;
12
+ requestTimeout?: number;
13
+ endpoints?: S2Endpoints;
14
+ };
10
15
  export declare class S2Client {
11
- private authToken;
16
+ private config;
12
17
  private _account?;
13
18
  get account(): S2Account;
14
19
  private _basin?;
15
20
  basin(basinName: string): S2Basin;
16
- constructor(authToken: string);
21
+ constructor(config?: S2ClientConfig);
17
22
  }
18
23
  declare class S2Account {
19
24
  private _account;
20
- private requestOptions;
21
- private authToken;
22
- constructor(authToken: string);
25
+ private config;
26
+ private readonly accountURLSuffx;
27
+ constructor(config: S2ClientConfig);
28
+ get URL(): string | undefined;
23
29
  basin(basinName: string): S2Basin;
24
30
  listBasins(request?: ListBasinsRequest): Promise<PageIterator<ListBasinsResponse, {
25
31
  cursor: string;
@@ -32,10 +38,12 @@ declare class S2Account {
32
38
  declare class S2Basin {
33
39
  private _basin;
34
40
  private _stream;
35
- private readonly basinURLSuffx;
36
- private requestOptions;
37
41
  private basinName;
38
- constructor(authToken: string, basinName: string);
42
+ private config;
43
+ private clientKind;
44
+ private readonly basinURLSuffx;
45
+ private get URL();
46
+ constructor(basinName: string, config: S2ClientConfig);
39
47
  stream(streamName: string): Stream;
40
48
  listStreams(request: ListStreamsRequest): Promise<PageIterator<ListStreamsResponse, {
41
49
  cursor: string;
@@ -47,12 +55,16 @@ declare class S2Basin {
47
55
  }
48
56
  declare class Stream {
49
57
  private _stream;
50
- private basinName;
51
58
  private streamName;
59
+ private config;
60
+ private clientKind;
52
61
  private readonly basinURLSuffx;
53
- constructor(basinName: string, streamName: string);
62
+ private get basinURL();
63
+ constructor(basinName: string, streamName: string, config: S2ClientConfig);
54
64
  checkTail(): Promise<CheckTailResponse | undefined>;
55
- read(request: ReadRequest, stream?: boolean): Promise<EventStream<ReadResponse> | Output | undefined>;
56
65
  append(request: AppendRequest): Promise<AppendOutput | undefined>;
66
+ read(request: ReadRequest): Promise<Output | undefined>;
67
+ readStream(request: ReadRequest): AsyncGenerator<ReadResponse, void, undefined>;
57
68
  }
69
+ export declare function genS2RequestToken(): string;
58
70
  //# sourceMappingURL=index.extras.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.extras.d.ts","sourceRoot":"","sources":["src/index.extras.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEvL,OAAO,EAEH,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EAInB,WAAW,IAAI,gBAAgB,EAC/B,aAAa,IAAI,kBAAkB,EACtC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAQvC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAA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C;IAMnD,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAMjE,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMtD,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,YAAY,EAAE,IAAI,EAAE,SAAS,CAAC;CAwCzF;AAED,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C"}
package/index.extras.js CHANGED
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.S2Client = void 0;
4
18
  exports.genS2RequestToken = genS2RequestToken;
@@ -9,51 +23,49 @@ const basin_1 = require("./sdk/basin");
9
23
  const account_1 = require("./sdk/account");
10
24
  const uuid_1 = require("uuid");
11
25
  const basinDeleteStream_1 = require("./funcs/basinDeleteStream");
12
- function genS2RequestToken() {
13
- return (0, uuid_1.v4)().replace(/-/g, '');
14
- }
26
+ const endpoints_1 = require("./endpoints");
27
+ __exportStar(require("./endpoints"), exports);
28
+ const defaultS2ClientConfig = {
29
+ requestTimeout: 3000,
30
+ endpoints: endpoints_1.S2Endpoints.forCloud(endpoints_1.S2Cloud.Aws),
31
+ };
15
32
  class S2Client {
16
33
  get account() {
17
- return (this._account ?? (this._account = new S2Account(this.authToken)));
34
+ return (this._account ?? (this._account = new S2Account(this.config)));
18
35
  }
19
36
  basin(basinName) {
20
- return (this._basin ?? (this._basin = new S2Basin(this.authToken, basinName)));
37
+ return (this._basin ?? (this._basin = new S2Basin(basinName, this.config)));
21
38
  }
22
- constructor(authToken) {
23
- this.authToken = authToken;
39
+ constructor(config) {
40
+ this.config = { ...defaultS2ClientConfig, ...config };
24
41
  }
25
42
  }
26
43
  exports.S2Client = S2Client;
27
44
  class S2Account {
28
- constructor(authToken) {
29
- this._account = new account_1.Account({ bearerAuth: authToken });
30
- this.authToken = authToken;
31
- this.requestOptions = {
32
- timeoutMs: 3000,
33
- retries: {
34
- strategy: 'backoff',
35
- backoff: {
36
- initialInterval: 100,
37
- maxInterval: 3000,
38
- exponent: 2,
39
- maxElapsedTime: 6000,
40
- },
41
- retryConnectionErrors: true,
42
- },
43
- retryCodes: ['500', '503', '504'],
44
- };
45
+ constructor(config) {
46
+ this.accountURLSuffx = "/v1alpha";
47
+ this._account = new account_1.Account({
48
+ ...(config.authToken !== undefined && { bearerAuth: config.authToken }),
49
+ ...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
50
+ });
51
+ this.config = config;
52
+ }
53
+ get URL() {
54
+ if (!this.config.endpoints)
55
+ return undefined;
56
+ return `https://${endpoints_1.ClientKind.toAuthority({ kind: "Account" }, this.config.endpoints)}${this.accountURLSuffx}`;
45
57
  }
46
58
  basin(basinName) {
47
- return new S2Basin(this.authToken, basinName);
59
+ return new S2Basin(basinName, this.config);
48
60
  }
49
61
  async listBasins(request) {
50
- return this._account.listBasins(request ?? {}, this.requestOptions);
62
+ const url = this.URL;
63
+ return this._account.listBasins(request ?? {}, url ? { serverURL: url } : {});
51
64
  }
52
65
  async getBasinConfig(basin) {
53
- const _request = {
54
- basin,
55
- };
56
- return (await this._account.getBasinConfig(_request, this.requestOptions)).basinConfig;
66
+ const _request = { basin };
67
+ const url = this.URL;
68
+ return (await this._account.getBasinConfig(_request, url ? { serverURL: url } : {})).basinConfig;
57
69
  }
58
70
  async createBasin(basin, request) {
59
71
  const _request = {
@@ -61,10 +73,12 @@ class S2Account {
61
73
  s2RequestToken: genS2RequestToken(),
62
74
  createBasinRequest: request ?? {},
63
75
  };
64
- return (await this._account.createBasin(_request, this.requestOptions)).basinInfo;
76
+ const url = this.URL;
77
+ return (await this._account.createBasin(_request, url ? { serverURL: url } : {})).basinInfo;
65
78
  }
66
79
  async deleteBasin(basin, if_exists) {
67
- const response = await (0, accountDeleteBasin_1.accountDeleteBasin)(this._account, { basin }, this.requestOptions);
80
+ const url = this.URL;
81
+ const response = await (0, accountDeleteBasin_1.accountDeleteBasin)(this._account, { basin }, url ? { serverURL: url } : {});
68
82
  if (if_exists && response.error instanceof errors_1.NotFoundError)
69
83
  return;
70
84
  if (response.error)
@@ -72,56 +86,46 @@ class S2Account {
72
86
  return;
73
87
  }
74
88
  async reconfigureBasin(basin, config) {
75
- const _request = {
76
- basin,
77
- basinConfig: config,
78
- };
79
- return (await this._account.reconfigureBasin(_request, this.requestOptions)).basinConfig;
89
+ const url = this.URL;
90
+ const _request = { basin, basinConfig: config };
91
+ return (await this._account.reconfigureBasin(_request, url ? { serverURL: url } : {})).basinConfig;
80
92
  }
81
93
  }
82
94
  class S2Basin {
83
- constructor(authToken, basinName) {
84
- this.basinURLSuffx = 'b.aws.s2.dev/v1alpha';
85
- this._basin = new basin_1.Basin({ bearerAuth: authToken });
95
+ get URL() {
96
+ return `https://${endpoints_1.ClientKind.toAuthority(this.clientKind, this.config.endpoints ?? endpoints_1.S2Endpoints.forCloud(endpoints_1.S2Cloud.Aws))}${this.basinURLSuffx}`;
97
+ }
98
+ constructor(basinName, config) {
99
+ this.basinURLSuffx = "/v1alpha";
100
+ this._basin = new basin_1.Basin({
101
+ ...(config.authToken !== undefined && { bearerAuth: config.authToken }),
102
+ ...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
103
+ });
104
+ this.config = config;
105
+ this.clientKind = { kind: "Basin", basin: basinName };
86
106
  this.basinName = basinName;
87
- this.requestOptions = {
88
- timeoutMs: 3000,
89
- retries: {
90
- strategy: 'backoff',
91
- backoff: {
92
- initialInterval: 100,
93
- maxInterval: 3000,
94
- exponent: 2,
95
- maxElapsedTime: 6000,
96
- },
97
- retryConnectionErrors: true,
98
- },
99
- retryCodes: ['500', '503', '504'],
100
- };
101
107
  }
102
108
  stream(streamName) {
103
- return (this._stream ?? (this._stream = new Stream(this.basinName, streamName)));
109
+ return (this._stream ?? (this._stream = new Stream(this.basinName, streamName, this.config)));
104
110
  }
105
111
  async listStreams(request) {
106
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
107
- return this._basin.listStreams(request, { serverURL: basinURL, ...this.requestOptions });
112
+ return this._basin.listStreams(request, { serverURL: this.URL });
108
113
  }
109
114
  async getStreamConfig(stream) {
110
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
111
- return (await this._basin.getStreamConfig({ stream }, { serverURL: basinURL, ...this.requestOptions })).streamConfig;
115
+ return (await this._basin.getStreamConfig({ stream }, { serverURL: this.URL })).streamConfig;
112
116
  }
113
117
  async createStream(stream, request) {
114
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
115
118
  const _request = {
116
119
  stream,
117
120
  s2RequestToken: genS2RequestToken(),
118
121
  createStreamRequest: request ?? {},
119
122
  };
120
- return (await this._basin.createStream(_request, { serverURL: basinURL, ...this.requestOptions })).streamInfo;
123
+ return (await this._basin.createStream(_request, { serverURL: this.URL })).streamInfo;
121
124
  }
122
125
  async deleteStream(stream, if_exists) {
123
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
124
- const response = await (0, basinDeleteStream_1.basinDeleteStream)(this._basin, { stream }, { serverURL: basinURL, ...this.requestOptions });
126
+ const response = await (0, basinDeleteStream_1.basinDeleteStream)(this._basin, { stream }, {
127
+ serverURL: this.URL,
128
+ });
125
129
  if (if_exists && response instanceof errors_1.NotFoundError)
126
130
  return;
127
131
  if (response.error)
@@ -129,32 +133,70 @@ class S2Basin {
129
133
  return;
130
134
  }
131
135
  async reconfigureStream(stream, config) {
132
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
133
- return (await this._basin.reconfigureStream({ stream, streamConfig: config }, { serverURL: basinURL, ...this.requestOptions })).streamConfig;
136
+ return (await this._basin.reconfigureStream({ stream, streamConfig: config }, { serverURL: this.URL })).streamConfig;
134
137
  }
135
138
  }
136
139
  class Stream {
137
- constructor(basinName, streamName) {
138
- this.basinURLSuffx = 'b.aws.s2.dev/v1alpha';
139
- this.basinName = basinName;
140
+ get basinURL() {
141
+ return `https://${endpoints_1.ClientKind.toAuthority(this.clientKind, this.config.endpoints ?? endpoints_1.S2Endpoints.forCloud(endpoints_1.S2Cloud.Aws))}${this.basinURLSuffx}`;
142
+ }
143
+ constructor(basinName, streamName, config) {
144
+ this.basinURLSuffx = "/v1alpha";
145
+ this.config = config;
146
+ this.clientKind = { kind: "Basin", basin: basinName };
140
147
  this.streamName = streamName;
141
- this._stream = new stream_1.Stream();
148
+ this._stream = new stream_1.Stream({
149
+ ...(config.authToken !== undefined && { bearerAuth: config.authToken }),
150
+ ...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
151
+ });
142
152
  }
143
153
  async checkTail() {
144
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
145
- return (await this._stream.checkTail({ stream: this.streamName }, { serverURL: basinURL }))
146
- .checkTailResponse;
147
- }
148
- async read(request, stream) {
149
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
150
- return (await this._stream.read({ ...request, stream: this.streamName }, stream
151
- ? { serverURL: basinURL, acceptHeaderOverride: stream_1.ReadAcceptEnum.textEventStream }
152
- : { serverURL: basinURL }))
153
- .readResponse;
154
+ return (await this._stream.checkTail({ stream: this.streamName }, { serverURL: this.basinURL })).checkTailResponse;
154
155
  }
155
156
  async append(request) {
156
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
157
- return (await this._stream.append({ ...request, stream: this.streamName }, { serverURL: basinURL })).appendOutput;
157
+ return (await this._stream.append({ ...request, stream: this.streamName }, { serverURL: this.basinURL })).appendOutput;
158
+ }
159
+ async read(request) {
160
+ return (await this._stream.read({ ...request, stream: this.streamName }, { serverURL: this.basinURL })).output;
161
+ }
162
+ async *readStream(request) {
163
+ let currentRequest = { ...request };
164
+ while (true) {
165
+ let stream;
166
+ try {
167
+ const response = await this._stream.read({ ...currentRequest, stream: this.streamName }, {
168
+ serverURL: this.basinURL,
169
+ timeoutMs: -1, // disable only for streaming
170
+ acceptHeaderOverride: stream_1.ReadAcceptEnum.textEventStream
171
+ });
172
+ stream = response.readResponse;
173
+ if (!stream)
174
+ return;
175
+ for await (const event of stream) {
176
+ yield event;
177
+ if (event.event === 'output') {
178
+ const output = event;
179
+ if ('batch' in output.data) {
180
+ const batch = output.data.batch;
181
+ if (batch.records && batch.records.length > 0) {
182
+ const lastRecord = batch.records[batch.records.length - 1];
183
+ if (lastRecord) {
184
+ currentRequest = { ...currentRequest, startSeqNum: lastRecord.seqNum + 1 };
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ return;
191
+ }
192
+ catch (error) {
193
+ console.error("Error while reading stream", error);
194
+ return;
195
+ }
196
+ }
158
197
  }
159
198
  }
199
+ function genS2RequestToken() {
200
+ return (0, uuid_1.v4)().replace(/-/g, "");
201
+ }
160
202
  //# sourceMappingURL=index.extras.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.extras.js","sourceRoot":"","sources":["src/index.extras.ts"],"names":[],"mappings":";;;AAsCA,8CAEC;AAxCD,mEAAgE;AAGhE,4CAAgD;AAehD,yCAAqE;AACrE,uCAAkD;AAClD,2CAAwD;AAExD,+BAA0B;AAC1B,iEAA8D;AAe9D,SAAgB,iBAAiB;IAC7B,OAAO,IAAA,SAAE,GAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,MAAa,QAAQ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AAK,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;gBACnD,OAAO;YACX,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAED,SAAgB,iBAAiB;IAC7B,OAAO,IAAA,SAAE,GAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC"}
package/jsr.json CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  {
4
4
  "name": "@s2-dev/streamstore",
5
- "version": "0.3.1",
5
+ "version": "0.3.7",
6
6
  "exports": {
7
7
  ".": "./src/index.ts",
8
8
  "./models/errors": "./src/models/errors/index.ts",
package/lib/config.d.ts CHANGED
@@ -27,8 +27,8 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
27
27
  export declare const SDK_METADATA: {
28
28
  readonly language: "typescript";
29
29
  readonly openapiDocVersion: "1.0.0";
30
- readonly sdkVersion: "0.3.1";
31
- readonly genVersion: "2.505.0";
32
- readonly userAgent: "speakeasy-sdk/typescript 0.3.1 2.505.0 1.0.0 @s2-dev/streamstore";
30
+ readonly sdkVersion: "0.3.7";
31
+ readonly genVersion: "2.506.0";
32
+ readonly userAgent: "speakeasy-sdk/typescript 0.3.7 2.506.0 1.0.0 @s2-dev/streamstore";
33
33
  };
34
34
  //# sourceMappingURL=config.d.ts.map
package/lib/config.js CHANGED
@@ -28,8 +28,8 @@ function serverURLFromOptions(options) {
28
28
  exports.SDK_METADATA = {
29
29
  language: "typescript",
30
30
  openapiDocVersion: "1.0.0",
31
- sdkVersion: "0.3.1",
32
- genVersion: "2.505.0",
33
- userAgent: "speakeasy-sdk/typescript 0.3.1 2.505.0 1.0.0 @s2-dev/streamstore",
31
+ sdkVersion: "0.3.7",
32
+ genVersion: "2.506.0",
33
+ userAgent: "speakeasy-sdk/typescript 0.3.7 2.506.0 1.0.0 @s2-dev/streamstore",
34
34
  };
35
35
  //# sourceMappingURL=config.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s2-dev/streamstore",
3
- "version": "0.3.1",
3
+ "version": "0.3.7",
4
4
  "author": "Speakeasy",
5
5
  "main": "./index.js",
6
6
  "sideEffects": false,
@@ -19,6 +19,7 @@
19
19
  "devDependencies": {
20
20
  "@eslint/js": "^9.19.0",
21
21
  "@types/jsonpath": "^0.2.4",
22
+ "@types/node": "^22.13.1",
22
23
  "@types/uuid": "^9.0.8",
23
24
  "eslint": "^9.19.0",
24
25
  "globals": "^15.14.0",
@@ -0,0 +1,159 @@
1
+ type Authority = string;
2
+
3
+ // Basin Name
4
+ type BasinName = string;
5
+
6
+ /**
7
+ * S2 cloud environment to connect with.
8
+ */
9
+ export enum S2Cloud {
10
+ /** S2 running on AWS */
11
+ Aws = "aws"
12
+ }
13
+
14
+ /**
15
+ * Endpoint for connecting to an S2 basin.
16
+ */
17
+ export enum BasinEndpointKind {
18
+ ParentZone = "ParentZone",
19
+ Direct = "Direct"
20
+ }
21
+
22
+ export type BasinEndpoint = {
23
+ kind: BasinEndpointKind.ParentZone;
24
+ authority: Authority;
25
+ } | {
26
+ kind: BasinEndpointKind.Direct;
27
+ authority: Authority;
28
+ };
29
+
30
+ class S2EndpointError extends Error {
31
+ constructor(message: string) {
32
+ super(message);
33
+ this.name = 'S2EndpointError';
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Endpoints for the S2 environment.
39
+ *
40
+ * You can find the S2 endpoints in our [documentation](https://s2.dev/docs/interface/endpoints)
41
+ */
42
+ export class S2Endpoints {
43
+ /** Used by `AccountService` requests */
44
+ public account: Authority;
45
+ /** Used by `BasinService` and `StreamService` requests */
46
+ public basin: BasinEndpoint;
47
+
48
+ constructor(account: Authority, basin: BasinEndpoint) {
49
+ this.account = account;
50
+ this.basin = basin;
51
+ }
52
+
53
+ /**
54
+ * Get S2 endpoints for the specified cloud.
55
+ */
56
+ static forCloud(cloud: S2Cloud): S2Endpoints {
57
+ const authority = `${cloud}.s2.dev`;
58
+ return new S2Endpoints(
59
+ authority,
60
+ {
61
+ kind: BasinEndpointKind.ParentZone,
62
+ authority: `b.${cloud}.s2.dev`
63
+ }
64
+ );
65
+ }
66
+
67
+ /**
68
+ * Get S2 endpoints for the specified cell.
69
+ */
70
+ static forCell(cloud: S2Cloud, cellId: string): S2Endpoints {
71
+ const cellEndpoint = `${cellId}.o.${cloud}.s2.dev`;
72
+ return new S2Endpoints(
73
+ cellEndpoint,
74
+ {
75
+ kind: BasinEndpointKind.Direct,
76
+ authority: cellEndpoint
77
+ }
78
+ );
79
+ }
80
+
81
+ /**
82
+ * Get S2 endpoints from environment variables.
83
+ *
84
+ * The following environment variables are used:
85
+ * - `S2_CLOUD`: Valid S2 cloud name. Defaults to AWS.
86
+ * - `S2_ACCOUNT_ENDPOINT`: Overrides the account endpoint.
87
+ * - `S2_BASIN_ENDPOINT`: Overrides the basin endpoint. The prefix `"{basin}."` indicates the
88
+ * basin endpoint is `ParentZone` else `Direct`.
89
+ */
90
+ static fromEnv(): S2Endpoints {
91
+ let cloud: S2Cloud;
92
+ try {
93
+ const cloudEnv = process.env['S2_CLOUD'] || S2Cloud.Aws;
94
+ if (Object.values(S2Cloud).includes(cloudEnv as S2Cloud)) {
95
+ cloud = cloudEnv as S2Cloud;
96
+ } else {
97
+ throw new S2EndpointError(`Invalid S2_CLOUD: ${cloudEnv}`);
98
+ }
99
+ } catch (err) {
100
+ const error = err as Error;
101
+ throw new S2EndpointError(`Invalid S2_CLOUD: ${error.message}`);
102
+ }
103
+
104
+ const endpoints = S2Endpoints.forCloud(cloud);
105
+
106
+ const accountEndpoint = process.env['S2_ACCOUNT_ENDPOINT'];
107
+ if (accountEndpoint !== undefined) {
108
+ if (typeof accountEndpoint !== 'string') {
109
+ throw new S2EndpointError('Invalid S2_ACCOUNT_ENDPOINT: not string');
110
+ }
111
+ endpoints.account = accountEndpoint;
112
+ }
113
+
114
+ const basinEndpoint = process.env['S2_BASIN_ENDPOINT'];
115
+ if (basinEndpoint !== undefined) {
116
+ if (typeof basinEndpoint !== 'string') {
117
+ throw new S2EndpointError('Invalid S2_BASIN_ENDPOINT: not string');
118
+ }
119
+
120
+ if (basinEndpoint.startsWith('{basin}.')) {
121
+ const parentZone = basinEndpoint.substring(7);
122
+ endpoints.basin = {
123
+ kind: BasinEndpointKind.ParentZone,
124
+ authority: parentZone
125
+ };
126
+ } else {
127
+ endpoints.basin = {
128
+ kind: BasinEndpointKind.Direct,
129
+ authority: basinEndpoint
130
+ };
131
+ }
132
+ }
133
+
134
+ return endpoints;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Client kind for different S2 services
140
+ */
141
+ export type ClientKind =
142
+ | { kind: 'Account' }
143
+ | { kind: 'Basin'; basin: BasinName };
144
+
145
+ export const ClientKind = {
146
+ toAuthority(kind: ClientKind, endpoints: S2Endpoints): Authority {
147
+ switch (kind.kind) {
148
+ case 'Account':
149
+ return endpoints.account;
150
+ case 'Basin':
151
+ switch (endpoints.basin.kind) {
152
+ case BasinEndpointKind.ParentZone:
153
+ return `${kind.basin}.${endpoints.basin.authority}`;
154
+ case BasinEndpointKind.Direct:
155
+ return endpoints.basin.authority;
156
+ }
157
+ }
158
+ }
159
+ };
@@ -1,6 +1,17 @@
1
1
  import { accountDeleteBasin } from "./funcs/accountDeleteBasin";
2
- import { RequestOptions } from "./lib/sdks";
3
- import { AppendOutput, BasinConfig, BasinInfo, CheckTailResponse, CreateBasinRequest, CreateStreamRequest, Output, ReadResponse, StreamConfig, StreamInfo } from "./models/components";
2
+ import {
3
+ AppendOutput,
4
+ BasinConfig,
5
+ BasinInfo,
6
+ CheckTailResponse,
7
+ CreateBasinRequest,
8
+ CreateStreamRequest,
9
+ Output,
10
+ ReadResponse,
11
+ ReadResponseOutput,
12
+ StreamConfig,
13
+ StreamInfo,
14
+ } from "./models/components";
4
15
  import { NotFoundError } from "./models/errors";
5
16
  import {
6
17
  GetBasinConfigRequest,
@@ -20,12 +31,13 @@ import { Stream as InnerStream, ReadAcceptEnum } from "./sdk/stream";
20
31
  import { Basin as InnerBasin } from "./sdk/basin";
21
32
  import { Account as InnerAccount } from "./sdk/account";
22
33
 
23
- import { v4 } from 'uuid';
34
+ import { v4 } from "uuid";
24
35
  import { basinDeleteStream } from "./funcs/basinDeleteStream";
25
36
  import { EventStream } from "./lib/event-streams";
37
+ import { ClientKind, S2Cloud, S2Endpoints } from "./endpoints";
26
38
 
27
- export type ReadRequest = Omit<ReadRequestInner, 'stream'>;
28
- export type AppendRequest = Omit<AppendRequestInner, 'stream'>;
39
+ export type ReadRequest = Omit<ReadRequestInner, "stream">;
40
+ export type AppendRequest = Omit<AppendRequestInner, "stream">;
29
41
  export type {
30
42
  GetBasinConfigRequest,
31
43
  ListBasinsRequest,
@@ -34,68 +46,83 @@ export type {
34
46
  ListStreamsResponse,
35
47
  ReconfigureBasinRequest,
36
48
  } from "./models/operations";
37
- export type { BasinConfig, BasinInfo, CheckTailResponse, CreateBasinRequest, CreateStreamRequest, Output, ReadResponse, StreamConfig, StreamInfo } from "./models/components";
49
+ export type {
50
+ BasinConfig,
51
+ BasinInfo,
52
+ CheckTailResponse,
53
+ CreateBasinRequest,
54
+ CreateStreamRequest,
55
+ Output,
56
+ ReadResponse,
57
+ StreamConfig,
58
+ StreamInfo,
59
+ } from "./models/components";
38
60
 
39
- export function genS2RequestToken(): string {
40
- return v4().replace(/-/g, '');
41
- }
61
+ export * from "./endpoints";
62
+
63
+ export type S2ClientConfig = {
64
+ authToken?: string;
65
+ requestTimeout?: number;
66
+ endpoints?: S2Endpoints;
67
+ };
68
+
69
+ const defaultS2ClientConfig: S2ClientConfig = {
70
+ requestTimeout: 3000,
71
+ endpoints: S2Endpoints.forCloud(S2Cloud.Aws),
72
+ };
42
73
 
43
74
  export class S2Client {
44
- private authToken: string;
75
+ private config: S2ClientConfig;
45
76
  private _account?: S2Account;
46
77
  get account(): S2Account {
47
- return (this._account ??= new S2Account(this.authToken));
78
+ return (this._account ??= new S2Account(this.config));
48
79
  }
49
80
 
50
81
  private _basin?: S2Basin;
51
82
  basin(basinName: string): S2Basin {
52
- return (this._basin ??= new S2Basin(this.authToken, basinName));
83
+ return (this._basin ??= new S2Basin(basinName, this.config));
53
84
  }
54
85
 
55
- constructor(authToken: string) {
56
- this.authToken = authToken;
86
+ constructor(config?: S2ClientConfig) {
87
+ this.config = { ...defaultS2ClientConfig, ...config };
57
88
  }
58
89
  }
59
90
 
60
91
  class S2Account {
61
92
  private _account: InnerAccount;
62
- private requestOptions: RequestOptions;
63
- private authToken: string;
64
-
65
- constructor(authToken: string) {
66
- this._account = new InnerAccount({ bearerAuth: authToken });
67
- this.authToken = authToken;
68
- this.requestOptions = {
69
- timeoutMs: 3000,
70
- retries: {
71
- strategy: 'backoff',
72
- backoff: {
73
- initialInterval: 100,
74
- maxInterval: 3000,
75
- exponent: 2,
76
- maxElapsedTime: 6000,
77
- },
78
- retryConnectionErrors: true,
79
- },
80
- retryCodes: ['500', '503', '504'],
81
- };
93
+ private config: S2ClientConfig;
94
+ private readonly accountURLSuffx = "/v1alpha";
95
+
96
+ constructor(config: S2ClientConfig) {
97
+ this._account = new InnerAccount({
98
+ ...(config.authToken !== undefined && { bearerAuth: config.authToken }),
99
+ ...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
100
+ });
101
+ this.config = config;
102
+ }
103
+
104
+ get URL(): string | undefined {
105
+ if (!this.config.endpoints) return undefined;
106
+ return `https://${ClientKind.toAuthority({ kind: "Account" }, this.config.endpoints)}${this.accountURLSuffx}`;
82
107
  }
83
108
 
84
109
  basin(basinName: string): S2Basin {
85
- return new S2Basin(this.authToken, basinName);
110
+ return new S2Basin(basinName, this.config);
86
111
  }
87
112
 
88
113
  async listBasins(
89
- request?: ListBasinsRequest,
114
+ request?: ListBasinsRequest
90
115
  ): Promise<PageIterator<ListBasinsResponse, { cursor: string }>> {
91
- return this._account.listBasins(request ?? {}, this.requestOptions);
116
+ const url = this.URL;
117
+ return this._account.listBasins(request ?? {}, url ? { serverURL: url } : {});
92
118
  }
93
119
 
94
120
  async getBasinConfig(basin: string): Promise<BasinConfig | undefined> {
95
- const _request: GetBasinConfigRequest = {
96
- basin,
97
- };
98
- return (await this._account.getBasinConfig(_request, this.requestOptions)).basinConfig;
121
+ const _request: GetBasinConfigRequest = { basin };
122
+ const url = this.URL;
123
+ return (await this._account.getBasinConfig(_request
124
+ , url ? { serverURL: url } : {}
125
+ )).basinConfig;
99
126
  }
100
127
 
101
128
  async createBasin(basin: string, request?: CreateBasinRequest): Promise<BasinInfo | undefined> {
@@ -104,144 +131,178 @@ class S2Account {
104
131
  s2RequestToken: genS2RequestToken(),
105
132
  createBasinRequest: request ?? {},
106
133
  };
107
- return (await this._account.createBasin(_request, this.requestOptions)).basinInfo;
134
+ const url = this.URL;
135
+ return (await this._account.createBasin(_request,
136
+ url ? { serverURL: url } : {}
137
+ )).basinInfo;
108
138
  }
109
139
 
110
140
  async deleteBasin(basin: string, if_exists?: boolean): Promise<void | undefined> {
111
- const response = await accountDeleteBasin(this._account, { basin }, this.requestOptions);
141
+ const url = this.URL;
142
+ const response = await accountDeleteBasin(this._account, { basin }, url ? { serverURL: url } : {});
112
143
  if (if_exists && response.error instanceof NotFoundError) return;
113
144
  if (response.error) throw new Error(response.error.message);
114
145
  return;
115
146
  }
116
147
 
117
148
  async reconfigureBasin(basin: string, config: BasinConfig): Promise<BasinConfig | undefined> {
118
- const _request: ReconfigureBasinRequest = {
119
- basin,
120
- basinConfig: config,
121
- };
122
- return (await this._account.reconfigureBasin(_request, this.requestOptions)).basinConfig;
149
+ const url = this.URL;
150
+ const _request: ReconfigureBasinRequest = { basin, basinConfig: config };
151
+ return (await this._account.reconfigureBasin(_request
152
+ , url ? { serverURL: url } : {}
153
+ )).basinConfig;
123
154
  }
124
155
  }
125
156
 
126
157
  class S2Basin {
127
158
  private _basin: InnerBasin;
128
159
  private _stream!: Stream;
129
- private readonly basinURLSuffx = 'b.aws.s2.dev/v1alpha';
130
- private requestOptions: RequestOptions;
131
160
  private basinName: string;
161
+ private config: S2ClientConfig;
162
+ private clientKind: ClientKind;
163
+ private readonly basinURLSuffx = "/v1alpha";
132
164
 
133
- constructor(authToken: string, basinName: string) {
134
- this._basin = new InnerBasin({ bearerAuth: authToken });
165
+ private get URL(): string {
166
+ return `https://${ClientKind.toAuthority(this.clientKind, this.config.endpoints ?? S2Endpoints.forCloud(S2Cloud.Aws))}${this.basinURLSuffx}`;
167
+ }
168
+
169
+ constructor(basinName: string, config: S2ClientConfig) {
170
+ this._basin = new InnerBasin({
171
+ ...(config.authToken !== undefined && { bearerAuth: config.authToken }),
172
+ ...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
173
+ });
174
+ this.config = config;
175
+ this.clientKind = { kind: "Basin" as const, basin: basinName };
135
176
  this.basinName = basinName;
136
- this.requestOptions = {
137
- timeoutMs: 3000,
138
- retries: {
139
- strategy: 'backoff',
140
- backoff: {
141
- initialInterval: 100,
142
- maxInterval: 3000,
143
- exponent: 2,
144
- maxElapsedTime: 6000,
145
- },
146
- retryConnectionErrors: true,
147
- },
148
- retryCodes: ['500', '503', '504'],
149
- };
150
177
  }
151
178
 
152
179
  stream(streamName: string): Stream {
153
- return (this._stream ??= new Stream(this.basinName, streamName));
180
+ return (this._stream ??= new Stream(this.basinName, streamName, this.config));
154
181
  }
155
182
 
156
183
  async listStreams(
157
- request: ListStreamsRequest,
184
+ request: ListStreamsRequest
158
185
  ): Promise<PageIterator<ListStreamsResponse, { cursor: string }>> {
159
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
160
- return this._basin.listStreams(request, { serverURL: basinURL, ...this.requestOptions });
186
+ return this._basin.listStreams(request, { serverURL: this.URL });
161
187
  }
162
188
 
163
189
  async getStreamConfig(stream: string): Promise<StreamConfig | undefined> {
164
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
165
190
  return (
166
- await this._basin.getStreamConfig({ stream }, { serverURL: basinURL, ...this.requestOptions })
191
+ await this._basin.getStreamConfig({ stream }, { serverURL: this.URL })
167
192
  ).streamConfig;
168
193
  }
169
194
 
170
- async createStream(
171
- stream: string,
172
- request?: CreateStreamRequest,
173
- ): Promise<StreamInfo | undefined> {
174
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
195
+ async createStream(stream: string, request?: CreateStreamRequest): Promise<StreamInfo | undefined> {
175
196
  const _request: CreateStreamRequestInner = {
176
197
  stream,
177
198
  s2RequestToken: genS2RequestToken(),
178
199
  createStreamRequest: request ?? {},
179
200
  };
180
-
181
201
  return (
182
- await this._basin.createStream(_request, { serverURL: basinURL, ...this.requestOptions })
202
+ await this._basin.createStream(_request, { serverURL: this.URL })
183
203
  ).streamInfo;
184
204
  }
185
205
 
186
206
  async deleteStream(stream: string, if_exists?: boolean): Promise<void | undefined> {
187
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
188
- const response = await basinDeleteStream(this._basin, { stream }, { serverURL: basinURL, ...this.requestOptions });
207
+ const response = await basinDeleteStream(this._basin, { stream }, {
208
+ serverURL: this.URL,
209
+ });
189
210
  if (if_exists && response instanceof NotFoundError) return;
190
211
  if (response.error) throw new Error(response.error.message);
191
212
  return;
192
213
  }
193
214
 
194
215
  async reconfigureStream(stream: string, config: StreamConfig): Promise<StreamConfig | undefined> {
195
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
196
216
  return (
197
217
  await this._basin.reconfigureStream(
198
218
  { stream, streamConfig: config },
199
- { serverURL: basinURL, ...this.requestOptions },
219
+ { serverURL: this.URL }
200
220
  )
201
221
  ).streamConfig;
202
222
  }
203
223
  }
204
224
 
205
-
206
225
  class Stream {
207
226
  private _stream: InnerStream;
208
- private basinName: string;
209
227
  private streamName: string;
210
- private readonly basinURLSuffx = 'b.aws.s2.dev/v1alpha';
228
+ private config: S2ClientConfig;
229
+ private clientKind: ClientKind;
230
+ private readonly basinURLSuffx = "/v1alpha";
211
231
 
212
- constructor(basinName: string, streamName: string) {
213
- this.basinName = basinName;
232
+ private get basinURL(): string {
233
+ return `https://${ClientKind.toAuthority(this.clientKind, this.config.endpoints ?? S2Endpoints.forCloud(S2Cloud.Aws))}${this.basinURLSuffx}`;
234
+ }
235
+
236
+ constructor(basinName: string, streamName: string, config: S2ClientConfig) {
237
+ this.config = config;
238
+ this.clientKind = { kind: "Basin" as const, basin: basinName };
214
239
  this.streamName = streamName;
215
- this._stream = new InnerStream();
240
+ this._stream = new InnerStream({
241
+ ...(config.authToken !== undefined && { bearerAuth: config.authToken }),
242
+ ...(config.requestTimeout !== undefined && { timeoutMs: config.requestTimeout })
243
+ });
216
244
  }
217
245
 
218
246
  async checkTail(): Promise<CheckTailResponse | undefined> {
219
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
220
- return (await this._stream.checkTail({ stream: this.streamName }, { serverURL: basinURL }))
221
- .checkTailResponse;
222
- }
223
-
224
- async read(
225
- request: ReadRequest,
226
- stream?: boolean
227
- ): Promise<EventStream<ReadResponse> | Output | undefined> {
228
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
229
- return (await this._stream.read(
230
- { ...request, stream: this.streamName },
231
- stream
232
- ? { serverURL: basinURL, acceptHeaderOverride: ReadAcceptEnum.textEventStream }
233
- : { serverURL: basinURL }
234
- ))
235
- .readResponse;
236
- }
237
-
238
- async append(
239
- request: AppendRequest,
240
- ): Promise<AppendOutput | undefined> {
241
- const basinURL = `${this.basinName}.${this.basinURLSuffx}`;
242
- return (await this._stream.append(
243
- { ...request, stream: this.streamName },
244
- { serverURL: basinURL }
245
- )).appendOutput;
247
+ return (
248
+ await this._stream.checkTail({ stream: this.streamName }, { serverURL: this.basinURL })
249
+ ).checkTailResponse;
250
+ }
251
+
252
+ async append(request: AppendRequest): Promise<AppendOutput | undefined> {
253
+ return (
254
+ await this._stream.append({ ...request, stream: this.streamName }, { serverURL: this.basinURL })
255
+ ).appendOutput;
256
+ }
257
+
258
+ async read(request: ReadRequest): Promise<Output | undefined> {
259
+ return (
260
+ await this._stream.read({ ...request, stream: this.streamName }, { serverURL: this.basinURL })
261
+ ).output;
262
+ }
263
+
264
+ async *readStream(request: ReadRequest): AsyncGenerator<ReadResponse, void, undefined> {
265
+ let currentRequest: ReadRequest = { ...request };
266
+
267
+ while (true) {
268
+ let stream: EventStream<ReadResponse> | undefined;
269
+ try {
270
+ const response = await this._stream.read(
271
+ { ...currentRequest, stream: this.streamName },
272
+ {
273
+ serverURL: this.basinURL,
274
+ timeoutMs: -1, // disable only for streaming
275
+ acceptHeaderOverride: ReadAcceptEnum.textEventStream
276
+ }
277
+ );
278
+ stream = response.readResponse;
279
+ if (!stream) return;
280
+
281
+ for await (const event of stream) {
282
+ yield event;
283
+
284
+ if (event.event === 'output') {
285
+ const output = event as ReadResponseOutput;
286
+ if ('batch' in output.data) {
287
+ const batch = output.data.batch;
288
+ if (batch.records && batch.records.length > 0) {
289
+ const lastRecord = batch.records[batch.records.length - 1];
290
+ if (lastRecord) {
291
+ currentRequest = { ...currentRequest, startSeqNum: lastRecord.seqNum + 1 };
292
+ }
293
+ }
294
+ }
295
+ }
296
+ }
297
+ return;
298
+ } catch (error) {
299
+ console.error("Error while reading stream", error);
300
+ return;
301
+ }
302
+ }
246
303
  }
247
304
  }
305
+
306
+ export function genS2RequestToken(): string {
307
+ return v4().replace(/-/g, "");
308
+ }
package/src/lib/config.ts CHANGED
@@ -54,7 +54,7 @@ export function serverURLFromOptions(options: SDKOptions): URL | null {
54
54
  export const SDK_METADATA = {
55
55
  language: "typescript",
56
56
  openapiDocVersion: "1.0.0",
57
- sdkVersion: "0.3.1",
58
- genVersion: "2.505.0",
59
- userAgent: "speakeasy-sdk/typescript 0.3.1 2.505.0 1.0.0 @s2-dev/streamstore",
57
+ sdkVersion: "0.3.7",
58
+ genVersion: "2.506.0",
59
+ userAgent: "speakeasy-sdk/typescript 0.3.7 2.506.0 1.0.0 @s2-dev/streamstore",
60
60
  } as const;