Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(apps): Set app tokens #179

Merged
merged 21 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ jobs:
ECOM_AUTHENTICATION_ID: ${{ secrets.ECOM_AUTHENTICATION_ID }}
ECOM_API_KEY: ${{ secrets.ECOM_API_KEY }}
MERCADOPAGO_TOKEN: ${{ secrets.MERCADOPAGO_TOKEN }}
FRENET_TOKEN: ${{ secrets.FRENET_TOKEN }}
GALAXPAY_ID: ${{ secrets.GALAXPAY_ID }}
GALAXPAY_HASH: ${{ secrets.GALAXPAY_HASH }}
INFINITEPAY_ID: ${{ secrets.INFINITEPAY_ID }}
INFINITEPAY_SECRET: ${{ secrets.INFINITEPAY_SECRET }}
run: pnpm build

- name: Get npm global directories
Expand Down
56 changes: 56 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ inputs:
description: 'App: Random token (https://randomkeygen.com/) to validate Datafrete webhooks'
mercadopago-token:
description: 'App: Mercadopago API access token'
frenet-token:
description: 'App: Frenet API token'
galaxpay-id:
description: 'App: Galax Pay ID'
galaxpay-hash:
description: 'App: Galax Pay hash'
ga-api-token:
description: 'App: Google analytics API secret'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: 'App: Google analytics API secret'
description: 'App: Google Analytics API secret'

infinitepay-id:
description: 'App: InifinitePay Client ID'
infinitepay-secret:
description: 'App: InifinitePay Client Secret'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: 'App: InifinitePay Client ID'
infinitepay-secret:
description: 'App: InifinitePay Client Secret'
description: 'App: InifinitePay client ID'
infinitepay-secret:
description: 'App: InifinitePay client secret'

fb-graph-token:
description: 'App: Facebook Graph token'
jadlog-contract-token:
description: 'App: Jadlog contract token'
pagarme-encry-key:
description: 'App: PagarMe Encryption Key'
pagarme-token:
description: 'App: PagarMe API token'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pagarme-encry-key:
description: 'App: PagarMe Encryption Key'
pagarme-token:
description: 'App: PagarMe API token'
pagarme-encrypt-key:
description: 'App: Pagar.me encryption Key'
pagarme-token:
description: 'App: Pagar.me API token'

paghiper-token:
description: 'App: PagHiper API token'
pix-credentials:
description: 'App: Pix credentials'
flashcourier-contract:
description: 'App: Flash Courier contract'
webhook-app-token:
description: 'App: Webhooks App Token'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
webhook-app-token:
description: 'App: Webhooks App Token'
webhooks-token:
description: 'App: Webhooks token'


outputs: {}

