Skip to content

Commit

Permalink
Merge branch 'feature/mileage-shop' into preview
Browse files Browse the repository at this point in the history
  • Loading branch information
U-lis committed Oct 16, 2024
2 parents df218d0 + 3019beb commit be66911
Show file tree
Hide file tree
Showing 77 changed files with 4,071 additions and 1,633 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ on:
required: true
KMS_KEY_ID:
required: true
ADHOC_KMS_KEY_ID:
required: true
GOOGLE_CREDENTIAL:
required: true
APPLE_CREDENTIAL:
Expand Down Expand Up @@ -51,6 +53,8 @@ on:
required: true
REFUND_SHEET_ID:
required: true
HEADLESS_GQL_JWT_SECRET:
required: true

jobs:
deployment:
Expand Down Expand Up @@ -133,6 +137,7 @@ jobs:
ODIN_GQL_URL: ${{ vars.ODIN_GQL_URL }}
HEIMDALL_GQL_URL: ${{ vars.HEIMDALL_GQL_URL }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
ADHOC_KMS_KEY_ID: ${{ secrets.ADHOC_KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
GOOGLE_PACKAGE_NAME: ${{ vars.GOOGLE_PACKAGE_NAME }}
APPLE_BUNDLE_ID: ${{ vars.APPLE_BUNDLE_ID }}
Expand All @@ -146,12 +151,14 @@ jobs:
GOLDEN_DUST_WORK_SHEET_ID: ${{ secrets.GOLDEN_DUST_WORK_SHEET_ID }}
FORM_SHEET: ${{ vars.FORM_SHEET }}
CDN_HOST: ${{ vars.CDN_HOST }}
CDN_HOST_K: ${{ vars.CDN_HOST_K }}
PLANET_URL: ${{ vars.PLANET_URL }}
SEASON_PASS_JWT_SECRET: ${{ secrets.SEASON_PASS_JWT_SECRET }}
VOUCHER_URL: ${{ secrets.VOUCHER_URL }}
VOUCHER_JWT_SECRET: ${{ secrets.VOUCHER_JWT_SECRET }}
BRIDGE_DATA: ${{ secrets.BRIDGE_DATA }}
REFUND_SHEET_ID : ${{ secrets.REFUND_SHEET_ID }}
HEADLESS_GQL_JWT_SECRET: ${{ secrets.HEADLESS_GQL_JWT_SECRET }}
run: |
source $VENV
yarn cdk synth
Expand All @@ -168,6 +175,7 @@ jobs:
ODIN_GQL_URL: ${{ vars.ODIN_GQL_URL }}
HEIMDALL_GQL_URL: ${{ vars.HEIMDALL_GQL_URL }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
ADHOC_KMS_KEY_ID: ${{ secrets.ADHOC_KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
GOOGLE_PACKAGE_NAME: ${{ vars.GOOGLE_PACKAGE_NAME }}
APPLE_BUNDLE_ID: ${{ vars.APPLE_BUNDLE_ID }}
Expand All @@ -181,12 +189,14 @@ jobs:
GOLDEN_DUST_WORK_SHEET_ID: ${{ secrets.GOLDEN_DUST_WORK_SHEET_ID }}
FORM_SHEET: ${{ vars.FORM_SHEET }}
CDN_HOST: ${{ vars.CDN_HOST }}
CDN_HOST_K: ${{ vars.CDN_HOST_K }}
PLANET_URL: ${{ vars.PLANET_URL }}
SEASON_PASS_JWT_SECRET: ${{ secrets.SEASON_PASS_JWT_SECRET }}
VOUCHER_URL: ${{ secrets.VOUCHER_URL }}
VOUCHER_JWT_SECRET: ${{ secrets.VOUCHER_JWT_SECRET }}
BRIDGE_DATA: ${{ secrets.BRIDGE_DATA }}
REFUND_SHEET_ID : ${{ secrets.REFUND_SHEET_ID }}
HEADLESS_GQL_JWT_SECRET: ${{ secrets.HEADLESS_GQL_JWT_SECRET }}
run: |
source $VENV
yarn cdk deploy --all --require-approval never -O output.txt
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
SEASON_PASS_JWT_SECRET: ${{ secrets.SEASON_PASS_JWT_SECRET }}
HEADLESS_GQL_JWT_SECRET: ${{ secrets.HEADLESS_GQL_JWT_SECRET }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

build_frontend:
Expand All @@ -42,6 +43,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
ADHOC_KMS_KEY_ID: ${{ secrets.ADHOC_KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
APPLE_CREDENTIAL: ${{ secrets.APPLE_CREDENTIAL }}
APPLE_KEY_ID: ${{ secrets.APPLE_KEY_ID }}
Expand All @@ -56,10 +58,11 @@ jobs:
VOUCHER_JWT_SECRET: ${{ secrets.VOUCHER_JWT_SECRET }}
BRIDGE_DATA: ${{ secrets.BRIDGE_DATA }}
REFUND_SHEET_ID : ${{ secrets.REFUND_SHEET_ID }}
HEADLESS_GQL_JWT_SECRET: ${{ secrets.HEADLESS_GQL_JWT_SECRET }}

deploy_without_approval:
# This is for development / internal deployment
if: ${{ github.ref == 'refs/heads/preview' || github.ref == 'refs/heads/development' || startsWith(github.ref, 'refs/heads/release') }}
# This is for preview / internal deployment
if: ${{ github.ref == 'refs/heads/preview' || github.ref == 'refs/heads/internal' || startsWith(github.ref, 'refs/heads/release') }}
needs: [ "test", "build_frontend", "synth" ]
uses: ./.github/workflows/deploy.yml
with:
Expand All @@ -69,6 +72,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
ADHOC_KMS_KEY_ID: ${{ secrets.ADHOC_KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
APPLE_CREDENTIAL: ${{ secrets.APPLE_CREDENTIAL }}
APPLE_KEY_ID: ${{ secrets.APPLE_KEY_ID }}
Expand All @@ -83,6 +87,7 @@ jobs:
VOUCHER_JWT_SECRET: ${{ secrets.VOUCHER_JWT_SECRET }}
BRIDGE_DATA: ${{ secrets.BRIDGE_DATA }}
REFUND_SHEET_ID : ${{ secrets.REFUND_SHEET_ID }}
HEADLESS_GQL_JWT_SECRET: ${{ secrets.HEADLESS_GQL_JWT_SECRET }}

approval:
runs-on: ubuntu-latest
Expand All @@ -108,6 +113,7 @@ jobs:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
ADHOC_KMS_KEY_ID: ${{ secrets.ADHOC_KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
APPLE_CREDENTIAL: ${{ secrets.APPLE_CREDENTIAL }}
APPLE_KEY_ID: ${{ secrets.APPLE_KEY_ID }}
Expand All @@ -122,3 +128,4 @@ jobs:
VOUCHER_JWT_SECRET: ${{ secrets.VOUCHER_JWT_SECRET }}
BRIDGE_DATA: ${{ secrets.BRIDGE_DATA }}
REFUND_SHEET_ID : ${{ secrets.REFUND_SHEET_ID }}
HEADLESS_GQL_JWT_SECRET: ${{ secrets.HEADLESS_GQL_JWT_SECRET }}
7 changes: 7 additions & 0 deletions .github/workflows/synth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ on:
required: true
KMS_KEY_ID:
required: true
ADHOC_KMS_KEY_ID:
required: true
GOOGLE_CREDENTIAL:
required: true
APPLE_CREDENTIAL:
Expand Down Expand Up @@ -46,6 +48,8 @@ on:
required: true
REFUND_SHEET_ID:
required: true
HEADLESS_GQL_JWT_SECRET:
required: true

jobs:
synth:
Expand Down Expand Up @@ -120,6 +124,7 @@ jobs:
ODIN_GQL_URL: ${{ vars.ODIN_GQL_URL }}
HEIMDALL_GQL_URL: ${{ vars.HEIMDALL_GQL_URL }}
KMS_KEY_ID: ${{ secrets.KMS_KEY_ID }}
ADHOC_KMS_KEY_ID: ${{ secrets.ADHOC_KMS_KEY_ID }}
GOOGLE_CREDENTIAL: ${{ secrets.GOOGLE_CREDENTIAL }}
GOOGLE_PACKAGE_NAME: ${{ vars.GOOGLE_PACKAGE_NAME }}
APPLE_BUNDLE_ID: ${{ vars.APPLE_BUNDLE_ID }}
Expand All @@ -133,12 +138,14 @@ jobs:
GOLDEN_DUST_WORK_SHEET_ID: ${{ secrets.GOLDEN_DUST_WORK_SHEET_ID }}
FORM_SHEET: ${{ vars.FORM_SHEET }}
CDN_HOST: ${{ vars.CDN_HOST }}
CDN_HOST_K: ${{ vars.CDN_HOST_K }}
PLANET_URL: ${{ vars.PLANET_URL }}
SEASON_PASS_JWT_SECRET: ${{ secrets.SEASON_PASS_JWT_SECRET }}
VOUCHER_URL: ${{ secrets.VOUCHER_URL }}
VOUCHER_JWT_SECRET: ${{ secrets.VOUCHER_JWT_SECRET }}
BRIDGE_DATA: ${{ secrets.BRIDGE_DATA }}
REFUND_SHEET_ID : ${{ secrets.REFUND_SHEET_ID }}
HEADLESS_GQL_JWT_SECRET: ${{ secrets.HEADLESS_GQL_JWT_SECRET }}
run: |
source $VENV
yarn cdk synth
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ on:
required: true
SEASON_PASS_JWT_SECRET:
required: true
HEADLESS_GQL_JWT_SECRET:
required: true
SLACK_WEBHOOK_URL:
required: true

Expand Down Expand Up @@ -87,6 +89,7 @@ jobs:
APPLE_ISSUER_ID: ${{ secrets.APPLE_ISSUER_ID }}
APPLE_BUNDLE_ID: ${{ vars.APPLE_BUNDLE_ID }}
SEASON_PASS_JWT_SECRET: ${{ secrets.SEASON_PASS_JWT_SECRET }}
HEADLESS_GQL_JWT_SECRET: ${{ secrets.HEADLESS_GQL_JWT_SECRET }}
run: |
poetry run pytest tests
Expand Down
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
# CHANGELOG of NineChronicles.IAP

## 0.12.0 (2024-03-27)

### Feature

- Add AvatarLevel table and cache level data
- Add all product list API

### Enhancement

- Move all views into `/views` router
- Optimize Queries

### Bugfix

- Consume valid purchase to avoid unintended refund

## 0.5.2 (2023-11-08)

### Enhancement

- Change GQL scheme from `exceptionName` to `exceptionNames` to apply GQL scheme update


## 0.5.1 (2023-10-23)

### Bugfix
Expand Down
3 changes: 3 additions & 0 deletions common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ class Config:
account_id: str
region_name: str
cdn_host: str
cdn_host_k: str
odin_gql_url: str
heimdall_gql_url: str
headless_gql_jwt_secret: str

# Multiplanetary
planet_url: str
Expand All @@ -56,6 +58,7 @@ class Config:

headless: str = "http://localhost"
kms_key_id: Optional[str] = None
adhoc_kms_key_id: Optional[str] = None
golden_dust_request_sheet_id: Optional[str] = None
golden_dust_work_sheet_id: Optional[str] = None
form_sheet: Optional[str] = None
Expand Down
2 changes: 2 additions & 0 deletions common/_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def sign_tx(self, unsigned_tx: bytes) -> bytes:
return der_encode(seq)



# Deprecated
def derive_address(address: Union[str, bytes], key: Union[str, bytes], get_byte: bool = False) -> Union[bytes, str]:
"""
Derive given address using key.
Expand Down
24 changes: 19 additions & 5 deletions common/_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from typing import Union, Dict, Any, Tuple, Optional

import jwt
from gql import Client
from gql.dsl import DSLSchema, dsl_gql, DSLQuery, DSLMutation
from gql.transport.requests import RequestsHTTPTransport
Expand All @@ -12,16 +13,29 @@


class GQL:
def __init__(self, url: str = f"{os.environ.get('HEADLESS')}/graphql"):
def __init__(self, url: str, jwt_secret: str = None):
assert url is not None
self._url = url
self.__jwt_secret = jwt_secret
self.client = None
self.ds = None
transport = RequestsHTTPTransport(url=self._url, verify=True, retries=2)
transport = RequestsHTTPTransport(url=self._url, verify=True, retries=2, headers=self.__create_header())
self.client = Client(transport=transport, fetch_schema_from_transport=True)
with self.client as _:
assert self.client.schema is not None
self.ds = DSLSchema(self.client.schema)

def create_token(self) -> str:
iat = datetime.datetime.utcnow()
return jwt.encode({
"iat": iat,
"exp": iat + datetime.timedelta(minutes=1),
"iss": "planetariumhq.com"
}, self.__jwt_secret)

def __create_header(self):
return {"Authorization": f"Bearer {self.create_token()}"}

def execute(self, query: DocumentNode) -> Union[Dict[str, Any], ExecutionResult]:
with self.client as sess:
return sess.execute(query)
Expand Down Expand Up @@ -52,7 +66,7 @@ def get_next_nonce(self, address: str) -> int:
return resp["transaction"]["nextTxNonce"]

def _unload_from_garage(self, pubkey: bytes, nonce: int, **kwargs) -> bytes:
ts = kwargs.get("timestamp", (datetime.datetime.utcnow()+datetime.timedelta(days=1)).isoformat())
ts = kwargs.get("timestamp", (datetime.datetime.utcnow() + datetime.timedelta(days=1)).isoformat())
fav_data = kwargs.get("fav_data")
avatar_addr = kwargs.get("avatar_addr")
item_data = kwargs.get("item_data")
Expand Down Expand Up @@ -81,7 +95,7 @@ def _unload_from_garage(self, pubkey: bytes, nonce: int, **kwargs) -> bytes:
return bytes.fromhex(result["actionTxQuery"]["unloadFromMyGarages"])

def _claim_items(self, pubkey: bytes, nonce: int, **kwargs) -> bytes:
ts = kwargs.get("timestamp", (datetime.datetime.utcnow()+datetime.timedelta(days=1)).isoformat())
ts = kwargs.get("timestamp", (datetime.datetime.utcnow() + datetime.timedelta(days=1)).isoformat())
claim_data = kwargs.get("claim_data")
memo = kwargs.get("memo")

Expand All @@ -103,7 +117,7 @@ def _claim_items(self, pubkey: bytes, nonce: int, **kwargs) -> bytes:
return bytes.fromhex(result["actionTxQuery"]["unloadFromMyGarages"])

def _transfer_asset(self, pubkey: bytes, nonce: int, **kwargs) -> bytes:
ts = kwargs.get("timestamp", (datetime.datetime.utcnow()+datetime.timedelta(days=1)).isoformat())
ts = kwargs.get("timestamp", (datetime.datetime.utcnow() + datetime.timedelta(days=1)).isoformat())
sender = kwargs.get("sender")
recipient = kwargs.get("recipient")
currency = kwargs.get("currency")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Add package_name into Receipt table
Revision ID: 065b2b11e898
Revises: f6de778b7fe3
Create Date: 2024-04-25 11:54:30.925518
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '065b2b11e898'
down_revision = 'f6de778b7fe3'
branch_labels = None
depends_on = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('receipt', sa.Column('package_name', sa.Text(), nullable=False,
server_default='com.planetariumlabs.ninechroniclesmobile'))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('receipt', 'package_name')
# ### end Alembic commands ###
Loading

0 comments on commit be66911

Please sign in to comment.