@revenuecat/purchases-js 1.3.0 → 1.4.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.
@@ -911,227 +911,434 @@ export declare class Purchases {
911
911
  */
912
912
  getAppUserId(): string;
913
913
  /**
914
- * Change the current app user id. Returns the customer info for the new
915
- * user id.
916
- * @param newAppUserId - The user id to change to.
917
- */
918
- changeUser(newAppUserId: string): Promise<CustomerInfo>;
914
+ * Sets attributes for the current user. Attributes are useful for storing additional, structured information on a customer that can be used elsewhere in the system.
915
+ * For example, you could store your customer's email address or additional system identifiers through the applicable reserved attributes, or store arbitrary facts like onboarding survey responses, feature usage, or other dimensions as custom attributes.
916
+ *
917
+ * Note: Unlike our mobile SDKs, the web SDK does not cache or retry sending attributes if the request fails. If the request fails, the attributes will not be saved and you will need to retry the operation.
918
+ *
919
+ * @param attributes - A dictionary of attributes to set for the current user.
920
+ * @throws {@link PurchasesError} if there is an error while setting the attributes or if the customer doesn't exist.
921
+ */
922
+ setAttributes(attributes: {
923
+ [key: string | ReservedCustomerAttribute]: string | null;
924
+ }): Promise<void>;
925
+ /**
926
+ * Change the current app user id. Returns the customer info for the new
927
+ * user id.
928
+ * @param newAppUserId - The user id to change to.
929
+ */
930
+ changeUser(newAppUserId: string): Promise<CustomerInfo>;
931
+ /**
932
+ * @returns Whether the SDK is using a sandbox API Key.
933
+ */
934
+ isSandbox(): boolean;
935
+ /**
936
+ * @returns Whether the current user is anonymous.
937
+ */
938
+ isAnonymous(): boolean;
939
+ /**
940
+ * Closes the Purchases instance. You should never have to do this normally.
941
+ */
942
+ close(): void;
943
+ /**
944
+ * Generates an anonymous app user ID that follows RevenueCat's format.
945
+ * This can be used when you don't have a user identifier system in place.
946
+ * The generated ID will be in the format: $RCAnonymousID:\<UUID without dashes\>
947
+ * Example: $RCAnonymousID:123e4567e89b12d3a456426614174000
948
+ * @returns A new anonymous app user ID string
949
+ * @public
950
+ */
951
+ static generateRevenueCatAnonymousAppUserId(): string;
952
+ }
953
+
919
954
  /**
920
- * @returns Whether the SDK is using a sandbox API Key.
955
+ * Error class for Purchases SDK. You should handle these errors and react
956
+ * accordingly in your app.
957
+ * @public
921
958
  */
922
- isSandbox(): boolean;
959
+ export declare class PurchasesError extends Error {
960
+ /**
961
+ * Error code for the error. This is useful to appropriately react to
962
+ * different error situations.
963
+ */
964
+ readonly errorCode: ErrorCode;
965
+ /**
966
+ * Underlying error message. This provides more details on the error and
967
+ * can be useful for debugging and logging.
968
+ */
969
+ readonly underlyingErrorMessage?: string | null | undefined;
970
+ /**
971
+ * Contains extra information that is available in certain types of errors.
972
+ */
973
+ readonly extra?: PurchasesErrorExtra | undefined;
974
+ constructor(
975
+ /**
976
+ * Error code for the error. This is useful to appropriately react to
977
+ * different error situations.
978
+ */
979
+ errorCode: ErrorCode,
980
+ /**
981
+ * Message for the error. This is useful for debugging and logging.
982
+ */
983
+ message?: string,
984
+ /**
985
+ * Underlying error message. This provides more details on the error and
986
+ * can be useful for debugging and logging.
987
+ */
988
+ underlyingErrorMessage?: string | null | undefined,
989
+ /**
990
+ * Contains extra information that is available in certain types of errors.
991
+ */
992
+ extra?: PurchasesErrorExtra | undefined);
993
+ toString: () => string;
994
+ }
995
+
923
996
  /**
924
- * @returns Whether the current user is anonymous.
997
+ * Extra information that is available in certain types of errors.
998
+ * @public
925
999
  */
