freerasp-react-native 5.0.0 → 5.1.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 (47) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/android/src/main/java/com/freeraspreactnative/FreeraspReactNativeModule.kt +8 -4
  3. package/android/src/main/java/com/freeraspreactnative/events/RaspExecutionStateEvent.kt +3 -5
  4. package/android/src/main/java/com/freeraspreactnative/events/ThreatEvent.kt +23 -25
  5. package/freerasp-react-native.podspec +31 -8
  6. package/freerasp_spm.rb +88 -0
  7. package/ios/TalsecRuntime.xcframework/Info.plist +5 -5
  8. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeDirectory +0 -0
  9. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeResources +42 -42
  10. package/ios/TalsecRuntime.xcframework/_CodeSignature/CodeSignature +0 -0
  11. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/CurlWrapper.h +1 -1
  12. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/TalsecRuntime-Swift.h +1 -1
  13. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/curl.h +7 -7
  14. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/multi.h +4 -4
  15. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/options.h +1 -1
  16. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Headers/urlapi.h +1 -1
  17. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Info.plist +0 -0
  18. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios.abi.json +345 -289
  19. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/TalsecRuntime +0 -0
  20. package/ios/TalsecRuntime.xcframework/ios-arm64/TalsecRuntime.framework/_CodeSignature/CodeResources +15 -15
  21. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/CurlWrapper.h +1 -1
  22. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/TalsecRuntime-Swift.h +2 -2
  23. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/curl.h +7 -7
  24. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/multi.h +4 -4
  25. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/options.h +1 -1
  26. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Headers/urlapi.h +1 -1
  27. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Info.plist +0 -0
  28. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.abi.json +279 -223
  29. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.abi.json +279 -223
  30. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/TalsecRuntime +0 -0
  31. package/ios/TalsecRuntime.xcframework/ios-arm64_x86_64-simulator/TalsecRuntime.framework/_CodeSignature/CodeResources +17 -17
  32. package/ios/TalsecRuntimePackage/Package.swift +19 -0
  33. package/lib/typescript/plugin/src/index.d.ts.map +1 -1
  34. package/lib/typescript/plugin/src/iosSpm.d.ts +8 -0
  35. package/lib/typescript/plugin/src/iosSpm.d.ts.map +1 -0
  36. package/lib/typescript/plugin/src/iosSpmProperties.d.ts +3 -0
  37. package/lib/typescript/plugin/src/iosSpmProperties.d.ts.map +1 -0
  38. package/lib/typescript/plugin/src/pluginConfig.d.ts +8 -0
  39. package/lib/typescript/plugin/src/pluginConfig.d.ts.map +1 -1
  40. package/package.json +2 -1
  41. package/plugin/build/index.js +38 -0
  42. package/plugin/build/iosSpm.d.ts +7 -0
  43. package/plugin/build/iosSpm.js +136 -0
  44. package/plugin/build/iosSpmProperties.d.ts +2 -0
  45. package/plugin/build/iosSpmProperties.js +29 -0
  46. package/plugin/build/pluginConfig.d.ts +8 -0
  47. package/plugin/tests/iosSpm.test.js +126 -0
@@ -14,11 +14,11 @@
14
14
  </data>
15
15
  <key>Headers/CurlWrapper.h</key>
16
16
  <data>
17
- +/BZdehMbZTktyXpd1TfVf9L1TE=
17
+ 6wr8OlswVsoDXIHFSIehCZy5/WM=
18
18
  </data>
19
19
  <key>Headers/TalsecRuntime-Swift.h</key>
20
20
  <data>
21
- /hUoXGGTi7vIdiKBlqtxp5Iwz54=
21
+ iLkhsEJ2P6OlkRZ1d+X83uEJ4X8=
22
22
  </data>
23
23
  <key>Headers/TalsecRuntime_iOS.h</key>
24
24
  <data>
@@ -26,7 +26,7 @@
26
26
  </data>
27
27
  <key>Headers/curl.h</key>
28
28
  <data>
29
- LvMb8KdGM9H1BRrKId0CgKpQD/I=
29
+ E5TLp3MrkfYvnHGaoct5aqk31Xg=
30
30
  </data>
