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