@instantdb/platform 0.22.98 → 0.22.99-experimental.add-user-perm-rules.20792844601.1
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/.turbo/turbo-build.log +8 -8
- package/dist/commonjs/ProgressPromise.js +58 -45
- package/dist/commonjs/ProgressPromise.js.map +1 -1
- package/dist/commonjs/api.js +412 -366
- package/dist/commonjs/api.js.map +1 -1
- package/dist/commonjs/migrationUtils.js +4 -16
- package/dist/commonjs/migrationUtils.js.map +1 -1
- package/dist/commonjs/migrations.js +21 -10
- package/dist/commonjs/migrations.js.map +1 -1
- package/dist/commonjs/oauth.js +55 -52
- package/dist/commonjs/oauth.js.map +1 -1
- package/dist/commonjs/oauthCommon.js +0 -2
- package/dist/commonjs/oauthCommon.js.map +1 -1
- package/dist/commonjs/perms.js +1 -1
- package/dist/commonjs/perms.js.map +1 -1
- package/dist/commonjs/schema.js +14 -8
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/serverOAuth.js +68 -55
- package/dist/commonjs/serverOAuth.js.map +1 -1
- package/dist/commonjs/typescript-schema.js +2 -1
- package/dist/commonjs/typescript-schema.js.map +1 -1
- package/dist/commonjs/util.js +1 -1
- package/dist/commonjs/util.js.map +1 -1
- package/dist/esm/ProgressPromise.js +58 -45
- package/dist/esm/ProgressPromise.js.map +1 -1
- package/dist/esm/api.js +412 -366
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/migrationUtils.js +4 -16
- package/dist/esm/migrationUtils.js.map +1 -1
- package/dist/esm/migrations.js +21 -10
- package/dist/esm/migrations.js.map +1 -1
- package/dist/esm/oauth.js +55 -52
- package/dist/esm/oauth.js.map +1 -1
- package/dist/esm/oauthCommon.js +0 -2
- package/dist/esm/oauthCommon.js.map +1 -1
- package/dist/esm/perms.js +1 -1
- package/dist/esm/perms.js.map +1 -1
- package/dist/esm/schema.js +14 -8
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/serverOAuth.js +68 -55
- package/dist/esm/serverOAuth.js.map +1 -1
- package/dist/esm/typescript-schema.js +2 -1
- package/dist/esm/typescript-schema.js.map +1 -1
- package/dist/esm/util.js +1 -1
- package/dist/esm/util.js.map +1 -1
- package/dist/standalone/index.js +660 -690
- package/dist/standalone/index.umd.cjs +16 -16
- package/package.json +3 -3
package/dist/esm/api.js
CHANGED
|
@@ -1,33 +1,50 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
11
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
15
|
+
};
|
|
16
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
17
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
18
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
|
+
};
|
|
21
|
+
var _PlatformApi_auth, _PlatformApi_apiURI;
|
|
1
22
|
import { InstantAPIError, version as coreVersion, i, } from '@instantdb/core';
|
|
2
23
|
import version from "./version.js";
|
|
3
24
|
import { attrFwdLabel, attrFwdName, attrRevName, identName, } from "./schema.js";
|
|
4
25
|
import { ProgressPromise } from "./ProgressPromise.js";
|
|
5
26
|
import { capitalizeFirstLetter, deriveClientType, rels, sortedEntries, } from "./util.js";
|
|
6
27
|
import { exchangeRefreshToken } from "./serverOAuth.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
status: res.status,
|
|
28
|
-
body: { type: undefined, message: body },
|
|
29
|
-
}));
|
|
30
|
-
}
|
|
28
|
+
function jsonFetch(input, init) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const headers = Object.assign(Object.assign({}, ((init === null || init === void 0 ? void 0 : init.headers) || {})), { 'Instant-Platform-Version': version, 'Instant-Core-Version': coreVersion, 'X-Instant-Source': 'platform-sdk', 'X-Instant-Version': version });
|
|
31
|
+
const res = yield fetch(input, Object.assign(Object.assign({}, init), { headers }));
|
|
32
|
+
if (res.status === 200) {
|
|
33
|
+
const json = yield res.json();
|
|
34
|
+
return Promise.resolve(json);
|
|
35
|
+
}
|
|
36
|
+
const body = yield res.text();
|
|
37
|
+
try {
|
|
38
|
+
const json = JSON.parse(body);
|
|
39
|
+
return Promise.reject(new InstantAPIError({ status: res.status, body: json }));
|
|
40
|
+
}
|
|
41
|
+
catch (_e) {
|
|
42
|
+
return Promise.reject(new InstantAPIError({
|
|
43
|
+
status: res.status,
|
|
44
|
+
body: { type: undefined, message: body },
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
});
|
|
31
48
|
}
|
|
32
49
|
function attrDefForType(type) {
|
|
33
50
|
switch (type) {
|
|
@@ -50,7 +67,7 @@ function attrDefForType(type) {
|
|
|
50
67
|
}
|
|
51
68
|
}
|
|
52
69
|
function apiSchemaAttrToDataAttrDef(attr, opts) {
|
|
53
|
-
const derivedType = deriveClientType(attr, opts
|
|
70
|
+
const derivedType = deriveClientType(attr, opts === null || opts === void 0 ? void 0 : opts.disableTypeInference);
|
|
54
71
|
let i = attrDefForType(derivedType.type);
|
|
55
72
|
if (attr['unique?']) {
|
|
56
73
|
i = i.unique();
|
|
@@ -114,13 +131,7 @@ export function apiSchemaToInstantSchemaDef(apiSchema, opts) {
|
|
|
114
131
|
return i.schema({ entities, links });
|
|
115
132
|
}
|
|
116
133
|
function coerceApp(app) {
|
|
117
|
-
const base = {
|
|
118
|
-
id: app.id,
|
|
119
|
-
title: app.title,
|
|
120
|
-
createdAt: new Date(app.created_at),
|
|
121
|
-
orgId: app.org_id,
|
|
122
|
-
...(app['admin-token'] ? { adminToken: app['admin-token'] } : {}),
|
|
123
|
-
};
|
|
134
|
+
const base = Object.assign({ id: app.id, title: app.title, createdAt: new Date(app.created_at), orgId: app.org_id }, (app['admin-token'] ? { adminToken: app['admin-token'] } : {}));
|
|
124
135
|
// `in` narrows the union, so it’s safe to read `perms` / `schema`
|
|
125
136
|
// when the property exists. :contentReference[oaicite:0]{index=0}
|
|
126
137
|
const permsPart = ('perms' in app ? { perms: app.perms } : {});
|
|
@@ -129,7 +140,7 @@ function coerceApp(app) {
|
|
|
129
140
|
schema: apiSchemaToInstantSchemaDef(app.schema),
|
|
130
141
|
}
|
|
131
142
|
: {});
|
|
132
|
-
return {
|
|
143
|
+
return Object.assign(Object.assign(Object.assign({}, base), permsPart), schemaPart);
|
|
133
144
|
}
|
|
134
145
|
function coerceOrg(org) {
|
|
135
146
|
return {
|
|
@@ -138,157 +149,167 @@ function coerceOrg(org) {
|
|
|
138
149
|
createdAt: new Date(org.created_at),
|
|
139
150
|
};
|
|
140
151
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
152
|
+
function getApps(apiURI, token, opts) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
const url = new URL(`${apiURI}/superadmin/apps`);
|
|
155
|
+
const include = [];
|
|
156
|
+
if (opts === null || opts === void 0 ? void 0 : opts.includePerms) {
|
|
157
|
+
include.push('perms');
|
|
158
|
+
}
|
|
159
|
+
if (opts === null || opts === void 0 ? void 0 : opts.includeSchema) {
|
|
160
|
+
include.push('schema');
|
|
161
|
+
}
|
|
162
|
+
if (include.length) {
|
|
163
|
+
url.searchParams.set('include', include.join(','));
|
|
164
|
+
}
|
|
165
|
+
const resp = yield jsonFetch(url.toString(), {
|
|
166
|
+
method: 'GET',
|
|
167
|
+
headers: {
|
|
168
|
+
Authorization: `Bearer ${token}`,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
return { apps: resp.apps.map(coerceApp) };
|
|
158
172
|
});
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
173
|
+
}
|
|
174
|
+
function getOrgs(apiURI, token) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
const url = new URL(`${apiURI}/superadmin/orgs`);
|
|
177
|
+
const resp = yield jsonFetch(url.toString(), {
|
|
178
|
+
method: 'GET',
|
|
179
|
+
headers: {
|
|
180
|
+
Authorization: `Bearer ${token}`,
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
return { orgs: resp.orgs.map(coerceOrg) };
|
|
168
184
|
});
|
|
169
|
-
return { orgs: resp.orgs.map(coerceOrg) };
|
|
170
185
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
function getAppsForOrg(apiURI, token, orgId, opts) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const url = new URL(`${apiURI}/superadmin/orgs/${orgId}/apps`);
|
|
189
|
+
const include = [];
|
|
190
|
+
if (opts === null || opts === void 0 ? void 0 : opts.includePerms) {
|
|
191
|
+
include.push('perms');
|
|
192
|
+
}
|
|
193
|
+
if (opts === null || opts === void 0 ? void 0 : opts.includeSchema) {
|
|
194
|
+
include.push('schema');
|
|
195
|
+
}
|
|
196
|
+
if (include.length) {
|
|
197
|
+
url.searchParams.set('include', include.join(','));
|
|
198
|
+
}
|
|
199
|
+
const resp = yield jsonFetch(url.toString(), {
|
|
200
|
+
method: 'GET',
|
|
201
|
+
headers: {
|
|
202
|
+
Authorization: `Bearer ${token}`,
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
return { apps: resp.apps.map(coerceApp) };
|
|
188
206
|
});
|
|
189
|
-
return { apps: resp.apps.map(coerceApp) };
|
|
190
207
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
208
|
+
function getAppSchema(apiURI, token, appId) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
const { schema } = yield jsonFetch(`${apiURI}/superadmin/apps/${appId}/schema`, {
|
|
211
|
+
method: 'GET',
|
|
212
|
+
headers: {
|
|
213
|
+
Authorization: `Bearer ${token}`,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
return { schema: apiSchemaToInstantSchemaDef(schema) };
|
|
197
217
|
});
|
|
198
|
-
return { schema: apiSchemaToInstantSchemaDef(schema) };
|
|
199
218
|
}
|
|
200
|
-
|
|
201
|
-
return
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
219
|
+
function getAppPerms(apiURI, token, appId) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
return yield jsonFetch(`${apiURI}/superadmin/apps/${appId}/perms`, {
|
|
222
|
+
method: 'GET',
|
|
223
|
+
headers: {
|
|
224
|
+
Authorization: `Bearer ${token}`,
|
|
225
|
+
},
|
|
226
|
+
});
|
|
206
227
|
});
|
|
207
228
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
229
|
+
function getApp(apiURI, token, appId, opts) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
let permsPromise = null;
|
|
232
|
+
let schemaPromise = null;
|
|
233
|
+
if (opts === null || opts === void 0 ? void 0 : opts.includePerms) {
|
|
234
|
+
permsPromise = getAppPerms(apiURI, token, appId);
|
|
235
|
+
}
|
|
236
|
+
if (opts === null || opts === void 0 ? void 0 : opts.includeSchema) {
|
|
237
|
+
schemaPromise = getAppSchema(apiURI, token, appId);
|
|
238
|
+
}
|
|
239
|
+
const { app: apiApp } = yield jsonFetch(`${apiURI}/superadmin/apps/${appId}`, {
|
|
240
|
+
method: 'GET',
|
|
241
|
+
headers: {
|
|
242
|
+
Authorization: `Bearer ${token}`,
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
if (!permsPromise && !schemaPromise) {
|
|
246
|
+
const app = coerceApp(apiApp);
|
|
247
|
+
return { app };
|
|
248
|
+
}
|
|
249
|
+
const app = Object.assign(Object.assign(Object.assign({}, coerceApp(apiApp)), (permsPromise ? { perms: (yield permsPromise).perms } : {})), (schemaPromise ? { schema: (yield schemaPromise).schema } : {}));
|
|
250
|
+
return {
|
|
251
|
+
app,
|
|
252
|
+
};
|
|
222
253
|
});
|
|
223
|
-
if (!permsPromise && !schemaPromise) {
|
|
224
|
-
const app = coerceApp(apiApp);
|
|
225
|
-
return { app };
|
|
226
|
-
}
|
|
227
|
-
const app = {
|
|
228
|
-
...coerceApp(apiApp),
|
|
229
|
-
...(permsPromise ? { perms: (await permsPromise).perms } : {}),
|
|
230
|
-
...(schemaPromise ? { schema: (await schemaPromise).schema } : {}),
|
|
231
|
-
};
|
|
232
|
-
return {
|
|
233
|
-
app,
|
|
234
|
-
};
|
|
235
254
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
255
|
+
function createApp(apiURI, token, fields) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const apiFields = fields;
|
|
258
|
+
apiFields.org_id = fields.orgId;
|
|
259
|
+
const { app } = yield jsonFetch(`${apiURI}/superadmin/apps`, {
|
|
260
|
+
method: 'POST',
|
|
261
|
+
headers: {
|
|
262
|
+
'Content-Type': 'application/json',
|
|
263
|
+
Authorization: `Bearer ${token}`,
|
|
264
|
+
},
|
|
265
|
+
body: JSON.stringify(apiFields),
|
|
266
|
+
});
|
|
267
|
+
const withAdminToken = Object.assign(Object.assign({}, coerceApp(app)), { adminToken: app['admin-token'] });
|
|
268
|
+
return {
|
|
269
|
+
app: withAdminToken,
|
|
270
|
+
};
|
|
246
271
|
});
|
|
247
|
-
const withAdminToken = {
|
|
248
|
-
...coerceApp(app),
|
|
249
|
-
adminToken: app['admin-token'],
|
|
250
|
-
};
|
|
251
|
-
return {
|
|
252
|
-
app: withAdminToken,
|
|
253
|
-
};
|
|
254
272
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
273
|
+
function createTemporaryApp(apiURI, fields) {
|
|
274
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
275
|
+
const response = yield jsonFetch(`${apiURI}/dash/apps/ephemeral`, {
|
|
276
|
+
method: 'POST',
|
|
277
|
+
headers: {
|
|
278
|
+
'Content-Type': 'application/json',
|
|
279
|
+
},
|
|
280
|
+
body: JSON.stringify(fields),
|
|
281
|
+
});
|
|
282
|
+
const withAdminToken = Object.assign(Object.assign({}, coerceApp(response.app)), { adminToken: response.app['admin-token'] });
|
|
283
|
+
return {
|
|
284
|
+
app: withAdminToken,
|
|
285
|
+
expiresMs: response.expires_ms,
|
|
286
|
+
};
|
|
262
287
|
});
|
|
263
|
-
const withAdminToken = {
|
|
264
|
-
...coerceApp(response.app),
|
|
265
|
-
adminToken: response.app['admin-token'],
|
|
266
|
-
};
|
|
267
|
-
return {
|
|
268
|
-
app: withAdminToken,
|
|
269
|
-
expiresMs: response.expires_ms,
|
|
270
|
-
};
|
|
271
288
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
289
|
+
function updateApp(apiURI, token, appId, fields) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
const { app } = yield jsonFetch(`${apiURI}/superadmin/apps/${appId}`, {
|
|
292
|
+
method: 'POST',
|
|
293
|
+
headers: {
|
|
294
|
+
'Content-Type': 'application/json',
|
|
295
|
+
Authorization: `Bearer ${token}`,
|
|
296
|
+
},
|
|
297
|
+
body: JSON.stringify(fields),
|
|
298
|
+
});
|
|
299
|
+
return { app: coerceApp(app) };
|
|
280
300
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
301
|
+
}
|
|
302
|
+
function deleteApp(apiURI, token, appId) {
|
|
303
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
304
|
+
const { app } = yield jsonFetch(`${apiURI}/superadmin/apps/${appId}`, {
|
|
305
|
+
method: 'DELETE',
|
|
306
|
+
headers: {
|
|
307
|
+
'Content-Type': 'application/json',
|
|
308
|
+
Authorization: `Bearer ${token}`,
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
return { app: coerceApp(app) };
|
|
290
312
|
});
|
|
291
|
-
return { app: coerceApp(app) };
|
|
292
313
|
}
|
|
293
314
|
function translatePlanStep(apiStep) {
|
|
294
315
|
const [stepType, stepParams] = apiStep;
|
|
@@ -414,29 +435,27 @@ function translatePushStep(apiStep, jobs) {
|
|
|
414
435
|
if (planStep.type !== backgroundJob.type) {
|
|
415
436
|
throw new Error('Invalid type');
|
|
416
437
|
}
|
|
417
|
-
return {
|
|
438
|
+
return Object.assign(Object.assign({}, planStep), { backgroundJob });
|
|
418
439
|
}
|
|
419
440
|
function translatePushSteps(apiSteps, jobs) {
|
|
420
441
|
return apiSteps.map((step) => translatePushStep(step, jobs));
|
|
421
442
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
443
|
+
function planSchemaPush(apiURI, token, appId, body) {
|
|
444
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
445
|
+
const resp = yield jsonFetch(`${apiURI}/superadmin/apps/${appId}/schema/push/plan`, {
|
|
446
|
+
method: 'POST',
|
|
447
|
+
headers: {
|
|
448
|
+
'Content-Type': 'application/json',
|
|
449
|
+
Authorization: `Bearer ${token}`,
|
|
450
|
+
},
|
|
451
|
+
body: JSON.stringify(Object.assign(Object.assign({}, body), { check_types: true, supports_background_updates: true })),
|
|
452
|
+
});
|
|
453
|
+
return {
|
|
454
|
+
newSchema: apiSchemaToInstantSchemaDef(resp['new-schema']),
|
|
455
|
+
currentSchema: apiSchemaToInstantSchemaDef(resp['current-schema']),
|
|
456
|
+
steps: translatePlanSteps(resp['steps']),
|
|
457
|
+
};
|
|
434
458
|
});
|
|
435
|
-
return {
|
|
436
|
-
newSchema: apiSchemaToInstantSchemaDef(resp['new-schema']),
|
|
437
|
-
currentSchema: apiSchemaToInstantSchemaDef(resp['current-schema']),
|
|
438
|
-
steps: translatePlanSteps(resp['steps']),
|
|
439
|
-
};
|
|
440
459
|
}
|
|
441
460
|
function allJobsComplete(jobs) {
|
|
442
461
|
return !!jobs.find((j) => j.job_status === 'completed' || j.job_status === 'errored');
|
|
@@ -453,44 +472,47 @@ function latestJobUpdate(jobs) {
|
|
|
453
472
|
}, null);
|
|
454
473
|
return res;
|
|
455
474
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
catch (e) {
|
|
482
|
-
if (errorCount > 3) {
|
|
483
|
-
throw e;
|
|
475
|
+
function jobFetchLoop(apiURI, token, appId, groupId, startingJobs, onFetch) {
|
|
476
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
477
|
+
let interval = 100;
|
|
478
|
+
let lastJobs = startingJobs;
|
|
479
|
+
let errorCount = 0;
|
|
480
|
+
while (!allJobsComplete(lastJobs)) {
|
|
481
|
+
yield new Promise((resolve) => setTimeout(resolve, interval));
|
|
482
|
+
try {
|
|
483
|
+
const nextJobs = (yield jsonFetch(`${apiURI}/dash/apps/${appId}/indexing-jobs/group/${groupId}`, {
|
|
484
|
+
method: 'GET',
|
|
485
|
+
headers: {
|
|
486
|
+
Authorization: `Bearer ${token}`,
|
|
487
|
+
},
|
|
488
|
+
})).jobs;
|
|
489
|
+
onFetch(nextJobs);
|
|
490
|
+
if (allJobsComplete(nextJobs)) {
|
|
491
|
+
return nextJobs;
|
|
492
|
+
}
|
|
493
|
+
errorCount = 0;
|
|
494
|
+
const lastUpdate = latestJobUpdate(lastJobs);
|
|
495
|
+
const thisUpdate = latestJobUpdate(nextJobs);
|
|
496
|
+
interval =
|
|
497
|
+
thisUpdate === null || (lastUpdate && lastUpdate >= thisUpdate)
|
|
498
|
+
? Math.min(interval * 2, 10000)
|
|
499
|
+
: 100;
|
|
484
500
|
}
|
|
485
|
-
|
|
486
|
-
errorCount
|
|
487
|
-
|
|
501
|
+
catch (e) {
|
|
502
|
+
if (errorCount > 3) {
|
|
503
|
+
throw e;
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
errorCount++;
|
|
507
|
+
interval = Math.min(interval * 2, 10000);
|
|
508
|
+
}
|
|
488
509
|
}
|
|
489
510
|
}
|
|
490
|
-
|
|
491
|
-
|
|
511
|
+
return lastJobs;
|
|
512
|
+
});
|
|
492
513
|
}
|
|
493
514
|
function formatJob(job) {
|
|
515
|
+
var _a;
|
|
494
516
|
const baseJob = {
|
|
495
517
|
id: job.id,
|
|
496
518
|
createdAt: new Date(job.created_at),
|
|
@@ -499,7 +521,7 @@ function formatJob(job) {
|
|
|
499
521
|
workEstimate: job.work_estimate,
|
|
500
522
|
workCompleted: job.work_completed,
|
|
501
523
|
error: job.error,
|
|
502
|
-
invalidTriplesSample: job.invalid_triples_sample
|
|
524
|
+
invalidTriplesSample: (_a = job.invalid_triples_sample) === null || _a === void 0 ? void 0 : _a.map((s) => {
|
|
503
525
|
return { entityId: s.entity_id, value: s.value, jsonType: s.json_type };
|
|
504
526
|
}),
|
|
505
527
|
};
|
|
@@ -510,21 +532,13 @@ function formatJob(job) {
|
|
|
510
532
|
case 'required':
|
|
511
533
|
case 'remove-required':
|
|
512
534
|
case 'remove-unique': {
|
|
513
|
-
return {
|
|
535
|
+
return Object.assign(Object.assign({}, baseJob), { type: job.job_type });
|
|
514
536
|
}
|
|
515
537
|
case 'check-data-type': {
|
|
516
|
-
return {
|
|
517
|
-
...baseJob,
|
|
518
|
-
type: job.job_type,
|
|
519
|
-
checkedDataType: job.checked_data_type,
|
|
520
|
-
};
|
|
538
|
+
return Object.assign(Object.assign({}, baseJob), { type: job.job_type, checkedDataType: job.checked_data_type });
|
|
521
539
|
}
|
|
522
540
|
case 'unique': {
|
|
523
|
-
return {
|
|
524
|
-
...baseJob,
|
|
525
|
-
type: job.job_type,
|
|
526
|
-
invalidUniqueValue: job.invalid_unique_value,
|
|
527
|
-
};
|
|
541
|
+
return Object.assign(Object.assign({}, baseJob), { type: job.job_type, invalidUniqueValue: job.invalid_unique_value });
|
|
528
542
|
}
|
|
529
543
|
default: {
|
|
530
544
|
const neverType = job.job_type;
|
|
@@ -555,27 +569,23 @@ function stepSummary(steps) {
|
|
|
555
569
|
};
|
|
556
570
|
}
|
|
557
571
|
function schemaPush(apiURI, token, appId, body) {
|
|
558
|
-
return new ProgressPromise(
|
|
572
|
+
return new ProgressPromise((progress, resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
559
573
|
try {
|
|
560
|
-
const resp =
|
|
574
|
+
const resp = yield jsonFetch(`${apiURI}/superadmin/apps/${appId}/schema/push/apply`, {
|
|
561
575
|
method: 'POST',
|
|
562
576
|
headers: {
|
|
563
577
|
'Content-Type': 'application/json',
|
|
564
578
|
Authorization: `Bearer ${token}`,
|
|
565
579
|
},
|
|
566
|
-
body: JSON.stringify({
|
|
567
|
-
...body,
|
|
568
|
-
check_types: true,
|
|
569
|
-
supports_background_updates: true,
|
|
570
|
-
}),
|
|
580
|
+
body: JSON.stringify(Object.assign(Object.assign({}, body), { check_types: true, supports_background_updates: true })),
|
|
571
581
|
});
|
|
572
582
|
const indexingJobs = resp['indexing-jobs'];
|
|
573
583
|
const jobs = !indexingJobs
|
|
574
584
|
? []
|
|
575
|
-
:
|
|
585
|
+
: yield jobFetchLoop(apiURI, token, appId, indexingJobs['group-id'], indexingJobs['jobs'], (jobs) => {
|
|
576
586
|
progress(stepSummary(translatePushSteps(resp.steps, jobs)));
|
|
577
587
|
});
|
|
578
|
-
const schemaRes =
|
|
588
|
+
const schemaRes = yield getAppSchema(apiURI, token, appId);
|
|
579
589
|
resolve({
|
|
580
590
|
newSchema: schemaRes.schema,
|
|
581
591
|
steps: translatePushSteps(resp.steps, jobs),
|
|
@@ -585,28 +595,32 @@ function schemaPush(apiURI, token, appId, body) {
|
|
|
585
595
|
catch (e) {
|
|
586
596
|
reject(e);
|
|
587
597
|
}
|
|
588
|
-
});
|
|
598
|
+
}));
|
|
589
599
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
600
|
+
function pushPerms(apiURI, token, appId, body) {
|
|
601
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
602
|
+
const result = yield jsonFetch(`${apiURI}/superadmin/apps/${appId}/perms`, {
|
|
603
|
+
method: 'POST',
|
|
604
|
+
headers: {
|
|
605
|
+
'Content-Type': 'application/json',
|
|
606
|
+
Authorization: `Bearer ${token}`,
|
|
607
|
+
},
|
|
608
|
+
body: JSON.stringify({ code: body.perms }),
|
|
609
|
+
});
|
|
610
|
+
return { perms: result.rules.code };
|
|
598
611
|
});
|
|
599
|
-
return { perms: result.rules.code };
|
|
600
612
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
613
|
+
function tokenInfo(apiURI, token) {
|
|
614
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
615
|
+
const result = yield jsonFetch(`${apiURI}/platform/oauth/token-info?access_token=${token}`, {
|
|
616
|
+
method: 'GET',
|
|
617
|
+
});
|
|
618
|
+
return {
|
|
619
|
+
tokenType: result.token_type,
|
|
620
|
+
scopes: result.scopes,
|
|
621
|
+
expiresAt: new Date(Date.now() + (result.expires_in - 60) * 1000),
|
|
622
|
+
};
|
|
604
623
|
});
|
|
605
|
-
return {
|
|
606
|
-
tokenType: result.token_type,
|
|
607
|
-
scopes: result.scopes,
|
|
608
|
-
expiresAt: new Date(Date.now() + (result.expires_in - 60) * 1000),
|
|
609
|
-
};
|
|
610
624
|
}
|
|
611
625
|
export class PlatformApiMissingAuthError extends Error {
|
|
612
626
|
constructor() {
|
|
@@ -629,8 +643,6 @@ export class PlatformApiMissingAuthError extends Error {
|
|
|
629
643
|
* ```
|
|
630
644
|
*/
|
|
631
645
|
export class PlatformApi {
|
|
632
|
-
#auth;
|
|
633
|
-
#apiURI;
|
|
634
646
|
/**
|
|
635
647
|
* @param config – Runtime configuration.
|
|
636
648
|
* @param config.auth.token – OAuth access-token obtained via the oauth flow
|
|
@@ -638,76 +650,83 @@ export class PlatformApi {
|
|
|
638
650
|
* @throws {Error} When `token` is missing.
|
|
639
651
|
*/
|
|
640
652
|
constructor(config) {
|
|
641
|
-
this
|
|
642
|
-
this
|
|
653
|
+
_PlatformApi_auth.set(this, void 0);
|
|
654
|
+
_PlatformApi_apiURI.set(this, void 0);
|
|
655
|
+
__classPrivateFieldSet(this, _PlatformApi_auth, config === null || config === void 0 ? void 0 : config.auth, "f");
|
|
656
|
+
__classPrivateFieldSet(this, _PlatformApi_apiURI, (config === null || config === void 0 ? void 0 : config.apiURI) || 'https://api.instantdb.com', "f");
|
|
643
657
|
}
|
|
644
658
|
token() {
|
|
645
|
-
if (!this
|
|
659
|
+
if (!__classPrivateFieldGet(this, _PlatformApi_auth, "f")) {
|
|
646
660
|
throw new PlatformApiMissingAuthError();
|
|
647
661
|
}
|
|
648
|
-
if ('token' in this
|
|
649
|
-
return this
|
|
662
|
+
if ('token' in __classPrivateFieldGet(this, _PlatformApi_auth, "f")) {
|
|
663
|
+
return __classPrivateFieldGet(this, _PlatformApi_auth, "f").token;
|
|
650
664
|
}
|
|
651
|
-
return this
|
|
665
|
+
return __classPrivateFieldGet(this, _PlatformApi_auth, "f").accessToken;
|
|
652
666
|
}
|
|
653
667
|
canRefreshToken() {
|
|
654
|
-
if (!this
|
|
668
|
+
if (!__classPrivateFieldGet(this, _PlatformApi_auth, "f")) {
|
|
655
669
|
throw new PlatformApiMissingAuthError();
|
|
656
670
|
}
|
|
657
|
-
return ('refreshToken' in this
|
|
658
|
-
'clientId' in this
|
|
659
|
-
'clientSecret' in this
|
|
660
|
-
this
|
|
661
|
-
this
|
|
662
|
-
this
|
|
671
|
+
return ('refreshToken' in __classPrivateFieldGet(this, _PlatformApi_auth, "f") &&
|
|
672
|
+
'clientId' in __classPrivateFieldGet(this, _PlatformApi_auth, "f") &&
|
|
673
|
+
'clientSecret' in __classPrivateFieldGet(this, _PlatformApi_auth, "f") &&
|
|
674
|
+
__classPrivateFieldGet(this, _PlatformApi_auth, "f").refreshToken != null &&
|
|
675
|
+
__classPrivateFieldGet(this, _PlatformApi_auth, "f").clientId != null &&
|
|
676
|
+
__classPrivateFieldGet(this, _PlatformApi_auth, "f").clientSecret != null);
|
|
663
677
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
678
|
+
refreshToken() {
|
|
679
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
680
|
+
if (!__classPrivateFieldGet(this, _PlatformApi_auth, "f")) {
|
|
681
|
+
throw new PlatformApiMissingAuthError();
|
|
682
|
+
}
|
|
683
|
+
if (!this.canRefreshToken() ||
|
|
684
|
+
// Checked in canRefreshToken, but this lets
|
|
685
|
+
// typescript refine this.#auth here
|
|
686
|
+
!('clientId' in __classPrivateFieldGet(this, _PlatformApi_auth, "f"))) {
|
|
687
|
+
return null;
|
|
688
|
+
}
|
|
689
|
+
const token = yield exchangeRefreshToken({
|
|
690
|
+
apiURI: __classPrivateFieldGet(this, _PlatformApi_apiURI, "f"),
|
|
691
|
+
clientId: __classPrivateFieldGet(this, _PlatformApi_auth, "f").clientId,
|
|
692
|
+
clientSecret: __classPrivateFieldGet(this, _PlatformApi_auth, "f").clientSecret,
|
|
693
|
+
refreshToken: __classPrivateFieldGet(this, _PlatformApi_auth, "f").refreshToken,
|
|
694
|
+
});
|
|
695
|
+
__classPrivateFieldGet(this, _PlatformApi_auth, "f").accessToken = token.accessToken;
|
|
696
|
+
if (__classPrivateFieldGet(this, _PlatformApi_auth, "f").onRefresh) {
|
|
697
|
+
yield __classPrivateFieldGet(this, _PlatformApi_auth, "f").onRefresh(token);
|
|
698
|
+
}
|
|
699
|
+
return token;
|
|
679
700
|
});
|
|
680
|
-
this.#auth.accessToken = token.accessToken;
|
|
681
|
-
if (this.#auth.onRefresh) {
|
|
682
|
-
await this.#auth.onRefresh(token);
|
|
683
|
-
}
|
|
684
|
-
return token;
|
|
685
701
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
(e.
|
|
699
|
-
e.body.
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
702
|
+
withRetry(f, args) {
|
|
703
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
704
|
+
var _a, _b;
|
|
705
|
+
let attempt = 0;
|
|
706
|
+
const [apiURI, tokenInArg, ...restArgs] = args;
|
|
707
|
+
let token = tokenInArg;
|
|
708
|
+
while (attempt < 2) {
|
|
709
|
+
try {
|
|
710
|
+
return yield f(apiURI, token, ...restArgs);
|
|
711
|
+
}
|
|
712
|
+
catch (e) {
|
|
713
|
+
if (e instanceof InstantAPIError &&
|
|
714
|
+
(e.status === 401 ||
|
|
715
|
+
((_a = e.body) === null || _a === void 0 ? void 0 : _a.type) === 'record-expired' ||
|
|
716
|
+
(((_b = e.body) === null || _b === void 0 ? void 0 : _b.type) === 'record-not-found' &&
|
|
717
|
+
e.body.hint['record-type'].match(/token/i))) &&
|
|
718
|
+
this.canRefreshToken()) {
|
|
719
|
+
const refreshedToken = yield this.refreshToken();
|
|
720
|
+
if (refreshedToken) {
|
|
721
|
+
token = refreshedToken.accessToken;
|
|
722
|
+
attempt++;
|
|
723
|
+
continue;
|
|
724
|
+
}
|
|
706
725
|
}
|
|
726
|
+
throw e;
|
|
707
727
|
}
|
|
708
|
-
throw e;
|
|
709
728
|
}
|
|
710
|
-
}
|
|
729
|
+
});
|
|
711
730
|
}
|
|
712
731
|
/**
|
|
713
732
|
* Fetch a single app by its id.
|
|
@@ -726,8 +745,10 @@ export class PlatformApi {
|
|
|
726
745
|
* @returns A typed wrapper containing the app, whose shape is expanded
|
|
727
746
|
* according to `Opts`.
|
|
728
747
|
*/
|
|
729
|
-
|
|
730
|
-
return
|
|
748
|
+
getApp(appId, opts) {
|
|
749
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
750
|
+
return this.withRetry(getApp, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token(), appId, opts]);
|
|
751
|
+
});
|
|
731
752
|
}
|
|
732
753
|
/**
|
|
733
754
|
* List **all apps** owned by the auth owner.
|
|
@@ -743,8 +764,10 @@ export class PlatformApi {
|
|
|
743
764
|
* @param opts – `{ includeSchema?: boolean; includePerms?: boolean }`
|
|
744
765
|
* @returns An array wrapper; each element’s shape follows `Opts`.
|
|
745
766
|
*/
|
|
746
|
-
|
|
747
|
-
return this
|
|
767
|
+
getApps(opts) {
|
|
768
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
769
|
+
return this.withRetry(getApps, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token(), opts]);
|
|
770
|
+
});
|
|
748
771
|
}
|
|
749
772
|
/**
|
|
750
773
|
* List **all orgs** that the auth owner is a member of.
|
|
@@ -755,8 +778,10 @@ export class PlatformApi {
|
|
|
755
778
|
*
|
|
756
779
|
* @returns An array of orgs
|
|
757
780
|
*/
|
|
758
|
-
|
|
759
|
-
return this
|
|
781
|
+
getOrgs() {
|
|
782
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
783
|
+
return this.withRetry(getOrgs, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token()]);
|
|
784
|
+
});
|
|
760
785
|
}
|
|
761
786
|
/**
|
|
762
787
|
* List **all apps** owned by the auth owner.
|
|
@@ -772,13 +797,15 @@ export class PlatformApi {
|
|
|
772
797
|
* @param opts – `{ includeSchema?: boolean; includePerms?: boolean }`
|
|
773
798
|
* @returns An array wrapper; each element’s shape follows `Opts`.
|
|
774
799
|
*/
|
|
775
|
-
|
|
776
|
-
return this
|
|
777
|
-
this
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
800
|
+
getAppsForOrg(orgId, opts) {
|
|
801
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
802
|
+
return this.withRetry(getAppsForOrg, [
|
|
803
|
+
__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"),
|
|
804
|
+
this.token(),
|
|
805
|
+
orgId,
|
|
806
|
+
opts,
|
|
807
|
+
]);
|
|
808
|
+
});
|
|
782
809
|
}
|
|
783
810
|
/**
|
|
784
811
|
* Gets the schema for an app by its id.
|
|
@@ -789,8 +816,10 @@ export class PlatformApi {
|
|
|
789
816
|
*
|
|
790
817
|
* @param appId -- UUID of the app
|
|
791
818
|
*/
|
|
792
|
-
|
|
793
|
-
return this
|
|
819
|
+
getSchema(appId) {
|
|
820
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
821
|
+
return this.withRetry(getAppSchema, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token(), appId]);
|
|
822
|
+
});
|
|
794
823
|
}
|
|
795
824
|
/**
|
|
796
825
|
* Gets the permissions for an app by its id.
|
|
@@ -801,8 +830,10 @@ export class PlatformApi {
|
|
|
801
830
|
*
|
|
802
831
|
* @param appId -- UUID of the app
|
|
803
832
|
*/
|
|
804
|
-
|
|
805
|
-
return this
|
|
833
|
+
getPerms(appId) {
|
|
834
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
835
|
+
return this.withRetry(getAppPerms, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token(), appId]);
|
|
836
|
+
});
|
|
806
837
|
}
|
|
807
838
|
/**
|
|
808
839
|
* Create a new app.
|
|
@@ -830,8 +861,10 @@ export class PlatformApi {
|
|
|
830
861
|
* @param fields.perms -- Optional permissions for the app
|
|
831
862
|
* @param fields.orgId -- Optional id of the org that the app will be placed in
|
|
832
863
|
*/
|
|
833
|
-
|
|
834
|
-
return this
|
|
864
|
+
createApp(fields) {
|
|
865
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
866
|
+
return this.withRetry(createApp, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token(), fields]);
|
|
867
|
+
});
|
|
835
868
|
}
|
|
836
869
|
/**
|
|
837
870
|
* Create a new temporary app.
|
|
@@ -855,8 +888,10 @@ export class PlatformApi {
|
|
|
855
888
|
* @param fields.schema -- Optional schema for the app
|
|
856
889
|
* @param fields.perms -- Optional permissions for the app
|
|
857
890
|
*/
|
|
858
|
-
|
|
859
|
-
return
|
|
891
|
+
createTemporaryApp(fields) {
|
|
892
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
893
|
+
return createTemporaryApp(__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), fields);
|
|
894
|
+
});
|
|
860
895
|
}
|
|
861
896
|
/**
|
|
862
897
|
* Update the title of an app by its id.
|
|
@@ -870,13 +905,15 @@ export class PlatformApi {
|
|
|
870
905
|
* @param appId -- UUID of the app
|
|
871
906
|
* @param fields.title -- New title for the app
|
|
872
907
|
*/
|
|
873
|
-
|
|
874
|
-
return this
|
|
875
|
-
this
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
908
|
+
updateApp(appId, fields) {
|
|
909
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
910
|
+
return this.withRetry(updateApp, [
|
|
911
|
+
__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"),
|
|
912
|
+
this.token(),
|
|
913
|
+
appId,
|
|
914
|
+
fields,
|
|
915
|
+
]);
|
|
916
|
+
});
|
|
880
917
|
}
|
|
881
918
|
/**
|
|
882
919
|
* Delete an app by its id.
|
|
@@ -887,8 +924,10 @@ export class PlatformApi {
|
|
|
887
924
|
*
|
|
888
925
|
* @param appId -- UUID of the app
|
|
889
926
|
*/
|
|
890
|
-
|
|
891
|
-
return this
|
|
927
|
+
deleteApp(appId) {
|
|
928
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
929
|
+
return this.withRetry(deleteApp, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token(), appId]);
|
|
930
|
+
});
|
|
892
931
|
}
|
|
893
932
|
/**
|
|
894
933
|
* Dry-run a **schema push** and receive a _plan_ of steps the server would
|
|
@@ -898,13 +937,15 @@ export class PlatformApi {
|
|
|
898
937
|
* const { steps } = await api.planSchemaPush(appId, body);
|
|
899
938
|
* ```
|
|
900
939
|
*/
|
|
901
|
-
|
|
902
|
-
return this
|
|
903
|
-
this
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
940
|
+
planSchemaPush(appId, body) {
|
|
941
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
942
|
+
return this.withRetry(planSchemaPush, [
|
|
943
|
+
__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"),
|
|
944
|
+
this.token(),
|
|
945
|
+
appId,
|
|
946
|
+
body,
|
|
947
|
+
]);
|
|
948
|
+
});
|
|
908
949
|
}
|
|
909
950
|
/**
|
|
910
951
|
* Execute a **schema push**. The server returns a long-running job
|
|
@@ -933,19 +974,19 @@ export class PlatformApi {
|
|
|
933
974
|
* ```
|
|
934
975
|
*/
|
|
935
976
|
schemaPush(appId, body) {
|
|
936
|
-
if (!this
|
|
977
|
+
if (!__classPrivateFieldGet(this, _PlatformApi_auth, "f")) {
|
|
937
978
|
throw new PlatformApiMissingAuthError();
|
|
938
979
|
}
|
|
939
|
-
return new ProgressPromise(
|
|
980
|
+
return new ProgressPromise((progress, resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
940
981
|
// It's tricky to add withRetry to the background process that fetches the jobs,
|
|
941
982
|
// so we'll just refresh the token at the start.
|
|
942
983
|
if (this.canRefreshToken()) {
|
|
943
984
|
try {
|
|
944
|
-
|
|
985
|
+
yield this.refreshToken();
|
|
945
986
|
}
|
|
946
987
|
catch (_e) { }
|
|
947
988
|
}
|
|
948
|
-
schemaPush(this
|
|
989
|
+
schemaPush(__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token(), appId, body).subscribe({
|
|
949
990
|
complete(v) {
|
|
950
991
|
resolve(v);
|
|
951
992
|
},
|
|
@@ -956,7 +997,7 @@ export class PlatformApi {
|
|
|
956
997
|
progress(v);
|
|
957
998
|
},
|
|
958
999
|
});
|
|
959
|
-
});
|
|
1000
|
+
}));
|
|
960
1001
|
}
|
|
961
1002
|
/**
|
|
962
1003
|
* Update permission rules for an app by its id.
|
|
@@ -972,17 +1013,22 @@ export class PlatformApi {
|
|
|
972
1013
|
* });
|
|
973
1014
|
* ```
|
|
974
1015
|
*/
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1016
|
+
pushPerms(appId, body) {
|
|
1017
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1018
|
+
if (!__classPrivateFieldGet(this, _PlatformApi_auth, "f")) {
|
|
1019
|
+
throw new PlatformApiMissingAuthError();
|
|
1020
|
+
}
|
|
1021
|
+
return this.withRetry(pushPerms, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token(), appId, body]);
|
|
1022
|
+
});
|
|
980
1023
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1024
|
+
tokenInfo() {
|
|
1025
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1026
|
+
if (!__classPrivateFieldGet(this, _PlatformApi_auth, "f")) {
|
|
1027
|
+
throw new PlatformApiMissingAuthError();
|
|
1028
|
+
}
|
|
1029
|
+
return this.withRetry(tokenInfo, [__classPrivateFieldGet(this, _PlatformApi_apiURI, "f"), this.token()]);
|
|
1030
|
+
});
|
|
986
1031
|
}
|
|
987
1032
|
}
|
|
1033
|
+
_PlatformApi_auth = new WeakMap(), _PlatformApi_apiURI = new WeakMap();
|
|
988
1034
|
//# sourceMappingURL=api.js.map
|