simpleloan_api 1.0.1 → 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,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SimpleloanApi = void 0;
4
+ var vue_1 = require("vue");
5
+ var SimpleloanApi;
6
+ (function (SimpleloanApi) {
7
+ var mode = (0, vue_1.ref)("development");
8
+ var token = null;
9
+ function setMode(newMode) {
10
+ mode.value = newMode;
11
+ }
12
+ SimpleloanApi.setMode = setMode;
13
+ function getMode() {
14
+ return mode.value;
15
+ }
16
+ SimpleloanApi.getMode = getMode;
17
+ function setToken(newToken) {
18
+ token = newToken;
19
+ }
20
+ SimpleloanApi.setToken = setToken;
21
+ function removeToken() {
22
+ token = null;
23
+ }
24
+ SimpleloanApi.removeToken = removeToken;
25
+ function getToken() {
26
+ return token;
27
+ }
28
+ SimpleloanApi.getToken = getToken;
29
+ })(SimpleloanApi || (exports.SimpleloanApi = SimpleloanApi = {}));
30
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;AAAA,2BAA0B;AAI1B,IAAiB,aAAa,CAuB7B;AAvBD,WAAiB,aAAa;IAC5B,IAAM,IAAI,GAAG,IAAA,SAAG,EAAO,aAAa,CAAC,CAAC;IACtC,IAAI,KAAK,GAAkB,IAAI,CAAC;IAEhC,SAAgB,OAAO,CAAC,OAAa;QACnC,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;IACvB,CAAC;IAFe,qBAAO,UAEtB,CAAA;IAED,SAAgB,OAAO;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAFe,qBAAO,UAEtB,CAAA;IAED,SAAgB,QAAQ,CAAC,QAAgB;QACvC,KAAK,GAAG,QAAQ,CAAC;IACnB,CAAC;IAFe,sBAAQ,WAEvB,CAAA;IAED,SAAgB,WAAW;QACzB,KAAK,GAAG,IAAI,CAAC;IACf,CAAC;IAFe,yBAAW,cAE1B,CAAA;IAED,SAAgB,QAAQ;QACtB,OAAO,KAAK,CAAC;IACf,CAAC;IAFe,sBAAQ,WAEvB,CAAA;AACH,CAAC,EAvBgB,aAAa,6BAAb,aAAa,QAuB7B"}
package/dist/index.js CHANGED
@@ -1,20 +1,6 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./fetch"), exports);
18
- __exportStar(require("./repositories"), exports);
19
- __exportStar(require("./settings"), exports);
3
+ var api_1 = require("./api");
4
+ exports.default = api_1.SimpleloanApi;
5
+ Object.assign(module.exports, api_1.SimpleloanApi);
20
6
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAuB;AACvB,iDAA8B;AAC9B,6CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,6BAAsC;AACtC,kBAAe,mBAAa,CAAC;AAC7B,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,mBAAa,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "simpleloan_api",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "main": "dist/index.js",
5
+ "files": [
6
+ "dist"
7
+ ],
5
8
  "scripts": {
6
9
  "build": "tsc",
7
10
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -13,6 +16,7 @@
13
16
  "license": "ISC",
14
17
  "description": "simpleloan api methods with types",
15
18
  "dependencies": {
19
+ "@types/node": "^22.1.0",
16
20
  "typescript": "^5.5.4",
17
21
  "vue": "^3.2.13"
18
22
  }
package/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './src'
@@ -1,84 +0,0 @@
1
- import { Ref, ref } from "vue";
2
- import { ApiResponse, PostParams, SearchParams } from "./types";
3
- import { getToken, mode } from "../settings";
4
-
5
- async function getContent(response: Response) {
6
- const contentType = response.headers.get("Content-Type");
7
- if (!contentType) return null;
8
-
9
- if (contentType.includes("application/json")) {
10
- return response.json();
11
- }
12
-
13
- if (contentType.includes("text")) {
14
- return response.text();
15
- }
16
-
17
- if (
18
- contentType.includes("application/octet-stream") ||
19
- contentType.includes("blob")
20
- ) {
21
- return response.blob();
22
- }
23
- }
24
-
25
- function getHeaders() {
26
- return {
27
- Accept: "application/json, text/plain, */*",
28
- "Content-Type": "application/json; text/html; image/png",
29
- };
30
- }
31
-
32
- function getApiUrl() {
33
- return mode.value === "production"
34
- ? "portal.simpleloan.ru/api/"
35
- : "slb.medv.ru/api/";
36
- }
37
-
38
- function getBody(params: { body?: any; search?: SearchParams }) {
39
- return JSON.stringify({
40
- _data: params.body || undefined,
41
- _searchParams: params.search || undefined,
42
- _token: getToken(),
43
- });
44
- }
45
-
46
- type FetchReturn<T, Body> = {
47
- response: Ref<ApiResponse<T> | null>;
48
- pending: Ref<boolean>;
49
- post(params: PostParams<Body>): Promise<ApiResponse<T> | null>;
50
- };
51
-
52
- export function useFetch<T, Body>(url: string): FetchReturn<T, Body>;
53
-
54
- export function useFetch<T, Body>(url: string) {
55
- const response = ref<ApiResponse<T> | null>(
56
- null
57
- ) as Ref<ApiResponse<T> | null>;
58
- const pending = ref<boolean>(false);
59
- const fullUrl = getApiUrl() + url;
60
-
61
- async function post(params?: PostParams<Body>) {
62
- pending.value = true;
63
-
64
- const body = params?.body;
65
- const search = params?.search;
66
-
67
- try {
68
- const fetchResponse = await fetch(fullUrl, {
69
- method: "POST",
70
- body: getBody({ body, search }),
71
- headers: getHeaders(),
72
- });
73
-
74
- const content = await getContent(fetchResponse);
75
- response.value = content;
76
- } catch (error) {
77
- response.value = null;
78
- }
79
-
80
- return response.value;
81
- }
82
-
83
- return { post, response, pending };
84
- }
@@ -1,20 +0,0 @@
1
- export type ApiResponse<T> = {
2
- _code: number;
3
- _message?: string;
4
- _detail?: { [param: string]: string[] };
5
- _data_total_size?: number;
6
- _data?: T;
7
- };
8
-
9
- export type SearchParams = {
10
- _filter?: Record<string, any>;
11
- _page_size?: number;
12
- _fields?: string[];
13
- _start_index?: number;
14
- _sort?: string[];
15
- };
16
-
17
- export type PostParams<Body> = {
18
- body: Body;
19
- search?: SearchParams;
20
- };
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './fetch'
2
- export * from './repositories'
3
- export * from './settings'
@@ -1,7 +0,0 @@
1
- import { useFetch } from "../../fetch";
2
- import { General } from "./types";
3
-
4
- export const useGetGeneral = () =>
5
- useFetch<General, { id: number }>("general/get/");
6
-
7
-
@@ -1,5 +0,0 @@
1
- export type General = {
2
- id: number;
3
- user_id: number;
4
- salespoint_id: number;
5
- }
@@ -1 +0,0 @@
1
- export * from './general'
@@ -1,32 +0,0 @@
1
- import { ref } from "vue";
2
-
3
- type Mode = "development" | "production";
4
-
5
- let token: string | null = null;
6
-
7
- export const mode = ref<Mode>("development");
8
-
9
-
10
- export function setMode(newMode: Mode) {
11
- mode.value = newMode;
12
- }
13
-
14
-
15
- export function getMode() {
16
- return mode.value
17
- }
18
-
19
-
20
- export function setToken(newToken: string) {
21
- token = newToken;
22
- }
23
-
24
-
25
- export function removeToken() {
26
- token = null;
27
- }
28
-
29
-
30
- export function getToken() {
31
- return token;
32
- }
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "dist",
4
- "lib": [
5
- "es2016",
6
- "dom",
7
- ],
8
- "sourceMap": true
9
- },
10
- "include": [
11
- "src/**/*.ts"
12
- ]
13
- }