Expand Down Expand Up @@ -166,6 +194,20 @@ runs:
GALAXPAY_PARTNER_HASH: ${{ inputs.galaxpay-partner-hash }}
DATAFRETE_OPERATOR_TOKEN: ${{ inputs.datafrete-operator-token }}
MERCADOPAGO_TOKEN: ${{ inputs.mercadopago-token }}
FRENET_TOKEN: ${{ inputs.frenet-token }}
GALAXPAY_ID: ${{ inputs.galaxpay-id }}
GALAXPAY_HASH: ${{ inputs.galaxpay-hash }}
GA_API_TOKEN: ${{ inputs.ga-api-token }}
INFINITEPAY_ID: ${{ inputs.infinitepay-id }}
INFINITEPAY_SECRET: ${{ inputs.infinitepay-secret }}
FB_GRAPH_TOKEN: ${{ inputs.fb-graph-token }}
JADLOG_CONTRACT_TOKEN: ${{ inputs.jadlog-contract-token }}
PAGARME_ENCRYP_KEY: ${{ inputs.pagarme-encry-key }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PAGARME_ENCRYP_KEY: ${{ inputs.pagarme-encry-key }}
PAGARME_ENCRYPT_KEY: ${{ inputs.pagarme-encrypt-key }}

PAGARME_TOKEN: ${{ inputs.pagarme-token }}
PAGHIPER_TOKEN: ${{ inputs.paghiper-token }}
PIX_CREDENTIALS: ${{ inputs.pix-credentials }}
FLASHCOURIER_CONTRACT: ${{ inputs.flashcourier-contract }}
WEBHOOKAPP_TOKEN: ${{ inputs.webhook-app-token }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WEBHOOKAPP_TOKEN: ${{ inputs.webhook-app-token }}
WEBHOOKS_TOKEN: ${{ inputs.webhooks-token }}

run: |
export GAC_FILENAME=".gac-$RANDOM.json"
echo $FIREBASE_SERVICE_ACCOUNT > $GAC_FILENAME
Expand All @@ -189,6 +231,20 @@ runs:
GALAXPAY_PARTNER_HASH=$GALAXPAY_PARTNER_HASH
DATAFRETE_OPERATOR_TOKEN=$DATAFRETE_OPERATOR_TOKEN
MERCADOPAGO_TOKEN=$MERCADOPAGO_TOKEN
FRENET_TOKEN:$FRENET_TOKEN
GALAXPAY_ID=$GALAXPAY_ID
GALAXPAY_HASH=$GALAXPAY_HASH
GA_API_TOKEN=$GA_API_TOKEN
INFINITEPAY_ID=$INFINITEPAY_ID
INFINITEPAY_SECRET=$INFINITEPAY_SECRET
FB_GRAPH_TOKEN=$FB_GRAPH_TOKEN
JADLOG_CONTRACT_TOKEN=$JADLOG_CONTRACT_TOKEN
PAGARME_ENCRYP_KEY=$PAGARME_ENCRYP_KEY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PAGARME_ENCRYP_KEY=$PAGARME_ENCRYP_KEY
PAGARME_ENCRYPT_KEY=$PAGARME_ENCRYPT_KEY

PAGARME_TOKEN=$PAGARME_TOKEN
PAGHIPER_TOKEN=$PAGHIPER_TOKEN
PIX_CREDENTIALS=$PIX_CREDENTIALS
FLASHCOURIER_CONTRACT=$FLASHCOURIER_CONTRACT
WEBHOOKAPP_TOKEN=$WEBHOOKAPP_TOKEN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
WEBHOOKAPP_TOKEN=$WEBHOOKAPP_TOKEN
WEBHOOKS_TOKEN=$WEBHOOKS_TOKEN

" > functions/.env
if [ -z "$DEPLOY_CODEBASE" ]; then
GOOGLE_APPLICATION_CREDENTIALS=$GAC_FILENAME npm run deploy
Expand Down
19 changes: 14 additions & 5 deletions packages/apps/fb-conversions/src/fb-conversions-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ const handleApiEvent: ApiEventHandler = async ({
}
logger.info(`> Webhook ${resourceId} [${evName}]`);

if (!process.env.FB_GRAPH_TOKEN) {
const fbGraphToken = appData.fb_graph_token;
if (typeof fbGraphToken === 'string' && fbGraphToken) {
process.env.FB_GRAPH_TOKEN = fbGraphToken;
} else {
logger.warn('Missing Facebook Graph token');
}
}

const fbPixelId = appData.fb_pixel_id;
const fbGraphToken = appData.fb_graph_token;
// const fbGraphToken = appData.fb_graph_token;

if (fbPixelId && fbGraphToken) {
FacebookAdsApi.init(fbGraphToken);
if (fbPixelId && process.env.FB_GRAPH_TOKEN) {
FacebookAdsApi.init(process.env.FB_GRAPH_TOKEN);

if (evName === 'orders-new') {
const order = apiDoc as Orders;
Expand Down Expand Up @@ -119,7 +128,7 @@ const handleApiEvent: ApiEventHandler = async ({
);

const eventsData = [serverEvent];
const eventRequest = (new EventRequest(fbGraphToken, fbPixelId))
const eventRequest = (new EventRequest(process.env.FB_GRAPH_TOKEN, fbPixelId))
.setEvents(eventsData);

try {
Expand Down Expand Up @@ -201,7 +210,7 @@ const handleApiEvent: ApiEventHandler = async ({
);

const eventsData = [serverEvent];
const eventRequest = (new EventRequest(fbGraphToken, fbPixelId))
const eventRequest = (new EventRequest(process.env.FB_GRAPH_TOKEN, fbPixelId))
.setEvents(eventsData);

try {
Expand Down
16 changes: 15 additions & 1 deletion packages/apps/flash-courier/lib-mjs/calculate-flash-courier.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import logger from 'firebase-functions/logger';

export default async ({ params, application }) => {
const appData = {
Expand All @@ -21,7 +22,20 @@ export default async ({ params, application }) => {
return response;
}

const flashcourierKey = appData.flashcourier_contract && appData.flashcourier_contract.key;
let flashcourierKey;

if (process.env.FLASHCOURIER_CONTRACT) {
try {
const contract = JSON.parse(process.env.FLASHCOURIER_CONTRACT);
flashcourierKey = contract.key;
} catch (e) {
logger.error(e);
flashcourierKey = appData.flashcourier_contract && appData.flashcourier_contract.key;
}
} else {
flashcourierKey = appData.flashcourier_contract && appData.flashcourier_contract.key;
}

if (!flashcourierKey) {
return {
status: 409,
Expand Down
13 changes: 12 additions & 1 deletion packages/apps/flash-courier/lib-mjs/update-tracking.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ export default () => {
}

if (appData) {
const contract = appData.flashcourier_contract;
let contract;
if (process.env.FLASHCOURIER_CONTRACT) {
try {
contract = JSON.parse(process.env.FLASHCOURIER_CONTRACT);
} catch (e) {
logger.error(e);
contract = appData.flashcourier_contract;
}
} else {
contract = appData.flashcourier_contract;
}

if (contract) {
const {
login,
Expand Down
3 changes: 2 additions & 1 deletion packages/apps/flash-courier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"dependencies": {
"@cloudcommerce/api": "workspace:*",
"@cloudcommerce/firebase": "workspace:*",
"axios": "^1.4.0"
"axios": "^1.4.0",
"firebase-functions": "^4.4.1"
},
"devDependencies": {
"@cloudcommerce/types": "workspace:*"
Expand Down
20 changes: 14 additions & 6 deletions packages/apps/frenet/lib-mjs/calculate-frenet.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import logger from 'firebase-functions/logger';

const getDimension = (side, item) => {
if (item.dimensions && item.dimensions[side]) {
Expand All @@ -23,11 +24,18 @@ export default async ({ params, application }) => {
...application.hidden_data,
};

if (!config.frenet_access_token) {
return {
error: 'FRENET_ERR',
message: 'Frenet token is unset on app hidden data (calculate unavailable) for this store',
};
if (!process.env.FRENET_TOKEN) {
const frenetToken = config.frenet_access_token;
if (typeof frenetToken === 'string' && frenetToken) {
process.env.FRENET_TOKEN = frenetToken;
} else {
logger.warn('Missing Frenet token');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

return {
error: 'FRENET_ERR',
message: 'Frenet token is unset on app hidden data (calculate unavailable) for this store',
};
}
}

// https://apx-mods.e-com.plus/api/v1/calculate_shipping/response_schema.json?store_id=100
Expand Down Expand Up @@ -87,7 +95,7 @@ export default async ({ params, application }) => {
method: 'post',
headers: {
'Content-Type': 'application/json',
token: config.frenet_access_token,
token: process.env.FRENET_TOKEN,
},
data: schema,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,28 @@ const handleApiEvent: ApiEventHandler = async ({
return null;
}
logger.info(`> Webhook ${resourceId} [${evName}] => ${apiDoc}`);

if (!process.env.GALAXPAY_ID) {
const galaxpayId = appData.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = appData.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay Hash');
}
}

const galaxpayAxios = new GalaxpayAxios({
galaxpayId: appData.galaxpay_id,
galaxpayHash: appData.galaxpay_hash,
galaxpayId: process.env.GALAXPAY_ID,
galaxpayHash: process.env.GALAXPAY_HASH,
});

await galaxpayAxios.preparing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const { GALAXPAY_PARTNER_ID, GALAXPAY_PARTNER_HASH } = process.env;
const firestoreColl = 'galaxpayTokens';

type Option = {
galaxpayId: string;
galaxpayHash: string;
galaxpayId?: string;
galaxpayHash?: string;
}

export default class GalaxPay {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Orders, Applications } from '@cloudcommerce/types';
import logger from 'firebase-functions/logger';
import GalaxpayAxios from './auth/create-access';

const checkAmountItemsOrder = (
Expand Down Expand Up @@ -47,10 +48,28 @@ const updateValueSubscription = (
) => {
const value = checkAmountItemsOrder({ ...amount }, [...items], { ...plan });

if (!process.env.GALAXPAY_ID) {
const galaxpayId = appData.hidden_data?.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = appData.hidden_data?.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay ID');
}
}

return new Promise((resolve, reject) => {
const galaxpayAxios = new GalaxpayAxios({
galaxpayId: appData.hidden_data?.galaxpay_id,
galaxpayHash: appData.hidden_data?.galaxpay_hash,
galaxpayId: process.env.GALAXPAY_ID,
galaxpayHash: process.env.GALAXPAY_HASH,
});

galaxpayAxios.preparing
Expand Down
21 changes: 19 additions & 2 deletions packages/apps/galaxpay/src/functions-lib/galaxpay/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,27 @@ const handleWehook = async (req: Request, res: Response) => {

try {
// check subscription and transaction status before in galaxpay
if (!process.env.GALAXPAY_ID) {
const galaxpayId = app.hidden_data?.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = app.hidden_data?.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay Hash');
}
}

const galaxpayAxios = new GalaxpayAxios({
galaxpayId: app.hidden_data?.galaxpay_id,
galaxpayHash: app.hidden_data?.galaxpay_hash,
galaxpayId: process.env.GALAXPAY_ID,
galaxpayHash: process.env.GALAXPAY_HASH,
});
await galaxpayAxios.preparing;

Expand Down
21 changes: 19 additions & 2 deletions packages/apps/galaxpay/src/galaxpay-create-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,27 @@ export default async (appData: AppModuleBody) => {
amount: amount.total,
};

if (!process.env.GALAXPAY_ID) {
const galaxpayId = configApp.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = configApp.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay Hash');
}
}
// setup required `transaction` response object
const galaxpayAxios = new Galaxpay({
galaxpayId: configApp.galaxpay_id,
galaxpayHash: configApp.galaxpay_hash,
galaxpayId: process.env.GALAXPAY_ID,
galaxpayHash: process.env.GALAXPAY_HASH,
});

// indicates whether the buyer should be redirected to payment link right after checkout
Expand Down
20 changes: 19 additions & 1 deletion packages/apps/galaxpay/src/galaxpay-list-payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,25 @@ export default async (data: AppModuleBody) => {
payment_gateways: [],
};

if (!configApp.galaxpay_id || !configApp.galaxpay_hash) {
if (!process.env.GALAXPAY_ID) {
const galaxpayId = configApp.galaxpay_id;
if (typeof galaxpayId === 'string' && galaxpayId) {
process.env.GALAXPAY_ID = galaxpayId;
} else {
logger.warn('Missing GalaxPay ID');
}
}

if (!process.env.GALAXPAY_HASH) {
const galaxpayHash = configApp.galaxpay_hash;
if (typeof galaxpayHash === 'string' && galaxpayHash) {
process.env.GALAXPAY_HASH = galaxpayHash;
} else {
logger.warn('Missing GalaxPay Hash');
}
}

if (!process.env.GALAXPAY_ID || !process.env.GALAXPAY_HASH) {
return responseError(
409,
'NO_GALAXPAY_KEYS',
Expand Down
Loading
Loading