@ampless/backend 1.0.0-beta.77 → 1.0.0-beta.78

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.ja.md CHANGED
@@ -64,7 +64,7 @@ amplessAuthConfig({ // カスタム
64
64
  amplessAuthConfig({ postConfirmation, webAuthn: false }) // パスワードのみのサインイン
65
65
  ```
66
66
 
67
- デフォルト(`true`)では Amplify がデプロイドメインから WebAuthnRelying Party ID を自動解決します。これは Amplify Hosting ドメインと `localhost` サンドボックスで動作します。管理画面を **CDN 配下のカスタムドメイン** で配信している場合、自動解決された RP ID がブラウザの見る URL と一致せず、サインインが `SecurityError` で失敗します。その場合はオペレーターがアクセスする bare domain を `relyingPartyId` に固定してください。パスキー登録後に RP ID を変更すると、登録済みの認証情報がすべて無効化されます。テンプレートではこのノブを `amplify/auth/resource.custom.ts`(`webAuthn?: AmplessWebAuthnOption | false`)経由で設定します。[docs/passkeys.ja.md](https://github.com/heavymoons/ampless/blob/main/docs/passkeys.ja.md) を参照してください。
67
+ Amplify Hosting パイプラインビルドでは、テンプレートが `cms.config.ts` `site.url` から `resolveWebAuthn({ override, siteUrl, isPipeline })` を通じて Relying Party ID を自動導出します。最も一般的なケースでは手動設定不要です。`ampx sandbox` では RP ID `localhost` のまま(Amplify が自動解決)です。管理画面を `site.url` と**異なるサブドメイン**で配信している場合は、`amplify/auth/resource.custom.ts` でオペレーターがアクセスする bare domain を `relyingPartyId` に固定してください。パスキー登録後に RP ID を変更すると、登録済みの認証情報がすべて無効化されます。[docs/passkeys.ja.md](https://github.com/heavymoons/ampless/blob/main/docs/passkeys.ja.md) を参照してください。
68
68
 
69
69
  ### `amplify/data/resource.ts`
70
70
 
@@ -127,7 +127,7 @@ export { handler } from '@ampless/backend/functions/api-key-renewer'
127
127
 
128
128
  ## サブパス
129
129
 
130
- - `@ampless/backend` — `defineAmplessBackend`、`amplessAuthConfig`、`amplessStorageConfig`、`amplessSchemaModels`、`extendAmplessSchema`、`defaultAuthorizationModes`
130
+ - `@ampless/backend` — `defineAmplessBackend`、`amplessAuthConfig`、`resolveWebAuthn`、`amplessStorageConfig`、`amplessSchemaModels`、`extendAmplessSchema`、`defaultAuthorizationModes`
131
131
  - `@ampless/backend/auth/post-confirmation` — Lambda ハンドラー
132
132
  - `@ampless/backend/events/dispatcher` — Lambda ハンドラー
133
133
  - `@ampless/backend/events/processor-trusted` — `createProcessorTrustedHandler({ plugins, site })`
package/README.md CHANGED
@@ -64,7 +64,7 @@ amplessAuthConfig({ // pin the Relyin
64
64
  amplessAuthConfig({ postConfirmation, webAuthn: false }) // password-only sign-in
65
65
  ```
66
66
 
67
- The default (`true`) lets Amplify auto-resolve the WebAuthn Relying Party ID from the deployment domain, which works on Amplify Hosting domains and on a `localhost` sandbox. If the admin is served from a **custom domain behind a CDN**, the auto-resolved RP ID won't match the URL the browser sees and sign-in fails with a `SecurityError` pin `relyingPartyId` to the bare domain operators visit. Changing the RP ID after passkeys exist invalidates every registered credential. The template wires this knob through `amplify/auth/resource.custom.ts` (`webAuthn?: AmplessWebAuthnOption | false`). See [docs/passkeys.md](https://github.com/heavymoons/ampless/blob/main/docs/passkeys.md).
67
+ In Amplify Hosting pipeline builds the template auto-derives the Relying Party ID from `site.url` in `cms.config.ts` via `resolveWebAuthn({ override, siteUrl, isPipeline })` no manual configuration needed for the common case. In `ampx sandbox` the RP ID stays `localhost` (auto-resolved by Amplify). If the admin is served from a **different subdomain** than `site.url`, pin `relyingPartyId` to the bare domain operators visit in `amplify/auth/resource.custom.ts`. Changing the RP ID after passkeys exist invalidates every registered credential. See [docs/passkeys.md](https://github.com/heavymoons/ampless/blob/main/docs/passkeys.md).
68
68
 
69
69
  ### `amplify/data/resource.ts`
70
70
 
@@ -127,7 +127,7 @@ export { handler } from '@ampless/backend/functions/api-key-renewer'
127
127
 
128
128
  ## Sub-paths
129
129
 
130
- - `@ampless/backend` — `defineAmplessBackend`, `amplessAuthConfig`, `amplessStorageConfig`, `amplessSchemaModels`, `extendAmplessSchema`, `defaultAuthorizationModes`
130
+ - `@ampless/backend` — `defineAmplessBackend`, `amplessAuthConfig`, `resolveWebAuthn`, `amplessStorageConfig`, `amplessSchemaModels`, `extendAmplessSchema`, `defaultAuthorizationModes`
131
131
  - `@ampless/backend/auth/post-confirmation` — Lambda handler
132
132
  - `@ampless/backend/events/dispatcher` — Lambda handler
133
133
  - `@ampless/backend/events/processor-trusted` — `createProcessorTrustedHandler({ plugins, site })`
package/dist/index.d.ts CHANGED
@@ -120,6 +120,25 @@ interface AmplessAuthConfigOpts {
120
120
  */
121
121
  webAuthn?: AmplessWebAuthnOption | false;
122
122
  }
123
+ interface ResolveWebAuthnOpts {
124
+ /** Explicit override from resource.custom.ts. When present, takes precedence. */
125
+ override?: AmplessWebAuthnOption | false;
126
+ /** `site.url` from cms.config — used to derive hostname in pipeline builds. */
127
+ siteUrl: string;
128
+ /** True only in Amplify Hosting pipeline builds (`Boolean(process.env.AWS_BRANCH)`). */
129
+ isPipeline: boolean;
130
+ }
131
+ /**
132
+ * Single source of truth for the WebAuthn relying-party configuration.
133
+ *
134
+ * Priority:
135
+ * 1. `override !== undefined` → return it verbatim (supports `false` to disable).
136
+ * 2. Not a pipeline build (sandbox / local) → return `true` so Amplify
137
+ * auto-resolves the RP ID from `localhost` (no RP ID needed in dev).
138
+ * 3. Pipeline build → derive `{ relyingPartyId }` from `siteUrl`.
139
+ * Falls back to `true` if `siteUrl` is not a valid URL (logs a warning).
140
+ */
141
+ declare function resolveWebAuthn(opts: ResolveWebAuthnOpts): AmplessWebAuthnOption | false;
123
142
  /**
124
143
  * Build the ampless Cognito configuration (User Pool + Identity Pool
125
144
  * with the three role groups and the optional post-confirmation
@@ -327,4 +346,4 @@ declare function amplessSchemaAuthorization(allow: any, opts?: AmplessSchemaAuth
327
346
  */
328
347
  declare const defaultAuthorizationModes: Parameters<typeof defineData>[0]['authorizationModes'];
329
348
 
330
- export { type AmplessAuthConfigOpts, type AmplessBackend, type AmplessResolverPaths, type AmplessSchemaAuthorizationOpts, type AmplessSchemaModelsOpts, type AmplessWebAuthnOption, DEFAULT_RESOLVER_PATHS, type DefineAmplessBackendOpts, amplessAuthConfig, amplessSchemaAuthorization, amplessSchemaModels, amplessStorageConfig, defaultAuthorizationModes, defineAmplessBackend, extendAmplessSchema };
349
+ export { type AmplessAuthConfigOpts, type AmplessBackend, type AmplessResolverPaths, type AmplessSchemaAuthorizationOpts, type AmplessSchemaModelsOpts, type AmplessWebAuthnOption, DEFAULT_RESOLVER_PATHS, type DefineAmplessBackendOpts, type ResolveWebAuthnOpts, amplessAuthConfig, amplessSchemaAuthorization, amplessSchemaModels, amplessStorageConfig, defaultAuthorizationModes, defineAmplessBackend, extendAmplessSchema, resolveWebAuthn };
package/dist/index.js CHANGED
@@ -264,6 +264,20 @@ function defineAmplessBackend(opts) {
264
264
  }
265
265
 
266
266
  // src/auth/index.ts
267
+ function resolveWebAuthn(opts) {
268
+ if (opts.override !== void 0) return opts.override;
269
+ if (!opts.isPipeline) return true;
270
+ try {
271
+ const hostname = new URL(opts.siteUrl).hostname;
272
+ return { relyingPartyId: hostname };
273
+ } catch {
274
+ console.warn(
275
+ "[ampless] invalid site.url for WebAuthn relying party, falling back to auto:",
276
+ opts.siteUrl
277
+ );
278
+ return true;
279
+ }
280
+ }
267
281
  function amplessAuthConfig(opts = {}) {
268
282
  return {
269
283
  loginWith: {
@@ -749,5 +763,6 @@ export {
749
763
  amplessStorageConfig,
750
764
  defaultAuthorizationModes,
751
765
  defineAmplessBackend,
752
- extendAmplessSchema
766
+ extendAmplessSchema,
767
+ resolveWebAuthn
753
768
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/backend",
3
- "version": "1.0.0-beta.77",
3
+ "version": "1.0.0-beta.78",
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",