@canva/error 1.2.0 → 2.1.0
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/index.d.ts +36 -52
- package/lib/cjs/sdk/error/fake/fake_canva_error.js +19 -0
- package/lib/cjs/sdk/error/fake/inject.js +20 -0
- package/lib/cjs/sdk/error/index.js +4 -4
- package/lib/cjs/sdk/error/public.js +2 -2
- package/lib/cjs/sdk/error/test/index.js +16 -0
- package/lib/cjs/sdk/utils/canva_sdk.js +41 -0
- package/lib/esm/sdk/error/fake/fake_canva_error.js +9 -0
- package/lib/esm/sdk/error/fake/inject.js +10 -0
- package/lib/esm/sdk/error/index.js +4 -3
- package/lib/esm/sdk/error/public.js +2 -5
- package/lib/esm/sdk/error/test/index.js +6 -0
- package/lib/esm/sdk/utils/canva_sdk.js +20 -0
- package/package.json +9 -9
- package/test/index.d.ts +11 -0
package/index.d.ts
CHANGED
|
@@ -5,15 +5,18 @@ declare interface BaseCanvaError extends Error {
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @public
|
|
8
|
-
*
|
|
8
|
+
* An error thrown by the Apps SDK.
|
|
9
9
|
*/
|
|
10
10
|
export declare const CanvaError: typeof CanvaErrorClass;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @public
|
|
14
|
-
*
|
|
14
|
+
* An error thrown by the Apps SDK.
|
|
15
15
|
*/
|
|
16
16
|
declare class CanvaErrorClass extends Error implements BaseCanvaError {
|
|
17
|
+
/**
|
|
18
|
+
* A code that identifies why the error was thrown.
|
|
19
|
+
*/
|
|
17
20
|
readonly code: ErrorCode;
|
|
18
21
|
|
|
19
22
|
constructor(opts: { code: ErrorCode; message: string });
|
|
@@ -21,57 +24,38 @@ declare class CanvaErrorClass extends Error implements BaseCanvaError {
|
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
26
|
* @public
|
|
24
|
-
*
|
|
27
|
+
* An error code that identifies why an error was thrown by the Apps SDK.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* The possible error codes include:
|
|
31
|
+
*
|
|
32
|
+
* - `"bad_external_service_response"` - A response from an external service is invalid or malformed.
|
|
33
|
+
* - `"bad_request"` - The app made a request with invalid or malformed inputs.
|
|
34
|
+
* - `"failed_precondition"` - The requested operation can't be performed because a precondition hasn't been met.
|
|
35
|
+
* - `"internal_error"` - An error occurred within the Apps SDK's internal implementation.
|
|
36
|
+
* - `"not_found"` - The specified resource couldn't be found.
|
|
37
|
+
* - `"not_allowed"` - The app isn't allowed to perform the requested operation.
|
|
38
|
+
* - `"permission_denied"` - The app isn't allowed perform the requested operation because the appropriate permissions aren't set.
|
|
39
|
+
* - `"quota_exceeded"` - The app or user has exceeded their allocated quota for a resource or service.
|
|
40
|
+
* - `"rate_limited"` - The app attempted too many operations within a certain period of time.
|
|
41
|
+
* - `"timeout"` - The requested operation took too long to complete.
|
|
42
|
+
* - `"unsupported_surface"` - The requested operation isn't supported on the current surface.
|
|
43
|
+
* - `"unsupported_page_type"` - The requested operation isn't supported on the current page.
|
|
44
|
+
* - `"user_offline"` - The requested operation can't be performed because the user is offline.
|
|
25
45
|
*/
|
|
26
46
|
export declare type ErrorCode =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
| "
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
| "
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
| "
|
|
40
|
-
/**
|
|
41
|
-
* An error occurred within the SDK's internal implementation.
|
|
42
|
-
*/
|
|
43
|
-
| "INTERNAL_ERROR"
|
|
44
|
-
/**
|
|
45
|
-
* The allocated quota for the resource or service has been exceeded.
|
|
46
|
-
*/
|
|
47
|
-
| "QUOTA_EXCEEDED"
|
|
48
|
-
/**
|
|
49
|
-
* The system has received too many requests in a short period of time.
|
|
50
|
-
*/
|
|
51
|
-
| "RATE_LIMITED"
|
|
52
|
-
/**
|
|
53
|
-
* The caller does not have sufficient permissions to execute the specified operation.
|
|
54
|
-
*/
|
|
55
|
-
| "PERMISSION_DENIED"
|
|
56
|
-
/**
|
|
57
|
-
* The specified operation is not supported on the surface.
|
|
58
|
-
*/
|
|
59
|
-
| "UNSUPPORTED_SURFACE"
|
|
60
|
-
/**
|
|
61
|
-
* The user is currently offline and cannot perform the requested operation.
|
|
62
|
-
*/
|
|
63
|
-
| "USER_OFFLINE"
|
|
64
|
-
/**
|
|
65
|
-
* The specified resource was not found
|
|
66
|
-
*/
|
|
67
|
-
| "NOT_FOUND"
|
|
68
|
-
/**
|
|
69
|
-
* The specified operation was not allowed
|
|
70
|
-
*/
|
|
71
|
-
| "NOT_ALLOWED"
|
|
72
|
-
/**
|
|
73
|
-
* The operation exceeded the maximum allowed time to complete.
|
|
74
|
-
*/
|
|
75
|
-
| "TIMEOUT";
|
|
47
|
+
| "bad_external_service_response"
|
|
48
|
+
| "bad_request"
|
|
49
|
+
| "failed_precondition"
|
|
50
|
+
| "internal_error"
|
|
51
|
+
| "not_found"
|
|
52
|
+
| "not_allowed"
|
|
53
|
+
| "permission_denied"
|
|
54
|
+
| "quota_exceeded"
|
|
55
|
+
| "rate_limited"
|
|
56
|
+
| "timeout"
|
|
57
|
+
| "unsupported_surface"
|
|
58
|
+
| "unsupported_page_type"
|
|
59
|
+
| "user_offline";
|
|
76
60
|
|
|
77
61
|
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FakeCanvaError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FakeCanvaError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class FakeCanvaError extends Error {
|
|
12
|
+
constructor(opts){
|
|
13
|
+
const message = `Fake mode error - [${opts.code}]: ${opts.message}`;
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'FakeCanvaError';
|
|
16
|
+
this.rawMessage = opts.message;
|
|
17
|
+
this.code = opts.code;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "injectError", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return injectError;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fake_canva_error = require("./fake_canva_error");
|
|
12
|
+
function injectError() {
|
|
13
|
+
return {
|
|
14
|
+
error: {
|
|
15
|
+
v2: {
|
|
16
|
+
CanvaError: _fake_canva_error.FakeCanvaError
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
"use strict";
|
|
1
|
+
"use strict"
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
3
|
value: true
|
|
5
4
|
});
|
|
@@ -17,5 +16,6 @@ function _export_star(from, to) {
|
|
|
17
16
|
});
|
|
18
17
|
return from;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
var _window___canva___sdkRegistration, _window___canva__;
|
|
20
|
+
(_window___canva__ =
|
|
21
|
+
window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('error', '2.1.0', 'ga');
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "initTestEnvironment", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return initTestEnvironment;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _inject = require('../fake/inject');
|
|
12
|
+
const _canva_sdk = require('../../utils/canva_sdk');
|
|
13
|
+
function initTestEnvironment() {
|
|
14
|
+
(0, _canva_sdk.assertIsTestCanvaSdk)();
|
|
15
|
+
(0, _canva_sdk.injectFakeAPIClients)((0, _inject.injectError)());
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getCanvaSdk: function() {
|
|
13
|
+
return getCanvaSdk;
|
|
14
|
+
},
|
|
15
|
+
assertIsTestCanvaSdk: function() {
|
|
16
|
+
return assertIsTestCanvaSdk;
|
|
17
|
+
},
|
|
18
|
+
injectFakeAPIClients: function() {
|
|
19
|
+
return injectFakeAPIClients;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
function getCanvaSdk() {
|
|
23
|
+
return window.canva_sdk;
|
|
24
|
+
}
|
|
25
|
+
function assertIsTestCanvaSdk() {
|
|
26
|
+
var _window___canva__;
|
|
27
|
+
if ((_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : _window___canva__.uiKit) {
|
|
28
|
+
var _getCanvaSdk_error, _getCanvaSdk;
|
|
29
|
+
const CanvaError = (_getCanvaSdk = getCanvaSdk()) === null || _getCanvaSdk === void 0 ? void 0 : (_getCanvaSdk_error = _getCanvaSdk.error) === null || _getCanvaSdk_error === void 0 ? void 0 : _getCanvaSdk_error.v2.CanvaError;
|
|
30
|
+
throw new CanvaError({
|
|
31
|
+
code: 'failed_precondition',
|
|
32
|
+
message: "Canva App SDK: You're attempting to call `initTestEnvironment` in a non-test environment, such as in production. This method should be called in test environments, once and only once. For more info refer to https://canva.dev/docs/apps/testing/"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function injectFakeAPIClients(clients) {
|
|
37
|
+
window.canva_sdk = {
|
|
38
|
+
...getCanvaSdk(),
|
|
39
|
+
...clients
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export * from './public';
|
|
3
|
-
|
|
1
|
+
var _window___canva___sdkRegistration, _window___canva__;
|
|
2
|
+
export * from './public';
|
|
3
|
+
(_window___canva__ =
|
|
4
|
+
window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('error', '2.1.0', 'ga');
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function getCanvaSdk() {
|
|
2
|
+
return window.canva_sdk;
|
|
3
|
+
}
|
|
4
|
+
export function assertIsTestCanvaSdk() {
|
|
5
|
+
var _window___canva__;
|
|
6
|
+
if ((_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : _window___canva__.uiKit) {
|
|
7
|
+
var _getCanvaSdk_error, _getCanvaSdk;
|
|
8
|
+
const CanvaError = (_getCanvaSdk = getCanvaSdk()) === null || _getCanvaSdk === void 0 ? void 0 : (_getCanvaSdk_error = _getCanvaSdk.error) === null || _getCanvaSdk_error === void 0 ? void 0 : _getCanvaSdk_error.v2.CanvaError;
|
|
9
|
+
throw new CanvaError({
|
|
10
|
+
code: 'failed_precondition',
|
|
11
|
+
message: "Canva App SDK: You're attempting to call `initTestEnvironment` in a non-test environment, such as in production. This method should be called in test environments, once and only once. For more info refer to https://canva.dev/docs/apps/testing/"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function injectFakeAPIClients(clients) {
|
|
16
|
+
window.canva_sdk = {
|
|
17
|
+
...getCanvaSdk(),
|
|
18
|
+
...clients
|
|
19
|
+
};
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canva/error",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "The Canva Apps SDK error library",
|
|
5
5
|
"author": "Canva Pty Ltd.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md FILE",
|
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"module": "./lib/esm/sdk/error/index.js",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"require": "./lib/cjs/sdk/error/index.js",
|
|
13
|
+
"import": "./lib/esm/sdk/error/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./test": {
|
|
16
|
+
"types": "./test/index.d.ts",
|
|
17
|
+
"require": "./lib/cjs/sdk/error/test/index.js",
|
|
18
|
+
"import": "./lib/esm/sdk/error/test/index.js"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"typings": "./index.d.ts"
|
package/test/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
* Initializes a test environment for the `@canva/error` package, enabling unit tests to mock Canva's APIs.
|
|
4
|
+
* @remarks
|
|
5
|
+
* This method should only be called once in a test environment, such as in a Jest setup file.
|
|
6
|
+
* @see
|
|
7
|
+
* https://www.canva.dev/docs/apps/testing/
|
|
8
|
+
*/
|
|
9
|
+
export declare function initTestEnvironment(): void;
|
|
10
|
+
|
|
11
|
+
export {};
|