Browse Source

initial commit

develop
Dale 2 months ago
commit
5187d8e7a9
27 changed files with 355 additions and 0 deletions
  1. +3
    -0
      .gitignore
  2. +12
    -0
      package.json
  3. +57
    -0
      src/lib/const.js
  4. +52
    -0
      src/lib/const.ts
  5. +2
    -0
      src/types/api/v1/interfaces/IActivity.js
  6. +21
    -0
      src/types/api/v1/interfaces/IActivity.ts
  7. +2
    -0
      src/types/api/v1/interfaces/IChannel.js
  8. +17
    -0
      src/types/api/v1/interfaces/IChannel.ts
  9. +2
    -0
      src/types/api/v1/interfaces/ISession.js
  10. +11
    -0
      src/types/api/v1/interfaces/ISession.ts
  11. +2
    -0
      src/types/api/v1/interfaces/IStreamKey.js
  12. +10
    -0
      src/types/api/v1/interfaces/IStreamKey.ts
  13. +2
    -0
      src/types/api/v1/interfaces/IUser.js
  14. +26
    -0
      src/types/api/v1/interfaces/IUser.ts
  15. +9
    -0
      src/types/api/v1/schemas/activity/createActivity.json
  16. +9
    -0
      src/types/api/v1/schemas/auth/loginRequest.json
  17. +11
    -0
      src/types/api/v1/schemas/channel/createChannel.json
  18. +15
    -0
      src/types/api/v1/schemas/index.js
  19. +14
    -0
      src/types/api/v1/schemas/index.ts
  20. +9
    -0
      src/types/api/v1/schemas/streamkeys/createStreamkey.json
  21. +10
    -0
      src/types/api/v1/schemas/user/createUser.json
  22. +9
    -0
      src/types/api/v1/schemas/user/updateUser.json
  23. +2
    -0
      src/types/db/interfaces.js
  24. +8
    -0
      src/types/db/interfaces.ts
  25. +23
    -0
      tsconfig.json
  26. +9
    -0
      tslint.json
  27. +8
    -0
      yarn.lock

+ 3
- 0
.gitignore View File

@@ -0,0 +1,3 @@
dist/
node_modules/
.log/

+ 12
- 0
package.json View File

@@ -0,0 +1,12 @@
{
"dependencies": {
"typescript": "^3.9.7"
},
"name": "miracle-tv-shared",
"version": "0.1.0",
"main": "index.js",
"types": "dist/index.d.ts",
"author": "Dale <deiru2k@gmail.com>",
"license": "MIT",
"private": false
}

+ 57
- 0
src/lib/const.js View File

