Skip to content

Commit c72a347

Browse files
authored
refactor: add & use shared packages (#168)
1 parent 9b6a38d commit c72a347

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+373
-466
lines changed

api/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"version": "1.0.0",
44
"scripts": {
55
"dev": "wrangler dev",
6-
"build": "tsc --project tsconfig.json",
6+
"build": "wrangler deploy --dry-run --outdir dist",
77
"preview": "wrangler dev",
8+
"typecheck": "tsc --noEmit",
89
"deploy": "wrangler deploy"
910
},
1011
"keywords": [],
@@ -16,14 +17,16 @@
1617
"@interledger/open-payments": "^7.0.0",
1718
"@noble/ed25519": "^2.2.3",
1819
"@paralleldrive/cuid2": "^2.2.2",
19-
"aws4fetch": "^1.0.20",
20+
"@shared/config-storage-service": "workspace:^",
21+
"@shared/utils": "workspace:^",
2022
"hono": "^4.7.8",
2123
"http-message-signatures": "^1.0.4",
2224
"httpbis-digest-headers": "^1.0.0",
2325
"zod": "^3.25.67"
2426
},
2527
"types": "./src/types.ts",
2628
"devDependencies": {
29+
"@shared/types": "workspace:^",
2730
"typescript": "5.1.6",
2831
"wrangler": "^4.16.1"
2932
},

api/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { cors } from 'hono/cors'
33
import { zValidator } from '@hono/zod-validator'
44
import { HTTPException } from 'hono/http-exception'
55
import { ZodError } from 'zod'
6-
import { ConfigStorageService } from './utils/config-storage.js'
6+
import { ConfigStorageService } from '@shared/config-storage-service'
7+
import type { ConfigVersions } from '@shared/types'
78
import { OpenPaymentsService } from './utils/open-payments.js'
89
import {
910
PaymentQuoteSchema,
1011
PaymentGrantSchema,
1112
PaymentFinalizeSchema,
1213
WalletAddressParamSchema
1314
} from './schemas/payment.js'
14-
import type { ConfigVersions } from './types.js'
1515
import { createHTTPException, serializeError } from './utils/utils.js'
1616

