Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding user_tag table to facilitate user restricted application features. #955

Merged
1 commit merged into from
Feb 11, 2022

Conversation

ghost
Copy link

@ghost ghost commented Feb 4, 2022

  • pinning allowlist and user account storage limits can be managed by this single table without the need for one-off tables e.g. pinning_authorization.
  • this allows the admin.storage site to easily manage tags.

nft pr here

@ghost ghost changed the title Adding user_tag table to facilitate user restricted application features. Adding user_tags table to facilitate user restricted application features. Feb 4, 2022
@ghost ghost changed the title Adding user_tags table to facilitate user restricted application features. Adding user_tag table to facilitate user restricted application features. Feb 4, 2022
@ghost ghost force-pushed the feature/trigramdev9/user-tag-schema branch from 0e01a5a to 3fed3d8 Compare February 4, 2022 21:13
@LeslieOA
Copy link
Contributor

LeslieOA commented Feb 4, 2022

@trigramdev9 This makes a lot of sense and makes extending feature access trivial in the future.
I guess "tag" is usefully more generic than auth or permissions in this case.
Would we need a massive enum of all potential options for tag_value also, or would that be excessive?

@ghost
Copy link
Author

ghost commented Feb 4, 2022

Would we need a massive enum of all potential options for tag_value also, or would that be excessive?

That's a great question. I asked dchoi on slack if there is a finite set of values (i.e. for storage limits) and he said no, so I'm somewhat assuming it may be more flexible to have tag_value remain a text field.

…res.

* pinning allowlist and user account storage limits can be managed by this single table without the need for one-off tables e.g. pinning_authorization.
* this allows the admin.storage site to easily manage tags.
@ghost ghost force-pushed the feature/trigramdev9/user-tag-schema branch from 3fed3d8 to 88ca673 Compare February 9, 2022 18:05
Copy link
Contributor

@dashcraft dashcraft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical, LGTM!

@ghost ghost merged commit 2a1975d into main Feb 11, 2022
@ghost ghost deleted the feature/trigramdev9/user-tag-schema branch February 11, 2022 22:04
user_id BIGINT NOT NULL REFERENCES public.user (id),
tag user_tag_type NOT NULL,
-- tag_value is useful for certain tags like STORAGE_LIMIT e.g. tag="STORAGE_LIMIT", tag_value="1TB"
tag_value TEXT ,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What value will exist for "Pinning"? Empty?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea. are you thinking null values would consume too much space in the db? the alternative is a user_tag value table we could join on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my answer above provides a suggested resolution to this question.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not concerned on space, just on consumer expectations to be different for each type of tag. Which would leave us with hardcoded logic for each context. That's why I suggested the type column, which seems we are aligned :)

-- tag_value is useful for certain tags like STORAGE_LIMIT e.g. tag="STORAGE_LIMIT", tag_value="1TB"
tag_value TEXT ,
inserted_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL,
deleted_at TIMESTAMP WITH TIME ZONE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if tag deleted and then created for same user? In other words, should we have updated_at?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better to keep it this way to allow to have a "history".
So we would have a new row for every state change, what do you think?

Copy link
Contributor

@vasco-santos vasco-santos Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flea89
From https://www.notion.so/pl-strflt/Enforcing-user-storage-capacity-limits-a29aa59f28484842bea2721f5982234a#c7c52385776f49148c28d4fbdede6f1b we were already keeping a history table, that is basically interacted by admin dashboard. It also has "reason" for blocking, or unblocking. With that in mind, I think we should just have the latest in this table, which is the table that controls the product flows authorization. Any thing that I am missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right but we'd be tracking 2 different things.
This table would give you the history trail on how how a user tag as evolved ( ie how your limits have increased) which is different from block history.
So I don't see any harm in keeping the trail here as well and, as you said, take the latest (not deleted) to define the outcome.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is fine, have no strong preference.

But, thinking better about updated_at individually, we should still have it as tag_value can be updated. Or were you considering deleting and adding a new one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want history we would have to have to delete (update the deleted_at) and add a new line indeed.
I'm not too opinionated as well, but I think, especially from a reporting perspective, it's useful information to keep the history.
Do you see any problem with that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vasco-santos i believe admin would delete then add a new row to preserve a history. updated_at muddies history a bit.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually on further thought i'm gonna add updated_at.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trigramdev9 what's your thinking behind adding updated_at? I thought that the inserted_at and deleted_at combo to give us history was quite neat. Interested to know what's swayed you the other way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we want to go with delete and create new one, sounds good to not have updated_ at

