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

Require ids in find methods #807

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .changeset/short-pillows-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopify/shopify-api": patch
---

Fixing REST resource `find()` methods to fail when missing all ids, instead of defaulting to the same behaviour as `all()`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '../../../../__tests__/test-helper';
import {testConfig} from '../../../../__tests__/test-config';
import {Session} from '../../../../session/session';
import {HttpResponseError} from '../../../../error';
import {HttpResponseError, RestResourceError} from '../../../../error';
import {PageInfo} from '../../../types';
import {ApiVersion, LATEST_API_VERSION} from '../../../../types';
import {shopifyApi} from '../../../../index';
Expand Down Expand Up @@ -45,6 +45,14 @@ describe('Base REST resource', () => {
}).toMatchMadeHttpRequest();
});

it.each([NaN, null, undefined])('throws an error if id is %s', async (id) => {
const shopify = shopifyApi(testConfig({restResources}));

expect(async () =>
shopify.rest.FakeResource.find({id: id as number, session}),
).rejects.toThrow(RestResourceError);
});

it('finds resource with param', async () => {
const shopify = shopifyApi(testConfig({restResources}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class FakeResource extends Base {
session,
urlIds: {id, other_resource_id},
params: {param, ...otherArgs},
requireIds: true,
});
return result.data ? result.data[0] : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class AndroidPayKey extends Base {
): Promise<AndroidPayKey | null> {
const result = await this.baseFind<AndroidPayKey>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ApplePayCertificate extends Base {
): Promise<ApplePayCertificate | null> {
const result = await this.baseFind<ApplePayCertificate>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class ApplicationCharge extends Base {
): Promise<ApplicationCharge | null> {
const result = await this.baseFind<ApplicationCharge>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ApplicationCredit extends Base {
): Promise<ApplicationCredit | null> {
const result = await this.baseFind<ApplicationCredit>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class Article extends Base {
): Promise<Article | null> {
const result = await this.baseFind<Article>({
session: session,
requireIds: true,
urlIds: {"id": id, "blog_id": blog_id},
params: {"fields": fields},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class Blog extends Base {
): Promise<Blog | null> {
const result = await this.baseFind<Blog>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class CarrierService extends Base {
): Promise<CarrierService | null> {
const result = await this.baseFind<CarrierService>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Checkout extends Base {
): Promise<Checkout | null> {
const result = await this.baseFind<Checkout>({
session: session,
requireIds: true,
urlIds: {"token": token},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class Collect extends Base {
): Promise<Collect | null> {
const result = await this.baseFind<Collect>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class Collection extends Base {
): Promise<Collection | null> {
const result = await this.baseFind<Collection>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class CollectionListing extends Base {
): Promise<CollectionListing | null> {
const result = await this.baseFind<CollectionListing>({
session: session,
requireIds: true,
urlIds: {"collection_id": collection_id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class Comment extends Base {
): Promise<Comment | null> {
const result = await this.baseFind<Comment>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/country.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class Country extends Base {
): Promise<Country | null> {
const result = await this.baseFind<Country>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class CustomCollection extends Base {
): Promise<CustomCollection | null> {
const result = await this.baseFind<CustomCollection>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class Customer extends Base {
): Promise<Customer | null> {
const result = await this.baseFind<Customer>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class CustomerAddress extends Base {
): Promise<CustomerAddress | null> {
const result = await this.baseFind<CustomerAddress>({
session: session,
requireIds: true,
urlIds: {"id": id, "customer_id": customer_id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export class DiscountCode extends Base {
): Promise<DiscountCode | null> {
const result = await this.baseFind<DiscountCode>({
session: session,
requireIds: true,
urlIds: {"id": id, "price_rule_id": price_rule_id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/dispute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class Dispute extends Base {
): Promise<Dispute | null> {
const result = await this.baseFind<Dispute>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class DisputeEvidence extends Base {
): Promise<DisputeEvidence | null> {
const result = await this.baseFind<DisputeEvidence>({
session: session,
requireIds: true,
urlIds: {"dispute_id": dispute_id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class DraftOrder extends Base {
): Promise<DraftOrder | null> {
const result = await this.baseFind<DraftOrder>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class Event extends Base {
): Promise<Event | null> {
const result = await this.baseFind<Event>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class Fulfillment extends Base {
): Promise<Fulfillment | null> {
const result = await this.baseFind<Fulfillment>({
session: session,
requireIds: true,
urlIds: {"id": id, "order_id": order_id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class FulfillmentEvent extends Base {
): Promise<FulfillmentEvent | null> {
const result = await this.baseFind<FulfillmentEvent>({
session: session,
requireIds: true,
urlIds: {"id": id, "order_id": order_id, "fulfillment_id": fulfillment_id},
params: {"event_id": event_id},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class FulfillmentOrder extends Base {
): Promise<FulfillmentOrder | null> {
const result = await this.baseFind<FulfillmentOrder>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class FulfillmentService extends Base {
): Promise<FulfillmentService | null> {
const result = await this.baseFind<FulfillmentService>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class GiftCard extends Base {
): Promise<GiftCard | null> {
const result = await this.baseFind<GiftCard>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class GiftCardAdjustment extends Base {
): Promise<GiftCardAdjustment | null> {
const result = await this.baseFind<GiftCardAdjustment>({
session: session,
requireIds: true,
urlIds: {"id": id, "gift_card_id": gift_card_id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class Image extends Base {
): Promise<Image | null> {
const result = await this.baseFind<Image>({
session: session,
requireIds: true,
urlIds: {"id": id, "product_id": product_id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class InventoryItem extends Base {
): Promise<InventoryItem | null> {
const result = await this.baseFind<InventoryItem>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class Location extends Base {
): Promise<Location | null> {
const result = await this.baseFind<Location>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class MarketingEvent extends Base {
): Promise<MarketingEvent | null> {
const result = await this.baseFind<MarketingEvent>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export class Metafield extends Base {
): Promise<Metafield | null> {
const result = await this.baseFind<Metafield>({
session: session,
requireIds: true,
urlIds: {"id": id, "article_id": article_id, "blog_id": blog_id, "collection_id": collection_id, "customer_id": customer_id, "draft_order_id": draft_order_id, "order_id": order_id, "page_id": page_id, "product_image_id": product_image_id, "product_id": product_id, "variant_id": variant_id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class MobilePlatformApplication extends Base {
): Promise<MobilePlatformApplication | null> {
const result = await this.baseFind<MobilePlatformApplication>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class Order extends Base {
): Promise<Order | null> {
const result = await this.baseFind<Order>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class OrderRisk extends Base {
): Promise<OrderRisk | null> {
const result = await this.baseFind<OrderRisk>({
session: session,
requireIds: true,
urlIds: {"id": id, "order_id": order_id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class Page extends Base {
): Promise<Page | null> {
const result = await this.baseFind<Page>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class Payment extends Base {
): Promise<Payment | null> {
const result = await this.baseFind<Payment>({
session: session,
requireIds: true,
urlIds: {"id": id, "checkout_id": checkout_id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class PaymentGateway extends Base {
): Promise<PaymentGateway | null> {
const result = await this.baseFind<PaymentGateway>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/payout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class Payout extends Base {
): Promise<Payout | null> {
const result = await this.baseFind<Payout>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class PriceRule extends Base {
): Promise<PriceRule | null> {
const result = await this.baseFind<PriceRule>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class Product extends Base {
): Promise<Product | null> {
const result = await this.baseFind<Product>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export class ProductListing extends Base {
): Promise<ProductListing | null> {
const result = await this.baseFind<ProductListing>({
session: session,
requireIds: true,
urlIds: {"product_id": product_id},
params: {},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/province.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class Province extends Base {
): Promise<Province | null> {
const result = await this.baseFind<Province>({
session: session,
requireIds: true,
urlIds: {"id": id, "country_id": country_id},
params: {"fields": fields},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class RecurringApplicationCharge extends Base {
): Promise<RecurringApplicationCharge | null> {
const result = await this.baseFind<RecurringApplicationCharge>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
1 change: 1 addition & 0 deletions packages/apps/shopify-api/rest/admin/2022-10/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export class Redirect extends Base {
): Promise<Redirect | null> {
const result = await this.baseFind<Redirect>({
session: session,
requireIds: true,
urlIds: {"id": id},
params: {"fields": fields},
});
Expand Down
Loading
Loading