Skip to content

Commit

Permalink
feat(ama-sdk): move ApiFetchClient to dedicated package
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot committed Sep 3, 2024
1 parent afe641a commit aaa0ba9
Show file tree
Hide file tree
Showing 95 changed files with 2,776 additions and 43 deletions.
1 change: 1 addition & 0 deletions apps/showcase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"dependencies": {
"@agnos-ui/angular": "~0.2.0",
"@ama-sdk/client-fetch": "workspace:^",
"@ama-sdk/core": "workspace:^",
"@ama-sdk/schematics": "workspace:^",
"@ama-sdk/showcase-sdk": "workspace:^",
Expand Down
19 changes: 19 additions & 0 deletions packages/@ama-sdk/client-fetch/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable quote-props */

module.exports = {
'root': true,
'parserOptions': {
'tsconfigRootDir': __dirname,
'project': [
'tsconfig.build.json',
'tsconfig.builders.json',
'tsconfig.spec.json',
'tsconfig.eslint.json'
],
'sourceType': 'module'
},
'extends': [
'../../../.eslintrc.js'
]
};
10 changes: 10 additions & 0 deletions packages/@ama-sdk/client-fetch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/fwk
/helpers
/index.*
/bundles
/test
/dist-test
/plugins
/dist
/utils
/build
Empty file.
21 changes: 21 additions & 0 deletions packages/@ama-sdk/client-fetch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Ama SDK Fetch Client

[![Stable Version](https://img.shields.io/npm/v/@ama-sdk/core?style=for-the-badge)](https://www.npmjs.com/package/@ama-sdk/core)
[![Bundle Size](https://img.shields.io/bundlephobia/min/@ama-sdk/core?color=green&style=for-the-badge)](https://www.npmjs.com/package/@ama-sdk/core)

This package exposes the **Api Fetch Client** from an SDK based on [@ama-sdk/core](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/core).

This package contains all the [Fetch Plugins](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins), helpers and object definitions to dialog with an API following the `ama-sdk` architecture.

Please refer to the [ama-sdk-schematics](../schematics/README.md) package for getting started with an API based on `ama-sdk`.

## Available plugins

- [abort](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins/abort)
- [concurrent](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins/concurrent)
- [keepalive](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins/keepalive)
- [mock-intercept](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins/mock-intercept)
- [perf-metric](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins/perf-metric)
- [retry](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins/retry)
- [timeout](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins/timeout)
- [wait-for](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-fetch/src/plugins/wait-for)
11 changes: 11 additions & 0 deletions packages/@ama-sdk/client-fetch/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://raw.githubusercontent.com/angular/angular-cli/main/packages/angular_devkit/schematics/collection-schema.json",
"schematics": {
"ng-add": {
"description": "Add the SDK Fetch Client API to the project.",
"factory": "./schematics/ng-add/index#ngAdd",
"schema": "./schematics/ng-add/schema.json",
"aliases": ["install", "i"]
}
}
}
10 changes: 10 additions & 0 deletions packages/@ama-sdk/client-fetch/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const getJestGlobalConfig = require('../../../jest.config.ut').getJestGlobalConfig;

/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
module.exports = {
...getJestGlobalConfig(),
projects: [
'<rootDir>/testing/jest.config.ut.js',
'<rootDir>/testing/jest.config.ut.builders.js'
]
};
128 changes: 128 additions & 0 deletions packages/@ama-sdk/client-fetch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"name": "@ama-sdk/client-fetch",
"version": "0.0.0-placeholder",
"publishConfig": {
"access": "public"
},
"description": "API Request client for @ama-sdk/core based SDK",
"module": "dist/src/public_api.js",
"esm2015": "dist/esm2015/public_api.js",
"esm2020": "dist/src/public_api.js",
"typings": "dist/src/public_api.d.ts",
"sideEffects": false,
"exports": {
"./package.json": {
"default": "./package.json"
},
".": {
"module": "./dist/src/public_api.js",
"esm2020": "./dist/src/public_api.js",
"esm2015": "./dist/esm2015/public_api.js",
"es2020": "./dist/cjs/public_api.js",
"default": "./dist/cjs/public_api.js",
"typings": "./dist/src/public_api.d.ts",
"import": "./dist/src/public_api.js",
"node": "./dist/cjs/public_api.js",
"require": "./dist/cjs/public_api.js"
}
},
"scripts": {
"nx": "nx",
"ng": "yarn nx",
"build": "yarn nx build ama-sdk-client-fetch",
"build:cjs": "swc src -d dist/cjs -C module.type=commonjs -q --strip-leading-paths",
"build:esm2015": "swc src -d dist/esm2015 -C module.type=es6 -q --strip-leading-paths",
"build:esm2020": "tsc -b tsconfig.build.json",
"postbuild": "yarn cpy './package.json' dist && patch-package-json-main",
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' dist/schematics && yarn cpy 'collection.json' dist",
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest",
"prepare:publish": "prepare-publish ./dist"
},
"dependencies": {
"@swc/helpers": "~0.5.0",
"tslib": "^2.6.2",
"uuid": "^10.0.0"
},
"peerDependencies": {
"@ama-sdk/core": "workspace:^",
"@angular-devkit/schematics": "~18.2.0",
"@angular/cli": "~18.2.0",
"@angular/common": "~18.2.0",
"@o3r/schematics": "workspace:^",
"@schematics/angular": "~18.2.0",
"isomorphic-fetch": "^3.0.0",
"typescript": "~5.5.4"
},
"peerDependenciesMeta": {
"@angular-devkit/schematics": {
"optional": true
},
"@angular/cli": {
"optional": true
},
"@angular/common": {
"optional": true
},
"@o3r/schematics": {
"optional": true
},
"@schematics/angular": {
"optional": true
},
"isomorphic-fetch": {
"optional": true
},
"typescript": {
"optional": true
}
},
"devDependencies": {
"@ama-sdk/core": "workspace:^",
"@angular-devkit/core": "~18.2.0",
"@angular-devkit/schematics": "~18.2.0",
"@angular-eslint/eslint-plugin": "~18.3.0",
"@angular/common": "~18.2.0",
"@angular/core": "~18.2.0",
"@nx/eslint-plugin": "~19.5.0",
"@nx/jest": "~19.5.0",
"@o3r/build-helpers": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin-ts": "~2.4.0",
"@swc/cli": "~0.4.0",
"@swc/core": "~1.7.0",
"@types/jest": "~29.5.2",
"@types/node": "^20.0.0",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.14.1",
"@typescript-eslint/utils": "^7.14.1",
"copyfiles": "^2.4.1",
"cpy-cli": "^5.0.0",
"eslint": "^8.57.0",
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-jest": "~28.8.0",
"eslint-plugin-jsdoc": "~48.11.0",
"eslint-plugin-prefer-arrow": "~1.2.3",
"eslint-plugin-unicorn": "^54.0.0",
"isomorphic-fetch": "~3.0.0",
"jest": "~29.7.0",
"jest-junit": "~16.0.0",
"jsonc-eslint-parser": "~2.4.0",
"minimist": "^1.2.6",
"pid-from-port": "^1.1.3",
"rimraf": "^5.0.1",
"rxjs": "^7.8.1",
"semver": "^7.5.2",
"ts-jest": "~29.2.0",
"ts-node": "~10.9.2",
"type-fest": "^4.10.2",
"typescript": "~5.5.4",
"zone.js": "~0.14.2"
},
"engines": {
"node": "^18.19.1 || ^20.11.1 || >=22.0.0"
},
"schematics": "./collection.json"
}
84 changes: 84 additions & 0 deletions packages/@ama-sdk/client-fetch/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"name": "ama-sdk-client-fetch",
"$schema": "https://raw.githubusercontent.com/nrwl/nx/master/packages/nx/schemas/project-schema.json",
"projectType": "library",
"sourceRoot": "packages/@ama-sdk/client-fetch/src",
"prefix": "o3r",
"targets": {
"build": {
"executor": "nx:run-script",
"outputs": ["{projectRoot}/dist/package.json"],
"options": {
"script": "postbuild"
},
"dependsOn": [
"build-builders",
"compile",
"build-esm2015",
"build-cjs"
]
},
"build-esm2015": {
"executor": "nx:run-script",
"options": {
"script": "build:esm2015"
}
},
"build-cjs": {
"executor": "nx:run-script",
"options": {
"script": "build:cjs"
}
},
"compile": {
"executor": "nx:run-script",
"options": {
"script": "build:esm2020"
},
"outputs": ["{projectRoot}/dist/src"]
},
"lint": {
"options": {
"eslintConfig": "packages/@ama-sdk/client-fetch/.eslintrc.js",
"lintFilePatterns": [
"packages/@ama-sdk/client-fetch/src/**/*.ts",
"packages/@ama-sdk/client-fetch/package.json"
]
},
"dependsOn": [
"build"
]
},
"test": {
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "packages/@ama-sdk/client-fetch/jest.config.js"
}
},
"prepare-publish": {
"executor": "nx:run-script",
"options": {
"script": "prepare:publish"
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"command": "npm publish packages/@ama-sdk/client-fetch/dist"
}
},
"prepare-build-builders": {
"executor": "nx:run-script",
"options": {
"script": "prepare:build:builders"
}
},
"build-builders": {
"executor": "nx:run-script",
"options": {
"script": "build:builders"
}
}
},
"tags": []
}
13 changes: 13 additions & 0 deletions packages/@ama-sdk/client-fetch/schematics/ng-add/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
This files is used to allow the usage of the builder within @o3r/framework mono-repository.
It should not be part of the package.
*/

const {resolve} = require('node:path');

require('ts-node').register({ project: resolve(__dirname, '..', '..', 'tsconfig.builders.json') });
require('ts-node').register = () => {};

module.exports = require('./index.ts');
79 changes: 79 additions & 0 deletions packages/@ama-sdk/client-fetch/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { chain, noop, Rule } from '@angular-devkit/schematics';
import type { NgAddSchematicsSchema } from './schema';
import * as path from 'node:path';
import { NodeDependencyType } from '@schematics/angular/utility/dependencies';

const devDependenciesToInstall: string[] = [

];


const reportMissingSchematicsDep = (logger: { error: (message: string) => any }) => (reason: any) => {
logger.error(`[ERROR]: Adding @ama-sdk/client-fetch has failed.
If the error is related to missing @o3r dependencies you need to install '@o3r/core' to be able to use the store-sync package. Please run 'ng add @o3r/core' .
Otherwise, use the error message as guidance.`);
throw reason;
};

/**
* Add Otter store-sync to an Otter Project
* @param options
*/
function ngAddFn(options: NgAddSchematicsSchema): Rule {
return async (tree, context) => {
// use dynamic import to properly raise an exception if it is not an Otter project.
const {
getPackageInstallConfig,
applyEsLintFix,
setupDependencies,
getO3rPeerDeps,
getProjectNewDependenciesTypes,
getWorkspaceConfig,
getExternalDependenciesVersionRange
} = await import('@o3r/schematics');

const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const depsInfo = getO3rPeerDeps(packageJsonPath);

const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
acc[dep] = {
inManifest: [{
range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`,
types: getProjectNewDependenciesTypes(workspaceProject)
}],
ngAddOptions: { exactO3rVersion: options.exactO3rVersion }
};
return acc;
}, getPackageInstallConfig(packageJsonPath, tree, options.projectName, false, !!options.exactO3rVersion));
Object.entries(getExternalDependenciesVersionRange(devDependenciesToInstall, packageJsonPath, context.logger))
.forEach(([dep, range]) => {
dependencies[dep] = {
inManifest: [{
range,
types: [NodeDependencyType.Dev]
}]
};
});

return chain([
// optional custom action dedicated to this module
options.skipLinter ? noop() : applyEsLintFix(),
// add the missing Otter modules in the current project
setupDependencies({
projectName: options.projectName,
dependencies,
ngAddToRun: depsInfo.o3rPeerDeps
})
]);
};
}

/**
* Add Otter store-sync to an Otter Project
* @param options
*/
export const ngAdd = (options: NgAddSchematicsSchema): Rule => async (_, { logger }) => {
const { createSchematicWithMetricsIfInstalled } = await import('@o3r/schematics').catch(reportMissingSchematicsDep(logger));
return createSchematicWithMetricsIfInstalled(ngAddFn)(options);
};
Loading

0 comments on commit aaa0ba9

Please sign in to comment.