@@ -0,0 +1,57 @@
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
exports.__esModule = true;
exports.ROLE_LIST = exports.ROLE_LABEL_MAP = exports.ROLE_OPTIONS = exports.USER_ROLE = exports.MODERATOR_ROLE = exports.ADMIN_ROLE = exports.HTTP_CODES = exports.HTTP_CODE_NOT_IMPLEMENTED = exports.HTTP_CODE_DUPLICATE = exports.HTTP_CODE_SERVER_ERROR = exports.HTTP_CODE_NOT_FOUND = exports.HTTP_CODE_UNAUTHORIZED = exports.HTTP_CODE_UNAUTHENTICATED = exports.HTTP_CODE_BAD_REQUEST = exports.HTTP_CODE_NO_CONTENT = exports.HTTP_CODE_CREATED = exports.HTTP_CODE_OK = exports.ERROR_CODE_MIN_STRING = exports.ERROR_CODE_MAX_STRING = exports.ERROR_CODE_MIN_NUM = exports.ERROR_CODE_MAX_NUM = exports.ERROR_CODE_TYPE = exports.ERROR_CODE_EXTRA_PROPERTY = exports.ERROR_CODE_MISSING_PROPERTY = void 0;
exports.ERROR_CODE_MISSING_PROPERTY = 'errors.schema.field.missing';
exports.ERROR_CODE_EXTRA_PROPERTY = 'errors.schema.field.noExtra';
exports.ERROR_CODE_TYPE = 'errors.schema.field.type';
exports.ERROR_CODE_MAX_NUM = 'errors.schema.field.maximumNumber';
exports.ERROR_CODE_MIN_NUM = 'errors.schema.field.minimumNumber';
exports.ERROR_CODE_MAX_STRING = 'errors.schema.field.maximumStringLength';
exports.ERROR_CODE_MIN_STRING = 'errors.schema.field.minimumStringLength';
exports.HTTP_CODE_OK = 200;
exports.HTTP_CODE_CREATED = 201;
exports.HTTP_CODE_NO_CONTENT = 204;
exports.HTTP_CODE_BAD_REQUEST = 400;
exports.HTTP_CODE_UNAUTHENTICATED = 401;
exports.HTTP_CODE_UNAUTHORIZED = 403;
exports.HTTP_CODE_NOT_FOUND = 404;
exports.HTTP_CODE_SERVER_ERROR = 500;
exports.HTTP_CODE_DUPLICATE = 409;
exports.HTTP_CODE_NOT_IMPLEMENTED = 501;
exports.HTTP_CODES = {
OK: exports.HTTP_CODE_OK,
CREATED: exports.HTTP_CODE_CREATED,
NO_CONTENT: exports.HTTP_CODE_NO_CONTENT,
BAD_REQUEST: exports.HTTP_CODE_BAD_REQUEST,
UNAUTHENTICATED: exports.HTTP_CODE_UNAUTHENTICATED,
UNAUTHORIZED: exports.HTTP_CODE_UNAUTHORIZED,
NOT_FOUND: exports.HTTP_CODE_NOT_FOUND,
SERVER_ERROR: exports.HTTP_CODE_SERVER_ERROR,
DUPLICATE: exports.HTTP_CODE_DUPLICATE,
NOT_IMPLEMENTED: exports.HTTP_CODE_NOT_IMPLEMENTED
};
exports.ADMIN_ROLE = 'admin';
exports.MODERATOR_ROLE = 'mod';
exports.USER_ROLE = 'user';
exports.ROLE_OPTIONS = [
{ label: 'Admin', value: exports.ADMIN_ROLE },
{ label: 'Moderator', value: exports.MODERATOR_ROLE },
{ label: 'User', value: exports.USER_ROLE },
];
exports.ROLE_LABEL_MAP = exports.ROLE_OPTIONS
.reduce(function (acc, opt) {
var _a;
return (__assign(__assign({}, acc), (_a = {}, _a[opt.value] = opt.label, _a)));
}, {});
exports.ROLE_LIST = exports.ROLE_OPTIONS.map(function (opt) { return opt.value; });

+ 52
- 0
src/lib/const.ts View File

@@ -0,0 +1,52 @@
export const ERROR_CODE_MISSING_PROPERTY = 'errors.schema.field.missing';
export const ERROR_CODE_EXTRA_PROPERTY = 'errors.schema.field.noExtra';
export const ERROR_CODE_TYPE = 'errors.schema.field.type';
export const ERROR_CODE_MAX_NUM = 'errors.schema.field.maximumNumber';
export const ERROR_CODE_MIN_NUM = 'errors.schema.field.minimumNumber';
export const ERROR_CODE_MAX_STRING = 'errors.schema.field.maximumStringLength';
export const ERROR_CODE_MIN_STRING = 'errors.schema.field.minimumStringLength';

export const HTTP_CODE_OK = 200;
export const HTTP_CODE_CREATED = 201;
export const HTTP_CODE_NO_CONTENT = 204;
export const HTTP_CODE_BAD_REQUEST = 400;
export const HTTP_CODE_UNAUTHENTICATED = 401;
export const HTTP_CODE_UNAUTHORIZED = 403;
export const HTTP_CODE_NOT_FOUND = 404;
export const HTTP_CODE_SERVER_ERROR = 500;
export const HTTP_CODE_DUPLICATE = 409;
export const HTTP_CODE_NOT_IMPLEMENTED = 501;
export const HTTP_CODES = {
OK: HTTP_CODE_OK,
CREATED: HTTP_CODE_CREATED,
NO_CONTENT: HTTP_CODE_NO_CONTENT,
BAD_REQUEST: HTTP_CODE_BAD_REQUEST,
UNAUTHENTICATED: HTTP_CODE_UNAUTHENTICATED,
UNAUTHORIZED: HTTP_CODE_UNAUTHORIZED,
NOT_FOUND: HTTP_CODE_NOT_FOUND,
SERVER_ERROR: HTTP_CODE_SERVER_ERROR,
DUPLICATE: HTTP_CODE_DUPLICATE,
NOT_IMPLEMENTED: HTTP_CODE_NOT_IMPLEMENTED,
};

