@nylas/react 1.1.0-canary.10 → 1.1.0-canary.12

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.
Files changed (109) hide show
  1. package/dist/add-circle-icon_21.entry-172d31c3.js +6726 -0
  2. package/dist/add-circle-icon_21.entry-71af48f1.cjs +41 -0
  3. package/dist/{archive-icon_7.entry-a69d3d98.cjs → archive-icon_7.entry-59d9e24f.cjs} +1 -1
  4. package/dist/{archive-icon_7.entry-70efea56.js → archive-icon_7.entry-e892a458.js} +1 -1
  5. package/dist/{arrow-icon.entry-c9230436.js → arrow-icon.entry-060b9b4f.js} +1 -1
  6. package/dist/{arrow-icon.entry-0a07d7cc.cjs → arrow-icon.entry-834b8066.cjs} +1 -1
  7. package/dist/{bold-icon_3.entry-54ff7799.js → bold-icon_3.entry-0f038db3.js} +1 -1
  8. package/dist/{bold-icon_3.entry-f7df4331.cjs → bold-icon_3.entry-eb0fcdaa.cjs} +1 -1
  9. package/dist/{calendar-cancel-icon.entry-71cc68e2.cjs → calendar-cancel-icon.entry-27a6f628.cjs} +1 -1
  10. package/dist/{calendar-cancel-icon.entry-e5157332.js → calendar-cancel-icon.entry-96156441.js} +1 -1
  11. package/dist/{calendar-check-icon_2.entry-f02bf0fe.cjs → calendar-check-icon_2.entry-b6d6d220.cjs} +1 -1
  12. package/dist/{calendar-check-icon_2.entry-f75ef95e.js → calendar-check-icon_2.entry-c7c13e3e.js} +1 -1
  13. package/dist/{calendar-icon.entry-a164e957.cjs → calendar-icon.entry-e7f6a9a8.cjs} +1 -1
  14. package/dist/{calendar-icon.entry-67aa69f5.js → calendar-icon.entry-f088fb14.js} +1 -1
  15. package/dist/{chevron-icon_3.entry-7687ca7a.cjs → chevron-icon_3.entry-8c6e6f74.cjs} +1 -1
  16. package/dist/{chevron-icon_3.entry-81c68946.js → chevron-icon_3.entry-90a3e89c.js} +1 -1
  17. package/dist/{close-icon.entry-147b4d47.cjs → close-icon.entry-175b9674.cjs} +1 -1
  18. package/dist/{close-icon.entry-3325a08e.js → close-icon.entry-e694948f.js} +1 -1
  19. package/dist/{constants-f34b9c6e-99030371.cjs → constants-f34b9c6e-593e21cc.cjs} +1 -1
  20. package/dist/{constants-f34b9c6e-21ac1910.js → constants-f34b9c6e-91f6ad05.js} +1 -1
  21. package/dist/{document-refresh-icon.entry-dea23e07.cjs → document-refresh-icon.entry-a54c74b9.cjs} +1 -1
  22. package/dist/{document-refresh-icon.entry-1b076630.js → document-refresh-icon.entry-ca98d879.js} +1 -1
  23. package/dist/{elements-dc5b338e-83c23e9b.cjs → elements-dc5b338e-60f95088.cjs} +1 -1
  24. package/dist/{elements-dc5b338e-c69d1f8a.js → elements-dc5b338e-68eab1e5.js} +1 -1
  25. package/dist/{focus-visible-e8093c16-3082af2c.cjs → focus-visible-e8093c16-a0869441.cjs} +1 -1
  26. package/dist/{focus-visible-e8093c16-a6aff071.js → focus-visible-e8093c16-b5d785fc.js} +1 -1
  27. package/dist/{forward-icon_6.entry-59c7a975.cjs → forward-icon_6.entry-4b321b9a.cjs} +1 -1
  28. package/dist/{forward-icon_6.entry-55fce1ca.js → forward-icon_6.entry-84ac76ac.js} +2 -2
  29. package/dist/global-37eeb0cd-6c5934cf.cjs +1 -0
  30. package/dist/global-37eeb0cd-b42e0abc.js +4 -0
  31. package/dist/{globe-icon.entry-25145785.js → globe-icon.entry-14a60f32.js} +1 -1
  32. package/dist/{globe-icon.entry-904f180f.cjs → globe-icon.entry-ef04c8bf.cjs} +1 -1
  33. package/dist/{google-logo-icon_4.entry-1f7b9522.js → google-logo-icon_4.entry-4fa3cb8e.js} +38 -42
  34. package/dist/{google-logo-icon_4.entry-feb7a561.cjs → google-logo-icon_4.entry-ffeec491.cjs} +1 -1
  35. package/dist/{index-5f0940e0.cjs → index-3a004ec1.cjs} +2 -2
  36. package/dist/{index-fd39ea9d.js → index-4c7e8f2f.js} +161 -158
  37. package/dist/index-92989ac4-69175657.js +902 -0
  38. package/dist/index-92989ac4-6f32ff2a.cjs +6 -0
  39. package/dist/{index.es-be19d2df-9ba9a7a6.cjs → index.es-9190f785-60475c4c.cjs} +6 -6
  40. package/dist/{index.es-be19d2df-ff4f0a10.js → index.es-9190f785-69269065.js} +12 -13
  41. package/dist/{info-icon_2.entry-0e2105da.js → info-icon_2.entry-45f6f01f.js} +1 -1
  42. package/dist/{info-icon_2.entry-808e6516.cjs → info-icon_2.entry-fb099090.cjs} +1 -1
  43. package/dist/{loading-icon.entry-a3b845bf.js → loading-icon.entry-67c8b1fa.js} +1 -1
  44. package/dist/{loading-icon.entry-17efa7ca.cjs → loading-icon.entry-eaabff41.cjs} +1 -1
  45. package/dist/{mailbox-store-76540d24-ad0e366a.cjs → mailbox-store-29139d89-dd9d3d1b.cjs} +1 -1
  46. package/dist/{mailbox-store-76540d24-5f0d1dff.js → mailbox-store-29139d89-e3513416.js} +2 -2
  47. package/dist/{nylas-additional-participants.entry-7e2446cb.cjs → nylas-additional-participants.entry-6413fc87.cjs} +1 -1
  48. package/dist/{nylas-additional-participants.entry-4120ea2e.js → nylas-additional-participants.entry-a1fb4ef4.js} +2 -2
  49. package/dist/{nylas-booked-event-card_10.entry-44812e35.cjs → nylas-booked-event-card_10.entry-ce660783.cjs} +1 -1
  50. package/dist/{nylas-booked-event-card_10.entry-5e87b199.js → nylas-booked-event-card_10.entry-e435ff63.js} +12 -12
  51. package/dist/{nylas-custom-booking-flow.entry-da5e66bb.cjs → nylas-custom-booking-flow.entry-3e690bb7.cjs} +1 -1
  52. package/dist/{nylas-custom-booking-flow.entry-cbff44c8.js → nylas-custom-booking-flow.entry-56075ecd.js} +2 -2
  53. package/dist/{nylas-form-card.entry-1c608edd.js → nylas-form-card.entry-33ff95e1.js} +2 -2
  54. package/dist/{nylas-form-card.entry-2e629e36.cjs → nylas-form-card.entry-64d7be4d.cjs} +1 -1
  55. package/dist/{nylas-if-state.entry-61771f3d.cjs → nylas-if-state.entry-1e4b0a58.cjs} +1 -1
  56. package/dist/{nylas-if-state.entry-2c0d8724.js → nylas-if-state.entry-3d22bca7.js} +3 -3
  57. package/dist/{nylas-list-folders.entry-fa8e8ce9.cjs → nylas-list-folders.entry-3da37b1c.cjs} +1 -1
  58. package/dist/{nylas-list-folders.entry-d6e085b0.js → nylas-list-folders.entry-e634780d.js} +2 -2
  59. package/dist/{nylas-list-threads.entry-4dd2de0a.js → nylas-list-threads.entry-26dbb8ff.js} +2 -2
  60. package/dist/{nylas-list-threads.entry-99fc0baa.cjs → nylas-list-threads.entry-ef4743af.cjs} +1 -1
  61. package/dist/{nylas-login.entry-0ec0813c.cjs → nylas-login.entry-a76e4aae.cjs} +1 -1
  62. package/dist/{nylas-login.entry-6730e226.js → nylas-login.entry-ff7d9db5.js} +2 -2
  63. package/dist/{nylas-mailbox-pagination.entry-e3e52f42.cjs → nylas-mailbox-pagination.entry-565ee29b.cjs} +1 -1
  64. package/dist/{nylas-mailbox-pagination.entry-5310880c.js → nylas-mailbox-pagination.entry-fcb3cc47.js} +2 -2
  65. package/dist/{nylas-mailbox-toolbar-button.entry-4c377337.cjs → nylas-mailbox-toolbar-button.entry-3a94b1e9.cjs} +1 -1
  66. package/dist/{nylas-mailbox-toolbar-button.entry-028075db.js → nylas-mailbox-toolbar-button.entry-ae13c538.js} +2 -2
  67. package/dist/{nylas-mailbox.entry-ab92780c.js → nylas-mailbox.entry-6d86abe9.js} +7 -6
  68. package/dist/nylas-mailbox.entry-8f41c35a.cjs +1 -0
  69. package/dist/{nylas-provider.entry-678a9fe7.js → nylas-provider.entry-01e0944e.js} +6 -5
  70. package/dist/nylas-provider.entry-65f0f8da.cjs +1 -0
  71. package/dist/nylas-scheduler-editor.entry-7dc20e4d.cjs +2 -0
  72. package/dist/nylas-scheduler-editor.entry-8f62880a.js +1391 -0
  73. package/dist/nylas-scheduling.entry-1b6628a3.cjs +1 -0
  74. package/dist/{nylas-scheduling.entry-e38c3870.js → nylas-scheduling.entry-f15b3106.js} +40 -38
  75. package/dist/{nylas-threads-refresh.entry-79c8a061.cjs → nylas-threads-refresh.entry-d62d0574.cjs} +1 -1
  76. package/dist/{nylas-threads-refresh.entry-fcb2175f.js → nylas-threads-refresh.entry-d7727ccb.js} +2 -2
  77. package/dist/{nylas-threads-search.entry-7565bdf8.js → nylas-threads-search.entry-4803d20b.js} +2 -2
  78. package/dist/{nylas-threads-search.entry-f2d5d0fb.cjs → nylas-threads-search.entry-eec50b1b.cjs} +1 -1
  79. package/dist/{nylas-view-thread.entry-1772e0c4.js → nylas-view-thread.entry-2b85f8e2.js} +2 -2
  80. package/dist/{nylas-view-thread.entry-6a2ccece.cjs → nylas-view-thread.entry-5da789da.cjs} +1 -1
  81. package/dist/{people-icon.entry-bc2c70cf.js → people-icon.entry-63f63064.js} +1 -1
  82. package/dist/{people-icon.entry-3218a267.cjs → people-icon.entry-b6426fe6.cjs} +1 -1
  83. package/dist/{play-icon_2.entry-450a7fa6.cjs → play-icon_2.entry-2b8094d7.cjs} +1 -1
  84. package/dist/{play-icon_2.entry-b4dc4e6d.js → play-icon_2.entry-a3262db3.js} +1 -1
  85. package/dist/react.cjs +1 -1
  86. package/dist/react.js +1 -1
  87. package/dist/{refresh-icon.entry-030dda82.cjs → refresh-icon.entry-542f680c.cjs} +1 -1
  88. package/dist/{refresh-icon.entry-d30c7264.js → refresh-icon.entry-64679ef7.js} +1 -1
  89. package/dist/{register-component-83e24412-35c484c4.js → register-component-83e24412-51af5293.js} +1 -1
  90. package/dist/{register-component-83e24412-0b25de7f.cjs → register-component-83e24412-d76a2962.cjs} +1 -1
  91. package/dist/{scheduler-config-store-ec3b6190-6d8cef0f.cjs → scheduler-config-store-ec3b6190-2710b76a.cjs} +1 -1
  92. package/dist/{scheduler-config-store-ec3b6190-d5edbae5.js → scheduler-config-store-ec3b6190-df09ddc0.js} +1 -1
  93. package/dist/scheduler-store-dabdbc4f-404dc261.cjs +1 -0
  94. package/dist/{scheduler-store-8ca9003d-38cca5ba.js → scheduler-store-dabdbc4f-6f6096d6.js} +41 -28
  95. package/dist/{time-period-selector.entry-b366ba86.js → time-period-selector.entry-8e6954f5.js} +1 -1
  96. package/dist/{time-period-selector.entry-b3d04e93.cjs → time-period-selector.entry-c5faae46.cjs} +1 -1
  97. package/dist/{translate-icon.entry-03ab2513.cjs → translate-icon.entry-49a653f0.cjs} +1 -1
  98. package/dist/{translate-icon.entry-b3c21ae9.js → translate-icon.entry-57dedacf.js} +1 -1
  99. package/dist/{warning-icon.entry-602d459b.js → warning-icon.entry-a7977526.js} +1 -1
  100. package/dist/{warning-icon.entry-65ecfdf0.cjs → warning-icon.entry-bce861bd.cjs} +1 -1
  101. package/package.json +2 -2
  102. package/dist/add-circle-icon_21.entry-125b87a0.js +0 -1719
  103. package/dist/add-circle-icon_21.entry-1a699a29.cjs +0 -1
  104. package/dist/nylas-mailbox.entry-87304850.cjs +0 -1
  105. package/dist/nylas-provider.entry-3fb60fe4.cjs +0 -1
  106. package/dist/nylas-scheduler-editor.entry-a0de0ae6.js +0 -2269
  107. package/dist/nylas-scheduler-editor.entry-cf19391e.cjs +0 -7
  108. package/dist/nylas-scheduling.entry-d8bb2648.cjs +0 -1
  109. package/dist/scheduler-store-8ca9003d-c2aa3522.cjs +0 -1
