Skip to content

Commit a08ec0a

Browse files
committed
feat: make groupIdentifier required
1 parent 24e7735 commit a08ec0a

8 files changed

Lines changed: 37 additions & 33 deletions

File tree

plugin/src/features/ios/eas/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { addApplicationGroupsEntitlement, getWidgetExtensionEntitlements } from
55
export interface ConfigureEasBuildProps {
66
bundleIdentifier: string
77
targetName: string
8-
groupIdentifier?: string
8+
groupIdentifier: string
99
}
1010

1111
/**

plugin/src/features/ios/files/entitlements.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,21 @@ import { logger } from '../../../utils'
99
*/
1010
export function addApplicationGroupsEntitlement(
1111
entitlements: Record<string, any>,
12-
groupIdentifier?: string
12+
groupIdentifier: string
1313
): Record<string, any> {
14-
if (groupIdentifier) {
15-
const existingApplicationGroups = (
16-
(entitlements['com.apple.security.application-groups'] as string[]) ?? []
17-
).filter(Boolean)
14+
const existingApplicationGroups = (
15+
(entitlements['com.apple.security.application-groups'] as string[]) ?? []
16+
).filter(Boolean)
1817

19-
entitlements['com.apple.security.application-groups'] = [groupIdentifier, ...existingApplicationGroups]
20-
}
18+
entitlements['com.apple.security.application-groups'] = [groupIdentifier, ...existingApplicationGroups]
2119

2220
return entitlements
2321
}
2422

