@leisuresaas/react-native 0.6.13-dev.1 → 0.6.14-dev.1

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
@@ -80,6 +80,8 @@ await apiFetch(accessToken, "/v1/notifications/device-tokens", {
80
80
 
81
81
  需 Dev Client / Store build(不要 Expo Go)。
82
82
 
83
+ iOS 的 `environment`(APNs 环境)强烈建议带(平台不带时按 `production`,Xcode 调试包会收不到推送),SDK 按顺序取:`buildEnablePushRegistration({ environment })` → 描述文件的 `aps-environment`(经 `expo-application`,Xcode 调试包 `development`,Ad Hoc 包 `production`)→ 没有描述文件时 App Store / TestFlight 安装为 `production`、模拟器为 `development`。都取不到时抛错,请安装 `expo-application` 或显式传入。Android 不带 `environment`。
84
+
83
85
  ## 环境变量
84
86
 
85
87
  | Variable | Use |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leisuresaas/react-native",
3
- "version": "0.6.13-dev.1",
3
+ "version": "0.6.14-dev.1",
4
4
  "description": "React Native SDK for LeisureSaas: OAuth, Public Ads/App Config, Drive User Plane (publishable keys). Frontend-only — no Integration Key.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/index.ts CHANGED
@@ -200,8 +200,9 @@ export {
200
200
  refreshOAuthTokens,
201
201
  } from "./auth-session";
202
202
  export type { OAuthTokenResponse } from "./auth-session";
203
- export { buildEnablePushRegistration, fetchNativeDevicePushToken } from "./push";
204
- export { devAppleSignedTransaction, devDeviceToken, devGooglePurchaseToken } from "./dev";
203
+ export { buildEnablePushRegistration, fetchNativeDevicePushToken, resolvePushEnvironment } from "./push";
204
+ export { resolveIosPushEnvironment, IosReleaseType } from "./push-environment";
205
+ export type { PushEnvironment, IosPushProbe } from "./push-environment";
205
206
  export {
206
207
  PlatformError,
207
208
  LeisureSaasHttpError,
@@ -0,0 +1,49 @@
1
+ /** APNs environment of a device token. */
2
+ export type PushEnvironment = "development" | "production";
3
+
4
+ /** What expo-application reports on iOS (`getIosPushNotificationServiceEnvironmentAsync`,
5
+ * `getIosApplicationReleaseTypeAsync`). `releaseType` uses expo's `ApplicationReleaseType` numbers. */
6
+ export type IosPushProbe = {
7
+ /** `aps-environment` from the embedded provisioning profile; null when there is no profile
8
+ * (App Store / TestFlight installs, simulator) or no push entitlement. */
9
+ apsEnvironment: string | null | undefined;
10
+ releaseType: number | null | undefined;
11
+ };
12
+
13
+ /** expo-application `ApplicationReleaseType`. */
14
+ export const IosReleaseType = { Unknown: 0, Simulator: 1, Enterprise: 2, Development: 3, AdHoc: 4, AppStore: 5 } as const;
15
+
16
+ /**
17
+ * Decides the APNs environment without guessing from `__DEV__` (a Release scheme can still be
18
+ * signed with a development profile). Order: explicit value → the profile's `aps-environment` →
19
+ * no profile on a device means an App Store / TestFlight install (production), simulator means
20
+ * development. Anything else throws: the caller must pass `environment`.
21
+ */
22
+ export function resolveIosPushEnvironment(explicit: string | undefined, probe: IosPushProbe | null): PushEnvironment {
23
+ const fromExplicit = normalize(explicit);
24
+ if (fromExplicit) return fromExplicit;
25
+ if (explicit?.trim()) {
26
+ throw new Error(`push environment "${explicit}" is not supported; use "development" or "production"`);
27
+ }
28
+
29
+ const fromProfile = normalize(probe?.apsEnvironment ?? undefined);
30
+ if (fromProfile) return fromProfile;
31
+ if (probe?.releaseType === IosReleaseType.AppStore) return "production";
32
+ if (probe?.releaseType === IosReleaseType.Simulator) return "development";
33
+
34
+ throw new Error(
35
+ "cannot determine the APNs environment (install expo-application, or pass environment: " +
36
+ '"development" for Xcode debug builds, "production" for TestFlight and App Store)',
37
+ );
38
+ }
39
+
40
+ function normalize(value: string | undefined): PushEnvironment | undefined {
41
+ switch (value?.trim().toLowerCase()) {
42
+ case "development":
43
+ return "development";
44
+ case "production":
45
+ return "production";
46
+ default:
47
+ return undefined;
48
+ }
49
+ }
package/src/push.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { appBundleId } from "./ads/bundle-id";
2
2
  import { mobilePlatform } from "./platform";
3
+ import { resolveIosPushEnvironment, type IosPushProbe, type PushEnvironment } from "./push-environment";
3
4
  import type { EnablePushOptions, MobilePlatform, RegisterDeviceTokenInput } from "./types";
4
5
 
5
6
  type ExpoNotificationsModule = {
@@ -36,11 +37,30 @@ function resolveBundleId(opts?: EnablePushOptions): string | undefined {
36
37
  return appBundleId() || undefined;
37
38
  }
38
39
 
39
- function resolveEnvironment(opts?: EnablePushOptions): "development" | "production" {
40
- if (opts?.environment === "development" || opts?.environment === "production") {
41
- return opts.environment;
40
+ type ExpoApplicationPush = {
41
+ getIosPushNotificationServiceEnvironmentAsync?: () => Promise<string | null>;
42
+ getIosApplicationReleaseTypeAsync?: () => Promise<number>;
43
+ };
44
+
45
+ /** Reads the provisioning profile through expo-application; null when it is not installed. */
46
+ async function probeIosPush(): Promise<IosPushProbe | null> {
47
+ let Application: ExpoApplicationPush;
48
+ try {
49
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
50
+ Application = require("expo-application") as ExpoApplicationPush;
51
+ } catch {
52
+ return null;
42
53
  }
43
- return typeof __DEV__ !== "undefined" && __DEV__ ? "development" : "production";
54
+ const apsEnvironment = await Application.getIosPushNotificationServiceEnvironmentAsync?.().catch(() => null);
55
+ const releaseType = await Application.getIosApplicationReleaseTypeAsync?.().catch(() => null);
56
+ return { apsEnvironment, releaseType };
57
+ }
58
+
59
+ /** The APNs environment of this build; throws when it cannot be determined (see `resolveIosPushEnvironment`). */
60
+ export async function resolvePushEnvironment(opts?: EnablePushOptions): Promise<PushEnvironment> {
61
+ const explicit = opts?.environment;
62
+ if (explicit) return resolveIosPushEnvironment(explicit, null);
63
+ return resolveIosPushEnvironment(undefined, await probeIosPush());
44
64
  }
45
65
 
46
66
  /** Read native FCM/APNs device token (not Expo Push Token). */
@@ -60,8 +80,11 @@ export async function fetchNativeDevicePushToken(): Promise<string> {
60
80
  }
61
81
 
62
82
  /**
63
- * Request permission and build the body for product BFF
64
- * `POST /v1/notifications/device-tokens` (path is product-defined).
83
+ * Request permission and build the body for product BFF.
84
+ * iOS: `environment` comes from the provisioning profile's `aps-environment` (via expo-application);
85
+ * App Store / TestFlight installs are production, the simulator development. When it cannot be
86
+ * determined the call throws and the caller must pass `opts.environment`. Android sends none.
87
+ * The BFF forwards it to `POST /v1/notifications/device-tokens` (its own path is product-defined).
65
88
  * Does not call the network — App must POST via its own apiFetch.
66
89
  */
67
90
  export async function buildEnablePushRegistration(
@@ -75,15 +98,12 @@ export async function buildEnablePushRegistration(
75
98
 
76
99
  const token = await fetchNativeDevicePushToken();
77
100
  const platform: MobilePlatform = opts?.platform ?? mobilePlatform();
78
- const input: RegisterDeviceTokenInput = {
79
- platform,
80
- token,
81
- environment: resolveEnvironment(opts),
82
- };
101
+ const input: RegisterDeviceTokenInput = { platform, token };
83
102
  if (platform === "android") {
84
103
  input.androidPackage = resolveAndroidPackage(opts);
85
104
  } else {
86
105
  input.bundleId = resolveBundleId(opts);
106
+ input.environment = await resolvePushEnvironment(opts);
87
107
  }
88
108
  return input;
89
109
  }
package/src/types.ts CHANGED
@@ -265,6 +265,7 @@ export type RegisterDeviceTokenInput = {
265
265
  token: string;
266
266
  androidPackage?: string;
267
267
  bundleId?: string;
268
+ /** Always set for iOS (the platform treats a missing value as production); absent for Android. */
268
269
  environment?: "development" | "production";
269
270
  };
270
271
 
@@ -272,6 +273,7 @@ export type EnablePushOptions = {
272
273
  platform?: MobilePlatform;
273
274
  androidPackage?: string;
274
275
  bundleId?: string;
276
+ /** iOS APNs environment. Omit to read it from the provisioning profile (needs expo-application). */
275
277
  environment?: "development" | "production";
276
278
  };
277
279
 
package/src/dev.ts DELETED
@@ -1,16 +0,0 @@
1
- /** Dev-mode Apple signed_transaction for store.verification_mode=dev. */
2
- export function devAppleSignedTransaction(storeProductId: string, suffix?: string): string {
3
- const tx = suffix?.trim() || `expo-${Date.now()}`;
4
- return `dev:${storeProductId.trim()}:${tx}`;
5
- }
6
-
7
- /** Dev-mode Google purchase_token for store.verification_mode=dev. */
8
- export function devGooglePurchaseToken(suffix?: string): string {
9
- return `dev-token-${suffix?.trim() || Date.now()}`;
10
- }
11
-
12
- /** Dev-mode push device token for notification integration smoke tests. */
13
- export function devDeviceToken(platform: "ios" | "android", suffix?: string): string {
14
- const id = suffix?.trim() || String(Date.now());
15
- return `dev:${platform}:${id}`;
16
- }