capacitor-event-bird 0.0.4 → 0.0.7

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
@@ -14,7 +14,10 @@ npx cap sync
14
14
  <docgen-index>
15
15
 
16
16
  * [`echo(...)`](#echo)
17
+ * [`notifyNativeReady()`](#notifynativeready)
17
18
  * [`logout()`](#logout)
19
+ * [`addListener('authTokenReceived', ...)`](#addlistenerauthtokenreceived-)
20
+ * [Interfaces](#interfaces)
18
21
 
19
22
  </docgen-index>
20
23
 
@@ -36,6 +39,15 @@ echo(options: { value: string; }) => Promise<{ value: string; }>
36
39
  --------------------
37
40
 
38
41
 
42
+ ### notifyNativeReady()
43
+
44
+ ```typescript
45
+ notifyNativeReady() => Promise<void>
46
+ ```
47
+
48
+ --------------------
49
+
50
+
39
51
  ### logout()
40
52
 
41
53
  ```typescript
@@ -44,4 +56,30 @@ logout() => Promise<void>
44
56
 
45
57
  --------------------
46
58
 
59
+
60
+ ### addListener('authTokenReceived', ...)
61
+
62
+ ```typescript
63
+ addListener(eventName: 'authTokenReceived', listenerFunc: (data: AuthTokenReceivedData) => void) => Promise<{ remove: () => void; }>
64
+ ```
65
+
66
+ | Param | Type |
67
+ | ------------------ | ------------------------------------------------------------------------------------------ |
68
+ | **`eventName`** | <code>'authTokenReceived'</code> |
69
+ | **`listenerFunc`** | <code>(data: <a href="#authtokenreceiveddata">AuthTokenReceivedData</a>) =&gt; void</code> |
70
+
71
+ **Returns:** <code>Promise&lt;{ remove: () =&gt; void; }&gt;</code>
72
+
73
+ --------------------
74
+
75
+
76
+ ### Interfaces
77
+
78
+
79
+ #### AuthTokenReceivedData
80
+
81
+ | Prop | Type |
82
+ | ----------- | ------------------- |
83
+ | **`token`** | <code>string</code> |
84
+
47
85
  </docgen-api>
package/dist/docs.json CHANGED
@@ -21,6 +21,16 @@
21
21
  "complexTypes": [],
22
22
  "slug": "echo"
23
23
  },
24
+ {
25
+ "name": "notifyNativeReady",
26
+ "signature": "() => Promise<void>",
27
+ "parameters": [],
28
+ "returns": "Promise<void>",
29
+ "tags": [],
30
+ "docs": "",
31
+ "complexTypes": [],
32
+ "slug": "notifynativeready"
33
+ },
24
34
  {
25
35
  "name": "logout",
26
36
  "signature": "() => Promise<void>",
@@ -30,11 +40,51 @@
30
40
  "docs": "",
31
41
  "complexTypes": [],
32
42
  "slug": "logout"
43
+ },
44
+ {
45
+ "name": "addListener",
46
+ "signature": "(eventName: 'authTokenReceived', listenerFunc: (data: AuthTokenReceivedData) => void) => Promise<{ remove: () => void; }>",
47
+ "parameters": [
48
+ {
49
+ "name": "eventName",
50
+ "docs": "",
51
+ "type": "'authTokenReceived'"
52
+ },
53
+ {
54
+ "name": "listenerFunc",
55
+ "docs": "",
56
+ "type": "(data: AuthTokenReceivedData) => void"
57
+ }
58
+ ],
59
+ "returns": "Promise<{ remove: () => void; }>",
60
+ "tags": [],
61
+ "docs": "",
62
+ "complexTypes": [
63
+ "AuthTokenReceivedData"
64
+ ],
65
+ "slug": "addlistenerauthtokenreceived-"
33
66
  }
34
67
  ],
35
68
  "properties": []
36
69
  },
37
- "interfaces": [],
70
+ "interfaces": [
71
+ {
72
+ "name": "AuthTokenReceivedData",
73
+ "slug": "authtokenreceiveddata",
74
+ "docs": "",
75
+ "tags": [],
76
+ "methods": [],
77
+ "properties": [
78
+ {
79
+ "name": "token",
80
+ "tags": [],
81
+ "docs": "",
82
+ "complexTypes": [],
83
+ "type": "string"
84
+ }
85
+ ]
86
+ }
87
+ ],
38
88
  "enums": [],
39
89
  "typeAliases": [],
40
90
  "pluginConfigs": []
@@ -1,8 +1,15 @@
1
+ export interface AuthTokenReceivedData {
2
+ token: string;
3
+ }
1
4
  export interface CapacitorEventBirdPlugin {
2
5
  echo(options: {
3
6
  value: string;
4
7
  }): Promise<{
5
8
  value: string;
6
9
  }>;
10
+ notifyNativeReady(): Promise<void>;
7
11
  logout(): Promise<void>;
12
+ addListener(eventName: 'authTokenReceived', listenerFunc: (data: AuthTokenReceivedData) => void): Promise<{
13
+ remove: () => void;
14
+ }>;
8
15
  }
@@ -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 notifyNativeReady(): Promise<void>;\n logout(): Promise<void>;\n addListener(\n eventName: 'authTokenReceived',\n listenerFunc: (data: AuthTokenReceivedData) => void\n ): Promise<{ remove: () => void }>;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import type { CapacitorEventBirdPlugin } from './definitions';
3
3
  export declare class CapacitorEventBirdWeb extends WebPlugin implements CapacitorEventBirdPlugin {
4
+ notifyNativeReady(): Promise<void>;
4
5
  echo(options: {
5
6
  value: string;
6
7
  }): Promise<{
package/dist/esm/web.js CHANGED
@@ -1,5 +1,11 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  export class CapacitorEventBirdWeb extends WebPlugin {
3
+ notifyNativeReady() {
4
+ console.log('notifyNativeReady() not implemented.');
5
+ return new Promise((resolve, _) => {
6
+ resolve();
7
+ });
8
+ }
3
9
  async echo(options) {
4
10
  console.log('ECHO', options);
5
11
  return options;
@@ -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,iBAAiB;QACf,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;QAEpD,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE;YACtC,OAAO,EAAE,CAAC;QACZ,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,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 notifyNativeReady(): Promise<void> {\n console.log('notifyNativeReady() not implemented.');\n\n return new Promise<void>((resolve, _) => {\n resolve();\n })\n }\n\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"]}
@@ -7,6 +7,12 @@ const CapacitorEventBird = core.registerPlugin('CapacitorEventBird', {
7
7
  });
8
8
 
9
9
  class CapacitorEventBirdWeb extends core.WebPlugin {
10
+ notifyNativeReady() {
11
+ console.log('notifyNativeReady() not implemented.');
12
+ return new Promise((resolve, _) => {
13
+ resolve();
14
+ });
15
+ }
10
16
  async echo(options) {
11
17
  console.log('ECHO', options);
12
18
  return options;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorEventBird = registerPlugin('CapacitorEventBird', {\n web: () => import('./web').then((m) => new m.CapacitorEventBirdWeb()),\n});\nexport * from './definitions';\nexport { CapacitorEventBird };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorEventBirdWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async logout() {\n console.log('logout in web isnt really needed it already works');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;AACzE,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC,QAAQ,OAAO,OAAO;AACtB;AACA,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC;AACxE;AACA;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorEventBird = registerPlugin('CapacitorEventBird', {\n web: () => import('./web').then((m) => new m.CapacitorEventBirdWeb()),\n});\nexport * from './definitions';\nexport { CapacitorEventBird };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorEventBirdWeb extends WebPlugin {\n notifyNativeReady() {\n console.log('notifyNativeReady() not implemented.');\n return new Promise((resolve, _) => {\n resolve();\n });\n }\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async logout() {\n console.log('logout in web isnt really needed it already works');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;AAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;AACzE,CAAC;;ACFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;AACrD,IAAI,iBAAiB,GAAG;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC;AAC3D,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK;AAC3C,YAAY,OAAO,EAAE;AACrB,SAAS,CAAC;AACV;AACA,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC,QAAQ,OAAO,OAAO;AACtB;AACA,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC;AACxE;AACA;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -6,6 +6,12 @@ var capacitorCapacitorEventBird = (function (exports, core) {
6
6
  });
7
7
 
8
8
  class CapacitorEventBirdWeb extends core.WebPlugin {
9
+ notifyNativeReady() {
10
+ console.log('notifyNativeReady() not implemented.');
11
+ return new Promise((resolve, _) => {
12
+ resolve();
13
+ });
14
+ }
9
15
  async echo(options) {
10
16
  console.log('ECHO', options);
11
17
  return options;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorEventBird = registerPlugin('CapacitorEventBird', {\n web: () => import('./web').then((m) => new m.CapacitorEventBirdWeb()),\n});\nexport * from './definitions';\nexport { CapacitorEventBird };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorEventBirdWeb extends WebPlugin {\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async logout() {\n console.log('logout in web isnt really needed it already works');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;IAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;IACzE,CAAC;;ICFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;IACrD,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC,QAAQ,OAAO,OAAO;IACtB;IACA,IAAI,MAAM,MAAM,GAAG;IACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC;IACxE;IACA;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapacitorEventBird = registerPlugin('CapacitorEventBird', {\n web: () => import('./web').then((m) => new m.CapacitorEventBirdWeb()),\n});\nexport * from './definitions';\nexport { CapacitorEventBird };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorEventBirdWeb extends WebPlugin {\n notifyNativeReady() {\n console.log('notifyNativeReady() not implemented.');\n return new Promise((resolve, _) => {\n resolve();\n });\n }\n async echo(options) {\n console.log('ECHO', options);\n return options;\n }\n async logout() {\n console.log('logout in web isnt really needed it already works');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,kBAAkB,GAAGA,mBAAc,CAAC,oBAAoB,EAAE;IAChE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,qBAAqB,EAAE,CAAC;IACzE,CAAC;;ICFM,MAAM,qBAAqB,SAASC,cAAS,CAAC;IACrD,IAAI,iBAAiB,GAAG;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC;IAC3D,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK;IAC3C,YAAY,OAAO,EAAE;IACrB,SAAS,CAAC;IACV;IACA,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC,QAAQ,OAAO,OAAO;IACtB;IACA,IAAI,MAAM,MAAM,GAAG;IACnB,QAAQ,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC;IACxE;IACA;;;;;;;;;;;;;;;"}
@@ -5,9 +5,11 @@ 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
- CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise)
11
+ CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise),
12
+ CAPPluginMethod(name: "notifyNativeReady", returnType: CAPPluginReturnPromise),
11
13
  ]
12
14
 
13
15
  private let implementation = CapacitorEventBird()
@@ -20,7 +22,29 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
20
22
  }
21
23
 
22
24
  @objc func logout(_ call: CAPPluginCall) {
23
- NotificationCenter.default.post(name: Notification.Name("NativeLogoutEvent"), object: nil)
24
- call.resolve()
25
+ NotificationCenter.default.post(name: Notification.Name("NativeLogoutEvent"), object: nil)
26
+ call.resolve()
27
+ }
28
+
29
+ // Call this from AppDelegate or native to emit the token to JS
30
+ @objc public func sendAuthTokenToJS(_ token: String) {
31
+ let json = "{ \"token\": \"\(token)\" }"
32
+ bridge?.triggerJSEvent(
33
+ eventName: "authTokenReceived",
34
+ target: "window",
35
+ data: json
36
+ )
37
+ }
38
+
39
+ @objc func notifyNativeReady(_ call: CAPPluginCall) {
40
+ print("[Native] JS signaled ready")
41
+
42
+ // If we already have a token pending, send it now
43
+ if let token = AppDelegate.shared?.pendingToken {
44
+ sendAuthTokenToJS(token)
45
+ AppDelegate.shared?.pendingToken = nil
46
+ }
47
+
48
+ call.resolve()
25
49
  }
26
50
  }
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.7",
4
4
  "description": "returns events back to native env",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",