How to use the @vtex/api.Apps function in @vtex/api

To help you get started, we’ve selected a few @vtex/api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vtex / toolbelt / src / modules / workspace / abtest / utils.ts View on Github external
id: '',
    params: {},
  },
  userAgent,
  workspace: 'master',
  requestId: '',
  operationId: '',
  logger: dummyLogger,
  platform: '',
}

const options = { timeout: (envTimeout || DEFAULT_TIMEOUT) as number }

// Clients for the 'master' workspace
export const abtester = new ABTester(contextForMaster, { ...options, retries: 3 })
export const apps = new Apps(contextForMaster, options)

export const formatDays = (days: number) => {
  let suffix = 'days'
  if (days === 1) {
    suffix = 'day'
  }
  return `${numbro(days).format('0,0')} ${suffix}`
}

export const formatDuration = (durationInMinutes: number) => {
  const minutes = durationInMinutes % 60
  const hours = Math.trunc(durationInMinutes / 60) % 24
  const days = Math.trunc(durationInMinutes / (60 * 24))
  return `${days} days, ${hours} hours and ${minutes} minutes`
}
github vtex / toolbelt / scripts / mass-apps-operations.ts View on Github external
const uninstall = (workspace: string, workspaces: Workspaces) => async ({name: account}: {name: string}) => {
  const apps = new Apps({
    account,
    workspace,
    authToken,
    userAgent: USER_AGENT,
    region: REGION,
  })
  const prefix = c.bold(`[${account}/${workspace}]`)
  const log = (s) => console.log(`${prefix} ${s}`)

  log('Creating workspace...')
  try {
    await workspaces.create(account, workspace)
  } catch (e) {
    const code = e.response.data.code
    if (code === 'WorkspaceAlreadyExists') {
      try {
github vtex / toolbelt / src / modules / deps / utils.ts View on Github external
export const getCleanDependencies = async context => {
  return (await new Apps(context).getDependencies().then(cleanDeps)) as string[]
}
github vtex / toolbelt / src / clients / index.ts View on Github external
const createClients = (customContext: Partial = {}, customOptions: InstanceOptions = {}) => {
  const mergedContext = { ...context, ...customContext }
  const mergedOptions = { ...options, ...customOptions }
  return {
    builder: new Builder(mergedContext, mergedOptions),
    logger: new Logger(mergedContext, mergedOptions),
    registry: new Registry(mergedContext, mergedOptions),
    rewriter: new Rewriter(mergedContext, mergedOptions),
    events: new Events(mergedContext, mergedOptions),
  }
}

const [apps, router, workspaces, logger, events, billing, rewriter] = getToken()
  ? [
      new Apps(context, options),
      new Router(context, options),
      new Workspaces(context, options),
      new Logger(context),
      new Events(context),
      new Billing(context, options),
      new Rewriter(context, options),
    ]
  : [
      interceptor('apps'),
      interceptor('router'),
      interceptor('workspaces'),
      interceptor('logger'),
      interceptor('events'),
      interceptor('billing'),
      interceptor('rewriter'),
    ]