Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1318 from nullndr/main
Browse files Browse the repository at this point in the history
feat: add Shop.current method
  • Loading branch information
paulomarg authored Apr 3, 2024
2 parents d4f49b1 + de3bdb8 commit 9eb1065
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-impalas-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopify/shopify-api": minor
---

Add `Shop.current()` method to the REST resources
16 changes: 16 additions & 0 deletions packages/shopify-api/rest/admin/2022-10/shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export class Shop extends Base {
}
];

public static async current(
{
session,
fields = null,
...otherArgs
}: AllArgs
): Promise<Shop | null> {
const result = await this.baseFind<Shop>({
session: session,
urlIds: {},
params: {"fields": fields, ...otherArgs},
});

return result.data ? result.data[0] : null;
}

public static async all(
{
session,
Expand Down
16 changes: 16 additions & 0 deletions packages/shopify-api/rest/admin/2023-01/shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export class Shop extends Base {
}
];

public static async current(
{
session,
fields = null,
...otherArgs
}: AllArgs
): Promise<Shop | null> {
const result = await this.baseFind<Shop>({
session: session,
urlIds: {},
params: {"fields": fields, ...otherArgs},
});

return result.data ? result.data[0] : null;
}

public static async all(
{
session,
Expand Down
16 changes: 16 additions & 0 deletions packages/shopify-api/rest/admin/2023-04/shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export class Shop extends Base {
}
];

public static async current(
{
session,
fields = null,
...otherArgs
}: AllArgs
): Promise<Shop | null> {
const result = await this.baseFind<Shop>({
session: session,
urlIds: {},
params: {"fields": fields, ...otherArgs},
});

return result.data ? result.data[0] : null;
}

public static async all(
{
session,
Expand Down
16 changes: 16 additions & 0 deletions packages/shopify-api/rest/admin/2023-07/shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export class Shop extends Base {
}
];

public static async current(
{
session,
fields = null,
...otherArgs
}: AllArgs
): Promise<Shop | null> {
const result = await this.baseFind<Shop>({
session: session,
urlIds: {},
params: {"fields": fields, ...otherArgs},
});

return result.data ? result.data[0] : null;
}

public static async all(
{
session,
Expand Down
16 changes: 16 additions & 0 deletions packages/shopify-api/rest/admin/2023-10/shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export class Shop extends Base {
}
];

public static async current(
{
session,
fields = null,
...otherArgs
}: AllArgs
): Promise<Shop | null> {
const result = await this.baseFind<Shop>({
session: session,
urlIds: {},
params: {"fields": fields, ...otherArgs},
});

return result.data ? result.data[0] : null;
}

public static async all(
{
session,
Expand Down
17 changes: 17 additions & 0 deletions packages/shopify-api/rest/admin/2024-01/shop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ export class Shop extends Base {
}
];

public static async current(
{
session,
fields = null,
...otherArgs
}: AllArgs
): Promise<Shop | null> {
const result = await this.baseFind<Shop>({
session: session,
urlIds: {},
params: {"fields": fields, ...otherArgs},
});

return result.data ? result.data[0] : null;
}


public static async all(
{
session,
Expand Down
43 changes: 43 additions & 0 deletions packages/shopify-api/rest/admin/__tests__/2022-10/shop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,48 @@ describe('Shop resource', () => {
data: undefined
}).toMatchMadeHttpRequest();
});

it('test_3', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.October22, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"id": 548380009, "name": "John Smith Test Store", "email": "[email protected]", "domain": "shop.apple.com", "province": "California", "country": "US", "address1": "1 Infinite Loop", "zip": "95014", "city": "Cupertino", "source": null, "phone": "1231231234", "latitude": 45.45, "longitude": -75.43, "primary_locale": "en", "address2": "Suite 100", "created_at": "2007-12-31T19:00:00-05:00", "updated_at": "2023-10-03T13:18:39-04:00", "country_code": "US", "country_name": "United States", "currency": "USD", "customer_email": "[email protected]", "timezone": "(GMT-05:00) Eastern Time (US & Canada)", "iana_timezone": "America/New_York", "shop_owner": "John Smith", "money_format": "${{amount}}", "money_with_currency_format": "${{amount}} USD", "weight_unit": "lb", "province_code": "CA", "taxes_included": null, "auto_configure_tax_inclusivity": null, "tax_shipping": null, "county_taxes": true, "plan_display_name": "Shopify Plus", "plan_name": "enterprise", "has_discounts": true, "has_gift_cards": true, "myshopify_domain": "jsmith.myshopify.com", "google_apps_domain": null, "google_apps_login_enabled": null, "money_in_emails_format": "${{amount}}", "money_with_currency_in_emails_format": "${{amount}} USD", "eligible_for_payments": true, "requires_extra_payments_agreement": false, "password_enabled": false, "has_storefront": true, "finances": true, "primary_location_id": 655441491, "checkout_api_supported": true, "multi_location_enabled": true, "setup_required": false, "pre_launch_enabled": false, "enabled_presentment_currencies": ["USD"], "transactional_sms_disabled": false, "marketing_sms_consent_enabled_at_checkout": false}}));

await shopify.rest.Shop.current({
session: session,
});

expect({
method: 'GET',
domain,
path: '/admin/api/2022-10/shop.json',
query: '',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

it('test_4', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.October22, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"province": "California", "country": "US", "address1": "1 Infinite Loop", "city": "Cupertino", "address2": "Suite 100"}}));

await shopify.rest.Shop.current({
session: session,
fields: "address1,address2,city,province,country",
});

expect({
method: 'GET',
domain,
path: '/admin/api/2022-10/shop.json',
query: 'fields=address1%2Caddress2%2Ccity%2Cprovince%2Ccountry',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

});
43 changes: 43 additions & 0 deletions packages/shopify-api/rest/admin/__tests__/2023-01/shop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,47 @@ describe('Shop resource', () => {
}).toMatchMadeHttpRequest();
});