926
- isAnonymous(): boolean;
1000
+ export declare interface PurchasesErrorExtra {
1001
+ /**
1002
+ * If this is a request error, the HTTP status code of the response.
1003
+ */
1004
+ readonly statusCode?: number;
1005
+ /**
1006
+ * If this is a RevenueCat backend error, the error code from the servers.
1007
+ */
1008
+ readonly backendErrorCode?: number;
1009
+ }
1010
+
927
1011
  /**
928
- * Closes the Purchases instance. You should never have to do this normally.
1012
+ * This object gives you access to the purchase redemption data when
1013
+ * the purchase can be redeemed to a mobile user, like in the case of anonymous users.
1014
+ * @public
929
1015
  */
930
- close(): void;
1016
+ export declare interface RedemptionInfo {
1017
+ /**
1018
+ * The redeem url.
1019
+ */
1020
+ readonly redeemUrl: string | null;
1021
+ }
1022
+
931
1023
  /**
932
- * Generates an anonymous app user ID that follows RevenueCat's format.
933
- * This can be used when you don't have a user identifier system in place.
934
- * The generated ID will be in the format: $RCAnonymousID:\<UUID without dashes\>
935
- * Example: $RCAnonymousID:123e4567e89b12d3a456426614174000
936
- * @returns A new anonymous app user ID string
1024
+ * Enumeration of reserved customer attributes.
937
1025
  * @public
938
1026
  */
