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

Add DynamoDB APL to Segment app #1690

Merged
merged 9 commits into from
Jan 17, 2025
Merged

Conversation

krzysztofzuraw
Copy link
Member

@krzysztofzuraw krzysztofzuraw commented Jan 13, 2025

Scope of the PR

Added DynamoDB APL. This APL is using DynamoDB as storage.

Related issues

Checklist

Copy link

changeset-bot bot commented Jan 13, 2025

🦋 Changeset detected

Latest commit: af4d5f6

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 13, 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 17, 2025 9:05am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
saleor-app-avatax ⬜️ Skipped (Inspect) Jan 17, 2025 9:05am
saleor-app-cms ⬜️ Skipped (Inspect) Jan 17, 2025 9:05am
saleor-app-klaviyo ⬜️ Skipped (Inspect) Jan 17, 2025 9:05am
saleor-app-products-feed ⬜️ Skipped (Inspect) Jan 17, 2025 9:05am
saleor-app-search ⬜️ Skipped (Inspect) Jan 17, 2025 9:05am
saleor-app-smtp ⬜️ Skipped (Inspect) Jan 17, 2025 9:05am

static MissingEnvVariablesError = BaseError.subclass("MissingEnvVariablesError");

constructor({ segmentAPLEntity }: { segmentAPLEntity: SegmentAPLEntityType }) {
this.segmentAPLRepository = new SegmentAPLRepository({ segmentAPLEntity });
Copy link
Member

Choose a reason for hiding this comment

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

why dont you inject repo?

});

