Skip to content

Commit

Permalink
feat(lemonsqueezy): stub out userland APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
DominusKelvin committed Dec 17, 2023
1 parent 16f3868 commit 362055e
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 80 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions packages/sails-hook-pay/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* pay hook
*
* @description :: A hook definition. Extends Sails by adding shadow routes, implicit actions, and/or initialization logic.
* @docs :: https://sailsjs.com/docs/concepts/extending-sails/hooks
*/

module.exports = function (sails) {
return {
defaults: {
pay: {
provider: 'default',
providers: {}
}
},
/**
* Runs when this Sails app loads/lifts.
*/
initialize: async function () {
sails.log.info('Initializing custom hook (`pay`)')
}
}
}
2 changes: 1 addition & 1 deletion playgrounds/lemonsqueezy/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"single",
{ "avoidEscape": false, "allowTemplateLiterals": true }
],
"semi": ["warn", "always"],
"semi": ["never"],
"semi-spacing": ["warn", { "before": false, "after": true }],
"semi-style": ["warn", "last"]
}
Expand Down
17 changes: 17 additions & 0 deletions playgrounds/lemonsqueezy/api/controllers/pay/checkout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
friendlyName: 'Checkout',

description: 'Checkout pay.',

inputs: {},

exits: {},

fn: async function (inputs) {
// All done.
sails.helpers.pay.checkout.with({})
sails.helpers.pay.charge.with({})
sails.helpers.pay.charge.with({ provider: 'lemonsqueezy' })
return
}
}
7 changes: 7 additions & 0 deletions playgrounds/lemonsqueezy/config/pay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports.pay = {
providers: {
default: {
adapter: 'sails-lemonsqueezy'
}
}
}
2 changes: 1 addition & 1 deletion playgrounds/lemonsqueezy/config/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports.routes = {
* *
***************************************************************************/

'/': { view: 'pages/homepage' }
'/checkout': 'pay/checkout'

/***************************************************************************
* *
Expand Down
22 changes: 22 additions & 0 deletions playgrounds/lemonsqueezy/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"include": ["api/**/*", "assets/js/**/*", "types/index.d.ts"],

"compilerOptions": {
"types": ["node"],
"typeRoots": ["./types", "./node_modules/@types"],
"lib": ["es2016"],
// silences wrong TS error, we don't compile, we only typecheck
"outDir": "./irrelevant/unused",
"allowJs": true,
"checkJs": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noEmitOnError": true,
"noErrorTruncation": true,
"baseUrl": ".",
"paths": {
"@/*": ["assets/js/*"]
}
}
}
1 change: 1 addition & 0 deletions playgrounds/lemonsqueezy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"sails-lemonsqueezy": "^0.0.1"
},
"devDependencies": {
"@types/node": "^20.10.4",
"eslint": "5.16.0"
},
"scripts": {
Expand Down
182 changes: 182 additions & 0 deletions playgrounds/lemonsqueezy/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
interface Sails {
log: LogMethod & LogObject
models: { [modelName: string]: Model }
helpers: Helper
on(event: string, listener: (...args: any[]) => void): void
off(event: string, listener: (...args: any[]) => void): void
emit(event: string, ...args: any[]): void
lift(cb?: (err: Error, sails: Sails) => void): Sails
lower(cb?: (err?: Error) => void): void
load(): Sails
getVersion(): string
inertia: Inertia
wish: Wish
hooks: Hook
config: Config
req: {
ip: string
}
renderView: (
relPathToView: string,
_options: Dictionary,
optionalCb?: (err: Error | null, compiledHtml: string) => void
) => Sails & Promise<string>
intercept(callback: (err: Error) => Error): Sails & Promise<string>
}

interface Helper {
passwords: {
hashPassword: (password: string, strength?: number) => Promise<string>
checkPassword: (
passwordAttempt: string,
hashedPassword: string
) => Promise<Sails>
}
strings: {
random: (style?: 'url-friendly' | 'alphanumeric') => string
uuid: () => string
}
mail: {
send: {
with: (params: EmailParams) => Promise<string>
}
}
pay: {
checkout: {
with: (params: CheckoutParams) => Promise<string>
}
charge: {
with: (params: CheckoutParams) => Promise<string>
}
}
getUserInitials: (fullName: string) => string
capitalize: (inputString: string) => string
}
interface EmailParams {
mailer?: string
to: string
cc?: string | array<string>
bcc?: string | array<string>
subject?: string
template?: string
templateData?: object
attachments?: EmailAttachment[]
}
interface EmailAttachment {
filename: string
content?: string | Buffer | NodeJS.ReadableStream
path?: string
href?: string
httpHeaders?: { [key: string]: string }
contentType?: string
contentDisposition?: string
cid?: string
encoding?: string
headers?: { [key: string]: string }
raw?: string
}

interface Hook {
inertia: Inertia
pay: Pay
}
interface LogMethod {
(...args: any[]): void
}

interface LogObject {
info: LogMethod
warn: LogMethod
error: LogMethod
debug: LogMethod
silly: LogMethod
verbose: LogMethod
}

interface Config {
smtp: {
transport?: 'smtp'
host?: string
port?: number
encryption?: 'tls' | 'ssl'
username: string
password: string
}
google: {
clientId: string
clientSecret: string
redirect: string
}
mail: {
default: string
mailers: {
log: object
smtp: {
transport: 'smtp'
host: string
port: number
encryption: 'tls' | 'ssl'
username?: string
password?: string
}
}
from: {
name: string
address: string
}
}
custom: Custom
}

interface Custom {
baseUrl: string
passwordResetTokenTTL: number
emailProofTokenTTL: number
rememberMeCookieMaxAge: number
internalEmail: string
verifyEmail: boolean
}
interface Wish {
provider: (provider: string) => Wish
redirect: () => string
user: (code: string) => GoogleUser | GitHubUser
}
interface Inertia {
share: (key: string, value?: any) => void
render: (
component: string,
props?: Record<string, any>,
viewData?: Record<string, any>
) => any
flushShared: (key?: string) => void
viewData: (key: string, value: any) => void
getViewData: (key: string) => any
setRootView: (newRootView: string) => void
getRootView: () => string
location: (path: string) => void
}

interface GoogleUser {
id: string
email: string
verified_email: boolean
name: string
given_name: string
family_name: string
picture: string
locale: string
accessToken: string
idToken: string
}

interface LoggedInUser {
id: string
fullName: string
email: string
initials?: string
googleAvatarUrl?: string
value: LoggedInUser
}
declare const sails: Sails

declare const User
78 changes: 0 additions & 78 deletions playgrounds/lemonsqueezy/views/pages/homepage.ejs

This file was deleted.

0 comments on commit 362055e

Please sign in to comment.