react-native-spike-sdk 4.3.63 → 4.3.73-beta.1

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/app.plugin.js CHANGED
@@ -1,21 +1,29 @@
1
1
  const {
2
2
  withEntitlementsPlist,
3
3
  withInfoPlist,
4
+ withProjectBuildGradle,
5
+ withAndroidManifest,
4
6
  } = require('@expo/config-plugins');
5
7
 
6
- const HEALTH_SHARE = 'Allow $(PRODUCT_NAME) to check health info';
7
- const HEALTH_UPDATE = 'Allow $(PRODUCT_NAME) to update health info';
8
- const HEALTH_CLINIC_SHARE =
9
- 'Allow $(PRODUCT_NAME) to check health clinical info';
8
+ // Default permission descriptions - these are used as fallbacks if no custom descriptions are provided
9
+ const DEFAULT_HEALTH_SHARE_DESCRIPTION = 'Allow $(PRODUCT_NAME) to check health info';
10
+ const DEFAULT_HEALTH_UPDATE_DESCRIPTION = 'Allow $(PRODUCT_NAME) to update health info';
10
11
 
12
+ /**
13
+ * Configures HealthKit permissions and entitlements for iOS
14
+ * @param {Object} config - Expo config object
15
+ * @param {Object} options - Configuration options
16
+ * @param {string} [options.healthSharePermission] - Custom description for health share permission (NSHealthShareUsageDescription)
17
+ * @param {string} [options.healthUpdatePermission] - Custom description for health update permission (NSHealthUpdateUsageDescription)
18
+ * @param {boolean} [options.isBackgroundDeliveryEnabled=true] - Whether to enable background health data deliveries (defaults to true)
19
+ * @returns {Object} Modified config object
20
+ */
11
21
  const withSpikeHealthKit = (
12
22
  config,
13
23
  {
14
24
  healthSharePermission,
15
25
  healthUpdatePermission,
16
- isClinicalDataEnabled,
17
- healthClinicalDescription,
18
- isBackgroundDeliveriesEnabled,
26
+ isBackgroundDeliveryEnabled = true,
19
27
  } = {}
20
28
  ) => {
21
29
  // Add permissions
@@ -23,18 +31,11 @@ const withSpikeHealthKit = (
23
31
  config.modResults.NSHealthShareUsageDescription =
24
32
  healthSharePermission ||
25
33
  config.modResults.NSHealthShareUsageDescription ||
26
- HEALTH_SHARE;
34
+ DEFAULT_HEALTH_SHARE_DESCRIPTION;
27
35
  config.modResults.NSHealthUpdateUsageDescription =
28
36
  healthUpdatePermission ||
29
37
  config.modResults.NSHealthUpdateUsageDescription ||
30
- HEALTH_UPDATE;
31
- isClinicalDataEnabled
32
- ? (config.modResults.NSHealthClinicalHealthRecordsShareUsageDescription =
33
- healthClinicalDescription ||
34
- config.modResults
35
- .NSHealthClinicalHealthRecordsShareUsageDescription ||
36
- HEALTH_CLINIC_SHARE)
37
- : null;
38
+ DEFAULT_HEALTH_UPDATE_DESCRIPTION;
38
39
 
39
40
  return config;
40
41
  });
@@ -48,18 +49,7 @@ const withSpikeHealthKit = (
48
49
  config.modResults['com.apple.developer.healthkit.access'] = [];
49
50
  }
50
51
 
