Skip to content

Commit

Permalink
BREAKING CHANGE: extends CookieOptions from js-cookie v3
Browse files Browse the repository at this point in the history
changelog

OKTA-461753
<<<Jenkins Check-In of Tested SHA: 20f5e69 for eng_productivity_ci_bot_okta@okta.com>>>
Artifact: okta-auth-js
Files changed count: 2
PR Link: "#1066"
  • Loading branch information
shuowu authored and jaredperreault-okta committed Jan 20, 2022
1 parent 5526ba9 commit 025b091
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- [#1062](https://github.com/okta/okta-auth-js/pull/1062)
- Authn method `introspect` is renamed to `introspectAuthn` (still callable as `tx.introspect`)
- `IdxFeature` enum is now defined as strings instead of numbers
- [#1066](https://github.com/okta/okta-auth-js/pull/1066) Extends type `CookieOptions` from `js-cookie` v3
- Uses enums for `CookieOptions.sameSite`
- Removes type `SetCookieOptions`

### Features

Expand Down
52 changes: 43 additions & 9 deletions lib/types/Cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,54 @@
* See the License for the specific language governing permissions and limitations under the License.
*/

export interface CookieOptions {
path?: string;
secure?: boolean;
sessionCookie?: boolean;
sameSite?: string | boolean;
expires?: Date;
// From @types/js-cookie@3.0.1
// https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/js-cookie
// TODO: remove and import from "js-cookie" once it's upgrade to v3
interface CookieAttributes {
/**
* Define when the cookie will be removed. Value can be a Number
* which will be interpreted as days from time of creation or a
* Date instance. If omitted, the cookie becomes a session cookie.
*/
expires?: number | Date | undefined;

/**
* Define the path where the cookie is available. Defaults to '/'
*/
path?: string | undefined;

/**
* Define the domain where the cookie is available. Defaults to
* the domain of the page where the cookie was created.
*/
domain?: string | undefined;

/**
* A Boolean indicating if the cookie transmission requires a
* secure protocol (https). Defaults to false.
*/
secure?: boolean | undefined;

/**
* Asserts that a cookie must not be sent with cross-origin requests,
* providing some protection against cross-site request forgery
* attacks (CSRF)
*/
sameSite?: 'strict' | 'Strict' | 'lax' | 'Lax' | 'none' | 'None' | undefined;

/**
* An attribute which will be serialized, conformably to RFC 6265
* section 5.2.
*/
[property: string]: any;
}

export interface SetCookieOptions extends CookieOptions {
path?: string;
export interface CookieOptions extends CookieAttributes{
sessionCookie?: boolean;
}

export interface Cookies {
set(name: string, value: string, expiresAt: string, options: SetCookieOptions): string;
set(name: string, value: string, expiresAt: string, options: CookieOptions): string;
get(name: string): string;
delete(name: string): string;
}

0 comments on commit 025b091

Please sign in to comment.