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

Commit 9eb1065

Browse files
authored
Merge pull request #1318 from nullndr/main
feat: add Shop.current method
2 parents d4f49b1 + de3bdb8 commit 9eb1065

File tree

13 files changed

+360
-0
lines changed

13 files changed

+360
-0
lines changed

.changeset/twenty-impalas-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@shopify/shopify-api": minor
3+
---
4+
5+
Add `Shop.current()` method to the REST resources

packages/shopify-api/rest/admin/2022-10/shop.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ export class Shop extends Base {
2828
}
2929
];
3030

31+
public static async current(
32+
{
33+
session,
34+
fields = null,
35+
...otherArgs
36+
}: AllArgs
37+
): Promise<Shop | null> {
38+
const result = await this.baseFind<Shop>({
39+
session: session,
40+
urlIds: {},
41+
params: {"fields": fields, ...otherArgs},
42+
});
43+
44+
return result.data ? result.data[0] : null;
45+
}
46+
3147
public static async all(
3248
{
3349
session,

packages/shopify-api/rest/admin/2023-01/shop.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ export class Shop extends Base {
2828
}
2929
];
3030

31+
public static async current(
32+
{
33+
session,
34+
fields = null,
35+
...otherArgs
36+
}: AllArgs
37+
): Promise<Shop | null> {
38+
const result = await this.baseFind<Shop>({
39+
session: session,
40+
urlIds: {},
41+
params: {"fields": fields, ...otherArgs},
42+
});
43+
44+
return result.data ? result.data[0] : null;
45+
}
46+
3147
public static async all(
3248
{
3349
session,

packages/shopify-api/rest/admin/2023-04/shop.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ export class Shop extends Base {
2828
}
2929
];
3030

31+
public static async current(
32+
{
33+
session,
34+
fields = null,
35+
...otherArgs
36+
}: AllArgs
37+
): Promise<Shop | null> {
38+
const result = await this.baseFind<Shop>({
39+
session: session,
40+
urlIds: {},
41+
params: {"fields": fields, ...otherArgs},
42+
});
43+
44+
return result.data ? result.data[0] : null;
45+
}
46+
3147
public static async all(
3248
{
3349
session,

packages/shopify-api/rest/admin/2023-07/shop.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ export class Shop extends Base {
2828
}
2929
];
3030

31+
public static async current(
32+
{
33+
session,
34+
fields = null,
35+
...otherArgs
36+
}: AllArgs
37+
): Promise<Shop | null> {
38+
const result = await this.baseFind<Shop>({
39+
session: session,
40+
urlIds: {},
41+
params: {"fields": fields, ...otherArgs},
42+
});
43+
44+
return result.data ? result.data[0] : null;
45+
}
46+
3147
public static async all(
3248
{
3349
session,

packages/shopify-api/rest/admin/2023-10/shop.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ export class Shop extends Base {
2828
}
2929
];
3030

31+
public static async current(
32+
{
33+
session,
34+
fields = null,
35+
...otherArgs
36+
}: AllArgs
37+
): Promise<Shop | null> {
38+
const result = await this.baseFind<Shop>({
39+
session: session,
40+
urlIds: {},
41+
params: {"fields": fields, ...otherArgs},
42+
});
43+
44+
return result.data ? result.data[0] : null;
45+
}
46+
3147
public static async all(
3248
{
3349
session,

packages/shopify-api/rest/admin/2024-01/shop.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,23 @@ export class Shop extends Base {
2828
}
2929
];
3030

31+
public static async current(
32+
{
33+
session,
34+
fields = null,
35+
...otherArgs
36+
}: AllArgs
37+
): Promise<Shop | null> {
38+
const result = await this.baseFind<Shop>({
39+
session: session,
40+
urlIds: {},
41+
params: {"fields": fields, ...otherArgs},
42+
});
43+
44+
return result.data ? result.data[0] : null;
45+
}
46+
47+
3148
public static async all(
3249
{
3350
session,

packages/shopify-api/rest/admin/__tests__/2022-10/shop.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,48 @@ describe('Shop resource', () => {
6363
data: undefined
6464
}).toMatchMadeHttpRequest();
6565
});
66+
67+
it('test_3', async () => {
68+
const shopify = shopifyApi(
69+
testConfig({apiVersion: ApiVersion.October22, restResources}),
70+
);
71+
72+
queueMockResponse(JSON.stringify({"shop": {"id": 548380009, "name": "John Smith Test Store", "email": "j.smith@example.com", "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": "customers@apple.com", "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}}));
73+
74+
await shopify.rest.Shop.current({
75+
session: session,
76+
});
77+
78+
expect({
79+
method: 'GET',
80+
domain,
81+
path: '/admin/api/2022-10/shop.json',
82+
query: '',
83+
headers,
84+
data: undefined
85+
}).toMatchMadeHttpRequest();
86+
});
87+
88+
it('test_4', async () => {
89+
const shopify = shopifyApi(
90+
testConfig({apiVersion: ApiVersion.October22, restResources}),
91+
);
92+
93+
queueMockResponse(JSON.stringify({"shop": {"province": "California", "country": "US", "address1": "1 Infinite Loop", "city": "Cupertino", "address2": "Suite 100"}}));
94+
95+
await shopify.rest.Shop.current({
96+
session: session,
97+
fields: "address1,address2,city,province,country",
98+
});
99+
100+
expect({
101+
method: 'GET',
102+
domain,
103+
path: '/admin/api/2022-10/shop.json',
104+
query: 'fields=address1%2Caddress2%2Ccity%2Cprovince%2Ccountry',
105+
headers,
106+
data: undefined
107+
}).toMatchMadeHttpRequest();
108+
});
66109

67110
});

packages/shopify-api/rest/admin/__tests__/2023-01/shop.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,47 @@ describe('Shop resource', () => {
6464
}).toMatchMadeHttpRequest();
6565
});
6666

67+
it('test_3', async () => {
68+
const shopify = shopifyApi(
69+
testConfig({apiVersion: ApiVersion.January23, restResources}),
70+
);
71+
72+
queueMockResponse(JSON.stringify({"shop": {"id": 548380009, "name": "John Smith Test Store", "email": "j.smith@example.com", "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": "customers@apple.com", "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}}));
73+
74+
await shopify.rest.Shop.current({
75+
session: session,
76+
});
77+
78+
expect({
79+
method: 'GET',
80+
domain,
81+
path: '/admin/api/2023-01/shop.json',
82+
query: '',
83+
headers,
84+
data: undefined
85+
}).toMatchMadeHttpRequest();
86+
});
87+
88+
it('test_4', async () => {
89+
const shopify = shopifyApi(
90+
testConfig({apiVersion: ApiVersion.January23, restResources}),
91+
);
92+
93+
queueMockResponse(JSON.stringify({"shop": {"province": "California", "country": "US", "address1": "1 Infinite Loop", "city": "Cupertino", "address2": "Suite 100"}}));
94+
95+
await shopify.rest.Shop.current({
96+
session: session,
97+
fields: "address1,address2,city,province,country",
98+
});
99+
100+
expect({
101+
method: 'GET',
102+
domain,
103+
path: '/admin/api/2023-01/shop.json',
104+
query: 'fields=address1%2Caddress2%2Ccity%2Cprovince%2Ccountry',
105+
headers,
106+
data: undefined
107+
}).toMatchMadeHttpRequest();
108+
});
109+
67110
});

packages/shopify-api/rest/admin/__tests__/2023-04/shop.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,47 @@ describe('Shop resource', () => {
6464
}).toMatchMadeHttpRequest();
6565
});
6666

67+
it('test_3', async () => {
68+
const shopify = shopifyApi(
69+
testConfig({apiVersion: ApiVersion.April23, restResources}),
70+
);
71+
72+
queueMockResponse(JSON.stringify({"shop": {"id": 548380009, "name": "John Smith Test Store", "email": "j.smith@example.com", "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": "customers@apple.com", "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}}));
73+
74+
await shopify.rest.Shop.current({
75+
session: session,
76+
});
77+
78+
expect({
79+
method: 'GET',
80+
domain,
81+
path: '/admin/api/2023-04/shop.json',
82+
query: '',
83+
headers,
84+
data: undefined
85+
}).toMatchMadeHttpRequest();
86+
});
87+
88+
it('test_4', async () => {
89+
const shopify = shopifyApi(
90+
testConfig({apiVersion: ApiVersion.April23, restResources}),
91+
);
92+
93+
queueMockResponse(JSON.stringify({"shop": {"province": "California", "country": "US", "address1": "1 Infinite Loop", "city": "Cupertino", "address2": "Suite 100"}}));
94+
95+
await shopify.rest.Shop.current({
96+
session: session,
97+
fields: "address1,address2,city,province,country",
98+
});
99+
100+
expect({
101+
method: 'GET',
102+
domain,
103+
path: '/admin/api/2023-04/shop.json',
104+
query: 'fields=address1%2Caddress2%2Ccity%2Cprovince%2Ccountry',
105+
headers,
106+
data: undefined
107+
}).toMatchMadeHttpRequest();
108+
});
109+
67110
});

0 commit comments

Comments
 (0)