id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES public.user (id),
tag user_tag_type NOT NULL,
-- tag_value is useful for certain tags like STORAGE_LIMIT e.g. tag="STORAGE_LIMIT", tag_value="1TB"
Copy link
Contributor

@vasco-santos vasco-santos Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit concerned here. Why a text with "1TB" string?

Two things here:

  • text for being a generic value is ok, but I would prefer to see a type enum with the type the value is and a text value that you can parse as stated by type
  • We stored user used storage as bytes number in the DB. We should follow same pattern here and use bytes number value.

With above, I would expect the admin dashboard to be able to receive and parse tag values such as 1TB, but convert it to bytes instead. Everything would be handled in bytes within API logic instead of conversions for every single validation of used storage

Copy link
Author

@ghost ghost Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that user_tag is meant to be a very general table, it follows that potential values for tags may range from all sorts of different data types. PINNING doesn't need a value, STORAGE_LIMIT uses bytes as you mentioned: but what about future tags? To make the tag value bytes assumes that all future tags will have byte values. Also thinking about this from an admin perspective, I wonder if an admin user will want to type 1000000000000 when they really mean 1TB?

If I understand you correctly though @vasco-santos , I think your main concern is that the applications will have to convert string values to bytes for storage limit logic. Is that correct?

Copy link
Contributor

@adamalton adamalton Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We (@LeslieOA, @flea89 and I) discussed this earlier today (but before your comment was added @trigramdev9). I'll summarise our thoughts…

We interpreted @vasco-santos's comment as suggesting that we should add an additional column to denote the data type which is being stored in the tag_value column. And we agreed that that seems like a good idea. So then the table and enums would look like:

CREATE TYPE user_tag_type AS ENUM
(
  'PSA_ENABLED',
  'STORAGE_LIMIT_BYTES'
  -- others can be added in future
);

CREATE TYPE user_tag_value_type AS ENUM
(
  'bool',
  'int'
  'float'
  -- Potentially other types, as the application may require in future
);

CREATE TABLE IF NOT EXISTS public.user_tag
(
  tag                user_tag_type          NOT NULL,
  value_type     user_tag_value_type
  value          TEXT
  -- other fields (id, user_id, inserted_at, deleted_at) as before
);

So then, for example, the storage limit use case would be like:

  • tag = "STORAGE_LIMIT_BYTES" (from the enum)
  • value_type = "int" (from the enum)
  • value = "1099511627776" (text)

And the pinning authorization use case would be like:

  • tag = "PSA_ENABLED" (from the enum)
  • value_type = "bool" (from the enum)
  • value = "true" (text)

@trigramdev9, re. your point about an admin using having to type 1000...0000 instead of 1TB: I'm thinking that this should be solved in the UI level, rather than at the DB level. (Which I think is what @vasco-santos is suggesting in his last paragraph above..?) So each part of the application (the admin UI, the upload API, etc) can get the raw value and then use/present it as necessary.

One minor note, is that in my DB schema above, I've omited the tag_ prefix from the value_type and value columns, just because the table is already called user_tag, so they're hopefully unnecessary (but happy to be defeated on this).

Thoughts on the above? Good? Objections? :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamalton i see. yea, i like your proposal and feel it will fit in and be generic enough for all use cases i can think of moving forward. can you see any downsides to this approach? i do wonder if being too general here is a limiting factor, but for now it seems good. not sure how i missed the proposal from @vasco-santos to have another column to denote the type but that makes perfect sense to me.

Copy link
Contributor

@adamalton adamalton Feb 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you see any downsides to this approach?

@jsdevel I think that this approach gives us the best balance that we're going to get between flexible/generic and not too crazy. The only thing that ran through my mind was that casting values from text to their declared type (e.g. parseInt(text_value)) feels like it's veering a little bit towards eval(untrusted_value_from_db)! But I think it's safely a good distance away from that yet!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @adamalton to put that code snippet together! That was exactly my thoughts

ghost pushed a commit that referenced this pull request Feb 15, 2022
…#955) (#979)

