-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add merchant onboarding field definitions API #2214
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
Open
mirunagherman
wants to merge
3
commits into
main
Choose a base branch
from
miruna/int1-658
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
packages/wallet/backend/migrations/20260618154710_create_field_definitions.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| const fields = [ | ||
| { | ||
| key: 'contactEmail', | ||
| label: 'Contact email', | ||
| description: 'We use this to send onboarding confirmation.', | ||
| type: 'email', | ||
| required: true, | ||
| placeholder: 'me@interledger.org', | ||
| order: 2, | ||
| format: 'email', | ||
| maxLength: 255 | ||
| }, | ||
| { | ||
| id: '1acf7723-e1cd-44e7-a5db-3f614ce045ac', | ||
| key: 'merchantCategoryCode', | ||
| label: 'Merchant category', | ||
| type: 'select', | ||
| required: true, | ||
| order: 1 | ||
| } | ||
| ] | ||
|
|
||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.up = async function (knex) { | ||
| await knex.schema.createTable('field_definitions', (table) => { | ||
| table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()')) | ||
|
|
||
| table.string('key').notNullable() | ||
| table.string('label').notNullable() | ||
| table.string('description').nullable() | ||
| table | ||
| .enum('type', [ | ||
| 'text', | ||
| 'email', | ||
| 'tel', | ||
| 'number', | ||
| 'select', | ||
| 'checkbox', | ||
| 'date' | ||
| ]) | ||
| .notNullable() | ||
| table.boolean('required').notNullable().defaultTo(false) | ||
| table.string('placeholder').nullable() | ||
| table.integer('order').notNullable() | ||
|
|
||
| table.integer('maxLength').nullable() | ||
| table.string('format').nullable() | ||
|
|
||
| table.timestamp('createdAt').notNullable().defaultTo(knex.fn.now()) | ||
| table.timestamp('updatedAt').notNullable().defaultTo(knex.fn.now()) | ||
| }) | ||
|
|
||
| return knex('field_definitions').insert(fields) | ||
| } | ||
|
|
||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.down = function (knex) { | ||
| return knex.schema.dropTableIfExists('field_definitions') | ||
| } |
44 changes: 44 additions & 0 deletions
44
packages/wallet/backend/migrations/20260619142642_create_options.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| const options = [ | ||
| { | ||
| fieldId: '1acf7723-e1cd-44e7-a5db-3f614ce045ac', | ||
| value: '5411', | ||
| label: 'Grocery stores / supermarkets' | ||
| }, | ||
| { | ||
| fieldId: '1acf7723-e1cd-44e7-a5db-3f614ce045ac', | ||
| value: '5812', | ||
| label: 'Eating places / restaurants' | ||
| }, | ||
| { | ||
| fieldId: '1acf7723-e1cd-44e7-a5db-3f614ce045ac', | ||
| value: '5999', | ||
| label: 'Miscellaneous retail' | ||
| } | ||
| ] | ||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.up = async function (knex) { | ||
| await knex.schema.createTable('options', (table) => { | ||
| table.uuid('id').primary().defaultTo(knex.raw('gen_random_uuid()')) | ||
|
|
||
| table.uuid('fieldId').notNullable() | ||
| table.foreign('fieldId').references('id').inTable('field_definitions') | ||
| table.string('value').notNullable() | ||
| table.string('label').notNullable() | ||
|
|
||
| table.timestamp('createdAt').notNullable().defaultTo(knex.fn.now()) | ||
| table.timestamp('updatedAt').notNullable().defaultTo(knex.fn.now()) | ||
| }) | ||
|
|
||
| return knex('options').insert(options) | ||
| } | ||
|
|
||
| /** | ||
| * @param { import("knex").Knex } knex | ||
| * @returns { Promise<void> } | ||
| */ | ||
| exports.down = function (knex) { | ||
| return knex.schema.dropTableIfExists('options') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||
| import { Request, Response, NextFunction } from 'express' | ||||||
| import { TerminalService } from './service' | ||||||
|
|
||||||
| export class TerminalController { | ||||||
| constructor(private terminalService: TerminalService) {} | ||||||
|
|
||||||
| getOnboardingFormDefinition = async ( | ||||||
| _req: Request, | ||||||
| res: Response, | ||||||
| next: NextFunction | ||||||
| ) => { | ||||||
| try { | ||||||
| const formDefinition = | ||||||
| await this.terminalService.getOnboardingFormDefinition() | ||||||
| res.status(200).json(formDefinition) | ||||||
|
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.
Suggested change
|
||||||
| } catch (error) { | ||||||
| next(error) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { BaseModel } from '@shared/backend' | ||
| import { Model } from 'objection' | ||
|
|
||
| interface Validation { | ||
| minLength?: number | ||
| maxLength?: number | ||
| pattern?: string | ||
| min?: number | ||
| max?: number | ||
| format?: string | ||
| mustEqual?: boolean | ||
| } | ||
|
|
||
| enum FieldType { | ||
| TEXT = 'text', | ||
| EMAIL = 'email', | ||
| TEL = 'tel', | ||
| NUMBER = 'number', | ||
| SELECT = 'select', | ||
| CHECKBOX = 'checkbox', | ||
| DATE = 'date' | ||
| } | ||
|
|
||
| export class FieldDefinitions extends BaseModel { | ||
| static tableName = 'field_definitions' | ||
|
|
||
| public key!: string | ||
| public label!: string | ||
| public description?: string | ||
| public type!: FieldType | ||
| public required!: boolean | ||
| public placeholder?: string | ||
| public order!: number | ||
| public options?: Options[] | ||
| public validation?: Validation | ||
| public format?: string | ||
| public maxLength?: number | ||
|
|
||
| static relationMappings = () => ({ | ||
| options: { | ||
| relation: Model.HasManyRelation, | ||
| modelClass: Options, | ||
| join: { | ||
| from: 'field_definitions.id', | ||
| to: 'options.fieldId' | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| export class Options extends BaseModel { | ||
| static tableName = 'options' | ||
|
|
||
| public fieldId?: string | ||
| public value!: string | ||
| public label!: string | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { Logger } from 'winston' | ||
| import { FieldDefinitions } from './model' | ||
|
|
||
| export class TerminalService { | ||
| constructor(private logger: Logger) {} | ||
|
|
||
| async getOnboardingFormDefinition(): Promise<FieldDefinitions[]> { | ||
| const fields = await FieldDefinitions.query() | ||
| .withGraphFetched('options') | ||
| .orderBy('order', 'asc') | ||
|
|
||
| this.logger.debug('Returning merchant onboarding form definition', { | ||
| fields: fields | ||
| }) | ||
|
|
||
| return fields.map((field) => { | ||
| const mapped = { | ||
| key: field.key, | ||
| label: field.label, | ||
| type: field.type, | ||
| required: field.required, | ||
| order: field.order | ||
| } as Partial<FieldDefinitions> | ||
|
|
||
| if (field.description) mapped.description = field.description | ||
| if (field.placeholder) mapped.placeholder = field.placeholder | ||
| if (field.format) | ||
| mapped.validation = { | ||
| ...(mapped.validation || {}), | ||
| format: field.format | ||
| } | ||
| if (field.maxLength) | ||
| mapped.validation = { | ||
| ...(mapped.validation || {}), | ||
| maxLength: field.maxLength | ||
| } | ||
| if (field.options?.length) { | ||
| mapped.options = field.options.map((opt) => ({ | ||
| ...(opt.value && { value: opt.value }), | ||
| ...(opt.label && { label: opt.label }) | ||
| })) as FieldDefinitions['options'] | ||
| } | ||
|
|
||
| return mapped as FieldDefinitions | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Non-blocking:
Should this endpoint be public? or protected by a custom terminal auth middleware or a rate limiter if it's left public.
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.
Agreed with Daev. This endpoint should not be public. It is called only from Merchant API - We can pass some API key (uuid) in the request head for example and you can check if the header is correct - need to discuss about this.
Does testnet wallet has proper HTTP signatures (RFC 9421)?