react-native-nitro-cookies 1.1.0 → 1.2.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/android/src/main/java/com/margelo/nitro/nitrocookies/NitroCookies.kt +69 -0
- package/ios/NitroCookies.swift +101 -0
- package/lib/module/index.js +96 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NitroCookies.nitro.d.ts +48 -0
- package/lib/typescript/src/NitroCookies.nitro.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +88 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JCookie.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridNitroCookiesSpec.cpp +76 -16
- package/nitrogen/generated/android/c++/JHybridNitroCookiesSpec.hpp +6 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/Cookie.kt +27 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/HybridNitroCookiesSpec.kt +16 -0
- package/nitrogen/generated/android/nitrocookiesOnLoad.cpp +2 -2
- package/nitrogen/generated/ios/NitroCookies+autolinking.rb +2 -0
- package/nitrogen/generated/ios/NitroCookies-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/NitroCookies-Swift-Cxx-Bridge.hpp +52 -0
- package/nitrogen/generated/ios/c++/HybridNitroCookiesSpecSwift.hpp +32 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNitroCookiesSpec.swift +4 -0
- package/nitrogen/generated/ios/swift/HybridNitroCookiesSpec_cxx.swift +76 -0
- package/nitrogen/generated/shared/c++/HybridNitroCookiesSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNitroCookiesSpec.hpp +4 -0
- package/package.json +8 -7
- package/src/NitroCookies.nitro.ts +56 -0
- package/src/index.tsx +104 -0
|
@@ -75,6 +75,33 @@ export interface NitroCookies extends HybridObject<{
|
|
|
75
75
|
*/
|
|
76
76
|
clearByNameSync(url: string, name: string): boolean;
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Get the `Cookie` request-header string for a URL synchronously
|
|
80
|
+
*
|
|
81
|
+
* Returns the value you would put in an HTTP `Cookie` request header
|
|
82
|
+
* (e.g. "name1=value1; name2=value2"), built from every cookie that
|
|
83
|
+
* matches the URL. Use this to attach cookies to a manual `fetch`/
|
|
84
|
+
* `XMLHttpRequest`. Uses NSHTTPCookieStorage (iOS) or CookieManager (Android).
|
|
85
|
+
*
|
|
86
|
+
* @param url - The URL to match cookies against (must include protocol)
|
|
87
|
+
* @returns The Cookie header string, or "" when no cookies match
|
|
88
|
+
* @throws Error if URL is invalid
|
|
89
|
+
*/
|
|
90
|
+
getCookieHeaderSync(url: string): string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Set multiple cookies for a URL synchronously
|
|
94
|
+
*
|
|
95
|
+
* Applies the same domain validation as `setSync` to every cookie.
|
|
96
|
+
* Uses NSHTTPCookieStorage (iOS) or CookieManager (Android).
|
|
97
|
+
*
|
|
98
|
+
* @param url - The URL for which to set the cookies (must include protocol)
|
|
99
|
+
* @param cookies - The cookie objects to store
|
|
100
|
+
* @returns true on success
|
|
101
|
+
* @throws Error if URL is invalid or any cookie's domain mismatches
|
|
102
|
+
*/
|
|
103
|
+
setManySync(url: string, cookies: Cookie[]): boolean;
|
|
104
|
+
|
|
78
105
|
// ========================================
|
|
79
106
|
// ASYNCHRONOUS METHODS
|
|
80
107
|
// ========================================
|
|
@@ -89,6 +116,35 @@ export interface NitroCookies extends HybridObject<{
|
|
|
89
116
|
*/
|
|
90
117
|
set(url: string, cookie: Cookie, useWebKit?: boolean): Promise<boolean>;
|
|
91
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Set multiple cookies for a URL
|
|
121
|
+
*
|
|
122
|
+
* Applies the same domain validation as `set` to every cookie.
|
|
123
|
+
*
|
|
124
|
+
* @param url - The URL for which to set the cookies (must include protocol)
|
|
125
|
+
* @param cookies - The cookie objects to store
|
|
126
|
+
* @param useWebKit - (iOS only) If true, use WKHTTPCookieStore instead of NSHTTPCookieStorage (requires iOS 11+)
|
|
127
|
+
* @returns Promise that resolves to true on success
|
|
128
|
+
*/
|
|
129
|
+
setMany(
|
|
130
|
+
url: string,
|
|
131
|
+
cookies: Cookie[],
|
|
132
|
+
useWebKit?: boolean
|
|
133
|
+
): Promise<boolean>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Get the `Cookie` request-header string for a URL
|
|
137
|
+
*
|
|
138
|
+
* Returns the value you would put in an HTTP `Cookie` request header
|
|
139
|
+
* (e.g. "name1=value1; name2=value2"), built from every cookie that
|
|
140
|
+
* matches the URL.
|
|
141
|
+
*
|
|
142
|
+
* @param url - The URL to match cookies against (must include protocol)
|
|
143
|
+
* @param useWebKit - (iOS only) If true, read from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
144
|
+
* @returns Promise that resolves to the Cookie header string, or "" when no cookies match
|
|
145
|
+
*/
|
|
146
|
+
getCookieHeader(url: string, useWebKit?: boolean): Promise<string>;
|
|
147
|
+
|
|
92
148
|
/**
|
|
93
149
|
* Get all cookies matching a specific URL's domain
|
|
94
150
|
*
|
package/src/index.tsx
CHANGED
|
@@ -123,6 +123,53 @@ export const NitroCookies = {
|
|
|
123
123
|
return NitroCookiesHybridObject.clearByNameSync(url, name);
|
|
124
124
|
},
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Get the `Cookie` request-header string for a URL synchronously.
|
|
128
|
+
*
|
|
129
|
+
* Returns the value you would put in an HTTP `Cookie` request header
|
|
130
|
+
* (e.g. `"name1=value1; name2=value2"`), built from every cookie that
|
|
131
|
+
* matches the URL. Handy for attaching cookies to a manual `fetch` or
|
|
132
|
+
* `XMLHttpRequest`. Returns an empty string when no cookies match.
|
|
133
|
+
*
|
|
134
|
+
* @param url - The URL to match cookies against (must include protocol)
|
|
135
|
+
* @returns The Cookie header string, or "" when no cookies match
|
|
136
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const header = NitroCookies.getCookieHeaderSync('https://example.com');
|
|
141
|
+
* await fetch('https://example.com/api', { headers: { Cookie: header } });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
getCookieHeaderSync(url: string): string {
|
|
145
|
+
return NitroCookiesHybridObject.getCookieHeaderSync(url);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Set multiple cookies for a URL synchronously.
|
|
150
|
+
*
|
|
151
|
+
* Applies the same domain validation as `setSync` to every cookie. If any
|
|
152
|
+
* cookie's domain doesn't match the URL host, the whole call throws and no
|
|
153
|
+
* cookies are written.
|
|
154
|
+
*
|
|
155
|
+
* @param url - The URL for which to set the cookies (must include protocol)
|
|
156
|
+
* @param cookies - The cookie objects to store
|
|
157
|
+
* @returns true on success
|
|
158
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
159
|
+
* @throws {Error} DOMAIN_MISMATCH - A cookie's domain doesn't match URL host
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* NitroCookies.setManySync('https://example.com', [
|
|
164
|
+
* { name: 'session', value: 'abc123' },
|
|
165
|
+
* { name: 'theme', value: 'dark' },
|
|
166
|
+
* ]);
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
setManySync(url: string, cookies: Cookie[]): boolean {
|
|
170
|
+
return NitroCookiesHybridObject.setManySync(url, cookies);
|
|
171
|
+
},
|
|
172
|
+
|
|
126
173
|
// ========================================
|
|
127
174
|
// ASYNCHRONOUS METHODS
|
|
128
175
|
// ========================================
|
|
@@ -168,6 +215,63 @@ export const NitroCookies = {
|
|
|
168
215
|
return NitroCookiesHybridObject.set(url, cookie, useWebKit ?? false);
|
|
169
216
|
},
|
|
170
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Set multiple cookies for a URL.
|
|
220
|
+
*
|
|
221
|
+
* Applies the same domain validation as `set` to every cookie. If any
|
|
222
|
+
* cookie's domain doesn't match the URL host, the whole call rejects and no
|
|
223
|
+
* cookies are written.
|
|
224
|
+
*
|
|
225
|
+
* @param url - The URL for which to set the cookies. Must include protocol.
|
|
226
|
+
* @param cookies - The cookie objects to store
|
|
227
|
+
* @param useWebKit - (iOS only) If true, use WKHTTPCookieStore instead of NSHTTPCookieStorage. Requires iOS 11+.
|
|
228
|
+
*
|
|
229
|
+
* @returns Promise that resolves to true on success
|
|
230
|
+
*
|
|
231
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
232
|
+
* @throws {Error} DOMAIN_MISMATCH - A cookie's domain doesn't match URL host
|
|
233
|
+
* @throws {Error} WEBKIT_UNAVAILABLE - useWebKit=true on iOS < 11
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* await NitroCookies.setMany('https://example.com', [
|
|
238
|
+
* { name: 'session', value: 'abc123', secure: true },
|
|
239
|
+
* { name: 'theme', value: 'dark' },
|
|
240
|
+
* ]);
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
async setMany(
|
|
244
|
+
url: string,
|
|
245
|
+
cookies: Cookie[],
|
|
246
|
+
useWebKit?: boolean
|
|
247
|
+
): Promise<boolean> {
|
|
248
|
+
return NitroCookiesHybridObject.setMany(url, cookies, useWebKit ?? false);
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get the `Cookie` request-header string for a URL.
|
|
253
|
+
*
|
|
254
|
+
* Returns the value you would put in an HTTP `Cookie` request header
|
|
255
|
+
* (e.g. `"name1=value1; name2=value2"`), built from every cookie that
|
|
256
|
+
* matches the URL. Returns an empty string when no cookies match.
|
|
257
|
+
*
|
|
258
|
+
* @param url - The URL to match cookies against. Must include protocol.
|
|
259
|
+
* @param useWebKit - (iOS only) If true, read from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
260
|
+
*
|
|
261
|
+
* @returns Promise that resolves to the Cookie header string, or "" when no cookies match
|
|
262
|
+
*
|
|
263
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const header = await NitroCookies.getCookieHeader('https://example.com');
|
|
268
|
+
* await fetch('https://example.com/api', { headers: { Cookie: header } });
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
async getCookieHeader(url: string, useWebKit?: boolean): Promise<string> {
|
|
272
|
+
return NitroCookiesHybridObject.getCookieHeader(url, useWebKit ?? false);
|
|
273
|
+
},
|
|
274
|
+
|
|
171
275
|
/**
|
|
172
276
|
* Get all cookies matching a specific URL's domain.
|
|
173
277
|
*
|