@capgo/capacitor-social-login 8.4.0 → 8.4.2

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 CHANGED
@@ -115,7 +115,7 @@ export default config;
115
115
  - This configuration only affects iOS and Android platforms; it does not affect the web platform.
116
116
  - **Important**: Using `false` means the dependency won't be bundled, but the plugin code still compiles against it. Ensure the consuming app includes the dependency if needed.
117
117
  - **Facebook**: When `facebook: false`, the Facebook SDK is omitted and the plugin compiles a provider stub in its own package — no `com.facebook.*` classes are shipped (avoids privacy-scanner false positives).
118
- - **Apple (iOS)**: Basic Sign in with Apple always works via AuthenticationServices (no external SDK). Alamofire is only required when using `redirectUrl` / backend token exchange. CocoaPods toggles Alamofire via `apple: true|false`; SPM always resolves Alamofire from `Package.swift` when the plugin is linked.
118
+ - **Apple (iOS)**: `apple: true` enables Sign in with Apple (AuthenticationServices; no external SDK for basic login). Alamofire is only linked when using `redirectUrl` / backend token exchange. `apple: false` removes Alamofire and disables Apple authentication at runtime—including basic Sign in with Apple—consistent with the rule above that `false` providers are unavailable at runtime. CocoaPods and Swift Package Manager both toggle Alamofire based on `apple: true|false`.
119
119
  - Apple Sign-In on Android uses OAuth flow without external SDK dependencies
120
120
  - Twitter uses standard OAuth 2.0 flow without external SDK dependencies
121
121
 
@@ -124,6 +124,7 @@ dependencies {
124
124
 
125
125
  // Test dependencies (always included)
126
126
  testImplementation "junit:junit:$junitVersion"
127
+ testImplementation "org.json:json:20240303"
127
128
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
128
129
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
129
130
  }
@@ -24,7 +24,7 @@ import org.json.JSONObject;
24
24
  @CapacitorPlugin(name = "SocialLogin")
25
25
  public class SocialLoginPlugin extends Plugin {
26
26
 
27
- private final String pluginVersion = "8.4.0";
27
+ private final String pluginVersion = "8.4.2";
28
28
 
29
29
  public static String LOG_TAG = "CapgoSocialLogin";
30
30
  public HashMap<String, SocialProvider> socialProviderHashMap = new HashMap<>();
@@ -532,9 +532,22 @@ public class SocialLoginPlugin extends Plugin {
532
532
  }
533
533
  }
534
534
 
535
+ // Capacitor's PluginCall.getLong() only reads Java Long values. JS numbers that
536
+ // fit in 32 bits cross the bridge as Integer, so Number coercion is required.
537
+ static Long longOptionFromCall(PluginCall call, String key) {
538
+ if (!call.getData().has(key)) {
539
+ return null;
540
+ }
541
+ Object value = call.getData().opt(key);
542
+ if (value == null || !(value instanceof Number)) {
543
+ return null;
544
+ }
545
+ return ((Number) value).longValue();
546
+ }
547
+
535
548
  @PluginMethod
