Skip to content
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

ClientSide types #15

Merged
merged 27 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9a802ce
Added ClientSide type
pkgacek Jan 14, 2021
6b2072b
Added changeset
pkgacek Jan 14, 2021
56a0928
Updated types/index.ts
pkgacek Jan 14, 2021
d1a769a
Removed deprecated endpoint
pkgacek Jan 14, 2021
aed070d
Revert "Updated types/index.ts"
pkgacek Jan 14, 2021
7a55305
Revert "Removed deprecated endpoint"
pkgacek Jan 14, 2021
4cbe255
Added missing ClientSide types
pkgacek Jan 14, 2021
cb2b13f
Updated types for client side publish method
pkgacek Jan 14, 2021
76a04d3
Used FixMe convention for unknown types
pkgacek Jan 14, 2021
4a5ec58
Merge branch 'main' into types-clientside
pkgacek Jan 20, 2021
68939e7
Merge branch 'main' into types-clientside
pkgacek Jan 21, 2021
252ac31
Merge branch 'main' into types-clientside
pkgacek Feb 10, 2021
cc14b0c
Merge branch 'main' into types-clientside
pkgacek Feb 11, 2021
ff17bab
Updated types
pkgacek Feb 11, 2021
7ef3df8
Linting
pkgacek Feb 11, 2021
44c9734
Merge branch 'main' into types-clientside
pkgacek Feb 17, 2021
d3cbdd9
Merge branch 'main' into types-clientside
pkgacek Feb 22, 2021
2bf06c9
Merge branch 'main' into types-clientside
pkgacek Feb 25, 2021
d4965c9
Updated encoding
pkgacek Mar 2, 2021
c7c36a0
fixed payload & added new method & added code trimming
pkgacek Mar 4, 2021
ec04ce7
removed console.logs
pkgacek Mar 4, 2021
e946fff
updated yarn.lock to correct node
pkgacek Mar 4, 2021
b66ad4b
Updated git workflows
pkgacek Mar 4, 2021
b422df4
Updates
pkgacek Mar 10, 2021
ab91ba1
Updated
pkgacek Mar 10, 2021
d5be8a3
updates
pkgacek Mar 10, 2021
2a00e78
updates
pkgacek Mar 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/sdk/src/ClientSide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ClientSide {
/**
* @see https://docs.voucherify.io/reference/#vouchers-validate
*/
public validate(params: T.ClientSideValidateParams) {
public validate(params: T.ClientSideValidateParams | string) {
darekg11 marked this conversation as resolved.
Show resolved Hide resolved
assert(
isObject(params) || isString(params),
'client.validate: expected "params" argument to be an object or a string',
Expand All @@ -25,10 +25,10 @@ export class ClientSide {
query.code = params
} else {
query.code = params.code
query.item = params.order?.items
query.items = params.items
darekg11 marked this conversation as resolved.
Show resolved Hide resolved
query.amount = params.amount
query.metadata = params.metadata
query.order = { metadata: params.order?.metadata }
query.order = { metadata: params.orderMetadata }
query.customer = params.customer
query.trackingId = this.trackingId
}
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/RequestController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios, { AxiosInstance, AxiosError } from 'axios'
import { VoucherifyError } from './VoucherifyError'
import axios, { AxiosError, AxiosInstance } from 'axios'
darekg11 marked this conversation as resolved.
Show resolved Hide resolved

import Qs from 'qs'
import { VoucherifyError } from './VoucherifyError'

export interface RequestControllerOptions {
baseURL: string
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export function toQueryParams(obj: Record<string, unknown>): Record<string, stri
case 'number':
case 'boolean':
case 'bigint':
if (prefix) return entries.push([`${prefix}[${key}]`, val.toString()])
return entries.push([key, val.toString()])
if (prefix) return entries.push([`${prefix}[${key}]`, encode(val.toString())])
return entries.push([key, encode(val.toString())])
case 'object':
if (prefix) return mapToEntries(`${prefix}[${key}]`, <Record<string, unknown>>val)
return mapToEntries(key, <Record<string, unknown>>val)
Expand Down
12 changes: 5 additions & 7 deletions packages/sdk/src/types/ClientSide.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { VouchersResponse, DiscountUnit, DiscountAmount, DiscountPercent } from './Vouchers'
import { CustomerRequest, SimpleCustomer } from './Customers'
import { OrdersItem, OrdersCreateResponse } from './Orders'
import { DiscountAmount, DiscountPercent, DiscountUnit, VouchersResponse } from './Vouchers'
import { OrdersCreateResponse, OrdersItem } from './Orders'

export interface ClientSideValidateParams {
code: string
code?: string
tracking_id?: string
amount?: number
order?: {
items?: Pick<OrdersItem, 'source_id' | 'product_id' | 'sku' | 'quantity'>[]
metadata?: Record<string, any>
}
items?: Pick<OrdersItem, 'source_id' | 'product_id' | 'sku' | 'quantity'>[]
orderMetadata?: Record<string, any>
customer?: Pick<CustomerRequest, 'source_id' | 'metadata'>
metadata?: Record<string, any>
session_type?: 'LOCK'
Expand Down