51
- if (isClinicalDataEnabled != false) {
52
- config.modResults['com.apple.developer.healthkit.access'].push(
53
- 'health-records'
54
- );
55
-
56
- // Remove duplicates
57
- config.modResults['com.apple.developer.healthkit.access'] = [
58
- ...new Set(config.modResults['com.apple.developer.healthkit.access']),
59
- ];
60
- }
61
-
62
- if (isBackgroundDeliveriesEnabled) {
52
+ if (isBackgroundDeliveryEnabled) {
63
53
  config.modResults[
64
54
  'com.apple.developer.healthkit.background-delivery'
65
55
  ] = true;
@@ -70,4 +60,254 @@ const withSpikeHealthKit = (
70
60
 
71
61
  return config;
72
62
  };
73
- module.exports = withSpikeHealthKit;
63
+
64
+ /**
65
+ * Configures Android-specific settings for the Spike SDK
66
+ * @param {Object} config - Expo config object
67
+ * @param {Object} options - Configuration options
68
+ * @param {boolean} [options.isBackgroundDeliveryEnabled=true] - Whether to enable background health data deliveries
69
+ * @param {string[]} [options.healthConnectPermissions=[]] - Array of Health Connect Android permissions to add to the manifest
70
+ * @returns {Object} Modified config object
71
+ */
72
+ const withSpikeAndroid = (config, { isBackgroundDeliveryEnabled = true, healthConnectPermissions = [] } = {}) => {
73
+ // Add Maven repository to allprojects repositories
74
+ config = withProjectBuildGradle(config, (config) => {
75
+ const mavenUrl = 'https://gitlab.com/api/v4/projects/43396247/packages/maven';
76
+ // Find the allprojects block
77
+ const allprojectsRegex = /allprojects\s*\{[\s\S]*?repositories\s*\{([\s\S]*?)\}/;
78
+ const match = config.modResults.contents.match(allprojectsRegex);
79
+ if (match) {
80
+ // Check if the maven repository is already in the repositories block
81
+ if (!match[1].includes(`url '${mavenUrl}'`)) {
82
+ // Add the maven repository to the repositories block
83
+ const updatedContents = config.modResults.contents.replace(
84
+ allprojectsRegex,
85
+ (allBlock) =>
86
+ allBlock.replace(
87
+ /repositories\s*\{/,
88
+ `repositories {\n maven {\n url '${mavenUrl}'\n }`
89
+ )
90
+ );
91
+ config.modResults.contents = updatedContents;
92
+ }
93
+ } else {
94
+ // No allprojects block found, add it at the end of the file
95
+ if (!config.modResults.contents.includes(`url '${mavenUrl}'`)) {
96
+ const insertPosition = config.modResults.contents.lastIndexOf('}');
97
+ if (insertPosition !== -1) {
98
+ const beforeInsert = config.modResults.contents.substring(0, insertPosition);
99
+ const afterInsert = config.modResults.contents.substring(insertPosition);
100
+ config.modResults.contents = `${beforeInsert}\n\nallprojects {\n repositories {\n maven {\n url '${mavenUrl}'\n }\n }\n}${afterInsert}`;
101
+ }
102
+ }
103
+ }
104
+ return config;
105
+ });
106
+
107
+ // Set minSdkVersion to 28 if it's less than 28 or not set
108
+ config = withProjectBuildGradle(config, (config) => {
109
+ // Find the buildscript.ext block and update minSdkVersion
110
+ const buildscriptExtRegex = /buildscript\s*\{\s*ext\s*\{([\s\S]*?)\}/;
111
+ const match = config.modResults.contents.match(buildscriptExtRegex);
112
+
113
+ if (match) {
114
+ const extBlock = match[1];
115
+ const minSdkRegex = /minSdkVersion\s*=\s*(\d+)/;
116
+ const minSdkMatch = extBlock.match(minSdkRegex);
117
+
118
+ if (minSdkMatch) {
119
+ const currentMinSdk = parseInt(minSdkMatch[1], 10);
120
+ if (currentMinSdk < 28) {
121
+ // Replace the existing minSdkVersion
122
+ config.modResults.contents = config.modResults.contents.replace(
123
+ minSdkRegex,
124
+ 'minSdkVersion = 28'
125
+ );
126
+ }
127
+ } else {
128
+ // No minSdkVersion found, add it to the ext block
129
+ config.modResults.contents = config.modResults.contents.replace(
130
+ buildscriptExtRegex,
131
+ (fullMatch, extBlock) => {
132
+ // Find the closing brace of the ext block
133
+ const lines = extBlock.split('\n');
134
+ const lastLineIndex = lines.length - 1;
135
+ const lastLine = lines[lastLineIndex];
136
+
137
+ // Add minSdkVersion before the closing brace
138
+ lines.splice(lastLineIndex, 0, ' minSdkVersion = 28');
139
+
140
+ return `buildscript {\n ext {\n${lines.join('\n')}\n }`;
141
+ }
142
+ );
143
+ }
144
+ } else {
145
+ // No buildscript.ext block found, add it
146
+ const buildscriptRegex = /buildscript\s*\{/;
147
+ const buildscriptMatch = config.modResults.contents.match(buildscriptRegex);
148
+
149
+ if (buildscriptMatch) {
150
+ // Insert ext block after the opening buildscript brace
151
+ config.modResults.contents = config.modResults.contents.replace(
152
+ buildscriptRegex,
153
+ 'buildscript {\n ext {\n minSdkVersion = 28\n }'
154
+ );
155
+ }
156
+ }
157
+
158
+ return config;
159
+ });
160
+
161
+ // Add tools replacement attributes to the AndroidManifest.xml file
162
+ config = withCustomAndroidManifest(config, { isBackgroundDeliveryEnabled, healthConnectPermissions });
163
+
164
+ return config;
165
+ };
166
+
167
+ /**
168
+ * Configures Android manifest with Spike SDK specific settings
169
+ * @param {Object} config - Expo config object
170
+ * @param {Object} options - Configuration options
171
+ * @param {boolean} [options.isBackgroundDeliveryEnabled=true] - Whether to enable background health data deliveries
172
+ * @param {string[]} [options.healthConnectPermissions=[]] - Array of Health Connect Android permissions to add to the manifest
173
+ * @returns {Object} Modified config object
174
+ */
175
+ function withCustomAndroidManifest(config, { isBackgroundDeliveryEnabled = true, healthConnectPermissions = [] } = {}) {
176
+ return withAndroidManifest(config, async (config) => {
177
+ const androidManifest = config.modResults;
178
+ const manifest = androidManifest.manifest;
179
+
180
+ // Ensure xmlns:tools is present in the <manifest> tag
181
+ if (!manifest.$['xmlns:tools']) {
182
+ manifest.$['xmlns:tools'] = 'http://schemas.android.com/tools';
183
+ }
184
+
185
+ // Add background health data permission to healthConnectPermissions when background delivery is enabled
186
+ if (isBackgroundDeliveryEnabled) {
187
+ const backgroundPermission = 'android.permission.health.READ_HEALTH_DATA_IN_BACKGROUND';
188
+ if (!healthConnectPermissions.includes(backgroundPermission)) {
189
+ healthConnectPermissions = [backgroundPermission, ...healthConnectPermissions];
190
+ }
191
+ }
192
+
193
+ // Add health connect permissions if provided
194
+ if (healthConnectPermissions && healthConnectPermissions.length > 0) {
195
+ if (!manifest['uses-permission']) {
196
+ manifest['uses-permission'] = [];
197
+ }
198
+ for (const permission of healthConnectPermissions) {
199
+ if (!manifest['uses-permission'].some(p => p['$'] && p['$']['android:name'] === permission)) {
200
+ manifest['uses-permission'].push({
201
+ $: {
202
+ 'android:name': permission
203
+ }
204
+ });
205
+ }
206
+ }
207
+ }
208
+
209
+ const application = manifest.application[0];
210
+
211
+ // Add tools:replace attribute for dataExtractionRules and fullBackupContent
212
+ application['$']['tools:replace'] = 'android:dataExtractionRules, android:fullBackupContent';
213
+
214
+ // Set dataExtractionRules and fullBackupContent as attributes within <application>
215
+ application['$']['android:dataExtractionRules'] = '@xml/secure_store_data_extraction_rules';
216
+ application['$']['android:fullBackupContent'] = '@xml/secure_store_backup_rules';
217
+
218
+ // Find the main activity and add the intent filter for permissions rationale
219
+ if (application.activity) {
220
+ for (const activity of application.activity) {
221
+ if (activity['$'] && activity['$']['android:name'] &&
222
+ activity['$']['android:name'].endsWith('.MainActivity')) {
223
+
224
+ // Initialize intent-filter array if it doesn't exist
225
+ if (!activity['intent-filter']) {
226
+ activity['intent-filter'] = [];
227
+ }
228
+
229
+ // Check if the permissions rationale intent filter already exists
230
+ const hasPermissionsRationale = activity['intent-filter'].some(filter =>
231
+ filter.action && filter.action.some(action =>
232
+ action['$']['android:name'] === 'androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE'
233
+ )
234
+ );
235
+
236
+ if (!hasPermissionsRationale) {
237
+ activity['intent-filter'].push({
238
+ action: [{
239
+ $: {
240
+ 'android:name': 'androidx.health.ACTION_SHOW_PERMISSIONS_RATIONALE'
241
+ }
242
+ }]
243
+ });
244
+ }
245
+ break;
246
+ }
247
+ }
248
+ }
249
+
250
+ // Add activity-alias for ViewPermissionUsageActivity
251
+ if (!application['activity-alias']) {
252
+ application['activity-alias'] = [];
253
+ }
254
+
255
+ // Check if the activity-alias already exists
256
+ const hasViewPermissionUsageActivity = application['activity-alias'].some(alias =>
257
+ alias['$'] && alias['$']['android:name'] === 'ViewPermissionUsageActivity'
258
+ );
259
+
260
+ if (!hasViewPermissionUsageActivity) {
261
+ application['activity-alias'].push({
262
+ $: {
263
+ 'android:name': 'ViewPermissionUsageActivity',
264
+ 'android:exported': 'true',
265
+ 'android:targetActivity': '.MainActivity',
266
+ 'android:permission': 'android.permission.START_VIEW_PERMISSION_USAGE'
267
+ },
268
+ 'intent-filter': [{
269
+ action: [{
270
+ $: {
271
+ 'android:name': 'android.intent.action.VIEW_PERMISSION_USAGE'
272
+ }
273
+ }],
274
+ category: [{
275
+ $: {
276
+ 'android:name': 'android.intent.category.HEALTH_PERMISSIONS'
277
+ }
278
+ }]
279
+ }]
280
+ });
281
+ }
282
+
283
+ return config;
284
+ });
285
+ };
286
+
287
+ /**
288
+ * Main plugin function that configures the Spike SDK for both iOS and Android
289
+ * @param {Object} config - Expo config object
290
+ * @param {Object} props - Configuration properties
291
+ * @param {Object} [props.ios] - iOS-specific configuration
292
+ * @param {string} [props.ios.healthSharePermission] - Custom description for health share permission (NSHealthShareUsageDescription)
293
+ * @param {string} [props.ios.healthUpdatePermission] - Custom description for health update permission (NSHealthUpdateUsageDescription)
294
+ * @param {boolean} [props.ios.isBackgroundDeliveryEnabled=true] - Whether to enable background health data deliveries (defaults to true)
295
+ * @param {Object} [props.android] - Android-specific configuration
296
+ * @param {boolean} [props.android.isBackgroundDeliveryEnabled=true] - Whether to enable background health data deliveries (defaults to true)
297
+ * @param {string[]} [props.android.healthConnectPermissions=[]] - Array of Health Connect Android permissions to add to the manifest
298
+ * @returns {Object} Modified config object
299
+ *
300
+ */
301
+ const withSpikeSdk = (config, props = {}) => {
302
+ const { ios = {}, android = {} } = props;
303
+
304
+ // Apply iOS configuration
305
+ config = withSpikeHealthKit(config, ios);
306
+
307
+ // Apply Android configuration
308
+ config = withSpikeAndroid(config, android);
309
+
310
+ return config;
311
+ };
312
+
313
+ module.exports = withSpikeSdk;
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.SPIKE_SDK_VERSION = void 0;
7
7
  // This file is auto-generated. Do not edit manually.
8
- const SPIKE_SDK_VERSION = exports.SPIKE_SDK_VERSION = "4.3.63";
8
+ const SPIKE_SDK_VERSION = exports.SPIKE_SDK_VERSION = "4.3.73-beta.1";
9
9
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["SPIKE_SDK_VERSION","exports"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;;;;;AAAA;AACO,MAAMA,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,QAAQ","ignoreList":[]}
1
+ {"version":3,"names":["SPIKE_SDK_VERSION","exports"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;;;;;AAAA;AACO,MAAMA,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG,eAAe","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
 
3
3
  // This file is auto-generated. Do not edit manually.
4
- export const SPIKE_SDK_VERSION = "4.3.63";
4
+ export const SPIKE_SDK_VERSION = "4.3.73-beta.1";
5
5
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["SPIKE_SDK_VERSION"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;AAAA;AACA,OAAO,MAAMA,iBAAiB,GAAG,QAAQ","ignoreList":[]}
1
+ {"version":3,"names":["SPIKE_SDK_VERSION"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;AAAA;AACA,OAAO,MAAMA,iBAAiB,GAAG,eAAe","ignoreList":[]}
@@ -1,2 +1,2 @@
1
- export declare const SPIKE_SDK_VERSION = "4.3.63";
1
+ export declare const SPIKE_SDK_VERSION = "4.3.73-beta.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,iBAAiB,WAAW,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,iBAAiB,kBAAkB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-spike-sdk",
3
- "version": "4.3.63",
3
+ "version": "4.3.73-beta.1",
4
4
  "iosVersion": "4.3.41",
5
5
  "description": "Spike API for health and productivity data from wearables and IoT devices",
6
6
  "main": "lib/commonjs/index",
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is auto-generated. Do not edit manually.
2
- export const SPIKE_SDK_VERSION = "4.3.63";
2
+ export const SPIKE_SDK_VERSION = "4.3.73-beta.1";
3
3