Copy the Chatwoot (v4.14.0) frontend runnable subset into frontend/ for customization: - app/javascript/ (Vue SPA: dashboard, widget, sdk, portal, superadmin) - app/views/ (ERB templates for vite-plugin-ruby entrypoint resolution) - app/helpers/, app/assets/ (Rails view helpers, static assets) - enterprise/ (Enterprise edition frontend overlay) - config/vite.json, vite.config.ts, bin/vite (Vite-Rails toolchain) - package.json, pnpm-lock.yaml, tailwind/postcss/eslint configs - Gemfile, Gemfile.lock (vite_rails gem for bin/vite binstub) Excluded Rails backend: controllers, models, services, jobs, mailers, policies, db, lib, spec, public, node_modules. Update references to the new frontend location: - .gitignore: exclude frontend build artifacts (node_modules, tmp, packs), keep frontend/bin/ and frontend/vendor/ via negation - backend/scripts/parity_frontend_smoke.sh: CHATWOOT_DIR default reference/chatwoot -> ../frontend - backend/scripts/parity_frontend_browser_smoke.mjs: same default update - AGENTS.md: add frontend section with Rails/Vite coupling notes - README: architecture tree includes frontend/
59 lines
1.5 KiB
Ruby
59 lines
1.5 KiB
Ruby
module Shopify::IntegrationHelper
|
|
REQUIRED_SCOPES = %w[read_customers read_orders read_fulfillments].freeze
|
|
|
|
# Generates a signed JWT token for Shopify integration
|
|
#
|
|
# @param account_id [Integer] The account ID to encode in the token
|
|
# @return [String, nil] The encoded JWT token or nil if client secret is missing
|
|
def generate_shopify_token(account_id)
|
|
return if client_secret.blank?
|
|
|
|
JWT.encode(token_payload(account_id), client_secret, 'HS256')
|
|
rescue StandardError => e
|
|
Rails.logger.error("Failed to generate Shopify token: #{e.message}")
|
|
nil
|
|
end
|
|
|
|
def token_payload(account_id)
|
|
{
|
|
sub: account_id,
|
|
iat: Time.current.to_i
|
|
}
|
|
end
|
|
|
|
# Verifies and decodes a Shopify JWT token
|
|
#
|
|
# @param token [String] The JWT token to verify
|
|
# @return [Integer, nil] The account ID from the token or nil if invalid
|
|
def verify_shopify_token(token)
|
|
return if token.blank? || client_secret.blank?
|
|
|
|
decode_token(token, client_secret)
|
|
end
|
|
|
|
private
|
|
|
|
def client_id
|
|
@client_id ||= GlobalConfigService.load('SHOPIFY_CLIENT_ID', nil)
|
|
end
|
|
|
|
def client_secret
|
|
@client_secret ||= GlobalConfigService.load('SHOPIFY_CLIENT_SECRET', nil)
|
|
end
|
|
|
|
def decode_token(token, secret)
|
|
JWT.decode(
|
|
token,
|
|
secret,
|
|
true,
|
|
{
|
|
algorithm: 'HS256',
|
|
verify_expiration: true
|
|
}
|
|
).first['sub']
|
|
rescue StandardError => e
|
|
Rails.logger.error("Unexpected error verifying Shopify token: #{e.message}")
|
|
nil
|
|
end
|
|
end
|