@symbiote-native/notifications 0.1.0

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.
Files changed (94) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +258 -0
  3. package/build/angular/index.d.ts +1 -0
  4. package/build/angular/index.js +1 -0
  5. package/build/core/background-task.d.ts +9 -0
  6. package/build/core/background-task.js +28 -0
  7. package/build/core/badge.d.ts +7 -0
  8. package/build/core/badge.js +23 -0
  9. package/build/core/categories.d.ts +10 -0
  10. package/build/core/categories.js +28 -0
  11. package/build/core/channels.d.ts +20 -0
  12. package/build/core/channels.js +106 -0
  13. package/build/core/emitter.d.ts +24 -0
  14. package/build/core/emitter.js +58 -0
  15. package/build/core/handler.d.ts +15 -0
  16. package/build/core/handler.js +50 -0
  17. package/build/core/index.d.ts +12 -0
  18. package/build/core/index.js +11 -0
  19. package/build/core/native-modules.d.ts +82 -0
  20. package/build/core/native-modules.js +33 -0
  21. package/build/core/permissions.d.ts +8 -0
  22. package/build/core/permissions.js +30 -0
  23. package/build/core/presenter.d.ts +7 -0
  24. package/build/core/presenter.js +27 -0
  25. package/build/core/scheduler.d.ts +13 -0
  26. package/build/core/scheduler.js +193 -0
  27. package/build/core/tokens.d.ts +30 -0
  28. package/build/core/tokens.js +192 -0
  29. package/build/core/types.d.ts +633 -0
  30. package/build/core/types.js +116 -0
  31. package/build/core/utils.d.ts +6 -0
  32. package/build/core/utils.js +53 -0
  33. package/build-ngc/angular/index.d.ts +1 -0
  34. package/build-ngc/angular/index.js +2 -0
  35. package/build-ngc/angular/index.js.map +1 -0
  36. package/build-ngc/core/background-task.d.ts +9 -0
  37. package/build-ngc/core/background-task.js +29 -0
  38. package/build-ngc/core/background-task.js.map +1 -0
  39. package/build-ngc/core/badge.d.ts +7 -0
  40. package/build-ngc/core/badge.js +24 -0
  41. package/build-ngc/core/badge.js.map +1 -0
  42. package/build-ngc/core/categories.d.ts +10 -0
  43. package/build-ngc/core/categories.js +29 -0
  44. package/build-ngc/core/categories.js.map +1 -0
  45. package/build-ngc/core/channels.d.ts +20 -0
  46. package/build-ngc/core/channels.js +107 -0
  47. package/build-ngc/core/channels.js.map +1 -0
  48. package/build-ngc/core/emitter.d.ts +24 -0
  49. package/build-ngc/core/emitter.js +59 -0
  50. package/build-ngc/core/emitter.js.map +1 -0
  51. package/build-ngc/core/handler.d.ts +15 -0
  52. package/build-ngc/core/handler.js +51 -0
  53. package/build-ngc/core/handler.js.map +1 -0
  54. package/build-ngc/core/index.d.ts +12 -0
  55. package/build-ngc/core/index.js +12 -0
  56. package/build-ngc/core/index.js.map +1 -0
  57. package/build-ngc/core/native-modules.d.ts +82 -0
  58. package/build-ngc/core/native-modules.js +34 -0
  59. package/build-ngc/core/native-modules.js.map +1 -0
  60. package/build-ngc/core/permissions.d.ts +8 -0
  61. package/build-ngc/core/permissions.js +31 -0
  62. package/build-ngc/core/permissions.js.map +1 -0
  63. package/build-ngc/core/presenter.d.ts +7 -0
  64. package/build-ngc/core/presenter.js +28 -0
  65. package/build-ngc/core/presenter.js.map +1 -0
  66. package/build-ngc/core/scheduler.d.ts +13 -0
  67. package/build-ngc/core/scheduler.js +194 -0
  68. package/build-ngc/core/scheduler.js.map +1 -0
  69. package/build-ngc/core/tokens.d.ts +30 -0
  70. package/build-ngc/core/tokens.js +193 -0
  71. package/build-ngc/core/tokens.js.map +1 -0
  72. package/build-ngc/core/types.d.ts +633 -0
  73. package/build-ngc/core/types.js +117 -0
  74. package/build-ngc/core/types.js.map +1 -0
  75. package/build-ngc/core/utils.d.ts +6 -0
  76. package/build-ngc/core/utils.js +54 -0
  77. package/build-ngc/core/utils.js.map +1 -0
  78. package/native-link.json +88 -0
  79. package/package.json +150 -0
  80. package/src/angular/index.ts +1 -0
  81. package/src/core/background-task.ts +32 -0
  82. package/src/core/badge.ts +26 -0
  83. package/src/core/categories.ts +60 -0
  84. package/src/core/channels.ts +183 -0
  85. package/src/core/emitter.ts +95 -0
  86. package/src/core/handler.ts +95 -0
  87. package/src/core/index.ts +144 -0
  88. package/src/core/native-modules.ts +209 -0
  89. package/src/core/permissions.ts +46 -0
  90. package/src/core/presenter.ts +45 -0
  91. package/src/core/scheduler.ts +265 -0
  92. package/src/core/tokens.ts +272 -0
  93. package/src/core/types.ts +767 -0
  94. package/src/core/utils.ts +82 -0
