@codixus/client 0.1.7 → 0.1.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/dist/push-expo/index.cjs
CHANGED
|
@@ -35,6 +35,16 @@ __export(push_expo_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(push_expo_exports);
|
|
36
36
|
var Notifications = __toESM(require("expo-notifications"), 1);
|
|
37
37
|
var import_react_native = require("react-native");
|
|
38
|
+
var ANDROID_CHANNEL_ID = "default";
|
|
39
|
+
async function ensureAndroidChannel(platform) {
|
|
40
|
+
if (platform !== "android") {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await Notifications.setNotificationChannelAsync(ANDROID_CHANNEL_ID, {
|
|
44
|
+
name: ANDROID_CHANNEL_ID,
|
|
45
|
+
importance: Notifications.AndroidImportance.MAX
|
|
46
|
+
});
|
|
47
|
+
}
|
|
38
48
|
function resolvePlatform() {
|
|
39
49
|
if (import_react_native.Platform.OS === "ios" || import_react_native.Platform.OS === "android") {
|
|
40
50
|
return import_react_native.Platform.OS;
|
|
@@ -79,10 +89,12 @@ function createExpoAdapter(opts) {
|
|
|
79
89
|
return mapPermissionStatus(status);
|
|
80
90
|
},
|
|
81
91
|
async requestPermission() {
|
|
92
|
+
await ensureAndroidChannel(platform);
|
|
82
93
|
const { status } = await Notifications.requestPermissionsAsync();
|
|
83
94
|
return status === "granted";
|
|
84
95
|
},
|
|
85
96
|
async getToken() {
|
|
97
|
+
await ensureAndroidChannel(platform);
|
|
86
98
|
const permission = await this.getPermissionStatus();
|
|
87
99
|
if (permission !== "granted") {
|
|
88
100
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/push-expo/index.ts"],"sourcesContent":["import * as Notifications from \"expo-notifications\";\nimport { Platform } from \"react-native\";\nimport type { PushAdapter, PushAdapterToken } from \"../push/types.js\";\n\nexport type { PushAdapter, PushAdapterToken } from \"../push/types.js\";\n\ntype PlatformOS = \"ios\" | \"android\";\n\nfunction resolvePlatform(): PlatformOS | null {\n if (Platform.OS === \"ios\" || Platform.OS === \"android\") {\n return Platform.OS;\n }\n return null;\n}\n\nfunction flattenPayload(\n notification: Notifications.Notification,\n): Record<string, unknown> {\n const data = notification.request.content.data;\n if (data && typeof data === \"object\" && !Array.isArray(data)) {\n return { ...(data as Record<string, unknown>) };\n }\n return {};\n}\n\nfunction mapPermissionStatus(\n status: string,\n): \"granted\" | \"denied\" | \"undetermined\" {\n if (status === \"granted\") {\n return \"granted\";\n }\n if (status === \"denied\") {\n return \"denied\";\n }\n return \"undetermined\";\n}\n\nconst noopUnsubscribe = (): void => {};\n\nfunction createNoopAdapter(): PushAdapter {\n return {\n getPermissionStatus: async () => \"denied\",\n requestPermission: async () => false,\n getToken: async () => null,\n addNotificationReceivedListener: () => noopUnsubscribe,\n addNotificationOpenedListener: () => noopUnsubscribe,\n };\n}\n\nexport function createExpoAdapter(opts: { projectId: string }): PushAdapter {\n const platform = resolvePlatform();\n if (!platform) {\n return createNoopAdapter();\n }\n\n return {\n async getPermissionStatus() {\n const { status } = await Notifications.getPermissionsAsync();\n return mapPermissionStatus(status);\n },\n\n async requestPermission() {\n const { status } = await Notifications.requestPermissionsAsync();\n return status === \"granted\";\n },\n\n async getToken(): Promise<PushAdapterToken | null> {\n const permission = await this.getPermissionStatus();\n if (permission !== \"granted\") {\n return null;\n }\n\n try {\n const result = await Notifications.getExpoPushTokenAsync({\n projectId: opts.projectId,\n });\n return {\n token: result.data,\n provider: \"expo\",\n platform,\n };\n } catch {\n return null;\n }\n },\n\n addNotificationReceivedListener(handler) {\n const subscription = Notifications.addNotificationReceivedListener(\n (notification) => {\n handler(flattenPayload(notification));\n },\n );\n return () => subscription.remove();\n },\n\n addNotificationOpenedListener(handler) {\n const subscription =\n Notifications.addNotificationResponseReceivedListener((response) => {\n handler(flattenPayload(response.notification));\n });\n return () => subscription.remove();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;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sB;AAAA,UACvD,WAAW,KAAK;AAAA,QAClB,CAAC;AACD,eAAO;AAAA,UACL,OAAO,OAAO;AAAA,UACd,UAAU;AAAA,UACV;AAAA,QACF;AAAA,MACF,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,gCAAgC,SAAS;AACvC,YAAM,eAA6B;AAAA,QACjC,CAAC,iBAAiB;AAChB,kBAAQ,eAAe,YAAY,CAAC;AAAA,QACtC;AAAA,MACF;AACA,aAAO,MAAM,aAAa,OAAO;AAAA,IACnC;AAAA,IAEA,8BAA8B,SAAS;AACrC,YAAM,eACU,sDAAwC,CAAC,aAAa;AAClE,gBAAQ,eAAe,SAAS,YAAY,CAAC;AAAA,MAC/C,CAAC;AACH,aAAO,MAAM,aAAa,OAAO;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/push-expo/index.ts"],"sourcesContent":["import * as Notifications from \"expo-notifications\";\nimport { Platform } from \"react-native\";\nimport type { PushAdapter, PushAdapterToken } from \"../push/types.js\";\n\nexport type { PushAdapter, PushAdapterToken } from \"../push/types.js\";\n\ntype PlatformOS = \"ios\" | \"android\";\n\nconst ANDROID_CHANNEL_ID = \"default\";\n\nasync function ensureAndroidChannel(platform: PlatformOS): Promise<void> {\n if (platform !== \"android\") {\n return;\n }\n\n await Notifications.setNotificationChannelAsync(ANDROID_CHANNEL_ID, {\n name: ANDROID_CHANNEL_ID,\n importance: Notifications.AndroidImportance.MAX,\n });\n}\n\nfunction resolvePlatform(): PlatformOS | null {\n if (Platform.OS === \"ios\" || Platform.OS === \"android\") {\n return Platform.OS;\n }\n return null;\n}\n\nfunction flattenPayload(\n notification: Notifications.Notification,\n): Record<string, unknown> {\n const data = notification.request.content.data;\n if (data && typeof data === \"object\" && !Array.isArray(data)) {\n return { ...(data as Record<string, unknown>) };\n }\n return {};\n}\n\nfunction mapPermissionStatus(\n status: string,\n): \"granted\" | \"denied\" | \"undetermined\" {\n if (status === \"granted\") {\n return \"granted\";\n }\n if (status === \"denied\") {\n return \"denied\";\n }\n return \"undetermined\";\n}\n\nconst noopUnsubscribe = (): void => {};\n\nfunction createNoopAdapter(): PushAdapter {\n return {\n getPermissionStatus: async () => \"denied\",\n requestPermission: async () => false,\n getToken: async () => null,\n addNotificationReceivedListener: () => noopUnsubscribe,\n addNotificationOpenedListener: () => noopUnsubscribe,\n };\n}\n\nexport function createExpoAdapter(opts: { projectId: string }): PushAdapter {\n const platform = resolvePlatform();\n if (!platform) {\n return createNoopAdapter();\n }\n\n return {\n async getPermissionStatus() {\n const { status } = await Notifications.getPermissionsAsync();\n return mapPermissionStatus(status);\n },\n\n async requestPermission() {\n await ensureAndroidChannel(platform);\n const { status } = await Notifications.requestPermissionsAsync();\n return status === \"granted\";\n },\n\n async getToken(): Promise<PushAdapterToken | null> {\n await ensureAndroidChannel(platform);\n const permission = await this.getPermissionStatus();\n if (permission !== \"granted\") {\n return null;\n }\n\n try {\n const result = await Notifications.getExpoPushTokenAsync({\n projectId: opts.projectId,\n });\n return {\n token: result.data,\n provider: \"expo\",\n platform,\n };\n } catch {\n return null;\n }\n },\n\n addNotificationReceivedListener(handler) {\n const subscription = Notifications.addNotificationReceivedListener(\n (notification) => {\n handler(flattenPayload(notification));\n },\n );\n return () => subscription.remove();\n },\n\n addNotificationOpenedListener(handler) {\n const subscription =\n Notifications.addNotificationResponseReceivedListener((response) => {\n handler(flattenPayload(response.notification));\n });\n return () => subscription.remove();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B;AAC/B,0BAAyB;AAOzB,IAAM,qBAAqB;AAE3B,eAAe,qBAAqB,UAAqC;AACvE,MAAI,aAAa,WAAW;AAC1B;AAAA,EACF;AAEA,QAAoB,0CAA4B,oBAAoB;AAAA,IAClE,MAAM;AAAA,IACN,YAA0B,gCAAkB;AAAA,EAC9C,CAAC;AACH;AAEA,S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A,QAClB,CAAC;AACD,eAAO;AAAA,UACL,OAAO,OAAO;AAAA,UACd,UAAU;AAAA,UACV;AAAA,QACF;AAAA,MACF,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,gCAAgC,SAAS;AACvC,YAAM,eAA6B;AAAA,QACjC,CAAC,iBAAiB;AAChB,kBAAQ,eAAe,YAAY,CAAC;AAAA,QACtC;AAAA,MACF;AACA,aAAO,MAAM,aAAa,OAAO;AAAA,IACnC;AAAA,IAEA,8BAA8B,SAAS;AACrC,YAAM,eACU,sDAAwC,CAAC,aAAa;AAClE,gBAAQ,eAAe,SAAS,YAAY,CAAC;AAAA,MAC/C,CAAC;AACH,aAAO,MAAM,aAAa,OAAO;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
|
package/dist/push-expo/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// src/push-expo/index.ts
|
|
2
2
|
import * as Notifications from "expo-notifications";
|
|
3
3
|
import { Platform } from "react-native";
|
|
4
|
+
var ANDROID_CHANNEL_ID = "default";
|
|
5
|
+
async function ensureAndroidChannel(platform) {
|
|
6
|
+
if (platform !== "android") {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
await Notifications.setNotificationChannelAsync(ANDROID_CHANNEL_ID, {
|
|
10
|
+
name: ANDROID_CHANNEL_ID,
|
|
11
|
+
importance: Notifications.AndroidImportance.MAX
|
|
12
|
+
});
|
|
13
|
+
}
|
|
4
14
|
function resolvePlatform() {
|
|
5
15
|
if (Platform.OS === "ios" || Platform.OS === "android") {
|
|
6
16
|
return Platform.OS;
|
|
@@ -45,10 +55,12 @@ function createExpoAdapter(opts) {
|
|
|
45
55
|
return mapPermissionStatus(status);
|
|
46
56
|
},
|
|
47
57
|
async requestPermission() {
|
|
58
|
+
await ensureAndroidChannel(platform);
|
|
48
59
|
const { status } = await Notifications.requestPermissionsAsync();
|
|
49
60
|
return status === "granted";
|
|
50
61
|
},
|
|
51
62
|
async getToken() {
|
|
63
|
+
await ensureAndroidChannel(platform);
|
|
52
64
|
const permission = await this.getPermissionStatus();
|
|
53
65
|
if (permission !== "granted") {
|
|
54
66
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/push-expo/index.ts"],"sourcesContent":["import * as Notifications from \"expo-notifications\";\nimport { Platform } from \"react-native\";\nimport type { PushAdapter, PushAdapterToken } from \"../push/types.js\";\n\nexport type { PushAdapter, PushAdapterToken } from \"../push/types.js\";\n\ntype PlatformOS = \"ios\" | \"android\";\n\nfunction resolvePlatform(): PlatformOS | null {\n if (Platform.OS === \"ios\" || Platform.OS === \"android\") {\n return Platform.OS;\n }\n return null;\n}\n\nfunction flattenPayload(\n notification: Notifications.Notification,\n): Record<string, unknown> {\n const data = notification.request.content.data;\n if (data && typeof data === \"object\" && !Array.isArray(data)) {\n return { ...(data as Record<string, unknown>) };\n }\n return {};\n}\n\nfunction mapPermissionStatus(\n status: string,\n): \"granted\" | \"denied\" | \"undetermined\" {\n if (status === \"granted\") {\n return \"granted\";\n }\n if (status === \"denied\") {\n return \"denied\";\n }\n return \"undetermined\";\n}\n\nconst noopUnsubscribe = (): void => {};\n\nfunction createNoopAdapter(): PushAdapter {\n return {\n getPermissionStatus: async () => \"denied\",\n requestPermission: async () => false,\n getToken: async () => null,\n addNotificationReceivedListener: () => noopUnsubscribe,\n addNotificationOpenedListener: () => noopUnsubscribe,\n };\n}\n\nexport function createExpoAdapter(opts: { projectId: string }): PushAdapter {\n const platform = resolvePlatform();\n if (!platform) {\n return createNoopAdapter();\n }\n\n return {\n async getPermissionStatus() {\n const { status } = await Notifications.getPermissionsAsync();\n return mapPermissionStatus(status);\n },\n\n async requestPermission() {\n const { status } = await Notifications.requestPermissionsAsync();\n return status === \"granted\";\n },\n\n async getToken(): Promise<PushAdapterToken | null> {\n const permission = await this.getPermissionStatus();\n if (permission !== \"granted\") {\n return null;\n }\n\n try {\n const result = await Notifications.getExpoPushTokenAsync({\n projectId: opts.projectId,\n });\n return {\n token: result.data,\n provider: \"expo\",\n platform,\n };\n } catch {\n return null;\n }\n },\n\n addNotificationReceivedListener(handler) {\n const subscription = Notifications.addNotificationReceivedListener(\n (notification) => {\n handler(flattenPayload(notification));\n },\n );\n return () => subscription.remove();\n },\n\n addNotificationOpenedListener(handler) {\n const subscription =\n Notifications.addNotificationResponseReceivedListener((response) => {\n handler(flattenPayload(response.notification));\n });\n return () => subscription.remove();\n },\n };\n}\n"],"mappings":";AAAA,YAAY,mBAAmB;AAC/B,SAAS,gBAAgB;AAOzB,SAAS,kBAAqC;AAC5C,MAAI,SAAS,OAAO,SAAS,SAAS,OAAO,WAAW;AACtD,WAAO,SAAS;AAAA,EAClB;AACA,SAAO;AACT;AAEA,SAAS,eACP,cACyB;AACzB,QAAM,OAAO,aAAa,QAAQ,QAAQ;AAC1C,MAAI,QAAQ,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI,GAAG;AAC5D,WAAO,EAAE,GAAI,KAAiC;AAAA,EAChD;AACA,SAAO,CAAC;AACV;AAEA,SAAS,oBACP,QACuC;AACvC,MAAI,WAAW,WAAW;AACxB,WAAO;AAAA,EACT;AACA,MAAI,WAAW,UAAU;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,IAAM,kBAAkB,MAAY;AAAC;AAErC,SAAS,oBAAiC;AACxC,SAAO;AAAA,IACL,qBAAqB,YAAY;AAAA,IACjC,mBAAmB,YAAY;AAAA,IAC/B,UAAU,YAAY;AAAA,IACtB,iCAAiC,MAAM;AAAA,IACvC,+BAA+B,MAAM;AAAA,EACvC;AACF;AAEO,SAAS,kBAAkB,MAA0C;AAC1E,QAAM,WAAW,gBAAgB;AACjC,MAAI,CAAC,UAAU;AACb,WAAO,kBAAkB;AAAA,EAC3B;AAEA,SAAO;AAAA,IACL,MAAM,sBAAsB;AAC1B,YAAM,EAAE,OAAO,IAAI,MAAoB,kCAAoB;AAC3D,aAAO,oBAAoB,MAAM;AAAA,IACnC;AAAA,IAEA,MAAM,oBAAoB;AACxB,YAAM,EAAE,OAAO,IAAI,MAAoB,sCAAwB;AAC/D,aAAO,WAAW;AAAA,IACpB;AAAA,IAEA,MAAM,WAA6C;AACjD,YAAM,aAAa,MAAM,KAAK,oBAAoB;AAClD,UAAI,eAAe,WAAW;AAC5B,eAAO;AAAA,MACT;AAEA,UAAI;AACF,cAAM,SAAS,MAAoB,oCAAsB;AAAA,UACvD,WAAW,KAAK;AAAA,QAClB,CAAC;AACD,eAAO;AAAA,UACL,OAAO,OAAO;AAAA,UACd,UAAU;AAAA,UACV;AAAA,QACF;AAAA,MACF,QAAQ;AACN,eAAO;AAAA,MACT;AAAA,IACF;AAAA,IAEA,gCAAgC,SAAS;AACvC,YAAM,eAA6B;AAAA,QACjC,CAAC,iBAAiB;AAChB,kBAAQ,eAAe,YAAY,CAAC;AAAA,QACtC;AAAA,MACF;AACA,aAAO,MAAM,aAAa,OAAO;AAAA,IACnC;AAAA,IAEA,8BAA8B,SAAS;AACrC,YAAM,eACU,sDAAwC,CAAC,aAAa;AAClE,gBAAQ,eAAe,SAAS,YAAY,CAAC;AAAA,MAC/C,CAAC;AACH,aAAO,MAAM,aAAa,OAAO;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/push-expo/index.ts"],"sourcesContent":["import * as Notifications from \"expo-notifications\";\nimport { Platform } from \"react-native\";\nimport type { PushAdapter, PushAdapterToken } from \"../push/types.js\";\n\nexport type { PushAdapter, PushAdapterToken } from \"../push/types.js\";\n\ntype PlatformOS = \"ios\" | \"android\";\n\nconst ANDROID_CHANNEL_ID = \"default\";\n\nasync function ensureAndroidChannel(platform: PlatformOS): Promise<void> {\n if (platform !== \"android\") {\n return;\n }\n\n await Notifications.setNotificationChannelAsync(ANDROID_CHANNEL_ID, {\n name: ANDROID_CHANNEL_ID,\n importance: Notifications.AndroidImportance.MAX,\n });\n}\n\nfunction resolvePlatform(): PlatformOS | null {\n if (Platform.OS === \"ios\" || Platform.OS === \"android\") {\n return Platform.OS;\n }\n return null;\n}\n\nfunction flattenPayload(\n notification: Notifications.Notification,\n): Record<string, unknown> {\n const data = notification.request.content.data;\n if (data && typeof data === \"object\" && !Array.isArray(data)) {\n return { ...(data as Record<string, unknown>) };\n }\n return {};\n}\n\nfunction mapPermissionStatus(\n status: string,\n): \"granted\" | \"denied\" | \"undetermined\" {\n if (status === \"granted\") {\n return \"granted\";\n }\n if (status === \"denied\") {\n return \"denied\";\n }\n return \"undetermined\";\n}\n\nconst noopUnsubscribe = (): void => {};\n\nfunction createNoopAdapter(): PushAdapter {\n return {\n getPermissionStatus: async () => \"denied\",\n requestPermission: async () => false,\n getToken: async () => null,\n addNotificationReceivedListener: () => noopUnsubscribe,\n addNotificationOpenedListener: () => noopUnsubscribe,\n };\n}\n\nexport function createExpoAdapter(opts: { projectId: string }): PushAdapter {\n const platform = resolvePlatform();\n if (!platform) {\n return createNoopAdapter();\n }\n\n return {\n async getPermissionStatus() {\n const { status } = await Notifications.getPermissionsAsync();\n return mapPermissionStatus(status);\n },\n\n async requestPermission() {\n await ensureAndroidChannel(platform);\n const { status } = await Notifications.requestPermissionsAsync();\n return status === \"granted\";\n },\n\n async getToken(): Promise<PushAdapterToken | null> {\n await ensureAndroidChannel(platform);\n const permission = await this.getPermissionStatus();\n if (permission !== \"granted\") {\n return null;\n }\n\n try {\n const result = await Notifications.getExpoPushTokenAsync({\n projectId: opts.projectId,\n });\n return {\n token: result.data,\n provider: \"expo\",\n platform,\n };\n } catch {\n return null;\n }\n },\n\n addNotificationReceivedListener(handler) {\n const subscription = Notifications.addNotificationReceivedListener(\n (notification) => {\n handler(flattenPayload(notification));\n },\n );\n return () => subscription.remove();\n },\n\n addNotificationOpenedListener(handler) {\n const subscription =\n Notifications.addNotificationResponseReceivedListener((response) => {\n handler(flattenPayload(response.notification));\n });\n return () => subscription.remove();\n },\n };\n}\n"],"mappings":";AAAA,YAAY,mBAAmB;AAC/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