@capgo/capacitor-persona 8.0.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/CapgoCapacitorPersona.podspec +18 -0
- package/LICENSE +373 -0
- package/Package.swift +30 -0
- package/README.md +244 -0
- package/android/build.gradle +66 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/app/capgo/persona/PersonaPlugin.java +268 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +380 -0
- package/dist/esm/definitions.d.ts +106 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +5 -0
- package/dist/esm/web.js +7 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +21 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +24 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/PersonaPlugin/PersonaPlugin.swift +216 -0
- package/ios/Tests/PersonaPluginTests/PersonaPluginTests.swift +8 -0
- package/package.json +90 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxActivityVersion = project.hasProperty('androidxActivityVersion') ? rootProject.ext.androidxActivityVersion : '1.10.1'
|
|
5
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
6
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
7
|
+
personaInquiryVersion = project.hasProperty('personaInquiryVersion') ? rootProject.ext.personaInquiryVersion : '2.32.1'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
buildscript {
|
|
11
|
+
repositories {
|
|
12
|
+
google()
|
|
13
|
+
mavenCentral()
|
|
14
|
+
}
|
|
15
|
+
dependencies {
|
|
16
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
apply plugin: 'com.android.library'
|
|
21
|
+
|
|
22
|
+
android {
|
|
23
|
+
namespace = "app.capgo.persona"
|
|
24
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
25
|
+
defaultConfig {
|
|
26
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
27
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
28
|
+
versionCode 1
|
|
29
|
+
versionName "1.0"
|
|
30
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
31
|
+
}
|
|
32
|
+
buildTypes {
|
|
33
|
+
release {
|
|
34
|
+
minifyEnabled false
|
|
35
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
lintOptions {
|
|
39
|
+
abortOnError = false
|
|
40
|
+
}
|
|
41
|
+
compileOptions {
|
|
42
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
43
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
repositories {
|
|
48
|
+
google()
|
|
49
|
+
mavenCentral()
|
|
50
|
+
maven {
|
|
51
|
+
url 'https://sdk.withpersona.com/android/releases'
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
dependencies {
|
|
57
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
58
|
+
implementation project(':capacitor-android')
|
|
59
|
+
annotationProcessor project(':capacitor-android')
|
|
60
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
61
|
+
implementation "androidx.activity:activity:$androidxActivityVersion"
|
|
62
|
+
implementation "com.withpersona.sdk2:inquiry:$personaInquiryVersion"
|
|
63
|
+
testImplementation "junit:junit:$junitVersion"
|
|
64
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
65
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
66
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
package app.capgo.persona;
|
|
2
|
+
|
|
3
|
+
import androidx.activity.result.ActivityResultLauncher;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import com.getcapacitor.Plugin;
|
|
6
|
+
import com.getcapacitor.PluginCall;
|
|
7
|
+
import com.getcapacitor.PluginMethod;
|
|
8
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
9
|
+
import com.withpersona.sdk2.inquiry.Environment;
|
|
10
|
+
import com.withpersona.sdk2.inquiry.Fields;
|
|
11
|
+
import com.withpersona.sdk2.inquiry.Inquiry;
|
|
12
|
+
import com.withpersona.sdk2.inquiry.InquiryBuilder;
|
|
13
|
+
import com.withpersona.sdk2.inquiry.InquiryField;
|
|
14
|
+
import com.withpersona.sdk2.inquiry.InquiryResponse;
|
|
15
|
+
import com.withpersona.sdk2.inquiry.InquiryTemplateBuilder;
|
|
16
|
+
import java.util.Iterator;
|
|
17
|
+
import java.util.Map;
|
|
18
|
+
import org.json.JSONArray;
|
|
19
|
+
import org.json.JSONObject;
|
|
20
|
+
|
|
21
|
+
@CapacitorPlugin(name = "Persona")
|
|
22
|
+
public class PersonaPlugin extends Plugin {
|
|
23
|
+
|
|
24
|
+
private ActivityResultLauncher<Inquiry> inquiryLauncher;
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public void load() {
|
|
28
|
+
inquiryLauncher = bridge.registerForActivityResult(new Inquiry.Contract(getContext()), this::handleInquiryResult);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@PluginMethod
|
|
32
|
+
public void startInquiry(PluginCall call) {
|
|
33
|
+
final Inquiry inquiry;
|
|
34
|
+
try {
|
|
35
|
+
inquiry = buildInquiry(call);
|
|
36
|
+
} catch (IllegalArgumentException ex) {
|
|
37
|
+
call.reject(ex.getMessage());
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (inquiryLauncher == null) {
|
|
42
|
+
call.reject("Persona inquiry launcher is not initialized.");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
inquiryLauncher.launch(inquiry);
|
|
47
|
+
call.resolve();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private Inquiry buildInquiry(PluginCall call) {
|
|
51
|
+
String inquiryId = trimToNull(call.getString("inquiryId"));
|
|
52
|
+
String sessionToken = trimToNull(call.getString("sessionToken"));
|
|
53
|
+
String templateId = trimToNull(call.getString("templateId"));
|
|
54
|
+
String templateVersion = trimToNull(call.getString("templateVersion"));
|
|
55
|
+
String referenceId = trimToNull(call.getString("referenceId"));
|
|
56
|
+
String accountId = trimToNull(call.getString("accountId"));
|
|
57
|
+
String locale = trimToNull(call.getString("locale"));
|
|
58
|
+
Environment environment = parseEnvironment(trimToNull(call.getString("environment")));
|
|
59
|
+
Fields fields = toFields(call.getObject("fields"));
|
|
60
|
+
|
|
61
|
+
if (inquiryId != null) {
|
|
62
|
+
InquiryBuilder builder = Inquiry.fromInquiry(inquiryId);
|
|
63
|
+
if (sessionToken != null) {
|
|
64
|
+
builder.sessionToken(sessionToken);
|
|
65
|
+
}
|
|
66
|
+
if (locale != null) {
|
|
67
|
+
builder.locale(locale);
|
|
68
|
+
}
|
|
69
|
+
return builder.build();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
InquiryTemplateBuilder templateBuilder;
|
|
73
|
+
if (templateId != null) {
|
|
74
|
+
templateBuilder = Inquiry.fromTemplate(templateId);
|
|
75
|
+
} else if (templateVersion != null) {
|
|
76
|
+
templateBuilder = Inquiry.fromTemplateVersion(templateVersion);
|
|
77
|
+
} else {
|
|
78
|
+
throw new IllegalArgumentException("At least one of inquiryId, templateId, or templateVersion must be provided.");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (referenceId != null) {
|
|
82
|
+
templateBuilder.referenceId(referenceId);
|
|
83
|
+
}
|
|
84
|
+
if (accountId != null) {
|
|
85
|
+
templateBuilder.accountId(accountId);
|
|
86
|
+
}
|
|
87
|
+
if (fields != null) {
|
|
88
|
+
templateBuilder.fields(fields);
|
|
89
|
+
}
|
|
90
|
+
if (environment != null) {
|
|
91
|
+
templateBuilder.environment(environment);
|
|
92
|
+
}
|
|
93
|
+
if (locale != null) {
|
|
94
|
+
templateBuilder.locale(locale);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return templateBuilder.build();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private Fields toFields(JSObject fieldsObject) {
|
|
101
|
+
if (fieldsObject == null) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
Fields.Builder builder = new Fields.Builder();
|
|
106
|
+
Iterator<String> keys = fieldsObject.keys();
|
|
107
|
+
while (keys.hasNext()) {
|
|
108
|
+
String key = keys.next();
|
|
109
|
+
Object value = fieldsObject.opt(key);
|
|
110
|
+
|
|
111
|
+
if (value == null || value == JSONObject.NULL) {
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (value instanceof String) {
|
|
116
|
+
builder.field(key, (String) value);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (value instanceof Boolean) {
|
|
121
|
+
builder.field(key, (Boolean) value);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (value instanceof Number) {
|
|
126
|
+
Number number = (Number) value;
|
|
127
|
+
if (value instanceof Float || value instanceof Double) {
|
|
128
|
+
builder.field(key, number.floatValue());
|
|
129
|
+
} else {
|
|
130
|
+
double asDouble = number.doubleValue();
|
|
131
|
+
if (Math.floor(asDouble) == asDouble) {
|
|
132
|
+
builder.field(key, number.intValue());
|
|
133
|
+
} else {
|
|
134
|
+
builder.field(key, number.floatValue());
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (value instanceof JSONArray) {
|
|
141
|
+
builder.fieldMultiChoices(key, toStringArray((JSONArray) value));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return builder.build();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private String[] toStringArray(JSONArray array) {
|
|
149
|
+
String[] values = new String[array.length()];
|
|
150
|
+
for (int i = 0; i < array.length(); i++) {
|
|
151
|
+
Object value = array.opt(i);
|
|
152
|
+
values[i] = value == null || value == JSONObject.NULL ? "" : String.valueOf(value);
|
|
153
|
+
}
|
|
154
|
+
return values;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private void handleInquiryResult(InquiryResponse response) {
|
|
158
|
+
if (response instanceof InquiryResponse.Complete) {
|
|
159
|
+
onInquiryComplete((InquiryResponse.Complete) response);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (response instanceof InquiryResponse.Cancel) {
|
|
163
|
+
onInquiryCanceled((InquiryResponse.Cancel) response);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (response instanceof InquiryResponse.Error) {
|
|
167
|
+
onInquiryError((InquiryResponse.Error) response);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private void onInquiryComplete(InquiryResponse.Complete response) {
|
|
172
|
+
JSObject payload = new JSObject();
|
|
173
|
+
payload.put("inquiryId", response.getInquiryId());
|
|
174
|
+
payload.put("status", response.getStatus());
|
|
175
|
+
|
|
176
|
+
JSObject fields = new JSObject();
|
|
177
|
+
Map<String, InquiryField> source = response.getFields();
|
|
178
|
+
if (source != null) {
|
|
179
|
+
for (Map.Entry<String, InquiryField> entry : source.entrySet()) {
|
|
180
|
+
fields.put(entry.getKey(), serializeInquiryField(entry.getValue()));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
payload.put("fields", fields);
|
|
184
|
+
|
|
185
|
+
notifyListeners("inquiryComplete", payload);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private void onInquiryCanceled(InquiryResponse.Cancel response) {
|
|
189
|
+
JSObject payload = new JSObject();
|
|
190
|
+
if (response.getInquiryId() != null) {
|
|
191
|
+
payload.put("inquiryId", response.getInquiryId());
|
|
192
|
+
}
|
|
193
|
+
if (response.getSessionToken() != null) {
|
|
194
|
+
payload.put("sessionToken", response.getSessionToken());
|
|
195
|
+
}
|
|
196
|
+
notifyListeners("inquiryCanceled", payload);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private void onInquiryError(InquiryResponse.Error response) {
|
|
200
|
+
JSObject payload = new JSObject();
|
|
201
|
+
payload.put("error", response.getDebugMessage());
|
|
202
|
+
if (response.getErrorCode() != null) {
|
|
203
|
+
payload.put("errorCode", response.getErrorCode().name());
|
|
204
|
+
}
|
|
205
|
+
if (response.getCause() != null) {
|
|
206
|
+
payload.put("cause", response.getCause());
|
|
207
|
+
}
|
|
208
|
+
notifyListeners("inquiryError", payload);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private Object serializeInquiryField(InquiryField field) {
|
|
212
|
+
if (field instanceof InquiryField.StringField) {
|
|
213
|
+
return ((InquiryField.StringField) field).getValue();
|
|
214
|
+
}
|
|
215
|
+
if (field instanceof InquiryField.IntegerField) {
|
|
216
|
+
return ((InquiryField.IntegerField) field).getValue();
|
|
217
|
+
}
|
|
218
|
+
if (field instanceof InquiryField.FloatField) {
|
|
219
|
+
return ((InquiryField.FloatField) field).getValue();
|
|
220
|
+
}
|
|
221
|
+
if (field instanceof InquiryField.BooleanField) {
|
|
222
|
+
return ((InquiryField.BooleanField) field).getValue();
|
|
223
|
+
}
|
|
224
|
+
if (field instanceof InquiryField.DateField) {
|
|
225
|
+
java.util.Date date = ((InquiryField.DateField) field).getValue();
|
|
226
|
+
return date != null ? date.getTime() : JSONObject.NULL;
|
|
227
|
+
}
|
|
228
|
+
if (field instanceof InquiryField.DatetimeField) {
|
|
229
|
+
java.util.Date date = ((InquiryField.DatetimeField) field).getValue();
|
|
230
|
+
return date != null ? date.getTime() : JSONObject.NULL;
|
|
231
|
+
}
|
|
232
|
+
if (field instanceof InquiryField.ChoicesField) {
|
|
233
|
+
return ((InquiryField.ChoicesField) field).getValue();
|
|
234
|
+
}
|
|
235
|
+
if (field instanceof InquiryField.MultiChoicesField) {
|
|
236
|
+
JSONArray values = new JSONArray();
|
|
237
|
+
String[] source = ((InquiryField.MultiChoicesField) field).getValue();
|
|
238
|
+
if (source != null) {
|
|
239
|
+
for (String value : source) {
|
|
240
|
+
values.put(value);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return values;
|
|
244
|
+
}
|
|
245
|
+
return JSONObject.NULL;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private Environment parseEnvironment(String value) {
|
|
249
|
+
if (value == null) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
if ("production".equalsIgnoreCase(value)) {
|
|
253
|
+
return Environment.PRODUCTION;
|
|
254
|
+
}
|
|
255
|
+
if ("sandbox".equalsIgnoreCase(value)) {
|
|
256
|
+
return Environment.SANDBOX;
|
|
257
|
+
}
|
|
258
|
+
throw new IllegalArgumentException("Unsupported Persona environment '" + value + "'. Use 'production' or 'sandbox'.");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private String trimToNull(String value) {
|
|
262
|
+
if (value == null) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
String trimmed = value.trim();
|
|
266
|
+
return trimmed.isEmpty() ? null : trimmed;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
File without changes
|