capacitor-event-bird 0.0.4 → 0.0.5

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,6 +15,8 @@ npx cap sync
15
15
 
16
16
  * [`echo(...)`](#echo)
17
17
  * [`logout()`](#logout)
18
+ * [`addListener('authTokenReceived', ...)`](#addlistenerauthtokenreceived-)
19
+ * [Interfaces](#interfaces)
18
20
 
19
21
  </docgen-index>
20
22
 
@@ -44,4 +46,30 @@ logout() => Promise<void>
44
46
 
45
47
  --------------------
46
48
 
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
+
47
75
  </docgen-api>
package/dist/docs.json CHANGED
@@ -30,11 +30,51 @@
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-"
33
56
  }
34
57
  ],
35
58
  "properties": []
36
59
  },
37
- "interfaces": [],
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
+ ],
38
78
  "enums": [],
39
79
  "typeAliases": [],
40
80
  "pluginConfigs": []
@@ -1,3 +1,6 @@
1
+ export interface AuthTokenReceivedData {
2
+ token: string;
3
+ }
1
4
  export interface CapacitorEventBirdPlugin {
2
5
  echo(options: {
3
6
  value: string;
@@ -5,4 +8,7 @@ export interface CapacitorEventBirdPlugin {
5
8
  value: string;
6
9
  }>;
7
10
  logout(): Promise<void>;
11
+ addListener(eventName: 'authTokenReceived', listenerFunc: (data: AuthTokenReceivedData) => void): Promise<{
12
+ remove: () => void;
13
+ }>;
8
14
  }
@@ -1 +1 @@
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
+ {"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"]}
@@ -5,11 +5,17 @@ import Capacitor
5
5
  public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
6
6
  public let identifier = "CapacitorEventBirdPlugin"
7
7
  public let jsName = "CapacitorEventBird"
8
+
8
9
  public let pluginMethods: [CAPPluginMethod] = [
9
10
  CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
10
11
  CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise)
11
12
  ]
12
13
 
14
+ // Register the supported events
15
+ public let pluginEvents: [CAPPluginEvent] = [
16
+ CAPPluginEvent(name: "authTokenReceived", returnType: CAPPluginReturnCallback)
17
+ ]
18
+
13
19
  private let implementation = CapacitorEventBird()
14
20
 
15
21
  @objc func echo(_ call: CAPPluginCall) {
@@ -20,7 +26,17 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
20
26
  }
21
27
 
22
28
  @objc func logout(_ call: CAPPluginCall) {
23
- NotificationCenter.default.post(name: Notification.Name("NativeLogoutEvent"), object: nil)
24
- call.resolve()
29
+ NotificationCenter.default.post(name: Notification.Name("NativeLogoutEvent"), object: nil)
30
+ call.resolve()
31
+ }
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
+ )
25
41
  }
26
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-event-bird",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "returns events back to native env",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",