@dev-crew-berlin/enter-js-utils 0.47.4 → 0.49.0

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
@@ -25,20 +25,29 @@ typed js client for the enter api.
25
25
  ```typescript
26
26
  import EnterAPIClient from '@dev-crew-berlin/enter-js-utils/api-client'
27
27
 
28
- const url = 'https://api.enter.events'
29
28
 
30
29
  async function apiExample() {
31
30
  // fetch access Token
32
- const accessToken = await EnterAPIClient.fetchAccessToken({
33
- url: url,
34
- user: 'me',
35
- password: 'xxx',
36
- deviceName: 'my-device',
31
+ const accessTokenResult = await EnterAPIClient.fetchAccessToken({
32
+ oidc: {
33
+ url: 'https://auth.enter.events',
34
+ projectId: '246359835166114187'
35
+ }
36
+ user: {
37
+ userId: '',
38
+ keyId: '',
39
+ key: ''
40
+ }
37
41
  })
42
+ if (!accessTokenResult.success) {
43
+ throw new Error(accessTokenResult.error)
44
+ }
45
+
46
+ const accessToken = accessTokenResult.data.accessToken
38
47
 
39
48
  // create api instance
40
49
  const api = new EnterAPIClient({
41
- credentials: { accessToken, url },
50
+ credentials: { accessToken, url: 'https://api.enter.events' },
42
51
  onLogout: (reason?: string) => {
43
52
  deleteCredetials()
44
53
  },
@@ -1,4 +1,4 @@
1
- import { APIResult } from '../lib';
1
+ import { APIResult, Result } from '../lib';
2
2
  import { paths } from '../generated/api-schema';
3
3
  export interface APICredentials {
4
4
  accessToken: string;
@@ -30,6 +30,20 @@ export default class APIBase {
30
30
  onLogout: (reason?: string) => void;
31
31
  });
32
32
  private static fetchResult;
33
+ static fetchAccessToken(args: {
34
+ oidc: {
35
+ url: string;
36
+ projectId: string;
37
+ };
38
+ user: {
39
+ userId: string;
40
+ keyId: string;
41
+ key: string;
42
+ };
43
+ }): Promise<Result<string, {
44
+ accessToken: string;
45
+ expires: Date;
46
+ }>>;
33
47
  private fetchFromEnter;
34
48
  protected get<Path extends keyof paths>(endpoint: Path): Promise<APIResult<ResponseType<Path, 'get'>>>;
35
49
  protected post<Path extends keyof paths>(endpoint: Path, data: RequestBody<Path, 'post'>): Promise<APIResult<ResponseType<Path, 'post'>>>;
@@ -1,3 +1,4 @@
1
+ import jws from 'jws';
1
2
  import { failure, success } from '../lib';
2
3
  export default class APIBase {
3
4
  constructor(args) {
@@ -15,6 +16,58 @@ export default class APIBase {
15
16
  return failure(e);
16
17
  }
17
18
  }
19
+ static async fetchAccessToken(args) {
20
+ // see https://zitadel.com/docs/guides/integrate/private-key-jwt to learn about this flow
21
+ const {
22
+ oidc,
23
+ user
24
+ } = args;
25
+ const timestampNow = new Date().getTime() / 1000;
26
+ const assertionToken = jws.sign({
27
+ header: {
28
+ alg: 'RS256',
29
+ kid: user.keyId
30
+ },
31
+ payload: {
32
+ iss: user.userId,
33
+ sub: user.userId,
34
+ aud: oidc.url,
35
+ iat: timestampNow,
36
+ exp: timestampNow + 60 * 5
37
+ },
38
+ privateKey: user.key
39
+ });
40
+ const scopes = ['openid', 'profile', `urn:zitadel:iam:org:project:id:${oidc.projectId}:aud`];
41
+ try {
42
+ const res = await fetch(`${oidc.url}/oauth/v2/token`, {
43
+ method: 'POST',
44
+ headers: {
45
+ 'Content-Type': 'application/x-www-form-urlencoded'
46
+ },
47
+ body: new URLSearchParams({
48
+ grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
49
+ scope: scopes.join(' '),
50
+ assertion: assertionToken
51
+ })
52
+ });
53
+ if (res.status >= 300) {
54
+ try {
55
+ const error = await res.json();
56
+ return failure(error.toString());
57
+ } catch {
58
+ return failure(res.statusText);
59
+ }
60
+ }
61
+ const token = await res.json();
62
+ const expireTimestamp = new Date().getTime() + token.expires_in * 1000;
63
+ return success({
64
+ accessToken: token.access_token,
65
+ expires: new Date(expireTimestamp)
66
+ });
67
+ } catch (error) {
68
+ return failure(`${error}`);
69
+ }
70
+ }
18
71
  async fetchFromEnter(endpoint, method, data) {
19
72
  const body = data !== null ? JSON.stringify(data) : null;
20
73
  const headers = {
@@ -65,6 +65,29 @@ export declare type paths = {
65
65
  };
66
66
  export declare type components = {
67
67
  schemas: {
68
+ /**
69
+ * AttendeeAuthCodeRequested
70
+ * @description A request to set an auth_code for the attendee
71
+ *
72
+ * This will generate and set an auth code for the attendee. If none is already set.
73
+ */
74
+ AttendeeAuthCodeRequested: {
75
+ /**
76
+ * Id
77
+ * Format: uuid
78
+ */
79
+ id?: string;
80
+ /**
81
+ * Event
82
+ * @default attendee-auth-code-requested
83
+ * @enum {string}
84
+ */
85
+ event: "attendee-auth-code-requested";
86
+ /** Instancename */
87
+ instanceName: string;
88
+ /** Attendeeid */
89
+ attendeeId: string;
90
+ };
68
91
  /**
69
92
  * AttendeeCreatedEvent
70
93
  * @description New attendee was created
@@ -135,6 +158,11 @@ export declare type components = {
135
158
  rsvp: {
136
159
  [key: string]: number | null;
137
160
  };
161
+ /**
162
+ * Responsetime
163
+ * Format: date-time
164
+ */
165
+ responseTime?: string;
138
166
  /** Isedit */
139
167
  isEdit: boolean;
140
168
  };
@@ -213,55 +241,6 @@ export declare type components = {
213
241
  */
214
242
  suffix: string;
215
243
  };
216
- /** AuthField */
217
- AuthField: {
218
- /**
219
- * Type
220
- * @default auth
221
- * @enum {string}
222
- */
223
- type: "auth";
224
- /**
225
- * Name
226
- * @default new_field
227
- */
228
- name: string;
229
- /** Title */
230
- title?: string | {
231
- [key: string]: string;
232
- };
233
- /** Info */
234
- info?: string | {
235
- [key: string]: string;
236
- };
237
- /**
238
- * Class
239
- * @default
240
- */
241
- class: string;
242
- /**
243
- * Ismetafield
244
- * @default false
245
- */
246
- isMetaField: boolean;
247
- /**
248
- * Static
249
- * @default false
250
- */
251
- static: boolean;
252
- /**
253
- * Required
254
- * @default false
255
- */
256
- required: boolean;
257
- /**
258
- * Hidden
259
- * @default false
260
- */
261
- hidden: boolean;
262
- /** Value */
263
- value?: string;
264
- };
265
244
  /** CheckboxField */
266
245
  CheckboxField: {
267
246
  /**
@@ -468,6 +447,65 @@ export declare type components = {
468
447
  */
469
448
  deleted: string[];
470
449
  };
450
+ /** CodeField */
451
+ CodeField: {
452
+ /**
453
+ * Type
454
+ * @default code
455
+ * @enum {string}
456
+ */
457
+ type: "code";
458
+ /**
459
+ * Name
460
+ * @default new_field
461
+ */
462
+ name: string;
463
+ /** Title */
464
+ title?: string | {
465
+ [key: string]: string;
466
+ };
467
+ /** Info */
468
+ info?: string | {
469
+ [key: string]: string;
470
+ };
471
+ /**
472
+ * Class
473
+ * @default
474
+ */
475
+ class: string;
476
+ /**
477
+ * Ismetafield
478
+ * @default false
479
+ */
480
+ isMetaField: boolean;
481
+ /**
482
+ * Static
483
+ * @default false
484
+ */
485
+ static: boolean;
486
+ /**
487
+ * Required
488
+ * @default false
489
+ */
490
+ required: boolean;
491
+ /**
492
+ * Hidden
493
+ * @default false
494
+ */
495
+ hidden: boolean;
496
+ /** Value */
497
+ value?: string;
498
+ /**
499
+ * Min
500
+ * @default 0
501
+ */
502
+ min: number;
503
+ /**
504
+ * Max
505
+ * @default 2000
506
+ */
507
+ max: number;
508
+ };
471
509
  /** CompanionJSON */
472
510
  CompanionJSON: {
473
511
  /**
@@ -632,10 +670,16 @@ export declare type components = {
632
670
  hidden: boolean;
633
671
  /** Value */
634
672
  value?: string;
635
- /** Min */
636
- min?: number;
637
- /** Max */
638
- max?: number;
673
+ /**
674
+ * Min
675
+ * @default 0
676
+ */
677
+ min: number;
678
+ /**
679
+ * Max
680
+ * @default 1000
681
+ */
682
+ max: number;
639
683
  };
640
684
  /**
641
685
  * EmailUnsubscribedEvent
@@ -658,11 +702,15 @@ export declare type components = {
658
702
  event: "email-unsubscribed";
659
703
  /** Instancename */
660
704
  instanceName: string;
705
+ /** Attendeeid */
706
+ attendeeId: string;
707
+ /** Emailname */
708
+ emailName: string;
661
709
  /** Emailaddress */
662
710
  emailAddress: string;
663
711
  };
664
712
  /** EventList */
665
- EventList: (components["schemas"]["AttendeeCreatedEvent"] | components["schemas"]["AttendeeUpdatedEvent"] | components["schemas"]["AttendeeRespondedEvent"] | components["schemas"]["EmailUnsubscribedEvent"] | components["schemas"]["AttendeeDeletedEvent"] | components["schemas"]["CheckinCreatedEvent"] | components["schemas"]["CheckinDeletedEvent"] | components["schemas"]["PaymentPaidEvent"])[];
713
+ EventList: (components["schemas"]["AttendeeCreatedEvent"] | components["schemas"]["AttendeeUpdatedEvent"] | components["schemas"]["AttendeeRespondedEvent"] | components["schemas"]["AttendeeAuthCodeRequested"] | components["schemas"]["EmailUnsubscribedEvent"] | components["schemas"]["AttendeeDeletedEvent"] | components["schemas"]["CheckinCreatedEvent"] | components["schemas"]["CheckinDeletedEvent"] | components["schemas"]["PaymentPaidEvent"])[];
666
714
  /** EventResponse */
667
715
  EventResponse: {
668
716
  /** Created */
@@ -671,7 +719,7 @@ export declare type components = {
671
719
  /** FieldGroup */
672
720
  FieldGroup: {
673
721
  /** Questions */
674
- questions: (components["schemas"]["TextField"] | components["schemas"]["StaticField"] | components["schemas"]["ImageUploadField"] | components["schemas"]["FileUploadField"] | components["schemas"]["LongtextField"] | components["schemas"]["RadioButtonField"] | components["schemas"]["RadioButtonGroupField"] | components["schemas"]["DropdownField"] | components["schemas"]["DateField"] | components["schemas"]["EmailField"] | components["schemas"]["AuthField"] | components["schemas"]["NumberField"] | components["schemas"]["CheckboxField"] | components["schemas"]["CheckboxGroupField"])[];
722
+ questions: (components["schemas"]["TextField"] | components["schemas"]["StaticField"] | components["schemas"]["ImageUploadField"] | components["schemas"]["FileUploadField"] | components["schemas"]["LongtextField"] | components["schemas"]["RadioButtonGroupField"] | components["schemas"]["DropdownField"] | components["schemas"]["DateField"] | components["schemas"]["EmailField"] | components["schemas"]["NumberField"] | components["schemas"]["CheckboxField"] | components["schemas"]["CheckboxGroupField"] | components["schemas"]["CodeField"])[];
675
723
  /** Info */
676
724
  info?: string | {
677
725
  [key: string]: string;
@@ -735,7 +783,9 @@ export declare type components = {
735
783
  */
736
784
  hidden: boolean;
737
785
  /** Value */
738
- value?: string;
786
+ value?: {
787
+ [key: string]: unknown;
788
+ };
739
789
  /** Min */
740
790
  min?: number;
741
791
  /** Max */
@@ -876,10 +926,16 @@ export declare type components = {
876
926
  hidden: boolean;
877
927
  /** Value */
878
928
  value?: string;
879
- /** Min */
880
- min?: number;
881
- /** Max */
882
- max?: number;
929
+ /**
930
+ * Min
931
+ * @default 0
932
+ */
933
+ min: number;
934
+ /**
935
+ * Max
936
+ * @default 1000
937
+ */
938
+ max: number;
883
939
  };
884
940
  /** MainGuestJSON */
885
941
  MainGuestJSON: {
@@ -937,10 +993,16 @@ export declare type components = {
937
993
  hidden: boolean;
938
994
  /** Value */
939
995
  value?: string;
940
- /** Min */
941
- min?: number;
942
- /** Max */
943
- max?: number;
996
+ /**
997
+ * Min
998
+ * @default 0
999
+ */
1000
+ min: number;
1001
+ /**
1002
+ * Max
1003
+ * @default 1000
1004
+ */
1005
+ max: number;
944
1006
  };
945
1007
  /** Payment */
946
1008
  Payment: {
@@ -1094,57 +1156,6 @@ export declare type components = {
1094
1156
  /** Answer */
1095
1157
  answer: string;
1096
1158
  };
1097
- /** RadioButtonField */
1098
- RadioButtonField: {
1099
- /**
1100
- * Type
1101
- * @default radiobutton
1102
- * @enum {string}
1103
- */
1104
- type: "radiobutton";
1105
- /**
1106
- * Name
1107
- * @default new_field
1108
- */
1109
- name: string;
1110
- /** Title */
1111
- title?: string | {
1112
- [key: string]: string;
1113
- };
1114
- /** Info */
1115
- info?: string | {
1116
- [key: string]: string;
1117
- };
1118
- /**
1119
- * Class
1120
- * @default
1121
- */
1122
- class: string;
1123
- /**
1124
- * Ismetafield
1125
- * @default false
1126
- */
1127
- isMetaField: boolean;
1128
- /**
1129
- * Static
1130
- * @default false
1131
- */
1132
- static: boolean;
1133
- /**
1134
- * Required
1135
- * @default false
1136
- */
1137
- required: boolean;
1138
- /**
1139
- * Hidden
1140
- * @default false
1141
- */
1142
- hidden: boolean;
1143
- /** Value */
1144
- value?: string;
1145
- /** Itemval */
1146
- itemval?: string;
1147
- };
1148
1159
  /** RadioButtonGroupField */
1149
1160
  RadioButtonGroupField: {
1150
1161
  /**
@@ -1271,9 +1282,8 @@ export declare type components = {
1271
1282
  /**
1272
1283
  * Static
1273
1284
  * @default true
1274
- * @enum {boolean}
1275
1285
  */
1276
- static: true;
1286
+ static: boolean;
1277
1287
  /**
1278
1288
  * Required
1279
1289
  * @default false
@@ -1286,6 +1296,16 @@ export declare type components = {
1286
1296
  hidden: boolean;
1287
1297
  /** Value */
1288
1298
  value?: string;
1299
+ /**
1300
+ * Min
1301
+ * @default 0
1302
+ */
1303
+ min: number;
1304
+ /**
1305
+ * Max
1306
+ * @default 1000
1307
+ */
1308
+ max: number;
1289
1309
  };
1290
1310
  /** TextField */
1291
1311
  TextField: {
@@ -1335,10 +1355,16 @@ export declare type components = {
1335
1355
  hidden: boolean;
1336
1356
  /** Value */
1337
1357
  value?: string;
1338
- /** Min */
1339
- min?: number;
1340
- /** Max */
1341
- max?: number;
1358
+ /**
1359
+ * Min
1360
+ * @default 0
1361
+ */
1362
+ min: number;
1363
+ /**
1364
+ * Max
1365
+ * @default 1000
1366
+ */
1367
+ max: number;
1342
1368
  };
1343
1369
  /** UserPreferencesUpdate */
1344
1370
  UserPreferencesUpdate: {
@@ -20,9 +20,6 @@ export declare type SingleCheckboxField = components['schemas']['CheckboxField']
20
20
  export declare type RadioField = components['schemas']['RadioButtonGroupField'] & {
21
21
  group: string;
22
22
  };
23
- export declare type SingleRadioField = components['schemas']['RadioButtonField'] & {
24
- group: string;
25
- };
26
23
  export declare type SelectField = components['schemas']['DropdownField'] & {
27
24
  group: string;
28
25
  };
@@ -9,7 +9,7 @@ export type { Event, AttendeeUpdatedEvent, AttendeeCreatedEvent, AttendeeRespond
9
9
  export type { FieldGroup } from './field-group';
10
10
  export { FieldGroups } from './field-group';
11
11
  export type { FieldValue } from './field-value';
12
- export type { StaticField, TextField, EmailField, NumberField, CheckboxField, SingleCheckboxField, RadioField, SingleRadioField, SelectField, Field, } from './field';
12
+ export type { StaticField, TextField, EmailField, NumberField, CheckboxField, SingleCheckboxField, RadioField, SelectField, Field, } from './field';
13
13
  export { Instance } from './instance';
14
14
  export type { InstanceJSON } from './instance';
15
15
  export type { Permission } from './permission';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.47.4",
3
+ "version": "0.49.0",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",
@@ -52,6 +52,7 @@
52
52
  "@storybook/manager-webpack4": "^6.5.15",
53
53
  "@storybook/react": "^6.5.15",
54
54
  "@storybook/testing-library": "^0.0.13",
55
+ "@types/jws": "^3.2.9",
55
56
  "@types/node": "^17.0.38",
56
57
  "@types/react": "^18.0.10",
57
58
  "@types/react-dom": "^18.0.5",
@@ -72,6 +73,7 @@
72
73
  },
73
74
  "dependencies": {
74
75
  "fp-ts": "^2.12.1",
76
+ "jws": "^4.0.0",
75
77
  "styled-jsx": "^5.0.2",
76
78
  "uuid": "^9.0.0"
77
79
  }