Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
feat: customer and metafield types (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyko authored Feb 28, 2021
1 parent a962957 commit 2e80d11
Show file tree
Hide file tree
Showing 11 changed files with 1,197 additions and 13 deletions.
426 changes: 426 additions & 0 deletions 2021/01/payloads/customer.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions 2021/01/payloads/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './access';
export * from './analytics';
export * from './customer';
export * from './billing';
export * from './metafield';
54 changes: 54 additions & 0 deletions 2021/01/payloads/metafield.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* https://shopify.dev/docs/admin-api/rest/reference/metafield#properties-2020-04
*/
export interface Metafield {
/**
* The date when the metafield was created
* @readonly
*/
created_at: string;
/**
* The date when the metafield was last updated
*/
updated_at: string;
/**
* The description of the information the metafield contains
*/
description: string | null;
/**
* The unique id of the metafield
*/
id: number;
/**
* The name of the metafield (3 - 30 characters)
* @required
*/
key: string;
/**
* The container for a set of metafields (2 - 20 characters)
* @required
*/
namespace: string;
/**
* The unique id of the resource that the metafield is attached to
*/
owner_id: number;
/**
* The type of resource that the metafield is attached to
*/
owner_resource: string;
/**
* The information to be stored as metadata
* * When the namespace is `tags`, the key is equal to `alt` (max 512 characters)
*
* The maximum length of `value` depends on {@link Metafield#value_type value_type}:
* * `value_type` is `string`: max 5,000,000 characters
* * `value_type` is `integer`: max 100,000 characters
* * `value_type` is `json_string`: max 100,000 characters
*/
value: string | number;
/**
* The metafield's information type
*/
value_type: 'string' | 'integer' | 'json_string';
}
3 changes: 2 additions & 1 deletion 2021/01/rest/access.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { EmptyResponse } from '../../../common';
import type { AccessScope, StorefrontAccessToken } from '../payloads';

/**
Expand All @@ -17,7 +18,7 @@ export interface PostStorefrontAccessTokenResult {
/**
* https://shopify.dev/docs/admin-api/rest/reference/access/storefrontaccesstoken#destroy-2021-01
*/
export type DeleteStorefrontAccessTokenResult = never;
export type DeleteStorefrontAccessTokenResult = EmptyResponse;

/**
* https://shopify.dev/docs/admin-api/rest/reference/access/storefrontaccesstoken#index-2021-01
Expand Down
3 changes: 2 additions & 1 deletion 2021/01/rest/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { EmptyResponse } from '../../../common';
import type { Report } from '../payloads/analytics';

export interface GetReportsQuery {
Expand Down Expand Up @@ -64,4 +65,4 @@ export interface PutReportResult {
/**
* https://shopify.dev/docs/admin-api/rest/reference/analytics/report#destroy-2021-01
*/
export type DeleteReportResult = never;
export type DeleteReportResult = EmptyResponse;
4 changes: 2 additions & 2 deletions 2021/01/rest/billing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FieldQueryInterface } from '../../../common';
import type { EmptyResponse, FieldQueryInterface } from '../../../common';
import type {
ApplicationCharge,
ApplicationCredit,
Expand Down Expand Up @@ -113,7 +113,7 @@ export interface GetRecurringApplicationChargesQyery extends FieldQueryInterface
/**
* https://shopify.dev/docs/admin-api/rest/reference/billing/recurringapplicationcharge#destroy-2021-01
*/
export type DeleteRecurringApplicationChargeResult = never;
export type DeleteRecurringApplicationChargeResult = EmptyResponse;

/**
* https://shopify.dev/docs/admin-api/rest/reference/billing/recurringapplicationcharge#update-2021-01
Expand Down
276 changes: 276 additions & 0 deletions 2021/01/rest/customers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
import type { CountResult, EmptyResponse, FieldQueryInterface } from '../../../common';
import type { Customer, CustomerAddress, CustomerInvite, CustomerSavedSearch } from '../payloads/customer';
import type { PostMetafieldJSONBody } from './metafield';

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#index-2020-04
*/
export interface GetCustomersResponse {
customers: Customer[];
}

export interface GetCustomersQuery extends FieldQueryInterface {
/**
* Restrict results to customers specified by a comma-separated list of ids
*/
ids?: string;
/**
* Restrict results to hose after the specific id
*/
since_id?: string;
/**
* Shows customers created after the provided date
*/
created_at_min?: string;
/**
* Shows customers created before the provided date
*/
created_at_max?: string;
/**
* Shows customers updated after the provided date
*/
updated_at_min?: string;
/**
* Shows customers updated before the provided date
*/
updated_at_max?: string;
/**
* The maximum number of results to show (50 - 250)
*/
limit?: number;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#search-2020-04
*/
export type GetCustomerSearchResponse = GetCustomersResponse;

export interface GetCustomerSearchQuery extends FieldQueryInterface {
/**
* Set the field and direction by which to order results (default: `last_order_date DESC`)
*/
order?: string;
/**
* Text to search for the the shop's customer data.
*
* Supported queries: `accepts_marketing`,`activation_date`,`address1`,`address2`,`city`,`company`,`country`,`customer_date`,`customer_first_name`,`customer_id`,`customer_last_name`,`customer_tag`,`email`,`email_marketing_state`,`first_name`,`first_order_date`,`id`,`last_abandoned_order_date`,`last_name`,`multipass_identifier`,`orders_count`,`order_date`,`phone`,`province`,`shop_id`,`state`,`tag`,`total_spent`,`updated_at`,`verified_email`,`product_subscriber_status`
*/
query: string;
/**
* The maximum number of results to show (default: `50`, maximum: `250`)
*/
limit?: number;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#show-2020-04
*/
export interface GetCustomerResponse {
customer: Customer;
}

export type GetCustomerQuery = FieldQueryInterface;

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#create-2020-04
*/
export type PostCustomerResponse = GetCustomerResponse;

type PostCustomerPassword =
| { password?: undefined; password_confirmation?: undefined }
| { password: string; password_confirmation: string };
export interface PostCustomerJSONBody {
customer: Pick<Customer, 'first_name' | 'last_name' | 'email'> &
Partial<Pick<Customer, 'first_name' | 'last_name' | 'email' | 'phone' | 'verified_email' | 'addresses'>> & {
metafields?: PostMetafieldJSONBody[];
send_email_invite?: boolean;
} & PostCustomerPassword;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#update-2020-04
*/
export type PutCustomerResponse = GetCustomerResponse;

export interface PutCustomerJSONBody {
customer: Pick<Customer, 'id'> & Partial<Customer>;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#account_activation_url-2020-04
*/
export interface PostCustomerActivationURLResponse {
/**
* The generated account activation URL
*/
account_activation_url?: string;
/**
* If the request fails and errors are thrown
*/
errors?: string[];
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#send_invite-2020-04
*/
export interface PostCustomerAccountInviteResponse {
customer_invite: CustomerInvite;
}

export interface PostCustomerAccountInviteJSONBody {
customer_invite?: Partial<CustomerInvite>;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#destroy-2020-04
*/
export type DeleteCustomerResponse = EmptyResponse;

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#count-2020-04
*/
export type GetCustomerCountResponse = CountResult;

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer#orders-2020-04
*/
// TODO: relies on Order data
export type GetCustomerOrdersResponse = unknown;

/* Customer Address */

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address#index-2020-04
*/
export interface GetCustomerAddressesResponse {
addresses: CustomerAddress[];
}

export interface GetCustomerAddressesQuery {
/**
* The amount of customer addresses to return (default: `50`, maximum: `250`)
*/
limit: number;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address#show-2020-04
*/
export interface GetCustomerAddressResponse {
customer_address: CustomerAddress;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address#create-2020-04
*/
export type PostCustomerAddressResponse = GetCustomerAddressResponse;

export interface PostCustomerAddressJSONBody {
address: Omit<CustomerAddress, 'name'>;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address#update-2020-04
*/
export type PutCustomerAddressResponse = GetCustomerAddressResponse;

export interface PutCustomerAddressJSONBody {
address: Partial<CustomerAddress>;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address#destroy-2020-04
*/
export type DeleteCustomerAddressResponse = EmptyResponse;

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address#set-2020-04
*/
export type PutBulkCustomerAddressesResponse = EmptyResponse;

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address#default-2020-04
*/
export type PutCustomerDefaultAddressResponse = GetCustomerAddressResponse;

/* Customer Saved Search */

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customersavedsearch#index-2020-04
*/
export interface GetCustomerSavedSearchesResponse {
customer_saved_searches: CustomerSavedSearch[];
}

export interface GetCustomerSavedSearchsQuery extends FieldQueryInterface {
/**
* The maximum number of results to show (default: `50`, maximum: `250`)
*/
limit?: number;
/**
* Restrict results to after the specified id
*/
since_id?: number;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customersavedsearch#count-2020-04
*/
export type GetCustomerSavedSearchesCountResponse = CountResult;

export interface GetCustomerSavedSearchesCountQuery {
/**
* Restrict results to after the specified id
*/
since_id?: number;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customersavedsearch#show-2020-04
*/
export interface GetCustomerSavedSearchResponse {
customer_saved_search: CustomerSavedSearch;
}

export type GetCustomerSavedSearchQuery = FieldQueryInterface;

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customersavedsearch#other-2020-04
*/
export type GetCustomerSavedSearchCustomersResponse = GetCustomersResponse;

export interface GetCustomerSavedSearchCustomersQuery extends FieldQueryInterface {
/**
* Set the field and direction by which to order results (default: `last_order_date DESC`)
*/
order?: string;
/**
* The maximum number of results to show (default: `50`, maximum: `250`)
*/
limit?: number;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customersavedsearch#create-2020-04
*/
export interface PostCustomerSavedSearchResponse {
customer_saved_search: CustomerSavedSearch;
}

export interface PostCustomerSavedSearchJSONBody {
customer_saved_search: Pick<CustomerSavedSearch, 'name' | 'query'>;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customersavedsearch#update-2020-04
*/
export type PutCustomerSavedSearchResponse = GetCustomerSavedSearchResponse;

export interface PutCustomerSavedSearchJSONBody {
customer_saved_search: Pick<CustomerSavedSearch, 'id'> & Partial<Pick<CustomerSavedSearch, 'name' | 'query'>>;
}

/**
* https://shopify.dev/docs/admin-api/rest/reference/customers/customersavedsearch#destroy-2020-04
*/
export type DeleteCustomerSavedSearchResponse = EmptyResponse;
Loading

0 comments on commit 2e80d11

Please sign in to comment.