mobilyflow-react-native-sdk 0.0.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/LICENSE +20 -0
- package/MobilyflowReactNativeSdk.podspec +52 -0
- package/README.md +33 -0
- package/android/build.gradle +114 -0
- package/android/generated/java/com/mobilyflowreactnativesdk/NativeMobilyflowReactNativeSdkSpec.java +89 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNMobilyflowReactNativeSdkSpec-generated.cpp +104 -0
- package/android/generated/jni/RNMobilyflowReactNativeSdkSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNMobilyflowReactNativeSdkSpec/RNMobilyflowReactNativeSdkSpecJSI-generated.cpp +124 -0
- package/android/generated/jni/react/renderer/components/RNMobilyflowReactNativeSdkSpec/RNMobilyflowReactNativeSdkSpecJSI.h +287 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/mobilyflowreactnativesdk/MobilyflowReactNativeSdkModule.kt +183 -0
- package/android/src/main/java/com/mobilyflowreactnativesdk/MobilyflowReactNativeSdkPackage.kt +32 -0
- package/android/src/main/java/com/mobilyflowreactnativesdk/ParserUtils.kt +149 -0
- package/ios/MobilyflowReactNativeSdk.h +7 -0
- package/ios/MobilyflowReactNativeSdk.mm +204 -0
- package/ios/Utils/ParserMobilyPurchaseSDKOptions.h +21 -0
- package/ios/Utils/ParserMobilyPurchaseSDKOptions.mm +25 -0
- package/ios/Utils/Utils.h +18 -0
- package/ios/Utils/Utils.m +22 -0
- package/ios/generated/RNMobilyflowReactNativeSdkSpec/RNMobilyflowReactNativeSdkSpec-generated.mm +134 -0
- package/ios/generated/RNMobilyflowReactNativeSdkSpec/RNMobilyflowReactNativeSdkSpec.h +161 -0
- package/ios/generated/RNMobilyflowReactNativeSdkSpecJSI-generated.cpp +124 -0
- package/ios/generated/RNMobilyflowReactNativeSdkSpecJSI.h +287 -0
- package/package.json +183 -0
- package/react-native.config.js +12 -0
- package/src/NativeMobilyflowReactNativeSdk.ts +46 -0
- package/src/entities/mobily-customer-entitlement.ts +37 -0
- package/src/entities/mobily-one-time-product.ts +11 -0
- package/src/entities/mobily-product.ts +34 -0
- package/src/entities/mobily-subscription-group.ts +20 -0
- package/src/entities/mobily-subscription-offer.ts +16 -0
- package/src/entities/mobily-subscription-product.ts +14 -0
- package/src/enums/mobily-environment.ts +5 -0
- package/src/enums/period-unit.ts +5 -0
- package/src/enums/platform.ts +4 -0
- package/src/enums/product-status.ts +5 -0
- package/src/enums/product-type.ts +4 -0
- package/src/enums/webhook-status.ts +5 -0
- package/src/errors/mobily-error.ts +18 -0
- package/src/errors/mobily-purchase-error.ts +30 -0
- package/src/errors/mobily-transfer-ownership-error.ts +20 -0
- package/src/index.tsx +153 -0
- package/src/utils/object-transformer.ts +60 -0
@@ -0,0 +1,124 @@
|
|
1
|
+
/**
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
3
|
+
*
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
5
|
+
* once the code is regenerated.
|
6
|
+
*
|
7
|
+
* @generated by codegen project: GenerateModuleCpp.js
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include "RNMobilyflowReactNativeSdkSpecJSI.h"
|
11
|
+
|
12
|
+
namespace facebook::react {
|
13
|
+
|
14
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_instantiate(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
15
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->instantiate(
|
16
|
+
rt,
|
17
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
18
|
+
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt),
|
19
|
+
count <= 2 ? throw jsi::JSError(rt, "Expected argument in position 2 to be passed") : args[2].asNumber(),
|
20
|
+
count <= 3 || args[3].isUndefined() ? std::nullopt : std::make_optional(args[3].asObject(rt))
|
21
|
+
);
|
22
|
+
}
|
23
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_close(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
24
|
+
static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->close(
|
25
|
+
rt,
|
26
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
27
|
+
);
|
28
|
+
return jsi::Value::undefined();
|
29
|
+
}
|
30
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_login(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
31
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->login(
|
32
|
+
rt,
|
33
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
34
|
+
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt)
|
35
|
+
);
|
36
|
+
}
|
37
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getProducts(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
38
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->getProducts(
|
39
|
+
rt,
|
40
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
41
|
+
count <= 1 || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asObject(rt).asArray(rt))
|
42
|
+
);
|
43
|
+
}
|
44
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getSubscriptionGroups(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
45
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->getSubscriptionGroups(
|
46
|
+
rt,
|
47
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
48
|
+
count <= 1 || args[1].isUndefined() ? std::nullopt : std::make_optional(args[1].asObject(rt).asArray(rt))
|
49
|
+
);
|
50
|
+
}
|
51
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getEntitlementForSubscription(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
52
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->getEntitlementForSubscription(
|
53
|
+
rt,
|
54
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
55
|
+
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt)
|
56
|
+
);
|
57
|
+
}
|
58
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getEntitlement(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
59
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->getEntitlement(
|
60
|
+
rt,
|
61
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
62
|
+
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt)
|
63
|
+
);
|
64
|
+
}
|
65
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getEntitlements(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
66
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->getEntitlements(
|
67
|
+
rt,
|
68
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
69
|
+
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asObject(rt).asArray(rt)
|
70
|
+
);
|
71
|
+
}
|
72
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_requestTransferOwnership(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
73
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->requestTransferOwnership(
|
74
|
+
rt,
|
75
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
76
|
+
);
|
77
|
+
}
|
78
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_openManageSubscription(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
79
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->openManageSubscription(
|
80
|
+
rt,
|
81
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
82
|
+
);
|
83
|
+
}
|
84
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_purchaseProduct(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
85
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->purchaseProduct(
|
86
|
+
rt,
|
87
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
|
88
|
+
count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt),
|
89
|
+
count <= 2 || args[2].isUndefined() ? std::nullopt : std::make_optional(args[2].asObject(rt))
|
90
|
+
);
|
91
|
+
}
|
92
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_sendDiagnotic(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
93
|
+
static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->sendDiagnotic(
|
94
|
+
rt,
|
95
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
96
|
+
);
|
97
|
+
return jsi::Value::undefined();
|
98
|
+
}
|
99
|
+
static jsi::Value __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getStoreCountry(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
100
|
+
return static_cast<NativeMobilyflowReactNativeSdkCxxSpecJSI *>(&turboModule)->getStoreCountry(
|
101
|
+
rt,
|
102
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
103
|
+
);
|
104
|
+
}
|
105
|
+
|
106
|
+
NativeMobilyflowReactNativeSdkCxxSpecJSI::NativeMobilyflowReactNativeSdkCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
107
|
+
: TurboModule("MobilyflowReactNativeSdk", jsInvoker) {
|
108
|
+
methodMap_["instantiate"] = MethodMetadata {4, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_instantiate};
|
109
|
+
methodMap_["close"] = MethodMetadata {1, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_close};
|
110
|
+
methodMap_["login"] = MethodMetadata {2, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_login};
|
111
|
+
methodMap_["getProducts"] = MethodMetadata {2, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getProducts};
|
112
|
+
methodMap_["getSubscriptionGroups"] = MethodMetadata {2, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getSubscriptionGroups};
|
113
|
+
methodMap_["getEntitlementForSubscription"] = MethodMetadata {2, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getEntitlementForSubscription};
|
114
|
+
methodMap_["getEntitlement"] = MethodMetadata {2, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getEntitlement};
|
115
|
+
methodMap_["getEntitlements"] = MethodMetadata {2, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getEntitlements};
|
116
|
+
methodMap_["requestTransferOwnership"] = MethodMetadata {1, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_requestTransferOwnership};
|
117
|
+
methodMap_["openManageSubscription"] = MethodMetadata {1, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_openManageSubscription};
|
118
|
+
methodMap_["purchaseProduct"] = MethodMetadata {3, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_purchaseProduct};
|
119
|
+
methodMap_["sendDiagnotic"] = MethodMetadata {1, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_sendDiagnotic};
|
120
|
+
methodMap_["getStoreCountry"] = MethodMetadata {1, __hostFunction_NativeMobilyflowReactNativeSdkCxxSpecJSI_getStoreCountry};
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
} // namespace facebook::react
|
@@ -0,0 +1,287 @@
|
|
1
|
+
/**
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
3
|
+
*
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
5
|
+
* once the code is regenerated.
|
6
|
+
*
|
7
|
+
* @generated by codegen project: GenerateModuleH.js
|
8
|
+
*/
|
9
|
+
|
10
|
+
#pragma once
|
11
|
+
|
12
|
+
#include <ReactCommon/TurboModule.h>
|
13
|
+
#include <react/bridging/Bridging.h>
|
14
|
+
|
15
|
+
namespace facebook::react {
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#pragma mark - NativeMobilyflowReactNativeSdkMobilyPurchaseSDKOptions
|
20
|
+
|
21
|
+
template <typename P0, typename P1, typename P2>
|
22
|
+
struct NativeMobilyflowReactNativeSdkMobilyPurchaseSDKOptions {
|
23
|
+
P0 languages;
|
24
|
+
P1 debug;
|
25
|
+
P2 apiURL;
|
26
|
+
bool operator==(const NativeMobilyflowReactNativeSdkMobilyPurchaseSDKOptions &other) const {
|
27
|
+
return languages == other.languages && debug == other.debug && apiURL == other.apiURL;
|
28
|
+
}
|
29
|
+
};
|
30
|
+
|
31
|
+
template <typename T>
|
32
|
+
struct NativeMobilyflowReactNativeSdkMobilyPurchaseSDKOptionsBridging {
|
33
|
+
static T types;
|
34
|
+
|
35
|
+
static T fromJs(
|
36
|
+
jsi::Runtime &rt,
|
37
|
+
const jsi::Object &value,
|
38
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
39
|
+
T result{
|
40
|
+
bridging::fromJs<decltype(types.languages)>(rt, value.getProperty(rt, "languages"), jsInvoker),
|
41
|
+
bridging::fromJs<decltype(types.debug)>(rt, value.getProperty(rt, "debug"), jsInvoker),
|
42
|
+
bridging::fromJs<decltype(types.apiURL)>(rt, value.getProperty(rt, "apiURL"), jsInvoker)};
|
43
|
+
return result;
|
44
|
+
}
|
45
|
+
|
46
|
+
#ifdef DEBUG
|
47
|
+
static jsi::Array languagesToJs(jsi::Runtime &rt, decltype(types.languages) value) {
|
48
|
+
return bridging::toJs(rt, value);
|
49
|
+
}
|
50
|
+
|
51
|
+
static bool debugToJs(jsi::Runtime &rt, decltype(types.debug) value) {
|
52
|
+
return bridging::toJs(rt, value);
|
53
|
+
}
|
54
|
+
|
55
|
+
static jsi::String apiURLToJs(jsi::Runtime &rt, decltype(types.apiURL) value) {
|
56
|
+
return bridging::toJs(rt, value);
|
57
|
+
}
|
58
|
+
#endif
|
59
|
+
|
60
|
+
static jsi::Object toJs(
|
61
|
+
jsi::Runtime &rt,
|
62
|
+
const T &value,
|
63
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
64
|
+
auto result = facebook::jsi::Object(rt);
|
65
|
+
if (value.languages) {
|
66
|
+
result.setProperty(rt, "languages", bridging::toJs(rt, value.languages.value(), jsInvoker));
|
67
|
+
}
|
68
|
+
if (value.debug) {
|
69
|
+
result.setProperty(rt, "debug", bridging::toJs(rt, value.debug.value(), jsInvoker));
|
70
|
+
}
|
71
|
+
if (value.apiURL) {
|
72
|
+
result.setProperty(rt, "apiURL", bridging::toJs(rt, value.apiURL.value(), jsInvoker));
|
73
|
+
}
|
74
|
+
return result;
|
75
|
+
}
|
76
|
+
};
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
#pragma mark - NativeMobilyflowReactNativeSdkPurchaseOptions
|
81
|
+
|
82
|
+
template <typename P0, typename P1>
|
83
|
+
struct NativeMobilyflowReactNativeSdkPurchaseOptions {
|
84
|
+
P0 offerId;
|
85
|
+
P1 quantity;
|
86
|
+
bool operator==(const NativeMobilyflowReactNativeSdkPurchaseOptions &other) const {
|
87
|
+
return offerId == other.offerId && quantity == other.quantity;
|
88
|
+
}
|
89
|
+
};
|
90
|
+
|
91
|
+
template <typename T>
|
92
|
+
struct NativeMobilyflowReactNativeSdkPurchaseOptionsBridging {
|
93
|
+
static T types;
|
94
|
+
|
95
|
+
static T fromJs(
|
96
|
+
jsi::Runtime &rt,
|
97
|
+
const jsi::Object &value,
|
98
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
99
|
+
T result{
|
100
|
+
bridging::fromJs<decltype(types.offerId)>(rt, value.getProperty(rt, "offerId"), jsInvoker),
|
101
|
+
bridging::fromJs<decltype(types.quantity)>(rt, value.getProperty(rt, "quantity"), jsInvoker)};
|
102
|
+
return result;
|
103
|
+
}
|
104
|
+
|
105
|
+
#ifdef DEBUG
|
106
|
+
static jsi::String offerIdToJs(jsi::Runtime &rt, decltype(types.offerId) value) {
|
107
|
+
return bridging::toJs(rt, value);
|
108
|
+
}
|
109
|
+
|
110
|
+
static double quantityToJs(jsi::Runtime &rt, decltype(types.quantity) value) {
|
111
|
+
return bridging::toJs(rt, value);
|
112
|
+
}
|
113
|
+
#endif
|
114
|
+
|
115
|
+
static jsi::Object toJs(
|
116
|
+
jsi::Runtime &rt,
|
117
|
+
const T &value,
|
118
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
119
|
+
auto result = facebook::jsi::Object(rt);
|
120
|
+
result.setProperty(rt, "offerId", bridging::toJs(rt, value.offerId, jsInvoker));
|
121
|
+
result.setProperty(rt, "quantity", bridging::toJs(rt, value.quantity, jsInvoker));
|
122
|
+
return result;
|
123
|
+
}
|
124
|
+
};
|
125
|
+
|
126
|
+
class JSI_EXPORT NativeMobilyflowReactNativeSdkCxxSpecJSI : public TurboModule {
|
127
|
+
protected:
|
128
|
+
NativeMobilyflowReactNativeSdkCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
|
129
|
+
|
130
|
+
public:
|
131
|
+
virtual jsi::String instantiate(jsi::Runtime &rt, jsi::String appId, jsi::String apiKey, double environment, std::optional<jsi::Object> options) = 0;
|
132
|
+
virtual void close(jsi::Runtime &rt, jsi::String uuid) = 0;
|
133
|
+
virtual jsi::Value login(jsi::Runtime &rt, jsi::String uuid, jsi::String externalId) = 0;
|
134
|
+
virtual jsi::Value getProducts(jsi::Runtime &rt, jsi::String uuid, std::optional<jsi::Array> identifiers) = 0;
|
135
|
+
virtual jsi::Value getSubscriptionGroups(jsi::Runtime &rt, jsi::String uuid, std::optional<jsi::Array> identifiers) = 0;
|
136
|
+
virtual jsi::Value getEntitlementForSubscription(jsi::Runtime &rt, jsi::String uuid, jsi::String subscriptionGroupId) = 0;
|
137
|
+
virtual jsi::Value getEntitlement(jsi::Runtime &rt, jsi::String uuid, jsi::String productId) = 0;
|
138
|
+
virtual jsi::Value getEntitlements(jsi::Runtime &rt, jsi::String uuid, jsi::Array productIds) = 0;
|
139
|
+
virtual jsi::Value requestTransferOwnership(jsi::Runtime &rt, jsi::String uuid) = 0;
|
140
|
+
virtual jsi::Value openManageSubscription(jsi::Runtime &rt, jsi::String uuid) = 0;
|
141
|
+
virtual jsi::Value purchaseProduct(jsi::Runtime &rt, jsi::String uuid, jsi::String productId, std::optional<jsi::Object> options) = 0;
|
142
|
+
virtual void sendDiagnotic(jsi::Runtime &rt, jsi::String uuid) = 0;
|
143
|
+
virtual jsi::Value getStoreCountry(jsi::Runtime &rt, jsi::String uuid) = 0;
|
144
|
+
|
145
|
+
};
|
146
|
+
|
147
|
+
template <typename T>
|
148
|
+
class JSI_EXPORT NativeMobilyflowReactNativeSdkCxxSpec : public TurboModule {
|
149
|
+
public:
|
150
|
+
jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
|
151
|
+
return delegate_.create(rt, propName);
|
152
|
+
}
|
153
|
+
|
154
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override {
|
155
|
+
return delegate_.getPropertyNames(runtime);
|
156
|
+
}
|
157
|
+
|
158
|
+
static constexpr std::string_view kModuleName = "MobilyflowReactNativeSdk";
|
159
|
+
|
160
|
+
protected:
|
161
|
+
NativeMobilyflowReactNativeSdkCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
|
162
|
+
: TurboModule(std::string{NativeMobilyflowReactNativeSdkCxxSpec::kModuleName}, jsInvoker),
|
163
|
+
delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
|
164
|
+
|
165
|
+
|
166
|
+
private:
|
167
|
+
class Delegate : public NativeMobilyflowReactNativeSdkCxxSpecJSI {
|
168
|
+
public:
|
169
|
+
Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
|
170
|
+
NativeMobilyflowReactNativeSdkCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
|
171
|
+
|
172
|
+
}
|
173
|
+
|
174
|
+
jsi::String instantiate(jsi::Runtime &rt, jsi::String appId, jsi::String apiKey, double environment, std::optional<jsi::Object> options) override {
|
175
|
+
static_assert(
|
176
|
+
bridging::getParameterCount(&T::instantiate) == 5,
|
177
|
+
"Expected instantiate(...) to have 5 parameters");
|
178
|
+
|
179
|
+
return bridging::callFromJs<jsi::String>(
|
180
|
+
rt, &T::instantiate, jsInvoker_, instance_, std::move(appId), std::move(apiKey), std::move(environment), std::move(options));
|
181
|
+
}
|
182
|
+
void close(jsi::Runtime &rt, jsi::String uuid) override {
|
183
|
+
static_assert(
|
184
|
+
bridging::getParameterCount(&T::close) == 2,
|
185
|
+
"Expected close(...) to have 2 parameters");
|
186
|
+
|
187
|
+
return bridging::callFromJs<void>(
|
188
|
+
rt, &T::close, jsInvoker_, instance_, std::move(uuid));
|
189
|
+
}
|
190
|
+
jsi::Value login(jsi::Runtime &rt, jsi::String uuid, jsi::String externalId) override {
|
191
|
+
static_assert(
|
192
|
+
bridging::getParameterCount(&T::login) == 3,
|
193
|
+
"Expected login(...) to have 3 parameters");
|
194
|
+
|
195
|
+
return bridging::callFromJs<jsi::Value>(
|
196
|
+
rt, &T::login, jsInvoker_, instance_, std::move(uuid), std::move(externalId));
|
197
|
+
}
|
198
|
+
jsi::Value getProducts(jsi::Runtime &rt, jsi::String uuid, std::optional<jsi::Array> identifiers) override {
|
199
|
+
static_assert(
|
200
|
+
bridging::getParameterCount(&T::getProducts) == 3,
|
201
|
+
"Expected getProducts(...) to have 3 parameters");
|
202
|
+
|
203
|
+
return bridging::callFromJs<jsi::Value>(
|
204
|
+
rt, &T::getProducts, jsInvoker_, instance_, std::move(uuid), std::move(identifiers));
|
205
|
+
}
|
206
|
+
jsi::Value getSubscriptionGroups(jsi::Runtime &rt, jsi::String uuid, std::optional<jsi::Array> identifiers) override {
|
207
|
+
static_assert(
|
208
|
+
bridging::getParameterCount(&T::getSubscriptionGroups) == 3,
|
209
|
+
"Expected getSubscriptionGroups(...) to have 3 parameters");
|
210
|
+
|
211
|
+
return bridging::callFromJs<jsi::Value>(
|
212
|
+
rt, &T::getSubscriptionGroups, jsInvoker_, instance_, std::move(uuid), std::move(identifiers));
|
213
|
+
}
|
214
|
+
jsi::Value getEntitlementForSubscription(jsi::Runtime &rt, jsi::String uuid, jsi::String subscriptionGroupId) override {
|
215
|
+
static_assert(
|
216
|
+
bridging::getParameterCount(&T::getEntitlementForSubscription) == 3,
|
217
|
+
"Expected getEntitlementForSubscription(...) to have 3 parameters");
|
218
|
+
|
219
|
+
return bridging::callFromJs<jsi::Value>(
|
220
|
+
rt, &T::getEntitlementForSubscription, jsInvoker_, instance_, std::move(uuid), std::move(subscriptionGroupId));
|
221
|
+
}
|
222
|
+
jsi::Value getEntitlement(jsi::Runtime &rt, jsi::String uuid, jsi::String productId) override {
|
223
|
+
static_assert(
|
224
|
+
bridging::getParameterCount(&T::getEntitlement) == 3,
|
225
|
+
"Expected getEntitlement(...) to have 3 parameters");
|
226
|
+
|
227
|
+
return bridging::callFromJs<jsi::Value>(
|
228
|
+
rt, &T::getEntitlement, jsInvoker_, instance_, std::move(uuid), std::move(productId));
|
229
|
+
}
|
230
|
+
jsi::Value getEntitlements(jsi::Runtime &rt, jsi::String uuid, jsi::Array productIds) override {
|
231
|
+
static_assert(
|
232
|
+
bridging::getParameterCount(&T::getEntitlements) == 3,
|
233
|
+
"Expected getEntitlements(...) to have 3 parameters");
|
234
|
+
|
235
|
+
return bridging::callFromJs<jsi::Value>(
|
236
|
+
rt, &T::getEntitlements, jsInvoker_, instance_, std::move(uuid), std::move(productIds));
|
237
|
+
}
|
238
|
+
jsi::Value requestTransferOwnership(jsi::Runtime &rt, jsi::String uuid) override {
|
239
|
+
static_assert(
|
240
|
+
bridging::getParameterCount(&T::requestTransferOwnership) == 2,
|
241
|
+
"Expected requestTransferOwnership(...) to have 2 parameters");
|
242
|
+
|
243
|
+
return bridging::callFromJs<jsi::Value>(
|
244
|
+
rt, &T::requestTransferOwnership, jsInvoker_, instance_, std::move(uuid));
|
245
|
+
}
|
246
|
+
jsi::Value openManageSubscription(jsi::Runtime &rt, jsi::String uuid) override {
|
247
|
+
static_assert(
|
248
|
+
bridging::getParameterCount(&T::openManageSubscription) == 2,
|
249
|
+
"Expected openManageSubscription(...) to have 2 parameters");
|
250
|
+
|
251
|
+
return bridging::callFromJs<jsi::Value>(
|
252
|
+
rt, &T::openManageSubscription, jsInvoker_, instance_, std::move(uuid));
|
253
|
+
}
|
254
|
+
jsi::Value purchaseProduct(jsi::Runtime &rt, jsi::String uuid, jsi::String productId, std::optional<jsi::Object> options) override {
|
255
|
+
static_assert(
|
256
|
+
bridging::getParameterCount(&T::purchaseProduct) == 4,
|
257
|
+
"Expected purchaseProduct(...) to have 4 parameters");
|
258
|
+
|
259
|
+
return bridging::callFromJs<jsi::Value>(
|
260
|
+
rt, &T::purchaseProduct, jsInvoker_, instance_, std::move(uuid), std::move(productId), std::move(options));
|
261
|
+
}
|
262
|
+
void sendDiagnotic(jsi::Runtime &rt, jsi::String uuid) override {
|
263
|
+
static_assert(
|
264
|
+
bridging::getParameterCount(&T::sendDiagnotic) == 2,
|
265
|
+
"Expected sendDiagnotic(...) to have 2 parameters");
|
266
|
+
|
267
|
+
return bridging::callFromJs<void>(
|
268
|
+
rt, &T::sendDiagnotic, jsInvoker_, instance_, std::move(uuid));
|
269
|
+
}
|
270
|
+
jsi::Value getStoreCountry(jsi::Runtime &rt, jsi::String uuid) override {
|
271
|
+
static_assert(
|
272
|
+
bridging::getParameterCount(&T::getStoreCountry) == 2,
|
273
|
+
"Expected getStoreCountry(...) to have 2 parameters");
|
274
|
+
|
275
|
+
return bridging::callFromJs<jsi::Value>(
|
276
|
+
rt, &T::getStoreCountry, jsInvoker_, instance_, std::move(uuid));
|
277
|
+
}
|
278
|
+
|
279
|
+
private:
|
280
|
+
friend class NativeMobilyflowReactNativeSdkCxxSpec;
|
281
|
+
T *instance_;
|
282
|
+
};
|
283
|
+
|
284
|
+
Delegate delegate_;
|
285
|
+
};
|
286
|
+
|
287
|
+
} // namespace facebook::react
|
package/package.json
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
{
|
2
|
+
"name": "mobilyflow-react-native-sdk",
|
3
|
+
"version": "0.0.1",
|
4
|
+
"description": "MobilyFlow React Native SDK",
|
5
|
+
"source": "./src/index.tsx",
|
6
|
+
"main": "./lib/commonjs/index.js",
|
7
|
+
"module": "./lib/module/index.js",
|
8
|
+
"exports": {
|
9
|
+
".": {
|
10
|
+
"import": {
|
11
|
+
"types": "./lib/typescript/module/src/index.d.ts",
|
12
|
+
"default": "./lib/module/index.js"
|
13
|
+
},
|
14
|
+
"require": {
|
15
|
+
"types": "./lib/typescript/commonjs/src/index.d.ts",
|
16
|
+
"default": "./lib/commonjs/index.js"
|
17
|
+
}
|
18
|
+
}
|
19
|
+
},
|
20
|
+
"files": [
|
21
|
+
"src",
|
22
|
+
"lib",
|
23
|
+
"android",
|
24
|
+
"ios",
|
25
|
+
"cpp",
|
26
|
+
"*.podspec",
|
27
|
+
"react-native.config.js",
|
28
|
+
"!ios/build",
|
29
|
+
"!android/build",
|
30
|
+
"!android/gradle",
|
31
|
+
"!android/gradlew",
|
32
|
+
"!android/gradlew.bat",
|
33
|
+
"!android/local.properties",
|
34
|
+
"!**/__tests__",
|
35
|
+
"!**/__fixtures__",
|
36
|
+
"!**/__mocks__",
|
37
|
+
"!**/.*"
|
38
|
+
],
|
39
|
+
"scripts": {
|
40
|
+
"example": "yarn workspace mobilyflow-react-native-sdk-example",
|
41
|
+
"test": "jest",
|
42
|
+
"typecheck": "tsc",
|
43
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
44
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
45
|
+
"prepare": "bob build",
|
46
|
+
"pub": "yarn npm publish --access public"
|
47
|
+
},
|
48
|
+
"keywords": [
|
49
|
+
"react-native",
|
50
|
+
"ios",
|
51
|
+
"android"
|
52
|
+
],
|
53
|
+
"repository": {
|
54
|
+
"type": "git",
|
55
|
+
"url": "git+https://github.com/MobilyFlow/mobilyflow-react-native-sdk.git"
|
56
|
+
},
|
57
|
+
"author": "MobilyFlow <dev@mobilyflow.com> (https://www.mobilyflow.com/)",
|
58
|
+
"license": "MIT",
|
59
|
+
"bugs": {
|
60
|
+
"url": "https://github.com/MobilyFlow/mobilyflow-react-native-sdk/issues"
|
61
|
+
},
|
62
|
+
"homepage": "https://github.com/MobilyFlow/mobilyflow-react-native-sdk#readme",
|
63
|
+
"publishConfig": {
|
64
|
+
"registry": "https://registry.npmjs.org/"
|
65
|
+
},
|
66
|
+
"devDependencies": {
|
67
|
+
"@react-native-community/cli": "15.0.1",
|
68
|
+
"@react-native/eslint-config": "^0.73.1",
|
69
|
+
"@types/jest": "^29.5.5",
|
70
|
+
"@types/react": "^18.2.44",
|
71
|
+
"del-cli": "^5.1.0",
|
72
|
+
"eslint": "^8.51.0",
|
73
|
+
"eslint-config-prettier": "^9.0.0",
|
74
|
+
"eslint-plugin-prettier": "^5.0.1",
|
75
|
+
"jest": "^29.7.0",
|
76
|
+
"prettier": "^3.0.3",
|
77
|
+
"react": "19.0.0",
|
78
|
+
"react-native": "0.78.0",
|
79
|
+
"react-native-builder-bob": "^0.36.0",
|
80
|
+
"turbo": "^1.10.7",
|
81
|
+
"typescript": "^5.2.2"
|
82
|
+
},
|
83
|
+
"resolutions": {
|
84
|
+
"@types/react": "^18.2.44"
|
85
|
+
},
|
86
|
+
"peerDependencies": {
|
87
|
+
"react": "*",
|
88
|
+
"react-native": "*"
|
89
|
+
},
|
90
|
+
"workspaces": [
|
91
|
+
"example"
|
92
|
+
],
|
93
|
+
"packageManager": "yarn@3.6.1",
|
94
|
+
"jest": {
|
95
|
+
"preset": "react-native",
|
96
|
+
"modulePathIgnorePatterns": [
|
97
|
+
"<rootDir>/example/node_modules",
|
98
|
+
"<rootDir>/lib/"
|
99
|
+
]
|
100
|
+
},
|
101
|
+
"commitlint": {
|
102
|
+
"extends": [
|
103
|
+
"@commitlint/config-conventional"
|
104
|
+
]
|
105
|
+
},
|
106
|
+
"eslintConfig": {
|
107
|
+
"root": true,
|
108
|
+
"extends": [
|
109
|
+
"@react-native",
|
110
|
+
"prettier"
|
111
|
+
],
|
112
|
+
"rules": {
|
113
|
+
"react/react-in-jsx-scope": "off",
|
114
|
+
"prettier/prettier": [
|
115
|
+
"error",
|
116
|
+
{
|
117
|
+
"quoteProps": "consistent",
|
118
|
+
"singleQuote": true,
|
119
|
+
"tabWidth": 2,
|
120
|
+
"trailingComma": "es5",
|
121
|
+
"useTabs": false,
|
122
|
+
"printWidth": 120
|
123
|
+
}
|
124
|
+
]
|
125
|
+
}
|
126
|
+
},
|
127
|
+
"eslintIgnore": [
|
128
|
+
"node_modules/",
|
129
|
+
"lib/"
|
130
|
+
],
|
131
|
+
"prettier": {
|
132
|
+
"quoteProps": "consistent",
|
133
|
+
"singleQuote": true,
|
134
|
+
"tabWidth": 2,
|
135
|
+
"trailingComma": "es5",
|
136
|
+
"useTabs": false,
|
137
|
+
"printWidth": 120
|
138
|
+
},
|
139
|
+
"react-native-builder-bob": {
|
140
|
+
"source": "src",
|
141
|
+
"output": "lib",
|
142
|
+
"targets": [
|
143
|
+
"codegen",
|
144
|
+
[
|
145
|
+
"commonjs",
|
146
|
+
{
|
147
|
+
"esm": true
|
148
|
+
}
|
149
|
+
],
|
150
|
+
[
|
151
|
+
"module",
|
152
|
+
{
|
153
|
+
"esm": true
|
154
|
+
}
|
155
|
+
],
|
156
|
+
[
|
157
|
+
"typescript",
|
158
|
+
{
|
159
|
+
"project": "tsconfig.build.json",
|
160
|
+
"esm": true
|
161
|
+
}
|
162
|
+
]
|
163
|
+
]
|
164
|
+
},
|
165
|
+
"codegenConfig": {
|
166
|
+
"name": "RNMobilyflowReactNativeSdkSpec",
|
167
|
+
"type": "modules",
|
168
|
+
"jsSrcsDir": "src",
|
169
|
+
"outputDir": {
|
170
|
+
"ios": "ios/generated",
|
171
|
+
"android": "android/generated"
|
172
|
+
},
|
173
|
+
"android": {
|
174
|
+
"javaPackageName": "com.mobilyflowreactnativesdk"
|
175
|
+
},
|
176
|
+
"includesGeneratedCode": true
|
177
|
+
},
|
178
|
+
"create-react-native-library": {
|
179
|
+
"type": "turbo-module",
|
180
|
+
"languages": "kotlin-objc",
|
181
|
+
"version": "0.48.3"
|
182
|
+
}
|
183
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
3
|
+
import { MobilyProduct } from './entities/mobily-product';
|
4
|
+
import { MobilySubscriptionGroup } from './entities/mobily-subscription-group';
|
5
|
+
import { MobilyCustomerEntitlement } from './entities/mobily-customer-entitlement';
|
6
|
+
import { WebhookStatus } from './enums/webhook-status';
|
7
|
+
|
8
|
+
export type MobilyPurchaseSDKOptions = {
|
9
|
+
languages?: string[];
|
10
|
+
debug?: boolean;
|
11
|
+
apiURL?: string;
|
12
|
+
};
|
13
|
+
|
14
|
+
type PurchaseOptions = {
|
15
|
+
offerId: string;
|
16
|
+
quantity: number;
|
17
|
+
};
|
18
|
+
|
19
|
+
export interface Spec extends TurboModule {
|
20
|
+
instantiate(appId: string, apiKey: string, environment: number, options?: MobilyPurchaseSDKOptions): string;
|
21
|
+
close(uuid: string): void;
|
22
|
+
|
23
|
+
login(uuid: string, externalId: string): Promise<void>;
|
24
|
+
getProducts(uuid: string, identifiers?: string[]): Promise<MobilyProduct[]>;
|
25
|
+
getSubscriptionGroups(uuid: string, identifiers?: string[]): Promise<MobilySubscriptionGroup[]>;
|
26
|
+
|
27
|
+
getEntitlementForSubscription(uuid: string, subscriptionGroupId: string): Promise<MobilyCustomerEntitlement | null>;
|
28
|
+
getEntitlement(uuid: string, productId: string): Promise<MobilyCustomerEntitlement | null>;
|
29
|
+
getEntitlements(uuid: string, productIds: string[]): Promise<MobilyCustomerEntitlement[]>;
|
30
|
+
|
31
|
+
requestTransferOwnership(uuid: string): Promise<void>;
|
32
|
+
openManageSubscription(uuid: string): Promise<void>;
|
33
|
+
// openRefundDialog(uuid: string, transactionId: string): Promise<void>;
|
34
|
+
|
35
|
+
purchaseProduct(uuid: string, productId: string, options?: PurchaseOptions): Promise<WebhookStatus>;
|
36
|
+
|
37
|
+
sendDiagnotic(uuid: string): void;
|
38
|
+
getStoreCountry(uuid: string): Promise<string>;
|
39
|
+
}
|
40
|
+
|
41
|
+
// export default TurboModuleRegistry.getEnforcing<Spec>('MobilyflowReactNativeSdk');
|
42
|
+
console.log('Before module');
|
43
|
+
const module = TurboModuleRegistry.getEnforcing<Spec>('MobilyflowReactNativeSdk');
|
44
|
+
console.log('after module ', module);
|
45
|
+
|
46
|
+
export default module;
|