Skip to content

Commit 8d147da

Browse files
feat: add 'scope' prop to cl-identity-link to support private scopes
1 parent 4046b61 commit 8d147da

14 files changed

+184
-48
lines changed

packages/docs/stories/identity/cl-identity-link.stories.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const Template: StoryFn<Args> = (args) => {
1717
<cl-identity-link
1818
type=${args.type ?? nothing}
1919
target=${args.target ?? nothing}
20+
scope=${args.scope ?? nothing}
2021
>
2122
Identity link
2223
</cl-identity-link>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"reference": "customer_group_1",
4+
"name": "Employees"
5+
},
6+
{
7+
"reference": "customer_group_2",
8+
"name": "VIP Customers"
9+
}
10+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"reference": "customer_1_employees",
4+
"email": "drop-in.js@commercelayer.io",
5+
"password": "123456",
6+
"customer_group": "customer_group_1"
7+
}
8+
]

packages/drop-in/seed/data/markets.json

+30
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
"code": "europe",
99
"subscription_model": "subscription_model_1"
1010
},
11+
{
12+
"reference": "market_1_employees",
13+
"merchant": "merchant_1",
14+
"inventory_model": "inventory_model_1",
15+
"price_list": "price_list_1_employees",
16+
"name": "Europe (employees)",
17+
"code": "europe-employees",
18+
"subscription_model": "subscription_model_1",
19+
"customer_group": "customer_group_1"
20+
},
1121
{
1222
"reference": "market_2",
1323
"merchant": "merchant_1",
@@ -17,6 +27,16 @@
1727
"code": "usa",
1828
"subscription_model": "subscription_model_1"
1929
},
30+
{
31+
"reference": "market_2_employees",
32+
"merchant": "merchant_1",
33+
"inventory_model": "inventory_model_2",
34+
"price_list": "price_list_2_employees",
35+
"name": "USA (employees)",
36+
"code": "usa-employees",
37+
"subscription_model": "subscription_model_1",
38+
"customer_group": "customer_group_1"
39+
},
2040
{
2141
"reference": "market_3",
2242
"merchant": "merchant_1",
@@ -25,5 +45,15 @@
2545
"name": "UK",
2646
"code": "uk",
2747
"subscription_model": "subscription_model_1"
48+
},
49+
{
50+
"reference": "market_3_employees",
51+
"merchant": "merchant_1",
52+
"inventory_model": "inventory_model_1",
53+
"price_list": "price_list_3_employees",
54+
"name": "UK (employees)",
55+
"code": "uk-employees",
56+
"subscription_model": "subscription_model_1",
57+
"customer_group": "customer_group_1"
2858
}
2959
]

packages/drop-in/seed/data/payment_methods.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[
22
{
33
"reference": "payment_method_1",
4-
"market": "market_1",
4+
"currency_code": "EUR",
55
"payment_source_type": "WireTransfer",
66
"payment_gateway": "payment_gateway_1"
77
},
88
{
99
"reference": "payment_method_2",
10-
"market": "market_2",
10+
"currency_code": "USD",
1111
"payment_source_type": "WireTransfer",
1212
"payment_gateway": "payment_gateway_1"
1313
},
1414
{
1515
"reference": "payment_method_3",
16-
"market": "market_3",
16+
"currency_code": "GBP",
1717
"payment_source_type": "WireTransfer",
1818
"payment_gateway": "payment_gateway_1"
1919
}

packages/drop-in/seed/data/price_lists.json

+16
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,31 @@
44
"name": "EUR Price List",
55
"currency_code": "EUR"
66
},
7+
{
8+
"reference": "price_list_1_employees",
9+
"name": "EUR Price List (employees)",
10+
"currency_code": "EUR"
11+
},
712
{
813
"reference": "price_list_2",
914
"name": "USD Price List",
1015
"currency_code": "USD",
1116
"tax_included": false
1217
},
18+
{
19+
"reference": "price_list_2_employees",
20+
"name": "USD Price List (employees)",
21+
"currency_code": "USD",
22+
"tax_included": false
23+
},
1324
{
1425
"reference": "price_list_3",
1526
"name": "GBP Price List",
1627
"currency_code": "GBP"
28+
},
29+
{
30+
"reference": "price_list_3_employees",
31+
"name": "GBP Price List (employees)",
32+
"currency_code": "GBP"
1733
}
1834
]