interface IRoleOption {
label: string;
value: string;
}

interface IRoleLabelMap {
[key: string]: string;
}

export const ADMIN_ROLE = 'admin';
export const MODERATOR_ROLE = 'mod';
export const USER_ROLE = 'user';
export const ROLE_OPTIONS: IRoleOption[] = [
{ label: 'Admin', value: ADMIN_ROLE },
{ label: 'Moderator', value: MODERATOR_ROLE },
{ label: 'User', value: USER_ROLE },
];

export const ROLE_LABEL_MAP: IRoleLabelMap = ROLE_OPTIONS
.reduce((acc: object, opt: IRoleOption) => ({ ...acc, [opt.value]: opt.label }), {});
export const ROLE_LIST: string[] = ROLE_OPTIONS.map(opt => opt.value);

+ 2
- 0
src/types/api/v1/interfaces/IActivity.js View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

+ 21
- 0
src/types/api/v1/interfaces/IActivity.ts View File

@@ -0,0 +1,21 @@
import { IUserSafe } from './IUser';
import { IWithTimestamps, IWithId } from 'shared/types/db/interfaces';

interface IActivityFields {
name: string;
verb: string;
created_by_id: string;
}

export interface IActivityRaw extends IWithTimestamps, IWithId, IActivityFields {}

interface IActivity extends IActivityRaw {
created_by: IUserSafe;
}

export interface IActivityForChannel extends IWithId {
name: string;
verb: string;
}

export default IActivity;

+ 2
- 0
src/types/api/v1/interfaces/IChannel.js View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

+ 17
- 0
src/types/api/v1/interfaces/IChannel.ts View File

@@ -0,0 +1,17 @@
import { IUserSafe } from 'shared/types/api/v1/interfaces/IUser';
import { IActivityForChannel } from './IActivity';

export interface IChannelRaw {
id?: string;
slug: string;
title: string;
description?: string;
created_by_id: string;
activity_id: string;
created_at?: Date;
updated_at?: Date;
}
export default interface IChannel extends IChannelRaw {
created_by: IUserSafe;
activity: IActivityForChannel;
}

+ 2
- 0
src/types/api/v1/interfaces/ISession.js View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

+ 11
- 0
src/types/api/v1/interfaces/ISession.ts View File

@@ -0,0 +1,11 @@
import IUser from 'shared/types/api/v1/interfaces/IUser';

export default interface ISession {
id?: string;
user: IUser;
}

export interface ISessionRaw {
id?: string;
user_id: string;
}

+ 2
- 0
src/types/api/v1/interfaces/IStreamKey.js View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

+ 10
- 0
src/types/api/v1/interfaces/IStreamKey.ts View File

@@ -0,0 +1,10 @@
import { IWithId, IWithTimestamps } from 'shared/types/db/interfaces';

interface IStreamKeyFields {
user_id: string;
channel_id: string;
created_by_id: string;
valid_for: number;
}

export default interface IStreamKey extends IStreamKeyFields, IWithId, IWithTimestamps {}

+ 2
- 0
src/types/api/v1/interfaces/IUser.js View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

+ 26
- 0
src/types/api/v1/interfaces/IUser.ts View File

@@ -0,0 +1,26 @@
interface ICommonUserFields {
id: string;
username: string;
bio?: string;
displayName: string;
singleChannelMode: boolean;
role: string;
}

export interface IUser extends ICommonUserFields {
email: string;
passwordHash: string;
passwordSalt: string;
}

export interface IUserSafe extends ICommonUserFields {
emailHash?: string;
}

export interface IUserCreation {
username: string;
email: string;
password: string;
}

export default IUser;

+ 9
- 0
src/types/api/v1/schemas/activity/createActivity.json View File

@@ -0,0 +1,9 @@
{
"type": "object",
"properties": {
"name": { "type": "string" },
"verb": { "type": "string" }
},
"additionalProperties": false,
"required": [ "name" ]
}

+ 9
- 0
src/types/api/v1/schemas/auth/loginRequest.json View File

@@ -0,0 +1,9 @@
{
"type": "object",
"properties": {
"username": { "type": "string" },
"password": { "type": "string", "minLength": 8 }
},
"additionalProperties": false,
"required": [ "username", "password" ]
}

