@jskit-ai/agent-docs 0.1.397 → 0.1.398

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.
Files changed (89) hide show
  1. package/guide/agent/app-extras/assistant-conversation.md +1 -2
  2. package/guide/agent/app-extras/assistant.md +171 -20
  3. package/guide/agent/app-extras/mobile-capacitor.md +110 -4
  4. package/guide/agent/app-extras/push-notifications.md +149 -0
  5. package/guide/agent/app-extras/realtime.md +11 -0
  6. package/guide/agent/app-setup/authentication.md +93 -1
  7. package/guide/agent/framework/client-features.md +65 -0
  8. package/guide/agent/framework/test-pass.md +3 -1
  9. package/guide/agent/framework/typed-features.md +12 -0
  10. package/guide/agent/index.md +1 -0
  11. package/guide/agent/recipes/file-uploads-and-images.md +24 -1
  12. package/guide/agent/recipes/installable-app.md +76 -82
  13. package/guide/agent/recipes/payments-and-subscriptions.md +30 -1
  14. package/package.json +1 -1
  15. package/patterns/feature-package/example/booking-engine/package.json +1 -1
  16. package/patterns/minimal-foundation/example/config/public.js +9 -1
  17. package/patterns/minimal-foundation/example/package.json +3 -3
  18. package/patterns/shell-foundation/example/config/public.js +9 -1
  19. package/patterns/shell-foundation/example/package.json +4 -4
  20. package/patterns/shell-foundation/example/packages/main/package.json +1 -1
  21. package/reference/autogen/PATTERN_INDEX.md +106 -40
  22. package/reference/autogen/README.md +4 -0
  23. package/reference/autogen/packages/assistant-core.md +4 -2
  24. package/reference/autogen/packages/assistant-runtime.md +14 -3
  25. package/reference/autogen/packages/auth-core.md +33 -0
  26. package/reference/autogen/packages/auth-provider-local-core.md +35 -2
  27. package/reference/autogen/packages/auth-provider-local-db-core.md +4 -0
  28. package/reference/autogen/packages/auth-web.md +42 -5
  29. package/reference/autogen/packages/http-runtime.md +9 -1
  30. package/reference/autogen/packages/http-web.md +36 -0
  31. package/reference/autogen/packages/mobile-capacitor.md +121 -5
  32. package/reference/autogen/packages/payments-core.md +2 -0
  33. package/reference/autogen/packages/push-core.md +128 -0
  34. package/reference/autogen/packages/push-web.md +99 -0
  35. package/reference/autogen/packages/realtime.md +6 -3
  36. package/reference/autogen/packages/store-purchases-core.md +113 -0
  37. package/reference/autogen/packages/store-purchases-web.md +55 -0
  38. package/reference/autogen/packages/uploads-image-web.md +2 -1
  39. package/reference/autogen/packages/uploads-runtime.md +21 -1
  40. package/reference/autogen/tooling/jskit-catalog.md +23 -1
  41. package/reference/autogen/tooling/jskit-release.md +4 -1
  42. package/skills/jskit/references/client-features.md +65 -0
  43. package/skills/jskit/references/pattern-index.md +106 -40
  44. package/skills/jskit/references/patterns/app/minimal-foundation/example/config/public.js +9 -1
  45. package/skills/jskit/references/patterns/app/minimal-foundation/example/package.json +3 -3
  46. package/skills/jskit/references/patterns/app/shell-foundation/example/config/public.js +9 -1
  47. package/skills/jskit/references/patterns/app/shell-foundation/example/package.json +4 -4
  48. package/skills/jskit/references/patterns/app/shell-foundation/example/packages/main/package.json +1 -1
  49. package/skills/jskit/references/patterns/auth/accounts-hub/example/package.json +3 -3
  50. package/skills/jskit/references/patterns/auth/oidc-sign-in/example/package.json +2 -2
  51. package/skills/jskit/references/patterns/auth/supabase-auth/example/package.json +1 -1
  52. package/skills/jskit/references/patterns/connectors/calendar-cli/example/package.json +5 -5
  53. package/skills/jskit/references/patterns/crud/crud-feature-package/example/packages/books/package.json +3 -3
  54. package/skills/jskit/references/patterns/database/mysql-application/example/package.json +2 -2
  55. package/skills/jskit/references/patterns/database/postgres-application/example/package.json +2 -2
  56. package/skills/jskit/references/patterns/mobile/android-app-actions/PATTERN.md +78 -0
  57. package/skills/jskit/references/patterns/mobile/android-app-actions/example/android/app/src/main/java/com/example/app/SummaryWidget.kt +33 -0
  58. package/skills/jskit/references/patterns/mobile/android-app-actions/example/android/app/src/main/res/layout/summary_widget.xml +17 -0
  59. package/skills/jskit/references/patterns/mobile/android-app-actions/example/android/app/src/main/res/xml/shortcuts.xml +16 -0
  60. package/skills/jskit/references/patterns/mobile/android-app-actions/example/android/app/src/main/res/xml/summary_widget_info.xml +8 -0
  61. package/skills/jskit/references/patterns/mobile/android-application/PATTERN.md +45 -2
  62. package/skills/jskit/references/patterns/mobile/android-application/example/android/app/src/main/AndroidManifest.xml +65 -0
  63. package/skills/jskit/references/patterns/mobile/android-application/example/src/placement.js +19 -0
  64. package/skills/jskit/references/patterns/mobile/ios-app-intents/PATTERN.md +55 -0
  65. package/skills/jskit/references/patterns/mobile/ios-app-intents/example/ios/App/App/Intents/ExampleShortcuts.swift +9 -0
  66. package/skills/jskit/references/patterns/mobile/ios-app-intents/example/ios/App/App/Intents/UnreadCountIntent.swift +33 -0
  67. package/skills/jskit/references/patterns/mobile/ios-application/PATTERN.md +169 -0
  68. package/skills/jskit/references/patterns/mobile/ios-application/example/capacitor.config.json +10 -0
  69. package/skills/jskit/references/patterns/mobile/ios-application/example/ios/App/App/App.entitlements +12 -0
  70. package/skills/jskit/references/patterns/mobile/ios-application/example/ios/App/App/App.swift +20 -0
  71. package/skills/jskit/references/patterns/mobile/ios-application/example/ios/App/App/Info.plist +63 -0
  72. package/skills/jskit/references/patterns/mobile/ios-application/example/package.json +15 -0
  73. package/skills/jskit/references/patterns/mobile/ios-application/example/src/placement.js +19 -0
  74. package/skills/jskit/references/patterns/mobile/ios-live-activity/PATTERN.md +73 -0
  75. package/skills/jskit/references/patterns/mobile/ios-live-activity/example/ios/App/LiveActivities/LiveActivitiesBundle.swift +13 -0
  76. package/skills/jskit/references/patterns/mobile/ios-live-activity/example/src/deliveryActivity.js +33 -0
  77. package/skills/jskit/references/patterns/mobile/ios-share-extension/PATTERN.md +83 -0
  78. package/skills/jskit/references/patterns/mobile/ios-share-extension/example/ios/App/ShareExtension/Info.plist +31 -0
  79. package/skills/jskit/references/patterns/mobile/ios-share-extension/example/ios/App/ShareExtension/ShareExtension.entitlements +10 -0
  80. package/skills/jskit/references/patterns/mobile/ios-share-extension/example/ios/App/ShareExtension/ShareViewController.swift +94 -0
  81. package/skills/jskit/references/patterns/mobile/ios-widget/PATTERN.md +66 -0
  82. package/skills/jskit/references/patterns/mobile/ios-widget/example/ios/App/SummaryWidget/SummaryWidget.swift +64 -0
  83. package/skills/jskit/references/patterns/mobile/ios-widget/example/src/widgetSummary.js +10 -0
  84. package/skills/jskit/references/patterns/realtime/realtime-application/example/package.json +2 -2
  85. package/skills/jskit/references/patterns/server/feature-package/example/booking-engine/package.json +1 -1
  86. package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users/package.json +3 -3
  87. package/skills/jskit/references/patterns/users/user-administration-server/example/packages/users-workspace/package.json +6 -6
  88. package/skills/jskit/references/test-pass.md +3 -1
  89. package/skills/jskit/references/typed-features.md +12 -0
