@forstaglobal/react-native-mobilesdk 3.12.0 → 3.13.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.
Files changed (92) hide show
  1. package/README.md +3 -3
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/mobilesdk/MobileSdkModule.kt +25 -4
  4. package/android/src/main/java/com/mobilesdk/MobileSdkPackage.kt +1 -1
  5. package/android/src/main/java/com/mobilesdk/MobileSdkSurveyModule.kt +296 -0
  6. package/android/src/main/java/com/mobilesdk/module/TriggerCallback.kt +31 -1
  7. package/android/src/main/java/com/mobilesdk/survey/MobileSdkSurveyManager.kt +23 -0
  8. package/android/src/main/java/com/mobilesdk/survey/MobileSdkSurveyWrapper.kt +104 -0
  9. package/ios/MobileSdk.mm +8 -1
  10. package/ios/MobileSdk.swift +15 -2
  11. package/ios/MobileSdkSurvey-Bridging-Header.h +2 -0
  12. package/ios/MobileSdkSurvey.mm +111 -0
  13. package/ios/MobileSdkSurvey.swift +274 -0
  14. package/ios/Mobilesdk.xcodeproj/project.pbxproj +0 -2
  15. package/ios/Module/MobileTriggerCallback.swift +31 -1
  16. package/ios/Module/SdkEmitter.swift +1 -1
  17. package/ios/Podfile +1 -1
  18. package/ios/Podfile.lock +1 -1
  19. package/ios/Survey/MobileSdkSurveyManager.swift +21 -0
  20. package/ios/Survey/MobileSdkSurveyWrapper.swift +79 -0
  21. package/lib/commonjs/confirmitSdk.js +29 -0
  22. package/lib/commonjs/confirmitSdk.js.map +1 -0
  23. package/lib/commonjs/index.js +48 -140
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/models/models.js +24 -0
  26. package/lib/commonjs/models/models.js.map +1 -1
  27. package/lib/commonjs/program/triggerCallback.js +9 -21
  28. package/lib/commonjs/program/triggerCallback.js.map +1 -1
  29. package/lib/commonjs/serverSdk.js +83 -0
  30. package/lib/commonjs/serverSdk.js.map +1 -0
  31. package/lib/commonjs/survey/pageControl.js +72 -0
  32. package/lib/commonjs/survey/pageControl.js.map +1 -0
  33. package/lib/commonjs/survey/surveyFrameCallback.js +28 -0
  34. package/lib/commonjs/survey/surveyFrameCallback.js.map +1 -0
  35. package/lib/commonjs/surveySdk.js +23 -0
  36. package/lib/commonjs/surveySdk.js.map +1 -0
  37. package/lib/commonjs/triggerSdk.js +50 -0
  38. package/lib/commonjs/triggerSdk.js.map +1 -0
  39. package/lib/commonjs/views/surveyWebView.js +42 -42
  40. package/lib/commonjs/views/surveyWebView.js.map +1 -1
  41. package/lib/module/confirmitSdk.js +23 -0
  42. package/lib/module/confirmitSdk.js.map +1 -0
  43. package/lib/module/index.js +7 -113
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/models/models.js +19 -1
  46. package/lib/module/models/models.js.map +1 -1
  47. package/lib/module/program/triggerCallback.js +9 -21
  48. package/lib/module/program/triggerCallback.js.map +1 -1
  49. package/lib/module/serverSdk.js +77 -0
  50. package/lib/module/serverSdk.js.map +1 -0
  51. package/lib/module/survey/pageControl.js +65 -0
  52. package/lib/module/survey/pageControl.js.map +1 -0
  53. package/lib/module/survey/surveyFrameCallback.js +22 -0
  54. package/lib/module/survey/surveyFrameCallback.js.map +1 -0
  55. package/lib/module/surveySdk.js +17 -0
  56. package/lib/module/surveySdk.js.map +1 -0
  57. package/lib/module/triggerSdk.js +44 -0
  58. package/lib/module/triggerSdk.js.map +1 -0
  59. package/lib/module/views/surveyWebView.js +43 -42
  60. package/lib/module/views/surveyWebView.js.map +1 -1
  61. package/lib/typescript/confirmitSdk.d.ts +8 -0
  62. package/lib/typescript/confirmitSdk.d.ts.map +1 -0
  63. package/lib/typescript/index.d.ts +8 -36
  64. package/lib/typescript/index.d.ts.map +1 -1
  65. package/lib/typescript/models/models.d.ts +91 -0
  66. package/lib/typescript/models/models.d.ts.map +1 -1
  67. package/lib/typescript/program/triggerCallback.d.ts +5 -13
  68. package/lib/typescript/program/triggerCallback.d.ts.map +1 -1
  69. package/lib/typescript/serverSdk.d.ts +24 -0
  70. package/lib/typescript/serverSdk.d.ts.map +1 -0
  71. package/lib/typescript/survey/pageControl.d.ts +27 -0
  72. package/lib/typescript/survey/pageControl.d.ts.map +1 -0
  73. package/lib/typescript/survey/surveyFrameCallback.d.ts +15 -0
  74. package/lib/typescript/survey/surveyFrameCallback.d.ts.map +1 -0
  75. package/lib/typescript/surveySdk.d.ts +10 -0
  76. package/lib/typescript/surveySdk.d.ts.map +1 -0
  77. package/lib/typescript/triggerSdk.d.ts +23 -0
  78. package/lib/typescript/triggerSdk.d.ts.map +1 -0
  79. package/lib/typescript/views/surveyWebView.d.ts +4 -13
  80. package/lib/typescript/views/surveyWebView.d.ts.map +1 -1
  81. package/package.json +4 -3
  82. package/react-native-mobilesdk.podspec +1 -1
  83. package/src/confirmitSdk.ts +34 -0
  84. package/src/index.tsx +45 -152
  85. package/src/models/models.ts +96 -0
  86. package/src/program/triggerCallback.ts +10 -27
  87. package/src/serverSdk.ts +105 -0
  88. package/src/survey/pageControl.ts +97 -0
  89. package/src/survey/surveyFrameCallback.ts +28 -0
  90. package/src/surveySdk.ts +32 -0
  91. package/src/triggerSdk.ts +62 -0
  92. package/src/views/surveyWebView.tsx +46 -44