939
- static generateRevenueCatAnonymousAppUserId(): string;
940
- }
941
-
942
- /**
943
- * Error class for Purchases SDK. You should handle these errors and react
944
- * accordingly in your app.
945
- * @public
946
- */
947
- export declare class PurchasesError extends Error {
948
- /**
949
- * Error code for the error. This is useful to appropriately react to
950
- * different error situations.
951
- */
952
- readonly errorCode: ErrorCode;
953
- /**
954
- * Underlying error message. This provides more details on the error and
955
- * can be useful for debugging and logging.
956
- */
957
- readonly underlyingErrorMessage?: string | null | undefined;
958
- /**
959
- * Contains extra information that is available in certain types of errors.
960
- */
961
- readonly extra?: PurchasesErrorExtra | undefined;
962
- constructor(
963
- /**
964
- * Error code for the error. This is useful to appropriately react to
965
- * different error situations.
966
- */
967
- errorCode: ErrorCode,
968
- /**
969
- * Message for the error. This is useful for debugging and logging.
970
- */
971
- message?: string,
972
- /**
973
- * Underlying error message. This provides more details on the error and
974
- * can be useful for debugging and logging.
975
- */
976
- underlyingErrorMessage?: string | null | undefined,
977
- /**
978
- * Contains extra information that is available in certain types of errors.
979
- */
980
- extra?: PurchasesErrorExtra | undefined);
981
- toString: () => string;
982
- }
983
-
984
- /**
985
- * Extra information that is available in certain types of errors.
986
- * @public
987
- */
988
- export declare interface PurchasesErrorExtra {
989
- /**
990
- * If this is a request error, the HTTP status code of the response.
991
- */
992
- readonly statusCode?: number;
993
- /**
994
- * If this is a RevenueCat backend error, the error code from the servers.
995
- */
996
- readonly backendErrorCode?: number;
997
- }
1027
+ export declare enum ReservedCustomerAttribute {
1028
+ /**
1029
+ * The display name that should be used to reference the customer.
1030
+ */
1031
+ DisplayName = "$displayName",
1032
+ /**
1033
+ * The email address of the customer.
1034
+ */
1035
+ Email = "$email",
1036
+ /**
1037
+ * The phone number of the customer.
1038
+ */
1039
+ PhoneNumber = "$phoneNumber",
1040
+ /**
1041
+ * iOS advertising identifier UUID for the customer.
1042
+ */
1043
+ IDFA = "$idfa",
1044
+ /**
1045
+ * iOS vendor identifier UUID for the customer.
1046
+ */
1047
+ IDFV = "$idfv",
1048
+ /**
1049
+ * The advertising ID that is provided by Google Play services for the customer.
1050
+ */
1051
+ GPSAdId = "$gpsAdId",
1052
+ /**
1053
+ * The Android ID of the customer.
1054
+ */
1055
+ AndroidId = "$androidId",
1056
+ /**
1057
+ * The Amazon Advertising ID of the customer.
1058
+ */
1059
+ AmazonAdId = "$amazonAdId",
1060
+ /**
1061
+ * The IP address of the customer.
1062
+ */
1063
+ IP = "$ip",
1064
+ /**
1065
+ * The unique Adjust identifier for the customer.
1066
+ */
1067
+ AdjustId = "$adjustId",
1068
+ /**
1069
+ * The Amplitude device ID of the customer.
1070
+ */
1071
+ AmplitudeDeviceId = "$amplitudeDeviceId",
1072
+ /**
1073
+ * The Amplitude user ID of the customer.
1074
+ */
1075
+ AmplitudeUserId = "$amplitudeUserId",
1076
+ /**
1077
+ * Appsflyer Id. The unique Appsflyer identifier for the customer.
1078
+ */
1079
+ AppsflyerId = "$appsflyerId",
1080
+ /**
1081
+ * The AppsFlyer sharing filter of the customer.
1082
+ */
1083
+ AppsflyerSharingFilter = "$appsflyerSharingFilter",
1084
+ /**
1085
+ * The Branch ID of the customer.
1086
+ */
1087
+ BranchId = "$branchId",
1088
+ /**
1089
+ * The Braze 'alias_name' in User Alias Object.
1090
+ */
1091
+ BrazeAliasName = "$brazeAliasName",
1092
+ /**
1093
+ * The Braze 'alias_label' in User Alias Object.
1094
+ */
1095
+ BrazeAliasLabel = "$brazeAliasLabel",
1096
+ /**
1097
+ * The CleverTap ID of the customer.
1098
+ */
1099
+ ClevertapId = "$clevertapId",
1100
+ /**
1101
+ * The Facebook anonymous ID of the customer.
1102
+ */
1103
+ FbAnonId = "$fbAnonId",
1104
+ /**
1105
+ * The unique mParticle user identifier (mpid).
1106
+ */
1107
+ MparticleId = "$mparticleId",
1108
+ /**
1109
+ * The OneSignal Player Id for the customer.
1110
+ */
1111
+ OnesignalId = "$onesignalId",
1112
+ /**
1113
+ * The OneSignal user ID of the customer.
1114
+ */
1115
+ OnesignalUserId = "$onesignalUserId",
1116
+ /**
1117
+ * The Intercom contact ID of the customer.
1118
+ */
1119
+ IntercomContactId = "$intercomContactId",
1120
+ /**
1121
+ * The media source of the customer.
1122
+ */
1123
+ MediaSource = "$mediaSource",
1124
+ /**
1125
+ * The campaign of the customer.
1126
+ */
1127
+ Campaign = "$campaign",
1128
+ /**
1129
+ * The ad group of the customer.
1130
+ */
1131
+ AdGroup = "$adGroup",
1132
+ /**
1133
+ * The Ad ID of the customer.
1134
+ */
1135
+ AdId = "$ad",
1136
+ /**
1137
+ * The keyword of the customer.
1138
+ */
1139
+ Keyword = "$keyword",
1140
+ /**
1141
+ * The creative of the customer.
1142
+ */
1143
+ Creative = "$creative",
1144
+ /**
1145
+ * Apple push notification tokens for the customer.
1146
+ */
1147
+ APNSTokens = "$apnsTokens",
1148
+ /**
1149
+ * Google push notification tokens for the customer.
1150
+ */
1151
+ FCMTokens = "$fcmTokens",
1152
+ /**
1153
+ * The Airship channel ID of the customer.
1154
+ */
1155
+ AirshipChannelId = "$airshipChannelId",
1156
+ /**
1157
+ * The segment ID of the customer.
1158
+ */
1159
+ SegmentId = "$segmentId",
1160
+ /**
1161
+ * The Iterable user ID of the customer.
1162
+ */
1163
+ IterableUserId = "$iterableUserId",
1164
+ /**
1165
+ * The Iterable campaign ID of the customer.
1166
+ */
1167
+ IterableCampaignId = "$iterableCampaignId",
1168
+ /**
1169
+ * The Iterable template ID of the customer.
1170
+ */
1171
+ IterableTemplateId = "$iterableTemplateId",
1172
+ /**
1173
+ * The Firebase app instance ID of the customer.
1174
+ */
1175
+ FirebaseAppInstanceId = "$firebaseAppInstanceId",
1176
+ /**
1177
+ * The Mixpanel distinct ID of the customer.
1178
+ */
1179
+ MixpanelDistinctId = "$mixpanelDistinctId",
1180
+ /**
1181
+ * Apple App Tracking Transparency consent status for the customer.
1182
+ */
1183
+ ATTConsentStatus = "$attConsentStatus",
1184
+ /**
1185
+ * The unique Kochava device identifier of the customer.
1186
+ */
1187
+ KochavaDeviceId = "$kochavaDeviceId",
1188
+ /**
1189
+ * The device version of the customer.
1190
+ */
1191
+ DeviceVersion = "$deviceVersion",
1192
+ /**
1193
+ * The PostHog user ID of the customer.
1194
+ */
1195
+ PosthogUserId = "$posthogUserId",
1196
+ /**
1197
+ * The Telemetry Deck user ID of the customer.
1198
+ */
1199
+ TelemetryDeckUserId = "$telemetryDeckUserId",
1200
+ /**
1201
+ * The Telemetry Deck app ID of the customer.
1202
+ */
1203
+ TelemetryDeckAppId = "$telemetryDeckAppId",
1204
+ /**
1205
+ * The Apple refund handling preference of the customer.
1206
+ */
1207
+ AppleRefundHandlingPreference = "$appleRefundHandlingPreference",
1208
+ /**
1209
+ * The customer.io ID of the customer.
1210
+ */
1211
+ CustomerioId = "$customerioId",
1212
+ /**
1213
+ * The Tenjin ID of the customer.
1214
+ */
1215
+ TenjinId = "$tenjinId"
1216
+ }
998
1217
 
