react-native-nitro-cookies 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NitroCookies.podspec +30 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +128 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/nitrocookies/NitroCookies.kt +340 -0
- package/android/src/main/java/com/margelo/nitro/nitrocookies/NitroCookiesPackage.kt +22 -0
- package/ios/NitroCookies.swift +411 -0
- package/lib/module/NitroCookies.nitro.js +4 -0
- package/lib/module/NitroCookies.nitro.js.map +1 -0
- package/lib/module/index.js +264 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/types.js +43 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NitroCookies.nitro.d.ts +89 -0
- package/lib/typescript/src/NitroCookies.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +229 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +86 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/nitro.json +17 -0
- package/nitrogen/generated/android/c++/JCookie.hpp +86 -0
- package/nitrogen/generated/android/c++/JHybridNitroCookiesSpec.cpp +224 -0
- package/nitrogen/generated/android/c++/JHybridNitroCookiesSpec.hpp +73 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/Cookie.kt +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/HybridNitroCookiesSpec.kt +90 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/nitrocookiesOnLoad.kt +35 -0
- package/nitrogen/generated/android/nitrocookies+autolinking.cmake +81 -0
- package/nitrogen/generated/android/nitrocookies+autolinking.gradle +27 -0
- package/nitrogen/generated/android/nitrocookiesOnLoad.cpp +44 -0
- package/nitrogen/generated/android/nitrocookiesOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/NitroCookies+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroCookies-Swift-Cxx-Bridge.cpp +64 -0
- package/nitrogen/generated/ios/NitroCookies-Swift-Cxx-Bridge.hpp +243 -0
- package/nitrogen/generated/ios/NitroCookies-Swift-Cxx-Umbrella.hpp +50 -0
- package/nitrogen/generated/ios/NitroCookiesAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroCookiesAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridNitroCookiesSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroCookiesSpecSwift.hpp +145 -0
- package/nitrogen/generated/ios/swift/Cookie.swift +226 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_Cookie_.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridNitroCookiesSpec.swift +65 -0
- package/nitrogen/generated/ios/swift/HybridNitroCookiesSpec_cxx.swift +344 -0
- package/nitrogen/generated/shared/c++/Cookie.hpp +104 -0
- package/nitrogen/generated/shared/c++/HybridNitroCookiesSpec.cpp +29 -0
- package/nitrogen/generated/shared/c++/HybridNitroCookiesSpec.hpp +75 -0
- package/package.json +129 -0
- package/src/NitroCookies.nitro.ts +99 -0
- package/src/index.tsx +283 -0
- package/src/types.ts +99 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nitro Cookies HybridObject Interface
|
|
3
|
+
*
|
|
4
|
+
* This file defines the TypeScript interface for the NitroCookies HybridObject.
|
|
5
|
+
* Nitrogen code generator will use this to create platform-specific implementations.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
9
|
+
import type { Cookie } from './types';
|
|
10
|
+
|
|
11
|
+
// Cookies dictionary will be returned as an array of cookies
|
|
12
|
+
// JavaScript layer will convert to dictionary format for backwards compatibility
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* NitroCookies HybridObject
|
|
16
|
+
*
|
|
17
|
+
* Provides high-performance HTTP cookie management for React Native applications.
|
|
18
|
+
* Uses Nitro Modules JSI architecture to achieve 5x+ faster operations compared
|
|
19
|
+
* to traditional React Native bridge-based implementations.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export interface NitroCookies
|
|
23
|
+
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
24
|
+
/**
|
|
25
|
+
* Set a single cookie for a specific URL
|
|
26
|
+
*
|
|
27
|
+
* @param url - The URL for which to set the cookie (must include protocol: http:// or https://)
|
|
28
|
+
* @param cookie - The cookie object to store
|
|
29
|
+
* @param useWebKit - (iOS only) If true, use WKHTTPCookieStore instead of NSHTTPCookieStorage (requires iOS 11+)
|
|
30
|
+
* @returns Promise that resolves to true on success
|
|
31
|
+
*/
|
|
32
|
+
set(url: string, cookie: Cookie, useWebKit?: boolean): Promise<boolean>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get all cookies matching a specific URL's domain
|
|
36
|
+
*
|
|
37
|
+
* @param url - The URL to match cookies against (must include protocol)
|
|
38
|
+
* @param useWebKit - (iOS only) If true, retrieve from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
39
|
+
* @returns Promise that resolves to array of cookies
|
|
40
|
+
*/
|
|
41
|
+
get(url: string, useWebKit?: boolean): Promise<Cookie[]>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Clear all cookies from storage
|
|
45
|
+
*
|
|
46
|
+
* @param useWebKit - (iOS only) If true, clear from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
47
|
+
* @returns Promise that resolves to true on success
|
|
48
|
+
*/
|
|
49
|
+
clearAll(useWebKit?: boolean): Promise<boolean>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parse and store cookies from HTTP Set-Cookie header string
|
|
53
|
+
*
|
|
54
|
+
* @param url - The URL associated with the Set-Cookie header
|
|
55
|
+
* @param value - The raw Set-Cookie header value
|
|
56
|
+
* @returns Promise that resolves to true on success
|
|
57
|
+
*/
|
|
58
|
+
setFromResponse(url: string, value: string): Promise<boolean>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Make HTTP request to URL and extract cookies from response headers
|
|
62
|
+
*
|
|
63
|
+
* @param url - The URL to request (must include protocol)
|
|
64
|
+
* @returns Promise that resolves to array of cookies from response
|
|
65
|
+
*/
|
|
66
|
+
getFromResponse(url: string): Promise<Cookie[]>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get ALL cookies from storage regardless of domain (iOS only)
|
|
70
|
+
*
|
|
71
|
+
* @param useWebKit - If true, retrieve from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
72
|
+
* @returns Promise that resolves to array of all cookies
|
|
73
|
+
*/
|
|
74
|
+
getAll(useWebKit?: boolean): Promise<Cookie[]>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Clear a specific cookie by name and domain (iOS only)
|
|
78
|
+
*
|
|
79
|
+
* @param url - The URL to match the cookie domain
|
|
80
|
+
* @param name - The name of the cookie to remove
|
|
81
|
+
* @param useWebKit - If true, remove from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
82
|
+
* @returns Promise that resolves to true if cookie was found and removed
|
|
83
|
+
*/
|
|
84
|
+
clearByName(url: string, name: string, useWebKit?: boolean): Promise<boolean>;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Flush in-memory cookies to persistent storage (Android only)
|
|
88
|
+
*
|
|
89
|
+
* @returns Promise that resolves when flush is complete
|
|
90
|
+
*/
|
|
91
|
+
flush(): Promise<void>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Remove all session cookies (cookies without expires) (Android only)
|
|
95
|
+
*
|
|
96
|
+
* @returns Promise that resolves to true if any session cookies were removed
|
|
97
|
+
*/
|
|
98
|
+
removeSessionCookies(): Promise<boolean>;
|
|
99
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
2
|
+
import type { NitroCookies as NitroCookiesType } from './NitroCookies.nitro';
|
|
3
|
+
import type { Cookie, Cookies, CookieErrorCode, CookieError } from './types';
|
|
4
|
+
|
|
5
|
+
const NitroCookiesHybridObject =
|
|
6
|
+
NitroModules.createHybridObject<NitroCookiesType>('NitroCookies');
|
|
7
|
+
|
|
8
|
+
function cookiesToDictionary(cookies: Cookie[]): Cookies {
|
|
9
|
+
const result: Cookies = {};
|
|
10
|
+
for (const cookie of cookies) {
|
|
11
|
+
result[cookie.name] = cookie;
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Main NitroCookies export object with all cookie management methods.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import NitroCookies from 'react-native-nitro-cookies';
|
|
22
|
+
*
|
|
23
|
+
* // Set a cookie
|
|
24
|
+
* await NitroCookies.set('https://example.com', {
|
|
25
|
+
* name: 'session',
|
|
26
|
+
* value: 'abc123',
|
|
27
|
+
* secure: true,
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Get cookies
|
|
31
|
+
* const cookies = await NitroCookies.get('https://example.com');
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const NitroCookies = {
|
|
35
|
+
/**
|
|
36
|
+
* Set a single cookie for a specific URL.
|
|
37
|
+
*
|
|
38
|
+
* @param url - The URL for which to set the cookie. Must include protocol (http:// or https://).
|
|
39
|
+
* @param cookie - Cookie object containing name, value, and optional attributes.
|
|
40
|
+
* @param cookie.name - Cookie name (required)
|
|
41
|
+
* @param cookie.value - Cookie value (required)
|
|
42
|
+
* @param cookie.path - URL path for cookie. Defaults to "/"
|
|
43
|
+
* @param cookie.domain - Cookie domain. Defaults to URL host. Supports wildcard (.example.com)
|
|
44
|
+
* @param cookie.expires - Expiration date in ISO 8601 format (yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ). Omit for session cookie.
|
|
45
|
+
* @param cookie.secure - If true, cookie only sent over HTTPS
|
|
46
|
+
* @param cookie.httpOnly - If true, cookie not accessible via JavaScript (prevents XSS)
|
|
47
|
+
* @param cookie.version - Cookie version (rarely used, for RFC 2109 compatibility)
|
|
48
|
+
* @param useWebKit - (iOS only) If true, use WKHTTPCookieStore instead of NSHTTPCookieStorage. Requires iOS 11+.
|
|
49
|
+
*
|
|
50
|
+
* @returns Promise that resolves to true on success
|
|
51
|
+
*
|
|
52
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
53
|
+
* @throws {Error} DOMAIN_MISMATCH - Cookie domain doesn't match URL host
|
|
54
|
+
* @throws {Error} WEBKIT_UNAVAILABLE - useWebKit=true on iOS < 11
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* await NitroCookies.set('https://api.example.com', {
|
|
59
|
+
* name: 'auth_token',
|
|
60
|
+
* value: 'xyz789',
|
|
61
|
+
* path: '/api',
|
|
62
|
+
* domain: '.example.com',
|
|
63
|
+
* secure: true,
|
|
64
|
+
* httpOnly: true,
|
|
65
|
+
* expires: '2030-01-01T00:00:00.000Z',
|
|
66
|
+
* });
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
async set(
|
|
70
|
+
url: string,
|
|
71
|
+
cookie: Cookie,
|
|
72
|
+
useWebKit?: boolean
|
|
73
|
+
): Promise<boolean> {
|
|
74
|
+
return NitroCookiesHybridObject.set(url, cookie, useWebKit ?? false);
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Get all cookies matching a specific URL's domain.
|
|
79
|
+
*
|
|
80
|
+
* Returns cookies as a dictionary keyed by cookie name for backwards
|
|
81
|
+
* compatibility with @react-native-cookies/cookies.
|
|
82
|
+
*
|
|
83
|
+
* @param url - The URL to match cookies against. Must include protocol.
|
|
84
|
+
* @param useWebKit - (iOS only) If true, retrieve from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
85
|
+
*
|
|
86
|
+
* @returns Promise that resolves to dictionary of cookies keyed by name
|
|
87
|
+
*
|
|
88
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const cookies = await NitroCookies.get('https://api.example.com');
|
|
93
|
+
* // Returns: { auth_token: { name: 'auth_token', value: 'xyz789', ... } }
|
|
94
|
+
* console.log(cookies.auth_token.value); // 'xyz789'
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
async get(url: string, useWebKit?: boolean): Promise<Cookies> {
|
|
98
|
+
const cookies = await NitroCookiesHybridObject.get(url, useWebKit ?? false);
|
|
99
|
+
return cookiesToDictionary(cookies);
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Clear all cookies from storage.
|
|
104
|
+
*
|
|
105
|
+
* @param useWebKit - (iOS only) If true, clear from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
106
|
+
*
|
|
107
|
+
* @returns Promise that resolves to true on success
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* await NitroCookies.clearAll();
|
|
112
|
+
* console.log('All cookies cleared');
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
async clearAll(useWebKit?: boolean): Promise<boolean> {
|
|
116
|
+
return NitroCookiesHybridObject.clearAll(useWebKit ?? false);
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Parse and store cookies from a raw HTTP Set-Cookie header string.
|
|
121
|
+
*
|
|
122
|
+
* Automatically parses cookie attributes (path, domain, expires, secure, httpOnly)
|
|
123
|
+
* from the header value.
|
|
124
|
+
*
|
|
125
|
+
* @param url - The URL associated with the Set-Cookie header
|
|
126
|
+
* @param value - The raw Set-Cookie header value (e.g., "session=abc; path=/; secure")
|
|
127
|
+
*
|
|
128
|
+
* @returns Promise that resolves to true on success
|
|
129
|
+
*
|
|
130
|
+
* @throws {Error} INVALID_URL - URL is malformed
|
|
131
|
+
* @throws {Error} PARSE_ERROR - Set-Cookie header is malformed
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* await NitroCookies.setFromResponse(
|
|
136
|
+
* 'https://example.com',
|
|
137
|
+
* 'session=abc123; path=/; expires=Thu, 1 Jan 2030 00:00:00 GMT; secure; HttpOnly'
|
|
138
|
+
* );
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
async setFromResponse(url: string, value: string): Promise<boolean> {
|
|
142
|
+
return NitroCookiesHybridObject.setFromResponse(url, value);
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Make an HTTP GET request to a URL and extract cookies from response headers.
|
|
147
|
+
*
|
|
148
|
+
* Automatically retrieves and parses all Set-Cookie headers from the HTTP response.
|
|
149
|
+
* Returns cookies as a dictionary keyed by name.
|
|
150
|
+
*
|
|
151
|
+
* @param url - The URL to request. Must include protocol.
|
|
152
|
+
*
|
|
153
|
+
* @returns Promise that resolves to dictionary of cookies from response
|
|
154
|
+
*
|
|
155
|
+
* @throws {Error} NETWORK_ERROR - HTTP request failed
|
|
156
|
+
* @throws {Error} INVALID_URL - URL is malformed
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const cookies = await NitroCookies.getFromResponse('https://api.example.com/login');
|
|
161
|
+
* // Returns cookies set by server in Set-Cookie headers
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
async getFromResponse(url: string): Promise<Cookies> {
|
|
165
|
+
const cookies = await NitroCookiesHybridObject.getFromResponse(url);
|
|
166
|
+
return cookiesToDictionary(cookies);
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Get ALL cookies from storage regardless of domain.
|
|
171
|
+
*
|
|
172
|
+
* **iOS only** - Returns all cookies from all domains. Useful for debugging
|
|
173
|
+
* and auditing. Returns cookies as a dictionary keyed by name.
|
|
174
|
+
*
|
|
175
|
+
* @param useWebKit - If true, retrieve from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
176
|
+
*
|
|
177
|
+
* @returns Promise that resolves to dictionary of all cookies
|
|
178
|
+
*
|
|
179
|
+
* @throws {Error} PLATFORM_UNSUPPORTED - Called on Android (not supported)
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* import { Platform } from 'react-native';
|
|
184
|
+
*
|
|
185
|
+
* if (Platform.OS === 'ios') {
|
|
186
|
+
* const allCookies = await NitroCookies.getAll();
|
|
187
|
+
* // Returns cookies from ALL domains
|
|
188
|
+
* console.log(Object.keys(allCookies).length, 'total cookies');
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
async getAll(useWebKit?: boolean): Promise<Cookies> {
|
|
193
|
+
const cookies = await NitroCookiesHybridObject.getAll(useWebKit ?? false);
|
|
194
|
+
return cookiesToDictionary(cookies);
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Clear a specific cookie by name and domain.
|
|
199
|
+
*
|
|
200
|
+
* **iOS preferred** - On iOS, removes the cookie immediately. On Android,
|
|
201
|
+
* sets an expired cookie (may not remove immediately due to platform limitations).
|
|
202
|
+
*
|
|
203
|
+
* @param url - The URL to match the cookie domain
|
|
204
|
+
* @param name - The name of the cookie to remove
|
|
205
|
+
* @param useWebKit - (iOS only) If true, remove from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
206
|
+
*
|
|
207
|
+
* @returns Promise that resolves to true if cookie was found and removed, false otherwise
|
|
208
|
+
*
|
|
209
|
+
* @throws {Error} INVALID_URL - URL is malformed
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* const removed = await NitroCookies.clearByName('https://example.com', 'session_token');
|
|
214
|
+
* if (removed) {
|
|
215
|
+
* console.log('Cookie removed');
|
|
216
|
+
* }
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
async clearByName(
|
|
220
|
+
url: string,
|
|
221
|
+
name: string,
|
|
222
|
+
useWebKit?: boolean
|
|
223
|
+
): Promise<boolean> {
|
|
224
|
+
return NitroCookiesHybridObject.clearByName(url, name, useWebKit ?? false);
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Flush in-memory cookies to persistent storage.
|
|
229
|
+
*
|
|
230
|
+
* **Android only** - Forces cookies to be written to disk immediately.
|
|
231
|
+
* Required on Android to ensure cookies persist across app restarts.
|
|
232
|
+
* Automatically called on API 21+ but explicit call ensures immediate persistence.
|
|
233
|
+
*
|
|
234
|
+
* @returns Promise that resolves when flush is complete
|
|
235
|
+
*
|
|
236
|
+
* @throws {Error} PLATFORM_UNSUPPORTED - Called on iOS (not needed)
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* import { Platform } from 'react-native';
|
|
241
|
+
*
|
|
242
|
+
* if (Platform.OS === 'android') {
|
|
243
|
+
* await NitroCookies.flush();
|
|
244
|
+
* console.log('Cookies persisted to disk');
|
|
245
|
+
* }
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
async flush(): Promise<void> {
|
|
249
|
+
return NitroCookiesHybridObject.flush();
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Remove all session cookies (cookies without an expiration date).
|
|
254
|
+
*
|
|
255
|
+
* **Android only** - Session cookies are automatically removed when the app
|
|
256
|
+
* closes on iOS. On Android, this method explicitly removes them.
|
|
257
|
+
*
|
|
258
|
+
* @returns Promise that resolves to true if any session cookies were removed
|
|
259
|
+
*
|
|
260
|
+
* @throws {Error} PLATFORM_UNSUPPORTED - Called on iOS (not needed)
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* import { Platform } from 'react-native';
|
|
265
|
+
*
|
|
266
|
+
* if (Platform.OS === 'android') {
|
|
267
|
+
* const removed = await NitroCookies.removeSessionCookies();
|
|
268
|
+
* if (removed) {
|
|
269
|
+
* console.log('Session cookies removed');
|
|
270
|
+
* }
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
async removeSessionCookies(): Promise<boolean> {
|
|
275
|
+
return NitroCookiesHybridObject.removeSessionCookies();
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// Export types
|
|
280
|
+
export type { Cookie, Cookies, CookieErrorCode, CookieError };
|
|
281
|
+
|
|
282
|
+
// Default export for convenience
|
|
283
|
+
export default NitroCookies;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for React Native Nitro Cookies
|
|
3
|
+
*
|
|
4
|
+
* These types define the structure of cookies and error handling
|
|
5
|
+
* for the Nitro-based cookie management library.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents an HTTP cookie with all RFC 6265 attributes
|
|
10
|
+
*/
|
|
11
|
+
export interface Cookie {
|
|
12
|
+
/**
|
|
13
|
+
* Cookie name/identifier (required)
|
|
14
|
+
*/
|
|
15
|
+
name: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Cookie value (required)
|
|
19
|
+
*/
|
|
20
|
+
value: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* URL path for which cookie is valid
|
|
24
|
+
* @default "/"
|
|
25
|
+
*/
|
|
26
|
+
path?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Domain for which cookie is valid (supports wildcard format like ".example.com")
|
|
30
|
+
* @default URL host
|
|
31
|
+
*/
|
|
32
|
+
domain?: string;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Cookie version (rarely used, for RFC 2109 compatibility)
|
|
36
|
+
*/
|
|
37
|
+
version?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Expiration date in ISO 8601 format (yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ)
|
|
41
|
+
* Omit for session cookie (expires when browser closes)
|
|
42
|
+
*/
|
|
43
|
+
expires?: string;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* If true, cookie only sent over HTTPS connections
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
secure?: boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* If true, cookie not accessible via JavaScript (prevents XSS attacks)
|
|
53
|
+
* @default false
|
|
54
|
+
*/
|
|
55
|
+
httpOnly?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Collection of cookies keyed by cookie name
|
|
60
|
+
* Using type alias instead of interface for Nitrogen compatibility
|
|
61
|
+
*/
|
|
62
|
+
export type Cookies = Record<string, Cookie>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Error codes for cookie operations
|
|
66
|
+
*/
|
|
67
|
+
export enum CookieErrorCode {
|
|
68
|
+
/** URL is malformed or missing protocol */
|
|
69
|
+
INVALID_URL = 'INVALID_URL',
|
|
70
|
+
/** Cookie domain doesn't match URL host */
|
|
71
|
+
DOMAIN_MISMATCH = 'DOMAIN_MISMATCH',
|
|
72
|
+
/** Method not available on current platform */
|
|
73
|
+
PLATFORM_UNSUPPORTED = 'PLATFORM_UNSUPPORTED',
|
|
74
|
+
/** WebKit operations on iOS < 11 */
|
|
75
|
+
WEBKIT_UNAVAILABLE = 'WEBKIT_UNAVAILABLE',
|
|
76
|
+
/** Failed to parse Set-Cookie header */
|
|
77
|
+
PARSE_ERROR = 'PARSE_ERROR',
|
|
78
|
+
/** Network request failed */
|
|
79
|
+
NETWORK_ERROR = 'NETWORK_ERROR',
|
|
80
|
+
/** Platform storage operation failed */
|
|
81
|
+
STORAGE_ERROR = 'STORAGE_ERROR',
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Structured error for cookie operations
|
|
86
|
+
*/
|
|
87
|
+
export interface CookieError extends Error {
|
|
88
|
+
/** Error code for programmatic handling */
|
|
89
|
+
code: CookieErrorCode | string;
|
|
90
|
+
|
|
91
|
+
/** Human-readable error message */
|
|
92
|
+
message: string;
|
|
93
|
+
|
|
94
|
+
/** URL that caused the error (if applicable) */
|
|
95
|
+
url?: string;
|
|
96
|
+
|
|
97
|
+
/** Cookie name that caused the error (if applicable) */
|
|
98
|
+
cookieName?: string;
|
|
99
|
+
}
|