@forstaglobal/react-native-mobilesdk 3.12.0 → 3.14.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 +4 -4
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/mobilesdk/MobileSdkModule.kt +25 -4
- package/android/src/main/java/com/mobilesdk/MobileSdkPackage.kt +1 -1
- package/android/src/main/java/com/mobilesdk/MobileSdkSurveyModule.kt +296 -0
- package/android/src/main/java/com/mobilesdk/module/TriggerCallback.kt +31 -1
- package/android/src/main/java/com/mobilesdk/survey/MobileSdkSurveyManager.kt +23 -0
- package/android/src/main/java/com/mobilesdk/survey/MobileSdkSurveyWrapper.kt +104 -0
- package/ios/MobileSdk.mm +8 -1
- package/ios/MobileSdk.swift +15 -2
- package/ios/MobileSdkSurvey-Bridging-Header.h +2 -0
- package/ios/MobileSdkSurvey.mm +111 -0
- package/ios/MobileSdkSurvey.swift +274 -0
- package/ios/Mobilesdk.xcodeproj/project.pbxproj +0 -2
- package/ios/Module/MobileTriggerCallback.swift +31 -1
- package/ios/Module/SdkEmitter.swift +1 -1
- package/ios/Podfile +1 -1
- package/ios/Podfile.lock +1 -1
- package/ios/Survey/MobileSdkSurveyManager.swift +21 -0
- package/ios/Survey/MobileSdkSurveyWrapper.swift +79 -0
- package/lib/commonjs/confirmitSdk.js +29 -0
- package/lib/commonjs/confirmitSdk.js.map +1 -0
- package/lib/commonjs/index.js +62 -141
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/models.js +24 -0
- package/lib/commonjs/models/models.js.map +1 -1
- package/lib/commonjs/program/triggerCallback.js +9 -21
- package/lib/commonjs/program/triggerCallback.js.map +1 -1
- package/lib/commonjs/serverSdk.js +83 -0
- package/lib/commonjs/serverSdk.js.map +1 -0
- package/lib/commonjs/survey/pageControl.js +72 -0
- package/lib/commonjs/survey/pageControl.js.map +1 -0
- package/lib/commonjs/survey/surveyFrameCallback.js +28 -0
- package/lib/commonjs/survey/surveyFrameCallback.js.map +1 -0
- package/lib/commonjs/surveySdk.js +23 -0
- package/lib/commonjs/surveySdk.js.map +1 -0
- package/lib/commonjs/triggerSdk.js +50 -0
- package/lib/commonjs/triggerSdk.js.map +1 -0
- package/lib/commonjs/views/surveyWebView.js +44 -45
- package/lib/commonjs/views/surveyWebView.js.map +1 -1
- package/lib/module/confirmitSdk.js +23 -0
- package/lib/module/confirmitSdk.js.map +1 -0
- package/lib/module/index.js +8 -113
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/models.js +19 -1
- package/lib/module/models/models.js.map +1 -1
- package/lib/module/program/triggerCallback.js +9 -21
- package/lib/module/program/triggerCallback.js.map +1 -1
- package/lib/module/serverSdk.js +77 -0
- package/lib/module/serverSdk.js.map +1 -0
- package/lib/module/survey/pageControl.js +65 -0
- package/lib/module/survey/pageControl.js.map +1 -0
- package/lib/module/survey/surveyFrameCallback.js +22 -0
- package/lib/module/survey/surveyFrameCallback.js.map +1 -0
- package/lib/module/surveySdk.js +17 -0
- package/lib/module/surveySdk.js.map +1 -0
- package/lib/module/triggerSdk.js +44 -0
- package/lib/module/triggerSdk.js.map +1 -0
- package/lib/module/views/surveyWebView.js +44 -43
- package/lib/module/views/surveyWebView.js.map +1 -1
- package/lib/typescript/confirmitSdk.d.ts +8 -0
- package/lib/typescript/confirmitSdk.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +9 -36
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/models.d.ts +91 -0
- package/lib/typescript/models/models.d.ts.map +1 -1
- package/lib/typescript/program/triggerCallback.d.ts +5 -13
- package/lib/typescript/program/triggerCallback.d.ts.map +1 -1
- package/lib/typescript/serverSdk.d.ts +24 -0
- package/lib/typescript/serverSdk.d.ts.map +1 -0
- package/lib/typescript/survey/pageControl.d.ts +27 -0
- package/lib/typescript/survey/pageControl.d.ts.map +1 -0
- package/lib/typescript/survey/surveyFrameCallback.d.ts +15 -0
- package/lib/typescript/survey/surveyFrameCallback.d.ts.map +1 -0
- package/lib/typescript/surveySdk.d.ts +10 -0
- package/lib/typescript/surveySdk.d.ts.map +1 -0
- package/lib/typescript/triggerSdk.d.ts +23 -0
- package/lib/typescript/triggerSdk.d.ts.map +1 -0
- package/lib/typescript/views/surveyWebView.d.ts +4 -13
- package/lib/typescript/views/surveyWebView.d.ts.map +1 -1
- package/package.json +6 -5
- package/react-native-mobilesdk.podspec +1 -1
- package/src/confirmitSdk.ts +34 -0
- package/src/index.tsx +47 -152
- package/src/models/models.ts +96 -0
- package/src/program/triggerCallback.ts +10 -27
- package/src/serverSdk.ts +105 -0
- package/src/survey/pageControl.ts +97 -0
- package/src/survey/surveyFrameCallback.ts +28 -0
- package/src/surveySdk.ts +32 -0
- package/src/triggerSdk.ts +62 -0
- package/src/views/surveyWebView.tsx +46 -44
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(MobileSdkSurvey, NSObject)
|
|
4
|
+
|
|
5
|
+
// survey page
|
|
6
|
+
RCT_EXTERN_METHOD(getTitle:(NSString)serverId
|
|
7
|
+
withProgramKey:(NSString)programKey
|
|
8
|
+
withSurveyId:(NSString)surveyId
|
|
9
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
10
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
11
|
+
|
|
12
|
+
RCT_EXTERN_METHOD(getPageText:(NSString)serverId
|
|
13
|
+
withProgramKey:(NSString)programKey
|
|
14
|
+
withSurveyId:(NSString)surveyId
|
|
15
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
16
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
17
|
+
|
|
18
|
+
RCT_EXTERN_METHOD(getQuestions:(NSString)serverId
|
|
19
|
+
withProgramKey:(NSString)programKey
|
|
20
|
+
withSurveyId:(NSString)surveyId
|
|
21
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
22
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
23
|
+
|
|
24
|
+
RCT_EXTERN_METHOD(setText:(NSString)serverId
|
|
25
|
+
withProgramKey:(NSString)programKey
|
|
26
|
+
withSurveyId:(NSString)surveyId
|
|
27
|
+
withQuestionId:(NSString)questionId
|
|
28
|
+
withAnswer:(NSString)answer)
|
|
29
|
+
|
|
30
|
+
RCT_EXTERN_METHOD(getText:(NSString)serverId
|
|
31
|
+
withProgramKey:(NSString)programKey
|
|
32
|
+
withSurveyId:(NSString)surveyId
|
|
33
|
+
withQuestionId:(NSString)questionId
|
|
34
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
35
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
36
|
+
|
|
37
|
+
RCT_EXTERN_METHOD(setNumeric:(NSString)serverId
|
|
38
|
+
withProgramKey:(NSString)programKey
|
|
39
|
+
withSurveyId:(NSString)surveyId
|
|
40
|
+
withQuestionId:(NSString)questionId
|
|
41
|
+
withAnswer:(double)answer
|
|
42
|
+
withIsDouble:(BOOL)isDouble)
|
|
43
|
+
|
|
44
|
+
RCT_EXTERN_METHOD(getNumeric:(NSString)serverId
|
|
45
|
+
withProgramKey:(NSString)programKey
|
|
46
|
+
withSurveyId:(NSString)surveyId
|
|
47
|
+
withQuestionId:(NSString)questionId
|
|
48
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
49
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
50
|
+
|
|
51
|
+
RCT_EXTERN_METHOD(setSingle:(NSString)serverId
|
|
52
|
+
withProgramKey:(NSString)programKey
|
|
53
|
+
withSurveyId:(NSString)surveyId
|
|
54
|
+
withQuestionId:(NSString)questionId
|
|
55
|
+
withCode:(NSString)code)
|
|
56
|
+
|
|
57
|
+
RCT_EXTERN_METHOD(getSingle:(NSString)serverId
|
|
58
|
+
withProgramKey:(NSString)programKey
|
|
59
|
+
withSurveyId:(NSString)surveyId
|
|
60
|
+
withQuestionId:(NSString)questionId
|
|
61
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
62
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
63
|
+
|
|
64
|
+
RCT_EXTERN_METHOD(setMulti:(NSString)serverId
|
|
65
|
+
withProgramKey:(NSString)programKey
|
|
66
|
+
withSurveyId:(NSString)surveyId
|
|
67
|
+
withQuestionId:(NSString)questionId
|
|
68
|
+
withCode:(NSString)answer
|
|
69
|
+
withSelected:(BOOL)selected)
|
|
70
|
+
|
|
71
|
+
RCT_EXTERN_METHOD(getMulti:(NSString)serverId
|
|
72
|
+
withProgramKey:(NSString)programKey
|
|
73
|
+
withSurveyId:(NSString)surveyId
|
|
74
|
+
withQuestionId:(NSString)questionId
|
|
75
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
76
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
77
|
+
|
|
78
|
+
// Survey Control
|
|
79
|
+
RCT_EXTERN_METHOD(startSurvey:(NSString)serverId
|
|
80
|
+
withProgramKey:(NSString)programKey
|
|
81
|
+
withSurveyId:(NSString)surveyId
|
|
82
|
+
withData:(NSDictionary)data
|
|
83
|
+
withRespondentValues:(NSDictionary)respondentValues
|
|
84
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
85
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
86
|
+
|
|
87
|
+
RCT_EXTERN_METHOD(next:(NSString)serverId
|
|
88
|
+
withProgramKey:(NSString)programKey
|
|
89
|
+
withSurveyId:(NSString)surveyId
|
|
90
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
91
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
92
|
+
|
|
93
|
+
RCT_EXTERN_METHOD(back:(NSString)serverId
|
|
94
|
+
withProgramKey:(NSString)programKey
|
|
95
|
+
withSurveyId:(NSString)surveyId
|
|
96
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
97
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
98
|
+
|
|
99
|
+
RCT_EXTERN_METHOD(quit:(NSString)serverId
|
|
100
|
+
withProgramKey:(NSString)programKey
|
|
101
|
+
withSurveyId:(NSString)surveyId
|
|
102
|
+
withUpload:(NSString)upload
|
|
103
|
+
withResolver:(RCTPromiseResolveBlock)resolve
|
|
104
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
105
|
+
|
|
106
|
+
+ (BOOL)requiresMainQueueSetup
|
|
107
|
+
{
|
|
108
|
+
return NO;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@end
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import ConfirmitMobileSDK
|
|
2
|
+
import Foundation
|
|
3
|
+
|
|
4
|
+
@objc(MobileSdkSurvey)
|
|
5
|
+
class MobileSdkSurvey: NSObject {
|
|
6
|
+
private let surveyManager = MobileSdkSurveyManager()
|
|
7
|
+
|
|
8
|
+
@objc(getTitle:withProgramKey:withSurveyId:withResolver:withRejecter:)
|
|
9
|
+
func getTitle(serverId: String, programKey: String, surveyId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
10
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
11
|
+
resolve(page.title.get())
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@objc(getPageText:withProgramKey:withSurveyId:withResolver:withRejecter:)
|
|
16
|
+
func getPageText(serverId: String, programKey: String, surveyId: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
17
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
18
|
+
resolve(page.text?.get())
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@objc(getQuestions:withProgramKey:withSurveyId:withResolver:withRejecter:)
|
|
23
|
+
func getQuestions(serverId: String, programKey: String, surveyId: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
24
|
+
var results: [[String: Any]] = []
|
|
25
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
26
|
+
for question in page.questions {
|
|
27
|
+
let nodeType = "\(question.nodeType)"
|
|
28
|
+
var result: [String: Any] = [
|
|
29
|
+
"id": question.id,
|
|
30
|
+
"nodeType": nodeType.uppercased()
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
switch question {
|
|
34
|
+
case let question as InfoQuestion:
|
|
35
|
+
result["title"] = question.title.get()
|
|
36
|
+
result["text"] = question.text.get()
|
|
37
|
+
result["instruction"] = question.instruction.get()
|
|
38
|
+
case let question as TextQuestion:
|
|
39
|
+
result["title"] = question.title.get()
|
|
40
|
+
result["text"] = question.text.get()
|
|
41
|
+
result["instruction"] = question.instruction.get()
|
|
42
|
+
case let question as NumericQuestion:
|
|
43
|
+
result["title"] = question.title.get()
|
|
44
|
+
result["text"] = question.text.get()
|
|
45
|
+
result["instruction"] = question.instruction.get()
|
|
46
|
+
case let question as SingleQuestion:
|
|
47
|
+
result["title"] = question.title.get()
|
|
48
|
+
result["text"] = question.text.get()
|
|
49
|
+
result["instruction"] = question.instruction.get()
|
|
50
|
+
result["appearance"] = question.appearance.rawValue
|
|
51
|
+
result["answers"] = getAnswers(questionAnswers: question.answers)
|
|
52
|
+
case let question as MultiQuestion:
|
|
53
|
+
result["title"] = question.title.get()
|
|
54
|
+
result["text"] = question.text.get()
|
|
55
|
+
result["instruction"] = question.instruction.get()
|
|
56
|
+
result["appearance"] = question.appearance.rawValue
|
|
57
|
+
result["answers"] = getAnswers(questionAnswers: question.answers)
|
|
58
|
+
default:
|
|
59
|
+
break
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var errors: [[String: String]] = []
|
|
63
|
+
if let question = question as? DefaultQuestion {
|
|
64
|
+
for error in question.errors {
|
|
65
|
+
errors.append([
|
|
66
|
+
"code": "\(error.code)",
|
|
67
|
+
"message": error.message
|
|
68
|
+
])
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
result["errors"] = errors
|
|
72
|
+
results.append(result)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
resolve(results)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private func getAnswers(questionAnswers: [QuestionAnswer]) -> [[String: Any]] {
|
|
79
|
+
var answers: [[String: Any]] = []
|
|
80
|
+
for answer in questionAnswers {
|
|
81
|
+
var result: [String: Any] = [
|
|
82
|
+
"code": answer.code,
|
|
83
|
+
"text": answer.text.get(),
|
|
84
|
+
"isHeader": answer.isHeader
|
|
85
|
+
]
|
|
86
|
+
var groupAnswer: [[String: Any]] = []
|
|
87
|
+
for innerAnswer in answer.answers {
|
|
88
|
+
groupAnswer.append([
|
|
89
|
+
"code": innerAnswer.code,
|
|
90
|
+
"text": innerAnswer.text.get(),
|
|
91
|
+
"isHeader": innerAnswer.isHeader
|
|
92
|
+
])
|
|
93
|
+
}
|
|
94
|
+
result["answers"] = groupAnswer
|
|
95
|
+
answers.append(result)
|
|
96
|
+
}
|
|
97
|
+
return answers
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Question Control
|
|
101
|
+
@objc(setText:withProgramKey:withSurveyId:withQuestionId:withAnswer:)
|
|
102
|
+
func setText(serverId: String, programKey: String, surveyId: String, questionId: String, answer: String) {
|
|
103
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
104
|
+
if let question = page.questions.first(where: { $0.id == questionId }), let text = question as? TextQuestion {
|
|
105
|
+
text.setValue(value: answer)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@objc(getText:withProgramKey:withSurveyId:withQuestionId:withResolver:withRejecter:)
|
|
111
|
+
func getText(serverId: String, programKey: String, surveyId: String, questionId: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
112
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
113
|
+
if let question = page.questions.first(where: { $0.id == questionId }), let text = question as? TextQuestion {
|
|
114
|
+
resolve(text.getValue())
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@objc(setNumeric:withProgramKey:withSurveyId:withQuestionId:withAnswer:withIsDouble:)
|
|
120
|
+
func setNumeric(serverId: String, programKey: String, surveyId: String, questionId: String, answer: Double, isDouble: Bool) {
|
|
121
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
122
|
+
if let question = page.questions.first(where: { $0.id == questionId }), let numeric = question as? NumericQuestion {
|
|
123
|
+
if isDouble {
|
|
124
|
+
numeric.setValue(value: answer)
|
|
125
|
+
} else {
|
|
126
|
+
numeric.setValue(value: Int(answer))
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@objc(getNumeric:withProgramKey:withSurveyId:withQuestionId:withResolver:withRejecter:)
|
|
133
|
+
func getNumeric(serverId: String, programKey: String, surveyId: String, questionId: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
134
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
135
|
+
if let question = page.questions.first(where: { $0.id == questionId }), let numeric = question as? TextQuestion {
|
|
136
|
+
resolve(numeric.getValue())
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@objc(setSingle:withProgramKey:withSurveyId:withQuestionId:withCode:)
|
|
142
|
+
func setSingle(serverId: String, programKey: String, surveyId: String, questionId: String, code: String) {
|
|
143
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
144
|
+
if let question = page.questions.first(where: { $0.id == questionId }), let single = question as? SingleQuestion {
|
|
145
|
+
let allAnswers = single.answers.flatMap {
|
|
146
|
+
if $0.isHeader {
|
|
147
|
+
return $0.answers
|
|
148
|
+
}
|
|
149
|
+
return [$0]
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if let questionAnswer = allAnswers.first(where: { $0.code == code }) {
|
|
153
|
+
single.select(answer: questionAnswer)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@objc(getSingle:withProgramKey:withSurveyId:withQuestionId:withResolver:withRejecter:)
|
|
160
|
+
func getSingle(serverId: String, programKey: String, surveyId: String, questionId: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
161
|
+
var result: [String: Any] = [:]
|
|
162
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
163
|
+
if let question = page.questions.first(where: { $0.id == questionId }), let single = question as? SingleQuestion, let selected = single.selected() {
|
|
164
|
+
result["code"] = selected.code
|
|
165
|
+
result["text"] = selected.text
|
|
166
|
+
result["isHeader"] = selected.isHeader
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
resolve(result)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@objc(setMulti:withProgramKey:withSurveyId:withQuestionId:withCode:withSelected:)
|
|
173
|
+
func setMulti(serverId: String, programKey: String, surveyId: String, questionId: String, code: String, selected: Bool) {
|
|
174
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
175
|
+
if let question = page.questions.first(where: { $0.id == questionId }), let multi = question as? MultiQuestion {
|
|
176
|
+
let allAnswers = multi.answers.flatMap {
|
|
177
|
+
if $0.isHeader {
|
|
178
|
+
return $0.answers
|
|
179
|
+
}
|
|
180
|
+
return [$0]
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if let questionAnswer = allAnswers.first(where: { $0.code == code }) {
|
|
184
|
+
multi.set(answer: questionAnswer, select: selected)
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
@objc(getMulti:withProgramKey:withSurveyId:withQuestionId:withResolver:withRejecter:)
|
|
191
|
+
func getMulti(serverId: String, programKey: String, surveyId: String, questionId: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
192
|
+
var result: [[String: Any]] = []
|
|
193
|
+
getSurveyPage(serverId: serverId, programKey: programKey, surveyId: surveyId) { page in
|
|
194
|
+
if let question = page.questions.first(where: { $0.id == questionId }), let multi = question as? MultiQuestion {
|
|
195
|
+
let allAnswers = multi.answers.flatMap {
|
|
196
|
+
if $0.isHeader {
|
|
197
|
+
return $0.answers
|
|
198
|
+
}
|
|
199
|
+
return [$0]
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for answer in allAnswers {
|
|
203
|
+
if multi.get(answer: answer) {
|
|
204
|
+
result.append([
|
|
205
|
+
"code": answer.code,
|
|
206
|
+
"text": answer.text.get(),
|
|
207
|
+
"isHeader": answer.isHeader
|
|
208
|
+
])
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
resolve(result)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private func getSurveyPage(serverId: String, programKey: String, surveyId: String, block: (_ page: SurveyPage) -> Void) {
|
|
217
|
+
if let wrapper = surveyManager.getSurvey(serverId: serverId, programKey: programKey, surveyId: surveyId), let surveyFrame = wrapper.surveyFrame, let page = surveyFrame.page {
|
|
218
|
+
block(page)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Survey Control
|
|
223
|
+
@objc(startSurvey:withProgramKey:withSurveyId:withData:withRespondentValues:withResolver:withRejecter:)
|
|
224
|
+
func startSurvey(serverId: String, programKey: String, surveyId: String, data: NSDictionary, respondentValues: NSDictionary, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
225
|
+
if let wrapper = surveyManager.getSurvey(serverId: serverId, programKey: programKey, surveyId: surveyId) {
|
|
226
|
+
do {
|
|
227
|
+
if let result = try wrapper.startSurvey(customData: data.swiftDictionary, respondentValues: respondentValues.swiftDictionary) {
|
|
228
|
+
resolve([
|
|
229
|
+
"success": result.success,
|
|
230
|
+
"message": result.message
|
|
231
|
+
])
|
|
232
|
+
} else {
|
|
233
|
+
reject("survey", "failed to start survey", nil)
|
|
234
|
+
}
|
|
235
|
+
} catch {
|
|
236
|
+
// let reject resolve the
|
|
237
|
+
reject("survey", "failed to start survey", error)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
@objc(next:withProgramKey:withSurveyId:withResolver:withRejecter:)
|
|
243
|
+
func next(serverId: String, programKey: String, surveyId: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
244
|
+
surveyControlAction(serverId: serverId, programKey: programKey, surveyId: surveyId, resolve: resolve, reject: reject) { surveyFrame in
|
|
245
|
+
surveyFrame.next()
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
@objc(back:withProgramKey:withSurveyId:withResolver:withRejecter:)
|
|
250
|
+
func back(serverId: String, programKey: String, surveyId: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
251
|
+
surveyControlAction(serverId: serverId, programKey: programKey, surveyId: surveyId, resolve: resolve, reject: reject) { surveyFrame in
|
|
252
|
+
surveyFrame.back()
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@objc(quit:withProgramKey:withSurveyId:withUpload:withResolver:withRejecter:)
|
|
257
|
+
func quit(serverId: String, programKey: String, surveyId: String, upload: Bool, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
258
|
+
surveyControlAction(serverId: serverId, programKey: programKey, surveyId: surveyId, resolve: resolve, reject: reject) { surveyFrame in
|
|
259
|
+
surveyFrame.quit(upload: upload)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private func surveyControlAction(serverId: String, programKey: String, surveyId: String, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock, block: (_ surveyFrame: SurveyFrame) -> SurveyFrameActionResult) {
|
|
264
|
+
if let wrapper = surveyManager.getSurvey(serverId: serverId, programKey: programKey, surveyId: surveyId), let surveyFrame = wrapper.surveyFrame {
|
|
265
|
+
let result = block(surveyFrame)
|
|
266
|
+
resolve([
|
|
267
|
+
"success": result.success,
|
|
268
|
+
"message": result.message
|
|
269
|
+
])
|
|
270
|
+
} else {
|
|
271
|
+
reject("survey", "failed to find active survey for serverId: \(serverId) programKey: \(programKey) surveyId: \(surveyId)", nil)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
/* Begin PBXFileReference section */
|
|
29
29
|
0E4FC8FADE7EB672217188C9 /* Pods-Mobilesdk.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mobilesdk.release.xcconfig"; path = "Target Support Files/Pods-Mobilesdk/Pods-Mobilesdk.release.xcconfig"; sourceTree = "<group>"; };
|
|
30
30
|
134814201AA4EA6300B7C361 /* libMobilesdk.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libMobilesdk.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
31
|
-
2D326A992AD8B38F00B2A5C7 /* Exts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Exts.swift; sourceTree = "<group>"; };
|
|
32
31
|
2D326A9D2AD8B53200B2A5C7 /* TriggerCallback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TriggerCallback.swift; sourceTree = "<group>"; };
|
|
33
32
|
2D326A9E2AD8B53200B2A5C7 /* TriggerCallbackBridge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TriggerCallbackBridge.m; sourceTree = "<group>"; };
|
|
34
33
|
6A73BA7DBF7DE33508DCC5DF /* Pods_Mobilesdk.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Mobilesdk.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
@@ -88,7 +87,6 @@
|
|
|
88
87
|
isa = PBXGroup;
|
|
89
88
|
children = (
|
|
90
89
|
2D326A9C2AD8B51500B2A5C7 /* Module */,
|
|
91
|
-
2D326A992AD8B38F00B2A5C7 /* Exts.swift */,
|
|
92
90
|
F4FF95D6245B92E800C19C63 /* Mobilesdk.swift */,
|
|
93
91
|
B3E7B5891CC2AC0600A0062D /* Mobilesdk.mm */,
|
|
94
92
|
F4FF95D5245B92E700C19C63 /* Mobilesdk-Bridging-Header.h */,
|
|
@@ -12,7 +12,37 @@ class MobileTriggerCallback: ProgramCallback {
|
|
|
12
12
|
|
|
13
13
|
func onSurveyDownloadCompleted(triggerInfo: ConfirmitMobileSDK.TriggerInfo, surveyId: String, error: Error?) {}
|
|
14
14
|
|
|
15
|
-
func onSurveyStart(config: ConfirmitMobileSDK.SurveyFrameConfig) {
|
|
15
|
+
func onSurveyStart(config: ConfirmitMobileSDK.SurveyFrameConfig) {
|
|
16
|
+
MobileSdkSurveyManager().addSurvey(serverId: serverId, programKey: programKey, surveyId: config.surveyId, survey: MobileSdkSurveyWrapper(config: config))
|
|
17
|
+
|
|
18
|
+
var values: [String: Any] = [
|
|
19
|
+
"serverId": serverId,
|
|
20
|
+
"programKey": programKey,
|
|
21
|
+
"surveyId": config.surveyId
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
if let languageId = config.languageId {
|
|
25
|
+
values["languageId"] = languageId
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var customData: [String: Any] = [:]
|
|
29
|
+
for data in config.customData {
|
|
30
|
+
customData[data.key] = data.value
|
|
31
|
+
}
|
|
32
|
+
values["customTable"] = customData
|
|
33
|
+
|
|
34
|
+
var respondentValue: [String: Any] = [:]
|
|
35
|
+
for respondent in config.respondentValues {
|
|
36
|
+
respondentValue[respondent.key] = respondent.value
|
|
37
|
+
}
|
|
38
|
+
values["respondentValue"] = respondentValue
|
|
39
|
+
|
|
40
|
+
SdkEmitter.shared.sendEvent(withName: "__mobileOnSurveyStart", body: [
|
|
41
|
+
"serverId": serverId,
|
|
42
|
+
"programKey": programKey,
|
|
43
|
+
"surveyId": config.surveyId
|
|
44
|
+
])
|
|
45
|
+
}
|
|
16
46
|
|
|
17
47
|
func onScenarioLoad(triggerInfo: ConfirmitMobileSDK.TriggerInfo, error: Error?) {
|
|
18
48
|
SdkEmitter.shared.sendEvent(withName: "__mobileOnScenarioLoad", body: [
|
|
@@ -21,6 +21,6 @@ class SdkEmitter: RCTEventEmitter {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
override func supportedEvents() -> [String]! {
|
|
24
|
-
return ["__mobileOnWebSurveyStart", "__mobileOnScenarioError", "__mobileOnScenarioLoad", "__mobileOnSurveyClosed"]
|
|
24
|
+
return ["__mobileOnWebSurveyStart", "__mobileOnSurveyStart", "__mobileOnScenarioError", "__mobileOnScenarioLoad", "__mobileOnSurveyClosed", "__mobileOnSurveyErrored", "__mobileOnSurveyFinished", "__mobileOnSurveyPageReady", "__mobileOnSurveyQuit"]
|
|
25
25
|
}
|
|
26
26
|
}
|
package/ios/Podfile
CHANGED
package/ios/Podfile.lock
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
class MobileSdkSurveyManager {
|
|
4
|
+
private static var activeSurvey: [String: MobileSdkSurveyWrapper] = [:]
|
|
5
|
+
|
|
6
|
+
func getSurvey(serverId: String, programKey: String, surveyId: String) -> MobileSdkSurveyWrapper? {
|
|
7
|
+
return MobileSdkSurveyManager.activeSurvey[getKey(serverId: serverId, programKey: programKey, surveyId: surveyId)]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
func addSurvey(serverId: String, programKey: String, surveyId: String, survey: MobileSdkSurveyWrapper) {
|
|
11
|
+
MobileSdkSurveyManager.activeSurvey[getKey(serverId: serverId, programKey: programKey, surveyId: surveyId)] = survey
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func removeSurvey(serverId: String, programKey: String, surveyId: String) {
|
|
15
|
+
MobileSdkSurveyManager.activeSurvey.removeValue(forKey: getKey(serverId: serverId, programKey: programKey, surveyId: surveyId))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private func getKey(serverId: String, programKey: String, surveyId: String) -> String {
|
|
19
|
+
return "\(serverId)_\(programKey)_\(surveyId)"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import ConfirmitMobileSDK
|
|
3
|
+
|
|
4
|
+
class MobileSdkSurveyWrapper {
|
|
5
|
+
var surveyFrame: SurveyFrame? = SurveyFrame()
|
|
6
|
+
private let config: SurveyFrameConfig
|
|
7
|
+
private let surveyManager = MobileSdkSurveyManager()
|
|
8
|
+
|
|
9
|
+
init(config: SurveyFrameConfig) {
|
|
10
|
+
self.config = config
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func startSurvey(customData: [String:String], respondentValues: [String: String]) throws -> SurveyFrameActionResult? {
|
|
14
|
+
for data in customData {
|
|
15
|
+
config.customData[data.key] = data.value
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
config.respondentValues = respondentValues
|
|
19
|
+
surveyFrame?.delegate = self
|
|
20
|
+
try surveyFrame?.load(config: config)
|
|
21
|
+
return surveyFrame?.start()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
extension MobileSdkSurveyWrapper: SurveyFrameDelegate {
|
|
26
|
+
func onSurveyPageReady(page: ConfirmitMobileSDK.SurveyPage) {
|
|
27
|
+
SdkEmitter.shared.sendEvent(withName: "__mobileOnSurveyPageReady", body: [
|
|
28
|
+
"serverId": config.serverId,
|
|
29
|
+
"programKey": config.programKey,
|
|
30
|
+
"surveyId": config.surveyId,
|
|
31
|
+
"forwardText": page.forwardText,
|
|
32
|
+
"backwardText": page.backwardText,
|
|
33
|
+
"okText": page.okText,
|
|
34
|
+
"showForward": page.showForward,
|
|
35
|
+
"showBackward": page.showBackward
|
|
36
|
+
])
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
func onSurveyErrored(page: ConfirmitMobileSDK.SurveyPage, values: [String : String?], error: any Error) {
|
|
40
|
+
SdkEmitter.shared.sendEvent(withName: "__mobileOnSurveyErrored", body: [
|
|
41
|
+
"forwardText": page.forwardText,
|
|
42
|
+
"backwardText": page.backwardText,
|
|
43
|
+
"okText": page.okText,
|
|
44
|
+
"showForward": page.showForward,
|
|
45
|
+
"showBackward": page.showBackward,
|
|
46
|
+
"error": [
|
|
47
|
+
"message": error.localizedDescription
|
|
48
|
+
],
|
|
49
|
+
"values": values
|
|
50
|
+
])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
func onSurveyFinished(page: ConfirmitMobileSDK.SurveyPage, values: [String : String?]) {
|
|
54
|
+
SdkEmitter.shared.sendEvent(withName: "__mobileOnSurveyFinished", body: [
|
|
55
|
+
"forwardText": page.forwardText,
|
|
56
|
+
"backwardText": page.backwardText,
|
|
57
|
+
"okText": page.okText,
|
|
58
|
+
"showForward": page.showForward,
|
|
59
|
+
"showBackward": page.showBackward,
|
|
60
|
+
"values": values
|
|
61
|
+
])
|
|
62
|
+
|
|
63
|
+
cleanupSurvey()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func onSurveyQuit(values: [String : String?]) {
|
|
67
|
+
SdkEmitter.shared.sendEvent(withName: "__mobileOnSurveyQuit", body: [
|
|
68
|
+
"values": values
|
|
69
|
+
])
|
|
70
|
+
|
|
71
|
+
cleanupSurvey()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private func cleanupSurvey() {
|
|
75
|
+
surveyFrame?.delegate = nil
|
|
76
|
+
surveyFrame = nil
|
|
77
|
+
surveyManager.removeSurvey(serverId: config.serverId, programKey: config.programKey ?? "", surveyId: config.surveyId)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ConfirmitSdk = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
const LINKING_ERROR = `The package 'react-native-mobilesdk' doesn't seem to be linked. Make sure: \n\n${_reactNative.Platform.select({
|
|
9
|
+
ios: "- You have run 'pod install'\n",
|
|
10
|
+
default: ''
|
|
11
|
+
})}- You rebuilt the app after installing the package\n` + '- You are not using Expo Go\n';
|
|
12
|
+
const MobileSdk = _reactNative.NativeModules.MobileSdk ? _reactNative.NativeModules.MobileSdk : new Proxy({}, {
|
|
13
|
+
get() {
|
|
14
|
+
throw new Error(LINKING_ERROR);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
class Manager {
|
|
18
|
+
injectWebView() {
|
|
19
|
+
MobileSdk.injectWebView();
|
|
20
|
+
}
|
|
21
|
+
async initSdk() {
|
|
22
|
+
return MobileSdk.initSdk();
|
|
23
|
+
}
|
|
24
|
+
enableLog(enable) {
|
|
25
|
+
MobileSdk.enableLog(enable);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const ConfirmitSdk = exports.ConfirmitSdk = new Manager();
|
|
29
|
+
//# sourceMappingURL=confirmitSdk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","MobileSdk","NativeModules","Proxy","get","Error","Manager","injectWebView","initSdk","enableLog","enable","ConfirmitSdk","exports"],"sourceRoot":"../../src","sources":["confirmitSdk.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACf,kFAAkFC,qBAAQ,CAACC,MAAM,CAAC;EAC9FC,GAAG,EAAE,gCAAgC;EACrCC,OAAO,EAAE;AACb,CAAC,CAAC,sDAAsD,GAAG,+BAA+B;AAE9F,MAAMC,SAAS,GAAGC,0BAAa,CAACD,SAAS,GACnCC,0BAAa,CAACD,SAAS,GACvB,IAAIE,KAAK,CACL,CAAC,CAAC,EACF;EACIC,GAAGA,CAAA,EAAG;IACF,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAClC;AACJ,CACJ,CAAC;AAEP,MAAMU,OAAO,CAAC;EACHC,aAAaA,CAAA,EAAG;IACnBN,SAAS,CAACM,aAAa,CAAC,CAAC;EAC7B;EAEA,MAAaC,OAAOA,CAAA,EAAkB;IAClC,OAAOP,SAAS,CAACO,OAAO,CAAC,CAAC;EAC9B;EAEOC,SAASA,CAACC,MAAe,EAAE;IAC9BT,SAAS,CAACQ,SAAS,CAACC,MAAM,CAAC;EAC/B;AACJ;AAEO,MAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,IAAIL,OAAO,CAAC,CAAC","ignoreList":[]}
|