Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
phinternal-api
Advanced tools
Internal API used by phin-web, phin-service-network, and phin-api. This project owns the main phin Postgresql database and its migrations.
Install Homebrew [http://brew.sh/]
Install Postgres 13.x with postgis 3.0.3
Ensure that createdb
is on your $PATH: http://postgresapp.com/documentation/cli-tools.html.
npm install
git submodule init
git submodule update
npm run create:pguser
for migrationsphinternal
database inside Postgres by running npm run create:db
.phinternal-swagger.yml
with API route changes.tests\integration
for all routes. Tests should verify database modifications and check validations.phin-common-js/lib/phinternal
.migrations
which performs the change up
and down
.models
for the new table or change.cd ./tools/heroku-phin && npm install
.heroku plugins:link ./tools/heroku-phin
.heroku
and verifying that phin
shows up in the command list. You can also run heroku phin --help
for a list of options.You can export a user from any environment to a JSON file that can be imported to another database. You can view usage instructions by running heroku phin:export-user --help
.
Examples:
Export from a Heroku database: heroku phin:export-user --app=[heroku app name] --userId=456
Export from a local database: heroku phin:export-user --userId=456
After exporting a user to a JSON file you can import that file to a local or remote database. You can view usage instructions by running heroku phin:import-user --help
.
Examples:
Importing into your local database: heroku phin:import-user [exported account file].json
Importing into a Heroku database: heroku phin:import-user --app=[heroku app name] [exported account file].json
To create an admin user in a local database:
heroku phin:create-user --email=barack@gmail.com --password=muscularMichelle96 --firstName=Barack --lastName=Obama --isAdmin
To create a standard user just leave out the admin
flag:
heroku phin:create-user --email=barack@gmail.com --password=muscularMichelle96 --firstName=Barack --lastName=Obama
To create a user in a Heroku database just provide the --app
paramater and choose the correct database.
To change a pHin user's password in your local database run the following command:
heroku phin:change-password --email=[email] --password=[new password]
To insert some fake user accounts ( the same accounts we use in tests ) run the following command:
heroku phin:insert-fake-accounts
To change a user's password in a Heroku database just provide the --app
paramater and choose the correct database.
Run heroku phin:run --app=[heroku app name] script.js [args]
. This command will
query heroku and prompt you to select a database connected to the app. It will then execute your script with the following
environemnt variables:
This allows you to build scripts that connect to our heroku postgres databases which accept the env variables above to keep
us from committing database credentials or having to load ./src/config
.
brew install rabbitmq
.~/.bash_profile
-> export PATH="/usr/local/sbin:$PATH"
.rabbitmq-server
.Install version 12.3.x with postgis 3.0.x
sudo apt install postgresql-9.6 postgresql-9.6-postgis-2.3 postgresql-9.6-postgis-2.3-scripts postgresql-contrib-9.6
npm run drop:db
# Reset your local environment by dropping and creating from scratchnpm run create:pguser
# Create postgres role if you are running it for first timenpm run create:db
npm run migrate:up
# Run pending migrations up to latest version.npm run drop:db
# Reset your local environment by dropping and creating from scratchnpm run create:pguser
# Create postgres role if you are running it for first timenpm run create:db
npm run migrate:up
# Run pending migrations up to latest version.npm run migrate:down
# Revert the last migration run.To load static DB data in your local database, run npm run load:static-data
.
To load the static data on Heroku, run heroku run bash
then npm run load:static-data
.
When it's time to add a new migration so that you can make changes to the database schema, run npm run migration:create [name]
. An
empty migration file will be created in the migrations
folder. Change the name of the file to reflect your changes, add both
up
and down
code, and test both up
and down
.
Login to the Heroku instance using npm run bash:prod
or npm run bash:stage
and run npm run migrate:heroku:up
.
// DUMP LOCAL DATABASE
pg_dump --host=localhost --dbname=phinternal -a -b -f dump.sql
// IMPORT LOCAL
psql --host=localhost --dbname=phinternal -f dump.sql
// IMPORT TO HEROKU
psql --host=ec2-54-227-247-40.compute-1.amazonaws.com --dbname=d7eb3pqu74oa4f --port=6702 --username=ufnehfa9ur7gev -f dump.sql
You can also download DB backups from postgres and import them locally:
pg_restore --verbose --clean --no-acl --no-owner -h localhost -d phinternal [filename of downloaded backup]
EXAMPLES
SELECT setval('"UserAudits_user_audit_id_seq"', max("user_audit_id")) FROM "UserAudits";
SELECT setval('"Users_userId_seq"', max("userId")) FROM "Users";
This project includes npm scripts for testing, which create their own database for testing before they are run and drop them after the test completes (doesn't matter if its successful or not)
The complete test suite can be executed by using the command npm test
tests/integration/
and are run with the command: npm run test:integration
tests/database/
and are run with the command: npm run test:database
tests/unit/
and are run with the command: npm run test:unit
Important Note: Chai and Assert (chai.assert
) are loaded as globals before the tests are instantiated, so they are no longer needed to be required on every test file
You can test the chem engine by inserting test data for a vessel and enqueing a chem-check for that vessel.
If you run into an error building a deployment try the following:
Install the Heroku Repo plugin if you haven't already
heroku plugins:install https://github.com/heroku/heroku-repo.git
Run
heroku repo:purge-cache -a appname
If your heroku command line tools will not exit after completing. Delete the following folders:
~/.local/share/heroku
~/Library/Caches/heroku
/// List addons
heroku:addons
// Attach an addon
heroku addons:attach postgresql-tetrahedral-6520 --as SERVICENETWORK_DATABASE_URL
// Detach an addon
heroku addons:detach HEROKU_POSTGRESQL_GREEN
heroku drains:add syslog+tls://logs4.papertrailapp.com:31567 --app [appname]
heroku drains --app [appname]
- the value in parenthesis at the end of the drain, leave out the d.
at the frontd.
at the front ) and paste it into the filter box.From here I learned that you can control some of the V8 garbage collection behavior. Heroku recommends these Procfile settings for 512Mb instances:
node --optimize_for_size --max_old_space_size=460 --gc_interval=100
This should trigger GC before the memory warning kicks in. Here is the article for reference: Heroku Node Habits.
Run heroku pg:psql HEROKU_POSTGRESQL_BRONZE --app=phinternal
Then run \copy (SELECT hardware_id, sample_index, temp_c, ph, orp_mv, battery_mv, sample_date FROM "PhinDeviceSamples" ORDER BY hardware_id ASC, sample_date DESC ) TO dump.csv CSV DELIMITER ','
> psql
dyld: Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/bin/bash
Reason: image not found
Resolved With:
ln -s /usr/local/opt/readline/lib/libreadline.7.dylib /usr/local/opt/readline/lib/libreadline.6.dylib
Having the testing blues? Has your shiny new table started throwing validation errors the next time you run your tests? I have good news for you, this is an easy fix! You forgot to update the 'testDb/tables' file. Go add your table in the appropriate referential point (e.g. if it depends on Vessel it needs to be below Vessel in the list)
\copy (SELECT * FROM "PhinDeviceSamples" WHERE EXTRACT(YEAR FROM sample_date) = 2017 AND EXTRACT(MONTH FROM sample_date) = 1 ORDER BY sample_date ASC ) TO samples-2017-01.csv CSV DELIMITER ',';
Data has been stashed in the phin-data-exports
AWS S3 bucket. The CSV files are zipped before uploading to save space.
If you're testing stuff using the Shopify API you should know there are 2 stores: the production store found at chemicals.phin.co and the test store at /phintest.myshopify.com. In stage, all API calls go against phintest.myshopify.com. You'll need access to the production or test stores to see if things are working.
You should use the subscription editor to drive states. You can find it at https://github.com/PhinCo/sandbox/tree/master/subscription_editor along with the test cases.
Chemicals are chosen in the following scenarios.
Scanning a chemical
Rendering skus for a protocol
Find best fitting chemical using chemical purposes and vessel type
Find chemical from inventory
Find all retail chemicals with matching chemical purpose for a given vessel type and manufacturer
FAQs
Internal API
The npm package phinternal-api receives a total of 0 weekly downloads. As such, phinternal-api popularity was classified as not popular.
We found that phinternal-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.