diff --git a/.github/workflows/dhis2-verify-lib.yml b/.github/workflows/dhis2-verify-lib.yml index 29aac06e..3519ebbe 100644 --- a/.github/workflows/dhis2-verify-lib.yml +++ b/.github/workflows/dhis2-verify-lib.yml @@ -22,7 +22,7 @@ jobs: with: node-version: 20.x - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: path: '**/node_modules' @@ -44,7 +44,7 @@ jobs: with: node-version: 20.x - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: yarn-cache with: path: '**/node_modules' @@ -71,7 +71,7 @@ jobs: with: node-version: 20.x - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: yarn-cache with: path: '**/node_modules' @@ -98,7 +98,7 @@ jobs: with: node-version: 20.x - - uses: actions/cache@v2 + - uses: actions/cache@v4 id: yarn-cache with: path: '**/node_modules' diff --git a/services/data/src/links/RestAPILink/queryToResourcePath.test.ts b/services/data/src/links/RestAPILink/queryToResourcePath.test.ts index 9d7e0dbc..ed508686 100644 --- a/services/data/src/links/RestAPILink/queryToResourcePath.test.ts +++ b/services/data/src/links/RestAPILink/queryToResourcePath.test.ts @@ -41,6 +41,26 @@ describe('queryToResourcePath', () => { ) }) }) + describe('legacy', () => { + it('should return the apps bundle url if using `legacy::bundledApps`', () => { + const query: ResolvedResourceQuery = { + resource: 'legacy::bundledApps', + } + expect(queryToResourcePath(link, query, 'read')).toBe( + 'dhis-web-apps/apps-bundle.json' + ) + console.log({ apiPath }) + }) + it('should return the specified path if using `legacy::`', () => { + const query: ResolvedResourceQuery = { + resource: 'legacy::dhis-web-apps', + } + expect(queryToResourcePath(link, query, 'read')).toBe( + 'dhis-web-apps' + ) + console.log({ apiPath }) + }) + }) describe('resource with dot', () => { it('should leave dots in resources', () => { const query: ResolvedResourceQuery = { diff --git a/services/data/src/links/RestAPILink/queryToResourcePath.ts b/services/data/src/links/RestAPILink/queryToResourcePath.ts index 2fdc48db..0ee37e05 100644 --- a/services/data/src/links/RestAPILink/queryToResourcePath.ts +++ b/services/data/src/links/RestAPILink/queryToResourcePath.ts @@ -71,6 +71,21 @@ const makeActionPath = (resource: string) => `${resource.substr(actionPrefix.length)}.action` ) +const legacyPrefix = 'legacy::' +const isLegacy = (resource: string) => resource.startsWith(legacyPrefix) +const makeLegacyPath = (resource: string) => { + switch (resource) { + case 'legacy::bundledApps': { + return 'dhis-web-apps/apps-bundle.json' + } + // Not necessary here, but brainstorming: + // you can use whatever path you want 🤷 + default: { + return resource.replace(legacyPrefix, '') + } + } +} + const skipApiVersion = (resource: string, config: Config): boolean => { if (resource === 'tracker' || resource.startsWith('tracker/')) { if (!config.serverVersion?.minor || config.serverVersion?.minor < 38) { @@ -99,6 +114,8 @@ export const queryToResourcePath = ( const base = isAction(resource) ? makeActionPath(resource) + : isLegacy(resource) + ? makeLegacyPath(resource) : joinPath(apiBase, resource, id) validateResourceQuery(query, type)