999
- /**
1000
- * This object gives you access to the purchase redemption data when
1001
- * the purchase can be redeemed to a mobile user, like in the case of anonymous users.
1002
- * @public
1003
- */
1004
- export declare interface RedemptionInfo {
1005
- /**
1006
- * The redeem url.
1007
- */
1008
- readonly redeemUrl: string | null;
1009
- }
1010
-
1011
- /**
1012
- * The store where the user originally subscribed.
1013
- * @public
1014
- */
1015
- export declare type Store = "app_store" | "mac_app_store" | "play_store" | "amazon" | "stripe" | "rc_billing" | "promotional" | "unknown";
1218
+ /**
1219
+ * The store where the user originally subscribed.
1220
+ * @public
1221
+ */
1222
+ export declare type Store = "app_store" | "mac_app_store" | "play_store" | "amazon" | "stripe" | "rc_billing" | "promotional" | "unknown";
1016
1223
 
1017
- /**
1018
- * Subscription purchases of the Customer.
1019
- * @public
1020
- */
1021
- export declare interface SubscriptionInfo {
1022
- /**
1023
- * The product identifier.
1024
- */
1025
- readonly productIdentifier: string;
1026
- /**
1027
- * Date when the last subscription period started.
1028
- */
1029
- readonly purchaseDate: Date;
1030
- /**
1031
- * Date when this subscription first started. This property does not update with renewals.
1032
- * This property also does not update for product changes within a subscription group or
1033
- * re-subscriptions by lapsed subscribers.
1034
- */
1035
- readonly originalPurchaseDate: Date | null;
1036
- /**
1037
- * Date when the subscription expires/expired
1038
- */
1039
- readonly expiresDate: Date | null;
1040
- /**
1041
- * Store where the subscription was purchased.
1042
- */
1043
- readonly store: Store;
1044
- /**
1045
- * Date when RevenueCat detected that auto-renewal was turned off for this subscription.
1046
- * Note the subscription may still be active, check the {@link SubscriptionInfo.expiresDate} attribute.
1047
- */
1048
- readonly unsubscribeDetectedAt: Date | null;
1049
- /**
1050
- * Whether or not the purchase was made in sandbox mode.
1051
- */
1052
- readonly isSandbox: boolean;
1053
- /**
1054
- * Date when RevenueCat detected any billing issues with this subscription.
1055
- * If and when the billing issue gets resolved, this field is set to null.
1056
- * Note the subscription may still be active, check the {@link SubscriptionInfo.expiresDate} attribute.
1057
- */
1058
- readonly billingIssuesDetectedAt: Date | null;
1059
- /**
1060
- * Date when any grace period for this subscription expires/expired.
1061
- * null if the customer has never been in a grace period.
1062
- */
1063
- readonly gracePeriodExpiresDate: Date | null;
1064
- /**
1065
- * How the Customer received access to this subscription:
1066
- * - "PURCHASED": The customer bought the subscription.
1067
- * - "FAMILY_SHARED": The customer has access to the product via their family.
1068
- */
1069
- readonly ownershipType: OwnershipType;
1070
- /**
1071
- * Type of the current subscription period:
1072
- * - "normal": The product is in a normal period (default)
1073
- * - "trial": The product is in a free trial period
1074
- * - "intro": The product is in an introductory pricing period
1075
- * - "prepaid": The product is in a prepaid pricing period
1076
- */
1077
- readonly periodType: PeriodType;
1078
- /**
1079
- * Date when RevenueCat detected a refund of this subscription.
1080
- */
1081
- readonly refundedAt: Date | null;
1082
- /**
1083
- * The transaction id in the store of the subscription.
1084
- */
1085
- readonly storeTransactionId: string | null;
1086
- /**
1087
- * Whether the subscription is currently active
1088
- * (at the time this object was obtained).
1089
- */
1090
- readonly isActive: boolean;
1091
- /**
1092
- * Whether the subscription will renew at the next billing period.
1093
- */
1094
- readonly willRenew: boolean;
1095
- }
1224
+ /**
1225
+ * Subscription purchases of the Customer.
1226
+ * @public
1227
+ */
1228
+ export declare interface SubscriptionInfo {
1229
+ /**
1230
+ * The product identifier.
1231
+ */
1232
+ readonly productIdentifier: string;
1233
+ /**
1234
+ * Date when the last subscription period started.
1235
+ */
1236
+ readonly purchaseDate: Date;
1237
+ /**
1238
+ * Date when this subscription first started. This property does not update with renewals.
1239
+ * This property also does not update for product changes within a subscription group or
1240
+ * re-subscriptions by lapsed subscribers.
1241
+ */
1242
+ readonly originalPurchaseDate: Date | null;
1243
+ /**
1244
+ * Date when the subscription expires/expired
1245
+ */
1246
+ readonly expiresDate: Date | null;
1247
+ /**
1248
+ * Store where the subscription was purchased.
1249
+ */
1250
+ readonly store: Store;
1251
+ /**
1252
+ * Date when RevenueCat detected that auto-renewal was turned off for this subscription.
1253
+ * Note the subscription may still be active, check the {@link SubscriptionInfo.expiresDate} attribute.
1254
+ */
1255
+ readonly unsubscribeDetectedAt: Date | null;
1256
+ /**
1257
+ * Whether or not the purchase was made in sandbox mode.
1258
+ */
1259
+ readonly isSandbox: boolean;
1260
+ /**
1261
+ * Date when RevenueCat detected any billing issues with this subscription.
1262
+ * If and when the billing issue gets resolved, this field is set to null.
1263
+ * Note the subscription may still be active, check the {@link SubscriptionInfo.expiresDate} attribute.
1264
+ */
1265
+ readonly billingIssuesDetectedAt: Date | null;
1266
+ /**
1267
+ * Date when any grace period for this subscription expires/expired.
1268
+ * null if the customer has never been in a grace period.
1269
+ */
1270
+ readonly gracePeriodExpiresDate: Date | null;
1271
+ /**
1272
+ * How the Customer received access to this subscription:
1273
+ * - "PURCHASED": The customer bought the subscription.
1274
+ * - "FAMILY_SHARED": The customer has access to the product via their family.
1275
+ */
1276
+ readonly ownershipType: OwnershipType;
1277
+ /**
1278
+ * Type of the current subscription period:
1279
+ * - "normal": The product is in a normal period (default)
1280
+ * - "trial": The product is in a free trial period
1281
+ * - "intro": The product is in an introductory pricing period
1282
+ * - "prepaid": The product is in a prepaid pricing period
1283
+ */
1284
+ readonly periodType: PeriodType;
1285
+ /**
1286
+ * Date when RevenueCat detected a refund of this subscription.
1287
+ */
1288
+ readonly refundedAt: Date | null;
1289
+ /**
1290
+ * The transaction id in the store of the subscription.
1291
+ */
1292
+ readonly storeTransactionId: string | null;
1293
+ /**
1294
+ * Whether the subscription is currently active
1295
+ * (at the time this object was obtained).
1296
+ */
1297
+ readonly isActive: boolean;
1298
+ /**
1299
+ * Whether the subscription will renew at the next billing period.
1300
+ */
1301
+ readonly willRenew: boolean;
1302
+ }
1096
1303
 
