@smileid/usesmileid_vision_face 12.0.0-beta01
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/CHANGELOG.md +3 -0
- package/LICENSE +21 -0
- package/README.md +50 -0
- package/app.plugin.js +3 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/expo-module.config.json +6 -0
- package/ios/UseSmileIDVisionFaceExpo.podspec +61 -0
- package/ios/UseSmileIDVisionFaceModule/ResizingFrameStorage.swift +181 -0
- package/ios/UseSmileIDVisionFaceModule/UseSmileIDAnalyzerExecutor.swift +119 -0
- package/ios/UseSmileIDVisionFaceModule/UseSmileIDVisionFaceFrameProcessorPlugin.swift +96 -0
- package/ios/UseSmileIDVisionFaceModule/UseSmileIDVisionFaceModule.swift +280 -0
- package/ios/UseSmileIDVisionFaceModule/UseSmileIDVisionFaceSessionHolder.swift +105 -0
- package/package.json +79 -0
- package/plugin/build/index.d.ts +3 -0
- package/plugin/build/index.js +115 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/lib/podfile.d.ts +17 -0
- package/plugin/build/lib/podfile.js +180 -0
- package/plugin/build/lib/podfile.js.map +1 -0
- package/plugin/build/lib/spm.d.ts +33 -0
- package/plugin/build/lib/spm.js +196 -0
- package/plugin/build/lib/spm.js.map +1 -0
- package/plugin/src/index.ts +96 -0
- package/plugin/src/lib/podfile.ts +209 -0
- package/plugin/src/lib/spm.ts +314 -0
- package/plugin/tsconfig.json +19 -0
- package/src/__tests__/use_smile_id_vision_face.test.ts +79 -0
- package/src/index.ts +41 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Injects an idempotent Ruby block into the Expo-generated Podfile's
|
|
2
|
+
// `post_install` hook. The block runs at `pod install` time and wires
|
|
3
|
+
// the Smile ID Swift Package into the autogenerated Pods.xcodeproj
|
|
4
|
+
// for a specific bridge pod target — Pods.xcodeproj only exists at
|
|
5
|
+
// pod-install time, so this is the only hook that can mutate it.
|
|
6
|
+
|
|
7
|
+
import type { SpmPackage, SpmRequirement } from "./spm";
|
|
8
|
+
|
|
9
|
+
const BEGIN_PREFIX = "# === BEGIN smileid-spm:";
|
|
10
|
+
const END_PREFIX = "# === END smileid-spm:";
|
|
11
|
+
|
|
12
|
+
export interface PodfileLinkOptions {
|
|
13
|
+
/** Marker key — distinct per bridge so each plugin owns its own block. */
|
|
14
|
+
marker: string;
|
|
15
|
+
package: SpmPackage;
|
|
16
|
+
/** Pod target name (e.g. `UseSmileIDVisionFaceExpo`). */
|
|
17
|
+
podTarget: string;
|
|
18
|
+
/** SPM library product names to link to the pod target. */
|
|
19
|
+
products: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Idempotently injects an SPM-linking Ruby block into the Podfile's
|
|
24
|
+
* top-level `post_install` block. Re-running on an already-injected
|
|
25
|
+
* Podfile rewrites the same marker block in place (so version /
|
|
26
|
+
* product changes flow through cleanly on the next prebuild).
|
|
27
|
+
*/
|
|
28
|
+
export function injectPodfileSpmBlock(
|
|
29
|
+
podfile: string,
|
|
30
|
+
options: PodfileLinkOptions,
|
|
31
|
+
): string {
|
|
32
|
+
validateRubySafe(options);
|
|
33
|
+
|
|
34
|
+
const block = renderBlock(options);
|
|
35
|
+
const beginMarker = `${BEGIN_PREFIX} ${options.marker} ===`;
|
|
36
|
+
const endMarker = `${END_PREFIX} ${options.marker} ===`;
|
|
37
|
+
|
|
38
|
+
const blockRegex = new RegExp(
|
|
39
|
+
`${escapeRegExp(beginMarker)}[\\s\\S]*?${escapeRegExp(endMarker)}`,
|
|
40
|
+
"m",
|
|
41
|
+
);
|
|
42
|
+
if (blockRegex.test(podfile)) {
|
|
43
|
+
return podfile.replace(blockRegex, block);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Inject at the *start* of the post_install body — right after
|
|
47
|
+
// `post_install do |installer|`. We tried matching the closing
|
|
48
|
+
// `end` pair instead, but a second plugin running on a Podfile
|
|
49
|
+
// already mutated by the first sees a non-flat body and the
|
|
50
|
+
// non-greedy `end…end` match latches onto inner block ends,
|
|
51
|
+
// nesting the second injection inside the first. Anchoring on
|
|
52
|
+
// the opening line removes that failure mode entirely. Order
|
|
53
|
+
// relative to `react_native_post_install` doesn't matter because
|
|
54
|
+
// CocoaPods persists the Pods project at the end of pod install
|
|
55
|
+
// regardless of what we explicitly save mid-block.
|
|
56
|
+
const headerRegex = /(post_install\s+do\s*\|\s*installer\s*\|)\r?\n/;
|
|
57
|
+
const headerMatch = podfile.match(headerRegex);
|
|
58
|
+
if (!headerMatch || headerMatch.index === undefined) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
"[smileid-spm] Could not locate `post_install do |installer|` in Podfile. " +
|
|
61
|
+
"Refusing to append a top-level post_install hook because CocoaPods only honors one — adding a second " +
|
|
62
|
+
"would silently override the React Native post-install plumbing. Restore the Expo Podfile template " +
|
|
63
|
+
"or wire the SPM block in manually.",
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const insertAt = headerMatch.index + headerMatch[0].length;
|
|
67
|
+
const indented =
|
|
68
|
+
block
|
|
69
|
+
.split("\n")
|
|
70
|
+
.map((line) => (line.length > 0 ? ` ${line}` : line))
|
|
71
|
+
.join("\n") + "\n";
|
|
72
|
+
return podfile.slice(0, insertAt) + indented + podfile.slice(insertAt);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// All injected strings flow into single-quoted Ruby literals. We
|
|
76
|
+
// reject characters that could break out of those literals so a
|
|
77
|
+
// typo in the bridge plugin can't produce code that runs during
|
|
78
|
+
// `pod install`. Rejected: single-quote, backslash, control chars.
|
|
79
|
+
function validateRubySafe(options: PodfileLinkOptions): void {
|
|
80
|
+
const fields: Array<[string, string]> = [
|
|
81
|
+
["marker", options.marker],
|
|
82
|
+
["package.url", options.package.url],
|
|
83
|
+
["podTarget", options.podTarget],
|
|
84
|
+
];
|
|
85
|
+
for (const product of options.products) {
|
|
86
|
+
fields.push(["products[*]", product]);
|
|
87
|
+
}
|
|
88
|
+
switch (options.package.requirement.kind) {
|
|
89
|
+
case "upToNextMajorVersion":
|
|
90
|
+
case "upToNextMinorVersion":
|
|
91
|
+
fields.push([
|
|
92
|
+
"requirement.minimumVersion",
|
|
93
|
+
options.package.requirement.minimumVersion,
|
|
94
|
+
]);
|
|
95
|
+
break;
|
|
96
|
+
case "exactVersion":
|
|
97
|
+
fields.push(["requirement.version", options.package.requirement.version]);
|
|
98
|
+
break;
|
|
99
|
+
case "branch":
|
|
100
|
+
fields.push(["requirement.branch", options.package.requirement.branch]);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
for (const [name, value] of fields) {
|
|
104
|
+
if (/['\\\n\r\t]/.test(value)) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`[smileid-spm] Refusing to inject Podfile block: '${name}' contains an unsafe character (got: ${JSON.stringify(value)}).`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function renderBlock(options: PodfileLinkOptions): string {
|
|
113
|
+
const beginMarker = `${BEGIN_PREFIX} ${options.marker} ===`;
|
|
114
|
+
const endMarker = `${END_PREFIX} ${options.marker} ===`;
|
|
115
|
+
const requirement = renderRequirement(options.package.requirement);
|
|
116
|
+
const productList = options.products.map((p) => `'${p}'`).join(", ");
|
|
117
|
+
|
|
118
|
+
return `${beginMarker}
|
|
119
|
+
# Wires ${options.package.url} into Pods.xcodeproj and links its
|
|
120
|
+
# products to the '${options.podTarget}' pod target so the Swift
|
|
121
|
+
# bridge code can \`import\` them. Idempotent across pod installs.
|
|
122
|
+
#
|
|
123
|
+
# UUIDs are minted via SecureRandom rather than \`pods_project.new\`
|
|
124
|
+
# because \`prepare_react_native_project!\` sets
|
|
125
|
+
# \`:deterministic_uuids => false\`. With that flag off, CocoaPods
|
|
126
|
+
# skips its predictabilize step and \`stabilize_target_uuids\` resets
|
|
127
|
+
# \`@generated_uuids\` to a tiny leftover pool — so any post_install
|
|
128
|
+
# call to \`pods_project.new\` restarts the sequential index near 0
|
|
129
|
+
# and re-mints UUIDs already in use. The collision then runs through
|
|
130
|
+
# \`add_referrer\`, which clobbers \`objects_by_uuid[uuid]\` and
|
|
131
|
+
# leaves the rootObject (\`46EB2E00000000\`) unreachable, crashing
|
|
132
|
+
# Xcode 26 with \`XCSwiftPackageProductDependency
|
|
133
|
+
# _setSavedArchiveVersion:\` unrecognized selector. Random 24-char
|
|
134
|
+
# hex IDs can't collide with the 14-char cocoapods scheme.
|
|
135
|
+
begin
|
|
136
|
+
pods_project = installer.pods_project
|
|
137
|
+
spm_url = '${options.package.url}'
|
|
138
|
+
spm_requirement = ${requirement}
|
|
139
|
+
product_names = [${productList}]
|
|
140
|
+
target_name = '${options.podTarget}'
|
|
141
|
+
|
|
142
|
+
smileid_spm_safe_uuid = lambda do |project|
|
|
143
|
+
loop do
|
|
144
|
+
candidate = SecureRandom.hex(12).upcase
|
|
145
|
+
return candidate unless project.objects_by_uuid.key?(candidate)
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
pkg = pods_project.root_object.package_references.find do |r|
|
|
150
|
+
r.respond_to?(:repositoryURL) && r.repositoryURL == spm_url
|
|
151
|
+
end
|
|
152
|
+
unless pkg
|
|
153
|
+
pkg_uuid = smileid_spm_safe_uuid.call(pods_project)
|
|
154
|
+
pkg = Xcodeproj::Project::Object::XCRemoteSwiftPackageReference.new(pods_project, pkg_uuid)
|
|
155
|
+
pkg.initialize_defaults
|
|
156
|
+
pkg.repositoryURL = spm_url
|
|
157
|
+
pkg.requirement = spm_requirement
|
|
158
|
+
pods_project.root_object.package_references << pkg
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
target = pods_project.targets.find { |t| t.name == target_name }
|
|
162
|
+
if target.nil?
|
|
163
|
+
Pod::UI.warn "[smileid-spm] Pod target #{target_name} not found; skipping SPM link."
|
|
164
|
+
else
|
|
165
|
+
product_names.each do |product_name|
|
|
166
|
+
already = target.package_product_dependencies.any? do |d|
|
|
167
|
+
d.package == pkg && d.product_name == product_name
|
|
168
|
+
end
|
|
169
|
+
next if already
|
|
170
|
+
|
|
171
|
+
dep_uuid = smileid_spm_safe_uuid.call(pods_project)
|
|
172
|
+
dep = Xcodeproj::Project::Object::XCSwiftPackageProductDependency.new(pods_project, dep_uuid)
|
|
173
|
+
dep.initialize_defaults
|
|
174
|
+
dep.package = pkg
|
|
175
|
+
dep.product_name = product_name
|
|
176
|
+
target.package_product_dependencies << dep
|
|
177
|
+
|
|
178
|
+
bf_uuid = smileid_spm_safe_uuid.call(pods_project)
|
|
179
|
+
bf = Xcodeproj::Project::Object::PBXBuildFile.new(pods_project, bf_uuid)
|
|
180
|
+
bf.initialize_defaults
|
|
181
|
+
bf.product_ref = dep
|
|
182
|
+
target.frameworks_build_phase.files << bf
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
pods_project.save
|
|
187
|
+
rescue => e
|
|
188
|
+
Pod::UI.warn "[smileid-spm] Failed to link SPM products for ${options.podTarget}: #{e.message}"
|
|
189
|
+
raise
|
|
190
|
+
end
|
|
191
|
+
${endMarker}`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function renderRequirement(req: SpmRequirement): string {
|
|
195
|
+
switch (req.kind) {
|
|
196
|
+
case "upToNextMajorVersion":
|
|
197
|
+
return `{ kind: 'upToNextMajorVersion', minimumVersion: '${req.minimumVersion}' }`;
|
|
198
|
+
case "upToNextMinorVersion":
|
|
199
|
+
return `{ kind: 'upToNextMinorVersion', minimumVersion: '${req.minimumVersion}' }`;
|
|
200
|
+
case "exactVersion":
|
|
201
|
+
return `{ kind: 'exactVersion', version: '${req.version}' }`;
|
|
202
|
+
case "branch":
|
|
203
|
+
return `{ kind: 'branch', branch: '${req.branch}' }`;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function escapeRegExp(s: string): string {
|
|
208
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
209
|
+
}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// Shared plumbing for wiring a remote Swift Package into both the
|
|
2
|
+
// consuming Expo app's Xcode project and the autogenerated CocoaPods
|
|
3
|
+
// project for a specific bridge pod target.
|
|
4
|
+
//
|
|
5
|
+
// Why this exists: `expo-modules-autolinking@55.0.x`'s
|
|
6
|
+
// `RawModuleConfigApple` schema does not surface a `dependencies`
|
|
7
|
+
// field, so listing SPM products in `expo-module.config.json` is a
|
|
8
|
+
// silent no-op. This module fills that gap.
|
|
9
|
+
|
|
10
|
+
import { XcodeProject } from "@expo/config-plugins";
|
|
11
|
+
|
|
12
|
+
export interface SpmPackage {
|
|
13
|
+
/** Remote git URL of the Swift Package, e.g. `https://github.com/smileidentity/ios-spm`. */
|
|
14
|
+
url: string;
|
|
15
|
+
/** Version requirement; mirrors Xcode's package resolution UI. */
|
|
16
|
+
requirement: SpmRequirement;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type SpmRequirement =
|
|
20
|
+
| { kind: "upToNextMajorVersion"; minimumVersion: string }
|
|
21
|
+
| { kind: "upToNextMinorVersion"; minimumVersion: string }
|
|
22
|
+
| { kind: "exactVersion"; version: string }
|
|
23
|
+
| { kind: "branch"; branch: string };
|
|
24
|
+
|
|
25
|
+
export interface SpmTargetLink {
|
|
26
|
+
/** Native target name in the project (app target or pod target). */
|
|
27
|
+
targetName: string;
|
|
28
|
+
/** SPM library product names to attach to the target. */
|
|
29
|
+
products: string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Adds (or reuses) a remote Swift Package reference on the given
|
|
34
|
+
* Xcode project and links the requested products to the target.
|
|
35
|
+
* Idempotent: existing package refs and product deps are reused so
|
|
36
|
+
* multiple plugins can compose without conflict.
|
|
37
|
+
*/
|
|
38
|
+
export function linkSpmPackage(
|
|
39
|
+
project: XcodeProject,
|
|
40
|
+
pkg: SpmPackage,
|
|
41
|
+
link: SpmTargetLink,
|
|
42
|
+
): void {
|
|
43
|
+
const pkgRef = upsertPackageReference(project, pkg);
|
|
44
|
+
const target = findNativeTarget(project, link.targetName);
|
|
45
|
+
if (!target) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`[smileid-spm] Native target '${link.targetName}' not found in Xcode project.`,
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
for (const product of link.products) {
|
|
51
|
+
upsertProductDependency(project, target.uuid, pkgRef, product);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Internals — pbxproj surgery. xcode.js doesn't expose SPM helpers,
|
|
56
|
+
// so we manipulate the underlying object graph directly.
|
|
57
|
+
|
|
58
|
+
interface PackageRef {
|
|
59
|
+
uuid: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
interface NativeTarget {
|
|
63
|
+
uuid: string;
|
|
64
|
+
obj: PbxNativeTarget;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface PbxNativeTarget {
|
|
68
|
+
isa: "PBXNativeTarget";
|
|
69
|
+
name: string;
|
|
70
|
+
packageProductDependencies?: Array<{ value: string; comment?: string }>;
|
|
71
|
+
buildPhases: Array<{ value: string; comment?: string }>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface PbxProject {
|
|
75
|
+
isa: "PBXProject";
|
|
76
|
+
packageReferences?: Array<{ value: string; comment?: string }>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function objects(project: XcodeProject): Record<string, unknown> {
|
|
80
|
+
const hash = (
|
|
81
|
+
project as unknown as {
|
|
82
|
+
hash: { project: { objects: Record<string, unknown> } };
|
|
83
|
+
}
|
|
84
|
+
).hash.project.objects;
|
|
85
|
+
return hash;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function section<T>(project: XcodeProject, isa: string): Record<string, T> {
|
|
89
|
+
const objs = objects(project);
|
|
90
|
+
if (!objs[isa]) {
|
|
91
|
+
objs[isa] = {};
|
|
92
|
+
}
|
|
93
|
+
return objs[isa] as Record<string, T>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function generateUuid(project: XcodeProject): string {
|
|
97
|
+
return (project as unknown as { generateUuid: () => string }).generateUuid();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function upsertPackageReference(
|
|
101
|
+
project: XcodeProject,
|
|
102
|
+
pkg: SpmPackage,
|
|
103
|
+
): PackageRef {
|
|
104
|
+
const refs = section<{
|
|
105
|
+
isa: string;
|
|
106
|
+
repositoryURL?: string;
|
|
107
|
+
requirement?: object;
|
|
108
|
+
}>(project, "XCRemoteSwiftPackageReference");
|
|
109
|
+
|
|
110
|
+
for (const [uuid, ref] of Object.entries(refs)) {
|
|
111
|
+
if (uuid.endsWith("_comment")) continue;
|
|
112
|
+
if (typeof ref !== "object" || ref === null) continue;
|
|
113
|
+
if (ref.repositoryURL?.replace(/^"|"$/g, "") === pkg.url) {
|
|
114
|
+
return { uuid };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const uuid = generateUuid(project);
|
|
119
|
+
refs[uuid] = {
|
|
120
|
+
isa: "XCRemoteSwiftPackageReference",
|
|
121
|
+
repositoryURL: `"${pkg.url}"`,
|
|
122
|
+
requirement: serializeRequirement(pkg.requirement),
|
|
123
|
+
};
|
|
124
|
+
refs[`${uuid}_comment`] =
|
|
125
|
+
`XCRemoteSwiftPackageReference "${repoName(pkg.url)}"` as never;
|
|
126
|
+
|
|
127
|
+
// Attach to the PBXProject's packageReferences list.
|
|
128
|
+
const projectSection = section<PbxProject>(project, "PBXProject");
|
|
129
|
+
for (const [projUuid, proj] of Object.entries(projectSection)) {
|
|
130
|
+
if (projUuid.endsWith("_comment")) continue;
|
|
131
|
+
if (typeof proj !== "object" || proj === null) continue;
|
|
132
|
+
if (proj.isa !== "PBXProject") continue;
|
|
133
|
+
proj.packageReferences ??= [];
|
|
134
|
+
if (!proj.packageReferences.some((r) => r.value === uuid)) {
|
|
135
|
+
proj.packageReferences.push({
|
|
136
|
+
value: uuid,
|
|
137
|
+
comment: `XCRemoteSwiftPackageReference "${repoName(pkg.url)}"`,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return { uuid };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function upsertProductDependency(
|
|
146
|
+
project: XcodeProject,
|
|
147
|
+
targetUuid: string,
|
|
148
|
+
pkgRef: PackageRef,
|
|
149
|
+
productName: string,
|
|
150
|
+
): void {
|
|
151
|
+
const targetSection = section<PbxNativeTarget>(project, "PBXNativeTarget");
|
|
152
|
+
const target = targetSection[targetUuid];
|
|
153
|
+
if (!target || typeof target !== "object") {
|
|
154
|
+
throw new Error(
|
|
155
|
+
`[smileid-spm] Target ${targetUuid} disappeared between lookups.`,
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const productDeps = section<{
|
|
160
|
+
isa: string;
|
|
161
|
+
package?: string;
|
|
162
|
+
productName?: string;
|
|
163
|
+
}>(project, "XCSwiftPackageProductDependency");
|
|
164
|
+
|
|
165
|
+
// Each target owns its own XCSwiftPackageProductDependency entry —
|
|
166
|
+
// sharing one across targets is not how Xcode writes pbxproj and
|
|
167
|
+
// would cause downstream tools (and re-runs of this plugin) to
|
|
168
|
+
// silently drop the second target's binding. Look up the dep
|
|
169
|
+
// *within this target's* packageProductDependencies, never globally.
|
|
170
|
+
target.packageProductDependencies ??= [];
|
|
171
|
+
let depUuid = target.packageProductDependencies.find((d) => {
|
|
172
|
+
const entry = productDeps[d.value];
|
|
173
|
+
return (
|
|
174
|
+
entry !== undefined &&
|
|
175
|
+
typeof entry === "object" &&
|
|
176
|
+
entry !== null &&
|
|
177
|
+
entry.package === pkgRef.uuid &&
|
|
178
|
+
entry.productName === productName
|
|
179
|
+
);
|
|
180
|
+
})?.value;
|
|
181
|
+
|
|
182
|
+
if (!depUuid) {
|
|
183
|
+
depUuid = generateUuid(project);
|
|
184
|
+
productDeps[depUuid] = {
|
|
185
|
+
isa: "XCSwiftPackageProductDependency",
|
|
186
|
+
package: pkgRef.uuid,
|
|
187
|
+
productName,
|
|
188
|
+
};
|
|
189
|
+
productDeps[`${depUuid}_comment`] = productName as never;
|
|
190
|
+
target.packageProductDependencies.push({
|
|
191
|
+
value: depUuid,
|
|
192
|
+
comment: productName,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
ensureFrameworkLink(project, target, depUuid, productName);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function ensureFrameworkLink(
|
|
200
|
+
project: XcodeProject,
|
|
201
|
+
target: PbxNativeTarget,
|
|
202
|
+
productDepUuid: string,
|
|
203
|
+
productName: string,
|
|
204
|
+
): void {
|
|
205
|
+
const frameworksPhase = findFrameworksBuildPhase(project, target);
|
|
206
|
+
if (!frameworksPhase) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`[smileid-spm] Target '${target.name}' has no PBXFrameworksBuildPhase; cannot link ${productName}.`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const buildFiles = section<{ isa: string; productRef?: string }>(
|
|
213
|
+
project,
|
|
214
|
+
"PBXBuildFile",
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// Scope the existence check to *this target's* frameworks phase.
|
|
218
|
+
// A globally-scoped check would early-return when a sibling target
|
|
219
|
+
// already linked the same product, leaving this target unlinked.
|
|
220
|
+
frameworksPhase.obj.files ??= [];
|
|
221
|
+
for (const fileRef of frameworksPhase.obj.files) {
|
|
222
|
+
const bf = buildFiles[fileRef.value];
|
|
223
|
+
if (
|
|
224
|
+
bf !== undefined &&
|
|
225
|
+
typeof bf === "object" &&
|
|
226
|
+
bf !== null &&
|
|
227
|
+
bf.productRef === productDepUuid
|
|
228
|
+
) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const buildFileUuid = generateUuid(project);
|
|
234
|
+
buildFiles[buildFileUuid] = {
|
|
235
|
+
isa: "PBXBuildFile",
|
|
236
|
+
productRef: productDepUuid,
|
|
237
|
+
};
|
|
238
|
+
buildFiles[`${buildFileUuid}_comment`] =
|
|
239
|
+
`${productName} in Frameworks` as never;
|
|
240
|
+
|
|
241
|
+
frameworksPhase.obj.files.push({
|
|
242
|
+
value: buildFileUuid,
|
|
243
|
+
comment: `${productName} in Frameworks`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface FrameworksPhase {
|
|
248
|
+
uuid: string;
|
|
249
|
+
obj: {
|
|
250
|
+
isa: "PBXFrameworksBuildPhase";
|
|
251
|
+
files?: Array<{ value: string; comment?: string }>;
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function findFrameworksBuildPhase(
|
|
256
|
+
project: XcodeProject,
|
|
257
|
+
target: PbxNativeTarget,
|
|
258
|
+
): FrameworksPhase | undefined {
|
|
259
|
+
const phaseSection = section<{
|
|
260
|
+
isa: string;
|
|
261
|
+
files?: Array<{ value: string; comment?: string }>;
|
|
262
|
+
}>(project, "PBXFrameworksBuildPhase");
|
|
263
|
+
for (const phaseRef of target.buildPhases) {
|
|
264
|
+
const phase = phaseSection[phaseRef.value];
|
|
265
|
+
if (
|
|
266
|
+
phase &&
|
|
267
|
+
typeof phase === "object" &&
|
|
268
|
+
phase.isa === "PBXFrameworksBuildPhase"
|
|
269
|
+
) {
|
|
270
|
+
return { uuid: phaseRef.value, obj: phase as FrameworksPhase["obj"] };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function findNativeTarget(
|
|
277
|
+
project: XcodeProject,
|
|
278
|
+
name: string,
|
|
279
|
+
): NativeTarget | undefined {
|
|
280
|
+
const targets = section<PbxNativeTarget>(project, "PBXNativeTarget");
|
|
281
|
+
for (const [uuid, t] of Object.entries(targets)) {
|
|
282
|
+
if (uuid.endsWith("_comment")) continue;
|
|
283
|
+
if (typeof t !== "object" || t === null) continue;
|
|
284
|
+
if (t.isa !== "PBXNativeTarget") continue;
|
|
285
|
+
if (t.name === name || t.name === `"${name}"`) {
|
|
286
|
+
return { uuid, obj: t };
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function serializeRequirement(req: SpmRequirement): object {
|
|
293
|
+
switch (req.kind) {
|
|
294
|
+
case "upToNextMajorVersion":
|
|
295
|
+
return {
|
|
296
|
+
kind: "upToNextMajorVersion",
|
|
297
|
+
minimumVersion: req.minimumVersion,
|
|
298
|
+
};
|
|
299
|
+
case "upToNextMinorVersion":
|
|
300
|
+
return {
|
|
301
|
+
kind: "upToNextMinorVersion",
|
|
302
|
+
minimumVersion: req.minimumVersion,
|
|
303
|
+
};
|
|
304
|
+
case "exactVersion":
|
|
305
|
+
return { kind: "exactVersion", version: req.version };
|
|
306
|
+
case "branch":
|
|
307
|
+
return { kind: "branch", branch: req.branch };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function repoName(url: string): string {
|
|
312
|
+
const match = url.replace(/\.git$/, "").match(/\/([^/]+)$/);
|
|
313
|
+
return match?.[1] ?? url;
|
|
314
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./build",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"ignoreDeprecations": "6.0",
|
|
9
|
+
"target": "ES2021",
|
|
10
|
+
"lib": ["ES2022"],
|
|
11
|
+
"types": ["node"],
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationMap": false,
|
|
14
|
+
"sourceMap": true,
|
|
15
|
+
"composite": false
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*"],
|
|
18
|
+
"exclude": ["build", "node_modules"]
|
|
19
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach, type Mock } from "vitest";
|
|
2
|
+
|
|
3
|
+
const native = vi.hoisted(() => ({
|
|
4
|
+
configure: vi.fn(),
|
|
5
|
+
reset: vi.fn(),
|
|
6
|
+
close: vi.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
vi.mock("expo-modules-core", () => ({
|
|
10
|
+
requireNativeModule: vi.fn(() => native),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
import { requireNativeModule } from "expo-modules-core";
|
|
14
|
+
import {
|
|
15
|
+
useSmileIDVisionFace,
|
|
16
|
+
UseSmileIDVisionFaceIdentifiers,
|
|
17
|
+
} from "../index";
|
|
18
|
+
|
|
19
|
+
describe("useSmileIDVisionFace — TS wrapper", () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
Object.values(native).forEach((m) => (m as Mock).mockReset());
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("looks up the native module under the contract-stable name", () => {
|
|
25
|
+
expect(requireNativeModule).toHaveBeenCalledWith("UseSmileIDVisionFace");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("exposes the lifecycle surface — no per-frame analyze method", () => {
|
|
29
|
+
expect(typeof useSmileIDVisionFace.configure).toBe("function");
|
|
30
|
+
expect(typeof useSmileIDVisionFace.reset).toBe("function");
|
|
31
|
+
expect(typeof useSmileIDVisionFace.close).toBe("function");
|
|
32
|
+
// Per-frame analysis lives in the native VisionCamera frame
|
|
33
|
+
// processor plugin — raw pixels never cross the JS bridge.
|
|
34
|
+
expect("analyze" in useSmileIDVisionFace).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("exposes the kind discriminator and frame processor plugin name", () => {
|
|
38
|
+
expect(useSmileIDVisionFace.kind).toBe("face");
|
|
39
|
+
expect(useSmileIDVisionFace.frameProcessorPluginName).toBe(
|
|
40
|
+
UseSmileIDVisionFaceIdentifiers.frameProcessorPluginName,
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe("configure", () => {
|
|
45
|
+
it("passes the validated config through to native", async () => {
|
|
46
|
+
native.configure.mockResolvedValueOnce(undefined);
|
|
47
|
+
await useSmileIDVisionFace.configure({ selfieCaptureTimeout: 60_000 });
|
|
48
|
+
expect(native.configure).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(native.configure).toHaveBeenCalledWith({
|
|
50
|
+
selfieCaptureTimeout: 60_000,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("rejects malformed config at the JS boundary", async () => {
|
|
55
|
+
await expect(
|
|
56
|
+
useSmileIDVisionFace.configure({
|
|
57
|
+
// @ts-expect-error — int field with float value
|
|
58
|
+
selfieCaptureTimeout: 60_000.5,
|
|
59
|
+
}),
|
|
60
|
+
).rejects.toThrow();
|
|
61
|
+
expect(native.configure).not.toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("reset / close", () => {
|
|
66
|
+
it("routes reset through to native", async () => {
|
|
67
|
+
native.reset.mockResolvedValueOnce(undefined);
|
|
68
|
+
await useSmileIDVisionFace.reset();
|
|
69
|
+
expect(native.reset).toHaveBeenCalledTimes(1);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("routes close through to native and is idempotent", async () => {
|
|
73
|
+
native.close.mockResolvedValue(undefined);
|
|
74
|
+
await useSmileIDVisionFace.close();
|
|
75
|
+
await useSmileIDVisionFace.close();
|
|
76
|
+
expect(native.close).toHaveBeenCalledTimes(2);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { AnalyzerFactoryKey } from "@smileid/usesmileid_bridge";
|
|
2
|
+
import type { FaceConfig, FaceScanResult } from "@smileid/usesmileid_bridge";
|
|
3
|
+
import { useSmileIDAnalyzerExecutor } from "@smileid/usesmileid_platform_interface";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Apple Vision face analyzer (iOS-only).
|
|
7
|
+
*
|
|
8
|
+
* Thin shim around the existing native session
|
|
9
|
+
* `UseSmileID.UseSmileIDFaceSession(FaceDetectorAnalyzer())` shipped in
|
|
10
|
+
* the `UseSmileIDVisionFace` Swift Package. The native side runs the
|
|
11
|
+
* entire pipeline (analyzer + validator + transitioner + state
|
|
12
|
+
* machine); this TS layer routes calls and validates wire payloads at
|
|
13
|
+
* the channel boundary.
|
|
14
|
+
*
|
|
15
|
+
* The canonical wiring lives in [useSmileIDAnalyzerExecutor] in
|
|
16
|
+
* `usesmileid_platform_interface`.
|
|
17
|
+
*
|
|
18
|
+
* Lifecycle: `configure()` → per-frame analysis via the native frame
|
|
19
|
+
* processor plugin → `reset()`? → `close()`. See
|
|
20
|
+
* `usesmileid_platform_interface` `FaceAnalyzer` for the canonical
|
|
21
|
+
* contract.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* Must match the Swift Expo Module's `Name("UseSmileIDVisionFace")` and its
|
|
25
|
+
* VisionCamera frame-processor-plugin registration — drift is a runtime
|
|
26
|
+
* "module/plugin not found" error, not a compile error.
|
|
27
|
+
*/
|
|
28
|
+
export const UseSmileIDVisionFaceIdentifiers = {
|
|
29
|
+
nativeModuleName: "UseSmileIDVisionFace",
|
|
30
|
+
frameProcessorPluginName: "UseSmileIDVisionFaceFrameProcessor",
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
33
|
+
export const useSmileIDVisionFace = useSmileIDAnalyzerExecutor({
|
|
34
|
+
nativeModuleName: UseSmileIDVisionFaceIdentifiers.nativeModuleName,
|
|
35
|
+
frameProcessorPluginName:
|
|
36
|
+
UseSmileIDVisionFaceIdentifiers.frameProcessorPluginName,
|
|
37
|
+
kind: "face",
|
|
38
|
+
key: AnalyzerFactoryKey.VisionFace,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export type { FaceConfig, FaceScanResult };
|