-
Notifications
You must be signed in to change notification settings - Fork 180
create nice structure for the mobile sdk #1177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c8cb592
e5e800a
9ea40cf
e4e564e
94d0d77
f75eb88
be673a0
aee77b4
abcfcc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Read This | ||
|
|
||
| This folder contains folders for flows ie steps to complete a task like onboarding aka document registration or disclosing. In each folder each file represents roughly 1 step. Usually this means 1 screen but can be multiple depending on how error and bad states are represented in the UI. This helps with implementation as consumers of the api when building out their screens will more easily know which functions, hooks, Components, and constants to use together. | ||
|
|
||
| The files here and their structure are part of the external mobile sdk API. | ||
|
|
||
| convention is for folder for each flow to end in --ing and for file names to be verb-noun.ts | ||
aaronmgdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| read-mrz | ||
| scan-nfc | ||
| import-aadhaar | ||
| confirm-ownership | ||
| generate-proof | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||||||||||||||||
| // SPDX-License-Identifier: BUSL-1.1 | ||||||||||||||||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||||||||||||||||
|
|
||||||||||||||||
| import { useEffect } from 'react'; | ||||||||||||||||
|
|
||||||||||||||||
| import { useSelfClient } from '../../context'; | ||||||||||||||||
| import { loadSelectedDocument } from '../../documents/utils'; | ||||||||||||||||
|
|
||||||||||||||||
| /*Add a comment on lines R7 to R9Add diff commentMarkdown input: edit mode selected.WritePreviewAdd a suggestionHeadingBoldItalicQuoteCodeLinkUnordered listNumbered listTask listMentionReferenceSaved repliesAdd FilesPaste, drop, or click to add filesCancelCommentStart a reviewReturn to code | ||||||||||||||||
| Display this to users before they confirm ownership of a document | ||||||||||||||||
| */ | ||||||||||||||||
| export function getPreRegistrationDescription() { | ||||||||||||||||
| return "By continuing, you certify that this passport, biometric ID or Aadhaar card belongs to you and is not stolen or forged. Once registered with Self, this document will be permanently linked to your identity and can't be linked to another one."; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /* | ||||||||||||||||
| Hook to prepare for proving a document by initializing the proving state machine. | ||||||||||||||||
| It loads the selected document and initializes the proving process based on the document type. | ||||||||||||||||
| returns functions to set FCM token and mark user confirmation, along with a boolean indicating readiness to prove. | ||||||||||||||||
| Usage: | ||||||||||||||||
| use `isReadyToProve` to enable/disable the confirmation button. | ||||||||||||||||
| call `setUserConfirmed` when the user presses your confirm button. | ||||||||||||||||
| after calling `setUserConfirmed`, the proving process will start. You MUST Navigate to wait-generation screen. | ||||||||||||||||
| */ | ||||||||||||||||
| export function usePrepareDocumentProof() { | ||||||||||||||||
| const selfClient = useSelfClient(); | ||||||||||||||||
| const { useProvingStore } = selfClient; | ||||||||||||||||
| const currentState = useProvingStore(state => state.currentState); | ||||||||||||||||
| const init = useProvingStore(state => state.init); | ||||||||||||||||
| const setUserConfirmed = useProvingStore(state => state.setUserConfirmed); | ||||||||||||||||
| const isReadyToProve = currentState === 'ready_to_prove'; | ||||||||||||||||
|
|
||||||||||||||||
| useEffect(() => { | ||||||||||||||||
| const initializeProving = async () => { | ||||||||||||||||
| try { | ||||||||||||||||
| const selectedDocument = await loadSelectedDocument(selfClient); | ||||||||||||||||
| if (selectedDocument?.data?.documentCategory === 'aadhaar') { | ||||||||||||||||
| init(selfClient, 'register'); | ||||||||||||||||
| } else { | ||||||||||||||||
| init(selfClient, 'dsc'); | ||||||||||||||||
| } | ||||||||||||||||
| } catch (error) { | ||||||||||||||||
| console.error('Error loading selected document:', error); | ||||||||||||||||
aaronmgdr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| init(selfClient, 'dsc'); | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+45
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redact error logging to avoid potential PII exposure. The error may contain document details (PII). Log a generic message only. Apply this diff: - } catch (error) {
- console.error('Error loading selected document:', error);
- init(selfClient, 'dsc');
+ } catch (_error) {
+ console.error('Error loading selected document: [redacted]');
+ init(selfClient, 'dsc');
}As per coding guidelines. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| initializeProving(); | ||||||||||||||||
| }, [init, selfClient]); | ||||||||||||||||
|
|
||||||||||||||||
| return { setUserConfirmed, isReadyToProve }; | ||||||||||||||||
| } | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||
|
|
||
| export { MRZScannerView, MRZScannerViewProps } from '../../components/MRZScannerView'; | ||
| export function mrzReadInstructions() { | ||
| return 'Lay your document flat and position the machine readable text in the viewfinder'; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,15 +2,44 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: BUSL-1.1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as fs from 'node:fs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import * as path from 'node:path'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { defineConfig } from 'tsup'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const banner = `// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Dynamically find all flow files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function findFlowFiles(dir: string, basePath = ''): Record<string, string> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const entries: Record<string, string> = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!fs.existsSync(dir)) return entries; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const items = fs.readdirSync(dir, { withFileTypes: true }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const item of items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const itemPath = path.join(dir, item.name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const relativePath = basePath ? path.join(basePath, item.name) : item.name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (item.isDirectory()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.assign(entries, findFlowFiles(itemPath, relativePath)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else if (item.isFile() && item.name.endsWith('.ts')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const key = path.join('flows', relativePath).replace(/\.ts$/, ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| entries[key] = path.join('src', 'flows', relativePath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return entries; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Make flow discovery OS-agnostic, support .tsx and index files, and exclude tests. Current logic risks:
Refactor finder accordingly. Apply this diff: -// Dynamically find all flow files
-function findFlowFiles(dir: string, basePath = ''): Record<string, string> {
- const entries: Record<string, string> = {};
-
- if (!fs.existsSync(dir)) return entries;
-
- const items = fs.readdirSync(dir, { withFileTypes: true });
-
- for (const item of items) {
- const itemPath = path.join(dir, item.name);
- const relativePath = basePath ? path.join(basePath, item.name) : item.name;
-
- if (item.isDirectory()) {
- Object.assign(entries, findFlowFiles(itemPath, relativePath));
- } else if (item.isFile() && item.name.endsWith('.ts')) {
- const key = path.join('flows', relativePath).replace(/\.ts$/, '');
- entries[key] = path.join('src', 'flows', relativePath);
- }
- }
-
- return entries;
-}
+// Dynamically find all flow files
+function findFlowFiles(dir: string, basePath = ''): Record<string, string> {
+ const entries: Record<string, string> = {};
+ if (!fs.existsSync(dir)) return entries;
+
+ const items = fs.readdirSync(dir, { withFileTypes: true });
+
+ for (const item of items) {
+ const itemPath = path.join(dir, item.name);
+ const nextBasePosix = basePath
+ ? path.posix.join(basePath, item.name)
+ : item.name;
+
+ if (item.isDirectory()) {
+ Object.assign(entries, findFlowFiles(itemPath, nextBasePosix));
+ continue;
+ }
+
+ if (!item.isFile()) continue;
+ // include .ts/.tsx, exclude .d.ts and tests
+ if (!/\.(ts|tsx)$/.test(item.name)) continue;
+ if (/\.d\.ts$/.test(item.name)) continue;
+ if (/\.(test|spec)\.(ts|tsx)$/.test(item.name)) continue;
+
+ const relPosix = nextBasePosix;
+ const withoutExt = relPosix.replace(/\.(ts|tsx)$/, '');
+ const keyPath = withoutExt.endsWith('/index')
+ ? withoutExt.slice(0, -('/index'.length))
+ : withoutExt;
+ const key = path.posix.join('flows', keyPath);
+
+ entries[key] = path.join('src', 'flows', relPosix);
+ }
+
+ return entries;
+}This ensures stable subpath outputs, covers component files, and avoids bundling tests. As per coding guidelines. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is for converting ts/x files into cjs and mjs files and d,ts files so i dont see why we need to worry about ignoring. d.ts files here
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aaronmgdr, you're right—since this is discovering source files in The more important improvements in my suggestion are:
If you're confident your flows will only be |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const flowEntries = findFlowFiles('src/flows'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const entry = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| index: 'src/index.ts', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| browser: 'src/browser.ts', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'constants/analytics': 'src/constants/analytics.ts', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| stores: 'src/stores/index.ts', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...flowEntries, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default defineConfig([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Harden flow resolution: add try/catch and index.js fallback; always delegate on miss.
Prevent resolver breakage and support folder indexes.
Apply this diff:
if (moduleName.startsWith('@selfxyz/mobile-sdk-alpha/')) { const subPath = moduleName.replace('@selfxyz/mobile-sdk-alpha/', ''); // Check if it's a flow import (onboarding/* or disclosing/*) if ( subPath.startsWith('onboarding/') || subPath.startsWith('disclosing/') ) { - const flowPath = path.resolve( - sdkAlphaPath, - 'dist/esm/flows', - `${subPath}.js`, - ); - - // Check if the file exists - if (fs.existsSync(flowPath)) { - return { - type: 'sourceFile', - filePath: flowPath, - }; - } + try { + const flowPath = path.resolve( + sdkAlphaPath, + 'dist/esm/flows', + `${subPath}.js`, + ); + const flowIndexPath = path.resolve( + sdkAlphaPath, + 'dist/esm/flows', + subPath, + 'index.js', + ); + if (fs.existsSync(flowPath)) { + return { type: 'sourceFile', filePath: flowPath }; + } + if (fs.existsSync(flowIndexPath)) { + return { type: 'sourceFile', filePath: flowIndexPath }; + } + } catch (e) { + console.warn(`Flow resolve error for ${moduleName}:`, e?.message ?? e); + } + // Delegate to default resolution on miss + return context.resolveRequest(context, moduleName, platform); } }This avoids hard failures and supports directory-based flows (…/foo/index.js).
📝 Committable suggestion
🤖 Prompt for AI Agents