@fatehan/tsrp 1.0.2

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.
@@ -0,0 +1,8 @@
1
+ import { TripPerformanceRequest, TripPerformanceResponse, TripReportRequest, TripReportResponse } from "./fatehan/reports/report";
2
+ export declare class ReportService {
3
+ private readonly url;
4
+ private readonly headers;
5
+ constructor(url: string, authorization?: string, organizationId?: string);
6
+ TripPerformanceReport(request: TripPerformanceRequest): Promise<TripPerformanceResponse>;
7
+ TripReport(request: TripReportRequest): Promise<TripReportResponse>;
8
+ }
package/dist/index.js ADDED
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ReportService = void 0;
13
+ const report_1 = require("./fatehan/reports/report");
14
+ class ReportService {
15
+ constructor(url, authorization, organizationId) {
16
+ this.url = url;
17
+ this.headers = {
18
+ "Content-Type": "application/octet-stream",
19
+ "Accept": "application/octet-stream",
20
+ };
21
+ if (authorization) {
22
+ this.headers["Authorization"] = authorization;
23
+ }
24
+ if (organizationId) {
25
+ this.headers["Organization-Id"] = organizationId;
26
+ }
27
+ }
28
+ TripPerformanceReport(request) {
29
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
30
+ const response = yield fetch(`${this.url}/grpc/trip/performance`, {
31
+ method: "POST",
32
+ headers: this.headers,
33
+ body: report_1.TripPerformanceRequest.encode(request).finish(),
34
+ });
35
+ if (response.ok) {
36
+ resolve(report_1.TripPerformanceResponse.decode(new Uint8Array(yield response.arrayBuffer())));
37
+ }
38
+ else {
39
+ reject(yield response.text());
40
+ }
41
+ }));
42
+ }
43
+ TripReport(request) {
44
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
45
+ const response = yield fetch(`${this.url}/grpc/trip/index`, {
46
+ method: "POST",
47
+ headers: this.headers,
48
+ body: report_1.TripReportRequest.encode(request).finish(),
49
+ });
50
+ if (response.ok) {
51
+ resolve(report_1.TripReportResponse.decode(new Uint8Array(yield response.arrayBuffer())));
52
+ }
53
+ else {
54
+ reject(yield response.text());
55
+ }
56
+ }));
57
+ }
58
+ }
59
+ exports.ReportService = ReportService;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const vitest_1 = require("vitest");
13
+ const index_1 = require("./index");
14
+ const report_1 = require("./fatehan/reports/report");
15
+ (0, vitest_1.describe)('ReportService', () => {
16
+ let url = "http://localhost:1272";
17
+ let token = "1000066|wEjtQWKOr8WEtyzC4L4jg9wIkqvYn4maXzmpZRpi281f9f67";
18
+ let organization = "1000000";
19
+ let c = new index_1.ReportService(url, token, organization);
20
+ (0, vitest_1.it)('TripPerformanceReport', () => __awaiter(void 0, void 0, void 0, function* () {
21
+ let res = yield c.TripPerformanceReport({
22
+ groupByDevice: true,
23
+ groupByDatetime: report_1.TripPerformanceRequest_GroupBy.Day,
24
+ deviceId: [118709, 117989, 118710, 115351, 115972, 115248, 114845],
25
+ startedAt: new Date("2025-04-01 00:00:00"),
26
+ finishedAt: new Date("2025-04-22 00:00:00")
27
+ });
28
+ console.log("TripPerformanceReport", res.records);
29
+ }));
30
+ (0, vitest_1.it)('TripReport', () => __awaiter(void 0, void 0, void 0, function* () {
31
+ let res = yield c.TripReport({
32
+ deviceIds: [118709, 117989, 118710, 115351, 115972, 115248, 114845],
33
+ startedAt: new Date("2025-04-01 00:00:00"),
34
+ finishedAt: new Date("2025-04-22 00:00:00")
35
+ });
36
+ console.log("TripReport", res.records);
37
+ }));
38
+ });
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@fatehan/tsrp",
3
+ "version": "1.0.2",
4
+ "description": "fatehan main models",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+ssh://git@github.com:FatehanNew/tsrp.git"
13
+ },
14
+ "keywords": [],
15
+ "author": "96rajabi@gmail.com",
16
+ "license": "MIT",
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "test": "vitest"
20
+ },
21
+ "dependencies": {
22
+ "google-protobuf": "^3.21.4"
23
+ },
24
+ "devDependencies": {
25
+ "@types/google-protobuf": "^3.15.12",
26
+ "@types/node": "^22.14.1",
27
+ "ts-node": "^10.9.2",
28
+ "ts-proto": "^2.7.0",
29
+ "typescript": "^5.5.3",
30
+ "vitest": "^3.1.2"
31
+ }
32
+ }
package/readme.md ADDED
@@ -0,0 +1,11 @@
1
+ ### Compile
2
+
3
+ ```cmd
4
+ protoc \
5
+ --plugin=protoc-gen-ts_proto=/usr/bin/protoc-gen-ts_proto \
6
+ -I ./src/fatehan \
7
+ -I ../protocols \
8
+ --ts_proto_out=./src/fatehan \
9
+ --ts_proto_opt=outputServices=none,outputClientImpl=false,esModuleInterop=true,outputEncodeMethods=true,outputJsonMethods=true \
10
+ ../protocols/**/*.proto
11
+ ```