Skip to content

Commit 509b4bb

Browse files
authored
feat(module): Initial Launch of react-native-cookies
BREAKING CHANGE: Temporary breaking change to trigger semantic major version bump.
1 parent 4c98ed5 commit 509b4bb

23 files changed

+6809
-21
lines changed

.circleci/config.yml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
1-
version: 2
2-
jobs:
3-
build:
4-
docker:
5-
- image: debian:stretch
1+
version: 2.1
2+
orbs:
3+
rn: react-native-community/[email protected]
64

5+
jobs:
6+
checkout_code:
7+
executor: rn/linux_js
78
steps:
89
- checkout
10+
- persist_to_workspace:
11+
root: .
12+
paths: .
913

14+
analyse_js:
15+
executor: rn/linux_js
16+
steps:
17+
- attach_workspace:
18+
at: .
19+
- rn/yarn_install
1020
- run:
11-
name: Greeting
12-
command: echo Hello, world.
21+
name: Run ESLint
22+
command: yarn lint
1323

24+
release:
25+
executor: rn/linux_js
26+
steps:
27+
- attach_workspace:
28+
at: .
29+
- rn/yarn_install
1430
- run:
15-
name: Print the Current Time
16-
command: date
31+
name: Publish to NPM
32+
command: yarn semantic-release || true
33+
34+
workflows:
35+
ci:
36+
jobs:
37+
- checkout_code
38+
- analyse_js:
39+
requires:
40+
- checkout_code
41+
- release:
42+
requires:
43+
- analyse_js
44+
filters:
45+
branches:
46+
only: master
47+

.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@react-native-community"
3+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pbxproj -text

