feeef 0.0.27 → 0.1.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/LICENSE.md +9 -0
- package/README.md +50 -2
- package/build/index.d.ts +1 -0
- package/build/index.js +632 -0
- package/build/index.js.map +1 -0
- package/build/src/core/embadded/address.d.ts +13 -0
- package/build/src/core/embadded/category.d.ts +7 -0
- package/build/src/core/embadded/contact.d.ts +22 -0
- package/build/src/core/entities/order.d.ts +76 -0
- package/build/src/core/entities/product.d.ts +71 -0
- package/build/src/core/entities/shipping_method.d.ts +29 -0
- package/build/src/core/entities/store.d.ts +125 -0
- package/build/src/core/entities/user.d.ts +28 -0
- package/build/src/feeef/feeef.d.ts +66 -0
- package/build/src/feeef/repositories/orders.d.ts +21 -0
- package/build/src/feeef/repositories/products.d.ts +15 -0
- package/build/src/feeef/repositories/repository.d.ts +112 -0
- package/build/src/feeef/repositories/stores.d.ts +21 -0
- package/build/src/feeef/repositories/users.d.ts +51 -0
- package/build/src/feeef/validators/auth.d.ts +76 -0
- package/build/src/feeef/validators/custom/datetime.d.ts +1 -0
- package/build/src/feeef/validators/helpers.d.ts +148 -0
- package/build/src/feeef/validators/order.d.ts +366 -0
- package/build/src/feeef/validators/product.d.ts +595 -0
- package/build/src/feeef/validators/shipping_method.d.ts +112 -0
- package/build/src/feeef/validators/stores.d.ts +590 -0
- package/build/src/feeef/validators/user_stores.d.ts +623 -0
- package/build/src/feeef/validators/users.d.ts +98 -0
- package/build/src/index.d.ts +10 -0
- package/package.json +114 -18
- package/.eslintrc.cjs +0 -19
- package/src/core/core.ts +0 -12
- package/src/core/embadded/address.ts +0 -13
- package/src/core/embadded/category.ts +0 -7
- package/src/core/embadded/contact.ts +0 -25
- package/src/core/entities/order.ts +0 -79
- package/src/core/entities/product.ts +0 -108
- package/src/core/entities/shipping_method.ts +0 -32
- package/src/core/entities/store.ts +0 -155
- package/src/core/entities/user.ts +0 -30
- package/src/feeef/feeef.ts +0 -110
- package/src/feeef/repositories/orders.ts +0 -37
- package/src/feeef/repositories/products.ts +0 -25
- package/src/feeef/repositories/repository.ts +0 -175
- package/src/feeef/repositories/stores.ts +0 -39
- package/src/feeef/repositories/users.ts +0 -92
- package/src/feeef/validators/auth.ts +0 -50
- package/src/feeef/validators/custom/datetime.ts +0 -9
- package/src/feeef/validators/helpers.ts +0 -69
- package/src/feeef/validators/order.ts +0 -89
- package/src/feeef/validators/product.ts +0 -95
- package/src/feeef/validators/shipping_method.ts +0 -44
- package/src/feeef/validators/stores.ts +0 -101
- package/src/feeef/validators/user_stores.ts +0 -85
- package/src/feeef/validators/users.ts +0 -69
- package/src/index.ts +0 -2
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -24
- package/tsconfig.node.json +0 -10
- package/vite.config.ts +0 -6
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { EmbaddedAddress } from "../embadded/address.js";
|
|
2
|
-
import { EmbaddedCategory } from "../embadded/category.js";
|
|
3
|
-
import { EmbaddedContact } from "../embadded/contact.js";
|
|
4
|
-
// import { OrderEntity } from "./order.js";
|
|
5
|
-
// import { ShippingMethodEntity } from "./shipping_method.js";
|
|
6
|
-
import { UserEntity } from "./user.js";
|
|
7
|
-
import { DateTime } from "luxon";
|
|
8
|
-
|
|
9
|
-
export interface StoreEntity {
|
|
10
|
-
id: string;
|
|
11
|
-
slug: string;
|
|
12
|
-
banner: StoreBanner | null;
|
|
13
|
-
action: StoreAction | null;
|
|
14
|
-
domain: StoreDomain | null;
|
|
15
|
-
decoration: StoreDecoration | null;
|
|
16
|
-
name: string;
|
|
17
|
-
logoUrl: string | null;
|
|
18
|
-
ondarkLogoUrl: string | null;
|
|
19
|
-
userId: string;
|
|
20
|
-
categories: EmbaddedCategory[];
|
|
21
|
-
title: string | null;
|
|
22
|
-
description: string | null;
|
|
23
|
-
addresses: EmbaddedAddress[];
|
|
24
|
-
metadata: Record<string, any>;
|
|
25
|
-
contacts: EmbaddedContact[];
|
|
26
|
-
integrations: StoreIntegrations;
|
|
27
|
-
verifiedAt: any | null;
|
|
28
|
-
blockedAt: any | null;
|
|
29
|
-
createdAt: any;
|
|
30
|
-
updatedAt: any;
|
|
31
|
-
// products: ProductEntity[];
|
|
32
|
-
user?: UserEntity;
|
|
33
|
-
// orders: OrderEntity[];
|
|
34
|
-
// shippingMethods: ShippingMethodEntity[];
|
|
35
|
-
defaultShippingRates: (number | null)[][] | null;
|
|
36
|
-
|
|
37
|
-
// subscription
|
|
38
|
-
subscription?: any;
|
|
39
|
-
due?: number;
|
|
40
|
-
|
|
41
|
-
// StoreConfigs
|
|
42
|
-
configs?: StoreConfigs;
|
|
43
|
-
|
|
44
|
-
// metaPixelIds
|
|
45
|
-
metaPixelIds?: string[];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface StoreConfigs {
|
|
49
|
-
currencies: StoreCurrencyConfig[];
|
|
50
|
-
defaultCurrency: number;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface StoreCurrencyConfig {
|
|
54
|
-
code: string;
|
|
55
|
-
symbol: string;
|
|
56
|
-
precision: number;
|
|
57
|
-
rate: number;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface StoreDomain {
|
|
61
|
-
name: string;
|
|
62
|
-
verifiedAt: any | null;
|
|
63
|
-
metadata: Record<string, any>;
|
|
64
|
-
}
|
|
65
|
-
export interface StoreBanner {
|
|
66
|
-
title: string;
|
|
67
|
-
url?: string | null;
|
|
68
|
-
enabled: boolean;
|
|
69
|
-
metadata: Record<string, any>;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface StoreDecoration {
|
|
73
|
-
primary: number;
|
|
74
|
-
onPrimary?: number;
|
|
75
|
-
showStoreLogoInHeader?: boolean;
|
|
76
|
-
logoFullHeight?: boolean;
|
|
77
|
-
showStoreNameInHeader?: boolean;
|
|
78
|
-
metadata?: Record<string, any>;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface StoreAction {
|
|
82
|
-
label: string;
|
|
83
|
-
url: string;
|
|
84
|
-
type: StoreActionType;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export enum StoreActionType {
|
|
88
|
-
link = "link",
|
|
89
|
-
whatsapp = "whatsapp",
|
|
90
|
-
telegram = "telegram",
|
|
91
|
-
phone = "phone",
|
|
92
|
-
}
|
|
93
|
-
export interface MetaPixel {
|
|
94
|
-
id: string;
|
|
95
|
-
key?: string;
|
|
96
|
-
}
|
|
97
|
-
export interface MetaPixelIntegration {
|
|
98
|
-
id: string;
|
|
99
|
-
pixels: MetaPixel[];
|
|
100
|
-
active: boolean;
|
|
101
|
-
metadata: Record<string, any>;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface StoreIntegrations {
|
|
105
|
-
[key: string]: any;
|
|
106
|
-
metadata?: Record<string, any>;
|
|
107
|
-
|
|
108
|
-
// @Default('default') String id,
|
|
109
|
-
// @Default([]) List<MetaPixel> pixels,
|
|
110
|
-
// @Default(true) bool active,
|
|
111
|
-
// @Default({}) Map<String, dynamic> metadata,
|
|
112
|
-
metaPixel?: MetaPixelIntegration;
|
|
113
|
-
googleAnalytics?: any;
|
|
114
|
-
googleSheet?: any;
|
|
115
|
-
sms?: any;
|
|
116
|
-
telegram?: any;
|
|
117
|
-
yalidine?: any;
|
|
118
|
-
maystroDelivery?: any;
|
|
119
|
-
echotrak?: any;
|
|
120
|
-
procolis?: any;
|
|
121
|
-
noest?: any;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export enum StoreSubscriptionStatus {
|
|
125
|
-
active = "active",
|
|
126
|
-
inactive = "inactive",
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export enum StoreSubscriptionType {
|
|
130
|
-
free = "free",
|
|
131
|
-
quota = "quota",
|
|
132
|
-
percentage = "percentage",
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export interface StoreSubscription {
|
|
136
|
-
type: StoreSubscriptionType;
|
|
137
|
-
status: StoreSubscriptionStatus;
|
|
138
|
-
startedAt: DateTime;
|
|
139
|
-
expiresAt: DateTime | null;
|
|
140
|
-
metadata: Record<string, any>;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export interface StoreFreeSubscription extends StoreSubscription {
|
|
144
|
-
type: StoreSubscriptionType.free;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface StoreQuotaSubscription extends StoreSubscription {
|
|
148
|
-
type: StoreSubscriptionType.quota;
|
|
149
|
-
quota: number;
|
|
150
|
-
}
|
|
151
|
-
// another way is by taking percentage of the sales
|
|
152
|
-
export interface StorePercentageSubscription extends StoreSubscription {
|
|
153
|
-
type: StoreSubscriptionType.percentage;
|
|
154
|
-
percentage: number;
|
|
155
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface UserEntity {
|
|
2
|
-
id: string
|
|
3
|
-
name: string | null
|
|
4
|
-
email: string
|
|
5
|
-
phone: string
|
|
6
|
-
password: string
|
|
7
|
-
photoUrl: string | null
|
|
8
|
-
emailVerifiedAt: any | null
|
|
9
|
-
phoneVerifiedAt: any | null
|
|
10
|
-
verifiedAt: any | null
|
|
11
|
-
blockedAt: any | null
|
|
12
|
-
createdAt: any
|
|
13
|
-
updatedAt: any | null
|
|
14
|
-
metadata: Record<string, any>
|
|
15
|
-
wallet: EmbaddedWallet
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface EmbaddedWallet {
|
|
19
|
-
currency: 'DZD' | 'USD' | 'EUR'
|
|
20
|
-
balance: number
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface AuthToken {
|
|
24
|
-
type: string
|
|
25
|
-
name: string | null
|
|
26
|
-
token: string
|
|
27
|
-
abilities: string[]
|
|
28
|
-
lastUsedAt: any
|
|
29
|
-
expiresAt: any
|
|
30
|
-
}
|
package/src/feeef/feeef.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import axios, { AxiosInstance } from "axios";
|
|
2
|
-
import {
|
|
3
|
-
buildMemoryStorage,
|
|
4
|
-
buildWebStorage,
|
|
5
|
-
setupCache,
|
|
6
|
-
} from "axios-cache-interceptor";
|
|
7
|
-
import { OrderRepository } from "./repositories/orders";
|
|
8
|
-
import { ProductRepository } from "./repositories/products";
|
|
9
|
-
import { StoreRepository } from "./repositories/stores";
|
|
10
|
-
import { UserRepository } from "./repositories/users";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Configuration options for the FeeeF module.
|
|
14
|
-
*/
|
|
15
|
-
export interface FeeeFConfig {
|
|
16
|
-
/**
|
|
17
|
-
* The API key to be used for authentication.
|
|
18
|
-
*/
|
|
19
|
-
apiKey: string;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* An optional Axios instance to be used for making HTTP requests.
|
|
23
|
-
*/
|
|
24
|
-
client?: AxiosInstance;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Specifies whether caching should be enabled or disabled.
|
|
28
|
-
* If set to a number, it represents the maximum number of seconds to cache the responses.
|
|
29
|
-
* If set to `false`, caching will be disabled (5s).
|
|
30
|
-
* cannot be less than 5 seconds
|
|
31
|
-
*/
|
|
32
|
-
cache?: false | number;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The base URL for the API.
|
|
36
|
-
*/
|
|
37
|
-
baseURL?: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Represents the FeeeF class.
|
|
42
|
-
*/
|
|
43
|
-
export class FeeeF {
|
|
44
|
-
/**
|
|
45
|
-
* The API key used for authentication.
|
|
46
|
-
*/
|
|
47
|
-
apiKey: string;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The Axios instance used for making HTTP requests.
|
|
51
|
-
*/
|
|
52
|
-
client: AxiosInstance;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The repository for managing stores.
|
|
56
|
-
*/
|
|
57
|
-
stores: StoreRepository;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The repository for managing products.
|
|
61
|
-
*/
|
|
62
|
-
products: ProductRepository;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The repository for managing users.
|
|
66
|
-
*/
|
|
67
|
-
users: UserRepository;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The repository for managing orders.
|
|
71
|
-
*/
|
|
72
|
-
orders: OrderRepository;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Constructs a new instance of the FeeeF class.
|
|
76
|
-
* @param {FeeeFConfig} config - The configuration object.
|
|
77
|
-
* @param {string} config.apiKey - The API key used for authentication.
|
|
78
|
-
* @param {AxiosInstance} config.client - The Axios instance used for making HTTP requests.
|
|
79
|
-
* @param {boolean | number} config.cache - The caching configuration. Set to `false` to disable caching, or provide a number to set the cache TTL in milliseconds.
|
|
80
|
-
*/
|
|
81
|
-
constructor({
|
|
82
|
-
apiKey,
|
|
83
|
-
client,
|
|
84
|
-
cache,
|
|
85
|
-
baseURL = "http://localhost:3333/api/v1",
|
|
86
|
-
}: FeeeFConfig) {
|
|
87
|
-
this.apiKey = apiKey;
|
|
88
|
-
// get th "cache" search param
|
|
89
|
-
// if is 0 or false, disable cache
|
|
90
|
-
if (cache === false) {
|
|
91
|
-
this.client = client || axios;
|
|
92
|
-
} else {
|
|
93
|
-
const isInBrowser =
|
|
94
|
-
typeof window !== "undefined" && typeof localStorage !== "undefined";
|
|
95
|
-
this.client = setupCache(client || axios, {
|
|
96
|
-
ttl: cache === undefined ? 1000 * 60 * 5 : Math.max(cache!, 1000), //|| 1 * 60 * 1000, // 1 minute by default
|
|
97
|
-
// for persistent cache use buildWebStorage
|
|
98
|
-
storage: isInBrowser
|
|
99
|
-
? buildWebStorage(localStorage, "ff:")
|
|
100
|
-
: buildMemoryStorage(),
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
// set base url
|
|
104
|
-
this.client.defaults.baseURL = baseURL;
|
|
105
|
-
this.stores = new StoreRepository(this.client);
|
|
106
|
-
this.products = new ProductRepository(this.client);
|
|
107
|
-
this.users = new UserRepository(this.client);
|
|
108
|
-
this.orders = new OrderRepository(this.client);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import vine from "@vinejs/vine";
|
|
2
|
-
import { InferInput } from "@vinejs/vine/types";
|
|
3
|
-
import { AxiosInstance } from "axios";
|
|
4
|
-
import { OrderEntity } from "../../core/core";
|
|
5
|
-
import { CreateOrderSchema, SendOrderSchema } from "../validators/order";
|
|
6
|
-
import { ModelRepository } from "./repository";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Represents a repository for managing orders.
|
|
10
|
-
*/
|
|
11
|
-
export class OrderRepository extends ModelRepository<
|
|
12
|
-
OrderEntity,
|
|
13
|
-
InferInput<typeof CreateOrderSchema>,
|
|
14
|
-
InferInput<typeof CreateOrderSchema>
|
|
15
|
-
> {
|
|
16
|
-
/**
|
|
17
|
-
* Constructs a new OrderRepository instance.
|
|
18
|
-
* @param client - The AxiosInstance used for making HTTP requests.
|
|
19
|
-
*/
|
|
20
|
-
constructor(client: AxiosInstance) {
|
|
21
|
-
super("orders", client);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Sends an order from an anonymous user.
|
|
26
|
-
* @param data - The data representing the order to be sent.
|
|
27
|
-
* @returns A Promise that resolves to the sent OrderEntity.
|
|
28
|
-
*/
|
|
29
|
-
async send(data: InferInput<typeof SendOrderSchema>): Promise<OrderEntity> {
|
|
30
|
-
const validator = vine.compile(SendOrderSchema);
|
|
31
|
-
const output = await validator.validate(data);
|
|
32
|
-
const res = await this.client.post(`/${this.resource}/send`, output);
|
|
33
|
-
|
|
34
|
-
// Return the sent OrderEntity
|
|
35
|
-
return res.data;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { InferInput } from "@vinejs/vine/types";
|
|
2
|
-
import { AxiosInstance } from "axios";
|
|
3
|
-
import { ProductEntity } from "../../core/core";
|
|
4
|
-
import {
|
|
5
|
-
CreateProductSchema,
|
|
6
|
-
UpdateProductSchema,
|
|
7
|
-
} from "../validators/product";
|
|
8
|
-
import { ModelRepository } from "./repository";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Represents a repository for managing products.
|
|
12
|
-
*/
|
|
13
|
-
export class ProductRepository extends ModelRepository<
|
|
14
|
-
ProductEntity,
|
|
15
|
-
InferInput<typeof CreateProductSchema>,
|
|
16
|
-
InferInput<typeof UpdateProductSchema>
|
|
17
|
-
> {
|
|
18
|
-
/**
|
|
19
|
-
* Creates a new instance of the ProductRepository class.
|
|
20
|
-
* @param client - The AxiosInstance used for making HTTP requests.
|
|
21
|
-
*/
|
|
22
|
-
constructor(client: AxiosInstance) {
|
|
23
|
-
super("products", client);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a generic model repository.
|
|
5
|
-
* @template T - The type of the model.
|
|
6
|
-
* @template C - The type of the create options.
|
|
7
|
-
* @template U - The type of the update options.
|
|
8
|
-
*/
|
|
9
|
-
export abstract class ModelRepository<T, C, U> {
|
|
10
|
-
resource: string;
|
|
11
|
-
// client
|
|
12
|
-
client: AxiosInstance;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Constructs a new instance of the ModelRepository class.
|
|
16
|
-
* @param resource - The resource name.
|
|
17
|
-
* @param client - The Axios instance used for making HTTP requests.
|
|
18
|
-
*/
|
|
19
|
-
constructor(resource: string, client: AxiosInstance) {
|
|
20
|
-
this.resource = resource;
|
|
21
|
-
this.client = client;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Finds a model by its ID or other criteria.
|
|
26
|
-
* @param options - The options for finding the model.
|
|
27
|
-
* @returns A promise that resolves to the found model.
|
|
28
|
-
*/
|
|
29
|
-
async find(options: ModelFindOptions): Promise<T> {
|
|
30
|
-
const { id, by, params } = options;
|
|
31
|
-
const res = await this.client.get(`/${this.resource}/${id}`, {
|
|
32
|
-
params: {
|
|
33
|
-
by: by || "id",
|
|
34
|
-
...params,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return res.data;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Lists models with optional pagination and filtering.
|
|
42
|
-
* @param options - The options for listing the models.
|
|
43
|
-
* @returns A promise that resolves to a list of models.
|
|
44
|
-
*/
|
|
45
|
-
async list(options?: ModelListOptions): Promise<ListResponse<T>> {
|
|
46
|
-
const { page, offset, limit, params } = options || {};
|
|
47
|
-
const res = await this.client.get(`/${this.resource}`, {
|
|
48
|
-
params: { page, offset, limit, ...params },
|
|
49
|
-
});
|
|
50
|
-
// if res.data is an array then create ListResponse
|
|
51
|
-
if (Array.isArray(res.data)) {
|
|
52
|
-
return {
|
|
53
|
-
data: res.data,
|
|
54
|
-
};
|
|
55
|
-
} else {
|
|
56
|
-
return {
|
|
57
|
-
data: res.data.data,
|
|
58
|
-
total: res.data.meta.total,
|
|
59
|
-
page: res.data.meta.currentPage,
|
|
60
|
-
limit: res.data.meta.perPage,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Creates a new model.
|
|
67
|
-
* @param options - The options for creating the model.
|
|
68
|
-
* @returns A promise that resolves to the created model.
|
|
69
|
-
*/
|
|
70
|
-
async create(options: ModelCreateOptions<C>): Promise<T> {
|
|
71
|
-
const { data, params } = options;
|
|
72
|
-
const res = await this.client.post(`/${this.resource}`, data, { params });
|
|
73
|
-
return res.data;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Updates an existing model.
|
|
78
|
-
* @param options - The options for updating the model.
|
|
79
|
-
* @returns A promise that resolves to the updated model.
|
|
80
|
-
*/
|
|
81
|
-
async update(options: ModelUpdateOptions<U>): Promise<T> {
|
|
82
|
-
const { id, data, params } = options;
|
|
83
|
-
const res = await this.client.put(`/${this.resource}/${id}`, data, {
|
|
84
|
-
params,
|
|
85
|
-
});
|
|
86
|
-
return res.data;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Deletes a model by its ID or other criteria.
|
|
91
|
-
* @param options - The options for deleting the model.
|
|
92
|
-
* @returns A promise that resolves when the model is deleted.
|
|
93
|
-
*/
|
|
94
|
-
async delete(options: ModelFindOptions): Promise<void> {
|
|
95
|
-
const { id, by, params } = options;
|
|
96
|
-
await this.client.delete(`/${this.resource}/${id}`, {
|
|
97
|
-
params: {
|
|
98
|
-
by: by || "id",
|
|
99
|
-
...params,
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Represents a list response containing an array of data of type T.
|
|
107
|
-
*/
|
|
108
|
-
export interface ListResponse<T> {
|
|
109
|
-
data: T[];
|
|
110
|
-
total?: number;
|
|
111
|
-
page?: number;
|
|
112
|
-
limit?: number;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Represents the options for making a request.
|
|
117
|
-
*/
|
|
118
|
-
interface RequestOptions {
|
|
119
|
-
params?: Record<string, any>;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export interface ModelFindOptions extends RequestOptions {
|
|
123
|
-
/**
|
|
124
|
-
* The ID of the model to find or the value to find by.
|
|
125
|
-
*/
|
|
126
|
-
id: string;
|
|
127
|
-
/**
|
|
128
|
-
* The field to find by.
|
|
129
|
-
* @default "id" - The ID field.
|
|
130
|
-
*/
|
|
131
|
-
by?: string;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Options for listing models.
|
|
136
|
-
*/
|
|
137
|
-
export interface ModelListOptions extends RequestOptions {
|
|
138
|
-
/**
|
|
139
|
-
* The page number to retrieve.
|
|
140
|
-
*/
|
|
141
|
-
page?: number;
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* The offset from the beginning of the list.
|
|
145
|
-
*/
|
|
146
|
-
offset?: number;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* The maximum number of models to retrieve per page.
|
|
150
|
-
*/
|
|
151
|
-
limit?: number;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Represents the options for creating a model.
|
|
156
|
-
* @template T - The type of data being created.
|
|
157
|
-
*/
|
|
158
|
-
export interface ModelCreateOptions<T> extends RequestOptions {
|
|
159
|
-
data: T;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Represents the options for updating a model.
|
|
164
|
-
* @template T - The type of the data being updated.
|
|
165
|
-
*/
|
|
166
|
-
export interface ModelUpdateOptions<T> extends RequestOptions {
|
|
167
|
-
/**
|
|
168
|
-
* The ID of the model to update.
|
|
169
|
-
*/
|
|
170
|
-
id: string;
|
|
171
|
-
/**
|
|
172
|
-
* The data to update the model with.
|
|
173
|
-
*/
|
|
174
|
-
data: T;
|
|
175
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import vine from "@vinejs/vine";
|
|
2
|
-
import { InferInput } from "@vinejs/vine/types";
|
|
3
|
-
import { AxiosInstance } from "axios";
|
|
4
|
-
import { StoreEntity } from "../../core/core";
|
|
5
|
-
import {
|
|
6
|
-
CreateUserStoreSchema,
|
|
7
|
-
UpdateUserStoreSchema,
|
|
8
|
-
} from "../validators/user_stores";
|
|
9
|
-
import { ModelRepository, ModelCreateOptions } from "./repository";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Repository for managing Store entities.
|
|
13
|
-
*/
|
|
14
|
-
export class StoreRepository extends ModelRepository<
|
|
15
|
-
StoreEntity,
|
|
16
|
-
InferInput<typeof CreateUserStoreSchema>,
|
|
17
|
-
InferInput<typeof UpdateUserStoreSchema>
|
|
18
|
-
> {
|
|
19
|
-
/**
|
|
20
|
-
* Constructs a new StoreRepository instance.
|
|
21
|
-
* @param client The AxiosInstance used for making HTTP requests.
|
|
22
|
-
*/
|
|
23
|
-
constructor(client: AxiosInstance) {
|
|
24
|
-
super("stores", client);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Creates a new Store entity.
|
|
29
|
-
* @param options The options for creating the Store entity.
|
|
30
|
-
* @returns A Promise that resolves to the created Store entity.
|
|
31
|
-
*/
|
|
32
|
-
async create(
|
|
33
|
-
options: ModelCreateOptions<InferInput<typeof CreateUserStoreSchema>>
|
|
34
|
-
): Promise<StoreEntity> {
|
|
35
|
-
const validator = vine.compile(CreateUserStoreSchema);
|
|
36
|
-
const output = await validator.validate(options.data);
|
|
37
|
-
return super.create({ ...options, data: output });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import vine from "@vinejs/vine";
|
|
2
|
-
import { InferInput } from "@vinejs/vine/types";
|
|
3
|
-
import { AxiosInstance } from "axios";
|
|
4
|
-
import { AuthToken, UserEntity } from "../../core/core";
|
|
5
|
-
import { SigninSchema, AuthUpdateUserSchema } from "../validators/auth";
|
|
6
|
-
import { CreateUserSchema, UpdateUserSchema } from "../validators/users";
|
|
7
|
-
import { ModelRepository } from "./repository";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Represents the response returned by the authentication process.
|
|
11
|
-
*/
|
|
12
|
-
export interface AuthResponse {
|
|
13
|
-
token: AuthToken;
|
|
14
|
-
user: UserEntity;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Represents a repository for managing user data.
|
|
19
|
-
* Extends the ModelRepository class.
|
|
20
|
-
*/
|
|
21
|
-
export class UserRepository extends ModelRepository<
|
|
22
|
-
UserEntity,
|
|
23
|
-
InferInput<typeof CreateUserSchema>,
|
|
24
|
-
InferInput<typeof UpdateUserSchema>
|
|
25
|
-
> {
|
|
26
|
-
/**
|
|
27
|
-
* Represents the authentication response.
|
|
28
|
-
*/
|
|
29
|
-
auth: AuthResponse | null = null;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Constructs a new UserRepository instance.
|
|
33
|
-
* @param client - The AxiosInstance used for making HTTP requests.
|
|
34
|
-
*/
|
|
35
|
-
constructor(client: AxiosInstance) {
|
|
36
|
-
super("users", client);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Signs in a user with the provided credentials.
|
|
41
|
-
* @param credentials - The user credentials.
|
|
42
|
-
* @returns A promise that resolves to the authentication response.
|
|
43
|
-
*/
|
|
44
|
-
async signin(
|
|
45
|
-
credentials: InferInput<typeof SigninSchema>
|
|
46
|
-
): Promise<AuthResponse> {
|
|
47
|
-
// validate the input
|
|
48
|
-
const validator = vine.compile(SigninSchema);
|
|
49
|
-
const output = await validator.validate(credentials);
|
|
50
|
-
const res = await this.client.post(`/${this.resource}/auth/signin`, output);
|
|
51
|
-
this.auth = res.data;
|
|
52
|
-
return res.data;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Signs up a new user with the provided credentials.
|
|
57
|
-
* @param credentials - The user credentials.
|
|
58
|
-
* @returns A promise that resolves to the authentication response.
|
|
59
|
-
*/
|
|
60
|
-
async signup(
|
|
61
|
-
credentials: InferInput<typeof CreateUserSchema>
|
|
62
|
-
): Promise<AuthResponse> {
|
|
63
|
-
// validate the input
|
|
64
|
-
const validator = vine.compile(CreateUserSchema);
|
|
65
|
-
const output = await validator.validate(credentials);
|
|
66
|
-
const res = await this.client.post(`/${this.resource}/auth/signup`, output);
|
|
67
|
-
this.auth = res.data;
|
|
68
|
-
return res.data;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Signs out the currently authenticated user.
|
|
73
|
-
* @returns A promise that resolves when the user is signed out.
|
|
74
|
-
*/
|
|
75
|
-
async signout(): Promise<void> {
|
|
76
|
-
this.auth = null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Updates the authenticated user's data.
|
|
81
|
-
* @param data - The updated user data.
|
|
82
|
-
* @returns A promise that resolves to the updated user entity.
|
|
83
|
-
*/
|
|
84
|
-
async updateMe(
|
|
85
|
-
data: InferInput<typeof AuthUpdateUserSchema>
|
|
86
|
-
): Promise<UserEntity> {
|
|
87
|
-
const validator = vine.compile(AuthUpdateUserSchema);
|
|
88
|
-
const output = await validator.validate(data);
|
|
89
|
-
const res = await this.client.put(`/${this.resource}/auth`, output);
|
|
90
|
-
return res.data;
|
|
91
|
-
}
|
|
92
|
-
}
|