@react-native-ohos/cookies 6.2.2-rc.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 +21 -0
- package/README.md +14 -0
- package/harmony/rn_cookies/BuildProfile.ets +17 -0
- package/harmony/rn_cookies/Index.ets +1 -0
- package/harmony/rn_cookies/build-profile.json5 +28 -0
- package/harmony/rn_cookies/consumer-rules.txt +0 -0
- package/harmony/rn_cookies/hvigorfile.ts +6 -0
- package/harmony/rn_cookies/obfuscation-rules.txt +18 -0
- package/harmony/rn_cookies/oh-package-lock.json5 +18 -0
- package/harmony/rn_cookies/oh-package.json5 +11 -0
- package/harmony/rn_cookies/src/main/cpp/CMakeLists.txt +10 -0
- package/harmony/rn_cookies/src/main/cpp/CookiesPackage.h +19 -0
- package/harmony/rn_cookies/src/main/cpp/CookiesTurboModule.cpp +57 -0
- package/harmony/rn_cookies/src/main/cpp/CookiesTurboModule.h +25 -0
- package/harmony/rn_cookies/src/main/cpp/generated/RNOH/generated/BaseReactNativeCookiesPackage.h +72 -0
- package/harmony/rn_cookies/src/main/cpp/generated/RNOH/generated/turbo_modules/RTNCookies.cpp +21 -0
- package/harmony/rn_cookies/src/main/cpp/generated/RNOH/generated/turbo_modules/RTNCookies.h +16 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/ComponentDescriptors.h +24 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/EventEmitters.cpp +16 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/EventEmitters.h +17 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/Props.cpp +19 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/Props.h +18 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/ShadowNodes.cpp +17 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/ShadowNodes.h +23 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/States.cpp +16 -0
- package/harmony/rn_cookies/src/main/cpp/generated/react/renderer/components/react_native_cookies/States.h +19 -0
- package/harmony/rn_cookies/src/main/ets/CookiesModule.ts +177 -0
- package/harmony/rn_cookies/src/main/ets/CookiesPackage.ts +26 -0
- package/harmony/rn_cookies/src/main/ets/Logger.ets +64 -0
- package/harmony/rn_cookies/src/main/ets/generated/components/ts.ts +5 -0
- package/harmony/rn_cookies/src/main/ets/generated/index.ets +5 -0
- package/harmony/rn_cookies/src/main/ets/generated/ts.ts +6 -0
- package/harmony/rn_cookies/src/main/ets/generated/turboModules/RTNCookies.ts +26 -0
- package/harmony/rn_cookies/src/main/ets/generated/turboModules/ts.ts +5 -0
- package/harmony/rn_cookies/src/main/module.json5 +11 -0
- package/harmony/rn_cookies/src/main/resources/base/element/string.json +8 -0
- package/harmony/rn_cookies/src/main/resources/en_US/element/string.json +8 -0
- package/harmony/rn_cookies/src/main/resources/zh_CN/element/string.json +8 -0
- package/harmony/rn_cookies/src/test/List.test.ets +5 -0
- package/harmony/rn_cookies/src/test/LocalUnit.test.ets +33 -0
- package/harmony/rn_cookies/ts.ts +2 -0
- package/harmony/rn_cookies.har +0 -0
- package/index.d.ts +43 -0
- package/index.js +62 -0
- package/package.json +59 -0
- package/react-native-cookies.podspec +18 -0
- package/src/NativeRTNCookies.tsx +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 React Native Community
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @react-native-oh-tpl/react-native-cookies
|
|
2
|
+
|
|
3
|
+
This project is based on [cookies](https://github.com/react-native-cookies/cookies)
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
- [中文](https://gitee.com/react-native-oh-library/usage-docs/blob/master/zh-cn/react-native-cookies-cookies.md)
|
|
8
|
+
|
|
9
|
+
- [English](https://gitee.com/react-native-oh-library/usage-docs/blob/master/en/react-native-cookies-cookies.md)
|
|
10
|
+
|
|
11
|
+
## License
|
|
12
|
+
|
|
13
|
+
This library is licensed under [The MIT License (MIT)](https://github.com/react-native-oh-library/react-native-cookies/blob/sig/LICENSE)
|
|
14
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use these variables when you tailor your ArkTS code. They must be of the const type.
|
|
3
|
+
*/
|
|
4
|
+
export const HAR_VERSION = '6.2.1-0.0.8';
|
|
5
|
+
export const BUILD_MODE_NAME = 'debug';
|
|
6
|
+
export const DEBUG = true;
|
|
7
|
+
export const TARGET_NAME = 'default';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* BuildProfile Class is used only for compatibility purposes.
|
|
11
|
+
*/
|
|
12
|
+
export default class BuildProfile {
|
|
13
|
+
static readonly HAR_VERSION = HAR_VERSION;
|
|
14
|
+
static readonly BUILD_MODE_NAME = BUILD_MODE_NAME;
|
|
15
|
+
static readonly DEBUG = DEBUG;
|
|
16
|
+
static readonly TARGET_NAME = TARGET_NAME;
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ts'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"apiType": "stageMode",
|
|
3
|
+
"buildOption": {
|
|
4
|
+
},
|
|
5
|
+
"buildOptionSet": [
|
|
6
|
+
{
|
|
7
|
+
"name": "release",
|
|
8
|
+
"arkOptions": {
|
|
9
|
+
"obfuscation": {
|
|
10
|
+
"ruleOptions": {
|
|
11
|
+
"enable": true,
|
|
12
|
+
"files": [
|
|
13
|
+
"./obfuscation-rules.txt"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"consumerFiles": [
|
|
17
|
+
"./consumer-rules.txt"
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
"targets": [
|
|
24
|
+
{
|
|
25
|
+
"name": "default"
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Define project specific obfuscation rules here.
|
|
2
|
+
# You can include the obfuscation configuration files in the current module's build-profile.json5.
|
|
3
|
+
#
|
|
4
|
+
# For more details, see
|
|
5
|
+
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
|
|
6
|
+
|
|
7
|
+
# Obfuscation options:
|
|
8
|
+
# -disable-obfuscation: disable all obfuscations
|
|
9
|
+
# -enable-property-obfuscation: obfuscate the property names
|
|
10
|
+
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
|
|
11
|
+
# -compact: remove unnecessary blank spaces and all line feeds
|
|
12
|
+
# -remove-log: remove all console.* statements
|
|
13
|
+
# -print-namecache: print the name cache that contains the mapping from the old names to new names
|
|
14
|
+
# -apply-namecache: reuse the given cache file
|
|
15
|
+
|
|
16
|
+
# Keep options:
|
|
17
|
+
# -keep-property-name: specifies property names that you want to keep
|
|
18
|
+
# -keep-global-name: specifies names that you want to keep in the global scope
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"stableOrder": false
|
|
4
|
+
},
|
|
5
|
+
"lockfileVersion": 3,
|
|
6
|
+
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
|
7
|
+
"specifiers": {
|
|
8
|
+
"@rnoh/react-native-openharmony@../libs/react_native_openharmony-5.0.0.491.har": "@rnoh/react-native-openharmony@../libs/react_native_openharmony-5.0.0.491.har"
|
|
9
|
+
},
|
|
10
|
+
"packages": {
|
|
11
|
+
"@rnoh/react-native-openharmony@../libs/react_native_openharmony-5.0.0.491.har": {
|
|
12
|
+
"name": "@rnoh/react-native-openharmony",
|
|
13
|
+
"version": "0.72.28",
|
|
14
|
+
"resolved": "../libs/react_native_openharmony-5.0.0.491.har",
|
|
15
|
+
"registryType": "local"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native-ohos/cookies",
|
|
3
|
+
"version": "6.2.2-rc.1",
|
|
4
|
+
"description": "Please describe the basic information.",
|
|
5
|
+
"main": "Index.ets",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@rnoh/react-native-openharmony": "file:../react_native_openharmony"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# the minimum version of CMake
|
|
2
|
+
cmake_minimum_required(VERSION 3.13)
|
|
3
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
4
|
+
|
|
5
|
+
set(rnoh_cookies_generated_dir "${CMAKE_CURRENT_SOURCE_DIR}/generated")
|
|
6
|
+
file(GLOB_RECURSE rnoh_cookies_generated_SRC "${rnoh_cookies_generated_dir}/**/*.cpp")
|
|
7
|
+
file(GLOB rnoh_cookies_SRC CONFIGURE_DEPENDS *.cpp)
|
|
8
|
+
add_library(rnoh_cookies SHARED ${rnoh_cookies_SRC} ${rnoh_cookies_generated_SRC})
|
|
9
|
+
target_include_directories(rnoh_cookies PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${rnoh_cookies_generated_dir} ${CMAKE_CURRENT_SOURCE_DIR}/generated/RNOH/generated)
|
|
10
|
+
target_link_libraries(rnoh_cookies PUBLIC rnoh)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
#ifndef COOKIESPACKAGE_H
|
|
6
|
+
#define COOKIESPACKAGE_H
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
#include "generated/RNOH/generated/BaseReactNativeCookiesPackage.h"
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
namespace rnoh {
|
|
14
|
+
class CookiesPackage : public BaseReactNativeCookiesPackage {
|
|
15
|
+
using Super = BaseReactNativeCookiesPackage;
|
|
16
|
+
using Super::Super;
|
|
17
|
+
};
|
|
18
|
+
} // namespace rnoh
|
|
19
|
+
#endif //COOKIESPACKAGE_H
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
|
|
4
|
+
* Licensed under the The MIT License (MIT) (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
* https://github.com/react-native-cookies/cookies/blob/master/LICENSE
|
|
9
|
+
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include "CookiesTurboModule.h"
|
|
18
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
19
|
+
|
|
20
|
+
using namespace rnoh;
|
|
21
|
+
using namespace facebook;
|
|
22
|
+
|
|
23
|
+
static jsi::Value __hostFunction_RTNCookiesTurboModule_get(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
24
|
+
const jsi::Value *args, size_t count) {
|
|
25
|
+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "get", args, count);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static jsi::Value __hostFunction_RTNCookiesTurboModule_set(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
29
|
+
const jsi::Value *args, size_t count) {
|
|
30
|
+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "set", args, count);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static jsi::Value __hostFunction_RTNCookiesTurboModule_clearByName(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
34
|
+
const jsi::Value *args, size_t count) {
|
|
35
|
+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "clearByName", args, count);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static jsi::Value __hostFunction_RTNCookiesTurboModule_clearAll(jsi::Runtime &rt, react::TurboModule &turboModule,
|
|
39
|
+
const jsi::Value *args, size_t count) {
|
|
40
|
+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "clearAll", args, count);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static jsi::Value __hostFunction_RTNCookiesTurboModule_removeSessionCookies(jsi::Runtime &rt,
|
|
44
|
+
react::TurboModule &turboModule,
|
|
45
|
+
const jsi::Value *args, size_t count) {
|
|
46
|
+
return static_cast<ArkTSTurboModule &>(turboModule).callAsync(rt, "removeSessionCookies", args, count);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
RTNCookiesTurboModule::RTNCookiesTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
|
|
51
|
+
: ArkTSTurboModule(ctx, name) {
|
|
52
|
+
methodMap_["get"] = MethodMetadata{2, __hostFunction_RTNCookiesTurboModule_get};
|
|
53
|
+
methodMap_["set"] = MethodMetadata{3, __hostFunction_RTNCookiesTurboModule_set};
|
|
54
|
+
methodMap_["clearByName"] = MethodMetadata{3, __hostFunction_RTNCookiesTurboModule_clearByName};
|
|
55
|
+
methodMap_["clearAll"] = MethodMetadata{1, __hostFunction_RTNCookiesTurboModule_clearAll};
|
|
56
|
+
methodMap_["removeSessionCookies"] = MethodMetadata{0, __hostFunction_RTNCookiesTurboModule_removeSessionCookies};
|
|
57
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
|
|
4
|
+
* Licensed under the The MIT License (MIT) (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
* https://github.com/react-native-cookies/cookies/blob/master/LICENSE
|
|
9
|
+
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#pragma once
|
|
18
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
19
|
+
|
|
20
|
+
namespace rnoh {
|
|
21
|
+
class JSI_EXPORT RTNCookiesTurboModule : public ArkTSTurboModule {
|
|
22
|
+
public:
|
|
23
|
+
RTNCookiesTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
24
|
+
};
|
|
25
|
+
} // namespace rnoh
|
package/harmony/rn_cookies/src/main/cpp/generated/RNOH/generated/BaseReactNativeCookiesPackage.h
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "RNOH/Package.h"
|
|
8
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
9
|
+
#include "RNOH/generated/turbo_modules/RTNCookies.h"
|
|
10
|
+
|
|
11
|
+
namespace rnoh {
|
|
12
|
+
|
|
13
|
+
class BaseReactNativeCookiesPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
|
14
|
+
public:
|
|
15
|
+
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
|
16
|
+
if (name == "RTNCookies") {
|
|
17
|
+
return std::make_shared<RTNCookies>(ctx, name);
|
|
18
|
+
}
|
|
19
|
+
return nullptr;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class BaseReactNativeCookiesPackageEventEmitRequestHandler : public EventEmitRequestHandler {
|
|
24
|
+
public:
|
|
25
|
+
void handleEvent(Context const &ctx) override {
|
|
26
|
+
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
|
27
|
+
auto componentName = ctx.shadowViewRegistry->getComponentName(ctx.tag);
|
|
28
|
+
|
|
29
|
+
if (eventEmitter == nullptr) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
std::vector<std::string> supportedComponentNames = {
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
std::vector<std::string> supportedEventNames = {
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
if (std::find(supportedComponentNames.begin(), supportedComponentNames.end(), componentName) != supportedComponentNames.end() &&
|
|
40
|
+
std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
|
41
|
+
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class BaseReactNativeCookiesPackage : public Package {
|
|
48
|
+
public:
|
|
49
|
+
BaseReactNativeCookiesPackage(Package::Context ctx) : Package(ctx){};
|
|
50
|
+
|
|
51
|
+
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
|
52
|
+
return std::make_unique<BaseReactNativeCookiesPackageTurboModuleFactoryDelegate>();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
|
56
|
+
return {
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
|
61
|
+
return {
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
|
66
|
+
return {
|
|
67
|
+
std::make_shared<BaseReactNativeCookiesPackageEventEmitRequestHandler>(),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#include "RTNCookies.h"
|
|
6
|
+
|
|
7
|
+
namespace rnoh {
|
|
8
|
+
using namespace facebook;
|
|
9
|
+
|
|
10
|
+
RTNCookies::RTNCookies(const ArkTSTurboModule::Context ctx, const std::string name) : ArkTSTurboModule(ctx, name) {
|
|
11
|
+
methodMap_ = {
|
|
12
|
+
ARK_ASYNC_METHOD_METADATA(clearAll, 1),
|
|
13
|
+
ARK_ASYNC_METHOD_METADATA(get, 2),
|
|
14
|
+
ARK_ASYNC_METHOD_METADATA(set, 3),
|
|
15
|
+
ARK_ASYNC_METHOD_METADATA(clearByName, 3),
|
|
16
|
+
ARK_ASYNC_METHOD_METADATA(flush, 0),
|
|
17
|
+
ARK_ASYNC_METHOD_METADATA(removeSessionCookies, 0),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include "RNOH/ArkTSTurboModule.h"
|
|
8
|
+
|
|
9
|
+
namespace rnoh {
|
|
10
|
+
|
|
11
|
+
class JSI_EXPORT RTNCookies : public ArkTSTurboModule {
|
|
12
|
+
public:
|
|
13
|
+
RTNCookies(const ArkTSTurboModule::Context ctx, const std::string name);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
} // namespace rnoh
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateComponentDescriptorH.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include "ShadowNodes.h"
|
|
14
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
15
|
+
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
|
16
|
+
|
|
17
|
+
namespace facebook::react {
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
void react_native_cookies_registerComponentDescriptorsFromCodegen(
|
|
22
|
+
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry);
|
|
23
|
+
|
|
24
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateEventEmitterCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "EventEmitters.h"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
namespace facebook::react {
|
|
15
|
+
|
|
16
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateEventEmitterH.js
|
|
9
|
+
*/
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GeneratePropsCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "Props.h"
|
|
12
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
13
|
+
#include <react/renderer/core/propsConversions.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GeneratePropsH.js
|
|
9
|
+
*/
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
namespace facebook::react {
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateShadowNodeCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "ShadowNodes.h"
|
|
12
|
+
|
|
13
|
+
namespace facebook::react {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateShadowNodeH.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include "EventEmitters.h"
|
|
14
|
+
#include "Props.h"
|
|
15
|
+
#include "States.h"
|
|
16
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
17
|
+
#include <jsi/jsi.h>
|
|
18
|
+
|
|
19
|
+
namespace facebook::react {
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateStateCpp.js
|
|
9
|
+
*/
|
|
10
|
+
#include "States.h"
|
|
11
|
+
|
|
12
|
+
namespace facebook::react {
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,19 @@
|
|
|
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: GenerateStateH.js
|
|
8
|
+
*/
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#ifdef ANDROID
|
|
12
|
+
#include <folly/dynamic.h>
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import { TurboModule } from '@rnoh/react-native-openharmony/ts';
|
|
6
|
+
import web_webview from '@ohos.web.webview';
|
|
7
|
+
|
|
8
|
+
export interface Cookie {
|
|
9
|
+
name: string;
|
|
10
|
+
value: string;
|
|
11
|
+
path?: string;
|
|
12
|
+
domain?: string;
|
|
13
|
+
version?: string;
|
|
14
|
+
expires?: string;
|
|
15
|
+
secure?: boolean;
|
|
16
|
+
httpOnly?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Cookies {
|
|
20
|
+
[key: string]: Cookie;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class CookiesModule extends TurboModule {
|
|
24
|
+
clearAll(useWebKit?: boolean): Promise<boolean> {
|
|
25
|
+
try {
|
|
26
|
+
if (useWebKit) {
|
|
27
|
+
web_webview.WebCookieManager.clearAllCookies();
|
|
28
|
+
} else {
|
|
29
|
+
web_webview.WebCookieManager.clearAllCookiesSync();
|
|
30
|
+
}
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
resolve(true);
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
resolve(false);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async get(url: string, useWebKit?: boolean): Promise<Cookies> {
|
|
42
|
+
if ((url === '') || (url === undefined) || (url === null)) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
let cookies: Cookies = { 'cookies': {name: 'error', value: 'url有误'} };
|
|
45
|
+
resolve(cookies);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
let result: string = '';
|
|
50
|
+
if (useWebKit) {
|
|
51
|
+
result = await web_webview.WebCookieManager.fetchCookie(url);
|
|
52
|
+
} else {
|
|
53
|
+
result = web_webview.WebCookieManager.fetchCookieSync(url);
|
|
54
|
+
}
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
if (result === '') {
|
|
57
|
+
let cookies: Cookies = { 'cookies': {name: 'error', value: '未查询到cookie'} };
|
|
58
|
+
resolve(cookies);
|
|
59
|
+
} else {
|
|
60
|
+
let queryCookieArray: Array<string> = result.split(';');
|
|
61
|
+
let cookies: Cookies = {};
|
|
62
|
+
for (let i = 0 ; i < queryCookieArray.length; i++) {
|
|
63
|
+
let name = queryCookieArray[i].split('=')[0];
|
|
64
|
+
let value = queryCookieArray[i].split('=')[1];
|
|
65
|
+
cookies[name] = { name: name, value: value } as Cookie;
|
|
66
|
+
}
|
|
67
|
+
resolve(cookies);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
} catch (error) {
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
let cookies: Cookies = { 'cookie': {name: 'error', value: JSON.stringify(error)} }
|
|
73
|
+
resolve(cookies);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
isEmpty(value:string) {
|
|
79
|
+
return value == null || value.length === 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async set(url: string, cookie: Cookie, useWebKit?: boolean): Promise<boolean>{
|
|
83
|
+
try {
|
|
84
|
+
|
|
85
|
+
let cookieBuilder:string = cookie.name + '=' + cookie.value
|
|
86
|
+
Object.keys(cookie).forEach((key)=>{
|
|
87
|
+
if(key !== "name" && key !== "value" && key !== "domain"){
|
|
88
|
+
cookieBuilder+= `; ${key}=${cookie[key]}`
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
const topLevelDomain = url.match(/^https?:\/\/([^/?#]+)(?:[/?#]|$)/i)[1];
|
|
93
|
+
if (cookie.hasOwnProperty("domain") && !this.isEmpty(cookie.domain)) {
|
|
94
|
+
let domain = cookie.domain;
|
|
95
|
+
if (domain.startsWith(".")) {
|
|
96
|
+
domain = domain.substring(1);
|
|
97
|
+
}
|
|
98
|
+
if (topLevelDomain !==domain ) {
|
|
99
|
+
throw new Error(`Cookie URL host ${topLevelDomain} and domain ${domain} mismatched. The cookie won't set correctly.`);
|
|
100
|
+
}
|
|
101
|
+
cookieBuilder+=`; domain=${domain}`
|
|
102
|
+
} else {
|
|
103
|
+
cookieBuilder +=`; domain=${topLevelDomain}`
|
|
104
|
+
}
|
|
105
|
+
if (useWebKit) {
|
|
106
|
+
await web_webview.WebCookieManager.configCookie(url, cookieBuilder);
|
|
107
|
+
} else {
|
|
108
|
+
web_webview.WebCookieManager.configCookieSync(url, cookieBuilder,false);
|
|
109
|
+
}
|
|
110
|
+
return new Promise((resolve) => {
|
|
111
|
+
resolve(true);
|
|
112
|
+
});
|
|
113
|
+
} catch(error) {
|
|
114
|
+
return new Promise((resolve) => {
|
|
115
|
+
resolve(false);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async clearByName(url: string, name: string, useWebKit?: boolean): Promise<boolean>{
|
|
121
|
+
if ((url === '') || (url === undefined) || (url === null)) {
|
|
122
|
+
return new Promise((resolve) => {
|
|
123
|
+
resolve(false);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
let cookieExist = false;
|
|
128
|
+
let cookieStr: string = '';
|
|
129
|
+
let cookies: Array<string> = [];
|
|
130
|
+
if (useWebKit) {
|
|
131
|
+
cookieStr = await web_webview.WebCookieManager.fetchCookie(url);
|
|
132
|
+
} else {
|
|
133
|
+
cookieStr = web_webview.WebCookieManager.fetchCookieSync(url);
|
|
134
|
+
}
|
|
135
|
+
cookies = cookieStr.split(';');
|
|
136
|
+
for (let i = 0 ; i < cookies.length; i++) {
|
|
137
|
+
if (cookies[i].split('=')[0].trim() === name) {
|
|
138
|
+
cookieExist = true;
|
|
139
|
+
cookies.splice(i, 1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (!cookieExist) {
|
|
143
|
+
return new Promise((resolve) => {
|
|
144
|
+
resolve(true);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
if (useWebKit) {
|
|
148
|
+
await web_webview.WebCookieManager.clearAllCookies();
|
|
149
|
+
} else {
|
|
150
|
+
web_webview.WebCookieManager.clearAllCookiesSync();
|
|
151
|
+
}
|
|
152
|
+
cookies.forEach((item) => {
|
|
153
|
+
web_webview.WebCookieManager.configCookie(url, item);
|
|
154
|
+
})
|
|
155
|
+
return new Promise((resolve) => {
|
|
156
|
+
resolve(true);
|
|
157
|
+
});
|
|
158
|
+
} catch(error) {
|
|
159
|
+
return new Promise((resolve) => {
|
|
160
|
+
resolve(false);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
removeSessionCookies(): Promise<boolean>{
|
|
166
|
+
try {
|
|
167
|
+
web_webview.WebCookieManager.clearSessionCookieSync();
|
|
168
|
+
return new Promise((resolve) => {
|
|
169
|
+
resolve(true);
|
|
170
|
+
});
|
|
171
|
+
} catch(error) {
|
|
172
|
+
return new Promise((resolve) => {
|
|
173
|
+
resolve(false);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
|
|
2
|
+
// Use of this source code is governed by a Apache-2.0 license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
|
|
6
|
+
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
|
7
|
+
import { CookiesModule } from './CookiesModule';
|
|
8
|
+
|
|
9
|
+
class CookiesModulesFactory extends TurboModulesFactory {
|
|
10
|
+
createTurboModule(name: string): TurboModule | null {
|
|
11
|
+
if (name === 'RTNCookies') {
|
|
12
|
+
return new CookiesModule(this.ctx)
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
hasTurboModule(name: string): boolean {
|
|
18
|
+
return name === 'RTNCookies';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class CookiesPackage extends RNPackage {
|
|
23
|
+
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
|
|
24
|
+
return new CookiesModulesFactory(ctx);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2024 Huawei Device Co., Ltd.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import hilog from '@ohos.hilog';
|
|
26
|
+
|
|
27
|
+
class Logger {
|
|
28
|
+
private domain: number;
|
|
29
|
+
private prefix: string;
|
|
30
|
+
private format: string = '%{public}s, %{public}s';
|
|
31
|
+
private isDebug: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* constructor.
|
|
35
|
+
*
|
|
36
|
+
* @param Prefix Identifies the log tag.
|
|
37
|
+
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
|
|
38
|
+
*/
|
|
39
|
+
constructor(prefix: string = 'RNCookies', domain: number = 0xFF00, isDebug = false) {
|
|
40
|
+
this.prefix = prefix;
|
|
41
|
+
this.domain = domain;
|
|
42
|
+
this.isDebug = isDebug;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
debug(...args: string[]): void {
|
|
46
|
+
if (this.isDebug) {
|
|
47
|
+
hilog.debug(this.domain, this.prefix, this.format, args);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
info(...args: string[]): void {
|
|
52
|
+
hilog.info(this.domain, this.prefix, this.format, args);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
warn(...args: string[]): void {
|
|
56
|
+
hilog.warn(this.domain, this.prefix, this.format, args);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
error(...args: string[]): void {
|
|
60
|
+
hilog.error(this.domain, this.prefix, this.format, args);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default new Logger('RNCookies', 0xFF00, false)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by "react-native codegen-lib-harmony"
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Tag } from "@rnoh/react-native-openharmony/ts"
|
|
6
|
+
|
|
7
|
+
export namespace RTNCookies {
|
|
8
|
+
export const NAME = 'RTNCookies' as const
|
|
9
|
+
|
|
10
|
+
export type Cookie = {name: string, value: string, path?: string, domain?: string, version?: string, expires?: string, secure?: boolean, httpOnly?: boolean}
|
|
11
|
+
|
|
12
|
+
export interface Spec {
|
|
13
|
+
clearAll(useWebKit: boolean): Promise<boolean>;
|
|
14
|
+
|
|
15
|
+
get(url: string, useWebKit: boolean): Promise<void>;
|
|
16
|
+
|
|
17
|
+
set(url: string, cookie: Cookie, useWebKit: boolean): Promise<boolean>;
|
|
18
|
+
|
|
19
|
+
clearByName(url: string, name: string, useWebKit: boolean): Promise<boolean>;
|
|
20
|
+
|
|
21
|
+
flush(): Promise<boolean>;
|
|
22
|
+
|
|
23
|
+
removeSessionCookies(): Promise<boolean>;
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
|
2
|
+
|
|
3
|
+
export default function localUnitTest() {
|
|
4
|
+
describe('localUnitTest',() => {
|
|
5
|
+
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
|
6
|
+
beforeAll(() => {
|
|
7
|
+
// Presets an action, which is performed only once before all test cases of the test suite start.
|
|
8
|
+
// This API supports only one parameter: preset action function.
|
|
9
|
+
});
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
// Presets an action, which is performed before each unit test case starts.
|
|
12
|
+
// The number of execution times is the same as the number of test cases defined by **it**.
|
|
13
|
+
// This API supports only one parameter: preset action function.
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
// Presets a clear action, which is performed after each unit test case ends.
|
|
17
|
+
// The number of execution times is the same as the number of test cases defined by **it**.
|
|
18
|
+
// This API supports only one parameter: clear action function.
|
|
19
|
+
});
|
|
20
|
+
afterAll(() => {
|
|
21
|
+
// Presets a clear action, which is performed after all test cases of the test suite end.
|
|
22
|
+
// This API supports only one parameter: clear action function.
|
|
23
|
+
});
|
|
24
|
+
it('assertContain', 0, () => {
|
|
25
|
+
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
|
26
|
+
let a = 'abc';
|
|
27
|
+
let b = 'b';
|
|
28
|
+
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
|
29
|
+
expect(a).assertContain(b);
|
|
30
|
+
expect(a).assertEqual(a);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
Binary file
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
declare module '@react-native-cookies/cookies' {
|
|
2
|
+
export interface Cookie {
|
|
3
|
+
name: string;
|
|
4
|
+
value: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
domain?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
expires?: string;
|
|
9
|
+
secure?: boolean;
|
|
10
|
+
httpOnly?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Cookies {
|
|
14
|
+
[key: string]: Cookie;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CookieManagerStatic {
|
|
18
|
+
set(url: string, cookie: Cookie, useWebKit?: boolean): Promise<boolean>;
|
|
19
|
+
setFromResponse(url: string, cookie: string): Promise<boolean>;
|
|
20
|
+
|
|
21
|
+
get(url: string, useWebKit?: boolean): Promise<Cookies>;
|
|
22
|
+
getFromResponse(url: string): Promise<Cookies>;
|
|
23
|
+
|
|
24
|
+
clearAll(useWebKit?: boolean): Promise<boolean>;
|
|
25
|
+
|
|
26
|
+
// Android only
|
|
27
|
+
flush(): Promise<void>;
|
|
28
|
+
removeSessionCookies(): Promise<boolean>;
|
|
29
|
+
|
|
30
|
+
// iOS only
|
|
31
|
+
getAll(useWebKit?: boolean): Promise<Cookies>;
|
|
32
|
+
clearByName(
|
|
33
|
+
url: string,
|
|
34
|
+
name: string,
|
|
35
|
+
useWebKit?: boolean,
|
|
36
|
+
): Promise<boolean>;
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const CookieManager: CookieManagerStatic;
|
|
41
|
+
|
|
42
|
+
export default CookieManager;
|
|
43
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Joseph P. Ferraro
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file here: https://github.com/joeferraro/react-native-cookies/blob/master/LICENSE.md.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { NativeModules, Platform } from 'react-native';
|
|
9
|
+
import RTNCookies from './src/NativeRTNCookies';
|
|
10
|
+
const invariant = require('invariant');
|
|
11
|
+
const RNCookieManagerIOS = NativeModules.RNCookieManagerIOS;
|
|
12
|
+
const RNCookieManagerAndroid = NativeModules.RNCookieManagerAndroid;
|
|
13
|
+
|
|
14
|
+
let CookieManager;
|
|
15
|
+
if (Platform.OS === 'ios') {
|
|
16
|
+
invariant(
|
|
17
|
+
RNCookieManagerIOS,
|
|
18
|
+
'@react-native-community/cookies: Add RNCookieManagerIOS.h and RNCookieManagerIOS.m to your Xcode project',
|
|
19
|
+
);
|
|
20
|
+
CookieManager = RNCookieManagerIOS;
|
|
21
|
+
} else if (Platform.OS === 'android') {
|
|
22
|
+
invariant(
|
|
23
|
+
RNCookieManagerAndroid,
|
|
24
|
+
'@react-native-community/cookies: Import libraries to android "react-native link @react-native-community/cookies"',
|
|
25
|
+
);
|
|
26
|
+
CookieManager = RNCookieManagerAndroid;
|
|
27
|
+
} else if (Platform.OS === 'harmony') {
|
|
28
|
+
CookieManager = RTNCookies;
|
|
29
|
+
} else {
|
|
30
|
+
invariant(
|
|
31
|
+
CookieManager,
|
|
32
|
+
'@react-native-community/cookies: Invalid platform. This library only supports Android and iOS.',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
const functions = ['setFromResponse', 'getFromResponse'];
|
|
38
|
+
|
|
39
|
+
module.exports = {
|
|
40
|
+
getAll: (useWebKit = false) => CookieManager.getAll(useWebKit),
|
|
41
|
+
clearAll: (useWebKit = false) => CookieManager.clearAll(useWebKit),
|
|
42
|
+
get: (url, useWebKit = false) => CookieManager.get(url, useWebKit),
|
|
43
|
+
set: (url, cookie, useWebKit = false) =>
|
|
44
|
+
CookieManager.set(url, cookie, useWebKit),
|
|
45
|
+
clearByName: (url, name, useWebKit = false) =>
|
|
46
|
+
CookieManager.clearByName(url, name, useWebKit),
|
|
47
|
+
flush: async () => {
|
|
48
|
+
if (Platform.OS === 'android') {
|
|
49
|
+
await CookieManager.flush();
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
removeSessionCookies: async () => {
|
|
53
|
+
if (Platform.OS === 'android' || Platform.OS === 'harmony') {
|
|
54
|
+
return await CookieManager.removeSessionCookies();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
for (var i = 0; i < functions.length; i++) {
|
|
61
|
+
module.exports[functions[i]] = CookieManager[functions[i]];
|
|
62
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-native-ohos/cookies",
|
|
3
|
+
"version": "6.2.2-rc.1",
|
|
4
|
+
"description": "Cookie Manager for React Native",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/react-native-cookies/cookies.git",
|
|
8
|
+
"baseUrl": "https://github.com/react-native-cookies/cookies"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"react native",
|
|
12
|
+
"react-native-component",
|
|
13
|
+
"cookies",
|
|
14
|
+
"webview"
|
|
15
|
+
],
|
|
16
|
+
"files": [
|
|
17
|
+
"harmony",
|
|
18
|
+
"src",
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"react-native-cookies.podspec"
|
|
21
|
+
],
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Jason Safaiyeh",
|
|
24
|
+
"email": "safaiyeh@protonmail.com"
|
|
25
|
+
},
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"licenseFilename": "LICENSE",
|
|
28
|
+
"readmeFilename": "README.md",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/react-native-cookies/cookies/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/react-native-cookies/cookies#readme",
|
|
33
|
+
"main": "index.js",
|
|
34
|
+
"types": "index.d.ts",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"lint": "eslint index.js",
|
|
37
|
+
"semantic-release": "semantic-release",
|
|
38
|
+
"codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-cookies --cpp-output-path ./harmony/rn_cookies/src/main/cpp/generated --ets-output-path ./harmony/rn_cookies/src/main/ets/generated --turbo-modules-spec-paths ./src/NativeRTNCookies.tsx"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"invariant": "^2.2.4"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react-native": ">= 0.60.2"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"react-native": "0.72.5",
|
|
48
|
+
"@react-native-community/eslint-config": "^0.0.6",
|
|
49
|
+
"@react-native-community/eslint-plugin": "^1.0.0",
|
|
50
|
+
"@semantic-release/git": "^8.0.0",
|
|
51
|
+
"eslint": "^6.8.0",
|
|
52
|
+
"rtn-cookies": "file:rtn-cookies",
|
|
53
|
+
"semantic-release": "*",
|
|
54
|
+
"react-native-harmony-cli": "npm:@react-native-oh/react-native-harmony-cli@^0.0.27"
|
|
55
|
+
},
|
|
56
|
+
"harmony": {
|
|
57
|
+
"alias": "@react-native-cookies/cookies"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "react-native-cookies"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.author = { package["author"]["name"] => package["author"]["email"] }
|
|
12
|
+
s.source = { :git => "git@github.com:react-native-community/cookies.git", :tag => "v#{s.version}" }
|
|
13
|
+
s.requires_arc = true
|
|
14
|
+
s.platform = :ios, "7.0"
|
|
15
|
+
s.preserve_paths = "*.framework"
|
|
16
|
+
s.source_files = "ios/**/*.{h,m}"
|
|
17
|
+
s.dependency "React-Core"
|
|
18
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
19
|
+
*
|
|
20
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
* you may not use this file except in compliance with the License.
|
|
22
|
+
* You may obtain a copy of the License at
|
|
23
|
+
*
|
|
24
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
*
|
|
26
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
* See the License for the specific language governing permissions and
|
|
30
|
+
* limitations under the License.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
|
|
34
|
+
import { TurboModuleRegistry, NativeModules, Platform } from "react-native";
|
|
35
|
+
|
|
36
|
+
export interface Cookie {
|
|
37
|
+
name: string;
|
|
38
|
+
value: string;
|
|
39
|
+
path?: string;
|
|
40
|
+
domain?: string;
|
|
41
|
+
version?: string;
|
|
42
|
+
expires?: string;
|
|
43
|
+
secure?: boolean;
|
|
44
|
+
httpOnly?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface Cookies {
|
|
48
|
+
[key: string]: Cookie;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface Spec extends TurboModule {
|
|
52
|
+
clearAll(useWebKit: boolean): Promise<boolean>;
|
|
53
|
+
get(url: string, useWebKit?: boolean): Promise<Cookies>;
|
|
54
|
+
set(url: string, cookie: Cookie, useWebKit?: boolean): Promise<boolean>;
|
|
55
|
+
clearByName(url: string, name: string, useWebKit?: boolean): Promise<boolean>;
|
|
56
|
+
flush(): Promise<boolean>;
|
|
57
|
+
removeSessionCookies(): Promise<boolean>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const RTNCookies = TurboModuleRegistry.getEnforcing<Spec>('RTNCookies');
|
|
61
|
+
export default RTNCookies;
|