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: Add integration with: Webflow (ecommerce) #685

Merged
merged 12 commits into from
Sep 3, 2024

Conversation

amuwal
Copy link
Contributor

@amuwal amuwal commented Sep 1, 2024

Adding webflow integrating to ecommerce front. Issue #640

Objects

  • Customers (read)
  • Orders (read)
  • Products (read, add-product)

demo: https://drive.google.com/file/d/1QGYlbbgcTYEQIJGtWV0O8DcLO_U0Qcti/view?usp=sharing

Summary by CodeRabbit

  • New Features

    • Added support for the Webflow e-commerce platform, enabling integration for products, orders, and customers.
    • Expanded the e-commerce connectors to include Webflow, improving integration options.
  • Bug Fixes

    • Addressed issues related to the handling of new data structures and integration processes.
  • Documentation

    • Updated documentation to reflect the new Webflow integrations and usage guidelines.
  • Chores

    • Improved internal configurations to support the new Webflow connector functionalities.

@naelob
Copy link
Member

naelob commented Sep 1, 2024

Qovery Preview

Qovery can create a Preview Environment for this PR.
To trigger its creation, please post a comment with one of the following command.

Command Blueprint environment
/qovery preview 783d0240-ec38-4387-a9a9-8e225f1bd3e1 dev
/qovery preview {all|UUID1,UUID2,...} To preview multiple environments

This comment has been generated from Qovery AI 🤖.
Below, a word from its wisdom :

You are going to thank you later if it contains tests

Copy link

changeset-bot bot commented Sep 1, 2024

⚠️ No Changeset found

Latest commit: 5e42b21

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@CLAassistant
Copy link

CLAassistant commented Sep 1, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ amuwal
❌ naelob
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

coderabbitai bot commented Sep 1, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

Walkthrough

The changes introduce support for the Webflow e-commerce platform across various components of the application. This includes modifications to the database schema, seed data, type definitions, and service implementations to facilitate integration with Webflow. Additionally, connectors and metadata configurations have been updated to activate the Webflow integration, expanding the application's e-commerce capabilities.

Changes

Files Change Summary
packages/api/scripts/init.sql, packages/api/scripts/seed.sql Added a new column ecom_webflow to the connector_sets table and updated seed data to include this column with values set to TRUE.
packages/shared/src/connectors/enum.ts, packages/shared/src/connectors/index.ts Updated EcommerceConnectors enum to include WEBFLOW and added 'webflow' to the ECOMMERCE_PROVIDERS array.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between baa43eb and 4655583.

Files selected for processing (18)
  • packages/api/scripts/init.sql (1 hunks)
  • packages/api/scripts/seed.sql (1 hunks)
  • packages/api/src/@core/utils/types/original/original.ecommerce.ts (4 hunks)
  • packages/api/src/ecommerce/customer/customer.module.ts (2 hunks)
  • packages/api/src/ecommerce/customer/services/webflow/index.ts (1 hunks)
  • packages/api/src/ecommerce/customer/services/webflow/mappers.ts (1 hunks)
  • packages/api/src/ecommerce/customer/services/webflow/types.ts (1 hunks)
  • packages/api/src/ecommerce/order/order.module.ts (2 hunks)
  • packages/api/src/ecommerce/order/services/webflow/index.ts (1 hunks)
  • packages/api/src/ecommerce/order/services/webflow/mappers.ts (1 hunks)
  • packages/api/src/ecommerce/order/services/webflow/types.ts (1 hunks)
  • packages/api/src/ecommerce/product/product.module.ts (2 hunks)
  • packages/api/src/ecommerce/product/services/webflow/index.ts (1 hunks)
  • packages/api/src/ecommerce/product/services/webflow/mappers.ts (1 hunks)
  • packages/api/src/ecommerce/product/services/webflow/types.ts (1 hunks)
  • packages/shared/src/connectors/enum.ts (1 hunks)
  • packages/shared/src/connectors/index.ts (1 hunks)
  • packages/shared/src/connectors/metadata.ts (1 hunks)
Additional context used
Biome
packages/api/src/ecommerce/customer/services/webflow/index.ts

