@shopify/shop-minis-cli 0.0.142 → 0.0.143
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/app/index.js +1 -1
- package/build/commands/app/index.js.map +1 -1
- package/build/commands/setup/index.js +86 -77
- package/build/commands/setup/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/__template_getting_started/src/screens/HomeScreen.tsx +15 -21
- package/build/commands/setup/create.d.ts +0 -3
- package/build/commands/setup/create.js +0 -100
- package/build/commands/setup/create.js.map +0 -1
|
@@ -9,6 +9,6 @@ export function loadCommand(parentProgram) {
|
|
|
9
9
|
.addCommand(listCommand)
|
|
10
10
|
.addCommand(linkCommand)
|
|
11
11
|
.addCommand(unlinkCommand);
|
|
12
|
-
parentProgram.addCommand(command
|
|
12
|
+
parentProgram.addCommand(command);
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,WAAW,CAAA;AAChD,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,WAAW,CAAA;AAChD,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,aAAa,CAAA;AAEpD,MAAM,UAAU,WAAW,CAAC,aAAsB;IAChD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE;SAC1B,IAAI,CAAC,KAAK,CAAC;SACX,WAAW,CAAC,kDAAkD,CAAC;SAC/D,UAAU,CAAC,WAAW,CAAC;SACvB,UAAU,CAAC,WAAW,CAAC;SACvB,UAAU,CAAC,aAAa,CAAC,CAAA;IAE5B,aAAa,CAAC,UAAU,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AAEjC,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,WAAW,CAAA;AAChD,OAAO,EAAC,OAAO,IAAI,WAAW,EAAC,MAAM,WAAW,CAAA;AAChD,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,aAAa,CAAA;AAEpD,MAAM,UAAU,WAAW,CAAC,aAAsB;IAChD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE;SAC1B,IAAI,CAAC,KAAK,CAAC;SACX,WAAW,CAAC,kDAAkD,CAAC;SAC/D,UAAU,CAAC,WAAW,CAAC;SACvB,UAAU,CAAC,WAAW,CAAC;SACvB,UAAU,CAAC,aAAa,CAAC,CAAA;IAE5B,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -1,92 +1,101 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
import { renderSelectPrompt, renderSuccess, renderError, } from '@shopify/cli-kit/node/ui';
|
|
5
|
+
import { AbortError, handler as handleError } from '@shopify/cli-kit/node/error';
|
|
6
|
+
import { getMiniManifest } from '../../utils/minis-manifest.js';
|
|
7
|
+
import { fetchAllOrgs, token } from '../../data/partners/query.js';
|
|
8
|
+
import { miniCreate } from '../../data/mini-create.js';
|
|
9
|
+
import { syncManifest } from '../../utils/sync-manifest.js';
|
|
10
|
+
async function loginAndSetup() {
|
|
11
|
+
const envFilePath = path.join(process.cwd(), '.env');
|
|
12
|
+
let envFileContents = '';
|
|
13
|
+
if (fs.existsSync(envFilePath)) {
|
|
14
|
+
envFileContents = fs.readFileSync(envFilePath, 'utf-8');
|
|
15
|
+
// Prevent creating a new Mini if SHOP_MINIS_API_KEY is already set
|
|
16
|
+
if (envFileContents.includes('SHOP_MINIS_API_KEY')) {
|
|
17
|
+
renderError({
|
|
18
|
+
headline: 'Mini already set up',
|
|
19
|
+
body: ['An API key is already configured in `.env`.'],
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const { handle: miniHandle, name: miniName } = getMiniManifest();
|
|
25
|
+
if (miniHandle) {
|
|
26
|
+
// Prevent creating a new Mini if manifest.json is already set
|
|
27
|
+
renderError({
|
|
28
|
+
headline: 'Mini already set up',
|
|
29
|
+
body: [
|
|
30
|
+
'Configuration already exists in `manifest.json`. Please set',
|
|
31
|
+
{
|
|
32
|
+
bold: 'SHOP_MINIS_API_KEY',
|
|
33
|
+
},
|
|
34
|
+
'in `.env` to set up this Mini.',
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Select the organization
|
|
40
|
+
const organizations = await fetchAllOrgs();
|
|
41
|
+
const organizationId = await renderSelectPrompt({
|
|
42
|
+
message: 'Select your organization',
|
|
43
|
+
choices: organizations.map(org => ({
|
|
44
|
+
label: org.businessName,
|
|
45
|
+
value: org.id,
|
|
46
|
+
})),
|
|
47
|
+
});
|
|
48
|
+
const result = await miniCreate({
|
|
49
|
+
name: miniName,
|
|
50
|
+
organizationId: `gid://shopify/Organization/${organizationId}`,
|
|
51
|
+
partnersAccessToken: await token(),
|
|
52
|
+
});
|
|
53
|
+
if (result.userErrors.length > 0) {
|
|
54
|
+
if (result.userErrors.length === 1) {
|
|
55
|
+
if (result.userErrors[0].code === 'TOO_MANY_MINIS') {
|
|
56
|
+
renderError({
|
|
57
|
+
body: `You have reached the maximum number of Shop Minis for your organization. Please contact support to request more.`,
|
|
58
|
+
});
|
|
59
|
+
process.exit(0);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new AbortError(result.userErrors[0].message);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new AbortError(result.userErrors.map(({ message }) => message).join('\n'));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Append the new SHOP_MINIS_API_KEY to the .env file
|
|
70
|
+
envFileContents += `\nSHOP_MINIS_API_KEY=${result.token}`;
|
|
71
|
+
fs.writeFileSync(envFilePath, envFileContents, {
|
|
72
|
+
encoding: 'utf-8',
|
|
73
|
+
});
|
|
74
|
+
// Sync the manifest
|
|
75
|
+
if (result.mini) {
|
|
76
|
+
syncManifest({ handle: result.mini.handle });
|
|
77
|
+
renderSuccess({
|
|
78
|
+
headline: 'Shop Mini created',
|
|
79
|
+
body: [
|
|
80
|
+
'Shop Mini with handle',
|
|
81
|
+
{
|
|
82
|
+
bold: result.mini.handle,
|
|
83
|
+
},
|
|
84
|
+
'has been created.',
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
}
|
|
15
88
|
}
|
|
16
89
|
export function loadCommand(parentProgram) {
|
|
17
90
|
const command = new Command()
|
|
18
91
|
.name('setup')
|
|
19
92
|
.description('Set up a new Shop Mini')
|
|
20
|
-
.addCommand(createCommand, { hidden: true }) // TODO: remove hidden
|
|
21
93
|
.action(async () => {
|
|
22
|
-
const { confirmInvitationEmail } = await prompts.prompt({
|
|
23
|
-
type: 'confirm',
|
|
24
|
-
name: 'confirmInvitationEmail',
|
|
25
|
-
message: 'To begin the setup process, please confirm that you have received an invitation email from the Shop Minis team. If you have not, please apply to join the early access program at https://shop.app/minis/apply/.',
|
|
26
|
-
}, { onCancel });
|
|
27
|
-
if (!confirmInvitationEmail) {
|
|
28
|
-
onCancel();
|
|
29
|
-
}
|
|
30
|
-
if (SHOP_MINIS_ADMIN_API_KEY) {
|
|
31
|
-
const { confirmOverwrite } = await prompts.prompt({
|
|
32
|
-
type: 'confirm',
|
|
33
|
-
name: 'confirmOverwrite',
|
|
34
|
-
message: 'This command will overwrite your exiting Shop Minis Admin API Key. If you have an existing .env file, it will be backed up as .env.bak. Do you want to continue?',
|
|
35
|
-
}, { onCancel });
|
|
36
|
-
if (!confirmOverwrite) {
|
|
37
|
-
onCancel();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const response = await prompts.prompt({
|
|
41
|
-
type: 'text',
|
|
42
|
-
name: 'invitationCode',
|
|
43
|
-
message: `Provide the invitation code from the welcome email:`,
|
|
44
|
-
}, { onCancel });
|
|
45
|
-
const token = await wrapWithLoadingIndicator(acceptInvitation({ code: response.invitationCode }), {
|
|
46
|
-
loadingMessage: 'Fetching API key...',
|
|
47
|
-
successMessage: 'API key fetched',
|
|
48
|
-
});
|
|
49
|
-
const envFilePath = path.join(process.cwd(), '.env');
|
|
50
|
-
if (fs.existsSync(envFilePath)) {
|
|
51
|
-
fs.copyFileSync(envFilePath, `${envFilePath}.bak`);
|
|
52
|
-
}
|
|
53
|
-
fs.writeFileSync(envFilePath, `SHOP_MINIS_API_KEY=${token}\n`, {
|
|
54
|
-
encoding: 'utf-8',
|
|
55
|
-
});
|
|
56
94
|
try {
|
|
57
|
-
|
|
58
|
-
Authorization: `Bearer ${token}`,
|
|
59
|
-
});
|
|
60
|
-
if (miniInfo) {
|
|
61
|
-
const manifestJsonPath = path.join(getMiniBasePath(), 'src/manifest.json');
|
|
62
|
-
const manifestJsonString = fs.readFileSync(manifestJsonPath, {
|
|
63
|
-
encoding: 'utf-8',
|
|
64
|
-
});
|
|
65
|
-
const manifestJson = JSON.parse(manifestJsonString) || {};
|
|
66
|
-
manifestJson.handle = miniInfo.handle;
|
|
67
|
-
if (miniInfo.productionShopifyAppId) {
|
|
68
|
-
manifestJson.shopify_apps ||= {};
|
|
69
|
-
manifestJson.shopify_apps.production = extractIdFromGID(miniInfo.productionShopifyAppId);
|
|
70
|
-
}
|
|
71
|
-
if (miniInfo.developmentShopifyAppIds.length > 0) {
|
|
72
|
-
manifestJson.shopify_apps ||= {};
|
|
73
|
-
manifestJson.shopify_apps.development =
|
|
74
|
-
miniInfo.developmentShopifyAppIds.map(id => extractIdFromGID(id));
|
|
75
|
-
}
|
|
76
|
-
fs.writeFileSync(manifestJsonPath, `${JSON.stringify(manifestJson, null, 2)}\n`, {
|
|
77
|
-
encoding: 'utf-8',
|
|
78
|
-
});
|
|
79
|
-
console.log('Your Shop Mini has been set up.');
|
|
80
|
-
}
|
|
95
|
+
await loginAndSetup();
|
|
81
96
|
}
|
|
82
97
|
catch (error) {
|
|
83
|
-
|
|
84
|
-
console.error('Invalid invitation code.');
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
console.error('An error occurred.');
|
|
88
|
-
console.error(error);
|
|
89
|
-
}
|
|
98
|
+
handleError(error);
|
|
90
99
|
}
|
|
91
100
|
});
|
|
92
101
|
parentProgram.addCommand(command);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/setup/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,SAAS,CAAA;AAExB,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/setup/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,SAAS,CAAA;AAExB,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,WAAW,GACZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAC,UAAU,EAAE,OAAO,IAAI,WAAW,EAAC,MAAM,6BAA6B,CAAA;AAE9E,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAC,YAAY,EAAE,KAAK,EAAC,MAA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CAAC,CAAA;KACH;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,aAAsB;IAChD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE;SAC1B,IAAI,CAAC,OAAO,CAAC;SACb,WAAW,CAAC,wBAAwB,CAAC;SACrC,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,IAAI;YACF,MAAM,aAAa,EAAE,CAAA;SACtB;QAAC,OAAO,KAAK,EAAE;YACd,WAAW,CAAC,KAAK,CAAC,CAAA;SACnB;IACH,CAAC,CAAC,CAAA;IAEJ,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;AACnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
useTheme,
|
|
13
13
|
Button,
|
|
14
14
|
TextField,
|
|
15
|
-
|
|
15
|
+
RadioButton,
|
|
16
16
|
} from '@shopify/shop-minis-platform-sdk'
|
|
17
17
|
|
|
18
18
|
import {RootStackParamList} from '../types/screens'
|
|
@@ -32,7 +32,9 @@ export function HomeScreen() {
|
|
|
32
32
|
'gid://shopify/Shop/62104633599'
|
|
33
33
|
)
|
|
34
34
|
|
|
35
|
-
const [
|
|
35
|
+
const radioButtonOptions = ['Option A', 'Option B', 'Option C']
|
|
36
|
+
|
|
37
|
+
const [selectedOption, setSelectedOption] = useState(radioButtonOptions[0])
|
|
36
38
|
|
|
37
39
|
return (
|
|
38
40
|
<SafeAreaView
|
|
@@ -91,25 +93,17 @@ export function HomeScreen() {
|
|
|
91
93
|
<Box marginBottom="s">
|
|
92
94
|
<TextField placeholder="Text input" />
|
|
93
95
|
</Box>
|
|
94
|
-
<
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
{label: 'Red', value: 'Red'},
|
|
106
|
-
{label: 'Green', value: 'Green'},
|
|
107
|
-
{label: 'Blue', value: 'Blue'},
|
|
108
|
-
]}
|
|
109
|
-
handleDismiss={() => setPickerVisible(false)}
|
|
110
|
-
headerText="Select a color"
|
|
111
|
-
/>
|
|
112
|
-
) : null}
|
|
96
|
+
<Text>Radio buttons</Text>
|
|
97
|
+
{radioButtonOptions.map(option => (
|
|
98
|
+
<Box key={option} marginVertical="xs">
|
|
99
|
+
<RadioButton
|
|
100
|
+
variant="tertiary"
|
|
101
|
+
text={option}
|
|
102
|
+
active={selectedOption === option}
|
|
103
|
+
onPress={() => setSelectedOption(option)}
|
|
104
|
+
/>
|
|
105
|
+
</Box>
|
|
106
|
+
))}
|
|
113
107
|
<Text marginBottom="s">
|
|
114
108
|
Ready for more? Let's explore native capabilities in the
|
|
115
109
|
screen.
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import { renderSelectPrompt, renderSuccess, renderError, } from '@shopify/cli-kit/node/ui';
|
|
5
|
-
import { AbortError, handler as handleError } from '@shopify/cli-kit/node/error';
|
|
6
|
-
import { fetchAllOrgs, token } from '../../data/partners/query.js';
|
|
7
|
-
import { miniCreate } from '../../data/mini-create.js';
|
|
8
|
-
import { getMiniManifest } from '../../utils/minis-manifest.js';
|
|
9
|
-
import { syncManifest } from '../../utils/sync-manifest.js';
|
|
10
|
-
export async function loginAndSetup() {
|
|
11
|
-
const envFilePath = path.join(process.cwd(), '.env');
|
|
12
|
-
let envFileContents = '';
|
|
13
|
-
if (fs.existsSync(envFilePath)) {
|
|
14
|
-
envFileContents = fs.readFileSync(envFilePath, 'utf-8');
|
|
15
|
-
// Prevent creating a new Mini if SHOP_MINIS_API_KEY is already set
|
|
16
|
-
if (envFileContents.includes('SHOP_MINIS_API_KEY')) {
|
|
17
|
-
renderError({
|
|
18
|
-
headline: 'Mini already set up',
|
|
19
|
-
body: ['An API key is already configured in `.env`.'],
|
|
20
|
-
});
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const { handle: miniHandle, name: miniName } = getMiniManifest();
|
|
25
|
-
if (miniHandle) {
|
|
26
|
-
// Prevent creating a new Mini if manifest.json is already set
|
|
27
|
-
renderError({
|
|
28
|
-
headline: 'Mini already set up',
|
|
29
|
-
body: [
|
|
30
|
-
'Configuration already exists in `manifest.json`. Please set',
|
|
31
|
-
{
|
|
32
|
-
bold: 'SHOP_MINIS_API_KEY',
|
|
33
|
-
},
|
|
34
|
-
'in `.env` to set up this Mini.',
|
|
35
|
-
],
|
|
36
|
-
});
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
// Select the organization
|
|
40
|
-
const organizations = await fetchAllOrgs();
|
|
41
|
-
const organizationId = await renderSelectPrompt({
|
|
42
|
-
message: 'Select your organization',
|
|
43
|
-
choices: organizations.map(org => ({
|
|
44
|
-
label: org.businessName,
|
|
45
|
-
value: org.id,
|
|
46
|
-
})),
|
|
47
|
-
});
|
|
48
|
-
const result = await miniCreate({
|
|
49
|
-
name: miniName,
|
|
50
|
-
organizationId: `gid://shopify/Organization/${organizationId}`,
|
|
51
|
-
partnersAccessToken: await token(),
|
|
52
|
-
});
|
|
53
|
-
if (result.userErrors.length > 0) {
|
|
54
|
-
if (result.userErrors.length === 1) {
|
|
55
|
-
if (result.userErrors[0].code === 'TOO_MANY_MINIS') {
|
|
56
|
-
renderError({
|
|
57
|
-
body: `You have reached the maximum number of Shop Minis for your organization. Please contact support to request more.`,
|
|
58
|
-
});
|
|
59
|
-
process.exit(0);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw new AbortError(result.userErrors[0].message);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
throw new AbortError(result.userErrors.map(({ message }) => message).join('\n'));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// Append the new SHOP_MINIS_API_KEY to the .env file
|
|
70
|
-
envFileContents += `\nSHOP_MINIS_API_KEY=${result.token}`;
|
|
71
|
-
fs.writeFileSync(envFilePath, envFileContents, {
|
|
72
|
-
encoding: 'utf-8',
|
|
73
|
-
});
|
|
74
|
-
// Sync the manifest
|
|
75
|
-
if (result.mini) {
|
|
76
|
-
syncManifest({ handle: result.mini.handle });
|
|
77
|
-
renderSuccess({
|
|
78
|
-
headline: 'Shop Mini created',
|
|
79
|
-
body: [
|
|
80
|
-
'Shop Mini with handle',
|
|
81
|
-
{
|
|
82
|
-
bold: result.mini.handle,
|
|
83
|
-
},
|
|
84
|
-
'has been created.',
|
|
85
|
-
],
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export const command = new Command()
|
|
90
|
-
.name('create')
|
|
91
|
-
.description('Create a new Shop Mini')
|
|
92
|
-
.action(async () => {
|
|
93
|
-
try {
|
|
94
|
-
await loginAndSetup();
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
handleError(error);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
//# sourceMappingURL=create.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create.js","sourceRoot":"","sources":["../../../src/commands/setup/create.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,MAAM,SAAS,CAAA;AAExB,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAA;AACjC,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,WAAW,GACZ,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAC,UAAU,EAAE,OAAO,IAAI,WAAW,EAAC,MAAM,6BAA6B,CAAA;AAE9E,OAAO,EAAC,YAAY,EAAE,KAAK,EAAC,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAC,UAAU,EAAC,MAAM,2BAA2B,CAAA;AACpD,OAAO,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAA;AAC7D,OAAO,EAAC,YAAY,EAAC,MAA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