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