forked from tsai/budibase
18 changed files with 297 additions and 121 deletions
@ -1,39 +0,0 @@ |
|||||
const API = require("./api") |
|
||||
const env = require("../environment") |
|
||||
const { Headers } = require("../constants") |
|
||||
|
|
||||
const api = new API(env.ACCOUNT_PORTAL_URL) |
|
||||
|
|
||||
exports.getAccount = async email => { |
|
||||
const payload = { |
|
||||
email, |
|
||||
} |
|
||||
const response = await api.post(`/api/accounts/search`, { |
|
||||
body: payload, |
|
||||
headers: { |
|
||||
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
|
||||
}, |
|
||||
}) |
|
||||
const json = await response.json() |
|
||||
|
|
||||
if (response.status !== 200) { |
|
||||
throw new Error(`Error getting account by email ${email}`, json) |
|
||||
} |
|
||||
|
|
||||
return json[0] |
|
||||
} |
|
||||
|
|
||||
exports.getStatus = async () => { |
|
||||
const response = await api.get(`/api/status`, { |
|
||||
headers: { |
|
||||
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
|
||||
}, |
|
||||
}) |
|
||||
const json = await response.json() |
|
||||
|
|
||||
if (response.status !== 200) { |
|
||||
throw new Error(`Error getting status`) |
|
||||
} |
|
||||
|
|
||||
return json |
|
||||
} |
|
||||
@ -0,0 +1,63 @@ |
|||||
|
import API from "./api" |
||||
|
import env from "../environment" |
||||
|
import { Headers } from "../constants" |
||||
|
import { CloudAccount } from "@budibase/types" |
||||
|
|
||||
|
const api = new API(env.ACCOUNT_PORTAL_URL) |
||||
|
|
||||
|
export const getAccount = async ( |
||||
|
email: string |
||||
|
): Promise<CloudAccount | undefined> => { |
||||
|
const payload = { |
||||
|
email, |
||||
|
} |
||||
|
const response = await api.post(`/api/accounts/search`, { |
||||
|
body: payload, |
||||
|
headers: { |
||||
|
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
|
if (response.status !== 200) { |
||||
|
throw new Error(`Error getting account by email ${email}`) |
||||
|
} |
||||
|
|
||||
|
const json: CloudAccount[] = await response.json() |
||||
|
return json[0] |
||||
|
} |
||||
|
|
||||
|
export const getAccountByTenantId = async ( |
||||
|
tenantId: string |
||||
|
): Promise<CloudAccount | undefined> => { |
||||
|
const payload = { |
||||
|
tenantId, |
||||
|
} |
||||
|
const response = await api.post(`/api/accounts/search`, { |
||||
|
body: payload, |
||||
|
headers: { |
||||
|
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
||||
|
}, |
||||
|
}) |
||||
|
|
||||
|
if (response.status !== 200) { |
||||
|
throw new Error(`Error getting account by tenantId ${tenantId}`) |
||||
|
} |
||||
|
|
||||
|
const json: CloudAccount[] = await response.json() |
||||
|
return json[0] |
||||
|
} |
||||
|
|
||||
|
export const getStatus = async () => { |
||||
|
const response = await api.get(`/api/status`, { |
||||
|
headers: { |
||||
|
[Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, |
||||
|
}, |
||||
|
}) |
||||
|
const json = await response.json() |
||||
|
|
||||
|
if (response.status !== 200) { |
||||
|
throw new Error(`Error getting status`) |
||||
|
} |
||||
|
|
||||
|
return json |
||||
|
} |
||||
@ -1,17 +1,29 @@ |
|||||
import { publishEvent } from "../events" |
import { publishEvent } from "../events" |
||||
import { Event, Account } from "@budibase/types" |
import { |
||||
|
Event, |
||||
|
Account, |
||||
|
AccountCreatedEvent, |
||||
|
AccountDeletedEvent, |
||||
|
AccountVerifiedEvent, |
||||
|
} from "@budibase/types" |
||||
|
|
||||
export async function created(account: Account) { |
export async function created(account: Account) { |
||||
const properties = {} |
const properties: AccountCreatedEvent = { |
||||
|
tenantId: account.tenantId, |
||||
|
} |
||||
await publishEvent(Event.ACCOUNT_CREATED, properties) |
await publishEvent(Event.ACCOUNT_CREATED, properties) |
||||
} |
} |
||||
|
|
||||
export async function deleted(account: Account) { |
export async function deleted(account: Account) { |
||||
const properties = {} |
const properties: AccountDeletedEvent = { |
||||
|
tenantId: account.tenantId, |
||||
|
} |
||||
await publishEvent(Event.ACCOUNT_DELETED, properties) |
await publishEvent(Event.ACCOUNT_DELETED, properties) |
||||
} |
} |
||||
|
|
||||
export async function verified(account: Account) { |
export async function verified(account: Account) { |
||||
const properties = {} |
const properties: AccountVerifiedEvent = { |
||||
|
tenantId: account.tenantId, |
||||
|
} |
||||
await publishEvent(Event.ACCOUNT_VERIFIED, properties) |
await publishEvent(Event.ACCOUNT_VERIFIED, properties) |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,13 @@ |
|||||
|
export interface AccountCreatedEvent { |
||||
|
tenantId: string |
||||
|
registrationStep?: string |
||||
|
} |
||||
|
|
||||
|
export interface AccountDeletedEvent { |
||||
|
tenantId: string |
||||
|
registrationStep?: string |
||||
|
} |
||||
|
|
||||
|
export interface AccountVerifiedEvent { |
||||
|
tenantId: string |
||||
|
} |
||||
@ -1,21 +1,50 @@ |
|||||
export interface AppCreatedEvent {} |
export interface AppCreatedEvent { |
||||
|
appId: string |
||||
export interface AppUpdatedEvent {} |
version: string |
||||
|
} |
||||
export interface AppDeletedEvent {} |
|
||||
|
export interface AppUpdatedEvent { |
||||
export interface AppPublishedEvent {} |
appId: string |
||||
|
version: string |
||||
export interface AppUnpublishedEvent {} |
} |
||||
|
|
||||
export interface AppFileImportedEvent {} |
export interface AppDeletedEvent { |
||||
|
appId: string |
||||
export interface AppTemplateImportedEvent {} |
} |
||||
|
|
||||
export interface AppVersionUpdatedEvent {} |
export interface AppPublishedEvent { |
||||
|
appId: string |
||||
export interface AppVersionRevertedEvent {} |
} |
||||
|
|
||||
export interface AppRevertedEvent {} |
export interface AppUnpublishedEvent { |
||||
|
appId: string |
||||
export interface AppExportedEvent {} |
} |
||||
|
|
||||
|
export interface AppFileImportedEvent { |
||||
|
appId: string |
||||
|
} |
||||
|
|
||||
|
export interface AppTemplateImportedEvent { |
||||
|
appId: string |
||||
|
templateKey: string |
||||
|
} |
||||
|
|
||||
|
export interface AppVersionUpdatedEvent { |
||||
|
appId: string |
||||
|
currentVersion: string |
||||
|
updatedToVersion: string |
||||
|
} |
||||
|
|
||||
|
export interface AppVersionRevertedEvent { |
||||
|
appId: string |
||||
|
currentVersion: string |
||||
|
revertedToVersion: string |
||||
|
} |
||||
|
|
||||
|
export interface AppRevertedEvent { |
||||
|
appId: string |
||||
|
} |
||||
|
|
||||
|
export interface AppExportedEvent { |
||||
|
appId: string |
||||
|
} |
||||
|
|||||
Loading…
Reference in new issue