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

feat(galaxy|access): "appdata" 128kb storage api #2763

Merged
merged 35 commits into from
Dec 11, 2023

Conversation

Cosmin-Parvulescu
Copy link
Contributor

@Cosmin-Parvulescu Cosmin-Parvulescu commented Nov 16, 2023

Description

  • Added storage menu item
  • Added early access panel for pro plan (this still needs copy and alignment on what info we display)
  • Added hidden storage page with functionality (this still needs copy and alignment on what info we display)
  • Updated toggle input props to handle lack of label
  • Added gql schemas for get / set external app data
  • Added authorization resolver to handle external app data
  • Added external app data packages, notably STARTER
  • Added new KV for usage categories (will hold reads / writes for the get / set endpoints for app data, and others in the future)
  • Added external app data endpoints in worker & durable objects
  • Added new middleware for validating existance of both JWT and X-GALAXY-KEY in requests to Galaxy

Related Issues

Testing

Console

  1. Create an app
  2. Go to storage
  3. Go to <current_url>/ostrich
  4. Toggle on the feature

Galaxy

  1. Using Yoga (http://localhost:10401/), select the get / set query / mutation
  2. In the Headers section add the following:
{
  "Authorization": "Bearer <an app user's jwt>",
  "X-GALAXY-KEY": "API key from Auth tab in Console"
}
  1. Run queries / mutations, be aware that the payload has to be an escaped JSON like { /"foo/":/"bar/"}
  2. Marvel

Profile

  1. Authenticate to Profile app
  2. Throw this code in the profile.tsx route
export const loader: LoaderFunction = async ({ request, context }) => {
  const jwt = await requireJWT(request, context.env)
  const galaxyClient = await getGalaxyClient(
    {
      ...generateTraceContextHeaders(context.traceSpan),
      ...getAuthzHeaderConditionallyFromToken(jwt),
      ...{
        'X-GALAXY-KEY': ‘<galaxy_api_key>’,
      },
    },
    context.env
  )

  await galaxyClient.setExternalData({
    payload: {
      foo: 'bar',
      biz: 'baz',
    },
  })

  const { externalData } = await galaxyClient.getExternalData()

  console.log(JSON.stringify(externalData, null, 2))

  return null
}

Checklist

  • I have read the CONTRIBUTING guidelines
  • I have tested my code (manually and/or automated if applicable)
  • I have updated the documentation (if necessary)

@Cosmin-Parvulescu Cosmin-Parvulescu added the enhancement Indicates new feature requests label Nov 16, 2023
@Cosmin-Parvulescu Cosmin-Parvulescu self-assigned this Nov 16, 2023
case 'enable':
await coreClient.starbase.setExternalDataPackage.mutate({
clientId,
packageType: ExternalDataPackageType.BASE,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's name this STARTER, to future-proof it a little.

const node = initAuthorizationNodeByName(urn, ctx.env.Authorization)

const externalStorageReads = await ctx.env.UsageKV.get<number>(
`${clientId}:external-storage:read`
Copy link
Contributor

Choose a reason for hiding this comment

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

Externalize this into function that gives you the usage key.

@@ -0,0 +1,7 @@
query getExternalData {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename references of this to *ExternalAppData, here and everywhere else in the PR, to differentiate it from future external data features.

const node = initAuthorizationNodeByName(urn, ctx.env.Authorization)

const externalStorageWrites = await ctx.env.UsageKV.get<number>(
`${clientId}:external-storage:write`
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as previous comment on externalizing this into a function.

})
}

await node.storage.put('externalData', payload)
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the await below should be run concurrently

})
}

const externalData = await node.storage.get('externalData')
Copy link
Contributor

Choose a reason for hiding this comment

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

This and promise below should run concurrently.

@@ -6,6 +6,10 @@ logpush = true
node_compat = true
workers_dev = false

kv_namespaces = [
{ binding = "UsageKV", id = "UsageKV", preview_id = "UsageKV" },
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 the env-specific wrangler files would also need to be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll update them once we reach the final design.

ExternalDataPackageDefinition | undefined
> {
return this.state.storage.get<ExternalDataPackageDefinition>(
'externalDataPackage'
Copy link
Contributor

Choose a reason for hiding this comment

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

This key name and the one below for the next function don't match.

},
]

export default packages.reduce((acc, curr) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be set statically in code (map or object) as opposed to being calculated at runtime?

@Cosmin-Parvulescu Cosmin-Parvulescu force-pushed the feat/galaxy_access/appdata-128kb-storage-api branch 3 times, most recently from 01575c8 to ad59884 Compare November 22, 2023 14:20
@Cosmin-Parvulescu Cosmin-Parvulescu force-pushed the feat/galaxy_access/appdata-128kb-storage-api branch from c7c8bea to 939a499 Compare November 27, 2023 13:18
@betimshahini
Copy link
Contributor

betimshahini commented Nov 28, 2023

@Cosmin-Parvulescu copy for early access panel and service description inside storage page:
App Data Storage service provides a hassle-free way to store and retrieve per-user data for your application. Once activated, the service can be accessed through our Galaxy API and it supports storing data up to 128kb, per user.

Remove API URL from currently-hidden app data storage page itself.

@Cosmin-Parvulescu Cosmin-Parvulescu force-pushed the feat/galaxy_access/appdata-128kb-storage-api branch from 0420ed3 to 384100e Compare December 1, 2023 10:36
@Cosmin-Parvulescu Cosmin-Parvulescu marked this pull request as ready for review December 1, 2023 10:37
@Cosmin-Parvulescu Cosmin-Parvulescu force-pushed the feat/galaxy_access/appdata-128kb-storage-api branch from 384100e to 928b44b Compare December 1, 2023 10:57
...generateTraceContextHeaders(traceSpan),
})

return coreClient.authorization.getExternalAppData.query({
Copy link
Contributor

Choose a reason for hiding this comment

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

In the case of external storage not being defined, the error exposed through Galaxy is 400 Bad request, yet the TRPC one comes through correctly as external storage not enabled

payload,
})
} catch (ex) {
console.error(ex)
Copy link
Contributor

Choose a reason for hiding this comment

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

Related to comment above, when external storage is not enabled, this returns false as opposed to throwing the exception being thrown for the getExternalAppData query.

@betimshahini
Copy link
Contributor

This is good to go; will be approved and merged once #2743 is in.

@Cosmin-Parvulescu Cosmin-Parvulescu force-pushed the feat/galaxy_access/appdata-128kb-storage-api branch from b055bae to 8555c6f Compare December 11, 2023 08:46
@betimshahini betimshahini merged commit f3e36b7 into main Dec 11, 2023
15 of 16 checks passed
@betimshahini betimshahini deleted the feat/galaxy_access/appdata-128kb-storage-api branch December 11, 2023 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(galaxy|access): "appdata" 128kb storage api
2 participants