@unsource/ui 2.2.4 → 2.3.0

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unsource-ui",
3
3
  "configKey": "unsourceUi",
4
- "version": "2.2.4",
4
+ "version": "2.3.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,2 +1,26 @@
1
- import type { Form } from '../types/models.js';
1
+ import type { Form, InputOption, Section, Profile, Transaction, Slider, User, Banner, WithdrawRequest, Coin } from '../types/models.js';
2
2
  export declare const getForms: (name: string) => Promise<Form[] | undefined>;
3
+ export declare const getUserInfo: () => Promise<User | null>;
4
+ export declare const getCoin: (id?: string | null) => Promise<Coin | undefined>;
5
+ export declare const getBanner: (cat: string) => Promise<Banner | null | undefined>;
6
+ export declare const getSections: () => Promise<Section | never[]>;
7
+ export declare const getCategorySection: (data: Slider) => Promise<InputOption[]>;
8
+ export declare const getOption: (key: string, params?: {}) => Promise<InputOption | null>;
9
+ export declare const getOptions: (key: string) => Promise<InputOption[]>;
10
+ export declare const getTransactions: (walletIds: string[], justWallet?: boolean) => Promise<Transaction[] | undefined>;
11
+ export declare const saveUser: (user: User) => Promise<any>;
12
+ export declare const saveProfile: (profile: Profile) => Promise<any>;
13
+ export declare const saveWithdraw: (withdraw: WithdrawRequest) => Promise<any>;
14
+ export declare const cancelRequest: (request: WithdrawRequest) => Promise<any>;
15
+ export declare const verifyPayment: (txId?: string) => Promise<{
16
+ trx: Transaction;
17
+ status: boolean;
18
+ message: string;
19
+ } | {
20
+ trx: undefined;
21
+ status: boolean;
22
+ message: string;
23
+ } | undefined>;
24
+ export declare const submitInviteCode: (code: string) => Promise<void>;
25
+ export declare const normalizePersian: (text: string) => string;
26
+ export declare const unNormalizePersian: (text: string) => string;
@@ -1,4 +1,8 @@
1
1
  import { useGet } from "../composables/fetch.js";