[error] 57-57: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

packages/api/src/ecommerce/order/services/webflow/index.ts

[error] 55-55: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

packages/api/src/ecommerce/product/services/webflow/index.ts

[error] 61-61: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 97-97: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

packages/api/src/ecommerce/product/services/webflow/mappers.ts

[error] 49-49: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)

Additional comments not posted (36)
packages/shared/src/connectors/index.ts (1)

8-8: LGTM!

The addition of 'webflow' to the ECOMMERCE_PROVIDERS constant is approved. It expands the supported ecommerce providers without introducing any issues.

packages/shared/src/connectors/enum.ts (1)

14-15: LGTM!

The addition of the WEBFLOW enum value to the EcommerceConnectors enum is approved. It expands the supported ecommerce connectors without introducing any issues and aligns with the change made in the index.ts file.

packages/api/src/ecommerce/customer/services/webflow/types.ts (1)

1-33: LGTM! The type definitions align with the Webflow API documentation.

The WebflowCustomerInput interface, WebflowCustomerOutput type, and related types and enums are well-defined and match the structure described in the Webflow API documentation.

packages/api/scripts/seed.sql (1)

4-7: LGTM!

The code changes are approved. The SQL statement has been updated to include the new ecom_webflow column, and the values are consistent across all entries.

packages/api/src/ecommerce/product/product.module.ts (1)

15-16: LGTM!

The code changes are approved. The module has been enhanced to support Webflow by importing and providing WebflowService and WebflowProductMapper, following the existing pattern for other e-commerce platforms.

Also applies to: 36-37

packages/api/src/ecommerce/customer/customer.module.ts (1)

16-17: LGTM!

The code changes are approved. The module has been enhanced to support Webflow by importing and providing WebflowService and WebflowCustomerMapper, following the existing pattern for other e-commerce platforms.

Also applies to: 35-36

packages/api/src/ecommerce/order/order.module.ts (2)

13-14: LGTM!

The code changes are approved.


40-41: LGTM!

The code changes are approved.

packages/api/src/ecommerce/product/services/webflow/types.ts (1)

1-107: LGTM!

The new type definitions for Webflow products are well-structured and comprehensive. They cover the essential properties of products, SKUs, pricing, images, and subscription plans. The interfaces follow a clear naming convention and are well-documented with references to the Webflow API documentation.

The code changes are approved.

packages/api/src/ecommerce/customer/services/webflow/mappers.ts (1)

1-91: LGTM!

The new mapper service for Webflow customers is well-implemented. It follows the dependency injection pattern and is properly registered with the mappers registry. The unify method handles both single customer and array of customers, mapping them to the unified customer type using the mapSingleCustomerToUnified method.

The code changes are approved.

packages/api/src/ecommerce/product/services/webflow/index.ts (1)

1-100: LGTM!

The new Webflow product service is well-implemented. It properly handles the creation and syncing of products using the Webflow API. The service is decorated with @Injectable() and registered with the service registry. The addProduct and sync methods make the necessary API requests using Axios and decrypt the access token from the database connection.

The code changes are approved.

Tools
Biome

[error] 61-61: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 97-97: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

packages/api/src/@core/utils/types/original/original.ecommerce.ts (6)

69-70: LGTM!

The code changes are approved.


77-78: LGTM!

The code changes are approved.


87-88: LGTM!

The code changes are approved.


106-107: LGTM!

The code changes are approved.


114-115: LGTM!

The code changes are approved.


125-126: LGTM!

The code changes are approved.

packages/api/src/ecommerce/product/services/webflow/mappers.ts (2)

27-66: LGTM!

The code changes are approved.

Tools
Biome

[error] 49-49: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


68-118: LGTM!

The code changes are approved.

packages/api/src/ecommerce/order/services/webflow/mappers.ts (2)

32-52: LGTM!

The code changes are approved.


54-112: LGTM!

The code changes are approved.

packages/api/src/ecommerce/order/services/webflow/types.ts (13)

3-54: LGTM!

