@warpstore/warpstore-package 1.0.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/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@warpstore/warpstore-package",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/src/main.js",
6
+ "types": "dist/src/main.d.ts",
7
+ "repository": "https://github.com/Warp-Store/warpstore-package",
8
+ "scripts": {
9
+ "prebuild": "rimraf dist",
10
+ "build": "ttsc",
11
+ "build:w": "ttsc -w",
12
+ "dev": "ts-node-dev -r tsconfig-paths/register --respawn --poll --inspect --exit-child ./src/index.ts",
13
+ "test:unit": "npx tsc --noEmit && npm run test:skipchecks -- --config jest.config.ts",
14
+ "test:integration": "npx tsc --noEmit && npm run test:skipchecks -- --config jest.config.integration.ts",
15
+ "test:integration:skipchecks": "jest --watch --no-cache --runInBand --config jest.config.integration.ts",
16
+ "test:skipchecks": "jest --passWithNoTests --watch --no-cache --runInBand"
17
+ },
18
+ "author": "",
19
+ "license": "ISC",
20
+ "devDependencies": {
21
+ "@swc/core": "^1.3.55",
22
+ "@swc/jest": "^0.2.26",
23
+ "@types/dotenv": "^8.2.0",
24
+ "@types/jest": "^29.5.1",
25
+ "@types/node": "^18.18.12",
26
+ "@types/yup": "^0.32.0",
27
+ "dotenv": "^16.3.1",
28
+ "jest": "^29.5.0",
29
+ "rimraf": "^5.0.1",
30
+ "ts-jest": "^29.1.0",
31
+ "ttypescript": "^1.5.15",
32
+ "typescript": "^4.4.4",
33
+ "typescript-transform-paths": "^3.4.6"
34
+ },
35
+ "dependencies": {
36
+ "@types/express": "^4.17.21",
37
+ "axios": "^1.6.7",
38
+ "express": "^4.18.2",
39
+ "jest-mock-extended": "^3.0.4",
40
+ "node-fetch": "^3.3.2",
41
+ "reflect-metadata": "^0.1.13",
42
+ "ts-node-dev": "^2.0.0",
43
+ "tsconfig-paths": "^4.2.0"
44
+ }
45
+ }
@@ -0,0 +1,12 @@
1
+ import { DomainError } from "./domain-error";
2
+
3
+ export class CustomDomainError<T> extends DomainError {
4
+
5
+ errorName: T
6
+
7
+ constructor(name: T) {
8
+ super()
9
+ this.errorName = name
10
+ this.name = name as any
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+
2
+ export class DomainError extends Error {
3
+ constructor(message?: string) {
4
+ super(message)
5
+ this.name = this.constructor.name
6
+ }
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./domain-error"
2
+ export * from "./custom-domain-error"
@@ -0,0 +1,41 @@
1
+ export class Failure<F, S> {
2
+ readonly value: F
3
+
4
+ constructor(value: F) {
5
+ this.value = value
6
+ }
7
+
8
+ isFailure(): this is Failure<F, S> {
9
+ return true
10
+ }
11
+
12
+ isSuccess(): this is Success<F, S> {
13
+ return false
14
+ }
15
+ }
16
+
17
+ export class Success<F, S> {
18
+ readonly value: S
19
+
20
+ constructor(value: S) {
21
+ this.value = value
22
+ }
23
+
24
+ isFailure(): this is Failure<F, S> {
25
+ return false
26
+ }
27
+
28
+ isSuccess(): this is Success<F, S> {
29
+ return true
30
+ }
31
+ }
32
+
33
+ export type Either<F, S> = Failure<F, S> | Success<F, S>
34
+
35
+ export const failure = <F, S>(f?: F): Either<F, S> => {
36
+ return new Failure<F, S>(f!)
37
+ }
38
+
39
+ export const success = <F, S>(s?: S): Either<F, S> => {
40
+ return new Success<F, S>(s!)
41
+ }
@@ -0,0 +1 @@
1
+ export * from "./either"
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { WarpStore } from "./main"
2
+
3
+
4
+
5
+ (async () => {
6
+
7
+ const warpstore = new WarpStore()
8
+
9
+ const response = await warpstore.template.v1.getStoreInfo({
10
+ subDomain: "batata"
11
+ })
12
+
13
+ console.log(response.value)
14
+ if(response.isFailure()){
15
+ return
16
+ }
17
+ })()
18
+
@@ -0,0 +1 @@
1
+ export * from "./request-manager"
@@ -0,0 +1,48 @@
1
+ import { CustomDomainError, DomainError } from "@/core/errors";
2
+ import { Either, failure, success } from "@/core/logic";
3
+ import axios, { AxiosResponse } from "axios"
4
+
5
+ const api = axios.create({
6
+ baseURL: 'http://localhost:5000',
7
+ timeout: 1000,
8
+ validateStatus: () => true
9
+ })
10
+
11
+ export class RequestManager {
12
+
13
+ static async makeRequest<TResponse, TError, >(path: string, httpInput: RequestManager.HttpInput = {} as any): Promise<Either<TError, TResponse>> {
14
+ const { body, headers, query, method } = httpInput
15
+
16
+ let response: AxiosResponse
17
+
18
+ if(method === "POST") {
19
+ response = await api.post(path, body, {
20
+ headers,
21
+ params: query
22
+ })
23
+ }else {
24
+ response = await api.get(path, {
25
+ headers,
26
+ params: query
27
+ })
28
+ }
29
+
30
+ if(response.status !== 200) {
31
+ return failure(new CustomDomainError(response.data?.error?.name)) as any
32
+ }
33
+
34
+ return success(response.data) as any
35
+ }
36
+
37
+ }
38
+
39
+ export namespace RequestManager {
40
+
41
+
42
+ export type HttpInput = {
43
+ method: "GET" | "POST"
44
+ body?: object
45
+ headers?: object
46
+ query?: object
47
+ }
48
+ }
package/src/main.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { Template } from "./template";
2
+
3
+ export class WarpStore {
4
+ template: Template = new Template()
5
+ }
6
+
7
+
@@ -0,0 +1,7 @@
1
+ import { TemplateV1 } from "./versions";
2
+
3
+ export class Template {
4
+
5
+ v1: TemplateV1 = new TemplateV1()
6
+
7
+ }
@@ -0,0 +1,81 @@
1
+
2
+
3
+ export const PlanEnum = {
4
+ BASIC: "BASIC",
5
+ SUPER: "SUPER",
6
+ ADVANCED: "ADVANCED"
7
+ } as const
8
+
9
+ export const PaymentMethodsEnum = {
10
+ MERCADO_PAGO: 'MERCADO_PAGO',
11
+ PIX: 'PIX',
12
+ STRIPE: 'STRIPE',
13
+ } as const
14
+
15
+ export type StoreThemeDto = {
16
+ id: string
17
+ title: string
18
+ description: string
19
+ logo: string
20
+ favicon: string
21
+ banner: string
22
+ subdomain: string
23
+ domain: string | undefined
24
+ currency: string
25
+ keywords: string
26
+ plan: keyof typeof PlanEnum
27
+ theme: {
28
+ primaryColor: string
29
+ secondaryColor: string
30
+ backgroundPrimaryColor: string
31
+ backgroundSecondaryColor: string
32
+ },
33
+ widgets: {
34
+ FEATURED_PRODUCT?: {
35
+ id: string
36
+ name: string
37
+ image: string
38
+ price: number
39
+ }
40
+ DISCORD?: {
41
+ discordURL: string
42
+ }
43
+ ONLINE_PLAYERS?: {
44
+ ip: string
45
+ port: number
46
+ }
47
+ },
48
+ visualEffects: {
49
+ SNOW_FLAKE?: {
50
+ color: string,
51
+ radius: number,
52
+ snowFlakeCount: number
53
+ }
54
+ },
55
+ socialMedia: {
56
+ instagram?: string
57
+ tiktok?: string
58
+ youtube?: string
59
+ discord?: string
60
+ },
61
+ paymentMethods: keyof typeof PaymentMethodsEnum[]
62
+
63
+ categories: {
64
+ id: string
65
+ title: string
66
+ slug: string
67
+ description: string
68
+ }[]
69
+ }
70
+
71
+ export type ProductInfoDto = {
72
+ products: {
73
+ id: string
74
+ name: string
75
+ description: string
76
+ price: number
77
+ image: string
78
+ }
79
+ quantityReturned: number
80
+ totalQuantity: number
81
+ }
@@ -0,0 +1,12 @@
1
+ import { CustomDomainError } from "@/core/errors";
2
+
3
+ type Error = "NoParamsProvidedError" | "StoreNotFoundError" | "InvalidRequestError"
4
+
5
+ export class GetStoreInfoError extends CustomDomainError<Error> {
6
+
7
+ constructor(name: Error) {
8
+ super(name)
9
+ }
10
+ }
11
+
12
+
File without changes
@@ -0,0 +1 @@
1
+ export * from "./v1"
@@ -0,0 +1,37 @@
1
+ import { DomainError } from "@/core/errors"
2
+ import { Either, success } from "@/core/logic"
3
+ import { ProductInfoDto, StoreThemeDto } from "./dtos"
4
+ import { RequestManager } from "@/lib"
5
+ import { GetStoreInfoError } from "./errors/errors"
6
+
7
+ export class TemplateV1 {
8
+
9
+ async getStoreInfo(input: TemplateV1.GetStoreInfoInputDto): Promise<Either<GetStoreInfoError, StoreThemeDto>>{
10
+ return await RequestManager.makeRequest<StoreThemeDto, GetStoreInfoError>("/template/v1/store-info", {
11
+ method: "GET",
12
+ query: input
13
+ })
14
+ }
15
+
16
+ async getProducts(input: TemplateV1.GetProductsInputDto): Promise<Either<DomainError, ProductInfoDto>>{
17
+ return await RequestManager.makeRequest<ProductInfoDto, DomainError>("/template/v1/products", {
18
+ method: "GET",
19
+ query: input
20
+ })
21
+ }
22
+ }
23
+
24
+
25
+ export namespace TemplateV1 {
26
+
27
+ export type GetProductsInputDto = {
28
+ categoryId: string
29
+ limit?: number
30
+ skip?: number
31
+ }
32
+
33
+ export type GetStoreInfoInputDto = {
34
+ subDomain?: string
35
+ domain?: string
36
+ }
37
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+
3
+ "compilerOptions": {
4
+ "experimentalDecorators": true,
5
+ "declaration": true,
6
+ "declarationMap": true,
7
+ "composite": true,
8
+ "target": "es2021",
9
+ "module": "commonjs",
10
+ "rootDir": ".",
11
+ "moduleResolution": "node",
12
+ "baseUrl": "./src",
13
+ "noImplicitAny": true,
14
+ "paths": {
15
+ "@/*": [
16
+ "*"
17
+ ]
18
+ },
19
+ "plugins": [
20
+ {
21
+ "transform": "typescript-transform-paths"
22
+ },
23
+ {
24
+ "transform": "typescript-transform-paths",
25
+ "afterDeclarations": true
26
+ }
27
+ ],
28
+ "outDir": "./dist",
29
+ "forceConsistentCasingInFileNames": true,
30
+ "strict": true,
31
+ "skipLibCheck": true
32
+ }
33
+ }