1097
- /**
1098
- * Represents a possible option to purchase a subscription product.
1099
- * @public
1100
- */
1101
- export declare interface SubscriptionOption extends PurchaseOption {
1102
- /**
1103
- * The base phase for a SubscriptionOption, represents
1104
- * the price that the customer will be charged after all the discounts have
1105
- * been consumed and the period at which it will renew.
1106
- */
1107
- readonly base: PricingPhase;
1108
- /**
1109
- * The trial information for this subscription option if available.
1110
- */
1111
- readonly trial: PricingPhase | null;
1112
- }
1304
+ /**
1305
+ * Represents a possible option to purchase a subscription product.
1306
+ * @public
1307
+ */
1308
+ export declare interface SubscriptionOption extends PurchaseOption {
1309
+ /**
1310
+ * The base phase for a SubscriptionOption, represents
1311
+ * the price that the customer will be charged after all the discounts have
1312
+ * been consumed and the period at which it will renew.
1313
+ */
1314
+ readonly base: PricingPhase;
1315
+ /**
1316
+ * The trial information for this subscription option if available.
1317
+ */
1318
+ readonly trial: PricingPhase | null;
1319
+ }
1113
1320
 
1114
- /**
1115
- * Contains information about the targeting context used to obtain an object.
1116
- * @public
1117
- */
1118
- export declare interface TargetingContext {
1119
- /**
1120
- * The rule id from the targeting used to obtain this object.
1121
- */
1122
- readonly ruleId: string;
1123
- /**
1124
- * The revision of the targeting used to obtain this object.
1125
- */
1126
- readonly revision: number;
1127
- }
1321
+ /**
1322
+ * Contains information about the targeting context used to obtain an object.
1323
+ * @public
1324
+ */
1325
+ export declare interface TargetingContext {
1326
+ /**
1327
+ * The rule id from the targeting used to obtain this object.
1328
+ */
1329
+ readonly ruleId: string;
1330
+ /**
1331
+ * The revision of the targeting used to obtain this object.
1332
+ */
1333
+ readonly revision: number;
1334
+ }
1128
1335
 
1129
- /**
1130
- * Error indicating that the SDK was accessed before it was initialized.
1131
- * @public
1132
- */
1133
- export declare class UninitializedPurchasesError extends Error {
1134
- constructor();
1135
- }
1336
+ /**
1337
+ * Error indicating that the SDK was accessed before it was initialized.
1338
+ * @public
1339
+ */
1340
+ export declare class UninitializedPurchasesError extends Error {
1341
+ constructor();
1342
+ }
1136
1343
 
1137
- export { }
1344
+ export { }