diff --git a/CHANGELOG.md b/CHANGELOG.md index a9875079..98b691d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features - support client certificates on OAuth2 Requests (#802) - update tough-cookie to remove punycode deprecation warning (#813) +- support $env intellij environment variables access (#811) ## [6.15.1] ( 2024-08-22) ### Features diff --git a/src/plugins/intellij/api/index.ts b/src/plugins/intellij/api/index.ts index 133579d6..5b200aaf 100644 --- a/src/plugins/intellij/api/index.ts +++ b/src/plugins/intellij/api/index.ts @@ -1,6 +1,7 @@ -export * from './stubs'; export * from './intellijCryptoSupport'; export * from './intellijHttpClient'; export * from './intellijHttpRequest'; export * from './intellijHttpResponse'; +export * from './intellijRandom'; export * from './intellijVariables'; +export * from './stubs'; diff --git a/src/plugins/intellij/api/intellijRandom.ts b/src/plugins/intellij/api/intellijRandom.ts new file mode 100644 index 00000000..16bfe035 --- /dev/null +++ b/src/plugins/intellij/api/intellijRandom.ts @@ -0,0 +1,30 @@ +import dayjs from 'dayjs'; +import { randomEmail, randomText } from '../../../utils'; +import { v4 } from 'uuid'; + +export class IntellijRandom { + alphabetic(length = 10) { + return randomText(length, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'); + } + numeric(length = 10) { + return randomText(length); + } + hexadecimal(length = 10) { + return randomText(length, '1234567890ABCDEF'); + } + get email() { + return randomEmail(); + } + float(from = 0, to = 100) { + return Math.random() * (to - from) + from; + } + integer(from = 0, to = 100) { + return Math.floor(Math.random() * (to - from) + from); + } + get uuid() { + return v4(); + } + date(date: Date = new Date(), format: string | undefined = undefined) { + return dayjs(date).format(format); + } +} diff --git a/src/plugins/intellij/intellijAction.ts b/src/plugins/intellij/intellijAction.ts index cb5dbe02..08314083 100644 --- a/src/plugins/intellij/intellijAction.ts +++ b/src/plugins/intellij/intellijAction.ts @@ -109,6 +109,8 @@ function initIntellijVariables(context: models.ProcessorContext): intellij.Intel const variables: intellij.IntellijJavascriptGlobal = { client: new intellij.IntellijHttpClient(context), crypto: new intellij.IntellijCryptoSupport(), + $random: new intellij.IntellijRandom(), + $env: process.env, }; if (context.request) { if (context.httpRegion.response) {