@qafka/react-native-cms 0.0.0-stage → 0.1.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/AGENTS.md +510 -0
- package/README.md +244 -2
- package/android/build.gradle +41 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/qafkacms/QafkaCmsPackage.kt +21 -0
- package/android/src/main/java/com/qafkacms/attestation/QafkaCmsAttestationModule.kt +92 -0
- package/android/src/main/java/com/qafkacms/push/QafkaCmsPushModule.kt +163 -0
- package/android/src/main/java/com/qafkacms/storage/QafkaCmsStorageModule.kt +80 -0
- package/app.plugin.js +1 -0
- package/dist/index.d.ts +2373 -0
- package/dist/index.js +4468 -0
- package/dist/index.js.map +1 -0
- package/expo-plugin/apnsForwarding.js +48 -0
- package/expo-plugin/withQafkaCms.js +23 -0
- package/expo-plugin/withQafkaCmsAttestation.js +27 -0
- package/expo-plugin/withQafkaCmsPush.js +53 -0
- package/ios/QafkaCmsAttestation.m +25 -0
- package/ios/QafkaCmsAttestation.swift +128 -0
- package/ios/QafkaCmsPush.m +22 -0
- package/ios/QafkaCmsPush.swift +143 -0
- package/ios/QafkaCmsReactImports.h +2 -0
- package/ios/QafkaCmsStorage.m +26 -0
- package/ios/QafkaCmsStorage.swift +118 -0
- package/package.json +42 -4
- package/qafkacms.config.d.ts +9 -0
- package/qafkacms.config.js +13 -0
- package/react-native-qafkacms.podspec +20 -0
- package/react-native.config.js +17 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AppDelegate edit for APNs token forwarding (E57), kept free of `expo` so it
|
|
3
|
+
* can be unit-tested.
|
|
4
|
+
*
|
|
5
|
+
* - The code goes into the `AppDelegate` class body. Expo SDK 58's template
|
|
6
|
+
* ends with `ReactNativeDelegate`, so "before the last brace" is wrong.
|
|
7
|
+
* - `QafkaCmsPush` is an internal Swift class of the SDK pod and is not visible
|
|
8
|
+
* to the app target, so it is resolved at runtime through its Objective-C
|
|
9
|
+
* name and selectors (`@objc(QafkaCmsPush)` in ios/QafkaCmsPush.swift).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const MARKER = 'NSClassFromString("QafkaCmsPush")';
|
|
13
|
+
|
|
14
|
+
const SWIFT_FORWARD = `
|
|
15
|
+
// Added by @qafka/react-native-cms (E57): APNs token forwarding to QafkaCmsPush.
|
|
16
|
+
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
|
|
17
|
+
_ = (NSClassFromString("QafkaCmsPush") as AnyObject?)?.perform(NSSelectorFromString("didRegisterForRemoteNotificationsWithDeviceToken:"), with: deviceToken)
|
|
18
|
+
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
|
|
22
|
+
_ = (NSClassFromString("QafkaCmsPush") as AnyObject?)?.perform(NSSelectorFromString("didFailToRegisterForRemoteNotificationsWithError:"), with: error as NSError)
|
|
23
|
+
super.application(application, didFailToRegisterForRemoteNotificationsWithError: error)
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
/** Index of the brace closing the block opened at `open`, or -1. */
|
|
28
|
+
function matchingBrace(src, open) {
|
|
29
|
+
let depth = 0;
|
|
30
|
+
for (let i = open; i < src.length; i++) {
|
|
31
|
+
if (src[i] === '{') depth++;
|
|
32
|
+
else if (src[i] === '}' && --depth === 0) return i;
|
|
33
|
+
}
|
|
34
|
+
return -1;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Insert the forwarding into `class AppDelegate`; idempotent; no-op without one. */
|
|
38
|
+
function injectApnsForwarding(contents) {
|
|
39
|
+
if (contents.includes(MARKER)) return contents;
|
|
40
|
+
const decl = /\bclass\s+AppDelegate\b[^{]*\{/.exec(contents);
|
|
41
|
+
if (!decl) return contents;
|
|
42
|
+
const open = decl.index + decl[0].length - 1;
|
|
43
|
+
const close = matchingBrace(contents, open);
|
|
44
|
+
if (close === -1) return contents;
|
|
45
|
+
return contents.slice(0, close) + SWIFT_FORWARD + contents.slice(close);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = { injectApnsForwarding };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const withQafkaCmsAttestation = require('./withQafkaCmsAttestation');
|
|
2
|
+
const withQafkaCmsPush = require('./withQafkaCmsPush');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Combined QafkaCMS Expo config plugin — applies every native integration the
|
|
6
|
+
* SDK needs:
|
|
7
|
+
* - device attestation entitlement (App Attest), E22/E42;
|
|
8
|
+
* - push: `aps-environment` entitlement + APNs AppDelegate forwarding (iOS)
|
|
9
|
+
* and `POST_NOTIFICATIONS` permission (Android), E57.
|
|
10
|
+
*
|
|
11
|
+
* Usage (app.json / app.config.js):
|
|
12
|
+
* { "plugins": [["@qafkacms/react-native-qafkacms", { "appleEnvironment": "production" }]] }
|
|
13
|
+
*
|
|
14
|
+
* `appleEnvironment` ("production" | "development") feeds both the App Attest and
|
|
15
|
+
* the APNs environments.
|
|
16
|
+
*/
|
|
17
|
+
const withQafkaCms = (config, props = {}) => {
|
|
18
|
+
let cfg = withQafkaCmsAttestation(config, props);
|
|
19
|
+
cfg = withQafkaCmsPush(cfg, props);
|
|
20
|
+
return cfg;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = withQafkaCms;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { withEntitlementsPlist } = require('expo/config-plugins');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Expo config plugin for QafkaCMS device attestation.
|
|
5
|
+
*
|
|
6
|
+
* iOS App Attest requires the DeviceCheck App Attest entitlement to be present
|
|
7
|
+
* in the build's entitlements; without it `DCAppAttestService.generateKey()`
|
|
8
|
+
* fails at runtime on real devices. This injects it so a release build can
|
|
9
|
+
* attest. (Android Key Attestation uses the AndroidKeyStore core API and needs
|
|
10
|
+
* no Gradle/manifest changes, so there is no Android counterpart here.)
|
|
11
|
+
*
|
|
12
|
+
* Usage (app.json / app.config.js):
|
|
13
|
+
* { "plugins": [["@qafka/react-native-cms", { "appleEnvironment": "production" }]] }
|
|
14
|
+
*
|
|
15
|
+
* `appleEnvironment` is "production" (default) or "development". Use
|
|
16
|
+
* "development" only for builds attesting against Apple's development
|
|
17
|
+
* App Attest environment.
|
|
18
|
+
*/
|
|
19
|
+
const withQafkaCmsAttestation = (config, { appleEnvironment = 'production' } = {}) => {
|
|
20
|
+
return withEntitlementsPlist(config, (cfg) => {
|
|
21
|
+
cfg.modResults['com.apple.developer.devicecheck.appattest-environment'] =
|
|
22
|
+
appleEnvironment;
|
|
23
|
+
return cfg;
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = withQafkaCmsAttestation;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const {
|
|
2
|
+
withEntitlementsPlist,
|
|
3
|
+
withAppDelegate,
|
|
4
|
+
AndroidConfig,
|
|
5
|
+
} = require('expo/config-plugins');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Expo config plugin for QafkaCMS push token collection (E57).
|
|
9
|
+
*
|
|
10
|
+
* iOS (raw APNs, no Firebase):
|
|
11
|
+
* - adds the `aps-environment` entitlement (required to register for remote
|
|
12
|
+
* notifications);
|
|
13
|
+
* - forwards the AppDelegate's `didRegister/didFailToRegister...` callbacks
|
|
14
|
+
* into the native `QafkaCmsPush` module so `getToken()` can resolve.
|
|
15
|
+
* Android (FCM via a SDK-bundled secondary FirebaseApp):
|
|
16
|
+
* - adds the `POST_NOTIFICATIONS` runtime permission (Android 13+).
|
|
17
|
+
*
|
|
18
|
+
* NOTE: the iOS AppDelegate forwarding is injected for the Swift AppDelegate
|
|
19
|
+
* (the Expo default). It is idempotent. On-device verification (real APNs token)
|
|
20
|
+
* is required — see QFK2-E57 task 57.9. Apps with a custom/ObjC AppDelegate
|
|
21
|
+
* should forward the two callbacks to `QafkaCmsPush` manually.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const { injectApnsForwarding } = require('./apnsForwarding');
|
|
25
|
+
|
|
26
|
+
function withApsEntitlement(config, appleEnvironment) {
|
|
27
|
+
return withEntitlementsPlist(config, (cfg) => {
|
|
28
|
+
cfg.modResults['aps-environment'] = appleEnvironment;
|
|
29
|
+
return cfg;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function withApnsForwarding(config) {
|
|
34
|
+
return withAppDelegate(config, (cfg) => {
|
|
35
|
+
if (cfg.modResults.language !== 'swift') {
|
|
36
|
+
// ObjC AppDelegate — leave a breadcrumb; manual forwarding required.
|
|
37
|
+
return cfg;
|
|
38
|
+
}
|
|
39
|
+
cfg.modResults.contents = injectApnsForwarding(cfg.modResults.contents);
|
|
40
|
+
return cfg;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const withQafkaCmsPush = (config, { appleEnvironment = 'production' } = {}) => {
|
|
45
|
+
let cfg = withApsEntitlement(config, appleEnvironment);
|
|
46
|
+
cfg = withApnsForwarding(cfg);
|
|
47
|
+
cfg = AndroidConfig.Permissions.withPermissions(cfg, [
|
|
48
|
+
'android.permission.POST_NOTIFICATIONS',
|
|
49
|
+
]);
|
|
50
|
+
return cfg;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = withQafkaCmsPush;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(QafkaCmsAttestation, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(isSupported:
|
|
6
|
+
(RCTPromiseResolveBlock)resolve
|
|
7
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
8
|
+
|
|
9
|
+
RCT_EXTERN_METHOD(generateKey:
|
|
10
|
+
(RCTPromiseResolveBlock)resolve
|
|
11
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
12
|
+
|
|
13
|
+
RCT_EXTERN_METHOD(attestKey:
|
|
14
|
+
(NSString *)keyId
|
|
15
|
+
challengeBase64:(NSString *)challengeBase64
|
|
16
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
17
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
18
|
+
|
|
19
|
+
RCT_EXTERN_METHOD(generateAssertion:
|
|
20
|
+
(NSString *)keyId
|
|
21
|
+
clientDataBase64:(NSString *)clientDataBase64
|
|
22
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
23
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
24
|
+
|
|
25
|
+
@end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import DeviceCheck
|
|
3
|
+
import CryptoKit
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
@objc(QafkaCmsAttestation)
|
|
7
|
+
class QafkaCmsAttestation: NSObject {
|
|
8
|
+
|
|
9
|
+
@objc static func requiresMainQueueSetup() -> Bool {
|
|
10
|
+
return true
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@objc func constantsToExport() -> [AnyHashable: Any]! {
|
|
14
|
+
let bundle = Bundle.main
|
|
15
|
+
let bundleId = bundle.bundleIdentifier ?? ""
|
|
16
|
+
let appVersion = bundle.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
|
|
17
|
+
let deviceModel = UIDevice.current.model
|
|
18
|
+
return [
|
|
19
|
+
"bundleId": bundleId,
|
|
20
|
+
"appVersion": appVersion,
|
|
21
|
+
"deviceModel": deviceModel,
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@objc func isSupported(
|
|
26
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
27
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
28
|
+
) {
|
|
29
|
+
if #available(iOS 14.0, *) {
|
|
30
|
+
resolve(DCAppAttestService.shared.isSupported)
|
|
31
|
+
} else {
|
|
32
|
+
resolve(false)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@objc func generateKey(
|
|
37
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
38
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
39
|
+
) {
|
|
40
|
+
guard #available(iOS 14.0, *) else {
|
|
41
|
+
reject("UNSUPPORTED", "App Attest requires iOS 14+", nil)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
let service = DCAppAttestService.shared
|
|
45
|
+
guard service.isSupported else {
|
|
46
|
+
reject("UNSUPPORTED", "App Attest not supported on this device", nil)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
service.generateKey { keyId, error in
|
|
51
|
+
if let error = error {
|
|
52
|
+
reject("KEY_GEN_FAILED", error.localizedDescription, error)
|
|
53
|
+
} else if let keyId = keyId {
|
|
54
|
+
resolve(keyId)
|
|
55
|
+
} else {
|
|
56
|
+
reject("KEY_GEN_FAILED", "Unknown error generating key", nil)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@objc func attestKey(
|
|
62
|
+
_ keyId: String,
|
|
63
|
+
challengeBase64: String,
|
|
64
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
65
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
66
|
+
) {
|
|
67
|
+
guard #available(iOS 14.0, *) else {
|
|
68
|
+
reject("UNSUPPORTED", "App Attest requires iOS 14+", nil)
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
guard let challengeData = Data(base64Encoded: challengeBase64) else {
|
|
73
|
+
reject("INVALID_INPUT", "Invalid base64 challenge", nil)
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let hash = Data(SHA256.hash(data: challengeData))
|
|
78
|
+
|
|
79
|
+
DCAppAttestService.shared.attestKey(keyId, clientDataHash: hash) { attestation, error in
|
|
80
|
+
if let error = error {
|
|
81
|
+
let code: String
|
|
82
|
+
if let dcError = error as? DCError {
|
|
83
|
+
switch dcError.code {
|
|
84
|
+
case .invalidKey: code = "INVALID_KEY"
|
|
85
|
+
case .serverUnavailable: code = "SERVER_UNAVAILABLE"
|
|
86
|
+
default: code = "ATTEST_FAILED"
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
code = "ATTEST_FAILED"
|
|
90
|
+
}
|
|
91
|
+
reject(code, error.localizedDescription, error)
|
|
92
|
+
} else if let attestation = attestation {
|
|
93
|
+
resolve(attestation.base64EncodedString())
|
|
94
|
+
} else {
|
|
95
|
+
reject("ATTEST_FAILED", "Unknown error during attestation", nil)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
@objc func generateAssertion(
|
|
101
|
+
_ keyId: String,
|
|
102
|
+
clientDataBase64: String,
|
|
103
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
104
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
105
|
+
) {
|
|
106
|
+
guard #available(iOS 14.0, *) else {
|
|
107
|
+
reject("UNSUPPORTED", "App Attest requires iOS 14+", nil)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
guard let clientData = Data(base64Encoded: clientDataBase64) else {
|
|
112
|
+
reject("INVALID_INPUT", "Invalid base64 client data", nil)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let hash = Data(SHA256.hash(data: clientData))
|
|
117
|
+
|
|
118
|
+
DCAppAttestService.shared.generateAssertion(keyId, clientDataHash: hash) { assertion, error in
|
|
119
|
+
if let error = error {
|
|
120
|
+
reject("ASSERTION_FAILED", error.localizedDescription, error)
|
|
121
|
+
} else if let assertion = assertion {
|
|
122
|
+
resolve(assertion.base64EncodedString())
|
|
123
|
+
} else {
|
|
124
|
+
reject("ASSERTION_FAILED", "Unknown error generating assertion", nil)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(QafkaCmsPush, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(getPermissionStatus:
|
|
6
|
+
(RCTPromiseResolveBlock)resolve
|
|
7
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
8
|
+
|
|
9
|
+
RCT_EXTERN_METHOD(requestPermission:
|
|
10
|
+
(RCTPromiseResolveBlock)resolve
|
|
11
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
12
|
+
|
|
13
|
+
RCT_EXTERN_METHOD(getToken:
|
|
14
|
+
(NSDictionary *)androidConfig
|
|
15
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
16
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
17
|
+
|
|
18
|
+
RCT_EXTERN_METHOD(getDeviceInfo:
|
|
19
|
+
(RCTPromiseResolveBlock)resolve
|
|
20
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
21
|
+
|
|
22
|
+
@end
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
import UserNotifications
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Native push token collection (E57) — iOS, dependency-free (raw APNs, no
|
|
7
|
+
* Firebase iOS SDK).
|
|
8
|
+
*
|
|
9
|
+
* The APNs device token arrives asynchronously in the app's `AppDelegate`
|
|
10
|
+
* (`application(_:didRegisterForRemoteNotificationsWithDeviceToken:)`). The Expo
|
|
11
|
+
* config plugin (`withQafkaCmsPush`) wires that callback to forward into the
|
|
12
|
+
* static hooks below. `getToken()` registers for remote notifications and parks
|
|
13
|
+
* a resolver until the token (or a failure) arrives; a cached token resolves
|
|
14
|
+
* immediately. iOS ignores the `androidConfig` argument.
|
|
15
|
+
*/
|
|
16
|
+
@objc(QafkaCmsPush)
|
|
17
|
+
class QafkaCmsPush: NSObject {
|
|
18
|
+
|
|
19
|
+
private static var cachedToken: String?
|
|
20
|
+
private static var pendingResolvers: [(String?) -> Void] = []
|
|
21
|
+
private static let lock = NSLock()
|
|
22
|
+
|
|
23
|
+
@objc static func requiresMainQueueSetup() -> Bool {
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// MARK: - AppDelegate forwarding (wired by the Expo config plugin)
|
|
28
|
+
|
|
29
|
+
/// Forward `didRegisterForRemoteNotificationsWithDeviceToken` here.
|
|
30
|
+
@objc(didRegisterForRemoteNotificationsWithDeviceToken:)
|
|
31
|
+
static func didRegister(deviceToken: Data) {
|
|
32
|
+
let token = deviceToken.map { String(format: "%02x", $0) }.joined()
|
|
33
|
+
lock.lock()
|
|
34
|
+
cachedToken = token
|
|
35
|
+
let resolvers = pendingResolvers
|
|
36
|
+
pendingResolvers.removeAll()
|
|
37
|
+
lock.unlock()
|
|
38
|
+
resolvers.forEach { $0(token) }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Forward `didFailToRegisterForRemoteNotificationsWithError` here.
|
|
42
|
+
@objc(didFailToRegisterForRemoteNotificationsWithError:)
|
|
43
|
+
static func didFail(error: Error) {
|
|
44
|
+
lock.lock()
|
|
45
|
+
let resolvers = pendingResolvers
|
|
46
|
+
pendingResolvers.removeAll()
|
|
47
|
+
lock.unlock()
|
|
48
|
+
resolvers.forEach { $0(nil) }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// MARK: - Permission
|
|
52
|
+
|
|
53
|
+
private func map(_ status: UNAuthorizationStatus) -> String {
|
|
54
|
+
switch status {
|
|
55
|
+
case .authorized, .provisional, .ephemeral: return "granted"
|
|
56
|
+
case .denied: return "denied"
|
|
57
|
+
case .notDetermined: return "undetermined"
|
|
58
|
+
@unknown default: return "undetermined"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@objc func getPermissionStatus(
|
|
63
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
64
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
65
|
+
) {
|
|
66
|
+
UNUserNotificationCenter.current().getNotificationSettings { settings in
|
|
67
|
+
resolve(self.map(settings.authorizationStatus))
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@objc func requestPermission(
|
|
72
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
73
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
74
|
+
) {
|
|
75
|
+
UNUserNotificationCenter.current().requestAuthorization(
|
|
76
|
+
options: [.alert, .badge, .sound]
|
|
77
|
+
) { granted, _ in
|
|
78
|
+
if granted {
|
|
79
|
+
DispatchQueue.main.async {
|
|
80
|
+
UIApplication.shared.registerForRemoteNotifications()
|
|
81
|
+
}
|
|
82
|
+
resolve("granted")
|
|
83
|
+
} else {
|
|
84
|
+
resolve("denied")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// MARK: - Token
|
|
90
|
+
|
|
91
|
+
@objc func getToken(
|
|
92
|
+
_ androidConfig: NSDictionary?,
|
|
93
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
94
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
95
|
+
) {
|
|
96
|
+
if let token = QafkaCmsPush.cachedToken {
|
|
97
|
+
resolve(token)
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
QafkaCmsPush.lock.lock()
|
|
102
|
+
QafkaCmsPush.pendingResolvers.append { token in resolve(token) }
|
|
103
|
+
QafkaCmsPush.lock.unlock()
|
|
104
|
+
|
|
105
|
+
DispatchQueue.main.async {
|
|
106
|
+
UIApplication.shared.registerForRemoteNotifications()
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Safety net: never wedge the JS side if APNs is slow/unreachable.
|
|
110
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 15) {
|
|
111
|
+
QafkaCmsPush.lock.lock()
|
|
112
|
+
let resolvers = QafkaCmsPush.pendingResolvers
|
|
113
|
+
QafkaCmsPush.pendingResolvers.removeAll()
|
|
114
|
+
QafkaCmsPush.lock.unlock()
|
|
115
|
+
resolvers.forEach { $0(QafkaCmsPush.cachedToken) }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// MARK: - Device info
|
|
120
|
+
|
|
121
|
+
@objc func getDeviceInfo(
|
|
122
|
+
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
123
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
124
|
+
) {
|
|
125
|
+
resolve([
|
|
126
|
+
"osVersion": "iOS \(UIDevice.current.systemVersion)",
|
|
127
|
+
"model": QafkaCmsPush.hardwareModel(),
|
|
128
|
+
"brand": "Apple",
|
|
129
|
+
])
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private static func hardwareModel() -> String {
|
|
133
|
+
var systemInfo = utsname()
|
|
134
|
+
uname(&systemInfo)
|
|
135
|
+
let identifier = Mirror(reflecting: systemInfo.machine).children
|
|
136
|
+
.reduce(into: "") { acc, element in
|
|
137
|
+
if let value = element.value as? Int8, value != 0 {
|
|
138
|
+
acc.append(Character(UnicodeScalar(UInt8(value))))
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return identifier.isEmpty ? UIDevice.current.model : identifier
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
|
|
3
|
+
@interface RCT_EXTERN_MODULE(QafkaCmsStorage, NSObject)
|
|
4
|
+
|
|
5
|
+
RCT_EXTERN_METHOD(getItem:
|
|
6
|
+
(NSString *)key
|
|
7
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
8
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
9
|
+
|
|
10
|
+
RCT_EXTERN_METHOD(setItem:
|
|
11
|
+
(NSString *)key
|
|
12
|
+
value:(NSString *)value
|
|
13
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
14
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
15
|
+
|
|
16
|
+
RCT_EXTERN_METHOD(removeItem:
|
|
17
|
+
(NSString *)key
|
|
18
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
19
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
20
|
+
|
|
21
|
+
RCT_EXTERN_METHOD(multiRemove:
|
|
22
|
+
(NSArray<NSString *> *)keys
|
|
23
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
24
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
25
|
+
|
|
26
|
+
@end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Security
|
|
3
|
+
|
|
4
|
+
@objc(QafkaCmsStorage)
|
|
5
|
+
class QafkaCmsStorage: NSObject {
|
|
6
|
+
|
|
7
|
+
private static let service = "app.qafkacms.sdk"
|
|
8
|
+
|
|
9
|
+
@objc static func requiresMainQueueSetup() -> Bool {
|
|
10
|
+
return false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// MARK: - Helpers
|
|
14
|
+
|
|
15
|
+
private func baseQuery(forKey key: String) -> [String: Any] {
|
|
16
|
+
return [
|
|
17
|
+
kSecClass as String: kSecClassGenericPassword,
|
|
18
|
+
kSecAttrService as String: QafkaCmsStorage.service,
|
|
19
|
+
kSecAttrAccount as String: key,
|
|
20
|
+
kSecAttrSynchronizable as String: kCFBooleanFalse as Any,
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// MARK: - React methods
|
|
25
|
+
|
|
26
|
+
@objc func getItem(
|
|
27
|
+
_ key: String,
|
|
28
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
29
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
30
|
+
) {
|
|
31
|
+
var query = baseQuery(forKey: key)
|
|
32
|
+
query[kSecReturnData as String] = kCFBooleanTrue
|
|
33
|
+
query[kSecMatchLimit as String] = kSecMatchLimitOne
|
|
34
|
+
|
|
35
|
+
var item: CFTypeRef?
|
|
36
|
+
let status = SecItemCopyMatching(query as CFDictionary, &item)
|
|
37
|
+
|
|
38
|
+
switch status {
|
|
39
|
+
case errSecSuccess:
|
|
40
|
+
if let data = item as? Data, let str = String(data: data, encoding: .utf8) {
|
|
41
|
+
resolve(str)
|
|
42
|
+
} else {
|
|
43
|
+
resolve(NSNull())
|
|
44
|
+
}
|
|
45
|
+
case errSecItemNotFound:
|
|
46
|
+
resolve(NSNull())
|
|
47
|
+
default:
|
|
48
|
+
reject("KEYCHAIN_READ_FAILED", "Keychain read failed (OSStatus \(status))", nil)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@objc func setItem(
|
|
53
|
+
_ key: String,
|
|
54
|
+
value: String,
|
|
55
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
56
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
57
|
+
) {
|
|
58
|
+
guard let data = value.data(using: .utf8) else {
|
|
59
|
+
reject("INVALID_INPUT", "Value is not valid UTF-8", nil)
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let query = baseQuery(forKey: key)
|
|
64
|
+
let updateAttrs: [String: Any] = [
|
|
65
|
+
kSecValueData as String: data,
|
|
66
|
+
kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlock,
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
let updateStatus = SecItemUpdate(query as CFDictionary, updateAttrs as CFDictionary)
|
|
70
|
+
if updateStatus == errSecSuccess {
|
|
71
|
+
resolve(NSNull())
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
if updateStatus != errSecItemNotFound {
|
|
75
|
+
reject("KEYCHAIN_UPDATE_FAILED", "Keychain update failed (OSStatus \(updateStatus))", nil)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var addQuery = query
|
|
80
|
+
addQuery[kSecValueData as String] = data
|
|
81
|
+
addQuery[kSecAttrAccessible as String] = kSecAttrAccessibleAfterFirstUnlock
|
|
82
|
+
|
|
83
|
+
let addStatus = SecItemAdd(addQuery as CFDictionary, nil)
|
|
84
|
+
if addStatus == errSecSuccess {
|
|
85
|
+
resolve(NSNull())
|
|
86
|
+
} else {
|
|
87
|
+
reject("KEYCHAIN_ADD_FAILED", "Keychain add failed (OSStatus \(addStatus))", nil)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@objc func removeItem(
|
|
92
|
+
_ key: String,
|
|
93
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
94
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
95
|
+
) {
|
|
96
|
+
let status = SecItemDelete(baseQuery(forKey: key) as CFDictionary)
|
|
97
|
+
if status == errSecSuccess || status == errSecItemNotFound {
|
|
98
|
+
resolve(NSNull())
|
|
99
|
+
} else {
|
|
100
|
+
reject("KEYCHAIN_DELETE_FAILED", "Keychain delete failed (OSStatus \(status))", nil)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@objc func multiRemove(
|
|
105
|
+
_ keys: [String],
|
|
106
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
107
|
+
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
108
|
+
) {
|
|
109
|
+
for key in keys {
|
|
110
|
+
let status = SecItemDelete(baseQuery(forKey: key) as CFDictionary)
|
|
111
|
+
if status != errSecSuccess && status != errSecItemNotFound {
|
|
112
|
+
reject("KEYCHAIN_DELETE_FAILED", "Keychain delete failed for key \(key) (OSStatus \(status))", nil)
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
resolve(NSNull())
|
|
117
|
+
}
|
|
118
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qafka/react-native-cms",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "QafkaCMS React Native runtime SDK — auth, content API, device attestation, secure storage, config-sync.",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"react-native": "./dist/index.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"ios/",
|
|
12
|
+
"android/",
|
|
13
|
+
"expo-plugin/",
|
|
14
|
+
"app.plugin.js",
|
|
15
|
+
"react-native-qafkacms.podspec",
|
|
16
|
+
"react-native.config.js",
|
|
17
|
+
"qafkacms.config.js",
|
|
18
|
+
"qafkacms.config.d.ts",
|
|
19
|
+
"README.md",
|
|
20
|
+
"AGENTS.md"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "rm -rf dist tsconfig.tsbuildinfo && tsup",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"lint": "echo \"(lint placeholder — eslint pending)\"",
|
|
27
|
+
"test": "jest",
|
|
28
|
+
"prepublishOnly": "pnpm build && pnpm typecheck && pnpm test"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": ">=18.0.0",
|
|
32
|
+
"react-native": ">=0.72.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@qafka/cms-core": "workspace:*",
|
|
36
|
+
"@qafka/cms-react": "workspace:*"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22.0.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Generated by QafkaCMS CLI — do not edit by hand.
|
|
2
|
+
// Augmented with the consumer's real project ids by `qafkacms login` (QFK2-E44)
|
|
3
|
+
// to give `<QafkaCMS projectId="..." />` literal-typed autocomplete.
|
|
4
|
+
declare const config: {
|
|
5
|
+
defaultProjectId?: string;
|
|
6
|
+
apiUrl?: string;
|
|
7
|
+
projects: Record<string, { developmentKey?: string }>;
|
|
8
|
+
};
|
|
9
|
+
export = config;
|