2523
/**
2624
* Gets the entitlements for the widget extension.
2725
*/
28-
export function getWidgetExtensionEntitlements(groupIdentifier?: string): Record<string, any> {
26+
export function getWidgetExtensionEntitlements(groupIdentifier: string): Record<string, any> {
2927
const entitlements: Record<string, any> = {}
3028
addApplicationGroupsEntitlement(entitlements, groupIdentifier)
3129
return entitlements
@@ -34,7 +32,7 @@ export function getWidgetExtensionEntitlements(groupIdentifier?: string): Record
3432
export interface GenerateEntitlementsOptions {
3533
targetPath: string
3634
targetName: string
37-
groupIdentifier?: string
35+
groupIdentifier: string
3836
}
3937

4038
/**

plugin/src/features/ios/files/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { generateSwiftFiles } from './swift'
1111
export interface GenerateWidgetExtensionFilesProps {
1212
targetName: string
1313
widgets?: WidgetConfig[]
14-
groupIdentifier?: string
14+
groupIdentifier: string
1515
}
1616

1717
/**

plugin/src/features/ios/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface WithIOSProps {
1212
bundleIdentifier: string
1313
deploymentTarget: string
1414
widgets?: WidgetConfig[]
15-
groupIdentifier?: string
15+
groupIdentifier: string
1616
}
1717

1818
/**

plugin/src/features/ios/plist/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { join as joinPath } from 'path'
55

66
export interface ConfigureMainAppPlistProps {
77
targetName: string
8-
groupIdentifier?: string
8+
groupIdentifier: string
99
}
1010

1111
/**
@@ -42,9 +42,7 @@ export const configureMainAppPlist: ConfigPlugin<ConfigureMainAppPlistProps> = (
4242
},
4343
]
4444

45-
if (groupIdentifier) {
46-
;(content as any)['Voltra_AppGroupIdentifier'] = groupIdentifier
47-
}
45+
;(content as any)['Voltra_AppGroupIdentifier'] = groupIdentifier
4846

4947
writeFileSync(filePath, plist.build(content))
5048
}

plugin/src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ const withVoltra: VoltraConfigPlugin = (config, props) => {
1919
// Validate props at entry point
2020
validateProps(props)
2121

22+
// After validation, props is guaranteed to be defined and have groupIdentifier
23+
if (!props) {
24+
throw new Error('Voltra plugin requires configuration. Please provide at least groupIdentifier in your plugin config.')
25+
}
26+
2227
// Use deploymentTarget from props if provided, otherwise fall back to default
23-
const deploymentTarget = props?.deploymentTarget || IOS.DEPLOYMENT_TARGET
28+
const deploymentTarget = props.deploymentTarget || IOS.DEPLOYMENT_TARGET
2429
const targetName = `${IOSConfig.XcodeUtils.sanitizedName(config.name)}LiveActivity`
2530
const bundleIdentifier = `${config.ios?.bundleIdentifier}.${targetName}`
2631

@@ -34,9 +39,9 @@ const withVoltra: VoltraConfigPlugin = (config, props) => {
3439
...config.ios?.infoPlist,
3540
NSSupportsLiveActivities: true,
3641
NSSupportsLiveActivitiesFrequentUpdates: false,
37-
...(props?.groupIdentifier ? { Voltra_AppGroupIdentifier: props.groupIdentifier } : {}),
42+
Voltra_AppGroupIdentifier: props.groupIdentifier,
3843
// Store widget IDs in Info.plist for native module to access
39-
...(props?.widgets && props.widgets.length > 0 ? { Voltra_WidgetIds: props.widgets.map((w) => w.id) } : {}),
44+
...(props.widgets && props.widgets.length > 0 ? { Voltra_WidgetIds: props.widgets.map((w) => w.id) } : {}),
4045
},
4146
}
4247

@@ -45,12 +50,12 @@ const withVoltra: VoltraConfigPlugin = (config, props) => {
4550
targetName,
4651
bundleIdentifier,
4752
deploymentTarget,
48-
widgets: props?.widgets,
49-
groupIdentifier: props?.groupIdentifier,
53+
widgets: props.widgets,
54+
groupIdentifier: props.groupIdentifier,
5055
})
5156

5257
// Optionally enable push notifications
53-
if (props?.enablePushNotifications) {
58+
if (props.enablePushNotifications) {
5459
config = withPushNotifications(config)
5560
}
5661

plugin/src/types/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface ConfigPluginProps {
1313
/**
1414
* App group identifier for sharing data between app and widget extension
1515
*/
16-
groupIdentifier?: string
16+
groupIdentifier: string
1717
/**
1818
* Configuration for home screen widgets
1919
* Each widget will be available in the widget gallery
@@ -39,7 +39,7 @@ export interface IOSPluginProps {
3939
bundleIdentifier: string
4040
deploymentTarget: string
4141
widgets?: WidgetConfig[]
42-
groupIdentifier?: string
42+
groupIdentifier: string
4343
projectRoot: string
4444
platformProjectRoot: string
4545
}

plugin/src/validation/validateProps.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ import { validateWidgetConfig } from './validateWidget'
77
*/
88
export function validateProps(props: ConfigPluginProps | undefined): void {
99
if (!props) {
10-
return // No props is valid
10+
throw new Error('Voltra plugin requires configuration. Please provide at least groupIdentifier in your plugin config.')
1111
}
1212

13-
// Validate group identifier format if provided
14-
if (props.groupIdentifier !== undefined) {
15-
if (typeof props.groupIdentifier !== 'string') {
16-
throw new Error('groupIdentifier must be a string')
17-
}
13+
// Validate group identifier is provided
14+
if (!props.groupIdentifier) {
15+
throw new Error('groupIdentifier is required. Please provide a groupIdentifier in your Voltra plugin config.')
16+
}
1817

19-
if (!props.groupIdentifier.startsWith('group.')) {
20-
throw new Error(`groupIdentifier '${props.groupIdentifier}' must start with 'group.'`)
21-
}
18+
// Validate group identifier format
19+
if (typeof props.groupIdentifier !== 'string') {
20+
throw new Error('groupIdentifier must be a string')
21+
}
22+
23+
if (!props.groupIdentifier.startsWith('group.')) {
24+
throw new Error(`groupIdentifier '${props.groupIdentifier}' must start with 'group.'`)
2225
}
2326

2427
// Validate widgets if provided

0 commit comments

Comments
 (0)