@simplysf/simply-settings-core 0.0.0-stage → 0.2.0
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/LICENSE.txt +206 -0
- package/README.md +81 -2
- package/lib/address/activateStates.d.ts +23 -0
- package/lib/address/activateStates.js +34 -0
- package/lib/address/activateStates.js.map +1 -0
- package/lib/address/addressSettingsTransfer.d.ts +42 -0
- package/lib/address/addressSettingsTransfer.js +90 -0
- package/lib/address/addressSettingsTransfer.js.map +1 -0
- package/lib/address/addressSettingsXml.d.ts +49 -0
- package/lib/address/addressSettingsXml.js +128 -0
- package/lib/address/addressSettingsXml.js.map +1 -0
- package/lib/address/createStates.d.ts +63 -0
- package/lib/address/createStates.js +115 -0
- package/lib/address/createStates.js.map +1 -0
- package/lib/address/newStateForm.d.ts +52 -0
- package/lib/address/newStateForm.js +218 -0
- package/lib/address/newStateForm.js.map +1 -0
- package/lib/address/setupSession.d.ts +78 -0
- package/lib/address/setupSession.js +219 -0
- package/lib/address/setupSession.js.map +1 -0
- package/lib/address/stateDefinitions.d.ts +31 -0
- package/lib/address/stateDefinitions.js +83 -0
- package/lib/address/stateDefinitions.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +28 -0
- package/lib/index.js.map +1 -0
- package/package.json +137 -4
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
Apache License Version 2.0
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, SimplySF.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
193
|
+
|
|
194
|
+
Copyright {yyyy} {name of copyright owner}
|
|
195
|
+
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
199
|
+
|
|
200
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
201
|
+
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @simplysf/simply-settings-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://npmjs.com/@simplysf/simply-settings-core) [](https://npmjs.com/@simplysf/simply-settings-core) [](https://raw.githubusercontent.com/SimplySF/simply-plugins-core/main/LICENSE.txt)
|
|
4
|
+
|
|
5
|
+
State and Country/Territory picklist automation. This package creates states through Setup's
|
|
6
|
+
_Configure New State_ form, which no Salesforce API can do. It also activates them by deploying
|
|
7
|
+
`AddressSettings`. It is not a Salesforce CLI plugin. It's the library layer behind
|
|
8
|
+
[`@simplysf/simply-settings`](https://github.com/SimplySF/simply-plugins/tree/main/packages/simply-settings)'s
|
|
9
|
+
`settings address state` commands, published separately so anything can import the same logic
|
|
10
|
+
without pulling in the CLI framework: an editor extension, a CI job, a script.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @simplysf/simply-settings-core
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Requires Node.js `>=22` and either `"type": "module"` or a dynamic `import()`. This package ships ESM only.
|
|
19
|
+
|
|
20
|
+
## API
|
|
21
|
+
|
|
22
|
+
Everything below is exported from the package root. Removing or renaming an export is a breaking change; see [`src/index.ts`](src/index.ts).
|
|
23
|
+
|
|
24
|
+
| Export | Description |
|
|
25
|
+
| --------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
26
|
+
| `parseStateDefinitions(json)` | Validates a `{ "US-CA": "California" }` object into `StateDefinition[]`, naming the first bad entry. |
|
|
27
|
+
| `filterStateDefinitions(definitions, countries?)` | Narrows definitions to ISO country codes. Fails on a malformed code or a country with no definitions. |
|
|
28
|
+
| `formatStateKey(definition)` | `US-CA` for a definition. |
|
|
29
|
+
| `retrieveAddressSettingsXml(options)` / `deployAddressSettingsXml(options)` | Metadata API retrieve/deploy of the org's `Address` settings, as `Address.settings-meta.xml` text. A failed deploy is reported in the result, not thrown. |
|
|
30
|
+
| `parseAddressSettingsXml(xml)` | The countries and states in a settings file, with ISO codes kept as strings (Andorra's `02` stays `02`). |
|
|
31
|
+
| `planStateCreation(definitions, settings)` | Splits definitions into `pending` (to submit) and `settled` (`exists`, `country-missing`) without any Setup traffic. |
|
|
32
|
+
| `openSetupSession(options)` / `SetupSession` | A cookie-carrying session on the org's Setup pages, opened through a single-use frontdoor URL (the mechanism `sf org open` uses). |
|
|
33
|
+
| `createState(session, definition, options?)` | Submits one state through _Configure New State_ and classifies the result. Retries transport failures, and reports per-state problems as `failed` instead of throwing. |
|
|
34
|
+
| `createStates(options)` | Runs `createState` over many states, `concurrency` at a time (default `DEFAULT_CREATE_CONCURRENCY`, 4). |
|
|
35
|
+
| `parseNewStateForm(html)` / `fillNewStateForm(form, definition)` | Finds the form by its fields' stable id suffixes, not Visualforce's generated ids, and builds the submission. |
|
|
36
|
+
| `classifyNewStateResponse(response)` | Maps a form POST response to `created`, `exists`, `rejected`, `country-missing`, or `failed`. |
|
|
37
|
+
| `planStateActivation(xml, definitions)` | Sets `<active>`/`<visible>` on exactly the listed states. Every other state and country is untouched. |
|
|
38
|
+
| `activateStates(options)` | Retrieve, `planStateActivation`, then deploy. Supports `dryRun`. |
|
|
39
|
+
| `isLoginPage(response)`, `NEW_STATE_FORM_PATH`, `SetupTransportError` | Supporting helpers and constants. |
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import {
|
|
43
|
+
createStates,
|
|
44
|
+
openSetupSession,
|
|
45
|
+
parseAddressSettingsXml,
|
|
46
|
+
parseStateDefinitions,
|
|
47
|
+
planStateCreation,
|
|
48
|
+
retrieveAddressSettingsXml,
|
|
49
|
+
} from '@simplysf/simply-settings-core';
|
|
50
|
+
import { Duration } from '@salesforce/kit';
|
|
51
|
+
|
|
52
|
+
const definitions = parseStateDefinitions({ 'US-GU': 'Guam', 'AD-02': 'Canillo' });
|
|
53
|
+
const settings = parseAddressSettingsXml(await retrieveAddressSettingsXml({ connection, wait: Duration.minutes(10) }));
|
|
54
|
+
const { pending, settled } = planStateCreation(definitions, settings);
|
|
55
|
+
|
|
56
|
+
const session = await openSetupSession({ connection });
|
|
57
|
+
const outcomes = await createStates({ session, states: pending, onProgress: (outcome) => console.log(outcome) });
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { activateStates, parseStateDefinitions } from '@simplysf/simply-settings-core';
|
|
62
|
+
import { Duration } from '@salesforce/kit';
|
|
63
|
+
|
|
64
|
+
const result = await activateStates({
|
|
65
|
+
connection,
|
|
66
|
+
wait: Duration.minutes(10),
|
|
67
|
+
states: parseStateDefinitions({ 'US-GU': 'Guam' }),
|
|
68
|
+
});
|
|
69
|
+
// result.activated / alreadyActive / notInOrg, and result.deploy if a deploy ran
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Opening a Setup session needs an access token that can reach the UI (the `web` or `full` OAuth
|
|
73
|
+
scope), as granted by `sf org login web`. Without one, `openSetupSession` throws a
|
|
74
|
+
`SetupSessionError` before anything is submitted.
|
|
75
|
+
|
|
76
|
+
## Issues
|
|
77
|
+
|
|
78
|
+
Please report any issues at https://github.com/SimplySF/simply-plugins-core/issues
|
|
79
|
+
|
|
80
|
+
## Contributing
|
|
81
|
+
|
|
82
|
+
This package is part of the [`@simplysf/simply`](https://github.com/SimplySF/simply-plugins-core) monorepo. See [CONTRIBUTING.md](CONTRIBUTING.md) for what's specific to this package, and the repo's [root CONTRIBUTING.md](https://github.com/SimplySF/simply-plugins-core/blob/main/CONTRIBUTING.md) for repo structure, setup, commit conventions, and how to submit a pull request. Please also read our [Code of Conduct](https://github.com/SimplySF/simply-plugins-core/blob/main/CODE_OF_CONDUCT.md).
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type AddressSettingsDeployResult, type AddressSettingsTransferOptions } from './addressSettingsTransfer.js';
|
|
2
|
+
import type { StateDefinition } from './stateDefinitions.js';
|
|
3
|
+
export type ActivateStatesOptions = AddressSettingsTransferOptions & {
|
|
4
|
+
states: StateDefinition[];
|
|
5
|
+
/** Plan only: report what would change, deploy nothing. */
|
|
6
|
+
dryRun?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type ActivateStatesResult = {
|
|
9
|
+
activated: StateDefinition[];
|
|
10
|
+
alreadyActive: StateDefinition[];
|
|
11
|
+
notInOrg: StateDefinition[];
|
|
12
|
+
/** Present when a deploy ran — not for a dry run, or when nothing needed changing. */
|
|
13
|
+
deploy?: AddressSettingsDeployResult;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Sets the given states active and visible: retrieves the org's AddressSettings, flips
|
|
17
|
+
* `<active>`/`<visible>` on exactly those states, and deploys the result back.
|
|
18
|
+
*
|
|
19
|
+
* @param options - Connection, states, wait, and dry-run.
|
|
20
|
+
* @returns How each state was handled, and the deploy result if one ran. A failed deploy is
|
|
21
|
+
* reported in `deploy.success`/`deploy.failures`, not thrown.
|
|
22
|
+
*/
|
|
23
|
+
export declare function activateStates(options: ActivateStatesOptions): Promise<ActivateStatesResult>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026, SimplySF.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { planStateActivation } from './addressSettingsXml.js';
|
|
17
|
+
import { deployAddressSettingsXml, retrieveAddressSettingsXml, } from './addressSettingsTransfer.js';
|
|
18
|
+
/**
|
|
19
|
+
* Sets the given states active and visible: retrieves the org's AddressSettings, flips
|
|
20
|
+
* `<active>`/`<visible>` on exactly those states, and deploys the result back.
|
|
21
|
+
*
|
|
22
|
+
* @param options - Connection, states, wait, and dry-run.
|
|
23
|
+
* @returns How each state was handled, and the deploy result if one ran. A failed deploy is
|
|
24
|
+
* reported in `deploy.success`/`deploy.failures`, not thrown.
|
|
25
|
+
*/
|
|
26
|
+
export async function activateStates(options) {
|
|
27
|
+
const xml = await retrieveAddressSettingsXml(options);
|
|
28
|
+
const { xml: updatedXml, ...plan } = planStateActivation(xml, options.states);
|
|
29
|
+
if (options.dryRun || updatedXml === undefined) {
|
|
30
|
+
return plan;
|
|
31
|
+
}
|
|
32
|
+
return { ...plan, deploy: await deployAddressSettingsXml({ ...options, xml: updatedXml }) };
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=activateStates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activateStates.js","sourceRoot":"","sources":["../../src/address/activateStates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EACL,wBAAwB,EACxB,0BAA0B,GAG3B,MAAM,8BAA8B,CAAC;AAiBtC;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAA8B;IACjE,MAAM,GAAG,GAAG,MAAM,0BAA0B,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAE9E,IAAI,OAAO,CAAC,MAAM,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Connection } from '@salesforce/core';
|
|
2
|
+
import type { Duration } from '@salesforce/kit';
|
|
3
|
+
export type AddressSettingsTransferOptions = {
|
|
4
|
+
connection: Connection;
|
|
5
|
+
/** How long to poll the retrieve/deploy before giving up. */
|
|
6
|
+
wait: Duration;
|
|
7
|
+
};
|
|
8
|
+
export type AddressSettingsDeployFailure = {
|
|
9
|
+
fullName: string;
|
|
10
|
+
type: string;
|
|
11
|
+
error: string;
|
|
12
|
+
};
|
|
13
|
+
export type AddressSettingsDeployResult = {
|
|
14
|
+
id: string;
|
|
15
|
+
status: string;
|
|
16
|
+
success: boolean;
|
|
17
|
+
failures: AddressSettingsDeployFailure[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Retrieves the org's `Address` settings (the `AddressSettings` metadata type, which holds every
|
|
21
|
+
* country and state in State and Country/Territory Picklists).
|
|
22
|
+
*
|
|
23
|
+
* A Metadata API retrieve rather than a `readMetadata` call, because what comes back is then
|
|
24
|
+
* exactly the source-format file `deployAddressSettingsXml` sends back — one representation for
|
|
25
|
+
* both reading and writing, with no type coercion in between.
|
|
26
|
+
*
|
|
27
|
+
* @param options - The org connection and how long to wait for the retrieve.
|
|
28
|
+
* @returns The `Address.settings-meta.xml` file's text.
|
|
29
|
+
*/
|
|
30
|
+
export declare function retrieveAddressSettingsXml(options: AddressSettingsTransferOptions): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Deploys `Address.settings-meta.xml` content to the org and polls to completion.
|
|
33
|
+
*
|
|
34
|
+
* Does not throw on a failed deploy — the failure is reported in the result (`success: false`,
|
|
35
|
+
* populated `failures`). An error here means the deploy request or polling itself broke.
|
|
36
|
+
*
|
|
37
|
+
* @param options - The org connection, the settings XML, and how long to wait.
|
|
38
|
+
* @returns The deploy's id, terminal status, and component failures.
|
|
39
|
+
*/
|
|
40
|
+
export declare function deployAddressSettingsXml(options: AddressSettingsTransferOptions & {
|
|
41
|
+
xml: string;
|
|
42
|
+
}): Promise<AddressSettingsDeployResult>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026, SimplySF.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
17
|
+
import { tmpdir } from 'node:os';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import { SfError } from '@salesforce/core';
|
|
20
|
+
import { ComponentSet, ComponentStatus } from '@salesforce/source-deploy-retrieve';
|
|
21
|
+
const SETTINGS_FILE = path.join('settings', 'Address.settings-meta.xml');
|
|
22
|
+
async function withTempDir(fn) {
|
|
23
|
+
const dir = await mkdtemp(path.join(tmpdir(), 'simply-settings-'));
|
|
24
|
+
try {
|
|
25
|
+
return await fn(dir);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
await rm(dir, { recursive: true, force: true });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves the org's `Address` settings (the `AddressSettings` metadata type, which holds every
|
|
33
|
+
* country and state in State and Country/Territory Picklists).
|
|
34
|
+
*
|
|
35
|
+
* A Metadata API retrieve rather than a `readMetadata` call, because what comes back is then
|
|
36
|
+
* exactly the source-format file `deployAddressSettingsXml` sends back — one representation for
|
|
37
|
+
* both reading and writing, with no type coercion in between.
|
|
38
|
+
*
|
|
39
|
+
* @param options - The org connection and how long to wait for the retrieve.
|
|
40
|
+
* @returns The `Address.settings-meta.xml` file's text.
|
|
41
|
+
*/
|
|
42
|
+
export async function retrieveAddressSettingsXml(options) {
|
|
43
|
+
return withTempDir(async (dir) => {
|
|
44
|
+
const componentSet = new ComponentSet([{ fullName: 'Address', type: 'Settings' }]);
|
|
45
|
+
const retrieve = await componentSet.retrieve({
|
|
46
|
+
usernameOrConnection: options.connection,
|
|
47
|
+
output: dir,
|
|
48
|
+
merge: false,
|
|
49
|
+
});
|
|
50
|
+
const result = await retrieve.pollStatus({ timeout: options.wait });
|
|
51
|
+
const file = result
|
|
52
|
+
.getFileResponses()
|
|
53
|
+
.find((response) => response.state !== ComponentStatus.Failed && response.filePath?.endsWith('.settings-meta.xml'));
|
|
54
|
+
if (!file?.filePath) {
|
|
55
|
+
const messages = result.getFileResponses().flatMap((response) => ('error' in response ? [response.error] : []));
|
|
56
|
+
throw new SfError(`Couldn't retrieve AddressSettings from the org.${messages.length > 0 ? ` ${messages.join(' ')}` : ''}`, 'AddressSettingsRetrieveError');
|
|
57
|
+
}
|
|
58
|
+
return readFile(file.filePath, 'utf8');
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Deploys `Address.settings-meta.xml` content to the org and polls to completion.
|
|
63
|
+
*
|
|
64
|
+
* Does not throw on a failed deploy — the failure is reported in the result (`success: false`,
|
|
65
|
+
* populated `failures`). An error here means the deploy request or polling itself broke.
|
|
66
|
+
*
|
|
67
|
+
* @param options - The org connection, the settings XML, and how long to wait.
|
|
68
|
+
* @returns The deploy's id, terminal status, and component failures.
|
|
69
|
+
*/
|
|
70
|
+
export async function deployAddressSettingsXml(options) {
|
|
71
|
+
return withTempDir(async (dir) => {
|
|
72
|
+
const filePath = path.join(dir, SETTINGS_FILE);
|
|
73
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
74
|
+
await writeFile(filePath, options.xml, 'utf8');
|
|
75
|
+
const deploy = await ComponentSet.fromSource(filePath).deploy({ usernameOrConnection: options.connection });
|
|
76
|
+
const result = await deploy.pollStatus({ timeout: options.wait });
|
|
77
|
+
const failures = result
|
|
78
|
+
.getFileResponses()
|
|
79
|
+
.flatMap((response) => response.state === ComponentStatus.Failed
|
|
80
|
+
? [{ fullName: response.fullName, type: response.type, error: response.error }]
|
|
81
|
+
: []);
|
|
82
|
+
return {
|
|
83
|
+
id: result.response.id,
|
|
84
|
+
status: result.response.status,
|
|
85
|
+
success: result.response.success,
|
|
86
|
+
failures,
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=addressSettingsTransfer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addressSettingsTransfer.js","sourceRoot":"","sources":["../../src/address/addressSettingsTransfer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAmB,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAqBnF,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,2BAA2B,CAAC,CAAC;AAEzE,KAAK,UAAU,WAAW,CAAI,EAA+B;IAC3D,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,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AAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;YAC/E,CAAC,CAAC,EAAE,CACP,CAAC;QAEJ,OAAO;YACL,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE;YACtB,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM;YAC9B,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO;YAChC,QAAQ;SACT,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { StateDefinition } from './stateDefinitions.js';
|
|
2
|
+
export type AddressSettingsState = {
|
|
3
|
+
isoCode: string;
|
|
4
|
+
label: string;
|
|
5
|
+
active: boolean;
|
|
6
|
+
visible: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type AddressSettingsCountry = {
|
|
9
|
+
isoCode: string;
|
|
10
|
+
label: string;
|
|
11
|
+
active: boolean;
|
|
12
|
+
visible: boolean;
|
|
13
|
+
states: AddressSettingsState[];
|
|
14
|
+
};
|
|
15
|
+
/** The parts of an org's `AddressSettings` this package reads. */
|
|
16
|
+
export type AddressSettings = {
|
|
17
|
+
countries: AddressSettingsCountry[];
|
|
18
|
+
};
|
|
19
|
+
export type StateActivationPlan = {
|
|
20
|
+
/**
|
|
21
|
+
* The settings XML with every `activated` state set active and visible, or `undefined` when
|
|
22
|
+
* `activated` is empty — there is nothing to deploy.
|
|
23
|
+
*/
|
|
24
|
+
xml?: string;
|
|
25
|
+
/** Definitions whose state was inactive or hidden and is now set active and visible. */
|
|
26
|
+
activated: StateDefinition[];
|
|
27
|
+
/** Definitions whose state was already active and visible. */
|
|
28
|
+
alreadyActive: StateDefinition[];
|
|
29
|
+
/** Definitions with no matching state in the org (not created yet, or the country is absent). */
|
|
30
|
+
notInOrg: StateDefinition[];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Reads the countries and states out of an `Address.settings-meta.xml` document.
|
|
34
|
+
*
|
|
35
|
+
* @param xml - The settings file's text, as retrieved.
|
|
36
|
+
* @returns Every country with its states, in document order.
|
|
37
|
+
* @throws SfError when the document isn't AddressSettings or has no countries (State and
|
|
38
|
+
* Country/Territory Picklists not enabled).
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseAddressSettingsXml(xml: string): AddressSettings;
|
|
41
|
+
/**
|
|
42
|
+
* Sets `<active>` and `<visible>` to `true` on exactly the states named by `definitions`, leaving
|
|
43
|
+
* every other state and every country untouched.
|
|
44
|
+
*
|
|
45
|
+
* @param xml - The settings file's text, as retrieved from the same org it will be deployed to.
|
|
46
|
+
* @param definitions - The states to activate.
|
|
47
|
+
* @returns The rewritten XML (only when something changed) and how each definition was handled.
|
|
48
|
+
*/
|
|
49
|
+
export declare function planStateActivation(xml: string, definitions: StateDefinition[]): StateActivationPlan;
|