@ampless/backend 0.2.0-alpha.0 → 0.2.0-alpha.1
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/README.md +11 -5
- package/dist/index.d.ts +40 -12
- package/dist/index.js +8 -10
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -38,12 +38,15 @@ export default defineAmplessBackend({
|
|
|
38
38
|
### `amplify/auth/resource.ts`
|
|
39
39
|
|
|
40
40
|
```ts
|
|
41
|
-
import {
|
|
41
|
+
import { defineAuth } from '@aws-amplify/backend'
|
|
42
|
+
import { amplessAuthConfig } from '@ampless/backend'
|
|
42
43
|
import { postConfirmation } from './post-confirmation/resource'
|
|
43
44
|
|
|
44
|
-
export const auth =
|
|
45
|
+
export const auth = defineAuth(amplessAuthConfig({ postConfirmation }))
|
|
45
46
|
```
|
|
46
47
|
|
|
48
|
+
> `defineAuth` must live in `amplify/auth/resource.ts` itself. Amplify Gen 2's import-path verifier inspects the call site of `defineAuth` / `defineData` / `defineStorage` and throws `Amplify Auth must be defined in amplify/auth/resource.ts` if it's invoked from any other file (including a `node_modules/@ampless/backend/...` wrapper). `amplessAuthConfig` returns the props object so you can call `defineAuth(...)` here without losing the ampless defaults.
|
|
49
|
+
|
|
47
50
|
### `amplify/data/resource.ts`
|
|
48
51
|
|
|
49
52
|
```ts
|
|
@@ -65,10 +68,13 @@ The three AppSync JS resolver files (`list-published-posts.js`, `get-published-p
|
|
|
65
68
|
### `amplify/storage/resource.ts`
|
|
66
69
|
|
|
67
70
|
```ts
|
|
68
|
-
import {
|
|
69
|
-
|
|
71
|
+
import { defineStorage } from '@aws-amplify/backend'
|
|
72
|
+
import { amplessStorageConfig } from '@ampless/backend'
|
|
73
|
+
export const storage = defineStorage(amplessStorageConfig())
|
|
70
74
|
```
|
|
71
75
|
|
|
76
|
+
> Same import-path verifier constraint as auth — `defineStorage` has to be called from this file directly. `amplessStorageConfig` returns the props object.
|
|
77
|
+
|
|
72
78
|
### Lambda thin shells
|
|
73
79
|
|
|
74
80
|
Every handler file in `amplify/auth/`, `amplify/events/`, and `amplify/functions/` becomes a 1–3 line re-export. Amplify's esbuild follows the import into this package and bundles the real handler code into the Lambda artifact.
|
|
@@ -102,7 +108,7 @@ export { handler } from '@ampless/backend/functions/api-key-renewer'
|
|
|
102
108
|
|
|
103
109
|
## Sub-paths
|
|
104
110
|
|
|
105
|
-
- `@ampless/backend` — `defineAmplessBackend`, `
|
|
111
|
+
- `@ampless/backend` — `defineAmplessBackend`, `amplessAuthConfig`, `amplessStorageConfig`, `amplessSchemaModels`, `extendAmplessSchema`, `defaultAuthorizationModes`
|
|
106
112
|
- `@ampless/backend/auth/post-confirmation` — Lambda handler
|
|
107
113
|
- `@ampless/backend/events/dispatcher` — Lambda handler
|
|
108
114
|
- `@ampless/backend/events/processor-trusted` — `createProcessorTrustedHandler({ plugins, site })`
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineData } from '@aws-amplify/backend';
|
|
1
|
+
import { defineAuth, defineStorage, defineData } from '@aws-amplify/backend';
|
|
2
2
|
|
|
3
3
|
type AuthResource = any;
|
|
4
4
|
type DataResource = any;
|
|
@@ -44,7 +44,7 @@ type AmplessBackend = any;
|
|
|
44
44
|
*/
|
|
45
45
|
declare function defineAmplessBackend(opts: DefineAmplessBackendOpts): AmplessBackend;
|
|
46
46
|
|
|
47
|
-
interface
|
|
47
|
+
interface AmplessAuthConfigOpts {
|
|
48
48
|
/**
|
|
49
49
|
* The `post-confirmation` Cognito Lambda trigger that promotes the
|
|
50
50
|
* first signup to `ampless-admin`. Wire your own `defineFunction`
|
|
@@ -59,17 +59,35 @@ interface DefineAmplessAuthOpts {
|
|
|
59
59
|
postConfirmation?: unknown;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
* three role groups and the optional post-confirmation
|
|
62
|
+
* Build the ampless Cognito configuration (User Pool + Identity Pool
|
|
63
|
+
* with the three role groups and the optional post-confirmation
|
|
64
|
+
* trigger) as a plain options object suitable for `defineAuth(...)`.
|
|
65
|
+
*
|
|
66
|
+
* Returning a config object — rather than calling `defineAuth`
|
|
67
|
+
* internally — keeps the actual `defineAuth` call inside the user's
|
|
68
|
+
* `amplify/auth/resource.ts`. Amplify Gen 2's import-path verifier
|
|
69
|
+
* (`@aws-amplify/backend-auth/lib/factory.js`) inspects the second
|
|
70
|
+
* stack frame and requires the call site to live at
|
|
71
|
+
* `amplify/auth/resource.ts`; routing through this package fails
|
|
72
|
+
* that check.
|
|
64
73
|
*
|
|
65
74
|
* Public reads use AppSync's API key (not the guest Identity Pool
|
|
66
75
|
* role) because `a.handler.custom` doesn't accept `allow.guest()`
|
|
67
76
|
* in Amplify Gen 2 — see `data/resource.ts` and the RUNBOOK.
|
|
77
|
+
*
|
|
78
|
+
* Usage:
|
|
79
|
+
*
|
|
80
|
+
* // amplify/auth/resource.ts
|
|
81
|
+
* import { defineAuth } from '@aws-amplify/backend'
|
|
82
|
+
* import { amplessAuthConfig } from '@ampless/backend'
|
|
83
|
+
* import { postConfirmation } from './post-confirmation/resource.js'
|
|
84
|
+
* export const auth = defineAuth(amplessAuthConfig({ postConfirmation }))
|
|
68
85
|
*/
|
|
69
|
-
declare function
|
|
86
|
+
declare function amplessAuthConfig(opts?: AmplessAuthConfigOpts): Parameters<typeof defineAuth>[0];
|
|
70
87
|
|
|
71
88
|
/**
|
|
72
|
-
*
|
|
89
|
+
* Build the ampless S3 bucket configuration as a plain options object
|
|
90
|
+
* suitable for `defineStorage(...)`. Access map:
|
|
73
91
|
* - `public/media/*` — guest read, admin/editor full
|
|
74
92
|
* - `public/plugins/*` — guest read, admin full
|
|
75
93
|
*
|
|
@@ -77,12 +95,22 @@ declare function defineAmplessAuth(opts?: DefineAmplessAuthOpts): any;
|
|
|
77
95
|
* `public/site-settings/*`) are applied by `defineAmplessBackend`
|
|
78
96
|
* after `defineBackend` runs.
|
|
79
97
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
98
|
+
* Returning a config object — rather than calling `defineStorage`
|
|
99
|
+
* internally — keeps the actual `defineStorage` call inside the
|
|
100
|
+
* user's `amplify/storage/resource.ts`. Amplify Gen 2's import-path
|
|
101
|
+
* verifier (`@aws-amplify/backend-storage/lib/factory.js`) inspects
|
|
102
|
+
* the second stack frame and requires the call site to live at
|
|
103
|
+
* `amplify/storage/resource.ts`; routing through this package fails
|
|
104
|
+
* that check.
|
|
105
|
+
*
|
|
106
|
+
* Usage:
|
|
107
|
+
*
|
|
108
|
+
* // amplify/storage/resource.ts
|
|
109
|
+
* import { defineStorage } from '@aws-amplify/backend'
|
|
110
|
+
* import { amplessStorageConfig } from '@ampless/backend'
|
|
111
|
+
* export const storage = defineStorage(amplessStorageConfig())
|
|
84
112
|
*/
|
|
85
|
-
declare function
|
|
113
|
+
declare function amplessStorageConfig(): Parameters<typeof defineStorage>[0];
|
|
86
114
|
|
|
87
115
|
interface AmplessResolverPaths {
|
|
88
116
|
listPublishedPosts: string;
|
|
@@ -155,4 +183,4 @@ declare function extendAmplessSchema(a: any, custom?: Record<string, any>, opts?
|
|
|
155
183
|
*/
|
|
156
184
|
declare const defaultAuthorizationModes: Parameters<typeof defineData>[0]['authorizationModes'];
|
|
157
185
|
|
|
158
|
-
export { type AmplessBackend, type AmplessResolverPaths, type AmplessSchemaModelsOpts, DEFAULT_RESOLVER_PATHS, type
|
|
186
|
+
export { type AmplessAuthConfigOpts, type AmplessBackend, type AmplessResolverPaths, type AmplessSchemaModelsOpts, DEFAULT_RESOLVER_PATHS, type DefineAmplessBackendOpts, amplessAuthConfig, amplessSchemaModels, amplessStorageConfig, defaultAuthorizationModes, defineAmplessBackend, extendAmplessSchema };
|
package/dist/index.js
CHANGED
|
@@ -153,9 +153,8 @@ function defineAmplessBackend(opts) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
// src/auth/index.ts
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return defineAuth({
|
|
156
|
+
function amplessAuthConfig(opts = {}) {
|
|
157
|
+
return {
|
|
159
158
|
loginWith: {
|
|
160
159
|
email: true
|
|
161
160
|
},
|
|
@@ -164,13 +163,12 @@ function defineAmplessAuth(opts = {}) {
|
|
|
164
163
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
164
|
{ postConfirmation: opts.postConfirmation }
|
|
166
165
|
) : void 0
|
|
167
|
-
}
|
|
166
|
+
};
|
|
168
167
|
}
|
|
169
168
|
|
|
170
169
|
// src/storage/index.ts
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return defineStorage({
|
|
170
|
+
function amplessStorageConfig() {
|
|
171
|
+
return {
|
|
174
172
|
name: "amplessMedia",
|
|
175
173
|
access: (allow) => ({
|
|
176
174
|
"public/media/*": [
|
|
@@ -182,7 +180,7 @@ function defineAmplessStorage() {
|
|
|
182
180
|
allow.groups(["ampless-admin"]).to(["read", "write", "delete"])
|
|
183
181
|
]
|
|
184
182
|
})
|
|
185
|
-
}
|
|
183
|
+
};
|
|
186
184
|
}
|
|
187
185
|
|
|
188
186
|
// src/data/index.ts
|
|
@@ -384,10 +382,10 @@ var defaultAuthorizationModes = {
|
|
|
384
382
|
};
|
|
385
383
|
export {
|
|
386
384
|
DEFAULT_RESOLVER_PATHS,
|
|
385
|
+
amplessAuthConfig,
|
|
387
386
|
amplessSchemaModels,
|
|
387
|
+
amplessStorageConfig,
|
|
388
388
|
defaultAuthorizationModes,
|
|
389
|
-
defineAmplessAuth,
|
|
390
389
|
defineAmplessBackend,
|
|
391
|
-
defineAmplessStorage,
|
|
392
390
|
extendAmplessSchema
|
|
393
391
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampless/backend",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.1",
|
|
4
4
|
"description": "Amplify Gen 2 backend factories for ampless: auth, data, storage, event processors, API key renewer",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"@aws-sdk/client-appsync": "^3.717.0",
|
|
49
49
|
"@aws-sdk/client-cognito-identity-provider": "^3.717.0",
|
|
50
50
|
"@aws-sdk/client-dynamodb": "^3.717.0",
|
|
51
|
-
"@aws-sdk/client-s3": "^3.
|
|
51
|
+
"@aws-sdk/client-s3": "^3.1048.0",
|
|
52
52
|
"@aws-sdk/client-sqs": "^3.717.0",
|
|
53
53
|
"@aws-sdk/lib-dynamodb": "^3.717.0",
|
|
54
54
|
"@aws-sdk/util-dynamodb": "^3.717.0",
|
|
55
|
-
"ampless": "0.2.0-alpha.
|
|
55
|
+
"ampless": "0.2.0-alpha.1"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@aws-amplify/backend": "^1",
|