From 5e6de49f2bb448042954bd86f12048c8f00f9755 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Wed, 21 Dec 2022 10:48:39 +0330 Subject: [PATCH 1/8] feat(uniquely/com-api): new uniquely service --- uniquely/com-api/demo.http | 6 +++ uniquely/com-api/package.json | 53 +++++++++++++++++++++++++ uniquely/com-api/src/config.ts | 20 ++++++++++ uniquely/com-api/src/index.ts | 4 ++ uniquely/com-api/src/lib/nano-server.ts | 5 +++ uniquely/com-api/src/lib/storage.ts | 7 ++++ uniquely/com-api/src/lib/type.ts | 28 +++++++++++++ uniquely/com-api/src/route/home.ts | 11 +++++ uniquely/com-api/tsconfig.json | 19 +++++++++ 9 files changed, 153 insertions(+) create mode 100644 uniquely/com-api/demo.http create mode 100644 uniquely/com-api/package.json create mode 100644 uniquely/com-api/src/config.ts create mode 100644 uniquely/com-api/src/index.ts create mode 100644 uniquely/com-api/src/lib/nano-server.ts create mode 100644 uniquely/com-api/src/lib/storage.ts create mode 100644 uniquely/com-api/src/lib/type.ts create mode 100644 uniquely/com-api/src/route/home.ts create mode 100644 uniquely/com-api/tsconfig.json diff --git a/uniquely/com-api/demo.http b/uniquely/com-api/demo.http new file mode 100644 index 0000000000..905ce4c902 --- /dev/null +++ b/uniquely/com-api/demo.http @@ -0,0 +1,6 @@ +@apiUrl = http://127.0.0.1:8000 +@apiVersion = v0 +@token = YOUR_SECRET_TOKEN + +### Home +GET {{apiUrl}}/{{apiVersion}} diff --git a/uniquely/com-api/package.json b/uniquely/com-api/package.json new file mode 100644 index 0000000000..5d649677f4 --- /dev/null +++ b/uniquely/com-api/package.json @@ -0,0 +1,53 @@ +{ + "name": "@alwatr/com-api", + "version": "0.0.0", + "description": "Alwatr Customer Order Management API Microservice", + "type": "module", + "author": "S. Ali Mihandoost (https://ali.mihandoost.com)", + "contributors": [ + "S. Amir Mohammad Najafi (https://njfamirm.ir)" + ], + "private": true, + "engines": { + "node": ">=19.0.0", + "npm": ">=8.0.0", + "yarn": ">=1.22.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/AliMD/alwatr", + "directory": "uniquely/com-api" + }, + "scripts": { + "b": "yarn build", + "c": "yarn clean", + "cb": "run-s clean build", + "s": "yarn start", + "w": "yarn watch", + "start": "NODE_OPTIONS=--enable-source-maps run-s clean build serve", + "build": "yarn build:es --analyze=verbose", + "build:ts": "tsc --build", + "build:es": "esbuild src/index.ts --platform=node --target=node19 --bundle --format=esm --minify --sourcemap --outdir=dist --out-extension:.js=.mjs", + "clean": "rimraf dist build .tsbuildinfo **/*.{d.ts,map} src/**/*.{js,cjs,mjs}", + "serve": "node --enable-source-maps dist/index.mjs", + "serve:debug": "node --inspect --enable-source-maps dist/index.mjs", + "watch": "run-s clean build && run-p watch:es watch:node", + "watch:node": "nodemon -w dist/ --enable-source-maps dist/index.mjs", + "watch:debug-node": "nodemon -w dist/ --inspect --enable-source-maps dist/index.mjs", + "watch:ts": "yarn build:ts --watch --preserveWatchOutput", + "watch:es": "yarn build:es --watch" + }, + "dependencies": { + }, + "devDependencies": { + "@alwatr/logger": "~0.25.0", + "@alwatr/nano-server": "~0.25.0", + "@alwatr/storage-client": "~0.25.0", + "@types/node": "~18.11.17", + "esbuild": "~0.16.10", + "nodemon": "~2.0.20", + "npm-run-all": "~4.1.5", + "rimraf": "~3.0.2", + "typescript": "~4.9.4" + } +} diff --git a/uniquely/com-api/src/config.ts b/uniquely/com-api/src/config.ts new file mode 100644 index 0000000000..708aea95ce --- /dev/null +++ b/uniquely/com-api/src/config.ts @@ -0,0 +1,20 @@ +import {createLogger} from '@alwatr/logger'; + +export const logger = createLogger('flight-finder-api'); + +export const config = { + storage: { + host: process.env.STORAGE_HOST ?? '127.0.0.1', + port: process.env.STORAGE_PORT != null ? +process.env.STORAGE_PORT : 9000, + name: process.env.STORAGE_NAME ?? 'job', + token: process.env.STORAGE_TOKEN ?? 'YOUR_SECRET_TOKEN', + }, + nanoServer: { + host: process.env.HOST ?? '0.0.0.0', + port: process.env.PORT != null ? +process.env.PORT : 8000, + accessToken: process.env.ACCESS_TOKEN ?? 'YOUR_SECRET_TOKEN', + allowAllOrigin: true, + }, +}; + +logger.logProperty('config', config); diff --git a/uniquely/com-api/src/index.ts b/uniquely/com-api/src/index.ts new file mode 100644 index 0000000000..70fbe57dec --- /dev/null +++ b/uniquely/com-api/src/index.ts @@ -0,0 +1,4 @@ +import './route/home.js'; +import {logger} from './config.js'; + +logger.logOther('..:: Customer Order Management API ::..'); diff --git a/uniquely/com-api/src/lib/nano-server.ts b/uniquely/com-api/src/lib/nano-server.ts new file mode 100644 index 0000000000..593467ef56 --- /dev/null +++ b/uniquely/com-api/src/lib/nano-server.ts @@ -0,0 +1,5 @@ +import {AlwatrNanoServer} from '@alwatr/nano-server'; + +import {config} from '../config.js'; + +export const nanoServer = new AlwatrNanoServer(config.nanoServer); diff --git a/uniquely/com-api/src/lib/storage.ts b/uniquely/com-api/src/lib/storage.ts new file mode 100644 index 0000000000..ef82ca2f01 --- /dev/null +++ b/uniquely/com-api/src/lib/storage.ts @@ -0,0 +1,7 @@ +import {AlwatrStorageClient} from '@alwatr/storage-client'; + +import {config} from '../config.js'; + +import type {Order} from './type.js'; + +export const storageClient = new AlwatrStorageClient(config.storage); diff --git a/uniquely/com-api/src/lib/type.ts b/uniquely/com-api/src/lib/type.ts new file mode 100644 index 0000000000..72c8dcabaa --- /dev/null +++ b/uniquely/com-api/src/lib/type.ts @@ -0,0 +1,28 @@ +import type {AlwatrDocumentObject} from '@alwatr/storage-client'; + +export interface Job extends AlwatrDocumentObject { + detail: JobDetail; + resultList: Array; +} + +export type dayParts = 'earlyMorning' | 'morning' | 'midday' | 'afternoon' | 'evening' | 'night'; + +export interface JobDetail extends Record { + origin: string; + destination: string; + date: string; + seatCount: number; + maxPrice: number | null; + dayPart: Array; + description: string; +} + +export interface JobResult extends Record { + price: number; + time: string; + seatCount: number; + airline: string, + airplane: string, + flightId: string, + arrivalTime: string, +} diff --git a/uniquely/com-api/src/route/home.ts b/uniquely/com-api/src/route/home.ts new file mode 100644 index 0000000000..4077477db0 --- /dev/null +++ b/uniquely/com-api/src/route/home.ts @@ -0,0 +1,11 @@ +import {nanoServer} from '../lib/nano-server.js'; + +nanoServer.route('GET', '/', async (connection) => { + connection.reply({ + ok: true, + data: { + app: 'Alwatr Customer Order Management API Microservice', + message: 'Hello ;)', + }, + }); +}); diff --git a/uniquely/com-api/tsconfig.json b/uniquely/com-api/tsconfig.json new file mode 100644 index 0000000000..5174e62755 --- /dev/null +++ b/uniquely/com-api/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../tsconfig.base", + "compilerOptions": { + "target": "ESNext", + "composite": true, + "tsBuildInfoFile": ".tsbuildinfo", + "rootDir": "src", + "outDir": "build", + // "noEmit": true + }, + + "include": ["src/**/*.ts"], + "exclude": [], + "references": [ + {"path": "../../core/nano-server"}, + {"path": "../../core/logger"}, + {"path": "../../core/storage-client"}, + ] +} From e9d85280902a1519144f65fbf8a323bc3d56c58f Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Wed, 21 Dec 2022 10:49:37 +0330 Subject: [PATCH 2/8] chore: package.json repo --- uniquely/flight-finder-api/package.json | 7 +++++-- uniquely/flight-finder-pwa/package.json | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/uniquely/flight-finder-api/package.json b/uniquely/flight-finder-api/package.json index c5ef36418d..e116e01e09 100644 --- a/uniquely/flight-finder-api/package.json +++ b/uniquely/flight-finder-api/package.json @@ -4,6 +4,9 @@ "description": "Alwatr Flight Finder API Microservice", "type": "module", "author": "S. Ali Mihandoost (https://ali.mihandoost.com)", + "contributors": [ + "S. Amir Mohammad Najafi (https://njfamirm.ir)" + ], "private": true, "engines": { "node": ">=19.0.0", @@ -12,8 +15,8 @@ }, "repository": { "type": "git", - "url": "https://github.com/AliMD/flight-finder", - "directory": "api" + "url": "https://github.com/AliMD/alwatr", + "directory": "uniquely/flight-finder-api" }, "scripts": { "b": "yarn build", diff --git a/uniquely/flight-finder-pwa/package.json b/uniquely/flight-finder-pwa/package.json index 0047be7a99..c4ee9e004c 100644 --- a/uniquely/flight-finder-pwa/package.json +++ b/uniquely/flight-finder-pwa/package.json @@ -13,8 +13,8 @@ "browserslist": "> 0.1%, not dead", "repository": { "type": "git", - "url": "https://github.com/AliMD/flight-finder", - "directory": "pwa" + "url": "https://github.com/AliMD/alwatr", + "directory": "uniquely/flight-finder-pwa" }, "scripts": { "b": "yarn build", From 3b144839bc6c1760bc9feb29e5f48fb0836a5562 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Wed, 21 Dec 2022 11:12:18 +0330 Subject: [PATCH 3/8] chore(uniquely/com-api): remove types --- uniquely/com-api/src/lib/type.ts | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/uniquely/com-api/src/lib/type.ts b/uniquely/com-api/src/lib/type.ts index 72c8dcabaa..6703f1d71a 100644 --- a/uniquely/com-api/src/lib/type.ts +++ b/uniquely/com-api/src/lib/type.ts @@ -1,28 +1,3 @@ import type {AlwatrDocumentObject} from '@alwatr/storage-client'; -export interface Job extends AlwatrDocumentObject { - detail: JobDetail; - resultList: Array; -} - -export type dayParts = 'earlyMorning' | 'morning' | 'midday' | 'afternoon' | 'evening' | 'night'; - -export interface JobDetail extends Record { - origin: string; - destination: string; - date: string; - seatCount: number; - maxPrice: number | null; - dayPart: Array; - description: string; -} - -export interface JobResult extends Record { - price: number; - time: string; - seatCount: number; - airline: string, - airplane: string, - flightId: string, - arrivalTime: string, -} +export type Order = AlwatrDocumentObject From b6af7ef59b33accf901dda07c02f24399506e132 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Wed, 21 Dec 2022 11:23:34 +0330 Subject: [PATCH 4/8] feat(uniquely/com-api): types --- uniquely/com-api/src/lib/type.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/uniquely/com-api/src/lib/type.ts b/uniquely/com-api/src/lib/type.ts index 6703f1d71a..c09afa82c3 100644 --- a/uniquely/com-api/src/lib/type.ts +++ b/uniquely/com-api/src/lib/type.ts @@ -1,3 +1,31 @@ import type {AlwatrDocumentObject} from '@alwatr/storage-client'; -export type Order = AlwatrDocumentObject +export type Order = AlwatrDocumentObject & { + user: User; + detail: OrderDetail; + itemList: Array +} + +export type User = AlwatrDocumentObject & { + name: string; + phoneNumber: string; + id: string; + nationalCode: number; +} + +export type OrderDetail = { + description: string; + reciver: User; +} + +export type Product = AlwatrDocumentObject & { + id: string; + name: string; + description: string; + type: string; + price: number; +} + +export type ProductValue = Product & { + value: number; +} From 469c36aec2fd991b30c63753f6d6a13a8d063bfb Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Wed, 21 Dec 2022 11:29:15 +0330 Subject: [PATCH 5/8] feat(uniquely/com-api): improve types --- uniquely/com-api/src/lib/type.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/uniquely/com-api/src/lib/type.ts b/uniquely/com-api/src/lib/type.ts index c09afa82c3..51213febc9 100644 --- a/uniquely/com-api/src/lib/type.ts +++ b/uniquely/com-api/src/lib/type.ts @@ -3,29 +3,30 @@ import type {AlwatrDocumentObject} from '@alwatr/storage-client'; export type Order = AlwatrDocumentObject & { user: User; detail: OrderDetail; - itemList: Array -} + itemList: Array; +}; export type User = AlwatrDocumentObject & { name: string; phoneNumber: string; - id: string; +}; + +export type Reciver = User & { nationalCode: number; } export type OrderDetail = { description: string; - reciver: User; -} + reciver: Reciver; +}; export type Product = AlwatrDocumentObject & { - id: string; name: string; description: string; type: string; price: number; -} +}; export type ProductValue = Product & { value: number; -} +}; From 0497f37bb28f41ef2dfc4835324a3d8f42b1b687 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Thu, 22 Dec 2022 09:52:46 +0330 Subject: [PATCH 6/8] fix(com-api): update home route --- uniquely/com-api/src/route/home.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/uniquely/com-api/src/route/home.ts b/uniquely/com-api/src/route/home.ts index 4077477db0..d3e34600bd 100644 --- a/uniquely/com-api/src/route/home.ts +++ b/uniquely/com-api/src/route/home.ts @@ -1,11 +1,9 @@ import {nanoServer} from '../lib/nano-server.js'; -nanoServer.route('GET', '/', async (connection) => { - connection.reply({ - ok: true, - data: { - app: 'Alwatr Customer Order Management API Microservice', - message: 'Hello ;)', - }, - }); -}); +nanoServer.route('GET', '/', () => ({ + ok: true, + data: { + app: 'Alwatr Customer Order Management API Microservice', + message: 'Hello ;)', + }, +})); From 0bc7c0c868ea8821465975bcc07fa0c644f241d1 Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Sun, 1 Jan 2023 15:19:45 +0330 Subject: [PATCH 7/8] feat(com-api): update packages --- uniquely/com-api/package.json | 14 ++++++-------- uniquely/com-api/src/lib/type.ts | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/uniquely/com-api/package.json b/uniquely/com-api/package.json index 5d649677f4..6751d0f93c 100644 --- a/uniquely/com-api/package.json +++ b/uniquely/com-api/package.json @@ -1,6 +1,6 @@ { "name": "@alwatr/com-api", - "version": "0.0.0", + "version": "0.27.0", "description": "Alwatr Customer Order Management API Microservice", "type": "module", "author": "S. Ali Mihandoost (https://ali.mihandoost.com)", @@ -37,14 +37,12 @@ "watch:ts": "yarn build:ts --watch --preserveWatchOutput", "watch:es": "yarn build:es --watch" }, - "dependencies": { - }, "devDependencies": { - "@alwatr/logger": "~0.25.0", - "@alwatr/nano-server": "~0.25.0", - "@alwatr/storage-client": "~0.25.0", - "@types/node": "~18.11.17", - "esbuild": "~0.16.10", + "@alwatr/logger": "~0.27.0", + "@alwatr/nano-server": "~0.27.0", + "@alwatr/storage-client": "~0.27.0", + "@types/node": "~18.11.18", + "esbuild": "~0.16.11", "nodemon": "~2.0.20", "npm-run-all": "~4.1.5", "rimraf": "~3.0.2", diff --git a/uniquely/com-api/src/lib/type.ts b/uniquely/com-api/src/lib/type.ts index 51213febc9..676c9992d4 100644 --- a/uniquely/com-api/src/lib/type.ts +++ b/uniquely/com-api/src/lib/type.ts @@ -1,4 +1,4 @@ -import type {AlwatrDocumentObject} from '@alwatr/storage-client'; +import type {AlwatrDocumentObject} from '@alwatr/type'; export type Order = AlwatrDocumentObject & { user: User; From 815fef62dd03bf4d5d711525984c1ef92d0fcc8e Mon Sep 17 00:00:00 2001 From: "S. Amir Mohammad Najafi" Date: Sun, 1 Jan 2023 15:46:43 +0330 Subject: [PATCH 8/8] chore(com-api): remove types --- uniquely/com-api/src/config.ts | 2 +- uniquely/com-api/src/lib/storage.ts | 4 +--- uniquely/com-api/src/lib/type.ts | 32 ----------------------------- 3 files changed, 2 insertions(+), 36 deletions(-) delete mode 100644 uniquely/com-api/src/lib/type.ts diff --git a/uniquely/com-api/src/config.ts b/uniquely/com-api/src/config.ts index 708aea95ce..b52e0b1e46 100644 --- a/uniquely/com-api/src/config.ts +++ b/uniquely/com-api/src/config.ts @@ -1,6 +1,6 @@ import {createLogger} from '@alwatr/logger'; -export const logger = createLogger('flight-finder-api'); +export const logger = createLogger('com-api'); export const config = { storage: { diff --git a/uniquely/com-api/src/lib/storage.ts b/uniquely/com-api/src/lib/storage.ts index ef82ca2f01..52f8dee88c 100644 --- a/uniquely/com-api/src/lib/storage.ts +++ b/uniquely/com-api/src/lib/storage.ts @@ -2,6 +2,4 @@ import {AlwatrStorageClient} from '@alwatr/storage-client'; import {config} from '../config.js'; -import type {Order} from './type.js'; - -export const storageClient = new AlwatrStorageClient(config.storage); +export const storageClient = new AlwatrStorageClient(config.storage); diff --git a/uniquely/com-api/src/lib/type.ts b/uniquely/com-api/src/lib/type.ts deleted file mode 100644 index 676c9992d4..0000000000 --- a/uniquely/com-api/src/lib/type.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type {AlwatrDocumentObject} from '@alwatr/type'; - -export type Order = AlwatrDocumentObject & { - user: User; - detail: OrderDetail; - itemList: Array; -}; - -export type User = AlwatrDocumentObject & { - name: string; - phoneNumber: string; -}; - -export type Reciver = User & { - nationalCode: number; -} - -export type OrderDetail = { - description: string; - reciver: Reciver; -}; - -export type Product = AlwatrDocumentObject & { - name: string; - description: string; - type: string; - price: number; -}; - -export type ProductValue = Product & { - value: number; -};