Skip to content

Commit

Permalink
feat: include js-ceramic and ceramic-one version in request creation …
Browse files Browse the repository at this point in the history
…metric
  • Loading branch information
stbrody committed Jun 20, 2024
1 parent 54454dd commit 2f08de6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/ancillary/anchor-request-params-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ import {
const carFactory = new CARFactory()
carFactory.codecs.add(DAG_JOSE)

export const RequestAnchorParamsV1 = sparse(
const RequestAnchorParamsV3 = sparse(
{
streamId: string.pipe(streamIdAsString),
cid: string.pipe(cidAsString),
timestamp: optional(date),
timestamp: date,
jsCeramicVersion: optional(string),
ceramicOneVersion: optional(string),
},
'RequestAnchorParamsV1'
'RequestAnchorParamsV3'
)

type RequestAnchorParamsV1 = TypeOf<typeof RequestAnchorParamsV1>
export type RequestAnchorParamsV3 = TypeOf<typeof RequestAnchorParamsV3>

const RequestAnchorParamsV2Root = strict({
streamId: uint8array.pipe(streamIdAsBytes),
Expand All @@ -56,12 +58,12 @@ export const RequestAnchorParamsV2 = sparse({

export type RequestAnchorParamsV2 = TypeOf<typeof RequestAnchorParamsV2>

export type RequestAnchorParams = RequestAnchorParamsV1 | RequestAnchorParamsV2
export type RequestAnchorParams = RequestAnchorParamsV3 | RequestAnchorParamsV2

/**
* Encode request params for logging purposes.
*/
export const RequestAnchorParamsCodec = union([RequestAnchorParamsV1, RequestAnchorParamsV2])
export const RequestAnchorParamsCodec = union([RequestAnchorParamsV3, RequestAnchorParamsV2])

export class AnchorRequestCarFileDecoder implements Decoder<Uint8Array, RequestAnchorParamsV2> {
readonly name = 'RequestAnchorParamsV2'
Expand Down Expand Up @@ -96,7 +98,7 @@ export class AnchorRequestParamsParser {
if (req.get('Content-Type') !== 'application/vnd.ipld.car') {
// Legacy requests
Metrics.count(METRIC_NAMES.CTRL_LEGACY_REQUESTED, 1)
return validate(RequestAnchorParamsV1, req.body)
return validate(RequestAnchorParamsV3, req.body)
} else {
// Next version of anchor requests, using the CAR file format
// TODO: CDB-2212 Store the car file somewhere for future reference/validation of signatures
Expand Down
8 changes: 7 additions & 1 deletion src/controllers/request-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
AnchorRequestParamsParser,
RequestAnchorParams,
RequestAnchorParamsCodec,
RequestAnchorParamsV3,
} from '../ancillary/anchor-request-params-parser.js'
import bodyParser from 'body-parser'
import { type RequestService, RequestDoesNotExistError } from '../services/request-service.js'
Expand Down Expand Up @@ -124,7 +125,12 @@ export class RequestController {

// request was newly created
if (body) {
Metrics.count(METRIC_NAMES.CTRL_NEW_ANCHOR_REQUEST, 1, { source: parseOrigin(req) })
const v3Params = requestParams as RequestAnchorParamsV3
Metrics.count(METRIC_NAMES.CTRL_NEW_ANCHOR_REQUEST, 1, {
source: parseOrigin(req),
jsCeramicVersion: v3Params.jsCeramicVersion,
ceramicOneVersion: v3Params.ceramicOneVersion,
})
return res.status(StatusCodes.CREATED).json(body)
}

Expand Down

0 comments on commit 2f08de6

Please sign in to comment.