-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from OfflineHQ/286-unlock-4-implement-key-loy…
…alty-card-contract 286 unlock 4 implement key loyalty card contract
- Loading branch information
Showing
804 changed files
with
186,395 additions
and
96,086 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Project Context | ||
|
||
- Name: Offline - Next-gen Consumer Brand Interaction | ||
- Description: At Offline, we are developing innovative solutions to enhance brand-customer interactions through user-centric applications using blockchain and NFT technologies. The project consists of three main apps: the web platform for users, a back-office for companies and organizers, and a micro-app called 'unlock' for token gating on Shopify pages and potential future vendor integrations. | ||
|
||
# Technology Stack | ||
|
||
- Frontend: Next.js 14, Storybook for component development | ||
- Backend: Hasura/Postgres for database operations | ||
- Testing: Jest for unit and integration tests; Playwright for end-to-end testing | ||
- Architecture: Nx monorepo setup with clean domain models. Libraries are organized within the 'libs' folder. | ||
|
||
# Code Standards | ||
|
||
- Clean Code: Follow SOLID principles and ensure code is DRY and easily testable. | ||
- Typing: Employ strict TypeScript typing to ensure robustness and maintainability. | ||
- Testing: Aim for high test coverage with well-thought-out unit, integration, and E2E tests. | ||
- Documentation: Maintain clear and comprehensive documentation, especially for public APIs and complex logic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ NX_VERCEL_REMOTE_CACHE_TOKEN=8HfZAvj1ZCUEYLuNISczuuF2 | |
NX_VERCEL_REMOTE_CACHE_TEAM=team_cNOd6z2HTsiaB0cibAjaQSIM | ||
|
||
# hasura | ||
HASURA_VERSION=v2.35.0 | ||
HASURA_VERSION=v2.38.0 | ||
HASURA_GRAPHQL_SERVER_PORT=8080 | ||
HASURA_GRAPHQL_ADMIN_SECRET=password | ||
HASURA_CONSOLE_PORT=9695 | ||
|
@@ -39,13 +39,13 @@ NEXTAUTH_SECRET="-----BEGIN RSA PRIVATE KEY-----\nMIIJKQIBAAKCAgEAtHmpqKfTdp2DNn | |
TOKEN_LIFE_TIME="648000" | ||
|
||
## web3 | ||
## Here we take the Mumbai testnet | ||
NEXT_PUBLIC_CHAIN='80001' | ||
CHAIN='80001' | ||
## Here we take the Amoy testnet | ||
NEXT_PUBLIC_CHAIN='80002' | ||
CHAIN='80002' | ||
|
||
## Alchemy | ||
NEXT_PUBLIC_ALCHEMY_API_KEY='aTwl7l6SRRC22e-7joQbT7oMG6yTjUm0' | ||
ALCHEMY_API_KEY='aTwl7l6SRRC22e-7joQbT7oMG6yTjUm0' | ||
NEXT_PUBLIC_ALCHEMY_API_KEY='o-0Gv1BvrP4mEFNNQEQziQvc7SI3T7rm' | ||
ALCHEMY_API_KEY='o-0Gv1BvrP4mEFNNQEQziQvc7SI3T7rm' | ||
ALCHEMY_AUTH_TOKEN='dGlcmvJsh6Oac3KFJFok2r0R2UgTrcYm' | ||
|
||
|
||
|
@@ -62,6 +62,10 @@ EMAIL_WEB_UI=8025 | |
WEB_APP_URL='https://www.staging.offline.live/' | ||
NEXT_PUBLIC_WEB_APP_URL='https://www.staging.offline.live/' | ||
|
||
## API | ||
|
||
API_SECRET_ENCRYPTION_KEY="5557ed70d7c542efa7d9b23516a3baed" | ||
|
||
# VIRTUAL_HOST=example.com | ||
# LETSENCRYPT_HOST=example.com | ||
# [email protected] | ||
|
@@ -127,9 +131,12 @@ POSTHOG_PERSONAL_API_KEY=phx_wIGzuBaUWMAdzBpxpkil4yIDdINhy5FfnFR4QYhUj6q | |
NEXT_PUBLIC_POSTHOG_KEY=phc_FcjrV3dP2qG5qVafKh6ULkTYGq5FWD5mT8XPk7t9Y8Q | ||
|
||
# Cometh | ||
NEXT_PUBLIC_COMETH_CONNECT_API_KEY=xPVZx4OVf7oR9O2yOI5zTOgkatkkzF6W | ||
COMETH_CONNECT_API_KEY=xPVZx4OVf7oR9O2yOI5zTOgkatkkzF6W | ||
NEXT_PUBLIC_COMETH_CONNECT_API_KEY=vDMJtXRUsdDVCXJ0GBAaKMTjuebI5S3Y | ||
COMETH_CONNECT_API_KEY=vDMJtXRUsdDVCXJ0GBAaKMTjuebI5S3Y | ||
|
||
# Wallet connect | ||
NEXT_PUBLIC_WC_PROJECT_ID=68b34422801cb3e8ea1eb7f823266c28 | ||
NEXT_PUBLIC_WC_RELAY_URL=wss://relay.walletconnect.com | ||
NEXT_PUBLIC_WC_RELAY_URL=wss://relay.walletconnect.com | ||
|
||
# Shopify | ||
SHOPIFY_SHARED_SECRET=c886ebdff67650455049c4cc52517c0d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
auto-install-peers=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { LoyaltyCardSkeleton } from '@features/back-office/loyalty-card'; | ||
|
||
export default function LoyaltyCardLoading() { | ||
return <LoyaltyCardSkeleton />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { LoyaltyCardPage } from '@features/back-office/loyalty-card'; | ||
import { getLoyaltyCardOrganizer } from '@features/back-office/loyalty-card-api'; | ||
import { type Locale } from '@next/i18n'; | ||
|
||
interface LoyaltyCardProps { | ||
params: { | ||
locale: Locale; | ||
}; | ||
} | ||
|
||
export default async function LoyaltyCard({ | ||
params: { locale }, | ||
}: LoyaltyCardProps) { | ||
const loyaltyCard = await getLoyaltyCardOrganizer(); | ||
return <LoyaltyCardPage loyaltyCard={loyaltyCard} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext" | ||
}, | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.app.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"esModuleInterop": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import env from '@env/server'; | ||
import jwt from 'jsonwebtoken'; | ||
import type { NextRequest } from 'next/server'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export const config = { | ||
matcher: '/api/shopify/admin/:path*', | ||
}; | ||
|
||
// WIP: Complete the implementation of Shopify admin API middleware. | ||
// This includes verifying session tokens, errors and test more thoughtfully with shopify app making requests using APP Bridge | ||
export async function middleware(request: NextRequest) { | ||
const sessionToken = request.headers | ||
.get('authorization') | ||
?.split('Bearer ')[1]; | ||
if (!sessionToken) { | ||
return new Response('Unauthorized: No session token provided', { | ||
status: 401, | ||
}); | ||
} | ||
|
||
try { | ||
await new Promise((resolve, reject) => { | ||
jwt.verify( | ||
sessionToken, | ||
env.SHOPIFY_SHARED_SECRET, | ||
{ algorithms: ['HS256'] }, | ||
(err, decoded) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(decoded); | ||
} | ||
}, | ||
); | ||
}); | ||
|
||
return NextResponse.next(); | ||
} catch (error) { | ||
console.error('Token verification error:', error); | ||
return new Response('Unauthorized: Invalid token', { status: 401 }); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/web/app/api/shopify/loyalty-card/[contractAddress]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ShopifyWebhookAndApiHandler } from '@integrations/external-api-handlers'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export async function POST( | ||
req: NextRequest, | ||
{ params: { contractAddress } }: { params: { contractAddress: string } }, | ||
) { | ||
const shopifyHandler = new ShopifyWebhookAndApiHandler(); | ||
return shopifyHandler.mintLoyaltyCardWithCustomerId({ | ||
req, | ||
contractAddress, | ||
}); | ||
} | ||
|
||
export async function GET( | ||
req: NextRequest, | ||
{ params: { contractAddress } }: { params: { contractAddress: string } }, | ||
) { | ||
const shopifyHandler = new ShopifyWebhookAndApiHandler(); | ||
return shopifyHandler.hasLoyaltyCard({ req, contractAddress }); | ||
} |
Oops, something went wrong.