diff --git a/apps/peatix-adapter/.env.example b/apps/peatix-adapter/.env.example index 032166a6..fe986aa9 100644 --- a/apps/peatix-adapter/.env.example +++ b/apps/peatix-adapter/.env.example @@ -4,3 +4,5 @@ PUPPETEER_EXECUTABLE_PATH= PEATIX_EVENT_ID= PEATIX_BASIC_EMAIL= PEATIX_BASIC_PASSWORD= +SUPABASE_URL= +SUPABASE_KEY= diff --git a/apps/peatix-adapter/package.json b/apps/peatix-adapter/package.json index 8721fd6e..49563e56 100644 --- a/apps/peatix-adapter/package.json +++ b/apps/peatix-adapter/package.json @@ -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" diff --git a/apps/peatix-adapter/src/after-purchase/after-purchase.module.ts b/apps/peatix-adapter/src/after-purchase/after-purchase.module.ts index 7675bf3a..52f2ceea 100644 --- a/apps/peatix-adapter/src/after-purchase/after-purchase.module.ts +++ b/apps/peatix-adapter/src/after-purchase/after-purchase.module.ts @@ -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: [ @@ -22,6 +24,7 @@ import { PeatixOrderModule } from 'src/peatix-order/peatix-order.module' }), EnvModule, HttpModule, + SupabaseModule, PeatixOrderModule, ], providers: [ @@ -33,6 +36,7 @@ import { PeatixOrderModule } from 'src/peatix-order/peatix-order.module' }, AfterPurchaseCommand, AfterPurchaseService, + SupabaseService, PeatixOrderService, ], }) diff --git a/apps/peatix-adapter/src/after-purchase/after-purchase.service.ts b/apps/peatix-adapter/src/after-purchase/after-purchase.service.ts index 972ca313..f4a317be 100644 --- a/apps/peatix-adapter/src/after-purchase/after-purchase.service.ts +++ b/apps/peatix-adapter/src/after-purchase/after-purchase.service.ts @@ -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) { // } async apply() { - const orders = this.peatixOrderService.getOrders() - this.logger.log(orders) + this.peatixOrderService.getOrders() } } diff --git a/apps/peatix-adapter/src/env/env.service.ts b/apps/peatix-adapter/src/env/env.service.ts index 827ef3e4..d331eebe 100644 --- a/apps/peatix-adapter/src/env/env.service.ts +++ b/apps/peatix-adapter/src/env/env.service.ts @@ -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') + } } diff --git a/apps/peatix-adapter/src/env/utils/configuration.ts b/apps/peatix-adapter/src/env/utils/configuration.ts index bc629a2f..b6bfa072 100644 --- a/apps/peatix-adapter/src/env/utils/configuration.ts +++ b/apps/peatix-adapter/src/env/utils/configuration.ts @@ -2,4 +2,6 @@ export const configuration = () => ({ peatixEventId: process.env.PEATIX_EVENT_ID || '', peatixBasicEmail: process.env.PEATIX_BASIC_EMAIL || '', peatixBasicPassword: process.env.PEATIX_BASIC_PASSWORD || '', + supabaseUrl: process.env.SUPABASE_URL || '', + supabaseKey: process.env.SUPABASE_KEY || '', }) diff --git a/apps/peatix-adapter/src/peatix-order/peatix-order.module.ts b/apps/peatix-adapter/src/peatix-order/peatix-order.module.ts index edb39593..72c92d15 100644 --- a/apps/peatix-adapter/src/peatix-order/peatix-order.module.ts +++ b/apps/peatix-adapter/src/peatix-order/peatix-order.module.ts @@ -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: [ @@ -16,6 +18,7 @@ import { IPuppeteerService, PuppeteerService } from 'src/puppeteer/puppeteer.ser }), EnvModule, HttpModule, + SupabaseModule, ], providers: [ ConfigService, @@ -24,6 +27,7 @@ import { IPuppeteerService, PuppeteerService } from 'src/puppeteer/puppeteer.ser provide: IPuppeteerService, useClass: PuppeteerService, }, + SupabaseService, PeatixOrderService, ], exports: [PeatixOrderService], diff --git a/apps/peatix-adapter/src/peatix-order/peatix-order.service.ts b/apps/peatix-adapter/src/peatix-order/peatix-order.service.ts index d900263d..7ad5659e 100644 --- a/apps/peatix-adapter/src/peatix-order/peatix-order.service.ts +++ b/apps/peatix-adapter/src/peatix-order/peatix-order.service.ts @@ -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') @@ -21,6 +22,7 @@ export class PeatixOrderService extends ScraperPage { envService: EnvService, puppeteerService: IPuppeteerService, private readonly httpService: HttpService, + private readonly supabaseService: SupabaseService, ) { super(envService, puppeteerService) } @@ -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 [] } } } diff --git a/apps/peatix-adapter/src/supabase/supabase.module.ts b/apps/peatix-adapter/src/supabase/supabase.module.ts new file mode 100644 index 00000000..acdce199 --- /dev/null +++ b/apps/peatix-adapter/src/supabase/supabase.module.ts @@ -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 {} diff --git a/apps/peatix-adapter/src/supabase/supabase.service.ts b/apps/peatix-adapter/src/supabase/supabase.service.ts new file mode 100644 index 00000000..087f4d22 --- /dev/null +++ b/apps/peatix-adapter/src/supabase/supabase.service.ts @@ -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 + } +} diff --git a/bun.lockb b/bun.lockb index dad087da..413ca899 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/yarn.lock b/yarn.lock index 2b020415..66199c12 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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": @@ -4105,6 +4105,13 @@ dependencies: "@supabase/node-fetch" "^2.6.14" +"@supabase/auth-js@2.64.2": + 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/functions-js@2.2.2": version "2.2.2" resolved "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.2.2.tgz" @@ -4112,6 +4119,13 @@ dependencies: "@supabase/node-fetch" "^2.6.14" +"@supabase/functions-js@2.3.1": + 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/node-fetch@2.6.15", "@supabase/node-fetch@^2.6.14": version "2.6.15" resolved "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.15.tgz" @@ -4126,6 +4140,13 @@ dependencies: "@supabase/node-fetch" "^2.6.14" +"@supabase/postgrest-js@1.15.2": + 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/realtime-js@2.9.3": version "2.9.3" resolved "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.9.3.tgz" @@ -4136,6 +4157,16 @@ "@types/ws" "^8.5.10" ws "^8.14.2" +"@supabase/realtime-js@2.9.5": + 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/storage-js@2.5.5": version "2.5.5" resolved "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.5.5.tgz" @@ -4155,6 +4186,18 @@ "@supabase/realtime-js" "2.9.3" "@supabase/storage-js" "2.5.5" +"@supabase/supabase-js@2.43.1": + 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/sax@0.2.0": version "0.2.0" resolved "https://registry.npmjs.org/@trysound/sax/-/sax-0.2.0.tgz" @@ -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"