@alicloud/cookie
Advanced tools
Comparing version 1.6.0-alpha.2 to 1.6.0-beta.1
@@ -15,8 +15,10 @@ "use strict"; | ||
domain = _ref.domain, | ||
path = _ref.path; | ||
path = _ref.path, | ||
partitioned = _ref.partitioned; | ||
(0, _setCookie.default)(name, '', { | ||
domain: domain, | ||
path: path, | ||
days: -1 | ||
days: -1, | ||
partitioned: partitioned | ||
}); | ||
} |
@@ -8,5 +8,9 @@ "use strict"; | ||
exports.default = setCookie; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _deleteCookie = _interopRequireDefault(require("./delete-cookie")); | ||
var _getExpireDate = _interopRequireDefault(require("./get-expire-date")); | ||
var _getDomain = _interopRequireDefault(require("./get-domain")); | ||
var _shouldUseChips = _interopRequireDefault(require("./should-use-chips")); | ||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
/** | ||
@@ -33,3 +37,3 @@ * 设置 cookie,默认为时间为 180 天,设置 extra.days 为 0 可以保存为 session cookie | ||
*/ | ||
function setCookie(name, value) { | ||
function _setCookie(name, value) { | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
@@ -43,6 +47,8 @@ _ref$domain = _ref.domain, | ||
sameSite0 = _ref.sameSite, | ||
secure0 = _ref.secure; | ||
secure0 = _ref.secure, | ||
partitioned0 = _ref.partitioned; | ||
var parts = ["".concat(name, "=").concat(encodeURIComponent(value)), "domain=".concat(domain), "path=".concat(path), "expires=".concat((0, _getExpireDate.default)(days))]; | ||
var sameSite = sameSite0; | ||
var secure = secure0; | ||
var partitioned = partitioned0; | ||
@@ -60,6 +66,19 @@ // 自动 sameSite + secure | ||
} | ||
if ((0, _shouldUseChips.default)()) { | ||
if (partitioned === true) { | ||
parts.push('partitioned'); | ||
} | ||
document.cookie = parts.join('; '); | ||
} | ||
function setCookie(name, value) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// 在特定的条件下自动设定 Partitioned Cookie | ||
if ((0, _shouldUseChips.default)()) { | ||
// 先删除非 Partitioned 值,然后再设定 Partitioned 值 | ||
(0, _deleteCookie.default)(name); | ||
_setCookie(name, value, _objectSpread(_objectSpread({}, options), {}, { | ||
partitioned: true | ||
})); | ||
} else { | ||
_setCookie(name, value, options); | ||
} | ||
} |
@@ -9,8 +9,10 @@ import setCookie from './set-cookie'; | ||
domain = _ref.domain, | ||
path = _ref.path; | ||
path = _ref.path, | ||
partitioned = _ref.partitioned; | ||
setCookie(name, '', { | ||
domain: domain, | ||
path: path, | ||
days: -1 | ||
days: -1, | ||
partitioned: partitioned | ||
}); | ||
} |
@@ -0,1 +1,5 @@ | ||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } | ||
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } | ||
import deleteCookie from './delete-cookie'; | ||
import getExpireDate from './get-expire-date'; | ||
@@ -26,3 +30,3 @@ import getDomain from './get-domain'; | ||
*/ | ||
export default function setCookie(name, value) { | ||
function _setCookie(name, value) { | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
@@ -36,6 +40,8 @@ _ref$domain = _ref.domain, | ||
sameSite0 = _ref.sameSite, | ||
secure0 = _ref.secure; | ||
secure0 = _ref.secure, | ||
partitioned0 = _ref.partitioned; | ||
var parts = ["".concat(name, "=").concat(encodeURIComponent(value)), "domain=".concat(domain), "path=".concat(path), "expires=".concat(getExpireDate(days))]; | ||
var sameSite = sameSite0; | ||
var secure = secure0; | ||
var partitioned = partitioned0; | ||
@@ -53,6 +59,19 @@ // 自动 sameSite + secure | ||
} | ||
if (shouldUseChips()) { | ||
if (partitioned === true) { | ||
parts.push('partitioned'); | ||
} | ||
document.cookie = parts.join('; '); | ||
} | ||
export default function setCookie(name, value) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
// 在特定的条件下自动设定 Partitioned Cookie | ||
if (shouldUseChips()) { | ||
// 先删除非 Partitioned 值,然后再设定 Partitioned 值 | ||
deleteCookie(name); | ||
_setCookie(name, value, _objectSpread(_objectSpread({}, options), {}, { | ||
partitioned: true | ||
})); | ||
} else { | ||
_setCookie(name, value, options); | ||
} | ||
} |
@@ -11,2 +11,3 @@ export interface ICookieOptions { | ||
secure?: boolean; | ||
partitioned?: boolean; | ||
} | ||
@@ -13,0 +14,0 @@ export interface ICookieSetOptions extends ICookieOptions { |
@@ -5,2 +5,2 @@ import { ICookieDeleteOptions } from '../types'; | ||
*/ | ||
export default function deleteCookie(name: string, { domain, path }?: ICookieDeleteOptions): void; | ||
export default function deleteCookie(name: string, { domain, path, partitioned }?: ICookieDeleteOptions): void; |
import { ICookieSetOptions } from '../types'; | ||
/** | ||
* 设置 cookie,默认为时间为 180 天,设置 extra.days 为 0 可以保存为 session cookie | ||
* | ||
* HTTP 下,非 Iframe、Iframe 不跨域、Iframe 跨子域(跨全域都不行)成功的测试用例: | ||
* | ||
* | SameSite | Secure | Firefox | Chrome | Safari | | ||
* |--------------|-------------|---------|--------|--------| | ||
* | `undefined` | `undefined` | ✅ | ✅ | ✅ | | ||
* | Lax | `undefined` | ✅ | ✅ | ✅ | | ||
* | Strict | `undefined` | ✅ | ✅ | ✅ | | ||
* | ||
* HTTPS 下,非 Iframe、Iframe 不跨域、Iframe 跨子域、Iframe 跨全域(Safari 都不行)成功的测试用例: | ||
* | ||
* | SameSite | Secure | Firefox | Chrome | Safari | | ||
* |--------------|-------------|---------|--------|--------| | ||
* | None | `true` | ✅ | ✅ | ✅ | | ||
* | None | `false` | ✅ | ✅ | ✅ | | ||
* | ||
* 1. 若 HTTPS,则 `sameSite=None; secure=true` | ||
* 2. 若 HTTP,则 `SameSite` 和 `secure` 不设置 | ||
*/ | ||
export default function setCookie(name: string, value: string | number | boolean, { domain, path, days, sameSite: sameSite0, secure: secure0 }?: ICookieSetOptions): void; | ||
export default function setCookie(name: string, value: string | number | boolean, options?: ICookieSetOptions): void; |
{ | ||
"name": "@alicloud/cookie", | ||
"version": "1.6.0-alpha.2", | ||
"version": "1.6.0-beta.1", | ||
"description": "ConsoleBase Cookie", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36289
533