|
| 1 | +## Immutable Checkout SDK Example App Generator - Part 1: Create the App |
| 2 | + |
| 3 | +Make sure to always write tests first. You must do Test Driven Development. |
| 4 | +# Overview |
| 5 | +This prompt helps you create a new React example app that demonstrates the {feature name} feature of the Immutable Checkout SDK. The output will be a fully functional, self-contained example with proper documentation and adherence to best practices. |
| 6 | + |
| 7 | +# App Information |
| 8 | +- Feature name: {feature name} |
| 9 | +- Framework: nextjs |
| 10 | + |
| 11 | +## UI Best Practices |
| 12 | +- Always ensure that you ONLY use available Biom3 Components without assuming they exist. (Text and Spinner DOES NOT exist in the Biom3 UI Library) |
| 13 | +- Use standard HTML elements (h1, h2, h3, p) for text content. |
| 14 | +- Use Biom3 Button and other UI components as documented |
| 15 | +- Show clear loading/error states |
| 16 | +- Keep UI simple and focused on demonstrating the {feature name} |
| 17 | + |
| 18 | +## Critical Error Prevention |
| 19 | +- Always check if objects exist before accessing their properties or methods |
| 20 | +- Use optional chaining when accessing potentially undefined properties: obj?.prop?.method?.() |
| 21 | +- Wrap all {feature name} setup and teardown in try/catch blocks |
| 22 | +- Test component mounting/unmounting thoroughly to catch cleanup issues |
| 23 | + |
| 24 | +## ALWAYS READ THIS BEFORE YOU DO ANYTHING |
| 25 | +- DO NOT call methods that don't exist on the SDK instances |
| 26 | +- DO NOT try to import types that aren't explicitly exported |
| 27 | +- DO NOT forget to clean up {feature name} setup and teardown |
| 28 | +- DO NOT use custom components or providers unless necessary |
| 29 | +- DO NOT modify dependency versions in package.json |
| 30 | +- DO NOT use inconsistent import methods (mixing default and named imports) |
| 31 | +- DO NOT forget to include 'use client' directive in client components |
| 32 | +- DO NOT assume any property or method exists without checking first |
| 33 | +- DO NOT MAKE ANY TUTORIAL/METADATA FILE FOR THE {feature name} EXAMPLE APP |
| 34 | +- NEVER ADD `"ignoreDuringBuilds": true` TO .eslintrc.json |
| 35 | +- ALways do lint checks and never turn it off when building. |
| 36 | +- NEVER FORGET TO RUN BUILD ONCE YOU'RE DONE WITH EVERYTHING ELSE. THIS IS VERY VERY VERY IMPORTANT TO ENSURE THAT EVERYTHING WORKS. |
| 37 | + |
| 38 | + |
| 39 | +# Step 1: Core Setup |
| 40 | +Create a new example app named {feature name}-with-nextjs in /examples/checkout/ with this structure: |
| 41 | + |
| 42 | +``` |
| 43 | +/examples/checkout/{feature name}-with-nextjs/ |
| 44 | +├── src/app/ |
| 45 | +│ ├── page.tsx # Main landing page with feature links |
| 46 | +│ ├── {feature name}/page.tsx # Primary feature implementation |
| 47 | +│ ├── redirect/page.tsx # Auth redirect handler |
| 48 | +│ ├── logout/page.tsx # Logout functionality |
| 49 | +│ ├── utils/ # Shared utilities |
| 50 | +│ │ ├── setupDefault.ts # SDK initialization |
| 51 | +│ │ └── wrapper.tsx # App context wrapper |
| 52 | +│ ├── layout.tsx # App layout with wrapper |
| 53 | +│ └── globals.css # Basic styles |
| 54 | +├── tests # Test directory |
| 55 | +│ └── base.spec.ts # E2E Test file |
| 56 | +├── README.md # Documentation |
| 57 | +├── package.json # Dependencies |
| 58 | +├── next.config.mjs # Next.js config |
| 59 | +├── tsconfig.json # TypeScript config |
| 60 | +├── .env.example # Environment variables |
| 61 | +├── .gitignore # Git ignore file |
| 62 | +├── playwright.config.ts # Playwright configuration |
| 63 | +|── eslintrc.json # ESLint configuration |
| 64 | +|── babel.config.jest.js # Babel config for tests |
| 65 | +└── features.json # JSON file showcasing the feature present in the {feature name} app |
| 66 | +``` |
| 67 | +Copy these essential files from an existing example (e.g., login-with-nextjs): |
| 68 | +- package.json (update the name to "{feature name}-with-nextjs", but keep ALL dependency versions the same) |
| 69 | +- next.config.mjs |
| 70 | +- tsconfig.json |
| 71 | +- .env.example |
| 72 | +- .gitignore |
| 73 | +- src/app/utils/setupDefault.ts |
| 74 | +- src/app/utils/wrapper.tsx |
| 75 | +- src/app/layout.tsx (modify to use AppWrapper) |
| 76 | +- src/app/globals.css |
| 77 | +- playwright.config.ts |
| 78 | +- .eslintrc.json |
| 79 | + |
| 80 | +IMPORTANT: Ensure that you've gone through the Checkout SDK Documentation and have a very deep understanding of the SDK before you start. |
| 81 | +IMPORTANT: We have an internal UI Library called Biom3. Make sure that you thoroughly understand all of the components. DON'T ASSUME that a component exists. ALWAYS DOUBLE CHECK BEFORE YOU IMPORT OR USE ANYTHING |
| 82 | +IF THE COMPONENT THAT YOU WANT DOESN'T EXIST IN BIOM3, ALWAYS USE NORMAL CSS/HTML AND NEVER ASSUME. (https://github.com/immutable/biom3 | https://immutable.atlassian.net/wiki/spaces/DS/pages/2335965298/BIOME+Docs) |
| 83 | + |
| 84 | +# Step 2: Features.json creation (IMPORTANT: This must be done before you make components, etc. Without this file, you're not allowed to make components/pages.) |
| 85 | +Take a look at another example apps' (such as login-with-nextjs) features.json file and understand the structure. |
| 86 | +Once that's done, create the features.json file in the {feature name} example app root directory |
| 87 | +Make sure that IF {feature name} is to showcase login functionality, set silent-login/silent-logout to false. Otherwise, set it to true. |
| 88 | +The feature name in the features.json file will always be {feature name} |
| 89 | +The manually-edited field will always be false if you're the one who's generating the feature. |
| 90 | +Set the order field to be {total number of apps under product (e.g. Checkout, checkout, etc)} + 1 |
| 91 | + |
| 92 | +# Step 3: Testing Files |
| 93 | +COPY OVER THE RELEVANT E2E TEST FILES (INCLUDING SETUP, ETC) FROM OTHER EXAMPLE APPS SUCH AS LOGIN-WITH-NEXTJS |
| 94 | + |
| 95 | +- Add the following dependencies to package.json: |
| 96 | + - @playwright/test |
| 97 | + |
| 98 | +- Test all pages renders perfectly |
| 99 | +- Test {feature name} functionality thoroughly with all possible scenarios. (If it's Checkout specific, this is not required) |
| 100 | +- Test all {feature name} handling and cleanup |
| 101 | +- Explicitly validate that components render without errors |
| 102 | +- Use act() for all asynchronous operations |
| 103 | + |
| 104 | +# Step 4: Component Implementation |
| 105 | + |
| 106 | +## Critical Import/Export Requirements |
| 107 | +For ALL component files: |
| 108 | +- ALWAYS use default exports for page components (export default function ComponentName) |
| 109 | +- ALWAYS import React explicitly if using JSX fragments (<>...</>): import React from 'react' |
| 110 | +- Verify all imports are correctly spelled and point to existing files |
| 111 | +- When importing from libraries, verify the component exists in that library |
| 112 | +- For Next.js client components, always include 'use client' at the top of the file |
| 113 | + |
| 114 | +IMPORTANT: MAKE SURE THAT THE Checkout SDK IS INITIALIZED CORRECTLY IN THE SETUPDEFAULT.TS FILE. REFER TO OTHER EXAMPLE APPS LIKE LOGIN-WITH-NEXTJS FOR THE CORRECT SETUP. |
| 115 | +IMPORTANT: DON'T IMPLEMENT THE {feature name} AT ALL. JUST SETUP THE PROJECT STRUCTURE AND DOCUMENTATION. |
| 116 | + |
| 117 | +## Main Landing Page (src/app/page.tsx) |
| 118 | +Create a simple landing page with: |
| 119 | +- Brief description of the Checkout {feature name} features |
| 120 | +- Link to the {feature name} implementation page |
| 121 | +- Clear, concise UI using standard HTML (h1, h2, p) and Biom3 Button components |
| 122 | + |
| 123 | +## Redirect and Logout Pages |
| 124 | +Create minimal, functional redirect and logout pages: |
| 125 | +- Ensure the redirect page properly handles the authentication callback |
| 126 | +- Implement robust error handling for failed auth callbacks |
| 127 | +- For the logout page, implement proper token cleanup |
| 128 | +- VERIFY that all components used in these pages are properly imported |
| 129 | + |
| 130 | +## Feature Implementation (src/app/{feature name}/page.tsx) |
| 131 | +- THIS PAGE SHOULD JUST BE A PLACEHOLDER FOR NOW. IT SHOULD NOT IMPLEMENT ANY FUNCTIONALITY. |
| 132 | + |
| 133 | +## setupDefault modification (If Applicable) |
| 134 | +- Go to the features.json file and check for the silent logout field. |
| 135 | +- If {feature name} has the silent logout field as true, ensure that the 'logoutMode' field in the setupDefault file is set to 'silent' |
| 136 | + |
| 137 | +## Silent Login mode (If Applicable) |
| 138 | +- Go to the features.json file and check for the silent login field. |
| 139 | +- If {feature name} has the silent login field as true, go through all of the pages in the app and change all login modes to silent login. |
| 140 | + |
| 141 | +# Step 5: Documentation |
| 142 | +IMPORTANT: Ensure that the command for installation, etc uses pnpm not npm. |
| 143 | +Create a comprehensive README.md including: |
| 144 | +- {feature name} feature description and purpose |
| 145 | +- Setup instructions including environment variables |
| 146 | +- Usage instructions with code examples for all {feature name} types |
| 147 | +- Common issues and troubleshooting |
| 148 | +- References to official documentation |
| 149 | +- {feature name} cleanup best practices |
| 150 | + |
| 151 | +# Step 6: Implementation Guidelines |
| 152 | +IMPORTANT: MAKE SURE THAT THE Checkout SDK IS INITIALIZED CORRECTLY IN THE SETUPDEFAULT.TS FILE. REFER TO OTHER EXAMPLE APPS LIKE LOGIN-WITH-NEXTJS FOR THE CORRECT SETUP. |
| 153 | +## SDK Usage Best Practices |
| 154 | +- Use only documented public SDK methods |
| 155 | +- If using internal properties, document with comments and type assertions |
| 156 | +- Always implement proper cleanup in useEffect hooks |
| 157 | +- Use local type definitions instead of importing non-exported types |
| 158 | +- Add robust error handling for all {feature name} and operations |
| 159 | +- Add TypeScript type guards for any SDK properties that might be undefined |
| 160 | + |
| 161 | +# Step 7: Final Checks |
| 162 | +- Ensure that the app can build. |
| 163 | +- Ensure that all of the components, etc are used appropriately. |
| 164 | +- run `pnpm build` and ensure that the setup is perfect. |
| 165 | +- Ensure that there's no problem in all files. Make sure that when using a component, you use the available properties and values. |
| 166 | +- Features.json exists and everything make sense |
| 167 | +- Always check for the login/logout mode if they are consistent with the features.json file. |
| 168 | + |
| 169 | +## UI Best Practices |
| 170 | +- Always ensure that you ONLY use available Biom3 Components without assuming they exist. (Text and Spinner DOES NOT exist in the Biom3 UI Library) |
| 171 | +- Use standard HTML elements (h1, h2, h3, p) for text content. |
| 172 | +- Use Biom3 Button and other UI components as documented |
| 173 | +- Show clear loading/error states |
| 174 | +- Keep UI simple and focused on demonstrating the {feature name} |
| 175 | + |
| 176 | +## Critical Error Prevention |
| 177 | +- Always check if objects exist before accessing their properties or methods |
| 178 | +- Use optional chaining when accessing potentially undefined properties: obj?.prop?.method?.() |
| 179 | +- Wrap all {feature name} setup and teardown in try/catch blocks |
| 180 | +- Test component mounting/unmounting thoroughly to catch cleanup issues |
| 181 | + |
| 182 | +## ALWAYS READ THIS BEFORE YOU DO ANYTHING |
| 183 | +- DO NOT call methods that don't exist on the SDK instances |
| 184 | +- DO NOT try to import types that aren't explicitly exported |
| 185 | +- DO NOT forget to clean up {feature name} setup and teardown |
| 186 | +- DO NOT use custom components or providers unless necessary |
| 187 | +- DO NOT modify dependency versions in package.json |
| 188 | +- DO NOT use inconsistent import methods (mixing default and named imports) |
| 189 | +- DO NOT forget to include 'use client' directive in client components |
| 190 | +- DO NOT assume any property or method exists without checking first |
| 191 | +- DO NOT MAKE ANY TUTORIAL/METADATA FILE FOR THE {feature name} EXAMPLE APP |
| 192 | +- NEVER ADD `"ignoreDuringBuilds": true` TO .eslintrc.json |
| 193 | +- ALways do lint checks and never turn it off when building. |
0 commit comments