31
31
  <key>Headers/curlver.h</key>
32
32
  <data>
@@ -46,11 +46,11 @@
46
46
  </data>
47
47
  <key>Headers/multi.h</key>
48
48
  <data>
49
- WvSLoI6h5jIKte3k+mNbUFuFVpk=
49
+ Ko0/m1T8kTNXlbTId/pXZ17V+zE=
50
50
  </data>
51
51
  <key>Headers/options.h</key>
52
52
  <data>
53
- GOKMw3bGfxoMmsny/FkGY3putw8=
53
+ bOPQbHhmMX2ezd6hVM1bewAXYqI=
54
54
  </data>
55
55
  <key>Headers/stdcheaders.h</key>
56
56
  <data>
@@ -66,7 +66,7 @@
66
66
  </data>
67
67
  <key>Headers/urlapi.h</key>
68
68
  <data>
69
- VQyVIjrt8oYo9v0Xdb8pUFMMcK8=
69
+ M+v28sJU6k2ohJY/oATOk0aofn4=
70
70
  </data>
71
71
  <key>Headers/websockets.h</key>
72
72
  <data>
@@ -74,11 +74,11 @@
74
74
  </data>
75
75
  <key>Info.plist</key>
76
76
  <data>
77
- eL5oFlB6wq1n2HB8CtBm1T2ZgRw=
77
+ C+rwNOVjD82c5I+dOxAQYEwvvbo=
78
78
  </data>
79
79
  <key>Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.abi.json</key>
80
80
  <data>
81
- pMnu+U/rFxEOr6qt1QqIToB3V+k=
81
+ PNRmP/piKLXPtWcsYCm5VVyEJl4=
82
82
  </data>
83
83
  <key>Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface</key>
84
84
  <data>
@@ -94,7 +94,7 @@
94
94
  </data>
95
95
  <key>Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.abi.json</key>
96
96
  <data>
97
- pMnu+U/rFxEOr6qt1QqIToB3V+k=
97
+ PNRmP/piKLXPtWcsYCm5VVyEJl4=
98
98
  </data>
99
99
  <key>Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface</key>
100
100
  <data>
@@ -145,14 +145,14 @@
145
145
  <dict>
146
146
  <key>hash2</key>
147
147
  <data>
148
- wPSwe3k7PIhN59OveXzb7euBGLsZpNDCe3rxi3qSacY=
148
+ tlBvZyxaTPi2iagbzloWGrPV3lMqGmUyovqjfFkUx6Y=
149
149
  </data>
150
150
  </dict>
151
151
  <key>Headers/TalsecRuntime-Swift.h</key>
152
152
  <dict>
153
153
  <key>hash2</key>
154
154
  <data>
155
- adt8Xcyxs1KLY/8S2qf012ln9H6nElyeVP+HNFcjHM4=
155
+ tzA65yDQ40zTr0zocuTMsSS4H5XKSXIoFHJ+zTsfOck=
156
156
  </data>
157
157
  </dict>
158
158
  <key>Headers/TalsecRuntime_iOS.h</key>
@@ -166,7 +166,7 @@
166
166
  <dict>
167
167
  <key>hash2</key>
168
168
  <data>
169
- u/SMN3beuzx0i2dt5e+l0JuybPQnoQxyGFOidtmUiuI=
169
+ uejrZlHZuIC8IbWQaIb5AvjvsYayIJlMEsSoStadCFI=
170
170
  </data>
171
171
  </dict>
172
172
  <key>Headers/curlver.h</key>
@@ -201,14 +201,14 @@
201
201
  <dict>
202
202
  <key>hash2</key>
203
203
  <data>
204
- yk/hky4WUCrFatYr3HMyyCgfMOytFyCTbgN8q7cxxdc=
204
+ nEbDSnR0zS8NMh0xJhVf0mL2qJAYjPu745j1rWVzyDM=
205
205
  </data>
206
206
  </dict>
207
207
  <key>Headers/options.h</key>
208
208
  <dict>
209
209
  <key>hash2</key>
