@dev-crew-berlin/enter-js-utils 0.87.0 → 0.87.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.
package/README.md CHANGED
@@ -8,20 +8,31 @@ npm install @dev-crew-berlin/enter-js-utils
8
8
 
9
9
  ## packages
10
10
 
11
+ ### ui
12
+
13
+ React ui components for enter and dcb apps.
14
+
15
+ > docs: https://js-utils.enter.events/storybook
16
+
11
17
  ### lib
12
18
 
13
19
  Some common helper functions and types.
14
20
  This also contains the dcb colors.
15
21
 
16
- ### ui
22
+ > docs: https://js-utils.enter.events/docs/modules/lib.html
23
+
24
+ ## models
17
25
 
18
- react ui components for enter and dcb apps.
19
- see: https://js-utils-main.dcb-utils.vercel.app
26
+ The models retured from the api-client.
27
+
28
+ > docs: https://js-utils.enter.events/docs/modules/models.html
20
29
 
21
30
  ### api-client
22
31
 
23
32
  typed js client for the enter api.
24
33
 
34
+ > docs: https://js-utils.enter.events/docs/modules/api-client.html
35
+
25
36
  ```typescript
26
37
  import EnterAPIClient from '@dev-crew-berlin/enter-js-utils/api-client'
27
38
 
@@ -58,10 +69,6 @@ async function apiExample() {
58
69
  }
59
70
  ```
60
71
 
61
- ## models
62
-
63
- The models retured from the api-client.
64
-
65
72
  ## publish
66
73
 
67
74
  This package is automatically published to npm for each new tag starting with `v*`.
@@ -36,6 +36,9 @@ export default class APIBase {
36
36
  onLogout: (reason?: string) => void;
37
37
  });
38
38
  private static fetchResult;
