From b0c23473f47b93ec157c1cd6107f8bee36614883 Mon Sep 17 00:00:00 2001 From: Travis Vachon Date: Thu, 31 Aug 2023 17:58:15 -0700 Subject: [PATCH 1/2] fix: fix a number of bugs with ProvisionStore#getConsumer upgrade w3up to bring in new tests that would have caught these bugs --- package-lock.json | 48 +++++++++---------- .../functions/ucan-invocation-router.js | 2 +- upload-api/package.json | 2 +- upload-api/tables/consumer.js | 11 +++-- upload-api/tables/space-metrics.js | 5 +- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8a0aea9e..0d62c7af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4826,9 +4826,9 @@ } }, "node_modules/@web3-storage/upload-api": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@web3-storage/upload-api/-/upload-api-5.2.0.tgz", - "integrity": "sha512-FqGLJjA0b/cldfOIrBZd/jamyjmtd/mTFFbhSWwrqR3INtOaGeUjDKBGkveBEC8H6PnhSdyrQQYFyMLFNxj9qA==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@web3-storage/upload-api/-/upload-api-5.3.0.tgz", + "integrity": "sha512-Q/4a9YKR1pft14l832xi/AflEdRnQWoob4X/2e1AeOyQQ/RbRI+c3NlfgV4dQx+zy7wByHsCcMVtD/8QMFBu5w==", "dependencies": { "@ucanto/client": "^8.0.0", "@ucanto/interface": "^8.0.0", @@ -4836,8 +4836,8 @@ "@ucanto/server": "^8.0.1", "@ucanto/transport": "^8.0.0", "@ucanto/validator": "^8.0.0", - "@web3-storage/access": "^15.1.1", - "@web3-storage/capabilities": "^9.2.0", + "@web3-storage/access": "^15.2.0", + "@web3-storage/capabilities": "^9.2.1", "@web3-storage/did-mailto": "^2.0.0", "multiformats": "^11.0.2", "p-retry": "^5.1.2" @@ -4847,9 +4847,9 @@ } }, "node_modules/@web3-storage/upload-api/node_modules/@web3-storage/access": { - "version": "15.1.1", - "resolved": "https://registry.npmjs.org/@web3-storage/access/-/access-15.1.1.tgz", - "integrity": "sha512-tnD/jLUbQx5Stg0bYJb4OZj6DuZBpCZVz8VwxDQ5H3hIpElyt3OCC6YLwStIbeqc5d7w9272VZAYKfZr4W5TTw==", + "version": "15.2.0", + "resolved": "https://registry.npmjs.org/@web3-storage/access/-/access-15.2.0.tgz", + "integrity": "sha512-515WwZZLs2M0Dau3JGgroyK0a6fcuREcFv+i2EjUMLW8neYP7k8j++rpOjBSUNIIHkBbYtqx2aeX6fzmmEPriw==", "dependencies": { "@ipld/car": "^5.1.1", "@ipld/dag-ucan": "^3.3.2", @@ -4881,9 +4881,9 @@ } }, "node_modules/@web3-storage/upload-api/node_modules/@web3-storage/capabilities": { - "version": "9.2.0", - "resolved": "https://registry.npmjs.org/@web3-storage/capabilities/-/capabilities-9.2.0.tgz", - "integrity": "sha512-Qm2OpH/zIRECrlrsq8ZMh9W8qtZecn+CmB6fbkDYL9CEWdm28s+UC+Dxt9yIPUCZZMC+eTrxwS7jUwalB7T+VA==", + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/@web3-storage/capabilities/-/capabilities-9.2.1.tgz", + "integrity": "sha512-NBXm9320grYtKYV7g8nI7zzzS6GfOPp7EmDeWxDwOZ3nHvXDuiR77e3Sf7rRY265rMyJCtRUJ7/qRk7unQSfmA==", "dependencies": { "@ucanto/core": "^8.0.0", "@ucanto/interface": "^8.0.0", @@ -15770,7 +15770,7 @@ "@web-std/fetch": "^4.1.0", "@web3-storage/access": "^14.0.0", "@web3-storage/capabilities": "^9.0.0", - "@web3-storage/upload-api": "^5.2.0", + "@web3-storage/upload-api": "^5.3.0", "@web3-storage/w3infra-ucan-invocation": "*", "multiformats": "^11.0.1", "nanoid": "^4.0.2", @@ -19786,9 +19786,9 @@ } }, "@web3-storage/upload-api": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/@web3-storage/upload-api/-/upload-api-5.2.0.tgz", - "integrity": "sha512-FqGLJjA0b/cldfOIrBZd/jamyjmtd/mTFFbhSWwrqR3INtOaGeUjDKBGkveBEC8H6PnhSdyrQQYFyMLFNxj9qA==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@web3-storage/upload-api/-/upload-api-5.3.0.tgz", + "integrity": "sha512-Q/4a9YKR1pft14l832xi/AflEdRnQWoob4X/2e1AeOyQQ/RbRI+c3NlfgV4dQx+zy7wByHsCcMVtD/8QMFBu5w==", "requires": { "@ucanto/client": "^8.0.0", "@ucanto/interface": "^8.0.0", @@ -19796,17 +19796,17 @@ "@ucanto/server": "^8.0.1", "@ucanto/transport": "^8.0.0", "@ucanto/validator": "^8.0.0", - "@web3-storage/access": "^15.1.1", - "@web3-storage/capabilities": "^9.2.0", + "@web3-storage/access": "^15.2.0", + "@web3-storage/capabilities": "^9.2.1", "@web3-storage/did-mailto": "^2.0.0", "multiformats": "^11.0.2", "p-retry": "^5.1.2" }, "dependencies": { "@web3-storage/access": { - "version": "15.1.1", - "resolved": "https://registry.npmjs.org/@web3-storage/access/-/access-15.1.1.tgz", - "integrity": "sha512-tnD/jLUbQx5Stg0bYJb4OZj6DuZBpCZVz8VwxDQ5H3hIpElyt3OCC6YLwStIbeqc5d7w9272VZAYKfZr4W5TTw==", + "version": "15.2.0", + "resolved": "https://registry.npmjs.org/@web3-storage/access/-/access-15.2.0.tgz", + "integrity": "sha512-515WwZZLs2M0Dau3JGgroyK0a6fcuREcFv+i2EjUMLW8neYP7k8j++rpOjBSUNIIHkBbYtqx2aeX6fzmmEPriw==", "requires": { "@ipld/car": "^5.1.1", "@ipld/dag-ucan": "^3.3.2", @@ -19835,9 +19835,9 @@ } }, "@web3-storage/capabilities": { - "version": "9.2.0", - "resolved": "https://registry.npmjs.org/@web3-storage/capabilities/-/capabilities-9.2.0.tgz", - "integrity": "sha512-Qm2OpH/zIRECrlrsq8ZMh9W8qtZecn+CmB6fbkDYL9CEWdm28s+UC+Dxt9yIPUCZZMC+eTrxwS7jUwalB7T+VA==", + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/@web3-storage/capabilities/-/capabilities-9.2.1.tgz", + "integrity": "sha512-NBXm9320grYtKYV7g8nI7zzzS6GfOPp7EmDeWxDwOZ3nHvXDuiR77e3Sf7rRY265rMyJCtRUJ7/qRk7unQSfmA==", "requires": { "@ucanto/core": "^8.0.0", "@ucanto/interface": "^8.0.0", @@ -20052,7 +20052,7 @@ "@web3-storage/access": "^14.0.0", "@web3-storage/capabilities": "^9.0.0", "@web3-storage/sigv4": "^1.0.2", - "@web3-storage/upload-api": "^5.2.0", + "@web3-storage/upload-api": "^5.3.0", "@web3-storage/w3infra-ucan-invocation": "*", "ava": "^4.3.3", "aws-lambda-test-utils": "^1.3.0", diff --git a/upload-api/functions/ucan-invocation-router.js b/upload-api/functions/ucan-invocation-router.js index adea44b2..f7d27feb 100644 --- a/upload-api/functions/ucan-invocation-router.js +++ b/upload-api/functions/ucan-invocation-router.js @@ -86,7 +86,7 @@ export async function ucanInvocationRouter(request) { CONSUMER_TABLE_NAME: consumerTableName = '', SUBSCRIPTION_TABLE_NAME: subscriptionTableName = '', DELEGATION_TABLE_NAME: delegationTableName = '', - SPACE_METRICS_TABLE: spaceMetricsTableName = '', + SPACE_METRICS_TABLE_NAME: spaceMetricsTableName = '', RATE_LIMIT_TABLE_NAME: rateLimitTableName = '', R2_ENDPOINT: r2DelegationBucketEndpoint = '', R2_ACCESS_KEY_ID: r2DelegationBucketAccessKeyId = '', diff --git a/upload-api/package.json b/upload-api/package.json index eaac7ccb..bd24da4f 100644 --- a/upload-api/package.json +++ b/upload-api/package.json @@ -24,7 +24,7 @@ "@web-std/fetch": "^4.1.0", "@web3-storage/access": "^14.0.0", "@web3-storage/capabilities": "^9.0.0", - "@web3-storage/upload-api": "^5.2.0", + "@web3-storage/upload-api": "^5.3.0", "@web3-storage/w3infra-ucan-invocation": "*", "multiformats": "^11.0.1", "nanoid": "^4.0.2", diff --git a/upload-api/tables/consumer.js b/upload-api/tables/consumer.js index 894ec758..51b29199 100644 --- a/upload-api/tables/consumer.js +++ b/upload-api/tables/consumer.js @@ -87,14 +87,15 @@ export function useConsumerTable (dynamoDb, tableName) { const response = await dynamoDb.send(new QueryCommand({ TableName: tableName, IndexName: 'consumer', - KeyConditionExpression: "consumer = :consumer and provider = :provider", + KeyConditionExpression: "consumer = :consumer", ExpressionAttributeValues: { ':consumer': { S: consumer }, - ':provider': { S: provider } - }, + } })) - if (response.Items && (response.Items.length > 0)) { - const record = unmarshall(response.Items[0]) + // we may need to worry about pagination in the future if we end up supporting many many subscriptions for a single + // provider/consumer pair, but I suspect we'll never get there + const record = response.Items?.map(i => unmarshall(i)).find(i => i.provider === provider) + if (record) { return { subscription: record.subscription } diff --git a/upload-api/tables/space-metrics.js b/upload-api/tables/space-metrics.js index 9ec2aaaa..8dfecc43 100644 --- a/upload-api/tables/space-metrics.js +++ b/upload-api/tables/space-metrics.js @@ -39,10 +39,9 @@ export function useSpaceMetricsTable(dynamoDb, tableName) { const response = await dynamoDb.send(new GetItemCommand({ TableName: tableName, Key: marshall({ - consumer, + space: consumer, name: METRICS_NAMES.STORE_ADD_SIZE_TOTAL - }), - AttributesToGet: ['value'] + }) })) return response.Item ? unmarshall(response.Item).value : 0 } From f7267b4305e138a5dc3581aaf25fb12d665be20f Mon Sep 17 00:00:00 2001 From: Travis Vachon Date: Tue, 5 Sep 2023 11:12:28 -0700 Subject: [PATCH 2/2] fix: linter --- upload-api/tables/consumer.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/upload-api/tables/consumer.js b/upload-api/tables/consumer.js index 51b29199..60b5bff2 100644 --- a/upload-api/tables/consumer.js +++ b/upload-api/tables/consumer.js @@ -95,13 +95,9 @@ export function useConsumerTable (dynamoDb, tableName) { // we may need to worry about pagination in the future if we end up supporting many many subscriptions for a single // provider/consumer pair, but I suspect we'll never get there const record = response.Items?.map(i => unmarshall(i)).find(i => i.provider === provider) - if (record) { - return { - subscription: record.subscription - } - } else { - return null - } + return record ? { + subscription: record.subscription + } : null }, /**