210
210
  <data>
211
- cJIaFXm+hGzgpoSmWUWKB06w1VdqPmWQvY70kcfbGBg=
211
+ A6nFG3FzyNnzrrGigO7cQ8Zqjk11eg6VD8256hBXfmA=
212
212
  </data>
213
213
  </dict>
214
214
  <key>Headers/stdcheaders.h</key>
@@ -236,7 +236,7 @@
236
236
  <dict>
237
237
  <key>hash2</key>
238
238
  <data>
239
- E7gKC6f/76z3wisiOh4O5LEK4UPtG8h7qY2QGjvOctE=
239
+ MyPHVGuak9RmTpd7eXMJSpPMMfYKG/MHOxeueefqLwk=
240
240
  </data>
241
241
  </dict>
242
242
  <key>Headers/websockets.h</key>
@@ -250,7 +250,7 @@
250
250
  <dict>
251
251
  <key>hash2</key>
252
252
  <data>
253
- M2tkP6t2EGgayYHcgC1xOjoiFwWwoBeyiI8jVBJ6ya0=
253
+ /hldVvxprpH5EL/sSmJhF8ltMvsmgCXzQ4U18KMS3uI=
254
254
  </data>
255
255
  </dict>
256
256
  <key>Modules/TalsecRuntime.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface</key>
@@ -278,7 +278,7 @@
278
278
  <dict>
279
279
  <key>hash2</key>
280
280
  <data>
281
- M2tkP6t2EGgayYHcgC1xOjoiFwWwoBeyiI8jVBJ6ya0=
281
+ /hldVvxprpH5EL/sSmJhF8ltMvsmgCXzQ4U18KMS3uI=
282
282
  </data>
283
283
  </dict>
284
284
  <key>Modules/TalsecRuntime.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface</key>
@@ -0,0 +1,19 @@
1
+ // swift-tools-version:5.9
2
+ import PackageDescription
3
+
4
+ let package = Package(
5
+ name: "TalsecRuntime",
6
+ platforms: [
7
+ .iOS(.v13),
8
+ ],
9
+ products: [
10
+ .library(name: "TalsecRuntime", targets: ["TalsecRuntime"]),
11
+ ],
12
+ targets: [
13
+ .binaryTarget(
14
+ name: "TalsecRuntime",
15
+ url: "https://storage.googleapis.com/talsec-artifact-repository/freerasp/ios/react-native/7.1.0/TalsecRuntime.xcframework.zip",
16
+ checksum: "35e62f290aca44e62519794334a1933011b1611dbb21ff2b7f083c97a88df006"
17
+ ),
18
+ ]
19
+ )
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../plugin/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;;AAmHvD,wBAA2E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../plugin/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;;AAiKvD,wBAA2E"}
@@ -0,0 +1,8 @@
1
+ export interface PodfileMutationResult {
2
+ contents: string;
3
+ changed: boolean;
4
+ missingAnchors: string[];
5
+ }
6
+ declare const mutatePodfileForFreeraspSpm: (contents: string, enabled?: boolean) => PodfileMutationResult;
7
+ export default mutatePodfileForFreeraspSpm;
8
+ //# sourceMappingURL=iosSpm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iosSpm.d.ts","sourceRoot":"","sources":["../../../../plugin/src/iosSpm.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AA2ED,QAAA,MAAM,2BAA2B,aACrB,MAAM,wBAEf,qBAsFF,CAAC;AAEF,eAAe,2BAA2B,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const configureIosSpmProperties: (properties: Record<string, string>, spmEnabled: boolean) => Record<string, string>;
2
+ export default configureIosSpmProperties;
3
+ //# sourceMappingURL=iosSpmProperties.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iosSpmProperties.d.ts","sourceRoot":"","sources":["../../../../plugin/src/iosSpmProperties.ts"],"names":[],"mappings":"AAKA,QAAA,MAAM,yBAAyB,eACjB,OAAO,MAAM,EAAE,MAAM,CAAC,cACtB,OAAO,KAClB,OAAO,MAAM,EAAE,MAAM,CAoBvB,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
@@ -2,12 +2,20 @@
2
2
  * Interface representing base build properties configuration.