+ 11
- 0
src/types/api/v1/schemas/channel/createChannel.json View File

@@ -0,0 +1,11 @@
{
"type": "object",
"properties": {
"title": { "type": "string" },
"slug": { "type": "string" },
"description": { "type": "string" },
"activity_id": { "type": "string" }
},
"additionalProperties": false,
"required": [ "title", "slug", "activity_id" ]
}

+ 15
- 0
src/types/api/v1/schemas/index.js View File

@@ -0,0 +1,15 @@
"use strict";
exports.__esModule = true;
var createActivity_json_1 = require("./activity/createActivity.json");
var loginRequest_json_1 = require("./auth/loginRequest.json");
var createChannel_json_1 = require("./channel/createChannel.json");
var createStreamkey_json_1 = require("./streamkeys/createStreamkey.json");
var createUser_json_1 = require("./user/createUser.json");
var updateUser_json_1 = require("./user/updateUser.json");
exports["default"] = {
activities: { createActivitySchema: createActivity_json_1["default"] },
auth: { loginRequestSchema: loginRequest_json_1["default"] },
channels: { createChannelSchema: createChannel_json_1["default"] },
streamKeys: { createStreamKeySchema: createStreamkey_json_1["default"] },
users: { createUserSchema: createUser_json_1["default"], updateUserSchema: updateUser_json_1["default"] }
};

+ 14
- 0
src/types/api/v1/schemas/index.ts View File

@@ -0,0 +1,14 @@
import createActivitySchema from "./activity/createActivity.json";
import loginRequestSchema from "./auth/loginRequest.json";
import createChannelSchema from "./channel/createChannel.json";
import createStreamKeySchema from "./streamkeys/createStreamkey.json";
import createUserSchema from "./user/createUser.json";
import updateUserSchema from "./user/updateUser.json";

export default {
activities: { createActivitySchema },
auth: { loginRequestSchema },
channels: { createChannelSchema },
streamKeys: { createStreamKeySchema },
users: { createUserSchema, updateUserSchema },
}

+ 9
- 0
src/types/api/v1/schemas/streamkeys/createStreamkey.json View File

@@ -0,0 +1,9 @@
{
"type": "object",
"properties": {
"user": { "type": "string" },
"channel": { "type": "string" }
},
"additionalProperties": false,
"required": [ "channel" ]
}

+ 10
- 0
src/types/api/v1/schemas/user/createUser.json View File

@@ -0,0 +1,10 @@
{
"type": "object",
"properties": {
"username": { "type": "string" },
"email": { "type": "string" },
"password": { "type": "string", "minLength": 8 }
},
"additionalProperties": false,
"required": [ "username", "password", "email" ]
}

+ 9
- 0
src/types/api/v1/schemas/user/updateUser.json View File

@@ -0,0 +1,9 @@
{
"type": "object",
"properties": {
"bio": { "type": "string" },
"displayName": { "type": "string" }
},
"minProperties": 1,
"additionalProperties": false
}

+ 2
- 0
src/types/db/interfaces.js View File

@@ -0,0 +1,2 @@
"use strict";
exports.__esModule = true;

+ 8
- 0
src/types/db/interfaces.ts View File

@@ -0,0 +1,8 @@
export interface IWithId {
id?: string;
}

export interface IWithTimestamps {
created_at?: Date;
updated_at?: Date;
}

+ 23
- 0
tsconfig.json View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "es6",
"declaration": true,
"module": "commonjs",
"lib": ["es2015", "es2016", "dom", "es2017", "es6", "es5"],
"esModuleInterop": true,
"noImplicitAny": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": false,
"outDir": "dist",
"baseUrl": "./",
"typeRoots" : ["./node_modules", "./node_modules/@types", "src/server/types"],
"paths": {
"shared/*": [ "src/*" ]
}
},
"include": [
"./test/**/*",
"./src/**/*"
]
}

+ 9
- 0
tslint.json View File

@@ -0,0 +1,9 @@
{
"extends": "tslint-config-airbnb",
"rules": {
"space-before-function-paren": { "options": ["always"] },
"import-name": false,
"variable-name": false,
"align": false
}
}

+ 8
- 0
yarn.lock View File

@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


typescript@^3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

Loading…
Cancel
Save