Skip to content

Commit

Permalink
Feat customer create run action (#67)
Browse files Browse the repository at this point in the history
* feat: customer create run action

* update index types

* add new param types

* add metadata parameter

* Update bot.ts

* Update bot.yaml
  • Loading branch information
Abel Jimenez Molla authored Feb 20, 2024
1 parent 7d3d54e commit afbc4e5
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
38 changes: 38 additions & 0 deletions apps/stripe/bundle/bots/runaction/customer_create/bot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { RunActionBotApi } from "@uesio/bots"
import { Params } from "@uesio/app/bots/runaction/uesio/stripe/customer_create"
import { Stripe } from "stripe"

export default function customer_create(bot: RunActionBotApi) {
const params = bot.params.getAll() as Params
const { name, email, metadata } = params
const actionName = bot.getActionName()

if (actionName !== "customer_create") {
bot.addError("unsupported action name: " + actionName)
return
}

const baseURL = bot.getIntegration().getBaseURL()
const result = bot.http.request<
Stripe.CustomerCreateParams,
Stripe.Customer
>({
method: "POST",
url: baseURL + "/v1/customers",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: {
name,
email,
metadata,
},
})

if (result.code !== 200) {
bot.addError("could not complete customer creation: " + result.code)
return
}

bot.addResult("customer", result.body)
}
17 changes: 17 additions & 0 deletions apps/stripe/bundle/bots/runaction/customer_create/bot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: customer_create
public: true
type: RUNACTION
dialect: TYPESCRIPT
params:
- name: name
label: Customer full name
type: TEXT
required: true
- name: email
type: TEXT
required: true
selectList: mode
- name: metadata
label: Set of key-value pairs
type: MAP
required: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: customer_create
label: Create a Customer Object
public: true
bot: customer_create
12 changes: 12 additions & 0 deletions apps/stripe/generated/@types/@uesio/app.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ declare module "@uesio/app/bots/runaction/uesio/stripe/checkout" {
mode: string
}

export type {
Params
}
}
declare module "@uesio/app/bots/runaction/uesio/stripe/customer_create" {

type Params = {
name: string
email: string
metadata: Record
}

export type {
Params
}
Expand Down
16 changes: 11 additions & 5 deletions apps/stripe/generated/@types/@uesio/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,27 @@ interface UserApi {
getUniqueKey: () => string
}

interface BotHttpRequest<Request> {
interface BotHttpRequest<
RequestBody = string | Record<string, unknown> | unknown[],
> {
url: string
method: string
headers?: Record<string, string>
body?: Request
body?: RequestBody
}
interface BotHttpResponse<Response> {
interface BotHttpResponse<
ResponseBody = string | Record<string, unknown> | null,
> {
code: number
status: string
headers: Record<string, string>
body: Response
body: ResponseBody
}

interface HttpApi {
request: <Request, Response>(options: BotHttpRequest<Request>) => BotHttpResponse<Response>
request: <RequestBody, ResponseBody>(
options: BotHttpRequest<RequestBody>
) => BotHttpResponse<ResponseBody>
}

interface SaveOptionsApi {
Expand Down

0 comments on commit afbc4e5

Please sign in to comment.