package/src/index.tsx CHANGED
@@ -1,155 +1,48 @@
1
- import { NativeModules, Platform } from 'react-native';
2
- import type { IScenarioCallback, IServerModel, IWebSurveyModel } from './models/models';
3
- import type { ISdkListener } from './program/triggerCallback';
1
+ import { ConfirmitSdk } from './confirmitSdk';
2
+ import {
3
+ IDefaultQuestion,
4
+ IInfoQuestion,
5
+ IMultiQuestion,
6
+ INumericQuestion,
7
+ IPageControl,
8
+ IQuestion,
9
+ IScenarioCallback,
10
+ IServerModel,
11
+ ISingleQuestion,
12
+ ISurveyError,
13
+ ISurveyErrored,
14
+ ISurveyFinished,
15
+ ISurveyFrameActionResult,
16
+ ISurveyModel,
17
+ ITextQuestion,
18
+ IWebSurveyModel,
19
+ NodeType,
20
+ QuestionAnswer
21
+ } from './models/models';
4
22
  import { TriggerManager } from './program/triggerCallback';
23
+ import { ServerSdk } from './serverSdk';
24
+ import { SurveyFrameManager } from './survey/surveyFrameCallback';
25
+ import { SurveySdk } from './surveySdk';
26
+ import { TriggerSdk } from './triggerSdk';
5
27
  import SurveyWebView from './views/surveyWebView';
6
28
 
