Skip to content

Commit

Permalink
chore: cherry-pick storrage internals subpath commits (#13873)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebpollman authored Oct 1, 2024
2 parents 53c96b8 + a84bcf8 commit cf3aed2
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import { CredentialsProviderOptions } from '@aws-amplify/core/internals/aws-client-utils';

import { getDataAccess } from '../../../src/storageBrowser/apis/getDataAccess';
import { getDataAccess } from '../../../src/internals/apis/getDataAccess';
import { getDataAccess as getDataAccessClient } from '../../../src/providers/s3/utils/client/s3control';
import { GetDataAccessInput } from '../../../src/storageBrowser/apis/types';
import { GetDataAccessInput } from '../../../src/internals/types/inputs';

jest.mock('../../../src/providers/s3/utils/client/s3control');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { CredentialsProviderOptions } from '@aws-amplify/core/internals/aws-client-utils';

import { listCallerAccessGrants } from '../../../src/storageBrowser/apis/listCallerAccessGrants';
import { listCallerAccessGrants } from '../../../src/internals/apis/listCallerAccessGrants';
import { listCallerAccessGrants as listCallerAccessGrantsClient } from '../../../src/providers/s3/utils/client/s3control';

jest.mock('../../../src/providers/s3/utils/client/s3control');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { createLocationCredentialsStore } from '../../../src/storageBrowser/locationCredentialsStore/create';
import { createLocationCredentialsStore } from '../../../src/internals/locationCredentialsStore/create';
import {
createStore,
getValue,
removeStore,
} from '../../../src/storageBrowser/locationCredentialsStore/registry';
import { LocationCredentialsStore } from '../../../src/storageBrowser/types';
} from '../../../src/internals/locationCredentialsStore/registry';
import { LocationCredentialsStore } from '../../../src/internals/types/credentials';
import {
StorageValidationErrorCode,
validationErrorMap,
} from '../../../src/errors/types/validation';
import { AWSTemporaryCredentials } from '../../../src/providers/s3/types/options';

jest.mock('../../../src/storageBrowser/locationCredentialsStore/registry');
jest.mock('../../../src/internals/locationCredentialsStore/registry');

const mockedCredentials = 'MOCK_CREDS' as any as AWSTemporaryCredentials;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import {
createStore,
getValue,
removeStore,
} from '../../../src/storageBrowser/locationCredentialsStore/registry';
} from '../../../src/internals/locationCredentialsStore/registry';
import {
LruLocationCredentialsStore,
fetchNewValue,
getCacheValue,
initStore,
} from '../../../src/storageBrowser/locationCredentialsStore/store';
} from '../../../src/internals/locationCredentialsStore/store';

jest.mock('../../../src/storageBrowser/locationCredentialsStore/store');
jest.mock('../../../src/internals/locationCredentialsStore/store');

const mockedStore = 'MOCKED_STORE' as any as LruLocationCredentialsStore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
fetchNewValue,
getCacheValue,
initStore,
} from '../../../src/storageBrowser/locationCredentialsStore/store';
import { CredentialsLocation } from '../../../src/storageBrowser/types';
} from '../../../src/internals/locationCredentialsStore/store';
import { CredentialsLocation } from '../../../src/internals/types/credentials';

