msw 2.12.3 → 2.12.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.
- package/lib/core/utils/cookieStore.js +2 -2
- package/lib/core/utils/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.mjs +2 -2
- package/lib/core/utils/cookieStore.mjs.map +1 -1
- package/lib/iife/index.js +2 -2
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/utils/cookieStore.ts +8 -2
|
@@ -48,7 +48,7 @@ class CookieStore {
|
|
|
48
48
|
this.persist();
|
|
49
49
|
}
|
|
50
50
|
getCookieStoreIndex() {
|
|
51
|
-
if (typeof localStorage === "undefined") {
|
|
51
|
+
if (typeof localStorage === "undefined" || typeof localStorage.getItem !== "function") {
|
|
52
52
|
return {};
|
|
53
53
|
}
|
|
54
54
|
const cookiesString = localStorage.getItem(this.#storageKey);
|
|
@@ -71,7 +71,7 @@ class CookieStore {
|
|
|
71
71
|
return cookies;
|
|
72
72
|
}
|
|
73
73
|
persist() {
|
|
74
|
-
if (typeof localStorage === "undefined") {
|
|
74
|
+
if (typeof localStorage === "undefined" || typeof localStorage.setItem !== "function") {
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
const data = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/cookieStore.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\nimport { invariant } from 'outvariant'\nimport {\n Cookie,\n CookieJar,\n MemoryCookieStore,\n type MemoryCookieStoreIndex,\n} from 'tough-cookie'\nimport { jsonParse } from './internal/jsonParse'\n\nclass CookieStore {\n #storageKey = '__msw-cookie-store__'\n #jar: CookieJar\n #memoryStore: MemoryCookieStore\n\n constructor() {\n if (!isNodeProcess()) {\n invariant(\n typeof localStorage !== 'undefined',\n 'Failed to create a CookieStore: `localStorage` is not available in this environment. This is likely an issue with your environment, which has been detected as browser (or browser-like) environment and must implement global browser APIs correctly.',\n )\n }\n\n this.#memoryStore = new MemoryCookieStore()\n this.#memoryStore.idx = this.getCookieStoreIndex()\n this.#jar = new CookieJar(this.#memoryStore)\n }\n\n public getCookies(url: string): Array<Cookie> {\n return this.#jar.getCookiesSync(url)\n }\n\n public async setCookie(cookieName: string, url: string): Promise<void> {\n await this.#jar.setCookie(cookieName, url)\n this.persist()\n }\n\n private getCookieStoreIndex(): MemoryCookieStoreIndex {\n if (typeof localStorage === 'undefined') {\n return {}\n }\n\n const cookiesString = localStorage.getItem(this.#storageKey)\n if (cookiesString == null) {\n return {}\n }\n\n const rawCookies = jsonParse<Array<Record<string, unknown>>>(cookiesString)\n if (rawCookies == null) {\n return {}\n }\n\n const cookies: MemoryCookieStoreIndex = {}\n\n for (const rawCookie of rawCookies) {\n const cookie = Cookie.fromJSON(rawCookie)\n\n if (cookie != null && cookie.domain != null && cookie.path != null) {\n cookies[cookie.domain] ||= {}\n cookies[cookie.domain][cookie.path] ||= {}\n cookies[cookie.domain][cookie.path][cookie.key] = cookie\n }\n }\n\n return cookies\n }\n\n private persist(): void {\n if (typeof localStorage === 'undefined') {\n return\n }\n\n const data = []\n const { idx } = this.#memoryStore\n\n for (const domain in idx) {\n for (const path in idx[domain]) {\n for (const key in idx[domain][path]) {\n data.push(idx[domain][path][key].toJSON())\n }\n }\n }\n\n localStorage.setItem(this.#storageKey, JSON.stringify(data))\n }\n}\n\nexport const cookieStore = new CookieStore()\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA8B;AAC9B,wBAA0B;AAC1B,0BAKO;AACP,uBAA0B;AAE1B,MAAM,YAAY;AAAA,EAChB,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EAEA,cAAc;AACZ,QAAI,KAAC,sCAAc,GAAG;AACpB;AAAA,QACE,OAAO,iBAAiB;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAEA,SAAK,eAAe,IAAI,sCAAkB;AAC1C,SAAK,aAAa,MAAM,KAAK,oBAAoB;AACjD,SAAK,OAAO,IAAI,8BAAU,KAAK,YAAY;AAAA,EAC7C;AAAA,EAEO,WAAW,KAA4B;AAC5C,WAAO,KAAK,KAAK,eAAe,GAAG;AAAA,EACrC;AAAA,EAEA,MAAa,UAAU,YAAoB,KAA4B;AACrE,UAAM,KAAK,KAAK,UAAU,YAAY,GAAG;AACzC,SAAK,QAAQ;AAAA,EACf;AAAA,EAEQ,sBAA8C;AACpD,
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/cookieStore.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\nimport { invariant } from 'outvariant'\nimport {\n Cookie,\n CookieJar,\n MemoryCookieStore,\n type MemoryCookieStoreIndex,\n} from 'tough-cookie'\nimport { jsonParse } from './internal/jsonParse'\n\nclass CookieStore {\n #storageKey = '__msw-cookie-store__'\n #jar: CookieJar\n #memoryStore: MemoryCookieStore\n\n constructor() {\n if (!isNodeProcess()) {\n invariant(\n typeof localStorage !== 'undefined',\n 'Failed to create a CookieStore: `localStorage` is not available in this environment. This is likely an issue with your environment, which has been detected as browser (or browser-like) environment and must implement global browser APIs correctly.',\n )\n }\n\n this.#memoryStore = new MemoryCookieStore()\n this.#memoryStore.idx = this.getCookieStoreIndex()\n this.#jar = new CookieJar(this.#memoryStore)\n }\n\n public getCookies(url: string): Array<Cookie> {\n return this.#jar.getCookiesSync(url)\n }\n\n public async setCookie(cookieName: string, url: string): Promise<void> {\n await this.#jar.setCookie(cookieName, url)\n this.persist()\n }\n\n private getCookieStoreIndex(): MemoryCookieStoreIndex {\n if (\n typeof localStorage === 'undefined' ||\n typeof localStorage.getItem !== 'function'\n ) {\n return {}\n }\n\n const cookiesString = localStorage.getItem(this.#storageKey)\n if (cookiesString == null) {\n return {}\n }\n\n const rawCookies = jsonParse<Array<Record<string, unknown>>>(cookiesString)\n if (rawCookies == null) {\n return {}\n }\n\n const cookies: MemoryCookieStoreIndex = {}\n\n for (const rawCookie of rawCookies) {\n const cookie = Cookie.fromJSON(rawCookie)\n\n if (cookie != null && cookie.domain != null && cookie.path != null) {\n cookies[cookie.domain] ||= {}\n cookies[cookie.domain][cookie.path] ||= {}\n cookies[cookie.domain][cookie.path][cookie.key] = cookie\n }\n }\n\n return cookies\n }\n\n private persist(): void {\n if (\n typeof localStorage === 'undefined' ||\n typeof localStorage.setItem !== 'function'\n ) {\n return\n }\n\n const data = []\n const { idx } = this.#memoryStore\n\n for (const domain in idx) {\n for (const path in idx[domain]) {\n for (const key in idx[domain][path]) {\n data.push(idx[domain][path][key].toJSON())\n }\n }\n }\n\n localStorage.setItem(this.#storageKey, JSON.stringify(data))\n }\n}\n\nexport const cookieStore = new CookieStore()\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BAA8B;AAC9B,wBAA0B;AAC1B,0BAKO;AACP,uBAA0B;AAE1B,MAAM,YAAY;AAAA,EAChB,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EAEA,cAAc;AACZ,QAAI,KAAC,sCAAc,GAAG;AACpB;AAAA,QACE,OAAO,iBAAiB;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAEA,SAAK,eAAe,IAAI,sCAAkB;AAC1C,SAAK,aAAa,MAAM,KAAK,oBAAoB;AACjD,SAAK,OAAO,IAAI,8BAAU,KAAK,YAAY;AAAA,EAC7C;AAAA,EAEO,WAAW,KAA4B;AAC5C,WAAO,KAAK,KAAK,eAAe,GAAG;AAAA,EACrC;AAAA,EAEA,MAAa,UAAU,YAAoB,KAA4B;AACrE,UAAM,KAAK,KAAK,UAAU,YAAY,GAAG;AACzC,SAAK,QAAQ;AAAA,EACf;AAAA,EAEQ,sBAA8C;AACpD,QACE,OAAO,iBAAiB,eACxB,OAAO,aAAa,YAAY,YAChC;AACA,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,gBAAgB,aAAa,QAAQ,KAAK,WAAW;AAC3D,QAAI,iBAAiB,MAAM;AACzB,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,iBAAa,4BAA0C,aAAa;AAC1E,QAAI,cAAc,MAAM;AACtB,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,UAAkC,CAAC;AAEzC,eAAW,aAAa,YAAY;AAClC,YAAM,SAAS,2BAAO,SAAS,SAAS;AAExC,UAAI,UAAU,QAAQ,OAAO,UAAU,QAAQ,OAAO,QAAQ,MAAM;AAClE,gBAAQ,OAAO,MAAM,MAAM,CAAC;AAC5B,gBAAQ,OAAO,MAAM,EAAE,OAAO,IAAI,MAAM,CAAC;AACzC,gBAAQ,OAAO,MAAM,EAAE,OAAO,IAAI,EAAE,OAAO,GAAG,IAAI;AAAA,MACpD;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,UAAgB;AACtB,QACE,OAAO,iBAAiB,eACxB,OAAO,aAAa,YAAY,YAChC;AACA;AAAA,IACF;AAEA,UAAM,OAAO,CAAC;AACd,UAAM,EAAE,IAAI,IAAI,KAAK;AAErB,eAAW,UAAU,KAAK;AACxB,iBAAW,QAAQ,IAAI,MAAM,GAAG;AAC9B,mBAAW,OAAO,IAAI,MAAM,EAAE,IAAI,GAAG;AACnC,eAAK,KAAK,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC;AAAA,QAC3C;AAAA,MACF;AAAA,IACF;AAEA,iBAAa,QAAQ,KAAK,aAAa,KAAK,UAAU,IAAI,CAAC;AAAA,EAC7D;AACF;AAEO,MAAM,cAAc,IAAI,YAAY;","names":[]}
|
|
@@ -29,7 +29,7 @@ class CookieStore {
|
|
|
29
29
|
this.persist();
|
|
30
30
|
}
|
|
31
31
|
getCookieStoreIndex() {
|
|
32
|
-
if (typeof localStorage === "undefined") {
|
|
32
|
+
if (typeof localStorage === "undefined" || typeof localStorage.getItem !== "function") {
|
|
33
33
|
return {};
|
|
34
34
|
}
|
|
35
35
|
const cookiesString = localStorage.getItem(this.#storageKey);
|
|
@@ -52,7 +52,7 @@ class CookieStore {
|
|
|
52
52
|
return cookies;
|
|
53
53
|
}
|
|
54
54
|
persist() {
|
|
55
|
-
if (typeof localStorage === "undefined") {
|
|
55
|
+
if (typeof localStorage === "undefined" || typeof localStorage.setItem !== "function") {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
const data = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/core/utils/cookieStore.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\nimport { invariant } from 'outvariant'\nimport {\n Cookie,\n CookieJar,\n MemoryCookieStore,\n type MemoryCookieStoreIndex,\n} from 'tough-cookie'\nimport { jsonParse } from './internal/jsonParse'\n\nclass CookieStore {\n #storageKey = '__msw-cookie-store__'\n #jar: CookieJar\n #memoryStore: MemoryCookieStore\n\n constructor() {\n if (!isNodeProcess()) {\n invariant(\n typeof localStorage !== 'undefined',\n 'Failed to create a CookieStore: `localStorage` is not available in this environment. This is likely an issue with your environment, which has been detected as browser (or browser-like) environment and must implement global browser APIs correctly.',\n )\n }\n\n this.#memoryStore = new MemoryCookieStore()\n this.#memoryStore.idx = this.getCookieStoreIndex()\n this.#jar = new CookieJar(this.#memoryStore)\n }\n\n public getCookies(url: string): Array<Cookie> {\n return this.#jar.getCookiesSync(url)\n }\n\n public async setCookie(cookieName: string, url: string): Promise<void> {\n await this.#jar.setCookie(cookieName, url)\n this.persist()\n }\n\n private getCookieStoreIndex(): MemoryCookieStoreIndex {\n if (typeof localStorage === 'undefined') {\n return {}\n }\n\n const cookiesString = localStorage.getItem(this.#storageKey)\n if (cookiesString == null) {\n return {}\n }\n\n const rawCookies = jsonParse<Array<Record<string, unknown>>>(cookiesString)\n if (rawCookies == null) {\n return {}\n }\n\n const cookies: MemoryCookieStoreIndex = {}\n\n for (const rawCookie of rawCookies) {\n const cookie = Cookie.fromJSON(rawCookie)\n\n if (cookie != null && cookie.domain != null && cookie.path != null) {\n cookies[cookie.domain] ||= {}\n cookies[cookie.domain][cookie.path] ||= {}\n cookies[cookie.domain][cookie.path][cookie.key] = cookie\n }\n }\n\n return cookies\n }\n\n private persist(): void {\n if (typeof localStorage === 'undefined') {\n return\n }\n\n const data = []\n const { idx } = this.#memoryStore\n\n for (const domain in idx) {\n for (const path in idx[domain]) {\n for (const key in idx[domain][path]) {\n data.push(idx[domain][path][key].toJSON())\n }\n }\n }\n\n localStorage.setItem(this.#storageKey, JSON.stringify(data))\n }\n}\n\nexport const cookieStore = new CookieStore()\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iBAAiB;AAE1B,MAAM,YAAY;AAAA,EAChB,cAAc;AAAA,EACd;AAAA,EACA;AAAA,EAEA,cAAc;AACZ,QAAI,CAAC,cAAc,GAAG;AACpB;AAAA,QACE,OAAO,iBAAiB;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAEA,SAAK,eAAe,IAAI,kBAAkB;AAC1C,SAAK,aAAa,MAAM,KAAK,oBAAoB;AACjD,SAAK,OAAO,IAAI,UAAU,KAAK,YAAY;AAAA,EAC7C;AAAA,EAEO,WAAW,KAA4B;AAC5C,WAAO,KAAK,KAAK,eAAe,GAAG;AAAA,EACrC;AAAA,EAEA,MAAa,UAAU,YAAoB,KAA4B;AACrE,UAAM,KAAK,KAAK,UAAU,YAAY,GAAG;AACzC,SAAK,QAAQ;AAAA,EACf;AAAA,EAEQ,sBAA8C;AACpD,
|
|
1
|
+
{"version":3,"sources":["../../../src/core/utils/cookieStore.ts"],"sourcesContent":["import { isNodeProcess } from 'is-node-process'\nimport { invariant } from 'outvariant'\nimport {\n Cookie,\n CookieJar,\n MemoryCookieStore,\n type MemoryCookieStoreIndex,\n} from 'tough-cookie'\nimport { jsonParse } from './internal/jsonParse'\n\nclass CookieStore {\n #storageKey = '__msw-cookie-store__'\n #jar: CookieJar\n #memoryStore: MemoryCookieStore\n\n constructor() {\n if (!isNodeProcess()) {\n invariant(\n typeof localStorage !== 'undefined',\n 'Failed to create a CookieStore: `localStorage` is not available in this environment. This is likely an issue with your environment, which has been detected as browser (or browser-like) environment and must implement global browser APIs correctly.',\n )\n }\n\n this.#memoryStore = new MemoryCookieStore()\n this.#memoryStore.idx = this.getCookieStoreIndex()\n this.#jar = new CookieJar(this.#memoryStore)\n }\n\n public getCookies(url: string): Array<Cookie> {\n return this.#jar.getCookiesSync(url)\n }\n\n public async setCookie(cookieName: string, url: string): Promise<void> {\n await this.#jar.setCookie(cookieName, url)\n this.persist()\n }\n\n private getCookieStoreIndex(): MemoryCookieStoreIndex {\n if (\n typeof localStorage === 'undefined' ||\n typeof localStorage.getItem !== 'function'\n ) {\n return {}\n }\n\n const cookiesString = localStorage.getItem(this.#storageKey)\n if (cookiesString == null) {\n return {}\n }\n\n const rawCookies = jsonParse<Array<Record<string, unknown>>>(cookiesString)\n if (rawCookies == null) {\n return {}\n }\n\n const cookies: MemoryCookieStoreIndex = {}\n\n for (const rawCookie of rawCookies) {\n const cookie = Cookie.fromJSON(rawCookie)\n\n if (cookie != null && cookie.domain != null && cookie.path != null) {\n cookies[cookie.domain] ||= {}\n cookies[cookie.domain][cookie.path] ||= {}\n cookies[cookie.domain][cookie.path][cookie.key] = cookie\n }\n }\n\n return cookies\n }\n\n private persist(): void {\n if (\n typeof localStorage === 'undefined' ||\n typeof localStorage.setItem !== 'function'\n ) {\n return\n }\n\n const data = []\n const { idx } = this.#memoryStore\n\n for (const domain in idx) {\n for (const path in idx[domain]) {\n for (const key in idx[domain][path]) {\n data.push(idx[domain][path][key].toJSON())\n }\n }\n }\n\n localStorage.setItem(this.#storageKey, JSON.stringify(data))\n }\n}\n\nexport const cookieStore = new CookieStore()\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,iBAAiB;AAE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UAAM,OAAO,CAAC;AACd,UAAM,EAAE,IAAI,IAAI,KAAK;AAErB,eAAW,UAAU,KAAK;AACxB,iBAAW,QAAQ,IAAI,MAAM,GAAG;AAC9B,mBAAW,OAAO,IAAI,MAAM,EAAE,IAAI,GAAG;AACnC,eAAK,KAAK,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC;AAAA,QAC3C;AAAA,MACF;AAAA,IACF;AAEA,iBAAa,QAAQ,KAAK,aAAa,KAAK,UAAU,IAAI,CAAC;AAAA,EAC7D;AACF;AAEO,MAAM,cAAc,IAAI,YAAY;","names":[]}
|
package/lib/iife/index.js
CHANGED
|
@@ -18505,7 +18505,7 @@ ${operationTypes.join("\n")}
|
|
|
18505
18505
|
this.persist();
|
|
18506
18506
|
}
|
|
18507
18507
|
getCookieStoreIndex() {
|
|
18508
|
-
if (typeof localStorage === "undefined") {
|
|
18508
|
+
if (typeof localStorage === "undefined" || typeof localStorage.getItem !== "function") {
|
|
18509
18509
|
return {};
|
|
18510
18510
|
}
|
|
18511
18511
|
const cookiesString = localStorage.getItem(this.#storageKey);
|
|
@@ -18528,7 +18528,7 @@ ${operationTypes.join("\n")}
|
|
|
18528
18528
|
return cookies;
|
|
18529
18529
|
}
|
|
18530
18530
|
persist() {
|
|
18531
|
-
if (typeof localStorage === "undefined") {
|
|
18531
|
+
if (typeof localStorage === "undefined" || typeof localStorage.setItem !== "function") {
|
|
18532
18532
|
return;
|
|
18533
18533
|
}
|
|
18534
18534
|
const data = [];
|