it('test_3', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.January23, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"id": 548380009, "name": "John Smith Test Store", "email": "[email protected]", "domain": "shop.apple.com", "province": "California", "country": "US", "address1": "1 Infinite Loop", "zip": "95014", "city": "Cupertino", "source": null, "phone": "1231231234", "latitude": 45.45, "longitude": -75.43, "primary_locale": "en", "address2": "Suite 100", "created_at": "2007-12-31T19:00:00-05:00", "updated_at": "2024-01-02T09:00:54-05:00", "country_code": "US", "country_name": "United States", "currency": "USD", "customer_email": "[email protected]", "timezone": "(GMT-05:00) Eastern Time (US & Canada)", "iana_timezone": "America/New_York", "shop_owner": "John Smith", "money_format": "${{amount}}", "money_with_currency_format": "${{amount}} USD", "weight_unit": "lb", "province_code": "CA", "taxes_included": null, "auto_configure_tax_inclusivity": null, "tax_shipping": null, "county_taxes": true, "plan_display_name": "Shopify Plus", "plan_name": "enterprise", "has_discounts": true, "has_gift_cards": true, "myshopify_domain": "jsmith.myshopify.com", "google_apps_domain": null, "google_apps_login_enabled": null, "money_in_emails_format": "${{amount}}", "money_with_currency_in_emails_format": "${{amount}} USD", "eligible_for_payments": true, "requires_extra_payments_agreement": false, "password_enabled": false, "has_storefront": true, "finances": true, "primary_location_id": 655441491, "checkout_api_supported": true, "multi_location_enabled": true, "setup_required": false, "pre_launch_enabled": false, "enabled_presentment_currencies": ["USD"], "transactional_sms_disabled": false, "marketing_sms_consent_enabled_at_checkout": false}}));

await shopify.rest.Shop.current({
session: session,
});

expect({
method: 'GET',
domain,
path: '/admin/api/2023-01/shop.json',
query: '',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

it('test_4', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.January23, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"province": "California", "country": "US", "address1": "1 Infinite Loop", "city": "Cupertino", "address2": "Suite 100"}}));

await shopify.rest.Shop.current({
session: session,
fields: "address1,address2,city,province,country",
});

