@nylas/react 1.1.0-canary.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/README.md +110 -2
  2. package/dist/add-circle-icon_2.entry-7165bd0e.js +25 -0
  3. package/dist/add-circle-icon_2.entry-f1ddca18.cjs +1 -0
  4. package/dist/{archive-icon_7.entry-e2954750.js → archive-icon_7.entry-7411c224.js} +16 -16
  5. package/dist/archive-icon_7.entry-e3df60ed.cjs +1 -0
  6. package/dist/{arrow-icon.entry-548b027e.cjs → arrow-icon.entry-280e18b0.cjs} +1 -1
  7. package/dist/{arrow-icon.entry-03a85113.js → arrow-icon.entry-38949317.js} +4 -4
  8. package/dist/{bold-icon_3.entry-70ffa7f0.js → bold-icon_3.entry-5963945c.js} +4 -4
  9. package/dist/{bold-icon_3.entry-9a7b1869.cjs → bold-icon_3.entry-5dffbedd.cjs} +1 -1
  10. package/dist/button-component_2.entry-237733b4.js +26 -0
  11. package/dist/button-component_2.entry-b29d2873.cjs +1 -0
  12. package/dist/calendar-agenda-fill-icon_48.entry-9afba869.js +5105 -0
  13. package/dist/calendar-agenda-fill-icon_48.entry-d3830dbb.cjs +7 -0
  14. package/dist/{calendar-cancel-icon.entry-45388fdc.cjs → calendar-cancel-icon.entry-77ccf227.cjs} +1 -1
  15. package/dist/{calendar-cancel-icon.entry-6bbc119f.js → calendar-cancel-icon.entry-780723a6.js} +5 -5
  16. package/dist/{calendar-check-icon_2.entry-f633f7a6.js → calendar-check-icon_2.entry-2c89c230.js} +7 -7
  17. package/dist/{calendar-check-icon_2.entry-6628456c.cjs → calendar-check-icon_2.entry-b37ac7f0.cjs} +1 -1
  18. package/dist/{calendar-icon.entry-62b82c27.js → calendar-icon.entry-02dd3990.js} +4 -4
  19. package/dist/{calendar-icon.entry-379b1fa1.cjs → calendar-icon.entry-ffc93569.cjs} +1 -1
  20. package/dist/checkbox-component_2.entry-00b6a1e9.cjs +1 -0
  21. package/dist/checkbox-component_2.entry-ee9d0e6c.js +56 -0
  22. package/dist/chevron-icon_3.entry-468abc26.cjs +1 -0
  23. package/dist/chevron-icon_3.entry-f62e9ef1.js +129 -0
  24. package/dist/clock-icon_4.entry-766a1b23.js +45 -0
  25. package/dist/clock-icon_4.entry-7dc2cc4a.cjs +1 -0
  26. package/dist/{constants-f34b9c6e-95a17764.js → constants-50c3e067-8a40a5fe.js} +885 -751
  27. package/dist/{constants-f34b9c6e-e7137e51.cjs → constants-50c3e067-9f2a6372.cjs} +5 -5
  28. package/dist/copy-icon.entry-2a841508.js +15 -0
  29. package/dist/copy-icon.entry-e5251410.cjs +1 -0
  30. package/dist/delete-icon_2.entry-1a5c39dc.cjs +1 -0
  31. package/dist/delete-icon_2.entry-64555a2f.js +25 -0
  32. package/dist/{document-refresh-icon.entry-32c75418.js → document-refresh-icon.entry-4bf6398b.js} +4 -4
  33. package/dist/document-refresh-icon.entry-fdc7ddda.cjs +1 -0
  34. package/dist/elements/index.d.ts +47 -1
  35. package/dist/{elements-dc5b338e-62fe1cf3.js → elements-dc5b338e-2da1fe61.js} +1 -1
  36. package/dist/{elements-dc5b338e-1f23530f.cjs → elements-dc5b338e-c8016c3d.cjs} +1 -1
  37. package/dist/{focus-visible-e8093c16-f0f05815.cjs → focus-visible-e8093c16-0a38a184.cjs} +1 -1
  38. package/dist/{focus-visible-e8093c16-1f664070.js → focus-visible-e8093c16-9d0c98c0.js} +1 -1
  39. package/dist/{forward-icon_6.entry-7fab04d7.js → forward-icon_6.entry-390ef70a.js} +9 -9
  40. package/dist/{forward-icon_6.entry-ef5e2e0f.cjs → forward-icon_6.entry-7238ef38.cjs} +3 -3
  41. package/dist/{globe-icon.entry-398a9826.cjs → globe-icon.entry-81f42f89.cjs} +1 -1
  42. package/dist/{globe-icon.entry-b8e1efae.js → globe-icon.entry-8d106260.js} +5 -5
  43. package/dist/google-logo-icon_4.entry-aabd3886.js +680 -0
  44. package/dist/google-logo-icon_4.entry-fa2b8999.cjs +1 -0
  45. package/dist/index-53420959-5fc8ad2b.js +5 -0
  46. package/dist/index-53420959-fcf45780.cjs +1 -0
  47. package/dist/index-5ccfd9df.js +7859 -0
  48. package/dist/index-6d9eeb53-58c8980a.js +4971 -0
  49. package/dist/index-6d9eeb53-b2a6d09f.cjs +41 -0
  50. package/dist/index-eb33703c.cjs +42 -0
  51. package/dist/{index.es-df564f87-b773d34f.js → index.es-c9454237-00ccd1e6.js} +6 -8
  52. package/dist/{index.es-df564f87-e4a4092a.cjs → index.es-c9454237-b64161d1.cjs} +6 -6
  53. package/dist/{info-icon_2.entry-2eb70f49.cjs → info-icon_2.entry-b2e11336.cjs} +1 -1
  54. package/dist/{info-icon_2.entry-6bbfa6dc.js → info-icon_2.entry-bb8ed71c.js} +3 -3
  55. package/dist/input-component.entry-378b1ccc.cjs +1 -0
  56. package/dist/input-component.entry-cb86170f.js +65 -0
  57. package/dist/input-dropdown.entry-98954c93.cjs +1 -0
  58. package/dist/input-dropdown.entry-a76c339e.js +134 -0
  59. package/dist/{mailbox-store-69c5c5f6-631eddb5.cjs → mailbox-store-edc386fc-156b7236.cjs} +1 -1
  60. package/dist/{mailbox-store-69c5c5f6-8ab4670b.js → mailbox-store-edc386fc-8bc7558b.js} +2 -2
  61. package/dist/multi-select-dropdown.entry-40b855e1.cjs +1 -0
  62. package/dist/multi-select-dropdown.entry-6b686695.js +91 -0
  63. package/dist/nylas-booked-event-card_12.entry-9d693125.cjs +1 -0
  64. package/dist/nylas-booked-event-card_12.entry-e861bb16.js +1134 -0
  65. package/dist/nylas-form-card.entry-b158d789.js +57 -0
  66. package/dist/nylas-form-card.entry-ca4a8746.cjs +1 -0
  67. package/dist/{nylas-if-state.entry-f8abd025.js → nylas-if-state.entry-8e4d922c.js} +8 -8
  68. package/dist/{nylas-if-state.entry-276d61ad.cjs → nylas-if-state.entry-95fac42d.cjs} +1 -1
  69. package/dist/{nylas-list-folders.entry-78cc680e.js → nylas-list-folders.entry-83c39684.js} +8 -8
  70. package/dist/{nylas-list-folders.entry-afe02f0e.cjs → nylas-list-folders.entry-8a22e0c8.cjs} +1 -1
  71. package/dist/{nylas-list-threads.entry-6395c12f.cjs → nylas-list-threads.entry-54c582af.cjs} +1 -1
  72. package/dist/{nylas-list-threads.entry-217088de.js → nylas-list-threads.entry-7ea370e1.js} +4 -4
  73. package/dist/{nylas-login.entry-e4d57589.js → nylas-login.entry-9115fd81.js} +7 -7
  74. package/dist/{nylas-login.entry-ec81e21b.cjs → nylas-login.entry-fb627e40.cjs} +1 -1
  75. package/dist/{nylas-mailbox-pagination.entry-d4d929f1.cjs → nylas-mailbox-pagination.entry-04626d27.cjs} +1 -1
  76. package/dist/{nylas-mailbox-pagination.entry-069673aa.js → nylas-mailbox-pagination.entry-3ff02cf9.js} +2 -2
  77. package/dist/{nylas-mailbox-toolbar-button.entry-2b9e4431.cjs → nylas-mailbox-toolbar-button.entry-8d00c789.cjs} +1 -1
  78. package/dist/{nylas-mailbox-toolbar-button.entry-03c5f5c8.js → nylas-mailbox-toolbar-button.entry-f752e925.js} +4 -4
  79. package/dist/{nylas-mailbox.entry-7e6b4791.js → nylas-mailbox.entry-99c27b6c.js} +4 -4
  80. package/dist/{nylas-mailbox.entry-1342178d.cjs → nylas-mailbox.entry-b3974f4e.cjs} +1 -1
  81. package/dist/{nylas-provider.entry-0ae8e70a.cjs → nylas-provider.entry-a3ad02a5.cjs} +1 -1
  82. package/dist/{nylas-provider.entry-498a7be9.js → nylas-provider.entry-c206aa32.js} +39 -39
  83. package/dist/nylas-reminder-emails.entry-414ce6fe.js +129 -0
  84. package/dist/nylas-reminder-emails.entry-59c07bfe.cjs +4 -0
  85. package/dist/nylas-reminder-time_2.entry-197d83a0.js +105 -0
  86. package/dist/nylas-reminder-time_2.entry-d79dcd85.cjs +1 -0
  87. package/dist/nylas-scheduler-editor.entry-7f389982.js +1447 -0
  88. package/dist/nylas-scheduler-editor.entry-f1c6964a.cjs +2 -0
  89. package/dist/nylas-scheduling.entry-1a8bd6fc.cjs +1 -0
  90. package/dist/nylas-scheduling.entry-4fa5381d.js +345 -0
  91. package/dist/{nylas-threads-refresh.entry-fc2d8028.js → nylas-threads-refresh.entry-20602e7b.js} +4 -4
  92. package/dist/{nylas-threads-refresh.entry-d020c89e.cjs → nylas-threads-refresh.entry-56b53449.cjs} +1 -1
  93. package/dist/{nylas-threads-search.entry-f92f7e30.js → nylas-threads-search.entry-8872473c.js} +12 -12
  94. package/dist/{nylas-threads-search.entry-0abcbc10.cjs → nylas-threads-search.entry-8e0ec3ae.cjs} +1 -1
  95. package/dist/nylas-time-window-picker.entry-9ac542b7.js +316 -0
  96. package/dist/nylas-time-window-picker.entry-ca47f721.cjs +1 -0
  97. package/dist/{nylas-view-thread.entry-56080c89.cjs → nylas-view-thread.entry-1f758e43.cjs} +1 -1
  98. package/dist/{nylas-view-thread.entry-2f1474cf.js → nylas-view-thread.entry-dcd3d5be.js} +6 -6
  99. package/dist/person-icon.entry-63b28ace.cjs +1 -0
  100. package/dist/person-icon.entry-93130c05.js +15 -0
  101. package/dist/{play-icon_2.entry-24ffa01f.js → play-icon_2.entry-6a99c32d.js} +6 -6
  102. package/dist/play-icon_2.entry-b67fb649.cjs +1 -0
  103. package/dist/react.cjs +1 -1
  104. package/dist/react.js +136 -90
  105. package/dist/{refresh-icon.entry-8395104b.js → refresh-icon.entry-84783c91.js} +4 -4
  106. package/dist/{refresh-icon.entry-cf4416b8.cjs → refresh-icon.entry-b49792fc.cjs} +1 -1
  107. package/dist/{register-component-b9cfcbaf-d40e1f3c.cjs → register-component-887199a9-003f96c5.cjs} +1 -1
  108. package/dist/{register-component-b9cfcbaf-c0147194.js → register-component-887199a9-b41dfa7a.js} +1 -1
  109. package/dist/scheduler-config-store-2a3b403d-73610089.js +27 -0
  110. package/dist/scheduler-config-store-2a3b403d-a5e3433a.cjs +1 -0
  111. package/dist/scheduler-store-fe281404-bddb1b6a.js +469 -0
  112. package/dist/scheduler-store-fe281404-c3e477f6.cjs +1 -0
  113. package/dist/textarea-component.entry-28c4bc05.cjs +1 -0
  114. package/dist/textarea-component.entry-40e959e5.js +36 -0
  115. package/dist/time-period-selector.entry-af71523a.cjs +1 -0
  116. package/dist/time-period-selector.entry-da5d8652.js +93 -0
  117. package/dist/{translate-icon.entry-d847f706.js → translate-icon.entry-92b83635.js} +5 -5
  118. package/dist/{translate-icon.entry-66533238.cjs → translate-icon.entry-a2ed4f76.cjs} +1 -1
  119. package/dist/warning-icon.entry-19f721c3.js +15 -0
  120. package/dist/warning-icon.entry-3ab9a59e.cjs +1 -0
  121. package/package.json +3 -3
  122. package/dist/add-circle-icon_22.entry-080abc71.cjs +0 -1
  123. package/dist/add-circle-icon_22.entry-bda9be31.js +0 -1818
  124. package/dist/archive-icon_7.entry-ca20da59.cjs +0 -1
  125. package/dist/chevron-icon_3.entry-74425e1f.js +0 -117
  126. package/dist/chevron-icon_3.entry-7ff803ad.cjs +0 -1
  127. package/dist/close-icon.entry-18e140ed.cjs +0 -1
  128. package/dist/close-icon.entry-6a8ea4a7.js +0 -15
  129. package/dist/document-refresh-icon.entry-f15f795a.cjs +0 -1
  130. package/dist/google-logo-icon_4.entry-38d5c2f2.cjs +0 -1
  131. package/dist/google-logo-icon_4.entry-5eca9538.js +0 -381
  132. package/dist/index-93c50de4.cjs +0 -37
  133. package/dist/index-f93f6948.js +0 -4006
  134. package/dist/loading-icon.entry-b563b2e6.js +0 -15
  135. package/dist/loading-icon.entry-fb04b893.cjs +0 -1
  136. package/dist/nylas-additional-participants.entry-33a45477.cjs +0 -1
  137. package/dist/nylas-additional-participants.entry-4b214308.js +0 -81
  138. package/dist/nylas-booked-event-card_10.entry-3e225025.cjs +0 -1
  139. package/dist/nylas-booked-event-card_10.entry-e93bc290.js +0 -782
  140. package/dist/nylas-form-card.entry-0748fdd5.js +0 -54
  141. package/dist/nylas-form-card.entry-eb3607bc.cjs +0 -1
  142. package/dist/nylas-scheduler-editor.entry-4de2bb97.js +0 -2275
  143. package/dist/nylas-scheduler-editor.entry-72c91b7d.cjs +0 -7
  144. package/dist/nylas-scheduling.entry-1a004916.cjs +0 -1
  145. package/dist/nylas-scheduling.entry-4e18ab43.js +0 -235
  146. package/dist/people-icon.entry-431e5044.cjs +0 -1
  147. package/dist/people-icon.entry-b4778e15.js +0 -15
  148. package/dist/play-icon_2.entry-f97db395.cjs +0 -1
  149. package/dist/scheduler-config-store-07d98279-0610e42f.cjs +0 -1
  150. package/dist/scheduler-config-store-07d98279-3b70606c.js +0 -24
  151. package/dist/scheduler-store-24fd0e91-2dba20c2.cjs +0 -1
  152. package/dist/scheduler-store-24fd0e91-47098841.js +0 -302
  153. package/dist/time-period-selector.entry-1e849c2e.js +0 -76
  154. package/dist/time-period-selector.entry-d8f3462f.cjs +0 -1
  155. package/dist/warning-icon.entry-1f0f00ed.cjs +0 -1
  156. package/dist/warning-icon.entry-b5db0151.js +0 -15
