@nylas/react 2.2.0 → 2.2.2

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.
@@ -1,279 +1,284 @@
1
- import { useRef as m, useEffect as f, useState as D, useCallback as i } from "react";
2
- import { NylasConnect as O } from "@nylas/connect";
3
- import { BrowserTokenStorage as z, ConfigError as G, MemoryTokenStorage as K, NetworkError as V, NylasConnect as B, NylasConnectError as W, OAuthError as X, PopupError as j, TokenError as q, isAuthCallback as F, logger as J, parseAuthCallback as Q } from "@nylas/connect";
4
- function M(E) {
1
+ import { useRef as m, useEffect as f, useState as _, useCallback as i } from "react";
2
+ import { NylasConnect as U } from "@nylas/connect";
3
+ import { BrowserTokenStorage as K, ConfigError as V, MemoryTokenStorage as B, NetworkError as W, NylasConnect as X, NylasConnectError as j, OAuthError as q, PopupError as F, TokenError as H, isConnectCallback as J, logger as Q, parseConnectCallback as Y } from "@nylas/connect";
4
+ function v(y) {
5
5
  const {
6
6
  autoRefreshInterval: d,
7
- initialLoadingState: y = !0,
7
+ initialLoadingState: P = !0,
8
8
  retryAttempts: u = 0,
9
- enableAutoRecovery: b = !1,
10
- ...P
11
- } = E, h = m(null);
12
- h.current || (h.current = new O(P));
13
- const n = h.current, w = m({
9
+ enableAutoRecovery: C = !1,
10
+ ...L
11
+ } = y, h = m(null);
12
+ h.current || (h.current = new U(L));
13
+ const t = h.current, w = m({
14
14
  isProcessing: !1,
15
15
  processedUrl: null,
16
16
  hasProcessed: !1
17
17
  });
18
18
  f(() => {
19
- var r;
20
- const s = ((r = globalThis.window) == null ? void 0 : r.location.href) || "", t = w.current;
21
- !(s.includes("code=") && s.includes("state=")) && t.hasProcessed && (t.hasProcessed = !1, t.processedUrl = null);
22
- }), f(() => n.isAutoCallbackEnabled() ? ((async () => {
23
- var o, a, g;
24
- const t = ((o = globalThis.window) == null ? void 0 : o.location.href) || "", e = w.current;
25
- if (!(e.isProcessing || e.processedUrl === t || e.hasProcessed || !(t.includes("code=") && t.includes("state=")))) {
26
- try {
27
- if (await n.getSession()) {
28
- e.hasProcessed = !0, e.processedUrl = t;
29
- return;
19
+ var e;
20
+ const n = ((e = globalThis.window) == null ? void 0 : e.location.href) || "", s = w.current;
21
+ !(n.includes("code=") && n.includes("state=")) && s.hasProcessed && (s.hasProcessed = !1, s.processedUrl = null);
22
+ }), f(() => {
23
+ if (!t.isAutoCallbackEnabled())
24
+ return;
25
+ const n = w;
26
+ return (async () => {
27
+ var o, g, b;
28
+ const r = ((o = globalThis.window) == null ? void 0 : o.location.href) || "", e = n.current;
29
+ if (!(e.isProcessing || e.processedUrl === r || e.hasProcessed || !(r.includes("code=") && r.includes("state=")))) {
30
+ try {
31
+ if (await t.getSession()) {
32
+ e.hasProcessed = !0, e.processedUrl = r;
33
+ return;
34
+ }
35
+ } catch {
30
36
  }
31
- } catch {
32
- }
33
- e.isProcessing = !0, e.processedUrl = t;
34
- try {
35
- if (await n.callback(), e.hasProcessed = !0, (g = (a = globalThis.window) == null ? void 0 : a.history) != null && g.replaceState) {
36
- const c = new URL(globalThis.window.location.href), U = ["code", "state", "error", "error_description"];
37
- let C = !1;
38
- U.forEach((S) => {
39
- c.searchParams.has(S) && (c.searchParams.delete(S), C = !0);
40
- }), C && globalThis.window.history.replaceState(
41
- globalThis.window.history.state,
42
- document.title,
43
- c.toString()
44
- );
37
+ e.isProcessing = !0, e.processedUrl = r;
38
+ try {
39
+ if (await t.callback(), e.hasProcessed = !0, (b = (g = globalThis.window) == null ? void 0 : g.history) != null && b.replaceState) {
40
+ const c = new URL(globalThis.window.location.href), D = ["code", "state", "error", "error_description"];
41
+ let E = !1;
42
+ D.forEach((S) => {
43
+ c.searchParams.has(S) && (c.searchParams.delete(S), E = !0);
44
+ }), E && globalThis.window.history.replaceState(
45
+ globalThis.window.history.state,
46
+ document.title,
47
+ c.toString()
48
+ );
49
+ }
50
+ } catch (c) {
51
+ console.log("callback error", c), e.isProcessing = !1, e.processedUrl = null;
52
+ } finally {
53
+ e.isProcessing = !1;
45
54
  }
46
- } catch (c) {
47
- console.log("callback error", c), e.isProcessing = !1, e.processedUrl = null;
48
- } finally {
49
- e.isProcessing = !1;
50
55
  }
51
- }
52
- })(), () => {
53
- const t = w.current;
54
- t.isProcessing || (t.processedUrl = null, t.hasProcessed = !1);
55
- }) : void 0, [n]);
56
- const [L, l] = D({
56
+ })(), () => {
57
+ const r = n.current;
58
+ r != null && r.isProcessing || (r.processedUrl = null, r.hasProcessed = !1);
59
+ };
60
+ }, [t]);
61
+ const [p, l] = _({
57
62
  isConnected: !1,
58
63
  grant: null,
59
- isLoading: y,
64
+ isLoading: P,
60
65
  error: null
61
66
  });
62
67
  f(() => {
63
- let s = !0;
68
+ let n = !0;
64
69
  return (async () => {
65
70
  try {
66
- const e = await n.getSession(), r = await n.isConnected();
67
- s && l((o) => ({
68
- ...o,
69
- isConnected: r,
70
- grant: (e == null ? void 0 : e.grantInfo) || null,
71
+ const r = await t.getSession(), e = await t.isConnected();
72
+ n && l((a) => ({
73
+ ...a,
74
+ isConnected: e,
75
+ grant: (r == null ? void 0 : r.grantInfo) || null,
71
76
  isLoading: !1,
72
77
  error: null
73
78
  }));
74
- } catch (e) {
75
- s && l((r) => ({
76
- ...r,
79
+ } catch (r) {
80
+ n && l((e) => ({
81
+ ...e,
77
82
  isConnected: !1,
78
83
  grant: null,
79
84
  isLoading: !1,
80
- error: e
85
+ error: r
81
86
  }));
82
87
  }
83
88
  })(), () => {
84
- s = !1;
89
+ n = !1;
85
90
  };
86
- }, [n]), f(() => {
91
+ }, [t]), f(() => {
87
92
  if (!d || d <= 0)
88
93
  return;
89
- const s = setInterval(async () => {
94
+ const n = setInterval(async () => {
90
95
  try {
91
- const t = await n.getSession(), e = await n.isConnected();
92
- l((r) => ({
93
- ...r,
94
- isConnected: e,
95
- grant: (t == null ? void 0 : t.grantInfo) || null,
96
+ const s = await t.getSession(), r = await t.isConnected();
97
+ l((e) => ({
98
+ ...e,
99
+ isConnected: r,
100
+ grant: (s == null ? void 0 : s.grantInfo) || null,
96
101
  error: null
97
102
  }));
98
- } catch (t) {
99
- b ? console.debug(
103
+ } catch (s) {
104
+ C ? console.debug(
100
105
  "Auto-refresh failed, will retry next interval:",
101
- t
102
- ) : l((e) => ({
103
- ...e,
104
- error: t
106
+ s
107
+ ) : l((r) => ({
108
+ ...r,
109
+ error: s
105
110
  }));
106
111
  }
107
112
  }, d);
108
- return () => clearInterval(s);
109
- }, [n, d, b]), f(() => {
110
- const s = (e, r, o) => {
111
- l((a) => {
112
- switch (e) {
113
- case "AUTH_STARTED":
113
+ return () => clearInterval(n);
114
+ }, [t, d, C]), f(() => {
115
+ const n = (r, e, a) => {
116
+ l((o) => {
117
+ switch (r) {
118
+ case "CONNECT_STARTED":
114
119
  return {
115
- ...a,
120
+ ...o,
116
121
  isLoading: !0,
117
122
  error: null
118
123
  };
119
124
  case "SIGNED_IN":
120
125
  case "SESSION_RESTORED":
121
126
  return {
122
- ...a,
127
+ ...o,
123
128
  isConnected: !0,
124
- grant: (r == null ? void 0 : r.grantInfo) || null,
129
+ grant: (e == null ? void 0 : e.grantInfo) || null,
125
130
  isLoading: !1,
126
131
  error: null
127
132
  };
128
133
  case "SIGNED_OUT":
129
134
  return {
130
- ...a,
135
+ ...o,
131
136
  isConnected: !1,
132
137
  grant: null,
133
138
  isLoading: !1,
134
139
  error: null
135
140
  };
136
- case "AUTH_ERROR":
141
+ case "CONNECT_ERROR":
137
142
  case "NETWORK_ERROR":
138
143
  case "TOKEN_VALIDATION_ERROR":
139
144
  return {
140
- ...a,
145
+ ...o,
141
146
  isLoading: !1,
142
- error: (o == null ? void 0 : o.error) || new Error("Authentication error")
147
+ error: (a == null ? void 0 : a.error) || new Error("Authentication error")
143
148
  };
144
- case "AUTH_CANCELLED":
149
+ case "CONNECT_CANCELLED":
145
150
  return {
146
- ...a,
151
+ ...o,
147
152
  isLoading: !1,
148
153
  error: null
149
154
  };
150
155
  case "SESSION_EXPIRED":
151
156
  case "SESSION_INVALID":
152
157
  return {
153
- ...a,
158
+ ...o,
154
159
  isConnected: !1,
155
160
  grant: null,
156
161
  isLoading: !1,
157
162
  error: null
158
163
  };
159
164
  default:
160
- return a;
165
+ return o;
161
166
  }
162
167
  });
163
168
  };
164
- return n.onAuthStateChange(
165
- s
169
+ return t.onConnectStateChange(
170
+ n
166
171
  );
167
- }, [n]);
168
- const A = i(
169
- async (s = {}) => {
170
- l((r) => ({ ...r, isLoading: !0, error: null }));
171
- let t;
172
- const e = u + 1;
173
- for (let r = 1; r <= e; r++)
172
+ }, [t]);
173
+ const N = i(
174
+ async (n = {}) => {
175
+ l((e) => ({ ...e, isLoading: !0, error: null }));
176
+ let s;
177
+ const r = u + 1;
178
+ for (let e = 1; e <= r; e++)
174
179
  try {
175
- return await n.connect(s);
176
- } catch (o) {
177
- if (t = o, r < e) {
178
- const a = Math.min(1e3 * Math.pow(2, r - 1), 5e3);
179
- await new Promise((g) => setTimeout(g, a));
180
+ return await t.connect(n);
181
+ } catch (a) {
182
+ if (s = a, e < r) {
183
+ const o = Math.min(1e3 * Math.pow(2, e - 1), 5e3);
184
+ await new Promise((g) => setTimeout(g, o));
180
185
  }
181
186
  }
182
- throw t;
187
+ throw s;
183
188
  },
184
- [n, u]
185
- ), p = i(
186
- async (s) => {
187
- l((r) => ({ ...r, isLoading: !0, error: null }));
188
- let t;
189
- const e = u + 1;
190
- for (let r = 1; r <= e; r++)
189
+ [t, u]
190
+ ), T = i(
191
+ async (n) => {
192
+ l((e) => ({ ...e, isLoading: !0, error: null }));
193
+ let s;
194
+ const r = u + 1;
195
+ for (let e = 1; e <= r; e++)
191
196
  try {
192
- await n.logout(s);
197
+ await t.logout(n);
193
198
  return;
194
- } catch (o) {
195
- if (t = o, r < e) {
196
- const a = Math.min(1e3 * Math.pow(2, r - 1), 3e3);
197
- await new Promise((g) => setTimeout(g, a));
199
+ } catch (a) {
200
+ if (s = a, e < r) {
201
+ const o = Math.min(1e3 * Math.pow(2, e - 1), 3e3);
202
+ await new Promise((g) => setTimeout(g, o));
198
203
  }
199
204
  }
200
- throw l((r) => ({
201
- ...r,
205
+ throw l((e) => ({
206
+ ...e,
202
207
  isLoading: !1,
203
- error: t
204
- })), t;
208
+ error: s
209
+ })), s;
205
210
  },
206
- [n, u]
207
- ), T = i(async () => {
208
- l((e) => ({ ...e, isLoading: !0, error: null }));
209
- let s;
210
- const t = u + 1;
211
- for (let e = 1; e <= t; e++)
211
+ [t, u]
212
+ ), R = i(async () => {
213
+ l((r) => ({ ...r, isLoading: !0, error: null }));
214
+ let n;
215
+ const s = u + 1;
216
+ for (let r = 1; r <= s; r++)
212
217
  try {
213
- const r = await n.getSession(), o = await n.isConnected();
214
- l((a) => ({
215
- ...a,
216
- isConnected: o,
217
- grant: (r == null ? void 0 : r.grantInfo) || null,
218
+ const e = await t.getSession(), a = await t.isConnected();
219
+ l((o) => ({
220
+ ...o,
221
+ isConnected: a,
222
+ grant: (e == null ? void 0 : e.grantInfo) || null,
218
223
  isLoading: !1,
219
224
  error: null
220
225
  }));
221
226
  return;
222
- } catch (r) {
223
- if (s = r, e < t) {
224
- const o = Math.min(1e3 * Math.pow(2, e - 1), 3e3);
225
- await new Promise((a) => setTimeout(a, o));
227
+ } catch (e) {
228
+ if (n = e, r < s) {
229
+ const a = Math.min(1e3 * Math.pow(2, r - 1), 3e3);
230
+ await new Promise((o) => setTimeout(o, a));
226
231
  }
227
232
  }
228
- throw l((e) => ({
229
- ...e,
233
+ throw l((r) => ({
234
+ ...r,
230
235
  isConnected: !1,
231
236
  grant: null,
232
237
  isLoading: !1,
233
- error: s
234
- })), s;
235
- }, [n, u]), k = i(
236
- (s) => n.onAuthStateChange(s),
237
- [n]
238
- ), R = i(() => {
239
- n.enableDebug();
240
- }, [n]), I = i(() => {
241
- n.disableDebug();
242
- }, [n]), N = i(
243
- (s) => {
244
- n.setLogLevel(s);
238
+ error: n
239
+ })), n;
240
+ }, [t, u]), k = i(
241
+ (n) => t.onConnectStateChange(n),
242
+ [t]
243
+ ), I = i(() => {
244
+ t.enableDebug();
245
+ }, [t]), A = i(() => {
246
+ t.disableDebug();
247
+ }, [t]), O = i(
248
+ (n) => {
249
+ t.setLogLevel(n);
245
250
  },
246
- [n]
251
+ [t]
247
252
  );
248
253
  return {
249
254
  // State
250
- ...L,
255
+ ...p,
251
256
  // Actions
252
- connect: A,
253
- logout: p,
254
- refreshSession: T,
257
+ connect: N,
258
+ logout: T,
259
+ refreshSession: R,
255
260
  subscribe: k,
256
261
  // Logger controls
257
- enableDebug: R,
258
- disableDebug: I,
259
- setLogLevel: N,
262
+ enableDebug: I,
263
+ disableDebug: A,
264
+ setLogLevel: O,
260
265
  // Direct access
261
- authClient: n,
262
- logger: n.logger
266
+ connectClient: t,
267
+ logger: t.logger
263
268
  };
264
269
  }
265
270
  export {
266
- z as BrowserTokenStorage,
267
- G as ConfigError,
268
- K as MemoryTokenStorage,
269
- V as NetworkError,
270
- B as NylasConnect,
271
- W as NylasConnectError,
272
- X as OAuthError,
273
- j as PopupError,
274
- q as TokenError,
275
- F as isAuthCallback,
276
- J as logger,
277
- Q as parseAuthCallback,
278
- M as useNylasConnect
271
+ K as BrowserTokenStorage,
272
+ V as ConfigError,
273
+ B as MemoryTokenStorage,
274
+ W as NetworkError,
275
+ X as NylasConnect,
276
+ j as NylasConnectError,
277
+ q as OAuthError,
278
+ F as PopupError,
279
+ H as TokenError,
280
+ J as isConnectCallback,
281
+ Q as logger,
282
+ Y as parseConnectCallback,
283
+ v as useNylasConnect
279
284
  };
package/dist/es/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { AddCircleIcon as Di, ArchiveIcon as Li, ArrowIcon as wi, BoldIcon as Ai, ButtonComponent as Ri, CalendarAgendaFillIcon as xi, CalendarAgendaIcon as Mi, CalendarCancelIcon as Gi, CalendarCheckIcon as Wi, CalendarIcon as zi, CalendarInfoIcon as Oi, CalendarPatternsIcon as Ui, CheckboxComponent as qi, CheckboxGroup as Vi, CheckmarkCircleIcon as Zi, CheckmarkIcon as ji, ChevronIcon as Hi, ClockIcon as Ji, CloseIcon as Ki, CopyIcon as Qi, DeleteIcon as Xi, DocumentRefreshIcon as Yi, DragableIcon as _i, EditIcon as $i, EnvelopeFillIcon as ot, EnvelopeIcon as it, EyeIcon as tt, FeedbackIcon as rt, FlowIcon as nt, FolderIcon as mt, ForwardIcon as et, GlobeIcon as pt, GoogleLogoIcon as at, GoogleMeetIcon as lt, InboxIcon as ct, InfoIcon as st, InputColorPicker as yt, InputComponent as It, InputDropdown as Nt, InputImageUrl as dt, ItalicIcon as Ct, LoadingIcon as gt, LocationIcon as kt, LocationOffIcon as ut, MicrosoftLogoIcon as vt, MicrosoftTeamsIcon as Et, MultiSelectDropdown as Pt, NylasAdditionalParticipants as St, NylasAvailabilityPicker as ft, NylasBookedEventCard as Tt, NylasBookingCalendarPicker as ht, NylasBookingConfirmationRedirect as bt, NylasBookingConfirmationType as Bt, NylasBookingForm as Ft, NylasBookingFormConfig as Dt, NylasBufferTime as Lt, NylasCalendarPicker as wt, NylasCancelBookingForm as At, NylasCancellationPolicy as Rt, NylasCancelledEventCard as xt, NylasConfirmationEmail as Mt, NylasConfirmedEventCard as Gt, NylasConnectedCalendars as Wt, NylasCustomBookingFlow as zt, NylasCustomEventSlug as Ot, NylasCustomizeBookingSettings as Ut, NylasDateComponent as qt, NylasDatePicker as Vt, NylasDisableEmails as Zt, NylasEditorTabs as jt, NylasEditorTabsGroup as Ht, NylasEventCalendar as Jt, NylasEventCapacity as Kt, NylasEventDescription as Qt, NylasEventDuration as Xt, NylasEventInfo as Yt, NylasEventLimits as _t, NylasEventLocation as $t, NylasEventTimeslot as or, NylasEventTitle as ir, NylasFeedbackForm as tr, NylasFormCard as rr, NylasLimitFutureBookings as nr, NylasListConfigurations as mr, NylasLocaleSwitch as er, NylasLogo as pr, NylasMinBookingNotice as ar, NylasMinCancellationNotice as lr, NylasNotification as cr, NylasOrganizerConfirmationCard as sr, NylasPageName as yr, NylasPageStyling as Ir, NylasParticipantBookingCalendars as Nr, NylasParticipantsCustomAvailability as dr, NylasReminderEmails as Cr, NylasReminderTime as gr, NylasSchedulerEditor as kr, NylasScheduling as ur, NylasSchedulingMethod as vr, NylasSelectEventType as Er, NylasSelectedEventCard as Pr, NylasSpecificTimeAvailabilityPicker as Sr, NylasTimeWindowPicker as fr, NylasTimeslotInterval as Tr, NylasTimeslotPicker as hr, PaintbrushFillIcon as br, PaintbrushIcon as Br, PeopleIcon as Fr, PersonClipboardIcon as Dr, PersonIcon as Lr, PlayIcon as wr, PlusIcon as Ar, RadioButtonGroup as Rr, RefreshIcon as xr, ReplyAllIcon as Mr, ReplyIcon as Gr, SearchIcon as Wr, SelectDropdown as zr, SentIcon as Or, SpamIcon as Ur, StarIcon as qr, StopIcon as Vr, TextareaComponent as Zr, TimePeriodSelector as jr, ToggleSwitch as Hr, TooltipComponent as Jr, TranslateIcon as Kr, TrashFillIcon as Qr, TrashIcon as Xr, UnderlineIcon as Yr, WarningIcon as _r, ZoomIcon as $r } from "./elements.js";
2
2
  import { CalendarSync as tn, SendNotetaker as rn, Transcript as nn, VideoPlayer as mn, calendarSyncStore as en, provider as pn, sendNotetakerStore as an, videoPlayerStore as ln } from "./notetaker.js";
3
- import { NylasIdentityRequestWrapper as sn } from "./utils.js";
3
+ import { NylasIdentityRequestWrapper as sn } from "@nylas/web-elements/components";
4
4
  import "@nylas/web-elements/dist/components/add-circle-icon.js";
5
5
  import "@nylas/web-elements/dist/components/archive-icon.js";
6
6
  import "@nylas/web-elements/dist/components/arrow-icon.js";
@@ -5248,7 +5248,7 @@ He.interceptors.request.use((e) => {
5248
5248
  const n = t.getAccessToken();
5249
5249
  return n && (e.headers.Authorization = `Bearer ${n}`), e;
5250
5250
  });
5251
- var J = /* @__PURE__ */ ((e) => (e.Video = "video", e.Audio = "audio", e.Transcript = "transcript", e))(J || {}), ae = /* @__PURE__ */ ((e) => (e.All = "all", e.Internal = "internal", e.External = "external", e.MyMeetings = "my_meetings", e.Participant = "participant", e))(ae || {});
5251
+ var J = /* @__PURE__ */ ((e) => (e.Video = "video", e.Audio = "audio", e.Transcript = "transcript", e))(J || {}), ae = /* @__PURE__ */ ((e) => (e.All = "all", e.Internal = "internal", e.External = "external", e.MyMeetings = "own_events", e.Participant = "participant_only", e))(ae || {});
5252
5252
  const Kn = [
5253
5253
  J.Video,
5254
5254
  J.Audio,
@@ -5446,7 +5446,7 @@ function Jo({
5446
5446
  _(e, t, n);
5447
5447
  }, [e, t, n, _]), Se(() => {
5448
5448
  n && O(n);
5449
- }, []);
5449
+ }, [n, O]);
5450
5450
  const q = Object.keys((l == null ? void 0 : l.notetaker) || {}).length === 0;
5451
5451
  return /* @__PURE__ */ H("div", { className: "ny:flex ny:flex-col ny:gap-1", children: [
5452
5452
  !a && /* @__PURE__ */ H("div", { className: "ny:mb-2", children: [
@@ -5665,7 +5665,7 @@ function Yo({
5665
5665
  } = Vo();
5666
5666
  Se(() => {
5667
5667
  r && o(r);
5668
- }, []);
5668
+ }, [r, o]);
5669
5669
  const O = !!a;
5670
5670
  return /* @__PURE__ */ H("div", { className: `ny:flex ny:flex-col ny:gap-3 ${e}`, children: [
5671
5671
  /* @__PURE__ */ H("div", { children: [