The WebflowOrderInput interface looks comprehensive and well-structured. The use of the readonly modifier for most fields is a good practice to prevent unintended mutations.


56-60: LGTM!

The Money interface looks good and captures the essential components of a monetary value.


62-72: LGTM!

The Address interface looks comprehensive and caters to different address formats. The inclusion of the optional japanType field for handling Japan-specific addresses is a nice touch.


74-80: LGTM!

The FileObjectVariant interface looks good and captures the essential properties of a file object variant.


82-90: LGTM!

The FileObject interface looks comprehensive and includes all the essential details of a file object.


92-111: LGTM!

The PurchasedItem interface looks comprehensive and captures all the relevant details of a purchased item in an order.


113-122: LGTM!

The StripeDetails interface looks good and includes all the necessary Stripe-related details for an order.


124-131: LGTM!

The PaypalDetails interface looks good and includes all the necessary PayPal-related details for an order.


133-141: LGTM!

The StripeCard interface looks good and captures the essential details of a Stripe card used for payment.


143-152: LGTM!

The Totals interface looks good and provides a clear breakdown of the order totals, including subtotal, extras, and the grand total.


154-163: LGTM!

The DisputeStatus enum looks comprehensive and covers all the possible statuses of a payment dispute.


175-175: LGTM!

The WebflowOrderOutput type alias looks good and provides flexibility for representing partial Webflow order outputs by making all fields of WebflowOrderInput optional.


165-173: Consider adding a few more popular card brands.

The StripeCardBrands enum looks good and covers the common card brands. However, consider adding a few more popular brands like Discover and JCB for completeness.

 enum StripeCardBrands {
   VISA = 'Visa',
   AMEX = 'American Express',
   MASTERCARD = 'MasterCard',
+  DISCOVER = 'Discover',
+  JCB = 'JCB',
   UNKNOWN = 'Unknown',
 }

Likely invalid or redundant comment.

packages/api/scripts/init.sql (1)

552-552: LGTM!

The addition of the ecom_webflow column to the connector_sets table looks good. It enables tracking the integration status or configuration for the Webflow e-commerce platform, enhancing the table's structure to accommodate more diverse e-commerce integrations.

packages/shared/src/connectors/metadata.ts (1)

2923-2923: Verify the readiness and intentionality of enabling the Webflow connector.

The change itself to enable the Webflow connector is straightforward. However, it's important to verify that:

  1. The Webflow integration is fully implemented, tested and ready to be enabled.
  2. Enabling the connector at this point is intentional and aligns with the PR objectives.
  3. There are no breaking changes or unintended side-effects of enabling the connector.

To verify the above, please confirm that:

  • The Webflow integration has been fully implemented, covering the sync and creation of orders, fulfillments, fulfillment orders, customers and products.
  • Comprehensive testing has been done, including end-to-end scenarios, to ensure the integration works as expected.
  • Enabling the connector at this stage is a conscious decision and aligns with the goals of this PR.
  • Thorough testing has been done to verify there are no breaking changes or unintended side-effects on other parts of the application due to enabling this connector.

Comment on lines +1 to +33
// ref: https://docs.developers.webflow.com/data/reference/list-users

export interface WebflowCustomerInput {
id: string;
isEmailVerified: boolean;
lastUpdated: string;
invitedOn: string;
createdOn: string;
lastLogin: string;
status: 'invited' | 'verified' | 'unverified';
accessGroups: AccessGroup[];
data: UserData;
}

type AccessGroup = {
slug: string;
type: AccessGroupType;
};

enum AccessGroupType {
ADMIN = 'admin', // Assigned to the user via API or in the designer
ECOMMERCE = 'ecommerce', // Assigned to the user via an ecommerce purchase
}

type UserData = {
name: string;
email: string;
acceptPrivacy: boolean;
acceptCommunications: boolean;
[key: string]: any;
};

export type WebflowCustomerOutput = Partial<WebflowCustomerInput>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Add JSDoc comments to improve documentation.

Consider adding JSDoc comments to the interfaces, types, and enums to provide more context and improve the documentation of the code.

For example:

