@codixus/client 0.1.4 → 0.1.6
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/index.cjs +161 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -2
- package/dist/index.d.ts +40 -2
- package/dist/index.js +161 -37
- package/dist/index.js.map +1 -1
- package/dist/push-expo/index.cjs +123 -0
- package/dist/push-expo/index.cjs.map +1 -0
- package/dist/push-expo/index.d.cts +8 -0
- package/dist/push-expo/index.d.ts +8 -0
- package/dist/push-expo/index.js +88 -0
- package/dist/push-expo/index.js.map +1 -0
- package/dist/react/index.d.cts +3 -2
- package/dist/react/index.d.ts +3 -2
- package/dist/types-maS8y9s9.d.cts +14 -0
- package/dist/types-maS8y9s9.d.ts +14 -0
- package/package.json +15 -4
|
@@ -0,0 +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;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 +1,9 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { CodixusClient, AuthState, SignInParams } from '../index.cjs';
|
|
4
4
|
import '@codixus/shared';
|
|
5
5
|
import 'axios';
|
|
6
|
+
import '../types-maS8y9s9.cjs';
|
|
6
7
|
|
|
7
8
|
interface CodixusContextValue {
|
|
8
9
|
client: CodixusClient;
|
|
@@ -18,7 +19,7 @@ interface CodixusContextValue {
|
|
|
18
19
|
declare function CodixusProvider({ client, children, }: {
|
|
19
20
|
client: CodixusClient;
|
|
20
21
|
children: ReactNode;
|
|
21
|
-
}):
|
|
22
|
+
}): react.JSX.Element;
|
|
22
23
|
declare function useCodixus(): CodixusContextValue;
|
|
23
24
|
declare function useAuth(): AuthState & {
|
|
24
25
|
signIn: (params: SignInParams) => Promise<{
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { CodixusClient, AuthState, SignInParams } from '../index.js';
|
|
4
4
|
import '@codixus/shared';
|
|
5
5
|
import 'axios';
|
|
6
|
+
import '../types-maS8y9s9.js';
|
|
6
7
|
|
|
7
8
|
interface CodixusContextValue {
|
|
8
9
|
client: CodixusClient;
|
|
@@ -18,7 +19,7 @@ interface CodixusContextValue {
|
|
|
18
19
|
declare function CodixusProvider({ client, children, }: {
|
|
19
20
|
client: CodixusClient;
|
|
20
21
|
children: ReactNode;
|
|
21
|
-
}):
|
|
22
|
+
}): react.JSX.Element;
|
|
22
23
|
declare function useCodixus(): CodixusContextValue;
|
|
23
24
|
declare function useAuth(): AuthState & {
|
|
24
25
|
signIn: (params: SignInParams) => Promise<{
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type PushAdapterToken = {
|
|
2
|
+
token: string;
|
|
3
|
+
provider: "expo" | "fcm" | "apns";
|
|
4
|
+
platform: "ios" | "android";
|
|
5
|
+
};
|
|
6
|
+
interface PushAdapter {
|
|
7
|
+
getPermissionStatus(): Promise<"granted" | "denied" | "undetermined">;
|
|
8
|
+
requestPermission(): Promise<boolean>;
|
|
9
|
+
getToken(): Promise<PushAdapterToken | null>;
|
|
10
|
+
addNotificationReceivedListener(handler: (payload: Record<string, unknown>) => void): () => void;
|
|
11
|
+
addNotificationOpenedListener(handler: (payload: Record<string, unknown>) => void): () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type { PushAdapter as P, PushAdapterToken as a };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type PushAdapterToken = {
|
|
2
|
+
token: string;
|
|
3
|
+
provider: "expo" | "fcm" | "apns";
|
|
4
|
+
platform: "ios" | "android";
|
|
5
|
+
};
|
|
6
|
+
interface PushAdapter {
|
|
7
|
+
getPermissionStatus(): Promise<"granted" | "denied" | "undetermined">;
|
|
8
|
+
requestPermission(): Promise<boolean>;
|
|
9
|
+
getToken(): Promise<PushAdapterToken | null>;
|
|
10
|
+
addNotificationReceivedListener(handler: (payload: Record<string, unknown>) => void): () => void;
|
|
11
|
+
addNotificationOpenedListener(handler: (payload: Record<string, unknown>) => void): () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type { PushAdapter as P, PushAdapterToken as a };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codixus/client",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Client SDK for React Native and web
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "Client SDK for React Native and web: auth, API client, typed collections",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
@@ -17,6 +17,11 @@
|
|
|
17
17
|
"types": "./dist/react/index.d.ts",
|
|
18
18
|
"import": "./dist/react/index.js",
|
|
19
19
|
"require": "./dist/react/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./push-expo": {
|
|
22
|
+
"types": "./dist/push-expo/index.d.ts",
|
|
23
|
+
"import": "./dist/push-expo/index.js",
|
|
24
|
+
"require": "./dist/push-expo/index.cjs"
|
|
20
25
|
}
|
|
21
26
|
},
|
|
22
27
|
"files": ["dist", "LICENSE"],
|
|
@@ -34,11 +39,17 @@
|
|
|
34
39
|
"clean": "rm -rf dist"
|
|
35
40
|
},
|
|
36
41
|
"dependencies": {
|
|
37
|
-
"@codixus/shared": "
|
|
42
|
+
"@codixus/shared": "workspace:*",
|
|
38
43
|
"axios": "^1.7.0"
|
|
39
44
|
},
|
|
40
45
|
"peerDependencies": {
|
|
41
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
46
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
47
|
+
"expo-notifications": "*"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"expo-notifications": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
42
53
|
},
|
|
43
54
|
"devDependencies": {
|
|
44
55
|
"@types/react": "^19",
|