@leisuresaas/react-native 0.6.11 → 0.6.12-dev.2
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 +4 -0
- package/package.json +1 -1
- package/src/errors.ts +24 -0
- package/src/index.ts +9 -0
- package/src/types.ts +138 -0
package/README.md
CHANGED
|
@@ -58,6 +58,10 @@ Admin → Social login 必须配置,否则换产品会话失败。Publishable
|
|
|
58
58
|
|
|
59
59
|
注册页按 `getPublicAppConfig` 返回的 `consents` 画勾选框,勾选项传给 `register({ consents })`。登录后调 `getConsents`,`allRequiredAccepted` 为假时显示同意页,再 `submitConsents`。详见 [AGENTS.md](AGENTS.md) §2c。
|
|
60
60
|
|
|
61
|
+
## 商店优惠
|
|
62
|
+
|
|
63
|
+
`Offer`、`OfferList`、`ClaimOfferResult`、`SubscriptionOffer` 等类型和 `ErrorReason.Offer*` 用于读产品 BFF 透传的优惠(试用)结果,SDK 不调 billing。见 AGENTS.md 4e。
|
|
64
|
+
|
|
61
65
|
## Push(产品 BFF 登记)
|
|
62
66
|
|
|
63
67
|
```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leisuresaas/react-native",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.12-dev.2",
|
|
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/errors.ts
CHANGED
|
@@ -36,6 +36,30 @@ export const ErrorReason = {
|
|
|
36
36
|
FallbackPlanMissing: "FALLBACK_PLAN_MISSING",
|
|
37
37
|
WorkspaceHasMembers: "WORKSPACE_HAS_MEMBERS",
|
|
38
38
|
SubscriptionActiveOtherSource: "SUBSCRIPTION_ACTIVE_OTHER_SOURCE",
|
|
39
|
+
// Offers (R-1125-1), passed through by the product BFF from claim / checkout. The user or another
|
|
40
|
+
// workspace member already had a trial of the product / the workspace subscribed before / outside
|
|
41
|
+
// the audience / no mapping for this platform or app / iOS new user without apple_intro / plan not
|
|
42
|
+
// in the campaign / before or after the campaign dates / limit used up / no such offer / the
|
|
43
|
+
// redemption is already used or released.
|
|
44
|
+
OfferTrialAlreadyUsed: "OFFER_TRIAL_ALREADY_USED",
|
|
45
|
+
OfferPreviousSubscriber: "OFFER_PREVIOUS_SUBSCRIBER",
|
|
46
|
+
OfferNotEligible: "OFFER_NOT_ELIGIBLE",
|
|
47
|
+
OfferPlatformNotSupported: "OFFER_PLATFORM_NOT_SUPPORTED",
|
|
48
|
+
OfferAppleNewUserNotSupported: "OFFER_APPLE_NEW_USER_NOT_SUPPORTED",
|
|
49
|
+
OfferPlanNotApplicable: "OFFER_PLAN_NOT_APPLICABLE",
|
|
50
|
+
OfferNotStarted: "OFFER_NOT_STARTED",
|
|
51
|
+
OfferExpired: "OFFER_EXPIRED",
|
|
52
|
+
OfferLimitReached: "OFFER_LIMIT_REACHED",
|
|
53
|
+
OfferNotFound: "OFFER_NOT_FOUND",
|
|
54
|
+
OfferRedemptionNotHeld: "OFFER_REDEMPTION_NOT_HELD",
|
|
55
|
+
// Targeted offers (R-1125-1 P3): for current or former subscribers only (on ios an Apple
|
|
56
|
+
// promotional offer also needs an App Store subscription before) / for the campaign's audience list
|
|
57
|
+
// only / web offers are new purchases and the workspace has an active paid subscription.
|
|
58
|
+
OfferNotASubscriber: "OFFER_NOT_A_SUBSCRIBER",
|
|
59
|
+
OfferNotInList: "OFFER_NOT_IN_LIST",
|
|
60
|
+
OfferAlreadySubscribed: "OFFER_ALREADY_SUBSCRIBED",
|
|
61
|
+
// apple_intro claim: the product has no App Store In-App Purchase key.
|
|
62
|
+
StoreNotConfigured: "STORE_NOT_CONFIGURED",
|
|
39
63
|
// The token's workspace is no longer the user's active one: refresh the token, then retry.
|
|
40
64
|
ActiveWorkspaceChanged: "ACTIVE_WORKSPACE_CHANGED",
|
|
41
65
|
// Sessions: signed out because the user signed in on another device / a sign-in refused because
|
package/src/index.ts
CHANGED
|
@@ -218,13 +218,22 @@ export type {
|
|
|
218
218
|
AdFeedRotation,
|
|
219
219
|
AdFeedSource,
|
|
220
220
|
AdsFeedResponse,
|
|
221
|
+
ApplePromotionalSignature,
|
|
221
222
|
AuthConfig,
|
|
223
|
+
ClaimOfferResult,
|
|
222
224
|
EnablePushOptions,
|
|
223
225
|
Entitlement,
|
|
224
226
|
LeisureSaasAuthConfig,
|
|
225
227
|
MobilePlatform,
|
|
228
|
+
Offer,
|
|
229
|
+
OfferBenefit,
|
|
230
|
+
OfferCampaign,
|
|
231
|
+
OfferList,
|
|
232
|
+
OfferMethod,
|
|
233
|
+
OfferRedemption,
|
|
226
234
|
Plan,
|
|
227
235
|
RegisterDeviceTokenInput,
|
|
236
|
+
SubscriptionOffer,
|
|
228
237
|
SubscriptionStatus,
|
|
229
238
|
} from "./types";
|
|
230
239
|
|
package/src/types.ts
CHANGED
|
@@ -23,6 +23,144 @@ export type SubscriptionStatus = {
|
|
|
23
23
|
plan_version_id?: string;
|
|
24
24
|
billing_source?: string;
|
|
25
25
|
current_period_end_unix?: number;
|
|
26
|
+
cancel_at_period_end?: boolean;
|
|
27
|
+
price_id?: string;
|
|
28
|
+
/** The offer the subscription is under or came from (R-1125-1); absent when none. */
|
|
29
|
+
offer?: SubscriptionOffer;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Offer on a subscription. `phase` is `trial` or `intro` while it lasts and empty after conversion;
|
|
34
|
+
* `type` stays.
|
|
35
|
+
*/
|
|
36
|
+
export type SubscriptionOffer = {
|
|
37
|
+
type:
|
|
38
|
+
| "introductory"
|
|
39
|
+
| "promotional"
|
|
40
|
+
| "offer_code"
|
|
41
|
+
| "win_back"
|
|
42
|
+
| "offer"
|
|
43
|
+
| "promo_code"
|
|
44
|
+
| "platform_offer"
|
|
45
|
+
| "stripe_trial"
|
|
46
|
+
| "stripe_coupon";
|
|
47
|
+
id?: string;
|
|
48
|
+
phase?: "" | "trial" | "intro";
|
|
49
|
+
phase_ends_at_unix?: number;
|
|
50
|
+
/** Platform campaign; absent for a store offer the platform did not hand out. */
|
|
51
|
+
campaign_id?: string;
|
|
52
|
+
redemption_id?: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* How an offer is used: `platform_grant` / `stripe_trial` / `stripe_coupon` (web), `google_offer`
|
|
57
|
+
* (android: buy with the Play offer), `apple_intro` (ios: buy with `ios.intro_eligibility_jws`),
|
|
58
|
+
* `apple_promotional` (ios: buy with `ios.promotional_offer_id` + signature or JWS and
|
|
59
|
+
* `appAccountToken = account_token`).
|
|
60
|
+
*/
|
|
61
|
+
export type OfferMethod =
|
|
62
|
+
| "platform_grant"
|
|
63
|
+
| "stripe_trial"
|
|
64
|
+
| "stripe_coupon"
|
|
65
|
+
| "google_offer"
|
|
66
|
+
| "apple_intro"
|
|
67
|
+
| "apple_promotional";
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Classic Apple promotional offer signature (`ios.promotional_signature`), for
|
|
71
|
+
* `promotionalOffer(offerID:keyID:nonce:signature:timestamp:)`. Valid 24 hours, single use.
|
|
72
|
+
*/
|
|
73
|
+
export type ApplePromotionalSignature = {
|
|
74
|
+
key_id: string;
|
|
75
|
+
/** Lowercase UUID. */
|
|
76
|
+
nonce: string;
|
|
77
|
+
timestamp_ms: number;
|
|
78
|
+
/** Base64. */
|
|
79
|
+
signature: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type OfferBenefit = {
|
|
83
|
+
type: "free_days" | "percent_off" | "amount_off";
|
|
84
|
+
free_days?: number;
|
|
85
|
+
percent_off?: number;
|
|
86
|
+
amount_off_cents?: number;
|
|
87
|
+
currency?: string;
|
|
88
|
+
duration_periods?: number;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export type OfferCampaign = {
|
|
92
|
+
id: string;
|
|
93
|
+
name: string;
|
|
94
|
+
purpose: "trial" | "promotion";
|
|
95
|
+
benefit: OfferBenefit;
|
|
96
|
+
ends_at_unix?: number;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* An offer as the product BFF returns it from sdk/go `ListOffers` / `ClaimOffer` (Integration
|
|
101
|
+
* `GET /v1/billing/offers`, `POST /v1/billing/offers/claim`). The app never calls billing itself.
|
|
102
|
+
*/
|
|
103
|
+
export type Offer = {
|
|
104
|
+
/** Pass to the BFF's claim. */
|
|
105
|
+
offer_ref: string;
|
|
106
|
+
campaign: OfferCampaign;
|
|
107
|
+
/** Plans the offer applies to; empty = every paid plan. */
|
|
108
|
+
plan_ids: string[];
|
|
109
|
+
method: OfferMethod;
|
|
110
|
+
/** Set while the user holds this offer (until `held_until_unix`). */
|
|
111
|
+
redemption_id?: string | null;
|
|
112
|
+
held_until_unix?: number;
|
|
113
|
+
price_id?: string;
|
|
114
|
+
android?: { package_name?: string; store_product_id: string; base_plan_id: string; offer_id: string };
|
|
115
|
+
/** `intro_eligibility_jws`, `promotional_signature` and `promotional_offer_jws` are set on claims only. */
|
|
116
|
+
ios?: {
|
|
117
|
+
bundle_id?: string;
|
|
118
|
+
store_product_id: string;
|
|
119
|
+
intro_eligibility_jws?: string;
|
|
120
|
+
/** apple_promotional: the promotional offer identifier in App Store Connect. */
|
|
121
|
+
promotional_offer_id?: string;
|
|
122
|
+
promotional_signature?: ApplePromotionalSignature;
|
|
123
|
+
/** apple_promotional: for `promotionalOffer(_:compactJWS:)`. */
|
|
124
|
+
promotional_offer_jws?: string;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Claims on ios / android: the user's fixed account token for the product (lowercase UUID). Pass it
|
|
128
|
+
* as Apple `appAccountToken` / Google `obfuscatedAccountId` on every purchase.
|
|
129
|
+
*/
|
|
130
|
+
account_token?: string;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** `GET /v1/billing/offers` response. */
|
|
134
|
+
export type OfferList = {
|
|
135
|
+
offers: Offer[];
|
|
136
|
+
/** ios with `app_transaction_id` and no `apple_intro` offer: a "no trial" JWS per App Store product. */
|
|
137
|
+
apple_intro_ineligible?: { store_product_id: string; jws: string }[];
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export type OfferRedemption = {
|
|
141
|
+
id: string;
|
|
142
|
+
campaign_id?: string;
|
|
143
|
+
platform: "web" | "ios" | "android";
|
|
144
|
+
method: string;
|
|
145
|
+
purpose: "trial" | "promotion";
|
|
146
|
+
status: "held" | "used" | "released";
|
|
147
|
+
plan_id?: string;
|
|
148
|
+
price_id?: string;
|
|
149
|
+
held_until_unix?: number;
|
|
150
|
+
subscription_id?: string;
|
|
151
|
+
order_id?: string;
|
|
152
|
+
outcome?: "active" | "converted" | "expired" | "replaced";
|
|
153
|
+
release_reason?: "expired" | "user" | "replaced" | "checkout_expired" | "admin";
|
|
154
|
+
created_at_unix?: number;
|
|
155
|
+
used_at_unix?: number;
|
|
156
|
+
released_at_unix?: number;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/** `POST /v1/billing/offers/claim` response; `subscription` is set for `platform_grant`. */
|
|
160
|
+
export type ClaimOfferResult = {
|
|
161
|
+
redemption: OfferRedemption;
|
|
162
|
+
offer: Offer;
|
|
163
|
+
subscription?: SubscriptionStatus;
|
|
26
164
|
};
|
|
27
165
|
|
|
28
166
|
export type Entitlement = {
|