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