diff --git a/generatePathMap.cjs.js b/generatePathMap.cjs.js
index d1562163a0a..dd57d679000 100644
--- a/generatePathMap.cjs.js
+++ b/generatePathMap.cjs.js
@@ -1,153 +1,156 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
-const fs = require("fs");
+const fs = require('fs');
function generatePathMap(
obj,
pathMap = {
- "/": {
- page: "/",
+ '/': {
+ page: '/'
},
- "/404": {
- page: "/404",
+ '/404': {
+ page: '/404'
},
- "/start": {
- page: "/start",
+ '/start': {
+ page: '/start'
},
- "/start/q/integration/js": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/js': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/react": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/react': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/angular": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/angular': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/vue": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/vue': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/next": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/next': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/android": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/android': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/react-native": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/react-native': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/ionic": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/ionic': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/ios": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/ios': {
+ page: '/start/q/integration/[integration]'
},
- "/start/q/integration/flutter": {
- page: "/start/q/integration/[integration]",
+ '/start/q/integration/flutter': {
+ page: '/start/q/integration/[integration]'
},
- "/lib/q/platform/flutter": {
- page: "/lib/q/platform/[platform]",
+ '/lib/q/platform/flutter': {
+ page: '/lib/q/platform/[platform]'
},
- "/lib/q/platform/android": {
- page: "/lib/q/platform/[platform]",
+ '/lib/q/platform/android': {
+ page: '/lib/q/platform/[platform]'
},
- "/lib/q/platform/ios": {
- page: "/lib/q/platform/[platform]",
+ '/lib/q/platform/ios': {
+ page: '/lib/q/platform/[platform]'
},
- "/lib/q/platform/js": {
- page: "/lib/q/platform/[platform]",
+ '/lib/q/platform/js': {
+ page: '/lib/q/platform/[platform]'
},
- "/ui/q/framework/react": {
- page: "/ui/q/framework/[framework]",
+ '/lib/q/platform/react-native': {
+ page: '/lib/q/platform/[platform]'
},
- "/ui/q/framework/react-native": {
- page: "/ui/q/framework/[framework]",
+ '/ui/q/framework/react': {
+ page: '/ui/q/framework/[framework]'
},
- "/ui/q/framework/angular": {
- page: "/ui/q/framework/[framework]",
+ '/ui/q/framework/react-native': {
+ page: '/ui/q/framework/[framework]'
},
- "/ui/q/framework/vue": {
- page: "/ui/q/framework/[framework]",
+ '/ui/q/framework/angular': {
+ page: '/ui/q/framework/[framework]'
},
- "/ui/q/framework/ionic": {
- page: "/ui/q/framework/[framework]",
+ '/ui/q/framework/vue': {
+ page: '/ui/q/framework/[framework]'
},
- "/ui/q/framework/flutter": {
- page: "/ui/q/framework/[framework]",
+ '/ui/q/framework/ionic': {
+ page: '/ui/q/framework/[framework]'
},
- "/ui/q/framework/next": {
- page: "/ui/q/framework/[framework]",
+ '/ui/q/framework/flutter': {
+ page: '/ui/q/framework/[framework]'
},
- "/ui-legacy/q/framework/react": {
- page: "/ui-legacy/q/framework/[framework]",
+ '/ui/q/framework/next': {
+ page: '/ui/q/framework/[framework]'
},
- "/ui-legacy/q/framework/react-native": {
- page: "/ui-legacy/q/framework/[framework]",
+ '/ui-legacy/q/framework/react': {
+ page: '/ui-legacy/q/framework/[framework]'
},
- "/ui-legacy/q/framework/angular": {
- page: "/ui-legacy/q/framework/[framework]",
+ '/ui-legacy/q/framework/react-native': {
+ page: '/ui-legacy/q/framework/[framework]'
},
- "/ui-legacy/q/framework/vue": {
- page: "/ui-legacy/q/framework/[framework]",
+ '/ui-legacy/q/framework/angular': {
+ page: '/ui-legacy/q/framework/[framework]'
},
- "/ui-legacy/q/framework/ionic": {
- page: "/ui-legacy/q/framework/[framework]",
+ '/ui-legacy/q/framework/vue': {
+ page: '/ui-legacy/q/framework/[framework]'
},
- "/ui-legacy/q/framework/next": {
- page: "/ui-legacy/q/framework/[framework]",
+ '/ui-legacy/q/framework/ionic': {
+ page: '/ui-legacy/q/framework/[framework]'
},
- "/sdk/q/platform/js": {
- page: "/sdk/q/platform/[platform]",
+ '/ui-legacy/q/framework/next': {
+ page: '/ui-legacy/q/framework/[framework]'
},
- "/sdk/q/platform/android": {
- page: "/sdk/q/platform/[platform]",
+ '/sdk/q/platform/js': {
+ page: '/sdk/q/platform/[platform]'
},
- "/sdk/q/platform/ios": {
- page: "/sdk/q/platform/[platform]",
+ '/sdk/q/platform/android': {
+ page: '/sdk/q/platform/[platform]'
},
- "/sdk/q/platform/flutter": {
- page: "/sdk/q/platform/[platform]",
+ '/sdk/q/platform/ios': {
+ page: '/sdk/q/platform/[platform]'
},
- "/console": {
- page: "/console",
+ '/sdk/q/platform/flutter': {
+ page: '/sdk/q/platform/[platform]'
},
- "/cli": {
- page: "/cli",
+ '/console': {
+ page: '/console'
},
- "/cli/function": {
- page: "/cli/function",
+ '/cli': {
+ page: '/cli'
},
- },
+ '/cli/function': {
+ page: '/cli/function'
+ }
+ }
) {
for (const [_, value] of Object.entries(obj)) {
- const {items, filters, route, productRoot} = value;
+ const { items, filters, route, productRoot } = value;
if (productRoot) {
- const {route} = productRoot;
+ const { route } = productRoot;
- let filterKind = "";
- if (route.startsWith("/cli") || route.startsWith("/console")) {
- filterKind = "";
- } else if (route.startsWith("/lib")) {
- filterKind = "platform";
- } else if (route.startsWith("/sdk")) {
- filterKind = "platform";
- } else if (route.startsWith("/ui")) {
- filterKind = "framework";
- } else if (route.startsWith("/guides")) {
- filterKind = "platform";
- } else if (route.startsWith("/start")) {
- filterKind = "integration";
+ let filterKind = '';
+ if (route.startsWith('/cli') || route.startsWith('/console')) {
+ filterKind = '';
+ } else if (route.startsWith('/lib')) {
+ filterKind = 'platform';
+ } else if (route.startsWith('/sdk')) {
+ filterKind = 'platform';
+ } else if (route.startsWith('/ui')) {
+ filterKind = 'framework';
+ } else if (route.startsWith('/guides')) {
+ filterKind = 'platform';
+ } else if (route.startsWith('/start')) {
+ filterKind = 'integration';
}
- if (filterKind !== "") {
- const aOrAn = "aeiou".includes(filterKind[0]) ? "an" : "a";
+ if (filterKind !== '') {
+ const aOrAn = 'aeiou'.includes(filterKind[0]) ? 'an' : 'a';
pathMap[route] = {
- page: "/ChooseFilterPage",
+ page: '/ChooseFilterPage',
query: {
address: route,
- directoryPath: "/ChooseFilterPage",
+ directoryPath: '/ChooseFilterPage',
filterKind: filterKind,
- message: `Choose ${aOrAn} ${filterKind}:`,
- },
+ message: `Choose ${aOrAn} ${filterKind}:`
+ }
};
}
}
@@ -157,12 +160,12 @@ function generatePathMap(
}
if (!filters || !filters.length) {
- let page = "";
+ let page = '';
const mdxSrc = `${route}.mdx`;
const tsxSrc = `${route}.tsx`;
- const maybeMDXFile = "./src/pages" + mdxSrc;
- const maybeTSXFile = "./src/pages" + tsxSrc;
+ const maybeMDXFile = './src/pages' + mdxSrc;
+ const maybeTSXFile = './src/pages' + tsxSrc;
if (fs.existsSync(maybeTSXFile)) {
page = tsxSrc;
@@ -172,18 +175,18 @@ function generatePathMap(
if (page.length) {
pathMap[route] = {
- page: route,
+ page: route
};
}
continue;
}
- let page = "";
- let routeType = "";
- ["platform", "framework", "integration"].forEach((type) => {
+ let page = '';
+ let routeType = '';
+ ['platform', 'framework', 'integration'].forEach((type) => {
const src = `${route}/q/${type}/[${type}].mdx`;
- const maybeFile = "./src/pages" + src;
+ const maybeFile = './src/pages' + src;
if (fs.existsSync(maybeFile)) {
page = src;
routeType = type;
@@ -197,35 +200,35 @@ function generatePathMap(
// generate for _all_ filters -- unsupported filters will just generate ChooseFilterPages, which is what we want
// ideally misspellings would also map to a ChooseFilterPage, but this doesn't work with SSG
let allFilters = filters;
- if (routeType !== "") {
+ if (routeType !== '') {
allFilters = [
- "js",
- "android",
- "ios",
- "flutter",
- "react",
- "react-native",
- "angular",
- "vue",
- "ionic",
- "next",
+ 'js',
+ 'android',
+ 'ios',
+ 'flutter',
+ 'react',
+ 'react-native',
+ 'angular',
+ 'vue',
+ 'ionic',
+ 'next'
];
}
allFilters.forEach((filter) => {
- pathMap[route + "/q/" + routeType + "/" + filter] = {
- page: `${route}/q/${routeType}/[${routeType}]`,
+ pathMap[route + '/q/' + routeType + '/' + filter] = {
+ page: `${route}/q/${routeType}/[${routeType}]`
};
});
- const aOrAn = "aeiou".includes(routeType[0]) ? "an" : "a";
+ const aOrAn = 'aeiou'.includes(routeType[0]) ? 'an' : 'a';
pathMap[route] = {
- page: "/ChooseFilterPage",
+ page: '/ChooseFilterPage',
query: {
address: route,
- directoryPath: "/ChooseFilterPage",
+ directoryPath: '/ChooseFilterPage',
filterKind: routeType,
filters: filters,
- message: `Choose ${aOrAn} ${routeType}:`,
- },
+ message: `Choose ${aOrAn} ${routeType}:`
+ }
};
}
return pathMap;
diff --git a/src/directory/directory.js b/src/directory/directory.js
index acb4b225c80..7bbbab8dca2 100644
--- a/src/directory/directory.js
+++ b/src/directory/directory.js
@@ -21,12 +21,12 @@ const directory = {
{
title: 'Prerequisites',
route: '/lib/project-setup/prereq',
- filters: ['android', 'ios', 'flutter']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Create your application',
route: '/lib/project-setup/create-application',
- filters: ['android', 'ios', 'flutter']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Null safety',
@@ -76,37 +76,52 @@ const directory = {
{
title: 'Getting started',
route: '/lib/analytics/getting-started',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Record events',
route: '/lib/analytics/record',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
+ },
+ {
+ title: 'Update Endpoint',
+ route: '/lib/analytics/update-endpoint',
+ filters: ['js', 'react-native']
},
{
title: 'Automatically track sessions',
route: '/lib/analytics/autotrack',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
+ },
+ {
+ title: 'Enable/Disable Analytics',
+ route: '/lib/analytics/enable-disable',
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Identify user',
route: '/lib/analytics/identifyuser',
- filters: ['android', 'flutter', 'ios']
+ filters: ['android', 'flutter', 'ios', 'react-native', 'js']
},
{
title: 'Streaming analytics data',
route: '/lib/analytics/streaming',
- filters: ['js']
+ filters: ['js', 'react-native']
+ },
+ {
+ title: 'Create a custom analytics plugin',
+ route: '/lib/analytics/create-custom-plugin',
+ filters: ['js', 'react-native']
},
{
title: 'Storing analytics data',
route: '/lib/analytics/storing',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Personalized recommendations',
route: '/lib/analytics/personalize',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Escape hatch',
@@ -116,7 +131,7 @@ const directory = {
{
title: 'Use existing AWS resources',
route: '/lib/analytics/existing-resources',
- filters: ['android', 'flutter', 'ios']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
}
]
},
@@ -126,62 +141,57 @@ const directory = {
{
title: 'Getting started',
route: '/lib/graphqlapi/getting-started',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Concepts',
route: '/lib/graphqlapi/concepts',
- filters: ['android', 'flutter', 'ios', 'js']
- },
- {
- title: 'Create or re-use existing backend',
- route: '/lib/graphqlapi/create-or-re-use-existing-backend',
- filters: ['js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Configure authorization modes',
route: '/lib/graphqlapi/authz',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Create, update, delete data',
route: '/lib/graphqlapi/mutate-data',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Fetch data',
route: '/lib/graphqlapi/query-data',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Subscribe to data',
route: '/lib/graphqlapi/subscribe-data',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Cancel API requests',
route: '/lib/graphqlapi/cancel-request',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Offline scenarios',
route: '/lib/graphqlapi/offline',
- filters: ['js']
+ filters: ['js', 'react-native', 'flutter', 'android', 'ios']
},
{
title: 'GraphQL from NodeJS',
route: '/lib/graphqlapi/graphql-from-nodejs',
- filters: ['js']
+ filters: ['js', 'react-native', 'react-native']
},
{
title: 'Advanced Workflows',
route: '/lib/graphqlapi/advanced-workflows',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Use existing AWS resources',
route: '/lib/graphqlapi/existing-resources',
- filters: ['android', 'flutter', 'ios']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
}
]
},
@@ -191,32 +201,32 @@ const directory = {
{
title: 'Getting started',
route: '/lib/restapi/getting-started',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Fetching data',
route: '/lib/restapi/fetch',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Updating data',
route: '/lib/restapi/update',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Deleting data',
route: '/lib/restapi/delete',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Cancel API requests',
route: '/lib/restapi/cancel',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Define authorization rules',
route: '/lib/restapi/authz',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Use existing AWS resources',
@@ -231,47 +241,47 @@ const directory = {
{
title: 'Getting started',
route: '/lib/auth/getting-started',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Create or re-use existing backend',
route: '/lib/auth/start',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Sign up, Sign in & Sign out',
route: '/lib/auth/emailpassword',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Social sign-in (OAuth)',
route: '/lib/auth/social',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Multi-factor authentication',
route: '/lib/auth/mfa',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Password & user management',
route: '/lib/auth/manageusers',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Switching authentication flows',
route: '/lib/auth/switch-auth',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Customize UI components',
route: '/lib/auth/customui',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Advanced workflows',
route: '/lib/auth/advanced',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Sign in',
@@ -311,7 +321,7 @@ const directory = {
{
title: 'Auth events',
route: '/lib/auth/auth-events',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'User attributes',
@@ -321,7 +331,7 @@ const directory = {
{
title: 'Remember a device',
route: '/lib/auth/device_features',
- filters: ['android', 'ios', 'js', 'flutter']
+ filters: ['android', 'ios', 'js', 'flutter', 'react-native']
},
{
title: 'Password management',
@@ -346,7 +356,7 @@ const directory = {
{
title: 'Delete user',
route: '/lib/auth/delete_user',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Escape hatch',
@@ -356,7 +366,7 @@ const directory = {
{
title: 'Under the hood',
route: '/lib/auth/overview',
- filters: ['android', 'ios', 'js']
+ filters: ['android', 'ios', 'js', 'react-native']
},
{
title: 'Use existing Amazon Cognito resources',
@@ -371,62 +381,62 @@ const directory = {
{
title: 'Getting started',
route: '/lib/datastore/getting-started',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Manipulating data',
route: '/lib/datastore/data-access',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Relational models',
route: '/lib/datastore/relational',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Syncing data to cloud',
route: '/lib/datastore/sync',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Setup authorization rules',
route: '/lib/datastore/setup-auth-rules',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Conflict resolution',
route: '/lib/datastore/conflict',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Real time',
route: '/lib/datastore/real-time',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'DataStore Events',
route: '/lib/datastore/datastore-events',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Other methods',
route: '/lib/datastore/other-methods',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Schema updates',
route: '/lib/datastore/schema-updates',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'How it works',
route: '/lib/datastore/how-it-works',
- filters: ['android', 'flutter', 'ios', 'js']
+ filters: ['android', 'flutter', 'ios', 'js', 'react-native']
},
{
title: 'Examples',
route: '/lib/datastore/examples',
- filters: ['js']
+ filters: ['js', 'react-native']
}
]
},
@@ -476,57 +486,57 @@ const directory = {
{
title: 'Overview',
route: '/lib/in-app-messaging/overview',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Prerequisites',
route: '/lib/in-app-messaging/prerequisites',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Create an In-App Messaging campaign',
route: '/lib/in-app-messaging/create-campaign',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Getting started',
route: '/lib/in-app-messaging/getting-started',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Sync messages',
route: '/lib/in-app-messaging/sync-messages',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Display message',
route: '/lib/in-app-messaging/display-message',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Clear messages',
route: '/lib/in-app-messaging/clear-messages',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Customize your UI',
route: '/lib/in-app-messaging/customize',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Identify a user',
route: '/lib/in-app-messaging/identify-user',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Respond to interaction events',
route: '/lib/in-app-messaging/respond-interaction-events',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Resolving conflicts',
route: '/lib/in-app-messaging/resolve-conflicts',
- filters: ['js']
+ filters: ['react-native']
}
]
},
@@ -536,62 +546,63 @@ const directory = {
{
title: 'Getting started',
route: '/lib/interactions/getting-started',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Interact with bots',
route: '/lib/interactions/chatbot',
- filters: ['js']
+ filters: ['js', 'react-native']
}
]
},
predictions: {
title: 'Predictions',
items: [
+ // TODO Rewrite why do we have an intro for RN and JS and not iOS/Android?
{
title: 'Overview',
route: '/lib/predictions/intro',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Getting started',
route: '/lib/predictions/getting-started',
- filters: ['android', 'ios', 'js']
+ filters: ['android', 'ios', 'js', 'react-native']
},
{
title: 'Text to speech',
route: '/lib/predictions/text-speech',
- filters: ['android', 'ios', 'js']
+ filters: ['android', 'ios', 'js', 'react-native']
},
{
title: 'Transcribe audio to text',
route: '/lib/predictions/transcribe',
- filters: ['ios', 'js']
+ filters: ['ios', 'js', 'react-native']
},
{
title: 'Translate language',
route: '/lib/predictions/translate',
- filters: ['android', 'ios', 'js']
+ filters: ['android', 'ios', 'js', 'react-native']
},
{
title: 'Identify text',
route: '/lib/predictions/identify-text',
- filters: ['android', 'ios', 'js']
+ filters: ['android', 'ios', 'js', 'react-native']
},
{
title: 'Identify entities from images',
route: '/lib/predictions/identify-entity',
- filters: ['android', 'ios', 'js']
+ filters: ['android', 'ios', 'js', 'react-native']
},
{
title: 'Label objects in image',
route: '/lib/predictions/label-image',
- filters: ['android', 'ios', 'js']
+ filters: ['android', 'ios', 'js', 'react-native']
},
{
title: 'Interpret sentiment',
route: '/lib/predictions/interpret',
- filters: ['android', 'ios', 'js']
+ filters: ['android', 'ios', 'js', 'react-native']
},
{
title: 'Escape hatch',
@@ -601,7 +612,7 @@ const directory = {
{
title: 'Example',
route: '/lib/predictions/sample',
- filters: ['js']
+ filters: ['js', 'react-native']
}
]
},
@@ -611,14 +622,18 @@ const directory = {
{
title: 'Getting started',
route: '/lib/pubsub/getting-started',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Subscribe & Unsubscribe',
route: '/lib/pubsub/subunsub',
- filters: ['js']
+ filters: ['js', 'react-native']
},
- { title: 'Publish', route: '/lib/pubsub/publish', filters: ['js'] }
+ {
+ title: 'Publish',
+ route: '/lib/pubsub/publish',
+ filters: ['js', 'react-native']
+ }
]
},
'push-notifications': {
@@ -627,22 +642,22 @@ const directory = {
{
title: 'Overview',
route: '/lib/push-notifications/overview',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Getting started',
route: '/lib/push-notifications/getting-started',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Working with API',
route: '/lib/push-notifications/working-with-api',
- filters: ['js']
+ filters: ['react-native']
},
{
title: 'Testing',
route: '/lib/push-notifications/testing',
- filters: ['js']
+ filters: ['react-native']
}
]
},
@@ -652,57 +667,62 @@ const directory = {
{
title: 'Getting started',
route: '/lib/storage/getting-started',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Concepts',
route: '/lib/storage/overview',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Upload files',
route: '/lib/storage/upload',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Download files',
route: '/lib/storage/download',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'List files',
route: '/lib/storage/list',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Copy files',
route: '/lib/storage/copy',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Remove files',
route: '/lib/storage/remove',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
title: 'Cancel requests',
route: '/lib/storage/cancel-requests',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'File access levels',
route: '/lib/storage/configureaccess',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
},
{
- title: 'Automatically track events',
+ title: 'Automatically track Storage events',
route: '/lib/storage/autotrack',
- filters: ['js']
+ filters: ['js', 'react-native']
},
{
title: 'Lambda triggers',
route: '/lib/storage/triggers',
- filters: ['android', 'ios', 'flutter', 'js']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
+ },
+ {
+ title: 'Custom Plugin',
+ route: '/lib/storage/custom-plugin',
+ filters: ['js', 'react-native']
},
{
title: 'Escape hatch',
@@ -712,7 +732,7 @@ const directory = {
{
title: 'Use existing AWS resources',
route: '/lib/storage/existing-resources',
- filters: ['android', 'ios', 'flutter']
+ filters: ['android', 'ios', 'flutter', 'js', 'react-native']
}
]
},
@@ -724,25 +744,38 @@ const directory = {
route: '/lib/xr/getting-started',
filters: ['js']
},
- { title: 'Scene API', route: '/lib/xr/sceneapi', filters: ['js'] }
+ {
+ title: 'Scene API',
+ route: '/lib/xr/sceneapi',
+ filters: ['js']
+ }
]
},
utilities: {
title: 'Utilities',
items: [
+ // TODO Rewrite do we have service workers for React native?
{
title: 'Service Worker',
route: '/lib/utilities/serviceworker',
filters: ['js']
},
{ title: 'Cache', route: '/lib/utilities/cache', filters: ['js'] },
- { title: 'Hub', route: '/lib/utilities/hub', filters: ['android', 'ios', 'js'] },
+ {
+ title: 'Hub',
+ route: '/lib/utilities/hub',
+ filters: ['android', 'ios', 'js', 'react-native']
+ },
{
title: 'Internationalization',
route: '/lib/utilities/i18n',
- filters: ['js']
+ filters: ['js', 'react-native']
},
- { title: 'Logger', route: '/lib/utilities/logger', filters: ['js'] }
+ {
+ title: 'Logger',
+ route: '/lib/utilities/logger',
+ filters: ['js', 'react-native']
+ }
]
},
'client-configuration': {
@@ -751,7 +784,7 @@ const directory = {
{
title: 'Configuring Amplify Categories',
route: '/lib/client-configuration/configuring-amplify-categories',
- filters: ['js']
+ filters: ['js', 'react-native']
}
]
},
@@ -796,12 +829,12 @@ const directory = {
{
title: 'Upgrading Amplify packages',
route: '/lib/troubleshooting/upgrading',
- filters: ['flutter', 'js']
+ filters: ['flutter', 'js', 'react-native']
},
{
title: 'TypeScript strict mode',
route: '/lib/troubleshooting/strict-mode',
- filters: ['js']
+ filters: ['js', 'react-native']
}
]
}
@@ -1759,8 +1792,8 @@ const directory = {
route: '/console/uibuilder/collections'
},
{
- title: 'Component slots',
- route: '/console/uibuilder/slots'
+ title: 'Component slots',
+ route: '/console/uibuilder/slots'
},
{
title: 'Theming',
@@ -2054,4 +2087,4 @@ const directory = {
}
};
-module.exports = directory;
\ No newline at end of file
+module.exports = directory;
diff --git a/src/fragments/lib/analytics/android/enable-disable/disable.mdx b/src/fragments/lib/analytics/android/enable-disable/disable.mdx
new file mode 100644
index 00000000000..01efae27a7b
--- /dev/null
+++ b/src/fragments/lib/analytics/android/enable-disable/disable.mdx
@@ -0,0 +1,23 @@
+
+
+
+```java
+Amplify.Analytics.disable();
+```
+
+
+
+
+```kotlin
+Amplify.Analytics.disable()
+```
+
+
+
+
+```java
+RxAmplify.Analytics.disable();
+```
+
+
+
\ No newline at end of file
diff --git a/src/fragments/lib/analytics/android/enable-disable/enable.mdx b/src/fragments/lib/analytics/android/enable-disable/enable.mdx
new file mode 100644
index 00000000000..688a3611dac
--- /dev/null
+++ b/src/fragments/lib/analytics/android/enable-disable/enable.mdx
@@ -0,0 +1,23 @@
+
+
+
+```java
+Amplify.Analytics.enable();
+```
+
+
+
+
+```kotlin
+Amplify.Analytics.enable()
+```
+
+
+
+
+```java
+RxAmplify.Analytics.enable();
+```
+
+
+
\ No newline at end of file
diff --git a/src/fragments/lib/analytics/existing-resources.mdx b/src/fragments/lib/analytics/android/existing-resources.mdx
similarity index 98%
rename from src/fragments/lib/analytics/existing-resources.mdx
rename to src/fragments/lib/analytics/android/existing-resources.mdx
index 4a965220e83..47df86825f1 100644
--- a/src/fragments/lib/analytics/existing-resources.mdx
+++ b/src/fragments/lib/analytics/android/existing-resources.mdx
@@ -1,6 +1,6 @@
Existing Amazon Pinpoint resources can be used with the Amplify Libraries by referencing your **Application ID** and **Region** in your `amplifyconfiguration.json` file.
-```dart
+```json
{
"analytics": {
"plugins": {
@@ -24,4 +24,4 @@ Existing Amazon Pinpoint resources can be used with the Amplify Libraries by ref
- **pinpointTargeting**
- **region**: AWS Region where the resources are provisioned (e.g. `us-east-1`)
-Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see [Install Amplify Libraries](/lib/project-setup/create-application#n2-install-amplify-libraries).
+Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see [Install Amplify Libraries](/lib/project-setup/create-application#n2-install-amplify-libraries).
diff --git a/src/fragments/lib/analytics/android/record.mdx b/src/fragments/lib/analytics/android/record.mdx
index 9306f3b8824..ff3413eac0d 100644
--- a/src/fragments/lib/analytics/android/record.mdx
+++ b/src/fragments/lib/analytics/android/record.mdx
@@ -162,61 +162,4 @@ RxAmplify.Analytics.unregisterGlobalProperties("AppStyle", "OtherProperty");
```
-
-
-## Disable Analytics
-
-To disable analytics, call:
-
-
-
-
-```java
-Amplify.Analytics.disable();
-```
-
-
-
-
-```kotlin
-Amplify.Analytics.disable()
-```
-
-
-
-
-```java
-RxAmplify.Analytics.disable();
-```
-
-
-
-
-## Enable Analytics
-
-To re-enable, call:
-
-
-
-
-```java
-Amplify.Analytics.enable();
-```
-
-
-
-
-```kotlin
-Amplify.Analytics.enable()
-```
-
-
-
-
-```java
-RxAmplify.Analytics.enable();
-```
-
-
-
-
+
\ No newline at end of file
diff --git a/src/fragments/lib/analytics/flutter/enable-disable/disable.mdx b/src/fragments/lib/analytics/flutter/enable-disable/disable.mdx
new file mode 100644
index 00000000000..b2a99161630
--- /dev/null
+++ b/src/fragments/lib/analytics/flutter/enable-disable/disable.mdx
@@ -0,0 +1,3 @@
+```dart
+Amplify.Analytics.disable();
+```
diff --git a/src/fragments/lib/analytics/flutter/enable-disable/enable.mdx b/src/fragments/lib/analytics/flutter/enable-disable/enable.mdx
new file mode 100644
index 00000000000..6eb1405d78f
--- /dev/null
+++ b/src/fragments/lib/analytics/flutter/enable-disable/enable.mdx
@@ -0,0 +1,3 @@
+```dart
+Amplify.Analytics.enable();
+```
diff --git a/src/fragments/lib/analytics/flutter/existing-resources.mdx b/src/fragments/lib/analytics/flutter/existing-resources.mdx
new file mode 100644
index 00000000000..7c52ceac435
--- /dev/null
+++ b/src/fragments/lib/analytics/flutter/existing-resources.mdx
@@ -0,0 +1,27 @@
+Existing Amazon Pinpoint resources can be used with the Amplify Libraries by referencing your **Application ID** and **Region** in your `amplifyconfiguration.dart` file.
+
+```dart
+{
+ "analytics": {
+ "plugins": {
+ "awsPinpointAnalyticsPlugin": {
+ "pinpointAnalytics": {
+ "appId": "[APP ID]",
+ "region": "[REGION]"
+ },
+ "pinpointTargeting": {
+ "region": "[REGION]"
+ }
+ }
+ }
+ }
+}
+```
+
+- **pinpointAnalytics**
+ - **appId**: Amazon Pinpoint application ID
+ - **region**: AWS Region where the resources are provisioned (e.g. `us-east-1`)
+- **pinpointTargeting**
+ - **region**: AWS Region where the resources are provisioned (e.g. `us-east-1`)
+
+Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see [Install Amplify Libraries](/lib/project-setup/create-application#n2-install-amplify-libraries).
diff --git a/src/fragments/lib/analytics/flutter/record.mdx b/src/fragments/lib/analytics/flutter/record.mdx
index 17dccdcb498..b3ce7c3e8e2 100644
--- a/src/fragments/lib/analytics/flutter/record.mdx
+++ b/src/fragments/lib/analytics/flutter/record.mdx
@@ -24,22 +24,22 @@ Events have default configuration to flush out to the network every 30 seconds.
```json
{
- "UserAgent": "aws-amplify-cli/2.0",
- "Version": "1.0",
- "analytics": {
- "plugins": {
- "awsPinpointAnalyticsPlugin": {
- "pinpointAnalytics": {
- "appId": "AppID",
- "region": "Region"
- },
- "pinpointTargeting": {
- "region": "Region"
- },
- "autoFlushEventsInterval": 10000
- }
- }
+ "UserAgent": "aws-amplify-cli/2.0",
+ "Version": "1.0",
+ "analytics": {
+ "plugins": {
+ "awsPinpointAnalyticsPlugin": {
+ "pinpointAnalytics": {
+ "appId": "AppID",
+ "region": "Region"
+ },
+ "pinpointTargeting": {
+ "region": "Region"
+ },
+ "autoFlushEventsInterval": 10000
+ }
}
+ }
}
```
@@ -70,20 +70,3 @@ Future unregisterGlobalProperties() async {
);
}
```
-
-## Disable Analytics
-
-To disable analytics, call:
-
-```dart
-Amplify.Analytics.disable();
-```
-
-## Enable Analytics
-
-To re-enable, call:
-
-```dart
-Amplify.Analytics.enable();
-```
-
diff --git a/src/fragments/lib/analytics/ios/enable-disable/disable.mdx b/src/fragments/lib/analytics/ios/enable-disable/disable.mdx
new file mode 100644
index 00000000000..6a4e3fb69a7
--- /dev/null
+++ b/src/fragments/lib/analytics/ios/enable-disable/disable.mdx
@@ -0,0 +1,3 @@
+```swift
+Amplify.Analytics.disable()
+```
diff --git a/src/fragments/lib/analytics/ios/enable-disable/enable.mdx b/src/fragments/lib/analytics/ios/enable-disable/enable.mdx
new file mode 100644
index 00000000000..eb0ac5acabe
--- /dev/null
+++ b/src/fragments/lib/analytics/ios/enable-disable/enable.mdx
@@ -0,0 +1,3 @@
+```swift
+Amplify.Analytics.enable()
+```
diff --git a/src/fragments/lib/analytics/ios/existing-resources.mdx b/src/fragments/lib/analytics/ios/existing-resources.mdx
new file mode 100644
index 00000000000..49b1e4f24fb
--- /dev/null
+++ b/src/fragments/lib/analytics/ios/existing-resources.mdx
@@ -0,0 +1,29 @@
+Existing Amazon Pinpoint resources can be used with the Amplify Libraries by referencing your **Application ID** and **Region** in your `amplifyconfiguration.json` file.
+
+
+
+```json
+{
+ "analytics": {
+ "plugins": {
+ "awsPinpointAnalyticsPlugin": {
+ "pinpointAnalytics": {
+ "appId": "[APP ID]",
+ "region": "[REGION]"
+ },
+ "pinpointTargeting": {
+ "region": "[REGION]"
+ }
+ }
+ }
+ }
+}
+```
+
+- **pinpointAnalytics**
+ - **appId**: Amazon Pinpoint application ID
+ - **region**: AWS Region where the resources are provisioned (e.g. `us-east-1`)
+- **pinpointTargeting**
+ - **region**: AWS Region where the resources are provisioned (e.g. `us-east-1`)
+
+Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see [Install Amplify Libraries](/lib/project-setup/create-application#n2-install-amplify-libraries).
diff --git a/src/fragments/lib/analytics/ios/record.mdx b/src/fragments/lib/analytics/ios/record.mdx
index 4d99feb7355..08c46250aa8 100644
--- a/src/fragments/lib/analytics/ios/record.mdx
+++ b/src/fragments/lib/analytics/ios/record.mdx
@@ -21,22 +21,22 @@ Events have default configuration to flush out to the network every 60 seconds.
```json
{
- "UserAgent": "aws-amplify-cli/2.0",
- "Version": "1.0",
- "analytics": {
- "plugins": {
- "awsPinpointAnalyticsPlugin": {
- "pinpointAnalytics": {
- "appId": "AppID",
- "region": "Region"
- },
- "pinpointTargeting": {
- "region": "Region"
- },
- "autoFlushEventsInterval": 60
- }
- }
+ "UserAgent": "aws-amplify-cli/2.0",
+ "Version": "1.0",
+ "analytics": {
+ "plugins": {
+ "awsPinpointAnalyticsPlugin": {
+ "pinpointAnalytics": {
+ "appId": "AppID",
+ "region": "Region"
+ },
+ "pinpointTargeting": {
+ "region": "Region"
+ },
+ "autoFlushEventsInterval": 60
+ }
}
+ }
}
```
@@ -60,19 +60,3 @@ Amplify.Analytics.unregisterGlobalProperties()
// or you can specify properties to unregister
Amplify.Analytics.unregisterGlobalProperties(["globalPropertyKey1", "globalPropertyKey2"])
```
-
-## Disable Analytics
-
-Analytics are sent to the backend automatically (i.e. it's enabled by default). To disable it call:
-
-```swift
-Amplify.Analytics.disable()
-```
-
-## Enable Analytics
-
-To re-enable it call:
-
-```swift
-Amplify.Analytics.enable()
-```
diff --git a/src/fragments/lib/analytics/js/autotrack.mdx b/src/fragments/lib/analytics/js/autotrack.mdx
deleted file mode 100644
index ab2a9f7ca2e..00000000000
--- a/src/fragments/lib/analytics/js/autotrack.mdx
+++ /dev/null
@@ -1,157 +0,0 @@
-Analytics Auto Tracking helps you to automatically track user behaviors like sessions start/stop, page view change and web events like clicking, mouseover.
-
-## Session Tracking
-
-You can track the session both in a web app or a React Native app by using Analytics. A web session can be defined in different ways. To keep it simple we define that the web session is active when the page is not hidden and inactive when the page is hidden.
-A session in the React Native app is active when the app is in the foreground and inactive when the app is in the background.
-
-For example:
-```javascript
-Analytics.autoTrack('session', {
- // REQUIRED, turn on/off the auto tracking
- enable: true,
- // OPTIONAL, the attributes of the event, you can either pass an object or a function
- // which allows you to define dynamic attributes
- attributes: {
- attr: 'attr'
- },
- // when using function
- // attributes: () => {
- // const attr = somewhere();
- // return {
- // myAttr: attr
- // }
- // },
- // OPTIONAL, the service provider, by default is the Amazon Pinpoint
- provider: 'AWSPinpoint'
-});
-```
-
-When the page is loaded, the Analytics module will send an event to the Amazon Pinpoint Service.
-```javascript
-{
- eventType: '_session_start',
- attributes: {
- attr: 'attr'
- }
-}
-```
-
-To keep backward compatibility, the auto tracking of the session is enabled by default. You can turn it off by:
-```javascript
-Analytics.configure({
- // OPTIONAL - Allow recording session events. Default is true.
- autoSessionRecord: false,
-});
-```
-or
-```javascript
-Analytics.autoTrack('session', {
- enable: false
-});
-
-// Note: this must be called before Amplify.configure() or Analytics.configure() to cancel the session_start event
-```
-
-## Page View Tracking
-
-If you want to track which page/url in your webapp is the most frequently viewed one, you can use this feature. It will automatically send events containing url information when the page is visited.
-
-To turn it on:
-```javascript
-Analytics.autoTrack('pageView', {
- // REQUIRED, turn on/off the auto tracking
- enable: true,
- // OPTIONAL, the event name, by default is 'pageView'
- eventName: 'pageView',
- // OPTIONAL, the attributes of the event, you can either pass an object or a function
- // which allows you to define dynamic attributes
- attributes: {
- attr: 'attr'
- },
- // when using function
- // attributes: () => {
- // const attr = somewhere();
- // return {
- // myAttr: attr
- // }
- // },
- // OPTIONAL, by default is 'multiPageApp'
- // you need to change it to 'SPA' if your app is a single-page app like React
- type: 'multiPageApp',
- // OPTIONAL, the service provider, by default is the Amazon Pinpoint
- provider: 'AWSPinpoint',
- // OPTIONAL, to get the current page url
- getUrl: () => {
- // the default function
- return window.location.origin + window.location.pathname;
- }
-});
-```
-Note: This is not supported in React Native.
-
-## Page Event Tracking
-
-If you want to track user interactions with elements on the page, you can use this feature. All you need to do is attach the specified selectors to your dom element and turn on the auto tracking.
-
-To turn it on:
-```javascript
-Analytics.autoTrack('event', {
- // REQUIRED, turn on/off the auto tracking
- enable: true,
- // OPTIONAL, events you want to track, by default is 'click'
- events: ['click'],
- // OPTIONAL, the prefix of the selectors, by default is 'data-amplify-analytics-'
- // in order to avoid collision with the user agent, according to https://www.w3schools.com/tags/att_global_data.asp
- // always put 'data' as the first prefix
- selectorPrefix: 'data-amplify-analytics-',
- // OPTIONAL, the service provider, by default is the Amazon Pinpoint
- provider: 'AWSPinpoint',
- // OPTIONAL, the default attributes of the event, you can either pass an object or a function
- // which allows you to define dynamic attributes
- attributes: {
- attr: 'attr'
- }
- // when using function
- // attributes: () => {
- // const attr = somewhere();
- // return {
- // myAttr: attr
- // }
- // }
-});
-```
-
-For example:
-```html
-
-
-```
-When the button above is clicked, an event will be sent automatically and this is equivalent to do:
-```html
-
-
-```
-Note: This is not supported in React Native.
-
-
-
-Note: Amplify doesn't capture the location automatically. Instead you can add the location information, in the default config when you [configure Analytics](https://docs.amplify.aws/lib/analytics/getting-started/q/platform/js#set-up-existing-analytics-backend) or while [updating the end point](https://docs.amplify.aws/lib/analytics/getting-started/q/platform/js#update-endpoint).
-
-
-
diff --git a/src/fragments/lib/analytics/js/autotrack/autotrack.mdx b/src/fragments/lib/analytics/js/autotrack/autotrack.mdx
new file mode 100644
index 00000000000..caba8bbd260
--- /dev/null
+++ b/src/fragments/lib/analytics/js/autotrack/autotrack.mdx
@@ -0,0 +1,64 @@
+Analytics Auto Tracking helps you to automatically track user behaviors like sessions start/stop, page view change and web events like clicking or mouseover.
+
+## Session Tracking
+
+You can track the session both in a web app or a React Native app by using Analytics. A web session can be defined in different ways. To keep it simple we define a web session as being active when the page is not hidden and inactive when the page is hidden.
+A session in a React Native app is active when the app is in the foreground and inactive when the app is in the background.
+
+For example:
+```javascript
+Analytics.autoTrack('session', {
+ // REQUIRED, turn on/off the auto tracking
+ enable: true,
+ // OPTIONAL, the attributes of the event, you can either pass an object or a function
+ // which allows you to define dynamic attributes
+ attributes: {
+ attr: 'attr'
+ },
+ // when using function
+ // attributes: () => {
+ // const attr = somewhere();
+ // return {
+ // myAttr: attr
+ // }
+ // },
+ // OPTIONAL, the service provider, by default is the Amazon Pinpoint
+ provider: 'AWSPinpoint'
+});
+```
+
+When the page is loaded, the Analytics module will send an event to the Amazon Pinpoint Service.
+```javascript
+{
+ eventType: '_session_start',
+ attributes: {
+ attr: 'attr'
+ }
+}
+```
+
+To keep backward compatibility, the auto tracking of the session is enabled by default. You can turn it off by:
+```javascript
+Analytics.configure({
+ // OPTIONAL - Allow recording session events. Default is true.
+ autoSessionRecord: false,
+});
+```
+or
+```javascript
+Analytics.autoTrack('session', {
+ enable: false
+});
+
+// Note: this must be called before Amplify.configure() or Analytics.configure() to cancel the session_start event
+```
+
+import js0 from '/src/fragments/lib/analytics/js/autotrack/page-tracking.mdx';
+
+
+
+
+
+Note: Amplify doesn't capture the location automatically. Instead, you can add the location information in the default config when you [configure Analytics](https://docs.amplify.aws/lib/analytics/getting-started/q/platform/js#set-up-existing-analytics-backend) or while [updating the end point](https://docs.amplify.aws/lib/analytics/getting-started/q/platform/js#update-endpoint).
+
+
\ No newline at end of file
diff --git a/src/fragments/lib/analytics/js/autotrack/page-tracking.mdx b/src/fragments/lib/analytics/js/autotrack/page-tracking.mdx
new file mode 100644
index 00000000000..e584866b2f4
--- /dev/null
+++ b/src/fragments/lib/analytics/js/autotrack/page-tracking.mdx
@@ -0,0 +1,98 @@
+## Page View Tracking
+
+If you want to track which page/url in your webapp is the most frequently viewed one, you can use this feature. It will automatically send events containing url information when the page is visited.
+
+To turn it on:
+
+```javascript
+Analytics.autoTrack('pageView', {
+ // REQUIRED, turn on/off the auto tracking
+ enable: true,
+ // OPTIONAL, the event name, by default is 'pageView'
+ eventName: 'pageView',
+ // OPTIONAL, the attributes of the event, you can either pass an object or a function
+ // which allows you to define dynamic attributes
+ attributes: {
+ attr: 'attr'
+ },
+ // when using function
+ // attributes: () => {
+ // const attr = somewhere();
+ // return {
+ // myAttr: attr
+ // }
+ // },
+ // OPTIONAL, by default is 'multiPageApp'
+ // you need to change it to 'SPA' if your app is a single-page app like React
+ type: 'multiPageApp',
+ // OPTIONAL, the service provider, by default is the Amazon Pinpoint
+ provider: 'AWSPinpoint',
+ // OPTIONAL, to get the current page url
+ getUrl: () => {
+ // the default function
+ return window.location.origin + window.location.pathname;
+ }
+});
+```
+
+## Page Event Tracking
+
+If you want to track user interactions with elements on the page, you can use this feature. All you need to do is attach the specified selectors to your dom element and turn on the auto tracking.
+
+To turn it on:
+
+```javascript
+Analytics.autoTrack('event', {
+ // REQUIRED, turn on/off the auto tracking
+ enable: true,
+ // OPTIONAL, events you want to track, by default is 'click'
+ events: ['click'],
+ // OPTIONAL, the prefix of the selectors, by default is 'data-amplify-analytics-'
+ // in order to avoid collision with the user agent, according to https://www.w3schools.com/tags/att_global_data.asp
+ // always put 'data' as the first prefix
+ selectorPrefix: 'data-amplify-analytics-',
+ // OPTIONAL, the service provider, by default is the Amazon Pinpoint
+ provider: 'AWSPinpoint',
+ // OPTIONAL, the default attributes of the event, you can either pass an object or a function
+ // which allows you to define dynamic attributes
+ attributes: {
+ attr: 'attr'
+ }
+ // when using function
+ // attributes: () => {
+ // const attr = somewhere();
+ // return {
+ // myAttr: attr
+ // }
+ // }
+});
+```
+
+For example:
+
+```html
+
+
+```
+
+When the button above is clicked, an event will be sent automatically. This is equivalent to doing:
+
+```html
+
+
+```
diff --git a/src/fragments/lib/analytics/js/create-custom-plugin.mdx b/src/fragments/lib/analytics/js/create-custom-plugin.mdx
new file mode 100644
index 00000000000..415be94ad05
--- /dev/null
+++ b/src/fragments/lib/analytics/js/create-custom-plugin.mdx
@@ -0,0 +1,48 @@
+You can create your custom pluggable for Analytics. This may be helpful if you want to integrate your app with a custom analytics backend.
+
+To create a plugin implement the `AnalyticsProvider` interface:
+
+```typescript
+import { Analytics, AnalyticsProvider } from 'aws-amplify';
+
+export default class MyAnalyticsProvider implements AnalyticsProvider {
+ // category and provider name
+ static category = 'Analytics';
+ static providerName = 'MyAnalytics';
+
+ // you need to implement these four methods
+ // configure your provider
+ configure(config: object): object;
+
+ // record events and returns true if succeeds
+ record(params: object): Promise;
+
+ // return 'Analytics';
+ getCategory(): string;
+
+ // return the name of you provider
+ getProviderName(): string;
+}
+```
+
+You can now register your pluggable:
+
+```javascript
+// add the plugin
+Analytics.addPluggable(new MyAnalyticsProvider());
+
+// get the plugin
+Analytics.getPluggable(MyAnalyticsProvider.providerName);
+
+// remove the plugin
+Analytics.removePluggable(MyAnalyticsProvider.providerName);
+
+// send configuration into Amplify
+Analytics.configure({
+ MyAnalyticsProvider: {
+ // My Analytics provider configuration
+ }
+});
+```
+
+The default provider (Amazon Pinpoint) is in use when you call `Analytics.record()` unless you specify a different provider: `Analytics.record({..},'MyAnalytics')`.
diff --git a/src/fragments/lib/analytics/js/enable-disable/disable.mdx b/src/fragments/lib/analytics/js/enable-disable/disable.mdx
new file mode 100644
index 00000000000..7f153befbdc
--- /dev/null
+++ b/src/fragments/lib/analytics/js/enable-disable/disable.mdx
@@ -0,0 +1,4 @@
+```javascript
+// to disable Analytics
+Analytics.disable();
+```
diff --git a/src/fragments/lib/analytics/js/enable-disable/enable.mdx b/src/fragments/lib/analytics/js/enable-disable/enable.mdx
new file mode 100644
index 00000000000..64f05f9c9fd
--- /dev/null
+++ b/src/fragments/lib/analytics/js/enable-disable/enable.mdx
@@ -0,0 +1,4 @@
+```javascript
+// to enable Analytics
+Analytics.enable();
+```
diff --git a/src/fragments/lib/analytics/js/existing-resources.mdx b/src/fragments/lib/analytics/js/existing-resources.mdx
new file mode 100644
index 00000000000..00ad34e5b27
--- /dev/null
+++ b/src/fragments/lib/analytics/js/existing-resources.mdx
@@ -0,0 +1,105 @@
+## Set up existing analytics backend
+
+The manual setup enables you to use your existing Amazon Pinpoint resource in your app.
+
+```javascript
+import { Amplify } from 'aws-amplify';
+
+Amplify.configure({
+ // To get the AWS Credentials, you need to configure
+ // the Auth module with your Cognito Federated Identity Pool
+ Auth: {
+ identityPoolId: 'us-east-1:xxx-xxx-xxx-xxx-xxx',
+ region: 'us-east-1'
+ },
+ Analytics: {
+ // OPTIONAL - disable Analytics if true
+ disabled: false,
+ // OPTIONAL - Allow recording session events. Default is true.
+ autoSessionRecord: true,
+
+ AWSPinpoint: {
+ // OPTIONAL - Amazon Pinpoint App Client ID
+ appId: 'XXXXXXXXXXabcdefghij1234567890ab',
+ // OPTIONAL - Amazon service region
+ region: 'XX-XXXX-X',
+ // OPTIONAL - Customized endpoint
+ endpointId: 'XXXXXXXXXXXX',
+ // OPTIONAL - Default Endpoint Information
+ endpoint: {
+ address: 'xxxxxxx', // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
+ attributes: {
+ // Custom attributes that your app reports to Amazon Pinpoint. You can use these attributes as selection criteria when you create a segment.
+ hobbies: ['piano', 'hiking']
+ },
+ channelType: 'APNS', // The channel type. Valid values: APNS, GCM
+ demographic: {
+ appVersion: 'xxxxxxx', // The version of the application associated with the endpoint.
+ locale: 'xxxxxx', // The endpoint locale in the following format: The ISO 639-1 alpha-2 code, followed by an underscore, followed by an ISO 3166-1 alpha-2 value
+ make: 'xxxxxx', // The manufacturer of the endpoint device, such as Apple or Samsung.
+ model: 'xxxxxx', // The model name or number of the endpoint device, such as iPhone.
+ modelVersion: 'xxxxxx', // The model version of the endpoint device.
+ platform: 'xxxxxx', // The platform of the endpoint device, such as iOS or Android.
+ platformVersion: 'xxxxxx', // The platform version of the endpoint device.
+ timezone: 'xxxxxx' // The timezone of the endpoint. Specified as a tz database value, such as Americas/Los_Angeles.
+ },
+ location: {
+ city: 'xxxxxx', // The city where the endpoint is located.
+ country: 'xxxxxx', // The two-letter code for the country or region of the endpoint. Specified as an ISO 3166-1 alpha-2 code, such as "US" for the United States.
+ latitude: 0, // The latitude of the endpoint location, rounded to one decimal place.
+ longitude: 0, // The longitude of the endpoint location, rounded to one decimal place.
+ postalCode: 'xxxxxx', // The postal code or zip code of the endpoint.
+ region: 'xxxxxx' // The region of the endpoint location. For example, in the United States, this corresponds to a state.
+ },
+ metrics: {
+ // Custom metrics that your app reports to Amazon Pinpoint.
+ },
+ /** Indicates whether a user has opted out of receiving messages with one of the following values:
+ * ALL (default) - User has opted out of all messages.
+ * NONE - Users has not opted out and receives all messages.
+ */
+ optOut: 'ALL',
+ // Customized userId
+ userId: 'XXXXXXXXXXXX',
+ // User attributes
+ userAttributes: {
+ interests: ['football', 'basketball', 'AWS']
+ // ...
+ }
+ },
+
+ // Buffer settings used for reporting analytics events.
+ // OPTIONAL - The buffer size for events in number of items.
+ bufferSize: 1000,
+
+ // OPTIONAL - The interval in milliseconds to perform a buffer check and flush if necessary.
+ flushInterval: 5000, // 5s
+
+ // OPTIONAL - The number of events to be deleted from the buffer when flushed.
+ flushSize: 100,
+
+ // OPTIONAL - The limit for failed recording retries.
+ resendLimit: 5
+ }
+ }
+});
+```
+
+## Update your IAM Policy
+
+
+
+Amazon Pinpoint service requires an IAM policy in order to use the `record` API:
+
+```json
+{
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Effect": "Allow",
+ "Action": ["mobiletargeting:UpdateEndpoint", "mobiletargeting:PutEvents"],
+ "Resource": ["arn:aws:mobiletargeting:*:${accountID}:apps/${appId}*"]
+ }
+ ]
+}
+```
diff --git a/src/fragments/lib/analytics/js/getting-started.mdx b/src/fragments/lib/analytics/js/getting-started.mdx
deleted file mode 100644
index f011605aae2..00000000000
--- a/src/fragments/lib/analytics/js/getting-started.mdx
+++ /dev/null
@@ -1,291 +0,0 @@
-The Analytics category enables you to collect analytics data for your App. The Analytics category comes with built-in support for [Amazon Pinpoint](https://aws.amazon.com/pinpoint) and [Amazon Kinesis](https://aws.amazon.com/kinesis) (Kinesis support is currently only available in the Amplify JavaScript library). The Analytics category uses [Amazon Cognito Identity pools](https://docs.aws.amazon.com/cognito/latest/developerguide/identity-pools.html) to identify users in your App. Cognito allows you to receive data from authenticated, and unauthenticated users in your App.
-
-## Goal
-
-To setup and configure your application with Amplify Analytics and record an analytics event.
-
-## Prerequisites
-
-- [Install and configure Amplify CLI](https://docs.amplify.aws/cli/start/install)
-
-## Set up Analytics backend
-
-Run the following command in your project's root folder. The CLI will prompt configuration options for the Analytics category such as Amazon Pinpoint resource name and analytics event settings.
-
-> The Analytics category utilizes the Authentication category behind the scenes to authorize your app to send analytics events.
-
-```bash
-amplify add analytics
-```
-
-```console
-? Provide your pinpoint resource name:
- `yourPinpointResourceName`
-Adding analytics would add the Auth category to the project if not already added.
-? Apps need authorization to send analytics events. Do you want to allow guests and unauthenticated users to send analytics events? (we recommend you allow this when getting started)
- `Yes`
-```
-
-To deploy your backend, run:
-
-```bash
-amplify push
-```
-
-A configuration file called `aws-exports.js` will be copied to your configured source directory, for example `./src`. The CLI will also print the URL for Amazon Pinpoint console to track your app events.
-
-## Configure Your App
-
-Import and load the configuration file in your app. It's recommended you add the Amplify configuration step to your app's root entry point. For example `App.js` in React or `main.ts` in Angular.
-
-```javascript
-import { Amplify, Analytics } from 'aws-amplify';
-import awsconfig from './aws-exports';
-Amplify.configure(awsconfig);
-```
-
-User session data is automatically collected unless you disabled analytics. To see the results visit the [Amazon Pinpoint console](https://console.aws.amazon.com/pinpoint/home/).
-
-## Recording an event
-
-To record custom events call the `record` method:
-
-```javascript
-import { Amplify, Analytics } from 'aws-amplify';
-
-Analytics.record({ name: 'albumVisit' });
-```
-
-## API Reference
-
-For a complete API reference visit the [API Reference](https://aws-amplify.github.io/amplify-js/api/classes/analyticsclass.html)
-
-## Set up existing analytics backend
-
-The manual setup enables you to use your existing Amazon Pinpoint resource in your app.
-
-```javascript
-import { Amplify } from 'aws-amplify';
-
-Amplify.configure({
- // To get the AWS Credentials, you need to configure
- // the Auth module with your Cognito Federated Identity Pool
- Auth: {
- identityPoolId: 'us-east-1:xxx-xxx-xxx-xxx-xxx',
- region: 'us-east-1'
- },
- Analytics: {
- // OPTIONAL - disable Analytics if true
- disabled: false,
- // OPTIONAL - Allow recording session events. Default is true.
- autoSessionRecord: true,
-
- AWSPinpoint: {
- // OPTIONAL - Amazon Pinpoint App Client ID
- appId: 'XXXXXXXXXXabcdefghij1234567890ab',
- // OPTIONAL - Amazon service region
- region: 'XX-XXXX-X',
- // OPTIONAL - Customized endpoint
- endpointId: 'XXXXXXXXXXXX',
- // OPTIONAL - Default Endpoint Information
- endpoint: {
- address: 'xxxxxxx', // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
- attributes: {
- // Custom attributes that your app reports to Amazon Pinpoint. You can use these attributes as selection criteria when you create a segment.
- hobbies: ['piano', 'hiking']
- },
- channelType: 'APNS', // The channel type. Valid values: APNS, GCM
- demographic: {
- appVersion: 'xxxxxxx', // The version of the application associated with the endpoint.
- locale: 'xxxxxx', // The endpoint locale in the following format: The ISO 639-1 alpha-2 code, followed by an underscore, followed by an ISO 3166-1 alpha-2 value
- make: 'xxxxxx', // The manufacturer of the endpoint device, such as Apple or Samsung.
- model: 'xxxxxx', // The model name or number of the endpoint device, such as iPhone.
- modelVersion: 'xxxxxx', // The model version of the endpoint device.
- platform: 'xxxxxx', // The platform of the endpoint device, such as iOS or Android.
- platformVersion: 'xxxxxx', // The platform version of the endpoint device.
- timezone: 'xxxxxx' // The timezone of the endpoint. Specified as a tz database value, such as Americas/Los_Angeles.
- },
- location: {
- city: 'xxxxxx', // The city where the endpoint is located.
- country: 'xxxxxx', // The two-letter code for the country or region of the endpoint. Specified as an ISO 3166-1 alpha-2 code, such as "US" for the United States.
- latitude: 0, // The latitude of the endpoint location, rounded to one decimal place.
- longitude: 0, // The longitude of the endpoint location, rounded to one decimal place.
- postalCode: 'xxxxxx', // The postal code or zip code of the endpoint.
- region: 'xxxxxx' // The region of the endpoint location. For example, in the United States, this corresponds to a state.
- },
- metrics: {
- // Custom metrics that your app reports to Amazon Pinpoint.
- },
- /** Indicates whether a user has opted out of receiving messages with one of the following values:
- * ALL (default) - User has opted out of all messages.
- * NONE - Users has not opted out and receives all messages.
- */
- optOut: 'ALL',
- // Customized userId
- userId: 'XXXXXXXXXXXX',
- // User attributes
- userAttributes: {
- interests: ['football', 'basketball', 'AWS']
- // ...
- }
- },
-
- // Buffer settings used for reporting analytics events.
- // OPTIONAL - The buffer size for events in number of items.
- bufferSize: 1000,
-
- // OPTIONAL - The interval in milliseconds to perform a buffer check and flush if necessary.
- flushInterval: 5000, // 5s
-
- // OPTIONAL - The number of events to be deleted from the buffer when flushed.
- flushSize: 100,
-
- // OPTIONAL - The limit for failed recording retries.
- resendLimit: 5
- }
- }
-});
-```
-
-### Update your IAM Policy:
-
-Amazon Pinpoint service requires an IAM policy in order to use the `record` API:
-
-```json
-{
- "Version": "2012-10-17",
- "Statement": [
- {
- "Effect": "Allow",
- "Action": ["mobiletargeting:UpdateEndpoint", "mobiletargeting:PutEvents"],
- "Resource": ["arn:aws:mobiletargeting:*:${accountID}:apps/${appId}*"]
- }
- ]
-}
-```
-
-## Update Endpoint
-
-An endpoint uniquely identifies your app within Pinpoint. In order to update your endpoint use the `updateEndpoint()` method:
-
-```javascript
-import { Analytics } from 'aws-amplify';
-
-Analytics.updateEndpoint({
- address: 'xxxxxxx', // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
- attributes: {
- // Custom attributes that your app reports to Amazon Pinpoint. You can use these attributes as selection criteria when you create a segment.
- hobbies: ['piano', 'hiking']
- },
- channelType: 'APNS', // The channel type. Valid values: APNS, GCM
- demographic: {
- appVersion: 'xxxxxxx', // The version of the application associated with the endpoint.
- locale: 'xxxxxx', // The endpoint locale in the following format: The ISO 639-1 alpha-2 code, followed by an underscore, followed by an ISO 3166-1 alpha-2 value
- make: 'xxxxxx', // The manufacturer of the endpoint device, such as Apple or Samsung.
- model: 'xxxxxx', // The model name or number of the endpoint device, such as iPhone.
- modelVersion: 'xxxxxx', // The model version of the endpoint device.
- platform: 'xxxxxx', // The platform of the endpoint device, such as iOS or Android.
- platformVersion: 'xxxxxx', // The platform version of the endpoint device.
- timezone: 'xxxxxx' // The timezone of the endpoint. Specified as a tz database value, such as Americas/Los_Angeles.
- },
- location: {
- city: 'xxxxxx', // The city where the endpoint is located.
- country: 'xxxxxx', // The two-letter code for the country or region of the endpoint. Specified as an ISO 3166-1 alpha-2 code, such as "US" for the United States.
- latitude: 0, // The latitude of the endpoint location, rounded to one decimal place.
- longitude: 0, // The longitude of the endpoint location, rounded to one decimal place.
- postalCode: 'xxxxxx', // The postal code or zip code of the endpoint.
- region: 'xxxxxx' // The region of the endpoint location. For example, in the United States, this corresponds to a state.
- },
- metrics: {
- // Custom metrics that your app reports to Amazon Pinpoint.
- },
- /** Indicates whether a user has opted out of receiving messages with one of the following values:
- * ALL - User has opted out of all messages.
- * NONE - Users has not opted out and receives all messages.
- */
- optOut: 'ALL',
- // Customized userId
- userId: 'XXXXXXXXXXXX',
- // User attributes
- userAttributes: {
- interests: ['football', 'basketball', 'AWS']
- // ...
- }
-}).then(() => {});
-```
-
-
- There is a limit of 15 unique endpoints per user ID. See Pinpoint's{' '}
-
- documentation
- {' '}
- on endpoint quotas to learn more.
-
-
- Learn more
- about Amazon Pinpoint and Endpoints.
-
-## Using a Custom Plugin
-
-You can create your custom pluggable for Analytics. This may be helpful if you want to integrate your app with a custom analytics backend.
-
-To create a plugin implement the `AnalyticsProvider` interface:
-
-```typescript
-import { Analytics, AnalyticsProvider } from 'aws-amplify';
-
-export default class MyAnalyticsProvider implements AnalyticsProvider {
- // category and provider name
- static category = 'Analytics';
- static providerName = 'MyAnalytics';
-
- // you need to implement these four methods
- // configure your provider
- configure(config: object): object;
-
- // record events and returns true if succeeds
- record(params: object): Promise;
-
- // return 'Analytics';
- getCategory(): string;
-
- // return the name of you provider
- getProviderName(): string;
-}
-```
-
-You can now register your pluggable:
-
-```javascript
-// add the plugin
-Analytics.addPluggable(new MyAnalyticsProvider());
-
-// get the plugin
-Analytics.getPluggable(MyAnalyticsProvider.providerName);
-
-// remove the plugin
-Analytics.removePluggable(MyAnalyticsProvider.providerName);
-
-// send configuration into Amplify
-Analytics.configure({
- MyAnalyticsProvider: {
- // My Analytics provider configuration
- }
-});
-```
-
-The default provider (Amazon Pinpoint) is in use when you call `Analytics.record()` unless you specify a different provider: `Analytics.record({..},'MyAnalyticsProvider')`.
-
-## View Analytics Console
-
-From the terminal run the following command. Navigate to the Analytics tab, and then choose View in Pinpoint.
-
-```console
-amplify console analytics
-```
diff --git a/src/fragments/lib/analytics/js/getting-started/10_preReq.mdx b/src/fragments/lib/analytics/js/getting-started/10_preReq.mdx
new file mode 100644
index 00000000000..6e21736834f
--- /dev/null
+++ b/src/fragments/lib/analytics/js/getting-started/10_preReq.mdx
@@ -0,0 +1 @@
+- [Install and configure Amplify CLI](https://docs.amplify.aws/cli/start/install)
diff --git a/src/fragments/lib/analytics/js/getting-started/12_amplifyConfig.mdx b/src/fragments/lib/analytics/js/getting-started/12_amplifyConfig.mdx
new file mode 100644
index 00000000000..cd34cf1f8b2
--- /dev/null
+++ b/src/fragments/lib/analytics/js/getting-started/12_amplifyConfig.mdx
@@ -0,0 +1 @@
+A configuration file called `aws-exports.js` will be copied to your configured source directory, for example `./src`. The CLI will also print the URL for Amazon Pinpoint console to track your app events.
diff --git a/src/fragments/lib/analytics/js/getting-started/20_installLib.mdx b/src/fragments/lib/analytics/js/getting-started/20_installLib.mdx
new file mode 100644
index 00000000000..82948a4eaf8
--- /dev/null
+++ b/src/fragments/lib/analytics/js/getting-started/20_installLib.mdx
@@ -0,0 +1,5 @@
+To install the Amplify library to use the analytics features, run the following command in your project’s root folder:
+
+```bash
+npm install aws-amplify
+```
diff --git a/src/fragments/lib/analytics/js/getting-started/30_initAnalytics.mdx b/src/fragments/lib/analytics/js/getting-started/30_initAnalytics.mdx
new file mode 100644
index 00000000000..aaf12c4cc6b
--- /dev/null
+++ b/src/fragments/lib/analytics/js/getting-started/30_initAnalytics.mdx
@@ -0,0 +1,9 @@
+It's recommended you add the Amplify configuration step to your app's root entry point. For example `App.js` in React or `main.ts` in Angular.
+
+```javascript
+import { Amplify, Analytics } from 'aws-amplify';
+import awsconfig from './aws-exports';
+Amplify.configure(awsconfig);
+```
+
+User session data is automatically collected unless you disabled analytics. To see the results visit the [Amazon Pinpoint console](https://console.aws.amazon.com/pinpoint/home/).
diff --git a/src/fragments/lib/analytics/js/record.mdx b/src/fragments/lib/analytics/js/record.mdx
index 57af316b98e..e9f50df3e98 100644
--- a/src/fragments/lib/analytics/js/record.mdx
+++ b/src/fragments/lib/analytics/js/record.mdx
@@ -8,13 +8,13 @@ Analytics.record({ name: 'albumVisit' });
## Record a Custom Event with Attributes
-The `record` method lets you add additional attributes to an event. For example, to record *artist* information with an *albumVisit* event:
+The `record` method lets you add additional attributes to an event. For example, to record _artist_ information with an _albumVisit_ event:
```javascript
Analytics.record({
- name: 'albumVisit',
- // Attribute values must be strings
- attributes: { genre: '', artist: '' }
+ name: 'albumVisit',
+ // Attribute values must be strings
+ attributes: { genre: '', artist: '' }
});
```
@@ -24,9 +24,9 @@ Data can also be added to an event:
```javascript
Analytics.record({
- name: 'albumVisit',
- attributes: {},
- metrics: { minutesListened: 30 }
+ name: 'albumVisit',
+ attributes: {},
+ metrics: { minutesListened: 30 }
});
```
@@ -38,18 +38,7 @@ Amazon Pinpoint provider sends events in batch to optimize network bandwidth, ho
```javascript
Analytics.record({
- name: 'albumVisit',
- immediate: true
+ name: 'albumVisit',
+ immediate: true
});
```
-
-## Disable Analytics
-
-You can also disable or re-enable Analytics:
-```javascript
-// to disable Analytics
-Analytics.disable();
-
-// to enable Analytics
-Analytics.enable();
-```
diff --git a/src/fragments/lib/analytics/js/update-endpoint.mdx b/src/fragments/lib/analytics/js/update-endpoint.mdx
new file mode 100644
index 00000000000..0573f3ab66c
--- /dev/null
+++ b/src/fragments/lib/analytics/js/update-endpoint.mdx
@@ -0,0 +1,65 @@
+An endpoint uniquely identifies your app within Pinpoint. In order to update your endpoint use the `updateEndpoint()` method:
+
+```javascript
+import { Analytics } from 'aws-amplify';
+
+await Analytics.updateEndpoint({
+ address: 'xxxxxxx', // The unique identifier for the recipient. For example, an address could be a device token, email address, or mobile phone number.
+ attributes: {
+ // Custom attributes that your app reports to Amazon Pinpoint. You can use these attributes as selection criteria when you create a segment.
+ hobbies: ['piano', 'hiking']
+ },
+ channelType: 'APNS', // The channel type. Valid values: APNS, GCM
+ demographic: {
+ appVersion: 'xxxxxxx', // The version of the application associated with the endpoint.
+ locale: 'xxxxxx', // The endpoint locale in the following format: The ISO 639-1 alpha-2 code, followed by an underscore, followed by an ISO 3166-1 alpha-2 value
+ make: 'xxxxxx', // The manufacturer of the endpoint device, such as Apple or Samsung.
+ model: 'xxxxxx', // The model name or number of the endpoint device, such as iPhone.
+ modelVersion: 'xxxxxx', // The model version of the endpoint device.
+ platform: 'xxxxxx', // The platform of the endpoint device, such as iOS or Android.
+ platformVersion: 'xxxxxx', // The platform version of the endpoint device.
+ timezone: 'xxxxxx' // The timezone of the endpoint. Specified as a tz database value, such as Americas/Los_Angeles.
+ },
+ location: {
+ city: 'xxxxxx', // The city where the endpoint is located.
+ country: 'xxxxxx', // The two-letter code for the country or region of the endpoint. Specified as an ISO 3166-1 alpha-2 code, such as "US" for the United States.
+ latitude: 0, // The latitude of the endpoint location, rounded to one decimal place.
+ longitude: 0, // The longitude of the endpoint location, rounded to one decimal place.
+ postalCode: 'xxxxxx', // The postal code or zip code of the endpoint.
+ region: 'xxxxxx' // The region of the endpoint location. For example, in the United States, this corresponds to a state.
+ },
+ metrics: {
+ // Custom metrics that your app reports to Amazon Pinpoint.
+ },
+ /** Indicates whether a user has opted out of receiving messages with one of the following values:
+ * ALL - User has opted out of all messages.
+ * NONE - Users has not opted out and receives all messages.
+ */
+ optOut: 'ALL',
+ // Customized userId
+ userId: 'XXXXXXXXXXXX',
+ // User attributes
+ userAttributes: {
+ interests: ['football', 'basketball', 'AWS']
+ // ...
+ }
+}).then(() => {});
+```
+
+
+ There is a limit of 15 unique endpoints per user ID. See Pinpoint's{' '}
+
+ documentation
+
+ {' '}
+ on endpoint quotas to learn more.
+
+
+ Learn more
+ about Amazon Pinpoint and Endpoints.
diff --git a/src/fragments/lib/analytics/native_common/getting-started/common.mdx b/src/fragments/lib/analytics/native_common/getting-started/common.mdx
index 52060312739..af16688206d 100644
--- a/src/fragments/lib/analytics/native_common/getting-started/common.mdx
+++ b/src/fragments/lib/analytics/native_common/getting-started/common.mdx
@@ -6,17 +6,25 @@ To setup and configure your application with Amplify Analytics and record an ana
## Prerequisites
-import ios0 from "/src/fragments/lib/analytics/ios/getting-started/10_preReq.mdx";
+import ios0 from '/src/fragments/lib/analytics/ios/getting-started/10_preReq.mdx';
-
+
-import android1 from "/src/fragments/lib/analytics/android/getting-started/10_preReq.mdx";
+import android1 from '/src/fragments/lib/analytics/android/getting-started/10_preReq.mdx';
-
+
-import flutter2 from "/src/fragments/lib/analytics/flutter/getting-started/10_preReq.mdx";
+import flutter2 from '/src/fragments/lib/analytics/flutter/getting-started/10_preReq.mdx';
-
+
+
+import js1 from '/src/fragments/lib/analytics/js/getting-started/10_preReq.mdx';
+
+
+
+import reactnative1 from '/src/fragments/lib/analytics/js/getting-started/10_preReq.mdx';
+
+
## Set up Analytics backend
@@ -43,53 +51,77 @@ To deploy your backend, run:
amplify push
```
-import ios3 from "/src/fragments/lib/analytics/ios/getting-started/12_amplifyConfig.mdx";
+import ios3 from '/src/fragments/lib/analytics/ios/getting-started/12_amplifyConfig.mdx';
+
+
+
+import android4 from '/src/fragments/lib/analytics/android/getting-started/12_amplifyConfig.mdx';
+
+
+
+import flutter5 from '/src/fragments/lib/analytics/flutter/getting-started/12_amplifyConfig.mdx';
-
+
-import android4 from "/src/fragments/lib/analytics/android/getting-started/12_amplifyConfig.mdx";
+import js2 from '/src/fragments/lib/analytics/js/getting-started/12_amplifyConfig.mdx';
-
+
-import flutter5 from "/src/fragments/lib/analytics/flutter/getting-started/12_amplifyConfig.mdx";
+import reactnative2 from '/src/fragments/lib/analytics/js/getting-started/12_amplifyConfig.mdx';
-
+
## Install Amplify Libraries
-import ios6 from "/src/fragments/lib/analytics/ios/getting-started/20_installLib.mdx";
+import ios6 from '/src/fragments/lib/analytics/ios/getting-started/20_installLib.mdx';
-
+
-import android7 from "/src/fragments/lib/analytics/android/getting-started/20_installLib.mdx";
+import android7 from '/src/fragments/lib/analytics/android/getting-started/20_installLib.mdx';
-
+
-import flutter8 from "/src/fragments/lib/analytics/flutter/getting-started/20_installLib.mdx";
+import flutter8 from '/src/fragments/lib/analytics/flutter/getting-started/20_installLib.mdx';
-
+
+
+import js3 from '/src/fragments/lib/analytics/js/getting-started/20_installLib.mdx';
+
+
+
+import reactnative3 from '/src/fragments/lib/analytics/js/getting-started/20_installLib.mdx';
+
+
## Initialize Amplify Analytics
-import ios9 from "/src/fragments/lib/analytics/ios/getting-started/30_initAnalytics.mdx";
+import ios9 from '/src/fragments/lib/analytics/ios/getting-started/30_initAnalytics.mdx';
+
+
+
+import android10 from '/src/fragments/lib/analytics/android/getting-started/30_initAnalytics.mdx';
+
+
+
+import flutter11 from '/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx';
-
+
-import android10 from "/src/fragments/lib/analytics/android/getting-started/30_initAnalytics.mdx";
+import js4 from '/src/fragments/lib/analytics/js/getting-started/30_initAnalytics.mdx';
-
+
-import flutter11 from "/src/fragments/lib/analytics/flutter/getting-started/30_initAnalytics.mdx";
+import reactnative4 from '/src/fragments/lib/analytics/js/getting-started/30_initAnalytics.mdx';
-
+
-import ios12 from "/src/fragments/lib/analytics/ios/getting-started/40_record.mdx";
+import ios12 from '/src/fragments/lib/analytics/ios/getting-started/40_record.mdx';
-
+
-import android13 from "/src/fragments/lib/analytics/android/getting-started/40_record.mdx";
+import android13 from '/src/fragments/lib/analytics/android/getting-started/40_record.mdx';
-
+
## View Analytics console
@@ -101,9 +133,9 @@ amplify console analytics
Next Steps:
-Congratulations! Now that you have Analytics' backend provisioned and Analytics library installed. Check out the following links to see Amplify Analytics use cases:
+Congratulations! Now that you have Analytics' backend provisioned and Analytics library installed. Check out the following links to see Amplify Analytics use cases:
-* [Record Events](/lib/analytics/record)
-* [Track Sessions](/lib/analytics/autotrack)
-* [Identify User](/lib/analytics/identifyuser)
-* [Escape Hatch](/lib/analytics/escapehatch)
+- [Record Events](/lib/analytics/record)
+- [Track Sessions](/lib/analytics/autotrack)
+- [Identify User](/lib/analytics/identifyuser)
+- [Escape Hatch](/lib/analytics/escapehatch)
diff --git a/src/fragments/lib/auth/js/enable_sign_in_sign_up.mdx b/src/fragments/lib/auth/js/enable_sign_in_sign_up.mdx
new file mode 100644
index 00000000000..7e9421e60aa
--- /dev/null
+++ b/src/fragments/lib/auth/js/enable_sign_in_sign_up.mdx
@@ -0,0 +1,168 @@
+There are two ways to add authentication capabilities to your application.
+
+1. [Use pre-built UI components](#option-1-use-pre-built-ui-components)
+
+2. [Call Authentication APIs manually](#option-2-call-authentication-apis-manually)
+
+## Option 1: Use pre-built UI components
+
+Creating the login flow can be quite difficult and time consuming to get right. Amplify Framework has authentication UI components you can use that will provide the entire authentication flow for you, using your configuration specified in your __aws-exports.js__ file.
+
+Amplify has pre-built UI components for React, Vue, Angular and React Native.
+
+
+
+
+First, install the `@aws-amplify/ui-react` library as well as `aws-amplify` if you have not already:
+
+```sh
+npm install aws-amplify @aws-amplify/ui-react
+```
+
+Next, open __src/App.js__ and add the `withAuthenticator` component.
+
+**withAuthenticator**
+
+import all1 from "/src/fragments/ui/auth/react/withauthenticator.mdx";
+
+
+
+
+
+
+First, install the `@aws-amplify/ui-vue` library as well as `aws-amplify` if you have not already:
+
+```bash
+npm install aws-amplify @aws-amplify/ui-vue
+```
+
+Next, open __src/App.js__ and add the `Authenticator` component.
+
+**Authenticator**
+
+The `Authenticator` component offers a simple way to add authentication flows into your app. This component encapsulates an authentication workflow in the framework of your choice and is backed by the cloud resources set up in your Auth cloud resources. You’ll also notice that `user` and `signOut` are passed to the inner template.
+
+```html
+
+
+
+
+
+
Hello {{ user.username }}!
+
+
+
+
+```
+
+
+
+
+First, install the `@aws-amplify/ui-components` library as well as `aws-amplify` if you have not already:
+
+```bash
+npm install aws-amplify @aws-amplify/ui-components
+```
+
+Now open __src/main.js__ and add the following below your last import:
+
+```js
+import '@aws-amplify/ui-components';
+import {
+ applyPolyfills,
+ defineCustomElements,
+} from '@aws-amplify/ui-components/loader';
+import Vue from 'vue';
+
+Vue.config.ignoredElements = [/amplify-\w*/];
+
+
+applyPolyfills().then(() => {
+ defineCustomElements(window);
+});
+```
+
+Next, open __src/App.js__ and add the `amplify-authenticator` component.
+
+**amplify-authenticator**
+
+The `amplify-authenticator` component offers a simple way to add authentication flows into your app. This component encapsulates an authentication workflow in the framework of your choice and is backed by the cloud resources set up in your Auth cloud resources. You’ll also notice the `amplify-sign-out` component. This is an optional component if you’d like to render a sign out button.
+
+```html
+
+
+
+ My App
+
+
+
+
+```
+
+
+
+
+First, install the `@aws-amplify/ui-angular` library as well as `aws-amplify` if you have not already:
+
+```bash
+npm install aws-amplify @aws-amplify/ui-angular
+```
+
+Now open __app.module.ts__ and add the Amplify imports and configuration:
+
+```js
+import { NgModule } from '@angular/core';
+import { BrowserModule } from '@angular/platform-browser';;
+import { AmplifyAuthenticatorModule } from '@aws-amplify/ui-angular';
+
+import { AppComponent } from './app.component';
+import awsconfig from '../aws-exports';
+
+Amplify.configure(awsconfig);
+
+@NgModule({
+ declarations: [AppComponent],
+ imports: [BrowserModule, AmplifyAuthenticatorModule],
+ providers: [],
+ bootstrap: [AppComponent],
+})
+export class AppModule {}
+```
+
+Next, import the default theme inside __styles.css__:
+
+```css
+@import '~@aws-amplify/ui-angular/theme.css';
+````
+
+Next, open __app.component.html__ and add the `amplify-authenticator` component.
+
+**amplify-authenticator**
+
+The `amplify-authenticator` component offers a simple way to add authentication flows into your app. This component encapsulates an authentication workflow in the framework of your choice and is backed by the cloud resources set up in your Auth cloud resources. You’ll also notice that `user` and `signOut` are provided to the inner template.
+
+```html
+
+
+
Welcome {{ user.username }}!
+
+
+
+```
+
+
+
+
+## Option 2: Call Authentication APIs manually
\ No newline at end of file
diff --git a/src/fragments/lib/auth/js/getting-started-steps-basic-auth-react-native.mdx b/src/fragments/lib/auth/js/getting-started-steps-basic-auth-react-native.mdx
new file mode 100644
index 00000000000..7901120580a
--- /dev/null
+++ b/src/fragments/lib/auth/js/getting-started-steps-basic-auth-react-native.mdx
@@ -0,0 +1,25 @@
+
+
+
+Install the necessary dependencies by running the following command:
+
+```sh
+npm install aws-amplify amazon-cognito-identity-js @react-native-community/netinfo @react-native-async-storage/async-storage
+```
+
+You will also need to install the pod dependencies for iOS:
+
+```sh
+npx pod-install
+```
+
+
+
+Install the necessary dependencies by running the following command:
+
+```sh
+npm install aws-amplify @react-native-community/netinfo @react-native-async-storage/async-storage
+```
+
+
+
diff --git a/src/fragments/lib/auth/js/getting-started-steps-basic-auth.mdx b/src/fragments/lib/auth/js/getting-started-steps-basic-auth.mdx
index 3d6a17980a5..70c37cfdafd 100644
--- a/src/fragments/lib/auth/js/getting-started-steps-basic-auth.mdx
+++ b/src/fragments/lib/auth/js/getting-started-steps-basic-auth.mdx
@@ -1,34 +1,5 @@
-
-
-
Install the necessary dependencies by running the following command:
```sh
npm install aws-amplify
```
-
-
-
-
-Install the necessary dependencies by running the following command:
-
-```sh
-npm install aws-amplify amazon-cognito-identity-js @react-native-community/netinfo @react-native-async-storage/async-storage
-```
-
-You will also need to install the pod dependencies for iOS:
-
-```sh
-npx pod-install
-```
-
-
-
-Install the necessary dependencies by running the following command:
-
-```sh
-npm install aws-amplify @react-native-community/netinfo @react-native-async-storage/async-storage
-```
-
-
-
diff --git a/src/fragments/lib/auth/js/getting-started.mdx b/src/fragments/lib/auth/js/getting-started.mdx
index 97d2d1d435f..9cf777f3fac 100644
--- a/src/fragments/lib/auth/js/getting-started.mdx
+++ b/src/fragments/lib/auth/js/getting-started.mdx
@@ -5,6 +5,7 @@
The Amplify Framework uses [Amazon Cognito](https://aws.amazon.com/cognito/) as the main authentication provider. Amazon Cognito is a robust user directory service that handles user registration, authentication, account recovery & other operations. In this tutorial, you'll learn how to add authentication to your application using Amazon Cognito and username/password login.
## Create authentication service
+
To start from scratch, run the following command in your project's root folder:
> If you want to re-use an existing authentication resource from AWS (e.g. Amazon Cognito UserPool or Identity Pool) refer to [this section](/lib/auth/start#re-use-existing-authentication-resource).
@@ -33,13 +34,15 @@ amplify console
## Configure your application
-Add Amplify to your app:
+import js0 from '/src/fragments/lib/auth/js/getting-started-steps-basic-auth.mdx';
+
+
-import all0 from "/src/fragments/lib/auth/js/getting-started-steps-basic-auth.mdx";
+import reactnative0 from '/src/fragments/lib/auth/js/getting-started-steps-basic-auth-react-native.mdx';
-
+
-In your app's entry point (i.e. __App.js__, __index.js__, or __main.js__), import and load the configuration file:
+In your app's entry point (i.e. **App.js**, **index.js**, or **main.js**), import and load the configuration file:
```javascript
import { Amplify, Auth } from 'aws-amplify';
@@ -49,174 +52,9 @@ Amplify.configure(awsconfig);
## Enable sign-up, sign-in, and sign-out
-There are two ways to add authentication capabilities to your application.
-
-1. [Use pre-built UI components](#option-1-use-pre-built-ui-components)
-
-2. [Call Authentication APIs manually](#option-2-call-authentication-apis-manually)
-
-## Option 1: Use pre-built UI components
-
-Creating the login flow can be quite difficult and time consuming to get right. Amplify Framework has authentication UI components you can use that will provide the entire authentication flow for you, using your configuration specified in your __aws-exports.js__ file.
-
-Amplify has pre-built UI components for React, Vue, Angular and React Native.
-
-
-
-
-First, install the `@aws-amplify/ui-react` library as well as `aws-amplify` if you have not already:
-
-```sh
-npm install aws-amplify @aws-amplify/ui-react
-```
-
-Next, open __src/App.js__ and add the `withAuthenticator` component.
-
-**withAuthenticator**
-
-import all1 from "/src/fragments/ui/auth/react/withauthenticator.mdx";
-
-
-
-
-
-
-First, install the `@aws-amplify/ui-vue` library as well as `aws-amplify` if you have not already:
-
-```bash
-npm install aws-amplify @aws-amplify/ui-vue
-```
-
-Next, open __src/App.js__ and add the `Authenticator` component.
-
-**Authenticator**
-
-The `Authenticator` component offers a simple way to add authentication flows into your app. This component encapsulates an authentication workflow in the framework of your choice and is backed by the cloud resources set up in your Auth cloud resources. You’ll also notice that `user` and `signOut` are passed to the inner template.
-
-```html
-
-
-
-
-
-
Hello {{ user.username }}!
-
-
-
-
-```
-
-
-
-
-First, install the `@aws-amplify/ui-components` library as well as `aws-amplify` if you have not already:
-
-```bash
-npm install aws-amplify @aws-amplify/ui-components
-```
-
-Now open __src/main.js__ and add the following below your last import:
-
-```js
-import '@aws-amplify/ui-components';
-import {
- applyPolyfills,
- defineCustomElements,
-} from '@aws-amplify/ui-components/loader';
-import Vue from 'vue';
-
-Vue.config.ignoredElements = [/amplify-\w*/];
-
-
-applyPolyfills().then(() => {
- defineCustomElements(window);
-});
-```
-
-Next, open __src/App.js__ and add the `amplify-authenticator` component.
-
-**amplify-authenticator**
-
-The `amplify-authenticator` component offers a simple way to add authentication flows into your app. This component encapsulates an authentication workflow in the framework of your choice and is backed by the cloud resources set up in your Auth cloud resources. You’ll also notice the `amplify-sign-out` component. This is an optional component if you’d like to render a sign out button.
-
-```html
-
-
-
- My App
-
-
-
-
-```
-
-
-
-
-First, install the `@aws-amplify/ui-angular` library as well as `aws-amplify` if you have not already:
-
-```bash
-npm install aws-amplify @aws-amplify/ui-angular
-```
-
-Now open __app.module.ts__ and add the Amplify imports and configuration:
-
-```js
-import { NgModule } from '@angular/core';
-import { BrowserModule } from '@angular/platform-browser';;
-import { AmplifyAuthenticatorModule } from '@aws-amplify/ui-angular';
-
-import { AppComponent } from './app.component';
-import awsconfig from '../aws-exports';
-
-Amplify.configure(awsconfig);
-
-@NgModule({
- declarations: [AppComponent],
- imports: [BrowserModule, AmplifyAuthenticatorModule],
- providers: [],
- bootstrap: [AppComponent],
-})
-export class AppModule {}
-```
-
-Next, import the default theme inside __styles.css__:
-
-```css
-@import '~@aws-amplify/ui-angular/theme.css';
-````
-
-Next, open __app.component.html__ and add the `amplify-authenticator` component.
-
-**amplify-authenticator**
-
-The `amplify-authenticator` component offers a simple way to add authentication flows into your app. This component encapsulates an authentication workflow in the framework of your choice and is backed by the cloud resources set up in your Auth cloud resources. You’ll also notice that `user` and `signOut` are provided to the inner template.
-
-```html
-
-
-
Welcome {{ user.username }}!
-
-
-
-```
-
-
-
+import js1 from '/src/fragments/lib/auth/js/enable_sign_in_sign_up.mdx';
-## Option 2: Call Authentication APIs manually
+
Follow the instructions in the [Sign in, Sign up and Sign out](/lib/auth/emailpassword) to learn about how to integrate these authentication flows in your application with the Auth APIs.
diff --git a/src/fragments/lib/datastore/android/getting-started/30_platformIntegration.mdx b/src/fragments/lib/datastore/android/getting-started/30_platformIntegration.mdx
new file mode 100644
index 00000000000..9dee930778e
--- /dev/null
+++ b/src/fragments/lib/datastore/android/getting-started/30_platformIntegration.mdx
@@ -0,0 +1 @@
+Coming Soon. Please use [Option #2](/lib/datastore/getting-started#option-2-use-amplify-cli). for now.
diff --git a/src/fragments/lib/datastore/js/examples-react-native.mdx b/src/fragments/lib/datastore/js/examples-react-native.mdx
new file mode 100644
index 00000000000..3def9517ef5
--- /dev/null
+++ b/src/fragments/lib/datastore/js/examples-react-native.mdx
@@ -0,0 +1,129 @@
+```jsx
+/**
+ * React Native DataStore Sample App
+ */
+
+import React, { Component } from 'react';
+import { Text, StyleSheet, ScrollView } from 'react-native';
+
+import { Amplify, DataStore, Predicates } from 'aws-amplify';
+import { Post, PostStatus, Comment } from './src/models';
+
+import awsConfig from './aws-exports';
+Amplify.configure(awsConfig);
+let subscription;
+
+class App extends Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ posts: []
+ };
+ }
+
+ componentDidMount() {
+ this.onQuery();
+ subscription = DataStore.observe(Post).subscribe((msg) => {
+ console.log('SUBSCRIPTION_UPDATE', msg);
+ this.onQuery();
+ });
+ }
+
+ componentWillUnmount() {
+ subscription.unsubscribe();
+ }
+
+ onCreatePost() {
+ DataStore.save(
+ new Post({
+ title: `New Post ${Date.now()}`,
+ rating: (function getRandomInt(min, max) {
+ min = Math.ceil(min);
+ max = Math.floor(max);
+ // The maximum is exclusive and the minimum is inclusive
+ return Math.floor(Math.random() * (max - min)) + min;
+ })(5, 10),
+ status: PostStatus.ACTIVE
+ })
+ );
+ }
+
+ async onCreatePostAndComments() {
+ const post = new Post({
+ title: `New Post with comments ${Date.now()}`,
+ rating: 5,
+ status: PostStatus.ACTIVE
+ });
+
+ await DataStore.save(post);
+
+ for (let i = 0; i < 2; i++) {
+ DataStore.save(
+ new Comment({
+ content: `New comment ${Date.now()}`,
+ post
+ })
+ );
+ }
+ }
+
+ onQuery = async () => {
+ const posts = await DataStore.query(Post, (c) => c.rating('gt', 2));
+ console.log('QUERY_POSTS_RESULT', posts);
+ const comments = await DataStore.query(Comment);
+ this.setState({ posts });
+ console.log('QUERY_COMMENTS_RESULT', comments);
+ };
+
+ onDelete = async () => {
+ const deletedPosts = await DataStore.delete(Post, Predicates.ALL);
+ console.log('DELETE_RESULT', deletedPosts);
+ };
+
+ render() {
+ return (
+
+
+ Create Post
+
+
+ Create Post & Comments
+
+
+ Query Posts
+
+
+ Delete All Posts
+
+ {this.state.posts.map((post, i) => (
+ {`${post.title} ${post.rating}`}
+ ))}
+
+ );
+ }
+}
+
+const styles = StyleSheet.create({
+ scrollview: {
+ paddingTop: 40,
+ flex: 1
+ },
+ container: {
+ alignItems: 'center'
+ },
+ text: {
+ fontSize: 20,
+ textAlign: 'center',
+ margin: 10
+ }
+});
+
+export default App;
+```
+
+## API Reference
+
+For the complete API documentation for DataStore, visit our [API Reference](https://aws-amplify.github.io/amplify-js/api/classes/datastore.html)
diff --git a/src/fragments/lib/datastore/js/examples.mdx b/src/fragments/lib/datastore/js/examples.mdx
index 3162c3eb2db..c8e1ae2ae5c 100644
--- a/src/fragments/lib/datastore/js/examples.mdx
+++ b/src/fragments/lib/datastore/js/examples.mdx
@@ -194,134 +194,6 @@ export default {
```
-
-
-```jsx
-/**
- * React Native DataStore Sample App
- */
-
-import React, { Component } from "react";
-import { Text, StyleSheet, ScrollView } from "react-native";
-
-import { Amplify, DataStore, Predicates } from "aws-amplify";
-import { Post, PostStatus, Comment } from "./src/models";
-
-import awsConfig from "./aws-exports";
-Amplify.configure(awsConfig);
-let subscription;
-
-class App extends Component {
- constructor(props) {
- super(props);
- this.state = {
- posts: [],
- };
- }
-
- componentDidMount() {
- this.onQuery();
- subscription = DataStore.observe(Post).subscribe((msg) => {
- console.log("SUBSCRIPTION_UPDATE", msg);
- this.onQuery();
- });
- }
-
- componentWillUnmount() {
- subscription.unsubscribe();
- }
-
- onCreatePost() {
- DataStore.save(
- new Post({
- title: `New Post ${Date.now()}`,
- rating: (function getRandomInt(min, max) {
- min = Math.ceil(min);
- max = Math.floor(max);
- // The maximum is exclusive and the minimum is inclusive
- return Math.floor(Math.random() * (max - min)) + min;
- })(5, 10),
- status: PostStatus.ACTIVE,
- })
- );
- }
-
- async onCreatePostAndComments() {
- const post = new Post({
- title: `New Post with comments ${Date.now()}`,
- rating: 5,
- status: PostStatus.ACTIVE,
- });
-
- await DataStore.save(post);
-
- for (let i = 0; i < 2; i++) {
- DataStore.save(
- new Comment({
- content: `New comment ${Date.now()}`,
- post,
- })
- );
- }
- }
-
- onQuery = async () => {
- const posts = await DataStore.query(Post, (c) => c.rating("gt", 2));
- console.log("QUERY_POSTS_RESULT", posts);
- const comments = await DataStore.query(Comment);
- this.setState({ posts });
- console.log("QUERY_COMMENTS_RESULT", comments);
- };
-
- onDelete = async () => {
- const deletedPosts = await DataStore.delete(Post, Predicates.ALL);
- console.log("DELETE_RESULT", deletedPosts);
- };
-
- render() {
- return (
-
-
- Create Post
-
-
- Create Post & Comments
-
-
- Query Posts
-
-
- Delete All Posts
-
- {this.state.posts.map((post, i) => (
- {`${post.title} ${post.rating}`}
- ))}
-
- );
- }
-}
-
-const styles = StyleSheet.create({
- scrollview: {
- paddingTop: 40,
- flex: 1,
- },
- container: {
- alignItems: "center",
- },
- text: {
- fontSize: 20,
- textAlign: "center",
- margin: 10,
- },
-});
-
-export default App;
-```
-
## API Reference
diff --git a/src/fragments/lib/datastore/js/getting-started/10_preReq.mdx b/src/fragments/lib/datastore/js/getting-started/10_preReq.mdx
index f50081ddc48..64f7debe43f 100644
--- a/src/fragments/lib/datastore/js/getting-started/10_preReq.mdx
+++ b/src/fragments/lib/datastore/js/getting-started/10_preReq.mdx
@@ -1,5 +1,5 @@
-* Install [Amplify CLI](/cli) version 4.21.0 or later by running:
+- Install [Amplify CLI](/cli) version 4.21.0 or later by running:
-import all0 from "/src/fragments/cli-install-block.mdx";
+import all0 from '/src/fragments/cli-install-block.mdx';
-
+
diff --git a/src/fragments/lib/datastore/js/getting-started/30_platformIntegration.mdx b/src/fragments/lib/datastore/js/getting-started/30_platformIntegration.mdx
index 0c96a187c3c..45a6c98fc73 100644
--- a/src/fragments/lib/datastore/js/getting-started/30_platformIntegration.mdx
+++ b/src/fragments/lib/datastore/js/getting-started/30_platformIntegration.mdx
@@ -1,10 +1,12 @@
The fastest way to get started is using the `amplify-app` npx script.
-
-
-
-
-
+
+
Start with [Create React app](https://create-react-app.dev):
@@ -12,86 +14,4 @@ Start with [Create React app](https://create-react-app.dev):
npx create-react-app amplify-datastore --use-npm
cd amplify-datastore
npx amplify-app@latest
-```
-
-
-
-
-Start with the [React Native CLI](https://reactnative.dev/docs/getting-started):
-
-```bash
-npx react-native init AmplifyDataStoreRN
-cd AmplifyDataStoreRN
-npx amplify-app@latest
-npm install aws-amplify @react-native-community/netinfo @react-native-async-storage/async-storage
-```
-
-You will also need to install the pod dependencies for iOS:
-
-```sh
-npx pod-install
-```
-
-**Use SQLite for enhanced performance (optional)**
-
-React Native CLI apps can now use SQLite with DataStore. SQLite offers considerable performance advantages over the default "AsyncStorage" database.
-
-To enable SQLite with DataStore for enhanced local database performance, follow the steps below:
-
-```sh
-npx react-native init AmplifyDataStoreRN
-cd AmplifyDataStoreRN
-npx amplify-app@latest
-npm install aws-amplify @aws-amplify/datastore-storage-adapter react-native-sqlite-storage @react-native-community/netinfo @react-native-async-storage/async-storage
-npx pod-install
-```
-
-Then configure the SQLite storage adapter with DataStore in your app:
-
-```js
-import { DataStore } from 'aws-amplify';
-import { SQLiteAdapter } from '@aws-amplify/datastore-storage-adapter/SQLiteAdapter';
-
-DataStore.configure({
- storageAdapter: SQLiteAdapter
-});
-```
-
-
-
-
-Start with the [Expo](https://docs.expo.dev/):
-
-```bash
-expo init AmplifyDataStoreExpo
-cd AmplifyDataStoreExpo
-npx amplify-app@latest
-expo install aws-amplify @react-native-community/netinfo @react-native-async-storage/async-storage
-```
-
-**Use SQLite for enhanced performance (optional)**
-
-Expo built apps can now use SQLite with DataStore. SQLite offers considerable performance advantages over the default "AsyncStorage" database.
-
-To enable SQLite with DataStore for enhanced local database performance, follow the steps below:
-
-```sh
-expo init AmplifyDataStoreExpo
-cd AmplifyDataStoreExpo
-npx amplify-app@latest
-expo install aws-amplify @aws-amplify/datastore-storage-adapter expo-sqlite expo-file-system @react-native-community/netinfo @react-native-async-storage/async-storage
```
-
-Then configure the SQLite storage adapter with DataStore in your app:
-
-```js
-import { DataStore } from 'aws-amplify';
-import { ExpoSQLiteAdapter } from '@aws-amplify/datastore-storage-adapter/ExpoSQLiteAdapter';
-
-DataStore.configure({
- storageAdapter: ExpoSQLiteAdapter
-});
-```
-
-
-
diff --git a/src/fragments/lib/datastore/native_common/conflict.mdx b/src/fragments/lib/datastore/native_common/conflict.mdx
index df38998fb2c..fcd891b8040 100644
--- a/src/fragments/lib/datastore/native_common/conflict.mdx
+++ b/src/fragments/lib/datastore/native_common/conflict.mdx
@@ -1,20 +1,19 @@
-
If data synchronization is enabled via [AppSync](https://aws.amazon.com/appsync/), there can be different versions of the same object on the client and server. Multiple clients may have updated their respective copies of an object. DataStore will converge different object versions by applying conflict detection and resolution strategies. The default resolution is called `Auto Merge`. This strategy allows collections to grow, and prefers server-side versions of single-field data. Other strategies include `Optimistic Concurrency` control and `Custom Lambda` functions. For more information, see the [AWS AppSync documentation on conflict handling](https://docs.aws.amazon.com/appsync/latest/devguide/conflict-detection-and-sync.html).
## Custom conflict resolution
-To select a different conflict resolution strategy, navigate into your project from a terminal and run `amplify update api`. Choose *Conflict resolution strategy* to change the conflict detection and resolution strategies.
+To select a different conflict resolution strategy, navigate into your project from a terminal and run `amplify update api`. Choose _Conflict resolution strategy_ to change the conflict detection and resolution strategies.
```console
-? Please select from one of the below mentioned services:
+? Please select from one of the below mentioned services:
`GraphQL`
...
-? Select a setting to edit
+? Select a setting to edit
`Conflict resolution strategy`
? Select the default resolution strategy
- Auto Merge
-❯ Optimistic Concurrency
- Custom Lambda
+ Auto Merge
+❯ Optimistic Concurrency
+ Custom Lambda
Learn More
```
@@ -24,31 +23,35 @@ Note that this flow will also allow you to change the strategy on each individua
```
? Do you want to override default per model settings? Yes
-? Select the models from below:
+? Select the models from below:
❯◉ Post
◯ PostEditor
◯ User
? Select the resolution strategy for Post model Custom Lambda
? Select from the options below (Use arrow keys)
-❯ Create a new Lambda Function
- Existing Lambda Function
+❯ Create a new Lambda Function
+ Existing Lambda Function
```
## Custom configuration
-import js0 from "/src/fragments/lib/datastore/js/conflict.mdx";
+import js0 from '/src/fragments/lib/datastore/js/conflict.mdx';
+
+
+
+import reactnative0 from '/src/fragments/lib/datastore/js/conflict.mdx';
-
+
-import ios1 from "/src/fragments/lib/datastore/ios/conflict.mdx";
+import ios1 from '/src/fragments/lib/datastore/ios/conflict.mdx';
-
+
-import android2 from "/src/fragments/lib/datastore/android/conflict.mdx";
+import android2 from '/src/fragments/lib/datastore/android/conflict.mdx';
-
+
-import flutter3 from "/src/fragments/lib/datastore/flutter/conflict.mdx";
+import flutter3 from '/src/fragments/lib/datastore/flutter/conflict.mdx';
-
+
diff --git a/src/fragments/lib/datastore/native_common/data-access.mdx b/src/fragments/lib/datastore/native_common/data-access.mdx
index 5871065ae0c..5264181f306 100644
--- a/src/fragments/lib/datastore/native_common/data-access.mdx
+++ b/src/fragments/lib/datastore/native_common/data-access.mdx
@@ -1,7 +1,13 @@
+
+
import js0 from "/src/fragments/lib/datastore/js/data-access/importing-datastore-snippet.mdx";
+import reactnative0 from "/src/fragments/lib/datastore/js/data-access/importing-datastore-snippet.mdx";
+
+
+
## Create and update
To write data to the DataStore, pass an instance of a model to `Amplify.DataStore.save()`:
@@ -10,6 +16,10 @@ import js1 from "/src/fragments/lib/datastore/js/data-access/save-snippet.mdx";
+import reactnative1 from "/src/fragments/lib/datastore/js/data-access/save-snippet.mdx";
+
+
+
import ios2 from "/src/fragments/lib/datastore/ios/data-access/save-snippet.mdx";
@@ -40,6 +50,8 @@ import flutter8 from "/src/fragments/lib/datastore/flutter/data-access/update-sn
+
+
**Avoid working with stale data!**
@@ -52,6 +64,10 @@ import js_observe_update from "/src/fragments/lib/datastore/js/data-access/obser
+import reactnative2 from "/src/fragments/lib/datastore/js/data-access/observe-update-snippet.mdx";
+
+
+
import ios_observe_update from "/src/fragments/lib/datastore/ios/data-access/observe-update-snippet.mdx";
@@ -72,6 +88,10 @@ import js9 from "/src/fragments/lib/datastore/js/data-access/delete-snippet.mdx"
+import reactnative3 from "/src/fragments/lib/datastore/js/data-access/delete-snippet.mdx";
+
+
+
import ios10 from "/src/fragments/lib/datastore/ios/data-access/delete-snippet.mdx";
@@ -94,6 +114,10 @@ import js13 from "/src/fragments/lib/datastore/js/data-access/query-basic-snippe
+import reactnative4 from "/src/fragments/lib/datastore/js/data-access/query-basic-snippet.mdx";
+
+
+
import ios14 from "/src/fragments/lib/datastore/ios/data-access/query-basic-snippet.mdx";
@@ -126,6 +150,10 @@ import js18 from "/src/fragments/lib/datastore/js/data-access/query-predicate-sn
+import reactnative5 from "/src/fragments/lib/datastore/js/data-access/query-predicate-snippet.mdx";
+
+
+
import ios19 from "/src/fragments/lib/datastore/ios/data-access/query-predicate-snippet.mdx";
@@ -144,6 +172,10 @@ import js22 from "/src/fragments/lib/datastore/js/data-access/query-predicate-mu
+import reactnative6 from "/src/fragments/lib/datastore/js/data-access/query-predicate-multiple-snippet.mdx";
+
+
+
import ios23 from "/src/fragments/lib/datastore/ios/data-access/query-predicate-multiple-snippet.mdx";
@@ -162,6 +194,10 @@ import js26 from "/src/fragments/lib/datastore/js/data-access/query-predicate-or
+import reactnative7 from "/src/fragments/lib/datastore/js/data-access/query-predicate-or-snippet.mdx";
+
+
+
import ios27 from "/src/fragments/lib/datastore/ios/data-access/query-predicate-or-snippet.mdx";
@@ -198,6 +234,10 @@ import js34 from "/src/fragments/lib/datastore/js/data-access/query-pagination-s
+import reactnative8 from "/src/fragments/lib/datastore/js/data-access/query-pagination-snippet.mdx";
+
+
+
import ios35 from "/src/fragments/lib/datastore/ios/data-access/query-pagination-snippet.mdx";
diff --git a/src/fragments/lib/datastore/native_common/getting-started.mdx b/src/fragments/lib/datastore/native_common/getting-started.mdx
index 0b18443817b..53332891a5f 100644
--- a/src/fragments/lib/datastore/native_common/getting-started.mdx
+++ b/src/fragments/lib/datastore/native_common/getting-started.mdx
@@ -18,6 +18,10 @@ import js0 from "/src/fragments/lib/datastore/js/getting-started/10_preReq.mdx";
+import reactnative0 from "/src/fragments/lib/datastore/js/getting-started/10_preReq.mdx";
+
+
+
import ios1 from "/src/fragments/lib/datastore/ios/getting-started/10_preReq.mdx";
@@ -48,6 +52,10 @@ import js7 from "/src/fragments/lib/datastore/native_common/setup-env.mdx";
+import reactnative1 from "/src/fragments/lib/datastore/native_common/setup-env.mdx";
+
+
+
import ios8 from "/src/fragments/lib/datastore/ios/getting-started/30_setupEnv.mdx";
@@ -99,6 +107,10 @@ import js11 from "/src/fragments/lib/datastore/js/getting-started/40_codegen.mdx
+import reactnative2 from "/src/fragments/lib/datastore/js/getting-started/40_codegen.mdx";
+
+
+
import ios12 from "/src/fragments/lib/datastore/ios/getting-started/40_codegen.mdx";
@@ -117,6 +129,10 @@ import js15 from "/src/fragments/lib/datastore/native_common/codegen.mdx";
+import reactnative3 from "/src/fragments/lib/datastore/native_common/codegen.mdx";
+
+
+
import ios16 from "/src/fragments/lib/datastore/native_common/codegen.mdx";
@@ -135,6 +151,10 @@ import js19 from "/src/fragments/lib/datastore/js/getting-started/50_initDataSto
+import reactnative4 from "/src/fragments/lib/datastore/js/getting-started/50_initDataStore.mdx";
+
+
+
import ios20 from "/src/fragments/lib/datastore/ios/getting-started/50_initDataStore.mdx";
@@ -161,6 +181,10 @@ import js23 from "/src/fragments/lib/datastore/js/getting-started/60_saveSnippet
+import reactnative5 from "/src/fragments/lib/datastore/js/getting-started/60_saveSnippet.mdx";
+
+
+
import ios24 from "/src/fragments/lib/datastore/ios/getting-started/60_saveSnippet.mdx";
@@ -181,6 +205,10 @@ import js27 from "/src/fragments/lib/datastore/js/getting-started/70_querySnippe
+import reactnative6 from "/src/fragments/lib/datastore/js/getting-started/70_querySnippet.mdx";
+
+
+
import ios28 from "/src/fragments/lib/datastore/ios/getting-started/70_querySnippet.mdx";
diff --git a/src/fragments/lib/datastore/native_common/real-time.mdx b/src/fragments/lib/datastore/native_common/real-time.mdx
index f4d4ad9c010..568a3c0564a 100644
--- a/src/fragments/lib/datastore/native_common/real-time.mdx
+++ b/src/fragments/lib/datastore/native_common/real-time.mdx
@@ -2,21 +2,25 @@
You can subscribe to changes on your Models. This reacts dynamically to updates of data to the underlying Storage Engine, which could be the result of GraphQL Subscriptions as well as Queries or Mutations that run against the backing AppSync API if you are synchronizing with the cloud.
-import js0 from "/src/fragments/lib/datastore/js/real-time/observe-snippet.mdx";
+import js0 from '/src/fragments/lib/datastore/js/real-time/observe-snippet.mdx';
-
+
-import ios1 from "/src/fragments/lib/datastore/ios/real-time/observe-snippet.mdx";
+import reactnative0 from '/src/fragments/lib/datastore/js/real-time/observe-snippet.mdx';
-
+
-import android2 from "/src/fragments/lib/datastore/android/real-time/observe-snippet.mdx";
+import ios1 from '/src/fragments/lib/datastore/ios/real-time/observe-snippet.mdx';
-
+
-import flutter3 from "/src/fragments/lib/datastore/flutter/real-time/observe-snippet.mdx";
+import android2 from '/src/fragments/lib/datastore/android/real-time/observe-snippet.mdx';
-
+
+
+import flutter3 from '/src/fragments/lib/datastore/flutter/real-time/observe-snippet.mdx';
+
+
## Observe query results in real-time
@@ -24,24 +28,28 @@ import flutter3 from "/src/fragments/lib/datastore/flutter/real-time/observe-sni
The first snapshot returned from `observeQuery` will contain the same results as calling `query` directly on your Model - a collection of all the locally-available records. Subsequent snapshots will be emitted as updates to the dataset are received in the local store.
-While data is syncing from the cloud, snapshots will contain all of the items synced so far and an `isSynced` status of `false`. When the sync process is complete, a snapshot will be emitted with all the records in the local store and an `isSynced` status of `true`.
+While data is syncing from the cloud, snapshots will contain all of the items synced so far and an `isSynced` status of `false`. When the sync process is complete, a snapshot will be emitted with all the records in the local store and an `isSynced` status of `true`.
In addition to typical real-time use cases, `observeQuery` can be used on app launch to show your customers an initial data set from the local store while new data is being synced from cloud.
`observeQuery` also accepts the same [predicates](/lib/datastore/data-access#predicates) and [sorting](/lib/datastore/data-access#sort) options as `query`.
-import js1 from "/src/fragments/lib/datastore/js/real-time/observe-query-snippet.mdx";
+import js1 from '/src/fragments/lib/datastore/js/real-time/observe-query-snippet.mdx';
+
+
+
+import reactnative1 from '/src/fragments/lib/datastore/js/real-time/observe-query-snippet.mdx';
-
+
-import ios2 from "/src/fragments/lib/datastore/ios/real-time/observe-query-snippet.mdx";
+import ios2 from '/src/fragments/lib/datastore/ios/real-time/observe-query-snippet.mdx';
-
+
-import android3 from "/src/fragments/lib/datastore/android/real-time/observe-query-snippet.mdx";
+import android3 from '/src/fragments/lib/datastore/android/real-time/observe-query-snippet.mdx';
-
+
-import flutter4 from "/src/fragments/lib/datastore/flutter/real-time/observe-query-snippet.mdx";
+import flutter4 from '/src/fragments/lib/datastore/flutter/real-time/observe-query-snippet.mdx';
-
+
diff --git a/src/fragments/lib/datastore/native_common/relational.mdx b/src/fragments/lib/datastore/native_common/relational.mdx
index 1624983c219..660620fb03c 100644
--- a/src/fragments/lib/datastore/native_common/relational.mdx
+++ b/src/fragments/lib/datastore/native_common/relational.mdx
@@ -13,6 +13,10 @@ import js0 from "/src/fragments/lib/datastore/js/relational/updated-schema.mdx";
+import reactnative0 from "/src/fragments/lib/datastore/js/relational/updated-schema.mdx";
+
+
+
import ios1 from "/src/fragments/lib/datastore/ios/relational/updated-schema.mdx";
@@ -33,6 +37,10 @@ import js4 from "/src/fragments/lib/datastore/js/relational/save-snippet.mdx";
+import reactnative1 from "/src/fragments/lib/datastore/js/relational/save-snippet.mdx";
+
+
+
import ios5 from "/src/fragments/lib/datastore/ios/relational/save-snippet.mdx";
@@ -51,6 +59,10 @@ import js8 from "/src/fragments/lib/datastore/js/relational/query-snippet.mdx";
+import reactnative2 from "/src/fragments/lib/datastore/js/relational/query-snippet.mdx";
+
+
+
import ios9 from "/src/fragments/lib/datastore/ios/relational/query-snippet.mdx";
@@ -71,6 +83,10 @@ import js12 from "/src/fragments/lib/datastore/js/relational/delete-snippet.mdx"
+import reactnative4 from "/src/fragments/lib/datastore/js/relational/delete-snippet.mdx";
+
+
+
import ios13 from "/src/fragments/lib/datastore/ios/relational/delete-snippet.mdx";
@@ -114,6 +130,10 @@ import js16 from "/src/fragments/lib/datastore/js/relational/save-many-snippet.m
+import reactnative5 from "/src/fragments/lib/datastore/js/relational/save-many-snippet.mdx";
+
+
+
import ios17 from "/src/fragments/lib/datastore/ios/relational/save-many-snippet.mdx";
@@ -128,4 +148,8 @@ import flutter19 from "/src/fragments/lib/datastore/flutter/relational/save-many
import js20 from "/src/fragments/lib/datastore/js/relational/query-many-snippet.mdx";
-
\ No newline at end of file
+
+
+import reactnative6 from "/src/fragments/lib/datastore/js/relational/query-many-snippet.mdx";
+
+
\ No newline at end of file
diff --git a/src/fragments/lib/datastore/native_common/setup-auth-rules.mdx b/src/fragments/lib/datastore/native_common/setup-auth-rules.mdx
index ed22fc33d54..4b52602b043 100644
--- a/src/fragments/lib/datastore/native_common/setup-auth-rules.mdx
+++ b/src/fragments/lib/datastore/native_common/setup-auth-rules.mdx
@@ -2,13 +2,13 @@ Amplify gives you the ability to limit which individuals or groups should have a
Here's a high-level overview of the authorization scenarios we support in the Amplify libraries. Each scenario has options you can tune to fit the needs of your application.
-* [**Owner Based Authorization**](#owner-based-authorization): Limit a model instance's access to an "owner" and defines authorization rules for those owners. Backed by Cognito User Pool.
-* [**Static Group Authorization**](#static-group-authorization): Limit a model instance's access to a specific group of users and define authorization rules for that group. Backend by Cognito User Pool.
-* [**Owner and Static Group Combined**](#owner-and-static-group-combined): Uses a combination of both *Owner Based Authorization* and *Static Group Authorization* to control ownership and access.
-* [**Public Authorization**](#public-authorization): Allow public access to your model instances. Backed by an API Key or IAM.
-* [**Private Authorization**](#private-authorization): Allow any signed-in user to access your model instances. Backed by IAM or Cognito User Pool.
-* [**Owner based Authorization with OIDC provider**](#owner-based-authorization-with-oidc-provider): Use a 3rd party OIDC Provider to achieve *Owner based authorization*.
-* [**Static Group Authorization with OIDC provider**](#static-group-authorization-with-oidc-provider): Use a 3rd party OIDC Provider to achieve *Static group authorization* using a custom `groupClaim`.
+- [**Owner Based Authorization**](#owner-based-authorization): Limit a model instance's access to an "owner" and defines authorization rules for those owners. Backed by Cognito User Pool.
+- [**Static Group Authorization**](#static-group-authorization): Limit a model instance's access to a specific group of users and define authorization rules for that group. Backend by Cognito User Pool.
+- [**Owner and Static Group Combined**](#owner-and-static-group-combined): Uses a combination of both _Owner Based Authorization_ and _Static Group Authorization_ to control ownership and access.
+- [**Public Authorization**](#public-authorization): Allow public access to your model instances. Backed by an API Key or IAM.
+- [**Private Authorization**](#private-authorization): Allow any signed-in user to access your model instances. Backed by IAM or Cognito User Pool.
+- [**Owner based Authorization with OIDC provider**](#owner-based-authorization-with-oidc-provider): Use a 3rd party OIDC Provider to achieve _Owner based authorization_.
+- [**Static Group Authorization with OIDC provider**](#static-group-authorization-with-oidc-provider): Use a 3rd party OIDC Provider to achieve _Static group authorization_ using a custom `groupClaim`.
import datastoreClearCallout from '/src/fragments/lib/datastore/native_common/callout/datastore-clear-with-auth.mdx';
@@ -18,16 +18,18 @@ import datastoreClearCallout from '/src/fragments/lib/datastore/native_common/ca
### Per User / Owner Based Data Access
-The following are commonly used patterns for owner based authorization. For more information on how to tune these examples, please see the [CLI documentation on owner based authorization](/cli/graphql/authorization-rules/#per-user--owner-based-data-access).
+The following are commonly used patterns for owner based authorization. For more information on how to tune these examples, please see the [CLI documentation on owner based authorization](/cli/graphql/authorization-rules/#per-user--owner-based-data-access).
+
+- Create/Read/Update/Delete mutations are private to the owner.
-* Create/Read/Update/Delete mutations are private to the owner.
```graphql
type YourModel @model @auth(rules: [{ allow: owner }]) {
...
}
```
-* Owners can create and delete; other signed-in users can read and update.
+- Owners can create and delete; other signed-in users can read and update.
+
```graphql
type YourModel
@model
@@ -42,9 +44,11 @@ type YourModel
```
### Static Group Authorization
-The following are commonly used patterns for static group authorization. For more information on how to tune these examples, please see the [CLI documentation on static group authorization](/cli/graphql/authorization-rules/#user-group-based-data-access).
-* Users belonging to the "Admin" group can CRUD (create, read, update, and delete), others cannot access anything.
+The following are commonly used patterns for static group authorization. For more information on how to tune these examples, please see the [CLI documentation on static group authorization](/cli/graphql/authorization-rules/#user-group-based-data-access).
+
+- Users belonging to the "Admin" group can CRUD (create, read, update, and delete), others cannot access anything.
+
```graphql
type YourModel @model @auth(rules: [{ allow: groups,
groups: ["Admin"] }]) {
@@ -52,7 +56,8 @@ type YourModel @model @auth(rules: [{ allow: groups,
}
```
-* Users belonging to the "Admin" group can create and delete, other signed users can read and update.
+- Users belonging to the "Admin" group can create and delete, other signed users can read and update.
+
```graphql
type YourModel
@model
@@ -67,9 +72,11 @@ type YourModel
```
### Owner and Static Group Combined
-The following are commonly used patterns for combining owner and static group authorization. For more information on how to tune these examples, please see the [CLI documentation on static group authorization](/cli/graphql/authorization-rules#static-group-authorization).
-* Users have their own data, but users who belong to the `Admin` group have access to their data and anyone else in that group. Users in the `Admin` group have the ability to make mutation on behalf of users not in the `Admin` group
+The following are commonly used patterns for combining owner and static group authorization. For more information on how to tune these examples, please see the [CLI documentation on static group authorization](/cli/graphql/authorization-rules#static-group-authorization).
+
+- Users have their own data, but users who belong to the `Admin` group have access to their data and anyone else in that group. Users in the `Admin` group have the ability to make mutation on behalf of users not in the `Admin` group
+
```graphql
type YourModel
@model
@@ -79,16 +86,19 @@ type YourModel
```
### Public Data Access
-The following are commonly used patterns to grant everyone access. For more information on how to tune these examples, please see the [CLI documentation on public data access](/cli/graphql/authorization-rules/#public-data-access).
-* Auth provider is API Key
+The following are commonly used patterns to grant everyone access. For more information on how to tune these examples, please see the [CLI documentation on public data access](/cli/graphql/authorization-rules/#public-data-access).
+
+- Auth provider is API Key
+
```graphql
type YourModel @model @auth(rules: [{ allow: public }]) {
...
}
```
-* Auth provider is IAM
+- Auth provider is IAM
+
```graphql
type YourModel @model @auth(rules: [{ allow: public, provider: iam }]) {
...
@@ -96,15 +106,19 @@ type YourModel @model @auth(rules: [{ allow: public, provider: iam }]) {
```
### Signed-in User Data Access
+
The following are commonly used patterns for private authorization. For more information on how to tune these examples, please see the [CLI documentation on signed-in user data access](https://docs.amplify.aws/cli/graphql/authorization-rules/#signed-in-user-data-access).
-* Cognito user pool authenticated users can CRUD all posts, regardless of who created it. Guest users do not have access.
+- Cognito user pool authenticated users can CRUD all posts, regardless of who created it. Guest users do not have access.
+
```graphql
type YourModel @model @auth(rules: [{ allow: private }]) {
...
}
```
-* IAM authenticated users can CRUD all posts, regardless of who created it. Guest users do not have access:
+
+- IAM authenticated users can CRUD all posts, regardless of who created it. Guest users do not have access:
+
```graphql
type YourModel @model @auth(rules: [{ allow: private, provider: iam }]) {
...
@@ -112,9 +126,11 @@ type YourModel @model @auth(rules: [{ allow: private, provider: iam }]) {
```
### Owner based Authorization with OIDC provider
+
The following are commonly used patterns for owner based authorization using a 3rd party OIDC provider (e.g. Facebook, Google, etc...). For more information on how to tune these examples, please see the [CLI documentation on using an oidc authorization provider](/cli/graphql/authorization-rules/#using-oidc-authorization-provider).
-* Using a 3rd party OIDC provider to achieve owner based authorization.
+- Using a 3rd party OIDC provider to achieve owner based authorization.
+
```graphql
type YourModel
@model
@@ -123,22 +139,24 @@ type YourModel
}
```
-import android0 from "/src/fragments/lib/datastore/android/setup-auth-rules/owner_based_auth_oidc.mdx";
+import android0 from '/src/fragments/lib/datastore/android/setup-auth-rules/owner_based_auth_oidc.mdx';
-
+
-import ios1 from "/src/fragments/lib/datastore/ios/setup-auth-rules/owner_based_auth_oidc.mdx";
+import ios1 from '/src/fragments/lib/datastore/ios/setup-auth-rules/owner_based_auth_oidc.mdx';
-
+
-import flutterOidc from "/src/fragments/lib/datastore/flutter/setup-auth-rules/owner_based_auth_oidc.mdx";
+import flutterOidc from '/src/fragments/lib/datastore/flutter/setup-auth-rules/owner_based_auth_oidc.mdx';
-
+
### Static Group Authorization with OIDC provider
+
The following are commonly used patterns for using `groupClaims` to achieve group based authorization using a 3rd party OIDC provider. For more information on how to tune these examples, please see the [CLI documentation on static group authorization](/cli/graphql/authorization-rules#custom-claims).
-* Using a custom value for `groupClaim` to achieve static group authorization with a 3rd party OIDC provider.
+- Using a custom value for `groupClaim` to achieve static group authorization with a 3rd party OIDC provider.
+
```graphql
type YourModel
@model
@@ -164,21 +182,25 @@ By default, DataStore uses your API's default authorization type specified in th
To enable DataStore to use multiple authorization types based on the model's `@auth` rules, run `amplify update api` to configure additional auth types and deploy by running `amplify push`. Then, configure the "auth mode strategy" when initializing DataStore:
-import ios2 from "/src/fragments/lib/datastore/ios/setup-auth-rules/10_multiauth-snippet.mdx";
+import ios2 from '/src/fragments/lib/datastore/ios/setup-auth-rules/10_multiauth-snippet.mdx';
-
+
-import android3 from "/src/fragments/lib/datastore/android/setup-auth-rules/10_multiauth-snippet.mdx";
+import android3 from '/src/fragments/lib/datastore/android/setup-auth-rules/10_multiauth-snippet.mdx';
-
+
-import js4 from "/src/fragments/lib/datastore/js/setup-auth-rules/10_multiauth-snippet.mdx";
+import js4 from '/src/fragments/lib/datastore/js/setup-auth-rules/10_multiauth-snippet.mdx';
-
+
-import flutterMultiAuth from "/src/fragments/lib/datastore/flutter/setup-auth-rules/10_multiauth-snippet.mdx";
+import reactnative0 from '/src/fragments/lib/datastore/js/setup-auth-rules/10_multiauth-snippet.mdx';
-
+
+
+import flutterMultiAuth from '/src/fragments/lib/datastore/flutter/setup-auth-rules/10_multiauth-snippet.mdx';
+
+
This configuration enables DataStore to synchronize data using the model's `@auth` rule provider for each model.
@@ -186,22 +208,22 @@ This configuration enables DataStore to synchronize data using the model's `@aut
If there are multiple `@auth` rules on a model, the rules will be ranked by priority (see below), and DataStore will attempt the synchronization with each authorization type until one succeeds (or they all fail).
-| Priority | `allow`: AuthStrategy | `provider` |
-|:----------|:-----:|:------:|
-| 1 | `owner` | `userPools` |
-| 2 | `owner` | `oidc` |
-| 3 | `group` | `userPools` |
-| 4 | `group` | `oidc` |
-| 5 | `private` | `userPools` |
-| 6 | `private` | `iam` |
-| 7 | `public` | `iam` |
-| 8 | `public` | `apiKey` |
+| Priority | `allow`: AuthStrategy | `provider` |
+| :------- | :-------------------: | :---------: |
+| 1 | `owner` | `userPools` |
+| 2 | `owner` | `oidc` |
+| 3 | `group` | `userPools` |
+| 4 | `group` | `oidc` |
+| 5 | `private` | `userPools` |
+| 6 | `private` | `iam` |
+| 7 | `public` | `iam` |
+| 8 | `public` | `apiKey` |
If there is **not** an authenticated user session, DataStore will only attempt `public` rules.
If a model has no auth rules defined, DataStore will continue to use the default authorization type from `amplifyconfiguration.json`/`.dart`.
-#### Example with multiple authorization types
+#### Example with multiple authorization types
```graphql
type YourModel
@@ -215,8 +237,13 @@ type YourModel
...
}
```
+
DataStore will attempt to use owner-based authorization first when synchronizing data if there is an authenticated user. If that request fails for some reason, DataStore will attempt the request again with public authorization. If there is **no** authenticated user, public authorization will be used.
-import js5 from "/src/fragments/lib/datastore/js/setup-auth-rules/20_function-auth-snippet.mdx";
+import js5 from '/src/fragments/lib/datastore/js/setup-auth-rules/20_function-auth-snippet.mdx';
+
+
+
+import reactnative1 from '/src/fragments/lib/datastore/js/setup-auth-rules/20_function-auth-snippet.mdx';
-
\ No newline at end of file
+
diff --git a/src/fragments/lib/datastore/native_common/setup-env.mdx b/src/fragments/lib/datastore/native_common/setup-env.mdx
index 95a2106eab2..83921a1bfd6 100644
--- a/src/fragments/lib/datastore/native_common/setup-env.mdx
+++ b/src/fragments/lib/datastore/native_common/setup-env.mdx
@@ -2,18 +2,28 @@ In order to setup your local development environment, you have two options.
### Option 1: Platform integration
-import js1 from "/src/fragments/lib/datastore/js/getting-started/30_platformIntegration.mdx";
+
-
+import js1 from '/src/fragments/lib/datastore/js/getting-started/30_platformIntegration.mdx';
-import flutter3 from "/src/fragments/lib/datastore/flutter/getting-started/30_platformIntegration.mdx";
+
-
+import reactnative0 from '/src/fragments/lib/datastore/react-native/getting-started/30_platformIntegration.mdx';
+
+
+
+import android2 from '/src/fragments/lib/datastore/android/getting-started/30_platformIntegration.mdx';
+
+
+
+import flutter3 from '/src/fragments/lib/datastore/flutter/getting-started/30_platformIntegration.mdx';
+
+
### Option 2: Use Amplify CLI
Instead of using the platform integration, you can alternatively use the Amplify CLI on its own. This option is particularly **useful for existing projects** where Amplify is already configured and you want to add DataStore to it.
-import all0 from "/src/fragments/lib/datastore/native_common/setup-env-cli.mdx";
+import all0 from '/src/fragments/lib/datastore/native_common/setup-env-cli.mdx';
-
\ No newline at end of file
+
diff --git a/src/fragments/lib/datastore/native_common/sync.mdx b/src/fragments/lib/datastore/native_common/sync.mdx
index a2c38a49cc7..eb99183d56f 100644
--- a/src/fragments/lib/datastore/native_common/sync.mdx
+++ b/src/fragments/lib/datastore/native_common/sync.mdx
@@ -93,6 +93,10 @@ import js6 from "/src/fragments/lib/datastore/js/sync/40-clear.mdx";
+import reactnative0 from "/src/fragments/lib/datastore/js/sync/40-clear.mdx";
+
+
+
import ios7 from "/src/fragments/lib/datastore/ios/sync/40-clear.mdx";
@@ -111,6 +115,10 @@ import js10 from "/src/fragments/lib/datastore/js/sync/50-selectiveSync.mdx";
+import reactnative1 from "/src/fragments/lib/datastore/js/sync/50-selectiveSync.mdx";
+
+
+
import android11 from "/src/fragments/lib/datastore/android/sync/50-selectiveSync.mdx";
diff --git a/src/fragments/lib/datastore/react-native/getting-started/30_platformIntegration.mdx b/src/fragments/lib/datastore/react-native/getting-started/30_platformIntegration.mdx
new file mode 100644
index 00000000000..53096656661
--- /dev/null
+++ b/src/fragments/lib/datastore/react-native/getting-started/30_platformIntegration.mdx
@@ -0,0 +1,86 @@
+The fastest way to get started is using the `amplify-app` npx script.
+
+
+
+
+
+
+
+Start with the [React Native CLI](https://reactnative.dev/docs/getting-started):
+
+```bash
+npx react-native@0.68.2 init AmplifyDataStoreRN --version 0.68.2
+cd AmplifyDataStoreRN
+npx amplify-app@latest
+npm install aws-amplify @react-native-community/netinfo @react-native-async-storage/async-storage
+```
+
+You will also need to install the pod dependencies for iOS:
+
+```sh
+npx pod-install
+```
+
+**Use SQLite for enhanced performance (optional)**
+
+React Native CLI apps can now use SQLite with DataStore. SQLite offers considerable performance advantages over the default "AsyncStorage" database.
+
+To enable SQLite with DataStore for enhanced local database performance, follow the steps below:
+
+```sh
+npx react-native@0.68.2 init AmplifyDataStoreRN --version 0.68.2
+cd AmplifyDataStoreRN
+npx amplify-app@latest
+npm install aws-amplify @aws-amplify/datastore-storage-adapter react-native-sqlite-storage @react-native-community/netinfo @react-native-async-storage/async-storage
+npx pod-install
+```
+
+Then configure the SQLite storage adapter with DataStore in your app:
+
+```js
+import { DataStore } from 'aws-amplify';
+import { SQLiteAdapter } from '@aws-amplify/datastore-storage-adapter/SQLiteAdapter';
+
+DataStore.configure({
+ storageAdapter: SQLiteAdapter
+});
+```
+
+
+
+
+Start with the [Expo CLI](https://docs.expo.dev/):
+
+```bash
+expo init AmplifyDataStoreExpo
+cd AmplifyDataStoreExpo
+npx amplify-app@latest
+expo install aws-amplify @react-native-community/netinfo @react-native-async-storage/async-storage
+```
+
+**Use SQLite for enhanced performance (optional)**
+
+Expo built apps can now use SQLite with DataStore. SQLite offers considerable performance advantages over the default "AsyncStorage" database.
+
+To enable SQLite with DataStore for enhanced local database performance, follow the steps below:
+
+```sh
+expo init AmplifyDataStoreExpo
+cd AmplifyDataStoreExpo
+npx amplify-app@latest
+expo install aws-amplify @aws-amplify/datastore-storage-adapter expo-sqlite expo-file-system @react-native-community/netinfo @react-native-async-storage/async-storage
+```
+
+Then configure the SQLite storage adapter with DataStore in your app:
+
+```js
+import { DataStore } from 'aws-amplify';
+import { ExpoSQLiteAdapter } from '@aws-amplify/datastore-storage-adapter/ExpoSQLiteAdapter';
+
+DataStore.configure({
+ storageAdapter: ExpoSQLiteAdapter
+});
+```
+
+
+
diff --git a/src/fragments/lib/graphqlapi/js/complex-objects.mdx b/src/fragments/lib/graphqlapi/js/complex-objects.mdx
index 0594a09e7db..7e88dce2ce5 100644
--- a/src/fragments/lib/graphqlapi/js/complex-objects.mdx
+++ b/src/fragments/lib/graphqlapi/js/complex-objects.mdx
@@ -1,4 +1,7 @@
+
+
## Complex objects
+
Many times you might want to create logical objects that have more complex data, such as images or videos, as part of their structure. For example, you might create a Person type with a profile picture or a Post type that has an associated image. With AWS AppSync, you can model these as GraphQL types, referred to as complex objects. If any of your mutations have a variable with bucket, key, region, mimeType and localUri fields, the SDK uploads the file to Amazon S3 for you.
For a complete working example of this feature, see [aws-amplify-graphql](https://github.com/aws-samples/aws-amplify-graphql) on GitHub.
@@ -12,18 +15,19 @@ amplify add api #Select Cognito User Pool for authorization type
```
When prompted, use the following schema:
+
```graphql
type Todo @model {
- id: ID!
- name: String!
- description: String!
- file: S3Object
+ id: ID!
+ name: String!
+ description: String!
+ file: S3Object
}
type S3Object {
- bucket: String!
- key: String!
- region: String!
+ bucket: String!
+ key: String!
+ region: String!
}
input CreateTodoInput {
@@ -33,9 +37,10 @@ input CreateTodoInput {
file: S3ObjectInput # This input type will be generated for you
}
```
+
Save and run `amplify push` to deploy changes.
-To use complex objects you need AWS Identity and Access Management credentials for reading and writing to Amazon S3 which `amplify add auth` configured in the default setting along with a Cognito user pool. These can be separate from the other auth credentials you use in your AWS AppSync client. Credentials for complex objects are set using the `complexObjectsCredentials` parameter, which you can use with AWS Amplify and the complex objects feature like so:
+To use complex objects you need AWS Identity and Access Management credentials for reading and writing to Amazon S3 which `amplify add auth` configures in the default setting along with a Cognito user pool. These can be separate from the other auth credentials you use in your AWS AppSync client. Credentials for complex objects are set using the `complexObjectsCredentials` parameter, which you can use with AWS Amplify and the complex objects feature like so:
```javascript
const client = new AWSAppSyncClient({
@@ -56,7 +61,7 @@ const client = new AWSAppSyncClient({
const region = aws_config.aws_user_files_s3_bucket_region;
const visibility = 'private';
const { identityId } = await Auth.currentCredentials();
-
+
const key = `${visibility}/${identityId}/${uuid()}${extension && '.'}${extension}`;
file = {
@@ -82,4 +87,4 @@ const client = new AWSAppSyncClient({
})();
```
-When you run the above mutation a record will be in a DynamoDB table for your AppSync API as well as the corresponding file in an S3 bucket.
\ No newline at end of file
+When you run the above mutation, a record will be in a DynamoDB table for your AppSync API as well as the corresponding file in an S3 bucket.
diff --git a/src/fragments/lib/graphqlapi/js/create-or-re-use-existing-backend.mdx b/src/fragments/lib/graphqlapi/js/existing-resources.mdx
similarity index 51%
rename from src/fragments/lib/graphqlapi/js/create-or-re-use-existing-backend.mdx
rename to src/fragments/lib/graphqlapi/js/existing-resources.mdx
index da5eb5c2795..763cab2c436 100644
--- a/src/fragments/lib/graphqlapi/js/create-or-re-use-existing-backend.mdx
+++ b/src/fragments/lib/graphqlapi/js/existing-resources.mdx
@@ -1,29 +1,3 @@
-## Create new AppSync GraphQL API
-
-To create a new GraphQL API, you can use the Amplify CLI `api` category:
-
-```bash
-amplify add api
-```
-
-When prompted, select **GraphQL**.
-
-The CLI prompts will help you to customize the options for your GraphQL API. With the provided options, you can:
-- Choose the API name
-- Choose the default authorization type
-- If using an API key as the authorization type, choose the expiration date for the API key
-- Configure additional authorization types
-- Enable conflict detection (for use with [DataStore](/lib/datastore/getting-started))
-- Choose to either reference an existing GraphQL schema or be given starter GraphQL schema boilerplates
-
-After configuring your GraphQL API options, update your backend:
-
-```bash
-amplify push
-```
-
-The `aws-exports.js` configuration file will be updated with the new API details,
-
## Re-use existing AppSync GraphQL API
As an alternative to automatic configuration, you can manually enter AWS AppSync configuration parameters in your app. Authentication type options are `API_KEY`, `AWS_IAM`, `AMAZON_COGNITO_USER_POOLS` and `OPENID_CONNECT`.
@@ -32,13 +6,14 @@ As an alternative to automatic configuration, you can manually enter AWS AppSync
```javascript
const myAppConfig = {
- // ...
- 'aws_appsync_graphqlEndpoint': 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
- 'aws_appsync_region': 'us-east-1',
- 'aws_appsync_authenticationType': 'API_KEY',
- 'aws_appsync_apiKey': 'da2-xxxxxxxxxxxxxxxxxxxxxxxxxx',
- // ...
-}
+ // ...
+ aws_appsync_graphqlEndpoint:
+ 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
+ aws_appsync_region: 'us-east-1',
+ aws_appsync_authenticationType: 'API_KEY',
+ aws_appsync_apiKey: 'da2-xxxxxxxxxxxxxxxxxxxxxxxxxx'
+ // ...
+};
Amplify.configure(myAppConfig);
```
@@ -47,12 +22,13 @@ Amplify.configure(myAppConfig);
```javascript
const myAppConfig = {
- // ...
- 'aws_appsync_graphqlEndpoint': 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
- 'aws_appsync_region': 'us-east-1',
- 'aws_appsync_authenticationType': 'AWS_IAM',
- // ...
-}
+ // ...
+ aws_appsync_graphqlEndpoint:
+ 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
+ aws_appsync_region: 'us-east-1',
+ aws_appsync_authenticationType: 'AWS_IAM'
+ // ...
+};
Amplify.configure(myAppConfig);
```
@@ -61,12 +37,13 @@ Amplify.configure(myAppConfig);
```javascript
const myAppConfig = {
- // ...
- 'aws_appsync_graphqlEndpoint': 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
- 'aws_appsync_region': 'us-east-1',
- 'aws_appsync_authenticationType': 'AMAZON_COGNITO_USER_POOLS', // You have configured Auth with Amazon Cognito User Pool ID and Web Client Id
- // ...
-}
+ // ...
+ aws_appsync_graphqlEndpoint:
+ 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
+ aws_appsync_region: 'us-east-1',
+ aws_appsync_authenticationType: 'AMAZON_COGNITO_USER_POOLS' // You have configured Auth with Amazon Cognito User Pool ID and Web Client Id
+ // ...
+};
Amplify.configure(myAppConfig);
```
@@ -75,12 +52,13 @@ Amplify.configure(myAppConfig);
```javascript
const myAppConfig = {
- // ...
- 'aws_appsync_graphqlEndpoint': 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
- 'aws_appsync_region': 'us-east-1',
- 'aws_appsync_authenticationType': 'OPENID_CONNECT', // Before calling API.graphql(...) is required to do Auth.federatedSignIn(...) check authentication guide for details.
- // ...
-}
+ // ...
+ aws_appsync_graphqlEndpoint:
+ 'https://xxxxxx.appsync-api.us-east-1.amazonaws.com/graphql',
+ aws_appsync_region: 'us-east-1',
+ aws_appsync_authenticationType: 'OPENID_CONNECT' // Before calling API.graphql(...) is required to do Auth.federatedSignIn(...) check authentication guide for details.
+ // ...
+};
Amplify.configure(myAppConfig);
```
@@ -91,17 +69,16 @@ Amplify.configure(myAppConfig);
```javascript
const myAppConfig = {
- // ...
- 'aws_appsync_graphqlEndpoint': 'https://api.yourdomain.com/graphql',
- 'aws_appsync_region': 'us-east-1',
- 'aws_appsync_authenticationType': 'API_KEY' // All auth modes are supported
- // ...
-}
+ // ...
+ aws_appsync_graphqlEndpoint: 'https://api.yourdomain.com/graphql',
+ aws_appsync_region: 'us-east-1',
+ aws_appsync_authenticationType: 'API_KEY' // All auth modes are supported
+ // ...
+};
Amplify.configure(myAppConfig);
```
-
## Using a non-AppSync GraphQL Server
To access a non-AppSync GraphQL API with your app, you need to configure the endpoint URL in your app’s configuration. Add the following line to your setup:
@@ -109,8 +86,8 @@ To access a non-AppSync GraphQL API with your app, you need to configure the end
```js
import { Amplify, API } from 'aws-amplify';
import awsconfig from './aws-exports';
-
-// Considering you have an existing aws-exports.js configuration file
+
+// Considering you have an existing aws-exports.js configuration file
Amplify.configure(awsconfig);
// Configure a custom GraphQL endpoint
@@ -129,7 +106,7 @@ When working with a non-AppSync GraphQL endpoint, you may need to set request he
Amplify.configure({
API: {
graphql_headers: async () => ({
- 'My-Custom-Header': 'my value'
+ 'My-Custom-Header': 'my value'
})
}
});
diff --git a/src/fragments/lib/graphqlapi/js/subscribe-data.mdx b/src/fragments/lib/graphqlapi/js/subscribe-data.mdx
index 05f6c4e511f..9a9875c082d 100644
--- a/src/fragments/lib/graphqlapi/js/subscribe-data.mdx
+++ b/src/fragments/lib/graphqlapi/js/subscribe-data.mdx
@@ -1,3 +1,5 @@
+
+
## Using Amplify GraphQL client
Subscriptions is a GraphQL feature allowing the server to send data to its clients when a specific event happens. You can enable real-time data integration in your app with a subscription.
diff --git a/src/fragments/lib/ios.mdx b/src/fragments/lib/ios.mdx
index e852c6567df..4fc22e12257 100644
--- a/src/fragments/lib/ios.mdx
+++ b/src/fragments/lib/ios.mdx
@@ -1,5 +1,7 @@
If you already have existing resources to add to your application and want to bypass the tutorial, see [Use existing AWS resources](/lib/project-setup/use-existing-resources).
+
+
**Amplify libraries should be used for all new cloud connected applications.** If you are currently using the AWS Mobile SDK for iOS, you can access the documentation [here](/sdk).
diff --git a/src/fragments/lib/js.mdx b/src/fragments/lib/js.mdx
index 65e12ac14c9..1cdf7a0f8dd 100644
--- a/src/fragments/lib/js.mdx
+++ b/src/fragments/lib/js.mdx
@@ -11,6 +11,5 @@ What's next? Here are some things you can add to your app:
- [Serverless APIs](/lib/graphqlapi/getting-started)
- [Analytics](/lib/analytics/getting-started)
- [AI/ML](/lib/predictions/getting-started)
-- [Push Notification](/lib/push-notifications/getting-started)
- [PubSub](/lib/pubsub/getting-started)
- [AR/VR](/lib/xr/getting-started)
diff --git a/src/fragments/lib/project-setup/js/getting-started.mdx b/src/fragments/lib/project-setup/js/getting-started.mdx
new file mode 100644
index 00000000000..464828a1f4e
--- /dev/null
+++ b/src/fragments/lib/project-setup/js/getting-started.mdx
@@ -0,0 +1,48 @@
+import js0 from '/src/fragments/start/getting-started/angular/setup.mdx';
+import js1 from '/src/fragments/start/getting-started/ionic/setup.mdx';
+import js2 from '/src/fragments/start/getting-started/react/setup.mdx';
+import js3 from '/src/fragments/start/getting-started/vue/setup.mdx';
+import js5 from '/src/fragments/start/getting-started/next/setup.mdx';
+import js6 from '/src/fragments/start/getting-started/vanillajs/setup.mdx';
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/fragments/lib/pubsub/js/getting-started.mdx b/src/fragments/lib/pubsub/js/getting-started.mdx
index ccada3076b1..855806abeff 100644
--- a/src/fragments/lib/pubsub/js/getting-started.mdx
+++ b/src/fragments/lib/pubsub/js/getting-started.mdx
@@ -1,14 +1,17 @@
The AWS Amplify PubSub category provides connectivity with cloud-based message-oriented middleware. You can use PubSub to pass messages between your app instances and your app's backend creating real-time interactive experiences.
-PubSub is available with **AWS IoT** and **Generic MQTT Over WebSocket Providers**.
+PubSub is available with **AWS IoT** and **Generic MQTT Over WebSocket Providers**.
+
+
+
-With AWS IoT, AWS Amplify's PubSub automatically signs your HTTP requests when sending your messages.
+ With AWS IoT, AWS Amplify's PubSub automatically signs your HTTP requests when sending your messages.
## AWS IoT
-When used with `AWSIoTProvider`, PubSub is capable of signing request according to [Signature Version 4](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html).
+When used with `AWSIoTProvider`, PubSub is capable of signing request according to [Signature Version 4](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html).
To use in your app, import `AWSIoTProvider`:
@@ -21,34 +24,38 @@ Define your endpoint and region in your configuration:
```javascript
// Apply plugin with configuration
-Amplify.addPluggable(new AWSIoTProvider({
- aws_pubsub_region: '',
- aws_pubsub_endpoint: 'wss://xxxxxxxxxxxxx.iot..amazonaws.com/mqtt',
- }));
+Amplify.addPluggable(
+ new AWSIoTProvider({
+ aws_pubsub_region: '',
+ aws_pubsub_endpoint:
+ 'wss://xxxxxxxxxxxxx.iot..amazonaws.com/mqtt'
+ })
+);
```
-Find your `aws_pubsub_endpoint` by logging onto your **AWS Console**, choose **IoT Core** from the list of services, then choose *Settings* from the left navigation pane.
+Find your `aws_pubsub_endpoint` by logging onto your **AWS Console**, choosing **IoT Core** from the list of services and then choosing _Settings_ from the left navigation pane.
### Step 1: Create IAM policies for AWS IoT
-To use PubSub with AWS IoT, you will need to create the necessary IAM policies in the AWS IoT Console, and attach them to your Amazon Cognito Identity.
+To use PubSub with AWS IoT, you will need to create the necessary IAM policies in the AWS IoT Console, and attach them to your Amazon Cognito Identity.
-Go to IoT Core and choose *Secure* from the left navigation pane, and then *Policies* from the dropdown menu. Next, click *Create*. The following `myIoTPolicy` policy will allow full access to all the topics.
+Go to IoT Core and choose _Secure_ from the left navigation pane, and then _Policies_ from the dropdown menu. Next, click _Create_. The following `myIoTPolicy` policy will allow full access to all the topics.

### Step 2: Attach your policy to your Amazon Cognito Identity
-The next step is attaching the policy to your *Cognito Identity*.
+The next step is attaching the policy to your _Cognito Identity_.
You can retrieve the `Cognito Identity Id` of a logged in user with Auth Module:
+
```javascript
- Auth.currentCredentials().then((info) => {
- const cognitoIdentityId = info.identityId;
- });
+Auth.currentCredentials().then((info) => {
+ const cognitoIdentityId = info.identityId;
+});
```
-Then, you need to send your *Cognito Identity Id* to the AWS backend and attach `myIoTPolicy`. You can do this with the following [AWS CLI](https://aws.amazon.com/cli/) command:
+Then, you need to send your _Cognito Identity Id_ to the AWS backend and attach `myIoTPolicy`. You can do this with the following [AWS CLI](https://aws.amazon.com/cli/) command:
```bash
aws iot attach-policy --policy-name 'myIoTPolicy' --target ''
@@ -59,10 +66,10 @@ aws iot attach-policy --policy-name 'myIoTPolicy' --target '-`.
Select the **Resources** tab and tap on `AuthRole` **Physical ID**.
-The IAM console will be opened in a new tab. Once there, tap on the button **Attach Policies**, then search `AWSIoTDataAccess` and `AWSIoTConfigAccess`, select them and tap on **Attach policy**.
+The IAM console will be opened in a new tab. Once there, tap on the button **Attach Policies**, then search `AWSIoTDataAccess` and `AWSIoTConfigAccess`, select them and tap on **Attach policy**.
+
+If you are using Cognito Groups, the IAM role associated with that group also need the `AWSIoTDataAccess` and `AWSIoTConfigAccess` policies attached to it.
-If you are using Cognito Groups the IAM role associated with that group also need the `AWSIoTDataAccess` and `AWSIoTConfigAccess` policies attached to it.
-
> Failing to grant IoT related permissions to the Cognito Authenticated Role will result in errors similar to the following in your browser console: `errorCode: 8, errorMessage: AMQJS0008I Socket closed.`
## Third Party MQTT Providers
@@ -71,15 +78,18 @@ Import PubSub module and related service provider plugin to your app:
```javascript
import { PubSub } from 'aws-amplify';
-import { MqttOverWSProvider } from "@aws-amplify/pubsub/lib/Providers";
+import { MqttOverWSProvider } from '@aws-amplify/pubsub/lib/Providers';
```
To configure your service provider with a service endpoint, add following code:
+
```javascript
// Apply plugin with configuration
-Amplify.addPluggable(new MqttOverWSProvider({
- aws_pubsub_endpoint: 'wss://iot.eclipse.org:443/mqtt',
-}));
+Amplify.addPluggable(
+ new MqttOverWSProvider({
+ aws_pubsub_endpoint: 'wss://iot.eclipse.org:443/mqtt'
+ })
+);
```
You can integrate any MQTT Over WebSocket provider with your app. Click [here](https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html#mqtt-ws) to learn more about MQTT Over WebSocket.
@@ -95,18 +105,23 @@ import { AWSIoTProvider } from '@aws-amplify/pubsub';
const pubsub = new PubSub({});
// Apply plugin with configuration
-pubsub.addPluggable(new AWSIoTProvider({
- aws_pubsub_region: '',
- aws_pubsub_endpoint: 'wss://xxxxxxxxxxxxx.iot..amazonaws.com/mqtt',
-}));
+pubsub.addPluggable(
+ new AWSIoTProvider({
+ aws_pubsub_region: '',
+ aws_pubsub_endpoint:
+ 'wss://xxxxxxxxxxxxx.iot..amazonaws.com/mqtt'
+ })
+);
// Remove plugin using the provider name
pubsub.removePluggable('AWSIoTProvider');
// Apply plugin with new configuration
-pubsub.addPluggable(new AWSIoTProvider({
- aws_pubsub_region: '',
- aws_pubsub_endpoint: 'wss://xxxxxxxxxxxxx.iot..amazonaws.com/mqtt',
-}));
-
+pubsub.addPluggable(
+ new AWSIoTProvider({
+ aws_pubsub_region: '',
+ aws_pubsub_endpoint:
+ 'wss://xxxxxxxxxxxxx.iot..amazonaws.com/mqtt'
+ })
+);
```
diff --git a/src/fragments/lib/push-notifications/js/reactnative.mdx b/src/fragments/lib/push-notifications/js/reactnative.mdx
deleted file mode 100644
index 8dafee77010..00000000000
--- a/src/fragments/lib/push-notifications/js/reactnative.mdx
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-Push Notifications are currently supported only for **React Native**. For handling Web Push Notifications with Service Workers, visit our [Service Workers Guide](/lib/utilities/serviceworker#handling-a-push-notification).
-
-
diff --git a/src/fragments/lib/reactnative.mdx b/src/fragments/lib/reactnative.mdx
new file mode 100644
index 00000000000..65e12ac14c9
--- /dev/null
+++ b/src/fragments/lib/reactnative.mdx
@@ -0,0 +1,16 @@
+## Amplify JavaScript
+
+The Amplify JavaScript libraries are supported for different web and mobile frameworks including React, React Native, Angular, Ionic, and Vue. It is recommended that you first complete the [Getting Started](https://docs.amplify.aws/start/q/integration/js/) guide for Amplify JavaScript.
+
+What's next? Here are some things you can add to your app:
+
+- [Authentication](/lib/auth/getting-started)
+- [DataStore](/lib/datastore/getting-started)
+- [User File Storage](/lib/storage/getting-started)
+- [Geo](/lib/geo/getting-started)
+- [Serverless APIs](/lib/graphqlapi/getting-started)
+- [Analytics](/lib/analytics/getting-started)
+- [AI/ML](/lib/predictions/getting-started)
+- [Push Notification](/lib/push-notifications/getting-started)
+- [PubSub](/lib/pubsub/getting-started)
+- [AR/VR](/lib/xr/getting-started)
diff --git a/src/fragments/lib/restapi/js/authz.mdx b/src/fragments/lib/restapi/js/authz.mdx
index 3c6503d5d0c..7dd7870ed65 100644
--- a/src/fragments/lib/restapi/js/authz.mdx
+++ b/src/fragments/lib/restapi/js/authz.mdx
@@ -1,5 +1,3 @@
-## Request headers
-
When working with a REST endpoint, you may need to set request headers for authorization purposes. This is done by passing a `custom_header` function into the configuration:
```javascript
@@ -7,10 +5,10 @@ Amplify.configure({
API: {
endpoints: [
{
- name: "sampleCloudApi",
- endpoint: "https://xyz.execute-api.us-east-1.amazonaws.com/Development",
- custom_header: async () => {
- return { Authorization : 'token' }
+ name: 'sampleCloudApi',
+ endpoint: 'https://xyz.execute-api.us-east-1.amazonaws.com/Development',
+ custom_header: async () => {
+ return { Authorization: 'token' };
// Alternatively, with Cognito User Pools use this:
// return { Authorization: `Bearer ${(await Auth.currentSession()).getAccessToken().getJwtToken()}` }
// return { Authorization: `Bearer ${(await Auth.currentSession()).getIdToken().getJwtToken()}` }
@@ -23,13 +21,13 @@ Amplify.configure({
## Note related to use Access Token or ID Token
-The ID Token contains claims about the identity of the authenticated user such as name, email, and phone_number. It could have custom claims as well, for example using [Amplify CLI](https://docs.amplify.aws/cli/usage/lambda-triggers#override-id-token-claims). On the Amplify Authentication category you can retrieve the Id Token using:
+The ID Token contains claims about the identity of the authenticated user such as name, email, and phone_number. It could have custom claims as well, for example using [Amplify CLI](https://docs.amplify.aws/cli/usage/lambda-triggers#override-id-token-claims). On the Amplify Authentication category you can retrieve the Id Token using:
```javascript
(await Auth.currentSession()).getIdToken().getJwtToken();
-```
+```
-The Access Token contains scopes and groups and is used to grant access to authorized resources. [This is a tutorial for enabling custom scopes.](https://aws.amazon.com/premiumsupport/knowledge-center/cognito-custom-scopes-api-gateway/). You can retrieve the Access Token using
+The Access Token contains scopes and groups and is used to grant access to authorized resources. [This is a tutorial for enabling custom scopes.](https://aws.amazon.com/premiumsupport/knowledge-center/cognito-custom-scopes-api-gateway/). You can retrieve the Access Token using
```javascript
(await Auth.currentSession()).getAccessToken().getJwtToken();
@@ -39,14 +37,14 @@ The Access Token contains scopes and groups and is used to grant access to autho
To use custom headers on your HTTP request, you need to add these to Amazon API Gateway first. For more info about configuring headers, please visit [Amazon API Gateway Developer Guide](http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html)
-If you have used Amplify CLI to create your API, you can enable custom headers by following above steps:
+If you have used Amplify CLI to create your API, you can enable custom headers by following above steps:
1. Visit [Amazon API Gateway console](https://aws.amazon.com/api-gateway/).
-3. On Amazon API Gateway console, click on the path you want to configure (e.g. /{proxy+})
-4. Then click the *Actions* dropdown menu and select **Enable CORS**
-5. Add your custom header (e.g. my-custom-header) on the text field Access-Control-Allow-Headers, separated by commas, like: 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,my-custom-header'.
-6. Click on 'Enable CORS and replace existing CORS headers' and confirm.
-7. Finally, similar to step 3, click the Actions drop-down menu and then select **Deploy API**. Select **Development** on deployment stage and then **Deploy**. (Deployment could take a couple of minutes).
+2. On Amazon API Gateway console, click on the path you want to configure (e.g. /{proxy+})
+3. Then click the _Actions_ dropdown menu and select **Enable CORS**
+4. Add your custom header (e.g. my-custom-header) on the text field Access-Control-Allow-Headers, separated by commas, like: 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,my-custom-header'.
+5. Click on 'Enable CORS and replace existing CORS headers' and confirm.
+6. Finally, similar to step 3, click the Actions drop-down menu and then select **Deploy API**. Select **Development** on deployment stage and then **Deploy**. (Deployment could take a couple of minutes).
## Unauthenticated Requests
@@ -57,16 +55,18 @@ You can use the API category to access API Gateway endpoints that don't require
You can use the JWT token provided by the Authentication API to authenticate against API Gateway directly when using a custom authorizer.
```javascript
-async function postData() {
- const apiName = 'MyApiName';
- const path = '/path';
- const myInit = {
- headers: {
- Authorization: `Bearer ${(await Auth.currentSession()).getIdToken().getJwtToken()}`,
- },
- };
-
- return await API.post(apiName, path, myInit);
+async function postData() {
+ const apiName = 'MyApiName';
+ const path = '/path';
+ const myInit = {
+ headers: {
+ Authorization: `Bearer ${(await Auth.currentSession())
+ .getIdToken()
+ .getJwtToken()}`
+ }
+ };
+
+ return await API.post(apiName, path, myInit);
}
postData();
diff --git a/src/fragments/lib/restapi/js/cancel.mdx b/src/fragments/lib/restapi/js/cancel.mdx
index 6c06bb40d84..68f36a4314b 100644
--- a/src/fragments/lib/restapi/js/cancel.mdx
+++ b/src/fragments/lib/restapi/js/cancel.mdx
@@ -1,5 +1,3 @@
-## CANCEL API requests
-
You may cancel any request made through API category by keeping a reference to the promise returned.
```javascript
@@ -11,7 +9,8 @@ try {
console.log(error);
// If the error is because the request was cancelled we can confirm here.
if(API.isCancel(error)) {
- console.log(error.message); // "my message for cancellation"
+ // "my message for cancellation"
+ console.log(error.message);
// handle user cancellation logic
}
}
@@ -26,10 +25,10 @@ You need to ensure that the promise returned from `API.get()` or any other API c
```javascript
async function makeAPICall() {
- return API.get(myApiName, myPath, myInit);
+ return API.get(myApiName, myPath, myInit);
}
const promise = makeAPICall();
// The following will NOT cancel the request.
-API.cancel(promise, "my error message");
+API.cancel(promise, 'my error message');
```
diff --git a/src/fragments/lib/restapi/js/delete.mdx b/src/fragments/lib/restapi/js/delete.mdx
index 74f8243c244..57fc04becf3 100644
--- a/src/fragments/lib/restapi/js/delete.mdx
+++ b/src/fragments/lib/restapi/js/delete.mdx
@@ -1,18 +1,19 @@
## DELETE data
+
+
```javascript
const apiName = 'MyApiName'; // replace this with your api name.
const path = '/path'; //replace this with the path you have configured on your API
-const myInit = { // OPTIONAL
- headers: {}, // OPTIONAL
+const myInit = {
+ headers: {} // OPTIONAL
};
-API
- .del(apiName, path, myInit)
- .then(response => {
+API.del(apiName, path, myInit)
+ .then((response) => {
// Add your code here
})
- .catch(error => {
+ .catch((error) => {
console.log(error.response);
});
```
@@ -20,13 +21,13 @@ API
Example with async/await
```javascript
-async function deleteData() {
- const apiName = 'MyApiName';
- const path = '/path';
- const myInit = { // OPTIONAL
- headers: {} // OPTIONAL
- }
- return await API.del(apiName, path, myInit);
+async function deleteData() {
+ const apiName = 'MyApiName';
+ const path = '/path';
+ const myInit = {
+ headers: {} // OPTIONAL
+ };
+ return await API.del(apiName, path, myInit);
}
deleteData();
@@ -34,14 +35,16 @@ deleteData();
Access body in the Lambda function
+
+
```javascript
// using a basic lambda handler
exports.handler = (event, context) => {
console.log('body: ', event.body);
-}
+};
// using serverless express
app.delete('/myendpoint', function(req, res) {
console.log('body: ', req.body);
});
-```
\ No newline at end of file
+```
diff --git a/src/fragments/lib/restapi/js/fetch.mdx b/src/fragments/lib/restapi/js/fetch.mdx
index 8a408b9ffd4..0c4628c619a 100644
--- a/src/fragments/lib/restapi/js/fetch.mdx
+++ b/src/fragments/lib/restapi/js/fetch.mdx
@@ -4,39 +4,38 @@ To invoke an endpoint, you need to set `apiName`, `path` and `headers` parameter
```javascript
const apiName = 'MyApiName';
-const path = '/path';
-const myInit = { // OPTIONAL
- headers: {}, // OPTIONAL
- response: true, // OPTIONAL (return the entire Axios response object instead of only response.data)
- queryStringParameters: { // OPTIONAL
- name: 'param',
- },
+const path = '/path';
+const myInit = {
+ headers: {}, // OPTIONAL
+ response: true, // OPTIONAL (return the entire Axios response object instead of only response.data)
+ queryStringParameters: {
+ name: 'param' // OPTIONAL
+ }
};
-API
- .get(apiName, path, myInit)
- .then(response => {
+API.get(apiName, path, myInit)
+ .then((response) => {
// Add your code here
})
- .catch(error => {
+ .catch((error) => {
console.log(error.response);
- });
+ });
```
Example with async/await
```javascript
-function getData() {
+function getData() {
const apiName = 'MyApiName';
const path = '/path';
- const myInit = { // OPTIONAL
- headers: {}, // OPTIONAL
+ const myInit = {
+ headers: {} // OPTIONAL
};
return API.get(apiName, path, myInit);
}
-(async function () {
+(async function() {
const response = await getData();
})();
```
@@ -47,42 +46,42 @@ To use query parameters with `get` method, you can pass them in `queryStringPara
```javascript
const items = await API.get('myCloudApi', '/items', {
- 'queryStringParameters': {
- 'order': 'byPrice'
+ queryStringParameters: {
+ order: 'byPrice'
}
});
```
## HEAD
+
+
```javascript
const apiName = 'MyApiName'; // replace this with your api name.
const path = '/path'; //replace this with the path you have configured on your API
-const myInit = { // OPTIONAL
- headers: {}, // OPTIONAL
+const myInit = {
+ headers: {} // OPTIONAL
};
-API
- .head(apiName, path, myInit)
- .then(response => {
- // Add your code here
- });
+API.head(apiName, path, myInit).then((response) => {
+ // Add your code here
+});
```
Example with async/await:
```javascript
-function head() {
+function head() {
const apiName = 'MyApiName';
const path = '/path';
- const myInit = { // OPTIONAL
- headers: {}, // OPTIONAL
+ const myInit = {
+ headers: {} // OPTIONAL
};
return API.head(apiName, path, myInit);
}
-(async function () {
+(async function() {
const response = await head();
})();
```
@@ -91,13 +90,13 @@ function head() {
> To learn more about Lambda Proxy Integration, please visit [Amazon API Gateway Developer Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-lambda.html).
-If you are using a REST API which is generated with Amplify CLI, your backend is created with Lambda Proxy Integration, and you can access your query parameters & body within your Lambda function via the *event* object:
+If you are using a REST API which is generated with Amplify CLI, your backend is created with Lambda Proxy Integration, and you can access your query parameters & body within your Lambda function via the _event_ object:
```javascript
exports.handler = function(event, context, callback) {
- console.log(event.queryStringParameters);
- console.log('body: ', event.body);
-}
+ console.log(event.queryStringParameters);
+ console.log('body: ', event.body);
+};
```
Alternatively, you can update your backend file which is located at `amplify/backend/function/[your-lambda-function]/app.js` with the middleware:
@@ -135,7 +134,7 @@ By default, calling an API with AWS Amplify parses a JSON response. If you have
```javascript
let file = await API.get('myCloudApi', '/items', {
- 'responseType': 'blob',
+ responseType: 'blob'
});
```
diff --git a/src/fragments/lib/restapi/js/getting-started.mdx b/src/fragments/lib/restapi/js/getting-started.mdx
index 2355a1f0d4f..9ecc99ae8c3 100644
--- a/src/fragments/lib/restapi/js/getting-started.mdx
+++ b/src/fragments/lib/restapi/js/getting-started.mdx
@@ -53,14 +53,10 @@ import { Amplify, API } from 'aws-amplify';
Amplify.configure({
// OPTIONAL - if your API requires authentication
Auth: {
- // REQUIRED - Amazon Cognito Identity Pool ID
- identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
- // REQUIRED - Amazon Cognito Region
- region: 'XX-XXXX-X',
- // OPTIONAL - Amazon Cognito User Pool ID
- userPoolId: 'XX-XXXX-X_abcd1234',
- // OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
- userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
+ identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab', // REQUIRED - Amazon Cognito Identity Pool ID
+ region: 'XX-XXXX-X', // REQUIRED - Amazon Cognito Region
+ userPoolId: 'XX-XXXX-X_abcd1234', // OPTIONAL - Amazon Cognito User Pool ID
+ userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3', // OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
},
API: {
endpoints: [
@@ -80,6 +76,8 @@ Amplify.configure({
### AWS Regional Endpoints
+
+
You can utilize regional endpoints by passing in the *service* and *region* information to the configuration. See [AWS Regions and Endpoints](https://docs.aws.amazon.com/general/latest/gr/rande.html). The example below defines a [Lambda invocation](https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html) in the `us-east-1` region:
```javascript
@@ -104,8 +102,4 @@ API: {
**Configuring Amazon Cognito Regional Endpoints:** To call regional service endpoints, your Amazon Cognito role needs to be configured with appropriate access for the related service. See [AWS Cognito Documentation](https://docs.aws.amazon.com/cognito/latest/developerguide/iam-roles.html) for more details.
-
-
-## API Reference
-
-For the complete API documentation for API module, visit our [API Reference](https://aws-amplify.github.io/amplify-js/api/classes/apiclass.html).
+
\ No newline at end of file
diff --git a/src/fragments/lib/restapi/js/update.mdx b/src/fragments/lib/restapi/js/update.mdx
index 21c00bf7975..985b42b4f8e 100644
--- a/src/fragments/lib/restapi/js/update.mdx
+++ b/src/fragments/lib/restapi/js/update.mdx
@@ -6,16 +6,15 @@ Posts data to the API endpoint:
const apiName = 'MyApiName'; // replace this with your api name.
const path = '/path'; //replace this with the path you have configured on your API
const myInit = {
- body: {}, // replace this with attributes you need
- headers: {}, // OPTIONAL
+ body: {}, // replace this with attributes you need
+ headers: {} // OPTIONAL
};
-API
- .post(apiName, path, myInit)
- .then(response => {
+API.post(apiName, path, myInit)
+ .then((response) => {
// Add your code here
})
- .catch(error => {
+ .catch((error) => {
console.log(error.response);
});
```
@@ -23,15 +22,15 @@ API
Example with async/await
```javascript
-async function postData() {
- const apiName = 'MyApiName';
- const path = '/path';
- const myInit = { // OPTIONAL
- body: {}, // replace this with attributes you need
- headers: {}, // OPTIONAL
- };
-
- return await API.post(apiName, path, myInit);
+async function postData() {
+ const apiName = 'MyApiName';
+ const path = '/path';
+ const myInit = {
+ body: {}, // replace this with attributes you need
+ headers: {} // OPTIONAL
+ };
+
+ return await API.post(apiName, path, myInit);
}
postData();
@@ -45,16 +44,15 @@ When used together with a REST API, `put()` method can be used to create or upda
const apiName = 'MyApiName'; // replace this with your api name.
const path = '/path'; // replace this with the path you have configured on your API
const myInit = {
- body: {}, // replace this with attributes you need
- headers: {}, // OPTIONAL
+ body: {}, // replace this with attributes you need
+ headers: {} // OPTIONAL
};
-API
- .put(apiName, path, myInit)
- .then(response => {
+API.put(apiName, path, myInit)
+ .then((response) => {
// Add your code here
})
- .catch(error => {
+ .catch((error) => {
console.log(error.response);
});
```
@@ -62,15 +60,15 @@ API
Example with async/await:
```javascript
-async function putData() {
- const apiName = 'MyApiName';
- const path = '/path';
- const myInit = { // OPTIONAL
- body: {}, // replace this with attributes you need
- headers: {}, // OPTIONAL
- };
-
- return await API.put(apiName, path, myInit);
+async function putData() {
+ const apiName = 'MyApiName';
+ const path = '/path';
+ const myInit = {
+ body: {}, // replace this with attributes you need
+ headers: {} // OPTIONAL
+ };
+
+ return await API.put(apiName, path, myInit);
}
putData();
@@ -82,7 +80,7 @@ Access body in the Lambda function
// using a basic lambda handler
exports.handler = (event, context) => {
console.log('body: ', event.body);
-}
+};
// using serverless express
app.put('/myendpoint', function(req, res) {
@@ -94,10 +92,10 @@ Update a record:
```javascript
const params = {
- body: {
- itemId: '12345',
- itemDesc: ' update description'
- },
+ body: {
+ itemId: '12345',
+ itemDesc: ' update description'
+ }
};
const apiResponse = await API.put('MyTableCRUD', '/manage-items', params);
@@ -105,14 +103,16 @@ const apiResponse = await API.put('MyTableCRUD', '/manage-items', params);
## Access body in Lambda proxy function
+
+
```javascript
// using a basic lambda handler
exports.handler = (event, context) => {
console.log('body: ', event.body);
-}
+};
// using serverless express
app.post('/myendpoint', function(req, res) {
console.log('body: ', req.body);
});
-```
\ No newline at end of file
+```
diff --git a/src/fragments/lib/storage/android/download.mdx b/src/fragments/lib/storage/android/download.mdx
index 518d06f9c97..d1bb9e57bb0 100644
--- a/src/fragments/lib/storage/android/download.mdx
+++ b/src/fragments/lib/storage/android/download.mdx
@@ -1,5 +1,7 @@
### Download to file
+
+
If you uploaded the data using the key `ExampleKey`, you can retrieve the data using `Amplify.Storage.downloadFile`.
diff --git a/src/fragments/lib/storage/existing-resources.mdx b/src/fragments/lib/storage/existing-resources.mdx
index 6a05527ca20..cb7dce4bb0f 100644
--- a/src/fragments/lib/storage/existing-resources.mdx
+++ b/src/fragments/lib/storage/existing-resources.mdx
@@ -6,26 +6,27 @@ amplify import storage
For more details, see how to [Use an existing S3 bucket or DynamoDB table](/cli/storage/import).
-If you are not using the Amplify CLI, an existing Amazon S3 bucket can be used by referencing it in your `amplifyconfiguration.json` file.
+If you are not using the Amplify CLI, an existing Amazon S3 bucket can be used by referencing it in your `amplifyconfiguration` file.
-When you are not using Amplify CLI, adding existing Amazon S3 bucket to your application may require configuring bucket access permissions. e.g. Enabling read/write access to the cognito user pool that you are using with the Amplify Auth category.
+ When you are not using Amplify CLI, adding existing Amazon S3 bucket to your application may require configuring bucket access permissions. e.g. Enabling read/write access to the cognito user pool that you are using with the Amplify Auth category.
```json
{
- "storage": {
- "plugins": {
- "awsS3StoragePlugin": {
- "bucket": "[BUCKET NAME]",
- "region": "[REGION]"
- }
- }
+ "storage": {
+ "plugins": {
+ "awsS3StoragePlugin": {
+ "bucket": "[BUCKET NAME]",
+ "region": "[REGION]"
+ }
}
+ }
}
```
- **bucket**: Name of the bucket to use for storage
-- **region**: AWS Region where the bucket is provisioned (e.g. *us-east-1*)
+- **region**: AWS Region where the bucket is provisioned (e.g. _us-east-1_)
+
-Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see [Install Amplify Libraries](/lib/project-setup/create-application#n2-install-amplify-libraries).
\ No newline at end of file
+Note that before you can add an AWS resource to your application, the application must have the Amplify libraries installed. If you need to perform this step, see [Install Amplify Libraries](/lib/project-setup/create-application#n2-install-amplify-libraries).
diff --git a/src/fragments/lib/storage/js/browser-uploads.mdx b/src/fragments/lib/storage/js/browser-uploads.mdx
new file mode 100644
index 00000000000..0db107cd016
--- /dev/null
+++ b/src/fragments/lib/storage/js/browser-uploads.mdx
@@ -0,0 +1,26 @@
+## Browser uploads
+
+Upload an image in the browser:
+
+```javascript
+async function onChange(e) {
+ const file = e.target.files[0];
+ try {
+ await Storage.put(file.name, file, {
+ contentType: "image/png", // contentType is optional
+ });
+ } catch (error) {
+ console.log("Error uploading file: ", error);
+ }
+}
+
+;
+```
+
+
+
+Note: 'contentType' is metadata (saved under the key 'Content-Type') for the S3 object and does not determine the 'Type' in the AWS S3 Console. If a file extension is not provided in the key of the uploaded object, the S3 console's 'Type' field will be emitted. Otherwise, the 'Type' will be populated to match the given extension of the key. The behavior of how the S3 object is treated will be based on 'contentType' in the metadata and not the 'Type'.
+
+For example: uploading a file with the key "example.jpg" will result in the 'Type' being set as "jpg", but the 'contentType' in metadata will determine it's behavior so setting it as "text/html" will result in the file being treated as an HTML file regardless of displayed 'Type' in the S3 console.
+
+
\ No newline at end of file
diff --git a/src/fragments/lib/storage/js/create-custom-plugin.mdx b/src/fragments/lib/storage/js/create-custom-plugin.mdx
new file mode 100644
index 00000000000..aeadda3c40e
--- /dev/null
+++ b/src/fragments/lib/storage/js/create-custom-plugin.mdx
@@ -0,0 +1,78 @@
+You can create your custom pluggable for Storage. This may be helpful if you want to integrate your app with a custom storage backend.
+
+To create a plugin implement the `StorageProvider` interface:
+
+```typescript
+import { Storage, StorageProvider } from 'aws-amplify';
+
+export default class MyStorageProvider implements StorageProvider {
+ // category and provider name
+ static category = 'Storage';
+ static providerName = 'MyStorage';
+
+ // you need to implement these seven methods
+ // configure your provider
+ configure(config: object): object;
+
+ // copy object, optional
+ copy?(
+ src: { key: string; identityId: string; level: 'public' | 'protected' | 'private' },
+ dest: { key: string; level: 'public' | 'protected' | 'private' },
+ options?
+ ): Promise
+
+ // get object/pre-signed url from storage
+ get(key: string, options?): Promise
+
+ // upload storage object
+ put(key: string, object, options?): Promise