@infrab4a/connect-nestjs 3.0.0-alpha.0 → 3.0.0-alpha.1
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/index.cjs.d.ts +1 -0
- package/index.cjs.default.js +1 -0
- package/index.cjs.js +1334 -0
- package/index.cjs.mjs +2 -0
- package/index.esm.js +1317 -0
- package/package.json +13 -3
- package/src/consts/es-config.const.d.ts +1 -0
- package/src/consts/hasura-options.const.d.ts +1 -0
- package/src/consts/index.d.ts +4 -0
- package/src/consts/storage.const.d.ts +1 -0
- package/src/consts/vertex-config.const.d.ts +1 -0
- package/src/index.d.ts +7 -0
- package/src/infra/elasticsearch/adapters/index.d.ts +1 -0
- package/src/infra/elasticsearch/adapters/native-elasticsearch-adapter.d.ts +19 -0
- package/src/infra/elasticsearch/index.d.ts +1 -0
- package/src/infra/firebase/firestore/index.d.ts +2 -0
- package/src/infra/firebase/firestore/services/connect-collection-reference.d.ts +19 -0
- package/src/infra/firebase/firestore/services/connect-collection.service.d.ts +32 -0
- package/src/infra/firebase/firestore/services/connect-document-reference.d.ts +11 -0
- package/src/infra/firebase/firestore/services/connect-document.service.d.ts +17 -0
- package/src/infra/firebase/firestore/services/connect-firestore.d.ts +7 -0
- package/src/infra/firebase/firestore/services/connect-firestore.service.d.ts +8 -0
- package/src/infra/firebase/firestore/services/index.d.ts +6 -0
- package/src/infra/firebase/firestore/types/connect-query-snapshot.type.d.ts +4 -0
- package/src/infra/firebase/firestore/types/index.d.ts +1 -0
- package/src/infra/firebase/firestore/vo/connect-base-document-snapshot.vo.d.ts +12 -0
- package/src/infra/firebase/firestore/vo/index.d.ts +1 -0
- package/src/infra/firebase/index.d.ts +1 -0
- package/src/infra/index.d.ts +4 -0
- package/src/infra/pagarme/adapters/index.d.ts +3 -0
- package/src/infra/pagarme/adapters/pagarme-bank-slip-api.adapter.d.ts +9 -0
- package/src/infra/pagarme/adapters/pagarme-card-api.adapter.d.ts +21 -0
- package/src/infra/pagarme/adapters/pagarme-pix-api.adapter.d.ts +8 -0
- package/src/infra/pagarme/index.d.ts +1 -0
- package/src/infra/vertex-ai/adapters/discovery-engine-adapter.d.ts +17 -0
- package/src/infra/vertex-ai/adapters/index.d.ts +1 -0
- package/src/infra/vertex-ai/helpers/index.d.ts +1 -0
- package/src/infra/vertex-ai/helpers/product-vertex-ai.helper.d.ts +7 -0
- package/src/infra/vertex-ai/index.d.ts +3 -0
- package/src/infra/vertex-ai/types/index.d.ts +2 -0
- package/src/infra/vertex-ai/types/vertex-config.d.ts +23 -0
- package/src/infra/vertex-ai/types/vertex-search-result.d.ts +18 -0
- package/src/nest-connect.module.d.ts +13 -0
- package/src/nest-elastic-search.module.d.ts +5 -0
- package/src/nest-firestore.module.d.ts +10 -0
- package/src/nest-hasura-graphql.module.d.ts +13 -0
- package/src/nest-storage.module.d.ts +2 -0
- package/src/nest-vertex-ai-search.module.d.ts +5 -0
- package/eslint.config.js +0 -17
- package/project.json +0 -49
- package/rollup.config.js +0 -17
- package/src/consts/es-config.const.ts +0 -1
- package/src/consts/hasura-options.const.ts +0 -1
- package/src/consts/index.ts +0 -4
- package/src/consts/storage.const.ts +0 -1
- package/src/consts/vertex-config.const.ts +0 -1
- package/src/index.ts +0 -7
- package/src/infra/elasticsearch/adapters/index.ts +0 -1
- package/src/infra/elasticsearch/adapters/native-elasticsearch-adapter.ts +0 -137
- package/src/infra/elasticsearch/index.ts +0 -1
- package/src/infra/firebase/firestore/index.ts +0 -2
- package/src/infra/firebase/firestore/services/connect-collection-reference.ts +0 -27
- package/src/infra/firebase/firestore/services/connect-collection.service.ts +0 -137
- package/src/infra/firebase/firestore/services/connect-document-reference.ts +0 -12
- package/src/infra/firebase/firestore/services/connect-document.service.ts +0 -51
- package/src/infra/firebase/firestore/services/connect-firestore.service.ts +0 -24
- package/src/infra/firebase/firestore/services/connect-firestore.ts +0 -9
- package/src/infra/firebase/firestore/services/index.ts +0 -6
- package/src/infra/firebase/firestore/types/connect-query-snapshot.type.ts +0 -6
- package/src/infra/firebase/firestore/types/index.ts +0 -1
- package/src/infra/firebase/firestore/vo/connect-base-document-snapshot.vo.ts +0 -27
- package/src/infra/firebase/firestore/vo/index.ts +0 -1
- package/src/infra/firebase/index.ts +0 -1
- package/src/infra/index.ts +0 -4
- package/src/infra/pagarme/adapters/index.ts +0 -3
- package/src/infra/pagarme/adapters/pagarme-bank-slip-api.adapter.ts +0 -96
- package/src/infra/pagarme/adapters/pagarme-card-api.adapter.ts +0 -226
- package/src/infra/pagarme/adapters/pagarme-pix-api.adapter.ts +0 -69
- package/src/infra/pagarme/index.ts +0 -1
- package/src/infra/vertex-ai/adapters/discovery-engine-adapter.ts +0 -148
- package/src/infra/vertex-ai/adapters/index.ts +0 -1
- package/src/infra/vertex-ai/helpers/index.ts +0 -1
- package/src/infra/vertex-ai/helpers/product-vertex-ai.helper.ts +0 -52
- package/src/infra/vertex-ai/index.ts +0 -3
- package/src/infra/vertex-ai/types/index.ts +0 -2
- package/src/infra/vertex-ai/types/vertex-config.ts +0 -23
- package/src/infra/vertex-ai/types/vertex-search-result.ts +0 -17
- package/src/nest-connect.module.ts +0 -36
- package/src/nest-elastic-search.module.ts +0 -26
- package/src/nest-firestore.module.ts +0 -363
- package/src/nest-hasura-graphql.module.ts +0 -227
- package/src/nest-storage.module.ts +0 -16
- package/src/nest-vertex-ai-search.module.ts +0 -26
- package/src/types/pagarme.d.ts +0 -25
- package/tsconfig.json +0 -15
- package/tsconfig.lib.json +0 -7
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { Client } from '@elastic/elasticsearch'
|
|
2
|
-
import {
|
|
3
|
-
BaseModel,
|
|
4
|
-
DebugHelper,
|
|
5
|
-
ElasticSearchAdapter,
|
|
6
|
-
ElasticSearchResult,
|
|
7
|
-
NotFoundError,
|
|
8
|
-
isEmpty,
|
|
9
|
-
} from '@infrab4a/connect'
|
|
10
|
-
import { Inject, Injectable } from '@nestjs/common'
|
|
11
|
-
|
|
12
|
-
import { ES_CONFIG } from '../../../consts'
|
|
13
|
-
|
|
14
|
-
export interface ESClientOptions {
|
|
15
|
-
cloud: { id: string }
|
|
16
|
-
auth: { apiKey: string }
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@Injectable()
|
|
20
|
-
export class NativeElasticSearchAdapter<T extends BaseModel<T> = any> implements ElasticSearchAdapter<T> {
|
|
21
|
-
private client: Client
|
|
22
|
-
private logger: DebugHelper
|
|
23
|
-
|
|
24
|
-
constructor(@Inject(ES_CONFIG) config: ESClientOptions) {
|
|
25
|
-
this.logger = DebugHelper.from(this)
|
|
26
|
-
|
|
27
|
-
try {
|
|
28
|
-
this.client = !isEmpty(config.cloud.id) && !isEmpty(config.auth.apiKey) && new Client(config)
|
|
29
|
-
} catch (error) {
|
|
30
|
-
this.logger.error({ req: config, res: error })
|
|
31
|
-
|
|
32
|
-
throw error
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
public async get(index: string, id: string): Promise<T> {
|
|
37
|
-
const logger = this.logger.with('get')
|
|
38
|
-
const req = { index, id }
|
|
39
|
-
|
|
40
|
-
try {
|
|
41
|
-
const data = await this.client.get({ index, id })
|
|
42
|
-
|
|
43
|
-
logger.log({ req, res: data })
|
|
44
|
-
|
|
45
|
-
return data._source as T
|
|
46
|
-
} catch (error) {
|
|
47
|
-
const message = error instanceof Error ? error.message : `${index}/${id} not found`
|
|
48
|
-
|
|
49
|
-
logger.log({ req, res: error })
|
|
50
|
-
|
|
51
|
-
throw new NotFoundError(message)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
public async query(index: string, query: any): Promise<ElasticSearchResult<T>> {
|
|
56
|
-
const logger = this.logger.with('query')
|
|
57
|
-
const params = {
|
|
58
|
-
index,
|
|
59
|
-
query,
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const result = await this.client.search(params)
|
|
64
|
-
const res = {
|
|
65
|
-
total: result.hits.total as number,
|
|
66
|
-
hits: result.hits.hits as ElasticSearchResult<T>['hits'],
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
logger.log({ req: params, res })
|
|
70
|
-
|
|
71
|
-
return res
|
|
72
|
-
} catch (error) {
|
|
73
|
-
logger.error({ req: params, res: error })
|
|
74
|
-
|
|
75
|
-
throw error
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public async save(index: string, data: T): Promise<void> {
|
|
80
|
-
const logger = this.logger.with('save')
|
|
81
|
-
const req = {
|
|
82
|
-
index,
|
|
83
|
-
id:
|
|
84
|
-
data.identifiersFields.length > 1
|
|
85
|
-
? JSON.stringify(data.identifier)
|
|
86
|
-
: Object.values(data.identifier).shift().toString(),
|
|
87
|
-
document: data.toPlain(),
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
const res = await this.client.index(req)
|
|
92
|
-
|
|
93
|
-
logger.log({ req, res })
|
|
94
|
-
} catch (error) {
|
|
95
|
-
logger.error({ req, res: error })
|
|
96
|
-
|
|
97
|
-
throw error
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public async update(index: string, id: string, data: Partial<T>): Promise<void> {
|
|
102
|
-
const logger = this.logger.with('update')
|
|
103
|
-
const req = {
|
|
104
|
-
index,
|
|
105
|
-
id,
|
|
106
|
-
doc: data,
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
try {
|
|
110
|
-
await this.client.update(req)
|
|
111
|
-
|
|
112
|
-
logger.log({ req, res: undefined })
|
|
113
|
-
} catch (error) {
|
|
114
|
-
logger.error({ req, res: error })
|
|
115
|
-
|
|
116
|
-
throw error
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
public async delete(index: string, id: string): Promise<void> {
|
|
121
|
-
const logger = this.logger.with('delete')
|
|
122
|
-
const req = {
|
|
123
|
-
index,
|
|
124
|
-
id,
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
await this.client.delete(req)
|
|
129
|
-
|
|
130
|
-
logger.log({ req, res: undefined })
|
|
131
|
-
} catch (error) {
|
|
132
|
-
logger.error({ req, res: error })
|
|
133
|
-
|
|
134
|
-
throw error
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './adapters'
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConnectDocumentData,
|
|
3
|
-
ConnectDocumentSnapshot,
|
|
4
|
-
ConnectQuerySnapshot,
|
|
5
|
-
ConnectSnapshotOptions,
|
|
6
|
-
ConnectWhereOption,
|
|
7
|
-
} from '@infrab4a/connect'
|
|
8
|
-
|
|
9
|
-
import { ConnectDocumentReference } from './connect-document-reference'
|
|
10
|
-
|
|
11
|
-
export interface ConnectCollectionReference<T extends ConnectDocumentData> {
|
|
12
|
-
add(data: T, id?: string): Promise<ConnectDocumentReference<T>>
|
|
13
|
-
where(attribute: string, operator: ConnectWhereOption, value: any): ConnectCollectionReference<T>
|
|
14
|
-
order(attribute: string, order: 'asc' | 'desc'): ConnectCollectionReference<T>
|
|
15
|
-
limit(quantity: number): ConnectCollectionReference<T>
|
|
16
|
-
offset(offset: number): ConnectCollectionReference<T>
|
|
17
|
-
fromStartAt(startAt: number): ConnectCollectionReference<T>
|
|
18
|
-
fromStartAt(startAt: ConnectDocumentReference<T>): ConnectCollectionReference<T>
|
|
19
|
-
fromStartAfter(startAt: number): ConnectCollectionReference<T>
|
|
20
|
-
fromStartAfter(startAt: ConnectDocumentReference<T>): ConnectCollectionReference<T>
|
|
21
|
-
withConverter(converter: {
|
|
22
|
-
toFirestore: (data: T) => ConnectDocumentData<T>
|
|
23
|
-
fromFirestore: (snapshot: ConnectDocumentSnapshot<T>, options?: ConnectSnapshotOptions) => T
|
|
24
|
-
}): ConnectCollectionReference<T>
|
|
25
|
-
getDoc(id?: string): ConnectDocumentReference<T>
|
|
26
|
-
getDocs(): Promise<ConnectQuerySnapshot<T>>
|
|
27
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConnectDocumentData,
|
|
3
|
-
ConnectDocumentSnapshot,
|
|
4
|
-
ConnectQuerySnapshot,
|
|
5
|
-
ConnectSnapshotOptions,
|
|
6
|
-
ConnectWhereOption,
|
|
7
|
-
isEmpty,
|
|
8
|
-
} from '@infrab4a/connect'
|
|
9
|
-
import {
|
|
10
|
-
CollectionReference,
|
|
11
|
-
DocumentReference,
|
|
12
|
-
Firestore,
|
|
13
|
-
Query,
|
|
14
|
-
QueryDocumentSnapshot,
|
|
15
|
-
} from 'firebase-admin/firestore'
|
|
16
|
-
|
|
17
|
-
import { ConnectBaseDocumentSnapshot } from '../vo'
|
|
18
|
-
|
|
19
|
-
import { ConnectCollectionReference } from './connect-collection-reference'
|
|
20
|
-
import { ConnectDocumentReference } from './connect-document-reference'
|
|
21
|
-
import { ConnectDocumentService } from './connect-document.service'
|
|
22
|
-
|
|
23
|
-
export class ConnectCollectionService<T extends ConnectDocumentData> implements ConnectCollectionReference<T> {
|
|
24
|
-
private reference: CollectionReference<T>
|
|
25
|
-
private query: Query
|
|
26
|
-
private orderBy: { fieldPath: string; directionStr: 'asc' | 'desc' }
|
|
27
|
-
private limitBy: number
|
|
28
|
-
private offsetBy: number
|
|
29
|
-
private startingAt: number | unknown
|
|
30
|
-
private startingAfter: number | unknown
|
|
31
|
-
private converter: {
|
|
32
|
-
toFirestore: (data: T) => ConnectDocumentData<T>
|
|
33
|
-
fromFirestore: (snapshot: ConnectDocumentSnapshot<T>, options?: ConnectSnapshotOptions) => T
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
constructor(path: string, private readonly firestore: Firestore) {
|
|
37
|
-
this.reference = firestore.collection(path).withConverter({
|
|
38
|
-
toFirestore: (data) => data,
|
|
39
|
-
fromFirestore: (snapshot) => {
|
|
40
|
-
return { id: snapshot.id, ...snapshot.data() } as T
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async add(data: T, id?: string): Promise<ConnectDocumentReference<T>> {
|
|
46
|
-
const newDoc = await this.save(data, id)
|
|
47
|
-
|
|
48
|
-
return new ConnectDocumentService<T>(newDoc.path, this.firestore).withConverter(this.converter)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async getDocs(): Promise<ConnectQuerySnapshot<T>> {
|
|
52
|
-
if (this.startingAt) this.limitBy += this.startingAt as number
|
|
53
|
-
|
|
54
|
-
let query = this.query ? this.query : this.reference
|
|
55
|
-
|
|
56
|
-
query = this.orderBy ? query.orderBy(this.orderBy.fieldPath, this.orderBy.directionStr) : query
|
|
57
|
-
query = this.limitBy ? query.limit(this.limitBy) : query
|
|
58
|
-
|
|
59
|
-
return query.get().then((docs) => {
|
|
60
|
-
const docsPaginated = this.startingAt ? docs.docs.slice(this.startingAt as number, this.limitBy) : docs.docs
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
empty: Boolean(docsPaginated.length),
|
|
64
|
-
size: docsPaginated.length,
|
|
65
|
-
docs: docsPaginated.map((doc) => new ConnectBaseDocumentSnapshot(doc)),
|
|
66
|
-
} as any
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
getDoc(id?: string): ConnectDocumentReference<T> {
|
|
71
|
-
return new ConnectDocumentService<T>(`${this.reference.path}/${id}`, this.firestore).withConverter(this.converter)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
where(fieldPath: string, opStr: ConnectWhereOption, value: any): ConnectCollectionReference<T> {
|
|
75
|
-
this.query = this.query ? this.query.where(fieldPath, opStr, value) : this.reference.where(fieldPath, opStr, value)
|
|
76
|
-
|
|
77
|
-
return this
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
order(attribute: string, order: 'asc' | 'desc'): ConnectCollectionReference<T> {
|
|
81
|
-
this.orderBy = { fieldPath: attribute, directionStr: order }
|
|
82
|
-
|
|
83
|
-
return this
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
limit(quantity: number): ConnectCollectionReference<T> {
|
|
87
|
-
this.limitBy = quantity
|
|
88
|
-
|
|
89
|
-
return this
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
offset(offsetBy: number): ConnectCollectionReference<T> {
|
|
93
|
-
this.offsetBy = offsetBy
|
|
94
|
-
|
|
95
|
-
return this
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
fromStartAt(startingAt: number): ConnectCollectionReference<T>
|
|
99
|
-
fromStartAt(startingAt: ConnectDocumentReference<T>): ConnectCollectionReference<T>
|
|
100
|
-
fromStartAt(startingAt: unknown): ConnectCollectionReference<T> {
|
|
101
|
-
this.startingAt = startingAt
|
|
102
|
-
|
|
103
|
-
return this
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
fromStartAfter(startingAt: number): ConnectCollectionReference<T>
|
|
107
|
-
fromStartAfter(startingAt: ConnectDocumentReference<T>): ConnectCollectionReference<T>
|
|
108
|
-
fromStartAfter(startingAt: unknown): ConnectCollectionReference<T> {
|
|
109
|
-
this.startingAfter = startingAt
|
|
110
|
-
|
|
111
|
-
return this
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
withConverter(params: {
|
|
115
|
-
toFirestore: (data: T) => ConnectDocumentData<T>
|
|
116
|
-
fromFirestore: (snapshot: ConnectDocumentSnapshot<T>, options?: ConnectSnapshotOptions) => T
|
|
117
|
-
}): ConnectCollectionReference<T> {
|
|
118
|
-
this.converter = params
|
|
119
|
-
this.reference = this.reference.withConverter({
|
|
120
|
-
toFirestore: (data: T) => params.toFirestore(data),
|
|
121
|
-
fromFirestore: (snapshot: QueryDocumentSnapshot<T>, options?: ConnectSnapshotOptions) =>
|
|
122
|
-
params.fromFirestore(new ConnectBaseDocumentSnapshot(snapshot), options),
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
return this
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private async save(data: T, id?: string): Promise<DocumentReference<T>> {
|
|
129
|
-
if (isEmpty(id)) return this.reference.add(data)
|
|
130
|
-
|
|
131
|
-
const docRef = this.reference.doc(id)
|
|
132
|
-
|
|
133
|
-
await docRef.set(data)
|
|
134
|
-
|
|
135
|
-
return docRef
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ConnectDocumentData, ConnectDocumentSnapshot, ConnectSnapshotOptions } from '@infrab4a/connect'
|
|
2
|
-
|
|
3
|
-
export interface ConnectDocumentReference<T extends ConnectDocumentData> {
|
|
4
|
-
get(): Promise<ConnectDocumentSnapshot<T>>
|
|
5
|
-
getId(): string
|
|
6
|
-
save(data: T): Promise<ConnectDocumentReference<T>>
|
|
7
|
-
delete(): Promise<void>
|
|
8
|
-
withConverter(converter: {
|
|
9
|
-
toFirestore: (data: T) => ConnectDocumentData<T>
|
|
10
|
-
fromFirestore: (snapshot: ConnectDocumentSnapshot<T>, options?: ConnectSnapshotOptions) => T
|
|
11
|
-
}): ConnectDocumentReference<T>
|
|
12
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ConnectDocumentData, ConnectDocumentSnapshot, ConnectSnapshotOptions } from '@infrab4a/connect'
|
|
2
|
-
import { DocumentReference, Firestore, QueryDocumentSnapshot } from 'firebase-admin/firestore'
|
|
3
|
-
|
|
4
|
-
import { ConnectBaseDocumentSnapshot } from '../vo'
|
|
5
|
-
|
|
6
|
-
import { ConnectDocumentReference } from './connect-document-reference'
|
|
7
|
-
|
|
8
|
-
export class ConnectDocumentService<T extends ConnectDocumentData> implements ConnectDocumentReference<T> {
|
|
9
|
-
private reference: DocumentReference<T>
|
|
10
|
-
|
|
11
|
-
constructor(private path: string, private firestore: Firestore) {
|
|
12
|
-
this.reference = this.firestore.doc(this.path).withConverter({
|
|
13
|
-
toFirestore: (data) => data as any,
|
|
14
|
-
fromFirestore: (snapshot) => {
|
|
15
|
-
return { id: snapshot.id, ...snapshot.data() } as T
|
|
16
|
-
},
|
|
17
|
-
})
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async get(): Promise<ConnectDocumentSnapshot<T>> {
|
|
21
|
-
return new ConnectBaseDocumentSnapshot(await this.reference.get())
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getId(): string {
|
|
25
|
-
return this.reference.id
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async save(data: T): Promise<ConnectDocumentReference<T>> {
|
|
29
|
-
if (this.reference) this.reference.update(data)
|
|
30
|
-
else await this.reference.set(data)
|
|
31
|
-
|
|
32
|
-
return this
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async delete(): Promise<void> {
|
|
36
|
-
await this.reference.delete()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
withConverter(params: {
|
|
40
|
-
toFirestore: (data: T) => ConnectDocumentData<T>
|
|
41
|
-
fromFirestore: (snapshot: ConnectDocumentSnapshot<T>, options?: ConnectSnapshotOptions) => T
|
|
42
|
-
}): ConnectDocumentReference<T> {
|
|
43
|
-
this.reference = this.reference.withConverter({
|
|
44
|
-
toFirestore: (data: T) => params.toFirestore(data),
|
|
45
|
-
fromFirestore: (snapshot: QueryDocumentSnapshot<T>, options?: ConnectSnapshotOptions) =>
|
|
46
|
-
params.fromFirestore(new ConnectBaseDocumentSnapshot(snapshot), options),
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
return this
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConnectCollectionReference,
|
|
3
|
-
ConnectDocumentData,
|
|
4
|
-
ConnectDocumentReference,
|
|
5
|
-
ConnectFirestore,
|
|
6
|
-
} from '@infrab4a/connect'
|
|
7
|
-
import { Injectable } from '@nestjs/common'
|
|
8
|
-
import { Firestore } from 'firebase-admin/firestore'
|
|
9
|
-
|
|
10
|
-
import { ConnectCollectionService } from './connect-collection.service'
|
|
11
|
-
import { ConnectDocumentService } from './connect-document.service'
|
|
12
|
-
|
|
13
|
-
@Injectable()
|
|
14
|
-
export class ConnectFirestoreService implements ConnectFirestore {
|
|
15
|
-
constructor(private readonly firestore: Firestore) {}
|
|
16
|
-
|
|
17
|
-
public getCollection<T extends ConnectDocumentData>(path: string): ConnectCollectionReference<T> {
|
|
18
|
-
return new ConnectCollectionService<T>(path, this.firestore)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public getDocument<T extends ConnectDocumentData>(path: string): ConnectDocumentReference<T> {
|
|
22
|
-
return new ConnectDocumentService<T>(path, this.firestore)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ConnectDocumentData } from '@infrab4a/connect'
|
|
2
|
-
|
|
3
|
-
import { ConnectCollectionReference } from './connect-collection-reference'
|
|
4
|
-
import { ConnectDocumentReference } from './connect-document-reference'
|
|
5
|
-
|
|
6
|
-
export interface ConnectFirestore {
|
|
7
|
-
getCollection<T extends ConnectDocumentData>(path: string): ConnectCollectionReference<T>
|
|
8
|
-
getDocument<T extends ConnectDocumentData>(path: string): ConnectDocumentReference<T>
|
|
9
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './connect-query-snapshot.type'
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ConnectDocumentData, ConnectSnapshotOptions } from '@infrab4a/connect'
|
|
2
|
-
import { DocumentSnapshot } from 'firebase-admin/firestore'
|
|
3
|
-
|
|
4
|
-
import { ConnectDocumentSnapshot } from '../types'
|
|
5
|
-
|
|
6
|
-
export class ConnectBaseDocumentSnapshot<T extends ConnectDocumentData = ConnectDocumentData>
|
|
7
|
-
implements ConnectDocumentSnapshot<T>
|
|
8
|
-
{
|
|
9
|
-
public id: string
|
|
10
|
-
public exists: boolean
|
|
11
|
-
|
|
12
|
-
constructor(private readonly connectDocumentSnapshot: DocumentSnapshot<T>) {
|
|
13
|
-
this.id = connectDocumentSnapshot.id
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public isNotEmpty(): boolean {
|
|
17
|
-
return this.connectDocumentSnapshot.exists
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public data(_options?: ConnectSnapshotOptions): T {
|
|
21
|
-
return this.connectDocumentSnapshot.data()
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public get(fieldPath: string) {
|
|
25
|
-
return this.connectDocumentSnapshot.get(fieldPath)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './connect-base-document-snapshot.vo'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './firestore'
|
package/src/infra/index.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
addDays,
|
|
3
|
-
BusinessError,
|
|
4
|
-
Checkout,
|
|
5
|
-
format,
|
|
6
|
-
PagarmeCredentials,
|
|
7
|
-
PagarmePaymentStatus,
|
|
8
|
-
Payment,
|
|
9
|
-
PaymentError,
|
|
10
|
-
PaymentProviderBankSlip,
|
|
11
|
-
PaymentRepository,
|
|
12
|
-
PaymentTransaction,
|
|
13
|
-
} from '@infrab4a/connect'
|
|
14
|
-
import pagarme from 'pagarme'
|
|
15
|
-
|
|
16
|
-
export class PagarmeBankSlipAPIAdapter implements PaymentProviderBankSlip {
|
|
17
|
-
constructor(private credentials: PagarmeCredentials, private paymentRepository: PaymentRepository) {}
|
|
18
|
-
|
|
19
|
-
public async pay(checkout: Checkout): Promise<Payment> {
|
|
20
|
-
try {
|
|
21
|
-
const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY })
|
|
22
|
-
const payload = this.createBoletoPayment(checkout)
|
|
23
|
-
const result = await client.transactions.create(payload)
|
|
24
|
-
|
|
25
|
-
console.warn('[PAGARME BOLETO DATA TO SEND]', payload)
|
|
26
|
-
console.warn('result PagarmeBankSlipAPIAdapter', JSON.stringify(result))
|
|
27
|
-
|
|
28
|
-
if (result.status !== PagarmePaymentStatus['Em processamento']) {
|
|
29
|
-
return Promise.reject(
|
|
30
|
-
new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
31
|
-
checkoutId: checkout.id,
|
|
32
|
-
userEmail: checkout.user.email,
|
|
33
|
-
info: result,
|
|
34
|
-
}),
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const payment = await this.paymentRepository.create({
|
|
39
|
-
createdAt: new Date(),
|
|
40
|
-
updatedAt: new Date(),
|
|
41
|
-
userId: checkout.user.id,
|
|
42
|
-
checkoutId: checkout.id,
|
|
43
|
-
totalPrice: checkout.totalPrice,
|
|
44
|
-
paymentProvider: 'pagarMe',
|
|
45
|
-
transaction: result,
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return payment
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error('Error PagarmeBankSlipAPIAdapter', JSON.stringify(error))
|
|
51
|
-
throw new PaymentError('Houve uma falha ao gerar o boleto. Tente novamente', {
|
|
52
|
-
checkoutId: checkout.id,
|
|
53
|
-
userEmail: checkout.user.email,
|
|
54
|
-
info: error,
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
public async getBoletoTransaction(paymentId: number): Promise<PaymentTransaction> {
|
|
60
|
-
try {
|
|
61
|
-
const client = await pagarme.client.connect({ api_key: this.credentials.API_KEY })
|
|
62
|
-
const result = await client.transactions.find({ id: paymentId })
|
|
63
|
-
|
|
64
|
-
return result as PaymentTransaction
|
|
65
|
-
} catch (error) {
|
|
66
|
-
throw new BusinessError('Houve uma falha buscar o boleto com paymentId: ' + paymentId, {
|
|
67
|
-
paymentId,
|
|
68
|
-
info: error,
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private createBoletoPayment(checkout: Checkout) {
|
|
74
|
-
return {
|
|
75
|
-
api_key: this.credentials.API_KEY,
|
|
76
|
-
amount: Math.floor(checkout.totalPrice * 100),
|
|
77
|
-
boleto_rules: ['strict_expiration_date'],
|
|
78
|
-
boleto_instructions: 'Sr. Caixa, NÃO aceitar o pagamento após o vencimento.',
|
|
79
|
-
boleto_expiration_date: format(addDays(new Date(), 3), 'yyyy-MM-dd'),
|
|
80
|
-
payment_method: 'boleto',
|
|
81
|
-
postback_url: this.credentials.URL_POSTBACK,
|
|
82
|
-
customer: {
|
|
83
|
-
external_id: checkout.user.id,
|
|
84
|
-
type: 'individual',
|
|
85
|
-
country: 'br',
|
|
86
|
-
name: checkout.user.displayName,
|
|
87
|
-
documents: [
|
|
88
|
-
{
|
|
89
|
-
type: 'cpf',
|
|
90
|
-
number: checkout.user.cpf,
|
|
91
|
-
},
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|