@protobase/ui 0.44.4 → 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,
@@ -78,7 +78,8 @@ const text = defineMessages({
78
78
  newOrganization: "New organization",
79
79
  newOrganizationDescription: "You become its owner, with every role, and work in it once it is made.",
80
80
  invitationsForYou: "Invitations for you",
81
- invitationsForYouDescription: "Open the link in the invitation email to accept one.",
81
+ invitationsForYouDescription: "Accept one to become a member and work there.",
82
+ accept: "Accept",
82
83
  anOrganization: "An organization",
83
84
  noAppRoles: "no app roles",
84
85
  until: (date) => `Until ${date}`,
@@ -165,7 +166,8 @@ const text = defineMessages({
165
166
  newOrganization: "Nieuwe organisatie",
166
167
  newOrganizationDescription: "Je wordt de eigenaar, met elke rol, en werkt erin zodra die is gemaakt.",
167
168
  invitationsForYou: "Uitnodigingen voor jou",
168
- invitationsForYouDescription: "Open de link in de uitnodigingsmail om er een te accepteren.",
169
+ invitationsForYouDescription: "Accepteer er een om lid te worden en daar te werken.",
170
+ accept: "Accepteren",
169
171
  anOrganization: "Een organisatie",
170
172
  noAppRoles: "geen app-rollen",
171
173
  until: (date) => `Tot ${date}`,
@@ -63,35 +63,50 @@ const NewOrganization = ({ basePath }) => {
63
63
  })]
64
64
  });
65
65
  };
66
- const YourInvitations = () => {
66
+ /** The invitations for the person's own address, each to accept, which opens the app in its organization. */
67
+ const YourInvitations = ({ basePath }) => {
67
68
  const { session, organizations } = useAuth();
68
69
  const [invitations, setInvitations] = useState([]);
70
+ const { busy, error, run } = useAction();
69
71
  useEffect(() => {
70
72
  session.organizations.myInvitations().then(setInvitations, () => setInvitations([]));
71
73
  }, [session]);
72
74
  if (invitations.length === 0) return null;
73
75
  const roles = organizations?.roles ?? [];
74
- return /* @__PURE__ */ jsx(AccountSection, {
76
+ const accept = (invitationId) => run(async () => {
77
+ await session.organizations.acceptMine(invitationId);
78
+ reopenIn(basePath);
79
+ });
80
+ return /* @__PURE__ */ jsxs(AccountSection, {
75
81
  title: text("invitationsForYou"),
76
82
  description: text("invitationsForYouDescription"),
77
- children: /* @__PURE__ */ jsx("ul", {
83
+ children: [/* @__PURE__ */ jsx(SectionError, { message: error }), /* @__PURE__ */ jsx("ul", {
78
84
  className: "divide-y rounded-md border",
79
85
  children: invitations.map((invitation) => /* @__PURE__ */ jsxs("li", {
80
- className: "px-3 py-2.5",
81
- children: [
82
- /* @__PURE__ */ jsx("span", {
83
- className: "font-medium",
84
- children: invitation.organizationName ?? text("anOrganization")
85
- }),
86
- ": ",
87
- invitation.appRoles.map((name) => roleLabel(roles, name)).join(", ") || text("noAppRoles"),
88
- /* @__PURE__ */ jsx("span", {
89
- className: "block text-xs text-muted-foreground",
90
- children: text("until", new Date(invitation.expiresAt).toLocaleDateString(formatTag()))
91
- })
92
- ]
86
+ className: "flex items-center gap-3 px-3 py-2.5",
87
+ children: [/* @__PURE__ */ jsxs("span", {
88
+ className: "min-w-0 flex-1",
89
+ children: [
90
+ /* @__PURE__ */ jsx("span", {
91
+ className: "font-medium",
92
+ children: invitation.organizationName ?? text("anOrganization")
93
+ }),
94
+ ": ",
95
+ invitation.appRoles.map((name) => roleLabel(roles, name)).join(", ") || text("noAppRoles"),
96
+ /* @__PURE__ */ jsx("span", {
97
+ className: "block text-xs text-muted-foreground",
98
+ children: text("until", new Date(invitation.expiresAt).toLocaleDateString(formatTag()))
99
+ })
100
+ ]
101
+ }), /* @__PURE__ */ jsx(Button, {
102
+ size: "sm",
103
+ variant: "primary",
104
+ loading: busy,
105
+ onClick: () => void accept(invitation.id),
106
+ children: text("accept")
107
+ })]
93
108
  }, invitation.id))
94
- })
109
+ })]
95
110
  });
96
111
  };
97
112
  /**
@@ -127,7 +142,7 @@ const OrganizationsPage = ({ state, basePath }) => {
127
142
  }, organization.id))
128
143
  })]
129
144
  }),
130
- /* @__PURE__ */ jsx(YourInvitations, {}),
145
+ /* @__PURE__ */ jsx(YourInvitations, { basePath }),
131
146
  mayCreate && /* @__PURE__ */ jsx(NewOrganization, { basePath }),
132
147
  (state.current?.globalRoles.length ?? 0) > 0 && /* @__PURE__ */ jsx(AllOrganizations, {
133
148
  basePath,
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.44.4";
2
+ var version = "0.45.0";
3
3
  var protobase = { "pluginApi": 1 };
4
4
  //#endregion
5
5
  export { protobase, version };