@dev-crew-berlin/enter-js-utils 0.96.1 → 0.97.3

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.
@@ -36,6 +36,8 @@ export default class APIBase {
36
36
  onLogout: (reason?: string) => void;
37
37
  });
38
38
  private static fetchResult;
39
+ private buildHeaders;
40
+ private fetchResponse;
39
41
  /**
40
42
  * @category Auth
41
43
  */
@@ -54,6 +56,7 @@ export default class APIBase {
54
56
  expires: Date;
55
57
  }>>;
56
58
  private fetchFromEnter;
59
+ protected stream<T>(endpoint: string, options?: FetchOptions): AsyncGenerator<T>;
57
60
  protected get<Path extends keyof paths>(endpoint: Path, options: FetchOptions): Promise<APIResult<ResponseType<Path, 'get'>>>;
58
61
  protected post<Path extends keyof paths>(endpoint: Path, data: RequestBody<Path, 'post'>, options: FetchOptions): Promise<APIResult<ResponseType<Path, 'post'>>>;
59
62
  protected put<Path extends keyof paths>(endpoint: Path, data: RequestBody<Path, 'put'>, options: FetchOptions): Promise<APIResult<ResponseType<Path, 'put'>>>;
@@ -1,4 +1,5 @@
1
1
  import jws from 'jws';
2
+ import { EventSourceParserStream } from 'eventsource-parser/stream';
2
3
  import { failure, success } from '../lib';
3
4
  export default class APIBase {
4
5
  constructor(args) {
@@ -16,6 +17,53 @@ export default class APIBase {
16
17
  return failure(e);
17
18
  }
18
19
  }
20
+ buildHeaders(extraHeaders = {}) {
21
+ return {
22
+ Authorization: `bearer ${this.credentials.accessToken}`,
23
+ 'Content-Type': 'application/json',
24
+ 'X-Enter-Device-Name': this.deviceName,
25
+ 'X-Enter-Requester-Id': this.requesterId,
26
+ ...extraHeaders
27
+ };
28
+ }
29
+ async fetchResponse(endpoint, init) {
30
+ const res = await APIBase.fetchResult(`${this.credentials.url}${endpoint}`, init);
31
+ if (!res.success) {
32
+ return failure([{
33
+ type: 'network-error',
34
+ message: res.error.message,
35
+ endpoint
36
+ }]);
37
+ }
38
+ if (res.data.status === 401) {
39
+ if (this.isLoggedIn) this.logout();
40
+ return failure([{
41
+ type: 'http-error',
42
+ statusCode: 401,
43
+ endpoint,
44
+ message: res.data.statusText
45
+ }]);
46
+ }
47
+ if (res.data.status >= 300) {
48
+ try {
49
+ const error = await res.data.json();
50
+ return failure([{
51
+ type: 'http-error',
52
+ statusCode: res.data.status,
53
+ message: error.error ?? res.data.statusText,
54
+ endpoint
55
+ }]);
56
+ } catch {
57
+ return failure([{
58
+ type: 'http-error',
59
+ statusCode: res.data.status,
60
+ message: `invalid response from backend: ${res.data.status} (${res.data.statusText}) for: ${endpoint}`,
61
+ endpoint
62
+ }]);
63
+ }
64
+ }
65
+ return success(res.data);
66
+ }
19
67
 
20
68
  /**
21
69
  * @category Auth
@@ -74,58 +122,52 @@ export default class APIBase {
74
122
  }
75
123
  async fetchFromEnter(endpoint, method, data, options) {
76
124
  const body = data !== null ? JSON.stringify(data) : null;
77
- const headers = {
78
- Authorization: `bearer ${this.credentials.accessToken}`,
79
- 'Content-Type': 'application/json',
80
- 'X-Enter-Device-Name': this.deviceName,
81
- 'X-Enter-Requester-Id': this.requesterId
82
- };
83
- const res = await APIBase.fetchResult(`${this.credentials.url}${endpoint}`, {
125
+ const res = await this.fetchResponse(endpoint, {
84
126
  method: method.toUpperCase(),
85
- headers,
127
+ headers: this.buildHeaders(),
86
128
  body,
87
129
  ...options
88
130
  });
89
- if (!res.success) {
90
- return failure([{
91
- type: 'network-error',
92
- message: res.error.message,
93
- endpoint
94
- }]);
95
- }
96
- if (res.data.status === 401) {
97
- if (this.isLoggedIn) this.logout();
98
- return failure([{
99
- type: 'http-error',
100
- statusCode: 401,
101
- endpoint,
102
- message: res.data.statusText
103
- }]);
104
- }
105
- if (res.data.status >= 300) {
106
- try {
107
- const error = await res.data.json();
108
- return failure([{
109
- type: 'http-error',
110
- statusCode: res.data.status,
111
- message: error.error ?? res.data.statusText,
112
- endpoint
113
- }]);
114
- } catch (e) {
115
- return failure([{
116
- type: 'http-error',
117
- statusCode: res.data.status,
118
- message: `invalid response from backend: ${res.data.status} (${res.data.statusText}) for: ${endpoint}`,
119
- endpoint
120
- }]);
121
- }
122
- }
131
+ if (!res.success) return res;
123
132
 
124
133
  // HTTP status 204 means no content so we can't parse it as json
125
134
  if (res.data.status === 204) return success(null);
126
135
  const json = await res.data.json();
127
136
  return success(json);
128
137
  }
138
+ async *stream(endpoint, options = {}) {
139
+ const res = await this.fetchResponse(endpoint, {
140
+ method: 'GET',
141
+ headers: this.buildHeaders({
142
+ Accept: 'text/event-stream'
143
+ }),
144
+ ...options
145
+ });
146
+ if (!res.success) {
147
+ throw new Error(res.error[0]?.message ?? 'Unknown error');
148
+ }
149
+ if (!res.data.body) {
150
+ throw new Error('Response body is null');
151
+ }
152
+ const reader = res.data.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).getReader();
153
+ try {
154
+ while (true) {
155
+ const {
156
+ done,
157
+ value: event
158
+ } = await reader.read();
159
+ if (done) break;
160
+ if (event.data === '[DONE]') return;
161
+ try {
162
+ yield JSON.parse(event.data);
163
+ } catch {
164
+ console.warn('[SSE] Failed to parse event data:', event.data);
165
+ }
166
+ }
167
+ } finally {
168
+ reader.releaseLock();
169
+ }
170
+ }
129
171
  async get(endpoint, options) {
130
172
  const rawResponse = await this.fetchFromEnter(endpoint, 'get', undefined, options);
131
173
  if (!rawResponse.success) return rawResponse;
@@ -161,5 +161,20 @@ declare class API extends APIBase {
161
161
  * @category Events
162
162
  */
163
163
  createEvents(args: Event[], options?: FetchOptions): Promise<APIResult<null>>;
164
+ /**
165
+ * Subscribe to the SSE event stream. Yields events as they arrive.
166
+ * Use `for await` to consume events, and `break` or `return` to unsubscribe.
167
+ *
168
+ * @example
169
+ * for await (const event of api.subscribeToEvents({ instanceName: 'my-instance' })) {
170
+ * console.log(event)
171
+ * }
172
+ *
173
+ * @category Events
174
+ */
175
+ subscribeToEvents(args: {
176
+ instanceName: string;
177
+ eventType?: string[];
178
+ }, options?: FetchOptions): AsyncGenerator<Event>;
164
179
  }