7
- const LINKING_ERROR =
8
- `The package 'react-native-mobilesdk' doesn't seem to be linked. Make sure: \n\n${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
-
13
- const MobileSdk = NativeModules.MobileSdk
14
- ? NativeModules.MobileSdk
15
- : new Proxy(
16
- {},
17
- {
18
- get() {
19
- throw new Error(LINKING_ERROR);
20
- }
21
- }
22
- );
23
-
24
- export type { IScenarioCallback, IServerModel, IWebSurveyModel, ISdkListener };
25
-
26
- export { SurveyWebView, TriggerManager };
27
-
28
- function transformServer(result: any): IServerModel {
29
- return {
30
- host: result.host,
31
- name: result.name,
32
- serverId: result.serverId
33
- };
34
- }
35
-
36
- export function injectWebView() {
37
- MobileSdk.injectWebView();
38
- }
39
-
40
- // Confirmit
41
- export function initSdk() {
42
- return MobileSdk.initSdk();
43
- }
44
-
45
- export function enableLog(enable: boolean) {
46
- MobileSdk.enableLog(enable);
47
- }
48
-
49
- // Trigger
50
- export function notifyEvent(event: string) {
51
- MobileSdk.notifyEvent(event);
52
- }
53
-
54
- export function notifyAppForeground(data: { [Name: string]: string }) {
55
- MobileSdk.notifyAppForeground(data);
56
- }
57
-
58
- export function deleteProgram(serverId: string, programKey: string, deleteCustomData: boolean): Promise<void> {
59
- return MobileSdk.deleteProgram(serverId, programKey, deleteCustomData);
60
- }
61
-
62
- export function deleteAll(deleteCustomData: boolean): Promise<void> {
63
- return MobileSdk.deleteAll(deleteCustomData);
64
- }
65
-
66
- export function setCallback(serverId: string, programKey: string) {
67
- MobileSdk.setCallback(serverId, programKey);
68
- }
69
-
70
- export function removeCallback(serverId: string, programKey: string) {
71
- MobileSdk.removeCallback(serverId, programKey);
72
- }
73
-
74
- export function triggerDownload(serverId: string, programKey: string): Promise<boolean> {
75
- return MobileSdk.triggerDownload(serverId, programKey);
76
- }
77
-
78
- export function notifyEventWithData(event: string, data: { [Name: string]: string }) {
79
- MobileSdk.notifyEventWithData(event, data);
80
- }
81
-
82
- // Server
83
- export async function getUs(): Promise<IServerModel> {
84
- return transformServer(await MobileSdk.getUs());
85
- }
86
-
87
- export async function getUk(): Promise<IServerModel> {
88
- return transformServer(await MobileSdk.getUk());
89
- }
90
-
91
- export async function getAustralia(): Promise<IServerModel> {
92
- return transformServer(await MobileSdk.getAustralia());
93
- }
94
-
95
- export async function getCanada(): Promise<IServerModel> {
96
- return transformServer(await MobileSdk.getCanada());
97
- }
98
-
99
- export async function getGermany(): Promise<IServerModel> {
100
- return transformServer(await MobileSdk.getGermany());
101
- }
102
-
103
- export async function getHxPlatform(): Promise<IServerModel> {
104
- return transformServer(await MobileSdk.getHxPlatform());
105
- }
106
-
107
- export async function getHxAustralia(): Promise<IServerModel> {
108
- return transformServer(await MobileSdk.getHxAustralia());
109
- }
110
-
111
- export async function configureUs(clientId: string, clientSecret: string): Promise<void> {
112
- return await MobileSdk.configureUs(clientId, clientSecret);
113
- }
114
-
115
- export async function configureUk(clientId: string, clientSecret: string): Promise<void> {
116
- return await MobileSdk.configureUk(clientId, clientSecret);
117
- }
118
-
119
- export async function configureAustralia(clientId: string, clientSecret: string): Promise<void> {
120
- return await MobileSdk.configureAustralia(clientId, clientSecret);
121
- }
122
-
123
- export async function configureCanada(clientId: string, clientSecret: string): Promise<void> {
124
- return await MobileSdk.configureCanada(clientId, clientSecret);
125
- }
126
-
127
- export async function configureGermany(clientId: string, clientSecret: string): Promise<void> {
128
- return await MobileSdk.configureGermany(clientId, clientSecret);
129
- }
130
-
131
- export async function configureHxPlatform(clientId: string, clientSecret: string): Promise<void> {
132
- return await MobileSdk.configureHxPlatform(clientId, clientSecret);
133
- }
134
-
135
- export async function configureHxAustralia(clientId: string, clientSecret: string): Promise<void> {
136
- return await MobileSdk.configureHxAustralia(clientId, clientSecret);
137
- }
138
-
139
- export async function configureServer(name: string, host: string, clientId: string, clientSecret: string): Promise<IServerModel> {
140
- return transformServer(await MobileSdk.configureServer(name, host, clientId, clientSecret));
141
- }
142
-
143
- export async function getServer(serverId: string): Promise<IServerModel> {
144
- return transformServer(await MobileSdk.getServer(serverId));
145
- }
146
-
147
- export async function getServers(): Promise<IServerModel[]> {
148
- const result = await MobileSdk.getServers();
149
- const servers = [];
150
- for (const server of result) {
151
- servers.push(transformServer(server));
152
- }
153
-
154
- return servers;
155
- }
29
+ export type {
30
+ IScenarioCallback,
31
+ IServerModel,
32
+ IWebSurveyModel,
33
+ ISurveyModel,
34
+ IQuestion,
35
+ IPageControl,
36
+ ISurveyErrored,
37
+ ISurveyFinished,
38
+ ISurveyError,
39
+ ISurveyFrameActionResult,
40
+ IDefaultQuestion,
41
+ ITextQuestion,
42
+ INumericQuestion,
43
+ ISingleQuestion,
44
+ IMultiQuestion,
45
+ IInfoQuestion
46
+ };
47
+
48
+ export { SurveyWebView, TriggerManager, SurveyFrameManager, NodeType, QuestionAnswer, ConfirmitSdk, TriggerSdk, ServerSdk, SurveySdk };
@@ -9,8 +9,104 @@ export interface IWebSurveyModel {
9
9
  url: string;
10
10
  }
11
11
 
12
+ export interface ISurveyModel {
13
+ serverId: string;
14
+ programKey: string;
15
+ surveyId: string;
16
+ languageId: number | null;
17
+ customData: { [key: string]: string };
18
+ respondentValue: { [key: string]: string };
19
+ }
20
+
12
21
  export interface IScenarioCallback {
13
22
  serverId: string;
14
23
  programKey: string;
15
24
  error: string;
16
25
  }
26
+
27
+ export interface ISurveyFrameActionResult {
28
+ success: string;
29
+ message: string;
30
+ }
31
+
32
+ export enum NodeType {
33
+ Single = 'SINGLE',
34
+ Multi = 'MULTI',
35
+ Text = 'TEXT',
36
+ Numeric = 'NUMERIC',
37
+ Info = 'INFO',
38
+ NotSupported = 'NOT_SUPPORTED'
39
+ }
40
+
41
+ export interface IQuestion {
42
+ id: string;
43
+ nodeType: NodeType;
44
+ }
45
+
46
+ export interface IPageControl {
47
+ forwardText: string;
48
+ backwardText: string;
49
+ okText: string;
50
+ showForward: boolean;
51
+ showBackward: boolean;
52
+ serverId: string;
53
+ surveyId: string;
54
+ programKey: string;
55
+ }
56
+
57
+ export interface ISurveyErrored extends IPageControl {
58
+ error: ISurveyError;
59
+ values: { [key: string]: string };
60
+ }
61
+
62
+ export interface ISurveyFinished extends IPageControl {
63
+ values: { [key: string]: string };
64
+ }
65
+
66
+ export interface ISurveyError {
67
+ message: string;
68
+ stack: string;
69
+ }
70
+
71
+ export interface IDefaultQuestion {
72
+ id: string;
73
+ nodeType: NodeType;
74
+ title: string;
75
+ titleSpan: string;
76
+ text: string;
77
+ instruction: string;
78
+ errors: ISurveyError[];
79
+ }
80
+
81
+ export interface IInfoQuestion extends IDefaultQuestion {}
82
+
83
+ export interface ITextQuestion extends IDefaultQuestion {}
84
+
85
+ export interface INumericQuestion extends IDefaultQuestion {}
86
+
87
+ export interface ISingleQuestion extends IDefaultQuestion {
88
+ appearance: number;
89
+ answers: QuestionAnswer[];
90
+ }
91
+
92
+ export interface IMultiQuestion extends IDefaultQuestion {
93
+ appearance: number;
94
+ answers: QuestionAnswer[];
95
+ }
96
+
97
+ export interface QuestionAnswer {
98
+ code: string;
99
+ text: string;
100
+ isHeader: boolean;
101
+ answers: QuestionAnswer[];
102
+ }
103
+
104
+ export enum SingleAppearance {
105
+ radioButton,
106
+ answerButton,
107
+ dropDown,
108
+ slider,
109
+ horizontalRatingScale,
110
+ startRating,
111
+ gridBars
112
+ }
@@ -1,42 +1,25 @@
1
1
  import { NativeEventEmitter, NativeModules } from 'react-native';
2
- import type { IScenarioCallback, IWebSurveyModel } from '../models/models';
3
-
4
- export interface ISdkListener {
5
- onSurveyWebview(model: IWebSurveyModel): void;
6
- onScenarioLoad(model: IScenarioCallback): void;
7
- onScenarioError(model: IScenarioCallback): void;
8
- }
2
+ import { IScenarioCallback, ISurveyModel, IWebSurveyModel } from '../models/models';
9
3
 
10
4
  class Manager {
11
- private listener: ISdkListener | null = null;
12
5
  private sdkEmitter = NativeModules.SdkEmitter;
13
6
  private triggerManagerEmitter = new NativeEventEmitter(this.sdkEmitter);
14
7
 
15
- public constructor() {
16
- this.triggerManagerEmitter.addListener('__mobileOnWebSurveyStart', this.onWebSurveyStart);
17
- this.triggerManagerEmitter.addListener('__mobileOnScenarioLoad', this.onScenarioLoad);
18
- this.triggerManagerEmitter.addListener('__mobileOnScenarioError', this.onScenarioError);
8
+ public setOnWebSurveyStart(callback: (event: IWebSurveyModel) => void) {
9
+ return this.triggerManagerEmitter.addListener('__mobileOnWebSurveyStart', callback);
19
10
  }
20
11
 
21
- public setSdkListener(callbackListener: ISdkListener) {
22
- this.listener = callbackListener;
12
+ public setOnSurveyStart(callback: (event: ISurveyModel) => void) {
13
+ return this.triggerManagerEmitter.addListener('__mobileOnSurveyStart', callback);
23
14
  }
24
15
 
25
- public removeSdkListener() {
26
- this.listener = null;
16
+ public setOnScenarioLoad(callback: (event: IScenarioCallback) => void) {
17
+ return this.triggerManagerEmitter.addListener('__mobileOnScenarioLoad', callback);
27
18
  }
28
19
 
29
- private onWebSurveyStart = (event: IWebSurveyModel) => {
30
- this.listener?.onSurveyWebview(event);
31
- };
32
-
33
- private onScenarioLoad = (event: IScenarioCallback) => {
34
- this.listener?.onScenarioLoad(event);
35
- };
36
-
37
- private onScenarioError = (event: IScenarioCallback) => {
38
- this.listener?.onScenarioError(event);
39
- };
20
+ public setOnScenarioError(callback: (event: IScenarioCallback) => void) {
21
+ return this.triggerManagerEmitter.addListener('__mobileOnScenarioError', callback);
22
+ }
40
23
  }
41
24
 
42
25
  export const TriggerManager = new Manager();
@@ -0,0 +1,105 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import { IServerModel } from './models/models';
3
+
4
+ const LINKING_ERROR =
5
+ `The package 'react-native-mobilesdk' doesn't seem to be linked. Make sure: \n\n${Platform.select({
6
+ ios: "- You have run 'pod install'\n",
7
+ default: ''
8
+ })}- You rebuilt the app after installing the package\n` + '- You are not using Expo Go\n';
9
+
10
+ const MobileSdk = NativeModules.MobileSdk
11
+ ? NativeModules.MobileSdk
12
+ : new Proxy(
13
+ {},
14
+ {
15
+ get() {
16
+ throw new Error(LINKING_ERROR);
17
+ }
18
+ }
19
+ );
20
+
21
+ class Manager {
22
+ public async getUs(): Promise<IServerModel> {
23
+ return this.transformServer(await MobileSdk.getUs());
24
+ }
25
+
26
+ public async getUk(): Promise<IServerModel> {
27
+ return this.transformServer(await MobileSdk.getUk());
28
+ }
29
+
30
+ public async getAustralia(): Promise<IServerModel> {
31
+ return this.transformServer(await MobileSdk.getAustralia());
32
+ }
33
+
34
+ public async getCanada(): Promise<IServerModel> {
35
+ return this.transformServer(await MobileSdk.getCanada());
36
+ }
37
+
38
+ public async getGermany(): Promise<IServerModel> {
39
+ return this.transformServer(await MobileSdk.getGermany());
40
+ }
41
+
42
+ public async getHxPlatform(): Promise<IServerModel> {
43
+ return this.transformServer(await MobileSdk.getHxPlatform());
44
+ }
45
+
46
+ public async getHxAustralia(): Promise<IServerModel> {
47
+ return this.transformServer(await MobileSdk.getHxAustralia());
48
+ }
49
+
50
+ public async configureUs(clientId: string, clientSecret: string): Promise<void> {
51
+ return await MobileSdk.configureUs(clientId, clientSecret);
52
+ }
53
+
54
+ public async configureUk(clientId: string, clientSecret: string): Promise<void> {
55
+ return await MobileSdk.configureUk(clientId, clientSecret);
56
+ }
57
+
58
+ public async configureAustralia(clientId: string, clientSecret: string): Promise<void> {
59
+ return await MobileSdk.configureAustralia(clientId, clientSecret);
60
+ }
61
+
62
+ public async configureCanada(clientId: string, clientSecret: string): Promise<void> {
63
+ return await MobileSdk.configureCanada(clientId, clientSecret);
64
+ }
65
+
66
+ public async configureGermany(clientId: string, clientSecret: string): Promise<void> {
67
+ return await MobileSdk.configureGermany(clientId, clientSecret);
68
+ }
69
+
70
+ public async configureHxPlatform(clientId: string, clientSecret: string): Promise<void> {
71
+ return await MobileSdk.configureHxPlatform(clientId, clientSecret);
72
+ }
73
+
74
+ public async configureHxAustralia(clientId: string, clientSecret: string): Promise<void> {
75
+ return await MobileSdk.configureHxAustralia(clientId, clientSecret);
76
+ }
77
+
78
+ public async configureServer(name: string, host: string, clientId: string, clientSecret: string): Promise<IServerModel> {
79
+ return this.transformServer(await MobileSdk.configureServer(name, host, clientId, clientSecret));
80
+ }
81
+
82
+ public async getServer(serverId: string): Promise<IServerModel> {
83
+ return this.transformServer(await MobileSdk.getServer(serverId));
84
+ }
85
+
86
+ public async getServers(): Promise<IServerModel[]> {
87
+ const result = await MobileSdk.getServers();
88
+ const servers = [];
89
+ for (const server of result) {
90
+ servers.push(this.transformServer(server));
91
+ }
92
+
93
+ return servers;
94
+ }
95
+
96
+ private transformServer(result: any): IServerModel {
97
+ return {
98
+ host: result.host,
99
+ name: result.name,
100
+ serverId: result.serverId
101
+ };
102
+ }
103
+ }
104
+
105
+ export const ServerSdk = new Manager();
@@ -0,0 +1,97 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import { IDefaultQuestion, IPageControl, ISurveyFrameActionResult, QuestionAnswer } from 'react-native-mobilesdk';
3
+
4
+ const LINKING_ERROR =
5
+ `The package 'react-native-mobilesdk' doesn't seem to be linked. Make sure: \n\n${Platform.select({
6
+ ios: "- You have run 'pod install'\n",
7
+ default: ''
8
+ })}- You rebuilt the app after installing the package\n` + '- You are not using Expo Go\n';
9
+
10
+ const MobileSdkSurvey = NativeModules.MobileSdkSurvey
11
+ ? NativeModules.MobileSdkSurvey
12
+ : new Proxy(
13
+ {},
14
+ {
15
+ get() {
16
+ throw new Error(LINKING_ERROR);
17
+ }
18
+ }
19
+ );
20
+
21
+ export class PageControl {
22
+ public forwardText: string;
23
+ public backwardText: string;
24
+ public showForward: boolean;
25
+ public showBackward: boolean;
26
+ public okText: string;
27
+ public serverId: string;
28
+ public programKey: string;
29
+ public surveyId: string;
30
+
31
+ public constructor(page: IPageControl) {
32
+ this.forwardText = page.forwardText;
33
+ this.backwardText = page.backwardText;
34
+ this.showForward = page.showForward;
35
+ this.showBackward = page.showBackward;
36
+ this.okText = page.okText;
37
+ this.serverId = page.serverId;
38
+ this.programKey = page.programKey;
39
+ this.surveyId = page.surveyId;
40
+ }
41
+
42
+ public async getQuestion(): Promise<IDefaultQuestion[]> {
43
+ return await MobileSdkSurvey.getQuestions(this.serverId, this.programKey, this.surveyId);
44
+ }
45
+
46
+ public async getMulti(questionId: string): Promise<QuestionAnswer[]> {
47
+ return await MobileSdkSurvey.getMulti(this.serverId, this.programKey, this.surveyId, questionId);
48
+ }
49
+
50
+ public async setMulti(questionId: string, code: string, selected: boolean) {
51
+ return await MobileSdkSurvey.setMulti(this.serverId, this.programKey, this.surveyId, questionId, code, selected);
52
+ }
53
+
54
+ public async getSingle(questionId: string): Promise<QuestionAnswer> {
55
+ return await MobileSdkSurvey.getSingle(this.serverId, this.programKey, this.surveyId, questionId);
56
+ }
57
+
58
+ public async setSingle(questionId: string, code: string): Promise<void> {
59
+ return await MobileSdkSurvey.setSingle(this.serverId, this.programKey, this.surveyId, questionId, code);
60
+ }
61
+
62
+ public async getText(questionId: string): Promise<string> {
63
+ return await MobileSdkSurvey.getText(this.serverId, this.programKey, this.surveyId, questionId);
64
+ }
65
+
66
+ public async setText(questionId: string, value: string): Promise<void> {
67
+ return await MobileSdkSurvey.setText(this.serverId, this.programKey, this.surveyId, questionId, value);
68
+ }
69
+
70
+ public async getNumeric(questionId: string): Promise<string> {
71
+ return await MobileSdkSurvey.getNumeric(this.serverId, this.programKey, this.surveyId, questionId);
72
+ }
73
+
74
+ public async setNumeric(questionId: string, value: number, isDouble: boolean): Promise<void> {
75
+ return await MobileSdkSurvey.setNumeric(this.serverId, this.programKey, this.surveyId, questionId, value, isDouble);
76
+ }
77
+
78
+ public async next(): Promise<ISurveyFrameActionResult> {
79
+ return await MobileSdkSurvey.next(this.serverId, this.programKey, this.surveyId);
80
+ }
81
+
82
+ public async back(): Promise<ISurveyFrameActionResult> {
83
+ return await MobileSdkSurvey.back(this.serverId, this.programKey, this.surveyId);
84
+ }
85
+
86
+ public async quit(upload: boolean): Promise<ISurveyFrameActionResult> {
87
+ return await MobileSdkSurvey.quit(this.serverId, this.programKey, this.surveyId, upload);
88
+ }
89
+
90
+ public async title(): Promise<string> {
91
+ return await MobileSdkSurvey.getTitle(this.serverId, this.programKey, this.surveyId);
92
+ }
93
+
94
+ public async text(): Promise<string> {
95
+ return await MobileSdkSurvey.getText(this.serverId, this.programKey, this.surveyId);
96
+ }
97
+ }
@@ -0,0 +1,28 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ import { PageControl } from './pageControl';
3
+ import { IPageControl, ISurveyErrored, ISurveyFinished } from '../models/models';
4
+
5
+ class Manager {
6
+ private sdkEmitter = NativeModules.SdkEmitter;
7
+ private triggerManagerEmitter = new NativeEventEmitter(this.sdkEmitter);
8
+
9
+ public setOnSurveyPageReady(callback: (event: PageControl) => void) {
10
+ return this.triggerManagerEmitter.addListener('__mobileOnSurveyPageReady', (event: IPageControl) => {
11
+ callback(new PageControl(event));
12
+ });
13
+ }
14
+
15
+ public setOnSurveyErrored(callback: (event: ISurveyErrored) => void) {
16
+ return this.triggerManagerEmitter.addListener('__mobileOnSurveyErrored', callback);
17
+ }
18
+
19
+ public setOnSurveyFinished(callback: (event: ISurveyFinished) => void) {
20
+ return this.triggerManagerEmitter.addListener('__mobileOnSurveyFinished', callback);
21
+ }
22
+
23
+ public setOnSurveyQuit(callback: (values: { [key: string]: string }) => void) {
24
+ return this.triggerManagerEmitter.addListener('__mobileOnSurveyQuit', callback);
25
+ }
26
+ }
27
+
28
+ export const SurveyFrameManager = new Manager();
@@ -0,0 +1,32 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package 'react-native-mobilesdk' doesn't seem to be linked. Make sure: \n\n${Platform.select({
5
+ ios: "- You have run 'pod install'\n",
6
+ default: ''
7
+ })}- You rebuilt the app after installing the package\n` + '- You are not using Expo Go\n';
8
+
9
+ const MobileSdkSurvey = NativeModules.MobileSdkSurvey
10
+ ? NativeModules.MobileSdkSurvey
11
+ : new Proxy(
12
+ {},
13
+ {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ }
17
+ }
18
+ );
19
+
20
+ class Manager {
21
+ public async startSurvey(
22
+ serverId: string,
23
+ programKey: string,
24
+ surveyId: string,
25
+ data: { [Name: string]: string },
26
+ respondentValues: { [Name: string]: string }
27
+ ): Promise<void> {
28
+ return await MobileSdkSurvey.startSurvey(serverId, programKey, surveyId, data, respondentValues);
29
+ }
30
+ }
31
+
32
+ export const SurveySdk = new Manager();
@@ -0,0 +1,62 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package 'react-native-mobilesdk' doesn't seem to be linked. Make sure: \n\n${Platform.select({
5
+ ios: "- You have run 'pod install'\n",
6
+ default: ''
7
+ })}- You rebuilt the app after installing the package\n` + '- You are not using Expo Go\n';
8
+
9
+ const MobileSdk = NativeModules.MobileSdk
10
+ ? NativeModules.MobileSdk
11
+ : new Proxy(
12
+ {},
13
+ {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ }
17
+ }
18
+ );
19
+
20
+ class Manager {
21
+ public notifyEvent(event: string) {
22
+ MobileSdk.notifyEvent(event);
23
+ }
24
+
25
+ public notifyAppForeground(data: { [Name: string]: string }) {
26
+ MobileSdk.notifyAppForeground(data);
27
+ }
28
+
29
+ public async deleteProgram(serverId: string, programKey: string, deleteCustomData: boolean): Promise<void> {
30
+ return MobileSdk.deleteProgram(serverId, programKey, deleteCustomData);
31
+ }
32
+
33
+ public async deleteAll(deleteCustomData: boolean): Promise<void> {
34
+ return MobileSdk.deleteAll(deleteCustomData);
35
+ }
36
+
37
+ public setCallback(serverId: string, programKey: string) {
38
+ MobileSdk.setCallback(serverId, programKey);
39
+ }
40
+
41
+ public removeCallback(serverId: string, programKey: string) {
42
+ MobileSdk.removeCallback(serverId, programKey);
43
+ }
44
+
45
+ public async triggerDownload(serverId: string, programKey: string): Promise<boolean> {
46
+ return MobileSdk.triggerDownload(serverId, programKey);
47
+ }
48
+
49
+ public notifyEventWithData(event: string, data: { [Name: string]: string }) {
50
+ MobileSdk.notifyEventWithData(event, data);
51
+ }
52
+
53
+ public addJourneyLog(data: { [Name: string]: string }) {
54
+ MobileSdk.addJourneyLog(data);
55
+ }
56
+
57
+ public addJourneyLogWithServer(serverId: string, programKey: string, data: { [Name: string]: string }) {
58
+ MobileSdk.addJourneyLogWithServer(serverId, programKey, data);
59
+ }
60
+ }
61
+
62
+ export const TriggerSdk = new Manager();