XuqmGroup-RNSDK/packages/push/src/PushSDK.ts

43 行
1.3 KiB
TypeScript

import { apiRequest, getConfig, getDeviceInfo } from '@xuqm/rn-common'
import type { PushVendor } from '@xuqm/rn-common'
export type { PushVendor }
export const PushSDK = {
/**
* Register a push device token for the given user.
* If vendor is omitted, it is auto-detected from the device brand.
*
* @param userId - The logged-in user's ID
* @param token - The device push token from the vendor SDK
* @param vendor - Optional; auto-detected when not provided
*/
async registerToken(userId: string, token: string, vendor?: PushVendor): Promise<void> {
const config = getConfig()
const device = await getDeviceInfo()
await apiRequest('/api/push/register', {
method: 'POST',
params: {
appId: config.appId,
userId,
vendor: vendor ?? device.pushVendor,
token,
platform: device.platform,
deviceId: device.deviceId,
brand: device.brand,
model: device.model,
osVersion: device.osVersion,
},
})
},
async unregisterToken(userId: string): Promise<void> {
const config = getConfig()
const { deviceId } = await getDeviceInfo()
await apiRequest('/api/push/unregister', {
method: 'DELETE',
params: { appId: config.appId, userId, deviceId },
})
},
}