39
+ /**
40
+ * @category Auth
41
+ */
39
42
  static fetchAccessToken(args: {
40
43
  oidc: {
41
44
  url: string;
@@ -56,6 +59,9 @@ export default class APIBase {
56
59
  protected put<Path extends keyof paths>(endpoint: Path, data: RequestBody<Path, 'put'>, options: FetchOptions): Promise<APIResult<ResponseType<Path, 'put'>>>;
57
60
  protected patch<Path extends keyof paths>(endpoint: Path, data: RequestBody<Path, 'patch'>, options: FetchOptions): Promise<APIResult<ResponseType<Path, 'patch'>>>;
58
61
  protected delete<Path extends keyof paths>(endpoint: Path, options: FetchOptions): Promise<APIResult<ResponseType<Path, 'delete'>>>;
62
+ /**
63
+ * @category Auth
64
+ */
59
65
  logout(): Promise<void>;
60
66
  }
61
67
  export {};
@@ -16,6 +16,10 @@ export default class APIBase {
16
16
  return failure(e);
17
17
  }
18
18
  }
19
+
20
+ /**
21
+ * @category Auth
22
+ */
19
23
  static async fetchAccessToken(args) {
20
24
  // see https://zitadel.com/docs/guides/integrate/private-key-jwt to learn about this flow
21
25
  const {
@@ -147,6 +151,10 @@ export default class APIBase {
147
151
  if (!rawResponse.success) return rawResponse;
148
152
  return success(rawResponse.data);
149
153
  }
154
+
155
+ /**
156
+ * @category Auth
157
+ */
150
158
  async logout() {
151
159
  this.isLoggedIn = false;
152
160
  this.onLogout();
@@ -10,73 +10,155 @@ import { Variable } from '../models/variable';
10
10
  import { components } from '../generated/api-schema';
11
11
  import { Email } from '../models/email';
12
12
  export type { APICredentials } from './api-base';
13
- export default class API extends APIBase {
13
+ /**
14
+ * api client for the enter backend
15
+ */
16
+ declare class API extends APIBase {
17
+ /**
18
+ * @category Instances
19
+ */
14
20
  getInstanceList(options?: FetchOptions): Promise<APIResult<Instance[]>>;
21
+ /**
22
+ * @category Instances
23
+ */
15
24
  getInstance(args: {
16
25
  instanceName: string;
17
26
  }, options?: FetchOptions): Promise<APIResult<Instance>>;
27
+ /**
28
+ * @category Fields
29
+ */
18
30
  getFields(args: {
19
31
  instanceName: string;
20
32
  }, options?: FetchOptions): Promise<APIResult<FieldGroups>>;
33
+ /**
34
+ * @category Counts
35
+ */
21
36
  getCheckinCounts(args: {
22
37
  instanceName: string;
23
38
  }, options?: FetchOptions): Promise<APIResult<CheckinCounts>>;
39
+ /**
40
+ * Get the number of guests for multiple custom filters. e.g. all guests that don't eat meat.
41
+ * This way you don't have to fetch the whole guestlist to calculate those counts.
42
+ * @category Counts
43
+ * @example
44
+ * api.calculateCustomCounts({
45
+ * instanceName: 'my-instance',
46
+ * counter: [
47
+ * {
48
+ * name: 'vegetarians',
49
+ * filter: '&(user.has_food_restriction checked, user.is_vegetatian checked)'
50
+ * },
51
+ * {
52
+ * name: 'other-restrictions',
53
+ * filter: '&(user.has_food_restriction checked, user.is_vegetatian unchecked)'
54
+ * }
55
+ * ]
56
+ * })
57
+ *
58
+ * @param args.instanceName
59
+ * @param args.counter A list of `CustomCounter`s. You have to give each of your counts a name `name` and a `filter`
60
+ * @param options
61
+ * @returns
62
+ */
24
63
  calculateCustomCounts(args: {
25
64
  instanceName: string;
26
65
  counter: components['schemas']['CustomCounter'][];
27
66
  }, options?: FetchOptions): Promise<APIResult<{
28
67
  [key: string]: number;
29
68
  }>>;
69
+ /**
70
+ * @category Attendees
71
+ */
30
72
  getAttendeeList(args: {
31
73
  instanceName: string;
32
74
  filter?: string;
33
75
  includeDeleted?: boolean;
34
76
  }, options?: FetchOptions): Promise<APIResult<Attendee[]>>;
77
+ /**
78
+ * @category Attendees
79
+ */
35
80
  getAttendee(args: {
36
81
  instanceName: string;
37
82
  attendeeId: string;
38
83
  includeDeleted?: boolean;
39
84
  }, options?: FetchOptions): Promise<APIResult<Attendee>>;
85
+ /**
86
+ * @category Attendees
87
+ */
40
88
  getCompanions(args: {
41
89
  instanceName: string;
42
90
  attendeeId: string;
43
91
  includeDeleted?: boolean;
44
92
  }, options?: FetchOptions): Promise<APIResult<Attendee[]>>;
93
+ /**
94
+ * @category Tokens
95
+ */
45
96
  generateRegistrationToken(args: {
46
97
  instanceName: string;
47
98
  check: components['schemas']['SecurityQuestion'] | components['schemas']['AuthCode'] | components['schemas']['AttendeeId'];
48
99
  }, options?: FetchOptions): Promise<APIResult<string>>;
100
+ /**
101
+ * @category Variables
102
+ */
49
103
  getVariableList(args: {
50
104
  instanceName: string;
51
105
  }, options?: FetchOptions): Promise<APIResult<Variable[]>>;
106
+ /**
107
+ * @category Variables
108
+ */
52
109
  getVariable(args: {
53
110
  instanceName: string;
54
111
  variableName: string;
55
112
  }, options?: FetchOptions): Promise<APIResult<Variable>>;
113
+ /**
114
+ * @category Variables
115
+ */
56
116
  createVariable(args: {
57
117
  instanceName: string;
58
118
  variable: Variable;
59
119
  }, options?: FetchOptions): Promise<APIResult<Variable>>;
120
+ /**
121
+ * @category Variables
122
+ */
60
123
  updateVariable(args: {
61
124
  instanceName: string;
62
125
  variableName: string;
63
126
  update: RequestBody<'/instances/{instance_name}/variables/{variable_name}', 'put'>;
64
127
  }, options?: FetchOptions): Promise<APIResult<Variable>>;
128
+ /**
129
+ * @category Variables
130
+ */
65
131
  deleteVariable(args: {
66
132
  instanceName: string;
67
133
  variableName: string;
68
134
  }, options?: FetchOptions): Promise<APIResult<null>>;
135
+ /**
136
+ * @category User
137
+ */
69
138
  getUser(options?: FetchOptions): Promise<APIResult<User>>;
139
+ /**
140
+ * @category User
141
+ */
70
142
  updateUser(args: RequestBody<'/users/me', 'patch'>, options?: FetchOptions): Promise<APIResult<User>>;
143
+ /**
144
+ * @category Emails
145
+ */
71
146
  sendEmail(args: {
72
147
  instanceName: string;
73
148
  attendeeId: string;
74
149
  emailName: string;
75
150
  }, options?: FetchOptions): Promise<APIResult<null>>;
151
+ /**
152
+ * @category Emails
153
+ */
76
154
  getRenderedEmail(args: {
77
155
  instanceName: string;
78
156
  attendeeId: string;
79
157
  emailName: string;
80
158
  }, options?: FetchOptions): Promise<APIResult<Email>>;
159
+ /**
160
+ * @category Events
161
+ */
81
162
  createEvents(args: Event[], options?: FetchOptions): Promise<APIResult<null>>;
82
163
  }
164
+ export default API;
@@ -3,34 +3,81 @@ import { success } from '../lib';
3
3
  import { Attendee } from '../models/attendee';
4
4
  import { FieldGroups } from '../models/field-group';
5
5
  import { Instance } from '../models/instance';
6
- export default class API extends APIBase {
6
+ /**
7
+ * api client for the enter backend
8
+ */
9
+ class API extends APIBase {
10
+ /**
11
+ * @category Instances
12
+ */
7
13
  async getInstanceList(options = {}) {
8
14
  const result = await this.get('/instances', options);
9
15
  if (!result.success) return result;
10
16
  return success(result.data.map(instanceJSON => new Instance(instanceJSON)));
11
17
  }
18
+
19
+ /**
20
+ * @category Instances
21
+ */
12
22
  async getInstance(args, options = {}) {
13
23
  const instanceName = args.instanceName;
14
24
  const result = await this.get(`/instances/${instanceName}`, options);
15
25
  if (!result.success) return result;
16
26
  return success(new Instance(result.data));
17
27
  }
28
+
29
+ /**
30
+ * @category Fields
31
+ */
18
32
  async getFields(args, options = {}) {
19
33
  const instanceName = args.instanceName;
20
34
  const result = await this.get(`/instances/${instanceName}/fields`, options);
21
35
  if (!result.success) return result;
22
36
  return success(new FieldGroups(result.data));
23
37
  }
38
+
39
+ /**
40
+ * @category Counts
41
+ */
24
42
  async getCheckinCounts(args, options = {}) {
25
43
  const instanceName = args.instanceName;
26
44
  return this.get(`/instances/${instanceName}/checkin_counts`, options);
27
45
  }
46
+
47
+ /**
48
+ * Get the number of guests for multiple custom filters. e.g. all guests that don't eat meat.
49
+ * This way you don't have to fetch the whole guestlist to calculate those counts.
50
+ * @category Counts
51
+ * @example
52
+ * api.calculateCustomCounts({
53
+ * instanceName: 'my-instance',
54
+ * counter: [
55
+ * {
56
+ * name: 'vegetarians',
57
+ * filter: '&(user.has_food_restriction checked, user.is_vegetatian checked)'
58
+ * },
59
+ * {
60
+ * name: 'other-restrictions',
61
+ * filter: '&(user.has_food_restriction checked, user.is_vegetatian unchecked)'
62
+ * }
63
+ * ]
64
+ * })
65
+ *
66
+ * @param args.instanceName
67
+ * @param args.counter A list of `CustomCounter`s. You have to give each of your counts a name `name` and a `filter`
68
+ * @param options
69
+ * @returns
70
+ */
28
71
  async calculateCustomCounts(args, options = {}) {
29
72
  const instanceName = args.instanceName;
30
73
  return this.post(`/instances/${instanceName}/custom_counts`, {
31
74
  counters: args.counter
32
75
  }, options);
33
76
  }
77
+
78
+ /**
79
+ * @category Attendees
80
+ */
34
81
  async getAttendeeList(args, options = {}) {
35
82
  const query = new URLSearchParams();
36
83
  if (args.filter) {
@@ -45,6 +92,10 @@ export default class API extends APIBase {
45
92
  if (!result.success) return result;
46
93
  return success(result.data.map(attendeeJSON => new Attendee(attendeeJSON)));
47
94
  }
95
+
96
+ /**
97
+ * @category Attendees
98
+ */
48
99
  async getAttendee(args, options = {}) {
49
100
  const query = new URLSearchParams();
50
101
  if (args.includeDeleted) {
@@ -57,6 +108,10 @@ export default class API extends APIBase {
57
108
  if (!result.success) return result;
58
109
  return success(new Attendee(result.data));
59
110
  }
111
+
112
+ /**
113
+ * @category Attendees
114
+ */
60
115
  async getCompanions(args, options = {}) {
61
116
  const query = new URLSearchParams();
62
117
  if (args.includeDeleted) {
@@ -69,52 +124,97 @@ export default class API extends APIBase {
69
124
  if (!result.success) return result;
70
125
  return success(result.data.map(attendeeJSON => new Attendee(attendeeJSON)));
71
126
  }
127
+
128
+ /**
129
+ * @category Tokens
130
+ */
72
131
  async generateRegistrationToken(args, options = {}) {
73
132
  const instanceName = args.instanceName;
74
133
  return this.post(`/instances/${instanceName}/registration/registration_token`, args.check, options);
75
134
  }
135
+
136
+ /**
137
+ * @category Variables
138
+ */
76
139
  async getVariableList(args, options = {}) {
77
140
  const instanceName = args.instanceName;
78
141
  return this.get(`/instances/${instanceName}/variables`, options);
79
142
  }
143
+
144
+ /**
145
+ * @category Variables
146
+ */
80
147
  async getVariable(args, options = {}) {
81
148
  const instanceName = args.instanceName;
82
149
  const variableName = args.variableName;
83
150
  return this.get(`/instances/${instanceName}/variables/${variableName}`, options);
84
151
  }
152
+
153
+ /**
154
+ * @category Variables
155
+ */
85
156
  async createVariable(args, options = {}) {
86
157
  const instanceName = args.instanceName;
87
158
  return this.post(`/instances/${instanceName}/variables`, args.variable, options);
88
159
  }
160
+
161
+ /**
162
+ * @category Variables
163
+ */
89
164
  async updateVariable(args, options = {}) {
90
165
  const instanceName = args.instanceName;
91
166
  const variableName = args.variableName;
92
167
  return this.put(`/instances/${instanceName}/variables/${variableName}`, args.update, options);
93
168
  }
169
+
170
+ /**
171
+ * @category Variables
172
+ */
94
173
  async deleteVariable(args, options = {}) {
95
174
  const instanceName = args.instanceName;
96
175
  const variableName = args.variableName;
97
176
  return this.delete(`/instances/${instanceName}/variables/${variableName}`, options);
98
177
  }
178
+
179
+ /**
180
+ * @category User
181
+ */
99
182
  async getUser(options = {}) {
100
183
  return this.get('/users/me', options);
101
184
  }
185
+
186
+ /**
187
+ * @category User
188
+ */
102
189
  async updateUser(args, options = {}) {
103
190
  return this.patch('/users/me', args, options);
104
191
  }
192
+
193
+ /**
194
+ * @category Emails
195
+ */
105
196
  async sendEmail(args, options = {}) {
106
197
  const instanceName = args.instanceName;
107
198
  const attendeeId = args.attendeeId;
108
199
  const emailName = args.emailName;
109
200
  return this.post(`/instances/${instanceName}/attendees/${attendeeId}/emails/${emailName}/send`, null, options);
110
201
  }
202
+
203
+ /**
204
+ * @category Emails
205
+ */
111
206
  async getRenderedEmail(args, options = {}) {
112
207
  const instanceName = args.instanceName;
113
208
  const attendeeId = args.attendeeId;
114
209
  const emailName = args.emailName;
115
210
  return this.get(`/instances/${instanceName}/attendees/${attendeeId}/emails/${emailName}/render`, options);
116
211
  }
212
+
213
+ /**
214
+ * @category Events
215
+ */
117
216
  async createEvents(args, options = {}) {
118
217
  return this.post(`/events`, args, options);
119
218
  }
120
- }
219
+ }
220
+ export default API;