Skip to content

Commit

Permalink
Merge branch 'main' of github.com:immutable/ts-immutable-sdk into tes…
Browse files Browse the repository at this point in the history
…t/clear-injected-providers
  • Loading branch information
jwhardwick committed Aug 28, 2024
2 parents 3cb1328 + 8071264 commit eac8a60
Show file tree
Hide file tree
Showing 273 changed files with 5,637 additions and 3,161 deletions.
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
"node_modules/",
"dist/",
"**sample-app**/",
"**playground**/"
"**playground**/",
"*.cjs",
"tests/func-tests/"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"project": "./tsconfig.base.json",
"tsconfigRootDir": "."
},
"rules": {
Expand Down
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# prevent heap limit allocation errors
export NODE_OPTIONS="--max-old-space-size=4096"

yarn lint-staged
2 changes: 1 addition & 1 deletion build-dependents.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ try {

if (isDependent || changedProject === currentProject) {
// Rebuild the current project
const command = `nx run-many --target=d --projects=${currentProject} --parallel=5`;
const command = `nx run-many --target=d --projects=${currentProject} --parallel=5 --no-cloud`;

console.log(`Running command: ${command}`);
execSync(command, { stdio: 'inherit' });
Expand Down
2 changes: 1 addition & 1 deletion dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ fi

# Run nx commands with the selected or provided package name
echo "Running commands for package: $PACKAGE_NAME"
nx run $PACKAGE_NAME:d --parallel=5
nx run $PACKAGE_NAME:d --parallel=5 --no-cloud
nx watch --all -- node ./build-dependents.js \$NX_PROJECT_NAME $(echo $PACKAGE_NAME)
353 changes: 231 additions & 122 deletions examples/README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/passport/identity-with-nextjs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": true,
"extends": "next/core-web-vitals"
}
1 change: 1 addition & 0 deletions examples/passport/next-connect-kit/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": true,
"extends": "next/core-web-vitals"
}
1 change: 1 addition & 0 deletions examples/passport/next-rainbow-kit/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": true,
"extends": "next/core-web-vitals"
}
1 change: 1 addition & 0 deletions examples/passport/next-wagmi/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": true,
"extends": "next/core-web-vitals"
}
1 change: 1 addition & 0 deletions examples/passport/next-web3-modal/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": true,
"extends": "next/core-web-vitals"
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": true,
"extends": ["next/core-web-vitals", "next"]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": true,
"extends": ["next/core-web-vitals", "next"]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"root": true,
"extends": "next/core-web-vitals"
}
9 changes: 9 additions & 0 deletions examples/primary-sales-backend-api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PORT=3000

# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://postgres:postgres@localhost:5432/primarysales?schema=public"
4 changes: 4 additions & 0 deletions examples/primary-sales-backend-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
# Keep environment variables out of version control
.env
build
1 change: 1 addition & 0 deletions examples/primary-sales-backend-api/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.16.0
40 changes: 40 additions & 0 deletions examples/primary-sales-backend-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Example Primary Sales Webhook API

