Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Kial Jinnah <kialj876@gmail.com>
  • Loading branch information
kialj876 committed Jun 14, 2024
1 parent 6a5817e commit a6e6d8e
Show file tree
Hide file tree
Showing 20 changed files with 423 additions and 271 deletions.
3 changes: 1 addition & 2 deletions src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<p class="font-normal mt-7">
If this issue persists, please contact us.
</p>
<bcros-contact-info class="font-normal font-16 mt-4" :contacts="RegistriesInfo" />
<bcros-contact-info class="font-normal font-16 mt-4" :contacts="getContactInfo('registries')" />
</template>
</bcros-dialog>
<div v-if="appLoading">
Expand All @@ -27,7 +27,6 @@
</template>
<script setup lang="ts">
import { StatusCodes } from 'http-status-codes'
import { RegistriesInfo } from '@/resources/contact-info'
const appLoading = ref(false)
// // errors
Expand Down
2 changes: 1 addition & 1 deletion src/components/bcros/BusinessDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const { currentBusiness, currentBusinessContact, currentBusinessName } = storeTo
const businessInfo = ref([] as { term: string, value: string }[])
function updateBusinessDetails () {
const isFirm = [BusinessTypeE.GP, BusinessTypeE.SP].includes(currentBusiness.value.legalType as BusinessTypeE)
const isFirm = [BusinessTypeE.PARTNERSHIP, BusinessTypeE.SOLE_PROP].includes(currentBusiness.value.legalType)
const identifierLabel = isFirm ? t('label.business.registrationNum') : t('label.business.incorporationNum')
businessInfo.value = [
{ term: t('label.business.businessNum'), value: currentBusiness.value.taxId || t('text.general.nA') },
Expand Down
8 changes: 8 additions & 0 deletions src/composables/useBcrosFetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// following docs: https://nuxt.com/docs/guide/recipes/custom-usefetch
export function useBcrosFetch<T>(url: string, options: any) {
return useFetch<T>(url, {
...options,
watch: false,
$fetch: useNuxtApp().$bcrosFetch
})
}
16 changes: 0 additions & 16 deletions src/composables/useFetchBcros.ts

This file was deleted.

63 changes: 52 additions & 11 deletions src/enums/business-type-e.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,54 @@
// FUTURE: add in full list
export enum BusinessTypeModernizedE {
COOPERATIVE_ASSOCIATION = 'CP',
BENEFIT_COMPANY = 'BEN',
GENERAL_PARTNERSHIP = 'GP',
SOLE_PROPRIETOR = 'SP'
}

export enum BusinessTypeE {
// Corporations
BC = 'BC',
BEN = 'BEN',
CCC = 'CCC',
ULC = 'ULC',
// Firms
GP = 'GP',
SP = 'SP',
// Other
CP = 'CP',
EXTRA_PRO_A = 'A',
EXTRA_PRO_B = 'B',
BC_COMPANY = 'BC',
BENEFIT_COMPANY = 'BEN',
CONTINUE_IN = 'C',
BC_CCC = 'CC',
CEMETARY = 'CEM',
COOP = 'CP',
CONT_IN_SOCIETY = 'CS',
ULC_CONTINUE_IN = 'CUL',
EXTRA_PRO_REG = 'EPR',
FINANCIAL = 'FI',
FOREIGN = 'FOR',
PARTNERSHIP = 'GP',
LIBRARY = 'LIB',
LICENSED = 'LIC',
LL_PARTNERSHIP = 'LL',
LIMITED_CO = 'LLC',
LIM_PARTNERSHIP = 'LP',
MISC_FIRM = 'MF',
PRIVATE_ACT = 'PA',
PARISHES = 'PAR',
PENSION_FUND_SOCIETY = 'PFS',
CO_1860 = 'QA',
CO_1862 = 'QB',
CO_1878 = 'QC',
CO_1890 = 'QD',
CO_1897 = 'QE',
REGISTRATION = 'REG',
RAILWAYS = 'RLY',
SOCIETY = 'S',
SOCIETY_BRANCH = 'SB',
SOLE_PROP = 'SP',
TRUST = 'T',
TRAMWAYS = 'TMY',
BC_ULC_COMPANY = 'ULC',
ULC_CO_1860 = 'UQA',
ULC_CO_1862 = 'UQB',
ULC_CO_1878 = 'UQC',
ULC_CO_1890 = 'UQD',
ULC_CO_1897 = 'UQE',
XPRO_COOP= 'XCP',
XPRO_LL_PARTNR = 'XL',
XPRO_LIM_PARTNR = 'XP',
XPRO_SOCIETY = 'XS'
}
50 changes: 0 additions & 50 deletions src/enums/corp-type-cd-e.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/enums/entity-type-e.ts

This file was deleted.

45 changes: 45 additions & 0 deletions src/plugins/bcros-fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// custom fetch docs: https://nuxt.com/docs/guide/recipes/custom-usefetch

const addHeader = (headers: HeadersInit, key: string, value: string) => {
if (Array.isArray(headers)) {
headers.push([key, value])
} else if (headers instanceof Headers) {
headers.set(key, value)
} else {
headers[key] = value
}
}

const headerExists = (headers: HeadersInit, key: string) => {
if (Array.isArray(headers)) {
return !!headers.find(val => val[0] === key)
}
return Object.keys(headers).includes(key)
}

export default defineNuxtPlugin(() => {
const bcrosFetch = $fetch.create({
onRequest({ options }) {
const headers = options.headers ||= {}

if (!headerExists(headers, 'Authorization') && useBcrosKeycloak().kc?.token) {
addHeader(headers, 'Authorization', `Bearer ${useBcrosKeycloak().kc.token}`)
}

if (!headerExists(headers, 'Account-Id') && useBcrosAccount().currentAccount?.id) {
addHeader(headers, 'Account-Id', (useBcrosAccount().currentAccount.id).toString())
}

if (!headerExists(headers, 'Accept')) {
addHeader(headers, 'Accept', 'application/json')
}
}
})

// Expose to useNuxtApp().$bcrosFetch
return {
provide: {
bcrosFetch
}
}
})
14 changes: 0 additions & 14 deletions src/resources/contact-info/helpdesk-info.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/resources/contact-info/index.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/resources/contact-info/registries-info.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/resources/other-corp-types.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const useBcrosAccount = defineStore('bcros/account', () => {

/** Get user information from AUTH */
async function getAuthUserProfile (identifier: string) {
return await useFetchBcros<KCUserI>(`${apiURL}/users/${identifier}`)
return await useBcrosFetch<KCUserI>(`${apiURL}/users/${identifier}`)
.then(({ data, error }) => {
if (error.value || !data.value) {
console.warn('Error fetching user info.', error.value)
Expand All @@ -38,7 +38,7 @@ export const useBcrosAccount = defineStore('bcros/account', () => {

/** Update user information in AUTH with current token info */
async function updateAuthUserInfo () {
return await useFetchBcros<KCUserI>(`${apiURL}/users`, { method: 'POST', body: { isLogin: true } })
return await useBcrosFetch<KCUserI>(`${apiURL}/users`, { method: 'POST', body: { isLogin: true } })
.then(({ data, error }) => {
if (error.value || !data.value) {
// not too worried if this errs -- log for ops
Expand All @@ -65,7 +65,7 @@ export const useBcrosAccount = defineStore('bcros/account', () => {

/** Get the user's account list */
async function getUserAccounts (keycloakGuid: string) {
return await useFetchBcros<UserSettingsI[]>(`${apiURL}/users/${keycloakGuid}/settings`)
return await useBcrosFetch<UserSettingsI[]>(`${apiURL}/users/${keycloakGuid}/settings`)
.then(({ data, error }) => {
if (error.value || !data.value) {
console.warn('Error fetching user settings / account list.', error.value)
Expand All @@ -83,7 +83,7 @@ export const useBcrosAccount = defineStore('bcros/account', () => {
/** Get all the current account products. */
async function getAccountProducts (): Promise<ProductI[]> {
const config = { baseURL: apiURL, params: { include_hidden: true } }
return await useFetchBcros<ProductI[]>(`orgs/${currentAccount.value?.id}/products`, config)
return await useBcrosFetch<ProductI[]>(`orgs/${currentAccount.value?.id}/products`, config)
.then(({ data, error }) => {
if (error.value || !data.value) {
console.info(error)
Expand Down
6 changes: 3 additions & 3 deletions src/stores/business.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const useBcrosBusiness = defineStore('bcros/business', () => {

const currentBusinessIdentifier = computed((): string => currentBusiness.value.identifier)
const currentBusinessName = computed((): string => {
if (currentBusiness.value.alternateNames && currentBusiness.value.legalType === BusinessTypeE.SP) {
if (currentBusiness.value.alternateNames && currentBusiness.value.legalType === BusinessTypeE.SOLE_PROP) {
return currentBusiness.value.alternateNames[0].operatingName
}
return currentBusiness.value.legalName
Expand All @@ -21,7 +21,7 @@ export const useBcrosBusiness = defineStore('bcros/business', () => {

/** Return the business details for the given identifier */
async function getBusinessDetails (identifier: string, params?: object) {
return await useFetchBcros<{ business: BusinessI }>(
return await useBcrosFetch<{ business: BusinessI }>(
`${apiURL}/businesses/${identifier}`,
{ params, dedupe: 'defer' }
)
Expand All @@ -41,7 +41,7 @@ export const useBcrosBusiness = defineStore('bcros/business', () => {
/** Return the business contacts for the given identifier */
async function getBusinessContact (identifier: string, params?: object) {
// NOTE: this data will be moved to the legal-api eventually
return await useFetchBcros<ContactsBusinessResponseI>(`${authApiURL}/entities/${identifier}`, { params })
return await useBcrosFetch<ContactsBusinessResponseI>(`${authApiURL}/entities/${identifier}`, { params })
.then(({ data, error }) => {
if (error.value || !data.value) {
console.warn('Error fetching business contacts for', identifier)
Expand Down
6 changes: 3 additions & 3 deletions src/stores/launchdarkly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const useBcrosLaunchdarkly = defineStore('bcros/launchdarkly', () => {
}
ldContext.value = { kind: 'multi', org, user }
const options: LDOptions = {
streaming: true,
useReport: true,
streaming: false,
useReport: false,
diagnosticOptOut: true
}
ldClient.value = initialize(ldClientId, ldContext.value, options)
Expand All @@ -67,7 +67,7 @@ export const useBcrosLaunchdarkly = defineStore('bcros/launchdarkly', () => {

function getStoredFlag (name: string): any {
if (!ldInitialized) {
console.warn('Accessing ldarkly flag, but ldarkly was not initialized.')
console.warn('Accessing ldarkly stored flag, but ldarkly is not initialized.')
}
return ldFlagSet.value[name]
}
Expand Down
Loading

0 comments on commit a6e6d8e

Please sign in to comment.