if (getEntryResult.isErr()) {
// TODO: should we throw here?
Copy link
Member

Choose a reason for hiding this comment

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

no, because APL interface is allowing undefined as a non-existing value

but, we should check:

  1. if its 404-like error, map to underfined
  2. if its connection error/db down etc, we should throw (panic mode)

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'm wondering if we have a easy way of knowing if there is connection error - I checked and toolbox doesn't expose that info if it throws error

Copy link
Member

Choose a reason for hiding this comment

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

I think:

  1. Every promise rejection from dynamo is "unhandled"
  2. Resolved promise with Item === null is correct request, but empty database row

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense - I will update implementation to add such logic

import { SegmentAPLEntityType } from "@/modules/db/segment-main-table";

export class DynamoAPL implements APL {
private segmentAPLRepository: SegmentAPLRepository;
Copy link
Member

Choose a reason for hiding this comment

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

nitpick, but the class is APL and app context is Segment, so you "know" the outer context - you dont have to prefix it. Calling variable "repo" or "repository" is verbose enough

apps/segment/src/lib/dynamodb-apl.ts Outdated Show resolved Hide resolved
const getAllEntriesResult = await this.segmentAPLRepository.getAllEntries();

if (getAllEntriesResult.isErr()) {
// TODO: should we throw here?
Copy link
Member

Choose a reason for hiding this comment

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

same as above- depending on the error type

Comment on lines 50 to 54
if (!getEntryResult.value.Item) {
this.logger.warn("APL entry not found", { args });

return err(new SegmentAPLRepository.ReadEntityError("APL entry not found"));
}
Copy link
Member

Choose a reason for hiding this comment

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

you can also consider less verobse interface: ResultAsync<AuthData | null, Error> where we push null as a successful data flow, separated from error flow. I'm not highly opinionated here, but handling will be less verbose than instanceOf

return err(setEntryResult.error);
}

return ok(undefined);
Copy link
Member

Choose a reason for hiding this comment

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

do we have anything valuable returned from dynamo?

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 checked and we have:

  • ConsumedCapacity
  • ToolboxItem - entry itself

I'm wondering if we need this data in APL class?

Copy link
Member

Choose a reason for hiding this comment

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

I think this happens so rarely it doesn't matter, but preferably if we don't return anything, we can save transfer from Dynamo too (don't fetch what we don't need).

Comment on lines 15 to 19
typeof Table<
{ name: "PK"; type: "string" },
{
name: "SK";
type: "string";
Copy link
Member

Choose a reason for hiding this comment

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

can you put these genetic to a variable? its cryptic and hard to read

Comment on lines 19 to 29
case "dynamodb": {
if (
!env.DYNAMODB_MAIN_TABLE_NAME ||
!env.AWS_REGION ||
!env.AWS_ACCESS_KEY_ID ||
!env.AWS_SECRET_ACCESS_KEY
) {
throw new MisconfiguredDynamoAPLError(
"DynamoDB APL is not configured - missing env variables. Check saleor-app.ts",
);
}
Copy link
Member

Choose a reason for hiding this comment

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

can we move it to env.ts?

Copy link
Contributor

Differences Found

✅ No packages or licenses were added.

Summary

Expand
License Name Package Count Packages
0BSD 1
Packages
  • tslib
CC BY-SA 4.0 1
Packages
  • @cspell/dict-en-common-misspellings
CC-BY-3.0 1
Packages
  • spdx-exceptions
GPL-3.0 1
Packages
  • store2
MIT (http://mootools.net/license.txt) 1
Packages
  • slick
Public Domain 1
Packages
  • jsonify
Python-2.0 1
Packages
  • argparse
SEE LICENSE IN LICENSE.md 1
Packages
  • lightcookie
WTFPL 1
Packages
  • opener
BlueOak-1.0.0 2
Packages
  • jackspeak
  • path-scurry
CC-BY-4.0 2
Packages
  • @saleor/macaw-ui
  • caniuse-lite
Unlicense 2
Packages
  • @sinonjs/text-encoding
  • big-integer
CC0-1.0 3
Packages
  • language-subtag-registry
  • spdx-license-ids
  • type-fest
<<missing>> 4
Packages
  • bruno
  • busboy
  • json-query
  • streamsearch
MPL-2.0 10
Packages
  • axe-core
  • eslint-config-turbo
  • eslint-plugin-turbo
  • turbo
  • turbo-darwin-64
  • turbo-darwin-arm64
  • turbo-linux-64
  • turbo-linux-arm64
  • turbo-windows-64
  • turbo-windows-arm64
BSD-2-Clause 31
Packages
  • @base2/pretty-print-object
  • @typescript-eslint/parser
  • @typescript-eslint/typescript-estree
  • @yarnpkg/esbuild-plugin-pnp
  • cheerio-select
  • css-select
  • css-what
  • damerau-levenshtein
  • domelementtype
  • domhandler
  • domutils
  • dotenv
  • dotenv-expand
  • entities
  • escodegen
  • eslint-scope
  • espree
  • esprima
  • esrecurse
  • estraverse
  • And 11 more...
BSD-3-Clause 52
Packages
  • @humanwhocodes/object-schema
  • @protobufjs/aspromise
  • @protobufjs/base64
  • @protobufjs/codegen
  • @protobufjs/eventemitter
  • @protobufjs/fetch
  • @protobufjs/float
  • @protobufjs/inquire
  • @protobufjs/path
  • @protobufjs/pool
  • @protobufjs/utf8
  • @saleor/eslint-plugin-saleor-app
  • @sentry/cli
  • @sentry/cli-darwin
  • @sentry/cli-linux-arm
  • @sentry/cli-linux-arm64
  • @sentry/cli-linux-i686
  • @sentry/cli-linux-x64
  • @sentry/cli-win32-i686
  • @sentry/cli-win32-x64
  • And 32 more...
ISC 72
Packages
  • @isaacs/cliui
  • @istanbuljs/load-nyc-config
  • @saleor/app-sdk
  • @ungap/structured-clone
  • abbrev
  • ansi-align
  • anymatch
  • aproba
  • are-we-there-yet
  • ast-types-flow
  • boolbase
  • c8
  • chownr
  • cli-width
  • cliui
  • color-support
  • concat-with-sourcemaps
  • console-control-strings
  • electron-to-chromium
  • eslint-import-resolver-typescript
  • And 52 more...
Apache-2.0 202
Packages
  • @ampproject/remapping
  • @aws-crypto/crc32
  • @aws-crypto/crc32c
  • @aws-crypto/ie11-detection
  • @aws-crypto/sha1-browser
  • @aws-crypto/sha256-browser
  • @aws-crypto/sha256-js
  • @aws-crypto/supports-web-crypto
  • @aws-crypto/util
  • @aws-sdk/abort-controller
  • @aws-sdk/chunked-blob-reader
  • @aws-sdk/client-dynamodb
  • @aws-sdk/client-s3
  • @aws-sdk/client-sso
  • @aws-sdk/client-sso-oidc
  • @aws-sdk/client-sts
  • @aws-sdk/config-resolver
  • @aws-sdk/core
  • @aws-sdk/credential-provider-env
  • @aws-sdk/credential-provider-http
  • And 182 more...
MIT 1662
Packages
  • @0no-co/graphql.web
  • @aashutoshrathi/word-wrap
  • @algolia/cache-browser-local-storage
  • @algolia/cache-common
  • @algolia/cache-in-memory
  • @algolia/client-account
  • @algolia/client-analytics
  • @algolia/client-common
  • @algolia/client-personalization
  • @algolia/client-search
  • @algolia/logger-common
  • @algolia/logger-console
  • @algolia/recommend
  • @algolia/requester-browser-xhr
  • @algolia/requester-common
  • @algolia/requester-node-http
  • @algolia/transporter
  • @ardatan/relay-compiler
  • @ardatan/sync-fetch
  • @arr/every
  • And 1642 more...

@krzysztofzuraw krzysztofzuraw removed the skip changeset Attach this label to PRs which does not need changes description for the release notes. label Jan 16, 2025
@krzysztofzuraw krzysztofzuraw changed the title WIP: Add DynamoDB APL Add DynamoDB APL to Segment app Jan 16, 2025
@krzysztofzuraw krzysztofzuraw marked this pull request as ready for review January 16, 2025 14:01
@krzysztofzuraw krzysztofzuraw requested a review from a team as a code owner January 16, 2025 14:01
@krzysztofzuraw krzysztofzuraw requested a review from a team January 16, 2025 14:01
@vercel vercel bot temporarily deployed to Preview – saleor-app-search January 17, 2025 09:04 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-products-feed January 17, 2025 09:04 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-klaviyo January 17, 2025 09:04 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-avatax January 17, 2025 09:04 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-smtp January 17, 2025 09:04 Inactive
@vercel vercel bot temporarily deployed to Preview – saleor-app-cms January 17, 2025 09:04 Inactive
@krzysztofzuraw krzysztofzuraw merged commit b61ce91 into main Jan 17, 2025
22 checks passed
@krzysztofzuraw krzysztofzuraw deleted the shopx-1749-dynamodb-apl-1 branch January 17, 2025 09:31
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