From 9d4e6353d68581fb9d5f397a9095f7d9b70b4186 Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Tue, 14 Mar 2023 17:53:15 +0100 Subject: [PATCH 1/2] fix: using string for expiration time --- src/shared/config/config.service.ts | 6 +++--- src/subscriptions/subscriptions.controller.ts | 2 ++ src/subscriptions/subscriptions.service.ts | 14 ++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/shared/config/config.service.ts b/src/shared/config/config.service.ts index 0c3b184c..6f2a59e3 100644 --- a/src/shared/config/config.service.ts +++ b/src/shared/config/config.service.ts @@ -32,7 +32,7 @@ export interface ComputeConfig { export interface SubscriptionsConfig { jwtSecret: Uint8Array neverminedProxyUri: string - defaultExpiryTime: number + defaultExpiryTime: string averageBlockTime: number } @@ -48,7 +48,7 @@ const DOTENV_SCHEMA = Joi.object({ .required() .error(new Error('JWT_SUBSCRIPTION_SECRET_KEY is required!')), // defaults to 2 years in seconds - SUBSCRIPTION_DEFAULT_EXPIRY_TIME: Joi.number().default(60 * 60 * 24 * 365 * 2), + SUBSCRIPTION_DEFAULT_EXPIRY_TIME: Joi.string().default('100 years'), // Used to calculate expiry time of subscriptions in milliseconds NETWORK_AVERAGE_BLOCK_TIME: Joi.number().default(2100), server: Joi.object({ @@ -158,7 +158,7 @@ export class ConfigService { .map((x) => parseInt(x)), ), neverminedProxyUri: this.get('NEVERMINED_PROXY_URI'), - defaultExpiryTime: this.get('SUBSCRIPTION_DEFAULT_EXPIRY_TIME'), + defaultExpiryTime: this.get('SUBSCRIPTION_DEFAULT_EXPIRY_TIME'), averageBlockTime: this.get('NETWORK_AVERAGE_BLOCK_TIME'), } } diff --git a/src/subscriptions/subscriptions.controller.ts b/src/subscriptions/subscriptions.controller.ts index 78b063ba..f4bb5595 100644 --- a/src/subscriptions/subscriptions.controller.ts +++ b/src/subscriptions/subscriptions.controller.ts @@ -2,6 +2,7 @@ import { Controller, ForbiddenException, Get, Param, Req } from '@nestjs/common' import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger' import { SubscriptionTokenDto } from './dto/token.dto' import { SubscriptionsService } from './subscriptions.service' +import { Logger } from '../shared/logger/logger.service' @ApiTags('Subscriptions') @Controller() @@ -44,6 +45,7 @@ export class SubscriptionsController { req.user.address, ) + Logger.debug(`Generating access token with expiration time: ${expiryTime}`) // get access token const accessToken = await this.subscriptionService.generateToken( did, diff --git a/src/subscriptions/subscriptions.service.ts b/src/subscriptions/subscriptions.service.ts index d668300d..c2194aae 100644 --- a/src/subscriptions/subscriptions.service.ts +++ b/src/subscriptions/subscriptions.service.ts @@ -22,7 +22,7 @@ export interface SubscriptionData { export class SubscriptionsService { private readonly jwtSecret: Uint8Array public readonly neverminedProxyUri: string - private readonly defaultExpiryTime: number + private readonly defaultExpiryTime: string private readonly averageBlockTime: number constructor(private nvmService: NeverminedService, private config: ConfigService) { @@ -123,7 +123,7 @@ export class SubscriptionsService { did: string, userAddress: string, endpoints: any, - expiryTime: number, + expiryTime: number | string, headers?: any, ): Promise { return await new jose.EncryptJWT({ @@ -139,15 +139,17 @@ export class SubscriptionsService { } /** - * Get the expiration time in seconds for a subscription + * Get the expiration time for a subscription. + * The expiration time is generated in string format using common abbreviations: + * `seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y` * * @param contractAddress - The NFT-721 contract address of the subscription * @param userAddress - The address of the user requesting a JWT token * * @throws {@link BadRequestException} - * @returns {@link Promise} The expiration time in seconds + * @returns {@link Promise} The expiration time */ - public async getExpirationTime(contractAddress: string, userAddress: string): Promise { + public async getExpirationTime(contractAddress: string, userAddress: string): Promise { // get subscription DDO const subscriptionDdo = await this.getSubscriptionDdo(contractAddress) // get duration @@ -180,7 +182,7 @@ export class SubscriptionsService { const currentDate = new Date() const expiryTime = Math.floor(currentDate.getTime() / 1000) + secondsLeft - return expiryTime + return `${expiryTime} secs` } /** From 631aff7b2891e0d9358d1631d838c795ecbab33b Mon Sep 17 00:00:00 2001 From: Aitor <1726644+aaitor@users.noreply.github.com> Date: Tue, 14 Mar 2023 17:53:41 +0100 Subject: [PATCH 2/2] build: bumping to v1.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 45619470..43c8ab9e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-ts", - "version": "1.1.1", + "version": "1.1.2", "description": "Nevermined Node", "main": "main.ts", "scripts": {