@nsshunt/stsoauth2plugin 1.0.151 → 1.0.153
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.
|
@@ -0,0 +1,3442 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const wt = require("node:worker_threads");
|
|
5
|
+
const stsutils = require("@nsshunt/stsutils");
|
|
6
|
+
const stsvueutils = require("@nsshunt/stsvueutils");
|
|
7
|
+
const pinia = require("pinia");
|
|
8
|
+
const stsobservability = require("@nsshunt/stsobservability");
|
|
9
|
+
const axios = require("axios");
|
|
10
|
+
const http = require("node:http");
|
|
11
|
+
const https = require("node:https");
|
|
12
|
+
function _interopNamespaceDefault(e) {
|
|
13
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
14
|
+
if (e) {
|
|
15
|
+
for (const k in e) {
|
|
16
|
+
if (k !== "default") {
|
|
17
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: () => e[k]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
const wt__namespace = /* @__PURE__ */ _interopNamespaceDefault(wt);
|
|
29
|
+
const STSOAuth2ManagerPluginKey = /* @__PURE__ */ Symbol();
|
|
30
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
31
|
+
function getDefaultExportFromCjs(x) {
|
|
32
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
33
|
+
}
|
|
34
|
+
var ansiStyles = { exports: {} };
|
|
35
|
+
var colorName;
|
|
36
|
+
var hasRequiredColorName;
|
|
37
|
+
function requireColorName() {
|
|
38
|
+
if (hasRequiredColorName) return colorName;
|
|
39
|
+
hasRequiredColorName = 1;
|
|
40
|
+
colorName = {
|
|
41
|
+
"aliceblue": [240, 248, 255],
|
|
42
|
+
"antiquewhite": [250, 235, 215],
|
|
43
|
+
"aqua": [0, 255, 255],
|
|
44
|
+
"aquamarine": [127, 255, 212],
|
|
45
|
+
"azure": [240, 255, 255],
|
|
46
|
+
"beige": [245, 245, 220],
|
|
47
|
+
"bisque": [255, 228, 196],
|
|
48
|
+
"black": [0, 0, 0],
|
|
49
|
+
"blanchedalmond": [255, 235, 205],
|
|
50
|
+
"blue": [0, 0, 255],
|
|
51
|
+
"blueviolet": [138, 43, 226],
|
|
52
|
+
"brown": [165, 42, 42],
|
|
53
|
+
"burlywood": [222, 184, 135],
|
|
54
|
+
"cadetblue": [95, 158, 160],
|
|
55
|
+
"chartreuse": [127, 255, 0],
|
|
56
|
+
"chocolate": [210, 105, 30],
|
|
57
|
+
"coral": [255, 127, 80],
|
|
58
|
+
"cornflowerblue": [100, 149, 237],
|
|
59
|
+
"cornsilk": [255, 248, 220],
|
|
60
|
+
"crimson": [220, 20, 60],
|
|
61
|
+
"cyan": [0, 255, 255],
|
|
62
|
+
"darkblue": [0, 0, 139],
|
|
63
|
+
"darkcyan": [0, 139, 139],
|
|
64
|
+
"darkgoldenrod": [184, 134, 11],
|
|
65
|
+
"darkgray": [169, 169, 169],
|
|
66
|
+
"darkgreen": [0, 100, 0],
|
|
67
|
+
"darkgrey": [169, 169, 169],
|
|
68
|
+
"darkkhaki": [189, 183, 107],
|
|
69
|
+
"darkmagenta": [139, 0, 139],
|
|
70
|
+
"darkolivegreen": [85, 107, 47],
|
|
71
|
+
"darkorange": [255, 140, 0],
|
|
72
|
+
"darkorchid": [153, 50, 204],
|
|
73
|
+
"darkred": [139, 0, 0],
|
|
74
|
+
"darksalmon": [233, 150, 122],
|
|
75
|
+
"darkseagreen": [143, 188, 143],
|
|
76
|
+
"darkslateblue": [72, 61, 139],
|
|
77
|
+
"darkslategray": [47, 79, 79],
|
|
78
|
+
"darkslategrey": [47, 79, 79],
|
|
79
|
+
"darkturquoise": [0, 206, 209],
|
|
80
|
+
"darkviolet": [148, 0, 211],
|
|
81
|
+
"deeppink": [255, 20, 147],
|
|
82
|
+
"deepskyblue": [0, 191, 255],
|
|
83
|
+
"dimgray": [105, 105, 105],
|
|
84
|
+
"dimgrey": [105, 105, 105],
|
|
85
|
+
"dodgerblue": [30, 144, 255],
|
|
86
|
+
"firebrick": [178, 34, 34],
|
|
87
|
+
"floralwhite": [255, 250, 240],
|
|
88
|
+
"forestgreen": [34, 139, 34],
|
|
89
|
+
"fuchsia": [255, 0, 255],
|
|
90
|
+
"gainsboro": [220, 220, 220],
|
|
91
|
+
"ghostwhite": [248, 248, 255],
|
|
92
|
+
"gold": [255, 215, 0],
|
|
93
|
+
"goldenrod": [218, 165, 32],
|
|
94
|
+
"gray": [128, 128, 128],
|
|
95
|
+
"green": [0, 128, 0],
|
|
96
|
+
"greenyellow": [173, 255, 47],
|
|
97
|
+
"grey": [128, 128, 128],
|
|
98
|
+
"honeydew": [240, 255, 240],
|
|
99
|
+
"hotpink": [255, 105, 180],
|
|
100
|
+
"indianred": [205, 92, 92],
|
|
101
|
+
"indigo": [75, 0, 130],
|
|
102
|
+
"ivory": [255, 255, 240],
|
|
103
|
+
"khaki": [240, 230, 140],
|
|
104
|
+
"lavender": [230, 230, 250],
|
|
105
|
+
"lavenderblush": [255, 240, 245],
|
|
106
|
+
"lawngreen": [124, 252, 0],
|
|
107
|
+
"lemonchiffon": [255, 250, 205],
|
|
108
|
+
"lightblue": [173, 216, 230],
|
|
109
|
+
"lightcoral": [240, 128, 128],
|
|
110
|
+
"lightcyan": [224, 255, 255],
|
|
111
|
+
"lightgoldenrodyellow": [250, 250, 210],
|
|
112
|
+
"lightgray": [211, 211, 211],
|
|
113
|
+
"lightgreen": [144, 238, 144],
|
|
114
|
+
"lightgrey": [211, 211, 211],
|
|
115
|
+
"lightpink": [255, 182, 193],
|
|
116
|
+
"lightsalmon": [255, 160, 122],
|
|
117
|
+
"lightseagreen": [32, 178, 170],
|
|
118
|
+
"lightskyblue": [135, 206, 250],
|
|
119
|
+
"lightslategray": [119, 136, 153],
|
|
120
|
+
"lightslategrey": [119, 136, 153],
|
|
121
|
+
"lightsteelblue": [176, 196, 222],
|
|
122
|
+
"lightyellow": [255, 255, 224],
|
|
123
|
+
"lime": [0, 255, 0],
|
|
124
|
+
"limegreen": [50, 205, 50],
|
|
125
|
+
"linen": [250, 240, 230],
|
|
126
|
+
"magenta": [255, 0, 255],
|
|
127
|
+
"maroon": [128, 0, 0],
|
|
128
|
+
"mediumaquamarine": [102, 205, 170],
|
|
129
|
+
"mediumblue": [0, 0, 205],
|
|
130
|
+
"mediumorchid": [186, 85, 211],
|
|
131
|
+
"mediumpurple": [147, 112, 219],
|
|
132
|
+
"mediumseagreen": [60, 179, 113],
|
|
133
|
+
"mediumslateblue": [123, 104, 238],
|
|
134
|
+
"mediumspringgreen": [0, 250, 154],
|
|
135
|
+
"mediumturquoise": [72, 209, 204],
|
|
136
|
+
"mediumvioletred": [199, 21, 133],
|
|
137
|
+
"midnightblue": [25, 25, 112],
|
|
138
|
+
"mintcream": [245, 255, 250],
|
|
139
|
+
"mistyrose": [255, 228, 225],
|
|
140
|
+
"moccasin": [255, 228, 181],
|
|
141
|
+
"navajowhite": [255, 222, 173],
|
|
142
|
+
"navy": [0, 0, 128],
|
|
143
|
+
"oldlace": [253, 245, 230],
|
|
144
|
+
"olive": [128, 128, 0],
|
|
145
|
+
"olivedrab": [107, 142, 35],
|
|
146
|
+
"orange": [255, 165, 0],
|
|
147
|
+
"orangered": [255, 69, 0],
|
|
148
|
+
"orchid": [218, 112, 214],
|
|
149
|
+
"palegoldenrod": [238, 232, 170],
|
|
150
|
+
"palegreen": [152, 251, 152],
|
|
151
|
+
"paleturquoise": [175, 238, 238],
|
|
152
|
+
"palevioletred": [219, 112, 147],
|
|
153
|
+
"papayawhip": [255, 239, 213],
|
|
154
|
+
"peachpuff": [255, 218, 185],
|
|
155
|
+
"peru": [205, 133, 63],
|
|
156
|
+
"pink": [255, 192, 203],
|
|
157
|
+
"plum": [221, 160, 221],
|
|
158
|
+
"powderblue": [176, 224, 230],
|
|
159
|
+
"purple": [128, 0, 128],
|
|
160
|
+
"rebeccapurple": [102, 51, 153],
|
|
161
|
+
"red": [255, 0, 0],
|
|
162
|
+
"rosybrown": [188, 143, 143],
|
|
163
|
+
"royalblue": [65, 105, 225],
|
|
164
|
+
"saddlebrown": [139, 69, 19],
|
|
165
|
+
"salmon": [250, 128, 114],
|
|
166
|
+
"sandybrown": [244, 164, 96],
|
|
167
|
+
"seagreen": [46, 139, 87],
|
|
168
|
+
"seashell": [255, 245, 238],
|
|
169
|
+
"sienna": [160, 82, 45],
|
|
170
|
+
"silver": [192, 192, 192],
|
|
171
|
+
"skyblue": [135, 206, 235],
|
|
172
|
+
"slateblue": [106, 90, 205],
|
|
173
|
+
"slategray": [112, 128, 144],
|
|
174
|
+
"slategrey": [112, 128, 144],
|
|
175
|
+
"snow": [255, 250, 250],
|
|
176
|
+
"springgreen": [0, 255, 127],
|
|
177
|
+
"steelblue": [70, 130, 180],
|
|
178
|
+
"tan": [210, 180, 140],
|
|
179
|
+
"teal": [0, 128, 128],
|
|
180
|
+
"thistle": [216, 191, 216],
|
|
181
|
+
"tomato": [255, 99, 71],
|
|
182
|
+
"turquoise": [64, 224, 208],
|
|
183
|
+
"violet": [238, 130, 238],
|
|
184
|
+
"wheat": [245, 222, 179],
|
|
185
|
+
"white": [255, 255, 255],
|
|
186
|
+
"whitesmoke": [245, 245, 245],
|
|
187
|
+
"yellow": [255, 255, 0],
|
|
188
|
+
"yellowgreen": [154, 205, 50]
|
|
189
|
+
};
|
|
190
|
+
return colorName;
|
|
191
|
+
}
|
|
192
|
+
var conversions;
|
|
193
|
+
var hasRequiredConversions;
|
|
194
|
+
function requireConversions() {
|
|
195
|
+
if (hasRequiredConversions) return conversions;
|
|
196
|
+
hasRequiredConversions = 1;
|
|
197
|
+
const cssKeywords = requireColorName();
|
|
198
|
+
const reverseKeywords = {};
|
|
199
|
+
for (const key of Object.keys(cssKeywords)) {
|
|
200
|
+
reverseKeywords[cssKeywords[key]] = key;
|
|
201
|
+
}
|
|
202
|
+
const convert = {
|
|
203
|
+
rgb: { channels: 3, labels: "rgb" },
|
|
204
|
+
hsl: { channels: 3, labels: "hsl" },
|
|
205
|
+
hsv: { channels: 3, labels: "hsv" },
|
|
206
|
+
hwb: { channels: 3, labels: "hwb" },
|
|
207
|
+
cmyk: { channels: 4, labels: "cmyk" },
|
|
208
|
+
xyz: { channels: 3, labels: "xyz" },
|
|
209
|
+
lab: { channels: 3, labels: "lab" },
|
|
210
|
+
lch: { channels: 3, labels: "lch" },
|
|
211
|
+
hex: { channels: 1, labels: ["hex"] },
|
|
212
|
+
keyword: { channels: 1, labels: ["keyword"] },
|
|
213
|
+
ansi16: { channels: 1, labels: ["ansi16"] },
|
|
214
|
+
ansi256: { channels: 1, labels: ["ansi256"] },
|
|
215
|
+
hcg: { channels: 3, labels: ["h", "c", "g"] },
|
|
216
|
+
apple: { channels: 3, labels: ["r16", "g16", "b16"] },
|
|
217
|
+
gray: { channels: 1, labels: ["gray"] }
|
|
218
|
+
};
|
|
219
|
+
conversions = convert;
|
|
220
|
+
for (const model of Object.keys(convert)) {
|
|
221
|
+
if (!("channels" in convert[model])) {
|
|
222
|
+
throw new Error("missing channels property: " + model);
|
|
223
|
+
}
|
|
224
|
+
if (!("labels" in convert[model])) {
|
|
225
|
+
throw new Error("missing channel labels property: " + model);
|
|
226
|
+
}
|
|
227
|
+
if (convert[model].labels.length !== convert[model].channels) {
|
|
228
|
+
throw new Error("channel and label counts mismatch: " + model);
|
|
229
|
+
}
|
|
230
|
+
const { channels, labels } = convert[model];
|
|
231
|
+
delete convert[model].channels;
|
|
232
|
+
delete convert[model].labels;
|
|
233
|
+
Object.defineProperty(convert[model], "channels", { value: channels });
|
|
234
|
+
Object.defineProperty(convert[model], "labels", { value: labels });
|
|
235
|
+
}
|
|
236
|
+
convert.rgb.hsl = function(rgb) {
|
|
237
|
+
const r = rgb[0] / 255;
|
|
238
|
+
const g = rgb[1] / 255;
|
|
239
|
+
const b = rgb[2] / 255;
|
|
240
|
+
const min = Math.min(r, g, b);
|
|
241
|
+
const max = Math.max(r, g, b);
|
|
242
|
+
const delta = max - min;
|
|
243
|
+
let h;
|
|
244
|
+
let s;
|
|
245
|
+
if (max === min) {
|
|
246
|
+
h = 0;
|
|
247
|
+
} else if (r === max) {
|
|
248
|
+
h = (g - b) / delta;
|
|
249
|
+
} else if (g === max) {
|
|
250
|
+
h = 2 + (b - r) / delta;
|
|
251
|
+
} else if (b === max) {
|
|
252
|
+
h = 4 + (r - g) / delta;
|
|
253
|
+
}
|
|
254
|
+
h = Math.min(h * 60, 360);
|
|
255
|
+
if (h < 0) {
|
|
256
|
+
h += 360;
|
|
257
|
+
}
|
|
258
|
+
const l = (min + max) / 2;
|
|
259
|
+
if (max === min) {
|
|
260
|
+
s = 0;
|
|
261
|
+
} else if (l <= 0.5) {
|
|
262
|
+
s = delta / (max + min);
|
|
263
|
+
} else {
|
|
264
|
+
s = delta / (2 - max - min);
|
|
265
|
+
}
|
|
266
|
+
return [h, s * 100, l * 100];
|
|
267
|
+
};
|
|
268
|
+
convert.rgb.hsv = function(rgb) {
|
|
269
|
+
let rdif;
|
|
270
|
+
let gdif;
|
|
271
|
+
let bdif;
|
|
272
|
+
let h;
|
|
273
|
+
let s;
|
|
274
|
+
const r = rgb[0] / 255;
|
|
275
|
+
const g = rgb[1] / 255;
|
|
276
|
+
const b = rgb[2] / 255;
|
|
277
|
+
const v = Math.max(r, g, b);
|
|
278
|
+
const diff = v - Math.min(r, g, b);
|
|
279
|
+
const diffc = function(c) {
|
|
280
|
+
return (v - c) / 6 / diff + 1 / 2;
|
|
281
|
+
};
|
|
282
|
+
if (diff === 0) {
|
|
283
|
+
h = 0;
|
|
284
|
+
s = 0;
|
|
285
|
+
} else {
|
|
286
|
+
s = diff / v;
|
|
287
|
+
rdif = diffc(r);
|
|
288
|
+
gdif = diffc(g);
|
|
289
|
+
bdif = diffc(b);
|
|
290
|
+
if (r === v) {
|
|
291
|
+
h = bdif - gdif;
|
|
292
|
+
} else if (g === v) {
|
|
293
|
+
h = 1 / 3 + rdif - bdif;
|
|
294
|
+
} else if (b === v) {
|
|
295
|
+
h = 2 / 3 + gdif - rdif;
|
|
296
|
+
}
|
|
297
|
+
if (h < 0) {
|
|
298
|
+
h += 1;
|
|
299
|
+
} else if (h > 1) {
|
|
300
|
+
h -= 1;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return [
|
|
304
|
+
h * 360,
|
|
305
|
+
s * 100,
|
|
306
|
+
v * 100
|
|
307
|
+
];
|
|
308
|
+
};
|
|
309
|
+
convert.rgb.hwb = function(rgb) {
|
|
310
|
+
const r = rgb[0];
|
|
311
|
+
const g = rgb[1];
|
|
312
|
+
let b = rgb[2];
|
|
313
|
+
const h = convert.rgb.hsl(rgb)[0];
|
|
314
|
+
const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
|
315
|
+
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
|
316
|
+
return [h, w * 100, b * 100];
|
|
317
|
+
};
|
|
318
|
+
convert.rgb.cmyk = function(rgb) {
|
|
319
|
+
const r = rgb[0] / 255;
|
|
320
|
+
const g = rgb[1] / 255;
|
|
321
|
+
const b = rgb[2] / 255;
|
|
322
|
+
const k = Math.min(1 - r, 1 - g, 1 - b);
|
|
323
|
+
const c = (1 - r - k) / (1 - k) || 0;
|
|
324
|
+
const m = (1 - g - k) / (1 - k) || 0;
|
|
325
|
+
const y = (1 - b - k) / (1 - k) || 0;
|
|
326
|
+
return [c * 100, m * 100, y * 100, k * 100];
|
|
327
|
+
};
|
|
328
|
+
function comparativeDistance(x, y) {
|
|
329
|
+
return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
|
|
330
|
+
}
|
|
331
|
+
convert.rgb.keyword = function(rgb) {
|
|
332
|
+
const reversed = reverseKeywords[rgb];
|
|
333
|
+
if (reversed) {
|
|
334
|
+
return reversed;
|
|
335
|
+
}
|
|
336
|
+
let currentClosestDistance = Infinity;
|
|
337
|
+
let currentClosestKeyword;
|
|
338
|
+
for (const keyword of Object.keys(cssKeywords)) {
|
|
339
|
+
const value = cssKeywords[keyword];
|
|
340
|
+
const distance = comparativeDistance(rgb, value);
|
|
341
|
+
if (distance < currentClosestDistance) {
|
|
342
|
+
currentClosestDistance = distance;
|
|
343
|
+
currentClosestKeyword = keyword;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return currentClosestKeyword;
|
|
347
|
+
};
|
|
348
|
+
convert.keyword.rgb = function(keyword) {
|
|
349
|
+
return cssKeywords[keyword];
|
|
350
|
+
};
|
|
351
|
+
convert.rgb.xyz = function(rgb) {
|
|
352
|
+
let r = rgb[0] / 255;
|
|
353
|
+
let g = rgb[1] / 255;
|
|
354
|
+
let b = rgb[2] / 255;
|
|
355
|
+
r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
|
|
356
|
+
g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
|
|
357
|
+
b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
|
|
358
|
+
const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
|
|
359
|
+
const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
|
360
|
+
const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
|
|
361
|
+
return [x * 100, y * 100, z * 100];
|
|
362
|
+
};
|
|
363
|
+
convert.rgb.lab = function(rgb) {
|
|
364
|
+
const xyz = convert.rgb.xyz(rgb);
|
|
365
|
+
let x = xyz[0];
|
|
366
|
+
let y = xyz[1];
|
|
367
|
+
let z = xyz[2];
|
|
368
|
+
x /= 95.047;
|
|
369
|
+
y /= 100;
|
|
370
|
+
z /= 108.883;
|
|
371
|
+
x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
372
|
+
y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
373
|
+
z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
374
|
+
const l = 116 * y - 16;
|
|
375
|
+
const a = 500 * (x - y);
|
|
376
|
+
const b = 200 * (y - z);
|
|
377
|
+
return [l, a, b];
|
|
378
|
+
};
|
|
379
|
+
convert.hsl.rgb = function(hsl) {
|
|
380
|
+
const h = hsl[0] / 360;
|
|
381
|
+
const s = hsl[1] / 100;
|
|
382
|
+
const l = hsl[2] / 100;
|
|
383
|
+
let t2;
|
|
384
|
+
let t3;
|
|
385
|
+
let val;
|
|
386
|
+
if (s === 0) {
|
|
387
|
+
val = l * 255;
|
|
388
|
+
return [val, val, val];
|
|
389
|
+
}
|
|
390
|
+
if (l < 0.5) {
|
|
391
|
+
t2 = l * (1 + s);
|
|
392
|
+
} else {
|
|
393
|
+
t2 = l + s - l * s;
|
|
394
|
+
}
|
|
395
|
+
const t1 = 2 * l - t2;
|
|
396
|
+
const rgb = [0, 0, 0];
|
|
397
|
+
for (let i = 0; i < 3; i++) {
|
|
398
|
+
t3 = h + 1 / 3 * -(i - 1);
|
|
399
|
+
if (t3 < 0) {
|
|
400
|
+
t3++;
|
|
401
|
+
}
|
|
402
|
+
if (t3 > 1) {
|
|
403
|
+
t3--;
|
|
404
|
+
}
|
|
405
|
+
if (6 * t3 < 1) {
|
|
406
|
+
val = t1 + (t2 - t1) * 6 * t3;
|
|
407
|
+
} else if (2 * t3 < 1) {
|
|
408
|
+
val = t2;
|
|
409
|
+
} else if (3 * t3 < 2) {
|
|
410
|
+
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
|
411
|
+
} else {
|
|
412
|
+
val = t1;
|
|
413
|
+
}
|
|
414
|
+
rgb[i] = val * 255;
|
|
415
|
+
}
|
|
416
|
+
return rgb;
|
|
417
|
+
};
|
|
418
|
+
convert.hsl.hsv = function(hsl) {
|
|
419
|
+
const h = hsl[0];
|
|
420
|
+
let s = hsl[1] / 100;
|
|
421
|
+
let l = hsl[2] / 100;
|
|
422
|
+
let smin = s;
|
|
423
|
+
const lmin = Math.max(l, 0.01);
|
|
424
|
+
l *= 2;
|
|
425
|
+
s *= l <= 1 ? l : 2 - l;
|
|
426
|
+
smin *= lmin <= 1 ? lmin : 2 - lmin;
|
|
427
|
+
const v = (l + s) / 2;
|
|
428
|
+
const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
|
|
429
|
+
return [h, sv * 100, v * 100];
|
|
430
|
+
};
|
|
431
|
+
convert.hsv.rgb = function(hsv) {
|
|
432
|
+
const h = hsv[0] / 60;
|
|
433
|
+
const s = hsv[1] / 100;
|
|
434
|
+
let v = hsv[2] / 100;
|
|
435
|
+
const hi = Math.floor(h) % 6;
|
|
436
|
+
const f = h - Math.floor(h);
|
|
437
|
+
const p = 255 * v * (1 - s);
|
|
438
|
+
const q = 255 * v * (1 - s * f);
|
|
439
|
+
const t = 255 * v * (1 - s * (1 - f));
|
|
440
|
+
v *= 255;
|
|
441
|
+
switch (hi) {
|
|
442
|
+
case 0:
|
|
443
|
+
return [v, t, p];
|
|
444
|
+
case 1:
|
|
445
|
+
return [q, v, p];
|
|
446
|
+
case 2:
|
|
447
|
+
return [p, v, t];
|
|
448
|
+
case 3:
|
|
449
|
+
return [p, q, v];
|
|
450
|
+
case 4:
|
|
451
|
+
return [t, p, v];
|
|
452
|
+
case 5:
|
|
453
|
+
return [v, p, q];
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
convert.hsv.hsl = function(hsv) {
|
|
457
|
+
const h = hsv[0];
|
|
458
|
+
const s = hsv[1] / 100;
|
|
459
|
+
const v = hsv[2] / 100;
|
|
460
|
+
const vmin = Math.max(v, 0.01);
|
|
461
|
+
let sl;
|
|
462
|
+
let l;
|
|
463
|
+
l = (2 - s) * v;
|
|
464
|
+
const lmin = (2 - s) * vmin;
|
|
465
|
+
sl = s * vmin;
|
|
466
|
+
sl /= lmin <= 1 ? lmin : 2 - lmin;
|
|
467
|
+
sl = sl || 0;
|
|
468
|
+
l /= 2;
|
|
469
|
+
return [h, sl * 100, l * 100];
|
|
470
|
+
};
|
|
471
|
+
convert.hwb.rgb = function(hwb) {
|
|
472
|
+
const h = hwb[0] / 360;
|
|
473
|
+
let wh = hwb[1] / 100;
|
|
474
|
+
let bl = hwb[2] / 100;
|
|
475
|
+
const ratio = wh + bl;
|
|
476
|
+
let f;
|
|
477
|
+
if (ratio > 1) {
|
|
478
|
+
wh /= ratio;
|
|
479
|
+
bl /= ratio;
|
|
480
|
+
}
|
|
481
|
+
const i = Math.floor(6 * h);
|
|
482
|
+
const v = 1 - bl;
|
|
483
|
+
f = 6 * h - i;
|
|
484
|
+
if ((i & 1) !== 0) {
|
|
485
|
+
f = 1 - f;
|
|
486
|
+
}
|
|
487
|
+
const n = wh + f * (v - wh);
|
|
488
|
+
let r;
|
|
489
|
+
let g;
|
|
490
|
+
let b;
|
|
491
|
+
switch (i) {
|
|
492
|
+
default:
|
|
493
|
+
case 6:
|
|
494
|
+
case 0:
|
|
495
|
+
r = v;
|
|
496
|
+
g = n;
|
|
497
|
+
b = wh;
|
|
498
|
+
break;
|
|
499
|
+
case 1:
|
|
500
|
+
r = n;
|
|
501
|
+
g = v;
|
|
502
|
+
b = wh;
|
|
503
|
+
break;
|
|
504
|
+
case 2:
|
|
505
|
+
r = wh;
|
|
506
|
+
g = v;
|
|
507
|
+
b = n;
|
|
508
|
+
break;
|
|
509
|
+
case 3:
|
|
510
|
+
r = wh;
|
|
511
|
+
g = n;
|
|
512
|
+
b = v;
|
|
513
|
+
break;
|
|
514
|
+
case 4:
|
|
515
|
+
r = n;
|
|
516
|
+
g = wh;
|
|
517
|
+
b = v;
|
|
518
|
+
break;
|
|
519
|
+
case 5:
|
|
520
|
+
r = v;
|
|
521
|
+
g = wh;
|
|
522
|
+
b = n;
|
|
523
|
+
break;
|
|
524
|
+
}
|
|
525
|
+
return [r * 255, g * 255, b * 255];
|
|
526
|
+
};
|
|
527
|
+
convert.cmyk.rgb = function(cmyk) {
|
|
528
|
+
const c = cmyk[0] / 100;
|
|
529
|
+
const m = cmyk[1] / 100;
|
|
530
|
+
const y = cmyk[2] / 100;
|
|
531
|
+
const k = cmyk[3] / 100;
|
|
532
|
+
const r = 1 - Math.min(1, c * (1 - k) + k);
|
|
533
|
+
const g = 1 - Math.min(1, m * (1 - k) + k);
|
|
534
|
+
const b = 1 - Math.min(1, y * (1 - k) + k);
|
|
535
|
+
return [r * 255, g * 255, b * 255];
|
|
536
|
+
};
|
|
537
|
+
convert.xyz.rgb = function(xyz) {
|
|
538
|
+
const x = xyz[0] / 100;
|
|
539
|
+
const y = xyz[1] / 100;
|
|
540
|
+
const z = xyz[2] / 100;
|
|
541
|
+
let r;
|
|
542
|
+
let g;
|
|
543
|
+
let b;
|
|
544
|
+
r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
545
|
+
g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
546
|
+
b = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
547
|
+
r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
|
|
548
|
+
g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
|
|
549
|
+
b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
|
|
550
|
+
r = Math.min(Math.max(0, r), 1);
|
|
551
|
+
g = Math.min(Math.max(0, g), 1);
|
|
552
|
+
b = Math.min(Math.max(0, b), 1);
|
|
553
|
+
return [r * 255, g * 255, b * 255];
|
|
554
|
+
};
|
|
555
|
+
convert.xyz.lab = function(xyz) {
|
|
556
|
+
let x = xyz[0];
|
|
557
|
+
let y = xyz[1];
|
|
558
|
+
let z = xyz[2];
|
|
559
|
+
x /= 95.047;
|
|
560
|
+
y /= 100;
|
|
561
|
+
z /= 108.883;
|
|
562
|
+
x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
|
563
|
+
y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
|
564
|
+
z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
|
565
|
+
const l = 116 * y - 16;
|
|
566
|
+
const a = 500 * (x - y);
|
|
567
|
+
const b = 200 * (y - z);
|
|
568
|
+
return [l, a, b];
|
|
569
|
+
};
|
|
570
|
+
convert.lab.xyz = function(lab) {
|
|
571
|
+
const l = lab[0];
|
|
572
|
+
const a = lab[1];
|
|
573
|
+
const b = lab[2];
|
|
574
|
+
let x;
|
|
575
|
+
let y;
|
|
576
|
+
let z;
|
|
577
|
+
y = (l + 16) / 116;
|
|
578
|
+
x = a / 500 + y;
|
|
579
|
+
z = y - b / 200;
|
|
580
|
+
const y2 = y ** 3;
|
|
581
|
+
const x2 = x ** 3;
|
|
582
|
+
const z2 = z ** 3;
|
|
583
|
+
y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
|
|
584
|
+
x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
|
|
585
|
+
z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
|
|
586
|
+
x *= 95.047;
|
|
587
|
+
y *= 100;
|
|
588
|
+
z *= 108.883;
|
|
589
|
+
return [x, y, z];
|
|
590
|
+
};
|
|
591
|
+
convert.lab.lch = function(lab) {
|
|
592
|
+
const l = lab[0];
|
|
593
|
+
const a = lab[1];
|
|
594
|
+
const b = lab[2];
|
|
595
|
+
let h;
|
|
596
|
+
const hr = Math.atan2(b, a);
|
|
597
|
+
h = hr * 360 / 2 / Math.PI;
|
|
598
|
+
if (h < 0) {
|
|
599
|
+
h += 360;
|
|
600
|
+
}
|
|
601
|
+
const c = Math.sqrt(a * a + b * b);
|
|
602
|
+
return [l, c, h];
|
|
603
|
+
};
|
|
604
|
+
convert.lch.lab = function(lch) {
|
|
605
|
+
const l = lch[0];
|
|
606
|
+
const c = lch[1];
|
|
607
|
+
const h = lch[2];
|
|
608
|
+
const hr = h / 360 * 2 * Math.PI;
|
|
609
|
+
const a = c * Math.cos(hr);
|
|
610
|
+
const b = c * Math.sin(hr);
|
|
611
|
+
return [l, a, b];
|
|
612
|
+
};
|
|
613
|
+
convert.rgb.ansi16 = function(args, saturation = null) {
|
|
614
|
+
const [r, g, b] = args;
|
|
615
|
+
let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
|
|
616
|
+
value = Math.round(value / 50);
|
|
617
|
+
if (value === 0) {
|
|
618
|
+
return 30;
|
|
619
|
+
}
|
|
620
|
+
let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
|
621
|
+
if (value === 2) {
|
|
622
|
+
ansi += 60;
|
|
623
|
+
}
|
|
624
|
+
return ansi;
|
|
625
|
+
};
|
|
626
|
+
convert.hsv.ansi16 = function(args) {
|
|
627
|
+
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
|
628
|
+
};
|
|
629
|
+
convert.rgb.ansi256 = function(args) {
|
|
630
|
+
const r = args[0];
|
|
631
|
+
const g = args[1];
|
|
632
|
+
const b = args[2];
|
|
633
|
+
if (r === g && g === b) {
|
|
634
|
+
if (r < 8) {
|
|
635
|
+
return 16;
|
|
636
|
+
}
|
|
637
|
+
if (r > 248) {
|
|
638
|
+
return 231;
|
|
639
|
+
}
|
|
640
|
+
return Math.round((r - 8) / 247 * 24) + 232;
|
|
641
|
+
}
|
|
642
|
+
const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
|
643
|
+
return ansi;
|
|
644
|
+
};
|
|
645
|
+
convert.ansi16.rgb = function(args) {
|
|
646
|
+
let color = args % 10;
|
|
647
|
+
if (color === 0 || color === 7) {
|
|
648
|
+
if (args > 50) {
|
|
649
|
+
color += 3.5;
|
|
650
|
+
}
|
|
651
|
+
color = color / 10.5 * 255;
|
|
652
|
+
return [color, color, color];
|
|
653
|
+
}
|
|
654
|
+
const mult = (~~(args > 50) + 1) * 0.5;
|
|
655
|
+
const r = (color & 1) * mult * 255;
|
|
656
|
+
const g = (color >> 1 & 1) * mult * 255;
|
|
657
|
+
const b = (color >> 2 & 1) * mult * 255;
|
|
658
|
+
return [r, g, b];
|
|
659
|
+
};
|
|
660
|
+
convert.ansi256.rgb = function(args) {
|
|
661
|
+
if (args >= 232) {
|
|
662
|
+
const c = (args - 232) * 10 + 8;
|
|
663
|
+
return [c, c, c];
|
|
664
|
+
}
|
|
665
|
+
args -= 16;
|
|
666
|
+
let rem;
|
|
667
|
+
const r = Math.floor(args / 36) / 5 * 255;
|
|
668
|
+
const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
|
669
|
+
const b = rem % 6 / 5 * 255;
|
|
670
|
+
return [r, g, b];
|
|
671
|
+
};
|
|
672
|
+
convert.rgb.hex = function(args) {
|
|
673
|
+
const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
|
|
674
|
+
const string = integer.toString(16).toUpperCase();
|
|
675
|
+
return "000000".substring(string.length) + string;
|
|
676
|
+
};
|
|
677
|
+
convert.hex.rgb = function(args) {
|
|
678
|
+
const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
679
|
+
if (!match) {
|
|
680
|
+
return [0, 0, 0];
|
|
681
|
+
}
|
|
682
|
+
let colorString = match[0];
|
|
683
|
+
if (match[0].length === 3) {
|
|
684
|
+
colorString = colorString.split("").map((char) => {
|
|
685
|
+
return char + char;
|
|
686
|
+
}).join("");
|
|
687
|
+
}
|
|
688
|
+
const integer = parseInt(colorString, 16);
|
|
689
|
+
const r = integer >> 16 & 255;
|
|
690
|
+
const g = integer >> 8 & 255;
|
|
691
|
+
const b = integer & 255;
|
|
692
|
+
return [r, g, b];
|
|
693
|
+
};
|
|
694
|
+
convert.rgb.hcg = function(rgb) {
|
|
695
|
+
const r = rgb[0] / 255;
|
|
696
|
+
const g = rgb[1] / 255;
|
|
697
|
+
const b = rgb[2] / 255;
|
|
698
|
+
const max = Math.max(Math.max(r, g), b);
|
|
699
|
+
const min = Math.min(Math.min(r, g), b);
|
|
700
|
+
const chroma = max - min;
|
|
701
|
+
let grayscale;
|
|
702
|
+
let hue;
|
|
703
|
+
if (chroma < 1) {
|
|
704
|
+
grayscale = min / (1 - chroma);
|
|
705
|
+
} else {
|
|
706
|
+
grayscale = 0;
|
|
707
|
+
}
|
|
708
|
+
if (chroma <= 0) {
|
|
709
|
+
hue = 0;
|
|
710
|
+
} else if (max === r) {
|
|
711
|
+
hue = (g - b) / chroma % 6;
|
|
712
|
+
} else if (max === g) {
|
|
713
|
+
hue = 2 + (b - r) / chroma;
|
|
714
|
+
} else {
|
|
715
|
+
hue = 4 + (r - g) / chroma;
|
|
716
|
+
}
|
|
717
|
+
hue /= 6;
|
|
718
|
+
hue %= 1;
|
|
719
|
+
return [hue * 360, chroma * 100, grayscale * 100];
|
|
720
|
+
};
|
|
721
|
+
convert.hsl.hcg = function(hsl) {
|
|
722
|
+
const s = hsl[1] / 100;
|
|
723
|
+
const l = hsl[2] / 100;
|
|
724
|
+
const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
|
|
725
|
+
let f = 0;
|
|
726
|
+
if (c < 1) {
|
|
727
|
+
f = (l - 0.5 * c) / (1 - c);
|
|
728
|
+
}
|
|
729
|
+
return [hsl[0], c * 100, f * 100];
|
|
730
|
+
};
|
|
731
|
+
convert.hsv.hcg = function(hsv) {
|
|
732
|
+
const s = hsv[1] / 100;
|
|
733
|
+
const v = hsv[2] / 100;
|
|
734
|
+
const c = s * v;
|
|
735
|
+
let f = 0;
|
|
736
|
+
if (c < 1) {
|
|
737
|
+
f = (v - c) / (1 - c);
|
|
738
|
+
}
|
|
739
|
+
return [hsv[0], c * 100, f * 100];
|
|
740
|
+
};
|
|
741
|
+
convert.hcg.rgb = function(hcg) {
|
|
742
|
+
const h = hcg[0] / 360;
|
|
743
|
+
const c = hcg[1] / 100;
|
|
744
|
+
const g = hcg[2] / 100;
|
|
745
|
+
if (c === 0) {
|
|
746
|
+
return [g * 255, g * 255, g * 255];
|
|
747
|
+
}
|
|
748
|
+
const pure = [0, 0, 0];
|
|
749
|
+
const hi = h % 1 * 6;
|
|
750
|
+
const v = hi % 1;
|
|
751
|
+
const w = 1 - v;
|
|
752
|
+
let mg = 0;
|
|
753
|
+
switch (Math.floor(hi)) {
|
|
754
|
+
case 0:
|
|
755
|
+
pure[0] = 1;
|
|
756
|
+
pure[1] = v;
|
|
757
|
+
pure[2] = 0;
|
|
758
|
+
break;
|
|
759
|
+
case 1:
|
|
760
|
+
pure[0] = w;
|
|
761
|
+
pure[1] = 1;
|
|
762
|
+
pure[2] = 0;
|
|
763
|
+
break;
|
|
764
|
+
case 2:
|
|
765
|
+
pure[0] = 0;
|
|
766
|
+
pure[1] = 1;
|
|
767
|
+
pure[2] = v;
|
|
768
|
+
break;
|
|
769
|
+
case 3:
|
|
770
|
+
pure[0] = 0;
|
|
771
|
+
pure[1] = w;
|
|
772
|
+
pure[2] = 1;
|
|
773
|
+
break;
|
|
774
|
+
case 4:
|
|
775
|
+
pure[0] = v;
|
|
776
|
+
pure[1] = 0;
|
|
777
|
+
pure[2] = 1;
|
|
778
|
+
break;
|
|
779
|
+
default:
|
|
780
|
+
pure[0] = 1;
|
|
781
|
+
pure[1] = 0;
|
|
782
|
+
pure[2] = w;
|
|
783
|
+
}
|
|
784
|
+
mg = (1 - c) * g;
|
|
785
|
+
return [
|
|
786
|
+
(c * pure[0] + mg) * 255,
|
|
787
|
+
(c * pure[1] + mg) * 255,
|
|
788
|
+
(c * pure[2] + mg) * 255
|
|
789
|
+
];
|
|
790
|
+
};
|
|
791
|
+
convert.hcg.hsv = function(hcg) {
|
|
792
|
+
const c = hcg[1] / 100;
|
|
793
|
+
const g = hcg[2] / 100;
|
|
794
|
+
const v = c + g * (1 - c);
|
|
795
|
+
let f = 0;
|
|
796
|
+
if (v > 0) {
|
|
797
|
+
f = c / v;
|
|
798
|
+
}
|
|
799
|
+
return [hcg[0], f * 100, v * 100];
|
|
800
|
+
};
|
|
801
|
+
convert.hcg.hsl = function(hcg) {
|
|
802
|
+
const c = hcg[1] / 100;
|
|
803
|
+
const g = hcg[2] / 100;
|
|
804
|
+
const l = g * (1 - c) + 0.5 * c;
|
|
805
|
+
let s = 0;
|
|
806
|
+
if (l > 0 && l < 0.5) {
|
|
807
|
+
s = c / (2 * l);
|
|
808
|
+
} else if (l >= 0.5 && l < 1) {
|
|
809
|
+
s = c / (2 * (1 - l));
|
|
810
|
+
}
|
|
811
|
+
return [hcg[0], s * 100, l * 100];
|
|
812
|
+
};
|
|
813
|
+
convert.hcg.hwb = function(hcg) {
|
|
814
|
+
const c = hcg[1] / 100;
|
|
815
|
+
const g = hcg[2] / 100;
|
|
816
|
+
const v = c + g * (1 - c);
|
|
817
|
+
return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
|
818
|
+
};
|
|
819
|
+
convert.hwb.hcg = function(hwb) {
|
|
820
|
+
const w = hwb[1] / 100;
|
|
821
|
+
const b = hwb[2] / 100;
|
|
822
|
+
const v = 1 - b;
|
|
823
|
+
const c = v - w;
|
|
824
|
+
let g = 0;
|
|
825
|
+
if (c < 1) {
|
|
826
|
+
g = (v - c) / (1 - c);
|
|
827
|
+
}
|
|
828
|
+
return [hwb[0], c * 100, g * 100];
|
|
829
|
+
};
|
|
830
|
+
convert.apple.rgb = function(apple) {
|
|
831
|
+
return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
|
|
832
|
+
};
|
|
833
|
+
convert.rgb.apple = function(rgb) {
|
|
834
|
+
return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
|
|
835
|
+
};
|
|
836
|
+
convert.gray.rgb = function(args) {
|
|
837
|
+
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
|
838
|
+
};
|
|
839
|
+
convert.gray.hsl = function(args) {
|
|
840
|
+
return [0, 0, args[0]];
|
|
841
|
+
};
|
|
842
|
+
convert.gray.hsv = convert.gray.hsl;
|
|
843
|
+
convert.gray.hwb = function(gray) {
|
|
844
|
+
return [0, 100, gray[0]];
|
|
845
|
+
};
|
|
846
|
+
convert.gray.cmyk = function(gray) {
|
|
847
|
+
return [0, 0, 0, gray[0]];
|
|
848
|
+
};
|
|
849
|
+
convert.gray.lab = function(gray) {
|
|
850
|
+
return [gray[0], 0, 0];
|
|
851
|
+
};
|
|
852
|
+
convert.gray.hex = function(gray) {
|
|
853
|
+
const val = Math.round(gray[0] / 100 * 255) & 255;
|
|
854
|
+
const integer = (val << 16) + (val << 8) + val;
|
|
855
|
+
const string = integer.toString(16).toUpperCase();
|
|
856
|
+
return "000000".substring(string.length) + string;
|
|
857
|
+
};
|
|
858
|
+
convert.rgb.gray = function(rgb) {
|
|
859
|
+
const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
|
860
|
+
return [val / 255 * 100];
|
|
861
|
+
};
|
|
862
|
+
return conversions;
|
|
863
|
+
}
|
|
864
|
+
var route;
|
|
865
|
+
var hasRequiredRoute;
|
|
866
|
+
function requireRoute() {
|
|
867
|
+
if (hasRequiredRoute) return route;
|
|
868
|
+
hasRequiredRoute = 1;
|
|
869
|
+
const conversions2 = requireConversions();
|
|
870
|
+
function buildGraph() {
|
|
871
|
+
const graph = {};
|
|
872
|
+
const models = Object.keys(conversions2);
|
|
873
|
+
for (let len = models.length, i = 0; i < len; i++) {
|
|
874
|
+
graph[models[i]] = {
|
|
875
|
+
// http://jsperf.com/1-vs-infinity
|
|
876
|
+
// micro-opt, but this is simple.
|
|
877
|
+
distance: -1,
|
|
878
|
+
parent: null
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
return graph;
|
|
882
|
+
}
|
|
883
|
+
function deriveBFS(fromModel) {
|
|
884
|
+
const graph = buildGraph();
|
|
885
|
+
const queue = [fromModel];
|
|
886
|
+
graph[fromModel].distance = 0;
|
|
887
|
+
while (queue.length) {
|
|
888
|
+
const current = queue.pop();
|
|
889
|
+
const adjacents = Object.keys(conversions2[current]);
|
|
890
|
+
for (let len = adjacents.length, i = 0; i < len; i++) {
|
|
891
|
+
const adjacent = adjacents[i];
|
|
892
|
+
const node = graph[adjacent];
|
|
893
|
+
if (node.distance === -1) {
|
|
894
|
+
node.distance = graph[current].distance + 1;
|
|
895
|
+
node.parent = current;
|
|
896
|
+
queue.unshift(adjacent);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
return graph;
|
|
901
|
+
}
|
|
902
|
+
function link(from, to) {
|
|
903
|
+
return function(args) {
|
|
904
|
+
return to(from(args));
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
function wrapConversion(toModel, graph) {
|
|
908
|
+
const path = [graph[toModel].parent, toModel];
|
|
909
|
+
let fn = conversions2[graph[toModel].parent][toModel];
|
|
910
|
+
let cur = graph[toModel].parent;
|
|
911
|
+
while (graph[cur].parent) {
|
|
912
|
+
path.unshift(graph[cur].parent);
|
|
913
|
+
fn = link(conversions2[graph[cur].parent][cur], fn);
|
|
914
|
+
cur = graph[cur].parent;
|
|
915
|
+
}
|
|
916
|
+
fn.conversion = path;
|
|
917
|
+
return fn;
|
|
918
|
+
}
|
|
919
|
+
route = function(fromModel) {
|
|
920
|
+
const graph = deriveBFS(fromModel);
|
|
921
|
+
const conversion = {};
|
|
922
|
+
const models = Object.keys(graph);
|
|
923
|
+
for (let len = models.length, i = 0; i < len; i++) {
|
|
924
|
+
const toModel = models[i];
|
|
925
|
+
const node = graph[toModel];
|
|
926
|
+
if (node.parent === null) {
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
conversion[toModel] = wrapConversion(toModel, graph);
|
|
930
|
+
}
|
|
931
|
+
return conversion;
|
|
932
|
+
};
|
|
933
|
+
return route;
|
|
934
|
+
}
|
|
935
|
+
var colorConvert;
|
|
936
|
+
var hasRequiredColorConvert;
|
|
937
|
+
function requireColorConvert() {
|
|
938
|
+
if (hasRequiredColorConvert) return colorConvert;
|
|
939
|
+
hasRequiredColorConvert = 1;
|
|
940
|
+
const conversions2 = requireConversions();
|
|
941
|
+
const route2 = requireRoute();
|
|
942
|
+
const convert = {};
|
|
943
|
+
const models = Object.keys(conversions2);
|
|
944
|
+
function wrapRaw(fn) {
|
|
945
|
+
const wrappedFn = function(...args) {
|
|
946
|
+
const arg0 = args[0];
|
|
947
|
+
if (arg0 === void 0 || arg0 === null) {
|
|
948
|
+
return arg0;
|
|
949
|
+
}
|
|
950
|
+
if (arg0.length > 1) {
|
|
951
|
+
args = arg0;
|
|
952
|
+
}
|
|
953
|
+
return fn(args);
|
|
954
|
+
};
|
|
955
|
+
if ("conversion" in fn) {
|
|
956
|
+
wrappedFn.conversion = fn.conversion;
|
|
957
|
+
}
|
|
958
|
+
return wrappedFn;
|
|
959
|
+
}
|
|
960
|
+
function wrapRounded(fn) {
|
|
961
|
+
const wrappedFn = function(...args) {
|
|
962
|
+
const arg0 = args[0];
|
|
963
|
+
if (arg0 === void 0 || arg0 === null) {
|
|
964
|
+
return arg0;
|
|
965
|
+
}
|
|
966
|
+
if (arg0.length > 1) {
|
|
967
|
+
args = arg0;
|
|
968
|
+
}
|
|
969
|
+
const result = fn(args);
|
|
970
|
+
if (typeof result === "object") {
|
|
971
|
+
for (let len = result.length, i = 0; i < len; i++) {
|
|
972
|
+
result[i] = Math.round(result[i]);
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
return result;
|
|
976
|
+
};
|
|
977
|
+
if ("conversion" in fn) {
|
|
978
|
+
wrappedFn.conversion = fn.conversion;
|
|
979
|
+
}
|
|
980
|
+
return wrappedFn;
|
|
981
|
+
}
|
|
982
|
+
models.forEach((fromModel) => {
|
|
983
|
+
convert[fromModel] = {};
|
|
984
|
+
Object.defineProperty(convert[fromModel], "channels", { value: conversions2[fromModel].channels });
|
|
985
|
+
Object.defineProperty(convert[fromModel], "labels", { value: conversions2[fromModel].labels });
|
|
986
|
+
const routes = route2(fromModel);
|
|
987
|
+
const routeModels = Object.keys(routes);
|
|
988
|
+
routeModels.forEach((toModel) => {
|
|
989
|
+
const fn = routes[toModel];
|
|
990
|
+
convert[fromModel][toModel] = wrapRounded(fn);
|
|
991
|
+
convert[fromModel][toModel].raw = wrapRaw(fn);
|
|
992
|
+
});
|
|
993
|
+
});
|
|
994
|
+
colorConvert = convert;
|
|
995
|
+
return colorConvert;
|
|
996
|
+
}
|
|
997
|
+
ansiStyles.exports;
|
|
998
|
+
var hasRequiredAnsiStyles;
|
|
999
|
+
function requireAnsiStyles() {
|
|
1000
|
+
if (hasRequiredAnsiStyles) return ansiStyles.exports;
|
|
1001
|
+
hasRequiredAnsiStyles = 1;
|
|
1002
|
+
(function(module2) {
|
|
1003
|
+
const wrapAnsi16 = (fn, offset) => (...args) => {
|
|
1004
|
+
const code = fn(...args);
|
|
1005
|
+
return `\x1B[${code + offset}m`;
|
|
1006
|
+
};
|
|
1007
|
+
const wrapAnsi256 = (fn, offset) => (...args) => {
|
|
1008
|
+
const code = fn(...args);
|
|
1009
|
+
return `\x1B[${38 + offset};5;${code}m`;
|
|
1010
|
+
};
|
|
1011
|
+
const wrapAnsi16m = (fn, offset) => (...args) => {
|
|
1012
|
+
const rgb = fn(...args);
|
|
1013
|
+
return `\x1B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
|
1014
|
+
};
|
|
1015
|
+
const ansi2ansi = (n) => n;
|
|
1016
|
+
const rgb2rgb = (r, g, b) => [r, g, b];
|
|
1017
|
+
const setLazyProperty = (object, property, get) => {
|
|
1018
|
+
Object.defineProperty(object, property, {
|
|
1019
|
+
get: () => {
|
|
1020
|
+
const value = get();
|
|
1021
|
+
Object.defineProperty(object, property, {
|
|
1022
|
+
value,
|
|
1023
|
+
enumerable: true,
|
|
1024
|
+
configurable: true
|
|
1025
|
+
});
|
|
1026
|
+
return value;
|
|
1027
|
+
},
|
|
1028
|
+
enumerable: true,
|
|
1029
|
+
configurable: true
|
|
1030
|
+
});
|
|
1031
|
+
};
|
|
1032
|
+
let colorConvert2;
|
|
1033
|
+
const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
|
1034
|
+
if (colorConvert2 === void 0) {
|
|
1035
|
+
colorConvert2 = requireColorConvert();
|
|
1036
|
+
}
|
|
1037
|
+
const offset = isBackground ? 10 : 0;
|
|
1038
|
+
const styles = {};
|
|
1039
|
+
for (const [sourceSpace, suite] of Object.entries(colorConvert2)) {
|
|
1040
|
+
const name = sourceSpace === "ansi16" ? "ansi" : sourceSpace;
|
|
1041
|
+
if (sourceSpace === targetSpace) {
|
|
1042
|
+
styles[name] = wrap(identity, offset);
|
|
1043
|
+
} else if (typeof suite === "object") {
|
|
1044
|
+
styles[name] = wrap(suite[targetSpace], offset);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
return styles;
|
|
1048
|
+
};
|
|
1049
|
+
function assembleStyles() {
|
|
1050
|
+
const codes = /* @__PURE__ */ new Map();
|
|
1051
|
+
const styles = {
|
|
1052
|
+
modifier: {
|
|
1053
|
+
reset: [0, 0],
|
|
1054
|
+
// 21 isn't widely supported and 22 does the same thing
|
|
1055
|
+
bold: [1, 22],
|
|
1056
|
+
dim: [2, 22],
|
|
1057
|
+
italic: [3, 23],
|
|
1058
|
+
underline: [4, 24],
|
|
1059
|
+
inverse: [7, 27],
|
|
1060
|
+
hidden: [8, 28],
|
|
1061
|
+
strikethrough: [9, 29]
|
|
1062
|
+
},
|
|
1063
|
+
color: {
|
|
1064
|
+
black: [30, 39],
|
|
1065
|
+
red: [31, 39],
|
|
1066
|
+
green: [32, 39],
|
|
1067
|
+
yellow: [33, 39],
|
|
1068
|
+
blue: [34, 39],
|
|
1069
|
+
magenta: [35, 39],
|
|
1070
|
+
cyan: [36, 39],
|
|
1071
|
+
white: [37, 39],
|
|
1072
|
+
// Bright color
|
|
1073
|
+
blackBright: [90, 39],
|
|
1074
|
+
redBright: [91, 39],
|
|
1075
|
+
greenBright: [92, 39],
|
|
1076
|
+
yellowBright: [93, 39],
|
|
1077
|
+
blueBright: [94, 39],
|
|
1078
|
+
magentaBright: [95, 39],
|
|
1079
|
+
cyanBright: [96, 39],
|
|
1080
|
+
whiteBright: [97, 39]
|
|
1081
|
+
},
|
|
1082
|
+
bgColor: {
|
|
1083
|
+
bgBlack: [40, 49],
|
|
1084
|
+
bgRed: [41, 49],
|
|
1085
|
+
bgGreen: [42, 49],
|
|
1086
|
+
bgYellow: [43, 49],
|
|
1087
|
+
bgBlue: [44, 49],
|
|
1088
|
+
bgMagenta: [45, 49],
|
|
1089
|
+
bgCyan: [46, 49],
|
|
1090
|
+
bgWhite: [47, 49],
|
|
1091
|
+
// Bright color
|
|
1092
|
+
bgBlackBright: [100, 49],
|
|
1093
|
+
bgRedBright: [101, 49],
|
|
1094
|
+
bgGreenBright: [102, 49],
|
|
1095
|
+
bgYellowBright: [103, 49],
|
|
1096
|
+
bgBlueBright: [104, 49],
|
|
1097
|
+
bgMagentaBright: [105, 49],
|
|
1098
|
+
bgCyanBright: [106, 49],
|
|
1099
|
+
bgWhiteBright: [107, 49]
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
styles.color.gray = styles.color.blackBright;
|
|
1103
|
+
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
|
1104
|
+
styles.color.grey = styles.color.blackBright;
|
|
1105
|
+
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
|
1106
|
+
for (const [groupName, group] of Object.entries(styles)) {
|
|
1107
|
+
for (const [styleName, style] of Object.entries(group)) {
|
|
1108
|
+
styles[styleName] = {
|
|
1109
|
+
open: `\x1B[${style[0]}m`,
|
|
1110
|
+
close: `\x1B[${style[1]}m`
|
|
1111
|
+
};
|
|
1112
|
+
group[styleName] = styles[styleName];
|
|
1113
|
+
codes.set(style[0], style[1]);
|
|
1114
|
+
}
|
|
1115
|
+
Object.defineProperty(styles, groupName, {
|
|
1116
|
+
value: group,
|
|
1117
|
+
enumerable: false
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
Object.defineProperty(styles, "codes", {
|
|
1121
|
+
value: codes,
|
|
1122
|
+
enumerable: false
|
|
1123
|
+
});
|
|
1124
|
+
styles.color.close = "\x1B[39m";
|
|
1125
|
+
styles.bgColor.close = "\x1B[49m";
|
|
1126
|
+
setLazyProperty(styles.color, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, false));
|
|
1127
|
+
setLazyProperty(styles.color, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, false));
|
|
1128
|
+
setLazyProperty(styles.color, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, false));
|
|
1129
|
+
setLazyProperty(styles.bgColor, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, true));
|
|
1130
|
+
setLazyProperty(styles.bgColor, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, true));
|
|
1131
|
+
setLazyProperty(styles.bgColor, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, true));
|
|
1132
|
+
return styles;
|
|
1133
|
+
}
|
|
1134
|
+
Object.defineProperty(module2, "exports", {
|
|
1135
|
+
enumerable: true,
|
|
1136
|
+
get: assembleStyles
|
|
1137
|
+
});
|
|
1138
|
+
})(ansiStyles);
|
|
1139
|
+
return ansiStyles.exports;
|
|
1140
|
+
}
|
|
1141
|
+
var browser;
|
|
1142
|
+
var hasRequiredBrowser;
|
|
1143
|
+
function requireBrowser() {
|
|
1144
|
+
if (hasRequiredBrowser) return browser;
|
|
1145
|
+
hasRequiredBrowser = 1;
|
|
1146
|
+
browser = {
|
|
1147
|
+
stdout: false,
|
|
1148
|
+
stderr: false
|
|
1149
|
+
};
|
|
1150
|
+
return browser;
|
|
1151
|
+
}
|
|
1152
|
+
var util;
|
|
1153
|
+
var hasRequiredUtil;
|
|
1154
|
+
function requireUtil() {
|
|
1155
|
+
if (hasRequiredUtil) return util;
|
|
1156
|
+
hasRequiredUtil = 1;
|
|
1157
|
+
const stringReplaceAll = (string, substring, replacer) => {
|
|
1158
|
+
let index = string.indexOf(substring);
|
|
1159
|
+
if (index === -1) {
|
|
1160
|
+
return string;
|
|
1161
|
+
}
|
|
1162
|
+
const substringLength = substring.length;
|
|
1163
|
+
let endIndex = 0;
|
|
1164
|
+
let returnValue = "";
|
|
1165
|
+
do {
|
|
1166
|
+
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
|
1167
|
+
endIndex = index + substringLength;
|
|
1168
|
+
index = string.indexOf(substring, endIndex);
|
|
1169
|
+
} while (index !== -1);
|
|
1170
|
+
returnValue += string.substr(endIndex);
|
|
1171
|
+
return returnValue;
|
|
1172
|
+
};
|
|
1173
|
+
const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
|
1174
|
+
let endIndex = 0;
|
|
1175
|
+
let returnValue = "";
|
|
1176
|
+
do {
|
|
1177
|
+
const gotCR = string[index - 1] === "\r";
|
|
1178
|
+
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
|
|
1179
|
+
endIndex = index + 1;
|
|
1180
|
+
index = string.indexOf("\n", endIndex);
|
|
1181
|
+
} while (index !== -1);
|
|
1182
|
+
returnValue += string.substr(endIndex);
|
|
1183
|
+
return returnValue;
|
|
1184
|
+
};
|
|
1185
|
+
util = {
|
|
1186
|
+
stringReplaceAll,
|
|
1187
|
+
stringEncaseCRLFWithFirstIndex
|
|
1188
|
+
};
|
|
1189
|
+
return util;
|
|
1190
|
+
}
|
|
1191
|
+
var templates;
|
|
1192
|
+
var hasRequiredTemplates;
|
|
1193
|
+
function requireTemplates() {
|
|
1194
|
+
if (hasRequiredTemplates) return templates;
|
|
1195
|
+
hasRequiredTemplates = 1;
|
|
1196
|
+
const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
|
1197
|
+
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
|
1198
|
+
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
|
1199
|
+
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
|
|
1200
|
+
const ESCAPES = /* @__PURE__ */ new Map([
|
|
1201
|
+
["n", "\n"],
|
|
1202
|
+
["r", "\r"],
|
|
1203
|
+
["t", " "],
|
|
1204
|
+
["b", "\b"],
|
|
1205
|
+
["f", "\f"],
|
|
1206
|
+
["v", "\v"],
|
|
1207
|
+
["0", "\0"],
|
|
1208
|
+
["\\", "\\"],
|
|
1209
|
+
["e", "\x1B"],
|
|
1210
|
+
["a", "\x07"]
|
|
1211
|
+
]);
|
|
1212
|
+
function unescape2(c) {
|
|
1213
|
+
const u = c[0] === "u";
|
|
1214
|
+
const bracket = c[1] === "{";
|
|
1215
|
+
if (u && !bracket && c.length === 5 || c[0] === "x" && c.length === 3) {
|
|
1216
|
+
return String.fromCharCode(parseInt(c.slice(1), 16));
|
|
1217
|
+
}
|
|
1218
|
+
if (u && bracket) {
|
|
1219
|
+
return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
|
|
1220
|
+
}
|
|
1221
|
+
return ESCAPES.get(c) || c;
|
|
1222
|
+
}
|
|
1223
|
+
function parseArguments(name, arguments_) {
|
|
1224
|
+
const results = [];
|
|
1225
|
+
const chunks = arguments_.trim().split(/\s*,\s*/g);
|
|
1226
|
+
let matches;
|
|
1227
|
+
for (const chunk of chunks) {
|
|
1228
|
+
const number = Number(chunk);
|
|
1229
|
+
if (!Number.isNaN(number)) {
|
|
1230
|
+
results.push(number);
|
|
1231
|
+
} else if (matches = chunk.match(STRING_REGEX)) {
|
|
1232
|
+
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape2, character) => escape2 ? unescape2(escape2) : character));
|
|
1233
|
+
} else {
|
|
1234
|
+
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
return results;
|
|
1238
|
+
}
|
|
1239
|
+
function parseStyle(style) {
|
|
1240
|
+
STYLE_REGEX.lastIndex = 0;
|
|
1241
|
+
const results = [];
|
|
1242
|
+
let matches;
|
|
1243
|
+
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
|
1244
|
+
const name = matches[1];
|
|
1245
|
+
if (matches[2]) {
|
|
1246
|
+
const args = parseArguments(name, matches[2]);
|
|
1247
|
+
results.push([name].concat(args));
|
|
1248
|
+
} else {
|
|
1249
|
+
results.push([name]);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
return results;
|
|
1253
|
+
}
|
|
1254
|
+
function buildStyle(chalk2, styles) {
|
|
1255
|
+
const enabled = {};
|
|
1256
|
+
for (const layer of styles) {
|
|
1257
|
+
for (const style of layer.styles) {
|
|
1258
|
+
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
let current = chalk2;
|
|
1262
|
+
for (const [styleName, styles2] of Object.entries(enabled)) {
|
|
1263
|
+
if (!Array.isArray(styles2)) {
|
|
1264
|
+
continue;
|
|
1265
|
+
}
|
|
1266
|
+
if (!(styleName in current)) {
|
|
1267
|
+
throw new Error(`Unknown Chalk style: ${styleName}`);
|
|
1268
|
+
}
|
|
1269
|
+
current = styles2.length > 0 ? current[styleName](...styles2) : current[styleName];
|
|
1270
|
+
}
|
|
1271
|
+
return current;
|
|
1272
|
+
}
|
|
1273
|
+
templates = (chalk2, temporary) => {
|
|
1274
|
+
const styles = [];
|
|
1275
|
+
const chunks = [];
|
|
1276
|
+
let chunk = [];
|
|
1277
|
+
temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
|
|
1278
|
+
if (escapeCharacter) {
|
|
1279
|
+
chunk.push(unescape2(escapeCharacter));
|
|
1280
|
+
} else if (style) {
|
|
1281
|
+
const string = chunk.join("");
|
|
1282
|
+
chunk = [];
|
|
1283
|
+
chunks.push(styles.length === 0 ? string : buildStyle(chalk2, styles)(string));
|
|
1284
|
+
styles.push({ inverse, styles: parseStyle(style) });
|
|
1285
|
+
} else if (close) {
|
|
1286
|
+
if (styles.length === 0) {
|
|
1287
|
+
throw new Error("Found extraneous } in Chalk template literal");
|
|
1288
|
+
}
|
|
1289
|
+
chunks.push(buildStyle(chalk2, styles)(chunk.join("")));
|
|
1290
|
+
chunk = [];
|
|
1291
|
+
styles.pop();
|
|
1292
|
+
} else {
|
|
1293
|
+
chunk.push(character);
|
|
1294
|
+
}
|
|
1295
|
+
});
|
|
1296
|
+
chunks.push(chunk.join(""));
|
|
1297
|
+
if (styles.length > 0) {
|
|
1298
|
+
const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`;
|
|
1299
|
+
throw new Error(errMessage);
|
|
1300
|
+
}
|
|
1301
|
+
return chunks.join("");
|
|
1302
|
+
};
|
|
1303
|
+
return templates;
|
|
1304
|
+
}
|
|
1305
|
+
var source;
|
|
1306
|
+
var hasRequiredSource;
|
|
1307
|
+
function requireSource() {
|
|
1308
|
+
if (hasRequiredSource) return source;
|
|
1309
|
+
hasRequiredSource = 1;
|
|
1310
|
+
const ansiStyles2 = requireAnsiStyles();
|
|
1311
|
+
const { stdout: stdoutColor, stderr: stderrColor } = requireBrowser();
|
|
1312
|
+
const {
|
|
1313
|
+
stringReplaceAll,
|
|
1314
|
+
stringEncaseCRLFWithFirstIndex
|
|
1315
|
+
} = requireUtil();
|
|
1316
|
+
const { isArray } = Array;
|
|
1317
|
+
const levelMapping = [
|
|
1318
|
+
"ansi",
|
|
1319
|
+
"ansi",
|
|
1320
|
+
"ansi256",
|
|
1321
|
+
"ansi16m"
|
|
1322
|
+
];
|
|
1323
|
+
const styles = /* @__PURE__ */ Object.create(null);
|
|
1324
|
+
const applyOptions = (object, options = {}) => {
|
|
1325
|
+
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
|
1326
|
+
throw new Error("The `level` option should be an integer from 0 to 3");
|
|
1327
|
+
}
|
|
1328
|
+
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
1329
|
+
object.level = options.level === void 0 ? colorLevel : options.level;
|
|
1330
|
+
};
|
|
1331
|
+
class ChalkClass {
|
|
1332
|
+
constructor(options) {
|
|
1333
|
+
return chalkFactory(options);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
const chalkFactory = (options) => {
|
|
1337
|
+
const chalk3 = {};
|
|
1338
|
+
applyOptions(chalk3, options);
|
|
1339
|
+
chalk3.template = (...arguments_) => chalkTag(chalk3.template, ...arguments_);
|
|
1340
|
+
Object.setPrototypeOf(chalk3, Chalk.prototype);
|
|
1341
|
+
Object.setPrototypeOf(chalk3.template, chalk3);
|
|
1342
|
+
chalk3.template.constructor = () => {
|
|
1343
|
+
throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
|
|
1344
|
+
};
|
|
1345
|
+
chalk3.template.Instance = ChalkClass;
|
|
1346
|
+
return chalk3.template;
|
|
1347
|
+
};
|
|
1348
|
+
function Chalk(options) {
|
|
1349
|
+
return chalkFactory(options);
|
|
1350
|
+
}
|
|
1351
|
+
for (const [styleName, style] of Object.entries(ansiStyles2)) {
|
|
1352
|
+
styles[styleName] = {
|
|
1353
|
+
get() {
|
|
1354
|
+
const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
|
|
1355
|
+
Object.defineProperty(this, styleName, { value: builder });
|
|
1356
|
+
return builder;
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
styles.visible = {
|
|
1361
|
+
get() {
|
|
1362
|
+
const builder = createBuilder(this, this._styler, true);
|
|
1363
|
+
Object.defineProperty(this, "visible", { value: builder });
|
|
1364
|
+
return builder;
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
const usedModels = ["rgb", "hex", "keyword", "hsl", "hsv", "hwb", "ansi", "ansi256"];
|
|
1368
|
+
for (const model of usedModels) {
|
|
1369
|
+
styles[model] = {
|
|
1370
|
+
get() {
|
|
1371
|
+
const { level } = this;
|
|
1372
|
+
return function(...arguments_) {
|
|
1373
|
+
const styler = createStyler(ansiStyles2.color[levelMapping[level]][model](...arguments_), ansiStyles2.color.close, this._styler);
|
|
1374
|
+
return createBuilder(this, styler, this._isEmpty);
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
for (const model of usedModels) {
|
|
1380
|
+
const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
|
|
1381
|
+
styles[bgModel] = {
|
|
1382
|
+
get() {
|
|
1383
|
+
const { level } = this;
|
|
1384
|
+
return function(...arguments_) {
|
|
1385
|
+
const styler = createStyler(ansiStyles2.bgColor[levelMapping[level]][model](...arguments_), ansiStyles2.bgColor.close, this._styler);
|
|
1386
|
+
return createBuilder(this, styler, this._isEmpty);
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
const proto = Object.defineProperties(() => {
|
|
1392
|
+
}, {
|
|
1393
|
+
...styles,
|
|
1394
|
+
level: {
|
|
1395
|
+
enumerable: true,
|
|
1396
|
+
get() {
|
|
1397
|
+
return this._generator.level;
|
|
1398
|
+
},
|
|
1399
|
+
set(level) {
|
|
1400
|
+
this._generator.level = level;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
const createStyler = (open, close, parent) => {
|
|
1405
|
+
let openAll;
|
|
1406
|
+
let closeAll;
|
|
1407
|
+
if (parent === void 0) {
|
|
1408
|
+
openAll = open;
|
|
1409
|
+
closeAll = close;
|
|
1410
|
+
} else {
|
|
1411
|
+
openAll = parent.openAll + open;
|
|
1412
|
+
closeAll = close + parent.closeAll;
|
|
1413
|
+
}
|
|
1414
|
+
return {
|
|
1415
|
+
open,
|
|
1416
|
+
close,
|
|
1417
|
+
openAll,
|
|
1418
|
+
closeAll,
|
|
1419
|
+
parent
|
|
1420
|
+
};
|
|
1421
|
+
};
|
|
1422
|
+
const createBuilder = (self2, _styler, _isEmpty) => {
|
|
1423
|
+
const builder = (...arguments_) => {
|
|
1424
|
+
if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
|
|
1425
|
+
return applyStyle(builder, chalkTag(builder, ...arguments_));
|
|
1426
|
+
}
|
|
1427
|
+
return applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
|
|
1428
|
+
};
|
|
1429
|
+
Object.setPrototypeOf(builder, proto);
|
|
1430
|
+
builder._generator = self2;
|
|
1431
|
+
builder._styler = _styler;
|
|
1432
|
+
builder._isEmpty = _isEmpty;
|
|
1433
|
+
return builder;
|
|
1434
|
+
};
|
|
1435
|
+
const applyStyle = (self2, string) => {
|
|
1436
|
+
if (self2.level <= 0 || !string) {
|
|
1437
|
+
return self2._isEmpty ? "" : string;
|
|
1438
|
+
}
|
|
1439
|
+
let styler = self2._styler;
|
|
1440
|
+
if (styler === void 0) {
|
|
1441
|
+
return string;
|
|
1442
|
+
}
|
|
1443
|
+
const { openAll, closeAll } = styler;
|
|
1444
|
+
if (string.indexOf("\x1B") !== -1) {
|
|
1445
|
+
while (styler !== void 0) {
|
|
1446
|
+
string = stringReplaceAll(string, styler.close, styler.open);
|
|
1447
|
+
styler = styler.parent;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
const lfIndex = string.indexOf("\n");
|
|
1451
|
+
if (lfIndex !== -1) {
|
|
1452
|
+
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
1453
|
+
}
|
|
1454
|
+
return openAll + string + closeAll;
|
|
1455
|
+
};
|
|
1456
|
+
let template;
|
|
1457
|
+
const chalkTag = (chalk3, ...strings) => {
|
|
1458
|
+
const [firstString] = strings;
|
|
1459
|
+
if (!isArray(firstString) || !isArray(firstString.raw)) {
|
|
1460
|
+
return strings.join(" ");
|
|
1461
|
+
}
|
|
1462
|
+
const arguments_ = strings.slice(1);
|
|
1463
|
+
const parts = [firstString.raw[0]];
|
|
1464
|
+
for (let i = 1; i < firstString.length; i++) {
|
|
1465
|
+
parts.push(
|
|
1466
|
+
String(arguments_[i - 1]).replace(/[{}\\]/g, "\\$&"),
|
|
1467
|
+
String(firstString.raw[i])
|
|
1468
|
+
);
|
|
1469
|
+
}
|
|
1470
|
+
if (template === void 0) {
|
|
1471
|
+
template = requireTemplates();
|
|
1472
|
+
}
|
|
1473
|
+
return template(chalk3, parts.join(""));
|
|
1474
|
+
};
|
|
1475
|
+
Object.defineProperties(Chalk.prototype, styles);
|
|
1476
|
+
const chalk2 = Chalk();
|
|
1477
|
+
chalk2.supportsColor = stdoutColor;
|
|
1478
|
+
chalk2.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
1479
|
+
chalk2.stderr.supportsColor = stderrColor;
|
|
1480
|
+
source = chalk2;
|
|
1481
|
+
return source;
|
|
1482
|
+
}
|
|
1483
|
+
var sourceExports = requireSource();
|
|
1484
|
+
const chalk = /* @__PURE__ */ getDefaultExportFromCjs(sourceExports);
|
|
1485
|
+
const isNode = Object.prototype.toString.call(typeof process !== "undefined" ? process : 0) === "[object process]";
|
|
1486
|
+
var AuthorizeOptionsResponseType = /* @__PURE__ */ ((AuthorizeOptionsResponseType2) => {
|
|
1487
|
+
AuthorizeOptionsResponseType2["CODE"] = "code";
|
|
1488
|
+
AuthorizeOptionsResponseType2["ID_TOKEN"] = "id_token";
|
|
1489
|
+
AuthorizeOptionsResponseType2["TOKEN"] = "token";
|
|
1490
|
+
return AuthorizeOptionsResponseType2;
|
|
1491
|
+
})(AuthorizeOptionsResponseType || {});
|
|
1492
|
+
var AuthorizeOptionsResponseMode = /* @__PURE__ */ ((AuthorizeOptionsResponseMode2) => {
|
|
1493
|
+
AuthorizeOptionsResponseMode2["QUERY"] = "query";
|
|
1494
|
+
AuthorizeOptionsResponseMode2["FRAGMENT"] = "fragment";
|
|
1495
|
+
AuthorizeOptionsResponseMode2["FORM_POST"] = "form_post";
|
|
1496
|
+
return AuthorizeOptionsResponseMode2;
|
|
1497
|
+
})(AuthorizeOptionsResponseMode || {});
|
|
1498
|
+
var OAuthGrantTypes = /* @__PURE__ */ ((OAuthGrantTypes2) => {
|
|
1499
|
+
OAuthGrantTypes2["CLIENT_CREDENTIALS"] = "client_credentials";
|
|
1500
|
+
OAuthGrantTypes2["AUTHORIZATION_CODE"] = "authorization_code";
|
|
1501
|
+
OAuthGrantTypes2["REFRESH_TOKEN"] = "refresh_token";
|
|
1502
|
+
return OAuthGrantTypes2;
|
|
1503
|
+
})(OAuthGrantTypes || {});
|
|
1504
|
+
var IOauth2ListenerCommand = /* @__PURE__ */ ((IOauth2ListenerCommand2) => {
|
|
1505
|
+
IOauth2ListenerCommand2["RESTORE_SESSION"] = "RestoreSession";
|
|
1506
|
+
IOauth2ListenerCommand2["AUTHORIZE"] = "Authorize";
|
|
1507
|
+
IOauth2ListenerCommand2["HANDLE_REDIRECT"] = "HandleRedirect";
|
|
1508
|
+
IOauth2ListenerCommand2["LOGOUT"] = "Logout";
|
|
1509
|
+
IOauth2ListenerCommand2["AUTHENTICATE_EVENT"] = "AuthenticateEvent";
|
|
1510
|
+
IOauth2ListenerCommand2["ERROR"] = "Error";
|
|
1511
|
+
IOauth2ListenerCommand2["LOG"] = "__LOG";
|
|
1512
|
+
IOauth2ListenerCommand2["UPDATE_INSTRUMENT"] = "__UPDATE_INSTRUMENT";
|
|
1513
|
+
IOauth2ListenerCommand2["ID_TOKEN"] = "__ID_TOKEN";
|
|
1514
|
+
IOauth2ListenerCommand2["ACCESS_TOKEN"] = "__ACCESS_TOKEN";
|
|
1515
|
+
IOauth2ListenerCommand2["COOKIES"] = "__COOKIES";
|
|
1516
|
+
IOauth2ListenerCommand2["EXECUTE_REFRESH_TOKEN"] = "__EXECUTE_REFRESH_TOKEN";
|
|
1517
|
+
return IOauth2ListenerCommand2;
|
|
1518
|
+
})(IOauth2ListenerCommand || {});
|
|
1519
|
+
class InvalidTokenError extends Error {
|
|
1520
|
+
}
|
|
1521
|
+
InvalidTokenError.prototype.name = "InvalidTokenError";
|
|
1522
|
+
function b64DecodeUnicode(str) {
|
|
1523
|
+
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => {
|
|
1524
|
+
let code = p.charCodeAt(0).toString(16).toUpperCase();
|
|
1525
|
+
if (code.length < 2) {
|
|
1526
|
+
code = "0" + code;
|
|
1527
|
+
}
|
|
1528
|
+
return "%" + code;
|
|
1529
|
+
}));
|
|
1530
|
+
}
|
|
1531
|
+
function base64UrlDecode(str) {
|
|
1532
|
+
let output = str.replace(/-/g, "+").replace(/_/g, "/");
|
|
1533
|
+
switch (output.length % 4) {
|
|
1534
|
+
case 0:
|
|
1535
|
+
break;
|
|
1536
|
+
case 2:
|
|
1537
|
+
output += "==";
|
|
1538
|
+
break;
|
|
1539
|
+
case 3:
|
|
1540
|
+
output += "=";
|
|
1541
|
+
break;
|
|
1542
|
+
default:
|
|
1543
|
+
throw new Error("base64 string is not of the correct length");
|
|
1544
|
+
}
|
|
1545
|
+
try {
|
|
1546
|
+
return b64DecodeUnicode(output);
|
|
1547
|
+
} catch (err) {
|
|
1548
|
+
return atob(output);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
function jwtDecode(token, options) {
|
|
1552
|
+
if (typeof token !== "string") {
|
|
1553
|
+
throw new InvalidTokenError("Invalid token specified: must be a string");
|
|
1554
|
+
}
|
|
1555
|
+
options || (options = {});
|
|
1556
|
+
const pos = options.header === true ? 0 : 1;
|
|
1557
|
+
const part = token.split(".")[pos];
|
|
1558
|
+
if (typeof part !== "string") {
|
|
1559
|
+
throw new InvalidTokenError(`Invalid token specified: missing part #${pos + 1}`);
|
|
1560
|
+
}
|
|
1561
|
+
let decoded;
|
|
1562
|
+
try {
|
|
1563
|
+
decoded = base64UrlDecode(part);
|
|
1564
|
+
} catch (e) {
|
|
1565
|
+
throw new InvalidTokenError(`Invalid token specified: invalid base64 for part #${pos + 1} (${e.message})`);
|
|
1566
|
+
}
|
|
1567
|
+
try {
|
|
1568
|
+
return JSON.parse(decoded);
|
|
1569
|
+
} catch (e) {
|
|
1570
|
+
throw new InvalidTokenError(`Invalid token specified: invalid json for part #${pos + 1} (${e.message})`);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
const STSOauth2Store = pinia.defineStore("__sts__STSOauth2Store", {
|
|
1574
|
+
state: () => {
|
|
1575
|
+
return {
|
|
1576
|
+
id_token: null,
|
|
1577
|
+
error: null
|
|
1578
|
+
};
|
|
1579
|
+
},
|
|
1580
|
+
actions: {
|
|
1581
|
+
UpdateIdToken(id_token) {
|
|
1582
|
+
this.id_token = id_token;
|
|
1583
|
+
},
|
|
1584
|
+
UpdateError(error) {
|
|
1585
|
+
if (this.error) {
|
|
1586
|
+
this.error.message = error;
|
|
1587
|
+
} else {
|
|
1588
|
+
this.error = {
|
|
1589
|
+
message: error
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
},
|
|
1594
|
+
getters: {
|
|
1595
|
+
LoggedIn: (state) => {
|
|
1596
|
+
if (typeof state.id_token === "undefined") {
|
|
1597
|
+
return false;
|
|
1598
|
+
}
|
|
1599
|
+
if (state.id_token === null) {
|
|
1600
|
+
return false;
|
|
1601
|
+
}
|
|
1602
|
+
return true;
|
|
1603
|
+
},
|
|
1604
|
+
UserDetails: (state) => {
|
|
1605
|
+
if (state.id_token) {
|
|
1606
|
+
const id_token = state.id_token;
|
|
1607
|
+
const decodedIdToken = jwtDecode(id_token);
|
|
1608
|
+
return decodedIdToken;
|
|
1609
|
+
} else {
|
|
1610
|
+
return null;
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
/*
|
|
1615
|
+
persist: {
|
|
1616
|
+
storage: globalThis.sessionStorage
|
|
1617
|
+
}
|
|
1618
|
+
*/
|
|
1619
|
+
});
|
|
1620
|
+
class STSOAuth2Manager {
|
|
1621
|
+
#router = null;
|
|
1622
|
+
#STORAGE_AUTHORIZE_OPTIONS_KEY = "authorize_options.stsmda.com.au";
|
|
1623
|
+
#aic = null;
|
|
1624
|
+
#options;
|
|
1625
|
+
#oauth2ManagerPort;
|
|
1626
|
+
#messageId = 0;
|
|
1627
|
+
#messageHandlers = {};
|
|
1628
|
+
// keyed by messageId
|
|
1629
|
+
#messageTimeout = 1e4;
|
|
1630
|
+
#worker;
|
|
1631
|
+
#transactionStore;
|
|
1632
|
+
// Transient transaction data used to establish a session via OAuth2 authorize handshake
|
|
1633
|
+
#operationSemaphore = false;
|
|
1634
|
+
#maxSemaphoreRetries = 100;
|
|
1635
|
+
// 100 retries, i.e. allow 100 x 50 = 5000ms to unblock
|
|
1636
|
+
#semaphoreRetrySleep = 50;
|
|
1637
|
+
// ms
|
|
1638
|
+
constructor(app, options) {
|
|
1639
|
+
this.#options = options;
|
|
1640
|
+
if (!isNode) {
|
|
1641
|
+
if (app.config.globalProperties.$sts[stsobservability.STSInstrumentControllerPluginKey]) {
|
|
1642
|
+
const STSInstrumentController = app.config.globalProperties.$sts[stsobservability.STSInstrumentControllerPluginKey];
|
|
1643
|
+
this.#aic = STSInstrumentController;
|
|
1644
|
+
}
|
|
1645
|
+
this.#router = app.config.globalProperties.$router;
|
|
1646
|
+
}
|
|
1647
|
+
if (isNode) {
|
|
1648
|
+
this.#transactionStore = new stsvueutils.ClientStorageFactory({ clientStorageType: stsvueutils.ClientStorageType.MEMORY_STORAGE, usePrefix: false }).GetStorage();
|
|
1649
|
+
} else {
|
|
1650
|
+
this.#transactionStore = new stsvueutils.ClientStorageFactory({ clientStorageType: stsvueutils.ClientStorageType.SESSION_STORAGE, usePrefix: false }).GetStorage();
|
|
1651
|
+
}
|
|
1652
|
+
if (this.#options.workerFactory) {
|
|
1653
|
+
this.#worker = this.#options.workerFactory();
|
|
1654
|
+
} else {
|
|
1655
|
+
throw new Error(`STSOAuth2Manager:constructor: Cannot init STSOAuth2Manager - this.#options.workerFactory not specified`);
|
|
1656
|
+
}
|
|
1657
|
+
if (!isNode) {
|
|
1658
|
+
this.#worker.onmessage = (data) => {
|
|
1659
|
+
this.#LogInfoMessage(chalk.green(`this.#worker.onmessage = [${data}]`));
|
|
1660
|
+
};
|
|
1661
|
+
this.#worker.onerror = (error) => {
|
|
1662
|
+
this.#LogInfoMessage(chalk.green(`this.#worker.onerror = [${JSON.stringify(error)}]`));
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
let workerMessage;
|
|
1666
|
+
if (isNode) {
|
|
1667
|
+
const {
|
|
1668
|
+
port1: oauth2ManagerPort,
|
|
1669
|
+
// this process port
|
|
1670
|
+
port2: oauth2WorkerPort
|
|
1671
|
+
// worker port
|
|
1672
|
+
} = new wt__namespace.MessageChannel();
|
|
1673
|
+
this.#oauth2ManagerPort = oauth2ManagerPort;
|
|
1674
|
+
workerMessage = {
|
|
1675
|
+
workerPort: oauth2WorkerPort,
|
|
1676
|
+
options: this.#options.workerOptions
|
|
1677
|
+
};
|
|
1678
|
+
this.#worker.postMessage(workerMessage, [oauth2WorkerPort]);
|
|
1679
|
+
this.#oauth2ManagerPort.on("message", (payload) => {
|
|
1680
|
+
this.#ProcessMessageResponse(payload);
|
|
1681
|
+
}).unref();
|
|
1682
|
+
} else {
|
|
1683
|
+
const {
|
|
1684
|
+
port1: oauth2ManagerPort,
|
|
1685
|
+
// this process port
|
|
1686
|
+
port2: oauth2WorkerPort
|
|
1687
|
+
// worker port
|
|
1688
|
+
} = new MessageChannel();
|
|
1689
|
+
this.#oauth2ManagerPort = oauth2ManagerPort;
|
|
1690
|
+
workerMessage = {
|
|
1691
|
+
workerPort: oauth2WorkerPort,
|
|
1692
|
+
options: this.#options.workerOptions
|
|
1693
|
+
};
|
|
1694
|
+
this.#worker.postMessage(workerMessage, [oauth2WorkerPort]);
|
|
1695
|
+
this.#oauth2ManagerPort.onmessage = (data) => {
|
|
1696
|
+
this.#ProcessMessageResponse(data.data);
|
|
1697
|
+
};
|
|
1698
|
+
this.#SetupRoute(app, this.#router);
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
#LogDebugMessage(message) {
|
|
1702
|
+
this.#options.logger.debug(message);
|
|
1703
|
+
}
|
|
1704
|
+
#LogInfoMessage(message) {
|
|
1705
|
+
this.#options.logger.info(message);
|
|
1706
|
+
}
|
|
1707
|
+
#LogErrorMessage(message) {
|
|
1708
|
+
this.#options.logger.error(message);
|
|
1709
|
+
}
|
|
1710
|
+
#ProcessMessageResponse = (data) => {
|
|
1711
|
+
const messageResponse = data;
|
|
1712
|
+
this.#LogDebugMessage(chalk.yellow(`STSOAuth2Manager:#ProcessMessageResponse: message data = [${JSON.stringify(messageResponse)}]`));
|
|
1713
|
+
if (messageResponse.messageId === -1) {
|
|
1714
|
+
switch (messageResponse.command) {
|
|
1715
|
+
case IOauth2ListenerCommand.AUTHENTICATE_EVENT:
|
|
1716
|
+
this.#HandleAuthenticateEvent(messageResponse.payload);
|
|
1717
|
+
break;
|
|
1718
|
+
case IOauth2ListenerCommand.ERROR:
|
|
1719
|
+
this.#HandleErrorEvent(messageResponse.payload);
|
|
1720
|
+
break;
|
|
1721
|
+
case IOauth2ListenerCommand.LOG:
|
|
1722
|
+
this.#HandleLogEvent(messageResponse.payload);
|
|
1723
|
+
break;
|
|
1724
|
+
case IOauth2ListenerCommand.UPDATE_INSTRUMENT:
|
|
1725
|
+
this.#HandleUpdateInstrumentEvent(messageResponse.payload.instrumentName, messageResponse.payload.telemetry);
|
|
1726
|
+
break;
|
|
1727
|
+
default:
|
|
1728
|
+
throw new Error(`ProcessMessageResponse command [${messageResponse.command}] not valid.`);
|
|
1729
|
+
}
|
|
1730
|
+
} else {
|
|
1731
|
+
const callBack = this.#messageHandlers[messageResponse.messageId];
|
|
1732
|
+
if (callBack) {
|
|
1733
|
+
callBack(messageResponse);
|
|
1734
|
+
} else {
|
|
1735
|
+
throw new Error(`Message: [${messageResponse.messageId}] does not exists in callBacks.`);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
#PostMessage = (message) => {
|
|
1740
|
+
message.messageId = this.#messageId++;
|
|
1741
|
+
return new Promise((resolve, reject) => {
|
|
1742
|
+
const timeout = setTimeout(() => {
|
|
1743
|
+
delete this.#messageHandlers[message.messageId];
|
|
1744
|
+
reject(`Message: [${message.messageId}] timeout error after: [${this.#messageTimeout}] ms.`);
|
|
1745
|
+
}, this.#messageTimeout);
|
|
1746
|
+
this.#messageHandlers[message.messageId] = (response) => {
|
|
1747
|
+
clearTimeout(timeout);
|
|
1748
|
+
delete this.#messageHandlers[message.messageId];
|
|
1749
|
+
this.#LogDebugMessage(chalk.yellow(`STSOAuth2Manager:#PostMessage: resolve callback response= [${JSON.stringify(response)}]`));
|
|
1750
|
+
resolve(response);
|
|
1751
|
+
};
|
|
1752
|
+
this.#LogDebugMessage(chalk.yellow(`STSOAuth2Manager:#PostMessage: posting message = [${JSON.stringify(message)}]`));
|
|
1753
|
+
this.#oauth2ManagerPort.postMessage(message);
|
|
1754
|
+
});
|
|
1755
|
+
};
|
|
1756
|
+
#HandleLogEvent = (message) => {
|
|
1757
|
+
if (this.#aic) {
|
|
1758
|
+
this.#aic.LogEx(message);
|
|
1759
|
+
}
|
|
1760
|
+
this.#LogDebugMessage(message);
|
|
1761
|
+
};
|
|
1762
|
+
// UpdateInstrument = (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry): void => {
|
|
1763
|
+
#HandleUpdateInstrumentEvent = (instrumentName, telemetry) => {
|
|
1764
|
+
if (this.#aic) {
|
|
1765
|
+
this.#aic.UpdateInstrument(instrumentName, telemetry);
|
|
1766
|
+
}
|
|
1767
|
+
};
|
|
1768
|
+
#GetStore = () => {
|
|
1769
|
+
return STSOauth2Store(this.#options.pinia);
|
|
1770
|
+
};
|
|
1771
|
+
// Will come from message channel
|
|
1772
|
+
#HandleErrorEvent = (error) => {
|
|
1773
|
+
if (isNode) ;
|
|
1774
|
+
else {
|
|
1775
|
+
this.#GetStore().UpdateError({
|
|
1776
|
+
// Authorize applications store
|
|
1777
|
+
message: error
|
|
1778
|
+
});
|
|
1779
|
+
setTimeout(() => {
|
|
1780
|
+
this.#router.replace(`${this.#options.uriBase}error`);
|
|
1781
|
+
}, 0);
|
|
1782
|
+
}
|
|
1783
|
+
};
|
|
1784
|
+
#HandleAuthenticateEvent = (id_token) => {
|
|
1785
|
+
if (isNode) ;
|
|
1786
|
+
else {
|
|
1787
|
+
if (this.#options.authenticateEvent) {
|
|
1788
|
+
this.#options.authenticateEvent(id_token);
|
|
1789
|
+
}
|
|
1790
|
+
this.#GetStore().UpdateIdToken(id_token);
|
|
1791
|
+
}
|
|
1792
|
+
};
|
|
1793
|
+
#SetupRoute = (app, router) => {
|
|
1794
|
+
this.#LogDebugMessage(chalk.gray(`STSOAuth2Manager:#SetupRoute`));
|
|
1795
|
+
router.beforeEach(async (to, from, next) => {
|
|
1796
|
+
const oAuth2Manager = app.config.globalProperties.$sts[STSOAuth2ManagerPluginKey];
|
|
1797
|
+
this.#LogDebugMessage(chalk.gray(`beforeEach: from: [${from.path}], to: [${to.path}]`));
|
|
1798
|
+
if (this.#GetStore().LoggedIn === false) {
|
|
1799
|
+
this.#LogInfoMessage(`Not logged in`);
|
|
1800
|
+
if (to.path.localeCompare(`${this.#options.uriBase}authorize`) === 0) {
|
|
1801
|
+
this.#LogInfoMessage(`to = ${this.#options.uriBase}authorize`);
|
|
1802
|
+
next();
|
|
1803
|
+
return;
|
|
1804
|
+
} else if (to.path.localeCompare(`${this.#options.uriBase}consent`) === 0) {
|
|
1805
|
+
if (this.#GetStore().id_token) {
|
|
1806
|
+
next();
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
if (to.path.localeCompare(`${this.#options.uriBase}logout`) === 0) {
|
|
1811
|
+
next();
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
if (to.path.localeCompare(`${this.#options.uriBase}error`) === 0) {
|
|
1815
|
+
next();
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
if (to.path.localeCompare(`${this.#options.uriBase}config`) === 0) {
|
|
1819
|
+
next();
|
|
1820
|
+
return;
|
|
1821
|
+
}
|
|
1822
|
+
if (to.path.localeCompare(`${this.#options.uriBase}redirected`) === 0) {
|
|
1823
|
+
next();
|
|
1824
|
+
return;
|
|
1825
|
+
}
|
|
1826
|
+
const str = to.query;
|
|
1827
|
+
if (str[stsutils.OAuth2ParameterType.CODE] || str[stsutils.OAuth2ParameterType.ERROR]) {
|
|
1828
|
+
this.#LogDebugMessage(chalk.magenta(`STSOAuth2Manager:#SetupRoute:Processing redirect: [${JSON.stringify(str)}]`));
|
|
1829
|
+
const retVal = await oAuth2Manager.HandleRedirect(str);
|
|
1830
|
+
this.#LogDebugMessage(chalk.magenta(`STSOAuth2Manager:#SetupRoute:Redirect result: [${retVal}]`));
|
|
1831
|
+
if (retVal) {
|
|
1832
|
+
next({
|
|
1833
|
+
path: `${this.#options.uriBase}`,
|
|
1834
|
+
replace: true
|
|
1835
|
+
});
|
|
1836
|
+
return;
|
|
1837
|
+
} else {
|
|
1838
|
+
next({
|
|
1839
|
+
path: `${this.#options.uriBase}error`,
|
|
1840
|
+
replace: true
|
|
1841
|
+
});
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
this.#LogDebugMessage(`STSOAuth2Manager:#SetupRoute:Restoring session`);
|
|
1846
|
+
const sessionRestored = await oAuth2Manager.RestoreSession();
|
|
1847
|
+
this.#LogDebugMessage(`STSOAuth2Manager:#SetupRoute:Session restored: [${sessionRestored}]`);
|
|
1848
|
+
if (sessionRestored !== true) {
|
|
1849
|
+
this.#LogDebugMessage(`STSOAuth2Manager:#SetupRoute:Session not restored - need to authorize`);
|
|
1850
|
+
oAuth2Manager.Authorize();
|
|
1851
|
+
next();
|
|
1852
|
+
return;
|
|
1853
|
+
} else {
|
|
1854
|
+
next(`${this.#options.uriBase}`);
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
} else {
|
|
1858
|
+
if (to.path.localeCompare(`${this.#options.uriBase}consent`) === 0) {
|
|
1859
|
+
next(`${this.#options.uriBase}`);
|
|
1860
|
+
return;
|
|
1861
|
+
}
|
|
1862
|
+
if (to.path.localeCompare(`${this.#options.uriBase}authorize`) === 0) {
|
|
1863
|
+
next(`${this.#options.uriBase}`);
|
|
1864
|
+
return;
|
|
1865
|
+
}
|
|
1866
|
+
if (to.path.localeCompare(`${this.#options.uriBase}logout`) === 0) {
|
|
1867
|
+
next(`${this.#options.uriBase}`);
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
next();
|
|
1871
|
+
}
|
|
1872
|
+
});
|
|
1873
|
+
};
|
|
1874
|
+
//@@ this needs to be re-implemented so that access_token never leaves the auth worker
|
|
1875
|
+
GetAccessToken = async () => {
|
|
1876
|
+
const response = await this.#PostMessage({ command: IOauth2ListenerCommand.ACCESS_TOKEN });
|
|
1877
|
+
return response.payload;
|
|
1878
|
+
};
|
|
1879
|
+
// Update operation protected using operationSemaphore. This may occur when using workers and/or multiple async fetch operations.
|
|
1880
|
+
ExecuteRefreshToken = async (retryCount = 0) => {
|
|
1881
|
+
if (this.#operationSemaphore === true) {
|
|
1882
|
+
if (retryCount > this.#maxSemaphoreRetries) {
|
|
1883
|
+
throw new Error(`STSOAuth2Manager:ExecuteRefreshToken:maxSemaphoreRetries: [${this.#maxSemaphoreRetries}] exceeded.`);
|
|
1884
|
+
}
|
|
1885
|
+
await stsutils.Sleep(this.#semaphoreRetrySleep);
|
|
1886
|
+
this.#LogDebugMessage(chalk.cyan(`STSOAuth2Manager:ExecuteRefreshToken:locked by operationSemaphore, retry count: [${retryCount}]`));
|
|
1887
|
+
return await this.ExecuteRefreshToken(retryCount + 1);
|
|
1888
|
+
} else {
|
|
1889
|
+
this.#operationSemaphore = true;
|
|
1890
|
+
const response = await this.#PostMessage({ command: IOauth2ListenerCommand.EXECUTE_REFRESH_TOKEN });
|
|
1891
|
+
this.#operationSemaphore = false;
|
|
1892
|
+
return response.payload;
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
GetCookies = async () => {
|
|
1896
|
+
const response = await this.#PostMessage({ command: IOauth2ListenerCommand.COOKIES });
|
|
1897
|
+
return response.payload;
|
|
1898
|
+
};
|
|
1899
|
+
RestoreSession = async () => {
|
|
1900
|
+
try {
|
|
1901
|
+
this.#LogDebugMessage(`STSOAuth2Manager:RestoreSession:postMessage: [${IOauth2ListenerCommand.RESTORE_SESSION}]`);
|
|
1902
|
+
const response = await this.#PostMessage({ command: IOauth2ListenerCommand.RESTORE_SESSION });
|
|
1903
|
+
this.#LogDebugMessage(`STSOAuth2Manager:RestoreSession:response: [${JSON.stringify(response.payload)}]`);
|
|
1904
|
+
return response.payload;
|
|
1905
|
+
} catch (error) {
|
|
1906
|
+
this.#LogErrorMessage(chalk.red(`RestoreSession Error: ${error}`));
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
};
|
|
1910
|
+
Authorize = async () => {
|
|
1911
|
+
try {
|
|
1912
|
+
const response = await this.#PostMessage({ command: IOauth2ListenerCommand.AUTHORIZE });
|
|
1913
|
+
this.#transactionStore.set(this.#STORAGE_AUTHORIZE_OPTIONS_KEY, response.payload.authorizeOptions);
|
|
1914
|
+
const url = response.payload.url;
|
|
1915
|
+
if (!isNode) {
|
|
1916
|
+
window.location.replace(url);
|
|
1917
|
+
} else {
|
|
1918
|
+
return response.payload.authorizeOptionsClientCopy;
|
|
1919
|
+
}
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
this.#LogErrorMessage(chalk.red(`Authorize Error: ${error}`));
|
|
1922
|
+
}
|
|
1923
|
+
return {};
|
|
1924
|
+
};
|
|
1925
|
+
HandleRedirect = async (queryVars) => {
|
|
1926
|
+
try {
|
|
1927
|
+
this.#LogDebugMessage(chalk.magenta(`STSOAuth2Manager:HandleRedirect`));
|
|
1928
|
+
let response = null;
|
|
1929
|
+
if (queryVars[stsutils.OAuth2ParameterType.CODE]) {
|
|
1930
|
+
const authorizeOptions = this.#transactionStore.get(this.#STORAGE_AUTHORIZE_OPTIONS_KEY);
|
|
1931
|
+
this.#transactionStore.remove(this.#STORAGE_AUTHORIZE_OPTIONS_KEY);
|
|
1932
|
+
this.#LogDebugMessage(chalk.magenta(`STSOAuth2Manager:HandleRedirect: sending HANDLE_REDIRECT command`));
|
|
1933
|
+
response = await this.#PostMessage({ command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: {
|
|
1934
|
+
queryVars,
|
|
1935
|
+
authorizeOptions
|
|
1936
|
+
} });
|
|
1937
|
+
} else {
|
|
1938
|
+
response = await this.#PostMessage({ command: IOauth2ListenerCommand.HANDLE_REDIRECT, payload: queryVars });
|
|
1939
|
+
}
|
|
1940
|
+
this.#LogDebugMessage(chalk.magenta(`STSOAuth2Manager:HandleRedirect: HANDLE_REDIRECT response: [${JSON.stringify(response)}]`));
|
|
1941
|
+
return response.payload;
|
|
1942
|
+
} catch (error) {
|
|
1943
|
+
this.#LogErrorMessage(chalk.red(`HandleRedirect Error: ${error}`));
|
|
1944
|
+
return false;
|
|
1945
|
+
}
|
|
1946
|
+
};
|
|
1947
|
+
Logout = async () => {
|
|
1948
|
+
try {
|
|
1949
|
+
const response = await this.#PostMessage({ command: IOauth2ListenerCommand.LOGOUT });
|
|
1950
|
+
return response.payload;
|
|
1951
|
+
} catch (error) {
|
|
1952
|
+
this.#LogErrorMessage(chalk.red(`Logout Error: ${error}`));
|
|
1953
|
+
return false;
|
|
1954
|
+
}
|
|
1955
|
+
};
|
|
1956
|
+
InvokeExternalAPI = async () => {
|
|
1957
|
+
try {
|
|
1958
|
+
const response = await this.#PostMessage({ command: IOauth2ListenerCommand.LOGOUT });
|
|
1959
|
+
return response.payload;
|
|
1960
|
+
} catch (error) {
|
|
1961
|
+
this.#LogErrorMessage(chalk.red(`InvokeExternalAPI Error: ${error}`));
|
|
1962
|
+
return null;
|
|
1963
|
+
}
|
|
1964
|
+
};
|
|
1965
|
+
LoggedIn = () => {
|
|
1966
|
+
try {
|
|
1967
|
+
return this.#GetStore().LoggedIn;
|
|
1968
|
+
} catch (error) {
|
|
1969
|
+
return false;
|
|
1970
|
+
}
|
|
1971
|
+
};
|
|
1972
|
+
}
|
|
1973
|
+
var sha256$2 = { exports: {} };
|
|
1974
|
+
function commonjsRequire(path) {
|
|
1975
|
+
throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
|
1976
|
+
}
|
|
1977
|
+
var core$1 = { exports: {} };
|
|
1978
|
+
var core = core$1.exports;
|
|
1979
|
+
var hasRequiredCore;
|
|
1980
|
+
function requireCore() {
|
|
1981
|
+
if (hasRequiredCore) return core$1.exports;
|
|
1982
|
+
hasRequiredCore = 1;
|
|
1983
|
+
(function(module2, exports2) {
|
|
1984
|
+
(function(root, factory) {
|
|
1985
|
+
{
|
|
1986
|
+
module2.exports = factory();
|
|
1987
|
+
}
|
|
1988
|
+
})(core, function() {
|
|
1989
|
+
var CryptoJS = CryptoJS || (function(Math2, undefined$1) {
|
|
1990
|
+
var crypto2;
|
|
1991
|
+
if (typeof window !== "undefined" && window.crypto) {
|
|
1992
|
+
crypto2 = window.crypto;
|
|
1993
|
+
}
|
|
1994
|
+
if (typeof self !== "undefined" && self.crypto) {
|
|
1995
|
+
crypto2 = self.crypto;
|
|
1996
|
+
}
|
|
1997
|
+
if (typeof globalThis !== "undefined" && globalThis.crypto) {
|
|
1998
|
+
crypto2 = globalThis.crypto;
|
|
1999
|
+
}
|
|
2000
|
+
if (!crypto2 && typeof window !== "undefined" && window.msCrypto) {
|
|
2001
|
+
crypto2 = window.msCrypto;
|
|
2002
|
+
}
|
|
2003
|
+
if (!crypto2 && typeof commonjsGlobal !== "undefined" && commonjsGlobal.crypto) {
|
|
2004
|
+
crypto2 = commonjsGlobal.crypto;
|
|
2005
|
+
}
|
|
2006
|
+
if (!crypto2 && typeof commonjsRequire === "function") {
|
|
2007
|
+
try {
|
|
2008
|
+
crypto2 = require("crypto");
|
|
2009
|
+
} catch (err) {
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
var cryptoSecureRandomInt = function() {
|
|
2013
|
+
if (crypto2) {
|
|
2014
|
+
if (typeof crypto2.getRandomValues === "function") {
|
|
2015
|
+
try {
|
|
2016
|
+
return crypto2.getRandomValues(new Uint32Array(1))[0];
|
|
2017
|
+
} catch (err) {
|
|
2018
|
+
}
|
|
2019
|
+
}
|
|
2020
|
+
if (typeof crypto2.randomBytes === "function") {
|
|
2021
|
+
try {
|
|
2022
|
+
return crypto2.randomBytes(4).readInt32LE();
|
|
2023
|
+
} catch (err) {
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
throw new Error("Native crypto module could not be used to get secure random number.");
|
|
2028
|
+
};
|
|
2029
|
+
var create = Object.create || /* @__PURE__ */ (function() {
|
|
2030
|
+
function F() {
|
|
2031
|
+
}
|
|
2032
|
+
return function(obj) {
|
|
2033
|
+
var subtype;
|
|
2034
|
+
F.prototype = obj;
|
|
2035
|
+
subtype = new F();
|
|
2036
|
+
F.prototype = null;
|
|
2037
|
+
return subtype;
|
|
2038
|
+
};
|
|
2039
|
+
})();
|
|
2040
|
+
var C = {};
|
|
2041
|
+
var C_lib = C.lib = {};
|
|
2042
|
+
var Base = C_lib.Base = /* @__PURE__ */ (function() {
|
|
2043
|
+
return {
|
|
2044
|
+
/**
|
|
2045
|
+
* Creates a new object that inherits from this object.
|
|
2046
|
+
*
|
|
2047
|
+
* @param {Object} overrides Properties to copy into the new object.
|
|
2048
|
+
*
|
|
2049
|
+
* @return {Object} The new object.
|
|
2050
|
+
*
|
|
2051
|
+
* @static
|
|
2052
|
+
*
|
|
2053
|
+
* @example
|
|
2054
|
+
*
|
|
2055
|
+
* var MyType = CryptoJS.lib.Base.extend({
|
|
2056
|
+
* field: 'value',
|
|
2057
|
+
*
|
|
2058
|
+
* method: function () {
|
|
2059
|
+
* }
|
|
2060
|
+
* });
|
|
2061
|
+
*/
|
|
2062
|
+
extend: function(overrides) {
|
|
2063
|
+
var subtype = create(this);
|
|
2064
|
+
if (overrides) {
|
|
2065
|
+
subtype.mixIn(overrides);
|
|
2066
|
+
}
|
|
2067
|
+
if (!subtype.hasOwnProperty("init") || this.init === subtype.init) {
|
|
2068
|
+
subtype.init = function() {
|
|
2069
|
+
subtype.$super.init.apply(this, arguments);
|
|
2070
|
+
};
|
|
2071
|
+
}
|
|
2072
|
+
subtype.init.prototype = subtype;
|
|
2073
|
+
subtype.$super = this;
|
|
2074
|
+
return subtype;
|
|
2075
|
+
},
|
|
2076
|
+
/**
|
|
2077
|
+
* Extends this object and runs the init method.
|
|
2078
|
+
* Arguments to create() will be passed to init().
|
|
2079
|
+
*
|
|
2080
|
+
* @return {Object} The new object.
|
|
2081
|
+
*
|
|
2082
|
+
* @static
|
|
2083
|
+
*
|
|
2084
|
+
* @example
|
|
2085
|
+
*
|
|
2086
|
+
* var instance = MyType.create();
|
|
2087
|
+
*/
|
|
2088
|
+
create: function() {
|
|
2089
|
+
var instance = this.extend();
|
|
2090
|
+
instance.init.apply(instance, arguments);
|
|
2091
|
+
return instance;
|
|
2092
|
+
},
|
|
2093
|
+
/**
|
|
2094
|
+
* Initializes a newly created object.
|
|
2095
|
+
* Override this method to add some logic when your objects are created.
|
|
2096
|
+
*
|
|
2097
|
+
* @example
|
|
2098
|
+
*
|
|
2099
|
+
* var MyType = CryptoJS.lib.Base.extend({
|
|
2100
|
+
* init: function () {
|
|
2101
|
+
* // ...
|
|
2102
|
+
* }
|
|
2103
|
+
* });
|
|
2104
|
+
*/
|
|
2105
|
+
init: function() {
|
|
2106
|
+
},
|
|
2107
|
+
/**
|
|
2108
|
+
* Copies properties into this object.
|
|
2109
|
+
*
|
|
2110
|
+
* @param {Object} properties The properties to mix in.
|
|
2111
|
+
*
|
|
2112
|
+
* @example
|
|
2113
|
+
*
|
|
2114
|
+
* MyType.mixIn({
|
|
2115
|
+
* field: 'value'
|
|
2116
|
+
* });
|
|
2117
|
+
*/
|
|
2118
|
+
mixIn: function(properties) {
|
|
2119
|
+
for (var propertyName in properties) {
|
|
2120
|
+
if (properties.hasOwnProperty(propertyName)) {
|
|
2121
|
+
this[propertyName] = properties[propertyName];
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
if (properties.hasOwnProperty("toString")) {
|
|
2125
|
+
this.toString = properties.toString;
|
|
2126
|
+
}
|
|
2127
|
+
},
|
|
2128
|
+
/**
|
|
2129
|
+
* Creates a copy of this object.
|
|
2130
|
+
*
|
|
2131
|
+
* @return {Object} The clone.
|
|
2132
|
+
*
|
|
2133
|
+
* @example
|
|
2134
|
+
*
|
|
2135
|
+
* var clone = instance.clone();
|
|
2136
|
+
*/
|
|
2137
|
+
clone: function() {
|
|
2138
|
+
return this.init.prototype.extend(this);
|
|
2139
|
+
}
|
|
2140
|
+
};
|
|
2141
|
+
})();
|
|
2142
|
+
var WordArray = C_lib.WordArray = Base.extend({
|
|
2143
|
+
/**
|
|
2144
|
+
* Initializes a newly created word array.
|
|
2145
|
+
*
|
|
2146
|
+
* @param {Array} words (Optional) An array of 32-bit words.
|
|
2147
|
+
* @param {number} sigBytes (Optional) The number of significant bytes in the words.
|
|
2148
|
+
*
|
|
2149
|
+
* @example
|
|
2150
|
+
*
|
|
2151
|
+
* var wordArray = CryptoJS.lib.WordArray.create();
|
|
2152
|
+
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
|
|
2153
|
+
* var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
|
|
2154
|
+
*/
|
|
2155
|
+
init: function(words, sigBytes) {
|
|
2156
|
+
words = this.words = words || [];
|
|
2157
|
+
if (sigBytes != undefined$1) {
|
|
2158
|
+
this.sigBytes = sigBytes;
|
|
2159
|
+
} else {
|
|
2160
|
+
this.sigBytes = words.length * 4;
|
|
2161
|
+
}
|
|
2162
|
+
},
|
|
2163
|
+
/**
|
|
2164
|
+
* Converts this word array to a string.
|
|
2165
|
+
*
|
|
2166
|
+
* @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
|
|
2167
|
+
*
|
|
2168
|
+
* @return {string} The stringified word array.
|
|
2169
|
+
*
|
|
2170
|
+
* @example
|
|
2171
|
+
*
|
|
2172
|
+
* var string = wordArray + '';
|
|
2173
|
+
* var string = wordArray.toString();
|
|
2174
|
+
* var string = wordArray.toString(CryptoJS.enc.Utf8);
|
|
2175
|
+
*/
|
|
2176
|
+
toString: function(encoder) {
|
|
2177
|
+
return (encoder || Hex).stringify(this);
|
|
2178
|
+
},
|
|
2179
|
+
/**
|
|
2180
|
+
* Concatenates a word array to this word array.
|
|
2181
|
+
*
|
|
2182
|
+
* @param {WordArray} wordArray The word array to append.
|
|
2183
|
+
*
|
|
2184
|
+
* @return {WordArray} This word array.
|
|
2185
|
+
*
|
|
2186
|
+
* @example
|
|
2187
|
+
*
|
|
2188
|
+
* wordArray1.concat(wordArray2);
|
|
2189
|
+
*/
|
|
2190
|
+
concat: function(wordArray) {
|
|
2191
|
+
var thisWords = this.words;
|
|
2192
|
+
var thatWords = wordArray.words;
|
|
2193
|
+
var thisSigBytes = this.sigBytes;
|
|
2194
|
+
var thatSigBytes = wordArray.sigBytes;
|
|
2195
|
+
this.clamp();
|
|
2196
|
+
if (thisSigBytes % 4) {
|
|
2197
|
+
for (var i = 0; i < thatSigBytes; i++) {
|
|
2198
|
+
var thatByte = thatWords[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
2199
|
+
thisWords[thisSigBytes + i >>> 2] |= thatByte << 24 - (thisSigBytes + i) % 4 * 8;
|
|
2200
|
+
}
|
|
2201
|
+
} else {
|
|
2202
|
+
for (var j = 0; j < thatSigBytes; j += 4) {
|
|
2203
|
+
thisWords[thisSigBytes + j >>> 2] = thatWords[j >>> 2];
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
this.sigBytes += thatSigBytes;
|
|
2207
|
+
return this;
|
|
2208
|
+
},
|
|
2209
|
+
/**
|
|
2210
|
+
* Removes insignificant bits.
|
|
2211
|
+
*
|
|
2212
|
+
* @example
|
|
2213
|
+
*
|
|
2214
|
+
* wordArray.clamp();
|
|
2215
|
+
*/
|
|
2216
|
+
clamp: function() {
|
|
2217
|
+
var words = this.words;
|
|
2218
|
+
var sigBytes = this.sigBytes;
|
|
2219
|
+
words[sigBytes >>> 2] &= 4294967295 << 32 - sigBytes % 4 * 8;
|
|
2220
|
+
words.length = Math2.ceil(sigBytes / 4);
|
|
2221
|
+
},
|
|
2222
|
+
/**
|
|
2223
|
+
* Creates a copy of this word array.
|
|
2224
|
+
*
|
|
2225
|
+
* @return {WordArray} The clone.
|
|
2226
|
+
*
|
|
2227
|
+
* @example
|
|
2228
|
+
*
|
|
2229
|
+
* var clone = wordArray.clone();
|
|
2230
|
+
*/
|
|
2231
|
+
clone: function() {
|
|
2232
|
+
var clone = Base.clone.call(this);
|
|
2233
|
+
clone.words = this.words.slice(0);
|
|
2234
|
+
return clone;
|
|
2235
|
+
},
|
|
2236
|
+
/**
|
|
2237
|
+
* Creates a word array filled with random bytes.
|
|
2238
|
+
*
|
|
2239
|
+
* @param {number} nBytes The number of random bytes to generate.
|
|
2240
|
+
*
|
|
2241
|
+
* @return {WordArray} The random word array.
|
|
2242
|
+
*
|
|
2243
|
+
* @static
|
|
2244
|
+
*
|
|
2245
|
+
* @example
|
|
2246
|
+
*
|
|
2247
|
+
* var wordArray = CryptoJS.lib.WordArray.random(16);
|
|
2248
|
+
*/
|
|
2249
|
+
random: function(nBytes) {
|
|
2250
|
+
var words = [];
|
|
2251
|
+
for (var i = 0; i < nBytes; i += 4) {
|
|
2252
|
+
words.push(cryptoSecureRandomInt());
|
|
2253
|
+
}
|
|
2254
|
+
return new WordArray.init(words, nBytes);
|
|
2255
|
+
}
|
|
2256
|
+
});
|
|
2257
|
+
var C_enc = C.enc = {};
|
|
2258
|
+
var Hex = C_enc.Hex = {
|
|
2259
|
+
/**
|
|
2260
|
+
* Converts a word array to a hex string.
|
|
2261
|
+
*
|
|
2262
|
+
* @param {WordArray} wordArray The word array.
|
|
2263
|
+
*
|
|
2264
|
+
* @return {string} The hex string.
|
|
2265
|
+
*
|
|
2266
|
+
* @static
|
|
2267
|
+
*
|
|
2268
|
+
* @example
|
|
2269
|
+
*
|
|
2270
|
+
* var hexString = CryptoJS.enc.Hex.stringify(wordArray);
|
|
2271
|
+
*/
|
|
2272
|
+
stringify: function(wordArray) {
|
|
2273
|
+
var words = wordArray.words;
|
|
2274
|
+
var sigBytes = wordArray.sigBytes;
|
|
2275
|
+
var hexChars = [];
|
|
2276
|
+
for (var i = 0; i < sigBytes; i++) {
|
|
2277
|
+
var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
2278
|
+
hexChars.push((bite >>> 4).toString(16));
|
|
2279
|
+
hexChars.push((bite & 15).toString(16));
|
|
2280
|
+
}
|
|
2281
|
+
return hexChars.join("");
|
|
2282
|
+
},
|
|
2283
|
+
/**
|
|
2284
|
+
* Converts a hex string to a word array.
|
|
2285
|
+
*
|
|
2286
|
+
* @param {string} hexStr The hex string.
|
|
2287
|
+
*
|
|
2288
|
+
* @return {WordArray} The word array.
|
|
2289
|
+
*
|
|
2290
|
+
* @static
|
|
2291
|
+
*
|
|
2292
|
+
* @example
|
|
2293
|
+
*
|
|
2294
|
+
* var wordArray = CryptoJS.enc.Hex.parse(hexString);
|
|
2295
|
+
*/
|
|
2296
|
+
parse: function(hexStr) {
|
|
2297
|
+
var hexStrLength = hexStr.length;
|
|
2298
|
+
var words = [];
|
|
2299
|
+
for (var i = 0; i < hexStrLength; i += 2) {
|
|
2300
|
+
words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << 24 - i % 8 * 4;
|
|
2301
|
+
}
|
|
2302
|
+
return new WordArray.init(words, hexStrLength / 2);
|
|
2303
|
+
}
|
|
2304
|
+
};
|
|
2305
|
+
var Latin1 = C_enc.Latin1 = {
|
|
2306
|
+
/**
|
|
2307
|
+
* Converts a word array to a Latin1 string.
|
|
2308
|
+
*
|
|
2309
|
+
* @param {WordArray} wordArray The word array.
|
|
2310
|
+
*
|
|
2311
|
+
* @return {string} The Latin1 string.
|
|
2312
|
+
*
|
|
2313
|
+
* @static
|
|
2314
|
+
*
|
|
2315
|
+
* @example
|
|
2316
|
+
*
|
|
2317
|
+
* var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
|
|
2318
|
+
*/
|
|
2319
|
+
stringify: function(wordArray) {
|
|
2320
|
+
var words = wordArray.words;
|
|
2321
|
+
var sigBytes = wordArray.sigBytes;
|
|
2322
|
+
var latin1Chars = [];
|
|
2323
|
+
for (var i = 0; i < sigBytes; i++) {
|
|
2324
|
+
var bite = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
2325
|
+
latin1Chars.push(String.fromCharCode(bite));
|
|
2326
|
+
}
|
|
2327
|
+
return latin1Chars.join("");
|
|
2328
|
+
},
|
|
2329
|
+
/**
|
|
2330
|
+
* Converts a Latin1 string to a word array.
|
|
2331
|
+
*
|
|
2332
|
+
* @param {string} latin1Str The Latin1 string.
|
|
2333
|
+
*
|
|
2334
|
+
* @return {WordArray} The word array.
|
|
2335
|
+
*
|
|
2336
|
+
* @static
|
|
2337
|
+
*
|
|
2338
|
+
* @example
|
|
2339
|
+
*
|
|
2340
|
+
* var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
|
|
2341
|
+
*/
|
|
2342
|
+
parse: function(latin1Str) {
|
|
2343
|
+
var latin1StrLength = latin1Str.length;
|
|
2344
|
+
var words = [];
|
|
2345
|
+
for (var i = 0; i < latin1StrLength; i++) {
|
|
2346
|
+
words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
|
|
2347
|
+
}
|
|
2348
|
+
return new WordArray.init(words, latin1StrLength);
|
|
2349
|
+
}
|
|
2350
|
+
};
|
|
2351
|
+
var Utf8 = C_enc.Utf8 = {
|
|
2352
|
+
/**
|
|
2353
|
+
* Converts a word array to a UTF-8 string.
|
|
2354
|
+
*
|
|
2355
|
+
* @param {WordArray} wordArray The word array.
|
|
2356
|
+
*
|
|
2357
|
+
* @return {string} The UTF-8 string.
|
|
2358
|
+
*
|
|
2359
|
+
* @static
|
|
2360
|
+
*
|
|
2361
|
+
* @example
|
|
2362
|
+
*
|
|
2363
|
+
* var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
|
|
2364
|
+
*/
|
|
2365
|
+
stringify: function(wordArray) {
|
|
2366
|
+
try {
|
|
2367
|
+
return decodeURIComponent(escape(Latin1.stringify(wordArray)));
|
|
2368
|
+
} catch (e) {
|
|
2369
|
+
throw new Error("Malformed UTF-8 data");
|
|
2370
|
+
}
|
|
2371
|
+
},
|
|
2372
|
+
/**
|
|
2373
|
+
* Converts a UTF-8 string to a word array.
|
|
2374
|
+
*
|
|
2375
|
+
* @param {string} utf8Str The UTF-8 string.
|
|
2376
|
+
*
|
|
2377
|
+
* @return {WordArray} The word array.
|
|
2378
|
+
*
|
|
2379
|
+
* @static
|
|
2380
|
+
*
|
|
2381
|
+
* @example
|
|
2382
|
+
*
|
|
2383
|
+
* var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
|
|
2384
|
+
*/
|
|
2385
|
+
parse: function(utf8Str) {
|
|
2386
|
+
return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
|
|
2387
|
+
}
|
|
2388
|
+
};
|
|
2389
|
+
var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
|
|
2390
|
+
/**
|
|
2391
|
+
* Resets this block algorithm's data buffer to its initial state.
|
|
2392
|
+
*
|
|
2393
|
+
* @example
|
|
2394
|
+
*
|
|
2395
|
+
* bufferedBlockAlgorithm.reset();
|
|
2396
|
+
*/
|
|
2397
|
+
reset: function() {
|
|
2398
|
+
this._data = new WordArray.init();
|
|
2399
|
+
this._nDataBytes = 0;
|
|
2400
|
+
},
|
|
2401
|
+
/**
|
|
2402
|
+
* Adds new data to this block algorithm's buffer.
|
|
2403
|
+
*
|
|
2404
|
+
* @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
|
|
2405
|
+
*
|
|
2406
|
+
* @example
|
|
2407
|
+
*
|
|
2408
|
+
* bufferedBlockAlgorithm._append('data');
|
|
2409
|
+
* bufferedBlockAlgorithm._append(wordArray);
|
|
2410
|
+
*/
|
|
2411
|
+
_append: function(data) {
|
|
2412
|
+
if (typeof data == "string") {
|
|
2413
|
+
data = Utf8.parse(data);
|
|
2414
|
+
}
|
|
2415
|
+
this._data.concat(data);
|
|
2416
|
+
this._nDataBytes += data.sigBytes;
|
|
2417
|
+
},
|
|
2418
|
+
/**
|
|
2419
|
+
* Processes available data blocks.
|
|
2420
|
+
*
|
|
2421
|
+
* This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
|
|
2422
|
+
*
|
|
2423
|
+
* @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
|
|
2424
|
+
*
|
|
2425
|
+
* @return {WordArray} The processed data.
|
|
2426
|
+
*
|
|
2427
|
+
* @example
|
|
2428
|
+
*
|
|
2429
|
+
* var processedData = bufferedBlockAlgorithm._process();
|
|
2430
|
+
* var processedData = bufferedBlockAlgorithm._process(!!'flush');
|
|
2431
|
+
*/
|
|
2432
|
+
_process: function(doFlush) {
|
|
2433
|
+
var processedWords;
|
|
2434
|
+
var data = this._data;
|
|
2435
|
+
var dataWords = data.words;
|
|
2436
|
+
var dataSigBytes = data.sigBytes;
|
|
2437
|
+
var blockSize = this.blockSize;
|
|
2438
|
+
var blockSizeBytes = blockSize * 4;
|
|
2439
|
+
var nBlocksReady = dataSigBytes / blockSizeBytes;
|
|
2440
|
+
if (doFlush) {
|
|
2441
|
+
nBlocksReady = Math2.ceil(nBlocksReady);
|
|
2442
|
+
} else {
|
|
2443
|
+
nBlocksReady = Math2.max((nBlocksReady | 0) - this._minBufferSize, 0);
|
|
2444
|
+
}
|
|
2445
|
+
var nWordsReady = nBlocksReady * blockSize;
|
|
2446
|
+
var nBytesReady = Math2.min(nWordsReady * 4, dataSigBytes);
|
|
2447
|
+
if (nWordsReady) {
|
|
2448
|
+
for (var offset = 0; offset < nWordsReady; offset += blockSize) {
|
|
2449
|
+
this._doProcessBlock(dataWords, offset);
|
|
2450
|
+
}
|
|
2451
|
+
processedWords = dataWords.splice(0, nWordsReady);
|
|
2452
|
+
data.sigBytes -= nBytesReady;
|
|
2453
|
+
}
|
|
2454
|
+
return new WordArray.init(processedWords, nBytesReady);
|
|
2455
|
+
},
|
|
2456
|
+
/**
|
|
2457
|
+
* Creates a copy of this object.
|
|
2458
|
+
*
|
|
2459
|
+
* @return {Object} The clone.
|
|
2460
|
+
*
|
|
2461
|
+
* @example
|
|
2462
|
+
*
|
|
2463
|
+
* var clone = bufferedBlockAlgorithm.clone();
|
|
2464
|
+
*/
|
|
2465
|
+
clone: function() {
|
|
2466
|
+
var clone = Base.clone.call(this);
|
|
2467
|
+
clone._data = this._data.clone();
|
|
2468
|
+
return clone;
|
|
2469
|
+
},
|
|
2470
|
+
_minBufferSize: 0
|
|
2471
|
+
});
|
|
2472
|
+
C_lib.Hasher = BufferedBlockAlgorithm.extend({
|
|
2473
|
+
/**
|
|
2474
|
+
* Configuration options.
|
|
2475
|
+
*/
|
|
2476
|
+
cfg: Base.extend(),
|
|
2477
|
+
/**
|
|
2478
|
+
* Initializes a newly created hasher.
|
|
2479
|
+
*
|
|
2480
|
+
* @param {Object} cfg (Optional) The configuration options to use for this hash computation.
|
|
2481
|
+
*
|
|
2482
|
+
* @example
|
|
2483
|
+
*
|
|
2484
|
+
* var hasher = CryptoJS.algo.SHA256.create();
|
|
2485
|
+
*/
|
|
2486
|
+
init: function(cfg) {
|
|
2487
|
+
this.cfg = this.cfg.extend(cfg);
|
|
2488
|
+
this.reset();
|
|
2489
|
+
},
|
|
2490
|
+
/**
|
|
2491
|
+
* Resets this hasher to its initial state.
|
|
2492
|
+
*
|
|
2493
|
+
* @example
|
|
2494
|
+
*
|
|
2495
|
+
* hasher.reset();
|
|
2496
|
+
*/
|
|
2497
|
+
reset: function() {
|
|
2498
|
+
BufferedBlockAlgorithm.reset.call(this);
|
|
2499
|
+
this._doReset();
|
|
2500
|
+
},
|
|
2501
|
+
/**
|
|
2502
|
+
* Updates this hasher with a message.
|
|
2503
|
+
*
|
|
2504
|
+
* @param {WordArray|string} messageUpdate The message to append.
|
|
2505
|
+
*
|
|
2506
|
+
* @return {Hasher} This hasher.
|
|
2507
|
+
*
|
|
2508
|
+
* @example
|
|
2509
|
+
*
|
|
2510
|
+
* hasher.update('message');
|
|
2511
|
+
* hasher.update(wordArray);
|
|
2512
|
+
*/
|
|
2513
|
+
update: function(messageUpdate) {
|
|
2514
|
+
this._append(messageUpdate);
|
|
2515
|
+
this._process();
|
|
2516
|
+
return this;
|
|
2517
|
+
},
|
|
2518
|
+
/**
|
|
2519
|
+
* Finalizes the hash computation.
|
|
2520
|
+
* Note that the finalize operation is effectively a destructive, read-once operation.
|
|
2521
|
+
*
|
|
2522
|
+
* @param {WordArray|string} messageUpdate (Optional) A final message update.
|
|
2523
|
+
*
|
|
2524
|
+
* @return {WordArray} The hash.
|
|
2525
|
+
*
|
|
2526
|
+
* @example
|
|
2527
|
+
*
|
|
2528
|
+
* var hash = hasher.finalize();
|
|
2529
|
+
* var hash = hasher.finalize('message');
|
|
2530
|
+
* var hash = hasher.finalize(wordArray);
|
|
2531
|
+
*/
|
|
2532
|
+
finalize: function(messageUpdate) {
|
|
2533
|
+
if (messageUpdate) {
|
|
2534
|
+
this._append(messageUpdate);
|
|
2535
|
+
}
|
|
2536
|
+
var hash = this._doFinalize();
|
|
2537
|
+
return hash;
|
|
2538
|
+
},
|
|
2539
|
+
blockSize: 512 / 32,
|
|
2540
|
+
/**
|
|
2541
|
+
* Creates a shortcut function to a hasher's object interface.
|
|
2542
|
+
*
|
|
2543
|
+
* @param {Hasher} hasher The hasher to create a helper for.
|
|
2544
|
+
*
|
|
2545
|
+
* @return {Function} The shortcut function.
|
|
2546
|
+
*
|
|
2547
|
+
* @static
|
|
2548
|
+
*
|
|
2549
|
+
* @example
|
|
2550
|
+
*
|
|
2551
|
+
* var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
|
|
2552
|
+
*/
|
|
2553
|
+
_createHelper: function(hasher) {
|
|
2554
|
+
return function(message, cfg) {
|
|
2555
|
+
return new hasher.init(cfg).finalize(message);
|
|
2556
|
+
};
|
|
2557
|
+
},
|
|
2558
|
+
/**
|
|
2559
|
+
* Creates a shortcut function to the HMAC's object interface.
|
|
2560
|
+
*
|
|
2561
|
+
* @param {Hasher} hasher The hasher to use in this HMAC helper.
|
|
2562
|
+
*
|
|
2563
|
+
* @return {Function} The shortcut function.
|
|
2564
|
+
*
|
|
2565
|
+
* @static
|
|
2566
|
+
*
|
|
2567
|
+
* @example
|
|
2568
|
+
*
|
|
2569
|
+
* var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
|
|
2570
|
+
*/
|
|
2571
|
+
_createHmacHelper: function(hasher) {
|
|
2572
|
+
return function(message, key) {
|
|
2573
|
+
return new C_algo.HMAC.init(hasher, key).finalize(message);
|
|
2574
|
+
};
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
var C_algo = C.algo = {};
|
|
2578
|
+
return C;
|
|
2579
|
+
})(Math);
|
|
2580
|
+
return CryptoJS;
|
|
2581
|
+
});
|
|
2582
|
+
})(core$1);
|
|
2583
|
+
return core$1.exports;
|
|
2584
|
+
}
|
|
2585
|
+
var sha256$1 = sha256$2.exports;
|
|
2586
|
+
var hasRequiredSha256;
|
|
2587
|
+
function requireSha256() {
|
|
2588
|
+
if (hasRequiredSha256) return sha256$2.exports;
|
|
2589
|
+
hasRequiredSha256 = 1;
|
|
2590
|
+
(function(module2, exports2) {
|
|
2591
|
+
(function(root, factory) {
|
|
2592
|
+
{
|
|
2593
|
+
module2.exports = factory(requireCore());
|
|
2594
|
+
}
|
|
2595
|
+
})(sha256$1, function(CryptoJS) {
|
|
2596
|
+
(function(Math2) {
|
|
2597
|
+
var C = CryptoJS;
|
|
2598
|
+
var C_lib = C.lib;
|
|
2599
|
+
var WordArray = C_lib.WordArray;
|
|
2600
|
+
var Hasher = C_lib.Hasher;
|
|
2601
|
+
var C_algo = C.algo;
|
|
2602
|
+
var H = [];
|
|
2603
|
+
var K = [];
|
|
2604
|
+
(function() {
|
|
2605
|
+
function isPrime(n2) {
|
|
2606
|
+
var sqrtN = Math2.sqrt(n2);
|
|
2607
|
+
for (var factor = 2; factor <= sqrtN; factor++) {
|
|
2608
|
+
if (!(n2 % factor)) {
|
|
2609
|
+
return false;
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
return true;
|
|
2613
|
+
}
|
|
2614
|
+
function getFractionalBits(n2) {
|
|
2615
|
+
return (n2 - (n2 | 0)) * 4294967296 | 0;
|
|
2616
|
+
}
|
|
2617
|
+
var n = 2;
|
|
2618
|
+
var nPrime = 0;
|
|
2619
|
+
while (nPrime < 64) {
|
|
2620
|
+
if (isPrime(n)) {
|
|
2621
|
+
if (nPrime < 8) {
|
|
2622
|
+
H[nPrime] = getFractionalBits(Math2.pow(n, 1 / 2));
|
|
2623
|
+
}
|
|
2624
|
+
K[nPrime] = getFractionalBits(Math2.pow(n, 1 / 3));
|
|
2625
|
+
nPrime++;
|
|
2626
|
+
}
|
|
2627
|
+
n++;
|
|
2628
|
+
}
|
|
2629
|
+
})();
|
|
2630
|
+
var W = [];
|
|
2631
|
+
var SHA256 = C_algo.SHA256 = Hasher.extend({
|
|
2632
|
+
_doReset: function() {
|
|
2633
|
+
this._hash = new WordArray.init(H.slice(0));
|
|
2634
|
+
},
|
|
2635
|
+
_doProcessBlock: function(M, offset) {
|
|
2636
|
+
var H2 = this._hash.words;
|
|
2637
|
+
var a = H2[0];
|
|
2638
|
+
var b = H2[1];
|
|
2639
|
+
var c = H2[2];
|
|
2640
|
+
var d = H2[3];
|
|
2641
|
+
var e = H2[4];
|
|
2642
|
+
var f = H2[5];
|
|
2643
|
+
var g = H2[6];
|
|
2644
|
+
var h = H2[7];
|
|
2645
|
+
for (var i = 0; i < 64; i++) {
|
|
2646
|
+
if (i < 16) {
|
|
2647
|
+
W[i] = M[offset + i] | 0;
|
|
2648
|
+
} else {
|
|
2649
|
+
var gamma0x = W[i - 15];
|
|
2650
|
+
var gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
|
|
2651
|
+
var gamma1x = W[i - 2];
|
|
2652
|
+
var gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
|
|
2653
|
+
W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
|
|
2654
|
+
}
|
|
2655
|
+
var ch = e & f ^ ~e & g;
|
|
2656
|
+
var maj = a & b ^ a & c ^ b & c;
|
|
2657
|
+
var sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
|
|
2658
|
+
var sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
|
|
2659
|
+
var t1 = h + sigma1 + ch + K[i] + W[i];
|
|
2660
|
+
var t2 = sigma0 + maj;
|
|
2661
|
+
h = g;
|
|
2662
|
+
g = f;
|
|
2663
|
+
f = e;
|
|
2664
|
+
e = d + t1 | 0;
|
|
2665
|
+
d = c;
|
|
2666
|
+
c = b;
|
|
2667
|
+
b = a;
|
|
2668
|
+
a = t1 + t2 | 0;
|
|
2669
|
+
}
|
|
2670
|
+
H2[0] = H2[0] + a | 0;
|
|
2671
|
+
H2[1] = H2[1] + b | 0;
|
|
2672
|
+
H2[2] = H2[2] + c | 0;
|
|
2673
|
+
H2[3] = H2[3] + d | 0;
|
|
2674
|
+
H2[4] = H2[4] + e | 0;
|
|
2675
|
+
H2[5] = H2[5] + f | 0;
|
|
2676
|
+
H2[6] = H2[6] + g | 0;
|
|
2677
|
+
H2[7] = H2[7] + h | 0;
|
|
2678
|
+
},
|
|
2679
|
+
_doFinalize: function() {
|
|
2680
|
+
var data = this._data;
|
|
2681
|
+
var dataWords = data.words;
|
|
2682
|
+
var nBitsTotal = this._nDataBytes * 8;
|
|
2683
|
+
var nBitsLeft = data.sigBytes * 8;
|
|
2684
|
+
dataWords[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
|
|
2685
|
+
dataWords[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math2.floor(nBitsTotal / 4294967296);
|
|
2686
|
+
dataWords[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
|
|
2687
|
+
data.sigBytes = dataWords.length * 4;
|
|
2688
|
+
this._process();
|
|
2689
|
+
return this._hash;
|
|
2690
|
+
},
|
|
2691
|
+
clone: function() {
|
|
2692
|
+
var clone = Hasher.clone.call(this);
|
|
2693
|
+
clone._hash = this._hash.clone();
|
|
2694
|
+
return clone;
|
|
2695
|
+
}
|
|
2696
|
+
});
|
|
2697
|
+
C.SHA256 = Hasher._createHelper(SHA256);
|
|
2698
|
+
C.HmacSHA256 = Hasher._createHmacHelper(SHA256);
|
|
2699
|
+
})(Math);
|
|
2700
|
+
return CryptoJS.SHA256;
|
|
2701
|
+
});
|
|
2702
|
+
})(sha256$2);
|
|
2703
|
+
return sha256$2.exports;
|
|
2704
|
+
}
|
|
2705
|
+
var sha256Exports = requireSha256();
|
|
2706
|
+
const sha256 = /* @__PURE__ */ getDefaultExportFromCjs(sha256Exports);
|
|
2707
|
+
var encBase64$1 = { exports: {} };
|
|
2708
|
+
var encBase64 = encBase64$1.exports;
|
|
2709
|
+
var hasRequiredEncBase64;
|
|
2710
|
+
function requireEncBase64() {
|
|
2711
|
+
if (hasRequiredEncBase64) return encBase64$1.exports;
|
|
2712
|
+
hasRequiredEncBase64 = 1;
|
|
2713
|
+
(function(module2, exports2) {
|
|
2714
|
+
(function(root, factory) {
|
|
2715
|
+
{
|
|
2716
|
+
module2.exports = factory(requireCore());
|
|
2717
|
+
}
|
|
2718
|
+
})(encBase64, function(CryptoJS) {
|
|
2719
|
+
(function() {
|
|
2720
|
+
var C = CryptoJS;
|
|
2721
|
+
var C_lib = C.lib;
|
|
2722
|
+
var WordArray = C_lib.WordArray;
|
|
2723
|
+
var C_enc = C.enc;
|
|
2724
|
+
C_enc.Base64 = {
|
|
2725
|
+
/**
|
|
2726
|
+
* Converts a word array to a Base64 string.
|
|
2727
|
+
*
|
|
2728
|
+
* @param {WordArray} wordArray The word array.
|
|
2729
|
+
*
|
|
2730
|
+
* @return {string} The Base64 string.
|
|
2731
|
+
*
|
|
2732
|
+
* @static
|
|
2733
|
+
*
|
|
2734
|
+
* @example
|
|
2735
|
+
*
|
|
2736
|
+
* var base64String = CryptoJS.enc.Base64.stringify(wordArray);
|
|
2737
|
+
*/
|
|
2738
|
+
stringify: function(wordArray) {
|
|
2739
|
+
var words = wordArray.words;
|
|
2740
|
+
var sigBytes = wordArray.sigBytes;
|
|
2741
|
+
var map = this._map;
|
|
2742
|
+
wordArray.clamp();
|
|
2743
|
+
var base64Chars = [];
|
|
2744
|
+
for (var i = 0; i < sigBytes; i += 3) {
|
|
2745
|
+
var byte1 = words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
|
|
2746
|
+
var byte2 = words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
|
|
2747
|
+
var byte3 = words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
|
|
2748
|
+
var triplet = byte1 << 16 | byte2 << 8 | byte3;
|
|
2749
|
+
for (var j = 0; j < 4 && i + j * 0.75 < sigBytes; j++) {
|
|
2750
|
+
base64Chars.push(map.charAt(triplet >>> 6 * (3 - j) & 63));
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
var paddingChar = map.charAt(64);
|
|
2754
|
+
if (paddingChar) {
|
|
2755
|
+
while (base64Chars.length % 4) {
|
|
2756
|
+
base64Chars.push(paddingChar);
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
return base64Chars.join("");
|
|
2760
|
+
},
|
|
2761
|
+
/**
|
|
2762
|
+
* Converts a Base64 string to a word array.
|
|
2763
|
+
*
|
|
2764
|
+
* @param {string} base64Str The Base64 string.
|
|
2765
|
+
*
|
|
2766
|
+
* @return {WordArray} The word array.
|
|
2767
|
+
*
|
|
2768
|
+
* @static
|
|
2769
|
+
*
|
|
2770
|
+
* @example
|
|
2771
|
+
*
|
|
2772
|
+
* var wordArray = CryptoJS.enc.Base64.parse(base64String);
|
|
2773
|
+
*/
|
|
2774
|
+
parse: function(base64Str) {
|
|
2775
|
+
var base64StrLength = base64Str.length;
|
|
2776
|
+
var map = this._map;
|
|
2777
|
+
var reverseMap = this._reverseMap;
|
|
2778
|
+
if (!reverseMap) {
|
|
2779
|
+
reverseMap = this._reverseMap = [];
|
|
2780
|
+
for (var j = 0; j < map.length; j++) {
|
|
2781
|
+
reverseMap[map.charCodeAt(j)] = j;
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
var paddingChar = map.charAt(64);
|
|
2785
|
+
if (paddingChar) {
|
|
2786
|
+
var paddingIndex = base64Str.indexOf(paddingChar);
|
|
2787
|
+
if (paddingIndex !== -1) {
|
|
2788
|
+
base64StrLength = paddingIndex;
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
return parseLoop(base64Str, base64StrLength, reverseMap);
|
|
2792
|
+
},
|
|
2793
|
+
_map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
|
2794
|
+
};
|
|
2795
|
+
function parseLoop(base64Str, base64StrLength, reverseMap) {
|
|
2796
|
+
var words = [];
|
|
2797
|
+
var nBytes = 0;
|
|
2798
|
+
for (var i = 0; i < base64StrLength; i++) {
|
|
2799
|
+
if (i % 4) {
|
|
2800
|
+
var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << i % 4 * 2;
|
|
2801
|
+
var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> 6 - i % 4 * 2;
|
|
2802
|
+
var bitsCombined = bits1 | bits2;
|
|
2803
|
+
words[nBytes >>> 2] |= bitsCombined << 24 - nBytes % 4 * 8;
|
|
2804
|
+
nBytes++;
|
|
2805
|
+
}
|
|
2806
|
+
}
|
|
2807
|
+
return WordArray.create(words, nBytes);
|
|
2808
|
+
}
|
|
2809
|
+
})();
|
|
2810
|
+
return CryptoJS.enc.Base64;
|
|
2811
|
+
});
|
|
2812
|
+
})(encBase64$1);
|
|
2813
|
+
return encBase64$1.exports;
|
|
2814
|
+
}
|
|
2815
|
+
var encBase64Exports = requireEncBase64();
|
|
2816
|
+
const Base64 = /* @__PURE__ */ getDefaultExportFromCjs(encBase64Exports);
|
|
2817
|
+
class CryptoUtils {
|
|
2818
|
+
#crypto;
|
|
2819
|
+
constructor() {
|
|
2820
|
+
try {
|
|
2821
|
+
this.#crypto = crypto;
|
|
2822
|
+
} catch {
|
|
2823
|
+
this.#crypto = require("node:crypto");
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
DigestMessage = async function(message) {
|
|
2827
|
+
const hashDigest = sha256(message);
|
|
2828
|
+
return Base64.stringify(hashDigest);
|
|
2829
|
+
};
|
|
2830
|
+
CreateRandomString = (size = 43) => {
|
|
2831
|
+
const randomValues = Array.from(this.#crypto.getRandomValues(new Uint8Array(size)));
|
|
2832
|
+
const b64 = btoa(String.fromCharCode(...randomValues));
|
|
2833
|
+
return b64;
|
|
2834
|
+
};
|
|
2835
|
+
}
|
|
2836
|
+
class QueryParams {
|
|
2837
|
+
DecodeQueryParams = (params) => {
|
|
2838
|
+
const retObj = {};
|
|
2839
|
+
Object.keys(params).filter((k) => typeof params[k] !== "undefined").map((k) => {
|
|
2840
|
+
retObj[decodeURIComponent(k)] = decodeURIComponent(params[k]);
|
|
2841
|
+
});
|
|
2842
|
+
return retObj;
|
|
2843
|
+
};
|
|
2844
|
+
CreateQueryParams = (params) => {
|
|
2845
|
+
return Object.keys(params).filter((k) => typeof params[k] !== "undefined").map((k) => {
|
|
2846
|
+
if (Array.isArray(params[k])) {
|
|
2847
|
+
return encodeURIComponent(k) + "=" + encodeURIComponent(params[k].join(" "));
|
|
2848
|
+
} else {
|
|
2849
|
+
return encodeURIComponent(k) + "=" + encodeURIComponent(params[k]);
|
|
2850
|
+
}
|
|
2851
|
+
}).join("&");
|
|
2852
|
+
};
|
|
2853
|
+
_GetQueryParams = (param) => {
|
|
2854
|
+
let retVal = {};
|
|
2855
|
+
const uri = param.split("?");
|
|
2856
|
+
if (uri.length == 2) {
|
|
2857
|
+
const vars = uri[1].split("&");
|
|
2858
|
+
const getVars = {};
|
|
2859
|
+
let tmp;
|
|
2860
|
+
vars.forEach(function(v) {
|
|
2861
|
+
tmp = v.split("=");
|
|
2862
|
+
if (tmp.length == 2) getVars[tmp[0]] = tmp[1];
|
|
2863
|
+
});
|
|
2864
|
+
retVal = this.DecodeQueryParams(getVars);
|
|
2865
|
+
}
|
|
2866
|
+
return retVal;
|
|
2867
|
+
};
|
|
2868
|
+
GetQueryParams = () => {
|
|
2869
|
+
return this._GetQueryParams(window.location.href);
|
|
2870
|
+
};
|
|
2871
|
+
}
|
|
2872
|
+
var StatusCodes;
|
|
2873
|
+
(function(StatusCodes2) {
|
|
2874
|
+
StatusCodes2[StatusCodes2["CONTINUE"] = 100] = "CONTINUE";
|
|
2875
|
+
StatusCodes2[StatusCodes2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
2876
|
+
StatusCodes2[StatusCodes2["PROCESSING"] = 102] = "PROCESSING";
|
|
2877
|
+
StatusCodes2[StatusCodes2["EARLY_HINTS"] = 103] = "EARLY_HINTS";
|
|
2878
|
+
StatusCodes2[StatusCodes2["OK"] = 200] = "OK";
|
|
2879
|
+
StatusCodes2[StatusCodes2["CREATED"] = 201] = "CREATED";
|
|
2880
|
+
StatusCodes2[StatusCodes2["ACCEPTED"] = 202] = "ACCEPTED";
|
|
2881
|
+
StatusCodes2[StatusCodes2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
2882
|
+
StatusCodes2[StatusCodes2["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
2883
|
+
StatusCodes2[StatusCodes2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
2884
|
+
StatusCodes2[StatusCodes2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
2885
|
+
StatusCodes2[StatusCodes2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
2886
|
+
StatusCodes2[StatusCodes2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
2887
|
+
StatusCodes2[StatusCodes2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
2888
|
+
StatusCodes2[StatusCodes2["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY";
|
|
2889
|
+
StatusCodes2[StatusCodes2["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
2890
|
+
StatusCodes2[StatusCodes2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
2891
|
+
StatusCodes2[StatusCodes2["USE_PROXY"] = 305] = "USE_PROXY";
|
|
2892
|
+
StatusCodes2[StatusCodes2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
2893
|
+
StatusCodes2[StatusCodes2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
2894
|
+
StatusCodes2[StatusCodes2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
2895
|
+
StatusCodes2[StatusCodes2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
2896
|
+
StatusCodes2[StatusCodes2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
2897
|
+
StatusCodes2[StatusCodes2["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
2898
|
+
StatusCodes2[StatusCodes2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
2899
|
+
StatusCodes2[StatusCodes2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
2900
|
+
StatusCodes2[StatusCodes2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
2901
|
+
StatusCodes2[StatusCodes2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
2902
|
+
StatusCodes2[StatusCodes2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
2903
|
+
StatusCodes2[StatusCodes2["CONFLICT"] = 409] = "CONFLICT";
|
|
2904
|
+
StatusCodes2[StatusCodes2["GONE"] = 410] = "GONE";
|
|
2905
|
+
StatusCodes2[StatusCodes2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
2906
|
+
StatusCodes2[StatusCodes2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
2907
|
+
StatusCodes2[StatusCodes2["REQUEST_TOO_LONG"] = 413] = "REQUEST_TOO_LONG";
|
|
2908
|
+
StatusCodes2[StatusCodes2["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
|
|
2909
|
+
StatusCodes2[StatusCodes2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
2910
|
+
StatusCodes2[StatusCodes2["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
|
|
2911
|
+
StatusCodes2[StatusCodes2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
2912
|
+
StatusCodes2[StatusCodes2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
2913
|
+
StatusCodes2[StatusCodes2["INSUFFICIENT_SPACE_ON_RESOURCE"] = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE";
|
|
2914
|
+
StatusCodes2[StatusCodes2["METHOD_FAILURE"] = 420] = "METHOD_FAILURE";
|
|
2915
|
+
StatusCodes2[StatusCodes2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
2916
|
+
StatusCodes2[StatusCodes2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
2917
|
+
StatusCodes2[StatusCodes2["LOCKED"] = 423] = "LOCKED";
|
|
2918
|
+
StatusCodes2[StatusCodes2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
2919
|
+
StatusCodes2[StatusCodes2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
2920
|
+
StatusCodes2[StatusCodes2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
2921
|
+
StatusCodes2[StatusCodes2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
2922
|
+
StatusCodes2[StatusCodes2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
2923
|
+
StatusCodes2[StatusCodes2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
2924
|
+
StatusCodes2[StatusCodes2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
2925
|
+
StatusCodes2[StatusCodes2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
2926
|
+
StatusCodes2[StatusCodes2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
2927
|
+
StatusCodes2[StatusCodes2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
2928
|
+
StatusCodes2[StatusCodes2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
2929
|
+
StatusCodes2[StatusCodes2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
2930
|
+
StatusCodes2[StatusCodes2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
2931
|
+
StatusCodes2[StatusCodes2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
2932
|
+
})(StatusCodes || (StatusCodes = {}));
|
|
2933
|
+
class STSOAuth2Worker {
|
|
2934
|
+
//#storageManager = null;
|
|
2935
|
+
#clientSessionStore;
|
|
2936
|
+
#cUtils = new CryptoUtils();
|
|
2937
|
+
#qParams = new QueryParams();
|
|
2938
|
+
#STORAGE_SESSION_KEY = "session.stsmda.com.au";
|
|
2939
|
+
//@@#aic = null;
|
|
2940
|
+
#oauthWorkerPort;
|
|
2941
|
+
#options;
|
|
2942
|
+
#logger;
|
|
2943
|
+
#agentManager = null;
|
|
2944
|
+
constructor(workerPort, options, logger) {
|
|
2945
|
+
this.#options = options;
|
|
2946
|
+
this.#logger = logger;
|
|
2947
|
+
this.#LogDebugMessage(`STSOAuth2Worker:constructor:#options: [${JSON.stringify(this.#options)}]`);
|
|
2948
|
+
this.#clientSessionStore = new stsvueutils.ClientStorageFactory({ clientStorageType: stsvueutils.ClientStorageType.MEMORY_STORAGE, usePrefix: false }).GetStorage();
|
|
2949
|
+
this.#oauthWorkerPort = workerPort;
|
|
2950
|
+
this.#LogDebugMessage(`STSOAuth2Worker:constructor:#oauthWorkerPort: [${JSON.stringify(this.#oauthWorkerPort)}]`);
|
|
2951
|
+
if (isNode && this.#options.agentOptions) {
|
|
2952
|
+
this.#agentManager = new stsutils.AgentManager({
|
|
2953
|
+
agentOptions: this.#options.agentOptions,
|
|
2954
|
+
httpAgentFactory(options2) {
|
|
2955
|
+
return new http.Agent(options2);
|
|
2956
|
+
},
|
|
2957
|
+
httpsAgentFactory(options2) {
|
|
2958
|
+
return new https.Agent(options2);
|
|
2959
|
+
}
|
|
2960
|
+
});
|
|
2961
|
+
}
|
|
2962
|
+
this.SetupListener();
|
|
2963
|
+
this.#UpdateInstrument(stsobservability.Gauge.LOGGER, {
|
|
2964
|
+
LogMessage: `STSOauth2 Plugin - Successfully Loaded`
|
|
2965
|
+
});
|
|
2966
|
+
}
|
|
2967
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2968
|
+
#LogDebugMessage(message) {
|
|
2969
|
+
this.#logger.debug(message);
|
|
2970
|
+
}
|
|
2971
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2972
|
+
#LogInfoMessage(message) {
|
|
2973
|
+
this.#logger.info(message);
|
|
2974
|
+
}
|
|
2975
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2976
|
+
#LogErrorMessage(message) {
|
|
2977
|
+
this.#logger.error(message);
|
|
2978
|
+
}
|
|
2979
|
+
// Attempt to restore a previous session using the STSBroker
|
|
2980
|
+
/*
|
|
2981
|
+
{ parameterType: OAuth2ParameterType.CLIENT_ID, errorType: authErrorType.CLIENT_ID_MISMATCH },
|
|
2982
|
+
{ parameterType: OAuth2ParameterType.SCOPE, errorType: authErrorType.SCOPE_MISMATCH }
|
|
2983
|
+
{ parameterType: OAuth2ParameterType.REDIRECT_URI, errorType: authErrorType.REDIRECT_URI_MISMATCH },
|
|
2984
|
+
{ parameterType: OAuth2ParameterType.AUDIENCE, errorType: authErrorType.SCOPE_MISMATCH }
|
|
2985
|
+
|
|
2986
|
+
Successful Response
|
|
2987
|
+
{
|
|
2988
|
+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1Q...",
|
|
2989
|
+
"token_type": "Bearer",
|
|
2990
|
+
"expires_in": 3599,
|
|
2991
|
+
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
|
|
2992
|
+
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
|
|
2993
|
+
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD...",
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
Error Response
|
|
2997
|
+
{
|
|
2998
|
+
"error": "invalid_scope",
|
|
2999
|
+
"error_description": "AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope https://foo.microsoft.com/mail.read is not valid.\r\nTrace ID: 255d1aef-8c98-452f-ac51-23d051240864\r\nCorrelation ID: fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\r\nTimestamp: 2016-01-09 02:02:12Z",
|
|
3000
|
+
"error_codes": [
|
|
3001
|
+
70011
|
|
3002
|
+
],
|
|
3003
|
+
"timestamp": "2016-01-09 02:02:12Z",
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
*/
|
|
3007
|
+
#HandleAuthenticateEvent = (id_token) => {
|
|
3008
|
+
const message = {
|
|
3009
|
+
messageId: -1,
|
|
3010
|
+
// un-solicited message
|
|
3011
|
+
command: IOauth2ListenerCommand.AUTHENTICATE_EVENT
|
|
3012
|
+
};
|
|
3013
|
+
this.#ProcessCommand(message, id_token);
|
|
3014
|
+
};
|
|
3015
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3016
|
+
#HandleErrorEvent = (error) => {
|
|
3017
|
+
const message = {
|
|
3018
|
+
messageId: -1,
|
|
3019
|
+
// un-solicited message
|
|
3020
|
+
command: IOauth2ListenerCommand.ERROR
|
|
3021
|
+
};
|
|
3022
|
+
this.#ProcessCommand(message, error);
|
|
3023
|
+
};
|
|
3024
|
+
#LogMessage = (messageToSend) => {
|
|
3025
|
+
const message = {
|
|
3026
|
+
messageId: -1,
|
|
3027
|
+
// un-solicited message
|
|
3028
|
+
command: IOauth2ListenerCommand.LOG
|
|
3029
|
+
};
|
|
3030
|
+
this.#ProcessCommand(message, messageToSend);
|
|
3031
|
+
};
|
|
3032
|
+
#GetAccessToken = () => {
|
|
3033
|
+
const sessionData = this.#clientSessionStore.get(this.#STORAGE_SESSION_KEY);
|
|
3034
|
+
if (sessionData) {
|
|
3035
|
+
const tokens = sessionData.tokenResponse;
|
|
3036
|
+
return tokens.access_token;
|
|
3037
|
+
} else {
|
|
3038
|
+
return null;
|
|
3039
|
+
}
|
|
3040
|
+
};
|
|
3041
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3042
|
+
#GetCookies = () => {
|
|
3043
|
+
if (isNode) {
|
|
3044
|
+
const sessionData = this.#clientSessionStore.get(this.#STORAGE_SESSION_KEY);
|
|
3045
|
+
if (sessionData) {
|
|
3046
|
+
return sessionData.brokerCookie;
|
|
3047
|
+
} else {
|
|
3048
|
+
return null;
|
|
3049
|
+
}
|
|
3050
|
+
} else {
|
|
3051
|
+
return null;
|
|
3052
|
+
}
|
|
3053
|
+
};
|
|
3054
|
+
#UpdateInstrument = (instrumentName, telemetry) => {
|
|
3055
|
+
const message = {
|
|
3056
|
+
messageId: -1,
|
|
3057
|
+
// un-solicited message
|
|
3058
|
+
command: IOauth2ListenerCommand.UPDATE_INSTRUMENT
|
|
3059
|
+
};
|
|
3060
|
+
this.#ProcessCommand(message, {
|
|
3061
|
+
instrumentName,
|
|
3062
|
+
telemetry
|
|
3063
|
+
});
|
|
3064
|
+
};
|
|
3065
|
+
SetupListener = () => {
|
|
3066
|
+
this.#oauthWorkerPort.onmessage = async (data) => {
|
|
3067
|
+
const auth2ListenerMessage = data.data;
|
|
3068
|
+
this.#LogDebugMessage(`STSOAuth2Worker:SetupListener:onmessage: [${auth2ListenerMessage.command}]`);
|
|
3069
|
+
switch (auth2ListenerMessage.command) {
|
|
3070
|
+
case IOauth2ListenerCommand.RESTORE_SESSION:
|
|
3071
|
+
this.#ProcessCommand(auth2ListenerMessage, await this.#RestoreSession());
|
|
3072
|
+
break;
|
|
3073
|
+
case IOauth2ListenerCommand.AUTHORIZE:
|
|
3074
|
+
this.#ProcessCommand(auth2ListenerMessage, await this.#Authorize());
|
|
3075
|
+
break;
|
|
3076
|
+
case IOauth2ListenerCommand.HANDLE_REDIRECT:
|
|
3077
|
+
this.#ProcessCommand(auth2ListenerMessage, await this.#HandleRedirect(auth2ListenerMessage.payload));
|
|
3078
|
+
break;
|
|
3079
|
+
case IOauth2ListenerCommand.LOGOUT:
|
|
3080
|
+
this.#ProcessCommand(auth2ListenerMessage, await this.#Logout());
|
|
3081
|
+
break;
|
|
3082
|
+
//@@ Need a way of keeping this out of the main thread - should always stay within the worker
|
|
3083
|
+
case IOauth2ListenerCommand.ACCESS_TOKEN:
|
|
3084
|
+
this.#ProcessCommand(auth2ListenerMessage, await this.#GetAccessToken());
|
|
3085
|
+
break;
|
|
3086
|
+
case IOauth2ListenerCommand.EXECUTE_REFRESH_TOKEN:
|
|
3087
|
+
this.#ProcessCommand(auth2ListenerMessage, await this.#RefreshToken());
|
|
3088
|
+
break;
|
|
3089
|
+
case IOauth2ListenerCommand.COOKIES:
|
|
3090
|
+
this.#ProcessCommand(auth2ListenerMessage, await this.#GetCookies());
|
|
3091
|
+
break;
|
|
3092
|
+
default:
|
|
3093
|
+
throw new Error(`Command: [${auth2ListenerMessage.command}'] not found.`);
|
|
3094
|
+
}
|
|
3095
|
+
};
|
|
3096
|
+
};
|
|
3097
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3098
|
+
#ProcessCommand = async (auth2ListenerMessage, response) => {
|
|
3099
|
+
const messageResponse = {
|
|
3100
|
+
messageId: auth2ListenerMessage.messageId,
|
|
3101
|
+
command: auth2ListenerMessage.command,
|
|
3102
|
+
payload: response
|
|
3103
|
+
};
|
|
3104
|
+
this.#oauthWorkerPort.postMessage(messageResponse);
|
|
3105
|
+
};
|
|
3106
|
+
#RestoreSession = async () => {
|
|
3107
|
+
let restoredSessionData = null;
|
|
3108
|
+
const sessionData = this.#clientSessionStore.get(this.#STORAGE_SESSION_KEY);
|
|
3109
|
+
if (sessionData) {
|
|
3110
|
+
restoredSessionData = sessionData.tokenResponse;
|
|
3111
|
+
this.#LogInfoMessage("Session restored from client storage.");
|
|
3112
|
+
this.#LogMessage("Session restored from client storage.");
|
|
3113
|
+
} else {
|
|
3114
|
+
const url = `${this.#options.brokerendpoint}:${this.#options.brokerport}${this.#options.brokerapiroot}/session`;
|
|
3115
|
+
this.#LogInfoMessage("RestoreSession");
|
|
3116
|
+
this.#LogInfoMessage(url);
|
|
3117
|
+
this.#LogMessage("RestoreSession.");
|
|
3118
|
+
this.#LogMessage(url);
|
|
3119
|
+
try {
|
|
3120
|
+
const rConfig = new stsutils.STSAxiosConfig(url, "post").withData({
|
|
3121
|
+
[stsutils.OAuth2ParameterType.CLIENT_ID]: this.#options.client_id,
|
|
3122
|
+
[stsutils.OAuth2ParameterType.SCOPE]: this.#options.scope,
|
|
3123
|
+
[stsutils.OAuth2ParameterType.REDIRECT_URI]: this.#options.redirect_uri,
|
|
3124
|
+
[stsutils.OAuth2ParameterType.AUDIENCE]: this.#options.audience
|
|
3125
|
+
}).withDefaultHeaders().withCredentials().withTimeout(this.#options.timeout);
|
|
3126
|
+
this.#LogDebugMessage(chalk.magenta(`#RestoreSession:session request detail: [${JSON.stringify(rConfig)}]`));
|
|
3127
|
+
if (isNode && this.#agentManager) {
|
|
3128
|
+
rConfig.withAgentManager(this.#agentManager);
|
|
3129
|
+
}
|
|
3130
|
+
const retVal = await axios(rConfig.config);
|
|
3131
|
+
if (retVal.data.status === StatusCodes.OK) {
|
|
3132
|
+
restoredSessionData = retVal.data.detail;
|
|
3133
|
+
if (restoredSessionData) {
|
|
3134
|
+
const newSessionData = {
|
|
3135
|
+
tokenResponse: restoredSessionData
|
|
3136
|
+
};
|
|
3137
|
+
if (isNode) {
|
|
3138
|
+
newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
3139
|
+
}
|
|
3140
|
+
this.#clientSessionStore.set(this.#STORAGE_SESSION_KEY, newSessionData);
|
|
3141
|
+
this.#LogInfoMessage("Session restored from server side cookie.");
|
|
3142
|
+
} else {
|
|
3143
|
+
this.#LogErrorMessage(`Could not restore previous session. No restoredSessionData available.`);
|
|
3144
|
+
this.#LogErrorMessage(JSON.stringify(retVal.data));
|
|
3145
|
+
}
|
|
3146
|
+
} else {
|
|
3147
|
+
this.#LogErrorMessage("Could not restore previous session:-");
|
|
3148
|
+
this.#LogErrorMessage(JSON.stringify(retVal.data));
|
|
3149
|
+
}
|
|
3150
|
+
} catch (error) {
|
|
3151
|
+
this.#LogErrorMessage("Could not restore previous session (error state):-");
|
|
3152
|
+
this.#LogErrorMessage(error);
|
|
3153
|
+
this.#LogErrorMessage(JSON.stringify(error));
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3156
|
+
if (restoredSessionData !== null) {
|
|
3157
|
+
this.#HandleAuthenticateEvent(restoredSessionData.id_token);
|
|
3158
|
+
this.#LogInfoMessage("Refreshing tokens ...");
|
|
3159
|
+
return await this.#RefreshToken();
|
|
3160
|
+
} else {
|
|
3161
|
+
this.#HandleAuthenticateEvent(null);
|
|
3162
|
+
return false;
|
|
3163
|
+
}
|
|
3164
|
+
};
|
|
3165
|
+
#Authorize = async () => {
|
|
3166
|
+
this.#LogInfoMessage("Authorize ...");
|
|
3167
|
+
const client_id = this.#options.client_id;
|
|
3168
|
+
const nonce = this.#cUtils.CreateRandomString();
|
|
3169
|
+
const response_type = [AuthorizeOptionsResponseType.CODE];
|
|
3170
|
+
const redirect_uri = this.#options.redirect_uri;
|
|
3171
|
+
const response_mode = AuthorizeOptionsResponseMode.QUERY;
|
|
3172
|
+
const scope = this.#options.scope;
|
|
3173
|
+
const state = this.#cUtils.CreateRandomString();
|
|
3174
|
+
const code_verifier = this.#cUtils.CreateRandomString();
|
|
3175
|
+
const code_challenge = await this.#cUtils.DigestMessage(code_verifier);
|
|
3176
|
+
const code_challenge_method = "S256";
|
|
3177
|
+
const authorizeOptions = {
|
|
3178
|
+
client_id,
|
|
3179
|
+
nonce,
|
|
3180
|
+
response_type,
|
|
3181
|
+
redirect_uri,
|
|
3182
|
+
response_mode,
|
|
3183
|
+
scope,
|
|
3184
|
+
state,
|
|
3185
|
+
code_challenge,
|
|
3186
|
+
code_challenge_method
|
|
3187
|
+
};
|
|
3188
|
+
const authorizeOptionsClientCopy = { ...authorizeOptions };
|
|
3189
|
+
const url = `${this.#options.authorizeendpoint}:${this.#options.authorizeport}${this.#options.authorizeapiroot}${this.#options.authorizeapi}?${this.#qParams.CreateQueryParams(authorizeOptions)}`;
|
|
3190
|
+
this.#LogInfoMessage(url);
|
|
3191
|
+
authorizeOptions.code_verifier = code_verifier;
|
|
3192
|
+
this.#LogInfoMessage(`Authorize:authorizeOptions: [${JSON.stringify(authorizeOptions)}]`);
|
|
3193
|
+
return {
|
|
3194
|
+
url,
|
|
3195
|
+
authorizeOptions,
|
|
3196
|
+
authorizeOptionsClientCopy
|
|
3197
|
+
};
|
|
3198
|
+
};
|
|
3199
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3200
|
+
#HandleRedirect = async (payload) => {
|
|
3201
|
+
const queryVars = payload.queryVars;
|
|
3202
|
+
const authorizeOptions = payload.authorizeOptions;
|
|
3203
|
+
this.#LogDebugMessage(chalk.magenta(`#HandleRedirect: HandleRedirect`));
|
|
3204
|
+
this.#LogDebugMessage(chalk.magenta(`#HandleRedirect: HandleRedirect:Query Vars: [${JSON.stringify(queryVars)}]`));
|
|
3205
|
+
if (queryVars[stsutils.OAuth2ParameterType.CODE]) {
|
|
3206
|
+
const response = queryVars;
|
|
3207
|
+
this.#LogInfoMessage(`authorizeOptions from transaction state: [${JSON.stringify(authorizeOptions)}]`);
|
|
3208
|
+
const redirectState = response.state;
|
|
3209
|
+
const authorizeOptionsState = authorizeOptions.state;
|
|
3210
|
+
if (authorizeOptionsState.localeCompare(redirectState) === 0) {
|
|
3211
|
+
this.#LogInfoMessage(chalk.green("redirected state (from queryVars) matched previously saved transaction authorizeOptions state"));
|
|
3212
|
+
return await this.#GetToken(authorizeOptions, response);
|
|
3213
|
+
} else {
|
|
3214
|
+
this.#LogErrorMessage(chalk.red("redirected state (from queryVars) did NOT match previously saved transaction authorizeOptions state"));
|
|
3215
|
+
this.#LogErrorMessage(chalk.red(`authorizeOptionsState: [${authorizeOptionsState}]`));
|
|
3216
|
+
this.#LogErrorMessage(chalk.red(`redirectState: [${redirectState}]`));
|
|
3217
|
+
this.#HandleErrorEvent({ message: "State un-matched" });
|
|
3218
|
+
return false;
|
|
3219
|
+
}
|
|
3220
|
+
} else if (queryVars[stsutils.OAuth2ParameterType.ERROR]) {
|
|
3221
|
+
this.#LogErrorMessage(chalk.red(`State un-matched (1)`));
|
|
3222
|
+
this.#HandleErrorEvent({ message: "State un-matched" });
|
|
3223
|
+
return false;
|
|
3224
|
+
} else {
|
|
3225
|
+
this.#LogErrorMessage(chalk.red(`State un-matched (2)`));
|
|
3226
|
+
this.#HandleErrorEvent({ message: "State un-matched" });
|
|
3227
|
+
return false;
|
|
3228
|
+
}
|
|
3229
|
+
};
|
|
3230
|
+
/*
|
|
3231
|
+
client_id=6731de76-14a6-49ae-97bc-6eba6914391e
|
|
3232
|
+
&scope=https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
|
|
3233
|
+
&code=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq3n8b2JRLk4OxVXr...
|
|
3234
|
+
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
|
|
3235
|
+
&grant_type=authorization_code
|
|
3236
|
+
&code_verifier=ThisIsntRandomButItNeedsToBe43CharactersLong
|
|
3237
|
+
&client_secret=JqQX2PNo9bpM0uEihUPzyrh // NOTE: Only required for web apps. This secret needs to be URL-Encoded.
|
|
3238
|
+
|
|
3239
|
+
Successful Response
|
|
3240
|
+
{
|
|
3241
|
+
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1Q...",
|
|
3242
|
+
"token_type": "Bearer",
|
|
3243
|
+
"expires_in": 3599,
|
|
3244
|
+
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
|
|
3245
|
+
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
|
|
3246
|
+
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD...",
|
|
3247
|
+
}
|
|
3248
|
+
*/
|
|
3249
|
+
// Get access_token, refresh_token and id_token using OAuth2 Authorization Code Flow
|
|
3250
|
+
#GetTokenFromBroker = async (authorizationCodeFlowParameters) => {
|
|
3251
|
+
this.#LogDebugMessage(chalk.magenta(`#GetTokenFromBroker`));
|
|
3252
|
+
this.#clientSessionStore.remove(this.#STORAGE_SESSION_KEY);
|
|
3253
|
+
const url = `${this.#options.brokerendpoint}:${this.#options.brokerport}${this.#options.brokerapiroot}/token`;
|
|
3254
|
+
try {
|
|
3255
|
+
const rConfig = new stsutils.STSAxiosConfig(url, "post").withDefaultHeaders().withData(authorizationCodeFlowParameters).withCredentials().withTimeout(this.#options.timeout);
|
|
3256
|
+
this.#LogDebugMessage(chalk.magenta(`#GetTokenFromBroker: request config: [${JSON.stringify(rConfig)}]`));
|
|
3257
|
+
if (isNode && this.#agentManager) {
|
|
3258
|
+
rConfig.withAgentManager(this.#agentManager);
|
|
3259
|
+
}
|
|
3260
|
+
this.#LogDebugMessage(chalk.magenta(`#GetTokenFromBroker: axios API call`));
|
|
3261
|
+
const retVal = await axios(rConfig.config);
|
|
3262
|
+
this.#LogDebugMessage(chalk.magenta(`#GetTokenFromBroker: axios API call result: [${retVal.status}]`));
|
|
3263
|
+
if (retVal.status === StatusCodes.OK) {
|
|
3264
|
+
this.#LogDebugMessage(chalk.magenta(`#GetTokenFromBroker: storing tokens`));
|
|
3265
|
+
const tokenResponse = retVal.data;
|
|
3266
|
+
this.#HandleAuthenticateEvent(tokenResponse.id_token);
|
|
3267
|
+
const newSessionData = {
|
|
3268
|
+
tokenResponse
|
|
3269
|
+
};
|
|
3270
|
+
if (isNode) {
|
|
3271
|
+
newSessionData.brokerCookie = retVal.headers["set-cookie"];
|
|
3272
|
+
}
|
|
3273
|
+
this.#clientSessionStore.set(this.#STORAGE_SESSION_KEY, newSessionData);
|
|
3274
|
+
return true;
|
|
3275
|
+
} else if (retVal.status === StatusCodes.UNAUTHORIZED) {
|
|
3276
|
+
this.#LogDebugMessage(chalk.magenta(`#GetTokenFromBroker: NOT storing tokens, status: [${retVal.status}]`));
|
|
3277
|
+
this.#HandleAuthenticateEvent(null);
|
|
3278
|
+
return false;
|
|
3279
|
+
} else {
|
|
3280
|
+
this.#LogDebugMessage(chalk.magenta(`#GetTokenFromBroker: NOT storing tokens (general error 1), status: [${retVal.status}]`));
|
|
3281
|
+
this.#HandleAuthenticateEvent(null);
|
|
3282
|
+
this.#LogErrorMessage(chalk.red("Could not obtain access_token from token end-point:-"));
|
|
3283
|
+
this.#LogErrorMessage(chalk.red(JSON.stringify(retVal.data)));
|
|
3284
|
+
return false;
|
|
3285
|
+
}
|
|
3286
|
+
} catch (error) {
|
|
3287
|
+
this.#LogErrorMessage(chalk.red(`#GetTokenFromBroker: NOT storing tokens (general error 2), status: [${error}]`));
|
|
3288
|
+
this.#HandleAuthenticateEvent(null);
|
|
3289
|
+
return false;
|
|
3290
|
+
}
|
|
3291
|
+
};
|
|
3292
|
+
// Get access_token, refresh_token and id_token using OAuth2 Authorization Code Flow
|
|
3293
|
+
#GetToken = async (authorizeOptions, authorizeResponse) => {
|
|
3294
|
+
this.#LogInfoMessage("#GetToken");
|
|
3295
|
+
this.#LogInfoMessage(authorizeResponse);
|
|
3296
|
+
this.#clientSessionStore.remove(this.#STORAGE_SESSION_KEY);
|
|
3297
|
+
const authorizationCodeFlowParameters = {
|
|
3298
|
+
client_id: this.#options.client_id,
|
|
3299
|
+
scope: this.#options.scope,
|
|
3300
|
+
code: authorizeResponse.code,
|
|
3301
|
+
redirect_uri: this.#options.redirect_uri,
|
|
3302
|
+
grant_type: OAuthGrantTypes.AUTHORIZATION_CODE,
|
|
3303
|
+
code_verifier: authorizeOptions.code_verifier
|
|
3304
|
+
};
|
|
3305
|
+
return await this.#GetTokenFromBroker(authorizationCodeFlowParameters);
|
|
3306
|
+
};
|
|
3307
|
+
/*
|
|
3308
|
+
// Line breaks for legibility only
|
|
3309
|
+
|
|
3310
|
+
POST /{tenant}/oauth2/v2.0/token HTTP/1.1
|
|
3311
|
+
Host: https://login.microsoftonline.com
|
|
3312
|
+
Content-Type: application/x-www-form-urlencoded
|
|
3313
|
+
|
|
3314
|
+
client_id=535fb089-9ff3-47b6-9bfb-4f1264799865
|
|
3315
|
+
&scope=https%3A%2F%2Fgraph.microsoft.com%2Fmail.read
|
|
3316
|
+
&refresh_token=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq...
|
|
3317
|
+
&grant_type=refresh_token
|
|
3318
|
+
&client_secret=sampleCredentia1s // NOTE: Only required for web apps. This secret needs to be URL-Encoded
|
|
3319
|
+
|
|
3320
|
+
Error Response
|
|
3321
|
+
{
|
|
3322
|
+
"error": "invalid_scope",
|
|
3323
|
+
"error_description": "AADSTS70011: The provided value for the input parameter 'scope' is not valid. The scope https://foo.microsoft.com/mail.read is not valid.\r\nTrace ID: 255d1aef-8c98-452f-ac51-23d051240864\r\nCorrelation ID: fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7\r\nTimestamp: 2016-01-09 02:02:12Z",
|
|
3324
|
+
"error_codes": [
|
|
3325
|
+
70011
|
|
3326
|
+
],
|
|
3327
|
+
"timestamp": "2016-01-09 02:02:12Z",
|
|
3328
|
+
"trace_id": "255d1aef-8c98-452f-ac51-23d051240864",
|
|
3329
|
+
"correlation_id": "fb3d2015-bc17-4bb9-bb85-30c5cf1aaaa7"
|
|
3330
|
+
}
|
|
3331
|
+
*/
|
|
3332
|
+
#RefreshToken = async () => {
|
|
3333
|
+
this.#LogDebugMessage(chalk.cyan(`STSOAuth2Worker:#RefreshToken:start`));
|
|
3334
|
+
const sessionData = this.#clientSessionStore.get(this.#STORAGE_SESSION_KEY);
|
|
3335
|
+
if (sessionData) {
|
|
3336
|
+
this.#LogDebugMessage(chalk.cyan(`STSOAuth2Worker:#RefreshToken:sessionData: [${JSON.stringify(sessionData)}]`));
|
|
3337
|
+
const currentSessionData = sessionData.tokenResponse;
|
|
3338
|
+
const refreshFlowParameters = {
|
|
3339
|
+
client_id: this.#options.client_id,
|
|
3340
|
+
scope: this.#options.scope,
|
|
3341
|
+
refresh_token: currentSessionData.refresh_token,
|
|
3342
|
+
grant_type: OAuthGrantTypes.REFRESH_TOKEN
|
|
3343
|
+
};
|
|
3344
|
+
return await this.#GetTokenFromBroker(refreshFlowParameters);
|
|
3345
|
+
} else {
|
|
3346
|
+
this.#LogErrorMessage(chalk.red(`STSOAuth2Worker:#RefreshToken:sessionData not found within clientSessionStore`));
|
|
3347
|
+
return false;
|
|
3348
|
+
}
|
|
3349
|
+
};
|
|
3350
|
+
// call broker to logout
|
|
3351
|
+
// broker to logout of server
|
|
3352
|
+
// delete cookie
|
|
3353
|
+
// clear session storage
|
|
3354
|
+
// clear all state from $store
|
|
3355
|
+
#Logout = async () => {
|
|
3356
|
+
this.#LogInfoMessage("Logout");
|
|
3357
|
+
const url = `${this.#options.brokerendpoint}:${this.#options.brokerport}${this.#options.brokerapiroot}/logout`;
|
|
3358
|
+
this.#LogInfoMessage(url);
|
|
3359
|
+
const sessionData = this.#clientSessionStore.get(this.#STORAGE_SESSION_KEY);
|
|
3360
|
+
if (sessionData) {
|
|
3361
|
+
const currentSessionData = sessionData.tokenResponse;
|
|
3362
|
+
const refresh_token = currentSessionData.refresh_token;
|
|
3363
|
+
this.#LogInfoMessage(refresh_token);
|
|
3364
|
+
const decodedRefreshToken = jwtDecode(refresh_token);
|
|
3365
|
+
this.#LogInfoMessage(decodedRefreshToken);
|
|
3366
|
+
const sessionId = decodedRefreshToken.sts_session;
|
|
3367
|
+
this.#LogInfoMessage(sessionId);
|
|
3368
|
+
this.#clientSessionStore.remove(this.#STORAGE_SESSION_KEY);
|
|
3369
|
+
this.#HandleAuthenticateEvent(null);
|
|
3370
|
+
try {
|
|
3371
|
+
const rConfig = new stsutils.STSAxiosConfig(url, "post").withData({
|
|
3372
|
+
sessionId
|
|
3373
|
+
}).withDefaultHeaders().withCredentials().withTimeout(this.#options.timeout);
|
|
3374
|
+
if (isNode && this.#agentManager) {
|
|
3375
|
+
rConfig.withAgentManager(this.#agentManager);
|
|
3376
|
+
}
|
|
3377
|
+
this.#LogDebugMessage(chalk.magenta(`#Logout: request config: [${rConfig}]`));
|
|
3378
|
+
const retVal = await axios(rConfig.config);
|
|
3379
|
+
if (retVal.data.status === StatusCodes.OK) {
|
|
3380
|
+
return true;
|
|
3381
|
+
} else {
|
|
3382
|
+
this.#LogErrorMessage(chalk.red("Error during logout (1: server side)"));
|
|
3383
|
+
this.#LogErrorMessage(chalk.red(JSON.stringify(retVal.data)));
|
|
3384
|
+
return false;
|
|
3385
|
+
}
|
|
3386
|
+
} catch (error) {
|
|
3387
|
+
this.#LogErrorMessage(chalk.red("Error during logout (2: server side)"));
|
|
3388
|
+
this.#LogErrorMessage(chalk.red(error));
|
|
3389
|
+
this.#LogErrorMessage(chalk.red(JSON.stringify(error)));
|
|
3390
|
+
return false;
|
|
3391
|
+
}
|
|
3392
|
+
} else {
|
|
3393
|
+
this.#LogInfoMessage("Error during logout. Could not restore session from session storage.");
|
|
3394
|
+
return false;
|
|
3395
|
+
}
|
|
3396
|
+
};
|
|
3397
|
+
}
|
|
3398
|
+
const TestStore = pinia.defineStore("__sts__TestStore", {
|
|
3399
|
+
state: () => {
|
|
3400
|
+
return {
|
|
3401
|
+
count: 0
|
|
3402
|
+
};
|
|
3403
|
+
},
|
|
3404
|
+
actions: {
|
|
3405
|
+
UpdateCount() {
|
|
3406
|
+
this.count++;
|
|
3407
|
+
}
|
|
3408
|
+
},
|
|
3409
|
+
getters: {
|
|
3410
|
+
CountXX: (state) => {
|
|
3411
|
+
return state.count * 2;
|
|
3412
|
+
}
|
|
3413
|
+
}
|
|
3414
|
+
/*
|
|
3415
|
+
persist: {
|
|
3416
|
+
storage: globalThis.sessionStorage
|
|
3417
|
+
}
|
|
3418
|
+
*/
|
|
3419
|
+
});
|
|
3420
|
+
const useSTSOAuth2ManagerPlugin = () => vue.inject(STSOAuth2ManagerPluginKey);
|
|
3421
|
+
const STSOAuth2ManagerPlugin = {
|
|
3422
|
+
install: (app, options) => {
|
|
3423
|
+
const om = new STSOAuth2Manager(app, options);
|
|
3424
|
+
if (!app.config.globalProperties.$sts) {
|
|
3425
|
+
app.config.globalProperties.$sts = {};
|
|
3426
|
+
}
|
|
3427
|
+
app.config.globalProperties.$sts[STSOAuth2ManagerPluginKey] = om;
|
|
3428
|
+
app.provide(STSOAuth2ManagerPluginKey, om);
|
|
3429
|
+
}
|
|
3430
|
+
};
|
|
3431
|
+
exports.AuthorizeOptionsResponseMode = AuthorizeOptionsResponseMode;
|
|
3432
|
+
exports.AuthorizeOptionsResponseType = AuthorizeOptionsResponseType;
|
|
3433
|
+
exports.IOauth2ListenerCommand = IOauth2ListenerCommand;
|
|
3434
|
+
exports.OAuthGrantTypes = OAuthGrantTypes;
|
|
3435
|
+
exports.STSOAuth2Manager = STSOAuth2Manager;
|
|
3436
|
+
exports.STSOAuth2ManagerPlugin = STSOAuth2ManagerPlugin;
|
|
3437
|
+
exports.STSOAuth2ManagerPluginKey = STSOAuth2ManagerPluginKey;
|
|
3438
|
+
exports.STSOAuth2Worker = STSOAuth2Worker;
|
|
3439
|
+
exports.STSOauth2Store = STSOauth2Store;
|
|
3440
|
+
exports.TestStore = TestStore;
|
|
3441
|
+
exports.useSTSOAuth2ManagerPlugin = useSTSOAuth2ManagerPlugin;
|
|
3442
|
+
//# sourceMappingURL=stsoauth2plugin.cjs.map
|