const mockCredentials = {
expiration: new Date(Date.now() + 60 * 60_1000),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { createListLocationsHandler } from '../../../src/storageBrowser/managedAuthConfigAdapter/createListLocationsHandler';
import { listCallerAccessGrants } from '../../../src/storageBrowser/apis/listCallerAccessGrants';
import { createListLocationsHandler } from '../../../src/internals/managedAuthConfigAdapter/createListLocationsHandler';
import { listCallerAccessGrants } from '../../../src/internals/apis/listCallerAccessGrants';

jest.mock('../../../src/storageBrowser/apis/listCallerAccessGrants');
jest.mock('../../../src/internals/apis/listCallerAccessGrants');

jest.mocked(listCallerAccessGrants).mockResolvedValue({
locations: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { createManagedAuthConfigAdapter } from '../../../src/storageBrowser/managedAuthConfigAdapter';
import { createListLocationsHandler } from '../../../src/storageBrowser/managedAuthConfigAdapter/createListLocationsHandler';
import { createLocationCredentialsHandler } from '../../../src/storageBrowser/managedAuthConfigAdapter/createLocationCredentialsHandler';
import { createManagedAuthConfigAdapter } from '../../../src/internals/managedAuthConfigAdapter';
import { createListLocationsHandler } from '../../../src/internals/managedAuthConfigAdapter/createListLocationsHandler';
import { createLocationCredentialsHandler } from '../../../src/internals/managedAuthConfigAdapter/createLocationCredentialsHandler';

jest.mock(
'../../../src/storageBrowser/managedAuthConfigAdapter/createListLocationsHandler',
'../../../src/internals/managedAuthConfigAdapter/createListLocationsHandler',
);
jest.mock(
'../../../src/storageBrowser/managedAuthConfigAdapter/createLocationCredentialsHandler',
'../../../src/internals/managedAuthConfigAdapter/createLocationCredentialsHandler',
);

describe('createManagedAuthConfigAdapter', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/storage/internals/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@aws-amplify/storage/internals",
"types": "../dist/esm/internals/index.d.ts",
"main": "../dist/cjs/internals/index.js",
"module": "../dist/esm/internals/index.mjs",
"sideEffects": false
}
19 changes: 10 additions & 9 deletions packages/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
"s3": [
"./dist/esm/providers/s3/index.d.ts"
],
"internals": [
"./dist/esm/internals/index.d.ts"
],
"server": [
"./dist/esm/server.d.ts"
],
"s3/server": [
"./dist/esm/providers/s3/server.d.ts"
],
"storage-browser": [
"./dist/esm/storageBrowser/index.d.ts"
]
]
}
},
"repository": {
Expand All @@ -64,6 +64,7 @@
"files": [
"dist/cjs",
"dist/esm",
"internals",
"src",
"server",
"s3"
Expand All @@ -83,6 +84,11 @@
"require": "./dist/cjs/index.js",
"react-native": "./src/index.ts"
},
"./internals": {
"types": "./dist/esm/internals/index.d.ts",
"import": "./dist/esm/internals/index.mjs",
"require": "./dist/cjs/internals/index.js"
},
"./server": {
"types": "./dist/esm/server.d.ts",
"import": "./dist/esm/server.mjs",
Expand All @@ -99,11 +105,6 @@
"import": "./dist/esm/providers/s3/server.mjs",
"require": "./dist/cjs/providers/s3/server.js"
},
"./storage-browser": {
"types": "./dist/esm/storageBrowser/index.d.ts",
"import": "./dist/esm/storageBrowser/index.mjs",
"require": "./dist/cjs/storageBrowser/index.js"
},
"./package.json": "./package.json"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import { CredentialsProviderOptions } from '@aws-amplify/core/internals/aws-clie
import { getStorageUserAgentValue } from '../../providers/s3/utils/userAgent';
import { getDataAccess as getDataAccessClient } from '../../providers/s3/utils/client/s3control';
import { StorageError } from '../../errors/StorageError';
import { GetDataAccessInput } from '../types/inputs';
import { GetDataAccessOutput } from '../types/outputs';
import { logger } from '../../utils';
import { DEFAULT_CRED_TTL } from '../utils/constants';

import { GetDataAccessInput, GetDataAccessOutput } from './types';
import { DEFAULT_CRED_TTL } from './constants';

/**
* @internal
*/
export const getDataAccess = async (
input: GetDataAccessInput,
): Promise<GetDataAccessOutput> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { CredentialsProviderOptions } from '@aws-amplify/core/internals/aws-clie

import { logger } from '../../utils';
import { listCallerAccessGrants as listCallerAccessGrantsClient } from '../../providers/s3/utils/client/s3control';
import { LocationAccess, LocationType } from '../types';
import { StorageError } from '../../errors/StorageError';
import { getStorageUserAgentValue } from '../../providers/s3/utils/userAgent';
import { LocationType } from '../types/common';
import { LocationAccess } from '../types/credentials';
import { ListCallerAccessGrantsInput } from '../types/inputs';
import { ListCallerAccessGrantsOutput } from '../types/outputs';
import { MAX_PAGE_SIZE } from '../utils/constants';

import {
ListCallerAccessGrantsInput,
ListCallerAccessGrantsOutput,
} from './types';
import { MAX_PAGE_SIZE } from './constants';

/**
* @internal
*/
export const listCallerAccessGrants = async (
input: ListCallerAccessGrantsInput,
): Promise<ListCallerAccessGrantsOutput> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@
export { LocationCredentialsProvider } from '../providers/s3/types/options';
export { StorageSubpathStrategy } from '../types/options';

export { Permission } from './types/common';

/*
Internal APIs
*/
export {
GetDataAccessInput,
ListCallerAccessGrantsInput,
} from './types/inputs';
export {
GetDataAccessOutput,
ListCallerAccessGrantsOutput,
} from './types/outputs';

export { getDataAccess } from './apis/getDataAccess';
export { listCallerAccessGrants } from './apis/listCallerAccessGrants';

/*
CredentialsStore exports
*/
export { createLocationCredentialsStore } from './locationCredentialsStore';
export {
AuthConfigAdapter,
Expand All @@ -20,6 +40,5 @@ export {
ListLocationsOutput,
GetLocationCredentialsInput,
GetLocationCredentialsOutput,
Permission,
} from './types';
} from './types/credentials';
export { AWSTemporaryCredentials } from '../providers/s3/types/options';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CreateLocationCredentialsStoreInput,
CredentialsLocation,
LocationCredentialsStore,
} from '../types';
} from '../types/credentials';
import { StorageValidationErrorCode } from '../../errors/types/validation';
import { assertValidationError } from '../../errors/utils/assertValidationError';
import { LocationCredentialsProvider } from '../../providers/s3/types/options';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { AWSTemporaryCredentials } from '../../providers/s3/types/options';
import { CredentialsLocation, GetLocationCredentials } from '../types';
import {
CredentialsLocation,
GetLocationCredentials,
} from '../types/credentials';
import { assertValidationError } from '../../errors/utils/assertValidationError';
import { StorageValidationErrorCode } from '../../errors/types/validation';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import {
CredentialsLocation,
GetLocationCredentials,
Permission,
} from '../types';
} from '../types/credentials';
import { Permission } from '../types/common';
import { AWSTemporaryCredentials } from '../../providers/s3/types/options';
import { assertValidationError } from '../../errors/utils/assertValidationError';
import { StorageValidationErrorCode } from '../../errors/types/validation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { CredentialsProvider, ListLocations } from '../types';
import { CredentialsProvider, ListLocations } from '../types/credentials';
import { listCallerAccessGrants } from '../apis/listCallerAccessGrants';

interface CreateListLocationsHandlerInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CredentialsProvider,
GetLocationCredentials,
GetLocationCredentialsInput,
} from '../types';
} from '../types/credentials';

interface CreateLocationCredentialsHandlerInput {
accountId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CredentialsProvider,
GetLocationCredentials,
ListLocations,
} from '../types';
} from '../types/credentials';

import { createListLocationsHandler } from './createListLocationsHandler';
import { createLocationCredentialsHandler } from './createLocationCredentialsHandler';
Expand Down
22 changes: 22 additions & 0 deletions packages/storage/src/internals/types/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

/**
* @internal
*/
export type Permission = 'READ' | 'READWRITE' | 'WRITE';

/**
* @internal
*/
export type LocationType = 'BUCKET' | 'PREFIX' | 'OBJECT';

/**
* @internal
*/
export type Privilege = 'Default' | 'Minimal';

/**
* @internal
*/
export type PrefixType = 'Object';
Loading

0 comments on commit cf3aed2

Please sign in to comment.