Co-authored-by: Joe Spencer <joe.spencer@discounttire.com>
MichaelPhan added a commit that referenced this pull request Feb 16, 2022
* feat: temporary api backdoor (#722)

* fix: postgres set max parallel workers per gather to 4 (#725)

* chore: release @web3-storage/db 3.1.0 (#700)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/api 4.3.0 (#727)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/website 1.8.0 (#710)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Issue 703 - Navigation Links the Nextjs way (#716)

* Fixed navigation links and trying to make loading screen more consistent because its jarring and the wrong color

* small housecleaning items, loading wasnnt taking full screen

* style updates for loading spinner

* add active indicator for active link

* trying something different adding active classes and a slug element

* missed a slug

* wrap navbar logo in Link component

* feat: issue 689 added new column and metadata for review (#729)

* added new column and metadata for review

* feat: add new column for availability and fix copy for pin status

* fix: mispelled available (#731)

* fix: remove backdoor routes (#737)

* fix: endpoint URL construction (#734)

* fix: do not prefer node.js builtins (#748)

* fix!: client should not throw on 404 (#751)

* chore: release @web3-storage/db 4.0.0 (#753)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: update db breaking change

* chore: release @web3-storage/api 5.0.0 (#752)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release web3.storage 3.5.1 (#740)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: created a formatter abstraction for filesize to standardize iec binary units for all file size display props (#757)

* fix: remove dagcargo materialized views (#735)

Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>

* fix: db delete key return value (#766)

* fix: api using db instead of mocks for tests (#765)

* fix: tolerant of failure for deals (#769)

* chore: release @web3-storage/db 4.0.1 (#767)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/api 5.0.1 (#768)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* feat: Multiple File upload and uniform drag and drop (#567)

* feat: multiple file upload

feat: drag and drop from account page

* fix: missed a deprecated function

* fix: updated to include a remove file option

* small update, add formatter

Co-authored-by: Daniel <daniel.ashcraft@ofashandfire.com>

* chore: create tool package with ipfs-cluster docker-compose setup.

* chore: persist db data locally

* chore: add start/stop scripts for db

* chore: add ipf cluster docker to repo

* chore: add debug npm script

* chore: move things around

* chore: create cli and expose it

* chore: use named volume and make sure is deleted using stop:clean

* chore: update readme

* chore: action PR feedback

* chore: remove stale mock:pgrest

* chore: remove console logging

* chore: make standard happy

* fix: delete ops should update updated ts (#774)

* chore: release @web3-storage/db 4.0.2 (#777)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/api 5.0.2 (#776)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: add metadata to backup (#783)

* fix: improve list tokens (#782)

Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>

* chore: release @web3-storage/db 4.0.3 (#787)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/api 5.0.3 (#785)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: backup unique constraint (#795)

* fix: remove temporary dag size sum for pins (#824)

* chore: release @web3-storage/api 5.0.4 (#825)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: react-scripts-v5 compatible issue. (#826)

* fix: update package lock (#827)

* chore: release web3.storage 3.5.2 (#828)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix scroll issue on desktop safari (#822)

* fix scroll issue on desktop safari

* dont update package lock or next env file

Co-authored-by: Daniel <daniel.ashcraft@ofashandfire.com>

* chore: update pgrest (#816)

* fix: db endpoint to use heroku (#817)

* feat: add list of known peers hosting content for web3.storage (#837)

A list of known IPFS peers that are hosting content uploaded to NFT.Storage.

YOU DO NOT NEED THIS LIST. All peers that provide content on IPFS are
discoverable via the DHT. IPFS transfers content P2P from multiple sources
including other peers that recently acquired the content.

Note: this list may be incorrect, may change, or become out of date at any
time without notice.

* chore: release @web3-storage/db 4.0.4 (#796)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/api 5.0.5 (#829)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/website 1.9.0 (#730)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: only disallow delete if dag size is unknown (#839)

* chore: added leslieoa to api wrangler config (#849)

* fix: dag size for big dags with non pb root (#850)

* fix: update deps in api and client (#855)

* chore: release @web3-storage/api 5.0.6 (#854)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release web3.storage 3.5.3 (#856)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/website 1.9.1 (#853)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: release @web3-storage/w3 2.4.2 (#857)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: api cluster add car explicitly (#858)

* chore: release @web3-storage/api 5.0.7 (#859)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: use single sentry project (#869)

* chore: release @web3-storage/api 5.0.8 (#870)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: update add to web3 action (#841)

* chore: update licenses (#831)

* chore: remove commented metrics for dag size sum in pins (#838)

* feat: w3 name CLI (#878)

Adds some simple CLI commands for managing w3 names.

* chore: release @web3-storage/w3 2.5.0 (#880)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: use docker cluster for api tests (#847)

* feat: pinning API implementation

* feat(pinning-api): add skeleton and validation for pinning apis

* feat: add pinning endpoints

* feat: add tests

* feat: add validation for endpoints and refactor error messages

* fix: validation bug

* feat: add tests for get and delete endpoints

* fix: test assertions

* feat: add replace pin api endpoint

* chore: rollback type changes for now

Co-authored-by: Paolo <paolo@potatolondon.com>

* feat(pinning-apis): work on db to support new pinning apis

* chore: rename PinsUpsertInput to PinUpsertInput

* chore: fix PinUpsertInput type

* chore: use PinUpsertInput where required

* chore(refactor types): refactor pinItem

* chore(refactor types): Use location with other types

* chore(refactor types): fix some type errors in db client

* chore(refactor types): rename PinItemOutput to PinItemNormalized

* chore(refactor types): Pin item should have an _id field

* Rename PinItemOutput back

* feat(pinning-api-db): create pinning table and update reset.sql

* feat(pinning-api-db): create initial types

* feat(pinning-api-db): create db client signatures

* feat(pinning-api-db): updat types

* feat(pinning-api-db): write first intial add pin spec

* feat(pinning-api-db): first implementation of create and get pinRequest

* feat(pinning-api-db): get pin data for request

* feat(pinning-api-db): housekeeping

* feat(pinning-api-db): get pin request tests

* feat(pinning-api-db): housekeeping

* feat: add types to db data types

* feat(pinning-api-db): create content function

* feat(pinning-api-db): remove duplicated type

* feat(pinning-api-db): housekeeping

* feat(pinning-api-db): update types

* feat(pinning-api-db): update documentation

* Add endpoint and logic to our api service (#702)

* feat(pinning-apis): get request endpoint work

* chore: remove logging

* chore: improve validation get /pin/requestId

* chore: better integer validation

* fix: requestId conditional

* fix: remove extra bracket

Co-authored-by: Alexandra Stoica <alexandra.stoica@potatolondon.com>

* feat(pinning-apis): POST /pin endpoint

* wip: create pin request

* feat: add async task

* chore: merge feature branch

* feat: code improvements

* chore: add todo

* feat: add comments and some small fixes

* fix: pass token id

* fix: normalized cid vs source cid

* fix: minor fix and tests updates

* fix: update return of get user mock

Co-authored-by: Paolo <paolo@potatolondon.com>

* chore:  make standard happier

* fix: fix token referemce

* fix: merge conflict issue

* feat : delete and replace pin requests endpoints

* wip: delete pin request

* feat: add db definitions

* feat: wip replace pin endpoint

* chore: update mocks

* fix: do not list deleted requests

* feat: add delete db tests

* fix: tests

* fix: improve validation

* feat: tests

* chore: update comments

* fix: replace pin bugs and tests

* fix: coerce to number using parseInt

* chore: disable tests for now

Co-authored-by: Paolo <paolo@potatolondon.com>

* feat: GET /pins endpoint

* feat: wip list pin requests

* feat: list pinning requests

* chore: renaming test descriptions

* chore: filter for list pins

* chore: fixing tests

* chore: list pins tests

* feat: db and api tests for list pins

* chore: reorder list test

* fix: correct count in list response

* fix: avoid double query on list

* feat: PR feedback

* feat: add todo for future improv

* fix: typos, use new URL in test, improve Date test

* feat: don't skip test

* fix: update tests and more fixes

* fix: take back the todo

Co-authored-by: Gary Homewood <gary@potatolondon.com>

* Refactor Pin APIs and PR feedback (#810)

chore: pinning apis refactoring and feedback

* feat: update sql and db client logic

* feat: update tests and minor fixes

* feat: more updates/fixes to db package

* feat: refactor pin creation flow and refactor car upload as well

* feat: pinning, fix tests and add more

* fix: rename table, functions and types

* chore: PR feedback

* fix: rename types

* chore: rename requestedCid to sourceCid

* fix: delete should not return a body and status should be 202

* chore: add some documentation to waitOkPins

* chore: delete stale mock

* fix: do not passa meta to cluster

* chore: remove comment

* chore: refactor createPin

* chore: linting

* Get request id by user token (#863)

* fix: get pin req ids by user token

* fix: update tests

* fix: rest api types

* fix: update function params

* fix: type name

* feat: add test

* fix: tests

* fix: merge conflict

* fix: merge

* fix: rename authToken id

* Add metadata to API (#881)

* feat: add metadata to psa pin req

* feat: add metadata to api

* feat: add metadata tests

* chore: feedback

* feat: added pinning service request issue mailto link/github button (#879)

* feat: added pinning service request issue mailto link/github button

* chore: new line

* Fix test

* fix: update comment to reflect changes

* fix: use uuid for psaPinRequests ids

* feat: set search_path to public for uuid function, use uuid as pk on pin_request

* feat: reinstated pin_request and updated psa_pin_request

* bug: resolve merge conflicts

* chore: typos and linting

* bug: pinrequestid type string

* fix: types

* fix: update code to use strings for psa request ids

Co-authored-by: Paolo <paolo@potatolondon.com>

* chore: linting

Co-authored-by: Alexandra Stoica <ralexandrastoica@gmail.com>
Co-authored-by: Alexandra Stoica <alexandra.stoica@potatolondon.com>
Co-authored-by: Gary Homewood <gary@potatolondon.com>
Co-authored-by: Leslie Owusu-Appiah <leslie@localhost.international>

* perf: update pin composite index and adds inserted at index to content (#882)

* docs: add note about reserved Remote upload type (#896)

In NFT.Storage pin requests are added to the upload table with type "Remote". In dagcargo, PSA pin requests from Web3.Storage are combined with uploads (as they are in NFT.Storage) and are artificially given a type "Remote". Hence specifically adding a "Remote" type here would be problematic.

* fix: unlist deleted pin requests (#899)

* feat: add origins to psa pin request (#897)

* feat: add origins to psa pin request

* chore: remove comment

* chore: remove only from test

* chore: add better name for test

* feat: filter pins by status (#848)

* feat(pinning-api): add skeleton and validation for pinning apis

* feat: add pinning endpoints

* feat: add tests

* feat: add validation for endpoints and refactor error messages

* fix: validation bug

* feat: add tests for get and delete endpoints

* fix: test assertions

* feat: add replace pin api endpoint

* chore: rollback type changes for now

Co-authored-by: Paolo <paolo@potatolondon.com>

* feat(pinning-apis): work on db to support new pinning apis

* chore: rename PinsUpsertInput to PinUpsertInput

* chore: fix PinUpsertInput type

* chore: use PinUpsertInput where required

* chore(refactor types): refactor pinItem

* chore(refactor types): Use location with other types

* chore(refactor types): fix some type errors in db client

* chore(refactor types): rename PinItemOutput to PinItemNormalized

* chore(refactor types): Pin item should have an _id field

* Rename PinItemOutput back

* feat(pinning-api-db): create pinning table and update reset.sql

* feat(pinning-api-db): create initial types

* feat(pinning-api-db): create db client signatures

* feat(pinning-api-db): updat types

* feat(pinning-api-db): write first intial add pin spec

* feat(pinning-api-db): first implementation of create and get pinRequest

* feat(pinning-api-db): get pin data for request

* feat(pinning-api-db): housekeeping

* feat(pinning-api-db): get pin request tests

* feat(pinning-api-db): housekeeping

* feat: add types to db data types

* feat(pinning-api-db): create content function

* feat(pinning-api-db): remove duplicated type

* feat(pinning-api-db): housekeeping

* feat(pinning-api-db): update types

* feat(pinning-api-db): update documentation

* Add endpoint and logic to our api service (#702)

* feat(pinning-apis): get request endpoint work

* chore: remove logging

* chore: improve validation get /pin/requestId

* chore: better integer validation

* fix: requestId conditional

* fix: remove extra bracket

Co-authored-by: Alexandra Stoica <alexandra.stoica@potatolondon.com>

* feat(pinning-apis): POST /pin endpoint

* wip: create pin request

* feat: add async task

* chore: merge feature branch

* feat: code improvements

* chore: add todo

* feat: add comments and some small fixes

* fix: pass token id

* fix: normalized cid vs source cid

* fix: minor fix and tests updates

* fix: update return of get user mock

Co-authored-by: Paolo <paolo@potatolondon.com>

* chore:  make standard happier

* fix: fix token referemce

* fix: merge conflict issue

* feat : delete and replace pin requests endpoints

* wip: delete pin request

* feat: add db definitions

* feat: wip replace pin endpoint

* chore: update mocks

* fix: do not list deleted requests

* feat: add delete db tests

* fix: tests

* fix: improve validation

* feat: tests

* chore: update comments

* fix: replace pin bugs and tests

* fix: coerce to number using parseInt

* chore: disable tests for now

Co-authored-by: Paolo <paolo@potatolondon.com>

* feat: GET /pins endpoint

* feat: wip list pin requests

* feat: list pinning requests

* chore: renaming test descriptions

* chore: filter for list pins

* chore: fixing tests

* chore: list pins tests

* feat: db and api tests for list pins

* chore: reorder list test

* fix: correct count in list response

* fix: avoid double query on list

* feat: PR feedback

* feat: add todo for future improv

* fix: typos, use new URL in test, improve Date test

* feat: don't skip test

* fix: update tests and more fixes

* fix: take back the todo

Co-authored-by: Gary Homewood <gary@potatolondon.com>

* feat: filter pins by status

* Refactor Pin APIs and PR feedback (#810)

chore: pinning apis refactoring and feedback

* feat: update sql and db client logic

* feat: update tests and minor fixes

* feat: more updates/fixes to db package

* feat: refactor pin creation flow and refactor car upload as well

* feat: pinning, fix tests and add more

* fix: rename table, functions and types

* chore: PR feedback

* fix: rename types

* chore: rename requestedCid to sourceCid

* fix: delete should not return a body and status should be 202

* chore: add some documentation to waitOkPins

* chore: delete stale mock

* fix: do not passa meta to cluster

* chore: remove comment

* chore: refactor createPin

* chore: linting

* fix: updates and fixes after merge

* Get request id by user token (#863)

* fix: get pin req ids by user token

* fix: update tests

* fix: rest api types

* fix: update function params

* fix: type name

* feat: add test

* fix: tests

* fix: merge conflict

* fix: merge

* fix: rename authToken id

* fix: requestedCid to sourceCid

* chore: clean up fixtures

* chore: refactor filter by status in the db package

* chore: refactor pinning api to match new db api

* chore: use chromium for tests

* chore: remove console log

* Add metadata to API (#881)

* feat: add metadata to psa pin req

* feat: add metadata to api

* feat: add metadata tests

* chore: feedback

* feat: added pinning service request issue mailto link/github button (#879)

* feat: added pinning service request issue mailto link/github button

* chore: new line

* Fix test

* fix: update comment to reflect changes

* fix: lint error

Co-authored-by: Alexandra Stoica <ralexandrastoica@gmail.com>
Co-authored-by: Paolo <paolo@potatolondon.com>
Co-authored-by: Paolo Chillari <flea89@users.noreply.github.com>
Co-authored-by: Alexandra Stoica <alexandra.stoica@potatolondon.com>
Co-authored-by: Leslie Owusu-Appiah <leslie@localhost.international>

* fix: update name in pinning status filtering test

* feat: pinning api allowlist (#705)

* feat(pinning-api): add skeleton and validation for pinning apis

* feat: add pinning endpoints

* feat: add tests

* feat: add validation for endpoints and refactor error messages

* fix: validation bug

* feat: add tests for get and delete endpoints

* fix: test assertions

* feat: add replace pin api endpoint

* chore: rollback type changes for now

Co-authored-by: Paolo <paolo@potatolondon.com>

* feat(pinning-apis): work on db to support new pinning apis

* chore: rename PinsUpsertInput to PinUpsertInput

* chore: fix PinUpsertInput type

* chore: use PinUpsertInput where required

* chore(refactor types): refactor pinItem

* chore(refactor types): Use location with other types

* chore(refactor types): fix some type errors in db client

* chore(refactor types): rename PinItemOutput to PinItemNormalized

* chore(refactor types): Pin item should have an _id field

* Rename PinItemOutput back

* feat(pinning-api-db): create pinning table and update reset.sql

* feat(pinning-api-db): create initial types

* feat(pinning-api-db): create db client signatures

* feat(pinning-api-db): updat types

* feat(pinning-api-db): write first intial add pin spec

* feat(pinning-api-db): first implementation of create and get pinRequest

* feat(pinning-api-db): get pin data for request

* feat(pinning-api-db): housekeeping

* feat(pinning-api-db): get pin request tests

* feat(pinning-api-db): housekeeping

* feat: add types to db data types

* feat(pinning-api-db): create content function

* feat(pinning-api-db): remove duplicated type

* feat(pinning-api-db): housekeeping

* feat(pinning-api-db): update types

* feat(pinning-api-db): update documentation

* chore: db change for allowlist

* Add endpoint and logic to our api service (#702)

* feat(pinning-apis): get request endpoint work

* chore: remove logging

* chore: improve validation get /pin/requestId

* chore: better integer validation

* fix: requestId conditional

* fix: remove extra bracket

Co-authored-by: Alexandra Stoica <alexandra.stoica@potatolondon.com>

* feat(pinning-apis): POST /pin endpoint

* wip: create pin request

* feat: add async task

* chore: merge feature branch

* feat: code improvements

* chore: add todo

* feat: add comments and some small fixes

* fix: pass token id

* fix: normalized cid vs source cid

* fix: minor fix and tests updates

* fix: update return of get user mock

Co-authored-by: Paolo <paolo@potatolondon.com>

* chore:  make standard happier

* feat: wip add pinning allowlist checking to API

* fix: fix token referemce

* chore: fix test mocking

* feat: add tests for pinning allowlist

* fix: merge conflict issue

* chore: fix tests after merge

* chore: review amends

* feat : delete and replace pin requests endpoints

* wip: delete pin request

* feat: add db definitions

* feat: wip replace pin endpoint

* chore: update mocks

* fix: do not list deleted requests

* feat: add delete db tests

* fix: tests

* fix: improve validation

* feat: tests

* chore: update comments

* fix: replace pin bugs and tests

* fix: coerce to number using parseInt

* chore: disable tests for now

Co-authored-by: Paolo <paolo@potatolondon.com>

* chore: simplified allowlist middleware

* feat: GET /pins endpoint

* feat: wip list pin requests

* feat: list pinning requests

* chore: renaming test descriptions

* chore: filter for list pins

* chore: fixing tests

* chore: list pins tests

* feat: db and api tests for list pins

* chore: reorder list test

* fix: correct count in list response

* fix: avoid double query on list

* feat: PR feedback

* feat: add todo for future improv

* fix: typos, use new URL in test, improve Date test

* feat: don't skip test

* fix: update tests and more fixes

* fix: take back the todo

Co-authored-by: Gary Homewood <gary@potatolondon.com>

* feat: use separate pinning auth table

* fix: db user test

* fix: correct db type

* Refactor Pin APIs and PR feedback (#810)

chore: pinning apis refactoring and feedback

* feat: update sql and db client logic

* feat: update tests and minor fixes

* feat: more updates/fixes to db package

* feat: refactor pin creation flow and refactor car upload as well

* feat: pinning, fix tests and add more

* fix: rename table, functions and types

* chore: PR feedback

* fix: rename types

* chore: rename requestedCid to sourceCid

* fix: delete should not return a body and status should be 202

* chore: add some documentation to waitOkPins

* chore: delete stale mock

* fix: allowlist on user id instead of token

* fix: allow pinning user for post

* fix: do not passa meta to cluster

* chore: remove comment

* chore: refactor createPin

* chore: linting

* chore: remove stale mock

* Get request id by user token (#863)

* fix: get pin req ids by user token

* fix: update tests

* fix: rest api types

* fix: update function params

* fix: type name

* feat: add test

* fix: tests

* fix: merge conflict

* fix: merge

* fix: rename authToken id

* fix: db test dead code

* chore: merge from pinning-apis, de-dupe tests

* fix: skip status db test

* Add metadata to API (#881)

* feat: add metadata to psa pin req

* feat: add metadata to api

* feat: add metadata tests

* chore: feedback

* feat: added pinning service request issue mailto link/github button (#879)

* feat: added pinning service request issue mailto link/github button

* chore: new line

* Fix test

* fix: update comment to reflect changes

* fix: code review

* chore: spelling consistency

* chore: review changes

Co-authored-by: Alexandra Stoica <ralexandrastoica@gmail.com>
Co-authored-by: Paolo <paolo@potatolondon.com>
Co-authored-by: Paolo Chillari <flea89@users.noreply.github.com>
Co-authored-by: Alexandra Stoica <alexandra.stoica@potatolondon.com>
Co-authored-by: Leslie Owusu-Appiah <leslie@localhost.international>

* chore: improve release ci (#907)

* fix: remove resize observer, use css for responsive menu (#778)

remove resize observer, use css instead

* fix: return right psa status in APIs

Co-authored-by: Vasco Santos <santos.vasco10@gmail.com>

* refactor: esm in worker (#902)

Converts the built worker JS to ESM. Uses miniflare for testing.

This enables using durable objects in the worker so that we can have websockets for w3name. When we get websockets, I can write the [IPNS publisher to listen for updates and publish to the DHT](#662). I realised it was going to be a PITA to get Cloudflare expected ESM format (export a default object with a fetch function) to work with regular workers in our tests...I ended up adding miniflare to the tests.

refs #659
reolves #852

* fix: sentry version cannot contain slash (#924)

Fixes:

```
Error: Command failed: /github/workspace/node_modules/@sentry/cli/sentry-cli releases new @web3-storage/api@5.0.8-dev+c1f7a1b
error: Invalid value for '<VERSION>': Invalid release version. Slashes and certain whitespace characters are not permitte
```

* fix: update package.json main entry

* fix: check if unpinned then downgrade to v0 (#919)

* fix: check if unpinned then denormalize to v0

* fix: renamed module

* fix: added cid module to cron package

* fix: correct paths/typo

* fix: denormaize contentCid not serial pk (id)

* fix: pr bugfixes and change requests

* chore: denormalize to downgrade

* fix: attempt to downgrade cid

* fix: move attempt to downgrade cid to cid util

* chore: remove unused util from api

* fix: error path

* fix: check if unpinned

* fix: unnecessary call to getpinstatus, push to resync pins

* fix: psa pin request status

* fix: limit the psa request listing and return right count

* fix: updated mailto link copy (#939)

* fix: bind normalizedCid instead of function (#941)

* fix: bind normalizedCid instead of function (#942)

* feat: websockets support for w3name (#932)

This PR adds support for websockets to w3name. Establish a websocket connection to `wss://api.web3.storage/name/:key/watch` and receive JSON encoded messages like: `{ key: string, value: string, record: string }` when updates to the key are published.

* [x] Refactor to ESM to allow usage of "Durable Objects" #902
* [x] Configuration to enable `NameRoom` as a durable object
* [ ] Client API (will do in separate PR)

supersedes #653

Related to #659

* fix: include meta for replace pin (#935)

* fix: include meta for create pin

* chore: include valid origins on pin replace

* fix: don't send meta to cluster

* chore(main): release api 5.1.0 (#909)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: durable objects config (#949)

I think the top level durable objects config does not work when publishing for reals.

* fix: user and auth token type declarations (#948)

* fix: add pre-bundled ESM build to package exports (#930)

* fix: add pre-bundled ESM build to package exports

* chore: format JSON

* chore: remove added whitespace

* chore: ok all of it fml

Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>

* fix: add initial migration (#951)

* chore(main): release web3.storage 3.5.4 (#952)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore(main): release api 5.1.1 (#950)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: size for single block raw node (#958)

* chore(main): release api 5.1.2 (#959)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: db client do not throw error when no upload found (#885)

* chore: remove migration tracking table (#832)

* chore(main): release api 5.1.3 (#964)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* feat: schema updates for admin site (#947)

Co-authored-by: Joe Spencer <joe.spencer@discounttire.com>

* Adding user_tag table to facilitate user restricted application features. (#955)

* pinning allowlist and user account storage limits can be managed by this single table without the need for one-off tables e.g. pinning_authorization.
* this allows the admin.storage site to easily manage tags.

Co-authored-by: Joe Spencer <joe.spencer@discounttire.com>

* fix: invalid CAR errors (#977)

* chore(main): release api 5.1.4 (#978)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* chore: Manually resolve collisions between main and new brand wip

* chore: Pinning and updating dependancies

Co-authored-by: Vasco Santos <santos.vasco10@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Daniel Ashcraft <daniel.ashcraft@ofashandfire.com>
Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>
Co-authored-by: Zé Bateira <jose.bateira@protonmail.com>
Co-authored-by: Paolo Chillari <flea89@users.noreply.github.com>
Co-authored-by: Victor <nftvictor@gmail.com>
Co-authored-by: Chris Anderson <jchris@gmail.com>
Co-authored-by: Leslie Owusu-Appiah <leslie@localhost.international>
Co-authored-by: Alexandra Stoica <ralexandrastoica@gmail.com>
Co-authored-by: Alexandra Stoica <alexandra.stoica@potatolondon.com>
Co-authored-by: Gary Homewood <gary@potatolondon.com>
Co-authored-by: Paolo <paolo@potatolondon.com>
Co-authored-by: Hugo Dias <hugomrdias@gmail.com>
Co-authored-by: Yusef Napora <yusef@protocol.ai>
Co-authored-by: trigramdev9 <98334141+trigramdev9@users.noreply.github.com>
Co-authored-by: Joe Spencer <joe.spencer@discounttire.com>
Co-authored-by: Michael Phan <michael.d.phan@gmail.com>
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use new user tags to authorise user to use pinning service APIs
7 participants