@@ -0,0 +1,82 @@
1
+ // Ported from expo-notifications @ sdk-57's utils/mapNotificationResponse.ts and
2
+ // hasValidTriggerObject.ts.
3
+ //
4
+ // ponytail: upstream's `warnOfExpoGoPushUsage` (warnOfExpoGoPushUsage.ts) checks
5
+ // `isRunningInExpoGo()` from the `expo` meta-package, which this project never depends on and
6
+ // never runs under (own Metro pipeline, dev-build only — see the `symbiote-expo-native-module`
7
+ // skill) — not ported, there is no Expo Go to warn about here.
8
+ import type {
9
+ INotification,
10
+ INotificationContent,
11
+ INotificationRequest,
12
+ INotificationResponse,
13
+ } from './types';
14
+
15
+ export function hasValidTriggerObject(trigger: unknown): boolean {
16
+ if (trigger === null) return true;
17
+ if (typeof trigger !== 'object') return false;
18
+ return 'type' in trigger || 'channelId' in trigger;
19
+ }
20
+
21
+ let warnedAboutDataString = false;
22
+
23
+ // Native hands over a raw payload that may carry a legacy `dataString` field this package's own
24
+ // `INotificationContent` type does not declare — the one narrowing boundary for that dynamic
25
+ // extra field lives here, not scattered across call sites.
26
+ function readLegacyDataString(
27
+ content: INotificationContent,
28
+ ): string | undefined {
29
+ const record: Record<string, unknown> = content;
30
+ const dataString = record.dataString;
31
+ return typeof dataString === 'string' ? dataString : undefined;
32
+ }
33
+
34
+ export function mapNotificationContent(
35
+ content: INotificationContent,
36
+ ): INotificationContent {
37
+ try {
38
+ const dataString = readLegacyDataString(content);
39
+ if (typeof dataString === 'string') {
40
+ const mapped: INotificationContent & { dataString?: string } = {
41
+ ...content,
42
+ };
43
+ mapped.data = JSON.parse(dataString);
44
+ Object.defineProperty(mapped, 'dataString', {
45
+ get() {
46
+ if (!warnedAboutDataString) {
47
+ warnedAboutDataString = true;
48
+ console.warn(
49
+ '[notifications] reading dataString is deprecated, use data instead',
50
+ );
51
+ }
52
+ return dataString;
53
+ },
54
+ });
55
+ return mapped;
56
+ }
57
+ } catch (error) {
58
+ console.error(
59
+ `[notifications] Error parsing notification content: ${error}`,
60
+ );
61
+ }
62
+ return content;
63
+ }
64
+
65
+ export function mapNotificationRequest(
66
+ request: INotificationRequest,
67
+ ): INotificationRequest {
68
+ return { ...request, content: mapNotificationContent(request.content) };
69
+ }
70
+
71
+ export function mapNotification(notification: INotification): INotification {
72
+ return {
73
+ ...notification,
74
+ request: mapNotificationRequest(notification.request),
75
+ };
76
+ }
77
+
78
+ export function mapNotificationResponse(
79
+ response: INotificationResponse,
80
+ ): INotificationResponse {
81
+ return { ...response, notification: mapNotification(response.notification) };
82
+ }