@proveanything/smartlinks 2.1.45 → 2.1.47
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/dist/api/dpp.d.ts +93 -0
- package/dist/api/dpp.js +182 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/serviceAccounts.d.ts +22 -5
- package/dist/api/serviceAccounts.js +35 -8
- package/dist/docs/API_SUMMARY.md +348 -5
- package/dist/docs/dpp.md +99 -0
- package/dist/docs/overview.md +1 -0
- package/dist/docs/service-accounts.md +25 -4
- package/dist/openapi.yaml +536 -0
- package/dist/types/dpp.d.ts +264 -0
- package/dist/types/dpp.js +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/serviceAccounts.d.ts +24 -1
- package/docs/API_SUMMARY.md +348 -5
- package/docs/dpp.md +99 -0
- package/docs/overview.md +1 -0
- package/docs/service-accounts.md +25 -4
- package/openapi.yaml +536 -0
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { DppEnvironment, DppRegistry, SetDppRegistryInput, DppRegistryCheckResult, DppGroup, DppPassport, DppPassportInput, DppPassportUpsertInput, DppPassportSaveResult, DppPassportUpsertResult, DppPassportBulkResult, DppPassportVersion, DppPassportListQuery, DppRegisterResult, DppTask, DppTaskRefreshResult, DppDocument } from "../types/dpp.js";
|
|
2
|
+
export declare namespace dpp {
|
|
3
|
+
/** What passports can be made: product groups, their kinds, and each view's fields and required fields. GET /dpp/groups */
|
|
4
|
+
function groups(collectionId: string): Promise<DppGroup[]>;
|
|
5
|
+
/**
|
|
6
|
+
* Read a passport as the public sees it, at its address (the EU JSON document), or an earlier version of it.
|
|
7
|
+
* No sign-in needed. GET /public/dpp/:collectionId/:passportId
|
|
8
|
+
*/
|
|
9
|
+
function read(collectionId: string, passportId: string, opts?: {
|
|
10
|
+
version?: number;
|
|
11
|
+
}): Promise<DppDocument>;
|
|
12
|
+
/**
|
|
13
|
+
* Send passports to the EU registry. They're grouped by product group and sent up to 100 at a time; the registry
|
|
14
|
+
* reads each one at its address. Passports still missing required fields, withdrawn or already registered come
|
|
15
|
+
* back in `skipped`. With `wait: true` the call waits (up to ~45 s) and returns each passport's outcome; otherwise
|
|
16
|
+
* follow up with `dpp.tasks.refresh`. POST /dpp/registry/:env/register
|
|
17
|
+
*/
|
|
18
|
+
function register(collectionId: string, env: DppEnvironment, passportIds: string[], opts?: {
|
|
19
|
+
wait?: boolean;
|
|
20
|
+
}): Promise<DppRegisterResult>;
|
|
21
|
+
/** The brand's EU registry connection (one per environment). Managed by the collection's admins. */
|
|
22
|
+
namespace registry {
|
|
23
|
+
/** Both environments, each with `nextStep` (what's left to connect). GET /dpp/registry */
|
|
24
|
+
function list(collectionId: string): Promise<DppRegistry[]>;
|
|
25
|
+
/** One environment. GET /dpp/registry/:env */
|
|
26
|
+
function get(collectionId: string, env: DppEnvironment): Promise<DppRegistry>;
|
|
27
|
+
/**
|
|
28
|
+
* Make (or replace) the key the brand's Service Account trusts. The private key stays on SmartLinks' servers;
|
|
29
|
+
* show `publicPem` (or `publicJwk`) for the brand to add to its Service Account in the registry. Replacing the
|
|
30
|
+
* key clears `kid` — the registry gives the new key its own. POST /dpp/registry/:env/key
|
|
31
|
+
*/
|
|
32
|
+
function makeKey(collectionId: string, env: DppEnvironment, opts?: {
|
|
33
|
+
alg?: "ES256" | "ES384" | "ES512";
|
|
34
|
+
}): Promise<DppRegistry>;
|
|
35
|
+
/** Save the Service Account's Client ID and key ID, and the brand's Organisation ID, from the registry. PUT /dpp/registry/:env */
|
|
36
|
+
function set(collectionId: string, env: DppEnvironment, input: SetDppRegistryInput): Promise<DppRegistry>;
|
|
37
|
+
/** Sign in to the registry and read its product groups — proves the connection works. POST /dpp/registry/:env/check */
|
|
38
|
+
function check(collectionId: string, env: DppEnvironment): Promise<DppRegistryCheckResult>;
|
|
39
|
+
}
|
|
40
|
+
/** The collection's passports. */
|
|
41
|
+
namespace passports {
|
|
42
|
+
/** GET /dpp/passports */
|
|
43
|
+
function list(collectionId: string, q?: DppPassportListQuery): Promise<DppPassport[]>;
|
|
44
|
+
/** One passport, with `check` (what it's still missing) and its `url`. GET /dpp/passports/:id */
|
|
45
|
+
function get(collectionId: string, passportId: string): Promise<DppPassport>;
|
|
46
|
+
/** Make a passport. POST /dpp/passports */
|
|
47
|
+
function create(collectionId: string, input: DppPassportInput & {
|
|
48
|
+
productGroup: string;
|
|
49
|
+
}): Promise<DppPassport>;
|
|
50
|
+
/**
|
|
51
|
+
* Change a passport. `public` / `restricted` are merged into what's there unless `replace` is true. A change to
|
|
52
|
+
* what it says makes a new version. PUT /dpp/passports/:id
|
|
53
|
+
*/
|
|
54
|
+
function update(collectionId: string, passportId: string, input: DppPassportInput, opts?: {
|
|
55
|
+
replace?: boolean;
|
|
56
|
+
}): Promise<DppPassportSaveResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Publish the passport for a product, batch or item (`productId` / `batchId` / `proofId`) at a granularity:
|
|
59
|
+
* updates the one already there or makes it. The fields replace what's there (pass `merge: true` to merge).
|
|
60
|
+
* Saving the same content again changes nothing. PUT /dpp/passports/by-anchor
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const { passport } = await dpp.passports.upsert(collectionId, {
|
|
65
|
+
* productId, productGroup: 'BATTERIES', productSubGroup: 'EV', granularity: 'model',
|
|
66
|
+
* public: { batteryChemistry: [...], manufacturerIdentification: {...} },
|
|
67
|
+
* restricted: { dismantlingInformation: [...] },
|
|
68
|
+
* })
|
|
69
|
+
* if (!passport.check.ready) console.log('Still missing', passport.check.missing)
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function upsert(collectionId: string, input: DppPassportUpsertInput, opts?: {
|
|
73
|
+
merge?: boolean;
|
|
74
|
+
}): Promise<DppPassportUpsertResult>;
|
|
75
|
+
/** `upsert` for up to 500 passports at once (e.g. one per battery); each answers on its own. POST /dpp/passports/bulk */
|
|
76
|
+
function upsertMany(collectionId: string, items: DppPassportUpsertInput[], opts?: {
|
|
77
|
+
merge?: boolean;
|
|
78
|
+
}): Promise<DppPassportBulkResult>;
|
|
79
|
+
/** Its versions, newest first; read one with `dpp.read(collectionId, id, { version })`. GET /dpp/passports/:id/versions */
|
|
80
|
+
function versions(collectionId: string, passportId: string): Promise<DppPassportVersion[]>;
|
|
81
|
+
/** No longer valid: stays at its address, marked invalid (the registry keeps its record). POST /dpp/passports/:id/withdraw */
|
|
82
|
+
function withdraw(collectionId: string, passportId: string): Promise<DppPassport>;
|
|
83
|
+
/** Valid again. POST /dpp/passports/:id/restore */
|
|
84
|
+
function restore(collectionId: string, passportId: string): Promise<DppPassport>;
|
|
85
|
+
}
|
|
86
|
+
/** Registry requests and their outcomes. */
|
|
87
|
+
namespace tasks {
|
|
88
|
+
/** Requests sent to one environment, newest first. GET /dpp/registry/:env/tasks */
|
|
89
|
+
function list(collectionId: string, env: DppEnvironment): Promise<DppTask[]>;
|
|
90
|
+
/** Ask the registry how a request went and record it on its passports. POST /dpp/registry/:env/tasks/:taskId/refresh */
|
|
91
|
+
function refresh(collectionId: string, env: DppEnvironment, taskId: string): Promise<DppTaskRefreshResult>;
|
|
92
|
+
}
|
|
93
|
+
}
|
package/dist/api/dpp.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// src/api/dpp.ts
|
|
2
|
+
//
|
|
3
|
+
// EU Digital Product Passports (ESPR) hosted by SmartLinks, and registering them in the EU registry for the brand
|
|
4
|
+
// (docs/dpp.md).
|
|
5
|
+
//
|
|
6
|
+
// The EU registry only lets an organisation register its own passports, so each brand enrols itself (with its own
|
|
7
|
+
// qualified e-seal, on the EU's site) and adds a Service Account holding SmartLinks' public key. From then on
|
|
8
|
+
// SmartLinks registers for it:
|
|
9
|
+
//
|
|
10
|
+
// 1. dpp.registry.makeKey(collectionId, 'acc') → show registry.publicPem to upload to the Service Account
|
|
11
|
+
// 2. dpp.registry.set(collectionId, 'acc', { clientId, kid, orgIdentifier })
|
|
12
|
+
// 3. dpp.registry.check(collectionId, 'acc') → signs in and reads the registry's product groups
|
|
13
|
+
// 4. dpp.passports.upsert(...) / upsertMany(...) → passports at their addresses (passport.url)
|
|
14
|
+
// 5. dpp.register(collectionId, 'acc', passportIds) → the registry reads each one and registers it
|
|
15
|
+
//
|
|
16
|
+
// 'acc' is the EU test registry, 'prod' the live one. Each passport is served at its address: the public view to
|
|
17
|
+
// anyone, and the restricted views only to the EU registry for that brand.
|
|
18
|
+
//
|
|
19
|
+
// Endpoints: /admin/collection/:collectionId/dpp/… and /public/dpp/:collectionId/:passportId
|
|
20
|
+
import { request, post, put } from "../http.js";
|
|
21
|
+
function enc(v) { return encodeURIComponent(v); }
|
|
22
|
+
const base = (collectionId) => `/admin/collection/${enc(collectionId)}/dpp`;
|
|
23
|
+
function query(q) {
|
|
24
|
+
const p = new URLSearchParams();
|
|
25
|
+
for (const [k, v] of Object.entries(q))
|
|
26
|
+
if (v !== undefined && v !== null && v !== "")
|
|
27
|
+
p.set(k, String(v));
|
|
28
|
+
const s = p.toString();
|
|
29
|
+
return s ? `?${s}` : "";
|
|
30
|
+
}
|
|
31
|
+
export var dpp;
|
|
32
|
+
(function (dpp) {
|
|
33
|
+
/** What passports can be made: product groups, their kinds, and each view's fields and required fields. GET /dpp/groups */
|
|
34
|
+
async function groups(collectionId) {
|
|
35
|
+
const out = await request(`${base(collectionId)}/groups`);
|
|
36
|
+
return out.groups;
|
|
37
|
+
}
|
|
38
|
+
dpp.groups = groups;
|
|
39
|
+
/**
|
|
40
|
+
* Read a passport as the public sees it, at its address (the EU JSON document), or an earlier version of it.
|
|
41
|
+
* No sign-in needed. GET /public/dpp/:collectionId/:passportId
|
|
42
|
+
*/
|
|
43
|
+
async function read(collectionId, passportId, opts = {}) {
|
|
44
|
+
return request(`/public/dpp/${enc(collectionId)}/${enc(passportId)}${query({ version: opts.version })}`);
|
|
45
|
+
}
|
|
46
|
+
dpp.read = read;
|
|
47
|
+
/**
|
|
48
|
+
* Send passports to the EU registry. They're grouped by product group and sent up to 100 at a time; the registry
|
|
49
|
+
* reads each one at its address. Passports still missing required fields, withdrawn or already registered come
|
|
50
|
+
* back in `skipped`. With `wait: true` the call waits (up to ~45 s) and returns each passport's outcome; otherwise
|
|
51
|
+
* follow up with `dpp.tasks.refresh`. POST /dpp/registry/:env/register
|
|
52
|
+
*/
|
|
53
|
+
async function register(collectionId, env, passportIds, opts = {}) {
|
|
54
|
+
return post(`${base(collectionId)}/registry/${enc(env)}/register`, { passportIds, wait: !!opts.wait });
|
|
55
|
+
}
|
|
56
|
+
dpp.register = register;
|
|
57
|
+
/** The brand's EU registry connection (one per environment). Managed by the collection's admins. */
|
|
58
|
+
let registry;
|
|
59
|
+
(function (registry) {
|
|
60
|
+
/** Both environments, each with `nextStep` (what's left to connect). GET /dpp/registry */
|
|
61
|
+
async function list(collectionId) {
|
|
62
|
+
const out = await request(`${base(collectionId)}/registry`);
|
|
63
|
+
return out.registries;
|
|
64
|
+
}
|
|
65
|
+
registry.list = list;
|
|
66
|
+
/** One environment. GET /dpp/registry/:env */
|
|
67
|
+
async function get(collectionId, env) {
|
|
68
|
+
const out = await request(`${base(collectionId)}/registry/${enc(env)}`);
|
|
69
|
+
return out.registry;
|
|
70
|
+
}
|
|
71
|
+
registry.get = get;
|
|
72
|
+
/**
|
|
73
|
+
* Make (or replace) the key the brand's Service Account trusts. The private key stays on SmartLinks' servers;
|
|
74
|
+
* show `publicPem` (or `publicJwk`) for the brand to add to its Service Account in the registry. Replacing the
|
|
75
|
+
* key clears `kid` — the registry gives the new key its own. POST /dpp/registry/:env/key
|
|
76
|
+
*/
|
|
77
|
+
async function makeKey(collectionId, env, opts = {}) {
|
|
78
|
+
const out = await post(`${base(collectionId)}/registry/${enc(env)}/key`, opts);
|
|
79
|
+
return out.registry;
|
|
80
|
+
}
|
|
81
|
+
registry.makeKey = makeKey;
|
|
82
|
+
/** Save the Service Account's Client ID and key ID, and the brand's Organisation ID, from the registry. PUT /dpp/registry/:env */
|
|
83
|
+
async function set(collectionId, env, input) {
|
|
84
|
+
const out = await put(`${base(collectionId)}/registry/${enc(env)}`, input);
|
|
85
|
+
return out.registry;
|
|
86
|
+
}
|
|
87
|
+
registry.set = set;
|
|
88
|
+
/** Sign in to the registry and read its product groups — proves the connection works. POST /dpp/registry/:env/check */
|
|
89
|
+
async function check(collectionId, env) {
|
|
90
|
+
return post(`${base(collectionId)}/registry/${enc(env)}/check`, {});
|
|
91
|
+
}
|
|
92
|
+
registry.check = check;
|
|
93
|
+
})(registry = dpp.registry || (dpp.registry = {}));
|
|
94
|
+
/** The collection's passports. */
|
|
95
|
+
let passports;
|
|
96
|
+
(function (passports) {
|
|
97
|
+
/** GET /dpp/passports */
|
|
98
|
+
async function list(collectionId, q = {}) {
|
|
99
|
+
const out = await request(`${base(collectionId)}/passports${query(q)}`);
|
|
100
|
+
return out.passports;
|
|
101
|
+
}
|
|
102
|
+
passports.list = list;
|
|
103
|
+
/** One passport, with `check` (what it's still missing) and its `url`. GET /dpp/passports/:id */
|
|
104
|
+
async function get(collectionId, passportId) {
|
|
105
|
+
const out = await request(`${base(collectionId)}/passports/${enc(passportId)}`);
|
|
106
|
+
return out.passport;
|
|
107
|
+
}
|
|
108
|
+
passports.get = get;
|
|
109
|
+
/** Make a passport. POST /dpp/passports */
|
|
110
|
+
async function create(collectionId, input) {
|
|
111
|
+
const out = await post(`${base(collectionId)}/passports`, input);
|
|
112
|
+
return out.passport;
|
|
113
|
+
}
|
|
114
|
+
passports.create = create;
|
|
115
|
+
/**
|
|
116
|
+
* Change a passport. `public` / `restricted` are merged into what's there unless `replace` is true. A change to
|
|
117
|
+
* what it says makes a new version. PUT /dpp/passports/:id
|
|
118
|
+
*/
|
|
119
|
+
async function update(collectionId, passportId, input, opts = {}) {
|
|
120
|
+
return put(`${base(collectionId)}/passports/${enc(passportId)}${query({ replace: opts.replace ? "true" : undefined })}`, input);
|
|
121
|
+
}
|
|
122
|
+
passports.update = update;
|
|
123
|
+
/**
|
|
124
|
+
* Publish the passport for a product, batch or item (`productId` / `batchId` / `proofId`) at a granularity:
|
|
125
|
+
* updates the one already there or makes it. The fields replace what's there (pass `merge: true` to merge).
|
|
126
|
+
* Saving the same content again changes nothing. PUT /dpp/passports/by-anchor
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const { passport } = await dpp.passports.upsert(collectionId, {
|
|
131
|
+
* productId, productGroup: 'BATTERIES', productSubGroup: 'EV', granularity: 'model',
|
|
132
|
+
* public: { batteryChemistry: [...], manufacturerIdentification: {...} },
|
|
133
|
+
* restricted: { dismantlingInformation: [...] },
|
|
134
|
+
* })
|
|
135
|
+
* if (!passport.check.ready) console.log('Still missing', passport.check.missing)
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
async function upsert(collectionId, input, opts = {}) {
|
|
139
|
+
return put(`${base(collectionId)}/passports/by-anchor${query({ replace: opts.merge ? "false" : undefined })}`, input);
|
|
140
|
+
}
|
|
141
|
+
passports.upsert = upsert;
|
|
142
|
+
/** `upsert` for up to 500 passports at once (e.g. one per battery); each answers on its own. POST /dpp/passports/bulk */
|
|
143
|
+
async function upsertMany(collectionId, items, opts = {}) {
|
|
144
|
+
return post(`${base(collectionId)}/passports/bulk${query({ replace: opts.merge ? "false" : undefined })}`, { passports: items });
|
|
145
|
+
}
|
|
146
|
+
passports.upsertMany = upsertMany;
|
|
147
|
+
/** Its versions, newest first; read one with `dpp.read(collectionId, id, { version })`. GET /dpp/passports/:id/versions */
|
|
148
|
+
async function versions(collectionId, passportId) {
|
|
149
|
+
const out = await request(`${base(collectionId)}/passports/${enc(passportId)}/versions`);
|
|
150
|
+
return out.versions;
|
|
151
|
+
}
|
|
152
|
+
passports.versions = versions;
|
|
153
|
+
/** No longer valid: stays at its address, marked invalid (the registry keeps its record). POST /dpp/passports/:id/withdraw */
|
|
154
|
+
async function withdraw(collectionId, passportId) {
|
|
155
|
+
const out = await post(`${base(collectionId)}/passports/${enc(passportId)}/withdraw`, {});
|
|
156
|
+
return out.passport;
|
|
157
|
+
}
|
|
158
|
+
passports.withdraw = withdraw;
|
|
159
|
+
/** Valid again. POST /dpp/passports/:id/restore */
|
|
160
|
+
async function restore(collectionId, passportId) {
|
|
161
|
+
const out = await post(`${base(collectionId)}/passports/${enc(passportId)}/restore`, {});
|
|
162
|
+
return out.passport;
|
|
163
|
+
}
|
|
164
|
+
passports.restore = restore;
|
|
165
|
+
})(passports = dpp.passports || (dpp.passports = {}));
|
|
166
|
+
/** Registry requests and their outcomes. */
|
|
167
|
+
let tasks;
|
|
168
|
+
(function (tasks) {
|
|
169
|
+
/** Requests sent to one environment, newest first. GET /dpp/registry/:env/tasks */
|
|
170
|
+
async function list(collectionId, env) {
|
|
171
|
+
const out = await request(`${base(collectionId)}/registry/${enc(env)}/tasks`);
|
|
172
|
+
return out.tasks;
|
|
173
|
+
}
|
|
174
|
+
tasks.list = list;
|
|
175
|
+
/** Ask the registry how a request went and record it on its passports. POST /dpp/registry/:env/tasks/:taskId/refresh */
|
|
176
|
+
async function refresh(collectionId, env, taskId) {
|
|
177
|
+
const out = await post(`${base(collectionId)}/registry/${enc(env)}/tasks/${enc(taskId)}/refresh`, {});
|
|
178
|
+
return out.task;
|
|
179
|
+
}
|
|
180
|
+
tasks.refresh = refresh;
|
|
181
|
+
})(tasks = dpp.tasks || (dpp.tasks = {}));
|
|
182
|
+
})(dpp || (dpp = {}));
|
package/dist/api/index.d.ts
CHANGED
|
@@ -56,6 +56,7 @@ export { translations } from "./translations.js";
|
|
|
56
56
|
export { integrations } from "./integrations.js";
|
|
57
57
|
export { secrets } from "./secrets.js";
|
|
58
58
|
export { serviceAccounts } from "./serviceAccounts.js";
|
|
59
|
+
export { dpp } from "./dpp.js";
|
|
59
60
|
export { research } from "./research.js";
|
|
60
61
|
export { config } from "./config.js";
|
|
61
62
|
export { http } from "./http.js";
|
package/dist/api/index.js
CHANGED
|
@@ -59,6 +59,7 @@ export { translations } from "./translations.js";
|
|
|
59
59
|
export { integrations } from "./integrations.js";
|
|
60
60
|
export { secrets } from "./secrets.js";
|
|
61
61
|
export { serviceAccounts } from "./serviceAccounts.js";
|
|
62
|
+
export { dpp } from "./dpp.js";
|
|
62
63
|
export { research } from "./research.js";
|
|
63
64
|
export { config } from "./config.js";
|
|
64
65
|
export { http } from "./http.js";
|
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
import type { ServiceAccount, ServiceAccountList, CreateServiceAccountInput, CreateServiceAccountResult, UpdateServiceAccountInput, ServiceAccountKeyResult } from "../types/serviceAccounts.js";
|
|
1
|
+
import type { ServiceAccount, ServiceAccountList, CreateServiceAccountInput, CreateServiceAccountResult, UpdateServiceAccountInput, ServiceAccountKeyResult, AddServiceAccountToCollectionInput } from "../types/serviceAccounts.js";
|
|
2
2
|
export declare namespace serviceAccounts {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The service accounts that work on this collection — its own (`home: true`, with `alsoOn`) and other
|
|
5
|
+
* collections' (`home: false`, with `homeCollection`) — never their keys, and the access levels that can be
|
|
6
|
+
* given. GET /service-accounts
|
|
7
|
+
*/
|
|
4
8
|
function list(collectionId: string): Promise<ServiceAccountList>;
|
|
5
9
|
/**
|
|
6
10
|
* Make a service account → `{ serviceAccount, key }`. Show the key once — it can't be read again. You can't
|
|
7
11
|
* give it more access than you have. POST /service-accounts
|
|
8
12
|
*/
|
|
9
13
|
function create(collectionId: string, input: CreateServiceAccountInput): Promise<CreateServiceAccountResult>;
|
|
10
|
-
/** Rename it and/or change its access. PUT /service-accounts/:id */
|
|
14
|
+
/** Rename it (home collection only) and/or change its access on this collection. PUT /service-accounts/:id */
|
|
11
15
|
function update(collectionId: string, id: string, input: UpdateServiceAccountInput): Promise<ServiceAccount>;
|
|
12
|
-
/** Give it a new key → `{ key }` (shown once); the old key stops working within a minute. POST /service-accounts/:id/key */
|
|
16
|
+
/** Give it a new key → `{ key }` (shown once; home collection only); the old key stops working within a minute. POST /service-accounts/:id/key */
|
|
13
17
|
function newKey(collectionId: string, id: string): Promise<ServiceAccountKeyResult>;
|
|
14
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Let it work on another collection too, or change its access there. Call on its home collection; you must
|
|
20
|
+
* be an admin of `input.collectionId` as well, and can't give more access than you have there.
|
|
21
|
+
* POST /service-accounts/:id/collections
|
|
22
|
+
*/
|
|
23
|
+
function addTo(collectionId: string, id: string, input: AddServiceAccountToCollectionInput): Promise<ServiceAccount>;
|
|
24
|
+
/** Stop it working on `otherCollectionId` (call on its home collection). DELETE /service-accounts/:id/collections/:otherId */
|
|
25
|
+
function removeFrom(collectionId: string, id: string, otherCollectionId: string): Promise<{
|
|
26
|
+
ok: true;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* On its home collection: delete it — its key stops working and its access is removed everywhere. On another
|
|
30
|
+
* collection it works on: remove it from that collection only. DELETE /service-accounts/:id
|
|
31
|
+
*/
|
|
15
32
|
function remove(collectionId: string, id: string): Promise<{
|
|
16
33
|
ok: true;
|
|
17
34
|
}>;
|
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
//
|
|
3
3
|
// A collection's service accounts: identities for the systems that work with it (an ERP, a warehouse
|
|
4
4
|
// system, an agency's integration), each with its own key and access level. A service account is a member of
|
|
5
|
-
//
|
|
6
|
-
//
|
|
5
|
+
// its HOME collection, like a person on the team, and optionally of other collections too ("also works on"),
|
|
6
|
+
// each with its own access. It belongs to its home collection — not to whoever made it — so it keeps working
|
|
7
|
+
// when people leave. (A personal API key is different: it IS its person, with everything they can do.) Use its key as the bearer (`initializeApi({ bearerToken: key })` or an
|
|
7
8
|
// `Authorization: Bearer <key>` header); it can do what a person with the same access can on that collection
|
|
8
|
-
// only. It can't invite people, change anyone's access, make keys or other service accounts, make
|
|
9
|
-
// collections or hand
|
|
9
|
+
// it works on only. It can't invite people, change anyone's access, make keys or other service accounts, make
|
|
10
|
+
// collections or hand a collection over.
|
|
11
|
+
//
|
|
12
|
+
// Only the home collection renames it, gives it a new key, deletes it (everywhere) or adds it to another
|
|
13
|
+
// collection — and adding needs you to be an admin of that collection too. A collection it also works on can
|
|
14
|
+
// change its access there or remove it from there.
|
|
10
15
|
//
|
|
11
16
|
// Managed by the collection's admins (Studio → Team → Service accounts). The key is shown ONCE, when the
|
|
12
17
|
// account is made or given a new key; only its hash is kept.
|
|
@@ -17,7 +22,11 @@ function enc(v) { return encodeURIComponent(v); }
|
|
|
17
22
|
export var serviceAccounts;
|
|
18
23
|
(function (serviceAccounts) {
|
|
19
24
|
const base = (collectionId) => `/admin/collection/${enc(collectionId)}/service-accounts`;
|
|
20
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* The service accounts that work on this collection — its own (`home: true`, with `alsoOn`) and other
|
|
27
|
+
* collections' (`home: false`, with `homeCollection`) — never their keys, and the access levels that can be
|
|
28
|
+
* given. GET /service-accounts
|
|
29
|
+
*/
|
|
21
30
|
async function list(collectionId) {
|
|
22
31
|
return request(base(collectionId));
|
|
23
32
|
}
|
|
@@ -30,18 +39,36 @@ export var serviceAccounts;
|
|
|
30
39
|
return post(base(collectionId), input);
|
|
31
40
|
}
|
|
32
41
|
serviceAccounts.create = create;
|
|
33
|
-
/** Rename it and/or change its access. PUT /service-accounts/:id */
|
|
42
|
+
/** Rename it (home collection only) and/or change its access on this collection. PUT /service-accounts/:id */
|
|
34
43
|
async function update(collectionId, id, input) {
|
|
35
44
|
const out = await put(`${base(collectionId)}/${enc(id)}`, input);
|
|
36
45
|
return out.serviceAccount;
|
|
37
46
|
}
|
|
38
47
|
serviceAccounts.update = update;
|
|
39
|
-
/** Give it a new key → `{ key }` (shown once); the old key stops working within a minute. POST /service-accounts/:id/key */
|
|
48
|
+
/** Give it a new key → `{ key }` (shown once; home collection only); the old key stops working within a minute. POST /service-accounts/:id/key */
|
|
40
49
|
async function newKey(collectionId, id) {
|
|
41
50
|
return post(`${base(collectionId)}/${enc(id)}/key`, {});
|
|
42
51
|
}
|
|
43
52
|
serviceAccounts.newKey = newKey;
|
|
44
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Let it work on another collection too, or change its access there. Call on its home collection; you must
|
|
55
|
+
* be an admin of `input.collectionId` as well, and can't give more access than you have there.
|
|
56
|
+
* POST /service-accounts/:id/collections
|
|
57
|
+
*/
|
|
58
|
+
async function addTo(collectionId, id, input) {
|
|
59
|
+
const out = await post(`${base(collectionId)}/${enc(id)}/collections`, input);
|
|
60
|
+
return out.serviceAccount;
|
|
61
|
+
}
|
|
62
|
+
serviceAccounts.addTo = addTo;
|
|
63
|
+
/** Stop it working on `otherCollectionId` (call on its home collection). DELETE /service-accounts/:id/collections/:otherId */
|
|
64
|
+
async function removeFrom(collectionId, id, otherCollectionId) {
|
|
65
|
+
return del(`${base(collectionId)}/${enc(id)}/collections/${enc(otherCollectionId)}`);
|
|
66
|
+
}
|
|
67
|
+
serviceAccounts.removeFrom = removeFrom;
|
|
68
|
+
/**
|
|
69
|
+
* On its home collection: delete it — its key stops working and its access is removed everywhere. On another
|
|
70
|
+
* collection it works on: remove it from that collection only. DELETE /service-accounts/:id
|
|
71
|
+
*/
|
|
45
72
|
async function remove(collectionId, id) {
|
|
46
73
|
return del(`${base(collectionId)}/${enc(id)}`);
|
|
47
74
|
}
|