2
+ import {
3
+ useUser,
4
+ useUserId
5
+ } from "./reuseable.js";
2
6
  export const getForms = async (name) => {
3
7
  const { result } = await useGet("/Form", {
4
8
  params: {
@@ -10,3 +14,174 @@ export const getForms = async (name) => {
10
14
  });
11
15
  return result;
12
16
  };
17
+ export const getUserInfo = async () => {
18
+ const userId = useUserId();
19
+ const user = useUser();
20
+ if (userId.value) {
21
+ const { result } = await useGet(`/user/${userId.value}`, {
22
+ params: {
23
+ "$i.profile": true
24
+ }
25
+ });
26
+ if (result) {
27
+ user.value = result;
28
+ return result;
29
+ }
30
+ }
31
+ return null;
32
+ };
33
+ export const getCoin = async (id = null) => {
34
+ let res;
35
+ if (id) {
36
+ res = await useGet(`/coin/${id}`);
37
+ } else {
38
+ res = await useGet("/coin/unit/IRT");
39
+ }
40
+ if (res) {
41
+ return res.result;
42
+ }
43
+ };
44
+ export const getBanner = async (cat) => {
45
+ if (!cat) return null;
46
+ const { result } = await useGet(`/Banner/categoryKey/${cat}`, {
47
+ headers: {
48
+ "no-error": true
49
+ }
50
+ });
51
+ return result;
52
+ };
53
+ export const getSections = async () => {
54
+ const { result } = await useGet("/Section", {
55
+ params: {
56
+ "$i.banner": true,
57
+ "$i.slider": true,
58
+ "$o.priority": "asc"
59
+ }
60
+ });
61
+ return result || [];
62
+ };
63
+ export const getCategorySection = async (data) => {
64
+ const { result } = await useGet(`/InputOption${data.query}`, {
65
+ headers: {
66
+ qt: "v1"
67
+ },
68
+ params: {
69
+ "with-input": true
70
+ }
71
+ });
72
+ return result || [];
73
+ };
74
+ export const getOption = async (key, params = {}) => {
75
+ const { result } = await useGet(`/InputOption/key/${key}`, {
76
+ params,
77
+ headers: {
78
+ "no-error": true
79
+ }
80
+ });
81
+ return result || null;
82
+ };
83
+ export const getOptions = async (key) => {
84
+ const { result } = await useGet("/InputOption", {
85
+ params: {
86
+ "$w.input.key": key
87
+ // "$i.input": true,
88
+ }
89
+ });
90
+ return result || [];
91
+ };
92
+ export const getTransactions = async (walletIds, justWallet = false) => {
93
+ const userId = useUserId();
94
+ const { result } = await useGet("/transaction", {
95
+ params: {
96
+ "$w.OR.0.walletId.in": justWallet ? void 0 : walletIds,
97
+ "$w.OR.1.toWalletId.in": justWallet ? void 0 : walletIds,
98
+ "$w.OR.2.userId": justWallet ? void 0 : userId.value,
99
+ "$w.OR.0.walletId": justWallet ? walletIds : void 0,
100
+ "$w.OR.1.toWalletId": justWallet ? walletIds : void 0,
101
+ "$w.status:not": "PENDING",
102
+ "$i.gateway.$i.gateway": true,
103
+ "$i.gateway.$i.coin": true,
104
+ "$i.wallet.$i.coin": true,
105
+ "$i.toWallet.$i.coin": true,
106
+ "$o.createdAt": "desc",
107
+ "$i.wallet.$i.user.$i.profile": true,
108
+ "$i.toWallet.$i.user.$i.profile": true
109
+ }
110
+ });
111
+ return result;
112
+ };
113
+ export const saveUser = async (user) => {
114
+ let res;
115
+ const userId = useUserId();
116
+ res = await usePut(`/user/${userId.value}`, user, { headers: { "no-error": true } });
117
+ await getUserInfo();
118
+ return res.result;
119
+ };
120
+ export const saveProfile = async (profile) => {
121
+ let res;
122
+ const user = useUser();
123
+ if (!profile.id) {
124
+ res = await usePost("/profile", profile);
125
+ } else {
126
+ res = await usePut(`/profile/${profile.id}`, profile);
127
+ }
128
+ _set(user.value, "profile", res.result);
129
+ return res.result;
130
+ };
131
+ export const saveWithdraw = async (withdraw) => {
132
+ const { result: res } = await usePost(`/WithdrawRequest`, withdraw);
133
+ return res;
134
+ };
135
+ export const cancelRequest = async (request) => {
136
+ const { $toast } = useNuxtApp();
137
+ const sure = confirm("\u0622\u06CC\u0627 \u0627\u0632 \u0644\u063A\u0648 \u062F\u0631\u062E\u0648\u0627\u0633\u062A \u062E\u0648\u062F \u0645\u0637\u0645\u0626\u0646 \u0647\u0633\u062A\u06CC\u062F\u061F");
138
+ if (sure) {
139
+ const { result } = await usePut(`/WithdrawRequest/${request.id}`, {
140
+ status: "CANCELLED"
141
+ });
142
+ if (result) {
143
+ $toast.success("\u062F\u0631\u062E\u0648\u0627\u0633\u062A \u0634\u0645\u0627 \u0628\u0627 \u0645\u0648\u0641\u0642\u06CC\u062A \u0644\u063A\u0648 \u0634\u062F.");
144
+ return result;
145
+ }
146
+ }
147
+ return null;
148
+ };
149
+ export const verifyPayment = async (txId = "") => {
150
+ const route = useRoute();
151
+ const { result } = await useGet(`/transaction/${txId || route.query.txId}`);
152
+ if (result) {
153
+ if (["SUCCESS", "ACCEPTED"].includes(result.status || "")) {
154
+ if (result.trade) {
155
+ return {
156
+ trx: result,
157
+ status: true,
158
+ message: "\u0645\u0639\u0627\u0645\u0644\u0647 \u062B\u0628\u062A \u0634\u062F"
159
+ };
160
+ }
161
+ } else {
162
+ return {
163
+ trx: result,
164
+ status: false,
165
+ message: "\u062A\u0631\u0627\u06A9\u0646\u0634 \u0646\u0627\u0645\u0648\u0641\u0642 \u0627\u0633\u062A"
166
+ };
167
+ }
168
+ } else {
169
+ return {
170
+ trx: result,
171
+ status: false,
172
+ message: "\u0634\u0646\u0627\u0633\u0647 \u062A\u0631\u0627\u06A9\u0646\u0634 \u0646\u0627\u0645\u0639\u062A\u0628\u0631 \u0627\u0633\u062A"
173
+ };
174
+ }
175
+ };
176
+ export const submitInviteCode = async (code) => {
177
+ if (!code) return;
178
+ const inviteCode = useCookie("inviteCode");
179
+ const { $toast } = useNuxtApp();
180
+ const { result: supervisor } = await useGet(`/user/inviteCode/${code}`);
181
+ if (supervisor?.id) {
182
+ await saveUser({ supervisorCode: code });
183
+ $toast.success("\u06A9\u062F \u0645\u0639\u0631\u0641 \u062B\u0628\u062A \u0634\u062F.");
184
+ }
185
+ };
186
+ export const normalizePersian = (text) => text.replace(/ي/g, "\u06CC").replace(/ك/g, "\u06A9").replace(/ؤ/g, "\u0648").replace(/ئ/g, "\u06CC");
187
+ export const unNormalizePersian = (text) => text.replace(/ی/g, "\u064A").replace(/ک/g, "\u0643").replace(/و/g, "\u0624").replace(/ی/g, "\u0626");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsource/ui",
3
- "version": "2.2.4",
3
+ "version": "2.3.0",
4
4
  "private": false,
5
5
  "description": "nuxt ui kit for unsource env",
6
6
  "repository": "https://github.com/alisa2142/unsource-ui",