@api-emulator/adp 0.1.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/README.md +42 -0
- package/api-emulator.mjs +113 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @api-emulator/adp
|
|
2
|
+
|
|
3
|
+
ADP provides Human Capital Management APIs for workers, payroll events, organizations, time, and pay data.
|
|
4
|
+
|
|
5
|
+
Part of [api-emulator](https://github.com/jsj/api-emulator) — local drop-in replacement services for CI and no-network sandboxes.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @api-emulator/adp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Run
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx -p api-emulator api --plugin ./@adp/api-emulator.mjs --service adp
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Endpoints
|
|
20
|
+
|
|
21
|
+
- `GET /hr/v2/workers`
|
|
22
|
+
- `GET /hr/v2/workers/:associateOid`
|
|
23
|
+
- `POST /events/hr/v1/worker.hire`
|
|
24
|
+
- `POST /payroll/v1/pay-data-input`
|
|
25
|
+
- `GET /inspect/contract`
|
|
26
|
+
- `GET /inspect/state`
|
|
27
|
+
|
|
28
|
+
## Auth
|
|
29
|
+
|
|
30
|
+
No production credentials are required. Use fake local credentials in client tests.
|
|
31
|
+
|
|
32
|
+
## Seed Configuration
|
|
33
|
+
|
|
34
|
+
```yaml
|
|
35
|
+
adp:
|
|
36
|
+
# Add provider-specific seed state here.
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Links
|
|
40
|
+
|
|
41
|
+
- [Official API docs](https://developers.adp.com/)
|
|
42
|
+
- [api-emulator](https://github.com/jsj/api-emulator)
|
package/api-emulator.mjs
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// @adp/api-emulator.mjs
|
|
2
|
+
function initialState(config = {}) {
|
|
3
|
+
return {
|
|
4
|
+
...{
|
|
5
|
+
workers: [
|
|
6
|
+
{
|
|
7
|
+
associateOID: "aoid_1",
|
|
8
|
+
workerID: {
|
|
9
|
+
idValue: "E0001"
|
|
10
|
+
},
|
|
11
|
+
person: {
|
|
12
|
+
legalName: {
|
|
13
|
+
givenName: "Ada",
|
|
14
|
+
familyName1: "Lovelace"
|
|
15
|
+
},
|
|
16
|
+
communication: {
|
|
17
|
+
emails: [
|
|
18
|
+
{
|
|
19
|
+
emailUri: "ada@example.com"
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
workerStatus: {
|
|
25
|
+
statusCode: {
|
|
26
|
+
codeValue: "Active"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
payDataInputs: [],
|
|
32
|
+
nextId: 2
|
|
33
|
+
},
|
|
34
|
+
...config
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function state(store) {
|
|
38
|
+
const current = store.getData?.("adp:state");
|
|
39
|
+
if (current)
|
|
40
|
+
return current;
|
|
41
|
+
const next = initialState();
|
|
42
|
+
store.setData?.("adp:state", next);
|
|
43
|
+
return next;
|
|
44
|
+
}
|
|
45
|
+
function saveState(store, next) {
|
|
46
|
+
store.setData?.("adp:state", next);
|
|
47
|
+
}
|
|
48
|
+
async function json(c) {
|
|
49
|
+
return c.req.json().catch(() => ({}));
|
|
50
|
+
}
|
|
51
|
+
async function createPlain(c, store, key, prefix) {
|
|
52
|
+
const s = state(store);
|
|
53
|
+
const body = await json(c);
|
|
54
|
+
const row = { id: body.id ?? s.nextId++, created_at: new Date().toISOString(), ...body };
|
|
55
|
+
s[key].push(row);
|
|
56
|
+
saveState(store, s);
|
|
57
|
+
return row;
|
|
58
|
+
}
|
|
59
|
+
async function createKeyed(c, store, key, prefix) {
|
|
60
|
+
const row = await createPlain(c, store, key, prefix);
|
|
61
|
+
row.id ??= `${prefix}_${state(store).nextId}`;
|
|
62
|
+
return c.json(row, 201);
|
|
63
|
+
}
|
|
64
|
+
function adpError(message) {
|
|
65
|
+
return { confirmMessage: { confirmMessageID: { idValue: "emulator-error" }, createDateTime: new Date().toISOString(), requestStatusCode: { codeValue: "failed" }, resourceMessages: [{ processMessages: [{ messageTypeCode: { codeValue: "error" }, userMessage: { messageTxt: message } }] }] } };
|
|
66
|
+
}
|
|
67
|
+
var contract = {
|
|
68
|
+
provider: "adp",
|
|
69
|
+
source: "ADP official API documentation-informed REST subset",
|
|
70
|
+
docs: "https://developers.adp.com/",
|
|
71
|
+
baseUrl: "https://api.adp.com",
|
|
72
|
+
scope: ["workers", "worker-read", "worker-hire-event", "pay-data-input"],
|
|
73
|
+
fidelity: "stateful-rest-emulator"
|
|
74
|
+
};
|
|
75
|
+
var plugin = {
|
|
76
|
+
name: "adp",
|
|
77
|
+
register(app, store) {
|
|
78
|
+
app.get("/hr/v2/workers", (c) => c.json({ workers: state(store).workers }));
|
|
79
|
+
app.get("/hr/v2/workers/:associateOid", (c) => {
|
|
80
|
+
const row = state(store).workers.find((w) => w.associateOID === c.req.param("associateOid"));
|
|
81
|
+
return row ? c.json(row) : c.json(adpError("Worker not found"), 404);
|
|
82
|
+
});
|
|
83
|
+
app.post("/events/hr/v1/worker.hire", async (c) => {
|
|
84
|
+
const s = state(store);
|
|
85
|
+
const body = await json(c);
|
|
86
|
+
const row = { associateOID: body.associateOID ?? `aoid_${s.nextId++}`, workerID: { idValue: body.workerID?.idValue ?? `E${String(s.nextId).padStart(4, "0")}` }, person: body.person ?? {}, workerStatus: { statusCode: { codeValue: "Active" } } };
|
|
87
|
+
s.workers.push(row);
|
|
88
|
+
saveState(store, s);
|
|
89
|
+
return c.json({ eventStatusCode: { codeValue: "complete" }, worker: row }, 201);
|
|
90
|
+
});
|
|
91
|
+
app.post("/payroll/v1/pay-data-input", async (c) => createKeyed(c, store, "payDataInputs", "payDataInput"));
|
|
92
|
+
app.get("/inspect/contract", (c) => c.json(contract));
|
|
93
|
+
app.get("/inspect/state", (c) => c.json(state(store)));
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
function seedFromConfig(store, _baseUrl, config = {}) {
|
|
97
|
+
saveState(store, initialState(config));
|
|
98
|
+
}
|
|
99
|
+
var label = "ADP API emulator";
|
|
100
|
+
var endpoints = contract.scope.join(", ");
|
|
101
|
+
var capabilities = contract.scope;
|
|
102
|
+
var initConfig = { adp: initialState() };
|
|
103
|
+
var api_emulator_default = plugin;
|
|
104
|
+
export {
|
|
105
|
+
seedFromConfig,
|
|
106
|
+
plugin,
|
|
107
|
+
label,
|
|
108
|
+
initConfig,
|
|
109
|
+
endpoints,
|
|
110
|
+
api_emulator_default as default,
|
|
111
|
+
contract,
|
|
112
|
+
capabilities
|
|
113
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@api-emulator/adp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./api-emulator.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./api-emulator.mjs"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"api-emulator.mjs",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://api-emulator.jsj.sh",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/jsj/api-emulator-registry.git",
|
|
18
|
+
"directory": "@adp"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/jsj/api-emulator/issues"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"api-emulator": ">=0.6.0"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
}
|
|
29
|
+
}
|