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

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