3
3
  */
4
4
  export interface PluginConfigType {
5
+ ios?: PluginConfigTypeIos;
5
6
  /**
6
7
  * Interface representing available configuration for Android native build properties.
7
8
  * @platform android
8
9
  */
9
10
  android?: PluginConfigTypeAndroid;
10
11
  }
12
+ /** @platform ios */
13
+ export interface PluginConfigTypeIos {
14
+ /**
15
+ * Use Swift Package Manager to deliver TalsecRuntime. Defaults to `true`.
16
+ */
17
+ useSpm?: boolean;
18
+ }
11
19
  /**
12
20
  * Interface representing available configuration for Android native build properties.
13
21
  * @platform android
@@ -1 +1 @@
1
- {"version":3,"file":"pluginConfig.d.ts","sourceRoot":"","sources":["../../../../plugin/src/pluginConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC;;SAEK;IACL,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"pluginConfig.d.ts","sourceRoot":"","sources":["../../../../plugin/src/pluginConfig.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAE1B;;;OAGG;IACH,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACnC;AAED,oBAAoB;AACpB,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC;;SAEK;IACL,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freerasp-react-native",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "React Native plugin for improving app security and threat monitoring on Android and iOS mobile devices.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -14,6 +14,7 @@
14
14
  "prettier": "prettier \"**/*.{ts,js}\"",
15
15
  "prepack": "bob build && yarn build:plugin",
16
16
  "build": "bob build",
17
+ "test:plugin": "yarn build:plugin && node plugin/tests/iosSpm.test.js",
17
18
  "example": "yarn --cwd example",
18
19
  "bootstrap": "yarn example && yarn install && yarn example pods",
19
20
  "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build",
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const config_plugins_1 = require("@expo/config-plugins");
7
+ const fs_1 = require("fs");
8
+ const path_1 = require("path");
9
+ const iosSpm_1 = __importDefault(require("./iosSpm"));
10
+ const iosSpmProperties_1 = __importDefault(require("./iosSpmProperties"));
4
11
  const { createBuildGradlePropsConfigPlugin } = config_plugins_1.AndroidConfig.BuildProperties;
5
12
  const urlFreerasp = 'https://europe-west3-maven.pkg.dev/talsec-artifact-repository/freerasp';
6
13
  const urlJitpack = 'https://www.jitpack.io';
@@ -71,10 +78,41 @@ const withAndroidR8Version = (expoConfig, props) => {
71
78
  return config;
72
79
  });
73
80
  };
81
+ const withFreeraspIosFrameworks = (config, spmEnabled) => {
82
+ return (0, config_plugins_1.withPodfileProperties)(config, (cfg) => {
83
+ (0, iosSpmProperties_1.default)(cfg.modResults, spmEnabled);
84
+ return cfg;
85
+ });
86
+ };
87
+ const withFreeraspIosPodfile = (config, props) => {
88
+ return (0, config_plugins_1.withDangerousMod)(config, [
89
+ 'ios',
90
+ (cfg) => {
91
+ const podfilePath = (0, path_1.join)(cfg.modRequest.platformProjectRoot, 'Podfile');
92
+ const contents = (0, fs_1.readFileSync)(podfilePath, 'utf-8');
93
+ const result = (0, iosSpm_1.default)(contents, props?.spmEnabled ?? true);
94
+ if (result.missingAnchors.length > 0) {
95
+ config_plugins_1.WarningAggregator.addWarningIOS('freerasp-react-native', 'Could not configure TalsecRuntime delivery because the Podfile is missing: ' +
96
+ result.missingAnchors.join(', '));
97
+ }
98
+ else if (result.changed) {
99
+ (0, fs_1.writeFileSync)(podfilePath, result.contents);
100
+ }
101
+ return cfg;
102
+ },
103
+ ]);
104
+ };
105
+ const withRnTalsecIos = (config, props) => {
106
+ const spmEnabled = props?.ios?.useSpm !== false && process.env.FREERASP_USE_SPM !== '0';
107
+ config = withFreeraspIosFrameworks(config, spmEnabled);
108
+ config = withFreeraspIosPodfile(config, { spmEnabled });
109
+ return config;
110
+ };
74
111
  const withRnTalsecApp = (config, props) => {
75
112
  config = withBuildscriptDependency(config);
76
113
  config = withAndroidMinSdkVersion(config, props);
77
114
  config = withAndroidR8Version(config, props);
115
+ config = withRnTalsecIos(config, props);
78
116
  return config;
79
117
  };