165
180
  export default API;
@@ -221,5 +221,23 @@ class API extends APIBase {
221
221
  async createEvents(args, options = {}) {
222
222
  return this.post(`/events`, args, options);
223
223
  }
224
+
225
+ /**
226
+ * Subscribe to the SSE event stream. Yields events as they arrive.
227
+ * Use `for await` to consume events, and `break` or `return` to unsubscribe.
228
+ *
229
+ * @example
230
+ * for await (const event of api.subscribeToEvents({ instanceName: 'my-instance' })) {
231
+ * console.log(event)
232
+ * }
233
+ *
234
+ * @category Events
235
+ */
236
+ async *subscribeToEvents(args, options = {}) {
237
+ const query = new URLSearchParams();
238
+ query.append('instance', args.instanceName);
239
+ args.eventType?.forEach(t => query.append('event_type', t));
240
+ yield* this.stream(`/events/stream?${query.toString()}`, options);
241
+ }
224
242
  }
225
243
  export default API;
@@ -25,6 +25,10 @@ export type paths = {
25
25
  */
26
26
  post: operations["create_events_events_post"];
27
27
  };
28
+ "/events/stream": {
29
+ /** Get Events */
30
+ get: operations["get_events_events_stream_get"];
31
+ };
28
32
  "/instances/{instance_name}/fields": {
29
33
  /** Fields */
30
34
  get: operations["fields_instances__instance_name__fields_get"];
@@ -93,13 +97,103 @@ export type paths = {
93
97
  export type webhooks = Record<string, never>;
94
98
  export type components = {
95
99
  schemas: {
100
+ /**
101
+ * Attendee
102
+ * @description A guest attending an event
103
+ */
104
+ Attendee: {
105
+ /** Id */
106
+ id: string;
107
+ /** Index */
108
+ index: number;
109
+ /** Auth Code */
110
+ auth_code?: string | null;
111
+ /** Instance */
112
+ instance: string;
113
+ /**
114
+ * Name
115
+ * @default
116
+ */
117
+ name?: string;
118
+ /**
119
+ * Userdata
120
+ * @default {}
121
+ */
122
+ userdata?: {
123
+ [key: string]: string | boolean | number | string[] | components["schemas"]["FileReference"] | null;
124
+ };
125
+ /** @default [] */
126
+ tags?: components["schemas"]["StorableSet_str_-Output"];
127
+ /** @default [] */
128
+ dynamic_tags?: components["schemas"]["StorableSet_str_-Output"];
129
+ /** @default [] */
130
+ changes?: components["schemas"]["StorableSet_str_-Output"];
131
+ /** Language */
132
+ language?: string | null;
133
+ /**
134
+ * Time
135
+ * Format: date-time
136
+ */
137
+ time?: string;
138
+ /**
139
+ * Updated
140
+ * Format: date-time
141
+ */
142
+ updated?: string;
143
+ /**
144
+ * Created By
145
+ * @default uknown
146
+ */
147
+ created_by?: string;
148
+ /**
149
+ * Rsvp
150
+ * @default {}
151
+ */
152
+ rsvp?: {
153
+ [key: string]: components["schemas"]["RSVP-Output"] | null;
154
+ };
155
+ /**
156
+ * Checkin
157
+ * @default {}
158
+ */
159
+ checkin?: {
160
+ [key: string]: components["schemas"]["Checkins-Output"];
161
+ };
162
+ /** @default [] */
163
+ branches?: components["schemas"]["StorableSet_str_-Output"];
164
+ /**
165
+ * @default {
166
+ * "isCompanion": false,
167
+ * "companionNames": {}
168
+ * }
169
+ */
170
+ companions?: components["schemas"]["RootModel_Union_Companion__MainGuest__-Output"];
171
+ payment?: components["schemas"]["Payment"] | null;
172
+ /**
173
+ * Emails
174
+ * @default {}
175
+ */
176
+ emails?: {
177
+ [key: string]: components["schemas"]["EmailStatus-Output"];
178
+ };
179
+ /**
180
+ * Log
181
+ * @default []
182
+ */
183
+ log?: Record<string, unknown>[];
184
+ /**
185
+ * Deleted
186
+ * @default false
187
+ */
188
+ deleted?: boolean;
189
+ };
96
190
  /**
97
191
  * AttendeeAuthCodeRequested
98
192
  * @description A request to set an auth_code for the attendee
99
193
  *
100
194
  * This will generate and set an auth code for the attendee. If none is already set.
101
195
  */
102
- AttendeeAuthCodeRequested: {
196
+ "AttendeeAuthCodeRequested-Input": {
103
197
  /**
104
198
  * Id
105
199
  * Format: uuid
@@ -116,11 +210,34 @@ export type components = {
116
210
  /** Attendeeid */
117
211
  attendeeId: string;
118
212
  };
213
+ /**
214
+ * AttendeeAuthCodeRequested
215
+ * @description A request to set an auth_code for the attendee
216
+ *
217
+ * This will generate and set an auth code for the attendee. If none is already set.
218
+ */
219
+ "AttendeeAuthCodeRequested-Output": {
220
+ /**
221
+ * Id
222
+ * Format: uuid
223
+ */
224
+ id: string;
225
+ /**
226
+ * Event
227
+ * @default attendee-auth-code-requested
228
+ * @constant
229
+ */
230
+ event: "attendee-auth-code-requested";
231
+ /** Instancename */
232
+ instanceName: string;
233
+ /** Attendeeid */
234
+ attendeeId: string;
235
+ };
119
236
  /**
120
237
  * AttendeeCreatedEvent
121
238
  * @description New attendee was created
122
239
  */
123
- AttendeeCreatedEvent: {
240
+ "AttendeeCreatedEvent-Input": {
124
241
  /**
125
242
  * Id
126
243
  * Format: uuid
@@ -136,11 +253,33 @@ export type components = {
136
253
  /** Instancename */
137
254
  instanceName: string;
138
255
  };
256
+ /**
257
+ * AttendeeCreatedEvent
258
+ * @description New attendee was created
259
+ */
260
+ "AttendeeCreatedEvent-Output": {
261
+ /**
262
+ * Id
263
+ * Format: uuid
264
+ */
265
+ id: string;
266
+ /**
267
+ * Event
268
+ * @default attendee-created
269
+ * @constant
270
+ */
271
+ event: "attendee-created";
272
+ attendee: components["schemas"]["PublicAttendee-Output"];
273
+ /** Instancename */
274
+ instanceName: string;
275
+ /** Attendeeid */
276
+ attendeeId: string;
277
+ };
139
278
  /**
140
279
  * AttendeeDeletedEvent
141
280
  * @description Attendee was deleted
142
281
  */
143
- AttendeeDeletedEvent: {
282
+ "AttendeeDeletedEvent-Input": {
144
283
  /**
145
284
  * Id
146
285
  * Format: uuid
@@ -159,6 +298,29 @@ export type components = {
159
298
  /** Final */
160
299
  final: boolean;
161
300
  };
301
+ /**
302
+ * AttendeeDeletedEvent
303
+ * @description Attendee was deleted
304
+ */
305
+ "AttendeeDeletedEvent-Output": {
306
+ /**
307
+ * Id
308
+ * Format: uuid
309
+ */
310
+ id: string;
311
+ /**
312
+ * Event
313
+ * @default attendee-deleted
314
+ * @constant
315
+ */
316
+ event: "attendee-deleted";
317
+ /** Attendeeid */
318
+ attendeeId: string;
319
+ /** Instancename */
320
+ instanceName: string;
321
+ /** Final */
322
+ final: boolean;
323
+ };
162
324
  /** AttendeeId */
163
325
  AttendeeId: {
164
326
  /** Attendeeid */
@@ -175,7 +337,7 @@ export type components = {
175
337
  * This triggers mails that are atomatically sent on response.
176
338
  * Alternatively you can set `is_edit` to trigger email that are sent on edit instead.
177
339
  */
178
- AttendeeRespondedEvent: {
340
+ "AttendeeRespondedEvent-Input": {
179
341
  /**
180
342
  * Id
181
343
  * Format: uuid
@@ -203,8 +365,64 @@ export type components = {
203
365
  /** Isedit */
204
366
  isEdit: boolean;
205
367
  };
368
+ /**
369
+ * AttendeeRespondedEvent
370
+ * @description Attendee response status was changed. Meaning the rsvp value was updated.
371
+ *
372
+ * This triggers mails that are atomatically sent on response.
373
+ * Alternatively you can set `is_edit` to trigger email that are sent on edit instead.
374
+ */
375
+ "AttendeeRespondedEvent-Output": {
376
+ /**
377
+ * Id
378
+ * Format: uuid
379
+ */
380
+ id: string;
381
+ /**
382
+ * Event
383
+ * @default attendee-responded
384
+ * @constant
385
+ */
386
+ event: "attendee-responded";
387
+ /** Instancename */
388
+ instanceName: string;
389
+ /** Attendeeid */
390
+ attendeeId: string;
391
+ /** Rsvp */
392
+ rsvp: {
393
+ [key: string]: components["schemas"]["RSVP-Output"] | null;
394
+ };
395
+ /**
396
+ * Responsetime
397
+ * Format: date-time
398
+ */
399
+ responseTime: string;
400
+ /** Isedit */
401
+ isEdit: boolean;
402
+ };
403
+ /**
404
+ * AttendeeRestoredEvent
405
+ * @description Attendee was restored
406
+ */
407
+ AttendeeRestoredEvent: {
408
+ /**
409
+ * Id
410
+ * Format: uuid
411
+ */
412
+ id: string;
413
+ /**
414
+ * Event
415
+ * @default attendee-restored
416
+ * @constant
417
+ */
418
+ event: "attendee-restored";
419
+ /** Attendeeid */
420
+ attendeeId: string;
421
+ /** Instancename */
422
+ instanceName: string;
423
+ };
206
424
  /** AttendeeUpdate */
207
- AttendeeUpdate: {
425
+ "AttendeeUpdate-Input": {
208
426
  /** Userdata */
209
427
  userdata?: {
210
428
  [key: string]: string | boolean | number | string[] | components["schemas"]["FileReference"] | null;
@@ -227,11 +445,35 @@ export type components = {
227
445
  /** Deletedbranches */
228
446
  deletedBranches?: string[];
229
447
  };
448
+ /** AttendeeUpdate */
449
+ "AttendeeUpdate-Output": {
450
+ /** Userdata */
451
+ userdata?: {
452
+ [key: string]: string | boolean | number | string[] | components["schemas"]["FileReference"] | null;
453
+ };
454
+ /** Tags */
455
+ tags?: string[];
456
+ /** Deletedtags */
457
+ deletedTags?: string[];
458
+ /** Language */
459
+ language?: string;
460
+ /** Rsvp */
461
+ rsvp?: {
462
+ [key: string]: components["schemas"]["RSVP-Output"] | null;
463
+ };
464
+ companions?: components["schemas"]["RootModel_Union_Companion__MainGuest__-Output"];
465
+ payment?: components["schemas"]["Payment"] | null;
466
+ partialPayment?: components["schemas"]["PartialPayment"];
467
+ /** Branches */
468
+ branches?: string[];
469
+ /** Deletedbranches */
470
+ deletedBranches?: string[];
471
+ };
230
472
  /**
231
473
  * AttendeeUpdatedEvent
232
474
  * @description Attendee was updated. This includes `userdata` but also other data such as `payment`, `rsvp` or `tags`
233
475
  */
234
- AttendeeUpdatedEvent: {
476
+ "AttendeeUpdatedEvent-Input": {
235
477
  /**
236
478
  * Id
237
479
  * Format: uuid
@@ -247,13 +489,40 @@ export type components = {
247
489
  instanceName: string;
248
490
  /** Attendeeid */
249
491
  attendeeId: string;
250
- updates: components["schemas"]["AttendeeUpdate"];
492
+ updates: components["schemas"]["AttendeeUpdate-Input"];
251
493
  /**
252
494
  * Time
253
495
  * Format: date-time
254
496
  */
255
497
  time?: string;
256
498
  };
499
+ /**
500
+ * AttendeeUpdatedEvent
501
+ * @description Attendee was updated. This includes `userdata` but also other data such as `payment`, `rsvp` or `tags`
502
+ */
503
+ "AttendeeUpdatedEvent-Output": {
504
+ /**
505
+ * Id
506
+ * Format: uuid
507
+ */
508
+ id: string;
509
+ /**
510
+ * Event
511
+ * @default attendee-updated
512
+ * @constant
513
+ */
514
+ event: "attendee-updated";
515
+ /** Instancename */
516
+ instanceName: string;
517
+ /** Attendeeid */
518
+ attendeeId: string;
519
+ updates: components["schemas"]["AttendeeUpdate-Output"];
520
+ /**
521
+ * Time
522
+ * Format: date-time
523
+ */
524
+ time: string;
525
+ };
257
526
  /** AuthCode */
258
527
  AuthCode: {
259
528
  /** Authcode */
@@ -472,7 +741,7 @@ export type components = {
472
741
  * CheckinCreatedEvent
473
742
  * @description A new checkin was created
474
743
  */
475
- CheckinCreatedEvent: {
744
+ "CheckinCreatedEvent-Input": {
476
745
  /**
477
746
  * Id
478
747
  * Format: uuid
@@ -492,11 +761,35 @@ export type components = {
492
761
  branchName: string;
493
762
  checkin: components["schemas"]["Checkin-Input"];
494
763
  };
764
+ /**
765
+ * CheckinCreatedEvent
766
+ * @description A new checkin was created
767
+ */
768
+ "CheckinCreatedEvent-Output": {
769
+ /**
770
+ * Id
771
+ * Format: uuid
772
+ */
773
+ id: string;
774
+ /**
775
+ * Event
776
+ * @default checkin-created
777
+ * @constant
778
+ */
779
+ event: "checkin-created";
780
+ /** Instancename */
781
+ instanceName: string;
782
+ /** Attendeeid */
783
+ attendeeId: string;
784
+ /** Branchname */
785
+ branchName: string;
786
+ checkin: components["schemas"]["Checkin-Output"];
787
+ };
495
788
  /**
496
789
  * CheckinDeletedEvent
497
790
  * @description An existing checkin was deleted
498
791
  */
499
- CheckinDeletedEvent: {
792
+ "CheckinDeletedEvent-Input": {
500
793
  /**
501
794
  * Id
502
795
  * Format: uuid
@@ -520,6 +813,34 @@ export type components = {
520
813
  /** Branchname */
521
814
  branchName: string;
522
815
  };
816
+ /**
817
+ * CheckinDeletedEvent
818
+ * @description An existing checkin was deleted
819
+ */
820
+ "CheckinDeletedEvent-Output": {
821
+ /**
822
+ * Id
823
+ * Format: uuid
824
+ */
825
+ id: string;
826
+ /**
827
+ * Event
828
+ * @default checkin-deleted
829
+ * @constant
830
+ */
831
+ event: "checkin-deleted";
832
+ /** Instancename */
833
+ instanceName: string;
834
+ /** Attendeeid */
835
+ attendeeId: string;
836
+ /**
837
+ * Checkinid
838
+ * Format: uuid
839
+ */
840
+ checkinId: string;
841
+ /** Branchname */
842
+ branchName: string;
843
+ };
523
844
  /**
524
845
  * Checkins
525
846
  * @description A list of checkins
@@ -645,6 +966,79 @@ export type components = {
645
966
  */
646
967
  isCompanion: true;
647
968
  };
969
+ /**
970
+ * CompanionLinkedEvent
971
+ * @description Companion was added to this attendee
972
+ */
973
+ CompanionLinkedEvent: {
974
+ /**
975
+ * Id
976
+ * Format: uuid
977
+ */
978
+ id: string;
979
+ /**
980
+ * Event
981
+ * @default companion-linked
982
+ * @constant
983
+ */
984
+ event: "companion-linked";
985
+ /** Instancename */
986
+ instanceName: string;
987
+ /** Attendeeid */
988
+ attendeeId: string;
989
+ /** Companionid */
990
+ companionId: string;
991
+ /** Companionname */
992
+ companionName: string;
993
+ };
994
+ /**
995
+ * CompanionNameChangedEvent
996
+ * @description The name of a linked companion was changed
997
+ */
998
+ CompanionNameChangedEvent: {
999
+ /**
1000
+ * Id
1001
+ * Format: uuid
1002
+ */
1003
+ id: string;
1004
+ /**
1005
+ * Event
1006
+ * @default companion-name-changed
1007
+ * @constant
1008
+ */
1009
+ event: "companion-name-changed";
1010
+ /** Instancename */
1011
+ instanceName: string;
1012
+ /** Attendeeid */
1013
+ attendeeId: string;
1014
+ /** Companionid */
1015
+ companionId: string;
1016
+ /** Companionname */
1017
+ companionName: string;
1018
+ };
1019
+ /**
1020
+ * CompanionUnlinkedEvent
1021
+ * @description Companion was removed from this attendee
1022
+ */
1023
+ CompanionUnlinkedEvent: {
1024
+ /**
1025
+ * Id
1026
+ * Format: uuid
1027
+ */
1028
+ id: string;
1029
+ /**
1030
+ * Event
1031
+ * @default companion-unlinked
1032
+ * @constant
1033
+ */
1034
+ event: "companion-unlinked";
1035
+ /** Instancename */
1036
+ instanceName: string;
1037
+ /** Attendeeid */
1038
+ attendeeId: string;
1039
+ /** Companionid */
1040
+ companionId: string;
1041
+ };
648
1042
  /** CustomCountQuery */
649
1043
  CustomCountQuery: {
650
1044
  /** Counters */
@@ -840,7 +1234,7 @@ export type components = {
840
1234
  max: number;
841
1235
  };
842
1236
  /** EmailStatus */
843
- EmailStatus: {
1237
+ "EmailStatus-Input": {
844
1238
  /**
845
1239
  * Mailing Id
846
1240
  * @description the unique id of the bulk or single mailing
@@ -871,6 +1265,38 @@ export type components = {
871
1265
  /** @description for clicked events a url can be provided (those will be merged with clicks from prevois events) */
872
1266
  clicks?: components["schemas"]["StorableSet_str_-Input"];
873
1267
  };
1268
+ /** EmailStatus */
1269
+ "EmailStatus-Output": {
1270
+ /**
1271
+ * Mailing Id
1272
+ * @description the unique id of the bulk or single mailing
1273
+ */
1274
+ mailing_id: string;
1275
+ /**
1276
+ * Status
1277
+ * @enum {string}
1278
+ */
1279
+ status: "pending" | "waiting" | "submitted" | "skipped" | "sent" | "opened" | "clicked" | "invalid" | "rejected" | "unsubscribed";
1280
+ /**
1281
+ * Updated At
1282
+ * Format: date-time
1283
+ */
1284
+ updated_at?: string;
1285
+ /**
1286
+ * Time
1287
+ * @description the time the email was sent (this should only be set when setting the status to 'sent')
1288
+ */
1289
+ time?: string | null;
1290
+ /**
1291
+ * Reason
1292
+ * @description for error states a reason can be added to the event (reasons will be merged with reasons from prevoius errors)
1293
+ */
1294
+ reason?: string | components["schemas"]["StorableSet_str_-Output"];
1295
+ /** @description for open events a set of email clients can be added (those will be merged with clients from prevois states) */
1296
+ clients?: components["schemas"]["StorableSet_str_-Output"];
1297
+ /** @description for clicked events a url can be provided (those will be merged with clicks from prevois events) */
1298
+ clicks?: components["schemas"]["StorableSet_str_-Output"];
1299
+ };
874
1300
  /**
875
1301
  * EmailStatusUpdatedEvent
876
1302
  * @description EmailStatus for attendee was updated.
@@ -897,7 +1323,7 @@ export type components = {
897
1323
  attendeeId: string;
898
1324
  /** Mailid */
899
1325
  mailId: string;
900
- emailStatus: components["schemas"]["EmailStatus"];
1326
+ emailStatus: components["schemas"]["EmailStatus-Input"];
901
1327
  };
902
1328
  /**
903
1329
  * EmailUnsubscribedEvent
@@ -1096,6 +1522,51 @@ export type components = {
1096
1522
  /** Ext */
1097
1523
  ext: string[] | null;
1098
1524
  };
1525
+ /**
1526
+ * InternalAttendeeCreatedEvent
1527
+ * @description New attendee was created via a public interface
1528
+ */
1529
+ InternalAttendeeCreatedEvent: {
1530
+ /**
1531
+ * Id
1532
+ * Format: uuid
1533
+ */
1534
+ id: string;
1535
+ /**
1536
+ * Event
1537
+ * @default internal-attendee-created
1538
+ * @constant
1539
+ */
1540
+ event: "internal-attendee-created";
1541
+ attendee: components["schemas"]["Attendee"];
1542
+ /** Attendeeid */
1543
+ attendeeId: string;
1544
+ /** Instancename */
1545
+ instanceName: string;
1546
+ };
1547
+ /**
1548
+ * InternalAttendeeUpdatedEvent
1549
+ * @description Attendee was updated. This includes `userdata` but also other data such as `payment`, `rsvp` or `tags`
1550
+ */
1551
+ InternalAttendeeUpdatedEvent: {
1552
+ /**
1553
+ * Id
1554
+ * Format: uuid
1555
+ */
1556
+ id: string;
1557
+ /**
1558
+ * Event
1559
+ * @default internal-attendee-updated
1560
+ * @constant
1561
+ */
1562
+ event: "internal-attendee-updated";
1563
+ /** Instancename */
1564
+ instanceName: string;
1565
+ /** Attendeeid */
1566
+ attendeeId: string;
1567
+ /** Attendeeupdates */
1568
+ attendeeUpdates: components["schemas"]["AttendeeUpdate-Output"][];
1569
+ };
1099
1570
  /** ItemOption */
1100
1571
  ItemOption: {
1101
1572
  /**
@@ -1201,6 +1672,75 @@ export type components = {
1201
1672
  [key: string]: string;
1202
1673
  };
1203
1674
  };
1675
+ /**
1676
+ * MainGuestLinkedEvent
1677
+ * @description Guest was converted to a companion and linked to a Main Guest
1678
+ */
1679
+ MainGuestLinkedEvent: {
1680
+ /**
1681
+ * Id
1682
+ * Format: uuid
1683
+ */
1684
+ id: string;
1685
+ /**
1686
+ * Event
1687
+ * @default main-guest-linked
1688
+ * @constant
1689
+ */
1690
+ event: "main-guest-linked";
1691
+ /** Instancename */
1692
+ instanceName: string;
1693
+ /** Attendeeid */
1694
+ attendeeId: string;
1695
+ /** Mainguestid */
1696
+ mainGuestId: string;
1697
+ /** Mainguestname */
1698
+ mainGuestName: string;
1699
+ };
1700
+ /**
1701
+ * MainGuestNameChangedEvent
1702
+ * @description Name of linked Main Guest changed
1703
+ */
1704
+ MainGuestNameChangedEvent: {
1705
+ /**
1706
+ * Id
1707
+ * Format: uuid
1708
+ */
1709
+ id: string;
1710
+ /**
1711
+ * Event
1712
+ * @default main-guest-name-changed
1713
+ * @constant
1714
+ */
1715
+ event: "main-guest-name-changed";
1716
+ /** Instancename */
1717
+ instanceName: string;
1718
+ /** Attendeeid */
1719
+ attendeeId: string;
1720
+ /** Mainguestname */
1721
+ mainGuestName: string;
1722
+ };
1723
+ /**
1724
+ * MainGuestUnlinkedEvent
1725
+ * @description Companion was converted to main guest
1726
+ */
1727
+ MainGuestUnlinkedEvent: {
1728
+ /**
1729
+ * Id
1730
+ * Format: uuid
1731
+ */
1732
+ id: string;
1733
+ /**
1734
+ * Event
1735
+ * @default main-guest-unlinked
1736
+ * @constant
1737
+ */
1738
+ event: "main-guest-unlinked";
1739
+ /** Instancename */
1740
+ instanceName: string;
1741
+ /** Attendeeid */
1742
+ attendeeId: string;
1743
+ };
1204
1744
  /** NumberField */
1205
1745
  NumberField: {
1206
1746
  /**
@@ -1309,7 +1849,7 @@ export type components = {
1309
1849
  *
1310
1850
  * This triggers mails that are atomatically sent on payment
1311
1851
  */
1312
- PaymentPaidEvent: {
1852
+ "PaymentPaidEvent-Input": {
1313
1853
  /**
1314
1854
  * Id
1315
1855
  * Format: uuid
@@ -1328,6 +1868,31 @@ export type components = {
1328
1868
  /** Provider */
1329
1869
  provider?: ("manual" | "sepa" | "credit" | "bank_transfer" | "paypal" | "stripe") | null;
1330
1870
  };
1871
+ /**
1872
+ * PaymentPaidEvent
1873
+ * @description The payment status for a attende was set to payed.
1874
+ *
1875
+ * This triggers mails that are atomatically sent on payment
1876
+ */
1877
+ "PaymentPaidEvent-Output": {
1878
+ /**
1879
+ * Id
1880
+ * Format: uuid
1881
+ */
1882
+ id: string;
1883
+ /**
1884
+ * Event
1885
+ * @default payment-paid
1886
+ * @constant
1887
+ */
1888
+ event: "payment-paid";
1889
+ /** Attendeeid */
1890
+ attendeeId: string;
1891
+ /** Instancename */
1892
+ instanceName: string;
1893
+ /** Provider */
1894
+ provider: ("manual" | "sepa" | "credit" | "bank_transfer" | "paypal" | "stripe") | null;
1895
+ };
1331
1896
  /** PublicAttendee */
1332
1897
  "PublicAttendee-Input": {
1333
1898
  /** Id */
@@ -1626,7 +2191,7 @@ export type components = {
1626
2191
  /** RootModel[Union[Companion, MainGuest]] */
1627
2192
  "RootModel_Union_Companion__MainGuest__-Output": components["schemas"]["Companion-Output"] | components["schemas"]["MainGuest-Output"];
1628
2193
  /** RootModel[list[Annotated[Union[AttendeeCreatedEvent, AttendeeUpdatedEvent, AttendeeRespondedEvent, AttendeeAuthCodeRequested, EmailStatusUpdatedEvent, EmailUnsubscribedEvent, AttendeeDeletedEvent, CheckinCreatedEvent, CheckinDeletedEvent, PaymentPaidEvent], FieldInfo(annotation=NoneType, required=True, discriminator='event')]]] */
1629
- RootModel_list_Annotated_Union_AttendeeCreatedEvent__AttendeeUpdatedEvent__AttendeeRespondedEvent__AttendeeAuthCodeRequested__EmailStatusUpdatedEvent__EmailUnsubscribedEvent__AttendeeDeletedEvent__CheckinCreatedEvent__CheckinDeletedEvent__PaymentPaidEvent___FieldInfo_annotation_NoneType__required_True__discriminator__event_____: (components["schemas"]["AttendeeCreatedEvent"] | components["schemas"]["AttendeeUpdatedEvent"] | components["schemas"]["AttendeeRespondedEvent"] | components["schemas"]["AttendeeAuthCodeRequested"] | components["schemas"]["EmailStatusUpdatedEvent"] | components["schemas"]["EmailUnsubscribedEvent"] | components["schemas"]["AttendeeDeletedEvent"] | components["schemas"]["CheckinCreatedEvent"] | components["schemas"]["CheckinDeletedEvent"] | components["schemas"]["PaymentPaidEvent"])[];
2194
+ RootModel_list_Annotated_Union_AttendeeCreatedEvent__AttendeeUpdatedEvent__AttendeeRespondedEvent__AttendeeAuthCodeRequested__EmailStatusUpdatedEvent__EmailUnsubscribedEvent__AttendeeDeletedEvent__CheckinCreatedEvent__CheckinDeletedEvent__PaymentPaidEvent___FieldInfo_annotation_NoneType__required_True__discriminator__event_____: (components["schemas"]["AttendeeCreatedEvent-Input"] | components["schemas"]["AttendeeUpdatedEvent-Input"] | components["schemas"]["AttendeeRespondedEvent-Input"] | components["schemas"]["AttendeeAuthCodeRequested-Input"] | components["schemas"]["EmailStatusUpdatedEvent"] | components["schemas"]["EmailUnsubscribedEvent"] | components["schemas"]["AttendeeDeletedEvent-Input"] | components["schemas"]["CheckinCreatedEvent-Input"] | components["schemas"]["CheckinDeletedEvent-Input"] | components["schemas"]["PaymentPaidEvent-Input"])[];
1630
2195
  /** SecurityQuestion */
1631
2196
  SecurityQuestion: {
1632
2197
  security_question: components["schemas"]["QuestionFields"];
@@ -1772,6 +2337,10 @@ export type components = {
1772
2337
  msg: string;
1773
2338
  /** Error Type */
1774
2339
  type: string;
2340
+ /** Input */
2341
+ input?: unknown;
2342
+ /** Context */
2343
+ ctx?: Record<string, unknown>;
1775
2344
  };
1776
2345
  /**
1777
2346
  * Variable
@@ -1954,6 +2523,29 @@ export type operations = {
1954
2523
  };
1955
2524
  };
1956
2525
  };
2526
+ /** Get Events */
2527
+ get_events_events_stream_get: {
2528
+ parameters: {
2529
+ query?: {
2530
+ instance?: string | null;
2531
+ event_type?: string[] | null;
2532
+ };
2533
+ };
2534
+ responses: {
2535
+ /** @description Successful Response */
2536
+ 200: {
2537
+ content: {
2538
+ "text/event-stream": components["schemas"]["AttendeeCreatedEvent-Output"] | components["schemas"]["AttendeeUpdatedEvent-Output"] | components["schemas"]["AttendeeRespondedEvent-Output"] | components["schemas"]["AttendeeRestoredEvent"] | components["schemas"]["AttendeeDeletedEvent-Output"] | components["schemas"]["AttendeeAuthCodeRequested-Output"] | components["schemas"]["InternalAttendeeCreatedEvent"] | components["schemas"]["InternalAttendeeUpdatedEvent"] | components["schemas"]["CheckinCreatedEvent-Output"] | components["schemas"]["CheckinDeletedEvent-Output"] | components["schemas"]["CompanionLinkedEvent"] | components["schemas"]["CompanionUnlinkedEvent"] | components["schemas"]["CompanionNameChangedEvent"] | components["schemas"]["MainGuestLinkedEvent"] | components["schemas"]["MainGuestUnlinkedEvent"] | components["schemas"]["MainGuestNameChangedEvent"] | components["schemas"]["PaymentPaidEvent-Output"];
2539
+ };
2540
+ };
2541
+ /** @description Validation Error */
2542
+ 422: {
2543
+ content: {
2544
+ "application/json": components["schemas"]["HTTPValidationError"];
2545
+ };
2546
+ };
2547
+ };
2548
+ };
1957
2549
  /** Fields */
1958
2550
  fields_instances__instance_name__fields_get: {
1959
2551
  parameters: {
@@ -1,12 +1,12 @@
1
1
  import { components } from '../generated/api-schema';
2
- export type AttendeeCreatedEvent = components['schemas']['AttendeeCreatedEvent'];
3
- export type AttendeeUpdatedEvent = components['schemas']['AttendeeUpdatedEvent'];
4
- export type AttendeeRespondedEvent = components['schemas']['AttendeeRespondedEvent'];
5
- export type AttendeeDeletedEvent = components['schemas']['AttendeeDeletedEvent'];
6
- export type AttendeeAuthCodeRequestedEvent = components['schemas']['AttendeeAuthCodeRequested'];
2
+ export type AttendeeCreatedEvent = components['schemas']['AttendeeCreatedEvent-Output'];
3
+ export type AttendeeUpdatedEvent = components['schemas']['AttendeeUpdatedEvent-Output'];
4
+ export type AttendeeRespondedEvent = components['schemas']['AttendeeRespondedEvent-Output'];
5
+ export type AttendeeDeletedEvent = components['schemas']['AttendeeDeletedEvent-Output'];
6
+ export type AttendeeAuthCodeRequestedEvent = components['schemas']['AttendeeAuthCodeRequested-Output'];
7
7
  export type EmailUnsubscribedEvent = components['schemas']['EmailUnsubscribedEvent'];
8
8
  export type EmailStatusUpdatedEvent = components['schemas']['EmailStatusUpdatedEvent'];
9
- export type CheckinCreatedEvent = components['schemas']['CheckinCreatedEvent'];
10
- export type CheckinDeletedEvent = components['schemas']['CheckinDeletedEvent'];
11
- export type PaymentPaidEvent = components['schemas']['PaymentPaidEvent'];
12
- export type Event = components['schemas']['RootModel_list_Annotated_Union_AttendeeCreatedEvent__AttendeeUpdatedEvent__AttendeeRespondedEvent__AttendeeAuthCodeRequested__EmailStatusUpdatedEvent__EmailUnsubscribedEvent__AttendeeDeletedEvent__CheckinCreatedEvent__CheckinDeletedEvent__PaymentPaidEvent___FieldInfo_annotation_NoneType__required_True__discriminator__event_____'][number];
9
+ export type CheckinCreatedEvent = components['schemas']['CheckinCreatedEvent-Output'];
10
+ export type CheckinDeletedEvent = components['schemas']['CheckinDeletedEvent-Output'];
11
+ export type PaymentPaidEvent = components['schemas']['PaymentPaidEvent-Output'];
12
+ export type Event = AttendeeCreatedEvent | AttendeeUpdatedEvent | AttendeeRespondedEvent | AttendeeDeletedEvent | AttendeeAuthCodeRequestedEvent | EmailUnsubscribedEvent | EmailStatusUpdatedEvent | CheckinCreatedEvent | CheckinDeletedEvent | PaymentPaidEvent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.96.1",
3
+ "version": "0.97.3",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",
@@ -22,7 +22,7 @@
22
22
  "test": "echo \"Error: no test specified\" && exit 1",
23
23
  "storybook": "storybook dev -p 6006",
24
24
  "build-storybook": "storybook build",
25
- "generate-client": "openapi-typescript https://api.enter.events/openapi.json --output src/generated/api-schema.ts --empty-objects-unknown --export-type",
25
+ "generate-client": "openapi-typescript https://api.dev.enter.events/openapi.json --output src/generated/api-schema.ts --empty-objects-unknown --export-type",
26
26
  "generate-docs": "typedoc --plugin typedoc-plugin-rename-defaults --entryPointStrategy expand"
27
27
  },
28
28
  "lint-staged": {
@@ -78,6 +78,7 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "cookie": "^1.0.1",
81
+ "eventsource-parser": "^3.0.6",
81
82
  "jws": "^4.0.0",
82
83
  "stable-hash": "^0.0.5",
83
84
  "styled-jsx": "^5.1.6",