chore: address review comments

This commit is contained in:
Pierre Maurice Schwang
2022-11-29 20:03:16 +01:00
parent f47d912074
commit 34e2c77934
12 changed files with 126 additions and 134 deletions

View File

@@ -2,30 +2,30 @@ import verifyCredentials from "./verify-credentials";
import isStillVerified from "./is-still-verified"; import isStillVerified from "./is-still-verified";
export default { export default {
fields: [ fields: [
{ {
key: 'secretKey', key: 'secretKey',
label: 'Secret Key', label: 'Secret Key',
type: 'string' as const, type: 'string' as const,
required: true, required: true,
readOnly: false, readOnly: false,
value: null, value: null,
placeholder: null, placeholder: null,
description: null, description: null,
clickToCopy: false, clickToCopy: false,
}, },
{ {
key: 'displayName', key: 'displayName',
label: 'Account Name', label: 'Account Name',
type: 'string' as const, type: 'string' as const,
required: true, required: true,
readOnly: false, readOnly: false,
value: null, value: null,
placeholder: null, placeholder: null,
description: 'The display name that identifies this stripe connection - most likely the associated account name', description: 'The display name that identifies this stripe connection - most likely the associated account name',
clickToCopy: false, clickToCopy: false,
}, },
], ],
verifyCredentials, verifyCredentials,
isStillVerified isStillVerified
}; };

View File

