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