1717
export type Env = {

api/src/types.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,6 @@ import type {
66
} from './schemas/payment.js'
77
import type { z } from 'zod/v4'
88

9-
export interface ConfigVersions {
10-
[key: string]: ElementConfigType
11-
}
12-
13-
export interface ElementConfigType {
14-
// general config
15-
css: string
16-
walletAddress: string
17-
18-
// button specific
19-
buttonFontName: string
20-
buttonText: string
21-
buttonBorder: CornerType
22-
buttonTextColor: string
23-
buttonBackgroundColor: string
24-
buttonDescriptionText?: string
25-
26-
// banner specific
27-
bannerFontName: string
28-
bannerFontSize: number
29-
bannerTitleText: string
30-
bannerDescriptionText: string
31-
bannerSlideAnimation: SlideAnimationType
32-
bannerPosition: PositionType
33-
bannerBorder: CornerType
34-
bannerTextColor: string
35-
bannerBackgroundColor: string
36-
37-
// widget specific
38-
widgetFontName: string
39-
widgetFontSize: number
40-
widgetTitleText: string
41-
widgetDescriptionText: string
42-
widgetButtonText: string
43-
widgetButtonBorder: CornerType
44-
widgetTextColor: string
45-
widgetBackgroundColor: string
46-
widgetButtonTextColor: string
47-
widgetButtonBackgroundColor: string
48-
widgetTriggerBackgroundColor: string
49-
widgetTriggerIcon: string
50-
}
51-
52-
export enum CornerType {
53-
None = 'None',
54-
Light = 'Light',
55-
Pill = 'Pill'
56-
}
57-
58-
export enum SlideAnimationType {
59-
None = 'None',
60-
Down = 'Down'
61-
}
62-
63-
export enum PositionType {
64-
Top = 'Top',
65-
Bottom = 'Bottom'
66-
}
67-
689
export type PaymentQuoteInput = z.infer<typeof PaymentQuoteSchema>
6910
export type PaymentGrantInput = z.infer<typeof PaymentGrantSchema>
7011
export type PaymentFinalizeInput = z.infer<typeof PaymentFinalizeSchema>

api/src/utils/config-storage.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

api/src/utils/open-payments.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
isPendingGrant,
99
createAuthenticatedClient
1010
} from '@interledger/open-payments'
11+
import { getWalletAddress } from '@shared/utils'
1112
import {
1213
createHeaders,
13-
toWalletAddressUrl,
1414
timeout,
1515
createHTTPException,
1616
urlWithParams
@@ -122,9 +122,7 @@ export class OpenPaymentsService {
122122
amount: number
123123
note?: string
124124
}) {
125-
const receiverWallet = await this.getWalletAddress(
126-
args.receiverWalletAddress
127-
)
125+
const receiverWallet = await getWalletAddress(args.receiverWalletAddress)
128126
const { quote, incomingPaymentGrant } = await this.fetchQuote(
129127
{
130128
walletAddress: args.senderWalletAddress,
@@ -152,7 +150,7 @@ export class OpenPaymentsService {
152150
},
153151
receiverWallet: WalletAddress
154152
): Promise<CreatePayment> {
155-
const walletAddress = await this.getWalletAddress(args.walletAddress)
153+
const walletAddress = await getWalletAddress(args.walletAddress)
156154

157155
const amountObj = {
158156
value: BigInt(
@@ -474,14 +472,4 @@ export class OpenPaymentsService {
474472

475473
return { success: true }
476474
}
477-
478-
private async getWalletAddress(url: string): Promise<WalletAddress> {
479-
const walletAddress = await this.client!.walletAddress.get({
480-
url: toWalletAddressUrl(url)
481-
}).catch(() => {
482-
throw new Error('Invalid wallet address.')
483-
})
484-
485-
return walletAddress
486-
}
487475
}

api/src/utils/utils.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,10 @@ interface SignOptions {
2828
keyId: string
2929
}
3030

31-
export function walletAddressToKey(walletAddress: string): string {
32-
return `${decodeURIComponent(walletAddress).replace('$', '').replace('https://', '')}.json`
33-
}
34-
3531
export function timeout(delay: number): Promise<void> {
3632
return new Promise((resolve) => setTimeout(resolve, delay))
3733
}
3834

39-
export function toWalletAddressUrl(s: string): string {
40-
return s.startsWith('$') ? s.replace('$', 'https://') : s
41-
}
42-
4335
export async function createHeaders({
4436
request,
4537
privateKey,

cdn/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build": "vite build",
99
"preview": "npm run build && vite preview",
1010
"deploy": "wrangler deploy",
11+
"typecheck": "tsc --noEmit",
1112
"prepare": "wrangler types"
1213
},
1314
"devDependencies": {

cdn/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
33
"lib": ["ES2022"],
4+
"skipLibCheck": true,
45
"types": ["./worker-configuration.d.ts", "vite/client"]
56
}
67
}

components/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
"./*": "./src/*.ts"
1010
},
1111
"dependencies": {
12+
"@shared/utils": "workspace:^",
1213
"lit": "^3.1.0"
1314
},
1415
"devDependencies": {
1516
"@interledger/open-payments": "^7.1.0",
1617
"publisher-tools-api": "workspace:^",
1718
"typescript": "^5.3.3",
1819
"vite": "^7.0.5"
20+
},
21+
"scripts": {
22+
"typecheck": "tsc --noEmit"
1923
}
2024
}

components/src/widget/controller.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { Grant, Quote, PendingGrant } from '@interledger/open-payments'
2-
import type { ReactiveController, ReactiveControllerHost } from 'lit'
31
import type {
4-
WalletAddress,
5-
WidgetConfig,
6-
FormatAmountArgs,
7-
FormattedAmount
8-
} from './types'
2+
Grant,
3+
Quote,
4+
PendingGrant,
5+
WalletAddress
6+
} from '@interledger/open-payments'
7+
import type { ReactiveController, ReactiveControllerHost } from 'lit'
8+
import type { WidgetConfig, FormatAmountArgs, FormattedAmount } from './types'
99

1010
export interface WidgetState {
1111
walletAddress: WalletAddress

0 commit comments

Comments
 (0)