packages/drop-in/seed/data/prices.json

+24-3
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,44 @@
8787
"reference": "price_8",
8888
"sku_code": "BACKPACKFFFFFF000000XXXX",
8989
"amount_cents": 9900,
90-
"compare_at_amount_cents": null,
90+
"compare_at_amount_cents": 9900,
9191
"price_list": "price_list_1"
9292
},
93+
{
94+
"reference": "price_8_employees",
95+
"sku_code": "BACKPACKFFFFFF000000XXXX",
96+
"amount_cents": 4900,
97+
"compare_at_amount_cents": 9900,
98+
"price_list": "price_list_1_employees"
99+
},
93100
{
94101
"reference": "price_258",
95102
"sku_code": "BACKPACKFFFFFF000000XXXX",
96103
"amount_cents": 11000,
97-
"compare_at_amount_cents": null,
104+
"compare_at_amount_cents": 11000,
98105
"price_list": "price_list_2"
99106
},
107+
{
108+
"reference": "price_258_employees",
109+
"sku_code": "BACKPACKFFFFFF000000XXXX",
110+
"amount_cents": 6000,
111+
"compare_at_amount_cents": 11000,
112+
"price_list": "price_list_2_employees"
113+
},
100114
{
101115
"reference": "price_508",
102116
"sku_code": "BACKPACKFFFFFF000000XXXX",
103117
"amount_cents": 9110,
104-
"compare_at_amount_cents": null,
118+
"compare_at_amount_cents": 9110,
105119
"price_list": "price_list_3"
106120
},
121+
{
122+
"reference": "price_508_employees",
123+
"sku_code": "BACKPACKFFFFFF000000XXXX",
124+
"amount_cents": 4000,
125+
"compare_at_amount_cents": 9110,
126+
"price_list": "price_list_3_employees"
127+
},
107128
{
108129
"reference": "price_21",
109130
"sku_code": "BOTT17OZFFFFFF000000XXXX",

packages/drop-in/seed/data/shipping_methods.json

+27
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,32 @@
4646
"name": "Standard Shipping",
4747
"price_amount_cents": 700,
4848
"free_over_amount_cents": 9900
49+
},
50+
{
51+
"reference": "shipping_method_1_employees",
52+
"market": "market_1_employees",
53+
"shipping_zone": "shipping_zone_1",
54+
"shipping_category": "shipping_category_1",
55+
"stock_location": "stock_location_1",
56+
"name": "Employee Free Shipping",
57+
"price_amount_cents": 0
58+
},
59+
{
60+
"reference": "shipping_method_2_employees",
61+
"market": "market_2_employees",
62+
"shipping_zone": "shipping_zone_2",
63+
"shipping_category": "shipping_category_1",
64+
"stock_location": "stock_location_2",
65+
"name": "Employee Free Shipping",
66+
"price_amount_cents": 0
67+
},
68+
{
69+
"reference": "shipping_method_3_employees",
70+
"market": "market_3_employees",
71+
"shipping_zone": "shipping_zone_1",
72+
"shipping_category": "shipping_category_1",
73+
"stock_location": "stock_location_1",
74+
"name": "Employee Free Shipping",
75+
"price_amount_cents": 0
4976
}
5077
]

packages/drop-in/seed/drop_in.json

