@opencrvs/mosip 1.7.0-alpha.1 → 1.7.0-alpha.11

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
@@ -0,0 +1,3 @@
1
+ # @opencrvs/mosip
2
+
3
+ This package contains helpers to country-config for using the [OpenCRVS-MOSIP API](https://github.com/opencrvs/mosip).
package/build/forms.d.ts CHANGED
@@ -1,6 +1,46 @@
1
1
  /**
2
- * E-Signet popup button form definition
2
+ * E-Signet popup button and hidden field form definitions
3
+ * @example
4
+ * ```
5
+ * [
6
+ * // ...other fields
7
+ * ...esignet({ url: "https://opencrvs-mosip-gateway.farajaland.opencrvs.org" })
8
+ * ]
9
+ * ```
3
10
  */
11
+ /**
12
+ *
13
+ * @description E-Signet REDIRECT button form definition. Calls E-Signet /authorize (this field may not be supported in the latest release of OpenCRVS yet)
14
+ *
15
+ */
16
+ export declare const esignet: (event: string, sectionId: string, esignetAuthUrl: string, openIdProviderClientId: string, openIdProviderClaims: string | undefined, fieldName: string, callbackFieldName: string) => {
17
+ name: string;
18
+ validator: never[];
19
+ icon: {
20
+ desktop: string;
21
+ mobile: string;
22
+ };
23
+ type: string;
24
+ custom: boolean;
25
+ label: {
26
+ id: string;
27
+ defaultMessage: string;
28
+ };
29
+ hideInPreview: boolean;
30
+ conditionals: {
31
+ action: string;
32
+ expression: string;
33
+ }[];
34
+ options: {
35
+ url: string;
36
+ callback: {
37
+ params: {
38
+ state: string;
39
+ };
40
+ trigger: string;
41
+ };
42
+ };
43
+ };
4
44
  export declare const popupButton: ({ url, }: {
5
45
  url: string;
6
46
  }) => {
@@ -8,24 +48,139 @@ export declare const popupButton: ({ url, }: {
8
48
  type: string;
9
49
  url: string;
10
50
  };
11
- export declare const hidden: () => {
51
+ /**
52
+ *
53
+ * @description esignet callback button form definition. Calls mosip-api/esignet-api /esignet/get-oidp-user-info (this field may not be supported in the latest release of OpenCRVS yet)
54
+ *
55
+ */
56
+ export declare const esignetCallback: ({ fieldName, event, sectionId, getOIDPUserInfoUrl, openIdProviderClientId, }: {
57
+ fieldName: string;
58
+ event: string;
59
+ sectionId: string;
60
+ getOIDPUserInfoUrl: string;
61
+ openIdProviderClientId: string;
62
+ }) => {
63
+ name: string;
64
+ type: string;
65
+ custom: boolean;
66
+ label: {
67
+ id: string;
68
+ defaultMessage: string;
69
+ };
70
+ validator: never[];
71
+ hideInPreview: boolean;
72
+ options: {
73
+ url: string;
74
+ headers: {
75
+ "Content-type": string;
76
+ };
77
+ body: {
78
+ clientId: string;
79
+ redirectUri: string;
80
+ };
81
+ method: string;
82
+ };
83
+ };
84
+ export declare const esignetHidden: () => {
12
85
  name: string;
13
86
  type: string;
14
87
  };
15
88
  /**
16
- * E-Signet popup button and hidden field form definitions
17
- * @example
18
- * ```
19
- * [
20
- * // ...other fields
21
- * ...esignet({ url: "https://opencrvs-mosip-gateway.farajaland.opencrvs.org" })
22
- * ]
23
- * ```
89
+ *
90
+ * @description QR reader type definition (this field may not be supported in the latest release of OpenCRVS yet)
91
+ *
24
92
  */
25
- export declare const esignet: ({ url, }: {
26
- /** URL to OpenCRVS-MOSIP gateway (e.g. https://opencrvs-mosip-gateway.farajaland.opencrvs.org) */
27
- url: string;
28
- }) => {
93
+ export declare const idReader: (event: string, sectionId: string, conditionals: any[], readers: any[]) => {
94
+ name: string;
95
+ customQuestionMappingId: string;
96
+ custom: boolean;
97
+ required: boolean;
98
+ type: string;
99
+ label: {
100
+ id: string;
101
+ defaultMessage: string;
102
+ };
103
+ hideInPreview: boolean;
104
+ initialValue: string;
105
+ validator: never[];
106
+ conditionals: any[];
107
+ dividerLabel: {
108
+ id: string;
109
+ defaultMessage: string;
110
+ };
111
+ manualInputInstructionLabel: {
112
+ id: string;
113
+ defaultMessage: string;
114
+ };
115
+ readers: any[];
116
+ };
117
+ export declare const qr: () => {
118
+ type: string;
119
+ };
120
+ export declare const verified: (event: string, sectionId: string) => {
121
+ name: string;
122
+ fieldId: string;
123
+ customQuestionMappingId: string;
124
+ type: string;
125
+ custom: boolean;
126
+ label: {
127
+ id: string;
128
+ defaultMessage: string;
129
+ };
130
+ initialValue: {
131
+ dependsOn: string[];
132
+ expression: string;
133
+ };
134
+ validator: never[];
135
+ };
136
+ export declare const idPendingVerificationBanner: (event: string, sectionId: string) => {
137
+ name: string;
138
+ type: string;
139
+ fieldId: string;
140
+ hideInPreview: boolean;
141
+ custom: boolean;
142
+ bannerType: string;
143
+ idFieldName: string;
144
+ label: {
145
+ id: string;
146
+ defaultMessage: string;
147
+ };
148
+ validator: never[];
149
+ conditionals: {
150
+ action: string;
151
+ expression: string;
152
+ }[];
153
+ };
154
+ export declare const idVerificationFields: (event: string, sectionId: string) => ({
155
+ name: string;
156
+ fieldId: string;
157
+ customQuestionMappingId: string;
158
+ type: string;
159
+ custom: boolean;
160
+ label: {
161
+ id: string;
162
+ defaultMessage: string;
163
+ };
164
+ initialValue: {
165
+ dependsOn: string[];
166
+ expression: string;
167
+ };
168
+ validator: never[];
169
+ } | {
29
170
  name: string;
30
171
  type: string;
31
- }[];
172
+ fieldId: string;
173
+ hideInPreview: boolean;
174
+ custom: boolean;
175
+ bannerType: string;
176
+ idFieldName: string;
177
+ label: {
178
+ id: string;
179
+ defaultMessage: string;
180
+ };
181
+ validator: never[];
182
+ conditionals: {
183
+ action: string;
184
+ expression: string;
185
+ }[];
186
+ })[];
package/build/forms.js CHANGED
@@ -1,11 +1,63 @@
1
1
  "use strict";
2
- // @TODO: we could start building these definitions to core tbh
3
- // @TODO: add renovate or something to listen for core updates and create a PRs, then we get an error message if we have broken this
2
+ // @TODO: Yet to be implemented! Placeholders for NPM publish.
4
3
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.esignet = exports.hidden = exports.popupButton = void 0;
4
+ exports.idVerificationFields = exports.idPendingVerificationBanner = exports.verified = exports.qr = exports.idReader = exports.esignetHidden = exports.esignetCallback = exports.popupButton = exports.esignet = void 0;
6
5
  /**
7
- * E-Signet popup button form definition
6
+ * E-Signet popup button and hidden field form definitions
7
+ * @example
8
+ * ```
9
+ * [
10
+ * // ...other fields
11
+ * ...esignet({ url: "https://opencrvs-mosip-gateway.farajaland.opencrvs.org" })
12
+ * ]
13
+ * ```
14
+ */
15
+ /**
16
+ *
17
+ * @description E-Signet REDIRECT button form definition. Calls E-Signet /authorize (this field may not be supported in the latest release of OpenCRVS yet)
18
+ *
8
19
  */
20
+ const esignet = (event, sectionId, esignetAuthUrl, openIdProviderClientId, openIdProviderClaims = "name,family_name,given_name,middle_name,birthdate,address", fieldName, callbackFieldName) => {
21
+ const url = new URL(esignetAuthUrl);
22
+ url.searchParams.append("client_id", openIdProviderClientId || "mock-client_id");
23
+ url.searchParams.append("response_type", "code");
24
+ url.searchParams.append("scope", "openid profile");
25
+ url.searchParams.append("acr_values", "mosip:idp:acr:static-code");
26
+ url.searchParams.append("claims", openIdProviderClaims);
27
+ url.searchParams.append("state", "fetch-on-mount");
28
+ url.searchParams.append("redirect_uri", '${window.location.origin}/drafts/${window.location.pathname.split("/")[2]}/events/${event}/${sectionId}/group/${sectionId}');
29
+ return {
30
+ name: fieldName,
31
+ validator: [],
32
+ icon: {
33
+ desktop: "Globe",
34
+ mobile: "Fingerprint",
35
+ },
36
+ type: "LINK_BUTTON",
37
+ custom: true,
38
+ label: {
39
+ id: "views.idReader.label.eSignet",
40
+ defaultMessage: "E-signet",
41
+ },
42
+ hideInPreview: true,
43
+ conditionals: [
44
+ {
45
+ action: "disable",
46
+ expression: "!!$form.redirectCallbackFetch",
47
+ },
48
+ ],
49
+ options: {
50
+ url: url.toString(),
51
+ callback: {
52
+ params: {
53
+ state: "fetch-on-mount",
54
+ },
55
+ trigger: callbackFieldName,
56
+ },
57
+ },
58
+ };
59
+ };
60
+ exports.esignet = esignet;
9
61
  const popupButton = ({
10
62
  /** URL to OpenCRVS-MOSIP gateway (e.g. https://opencrvs-mosip-gateway.farajaland.opencrvs.org) */
11
63
  url, }) => {
@@ -16,22 +68,129 @@ url, }) => {
16
68
  };
17
69
  };
18
70
  exports.popupButton = popupButton;
19
- const hidden = () => {
71
+ /**
72
+ *
73
+ * @description esignet callback button form definition. Calls mosip-api/esignet-api /esignet/get-oidp-user-info (this field may not be supported in the latest release of OpenCRVS yet)
74
+ *
75
+ */
76
+ const esignetCallback = ({ fieldName, event, sectionId, getOIDPUserInfoUrl, openIdProviderClientId, }) => ({
77
+ name: fieldName,
78
+ type: "HTTP",
79
+ custom: true,
80
+ label: {
81
+ id: "form.field.label.empty",
82
+ defaultMessage: "",
83
+ },
84
+ validator: [],
85
+ hideInPreview: true,
86
+ options: {
87
+ url: getOIDPUserInfoUrl,
88
+ headers: {
89
+ "Content-type": "application/json",
90
+ },
91
+ body: {
92
+ clientId: openIdProviderClientId,
93
+ redirectUri: '${window.location.origin}/drafts/${window.location.pathname.split("/")[2]}/events/${event}/${sectionId}/group/${sectionId}',
94
+ },
95
+ method: "POST",
96
+ },
97
+ });
98
+ exports.esignetCallback = esignetCallback;
99
+ const esignetHidden = () => {
20
100
  return {
21
101
  name: "INFORMANT_PSUT_TOKEN",
22
102
  type: "HIDDEN",
23
103
  };
24
104
  };
25
- exports.hidden = hidden;
105
+ exports.esignetHidden = esignetHidden;
26
106
  /**
27
- * E-Signet popup button and hidden field form definitions
28
- * @example
29
- * ```
30
- * [
31
- * // ...other fields
32
- * ...esignet({ url: "https://opencrvs-mosip-gateway.farajaland.opencrvs.org" })
33
- * ]
34
- * ```
107
+ *
108
+ * @description QR reader type definition (this field may not be supported in the latest release of OpenCRVS yet)
109
+ *
35
110
  */
36
- const esignet = ({ url, }) => [(0, exports.popupButton)({ url }), (0, exports.hidden)()];
37
- exports.esignet = esignet;
111
+ const idReader = (event, sectionId, conditionals, readers) => {
112
+ const fieldName = "idReader";
113
+ const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
114
+ return {
115
+ name: fieldName,
116
+ customQuestionMappingId: fieldId,
117
+ custom: true,
118
+ required: false,
119
+ type: "ID_READER",
120
+ label: {
121
+ id: "form.field.label.empty",
122
+ defaultMessage: "",
123
+ },
124
+ hideInPreview: true,
125
+ initialValue: "",
126
+ validator: [],
127
+ conditionals,
128
+ dividerLabel: {
129
+ id: "views.idReader.label.or",
130
+ defaultMessage: "Or",
131
+ },
132
+ manualInputInstructionLabel: {
133
+ id: "views.idReader.label.manualInput",
134
+ defaultMessage: "Complete fields below",
135
+ },
136
+ readers,
137
+ };
138
+ };
139
+ exports.idReader = idReader;
140
+ const qr = () => ({
141
+ type: "QR",
142
+ });
143
+ exports.qr = qr;
144
+ const verified = (event, sectionId) => {
145
+ const fieldName = "verified";
146
+ const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
147
+ return {
148
+ name: "verified",
149
+ fieldId,
150
+ customQuestionMappingId: fieldId,
151
+ type: "HIDDEN",
152
+ custom: true,
153
+ label: {
154
+ id: "form.field.label.empty",
155
+ defaultMessage: "",
156
+ },
157
+ initialValue: {
158
+ dependsOn: ["idReader"],
159
+ expression: 'Boolean($form?.idReader)? "pending":""',
160
+ },
161
+ validator: [],
162
+ };
163
+ };
164
+ exports.verified = verified;
165
+ const idPendingVerificationBanner = (event, sectionId) => {
166
+ const fieldName = "verified";
167
+ const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
168
+ return {
169
+ name: "idPending",
170
+ type: "ID_VERIFICATION_BANNER",
171
+ fieldId,
172
+ hideInPreview: true,
173
+ custom: true,
174
+ bannerType: "pending",
175
+ idFieldName: "idReader",
176
+ label: {
177
+ id: "form.field.label.empty",
178
+ defaultMessage: "",
179
+ },
180
+ validator: [],
181
+ conditionals: [
182
+ {
183
+ action: "hide",
184
+ expression: '$form?.verified !== "pending"',
185
+ },
186
+ ],
187
+ };
188
+ };
189
+ exports.idPendingVerificationBanner = idPendingVerificationBanner;
190
+ const idVerificationFields = (event, sectionId) => {
191
+ return [
192
+ (0, exports.verified)(event, sectionId),
193
+ (0, exports.idPendingVerificationBanner)(event, sectionId),
194
+ ];
195
+ };
196
+ exports.idVerificationFields = idVerificationFields;
package/package.json CHANGED
@@ -1,20 +1,18 @@
1
1
  {
2
2
  "name": "@opencrvs/mosip",
3
- "version": "1.7.0-alpha.1",
3
+ "version": "1.7.0-alpha.11",
4
4
  "license": "MPL-2.0",
5
5
  "main": "./build/index.js",
6
6
  "exports": {
7
7
  ".": "./build/index.js",
8
- "./form-definitions": "./build/form-definitions.js",
8
+ "./forms": "./build/forms.js",
9
9
  "./events": "./build/events.js"
10
10
  },
11
11
  "typings": "build/index.d.ts",
12
12
  "scripts": {
13
13
  "build": "tsc"
14
14
  },
15
- "dependencies": {
16
- "@hapi/hapi": "^20.0.1"
17
- },
15
+ "dependencies": {},
18
16
  "devDependencies": {
19
17
  "@types/hapi__hapi": "^20.0.0",
20
18
  "@types/node-fetch": "^2.6.11",
package/src/forms.ts CHANGED
@@ -1,9 +1,78 @@
1
- // @TODO: we could start building these definitions to core tbh
2
- // @TODO: add renovate or something to listen for core updates and create a PRs, then we get an error message if we have broken this
1
+ // @TODO: Yet to be implemented! Placeholders for NPM publish.
3
2
 
4
3
  /**
5
- * E-Signet popup button form definition
4
+ * E-Signet popup button and hidden field form definitions
5
+ * @example
6
+ * ```
7
+ * [
8
+ * // ...other fields
9
+ * ...esignet({ url: "https://opencrvs-mosip-gateway.farajaland.opencrvs.org" })
10
+ * ]
11
+ * ```
12
+ */
13
+
14
+ /**
15
+ *
16
+ * @description E-Signet REDIRECT button form definition. Calls E-Signet /authorize (this field may not be supported in the latest release of OpenCRVS yet)
17
+ *
6
18
  */
19
+ export const esignet = (
20
+ event: string,
21
+ sectionId: string,
22
+ esignetAuthUrl: string,
23
+ openIdProviderClientId: string,
24
+ openIdProviderClaims: string = "name,family_name,given_name,middle_name,birthdate,address",
25
+ fieldName: string,
26
+ callbackFieldName: string,
27
+ ) => {
28
+ const url = new URL(esignetAuthUrl);
29
+
30
+ url.searchParams.append(
31
+ "client_id",
32
+ openIdProviderClientId || "mock-client_id",
33
+ );
34
+ url.searchParams.append("response_type", "code");
35
+ url.searchParams.append("scope", "openid profile");
36
+ url.searchParams.append("acr_values", "mosip:idp:acr:static-code");
37
+ url.searchParams.append("claims", openIdProviderClaims);
38
+ url.searchParams.append("state", "fetch-on-mount");
39
+ url.searchParams.append(
40
+ "redirect_uri",
41
+ '${window.location.origin}/drafts/${window.location.pathname.split("/")[2]}/events/${event}/${sectionId}/group/${sectionId}',
42
+ );
43
+
44
+ return {
45
+ name: fieldName,
46
+ validator: [],
47
+ icon: {
48
+ desktop: "Globe",
49
+ mobile: "Fingerprint",
50
+ },
51
+ type: "LINK_BUTTON",
52
+ custom: true,
53
+ label: {
54
+ id: "views.idReader.label.eSignet",
55
+ defaultMessage: "E-signet",
56
+ },
57
+ hideInPreview: true,
58
+ conditionals: [
59
+ {
60
+ action: "disable",
61
+ expression: "!!$form.redirectCallbackFetch",
62
+ },
63
+ ],
64
+ options: {
65
+ url: url.toString(),
66
+ callback: {
67
+ params: {
68
+ state: "fetch-on-mount",
69
+ },
70
+ trigger: callbackFieldName,
71
+ },
72
+ },
73
+ };
74
+ };
75
+
7
76
  export const popupButton = ({
8
77
  /** URL to OpenCRVS-MOSIP gateway (e.g. https://opencrvs-mosip-gateway.farajaland.opencrvs.org) */
9
78
  url,
@@ -17,7 +86,50 @@ export const popupButton = ({
17
86
  };
18
87
  };
19
88
 
20
- export const hidden = () => {
89
+ /**
90
+ *
91
+ * @description esignet callback button form definition. Calls mosip-api/esignet-api /esignet/get-oidp-user-info (this field may not be supported in the latest release of OpenCRVS yet)
92
+ *
93
+ */
94
+
95
+ export const esignetCallback = ({
96
+ fieldName,
97
+ event,
98
+ sectionId,
99
+ getOIDPUserInfoUrl,
100
+ openIdProviderClientId,
101
+ }: {
102
+ fieldName: string;
103
+ event: string;
104
+ sectionId: string;
105
+ getOIDPUserInfoUrl: string;
106
+ openIdProviderClientId: string;
107
+ }) => ({
108
+ name: fieldName,
109
+ type: "HTTP",
110
+ custom: true,
111
+ label: {
112
+ id: "form.field.label.empty",
113
+ defaultMessage: "",
114
+ },
115
+ validator: [],
116
+ hideInPreview: true,
117
+ options: {
118
+ url: getOIDPUserInfoUrl,
119
+ headers: {
120
+ "Content-type": "application/json",
121
+ },
122
+ body: {
123
+ clientId: openIdProviderClientId,
124
+ redirectUri:
125
+ '${window.location.origin}/drafts/${window.location.pathname.split("/")[2]}/events/${event}/${sectionId}/group/${sectionId}',
126
+ },
127
+
128
+ method: "POST",
129
+ },
130
+ });
131
+
132
+ export const esignetHidden = () => {
21
133
  return {
22
134
  name: "INFORMANT_PSUT_TOKEN",
23
135
  type: "HIDDEN",
@@ -25,18 +137,101 @@ export const hidden = () => {
25
137
  };
26
138
 
27
139
  /**
28
- * E-Signet popup button and hidden field form definitions
29
- * @example
30
- * ```
31
- * [
32
- * // ...other fields
33
- * ...esignet({ url: "https://opencrvs-mosip-gateway.farajaland.opencrvs.org" })
34
- * ]
35
- * ```
140
+ *
141
+ * @description QR reader type definition (this field may not be supported in the latest release of OpenCRVS yet)
142
+ *
36
143
  */
37
- export const esignet = ({
38
- url,
39
- }: {
40
- /** URL to OpenCRVS-MOSIP gateway (e.g. https://opencrvs-mosip-gateway.farajaland.opencrvs.org) */
41
- url: string;
42
- }) => [popupButton({ url }), hidden()];
144
+
145
+ export const idReader = (
146
+ event: string,
147
+ sectionId: string,
148
+ conditionals: any[],
149
+ readers: any[],
150
+ ) => {
151
+ const fieldName: string = "idReader";
152
+ const fieldId: string = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
153
+ return {
154
+ name: fieldName,
155
+ customQuestionMappingId: fieldId,
156
+ custom: true,
157
+ required: false,
158
+ type: "ID_READER",
159
+ label: {
160
+ id: "form.field.label.empty",
161
+ defaultMessage: "",
162
+ },
163
+ hideInPreview: true,
164
+ initialValue: "",
165
+ validator: [],
166
+ conditionals,
167
+ dividerLabel: {
168
+ id: "views.idReader.label.or",
169
+ defaultMessage: "Or",
170
+ },
171
+ manualInputInstructionLabel: {
172
+ id: "views.idReader.label.manualInput",
173
+ defaultMessage: "Complete fields below",
174
+ },
175
+ readers,
176
+ };
177
+ };
178
+
179
+ export const qr = () => ({
180
+ type: "QR",
181
+ });
182
+
183
+ export const verified = (event: string, sectionId: string) => {
184
+ const fieldName = "verified";
185
+ const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
186
+ return {
187
+ name: "verified",
188
+ fieldId,
189
+ customQuestionMappingId: fieldId,
190
+ type: "HIDDEN",
191
+ custom: true,
192
+ label: {
193
+ id: "form.field.label.empty",
194
+ defaultMessage: "",
195
+ },
196
+ initialValue: {
197
+ dependsOn: ["idReader"],
198
+ expression: 'Boolean($form?.idReader)? "pending":""',
199
+ },
200
+ validator: [],
201
+ };
202
+ };
203
+
204
+ export const idPendingVerificationBanner = (
205
+ event: string,
206
+ sectionId: string,
207
+ ) => {
208
+ const fieldName = "verified";
209
+ const fieldId = `${event}.${sectionId}.${sectionId}-view-group.${fieldName}`;
210
+ return {
211
+ name: "idPending",
212
+ type: "ID_VERIFICATION_BANNER",
213
+ fieldId,
214
+ hideInPreview: true,
215
+ custom: true,
216
+ bannerType: "pending",
217
+ idFieldName: "idReader",
218
+ label: {
219
+ id: "form.field.label.empty",
220
+ defaultMessage: "",
221
+ },
222
+ validator: [],
223
+ conditionals: [
224
+ {
225
+ action: "hide",
226
+ expression: '$form?.verified !== "pending"',
227
+ },
228
+ ],
229
+ };
230
+ };
231
+
232
+ export const idVerificationFields = (event: string, sectionId: string) => {
233
+ return [
234
+ verified(event, sectionId),
235
+ idPendingVerificationBanner(event, sectionId),
236
+ ];
237
+ };
package/tsconfig.json CHANGED
@@ -8,4 +8,4 @@
8
8
  "declaration": true,
9
9
  "outDir": "./build"
10
10
  }
11
- }
11
+ }