@@ -2,7 +2,7 @@ import Foundation
22
33internal enum FormbricksEnvironment {
44
5- /// Only `appUrl` is user-supplied. Crash early if it’ s missing.
5+ /// Only `appUrl` is user-supplied. Crash early if it' s missing.
66 fileprivate static var baseApiUrl : String {
77 guard let url = Formbricks . appUrl else {
88 fatalError ( " Formbricks.setup must be called before using the SDK. " )
@@ -12,21 +12,22 @@ internal enum FormbricksEnvironment {
1212
1313 /// Returns the full survey‐script URL as a String
1414 static var surveyScriptUrlString : String {
15- let path = " / " + [ " js " , " surveys.umd.cjs " ] . joined ( separator: " / " ) // NOSONAR we can hard-code "/" here
16- return baseApiUrl + path
15+ guard let baseURL = URL ( string: baseApiUrl) else {
16+ fatalError ( " Invalid base URL: \( baseApiUrl) " )
17+ }
18+
19+ // Append path components properly using URL
20+ let surveyScriptURL = baseURL. appendingPathComponent ( " js " ) . appendingPathComponent ( " surveys.umd.cjs " )
21+ return surveyScriptURL. absoluteString
1722 }
1823
1924 /// Returns the full environment‐fetch URL as a String for the given ID
20- static var getEnvironmentRequestEndpoint : String {
21- let path = " / " + [ " api " , " v2 " , " client " , " {environmentId} " , " environment " ] // NOSONAR we can hard-code "/" here
22- . joined ( separator: " / " )
23- return path
25+ static var getEnvironmentRequestEndpoint : String {
26+ return [ " api " , " v2 " , " client " , " {environmentId} " , " environment " ] . joined ( separator: " / " )
2427 }
2528
2629 /// Returns the full post-user URL as a String for the given ID
27- static var postUserRequestEndpoint : String {
28- let path = " / " + [ " api " , " v2 " , " client " , " {environmentId} " , " user " ] // NOSONAR we can hard-code "/" here
29- . joined ( separator: " / " )
30- return path
30+ static var postUserRequestEndpoint : String {
31+ return [ " api " , " v2 " , " client " , " {environmentId} " , " user " ] . joined ( separator: " / " )
3132 }
3233}
0 commit comments