expect({
method: 'GET',
domain,
path: '/admin/api/2023-01/shop.json',
query: 'fields=address1%2Caddress2%2Ccity%2Cprovince%2Ccountry',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

});
43 changes: 43 additions & 0 deletions packages/shopify-api/rest/admin/__tests__/2023-04/shop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,47 @@ describe('Shop resource', () => {
}).toMatchMadeHttpRequest();
});

it('test_3', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.April23, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"id": 548380009, "name": "John Smith Test Store", "email": "[email protected]", "domain": "shop.apple.com", "province": "California", "country": "US", "address1": "1 Infinite Loop", "zip": "95014", "city": "Cupertino", "source": null, "phone": "1231231234", "latitude": 45.45, "longitude": -75.43, "primary_locale": "en", "address2": "Suite 100", "created_at": "2007-12-31T19:00:00-05:00", "updated_at": "2024-01-02T09:00:54-05:00", "country_code": "US", "country_name": "United States", "currency": "USD", "customer_email": "[email protected]", "timezone": "(GMT-05:00) Eastern Time (US & Canada)", "iana_timezone": "America/New_York", "shop_owner": "John Smith", "money_format": "${{amount}}", "money_with_currency_format": "${{amount}} USD", "weight_unit": "lb", "province_code": "CA", "taxes_included": null, "auto_configure_tax_inclusivity": null, "tax_shipping": null, "county_taxes": true, "plan_display_name": "Shopify Plus", "plan_name": "enterprise", "has_discounts": true, "has_gift_cards": true, "myshopify_domain": "jsmith.myshopify.com", "google_apps_domain": null, "google_apps_login_enabled": null, "money_in_emails_format": "${{amount}}", "money_with_currency_in_emails_format": "${{amount}} USD", "eligible_for_payments": true, "requires_extra_payments_agreement": false, "password_enabled": false, "has_storefront": true, "finances": true, "primary_location_id": 655441491, "checkout_api_supported": true, "multi_location_enabled": true, "setup_required": false, "pre_launch_enabled": false, "enabled_presentment_currencies": ["USD"], "transactional_sms_disabled": false, "marketing_sms_consent_enabled_at_checkout": false}}));

await shopify.rest.Shop.current({
session: session,
});

expect({
method: 'GET',
domain,
path: '/admin/api/2023-04/shop.json',
query: '',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

it('test_4', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.April23, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"province": "California", "country": "US", "address1": "1 Infinite Loop", "city": "Cupertino", "address2": "Suite 100"}}));

await shopify.rest.Shop.current({
session: session,
fields: "address1,address2,city,province,country",
});

expect({
method: 'GET',
domain,
path: '/admin/api/2023-04/shop.json',
query: 'fields=address1%2Caddress2%2Ccity%2Cprovince%2Ccountry',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

});
43 changes: 43 additions & 0 deletions packages/shopify-api/rest/admin/__tests__/2023-07/shop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,47 @@ describe('Shop resource', () => {
}).toMatchMadeHttpRequest();
});

it('test_3', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.July23, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"id": 548380009, "name": "John Smith Test Store", "email": "[email protected]", "domain": "shop.apple.com", "province": "California", "country": "US", "address1": "1 Infinite Loop", "zip": "95014", "city": "Cupertino", "source": null, "phone": "1231231234", "latitude": 45.45, "longitude": -75.43, "primary_locale": "en", "address2": "Suite 100", "created_at": "2007-12-31T19:00:00-05:00", "updated_at": "2024-01-02T09:00:54-05:00", "country_code": "US", "country_name": "United States", "currency": "USD", "customer_email": "[email protected]", "timezone": "(GMT-05:00) Eastern Time (US & Canada)", "iana_timezone": "America/New_York", "shop_owner": "John Smith", "money_format": "${{amount}}", "money_with_currency_format": "${{amount}} USD", "weight_unit": "lb", "province_code": "CA", "taxes_included": null, "auto_configure_tax_inclusivity": null, "tax_shipping": null, "county_taxes": true, "plan_display_name": "Shopify Plus", "plan_name": "enterprise", "has_discounts": true, "has_gift_cards": true, "myshopify_domain": "jsmith.myshopify.com", "google_apps_domain": null, "google_apps_login_enabled": null, "money_in_emails_format": "${{amount}}", "money_with_currency_in_emails_format": "${{amount}} USD", "eligible_for_payments": true, "requires_extra_payments_agreement": false, "password_enabled": false, "has_storefront": true, "finances": true, "primary_location_id": 655441491, "checkout_api_supported": true, "multi_location_enabled": true, "setup_required": false, "pre_launch_enabled": false, "enabled_presentment_currencies": ["USD"], "transactional_sms_disabled": false, "marketing_sms_consent_enabled_at_checkout": false}}));

await shopify.rest.Shop.current({
session: session,
});

expect({
method: 'GET',
domain,
path: '/admin/api/2023-07/shop.json',
query: '',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

it('test_4', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.July23, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"province": "California", "country": "US", "address1": "1 Infinite Loop", "city": "Cupertino", "address2": "Suite 100"}}));

await shopify.rest.Shop.current({
session: session,
fields: "address1,address2,city,province,country",
});

expect({
method: 'GET',
domain,
path: '/admin/api/2023-07/shop.json',
query: 'fields=address1%2Caddress2%2Ccity%2Cprovince%2Ccountry',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

});
43 changes: 43 additions & 0 deletions packages/shopify-api/rest/admin/__tests__/2023-10/shop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,47 @@ describe('Shop resource', () => {
}).toMatchMadeHttpRequest();
});

it('test_3', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.October23, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"id": 548380009, "name": "John Smith Test Store", "email": "[email protected]", "domain": "shop.apple.com", "province": "California", "country": "US", "address1": "1 Infinite Loop", "zip": "95014", "city": "Cupertino", "source": null, "phone": "1231231234", "latitude": 45.45, "longitude": -75.43, "primary_locale": "en", "address2": "Suite 100", "created_at": "2007-12-31T19:00:00-05:00", "updated_at": "2024-01-02T09:00:54-05:00", "country_code": "US", "country_name": "United States", "currency": "USD", "customer_email": "[email protected]", "timezone": "(GMT-05:00) Eastern Time (US & Canada)", "iana_timezone": "America/New_York", "shop_owner": "John Smith", "money_format": "${{amount}}", "money_with_currency_format": "${{amount}} USD", "weight_unit": "lb", "province_code": "CA", "taxes_included": null, "auto_configure_tax_inclusivity": null, "tax_shipping": null, "county_taxes": true, "plan_display_name": "Shopify Plus", "plan_name": "enterprise", "has_discounts": true, "has_gift_cards": true, "myshopify_domain": "jsmith.myshopify.com", "google_apps_domain": null, "google_apps_login_enabled": null, "money_in_emails_format": "${{amount}}", "money_with_currency_in_emails_format": "${{amount}} USD", "eligible_for_payments": true, "requires_extra_payments_agreement": false, "password_enabled": false, "has_storefront": true, "finances": true, "primary_location_id": 655441491, "checkout_api_supported": true, "multi_location_enabled": true, "setup_required": false, "pre_launch_enabled": false, "enabled_presentment_currencies": ["USD"], "transactional_sms_disabled": false, "marketing_sms_consent_enabled_at_checkout": false}}));

await shopify.rest.Shop.current({
session: session,
});

expect({
method: 'GET',
domain,
path: '/admin/api/2023-10/shop.json',
query: '',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

it('test_4', async () => {
const shopify = shopifyApi(
testConfig({apiVersion: ApiVersion.October23, restResources}),
);

queueMockResponse(JSON.stringify({"shop": {"province": "California", "country": "US", "address1": "1 Infinite Loop", "city": "Cupertino", "address2": "Suite 100"}}));

await shopify.rest.Shop.current({
session: session,
fields: "address1,address2,city,province,country",
});

expect({
method: 'GET',
domain,
path: '/admin/api/2023-10/shop.json',
query: 'fields=address1%2Caddress2%2Ccity%2Cprovince%2Ccountry',
headers,
data: undefined
}).toMatchMadeHttpRequest();
});

});
Loading

0 comments on commit 9eb1065

Please sign in to comment.