@canva/error 2.1.0 → 2.2.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/CHANGELOG.md +20 -0
- package/index.d.ts +14 -22
- package/lib/cjs/sdk/error/fake/fake_canva_error.js +1 -2
- package/lib/cjs/sdk/error/index.js +2 -3
- package/lib/cjs/sdk/error/version.js +24 -0
- package/lib/cjs/sdk/utils/canva_sdk.js +32 -10
- package/lib/esm/sdk/error/fake/fake_canva_error.js +1 -2
- package/lib/esm/sdk/error/index.js +2 -3
- package/lib/esm/sdk/error/version.js +3 -0
- package/lib/esm/sdk/utils/canva_sdk.js +23 -4
- package/package.json +1 -1
- package/test/index.d.ts +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# CHANGELOG
|
|
2
|
+
|
|
3
|
+
## 2.2.0 - 2026-01-19
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added a CHANGELOG.md to track changes.
|
|
8
|
+
- Added a new `missing_permission` error code.
|
|
9
|
+
|
|
10
|
+
## 2.1.0 - 2024-12-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Introduced a test harness to allow for [unit testing](https://www.canva.dev/docs/apps/testing/) of the package.
|
|
15
|
+
|
|
16
|
+
## 2.0.0 - 2024-09-19
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- **Breaking:** See [Apps SDK Migration Guide](https://www.canva.dev/docs/apps/upgrades-and-migrations/v2-migration-guide/) for full list of changes.
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @public */
|
|
2
2
|
declare interface BaseCanvaError extends Error {
|
|
3
|
-
|
|
3
|
+
code: ErrorCode;
|
|
4
|
+
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -14,12 +15,15 @@ export declare const CanvaError: typeof CanvaErrorClass;
|
|
|
14
15
|
* An error thrown by the Apps SDK.
|
|
15
16
|
*/
|
|
16
17
|
declare class CanvaErrorClass extends Error implements BaseCanvaError {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
/**
|
|
19
|
+
* A code that identifies why the error was thrown.
|
|
20
|
+
*/
|
|
21
|
+
readonly code: ErrorCode;
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
constructor(opts: {
|
|
24
|
+
code: ErrorCode;
|
|
25
|
+
message: string;
|
|
26
|
+
});
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -35,7 +39,8 @@ declare class CanvaErrorClass extends Error implements BaseCanvaError {
|
|
|
35
39
|
* - `"internal_error"` - An error occurred within the Apps SDK's internal implementation.
|
|
36
40
|
* - `"not_found"` - The specified resource couldn't be found.
|
|
37
41
|
* - `"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
|
|
42
|
+
* - `"permission_denied"` - The app isn't allowed to perform the requested operation because the appropriate permissions aren't accepted.
|
|
43
|
+
* - `"missing_permission"` - The app isn't allowed to perform the requested operation because the appropriate permissions aren't set in the app config.
|
|
39
44
|
* - `"quota_exceeded"` - The app or user has exceeded their allocated quota for a resource or service.
|
|
40
45
|
* - `"rate_limited"` - The app attempted too many operations within a certain period of time.
|
|
41
46
|
* - `"timeout"` - The requested operation took too long to complete.
|
|
@@ -43,19 +48,6 @@ declare class CanvaErrorClass extends Error implements BaseCanvaError {
|
|
|
43
48
|
* - `"unsupported_page_type"` - The requested operation isn't supported on the current page.
|
|
44
49
|
* - `"user_offline"` - The requested operation can't be performed because the user is offline.
|
|
45
50
|
*/
|
|
46
|
-
export declare type ErrorCode =
|
|
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";
|
|
51
|
+
export declare type ErrorCode = 'bad_external_service_response' | 'bad_request' | 'failed_precondition' | 'internal_error' | 'not_found' | 'not_allowed' | 'permission_denied' | 'missing_permission' | 'quota_exceeded' | 'rate_limited' | 'timeout' | 'unsupported_surface' | 'unsupported_page_type' | 'user_offline';
|
|
60
52
|
|
|
61
|
-
export {}
|
|
53
|
+
export { }
|
|
@@ -11,8 +11,7 @@ Object.defineProperty(exports, "FakeCanvaError", {
|
|
|
11
11
|
class FakeCanvaError extends Error {
|
|
12
12
|
constructor(opts){
|
|
13
13
|
const message = `Fake mode error - [${opts.code}]: ${opts.message}`;
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = 'FakeCanvaError';
|
|
14
|
+
super(message), this.name = 'FakeCanvaError';
|
|
16
15
|
this.rawMessage = opts.message;
|
|
17
16
|
this.code = opts.code;
|
|
18
17
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
const _version = require("./version");
|
|
5
6
|
_export_star(require("./public"), exports);
|
|
6
7
|
function _export_star(from, to) {
|
|
7
8
|
Object.keys(from).forEach(function(k) {
|
|
@@ -16,6 +17,4 @@ function _export_star(from, to) {
|
|
|
16
17
|
});
|
|
17
18
|
return from;
|
|
18
19
|
}
|
|
19
|
-
|
|
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');
|
|
20
|
+
window.__canva__?.sdkRegistration?.registerPackageVersion('error', _version.LATEST_VERSION, 'ga');
|
|
@@ -0,0 +1,24 @@
|
|
|
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: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get LATEST_VERSION () {
|
|
13
|
+
return LATEST_VERSION;
|
|
14
|
+
},
|
|
15
|
+
get LATEST_VERSION_ALPHA () {
|
|
16
|
+
return LATEST_VERSION_ALPHA;
|
|
17
|
+
},
|
|
18
|
+
get LATEST_VERSION_BETA () {
|
|
19
|
+
return LATEST_VERSION_BETA;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const LATEST_VERSION = '2.2.0';
|
|
23
|
+
const LATEST_VERSION_BETA = 'NONE';
|
|
24
|
+
const LATEST_VERSION_ALPHA = 'NONE';
|
|
@@ -5,17 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
function _export(target, all) {
|
|
6
6
|
for(var name in all)Object.defineProperty(target, name, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: all
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
return getCanvaSdk;
|
|
14
|
-
},
|
|
15
|
-
assertIsTestCanvaSdk: function() {
|
|
12
|
+
get assertIsTestCanvaSdk () {
|
|
16
13
|
return assertIsTestCanvaSdk;
|
|
17
14
|
},
|
|
18
|
-
|
|
15
|
+
get bindMethodsToClients () {
|
|
16
|
+
return bindMethodsToClients;
|
|
17
|
+
},
|
|
18
|
+
get getCanvaSdk () {
|
|
19
|
+
return getCanvaSdk;
|
|
20
|
+
},
|
|
21
|
+
get injectFakeAPIClients () {
|
|
19
22
|
return injectFakeAPIClients;
|
|
20
23
|
}
|
|
21
24
|
});
|
|
@@ -23,10 +26,8 @@ function getCanvaSdk() {
|
|
|
23
26
|
return window.canva_sdk;
|
|
24
27
|
}
|
|
25
28
|
function assertIsTestCanvaSdk() {
|
|
26
|
-
|
|
27
|
-
|
|
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;
|
|
29
|
+
if (window.__canva__?.uiKit) {
|
|
30
|
+
const CanvaError = getCanvaSdk()?.error?.v2.CanvaError;
|
|
30
31
|
throw new CanvaError({
|
|
31
32
|
code: 'failed_precondition',
|
|
32
33
|
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/"
|
|
@@ -34,8 +35,29 @@ function assertIsTestCanvaSdk() {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
function injectFakeAPIClients(clients) {
|
|
38
|
+
bindMethodsToClients(clients);
|
|
37
39
|
window.canva_sdk = {
|
|
38
40
|
...getCanvaSdk(),
|
|
39
41
|
...clients
|
|
40
42
|
};
|
|
41
43
|
}
|
|
44
|
+
function bindMethodsToClients(objectToBind) {
|
|
45
|
+
if (typeof objectToBind !== 'object' || objectToBind == null)
|
|
46
|
+
return;
|
|
47
|
+
const classMethods = new Set();
|
|
48
|
+
let currentPrototype = Object.getPrototypeOf(objectToBind);
|
|
49
|
+
while(currentPrototype && currentPrototype !== Object.prototype){
|
|
50
|
+
Object.getOwnPropertyNames(currentPrototype).forEach((method)=>classMethods.add(method));
|
|
51
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
52
|
+
}
|
|
53
|
+
classMethods.delete('constructor');
|
|
54
|
+
for (const method of classMethods) {
|
|
55
|
+
const originalFn = objectToBind[method];
|
|
56
|
+
if (typeof originalFn === 'function') Object.defineProperty(objectToBind, method, {
|
|
57
|
+
value: (...args)=>{
|
|
58
|
+
return originalFn.call(objectToBind, ...args);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
Object.values(objectToBind).forEach(bindMethodsToClients);
|
|
63
|
+
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export class FakeCanvaError extends Error {
|
|
2
2
|
constructor(opts){
|
|
3
3
|
const message = `Fake mode error - [${opts.code}]: ${opts.message}`;
|
|
4
|
-
super(message);
|
|
5
|
-
this.name = 'FakeCanvaError';
|
|
4
|
+
super(message), this.name = 'FakeCanvaError';
|
|
6
5
|
this.rawMessage = opts.message;
|
|
7
6
|
this.code = opts.code;
|
|
8
7
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { LATEST_VERSION } from './version';
|
|
2
2
|
export * from './public';
|
|
3
|
-
(
|
|
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');
|
|
3
|
+
window.__canva__?.sdkRegistration?.registerPackageVersion('error', LATEST_VERSION, 'ga');
|
|
@@ -2,10 +2,8 @@ export function getCanvaSdk() {
|
|
|
2
2
|
return window.canva_sdk;
|
|
3
3
|
}
|
|
4
4
|
export function assertIsTestCanvaSdk() {
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
5
|
+
if (window.__canva__?.uiKit) {
|
|
6
|
+
const CanvaError = getCanvaSdk()?.error?.v2.CanvaError;
|
|
9
7
|
throw new CanvaError({
|
|
10
8
|
code: 'failed_precondition',
|
|
11
9
|
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/"
|
|
@@ -13,8 +11,29 @@ export function assertIsTestCanvaSdk() {
|
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
export function injectFakeAPIClients(clients) {
|
|
14
|
+
bindMethodsToClients(clients);
|
|
16
15
|
window.canva_sdk = {
|
|
17
16
|
...getCanvaSdk(),
|
|
18
17
|
...clients
|
|
19
18
|
};
|
|
20
19
|
}
|
|
20
|
+
export function bindMethodsToClients(objectToBind) {
|
|
21
|
+
if (typeof objectToBind !== 'object' || objectToBind == null)
|
|
22
|
+
return;
|
|
23
|
+
const classMethods = new Set();
|
|
24
|
+
let currentPrototype = Object.getPrototypeOf(objectToBind);
|
|
25
|
+
while(currentPrototype && currentPrototype !== Object.prototype){
|
|
26
|
+
Object.getOwnPropertyNames(currentPrototype).forEach((method)=>classMethods.add(method));
|
|
27
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
28
|
+
}
|
|
29
|
+
classMethods.delete('constructor');
|
|
30
|
+
for (const method of classMethods) {
|
|
31
|
+
const originalFn = objectToBind[method];
|
|
32
|
+
if (typeof originalFn === 'function') Object.defineProperty(objectToBind, method, {
|
|
33
|
+
value: (...args)=>{
|
|
34
|
+
return originalFn.call(objectToBind, ...args);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
Object.values(objectToBind).forEach(bindMethodsToClients);
|
|
39
|
+
}
|
package/package.json
CHANGED
package/test/index.d.ts
CHANGED