Created
July 3, 2018 02:53
-
-
Save coolhome/0d16db16f07f03c51c69ce7341f64dea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { jarFromCookies } = require('insomnia-cookies'); | |
module.exports.templateTags = [ | |
{ | |
name: 'cookieJar', | |
displayName: 'CookieJar', | |
description: 'reference cookie value from cookie jar', | |
args: [ | |
{ | |
type: 'string', | |
displayName: "Cookie Domain" | |
}, | |
{ | |
type: 'string', | |
displayName: "Cookie Key" | |
} | |
], | |
async run(context, cookieDomain, cookieName) { | |
const { meta } = context; | |
if (!meta.requestId || !meta.workspaceId) { | |
return null; | |
} | |
const workspace = await context.util.models.workspace.getById( | |
meta.workspaceId | |
); | |
if (!workspace) { | |
throw new Error(`Workspace not found for ${meta.workspaceId}`); | |
} | |
const cookieJar = await context.util.models.cookieJar.getOrCreateForWorkspace( | |
workspace | |
); | |
const cookie = cookieJar.cookies.find(cookie => cookie.domain == cookieDomain && cookie.key == cookieName); | |
return cookie ? cookie.value : null; | |
} | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment