capacitor-event-bird 0.0.7 → 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
@@ -14,10 +14,7 @@ npx cap sync
14
14
  <docgen-index>
15
15
 
16
16
  * [`echo(...)`](#echo)
17
- * [`notifyNativeReady()`](#notifynativeready)
18
17
  * [`logout()`](#logout)
19
- * [`addListener('authTokenReceived', ...)`](#addlistenerauthtokenreceived-)
20
- * [Interfaces](#interfaces)
21
18
 
22
19
  </docgen-index>
23
20
 
@@ -39,15 +36,6 @@ echo(options: { value: string; }) => Promise<{ value: string; }>
39
36
  --------------------
40
37
 
41
38
 
42
- ### notifyNativeReady()
43
-
44
- ```typescript
45
- notifyNativeReady() => Promise<void>
46
- ```
47
-
48
- --------------------
49
-
50
-
51
39
  ### logout()
52
40
 
53
41
  ```typescript
@@ -56,30 +44,4 @@ logout() => Promise<void>
56
44
 
57
45
  --------------------
58
46
 
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
-
85
47
  </docgen-api>
package/dist/docs.json CHANGED
@@ -21,16 +21,6 @@
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
- },
34
24
  {
35
25
  "name": "logout",
36
26
  "signature": "() => Promise<void>",
@@ -40,51 +30,11 @@
40
30
  "docs": "",
41
31
  "complexTypes": [],
42
32
  "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-"
66
33
  }
67
34
  ],
68
35
  "properties": []
69
36
  },
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
- ],
37
+ "interfaces": [],
88
38
  "enums": [],
89
39
  "typeAliases": [],
90
40
  "pluginConfigs": []
@@ -1,15 +1,8 @@
1
- export interface AuthTokenReceivedData {
2
- token: string;
3
- }
4
1
  export interface CapacitorEventBirdPlugin {
5
2
  echo(options: {
6
3
  value: string;
7
4
  }): Promise<{
8
5
  value: string;
9
6
  }>;
10
- notifyNativeReady(): Promise<void>;
11
7
  logout(): Promise<void>;
12
- addListener(eventName: 'authTokenReceived', listenerFunc: (data: AuthTokenReceivedData) => void): Promise<{
13
- remove: () => void;
14
- }>;
15
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 notifyNativeReady(): Promise<void>;\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"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,7 +1,6 @@
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>;
5
4
  echo(options: {
6
5
  value: string;
7
6
  }): Promise<{
package/dist/esm/web.js CHANGED
@@ -1,11 +1,5 @@
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
- }
9
3
  async echo(options) {
10
4
  console.log('ECHO', options);
11
5
  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,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"]}
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"]}
@@ -7,12 +7,6 @@ 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
- }
16
10
  async echo(options) {
17
11
  console.log('ECHO', options);
18
12
  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 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;;;;;;;;;"}
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;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -6,12 +6,6 @@ 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
- }
15
9
  async echo(options) {
16
10
  console.log('ECHO', options);
17
11
  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 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;;;;;;;;;;;;;;;"}
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;;;;;;;;;;;;;;;"}
@@ -9,42 +9,35 @@ public class CapacitorEventBirdPlugin: CAPPlugin, CAPBridgedPlugin {
9
9
  public let pluginMethods: [CAPPluginMethod] = [
10
10
  CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
11
11
  CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise),
12
- CAPPluginMethod(name: "notifyNativeReady", returnType: CAPPluginReturnPromise),
13
12
  ]
14
13
 
14
+ private var pendingEchoCalls: [CAPPluginCall] = []
15
+ private var savedToken: String?
15
16
  private let implementation = CapacitorEventBird()
16
17
 
17
18
  @objc func echo(_ call: CAPPluginCall) {
18
- let value = call.getString("value") ?? ""
19
- call.resolve([
20
- "value": implementation.echo(value)
21
- ])
22
- }
23
-
24
- @objc func logout(_ call: CAPPluginCall) {
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
- )
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
+ }
37
25
  }
38
26
 
39
- @objc func notifyNativeReady(_ call: CAPPluginCall) {
40
- print("[Native] JS signaled ready")
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
41
31
 
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
32
+ // Resolve all pending echo calls
33
+ for call in pendingEchoCalls {
34
+ call.resolve(["value": token])
46
35
  }
36
+ pendingEchoCalls.removeAll()
37
+ }
47
38
 
39
+ @objc func logout(_ call: CAPPluginCall) {
40
+ NotificationCenter.default.post(name: Notification.Name("NativeLogoutEvent"), object: nil)
48
41
  call.resolve()
49
42
  }
50
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-event-bird",
3
- "version": "0.0.7",
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",