@remnawave/backend-contract 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/controllers/users.ts +2 -1
 - package/api/routes.ts +1 -0
 - package/build/api/controllers/users.js +2 -1
 - package/build/api/routes.js +1 -0
 - package/build/commands/users/index.js +1 -0
 - package/build/commands/users/update-user.command.js +58 -0
 - package/build/constants/errors/errors.js +5 -0
 - package/commands/users/index.ts +1 -0
 - package/commands/users/update-user.command.ts +64 -0
 - package/constants/errors/errors.ts +5 -0
 - package/package.json +1 -1
 
    
        package/api/controllers/users.ts
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ export const USERS_CONTROLLER = 'users' as const; 
     | 
|
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            export const USERS_ROUTES = {
         
     | 
| 
       4 
4 
     | 
    
         
             
                CREATE: '',
         
     | 
| 
       5 
     | 
    
         
            -
                GET_BY_UUID: ' 
     | 
| 
      
 5 
     | 
    
         
            +
                GET_BY_UUID: '',
         
     | 
| 
       6 
6 
     | 
    
         
             
                GET_BY_SHORT_UUID: 'short-uuid/:shortUuid',
         
     | 
| 
       7 
7 
     | 
    
         
             
                GET_BY_SUBSCRIPTION_UUID: 'sub-uuid/:subscriptionUuid',
         
     | 
| 
       8 
8 
     | 
    
         
             
                GET_ALL: '',
         
     | 
| 
         @@ -10,4 +10,5 @@ export const USERS_ROUTES = { 
     | 
|
| 
       10 
10 
     | 
    
         
             
                DISABLE_USER: '/disable/:uuid',
         
     | 
| 
       11 
11 
     | 
    
         
             
                ENABLE_USER: '/enable/:uuid',
         
     | 
| 
       12 
12 
     | 
    
         
             
                DELETE_USER: '/delete/:uuid',
         
     | 
| 
      
 13 
     | 
    
         
            +
                UPDATE: '/update',
         
     | 
| 
       13 
14 
     | 
    
         
             
            } as const;
         
     | 
    
        package/api/routes.ts
    CHANGED
    
    | 
         @@ -55,6 +55,7 @@ export const REST_API = { 
     | 
|
| 
       55 
55 
     | 
    
         
             
                        `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.ENABLE_USER}/${uuid}`,
         
     | 
| 
       56 
56 
     | 
    
         
             
                    DELETE_USER: (uuid: string) =>
         
     | 
| 
       57 
57 
     | 
    
         
             
                        `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.DELETE_USER}/${uuid}`,
         
     | 
| 
      
 58 
     | 
    
         
            +
                    UPDATE: `${ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.UPDATE}`,
         
     | 
| 
       58 
59 
     | 
    
         
             
                },
         
     | 
| 
       59 
60 
     | 
    
         
             
                SUBSCRIPTION: {
         
     | 
| 
       60 
61 
     | 
    
         
             
                    GET: (shortUuid: string) =>
         
     | 
| 
         @@ -4,7 +4,7 @@ exports.USERS_ROUTES = exports.USERS_CONTROLLER = void 0; 
     | 
|
| 
       4 
4 
     | 
    
         
             
            exports.USERS_CONTROLLER = 'users';
         
     | 
| 
       5 
5 
     | 
    
         
             
            exports.USERS_ROUTES = {
         
     | 
| 
       6 
6 
     | 
    
         
             
                CREATE: '',
         
     | 
| 
       7 
     | 
    
         
            -
                GET_BY_UUID: ' 
     | 
| 
      
 7 
     | 
    
         
            +
                GET_BY_UUID: '',
         
     | 
| 
       8 
8 
     | 
    
         
             
                GET_BY_SHORT_UUID: 'short-uuid/:shortUuid',
         
     | 
| 
       9 
9 
     | 
    
         
             
                GET_BY_SUBSCRIPTION_UUID: 'sub-uuid/:subscriptionUuid',
         
     | 
| 
       10 
10 
     | 
    
         
             
                GET_ALL: '',
         
     | 
| 
         @@ -12,4 +12,5 @@ exports.USERS_ROUTES = { 
     | 
|
| 
       12 
12 
     | 
    
         
             
                DISABLE_USER: '/disable/:uuid',
         
     | 
| 
       13 
13 
     | 
    
         
             
                ENABLE_USER: '/enable/:uuid',
         
     | 
| 
       14 
14 
     | 
    
         
             
                DELETE_USER: '/delete/:uuid',
         
     | 
| 
      
 15 
     | 
    
         
            +
                UPDATE: '/update',
         
     | 
| 
       15 
16 
     | 
    
         
             
            };
         
     | 
    
        package/build/api/routes.js
    CHANGED
    
    | 
         @@ -76,6 +76,7 @@ exports.REST_API = { 
     | 
|
| 
       76 
76 
     | 
    
         
             
                    DISABLE_USER: (uuid) => `${exports.ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.DISABLE_USER}/${uuid}`,
         
     | 
| 
       77 
77 
     | 
    
         
             
                    ENABLE_USER: (uuid) => `${exports.ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.ENABLE_USER}/${uuid}`,
         
     | 
| 
       78 
78 
     | 
    
         
             
                    DELETE_USER: (uuid) => `${exports.ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.DELETE_USER}/${uuid}`,
         
     | 
| 
      
 79 
     | 
    
         
            +
                    UPDATE: `${exports.ROOT}/${CONTROLLERS.USERS_CONTROLLER}/${CONTROLLERS.USERS_ROUTES.UPDATE}`,
         
     | 
| 
       79 
80 
     | 
    
         
             
                },
         
     | 
| 
       80 
81 
     | 
    
         
             
                SUBSCRIPTION: {
         
     | 
| 
       81 
82 
     | 
    
         
             
                    GET: (shortUuid) => `${exports.ROOT}/${CONTROLLERS.SUBSCRIPTION_CONTROLLER}/${CONTROLLERS.SUBSCRIPTION_ROUTES.GET}/${shortUuid}`,
         
     | 
| 
         @@ -23,3 +23,4 @@ __exportStar(require("./get-user-by-short-uuid.command"), exports); 
     | 
|
| 
       23 
23 
     | 
    
         
             
            __exportStar(require("./get-user-by-subscription-uuid.command"), exports);
         
     | 
| 
       24 
24 
     | 
    
         
             
            __exportStar(require("./get-user-by-uuid.command"), exports);
         
     | 
| 
       25 
25 
     | 
    
         
             
            __exportStar(require("./revoke-user-subscription.command"), exports);
         
     | 
| 
      
 26 
     | 
    
         
            +
            __exportStar(require("./update-user.command"), exports);
         
     | 
| 
         @@ -0,0 +1,58 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            "use strict";
         
     | 
| 
      
 2 
     | 
    
         
            +
            Object.defineProperty(exports, "__esModule", { value: true });
         
     | 
| 
      
 3 
     | 
    
         
            +
            exports.UpdateUserCommand = void 0;
         
     | 
| 
      
 4 
     | 
    
         
            +
            const zod_1 = require("zod");
         
     | 
| 
      
 5 
     | 
    
         
            +
            const api_1 = require("../../api");
         
     | 
| 
      
 6 
     | 
    
         
            +
            const constants_1 = require("../../constants");
         
     | 
| 
      
 7 
     | 
    
         
            +
            const models_1 = require("../../models");
         
     | 
| 
      
 8 
     | 
    
         
            +
            var UpdateUserCommand;
         
     | 
| 
      
 9 
     | 
    
         
            +
            (function (UpdateUserCommand) {
         
     | 
| 
      
 10 
     | 
    
         
            +
                UpdateUserCommand.url = api_1.REST_API.USERS.UPDATE;
         
     | 
| 
      
 11 
     | 
    
         
            +
                UpdateUserCommand.RequestSchema = models_1.UsersSchema.pick({
         
     | 
| 
      
 12 
     | 
    
         
            +
                    uuid: true,
         
     | 
| 
      
 13 
     | 
    
         
            +
                }).extend({
         
     | 
| 
      
 14 
     | 
    
         
            +
                    status: models_1.UsersSchema.shape.status.optional(),
         
     | 
| 
      
 15 
     | 
    
         
            +
                    trafficLimitBytes: zod_1.z
         
     | 
| 
      
 16 
     | 
    
         
            +
                        .number({
         
     | 
| 
      
 17 
     | 
    
         
            +
                        invalid_type_error: 'Traffic limit must be a number',
         
     | 
| 
      
 18 
     | 
    
         
            +
                    })
         
     | 
| 
      
 19 
     | 
    
         
            +
                        .int('Traffic limit must be an integer')
         
     | 
| 
      
 20 
     | 
    
         
            +
                        .min(0, 'Traffic limit must be greater than 0')
         
     | 
| 
      
 21 
     | 
    
         
            +
                        .describe('Traffic limit in bytes. 0 - unlimited')
         
     | 
| 
      
 22 
     | 
    
         
            +
                        .optional(),
         
     | 
| 
      
 23 
     | 
    
         
            +
                    trafficLimitStrategy: models_1.UsersSchema.shape.trafficLimitStrategy
         
     | 
| 
      
 24 
     | 
    
         
            +
                        .describe('Traffic limit reset strategy')
         
     | 
| 
      
 25 
     | 
    
         
            +
                        .optional()
         
     | 
| 
      
 26 
     | 
    
         
            +
                        .default(constants_1.RESET_PERIODS.NO_RESET)
         
     | 
| 
      
 27 
     | 
    
         
            +
                        .superRefine((val, ctx) => {
         
     | 
| 
      
 28 
     | 
    
         
            +
                        if (val && !Object.values(constants_1.RESET_PERIODS).includes(val)) {
         
     | 
| 
      
 29 
     | 
    
         
            +
                            ctx.addIssue({
         
     | 
| 
      
 30 
     | 
    
         
            +
                                code: zod_1.z.ZodIssueCode.invalid_enum_value,
         
     | 
| 
      
 31 
     | 
    
         
            +
                                message: 'Invalid traffic limit strategy',
         
     | 
| 
      
 32 
     | 
    
         
            +
                                path: ['trafficLimitStrategy'],
         
     | 
| 
      
 33 
     | 
    
         
            +
                                received: val,
         
     | 
| 
      
 34 
     | 
    
         
            +
                                options: Object.values(constants_1.RESET_PERIODS),
         
     | 
| 
      
 35 
     | 
    
         
            +
                            });
         
     | 
| 
      
 36 
     | 
    
         
            +
                        }
         
     | 
| 
      
 37 
     | 
    
         
            +
                    }),
         
     | 
| 
      
 38 
     | 
    
         
            +
                    enabledInbounds: zod_1.z
         
     | 
| 
      
 39 
     | 
    
         
            +
                        .array(models_1.InboundsSchema.pick({
         
     | 
| 
      
 40 
     | 
    
         
            +
                        uuid: true,
         
     | 
| 
      
 41 
     | 
    
         
            +
                    }), {
         
     | 
| 
      
 42 
     | 
    
         
            +
                        invalid_type_error: 'Enabled inbounds must be an array',
         
     | 
| 
      
 43 
     | 
    
         
            +
                    })
         
     | 
| 
      
 44 
     | 
    
         
            +
                        .optional(),
         
     | 
| 
      
 45 
     | 
    
         
            +
                    expireAt: zod_1.z.coerce
         
     | 
| 
      
 46 
     | 
    
         
            +
                        .date({
         
     | 
| 
      
 47 
     | 
    
         
            +
                        required_error: 'Expiration date is required',
         
     | 
| 
      
 48 
     | 
    
         
            +
                        invalid_type_error: 'Invalid expiration date format',
         
     | 
| 
      
 49 
     | 
    
         
            +
                    })
         
     | 
| 
      
 50 
     | 
    
         
            +
                        .refine((date) => date > new Date(), {
         
     | 
| 
      
 51 
     | 
    
         
            +
                        message: 'Expiration date cannot be in the past',
         
     | 
| 
      
 52 
     | 
    
         
            +
                    })
         
     | 
| 
      
 53 
     | 
    
         
            +
                        .optional(),
         
     | 
| 
      
 54 
     | 
    
         
            +
                });
         
     | 
| 
      
 55 
     | 
    
         
            +
                UpdateUserCommand.ResponseSchema = zod_1.z.object({
         
     | 
| 
      
 56 
     | 
    
         
            +
                    response: models_1.UsersSchema,
         
     | 
| 
      
 57 
     | 
    
         
            +
                });
         
     | 
| 
      
 58 
     | 
    
         
            +
            })(UpdateUserCommand || (exports.UpdateUserCommand = UpdateUserCommand = {}));
         
     | 
    
        package/commands/users/index.ts
    CHANGED
    
    
| 
         @@ -0,0 +1,64 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            import { z } from 'zod';
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { REST_API } from '../../api';
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { RESET_PERIODS } from '../../constants';
         
     | 
| 
      
 4 
     | 
    
         
            +
            import { InboundsSchema, UsersSchema } from '../../models';
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            export namespace UpdateUserCommand {
         
     | 
| 
      
 7 
     | 
    
         
            +
                export const url = REST_API.USERS.UPDATE;
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                export const RequestSchema = UsersSchema.pick({
         
     | 
| 
      
 10 
     | 
    
         
            +
                    uuid: true,
         
     | 
| 
      
 11 
     | 
    
         
            +
                }).extend({
         
     | 
| 
      
 12 
     | 
    
         
            +
                    status: UsersSchema.shape.status.optional(),
         
     | 
| 
      
 13 
     | 
    
         
            +
                    trafficLimitBytes: z
         
     | 
| 
      
 14 
     | 
    
         
            +
                        .number({
         
     | 
| 
      
 15 
     | 
    
         
            +
                            invalid_type_error: 'Traffic limit must be a number',
         
     | 
| 
      
 16 
     | 
    
         
            +
                        })
         
     | 
| 
      
 17 
     | 
    
         
            +
                        .int('Traffic limit must be an integer')
         
     | 
| 
      
 18 
     | 
    
         
            +
                        .min(0, 'Traffic limit must be greater than 0')
         
     | 
| 
      
 19 
     | 
    
         
            +
                        .describe('Traffic limit in bytes. 0 - unlimited')
         
     | 
| 
      
 20 
     | 
    
         
            +
                        .optional(),
         
     | 
| 
      
 21 
     | 
    
         
            +
                    trafficLimitStrategy: UsersSchema.shape.trafficLimitStrategy
         
     | 
| 
      
 22 
     | 
    
         
            +
                        .describe('Traffic limit reset strategy')
         
     | 
| 
      
 23 
     | 
    
         
            +
                        .optional()
         
     | 
| 
      
 24 
     | 
    
         
            +
                        .default(RESET_PERIODS.NO_RESET)
         
     | 
| 
      
 25 
     | 
    
         
            +
                        .superRefine((val, ctx) => {
         
     | 
| 
      
 26 
     | 
    
         
            +
                            if (val && !Object.values(RESET_PERIODS).includes(val)) {
         
     | 
| 
      
 27 
     | 
    
         
            +
                                ctx.addIssue({
         
     | 
| 
      
 28 
     | 
    
         
            +
                                    code: z.ZodIssueCode.invalid_enum_value,
         
     | 
| 
      
 29 
     | 
    
         
            +
                                    message: 'Invalid traffic limit strategy',
         
     | 
| 
      
 30 
     | 
    
         
            +
                                    path: ['trafficLimitStrategy'],
         
     | 
| 
      
 31 
     | 
    
         
            +
                                    received: val,
         
     | 
| 
      
 32 
     | 
    
         
            +
                                    options: Object.values(RESET_PERIODS),
         
     | 
| 
      
 33 
     | 
    
         
            +
                                });
         
     | 
| 
      
 34 
     | 
    
         
            +
                            }
         
     | 
| 
      
 35 
     | 
    
         
            +
                        }),
         
     | 
| 
      
 36 
     | 
    
         
            +
                    enabledInbounds: z
         
     | 
| 
      
 37 
     | 
    
         
            +
                        .array(
         
     | 
| 
      
 38 
     | 
    
         
            +
                            InboundsSchema.pick({
         
     | 
| 
      
 39 
     | 
    
         
            +
                                uuid: true,
         
     | 
| 
      
 40 
     | 
    
         
            +
                            }),
         
     | 
| 
      
 41 
     | 
    
         
            +
                            {
         
     | 
| 
      
 42 
     | 
    
         
            +
                                invalid_type_error: 'Enabled inbounds must be an array',
         
     | 
| 
      
 43 
     | 
    
         
            +
                            },
         
     | 
| 
      
 44 
     | 
    
         
            +
                        )
         
     | 
| 
      
 45 
     | 
    
         
            +
                        .optional(),
         
     | 
| 
      
 46 
     | 
    
         
            +
                    expireAt: z.coerce
         
     | 
| 
      
 47 
     | 
    
         
            +
                        .date({
         
     | 
| 
      
 48 
     | 
    
         
            +
                            required_error: 'Expiration date is required',
         
     | 
| 
      
 49 
     | 
    
         
            +
                            invalid_type_error: 'Invalid expiration date format',
         
     | 
| 
      
 50 
     | 
    
         
            +
                        })
         
     | 
| 
      
 51 
     | 
    
         
            +
                        .refine((date) => date > new Date(), {
         
     | 
| 
      
 52 
     | 
    
         
            +
                            message: 'Expiration date cannot be in the past',
         
     | 
| 
      
 53 
     | 
    
         
            +
                        })
         
     | 
| 
      
 54 
     | 
    
         
            +
                        .optional(),
         
     | 
| 
      
 55 
     | 
    
         
            +
                });
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                export type Request = z.infer<typeof RequestSchema>;
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
                export const ResponseSchema = z.object({
         
     | 
| 
      
 60 
     | 
    
         
            +
                    response: UsersSchema,
         
     | 
| 
      
 61 
     | 
    
         
            +
                });
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                export type Response = z.infer<typeof ResponseSchema>;
         
     | 
| 
      
 64 
     | 
    
         
            +
            }
         
     |