Skip to content

Commit

Permalink
feat: supabase initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyuujin committed May 11, 2024
1 parent 0a0c425 commit b5ec9b0
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 17 deletions.
2 changes: 2 additions & 0 deletions apps/peatix-adapter/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ PUPPETEER_EXECUTABLE_PATH=
PEATIX_EVENT_ID=
PEATIX_BASIC_EMAIL=
PEATIX_BASIC_PASSWORD=
SUPABASE_URL=
SUPABASE_KEY=
1 change: 1 addition & 0 deletions apps/peatix-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@nestjs/common": "10.3.7",
"@nestjs/core": "10.3.7",
"@nestjs/platform-express": "10.3.7",
"@supabase/supabase-js": "2.43.1",
"puppeteer": "19.9.1",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { EnvModule } from '../env/env.module'
import { PeatixOrderService } from '../peatix-order/peatix-order.service'
import { HttpModule } from '@nestjs/axios'
import { PeatixOrderModule } from 'src/peatix-order/peatix-order.module'
import { SupabaseModule } from 'src/supabase/supabase.module'
import { SupabaseService } from 'src/supabase/supabase.service'

@Module({
imports: [
Expand All @@ -22,6 +24,7 @@ import { PeatixOrderModule } from 'src/peatix-order/peatix-order.module'
}),
EnvModule,
HttpModule,
SupabaseModule,
PeatixOrderModule,
],
providers: [
Expand All @@ -33,6 +36,7 @@ import { PeatixOrderModule } from 'src/peatix-order/peatix-order.module'
},
AfterPurchaseCommand,
AfterPurchaseService,
SupabaseService,
PeatixOrderService,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { PeatixOrderService } from '../peatix-order/peatix-order.service'
export class AfterPurchaseService {
private readonly logger = new Logger(AfterPurchaseService.name)

constructor(private readonly peatixOrderService: PeatixOrderService,) {
constructor(private readonly peatixOrderService: PeatixOrderService) {

Check warning on line 8 in apps/peatix-adapter/src/after-purchase/after-purchase.service.ts

View workflow job for this annotation

GitHub Actions / lint (18.19.0)

'peatixOrderService' is defined but never used
//
}

async apply() {
const orders = this.peatixOrderService.getOrders()
this.logger.log(orders)
this.peatixOrderService.getOrders()
}
}
8 changes: 8 additions & 0 deletions apps/peatix-adapter/src/env/env.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ export class EnvService {
get PEATIX_BASIC_PASSWORD() {
return this.configService.getOrThrow('peatixBasicPassword')
}

get SUPABASE_URL() {
return this.configService.getOrThrow('supabaseUrl')
}

get SUPABASE_KEY() {
return this.configService.getOrThrow('supabaseKey')
}
}
2 changes: 2 additions & 0 deletions apps/peatix-adapter/src/env/utils/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export const configuration = () => ({
peatixEventId: process.env.PEATIX_EVENT_ID || '',

Check warning on line 2 in apps/peatix-adapter/src/env/utils/configuration.ts

View workflow job for this annotation

GitHub Actions / lint (18.19.0)

PEATIX_EVENT_ID is not listed as a dependency in turbo.json
peatixBasicEmail: process.env.PEATIX_BASIC_EMAIL || '',
peatixBasicPassword: process.env.PEATIX_BASIC_PASSWORD || '',
supabaseUrl: process.env.SUPABASE_URL || '',
supabaseKey: process.env.SUPABASE_KEY || '',
})
4 changes: 4 additions & 0 deletions apps/peatix-adapter/src/peatix-order/peatix-order.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { EnvModule } from 'src/env/env.module'
import { HttpModule } from '@nestjs/axios'
import { EnvService } from 'src/env/env.service'
import { IPuppeteerService, PuppeteerService } from 'src/puppeteer/puppeteer.service'
import { SupabaseModule } from 'src/supabase/supabase.module'
import { SupabaseService } from 'src/supabase/supabase.service'

@Module({
imports: [
Expand All @@ -16,6 +18,7 @@ import { IPuppeteerService, PuppeteerService } from 'src/puppeteer/puppeteer.ser
}),
EnvModule,
HttpModule,
SupabaseModule,
],
providers: [
ConfigService,
Expand All @@ -24,6 +27,7 @@ import { IPuppeteerService, PuppeteerService } from 'src/puppeteer/puppeteer.ser
provide: IPuppeteerService,
useClass: PuppeteerService,
},
SupabaseService,
PeatixOrderService,
],
exports: [PeatixOrderService],
Expand Down
23 changes: 10 additions & 13 deletions apps/peatix-adapter/src/peatix-order/peatix-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { promises, readFileSync } from 'fs'
import { ScraperPage } from '../scraper-page/scraper-page'
import { HttpService } from '@nestjs/axios'
import { JSON_USAGE, PUPPETEER_USAGE } from '../features'
import { SupabaseService } from 'src/supabase/supabase.service'

