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 c8026d4
Show file tree
Hide file tree
Showing 100 changed files with 2,794 additions and 49 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
4 changes: 2 additions & 2 deletions apps/showcase/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ApiClient, ApiFetchClient} from '@ama-sdk/core';
import { ApiFetchClient } from '@ama-sdk/client-fetch';
import {PetApi} from '@ama-sdk/showcase-sdk';
import { registerLocaleData } from '@angular/common';
import localeEN from '@angular/common/locales/en';
Expand Down Expand Up @@ -46,7 +46,7 @@ registerLocaleData(localeEN, 'en-GB');
registerLocaleData(localeFR, 'fr-FR');

function petApiFactory(logger: Logger) {
const apiConfig: ApiClient = new ApiFetchClient(
const apiConfig = new ApiFetchClient(
{
basePath: 'https://petstore3.swagger.io/api/v3',
requestPlugins: [],
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'
]
};
126 changes: 126 additions & 0 deletions packages/@ama-sdk/client-fetch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"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",
"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');
Loading

0 comments on commit c8026d4

Please sign in to comment.