@protobase/ui 0.44.5 → 0.45.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.
@@ -11,37 +11,65 @@ const nullBodyStatuses = [
11
11
  const encodedSeparator = /%2f|%5c/i;
12
12
  const isPlatform = (platform) => Object.hasOwn(capacitorOrigin, platform);
13
13
  const allowedUrl = (url, apiOrigin) => url.origin === apiOrigin && !url.username && !url.password && url.pathname.startsWith(`${authBasePath}/`) && !encodedSeparator.test(url.pathname);
14
+ /**
15
+ * The native call of a sign-in request: on Android Protobase's own ProtobaseAuth plugin, which checks the address,
16
+ * names the Capacitor origin, refuses redirects and keeps Set-Cookie from the page itself; on iOS, until it has that
17
+ * plugin too, Capacitor's native HTTP with the origin named here.
18
+ */
19
+ const nativeAuthCall = (platform, { url, method, headers, data }) => {
20
+ const withData = data === void 0 ? {} : { data };
21
+ if (platform === "android") return [
22
+ "ProtobaseAuth",
23
+ "request",
24
+ {
25
+ url,
26
+ method,
27
+ headers,
28
+ ...withData
29
+ }
30
+ ];
31
+ return [
32
+ "CapacitorHttp",
33
+ "request",
34
+ {
35
+ url,
36
+ method,
37
+ headers: {
38
+ ...headers,
39
+ origin: capacitorOrigin[platform]
40
+ },
41
+ ...withData,
42
+ responseType: "text",
43
+ disableRedirects: true
44
+ }
45
+ ];
46
+ };
14
47
  const bodyOf = ({ status, headers, data }) => {
15
48
  if (nullBodyStatuses.includes(status)) return null;
16
49
  if (Object.entries(headers).some(([name, value]) => name.toLowerCase() === "content-type" && value.startsWith("application/json"))) return JSON.stringify(data);
17
50
  return typeof data === "string" ? data : JSON.stringify(data);
18
51
  };
19
52
  /**
20
- * A `fetch` for the app's sign-in, at `<apiOrigin>/api/auth/...` only, through Capacitor's native HTTP: the session
21
- * cookie lives in the device's cookie jar, which native HTTP sends and keeps, and the request names the Capacitor
22
- * origin of the platform, which the server trusts for sign-in with a mobile section. The page cannot set `Cookie`, so
23
- * the cookie comes from the native jar alone. Any other address is refused before the bridge is called.
53
+ * A `fetch` for the app's sign-in, at `<apiOrigin>/api/auth/...` only, through native HTTP (`nativeAuthCall`): the
54
+ * session cookie lives in the device's cookie jar, which native HTTP sends and keeps, and the request names the
55
+ * Capacitor origin of the platform, which the server trusts for sign-in with a mobile section. The page cannot set
56
+ * `Cookie`, so the cookie comes from the native jar alone. Any other address is refused before the bridge is called.
24
57
  */
25
58
  const nativeAuthFetch = (bridge, apiOrigin) => {
26
59
  const platform = bridge.getPlatform();
27
60
  if (!isPlatform(platform)) throw new Error(`Signing in through native HTTP is for iOS and Android, not ${platform}`);
28
- const origin = capacitorOrigin[platform];
29
61
  return async (input, init) => {
30
62
  const request = new Request(input, init);
31
63
  const url = new URL(request.url);
32
64
  if (!allowedUrl(url, apiOrigin)) throw new Error(`Native sign-in requests go to ${apiOrigin}${authBasePath}/ only, not ${request.url}`);
33
65
  const withBody = request.method !== "GET" && request.method !== "HEAD";
34
- const answer = await bridge.nativePromise("CapacitorHttp", "request", {
66
+ const call = nativeAuthCall(platform, {
35
67
  url: url.href,
36
68
  method: request.method,
37
- headers: {
38
- ...Object.fromEntries(request.headers),
39
- origin
40
- },
41
- ...withBody && { data: await request.text() },
42
- responseType: "text",
43
- disableRedirects: true
69
+ headers: Object.fromEntries(request.headers),
70
+ ...withBody && { data: await request.text() }
44
71
  });
72
+ const answer = await bridge.nativePromise(...call);
45
73
  const headers = Object.entries(answer.headers).filter(([name]) => name.toLowerCase() !== "set-cookie");
46
74
  return new Response(bodyOf(answer), {
47
75
  status: answer.status,
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.44.5";
2
+ var version = "0.45.0";
3
3
  var protobase = { "pluginApi": 1 };
4
4
  //#endregion
5
5
  export { protobase, version };