mirror of
https://github.com/dadosfera/maestro.git
synced 2026-12-01 23:10:05 +00:00
Compare commits
54
Commits
@@ -1,73 +0,0 @@
|
|||||||
name: Deploy K8S Modifications
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
- beta
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
extract_environment:
|
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
outputs:
|
|
||||||
environment: ${{ steps.extract_environment.outputs.environment }}
|
|
||||||
steps:
|
|
||||||
- name: Extract Environment
|
|
||||||
run: |
|
|
||||||
if [ ${GITHUB_REF} == "refs/heads/main" ]; then
|
|
||||||
echo "environment=prd" >> $GITHUB_OUTPUT
|
|
||||||
elif [ ${GITHUB_REF} == "refs/heads/beta" ]; then
|
|
||||||
echo "environment=stg" >> $GITHUB_OUTPUT
|
|
||||||
fi
|
|
||||||
id: extract_environment
|
|
||||||
|
|
||||||
helmfile-deploy:
|
|
||||||
needs: [extract_environment]
|
|
||||||
runs-on: [self-hosted, "prd-azure"]
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up Helm
|
|
||||||
uses: azure/setup-helm@v1
|
|
||||||
with:
|
|
||||||
version: 'v3.9.0'
|
|
||||||
|
|
||||||
- name: Install Azure ClI
|
|
||||||
run: |
|
|
||||||
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
|
|
||||||
|
|
||||||
- uses: azure/login@v2
|
|
||||||
with:
|
|
||||||
creds: '{"clientId":"${{ secrets.ARM_CLIENT_ID }}","clientSecret":"${{ secrets.ARM_CLIENT_SECRET }}","subscriptionId":"${{ secrets.ARM_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.ARM_TENANT_ID }}"}'
|
|
||||||
|
|
||||||
- name: Set up Python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: '3.8'
|
|
||||||
|
|
||||||
- name: Install Helmfile
|
|
||||||
run: |
|
|
||||||
wget https://github.com/helmfile/helmfile/releases/download/v0.148.0/helmfile_0.148.0_linux_amd64.tar.gz
|
|
||||||
tar -xzf helmfile_0.148.0_linux_amd64.tar.gz
|
|
||||||
mv helmfile /usr/local/bin/
|
|
||||||
helmfile --version
|
|
||||||
|
|
||||||
- name: Install Helm Diff Plugin
|
|
||||||
run: helm plugin install https://github.com/databus23/helm-diff || true
|
|
||||||
|
|
||||||
- name: Setup kubectl
|
|
||||||
uses: azure/setup-kubectl@v1
|
|
||||||
with:
|
|
||||||
version: 'v1.30.1'
|
|
||||||
|
|
||||||
- name: Authenticate with cluster
|
|
||||||
env:
|
|
||||||
CLUSTER_NAME: platform-${{ needs.extract_environment.outputs.environment }}
|
|
||||||
run: az aks get-credentials --resource-group dadosfera-prd --name ${CLUSTER_NAME} --overwrite-existing
|
|
||||||
|
|
||||||
- name: Run Helmfile Apply
|
|
||||||
env:
|
|
||||||
ENV: ${{ needs.extract_environment.outputs.environment }}
|
|
||||||
run: helmfile -f helmfiles/${ENV}.yaml sync
|
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
<image src="./assets/maestro.svg" style="width:10rem">
|
<image src="./assets/maestro.svg" style="width:10rem">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
# Maestro
|
# Maestro
|
||||||
|
|
||||||
Maestro é a API principal da Dadosfera. É responsável pela comunicação do Frontend com nossos microsserviços.
|
Maestro é a API principal da Dadosfera. É responsável pela comunicação do Frontend com nossos microsserviços.
|
||||||
|
|||||||
+137
-176
@@ -5371,92 +5371,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/customers/{id}/theme": {
|
|
||||||
"post": {
|
|
||||||
"operationId": "CustomersController_saveCustomertheme",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"required": true,
|
|
||||||
"in": "path",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"requestBody": {
|
|
||||||
"required": true,
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/CustomerThemeRequest"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/CustomerThemeResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"201": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/CustomerThemeResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"Customers"
|
|
||||||
],
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"access-token": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"get": {
|
|
||||||
"operationId": "CustomersController_getCustomerTheme",
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "id",
|
|
||||||
"required": true,
|
|
||||||
"in": "path",
|
|
||||||
"schema": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/CustomerThemeResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"Customers"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/customers/token": {
|
"/customers/token": {
|
||||||
"get": {
|
"get": {
|
||||||
"operationId": "CustomersController_getCustomerToken",
|
"operationId": "CustomersController_getCustomerToken",
|
||||||
@@ -5517,20 +5431,6 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/health": {
|
|
||||||
"get": {
|
|
||||||
"operationId": "HealthController_check",
|
|
||||||
"parameters": [],
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"tags": [
|
|
||||||
"Health"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"/open-data/sharing-ocean-data": {
|
"/open-data/sharing-ocean-data": {
|
||||||
"post": {
|
"post": {
|
||||||
"operationId": "OpenDataController_createUser",
|
"operationId": "OpenDataController_createUser",
|
||||||
@@ -5546,6 +5446,37 @@
|
|||||||
],
|
],
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "language",
|
||||||
|
"required": true,
|
||||||
|
"in": "query",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"OpenData"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/customers/{id}/theme": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "ThemeController_saveCustomertheme",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"required": true,
|
||||||
|
"in": "path",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
@@ -5553,18 +5484,75 @@
|
|||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/CreateUserOpenDataDTO"
|
"$ref": "#/components/schemas/CustomerThemeRequest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/CustomerThemeResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Theme"
|
||||||
|
],
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"get": {
|
||||||
|
"operationId": "ThemeController_getCustomerTheme",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"required": true,
|
||||||
|
"in": "path",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/CustomerThemeResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Theme"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"/health": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "HealthController_check",
|
||||||
|
"parameters": [],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
"description": ""
|
"description": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tags": [
|
"tags": [
|
||||||
"OpenData"
|
"Health"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5631,6 +5619,9 @@
|
|||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"themeEnabled": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -5639,7 +5630,8 @@
|
|||||||
"name",
|
"name",
|
||||||
"tier",
|
"tier",
|
||||||
"scheduleLimit",
|
"scheduleLimit",
|
||||||
"links"
|
"links",
|
||||||
|
"themeEnabled"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"AuthUser": {
|
"AuthUser": {
|
||||||
@@ -8344,63 +8336,6 @@
|
|||||||
"links"
|
"links"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"CustomerThemeRequest": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"backgroundColor": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"textColor": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"logoWhite": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"logoBlack": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"backgroundColor",
|
|
||||||
"textColor",
|
|
||||||
"logoWhite",
|
|
||||||
"logoBlack"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"CustomerTheme": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"backgroundColor": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"textColor": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"logoWhite": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"logoBlack": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"backgroundColor",
|
|
||||||
"textColor",
|
|
||||||
"logoWhite",
|
|
||||||
"logoBlack"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"CustomerThemeResponse": {
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"theme": {
|
|
||||||
"$ref": "#/components/schemas/CustomerTheme"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"theme"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"CustomerLinkRequest": {
|
"CustomerLinkRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -8415,31 +8350,57 @@
|
|||||||
"links"
|
"links"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"CreateUserOpenDataDTO": {
|
"CustomerThemeRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"firstName": {
|
"displayName": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"lastName": {
|
"backgroundColor": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"email": {
|
"textColor": {
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"organization": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"enquiryType": {
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"firstName",
|
"displayName",
|
||||||
"lastName",
|
"backgroundColor",
|
||||||
"email",
|
"textColor"
|
||||||
"organization",
|
]
|
||||||
"enquiryType"
|
},
|
||||||
|
"CustomerTheme": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"backgroundColor": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"textColor": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"logo": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"logoLogin": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"backgroundColor",
|
||||||
|
"textColor",
|
||||||
|
"logo",
|
||||||
|
"logoLogin"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"CustomerThemeResponse": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"theme": {
|
||||||
|
"$ref": "#/components/schemas/CustomerTheme"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"theme"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-6
@@ -9,13 +9,14 @@ charts:
|
|||||||
- name: hostname
|
- name: hostname
|
||||||
value: maestro.stg.dadosfera.ai
|
value: maestro.stg.dadosfera.ai
|
||||||
- name: maestro.pi_factory_url
|
- name: maestro.pi_factory_url
|
||||||
value: pi-factory.stg.dadosfera.ai
|
value: pi-factory.dadosfera.ai
|
||||||
- name: maestro.in_factory_url
|
- name: maestro.in_factory_url
|
||||||
value: in-factory.stg.dadosfera.ai
|
value: in-factory.dadosfera.ai
|
||||||
- name: maestro.tr_factory_url
|
- name: maestro.tr_factory_url
|
||||||
value: in-factory.stg.dadosfera.ai
|
value: in-factory.dadosfera.ai
|
||||||
- name: maestro.open_customer_id
|
- name: maestro.open_customer_id
|
||||||
value: bb4e9b26-d465-40ff-9345-e768ca69a55e
|
value: b3e3dfe5-b992-4586-a73c-c0b0c00f615d
|
||||||
- name: maestro.open_group_id
|
- name: maestro.open_group_id
|
||||||
value: 4d621501-5ea4-444b-b46e-1a009f3132ff
|
value: e3f98a2f-7748-4981-8505-7695c8ca8218
|
||||||
|
- name: replicaCount
|
||||||
|
value: 1
|
||||||
@@ -36,6 +36,11 @@ spec:
|
|||||||
operator: In
|
operator: In
|
||||||
values:
|
values:
|
||||||
- backend
|
- backend
|
||||||
|
tolerations:
|
||||||
|
- key: "kubernetes.azure.com/scalesetpriority"
|
||||||
|
operator: "Equal"
|
||||||
|
value: "spot"
|
||||||
|
effect: "NoSchedule"
|
||||||
|
|
||||||
containers:
|
containers:
|
||||||
- name: maestro
|
- name: maestro
|
||||||
@@ -90,6 +95,10 @@ spec:
|
|||||||
value: {{ .Values.maestro.tr_factory_url }}
|
value: {{ .Values.maestro.tr_factory_url }}
|
||||||
- name: UPLOAD_FILE_AGENT_CONNECTION
|
- name: UPLOAD_FILE_AGENT_CONNECTION
|
||||||
value: {{ .Values.maestro.upload_file_agent_connection }}
|
value: {{ .Values.maestro.upload_file_agent_connection }}
|
||||||
|
- name: OPEN_CUSTOMER_ID
|
||||||
|
value: {{ .Values.maestro.open_customer_id }}
|
||||||
|
- name: OPEN_GROUP_ID
|
||||||
|
value: {{ .Values.maestro.open_group_id }}
|
||||||
- name: JWT_PRIVATE_KEY
|
- name: JWT_PRIVATE_KEY
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
|
|||||||
Generated
+9
-8
@@ -12,7 +12,7 @@
|
|||||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack": "2.5.3",
|
"@dadosfera/protospack": "2.5.3",
|
||||||
"@dadosfera/protospack-v2": "3.37.0-beta.1",
|
"@dadosfera/protospack-v2": "3.37.0-beta.5",
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
"@types/jest": "27.0.2",
|
"@types/jest": "27.0.2",
|
||||||
"@types/jsonwebtoken": "^8.5.9",
|
"@types/jsonwebtoken": "^8.5.9",
|
||||||
"@types/jwk-to-pem": "^2.0.1",
|
"@types/jwk-to-pem": "^2.0.1",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/multer": "^1.4.12",
|
||||||
"@types/node": "^16.18.52",
|
"@types/node": "^16.18.52",
|
||||||
"@types/passport-facebook": "^2.1.11",
|
"@types/passport-facebook": "^2.1.11",
|
||||||
"@types/passport-google-oauth20": "^2.0.11",
|
"@types/passport-google-oauth20": "^2.0.11",
|
||||||
@@ -1403,9 +1403,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@dadosfera/protospack-v2": {
|
"node_modules/@dadosfera/protospack-v2": {
|
||||||
"version": "3.37.0-beta.1",
|
"version": "3.37.0-beta.5",
|
||||||
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.37.0-beta.1.tgz",
|
"resolved": "https://dadosfera-611330257153.d.codeartifact.us-east-1.amazonaws.com/npm/dadosfera-npm/@dadosfera/protospack-v2/-/protospack-v2-3.37.0-beta.5.tgz",
|
||||||
"integrity": "sha512-AcDxeg7KruBJncOXbLJFHKH/5GQ9VHR8MxU7s1o1lrZVfZY4Ht3UWmvwL1F2b+6DIhTDqzVOsKjfg7KAbuDYuw==",
|
"integrity": "sha512-dtHMzMU2Qa9c6DpygWr7fib19l1zqbYgBi2wGkiJ6uMAvl1CGu9V0p+JA1FwGTQ0QRy7EkkRVi6X6sH5u/ICpA==",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
@@ -3527,10 +3527,11 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/multer": {
|
"node_modules/@types/multer": {
|
||||||
"version": "1.4.11",
|
"version": "1.4.12",
|
||||||
"resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.11.tgz",
|
"resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.12.tgz",
|
||||||
"integrity": "sha512-svK240gr6LVWvv3YGyhLlA+6LRRWA4mnGIU7RcNmgjBYFl6665wcXrRfxGp5tEPVHUNm5FMcmq7too9bxCwX/w==",
|
"integrity": "sha512-pQ2hoqvXiJt2FP9WQVLPRO+AmiIm/ZYkavPlIQnx282u4ZrVdztx0pkh3jjpQt0Kz+YI0YhSG264y08UJKoUQg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/express": "*"
|
"@types/express": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -30,7 +30,7 @@
|
|||||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack": "2.5.3",
|
"@dadosfera/protospack": "2.5.3",
|
||||||
"@dadosfera/protospack-v2": "3.37.0-beta.1",
|
"@dadosfera/protospack-v2": "3.37.0-beta.5",
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
"@types/jest": "27.0.2",
|
"@types/jest": "27.0.2",
|
||||||
"@types/jsonwebtoken": "^8.5.9",
|
"@types/jsonwebtoken": "^8.5.9",
|
||||||
"@types/jwk-to-pem": "^2.0.1",
|
"@types/jwk-to-pem": "^2.0.1",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/multer": "^1.4.12",
|
||||||
"@types/node": "^16.18.52",
|
"@types/node": "^16.18.52",
|
||||||
"@types/passport-facebook": "^2.1.11",
|
"@types/passport-facebook": "^2.1.11",
|
||||||
"@types/passport-google-oauth20": "^2.0.11",
|
"@types/passport-google-oauth20": "^2.0.11",
|
||||||
|
|||||||
+4
-2
@@ -27,6 +27,7 @@ import { ProductboardModule } from './modules/productboard/productboard.module';
|
|||||||
import { MixpanelModule } from './modules/mixpanel/mixpanel.module';
|
import { MixpanelModule } from './modules/mixpanel/mixpanel.module';
|
||||||
import { CustomersModule } from './modules/customers/customers.module';
|
import { CustomersModule } from './modules/customers/customers.module';
|
||||||
import { OpenDataModule } from './modules/open-data/open-data.module';
|
import { OpenDataModule } from './modules/open-data/open-data.module';
|
||||||
|
import { ThemeModule } from './modules/theme/theme.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
@@ -58,9 +59,10 @@ import { OpenDataModule } from './modules/open-data/open-data.module';
|
|||||||
ProductboardModule,
|
ProductboardModule,
|
||||||
MixpanelModule,
|
MixpanelModule,
|
||||||
CustomersModule,
|
CustomersModule,
|
||||||
//Always leave HealthModule last, so it is on the bottom of swagger
|
|
||||||
HealthModule,
|
|
||||||
OpenDataModule,
|
OpenDataModule,
|
||||||
|
ThemeModule,
|
||||||
|
//Always leave HealthModule last, so it is on the bottom of swagger
|
||||||
|
HealthModule
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import { Injectable, CanActivate, ExecutionContext, ForbiddenException } from '@nestjs/common';
|
|
||||||
import { Reflector } from '@nestjs/core';
|
|
||||||
import { SetMetadata } from '@nestjs/common';
|
|
||||||
|
|
||||||
export const SetOrigin = (origin: string) => SetMetadata('allowedOrigin', origin);
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class CORSGuard implements CanActivate {
|
|
||||||
constructor(private reflector: Reflector) {}
|
|
||||||
|
|
||||||
canActivate(context: ExecutionContext): boolean {
|
|
||||||
const response = context.switchToHttp().getResponse();
|
|
||||||
const request = context.switchToHttp().getRequest();
|
|
||||||
const origin = request.headers.origin;
|
|
||||||
|
|
||||||
// Obter a origem permitida através do decorador
|
|
||||||
const allowedOrigin = this.reflector.get<string>('allowedOrigin', context.getHandler());
|
|
||||||
if (process.env.ENV === "local") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verifica se a origem da requisição é permitida
|
|
||||||
if (allowedOrigin && origin !== allowedOrigin) {
|
|
||||||
throw new ForbiddenException('Acesso não permitido pela política CORS');
|
|
||||||
}
|
|
||||||
|
|
||||||
response.setHeader('Access-Control-Allow-Origin', allowedOrigin);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -77,6 +77,8 @@ export class AuthCustomer {
|
|||||||
scheduleLimit: string;
|
scheduleLimit: string;
|
||||||
@ApiProperty()
|
@ApiProperty()
|
||||||
links: Link[];
|
links: Link[];
|
||||||
|
@ApiProperty()
|
||||||
|
themeEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AuthSignInReq implements AuthSignInRequest {
|
export class AuthSignInReq implements AuthSignInRequest {
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { IdResponse } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Get,
|
Get,
|
||||||
HttpCode,
|
HttpCode,
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Inject,
|
Inject,
|
||||||
Param,
|
Param,
|
||||||
Post,
|
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
UseFilters,
|
UseFilters,
|
||||||
@@ -22,11 +19,10 @@ import {
|
|||||||
} from 'src/decorators/authentication.decorator';
|
} from 'src/decorators/authentication.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
import { CustomersService } from './customers.service';
|
import { CustomersService } from './customers.service';
|
||||||
import { CustomerLinkRequest, CustomerLinksResponse, CustomerThemeRequest, CustomerThemeResponse } from './dtos/customers';
|
import { CustomerLinkRequest, CustomerLinksResponse } from './dtos/customers';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
import type { StringValue } from 'ms';
|
import type { StringValue } from 'ms';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import ErrorCodes from 'src/utils/errorCodes';
|
|
||||||
|
|
||||||
@ApiTags('Customers')
|
@ApiTags('Customers')
|
||||||
@Controller('customers')
|
@Controller('customers')
|
||||||
@@ -51,51 +47,6 @@ export class CustomersController {
|
|||||||
return { links };
|
return { links };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post(':id/theme')
|
|
||||||
@Authenticated()
|
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
|
||||||
@ApiOkResponse({ type: CustomerThemeResponse })
|
|
||||||
async saveCustomertheme(@Param('id') id: string, @Body() data: CustomerThemeRequest) {
|
|
||||||
this.logger.info('saveCustomertheme', JSON.stringify({
|
|
||||||
id, theme: data
|
|
||||||
}));
|
|
||||||
|
|
||||||
try {
|
|
||||||
// const theme = await this.customersService.createThemeByCustomer(id, data);
|
|
||||||
this.logger.info('saveCustomertheme', JSON.stringify(data));
|
|
||||||
return { theme: null };
|
|
||||||
} catch (err) {
|
|
||||||
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
|
||||||
this.logger.error('Error - saveCustomertheme - Expect CUSTOMER.NOT_FOUND');
|
|
||||||
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
|
|
||||||
} else {
|
|
||||||
this.logger.error('Error - saveCustomertheme Unknown Error:' + err?.message);
|
|
||||||
return { theme: null };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Get(':id/theme')
|
|
||||||
@ApiOkResponse({ type: CustomerThemeResponse })
|
|
||||||
async getCustomerTheme(@Param('id') id: string) {
|
|
||||||
this.logger.info('getCustomerTheme with id' + id);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const data = await this.customersService.getThemeByCustomer(id);
|
|
||||||
this.logger.info('Success - getCustomerTheme with id'+ id);
|
|
||||||
return data;
|
|
||||||
}catch (err) {
|
|
||||||
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
|
||||||
this.logger.error('Error - getCustomerTheme - Expect CUSTOMER.NOT_FOUND');
|
|
||||||
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
|
|
||||||
} else {
|
|
||||||
this.logger.error('Error - getCustomerTheme Unknown Error:' + err?.message);
|
|
||||||
return { theme: null };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Put(':id/links')
|
@Put(':id/links')
|
||||||
@Authenticated()
|
@Authenticated()
|
||||||
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import {
|
|||||||
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
} from '@dadosfera/protospack-v2/dist/lib/PipelineV2';
|
||||||
import { Metadata } from '@grpc/grpc-js';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
import { PipelinesClientConfiguration } from '../pipelinesV2/pipelines-client';
|
import { PipelinesClientConfiguration } from '../pipelinesV2/pipelines-client';
|
||||||
import { CustomerThemeRequest, CustomerThemeResponse } from './dtos/customers';
|
|
||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
|
|
||||||
// This function will accept any string, which may result in a bug.
|
// This function will accept any string, which may result in a bug.
|
||||||
@@ -90,39 +89,6 @@ export class CustomersService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createThemeByCustomer(id: string, theme: CustomerThemeRequest): Promise<CustomerThemeResponse> {
|
|
||||||
if (!id) {
|
|
||||||
this.logger.error('Error - saveCustomertheme - not found id:' + id);
|
|
||||||
throw new HttpException(null, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await firstValueFrom(
|
|
||||||
this.customerService.CustomerCreateTheme({
|
|
||||||
customerId: id,
|
|
||||||
theme
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
return { theme: result };
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async getThemeByCustomer(id: string): Promise<CustomerThemeResponse> {
|
|
||||||
if (!id) {
|
|
||||||
this.logger.error('Error - getCustomerTheme - not found id:' + id);
|
|
||||||
throw new HttpException(null, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await firstValueFrom(
|
|
||||||
this.customerService.CustomerGetTheme({
|
|
||||||
id
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
theme: result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async generateToken(
|
async generateToken(
|
||||||
expiresIn = '30m',
|
expiresIn = '30m',
|
||||||
data: { customerId: string; userId: string; customerName: string },
|
data: { customerId: string; userId: string; customerName: string },
|
||||||
@@ -179,7 +145,7 @@ export class CustomersService implements OnModuleInit {
|
|||||||
const res = await lastValueFrom(
|
const res = await lastValueFrom(
|
||||||
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||||
{
|
{
|
||||||
dashboard_id: '45',
|
dashboard_id: '98',
|
||||||
exp: '15m',
|
exp: '15m',
|
||||||
metabase_customer_name: 'dadosferatech',
|
metabase_customer_name: 'dadosferatech',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Link, Theme } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
import { Link } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
|
||||||
export class CustomerLink implements Link {
|
export class CustomerLink implements Link {
|
||||||
@@ -21,29 +21,3 @@ export class CustomerLinksResponse {
|
|||||||
links: CustomerLink[];
|
links: CustomerLink[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CustomerTheme implements Theme {
|
|
||||||
@ApiProperty()
|
|
||||||
backgroundColor: string;
|
|
||||||
@ApiProperty()
|
|
||||||
textColor: string;
|
|
||||||
@ApiProperty()
|
|
||||||
logoWhite: string;
|
|
||||||
@ApiProperty()
|
|
||||||
logoBlack: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CustomerThemeResponse {
|
|
||||||
@ApiProperty()
|
|
||||||
theme: CustomerTheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CustomerThemeRequest {
|
|
||||||
@ApiProperty()
|
|
||||||
backgroundColor: string;
|
|
||||||
@ApiProperty()
|
|
||||||
textColor: string;
|
|
||||||
@ApiProperty()
|
|
||||||
logoWhite: string;
|
|
||||||
@ApiProperty()
|
|
||||||
logoBlack: string;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ export class DucClient {
|
|||||||
objects: true,
|
objects: true,
|
||||||
arrays: true,
|
arrays: true,
|
||||||
},
|
},
|
||||||
|
maxSendMessageLength: 15 * 1024 * 1024, // 15 MB por mensagem
|
||||||
|
maxReceiveMessageLength: 15 * 1024 * 1024,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
import { Body, Controller, Inject, Post, UseFilters, UseGuards } from '@nestjs/common';
|
import { Body, Controller, ForbiddenException, Header, HttpCode, Inject, Param, Post, Query, Req, UseFilters, UseGuards, UseInterceptors } from '@nestjs/common';
|
||||||
import { ApiCreatedResponse, ApiHeaders, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
import { ApiCreatedResponse, ApiHeaders, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||||
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
import { ApiInternalOnlyController } from 'src/decorators/swagger.decorator';
|
||||||
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
@@ -8,7 +8,10 @@ import { UsersService } from '../users/users.service';
|
|||||||
import { Language } from 'src/decorators/language.decorator';
|
import { Language } from 'src/decorators/language.decorator';
|
||||||
import { OpenDataService } from './open-data.service';
|
import { OpenDataService } from './open-data.service';
|
||||||
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
import { CreateUserOpenDataDTO, WordpressForm } from './dto/wordpres-form';
|
||||||
import { CORSGuard, SetOrigin } from 'src/decorators/set-origin.decorator';
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
|
import { request } from 'http';
|
||||||
|
import { Request } from 'express';
|
||||||
|
|
||||||
@Controller('open-data')
|
@Controller('open-data')
|
||||||
@ApiInternalOnlyController()
|
@ApiInternalOnlyController()
|
||||||
@@ -27,22 +30,30 @@ export class OpenDataController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post("/sharing-ocean-data")
|
@Post("/sharing-ocean-data")
|
||||||
@SetOrigin('https://devsbm.dadosfera.io/')
|
@HttpCode(200)
|
||||||
@UseGuards(CORSGuard)
|
@Header('content-type', 'application/json')
|
||||||
@ApiOkResponse()
|
@ApiOkResponse()
|
||||||
async createUser(
|
async createUser(
|
||||||
@Body()
|
@Body()
|
||||||
body: WordpressForm
|
body: WordpressForm,
|
||||||
|
@Query('language')
|
||||||
|
language: string,
|
||||||
|
@Req()
|
||||||
|
request: Request,
|
||||||
) {
|
) {
|
||||||
this.logger.info('createUser for open data' + JSON.stringify({ body }));
|
if (!request.headers['user-agent'].includes('WordPress/6.7.1; https://devsbm.dadosfera.io')) {
|
||||||
|
throw new ForbiddenException();
|
||||||
|
}
|
||||||
|
this.logger.info('createUser for open data');
|
||||||
|
|
||||||
// "401573bb-334f-44b2-b30e-88d4cea31ae9"
|
this.logger.info('user-agent', request.headers['user-agent']);
|
||||||
// const OPENDATA_PUBLIC_USERS_GROUP_ID = process.env.OPEN_GROUP_ID;
|
|
||||||
// ""f239718a-a271-4ef9-ae7e-02a2f0f3aa6e""
|
|
||||||
// const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
|
|
||||||
const OPENDATA_CUSTOMER_ID = "bb4e9b26-d465-40ff-9345-e768ca69a55e";
|
|
||||||
|
|
||||||
const roles = ["4d621501-5ea4-444b-b46e-1a009f3132ff"];
|
const OPENDATA_CUSTOMER_ID = process.env.OPEN_CUSTOMER_ID;
|
||||||
|
const OPENDATA_GROUP_ID = process.env.OPEN_GROUP_ID;
|
||||||
|
const roles = [process.env.OPEN_GROUP_ID];
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
language: language || 'en-us'
|
||||||
|
});
|
||||||
|
|
||||||
const data = {}
|
const data = {}
|
||||||
|
|
||||||
@@ -52,12 +63,11 @@ export class OpenDataController {
|
|||||||
.forEach(key => {
|
.forEach(key => {
|
||||||
const field = body.fields[key]
|
const field = body.fields[key]
|
||||||
data[field.id] = field.value
|
data[field.id] = field.value
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('user data' + e.message);
|
this.logger.error('user data ' + e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const user: CreateUserOpenDataDTO = {
|
const user: CreateUserOpenDataDTO = {
|
||||||
email: data["email"],
|
email: data["email"],
|
||||||
enquiryType: data["enquiry_type"],
|
enquiryType: data["enquiry_type"],
|
||||||
@@ -65,16 +75,24 @@ export class OpenDataController {
|
|||||||
lastName: data["last_name"],
|
lastName: data["last_name"],
|
||||||
organization: data["organization"]
|
organization: data["organization"]
|
||||||
}
|
}
|
||||||
this.logger.info('user request' + JSON.stringify({ user, roles, customer: OPENDATA_CUSTOMER_ID }));
|
this.logger.info(`user request to group ${OPENDATA_CUSTOMER_ID} with role ${OPENDATA_GROUP_ID}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles);
|
const id = await this.openDataService.createUser(OPENDATA_CUSTOMER_ID, user, roles, metadata);
|
||||||
this.logger.info('user created with sucessfull data' + JSON.stringify(response));
|
this.logger.info('user created with id: '+ id);
|
||||||
return "success"
|
return {
|
||||||
|
success: true,
|
||||||
|
status: 'success',
|
||||||
|
message: 'user created with succesfull'
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error('user data' + e.message);
|
this.logger.error('failed with exception: ' + e.message);
|
||||||
return e;
|
return {
|
||||||
|
success: false,
|
||||||
|
status: 'failed',
|
||||||
|
message: e.message
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { UsersProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfa
|
|||||||
import { DucClient } from '../duc/client.config';
|
import { DucClient } from '../duc/client.config';
|
||||||
import { ClientGrpc } from '@nestjs/microservices';
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OpenDataService implements OnModuleInit {
|
export class OpenDataService implements OnModuleInit {
|
||||||
@@ -28,7 +29,7 @@ export class OpenDataService implements OnModuleInit {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async createUser(customerId: string, data: CreateUserOpenDataDTO, roleIds: string[]) {
|
async createUser(customerId: string, data: CreateUserOpenDataDTO, roleIds: string[], metadata: Metadata) {
|
||||||
const body = {
|
const body = {
|
||||||
email: data.email,
|
email: data.email,
|
||||||
name: data.firstName + " " + data.lastName,
|
name: data.firstName + " " + data.lastName,
|
||||||
@@ -39,10 +40,10 @@ export class OpenDataService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await lastValueFrom(
|
const { user } = await lastValueFrom(
|
||||||
this.usersClientService.SimpleUserCreate(body),
|
this.usersClientService.SimpleUserCreate(body, metadata),
|
||||||
);
|
);
|
||||||
return "User created";
|
return user.id;
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ export class PipelinesService implements OnModuleInit {
|
|||||||
const res = await lastValueFrom(
|
const res = await lastValueFrom(
|
||||||
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
this.pipelineReadService.PipelineV2GetDashboardUrl(
|
||||||
{
|
{
|
||||||
dashboard_id: '83',
|
dashboard_id: '95',
|
||||||
exp: '15m',
|
exp: '15m',
|
||||||
metabase_customer_name: 'dadosferatech',
|
metabase_customer_name: 'dadosferatech',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { Link, Theme } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
||||||
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
|
||||||
|
export class CustomerLink implements Link {
|
||||||
|
@ApiProperty()
|
||||||
|
href: string;
|
||||||
|
@ApiProperty()
|
||||||
|
name: string;
|
||||||
|
@ApiProperty()
|
||||||
|
description: string;
|
||||||
|
@ApiPropertyOptional()
|
||||||
|
iconSrc: string;
|
||||||
|
}
|
||||||
|
export class CustomerLinkRequest {
|
||||||
|
@ApiProperty({ type: [CustomerLink] })
|
||||||
|
links: CustomerLink[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomerLinksResponse {
|
||||||
|
@ApiProperty({ type: [CustomerLink] })
|
||||||
|
links: CustomerLink[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomerTheme implements Theme {
|
||||||
|
@ApiProperty()
|
||||||
|
backgroundColor: string;
|
||||||
|
@ApiProperty()
|
||||||
|
textColor: string;
|
||||||
|
@ApiProperty()
|
||||||
|
logo: string;
|
||||||
|
@ApiProperty()
|
||||||
|
logoLogin: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomerThemeResponse {
|
||||||
|
@ApiProperty()
|
||||||
|
theme: CustomerTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CustomerThemeRequest {
|
||||||
|
@ApiProperty()
|
||||||
|
displayName: string;
|
||||||
|
@ApiProperty()
|
||||||
|
backgroundColor: string;
|
||||||
|
@ApiProperty()
|
||||||
|
textColor: string;
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
Inject,
|
||||||
|
Param,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Query,
|
||||||
|
UploadedFiles,
|
||||||
|
UseFilters,
|
||||||
|
UseInterceptors,
|
||||||
|
HttpCode
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { PERMISSIONS_GROUPS } from 'src/authentication/permissions.enum';
|
||||||
|
import {
|
||||||
|
Authenticated,
|
||||||
|
RequireAllPermissions,
|
||||||
|
} from 'src/decorators/authentication.decorator';
|
||||||
|
import { GrpcToHttpExceptionFilter } from 'src/error/grpc-to-http-exception.filter';
|
||||||
|
import { CustomerThemeRequest, CustomerThemeResponse } from './dtos/customers';
|
||||||
|
|
||||||
|
import ErrorCodes from 'src/utils/errorCodes';
|
||||||
|
import { AnyFilesInterceptor } from '@nestjs/platform-express';
|
||||||
|
import { ThemeService } from './theme.service';
|
||||||
|
|
||||||
|
@ApiTags('Theme')
|
||||||
|
@Controller('customers')
|
||||||
|
@UseFilters(GrpcToHttpExceptionFilter)
|
||||||
|
export class ThemeController {
|
||||||
|
logger: DadosferaLogger;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@Inject(DadosferaLogger)
|
||||||
|
dadosferaLogger: DadosferaLogger,
|
||||||
|
private themeService: ThemeService,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Post('/:id/theme')
|
||||||
|
@Authenticated()
|
||||||
|
@RequireAllPermissions(PERMISSIONS_GROUPS.USERS.permissions.ADMIN)
|
||||||
|
@ApiOkResponse({ type: CustomerThemeResponse })
|
||||||
|
@UseInterceptors(AnyFilesInterceptor())
|
||||||
|
@HttpCode(HttpStatus.OK)
|
||||||
|
async saveCustomertheme(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() data: CustomerThemeRequest,
|
||||||
|
@UploadedFiles() files: Array<Express.Multer.File>
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.logger.info('saveCustomertheme' + JSON.stringify({
|
||||||
|
id,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const logo = files.find(file => file.fieldname === 'logo');
|
||||||
|
const logoLogin = files.find(file => file.fieldname === 'logoLogin');
|
||||||
|
|
||||||
|
this.validFileSize(logo);
|
||||||
|
this.validFileSize(logoLogin);
|
||||||
|
this.validMimeType(logo);
|
||||||
|
this.validMimeType(logoLogin);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const theme = await this.themeService.createThemeByCustomer(id, {
|
||||||
|
...data,
|
||||||
|
logo,
|
||||||
|
logoLogin
|
||||||
|
});
|
||||||
|
this.logger.info('saveCustomertheme' + JSON.stringify(theme));
|
||||||
|
return theme;
|
||||||
|
} catch (err) {
|
||||||
|
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
||||||
|
this.logger.error('Error - saveCustomertheme - Expect CUSTOMER.NOT_FOUND');
|
||||||
|
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
|
||||||
|
} else {
|
||||||
|
this.logger.error('Error - saveCustomertheme Unknown Error:' + err?.message);
|
||||||
|
return { theme: null };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private validFileSize(file: Express.Multer.File) {
|
||||||
|
const maxFileSize = 10 * 1024 * 1024; // 10MB
|
||||||
|
|
||||||
|
if (file && file.size > maxFileSize) {
|
||||||
|
throw new HttpException(`O Arquivo ${file.filename} possui mais de 10MB`, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private validMimeType(file: Express.Multer.File) {
|
||||||
|
const mimeTypesValid = ['image/jpeg', 'image/jpg', 'image/png'];
|
||||||
|
|
||||||
|
if (file && !mimeTypesValid.includes(file.mimetype)) {
|
||||||
|
throw new HttpException(`O Arquivo ${file.fieldname} deve ser jpeg, jpg, ou png`, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get('/:id/theme')
|
||||||
|
@ApiOkResponse({ type: CustomerThemeResponse })
|
||||||
|
async getCustomerTheme(@Param('id') id: string) {
|
||||||
|
this.logger.info('getCustomerTheme with id' + id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.themeService.getThemeByCustomer(id);
|
||||||
|
this.logger.info('Success - getCustomerTheme'+ JSON.stringify(data));
|
||||||
|
if (data?.theme) return data;
|
||||||
|
|
||||||
|
return { theme: null };
|
||||||
|
}catch (err) {
|
||||||
|
if (err.details === ErrorCodes.CUSTOMER.NOT_FOUND) {
|
||||||
|
this.logger.error('Error - getCustomerTheme - Expect CUSTOMER.NOT_FOUND');
|
||||||
|
throw new HttpException(err.details, HttpStatus.NOT_FOUND);
|
||||||
|
} else {
|
||||||
|
this.logger.error('Error - getCustomerTheme Unknown Error:' + err?.message);
|
||||||
|
return { theme: null };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
|
import { ClientsModule } from '@nestjs/microservices';
|
||||||
|
import { ThemeController } from './theme.controller';
|
||||||
|
import { ThemeService } from './theme.service';
|
||||||
|
import { DucClient } from '../duc/client.config';
|
||||||
|
|
||||||
|
const ducClient = new DucClient();
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
ClientsModule.register([
|
||||||
|
ducClient.providerOptions,
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
controllers: [ThemeController],
|
||||||
|
providers: [ThemeService, DadosferaLogger],
|
||||||
|
exports: [ThemeService],
|
||||||
|
})
|
||||||
|
export class ThemeModule {}
|
||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import {
|
||||||
|
OnModuleInit,
|
||||||
|
Inject,
|
||||||
|
Injectable,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
InternalServerErrorException,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
|
import { firstValueFrom, lastValueFrom, ReplaySubject } from 'rxjs';
|
||||||
|
import { Link } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/entities';
|
||||||
|
import { DucClient } from '../duc/client.config';
|
||||||
|
import { ClientGrpc } from '@nestjs/microservices';
|
||||||
|
import { ProtoServices } from '@dadosfera/protospack-v2/dist/lib/Duc';
|
||||||
|
import { CustomerUpdateRequest } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
|
import { ThemeProtoService } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/write-service';
|
||||||
|
import { ThemeRequest } from '@dadosfera/protospack-v2/dist/lib/Duc/interfaces/messages';
|
||||||
|
import { CustomerThemeRequest, CustomerThemeResponse } from './dtos/customers';
|
||||||
|
import DadosferaLogger from '@dadosfera/dadosfera-logs';
|
||||||
|
import { resolve } from 'path';
|
||||||
|
import { Readable } from 'stream';
|
||||||
|
|
||||||
|
type Files = {
|
||||||
|
logo: Express.Multer.File,
|
||||||
|
logoLogin: Express.Multer.File,
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ThemeService implements OnModuleInit {
|
||||||
|
private themeService: ThemeProtoService;
|
||||||
|
private logger: DadosferaLogger;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
@Inject(DucClient.name) private readonly grpcClient: ClientGrpc,
|
||||||
|
@Inject(DadosferaLogger)
|
||||||
|
dadosferaLogger: DadosferaLogger,
|
||||||
|
) {
|
||||||
|
this.logger = dadosferaLogger.logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
onModuleInit() {
|
||||||
|
this.themeService = this.grpcClient.getService<ThemeProtoService>(
|
||||||
|
ProtoServices.ThemeProtoService,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async createThemeByCustomer(id: string, theme: CustomerThemeRequest & Files) {
|
||||||
|
if (!id) {
|
||||||
|
this.logger.error('Error - saveCustomertheme - not found id:' + id);
|
||||||
|
throw new HttpException(null, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
const customerThemeRequest$ = new ReplaySubject<ThemeRequest>();
|
||||||
|
|
||||||
|
customerThemeRequest$.next({
|
||||||
|
customerId: id,
|
||||||
|
displayName: theme.displayName,
|
||||||
|
backgroundColor: theme.backgroundColor,
|
||||||
|
textColor: theme.textColor,
|
||||||
|
isMetadata: true,
|
||||||
|
filename: '',
|
||||||
|
chunk: Buffer.alloc(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
if(theme.logo) {
|
||||||
|
await this.sendFile(theme.logo, customerThemeRequest$);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(theme.logoLogin) {
|
||||||
|
await this.sendFile(theme.logoLogin, customerThemeRequest$);
|
||||||
|
}
|
||||||
|
customerThemeRequest$.complete();
|
||||||
|
|
||||||
|
const stream = this.themeService.CustomerCreateTheme(customerThemeRequest$);
|
||||||
|
|
||||||
|
return lastValueFrom(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getThemeByCustomer(id: string): Promise<CustomerThemeResponse> {
|
||||||
|
if (!id) {
|
||||||
|
this.logger.error('Error - getCustomerTheme - not found id:' + id);
|
||||||
|
throw new HttpException(null, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { theme } = await firstValueFrom(
|
||||||
|
this.themeService.CustomerGetTheme({
|
||||||
|
id
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async sendFile(file: Express.Multer.File, stream$: ReplaySubject<ThemeRequest>) {
|
||||||
|
const chunkSize = 4 * 1024 * 1024;
|
||||||
|
const bufferStream = new CustomBufferStream(file.buffer, chunkSize);
|
||||||
|
const parseMimitypeForExtension = {
|
||||||
|
'image/jpeg': '.jpeg',
|
||||||
|
'image/jpg': '.jpg',
|
||||||
|
'image/png': '.png',
|
||||||
|
'image/svg+xml': '.svg',
|
||||||
|
}
|
||||||
|
|
||||||
|
const extension = parseMimitypeForExtension[file.mimetype];
|
||||||
|
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
bufferStream.on('data', (chunk) => {
|
||||||
|
const filename = file.fieldname.concat(extension);
|
||||||
|
stream$.next({
|
||||||
|
customerId: '',
|
||||||
|
displayName: '',
|
||||||
|
backgroundColor: '',
|
||||||
|
textColor: '',
|
||||||
|
isMetadata: false,
|
||||||
|
filename: filename,
|
||||||
|
chunk: chunk
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
bufferStream.on('end', () => {
|
||||||
|
resolve(file.filename)
|
||||||
|
});
|
||||||
|
|
||||||
|
bufferStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomBufferStream extends Readable {
|
||||||
|
buffer: Buffer;
|
||||||
|
offset: number;
|
||||||
|
chunkSize: number;
|
||||||
|
|
||||||
|
constructor(buffer: Buffer, chunkSize: number) {
|
||||||
|
super({ highWaterMark: chunkSize }); // Configura o tamanho do chunk
|
||||||
|
this.buffer = buffer;
|
||||||
|
this.offset = 0;
|
||||||
|
this.chunkSize = chunkSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
_read() {
|
||||||
|
if (this.offset < this.buffer.length) {
|
||||||
|
const end = Math.min(this.offset + this.chunkSize, this.buffer.length);
|
||||||
|
|
||||||
|
const copiedBuf = Uint8Array.prototype.slice.call(this.buffer);
|
||||||
|
const chunk = copiedBuf.slice(this.offset, end);
|
||||||
|
this.offset = end;
|
||||||
|
this.push(chunk);
|
||||||
|
} else {
|
||||||
|
this.push(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user