@fatehan/tsrp 1.1.13 → 1.1.15

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/dist/api.d.ts CHANGED
@@ -1,12 +1,19 @@
1
- import { AreaIndexRequest, AreaIndexResponse, ConfigRequest, ConfigResponse, DeviceRequest, DeviceResponse, MeRequest, MeResponse } from "./fatehan/services/api";
1
+ import { AreaIndexRequest, AreaIndexResponse, ConfigRequest, ConfigResponse, DeviceRequest, DeviceResponse, MeRequest, MeResponse, UserRequest, UserResponse } from "./fatehan/services/api";
2
+ export type HeaderProvider = () => Promise<HeadersInit> | HeadersInit;
2
3
  export declare class ApiService {
3
4
  private readonly url;
4
5
  private readonly namespace;
5
- private readonly headers;
6
- constructor(url: string, authorization?: string, organizationId?: string);
6
+ private readonly getDynamicHeaders;
7
+ /**
8
+ * @param url The base URL of the API server.
9
+ * @param headerProvider A function that returns headers to be added to each request.
10
+ */
11
+ constructor(url: string, headerProvider: HeaderProvider);
12
+ private _call;
7
13
  MeIndex(request: MeRequest): Promise<MeResponse>;
8
14
  DeviceIndex(request: DeviceRequest): Promise<DeviceResponse>;
9
15
  AreaIndex(request: AreaIndexRequest): Promise<AreaIndexResponse>;
10
16
  ConfigIndex(request: ConfigRequest): Promise<ConfigResponse>;
17
+ UserIndex(request: UserRequest): Promise<UserResponse>;
11
18
  }
12
19
  //# sourceMappingURL=api.d.ts.map
package/dist/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,SAAS,EACT,UAAU,EACX,MAAM,wBAAwB,CAAC;AAEhC,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA6C;IAC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AS,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAGhE"}
package/dist/api.js CHANGED
@@ -3,80 +3,50 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiService = void 0;
4
4
  const api_1 = require("./fatehan/services/api");
