@doordeck/headless-react-native-sdk 0.83.0
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/HeadlessReactNativeSdk.podspec +44 -0
- package/LICENSE +174 -0
- package/README.md +113 -0
- package/android/build.gradle +118 -0
- package/android/generated/java/com/doordeck/headlessreactnativesdk/NativeHeadlessReactNativeSdkSpec.java +62 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNHeadlessReactNativeSdkSpec-generated.cpp +68 -0
- package/android/generated/jni/RNHeadlessReactNativeSdkSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNHeadlessReactNativeSdkSpec/RNHeadlessReactNativeSdkSpecJSI-generated.cpp +68 -0
- package/android/generated/jni/react/renderer/components/RNHeadlessReactNativeSdkSpec/RNHeadlessReactNativeSdkSpecJSI.h +307 -0
- package/android/gradle.properties +5 -0
- package/android/settings.gradle.kts +16 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/doordeck/headlessreactnativesdk/HeadlessReactNativeSdkModule.kt +176 -0
- package/android/src/main/java/com/doordeck/headlessreactnativesdk/HeadlessReactNativeSdkPackage.kt +43 -0
- package/ios/HeadlessReactNativeSdk.h +6 -0
- package/ios/HeadlessReactNativeSdk.mm +54 -0
- package/ios/HeadlessReactNativeSdkImpl.swift +210 -0
- package/ios/generated/RNHeadlessReactNativeSdkSpec/RNHeadlessReactNativeSdkSpec-generated.mm +81 -0
- package/ios/generated/RNHeadlessReactNativeSdkSpec/RNHeadlessReactNativeSdkSpec.h +81 -0
- package/ios/generated/RNHeadlessReactNativeSdkSpecJSI-generated.cpp +68 -0
- package/ios/generated/RNHeadlessReactNativeSdkSpecJSI.h +307 -0
- package/lib/commonjs/NativeHeadlessReactNativeSdk.js +9 -0
- package/lib/commonjs/NativeHeadlessReactNativeSdk.js.map +1 -0
- package/lib/commonjs/index.js +36 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/NativeHeadlessReactNativeSdk.js +5 -0
- package/lib/module/NativeHeadlessReactNativeSdk.js.map +1 -0
- package/lib/module/index.js +25 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeHeadlessReactNativeSdk.d.ts +72 -0
- package/lib/typescript/commonjs/src/NativeHeadlessReactNativeSdk.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +9 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeHeadlessReactNativeSdk.d.ts +72 -0
- package/lib/typescript/module/src/NativeHeadlessReactNativeSdk.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +9 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +203 -0
- package/react-native.config.js +12 -0
- package/src/NativeHeadlessReactNativeSdk.ts +87 -0
- package/src/index.tsx +35 -0
|
@@ -0,0 +1,68 @@
|
|
|
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 "RNHeadlessReactNativeSdkSpecJSI.h"
|
|
11
|
+
|
|
12
|
+
namespace facebook::react {
|
|
13
|
+
|
|
14
|
+
static jsi::Value __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_login(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
15
|
+
return static_cast<NativeHeadlessReactNativeSdkCxxSpecJSI *>(&turboModule)->login(
|
|
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
|
+
);
|
|
20
|
+
}
|
|
21
|
+
static jsi::Value __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_setAuthToken(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
22
|
+
return static_cast<NativeHeadlessReactNativeSdkCxxSpecJSI *>(&turboModule)->setAuthToken(
|
|
23
|
+
rt,
|
|
24
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
static jsi::Value __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_getUserDetails(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
28
|
+
return static_cast<NativeHeadlessReactNativeSdkCxxSpecJSI *>(&turboModule)->getUserDetails(
|
|
29
|
+
rt
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
static jsi::Value __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_verify(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
33
|
+
return static_cast<NativeHeadlessReactNativeSdkCxxSpecJSI *>(&turboModule)->verify(
|
|
34
|
+
rt,
|
|
35
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
static jsi::Value __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_logout(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
39
|
+
return static_cast<NativeHeadlessReactNativeSdkCxxSpecJSI *>(&turboModule)->logout(
|
|
40
|
+
rt
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
static jsi::Value __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_getLocksBelongingToTile(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
44
|
+
return static_cast<NativeHeadlessReactNativeSdkCxxSpecJSI *>(&turboModule)->getLocksBelongingToTile(
|
|
45
|
+
rt,
|
|
46
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
static jsi::Value __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_unlockDevice(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
|
50
|
+
return static_cast<NativeHeadlessReactNativeSdkCxxSpecJSI *>(&turboModule)->unlockDevice(
|
|
51
|
+
rt,
|
|
52
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
NativeHeadlessReactNativeSdkCxxSpecJSI::NativeHeadlessReactNativeSdkCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
|
57
|
+
: TurboModule("HeadlessReactNativeSdk", jsInvoker) {
|
|
58
|
+
methodMap_["login"] = MethodMetadata {2, __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_login};
|
|
59
|
+
methodMap_["setAuthToken"] = MethodMetadata {1, __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_setAuthToken};
|
|
60
|
+
methodMap_["getUserDetails"] = MethodMetadata {0, __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_getUserDetails};
|
|
61
|
+
methodMap_["verify"] = MethodMetadata {1, __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_verify};
|
|
62
|
+
methodMap_["logout"] = MethodMetadata {0, __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_logout};
|
|
63
|
+
methodMap_["getLocksBelongingToTile"] = MethodMetadata {1, __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_getLocksBelongingToTile};
|
|
64
|
+
methodMap_["unlockDevice"] = MethodMetadata {1, __hostFunction_NativeHeadlessReactNativeSdkCxxSpecJSI_unlockDevice};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,307 @@
|
|
|
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 - NativeHeadlessReactNativeSdkAssistedRegisterEphemeralKeyResponse
|
|
20
|
+
|
|
21
|
+
template <typename P0>
|
|
22
|
+
struct NativeHeadlessReactNativeSdkAssistedRegisterEphemeralKeyResponse {
|
|
23
|
+
P0 requiresVerification;
|
|
24
|
+
bool operator==(const NativeHeadlessReactNativeSdkAssistedRegisterEphemeralKeyResponse &other) const {
|
|
25
|
+
return requiresVerification == other.requiresVerification;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
template <typename T>
|
|
30
|
+
struct NativeHeadlessReactNativeSdkAssistedRegisterEphemeralKeyResponseBridging {
|
|
31
|
+
static T types;
|
|
32
|
+
|
|
33
|
+
static T fromJs(
|
|
34
|
+
jsi::Runtime &rt,
|
|
35
|
+
const jsi::Object &value,
|
|
36
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
37
|
+
T result{
|
|
38
|
+
bridging::fromJs<decltype(types.requiresVerification)>(rt, value.getProperty(rt, "requiresVerification"), jsInvoker)};
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#ifdef DEBUG
|
|
43
|
+
static bool requiresVerificationToJs(jsi::Runtime &rt, decltype(types.requiresVerification) value) {
|
|
44
|
+
return bridging::toJs(rt, value);
|
|
45
|
+
}
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
static jsi::Object toJs(
|
|
49
|
+
jsi::Runtime &rt,
|
|
50
|
+
const T &value,
|
|
51
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
52
|
+
auto result = facebook::jsi::Object(rt);
|
|
53
|
+
result.setProperty(rt, "requiresVerification", bridging::toJs(rt, value.requiresVerification, jsInvoker));
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
#pragma mark - NativeHeadlessReactNativeSdkTileLocksResponse
|
|
61
|
+
|
|
62
|
+
template <typename P0, typename P1, typename P2>
|
|
63
|
+
struct NativeHeadlessReactNativeSdkTileLocksResponse {
|
|
64
|
+
P0 siteId;
|
|
65
|
+
P1 tileId;
|
|
66
|
+
P2 deviceIds;
|
|
67
|
+
bool operator==(const NativeHeadlessReactNativeSdkTileLocksResponse &other) const {
|
|
68
|
+
return siteId == other.siteId && tileId == other.tileId && deviceIds == other.deviceIds;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
template <typename T>
|
|
73
|
+
struct NativeHeadlessReactNativeSdkTileLocksResponseBridging {
|
|
74
|
+
static T types;
|
|
75
|
+
|
|
76
|
+
static T fromJs(
|
|
77
|
+
jsi::Runtime &rt,
|
|
78
|
+
const jsi::Object &value,
|
|
79
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
80
|
+
T result{
|
|
81
|
+
bridging::fromJs<decltype(types.siteId)>(rt, value.getProperty(rt, "siteId"), jsInvoker),
|
|
82
|
+
bridging::fromJs<decltype(types.tileId)>(rt, value.getProperty(rt, "tileId"), jsInvoker),
|
|
83
|
+
bridging::fromJs<decltype(types.deviceIds)>(rt, value.getProperty(rt, "deviceIds"), jsInvoker)};
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#ifdef DEBUG
|
|
88
|
+
static jsi::String siteIdToJs(jsi::Runtime &rt, decltype(types.siteId) value) {
|
|
89
|
+
return bridging::toJs(rt, value);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static jsi::String tileIdToJs(jsi::Runtime &rt, decltype(types.tileId) value) {
|
|
93
|
+
return bridging::toJs(rt, value);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static jsi::Array deviceIdsToJs(jsi::Runtime &rt, decltype(types.deviceIds) value) {
|
|
97
|
+
return bridging::toJs(rt, value);
|
|
98
|
+
}
|
|
99
|
+
#endif
|
|
100
|
+
|
|
101
|
+
static jsi::Object toJs(
|
|
102
|
+
jsi::Runtime &rt,
|
|
103
|
+
const T &value,
|
|
104
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
105
|
+
auto result = facebook::jsi::Object(rt);
|
|
106
|
+
result.setProperty(rt, "siteId", bridging::toJs(rt, value.siteId, jsInvoker));
|
|
107
|
+
result.setProperty(rt, "tileId", bridging::toJs(rt, value.tileId, jsInvoker));
|
|
108
|
+
result.setProperty(rt, "deviceIds", bridging::toJs(rt, value.deviceIds, jsInvoker));
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
#pragma mark - NativeHeadlessReactNativeSdkUserDetailsResponse
|
|
116
|
+
|
|
117
|
+
template <typename P0, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
|
|
118
|
+
struct NativeHeadlessReactNativeSdkUserDetailsResponse {
|
|
119
|
+
P0 userId;
|
|
120
|
+
P1 publicKey;
|
|
121
|
+
P2 email;
|
|
122
|
+
P3 displayName;
|
|
123
|
+
P4 emailVerified;
|
|
124
|
+
P5 certificateChainAboutToExpire;
|
|
125
|
+
P6 tokenAboutToExpire;
|
|
126
|
+
bool operator==(const NativeHeadlessReactNativeSdkUserDetailsResponse &other) const {
|
|
127
|
+
return userId == other.userId && publicKey == other.publicKey && email == other.email && displayName == other.displayName && emailVerified == other.emailVerified && certificateChainAboutToExpire == other.certificateChainAboutToExpire && tokenAboutToExpire == other.tokenAboutToExpire;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
template <typename T>
|
|
132
|
+
struct NativeHeadlessReactNativeSdkUserDetailsResponseBridging {
|
|
133
|
+
static T types;
|
|
134
|
+
|
|
135
|
+
static T fromJs(
|
|
136
|
+
jsi::Runtime &rt,
|
|
137
|
+
const jsi::Object &value,
|
|
138
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
139
|
+
T result{
|
|
140
|
+
bridging::fromJs<decltype(types.userId)>(rt, value.getProperty(rt, "userId"), jsInvoker),
|
|
141
|
+
bridging::fromJs<decltype(types.publicKey)>(rt, value.getProperty(rt, "publicKey"), jsInvoker),
|
|
142
|
+
bridging::fromJs<decltype(types.email)>(rt, value.getProperty(rt, "email"), jsInvoker),
|
|
143
|
+
bridging::fromJs<decltype(types.displayName)>(rt, value.getProperty(rt, "displayName"), jsInvoker),
|
|
144
|
+
bridging::fromJs<decltype(types.emailVerified)>(rt, value.getProperty(rt, "emailVerified"), jsInvoker),
|
|
145
|
+
bridging::fromJs<decltype(types.certificateChainAboutToExpire)>(rt, value.getProperty(rt, "certificateChainAboutToExpire"), jsInvoker),
|
|
146
|
+
bridging::fromJs<decltype(types.tokenAboutToExpire)>(rt, value.getProperty(rt, "tokenAboutToExpire"), jsInvoker)};
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#ifdef DEBUG
|
|
151
|
+
static jsi::String userIdToJs(jsi::Runtime &rt, decltype(types.userId) value) {
|
|
152
|
+
return bridging::toJs(rt, value);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static jsi::String publicKeyToJs(jsi::Runtime &rt, decltype(types.publicKey) value) {
|
|
156
|
+
return bridging::toJs(rt, value);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
static jsi::String emailToJs(jsi::Runtime &rt, decltype(types.email) value) {
|
|
160
|
+
return bridging::toJs(rt, value);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
static jsi::String displayNameToJs(jsi::Runtime &rt, decltype(types.displayName) value) {
|
|
164
|
+
return bridging::toJs(rt, value);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
static bool emailVerifiedToJs(jsi::Runtime &rt, decltype(types.emailVerified) value) {
|
|
168
|
+
return bridging::toJs(rt, value);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
static bool certificateChainAboutToExpireToJs(jsi::Runtime &rt, decltype(types.certificateChainAboutToExpire) value) {
|
|
172
|
+
return bridging::toJs(rt, value);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static bool tokenAboutToExpireToJs(jsi::Runtime &rt, decltype(types.tokenAboutToExpire) value) {
|
|
176
|
+
return bridging::toJs(rt, value);
|
|
177
|
+
}
|
|
178
|
+
#endif
|
|
179
|
+
|
|
180
|
+
static jsi::Object toJs(
|
|
181
|
+
jsi::Runtime &rt,
|
|
182
|
+
const T &value,
|
|
183
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
|
184
|
+
auto result = facebook::jsi::Object(rt);
|
|
185
|
+
if (value.userId) {
|
|
186
|
+
result.setProperty(rt, "userId", bridging::toJs(rt, value.userId.value(), jsInvoker));
|
|
187
|
+
}
|
|
188
|
+
result.setProperty(rt, "publicKey", bridging::toJs(rt, value.publicKey, jsInvoker));
|
|
189
|
+
result.setProperty(rt, "email", bridging::toJs(rt, value.email, jsInvoker));
|
|
190
|
+
if (value.displayName) {
|
|
191
|
+
result.setProperty(rt, "displayName", bridging::toJs(rt, value.displayName.value(), jsInvoker));
|
|
192
|
+
}
|
|
193
|
+
result.setProperty(rt, "emailVerified", bridging::toJs(rt, value.emailVerified, jsInvoker));
|
|
194
|
+
result.setProperty(rt, "certificateChainAboutToExpire", bridging::toJs(rt, value.certificateChainAboutToExpire, jsInvoker));
|
|
195
|
+
result.setProperty(rt, "tokenAboutToExpire", bridging::toJs(rt, value.tokenAboutToExpire, jsInvoker));
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
class JSI_EXPORT NativeHeadlessReactNativeSdkCxxSpecJSI : public TurboModule {
|
|
201
|
+
protected:
|
|
202
|
+
NativeHeadlessReactNativeSdkCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
|
|
203
|
+
|
|
204
|
+
public:
|
|
205
|
+
virtual jsi::Value login(jsi::Runtime &rt, jsi::String email, jsi::String password) = 0;
|
|
206
|
+
virtual jsi::Value setAuthToken(jsi::Runtime &rt, jsi::String authToken) = 0;
|
|
207
|
+
virtual jsi::Value getUserDetails(jsi::Runtime &rt) = 0;
|
|
208
|
+
virtual jsi::Value verify(jsi::Runtime &rt, jsi::String code) = 0;
|
|
209
|
+
virtual jsi::Value logout(jsi::Runtime &rt) = 0;
|
|
210
|
+
virtual jsi::Value getLocksBelongingToTile(jsi::Runtime &rt, jsi::String tileId) = 0;
|
|
211
|
+
virtual jsi::Value unlockDevice(jsi::Runtime &rt, jsi::String lockId) = 0;
|
|
212
|
+
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
template <typename T>
|
|
216
|
+
class JSI_EXPORT NativeHeadlessReactNativeSdkCxxSpec : public TurboModule {
|
|
217
|
+
public:
|
|
218
|
+
jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
|
|
219
|
+
return delegate_.create(rt, propName);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override {
|
|
223
|
+
return delegate_.getPropertyNames(runtime);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static constexpr std::string_view kModuleName = "HeadlessReactNativeSdk";
|
|
227
|
+
|
|
228
|
+
protected:
|
|
229
|
+
NativeHeadlessReactNativeSdkCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
|
|
230
|
+
: TurboModule(std::string{NativeHeadlessReactNativeSdkCxxSpec::kModuleName}, jsInvoker),
|
|
231
|
+
delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
private:
|
|
235
|
+
class Delegate : public NativeHeadlessReactNativeSdkCxxSpecJSI {
|
|
236
|
+
public:
|
|
237
|
+
Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
|
|
238
|
+
NativeHeadlessReactNativeSdkCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
|
|
239
|
+
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
jsi::Value login(jsi::Runtime &rt, jsi::String email, jsi::String password) override {
|
|
243
|
+
static_assert(
|
|
244
|
+
bridging::getParameterCount(&T::login) == 3,
|
|
245
|
+
"Expected login(...) to have 3 parameters");
|
|
246
|
+
|
|
247
|
+
return bridging::callFromJs<jsi::Value>(
|
|
248
|
+
rt, &T::login, jsInvoker_, instance_, std::move(email), std::move(password));
|
|
249
|
+
}
|
|
250
|
+
jsi::Value setAuthToken(jsi::Runtime &rt, jsi::String authToken) override {
|
|
251
|
+
static_assert(
|
|
252
|
+
bridging::getParameterCount(&T::setAuthToken) == 2,
|
|
253
|
+
"Expected setAuthToken(...) to have 2 parameters");
|
|
254
|
+
|
|
255
|
+
return bridging::callFromJs<jsi::Value>(
|
|
256
|
+
rt, &T::setAuthToken, jsInvoker_, instance_, std::move(authToken));
|
|
257
|
+
}
|
|
258
|
+
jsi::Value getUserDetails(jsi::Runtime &rt) override {
|
|
259
|
+
static_assert(
|
|
260
|
+
bridging::getParameterCount(&T::getUserDetails) == 1,
|
|
261
|
+
"Expected getUserDetails(...) to have 1 parameters");
|
|
262
|
+
|
|
263
|
+
return bridging::callFromJs<jsi::Value>(
|
|
264
|
+
rt, &T::getUserDetails, jsInvoker_, instance_);
|
|
265
|
+
}
|
|
266
|
+
jsi::Value verify(jsi::Runtime &rt, jsi::String code) override {
|
|
267
|
+
static_assert(
|
|
268
|
+
bridging::getParameterCount(&T::verify) == 2,
|
|
269
|
+
"Expected verify(...) to have 2 parameters");
|
|
270
|
+
|
|
271
|
+
return bridging::callFromJs<jsi::Value>(
|
|
272
|
+
rt, &T::verify, jsInvoker_, instance_, std::move(code));
|
|
273
|
+
}
|
|
274
|
+
jsi::Value logout(jsi::Runtime &rt) override {
|
|
275
|
+
static_assert(
|
|
276
|
+
bridging::getParameterCount(&T::logout) == 1,
|
|
277
|
+
"Expected logout(...) to have 1 parameters");
|
|
278
|
+
|
|
279
|
+
return bridging::callFromJs<jsi::Value>(
|
|
280
|
+
rt, &T::logout, jsInvoker_, instance_);
|
|
281
|
+
}
|
|
282
|
+
jsi::Value getLocksBelongingToTile(jsi::Runtime &rt, jsi::String tileId) override {
|
|
283
|
+
static_assert(
|
|
284
|
+
bridging::getParameterCount(&T::getLocksBelongingToTile) == 2,
|
|
285
|
+
"Expected getLocksBelongingToTile(...) to have 2 parameters");
|
|
286
|
+
|
|
287
|
+
return bridging::callFromJs<jsi::Value>(
|
|
288
|
+
rt, &T::getLocksBelongingToTile, jsInvoker_, instance_, std::move(tileId));
|
|
289
|
+
}
|
|
290
|
+
jsi::Value unlockDevice(jsi::Runtime &rt, jsi::String lockId) override {
|
|
291
|
+
static_assert(
|
|
292
|
+
bridging::getParameterCount(&T::unlockDevice) == 2,
|
|
293
|
+
"Expected unlockDevice(...) to have 2 parameters");
|
|
294
|
+
|
|
295
|
+
return bridging::callFromJs<jsi::Value>(
|
|
296
|
+
rt, &T::unlockDevice, jsInvoker_, instance_, std::move(lockId));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private:
|
|
300
|
+
friend class NativeHeadlessReactNativeSdkCxxSpec;
|
|
301
|
+
T *instance_;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
Delegate delegate_;
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
pluginManagement {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
gradlePluginPortal()
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
dependencyResolutionManagement {
|
|
10
|
+
repositories {
|
|
11
|
+
google()
|
|
12
|
+
mavenCentral()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
rootProject.name = "doordeck-react-native-headless-sdk"
|
package/android/src/main/java/com/doordeck/headlessreactnativesdk/HeadlessReactNativeSdkModule.kt
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
package com.doordeck.headlessreactnativesdk
|
|
2
|
+
|
|
3
|
+
import com.doordeck.multiplatform.sdk.Doordeck
|
|
4
|
+
import com.doordeck.multiplatform.sdk.exceptions.SdkException
|
|
5
|
+
import com.doordeck.multiplatform.sdk.model.data.LockOperations
|
|
6
|
+
import com.doordeck.multiplatform.sdk.model.responses.AssistedRegisterEphemeralKeyResponse
|
|
7
|
+
import com.doordeck.multiplatform.sdk.model.responses.TileLocksResponse
|
|
8
|
+
import com.doordeck.multiplatform.sdk.model.responses.UserDetailsResponse
|
|
9
|
+
import com.facebook.react.bridge.Arguments
|
|
10
|
+
import com.facebook.react.bridge.Promise
|
|
11
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
12
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
13
|
+
import java.security.KeyFactory
|
|
14
|
+
import java.security.Signature
|
|
15
|
+
import java.security.spec.PKCS8EncodedKeySpec
|
|
16
|
+
import kotlin.time.Duration.Companion.days
|
|
17
|
+
|
|
18
|
+
@ReactModule(name = HeadlessReactNativeSdkModule.NAME)
|
|
19
|
+
class HeadlessReactNativeSdkModule(
|
|
20
|
+
reactContext: ReactApplicationContext,
|
|
21
|
+
private val doordeckSdk: Doordeck,
|
|
22
|
+
) : NativeHeadlessReactNativeSdkSpec(reactContext) {
|
|
23
|
+
|
|
24
|
+
override fun getName(): String {
|
|
25
|
+
return NAME
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Auth operations
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
override fun login(
|
|
33
|
+
email: String,
|
|
34
|
+
password: String,
|
|
35
|
+
promise: Promise,
|
|
36
|
+
) {
|
|
37
|
+
setKeyPairIfNeeded()
|
|
38
|
+
|
|
39
|
+
doordeckSdk.accountless().loginAsync(email, password)
|
|
40
|
+
.thenApply {
|
|
41
|
+
respondNeedsVerification(promise)
|
|
42
|
+
}
|
|
43
|
+
.exceptionally { error ->
|
|
44
|
+
promise.reject("LOGIN_ERROR", error)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun setAuthToken(
|
|
49
|
+
authToken: String,
|
|
50
|
+
promise: Promise,
|
|
51
|
+
) {
|
|
52
|
+
setKeyPairIfNeeded()
|
|
53
|
+
|
|
54
|
+
doordeckSdk.contextManager().setCloudAuthToken(authToken)
|
|
55
|
+
respondNeedsVerification(promise)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
override fun verify(code: String, promise: Promise) {
|
|
59
|
+
doordeckSdk.account().verifyEphemeralKeyRegistrationAsync(code)
|
|
60
|
+
.thenApply {
|
|
61
|
+
promise.resolve(null)
|
|
62
|
+
}
|
|
63
|
+
.exceptionally { error ->
|
|
64
|
+
promise.reject("VERIFY_ERROR", error)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
override fun logout(promise: Promise) {
|
|
69
|
+
doordeckSdk.account().logoutAsync()
|
|
70
|
+
.thenApply {
|
|
71
|
+
promise.resolve(null)
|
|
72
|
+
}
|
|
73
|
+
.exceptionally { error ->
|
|
74
|
+
promise.reject("LOGOUT_ERROR", error)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* User operations
|
|
80
|
+
*/
|
|
81
|
+
override fun getUserDetails(promise: Promise) {
|
|
82
|
+
doordeckSdk.account().getUserDetailsAsync()
|
|
83
|
+
.thenApply { response ->
|
|
84
|
+
promise.resolve(response.toNativeMap(
|
|
85
|
+
userId = doordeckSdk.contextManager().getUserId(),
|
|
86
|
+
certificateChainAboutToExpire = doordeckSdk.contextManager().isCertificateChainAboutToExpire(),
|
|
87
|
+
tokenAboutToExpire = doordeckSdk.contextManager().isCloudAuthTokenAboutToExpire(),
|
|
88
|
+
))
|
|
89
|
+
}
|
|
90
|
+
.exceptionally { error ->
|
|
91
|
+
promise.reject("USER_DETAILS_ERROR", error)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Device and tile operations
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
override fun getLocksBelongingToTile(tileId: String, promise: Promise) {
|
|
100
|
+
doordeckSdk.tiles().getLocksBelongingToTileAsync(tileId)
|
|
101
|
+
.thenApply { response ->
|
|
102
|
+
promise.resolve(response.toNativeMap())
|
|
103
|
+
}
|
|
104
|
+
.exceptionally { error ->
|
|
105
|
+
promise.reject("LOCKS_ERROR", error)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
override fun unlockDevice(lockId: String, promise: Promise) {
|
|
110
|
+
doordeckSdk.lockOperations().unlockAsync(
|
|
111
|
+
LockOperations.UnlockOperation(
|
|
112
|
+
LockOperations.BaseOperation(
|
|
113
|
+
lockId = lockId,
|
|
114
|
+
)
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
.thenApply {
|
|
118
|
+
promise.resolve(null)
|
|
119
|
+
}
|
|
120
|
+
.exceptionally { error ->
|
|
121
|
+
promise.reject("UNLOCK_ERROR", error)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
companion object {
|
|
127
|
+
const val NAME = "HeadlessReactNativeSdk"
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private fun setKeyPairIfNeeded() {
|
|
131
|
+
if (!doordeckSdk.contextManager().isKeyPairValid()) {
|
|
132
|
+
val newKeyPair = doordeckSdk.crypto().generateKeyPair()
|
|
133
|
+
doordeckSdk.contextManager().setKeyPair(
|
|
134
|
+
publicKey = newKeyPair.public,
|
|
135
|
+
privateKey = newKeyPair.private,
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private fun respondNeedsVerification(promise: Promise) {
|
|
141
|
+
doordeckSdk.helper().assistedRegisterEphemeralKeyAsync()
|
|
142
|
+
.thenApply { response ->
|
|
143
|
+
promise.resolve(response.toNativeMap())
|
|
144
|
+
}
|
|
145
|
+
.exceptionally { error ->
|
|
146
|
+
promise.reject("NEEDS_VERIFICATION_ERROR", error)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private fun AssistedRegisterEphemeralKeyResponse.toNativeMap() = Arguments.createMap().apply {
|
|
151
|
+
putBoolean("requiresVerification", requiresVerification)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private fun TileLocksResponse.toNativeMap() = Arguments.createMap().apply {
|
|
155
|
+
putString("siteId", siteId)
|
|
156
|
+
putString("tileId", tileId)
|
|
157
|
+
putArray("deviceIds", Arguments.createArray().apply {
|
|
158
|
+
deviceIds.forEach { pushString(it) }
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private fun UserDetailsResponse.toNativeMap(
|
|
163
|
+
userId: String?,
|
|
164
|
+
certificateChainAboutToExpire: Boolean,
|
|
165
|
+
tokenAboutToExpire: Boolean,
|
|
166
|
+
) = Arguments.createMap().apply {
|
|
167
|
+
putString("userId", userId)
|
|
168
|
+
putBoolean("certificateChainAboutToExpire", certificateChainAboutToExpire)
|
|
169
|
+
putBoolean("tokenAboutToExpire", tokenAboutToExpire)
|
|
170
|
+
putString("publicKey", publicKey)
|
|
171
|
+
putString("email", email)
|
|
172
|
+
putString("displayName", displayName)
|
|
173
|
+
putBoolean("emailVerified", emailVerified)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
package/android/src/main/java/com/doordeck/headlessreactnativesdk/HeadlessReactNativeSdkPackage.kt
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
package com.doordeck.headlessreactnativesdk
|
|
2
|
+
|
|
3
|
+
import com.doordeck.multiplatform.sdk.ApplicationContext
|
|
4
|
+
import com.doordeck.multiplatform.sdk.KDoordeckFactory
|
|
5
|
+
import com.doordeck.multiplatform.sdk.config.SdkConfig
|
|
6
|
+
import com.facebook.react.BaseReactPackage
|
|
7
|
+
import com.facebook.react.bridge.NativeModule
|
|
8
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
10
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
11
|
+
import java.util.HashMap
|
|
12
|
+
|
|
13
|
+
class HeadlessReactNativeSdkPackage : BaseReactPackage() {
|
|
14
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
15
|
+
return if (name == HeadlessReactNativeSdkModule.NAME) {
|
|
16
|
+
HeadlessReactNativeSdkModule(
|
|
17
|
+
reactContext = reactContext,
|
|
18
|
+
doordeckSdk = KDoordeckFactory.initialize(
|
|
19
|
+
SdkConfig.Builder()
|
|
20
|
+
.setApplicationContext(ApplicationContext.apply { set(reactContext.applicationContext)})
|
|
21
|
+
.build()
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
} else {
|
|
25
|
+
null
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
30
|
+
return ReactModuleInfoProvider {
|
|
31
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
32
|
+
moduleInfos[HeadlessReactNativeSdkModule.NAME] = ReactModuleInfo(
|
|
33
|
+
HeadlessReactNativeSdkModule.NAME,
|
|
34
|
+
HeadlessReactNativeSdkModule.NAME,
|
|
35
|
+
false, // canOverrideExistingModule
|
|
36
|
+
false, // needsEagerInit
|
|
37
|
+
false, // isCxxModule
|
|
38
|
+
true // isTurboModule
|
|
39
|
+
)
|
|
40
|
+
moduleInfos
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#import "HeadlessReactNativeSdk.h"
|
|
2
|
+
#import "HeadlessReactNativeSdk-Swift.h"
|
|
3
|
+
|
|
4
|
+
@implementation HeadlessReactNativeSdk {
|
|
5
|
+
HeadlessReactNativeSdkImpl *moduleSdk;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
- (instancetype) init {
|
|
9
|
+
self = [super init];
|
|
10
|
+
if (self) {
|
|
11
|
+
moduleSdk = [HeadlessReactNativeSdkImpl new];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return self;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
RCT_EXPORT_MODULE()
|
|
18
|
+
|
|
19
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
20
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
21
|
+
{
|
|
22
|
+
return std::make_shared<facebook::react::NativeHeadlessReactNativeSdkSpecJSI>(params);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
- (void)getLocksBelongingToTile:(nonnull NSString *)tileId resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
26
|
+
[moduleSdk getLocksBelongingToTile:tileId resolver:resolve rejecter:reject];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
- (void)login:(nonnull NSString *)email password:(nonnull NSString *)password resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
30
|
+
[moduleSdk login:email password:password resolver:resolve rejecter:reject];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (void)getUserDetails:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
34
|
+
[moduleSdk getUserDetails:resolve rejecter:reject];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
- (void)logout:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
38
|
+
[moduleSdk logout:resolve rejecter:reject];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
- (void)setAuthToken:(nonnull NSString *)authToken resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
42
|
+
[moduleSdk setAuthToken:authToken resolver:resolve rejecter:reject];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (void)unlockDevice:(nonnull NSString *)lockId resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
46
|
+
[moduleSdk unlockDevice:lockId resolver:resolve rejecter:reject];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
- (void)verify:(nonnull NSString *)code resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
|
50
|
+
[moduleSdk verify:code resolver:resolve rejecter:reject];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@end
|
|
54
|
+
|