const { parse } = require('csv-parse/sync')

Expand All @@ -21,6 +22,7 @@ export class PeatixOrderService extends ScraperPage {
envService: EnvService,
puppeteerService: IPuppeteerService,
private readonly httpService: HttpService,
private readonly supabaseService: SupabaseService,
) {
super(envService, puppeteerService)
}
Expand Down Expand Up @@ -160,33 +162,28 @@ export class PeatixOrderService extends ScraperPage {
)

try {
let attendees = []

if (PUPPETEER_USAGE) {
await this.login(page)
await this.download(page, (res: PeatixCsv[]) => {
attendees = res
this.logger.log(res)
await this.download(page, async (res: PeatixCsv[]) => {
const attendees = res
this.logger.log(attendees)

const adminUsers = await this.supabaseService.fetchAdminUsers()
this.logger.log(adminUsers)
})
}

if (JSON_USAGE) {
const res = await this.fetchJson<{ json_data: Peatix }>()
attendees = res.json_data.event.attendees
this.logger.log(res)
const attendees = res.json_data.event.attendees
this.logger.log(attendees)
}

this.logger.log(attendees)

await browser.close()

return attendees
} catch (e) {
this.logger.error(e)

await browser.close()

return []
}
}
}
24 changes: 24 additions & 0 deletions apps/peatix-adapter/src/supabase/supabase.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Module } from '@nestjs/common'
import { ConfigModule, ConfigService } from '@nestjs/config'
import { SupabaseService } from './supabase.service'
import { EnvModule } from 'src/env/env.module'
import { configuration } from 'src/env/utils'
import { EnvService } from 'src/env/env.service'

@Module({
imports: [
ConfigModule.forRoot({
envFilePath: '.env',
expandVariables: true,
load: [configuration],
}),
EnvModule,
],
providers: [
ConfigService,
EnvService,
SupabaseService,
],
exports: [SupabaseService],
})
export class SupabaseModule {}
35 changes: 35 additions & 0 deletions apps/peatix-adapter/src/supabase/supabase.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Injectable, Logger } from '@nestjs/common'
import { SupabaseClient, createClient } from '@supabase/supabase-js'
import { EnvService } from 'src/env/env.service'

@Injectable()
export class SupabaseService {
private readonly logger = new Logger(SupabaseService.name)

private client: SupabaseClient

constructor(private readonly envService: EnvService) {
//
}

private getClient() {
if (this.client) {
this.logger.log('Client already exists')
return
}

this.client = createClient(
this.envService.SUPABASE_URL,
this.envService.SUPABASE_KEY,
)

this.client
}

public async fetchAdminUsers() {
this.getClient()

const { data } = await this.client.from('admin_users').select()
return data
}
}
Binary file modified bun.lockb
Binary file not shown.
46 changes: 45 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# bun ./bun.lockb --hash: 5B38A1FD462F2CC0-cc5d82060f66f195-E63DC497A5056974-f571d51b1211fdbd
# bun ./bun.lockb --hash: CEA8F34611DBFD29-3fde5bb29df8a869-2EDC06F627F40462-17c439776c20cdcd


"@aashutoshrathi/word-wrap@^1.2.3":
Expand Down Expand Up @@ -4105,13 +4105,27 @@
dependencies:
"@supabase/node-fetch" "^2.6.14"

