capacitor-event-bird 0.0.26 → 0.0.27

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
@@ -13,25 +13,49 @@ npx cap sync
13
13
 
14
14
  <docgen-index>
15
15
 
16
+ * [`echo(...)`](#echo)
17
+ * [`logout()`](#logout)
16
18
  * [`signupWithGoogle()`](#signupwithgoogle)
17
19
  * [`waitlistAfterInit()`](#waitlistafterinit)
18
20
  * [`openHelpModal()`](#openhelpmodal)
19
21
  * [`getDeviceId()`](#getdeviceid)
22
+ * [`getGoogleData()`](#getgoogledata)
20
23
  * [`getFCMToken(...)`](#getfcmtoken)
21
- * [`saveCredentials(...)`](#savecredentials)
22
24
 
23
25
  </docgen-index>
24
26
 
25
27
  <docgen-api>
26
28
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
27
29
 
28
- ### signupWithGoogle()
30
+ ### echo(...)
29
31
 
30
32
  ```typescript
31
- signupWithGoogle() => Promise<{ displayName: string; email: string; firebaseToken: string; }>
33
+ echo(options: { value: string; }) => Promise<{ value: string; }>
32
34
  ```
33
35
 
34
- **Returns:** <code>Promise&lt;{ displayName: string; email: string; firebaseToken: string; }&gt;</code>
36
+ | Param | Type |
37
+ | ------------- | ------------------------------- |
38
+ | **`options`** | <code>{ value: string; }</code> |
39
+
40
+ **Returns:** <code>Promise&lt;{ value: string; }&gt;</code>
41
+
42
+ --------------------
43
+
44
+
45
+ ### logout()
46
+
47
+ ```typescript
48
+ logout() => Promise<void>
49
+ ```
50
+
51
+ --------------------
52
+
53
+
54
+ ### signupWithGoogle()
55
+
56
+ ```typescript
57
+ signupWithGoogle() => Promise<void>
58
+ ```
35
59
 
36
60
  --------------------
37
61
 
@@ -65,32 +89,28 @@ getDeviceId() => Promise<{ value: string; }>
65
89
  --------------------
66
90
 
67
91
 
68
- ### getFCMToken(...)
92
+ ### getGoogleData()
69
93
 
70
94
  ```typescript
71
- getFCMToken(options: { value: string; }) => Promise<{ value: string; }>
95
+ getGoogleData() => Promise<{ displayName: string; email: string; firebaseToken: string; }>
72
96
  ```
73
97
 
74
- | Param | Type |
75
- | ------------- | ------------------------------- |
76
- | **`options`** | <code>{ value: string; }</code> |
77
-
78
- **Returns:** <code>Promise&lt;{ value: string; }&gt;</code>
98
+ **Returns:** <code>Promise&lt;{ displayName: string; email: string; firebaseToken: string; }&gt;</code>
79
99
 
80
100
  --------------------
81
101
 
82
102
 
83
- ### saveCredentials(...)
103
+ ### getFCMToken(...)
84
104
 
85
105
  ```typescript
86
- saveCredentials(options: { username: string; password: string; }) => Promise<{ isSuccess: boolean; }>
106
+ getFCMToken(options: { value: string; }) => Promise<{ value: string; }>
87
107
  ```
88
108
 
89
- | Param | Type |
90
- | ------------- | ---------------------------------------------------- |
91
- | **`options`** | <code>{ username: string; password: string; }</code> |
109
+ | Param | Type |
110
+ | ------------- | ------------------------------- |
111
+ | **`options`** | <code>{ value: string; }</code> |
92
112
 
93
- **Returns:** <code>Promise&lt;{ isSuccess: boolean; }&gt;</code>
113
+ **Returns:** <code>Promise&lt;{ value: string; }&gt;</code>
94
114
 
95
115
  --------------------
96
116
 
@@ -0,0 +1,8 @@
1
+ import Foundation
2
+
3
+ @objc public class CapacitorEventBird: NSObject {
4
+ @objc public func echo(_ value: String) -> String {
5
+ print(value)
6
+ return value
7
+ }
8
+ }
@@ -7,35 +7,33 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
7
7
  public let jsName = "CapacitorEventBird"
8
8
 
9
9
  public let pluginMethods: [CAPPluginMethod] = [
10
+ CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
10
11
  CAPPluginMethod(name: "getFCMToken", returnType: CAPPluginReturnPromise),
12
+ CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise),
13
+ CAPPluginMethod(name: "signupWithGoogle", returnType: CAPPluginReturnPromise),
11
14
  CAPPluginMethod(name: "waitlistAfterInit", returnType: CAPPluginReturnPromise),
12
15
  CAPPluginMethod(name: "openHelpModal", returnType: CAPPluginReturnPromise),
13
16
  CAPPluginMethod(name: "getDeviceId", returnType: CAPPluginReturnPromise),
14
- CAPPluginMethod(name: "signupWithGoogle", returnType: CAPPluginReturnPromise),
15
- CAPPluginMethod(name: "saveCredentials", returnType: CAPPluginReturnPromise),
17
+ CAPPluginMethod(name: "getGoogleData", returnType: CAPPluginReturnPromise),
16
18
  ]
17
19
 
20
+ private var pendingEchoCalls: [CAPPluginCall] = []
18
21
  private var pendingFCMCalls: [CAPPluginCall] = []
19
22
  private var pendingGoogleCalls: [CAPPluginCall] = []
20
- private var pendingSaveCredentialsCall: [CAPPluginCall] = []
21
23
 
24
+ private var savedToken: String?
22
25
  private var savedFCMToken: String?
23
26
 
24
- @objc func saveCredentials(_ call: CAPPluginCall) {
25
- let username = call.getString("username") ?? ""
26
- let password = call.getString("password") ?? ""
27
-
28
- NotificationCenter.default.post(name: Notification.Name("SaveCredentials"), object: ["username": username, "password": password])
29
- pendingSaveCredentialsCall.append(call)
30
- }
31
-
32
- @objc public func saveCredentialsResult(_ isSuccess: Bool) {
33
- print("[Native] saveCredentialsResult()")
27
+ private let implementation = CapacitorEventBird()
34
28
 
35
- for call in pendingSaveCredentialsCall {
36
- call.resolve(["isSuccess": isSuccess])
29
+ @objc func echo(_ call: CAPPluginCall) {
30
+ if let token = savedToken {
31
+ print("[Native] JS called echo, passing the token.")
32
+ call.resolve(["value": token])
33
+ } else {
34
+ print("[Native] JS called echo, but token not ready. Queuing callback.")
35
+ pendingEchoCalls.append(call)
37
36
  }
38
- pendingSaveCredentialsCall.removeAll()
39
37
  }
40
38
 
41
39
  @objc func getFCMToken(_ call: CAPPluginCall) {
@@ -53,9 +51,8 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
53
51
  return
54
52
  }
55
53
 
56
- @objc func signupWithGoogle(_ call: CAPPluginCall) {
57
- NotificationCenter.default.post(name: Notification.Name("CapacitorSignupWithGoogle"), object: nil)
58
- print("[Native] JS called getGoogleData, sending CapacitorSignupWithGoogle event")
54
+ @objc func getGoogleData(_ call: CAPPluginCall) {
55
+ print("[Native] JS called getGoogleData, but data not ready. Queuing callback.")
59
56
  pendingGoogleCalls.append(call)
60
57
  }
61
58
 
@@ -79,6 +76,28 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
79
76
  notifyListeners("fcmTokenRefreshed", data: ["token": token])
80
77
  }
81
78
 
79
+ @objc public func setAuthToken(_ token: String) {
80
+ print("[Native] Setting auth token in plugin")
81
+ self.savedToken = token
82
+
83
+ for call in pendingEchoCalls {
84
+ call.resolve(["value": token])
85
+ }
86
+ pendingEchoCalls.removeAll()
87
+ }
88
+
89
+ @objc func logout(_ call: CAPPluginCall) {
90
+ NotificationCenter.default.post(name: Notification.Name("NativeLogoutEvent"), object: nil)
91
+ savedToken = nil
92
+ pendingEchoCalls.removeAll()
93
+ call.resolve()
94
+ }
95
+
96
+ @objc func signupWithGoogle(_ call: CAPPluginCall) {
97
+ NotificationCenter.default.post(name: Notification.Name("CapacitorSignupWithGoogle"), object: nil)
98
+ call.resolve()
99
+ }
100
+
82
101
  @objc func openHelpModal(_ call: CAPPluginCall) {
83
102
  NotificationCenter.default.post(name: Notification.Name("HelpBeaconOpenEvent"), object: nil)
84
103
  call.resolve()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-event-bird",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "returns events back to native env",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",