@mjhls/mjh-framework 1.0.665-beta.2 → 1.0.665-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,447 +0,0 @@
1
- 'use strict';
2
-
3
- var _commonjsHelpers = require('./_commonjsHelpers-06173234.js');
4
- var asyncToGenerator = require('./asyncToGenerator-533d476a.js');
5
- var index$4 = require('./index-bd6c9f56.js');
6
- var getQuery = require('./getQuery.js');
7
-
8
- var defaultParseOptions = {
9
- decodeValues: true,
10
- map: false,
11
- silent: false,
12
- };
13
-
14
- function isNonEmptyString(str) {
15
- return typeof str === "string" && !!str.trim();
16
- }
17
-
18
- function parseString(setCookieValue, options) {
19
- var parts = setCookieValue.split(";").filter(isNonEmptyString);
20
- var nameValue = parts.shift().split("=");
21
- var name = nameValue.shift();
22
- var value = nameValue.join("="); // everything after the first =, joined by a "=" if there was more than one part
23
-
24
- options = options
25
- ? Object.assign({}, defaultParseOptions, options)
26
- : defaultParseOptions;
27
-
28
- var cookie = {
29
- name: name, // grab everything before the first =
30
- value: options.decodeValues ? decodeURIComponent(value) : value, // decode cookie value
31
- };
32
-
33
- parts.forEach(function (part) {
34
- var sides = part.split("=");
35
- var key = sides.shift().trimLeft().toLowerCase();
36
- var value = sides.join("=");
37
- if (key === "expires") {
38
- cookie.expires = new Date(value);
39
- } else if (key === "max-age") {
40
- cookie.maxAge = parseInt(value, 10);
41
- } else if (key === "secure") {
42
- cookie.secure = true;
43
- } else if (key === "httponly") {
44
- cookie.httpOnly = true;
45
- } else if (key === "samesite") {
46
- cookie.sameSite = value;
47
- } else {
48
- cookie[key] = value;
49
- }
50
- });
51
-
52
- return cookie;
53
- }
54
-
55
- function parse(input, options) {
56
- options = options
57
- ? Object.assign({}, defaultParseOptions, options)
58
- : defaultParseOptions;
59
-
60
- if (!input) {
61
- if (!options.map) {
62
- return [];
63
- } else {
64
- return {};
65
- }
66
- }
67
-
68
- if (input.headers && input.headers["set-cookie"]) {
69
- // fast-path for node.js (which automatically normalizes header names to lower-case
70
- input = input.headers["set-cookie"];
71
- } else if (input.headers) {
72
- // slow-path for other environments - see #25
73
- var sch =
74
- input.headers[
75
- Object.keys(input.headers).find(function (key) {
76
- return key.toLowerCase() === "set-cookie";
77
- })
78
- ];
79
- // warn if called on a request-like object with a cookie header rather than a set-cookie header - see #34, 36
80
- if (!sch && input.headers.cookie && !options.silent) {
81
- console.warn(
82
- "Warning: set-cookie-parser appears to have been called on a request object. It is designed to parse Set-Cookie headers from responses, not Cookie headers from requests. Set the option {silent: true} to suppress this warning."
83
- );
84
- }
85
- input = sch;
86
- }
87
- if (!Array.isArray(input)) {
88
- input = [input];
89
- }
90
-
91
- options = options
92
- ? Object.assign({}, defaultParseOptions, options)
93
- : defaultParseOptions;
94
-
95
- if (!options.map) {
96
- return input.filter(isNonEmptyString).map(function (str) {
97
- return parseString(str, options);
98
- });
99
- } else {
100
- var cookies = {};
101
- return input.filter(isNonEmptyString).reduce(function (cookies, str) {
102
- var cookie = parseString(str, options);
103
- cookies[cookie.name] = cookie;
104
- return cookies;
105
- }, cookies);
106
- }
107
- }
108
-
109
- /*
110
- Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
111
- that are within a single set-cookie field-value, such as in the Expires portion.
112
-
113
- This is uncommon, but explicitly allowed - see https://tools.ietf.org/html/rfc2616#section-4.2
114
- Node.js does this for every header *except* set-cookie - see https://github.com/nodejs/node/blob/d5e363b77ebaf1caf67cd7528224b651c86815c1/lib/_http_incoming.js#L128
115
- React Native's fetch does this for *every* header, including set-cookie.
116
-
117
- Based on: https://github.com/google/j2objc/commit/16820fdbc8f76ca0c33472810ce0cb03d20efe25
118
- Credits to: https://github.com/tomball for original and https://github.com/chrusart for JavaScript implementation
119
- */
120
- function splitCookiesString(cookiesString) {
121
- if (Array.isArray(cookiesString)) {
122
- return cookiesString;
123
- }
124
- if (typeof cookiesString !== "string") {
125
- return [];
126
- }
127
-
128
- var cookiesStrings = [];
129
- var pos = 0;
130
- var start;
131
- var ch;
132
- var lastComma;
133
- var nextStart;
134
- var cookiesSeparatorFound;
135
-
136
- function skipWhitespace() {
137
- while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) {
138
- pos += 1;
139
- }
140
- return pos < cookiesString.length;
141
- }
142
-
143
- function notSpecialChar() {
144
- ch = cookiesString.charAt(pos);
145
-
146
- return ch !== "=" && ch !== ";" && ch !== ",";
147
- }
148
-
149
- while (pos < cookiesString.length) {
150
- start = pos;
151
- cookiesSeparatorFound = false;
152
-
153
- while (skipWhitespace()) {
154
- ch = cookiesString.charAt(pos);
155
- if (ch === ",") {
156
- // ',' is a cookie separator if we have later first '=', not ';' or ','
157
- lastComma = pos;
158
- pos += 1;
159
-
160
- skipWhitespace();
161
- nextStart = pos;
162
-
163
- while (pos < cookiesString.length && notSpecialChar()) {
164
- pos += 1;
165
- }
166
-
167
- // currently special character
168
- if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") {
169
- // we found cookies separator
170
- cookiesSeparatorFound = true;
171
- // pos is inside the next cookie, so back up and return it.
172
- pos = nextStart;
173
- cookiesStrings.push(cookiesString.substring(start, lastComma));
174
- start = pos;
175
- } else {
176
- // in param ',' or param separator ';',
177
- // we continue from that comma
178
- pos = lastComma + 1;
179
- }
180
- } else {
181
- pos += 1;
182
- }
183
- }
184
-
185
- if (!cookiesSeparatorFound || pos >= cookiesString.length) {
186
- cookiesStrings.push(cookiesString.substring(start, cookiesString.length));
187
- }
188
- }
189
-
190
- return cookiesStrings;
191
- }
192
-
193
- var setCookie = parse;
194
- var parse_1 = parse;
195
- var parseString_1 = parseString;
196
- var splitCookiesString_1 = splitCookiesString;
197
- setCookie.parse = parse_1;
198
- setCookie.parseString = parseString_1;
199
- setCookie.splitCookiesString = splitCookiesString_1;
200
-
201
- var dist = _commonjsHelpers.createCommonjsModule(function (module, exports) {
202
- var __assign = (_commonjsHelpers.commonjsGlobal && _commonjsHelpers.commonjsGlobal.__assign) || function () {
203
- __assign = Object.assign || function(t) {
204
- for (var s, i = 1, n = arguments.length; i < n; i++) {
205
- s = arguments[i];
206
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
207
- t[p] = s[p];
208
- }
209
- return t;
210
- };
211
- return __assign.apply(this, arguments);
212
- };
213
- Object.defineProperty(exports, "__esModule", { value: true });
214
- exports.destroyCookie = exports.setCookie = exports.parseCookies = void 0;
215
-
216
-
217
- var isBrowser = function () { return typeof window !== 'undefined'; };
218
- function hasSameProperties(a, b) {
219
- var aProps = Object.getOwnPropertyNames(a);
220
- var bProps = Object.getOwnPropertyNames(b);
221
- if (aProps.length !== bProps.length) {
222
- return false;
223
- }
224
- for (var i = 0; i < aProps.length; i++) {
225
- var propName = aProps[i];
226
- if (a[propName] !== b[propName]) {
227
- return false;
228
- }
229
- }
230
- return true;
231
- }
232
- /**
233
- * Compare the cookie and return true if the cookies has equivalent
234
- * options and the cookies would be overwritten in the browser storage.
235
- *
236
- * @param a first Cookie for comparison
237
- * @param b second Cookie for comparison
238
- */
239
- function areCookiesEqual(a, b) {
240
- var sameSiteSame = a.sameSite === b.sameSite;
241
- if (typeof a.sameSite === 'string' && typeof b.sameSite === 'string') {
242
- sameSiteSame = a.sameSite.toLowerCase() === b.sameSite.toLowerCase();
243
- }
244
- return (hasSameProperties(__assign(__assign({}, a), { sameSite: undefined }), __assign(__assign({}, b), { sameSite: undefined })) && sameSiteSame);
245
- }
246
- /**
247
- * Create an instance of the Cookie interface
248
- *
249
- * @param name name of the Cookie
250
- * @param value value of the Cookie
251
- * @param options Cookie options
252
- */
253
- function createCookie(name, value, options) {
254
- var sameSite = options.sameSite;
255
- if (sameSite === true) {
256
- sameSite = 'strict';
257
- }
258
- if (sameSite === undefined || sameSite === false) {
259
- sameSite = 'lax';
260
- }
261
- var cookieToSet = __assign(__assign({}, options), { sameSite: sameSite });
262
- delete cookieToSet.encode;
263
- return __assign({ name: name, value: value }, cookieToSet);
264
- }
265
- /**
266
- *
267
- * Parses cookies.
268
- *
269
- * @param ctx
270
- * @param options
271
- */
272
- function parseCookies(ctx, options) {
273
- if (ctx && ctx.req && ctx.req.headers && ctx.req.headers.cookie) {
274
- return index$4.cookie.parse(ctx.req.headers.cookie, options);
275
- }
276
- if (isBrowser()) {
277
- return index$4.cookie.parse(document.cookie, options);
278
- }
279
- return {};
280
- }
281
- exports.parseCookies = parseCookies;
282
- /**
283
- *
284
- * Sets a cookie.
285
- *
286
- * @param ctx
287
- * @param name
288
- * @param value
289
- * @param options
290
- */
291
- function setCookie$1(ctx, name, value, options) {
292
- if (ctx && ctx.res && ctx.res.getHeader && ctx.res.setHeader) {
293
- var cookies = ctx.res.getHeader('Set-Cookie') || [];
294
- if (typeof cookies === 'string')
295
- cookies = [cookies];
296
- if (typeof cookies === 'number')
297
- cookies = [];
298
- var parsedCookies = setCookie.parse(cookies);
299
- var cookiesToSet_1 = [];
300
- parsedCookies.forEach(function (parsedCookie) {
301
- if (!areCookiesEqual(parsedCookie, createCookie(name, value, options))) {
302
- cookiesToSet_1.push(index$4.cookie.serialize(parsedCookie.name, parsedCookie.value, __assign({}, parsedCookie)));
303
- }
304
- });
305
- cookiesToSet_1.push(index$4.cookie.serialize(name, value, options));
306
- if (!ctx.res.finished) {
307
- ctx.res.setHeader('Set-Cookie', cookiesToSet_1);
308
- }
309
- }
310
- if (isBrowser()) {
311
- if (options && options.httpOnly) {
312
- throw new Error('Can not set a httpOnly cookie in the browser.');
313
- }
314
- document.cookie = index$4.cookie.serialize(name, value, options);
315
- }
316
- return {};
317
- }
318
- exports.setCookie = setCookie$1;
319
- /**
320
- *
321
- * Destroys a cookie with a particular name.
322
- *
323
- * @param ctx
324
- * @param name
325
- * @param options
326
- */
327
- function destroyCookie(ctx, name, options) {
328
- var opts = __assign(__assign({}, (options || {})), { maxAge: -1 });
329
- if (ctx && ctx.res && ctx.res.setHeader && ctx.res.getHeader) {
330
- var cookies = ctx.res.getHeader('Set-Cookie') || [];
331
- if (typeof cookies === 'string')
332
- cookies = [cookies];
333
- if (typeof cookies === 'number')
334
- cookies = [];
335
- cookies.push(index$4.cookie.serialize(name, '', opts));
336
- ctx.res.setHeader('Set-Cookie', cookies);
337
- }
338
- if (isBrowser()) {
339
- document.cookie = index$4.cookie.serialize(name, '', opts);
340
- }
341
- return {};
342
- }
343
- exports.destroyCookie = destroyCookie;
344
- exports.default = {
345
- set: setCookie$1,
346
- get: parseCookies,
347
- destroy: destroyCookie,
348
- };
349
-
350
- });
351
-
352
- _commonjsHelpers.unwrapExports(dist);
353
- var dist_1 = dist.destroyCookie;
354
- var dist_2 = dist.setCookie;
355
- var dist_3 = dist.parseCookies;
356
-
357
- var _this = undefined;
358
-
359
- var getRelatedArticle = function () {
360
- var _ref2 = asyncToGenerator._asyncToGenerator( /*#__PURE__*/asyncToGenerator.regenerator.mark(function _callee() {
361
- var ctx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
362
- var client = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
363
- var article = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
364
- var prevUrl = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '/';
365
- var articleCount = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
366
-
367
- var taxonomyMapping, _article$url, url, content_placement, taxonomy, params, conditions, cookies, prevSlugs, relatedArticleQuery, relatedArticle;
368
-
369
- return asyncToGenerator.regenerator.wrap(function _callee$(_context) {
370
- while (1) {
371
- switch (_context.prev = _context.next) {
372
- case 0:
373
- taxonomyMapping = article.taxonomyMapping, _article$url = article.url;
374
- _article$url = _article$url === undefined ? {
375
- current: null
376
- } : _article$url;
377
- url = _article$url.current, content_placement = article.content_placement;
378
- taxonomy = [];
379
- //404 articles were throwing server error
380
-
381
- if (content_placement) {
382
- content_placement.forEach(function (_ref3) {
383
- var path = _ref3.path,
384
- _id = _ref3._id;
385
-
386
- if (!_id || typeof _id == 'undefined') {
387
- return null;
388
- }
389
- var prev_url_to_check = prevUrl;
390
- if (prev_url_to_check.includes('?')) {
391
- prev_url_to_check = prev_url_to_check.split('?')[0];
392
- }
393
- if (prev_url_to_check.endsWith(path) && _id) taxonomy.push(_id);
394
- });
395
- }
396
-
397
- //404 articles were throwing server error
398
- if (taxonomy.length === 0 && taxonomyMapping) {
399
- taxonomyMapping.forEach(function (_ref4) {
400
- var _ref = _ref4._ref;
401
-
402
- if (_ref) {
403
- taxonomy.push(_ref);
404
- }
405
- });
406
- }
407
-
408
- params = {
409
- url: url,
410
- taxonomy: taxonomy,
411
- index: articleCount
412
- };
413
- conditions = '';
414
-
415
- if (ctx && url) {
416
- cookies = dist_3(ctx);
417
- prevSlugs = cookies['prevSlugs'];
418
-
419
- if (!!prevSlugs) {
420
- dist_2(ctx, 'prevSlugs', prevSlugs + ',"' + url + '"', {});
421
- conditions = '&& !(url.current in [' + prevSlugs + '])';
422
- } else dist_2(ctx, 'prevSlugs', '"' + url + '"', {});
423
- }
424
- relatedArticleQuery = getQuery('related', conditions, '', articleCount);
425
- _context.next = 12;
426
- return client.fetch(relatedArticleQuery, params);
427
-
428
- case 12:
429
- relatedArticle = _context.sent;
430
- return _context.abrupt('return', relatedArticle);
431
-
432
- case 14:
433
- case 'end':
434
- return _context.stop();
435
- }
436
- }
437
- }, _callee, _this);
438
- }));
439
-
440
- return function getRelatedArticle() {
441
- return _ref2.apply(this, arguments);
442
- };
443
- }();
444
-
445
- exports.dist_2 = dist_2;
446
- exports.dist_3 = dist_3;
447
- exports.getRelatedArticle = getRelatedArticle;