@akanjs/devkit 3.4.0-rc.1 → 3.4.0-rc.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.
@@ -158,7 +158,7 @@ describe("NativeConfig.build", () => {
158
158
  platform: "android",
159
159
  });
160
160
 
161
- expect(warnings).toEqual(["Permission 'speech' has no native plugin yet; the app ships without it."]);
161
+ expect(warnings).toEqual([]);
162
162
  expect(config).toEqual({
163
163
  app: { id: "com.portal.admin", name: "Portal Admin", fileName: "portal-admin", version: "2.1.0", build: 42 },
164
164
  web: { dir: "/repo/dist/native/portal/admin/web" },
@@ -180,7 +180,10 @@ describe("NativeConfig.build", () => {
180
180
  NSLocationAlwaysUsageDescription: "Portal Admin requires access to the location to get the user's location.",
181
181
  NSLocationWhenInUseUsageDescription: "Portal Admin requires access to the location to get the user's location.",
182
182
  NSContactsUsageDescription: "Portal Admin requires access to the contacts to find people you know.",
183
+ NSMicrophoneUsageDescription: "Portal Admin requires access to the microphone to recognize speech.",
184
+ NSSpeechRecognitionUsageDescription: "Portal Admin requires speech recognition to turn speech into text.",
183
185
  },
186
+ permissions: { microphone: true, speech: true },
184
187
  deepLinks: { domains: [{ host: "portal.example", pathPrefixes: ["/en/admin", "/ko/admin"] }] },
185
188
  native: {
186
189
  ios: { infoPlist: { ITSAppUsesNonExemptEncryption: false } },
@@ -506,6 +509,38 @@ describe("NativeConfig.build", () => {
506
509
  expect((await NativeApi.load(repoApp)).validateConfig(config, { appDir: root })).toEqual([]);
507
510
  });
508
511
 
512
+ test("a microphone permission gives the shell its usage key with no plugin, and desktop.infoPlist reaches the macOS build", async () => {
513
+ const root = await makeTempRoot();
514
+ const infoPlist = {
515
+ NSMicrophoneUsageDescription: "Talk in meetings.",
516
+ NSCameraUsageDescription: "Join video calls.",
517
+ };
518
+ const { config, warnings } = NativeConfig.build({
519
+ appPath: root,
520
+ target: {
521
+ ...minimalTarget,
522
+ permissions: ["microphone"],
523
+ deepLinks: undefined,
524
+ android: undefined,
525
+ desktop: { infoPlist },
526
+ },
527
+ webDir: path.join(root, "web"),
528
+ contributions: [],
529
+ locales: ["en"],
530
+ platform: "macos",
531
+ });
532
+
533
+ expect(warnings).toEqual([]);
534
+ expect(config.permissions).toEqual({ microphone: true });
535
+ expect(config.usageDescriptions).toEqual({
536
+ NSMicrophoneUsageDescription: `${minimalTarget.appName} requires access to the microphone for calls and recordings.`,
537
+ });
538
+ expect(config.native?.macos).toEqual({ infoPlist });
539
+ await mkdir(path.join(root, "web"), { recursive: true });
540
+ await writeFile(path.join(root, "web/index.html"), "<html><head></head><body></body></html>");
541
+ expect((await NativeApi.load(repoApp)).validateConfig(config, { appDir: root })).toEqual([]);
542
+ });
543
+
509
544
  test("ios.hideFormAccessoryBar reaches the iOS shell next to the dev build's id suffix, and the runtime accepts it", async () => {
510
545
  const root = await makeTempRoot();
511
546
  const build = (ios?: { hideFormAccessoryBar?: boolean }) =>
@@ -46,6 +46,7 @@ export interface NativeConfigResult {
46
46
  }
47
47
 
48
48
  type NativeIos = NonNullable<NonNullable<AkanNativeConfig["native"]>["ios"]>;
49
+ type NativeWebPermissions = NonNullable<AkanNativeConfig["permissions"]>;
49
50
 
50
51
  export class NativeConfig {
51
52
  //* What every akanjs page may call: routing, lifecycle, links, storage, the device facts the runtime reads, the
@@ -101,7 +102,8 @@ export class NativeConfig {
101
102
  ];
102
103
  //? Also bounds the links the shell hands to the OS; on mobile, openExternalUrl sends http(s) to the browser plugin.
103
104
  static readonly defaultOpenUrls: readonly string[] = ["https://*:*", "mailto:*", "tel:*"];
104
- //* Used when no plugin of the app or its libs claims the permission; speech has no native plugin yet.
105
+ //* Used when no plugin of the app or its libs claims the permission. microphone and speech bring no plugin: the page's
106
+ //* own getUserMedia and webkitSpeechRecognition use them, and webPermissions gives the shell their usage keys.
105
107
  static readonly builtinContributions: { [permission in NativePermission]: AkanPluginNativeConfig } = {
106
108
  camera: {
107
109
  permission: "camera",
@@ -128,8 +130,25 @@ export class NativeConfig {
128
130
  "$(PRODUCT_NAME) requires access to the location to get the user's location.",
129
131
  },
130
132
  },
133
+ microphone: {
134
+ permission: "microphone",
135
+ usageDescriptions: {
136
+ microphoneUsageDescription: "$(PRODUCT_NAME) requires access to the microphone for calls and recordings.",
137
+ },
138
+ },
131
139
  push: { permission: "push", plugins: ["push"] },
132
- speech: { permission: "speech" },
140
+ speech: {
141
+ permission: "speech",
142
+ usageDescriptions: {
143
+ microphoneUsageDescription: "$(PRODUCT_NAME) requires access to the microphone to recognize speech.",
144
+ speechRecognitionUsageDescription: "$(PRODUCT_NAME) requires speech recognition to turn speech into text.",
145
+ },
146
+ },
147
+ };
148
+ //? Speech recognition listens through the microphone, and WebKit refuses it without both usage texts.
149
+ static readonly webPermissions: { [permission in NativePermission]?: (keyof NativeWebPermissions)[] } = {
150
+ microphone: ["microphone"],
151
+ speech: ["microphone", "speech"],
133
152
  };
134
153
 
135
154
  static build({
@@ -150,7 +169,7 @@ export class NativeConfig {
150
169
  const applied = (target.permissions ?? []).flatMap((permission) => {
151
170
  const claimed = contributions.filter((contribution) => contribution.permission === permission);
152
171
  const used = claimed.length ? claimed : [NativeConfig.builtinContributions[permission]];
153
- if (!used.some((contribution) => contribution.plugins?.length))
172
+ if (!used.some((contribution) => contribution.plugins?.length) && !NativeConfig.webPermissions[permission])
154
173
  warnings.push(`Permission '${permission}' has no native plugin yet; the app ships without it.`);
155
174
  return used;
156
175
  });
@@ -214,7 +233,9 @@ export class NativeConfig {
214
233
  ...Object.entries(target.ios?.files ?? {}).map(([to, from]) => ({ from: abs(from), to: `ios/${to}` })),
215
234
  ...Object.entries(target.android?.files ?? {}).map(([to, from]) => ({ from: abs(from), to: `android/${to}` })),
216
235
  ];
217
- const macos = NativeConfig.#compact({ entitlements: target.desktop?.entitlements });
236
+ const { entitlements, infoPlist } = target.desktop ?? {};
237
+ const macos = NativeConfig.#compact({ entitlements, infoPlist });
238
+ const webPermissions = NativeConfig.#webPermissionsOf(target);
218
239
  const native = NativeConfig.#compact({ ios, macos, android, resources });
219
240
  const googleServices = target.android?.googleServices;
220
241
  const pushAndroid = target.android?.push;
@@ -248,6 +269,7 @@ export class NativeConfig {
248
269
  ],
249
270
  ...(csp ? { security: { csp } } : {}),
250
271
  ...(Object.keys(usageDescriptions).length ? { usageDescriptions } : {}),
272
+ ...(Object.keys(webPermissions).length ? { permissions: webPermissions } : {}),
251
273
  ...(target.deepLinks?.schemes?.length || target.deepLinks?.domains?.length
252
274
  ? { deepLinks: NativeConfig.#deepLinks(target, locales, i18n) }
253
275
  : {}),
@@ -452,6 +474,11 @@ export class NativeConfig {
452
474
  }
453
475
 
454
476
  /** Drops empty arrays and objects, and answers undefined when nothing is left. */
477
+ static #webPermissionsOf(target: AkanNativeTarget): NativeWebPermissions {
478
+ const names = (target.permissions ?? []).flatMap((permission) => NativeConfig.webPermissions[permission] ?? []);
479
+ return Object.fromEntries(names.map((name) => [name, true]));
480
+ }
481
+
455
482
  static #compact<T extends object>(value: { [key: string]: unknown }): T | undefined {
456
483
  const kept = Object.entries(value).filter(([, entry]) =>
457
484
  Array.isArray(entry)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "3.4.0-rc.1",
3
+ "version": "3.4.0-rc.2",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -52,10 +52,10 @@
52
52
  "./workspace/getRelatedCnsts": "./workspace/getRelatedCnsts.ts"
53
53
  },
54
54
  "dependencies": {
55
- "@akanjs/language": "3.4.0-rc.1",
55
+ "@akanjs/language": "3.4.0-rc.2",
56
56
  "@inquirer/prompts": "^8.7.3",
57
57
  "@tailwindcss/node": "^4.3.3",
58
- "akanjs": "3.4.0-rc.1",
58
+ "akanjs": "3.4.0-rc.2",
59
59
  "chalk": "^6.0.1",
60
60
  "commander": "^15.0.0",
61
61
  "dayjs": "^1.11.23",