Please help, i spent 2 days trying simply to use Datastore of amplify. Am building NPM package to wrap an Amplify project backend. Auth works good but datastore not. Am testing code with ts-node and Jest. It is package so i do not have a framework.
When i call the save function it does not work and throw this warning:
[WARN] 24:08.886 DataStore - Data won't be synchronized. No GraphQL endpoint configured. Did you forget `Amplify.configure(awsconfig)`? {
config: {
authProviders: undefined,
maxRecordsToSync: 10000,
syncPageSize: 1000
}
}
My api endpoint is 100% correct, also the api-key. The backend works in another project built with react. But in my case (NPM package) it does not work.
The script am trying to run:
import { DataStore } from '@aws-amplify/datastore';
import { AccountDetails } from '@/models';
import { SignUp } from "@/Authentication/SignUp";
import InvalidAccountRequirementsException from "@/Exceptions/InvalidAccountRequirementsException";
import "@/app.config";
/**
* @name CreateAccount
* @description:
* build the correct pattern to check specific string type.
*
* @type function
* @param email
* @param password
* @param hasOwnCompany
* @param optInMarketingEmail
* @param tacAgreed
* @constructor
* @return {Promise<AccountDetails>}
*/
const CreateAccount = async (
email: string,
password: string,
hasOwnCompany: boolean,
optInMarketingEmail: boolean,
tacAgreed: boolean,
): Promise<AccountDetails> => {
if (!tacAgreed) {
throw new InvalidAccountRequirementsException('Terms and conditions mus be agreed');
}
const user = await SignUp(email, password);
return await DataStore.save(
new AccountDetails({
cognitoSubId: user.userSub,
email: email,
optInMarketingEmail: optInMarketingEmail,
tacAgreed: tacAgreed,
hasOwnCompany: hasOwnCompany,
})
);
}
export default CreateAccount;
app.conf.ts
import Amplify from 'aws-amplify';
import awsExports from '@/aws-exports';
Amplify.configure(awsExports);
package.json
{
"name": "@financiallease/driver-seat-amplify-api",
"version": "1.0.0",
"description": "",
"author": "itsupport@financiallease.nl",
"main": "dist/financiallease.cjs.js",
"module": "dist/financiallease.es.js",
"browser": "dist/financiallease.js",
"license": "ISC",
"scripts": {
"build": "rollup -c",
"lint": "eslint --config eslint.config.js '{src,test}/**/*.ts' --no-ignore",
"autoformat": "eslint --config eslint.config.js '{src,test}/**/*.ts' --no-ignore --fix",
"test": "jest -c jest.config.ts",
"coverage": "jest --collectCoverage --coverageDirectory=\"./coverage\" --ci --reporters=default --reporters=jest-junit --watchAll=false",
"docs:generate": "typedoc --readme README.md --entryPoints src --entryPointStrategy expand --out docs --theme hierarchy --name \"Driver Seat Amplify Api - docs\" --includeVersion",
"amplify-modelgen": "node amplify/scripts/amplify-modelgen.js",
"amplify-push": "node amplify/scripts/amplify-push.js"
},
"publishConfig": {
"@financiallease:registry": "https://gitlab.com/api/v4/projects/35071033/packages/npm/"
},
"dependencies": {
"@aws-amplify/core": "^4.5.1",
"@aws-amplify/datastore": "^3.11.0",
"@rollup/plugin-alias": "^3.1.9",
"aws-amplify": "^4.3.19",
"dotenv": "^16.0.0",
"ts-node": "^10.7.0",
"typescript": "^4.6.3"
},
"devDependencies": {
"@babel/core": "^7.17.9",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.16.7",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^21.0.3",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-typescript": "^8.3.1",
"@types/amplify": "^1.1.25",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.30",
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.0",
"babel-jest": "^28.0.3",
"babel-plugin-module-resolver": "^4.1.0",
"eslint": "^8.12.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-react": "^7.29.4",
"esm": "^3.2.25",
"jest": "^27.5.1",
"jest-junit": "^13.2.0",
"jsdoc": "^3.6.10",
"nodemon": "^2.0.16",
"rollup": "^2.70.1",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.1.4",
"tsconfig-paths": "^3.14.1",
"tslib": "^2.3.1",
"typedoc": "^0.22.15",
"typedoc-theme-hierarchy": "^1.1.1",
"ini": "^1.3.5",
"inquirer": "^6.5.1"
}
}
Any ideas?