536
549
  public void getAccessTokenExpirationDate(final PluginCall call) {
537
- Long expiresAt = call.getLong("accessTokenExpirationDate");
550
+ Long expiresAt = longOptionFromCall(call, "accessTokenExpirationDate");
538
551
  if (expiresAt == null) {
539
552
  call.reject("accessTokenExpirationDate is required");
540
553
  return;
@@ -552,7 +565,7 @@ public class SocialLoginPlugin extends Plugin {
552
565
 
553
566
  @PluginMethod
554
567
  public void isAccessTokenExpired(final PluginCall call) {
555
- Long expiresAt = call.getLong("accessTokenExpirationDate");
568
+ Long expiresAt = longOptionFromCall(call, "accessTokenExpirationDate");
556
569
  if (expiresAt == null) {
557
570
  call.reject("accessTokenExpirationDate is required");
558
571
  return;
@@ -16,7 +16,7 @@ import GoogleSignIn
16
16
  */
17
17
  @objc(SocialLoginPlugin)
18
18
  public class SocialLoginPlugin: CAPPlugin, CAPBridgedPlugin {
19
- private let pluginVersion: String = "8.4.0"
19
+ private let pluginVersion: String = "8.4.2"
20
20
  public let identifier = "SocialLoginPlugin"
21
21
  public let jsName = "SocialLogin"
22
22
  private static let userCancelledCode = "USER_CANCELLED"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-social-login",
3
- "version": "8.4.0",
3
+ "version": "8.4.2",
4
4
  "description": "All social logins in one plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -63,6 +63,7 @@ const PLATFORM = process.env.CAPACITOR_PLATFORM_NAME;
63
63
  // const androidGradlePath = path.join(PLUGIN_ROOT, 'android', 'build.gradle');
64
64
  const gradlePropertiesPath = path.join(PLUGIN_ROOT, 'android', 'gradle.properties');
65
65
  const podspecPath = path.join(PLUGIN_ROOT, 'CapgoCapacitorSocialLogin.podspec');
66
+ const packageSwiftPath = path.join(PLUGIN_ROOT, 'Package.swift');
66
67
  // Default provider configuration (backward compatible)
67
68
  const defaultProviders = {
68
69
  google: 'implementation',
@@ -250,60 +251,111 @@ function configureAndroid(providerConfig) {
250
251
  logError(`Error updating gradle.properties: ${error.message}`);
251
252
  }
252
253
  }
253
- // ============================================================================
254
- // iOS: Podspec Configuration
255
- // ============================================================================
254
+ function applyDependencyReplacements(content, replacements) {
255
+ let updatedContent = content;
256
+ let modified = false;
257
+ for (const replacement of replacements) {
258
+ if (replacement.old.test(updatedContent)) {
259
+ const before = updatedContent;
260
+ updatedContent = updatedContent.replace(replacement.old, replacement.new);
261
+ if (before !== updatedContent) {
262
+ modified = true;
263
+ }
264
+ }
265
+ }
266
+ return { content: updatedContent, modified };
267
+ }
268
+ function getPodspecReplacements(providerConfig) {
269
+ const podspecTrailingComment = '([ \\t]*#[^\\r\\n]*)?';
270
+ return [
271
+ {
272
+ // Google SignIn - handle both active and commented (including existing disabled comments)
273
+ old: new RegExp(`(#[ \\t]*)?s\\.dependency\\s+'GoogleSignIn',\\s*'~>\\s*9\\.0\\.0'${podspecTrailingComment}`),
274
+ new: providerConfig.google === 'implementation'
275
+ ? `s.dependency 'GoogleSignIn', '~> 9.0.0'`
276
+ : `# s.dependency 'GoogleSignIn', '~> 9.0.0' # Disabled via config (compileOnly)`,
277
+ },
278
+ {
279
+ // Facebook Core - handle both active and commented (including existing disabled comments)
280
+ old: new RegExp(`(#[ \\t]*)?s\\.dependency\\s+'FBSDKCoreKit',\\s*'~>\\s*18\\.0'${podspecTrailingComment}`),
281
+ new: providerConfig.facebook === 'implementation'
282
+ ? `s.dependency 'FBSDKCoreKit', '~> 18.0'`
283
+ : `# s.dependency 'FBSDKCoreKit', '~> 18.0' # Disabled via config (compileOnly)`,
284
+ },
285
+ {
286
+ // Facebook Login - handle both active and commented (including existing disabled comments)
287
+ old: new RegExp(`(#[ \\t]*)?s\\.dependency\\s+'FBSDKLoginKit',\\s*'~>\\s*18\\.0'${podspecTrailingComment}`),
288
+ new: providerConfig.facebook === 'implementation'
289
+ ? `s.dependency 'FBSDKLoginKit', '~> 18.0'`
290
+ : `# s.dependency 'FBSDKLoginKit', '~> 18.0' # Disabled via config (compileOnly)`,
291
+ },
292
+ {
293
+ // Alamofire (for Apple) - handle both active and commented (including existing disabled comments)
294
+ old: new RegExp(`(#[ \\t]*)?s\\.dependency\\s+'Alamofire',\\s*'~>\\s*5\\.10\\.2'${podspecTrailingComment}`),
295
+ new: providerConfig.apple === 'implementation'
296
+ ? `s.dependency 'Alamofire', '~> 5.10.2'`
297
+ : `# s.dependency 'Alamofire', '~> 5.10.2' # Disabled via config (compileOnly)`,
298
+ },
299
+ ];
300
+ }
301
+ function getPackageSwiftReplacements(providerConfig) {
302
+ const swiftCommentPrefix = '(?:\\/\\/[ \\t]*)*';
303
+ const swiftTrailingComment = '(?:[ \\t]*\\/\\/[^\\r\\n]*)?';
304
+ return [
305
+ {
306
+ old: new RegExp(`${swiftCommentPrefix}\\.package\\(url:\\s*"https:\\/\\/github\\.com\\/facebook\\/facebook-ios-sdk\\.git",\\s*\\.upToNextMajor\\(from:\\s*"[^"]+"\\)\\),${swiftTrailingComment}`),
307
+ new: providerConfig.facebook === 'implementation'
308
+ ? `.package(url: "https://github.com/facebook/facebook-ios-sdk.git", .upToNextMajor(from: "18.0.3")),`
309
+ : `// .package(url: "https://github.com/facebook/facebook-ios-sdk.git", .upToNextMajor(from: "18.0.3")), // Disabled via config (compileOnly)`,
310
+ },
311
+ {
312
+ old: new RegExp(`${swiftCommentPrefix}\\.package\\(url:\\s*"https:\\/\\/github\\.com\\/google\\/GoogleSignIn-iOS\\.git",\\s*\\.upToNextMajor\\(from:\\s*"[^"]+"\\)\\),${swiftTrailingComment}`),
313
+ new: providerConfig.google === 'implementation'
314
+ ? `.package(url: "https://github.com/google/GoogleSignIn-iOS.git", .upToNextMajor(from: "9.0.0")),`
315
+ : `// .package(url: "https://github.com/google/GoogleSignIn-iOS.git", .upToNextMajor(from: "9.0.0")), // Disabled via config (compileOnly)`,
316
+ },
317
+ {
318
+ old: new RegExp(`${swiftCommentPrefix}\\.package\\(url:\\s*"https:\\/\\/github\\.com\\/Alamofire\\/Alamofire\\.git",\\s*\\.upToNextMajor\\(from:\\s*"[^"]+"\\)\\)${swiftTrailingComment}`),
319
+ new: providerConfig.apple === 'implementation'
320
+ ? `.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.11.2"))`
321
+ : `// .package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.11.2")) // Disabled via config (compileOnly)`,
322
+ },
323
+ {
324
+ old: new RegExp(`${swiftCommentPrefix}\\.product\\(name:\\s*"FacebookCore",\\s*package:\\s*"facebook-ios-sdk"\\),${swiftTrailingComment}`),
325
+ new: providerConfig.facebook === 'implementation'
326
+ ? `.product(name: "FacebookCore", package: "facebook-ios-sdk"),`
327
+ : `// .product(name: "FacebookCore", package: "facebook-ios-sdk"), // Disabled via config (compileOnly)`,
328
+ },
329
+ {
330
+ old: new RegExp(`${swiftCommentPrefix}\\.product\\(name:\\s*"FacebookLogin",\\s*package:\\s*"facebook-ios-sdk"\\),${swiftTrailingComment}`),
331
+ new: providerConfig.facebook === 'implementation'
332
+ ? `.product(name: "FacebookLogin", package: "facebook-ios-sdk"),`
333
+ : `// .product(name: "FacebookLogin", package: "facebook-ios-sdk"), // Disabled via config (compileOnly)`,
334
+ },
335
+ {
336
+ old: new RegExp(`${swiftCommentPrefix}\\.product\\(name:\\s*"GoogleSignIn",\\s*package:\\s*"GoogleSignIn-iOS"\\),${swiftTrailingComment}`),
337
+ new: providerConfig.google === 'implementation'
338
+ ? `.product(name: "GoogleSignIn", package: "GoogleSignIn-iOS"),`
339
+ : `// .product(name: "GoogleSignIn", package: "GoogleSignIn-iOS"), // Disabled via config (compileOnly)`,
340
+ },
341
+ {
342
+ old: new RegExp(`${swiftCommentPrefix}\\.product\\(name:\\s*"Alamofire",\\s*package:\\s*"Alamofire"\\)${swiftTrailingComment}`),
343
+ new: providerConfig.apple === 'implementation'
344
+ ? `.product(name: "Alamofire", package: "Alamofire")`
345
+ : `// .product(name: "Alamofire", package: "Alamofire") // Disabled via config (compileOnly)`,
346
+ },
347
+ ];
348
+ }
256
349
  /**
257
- * Modify Podspec for iOS conditional dependencies
350
+ * Modify Podspec and Package.swift for iOS conditional dependencies
258
351
  */
259
352
  function configureIOS(providerConfig) {
260
353
  logInfo('Configuring iOS dependencies...');
354
+ let success = true;
261
355
  try {
262
- let podspecContent = fs.readFileSync(podspecPath, 'utf8');
263
- // Replace dependency declarations with conditional ones
264
- // Handle both active and commented-out dependencies (including existing disabled comments)
265
- const replacements = [
266
- {
267
- // Google SignIn - handle both active and commented (including existing disabled comments)
268
- old: /(#\s*)?s\.dependency\s+'GoogleSignIn',\s*'~>\s*9\.0\.0'(\s*#.*)?/,
269
- new: providerConfig.google === 'implementation'
270
- ? `s.dependency 'GoogleSignIn', '~> 9.0.0'`
271
- : `# s.dependency 'GoogleSignIn', '~> 9.0.0' # Disabled via config (compileOnly)`,
272
- },
273
- {
274
- // Facebook Core - handle both active and commented (including existing disabled comments)
275
- old: /(#\s*)?s\.dependency\s+'FBSDKCoreKit',\s*'~>\s*18\.0'(\s*#.*)?/,
276
- new: providerConfig.facebook === 'implementation'
277
- ? `s.dependency 'FBSDKCoreKit', '~> 18.0'`
278
- : `# s.dependency 'FBSDKCoreKit', '~> 18.0' # Disabled via config (compileOnly)`,
279
- },
280
- {
281
- // Facebook Login - handle both active and commented (including existing disabled comments)
282
- old: /(#\s*)?s\.dependency\s+'FBSDKLoginKit',\s*'~>\s*18\.0'(\s*#.*)?/,
283
- new: providerConfig.facebook === 'implementation'
284
- ? `s.dependency 'FBSDKLoginKit', '~> 18.0'`
285
- : `# s.dependency 'FBSDKLoginKit', '~> 18.0' # Disabled via config (compileOnly)`,
286
- },
287
- {
288
- // Alamofire (for Apple) - handle both active and commented (including existing disabled comments)
289
- old: /(#\s*)?s\.dependency\s+'Alamofire',\s*'~>\s*5\.10\.2'(\s*#.*)?/,
290
- new: providerConfig.apple === 'implementation'
291
- ? `s.dependency 'Alamofire', '~> 5.10.2'`
292
- : `# s.dependency 'Alamofire', '~> 5.10.2' # Disabled via config (compileOnly)`,
293
- },
294
- ];
295
- let modified = false;
296
- for (const replacement of replacements) {
297
- if (replacement.old.test(podspecContent)) {
298
- const before = podspecContent;
299
- podspecContent = podspecContent.replace(replacement.old, replacement.new);
300
- if (before !== podspecContent) {
301
- modified = true;
302
- }
303
- }
304
- }
305
- if (modified) {
306
- fs.writeFileSync(podspecPath, podspecContent, 'utf8');
356
+ const podspecResult = applyDependencyReplacements(fs.readFileSync(podspecPath, 'utf8'), getPodspecReplacements(providerConfig));
357
+ if (podspecResult.modified) {
358
+ fs.writeFileSync(podspecPath, podspecResult.content, 'utf8');
307
359
  logSuccess('Modified podspec');
308
360
  }
309
361
  else {
@@ -312,7 +364,27 @@ function configureIOS(providerConfig) {
312
364
  }
313
365
  catch (error) {
314
366
  logError(`Error modifying podspec: ${error.message}`);
367
+ success = false;
368
+ }
369
+ if (!fs.existsSync(packageSwiftPath)) {
370
+ logError('Package.swift not found; Swift Package Manager configuration is required');
371
+ return false;
372
+ }
373
+ try {
374
+ const packageSwiftResult = applyDependencyReplacements(fs.readFileSync(packageSwiftPath, 'utf8'), getPackageSwiftReplacements(providerConfig));
375
+ if (packageSwiftResult.modified) {
376
+ fs.writeFileSync(packageSwiftPath, packageSwiftResult.content, 'utf8');
377
+ logSuccess('Modified Package.swift');
378
+ }
379
+ else {
380
+ logInfo('Package.swift already up to date');
381
+ }
315
382
  }
383
+ catch (error) {
384
+ logError(`Error modifying Package.swift: ${error.message}`);
385
+ success = false;
386
+ }
387
+ return success;
316
388
  }
317
389
  // ============================================================================
318
390
  // Web: No Configuration Needed
@@ -331,6 +403,7 @@ function configureWeb() {
331
403
  * Main execution
332
404
  */
333
405
  function main() {
406
+ let configurationSucceeded = true;
334
407
  // Route to platform-specific configuration
335
408
  switch (PLATFORM) {
336
409
  case 'android':
@@ -339,15 +412,13 @@ function main() {
339
412
  logInfo('Configuring dynamic provider dependencies for SocialLogin');
340
413
  logProviderConfig(androidConfig);
341
414
  configureAndroid(androidConfig);
342
- logSuccess('Configuration complete\n');
343
415
  break;
344
416
  case 'ios':
345
417
  // eslint-disable-next-line no-case-declarations
346
418
  const iosConfig = getProviderConfig();
347
419
  logInfo('Configuring dynamic provider dependencies for SocialLogin');
348
420
  logProviderConfig(iosConfig);
349
- configureIOS(iosConfig);
350
- logSuccess('Configuration complete\n');
421
+ configurationSucceeded = configureIOS(iosConfig);
351
422
  break;
352
423
  case 'web':
353
424
  configureWeb();
@@ -360,10 +431,14 @@ function main() {
360
431
  logProviderConfig(defaultConfig);
361
432
  logWarning(`Unknown platform: ${PLATFORM || 'undefined'}, configuring all platforms`);
362
433
  configureAndroid(defaultConfig);
363
- configureIOS(defaultConfig);
364
- logSuccess('Configuration complete\n');
434
+ configurationSucceeded = configureIOS(defaultConfig);
365
435
  break;
366
436
  }
437
+ if (!configurationSucceeded) {
438
+ logError('Configuration failed\n');
439
+ process.exit(1);
440
+ }
441
+ logSuccess('Configuration complete\n');
367
442
  }
368
443
  // Run if executed directly
369
444
  if (require.main === module) {