"@supabase/[email protected]":
version "2.64.2"
resolved "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.64.2.tgz"
integrity sha512-s+lkHEdGiczDrzXJ1YWt2y3bxRi+qIUnXcgkpLSrId7yjBeaXBFygNjTaoZLG02KNcYwbuZ9qkEIqmj2hF7svw==
dependencies:
"@supabase/node-fetch" "^2.6.14"

"@supabase/[email protected]":
version "2.2.2"
resolved "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.2.2.tgz"
integrity sha512-sJGq1nludmi7pY/fdtCpyY/pYonx7MfHdN408bqb736guWcVI1AChYVbI4kUM978EuOE4Ci6l7bUudfGg07QRw==
dependencies:
"@supabase/node-fetch" "^2.6.14"

"@supabase/[email protected]":
version "2.3.1"
resolved "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.3.1.tgz"
integrity sha512-QyzNle/rVzlOi4BbVqxLSH828VdGY1RElqGFAj+XeVypj6+PVtMlD21G8SDnsPQDtlqqTtoGRgdMlQZih5hTuw==
dependencies:
"@supabase/node-fetch" "^2.6.14"

"@supabase/[email protected]", "@supabase/node-fetch@^2.6.14":
version "2.6.15"
resolved "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.15.tgz"
Expand All @@ -4126,6 +4140,13 @@
dependencies:
"@supabase/node-fetch" "^2.6.14"

"@supabase/[email protected]":
version "1.15.2"
resolved "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-1.15.2.tgz"
integrity sha512-9/7pUmXExvGuEK1yZhVYXPZnLEkDTwxgMQHXLrN5BwPZZm4iUCL1YEyep/Z2lIZah8d8M433mVAUEGsihUj5KQ==
dependencies:
"@supabase/node-fetch" "^2.6.14"

"@supabase/[email protected]":
version "2.9.3"
resolved "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.9.3.tgz"
Expand All @@ -4136,6 +4157,16 @@
"@types/ws" "^8.5.10"
ws "^8.14.2"

"@supabase/[email protected]":
version "2.9.5"
resolved "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.9.5.tgz"
integrity sha512-TEHlGwNGGmKPdeMtca1lFTYCedrhTAv3nZVoSjrKQ+wkMmaERuCe57zkC5KSWFzLYkb5FVHW8Hrr+PX1DDwplQ==
dependencies:
"@supabase/node-fetch" "^2.6.14"
"@types/phoenix" "^1.5.4"
"@types/ws" "^8.5.10"
ws "^8.14.2"

"@supabase/[email protected]":
version "2.5.5"
resolved "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.5.5.tgz"
Expand All @@ -4155,6 +4186,18 @@
"@supabase/realtime-js" "2.9.3"
"@supabase/storage-js" "2.5.5"

"@supabase/[email protected]":
version "2.43.1"
resolved "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.43.1.tgz"
integrity sha512-A+RV50mWNtyKo6M0u4G6AOqEifQD+MoOjZcpRkPMPpEAFgMsc2dt3kBlBlR/MgZizWQgUKhsvrwKk0efc8g6Ug==
dependencies:
"@supabase/auth-js" "2.64.2"
"@supabase/functions-js" "2.3.1"
"@supabase/node-fetch" "2.6.15"
"@supabase/postgrest-js" "1.15.2"
"@supabase/realtime-js" "2.9.5"
"@supabase/storage-js" "2.5.5"

"@trysound/[email protected]":
version "0.2.0"
resolved "https://registry.npmjs.org/@trysound/sax/-/sax-0.2.0.tgz"
Expand Down Expand Up @@ -5592,6 +5635,7 @@
"@nestjs/common" "10.3.7"
"@nestjs/core" "10.3.7"
"@nestjs/platform-express" "10.3.7"
"@supabase/supabase-js" "2.43.1"
puppeteer "19.9.1"
reflect-metadata "0.2.2"
rxjs "7.8.1"
Expand Down

0 comments on commit b5ec9b0

Please sign in to comment.