/**
 * Represents a Webflow customer.
 * @see https://docs.developers.webflow.com/data/reference/list-users
 */
export interface WebflowCustomerInput {
  // ...
}

/**
 * Represents an access group assigned to a Webflow customer.
 */
type AccessGroup = {
  // ...
};

/**
 * Enum representing the possible types of access groups.
 */
enum AccessGroupType {
  // ...
}

/**
 * Represents the custom data associated with a Webflow customer.
 */
type UserData = {
  // ...
};

/**
 * Represents the output type for a Webflow customer.
 */
export type WebflowCustomerOutput = Partial<WebflowCustomerInput>;

Comment on lines +1 to +60
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { ICustomerService } from '@ecommerce/customer/types';
import { Injectable } from '@nestjs/common';
import { EcommerceObject } from '@panora/shared';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { WebflowCustomerOutput } from './types';

@Injectable()
export class WebflowService implements ICustomerService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
`${EcommerceObject.customer.toUpperCase()}:${WebflowService.name}`,
);
this.registry.registerService('webflow', this);
}

async sync(data: SyncParam): Promise<ApiResponse<WebflowCustomerOutput[]>> {
try {
const { linkedUserId } = data;

const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'webflow',
vertical: 'ecommerce',
},
});

const resp = await axios.get(`${connection.account_url}/users`, {
headers: {
'Content-Type': 'application/json',
authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
});
const customers: WebflowCustomerOutput[] = resp.data.users;

this.logger.log(`Synced webflow customers !`);

return {
data: customers,
message: 'Webflow customers retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! But remove the redundant catch clause.

The code changes are approved. However, the catch clause at line 57 is redundant and can be removed.

Apply this diff to remove the redundant catch clause:

-    } catch (error) {
-      throw error;
-    }
+    }
   }
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { ICustomerService } from '@ecommerce/customer/types';
import { Injectable } from '@nestjs/common';
import { EcommerceObject } from '@panora/shared';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { WebflowCustomerOutput } from './types';
@Injectable()
export class WebflowService implements ICustomerService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
`${EcommerceObject.customer.toUpperCase()}:${WebflowService.name}`,
);
this.registry.registerService('webflow', this);
}
async sync(data: SyncParam): Promise<ApiResponse<WebflowCustomerOutput[]>> {
try {
const { linkedUserId } = data;
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'webflow',
vertical: 'ecommerce',
},
});
const resp = await axios.get(`${connection.account_url}/users`, {
headers: {
'Content-Type': 'application/json',
authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
});
const customers: WebflowCustomerOutput[] = resp.data.users;
this.logger.log(`Synced webflow customers !`);
return {
data: customers,
message: 'Webflow customers retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
}
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { ICustomerService } from '@ecommerce/customer/types';
import { Injectable } from '@nestjs/common';
import { EcommerceObject } from '@panora/shared';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { WebflowCustomerOutput } from './types';
@Injectable()
export class WebflowService implements ICustomerService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
`${EcommerceObject.customer.toUpperCase()}:${WebflowService.name}`,
);
this.registry.registerService('webflow', this);
}
async sync(data: SyncParam): Promise<ApiResponse<WebflowCustomerOutput[]>> {
const { linkedUserId } = data;
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'webflow',
vertical: 'ecommerce',
},
});
const resp = await axios.get(`${connection.account_url}/users`, {
headers: {
'Content-Type': 'application/json',
authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
});
const customers: WebflowCustomerOutput[] = resp.data.users;
this.logger.log(`Synced webflow customers !`);
return {
data: customers,
message: 'Webflow customers retrieved',
statusCode: 200,
};
}
}
Tools
Biome

[error] 57-57: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

Comment on lines +1 to +58
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { IOrderService } from '@ecommerce/order/types';
import { Injectable } from '@nestjs/common';
import { EcommerceObject } from '@panora/shared';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { WebflowOrderInput, WebflowOrderOutput } from './types';

@Injectable()
export class WebflowService implements IOrderService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
`${EcommerceObject.order.toUpperCase()}:${WebflowService.name}`,
);
this.registry.registerService('webflow', this);
}