.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# OSX
2+
#
3+
.DS_Store
4+
5+
# node.js
6+
#
7+
node_modules/
8+
npm-debug.log
9+
yarn-error.log
10+
11+
# Xcode
12+
#
13+
build/
14+
*.pbxuser
15+
!default.pbxuser
16+
*.mode1v3
17+
!default.mode1v3
18+
*.mode2v3
19+
!default.mode2v3
20+
*.perspectivev3
21+
!default.perspectivev3
22+
xcuserdata
23+
*.xccheckout
24+
*.moved-aside
25+
DerivedData
26+
*.hmap
27+
*.ipa
28+
*.xcuserstate
29+
project.xcworkspace
30+
31+
# Android/IntelliJ
32+
#
33+
build/
34+
.idea
35+
.gradle
36+
local.properties
37+
*.iml
38+
.classpath
39+
.project
40+
.settings
41+
42+
# BUCK
43+
buck-out/
44+
\.buckd/
45+
*.keystore
46+
47+
# VS Code
48+
.vscode

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.eslintrc
2+
.prettierrc
3+
.releaserc
4+
.circleci/*

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

.releaserc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"plugins": [
3+
"@semantic-release/commit-analyzer",
4+
"@semantic-release/release-notes-generator",
5+
"@semantic-release/npm",
6+
"@semantic-release/github",
7+
[
8+
"@semantic-release/git",
9+
{
10+
"assets": "package.json",
11+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
12+
}
13+
]
14+
]
15+
}

README.md

Lines changed: 195 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,196 @@
1-
# @react-native-community/react-native-cookies
1+
# React Native Cookies - A Cookie Manager for React Native
22
Cookie Manager for React Native
3+
4+
## Maintainers
5+
- [Jason Safaiyeh](https://github.com/safaiyeh) ([Twitter @safaiyeh](https://twitter.com/safaiyeh)) from [Sumo Logic](https://www.sumologic.com)
6+
7+
## Platforms Supported
8+
- [x] iOS
9+
- [x] Android
10+
11+
Currently lacking support for Windows, Web, and Expo. Support for these platforms will created when there is a need for them. Starts with a posted issue.
12+
13+
## Installation
14+
15+
```
16+
yarn add @react-native-community/react-native-cookies
17+
```
18+
19+
20+
## Setup (React Native < 0.60.0)
21+
22+
### Automatic (recommended)
23+
24+
```
25+
react-native link @react-native-community/react-native-cookies
26+
```
27+
28+
### Manual
29+
30+
If automatic linking does not work, you can manually link this library by following the instructions below:
31+
32+
#### iOS
33+
34+
1. Open your project in Xcode, right click on `Libraries` and click `Add
35+
Files to "Your Project Name"` Look under `node_modules/@react-native-community/react-native-cookies/ios` and add `RNCookieManagerIOS.xcodeproj`.
36+
2. Add `libRNCookieManagerIOS.a` to `Build Phases -> Link Binary With Libraries.
37+
3. Clean and rebuild your project
38+
39+
#### Android
40+
41+
Run `react-native link` to link the react-native-cookies library.
42+
43+
Or if you have trouble, make the following additions to the given files manually:
44+
45+
**android/settings.gradle**
46+
47+
```gradle
48+
include ':@react-native-community_react-native-cookies'
49+
project(':@react-native-community_react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/react-native-cookies/android')
50+
```
51+
52+
**android/app/build.gradle**
53+
54+
```gradle
55+
dependencies {
56+
...
57+
implementation project(':@react-native-community_react-native-cookies')
58+
}
59+
```
60+
61+
**MainApplication.java**
62+
63+
On top, where imports are:
64+
65+
```java
66+
import com.reactnativecommunity.cookies.CookieManagerPackage;
67+
```
68+
69+
Add the `CookieManagerPackage` class to your list of exported packages.
70+
71+
```java
72+
@Override
73+
protected List<ReactPackage> getPackages() {
74+
return Arrays.asList(
75+
new MainReactPackage(),
76+
new CookieManagerPackage()
77+
);
78+
}
79+
```
80+
81+
82+
83+
## Usage
84+
85+
```javascript
86+
import CookieManager from 'react-native-cookie-store';
87+
88+
// set a cookie (IOS ONLY)
89+
CookieManager.set({
90+
name: 'myCookie',
91+
value: 'myValue',
92+
domain: 'some domain',
93+
origin: 'some origin',
94+
path: '/',
95+
version: '1',
96+
expiration: '2015-05-30T12:30:00.00-05:00'
97+
}).then((res) => {
98+
console.log('CookieManager.set =>', res);
99+
});
100+
101+
// Set cookies from a response header
102+
// This allows you to put the full string provided by a server's Set-Cookie
103+
// response header directly into the cookie store.
104+
CookieManager.setFromResponse(
105+
'http://example.com',
106+
'user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly')
107+
.then((res) => {
108+
// `res` will be true or false depending on success.
109+
console.log('CookieManager.setFromResponse =>', res);
110+
});
111+
112+
// Get cookies as a request header string
113+
CookieManager.get('http://example.com')
114+
.then((res) => {
115+
console.log('CookieManager.get =>', res); // => 'user_session=abcdefg; path=/;'
116+
});
117+
118+
// list cookies (IOS ONLY)
119+
// useWebKit: boolean
120+
CookieManager.getAll(useWebKit)
121+
.then((res) => {
122+
console.log('CookieManager.getAll =>', res);
123+
});
124+
125+
// clear cookies
126+
CookieManager.clearAll()
127+
.then((res) => {
128+
console.log('CookieManager.clearAll =>', res);
129+
});
130+
131+
// clear a specific cookie by its name (IOS ONLY)
132+
CookieManager.clearByName('cookie_name')
133+
.then((res) => {
134+
console.log('CookieManager.clearByName =>', res);
135+
});
136+
137+
```
138+
139+
### WebKit-Support (iOS only)
140+
React Native comes with a WebView component, which uses UIWebView on iOS. Introduced in iOS 8 Apple implemented the WebKit-Support with all the performance boost.
141+
142+
To use this it's required to use a special implementation of the WebView component (e.g. [react-native-wkwebview](https://github.com/CRAlpha/react-native-wkwebview)).
143+
144+
This special implementation of the WebView component stores the cookies __not__ in `NSHTTPCookieStorage` anymore. The new cookie-storage is `WKHTTPCookieStore` and implementes a differnt interface.
145+
146+
To use this _CookieManager_ with WebKit-Support we extended the interface with the attribute `useWebKit` (a boolean value, default: `FASLE`) for the following methods:
147+
148+
|Method|WebKit-Support|Method-Signature|
149+
|---|---|---|
150+
|getAll| Yes | `CookieManager.getAll(useWebKit:boolean)` |
151+
|clearAll| Yes | `CookieManager.clearAll(useWebKit:boolean)` |
152+
|get| Yes | `CookieManager.get(url:string, useWebKit:boolean)` |
153+
|set| Yes | `CookieManager.set(cookie:object, useWebKit:boolean)` |
154+
155+
##### Usage
156+
```javascript
157+
import CookieManager from 'react-native-cookie-store';
158+
159+
const useWebKit = true;
160+
161+
// list cookies (IOS ONLY)
162+
CookieManager.getAll(useWebKit)
163+
.then((res) => {
164+
console.log('CookieManager.getAll from webkit-view =>', res);
165+
});
166+
167+
// clear cookies
168+
CookieManager.clearAll(useWebKit)
169+
.then((res) => {
170+
console.log('CookieManager.clearAll from webkit-view =>', res);
171+
});
172+
173+
// Get cookies as a request header string
174+
CookieManager.get('http://example.com', useWebKit)
175+
.then((res) => {
176+
console.log('CookieManager.get from webkit-view =>', res);
177+
// => 'user_session=abcdefg; path=/;'
178+
});
179+
180+
// set a cookie (IOS ONLY)
181+
const newCookie: = {
182+
name: 'myCookie',
183+
value: 'myValue',
184+
domain: 'some domain',
185+
origin: 'some origin',
186+
path: '/',
187+
version: '1',
188+
expiration: '2015-05-30T12:30:00.00-05:00'
189+
};
190+
191+
CookieManager.set(newCookie, useWebKit)
192+
.then((res) => {
193+
console.log('CookieManager.set from webkit-view =>', res);
194+
});
195+
```
196+

0 commit comments

Comments
 (0)