Skip to content

Commit

Permalink
feat: Initial commit add standalone MPR postgress module
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmatau79 committed Dec 18, 2024
1 parent 1f30fa6 commit 71eb74e
Show file tree
Hide file tree
Showing 10 changed files with 2,403 additions and 1,307 deletions.
32 changes: 32 additions & 0 deletions packages/postgress/config/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { LogLevel } from '@credo-ts/core'
import dotenv from 'dotenv'

dotenv.config()

export const AGENT_PORT = Number(process.env.AGENT_PORT || 4000)
export const AGENT_LOG_LEVEL = process.env.AGENT_LOG_LEVEL ? Number(process.env.AGENT_LOG_LEVEL) : LogLevel.debug

export const AGENT_NAME = process.env.AGENT_NAME || 'Test Cloud Agent'
export const AGENT_ENDPOINTS = process.env.AGENT_ENDPOINTS?.replace(' ', '').split(',') || ['ws://localhost:4000']
export const AGENT_PUBLIC_DID = process.env.AGENT_PUBLIC_DID
export const HTTP_SUPPORT = Boolean(process.env.HTTP_SUPPORT ?? true)
export const WS_SUPPORT = Boolean(process.env.WS_SUPPORT ?? true)

// Wallet
export const WALLET_NAME = process.env.WALLET_NAME || 'test-cloud-agent'
export const WALLET_KEY = process.env.WALLET_KEY || 'Test Cloud Agent'
export const KEY_DERIVATION_METHOD = process.env.KEY_DERIVATION_METHOD
export const POSTGRES_HOST = process.env.POSTGRES_HOST
export const POSTGRES_USER = process.env.POSTGRES_USER
export const POSTGRES_PASSWORD = process.env.POSTGRES_PASSWORD
export const POSTGRES_ADMIN_USER = process.env.POSTGRES_ADMIN_USER
export const POSTGRES_ADMIN_PASSWORD = process.env.POSTGRES_ADMIN_PASSWORD

export enum MessageState {
pending = 'pending',
sending = 'sending',
}

// FCM variables build url
export const FCM_SERVICE_BASE_URL =
process.env.FCM_SERVICE_BASE_URL || 'http://localhost:3001/fcm/fcmNotificationSender/send'
27 changes: 27 additions & 0 deletions packages/postgress/config/dbCollections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const tableNameMessage = 'storequeuedmessage'

export const createTableMessage = `
CREATE TABLE IF NOT EXISTS ${tableNameMessage} (
id VARCHAR(20) DEFAULT substr(md5(random()::text), 1, 20) PRIMARY KEY,
connectionId VARCHAR(255),
recipientKeys TEXT[],
encryptedMessage JSONB,
state VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS "${tableNameMessage}_connectionId_index" ON "queuedmessages" (connectionId);
CREATE INDEX IF NOT EXISTS "${tableNameMessage}_created_at_index" ON "queuedmessages" (created_at);
`

export const tableNameLive = 'storelivesession'

export const createTableLive = `
CREATE TABLE IF NOT EXISTS ${tableNameLive} (
sessionid VARCHAR(255) PRIMARY KEY,
connectionid VARCHAR(50),
instance VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS "${tableNameLive}_connectionid" ON "${tableNameLive}" USING btree ("connectionid");`
21 changes: 21 additions & 0 deletions packages/postgress/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Config } from '@jest/types'

const config: Config.InitialOptions = {
preset: 'ts-jest',
testEnvironment: 'node',
coveragePathIgnorePatterns: ['/build/', '/node_modules/', '/__tests__/', 'tests'],
coverageDirectory: '<rootDir>/coverage/',
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
isolatedModules: true,
},
],
'^.+\\.jsx?$': require.resolve('babel-jest'),
},
moduleNameMapper: { '^uuid$': 'uuid' },
}

export default config
46 changes: 46 additions & 0 deletions packages/postgress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@2060.io/credo-ts-message-pickup-repository-pg",
"main": "build/index",
"types": "build/index",
"version": "0.0.1",
"files": [
"build"
],
"publishConfig": {
"access": "public"
},
"description": "Message Pickup Repository postgress module",
"license": "Apache-2.0",
"homepage": "https://github.com/2060-io/message-pickup-repository/tree/main/packages/postgress",
"repository": {
"type": "git",
"url": "https://github.com/2060-io/message-pickup-repository",
"directory": "packages/postgress"
},
"scripts": {
"build": "yarn run clean && yarn run compile",
"clean": "rimraf -rf ./build",
"compile": "tsc -p tsconfig.build.json",
"prepublishOnly": "yarn run build",
"test": "jest"
},
"dependencies": {
"@credo-ts/core": "^0.5.11",
"loglevel": "^1.8.0",
"pg": "^8.11.3",
"pg-pubsub": "^0.8.1",
"typescript": "^4.0.0"
},
"devDependencies": {
"@types/node": "^16.0.0",
"@types/pg": "^8.11.10",
"jest": "^27.0.0",
"ts-jest": "^27.0.0",
"ts-loader": "^9.0.0",
"webpack": "^5.0.0",
"webpack-cli": "^4.0.0"
},
"peerDependencies": {
"@credo-ts/core": "^0.5.11"
}
}
Loading

0 comments on commit 71eb74e

Please sign in to comment.