capacitor-event-bird 0.0.5 → 0.0.8

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
@@ -15,8 +15,6 @@ npx cap sync
15
15
 
16
16
  * [`echo(...)`](#echo)
17
17
  * [`logout()`](#logout)
18
- * [`addListener('authTokenReceived', ...)`](#addlistenerauthtokenreceived-)
19
- * [Interfaces](#interfaces)
20
18
 
21
19
  </docgen-index>
22
20
 
@@ -46,30 +44,4 @@ logout() => Promise<void>
46
44
 
47
45
  --------------------
48
46
 
49
-
50
- ### addListener('authTokenReceived', ...)
51
-
52
- ```typescript
53
- addListener(eventName: 'authTokenReceived', listenerFunc: (data: AuthTokenReceivedData) => void) => Promise<{ remove: () => void; }>
54
- ```
55
-
56
- | Param | Type |
57
- | ------------------ | ------------------------------------------------------------------------------------------ |
58
- | **`eventName`** | <code>'authTokenReceived'</code> |
59
- | **`listenerFunc`** | <code>(data: <a href="#authtokenreceiveddata">AuthTokenReceivedData</a>) =&gt; void</code> |
60
-
61
- **Returns:** <code>Promise&lt;{ remove: () =&gt; void; }&gt;</code>
62
-
63
- --------------------
64
-
65
-
66
- ### Interfaces
67
-
68
-
69
- #### AuthTokenReceivedData
70
-
71
- | Prop | Type |
72
- | ----------- | ------------------- |
73
- | **`token`** | <code>string</code> |
74
-
75
47
  </docgen-api>
package/dist/docs.json CHANGED
@@ -30,51 +30,11 @@
30
30
  "docs": "",
31
31
  "complexTypes": [],
32
32
  "slug": "logout"
33
- },
34
- {
35
- "name": "addListener",
36
- "signature": "(eventName: 'authTokenReceived', listenerFunc: (data: AuthTokenReceivedData) => void) => Promise<{ remove: () => void; }>",
37
- "parameters": [
38
- {
39
- "name": "eventName",
40
- "docs": "",
41
- "type": "'authTokenReceived'"
42
- },
43
- {
44
- "name": "listenerFunc",
45
- "docs": "",
46
- "type": "(data: AuthTokenReceivedData) => void"
47
- }
48
- ],
49
- "returns": "Promise<{ remove: () => void; }>",
50
- "tags": [],
51
- "docs": "",
52
- "complexTypes": [
53
- "AuthTokenReceivedData"
54
- ],
55
- "slug": "addlistenerauthtokenreceived-"
56
33
  }
57
34
  ],
58
35
  "properties": []
59
36
  },
60
- "interfaces": [
61
- {
62
- "name": "AuthTokenReceivedData",
63
- "slug": "authtokenreceiveddata",
64
- "docs": "",
65
- "tags": [],
66
- "methods": [],
67
- "properties": [
68
- {
69
- "name": "token",
70
- "tags": [],
71
- "docs": "",
72
- "complexTypes": [],
73
- "type": "string"
74
- }
75
- ]
76
- }
77
- ],
37
+ "interfaces": [],
78
38
  "enums": [],
79
39
  "typeAliases": [],
80
40
  "pluginConfigs": []
@@ -1,6 +1,3 @@
1
- export interface AuthTokenReceivedData {
2
- token: string;
3
- }
4
1
  export interface CapacitorEventBirdPlugin {
5
2
  echo(options: {
6
3
  value: string;
@@ -8,7 +5,4 @@ export interface CapacitorEventBirdPlugin {
8
5
  value: string;
9
6
  }>;
10
7
  logout(): Promise<void>;
11
- addListener(eventName: 'authTokenReceived', listenerFunc: (data: AuthTokenReceivedData) => void): Promise<{
12
- remove: () => void;
13
- }>;
14
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AuthTokenReceivedData {\n token: string;\n}\n\nexport interface CapacitorEventBirdPlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\n logout(): Promise<void>;\n addListener(\n eventName: 'authTokenReceived',\n listenerFunc: (data: AuthTokenReceivedData) => void\n ): Promise<{ remove: () => void }>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CapacitorEventBirdPlugin {\n echo(options: { value: string }): Promise<{ value: string }>;\n logout(): Promise<void>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAA;IAClE,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { CapacitorEventBirdPlugin } from './definitions';\n\nexport class CapacitorEventBirdWeb extends WebPlugin implements CapacitorEventBirdPlugin {\n async echo(options: { value: string }): Promise<{ value: string }> {\n console.log('ECHO', options);\n return options;\n }\n\n async logout(): Promise<void> {\n console.log('logout in web isnt really needed it already works')\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,KAAK,CAAC,IAAI,CAAC,OAA0B;QACnC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,MAAM;QACV,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { CapacitorEventBirdPlugin } from './definitions';\n\nexport class CapacitorEventBirdWeb extends WebPlugin implements CapacitorEventBirdPlugin {\n async echo(options: { value: string }): Promise<{ value: string }> {\n console.log('ECHO', options);\n return options;\n }\n\n async logout(): Promise<void> {\n console.log('logout in web isnt really needed it already works');\n }\n}\n"]}
@@ -8,35 +8,36 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
8
8
 
9
9
  public let pluginMethods: [CAPPluginMethod] = [
10
10
  CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
11
- CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise)
12
- ]
13
-
14
- // Register the supported events
15
- public let pluginEvents: [CAPPluginEvent] = [
16
- CAPPluginEvent(name: "authTokenReceived", returnType: CAPPluginReturnCallback)
11
+ CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise),
17
12
  ]
18
13
 
14
+ private var pendingEchoCalls: [CAPPluginCall] = []
15
+ private var savedToken: String?
19
16
  private let implementation = CapacitorEventBird()
20
17
 
21
18
  @objc func echo(_ call: CAPPluginCall) {
22
- let value = call.getString("value") ?? ""
23
- call.resolve([
24
- "value": implementation.echo(value)
25
- ])
19
+ if let token = savedToken {
20
+ call.resolve(["value": token])
21
+ } else {
22
+ print("[Native] JS called echo, but token not ready. Queuing callback.")
23
+ pendingEchoCalls.append(call)
24
+ }
25
+ }
26
+
27
+ // Called by native code to store the token
28
+ @objc public func setAuthToken(_ token: String) {
29
+ print("[Native] Setting auth token in plugin")
30
+ self.savedToken = token
31
+
32
+ // Resolve all pending echo calls
33
+ for call in pendingEchoCalls {
34
+ call.resolve(["value": token])
35
+ }
36
+ pendingEchoCalls.removeAll()
26
37
  }
27
38
 
28
39
  @objc func logout(_ call: CAPPluginCall) {
29
40
  NotificationCenter.default.post(name: Notification.Name("NativeLogoutEvent"), object: nil)
30
41
  call.resolve()
31
42
  }
32
-
33
- // Call this from AppDelegate or native to emit the token to JS
34
- @objc public func sendAuthTokenToJS(_ token: String) {
35
- let json = "{ \"token\": \"\(token)\" }"
36
- bridge?.triggerJSEvent(
37
- eventName: "authTokenReceived",
38
- target: "window",
39
- data: json
40
- )
41
- }
42
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-event-bird",
3
- "version": "0.0.5",
3
+ "version": "0.0.8",
4
4
  "description": "returns events back to native env",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",