5
5
  class ApiService {
6
- constructor(url, authorization, organizationId) {
6
+ /**
7
+ * @param url The base URL of the API server.
8
+ * @param headerProvider A function that returns headers to be added to each request.
9
+ */
10
+ constructor(url, headerProvider) {
7
11
  this.namespace = "com.fatehan.services.ApiService";
8
12
  this.url = url;
9
- this.headers = {
13
+ this.getDynamicHeaders = headerProvider;
14
+ }
15
+ async _call(methodName, request, encoder, decoder) {
16
+ const dynamicHeaders = await this.getDynamicHeaders();
17
+ const headers = {
10
18
  "Content-Type": "application/octet-stream",
11
19
  Accept: "application/octet-stream",
20
+ ...dynamicHeaders,
12
21
  };
13
- if (authorization) {
14
- this.headers["authorization"] = "Bearer " + authorization;
22
+ const response = await fetch(`${this.url}/${this.namespace}/${methodName}`, {
23
+ method: "POST",
24
+ headers: headers,
25
+ body: new Uint8Array(encoder.encode(request).finish()),
26
+ });
27
+ if (response.ok) {
28
+ const buffer = await response.arrayBuffer();
29
+ return decoder.decode(new Uint8Array(buffer));
15
30
  }
16
- if (organizationId) {
17
- this.headers["organization-id"] = organizationId;
31
+ else {
32
+ const errorText = await response.text();
33
+ throw new Error(`API Error (${response.status}): ${errorText}`);
18
34
  }
19
35
  }
20
36
  MeIndex(request) {
21
- return new Promise(async (resolve, reject) => {
22
- var req = new Uint8Array(api_1.MeRequest.encode(request).finish());
23
- const response = await fetch(`${this.url}/${this.namespace}/MeIndex`, {
24
- method: "POST",
25
- headers: this.headers,
26
- body: req,
27
- });
28
- if (response.ok) {
29
- resolve(api_1.MeResponse.decode(new Uint8Array(await response.arrayBuffer())));
30
- }
31
- else {
32
- reject(await response.text());
33
- }
34
- });
37
+ return this._call("MeIndex", request, api_1.MeRequest, api_1.MeResponse);
35
38
  }
36
39
  DeviceIndex(request) {
37
- return new Promise(async (resolve, reject) => {
38
- const response = await fetch(`${this.url}/${this.namespace}/DeviceIndex`, {
39
- method: "POST",
40
- headers: this.headers,
41
- body: new Uint8Array(api_1.DeviceRequest.encode(request).finish()),
42
- });
43
- if (response.ok) {
44
- resolve(api_1.DeviceResponse.decode(new Uint8Array(await response.arrayBuffer())));
45
- }
46
- else {
47
- reject(await response.text());
48
- }
49
- });
40
+ return this._call("DeviceIndex", request, api_1.DeviceRequest, api_1.DeviceResponse);
50
41
  }
51
42
  AreaIndex(request) {
52
- return new Promise(async (resolve, reject) => {
53
- const response = await fetch(`${this.url}/${this.namespace}/AreaIndex`, {
54
- method: "POST",
55
- headers: this.headers,
56
- body: new Uint8Array(api_1.AreaIndexRequest.encode(request).finish()),
57
- });
58
- if (response.ok) {
59
- resolve(api_1.AreaIndexResponse.decode(new Uint8Array(await response.arrayBuffer())));
60
- }
61
- else {
62
- reject(await response.text());
63
- }
64
- });
43
+ return this._call("AreaIndex", request, api_1.AreaIndexRequest, api_1.AreaIndexResponse);
65
44
  }
66
45
  ConfigIndex(request) {
67
- return new Promise(async (resolve, reject) => {
68
- const response = await fetch(`${this.url}/${this.namespace}/ConfigIndex`, {
69
- method: "POST",
70
- headers: this.headers,
71
- body: new Uint8Array(api_1.ConfigRequest.encode(request).finish()),
72
- });
73
- if (response.ok) {
74
- resolve(api_1.ConfigResponse.decode(new Uint8Array(await response.arrayBuffer())));
75
- }
76
- else {
77
- reject(await response.text());
78
- }
79
- });
46
+ return this._call("ConfigIndex", request, api_1.ConfigRequest, api_1.ConfigResponse);
47
+ }
48
+ UserIndex(request) {
49
+ return this._call("UserIndex", request, api_1.UserRequest, api_1.UserResponse);
80
50
  }
81
51
  }
82
52
  exports.ApiService = ApiService;
package/dist/api.test.js CHANGED
@@ -1,23 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const vitest_1 = require("vitest");
7
4
  const api_1 = require("./api");
8
- const long_1 = __importDefault(require("long"));
9
5
  (0, vitest_1.describe)("ApiService", () => {
10
6
  let url = "https://beta.myavl.ir/gapi";
11
- let token = "172|ofr8rAzW4WobrXeZb5mzRputv6GIpbK3KdWDU4ged2ca871c";
12
- let organization = "1000001";
7
+ let token = "result";
8
+ let organization = null;
13
9
  // let url: string = "http://127.0.0.1:4333";
14
10
  // let token: string = "157|HruYqS4J5V2Yj1Hu9IISH4CEQfl4TkujKFUzobnlef550974";
15
11
  // let organization: string = "1012494";
16
12
  let c = new api_1.ApiService(url, token, organization);
17
13
  (0, vitest_1.it)("MeIndex", async () => {
18
- let res = await c.MeIndex({
19
- deviceId: long_1.default.fromInt(119926),
20
- });
14
+ let res = await c.MeIndex({});
21
15
  console.log("MeIndex", res);
22
16
  });
23
17
  (0, vitest_1.it)("ConfigIndex", async () => {
@@ -0,0 +1,67 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ import Long from "long";
3
+ import { User } from "./identities";
4
+ export declare const protobufPackage = "com.fatehan.identities";
5
+ export interface OtpCodeRequest {
6
+ phone: Long;
7
+ }
8
+ export interface OtpCodeResponse {
9
+ message: string;
10
+ passwordRequired: boolean;
11
+ }
12
+ export interface AuthResponse {
13
+ user?: User | undefined;
14
+ token: string;
15
+ }
16
+ export interface AuthRequest {
17
+ passwordAuth?: PasswordAuth | undefined;
18
+ googleAuth?: GoogleAuth | undefined;
19
+ qrCodeAuth?: QrCodeAuth | undefined;
20
+ telegramAuth?: TelegramAuth | undefined;
21
+ otpAuth?: OtpAuth | undefined;
22
+ }
23
+ export interface PasswordAuth {
24
+ phone: Long;
25
+ password: string;
26
+ }
27
+ export interface QrCodeAuth {
28
+ token: string;
29
+ }
30
+ export interface OtpAuth {
31
+ phone: Long;
32
+ code: number;
33
+ password?: string | undefined;
34
+ }
35
+ export interface GoogleAuth {
36
+ }
37
+ export interface TelegramAuth {
38
+ }
39
+ export declare const OtpCodeRequest: MessageFns<OtpCodeRequest>;
40
+ export declare const OtpCodeResponse: MessageFns<OtpCodeResponse>;
41
+ export declare const AuthResponse: MessageFns<AuthResponse>;
42
+ export declare const AuthRequest: MessageFns<AuthRequest>;
43
+ export declare const PasswordAuth: MessageFns<PasswordAuth>;
44
+ export declare const QrCodeAuth: MessageFns<QrCodeAuth>;
45
+ export declare const OtpAuth: MessageFns<OtpAuth>;
46
+ export declare const GoogleAuth: MessageFns<GoogleAuth>;
47
+ export declare const TelegramAuth: MessageFns<TelegramAuth>;
48
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
49
+ export type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
50
+ [K in keyof T]?: DeepPartial<T[K]>;
51
+ } : Partial<T>;
52
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
53
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
54
+ [K in keyof P]: Exact<P[K], I[K]>;
55
+ } & {
56
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
57
+ };
58
+ export interface MessageFns<T> {
59
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
60
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
61
+ fromJSON(object: any): T;
62
+ toJSON(message: T): unknown;
63
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
64
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
65
+ }
66
+ export {};
67
+ //# sourceMappingURL=authentication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authentication.d.ts","sourceRoot":"","sources":["../../../src/fatehan/identities/authentication.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAy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