80
118
  let pkg = {
@@ -0,0 +1,7 @@
1
+ export interface PodfileMutationResult {
2
+ contents: string;
3
+ changed: boolean;
4
+ missingAnchors: string[];
5
+ }
6
+ declare const mutatePodfileForFreeraspSpm: (contents: string, enabled?: boolean) => PodfileMutationResult;
7
+ export default mutatePodfileForFreeraspSpm;
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const FREERASP_SPM_ACTIVATION_TAG = '# @generated freerasp-react-native (SPM activation)';
4
+ const FREERASP_SPM_DISABLED_TAG = '# @generated freerasp-react-native (SPM disabled)';
5
+ const FREERASP_SPM_EMBED_TAG = '# @generated freerasp-react-native (SPM embed)';
6
+ const PREPARE_REACT_NATIVE_ANCHOR = 'prepare_react_native_project!';
7
+ const REACT_NATIVE_POST_INSTALL_ANCHOR = 'react_native_post_install(';
8
+ const indentationAt = (contents, index) => {
9
+ const lineStart = contents.lastIndexOf('\n', index - 1) + 1;
10
+ return contents.slice(lineStart, index).match(/^\s*/)?.[0] ?? '';
11
+ };
12
+ const removeManagedBlock = (contents, tag, bodyLineCount) => {
13
+ const newline = contents.includes('\r\n') ? '\r\n' : '\n';
14
+ const lines = contents.split(/\r?\n/);
15
+ const tagIndex = lines.findIndex((line) => line.trim() === tag);
16
+ if (tagIndex === -1) {
17
+ return contents;
18
+ }
19
+ let startIndex = tagIndex;
20
+ while (startIndex > 0 && lines[startIndex - 1]?.trim() === '') {
21
+ startIndex -= 1;
22
+ }
23
+ lines.splice(startIndex, tagIndex - startIndex + bodyLineCount + 1);
24
+ return lines.join(newline);
25
+ };
26
+ const findClosingParenthesis = (contents, openingIndex) => {
27
+ let depth = 0;
28
+ let quote;
29
+ let escaped = false;
30
+ let inComment = false;
31
+ for (let index = openingIndex; index < contents.length; index += 1) {
32
+ const character = contents[index];
33
+ if (inComment) {
34
+ if (character === '\n') {
35
+ inComment = false;
36
+ }
37
+ continue;
38
+ }
39
+ if (quote) {
40
+ if (escaped) {
41
+ escaped = false;
42
+ }
43
+ else if (character === '\\') {
44
+ escaped = true;
45
+ }
46
+ else if (character === quote) {
47
+ quote = undefined;
48
+ }
49
+ continue;
50
+ }
51
+ if (character === '#') {
52
+ inComment = true;
53
+ }
54
+ else if (character === "'" || character === '"') {
55
+ quote = character;
56
+ }
57
+ else if (character === '(') {
58
+ depth += 1;
59
+ }
60
+ else if (character === ')') {
61
+ depth -= 1;
62
+ if (depth === 0) {
63
+ return index;
64
+ }
65
+ }
66
+ }
67
+ return -1;
68
+ };
69
+ const mutatePodfileForFreeraspSpm = (contents, enabled = true) => {
70
+ let updatedContents = removeManagedBlock(contents, FREERASP_SPM_ACTIVATION_TAG, 1);
71
+ updatedContents = removeManagedBlock(updatedContents, FREERASP_SPM_DISABLED_TAG, 1);
72
+ updatedContents = removeManagedBlock(updatedContents, FREERASP_SPM_EMBED_TAG, 4);
73
+ const missingAnchors = [];
74
+ const prepareIndex = updatedContents.indexOf(PREPARE_REACT_NATIVE_ANCHOR);
75
+ const postInstallIndex = enabled
76
+ ? updatedContents.indexOf(REACT_NATIVE_POST_INSTALL_ANCHOR)
77
+ : -1;
78
+ const postInstallOpeningIndex = postInstallIndex === -1
79
+ ? -1
80
+ : postInstallIndex + REACT_NATIVE_POST_INSTALL_ANCHOR.length - 1;
81
+ const postInstallClosingIndex = postInstallOpeningIndex === -1
82
+ ? -1
83
+ : findClosingParenthesis(updatedContents, postInstallOpeningIndex);
84
+ if (prepareIndex === -1) {
85
+ missingAnchors.push(PREPARE_REACT_NATIVE_ANCHOR);
86
+ }
87
+ if (enabled && postInstallClosingIndex === -1) {
88
+ missingAnchors.push(REACT_NATIVE_POST_INSTALL_ANCHOR);
89
+ }
90
+ if (missingAnchors.length > 0) {
91
+ return { contents, changed: false, missingAnchors };
92
+ }
93
+ const newline = updatedContents.includes('\r\n') ? '\r\n' : '\n';
94
+ if (enabled) {
95
+ // Preserve the post-install index by inserting its snippet first.
96
+ const indent = indentationAt(updatedContents, postInstallIndex);
97
+ const snippet = [
98
+ '',
99
+ '',
100
+ `${indent}${FREERASP_SPM_EMBED_TAG}`,
101
+ `${indent}require Pod::Executable.execute_command('node', ['-p',`,
102
+ `${indent} 'require.resolve("freerasp-react-native/freerasp_spm.rb", {paths: [process.argv[1]]})',`,
103
+ `${indent} __dir__]).strip`,
104
+ `${indent}freerasp_embed_talsec_spm!(installer)`,
105
+ ].join(newline);
106
+ updatedContents =
107
+ updatedContents.slice(0, postInstallClosingIndex + 1) +
108
+ snippet +
109
+ updatedContents.slice(postInstallClosingIndex + 1);
110
+ }
111
+ const insertAt = prepareIndex + PREPARE_REACT_NATIVE_ANCHOR.length;
112
+ const indent = indentationAt(updatedContents, prepareIndex);
113
+ const configurationSnippet = enabled
114
+ ? [
115
+ '',
116
+ '',
117
+ `${indent}${FREERASP_SPM_ACTIVATION_TAG}`,
118
+ `${indent}ENV['FREERASP_USE_SPM'] = '1' unless ENV['FREERASP_USE_SPM'] == '0'`,
119
+ ]
120
+ : [
121
+ '',
122
+ '',
123
+ `${indent}${FREERASP_SPM_DISABLED_TAG}`,
124
+ `${indent}ENV['FREERASP_USE_SPM'] = '0'`,
125
+ ];
126
+ updatedContents =
127
+ updatedContents.slice(0, insertAt) +
128
+ configurationSnippet.join(newline) +
129
+ updatedContents.slice(insertAt);
130
+ return {
131
+ contents: updatedContents,
132
+ changed: updatedContents !== contents,
133
+ missingAnchors: [],
134
+ };
135
+ };
136
+ exports.default = mutatePodfileForFreeraspSpm;
@@ -0,0 +1,2 @@
1
+ declare const configureIosSpmProperties: (properties: Record<string, string>, spmEnabled: boolean) => Record<string, string>;
2
+ export default configureIosSpmProperties;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const FRAMEWORKS_PROPERTY = 'ios.useFrameworks';
4
+ const MANAGED_PROPERTY = 'freerasp.iosUseFrameworks';
5
+ const PREVIOUS_VALUE_PROPERTY = 'freerasp.previousIosUseFrameworks';
6
+ const UNSET_VALUE = '__freerasp_unset__';
7
+ const configureIosSpmProperties = (properties, spmEnabled) => {
8
+ if (spmEnabled) {
9
+ if (properties[MANAGED_PROPERTY] !== 'true') {
10
+ properties[PREVIOUS_VALUE_PROPERTY] =
11
+ properties[FRAMEWORKS_PROPERTY] ?? UNSET_VALUE;
12
+ }
13
+ properties[FRAMEWORKS_PROPERTY] = 'dynamic';
14
+ properties[MANAGED_PROPERTY] = 'true';
15
+ }
16
+ else if (properties[MANAGED_PROPERTY] === 'true') {
17
+ const previousValue = properties[PREVIOUS_VALUE_PROPERTY];
18
+ if (previousValue && previousValue !== UNSET_VALUE) {
19
+ properties[FRAMEWORKS_PROPERTY] = previousValue;
20
+ }
21
+ else {
22
+ delete properties[FRAMEWORKS_PROPERTY];
23
+ }
24
+ delete properties[MANAGED_PROPERTY];
25
+ delete properties[PREVIOUS_VALUE_PROPERTY];
26
+ }
27
+ return properties;
28
+ };
29
+ exports.default = configureIosSpmProperties;
@@ -2,12 +2,20 @@
2
2
  * Interface representing base build properties configuration.
3
3
  */
4
4
  export interface PluginConfigType {
5
+ ios?: PluginConfigTypeIos;
5
6
  /**
6
7
  * Interface representing available configuration for Android native build properties.
7
8
  * @platform android
8
9
  */
9
10
  android?: PluginConfigTypeAndroid;
10
11
  }
12
+ /** @platform ios */
13
+ export interface PluginConfigTypeIos {
14
+ /**
15
+ * Use Swift Package Manager to deliver TalsecRuntime. Defaults to `true`.
16
+ */
17
+ useSpm?: boolean;
18
+ }
11
19
  /**
12
20
  * Interface representing available configuration for Android native build properties.
13
21
  * @platform android
@@ -0,0 +1,126 @@
1
+ /* eslint-env node */
2
+
3
+ const assert = require('assert').strict;
4
+ const mutatePodfileForFreeraspSpm = require('../build/iosSpm').default;
5
+ const configureIosSpmProperties = require('../build/iosSpmProperties').default;
6
+
7
+ const FREERASP_SPM_ACTIVATION_TAG =
8
+ '# @generated freerasp-react-native (SPM activation)';
9
+ const FREERASP_SPM_DISABLED_TAG =
10
+ '# @generated freerasp-react-native (SPM disabled)';
11
+ const FREERASP_SPM_EMBED_TAG = '# @generated freerasp-react-native (SPM embed)';
12
+
13
+ const podfile = `prepare_react_native_project!
14
+
15
+ target 'Example' do
16
+ post_install do |installer|
17
+ react_native_post_install(
18
+ installer,
19
+ config[:reactNativePath],
20
+ :mac_catalyst_enabled => nested_option(enabled: false),
21
+ :quoted_value => "parentheses do not count: ())"
22
+ )
23
+ end
24
+ end
25
+ `;
26
+
27
+ const mutation = mutatePodfileForFreeraspSpm(podfile);
28
+ assert.equal(mutation.changed, true);
29
+ assert.deepEqual(mutation.missingAnchors, []);
30
+
31
+ const activationIndex = mutation.contents.indexOf(FREERASP_SPM_ACTIVATION_TAG);
32
+ const targetIndex = mutation.contents.indexOf("target 'Example'");
33
+ assert(
34
+ activationIndex > mutation.contents.indexOf('prepare_react_native_project!')
35
+ );
36
+ assert(activationIndex < targetIndex);
37
+ assert(
38
+ mutation.contents.includes(
39
+ "ENV['FREERASP_USE_SPM'] = '1' unless ENV['FREERASP_USE_SPM'] == '0'"
40
+ )
41
+ );
42
+
43
+ const postInstallCloseIndex = mutation.contents.indexOf('\n )');
44
+ const embedIndex = mutation.contents.indexOf(FREERASP_SPM_EMBED_TAG);
45
+ const postInstallEndIndex = mutation.contents.indexOf('\n end', embedIndex);
46
+ assert(embedIndex > postInstallCloseIndex);
47
+ assert(embedIndex < postInstallEndIndex);
48
+
49
+ const secondMutation = mutatePodfileForFreeraspSpm(mutation.contents);
50
+ assert.equal(secondMutation.changed, false);
51
+ assert.equal(secondMutation.contents, mutation.contents);
52
+
53
+ const disabledMutation = mutatePodfileForFreeraspSpm(mutation.contents, false);
54
+ assert.equal(disabledMutation.changed, true);
55
+ assert(disabledMutation.contents.includes(FREERASP_SPM_DISABLED_TAG));
56
+ assert(disabledMutation.contents.includes("ENV['FREERASP_USE_SPM'] = '0'"));
57
+ assert.equal(
58
+ disabledMutation.contents.includes(FREERASP_SPM_ACTIVATION_TAG),
59
+ false
60
+ );
61
+ assert.equal(disabledMutation.contents.includes(FREERASP_SPM_EMBED_TAG), false);
62
+
63
+ const secondDisabledMutation = mutatePodfileForFreeraspSpm(
64
+ disabledMutation.contents,
65
+ false
66
+ );
67
+ assert.equal(secondDisabledMutation.changed, false);
68
+ assert.equal(secondDisabledMutation.contents, disabledMutation.contents);
69
+
70
+ const reenabledMutation = mutatePodfileForFreeraspSpm(
71
+ disabledMutation.contents,
72
+ true
73
+ );
74
+ assert.equal(reenabledMutation.changed, true);
75
+ assert(reenabledMutation.contents.includes(FREERASP_SPM_ACTIVATION_TAG));
76
+ assert(reenabledMutation.contents.includes(FREERASP_SPM_EMBED_TAG));
77
+ assert.equal(
78
+ reenabledMutation.contents.includes(FREERASP_SPM_DISABLED_TAG),
79
+ false
80
+ );
81
+
82
+ const missingAnchors = mutatePodfileForFreeraspSpm(
83
+ 'target "Example" do\nend\n'
84
+ );
85
+ assert.equal(missingAnchors.changed, false);
86
+ assert.equal(missingAnchors.contents, 'target "Example" do\nend\n');
87
+ assert.deepEqual(missingAnchors.missingAnchors, [
88
+ 'prepare_react_native_project!',
89
+ 'react_native_post_install(',
90
+ ]);
91
+
92
+ const windowsMutation = mutatePodfileForFreeraspSpm(
93
+ podfile.replace(/\n/g, '\r\n')
94
+ );
95
+ assert.equal(windowsMutation.changed, true);
96
+ assert.equal(
97
+ windowsMutation.contents.replace(/\r\n/g, '').includes('\n'),
98
+ false
99
+ );
100
+
101
+ const propertiesWithoutFrameworks = {};
102
+ configureIosSpmProperties(propertiesWithoutFrameworks, true);
103
+ assert.equal(propertiesWithoutFrameworks['ios.useFrameworks'], 'dynamic');
104
+ configureIosSpmProperties(propertiesWithoutFrameworks, false);
105
+ assert.deepEqual(propertiesWithoutFrameworks, {});
106
+
107
+ const propertiesWithStaticFrameworks = {
108
+ 'ios.useFrameworks': 'static',
109
+ };
110
+ configureIosSpmProperties(propertiesWithStaticFrameworks, true);
111
+ configureIosSpmProperties(propertiesWithStaticFrameworks, true);
112
+ assert.equal(propertiesWithStaticFrameworks['ios.useFrameworks'], 'dynamic');
113
+ configureIosSpmProperties(propertiesWithStaticFrameworks, false);
114
+ assert.deepEqual(propertiesWithStaticFrameworks, {
115
+ 'ios.useFrameworks': 'static',
116
+ });
117
+
118
+ const unownedProperties = {
119
+ 'ios.useFrameworks': 'dynamic',
120
+ };
121
+ configureIosSpmProperties(unownedProperties, false);
122
+ assert.deepEqual(unownedProperties, {
123
+ 'ios.useFrameworks': 'dynamic',
124
+ });
125
+
126
+ console.log('Expo iOS SPM tests passed.');