@forge/bridge 5.6.1-next.6 → 5.7.0-next.11
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/CHANGELOG.md +30 -0
- package/out/featureFlags/featureFlagEvents.d.ts +3 -0
- package/out/featureFlags/featureFlagEvents.d.ts.map +1 -0
- package/out/featureFlags/featureFlagEvents.js +26 -0
- package/out/featureFlags/featureFlags.d.ts +4 -1
- package/out/featureFlags/featureFlags.d.ts.map +1 -1
- package/out/featureFlags/featureFlags.js +19 -0
- package/out/featureFlags/index.d.ts +0 -1
- package/out/featureFlags/index.d.ts.map +1 -1
- package/out/featureFlags/index.js +0 -2
- package/out/featureFlags/initFeatureFlags.js +1 -1
- package/out/object-store/delete.d.ts +5 -0
- package/out/object-store/delete.d.ts.map +1 -0
- package/out/object-store/delete.js +17 -0
- package/out/object-store/download.d.ts +6 -0
- package/out/object-store/download.d.ts.map +1 -0
- package/out/object-store/download.js +52 -0
- package/out/object-store/getMetadata.d.ts +6 -0
- package/out/object-store/getMetadata.d.ts.map +1 -0
- package/out/object-store/getMetadata.js +25 -0
- package/out/object-store/types.d.ts +38 -0
- package/out/object-store/types.d.ts.map +1 -0
- package/out/object-store/types.js +2 -0
- package/out/object-store/upload.d.ts +6 -0
- package/out/object-store/upload.d.ts.map +1 -0
- package/out/object-store/upload.js +76 -0
- package/out/types.d.ts +13 -0
- package/out/types.d.ts.map +1 -1
- package/out/types.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @forge/bridge
|
|
2
2
|
|
|
3
|
+
## 5.7.0-next.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 18a7e05: Add Track Events for Feature flags
|
|
8
|
+
|
|
9
|
+
## 5.7.0-next.10
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- eda5e4f: Adds new bridge method objectStore.delete
|
|
14
|
+
|
|
15
|
+
## 5.7.0-next.9
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- a03c9c5: Adds new bridge method objectStore.getMetadata
|
|
20
|
+
|
|
21
|
+
## 5.7.0-next.8
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- 6e14850: Added FOS download bridge method
|
|
26
|
+
|
|
27
|
+
## 5.7.0-next.7
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- be6eab0: Add OS upload bridge method
|
|
32
|
+
|
|
3
33
|
## 5.6.1-next.6
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"featureFlagEvents.d.ts","sourceRoot":"","sources":["../../src/featureFlags/featureFlagEvents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,4BAA4B,EAAwB,MAAM,UAAU,CAAC;AA8B9E,eAAO,MAAM,qBAAqB,0DAKjC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trackFeatureFlagEvent = void 0;
|
|
4
|
+
const bridge_1 = require("../bridge");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const maxOps = 500;
|
|
9
|
+
const intervalInMs = 1000 * 25;
|
|
10
|
+
const callBridge = (0, bridge_1.getCallBridge)();
|
|
11
|
+
const validatePayload = (payload) => {
|
|
12
|
+
if (!payload || !payload.type || !payload.properties) {
|
|
13
|
+
throw new errors_1.BridgeAPIError('Missing required parameters. Parameter type, and properties are required in the payload.');
|
|
14
|
+
}
|
|
15
|
+
if (!(payload.type.toUpperCase() in types_1.FeatureFlagEventType)) {
|
|
16
|
+
throw new errors_1.BridgeAPIError('Event type is not supported');
|
|
17
|
+
}
|
|
18
|
+
if (Object.values(payload).some((val) => typeof val === 'function')) {
|
|
19
|
+
throw new errors_1.BridgeAPIError('Passing functions as part of the payload is not supported!');
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const _trackFeatureFlagEvent = (payload) => {
|
|
23
|
+
validatePayload(payload);
|
|
24
|
+
return callBridge('trackFeatureFlagEvent', payload);
|
|
25
|
+
};
|
|
26
|
+
exports.trackFeatureFlagEvent = (0, utils_1.withRateLimiter)(_trackFeatureFlagEvent, maxOps, intervalInMs, `Feature flags calls are rate limited at ${maxOps}req/${intervalInMs / 1000}s`);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { FeatureFlagEnvironment } from '../types';
|
|
1
2
|
export interface ForgeFeatureFlagConfig {
|
|
2
|
-
environment?:
|
|
3
|
+
environment?: FeatureFlagEnvironment;
|
|
3
4
|
}
|
|
4
5
|
export interface FeatureFlagUser {
|
|
5
6
|
userId?: string;
|
|
@@ -20,11 +21,13 @@ export declare class ForgeFeatureFlags {
|
|
|
20
21
|
private initialized;
|
|
21
22
|
private client;
|
|
22
23
|
private dataAdapter;
|
|
24
|
+
private eventProps;
|
|
23
25
|
private readonly CLIENT_KEY;
|
|
24
26
|
initialize(user: FeatureFlagUser, config?: ForgeFeatureFlagConfig): Promise<void>;
|
|
25
27
|
checkFlag(flagName: string): boolean;
|
|
26
28
|
shutdown(): Promise<void>;
|
|
27
29
|
isInitialized(): boolean;
|
|
28
30
|
private convertUser;
|
|
31
|
+
private sendCheckFlagEvent;
|
|
29
32
|
}
|
|
30
33
|
//# sourceMappingURL=featureFlags.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featureFlags.d.ts","sourceRoot":"","sources":["../../src/featureFlags/featureFlags.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"featureFlags.d.ts","sourceRoot":"","sources":["../../src/featureFlags/featureFlags.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,sBAAsB,EACvB,MAAM,UAAU,CAAC;AAGlB,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,sBAAsB,CAAC;CACtC;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IACzC,UAAU,CAAC,EAAE;QACX,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,WAAW,CAAC,EAAE;QACZ,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAID,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuC;IAKrD,UAAU,CAAC,IAAI,EAAE,eAAe,EAAE,MAAM,GAAE,sBAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB3F,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAa9B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAa/B,aAAa;IAIpB,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,kBAAkB;CAa3B"}
|
|
@@ -3,14 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ForgeFeatureFlags = void 0;
|
|
4
4
|
const js_client_1 = require("@statsig/js-client");
|
|
5
5
|
const dataAdapter_1 = require("./dataAdapter");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const featureFlagEvents_1 = require("./featureFlagEvents");
|
|
6
8
|
class ForgeFeatureFlags {
|
|
7
9
|
constructor() {
|
|
8
10
|
this.initialized = false;
|
|
9
11
|
this.client = null;
|
|
10
12
|
this.dataAdapter = null;
|
|
13
|
+
this.eventProps = {};
|
|
11
14
|
this.CLIENT_KEY = 'client-forge-internal-key';
|
|
12
15
|
}
|
|
13
16
|
async initialize(user, config = {}) {
|
|
17
|
+
var _a;
|
|
14
18
|
if (this.isInitialized()) {
|
|
15
19
|
return;
|
|
16
20
|
}
|
|
@@ -22,14 +26,17 @@ class ForgeFeatureFlags {
|
|
|
22
26
|
logLevel: js_client_1.LogLevel.None,
|
|
23
27
|
dataAdapter: this.dataAdapter
|
|
24
28
|
};
|
|
29
|
+
this.eventProps.environment = (_a = options.environment) === null || _a === void 0 ? void 0 : _a.tier;
|
|
25
30
|
this.client = new js_client_1.StatsigClient(this.CLIENT_KEY, this.convertUser(user), options);
|
|
26
31
|
await this.client.initializeAsync();
|
|
27
32
|
this.initialized = true;
|
|
28
33
|
}
|
|
29
34
|
checkFlag(flagName) {
|
|
30
35
|
if (!this.isInitialized() || !this.client) {
|
|
36
|
+
this.sendCheckFlagEvent(flagName, false);
|
|
31
37
|
throw new Error('ForgeFeatureFlags not initialized. Call initialize() first.');
|
|
32
38
|
}
|
|
39
|
+
this.sendCheckFlagEvent(flagName, true);
|
|
33
40
|
return this.client.checkGate(flagName, { disableExposureLog: true });
|
|
34
41
|
}
|
|
35
42
|
async shutdown() {
|
|
@@ -52,5 +59,17 @@ class ForgeFeatureFlags {
|
|
|
52
59
|
customIDs: user.identifiers || {}
|
|
53
60
|
};
|
|
54
61
|
}
|
|
62
|
+
sendCheckFlagEvent(flagName, success) {
|
|
63
|
+
const props = {
|
|
64
|
+
type: types_1.FeatureFlagEventType.CHECKFLAG,
|
|
65
|
+
properties: {
|
|
66
|
+
...this.eventProps,
|
|
67
|
+
environment: this.eventProps.environment || 'development',
|
|
68
|
+
name: flagName,
|
|
69
|
+
success
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
void (0, featureFlagEvents_1.trackFeatureFlagEvent)(props);
|
|
73
|
+
}
|
|
55
74
|
}
|
|
56
75
|
exports.ForgeFeatureFlags = ForgeFeatureFlags;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/featureFlags/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/featureFlags/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ForgeFeatureFlags = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
tslib_1.__exportStar(require("./initFeatureFlags"), exports);
|
|
6
4
|
var featureFlags_1 = require("./featureFlags");
|
|
7
5
|
Object.defineProperty(exports, "ForgeFeatureFlags", { enumerable: true, get: function () { return featureFlags_1.ForgeFeatureFlags; } });
|
|
@@ -19,4 +19,4 @@ const _initFeatureFlags = (payload) => {
|
|
|
19
19
|
validatePayload(payload);
|
|
20
20
|
return callBridge('initFeatureFlags', { user: payload.user });
|
|
21
21
|
};
|
|
22
|
-
exports.initFeatureFlags = (0, utils_1.withRateLimiter)(_initFeatureFlags, maxOps, intervalInMs,
|
|
22
|
+
exports.initFeatureFlags = (0, utils_1.withRateLimiter)(_initFeatureFlags, maxOps, intervalInMs, `Feature flags initialisation calls are rate limited at ${maxOps}req/${intervalInMs / 1000}s`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../src/object-store/delete.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,aAAa;iBAAgD,MAAM;UAAQ,MAAM,EAAE;MAAK,QAAQ,IAAI,CAchH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteObjects = void 0;
|
|
4
|
+
const invoke_1 = require("../invoke");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const deleteObjects = async ({ functionKey, keys }) => {
|
|
7
|
+
if (!functionKey || functionKey.length === 0) {
|
|
8
|
+
throw new errors_1.BridgeAPIError('functionKey is required to delete objects');
|
|
9
|
+
}
|
|
10
|
+
if (!Array.isArray(keys) || keys.length === 0) {
|
|
11
|
+
throw new errors_1.BridgeAPIError('keys array is required and must not be empty');
|
|
12
|
+
}
|
|
13
|
+
await Promise.all(keys.map(async (key) => {
|
|
14
|
+
await (0, invoke_1.invoke)(functionKey, { key });
|
|
15
|
+
}));
|
|
16
|
+
};
|
|
17
|
+
exports.deleteObjects = deleteObjects;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/object-store/download.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAsB,MAAM,SAAS,CAAC;AAUlE,eAAO,MAAM,QAAQ;iBAIN,MAAM;UACb,MAAM,EAAE;MACZ,QAAQ,cAAc,EAAE,CAqD3B,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.download = void 0;
|
|
4
|
+
const invoke_1 = require("../invoke");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const download = async ({ functionKey, keys }) => {
|
|
7
|
+
if (!functionKey || functionKey.length === 0) {
|
|
8
|
+
throw new errors_1.BridgeAPIError('functionKey is required to filter and generate download URLs');
|
|
9
|
+
}
|
|
10
|
+
if (!Array.isArray(keys) || keys.length === 0) {
|
|
11
|
+
throw new errors_1.BridgeAPIError('keys array is required and must not be empty');
|
|
12
|
+
}
|
|
13
|
+
const downloadUrlsTokeys = (await (0, invoke_1.invoke)(functionKey, {
|
|
14
|
+
keys
|
|
15
|
+
}));
|
|
16
|
+
if (!downloadUrlsTokeys || typeof downloadUrlsTokeys !== 'object') {
|
|
17
|
+
throw new errors_1.BridgeAPIError('Invalid response from functionKey');
|
|
18
|
+
}
|
|
19
|
+
const downloadPromises = Object.entries(downloadUrlsTokeys).map(async ([downloadUrl, key]) => {
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(downloadUrl, {
|
|
22
|
+
method: 'GET'
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
key: key,
|
|
28
|
+
status: response.status,
|
|
29
|
+
error: `Download failed with status ${response.status}`
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const blob = await response.blob();
|
|
33
|
+
return {
|
|
34
|
+
success: true,
|
|
35
|
+
key: key,
|
|
36
|
+
blob,
|
|
37
|
+
status: response.status
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return {
|
|
42
|
+
success: false,
|
|
43
|
+
key: key,
|
|
44
|
+
status: 503,
|
|
45
|
+
error: error instanceof Error ? error.message : 'Download failed'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const results = await Promise.all(downloadPromises);
|
|
50
|
+
return results;
|
|
51
|
+
};
|
|
52
|
+
exports.download = download;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMetadata.d.ts","sourceRoot":"","sources":["../../src/object-store/getMetadata.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAUjD,eAAO,MAAM,WAAW;iBAIT,MAAM;UACb,MAAM,EAAE;MACZ,QAAQ,iBAAiB,EAAE,CAyB9B,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMetadata = void 0;
|
|
4
|
+
const invoke_1 = require("../invoke");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const getMetadata = async ({ functionKey, keys }) => {
|
|
7
|
+
if (!functionKey || functionKey.length === 0) {
|
|
8
|
+
throw new errors_1.BridgeAPIError('functionKey is required to filter and generate object metadata');
|
|
9
|
+
}
|
|
10
|
+
if (!Array.isArray(keys) || keys.length === 0) {
|
|
11
|
+
throw new errors_1.BridgeAPIError('keys array is required and must not be empty');
|
|
12
|
+
}
|
|
13
|
+
const results = await Promise.all(keys.map(async (key) => {
|
|
14
|
+
const result = (await (0, invoke_1.invoke)(functionKey, { key }));
|
|
15
|
+
if (!result || typeof result !== 'object') {
|
|
16
|
+
return {
|
|
17
|
+
key: key,
|
|
18
|
+
error: 'Invalid response from functionKey'
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}));
|
|
23
|
+
return results;
|
|
24
|
+
};
|
|
25
|
+
exports.getMetadata = getMetadata;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare type ObjectMetadata = {
|
|
2
|
+
length: number;
|
|
3
|
+
checksum: string;
|
|
4
|
+
checksumType: string;
|
|
5
|
+
};
|
|
6
|
+
export declare type FileMetadata = ObjectMetadata & {
|
|
7
|
+
key: string;
|
|
8
|
+
ttlSeconds?: number;
|
|
9
|
+
overwrite?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare type UploadResult = {
|
|
12
|
+
success: boolean;
|
|
13
|
+
key: string;
|
|
14
|
+
status?: number;
|
|
15
|
+
error?: string;
|
|
16
|
+
};
|
|
17
|
+
export declare type DownloadResult = {
|
|
18
|
+
success: boolean;
|
|
19
|
+
key: string;
|
|
20
|
+
blob?: Blob;
|
|
21
|
+
status?: number;
|
|
22
|
+
error?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare type PresignedURLMapping = {
|
|
25
|
+
[url: string]: FileMetadata;
|
|
26
|
+
};
|
|
27
|
+
export declare type DownloadURLMapping = {
|
|
28
|
+
[url: string]: string;
|
|
29
|
+
};
|
|
30
|
+
export declare type GetMetadataResult = {
|
|
31
|
+
key: string;
|
|
32
|
+
checksum?: string;
|
|
33
|
+
size?: number;
|
|
34
|
+
createdAt?: string;
|
|
35
|
+
currentVersion?: string;
|
|
36
|
+
error?: string;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/object-store/types.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,oBAAY,YAAY,GAAG,cAAc,GAAG;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,oBAAY,YAAY,GAAG;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,cAAc,GAAG;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,oBAAY,mBAAmB,GAAG;IAChC,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CAAC;CAC7B,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/object-store/upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAuC,YAAY,EAAE,MAAM,SAAS,CAAC;AA8BjF,eAAO,MAAM,MAAM;iBAIJ,MAAM;aACV,IAAI,EAAE;MACb,QAAQ,YAAY,EAAE,CAkEzB,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upload = void 0;
|
|
4
|
+
const invoke_1 = require("../invoke");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const getObjectMetadata = async (blob) => {
|
|
7
|
+
const length = blob.size;
|
|
8
|
+
const arrayBuffer = await blob.arrayBuffer();
|
|
9
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', arrayBuffer);
|
|
10
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
11
|
+
const checksum = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
12
|
+
const checksumType = 'SHA-256';
|
|
13
|
+
return {
|
|
14
|
+
length,
|
|
15
|
+
checksum,
|
|
16
|
+
checksumType
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const upload = async ({ functionKey, objects }) => {
|
|
20
|
+
if (!functionKey || functionKey.length === 0) {
|
|
21
|
+
throw new errors_1.BridgeAPIError('functionKey is required to filter and generate presigned URLs');
|
|
22
|
+
}
|
|
23
|
+
if (!Array.isArray(objects) || objects.length === 0) {
|
|
24
|
+
throw new errors_1.BridgeAPIError('objects array is required and must not be empty');
|
|
25
|
+
}
|
|
26
|
+
const allObjectMetadata = await Promise.all(objects.map((obj) => getObjectMetadata(obj)));
|
|
27
|
+
const presignedURLsToObjectMetadata = (await (0, invoke_1.invoke)(functionKey, {
|
|
28
|
+
allObjectMetadata
|
|
29
|
+
}));
|
|
30
|
+
if (!presignedURLsToObjectMetadata || typeof presignedURLsToObjectMetadata !== 'object') {
|
|
31
|
+
throw new errors_1.BridgeAPIError('Invalid response from functionKey');
|
|
32
|
+
}
|
|
33
|
+
const checksumToBlobMap = new Map();
|
|
34
|
+
objects.forEach((blob, index) => {
|
|
35
|
+
const metadata = allObjectMetadata[index];
|
|
36
|
+
checksumToBlobMap.set(metadata.checksum, blob);
|
|
37
|
+
});
|
|
38
|
+
const uploadPromises = Object.entries(presignedURLsToObjectMetadata).map(async ([presignedUrl, metadata]) => {
|
|
39
|
+
const { key, length, checksum } = metadata;
|
|
40
|
+
const object = checksumToBlobMap.get(checksum);
|
|
41
|
+
if (!object) {
|
|
42
|
+
return {
|
|
43
|
+
success: false,
|
|
44
|
+
key: key,
|
|
45
|
+
error: `Blob not found for checksum ${checksum}`
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const response = await fetch(presignedUrl, {
|
|
50
|
+
method: 'PUT',
|
|
51
|
+
body: object,
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': object.type || 'application/octet-stream',
|
|
54
|
+
'Content-Length': length.toString()
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
success: response.ok,
|
|
59
|
+
key: key,
|
|
60
|
+
status: response.status,
|
|
61
|
+
error: response.ok ? undefined : `Upload failed with status ${response.status}`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
return {
|
|
66
|
+
success: false,
|
|
67
|
+
key: key,
|
|
68
|
+
status: 503,
|
|
69
|
+
error: error instanceof Error ? error.message : 'Upload failed'
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const results = await Promise.all(uploadPromises);
|
|
74
|
+
return results;
|
|
75
|
+
};
|
|
76
|
+
exports.upload = upload;
|
package/out/types.d.ts
CHANGED
|
@@ -66,6 +66,19 @@ export declare type InitFeatureFlagsPayload = {
|
|
|
66
66
|
user: StatsigUserInternal;
|
|
67
67
|
};
|
|
68
68
|
export declare type InitFeatureFlagsResponse = Record<string, any> | void;
|
|
69
|
+
export declare enum FeatureFlagEventType {
|
|
70
|
+
CHECKFLAG = "checkFlag"
|
|
71
|
+
}
|
|
72
|
+
export declare type FeatureFlagEnvironment = 'development' | 'staging' | 'production';
|
|
73
|
+
export declare type FeatureFlagEventProperties = {
|
|
74
|
+
environment?: FeatureFlagEnvironment;
|
|
75
|
+
success?: boolean;
|
|
76
|
+
name?: string;
|
|
77
|
+
};
|
|
78
|
+
export declare type FeatureFlagEventTrackPayload = {
|
|
79
|
+
type: FeatureFlagEventType;
|
|
80
|
+
properties: FeatureFlagEventProperties;
|
|
81
|
+
};
|
|
69
82
|
export interface RuntimePermissions {
|
|
70
83
|
scopes?: Scopes;
|
|
71
84
|
external?: External;
|
package/out/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE7D,oBAAY,aAAa,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strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExtensionEnvironment = void 0;
|
|
3
|
+
exports.FeatureFlagEventType = exports.ExtensionEnvironment = void 0;
|
|
4
4
|
var ExtensionEnvironment;
|
|
5
5
|
(function (ExtensionEnvironment) {
|
|
6
6
|
ExtensionEnvironment["DEVELOPMENT"] = "DEVELOPMENT";
|
|
@@ -11,3 +11,7 @@ var EcosystemLicenseMode;
|
|
|
11
11
|
(function (EcosystemLicenseMode) {
|
|
12
12
|
EcosystemLicenseMode["USER_ACCESS"] = "USER_ACCESS";
|
|
13
13
|
})(EcosystemLicenseMode || (EcosystemLicenseMode = {}));
|
|
14
|
+
var FeatureFlagEventType;
|
|
15
|
+
(function (FeatureFlagEventType) {
|
|
16
|
+
FeatureFlagEventType["CHECKFLAG"] = "checkFlag";
|
|
17
|
+
})(FeatureFlagEventType = exports.FeatureFlagEventType || (exports.FeatureFlagEventType = {}));
|