@@ -0,0 +1,1391 @@
1
+ var P = Object.defineProperty;
2
+ var O = (r, t, n) => t in r ? P(r, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[t] = n;
3
+ var m = (r, t, n) => (O(r, typeof t != "symbol" ? t + "" : t, n), n);
4
+ import { i as commonjsGlobal, r as registerInstance, c as createEvent, d as debug, N as NylasIdentityRequestWrapper, h, H as Host, g as getElement, j as dataResponse } from "./index-4c7e8f2f.js";
5
+ import { N as NylasBaseProvider, X as Xr } from "./index.es-9190f785-69269065.js";
6
+ import { C as CreateNylasSchedulerConfigStore } from "./scheduler-config-store-ec3b6190-df09ddc0.js";
7
+ import { p as process, B as Buffer } from "./index-92989ac4-69175657.js";
8
+ import "react";
9
+ import "react-dom";
10
+ import "./global-37eeb0cd-b42e0abc.js";
11
+ class NylasSchedulerConfigAPIConnector {
12
+ constructor({ nylasApiRequest: t, nylasSchedulerConfigStore: n }) {
13
+ this.nylasApiRequest = t, this.nylasSchedulerConfigStore = n;
14
+ }
15
+ async currentUser() {
16
+ return this.nylasApiRequest ? this.nylasApiRequest.currentUser() : (console.warn("Nylas API Request is not initialized"), null);
17
+ }
18
+ async getCalendars() {
19
+ var s;
20
+ if (!this.nylasApiRequest)
21
+ return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
22
+ message: "Error fetching calendars: Nylas API Request is not initialized"
23
+ });
24
+ const [t, n] = await this.nylasApiRequest.request({
25
+ method: "GET",
26
+ path: "calendars"
27
+ });
28
+ return n ? dataResponse(null, {
29
+ message: "Error fetching calendars: " + n.message
30
+ }) : Xr(t) ? dataResponse(null, {
31
+ message: "Error fetching calendars: " + ((s = t.error) == null ? void 0 : s.message)
32
+ }) : (this.nylasSchedulerConfigStore.state.calendars = t.data, dataResponse(t.data));
33
+ }
34
+ async getConfigurationById(t, n = !1) {
35
+ var a;
36
+ if (!this.nylasApiRequest)
37
+ return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
38
+ message: "Error fetching configuration: Nylas API Request is not initialized"
39
+ });
40
+ if (!n) {
41
+ const d = this.nylasSchedulerConfigStore.state.configurations.find((l) => l.id === t);
42
+ if (d)
43
+ return this.nylasSchedulerConfigStore.state.selectedConfiguration = d, dataResponse(d);
44
+ }
45
+ const [s, c] = await this.nylasApiRequest.request({
46
+ method: "GET",
47
+ path: `scheduling/configurations/${t}`
48
+ });
49
+ return c ? dataResponse(null, {
50
+ message: "Error fetching configuration: " + c.message
51
+ }) : Xr(s) ? dataResponse(null, {
52
+ message: "Error fetching configuration: " + ((a = s.error) == null ? void 0 : a.message)
53
+ }) : (this.nylasSchedulerConfigStore.state.selectedConfiguration = s.data, this.nylasSchedulerConfigStore.state.configurations.find((d) => d.id === t) ? this.nylasSchedulerConfigStore.state.configurations = this.nylasSchedulerConfigStore.state.configurations.map((d) => d.id === t ? s.data : d) : this.nylasSchedulerConfigStore.state.configurations = [...this.nylasSchedulerConfigStore.state.configurations, s.data], dataResponse(s.data));
54
+ }
55
+ async getConfigurations() {
56
+ var s;
57
+ if (!this.nylasApiRequest)
58
+ return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
59
+ message: "Error fetching configurations: Nylas API Request is not initialized"
60
+ });
61
+ const [t, n] = await this.nylasApiRequest.request({
62
+ method: "GET",
63
+ path: "scheduling/configurations"
64
+ });
65
+ return n ? dataResponse(null, {
66
+ message: "Error fetching configurations: " + n.message
67
+ }) : Xr(t) ? dataResponse(null, {
68
+ message: "Error fetching configurations: " + ((s = t.error) == null ? void 0 : s.message)
69
+ }) : (this.nylasSchedulerConfigStore.state.configurations = t.data, dataResponse(t.data));
70
+ }
71
+ async createConfiguration(t) {
72
+ var c;
73
+ if (!this.nylasApiRequest)
74
+ return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
75
+ message: "Error creating configuration: Nylas API Request is not initialized"
76
+ });
77
+ const [n, s] = await this.nylasApiRequest.request({
78
+ method: "POST",
79
+ path: "scheduling/configurations",
80
+ body: t
81
+ });
82
+ return s ? dataResponse(null, {
83
+ message: "Error creating configuration: " + s.message
84
+ }) : Xr(n) ? dataResponse(null, {
85
+ message: "Error creating configuration: " + ((c = n.error) == null ? void 0 : c.message)
86
+ }) : (this.nylasSchedulerConfigStore.state.selectedConfiguration = n.data, this.nylasSchedulerConfigStore.state.configurations = [...this.nylasSchedulerConfigStore.state.configurations, n.data], dataResponse(n.data));
87
+ }
88
+ async updateConfiguration(t) {
89
+ var c;
90
+ if (!this.nylasApiRequest)
91
+ return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
92
+ message: "Error updating configuration: Nylas API Request is not initialized"
93
+ });
94
+ const [n, s] = await this.nylasApiRequest.request({
95
+ method: "PUT",
96
+ path: `scheduling/configurations/${t.id}`,
97
+ body: t
98
+ });
99
+ return s ? dataResponse(null, {
100
+ message: "Error updating configuration: " + s.message
101
+ }) : Xr(n) ? dataResponse(null, {
102
+ message: "Error updating configuration: " + ((c = n.error) == null ? void 0 : c.message)
103
+ }) : (this.nylasSchedulerConfigStore.state.selectedConfiguration = n.data, this.nylasSchedulerConfigStore.state.configurations.find((a) => a.id === t.id) ? this.nylasSchedulerConfigStore.state.configurations = this.nylasSchedulerConfigStore.state.configurations.map((a) => a.id === t.id ? n.data : a) : this.nylasSchedulerConfigStore.state.configurations = [...this.nylasSchedulerConfigStore.state.configurations, n.data], dataResponse(n.data));
104
+ }
105
+ async deleteConfiguration(t) {
106
+ var c, a;
107
+ if (!this.nylasApiRequest)
108
+ return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
109
+ message: "Error deleting configuration: Nylas API Request is not initialized"
110
+ });
111
+ const [n, s] = await this.nylasApiRequest.request({
112
+ method: "DELETE",
113
+ path: `scheduling/configurations/${t}`
114
+ });
115
+ return s ? dataResponse(null, {
116
+ message: "Error deleting configuration: " + s.message
117
+ }) : Xr(n) ? dataResponse(null, {
118
+ message: "Error deleting configuration: " + ((c = n.error) == null ? void 0 : c.message)
119
+ }) : (this.nylasSchedulerConfigStore.state.configurations = this.nylasSchedulerConfigStore.state.configurations.filter((d) => d.id !== t), ((a = this.nylasSchedulerConfigStore.state.selectedConfiguration) == null ? void 0 : a.id) === t && this.nylasSchedulerConfigStore.resetSelectedConfiguration(), dataResponse(n.data));
120
+ }
121
+ }
122
+ class NylasSchedulerConfigConnector {
123
+ constructor({ nylasApiRequest: t, nylasSchedulerConfigStore: n }) {
124
+ this.nylasApiRequest = t, this.nylasSchedulerConfigStore = n;
125
+ }
126
+ init() {
127
+ debug("NylasSchedulerConfigConnector init");
128
+ }
129
+ get schedulerConfigStore() {
130
+ return this.nylasSchedulerConfigStore;
131
+ }
132
+ get schedulerConfig() {
133
+ return this._schedulerConfigConnector ? this._schedulerConfigConnector : (this._schedulerConfigConnector = new NylasSchedulerConfigAPIConnector({
134
+ nylasApiRequest: this.nylasApiRequest,
135
+ nylasSchedulerConfigStore: this.nylasSchedulerConfigStore
136
+ }), this._schedulerConfigConnector);
137
+ }
138
+ resetStores() {
139
+ debug("NylasSchedulerConfigConnector resetStores"), this.nylasSchedulerConfigStore.reset();
140
+ }
141
+ async logout() {
142
+ debug("NylasSchedulerConfigConnector logout"), this.resetStores();
143
+ }
144
+ }
145
+ class LocalStorage {
146
+ get(t) {
147
+ return new Promise((n) => {
148
+ const s = window.localStorage.getItem(t);
149
+ n(s ? JSON.parse(s) : null);
150
+ });
151
+ }
152
+ async remove(t) {
153
+ return window.localStorage.removeItem(t), new Promise((n) => {
154
+ n(null);
155
+ });
156
+ }
157
+ set(t, n) {
158
+ return window.localStorage.setItem(t, JSON.stringify(n)), new Promise((s) => {
159
+ s(null);
160
+ });
161
+ }
162
+ }
163
+ const PKCE_KEY = "pkce", GRANT_KEY = "grant", USER_KEY = "user";
164
+ class Storage {
165
+ constructor(t) {
166
+ m(this, "Storage", new LocalStorage());
167
+ if (t) {
168
+ this.Storage = t;
169
+ return;
170
+ }
171
+ }
172
+ setPKCE(t) {
173
+ const n = Buffer.from(t);
174
+ this.Storage.set(PKCE_KEY, n.toString("base64"));
175
+ }
176
+ async getPKCE() {
177
+ try {
178
+ const t = await this.Storage.get(PKCE_KEY);
179
+ if (t)
180
+ return Buffer.from(t, "base64").toString("utf8");
181
+ } catch {
182
+ return null;
183
+ }
184
+ return null;
185
+ }
186
+ removePKCE() {
187
+ this.Storage.remove(PKCE_KEY);
188
+ }
189
+ setGrant(t, n = !1) {
190
+ const { grant_id: s } = t;
191
+ this.Storage.set(`${GRANT_KEY}${n ? "-" + s : ""}`, t);
192
+ }
193
+ removeGrant(t, n = !1) {
194
+ this.Storage.remove(`${GRANT_KEY}${n ? "-" + t : ""}`);
195
+ }
196
+ async getGrant(t, n = !1) {
197
+ const s = await this.Storage.get(`${GRANT_KEY}${n ? "-" + t : ""}`);
198
+ return s || null;
199
+ }
200
+ // setUserToken is used to store the IDToken in storage
201
+ async setUserToken(t) {
202
+ const n = await this.getUserTokens();
203
+ if (n)
204
+ if (n.find((c) => c.sub === t.sub)) {
205
+ const c = n.map((a) => (a.sub === t.sub && (a = t), a));
206
+ this.Storage.set(USER_KEY, c);
207
+ } else {
208
+ const c = [...n, t];
209
+ this.Storage.set(USER_KEY, c);
210
+ }
211
+ else
212
+ this.Storage.set(USER_KEY, [t]);
213
+ }
214
+ // getUserToken is used to retrieve a specific IDToken from storage
215
+ async getUserToken(t = "") {
216
+ const n = await this.Storage.get(USER_KEY);
217
+ return n ? t === "" ? n[0] : n.find((c) => c.sub === t) : null;
218
+ }
219
+ // getUserTokens is used to retrieve all IDTokens from storage
220
+ async getUserTokens() {
221
+ const t = await this.Storage.get(USER_KEY);
222
+ return t || null;
223
+ }
224
+ // removeUserTokens is used to remove all IDTokens from storage
225
+ removeUserTokens() {
226
+ this.Storage.remove(USER_KEY);
227
+ }
228
+ // removeUserToken is used to remove a specific IDToken from storage
229
+ async removeUserToken(t) {
230
+ const n = await this.getUserTokens(), s = n == null ? void 0 : n.filter((c) => c.sub !== t);
231
+ this.Storage.set(USER_KEY, s);
232
+ }
233
+ async clearSession() {
234
+ const t = await this.getUserTokens();
235
+ t == null || t.forEach((n) => {
236
+ this.removeGrant(n.sub);
237
+ }), this.removePKCE(), this.removeUserTokens();
238
+ }
239
+ }
240
+ class IndexedDBStorage {
241
+ constructor() {
242
+ m(this, "databaseName", "identity-db");
243
+ m(this, "storeName", "identity");
244
+ }
245
+ get(t) {
246
+ const n = this;
247
+ return new Promise((s, c) => {
248
+ n.openDatabase().then(function(a) {
249
+ const d = a.transaction(n.storeName, "readwrite"), u = d.objectStore(n.storeName).get(t);
250
+ u.onsuccess = () => {
251
+ s(u.result);
252
+ }, u.onerror = () => {
253
+ c(u.error);
254
+ }, d.oncomplete = () => {
255
+ a.close();
256
+ };
257
+ });
258
+ });
259
+ }
260
+ async remove(t) {
261
+ const n = this;
262
+ return new Promise((s, c) => {
263
+ const a = indexedDB.open(this.databaseName);
264
+ a.onupgradeneeded = function(d) {
265
+ d.target.result.createObjectStore(n.storeName);
266
+ }, a.onerror = () => {
267
+ c(a.error);
268
+ }, a.onsuccess = (d) => {
269
+ const l = d.target.result, u = l.transaction(this.storeName, "readwrite"), g = u.objectStore(this.storeName).delete(t);
270
+ g.onsuccess = () => {
271
+ s(null);
272
+ }, g.onerror = () => {
273
+ c(g.error);
274
+ }, u.oncomplete = () => {
275
+ l.close();
276
+ };
277
+ };
278
+ });
279
+ }
280
+ set(t, n) {
281
+ return new Promise((s, c) => {
282
+ const a = indexedDB.open(this.databaseName);
283
+ a.onerror = () => {
284
+ c(a.error);
285
+ }, a.onupgradeneeded = (d) => {
286
+ d.target.result.createObjectStore(this.storeName);
287
+ }, a.onsuccess = (d) => {
288
+ const l = d.target.result, u = l.transaction(this.storeName, "readwrite"), g = u.objectStore(this.storeName).put(n, t);
289
+ g.onsuccess = () => {
290
+ s(n);
291
+ }, g.onerror = () => {
292
+ c(g.error);
293
+ }, u.oncomplete = () => {
294
+ l.close();
295
+ };
296
+ };
297
+ });
298
+ }
299
+ openDatabase() {
300
+ const t = this;
301
+ return new Promise(function(n, s) {
302
+ const c = indexedDB.open(t.databaseName, 2);
303
+ c.onupgradeneeded = function(a) {
304
+ a.target.result.createObjectStore(t.storeName);
305
+ }, c.onsuccess = function(a) {
306
+ n(a.target.result);
307
+ }, c.onerror = function(a) {
308
+ s(a.error);
309
+ };
310
+ });
311
+ }
312
+ }
313
+ var sha256 = { exports: {} };
314
+ (function(module) {
315
+ (function() {
316
+ var ERROR = "input is invalid type", WINDOW = typeof window == "object", root = WINDOW ? window : {};
317
+ root.JS_SHA256_NO_WINDOW && (WINDOW = !1);
318
+ var WEB_WORKER = !WINDOW && typeof self == "object", NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process == "object" && process.versions && process.versions.node;
319
+ NODE_JS ? root = commonjsGlobal : WEB_WORKER && (root = self);
320
+ var COMMON_JS = !root.JS_SHA256_NO_COMMON_JS && !0 && module.exports, ARRAY_BUFFER = !root.JS_SHA256_NO_ARRAY_BUFFER && typeof ArrayBuffer < "u", HEX_CHARS = "0123456789abcdef".split(""), EXTRA = [-2147483648, 8388608, 32768, 128], SHIFT = [24, 16, 8, 0], K = [
321
+ 1116352408,
322
+ 1899447441,
323
+ 3049323471,
324
+ 3921009573,
325
+ 961987163,
326
+ 1508970993,
327
+ 2453635748,
328
+ 2870763221,
329
+ 3624381080,
330
+ 310598401,
331
+ 607225278,
332
+ 1426881987,
333
+ 1925078388,
334
+ 2162078206,
335
+ 2614888103,
336
+ 3248222580,
337
+ 3835390401,
338
+ 4022224774,
339
+ 264347078,
340
+ 604807628,
341
+ 770255983,
342
+ 1249150122,
343
+ 1555081692,
344
+ 1996064986,
345
+ 2554220882,
346
+ 2821834349,
347
+ 2952996808,
348
+ 3210313671,
349
+ 3336571891,
350
+ 3584528711,
351
+ 113926993,
352
+ 338241895,
353
+ 666307205,
354
+ 773529912,
355
+ 1294757372,
356
+ 1396182291,
357
+ 1695183700,
358
+ 1986661051,
359
+ 2177026350,
360
+ 2456956037,
361
+ 2730485921,
362
+ 2820302411,
363
+ 3259730800,
364
+ 3345764771,
365
+ 3516065817,
366
+ 3600352804,
367
+ 4094571909,
368
+ 275423344,
369
+ 430227734,
370
+ 506948616,
371
+ 659060556,
372
+ 883997877,
373
+ 958139571,
374
+ 1322822218,
375
+ 1537002063,
376
+ 1747873779,
377
+ 1955562222,
378
+ 2024104815,
379
+ 2227730452,
380
+ 2361852424,
381
+ 2428436474,
382
+ 2756734187,
383
+ 3204031479,
384
+ 3329325298
385
+ ], OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"], blocks = [];
386
+ (root.JS_SHA256_NO_NODE_JS || !Array.isArray) && (Array.isArray = function(r) {
387
+ return Object.prototype.toString.call(r) === "[object Array]";
388
+ }), ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) && (ArrayBuffer.isView = function(r) {
389
+ return typeof r == "object" && r.buffer && r.buffer.constructor === ArrayBuffer;
390
+ });
391
+ var createOutputMethod = function(r, t) {
392
+ return function(n) {
393
+ return new Sha256(t, !0).update(n)[r]();
394
+ };
395
+ }, createMethod = function(r) {
396
+ var t = createOutputMethod("hex", r);
397
+ NODE_JS && (t = nodeWrap(t, r)), t.create = function() {
398
+ return new Sha256(r);
399
+ }, t.update = function(c) {
400
+ return t.create().update(c);
401
+ };
402
+ for (var n = 0; n < OUTPUT_TYPES.length; ++n) {
403
+ var s = OUTPUT_TYPES[n];
404
+ t[s] = createOutputMethod(s, r);
405
+ }
406
+ return t;
407
+ }, nodeWrap = function(method, is224) {
408
+ var crypto = eval("require('crypto')"), Buffer = eval("require('buffer').Buffer"), algorithm = is224 ? "sha224" : "sha256", nodeMethod = function(r) {
409
+ if (typeof r == "string")
410
+ return crypto.createHash(algorithm).update(r, "utf8").digest("hex");
411
+ if (r == null)
412
+ throw new Error(ERROR);
413
+ return r.constructor === ArrayBuffer && (r = new Uint8Array(r)), Array.isArray(r) || ArrayBuffer.isView(r) || r.constructor === Buffer ? crypto.createHash(algorithm).update(new Buffer(r)).digest("hex") : method(r);
414
+ };
415
+ return nodeMethod;
416
+ }, createHmacOutputMethod = function(r, t) {
417
+ return function(n, s) {
418
+ return new HmacSha256(n, t, !0).update(s)[r]();
419
+ };
420
+ }, createHmacMethod = function(r) {
421
+ var t = createHmacOutputMethod("hex", r);
422
+ t.create = function(c) {
423
+ return new HmacSha256(c, r);
424
+ }, t.update = function(c, a) {
425
+ return t.create(c).update(a);
426
+ };
427
+ for (var n = 0; n < OUTPUT_TYPES.length; ++n) {
428
+ var s = OUTPUT_TYPES[n];
429
+ t[s] = createHmacOutputMethod(s, r);
430
+ }
431
+ return t;
432
+ };
433
+ function Sha256(r, t) {
434
+ t ? (blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] = blocks[4] = blocks[5] = blocks[6] = blocks[7] = blocks[8] = blocks[9] = blocks[10] = blocks[11] = blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0, this.blocks = blocks) : this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], r ? (this.h0 = 3238371032, this.h1 = 914150663, this.h2 = 812702999, this.h3 = 4144912697, this.h4 = 4290775857, this.h5 = 1750603025, this.h6 = 1694076839, this.h7 = 3204075428) : (this.h0 = 1779033703, this.h1 = 3144134277, this.h2 = 1013904242, this.h3 = 2773480762, this.h4 = 1359893119, this.h5 = 2600822924, this.h6 = 528734635, this.h7 = 1541459225), this.block = this.start = this.bytes = this.hBytes = 0, this.finalized = this.hashed = !1, this.first = !0, this.is224 = r;
435
+ }
436
+ Sha256.prototype.update = function(r) {
437
+ if (!this.finalized) {
438
+ var t, n = typeof r;
439
+ if (n !== "string") {
440
+ if (n === "object") {
441
+ if (r === null)
442
+ throw new Error(ERROR);
443
+ if (ARRAY_BUFFER && r.constructor === ArrayBuffer)
444
+ r = new Uint8Array(r);
445
+ else if (!Array.isArray(r) && (!ARRAY_BUFFER || !ArrayBuffer.isView(r)))
446
+ throw new Error(ERROR);
447
+ } else
448
+ throw new Error(ERROR);
449
+ t = !0;
450
+ }
451
+ for (var s, c = 0, a, d = r.length, l = this.blocks; c < d; ) {
452
+ if (this.hashed && (this.hashed = !1, l[0] = this.block, l[16] = l[1] = l[2] = l[3] = l[4] = l[5] = l[6] = l[7] = l[8] = l[9] = l[10] = l[11] = l[12] = l[13] = l[14] = l[15] = 0), t)
453
+ for (a = this.start; c < d && a < 64; ++c)
454
+ l[a >> 2] |= r[c] << SHIFT[a++ & 3];
455
+ else
456
+ for (a = this.start; c < d && a < 64; ++c)
457
+ s = r.charCodeAt(c), s < 128 ? l[a >> 2] |= s << SHIFT[a++ & 3] : s < 2048 ? (l[a >> 2] |= (192 | s >> 6) << SHIFT[a++ & 3], l[a >> 2] |= (128 | s & 63) << SHIFT[a++ & 3]) : s < 55296 || s >= 57344 ? (l[a >> 2] |= (224 | s >> 12) << SHIFT[a++ & 3], l[a >> 2] |= (128 | s >> 6 & 63) << SHIFT[a++ & 3], l[a >> 2] |= (128 | s & 63) << SHIFT[a++ & 3]) : (s = 65536 + ((s & 1023) << 10 | r.charCodeAt(++c) & 1023), l[a >> 2] |= (240 | s >> 18) << SHIFT[a++ & 3], l[a >> 2] |= (128 | s >> 12 & 63) << SHIFT[a++ & 3], l[a >> 2] |= (128 | s >> 6 & 63) << SHIFT[a++ & 3], l[a >> 2] |= (128 | s & 63) << SHIFT[a++ & 3]);
458
+ this.lastByteIndex = a, this.bytes += a - this.start, a >= 64 ? (this.block = l[16], this.start = a - 64, this.hash(), this.hashed = !0) : this.start = a;
459
+ }
460
+ return this.bytes > 4294967295 && (this.hBytes += this.bytes / 4294967296 << 0, this.bytes = this.bytes % 4294967296), this;
461
+ }
462
+ }, Sha256.prototype.finalize = function() {
463
+ if (!this.finalized) {
464
+ this.finalized = !0;
465
+ var r = this.blocks, t = this.lastByteIndex;
466
+ r[16] = this.block, r[t >> 2] |= EXTRA[t & 3], this.block = r[16], t >= 56 && (this.hashed || this.hash(), r[0] = this.block, r[16] = r[1] = r[2] = r[3] = r[4] = r[5] = r[6] = r[7] = r[8] = r[9] = r[10] = r[11] = r[12] = r[13] = r[14] = r[15] = 0), r[14] = this.hBytes << 3 | this.bytes >>> 29, r[15] = this.bytes << 3, this.hash();
467
+ }
468
+ }, Sha256.prototype.hash = function() {
469
+ var r = this.h0, t = this.h1, n = this.h2, s = this.h3, c = this.h4, a = this.h5, d = this.h6, l = this.h7, u = this.blocks, f, g, y, w, p, S, b, x, R, _, A;
470
+ for (f = 16; f < 64; ++f)
471
+ p = u[f - 15], g = (p >>> 7 | p << 25) ^ (p >>> 18 | p << 14) ^ p >>> 3, p = u[f - 2], y = (p >>> 17 | p << 15) ^ (p >>> 19 | p << 13) ^ p >>> 10, u[f] = u[f - 16] + g + u[f - 7] + y << 0;
472
+ for (A = t & n, f = 0; f < 64; f += 4)
473
+ this.first ? (this.is224 ? (x = 300032, p = u[0] - 1413257819, l = p - 150054599 << 0, s = p + 24177077 << 0) : (x = 704751109, p = u[0] - 210244248, l = p - 1521486534 << 0, s = p + 143694565 << 0), this.first = !1) : (g = (r >>> 2 | r << 30) ^ (r >>> 13 | r << 19) ^ (r >>> 22 | r << 10), y = (c >>> 6 | c << 26) ^ (c >>> 11 | c << 21) ^ (c >>> 25 | c << 7), x = r & t, w = x ^ r & n ^ A, b = c & a ^ ~c & d, p = l + y + b + K[f] + u[f], S = g + w, l = s + p << 0, s = p + S << 0), g = (s >>> 2 | s << 30) ^ (s >>> 13 | s << 19) ^ (s >>> 22 | s << 10), y = (l >>> 6 | l << 26) ^ (l >>> 11 | l << 21) ^ (l >>> 25 | l << 7), R = s & r, w = R ^ s & t ^ x, b = l & c ^ ~l & a, p = d + y + b + K[f + 1] + u[f + 1], S = g + w, d = n + p << 0, n = p + S << 0, g = (n >>> 2 | n << 30) ^ (n >>> 13 | n << 19) ^ (n >>> 22 | n << 10), y = (d >>> 6 | d << 26) ^ (d >>> 11 | d << 21) ^ (d >>> 25 | d << 7), _ = n & s, w = _ ^ n & r ^ R, b = d & l ^ ~d & c, p = a + y + b + K[f + 2] + u[f + 2], S = g + w, a = t + p << 0, t = p + S << 0, g = (t >>> 2 | t << 30) ^ (t >>> 13 | t << 19) ^ (t >>> 22 | t << 10), y = (a >>> 6 | a << 26) ^ (a >>> 11 | a << 21) ^ (a >>> 25 | a << 7), A = t & n, w = A ^ t & s ^ _, b = a & d ^ ~a & l, p = c + y + b + K[f + 3] + u[f + 3], S = g + w, c = r + p << 0, r = p + S << 0;
474
+ this.h0 = this.h0 + r << 0, this.h1 = this.h1 + t << 0, this.h2 = this.h2 + n << 0, this.h3 = this.h3 + s << 0, this.h4 = this.h4 + c << 0, this.h5 = this.h5 + a << 0, this.h6 = this.h6 + d << 0, this.h7 = this.h7 + l << 0;
475
+ }, Sha256.prototype.hex = function() {
476
+ this.finalize();
477
+ var r = this.h0, t = this.h1, n = this.h2, s = this.h3, c = this.h4, a = this.h5, d = this.h6, l = this.h7, u = HEX_CHARS[r >> 28 & 15] + HEX_CHARS[r >> 24 & 15] + HEX_CHARS[r >> 20 & 15] + HEX_CHARS[r >> 16 & 15] + HEX_CHARS[r >> 12 & 15] + HEX_CHARS[r >> 8 & 15] + HEX_CHARS[r >> 4 & 15] + HEX_CHARS[r & 15] + HEX_CHARS[t >> 28 & 15] + HEX_CHARS[t >> 24 & 15] + HEX_CHARS[t >> 20 & 15] + HEX_CHARS[t >> 16 & 15] + HEX_CHARS[t >> 12 & 15] + HEX_CHARS[t >> 8 & 15] + HEX_CHARS[t >> 4 & 15] + HEX_CHARS[t & 15] + HEX_CHARS[n >> 28 & 15] + HEX_CHARS[n >> 24 & 15] + HEX_CHARS[n >> 20 & 15] + HEX_CHARS[n >> 16 & 15] + HEX_CHARS[n >> 12 & 15] + HEX_CHARS[n >> 8 & 15] + HEX_CHARS[n >> 4 & 15] + HEX_CHARS[n & 15] + HEX_CHARS[s >> 28 & 15] + HEX_CHARS[s >> 24 & 15] + HEX_CHARS[s >> 20 & 15] + HEX_CHARS[s >> 16 & 15] + HEX_CHARS[s >> 12 & 15] + HEX_CHARS[s >> 8 & 15] + HEX_CHARS[s >> 4 & 15] + HEX_CHARS[s & 15] + HEX_CHARS[c >> 28 & 15] + HEX_CHARS[c >> 24 & 15] + HEX_CHARS[c >> 20 & 15] + HEX_CHARS[c >> 16 & 15] + HEX_CHARS[c >> 12 & 15] + HEX_CHARS[c >> 8 & 15] + HEX_CHARS[c >> 4 & 15] + HEX_CHARS[c & 15] + HEX_CHARS[a >> 28 & 15] + HEX_CHARS[a >> 24 & 15] + HEX_CHARS[a >> 20 & 15] + HEX_CHARS[a >> 16 & 15] + HEX_CHARS[a >> 12 & 15] + HEX_CHARS[a >> 8 & 15] + HEX_CHARS[a >> 4 & 15] + HEX_CHARS[a & 15] + HEX_CHARS[d >> 28 & 15] + HEX_CHARS[d >> 24 & 15] + HEX_CHARS[d >> 20 & 15] + HEX_CHARS[d >> 16 & 15] + HEX_CHARS[d >> 12 & 15] + HEX_CHARS[d >> 8 & 15] + HEX_CHARS[d >> 4 & 15] + HEX_CHARS[d & 15];
478
+ return this.is224 || (u += HEX_CHARS[l >> 28 & 15] + HEX_CHARS[l >> 24 & 15] + HEX_CHARS[l >> 20 & 15] + HEX_CHARS[l >> 16 & 15] + HEX_CHARS[l >> 12 & 15] + HEX_CHARS[l >> 8 & 15] + HEX_CHARS[l >> 4 & 15] + HEX_CHARS[l & 15]), u;
479
+ }, Sha256.prototype.toString = Sha256.prototype.hex, Sha256.prototype.digest = function() {
480
+ this.finalize();
481
+ var r = this.h0, t = this.h1, n = this.h2, s = this.h3, c = this.h4, a = this.h5, d = this.h6, l = this.h7, u = [
482
+ r >> 24 & 255,
483
+ r >> 16 & 255,
484
+ r >> 8 & 255,
485
+ r & 255,
486
+ t >> 24 & 255,
487
+ t >> 16 & 255,
488
+ t >> 8 & 255,
489
+ t & 255,
490
+ n >> 24 & 255,
491
+ n >> 16 & 255,
492
+ n >> 8 & 255,
493
+ n & 255,
494
+ s >> 24 & 255,
495
+ s >> 16 & 255,
496
+ s >> 8 & 255,
497
+ s & 255,
498
+ c >> 24 & 255,
499
+ c >> 16 & 255,
500
+ c >> 8 & 255,
501
+ c & 255,
502
+ a >> 24 & 255,
503
+ a >> 16 & 255,
504
+ a >> 8 & 255,
505
+ a & 255,
506
+ d >> 24 & 255,
507
+ d >> 16 & 255,
508
+ d >> 8 & 255,
509
+ d & 255
510
+ ];
511
+ return this.is224 || u.push(l >> 24 & 255, l >> 16 & 255, l >> 8 & 255, l & 255), u;
512
+ }, Sha256.prototype.array = Sha256.prototype.digest, Sha256.prototype.arrayBuffer = function() {
513
+ this.finalize();
514
+ var r = new ArrayBuffer(this.is224 ? 28 : 32), t = new DataView(r);
515
+ return t.setUint32(0, this.h0), t.setUint32(4, this.h1), t.setUint32(8, this.h2), t.setUint32(12, this.h3), t.setUint32(16, this.h4), t.setUint32(20, this.h5), t.setUint32(24, this.h6), this.is224 || t.setUint32(28, this.h7), r;
516
+ };
517
+ function HmacSha256(r, t, n) {
518
+ var s, c = typeof r;
519
+ if (c === "string") {
520
+ var a = [], d = r.length, l = 0, u;
521
+ for (s = 0; s < d; ++s)
522
+ u = r.charCodeAt(s), u < 128 ? a[l++] = u : u < 2048 ? (a[l++] = 192 | u >> 6, a[l++] = 128 | u & 63) : u < 55296 || u >= 57344 ? (a[l++] = 224 | u >> 12, a[l++] = 128 | u >> 6 & 63, a[l++] = 128 | u & 63) : (u = 65536 + ((u & 1023) << 10 | r.charCodeAt(++s) & 1023), a[l++] = 240 | u >> 18, a[l++] = 128 | u >> 12 & 63, a[l++] = 128 | u >> 6 & 63, a[l++] = 128 | u & 63);
523
+ r = a;
524
+ } else if (c === "object") {
525
+ if (r === null)
526
+ throw new Error(ERROR);
527
+ if (ARRAY_BUFFER && r.constructor === ArrayBuffer)
528
+ r = new Uint8Array(r);
529
+ else if (!Array.isArray(r) && (!ARRAY_BUFFER || !ArrayBuffer.isView(r)))
530
+ throw new Error(ERROR);
531
+ } else
532
+ throw new Error(ERROR);
533
+ r.length > 64 && (r = new Sha256(t, !0).update(r).array());
534
+ var f = [], g = [];
535
+ for (s = 0; s < 64; ++s) {
536
+ var y = r[s] || 0;
537
+ f[s] = 92 ^ y, g[s] = 54 ^ y;
538
+ }
539
+ Sha256.call(this, t, n), this.update(g), this.oKeyPad = f, this.inner = !0, this.sharedMemory = n;
540
+ }
541
+ HmacSha256.prototype = new Sha256(), HmacSha256.prototype.finalize = function() {
542
+ if (Sha256.prototype.finalize.call(this), this.inner) {
543
+ this.inner = !1;
544
+ var r = this.array();
545
+ Sha256.call(this, this.is224, this.sharedMemory), this.update(this.oKeyPad), this.update(r), Sha256.prototype.finalize.call(this);
546
+ }
547
+ };
548
+ var exports = createMethod();
549
+ exports.sha256 = exports, exports.sha224 = createMethod(!0), exports.sha256.hmac = createHmacMethod(), exports.sha224.hmac = createHmacMethod(!0), COMMON_JS ? module.exports = exports : (root.sha256 = exports.sha256, root.sha224 = exports.sha224);
550
+ })();
551
+ })(sha256);
552
+ var getRandomValues, rnds8 = new Uint8Array(16);
553
+ function rng() {
554
+ if (!getRandomValues && (getRandomValues = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto < "u" && typeof msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto), !getRandomValues))
555
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
556
+ return getRandomValues(rnds8);
557
+ }
558
+ const REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
559
+ function validate(r) {
560
+ return typeof r == "string" && REGEX.test(r);
561
+ }
562
+ var byteToHex = [];
563
+ for (var i = 0; i < 256; ++i)
564
+ byteToHex.push((i + 256).toString(16).substr(1));
565
+ function stringify(r) {
566
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, n = (byteToHex[r[t + 0]] + byteToHex[r[t + 1]] + byteToHex[r[t + 2]] + byteToHex[r[t + 3]] + "-" + byteToHex[r[t + 4]] + byteToHex[r[t + 5]] + "-" + byteToHex[r[t + 6]] + byteToHex[r[t + 7]] + "-" + byteToHex[r[t + 8]] + byteToHex[r[t + 9]] + "-" + byteToHex[r[t + 10]] + byteToHex[r[t + 11]] + byteToHex[r[t + 12]] + byteToHex[r[t + 13]] + byteToHex[r[t + 14]] + byteToHex[r[t + 15]]).toLowerCase();
567
+ if (!validate(n))
568
+ throw TypeError("Stringified UUID is invalid");
569
+ return n;
570
+ }
571
+ function v4(r, t, n) {
572
+ r = r || {};
573
+ var s = r.random || (r.rng || rng)();
574
+ if (s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, t) {
575
+ n = n || 0;
576
+ for (var c = 0; c < 16; ++c)
577
+ t[n + c] = s[c];
578
+ return t;
579
+ }
580
+ return stringify(s);
581
+ }
582
+ async function getBytes(r, t) {
583
+ const n = r.getReader();
584
+ let s;
585
+ for (; !(s = await n.read()).done; )
586
+ t(s.value);
587
+ }
588
+ function getLines(r) {
589
+ let t, n, s, c = !1;
590
+ return function(d) {
591
+ t === void 0 ? (t = d, n = 0, s = -1) : t = concat(t, d);
592
+ const l = t.length;
593
+ let u = 0;
594
+ for (; n < l; ) {
595
+ c && (t[n] === 10 && (u = ++n), c = !1);
596
+ let f = -1;
597
+ for (; n < l && f === -1; ++n)
598
+ switch (t[n]) {
599
+ case 58:
600
+ s === -1 && (s = n - u);
601
+ break;
602
+ case 13:
603
+ c = !0;
604
+ case 10:
605
+ f = n;
606
+ break;
607
+ }
608
+ if (f === -1)
609
+ break;
610
+ r(t.subarray(u, f), s), u = n, s = -1;
611
+ }
612
+ u === l ? t = void 0 : u !== 0 && (t = t.subarray(u), n -= u);
613
+ };
614
+ }
615
+ function getMessages(r, t, n) {
616
+ let s = newMessage();
617
+ const c = new TextDecoder();
618
+ return function(d, l) {
619
+ if (d.length === 0)
620
+ n == null || n(s), s = newMessage();
621
+ else if (l > 0) {
622
+ const u = c.decode(d.subarray(0, l)), f = l + (d[l + 1] === 32 ? 2 : 1), g = c.decode(d.subarray(f));
623
+ switch (u) {
624
+ case "data":
625
+ s.data = s.data ? s.data + `
626
+ ` + g : g;
627
+ break;
628
+ case "event":
629
+ s.event = g;
630
+ break;
631
+ case "id":
632
+ r(s.id = g);
633
+ break;
634
+ case "retry":
635
+ const y = parseInt(g, 10);
636
+ isNaN(y) || t(s.retry = y);
637
+ break;
638
+ }
639
+ }
640
+ };
641
+ }
642
+ function concat(r, t) {
643
+ const n = new Uint8Array(r.length + t.length);
644
+ return n.set(r), n.set(t, r.length), n;
645
+ }
646
+ function newMessage() {
647
+ return {
648
+ data: "",
649
+ event: "",
650
+ id: "",
651
+ retry: void 0
652
+ };
653
+ }
654
+ var __rest = function(r, t) {
655
+ var n = {};
656
+ for (var s in r)
657
+ Object.prototype.hasOwnProperty.call(r, s) && t.indexOf(s) < 0 && (n[s] = r[s]);
658
+ if (r != null && typeof Object.getOwnPropertySymbols == "function")
659
+ for (var c = 0, s = Object.getOwnPropertySymbols(r); c < s.length; c++)
660
+ t.indexOf(s[c]) < 0 && Object.prototype.propertyIsEnumerable.call(r, s[c]) && (n[s[c]] = r[s[c]]);
661
+ return n;
662
+ };
663
+ const EventStreamContentType = "text/event-stream", DefaultRetryInterval = 1e3, LastEventId = "last-event-id";
664
+ function fetchEventSource(r, t) {
665
+ var { signal: n, headers: s, onopen: c, onmessage: a, onclose: d, onerror: l, openWhenHidden: u, fetch: f } = t, g = __rest(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
666
+ return new Promise((y, w) => {
667
+ const p = Object.assign({}, s);
668
+ p.accept || (p.accept = EventStreamContentType);
669
+ let S;
670
+ function b() {
671
+ S.abort(), document.hidden || k();
672
+ }
673
+ u || document.addEventListener("visibilitychange", b);
674
+ let x = DefaultRetryInterval, R = 0;
675
+ function _() {
676
+ document.removeEventListener("visibilitychange", b), window.clearTimeout(R), S.abort();
677
+ }
678
+ n == null || n.addEventListener("abort", () => {
679
+ _(), y();
680
+ });
681
+ const A = f ?? window.fetch, I = c ?? defaultOnOpen;
682
+ async function k() {
683
+ var U;
684
+ S = new AbortController();
685
+ try {
686
+ const T = await A(r, Object.assign(Object.assign({}, g), { headers: p, signal: S.signal }));
687
+ await I(T), await getBytes(T.body, getLines(getMessages((v) => {
688
+ v ? p[LastEventId] = v : delete p[LastEventId];
689
+ }, (v) => {
690
+ x = v;
691
+ }, a))), d == null || d(), _(), y();
692
+ } catch (T) {
693
+ if (!S.signal.aborted)
694
+ try {
695
+ const v = (U = l == null ? void 0 : l(T)) !== null && U !== void 0 ? U : x;
696
+ window.clearTimeout(R), R = window.setTimeout(k, v);
697
+ } catch (v) {
698
+ _(), w(v);
699
+ }
700
+ }
701
+ }
702
+ k();
703
+ });
704
+ }
705
+ function defaultOnOpen(r) {
706
+ const t = r.headers.get("content-type");
707
+ if (!(t != null && t.startsWith(EventStreamContentType)))
708
+ throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${t}`);
709
+ }
710
+ function Base64EncodeUrl(r) {
711
+ return r.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
712
+ }
713
+ function getTimestamp() {
714
+ return Math.floor(Date.now() / 1e3);
715
+ }
716
+ function e(r) {
717
+ this.message = r;
718
+ }
719
+ e.prototype = new Error(), e.prototype.name = "InvalidCharacterError";
720
+ var r$1 = typeof window < "u" && window.atob && window.atob.bind(window) || function(r) {
721
+ var t = String(r).replace(/=+$/, "");
722
+ if (t.length % 4 == 1)
723
+ throw new e("'atob' failed: The string to be decoded is not correctly encoded.");
724
+ for (var n, s, c = 0, a = 0, d = ""; s = t.charAt(a++); ~s && (n = c % 4 ? 64 * n + s : s, c++ % 4) ? d += String.fromCharCode(255 & n >> (-2 * c & 6)) : 0)
725
+ s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);
726
+ return d;
727
+ };
728
+ function t$1(r) {
729
+ var t = r.replace(/-/g, "+").replace(/_/g, "/");
730
+ switch (t.length % 4) {
731
+ case 0:
732
+ break;
733
+ case 2:
734
+ t += "==";
735
+ break;
736
+ case 3:
737
+ t += "=";
738
+ break;
739
+ default:
740
+ throw "Illegal base64url string!";
741
+ }
742
+ try {
743
+ return function(n) {
744
+ return decodeURIComponent(r$1(n).replace(/(.)/g, function(s, c) {
745
+ var a = c.charCodeAt(0).toString(16).toUpperCase();
746
+ return a.length < 2 && (a = "0" + a), "%" + a;
747
+ }));
748
+ }(t);
749
+ } catch {
750
+ return r$1(t);
751
+ }
752
+ }
753
+ function n$1(r) {
754
+ this.message = r;
755
+ }
756
+ function o(r, t) {
757
+ if (typeof r != "string")
758
+ throw new n$1("Invalid token specified");
759
+ var n = (t = t || {}).header === !0 ? 0 : 1;
760
+ try {
761
+ return JSON.parse(t$1(r.split(".")[n]));
762
+ } catch (s) {
763
+ throw new n$1("Invalid token specified: " + s.message);
764
+ }
765
+ }
766
+ n$1.prototype = new Error(), n$1.prototype.name = "InvalidTokenError";
767
+ class NylasSessions {
768
+ constructor(t) {
769
+ m(this, "clientId");
770
+ m(this, "redirectUri");
771
+ m(this, "accessType", "online");
772
+ m(this, "domain", "http://api.nylas.com");
773
+ m(this, "versioned", !1);
774
+ m(this, "Storage");
775
+ m(this, "hosted", !1);
776
+ m(this, "multiAccount", !1);
777
+ m(this, "loginId", "");
778
+ if (this.clientId = t.clientId, this.redirectUri = t.redirectUri, t.domain && (this.domain = t.domain, this.domain.substring(this.domain.length - 3).includes("/v") && (this.versioned = !0)), t.multiAccount && (this.multiAccount = t.multiAccount), t.sw) {
779
+ const n = new IndexedDBStorage();
780
+ this.Storage = new Storage(n);
781
+ } else
782
+ this.Storage = new Storage();
783
+ t.accessType && (this.accessType = t.accessType), t.loginId && (this.loginId = t.loginId), t.hosted && (this.hosted = t.hosted), this.codeExchange(null);
784
+ }
785
+ // Validates access token
786
+ async validateAccessToken(t = "") {
787
+ const n = await this.Storage.getGrant(t, this.multiAccount);
788
+ if (!n)
789
+ return !1;
790
+ const { access_token: s } = n;
791
+ try {
792
+ return !!(await (await fetch(`${this.domain}/connect/tokeninfo?access_token=${s}`, {
793
+ method: "GET"
794
+ })).json()).data;
795
+ } catch {
796
+ return !1;
797
+ }
798
+ }
799
+ // Validates id token
800
+ async validateIDToken(t = "") {
801
+ const n = await this.Storage.getGrant(t, this.multiAccount);
802
+ if (!n)
803
+ return !1;
804
+ const { id_token: s } = n;
805
+ try {
806
+ const c = await fetch(`${this.domain}/connect/tokeninfo?id_token=${s}`, {
807
+ method: "GET"
808
+ });
809
+ return !(c.status !== 200 || !(await c.json()).data);
810
+ } catch {
811
+ return !1;
812
+ }
813
+ }
814
+ // Gets domain of UAS
815
+ getDomain() {
816
+ return this.domain;
817
+ }
818
+ // Gets auth link
819
+ async auth(t) {
820
+ this.hosted && (this.domain === window.location.origin || this.versioned && this.domain.includes(window.location.origin)) && await this.hostedSetCodeChallenge();
821
+ const n = await this.generateAuthURL(t);
822
+ if (t.popup) {
823
+ this.popUp(n);
824
+ return;
825
+ }
826
+ return n;
827
+ }
828
+ // Generates auth URL
829
+ async generateAuthURL(t) {
830
+ const n = await this.getCodeChallege();
831
+ let s = `${this.domain}/connect/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&access_type=${this.accessType}&response_type=code`;
832
+ return n && (s += `&code_challenge=${n}&code_challenge_method=S256&options=rotate_refresh_token`), t.provider && (s += `&provider=${t.provider}`), t.loginHint && (s += `&login_hint=${t.loginHint}`, t.includeGrantScopes && (s += `&include_grant_scopes=${t.includeGrantScopes}`)), t.scope && (s += `&scope=${t.scope.join(" ")}`), t.prompt && (s += `&prompt=${t.prompt}`), t.metadata && (s += `&metadata=${t.metadata}`), (t.state || this.loginId) && (s += `&state=${this.loginId ? this.loginId : t.state}`), s;
833
+ }
834
+ // Generates auth URL
835
+ async generateReauthURL(t, n) {
836
+ if (!t)
837
+ throw new Error("Grant ID is required");
838
+ const s = await this.Storage.getUserToken(t), c = await this.getCodeChallege();
839
+ let a = `${this.domain}/connect/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&access_type=${this.accessType}&response_type=code`;
840
+ return c && (a += `&code_challenge=${c}&code_challenge_method=S256&options=rotate_refresh_token`), s != null && s.provider && (a += `&provider=${s.provider}`), s != null && s.email && (a += `&login_hint=${s.email}`), n && (a += `&scope=${n.join(" ")}`), a;
841
+ }
842
+ // Generates UUID code challenge
843
+ async generateCodeChallenge() {
844
+ if (await this.Storage.getPKCE())
845
+ return;
846
+ const n = v4();
847
+ this.Storage.setPKCE(n);
848
+ }
849
+ // Gets code challenge from URL query params
850
+ async hostedSetCodeChallenge() {
851
+ if (!this.hosted)
852
+ throw console.error("Method only used with hosted flag enabled");
853
+ const n = new URLSearchParams(window.location.search).get("code_challenge");
854
+ if (!n) {
855
+ if (await this.Storage.getPKCE())
856
+ return;
857
+ console.warn("Code challenge is recomended");
858
+ return;
859
+ }
860
+ this.Storage.setPKCE(n);
861
+ }
862
+ // Gets code challenge from store
863
+ async getCodeChallege() {
864
+ if (this.hosted && (this.domain === window.location.origin || this.versioned && this.domain.includes(window.location.origin))) {
865
+ const s = new URLSearchParams(window.location.search).get("code_challenge");
866
+ return s || (console.warn("Code challenge is recomended"), "");
867
+ }
868
+ const t = await this.Storage.getPKCE();
869
+ if (t) {
870
+ const n = sha256.exports.sha256(t);
871
+ let s = Buffer.from(n).toString("base64");
872
+ return s = Base64EncodeUrl(s), s;
873
+ }
874
+ return "";
875
+ }
876
+ // checks if user is logged in
877
+ async isLoggedIn() {
878
+ if (this.hosted && (this.domain === window.location.origin || this.versioned && this.domain.includes(window.location.origin)))
879
+ return !1;
880
+ const t = await this.Storage.getUserTokens();
881
+ return t && t.length > 0 ? (this.multiAccount && await this.generateCodeChallenge(), !0) : (await this.generateCodeChallenge(), !1);
882
+ }
883
+ // Checks if user is multi account
884
+ isMultiAccount() {
885
+ return this.multiAccount;
886
+ }
887
+ // Logs user out
888
+ async logout() {
889
+ const t = await this.getProfile();
890
+ await this.Storage.clearSession();
891
+ const n = { detail: t };
892
+ window.dispatchEvent(new CustomEvent("onLogoutSuccess", n));
893
+ }
894
+ // Gets profile info from ID token
895
+ async getProfile(t = "") {
896
+ let n;
897
+ return t ? n = await this.Storage.getUserToken(t) : n = await this.Storage.getUserToken(), n || null;
898
+ }
899
+ // Gets profile info from ID tokens
900
+ async getProfiles() {
901
+ const t = await this.Storage.getUserTokens();
902
+ return t || null;
903
+ }
904
+ // Remove a specific profile
905
+ async removeProfile(t) {
906
+ return await this.Storage.removeUserToken(t), await this.Storage.removeGrant(t), null;
907
+ }
908
+ // IMAP authentication
909
+ async authIMAP(t) {
910
+ const n = await this.getCodeChallege(), s = {
911
+ imap_username: t.username,
912
+ imap_password: t.password,
913
+ imap_host: t.hostIMAP,
914
+ imap_port: t.portIMAP,
915
+ type: t.type,
916
+ smtp_host: t.hostSMTP,
917
+ smtp_port: t.portSMTP,
918
+ provider: t.provider,
919
+ redirect_uri: this.redirectUri,
920
+ state: t.state,
921
+ public_application_id: this.clientId,
922
+ access_type: this.accessType
923
+ };
924
+ return this.loginId && (s.id = this.loginId), n != "" && (s.code_challenge = n, s.code_challenge_method = "S256"), await (await fetch(`${this.domain}/connect/login/imap`, {
925
+ method: "POST",
926
+ headers: new Headers({ "content-type": "application/json" }),
927
+ body: JSON.stringify(s)
928
+ })).json();
929
+ }
930
+ // EWS authentication
931
+ async authEWS(t) {
932
+ const n = await this.getCodeChallege(), s = {
933
+ ...t,
934
+ redirect_uri: this.redirectUri,
935
+ public_application_id: this.clientId,
936
+ access_type: this.accessType
937
+ };
938
+ return this.loginId && (s.id = this.loginId), n != "" && (s.code_challenge = n, s.code_challenge_method = "S256"), await (await fetch(`${this.domain}/connect/login/ews`, {
939
+ method: "POST",
940
+ headers: new Headers({ "content-type": "application/json" }),
941
+ body: JSON.stringify(s)
942
+ })).json();
943
+ }
944
+ // Detects email
945
+ async detectEmail(t) {
946
+ return (await (await fetch(`${this.versioned ? this.domain : this.domain + "/connect"}/providers/detect?client_id=${this.clientId}&email=${t}`, {
947
+ method: "POST",
948
+ headers: new Headers({ "content-type": "application/json" })
949
+ })).json()).data;
950
+ }
951
+ // Gets app info from UAS
952
+ async applicationInfo() {
953
+ return (await (await fetch(`${this.versioned ? this.domain : this.domain + "/connect"}/applications?client_id=${this.clientId}`, {
954
+ method: "GET",
955
+ headers: new Headers({ "content-type": "application/json" })
956
+ })).json()).data;
957
+ }
958
+ // Gets providers form UAS
959
+ async getAvailableProviders() {
960
+ const t = await fetch(`${this.domain}/connect/providers/find?client_id=${this.clientId}`, {
961
+ method: "GET",
962
+ headers: new Headers({ "content-type": "application/json" })
963
+ });
964
+ return t ? (await t.json()).data : null;
965
+ }
966
+ // EVENT HOOKS
967
+ onLoginSuccess(t) {
968
+ window.addEventListener("onLoginSuccess", (n) => t(n));
969
+ }
970
+ onLogoutSuccess(t) {
971
+ window.addEventListener("onLogoutSuccess", (n) => t(n));
972
+ }
973
+ onLoginFail(t) {
974
+ window.addEventListener("onLoginFail", (n) => t(n));
975
+ }
976
+ onTokenRefreshSuccess(t) {
977
+ window.addEventListener("onTokenRefreshSuccess", (n) => t(n));
978
+ }
979
+ onTokenRefreshFail(t) {
980
+ window.addEventListener("onTokenRefreshFail", (n) => t(n));
981
+ }
982
+ onSessionExpired(t) {
983
+ window.addEventListener("onSessionExpired", (n) => t(n));
984
+ }
985
+ // Exchanges code for ID token and refresh and access tokens
986
+ async codeExchange(t) {
987
+ let n = new URLSearchParams(window.location.search);
988
+ t && (n = new URLSearchParams(t));
989
+ const s = n.get("code"), c = n.get("state"), a = n.get("error"), d = n.get("error_description"), l = n.get("error_code");
990
+ if (a && d && l) {
991
+ const f = {
992
+ detail: { error: a, error_description: d, error_code: l }
993
+ };
994
+ return window.dispatchEvent(new CustomEvent("onLoginFail", f)), window.history.pushState({}, document.title, window.location.pathname), !1;
995
+ }
996
+ if (!s)
997
+ return console.warn("No code found"), !1;
998
+ if (window.opener && window.name === "uas-popup")
999
+ return console.warn("Popup window detected"), !1;
1000
+ const u = await this.Storage.getPKCE();
1001
+ if (!u)
1002
+ return console.warn("No code verifier found"), !1;
1003
+ try {
1004
+ const f = {
1005
+ client_id: this.clientId,
1006
+ redirect_uri: this.redirectUri,
1007
+ code: s,
1008
+ grant_type: "authorization_code",
1009
+ code_verifier: u
1010
+ }, y = await (await fetch(`${this.domain}/connect/token`, {
1011
+ method: "POST",
1012
+ headers: new Headers({ "content-type": "application/json" }),
1013
+ body: JSON.stringify(f)
1014
+ })).json();
1015
+ if (y) {
1016
+ if (y.error) {
1017
+ const p = { detail: y };
1018
+ return window.dispatchEvent(new CustomEvent("onLoginFail", p)), !0;
1019
+ }
1020
+ const w = await this.handleCodeExchangeResponse(y);
1021
+ if (w.valid) {
1022
+ c && (w.data.state = c);
1023
+ const p = { detail: w.data };
1024
+ window.dispatchEvent(new CustomEvent("onLoginSuccess", p)), window.history.pushState({}, document.title, window.location.pathname);
1025
+ } else {
1026
+ const p = { detail: w.data };
1027
+ return window.dispatchEvent(new CustomEvent("onLoginFail", p)), !0;
1028
+ }
1029
+ }
1030
+ return this.Storage.removePKCE(), !0;
1031
+ } catch (f) {
1032
+ const g = { detail: f };
1033
+ return window.dispatchEvent(new CustomEvent("onLoginFail", g)), window.history.pushState({}, document.title, window.location.pathname), !1;
1034
+ }
1035
+ }
1036
+ // Token Exchange for session maintenece
1037
+ async tokenExchange(t = "") {
1038
+ const n = await this.Storage.getGrant(t, this.multiAccount);
1039
+ if (!n)
1040
+ return !1;
1041
+ const s = n.refresh_token;
1042
+ try {
1043
+ const c = {
1044
+ client_id: this.clientId,
1045
+ redirect_uri: this.redirectUri,
1046
+ refresh_token: s,
1047
+ grant_type: "refresh_token"
1048
+ }, d = await (await fetch(`${this.domain}/connect/token`, {
1049
+ method: "POST",
1050
+ headers: new Headers({ "content-type": "application/json" }),
1051
+ body: JSON.stringify(c)
1052
+ })).json();
1053
+ if (d) {
1054
+ if (d.error) {
1055
+ const g = { detail: d };
1056
+ return window.dispatchEvent(new CustomEvent("onTokenRefreshFail", g)), !0;
1057
+ }
1058
+ const l = getTimestamp();
1059
+ if (d.expires_in = l + d.expires_in, this.Storage.setGrant(d, this.multiAccount), !await this.validateIDToken(t)) {
1060
+ const g = { detail: d };
1061
+ return window.dispatchEvent(new CustomEvent("onTokenRefreshFail", g)), !0;
1062
+ }
1063
+ const f = { detail: d };
1064
+ return window.dispatchEvent(new CustomEvent("onTokenRefreshSuccess", f)), !0;
1065
+ }
1066
+ this.Storage.removePKCE();
1067
+ } catch (c) {
1068
+ const a = { detail: c };
1069
+ return window.dispatchEvent(new CustomEvent("onTokenRefreshFail", a)), !1;
1070
+ }
1071
+ }
1072
+ // Handles the response of code exchange
1073
+ async handleCodeExchangeResponse(t) {
1074
+ if (t.error)
1075
+ return {
1076
+ data: t,
1077
+ valid: !1
1078
+ };
1079
+ const s = getTimestamp();
1080
+ t.expires_in = s + t.expires_in, this.Storage.setGrant(t, this.multiAccount);
1081
+ const c = o(t.id_token);
1082
+ return c.status = "authenticated", this.Storage.setUserToken(c), await this.validateIDToken(c.sub) ? {
1083
+ data: t,
1084
+ valid: !0
1085
+ } : {
1086
+ data: t,
1087
+ valid: !1
1088
+ };
1089
+ }
1090
+ // Regulates POPUP behaivior
1091
+ async popUp(t) {
1092
+ const c = window.screenX + (window.outerWidth - 500) / 2, a = window.screenY + (window.outerHeight - 600) / 2.5, d = "uas-popup", l = t, u = window.open(l, d, `width=500,height=600,left=${c},top=${a}`);
1093
+ if (!u)
1094
+ return;
1095
+ const f = setInterval(async () => {
1096
+ if (u.closed) {
1097
+ const g = {
1098
+ detail: { error_description: "OAuth provider window closed" }
1099
+ };
1100
+ window.dispatchEvent(new CustomEvent("onLoginFail", g)), f && clearInterval(f);
1101
+ return;
1102
+ }
1103
+ try {
1104
+ const g = u.location.href.split("?");
1105
+ if (!g[0])
1106
+ return;
1107
+ const y = u.location.search;
1108
+ if (u.history.pushState({}, document.title, window.location.pathname), g[0] === this.redirectUri && g.length > 1) {
1109
+ const w = await this.codeExchange(y);
1110
+ u.close(), w && location.reload(), f && clearInterval(f);
1111
+ return;
1112
+ }
1113
+ } catch {
1114
+ return;
1115
+ }
1116
+ }, 1e3);
1117
+ }
1118
+ // Returns access token
1119
+ async getAccessToken(t = "") {
1120
+ const n = getTimestamp(), s = await this.Storage.getGrant(t, this.multiAccount);
1121
+ if (!s)
1122
+ return null;
1123
+ const { access_token: c, expires_in: a } = s, d = c;
1124
+ return d && a && a > getTimestamp() && a - n > 30 ? d : (await this.tokenExchange(t), (await this.Storage.getGrant(t, this.multiAccount)).access_token);
1125
+ }
1126
+ async sse(t, n) {
1127
+ const s = n.headers || {}, c = s["Grant-ID"];
1128
+ let a = "";
1129
+ if (this.multiAccount) {
1130
+ if (!c)
1131
+ throw new Error("Grant ID is required for multi account calls");
1132
+ a = await this.getAccessToken(c);
1133
+ } else
1134
+ a = await this.getAccessToken();
1135
+ return delete s["Grant-ID"], s.Authorization = `Bearer ${a}`, s["content-type"] || (s["content-type"] = "application/json"), fetchEventSource(`${this.domain}/${t}`, {
1136
+ ...n,
1137
+ headers: s
1138
+ });
1139
+ }
1140
+ // Used to call Nylas API endpoints
1141
+ async fetch(t, n, s = !0, c) {
1142
+ let a = "", d = 1;
1143
+ if (this.multiAccount) {
1144
+ if (!n.grant_id)
1145
+ throw new Error("Grant ID is required for multi account calls");
1146
+ const u = await this.getProfiles();
1147
+ d = u ? u.length : 1, a = await this.getAccessToken(n.grant_id);
1148
+ } else
1149
+ a = await this.getAccessToken();
1150
+ if (!a)
1151
+ throw new Error("Access token not found");
1152
+ let l = n.headers;
1153
+ Headers.prototype.isPrototypeOf(l) ? (l.append("Authorization", `Bearer ${a}`), l.has("content-type") || l.append("content-type", "application/json")) : l = new Headers({
1154
+ Authorization: `Bearer ${a}`,
1155
+ "content-type": "application/json"
1156
+ });
1157
+ try {
1158
+ n != null && n.body && (n.body = JSON.stringify(n == null ? void 0 : n.body));
1159
+ const u = await fetch(`${c || this.domain}/${t}`, {
1160
+ ...n,
1161
+ headers: l
1162
+ });
1163
+ if (!s)
1164
+ return u;
1165
+ const f = await (u == null ? void 0 : u.json());
1166
+ if (!await this.isAuthenticatedResponse(u.status, f)) {
1167
+ if (d > 1) {
1168
+ const y = await this.getProfile(n.grant_id);
1169
+ if (y) {
1170
+ y.status = "unauthorized", await this.Storage.setUserToken(y);
1171
+ const w = {
1172
+ detail: { user: y }
1173
+ };
1174
+ window.dispatchEvent(new CustomEvent("onSessionExpired", w));
1175
+ }
1176
+ } else {
1177
+ const w = {
1178
+ detail: { user: await this.Storage.getUserToken() }
1179
+ };
1180
+ window.dispatchEvent(new CustomEvent("onSessionExpired", w));
1181
+ }
1182
+ this.logout();
1183
+ return;
1184
+ }
1185
+ return f;
1186
+ } catch (u) {
1187
+ throw u;
1188
+ }
1189
+ }
1190
+ async fetchRequest(t, n, s, c = !0, a, d) {
1191
+ const l = await this.isLoggedIn(), u = new URL(t, a ?? this.domain), f = new Headers();
1192
+ if (f.append("Accept", "application/json"), f.append("Content-Type", "application/json"), f.append("User-Agent", "nylas-identity"), l) {
1193
+ const w = await this.getAccessToken();
1194
+ f.append("Authorization", `Bearer ${w}`);
1195
+ }
1196
+ const g = await fetch(u.toString(), {
1197
+ method: n || "GET",
1198
+ headers: f,
1199
+ mode: "cors",
1200
+ referrer: location.origin,
1201
+ body: s ? JSON.stringify(s) : void 0,
1202
+ ...d || {}
1203
+ });
1204
+ return c ? await g.json() : g.body;
1205
+ }
1206
+ // Checks if the response is not 401
1207
+ async isAuthenticatedResponse(t, n) {
1208
+ var s;
1209
+ return !(t == 401 && ((s = n == null ? void 0 : n.error) == null ? void 0 : s.type) == "token.unauthorized_access");
1210
+ }
1211
+ addAPIKey(t, n, s) {
1212
+ this.Storage.setUserToken({
1213
+ aud: "https://api-staging.us.nylas.com/",
1214
+ exp: 2e9,
1215
+ email_verified: !0,
1216
+ iat: getTimestamp(),
1217
+ iss: "",
1218
+ email: n,
1219
+ provider: "virtual-calendar",
1220
+ status: "authenticated",
1221
+ name: n,
1222
+ sub: t
1223
+ }), this.Storage.setGrant({
1224
+ grant_id: t,
1225
+ access_token: s,
1226
+ expires_in: 2e9
1227
+ }, this.multiAccount);
1228
+ }
1229
+ }
1230
+ var B = { isMounted: function() {
1231
+ return !1;
1232
+ }, enqueueForceUpdate: function() {
1233
+ }, enqueueReplaceState: function() {
1234
+ }, enqueueSetState: function() {
1235
+ } }, C = Object.assign, D = {};
1236
+ function E(r, t, n) {
1237
+ this.props = r, this.context = t, this.refs = D, this.updater = n || B;
1238
+ }
1239
+ E.prototype.isReactComponent = {};
1240
+ E.prototype.setState = function(r, t) {
1241
+ if (typeof r != "object" && typeof r != "function" && r != null)
1242
+ throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");
1243
+ this.updater.enqueueSetState(this, r, t, "setState");
1244
+ };
1245
+ E.prototype.forceUpdate = function(r) {
1246
+ this.updater.enqueueForceUpdate(this, r, "forceUpdate");
1247
+ };
1248
+ function F() {
1249
+ }
1250
+ F.prototype = E.prototype;
1251
+ function G(r, t, n) {
1252
+ this.props = r, this.context = t, this.refs = D, this.updater = n || B;
1253
+ }
1254
+ var H = G.prototype = new F();
1255
+ H.constructor = G;
1256
+ C(H, E.prototype);
1257
+ H.isPureReactComponent = !0;
1258
+ const LoginRequired = ({ authenticationUrl: r }) => h(
1259
+ "div",
1260
+ { class: "login-required" },
1261
+ h(
1262
+ "div",
1263
+ { class: "card" },
1264
+ h("p", null, "Log into your account to use the Scheduler Editor."),
1265
+ h(
1266
+ "button",
1267
+ { class: "google-button", onClick: async (t) => {
1268
+ t.preventDefault();
1269
+ const n = await r("google");
1270
+ n ? window.location.href = n : console.error("[nylas-scheduler-editor] Unable to get authentication URL.");
1271
+ } },
1272
+ h(
1273
+ "span",
1274
+ { class: "icon" },
1275
+ h("google-logo-icon", { width: "15", height: "15" })
1276
+ ),
1277
+ "Continue with Google"
1278
+ ),
1279
+ h(
1280
+ "button",
1281
+ { class: "microsoft-button", onClick: async (t) => {
1282
+ t.preventDefault();
1283
+ const n = await r("microsoft");
1284
+ n ? window.location.href = n : console.error("[nylas-scheduler-editor] Unable to get authentication URL.");
1285
+ } },
1286
+ h(
1287
+ "span",
1288
+ { class: "icon" },
1289
+ h("microsoft-logo-icon", { width: "15", height: "15" })
1290
+ ),
1291
+ "Continue with Microsoft"
1292
+ ),
1293
+ h(
1294
+ "button",
1295
+ { class: "other-provider-button", onClick: async (t) => {
1296
+ t.preventDefault();
1297
+ const n = await r();
1298
+ n ? window.location.href = n : console.error("[nylas-scheduler-editor] Unable to get authentication URL.");
1299
+ } },
1300
+ "View all providers ",
1301
+ h("chevron-icon", { width: "17", height: "17" })
1302
+ ),
1303
+ h("small", { class: "disclaimer-text" }, "* You will be redirected to authenticate your account.")
1304
+ )
1305
+ ), nylasSchedulerEditorCss = ':host{display:flex;flex-direction:column;overflow:visible;border-radius:var(--nylas-border-radius-2x);width:fit-content;background:var(--nylas-base-0);position:relative;box-shadow:0px 4px 6px -2px rgba(0, 0, 0, 0.05), 0px 10px 15px -3px rgba(0, 0, 0, 0.1);--nylas-primary:#2563eb;--nylas-error:#cc4841;--nylas-error-pressed:#992222;--nylas-wraning:#f06c00;--nylas-success:#16a392;--nylas-info:#2b8fc2;--nylas-base-0:#ffffff;--nylas-base-25:#fcfcfd;--nylas-base-50:#f8f9fc;--nylas-base-100:#eaecf5;--nylas-base-200:#d5d9eb;--nylas-base-300:#b3b8d8;--nylas-base-400:#717bbc;--nylas-base-500:#4e5ba6;--nylas-base-600:#3e4784;--nylas-base-700:#263f72;--nylas-base-800:#293056;--nylas-base-900:#101323;--nylas-base-950:#0e101b;--nylas-border-radius:0.25rem;--nylas-border-radius-2x:0.5rem;--nylas-border-radius-3x:0.75rem;--nylas-font-family:"Inter", sans-serif}@media screen and (max-width: 768px){:host{width:auto;min-width:325px}}div.scheduler-editor-header{display:flex;align-items:center;justify-content:space-between;padding:1rem;border-bottom:1px solid var(--nylas-base-200);color:var(--nylas-base-900)}div.scheduler-editor-header h1.scheduler-editor-title{display:flex;align-items:center;gap:0.5rem;width:858px;margin:0;font-size:18px;line-height:24px;font-weight:600}@media screen and (max-width: 768px){div.scheduler-editor-header h1.scheduler-editor-title{width:auto;min-width:calc(325px - 1rem)}}div.scheduler-editor-header button{background:transparent;border:none;cursor:pointer}div.scheduler-editor-header button:hover,div.scheduler-editor-header button:active{color:var(--nylas-primary)}div.scheduler-editor-header button:disabled{cursor:not-allowed}nylas-editor-tabs{width:auto}nylas-editor-tabs nylas-event-info div[slot=inputs],nylas-editor-tabs nylas-event-limits div[slot=inputs]{display:flex;flex-direction:column;gap:1rem}.card{display:flex;flex-direction:column;padding:2rem;background-color:var(--nylas-base-0);border:1px solid var(--nylas-base-200);border-radius:5px;max-width:fit-content;align-self:center}.login-required{height:554px;overflow-y:auto;display:flex;flex-direction:column;justify-content:center;padding:2rem 1rem;background-color:var(--nylas-base-25)}@media screen and (max-width: 768px){.login-required{height:auto}}.login-required p{margin:0 0 1rem}.login-required .microsoft-button,.login-required .google-button{height:48px;border:1px solid var(--nylas-base-300);border-radius:var(--nylas-border-radius-2x);font-size:1rem;line-height:24px;padding:0 1rem;background-color:var(--nylas-base-0);font-weight:600;cursor:pointer;display:flex;margin-bottom:1rem;background-color:var(--nylas-base-0);border:1px solid var(--nylas-base-200);border-radius:5px;justify-content:center;gap:0.5rem;align-items:center}.login-required .microsoft-button:hover,.login-required .google-button:hover{background-color:var(--nylas-base-25)}.login-required .microsoft-button:hover,.login-required .google-button:hover{background-color:var(--nylas-base-25)}.login-required .other-provider-button{height:48px;border:1px solid var(--nylas-base-300);border-radius:var(--nylas-border-radius-2x);font-size:1rem;line-height:24px;padding:0 1rem;background-color:var(--nylas-base-0);font-weight:600;cursor:pointer;display:flex;border:0;background-color:var(--nylas-base-0);height:48px;margin-bottom:1rem;font-size:0.95rem;justify-content:center;gap:0.25rem;align-items:center}.login-required .other-provider-button:hover{background-color:var(--nylas-base-25)}.login-required .other-provider-button svg{transform:rotate(180deg)}.login-required .other-provider-button:hover{background-color:var(--nylas-base-25)}.login-required .disclaimer-text{font-size:0.75rem;color:var(--nylas-base-600);align-self:center}.list-configurations{padding:2rem;height:554px;background:var(--nylas-base-25)}@media screen and (max-width: 768px){.list-configurations{height:auto}}.list-configurations nylas-list-configurations{height:inherit;display:flex;flex-direction:column}', NylasSchedulerEditorStyle0 = nylasSchedulerEditorCss, NylasSchedulerEditor = class {
1306
+ constructor(r) {
1307
+ registerInstance(this, r), this.init = createEvent(this, "init", 7), this.loggedIn = createEvent(this, "loggedIn", 7), this.loggedOut = createEvent(this, "loggedOut", 7), this.schedulerConfigCloseClicked = createEvent(this, "schedulerConfigCloseClicked", 7), this.handleSchedulerConfigCloseClicked = (t) => {
1308
+ this.schedulerConfigCloseClicked.emit(this.host);
1309
+ }, this.authenticationUrl = async (t) => this.nylasApiRequest ? await this.nylasApiRequest.authenticationUrl({ provider: t }) || "" : (console.error("[nylas-scheduler-editor] Nylas API Request is not initialized."), ""), this.configurationId = void 0, this.nylasApiRequest = void 0, this.nylasSessionsConfig = void 0, this.defaultAuthArgs = void 0, this.eventOverrides = {}, this.schedulerPreviewLink = "", this.defaultSchedulerConfigState = void 0, this.mode = "app", this.automaticComponentRegistration = !0;
1310
+ }
1311
+ connectedCallback() {
1312
+ debug("[nylas-scheduler-editor] connectedCallback");
1313
+ }
1314
+ async componentWillLoad() {
1315
+ var n, s, c, a, d, l, u;
1316
+ if (debug("[nylas-scheduler-editor] componentWillLoad"), this.stores = {
1317
+ schedulerConfig: CreateNylasSchedulerConfigStore({
1318
+ ...this.defaultSchedulerConfigState
1319
+ })
1320
+ }, !this.nylasApiRequest && this.nylasSessionsConfig) {
1321
+ const f = new NylasSessions(this.nylasSessionsConfig);
1322
+ await f.isLoggedIn(), f.onLoginSuccess(async () => {
1323
+ var y, w;
1324
+ const g = await ((w = (y = this.nylasSchedulerConfigConnector) == null ? void 0 : y.schedulerConfig) == null ? void 0 : w.currentUser());
1325
+ g && (this.loggedIn.emit(this.host), this.loggedInHandler(g));
1326
+ }), f.onLoginFail(async () => {
1327
+ var g, y;
1328
+ (y = (g = this.stores) == null ? void 0 : g.schedulerConfig) == null || y.set("currentUser", null), this.loggedOut.emit(this.host);
1329
+ }), this.nylasApiRequest = new NylasIdentityRequestWrapper(f);
1330
+ }
1331
+ this.nylasApiRequest && this.defaultAuthArgs && this.nylasApiRequest.setDefaultAuthArgs(this.defaultAuthArgs), this.baseProvider = new NylasBaseProvider(this.host, this.stores, this.automaticComponentRegistration, this.eventOverrides);
1332
+ const r = this.baseProvider.getStore("schedulerConfig");
1333
+ if (this.nylasSchedulerConfigConnector = new NylasSchedulerConfigConnector({
1334
+ nylasApiRequest: this.nylasApiRequest,
1335
+ nylasSchedulerConfigStore: r
1336
+ }), !this.init.emit(this.host).defaultPrevented) {
1337
+ const f = await ((s = (n = this.nylasSchedulerConfigConnector) == null ? void 0 : n.schedulerConfig) == null ? void 0 : s.currentUser());
1338
+ f ? (this.loggedIn.emit(this.host), await this.loggedInHandler(f)) : ((a = (c = this.stores) == null ? void 0 : c.schedulerConfig) == null || a.set("currentUser", null), this.loggedOut.emit(this.host));
1339
+ }
1340
+ (l = (d = this.stores) == null ? void 0 : d.schedulerConfig) == null || l.onChange("selectedConfiguration", async (f) => {
1341
+ f && f.id && (this.configurationId = f.id);
1342
+ }), (u = this.baseProvider) == null || u.componentWillLoad(this.nylasSchedulerConfigConnector);
1343
+ }
1344
+ async componentDidLoad() {
1345
+ var r;
1346
+ debug("[nylas-scheduler-editor] componentDidLoad"), (r = this.baseProvider) == null || r.componentDidLoad();
1347
+ }
1348
+ componentDisconnected() {
1349
+ var r;
1350
+ (r = this.baseProvider) == null || r.componentDisconnected();
1351
+ }
1352
+ async configurationIdChanged(r) {
1353
+ var t, n, s, c, a, d, l, u;
1354
+ r ? (await ((n = (t = this.nylasSchedulerConfigConnector) == null ? void 0 : t.schedulerConfig) == null ? void 0 : n.getConfigurationById(r)), (c = (s = this.stores) == null ? void 0 : s.schedulerConfig) == null || c.set("action", "edit")) : ((d = (a = this.stores) == null ? void 0 : a.schedulerConfig) == null || d.set("selectedConfiguration", {}), (u = (l = this.stores) == null ? void 0 : l.schedulerConfig) == null || u.set("action", null));
1355
+ }
1356
+ async store() {
1357
+ var r;
1358
+ return (r = this.stores) == null ? void 0 : r.schedulerConfig;
1359
+ }
1360
+ async schedulerConnector() {
1361
+ return this.nylasSchedulerConfigConnector;
1362
+ }
1363
+ async registerComponentHandler(r) {
1364
+ var t;
1365
+ (t = this.baseProvider) == null || t.registerComponent(r.detail);
1366
+ }
1367
+ async unregisterComponentHandler(r) {
1368
+ var t;
1369
+ (t = this.baseProvider) == null || t.unregisterComponent(r.detail);
1370
+ }
1371
+ async loggedInHandler(r) {
1372
+ var t, n, s, c;
1373
+ (n = (t = this.stores) == null ? void 0 : t.schedulerConfig) == null || n.set("currentUser", r), this.nylasSchedulerConfigConnector && (this.configurationId && await ((s = this.nylasSchedulerConfigConnector.schedulerConfig) == null ? void 0 : s.getConfigurationById(this.configurationId)), await ((c = this.nylasSchedulerConfigConnector.schedulerConfig) == null ? void 0 : c.getCalendars()));
1374
+ }
1375
+ render() {
1376
+ var r, t, n, s, c, a, d, l;
1377
+ return h(Host, { key: "3c990c6167ba6e5913c2c0389ca7765f8d036abc" }, h("div", { key: "c4bded9f12b1d13892b405dd3d0210f1becce497", class: "scheduler-editor-header", part: "nse__header" }, h("h1", { key: "28d2f14a1d2ee9de3a6afb6b19d38a483ec3e900", class: "scheduler-editor-title", part: "nse__title" }, h("calendar-icon", { key: "d0ad4ea0bb536139e44193f720ba21d81f536c58", width: "18", height: "18" }), "Scheduler editor"), h("button", { key: "3dc7ee50b862662adc1379631cafb5c4bfe05379", class: "scheduler-editor-close", onClick: (u) => this.handleSchedulerConfigCloseClicked(u), part: "nse__close-button" }, h("close-icon", { key: "680cbbe8436d0ba6bf4a64198c7aa8abc21f0938", width: "18", height: "18" }))), ((t = (r = this.stores) == null ? void 0 : r.schedulerConfig) == null ? void 0 : t.state.currentUser) && this.stores.schedulerConfig.state.action === null && h("div", { class: "list-configurations" }, h("nylas-list-configurations", null)), ((s = (n = this.stores) == null ? void 0 : n.schedulerConfig) == null ? void 0 : s.state.currentUser) && this.stores.schedulerConfig.state.action === "create" && h("nylas-editor-tabs", { mode: "composable" }, h("nylas-event-info", null, h("div", { slot: "inputs" }, h("nylas-event-title", null), h("nylas-event-duration", null), h("nylas-location-component", null))), h("nylas-booking-calendar-picker", null)), ((a = (c = this.stores) == null ? void 0 : c.schedulerConfig) == null ? void 0 : a.state.currentUser) && this.stores.schedulerConfig.state.action === "edit" && h("nylas-editor-tabs", { mode: this.mode }, this.mode === "composable" && h("slot", null)), !((l = (d = this.stores) == null ? void 0 : d.schedulerConfig) != null && l.state.currentUser) && h("slot", { name: "login-required" }, h(LoginRequired, { authenticationUrl: this.authenticationUrl })));
1378
+ }
1379
+ get host() {
1380
+ return getElement(this);
1381
+ }
1382
+ static get watchers() {
1383
+ return {
1384
+ configurationId: ["configurationIdChanged"]
1385
+ };
1386
+ }
1387
+ };
1388
+ NylasSchedulerEditor.style = NylasSchedulerEditorStyle0;
1389
+ export {
1390
+ NylasSchedulerEditor as nylas_scheduler_editor
1391
+ };