async sync(data: SyncParam): Promise<ApiResponse<WebflowOrderOutput[]>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: data.linkedUserId,
provider_slug: 'webflow',
vertical: 'ecommerce',
},
});

// ref: https://docs.developers.webflow.com/data/reference/list-orders
const resp = await axios.get(`${connection.account_url}/orders`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
});
const orders: WebflowOrderOutput[] = resp.data.orders;
this.logger.log(`Synced webflow orders !`);

return {
data: orders,
message: 'Webflow orders retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM! But remove the redundant catch clause.

The code changes are approved. However, the catch clause at line 55 is redundant and can be removed.

Apply this diff to remove the redundant catch clause:

-    } catch (error) {
-      throw error;
-    }
+    }
   }
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { IOrderService } from '@ecommerce/order/types';
import { Injectable } from '@nestjs/common';
import { EcommerceObject } from '@panora/shared';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { WebflowOrderInput, WebflowOrderOutput } from './types';
@Injectable()
export class WebflowService implements IOrderService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
`${EcommerceObject.order.toUpperCase()}:${WebflowService.name}`,
);
this.registry.registerService('webflow', this);
}
async sync(data: SyncParam): Promise<ApiResponse<WebflowOrderOutput[]>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: data.linkedUserId,
provider_slug: 'webflow',
vertical: 'ecommerce',
},
});
// ref: https://docs.developers.webflow.com/data/reference/list-orders
const resp = await axios.get(`${connection.account_url}/orders`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
});
const orders: WebflowOrderOutput[] = resp.data.orders;
this.logger.log(`Synced webflow orders !`);
return {
data: orders,
message: 'Webflow orders retrieved',
statusCode: 200,
};
} catch (error) {
throw error;
}
}
}
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { IOrderService } from '@ecommerce/order/types';
import { Injectable } from '@nestjs/common';
import { EcommerceObject } from '@panora/shared';
import axios from 'axios';
import { ServiceRegistry } from '../registry.service';
import { WebflowOrderInput, WebflowOrderOutput } from './types';
@Injectable()
export class WebflowService implements IOrderService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(
`${EcommerceObject.order.toUpperCase()}:${WebflowService.name}`,
);
this.registry.registerService('webflow', this);
}
async sync(data: SyncParam): Promise<ApiResponse<WebflowOrderOutput[]>> {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: data.linkedUserId,
provider_slug: 'webflow',
vertical: 'ecommerce',
},
});
// ref: https://docs.developers.webflow.com/data/reference/list-orders
const resp = await axios.get(`${connection.account_url}/orders`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
});
const orders: WebflowOrderOutput[] = resp.data.orders;
this.logger.log(`Synced webflow orders !`);
return {
data: orders,
message: 'Webflow orders retrieved',
statusCode: 200,
};
}
}
Tools
Biome

[error] 55-55: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

Comment on lines +27 to +35
async desunify(
source: UnifiedEcommerceCustomerInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): Promise<WebflowCustomerInput> {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Reminder: Implement the desunify method.

The desunify method is currently not implemented and returns undefined. Please implement the logic to convert from the unified customer type to the Webflow-specific customer type.

Do you want me to generate the implementation for the desunify method or open a GitHub issue to track this task?

Comment on lines +60 to +62
} catch (error) {
throw error;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove redundant catch clauses.

The catch clauses in the addProduct and sync methods only rethrow the original error, which is redundant and can be confusing. It is recommended to remove these unnecessary catch clauses.

Apply this diff to remove the redundant catch clauses:

-    } catch (error) {
-      throw error;
-    }
+    }

Also applies to: 96-98

Tools
Biome

[error] 61-61: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

Comment on lines +22 to +30
async desunify(
source: UnifiedEcommerceOrderInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): Promise<WebflowOrderInput> {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Implement the desunify method.

The desunify method is not implemented and returns undefined. This may cause issues if the method is called.

Do you want me to generate the implementation for the desunify method or open a GitHub issue to track this task?

@naelob naelob merged commit dca151a into panoratech:main Sep 3, 2024
8 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants