vault/ui/lib/sync/addon/utils/api-method-resolver.ts
Jordan Reimer 712d3338b7
[UI] Ember Data Migration - Sync Overview/Destinations (#30524)
* improves path handling in capabilities service

* converts has-capability to class helper and adds pathKey and params args

* adds api service to sync engine

* updates sync types

* improves typings in paginate-list util

* adds api client error handling to error page component

* adds api utils for sync

* updates sync overview route and page component to use api service

* updates sync destinations route and page component to use api service

* adds missing copyright header

* fixes paginate-list regression

* fixes return type for has-capability helper

* Apply suggestions from code review

Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com>

* fixes page error tests

* resolves suggestions from review

* fixes has-capability usage errors

* fixes comment in capabilities service

* more test fixes

---------

Co-authored-by: Angel Garbarino <Monkeychip@users.noreply.github.com>
2025-05-07 10:53:56 -06:00

25 lines
1.2 KiB
TypeScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
/**
* Util that resolves the API client method name for a given action and destination type
* Typically both type and name would be defined as params -> /sys/sync/destinations/{type}/{name}
* This would result in a method on the API client like systemReadSyncDestinations('aws-sm', 'my-destination')
* This unfortunately is not the case and type was hardcoded in the path -> /sys/sync/destinations/aws-sm/{name}
* This results in GET, POST and DELETE methods for each destination type -> systemReadSyncDestinationsAwsSmName('my-destination')
* Since these are used in numerous places, this util was created to more easily resolve the method name
*/
import { capitalize, classify } from '@ember/string';
import type { DestinationType } from 'vault/sync';
type TypeKey = 'AwsSm' | 'AzureKv' | 'GcpSm' | 'Gh' | 'VercelProject';
export default function apiMethodResolver(action: 'read' | 'write' | 'delete', type: DestinationType) {
const method = `system${capitalize(action)}SyncDestinations${classify(type)}Name`;
return method as `system${Capitalize<typeof action>}SyncDestinations${TypeKey}Name`;
}