@@ -1,13 +1,9 @@
import { IGlobalVariable } from '@automatisch/types'; import { IGlobalVariable } from '@automatisch/types';
const verifyCredentials = async ($: IGlobalVariable) => { const verifyCredentials = async ($: IGlobalVariable) => {
try { await $.http.get(
await $.http.get( `/v1/events`,
`/v1/events`, );
);
} catch (e) {
throw new Error('Invalid secret key')
}
await $.auth.set({ await $.auth.set({
screenName: $.auth.data?.displayName, screenName: $.auth.data?.displayName,
}); });

View File

@@ -1,8 +1,8 @@
import {TBeforeRequest} from "@automatisch/types"; import {TBeforeRequest} from "@automatisch/types";
const addAuthHeader: TBeforeRequest = ($, requestConfig) => { const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
requestConfig.headers['Authorization'] = `Bearer ${$.auth.data?.secretKey}` requestConfig.headers['Authorization'] = `Bearer ${$.auth.data?.secretKey}`
return requestConfig return requestConfig
} }
export default addAuthHeader; export default addAuthHeader;

View File

@@ -1,34 +0,0 @@
import {IGlobalVariable, IJSONObject} from "@automatisch/types";
import {URLSearchParams} from "url";
import {isEmpty, omitBy} from "lodash";
const getBalanceTransactions = async ($: IGlobalVariable) => {
let response;
let lastId = undefined;
do {
const params: IJSONObject = {
starting_after: lastId,
ending_before: $.flow.lastInternalId
}
const queryParams = new URLSearchParams(omitBy(params, isEmpty))
const requestPath = `/v1/balance_transactions${
queryParams.toString() ? `?${queryParams.toString()}` : ''
}`;
response = (await $.http.get(requestPath)).data
for (const entry of response.data) {
$.pushTriggerItem({
raw: entry,
meta: {
internalId: entry.id as string
}
})
lastId = entry.id
}
} while (response.has_more)
return $.triggerOutput;
};
export default getBalanceTransactions;

View File

@@ -1,34 +0,0 @@
import {IGlobalVariable, IJSONObject} from "@automatisch/types";
import {URLSearchParams} from "url";
import {isEmpty, omitBy} from "lodash";
const getPayouts = async ($: IGlobalVariable) => {
let response;
let lastId = undefined;
do {
const params: IJSONObject = {
starting_after: lastId,
ending_before: $.flow.lastInternalId
}
const queryParams = new URLSearchParams(omitBy(params, isEmpty))
const requestPath = `/v1/payouts${
queryParams.toString() ? `?${queryParams.toString()}` : ''
}`;
response = (await $.http.get(requestPath)).data
for (const entry of response.data) {
$.pushTriggerItem({
raw: entry,
meta: {
internalId: entry.id as string
}
})
lastId = entry.id
}
} while (response.has_more)
return $.triggerOutput;
};
export default getPayouts;

View File

@@ -4,16 +4,16 @@ import auth from "./auth"
import triggers from "./triggers" import triggers from "./triggers"
export default defineApp({ export default defineApp({
name: 'Stripe', name: 'Stripe',
key: 'stripe', key: 'stripe',
iconUrl: '{BASE_URL}/apps/stripe/assets/favicon.svg', iconUrl: '{BASE_URL}/apps/stripe/assets/favicon.svg',
authDocUrl: 'https://automatisch.io/docs/apps/stripe/connection', authDocUrl: 'https://automatisch.io/docs/apps/stripe/connection',
supportsConnections: true, supportsConnections: true,
baseUrl: 'https://stripe.com', baseUrl: 'https://stripe.com',
apiBaseUrl: 'https://api.stripe.com', apiBaseUrl: 'https://api.stripe.com',
primaryColor: '635bff', primaryColor: '635bff',
beforeRequest: [addAuthHeader], beforeRequest: [addAuthHeader],
auth, auth,
triggers, triggers,
actions: [], actions: [],
}) })

View File

@@ -0,0 +1,32 @@
import {IGlobalVariable, IJSONObject} from "@automatisch/types";
import {URLSearchParams} from "url";
import {isEmpty, omitBy} from "lodash";
const getBalanceTransactions = async ($: IGlobalVariable) => {
let response;
let lastId = undefined;
do {
const params: IJSONObject = {
starting_after: lastId,
ending_before: $.flow.lastInternalId
}
const queryParams = new URLSearchParams(omitBy(params, isEmpty))
const requestPath = `/v1/balance_transactions${
queryParams.toString() ? `?${queryParams.toString()}` : ''
}`;
response = (await $.http.get(requestPath)).data
for (const entry of response.data) {
$.pushTriggerItem({
raw: entry,
meta: {
internalId: entry.id as string
}
})
lastId = entry.id
}
} while (response.has_more)
};
export default getBalanceTransactions;

View File

@@ -1,12 +1,12 @@
import defineTrigger from "../../../../helpers/define-trigger"; import defineTrigger from "../../../../helpers/define-trigger";
import getBalanceTransactions from "../../common/get-balance-transactions"; import getBalanceTransactions from "./get-balance-transactions";
export default defineTrigger({ export default defineTrigger({
name: 'Balance Transaction', name: 'New Balance Transactions',
key: 'balanceTransaction', key: 'balanceTransaction',
description: 'Triggers when a new transaction is processed (refund, payout, adjustment, ...)', description: 'Triggers when a new transaction is processed (refund, payout, adjustment, ...)',
pollInterval: 15, pollInterval: 15,
async run($) { async run($) {
await getBalanceTransactions($) await getBalanceTransactions($)
} }
}) })

View File

@@ -0,0 +1,32 @@
import {IGlobalVariable, IJSONObject} from "@automatisch/types";
import {URLSearchParams} from "url";
import {isEmpty, omitBy} from "lodash";
const getPayouts = async ($: IGlobalVariable) => {
let response;
let lastId = undefined;
do {
const params: IJSONObject = {
starting_after: lastId,
ending_before: $.flow.lastInternalId
}
const queryParams = new URLSearchParams(omitBy(params, isEmpty))
const requestPath = `/v1/payouts${
queryParams.toString() ? `?${queryParams.toString()}` : ''
}`;
response = (await $.http.get(requestPath)).data
for (const entry of response.data) {
$.pushTriggerItem({
raw: entry,
meta: {
internalId: entry.id as string
}
})
lastId = entry.id
}
} while (response.has_more)
};
export default getPayouts;

View File

@@ -1,12 +1,12 @@
import defineTrigger from "../../../../helpers/define-trigger"; import defineTrigger from "../../../../helpers/define-trigger";
import getPayouts from "../../common/get-payouts"; import getPayouts from "./get-payouts";
export default defineTrigger({ export default defineTrigger({
name: 'Payout', name: 'New Payouts',
key: 'payout', key: 'payout',
description: 'Triggers when a payout (Stripe <-> Bank account) has been updated', description: 'Triggers when a payout (Stripe <-> Bank account) has been updated',
pollInterval: 15, pollInterval: 15,
async run($) { async run($) {
await getPayouts($) await getPayouts($)
} }
}) })

View File

@@ -9,6 +9,6 @@ You are free to use the **Testing secret key** instead of the productive secret
::: :::
1. Go to the [Stripe Dashboard > Developer > API keys](https://dashboard.stripe.com/apikeys) 1. Go to the [Stripe Dashboard > Developer > API keys](https://dashboard.stripe.com/apikeys)
2. Click on **Reveal live key** in the table row **Secret key** and copy the now shown secret key 3 2. Click on **Reveal live key** in the table row **Secret key** and copy the now shown secret key
3. Paste the **Secret key** in the named field in Automatisch and assign a display name for the connection. 3. Paste the **Secret key** in the named field in Automatisch and assign a display name for the connection.
4. Congrats! You can start using the new Stripe connection! 4. Congrats! You can start using the new Stripe connection!

View File

@@ -1,11 +1,11 @@
--- ---
favicon: /favicons/stripe.svg favicon: /favicons/stripe.svg
items: items:
- name: Payout - name: New Payouts
desc: Triggers when stripe sent a payout to a third-party bank account or vice versa. desc: Triggers when stripe sent a payout to a third-party bank account or vice versa.
org: Stripe Documentation org: Stripe Documentation
orgLink: https://stripe.com/docs/api/payouts/object orgLink: https://stripe.com/docs/api/payouts/object
- name: Balance Transaction - name: New Balance Transactions
desc: Triggers when a fund has been moved through your stripe account. desc: Triggers when a fund has been moved through your stripe account.
org: Stripe Documentation org: Stripe Documentation
orgLink: https://stripe.com/docs/api/balance_transactions/object orgLink: https://stripe.com/docs/api/balance_transactions/object