@@ -1,2275 +0,0 @@
1
- var P = Object.defineProperty;
2
- var O = (n, t, r) => t in n ? P(n, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : n[t] = r;
3
- var m = (n, t, r) => (O(n, typeof t != "symbol" ? t + "" : t, r), r);
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-f93f6948.js";
5
- import { N as NylasBaseProvider, X as Xr, g as global$1 } from "./index.es-df564f87-b773d34f.js";
6
- import { C as CreateNylasSchedulerConfigStore } from "./scheduler-config-store-07d98279-3b70606c.js";
7
- import "react";
8
- import "react-dom";
9
- class NylasSchedulerConfigAPIConnector {
10
- constructor({ nylasApiRequest: t, nylasSchedulerConfigStore: r }) {
11
- this.nylasApiRequest = t, this.nylasSchedulerConfigStore = r;
12
- }
13
- async currentUser() {
14
- return this.nylasApiRequest ? this.nylasApiRequest.currentUser() : (console.warn("Nylas API Request is not initialized"), null);
15
- }
16
- async getCalendars() {
17
- var s;
18
- if (!this.nylasApiRequest)
19
- return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
20
- message: "Error fetching calendars: Nylas API Request is not initialized"
21
- });
22
- const [t, r] = await this.nylasApiRequest.request({
23
- method: "GET",
24
- path: "calendars"
25
- });
26
- return r ? dataResponse(null, {
27
- message: "Error fetching calendars: " + r.message
28
- }) : Xr(t) ? dataResponse(null, {
29
- message: "Error fetching calendars: " + ((s = t.error) == null ? void 0 : s.message)
30
- }) : (this.nylasSchedulerConfigStore.state.calendars = t.data, dataResponse(t.data));
31
- }
32
- async getConfigurationById(t, r = !1) {
33
- var c;
34
- if (!this.nylasApiRequest)
35
- return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
36
- message: "Error fetching configuration: Nylas API Request is not initialized"
37
- });
38
- if (!r) {
39
- const u = this.nylasSchedulerConfigStore.state.configurations.find((l) => l.id === t);
40
- if (u)
41
- return this.nylasSchedulerConfigStore.state.selectedConfiguration = u, dataResponse(u);
42
- }
43
- const [s, a] = await this.nylasApiRequest.request({
44
- method: "GET",
45
- path: `scheduling/configurations/${t}`
46
- });
47
- return a ? dataResponse(null, {
48
- message: "Error fetching configuration: " + a.message
49
- }) : Xr(s) ? dataResponse(null, {
50
- message: "Error fetching configuration: " + ((c = s.error) == null ? void 0 : c.message)
51
- }) : (this.nylasSchedulerConfigStore.state.selectedConfiguration = s.data, this.nylasSchedulerConfigStore.state.configurations.find((u) => u.id === t) ? this.nylasSchedulerConfigStore.state.configurations = this.nylasSchedulerConfigStore.state.configurations.map((u) => u.id === t ? s.data : u) : this.nylasSchedulerConfigStore.state.configurations = [...this.nylasSchedulerConfigStore.state.configurations, s.data], dataResponse(s.data));
52
- }
53
- async getConfigurations() {
54
- var s;
55
- if (!this.nylasApiRequest)
56
- return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
57
- message: "Error fetching configurations: Nylas API Request is not initialized"
58
- });
59
- const [t, r] = await this.nylasApiRequest.request({
60
- method: "GET",
61
- path: "scheduling/configurations"
62
- });
63
- return r ? dataResponse(null, {
64
- message: "Error fetching configurations: " + r.message
65
- }) : Xr(t) ? dataResponse(null, {
66
- message: "Error fetching configurations: " + ((s = t.error) == null ? void 0 : s.message)
67
- }) : (this.nylasSchedulerConfigStore.state.configurations = t.data, dataResponse(t.data));
68
- }
69
- async createConfiguration(t) {
70
- var a;
71
- if (!this.nylasApiRequest)
72
- return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
73
- message: "Error creating configuration: Nylas API Request is not initialized"
74
- });
75
- t.requires_session_auth = this.nylasSchedulerConfigStore.state.defaultRequiresSessionAuth;
76
- const [r, s] = await this.nylasApiRequest.request({
77
- method: "POST",
78
- path: "scheduling/configurations",
79
- body: t
80
- });
81
- return s ? dataResponse(null, {
82
- message: "Error creating configuration: " + s.message
83
- }) : Xr(r) ? dataResponse(null, {
84
- message: "Error creating configuration: " + ((a = r.error) == null ? void 0 : a.message)
85
- }) : (this.nylasSchedulerConfigStore.state.selectedConfiguration = r.data, this.nylasSchedulerConfigStore.state.configurations = [...this.nylasSchedulerConfigStore.state.configurations, r.data], dataResponse(r.data));
86
- }
87
- async updateConfiguration(t) {
88
- var a;
89
- if (!this.nylasApiRequest)
90
- return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
91
- message: "Error updating configuration: Nylas API Request is not initialized"
92
- });
93
- const [r, s] = await this.nylasApiRequest.request({
94
- method: "PUT",
95
- path: `scheduling/configurations/${t.id}`,
96
- body: t
97
- });
98
- return s ? dataResponse(null, {
99
- message: "Error updating configuration: " + s.message
100
- }) : Xr(r) ? dataResponse(null, {
101
- message: "Error updating configuration: " + ((a = r.error) == null ? void 0 : a.message)
102
- }) : (this.nylasSchedulerConfigStore.state.selectedConfiguration = r.data, this.nylasSchedulerConfigStore.state.configurations.find((c) => c.id === t.id) ? this.nylasSchedulerConfigStore.state.configurations = this.nylasSchedulerConfigStore.state.configurations.map((c) => c.id === t.id ? r.data : c) : this.nylasSchedulerConfigStore.state.configurations = [...this.nylasSchedulerConfigStore.state.configurations, r.data], dataResponse(r.data));
103
- }
104
- async deleteConfiguration(t) {
105
- var a, c;
106
- if (!this.nylasApiRequest)
107
- return console.warn("Nylas API Request is not initialized"), dataResponse(null, {
108
- message: "Error deleting configuration: Nylas API Request is not initialized"
109
- });
110
- const [r, s] = await this.nylasApiRequest.request({
111
- method: "DELETE",
112
- path: `scheduling/configurations/${t}`
113
- });
114
- return s ? dataResponse(null, {
115
- message: "Error deleting configuration: " + s.message
116
- }) : Xr(r) ? dataResponse(null, {
117
- message: "Error deleting configuration: " + ((a = r.error) == null ? void 0 : a.message)
118
- }) : (this.nylasSchedulerConfigStore.state.configurations = this.nylasSchedulerConfigStore.state.configurations.filter((u) => u.id !== t), ((c = this.nylasSchedulerConfigStore.state.selectedConfiguration) == null ? void 0 : c.id) === t && this.nylasSchedulerConfigStore.resetSelectedConfiguration(), dataResponse(r.data));
119
- }
120
- }
121
- class NylasSchedulerConfigConnector {
122
- constructor({ nylasApiRequest: t, nylasSchedulerConfigStore: r }) {
123
- this.nylasApiRequest = t, this.nylasSchedulerConfigStore = r;
124
- }
125
- init() {
126
- debug("NylasSchedulerConfigConnector init");
127
- }
128
- get schedulerConfigStore() {
129
- return this.nylasSchedulerConfigStore;
130
- }
131
- get schedulerConfig() {
132
- return this._schedulerConfigConnector ? this._schedulerConfigConnector : (this._schedulerConfigConnector = new NylasSchedulerConfigAPIConnector({
133
- nylasApiRequest: this.nylasApiRequest,
134
- nylasSchedulerConfigStore: this.nylasSchedulerConfigStore
135
- }), this._schedulerConfigConnector);
136
- }
137
- resetStores() {
138
- debug("NylasSchedulerConfigConnector resetStores"), this.nylasSchedulerConfigStore.reset();
139
- }
140
- async logout() {
141
- debug("NylasSchedulerConfigConnector logout"), this.resetStores();
142
- }
143
- }
144
- var lookup = [], revLookup = [], Arr = typeof Uint8Array < "u" ? Uint8Array : Array, inited = !1;
145
- function init() {
146
- inited = !0;
147
- for (var n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", t = 0, r = n.length; t < r; ++t)
148
- lookup[t] = n[t], revLookup[n.charCodeAt(t)] = t;
149
- revLookup["-".charCodeAt(0)] = 62, revLookup["_".charCodeAt(0)] = 63;
150
- }
151
- function toByteArray(n) {
152
- inited || init();
153
- var t, r, s, a, c, u, l = n.length;
154
- if (l % 4 > 0)
155
- throw new Error("Invalid string. Length must be a multiple of 4");
156
- c = n[l - 2] === "=" ? 2 : n[l - 1] === "=" ? 1 : 0, u = new Arr(l * 3 / 4 - c), s = c > 0 ? l - 4 : l;
157
- var f = 0;
158
- for (t = 0, r = 0; t < s; t += 4, r += 3)
159
- a = revLookup[n.charCodeAt(t)] << 18 | revLookup[n.charCodeAt(t + 1)] << 12 | revLookup[n.charCodeAt(t + 2)] << 6 | revLookup[n.charCodeAt(t + 3)], u[f++] = a >> 16 & 255, u[f++] = a >> 8 & 255, u[f++] = a & 255;
160
- return c === 2 ? (a = revLookup[n.charCodeAt(t)] << 2 | revLookup[n.charCodeAt(t + 1)] >> 4, u[f++] = a & 255) : c === 1 && (a = revLookup[n.charCodeAt(t)] << 10 | revLookup[n.charCodeAt(t + 1)] << 4 | revLookup[n.charCodeAt(t + 2)] >> 2, u[f++] = a >> 8 & 255, u[f++] = a & 255), u;
161
- }
162
- function tripletToBase64(n) {
163
- return lookup[n >> 18 & 63] + lookup[n >> 12 & 63] + lookup[n >> 6 & 63] + lookup[n & 63];
164
- }
165
- function encodeChunk(n, t, r) {
166
- for (var s, a = [], c = t; c < r; c += 3)
167
- s = (n[c] << 16) + (n[c + 1] << 8) + n[c + 2], a.push(tripletToBase64(s));
168
- return a.join("");
169
- }
170
- function fromByteArray(n) {
171
- inited || init();
172
- for (var t, r = n.length, s = r % 3, a = "", c = [], u = 16383, l = 0, f = r - s; l < f; l += u)
173
- c.push(encodeChunk(n, l, l + u > f ? f : l + u));
174
- return s === 1 ? (t = n[r - 1], a += lookup[t >> 2], a += lookup[t << 4 & 63], a += "==") : s === 2 && (t = (n[r - 2] << 8) + n[r - 1], a += lookup[t >> 10], a += lookup[t >> 4 & 63], a += lookup[t << 2 & 63], a += "="), c.push(a), c.join("");
175
- }
176
- function read(n, t, r, s, a) {
177
- var c, u, l = a * 8 - s - 1, f = (1 << l) - 1, d = f >> 1, g = -7, p = r ? a - 1 : 0, w = r ? -1 : 1, y = n[t + p];
178
- for (p += w, c = y & (1 << -g) - 1, y >>= -g, g += l; g > 0; c = c * 256 + n[t + p], p += w, g -= 8)
179
- ;
180
- for (u = c & (1 << -g) - 1, c >>= -g, g += s; g > 0; u = u * 256 + n[t + p], p += w, g -= 8)
181
- ;
182
- if (c === 0)
183
- c = 1 - d;
184
- else {
185
- if (c === f)
186
- return u ? NaN : (y ? -1 : 1) * (1 / 0);
187
- u = u + Math.pow(2, s), c = c - d;
188
- }
189
- return (y ? -1 : 1) * u * Math.pow(2, c - s);
190
- }
191
- function write(n, t, r, s, a, c) {
192
- var u, l, f, d = c * 8 - a - 1, g = (1 << d) - 1, p = g >> 1, w = a === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0, y = s ? 0 : c - 1, x = s ? 1 : -1, S = t < 0 || t === 0 && 1 / t < 0 ? 1 : 0;
193
- for (t = Math.abs(t), isNaN(t) || t === 1 / 0 ? (l = isNaN(t) ? 1 : 0, u = g) : (u = Math.floor(Math.log(t) / Math.LN2), t * (f = Math.pow(2, -u)) < 1 && (u--, f *= 2), u + p >= 1 ? t += w / f : t += w * Math.pow(2, 1 - p), t * f >= 2 && (u++, f /= 2), u + p >= g ? (l = 0, u = g) : u + p >= 1 ? (l = (t * f - 1) * Math.pow(2, a), u = u + p) : (l = t * Math.pow(2, p - 1) * Math.pow(2, a), u = 0)); a >= 8; n[r + y] = l & 255, y += x, l /= 256, a -= 8)
194
- ;
195
- for (u = u << a | l, d += a; d > 0; n[r + y] = u & 255, y += x, u /= 256, d -= 8)
196
- ;
197
- n[r + y - x] |= S * 128;
198
- }
199
- var toString = {}.toString, isArray = Array.isArray || function(n) {
200
- return toString.call(n) == "[object Array]";
201
- };
202
- /*!
203
- * The buffer module from node.js, for the browser.
204
- *
205
- * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
206
- * @license MIT
207
- */
208
- var INSPECT_MAX_BYTES = 50;
209
- Buffer.TYPED_ARRAY_SUPPORT = global$1.TYPED_ARRAY_SUPPORT !== void 0 ? global$1.TYPED_ARRAY_SUPPORT : !0;
210
- function kMaxLength() {
211
- return Buffer.TYPED_ARRAY_SUPPORT ? 2147483647 : 1073741823;
212
- }
213
- function createBuffer(n, t) {
214
- if (kMaxLength() < t)
215
- throw new RangeError("Invalid typed array length");
216
- return Buffer.TYPED_ARRAY_SUPPORT ? (n = new Uint8Array(t), n.__proto__ = Buffer.prototype) : (n === null && (n = new Buffer(t)), n.length = t), n;
217
- }
218
- function Buffer(n, t, r) {
219
- if (!Buffer.TYPED_ARRAY_SUPPORT && !(this instanceof Buffer))
220
- return new Buffer(n, t, r);
221
- if (typeof n == "number") {
222
- if (typeof t == "string")
223
- throw new Error(
224
- "If encoding is specified then the first argument must be a string"
225
- );
226
- return allocUnsafe(this, n);
227
- }
228
- return from(this, n, t, r);
229
- }
230
- Buffer.poolSize = 8192;
231
- Buffer._augment = function(n) {
232
- return n.__proto__ = Buffer.prototype, n;
233
- };
234
- function from(n, t, r, s) {
235
- if (typeof t == "number")
236
- throw new TypeError('"value" argument must not be a number');
237
- return typeof ArrayBuffer < "u" && t instanceof ArrayBuffer ? fromArrayBuffer(n, t, r, s) : typeof t == "string" ? fromString(n, t, r) : fromObject(n, t);
238
- }
239
- Buffer.from = function(n, t, r) {
240
- return from(null, n, t, r);
241
- };
242
- Buffer.TYPED_ARRAY_SUPPORT && (Buffer.prototype.__proto__ = Uint8Array.prototype, Buffer.__proto__ = Uint8Array);
243
- function assertSize(n) {
244
- if (typeof n != "number")
245
- throw new TypeError('"size" argument must be a number');
246
- if (n < 0)
247
- throw new RangeError('"size" argument must not be negative');
248
- }
249
- function alloc(n, t, r, s) {
250
- return assertSize(t), t <= 0 ? createBuffer(n, t) : r !== void 0 ? typeof s == "string" ? createBuffer(n, t).fill(r, s) : createBuffer(n, t).fill(r) : createBuffer(n, t);
251
- }
252
- Buffer.alloc = function(n, t, r) {
253
- return alloc(null, n, t, r);
254
- };
255
- function allocUnsafe(n, t) {
256
- if (assertSize(t), n = createBuffer(n, t < 0 ? 0 : checked(t) | 0), !Buffer.TYPED_ARRAY_SUPPORT)
257
- for (var r = 0; r < t; ++r)
258
- n[r] = 0;
259
- return n;
260
- }
261
- Buffer.allocUnsafe = function(n) {
262
- return allocUnsafe(null, n);
263
- };
264
- Buffer.allocUnsafeSlow = function(n) {
265
- return allocUnsafe(null, n);
266
- };
267
- function fromString(n, t, r) {
268
- if ((typeof r != "string" || r === "") && (r = "utf8"), !Buffer.isEncoding(r))
269
- throw new TypeError('"encoding" must be a valid string encoding');
270
- var s = byteLength(t, r) | 0;
271
- n = createBuffer(n, s);
272
- var a = n.write(t, r);
273
- return a !== s && (n = n.slice(0, a)), n;
274
- }
275
- function fromArrayLike(n, t) {
276
- var r = t.length < 0 ? 0 : checked(t.length) | 0;
277
- n = createBuffer(n, r);
278
- for (var s = 0; s < r; s += 1)
279
- n[s] = t[s] & 255;
280
- return n;
281
- }
282
- function fromArrayBuffer(n, t, r, s) {
283
- if (r < 0 || t.byteLength < r)
284
- throw new RangeError("'offset' is out of bounds");
285
- if (t.byteLength < r + (s || 0))
286
- throw new RangeError("'length' is out of bounds");
287
- return r === void 0 && s === void 0 ? t = new Uint8Array(t) : s === void 0 ? t = new Uint8Array(t, r) : t = new Uint8Array(t, r, s), Buffer.TYPED_ARRAY_SUPPORT ? (n = t, n.__proto__ = Buffer.prototype) : n = fromArrayLike(n, t), n;
288
- }
289
- function fromObject(n, t) {
290
- if (internalIsBuffer(t)) {
291
- var r = checked(t.length) | 0;
292
- return n = createBuffer(n, r), n.length === 0 || t.copy(n, 0, 0, r), n;
293
- }
294
- if (t) {
295
- if (typeof ArrayBuffer < "u" && t.buffer instanceof ArrayBuffer || "length" in t)
296
- return typeof t.length != "number" || isnan(t.length) ? createBuffer(n, 0) : fromArrayLike(n, t);
297
- if (t.type === "Buffer" && isArray(t.data))
298
- return fromArrayLike(n, t.data);
299
- }
300
- throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");
301
- }
302
- function checked(n) {
303
- if (n >= kMaxLength())
304
- throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x" + kMaxLength().toString(16) + " bytes");
305
- return n | 0;
306
- }
307
- Buffer.isBuffer = isBuffer;
308
- function internalIsBuffer(n) {
309
- return !!(n != null && n._isBuffer);
310
- }
311
- Buffer.compare = function(t, r) {
312
- if (!internalIsBuffer(t) || !internalIsBuffer(r))
313
- throw new TypeError("Arguments must be Buffers");
314
- if (t === r)
315
- return 0;
316
- for (var s = t.length, a = r.length, c = 0, u = Math.min(s, a); c < u; ++c)
317
- if (t[c] !== r[c]) {
318
- s = t[c], a = r[c];
319
- break;
320
- }
321
- return s < a ? -1 : a < s ? 1 : 0;
322
- };
323
- Buffer.isEncoding = function(t) {
324
- switch (String(t).toLowerCase()) {
325
- case "hex":
326
- case "utf8":
327
- case "utf-8":
328
- case "ascii":
329
- case "latin1":
330
- case "binary":
331
- case "base64":
332
- case "ucs2":
333
- case "ucs-2":
334
- case "utf16le":
335
- case "utf-16le":
336
- return !0;
337
- default:
338
- return !1;
339
- }
340
- };
341
- Buffer.concat = function(t, r) {
342
- if (!isArray(t))
343
- throw new TypeError('"list" argument must be an Array of Buffers');
344
- if (t.length === 0)
345
- return Buffer.alloc(0);
346
- var s;
347
- if (r === void 0)
348
- for (r = 0, s = 0; s < t.length; ++s)
349
- r += t[s].length;
350
- var a = Buffer.allocUnsafe(r), c = 0;
351
- for (s = 0; s < t.length; ++s) {
352
- var u = t[s];
353
- if (!internalIsBuffer(u))
354
- throw new TypeError('"list" argument must be an Array of Buffers');
355
- u.copy(a, c), c += u.length;
356
- }
357
- return a;
358
- };
359
- function byteLength(n, t) {
360
- if (internalIsBuffer(n))
361
- return n.length;
362
- if (typeof ArrayBuffer < "u" && typeof ArrayBuffer.isView == "function" && (ArrayBuffer.isView(n) || n instanceof ArrayBuffer))
363
- return n.byteLength;
364
- typeof n != "string" && (n = "" + n);
365
- var r = n.length;
366
- if (r === 0)
367
- return 0;
368
- for (var s = !1; ; )
369
- switch (t) {
370
- case "ascii":
371
- case "latin1":
372
- case "binary":
373
- return r;
374
- case "utf8":
375
- case "utf-8":
376
- case void 0:
377
- return utf8ToBytes(n).length;
378
- case "ucs2":
379
- case "ucs-2":
380
- case "utf16le":
381
- case "utf-16le":
382
- return r * 2;
383
- case "hex":
384
- return r >>> 1;
385
- case "base64":
386
- return base64ToBytes(n).length;
387
- default:
388
- if (s)
389
- return utf8ToBytes(n).length;
390
- t = ("" + t).toLowerCase(), s = !0;
391
- }
392
- }
393
- Buffer.byteLength = byteLength;
394
- function slowToString(n, t, r) {
395
- var s = !1;
396
- if ((t === void 0 || t < 0) && (t = 0), t > this.length || ((r === void 0 || r > this.length) && (r = this.length), r <= 0) || (r >>>= 0, t >>>= 0, r <= t))
397
- return "";
398
- for (n || (n = "utf8"); ; )
399
- switch (n) {
400
- case "hex":
401
- return hexSlice(this, t, r);
402
- case "utf8":
403
- case "utf-8":
404
- return utf8Slice(this, t, r);
405
- case "ascii":
406
- return asciiSlice(this, t, r);
407
- case "latin1":
408
- case "binary":
409
- return latin1Slice(this, t, r);
410
- case "base64":
411
- return base64Slice(this, t, r);
412
- case "ucs2":
413
- case "ucs-2":
414
- case "utf16le":
415
- case "utf-16le":
416
- return utf16leSlice(this, t, r);
417
- default:
418
- if (s)
419
- throw new TypeError("Unknown encoding: " + n);
420
- n = (n + "").toLowerCase(), s = !0;
421
- }
422
- }
423
- Buffer.prototype._isBuffer = !0;
424
- function swap(n, t, r) {
425
- var s = n[t];
426
- n[t] = n[r], n[r] = s;
427
- }
428
- Buffer.prototype.swap16 = function() {
429
- var t = this.length;
430
- if (t % 2 !== 0)
431
- throw new RangeError("Buffer size must be a multiple of 16-bits");
432
- for (var r = 0; r < t; r += 2)
433
- swap(this, r, r + 1);
434
- return this;
435
- };
436
- Buffer.prototype.swap32 = function() {
437
- var t = this.length;
438
- if (t % 4 !== 0)
439
- throw new RangeError("Buffer size must be a multiple of 32-bits");
440
- for (var r = 0; r < t; r += 4)
441
- swap(this, r, r + 3), swap(this, r + 1, r + 2);
442
- return this;
443
- };
444
- Buffer.prototype.swap64 = function() {
445
- var t = this.length;
446
- if (t % 8 !== 0)
447
- throw new RangeError("Buffer size must be a multiple of 64-bits");
448
- for (var r = 0; r < t; r += 8)
449
- swap(this, r, r + 7), swap(this, r + 1, r + 6), swap(this, r + 2, r + 5), swap(this, r + 3, r + 4);
450
- return this;
451
- };
452
- Buffer.prototype.toString = function() {
453
- var t = this.length | 0;
454
- return t === 0 ? "" : arguments.length === 0 ? utf8Slice(this, 0, t) : slowToString.apply(this, arguments);
455
- };
456
- Buffer.prototype.equals = function(t) {
457
- if (!internalIsBuffer(t))
458
- throw new TypeError("Argument must be a Buffer");
459
- return this === t ? !0 : Buffer.compare(this, t) === 0;
460
- };
461
- Buffer.prototype.inspect = function() {
462
- var t = "", r = INSPECT_MAX_BYTES;
463
- return this.length > 0 && (t = this.toString("hex", 0, r).match(/.{2}/g).join(" "), this.length > r && (t += " ... ")), "<Buffer " + t + ">";
464
- };
465
- Buffer.prototype.compare = function(t, r, s, a, c) {
466
- if (!internalIsBuffer(t))
467
- throw new TypeError("Argument must be a Buffer");
468
- if (r === void 0 && (r = 0), s === void 0 && (s = t ? t.length : 0), a === void 0 && (a = 0), c === void 0 && (c = this.length), r < 0 || s > t.length || a < 0 || c > this.length)
469
- throw new RangeError("out of range index");
470
- if (a >= c && r >= s)
471
- return 0;
472
- if (a >= c)
473
- return -1;
474
- if (r >= s)
475
- return 1;
476
- if (r >>>= 0, s >>>= 0, a >>>= 0, c >>>= 0, this === t)
477
- return 0;
478
- for (var u = c - a, l = s - r, f = Math.min(u, l), d = this.slice(a, c), g = t.slice(r, s), p = 0; p < f; ++p)
479
- if (d[p] !== g[p]) {
480
- u = d[p], l = g[p];
481
- break;
482
- }
483
- return u < l ? -1 : l < u ? 1 : 0;
484
- };
485
- function bidirectionalIndexOf(n, t, r, s, a) {
486
- if (n.length === 0)
487
- return -1;
488
- if (typeof r == "string" ? (s = r, r = 0) : r > 2147483647 ? r = 2147483647 : r < -2147483648 && (r = -2147483648), r = +r, isNaN(r) && (r = a ? 0 : n.length - 1), r < 0 && (r = n.length + r), r >= n.length) {
489
- if (a)
490
- return -1;
491
- r = n.length - 1;
492
- } else if (r < 0)
493
- if (a)
494
- r = 0;
495
- else
496
- return -1;
497
- if (typeof t == "string" && (t = Buffer.from(t, s)), internalIsBuffer(t))
498
- return t.length === 0 ? -1 : arrayIndexOf(n, t, r, s, a);
499
- if (typeof t == "number")
500
- return t = t & 255, Buffer.TYPED_ARRAY_SUPPORT && typeof Uint8Array.prototype.indexOf == "function" ? a ? Uint8Array.prototype.indexOf.call(n, t, r) : Uint8Array.prototype.lastIndexOf.call(n, t, r) : arrayIndexOf(n, [t], r, s, a);
501
- throw new TypeError("val must be string, number or Buffer");
502
- }
503
- function arrayIndexOf(n, t, r, s, a) {
504
- var c = 1, u = n.length, l = t.length;
505
- if (s !== void 0 && (s = String(s).toLowerCase(), s === "ucs2" || s === "ucs-2" || s === "utf16le" || s === "utf-16le")) {
506
- if (n.length < 2 || t.length < 2)
507
- return -1;
508
- c = 2, u /= 2, l /= 2, r /= 2;
509
- }
510
- function f(y, x) {
511
- return c === 1 ? y[x] : y.readUInt16BE(x * c);
512
- }
513
- var d;
514
- if (a) {
515
- var g = -1;
516
- for (d = r; d < u; d++)
517
- if (f(n, d) === f(t, g === -1 ? 0 : d - g)) {
518
- if (g === -1 && (g = d), d - g + 1 === l)
519
- return g * c;
520
- } else
521
- g !== -1 && (d -= d - g), g = -1;
522
- } else
523
- for (r + l > u && (r = u - l), d = r; d >= 0; d--) {
524
- for (var p = !0, w = 0; w < l; w++)
525
- if (f(n, d + w) !== f(t, w)) {
526
- p = !1;
527
- break;
528
- }
529
- if (p)
530
- return d;
531
- }
532
- return -1;
533
- }
534
- Buffer.prototype.includes = function(t, r, s) {
535
- return this.indexOf(t, r, s) !== -1;
536
- };
537
- Buffer.prototype.indexOf = function(t, r, s) {
538
- return bidirectionalIndexOf(this, t, r, s, !0);
539
- };
540
- Buffer.prototype.lastIndexOf = function(t, r, s) {
541
- return bidirectionalIndexOf(this, t, r, s, !1);
542
- };
543
- function hexWrite(n, t, r, s) {
544
- r = Number(r) || 0;
545
- var a = n.length - r;
546
- s ? (s = Number(s), s > a && (s = a)) : s = a;
547
- var c = t.length;
548
- if (c % 2 !== 0)
549
- throw new TypeError("Invalid hex string");
550
- s > c / 2 && (s = c / 2);
551
- for (var u = 0; u < s; ++u) {
552
- var l = parseInt(t.substr(u * 2, 2), 16);
553
- if (isNaN(l))
554
- return u;
555
- n[r + u] = l;
556
- }
557
- return u;
558
- }
559
- function utf8Write(n, t, r, s) {
560
- return blitBuffer(utf8ToBytes(t, n.length - r), n, r, s);
561
- }
562
- function asciiWrite(n, t, r, s) {
563
- return blitBuffer(asciiToBytes(t), n, r, s);
564
- }
565
- function latin1Write(n, t, r, s) {
566
- return asciiWrite(n, t, r, s);
567
- }
568
- function base64Write(n, t, r, s) {
569
- return blitBuffer(base64ToBytes(t), n, r, s);
570
- }
571
- function ucs2Write(n, t, r, s) {
572
- return blitBuffer(utf16leToBytes(t, n.length - r), n, r, s);
573
- }
574
- Buffer.prototype.write = function(t, r, s, a) {
575
- if (r === void 0)
576
- a = "utf8", s = this.length, r = 0;
577
- else if (s === void 0 && typeof r == "string")
578
- a = r, s = this.length, r = 0;
579
- else if (isFinite(r))
580
- r = r | 0, isFinite(s) ? (s = s | 0, a === void 0 && (a = "utf8")) : (a = s, s = void 0);
581
- else
582
- throw new Error(
583
- "Buffer.write(string, encoding, offset[, length]) is no longer supported"
584
- );
585
- var c = this.length - r;
586
- if ((s === void 0 || s > c) && (s = c), t.length > 0 && (s < 0 || r < 0) || r > this.length)
587
- throw new RangeError("Attempt to write outside buffer bounds");
588
- a || (a = "utf8");
589
- for (var u = !1; ; )
590
- switch (a) {
591
- case "hex":
592
- return hexWrite(this, t, r, s);
593
- case "utf8":
594
- case "utf-8":
595
- return utf8Write(this, t, r, s);
596
- case "ascii":
597
- return asciiWrite(this, t, r, s);
598
- case "latin1":
599
- case "binary":
600
- return latin1Write(this, t, r, s);
601
- case "base64":
602
- return base64Write(this, t, r, s);
603
- case "ucs2":
604
- case "ucs-2":
605
- case "utf16le":
606
- case "utf-16le":
607
- return ucs2Write(this, t, r, s);
608
- default:
609
- if (u)
610
- throw new TypeError("Unknown encoding: " + a);
611
- a = ("" + a).toLowerCase(), u = !0;
612
- }
613
- };
614
- Buffer.prototype.toJSON = function() {
615
- return {
616
- type: "Buffer",
617
- data: Array.prototype.slice.call(this._arr || this, 0)
618
- };
619
- };
620
- function base64Slice(n, t, r) {
621
- return t === 0 && r === n.length ? fromByteArray(n) : fromByteArray(n.slice(t, r));
622
- }
623
- function utf8Slice(n, t, r) {
624
- r = Math.min(n.length, r);
625
- for (var s = [], a = t; a < r; ) {
626
- var c = n[a], u = null, l = c > 239 ? 4 : c > 223 ? 3 : c > 191 ? 2 : 1;
627
- if (a + l <= r) {
628
- var f, d, g, p;
629
- switch (l) {
630
- case 1:
631
- c < 128 && (u = c);
632
- break;
633
- case 2:
634
- f = n[a + 1], (f & 192) === 128 && (p = (c & 31) << 6 | f & 63, p > 127 && (u = p));
635
- break;
636
- case 3:
637
- f = n[a + 1], d = n[a + 2], (f & 192) === 128 && (d & 192) === 128 && (p = (c & 15) << 12 | (f & 63) << 6 | d & 63, p > 2047 && (p < 55296 || p > 57343) && (u = p));
638
- break;
639
- case 4:
640
- f = n[a + 1], d = n[a + 2], g = n[a + 3], (f & 192) === 128 && (d & 192) === 128 && (g & 192) === 128 && (p = (c & 15) << 18 | (f & 63) << 12 | (d & 63) << 6 | g & 63, p > 65535 && p < 1114112 && (u = p));
641
- }
642
- }
643
- u === null ? (u = 65533, l = 1) : u > 65535 && (u -= 65536, s.push(u >>> 10 & 1023 | 55296), u = 56320 | u & 1023), s.push(u), a += l;
644
- }
645
- return decodeCodePointsArray(s);
646
- }
647
- var MAX_ARGUMENTS_LENGTH = 4096;
648
- function decodeCodePointsArray(n) {
649
- var t = n.length;
650
- if (t <= MAX_ARGUMENTS_LENGTH)
651
- return String.fromCharCode.apply(String, n);
652
- for (var r = "", s = 0; s < t; )
653
- r += String.fromCharCode.apply(
654
- String,
655
- n.slice(s, s += MAX_ARGUMENTS_LENGTH)
656
- );
657
- return r;
658
- }
659
- function asciiSlice(n, t, r) {
660
- var s = "";
661
- r = Math.min(n.length, r);
662
- for (var a = t; a < r; ++a)
663
- s += String.fromCharCode(n[a] & 127);
664
- return s;
665
- }
666
- function latin1Slice(n, t, r) {
667
- var s = "";
668
- r = Math.min(n.length, r);
669
- for (var a = t; a < r; ++a)
670
- s += String.fromCharCode(n[a]);
671
- return s;
672
- }
673
- function hexSlice(n, t, r) {
674
- var s = n.length;
675
- (!t || t < 0) && (t = 0), (!r || r < 0 || r > s) && (r = s);
676
- for (var a = "", c = t; c < r; ++c)
677
- a += toHex(n[c]);
678
- return a;
679
- }
680
- function utf16leSlice(n, t, r) {
681
- for (var s = n.slice(t, r), a = "", c = 0; c < s.length; c += 2)
682
- a += String.fromCharCode(s[c] + s[c + 1] * 256);
683
- return a;
684
- }
685
- Buffer.prototype.slice = function(t, r) {
686
- var s = this.length;
687
- t = ~~t, r = r === void 0 ? s : ~~r, t < 0 ? (t += s, t < 0 && (t = 0)) : t > s && (t = s), r < 0 ? (r += s, r < 0 && (r = 0)) : r > s && (r = s), r < t && (r = t);
688
- var a;
689
- if (Buffer.TYPED_ARRAY_SUPPORT)
690
- a = this.subarray(t, r), a.__proto__ = Buffer.prototype;
691
- else {
692
- var c = r - t;
693
- a = new Buffer(c, void 0);
694
- for (var u = 0; u < c; ++u)
695
- a[u] = this[u + t];
696
- }
697
- return a;
698
- };
699
- function checkOffset(n, t, r) {
700
- if (n % 1 !== 0 || n < 0)
701
- throw new RangeError("offset is not uint");
702
- if (n + t > r)
703
- throw new RangeError("Trying to access beyond buffer length");
704
- }
705
- Buffer.prototype.readUIntLE = function(t, r, s) {
706
- t = t | 0, r = r | 0, s || checkOffset(t, r, this.length);
707
- for (var a = this[t], c = 1, u = 0; ++u < r && (c *= 256); )
708
- a += this[t + u] * c;
709
- return a;
710
- };
711
- Buffer.prototype.readUIntBE = function(t, r, s) {
712
- t = t | 0, r = r | 0, s || checkOffset(t, r, this.length);
713
- for (var a = this[t + --r], c = 1; r > 0 && (c *= 256); )
714
- a += this[t + --r] * c;
715
- return a;
716
- };
717
- Buffer.prototype.readUInt8 = function(t, r) {
718
- return r || checkOffset(t, 1, this.length), this[t];
719
- };
720
- Buffer.prototype.readUInt16LE = function(t, r) {
721
- return r || checkOffset(t, 2, this.length), this[t] | this[t + 1] << 8;
722
- };
723
- Buffer.prototype.readUInt16BE = function(t, r) {
724
- return r || checkOffset(t, 2, this.length), this[t] << 8 | this[t + 1];
725
- };
726
- Buffer.prototype.readUInt32LE = function(t, r) {
727
- return r || checkOffset(t, 4, this.length), (this[t] | this[t + 1] << 8 | this[t + 2] << 16) + this[t + 3] * 16777216;
728
- };
729
- Buffer.prototype.readUInt32BE = function(t, r) {
730
- return r || checkOffset(t, 4, this.length), this[t] * 16777216 + (this[t + 1] << 16 | this[t + 2] << 8 | this[t + 3]);
731
- };
732
- Buffer.prototype.readIntLE = function(t, r, s) {
733
- t = t | 0, r = r | 0, s || checkOffset(t, r, this.length);
734
- for (var a = this[t], c = 1, u = 0; ++u < r && (c *= 256); )
735
- a += this[t + u] * c;
736
- return c *= 128, a >= c && (a -= Math.pow(2, 8 * r)), a;
737
- };
738
- Buffer.prototype.readIntBE = function(t, r, s) {
739
- t = t | 0, r = r | 0, s || checkOffset(t, r, this.length);
740
- for (var a = r, c = 1, u = this[t + --a]; a > 0 && (c *= 256); )
741
- u += this[t + --a] * c;
742
- return c *= 128, u >= c && (u -= Math.pow(2, 8 * r)), u;
743
- };
744
- Buffer.prototype.readInt8 = function(t, r) {
745
- return r || checkOffset(t, 1, this.length), this[t] & 128 ? (255 - this[t] + 1) * -1 : this[t];
746
- };
747
- Buffer.prototype.readInt16LE = function(t, r) {
748
- r || checkOffset(t, 2, this.length);
749
- var s = this[t] | this[t + 1] << 8;
750
- return s & 32768 ? s | 4294901760 : s;
751
- };
752
- Buffer.prototype.readInt16BE = function(t, r) {
753
- r || checkOffset(t, 2, this.length);
754
- var s = this[t + 1] | this[t] << 8;
755
- return s & 32768 ? s | 4294901760 : s;
756
- };
757
- Buffer.prototype.readInt32LE = function(t, r) {
758
- return r || checkOffset(t, 4, this.length), this[t] | this[t + 1] << 8 | this[t + 2] << 16 | this[t + 3] << 24;
759
- };
760
- Buffer.prototype.readInt32BE = function(t, r) {
761
- return r || checkOffset(t, 4, this.length), this[t] << 24 | this[t + 1] << 16 | this[t + 2] << 8 | this[t + 3];
762
- };
763
- Buffer.prototype.readFloatLE = function(t, r) {
764
- return r || checkOffset(t, 4, this.length), read(this, t, !0, 23, 4);
765
- };
766
- Buffer.prototype.readFloatBE = function(t, r) {
767
- return r || checkOffset(t, 4, this.length), read(this, t, !1, 23, 4);
768
- };
769
- Buffer.prototype.readDoubleLE = function(t, r) {
770
- return r || checkOffset(t, 8, this.length), read(this, t, !0, 52, 8);
771
- };
772
- Buffer.prototype.readDoubleBE = function(t, r) {
773
- return r || checkOffset(t, 8, this.length), read(this, t, !1, 52, 8);
774
- };
775
- function checkInt(n, t, r, s, a, c) {
776
- if (!internalIsBuffer(n))
777
- throw new TypeError('"buffer" argument must be a Buffer instance');
778
- if (t > a || t < c)
779
- throw new RangeError('"value" argument is out of bounds');
780
- if (r + s > n.length)
781
- throw new RangeError("Index out of range");
782
- }
783
- Buffer.prototype.writeUIntLE = function(t, r, s, a) {
784
- if (t = +t, r = r | 0, s = s | 0, !a) {
785
- var c = Math.pow(2, 8 * s) - 1;
786
- checkInt(this, t, r, s, c, 0);
787
- }
788
- var u = 1, l = 0;
789
- for (this[r] = t & 255; ++l < s && (u *= 256); )
790
- this[r + l] = t / u & 255;
791
- return r + s;
792
- };
793
- Buffer.prototype.writeUIntBE = function(t, r, s, a) {
794
- if (t = +t, r = r | 0, s = s | 0, !a) {
795
- var c = Math.pow(2, 8 * s) - 1;
796
- checkInt(this, t, r, s, c, 0);
797
- }
798
- var u = s - 1, l = 1;
799
- for (this[r + u] = t & 255; --u >= 0 && (l *= 256); )
800
- this[r + u] = t / l & 255;
801
- return r + s;
802
- };
803
- Buffer.prototype.writeUInt8 = function(t, r, s) {
804
- return t = +t, r = r | 0, s || checkInt(this, t, r, 1, 255, 0), Buffer.TYPED_ARRAY_SUPPORT || (t = Math.floor(t)), this[r] = t & 255, r + 1;
805
- };
806
- function objectWriteUInt16(n, t, r, s) {
807
- t < 0 && (t = 65535 + t + 1);
808
- for (var a = 0, c = Math.min(n.length - r, 2); a < c; ++a)
809
- n[r + a] = (t & 255 << 8 * (s ? a : 1 - a)) >>> (s ? a : 1 - a) * 8;
810
- }
811
- Buffer.prototype.writeUInt16LE = function(t, r, s) {
812
- return t = +t, r = r | 0, s || checkInt(this, t, r, 2, 65535, 0), Buffer.TYPED_ARRAY_SUPPORT ? (this[r] = t & 255, this[r + 1] = t >>> 8) : objectWriteUInt16(this, t, r, !0), r + 2;
813
- };
814
- Buffer.prototype.writeUInt16BE = function(t, r, s) {
815
- return t = +t, r = r | 0, s || checkInt(this, t, r, 2, 65535, 0), Buffer.TYPED_ARRAY_SUPPORT ? (this[r] = t >>> 8, this[r + 1] = t & 255) : objectWriteUInt16(this, t, r, !1), r + 2;
816
- };
817
- function objectWriteUInt32(n, t, r, s) {
818
- t < 0 && (t = 4294967295 + t + 1);
819
- for (var a = 0, c = Math.min(n.length - r, 4); a < c; ++a)
820
- n[r + a] = t >>> (s ? a : 3 - a) * 8 & 255;
821
- }
822
- Buffer.prototype.writeUInt32LE = function(t, r, s) {
823
- return t = +t, r = r | 0, s || checkInt(this, t, r, 4, 4294967295, 0), Buffer.TYPED_ARRAY_SUPPORT ? (this[r + 3] = t >>> 24, this[r + 2] = t >>> 16, this[r + 1] = t >>> 8, this[r] = t & 255) : objectWriteUInt32(this, t, r, !0), r + 4;
824
- };
825
- Buffer.prototype.writeUInt32BE = function(t, r, s) {
826
- return t = +t, r = r | 0, s || checkInt(this, t, r, 4, 4294967295, 0), Buffer.TYPED_ARRAY_SUPPORT ? (this[r] = t >>> 24, this[r + 1] = t >>> 16, this[r + 2] = t >>> 8, this[r + 3] = t & 255) : objectWriteUInt32(this, t, r, !1), r + 4;
827
- };
828
- Buffer.prototype.writeIntLE = function(t, r, s, a) {
829
- if (t = +t, r = r | 0, !a) {
830
- var c = Math.pow(2, 8 * s - 1);
831
- checkInt(this, t, r, s, c - 1, -c);
832
- }
833
- var u = 0, l = 1, f = 0;
834
- for (this[r] = t & 255; ++u < s && (l *= 256); )
835
- t < 0 && f === 0 && this[r + u - 1] !== 0 && (f = 1), this[r + u] = (t / l >> 0) - f & 255;
836
- return r + s;
837
- };
838
- Buffer.prototype.writeIntBE = function(t, r, s, a) {
839
- if (t = +t, r = r | 0, !a) {
840
- var c = Math.pow(2, 8 * s - 1);
841
- checkInt(this, t, r, s, c - 1, -c);
842
- }
843
- var u = s - 1, l = 1, f = 0;
844
- for (this[r + u] = t & 255; --u >= 0 && (l *= 256); )
845
- t < 0 && f === 0 && this[r + u + 1] !== 0 && (f = 1), this[r + u] = (t / l >> 0) - f & 255;
846
- return r + s;
847
- };
848
- Buffer.prototype.writeInt8 = function(t, r, s) {
849
- return t = +t, r = r | 0, s || checkInt(this, t, r, 1, 127, -128), Buffer.TYPED_ARRAY_SUPPORT || (t = Math.floor(t)), t < 0 && (t = 255 + t + 1), this[r] = t & 255, r + 1;
850
- };
851
- Buffer.prototype.writeInt16LE = function(t, r, s) {
852
- return t = +t, r = r | 0, s || checkInt(this, t, r, 2, 32767, -32768), Buffer.TYPED_ARRAY_SUPPORT ? (this[r] = t & 255, this[r + 1] = t >>> 8) : objectWriteUInt16(this, t, r, !0), r + 2;
853
- };
854
- Buffer.prototype.writeInt16BE = function(t, r, s) {
855
- return t = +t, r = r | 0, s || checkInt(this, t, r, 2, 32767, -32768), Buffer.TYPED_ARRAY_SUPPORT ? (this[r] = t >>> 8, this[r + 1] = t & 255) : objectWriteUInt16(this, t, r, !1), r + 2;
856
- };
857
- Buffer.prototype.writeInt32LE = function(t, r, s) {
858
- return t = +t, r = r | 0, s || checkInt(this, t, r, 4, 2147483647, -2147483648), Buffer.TYPED_ARRAY_SUPPORT ? (this[r] = t & 255, this[r + 1] = t >>> 8, this[r + 2] = t >>> 16, this[r + 3] = t >>> 24) : objectWriteUInt32(this, t, r, !0), r + 4;
859
- };
860
- Buffer.prototype.writeInt32BE = function(t, r, s) {
861
- return t = +t, r = r | 0, s || checkInt(this, t, r, 4, 2147483647, -2147483648), t < 0 && (t = 4294967295 + t + 1), Buffer.TYPED_ARRAY_SUPPORT ? (this[r] = t >>> 24, this[r + 1] = t >>> 16, this[r + 2] = t >>> 8, this[r + 3] = t & 255) : objectWriteUInt32(this, t, r, !1), r + 4;
862
- };
863
- function checkIEEE754(n, t, r, s, a, c) {
864
- if (r + s > n.length)
865
- throw new RangeError("Index out of range");
866
- if (r < 0)
867
- throw new RangeError("Index out of range");
868
- }
869
- function writeFloat(n, t, r, s, a) {
870
- return a || checkIEEE754(n, t, r, 4), write(n, t, r, s, 23, 4), r + 4;
871
- }
872
- Buffer.prototype.writeFloatLE = function(t, r, s) {
873
- return writeFloat(this, t, r, !0, s);
874
- };
875
- Buffer.prototype.writeFloatBE = function(t, r, s) {
876
- return writeFloat(this, t, r, !1, s);
877
- };
878
- function writeDouble(n, t, r, s, a) {
879
- return a || checkIEEE754(n, t, r, 8), write(n, t, r, s, 52, 8), r + 8;
880
- }
881
- Buffer.prototype.writeDoubleLE = function(t, r, s) {
882
- return writeDouble(this, t, r, !0, s);
883
- };
884
- Buffer.prototype.writeDoubleBE = function(t, r, s) {
885
- return writeDouble(this, t, r, !1, s);
886
- };
887
- Buffer.prototype.copy = function(t, r, s, a) {
888
- if (s || (s = 0), !a && a !== 0 && (a = this.length), r >= t.length && (r = t.length), r || (r = 0), a > 0 && a < s && (a = s), a === s || t.length === 0 || this.length === 0)
889
- return 0;
890
- if (r < 0)
891
- throw new RangeError("targetStart out of bounds");
892
- if (s < 0 || s >= this.length)
893
- throw new RangeError("sourceStart out of bounds");
894
- if (a < 0)
895
- throw new RangeError("sourceEnd out of bounds");
896
- a > this.length && (a = this.length), t.length - r < a - s && (a = t.length - r + s);
897
- var c = a - s, u;
898
- if (this === t && s < r && r < a)
899
- for (u = c - 1; u >= 0; --u)
900
- t[u + r] = this[u + s];
901
- else if (c < 1e3 || !Buffer.TYPED_ARRAY_SUPPORT)
902
- for (u = 0; u < c; ++u)
903
- t[u + r] = this[u + s];
904
- else
905
- Uint8Array.prototype.set.call(
906
- t,
907
- this.subarray(s, s + c),
908
- r
909
- );
910
- return c;
911
- };
912
- Buffer.prototype.fill = function(t, r, s, a) {
913
- if (typeof t == "string") {
914
- if (typeof r == "string" ? (a = r, r = 0, s = this.length) : typeof s == "string" && (a = s, s = this.length), t.length === 1) {
915
- var c = t.charCodeAt(0);
916
- c < 256 && (t = c);
917
- }
918
- if (a !== void 0 && typeof a != "string")
919
- throw new TypeError("encoding must be a string");
920
- if (typeof a == "string" && !Buffer.isEncoding(a))
921
- throw new TypeError("Unknown encoding: " + a);
922
- } else
923
- typeof t == "number" && (t = t & 255);
924
- if (r < 0 || this.length < r || this.length < s)
925
- throw new RangeError("Out of range index");
926
- if (s <= r)
927
- return this;
928
- r = r >>> 0, s = s === void 0 ? this.length : s >>> 0, t || (t = 0);
929
- var u;
930
- if (typeof t == "number")
931
- for (u = r; u < s; ++u)
932
- this[u] = t;
933
- else {
934
- var l = internalIsBuffer(t) ? t : utf8ToBytes(new Buffer(t, a).toString()), f = l.length;
935
- for (u = 0; u < s - r; ++u)
936
- this[u + r] = l[u % f];
937
- }
938
- return this;
939
- };
940
- var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g;
941
- function base64clean(n) {
942
- if (n = stringtrim(n).replace(INVALID_BASE64_RE, ""), n.length < 2)
943
- return "";
944
- for (; n.length % 4 !== 0; )
945
- n = n + "=";
946
- return n;
947
- }
948
- function stringtrim(n) {
949
- return n.trim ? n.trim() : n.replace(/^\s+|\s+$/g, "");
950
- }
951
- function toHex(n) {
952
- return n < 16 ? "0" + n.toString(16) : n.toString(16);
953
- }
954
- function utf8ToBytes(n, t) {
955
- t = t || 1 / 0;
956
- for (var r, s = n.length, a = null, c = [], u = 0; u < s; ++u) {
957
- if (r = n.charCodeAt(u), r > 55295 && r < 57344) {
958
- if (!a) {
959
- if (r > 56319) {
960
- (t -= 3) > -1 && c.push(239, 191, 189);
961
- continue;
962
- } else if (u + 1 === s) {
963
- (t -= 3) > -1 && c.push(239, 191, 189);
964
- continue;
965
- }
966
- a = r;
967
- continue;
968
- }
969
- if (r < 56320) {
970
- (t -= 3) > -1 && c.push(239, 191, 189), a = r;
971
- continue;
972
- }
973
- r = (a - 55296 << 10 | r - 56320) + 65536;
974
- } else
975
- a && (t -= 3) > -1 && c.push(239, 191, 189);
976
- if (a = null, r < 128) {
977
- if ((t -= 1) < 0)
978
- break;
979
- c.push(r);
980
- } else if (r < 2048) {
981
- if ((t -= 2) < 0)
982
- break;
983
- c.push(
984
- r >> 6 | 192,
985
- r & 63 | 128
986
- );
987
- } else if (r < 65536) {
988
- if ((t -= 3) < 0)
989
- break;
990
- c.push(
991
- r >> 12 | 224,
992
- r >> 6 & 63 | 128,
993
- r & 63 | 128
994
- );
995
- } else if (r < 1114112) {
996
- if ((t -= 4) < 0)
997
- break;
998
- c.push(
999
- r >> 18 | 240,
1000
- r >> 12 & 63 | 128,
1001
- r >> 6 & 63 | 128,
1002
- r & 63 | 128
1003
- );
1004
- } else
1005
- throw new Error("Invalid code point");
1006
- }
1007
- return c;
1008
- }
1009
- function asciiToBytes(n) {
1010
- for (var t = [], r = 0; r < n.length; ++r)
1011
- t.push(n.charCodeAt(r) & 255);
1012
- return t;
1013
- }
1014
- function utf16leToBytes(n, t) {
1015
- for (var r, s, a, c = [], u = 0; u < n.length && !((t -= 2) < 0); ++u)
1016
- r = n.charCodeAt(u), s = r >> 8, a = r % 256, c.push(a), c.push(s);
1017
- return c;
1018
- }
1019
- function base64ToBytes(n) {
1020
- return toByteArray(base64clean(n));
1021
- }
1022
- function blitBuffer(n, t, r, s) {
1023
- for (var a = 0; a < s && !(a + r >= t.length || a >= n.length); ++a)
1024
- t[a + r] = n[a];
1025
- return a;
1026
- }
1027
- function isnan(n) {
1028
- return n !== n;
1029
- }
1030
- function isBuffer(n) {
1031
- return n != null && (!!n._isBuffer || isFastBuffer(n) || isSlowBuffer(n));
1032
- }
1033
- function isFastBuffer(n) {
1034
- return !!n.constructor && typeof n.constructor.isBuffer == "function" && n.constructor.isBuffer(n);
1035
- }
1036
- function isSlowBuffer(n) {
1037
- return typeof n.readFloatLE == "function" && typeof n.slice == "function" && isFastBuffer(n.slice(0, 0));
1038
- }
1039
- class LocalStorage {
1040
- get(t) {
1041
- return new Promise((r) => {
1042
- const s = window.localStorage.getItem(t);
1043
- r(s ? JSON.parse(s) : null);
1044
- });
1045
- }
1046
- async remove(t) {
1047
- return window.localStorage.removeItem(t), new Promise((r) => {
1048
- r(null);
1049
- });
1050
- }
1051
- set(t, r) {
1052
- return window.localStorage.setItem(t, JSON.stringify(r)), new Promise((s) => {
1053
- s(null);
1054
- });
1055
- }
1056
- }
1057
- const PKCE_KEY = "pkce", GRANT_KEY = "grant", USER_KEY = "user";
1058
- class Storage {
1059
- constructor(t) {
1060
- m(this, "Storage", new LocalStorage());
1061
- if (t) {
1062
- this.Storage = t;
1063
- return;
1064
- }
1065
- }
1066
- setPKCE(t) {
1067
- const r = Buffer.from(t);
1068
- this.Storage.set(PKCE_KEY, r.toString("base64"));
1069
- }
1070
- async getPKCE() {
1071
- try {
1072
- const t = await this.Storage.get(PKCE_KEY);
1073
- if (t)
1074
- return Buffer.from(t, "base64").toString("utf8");
1075
- } catch {
1076
- return null;
1077
- }
1078
- return null;
1079
- }
1080
- removePKCE() {
1081
- this.Storage.remove(PKCE_KEY);
1082
- }
1083
- setGrant(t, r = !1) {
1084
- const { grant_id: s } = t;
1085
- this.Storage.set(`${GRANT_KEY}${r ? "-" + s : ""}`, t);
1086
- }
1087
- removeGrant(t, r = !1) {
1088
- this.Storage.remove(`${GRANT_KEY}${r ? "-" + t : ""}`);
1089
- }
1090
- async getGrant(t, r = !1) {
1091
- const s = await this.Storage.get(`${GRANT_KEY}${r ? "-" + t : ""}`);
1092
- return s || null;
1093
- }
1094
- // setUserToken is used to store the IDToken in storage
1095
- async setUserToken(t) {
1096
- const r = await this.getUserTokens();
1097
- if (r)
1098
- if (r.find((a) => a.sub === t.sub)) {
1099
- const a = r.map((c) => (c.sub === t.sub && (c = t), c));
1100
- this.Storage.set(USER_KEY, a);
1101
- } else {
1102
- const a = [...r, t];
1103
- this.Storage.set(USER_KEY, a);
1104
- }
1105
- else
1106
- this.Storage.set(USER_KEY, [t]);
1107
- }
1108
- // getUserToken is used to retrieve a specific IDToken from storage
1109
- async getUserToken(t = "") {
1110
- const r = await this.Storage.get(USER_KEY);
1111
- return r ? t === "" ? r[0] : r.find((a) => a.sub === t) : null;
1112
- }
1113
- // getUserTokens is used to retrieve all IDTokens from storage
1114
- async getUserTokens() {
1115
- const t = await this.Storage.get(USER_KEY);
1116
- return t || null;
1117
- }
1118
- // removeUserTokens is used to remove all IDTokens from storage
1119
- removeUserTokens() {
1120
- this.Storage.remove(USER_KEY);
1121
- }
1122
- // removeUserToken is used to remove a specific IDToken from storage
1123
- async removeUserToken(t) {
1124
- const r = await this.getUserTokens(), s = r == null ? void 0 : r.filter((a) => a.sub !== t);
1125
- this.Storage.set(USER_KEY, s);
1126
- }
1127
- async clearSession() {
1128
- const t = await this.getUserTokens();
1129
- t == null || t.forEach((r) => {
1130
- this.removeGrant(r.sub);
1131
- }), this.removePKCE(), this.removeUserTokens();
1132
- }
1133
- }
1134
- class IndexedDBStorage {
1135
- constructor() {
1136
- m(this, "databaseName", "identity-db");
1137
- m(this, "storeName", "identity");
1138
- }
1139
- get(t) {
1140
- const r = this;
1141
- return new Promise((s, a) => {
1142
- r.openDatabase().then(function(c) {
1143
- const u = c.transaction(r.storeName, "readwrite"), f = u.objectStore(r.storeName).get(t);
1144
- f.onsuccess = () => {
1145
- s(f.result);
1146
- }, f.onerror = () => {
1147
- a(f.error);
1148
- }, u.oncomplete = () => {
1149
- c.close();
1150
- };
1151
- });
1152
- });
1153
- }
1154
- async remove(t) {
1155
- const r = this;
1156
- return new Promise((s, a) => {
1157
- const c = indexedDB.open(this.databaseName);
1158
- c.onupgradeneeded = function(u) {
1159
- u.target.result.createObjectStore(r.storeName);
1160
- }, c.onerror = () => {
1161
- a(c.error);
1162
- }, c.onsuccess = (u) => {
1163
- const l = u.target.result, f = l.transaction(this.storeName, "readwrite"), g = f.objectStore(this.storeName).delete(t);
1164
- g.onsuccess = () => {
1165
- s(null);
1166
- }, g.onerror = () => {
1167
- a(g.error);
1168
- }, f.oncomplete = () => {
1169
- l.close();
1170
- };
1171
- };
1172
- });
1173
- }
1174
- set(t, r) {
1175
- return new Promise((s, a) => {
1176
- const c = indexedDB.open(this.databaseName);
1177
- c.onerror = () => {
1178
- a(c.error);
1179
- }, c.onupgradeneeded = (u) => {
1180
- u.target.result.createObjectStore(this.storeName);
1181
- }, c.onsuccess = (u) => {
1182
- const l = u.target.result, f = l.transaction(this.storeName, "readwrite"), g = f.objectStore(this.storeName).put(r, t);
1183
- g.onsuccess = () => {
1184
- s(r);
1185
- }, g.onerror = () => {
1186
- a(g.error);
1187
- }, f.oncomplete = () => {
1188
- l.close();
1189
- };
1190
- };
1191
- });
1192
- }
1193
- openDatabase() {
1194
- const t = this;
1195
- return new Promise(function(r, s) {
1196
- const a = indexedDB.open(t.databaseName, 2);
1197
- a.onupgradeneeded = function(c) {
1198
- c.target.result.createObjectStore(t.storeName);
1199
- }, a.onsuccess = function(c) {
1200
- r(c.target.result);
1201
- }, a.onerror = function(c) {
1202
- s(c.error);
1203
- };
1204
- });
1205
- }
1206
- }
1207
- var process = commonjsGlobal.process, sha256 = { exports: {} };
1208
- (function(module) {
1209
- (function() {
1210
- var ERROR = "input is invalid type", WINDOW = typeof window == "object", root = WINDOW ? window : {};
1211
- root.JS_SHA256_NO_WINDOW && (WINDOW = !1);
1212
- var WEB_WORKER = !WINDOW && typeof self == "object", NODE_JS = !root.JS_SHA256_NO_NODE_JS && typeof process == "object" && process.versions && process.versions.node;
1213
- NODE_JS ? root = commonjsGlobal : WEB_WORKER && (root = self);
1214
- 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 = [
1215
- 1116352408,
1216
- 1899447441,
1217
- 3049323471,
1218
- 3921009573,
1219
- 961987163,
1220
- 1508970993,
1221
- 2453635748,
1222
- 2870763221,
1223
- 3624381080,
1224
- 310598401,
1225
- 607225278,
1226
- 1426881987,
1227
- 1925078388,
1228
- 2162078206,
1229
- 2614888103,
1230
- 3248222580,
1231
- 3835390401,
1232
- 4022224774,
1233
- 264347078,
1234
- 604807628,
1235
- 770255983,
1236
- 1249150122,
1237
- 1555081692,
1238
- 1996064986,
1239
- 2554220882,
1240
- 2821834349,
1241
- 2952996808,
1242
- 3210313671,
1243
- 3336571891,
1244
- 3584528711,
1245
- 113926993,
1246
- 338241895,
1247
- 666307205,
1248
- 773529912,
1249
- 1294757372,
1250
- 1396182291,
1251
- 1695183700,
1252
- 1986661051,
1253
- 2177026350,
1254
- 2456956037,
1255
- 2730485921,
1256
- 2820302411,
1257
- 3259730800,
1258
- 3345764771,
1259
- 3516065817,
1260
- 3600352804,
1261
- 4094571909,
1262
- 275423344,
1263
- 430227734,
1264
- 506948616,
1265
- 659060556,
1266
- 883997877,
1267
- 958139571,
1268
- 1322822218,
1269
- 1537002063,
1270
- 1747873779,
1271
- 1955562222,
1272
- 2024104815,
1273
- 2227730452,
1274
- 2361852424,
1275
- 2428436474,
1276
- 2756734187,
1277
- 3204031479,
1278
- 3329325298
1279
- ], OUTPUT_TYPES = ["hex", "array", "digest", "arrayBuffer"], blocks = [];
1280
- (root.JS_SHA256_NO_NODE_JS || !Array.isArray) && (Array.isArray = function(n) {
1281
- return Object.prototype.toString.call(n) === "[object Array]";
1282
- }), ARRAY_BUFFER && (root.JS_SHA256_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) && (ArrayBuffer.isView = function(n) {
1283
- return typeof n == "object" && n.buffer && n.buffer.constructor === ArrayBuffer;
1284
- });
1285
- var createOutputMethod = function(n, t) {
1286
- return function(r) {
1287
- return new Sha256(t, !0).update(r)[n]();
1288
- };
1289
- }, createMethod = function(n) {
1290
- var t = createOutputMethod("hex", n);
1291
- NODE_JS && (t = nodeWrap(t, n)), t.create = function() {
1292
- return new Sha256(n);
1293
- }, t.update = function(a) {
1294
- return t.create().update(a);
1295
- };
1296
- for (var r = 0; r < OUTPUT_TYPES.length; ++r) {
1297
- var s = OUTPUT_TYPES[r];
1298
- t[s] = createOutputMethod(s, n);
1299
- }
1300
- return t;
1301
- }, nodeWrap = function(method, is224) {
1302
- var crypto = eval("require('crypto')"), Buffer = eval("require('buffer').Buffer"), algorithm = is224 ? "sha224" : "sha256", nodeMethod = function(n) {
1303
- if (typeof n == "string")
1304
- return crypto.createHash(algorithm).update(n, "utf8").digest("hex");
1305
- if (n == null)
1306
- throw new Error(ERROR);
1307
- return n.constructor === ArrayBuffer && (n = new Uint8Array(n)), Array.isArray(n) || ArrayBuffer.isView(n) || n.constructor === Buffer ? crypto.createHash(algorithm).update(new Buffer(n)).digest("hex") : method(n);
1308
- };
1309
- return nodeMethod;
1310
- }, createHmacOutputMethod = function(n, t) {
1311
- return function(r, s) {
1312
- return new HmacSha256(r, t, !0).update(s)[n]();
1313
- };
1314
- }, createHmacMethod = function(n) {
1315
- var t = createHmacOutputMethod("hex", n);
1316
- t.create = function(a) {
1317
- return new HmacSha256(a, n);
1318
- }, t.update = function(a, c) {
1319
- return t.create(a).update(c);
1320
- };
1321
- for (var r = 0; r < OUTPUT_TYPES.length; ++r) {
1322
- var s = OUTPUT_TYPES[r];
1323
- t[s] = createHmacOutputMethod(s, n);
1324
- }
1325
- return t;
1326
- };
1327
- function Sha256(n, t) {
1328
- 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], n ? (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 = n;
1329
- }
1330
- Sha256.prototype.update = function(n) {
1331
- if (!this.finalized) {
1332
- var t, r = typeof n;
1333
- if (r !== "string") {
1334
- if (r === "object") {
1335
- if (n === null)
1336
- throw new Error(ERROR);
1337
- if (ARRAY_BUFFER && n.constructor === ArrayBuffer)
1338
- n = new Uint8Array(n);
1339
- else if (!Array.isArray(n) && (!ARRAY_BUFFER || !ArrayBuffer.isView(n)))
1340
- throw new Error(ERROR);
1341
- } else
1342
- throw new Error(ERROR);
1343
- t = !0;
1344
- }
1345
- for (var s, a = 0, c, u = n.length, l = this.blocks; a < u; ) {
1346
- 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)
1347
- for (c = this.start; a < u && c < 64; ++a)
1348
- l[c >> 2] |= n[a] << SHIFT[c++ & 3];
1349
- else
1350
- for (c = this.start; a < u && c < 64; ++a)
1351
- s = n.charCodeAt(a), s < 128 ? l[c >> 2] |= s << SHIFT[c++ & 3] : s < 2048 ? (l[c >> 2] |= (192 | s >> 6) << SHIFT[c++ & 3], l[c >> 2] |= (128 | s & 63) << SHIFT[c++ & 3]) : s < 55296 || s >= 57344 ? (l[c >> 2] |= (224 | s >> 12) << SHIFT[c++ & 3], l[c >> 2] |= (128 | s >> 6 & 63) << SHIFT[c++ & 3], l[c >> 2] |= (128 | s & 63) << SHIFT[c++ & 3]) : (s = 65536 + ((s & 1023) << 10 | n.charCodeAt(++a) & 1023), l[c >> 2] |= (240 | s >> 18) << SHIFT[c++ & 3], l[c >> 2] |= (128 | s >> 12 & 63) << SHIFT[c++ & 3], l[c >> 2] |= (128 | s >> 6 & 63) << SHIFT[c++ & 3], l[c >> 2] |= (128 | s & 63) << SHIFT[c++ & 3]);
1352
- this.lastByteIndex = c, this.bytes += c - this.start, c >= 64 ? (this.block = l[16], this.start = c - 64, this.hash(), this.hashed = !0) : this.start = c;
1353
- }
1354
- return this.bytes > 4294967295 && (this.hBytes += this.bytes / 4294967296 << 0, this.bytes = this.bytes % 4294967296), this;
1355
- }
1356
- }, Sha256.prototype.finalize = function() {
1357
- if (!this.finalized) {
1358
- this.finalized = !0;
1359
- var n = this.blocks, t = this.lastByteIndex;
1360
- n[16] = this.block, n[t >> 2] |= EXTRA[t & 3], this.block = n[16], t >= 56 && (this.hashed || this.hash(), n[0] = this.block, n[16] = n[1] = n[2] = n[3] = n[4] = n[5] = n[6] = n[7] = n[8] = n[9] = n[10] = n[11] = n[12] = n[13] = n[14] = n[15] = 0), n[14] = this.hBytes << 3 | this.bytes >>> 29, n[15] = this.bytes << 3, this.hash();
1361
- }
1362
- }, Sha256.prototype.hash = function() {
1363
- var n = this.h0, t = this.h1, r = this.h2, s = this.h3, a = this.h4, c = this.h5, u = this.h6, l = this.h7, f = this.blocks, d, g, p, w, y, x, S, A, v, b, _;
1364
- for (d = 16; d < 64; ++d)
1365
- y = f[d - 15], g = (y >>> 7 | y << 25) ^ (y >>> 18 | y << 14) ^ y >>> 3, y = f[d - 2], p = (y >>> 17 | y << 15) ^ (y >>> 19 | y << 13) ^ y >>> 10, f[d] = f[d - 16] + g + f[d - 7] + p << 0;
1366
- for (_ = t & r, d = 0; d < 64; d += 4)
1367
- this.first ? (this.is224 ? (A = 300032, y = f[0] - 1413257819, l = y - 150054599 << 0, s = y + 24177077 << 0) : (A = 704751109, y = f[0] - 210244248, l = y - 1521486534 << 0, s = y + 143694565 << 0), this.first = !1) : (g = (n >>> 2 | n << 30) ^ (n >>> 13 | n << 19) ^ (n >>> 22 | n << 10), p = (a >>> 6 | a << 26) ^ (a >>> 11 | a << 21) ^ (a >>> 25 | a << 7), A = n & t, w = A ^ n & r ^ _, S = a & c ^ ~a & u, y = l + p + S + K[d] + f[d], x = g + w, l = s + y << 0, s = y + x << 0), g = (s >>> 2 | s << 30) ^ (s >>> 13 | s << 19) ^ (s >>> 22 | s << 10), p = (l >>> 6 | l << 26) ^ (l >>> 11 | l << 21) ^ (l >>> 25 | l << 7), v = s & n, w = v ^ s & t ^ A, S = l & a ^ ~l & c, y = u + p + S + K[d + 1] + f[d + 1], x = g + w, u = r + y << 0, r = y + x << 0, g = (r >>> 2 | r << 30) ^ (r >>> 13 | r << 19) ^ (r >>> 22 | r << 10), p = (u >>> 6 | u << 26) ^ (u >>> 11 | u << 21) ^ (u >>> 25 | u << 7), b = r & s, w = b ^ r & n ^ v, S = u & l ^ ~u & a, y = c + p + S + K[d + 2] + f[d + 2], x = g + w, c = t + y << 0, t = y + x << 0, g = (t >>> 2 | t << 30) ^ (t >>> 13 | t << 19) ^ (t >>> 22 | t << 10), p = (c >>> 6 | c << 26) ^ (c >>> 11 | c << 21) ^ (c >>> 25 | c << 7), _ = t & r, w = _ ^ t & s ^ b, S = c & u ^ ~c & l, y = a + p + S + K[d + 3] + f[d + 3], x = g + w, a = n + y << 0, n = y + x << 0;
1368
- this.h0 = this.h0 + n << 0, this.h1 = this.h1 + t << 0, this.h2 = this.h2 + r << 0, this.h3 = this.h3 + s << 0, this.h4 = this.h4 + a << 0, this.h5 = this.h5 + c << 0, this.h6 = this.h6 + u << 0, this.h7 = this.h7 + l << 0;
1369
- }, Sha256.prototype.hex = function() {
1370
- this.finalize();
1371
- var n = this.h0, t = this.h1, r = this.h2, s = this.h3, a = this.h4, c = this.h5, u = this.h6, l = this.h7, f = 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[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[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[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[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[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[u >> 28 & 15] + HEX_CHARS[u >> 24 & 15] + HEX_CHARS[u >> 20 & 15] + HEX_CHARS[u >> 16 & 15] + HEX_CHARS[u >> 12 & 15] + HEX_CHARS[u >> 8 & 15] + HEX_CHARS[u >> 4 & 15] + HEX_CHARS[u & 15];
1372
- return this.is224 || (f += 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]), f;
1373
- }, Sha256.prototype.toString = Sha256.prototype.hex, Sha256.prototype.digest = function() {
1374
- this.finalize();
1375
- var n = this.h0, t = this.h1, r = this.h2, s = this.h3, a = this.h4, c = this.h5, u = this.h6, l = this.h7, f = [
1376
- n >> 24 & 255,
1377
- n >> 16 & 255,
1378
- n >> 8 & 255,
1379
- n & 255,
1380
- t >> 24 & 255,
1381
- t >> 16 & 255,
1382
- t >> 8 & 255,
1383
- t & 255,
1384
- r >> 24 & 255,
1385
- r >> 16 & 255,
1386
- r >> 8 & 255,
1387
- r & 255,
1388
- s >> 24 & 255,
1389
- s >> 16 & 255,
1390
- s >> 8 & 255,
1391
- s & 255,
1392
- a >> 24 & 255,
1393
- a >> 16 & 255,
1394
- a >> 8 & 255,
1395
- a & 255,
1396
- c >> 24 & 255,
1397
- c >> 16 & 255,
1398
- c >> 8 & 255,
1399
- c & 255,
1400
- u >> 24 & 255,
1401
- u >> 16 & 255,
1402
- u >> 8 & 255,
1403
- u & 255
1404
- ];
1405
- return this.is224 || f.push(l >> 24 & 255, l >> 16 & 255, l >> 8 & 255, l & 255), f;
1406
- }, Sha256.prototype.array = Sha256.prototype.digest, Sha256.prototype.arrayBuffer = function() {
1407
- this.finalize();
1408
- var n = new ArrayBuffer(this.is224 ? 28 : 32), t = new DataView(n);
1409
- 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), n;
1410
- };
1411
- function HmacSha256(n, t, r) {
1412
- var s, a = typeof n;
1413
- if (a === "string") {
1414
- var c = [], u = n.length, l = 0, f;
1415
- for (s = 0; s < u; ++s)
1416
- f = n.charCodeAt(s), f < 128 ? c[l++] = f : f < 2048 ? (c[l++] = 192 | f >> 6, c[l++] = 128 | f & 63) : f < 55296 || f >= 57344 ? (c[l++] = 224 | f >> 12, c[l++] = 128 | f >> 6 & 63, c[l++] = 128 | f & 63) : (f = 65536 + ((f & 1023) << 10 | n.charCodeAt(++s) & 1023), c[l++] = 240 | f >> 18, c[l++] = 128 | f >> 12 & 63, c[l++] = 128 | f >> 6 & 63, c[l++] = 128 | f & 63);
1417
- n = c;
1418
- } else if (a === "object") {
1419
- if (n === null)
1420
- throw new Error(ERROR);
1421
- if (ARRAY_BUFFER && n.constructor === ArrayBuffer)
1422
- n = new Uint8Array(n);
1423
- else if (!Array.isArray(n) && (!ARRAY_BUFFER || !ArrayBuffer.isView(n)))
1424
- throw new Error(ERROR);
1425
- } else
1426
- throw new Error(ERROR);
1427
- n.length > 64 && (n = new Sha256(t, !0).update(n).array());
1428
- var d = [], g = [];
1429
- for (s = 0; s < 64; ++s) {
1430
- var p = n[s] || 0;
1431
- d[s] = 92 ^ p, g[s] = 54 ^ p;
1432
- }
1433
- Sha256.call(this, t, r), this.update(g), this.oKeyPad = d, this.inner = !0, this.sharedMemory = r;
1434
- }
1435
- HmacSha256.prototype = new Sha256(), HmacSha256.prototype.finalize = function() {
1436
- if (Sha256.prototype.finalize.call(this), this.inner) {
1437
- this.inner = !1;
1438
- var n = this.array();
1439
- Sha256.call(this, this.is224, this.sharedMemory), this.update(this.oKeyPad), this.update(n), Sha256.prototype.finalize.call(this);
1440
- }
1441
- };
1442
- var exports = createMethod();
1443
- 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);
1444
- })();
1445
- })(sha256);
1446
- var getRandomValues, rnds8 = new Uint8Array(16);
1447
- function rng() {
1448
- if (!getRandomValues && (getRandomValues = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto < "u" && typeof msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto), !getRandomValues))
1449
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1450
- return getRandomValues(rnds8);
1451
- }
1452
- 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;
1453
- function validate(n) {
1454
- return typeof n == "string" && REGEX.test(n);
1455
- }
1456
- var byteToHex = [];
1457
- for (var i = 0; i < 256; ++i)
1458
- byteToHex.push((i + 256).toString(16).substr(1));
1459
- function stringify(n) {
1460
- var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, r = (byteToHex[n[t + 0]] + byteToHex[n[t + 1]] + byteToHex[n[t + 2]] + byteToHex[n[t + 3]] + "-" + byteToHex[n[t + 4]] + byteToHex[n[t + 5]] + "-" + byteToHex[n[t + 6]] + byteToHex[n[t + 7]] + "-" + byteToHex[n[t + 8]] + byteToHex[n[t + 9]] + "-" + byteToHex[n[t + 10]] + byteToHex[n[t + 11]] + byteToHex[n[t + 12]] + byteToHex[n[t + 13]] + byteToHex[n[t + 14]] + byteToHex[n[t + 15]]).toLowerCase();
1461
- if (!validate(r))
1462
- throw TypeError("Stringified UUID is invalid");
1463
- return r;
1464
- }
1465
- function v4(n, t, r) {
1466
- n = n || {};
1467
- var s = n.random || (n.rng || rng)();
1468
- if (s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, t) {
1469
- r = r || 0;
1470
- for (var a = 0; a < 16; ++a)
1471
- t[r + a] = s[a];
1472
- return t;
1473
- }
1474
- return stringify(s);
1475
- }
1476
- async function getBytes(n, t) {
1477
- const r = n.getReader();
1478
- let s;
1479
- for (; !(s = await r.read()).done; )
1480
- t(s.value);
1481
- }
1482
- function getLines(n) {
1483
- let t, r, s, a = !1;
1484
- return function(u) {
1485
- t === void 0 ? (t = u, r = 0, s = -1) : t = concat(t, u);
1486
- const l = t.length;
1487
- let f = 0;
1488
- for (; r < l; ) {
1489
- a && (t[r] === 10 && (f = ++r), a = !1);
1490
- let d = -1;
1491
- for (; r < l && d === -1; ++r)
1492
- switch (t[r]) {
1493
- case 58:
1494
- s === -1 && (s = r - f);
1495
- break;
1496
- case 13:
1497
- a = !0;
1498
- case 10:
1499
- d = r;
1500
- break;
1501
- }
1502
- if (d === -1)
1503
- break;
1504
- n(t.subarray(f, d), s), f = r, s = -1;
1505
- }
1506
- f === l ? t = void 0 : f !== 0 && (t = t.subarray(f), r -= f);
1507
- };
1508
- }
1509
- function getMessages(n, t, r) {
1510
- let s = newMessage();
1511
- const a = new TextDecoder();
1512
- return function(u, l) {
1513
- if (u.length === 0)
1514
- r == null || r(s), s = newMessage();
1515
- else if (l > 0) {
1516
- const f = a.decode(u.subarray(0, l)), d = l + (u[l + 1] === 32 ? 2 : 1), g = a.decode(u.subarray(d));
1517
- switch (f) {
1518
- case "data":
1519
- s.data = s.data ? s.data + `
1520
- ` + g : g;
1521
- break;
1522
- case "event":
1523
- s.event = g;
1524
- break;
1525
- case "id":
1526
- n(s.id = g);
1527
- break;
1528
- case "retry":
1529
- const p = parseInt(g, 10);
1530
- isNaN(p) || t(s.retry = p);
1531
- break;
1532
- }
1533
- }
1534
- };
1535
- }
1536
- function concat(n, t) {
1537
- const r = new Uint8Array(n.length + t.length);
1538
- return r.set(n), r.set(t, n.length), r;
1539
- }
1540
- function newMessage() {
1541
- return {
1542
- data: "",
1543
- event: "",
1544
- id: "",
1545
- retry: void 0
1546
- };
1547
- }
1548
- var __rest = function(n, t) {
1549
- var r = {};
1550
- for (var s in n)
1551
- Object.prototype.hasOwnProperty.call(n, s) && t.indexOf(s) < 0 && (r[s] = n[s]);
1552
- if (n != null && typeof Object.getOwnPropertySymbols == "function")
1553
- for (var a = 0, s = Object.getOwnPropertySymbols(n); a < s.length; a++)
1554
- t.indexOf(s[a]) < 0 && Object.prototype.propertyIsEnumerable.call(n, s[a]) && (r[s[a]] = n[s[a]]);
1555
- return r;
1556
- };
1557
- const EventStreamContentType = "text/event-stream", DefaultRetryInterval = 1e3, LastEventId = "last-event-id";
1558
- function fetchEventSource(n, t) {
1559
- var { signal: r, headers: s, onopen: a, onmessage: c, onclose: u, onerror: l, openWhenHidden: f, fetch: d } = t, g = __rest(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
1560
- return new Promise((p, w) => {
1561
- const y = Object.assign({}, s);
1562
- y.accept || (y.accept = EventStreamContentType);
1563
- let x;
1564
- function S() {
1565
- x.abort(), document.hidden || T();
1566
- }
1567
- f || document.addEventListener("visibilitychange", S);
1568
- let A = DefaultRetryInterval, v = 0;
1569
- function b() {
1570
- document.removeEventListener("visibilitychange", S), window.clearTimeout(v), x.abort();
1571
- }
1572
- r == null || r.addEventListener("abort", () => {
1573
- b(), p();
1574
- });
1575
- const _ = d ?? window.fetch, U = a ?? defaultOnOpen;
1576
- async function T() {
1577
- var k;
1578
- x = new AbortController();
1579
- try {
1580
- const I = await _(n, Object.assign(Object.assign({}, g), { headers: y, signal: x.signal }));
1581
- await U(I), await getBytes(I.body, getLines(getMessages((R) => {
1582
- R ? y[LastEventId] = R : delete y[LastEventId];
1583
- }, (R) => {
1584
- A = R;
1585
- }, c))), u == null || u(), b(), p();
1586
- } catch (I) {
1587
- if (!x.signal.aborted)
1588
- try {
1589
- const R = (k = l == null ? void 0 : l(I)) !== null && k !== void 0 ? k : A;
1590
- window.clearTimeout(v), v = window.setTimeout(T, R);
1591
- } catch (R) {
1592
- b(), w(R);
1593
- }
1594
- }
1595
- }
1596
- T();
1597
- });
1598
- }
1599
- function defaultOnOpen(n) {
1600
- const t = n.headers.get("content-type");
1601
- if (!(t != null && t.startsWith(EventStreamContentType)))
1602
- throw new Error(`Expected content-type to be ${EventStreamContentType}, Actual: ${t}`);
1603
- }
1604
- function Base64EncodeUrl(n) {
1605
- return n.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1606
- }
1607
- function getTimestamp() {
1608
- return Math.floor(Date.now() / 1e3);
1609
- }
1610
- function e(n) {
1611
- this.message = n;
1612
- }
1613
- e.prototype = new Error(), e.prototype.name = "InvalidCharacterError";
1614
- var r$1 = typeof window < "u" && window.atob && window.atob.bind(window) || function(n) {
1615
- var t = String(n).replace(/=+$/, "");
1616
- if (t.length % 4 == 1)
1617
- throw new e("'atob' failed: The string to be decoded is not correctly encoded.");
1618
- for (var r, s, a = 0, c = 0, u = ""; s = t.charAt(c++); ~s && (r = a % 4 ? 64 * r + s : s, a++ % 4) ? u += String.fromCharCode(255 & r >> (-2 * a & 6)) : 0)
1619
- s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(s);
1620
- return u;
1621
- };
1622
- function t$1(n) {
1623
- var t = n.replace(/-/g, "+").replace(/_/g, "/");
1624
- switch (t.length % 4) {
1625
- case 0:
1626
- break;
1627
- case 2:
1628
- t += "==";
1629
- break;
1630
- case 3:
1631
- t += "=";
1632
- break;
1633
- default:
1634
- throw "Illegal base64url string!";
1635
- }
1636
- try {
1637
- return function(r) {
1638
- return decodeURIComponent(r$1(r).replace(/(.)/g, function(s, a) {
1639
- var c = a.charCodeAt(0).toString(16).toUpperCase();
1640
- return c.length < 2 && (c = "0" + c), "%" + c;
1641
- }));
1642
- }(t);
1643
- } catch {
1644
- return r$1(t);
1645
- }
1646
- }
1647
- function n$1(n) {
1648
- this.message = n;
1649
- }
1650
- function o(n, t) {
1651
- if (typeof n != "string")
1652
- throw new n$1("Invalid token specified");
1653
- var r = (t = t || {}).header === !0 ? 0 : 1;
1654
- try {
1655
- return JSON.parse(t$1(n.split(".")[r]));
1656
- } catch (s) {
1657
- throw new n$1("Invalid token specified: " + s.message);
1658
- }
1659
- }
1660
- n$1.prototype = new Error(), n$1.prototype.name = "InvalidTokenError";
1661
- class NylasSessions {
1662
- constructor(t) {
1663
- m(this, "clientId");
1664
- m(this, "redirectUri");
1665
- m(this, "accessType", "online");
1666
- m(this, "domain", "http://api.nylas.com");
1667
- m(this, "versioned", !1);
1668
- m(this, "Storage");
1669
- m(this, "hosted", !1);
1670
- m(this, "multiAccount", !1);
1671
- m(this, "loginId", "");
1672
- 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) {
1673
- const r = new IndexedDBStorage();
1674
- this.Storage = new Storage(r);
1675
- } else
1676
- this.Storage = new Storage();
1677
- t.accessType && (this.accessType = t.accessType), t.loginId && (this.loginId = t.loginId), t.hosted && (this.hosted = t.hosted), this.codeExchange(null);
1678
- }
1679
- // Validates access token
1680
- async validateAccessToken(t = "") {
1681
- const { access_token: r } = await this.Storage.getGrant(t, this.multiAccount);
1682
- try {
1683
- return !!(await (await fetch(`${this.domain}/connect/tokeninfo?access_token=${r}`, {
1684
- method: "GET"
1685
- })).json()).data;
1686
- } catch {
1687
- return !1;
1688
- }
1689
- }
1690
- // Validates id token
1691
- async validateIDToken(t = "") {
1692
- const { id_token: r } = await this.Storage.getGrant(t, this.multiAccount);
1693
- try {
1694
- const s = await fetch(`${this.domain}/connect/tokeninfo?id_token=${r}`, {
1695
- method: "GET"
1696
- });
1697
- return !(s.status !== 200 || !(await s.json()).data);
1698
- } catch {
1699
- return !1;
1700
- }
1701
- }
1702
- // Gets domain of UAS
1703
- getDomain() {
1704
- return this.domain;
1705
- }
1706
- // Gets auth link
1707
- async auth(t) {
1708
- this.hosted && (this.domain === window.location.origin || this.versioned && this.domain.includes(window.location.origin)) && await this.hostedSetCodeChallenge();
1709
- const r = await this.generateAuthURL(t);
1710
- if (t.popup) {
1711
- this.popUp(r);
1712
- return;
1713
- }
1714
- return r;
1715
- }
1716
- // Generates auth URL
1717
- async generateAuthURL(t) {
1718
- const r = await this.getCodeChallege();
1719
- let s = `${this.domain}/connect/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&access_type=${this.accessType}&response_type=code`;
1720
- return r && (s += `&code_challenge=${r}&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;
1721
- }
1722
- // Generates auth URL
1723
- async generateReauthURL(t, r) {
1724
- if (!t)
1725
- throw new Error("Grant ID is required");
1726
- const s = await this.Storage.getUserToken(t), a = await this.getCodeChallege();
1727
- let c = `${this.domain}/connect/auth?client_id=${this.clientId}&redirect_uri=${this.redirectUri}&access_type=${this.accessType}&response_type=code`;
1728
- return a && (c += `&code_challenge=${a}&code_challenge_method=S256&options=rotate_refresh_token`), s != null && s.provider && (c += `&provider=${s.provider}`), s != null && s.email && (c += `&login_hint=${s.email}`), r && (c += `&scope=${r.join(" ")}`), c;
1729
- }
1730
- // Generates UUID code challenge
1731
- async generateCodeChallenge() {
1732
- if (await this.Storage.getPKCE())
1733
- return;
1734
- const r = v4();
1735
- this.Storage.setPKCE(r);
1736
- }
1737
- // Gets code challenge from URL query params
1738
- async hostedSetCodeChallenge() {
1739
- if (!this.hosted)
1740
- throw console.error("Method only used with hosted flag enabled");
1741
- const r = new URLSearchParams(window.location.search).get("code_challenge");
1742
- if (!r) {
1743
- if (await this.Storage.getPKCE())
1744
- return;
1745
- console.warn("Code challenge is recomended");
1746
- return;
1747
- }
1748
- this.Storage.setPKCE(r);
1749
- }
1750
- // Gets code challenge from store
1751
- async getCodeChallege() {
1752
- if (this.hosted && (this.domain === window.location.origin || this.versioned && this.domain.includes(window.location.origin))) {
1753
- const s = new URLSearchParams(window.location.search).get("code_challenge");
1754
- return s || (console.warn("Code challenge is recomended"), "");
1755
- }
1756
- const t = await this.Storage.getPKCE();
1757
- if (t) {
1758
- const r = sha256.exports.sha256(t);
1759
- let s = Buffer.from(r).toString("base64");
1760
- return s = Base64EncodeUrl(s), s;
1761
- }
1762
- return "";
1763
- }
1764
- // checks if user is logged in
1765
- async isLoggedIn() {
1766
- if (this.hosted && (this.domain === window.location.origin || this.versioned && this.domain.includes(window.location.origin)))
1767
- return !1;
1768
- const t = await this.Storage.getUserTokens();
1769
- return t && t.length > 0 ? (this.multiAccount && await this.generateCodeChallenge(), !0) : (await this.generateCodeChallenge(), !1);
1770
- }
1771
- // Checks if user is multi account
1772
- isMultiAccount() {
1773
- return this.multiAccount;
1774
- }
1775
- // Logs user out
1776
- async logout() {
1777
- const t = await this.getProfile();
1778
- await this.Storage.clearSession();
1779
- const r = { detail: t };
1780
- window.dispatchEvent(new CustomEvent("onLogoutSuccess", r));
1781
- }
1782
- // Gets profile info from ID token
1783
- async getProfile(t = "") {
1784
- let r;
1785
- return t ? r = await this.Storage.getUserToken(t) : r = await this.Storage.getUserToken(), r || null;
1786
- }
1787
- // Gets profile info from ID tokens
1788
- async getProfiles() {
1789
- const t = await this.Storage.getUserTokens();
1790
- return t || null;
1791
- }
1792
- // Remove a specific profile
1793
- async removeProfile(t) {
1794
- return await this.Storage.removeUserToken(t), await this.Storage.removeGrant(t), null;
1795
- }
1796
- // IMAP authentication
1797
- async authIMAP(t) {
1798
- const r = await this.getCodeChallege(), s = {
1799
- imap_username: t.username,
1800
- imap_password: t.password,
1801
- imap_host: t.hostIMAP,
1802
- imap_port: t.portIMAP,
1803
- type: t.type,
1804
- smtp_host: t.hostSMTP,
1805
- smtp_port: t.portSMTP,
1806
- provider: t.provider,
1807
- redirect_uri: this.redirectUri,
1808
- state: t.state,
1809
- public_application_id: this.clientId,
1810
- access_type: this.accessType
1811
- };
1812
- return this.loginId && (s.id = this.loginId), r != "" && (s.code_challenge = r, s.code_challenge_method = "S256"), await (await fetch(`${this.domain}/connect/login/imap`, {
1813
- method: "POST",
1814
- headers: new Headers({ "content-type": "application/json" }),
1815
- body: JSON.stringify(s)
1816
- })).json();
1817
- }
1818
- // EWS authentication
1819
- async authEWS(t) {
1820
- const r = await this.getCodeChallege(), s = {
1821
- ...t,
1822
- redirect_uri: this.redirectUri,
1823
- public_application_id: this.clientId,
1824
- access_type: this.accessType
1825
- };
1826
- return this.loginId && (s.id = this.loginId), r != "" && (s.code_challenge = r, s.code_challenge_method = "S256"), await (await fetch(`${this.domain}/connect/login/ews`, {
1827
- method: "POST",
1828
- headers: new Headers({ "content-type": "application/json" }),
1829
- body: JSON.stringify(s)
1830
- })).json();
1831
- }
1832
- // Detects email
1833
- async detectEmail(t) {
1834
- return (await (await fetch(`${this.versioned ? this.domain : this.domain + "/connect"}/providers/detect?client_id=${this.clientId}&email=${t}`, {
1835
- method: "POST",
1836
- headers: new Headers({ "content-type": "application/json" })
1837
- })).json()).data;
1838
- }
1839
- // Gets app info from UAS
1840
- async applicationInfo() {
1841
- return (await (await fetch(`${this.versioned ? this.domain : this.domain + "/connect"}/applications?client_id=${this.clientId}`, {
1842
- method: "GET",
1843
- headers: new Headers({ "content-type": "application/json" })
1844
- })).json()).data;
1845
- }
1846
- // Gets providers form UAS
1847
- async getAvailableProviders() {
1848
- const t = await fetch(`${this.domain}/connect/providers/find?client_id=${this.clientId}`, {
1849
- method: "GET",
1850
- headers: new Headers({ "content-type": "application/json" })
1851
- });
1852
- return t ? (await t.json()).data : null;
1853
- }
1854
- // EVENT HOOKS
1855
- onLoginSuccess(t) {
1856
- window.addEventListener("onLoginSuccess", (r) => t(r));
1857
- }
1858
- onLogoutSuccess(t) {
1859
- window.addEventListener("onLogoutSuccess", (r) => t(r));
1860
- }
1861
- onLoginFail(t) {
1862
- window.addEventListener("onLoginFail", (r) => t(r));
1863
- }
1864
- onTokenRefreshSuccess(t) {
1865
- window.addEventListener("onTokenRefreshSuccess", (r) => t(r));
1866
- }
1867
- onTokenRefreshFail(t) {
1868
- window.addEventListener("onTokenRefreshFail", (r) => t(r));
1869
- }
1870
- onSessionExpired(t) {
1871
- window.addEventListener("onSessionExpired", (r) => t(r));
1872
- }
1873
- // Exchanges code for ID token and refresh and access tokens
1874
- async codeExchange(t) {
1875
- let r = new URLSearchParams(window.location.search);
1876
- t && (r = new URLSearchParams(t));
1877
- const s = r.get("code"), a = r.get("state"), c = r.get("error"), u = r.get("error_description"), l = r.get("error_code");
1878
- if (c && u && l) {
1879
- const d = {
1880
- detail: { error: c, error_description: u, error_code: l }
1881
- };
1882
- return window.dispatchEvent(new CustomEvent("onLoginFail", d)), window.history.pushState({}, document.title, window.location.pathname), !1;
1883
- }
1884
- if (!s)
1885
- return console.warn("No code found"), !1;
1886
- if (window.opener && window.name === "uas-popup")
1887
- return console.warn("Popup window detected"), !1;
1888
- const f = await this.Storage.getPKCE();
1889
- if (!f)
1890
- return console.warn("No code verifier found"), !1;
1891
- try {
1892
- const d = {
1893
- client_id: this.clientId,
1894
- redirect_uri: this.redirectUri,
1895
- code: s,
1896
- grant_type: "authorization_code",
1897
- code_verifier: f
1898
- }, p = await (await fetch(`${this.domain}/connect/token`, {
1899
- method: "POST",
1900
- headers: new Headers({ "content-type": "application/json" }),
1901
- body: JSON.stringify(d)
1902
- })).json();
1903
- if (p) {
1904
- if (p.error) {
1905
- const y = { detail: p };
1906
- return window.dispatchEvent(new CustomEvent("onLoginFail", y)), !0;
1907
- }
1908
- const w = await this.handleCodeExchangeResponse(p);
1909
- if (w.valid) {
1910
- a && (w.data.state = a);
1911
- const y = { detail: w.data };
1912
- window.dispatchEvent(new CustomEvent("onLoginSuccess", y)), window.history.pushState({}, document.title, window.location.pathname);
1913
- } else {
1914
- const y = { detail: w.data };
1915
- return window.dispatchEvent(new CustomEvent("onLoginFail", y)), !0;
1916
- }
1917
- }
1918
- return this.Storage.removePKCE(), !0;
1919
- } catch (d) {
1920
- const g = { detail: d };
1921
- return window.dispatchEvent(new CustomEvent("onLoginFail", g)), window.history.pushState({}, document.title, window.location.pathname), !1;
1922
- }
1923
- }
1924
- // Token Exchange for session maintenece
1925
- async tokenExchange(t = "") {
1926
- const { refresh_token: r } = await this.Storage.getGrant(t, this.multiAccount);
1927
- try {
1928
- const s = {
1929
- client_id: this.clientId,
1930
- redirect_uri: this.redirectUri,
1931
- refresh_token: r,
1932
- grant_type: "refresh_token"
1933
- }, c = await (await fetch(`${this.domain}/connect/token`, {
1934
- method: "POST",
1935
- headers: new Headers({ "content-type": "application/json" }),
1936
- body: JSON.stringify(s)
1937
- })).json();
1938
- if (c) {
1939
- if (c.error) {
1940
- const d = { detail: c };
1941
- return window.dispatchEvent(new CustomEvent("onTokenRefreshFail", d)), !0;
1942
- }
1943
- const u = getTimestamp();
1944
- if (c.expires_in = u + c.expires_in, this.Storage.setGrant(c, this.multiAccount), !await this.validateIDToken(t)) {
1945
- const d = { detail: c };
1946
- return window.dispatchEvent(new CustomEvent("onTokenRefreshFail", d)), !0;
1947
- }
1948
- const f = { detail: c };
1949
- return window.dispatchEvent(new CustomEvent("onTokenRefreshSuccess", f)), !0;
1950
- }
1951
- this.Storage.removePKCE();
1952
- } catch (s) {
1953
- const a = { detail: s };
1954
- return window.dispatchEvent(new CustomEvent("onTokenRefreshFail", a)), !1;
1955
- }
1956
- }
1957
- // Handles the response of code exchange
1958
- async handleCodeExchangeResponse(t) {
1959
- if (t.error)
1960
- return {
1961
- data: t,
1962
- valid: !1
1963
- };
1964
- const s = getTimestamp();
1965
- t.expires_in = s + t.expires_in, this.Storage.setGrant(t, this.multiAccount);
1966
- const a = o(t.id_token);
1967
- return a.status = "authenticated", this.Storage.setUserToken(a), await this.validateIDToken(a.sub) ? {
1968
- data: t,
1969
- valid: !0
1970
- } : {
1971
- data: t,
1972
- valid: !1
1973
- };
1974
- }
1975
- // Regulates POPUP behaivior
1976
- async popUp(t) {
1977
- const a = window.screenX + (window.outerWidth - 500) / 2, c = window.screenY + (window.outerHeight - 600) / 2.5, u = "uas-popup", l = t, f = window.open(l, u, `width=500,height=600,left=${a},top=${c}`);
1978
- if (!f)
1979
- return;
1980
- const d = setInterval(async () => {
1981
- if (f.closed) {
1982
- const g = {
1983
- detail: { error_description: "OAuth provider window closed" }
1984
- };
1985
- window.dispatchEvent(new CustomEvent("onLoginFail", g)), d && clearInterval(d);
1986
- return;
1987
- }
1988
- try {
1989
- const g = f.location.href.split("?");
1990
- if (!g[0])
1991
- return;
1992
- const p = f.location.search;
1993
- if (f.history.pushState({}, document.title, window.location.pathname), g[0] === this.redirectUri && g.length > 1) {
1994
- const w = await this.codeExchange(p);
1995
- f.close(), w && location.reload(), d && clearInterval(d);
1996
- return;
1997
- }
1998
- } catch {
1999
- return;
2000
- }
2001
- }, 1e3);
2002
- }
2003
- // Returns access token
2004
- async getAccessToken(t = "") {
2005
- const r = getTimestamp(), { access_token: s, expires_in: a } = await this.Storage.getGrant(t, this.multiAccount), c = s;
2006
- return c && a && a > getTimestamp() && a - r > 30 ? c : (await this.tokenExchange(t), (await this.Storage.getGrant(t, this.multiAccount)).access_token);
2007
- }
2008
- async sse(t, r) {
2009
- const s = r.headers || {}, a = s["Grant-ID"];
2010
- let c = "";
2011
- if (this.multiAccount) {
2012
- if (!a)
2013
- throw new Error("Grant ID is required for multi account calls");
2014
- c = await this.getAccessToken(a);
2015
- } else
2016
- c = await this.getAccessToken();
2017
- return delete s["Grant-ID"], s.Authorization = `Bearer ${c}`, s["content-type"] || (s["content-type"] = "application/json"), fetchEventSource(`${this.domain}/${t}`, {
2018
- ...r,
2019
- headers: s
2020
- });
2021
- }
2022
- // Used to call Nylas API endpoints
2023
- async fetch(t, r, s = !0, a) {
2024
- let c = "", u = 1;
2025
- if (this.multiAccount) {
2026
- if (!r.grant_id)
2027
- throw new Error("Grant ID is required for multi account calls");
2028
- const f = await this.getProfiles();
2029
- u = f ? f.length : 1, c = await this.getAccessToken(r.grant_id);
2030
- } else
2031
- c = await this.getAccessToken();
2032
- let l = r.headers;
2033
- Headers.prototype.isPrototypeOf(l) ? (l.append("Authorization", `Bearer ${c}`), l.has("content-type") || l.append("content-type", "application/json")) : l = new Headers({
2034
- Authorization: `Bearer ${c}`,
2035
- "content-type": "application/json"
2036
- });
2037
- try {
2038
- r != null && r.body && (r.body = JSON.stringify(r == null ? void 0 : r.body));
2039
- const f = await fetch(`${a || this.domain}/${t}`, {
2040
- ...r,
2041
- headers: l
2042
- });
2043
- if (!s)
2044
- return f;
2045
- const d = await (f == null ? void 0 : f.json());
2046
- if (!await this.isAuthenticatedResponse(f.status, d)) {
2047
- if (u > 1) {
2048
- const p = await this.getProfile(r.grant_id);
2049
- if (p) {
2050
- p.status = "unauthorized", await this.Storage.setUserToken(p);
2051
- const w = {
2052
- detail: { user: p }
2053
- };
2054
- window.dispatchEvent(new CustomEvent("onSessionExpired", w));
2055
- }
2056
- } else {
2057
- const w = {
2058
- detail: { user: await this.Storage.getUserToken() }
2059
- };
2060
- window.dispatchEvent(new CustomEvent("onSessionExpired", w)), this.logout();
2061
- }
2062
- return;
2063
- }
2064
- return d;
2065
- } catch (f) {
2066
- throw f;
2067
- }
2068
- }
2069
- async fetchRequest(t, r, s, a = !0, c, u) {
2070
- const l = await this.isLoggedIn(), f = new URL(t, c ?? this.domain), d = new Headers();
2071
- if (d.append("Accept", "application/json"), d.append("Content-Type", "application/json"), d.append("User-Agent", "nylas-identity"), l) {
2072
- const w = await this.getAccessToken();
2073
- d.append("Authorization", `Bearer ${w}`);
2074
- }
2075
- const g = await fetch(f.toString(), {
2076
- method: r || "GET",
2077
- headers: d,
2078
- mode: "cors",
2079
- referrer: location.origin,
2080
- body: s ? JSON.stringify(s) : void 0,
2081
- ...u || {}
2082
- });
2083
- return a ? await g.json() : g.body;
2084
- }
2085
- // Checks if the response is not 401
2086
- async isAuthenticatedResponse(t, r) {
2087
- var s;
2088
- return !(t == 401 && ((s = r == null ? void 0 : r.error) == null ? void 0 : s.type) == "token.unauthorized_access");
2089
- }
2090
- addAPIKey(t, r, s) {
2091
- this.Storage.setUserToken({
2092
- aud: "https://api-staging.us.nylas.com/",
2093
- exp: 2e9,
2094
- email_verified: !0,
2095
- iat: getTimestamp(),
2096
- iss: "",
2097
- email: r,
2098
- provider: "virtual-calendar",
2099
- status: "authenticated",
2100
- name: r,
2101
- sub: t
2102
- }), this.Storage.setGrant({
2103
- grant_id: t,
2104
- access_token: s,
2105
- expires_in: 2e9
2106
- }, this.multiAccount);
2107
- }
2108
- }
2109
- var B = { isMounted: function() {
2110
- return !1;
2111
- }, enqueueForceUpdate: function() {
2112
- }, enqueueReplaceState: function() {
2113
- }, enqueueSetState: function() {
2114
- } }, C = Object.assign, D = {};
2115
- function E(n, t, r) {
2116
- this.props = n, this.context = t, this.refs = D, this.updater = r || B;
2117
- }
2118
- E.prototype.isReactComponent = {};
2119
- E.prototype.setState = function(n, t) {
2120
- if (typeof n != "object" && typeof n != "function" && n != null)
2121
- throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");
2122
- this.updater.enqueueSetState(this, n, t, "setState");
2123
- };
2124
- E.prototype.forceUpdate = function(n) {
2125
- this.updater.enqueueForceUpdate(this, n, "forceUpdate");
2126
- };
2127
- function F() {
2128
- }
2129
- F.prototype = E.prototype;
2130
- function G(n, t, r) {
2131
- this.props = n, this.context = t, this.refs = D, this.updater = r || B;
2132
- }
2133
- var H = G.prototype = new F();
2134
- H.constructor = G;
2135
- C(H, E.prototype);
2136
- H.isPureReactComponent = !0;
2137
- const LoginRequired = ({ authenticationUrl: n }) => h(
2138
- "div",
2139
- { class: "login-required" },
2140
- h(
2141
- "div",
2142
- { class: "card" },
2143
- h("p", null, "Log into your account to use the Scheduler Editor."),
2144
- h(
2145
- "button",
2146
- { class: "google-button", onClick: async (t) => {
2147
- t.preventDefault();
2148
- const r = await n("google");
2149
- r ? window.location.href = r : console.error("[nylas-scheduler-editor] Unable to get authentication URL.");
2150
- } },
2151
- h(
2152
- "span",
2153
- { class: "icon" },
2154
- h("google-logo-icon", { width: "15", height: "15" })
2155
- ),
2156
- "Continue with Google"
2157
- ),
2158
- h(
2159
- "button",
2160
- { class: "microsoft-button", onClick: async (t) => {
2161
- t.preventDefault();
2162
- const r = await n("microsoft");
2163
- r ? window.location.href = r : console.error("[nylas-scheduler-editor] Unable to get authentication URL.");
2164
- } },
2165
- h(
2166
- "span",
2167
- { class: "icon" },
2168
- h("microsoft-logo-icon", { width: "15", height: "15" })
2169
- ),
2170
- "Continue with Microsoft"
2171
- ),
2172
- h(
2173
- "button",
2174
- { class: "other-provider-button", onClick: async (t) => {
2175
- t.preventDefault();
2176
- const r = await n();
2177
- r ? window.location.href = r : console.error("[nylas-scheduler-editor] Unable to get authentication URL.");
2178
- } },
2179
- "View all providers ",
2180
- h("chevron-icon", { width: "17", height: "17" })
2181
- ),
2182
- h("small", { class: "disclaimer-text" }, "* You will be redirected to authenticate your account.")
2183
- )
2184
- ), 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{display:flex;flex-direction:column;padding:2rem 1rem;background-color:var(--nylas-base-25)}.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}', NylasSchedulerEditorStyle0 = nylasSchedulerEditorCss, NylasSchedulerEditor = class {
2185
- constructor(n) {
2186
- registerInstance(this, n), 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) => {
2187
- this.schedulerConfigCloseClicked.emit(this.host);
2188
- }, this.authenticationUrl = async (t) => this.nylasApiRequest ? await this.nylasApiRequest.authenticationUrl({ provider: t }) || "" : (console.error("[nylas-scheduler-editor] Nylas API Request is not initialized."), ""), this.defaultRequiresSessionAuth = !0, this.configurationId = void 0, this.nylasApiRequest = void 0, this.nylasSessionsConfig = void 0, this.defaultAuthArgs = void 0, this.eventOverrides = {}, this.schedulerPreviewLink = "", this.defaultSchedulerConfigStoreState = void 0, this.mode = "app", this.automaticComponentRegistration = !0;
2189
- }
2190
- connectedCallback() {
2191
- debug("[nylas-scheduler-editor] connectedCallback");
2192
- }
2193
- async componentWillLoad() {
2194
- var r, s, a, c, u, l, f, d, g;
2195
- if (debug("[nylas-scheduler-editor] componentWillLoad"), this.stores = {
2196
- schedulerConfig: CreateNylasSchedulerConfigStore({
2197
- ...this.defaultSchedulerConfigStoreState
2198
- })
2199
- }, (s = (r = this.stores) == null ? void 0 : r.schedulerConfig) == null || s.set("defaultRequiresSessionAuth", this.defaultRequiresSessionAuth), !this.nylasApiRequest && this.nylasSessionsConfig) {
2200
- const p = new NylasSessions(this.nylasSessionsConfig);
2201
- await p.isLoggedIn(), p.onLoginSuccess(async () => {
2202
- var y, x;
2203
- const w = await ((x = (y = this.nylasSchedulerConfigConnector) == null ? void 0 : y.schedulerConfig) == null ? void 0 : x.currentUser());
2204
- w && (this.loggedIn.emit(this.host), this.loggedInHandler(w));
2205
- }), p.onLoginFail(async () => {
2206
- var w, y;
2207
- (y = (w = this.stores) == null ? void 0 : w.schedulerConfig) == null || y.set("currentUser", null), this.loggedOut.emit(this.host);
2208
- }), this.nylasApiRequest = new NylasIdentityRequestWrapper(p);
2209
- }
2210
- this.nylasApiRequest && this.defaultAuthArgs && this.nylasApiRequest.setDefaultAuthArgs(this.defaultAuthArgs), this.baseProvider = new NylasBaseProvider(this.host, this.stores, this.automaticComponentRegistration, this.eventOverrides);
2211
- const n = this.baseProvider.getStore("schedulerConfig");
2212
- if (this.nylasSchedulerConfigConnector = new NylasSchedulerConfigConnector({
2213
- nylasApiRequest: this.nylasApiRequest,
2214
- nylasSchedulerConfigStore: n
2215
- }), !this.init.emit(this.host).defaultPrevented) {
2216
- const p = await ((c = (a = this.nylasSchedulerConfigConnector) == null ? void 0 : a.schedulerConfig) == null ? void 0 : c.currentUser());
2217
- p ? (this.loggedIn.emit(this.host), await this.loggedInHandler(p)) : ((l = (u = this.stores) == null ? void 0 : u.schedulerConfig) == null || l.set("currentUser", null), this.loggedOut.emit(this.host));
2218
- }
2219
- (d = (f = this.stores) == null ? void 0 : f.schedulerConfig) == null || d.onChange("selectedConfiguration", async (p) => {
2220
- p && p.id && (this.configurationId = p.id);
2221
- }), (g = this.baseProvider) == null || g.componentWillLoad(this.nylasSchedulerConfigConnector);
2222
- }
2223
- async componentDidLoad() {
2224
- var n;
2225
- debug("[nylas-scheduler-editor] componentDidLoad"), (n = this.baseProvider) == null || n.componentDidLoad();
2226
- }
2227
- componentDisconnected() {
2228
- var n;
2229
- (n = this.baseProvider) == null || n.componentDisconnected();
2230
- }
2231
- defaultRequiresSessionAuthChanged(n) {
2232
- var t, r;
2233
- (r = (t = this.stores) == null ? void 0 : t.schedulerConfig) == null || r.set("defaultRequiresSessionAuth", n);
2234
- }
2235
- async configurationIdChanged(n) {
2236
- var t, r, s, a, c, u, l, f;
2237
- n ? (await ((r = (t = this.nylasSchedulerConfigConnector) == null ? void 0 : t.schedulerConfig) == null ? void 0 : r.getConfigurationById(n)), (a = (s = this.stores) == null ? void 0 : s.schedulerConfig) == null || a.set("action", "edit")) : ((u = (c = this.stores) == null ? void 0 : c.schedulerConfig) == null || u.set("selectedConfiguration", {}), (f = (l = this.stores) == null ? void 0 : l.schedulerConfig) == null || f.set("action", null));
2238
- }
2239
- async store() {
2240
- var n;
2241
- return (n = this.stores) == null ? void 0 : n.schedulerConfig;
2242
- }
2243
- async schedulerConnector() {
2244
- return this.nylasSchedulerConfigConnector;
2245
- }
2246
- async registerComponentHandler(n) {
2247
- var t;
2248
- (t = this.baseProvider) == null || t.registerComponent(n.detail);
2249
- }
2250
- async unregisterComponentHandler(n) {
2251
- var t;
2252
- (t = this.baseProvider) == null || t.unregisterComponent(n.detail);
2253
- }
2254
- async loggedInHandler(n) {
2255
- var t, r, s, a;
2256
- (r = (t = this.stores) == null ? void 0 : t.schedulerConfig) == null || r.set("currentUser", n), this.nylasSchedulerConfigConnector && (this.configurationId && await ((s = this.nylasSchedulerConfigConnector.schedulerConfig) == null ? void 0 : s.getConfigurationById(this.configurationId)), await ((a = this.nylasSchedulerConfigConnector.schedulerConfig) == null ? void 0 : a.getCalendars()));
2257
- }
2258
- render() {
2259
- var n, t, r, s, a, c, u, l;
2260
- return h(Host, { key: "14880638bcb9c031f748d72fe0052b6eb0df463d" }, h("div", { key: "f0ee0e9a97eddbd350dfc41469257475e6178e3d", class: "scheduler-editor-header", part: "nse__header" }, h("h1", { key: "eb85113f9650853bb6f3f348e6517ba83112f28f", class: "scheduler-editor-title", part: "nse__title" }, h("calendar-icon", { key: "48e6edb5828fbdb111a3360a5c49ef762008c69a", width: "18", height: "18" }), "Scheduler editor"), h("button", { key: "f3d02137c2a999e6305b20b6735efc77370a6a83", class: "scheduler-editor-close", onClick: (f) => this.handleSchedulerConfigCloseClicked(f), part: "nse__close-button" }, h("close-icon", { key: "05280d7af113731d30b659d9de308b23aa3ea014", width: "18", height: "18" }))), ((t = (n = this.stores) == null ? void 0 : n.schedulerConfig) == null ? void 0 : t.state.currentUser) && this.stores.schedulerConfig.state.action === null && h("div", { class: "list-configurations" }, h("nylas-list-configurations", null)), ((s = (r = this.stores) == null ? void 0 : r.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)), ((c = (a = this.stores) == null ? void 0 : a.schedulerConfig) == null ? void 0 : c.state.currentUser) && this.stores.schedulerConfig.state.action === "edit" && h("nylas-editor-tabs", { mode: this.mode }, this.mode === "composable" && h("slot", null)), !((l = (u = this.stores) == null ? void 0 : u.schedulerConfig) != null && l.state.currentUser) && h("slot", { name: "login-required" }, h(LoginRequired, { authenticationUrl: this.authenticationUrl })));
2261
- }
2262
- get host() {
2263
- return getElement(this);
2264
- }
2265
- static get watchers() {
2266
- return {
2267
- defaultRequiresSessionAuth: ["defaultRequiresSessionAuthChanged"],
2268
- configurationId: ["configurationIdChanged"]
2269
- };
2270
- }
2271
- };
2272
- NylasSchedulerEditor.style = NylasSchedulerEditorStyle0;
2273
- export {
2274
- NylasSchedulerEditor as nylas_scheduler_editor
2275
- };