@dev-crew-berlin/enter-js-utils 0.97.5 → 0.98.10

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.
@@ -1,4 +1,4 @@
1
- import APIBase, { FetchOptions, RequestBody } from './api-base';
1
+ import APIBase, { FetchOptions, RequestBody, SubscribeOptions } from './api-base';
2
2
  import { APIResult } from '../lib';
3
3
  import { Attendee } from '../models/attendee';
4
4
  import { Event, EventInput } from '../models';
@@ -9,7 +9,7 @@ import { User } from '../models/user';
9
9
  import { Variable } from '../models/variable';
10
10
  import { components } from '../generated/api-schema';
11
11
  import { Email } from '../models/email';
12
- export type { APICredentials } from './api-base';
12
+ export type { APICredentials, SubscribeOptions } from './api-base';
13
13
  /**
14
14
  * api client for the enter backend
15
15
  */
@@ -73,7 +73,10 @@ declare class API extends APIBase {
73
73
  instanceName: string;
74
74
  filter?: string;
75
75
  includeDeleted?: boolean;
76
- }, options?: FetchOptions): Promise<APIResult<Attendee[]>>;
76
+ }, options?: FetchOptions): Promise<APIResult<{
77
+ attendees: Attendee[];
78
+ eventCursor: string | null;
79
+ }>>;
77
80
  /**
78
81
  * @category Attendees
79
82
  */
@@ -160,7 +163,10 @@ declare class API extends APIBase {
160
163
  /**
161
164
  * @category Events
162
165
  */
163
- createEvents(args: EventInput[], options?: FetchOptions): Promise<APIResult<null>>;
166
+ createEvents(args: EventInput[], options?: FetchOptions): Promise<APIResult<{
167
+ created: number;
168
+ eventCursors: Record<string, string>;
169
+ }>>;
164
170
  /**
165
171
  * Subscribe to the SSE event stream. Yields events as they arrive.
166
172
  * Use `for await` to consume events, and `break` or `return` to unsubscribe.
@@ -175,6 +181,6 @@ declare class API extends APIBase {
175
181
  subscribeToEvents(args: {
176
182
  instanceName: string;
177
183
  eventType?: string[];
178
- }, options?: FetchOptions): AsyncGenerator<Event>;
184
+ }, options?: SubscribeOptions): AsyncGenerator<Event>;
179
185
  }
180
186
  export default API;
@@ -86,11 +86,20 @@ class API extends APIBase {
86
86
  if (args.includeDeleted) {
87
87
  query.append('include_deleted', 'true');
88
88
  }
89
- const instanceName = args.instanceName;
90
- const queryString = `?${query.toString()}`;
91
- const result = await this.get(`/instances/${instanceName}/attendees${queryString}`, options);
89
+ const qs = query.toString();
90
+ const endpoint = `/instances/${args.instanceName}/attendees${qs ? `?${qs}` : ''}`;
91
+ const result = await this.fetchResponse(endpoint, {
92
+ method: 'GET',
93
+ headers: this.buildHeaders(),
94
+ ...options
95
+ });
92
96
  if (!result.success) return result;
93
- return success(result.data.map(attendeeJSON => new Attendee(attendeeJSON)));
97
+ const data = await result.data.json();
98
+ const eventCursor = result.data.headers.get('X-Event-Cursor');
99
+ return success({
100
+ attendees: data.map(attendeeJSON => new Attendee(attendeeJSON)),
101
+ eventCursor: eventCursor ?? null
102
+ });
94
103
  }
95
104
 
96
105
  /**
@@ -219,7 +228,18 @@ class API extends APIBase {
219
228
  * @category Events
220
229
  */
221
230
  async createEvents(args, options = {}) {
222
- return this.post(`/events`, args, options);
231
+ const result = await this.fetchResponse(`/events`, {
232
+ method: 'POST',
233
+ headers: this.buildHeaders(),
234
+ body: JSON.stringify(args),
235
+ ...options
236
+ });
237
+ if (!result.success) return result;
238
+ const json = await result.data.json();
239
+ return success({
240
+ created: json.created,
241
+ eventCursors: json.event_cursors ?? {}
242
+ });
223
243
  }
224
244
 
225
245
  /**