-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): exported Angular and Beacon client to dedicated package
deprecate(sdk): the beacon and angular clients from @ama-sdk/core
- Loading branch information
Showing
58 changed files
with
1,742 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Ama SDK Angular Client | ||
|
||
[![Stable Version](https://img.shields.io/npm/v/@ama-sdk/client-angular?style=for-the-badge)](https://www.npmjs.com/package/@ama-sdk/client-angular) | ||
[![Bundle Size](https://img.shields.io/bundlephobia/min/@ama-sdk/client-angular?color=green&style=for-the-badge)](https://www.npmjs.com/package/@ama-sdk/client-angular) | ||
|
||
This package exposes the **Api Angular 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 [Angular Plugins](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-angular/src/plugins), helpers and object definitions to dialog with an API following the `ama-sdk` architecture. | ||
|
||
> [!TIP] | ||
> Please refer to the [SDK initializer](https://www.npmjs.com/package/@ama-sdk/create) package for getting started with an API client SDK based on `ama-sdk` architecture. | ||
## Setup | ||
|
||
The **Api Angular Client** can be added to your project via the following command: | ||
|
||
```shell | ||
ng add @ama-sdk/client-angular | ||
``` | ||
|
||
> [!NOTE] | ||
> In case of migration from deprecated `ApiAngularClient` imported from `@ama-sdk/core`, the `ng add` command will replace, in your existing code, the import from `@ama-sdk/core` to `@ama-sdk/client-angular` for the deprecated dependencies. | ||
## Available plugins | ||
|
||
- [mock-intercept](https://github.com/AmadeusITGroup/otter/tree/main/packages/%40ama-sdk/client-angular/src/plugins/mock-intercept) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Angular Client API to the project.", | ||
"factory": "./schematics/ng-add/index#ngAdd", | ||
"schema": "./schematics/ng-add/schema.json", | ||
"aliases": ["install", "i"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
{ | ||
"name": "@ama-sdk/client-angular", | ||
"version": "0.0.0-placeholder", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "Angular 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-angular", | ||
"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", | ||
"rxjs": "^7.8.1", | ||
"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 | ||
}, | ||
"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", | ||
"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", | ||
"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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"name": "ama-sdk-client-angular", | ||
"$schema": "https://raw.githubusercontent.com/nrwl/nx/master/packages/nx/schemas/project-schema.json", | ||
"projectType": "library", | ||
"sourceRoot": "packages/@ama-sdk/client-angular/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-angular/.eslintrc.js", | ||
"lintFilePatterns": [ | ||
"packages/@ama-sdk/client-angular/src/**/*.ts", | ||
"packages/@ama-sdk/client-angular/package.json" | ||
] | ||
}, | ||
"dependsOn": [ | ||
"build" | ||
] | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"options": { | ||
"jestConfig": "packages/@ama-sdk/client-angular/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-angular/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
13
packages/@ama-sdk/client-angular/schematics/ng-add/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
83 changes: 83 additions & 0 deletions
83
packages/@ama-sdk/client-angular/schematics/ng-add/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
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'; | ||
import { mapMigrationFromCoreImports } from './migration/import-map'; | ||
|
||
const devDependenciesToInstall: string[] = [ | ||
|
||
]; | ||
|
||
|
||
const reportMissingSchematicsDep = (logger: { error: (message: string) => any }) => (reason: any) => { | ||
logger.error(`[ERROR]: Adding @ama-sdk/client-angular has failed. | ||
If the error is related to missing @o3r dependencies you need to install '@o3r/schematics' as devDependency to be able to use this schematics. Please run 'ng add @o3r/schematics'. | ||
Otherwise, use the error message as guidance.`); | ||
throw reason; | ||
}; | ||
|
||
/** | ||
* Add SDk Angular Client 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, | ||
updateImports | ||
} = 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 | ||
}), | ||
|
||
updateImports(mapMigrationFromCoreImports) | ||
]); | ||
}; | ||
} | ||
|
||
/** | ||
* Add SDk Angular Client 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); | ||
}; |
Oops, something went wrong.