@aws-amplify/data-schema 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/data-schema",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,11 +10,11 @@ const __data = Symbol('data');
10
10
  *
11
11
  * This list should not be used if you need to restrict available providers
12
12
  * according to an auth strategcy. E.g., `public` auth can only be facilitated
13
- * by `apiKey` and `iam` providers.
13
+ * by `apiKey` and `identityPool` providers.
14
14
  */
15
15
  export const Providers = [
16
16
  'apiKey',
17
- 'iam',
17
+ 'identityPool',
18
18
  'userPools',
19
19
  'oidc',
20
20
  'function',
@@ -24,13 +24,13 @@ export type Provider = (typeof Providers)[number];
24
24
  /**
25
25
  * The subset of auth providers that can facilitate `public` auth.
26
26
  */
27
- export const PublicProviders = ['apiKey', 'iam'] as const;
27
+ export const PublicProviders = ['apiKey', 'identityPool'] as const;
28
28
  export type PublicProvider = (typeof PublicProviders)[number];
29
29
 
30
30
  /**
31
31
  * The subset of auth providers that can facilitate `private` auth.
32
32
  */
33
- export const PrivateProviders = ['userPools', 'oidc', 'iam'] as const;
33
+ export const PrivateProviders = ['userPools', 'oidc', 'identityPool'] as const;
34
34
  export type PrivateProvider = (typeof PrivateProviders)[number];
35
35
 
36
36
  /**
@@ -205,7 +205,7 @@ function authData<
205
205
 
206
206
  /**
207
207
  * Defines an authorization rule for your data models and fields. First choose an authorization strategy (`public`,
208
- * `private`, `owner`, `group`, or `custom`), then choose an auth provider (`apiKey`, `iam`, `userPools`, `oidc`, or `function`)
208
+ * `private`, `owner`, `group`, or `custom`), then choose an auth provider (`apiKey`, `identitypool`, `userPools`, `oidc`, or `function`)
209
209
  * and optionally use `.to(...)` to specify the operations that can be performed against your data models and fields.
210
210
  */
211
211
  export const allow = {
@@ -226,14 +226,14 @@ export const allow = {
226
226
  },
227
227
 
228
228
  /**
229
- * Authorize unauthenticated users by using IAM based authorization.
229
+ * Authorize unauthenticated users by using IDENTITYPOOL based authorization.
230
230
  * @returns an authorization rule for unauthenticated users
231
231
  */
232
232
  guest() {
233
233
  return authData(
234
234
  {
235
235
  strategy: 'public',
236
- provider: 'iam',
236
+ provider: 'identityPool',
237
237
  },
238
238
  {
239
239
  to,
@@ -242,9 +242,9 @@ export const allow = {
242
242
  },
243
243
 
244
244
  /**
245
- * Authorize authenticated users. By default, `.private()` uses an Amazon Cognito user pool based authorization. You can additionally
246
- * use `.authenticated("iam")` or `.authenticated("oidc")` to use IAM or OIDC based authorization for authenticated users.
247
- * @param provider the authentication provider - supports "userPools", "iam", or "oidc"
245
+ * Authorize authenticated users. By default, `.authenticated()` uses an Amazon Cognito user pool based authorization. You can additionally
246
+ * use `.authenticated("identityPool")` or `.authenticated("oidc")` to use identityPool or OIDC based authorization for authenticated users.
247
+ * @param provider the authentication provider - supports "userPools", "identityPool", or "oidc"
248
248
  * @returns an authorization rule for authenticated users
249
249
  */
250
250
  authenticated(provider?: PrivateProvider) {
@@ -272,7 +272,7 @@ export const allow = {
272
272
  * To change the specific claim that should be used as the user identifier within the owner field, chain the
273
273
  * `.identityClaim(...)` method.
274
274
  *
275
- * @param provider the authentication provider - supports "userPools", "iam", or "oidc"
275
+ * @param provider the authentication provider - supports "userPools", "identityPool", or "oidc"
276
276
  * @returns an authorization rule for authenticated users
277
277
  */
278
278
  owner(provider?: OwnerProviders) {
@@ -300,7 +300,7 @@ export const allow = {
300
300
  * `.identityClaim(...)` method.
301
301
  *
302
302
  * @param ownerField the field that contains the owner information
303
- * @param provider the authentication provider - supports "userPools", "iam", or "oidc"
303
+ * @param provider the authentication provider - supports "userPools", "identityPool", or "oidc"
304
304
  * @returns an authorization rule for authenticated users
305
305
  */
306
306
  ownerDefinedIn<T extends string>(ownerField: T, provider?: OwnerProviders) {
@@ -333,7 +333,7 @@ export const allow = {
333
333
  * `.identityClaim(...)` method.
334
334
  *
335
335
  * @param ownersField the field that contains the owners information
336
- * @param provider the authentication provider - supports "userPools", "iam", or "oidc"
336
+ * @param provider the authentication provider - supports "userPools", "identityPool", or "oidc"
337
337
  * @returns an authorization rule for authenticated users
338
338
  */
339
339
  ownersDefinedIn<T extends string>(ownersField: T, provider?: OwnerProviders) {
@@ -506,14 +506,14 @@ export const allowForCustomOperations = {
506
506
  },
507
507
 
508
508
  /**
509
- * Authorize unauthenticated users by using IAM based authorization.
509
+ * Authorize unauthenticated users by using identityPool based authorization.
510
510
  * @returns an authorization rule for unauthenticated users
511
511
  */
512
512
  guest() {
513
513
  return authData(
514
514
  {
515
515
  strategy: 'public',
516
- provider: 'iam',
516
+ provider: 'identityPool',
517
517
  },
518
518
  {},
519
519
  );
@@ -521,8 +521,8 @@ export const allowForCustomOperations = {
521
521
 
522
522
  /**
523
523
  * Authorize authenticated users. By default, `.private()` uses an Amazon Cognito user pool based authorization. You can additionally
524
- * use `.authenticated("iam")` or `.authenticated("oidc")` to use IAM or OIDC based authorization for authenticated users.
525
- * @param provider the authentication provider - supports "userPools", "iam", or "oidc"
524
+ * use `.authenticated("identityPool")` or `.authenticated("oidc")` to use Identity Pool or OIDC based authorization for authenticated users.
525
+ * @param provider the authentication provider - supports "userPools", "identityPool", or "oidc"
526
526
  * @returns an authorization rule for authenticated users
527
527
  */
528
528
  authenticated(provider?: PrivateProvider) {
@@ -237,7 +237,7 @@ export function query(): CustomOperation<
237
237
  typeName: 'Query';
238
238
  handlers: null;
239
239
  },
240
- never,
240
+ 'for',
241
241
  typeof queryBrand
242
242
  > {
243
243
  return _custom('Query', queryBrand);
@@ -258,7 +258,7 @@ export function mutation(): CustomOperation<
258
258
  typeName: 'Mutation';
259
259
  handlers: null;
260
260
  },
261
- never,
261
+ 'for',
262
262
  typeof mutationBrand
263
263
  > {
264
264
  return _custom('Mutation', mutationBrand);
@@ -571,7 +571,9 @@ function calculateAuth(authorization: Authorization<any, any, any>[]) {
571
571
  }
572
572
 
573
573
  if (rule.provider) {
574
- ruleParts.push(`provider: ${rule.provider}`);
574
+ // identityPool maps to iam in the transform
575
+ const provider = rule.provider === 'identityPool' ? 'iam' : rule.provider;
576
+ ruleParts.push(`provider: ${provider}`);
575
577
  }
576
578
 
577
579
  if (rule.operations) {
@@ -1270,6 +1272,12 @@ function validateCustomOperations(
1270
1272
  }
1271
1273
  }
1272
1274
 
1275
+ if (opType !== 'Subscription' && subscriptionSource.length > 0) {
1276
+ throw new Error(
1277
+ `The .for() modifier function can only be used with a custom subscription. ${typeName} is not a custom subscription.`,
1278
+ );
1279
+ }
1280
+
1273
1281
  if (opType === 'Subscription') {
1274
1282
  if (subscriptionSource.length < 1) {
1275
1283
  throw new Error(
@@ -174,6 +174,7 @@ export type GraphQLAuthMode =
174
174
  | 'oidc'
175
175
  | 'userPool'
176
176
  | 'iam'
177
+ | 'identityPool'
177
178
  | 'lambda'
178
179
  | 'none';
179
180
 
@@ -410,6 +410,7 @@ export type LazyLoader<Model, IsArray extends boolean> = (
410
410
  export type AuthMode =
411
411
  | 'apiKey'
412
412
  | 'iam'
413
+ | 'identityPool'
413
414
  | 'oidc'
414
415
  | 'userPool'
415
416
  | 'lambda'