This example shows how to implement the webhooks required for the [primary sales backend config](https://docs.immutable.com/products/zkEVM/checkout/widgets/primary-sales/backend/byo).

## Pre-requisites

* [NodeJS >= v20](https://nodejs.org/en)
* [Docker](https://www.docker.com/)

### Install dependencies

Run `npm i`

### Set environment variables

Copy the `.env.example` file and rename it to `.env`.

## Running the app

1. Run `docker-compose up -d` to start the postgres DB at port 5432.
2. Run `npx prisma migrate dev` and `npm run seed` to initialise the DB schema and seed it with data.
3. `npm run dev` to start your server on port 3000

## Webhook endpoints

To see the list of endpoints this example serves, go to [the Swagger UI](http://localhost:3000/docs).

Apart from the `/api/v1/products` endpoint which is used to list the products available in the DB, the rest of the endpoints correspond to the [Primary Sales backend config documentation](https://docs.immutable.com/products/zkEVM/checkout/widgets/primary-sales/backend/byo).


## Example requests

For your convenience, we have also added a postman collection under the `postman` folder. These contain sample requests for each endpoint, using the seeded products data.

To run the requests, download [Postman](https://www.postman.com/) and import the collection.


## TO-DO list

* Add authentication for each endpoint, as per the [webhook authentication section](https://docs.immutable.com/products/zkEVM/checkout/widgets/primary-sales/backend/byo#webhook-authentication)
18 changes: 18 additions & 0 deletions examples/primary-sales-backend-api/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.8'

services:
primary-sales-db:
image: postgres:14
ports:
- 5432:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=primarysales
restart: always
volumes:
- primary-sales-db-data:/data/postgres

volumes:
primary-sales-db-data:

29 changes: 29 additions & 0 deletions examples/primary-sales-backend-api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"devDependencies": {
"@types/node": "^22.2.0",
"fastify-tsconfig": "^2.0.0",
"nodemon": "^3.1.4",
"prisma": "^5.18.0",
"ts-node": "^10.9.2",
"typescript": "^5.5.4"
},
"dependencies": {
"@fastify/autoload": "^5.10.0",
"@fastify/env": "^4.4.0",
"@fastify/swagger": "^8.15.0",
"@fastify/swagger-ui": "^4.1.0",
"@fastify/type-provider-typebox": "^4.0.0",
"@paralleldrive/cuid2": "^2.2.2",
"@prisma/client": "^5.18.0",
"fastify": "^4.28.1"
},
"prisma": {
"seed": "ts-node prisma/seed.ts"
},
"scripts": {
"build": "rm -rf build ; tsc",
"start": "node build/src/server.js",
"dev": "nodemon --exec ts-node src/server.ts",
"seed": "prisma db seed"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"info": {
"_postman_id": "c754b503-fb61-4722-8fac-47fecc2efb3e",
"name": "Primary sales BE",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "25754861"
},
"item": [
{
"name": "Quote",
"request": {
"method": "POST",
"header": [
{
"key": "QUOTE_API_KEY",
"value": "test_api_key",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"recipient_address\": \"0xdd9AAE1C317eE6EFEb0F3DB0A068e9Ed952a6CEB\",\n \"products\": [\n {\n \"product_id\": \"vi7age4ku18qynwbk4wx90ge\",\n \"quantity\": 1\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "localhost:3000/api/v1/orders/quotes",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"orders",
"quotes"
]
}
},
"response": []
},
{
"name": "Create order",
"request": {
"method": "POST",
"header": [
{
"key": "QUOTE_API_KEY",
"value": "test_api_key",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"recipient_address\": \"0xdd9AAE1C317eE6EFEb0F3DB0A068e9Ed952a6CEB\",\n \"currency\": \"USDC\",\n \"products\": [\n {\n \"product_id\": \"vi7age4ku18qynwbk4wx90ge\",\n \"quantity\": 1\n },\n {\n \"product_id\": \"jtwrclpj0v1zab865ne893hb\",\n \"quantity\": 1\n }\n ]\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "localhost:3000/api/v1/sale-authorization",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"sale-authorization"
]
}
},
"response": []
},
{
"name": "Expire an order",
"request": {
"method": "POST",
"header": [
{
"key": "QUOTE_API_KEY",
"value": "test_api_key",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"reference\": \"cm02a70000001updhnudm7bop\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "localhost:3000/api/v1/expire",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"expire"
]
}
},
"response": []
},
{
"name": "Confirm",
"request": {
"method": "POST",
"header": [
{
"key": "QUOTE_API_KEY",
"value": "test_api_key",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"reference\": \"cm02apig000035o3ipwszr02z\",\n \"tx_hash\": \"test\",\n \"recipient_address\": \"0xdd9AAE1C317eE6EFEb0F3DB0A068e9Ed952a6CEB\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "localhost:3000/api/v1/confirm",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"confirm"
]
}
},
"response": []
},
{
"name": "Products",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "QUOTE_API_KEY",
"value": "test_api_key",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"reference\": \"cm02a70000001updhnudm7bop\",\n \"tx_hash\": \"test\",\n \"recipient_address\": \"0xdd9AAE1C317eE6EFEb0F3DB0A068e9Ed952a6CEB\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "localhost:3000/api/v1/products",
"host": [
"localhost"
],
"port": "3000",
"path": [
"api",
"v1",
"products"
]
}
},
"response": []
}
]
}
Loading

0 comments on commit eac8a60

Please sign in to comment.