@abella-bilhalba-engenharia/api-client 0.0.1 → 0.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.
- package/dist/index.cjs +152 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +109 -0
- package/package.json +1 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
authorizationHeader: () => authorizationHeader,
|
|
34
|
+
commonResponses: () => commonResponses,
|
|
35
|
+
commonResponsesBodySchema: () => commonResponsesBodySchema,
|
|
36
|
+
detailedUnitSchema: () => detailedUnitSchema,
|
|
37
|
+
moneySchema: () => moneySchema,
|
|
38
|
+
solarUnitContract: () => solarUnitContract,
|
|
39
|
+
unitSchema: () => unitSchema
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
|
|
43
|
+
// src/schemas.ts
|
|
44
|
+
var import_zod = __toESM(require("zod"), 1);
|
|
45
|
+
var authorizationHeader = import_zod.default.string().startsWith("Bearer ");
|
|
46
|
+
var commonResponsesBodySchema = {
|
|
47
|
+
unauthorized: import_zod.default.object({
|
|
48
|
+
error: import_zod.default.object({
|
|
49
|
+
type: import_zod.default.literal("UNAUTHORIZED"),
|
|
50
|
+
message: import_zod.default.string().default("").optional()
|
|
51
|
+
})
|
|
52
|
+
}),
|
|
53
|
+
entityNotFound: import_zod.default.object({
|
|
54
|
+
error: import_zod.default.object({
|
|
55
|
+
type: import_zod.default.literal("ENTITY_NOT_FOUND"),
|
|
56
|
+
entity: import_zod.default.string(),
|
|
57
|
+
message: import_zod.default.string().default("").optional()
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
entityAlreadyExists: import_zod.default.object({
|
|
61
|
+
error: import_zod.default.object({
|
|
62
|
+
type: import_zod.default.literal("ENTITY_ALREADY_EXISTS"),
|
|
63
|
+
entity: import_zod.default.string(),
|
|
64
|
+
message: import_zod.default.string().default("").optional()
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
internalServerError: import_zod.default.object({
|
|
68
|
+
error: import_zod.default.object({
|
|
69
|
+
type: import_zod.default.literal("INTERNAL_SERVER_ERROR"),
|
|
70
|
+
message: import_zod.default.string().default("").optional()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
var commonResponses = {
|
|
75
|
+
401: commonResponsesBodySchema.unauthorized,
|
|
76
|
+
404: commonResponsesBodySchema.entityNotFound,
|
|
77
|
+
409: commonResponsesBodySchema.entityAlreadyExists,
|
|
78
|
+
500: commonResponsesBodySchema.internalServerError
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/contracts/auth.contract.ts
|
|
82
|
+
var import_core = require("@ts-rest/core");
|
|
83
|
+
var import_zod2 = __toESM(require("zod"), 1);
|
|
84
|
+
var c = (0, import_core.initContract)();
|
|
85
|
+
var moneySchema = import_zod2.default.object({
|
|
86
|
+
format: import_zod2.default.string(),
|
|
87
|
+
value: import_zod2.default.number(),
|
|
88
|
+
unit: import_zod2.default.enum(["BRL"])
|
|
89
|
+
});
|
|
90
|
+
var unitSchema = import_zod2.default.object({
|
|
91
|
+
name: import_zod2.default.string(),
|
|
92
|
+
uuid: import_zod2.default.uuidv7(),
|
|
93
|
+
installationDate: import_zod2.default.date()
|
|
94
|
+
});
|
|
95
|
+
var detailedUnitSchema = unitSchema.extend({
|
|
96
|
+
equipments: import_zod2.default.object({
|
|
97
|
+
inverter: import_zod2.default.string(),
|
|
98
|
+
panels: import_zod2.default.array(
|
|
99
|
+
import_zod2.default.object({
|
|
100
|
+
model: import_zod2.default.string(),
|
|
101
|
+
quantity: import_zod2.default.number().positive()
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
}),
|
|
105
|
+
economies: import_zod2.default.array(
|
|
106
|
+
import_zod2.default.object({
|
|
107
|
+
date: import_zod2.default.date(),
|
|
108
|
+
valueWouldBe: moneySchema,
|
|
109
|
+
valuePaid: moneySchema,
|
|
110
|
+
economy: moneySchema,
|
|
111
|
+
economyAccumulated: moneySchema
|
|
112
|
+
})
|
|
113
|
+
).optional()
|
|
114
|
+
});
|
|
115
|
+
var solarUnitContract = c.router({
|
|
116
|
+
list: {
|
|
117
|
+
method: "GET",
|
|
118
|
+
path: "/solar/units",
|
|
119
|
+
headers: import_zod2.default.object({
|
|
120
|
+
authorization: authorizationHeader
|
|
121
|
+
}),
|
|
122
|
+
responses: {
|
|
123
|
+
200: import_zod2.default.object({
|
|
124
|
+
data: import_zod2.default.array(unitSchema)
|
|
125
|
+
})
|
|
126
|
+
},
|
|
127
|
+
summary: "List all units"
|
|
128
|
+
},
|
|
129
|
+
show: {
|
|
130
|
+
method: "GET",
|
|
131
|
+
path: "/solar/units/:uuid",
|
|
132
|
+
pathParams: import_zod2.default.object({
|
|
133
|
+
uuid: import_zod2.default.uuidv7()
|
|
134
|
+
}),
|
|
135
|
+
responses: {
|
|
136
|
+
200: import_zod2.default.object({
|
|
137
|
+
data: detailedUnitSchema
|
|
138
|
+
})
|
|
139
|
+
},
|
|
140
|
+
summary: "Show an unit by an UUID"
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
authorizationHeader,
|
|
146
|
+
commonResponses,
|
|
147
|
+
commonResponsesBodySchema,
|
|
148
|
+
detailedUnitSchema,
|
|
149
|
+
moneySchema,
|
|
150
|
+
solarUnitContract,
|
|
151
|
+
unitSchema
|
|
152
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const authorizationHeader: z.ZodString;
|
|
4
|
+
declare const commonResponsesBodySchema: {
|
|
5
|
+
unauthorized: z.ZodObject<{
|
|
6
|
+
error: z.ZodObject<{
|
|
7
|
+
type: z.ZodLiteral<"UNAUTHORIZED">;
|
|
8
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
entityNotFound: z.ZodObject<{
|
|
12
|
+
error: z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"ENTITY_NOT_FOUND">;
|
|
14
|
+
entity: z.ZodString;
|
|
15
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
entityAlreadyExists: z.ZodObject<{
|
|
19
|
+
error: z.ZodObject<{
|
|
20
|
+
type: z.ZodLiteral<"ENTITY_ALREADY_EXISTS">;
|
|
21
|
+
entity: z.ZodString;
|
|
22
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
internalServerError: z.ZodObject<{
|
|
26
|
+
error: z.ZodObject<{
|
|
27
|
+
type: z.ZodLiteral<"INTERNAL_SERVER_ERROR">;
|
|
28
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
};
|
|
32
|
+
declare const commonResponses: {
|
|
33
|
+
401: z.ZodObject<{
|
|
34
|
+
error: z.ZodObject<{
|
|
35
|
+
type: z.ZodLiteral<"UNAUTHORIZED">;
|
|
36
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
404: z.ZodObject<{
|
|
40
|
+
error: z.ZodObject<{
|
|
41
|
+
type: z.ZodLiteral<"ENTITY_NOT_FOUND">;
|
|
42
|
+
entity: z.ZodString;
|
|
43
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
409: z.ZodObject<{
|
|
47
|
+
error: z.ZodObject<{
|
|
48
|
+
type: z.ZodLiteral<"ENTITY_ALREADY_EXISTS">;
|
|
49
|
+
entity: z.ZodString;
|
|
50
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
500: z.ZodObject<{
|
|
54
|
+
error: z.ZodObject<{
|
|
55
|
+
type: z.ZodLiteral<"INTERNAL_SERVER_ERROR">;
|
|
56
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
};
|
|
60
|
+
type CommonResponsesType = {
|
|
61
|
+
[K in keyof typeof commonResponses]: {
|
|
62
|
+
status: K;
|
|
63
|
+
body: z.infer<(typeof commonResponses)[K]>;
|
|
64
|
+
};
|
|
65
|
+
}[keyof typeof commonResponses];
|
|
66
|
+
type CommonResponseType<T extends keyof typeof commonResponses> = {
|
|
67
|
+
status: T;
|
|
68
|
+
body: z.infer<(typeof commonResponses)[T]>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
declare const moneySchema: z.ZodObject<{
|
|
72
|
+
format: z.ZodString;
|
|
73
|
+
value: z.ZodNumber;
|
|
74
|
+
unit: z.ZodEnum<{
|
|
75
|
+
BRL: "BRL";
|
|
76
|
+
}>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
declare const unitSchema: z.ZodObject<{
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
uuid: z.ZodUUID;
|
|
81
|
+
installationDate: z.ZodDate;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
declare const detailedUnitSchema: z.ZodObject<{
|
|
84
|
+
name: z.ZodString;
|
|
85
|
+
uuid: z.ZodUUID;
|
|
86
|
+
installationDate: z.ZodDate;
|
|
87
|
+
equipments: z.ZodObject<{
|
|
88
|
+
inverter: z.ZodString;
|
|
89
|
+
panels: z.ZodArray<z.ZodObject<{
|
|
90
|
+
model: z.ZodString;
|
|
91
|
+
quantity: z.ZodNumber;
|
|
92
|
+
}, z.core.$strip>>;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
economies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
95
|
+
date: z.ZodDate;
|
|
96
|
+
valueWouldBe: z.ZodObject<{
|
|
97
|
+
format: z.ZodString;
|
|
98
|
+
value: z.ZodNumber;
|
|
99
|
+
unit: z.ZodEnum<{
|
|
100
|
+
BRL: "BRL";
|
|
101
|
+
}>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
valuePaid: z.ZodObject<{
|
|
104
|
+
format: z.ZodString;
|
|
105
|
+
value: z.ZodNumber;
|
|
106
|
+
unit: z.ZodEnum<{
|
|
107
|
+
BRL: "BRL";
|
|
108
|
+
}>;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
economy: z.ZodObject<{
|
|
111
|
+
format: z.ZodString;
|
|
112
|
+
value: z.ZodNumber;
|
|
113
|
+
unit: z.ZodEnum<{
|
|
114
|
+
BRL: "BRL";
|
|
115
|
+
}>;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
economyAccumulated: z.ZodObject<{
|
|
118
|
+
format: z.ZodString;
|
|
119
|
+
value: z.ZodNumber;
|
|
120
|
+
unit: z.ZodEnum<{
|
|
121
|
+
BRL: "BRL";
|
|
122
|
+
}>;
|
|
123
|
+
}, z.core.$strip>;
|
|
124
|
+
}, z.core.$strip>>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
declare const solarUnitContract: {
|
|
127
|
+
list: {
|
|
128
|
+
summary: "List all units";
|
|
129
|
+
method: "GET";
|
|
130
|
+
headers: z.ZodObject<{
|
|
131
|
+
authorization: z.ZodString;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
path: "/solar/units";
|
|
134
|
+
responses: {
|
|
135
|
+
200: z.ZodObject<{
|
|
136
|
+
data: z.ZodArray<z.ZodObject<{
|
|
137
|
+
name: z.ZodString;
|
|
138
|
+
uuid: z.ZodUUID;
|
|
139
|
+
installationDate: z.ZodDate;
|
|
140
|
+
}, z.core.$strip>>;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
show: {
|
|
145
|
+
pathParams: z.ZodObject<{
|
|
146
|
+
uuid: z.ZodUUID;
|
|
147
|
+
}, z.core.$strip>;
|
|
148
|
+
summary: "Show an unit by an UUID";
|
|
149
|
+
method: "GET";
|
|
150
|
+
path: "/solar/units/:uuid";
|
|
151
|
+
responses: {
|
|
152
|
+
200: z.ZodObject<{
|
|
153
|
+
data: z.ZodObject<{
|
|
154
|
+
name: z.ZodString;
|
|
155
|
+
uuid: z.ZodUUID;
|
|
156
|
+
installationDate: z.ZodDate;
|
|
157
|
+
equipments: z.ZodObject<{
|
|
158
|
+
inverter: z.ZodString;
|
|
159
|
+
panels: z.ZodArray<z.ZodObject<{
|
|
160
|
+
model: z.ZodString;
|
|
161
|
+
quantity: z.ZodNumber;
|
|
162
|
+
}, z.core.$strip>>;
|
|
163
|
+
}, z.core.$strip>;
|
|
164
|
+
economies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
165
|
+
date: z.ZodDate;
|
|
166
|
+
valueWouldBe: z.ZodObject<{
|
|
167
|
+
format: z.ZodString;
|
|
168
|
+
value: z.ZodNumber;
|
|
169
|
+
unit: z.ZodEnum<{
|
|
170
|
+
BRL: "BRL";
|
|
171
|
+
}>;
|
|
172
|
+
}, z.core.$strip>;
|
|
173
|
+
valuePaid: z.ZodObject<{
|
|
174
|
+
format: z.ZodString;
|
|
175
|
+
value: z.ZodNumber;
|
|
176
|
+
unit: z.ZodEnum<{
|
|
177
|
+
BRL: "BRL";
|
|
178
|
+
}>;
|
|
179
|
+
}, z.core.$strip>;
|
|
180
|
+
economy: z.ZodObject<{
|
|
181
|
+
format: z.ZodString;
|
|
182
|
+
value: z.ZodNumber;
|
|
183
|
+
unit: z.ZodEnum<{
|
|
184
|
+
BRL: "BRL";
|
|
185
|
+
}>;
|
|
186
|
+
}, z.core.$strip>;
|
|
187
|
+
economyAccumulated: z.ZodObject<{
|
|
188
|
+
format: z.ZodString;
|
|
189
|
+
value: z.ZodNumber;
|
|
190
|
+
unit: z.ZodEnum<{
|
|
191
|
+
BRL: "BRL";
|
|
192
|
+
}>;
|
|
193
|
+
}, z.core.$strip>;
|
|
194
|
+
}, z.core.$strip>>>;
|
|
195
|
+
}, z.core.$strip>;
|
|
196
|
+
}, z.core.$strip>;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export { type CommonResponseType, type CommonResponsesType, authorizationHeader, commonResponses, commonResponsesBodySchema, detailedUnitSchema, moneySchema, solarUnitContract, unitSchema };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const authorizationHeader: z.ZodString;
|
|
4
|
+
declare const commonResponsesBodySchema: {
|
|
5
|
+
unauthorized: z.ZodObject<{
|
|
6
|
+
error: z.ZodObject<{
|
|
7
|
+
type: z.ZodLiteral<"UNAUTHORIZED">;
|
|
8
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
9
|
+
}, z.core.$strip>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
entityNotFound: z.ZodObject<{
|
|
12
|
+
error: z.ZodObject<{
|
|
13
|
+
type: z.ZodLiteral<"ENTITY_NOT_FOUND">;
|
|
14
|
+
entity: z.ZodString;
|
|
15
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
entityAlreadyExists: z.ZodObject<{
|
|
19
|
+
error: z.ZodObject<{
|
|
20
|
+
type: z.ZodLiteral<"ENTITY_ALREADY_EXISTS">;
|
|
21
|
+
entity: z.ZodString;
|
|
22
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
internalServerError: z.ZodObject<{
|
|
26
|
+
error: z.ZodObject<{
|
|
27
|
+
type: z.ZodLiteral<"INTERNAL_SERVER_ERROR">;
|
|
28
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
};
|
|
32
|
+
declare const commonResponses: {
|
|
33
|
+
401: z.ZodObject<{
|
|
34
|
+
error: z.ZodObject<{
|
|
35
|
+
type: z.ZodLiteral<"UNAUTHORIZED">;
|
|
36
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
37
|
+
}, z.core.$strip>;
|
|
38
|
+
}, z.core.$strip>;
|
|
39
|
+
404: z.ZodObject<{
|
|
40
|
+
error: z.ZodObject<{
|
|
41
|
+
type: z.ZodLiteral<"ENTITY_NOT_FOUND">;
|
|
42
|
+
entity: z.ZodString;
|
|
43
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
44
|
+
}, z.core.$strip>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
409: z.ZodObject<{
|
|
47
|
+
error: z.ZodObject<{
|
|
48
|
+
type: z.ZodLiteral<"ENTITY_ALREADY_EXISTS">;
|
|
49
|
+
entity: z.ZodString;
|
|
50
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
500: z.ZodObject<{
|
|
54
|
+
error: z.ZodObject<{
|
|
55
|
+
type: z.ZodLiteral<"INTERNAL_SERVER_ERROR">;
|
|
56
|
+
message: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
};
|
|
60
|
+
type CommonResponsesType = {
|
|
61
|
+
[K in keyof typeof commonResponses]: {
|
|
62
|
+
status: K;
|
|
63
|
+
body: z.infer<(typeof commonResponses)[K]>;
|
|
64
|
+
};
|
|
65
|
+
}[keyof typeof commonResponses];
|
|
66
|
+
type CommonResponseType<T extends keyof typeof commonResponses> = {
|
|
67
|
+
status: T;
|
|
68
|
+
body: z.infer<(typeof commonResponses)[T]>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
declare const moneySchema: z.ZodObject<{
|
|
72
|
+
format: z.ZodString;
|
|
73
|
+
value: z.ZodNumber;
|
|
74
|
+
unit: z.ZodEnum<{
|
|
75
|
+
BRL: "BRL";
|
|
76
|
+
}>;
|
|
77
|
+
}, z.core.$strip>;
|
|
78
|
+
declare const unitSchema: z.ZodObject<{
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
uuid: z.ZodUUID;
|
|
81
|
+
installationDate: z.ZodDate;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
declare const detailedUnitSchema: z.ZodObject<{
|
|
84
|
+
name: z.ZodString;
|
|
85
|
+
uuid: z.ZodUUID;
|
|
86
|
+
installationDate: z.ZodDate;
|
|
87
|
+
equipments: z.ZodObject<{
|
|
88
|
+
inverter: z.ZodString;
|
|
89
|
+
panels: z.ZodArray<z.ZodObject<{
|
|
90
|
+
model: z.ZodString;
|
|
91
|
+
quantity: z.ZodNumber;
|
|
92
|
+
}, z.core.$strip>>;
|
|
93
|
+
}, z.core.$strip>;
|
|
94
|
+
economies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
95
|
+
date: z.ZodDate;
|
|
96
|
+
valueWouldBe: z.ZodObject<{
|
|
97
|
+
format: z.ZodString;
|
|
98
|
+
value: z.ZodNumber;
|
|
99
|
+
unit: z.ZodEnum<{
|
|
100
|
+
BRL: "BRL";
|
|
101
|
+
}>;
|
|
102
|
+
}, z.core.$strip>;
|
|
103
|
+
valuePaid: z.ZodObject<{
|
|
104
|
+
format: z.ZodString;
|
|
105
|
+
value: z.ZodNumber;
|
|
106
|
+
unit: z.ZodEnum<{
|
|
107
|
+
BRL: "BRL";
|
|
108
|
+
}>;
|
|
109
|
+
}, z.core.$strip>;
|
|
110
|
+
economy: z.ZodObject<{
|
|
111
|
+
format: z.ZodString;
|
|
112
|
+
value: z.ZodNumber;
|
|
113
|
+
unit: z.ZodEnum<{
|
|
114
|
+
BRL: "BRL";
|
|
115
|
+
}>;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
economyAccumulated: z.ZodObject<{
|
|
118
|
+
format: z.ZodString;
|
|
119
|
+
value: z.ZodNumber;
|
|
120
|
+
unit: z.ZodEnum<{
|
|
121
|
+
BRL: "BRL";
|
|
122
|
+
}>;
|
|
123
|
+
}, z.core.$strip>;
|
|
124
|
+
}, z.core.$strip>>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
declare const solarUnitContract: {
|
|
127
|
+
list: {
|
|
128
|
+
summary: "List all units";
|
|
129
|
+
method: "GET";
|
|
130
|
+
headers: z.ZodObject<{
|
|
131
|
+
authorization: z.ZodString;
|
|
132
|
+
}, z.core.$strip>;
|
|
133
|
+
path: "/solar/units";
|
|
134
|
+
responses: {
|
|
135
|
+
200: z.ZodObject<{
|
|
136
|
+
data: z.ZodArray<z.ZodObject<{
|
|
137
|
+
name: z.ZodString;
|
|
138
|
+
uuid: z.ZodUUID;
|
|
139
|
+
installationDate: z.ZodDate;
|
|
140
|
+
}, z.core.$strip>>;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
show: {
|
|
145
|
+
pathParams: z.ZodObject<{
|
|
146
|
+
uuid: z.ZodUUID;
|
|
147
|
+
}, z.core.$strip>;
|
|
148
|
+
summary: "Show an unit by an UUID";
|
|
149
|
+
method: "GET";
|
|
150
|
+
path: "/solar/units/:uuid";
|
|
151
|
+
responses: {
|
|
152
|
+
200: z.ZodObject<{
|
|
153
|
+
data: z.ZodObject<{
|
|
154
|
+
name: z.ZodString;
|
|
155
|
+
uuid: z.ZodUUID;
|
|
156
|
+
installationDate: z.ZodDate;
|
|
157
|
+
equipments: z.ZodObject<{
|
|
158
|
+
inverter: z.ZodString;
|
|
159
|
+
panels: z.ZodArray<z.ZodObject<{
|
|
160
|
+
model: z.ZodString;
|
|
161
|
+
quantity: z.ZodNumber;
|
|
162
|
+
}, z.core.$strip>>;
|
|
163
|
+
}, z.core.$strip>;
|
|
164
|
+
economies: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
165
|
+
date: z.ZodDate;
|
|
166
|
+
valueWouldBe: z.ZodObject<{
|
|
167
|
+
format: z.ZodString;
|
|
168
|
+
value: z.ZodNumber;
|
|
169
|
+
unit: z.ZodEnum<{
|
|
170
|
+
BRL: "BRL";
|
|
171
|
+
}>;
|
|
172
|
+
}, z.core.$strip>;
|
|
173
|
+
valuePaid: z.ZodObject<{
|
|
174
|
+
format: z.ZodString;
|
|
175
|
+
value: z.ZodNumber;
|
|
176
|
+
unit: z.ZodEnum<{
|
|
177
|
+
BRL: "BRL";
|
|
178
|
+
}>;
|
|
179
|
+
}, z.core.$strip>;
|
|
180
|
+
economy: z.ZodObject<{
|
|
181
|
+
format: z.ZodString;
|
|
182
|
+
value: z.ZodNumber;
|
|
183
|
+
unit: z.ZodEnum<{
|
|
184
|
+
BRL: "BRL";
|
|
185
|
+
}>;
|
|
186
|
+
}, z.core.$strip>;
|
|
187
|
+
economyAccumulated: z.ZodObject<{
|
|
188
|
+
format: z.ZodString;
|
|
189
|
+
value: z.ZodNumber;
|
|
190
|
+
unit: z.ZodEnum<{
|
|
191
|
+
BRL: "BRL";
|
|
192
|
+
}>;
|
|
193
|
+
}, z.core.$strip>;
|
|
194
|
+
}, z.core.$strip>>>;
|
|
195
|
+
}, z.core.$strip>;
|
|
196
|
+
}, z.core.$strip>;
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export { type CommonResponseType, type CommonResponsesType, authorizationHeader, commonResponses, commonResponsesBodySchema, detailedUnitSchema, moneySchema, solarUnitContract, unitSchema };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/schemas.ts
|
|
2
|
+
import z from "zod";
|
|
3
|
+
var authorizationHeader = z.string().startsWith("Bearer ");
|
|
4
|
+
var commonResponsesBodySchema = {
|
|
5
|
+
unauthorized: z.object({
|
|
6
|
+
error: z.object({
|
|
7
|
+
type: z.literal("UNAUTHORIZED"),
|
|
8
|
+
message: z.string().default("").optional()
|
|
9
|
+
})
|
|
10
|
+
}),
|
|
11
|
+
entityNotFound: z.object({
|
|
12
|
+
error: z.object({
|
|
13
|
+
type: z.literal("ENTITY_NOT_FOUND"),
|
|
14
|
+
entity: z.string(),
|
|
15
|
+
message: z.string().default("").optional()
|
|
16
|
+
})
|
|
17
|
+
}),
|
|
18
|
+
entityAlreadyExists: z.object({
|
|
19
|
+
error: z.object({
|
|
20
|
+
type: z.literal("ENTITY_ALREADY_EXISTS"),
|
|
21
|
+
entity: z.string(),
|
|
22
|
+
message: z.string().default("").optional()
|
|
23
|
+
})
|
|
24
|
+
}),
|
|
25
|
+
internalServerError: z.object({
|
|
26
|
+
error: z.object({
|
|
27
|
+
type: z.literal("INTERNAL_SERVER_ERROR"),
|
|
28
|
+
message: z.string().default("").optional()
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
};
|
|
32
|
+
var commonResponses = {
|
|
33
|
+
401: commonResponsesBodySchema.unauthorized,
|
|
34
|
+
404: commonResponsesBodySchema.entityNotFound,
|
|
35
|
+
409: commonResponsesBodySchema.entityAlreadyExists,
|
|
36
|
+
500: commonResponsesBodySchema.internalServerError
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/contracts/auth.contract.ts
|
|
40
|
+
import { initContract } from "@ts-rest/core";
|
|
41
|
+
import z2 from "zod";
|
|
42
|
+
var c = initContract();
|
|
43
|
+
var moneySchema = z2.object({
|
|
44
|
+
format: z2.string(),
|
|
45
|
+
value: z2.number(),
|
|
46
|
+
unit: z2.enum(["BRL"])
|
|
47
|
+
});
|
|
48
|
+
var unitSchema = z2.object({
|
|
49
|
+
name: z2.string(),
|
|
50
|
+
uuid: z2.uuidv7(),
|
|
51
|
+
installationDate: z2.date()
|
|
52
|
+
});
|
|
53
|
+
var detailedUnitSchema = unitSchema.extend({
|
|
54
|
+
equipments: z2.object({
|
|
55
|
+
inverter: z2.string(),
|
|
56
|
+
panels: z2.array(
|
|
57
|
+
z2.object({
|
|
58
|
+
model: z2.string(),
|
|
59
|
+
quantity: z2.number().positive()
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
}),
|
|
63
|
+
economies: z2.array(
|
|
64
|
+
z2.object({
|
|
65
|
+
date: z2.date(),
|
|
66
|
+
valueWouldBe: moneySchema,
|
|
67
|
+
valuePaid: moneySchema,
|
|
68
|
+
economy: moneySchema,
|
|
69
|
+
economyAccumulated: moneySchema
|
|
70
|
+
})
|
|
71
|
+
).optional()
|
|
72
|
+
});
|
|
73
|
+
var solarUnitContract = c.router({
|
|
74
|
+
list: {
|
|
75
|
+
method: "GET",
|
|
76
|
+
path: "/solar/units",
|
|
77
|
+
headers: z2.object({
|
|
78
|
+
authorization: authorizationHeader
|
|
79
|
+
}),
|
|
80
|
+
responses: {
|
|
81
|
+
200: z2.object({
|
|
82
|
+
data: z2.array(unitSchema)
|
|
83
|
+
})
|
|
84
|
+
},
|
|
85
|
+
summary: "List all units"
|
|
86
|
+
},
|
|
87
|
+
show: {
|
|
88
|
+
method: "GET",
|
|
89
|
+
path: "/solar/units/:uuid",
|
|
90
|
+
pathParams: z2.object({
|
|
91
|
+
uuid: z2.uuidv7()
|
|
92
|
+
}),
|
|
93
|
+
responses: {
|
|
94
|
+
200: z2.object({
|
|
95
|
+
data: detailedUnitSchema
|
|
96
|
+
})
|
|
97
|
+
},
|
|
98
|
+
summary: "Show an unit by an UUID"
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
export {
|
|
102
|
+
authorizationHeader,
|
|
103
|
+
commonResponses,
|
|
104
|
+
commonResponsesBodySchema,
|
|
105
|
+
detailedUnitSchema,
|
|
106
|
+
moneySchema,
|
|
107
|
+
solarUnitContract,
|
|
108
|
+
unitSchema
|
|
109
|
+
};
|
package/package.json
CHANGED