+17-33
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,67 @@
11
[
22
{
33
"resourceType": "subscription_models",
4-
"referenceKeys": ["subscription_model_1"]
4+
"importAll": true
55
},
66
{
77
"resourceType": "addresses",
8-
"referenceKeys": ["address_1", "address_2"]
8+
"importAll": true
99
},
1010
{
1111
"resourceType": "merchants",
1212
"referenceKeys": ["merchant_1"]
1313
},
1414
{
1515
"resourceType": "stock_locations",
16-
"referenceKeys": ["stock_location_1", "stock_location_2"]
16+
"importAll": true
1717
},
1818
{
1919
"resourceType": "inventory_models",
20-
"referenceKeys": ["inventory_model_1", "inventory_model_2"]
20+
"importAll": true
2121
},
2222
{
2323
"resourceType": "inventory_stock_locations",
24-
"referenceKeys": [
25-
"inventory_stock_location_1",
26-
"inventory_stock_location_2",
27-
"inventory_stock_location_3",
28-
"inventory_stock_location_4"
29-
]
24+
"importAll": true
3025
},
3126
{
3227
"resourceType": "inventory_return_locations",
33-
"referenceKeys": [
34-
"inventory_return_location_1",
35-
"inventory_return_location_2",
36-
"inventory_return_location_3",
37-
"inventory_return_location_4"
38-
]
28+
"importAll": true
3929
},
4030
{
4131
"resourceType": "price_lists",
42-
"referenceKeys": ["price_list_1", "price_list_2", "price_list_3"]
32+
"importAll": true
33+
},
34+
{
35+
"resourceType": "customer_groups",
36+
"importAll": true
4337
},
4438
{
4539
"resourceType": "markets",
46-
"referenceKeys": ["market_1", "market_2", "market_3"]
40+
"importAll": true
4741
},
4842
{
4943
"resourceType": "shipping_categories",
50-
"referenceKeys": ["shipping_category_1", "shipping_category_2"]
44+
"importAll": true
5145
},
5246
{
5347
"resourceType": "shipping_zones",
54-
"referenceKeys": ["shipping_zone_1", "shipping_zone_2"]
48+
"importAll": true
5549
},
5650
{
5751
"resourceType": "shipping_methods",
58-
"referenceKeys": [
59-
"shipping_method_1",
60-
"shipping_method_2",
61-
"shipping_method_3",
62-
"shipping_method_4",
63-
"shipping_method_5"
64-
]
52+
"importAll": true
6553
},
6654
{
6755
"resourceType": "delivery_lead_times",
6856
"importAll": true
6957
},
7058
{
7159
"resourceType": "payment_gateways",
72-
"referenceKeys": ["payment_gateway_1"]
60+
"importAll": true
7361
},
7462
{
7563
"resourceType": "payment_methods",
76-
"referenceKeys": [
77-
"payment_method_1",
78-
"payment_method_2",
79-
"payment_method_3"
80-
]
64+
"importAll": true
8165
},
8266
{
8367
"resourceType": "skus",

packages/drop-in/src/apis/commercelayer/account.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export async function getMyAccountUrl(): Promise<string | undefined> {
1717

1818
export async function getIdentityUrl(
1919
type: "login" | "signup" | "logout",
20+
scope?: string,
2021
): Promise<string | undefined> {
2122
const config = getConfig()
2223

@@ -28,5 +29,5 @@ export async function getIdentityUrl(
2829

2930
return `${organizationConfig.links.identity}/${type}?clientId=${
3031
config.clientId
31-
}&scope=${config.scope}&returnUrl=${getClosestLocationHref()}`
32+
}&scope=${scope ?? config.scope}&publicScope=${config.scope}&returnUrl=${getClosestLocationHref()}`
3233
}

packages/drop-in/src/components.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export namespace Components {
103103
"target": "_self" | "_blank" | "_parent" | "_top";
104104
}
105105
interface ClIdentityLink {
106+
/**
107+
* String specified during the authentication flow to restrict the scope of the obtained access token to a market and/or stock location. Example: `market:code:usa` or `stock_location:code:eu` or `market:code:eu stock_location:code:eu` This is optional, as by default the scope is taken from the drop-in.js configuration. This property is particularly useful when you want to set a scope related to a private market (restricted to a customer group).
108+
*/
109+
"scope"?: string;
106110
/**
107111
* The browsing context in which to open the linked URL (a tab, a window, or an &lt;iframe&gt;).
108112
*/
@@ -335,6 +339,10 @@ declare namespace LocalJSX {
335339
"target"?: "_self" | "_blank" | "_parent" | "_top";
336340
}
337341
interface ClIdentityLink {
342+
/**
343+
* String specified during the authentication flow to restrict the scope of the obtained access token to a market and/or stock location. Example: `market:code:usa` or `stock_location:code:eu` or `market:code:eu stock_location:code:eu` This is optional, as by default the scope is taken from the drop-in.js configuration. This property is particularly useful when you want to set a scope related to a private market (restricted to a customer group).
344+
*/
345+
"scope"?: string;
338346
/**
339347
* The browsing context in which to open the linked URL (a tab, a window, or an &lt;iframe&gt;).
340348
*/

0 commit comments

Comments
 (0)