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

App config in DynamoDB for Segment app #1698

Merged
merged 8 commits into from
Jan 20, 2025

Conversation

krzysztofzuraw
Copy link
Member

@krzysztofzuraw krzysztofzuraw commented Jan 17, 2025

Scope of the PR

  • Store app config in DynamoDB instead of Saleor app metadata.
  • Refactored a bit AppConfig.Schema not to have null value any more

Related issues

Checklist

@krzysztofzuraw krzysztofzuraw added the skip changeset Attach this label to PRs which does not need changes description for the release notes. label Jan 17, 2025
Copy link

changeset-bot bot commented Jan 17, 2025

🦋 Changeset detected

Latest commit: f202748

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
segment Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
saleor-app-segment ✅ Ready (Inspect) Visit Preview Jan 20, 2025 1:44pm
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
saleor-app-avatax ⬜️ Skipped (Inspect) Jan 20, 2025 1:44pm
saleor-app-cms ⬜️ Skipped (Inspect) Jan 20, 2025 1:44pm
saleor-app-klaviyo ⬜️ Skipped (Inspect) Jan 20, 2025 1:44pm
saleor-app-products-feed ⬜️ Skipped (Inspect) Jan 20, 2025 1:44pm
saleor-app-search ⬜️ Skipped (Inspect) Jan 20, 2025 1:44pm
saleor-app-smtp ⬜️ Skipped (Inspect) Jan 20, 2025 1:44pm

@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp January 17, 2025 11:45 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-search January 17, 2025 11:45 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed January 17, 2025 11:45 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-cms January 17, 2025 11:45 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax January 17, 2025 11:45 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-klaviyo January 17, 2025 11:45 Inactive
@krzysztofzuraw krzysztofzuraw changed the title WIP: DynamoDB config for Segment app WIP: App config in DynamoDB for Segment app Jan 17, 2025
export interface IAppConfigMetadataManager {
get(): Promise<AppConfig>;
set(config: AppConfig): Promise<void>;
export interface AppConfigMetadataManager {
Copy link
Member

Choose a reason for hiding this comment

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

metadata? metadata is specific to saleor metadata, we are opting out

Copy link
Member

Choose a reason for hiding this comment

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

we can keep this interface but lets drop legacy naming. Why it's not just a ConfigRepository? Repository has normally built-in methods like "get" "getAll", "find" etc (CRUD).

You can extract DynamoDB specific part to separate DAO but I think it's an overkill.

IMO we can simplify:

DynamoConfigRepository implements ConfigRepository and MemoryConfigRepository for testing

import { SegmentConfigEntityType, SegmentMainTable } from "./segment-main-table";
import { ConfigRepository } from "./types";

export class SegmentConfigRepository implements ConfigRepository {
Copy link
Member

Choose a reason for hiding this comment

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

I'd avoid prefixing with "Segment".

  1. You are in the context of segment app so you don't need this, of course it's related to the app
  2. In the context of Segment app, "segment" can be actual segment.io api/service which is confusing

ConfigRepository or AppConfigRepository will do

},
) {}

async getEntry(args: { saleorApiUrl: string; appId: string; configKey: string }) {
Copy link
Member

Choose a reason for hiding this comment

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

please strong type the function return, this is the part I'd like to avoid infering

config: schema({
PK: string().key(),
SK: string().key(),
value: string(),
Copy link
Member

Choose a reason for hiding this comment

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

why value is string? Why don't you add normal fields? AFAIK there is some token field, so why it's not just a token?

Copy link
Member Author

@krzysztofzuraw krzysztofzuraw Jan 17, 2025

Choose a reason for hiding this comment

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

Question is: do we store every config value in its own attribute and encrypt it or rather we store encrypted JSON in one attribute (e.g configValue)?

Storing every config value in its own attribute means that we need to refactor a bit AppConfig class to allow serializing single config entry and encrypt / decrypt every config entry on its own - but I don't have strong opinion here

Copy link
Member

@lkostrowski lkostrowski Jan 17, 2025

Choose a reason for hiding this comment

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

  1. We should encrypt data that is sensitive, which is a token. Other fields don't have to be encrypted (like checkbox value)
  2. AppConfig during serialization can encrypt and during parisng decrypt itself
  3. AppConfig was serialized before because it was used as saleor metadata which is much simpler mechanism

Here I think we should

  1. Treat token as "one of the fields" in app config
  2. include encyrption/decryption in app config serialization / parsing. It can be in AppConfig but to avoid injecting db schema to domain, we should probably have separate class that will convert one object to another

We shouldn't drop native database features, having a single key is problematic, doesn't work with concurrency, hard to migrate etc

@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp January 17, 2025 14:50 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-klaviyo January 17, 2025 14:50 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-cms January 17, 2025 14:50 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-search January 17, 2025 14:50 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed January 17, 2025 14:50 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax January 17, 2025 14:50 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp January 20, 2025 10:37 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax January 20, 2025 10:37 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-search January 20, 2025 10:37 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed January 20, 2025 10:37 Inactive
Comment on lines 51 to 52
setOrCreateConfig: protectedClientProcedure
.input(z.string().min(1))
Copy link
Member

Choose a reason for hiding this comment

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

Maybe YAGNI but

  • If we accept string, procedure probably should be setting only the token/key
  • If we accept the config, we should accept the object. Can be a FormData, maybe serialized AppConfig?

Copy link
Member Author

@krzysztofzuraw krzysztofzuraw Jan 20, 2025

Choose a reason for hiding this comment

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

currently config is one segmentWriteKey so I think having setOrCreateSegmentKey will be better here as I didn't plan to refactor UI form (at least now)

}

export class DynamoAppConfigManager implements AppConfigManager {
public readonly metadataKey = "app-config-v1";
Copy link
Member

Choose a reason for hiding this comment

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

metadata key? I guess not anymore

Copy link
Member Author

Choose a reason for hiding this comment

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

yes - it should be configKey instead 👍🏻


constructor(
private deps: {
segmentConfigEntity: SegmentConfigEntityType;
Copy link
Member

Choose a reason for hiding this comment

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

does it really have to be injected? In general DI is good, Im just wondering if this is not a false decoupling. Isn't it by design coupled? When can it be replaced with something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will check but I bet it won't be replaced

@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp January 20, 2025 13:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed January 20, 2025 13:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-cms January 20, 2025 13:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-klaviyo January 20, 2025 13:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax January 20, 2025 13:39 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-search January 20, 2025 13:39 Inactive
lkostrowski
lkostrowski previously approved these changes Jan 20, 2025
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax January 20, 2025 13:43 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-search January 20, 2025 13:43 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed January 20, 2025 13:43 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-klaviyo January 20, 2025 13:43 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-cms January 20, 2025 13:43 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp January 20, 2025 13:43 Inactive
@krzysztofzuraw krzysztofzuraw merged commit 36aea8d into main Jan 20, 2025
17 checks passed
@krzysztofzuraw krzysztofzuraw deleted the shopx-1749-segment-dynamodb-config branch January 20, 2025 14:21
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.

2 participants