akanjs 3.3.0-rc.70 → 3.3.0-rc.71

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/index.ts CHANGED
@@ -40,9 +40,11 @@ export type DockerConfig = string | DockerImageConfig;
40
40
 
41
41
  /**
42
42
  * The app's `docker` with the fields it names replaced and its `env` laid over the app's key by key, written beside
43
- * the Dockerfile as `Dockerfile.<name>`.
43
+ * the Dockerfile as `Dockerfile.<name>`. `profile` names a server env profile: the build carries
44
+ * `env/env.server.<env>.<profile>.ts` beside the environment's own env file, and the variant's `AKAN_ENV_PROFILE`
45
+ * picks it when the server starts.
44
46
  */
45
- export type DockerVariantOption = Partial<DockerImageConfig>;
47
+ export type DockerVariantOption = Partial<DockerImageConfig> & { profile?: string };
46
48
 
47
49
  export type DockerOption = string | (Partial<DockerImageConfig> & { variants?: Record<string, DockerVariantOption> });
48
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.70",
3
+ "version": "3.3.0-rc.71",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -417,6 +417,11 @@
417
417
  "import": "./server/lifecycle/buildEnv.ts",
418
418
  "default": "./server/lifecycle/buildEnv.ts"
419
419
  },
420
+ "./server/lifecycle/envProfile": {
421
+ "types": "./types/server/lifecycle/envProfile.d.ts",
422
+ "import": "./server/lifecycle/envProfile.ts",
423
+ "default": "./server/lifecycle/envProfile.ts"
424
+ },
420
425
  "./server/lifecycle/secretEnv": {
421
426
  "types": "./types/server/lifecycle/secretEnv.d.ts",
422
427
  "import": "./server/lifecycle/secretEnv.ts",
package/server/akanApp.ts CHANGED
@@ -15,6 +15,7 @@ import { GatewayRooms } from "./gateway/gatewayRooms";
15
15
  import { GatewayStatus } from "./gateway/gatewayStatus";
16
16
  import { GatewayWebSocketRelay, type GatewayWsData } from "./gateway/gatewayWebSocketRelay";
17
17
  import { ListeningPort } from "./gateway/listeningPort";
18
+ import { EnvProfile } from "./lifecycle/envProfile";
18
19
  import { isPortInUseError } from "./lifecycle/portInUse";
19
20
  import { SecretEnv } from "./lifecycle/secretEnv";
20
21
  import { LogStreamRoute } from "./logging/logStreamRoute";
@@ -102,7 +103,8 @@ export class AkanApp {
102
103
  await OpsCommand.run(process.argv.slice(3), { importServer: async () => await this.#importServer() }),
103
104
  );
104
105
  }
105
- SecretEnv.check(this.logger);
106
+
107
+ if (!EnvProfile.active()) SecretEnv.check(this.logger);
106
108
  if (this.#config.solo) return await this.#startSolo();
107
109
  if (SelfExec.carried)
108
110
  throw new AkanError(
@@ -0,0 +1,27 @@
1
+ import { AkanError } from "../../base/akanError";
2
+
3
+ export class EnvProfile {
4
+ static readonly key = "AKAN_ENV_PROFILE";
5
+
6
+ static readonly carriedKey = "AKAN_BUILD_ENV_PROFILES";
7
+ static readonly namePattern = /^[a-z][a-zA-Z0-9-]*$/;
8
+
9
+ static format(profiles: readonly string[]) {
10
+ return profiles.join(",");
11
+ }
12
+
13
+ static active(
14
+ env: NodeJS.ProcessEnv = process.env,
15
+ carried: string | undefined = process.env.AKAN_BUILD_ENV_PROFILES,
16
+ ): string | null {
17
+ const profile = env[EnvProfile.key];
18
+ if (!profile) return null;
19
+ const names = (carried ?? "").split(",").filter(Boolean);
20
+ if (names.includes(profile)) return profile;
21
+ const carries = names.length ? `it carries ${names.join(", ")}` : "it carries none";
22
+ throw new AkanError(
23
+ "envProfileUnbuilt",
24
+ `${EnvProfile.key}=${profile} names a server env profile this server was not built with (${carries}), so it does not start: it would run on the environment's own env file. \`docker.variants.<name>.profile\` in akan.config.ts makes \`akan build\` carry one.`,
25
+ );
26
+ }
27
+ }
@@ -5,11 +5,8 @@ export type SecretEnvKind = "string" | "json" | "multiline";
5
5
  export interface SecretEnvEntry {
6
6
  name: string;
7
7
  kind: SecretEnvKind;
8
- }
9
-
10
- export interface SecretEnvReport {
11
- missing: string[];
12
- escaped: string[];
8
+ /** The developer's own variables the env file reads first (`process.env.MY_URL ?? "…"`): one set stands in. */
9
+ ahead?: string[];
13
10
  }
14
11
 
15
12
  interface SecretEnvLogger {
@@ -20,8 +17,6 @@ export class SecretEnv {
20
17
 
21
18
  static readonly listKey = "AKAN_ENV_NAMES";
22
19
 
23
- static readonly fallbackKey = "AKAN_ENV_FALLBACK";
24
-
25
20
  static readonly #aliases: { readonly [name: string]: readonly string[] } = { POSTGRES_URL: ["POSTGRES_URI"] };
26
21
 
27
22
  static #value(name: string, env: NodeJS.ProcessEnv): string | undefined {
@@ -29,13 +24,13 @@ export class SecretEnv {
29
24
  return undefined;
30
25
  }
31
26
 
32
- static read(name: string, inlined?: string): string | undefined {
33
- return SecretEnv.#value(name, process.env) ?? inlined;
27
+ static read(name: string): string | undefined {
28
+ return SecretEnv.#value(name, process.env);
34
29
  }
35
30
 
36
- static json(name: string, inlined?: unknown): unknown {
31
+ static json(name: string): unknown {
37
32
  const text = SecretEnv.#value(name, process.env);
38
- return text === undefined ? inlined : SecretEnv.#parse(name, text);
33
+ return text === undefined ? undefined : SecretEnv.#parse(name, text);
39
34
  }
40
35
 
41
36
  static #parse(name: string, text: string): unknown[] {
@@ -53,7 +48,9 @@ export class SecretEnv {
53
48
  }
54
49
 
55
50
  static format(entries: readonly SecretEnvEntry[]): string {
56
- return entries.map(({ name, kind }) => (kind === "string" ? name : `${name}:${kind}`)).join(",");
51
+ return entries
52
+ .map(({ name, kind, ahead = [] }) => `${[name, ...ahead].join("|")}${kind === "string" ? "" : `:${kind}`}`)
53
+ .join(",");
57
54
  }
58
55
 
59
56
  static parse(list: string | undefined): SecretEnvEntry[] {
@@ -62,37 +59,40 @@ export class SecretEnv {
62
59
  .map((entry) => entry.trim())
63
60
  .filter(Boolean)
64
61
  .map((entry) => {
65
- const [name = "", kind] = entry.split(":");
66
- return { name, kind: kind === "json" || kind === "multiline" ? kind : "string" };
62
+ const [names = "", kind] = entry.split(":");
63
+ const [name = "", ...ahead] = names.split("|");
64
+ return {
65
+ name,
66
+ kind: kind === "json" || kind === "multiline" ? kind : "string",
67
+ ...(ahead.length ? { ahead } : {}),
68
+ };
67
69
  });
68
70
  }
69
71
 
70
- static check(logger: SecretEnvLogger, env: NodeJS.ProcessEnv = process.env): SecretEnvReport {
72
+ static check(logger: SecretEnvLogger, env: NodeJS.ProcessEnv = process.env): void {
71
73
  const missing: string[] = [];
72
74
  const escaped: string[] = [];
73
- for (const { name, kind } of SecretEnv.parse(env[SecretEnv.listKey])) {
75
+ for (const { name, kind, ahead = [] } of SecretEnv.parse(env[SecretEnv.listKey])) {
74
76
  const value = SecretEnv.#value(name, env);
75
- if (value === undefined) missing.push(name);
76
- else if (kind === "json") SecretEnv.#parse(name, value);
77
+ if (value === undefined) {
78
+ if (!ahead.some((own) => env[own])) missing.push(name);
79
+ } else if (kind === "json") SecretEnv.#parse(name, value);
77
80
  else if (kind === "multiline" && value.includes("\\n") && !value.includes("\n")) escaped.push(name);
78
81
  }
79
82
  if (escaped.length)
80
83
  logger.warn(
81
84
  `${escaped.join(", ")} ${escaped.length === 1 ? "holds" : "hold"} a backslash and an n where a line should break, as a key pasted onto one line does. Set ${escaped.length === 1 ? "it" : "them"} with real line breaks; \`akan secret-env\` writes ${escaped.length === 1 ? "it" : "them"} so.`,
82
85
  );
83
- if (missing.length) logger.warn(SecretEnv.#missingMessage(missing, env));
84
- return { missing, escaped };
86
+ if (missing.length) throw new AkanError("secretEnvMissing", SecretEnv.#missingMessage(missing, env));
85
87
  }
86
88
 
87
89
  static #missingMessage(missing: string[], env: NodeJS.ProcessEnv) {
88
90
  const one = missing.length === 1;
89
91
  const subject = one
90
- ? "1 secret env value this server declares is not set"
91
- : `${missing.length} secret env values this server declares are not set`;
92
+ ? "1 secret env value this server reads from its process env is not set"
93
+ : `${missing.length} secret env values this server reads from its process env are not set`;
92
94
  const them = one ? "it" : "them";
93
- if (env[SecretEnv.fallbackKey] === "image")
94
- return `${subject}, so it uses the ${one ? "value" : "values"} built into this image (akan build --inline-secrets): ${missing.join(", ")}. Set ${them} in the deployment's environment and build without the flag; akanjs 3.5.0 removes it.`;
95
95
  const command = `akan secret-env ${env.AKAN_PUBLIC_APP_NAME || "<app>"} --env ${env.AKAN_PUBLIC_ENV || "<env>"}`;
96
- return `${subject}: ${missing.join(", ")}. The framework does not stop for ${them} yet, though whatever reads ${them} may, and akanjs 3.5.0 will refuse to boot. Set ${them} in the deployment's environment; \`${command}\` lists every name.`;
96
+ return `${subject}, so it does not start: ${missing.join(", ")}. Its build left the ${one ? "value" : "values"} out of the image. Set ${them} in the deployment's environment; \`${command}\` lists every name and writes the values from the env file.`;
97
97
  }
98
98
  }
package/types/index.d.ts CHANGED
@@ -39,9 +39,13 @@ export interface DockerImageConfig {
39
39
  export type DockerConfig = string | DockerImageConfig;
40
40
  /**
41
41
  * The app's `docker` with the fields it names replaced and its `env` laid over the app's key by key, written beside
42
- * the Dockerfile as `Dockerfile.<name>`.
42
+ * the Dockerfile as `Dockerfile.<name>`. `profile` names a server env profile: the build carries
43
+ * `env/env.server.<env>.<profile>.ts` beside the environment's own env file, and the variant's `AKAN_ENV_PROFILE`
44
+ * picks it when the server starts.
43
45
  */
44
- export type DockerVariantOption = Partial<DockerImageConfig>;
46
+ export type DockerVariantOption = Partial<DockerImageConfig> & {
47
+ profile?: string;
48
+ };
45
49
  export type DockerOption = string | (Partial<DockerImageConfig> & {
46
50
  variants?: Record<string, DockerVariantOption>;
47
51
  });
@@ -0,0 +1,7 @@
1
+ export declare class EnvProfile {
2
+ static readonly key = "AKAN_ENV_PROFILE";
3
+ static readonly carriedKey = "AKAN_BUILD_ENV_PROFILES";
4
+ static readonly namePattern: RegExp;
5
+ static format(profiles: readonly string[]): string;
6
+ static active(env?: NodeJS.ProcessEnv, carried?: string | undefined): string | null;
7
+ }
@@ -2,10 +2,8 @@ export type SecretEnvKind = "string" | "json" | "multiline";
2
2
  export interface SecretEnvEntry {
3
3
  name: string;
4
4
  kind: SecretEnvKind;
5
- }
6
- export interface SecretEnvReport {
7
- missing: string[];
8
- escaped: string[];
5
+ /** The developer's own variables the env file reads first (`process.env.MY_URL ?? "…"`): one set stands in. */
6
+ ahead?: string[];
9
7
  }
10
8
  interface SecretEnvLogger {
11
9
  warn: (message: string) => void;
@@ -13,11 +11,10 @@ interface SecretEnvLogger {
13
11
  export declare class SecretEnv {
14
12
  #private;
15
13
  static readonly listKey = "AKAN_ENV_NAMES";
16
- static readonly fallbackKey = "AKAN_ENV_FALLBACK";
17
- static read(name: string, inlined?: string): string | undefined;
18
- static json(name: string, inlined?: unknown): unknown;
14
+ static read(name: string): string | undefined;
15
+ static json(name: string): unknown;
19
16
  static format(entries: readonly SecretEnvEntry[]): string;
20
17
  static parse(list: string | undefined): SecretEnvEntry[];
21
- static check(logger: SecretEnvLogger, env?: NodeJS.ProcessEnv): SecretEnvReport;
18
+ static check(logger: SecretEnvLogger, env?: NodeJS.ProcessEnv): void;
22
19
  }
23
20
  export {};
@@ -153,11 +153,20 @@ final class AkanNativeCall: @unchecked Sendable {
153
153
  /// sheet goes away) and only logs it; a completion handler or a plugin call waiting for that
154
154
  /// controller would then wait forever. So a request during a transition waits for it to end (up
155
155
  /// to three times), and `otherwise` runs when there is no window or the presentation was refused.
156
+ /// A `.fullScreen` controller is presented `.overFullScreen`: `.fullScreen` takes the web view out of the
157
+ /// window, iOS then suspends the page's process in the idle jetsam band, and a camera's memory ends it.
156
158
  @MainActor
157
159
  enum AkanNativePresent {
158
160
  static func present(_ controller: UIViewController, over root: UIViewController?, attempt: Int = 0,
159
161
  completion: (@MainActor () -> Void)? = nil, otherwise: @escaping @MainActor () -> Void)
160
162
  {
163
+ if controller.modalPresentationStyle == .fullScreen {
164
+ controller.modalPresentationStyle = .overFullScreen
165
+ controller.modalPresentationCapturesStatusBarAppearance = true
166
+ if controller.presentationController?.shouldRemovePresentersView == true {
167
+ AkanNativeLog.info("\(type(of: controller)) still takes the page out of the window: its presentationController was read while it was .fullScreen, so set .overFullScreen before reading it")
168
+ }
169
+ }
161
170
  guard var top = root, top.viewIfLoaded?.window != nil else { return otherwise() }
162
171
  while let next = top.presentedViewController { top = next }
163
172
  if top.isBeingPresented || top.isBeingDismissed, attempt < 3, let coordinator = top.transitionCoordinator {
@@ -1,11 +1,11 @@
1
1
  import SafariServices
2
2
  import UIKit
3
3
 
4
- /// SFSafariViewController, presented full screen from the topmost controller
4
+ /// SFSafariViewController, presented over the full screen from the topmost controller (AkanNativePresent)
5
5
  /// (capacitor-plugins/browser/ios/Sources/BrowserPlugin/Browser.swift and BrowserPlugin.swift).
6
6
  /// - http/https only (Browser.swift:19): anything else crashes SFSafariViewController.
7
7
  /// - finished: safariViewControllerDidFinish, sent for Done and the edge swipe. It is not sent
8
- /// for a dismissal the app asks for, so close() never produces it. With .fullScreen there is no
8
+ /// for a dismissal the app asks for, so close() never produces it. With .overFullScreen there is no
9
9
  /// swipe-down dismissal that would bypass the delegate.
10
10
  /// - SFSafariViewController dismisses itself after Done; Capacitor dismisses the presenter again
11
11
  /// in didFinish (BrowserPlugin.swift:31-39), which can dismiss an unrelated controller. Not here.
@@ -41,7 +41,8 @@ final class BrowserPlugin: NSObject, BrowserPluginSpec, @MainActor SFSafariViewC
41
41
  }
42
42
  let controller = SFSafariViewController(url: url)
43
43
  controller.delegate = self
44
- controller.modalPresentationStyle = .fullScreen
44
+ controller.modalPresentationStyle = .overFullScreen
45
+ controller.modalPresentationCapturesStatusBarAppearance = true
45
46
  safari = controller
46
47
  context.present(controller, completion: { reply.resolve() }) { [weak self] in
47
48
  self?.safari = nil
@@ -157,6 +157,9 @@ final class CameraPlugin: NSObject, CameraPluginSpec, UIImagePickerControllerDel
157
157
  picker.cameraDevice = .front
158
158
  }
159
159
  picker.delegate = self
160
+ //? Before presentationController is read, which fixes the style: .fullScreen would suspend the page (AkanNativePresent).
161
+ picker.modalPresentationStyle = .overFullScreen
162
+ picker.modalPresentationCapturesStatusBarAppearance = true
160
163
  picker.presentationController?.delegate = self
161
164
  pending = (reply, quality)
162
165
  context.present(picker) { [weak self] in
@@ -31,11 +31,7 @@ export const bootCsr = async (context: CsrRouteContext) => {
31
31
  const [device, jwt] = await Promise.all([Device.load({ supportLanguages: i18n.locales }), getStoredAuthToken()]);
32
32
 
33
33
  if (mobileTarget && window.location.pathname === "/")
34
- window.history.replaceState(
35
- window.history.state,
36
- "",
37
- `${mobileHomePath(device.lang, mobileTarget)}${window.location.search}${window.location.hash}`,
38
- );
34
+ window.history.replaceState(window.history.state, "", mobileHomeHref(device.lang, mobileTarget, window.location));
39
35
  else if (isPathLangPlaceholder)
40
36
  window.history.replaceState(window.history.state, "", onLang(window.location, device.lang, i18n.locales));
41
37
  const pathname = csrLocation.pathname;
@@ -105,9 +101,13 @@ function onLang(location: Location, lang: string | null, locales: string[]) {
105
101
  return `/${segments.join("/")}${query ? `?${query}` : ""}${location.hash}`;
106
102
  }
107
103
 
108
- function mobileHomePath(lang: string, target: { basePath?: string; indexPath?: string }) {
109
- const segments = [lang, target.basePath, target.indexPath]
104
+ function mobileHomeHref(lang: string, target: { basePath?: string; indexPath?: string }, location: Location) {
105
+ const [indexHref = "", indexHash = ""] = (target.indexPath ?? "").split("#");
106
+ const [indexPathname = "", indexQuery = ""] = indexHref.split("?");
107
+ const segments = [lang, target.basePath, indexPathname]
110
108
  .flatMap((part) => (part ?? "").split("/"))
111
109
  .filter((segment) => segment.length > 0);
112
- return `/${segments.join("/")}`;
110
+ const query = [indexQuery, location.search.slice(1)].filter(Boolean).join("&");
111
+ const hash = location.hash || (indexHash ? `#${indexHash}` : "");
112
+ return `/${segments.join("/")}${query ? `?${query}` : ""}${hash}`;
113
113
  }
@@ -187,7 +187,7 @@ export class NativeNavigation {
187
187
  }
188
188
 
189
189
  #leavesApp(path: string) {
190
- const fallbackPath = window.__AKAN_MOBILE_TARGET__?.indexPath ?? "/";
190
+ const fallbackPath = (window.__AKAN_MOBILE_TARGET__?.indexPath ?? "/").split(/[?#]/, 1)[0] || "/";
191
191
  return this.#didResetStack || NativeNavigation.#homeRelative(path) === fallbackPath;
192
192
  }
193
193