@nylas/react 1.0.0-prealpha1
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/LICENSE.md +22 -0
- package/README.md +3 -0
- package/dist/_commonjsHelpers-57e89916-4a3ae7d8.cjs +1 -0
- package/dist/_commonjsHelpers-57e89916-af061c86.js +19 -0
- package/dist/archive-icon_7.entry-53aede1b.js +75 -0
- package/dist/archive-icon_7.entry-8c90815a.cjs +1 -0
- package/dist/arrow-icon.entry-2867f4fb.js +15 -0
- package/dist/arrow-icon.entry-a2f53919.cjs +1 -0
- package/dist/bold-icon_3.entry-ad806730.js +35 -0
- package/dist/bold-icon_3.entry-e0bc6774.cjs +1 -0
- package/dist/calendar-cancel-icon.entry-546b7bd4.cjs +1 -0
- package/dist/calendar-cancel-icon.entry-74051835.js +15 -0
- package/dist/calendar-check-icon_3.entry-42bab0b4.js +35 -0
- package/dist/calendar-check-icon_3.entry-f5846fee.cjs +1 -0
- package/dist/calendar-icon.entry-25474b1e.cjs +1 -0
- package/dist/calendar-icon.entry-c751873f.js +15 -0
- package/dist/chevron-icon.entry-60842fb6.js +15 -0
- package/dist/chevron-icon.entry-97e4621e.cjs +1 -0
- package/dist/close-icon_2.entry-aa015993.cjs +1 -0
- package/dist/close-icon_2.entry-ef03bd27.js +25 -0
- package/dist/core-js-38e53e34.cjs +4 -0
- package/dist/core-js-a9d3b6e1.js +3297 -0
- package/dist/document-refresh-icon.entry-b27207eb.js +15 -0
- package/dist/document-refresh-icon.entry-ca2ef29e.cjs +1 -0
- package/dist/dom-68f08be9.cjs +15 -0
- package/dist/dom-86e17616.js +664 -0
- package/dist/duration-bddc4a13-05d3e3e2.cjs +1 -0
- package/dist/duration-bddc4a13-179ce826.js +41 -0
- package/dist/elements/index.d.ts +56 -0
- package/dist/elements/react-component-lib/createComponent.d.ts +10 -0
- package/dist/elements/react-component-lib/createOverlayComponent.d.ts +21 -0
- package/dist/elements/react-component-lib/index.d.ts +2 -0
- package/dist/elements/react-component-lib/interfaces.d.ts +29 -0
- package/dist/elements/react-component-lib/utils/attachProps.d.ts +9 -0
- package/dist/elements/react-component-lib/utils/case.d.ts +2 -0
- package/dist/elements/react-component-lib/utils/dev.d.ts +2 -0
- package/dist/elements/react-component-lib/utils/index.d.ts +10 -0
- package/dist/elements-60ebdb01-24595598.cjs +16494 -0
- package/dist/elements-60ebdb01-5d144002.js +27455 -0
- package/dist/flow-40ff9cea-6f8c30e2.cjs +9 -0
- package/dist/flow-40ff9cea-ee70fdf5.js +505 -0
- package/dist/focus-visible-e8093c16-28fc08a0.js +82 -0
- package/dist/focus-visible-e8093c16-f380b705.cjs +1 -0
- package/dist/forward-icon_6.entry-725d1be4.cjs +3 -0
- package/dist/forward-icon_6.entry-dc8f7235.js +955 -0
- package/dist/globe-icon.entry-796d3f48.js +15 -0
- package/dist/globe-icon.entry-918cfd35.cjs +1 -0
- package/dist/index-29d0e781.cjs +30 -0
- package/dist/index-2b85580a-bfc3ceac.cjs +7 -0
- package/dist/index-2b85580a-f9211f23.js +3238 -0
- package/dist/index-4f65b6f9.js +1489 -0
- package/dist/index.d.ts +4 -0
- package/dist/loading-icon.entry-8e49fab0.js +15 -0
- package/dist/loading-icon.entry-b2534e3e.cjs +1 -0
- package/dist/mailbox-store-0019772c-06d31a90.js +380 -0
- package/dist/mailbox-store-0019772c-d1254c5c.cjs +1 -0
- package/dist/nylas-booked-event-card_9.entry-d995d7cb.js +4567 -0
- package/dist/nylas-booked-event-card_9.entry-ea02f083.cjs +148 -0
- package/dist/nylas-if-state_3.entry-ce816adb.js +291 -0
- package/dist/nylas-if-state_3.entry-e8c831b7.cjs +1 -0
- package/dist/nylas-list-folders.entry-8134344b.js +121 -0
- package/dist/nylas-list-folders.entry-de8cca60.cjs +1 -0
- package/dist/nylas-list-threads.entry-1367fe30.js +71 -0
- package/dist/nylas-list-threads.entry-93b70a1a.cjs +1 -0
- package/dist/nylas-mailbox-pagination.entry-568ac217.js +102 -0
- package/dist/nylas-mailbox-pagination.entry-6bb0ee37.cjs +1 -0
- package/dist/nylas-mailbox-toolbar-button.entry-9214b283.js +83 -0
- package/dist/nylas-mailbox-toolbar-button.entry-d4ad5c15.cjs +1 -0
- package/dist/nylas-open-hours-picker.entry-109f13f5.js +186 -0
- package/dist/nylas-open-hours-picker.entry-2c19643f.cjs +1 -0
- package/dist/nylas-provider.entry-2cfe5f0e.js +134 -0
- package/dist/nylas-provider.entry-87fa9276.cjs +1 -0
- package/dist/nylas-scheduler.entry-6ec8e574.js +195 -0
- package/dist/nylas-scheduler.entry-b41cbf99.cjs +1 -0
- package/dist/nylas-threads-refresh.entry-6d61a689.cjs +1 -0
- package/dist/nylas-threads-refresh.entry-9111a403.js +75 -0
- package/dist/nylas-threads-search.entry-03073490.cjs +1 -0
- package/dist/nylas-threads-search.entry-2124f663.js +70 -0
- package/dist/nylas-view-thread.entry-4ecbcd78.cjs +1 -0
- package/dist/nylas-view-thread.entry-fe51c1f6.js +204 -0
- package/dist/play-icon_2.entry-8e156535.js +25 -0
- package/dist/play-icon_2.entry-cf1cbc8d.cjs +1 -0
- package/dist/property-0065dde7-83dc9cc4.cjs +23 -0
- package/dist/property-0065dde7-c57b8fa3.js +589 -0
- package/dist/react.cjs +1 -0
- package/dist/react.js +62 -0
- package/dist/refresh-icon.entry-4ddd53b0.js +15 -0
- package/dist/refresh-icon.entry-9f24e833.cjs +1 -0
- package/dist/register-component-55376f31-5eaf8954.js +105 -0
- package/dist/register-component-55376f31-8d6ddee4.cjs +1 -0
- package/dist/scheduler-store-5a39585a-117668e3.js +173 -0
- package/dist/scheduler-store-5a39585a-2c848bec.cjs +1 -0
- package/dist/translate-icon.entry-0cd24de4.cjs +1 -0
- package/dist/translate-icon.entry-db2cdf1d.js +15 -0
- package/dist/utils-5074a070-ce33ee6b.js +119 -0
- package/dist/utils-5074a070-d5ba6add.cjs +2 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export { applyPolyfills, defineCustomElements } from '@nylas/web-elements/loader';
|
|
3
|
+
export * from './elements/index';
|
|
4
|
+
export declare function useNylasMailboxElement(): readonly [import("react").MutableRefObject<HTMLNylasMailboxElement | undefined>, import("@nylas/web-elements").ObservableMap<import("@nylas/web-elements").NylasAuthStoreState> | null];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { r as t, h as a } from "./index-4f65b6f9.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import "react-dom";
|
|
4
|
+
const i = ".wave{display:flex;align-items:center;justify-content:center}.dot{width:4px;height:4px;background-color:var(--dot-color, white);border-radius:50%;margin:0 2px;animation:wave 1.5s infinite ease-in-out}.dot:nth-child(2){animation-delay:0.2s}.dot:nth-child(3){animation-delay:0.4s}@keyframes wave{0%,60%,100%{transform:translateY(0)}30%{transform:translateY(-4px)}}", n = i, o = class {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
t(this, e), this.width = "15", this.height = "15";
|
|
7
|
+
}
|
|
8
|
+
render() {
|
|
9
|
+
return a("div", { key: "236ae2f76a43a73bf12500c37a1315a798ee6682", class: "wave" }, a("div", { key: "53991ce94d24ad556b00eaf5a1110ce5ff442333", class: "dot" }), a("div", { key: "d0a4ba7f5c52e2942370b630a58dc7843d717ba3", class: "dot" }), a("div", { key: "a14c7426974e5d6eae289967b301dce3e6d2db39", class: "dot" }));
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
o.style = n;
|
|
13
|
+
export {
|
|
14
|
+
o as loading_icon
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-29d0e781.cjs");require("react");require("react-dom");const i=".wave{display:flex;align-items:center;justify-content:center}.dot{width:4px;height:4px;background-color:var(--dot-color, white);border-radius:50%;margin:0 2px;animation:wave 1.5s infinite ease-in-out}.dot:nth-child(2){animation-delay:0.2s}.dot:nth-child(3){animation-delay:0.4s}@keyframes wave{0%,60%,100%{transform:translateY(0)}30%{transform:translateY(-4px)}}",n=i,a=class{constructor(t){e.registerInstance(this,t),this.width="15",this.height="15"}render(){return e.h("div",{key:"236ae2f76a43a73bf12500c37a1315a798ee6682",class:"wave"},e.h("div",{key:"53991ce94d24ad556b00eaf5a1110ce5ff442333",class:"dot"}),e.h("div",{key:"d0a4ba7f5c52e2942370b630a58dc7843d717ba3",class:"dot"}),e.h("div",{key:"a14c7426974e5d6eae289967b301dce3e6d2db39",class:"dot"}))}};a.style=n;exports.loading_icon=a;
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { d as o } from "./utils-5074a070-ce33ee6b.js";
|
|
2
|
+
import { c as f, X as u, Z as d } from "./index-2b85580a-f9211f23.js";
|
|
3
|
+
class S {
|
|
4
|
+
constructor(t, e) {
|
|
5
|
+
this.nylasAuth = t, this.nylasAuthStore = e;
|
|
6
|
+
}
|
|
7
|
+
async validateSession() {
|
|
8
|
+
const t = await this.isAccessTokenValid();
|
|
9
|
+
if (!t)
|
|
10
|
+
this.logout();
|
|
11
|
+
else {
|
|
12
|
+
let e = await this.nylasAuth.getTokenInfo();
|
|
13
|
+
if (e) {
|
|
14
|
+
const a = Math.floor(Date.now() / 1e3);
|
|
15
|
+
if (e.expires_in && e.expires_in - a < 3e5 && (o("[NylasAuthConnectorMixin] Refreshing access token"), e = await this.nylasAuth.refreshAccessToken(), !e)) {
|
|
16
|
+
o("[NylasAuthConnectorMixin] Token is expired and could not be refreshed. Logging out."), this.logout();
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.nylasAuthStore.state.tokenInfo = e;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
this.nylasAuthStore.state.isAuthenticated = t;
|
|
23
|
+
}
|
|
24
|
+
async isAuthenticated() {
|
|
25
|
+
return this.nylasAuth.isAuthenticated();
|
|
26
|
+
}
|
|
27
|
+
async getTokenInfo() {
|
|
28
|
+
return this.nylasAuth.getTokenInfo();
|
|
29
|
+
}
|
|
30
|
+
async isAccessTokenValid() {
|
|
31
|
+
return this.nylasAuth.isAccessTokenValid();
|
|
32
|
+
}
|
|
33
|
+
async logout() {
|
|
34
|
+
await this.nylasAuth.logout();
|
|
35
|
+
}
|
|
36
|
+
async getHostedAuthRedirectURL(t, e, s) {
|
|
37
|
+
return this.nylasAuth.getHostedAuthRedirectURL(t, e, s);
|
|
38
|
+
}
|
|
39
|
+
async manageHostedAuthCodeExchange(t) {
|
|
40
|
+
const s = new URL(t).searchParams.get("code");
|
|
41
|
+
if (s) {
|
|
42
|
+
const a = await this.nylasAuth.exchangeAuthCodeForTokenInfo(s);
|
|
43
|
+
if (a)
|
|
44
|
+
return this.nylasAuthStore.state.tokenInfo = a, this.nylasAuthStore.state.isAuthenticated = !0, a;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class A {
|
|
50
|
+
constructor(t, e, s) {
|
|
51
|
+
this.nylasAuth = t, this.nylasAuthStore = e, this.nylasMailboxStore = s;
|
|
52
|
+
}
|
|
53
|
+
async getMessages() {
|
|
54
|
+
var n;
|
|
55
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
56
|
+
throw new Error("Not authenticated");
|
|
57
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
58
|
+
throw new Error("Missing message:read-only scope");
|
|
59
|
+
this.nylasMailboxStore.state.state = "loading";
|
|
60
|
+
const t = this.nylasMailboxStore.state.messgeQueryParams, e = new URLSearchParams();
|
|
61
|
+
for (const i in t) {
|
|
62
|
+
const l = (n = t[i]) == null ? void 0 : n.toString();
|
|
63
|
+
l && e.append(i, l);
|
|
64
|
+
}
|
|
65
|
+
const s = `/v3/grants/me/messages?${e.toString()}`, a = await this.nylasAuth.nylasAPIRequest(s);
|
|
66
|
+
if (u(a))
|
|
67
|
+
throw new d(a.error);
|
|
68
|
+
const r = a.data;
|
|
69
|
+
return this.nylasMailboxStore.state.messages = r, this.nylasMailboxStore.state.state = "ready", r;
|
|
70
|
+
}
|
|
71
|
+
async getThreadMessages(t) {
|
|
72
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
73
|
+
throw new Error("Not authenticated");
|
|
74
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
75
|
+
throw new Error("Missing message:read-only scope");
|
|
76
|
+
const e = await this.nylasAuth.nylasAPIRequest(`/v3/grants/me/messages?thread_id=${t}&fields=include_headers`);
|
|
77
|
+
if (u(e))
|
|
78
|
+
throw new d(e.error);
|
|
79
|
+
const s = e.data;
|
|
80
|
+
return this.nylasMailboxStore.state.messages = s, s;
|
|
81
|
+
}
|
|
82
|
+
downloadMessageAttachments(t) {
|
|
83
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
84
|
+
throw new Error("Not authenticated");
|
|
85
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
86
|
+
throw new Error("Missing message:read-only scope");
|
|
87
|
+
const e = [], s = t.attachments || [];
|
|
88
|
+
for (const a of s) {
|
|
89
|
+
const r = this.nylasAuth.nylasDownloadFileRequest(`/v3/grants/me/attachments/${a.id}?message_id=${t.id}`);
|
|
90
|
+
e.push(r);
|
|
91
|
+
}
|
|
92
|
+
return e;
|
|
93
|
+
}
|
|
94
|
+
async summarizeText(t) {
|
|
95
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
96
|
+
throw new Error("Not authenticated");
|
|
97
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
98
|
+
throw new Error("Missing message:read-only scope");
|
|
99
|
+
const e = await this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/summarize", "POST", {
|
|
100
|
+
message: {
|
|
101
|
+
body: t
|
|
102
|
+
}
|
|
103
|
+
}, !0, this.nylasAuth.config.elementsApiUri);
|
|
104
|
+
if (u(e))
|
|
105
|
+
throw new d(e.error);
|
|
106
|
+
return e.data.summary;
|
|
107
|
+
}
|
|
108
|
+
async textToSpeech(t, e) {
|
|
109
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
110
|
+
throw new Error("Not authenticated");
|
|
111
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
112
|
+
throw new Error("Missing message:read-only scope");
|
|
113
|
+
return this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/tts", "POST", {
|
|
114
|
+
text: t
|
|
115
|
+
}, !1, this.nylasAuth.config.elementsApiUri, {
|
|
116
|
+
...e ? { signal: e == null ? void 0 : e.signal } : {}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class T {
|
|
121
|
+
constructor(t, e, s, a) {
|
|
122
|
+
this.nylasAuth = t, this.nylasAuthStore = e, this.nylasMailboxStore = s, this.router = a;
|
|
123
|
+
}
|
|
124
|
+
async getThreads(t, e = "overwrite", s = !0) {
|
|
125
|
+
var y;
|
|
126
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
127
|
+
throw new Error("Not authenticated");
|
|
128
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
129
|
+
throw new Error("Missing thread:read-only scope");
|
|
130
|
+
s && (this.nylasMailboxStore.state.state = "loading");
|
|
131
|
+
const a = t || this.nylasMailboxStore.state.threadsQueryParams, r = new URLSearchParams();
|
|
132
|
+
for (const g in a) {
|
|
133
|
+
const c = (y = a[g]) == null ? void 0 : y.toString();
|
|
134
|
+
typeof c < "u" && c !== null && r.append(g, c);
|
|
135
|
+
}
|
|
136
|
+
a.search_query_native ? this.router.navigate(`/?query=${a.search_query_native}`, !0) : this.nylasMailboxStore.state.threadsQueryParams.search_query_native && !a.search_query_native && this.router.navigate("/", !0), a.page_token || (this.nylasMailboxStore.state.previousThreadPageTokens = []), this.nylasMailboxStore.state.threadsQueryParams = a;
|
|
137
|
+
const n = `/v3/grants/me/threads?${r.toString()}`, i = await this.nylasAuth.nylasAPIRequest(n);
|
|
138
|
+
if (u(i))
|
|
139
|
+
throw new d(i.error);
|
|
140
|
+
const l = i.data;
|
|
141
|
+
switch (e) {
|
|
142
|
+
case "prepend":
|
|
143
|
+
this.nylasMailboxStore.state.threads = [...l, ...this.nylasMailboxStore.state.threads];
|
|
144
|
+
break;
|
|
145
|
+
case "append":
|
|
146
|
+
this.nylasMailboxStore.state.threads = [...this.nylasMailboxStore.state.threads, ...l];
|
|
147
|
+
break;
|
|
148
|
+
case "overwrite":
|
|
149
|
+
default:
|
|
150
|
+
this.nylasMailboxStore.state.threads = l;
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
return i.next_cursor ? this.nylasMailboxStore.state.nextThreadPageToken = i.next_cursor : this.nylasMailboxStore.state.nextThreadPageToken = null, s && (this.nylasMailboxStore.state.state = "ready"), l;
|
|
154
|
+
}
|
|
155
|
+
async getThread(t) {
|
|
156
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
157
|
+
throw new Error("Not authenticated");
|
|
158
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
159
|
+
throw new Error("Missing thread:read-only scope");
|
|
160
|
+
const e = this.nylasMailboxStore.state.threads.find((n) => n.id === t);
|
|
161
|
+
if (e)
|
|
162
|
+
return e;
|
|
163
|
+
this.nylasMailboxStore.state.state = "loading";
|
|
164
|
+
const s = `/v3/grants/me/threads/${t}`, a = await this.nylasAuth.nylasAPIRequest(s);
|
|
165
|
+
if (u(a))
|
|
166
|
+
throw new d(a.error);
|
|
167
|
+
const r = a.data;
|
|
168
|
+
return this.nylasMailboxStore.state.threads = this.nylasMailboxStore.state.threads.map((n) => n.id === r.id ? r : n), this.nylasMailboxStore.state.state = "ready", r;
|
|
169
|
+
}
|
|
170
|
+
async nextThreadPage(t = "overwrite", e = !0) {
|
|
171
|
+
if (!this.nylasMailboxStore.state.nextThreadPageToken)
|
|
172
|
+
throw new Error("No next page token");
|
|
173
|
+
this.nylasMailboxStore.state.previousThreadPageTokens = Array.from(/* @__PURE__ */ new Set([...this.nylasMailboxStore.state.previousThreadPageTokens, this.nylasMailboxStore.state.threadsQueryParams.page_token ?? null]));
|
|
174
|
+
const s = this.nylasMailboxStore.state.nextThreadPageToken;
|
|
175
|
+
return this.getThreads({
|
|
176
|
+
...this.nylasMailboxStore.state.threadsQueryParams,
|
|
177
|
+
page_token: s
|
|
178
|
+
}, t, e);
|
|
179
|
+
}
|
|
180
|
+
async previousThreadPage(t = "overwrite", e = !0) {
|
|
181
|
+
if (!this.nylasMailboxStore.state.previousThreadPageTokens.length)
|
|
182
|
+
throw new Error("No previous page token");
|
|
183
|
+
const s = [...this.nylasMailboxStore.state.previousThreadPageTokens], a = s.pop();
|
|
184
|
+
return this.nylasMailboxStore.state.previousThreadPageTokens = s, this.getThreads({
|
|
185
|
+
...this.nylasMailboxStore.state.threadsQueryParams,
|
|
186
|
+
page_token: a ?? void 0
|
|
187
|
+
}, t, e);
|
|
188
|
+
}
|
|
189
|
+
updateThreadQueryParams(t) {
|
|
190
|
+
this.nylasMailboxStore.state.threadsQueryParams = {
|
|
191
|
+
...this.nylasMailboxStore.state.threadsQueryParams,
|
|
192
|
+
...t
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
back() {
|
|
196
|
+
this.router.navigate("/", !0), this.nylasMailboxStore.state.selectedThread = null;
|
|
197
|
+
}
|
|
198
|
+
unSelectThread() {
|
|
199
|
+
this.nylasMailboxStore.state.selectedThread = null;
|
|
200
|
+
}
|
|
201
|
+
async selectThread(t) {
|
|
202
|
+
this.router.navigate(`/thread/${t.id}`, !0), this.nylasMailboxStore.state.selectedThread = t, t.unread && this.markThreadAsRead(t).catch((e) => {
|
|
203
|
+
o("Error marking thread as read", e);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
async markThreadAsRead(t) {
|
|
207
|
+
return this.updateThread(t, { unread: !1 });
|
|
208
|
+
}
|
|
209
|
+
async updateThread(t, e) {
|
|
210
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
211
|
+
throw new Error("Not authenticated");
|
|
212
|
+
if (!this.nylasAuth.hasScopeByType("email", "modify"))
|
|
213
|
+
throw new Error("Missing thread:modify scope");
|
|
214
|
+
const s = `/v3/grants/me/threads/${t.id}`, a = await this.nylasAuth.nylasAPIRequest(s, "PUT", e);
|
|
215
|
+
if (u(a))
|
|
216
|
+
throw new d(a.error);
|
|
217
|
+
const r = a.data;
|
|
218
|
+
return this.nylasMailboxStore.state.threads = this.nylasMailboxStore.state.threads.map((n) => n.id === r.id ? r : n), this.nylasMailboxStore.state.selectedThread = r, r;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
class x {
|
|
222
|
+
constructor(t, e, s) {
|
|
223
|
+
this.nylasAuth = t, this.nylasAuthStore = e, this.nylasMailboxStore = s;
|
|
224
|
+
}
|
|
225
|
+
async getFolders() {
|
|
226
|
+
if (!this.nylasAuthStore.state.isAuthenticated)
|
|
227
|
+
throw new Error("Not authenticated");
|
|
228
|
+
if (!this.nylasAuth.hasScopeByType("email", ["read-only", "modify"]))
|
|
229
|
+
throw new Error("Missing thread:read-only scope");
|
|
230
|
+
this.nylasMailboxStore.state.state = "loading";
|
|
231
|
+
const t = "/v3/grants/me/folders", e = await this.nylasAuth.nylasAPIRequest(t);
|
|
232
|
+
if (u(e))
|
|
233
|
+
throw new d(e.error);
|
|
234
|
+
const s = e.data;
|
|
235
|
+
return this.nylasMailboxStore.state.folders = s, this.nylasMailboxStore.state.state = "ready", s;
|
|
236
|
+
}
|
|
237
|
+
async selectFolder(t) {
|
|
238
|
+
this.nylasMailboxStore.state.threadsQueryParams = {
|
|
239
|
+
in: t.id,
|
|
240
|
+
...this.nylasMailboxStore.state.threadsQueryParams || {}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
class m extends Event {
|
|
245
|
+
constructor(t, e) {
|
|
246
|
+
super(t, e), this.oldURL = e.oldURL, this.newURL = e.newURL;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
class P {
|
|
250
|
+
constructor() {
|
|
251
|
+
this.routeChangeListeners = [], o("HashRouter constructor");
|
|
252
|
+
}
|
|
253
|
+
destroy() {
|
|
254
|
+
o("HashRouter destroy"), window.removeEventListener("hashchange", this.onRouteChange.bind(this));
|
|
255
|
+
}
|
|
256
|
+
init() {
|
|
257
|
+
if (o("HashRouter init"), window.addEventListener("hashchange", this.onRouteChange.bind(this)), typeof HashChangeEvent < "u") {
|
|
258
|
+
const t = new HashChangeEvent("hashchange", { oldURL: "", newURL: window.location.href });
|
|
259
|
+
this.onRouteChange(t);
|
|
260
|
+
} else {
|
|
261
|
+
const t = new m("hashchange", { oldURL: "", newURL: window.location.href });
|
|
262
|
+
this.onRouteChange(t);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
addRouteChangeListener(t, e) {
|
|
266
|
+
o("HashRouter addRouteChangeListener"), this.routeChangeListeners.push([t, e]);
|
|
267
|
+
}
|
|
268
|
+
navigate(t, e) {
|
|
269
|
+
if (o("HashRouter navigate"), e)
|
|
270
|
+
return window.history.pushState(null, "", `#${t}`);
|
|
271
|
+
window.location.hash = t;
|
|
272
|
+
}
|
|
273
|
+
setRoute(t) {
|
|
274
|
+
o("HashRouter setRoute"), window.location.hash = t;
|
|
275
|
+
}
|
|
276
|
+
matchRoute(t, e) {
|
|
277
|
+
const s = t.split("/"), a = e.split("/");
|
|
278
|
+
if (o(`HashRouter matchRoute route=${t} path=${e}`, { routeParts: s, pathParts: a }), s[1] === "" && a[0] === "")
|
|
279
|
+
return !0;
|
|
280
|
+
if (s.length !== a.length)
|
|
281
|
+
return !1;
|
|
282
|
+
for (let r = 0; r < s.length; r++) {
|
|
283
|
+
const n = s[r], i = a[r];
|
|
284
|
+
if (!n.startsWith(":") && n !== i)
|
|
285
|
+
return !1;
|
|
286
|
+
}
|
|
287
|
+
return !0;
|
|
288
|
+
}
|
|
289
|
+
getRouteParams(t) {
|
|
290
|
+
o("HashRouter getRouteParams");
|
|
291
|
+
const e = {}, s = t.split("/"), a = window.location.hash.split("/");
|
|
292
|
+
return s.forEach((r, n) => {
|
|
293
|
+
if (r.startsWith(":")) {
|
|
294
|
+
const i = r.substring(1);
|
|
295
|
+
e[i] = a[n];
|
|
296
|
+
}
|
|
297
|
+
}), e;
|
|
298
|
+
}
|
|
299
|
+
getRouteWithParams(t, e) {
|
|
300
|
+
o("HashRouter getRouteWithParams");
|
|
301
|
+
let s = t;
|
|
302
|
+
return Object.keys(e).forEach((a) => {
|
|
303
|
+
s = s.replace(`:${a}`, e[a]);
|
|
304
|
+
}), s;
|
|
305
|
+
}
|
|
306
|
+
getRoute() {
|
|
307
|
+
return o("HashRouter getRoute"), window.location.hash;
|
|
308
|
+
}
|
|
309
|
+
onRouteChange(t) {
|
|
310
|
+
this.routeChangeListeners.forEach(async ([e, s]) => {
|
|
311
|
+
const a = t.newURL.indexOf("#") === -1 ? "" : t.newURL.substring(t.newURL.indexOf("#") + 1);
|
|
312
|
+
if (o(`HashRouter onRouteChange route=${e} path=${a}`, { event: t }), !this.matchRoute(e, a)) {
|
|
313
|
+
o(`HashRouter onRouteChange route=${e} path=${a} does not match`);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const r = this.getRouteParams(e);
|
|
317
|
+
await s(e, a, r);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
getBasePath() {
|
|
321
|
+
return o("HashRouter getBasePath"), "";
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function b(h = {}) {
|
|
325
|
+
const t = {
|
|
326
|
+
isAuthenticated: !1,
|
|
327
|
+
tokenInfo: null,
|
|
328
|
+
state: "ready",
|
|
329
|
+
...h
|
|
330
|
+
}, e = f(t);
|
|
331
|
+
return e.reset = () => {
|
|
332
|
+
for (const s in t) {
|
|
333
|
+
const a = t[s];
|
|
334
|
+
e.set(s, a);
|
|
335
|
+
}
|
|
336
|
+
}, e;
|
|
337
|
+
}
|
|
338
|
+
function M(h = {}) {
|
|
339
|
+
const t = {
|
|
340
|
+
state: "ready",
|
|
341
|
+
messages: [],
|
|
342
|
+
threads: [],
|
|
343
|
+
folders: [],
|
|
344
|
+
selectedThread: null,
|
|
345
|
+
nextThreadPageToken: null,
|
|
346
|
+
previousThreadPageTokens: [],
|
|
347
|
+
searchQuery: "",
|
|
348
|
+
hasNextThreadPage: !1,
|
|
349
|
+
hasPreviousThreadPage: !1,
|
|
350
|
+
selectedFolder: "inbox",
|
|
351
|
+
threadsQueryParams: {
|
|
352
|
+
in: "inbox"
|
|
353
|
+
},
|
|
354
|
+
messgeQueryParams: {
|
|
355
|
+
fields: "include_headers"
|
|
356
|
+
},
|
|
357
|
+
...h
|
|
358
|
+
}, e = f({ ...t });
|
|
359
|
+
return e.onChange("nextThreadPageToken", (s) => {
|
|
360
|
+
e.set("hasNextThreadPage", s !== null);
|
|
361
|
+
}), e.onChange("previousThreadPageTokens", (s) => {
|
|
362
|
+
e.set("hasPreviousThreadPage", s.length > 0);
|
|
363
|
+
}), e.onChange("threadsQueryParams", (s) => {
|
|
364
|
+
e.set("selectedFolder", s.in || "inbox"), e.set("searchQuery", s.search_query_native || "");
|
|
365
|
+
}), e.reset = () => {
|
|
366
|
+
for (const s in t) {
|
|
367
|
+
const a = t[s];
|
|
368
|
+
e.set(s, a);
|
|
369
|
+
}
|
|
370
|
+
}, e;
|
|
371
|
+
}
|
|
372
|
+
export {
|
|
373
|
+
b as C,
|
|
374
|
+
P as H,
|
|
375
|
+
S as N,
|
|
376
|
+
M as a,
|
|
377
|
+
T as b,
|
|
378
|
+
A as c,
|
|
379
|
+
x as d
|
|
380
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const o=require("./utils-5074a070-d5ba6add.cjs"),i=require("./index-2b85580a-bfc3ceac.cjs");class g{constructor(t,e){this.nylasAuth=t,this.nylasAuthStore=e}async validateSession(){const t=await this.isAccessTokenValid();if(!t)this.logout();else{let e=await this.nylasAuth.getTokenInfo();if(e){const a=Math.floor(Date.now()/1e3);if(e.expires_in&&e.expires_in-a<3e5&&(o.debug("[NylasAuthConnectorMixin] Refreshing access token"),e=await this.nylasAuth.refreshAccessToken(),!e)){o.debug("[NylasAuthConnectorMixin] Token is expired and could not be refreshed. Logging out."),this.logout();return}this.nylasAuthStore.state.tokenInfo=e}}this.nylasAuthStore.state.isAuthenticated=t}async isAuthenticated(){return this.nylasAuth.isAuthenticated()}async getTokenInfo(){return this.nylasAuth.getTokenInfo()}async isAccessTokenValid(){return this.nylasAuth.isAccessTokenValid()}async logout(){await this.nylasAuth.logout()}async getHostedAuthRedirectURL(t,e,s){return this.nylasAuth.getHostedAuthRedirectURL(t,e,s)}async manageHostedAuthCodeExchange(t){const s=new URL(t).searchParams.get("code");if(s){const a=await this.nylasAuth.exchangeAuthCodeForTokenInfo(s);if(a)return this.nylasAuthStore.state.tokenInfo=a,this.nylasAuthStore.state.isAuthenticated=!0,a}return null}}class f{constructor(t,e,s){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s}async getMessages(){var n;if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");this.nylasMailboxStore.state.state="loading";const t=this.nylasMailboxStore.state.messgeQueryParams,e=new URLSearchParams;for(const h in t){const u=(n=t[h])==null?void 0:n.toString();u&&e.append(h,u)}const s=`/v3/grants/me/messages?${e.toString()}`,a=await this.nylasAuth.nylasAPIRequest(s);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.messages=r,this.nylasMailboxStore.state.state="ready",r}async getThreadMessages(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=await this.nylasAuth.nylasAPIRequest(`/v3/grants/me/messages?thread_id=${t}&fields=include_headers`);if(i.Xr(e))throw new i.Zr(e.error);const s=e.data;return this.nylasMailboxStore.state.messages=s,s}downloadMessageAttachments(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=[],s=t.attachments||[];for(const a of s){const r=this.nylasAuth.nylasDownloadFileRequest(`/v3/grants/me/attachments/${a.id}?message_id=${t.id}`);e.push(r)}return e}async summarizeText(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");const e=await this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/summarize","POST",{message:{body:t}},!0,this.nylasAuth.config.elementsApiUri);if(i.Xr(e))throw new i.Zr(e.error);return e.data.summary}async textToSpeech(t,e){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing message:read-only scope");return this.nylasAuth.nylasAPIRequest("/v3/grants/me/mailbox/tts","POST",{text:t},!1,this.nylasAuth.config.elementsApiUri,{...e?{signal:e==null?void 0:e.signal}:{}})}}class w{constructor(t,e,s,a){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s,this.router=a}async getThreads(t,e="overwrite",s=!0){var c;if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");s&&(this.nylasMailboxStore.state.state="loading");const a=t||this.nylasMailboxStore.state.threadsQueryParams,r=new URLSearchParams;for(const y in a){const d=(c=a[y])==null?void 0:c.toString();typeof d<"u"&&d!==null&&r.append(y,d)}a.search_query_native?this.router.navigate(`/?query=${a.search_query_native}`,!0):this.nylasMailboxStore.state.threadsQueryParams.search_query_native&&!a.search_query_native&&this.router.navigate("/",!0),a.page_token||(this.nylasMailboxStore.state.previousThreadPageTokens=[]),this.nylasMailboxStore.state.threadsQueryParams=a;const n=`/v3/grants/me/threads?${r.toString()}`,h=await this.nylasAuth.nylasAPIRequest(n);if(i.Xr(h))throw new i.Zr(h.error);const u=h.data;switch(e){case"prepend":this.nylasMailboxStore.state.threads=[...u,...this.nylasMailboxStore.state.threads];break;case"append":this.nylasMailboxStore.state.threads=[...this.nylasMailboxStore.state.threads,...u];break;case"overwrite":default:this.nylasMailboxStore.state.threads=u;break}return h.next_cursor?this.nylasMailboxStore.state.nextThreadPageToken=h.next_cursor:this.nylasMailboxStore.state.nextThreadPageToken=null,s&&(this.nylasMailboxStore.state.state="ready"),u}async getThread(t){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");const e=this.nylasMailboxStore.state.threads.find(n=>n.id===t);if(e)return e;this.nylasMailboxStore.state.state="loading";const s=`/v3/grants/me/threads/${t}`,a=await this.nylasAuth.nylasAPIRequest(s);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.threads=this.nylasMailboxStore.state.threads.map(n=>n.id===r.id?r:n),this.nylasMailboxStore.state.state="ready",r}async nextThreadPage(t="overwrite",e=!0){if(!this.nylasMailboxStore.state.nextThreadPageToken)throw new Error("No next page token");this.nylasMailboxStore.state.previousThreadPageTokens=Array.from(new Set([...this.nylasMailboxStore.state.previousThreadPageTokens,this.nylasMailboxStore.state.threadsQueryParams.page_token??null]));const s=this.nylasMailboxStore.state.nextThreadPageToken;return this.getThreads({...this.nylasMailboxStore.state.threadsQueryParams,page_token:s},t,e)}async previousThreadPage(t="overwrite",e=!0){if(!this.nylasMailboxStore.state.previousThreadPageTokens.length)throw new Error("No previous page token");const s=[...this.nylasMailboxStore.state.previousThreadPageTokens],a=s.pop();return this.nylasMailboxStore.state.previousThreadPageTokens=s,this.getThreads({...this.nylasMailboxStore.state.threadsQueryParams,page_token:a??void 0},t,e)}updateThreadQueryParams(t){this.nylasMailboxStore.state.threadsQueryParams={...this.nylasMailboxStore.state.threadsQueryParams,...t}}back(){this.router.navigate("/",!0),this.nylasMailboxStore.state.selectedThread=null}unSelectThread(){this.nylasMailboxStore.state.selectedThread=null}async selectThread(t){this.router.navigate(`/thread/${t.id}`,!0),this.nylasMailboxStore.state.selectedThread=t,t.unread&&this.markThreadAsRead(t).catch(e=>{o.debug("Error marking thread as read",e)})}async markThreadAsRead(t){return this.updateThread(t,{unread:!1})}async updateThread(t,e){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email","modify"))throw new Error("Missing thread:modify scope");const s=`/v3/grants/me/threads/${t.id}`,a=await this.nylasAuth.nylasAPIRequest(s,"PUT",e);if(i.Xr(a))throw new i.Zr(a.error);const r=a.data;return this.nylasMailboxStore.state.threads=this.nylasMailboxStore.state.threads.map(n=>n.id===r.id?r:n),this.nylasMailboxStore.state.selectedThread=r,r}}class m{constructor(t,e,s){this.nylasAuth=t,this.nylasAuthStore=e,this.nylasMailboxStore=s}async getFolders(){if(!this.nylasAuthStore.state.isAuthenticated)throw new Error("Not authenticated");if(!this.nylasAuth.hasScopeByType("email",["read-only","modify"]))throw new Error("Missing thread:read-only scope");this.nylasMailboxStore.state.state="loading";const t="/v3/grants/me/folders",e=await this.nylasAuth.nylasAPIRequest(t);if(i.Xr(e))throw new i.Zr(e.error);const s=e.data;return this.nylasMailboxStore.state.folders=s,this.nylasMailboxStore.state.state="ready",s}async selectFolder(t){this.nylasMailboxStore.state.threadsQueryParams={in:t.id,...this.nylasMailboxStore.state.threadsQueryParams||{}}}}class p extends Event{constructor(t,e){super(t,e),this.oldURL=e.oldURL,this.newURL=e.newURL}}class S{constructor(){this.routeChangeListeners=[],o.debug("HashRouter constructor")}destroy(){o.debug("HashRouter destroy"),window.removeEventListener("hashchange",this.onRouteChange.bind(this))}init(){if(o.debug("HashRouter init"),window.addEventListener("hashchange",this.onRouteChange.bind(this)),typeof HashChangeEvent<"u"){const t=new HashChangeEvent("hashchange",{oldURL:"",newURL:window.location.href});this.onRouteChange(t)}else{const t=new p("hashchange",{oldURL:"",newURL:window.location.href});this.onRouteChange(t)}}addRouteChangeListener(t,e){o.debug("HashRouter addRouteChangeListener"),this.routeChangeListeners.push([t,e])}navigate(t,e){if(o.debug("HashRouter navigate"),e)return window.history.pushState(null,"",`#${t}`);window.location.hash=t}setRoute(t){o.debug("HashRouter setRoute"),window.location.hash=t}matchRoute(t,e){const s=t.split("/"),a=e.split("/");if(o.debug(`HashRouter matchRoute route=${t} path=${e}`,{routeParts:s,pathParts:a}),s[1]===""&&a[0]==="")return!0;if(s.length!==a.length)return!1;for(let r=0;r<s.length;r++){const n=s[r],h=a[r];if(!n.startsWith(":")&&n!==h)return!1}return!0}getRouteParams(t){o.debug("HashRouter getRouteParams");const e={},s=t.split("/"),a=window.location.hash.split("/");return s.forEach((r,n)=>{if(r.startsWith(":")){const h=r.substring(1);e[h]=a[n]}}),e}getRouteWithParams(t,e){o.debug("HashRouter getRouteWithParams");let s=t;return Object.keys(e).forEach(a=>{s=s.replace(`:${a}`,e[a])}),s}getRoute(){return o.debug("HashRouter getRoute"),window.location.hash}onRouteChange(t){this.routeChangeListeners.forEach(async([e,s])=>{const a=t.newURL.indexOf("#")===-1?"":t.newURL.substring(t.newURL.indexOf("#")+1);if(o.debug(`HashRouter onRouteChange route=${e} path=${a}`,{event:t}),!this.matchRoute(e,a)){o.debug(`HashRouter onRouteChange route=${e} path=${a} does not match`);return}const r=this.getRouteParams(e);await s(e,a,r)})}getBasePath(){return o.debug("HashRouter getBasePath"),""}}function A(l={}){const t={isAuthenticated:!1,tokenInfo:null,state:"ready",...l},e=i.createStore(t);return e.reset=()=>{for(const s in t){const a=t[s];e.set(s,a)}},e}function T(l={}){const t={state:"ready",messages:[],threads:[],folders:[],selectedThread:null,nextThreadPageToken:null,previousThreadPageTokens:[],searchQuery:"",hasNextThreadPage:!1,hasPreviousThreadPage:!1,selectedFolder:"inbox",threadsQueryParams:{in:"inbox"},messgeQueryParams:{fields:"include_headers"},...l},e=i.createStore({...t});return e.onChange("nextThreadPageToken",s=>{e.set("hasNextThreadPage",s!==null)}),e.onChange("previousThreadPageTokens",s=>{e.set("hasPreviousThreadPage",s.length>0)}),e.onChange("threadsQueryParams",s=>{e.set("selectedFolder",s.in||"inbox"),e.set("searchQuery",s.search_query_native||"")}),e.reset=()=>{for(const s in t){const a=t[s];e.set(s,a)}},e}exports.CreateNylasAuthStore=A;exports.CreateNylasMailboxStore=T;exports.HashRouter=S;exports.NylasAuthConnector=g;exports.NylasFoldersConnector=m;exports.NylasMessagesConnector=f;exports.NylasThreadsConnector=w;
|