@@ -0,0 +1,63 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>en</string>
7
+ <key>CFBundleDisplayName</key>
8
+ <string>Example App</string>
9
+ <key>CFBundleExecutable</key>
10
+ <string>$(EXECUTABLE_NAME)</string>
11
+ <key>CFBundleIdentifier</key>
12
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13
+ <key>CFBundleInfoDictionaryVersion</key>
14
+ <string>6.0</string>
15
+ <key>CFBundleName</key>
16
+ <string>$(PRODUCT_NAME)</string>
17
+ <key>CFBundlePackageType</key>
18
+ <string>APPL</string>
19
+ <key>CFBundleShortVersionString</key>
20
+ <string>$(MARKETING_VERSION)</string>
21
+ <key>CFBundleURLTypes</key>
22
+ <array>
23
+ <dict>
24
+ <key>CFBundleURLName</key>
25
+ <string>com.example.app</string>
26
+ <key>CFBundleURLSchemes</key>
27
+ <array>
28
+ <string>exampleapp</string>
29
+ </array>
30
+ </dict>
31
+ </array>
32
+ <key>CFBundleVersion</key>
33
+ <string>$(CURRENT_PROJECT_VERSION)</string>
34
+ <key>LSRequiresIPhoneOS</key>
35
+ <true/>
36
+ <key>UIApplicationSceneManifest</key>
37
+ <dict>
38
+ <key>UIApplicationSupportsMultipleScenes</key>
39
+ <false/>
40
+ </dict>
41
+ <key>UILaunchStoryboardName</key>
42
+ <string>LaunchScreen</string>
43
+ <key>UIRequiredDeviceCapabilities</key>
44
+ <array>
45
+ <string>armv7</string>
46
+ </array>
47
+ <key>UISupportedInterfaceOrientations</key>
48
+ <array>
49
+ <string>UIInterfaceOrientationPortrait</string>
50
+ <string>UIInterfaceOrientationLandscapeLeft</string>
51
+ <string>UIInterfaceOrientationLandscapeRight</string>
52
+ </array>
53
+ <key>UISupportedInterfaceOrientations~ipad</key>
54
+ <array>
55
+ <string>UIInterfaceOrientationPortrait</string>
56
+ <string>UIInterfaceOrientationPortraitUpsideDown</string>
57
+ <string>UIInterfaceOrientationLandscapeLeft</string>
58
+ <string>UIInterfaceOrientationLandscapeRight</string>
59
+ </array>
60
+ <key>UIViewControllerBasedStatusBarAppearance</key>
61
+ <true/>
62
+ </dict>
63
+ </plist>
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "example-app",
3
+ "private": true,
4
+ "type": "module",
5
+ "dependencies": {
6
+ "@capacitor/app": "^9.0.2",
7
+ "@capacitor/browser": "^9.0.2",
8
+ "@capacitor/core": "^9.0.0",
9
+ "@capacitor/ios": "^9.0.0",
10
+ "@jskit-ai/mobile-capacitor": "^0.2.72"
11
+ },
12
+ "devDependencies": {
13
+ "@capacitor/cli": "^9.0.0"
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ import { createPlacementRegistry } from "@jskit-ai/shell-web/client/placement";
2
+
3
+ const registry = createPlacementRegistry();
4
+ const { addPlacement } = registry;
5
+
6
+ // The "please update" screen. It renders nothing until the server refuses this app version (426); then its
7
+ // full-screen dialog covers the app, wherever the shell's status outlet is.
8
+ addPlacement({
9
+ id: "mobile.update-required",
10
+ target: "shell.status",
11
+ kind: "component",
12
+ surfaces: ["*"],
13
+ order: 1000,
14
+ componentToken: "mobile.web.update-required"
15
+ });
16
+
17
+ export default function getPlacements() {
18
+ return registry.build();
19
+ }
@@ -0,0 +1,73 @@
1
+ ---
2
+ id: mobile/ios-live-activity
3
+ title: iOS Live Activity
4
+ summary: A Live Activity on the Lock Screen and in the Dynamic Island, started by the app and updated by the app or the server.
5
+ keywords: activitykit, dynamic island, ios, iphone, live activity, lock screen, mobile, push
6
+ requires: @jskit-ai/mobile-capacitor, @capgo/capacitor-live-activities, @jskit-ai/push-core, @capacitor/ios
7
+ ---
8
+
9
+ # iOS Live Activity
10
+
11
+ ## Use when
12
+
13
+ Use this pattern for something happening now that the person follows for minutes or hours: a delivery, a ride, a
14
+ match, a timer, a long job.
15
+
16
+ ## Do not use when
17
+
18
+ Do not use it for lasting information (a widget is for that), or for anything that lasts more than about eight hours.
19
+
20
+ ## Product decisions
21
+
22
+ Choose what the activity shows on the Lock Screen and in the Dynamic Island (its JSON layout and data), when it starts
23
+ and ends, and whether the server updates it.
24
+
25
+ ## Framework APIs
26
+
27
+ ```bash
28
+ npm install @capgo/capacitor-live-activities@^2.0.0
29
+ npx cap sync ios
30
+ ```
31
+
32
+ Follow the plugin's iOS setup in its README: a Widget Extension target named `LiveActivities` (iOS 16.1 or later), the
33
+ App Groups capability on the app and the extension, `NSSupportsLiveActivities` in the app's `Info.plist`, the
34
+ `CapgoLiveActivitiesShared` library linked into the extension, the plugin's `CapgoLiveActivityWidget.template.swift`
35
+ copied in with the App Group set, and the Push Notifications capability on the app for server updates. This pattern's
36
+ `LiveActivitiesBundle.swift` is the extension's entry point.
37
+
38
+ From the screens, `mobile.liveActivities` (the `client.mobile` capability): `supported()`, `start({ layout,
39
+ dynamicIslandLayout, data })` answering the activity's id, `update(id, data)`, `end(id, data)`, and `pushTokens()`.
40
+ From the server, with the token the app sent and push-core's APNs settings:
41
+
42
+ ```js
43
+ await push.updateLiveActivity({ token, environment: "production", event: "update", data: { title, minutes: 2 } });
44
+ await push.updateLiveActivity({ token, event: "end", data: { title, minutes: 0 }, dismissAt: Date.now() + 60_000 });
45
+ ```
46
+
47
+ Each update replaces the activity's whole `data`. Outside `APP_ENV=production` the server logs it and sends nothing.
48
+
49
+ ## Example files
50
+
51
+ `example/ios/App/LiveActivities/LiveActivitiesBundle.swift` and `example/src/deliveryActivity.js` (a layout, starting
52
+ the activity and sending its push token to an app route of its own).
53
+
54
+ ## Variation points
55
+
56
+ The layout, the data, the start and end moments, and whether the server updates it.
57
+
58
+ ## Invariants
59
+
60
+ - Each update carries every value the layout reads.
61
+ - The push token is sent to the server again whenever it changes; ActivityKit gives it after start.
62
+ - Server updates go through push-core, which follows `APP_ENV`.
63
+
64
+ ## Verification
65
+
66
+ On an iPhone: start the activity, see it on the Lock Screen and in the Dynamic Island, update it from the app and from
67
+ the server, end it.
68
+
69
+ ## Avoid
70
+
71
+ - updates that send part of the data
72
+ - polling the server from the activity (it cannot)
73
+ - an activity that never ends
@@ -0,0 +1,13 @@
1
+ import SwiftUI
2
+ import WidgetKit
3
+
4
+ // The widget extension's entry point. CapgoLiveActivityWidget comes from the plugin's template
5
+ // (node_modules/@capgo/capacitor-live-activities/ios/WidgetExtension/CapgoLiveActivityWidget.template.swift), copied
6
+ // into this target as CapgoLiveActivityWidget.swift with the app's App Group set; it draws the JSON layout the app
7
+ // starts each activity with.
8
+ @main
9
+ struct LiveActivitiesBundle: WidgetBundle {
10
+ var body: some Widget {
11
+ CapgoLiveActivityWidget()
12
+ }
13
+ }
@@ -0,0 +1,33 @@
1
+ // A delivery's Live Activity: started from the app, then updated by the app or by the server with the activity's push
2
+ // token. `mobile` is the client.mobile capability; liveActivities does nothing outside iOS.
3
+
4
+ const layout = {
5
+ type: "container",
6
+ direction: "vertical",
7
+ children: [
8
+ { type: "text", content: "{{title}}", fontSize: 16, fontWeight: "bold" },
9
+ { type: "text", content: "Arriving in {{minutes}} min", fontSize: 14 }
10
+ ]
11
+ };
12
+
13
+ const dynamicIslandLayout = {
14
+ expanded: { center: { type: "text", content: "{{title}}" }, bottom: { type: "text", content: "{{minutes}} min" } },
15
+ compactLeading: { type: "text", content: "{{minutes}}" },
16
+ compactTrailing: { type: "text", content: "min" },
17
+ minimal: { type: "text", content: "{{minutes}}" }
18
+ };
19
+
20
+ /**
21
+ * Starts the activity and sends its push token to the app's own route, so the server can update it.
22
+ * @param {{ liveActivities: object }} mobile
23
+ * @param {{ request: (path: string, options: object) => Promise<unknown> }} http The page's HTTP client.
24
+ * @param {{ id: string, title: string, minutes: number }} delivery
25
+ */
26
+ export async function startDeliveryActivity(mobile, http, delivery) {
27
+ if (!(await mobile.liveActivities.supported())) return "";
28
+ const id = await mobile.liveActivities.start({ layout, dynamicIslandLayout, data: { title: delivery.title, minutes: delivery.minutes } });
29
+ // ActivityKit gives the token a moment after start, and may change it: send it again when the app comes back.
30
+ const [token] = (await mobile.liveActivities.pushTokens()).filter((activity) => activity.id === id);
31
+ if (token) await http.request(`/api/deliveries/${encodeURIComponent(delivery.id)}/activity`, { method: "PUT", body: { pushToken: token.pushToken } });
32
+ return id;
33
+ }
@@ -0,0 +1,83 @@
1
+ ---
2
+ id: mobile/ios-share-extension
3
+ title: iOS share extension
4
+ summary: Let people share files, images, links and text from other apps into a JSKIT iOS app, arriving as an upload.
5
+ keywords: app group, extension, ios, iphone, mobile, share, share sheet, upload
6
+ requires: @jskit-ai/mobile-capacitor, @capgo/capacitor-share-target, @capacitor/ios
7
+ ---
8
+
9
+ # iOS share extension
10
+
11
+ ## Use when
12
+
13
+ Use this pattern when people should be able to pick the app in iOS's share sheet (from Photos, Files, Mail, Safari) and
14
+ have what they shared arrive in the app, usually in an upload field. Android needs no extension: the
15
+ `mobile/android-application` pattern's `SEND` intent filters do it.
16
+
17
+ ## Do not use when
18
+
19
+ Do not use it for a web-only app, or when nothing in the app takes files or text from outside.
20
+
21
+ ## Product decisions
22
+
23
+ Choose the App Group id (`group.<bundle id>`), the types the app accepts (the activation rule in the extension's
24
+ `Info.plist`), and the app's page that takes a share (`config.mobile.shareIn.path`, such as `/uploads/shared`).
25
+
26
+ ## Framework APIs
27
+
28
+ Install the plugin and sync:
29
+
30
+ ```bash
31
+ npm install @capgo/capacitor-share-target@^9.0.0
32
+ npx cap sync ios
33
+ ```
34
+
35
+ In Xcode, add a target (File → New → Target → Share Extension) named `ShareExtension` to the app's committed `ios/App`
36
+ project, and give both the app and the extension the App Groups capability with the same group. Replace the extension's
37
+ generated files with this pattern's `example/ios/App/ShareExtension/` (`ShareViewController.swift`, `Info.plist`,
38
+ `ShareExtension.entitlements`), with the app's own App Group id and URL scheme (`config.mobile.auth.customScheme`).
39
+ Set the same group for the plugin in `capacitor.config.json`:
40
+
41
+ ```json
42
+ { "plugins": { "CapacitorShareTarget": { "appGroupId": "group.com.example.app" } } }
43
+ ```
44
+
45
+ The extension copies each shared file into the App Group, writes what was shared under `share-target-data` in the
46
+ group's UserDefaults, and opens the app with `<scheme>://share`. When the app becomes active the plugin reads it, and
47
+ `@jskit-ai/mobile-capacitor`'s share inbox (`client.mobile-share-in`) keeps it and opens
48
+ `config.mobile.shareIn.path`. That page's component calls `takeShared()`, which answers `{ title, texts, files }`
49
+ (`files` are `File` objects) once, and hands the files to its upload field, which checks and uploads them as any other.
50
+
51
+ ```js
52
+ // config/public.js
53
+ config.mobile = { ...config.mobile, shareIn: { path: "/uploads/shared" } };
54
+ ```
55
+
56
+ ## Example files
57
+
58
+ `example/ios/App/ShareExtension/ShareViewController.swift` (JSKIT's own Swift, no dependency),
59
+ `example/ios/App/ShareExtension/Info.plist` (up to ten files or images, one movie, text and one web link) and
60
+ `example/ios/App/ShareExtension/ShareExtension.entitlements` (the App Group). Replace `group.com.example.app` and
61
+ `exampleapp` directly.
62
+
63
+ ## Variation points
64
+
65
+ The activation rule (which types and how many), the App Group, the URL scheme and the app's page for shares.
66
+
67
+ ## Invariants
68
+
69
+ - The app and the extension share one App Group; the plugin's `appGroupId` names it.
70
+ - Shared files are copied into the group, never read from the sharing app's own storage after the extension ends.
71
+ - What arrives is uploaded through the app's ordinary upload fields and their checks.
72
+
73
+ ## Verification
74
+
75
+ On an iPhone: share a photo from Photos, a PDF from Files and a link from Safari to the app; each opens the app's share
76
+ page with what was shared, and the upload field takes it. Share a type the activation rule excludes: the app is not
77
+ offered.
78
+
79
+ ## Avoid
80
+
81
+ - a second App Group, or none, between the app and the extension
82
+ - reading the shared files from their original location
83
+ - an upload path for shared files that skips the field's own checks
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyLists/PLIST-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDisplayName</key>
6
+ <string>Example</string>
7
+ <key>NSExtension</key>
8
+ <dict>
9
+ <key>NSExtensionAttributes</key>
10
+ <dict>
11
+ <key>NSExtensionActivationRule</key>
12
+ <dict>
13
+ <key>NSExtensionActivationSupportsFileWithMaxCount</key>
14
+ <integer>10</integer>
15
+ <key>NSExtensionActivationSupportsImageWithMaxCount</key>
16
+ <integer>10</integer>
17
+ <key>NSExtensionActivationSupportsMovieWithMaxCount</key>
18
+ <integer>1</integer>
19
+ <key>NSExtensionActivationSupportsText</key>
20
+ <true/>
21
+ <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
22
+ <integer>1</integer>
23
+ </dict>
24
+ </dict>
25
+ <key>NSExtensionPointIdentifier</key>
26
+ <string>com.apple.share-services</string>
27
+ <key>NSExtensionPrincipalClass</key>
28
+ <string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
29
+ </dict>
30
+ </dict>
31
+ </plist>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyLists/PLIST-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>com.apple.security.application-groups</key>
6
+ <array>
7
+ <string>group.com.example.app</string>
8
+ </array>
9
+ </dict>
10
+ </plist>
@@ -0,0 +1,94 @@
1
+ import UIKit
2
+ import UniformTypeIdentifiers
3
+
4
+ // The app's share extension: what another app shares (files, images, links, text) is copied into the App Group the app
5
+ // and this extension share, described under "share-target-data" in the group's UserDefaults, which
6
+ // @capgo/capacitor-share-target reads when the app opens, and the app is opened with its own URL scheme.
7
+ // Replace APP_GROUP_ID and APP_URL_SCHEME with the app's own values.
8
+ final class ShareViewController: UIViewController {
9
+ private let APP_GROUP_ID = "group.com.example.app"
10
+ private let APP_URL_SCHEME = "exampleapp"
11
+ private let SHARE_KEY = "share-target-data"
12
+
13
+ override func viewDidLoad() {
14
+ super.viewDidLoad()
15
+ Task { await self.receive() }
16
+ }
17
+
18
+ private func receive() async {
19
+ let items = extensionContext?.inputItems as? [NSExtensionItem] ?? []
20
+ guard let container = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: APP_GROUP_ID) else {
21
+ finish()
22
+ return
23
+ }
24
+ let folder = container.appendingPathComponent("shared-\(UUID().uuidString)", isDirectory: true)
25
+ try? FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
26
+
27
+ var texts: [String] = []
28
+ var files: [[String: String]] = []
29
+ for item in items {
30
+ for provider in item.attachments ?? [] {
31
+ if provider.hasItemConformingToTypeIdentifier(UTType.url.identifier),
32
+ let url = try? await provider.loadItem(forTypeIdentifier: UTType.url.identifier) as? URL, !url.isFileURL {
33
+ texts.append(url.absoluteString)
34
+ } else if provider.hasItemConformingToTypeIdentifier(UTType.plainText.identifier),
35
+ let text = try? await provider.loadItem(forTypeIdentifier: UTType.plainText.identifier) as? String {
36
+ texts.append(text)
37
+ } else if let type = provider.registeredTypeIdentifiers.compactMap(UTType.init).first(where: { $0.conforms(to: .data) }),
38
+ let file = await copy(provider, type: type, into: folder) {
39
+ files.append(file)
40
+ }
41
+ }
42
+ }
43
+
44
+ let defaults = UserDefaults(suiteName: APP_GROUP_ID)
45
+ defaults?.set([
46
+ "title": items.first?.attributedContentText?.string ?? "",
47
+ "texts": texts,
48
+ "files": files
49
+ ], forKey: SHARE_KEY)
50
+ defaults?.synchronize()
51
+ open(URL(string: "\(APP_URL_SCHEME)://share")!)
52
+ finish()
53
+ }
54
+
55
+ // Copies one shared file into the App Group, where the app can read it after this extension ends.
56
+ private func copy(_ provider: NSItemProvider, type: UTType, into folder: URL) async -> [String: String]? {
57
+ await withCheckedContinuation { continuation in
58
+ provider.loadFileRepresentation(forTypeIdentifier: type.identifier) { source, _ in
59
+ guard let source else {
60
+ continuation.resume(returning: nil)
61
+ return
62
+ }
63
+ let name = source.lastPathComponent
64
+ let target = folder.appendingPathComponent(name)
65
+ do {
66
+ try FileManager.default.copyItem(at: source, to: target)
67
+ continuation.resume(returning: [
68
+ "uri": target.path,
69
+ "name": name,
70
+ "mimeType": type.preferredMIMEType ?? "application/octet-stream"
71
+ ])
72
+ } catch {
73
+ continuation.resume(returning: nil)
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ // An extension cannot call UIApplication.shared; the responder chain reaches the app's openURL.
80
+ private func open(_ url: URL) {
81
+ var responder: UIResponder? = self
82
+ while let current = responder {
83
+ if let application = current as? UIApplication {
84
+ application.open(url)
85
+ return
86
+ }
87
+ responder = current.next
88
+ }
89
+ }
90
+
91
+ private func finish() {
92
+ extensionContext?.completeRequest(returningItems: nil)
93
+ }
94
+ }
@@ -0,0 +1,66 @@
1
+ ---
2
+ id: mobile/ios-widget
3
+ title: iOS widget
4
+ summary: A WidgetKit Home Screen widget fed by what the app's screens write to a shared store.
5
+ keywords: app group, home screen, ios, iphone, mobile, shared store, widget, widgetkit
6
+ requires: @jskit-ai/mobile-capacitor, capacitor-widget-bridge, @capacitor/ios
7
+ ---
8
+
9
+ # iOS widget
10
+
11
+ ## Use when
12
+
13
+ Use this pattern when a glance at the Home Screen should show something from the app (unread messages, today's next
14
+ booking, a balance) without opening it.
15
+
16
+ ## Do not use when
17
+
18
+ Do not use it for anything that must be live to the second (a Live Activity is for that), or for private content on a
19
+ shared device.
20
+
21
+ ## Product decisions
22
+
23
+ Choose what the widget shows (a small JSON value), its sizes, and the page a tap opens (`widgetURL`, the app's scheme).
24
+
25
+ ## Framework APIs
26
+
27
+ ```bash
28
+ npm install capacitor-widget-bridge@^9.0.0
29
+ npx cap sync ios
30
+ ```
31
+
32
+ In Xcode, add a Widget Extension target (`SummaryWidget`) to the app's committed `ios/App` project, and give both the
33
+ app and the extension the App Groups capability with the same group. Set the group in `config/public.js`:
34
+
35
+ ```js
36
+ config.mobile = { ...config.mobile, sharedStore: { group: "group.com.example.app" } };
37
+ ```
38
+
39
+ The screens write with `mobile.sharedStore.set(key, value)` (the `client.mobile` capability): JSON, at most 64 KB a
40
+ value, refused above, into the group's UserDefaults; each write asks every widget to reload. On the web it does
41
+ nothing. The widget reads the same key with `UserDefaults(suiteName:)`.
42
+
43
+ ## Example files
44
+
45
+ `example/ios/App/SummaryWidget/SummaryWidget.swift` (the widget: provider, view and configuration) and
46
+ `example/src/widgetSummary.js` (what the screens call). Replace `group.com.example.app` and `exampleapp`.
47
+
48
+ ## Variation points
49
+
50
+ The value's shape, the widget's sizes and views, and the page a tap opens.
51
+
52
+ ## Invariants
53
+
54
+ - The widget reads only the shared store; it never calls the server.
55
+ - The app and the widget share one App Group, named in `config.mobile.sharedStore.group`.
56
+ - Values stay small: the store refuses more than 64 KB.
57
+
58
+ ## Verification
59
+
60
+ On an iPhone: add the widget, change what it shows in the app, see it update; tap it and land on the page it names.
61
+
62
+ ## Avoid
63
+
64
+ - network requests from the widget
65
+ - a second App Group, or different groups for the app and the widget
66
+ - secrets or tokens in the shared store
@@ -0,0 +1,64 @@
1
+ import SwiftUI
2
+ import WidgetKit
3
+
4
+ // A Home Screen widget showing what the app's screens wrote with mobile.sharedStore.set("summary", { title, unread }):
5
+ // JSON in the App Group's UserDefaults, which the widget reads whenever the app asks it to reload.
6
+ private let APP_GROUP_ID = "group.com.example.app"
7
+
8
+ struct Summary: Codable {
9
+ var title: String
10
+ var unread: Int
11
+ }
12
+
13
+ struct SummaryEntry: TimelineEntry {
14
+ let date: Date
15
+ let summary: Summary?
16
+ }
17
+
18
+ struct SummaryProvider: TimelineProvider {
19
+ func placeholder(in context: Context) -> SummaryEntry {
20
+ SummaryEntry(date: Date(), summary: Summary(title: "Inbox", unread: 0))
21
+ }
22
+
23
+ func getSnapshot(in context: Context, completion: @escaping (SummaryEntry) -> Void) {
24
+ completion(SummaryEntry(date: Date(), summary: readSummary()))
25
+ }
26
+
27
+ func getTimeline(in context: Context, completion: @escaping (Timeline<SummaryEntry>) -> Void) {
28
+ // The app reloads the widget after each write, so the timeline never needs to refresh itself.
29
+ completion(Timeline(entries: [SummaryEntry(date: Date(), summary: readSummary())], policy: .never))
30
+ }
31
+
32
+ private func readSummary() -> Summary? {
33
+ guard let text = UserDefaults(suiteName: APP_GROUP_ID)?.string(forKey: "summary"),
34
+ let data = text.data(using: .utf8) else { return nil }
35
+ return try? JSONDecoder().decode(Summary.self, from: data)
36
+ }
37
+ }
38
+
39
+ struct SummaryWidgetView: View {
40
+ let entry: SummaryEntry
41
+
42
+ var body: some View {
43
+ VStack(alignment: .leading, spacing: 4) {
44
+ Text(entry.summary?.title ?? "Example").font(.headline)
45
+ Text(entry.summary.map { "\($0.unread) unread" } ?? "Open the app to start")
46
+ .font(.subheadline)
47
+ .foregroundStyle(.secondary)
48
+ }
49
+ .widgetURL(URL(string: "exampleapp://inbox"))
50
+ .containerBackground(.fill.tertiary, for: .widget)
51
+ }
52
+ }
53
+
54
+ @main
55
+ struct SummaryWidget: Widget {
56
+ var body: some WidgetConfiguration {
57
+ StaticConfiguration(kind: "SummaryWidget", provider: SummaryProvider()) { entry in
58
+ SummaryWidgetView(entry: entry)
59
+ }
60
+ .configurationDisplayName("Summary")
61
+ .description("What's waiting in the app.")
62
+ .supportedFamilies([.systemSmall, .systemMedium])
63
+ }
64
+ }
@@ -0,0 +1,10 @@
1
+ // The screens keep the widget current: after anything that changes what it shows, write the small summary it reads.
2
+ // `mobile` is the client.mobile capability; sharedStore does nothing on the web.
3
+
4
+ /**
5
+ * @param {{ sharedStore: { set: (key: string, value: unknown) => Promise<void> } }} mobile
6
+ * @param {{ title: string, unread: number }} summary
7
+ */
8
+ export function writeWidgetSummary(mobile, summary) {
9
+ return mobile.sharedStore.set("summary", { title: summary.title, unread: summary.unread });
10
+ }
@@ -2,7 +2,7 @@
2
2
  "private": true,
3
3
  "type": "module",
4
4
  "dependencies": {
5
- "@jskit-ai/realtime": "0.2.75",
6
- "@jskit-ai/shell-web": "0.2.71"
5
+ "@jskit-ai/realtime": "0.2.76",
6
+ "@jskit-ai/shell-web": "0.2.72"
7
7
  }
8
8
  }
@@ -5,7 +5,7 @@
5
5
  "private": true,
6
6
  "type": "module",
7
7
  "dependencies": {
8
- "@jskit-ai/kernel": "0.2.40",
8
+ "@jskit-ai/kernel": "0.2.41",
9
9
  "json-rest-schema": "^1.0.20"
10
10
  },
11
11
  "exports": {
@@ -10,9 +10,9 @@
10
10
  "./shared": "./src/shared/index.js"
11
11
  },
12
12
  "dependencies": {
13
- "@jskit-ai/crud-core": "0.2.72",
14
- "@jskit-ai/resource-crud-core": "0.1.234",
15
- "@jskit-ai/users-core": "0.2.83"
13
+ "@jskit-ai/crud-core": "0.2.73",
14
+ "@jskit-ai/resource-crud-core": "0.1.235",
15
+ "@jskit-ai/users-core": "0.2.84"
16
16
  },
17
17
  "jskit": {
18
18
  "kind": "runtime",
@@ -10,14 +10,14 @@
10
10
  "./shared": "./src/shared/index.js"
11
11
  },
12
12
  "dependencies": {
13
- "@jskit-ai/crud-core": "0.2.72",
14
- "@jskit-ai/resource-crud-core": "0.1.234",
15
- "@jskit-ai/users-core": "0.2.83",
16
- "@jskit-ai/workspaces-core": "0.2.83"
13
+ "@jskit-ai/crud-core": "0.2.73",
14
+ "@jskit-ai/resource-crud-core": "0.1.235",
15
+ "@jskit-ai/users-core": "0.2.84",
16
+ "@jskit-ai/workspaces-core": "0.2.84"
17
17
  },
18
18
  "peerDependencies": {
19
- "@jskit-ai/kernel": "0.2.40",
20
- "@jskit-ai/resource-runtime": "0.2.65"
19
+ "@jskit-ai/kernel": "0.2.41",
20
+ "@jskit-ai/resource-runtime": "0.2.66"
21
21
  },
22
22
  "jskit": {
23
23
  "kind": "runtime",
@@ -46,7 +46,9 @@ The rules it applies are in [Typed features](typed-features.md),
46
46
  states once.
47
47
  - `jskit test --list` prints the files a run takes and their total, and runs
48
48
  nothing: the total matches the test files under `tests/`, or a file is named
49
- so that node's default pattern leaves it out.
49
+ so that node's default pattern leaves it out. `npm run verify --list [files]`
50
+ does the same for the whole Verification
51
+ ([A check runs once per tree](typed-features.md#a-check-runs-once-per-tree)).
50
52
  - `jskit test` starts by saying how many files it runs at a time and where that
51
53
  number came from (the host's `V64_TEST_CONCURRENCY`, else half the CPUs), and
52
54
  ends with its 10 slowest files and tests; each file's time is kept in