Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: 0.6.0 #171

Merged
merged 8 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ DD_VERSION= # (Optional) Your service version, ex: 1.0.0

## NHP Trace Proxy Body

By default, Pong not trace any requests / responses's body because it might be interupting data flow in proxy.

To enable it, follow this step:
By default, Pong not trace any requests / responses's body because it might be interupting data flow in proxy. But if you can enable it by following this steps:

1. Enable in your `nuxt.config.ts`
```ts
Expand All @@ -77,7 +75,7 @@ export default defineNuxtConfig({
})
```

1. Replace import from `@privyid/nhp/core` to `@privyid/pong/nhp` in your `server.config.ts`
2. Replace import from `@privyid/nhp/core` to `@privyid/pong/nhp` in your `server.config.ts`

```diff
-import { defineServer } from '@privyid/nhp/core'
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@privyid/pong",
"version": "0.5.0",
"version": "0.6.0",
"packageManager": "[email protected]",
"description": "Service discovery, Log & Trace module",
"repository": {
Expand Down Expand Up @@ -31,7 +31,7 @@
"build": "nuxt-module-build build",
"dev": "nuxi dev playground | pino-pretty",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint . --ext .js,.vue,.ts --format pretty",
"fix": "yarn lint --fix",
Expand All @@ -40,26 +40,29 @@
},
"dependencies": {
"@fingerprintjs/fingerprintjs": "^4.0.0",
"@nuxt/kit": "^3.12.4",
"@nuxt/kit": "^3.13.2",
"body-parser": "^1.20.3",
"browserslist-ua-parser": "^1.0.1",
"dd-trace": "^5.0.0",
"defu": "^6.1.2",
"destr": "^2.0.1",
"fast-content-type-parse": "^2.0.0",
"fast-redact": "^3.5.0",
"pino-http": "^10.0.0",
"pino-std-serializers": "^7.0.0",
"uuid": "^10.0.0"
},
"devDependencies": {
"@nuxt/devtools": "1.4.2",
"@nuxt/devtools": "1.5.0",
"@nuxt/module-builder": "0.8.4",
"@nuxt/schema": "3.12.4",
"@nuxt/schema": "3.13.2",
"@nuxt/test-utils": "3.14.2",
"@privyid/eslint-config-persona": "0.27.0",
"@privyid/eslint-config-persona": "1.0.0-rc.12",
"@privyid/nhp": "1.0.1",
"@privyid/nuapi": "0.3.0-alpha.6",
"@types/body-parser": "1.19.5",
"@types/express": "4.17.21",
"@types/fast-redact": "^3",
"@types/simple-oauth2": "5.0.7",
"@types/uuid": "10.0.0",
"@typescript-eslint/eslint-plugin": "5.62.0",
Expand All @@ -76,13 +79,13 @@
"eslint-plugin-unicorn": "47.0.0",
"eslint-plugin-varspacing": "1.2.2",
"eslint-plugin-vue": "9.28.0",
"nuxt": "3.12.4",
"nuxt": "3.13.2",
"pino-pretty": "11.2.2",
"typescript": "5.6.2",
"vitest": "2.1.1"
},
"peerDependencies": {
"@privyid/nhp": "^1.0.0",
"@privyid/nhp": ">=1.0.0",
"@privyid/nuapi": ">=0.3.0-alpha.5"
},
"peerDependenciesMeta": {
Expand Down
4 changes: 2 additions & 2 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const UUID_URL_REGEX = /\/[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}/gi

export const PRIVYID_URL_REGEX = /\/[a-z]{2,}\d{4,}/gi

export const ID_URL_REGEX = /\/\d+/gi
export const ID_URL_REGEX = /\/[\da-f]{4,}/gi

/**
* Replace ID or UUID in URL to "{id}""
Expand All @@ -15,7 +15,7 @@ export const ID_URL_REGEX = /\/\d+/gi
*/
export function replaceId (name: string) {
return name
.replaceAll(UUID_URL_REGEX, '/:id')
.replaceAll(UUID_URL_REGEX, '/:uuid')
.replaceAll(ID_URL_REGEX, '/:id')
.replaceAll(PRIVYID_URL_REGEX, '/:privy-id')
}
Expand Down
8 changes: 4 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface ModuleOptions {
bodyParser?: OptionsJson,
}

export interface ModulePrivateRuntimeConfig {
export interface ModuleRuntimeConfig {
pong: Required<ModuleOptions>,
}

Expand Down Expand Up @@ -92,7 +92,7 @@ export default defineNuxtModule<ModuleOptions>({
if (options.ping) {
addServerHandler({
route : '/ping',
handler: resolve('./runtime/pong'),
handler: resolve('./runtime/server/route/pong'),
})
}

Expand All @@ -110,10 +110,10 @@ export default defineNuxtModule<ModuleOptions>({
],
})

addServerPlugin(resolve('./runtime/logger'))
addServerPlugin(resolve('./runtime/server/plugins/pong'))
}

if (options.nuapi && hasNuxtModule('@privyid/nuapi'))
addPlugin(resolve('./runtime/nuapi'))
addPlugin(resolve('./runtime/plugins/nuapi'))
},
})
2 changes: 1 addition & 1 deletion src/runtime/nuapi.ts → src/runtime/plugins/nuapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { onRequest } from '@privyid/nuapi/core'
import { v4 as uuidv4 } from 'uuid'
import { env } from 'std-env'
import { isUUID } from '../core/utils'
import { isUUID } from '../../core/utils'

/**
* Waiting loading ref to false
Expand Down
11 changes: 4 additions & 7 deletions src/runtime/logger.ts → src/runtime/server/plugins/pong.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { useRuntimeConfig } from '#imports'
import type { NitroAppPlugin } from 'nitropack'
import { useLogger } from '../core/logger'
import { useLogger } from '../../../core/logger'
import { fromNodeMiddleware } from 'h3'
import bodyParser from 'body-parser'

function defineNitroPlugin (def: NitroAppPlugin) {
return def
}

export default defineNitroPlugin((nitroApp) => {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
export default <NitroAppPlugin> function (nitroApp) {
const config = useRuntimeConfig()

if (config.pong.tracer && config.pong.traceReqBody)
nitroApp.hooks.hook('request', fromNodeMiddleware(bodyParser.json(config.pong.bodyParser)))

if (config.pong.logger)
nitroApp.hooks.hook('request', fromNodeMiddleware(useLogger()))
})
}
File renamed without changes.
Loading